OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/memory/ref_counted.h" | 5 #include "base/memory/ref_counted.h" |
6 #include "base/memory/scoped_ptr.h" | 6 #include "base/memory/scoped_ptr.h" |
7 #include "base/strings/string16.h" | 7 #include "base/strings/string16.h" |
8 #include "base/values.h" | 8 #include "base/values.h" |
9 #include "chrome/browser/extensions/extension_service.h" | 9 #include "chrome/browser/extensions/extension_service.h" |
10 #include "chrome/browser/extensions/extension_service_unittest.h" | 10 #include "chrome/browser/extensions/extension_service_test_base.h" |
11 #include "chrome/browser/extensions/pending_extension_manager.h" | 11 #include "chrome/browser/extensions/pending_extension_manager.h" |
12 #include "chrome/browser/extensions/shared_module_service.h" | 12 #include "chrome/browser/extensions/shared_module_service.h" |
13 #include "chrome/common/extensions/features/feature_channel.h" | 13 #include "chrome/common/extensions/features/feature_channel.h" |
14 #include "extensions/browser/extension_registry.h" | 14 #include "extensions/browser/extension_registry.h" |
15 #include "extensions/common/extension_builder.h" | 15 #include "extensions/common/extension_builder.h" |
16 #include "extensions/common/id_util.h" | 16 #include "extensions/common/id_util.h" |
17 #include "extensions/common/value_builder.h" | 17 #include "extensions/common/value_builder.h" |
18 #include "sync/api/string_ordinal.h" | 18 #include "sync/api/string_ordinal.h" |
19 | 19 |
20 namespace extensions { | 20 namespace extensions { |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
58 | 58 |
59 void SharedModuleServiceUnitTest::SetUp() { | 59 void SharedModuleServiceUnitTest::SetUp() { |
60 ExtensionServiceTestBase::SetUp(); | 60 ExtensionServiceTestBase::SetUp(); |
61 InitializeGoodInstalledExtensionService(); | 61 InitializeGoodInstalledExtensionService(); |
62 service_->Init(); | 62 service_->Init(); |
63 } | 63 } |
64 | 64 |
65 testing::AssertionResult SharedModuleServiceUnitTest::InstallExtension( | 65 testing::AssertionResult SharedModuleServiceUnitTest::InstallExtension( |
66 const Extension* extension) { | 66 const Extension* extension) { |
67 // Verify the extension is not already installed. | 67 // Verify the extension is not already installed. |
68 if (registry_->GetExtensionById(extension->id(), | 68 if (registry()->GetExtensionById(extension->id(), |
69 ExtensionRegistry::ENABLED)) { | 69 ExtensionRegistry::ENABLED)) { |
70 return testing::AssertionFailure() << "Extension already installed."; | 70 return testing::AssertionFailure() << "Extension already installed."; |
71 } | 71 } |
72 | 72 |
73 // Notify the service that the extension is installed. This adds it to the | 73 // Notify the service that the extension is installed. This adds it to the |
74 // registry, notifies interested parties, etc. | 74 // registry, notifies interested parties, etc. |
75 service_->OnExtensionInstalled(extension, | 75 service_->OnExtensionInstalled(extension, |
76 syncer::StringOrdinal(), | 76 syncer::StringOrdinal(), |
77 false, // No requirement errors. | 77 false, // No requirement errors. |
78 NOT_BLACKLISTED, | 78 NOT_BLACKLISTED, |
79 false, // Not ephemeral. | 79 false, // Not ephemeral. |
80 false); // Don't wait for idle. | 80 false); // Don't wait for idle. |
81 | 81 |
82 // Verify that the extension is now installed. | 82 // Verify that the extension is now installed. |
83 if (!registry_->GetExtensionById(extension->id(), | 83 if (!registry()->GetExtensionById(extension->id(), |
84 ExtensionRegistry::ENABLED)) { | 84 ExtensionRegistry::ENABLED)) { |
85 return testing::AssertionFailure() << "Could not install extension."; | 85 return testing::AssertionFailure() << "Could not install extension."; |
86 } | 86 } |
87 | 87 |
88 return testing::AssertionSuccess(); | 88 return testing::AssertionSuccess(); |
89 } | 89 } |
90 | 90 |
91 TEST_F(SharedModuleServiceUnitTest, AddDependentSharedModules) { | 91 TEST_F(SharedModuleServiceUnitTest, AddDependentSharedModules) { |
92 // Create an extension that has a dependency. | 92 // Create an extension that has a dependency. |
93 std::string import_id = id_util::GenerateId("id"); | 93 std::string import_id = id_util::GenerateId("id"); |
94 std::string extension_id = id_util::GenerateId("extension_id"); | 94 std::string extension_id = id_util::GenerateId("extension_id"); |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
134 // Uninstall the extension that imports our module. | 134 // Uninstall the extension that imports our module. |
135 base::string16 error; | 135 base::string16 error; |
136 service_->UninstallExtension(importing_extension->id(), | 136 service_->UninstallExtension(importing_extension->id(), |
137 false, // Not external uninstall. | 137 false, // Not external uninstall. |
138 &error); | 138 &error); |
139 EXPECT_TRUE(error.empty()); | 139 EXPECT_TRUE(error.empty()); |
140 | 140 |
141 // Since the module was only referenced by that single extension, it should | 141 // Since the module was only referenced by that single extension, it should |
142 // have been uninstalled as a side-effect of uninstalling the extension that | 142 // have been uninstalled as a side-effect of uninstalling the extension that |
143 // depended upon it. | 143 // depended upon it. |
144 EXPECT_FALSE(registry_->GetExtensionById(shared_module->id(), | 144 EXPECT_FALSE(registry()->GetExtensionById(shared_module->id(), |
145 ExtensionRegistry::EVERYTHING)); | 145 ExtensionRegistry::EVERYTHING)); |
146 } | 146 } |
147 | 147 |
148 TEST_F(SharedModuleServiceUnitTest, WhitelistedImports) { | 148 TEST_F(SharedModuleServiceUnitTest, WhitelistedImports) { |
149 std::string whitelisted_id = id_util::GenerateId("whitelisted"); | 149 std::string whitelisted_id = id_util::GenerateId("whitelisted"); |
150 std::string nonwhitelisted_id = id_util::GenerateId("nonwhitelisted"); | 150 std::string nonwhitelisted_id = id_util::GenerateId("nonwhitelisted"); |
151 // Create a module which exports to a restricted whitelist. | 151 // Create a module which exports to a restricted whitelist. |
152 scoped_ptr<base::DictionaryValue> manifest = | 152 scoped_ptr<base::DictionaryValue> manifest = |
153 DictionaryBuilder() | 153 DictionaryBuilder() |
154 .Set("name", "Shared Module") | 154 .Set("name", "Shared Module") |
155 .Set("version", "1.0") | 155 .Set("version", "1.0") |
(...skipping 17 matching lines...) Expand all Loading... |
173 CreateExtensionImportingModule(shared_module->id(), whitelisted_id); | 173 CreateExtensionImportingModule(shared_module->id(), whitelisted_id); |
174 EXPECT_TRUE(InstallExtension(whitelisted_extension)); | 174 EXPECT_TRUE(InstallExtension(whitelisted_extension)); |
175 | 175 |
176 // Try to install an extension with an ID that is not whitelisted. | 176 // Try to install an extension with an ID that is not whitelisted. |
177 scoped_refptr<Extension> nonwhitelisted_extension = | 177 scoped_refptr<Extension> nonwhitelisted_extension = |
178 CreateExtensionImportingModule(shared_module->id(), nonwhitelisted_id); | 178 CreateExtensionImportingModule(shared_module->id(), nonwhitelisted_id); |
179 EXPECT_FALSE(InstallExtension(nonwhitelisted_extension)); | 179 EXPECT_FALSE(InstallExtension(nonwhitelisted_extension)); |
180 } | 180 } |
181 | 181 |
182 } // namespace extensions | 182 } // namespace extensions |
OLD | NEW |