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/memory/ref_counted.h" | 9 #include "base/memory/ref_counted.h" |
10 #include "extensions/browser/extension_registry_observer.h" | 10 #include "extensions/browser/extension_registry_observer.h" |
(...skipping 19 matching lines...) Expand all Loading... |
30 return testing::AssertionFailure() << "Expected " << extension->id() | 30 return testing::AssertionFailure() << "Expected " << extension->id() |
31 << " found " << did_load->id(); | 31 << " found " << did_load->id(); |
32 return testing::AssertionSuccess(); | 32 return testing::AssertionSuccess(); |
33 } | 33 } |
34 | 34 |
35 class TestObserver : public ExtensionRegistryObserver { | 35 class TestObserver : public ExtensionRegistryObserver { |
36 public: | 36 public: |
37 void Reset() { | 37 void Reset() { |
38 loaded_.clear(); | 38 loaded_.clear(); |
39 unloaded_.clear(); | 39 unloaded_.clear(); |
| 40 installed_.clear(); |
40 } | 41 } |
41 | 42 |
42 const ExtensionList& loaded() { return loaded_; } | 43 const ExtensionList& loaded() { return loaded_; } |
43 const ExtensionList& unloaded() { return unloaded_; } | 44 const ExtensionList& unloaded() { return unloaded_; } |
| 45 const ExtensionList& installed() { return installed_; } |
44 | 46 |
45 private: | 47 private: |
46 virtual void OnExtensionLoaded(content::BrowserContext* browser_context, | 48 virtual void OnExtensionLoaded(content::BrowserContext* browser_context, |
47 const Extension* extension) OVERRIDE { | 49 const Extension* extension) OVERRIDE { |
48 loaded_.push_back(extension); | 50 loaded_.push_back(extension); |
49 } | 51 } |
50 | 52 |
51 virtual void OnExtensionUnloaded(content::BrowserContext* browser_context, | 53 virtual void OnExtensionUnloaded(content::BrowserContext* browser_context, |
52 const Extension* extension, | 54 const Extension* extension, |
53 UnloadedExtensionInfo::Reason reason) | 55 UnloadedExtensionInfo::Reason reason) |
54 OVERRIDE { | 56 OVERRIDE { |
55 unloaded_.push_back(extension); | 57 unloaded_.push_back(extension); |
56 } | 58 } |
57 | 59 |
| 60 virtual void OnExtensionInstalled(content::BrowserContext* browser_context, |
| 61 const Extension* extension, |
| 62 InstalledExtensionInfo info) OVERRIDE { |
| 63 installed_.push_back(extension); |
| 64 } |
| 65 |
58 ExtensionList loaded_; | 66 ExtensionList loaded_; |
59 ExtensionList unloaded_; | 67 ExtensionList unloaded_; |
| 68 ExtensionList installed_; |
60 }; | 69 }; |
61 | 70 |
62 TEST_F(ExtensionRegistryTest, FillAndClearRegistry) { | 71 TEST_F(ExtensionRegistryTest, FillAndClearRegistry) { |
63 ExtensionRegistry registry(NULL); | 72 ExtensionRegistry registry(NULL); |
64 scoped_refptr<Extension> extension1 = test_util::CreateExtensionWithID("id1"); | 73 scoped_refptr<Extension> extension1 = test_util::CreateExtensionWithID("id1"); |
65 scoped_refptr<Extension> extension2 = test_util::CreateExtensionWithID("id2"); | 74 scoped_refptr<Extension> extension2 = test_util::CreateExtensionWithID("id2"); |
66 scoped_refptr<Extension> extension3 = test_util::CreateExtensionWithID("id3"); | 75 scoped_refptr<Extension> extension3 = test_util::CreateExtensionWithID("id3"); |
67 scoped_refptr<Extension> extension4 = test_util::CreateExtensionWithID("id4"); | 76 scoped_refptr<Extension> extension4 = test_util::CreateExtensionWithID("id4"); |
68 | 77 |
69 // All the sets start empty. | 78 // All the sets start empty. |
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
208 "enabled", ExtensionRegistry::DISABLED | ExtensionRegistry::BLACKLISTED)); | 217 "enabled", ExtensionRegistry::DISABLED | ExtensionRegistry::BLACKLISTED)); |
209 } | 218 } |
210 | 219 |
211 TEST_F(ExtensionRegistryTest, Observer) { | 220 TEST_F(ExtensionRegistryTest, Observer) { |
212 ExtensionRegistry registry(NULL); | 221 ExtensionRegistry registry(NULL); |
213 TestObserver observer; | 222 TestObserver observer; |
214 registry.AddObserver(&observer); | 223 registry.AddObserver(&observer); |
215 | 224 |
216 EXPECT_TRUE(observer.loaded().empty()); | 225 EXPECT_TRUE(observer.loaded().empty()); |
217 EXPECT_TRUE(observer.unloaded().empty()); | 226 EXPECT_TRUE(observer.unloaded().empty()); |
| 227 EXPECT_TRUE(observer.installed().empty()); |
218 | 228 |
219 scoped_refptr<const Extension> extension = | 229 scoped_refptr<const Extension> extension = |
220 test_util::CreateExtensionWithID("id"); | 230 test_util::CreateExtensionWithID("id"); |
221 | 231 |
| 232 registry.TriggerOnInstalled(extension, true, "foo"); |
| 233 EXPECT_TRUE(HasSingleExtension(observer.installed(), extension.get())); |
| 234 |
222 registry.AddEnabled(extension); | 235 registry.AddEnabled(extension); |
223 registry.TriggerOnLoaded(extension); | 236 registry.TriggerOnLoaded(extension); |
224 | 237 |
225 EXPECT_TRUE(HasSingleExtension(observer.loaded(), extension.get())); | 238 EXPECT_TRUE(HasSingleExtension(observer.loaded(), extension.get())); |
226 EXPECT_TRUE(observer.unloaded().empty()); | 239 EXPECT_TRUE(observer.unloaded().empty()); |
227 observer.Reset(); | 240 observer.Reset(); |
228 | 241 |
229 registry.RemoveEnabled(extension->id()); | 242 registry.RemoveEnabled(extension->id()); |
230 registry.TriggerOnUnloaded(extension, UnloadedExtensionInfo::REASON_DISABLE); | 243 registry.TriggerOnUnloaded(extension, UnloadedExtensionInfo::REASON_DISABLE); |
231 | 244 |
232 EXPECT_TRUE(observer.loaded().empty()); | 245 EXPECT_TRUE(observer.loaded().empty()); |
233 EXPECT_TRUE(HasSingleExtension(observer.unloaded(), extension.get())); | 246 EXPECT_TRUE(HasSingleExtension(observer.unloaded(), extension.get())); |
234 observer.Reset(); | 247 observer.Reset(); |
235 | 248 |
236 registry.RemoveObserver(&observer); | 249 registry.RemoveObserver(&observer); |
237 } | 250 } |
238 | 251 |
239 } // namespace | 252 } // namespace |
240 } // namespace extensions | 253 } // namespace extensions |
OLD | NEW |