| 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 OnExtensionWillBeInstalled( |
| 61 content::BrowserContext* browser_context, |
| 62 const Extension* extension, |
| 63 InstalledExtensionInfo info) OVERRIDE { |
| 64 installed_.push_back(extension); |
| 65 } |
| 66 |
| 58 ExtensionList loaded_; | 67 ExtensionList loaded_; |
| 59 ExtensionList unloaded_; | 68 ExtensionList unloaded_; |
| 69 ExtensionList installed_; |
| 60 }; | 70 }; |
| 61 | 71 |
| 62 TEST_F(ExtensionRegistryTest, FillAndClearRegistry) { | 72 TEST_F(ExtensionRegistryTest, FillAndClearRegistry) { |
| 63 ExtensionRegistry registry(NULL); | 73 ExtensionRegistry registry(NULL); |
| 64 scoped_refptr<Extension> extension1 = test_util::CreateExtensionWithID("id1"); | 74 scoped_refptr<Extension> extension1 = test_util::CreateExtensionWithID("id1"); |
| 65 scoped_refptr<Extension> extension2 = test_util::CreateExtensionWithID("id2"); | 75 scoped_refptr<Extension> extension2 = test_util::CreateExtensionWithID("id2"); |
| 66 scoped_refptr<Extension> extension3 = test_util::CreateExtensionWithID("id3"); | 76 scoped_refptr<Extension> extension3 = test_util::CreateExtensionWithID("id3"); |
| 67 scoped_refptr<Extension> extension4 = test_util::CreateExtensionWithID("id4"); | 77 scoped_refptr<Extension> extension4 = test_util::CreateExtensionWithID("id4"); |
| 68 | 78 |
| 69 // All the sets start empty. | 79 // All the sets start empty. |
| (...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 208 "enabled", ExtensionRegistry::DISABLED | ExtensionRegistry::BLACKLISTED)); | 218 "enabled", ExtensionRegistry::DISABLED | ExtensionRegistry::BLACKLISTED)); |
| 209 } | 219 } |
| 210 | 220 |
| 211 TEST_F(ExtensionRegistryTest, Observer) { | 221 TEST_F(ExtensionRegistryTest, Observer) { |
| 212 ExtensionRegistry registry(NULL); | 222 ExtensionRegistry registry(NULL); |
| 213 TestObserver observer; | 223 TestObserver observer; |
| 214 registry.AddObserver(&observer); | 224 registry.AddObserver(&observer); |
| 215 | 225 |
| 216 EXPECT_TRUE(observer.loaded().empty()); | 226 EXPECT_TRUE(observer.loaded().empty()); |
| 217 EXPECT_TRUE(observer.unloaded().empty()); | 227 EXPECT_TRUE(observer.unloaded().empty()); |
| 228 EXPECT_TRUE(observer.installed().empty()); |
| 218 | 229 |
| 219 scoped_refptr<const Extension> extension = | 230 scoped_refptr<const Extension> extension = |
| 220 test_util::CreateExtensionWithID("id"); | 231 test_util::CreateExtensionWithID("id"); |
| 221 | 232 |
| 233 registry.TriggerOnWillBeInstalled(extension, true, "foo"); |
| 234 EXPECT_TRUE(HasSingleExtension(observer.installed(), extension.get())); |
| 235 |
| 222 registry.AddEnabled(extension); | 236 registry.AddEnabled(extension); |
| 223 registry.TriggerOnLoaded(extension); | 237 registry.TriggerOnLoaded(extension); |
| 224 | 238 |
| 225 EXPECT_TRUE(HasSingleExtension(observer.loaded(), extension.get())); | 239 EXPECT_TRUE(HasSingleExtension(observer.loaded(), extension.get())); |
| 226 EXPECT_TRUE(observer.unloaded().empty()); | 240 EXPECT_TRUE(observer.unloaded().empty()); |
| 227 observer.Reset(); | 241 observer.Reset(); |
| 228 | 242 |
| 229 registry.RemoveEnabled(extension->id()); | 243 registry.RemoveEnabled(extension->id()); |
| 230 registry.TriggerOnUnloaded(extension, UnloadedExtensionInfo::REASON_DISABLE); | 244 registry.TriggerOnUnloaded(extension, UnloadedExtensionInfo::REASON_DISABLE); |
| 231 | 245 |
| 232 EXPECT_TRUE(observer.loaded().empty()); | 246 EXPECT_TRUE(observer.loaded().empty()); |
| 233 EXPECT_TRUE(HasSingleExtension(observer.unloaded(), extension.get())); | 247 EXPECT_TRUE(HasSingleExtension(observer.unloaded(), extension.get())); |
| 234 observer.Reset(); | 248 observer.Reset(); |
| 235 | 249 |
| 236 registry.RemoveObserver(&observer); | 250 registry.RemoveObserver(&observer); |
| 237 } | 251 } |
| 238 | 252 |
| 239 } // namespace | 253 } // namespace |
| 240 } // namespace extensions | 254 } // namespace extensions |
| OLD | NEW |