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

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

Issue 598173003: Run clang-modernize -use-nullptr over src/extensions/. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 2 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 "base/strings/string_util.h" 10 #include "base/strings/string_util.h"
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
80 Reset(); 80 Reset();
81 } 81 }
82 82
83 ExtensionList loaded_; 83 ExtensionList loaded_;
84 ExtensionList unloaded_; 84 ExtensionList unloaded_;
85 ExtensionList installed_; 85 ExtensionList installed_;
86 ExtensionList uninstalled_; 86 ExtensionList uninstalled_;
87 }; 87 };
88 88
89 TEST_F(ExtensionRegistryTest, FillAndClearRegistry) { 89 TEST_F(ExtensionRegistryTest, FillAndClearRegistry) {
90 ExtensionRegistry registry(NULL); 90 ExtensionRegistry registry(nullptr);
91 scoped_refptr<Extension> extension1 = test_util::CreateEmptyExtension("id1"); 91 scoped_refptr<Extension> extension1 = test_util::CreateEmptyExtension("id1");
92 scoped_refptr<Extension> extension2 = test_util::CreateEmptyExtension("id2"); 92 scoped_refptr<Extension> extension2 = test_util::CreateEmptyExtension("id2");
93 scoped_refptr<Extension> extension3 = test_util::CreateEmptyExtension("id3"); 93 scoped_refptr<Extension> extension3 = test_util::CreateEmptyExtension("id3");
94 scoped_refptr<Extension> extension4 = test_util::CreateEmptyExtension("id4"); 94 scoped_refptr<Extension> extension4 = test_util::CreateEmptyExtension("id4");
95 95
96 // All the sets start empty. 96 // All the sets start empty.
97 EXPECT_EQ(0u, registry.enabled_extensions().size()); 97 EXPECT_EQ(0u, registry.enabled_extensions().size());
98 EXPECT_EQ(0u, registry.disabled_extensions().size()); 98 EXPECT_EQ(0u, registry.disabled_extensions().size());
99 EXPECT_EQ(0u, registry.terminated_extensions().size()); 99 EXPECT_EQ(0u, registry.terminated_extensions().size());
100 EXPECT_EQ(0u, registry.blacklisted_extensions().size()); 100 EXPECT_EQ(0u, registry.blacklisted_extensions().size());
(...skipping 13 matching lines...) Expand all
114 registry.ClearAll(); 114 registry.ClearAll();
115 115
116 EXPECT_EQ(0u, registry.enabled_extensions().size()); 116 EXPECT_EQ(0u, registry.enabled_extensions().size());
117 EXPECT_EQ(0u, registry.disabled_extensions().size()); 117 EXPECT_EQ(0u, registry.disabled_extensions().size());
118 EXPECT_EQ(0u, registry.terminated_extensions().size()); 118 EXPECT_EQ(0u, registry.terminated_extensions().size());
119 EXPECT_EQ(0u, registry.blacklisted_extensions().size()); 119 EXPECT_EQ(0u, registry.blacklisted_extensions().size());
120 } 120 }
121 121
122 // A simple test of adding and removing things from sets. 122 // A simple test of adding and removing things from sets.
123 TEST_F(ExtensionRegistryTest, AddAndRemoveExtensionFromRegistry) { 123 TEST_F(ExtensionRegistryTest, AddAndRemoveExtensionFromRegistry) {
124 ExtensionRegistry registry(NULL); 124 ExtensionRegistry registry(nullptr);
125 125
126 // Adding an extension works. 126 // Adding an extension works.
127 scoped_refptr<Extension> extension = test_util::CreateEmptyExtension("id"); 127 scoped_refptr<Extension> extension = test_util::CreateEmptyExtension("id");
128 EXPECT_TRUE(registry.AddEnabled(extension)); 128 EXPECT_TRUE(registry.AddEnabled(extension));
129 EXPECT_EQ(1u, registry.enabled_extensions().size()); 129 EXPECT_EQ(1u, registry.enabled_extensions().size());
130 130
131 // The extension was only added to one set. 131 // The extension was only added to one set.
132 EXPECT_EQ(0u, registry.disabled_extensions().size()); 132 EXPECT_EQ(0u, registry.disabled_extensions().size());
133 EXPECT_EQ(0u, registry.terminated_extensions().size()); 133 EXPECT_EQ(0u, registry.terminated_extensions().size());
134 EXPECT_EQ(0u, registry.blacklisted_extensions().size()); 134 EXPECT_EQ(0u, registry.blacklisted_extensions().size());
135 135
136 // Removing an extension works. 136 // Removing an extension works.
137 EXPECT_TRUE(registry.RemoveEnabled(extension->id())); 137 EXPECT_TRUE(registry.RemoveEnabled(extension->id()));
138 EXPECT_EQ(0u, registry.enabled_extensions().size()); 138 EXPECT_EQ(0u, registry.enabled_extensions().size());
139 139
140 // Trying to remove an extension that isn't in the set fails cleanly. 140 // Trying to remove an extension that isn't in the set fails cleanly.
141 EXPECT_FALSE(registry.RemoveEnabled(extension->id())); 141 EXPECT_FALSE(registry.RemoveEnabled(extension->id()));
142 } 142 }
143 143
144 TEST_F(ExtensionRegistryTest, AddExtensionToRegistryTwice) { 144 TEST_F(ExtensionRegistryTest, AddExtensionToRegistryTwice) {
145 ExtensionRegistry registry(NULL); 145 ExtensionRegistry registry(nullptr);
146 scoped_refptr<Extension> extension = test_util::CreateEmptyExtension("id"); 146 scoped_refptr<Extension> extension = test_util::CreateEmptyExtension("id");
147 147
148 // An extension can exist in two sets at once. It would be nice to eliminate 148 // An extension can exist in two sets at once. It would be nice to eliminate
149 // this functionality, but some users of ExtensionRegistry need it. 149 // this functionality, but some users of ExtensionRegistry need it.
150 EXPECT_TRUE(registry.AddEnabled(extension)); 150 EXPECT_TRUE(registry.AddEnabled(extension));
151 EXPECT_TRUE(registry.AddDisabled(extension)); 151 EXPECT_TRUE(registry.AddDisabled(extension));
152 152
153 EXPECT_EQ(1u, registry.enabled_extensions().size()); 153 EXPECT_EQ(1u, registry.enabled_extensions().size());
154 EXPECT_EQ(1u, registry.disabled_extensions().size()); 154 EXPECT_EQ(1u, registry.disabled_extensions().size());
155 EXPECT_EQ(0u, registry.terminated_extensions().size()); 155 EXPECT_EQ(0u, registry.terminated_extensions().size());
156 EXPECT_EQ(0u, registry.blacklisted_extensions().size()); 156 EXPECT_EQ(0u, registry.blacklisted_extensions().size());
157 } 157 }
158 158
159 TEST_F(ExtensionRegistryTest, GetExtensionById) { 159 TEST_F(ExtensionRegistryTest, GetExtensionById) {
160 ExtensionRegistry registry(NULL); 160 ExtensionRegistry registry(nullptr);
161 161
162 // Trying to get an extension fails cleanly when the sets are empty. 162 // Trying to get an extension fails cleanly when the sets are empty.
163 EXPECT_FALSE( 163 EXPECT_FALSE(
164 registry.GetExtensionById("id", ExtensionRegistry::EVERYTHING)); 164 registry.GetExtensionById("id", ExtensionRegistry::EVERYTHING));
165 165
166 scoped_refptr<Extension> enabled = test_util::CreateEmptyExtension("enabled"); 166 scoped_refptr<Extension> enabled = test_util::CreateEmptyExtension("enabled");
167 scoped_refptr<Extension> disabled = 167 scoped_refptr<Extension> disabled =
168 test_util::CreateEmptyExtension("disabled"); 168 test_util::CreateEmptyExtension("disabled");
169 scoped_refptr<Extension> terminated = 169 scoped_refptr<Extension> terminated =
170 test_util::CreateEmptyExtension("terminated"); 170 test_util::CreateEmptyExtension("terminated");
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
228 // Enabled can be found with multiple flags set. 228 // Enabled can be found with multiple flags set.
229 EXPECT_TRUE(registry.GetExtensionById( 229 EXPECT_TRUE(registry.GetExtensionById(
230 "enabled", ExtensionRegistry::ENABLED | ExtensionRegistry::TERMINATED)); 230 "enabled", ExtensionRegistry::ENABLED | ExtensionRegistry::TERMINATED));
231 231
232 // Enabled isn't found if the wrong flags are set. 232 // Enabled isn't found if the wrong flags are set.
233 EXPECT_FALSE(registry.GetExtensionById( 233 EXPECT_FALSE(registry.GetExtensionById(
234 "enabled", ExtensionRegistry::DISABLED | ExtensionRegistry::BLACKLISTED)); 234 "enabled", ExtensionRegistry::DISABLED | ExtensionRegistry::BLACKLISTED));
235 } 235 }
236 236
237 TEST_F(ExtensionRegistryTest, Observer) { 237 TEST_F(ExtensionRegistryTest, Observer) {
238 ExtensionRegistry registry(NULL); 238 ExtensionRegistry registry(nullptr);
239 TestObserver observer; 239 TestObserver observer;
240 registry.AddObserver(&observer); 240 registry.AddObserver(&observer);
241 241
242 EXPECT_TRUE(observer.loaded().empty()); 242 EXPECT_TRUE(observer.loaded().empty());
243 EXPECT_TRUE(observer.unloaded().empty()); 243 EXPECT_TRUE(observer.unloaded().empty());
244 EXPECT_TRUE(observer.installed().empty()); 244 EXPECT_TRUE(observer.installed().empty());
245 245
246 scoped_refptr<const Extension> extension = 246 scoped_refptr<const Extension> extension =
247 test_util::CreateEmptyExtension("id"); 247 test_util::CreateEmptyExtension("id");
248 248
(...skipping 21 matching lines...) Expand all
270 registry.TriggerOnUninstalled(extension.get(), 270 registry.TriggerOnUninstalled(extension.get(),
271 extensions::UNINSTALL_REASON_FOR_TESTING); 271 extensions::UNINSTALL_REASON_FOR_TESTING);
272 EXPECT_TRUE(observer.installed().empty()); 272 EXPECT_TRUE(observer.installed().empty());
273 EXPECT_TRUE(HasSingleExtension(observer.uninstalled(), extension.get())); 273 EXPECT_TRUE(HasSingleExtension(observer.uninstalled(), extension.get()));
274 274
275 registry.RemoveObserver(&observer); 275 registry.RemoveObserver(&observer);
276 } 276 }
277 277
278 } // namespace 278 } // namespace
279 } // namespace extensions 279 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698