Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 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 "base/message_loop.h" | 5 #include "base/message_loop.h" |
| 6 #include "base/string_number_conversions.h" | 6 #include "base/string_number_conversions.h" |
| 7 #include "base/values.h" | 7 #include "base/values.h" |
| 8 #include "chrome/browser/extensions/blacklist.h" | 8 #include "chrome/browser/extensions/blacklist.h" |
| 9 #include "chrome/browser/extensions/extension_prefs.h" | 9 #include "chrome/browser/extensions/extension_prefs.h" |
| 10 #include "chrome/browser/extensions/standard_management_policy_provider.h" | 10 #include "chrome/browser/extensions/standard_management_policy_provider.h" |
| 11 #include "chrome/browser/extensions/test_extension_prefs.h" | 11 #include "chrome/browser/extensions/test_extension_prefs.h" |
| 12 #include "chrome/common/extensions/extension_manifest_constants.h" | 12 #include "chrome/common/extensions/extension_manifest_constants.h" |
| 13 #include "content/public/test/test_browser_thread.h" | 13 #include "content/public/test/test_browser_thread.h" |
| 14 #include "testing/gtest/include/gtest/gtest.h" | 14 #include "testing/gtest/include/gtest/gtest.h" |
| 15 | 15 |
| 16 namespace extensions { | 16 namespace extensions { |
| 17 | 17 |
| 18 class StandardManagementPolicyProviderTest : public testing::Test { | 18 class StandardManagementPolicyProviderTest : public testing::Test { |
| 19 public: | 19 public: |
| 20 StandardManagementPolicyProviderTest() | 20 StandardManagementPolicyProviderTest() |
| 21 : ui_thread_(content::BrowserThread::UI, &message_loop_), | 21 : ui_thread_(content::BrowserThread::UI, &message_loop_), |
| 22 file_thread_(content::BrowserThread::FILE, &message_loop_), | 22 file_thread_(content::BrowserThread::FILE, &message_loop_), |
| 23 prefs_(message_loop_.message_loop_proxy()), | 23 prefs_(message_loop_.message_loop_proxy()), |
| 24 blacklist_(prefs()), | 24 provider_(prefs()) { |
| 25 provider_(prefs(), &blacklist_) { | |
| 26 } | 25 } |
| 27 | 26 |
| 28 | |
| 29 protected: | 27 protected: |
| 30 ExtensionPrefs* prefs() { | 28 ExtensionPrefs* prefs() { |
| 31 return prefs_.prefs(); | 29 return prefs_.prefs(); |
| 32 } | 30 } |
| 33 | 31 |
| 34 scoped_refptr<const Extension> CreateExtension(Extension::Location location, | 32 scoped_refptr<const Extension> CreateExtension(Extension::Location location, |
| 35 bool required) { | 33 bool required) { |
| 36 base::DictionaryValue values; | 34 base::DictionaryValue values; |
| 37 values.SetString(extension_manifest_keys::kName, "test"); | 35 values.SetString(extension_manifest_keys::kName, "test"); |
| 38 values.SetString(extension_manifest_keys::kVersion, "0.1"); | 36 values.SetString(extension_manifest_keys::kVersion, "0.1"); |
| 39 std::string error; | 37 std::string error; |
| 40 scoped_refptr<const Extension> extension = Extension::Create( | 38 scoped_refptr<const Extension> extension = Extension::Create( |
| 41 FilePath(), location, values, Extension::NO_FLAGS, &error); | 39 FilePath(), location, values, Extension::NO_FLAGS, &error); |
| 42 CHECK(extension.get()) << error; | 40 CHECK(extension.get()) << error; |
| 43 return extension; | 41 return extension; |
| 44 } | 42 } |
| 45 | 43 |
| 46 MessageLoop message_loop_; | 44 MessageLoop message_loop_; |
| 47 content::TestBrowserThread ui_thread_; | 45 content::TestBrowserThread ui_thread_; |
| 48 content::TestBrowserThread file_thread_; | 46 content::TestBrowserThread file_thread_; |
| 49 | 47 |
| 50 TestExtensionPrefs prefs_; | 48 TestExtensionPrefs prefs_; |
| 51 | 49 |
| 52 Blacklist blacklist_; | |
| 53 | |
| 54 StandardManagementPolicyProvider provider_; | 50 StandardManagementPolicyProvider provider_; |
| 55 }; | 51 }; |
| 56 | 52 |
| 57 // Tests various areas of blacklist functionality. | 53 // Tests various areas of blacklist functionality. |
| 54 /* | |
|
asargent_no_longer_on_chrome
2012/11/30 21:44:22
Is there a reason you just commented this out inst
not at google - send to devlin
2012/11/30 23:09:54
Oh, I didn't notice. Oops. Yeah I incorporated the
| |
| 58 TEST_F(StandardManagementPolicyProviderTest, Blacklist) { | 55 TEST_F(StandardManagementPolicyProviderTest, Blacklist) { |
| 59 std::string not_installed_id = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"; | 56 std::string not_installed_id = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"; |
| 60 | 57 |
| 61 // Install 5 extensions. | 58 // Install 5 extensions. |
| 62 ExtensionList extensions; | 59 ExtensionList extensions; |
| 63 for (int i = 0; i < 5; i++) { | 60 for (int i = 0; i < 5; i++) { |
| 64 std::string name = "test" + base::IntToString(i); | 61 std::string name = "test" + base::IntToString(i); |
| 65 extensions.push_back(prefs_.AddExtension(name)); | 62 extensions.push_back(prefs_.AddExtension(name)); |
| 66 } | 63 } |
| 67 EXPECT_EQ(NULL, | 64 EXPECT_EQ(NULL, |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 88 // extensions data. | 85 // extensions data. |
| 89 scoped_ptr<ExtensionPrefs::ExtensionsInfo> info( | 86 scoped_ptr<ExtensionPrefs::ExtensionsInfo> info( |
| 90 prefs()->GetInstalledExtensionsInfo()); | 87 prefs()->GetInstalledExtensionsInfo()); |
| 91 EXPECT_EQ(4u, info->size()); | 88 EXPECT_EQ(4u, info->size()); |
| 92 ExtensionPrefs::ExtensionsInfo::iterator info_iter; | 89 ExtensionPrefs::ExtensionsInfo::iterator info_iter; |
| 93 for (info_iter = info->begin(); info_iter != info->end(); ++info_iter) { | 90 for (info_iter = info->begin(); info_iter != info->end(); ++info_iter) { |
| 94 ExtensionInfo* extension_info = info_iter->get(); | 91 ExtensionInfo* extension_info = info_iter->get(); |
| 95 EXPECT_NE(extensions[0]->id(), extension_info->extension_id); | 92 EXPECT_NE(extensions[0]->id(), extension_info->extension_id); |
| 96 } | 93 } |
| 97 } | 94 } |
| 95 */ | |
| 98 | 96 |
| 99 // Tests the behavior of the ManagementPolicy provider methods for an | 97 // Tests the behavior of the ManagementPolicy provider methods for an |
| 100 // extension required by policy. | 98 // extension required by policy. |
| 101 TEST_F(StandardManagementPolicyProviderTest, RequiredExtension) { | 99 TEST_F(StandardManagementPolicyProviderTest, RequiredExtension) { |
| 102 scoped_refptr<const Extension> extension = | 100 scoped_refptr<const Extension> extension = |
| 103 CreateExtension(Extension::EXTERNAL_POLICY_DOWNLOAD, true); | 101 CreateExtension(Extension::EXTERNAL_POLICY_DOWNLOAD, true); |
| 104 | 102 |
| 105 string16 error16; | 103 string16 error16; |
| 106 EXPECT_TRUE(provider_.UserMayLoad(extension.get(), &error16)); | 104 EXPECT_TRUE(provider_.UserMayLoad(extension.get(), &error16)); |
| 107 EXPECT_EQ(string16(), error16); | 105 EXPECT_EQ(string16(), error16); |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 123 string16 error16; | 121 string16 error16; |
| 124 EXPECT_TRUE(provider_.UserMayLoad(extension.get(), &error16)); | 122 EXPECT_TRUE(provider_.UserMayLoad(extension.get(), &error16)); |
| 125 EXPECT_EQ(string16(), error16); | 123 EXPECT_EQ(string16(), error16); |
| 126 EXPECT_TRUE(provider_.UserMayModifySettings(extension.get(), &error16)); | 124 EXPECT_TRUE(provider_.UserMayModifySettings(extension.get(), &error16)); |
| 127 EXPECT_EQ(string16(), error16); | 125 EXPECT_EQ(string16(), error16); |
| 128 EXPECT_FALSE(provider_.MustRemainEnabled(extension.get(), &error16)); | 126 EXPECT_FALSE(provider_.MustRemainEnabled(extension.get(), &error16)); |
| 129 EXPECT_EQ(string16(), error16); | 127 EXPECT_EQ(string16(), error16); |
| 130 } | 128 } |
| 131 | 129 |
| 132 } // namespace extensions | 130 } // namespace extensions |
| OLD | NEW |