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 "extensions/browser/extension_registry.h" | 5 #include "extensions/browser/extension_registry.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/macros.h" | 9 #include "base/macros.h" |
10 #include "base/memory/ref_counted.h" | 10 #include "base/memory/ref_counted.h" |
11 #include "extensions/browser/extension_registry_observer.h" | 11 #include "extensions/browser/extension_registry_observer.h" |
12 #include "extensions/browser/uninstall_reason.h" | 12 #include "extensions/browser/uninstall_reason.h" |
13 #include "extensions/common/extension_builder.h" | |
13 #include "extensions/common/test_util.h" | 14 #include "extensions/common/test_util.h" |
14 #include "testing/gtest/include/gtest/gtest.h" | 15 #include "testing/gtest/include/gtest/gtest.h" |
15 | 16 |
16 namespace extensions { | 17 namespace extensions { |
17 namespace { | 18 namespace { |
18 | 19 |
19 typedef testing::Test ExtensionRegistryTest; | 20 typedef testing::Test ExtensionRegistryTest; |
20 | 21 |
21 testing::AssertionResult HasSingleExtension( | 22 testing::AssertionResult HasSingleExtension( |
22 const ExtensionList& list, | 23 const ExtensionList& list, |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
65 | 66 |
66 void OnExtensionWillBeInstalled(content::BrowserContext* browser_context, | 67 void OnExtensionWillBeInstalled(content::BrowserContext* browser_context, |
67 const Extension* extension, | 68 const Extension* extension, |
68 bool is_update, | 69 bool is_update, |
69 const std::string& old_name) override { | 70 const std::string& old_name) override { |
70 installed_.push_back(extension); | 71 installed_.push_back(extension); |
71 } | 72 } |
72 | 73 |
73 void OnExtensionUninstalled(content::BrowserContext* browser_context, | 74 void OnExtensionUninstalled(content::BrowserContext* browser_context, |
74 const Extension* extension, | 75 const Extension* extension, |
75 extensions::UninstallReason reason) override { | 76 UninstallReason reason) override { |
76 uninstalled_.push_back(extension); | 77 uninstalled_.push_back(extension); |
77 } | 78 } |
78 | 79 |
79 void OnShutdown(extensions::ExtensionRegistry* registry) override { Reset(); } | 80 void OnShutdown(ExtensionRegistry* registry) override { Reset(); } |
80 | 81 |
81 ExtensionList loaded_; | 82 ExtensionList loaded_; |
82 ExtensionList unloaded_; | 83 ExtensionList unloaded_; |
83 ExtensionList installed_; | 84 ExtensionList installed_; |
84 ExtensionList uninstalled_; | 85 ExtensionList uninstalled_; |
85 | 86 |
86 DISALLOW_COPY_AND_ASSIGN(TestObserver); | 87 DISALLOW_COPY_AND_ASSIGN(TestObserver); |
87 }; | 88 }; |
88 | 89 |
89 TEST_F(ExtensionRegistryTest, FillAndClearRegistry) { | 90 TEST_F(ExtensionRegistryTest, FillAndClearRegistry) { |
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
265 EXPECT_TRUE(HasSingleExtension(observer.unloaded(), extension.get())); | 266 EXPECT_TRUE(HasSingleExtension(observer.unloaded(), extension.get())); |
266 registry.Shutdown(); | 267 registry.Shutdown(); |
267 | 268 |
268 registry.TriggerOnUninstalled(extension.get(), UNINSTALL_REASON_FOR_TESTING); | 269 registry.TriggerOnUninstalled(extension.get(), UNINSTALL_REASON_FOR_TESTING); |
269 EXPECT_TRUE(observer.installed().empty()); | 270 EXPECT_TRUE(observer.installed().empty()); |
270 EXPECT_TRUE(HasSingleExtension(observer.uninstalled(), extension.get())); | 271 EXPECT_TRUE(HasSingleExtension(observer.uninstalled(), extension.get())); |
271 | 272 |
272 registry.RemoveObserver(&observer); | 273 registry.RemoveObserver(&observer); |
273 } | 274 } |
274 | 275 |
276 // Regression test for https://crbug.com/724563. | |
277 TEST_F(ExtensionRegistryTest, TerminatedExtensionStoredVersion) { | |
278 const std::string kVersionString = "1.2.3.4"; | |
279 ExtensionRegistry registry(nullptr); | |
280 scoped_refptr<Extension> extension = | |
281 ExtensionBuilder() | |
282 .SetManifest(DictionaryBuilder() | |
283 .Set("name", "Test") | |
284 .Set("version", kVersionString) | |
285 .Build()) | |
286 .Build(); | |
287 const ExtensionId extension_id = extension->id(); | |
288 | |
289 EXPECT_TRUE(registry.AddEnabled(extension)); | |
290 EXPECT_FALSE( | |
291 registry.GetExtensionById(extension_id, ExtensionRegistry::TERMINATED)); | |
292 { | |
293 base::Version version = registry.GetStoredVersion(extension_id); | |
294 ASSERT_TRUE(version.IsValid()); | |
295 EXPECT_EQ(kVersionString, | |
296 registry.GetStoredVersion(extension_id).GetString()); | |
297 } | |
298 | |
299 // Simulate terminating |extension|. | |
300 EXPECT_TRUE(registry.RemoveEnabled(extension_id)); | |
lazyboy
2017/05/25 21:38:27
Moved the test to this file. However, is this the
Devlin
2017/05/25 21:40:12
Yep; this should be fine.
| |
301 EXPECT_TRUE(registry.AddTerminated(extension)); | |
302 EXPECT_TRUE( | |
303 registry.GetExtensionById(extension_id, ExtensionRegistry::TERMINATED)); | |
304 { | |
305 base::Version version = registry.GetStoredVersion(extension_id); | |
306 ASSERT_TRUE(version.IsValid()); | |
307 EXPECT_EQ(kVersionString, | |
308 registry.GetStoredVersion(extension_id).GetString()); | |
309 } | |
310 } | |
311 | |
275 } // namespace | 312 } // namespace |
276 } // namespace extensions | 313 } // namespace extensions |
OLD | NEW |