| 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_test_base.h" | 10 #include "chrome/browser/extensions/extension_service_test_base.h" |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 107 CreateExtensionImportingModule(import_id, extension_id, "1.0"); | 107 CreateExtensionImportingModule(import_id, extension_id, "1.0"); |
| 108 | 108 |
| 109 PendingExtensionManager* pending_extension_manager = | 109 PendingExtensionManager* pending_extension_manager = |
| 110 service()->pending_extension_manager(); | 110 service()->pending_extension_manager(); |
| 111 | 111 |
| 112 // Verify that we don't currently want to install the imported module. | 112 // Verify that we don't currently want to install the imported module. |
| 113 EXPECT_FALSE(pending_extension_manager->IsIdPending(import_id)); | 113 EXPECT_FALSE(pending_extension_manager->IsIdPending(import_id)); |
| 114 | 114 |
| 115 // Try to satisfy imports for the extension. This should queue the imported | 115 // Try to satisfy imports for the extension. This should queue the imported |
| 116 // module's installation. | 116 // module's installation. |
| 117 service()->shared_module_service()->SatisfyImports(extension); | 117 service()->shared_module_service()->SatisfyImports(extension.get()); |
| 118 EXPECT_TRUE(pending_extension_manager->IsIdPending(import_id)); | 118 EXPECT_TRUE(pending_extension_manager->IsIdPending(import_id)); |
| 119 } | 119 } |
| 120 | 120 |
| 121 TEST_F(SharedModuleServiceUnitTest, PruneSharedModulesOnUninstall) { | 121 TEST_F(SharedModuleServiceUnitTest, PruneSharedModulesOnUninstall) { |
| 122 // Create a module which exports a resource, and install it. | 122 // Create a module which exports a resource, and install it. |
| 123 scoped_ptr<base::DictionaryValue> manifest = | 123 scoped_ptr<base::DictionaryValue> manifest = |
| 124 DictionaryBuilder() | 124 DictionaryBuilder() |
| 125 .Set("name", "Shared Module") | 125 .Set("name", "Shared Module") |
| 126 .Set("version", "1.0") | 126 .Set("version", "1.0") |
| 127 .Set("manifest_version", 2) | 127 .Set("manifest_version", 2) |
| 128 .Set("export", | 128 .Set("export", |
| 129 DictionaryBuilder().Set("resources", | 129 DictionaryBuilder().Set("resources", |
| 130 ListBuilder().Append("foo.js"))).Build(); | 130 ListBuilder().Append("foo.js"))).Build(); |
| 131 scoped_refptr<Extension> shared_module = | 131 scoped_refptr<Extension> shared_module = |
| 132 ExtensionBuilder() | 132 ExtensionBuilder() |
| 133 .SetManifest(manifest.Pass()) | 133 .SetManifest(manifest.Pass()) |
| 134 .AddFlags(Extension::FROM_WEBSTORE) | 134 .AddFlags(Extension::FROM_WEBSTORE) |
| 135 .SetID(crx_file::id_util::GenerateId("shared_module")) | 135 .SetID(crx_file::id_util::GenerateId("shared_module")) |
| 136 .Build(); | 136 .Build(); |
| 137 | 137 |
| 138 EXPECT_TRUE(InstallExtension(shared_module, false)); | 138 EXPECT_TRUE(InstallExtension(shared_module.get(), false)); |
| 139 | 139 |
| 140 std::string extension_id = crx_file::id_util::GenerateId("extension_id"); | 140 std::string extension_id = crx_file::id_util::GenerateId("extension_id"); |
| 141 // Create and install an extension that imports our new module. | 141 // Create and install an extension that imports our new module. |
| 142 scoped_refptr<Extension> importing_extension = | 142 scoped_refptr<Extension> importing_extension = |
| 143 CreateExtensionImportingModule(shared_module->id(), extension_id, "1.0"); | 143 CreateExtensionImportingModule(shared_module->id(), extension_id, "1.0"); |
| 144 EXPECT_TRUE(InstallExtension(importing_extension, false)); | 144 EXPECT_TRUE(InstallExtension(importing_extension.get(), false)); |
| 145 | 145 |
| 146 // Uninstall the extension that imports our module. | 146 // Uninstall the extension that imports our module. |
| 147 base::string16 error; | 147 base::string16 error; |
| 148 service()->UninstallExtension(importing_extension->id(), | 148 service()->UninstallExtension(importing_extension->id(), |
| 149 extensions::UNINSTALL_REASON_FOR_TESTING, | 149 extensions::UNINSTALL_REASON_FOR_TESTING, |
| 150 base::Bind(&base::DoNothing), | 150 base::Bind(&base::DoNothing), |
| 151 &error); | 151 &error); |
| 152 EXPECT_TRUE(error.empty()); | 152 EXPECT_TRUE(error.empty()); |
| 153 | 153 |
| 154 // Since the module was only referenced by that single extension, it should | 154 // Since the module was only referenced by that single extension, it should |
| (...skipping 12 matching lines...) Expand all Loading... |
| 167 .Set("manifest_version", 2) | 167 .Set("manifest_version", 2) |
| 168 .Set("export", | 168 .Set("export", |
| 169 DictionaryBuilder().Set("resources", | 169 DictionaryBuilder().Set("resources", |
| 170 ListBuilder().Append("foo.js"))).Build(); | 170 ListBuilder().Append("foo.js"))).Build(); |
| 171 scoped_refptr<Extension> shared_module_1 = | 171 scoped_refptr<Extension> shared_module_1 = |
| 172 ExtensionBuilder() | 172 ExtensionBuilder() |
| 173 .SetManifest(manifest_1.Pass()) | 173 .SetManifest(manifest_1.Pass()) |
| 174 .AddFlags(Extension::FROM_WEBSTORE) | 174 .AddFlags(Extension::FROM_WEBSTORE) |
| 175 .SetID(crx_file::id_util::GenerateId("shared_module_1")) | 175 .SetID(crx_file::id_util::GenerateId("shared_module_1")) |
| 176 .Build(); | 176 .Build(); |
| 177 EXPECT_TRUE(InstallExtension(shared_module_1, false)); | 177 EXPECT_TRUE(InstallExtension(shared_module_1.get(), false)); |
| 178 | 178 |
| 179 scoped_ptr<base::DictionaryValue> manifest_2 = | 179 scoped_ptr<base::DictionaryValue> manifest_2 = |
| 180 DictionaryBuilder() | 180 DictionaryBuilder() |
| 181 .Set("name", "Shared Module 2") | 181 .Set("name", "Shared Module 2") |
| 182 .Set("version", "1.0") | 182 .Set("version", "1.0") |
| 183 .Set("manifest_version", 2) | 183 .Set("manifest_version", 2) |
| 184 .Set("export", | 184 .Set("export", |
| 185 DictionaryBuilder().Set("resources", | 185 DictionaryBuilder().Set("resources", |
| 186 ListBuilder().Append("foo.js"))).Build(); | 186 ListBuilder().Append("foo.js"))).Build(); |
| 187 scoped_refptr<Extension> shared_module_2 = | 187 scoped_refptr<Extension> shared_module_2 = |
| 188 ExtensionBuilder() | 188 ExtensionBuilder() |
| 189 .SetManifest(manifest_2.Pass()) | 189 .SetManifest(manifest_2.Pass()) |
| 190 .AddFlags(Extension::FROM_WEBSTORE) | 190 .AddFlags(Extension::FROM_WEBSTORE) |
| 191 .SetID(crx_file::id_util::GenerateId("shared_module_2")) | 191 .SetID(crx_file::id_util::GenerateId("shared_module_2")) |
| 192 .Build(); | 192 .Build(); |
| 193 EXPECT_TRUE(InstallExtension(shared_module_2, false)); | 193 EXPECT_TRUE(InstallExtension(shared_module_2.get(), false)); |
| 194 | 194 |
| 195 std::string extension_id = crx_file::id_util::GenerateId("extension_id"); | 195 std::string extension_id = crx_file::id_util::GenerateId("extension_id"); |
| 196 | 196 |
| 197 // Create and install an extension v1.0 that imports our new module 1. | 197 // Create and install an extension v1.0 that imports our new module 1. |
| 198 scoped_refptr<Extension> importing_extension_1 = | 198 scoped_refptr<Extension> importing_extension_1 = |
| 199 CreateExtensionImportingModule(shared_module_1->id(), | 199 CreateExtensionImportingModule(shared_module_1->id(), |
| 200 extension_id, | 200 extension_id, |
| 201 "1.0"); | 201 "1.0"); |
| 202 EXPECT_TRUE(InstallExtension(importing_extension_1, false)); | 202 EXPECT_TRUE(InstallExtension(importing_extension_1.get(), false)); |
| 203 | 203 |
| 204 // Create and install a new version of the extension that imports our new | 204 // Create and install a new version of the extension that imports our new |
| 205 // module 2. | 205 // module 2. |
| 206 scoped_refptr<Extension> importing_extension_2 = | 206 scoped_refptr<Extension> importing_extension_2 = |
| 207 CreateExtensionImportingModule(shared_module_2->id(), | 207 CreateExtensionImportingModule(shared_module_2->id(), |
| 208 extension_id, | 208 extension_id, |
| 209 "1.1"); | 209 "1.1"); |
| 210 EXPECT_TRUE(InstallExtension(importing_extension_2, true)); | 210 EXPECT_TRUE(InstallExtension(importing_extension_2.get(), true)); |
| 211 | 211 |
| 212 // Since the extension v1.1 depends the module 2 insteand module 1. | 212 // Since the extension v1.1 depends the module 2 insteand module 1. |
| 213 // So the module 1 should be uninstalled. | 213 // So the module 1 should be uninstalled. |
| 214 EXPECT_FALSE(registry()->GetExtensionById(shared_module_1->id(), | 214 EXPECT_FALSE(registry()->GetExtensionById(shared_module_1->id(), |
| 215 ExtensionRegistry::EVERYTHING)); | 215 ExtensionRegistry::EVERYTHING)); |
| 216 EXPECT_TRUE(registry()->GetExtensionById(shared_module_2->id(), | 216 EXPECT_TRUE(registry()->GetExtensionById(shared_module_2->id(), |
| 217 ExtensionRegistry::EVERYTHING)); | 217 ExtensionRegistry::EVERYTHING)); |
| 218 | 218 |
| 219 // Create and install a new version of the extension that does not import any | 219 // Create and install a new version of the extension that does not import any |
| 220 // module. | 220 // module. |
| 221 scoped_refptr<Extension> importing_extension_3 = | 221 scoped_refptr<Extension> importing_extension_3 = |
| 222 CreateExtensionImportingModule("", extension_id, "1.2"); | 222 CreateExtensionImportingModule("", extension_id, "1.2"); |
| 223 EXPECT_TRUE(InstallExtension(importing_extension_3, true)); | 223 EXPECT_TRUE(InstallExtension(importing_extension_3.get(), true)); |
| 224 | 224 |
| 225 // Since the extension v1.2 does not depend any module, so the all models | 225 // Since the extension v1.2 does not depend any module, so the all models |
| 226 // should have been uninstalled. | 226 // should have been uninstalled. |
| 227 EXPECT_FALSE(registry()->GetExtensionById(shared_module_1->id(), | 227 EXPECT_FALSE(registry()->GetExtensionById(shared_module_1->id(), |
| 228 ExtensionRegistry::EVERYTHING)); | 228 ExtensionRegistry::EVERYTHING)); |
| 229 EXPECT_FALSE(registry()->GetExtensionById(shared_module_2->id(), | 229 EXPECT_FALSE(registry()->GetExtensionById(shared_module_2->id(), |
| 230 ExtensionRegistry::EVERYTHING)); | 230 ExtensionRegistry::EVERYTHING)); |
| 231 | 231 |
| 232 } | 232 } |
| 233 | 233 |
| (...skipping 13 matching lines...) Expand all Loading... |
| 247 .Append(whitelisted_id)) | 247 .Append(whitelisted_id)) |
| 248 .Set("resources", | 248 .Set("resources", |
| 249 ListBuilder().Append("*"))).Build(); | 249 ListBuilder().Append("*"))).Build(); |
| 250 scoped_refptr<Extension> shared_module = | 250 scoped_refptr<Extension> shared_module = |
| 251 ExtensionBuilder() | 251 ExtensionBuilder() |
| 252 .SetManifest(manifest.Pass()) | 252 .SetManifest(manifest.Pass()) |
| 253 .AddFlags(Extension::FROM_WEBSTORE) | 253 .AddFlags(Extension::FROM_WEBSTORE) |
| 254 .SetID(crx_file::id_util::GenerateId("shared_module")) | 254 .SetID(crx_file::id_util::GenerateId("shared_module")) |
| 255 .Build(); | 255 .Build(); |
| 256 | 256 |
| 257 EXPECT_TRUE(InstallExtension(shared_module, false)); | 257 EXPECT_TRUE(InstallExtension(shared_module.get(), false)); |
| 258 | 258 |
| 259 // Create and install an extension with the whitelisted ID. | 259 // Create and install an extension with the whitelisted ID. |
| 260 scoped_refptr<Extension> whitelisted_extension = | 260 scoped_refptr<Extension> whitelisted_extension = |
| 261 CreateExtensionImportingModule(shared_module->id(), | 261 CreateExtensionImportingModule(shared_module->id(), |
| 262 whitelisted_id, | 262 whitelisted_id, |
| 263 "1.0"); | 263 "1.0"); |
| 264 EXPECT_TRUE(InstallExtension(whitelisted_extension, false)); | 264 EXPECT_TRUE(InstallExtension(whitelisted_extension.get(), false)); |
| 265 | 265 |
| 266 // Try to install an extension with an ID that is not whitelisted. | 266 // Try to install an extension with an ID that is not whitelisted. |
| 267 scoped_refptr<Extension> nonwhitelisted_extension = | 267 scoped_refptr<Extension> nonwhitelisted_extension = |
| 268 CreateExtensionImportingModule(shared_module->id(), | 268 CreateExtensionImportingModule(shared_module->id(), |
| 269 nonwhitelisted_id, | 269 nonwhitelisted_id, |
| 270 "1.0"); | 270 "1.0"); |
| 271 EXPECT_FALSE(InstallExtension(nonwhitelisted_extension, false)); | 271 EXPECT_FALSE(InstallExtension(nonwhitelisted_extension.get(), false)); |
| 272 } | 272 } |
| 273 | 273 |
| 274 } // namespace extensions | 274 } // namespace extensions |
| OLD | NEW |