0

birch: Add test for weather provider using correct weather client ID

Fetches to the backdrop server include a weather client ID. Test that
the birch weather provider passes the correct ID to FetchWeather()
(which the production code will use in an HTTP request to the server).

Bug: b:353754800
Test: ash_unittests
Change-Id: Ief074752decbef770ec518697de5c20f82946c74
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5722523
Reviewed-by: Matthew Mourgos <mmourgos@chromium.org>
Commit-Queue: James Cook <jamescook@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1329971}
This commit is contained in:
James Cook
2024-07-19 02:19:34 +00:00
committed by Chromium LUCI CQ
parent 1ec76b5444
commit 8355786628
3 changed files with 31 additions and 0 deletions

@ -149,6 +149,30 @@ TEST_F(BirchWeatherProviderTest, GetWeather) {
}));
}
TEST_F(BirchWeatherProviderTest, GetWeatherUsesChromeOSWeatherClientId) {
auto* birch_model = Shell::Get()->birch_model();
// Set up fake weather.
WeatherInfo info;
info.condition_description = "Cloudy";
info.condition_icon_url = "https://fake-icon-url";
info.temp_f = 70.0f;
ambient_backend_controller_->SetWeatherInfo(info);
// Fetch birch data, which includes weather.
base::RunLoop run_loop;
birch_model->RequestBirchDataFetch(/*is_post_login=*/false,
run_loop.QuitClosure());
EXPECT_TRUE(birch_model->GetWeatherForTest().empty());
run_loop.Run();
// Verify the controller was called with the correct weather client ID.
std::optional<std::string> weather_client_id =
ambient_backend_controller_->weather_client_id();
ASSERT_TRUE(weather_client_id.has_value());
EXPECT_EQ(*weather_client_id, "chromeos-system-ui");
}
TEST_F(BirchWeatherProviderTest, GetWeatherWaitsForRefreshTokens) {
auto* birch_model = Shell::Get()->birch_model();
StubBirchClient birch_client;

@ -166,6 +166,7 @@ void FakeAmbientBackendControllerImpl::FetchWeather(
bool prefer_aplha_endpoint,
FetchWeatherCallback callback) {
++fetch_weather_count_;
weather_client_id_ = weather_client_id;
if (run_fetch_weather_callback_) {
std::move(callback).Run(weather_info_);
}

@ -107,6 +107,11 @@ class ASH_PUBLIC_EXPORT FakeAmbientBackendControllerImpl
run_fetch_weather_callback_ = value;
}
// The latest `weather_client_id` passed to `FetchWeather()`.
std::optional<std::string> weather_client_id() const {
return weather_client_id_;
}
private:
OnSettingsAndAlbumsFetchedCallback pending_fetch_settings_albums_callback_;
@ -133,6 +138,7 @@ class ASH_PUBLIC_EXPORT FakeAmbientBackendControllerImpl
int fetch_weather_count_ = 0;
bool run_fetch_weather_callback_ = true;
std::optional<std::string> weather_client_id_;
};
} // namespace ash