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 <stddef.h> | 5 #include <stddef.h> |
6 | 6 |
7 #include <memory> | 7 #include <memory> |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/macros.h" | 10 #include "base/macros.h" |
11 #include "base/memory/ref_counted.h" | 11 #include "base/memory/ptr_util.h" |
12 #include "base/values.h" | 12 #include "base/values.h" |
13 #include "chrome/browser/extensions/api/content_settings/content_settings_servic
e.h" | 13 #include "chrome/browser/extensions/api/content_settings/content_settings_servic
e.h" |
14 #include "chrome/browser/extensions/api/preference/preference_api.h" | 14 #include "chrome/browser/extensions/api/preference/preference_api.h" |
15 #include "chrome/browser/extensions/extension_prefs_unittest.h" | 15 #include "chrome/browser/extensions/extension_prefs_unittest.h" |
16 #include "chrome/test/base/testing_profile.h" | 16 #include "chrome/test/base/testing_profile.h" |
17 #include "components/pref_registry/pref_registry_syncable.h" | 17 #include "components/pref_registry/pref_registry_syncable.h" |
18 #include "components/prefs/mock_pref_change_callback.h" | 18 #include "components/prefs/mock_pref_change_callback.h" |
19 #include "extensions/browser/extension_prefs.h" | 19 #include "extensions/browser/extension_prefs.h" |
20 #include "extensions/common/extension.h" | 20 #include "extensions/common/extension.h" |
21 #include "testing/gtest/include/gtest/gtest.h" | 21 #include "testing/gtest/include/gtest/gtest.h" |
(...skipping 382 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
404 Extension::DISABLE_USER_ACTION); | 404 Extension::DISABLE_USER_ACTION); |
405 prefs()->SetExtensionEnabled(extension1()->id()); | 405 prefs()->SetExtensionEnabled(extension1()->id()); |
406 } | 406 } |
407 void Verify() override { | 407 void Verify() override { |
408 std::string actual = prefs()->pref_service()->GetString(kPref1); | 408 std::string actual = prefs()->pref_service()->GetString(kPref1); |
409 EXPECT_EQ("val1", actual); | 409 EXPECT_EQ("val1", actual); |
410 } | 410 } |
411 }; | 411 }; |
412 TEST_F(ControlledPrefsDisableExtension, ControlledPrefsReenableExtension) { } | 412 TEST_F(ControlledPrefsDisableExtension, ControlledPrefsReenableExtension) { } |
413 | 413 |
414 // Mock class to test whether objects are deleted correctly. | |
415 class MockStringValue : public base::StringValue { | |
416 public: | |
417 explicit MockStringValue(const std::string& in_value) | |
418 : base::StringValue(in_value) { | |
419 } | |
420 virtual ~MockStringValue() { | |
421 Die(); | |
422 } | |
423 MOCK_METHOD0(Die, void()); | |
424 }; | |
425 | |
426 class ControlledPrefsSetExtensionControlledPref | 414 class ControlledPrefsSetExtensionControlledPref |
427 : public ExtensionControlledPrefsTest { | 415 : public ExtensionControlledPrefsTest { |
428 public: | 416 public: |
429 void Initialize() override { | 417 void Initialize() override { |
430 MockStringValue* v1 = new MockStringValue("https://www.chromium.org"); | 418 base::StringValue* v1 = new base::StringValue("https://www.chromium.org"); |
431 MockStringValue* v2 = new MockStringValue("https://www.chromium.org"); | 419 base::StringValue* v2 = new base::StringValue("https://www.chromium.org"); |
432 MockStringValue* v1i = new MockStringValue("https://www.chromium.org"); | 420 base::StringValue* v1i = new base::StringValue("https://www.chromium.org"); |
433 MockStringValue* v2i = new MockStringValue("https://www.chromium.org"); | 421 base::StringValue* v2i = new base::StringValue("https://www.chromium.org"); |
434 // Ownership is taken, value shall not be deleted. | 422 // Ownership is taken, value shall not be deleted. |
435 EXPECT_CALL(*v1, Die()).Times(0); | |
436 EXPECT_CALL(*v1i, Die()).Times(0); | |
437 InstallExtensionControlledPref(extension1(), kPref1, v1); | 423 InstallExtensionControlledPref(extension1(), kPref1, v1); |
438 InstallExtensionControlledPrefIncognito(extension1(), kPref1, v1i); | 424 InstallExtensionControlledPrefIncognito(extension1(), kPref1, v1i); |
439 testing::Mock::VerifyAndClearExpectations(v1); | |
440 testing::Mock::VerifyAndClearExpectations(v1i); | |
441 // Make sure there is no memory leak and both values are deleted. | 425 // Make sure there is no memory leak and both values are deleted. |
442 EXPECT_CALL(*v1, Die()).Times(1); | |
443 EXPECT_CALL(*v1i, Die()).Times(1); | |
444 EXPECT_CALL(*v2, Die()).Times(1); | |
445 EXPECT_CALL(*v2i, Die()).Times(1); | |
446 InstallExtensionControlledPref(extension1(), kPref1, v2); | 426 InstallExtensionControlledPref(extension1(), kPref1, v2); |
447 InstallExtensionControlledPrefIncognito(extension1(), kPref1, v2i); | 427 InstallExtensionControlledPrefIncognito(extension1(), kPref1, v2i); |
448 prefs_.RecreateExtensionPrefs(); | 428 prefs_.RecreateExtensionPrefs(); |
449 testing::Mock::VerifyAndClearExpectations(v1); | |
450 testing::Mock::VerifyAndClearExpectations(v1i); | |
451 testing::Mock::VerifyAndClearExpectations(v2); | |
452 testing::Mock::VerifyAndClearExpectations(v2i); | |
453 } | 429 } |
454 | 430 |
455 void Verify() override {} | 431 void Verify() override {} |
456 }; | 432 }; |
457 TEST_F(ControlledPrefsSetExtensionControlledPref, | 433 TEST_F(ControlledPrefsSetExtensionControlledPref, |
458 ControlledPrefsSetExtensionControlledPref) { } | 434 ControlledPrefsSetExtensionControlledPref) { } |
459 | 435 |
460 // Tests that the switches::kDisableExtensions command-line flag prevents | 436 // Tests that the switches::kDisableExtensions command-line flag prevents |
461 // extension controlled preferences from being enacted. | 437 // extension controlled preferences from being enacted. |
462 class ControlledPrefsDisableExtensions : public ExtensionControlledPrefsTest { | 438 class ControlledPrefsDisableExtensions : public ExtensionControlledPrefsTest { |
(...skipping 16 matching lines...) Expand all Loading... |
479 EXPECT_EQ(kDefaultPref1, actual); | 455 EXPECT_EQ(kDefaultPref1, actual); |
480 } | 456 } |
481 } | 457 } |
482 | 458 |
483 private: | 459 private: |
484 int iteration_; | 460 int iteration_; |
485 }; | 461 }; |
486 TEST_F(ControlledPrefsDisableExtensions, ControlledPrefsDisableExtensions) { } | 462 TEST_F(ControlledPrefsDisableExtensions, ControlledPrefsDisableExtensions) { } |
487 | 463 |
488 } // namespace extensions | 464 } // namespace extensions |
OLD | NEW |