OLD | NEW |
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/files/scoped_temp_dir.h" | 8 #include "base/files/scoped_temp_dir.h" |
9 #include "base/path_service.h" | 9 #include "base/path_service.h" |
10 #include "base/prefs/public/pref_change_registrar.h" | 10 #include "base/prefs/public/pref_change_registrar.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/pref_observer_mock.h" | 17 #include "chrome/browser/prefs/mock_pref_change_callback.h" |
18 #include "chrome/browser/prefs/scoped_user_pref_update.h" | 18 #include "chrome/browser/prefs/scoped_user_pref_update.h" |
19 #include "chrome/common/chrome_paths.h" | 19 #include "chrome/common/chrome_paths.h" |
20 #include "chrome/common/extensions/extension_manifest_constants.h" | 20 #include "chrome/common/extensions/extension_manifest_constants.h" |
21 #include "chrome/common/extensions/permissions/permission_set.h" | 21 #include "chrome/common/extensions/permissions/permission_set.h" |
22 #include "chrome/common/extensions/permissions/permissions_info.h" | 22 #include "chrome/common/extensions/permissions/permissions_info.h" |
23 #include "content/public/browser/notification_details.h" | 23 #include "content/public/browser/notification_details.h" |
24 #include "content/public/browser/notification_source.h" | 24 #include "content/public/browser/notification_source.h" |
25 #include "content/public/test/mock_notification_observer.h" | 25 #include "content/public/test/mock_notification_observer.h" |
26 #include "sync/api/string_ordinal.h" | 26 #include "sync/api/string_ordinal.h" |
27 | 27 |
(...skipping 982 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1010 TEST_F(ExtensionPrefsUninstallExtension, | 1010 TEST_F(ExtensionPrefsUninstallExtension, |
1011 ExtensionPrefsUninstallExtension) {} | 1011 ExtensionPrefsUninstallExtension) {} |
1012 | 1012 |
1013 // Tests triggering of notifications to registered observers. | 1013 // Tests triggering of notifications to registered observers. |
1014 class ExtensionPrefsNotifyWhenNeeded : public ExtensionPrefsPrepopulatedTest { | 1014 class ExtensionPrefsNotifyWhenNeeded : public ExtensionPrefsPrepopulatedTest { |
1015 virtual void Initialize() { | 1015 virtual void Initialize() { |
1016 using testing::_; | 1016 using testing::_; |
1017 using testing::Mock; | 1017 using testing::Mock; |
1018 using testing::StrEq; | 1018 using testing::StrEq; |
1019 | 1019 |
1020 PrefObserverMock observer; | 1020 MockPrefChangeCallback observer(prefs()->pref_service()); |
1021 PrefChangeRegistrar registrar; | 1021 PrefChangeRegistrar registrar; |
1022 registrar.Init(prefs()->pref_service()); | 1022 registrar.Init(prefs()->pref_service()); |
1023 registrar.Add(kPref1, &observer); | 1023 registrar.Add(kPref1, observer.GetCallback()); |
1024 | 1024 |
1025 PrefObserverMock incognito_observer; | 1025 MockPrefChangeCallback incognito_observer(prefs()->pref_service()); |
1026 scoped_ptr<PrefService> incog_prefs(prefs_.CreateIncognitoPrefService()); | 1026 scoped_ptr<PrefService> incog_prefs(prefs_.CreateIncognitoPrefService()); |
1027 PrefChangeRegistrar incognito_registrar; | 1027 PrefChangeRegistrar incognito_registrar; |
1028 incognito_registrar.Init(incog_prefs.get()); | 1028 incognito_registrar.Init(incog_prefs.get()); |
1029 incognito_registrar.Add(kPref1, &incognito_observer); | 1029 incognito_registrar.Add(kPref1, incognito_observer.GetCallback()); |
1030 | 1030 |
1031 // Write value and check notification. | 1031 // Write value and check notification. |
1032 EXPECT_CALL(observer, OnPreferenceChanged(_, _)); | 1032 EXPECT_CALL(observer, OnPreferenceChanged(_)); |
1033 EXPECT_CALL(incognito_observer, OnPreferenceChanged(_, _)); | 1033 EXPECT_CALL(incognito_observer, OnPreferenceChanged(_)); |
1034 InstallExtControlledPref(ext1_, kPref1, | 1034 InstallExtControlledPref(ext1_, kPref1, |
1035 Value::CreateStringValue("https://www.chromium.org")); | 1035 Value::CreateStringValue("https://www.chromium.org")); |
1036 Mock::VerifyAndClearExpectations(&observer); | 1036 Mock::VerifyAndClearExpectations(&observer); |
1037 Mock::VerifyAndClearExpectations(&incognito_observer); | 1037 Mock::VerifyAndClearExpectations(&incognito_observer); |
1038 | 1038 |
1039 // Write same value. | 1039 // Write same value. |
1040 EXPECT_CALL(observer, OnPreferenceChanged(_, _)).Times(0); | 1040 EXPECT_CALL(observer, OnPreferenceChanged(_)).Times(0); |
1041 EXPECT_CALL(incognito_observer, OnPreferenceChanged(_, _)).Times(0); | 1041 EXPECT_CALL(incognito_observer, OnPreferenceChanged(_)).Times(0); |
1042 InstallExtControlledPref(ext1_, kPref1, | 1042 InstallExtControlledPref(ext1_, kPref1, |
1043 Value::CreateStringValue("https://www.chromium.org")); | 1043 Value::CreateStringValue("https://www.chromium.org")); |
1044 Mock::VerifyAndClearExpectations(&observer); | 1044 Mock::VerifyAndClearExpectations(&observer); |
1045 Mock::VerifyAndClearExpectations(&incognito_observer); | 1045 Mock::VerifyAndClearExpectations(&incognito_observer); |
1046 | 1046 |
1047 // Change value. | 1047 // Change value. |
1048 EXPECT_CALL(observer, OnPreferenceChanged(_, _)); | 1048 EXPECT_CALL(observer, OnPreferenceChanged(_)); |
1049 EXPECT_CALL(incognito_observer, OnPreferenceChanged(_, _)); | 1049 EXPECT_CALL(incognito_observer, OnPreferenceChanged(_)); |
1050 InstallExtControlledPref(ext1_, kPref1, | 1050 InstallExtControlledPref(ext1_, kPref1, |
1051 Value::CreateStringValue("chrome://newtab")); | 1051 Value::CreateStringValue("chrome://newtab")); |
1052 Mock::VerifyAndClearExpectations(&observer); | 1052 Mock::VerifyAndClearExpectations(&observer); |
1053 Mock::VerifyAndClearExpectations(&incognito_observer); | 1053 Mock::VerifyAndClearExpectations(&incognito_observer); |
1054 | 1054 |
1055 // Change only incognito persistent value. | 1055 // Change only incognito persistent value. |
1056 EXPECT_CALL(observer, OnPreferenceChanged(_, _)).Times(0); | 1056 EXPECT_CALL(observer, OnPreferenceChanged(_)).Times(0); |
1057 EXPECT_CALL(incognito_observer, OnPreferenceChanged(_, _)); | 1057 EXPECT_CALL(incognito_observer, OnPreferenceChanged(_)); |
1058 InstallExtControlledPrefIncognito(ext1_, kPref1, | 1058 InstallExtControlledPrefIncognito(ext1_, kPref1, |
1059 Value::CreateStringValue("chrome://newtab2")); | 1059 Value::CreateStringValue("chrome://newtab2")); |
1060 Mock::VerifyAndClearExpectations(&observer); | 1060 Mock::VerifyAndClearExpectations(&observer); |
1061 Mock::VerifyAndClearExpectations(&incognito_observer); | 1061 Mock::VerifyAndClearExpectations(&incognito_observer); |
1062 | 1062 |
1063 // Change only incognito session-only value. | 1063 // Change only incognito session-only value. |
1064 EXPECT_CALL(observer, OnPreferenceChanged(_, _)).Times(0); | 1064 EXPECT_CALL(observer, OnPreferenceChanged(_)).Times(0); |
1065 EXPECT_CALL(incognito_observer, OnPreferenceChanged(_, _)); | 1065 EXPECT_CALL(incognito_observer, OnPreferenceChanged(_)); |
1066 InstallExtControlledPrefIncognito(ext1_, kPref1, | 1066 InstallExtControlledPrefIncognito(ext1_, kPref1, |
1067 Value::CreateStringValue("chrome://newtab3")); | 1067 Value::CreateStringValue("chrome://newtab3")); |
1068 Mock::VerifyAndClearExpectations(&observer); | 1068 Mock::VerifyAndClearExpectations(&observer); |
1069 Mock::VerifyAndClearExpectations(&incognito_observer); | 1069 Mock::VerifyAndClearExpectations(&incognito_observer); |
1070 | 1070 |
1071 // Uninstall. | 1071 // Uninstall. |
1072 EXPECT_CALL(observer, OnPreferenceChanged(_, _)); | 1072 EXPECT_CALL(observer, OnPreferenceChanged(_)); |
1073 EXPECT_CALL(incognito_observer, OnPreferenceChanged(_, _)); | 1073 EXPECT_CALL(incognito_observer, OnPreferenceChanged(_)); |
1074 UninstallExtension(ext1_->id()); | 1074 UninstallExtension(ext1_->id()); |
1075 Mock::VerifyAndClearExpectations(&observer); | 1075 Mock::VerifyAndClearExpectations(&observer); |
1076 Mock::VerifyAndClearExpectations(&incognito_observer); | 1076 Mock::VerifyAndClearExpectations(&incognito_observer); |
1077 | 1077 |
1078 registrar.Remove(kPref1); | 1078 registrar.Remove(kPref1); |
1079 incognito_registrar.Remove(kPref1); | 1079 incognito_registrar.Remove(kPref1); |
1080 } | 1080 } |
1081 virtual void Verify() { | 1081 virtual void Verify() { |
1082 std::string actual = prefs()->pref_service()->GetString(kPref1); | 1082 std::string actual = prefs()->pref_service()->GetString(kPref1); |
1083 EXPECT_EQ(kDefaultPref1, actual); | 1083 EXPECT_EQ(kDefaultPref1, actual); |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1183 EXPECT_EQ(kDefaultPref1, actual); | 1183 EXPECT_EQ(kDefaultPref1, actual); |
1184 } | 1184 } |
1185 } | 1185 } |
1186 | 1186 |
1187 private: | 1187 private: |
1188 int iteration_; | 1188 int iteration_; |
1189 }; | 1189 }; |
1190 TEST_F(ExtensionPrefsDisableExtensions, ExtensionPrefsDisableExtensions) {} | 1190 TEST_F(ExtensionPrefsDisableExtensions, ExtensionPrefsDisableExtensions) {} |
1191 | 1191 |
1192 } // namespace extensions | 1192 } // namespace extensions |
OLD | NEW |