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

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

Issue 775003002: Misc cleanup in extension_registry_unittest.cc. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "base/strings/string_util.h"
11 #include "extensions/browser/extension_registry_observer.h" 10 #include "extensions/browser/extension_registry_observer.h"
12 #include "extensions/browser/uninstall_reason.h" 11 #include "extensions/browser/uninstall_reason.h"
13 #include "extensions/common/test_util.h" 12 #include "extensions/common/test_util.h"
14 #include "testing/gtest/include/gtest/gtest.h" 13 #include "testing/gtest/include/gtest/gtest.h"
15 14
16 namespace extensions { 15 namespace extensions {
17 namespace { 16 namespace {
18 17
19 typedef testing::Test ExtensionRegistryTest; 18 typedef testing::Test ExtensionRegistryTest;
20 19
21 testing::AssertionResult HasSingleExtension( 20 testing::AssertionResult HasSingleExtension(
22 const ExtensionList& list, 21 const ExtensionList& list,
23 const scoped_refptr<const Extension>& extension) { 22 const scoped_refptr<const Extension>& extension) {
24 if (list.empty()) 23 if (list.empty())
25 return testing::AssertionFailure() << "No extensions in list"; 24 return testing::AssertionFailure() << "No extensions in list";
26 if (list.size() > 1) 25 if (list.size() > 1) {
27 return testing::AssertionFailure() << list.size() 26 return testing::AssertionFailure() << list.size()
28 << " extensions, expected 1"; 27 << " extensions, expected 1";
28 }
29 const Extension* did_load = list[0].get(); 29 const Extension* did_load = list[0].get();
30 if (did_load != extension.get()) 30 if (did_load != extension.get()) {
31 return testing::AssertionFailure() << "Expected " << extension->id() 31 return testing::AssertionFailure() << "Expected " << extension->id()
32 << " found " << did_load->id(); 32 << " found " << did_load->id();
33 }
33 return testing::AssertionSuccess(); 34 return testing::AssertionSuccess();
34 } 35 }
35 36
36 class TestObserver : public ExtensionRegistryObserver { 37 class TestObserver : public ExtensionRegistryObserver {
37 public: 38 public:
39 TestObserver() {}
40
38 void Reset() { 41 void Reset() {
39 loaded_.clear(); 42 loaded_.clear();
40 unloaded_.clear(); 43 unloaded_.clear();
41 installed_.clear(); 44 installed_.clear();
42 uninstalled_.clear(); 45 uninstalled_.clear();
43 } 46 }
44 47
45 const ExtensionList& loaded() { return loaded_; } 48 const ExtensionList& loaded() { return loaded_; }
46 const ExtensionList& unloaded() { return unloaded_; } 49 const ExtensionList& unloaded() { return unloaded_; }
47 const ExtensionList& installed() { return installed_; } 50 const ExtensionList& installed() { return installed_; }
(...skipping 24 matching lines...) Expand all
72 extensions::UninstallReason reason) override { 75 extensions::UninstallReason reason) override {
73 uninstalled_.push_back(extension); 76 uninstalled_.push_back(extension);
74 } 77 }
75 78
76 void OnShutdown(extensions::ExtensionRegistry* registry) override { Reset(); } 79 void OnShutdown(extensions::ExtensionRegistry* registry) override { Reset(); }
77 80
78 ExtensionList loaded_; 81 ExtensionList loaded_;
79 ExtensionList unloaded_; 82 ExtensionList unloaded_;
80 ExtensionList installed_; 83 ExtensionList installed_;
81 ExtensionList uninstalled_; 84 ExtensionList uninstalled_;
85
86 DISALLOW_COPY_AND_ASSIGN(TestObserver);
82 }; 87 };
83 88
84 TEST_F(ExtensionRegistryTest, FillAndClearRegistry) { 89 TEST_F(ExtensionRegistryTest, FillAndClearRegistry) {
85 ExtensionRegistry registry(NULL); 90 ExtensionRegistry registry(NULL);
86 scoped_refptr<Extension> extension1 = test_util::CreateEmptyExtension("id1"); 91 scoped_refptr<Extension> extension1 = test_util::CreateEmptyExtension("id1");
87 scoped_refptr<Extension> extension2 = test_util::CreateEmptyExtension("id2"); 92 scoped_refptr<Extension> extension2 = test_util::CreateEmptyExtension("id2");
88 scoped_refptr<Extension> extension3 = test_util::CreateEmptyExtension("id3"); 93 scoped_refptr<Extension> extension3 = test_util::CreateEmptyExtension("id3");
89 scoped_refptr<Extension> extension4 = test_util::CreateEmptyExtension("id4"); 94 scoped_refptr<Extension> extension4 = test_util::CreateEmptyExtension("id4");
90 95
91 // All the sets start empty. 96 // All the sets start empty.
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after
234 TestObserver observer; 239 TestObserver observer;
235 registry.AddObserver(&observer); 240 registry.AddObserver(&observer);
236 241
237 EXPECT_TRUE(observer.loaded().empty()); 242 EXPECT_TRUE(observer.loaded().empty());
238 EXPECT_TRUE(observer.unloaded().empty()); 243 EXPECT_TRUE(observer.unloaded().empty());
239 EXPECT_TRUE(observer.installed().empty()); 244 EXPECT_TRUE(observer.installed().empty());
240 245
241 scoped_refptr<const Extension> extension = 246 scoped_refptr<const Extension> extension =
242 test_util::CreateEmptyExtension("id"); 247 test_util::CreateEmptyExtension("id");
243 248
244 registry.TriggerOnWillBeInstalled( 249 registry.TriggerOnWillBeInstalled(extension.get(), false, false,
245 extension.get(), false, false, base::EmptyString()); 250 std::string());
246 EXPECT_TRUE(HasSingleExtension(observer.installed(), extension.get())); 251 EXPECT_TRUE(HasSingleExtension(observer.installed(), extension.get()));
247 252
248 registry.AddEnabled(extension); 253 registry.AddEnabled(extension);
249 registry.TriggerOnLoaded(extension.get()); 254 registry.TriggerOnLoaded(extension.get());
250 255
251 registry.TriggerOnWillBeInstalled(extension.get(), true, false, "foo"); 256 registry.TriggerOnWillBeInstalled(extension.get(), true, false, "foo");
252 257
253 EXPECT_TRUE(HasSingleExtension(observer.loaded(), extension.get())); 258 EXPECT_TRUE(HasSingleExtension(observer.loaded(), extension.get()));
254 EXPECT_TRUE(observer.unloaded().empty()); 259 EXPECT_TRUE(observer.unloaded().empty());
255 registry.Shutdown(); 260 registry.Shutdown();
256 261
257 registry.RemoveEnabled(extension->id()); 262 registry.RemoveEnabled(extension->id());
258 registry.TriggerOnUnloaded(extension.get(), 263 registry.TriggerOnUnloaded(extension.get(),
259 UnloadedExtensionInfo::REASON_DISABLE); 264 UnloadedExtensionInfo::REASON_DISABLE);
260 265
261 EXPECT_TRUE(observer.loaded().empty()); 266 EXPECT_TRUE(observer.loaded().empty());
262 EXPECT_TRUE(HasSingleExtension(observer.unloaded(), extension.get())); 267 EXPECT_TRUE(HasSingleExtension(observer.unloaded(), extension.get()));
263 registry.Shutdown(); 268 registry.Shutdown();
264 269
265 registry.TriggerOnUninstalled(extension.get(), 270 registry.TriggerOnUninstalled(extension.get(), UNINSTALL_REASON_FOR_TESTING);
266 extensions::UNINSTALL_REASON_FOR_TESTING);
267 EXPECT_TRUE(observer.installed().empty()); 271 EXPECT_TRUE(observer.installed().empty());
268 EXPECT_TRUE(HasSingleExtension(observer.uninstalled(), extension.get())); 272 EXPECT_TRUE(HasSingleExtension(observer.uninstalled(), extension.get()));
269 273
270 registry.RemoveObserver(&observer); 274 registry.RemoveObserver(&observer);
271 } 275 }
272 276
273 } // namespace 277 } // namespace
274 } // namespace extensions 278 } // namespace extensions
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698