| 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/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 1017 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1045 TEST_F(ExtensionPrefsUninstallExtension, | 1046 TEST_F(ExtensionPrefsUninstallExtension, |
| 1046 ExtensionPrefsUninstallExtension) {} | 1047 ExtensionPrefsUninstallExtension) {} |
| 1047 | 1048 |
| 1048 // Tests triggering of notifications to registered observers. | 1049 // Tests triggering of notifications to registered observers. |
| 1049 class ExtensionPrefsNotifyWhenNeeded : public ExtensionPrefsPrepopulatedTest { | 1050 class ExtensionPrefsNotifyWhenNeeded : public ExtensionPrefsPrepopulatedTest { |
| 1050 virtual void Initialize() { | 1051 virtual void Initialize() { |
| 1051 using testing::_; | 1052 using testing::_; |
| 1052 using testing::Mock; | 1053 using testing::Mock; |
| 1053 using testing::StrEq; | 1054 using testing::StrEq; |
| 1054 | 1055 |
| 1055 content::MockNotificationObserver observer; | 1056 PrefObserverMock observer; |
| 1056 PrefChangeRegistrar registrar; | 1057 PrefChangeRegistrar registrar; |
| 1057 registrar.Init(prefs()->pref_service()); | 1058 registrar.Init(prefs()->pref_service()); |
| 1058 registrar.Add(kPref1, &observer); | 1059 registrar.Add(kPref1, &observer); |
| 1059 | 1060 |
| 1060 content::MockNotificationObserver incognito_observer; | 1061 PrefObserverMock incognito_observer; |
| 1061 scoped_ptr<PrefService> incog_prefs(prefs_.CreateIncognitoPrefService()); | 1062 scoped_ptr<PrefService> incog_prefs(prefs_.CreateIncognitoPrefService()); |
| 1062 PrefChangeRegistrar incognito_registrar; | 1063 PrefChangeRegistrar incognito_registrar; |
| 1063 incognito_registrar.Init(incog_prefs.get()); | 1064 incognito_registrar.Init(incog_prefs.get()); |
| 1064 incognito_registrar.Add(kPref1, &incognito_observer); | 1065 incognito_registrar.Add(kPref1, &incognito_observer); |
| 1065 | 1066 |
| 1066 // Write value and check notification. | 1067 // Write value and check notification. |
| 1067 EXPECT_CALL(observer, Observe(_, _, _)); | 1068 EXPECT_CALL(observer, OnPreferenceChanged(_, _)); |
| 1068 EXPECT_CALL(incognito_observer, Observe(_, _, _)); | 1069 EXPECT_CALL(incognito_observer, OnPreferenceChanged(_, _)); |
| 1069 InstallExtControlledPref(ext1_, kPref1, | 1070 InstallExtControlledPref(ext1_, kPref1, |
| 1070 Value::CreateStringValue("https://www.chromium.org")); | 1071 Value::CreateStringValue("https://www.chromium.org")); |
| 1071 Mock::VerifyAndClearExpectations(&observer); | 1072 Mock::VerifyAndClearExpectations(&observer); |
| 1072 Mock::VerifyAndClearExpectations(&incognito_observer); | 1073 Mock::VerifyAndClearExpectations(&incognito_observer); |
| 1073 | 1074 |
| 1074 // Write same value. | 1075 // Write same value. |
| 1075 EXPECT_CALL(observer, Observe(_, _, _)).Times(0); | 1076 EXPECT_CALL(observer, OnPreferenceChanged(_, _)).Times(0); |
| 1076 EXPECT_CALL(incognito_observer, Observe(_, _, _)).Times(0); | 1077 EXPECT_CALL(incognito_observer, OnPreferenceChanged(_, _)).Times(0); |
| 1077 InstallExtControlledPref(ext1_, kPref1, | 1078 InstallExtControlledPref(ext1_, kPref1, |
| 1078 Value::CreateStringValue("https://www.chromium.org")); | 1079 Value::CreateStringValue("https://www.chromium.org")); |
| 1079 Mock::VerifyAndClearExpectations(&observer); | 1080 Mock::VerifyAndClearExpectations(&observer); |
| 1080 Mock::VerifyAndClearExpectations(&incognito_observer); | 1081 Mock::VerifyAndClearExpectations(&incognito_observer); |
| 1081 | 1082 |
| 1082 // Change value. | 1083 // Change value. |
| 1083 EXPECT_CALL(observer, Observe(_, _, _)); | 1084 EXPECT_CALL(observer, OnPreferenceChanged(_, _)); |
| 1084 EXPECT_CALL(incognito_observer, Observe(_, _, _)); | 1085 EXPECT_CALL(incognito_observer, OnPreferenceChanged(_, _)); |
| 1085 InstallExtControlledPref(ext1_, kPref1, | 1086 InstallExtControlledPref(ext1_, kPref1, |
| 1086 Value::CreateStringValue("chrome://newtab")); | 1087 Value::CreateStringValue("chrome://newtab")); |
| 1087 Mock::VerifyAndClearExpectations(&observer); | 1088 Mock::VerifyAndClearExpectations(&observer); |
| 1088 Mock::VerifyAndClearExpectations(&incognito_observer); | 1089 Mock::VerifyAndClearExpectations(&incognito_observer); |
| 1089 | 1090 |
| 1090 // Change only incognito persistent value. | 1091 // Change only incognito persistent value. |
| 1091 EXPECT_CALL(observer, Observe(_, _, _)).Times(0); | 1092 EXPECT_CALL(observer, OnPreferenceChanged(_, _)).Times(0); |
| 1092 EXPECT_CALL(incognito_observer, Observe(_, _, _)); | 1093 EXPECT_CALL(incognito_observer, OnPreferenceChanged(_, _)); |
| 1093 InstallExtControlledPrefIncognito(ext1_, kPref1, | 1094 InstallExtControlledPrefIncognito(ext1_, kPref1, |
| 1094 Value::CreateStringValue("chrome://newtab2")); | 1095 Value::CreateStringValue("chrome://newtab2")); |
| 1095 Mock::VerifyAndClearExpectations(&observer); | 1096 Mock::VerifyAndClearExpectations(&observer); |
| 1096 Mock::VerifyAndClearExpectations(&incognito_observer); | 1097 Mock::VerifyAndClearExpectations(&incognito_observer); |
| 1097 | 1098 |
| 1098 // Change only incognito session-only value. | 1099 // Change only incognito session-only value. |
| 1099 EXPECT_CALL(observer, Observe(_, _, _)).Times(0); | 1100 EXPECT_CALL(observer, OnPreferenceChanged(_, _)).Times(0); |
| 1100 EXPECT_CALL(incognito_observer, Observe(_, _, _)); | 1101 EXPECT_CALL(incognito_observer, OnPreferenceChanged(_, _)); |
| 1101 InstallExtControlledPrefIncognito(ext1_, kPref1, | 1102 InstallExtControlledPrefIncognito(ext1_, kPref1, |
| 1102 Value::CreateStringValue("chrome://newtab3")); | 1103 Value::CreateStringValue("chrome://newtab3")); |
| 1103 Mock::VerifyAndClearExpectations(&observer); | 1104 Mock::VerifyAndClearExpectations(&observer); |
| 1104 Mock::VerifyAndClearExpectations(&incognito_observer); | 1105 Mock::VerifyAndClearExpectations(&incognito_observer); |
| 1105 | 1106 |
| 1106 // Uninstall. | 1107 // Uninstall. |
| 1107 EXPECT_CALL(observer, Observe(_, _, _)); | 1108 EXPECT_CALL(observer, OnPreferenceChanged(_, _)); |
| 1108 EXPECT_CALL(incognito_observer, Observe(_, _, _)); | 1109 EXPECT_CALL(incognito_observer, OnPreferenceChanged(_, _)); |
| 1109 UninstallExtension(ext1_->id()); | 1110 UninstallExtension(ext1_->id()); |
| 1110 Mock::VerifyAndClearExpectations(&observer); | 1111 Mock::VerifyAndClearExpectations(&observer); |
| 1111 Mock::VerifyAndClearExpectations(&incognito_observer); | 1112 Mock::VerifyAndClearExpectations(&incognito_observer); |
| 1112 | 1113 |
| 1113 registrar.Remove(kPref1, &observer); | 1114 registrar.Remove(kPref1, &observer); |
| 1114 incognito_registrar.Remove(kPref1, &incognito_observer); | 1115 incognito_registrar.Remove(kPref1, &incognito_observer); |
| 1115 } | 1116 } |
| 1116 virtual void Verify() { | 1117 virtual void Verify() { |
| 1117 std::string actual = prefs()->pref_service()->GetString(kPref1); | 1118 std::string actual = prefs()->pref_service()->GetString(kPref1); |
| 1118 EXPECT_EQ(kDefaultPref1, actual); | 1119 EXPECT_EQ(kDefaultPref1, actual); |
| (...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1285 EXPECT_EQ(string16(), error16); | 1286 EXPECT_EQ(string16(), error16); |
| 1286 EXPECT_TRUE(prefs()->UserMayModifySettings(extension_.get(), &error16)); | 1287 EXPECT_TRUE(prefs()->UserMayModifySettings(extension_.get(), &error16)); |
| 1287 EXPECT_EQ(string16(), error16); | 1288 EXPECT_EQ(string16(), error16); |
| 1288 EXPECT_FALSE(prefs()->MustRemainEnabled(extension_.get(), &error16)); | 1289 EXPECT_FALSE(prefs()->MustRemainEnabled(extension_.get(), &error16)); |
| 1289 EXPECT_EQ(string16(), error16); | 1290 EXPECT_EQ(string16(), error16); |
| 1290 } | 1291 } |
| 1291 }; | 1292 }; |
| 1292 TEST_F(ExtensionPrefsNotRequiredExtension, NotRequiredExtension) {} | 1293 TEST_F(ExtensionPrefsNotRequiredExtension, NotRequiredExtension) {} |
| 1293 | 1294 |
| 1294 } // namespace extensions | 1295 } // namespace extensions |
| OLD | NEW |