Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(15)

Side by Side Diff: extensions/browser/extension_registry_unittest.cc

Issue 279073003: Add a function triggering extension installed to ExtensionRegistryObserver (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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
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 extensions::InstalledExtensionInfo details(extension, true, "foo");
233 registry.TriggerOnInstalled(extension, details);
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
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698