| 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" |
| (...skipping 11 matching lines...) Expand all Loading... |
| 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 provider_(prefs()) { | 24 provider_(prefs()) { |
| 25 } | 25 } |
| 26 | 26 |
| 27 protected: | 27 protected: |
| 28 ExtensionPrefs* prefs() { | 28 ExtensionPrefs* prefs() { |
| 29 return prefs_.prefs(); | 29 return prefs_.prefs(); |
| 30 } | 30 } |
| 31 | 31 |
| 32 scoped_refptr<const Extension> CreateExtension(Extension::Location location, | 32 scoped_refptr<const Extension> CreateExtension(Manifest::Location location, |
| 33 bool required) { | 33 bool required) { |
| 34 base::DictionaryValue values; | 34 base::DictionaryValue values; |
| 35 values.SetString(extension_manifest_keys::kName, "test"); | 35 values.SetString(extension_manifest_keys::kName, "test"); |
| 36 values.SetString(extension_manifest_keys::kVersion, "0.1"); | 36 values.SetString(extension_manifest_keys::kVersion, "0.1"); |
| 37 std::string error; | 37 std::string error; |
| 38 scoped_refptr<const Extension> extension = Extension::Create( | 38 scoped_refptr<const Extension> extension = Extension::Create( |
| 39 FilePath(), location, values, Extension::NO_FLAGS, &error); | 39 FilePath(), location, values, Extension::NO_FLAGS, &error); |
| 40 CHECK(extension.get()) << error; | 40 CHECK(extension.get()) << error; |
| 41 return extension; | 41 return extension; |
| 42 } | 42 } |
| 43 | 43 |
| 44 MessageLoop message_loop_; | 44 MessageLoop message_loop_; |
| 45 content::TestBrowserThread ui_thread_; | 45 content::TestBrowserThread ui_thread_; |
| 46 content::TestBrowserThread file_thread_; | 46 content::TestBrowserThread file_thread_; |
| 47 | 47 |
| 48 TestExtensionPrefs prefs_; | 48 TestExtensionPrefs prefs_; |
| 49 | 49 |
| 50 StandardManagementPolicyProvider provider_; | 50 StandardManagementPolicyProvider provider_; |
| 51 }; | 51 }; |
| 52 | 52 |
| 53 // Tests the behavior of the ManagementPolicy provider methods for an | 53 // Tests the behavior of the ManagementPolicy provider methods for an |
| 54 // extension required by policy. | 54 // extension required by policy. |
| 55 TEST_F(StandardManagementPolicyProviderTest, RequiredExtension) { | 55 TEST_F(StandardManagementPolicyProviderTest, RequiredExtension) { |
| 56 scoped_refptr<const Extension> extension = | 56 scoped_refptr<const Extension> extension = |
| 57 CreateExtension(Extension::EXTERNAL_POLICY_DOWNLOAD, true); | 57 CreateExtension(Manifest::EXTERNAL_POLICY_DOWNLOAD, true); |
| 58 | 58 |
| 59 string16 error16; | 59 string16 error16; |
| 60 EXPECT_TRUE(provider_.UserMayLoad(extension.get(), &error16)); | 60 EXPECT_TRUE(provider_.UserMayLoad(extension.get(), &error16)); |
| 61 EXPECT_EQ(string16(), error16); | 61 EXPECT_EQ(string16(), error16); |
| 62 | 62 |
| 63 // We won't check the exact wording of the error, but it should say | 63 // We won't check the exact wording of the error, but it should say |
| 64 // something. | 64 // something. |
| 65 EXPECT_FALSE(provider_.UserMayModifySettings(extension.get(), &error16)); | 65 EXPECT_FALSE(provider_.UserMayModifySettings(extension.get(), &error16)); |
| 66 EXPECT_NE(string16(), error16); | 66 EXPECT_NE(string16(), error16); |
| 67 EXPECT_TRUE(provider_.MustRemainEnabled(extension.get(), &error16)); | 67 EXPECT_TRUE(provider_.MustRemainEnabled(extension.get(), &error16)); |
| 68 EXPECT_NE(string16(), error16); | 68 EXPECT_NE(string16(), error16); |
| 69 } | 69 } |
| 70 | 70 |
| 71 // Tests the behavior of the ManagementPolicy provider methods for an | 71 // Tests the behavior of the ManagementPolicy provider methods for an |
| 72 // extension required by policy. | 72 // extension required by policy. |
| 73 TEST_F(StandardManagementPolicyProviderTest, NotRequiredExtension) { | 73 TEST_F(StandardManagementPolicyProviderTest, NotRequiredExtension) { |
| 74 scoped_refptr<const Extension> extension = | 74 scoped_refptr<const Extension> extension = |
| 75 CreateExtension(Extension::INTERNAL, false); | 75 CreateExtension(Manifest::INTERNAL, false); |
| 76 | 76 |
| 77 string16 error16; | 77 string16 error16; |
| 78 EXPECT_TRUE(provider_.UserMayLoad(extension.get(), &error16)); | 78 EXPECT_TRUE(provider_.UserMayLoad(extension.get(), &error16)); |
| 79 EXPECT_EQ(string16(), error16); | 79 EXPECT_EQ(string16(), error16); |
| 80 EXPECT_TRUE(provider_.UserMayModifySettings(extension.get(), &error16)); | 80 EXPECT_TRUE(provider_.UserMayModifySettings(extension.get(), &error16)); |
| 81 EXPECT_EQ(string16(), error16); | 81 EXPECT_EQ(string16(), error16); |
| 82 EXPECT_FALSE(provider_.MustRemainEnabled(extension.get(), &error16)); | 82 EXPECT_FALSE(provider_.MustRemainEnabled(extension.get(), &error16)); |
| 83 EXPECT_EQ(string16(), error16); | 83 EXPECT_EQ(string16(), error16); |
| 84 } | 84 } |
| 85 | 85 |
| 86 } // namespace extensions | 86 } // namespace extensions |
| OLD | NEW |