| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 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 <string> | 5 #include <string> |
| 6 | 6 |
| 7 #include "base/memory/ref_counted.h" | 7 #include "base/memory/ref_counted.h" |
| 8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
| 9 #include "base/prefs/mock_pref_change_callback.h" | 9 #include "base/prefs/mock_pref_change_callback.h" |
| 10 #include "base/values.h" | 10 #include "base/values.h" |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 42 class TestPreferenceAPI : public PreferenceAPIBase { | 42 class TestPreferenceAPI : public PreferenceAPIBase { |
| 43 public: | 43 public: |
| 44 explicit TestPreferenceAPI(TestExtensionPrefs* test_extension_prefs, | 44 explicit TestPreferenceAPI(TestExtensionPrefs* test_extension_prefs, |
| 45 ContentSettingsService* content_settings) | 45 ContentSettingsService* content_settings) |
| 46 : test_extension_prefs_(test_extension_prefs), | 46 : test_extension_prefs_(test_extension_prefs), |
| 47 content_settings_(content_settings) {} | 47 content_settings_(content_settings) {} |
| 48 ~TestPreferenceAPI() {} | 48 ~TestPreferenceAPI() {} |
| 49 | 49 |
| 50 private: | 50 private: |
| 51 // PreferenceAPIBase implementation. | 51 // PreferenceAPIBase implementation. |
| 52 virtual ExtensionPrefs* extension_prefs() OVERRIDE { | 52 virtual ExtensionPrefs* extension_prefs() override { |
| 53 return test_extension_prefs_->prefs(); | 53 return test_extension_prefs_->prefs(); |
| 54 } | 54 } |
| 55 virtual ExtensionPrefValueMap* extension_pref_value_map() OVERRIDE { | 55 virtual ExtensionPrefValueMap* extension_pref_value_map() override { |
| 56 return test_extension_prefs_->extension_pref_value_map(); | 56 return test_extension_prefs_->extension_pref_value_map(); |
| 57 } | 57 } |
| 58 virtual scoped_refptr<ContentSettingsStore> content_settings_store() | 58 virtual scoped_refptr<ContentSettingsStore> content_settings_store() |
| 59 OVERRIDE { | 59 override { |
| 60 return content_settings_->content_settings_store(); | 60 return content_settings_->content_settings_store(); |
| 61 } | 61 } |
| 62 | 62 |
| 63 TestExtensionPrefs* test_extension_prefs_; | 63 TestExtensionPrefs* test_extension_prefs_; |
| 64 ContentSettingsService* content_settings_; | 64 ContentSettingsService* content_settings_; |
| 65 | 65 |
| 66 DISALLOW_COPY_AND_ASSIGN(TestPreferenceAPI); | 66 DISALLOW_COPY_AND_ASSIGN(TestPreferenceAPI); |
| 67 }; | 67 }; |
| 68 | 68 |
| 69 class ExtensionControlledPrefsTest : public PrefsPrepopulatedTestBase { | 69 class ExtensionControlledPrefsTest : public PrefsPrepopulatedTestBase { |
| 70 public: | 70 public: |
| 71 ExtensionControlledPrefsTest(); | 71 ExtensionControlledPrefsTest(); |
| 72 virtual ~ExtensionControlledPrefsTest(); | 72 virtual ~ExtensionControlledPrefsTest(); |
| 73 | 73 |
| 74 virtual void RegisterPreferences(user_prefs::PrefRegistrySyncable* registry) | 74 virtual void RegisterPreferences(user_prefs::PrefRegistrySyncable* registry) |
| 75 OVERRIDE; | 75 override; |
| 76 void InstallExtensionControlledPref(Extension* extension, | 76 void InstallExtensionControlledPref(Extension* extension, |
| 77 const std::string& key, | 77 const std::string& key, |
| 78 base::Value* value); | 78 base::Value* value); |
| 79 void InstallExtensionControlledPrefIncognito(Extension* extension, | 79 void InstallExtensionControlledPrefIncognito(Extension* extension, |
| 80 const std::string& key, | 80 const std::string& key, |
| 81 base::Value* value); | 81 base::Value* value); |
| 82 void InstallExtensionControlledPrefIncognitoSessionOnly( | 82 void InstallExtensionControlledPrefIncognitoSessionOnly( |
| 83 Extension* extension, | 83 Extension* extension, |
| 84 const std::string& key, | 84 const std::string& key, |
| 85 base::Value* value); | 85 base::Value* value); |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 187 if (extensions[i]->id() == extension_id) { | 187 if (extensions[i]->id() == extension_id) { |
| 188 installed_[i] = false; | 188 installed_[i] = false; |
| 189 break; | 189 break; |
| 190 } | 190 } |
| 191 } | 191 } |
| 192 prefs()->OnExtensionUninstalled(extension_id, Manifest::INTERNAL, false); | 192 prefs()->OnExtensionUninstalled(extension_id, Manifest::INTERNAL, false); |
| 193 } | 193 } |
| 194 | 194 |
| 195 class ControlledPrefsInstallOneExtension | 195 class ControlledPrefsInstallOneExtension |
| 196 : public ExtensionControlledPrefsTest { | 196 : public ExtensionControlledPrefsTest { |
| 197 virtual void Initialize() OVERRIDE { | 197 virtual void Initialize() override { |
| 198 InstallExtensionControlledPref(extension1(), | 198 InstallExtensionControlledPref(extension1(), |
| 199 kPref1, | 199 kPref1, |
| 200 new base::StringValue("val1")); | 200 new base::StringValue("val1")); |
| 201 } | 201 } |
| 202 virtual void Verify() OVERRIDE { | 202 virtual void Verify() override { |
| 203 std::string actual = prefs()->pref_service()->GetString(kPref1); | 203 std::string actual = prefs()->pref_service()->GetString(kPref1); |
| 204 EXPECT_EQ("val1", actual); | 204 EXPECT_EQ("val1", actual); |
| 205 } | 205 } |
| 206 }; | 206 }; |
| 207 TEST_F(ControlledPrefsInstallOneExtension, | 207 TEST_F(ControlledPrefsInstallOneExtension, |
| 208 ControlledPrefsInstallOneExtension) { } | 208 ControlledPrefsInstallOneExtension) { } |
| 209 | 209 |
| 210 // Check that we do not forget persistent incognito values after a reload. | 210 // Check that we do not forget persistent incognito values after a reload. |
| 211 class ControlledPrefsInstallIncognitoPersistent | 211 class ControlledPrefsInstallIncognitoPersistent |
| 212 : public ExtensionControlledPrefsTest { | 212 : public ExtensionControlledPrefsTest { |
| 213 public: | 213 public: |
| 214 virtual void Initialize() OVERRIDE { | 214 virtual void Initialize() override { |
| 215 InstallExtensionControlledPref( | 215 InstallExtensionControlledPref( |
| 216 extension1(), kPref1, new base::StringValue("val1")); | 216 extension1(), kPref1, new base::StringValue("val1")); |
| 217 InstallExtensionControlledPrefIncognito( | 217 InstallExtensionControlledPrefIncognito( |
| 218 extension1(), kPref1, new base::StringValue("val2")); | 218 extension1(), kPref1, new base::StringValue("val2")); |
| 219 scoped_ptr<PrefService> incog_prefs(prefs_.CreateIncognitoPrefService()); | 219 scoped_ptr<PrefService> incog_prefs(prefs_.CreateIncognitoPrefService()); |
| 220 std::string actual = incog_prefs->GetString(kPref1); | 220 std::string actual = incog_prefs->GetString(kPref1); |
| 221 EXPECT_EQ("val2", actual); | 221 EXPECT_EQ("val2", actual); |
| 222 } | 222 } |
| 223 | 223 |
| 224 virtual void Verify() OVERRIDE { | 224 virtual void Verify() override { |
| 225 // Main pref service shall see only non-incognito settings. | 225 // Main pref service shall see only non-incognito settings. |
| 226 std::string actual = prefs()->pref_service()->GetString(kPref1); | 226 std::string actual = prefs()->pref_service()->GetString(kPref1); |
| 227 EXPECT_EQ("val1", actual); | 227 EXPECT_EQ("val1", actual); |
| 228 // Incognito pref service shall see incognito values. | 228 // Incognito pref service shall see incognito values. |
| 229 scoped_ptr<PrefService> incog_prefs(prefs_.CreateIncognitoPrefService()); | 229 scoped_ptr<PrefService> incog_prefs(prefs_.CreateIncognitoPrefService()); |
| 230 actual = incog_prefs->GetString(kPref1); | 230 actual = incog_prefs->GetString(kPref1); |
| 231 EXPECT_EQ("val2", actual); | 231 EXPECT_EQ("val2", actual); |
| 232 } | 232 } |
| 233 }; | 233 }; |
| 234 TEST_F(ControlledPrefsInstallIncognitoPersistent, | 234 TEST_F(ControlledPrefsInstallIncognitoPersistent, |
| 235 ControlledPrefsInstallIncognitoPersistent) { } | 235 ControlledPrefsInstallIncognitoPersistent) { } |
| 236 | 236 |
| 237 // Check that we forget 'session only' incognito values after a reload. | 237 // Check that we forget 'session only' incognito values after a reload. |
| 238 class ControlledPrefsInstallIncognitoSessionOnly | 238 class ControlledPrefsInstallIncognitoSessionOnly |
| 239 : public ExtensionControlledPrefsTest { | 239 : public ExtensionControlledPrefsTest { |
| 240 public: | 240 public: |
| 241 ControlledPrefsInstallIncognitoSessionOnly() : iteration_(0) {} | 241 ControlledPrefsInstallIncognitoSessionOnly() : iteration_(0) {} |
| 242 | 242 |
| 243 virtual void Initialize() OVERRIDE { | 243 virtual void Initialize() override { |
| 244 InstallExtensionControlledPref( | 244 InstallExtensionControlledPref( |
| 245 extension1(), kPref1, new base::StringValue("val1")); | 245 extension1(), kPref1, new base::StringValue("val1")); |
| 246 InstallExtensionControlledPrefIncognitoSessionOnly( | 246 InstallExtensionControlledPrefIncognitoSessionOnly( |
| 247 extension1(), kPref1, new base::StringValue("val2")); | 247 extension1(), kPref1, new base::StringValue("val2")); |
| 248 scoped_ptr<PrefService> incog_prefs(prefs_.CreateIncognitoPrefService()); | 248 scoped_ptr<PrefService> incog_prefs(prefs_.CreateIncognitoPrefService()); |
| 249 std::string actual = incog_prefs->GetString(kPref1); | 249 std::string actual = incog_prefs->GetString(kPref1); |
| 250 EXPECT_EQ("val2", actual); | 250 EXPECT_EQ("val2", actual); |
| 251 } | 251 } |
| 252 virtual void Verify() OVERRIDE { | 252 virtual void Verify() override { |
| 253 // Main pref service shall see only non-incognito settings. | 253 // Main pref service shall see only non-incognito settings. |
| 254 std::string actual = prefs()->pref_service()->GetString(kPref1); | 254 std::string actual = prefs()->pref_service()->GetString(kPref1); |
| 255 EXPECT_EQ("val1", actual); | 255 EXPECT_EQ("val1", actual); |
| 256 // Incognito pref service shall see session-only incognito values only | 256 // Incognito pref service shall see session-only incognito values only |
| 257 // during first run. Once the pref service was reloaded, all values shall be | 257 // during first run. Once the pref service was reloaded, all values shall be |
| 258 // discarded. | 258 // discarded. |
| 259 scoped_ptr<PrefService> incog_prefs(prefs_.CreateIncognitoPrefService()); | 259 scoped_ptr<PrefService> incog_prefs(prefs_.CreateIncognitoPrefService()); |
| 260 actual = incog_prefs->GetString(kPref1); | 260 actual = incog_prefs->GetString(kPref1); |
| 261 if (iteration_ == 0) { | 261 if (iteration_ == 0) { |
| 262 EXPECT_EQ("val2", actual); | 262 EXPECT_EQ("val2", actual); |
| 263 } else { | 263 } else { |
| 264 EXPECT_EQ("val1", actual); | 264 EXPECT_EQ("val1", actual); |
| 265 } | 265 } |
| 266 ++iteration_; | 266 ++iteration_; |
| 267 } | 267 } |
| 268 int iteration_; | 268 int iteration_; |
| 269 }; | 269 }; |
| 270 TEST_F(ControlledPrefsInstallIncognitoSessionOnly, | 270 TEST_F(ControlledPrefsInstallIncognitoSessionOnly, |
| 271 ControlledPrefsInstallIncognitoSessionOnly) { } | 271 ControlledPrefsInstallIncognitoSessionOnly) { } |
| 272 | 272 |
| 273 class ControlledPrefsUninstallExtension : public ExtensionControlledPrefsTest { | 273 class ControlledPrefsUninstallExtension : public ExtensionControlledPrefsTest { |
| 274 virtual void Initialize() OVERRIDE { | 274 virtual void Initialize() override { |
| 275 InstallExtensionControlledPref( | 275 InstallExtensionControlledPref( |
| 276 extension1(), kPref1, new base::StringValue("val1")); | 276 extension1(), kPref1, new base::StringValue("val1")); |
| 277 InstallExtensionControlledPref( | 277 InstallExtensionControlledPref( |
| 278 extension1(), kPref2, new base::StringValue("val2")); | 278 extension1(), kPref2, new base::StringValue("val2")); |
| 279 scoped_refptr<ContentSettingsStore> store = content_settings_store(); | 279 scoped_refptr<ContentSettingsStore> store = content_settings_store(); |
| 280 ContentSettingsPattern pattern = | 280 ContentSettingsPattern pattern = |
| 281 ContentSettingsPattern::FromString("http://[*.]example.com"); | 281 ContentSettingsPattern::FromString("http://[*.]example.com"); |
| 282 store->SetExtensionContentSetting(extension1()->id(), | 282 store->SetExtensionContentSetting(extension1()->id(), |
| 283 pattern, pattern, | 283 pattern, pattern, |
| 284 CONTENT_SETTINGS_TYPE_IMAGES, | 284 CONTENT_SETTINGS_TYPE_IMAGES, |
| 285 std::string(), | 285 std::string(), |
| 286 CONTENT_SETTING_BLOCK, | 286 CONTENT_SETTING_BLOCK, |
| 287 kExtensionPrefsScopeRegular); | 287 kExtensionPrefsScopeRegular); |
| 288 | 288 |
| 289 UninstallExtension(extension1()->id()); | 289 UninstallExtension(extension1()->id()); |
| 290 } | 290 } |
| 291 virtual void Verify() OVERRIDE { | 291 virtual void Verify() override { |
| 292 EXPECT_FALSE(prefs()->HasPrefForExtension(extension1()->id())); | 292 EXPECT_FALSE(prefs()->HasPrefForExtension(extension1()->id())); |
| 293 | 293 |
| 294 std::string actual; | 294 std::string actual; |
| 295 actual = prefs()->pref_service()->GetString(kPref1); | 295 actual = prefs()->pref_service()->GetString(kPref1); |
| 296 EXPECT_EQ(kDefaultPref1, actual); | 296 EXPECT_EQ(kDefaultPref1, actual); |
| 297 actual = prefs()->pref_service()->GetString(kPref2); | 297 actual = prefs()->pref_service()->GetString(kPref2); |
| 298 EXPECT_EQ(kDefaultPref2, actual); | 298 EXPECT_EQ(kDefaultPref2, actual); |
| 299 } | 299 } |
| 300 }; | 300 }; |
| 301 TEST_F(ControlledPrefsUninstallExtension, | 301 TEST_F(ControlledPrefsUninstallExtension, |
| 302 ControlledPrefsUninstallExtension) { } | 302 ControlledPrefsUninstallExtension) { } |
| 303 | 303 |
| 304 // Tests triggering of notifications to registered observers. | 304 // Tests triggering of notifications to registered observers. |
| 305 class ControlledPrefsNotifyWhenNeeded : public ExtensionControlledPrefsTest { | 305 class ControlledPrefsNotifyWhenNeeded : public ExtensionControlledPrefsTest { |
| 306 virtual void Initialize() OVERRIDE { | 306 virtual void Initialize() override { |
| 307 using testing::_; | 307 using testing::_; |
| 308 using testing::Mock; | 308 using testing::Mock; |
| 309 using testing::StrEq; | 309 using testing::StrEq; |
| 310 | 310 |
| 311 MockPrefChangeCallback observer(prefs()->pref_service()); | 311 MockPrefChangeCallback observer(prefs()->pref_service()); |
| 312 PrefChangeRegistrar registrar; | 312 PrefChangeRegistrar registrar; |
| 313 registrar.Init(prefs()->pref_service()); | 313 registrar.Init(prefs()->pref_service()); |
| 314 registrar.Add(kPref1, observer.GetCallback()); | 314 registrar.Add(kPref1, observer.GetCallback()); |
| 315 | 315 |
| 316 MockPrefChangeCallback incognito_observer(prefs()->pref_service()); | 316 MockPrefChangeCallback incognito_observer(prefs()->pref_service()); |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 361 // Uninstall. | 361 // Uninstall. |
| 362 EXPECT_CALL(observer, OnPreferenceChanged(_)); | 362 EXPECT_CALL(observer, OnPreferenceChanged(_)); |
| 363 EXPECT_CALL(incognito_observer, OnPreferenceChanged(_)); | 363 EXPECT_CALL(incognito_observer, OnPreferenceChanged(_)); |
| 364 UninstallExtension(extension1()->id()); | 364 UninstallExtension(extension1()->id()); |
| 365 Mock::VerifyAndClearExpectations(&observer); | 365 Mock::VerifyAndClearExpectations(&observer); |
| 366 Mock::VerifyAndClearExpectations(&incognito_observer); | 366 Mock::VerifyAndClearExpectations(&incognito_observer); |
| 367 | 367 |
| 368 registrar.Remove(kPref1); | 368 registrar.Remove(kPref1); |
| 369 incognito_registrar.Remove(kPref1); | 369 incognito_registrar.Remove(kPref1); |
| 370 } | 370 } |
| 371 virtual void Verify() OVERRIDE { | 371 virtual void Verify() override { |
| 372 std::string actual = prefs()->pref_service()->GetString(kPref1); | 372 std::string actual = prefs()->pref_service()->GetString(kPref1); |
| 373 EXPECT_EQ(kDefaultPref1, actual); | 373 EXPECT_EQ(kDefaultPref1, actual); |
| 374 } | 374 } |
| 375 }; | 375 }; |
| 376 TEST_F(ControlledPrefsNotifyWhenNeeded, | 376 TEST_F(ControlledPrefsNotifyWhenNeeded, |
| 377 ControlledPrefsNotifyWhenNeeded) { } | 377 ControlledPrefsNotifyWhenNeeded) { } |
| 378 | 378 |
| 379 // Tests disabling an extension. | 379 // Tests disabling an extension. |
| 380 class ControlledPrefsDisableExtension : public ExtensionControlledPrefsTest { | 380 class ControlledPrefsDisableExtension : public ExtensionControlledPrefsTest { |
| 381 virtual void Initialize() OVERRIDE { | 381 virtual void Initialize() override { |
| 382 InstallExtensionControlledPref( | 382 InstallExtensionControlledPref( |
| 383 extension1(), kPref1, new base::StringValue("val1")); | 383 extension1(), kPref1, new base::StringValue("val1")); |
| 384 std::string actual = prefs()->pref_service()->GetString(kPref1); | 384 std::string actual = prefs()->pref_service()->GetString(kPref1); |
| 385 EXPECT_EQ("val1", actual); | 385 EXPECT_EQ("val1", actual); |
| 386 prefs()->SetExtensionState(extension1()->id(), Extension::DISABLED); | 386 prefs()->SetExtensionState(extension1()->id(), Extension::DISABLED); |
| 387 } | 387 } |
| 388 virtual void Verify() OVERRIDE { | 388 virtual void Verify() override { |
| 389 std::string actual = prefs()->pref_service()->GetString(kPref1); | 389 std::string actual = prefs()->pref_service()->GetString(kPref1); |
| 390 EXPECT_EQ(kDefaultPref1, actual); | 390 EXPECT_EQ(kDefaultPref1, actual); |
| 391 } | 391 } |
| 392 }; | 392 }; |
| 393 TEST_F(ControlledPrefsDisableExtension, ControlledPrefsDisableExtension) { } | 393 TEST_F(ControlledPrefsDisableExtension, ControlledPrefsDisableExtension) { } |
| 394 | 394 |
| 395 // Tests disabling and reenabling an extension. | 395 // Tests disabling and reenabling an extension. |
| 396 class ControlledPrefsReenableExtension : public ExtensionControlledPrefsTest { | 396 class ControlledPrefsReenableExtension : public ExtensionControlledPrefsTest { |
| 397 virtual void Initialize() OVERRIDE { | 397 virtual void Initialize() override { |
| 398 InstallExtensionControlledPref( | 398 InstallExtensionControlledPref( |
| 399 extension1(), kPref1, new base::StringValue("val1")); | 399 extension1(), kPref1, new base::StringValue("val1")); |
| 400 prefs()->SetExtensionState(extension1()->id(), Extension::DISABLED); | 400 prefs()->SetExtensionState(extension1()->id(), Extension::DISABLED); |
| 401 prefs()->SetExtensionState(extension1()->id(), Extension::ENABLED); | 401 prefs()->SetExtensionState(extension1()->id(), Extension::ENABLED); |
| 402 } | 402 } |
| 403 virtual void Verify() OVERRIDE { | 403 virtual void Verify() override { |
| 404 std::string actual = prefs()->pref_service()->GetString(kPref1); | 404 std::string actual = prefs()->pref_service()->GetString(kPref1); |
| 405 EXPECT_EQ("val1", actual); | 405 EXPECT_EQ("val1", actual); |
| 406 } | 406 } |
| 407 }; | 407 }; |
| 408 TEST_F(ControlledPrefsDisableExtension, ControlledPrefsReenableExtension) { } | 408 TEST_F(ControlledPrefsDisableExtension, ControlledPrefsReenableExtension) { } |
| 409 | 409 |
| 410 // Mock class to test whether objects are deleted correctly. | 410 // Mock class to test whether objects are deleted correctly. |
| 411 class MockStringValue : public base::StringValue { | 411 class MockStringValue : public base::StringValue { |
| 412 public: | 412 public: |
| 413 explicit MockStringValue(const std::string& in_value) | 413 explicit MockStringValue(const std::string& in_value) |
| 414 : base::StringValue(in_value) { | 414 : base::StringValue(in_value) { |
| 415 } | 415 } |
| 416 virtual ~MockStringValue() { | 416 virtual ~MockStringValue() { |
| 417 Die(); | 417 Die(); |
| 418 } | 418 } |
| 419 MOCK_METHOD0(Die, void()); | 419 MOCK_METHOD0(Die, void()); |
| 420 }; | 420 }; |
| 421 | 421 |
| 422 class ControlledPrefsSetExtensionControlledPref | 422 class ControlledPrefsSetExtensionControlledPref |
| 423 : public ExtensionControlledPrefsTest { | 423 : public ExtensionControlledPrefsTest { |
| 424 public: | 424 public: |
| 425 virtual void Initialize() OVERRIDE { | 425 virtual void Initialize() override { |
| 426 MockStringValue* v1 = new MockStringValue("https://www.chromium.org"); | 426 MockStringValue* v1 = new MockStringValue("https://www.chromium.org"); |
| 427 MockStringValue* v2 = new MockStringValue("https://www.chromium.org"); | 427 MockStringValue* v2 = new MockStringValue("https://www.chromium.org"); |
| 428 MockStringValue* v1i = new MockStringValue("https://www.chromium.org"); | 428 MockStringValue* v1i = new MockStringValue("https://www.chromium.org"); |
| 429 MockStringValue* v2i = new MockStringValue("https://www.chromium.org"); | 429 MockStringValue* v2i = new MockStringValue("https://www.chromium.org"); |
| 430 // Ownership is taken, value shall not be deleted. | 430 // Ownership is taken, value shall not be deleted. |
| 431 EXPECT_CALL(*v1, Die()).Times(0); | 431 EXPECT_CALL(*v1, Die()).Times(0); |
| 432 EXPECT_CALL(*v1i, Die()).Times(0); | 432 EXPECT_CALL(*v1i, Die()).Times(0); |
| 433 InstallExtensionControlledPref(extension1(), kPref1, v1); | 433 InstallExtensionControlledPref(extension1(), kPref1, v1); |
| 434 InstallExtensionControlledPrefIncognito(extension1(), kPref1, v1i); | 434 InstallExtensionControlledPrefIncognito(extension1(), kPref1, v1i); |
| 435 testing::Mock::VerifyAndClearExpectations(v1); | 435 testing::Mock::VerifyAndClearExpectations(v1); |
| 436 testing::Mock::VerifyAndClearExpectations(v1i); | 436 testing::Mock::VerifyAndClearExpectations(v1i); |
| 437 // Make sure there is no memory leak and both values are deleted. | 437 // Make sure there is no memory leak and both values are deleted. |
| 438 EXPECT_CALL(*v1, Die()).Times(1); | 438 EXPECT_CALL(*v1, Die()).Times(1); |
| 439 EXPECT_CALL(*v1i, Die()).Times(1); | 439 EXPECT_CALL(*v1i, Die()).Times(1); |
| 440 EXPECT_CALL(*v2, Die()).Times(1); | 440 EXPECT_CALL(*v2, Die()).Times(1); |
| 441 EXPECT_CALL(*v2i, Die()).Times(1); | 441 EXPECT_CALL(*v2i, Die()).Times(1); |
| 442 InstallExtensionControlledPref(extension1(), kPref1, v2); | 442 InstallExtensionControlledPref(extension1(), kPref1, v2); |
| 443 InstallExtensionControlledPrefIncognito(extension1(), kPref1, v2i); | 443 InstallExtensionControlledPrefIncognito(extension1(), kPref1, v2i); |
| 444 prefs_.RecreateExtensionPrefs(); | 444 prefs_.RecreateExtensionPrefs(); |
| 445 testing::Mock::VerifyAndClearExpectations(v1); | 445 testing::Mock::VerifyAndClearExpectations(v1); |
| 446 testing::Mock::VerifyAndClearExpectations(v1i); | 446 testing::Mock::VerifyAndClearExpectations(v1i); |
| 447 testing::Mock::VerifyAndClearExpectations(v2); | 447 testing::Mock::VerifyAndClearExpectations(v2); |
| 448 testing::Mock::VerifyAndClearExpectations(v2i); | 448 testing::Mock::VerifyAndClearExpectations(v2i); |
| 449 } | 449 } |
| 450 | 450 |
| 451 virtual void Verify() OVERRIDE { | 451 virtual void Verify() override { |
| 452 } | 452 } |
| 453 }; | 453 }; |
| 454 TEST_F(ControlledPrefsSetExtensionControlledPref, | 454 TEST_F(ControlledPrefsSetExtensionControlledPref, |
| 455 ControlledPrefsSetExtensionControlledPref) { } | 455 ControlledPrefsSetExtensionControlledPref) { } |
| 456 | 456 |
| 457 // Tests that the switches::kDisableExtensions command-line flag prevents | 457 // Tests that the switches::kDisableExtensions command-line flag prevents |
| 458 // extension controlled preferences from being enacted. | 458 // extension controlled preferences from being enacted. |
| 459 class ControlledPrefsDisableExtensions : public ExtensionControlledPrefsTest { | 459 class ControlledPrefsDisableExtensions : public ExtensionControlledPrefsTest { |
| 460 public: | 460 public: |
| 461 ControlledPrefsDisableExtensions() | 461 ControlledPrefsDisableExtensions() |
| 462 : iteration_(0) {} | 462 : iteration_(0) {} |
| 463 virtual ~ControlledPrefsDisableExtensions() {} | 463 virtual ~ControlledPrefsDisableExtensions() {} |
| 464 virtual void Initialize() OVERRIDE { | 464 virtual void Initialize() override { |
| 465 InstallExtensionControlledPref( | 465 InstallExtensionControlledPref( |
| 466 extension1(), kPref1, new base::StringValue("val1")); | 466 extension1(), kPref1, new base::StringValue("val1")); |
| 467 // This becomes only active in the second verification phase. | 467 // This becomes only active in the second verification phase. |
| 468 prefs_.set_extensions_disabled(true); | 468 prefs_.set_extensions_disabled(true); |
| 469 } | 469 } |
| 470 virtual void Verify() OVERRIDE { | 470 virtual void Verify() override { |
| 471 std::string actual = prefs()->pref_service()->GetString(kPref1); | 471 std::string actual = prefs()->pref_service()->GetString(kPref1); |
| 472 if (iteration_ == 0) { | 472 if (iteration_ == 0) { |
| 473 EXPECT_EQ("val1", actual); | 473 EXPECT_EQ("val1", actual); |
| 474 ++iteration_; | 474 ++iteration_; |
| 475 } else { | 475 } else { |
| 476 EXPECT_EQ(kDefaultPref1, actual); | 476 EXPECT_EQ(kDefaultPref1, actual); |
| 477 } | 477 } |
| 478 } | 478 } |
| 479 | 479 |
| 480 private: | 480 private: |
| 481 int iteration_; | 481 int iteration_; |
| 482 }; | 482 }; |
| 483 TEST_F(ControlledPrefsDisableExtensions, ControlledPrefsDisableExtensions) { } | 483 TEST_F(ControlledPrefsDisableExtensions, ControlledPrefsDisableExtensions) { } |
| 484 | 484 |
| 485 } // namespace extensions | 485 } // namespace extensions |
| OLD | NEW |