Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(42)

Side by Side Diff: chrome/browser/extensions/extension_service_unittest.cc

Issue 1240573012: Extension syncing: Introduce a NeedsSync pref (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@ext_sync_uninstall
Patch Set: Created 5 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include <algorithm> 5 #include <algorithm>
6 #include <set> 6 #include <set>
7 #include <vector> 7 #include <vector>
8 8
9 #include "base/at_exit.h" 9 #include "base/at_exit.h"
10 #include "base/basictypes.h" 10 #include "base/basictypes.h"
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
65 #include "chrome/browser/policy/profile_policy_connector.h" 65 #include "chrome/browser/policy/profile_policy_connector.h"
66 #include "chrome/browser/policy/profile_policy_connector_factory.h" 66 #include "chrome/browser/policy/profile_policy_connector_factory.h"
67 #include "chrome/browser/prefs/pref_service_syncable.h" 67 #include "chrome/browser/prefs/pref_service_syncable.h"
68 #include "chrome/browser/sync/profile_sync_service.h" 68 #include "chrome/browser/sync/profile_sync_service.h"
69 #include "chrome/browser/sync/profile_sync_service_factory.h" 69 #include "chrome/browser/sync/profile_sync_service_factory.h"
70 #include "chrome/common/chrome_constants.h" 70 #include "chrome/common/chrome_constants.h"
71 #include "chrome/common/chrome_switches.h" 71 #include "chrome/common/chrome_switches.h"
72 #include "chrome/common/extensions/api/plugins/plugins_handler.h" 72 #include "chrome/common/extensions/api/plugins/plugins_handler.h"
73 #include "chrome/common/extensions/manifest_handlers/app_launch_info.h" 73 #include "chrome/common/extensions/manifest_handlers/app_launch_info.h"
74 #include "chrome/common/extensions/manifest_handlers/content_scripts_handler.h" 74 #include "chrome/common/extensions/manifest_handlers/content_scripts_handler.h"
75 #include "chrome/common/extensions/sync_helper.h"
75 #include "chrome/common/pref_names.h" 76 #include "chrome/common/pref_names.h"
76 #include "chrome/common/url_constants.h" 77 #include "chrome/common/url_constants.h"
77 #include "chrome/test/base/scoped_browser_locale.h" 78 #include "chrome/test/base/scoped_browser_locale.h"
78 #include "chrome/test/base/testing_pref_service_syncable.h" 79 #include "chrome/test/base/testing_pref_service_syncable.h"
79 #include "chrome/test/base/testing_profile.h" 80 #include "chrome/test/base/testing_profile.h"
80 #include "components/crx_file/id_util.h" 81 #include "components/crx_file/id_util.h"
81 #include "components/pref_registry/pref_registry_syncable.h" 82 #include "components/pref_registry/pref_registry_syncable.h"
82 #include "content/public/browser/dom_storage_context.h" 83 #include "content/public/browser/dom_storage_context.h"
83 #include "content/public/browser/gpu_data_manager.h" 84 #include "content/public/browser/gpu_data_manager.h"
84 #include "content/public/browser/indexed_db_context.h" 85 #include "content/public/browser/indexed_db_context.h"
(...skipping 5829 matching lines...) Expand 10 before | Expand all | Expand 10 after
5914 sync_data.push_back(disable_good_crx.GetSyncData()); 5915 sync_data.push_back(disable_good_crx.GetSyncData());
5915 extension_sync_service()->MergeDataAndStartSyncing( 5916 extension_sync_service()->MergeDataAndStartSyncing(
5916 syncer::EXTENSIONS, 5917 syncer::EXTENSIONS,
5917 sync_data, 5918 sync_data,
5918 scoped_ptr<syncer::SyncChangeProcessor>( 5919 scoped_ptr<syncer::SyncChangeProcessor>(
5919 new syncer::FakeSyncChangeProcessor), 5920 new syncer::FakeSyncChangeProcessor),
5920 scoped_ptr<syncer::SyncErrorFactory>(new syncer::SyncErrorFactoryMock())); 5921 scoped_ptr<syncer::SyncErrorFactory>(new syncer::SyncErrorFactoryMock()));
5921 ASSERT_FALSE(service()->IsExtensionEnabled(good0)); 5922 ASSERT_FALSE(service()->IsExtensionEnabled(good0));
5922 } 5923 }
5923 5924
5924 TEST_F(ExtensionServiceTest, DontDisableExtensionWithPendingEnableFromSync) { 5925 TEST_F(ExtensionServiceTest, IgnoreSyncChangesWhenLocalStateIsMoreRecent) {
5925 // Start the extensions service with one external extension already installed. 5926 // Start the extension service with three extensions already installed.
5926 base::FilePath source_install_dir = 5927 base::FilePath source_install_dir =
5927 data_dir().AppendASCII("good").AppendASCII("Extensions"); 5928 data_dir().AppendASCII("good").AppendASCII("Extensions");
5928 base::FilePath pref_path = 5929 base::FilePath pref_path =
5929 source_install_dir.DirName().Append(chrome::kPreferencesFilename); 5930 source_install_dir.DirName().Append(chrome::kPreferencesFilename);
5930 5931
5931 InitializeInstalledExtensionService(pref_path, source_install_dir); 5932 InitializeInstalledExtensionService(pref_path, source_install_dir);
5932 InitializeExtensionSyncService(); 5933 InitializeExtensionSyncService();
5933 5934
5934 // The user has enabled sync. 5935 // The user has enabled sync.
5935 ProfileSyncService* sync_service = 5936 ProfileSyncService* sync_service =
5936 ProfileSyncServiceFactory::GetForProfile(profile()); 5937 ProfileSyncServiceFactory::GetForProfile(profile());
5937 sync_service->SetSyncSetupCompleted(); 5938 sync_service->SetSyncSetupCompleted();
5938 5939
5939 service()->Init(); 5940 service()->Init();
5940 ASSERT_TRUE(service()->is_ready()); 5941 ASSERT_TRUE(service()->is_ready());
5941 ASSERT_EQ(3u, loaded_.size()); 5942 ASSERT_EQ(3u, loaded_.size());
5942 5943
5943 const Extension* extension = service()->GetExtensionById(good0, true);
5944 ASSERT_TRUE(service()->IsExtensionEnabled(good0)); 5944 ASSERT_TRUE(service()->IsExtensionEnabled(good0));
5945 ASSERT_TRUE(service()->IsExtensionEnabled(good2));
5945 5946
5946 // Disable extension before first sync data arrives. 5947 // Disable and re-enable good0 before first sync data arrives.
5947 service()->DisableExtension(good0, Extension::DISABLE_USER_ACTION); 5948 service()->DisableExtension(good0, Extension::DISABLE_USER_ACTION);
5948 ASSERT_FALSE(service()->IsExtensionEnabled(good0)); 5949 ASSERT_FALSE(service()->IsExtensionEnabled(good0));
5949
5950 // Enable extension - this is now the most recent state.
5951 service()->EnableExtension(good0); 5950 service()->EnableExtension(good0);
5952 ASSERT_TRUE(service()->IsExtensionEnabled(good0)); 5951 ASSERT_TRUE(service()->IsExtensionEnabled(good0));
5952 // Disable good2 before first sync data arrives (good1 is considered
5953 // non-syncable because it has plugin permission).
5954 service()->DisableExtension(good2, Extension::DISABLE_USER_ACTION);
5955 ASSERT_FALSE(service()->IsExtensionEnabled(good2));
5953 5956
5954 // Now sync data comes in that says to disable good0. This should be 5957 const Extension* extension0 = service()->GetExtensionById(good0, true);
5955 // ignored. 5958 const Extension* extension2 = service()->GetExtensionById(good2, true);
5956 ExtensionSyncData disable_good_crx(*extension, false, 5959 ASSERT_TRUE(extensions::sync_helper::IsSyncable(extension0));
5957 Extension::DISABLE_USER_ACTION, false, 5960 ASSERT_TRUE(extensions::sync_helper::IsSyncable(extension2));
5958 false, ExtensionSyncData::BOOLEAN_UNSET); 5961
5962 // Now sync data comes in that says to disable good0 and enable good2.
5963 ExtensionSyncData disable_good0(*extension0, false,
5964 Extension::DISABLE_USER_ACTION, false, false,
5965 ExtensionSyncData::BOOLEAN_UNSET);
5966 ExtensionSyncData enable_good2(*extension2, true, Extension::DISABLE_NONE,
5967 false, false,
5968 ExtensionSyncData::BOOLEAN_UNSET);
5959 syncer::SyncDataList sync_data; 5969 syncer::SyncDataList sync_data;
5960 sync_data.push_back(disable_good_crx.GetSyncData()); 5970 sync_data.push_back(disable_good0.GetSyncData());
5971 sync_data.push_back(enable_good2.GetSyncData());
5961 extension_sync_service()->MergeDataAndStartSyncing( 5972 extension_sync_service()->MergeDataAndStartSyncing(
5962 syncer::EXTENSIONS, 5973 syncer::EXTENSIONS,
5963 sync_data, 5974 sync_data,
5964 scoped_ptr<syncer::SyncChangeProcessor>( 5975 make_scoped_ptr(new syncer::FakeSyncChangeProcessor),
5965 new syncer::FakeSyncChangeProcessor), 5976 make_scoped_ptr(new syncer::SyncErrorFactoryMock));
5966 scoped_ptr<syncer::SyncErrorFactory>(new syncer::SyncErrorFactoryMock()));
5967 5977
5968 // The extension was enabled locally before the sync data arrived, so it 5978 // Both sync changes should be ignored, since the local state was changed
5969 // should still be enabled now. 5979 // before sync started, and so the local state is considered more recent.
5970 ASSERT_TRUE(service()->IsExtensionEnabled(good0)); 5980 EXPECT_TRUE(service()->IsExtensionEnabled(good0));
5981 EXPECT_FALSE(service()->IsExtensionEnabled(good2));
5971 } 5982 }
5972 5983
5973 TEST_F(ExtensionServiceTest, GetSyncData) { 5984 TEST_F(ExtensionServiceTest, GetSyncData) {
5974 InitializeEmptyExtensionService(); 5985 InitializeEmptyExtensionService();
5975 InitializeExtensionSyncService(); 5986 InitializeExtensionSyncService();
5976 InstallCRX(data_dir().AppendASCII("good.crx"), INSTALL_NEW); 5987 InstallCRX(data_dir().AppendASCII("good.crx"), INSTALL_NEW);
5977 const Extension* extension = service()->GetInstalledExtension(good_crx); 5988 const Extension* extension = service()->GetInstalledExtension(good_crx);
5978 ASSERT_TRUE(extension); 5989 ASSERT_TRUE(extension);
5979 5990
5980 extension_sync_service()->MergeDataAndStartSyncing( 5991 extension_sync_service()->MergeDataAndStartSyncing(
(...skipping 2120 matching lines...) Expand 10 before | Expand all | Expand 10 after
8101 8112
8102 service()->Observe(chrome::NOTIFICATION_PROFILE_DESTRUCTION_STARTED, 8113 service()->Observe(chrome::NOTIFICATION_PROFILE_DESTRUCTION_STARTED,
8103 content::Source<Profile>(profile()), 8114 content::Source<Profile>(profile()),
8104 content::NotificationService::NoDetails()); 8115 content::NotificationService::NoDetails());
8105 EXPECT_EQ(UnloadedExtensionInfo::REASON_PROFILE_SHUTDOWN, unloaded_reason_); 8116 EXPECT_EQ(UnloadedExtensionInfo::REASON_PROFILE_SHUTDOWN, unloaded_reason_);
8106 EXPECT_EQ(0u, registry()->enabled_extensions().size()); 8117 EXPECT_EQ(0u, registry()->enabled_extensions().size());
8107 EXPECT_EQ(0u, registry()->disabled_extensions().size()); 8118 EXPECT_EQ(0u, registry()->disabled_extensions().size());
8108 EXPECT_EQ(0u, registry()->terminated_extensions().size()); 8119 EXPECT_EQ(0u, registry()->terminated_extensions().size());
8109 EXPECT_EQ(0u, registry()->blacklisted_extensions().size()); 8120 EXPECT_EQ(0u, registry()->blacklisted_extensions().size());
8110 } 8121 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698