| 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 "base/strings/string_util.h" | 10 #include "base/strings/string_util.h" |
| (...skipping 21 matching lines...) Expand all Loading... |
| 32 << " found " << did_load->id(); | 32 << " found " << did_load->id(); |
| 33 return testing::AssertionSuccess(); | 33 return testing::AssertionSuccess(); |
| 34 } | 34 } |
| 35 | 35 |
| 36 class TestObserver : public ExtensionRegistryObserver { | 36 class TestObserver : public ExtensionRegistryObserver { |
| 37 public: | 37 public: |
| 38 void Reset() { | 38 void Reset() { |
| 39 loaded_.clear(); | 39 loaded_.clear(); |
| 40 unloaded_.clear(); | 40 unloaded_.clear(); |
| 41 installed_.clear(); | 41 installed_.clear(); |
| 42 uninstalled_.clear(); |
| 42 } | 43 } |
| 43 | 44 |
| 44 const ExtensionList& loaded() { return loaded_; } | 45 const ExtensionList& loaded() { return loaded_; } |
| 45 const ExtensionList& unloaded() { return unloaded_; } | 46 const ExtensionList& unloaded() { return unloaded_; } |
| 46 const ExtensionList& installed() { return installed_; } | 47 const ExtensionList& installed() { return installed_; } |
| 48 const ExtensionList& uninstalled() { return uninstalled_; } |
| 47 | 49 |
| 48 private: | 50 private: |
| 49 virtual void OnExtensionLoaded(content::BrowserContext* browser_context, | 51 virtual void OnExtensionLoaded(content::BrowserContext* browser_context, |
| 50 const Extension* extension) OVERRIDE { | 52 const Extension* extension) OVERRIDE { |
| 51 loaded_.push_back(extension); | 53 loaded_.push_back(extension); |
| 52 } | 54 } |
| 53 | 55 |
| 54 virtual void OnExtensionUnloaded(content::BrowserContext* browser_context, | 56 virtual void OnExtensionUnloaded(content::BrowserContext* browser_context, |
| 55 const Extension* extension, | 57 const Extension* extension, |
| 56 UnloadedExtensionInfo::Reason reason) | 58 UnloadedExtensionInfo::Reason reason) |
| 57 OVERRIDE { | 59 OVERRIDE { |
| 58 unloaded_.push_back(extension); | 60 unloaded_.push_back(extension); |
| 59 } | 61 } |
| 60 | 62 |
| 61 virtual void OnExtensionWillBeInstalled( | 63 virtual void OnExtensionWillBeInstalled( |
| 62 content::BrowserContext* browser_context, | 64 content::BrowserContext* browser_context, |
| 63 const Extension* extension, | 65 const Extension* extension, |
| 64 bool is_update, | 66 bool is_update, |
| 65 const std::string& old_name) OVERRIDE { | 67 const std::string& old_name) OVERRIDE { |
| 66 installed_.push_back(extension); | 68 installed_.push_back(extension); |
| 67 } | 69 } |
| 68 | 70 |
| 71 virtual void OnExtensionUninstalled(content::BrowserContext* browser_context, |
| 72 const Extension* extension) OVERRIDE { |
| 73 uninstalled_.push_back(extension); |
| 74 } |
| 75 |
| 69 ExtensionList loaded_; | 76 ExtensionList loaded_; |
| 70 ExtensionList unloaded_; | 77 ExtensionList unloaded_; |
| 71 ExtensionList installed_; | 78 ExtensionList installed_; |
| 79 ExtensionList uninstalled_; |
| 72 }; | 80 }; |
| 73 | 81 |
| 74 TEST_F(ExtensionRegistryTest, FillAndClearRegistry) { | 82 TEST_F(ExtensionRegistryTest, FillAndClearRegistry) { |
| 75 ExtensionRegistry registry(NULL); | 83 ExtensionRegistry registry(NULL); |
| 76 scoped_refptr<Extension> extension1 = test_util::CreateExtensionWithID("id1"); | 84 scoped_refptr<Extension> extension1 = test_util::CreateExtensionWithID("id1"); |
| 77 scoped_refptr<Extension> extension2 = test_util::CreateExtensionWithID("id2"); | 85 scoped_refptr<Extension> extension2 = test_util::CreateExtensionWithID("id2"); |
| 78 scoped_refptr<Extension> extension3 = test_util::CreateExtensionWithID("id3"); | 86 scoped_refptr<Extension> extension3 = test_util::CreateExtensionWithID("id3"); |
| 79 scoped_refptr<Extension> extension4 = test_util::CreateExtensionWithID("id4"); | 87 scoped_refptr<Extension> extension4 = test_util::CreateExtensionWithID("id4"); |
| 80 | 88 |
| 81 // All the sets start empty. | 89 // All the sets start empty. |
| (...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 244 EXPECT_TRUE(observer.unloaded().empty()); | 252 EXPECT_TRUE(observer.unloaded().empty()); |
| 245 observer.Reset(); | 253 observer.Reset(); |
| 246 | 254 |
| 247 registry.RemoveEnabled(extension->id()); | 255 registry.RemoveEnabled(extension->id()); |
| 248 registry.TriggerOnUnloaded(extension, UnloadedExtensionInfo::REASON_DISABLE); | 256 registry.TriggerOnUnloaded(extension, UnloadedExtensionInfo::REASON_DISABLE); |
| 249 | 257 |
| 250 EXPECT_TRUE(observer.loaded().empty()); | 258 EXPECT_TRUE(observer.loaded().empty()); |
| 251 EXPECT_TRUE(HasSingleExtension(observer.unloaded(), extension.get())); | 259 EXPECT_TRUE(HasSingleExtension(observer.unloaded(), extension.get())); |
| 252 observer.Reset(); | 260 observer.Reset(); |
| 253 | 261 |
| 262 registry.TriggerOnUninstalled(extension); |
| 263 EXPECT_TRUE(observer.installed().empty()); |
| 264 EXPECT_TRUE(HasSingleExtension(observer.uninstalled(), extension.get())); |
| 265 |
| 254 registry.RemoveObserver(&observer); | 266 registry.RemoveObserver(&observer); |
| 255 } | 267 } |
| 256 | 268 |
| 257 } // namespace | 269 } // namespace |
| 258 } // namespace extensions | 270 } // namespace extensions |
| OLD | NEW |