0

Revert "Add V2 birch weather provider"

We're not moving forward with the chromeossystemui server, so this
code is no longer needed.

This reverts commit 87e9422b71
with merge conflict resolution. See also:
https://chromium-review.googlesource.com/c/chromium/src/+/5551840

Bug: b:343205942
Test: manual, weather still loads, ash_unittests, unit_tests
Change-Id: I29b62675fd610407d55b44030784d35d53dae44a
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5717542
Reviewed-by: Nicolas Ouellet-Payeur <nicolaso@chromium.org>
Reviewed-by: Matthew Mourgos <mmourgos@chromium.org>
Commit-Queue: James Cook <jamescook@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1329806}
This commit is contained in:
James Cook
2024-07-18 21:01:29 +00:00
committed by Chromium LUCI CQ
parent c8b41e12a1
commit 84df7f402e
17 changed files with 44 additions and 848 deletions

@ -33,7 +33,6 @@ class ASH_EXPORT BirchClient {
virtual BirchDataProvider* GetSelfShareProvider() = 0;
virtual BirchDataProvider* GetLostMediaProvider() = 0;
virtual BirchDataProvider* GetReleaseNotesProvider() = 0;
virtual BirchDataProvider* GetWeatherV2Provider() = 0;
// Waits for refresh tokens to be loaded then calls `callback`. Calls
// `callback` immediately if tokens are already loaded. Only one waiter

@ -73,7 +73,6 @@ class StubBirchClient : public BirchClient {
BirchDataProvider* GetSelfShareProvider() override { return nullptr; }
BirchDataProvider* GetLostMediaProvider() override { return nullptr; }
BirchDataProvider* GetReleaseNotesProvider() override { return nullptr; }
BirchDataProvider* GetWeatherV2Provider() override { return nullptr; }
void WaitForRefreshTokens(base::OnceClosure callback) override {}
base::FilePath GetRemovedItemsFilePath() override { return base::FilePath(); }
void RemoveFileItemFromLauncher(const base::FilePath& path) override {}

@ -64,10 +64,7 @@ BirchModel::BirchModel()
release_notes_data_(prefs::kBirchUseReleaseNotes, "ReleaseNotes"),
weather_data_(prefs::kBirchUseWeather, "Weather"),
icon_cache_(std::make_unique<BirchIconCache>()) {
if (features::IsBirchWeatherEnabled() &&
!features::IsBirchWeatherV2Enabled()) {
// If BirchWeatherV2 is enabled, the weather provider is owned by birch
// client.
if (features::IsBirchWeatherEnabled()) {
weather_provider_ = std::make_unique<BirchWeatherProvider>(this);
}
Shell::Get()->session_controller()->AddObserver(this);
@ -236,16 +233,6 @@ void BirchModel::StartDataFetchIfNeeded(DataTypeInfo<T>& data_info,
data_provider->RequestBirchDataFetch();
}
BirchDataProvider* BirchModel::GetWeatherProvider() {
if (!features::IsBirchWeatherEnabled()) {
return nullptr;
}
if (features::IsBirchWeatherV2Enabled()) {
return birch_client_ ? birch_client_->GetWeatherV2Provider() : nullptr;
}
return weather_provider_.get();
}
void BirchModel::RequestBirchDataFetch(bool is_post_login,
base::OnceClosure callback) {
if (!Shell::Get()->session_controller()->IsUserPrimary()) {
@ -307,7 +294,7 @@ void BirchModel::RequestBirchDataFetch(bool is_post_login,
StartDataFetchIfNeeded(release_notes_data_,
birch_client_->GetReleaseNotesProvider());
}
StartDataFetchIfNeeded(weather_data_, GetWeatherProvider());
StartDataFetchIfNeeded(weather_data_, weather_provider_.get());
MaybeRespondToDataFetchRequest();
}
@ -516,7 +503,7 @@ bool BirchModel::IsDataFresh() {
release_notes_data_.is_fresh);
// Use the same logic for weather.
bool is_weather_fresh = !GetWeatherProvider() || weather_data_.is_fresh;
bool is_weather_fresh = !weather_provider_ || weather_data_.is_fresh;
return is_birch_client_fresh && is_weather_fresh;
}
@ -735,7 +722,7 @@ void BirchModel::OnLostMediaPrefChanged() {
}
void BirchModel::OnWeatherPrefChanged() {
StartDataFetchIfNeeded(weather_data_, GetWeatherProvider());
StartDataFetchIfNeeded(weather_data_, weather_provider_.get());
}
void BirchModel::OnReleaseNotesPrefChanged() {

@ -227,10 +227,6 @@ class ASH_EXPORT BirchModel : public SessionObserver,
// Returns true if most visited items should be included in the results.
bool ShouldShowMostVisited();
// Returns the weather provider to use, depending on whether BirchWeatherV2
// feature is enabled. Returns nullptr if weather provider is disabled.
BirchDataProvider* GetWeatherProvider();
// Whether this is a post-login fetch (occurring right after login).
bool is_post_login_fetch_ = false;

@ -99,12 +99,7 @@ class StubBirchDataProvider : public BirchDataProvider {
// A BirchClient that returns data providers that do nothing.
class StubBirchClient : public BirchClient {
public:
StubBirchClient() {
EXPECT_TRUE(test_dir_.CreateUniqueTempDir());
if (features::IsBirchWeatherV2Enabled()) {
weather_provider_ = std::make_unique<StubBirchDataProvider>();
}
}
StubBirchClient() { EXPECT_TRUE(test_dir_.CreateUniqueTempDir()); }
~StubBirchClient() override = default;
// BirchClient:
@ -132,9 +127,6 @@ class StubBirchClient : public BirchClient {
BirchDataProvider* GetReleaseNotesProvider() override {
return &release_notes_provider_;
}
BirchDataProvider* GetWeatherV2Provider() override {
return weather_provider_.get();
}
void WaitForRefreshTokens(base::OnceClosure callback) override {
std::move(callback).Run();
}
@ -160,8 +152,6 @@ class StubBirchClient : public BirchClient {
StubBirchDataProvider self_share_provider_;
StubBirchDataProvider lost_media_provider_;
StubBirchDataProvider release_notes_provider_;
std::unique_ptr<StubBirchDataProvider> weather_provider_;
base::ScopedTempDir test_dir_;
base::FilePath last_removed_path_;
};

@ -51,11 +51,6 @@ class StubBirchClient : public BirchClient {
BirchDataProvider* GetSelfShareProvider() override { return &provider_; }
BirchDataProvider* GetLostMediaProvider() override { return &provider_; }
BirchDataProvider* GetReleaseNotesProvider() override { return &provider_; }
BirchDataProvider* GetWeatherV2Provider() override {
// Null because V2 provider and the weather provider tested in this test
// suite never coexist.
return nullptr;
}
void WaitForRefreshTokens(base::OnceClosure callback) override {
did_wait_for_refresh_tokens_ = true;
@ -84,8 +79,7 @@ class BirchWeatherProviderTest : public AshTestBase {
public:
BirchWeatherProviderTest() {
feature_list_.InitWithFeatures(
{features::kForestFeature, features::kBirchWeather},
{features::kBirchWeatherV2});
{features::kForestFeature, features::kBirchWeather}, {});
}
~BirchWeatherProviderTest() override = default;

@ -263,12 +263,6 @@ BASE_FEATURE(kBatterySaverAlwaysOn,
// Display weather information in birch UI.
BASE_FEATURE(kBirchWeather, "BirchWeather", base::FEATURE_ENABLED_BY_DEFAULT);
// Display weather information in birch UI, with weather getting fetched from
// chromeos-system-ui endpoint.
BASE_FEATURE(kBirchWeatherV2,
"BirchWeatherV2",
base::FEATURE_DISABLED_BY_DEFAULT);
// Enables or disables the usage of fixed Bluetooth A2DP packet size to improve
// audio performance in noisy environment.
BASE_FEATURE(kBluetoothFixA2dpPacketSize,
@ -3520,9 +3514,6 @@ bool IsBirchWeatherEnabled() {
return base::FeatureList::IsEnabled(kBirchWeather);
}
bool IsBirchWeatherV2Enabled() {
return base::FeatureList::IsEnabled(kBirchWeatherV2);
}
bool IsBluetoothDisconnectWarningEnabled() {
return base::FeatureList::IsEnabled(kBluetoothDisconnectWarning);
}

@ -75,7 +75,6 @@ COMPONENT_EXPORT(ASH_CONSTANTS)
BASE_DECLARE_FEATURE(kAutozoomNudgeSessionReset);
COMPONENT_EXPORT(ASH_CONSTANTS) BASE_DECLARE_FEATURE(kBatterySaver);
COMPONENT_EXPORT(ASH_CONSTANTS) BASE_DECLARE_FEATURE(kBirchWeather);
COMPONENT_EXPORT(ASH_CONSTANTS) BASE_DECLARE_FEATURE(kBirchWeatherV2);
COMPONENT_EXPORT(ASH_CONSTANTS)
BASE_DECLARE_FEATURE(kBirchVideoConferenceSuggestions);
enum BatterySaverNotificationBehavior { kBSMAutoEnable, kBSMOptIn };
@ -1087,7 +1086,6 @@ COMPONENT_EXPORT(ASH_CONSTANTS) bool IsBatterySaverAvailable();
COMPONENT_EXPORT(ASH_CONSTANTS) bool IsBatterySaverAlwaysOn();
COMPONENT_EXPORT(ASH_CONSTANTS) bool IsBirchVideoConferenceSuggestionsEnabled();
COMPONENT_EXPORT(ASH_CONSTANTS) bool IsBirchWeatherEnabled();
COMPONENT_EXPORT(ASH_CONSTANTS) bool IsBirchWeatherV2Enabled();
COMPONENT_EXPORT(ASH_CONSTANTS) bool IsBluetoothQualityReportEnabled();
COMPONENT_EXPORT(ASH_CONSTANTS) bool IsBluetoothDisconnectWarningEnabled();
COMPONENT_EXPORT(ASH_CONSTANTS) bool IsBocaEnabled();

@ -178,13 +178,6 @@ class TestBirchClient : public BirchClient {
base::BindRepeating(&BirchModel::SetReleaseNotesItems,
base::Unretained(birch_model)),
std::string());
if (features::IsBirchWeatherV2Enabled()) {
weather_provider_ =
std::make_unique<TestBirchDataProvider<BirchWeatherItem>>(
base::BindRepeating(&BirchModel::SetWeatherItems,
base::Unretained(birch_model)),
prefs::kBirchUseWeather);
}
EXPECT_TRUE(test_dir_.CreateUniqueTempDir());
}
TestBirchClient(const TestBirchClient&) = delete;
@ -223,11 +216,6 @@ class TestBirchClient : public BirchClient {
lost_media_provider_->set_items(items);
}
void SetWeatherItems(const std::vector<BirchWeatherItem>& items) {
ASSERT_TRUE(weather_provider_);
weather_provider_->set_items(items);
}
// Clear all items.
void Reset() {
calendar_provider_->ClearItems();
@ -237,9 +225,6 @@ class TestBirchClient : public BirchClient {
release_notes_provider_->ClearItems();
self_share_provider_->ClearItems();
lost_media_provider_->ClearItems();
if (weather_provider_) {
weather_provider_->ClearItems();
}
}
// BirchClient:
@ -267,10 +252,6 @@ class TestBirchClient : public BirchClient {
BirchDataProvider* GetReleaseNotesProvider() override {
return release_notes_provider_.get();
}
BirchDataProvider* GetWeatherV2Provider() override {
return weather_provider_.get();
}
void WaitForRefreshTokens(base::OnceClosure callback) override {
std::move(callback).Run();
}
@ -310,34 +291,24 @@ class TestBirchClient : public BirchClient {
lost_media_provider_;
std::unique_ptr<TestBirchDataProvider<BirchReleaseNotesItem>>
release_notes_provider_;
std::unique_ptr<TestBirchDataProvider<BirchWeatherItem>> weather_provider_;
base::ScopedTempDir test_dir_;
};
} // namespace
////////////////////////////////////////////////////////////////////////////////
// BirchBarBaseTest:
// BirchBarTest:
// The test class of birch bar with Forest feature enabled by default.
class BirchBarTestBase : public AshTestBase {
class BirchBarTest : public AshTestBase {
public:
BirchBarTestBase(bool use_weather_v2_provider)
: use_weather_v2_provider_(use_weather_v2_provider) {
if (use_weather_v2_provider) {
feature_list_.InitWithFeatures(
{features::kForestFeature, features::kBirchWeather,
features::kBirchWeatherV2},
{});
} else {
feature_list_.InitWithFeatures(
{features::kForestFeature, features::kBirchWeather},
{features::kBirchWeatherV2});
}
BirchBarTest() {
feature_list_.InitWithFeatures(
{features::kForestFeature, features::kBirchWeather}, {});
}
BirchBarTestBase(const BirchBarTestBase&) = delete;
BirchBarTestBase& operator=(const BirchBarTestBase&) = delete;
~BirchBarTestBase() override = default;
BirchBarTest(const BirchBarTest&) = delete;
BirchBarTest& operator=(const BirchBarTest&) = delete;
~BirchBarTest() override = default;
void SetUp() override {
AshTestBase::SetUp();
@ -357,15 +328,13 @@ class BirchBarTestBase : public AshTestBase {
auto* birch_model = Shell::Get()->birch_model();
birch_client_ = std::make_unique<TestBirchClient>(birch_model);
birch_model->SetClientAndInit(birch_client_.get());
if (!use_weather_v2_provider_) {
auto weather_provider =
std::make_unique<TestBirchDataProvider<BirchWeatherItem>>(
base::BindRepeating(&BirchModel::SetWeatherItems,
base::Unretained(birch_model)),
prefs::kBirchUseWeather);
weather_provider_ = weather_provider.get();
birch_model->OverrideWeatherProviderForTest(std::move(weather_provider));
}
auto weather_provider =
std::make_unique<TestBirchDataProvider<BirchWeatherItem>>(
base::BindRepeating(&BirchModel::SetWeatherItems,
base::Unretained(birch_model)),
prefs::kBirchUseWeather);
weather_provider_ = weather_provider.get();
birch_model->OverrideWeatherProviderForTest(std::move(weather_provider));
base::RunLoop run_loop;
Shell::Get()
->birch_model()
@ -509,43 +478,26 @@ class BirchBarTestBase : public AshTestBase {
/*icon*/ ui::ImageModel());
item_list.back().set_ranking(1.0f);
}
if (use_weather_v2_provider_) {
birch_client_->SetWeatherItems(item_list);
} else {
weather_provider_->set_items(item_list);
}
weather_provider_->set_items(item_list);
}
std::unique_ptr<TestBirchClient> birch_client_;
raw_ptr<TestBirchDataProvider<BirchWeatherItem>> weather_provider_;
private:
const bool use_weather_v2_provider_;
base::test::ScopedFeatureList feature_list_;
// Ensure base::Time::Now() is a fixed value.
base::ScopedMockClockOverride mock_clock_override_;
};
class BirchBarTest : public BirchBarTestBase,
public testing::WithParamInterface<bool> {
public:
BirchBarTest() : BirchBarTestBase(/*use_weather_v2_provider=*/GetParam()) {}
BirchBarTest(const BirchBarTest&) = delete;
BirchBarTest& operator=(const BirchBarTest&) = delete;
~BirchBarTest() override = default;
};
INSTANTIATE_TEST_SUITE_P(UsingWeatherV2Provider, BirchBarTest, testing::Bool());
// Tests that the birch bar will be shown in the normal Overview.
TEST_P(BirchBarTest, ShowBirchBar) {
TEST_F(BirchBarTest, ShowBirchBar) {
EnterOverview();
EXPECT_TRUE(
OverviewGridTestApi(Shell::GetPrimaryRootWindow()).birch_bar_view());
}
TEST_P(BirchBarTest, DoNotShowBirchBarForSecondaryUser) {
TEST_F(BirchBarTest, DoNotShowBirchBarForSecondaryUser) {
// Sign in a secondary user.
SimulateUserLogin("user2@test.com");
ASSERT_FALSE(Shell::Get()->session_controller()->IsUserPrimary());
@ -555,7 +507,7 @@ TEST_P(BirchBarTest, DoNotShowBirchBarForSecondaryUser) {
OverviewGridTestApi(Shell::GetPrimaryRootWindow()).birch_bar_view());
}
TEST_P(BirchBarTest, RecordsHistogramWhenChipsShown) {
TEST_F(BirchBarTest, RecordsHistogramWhenChipsShown) {
// Ensure a consistent timezone for this test.
calendar_test_utils::ScopedLibcTimeZone scoped_timezone(
"America/Los_Angeles");
@ -597,7 +549,7 @@ TEST_P(BirchBarTest, RecordsHistogramWhenChipsShown) {
// Tests that the birch bar will be hidden in the partial Overview with a split
// screen.
TEST_P(BirchBarTest, HideBirchBarInPartialSplitScreen) {
TEST_F(BirchBarTest, HideBirchBarInPartialSplitScreen) {
// Create two windows.
auto window_1 = CreateAppWindow(gfx::Rect(100, 100));
// Need another window to keep partial Overview when `window_1` is snapped in
@ -621,7 +573,7 @@ TEST_P(BirchBarTest, HideBirchBarInPartialSplitScreen) {
EXPECT_TRUE(grid_test_api.birch_bar_view());
}
TEST_P(BirchBarTest, ShowBirchBarInTabletMode) {
TEST_F(BirchBarTest, ShowBirchBarInTabletMode) {
EnterOverview();
// Convert to Tablet mode, the birch bar should be shown in Overview mode.
auto* tablet_mode_controller = Shell::Get()->tablet_mode_controller();
@ -635,18 +587,16 @@ TEST_P(BirchBarTest, ShowBirchBarInTabletMode) {
////////////////////////////////////////////////////////////////////////////////
// BirchBarMenuTest:
// The test class of birch bar context menu.
class BirchBarMenuTest : public BirchBarTestBase,
public testing::WithParamInterface<bool> {
class BirchBarMenuTest : public BirchBarTest {
public:
BirchBarMenuTest()
: BirchBarTestBase(/*use_weather_v2_provider=*/GetParam()) {}
BirchBarMenuTest() = default;
BirchBarMenuTest(const BirchBarMenuTest&) = delete;
BirchBarMenuTest& operator=(const BirchBarMenuTest&) = delete;
~BirchBarMenuTest() override = default;
// BirchBarTest:
void SetUp() override {
BirchBarTestBase::SetUp();
BirchBarTest::SetUp();
// Clear existing items.
birch_client_->Reset();
// Ensure screen is large enough to be able to click on all menu items.
@ -669,12 +619,8 @@ class BirchBarMenuTest : public BirchBarTestBase,
}
};
INSTANTIATE_TEST_SUITE_P(UsingWeatherV2Provider,
BirchBarMenuTest,
testing::Bool());
// Tests that removing a suggestion from context menu.
TEST_P(BirchBarMenuTest, RemoveChip) {
TEST_F(BirchBarMenuTest, RemoveChip) {
// Create 5 suggestions with different item types.
SetWeatherItems(/*num=*/1);
SetCalendarItems(/*num=*/2);
@ -757,7 +703,7 @@ TEST_P(BirchBarMenuTest, RemoveChip) {
}
// Tests showing/hiding suggestions from context menu.
TEST_P(BirchBarMenuTest, ShowHideBar) {
TEST_F(BirchBarMenuTest, ShowHideBar) {
// Create a suggestion for test.
SetFileItems(/*num=*/1);
@ -845,7 +791,7 @@ TEST_P(BirchBarMenuTest, ShowHideBar) {
}
// Tests customizing suggestions from context menu.
TEST_P(BirchBarMenuTest, CustomizeSuggestions) {
TEST_F(BirchBarMenuTest, CustomizeSuggestions) {
// Create 4 suggestions, as the bar shows a maximum of 4 chips.
SetWeatherItems(/*num=*/1);
SetCalendarItems(/*num=*/1);
@ -931,7 +877,7 @@ TEST_P(BirchBarMenuTest, CustomizeSuggestions) {
// The bar shows a maximum of 4 suggestion chips. The above test verifies
// customizing the first 4 suggestion types; this test verifies the rest.
TEST_P(BirchBarMenuTest, CustomizeSuggestionsExtended) {
TEST_F(BirchBarMenuTest, CustomizeSuggestionsExtended) {
SetLastActiveItems(/*num=*/1);
SetMostVisitedItems(/*num=*/1);
SetSelfShareItems(/*num=*/1);
@ -1004,7 +950,7 @@ TEST_P(BirchBarMenuTest, CustomizeSuggestionsExtended) {
}
// Tests resetting suggestions from context menu.
TEST_P(BirchBarMenuTest, ResetSuggestions) {
TEST_F(BirchBarMenuTest, ResetSuggestions) {
// Create 4 suggestions, one for each customizable suggestion type.
SetCalendarItems(/*num=*/1);
SetFileItems(/*num=*/1);
@ -1077,7 +1023,7 @@ TEST_P(BirchBarMenuTest, ResetSuggestions) {
// The bar shows a maximum of 4 suggestion chips. The above test verifies
// resetting the first 4 suggestion types; this test verifies the rest.
TEST_P(BirchBarMenuTest, ResetSuggestionsExtended) {
TEST_F(BirchBarMenuTest, ResetSuggestionsExtended) {
SetLastActiveItems(/*num=*/1);
SetMostVisitedItems(/*num=*/1);
SetLostMediaItems(/*num=*/1);
@ -1125,7 +1071,7 @@ TEST_P(BirchBarMenuTest, ResetSuggestionsExtended) {
bar_chips));
}
TEST_P(BirchBarMenuTest, ToggleFahrenheitCelsiusPref) {
TEST_F(BirchBarMenuTest, ToggleFahrenheitCelsiusPref) {
// The pref defaults to Fahrenheit.
EXPECT_FALSE(GetPrefService()->GetBoolean(prefs::kBirchUseCelsius));
@ -1163,7 +1109,7 @@ TEST_P(BirchBarMenuTest, ToggleFahrenheitCelsiusPref) {
// Tests that there is no crash if hiding the suggestions by toggle the switch
// button in chip's submenu.
TEST_P(BirchBarMenuTest, NoCrashHideSuggestionsByChipSubmenu) {
TEST_F(BirchBarMenuTest, NoCrashHideSuggestionsByChipSubmenu) {
// Set show suggestions initially.
GetPrefService()->SetBoolean(prefs::kBirchShowSuggestions, true);
@ -1202,7 +1148,7 @@ TEST_P(BirchBarMenuTest, NoCrashHideSuggestionsByChipSubmenu) {
// Tests that there is no crash if customizing the suggestions by selecting the
// checkboxes in chip's submenu.
TEST_P(BirchBarMenuTest, NoCrashCustomizeSuggestionsByChipSubmenu) {
TEST_F(BirchBarMenuTest, NoCrashCustomizeSuggestionsByChipSubmenu) {
// Set show suggestions and enable weather suggestions initially.
GetPrefService()->SetBoolean(prefs::kBirchShowSuggestions, true);
@ -1265,7 +1211,7 @@ TEST_P(BirchBarMenuTest, NoCrashCustomizeSuggestionsByChipSubmenu) {
}
// Tests hiding certain types of suggestions from context menu.
TEST_P(BirchBarMenuTest, HideSuggestionTypes) {
TEST_F(BirchBarMenuTest, HideSuggestionTypes) {
// Create suggestions, at least one for each customizable suggestion type.
SetWeatherItems(/*num=*/1);
SetCalendarItems(/*num=*/2);
@ -1369,17 +1315,17 @@ struct LayoutTestParams {
// BirchBarLayoutTest:
// The test class of birch bar layout.
class BirchBarLayoutTest
: public BirchBarTestBase,
: public BirchBarTest,
public testing::WithParamInterface<LayoutTestParams> {
public:
BirchBarLayoutTest() : BirchBarTestBase(/*use_weather_v2_provider=*/false) {}
BirchBarLayoutTest() = default;
BirchBarLayoutTest(const BirchBarLayoutTest&) = delete;
BirchBarLayoutTest& operator=(const BirchBarLayoutTest&) = delete;
~BirchBarLayoutTest() override = default;
// BirchBarTest:
void SetUp() override {
BirchBarTestBase::SetUp();
BirchBarTest::SetUp();
// Clear existing items.
birch_client_->Reset();

@ -30,8 +30,6 @@ static_library("birch") {
"birch_release_notes_provider.h",
"birch_self_share_provider.cc",
"birch_self_share_provider.h",
"birch_weather_v2_provider.cc",
"birch_weather_v2_provider.h",
"refresh_token_waiter.cc",
"refresh_token_waiter.h",
]
@ -53,7 +51,6 @@ static_library("birch") {
"//chrome/browser/sync",
"//chrome/browser/ui/ash/calendar",
"//chrome/common",
"//chromeos/ash/components/geolocation",
"//components/favicon_base",
"//components/history/core/browser",
"//components/prefs",
@ -63,8 +60,6 @@ static_library("birch") {
"//components/sync/service",
"//components/sync_sessions",
"//net/traffic_annotation",
"//services/data_decoder/public/cpp",
"//services/network/public/cpp",
"//ui/base",
"//url",
]
@ -82,7 +77,6 @@ source_set("unit_tests") {
"birch_keyed_service_unittest.cc",
"birch_last_active_provider_unittest.cc",
"birch_most_visited_provider_unittest.cc",
"birch_weather_v2_provider_unittest.cc",
"refresh_token_waiter_unittest.cc",
]
@ -104,7 +98,6 @@ source_set("unit_tests") {
"//chrome/browser/ui/ash/holding_space:test_support",
"//chrome/common",
"//chrome/test:test_support",
"//chromeos/ash/components/geolocation",
"//components/favicon/core/test:test_support",
"//components/prefs",
"//components/send_tab_to_self",
@ -117,9 +110,7 @@ source_set("unit_tests") {
"//components/user_manager",
"//content/test:test_support",
"//net:test_support",
"//services/data_decoder/public/cpp:test_support",
"//services/media_session/public/cpp/test:test_support",
"//services/network:test_support",
"//testing/gmock",
"//testing/gtest",
]

@ -7,7 +7,6 @@
#include <memory>
#include <optional>
#include "ash/birch/birch_item.h"
#include "ash/birch/birch_model.h"
#include "ash/shell.h"
#include "base/functional/bind.h"
@ -22,7 +21,6 @@
#include "chrome/browser/ui/ash/birch/birch_recent_tabs_provider.h"
#include "chrome/browser/ui/ash/birch/birch_release_notes_provider.h"
#include "chrome/browser/ui/ash/birch/birch_self_share_provider.h"
#include "chrome/browser/ui/ash/birch/birch_weather_v2_provider.h"
#include "chrome/browser/ui/ash/birch/refresh_token_waiter.h"
#include "components/favicon/core/favicon_service.h"
#include "components/favicon_base/favicon_types.h"
@ -59,11 +57,6 @@ BirchKeyedService::BirchKeyedService(Profile* profile)
std::make_unique<BirchReleaseNotesProvider>(profile)),
self_share_provider_(std::make_unique<BirchSelfShareProvider>(profile)),
lost_media_provider_(std::make_unique<BirchLostMediaProvider>(profile)),
weather_v2_provider_(std::make_unique<BirchWeatherV2Provider>(
profile,
base::BindRepeating([](std::vector<BirchWeatherItem> items) {
Shell::Get()->birch_model()->SetWeatherItems(std::move(items));
}))),
refresh_token_waiter_(std::make_unique<RefreshTokenWaiter>(profile)) {
calendar_provider_->Initialize();
Shell::Get()->birch_model()->SetClientAndInit(this);
@ -134,10 +127,6 @@ BirchDataProvider* BirchKeyedService::GetLostMediaProvider() {
return lost_media_provider_.get();
}
BirchDataProvider* BirchKeyedService::GetWeatherV2Provider() {
return weather_v2_provider_.get();
}
void BirchKeyedService::WaitForRefreshTokens(base::OnceClosure callback) {
refresh_token_waiter_->Wait(std::move(callback));
}
@ -184,7 +173,6 @@ void BirchKeyedService::ShutdownBirch() {
shell_observation_.Reset();
Shell::Get()->birch_model()->SetClientAndInit(nullptr);
calendar_provider_->Shutdown();
weather_v2_provider_->Shutdown();
}
} // namespace ash

@ -20,12 +20,11 @@ namespace ash {
class BirchCalendarProvider;
class BirchFileSuggestProvider;
class BirchLastActiveProvider;
class BirchLostMediaProvider;
class BirchMostVisitedProvider;
class BirchRecentTabsProvider;
class BirchReleaseNotesProvider;
class BirchSelfShareProvider;
class BirchLostMediaProvider;
class BirchWeatherV2Provider;
class RefreshTokenWaiter;
class Shell;
@ -60,7 +59,6 @@ class BirchKeyedService : public KeyedService,
BirchDataProvider* GetReleaseNotesProvider() override;
BirchDataProvider* GetSelfShareProvider() override;
BirchDataProvider* GetLostMediaProvider() override;
BirchDataProvider* GetWeatherV2Provider() override;
void WaitForRefreshTokens(base::OnceClosure callback) override;
base::FilePath GetRemovedItemsFilePath() override;
@ -123,8 +121,6 @@ class BirchKeyedService : public KeyedService,
std::unique_ptr<BirchLostMediaProvider> lost_media_provider_;
std::unique_ptr<BirchWeatherV2Provider> weather_v2_provider_;
base::ScopedObservation<Shell, ShellObserver> shell_observation_{this};
std::unique_ptr<RefreshTokenWaiter> refresh_token_waiter_;

@ -1,175 +0,0 @@
// Copyright 2024 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/ui/ash/birch/birch_weather_v2_provider.h"
#include <string>
#include "ash/birch/birch_item.h"
#include "ash/birch/birch_model.h"
#include "ash/constants/ash_pref_names.h"
#include "ash/public/cpp/image_downloader.h"
#include "ash/public/cpp/session/session_types.h"
#include "ash/session/session_controller_impl.h"
#include "ash/shell.h"
#include "ash/strings/grit/ash_strings.h"
#include "base/check.h"
#include "base/functional/bind.h"
#include "chrome/browser/profiles/profile.h"
#include "chromeos/ash/components/geolocation/simple_geolocation_provider.h"
#include "components/prefs/pref_service.h"
#include "net/traffic_annotation/network_traffic_annotation.h"
#include "services/data_decoder/public/cpp/data_decoder.h"
#include "services/network/public/cpp/resource_request.h"
#include "services/network/public/cpp/simple_url_loader.h"
#include "ui/base/l10n/l10n_util.h"
#include "url/gurl.h"
namespace ash {
// Components of the chromeossystemui API request URL. Split in two parts so
// the base URL can be overridden in tests.
constexpr char kDefaultBaseUrl[] = "https://chromeossystemui-pa.googleapis.com";
constexpr char kRequestRelativeUrl[] = "/v1/weather?feature_id=1";
constexpr size_t kMaxDownloadBytes = 20 * 1024;
// TODO(b/343206102): The plan for the weather provider is to send location
// information to the weather service - update network
// annotations when that's implemented.
constexpr net::NetworkTrafficAnnotationTag kTrafficAnnotation =
net::DefineNetworkTrafficAnnotation("birch_weather_provider", R"(
semantics {
sender: "Post-login glanceables"
description:
"Fetch current, or forecasted weather information for the user's "
"current location. The weather is used in a suggestion chip button "
"for an activity the user might want to perform after login or "
"from overview mode (e.g. view the weather)."
trigger:
"User logs in to the device or enters overview mode."
data: "None"
user_data: {
type: NONE
}
destination: GOOGLE_OWNED_SERVICE
internal {
contacts {
email: "tbarzic@google.com"
}
contacts {
email: "chromeos-launcher@google.com"
}
}
last_reviewed: "2024-05-30"
}
policy {
cookies_allowed: NO
setting:
"This feature is off by default - guarded by ForestFeature, and "
"BirchWeatherV2 feature flags. If the feature flags are enabled, "
"the feature can be disabled by disabling weather in the context "
"menu on the suggestion chips."
chrome_policy {
ContextualGoogleIntegrationsEnabled {
ContextualGoogleIntegrationsEnabled: false
}
}
})");
BirchWeatherV2Provider::BirchWeatherV2Provider(
Profile* profile,
ModelUpdaterCallback model_updater)
: profile_(profile), model_updater_(model_updater) {
url_loader_factory_ = profile_->GetURLLoaderFactory();
}
BirchWeatherV2Provider::~BirchWeatherV2Provider() = default;
void BirchWeatherV2Provider::RequestBirchDataFetch() {
const auto* const pref_service = profile_->GetPrefs();
if (!pref_service ||
!base::Contains(pref_service->GetList(
prefs::kContextualGoogleIntegrationsConfiguration),
prefs::kWeatherIntegrationName)) {
// Weather integration is disabled by policy.
model_updater_.Run({});
return;
}
if (!SimpleGeolocationProvider::GetInstance()
->IsGeolocationUsageAllowedForSystem()) {
// Weather is not allowed if geolocation is off.
model_updater_.Run({});
return;
}
// Only allow one fetch at a time.
if (is_fetching_) {
return;
}
is_fetching_ = true;
FetchWeather();
}
void BirchWeatherV2Provider::Shutdown() {
url_loader_.reset();
weak_factory_.InvalidateWeakPtrs();
}
void BirchWeatherV2Provider::FetchWeather() {
auto resource_request = std::make_unique<network::ResourceRequest>();
resource_request->method = "GET";
resource_request->url = base_url_override_.value_or(GURL(kDefaultBaseUrl))
.Resolve(kRequestRelativeUrl);
DCHECK(resource_request->url.is_valid());
url_loader_ = network::SimpleURLLoader::Create(std::move(resource_request),
kTrafficAnnotation);
url_loader_->SetRetryOptions(0, network::SimpleURLLoader::RETRY_NEVER);
// Perform the request.
url_loader_->DownloadToString(
url_loader_factory_.get(),
base::BindOnce(&BirchWeatherV2Provider::OnWeatherFetched,
weak_factory_.GetWeakPtr()),
kMaxDownloadBytes);
}
void BirchWeatherV2Provider::OnWeatherFetched(
std::unique_ptr<std::string> json_response) {
if (!json_response) {
is_fetching_ = false;
model_updater_.Run({});
return;
}
data_decoder::DataDecoder::ParseJsonIsolated(
*json_response,
base::BindOnce(&BirchWeatherV2Provider::OnWeatherInfoParsed,
weak_factory_.GetWeakPtr()));
}
void BirchWeatherV2Provider::OnWeatherInfoParsed(
base::expected<base::Value, std::string> weather_info) {
is_fetching_ = false;
if (!weather_info.has_value() || !weather_info->is_dict()) {
model_updater_.Run({});
return;
}
std::optional<double> temp_f = weather_info->GetDict().FindDouble("tempF");
if (!temp_f) {
model_updater_.Run({});
return;
}
std::vector<BirchWeatherItem> items;
items.emplace_back(u"[i18n] Current weather", temp_f.value(),
ui::ImageModel());
model_updater_.Run(std::move(items));
}
} // namespace ash

@ -1,87 +0,0 @@
// Copyright 2024 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROME_BROWSER_UI_ASH_BIRCH_BIRCH_WEATHER_V2_PROVIDER_H_
#define CHROME_BROWSER_UI_ASH_BIRCH_BIRCH_WEATHER_V2_PROVIDER_H_
#include <optional>
#include "ash/ash_export.h"
#include "ash/birch/birch_data_provider.h"
#include "base/memory/weak_ptr.h"
#include "base/time/time.h"
#include "base/types/expected.h"
#include "services/network/public/cpp/shared_url_loader_factory.h"
#include "url/gurl.h"
class Profile;
namespace base {
class Value;
}
namespace network {
class SimpleURLLoader;
}
namespace ash {
class BirchWeatherItem;
// Birch weather provider that fetches weather information using
// chromeossystemui server.
class ASH_EXPORT BirchWeatherV2Provider : public BirchDataProvider {
public:
using ModelUpdaterCallback =
base::RepeatingCallback<void(std::vector<BirchWeatherItem> items)>;
BirchWeatherV2Provider(Profile* profile, ModelUpdaterCallback model_updater);
BirchWeatherV2Provider(const BirchWeatherV2Provider&) = delete;
BirchWeatherV2Provider& operator=(const BirchWeatherV2Provider&) = delete;
~BirchWeatherV2Provider() override;
// Called from birch model to request weather information to be displayed in
// UI.
void RequestBirchDataFetch() override;
void Shutdown();
void OverrideBaseRequestUrlForTesting(const GURL& base_url) {
base_url_override_ = base_url;
}
private:
// Starts the weather fetch.
void FetchWeather();
// Called in response to the weather info HTTP request. `json_response`
// contains the response with the weather info, or nullptr if the request
// fails.
void OnWeatherFetched(std::unique_ptr<std::string> json_response);
// Callback to the request to parse the weather info response JSON.
void OnWeatherInfoParsed(
base::expected<base::Value, std::string> weather_info);
const raw_ptr<Profile> profile_;
// Callback called when the weather info is fetched, and parsed. Expected
// to update weather items in the birch model. It will get called with an
// empty list of weather items if the request fails.
const ModelUpdaterCallback model_updater_;
// Whether a weather information fetch is currently in progress.
bool is_fetching_ = false;
// Used to override the base chromeos-system-ui server base URL.
std::optional<GURL> base_url_override_;
scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory_;
std::unique_ptr<network::SimpleURLLoader> url_loader_;
base::WeakPtrFactory<BirchWeatherV2Provider> weak_factory_{this};
};
} // namespace ash
#endif // CHROME_BROWSER_UI_ASH_BIRCH_BIRCH_WEATHER_V2_PROVIDER_H_

@ -1,415 +0,0 @@
// Copyright 2024 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/ui/ash/birch/birch_weather_v2_provider.h"
#include <memory>
#include <vector>
#include "ash/birch/birch_model.h"
#include "ash/constants/ash_pref_names.h"
#include "ash/shell.h"
#include "ash/system/geolocation/test_geolocation_url_loader_factory.h"
#include "base/test/scoped_feature_list.h"
#include "base/test/test_future.h"
#include "chrome/test/base/testing_browser_process.h"
#include "chrome/test/base/testing_profile.h"
#include "chrome/test/base/testing_profile_manager.h"
#include "chromeos/ash/components/geolocation/simple_geolocation_provider.h"
#include "components/prefs/pref_service.h"
#include "components/sync_preferences/testing_pref_service_syncable.h"
#include "content/public/test/browser_task_environment.h"
#include "net/test/embedded_test_server/embedded_test_server.h"
#include "net/test/embedded_test_server/http_request.h"
#include "net/test/embedded_test_server/http_response.h"
#include "services/data_decoder/public/cpp/test_support/in_process_data_decoder.h"
#include "services/network/test/test_shared_url_loader_factory.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace ash {
using ::base::test::TestFuture;
using ::net::test_server::BasicHttpResponse;
using ::net::test_server::HttpMethod;
using ::net::test_server::HttpRequest;
using ::net::test_server::HttpResponse;
using ::testing::AllOf;
using ::testing::ByMove;
using ::testing::Field;
using ::testing::Invoke;
using ::testing::Return;
// Helper class to simplify mocking `net::EmbeddedTestServer` responses,
// especially useful for subsequent responses when testing pagination logic.
class TestRequestHandler {
public:
static std::unique_ptr<HttpResponse> CreateSuccessfulResponse(
const std::string& content) {
auto response = std::make_unique<BasicHttpResponse>();
response->set_code(net::HTTP_OK);
response->set_content(content);
response->set_content_type("application/json");
return response;
}
static std::unique_ptr<HttpResponse> CreateFailedResponse() {
auto response = std::make_unique<BasicHttpResponse>();
response->set_code(net::HTTP_INTERNAL_SERVER_ERROR);
return response;
}
MOCK_METHOD(std::unique_ptr<HttpResponse>,
HandleRequest,
(const HttpRequest&));
};
class BirchWeatherV2ProviderTest : public testing::Test {
public:
BirchWeatherV2ProviderTest()
: profile_manager_(
TestingProfileManager(TestingBrowserProcess::GetGlobal())) {}
void SetUp() override {
ASSERT_TRUE(profile_manager_.SetUp());
SimpleGeolocationProvider::Initialize(
base::MakeRefCounted<TestGeolocationUrlLoaderFactory>());
profile_ = profile_manager_.CreateTestingProfile("profile@example.com",
/*is_main_profile=*/true,
url_loader_factory_);
weather_provider_ = std::make_unique<BirchWeatherV2Provider>(
profile_,
base::BindRepeating(&BirchWeatherV2ProviderTest::WeatherItemsUpdated,
base::Unretained(this)));
test_server_.RegisterRequestHandler(
base::BindRepeating(&TestRequestHandler::HandleRequest,
base::Unretained(&request_handler_)));
ASSERT_TRUE(test_server_.Start());
weather_provider_->OverrideBaseRequestUrlForTesting(
test_server_.base_url());
}
void TearDown() override { SimpleGeolocationProvider::DestroyForTesting(); }
using ItemsCallback = base::OnceCallback<void(std::vector<BirchWeatherItem>)>;
void SetItemsCallback(ItemsCallback callback) {
items_callback_ = std::move(callback);
}
TestRequestHandler& request_handler() { return request_handler_; }
BirchWeatherV2Provider* weather_provider() { return weather_provider_.get(); }
PrefService* GetPrefService() { return profile_->GetTestingPrefService(); }
private:
void WeatherItemsUpdated(std::vector<BirchWeatherItem> items) {
if (items_callback_) {
std::move(items_callback_).Run(std::move(items));
}
}
content::BrowserTaskEnvironment task_environment_{
base::test::TaskEnvironment::MainThreadType::IO};
TestingProfileManager profile_manager_;
net::EmbeddedTestServer test_server_;
scoped_refptr<network::TestSharedURLLoaderFactory> url_loader_factory_ =
base::MakeRefCounted<network::TestSharedURLLoaderFactory>(
/*network_service=*/nullptr,
/*is_trusted=*/true);
testing::StrictMock<TestRequestHandler> request_handler_;
data_decoder::test::InProcessDataDecoder data_decoder_;
std::unique_ptr<BirchWeatherV2Provider> weather_provider_;
ItemsCallback items_callback_;
raw_ptr<TestingProfile> profile_;
};
TEST_F(BirchWeatherV2ProviderTest, WeatherWithTemp) {
EXPECT_CALL(request_handler(),
HandleRequest(Field(&HttpRequest::relative_url,
"/v1/weather?feature_id=1")))
.WillOnce(Return(ByMove(
TestRequestHandler::CreateSuccessfulResponse(R"({"tempF": 70})"))));
TestFuture<std::vector<BirchWeatherItem>> items_future;
SetItemsCallback(items_future.GetCallback());
weather_provider()->RequestBirchDataFetch();
ASSERT_TRUE(items_future.Wait());
auto weather_items = items_future.Take();
ASSERT_EQ(1u, weather_items.size());
EXPECT_EQ(u"[i18n] Current weather", weather_items[0].title());
EXPECT_FLOAT_EQ(70.f, weather_items[0].temp_f());
}
TEST_F(BirchWeatherV2ProviderTest, WeatherWithNonIntegerTemp) {
EXPECT_CALL(request_handler(),
HandleRequest(Field(&HttpRequest::relative_url,
"/v1/weather?feature_id=1")))
.WillOnce(Return(ByMove(
TestRequestHandler::CreateSuccessfulResponse(R"({"tempF": 71.3})"))));
TestFuture<std::vector<BirchWeatherItem>> items_future;
SetItemsCallback(items_future.GetCallback());
weather_provider()->RequestBirchDataFetch();
ASSERT_TRUE(items_future.Wait());
auto weather_items = items_future.Take();
ASSERT_EQ(1u, weather_items.size());
EXPECT_EQ(u"[i18n] Current weather", weather_items[0].title());
EXPECT_EQ(71.3f, weather_items[0].temp_f());
}
TEST_F(BirchWeatherV2ProviderTest, ConcurrentRequests) {
EXPECT_CALL(request_handler(),
HandleRequest(Field(&HttpRequest::relative_url,
"/v1/weather?feature_id=1")))
.WillOnce(Return(ByMove(
TestRequestHandler::CreateSuccessfulResponse(R"({"tempF": 70})"))));
TestFuture<std::vector<BirchWeatherItem>> items_future;
SetItemsCallback(items_future.GetCallback());
weather_provider()->RequestBirchDataFetch();
weather_provider()->RequestBirchDataFetch();
ASSERT_TRUE(items_future.Wait());
auto weather_items = items_future.Take();
ASSERT_EQ(1u, weather_items.size());
EXPECT_EQ(u"[i18n] Current weather", weather_items[0].title());
EXPECT_FLOAT_EQ(70.f, weather_items[0].temp_f());
}
TEST_F(BirchWeatherV2ProviderTest, SequentialRequests) {
EXPECT_CALL(request_handler(),
HandleRequest(Field(&HttpRequest::relative_url,
"/v1/weather?feature_id=1")))
.WillOnce(Return(ByMove(
TestRequestHandler::CreateSuccessfulResponse(R"({"tempF": 70})"))))
.WillOnce(Return(ByMove(
TestRequestHandler::CreateSuccessfulResponse(R"({"tempF": 71})"))));
TestFuture<std::vector<BirchWeatherItem>> items_future;
SetItemsCallback(items_future.GetCallback());
weather_provider()->RequestBirchDataFetch();
ASSERT_TRUE(items_future.Wait());
auto weather_items = items_future.Take();
ASSERT_EQ(1u, weather_items.size());
EXPECT_EQ(u"[i18n] Current weather", weather_items[0].title());
EXPECT_FLOAT_EQ(70.f, weather_items[0].temp_f());
TestFuture<std::vector<BirchWeatherItem>> second_items_future;
SetItemsCallback(second_items_future.GetCallback());
weather_provider()->RequestBirchDataFetch();
ASSERT_TRUE(second_items_future.Wait());
weather_items = second_items_future.Take();
ASSERT_EQ(1u, weather_items.size());
EXPECT_EQ(u"[i18n] Current weather", weather_items[0].title());
EXPECT_FLOAT_EQ(71.f, weather_items[0].temp_f());
}
TEST_F(BirchWeatherV2ProviderTest, FailedRequest) {
EXPECT_CALL(request_handler(),
HandleRequest(Field(&HttpRequest::relative_url,
"/v1/weather?feature_id=1")))
.WillOnce(Return(ByMove(TestRequestHandler::CreateFailedResponse())));
TestFuture<std::vector<BirchWeatherItem>> items_future;
SetItemsCallback(items_future.GetCallback());
weather_provider()->RequestBirchDataFetch();
ASSERT_TRUE(items_future.Wait());
auto weather_items = items_future.Take();
EXPECT_EQ(0u, weather_items.size());
}
TEST_F(BirchWeatherV2ProviderTest, InvalidResponse) {
EXPECT_CALL(request_handler(),
HandleRequest(Field(&HttpRequest::relative_url,
"/v1/weather?feature_id=1")))
.WillOnce(Return(
ByMove(TestRequestHandler::CreateSuccessfulResponse("}{----!~"))));
TestFuture<std::vector<BirchWeatherItem>> items_future;
SetItemsCallback(items_future.GetCallback());
weather_provider()->RequestBirchDataFetch();
ASSERT_TRUE(items_future.Wait());
auto weather_items = items_future.Take();
EXPECT_EQ(0u, weather_items.size());
}
TEST_F(BirchWeatherV2ProviderTest, UnexpectedResponse_List) {
EXPECT_CALL(request_handler(),
HandleRequest(Field(&HttpRequest::relative_url,
"/v1/weather?feature_id=1")))
.WillOnce(Return(ByMove(
TestRequestHandler::CreateSuccessfulResponse(R"([{"tempF": 3}])"))));
TestFuture<std::vector<BirchWeatherItem>> items_future;
SetItemsCallback(items_future.GetCallback());
weather_provider()->RequestBirchDataFetch();
ASSERT_TRUE(items_future.Wait());
auto weather_items = items_future.Take();
EXPECT_EQ(0u, weather_items.size());
}
TEST_F(BirchWeatherV2ProviderTest, UnexpectedResponse_Integer) {
EXPECT_CALL(request_handler(),
HandleRequest(Field(&HttpRequest::relative_url,
"/v1/weather?feature_id=1")))
.WillOnce(
Return(ByMove(TestRequestHandler::CreateSuccessfulResponse("404"))));
TestFuture<std::vector<BirchWeatherItem>> items_future;
SetItemsCallback(items_future.GetCallback());
weather_provider()->RequestBirchDataFetch();
ASSERT_TRUE(items_future.Wait());
auto weather_items = items_future.Take();
EXPECT_EQ(0u, weather_items.size());
}
TEST_F(BirchWeatherV2ProviderTest, UnexpectedResponse_EmptyDict) {
EXPECT_CALL(request_handler(),
HandleRequest(Field(&HttpRequest::relative_url,
"/v1/weather?feature_id=1")))
.WillOnce(
Return(ByMove(TestRequestHandler::CreateSuccessfulResponse("{}"))));
TestFuture<std::vector<BirchWeatherItem>> items_future;
SetItemsCallback(items_future.GetCallback());
weather_provider()->RequestBirchDataFetch();
ASSERT_TRUE(items_future.Wait());
auto weather_items = items_future.Take();
EXPECT_EQ(0u, weather_items.size());
}
TEST_F(BirchWeatherV2ProviderTest, GeolocationDisabled) {
EXPECT_CALL(request_handler(),
HandleRequest(Field(&HttpRequest::relative_url,
"/v1/weather?feature_id=1")))
.Times(0);
// Disable geolocation.
SimpleGeolocationProvider::GetInstance()->SetGeolocationAccessLevel(
GeolocationAccessLevel::kDisallowed);
TestFuture<std::vector<BirchWeatherItem>> items_future;
SetItemsCallback(items_future.GetCallback());
weather_provider()->RequestBirchDataFetch();
ASSERT_TRUE(items_future.Wait());
auto weather_items = items_future.Take();
EXPECT_EQ(0u, weather_items.size());
}
TEST_F(BirchWeatherV2ProviderTest, DisabledByPolicy) {
EXPECT_CALL(request_handler(),
HandleRequest(Field(&HttpRequest::relative_url,
"/v1/weather?feature_id=1")))
.Times(0);
// Disable by policy.
GetPrefService()->SetList(prefs::kContextualGoogleIntegrationsConfiguration,
{});
TestFuture<std::vector<BirchWeatherItem>> items_future;
SetItemsCallback(items_future.GetCallback());
weather_provider()->RequestBirchDataFetch();
ASSERT_TRUE(items_future.Wait());
auto weather_items = items_future.Take();
EXPECT_EQ(0u, weather_items.size());
}
TEST_F(BirchWeatherV2ProviderTest, FailedRequestWithSuccessfulRetry) {
EXPECT_CALL(request_handler(),
HandleRequest(Field(&HttpRequest::relative_url,
"/v1/weather?feature_id=1")))
.WillOnce(Return(ByMove(TestRequestHandler::CreateFailedResponse())))
.WillOnce(Return(ByMove(
TestRequestHandler::CreateSuccessfulResponse(R"({"tempF": 71})"))));
TestFuture<std::vector<BirchWeatherItem>> items_future;
SetItemsCallback(items_future.GetCallback());
weather_provider()->RequestBirchDataFetch();
ASSERT_TRUE(items_future.Wait());
auto weather_items = items_future.Take();
EXPECT_EQ(0u, weather_items.size());
TestFuture<std::vector<BirchWeatherItem>> second_items_future;
SetItemsCallback(second_items_future.GetCallback());
weather_provider()->RequestBirchDataFetch();
ASSERT_TRUE(second_items_future.Wait());
weather_items = second_items_future.Take();
ASSERT_EQ(1u, weather_items.size());
EXPECT_EQ(u"[i18n] Current weather", weather_items[0].title());
EXPECT_FLOAT_EQ(71.f, weather_items[0].temp_f());
}
TEST_F(BirchWeatherV2ProviderTest, ImmediateProviderShutdownCancelsRequest) {
base::RunLoop request_waiter;
EXPECT_CALL(request_handler(),
HandleRequest(Field(&HttpRequest::relative_url,
"/v1/weather?feature_id=1")))
.Times(0);
TestFuture<std::vector<BirchWeatherItem>> items_future;
SetItemsCallback(base::BindOnce([](std::vector<BirchWeatherItem> items) {
ADD_FAILURE() << "Model updated unexpecstedly after shutdown";
}));
weather_provider()->RequestBirchDataFetch();
weather_provider()->Shutdown();
// Flush any tasks potentaly started asynchronously by the provider .
base::RunLoop().RunUntilIdle();
}
TEST_F(BirchWeatherV2ProviderTest, ProviderShutdownMidRequest) {
base::RunLoop request_waiter;
EXPECT_CALL(request_handler(),
HandleRequest(Field(&HttpRequest::relative_url,
"/v1/weather?feature_id=1")))
.WillOnce(Invoke([&](const HttpRequest& request) {
request_waiter.Quit();
return TestRequestHandler::CreateSuccessfulResponse(R"({"tempF": 71})");
}));
TestFuture<std::vector<BirchWeatherItem>> items_future;
SetItemsCallback(base::BindOnce([](std::vector<BirchWeatherItem> items) {
ADD_FAILURE() << "Model updated unexpecstedly after shutdown";
}));
weather_provider()->RequestBirchDataFetch();
// Wait to make sure that the request gets processed.
request_waiter.Run();
weather_provider()->Shutdown();
// Flush any tasks potentaly started asynchronously by the provider .
base::RunLoop().RunUntilIdle();
}
} // namespace ash

@ -450,7 +450,6 @@ Refer to README.md for content description and update process.
<item id="remoting_corp_session_reauthorize_host" added_in_milestone="123" content_hash_code="0731c945" os_list="linux,windows,android,chromeos" file_path="remoting/base/corp_session_authz_service_client.cc" />
<item id="weather_icon" added_in_milestone="123" content_hash_code="07b4f4c1" os_list="chromeos" file_path="ash/birch/birch_weather_provider.cc" />
<item id="birch_calendar_provider" added_in_milestone="124" content_hash_code="00ad7833" os_list="chromeos" file_path="chrome/browser/ui/ash/birch/birch_calendar_fetcher.cc" />
<item id="birch_weather_provider" added_in_milestone="127" content_hash_code="0091655e" os_list="chromeos" file_path="chrome/browser/ui/ash/birch/birch_weather_v2_provider.cc" />
<item id="recovery_key_store_fetch" added_in_milestone="124" content_hash_code="05d9dc45" os_list="linux,windows,chromeos" file_path="chrome/browser/webauthn/enclave_manager.cc" />
<item id="product_specifications_fetcher" added_in_milestone="123" content_hash_code="050058ef" os_list="linux,windows,android,chromeos" file_path="components/commerce/core/compare/product_specifications_server_proxy.cc" />
<item id="enterprise_logo_fetcher" added_in_milestone="124" content_hash_code="000f6a7b" os_list="linux,windows,android,chromeos" file_path="chrome/browser/enterprise/browser_management/browser_management_service.cc" />

@ -310,7 +310,6 @@ after discussions on the right group.
<annotation id="remoting_corp_session_reauthorize_host"/>
<annotation id="weather_icon"/>
<annotation id="birch_calendar_provider"/>
<annotation id="birch_weather_provider"/>
<annotation id="recovery_key_store_fetch"/>
<annotation id="enterprise_logo_fetcher"/>
<annotation id="remoting_corp_logging_report_session_disconnected"/>