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

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

Issue 11345008: Remove content::NotificationObserver dependency from most Prefs code. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix PrefNotifierImpl Created 8 years, 1 month 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "extension_prefs_unittest.h" 5 #include "extension_prefs_unittest.h"
6 6
7 #include "base/basictypes.h" 7 #include "base/basictypes.h"
8 #include "base/path_service.h" 8 #include "base/path_service.h"
9 #include "base/prefs/public/pref_change_registrar.h" 9 #include "base/prefs/public/pref_change_registrar.h"
10 #include "base/scoped_temp_dir.h" 10 #include "base/scoped_temp_dir.h"
11 #include "base/stl_util.h" 11 #include "base/stl_util.h"
12 #include "base/string_number_conversions.h" 12 #include "base/string_number_conversions.h"
13 #include "base/stringprintf.h" 13 #include "base/stringprintf.h"
14 #include "base/values.h" 14 #include "base/values.h"
15 #include "chrome/browser/extensions/extension_pref_value_map.h" 15 #include "chrome/browser/extensions/extension_pref_value_map.h"
16 #include "chrome/browser/extensions/extension_prefs.h" 16 #include "chrome/browser/extensions/extension_prefs.h"
17 #include "chrome/browser/prefs/scoped_user_pref_update.h" 17 #include "chrome/browser/prefs/scoped_user_pref_update.h"
18 #include "chrome/browser/prefs/pref_observer_mock.h"
18 #include "chrome/common/chrome_paths.h" 19 #include "chrome/common/chrome_paths.h"
19 #include "chrome/common/extensions/extension_manifest_constants.h" 20 #include "chrome/common/extensions/extension_manifest_constants.h"
20 #include "chrome/common/extensions/permissions/permission_set.h" 21 #include "chrome/common/extensions/permissions/permission_set.h"
21 #include "chrome/common/extensions/permissions/permissions_info.h" 22 #include "chrome/common/extensions/permissions/permissions_info.h"
22 #include "content/public/browser/notification_details.h" 23 #include "content/public/browser/notification_details.h"
23 #include "content/public/browser/notification_source.h" 24 #include "content/public/browser/notification_source.h"
24 #include "content/public/test/mock_notification_observer.h" 25 #include "content/public/test/mock_notification_observer.h"
25 #include "sync/api/string_ordinal.h" 26 #include "sync/api/string_ordinal.h"
26 27
27 using base::Time; 28 using base::Time;
(...skipping 1014 matching lines...) Expand 10 before | Expand all | Expand 10 after
1042 TEST_F(ExtensionPrefsUninstallExtension, 1043 TEST_F(ExtensionPrefsUninstallExtension,
1043 ExtensionPrefsUninstallExtension) {} 1044 ExtensionPrefsUninstallExtension) {}
1044 1045
1045 // Tests triggering of notifications to registered observers. 1046 // Tests triggering of notifications to registered observers.
1046 class ExtensionPrefsNotifyWhenNeeded : public ExtensionPrefsPrepopulatedTest { 1047 class ExtensionPrefsNotifyWhenNeeded : public ExtensionPrefsPrepopulatedTest {
1047 virtual void Initialize() { 1048 virtual void Initialize() {
1048 using testing::_; 1049 using testing::_;
1049 using testing::Mock; 1050 using testing::Mock;
1050 using testing::StrEq; 1051 using testing::StrEq;
1051 1052
1052 content::MockNotificationObserver observer; 1053 PrefObserverMock observer;
1053 PrefChangeRegistrar registrar; 1054 PrefChangeRegistrar registrar;
1054 registrar.Init(prefs()->pref_service()); 1055 registrar.Init(prefs()->pref_service());
1055 registrar.Add(kPref1, &observer); 1056 registrar.Add(kPref1, &observer);
1056 1057
1057 content::MockNotificationObserver incognito_observer; 1058 PrefObserverMock incognito_observer;
1058 scoped_ptr<PrefService> incog_prefs(prefs_.CreateIncognitoPrefService()); 1059 scoped_ptr<PrefService> incog_prefs(prefs_.CreateIncognitoPrefService());
1059 PrefChangeRegistrar incognito_registrar; 1060 PrefChangeRegistrar incognito_registrar;
1060 incognito_registrar.Init(incog_prefs.get()); 1061 incognito_registrar.Init(incog_prefs.get());
1061 incognito_registrar.Add(kPref1, &incognito_observer); 1062 incognito_registrar.Add(kPref1, &incognito_observer);
1062 1063
1063 // Write value and check notification. 1064 // Write value and check notification.
1064 EXPECT_CALL(observer, Observe(_, _, _)); 1065 EXPECT_CALL(observer, OnPreferenceChanged(_, _));
1065 EXPECT_CALL(incognito_observer, Observe(_, _, _)); 1066 EXPECT_CALL(incognito_observer, OnPreferenceChanged(_, _));
1066 InstallExtControlledPref(ext1_, kPref1, 1067 InstallExtControlledPref(ext1_, kPref1,
1067 Value::CreateStringValue("https://www.chromium.org")); 1068 Value::CreateStringValue("https://www.chromium.org"));
1068 Mock::VerifyAndClearExpectations(&observer); 1069 Mock::VerifyAndClearExpectations(&observer);
1069 Mock::VerifyAndClearExpectations(&incognito_observer); 1070 Mock::VerifyAndClearExpectations(&incognito_observer);
1070 1071
1071 // Write same value. 1072 // Write same value.
1072 EXPECT_CALL(observer, Observe(_, _, _)).Times(0); 1073 EXPECT_CALL(observer, OnPreferenceChanged(_, _)).Times(0);
1073 EXPECT_CALL(incognito_observer, Observe(_, _, _)).Times(0); 1074 EXPECT_CALL(incognito_observer, OnPreferenceChanged(_, _)).Times(0);
1074 InstallExtControlledPref(ext1_, kPref1, 1075 InstallExtControlledPref(ext1_, kPref1,
1075 Value::CreateStringValue("https://www.chromium.org")); 1076 Value::CreateStringValue("https://www.chromium.org"));
1076 Mock::VerifyAndClearExpectations(&observer); 1077 Mock::VerifyAndClearExpectations(&observer);
1077 Mock::VerifyAndClearExpectations(&incognito_observer); 1078 Mock::VerifyAndClearExpectations(&incognito_observer);
1078 1079
1079 // Change value. 1080 // Change value.
1080 EXPECT_CALL(observer, Observe(_, _, _)); 1081 EXPECT_CALL(observer, OnPreferenceChanged(_, _));
1081 EXPECT_CALL(incognito_observer, Observe(_, _, _)); 1082 EXPECT_CALL(incognito_observer, OnPreferenceChanged(_, _));
1082 InstallExtControlledPref(ext1_, kPref1, 1083 InstallExtControlledPref(ext1_, kPref1,
1083 Value::CreateStringValue("chrome://newtab")); 1084 Value::CreateStringValue("chrome://newtab"));
1084 Mock::VerifyAndClearExpectations(&observer); 1085 Mock::VerifyAndClearExpectations(&observer);
1085 Mock::VerifyAndClearExpectations(&incognito_observer); 1086 Mock::VerifyAndClearExpectations(&incognito_observer);
1086 1087
1087 // Change only incognito persistent value. 1088 // Change only incognito persistent value.
1088 EXPECT_CALL(observer, Observe(_, _, _)).Times(0); 1089 EXPECT_CALL(observer, OnPreferenceChanged(_, _)).Times(0);
1089 EXPECT_CALL(incognito_observer, Observe(_, _, _)); 1090 EXPECT_CALL(incognito_observer, OnPreferenceChanged(_, _));
1090 InstallExtControlledPrefIncognito(ext1_, kPref1, 1091 InstallExtControlledPrefIncognito(ext1_, kPref1,
1091 Value::CreateStringValue("chrome://newtab2")); 1092 Value::CreateStringValue("chrome://newtab2"));
1092 Mock::VerifyAndClearExpectations(&observer); 1093 Mock::VerifyAndClearExpectations(&observer);
1093 Mock::VerifyAndClearExpectations(&incognito_observer); 1094 Mock::VerifyAndClearExpectations(&incognito_observer);
1094 1095
1095 // Change only incognito session-only value. 1096 // Change only incognito session-only value.
1096 EXPECT_CALL(observer, Observe(_, _, _)).Times(0); 1097 EXPECT_CALL(observer, OnPreferenceChanged(_, _)).Times(0);
1097 EXPECT_CALL(incognito_observer, Observe(_, _, _)); 1098 EXPECT_CALL(incognito_observer, OnPreferenceChanged(_, _));
1098 InstallExtControlledPrefIncognito(ext1_, kPref1, 1099 InstallExtControlledPrefIncognito(ext1_, kPref1,
1099 Value::CreateStringValue("chrome://newtab3")); 1100 Value::CreateStringValue("chrome://newtab3"));
1100 Mock::VerifyAndClearExpectations(&observer); 1101 Mock::VerifyAndClearExpectations(&observer);
1101 Mock::VerifyAndClearExpectations(&incognito_observer); 1102 Mock::VerifyAndClearExpectations(&incognito_observer);
1102 1103
1103 // Uninstall. 1104 // Uninstall.
1104 EXPECT_CALL(observer, Observe(_, _, _)); 1105 EXPECT_CALL(observer, OnPreferenceChanged(_, _));
1105 EXPECT_CALL(incognito_observer, Observe(_, _, _)); 1106 EXPECT_CALL(incognito_observer, OnPreferenceChanged(_, _));
1106 UninstallExtension(ext1_->id()); 1107 UninstallExtension(ext1_->id());
1107 Mock::VerifyAndClearExpectations(&observer); 1108 Mock::VerifyAndClearExpectations(&observer);
1108 Mock::VerifyAndClearExpectations(&incognito_observer); 1109 Mock::VerifyAndClearExpectations(&incognito_observer);
1109 1110
1110 registrar.Remove(kPref1, &observer); 1111 registrar.Remove(kPref1, &observer);
1111 incognito_registrar.Remove(kPref1, &incognito_observer); 1112 incognito_registrar.Remove(kPref1, &incognito_observer);
1112 } 1113 }
1113 virtual void Verify() { 1114 virtual void Verify() {
1114 std::string actual = prefs()->pref_service()->GetString(kPref1); 1115 std::string actual = prefs()->pref_service()->GetString(kPref1);
1115 EXPECT_EQ(kDefaultPref1, actual); 1116 EXPECT_EQ(kDefaultPref1, actual);
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after
1282 EXPECT_EQ(string16(), error16); 1283 EXPECT_EQ(string16(), error16);
1283 EXPECT_TRUE(prefs()->UserMayModifySettings(extension_.get(), &error16)); 1284 EXPECT_TRUE(prefs()->UserMayModifySettings(extension_.get(), &error16));
1284 EXPECT_EQ(string16(), error16); 1285 EXPECT_EQ(string16(), error16);
1285 EXPECT_FALSE(prefs()->MustRemainEnabled(extension_.get(), &error16)); 1286 EXPECT_FALSE(prefs()->MustRemainEnabled(extension_.get(), &error16));
1286 EXPECT_EQ(string16(), error16); 1287 EXPECT_EQ(string16(), error16);
1287 } 1288 }
1288 }; 1289 };
1289 TEST_F(ExtensionPrefsNotRequiredExtension, NotRequiredExtension) {} 1290 TEST_F(ExtensionPrefsNotRequiredExtension, NotRequiredExtension) {}
1290 1291
1291 } // namespace extensions 1292 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698