Commit 084e02fe authored by Caroline Rising's avatar Caroline Rising Committed by Commit Bot

Migrate visible extensions to pinned extensions in the ExtensionsToolbarContainer.

Bug: 1041919
Change-Id: Icbdb857215141367764738a03064a180ff8abd0a
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2001402
Commit-Queue: Caroline Rising <corising@chromium.org>
Reviewed-by: default avatarDevlin <rdevlin.cronin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#737407}
parent 7cf93613
...@@ -493,6 +493,14 @@ void ToolbarActionsModel::InitializeActionList() { ...@@ -493,6 +493,14 @@ void ToolbarActionsModel::InitializeActionList() {
Populate(); Populate();
if (base::FeatureList::IsEnabled(features::kExtensionsToolbarMenu)) { if (base::FeatureList::IsEnabled(features::kExtensionsToolbarMenu)) {
if (!extension_prefs_->IsPinnedExtensionsMigrationComplete() &&
!profile_->IsOffTheRecord()) {
// Migrate extensions visible in the toolbar to pinned extensions.
auto new_pinned_action_ids = std::vector<ActionId>(
action_ids_.begin(), action_ids_.begin() + visible_icon_count());
extension_prefs_->SetPinnedExtensions(new_pinned_action_ids);
extension_prefs_->MarkPinnedExtensionsMigrationComplete();
}
// Set |pinned_action_ids_| directly to avoid notifying observers that they // Set |pinned_action_ids_| directly to avoid notifying observers that they
// have changed even though they haven't. // have changed even though they haven't.
pinned_action_ids_ = GetFilteredPinnedActionIds(); pinned_action_ids_ = GetFilteredPinnedActionIds();
......
...@@ -145,6 +145,8 @@ class ToolbarActionsModelUnitTest ...@@ -145,6 +145,8 @@ class ToolbarActionsModelUnitTest
// Initialize the ExtensionService, ToolbarActionsModel, and ExtensionSystem. // Initialize the ExtensionService, ToolbarActionsModel, and ExtensionSystem.
void Init(); void Init();
void InitToolbarModelAndObserver();
void TearDown() override; void TearDown() override;
// Adds or removes the given |extension| and verify success. // Adds or removes the given |extension| and verify success.
...@@ -225,6 +227,10 @@ class ToolbarActionsModelUnitTest ...@@ -225,6 +227,10 @@ class ToolbarActionsModelUnitTest
void ToolbarActionsModelUnitTest::Init() { void ToolbarActionsModelUnitTest::Init() {
InitializeEmptyExtensionService(); InitializeEmptyExtensionService();
InitToolbarModelAndObserver();
}
void ToolbarActionsModelUnitTest::InitToolbarModelAndObserver() {
toolbar_model_ = toolbar_model_ =
extensions::extension_action_test_util::CreateToolbarModelForProfile( extensions::extension_action_test_util::CreateToolbarModelForProfile(
profile()); profile());
...@@ -1483,3 +1489,47 @@ TEST_F(ToolbarActionsModelUnitTest, ChangesToPinnedOrderSavedInExtensionPrefs) { ...@@ -1483,3 +1489,47 @@ TEST_F(ToolbarActionsModelUnitTest, ChangesToPinnedOrderSavedInExtensionPrefs) {
testing::ElementsAre(browser_action_a()->id(), browser_action_c()->id(), testing::ElementsAre(browser_action_a()->id(), browser_action_c()->id(),
browser_action_b()->id())); browser_action_b()->id()));
} }
TEST_F(ToolbarActionsModelUnitTest,
VisibleExtensionsMigrateToPinnedExtensions) {
InitializeEmptyExtensionService();
// Add the three browser action extensions.
ASSERT_TRUE(AddBrowserActionExtensions());
base::test::ScopedFeatureList feature_list;
feature_list.InitAndEnableFeature(features::kExtensionsToolbarMenu);
// Initialization of the toolbar model triggers migration of the visible
// extensions to pinned extensions.
InitToolbarModelAndObserver();
// Verify that the extensions that were visible are now the pinned extensions.
extensions::ExtensionPrefs* const extension_prefs =
extensions::ExtensionPrefs::Get(profile());
EXPECT_THAT(
extension_prefs->GetPinnedExtensions(),
testing::ElementsAre(browser_action_a()->id(), browser_action_b()->id(),
browser_action_c()->id()));
}
TEST_F(ToolbarActionsModelUnitTest,
VisibleExtensionsOfConstrainedToolbarMigrateToPinnedExtensions) {
InitializeEmptyExtensionService();
profile()->GetPrefs()->SetInteger(extensions::pref_names::kToolbarSize, 2);
// Add the three browser action extensions.
ASSERT_TRUE(AddBrowserActionExtensions());
base::test::ScopedFeatureList feature_list;
feature_list.InitAndEnableFeature(features::kExtensionsToolbarMenu);
// Initialization of the toolbar model triggers migration of the visible
// extensions to pinned extensions.
InitToolbarModelAndObserver();
// Verify that the extensions that were visible are now the pinned extensions.
extensions::ExtensionPrefs* const extension_prefs =
extensions::ExtensionPrefs::Get(profile());
EXPECT_THAT(
extension_prefs->GetPinnedExtensions(),
testing::ElementsAre(browser_action_a()->id(), browser_action_b()->id()));
}
...@@ -751,6 +751,14 @@ bool ExtensionPrefs::SetAlertSystemFirstRun() { ...@@ -751,6 +751,14 @@ bool ExtensionPrefs::SetAlertSystemFirstRun() {
return g_run_alerts_in_first_run_for_testing; // Note: normally false. return g_run_alerts_in_first_run_for_testing; // Note: normally false.
} }
bool ExtensionPrefs::IsPinnedExtensionsMigrationComplete() {
return prefs_->GetBoolean(pref_names::kPinnedExtensionsMigrationComplete);
}
void ExtensionPrefs::MarkPinnedExtensionsMigrationComplete() {
prefs_->SetBoolean(pref_names::kPinnedExtensionsMigrationComplete, true);
}
bool ExtensionPrefs::DidExtensionEscalatePermissions( bool ExtensionPrefs::DidExtensionEscalatePermissions(
const std::string& extension_id) const { const std::string& extension_id) const {
return HasDisableReason(extension_id, return HasDisableReason(extension_id,
...@@ -1920,6 +1928,8 @@ void ExtensionPrefs::RegisterProfilePrefs( ...@@ -1920,6 +1928,8 @@ void ExtensionPrefs::RegisterProfilePrefs(
registry->RegisterListPref(pref_names::kPinnedExtensions, registry->RegisterListPref(pref_names::kPinnedExtensions,
user_prefs::PrefRegistrySyncable::SYNCABLE_PREF); user_prefs::PrefRegistrySyncable::SYNCABLE_PREF);
registry->RegisterIntegerPref(pref_names::kToolbarSize, -1); registry->RegisterIntegerPref(pref_names::kToolbarSize, -1);
registry->RegisterBooleanPref(pref_names::kPinnedExtensionsMigrationComplete,
false);
registry->RegisterDictionaryPref(kExtensionsBlacklistUpdate); registry->RegisterDictionaryPref(kExtensionsBlacklistUpdate);
registry->RegisterListPref(pref_names::kInstallAllowList); registry->RegisterListPref(pref_names::kInstallAllowList);
registry->RegisterListPref(pref_names::kInstallDenyList); registry->RegisterListPref(pref_names::kInstallDenyList);
......
...@@ -349,6 +349,12 @@ class ExtensionPrefs : public KeyedService { ...@@ -349,6 +349,12 @@ class ExtensionPrefs : public KeyedService {
// reset it. Don't call it unless you mean it! // reset it. Don't call it unless you mean it!
bool SetAlertSystemFirstRun(); bool SetAlertSystemFirstRun();
// Whether extensions that were previously visible in the toolbar from
// |BrowserActionsContainer| have been migrated to pinned extensions in the
// |ExtensionsToolbarContainer|.
bool IsPinnedExtensionsMigrationComplete();
void MarkPinnedExtensionsMigrationComplete();
// Returns the last value set via SetLastPingDay. If there isn't such a // Returns the last value set via SetLastPingDay. If there isn't such a
// pref, the returned Time will return true for is_null(). // pref, the returned Time will return true for is_null().
base::Time LastPingDay(const std::string& extension_id) const; base::Time LastPingDay(const std::string& extension_id) const;
......
...@@ -49,6 +49,8 @@ const char kPinnedExtensions[] = "extensions.pinned_extensions"; ...@@ -49,6 +49,8 @@ const char kPinnedExtensions[] = "extensions.pinned_extensions";
const char kStorageGarbageCollect[] = "extensions.storage.garbagecollect"; const char kStorageGarbageCollect[] = "extensions.storage.garbagecollect";
const char kToolbar[] = "extensions.toolbar"; const char kToolbar[] = "extensions.toolbar";
const char kToolbarSize[] = "extensions.toolbarsize"; const char kToolbarSize[] = "extensions.toolbarsize";
const char kPinnedExtensionsMigrationComplete[] =
"extensions.pinned_extension_migration";
const char kPrefPreferences[] = "preferences"; const char kPrefPreferences[] = "preferences";
const char kPrefIncognitoPreferences[] = "incognito_preferences"; const char kPrefIncognitoPreferences[] = "incognito_preferences";
......
...@@ -110,6 +110,10 @@ extern const char kToolbar[]; ...@@ -110,6 +110,10 @@ extern const char kToolbar[];
// actions toolbar. // actions toolbar.
extern const char kToolbarSize[]; extern const char kToolbarSize[];
// Indicates whether extensions have been migrated from BrowserActionsContainer
// to the ExtensionsToolbarContainer.
extern const char kPinnedExtensionsMigrationComplete[];
// Properties in kExtensions dictionaries -------------------------------------- // Properties in kExtensions dictionaries --------------------------------------
// Extension-controlled preferences. // Extension-controlled preferences.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment