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

Side by Side Diff: chrome/browser/extensions/extension_toolbar_model_unittest.cc

Issue 510313002: Extensions-related fixups for scoped_refptr conversion operator removal. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 3 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "base/macros.h" 5 #include "base/macros.h"
6 #include "base/memory/ref_counted.h" 6 #include "base/memory/ref_counted.h"
7 #include "base/memory/scoped_ptr.h" 7 #include "base/memory/scoped_ptr.h"
8 #include "chrome/browser/extensions/api/extension_action/extension_action_api.h" 8 #include "chrome/browser/extensions/api/extension_action/extension_action_api.h"
9 #include "chrome/browser/extensions/extension_service.h" 9 #include "chrome/browser/extensions/extension_service.h"
10 #include "chrome/browser/extensions/extension_service_test_base.h" 10 #include "chrome/browser/extensions/extension_service_test_base.h"
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
112 } // namespace 112 } // namespace
113 113
114 class ExtensionToolbarModelUnitTest : public ExtensionServiceTestBase { 114 class ExtensionToolbarModelUnitTest : public ExtensionServiceTestBase {
115 protected: 115 protected:
116 // Initialize the ExtensionService, ExtensionToolbarModel, and 116 // Initialize the ExtensionService, ExtensionToolbarModel, and
117 // ExtensionSystem. 117 // ExtensionSystem.
118 void Init(); 118 void Init();
119 119
120 // Adds or removes the given |extension| and verify success. 120 // Adds or removes the given |extension| and verify success.
121 testing::AssertionResult AddExtension( 121 testing::AssertionResult AddExtension(
122 scoped_refptr<const Extension> extension) WARN_UNUSED_RESULT; 122 const scoped_refptr<const Extension>& extension) WARN_UNUSED_RESULT;
123 testing::AssertionResult RemoveExtension( 123 testing::AssertionResult RemoveExtension(
124 scoped_refptr<const Extension> extension) WARN_UNUSED_RESULT; 124 const scoped_refptr<const Extension>& extension) WARN_UNUSED_RESULT;
125 125
126 // Adds three extensions, all with browser actions. 126 // Adds three extensions, all with browser actions.
127 testing::AssertionResult AddBrowserActionExtensions() WARN_UNUSED_RESULT; 127 testing::AssertionResult AddBrowserActionExtensions() WARN_UNUSED_RESULT;
128 128
129 // Adds three extensions, one each for browser action, page action, and no 129 // Adds three extensions, one each for browser action, page action, and no
130 // action, and are added in that order. 130 // action, and are added in that order.
131 testing::AssertionResult AddActionExtensions() WARN_UNUSED_RESULT; 131 testing::AssertionResult AddActionExtensions() WARN_UNUSED_RESULT;
132 132
133 // Returns the extension at the given index in the toolbar model, or NULL 133 // Returns the extension at the given index in the toolbar model, or NULL
134 // if one does not exist. 134 // if one does not exist.
135 const Extension* GetExtensionAtIndex(size_t index) const; 135 const Extension* GetExtensionAtIndex(size_t index) const;
136 136
137 ExtensionToolbarModel* toolbar_model() { return toolbar_model_.get(); } 137 ExtensionToolbarModel* toolbar_model() { return toolbar_model_.get(); }
138 138
139 const ExtensionToolbarModelTestObserver* observer() const { 139 const ExtensionToolbarModelTestObserver* observer() const {
140 return model_observer_.get(); 140 return model_observer_.get();
141 } 141 }
142 size_t num_toolbar_items() const { 142 size_t num_toolbar_items() const {
143 return toolbar_model_->toolbar_items().size(); 143 return toolbar_model_->toolbar_items().size();
144 } 144 }
145 const Extension* browser_action_a() const { 145 const Extension* browser_action_a() const { return browser_action_a_.get(); }
146 return browser_action_a_; 146 const Extension* browser_action_b() const { return browser_action_b_.get(); }
147 } 147 const Extension* browser_action_c() const { return browser_action_c_.get(); }
148 const Extension* browser_action_b() const {
149 return browser_action_b_;
150 }
151 const Extension* browser_action_c() const {
152 return browser_action_c_;
153 }
154 const Extension* browser_action() const { 148 const Extension* browser_action() const {
155 return browser_action_extension_.get(); 149 return browser_action_extension_.get();
156 } 150 }
157 const Extension* page_action() const { return page_action_extension_.get(); } 151 const Extension* page_action() const { return page_action_extension_.get(); }
158 const Extension* no_action() const { return no_action_extension_.get(); } 152 const Extension* no_action() const { return no_action_extension_.get(); }
159 153
160 private: 154 private:
161 // Verifies that all extensions in |extensions| are added successfully. 155 // Verifies that all extensions in |extensions| are added successfully.
162 testing::AssertionResult AddAndVerifyExtensions( 156 testing::AssertionResult AddAndVerifyExtensions(
163 const ExtensionList& extensions); 157 const ExtensionList& extensions);
(...skipping 22 matching lines...) Expand all
186 new ExtensionToolbarModel(profile(), ExtensionPrefs::Get(profile()))); 180 new ExtensionToolbarModel(profile(), ExtensionPrefs::Get(profile())));
187 model_observer_.reset( 181 model_observer_.reset(
188 new ExtensionToolbarModelTestObserver(toolbar_model_.get())); 182 new ExtensionToolbarModelTestObserver(toolbar_model_.get()));
189 static_cast<TestExtensionSystem*>(ExtensionSystem::Get(profile()))-> 183 static_cast<TestExtensionSystem*>(ExtensionSystem::Get(profile()))->
190 SetReady(); 184 SetReady();
191 // Run tasks posted to TestExtensionSystem. 185 // Run tasks posted to TestExtensionSystem.
192 base::RunLoop().RunUntilIdle(); 186 base::RunLoop().RunUntilIdle();
193 } 187 }
194 188
195 testing::AssertionResult ExtensionToolbarModelUnitTest::AddExtension( 189 testing::AssertionResult ExtensionToolbarModelUnitTest::AddExtension(
196 scoped_refptr<const Extension> extension) { 190 const scoped_refptr<const Extension>& extension) {
197 if (registry()->enabled_extensions().GetByID(extension->id())) { 191 if (registry()->enabled_extensions().GetByID(extension->id())) {
198 return testing::AssertionFailure() << "Extension " << extension->name() << 192 return testing::AssertionFailure() << "Extension " << extension->name() <<
199 " already installed!"; 193 " already installed!";
200 } 194 }
201 service()->AddExtension(extension); 195 service()->AddExtension(extension.get());
202 if (!registry()->enabled_extensions().GetByID(extension->id())) { 196 if (!registry()->enabled_extensions().GetByID(extension->id())) {
203 return testing::AssertionFailure() << "Failed to install extension: " << 197 return testing::AssertionFailure() << "Failed to install extension: " <<
204 extension->name(); 198 extension->name();
205 } 199 }
206 return testing::AssertionSuccess(); 200 return testing::AssertionSuccess();
207 } 201 }
208 202
209 testing::AssertionResult ExtensionToolbarModelUnitTest::RemoveExtension( 203 testing::AssertionResult ExtensionToolbarModelUnitTest::RemoveExtension(
210 scoped_refptr<const Extension> extension) { 204 const scoped_refptr<const Extension>& extension) {
211 if (!registry()->enabled_extensions().GetByID(extension->id())) { 205 if (!registry()->enabled_extensions().GetByID(extension->id())) {
212 return testing::AssertionFailure() << "Extension " << extension->name() << 206 return testing::AssertionFailure() << "Extension " << extension->name() <<
213 " not installed!"; 207 " not installed!";
214 } 208 }
215 service()->UnloadExtension(extension->id(), 209 service()->UnloadExtension(extension->id(),
216 UnloadedExtensionInfo::REASON_DISABLE); 210 UnloadedExtensionInfo::REASON_DISABLE);
217 if (registry()->enabled_extensions().GetByID(extension->id())) { 211 if (registry()->enabled_extensions().GetByID(extension->id())) {
218 return testing::AssertionFailure() << "Failed to unload extension: " << 212 return testing::AssertionFailure() << "Failed to unload extension: " <<
219 extension->name(); 213 extension->name();
220 } 214 }
(...skipping 27 matching lines...) Expand all
248 ExtensionList extensions; 242 ExtensionList extensions;
249 extensions.push_back(browser_action_a_); 243 extensions.push_back(browser_action_a_);
250 extensions.push_back(browser_action_b_); 244 extensions.push_back(browser_action_b_);
251 extensions.push_back(browser_action_c_); 245 extensions.push_back(browser_action_c_);
252 246
253 return AddAndVerifyExtensions(extensions); 247 return AddAndVerifyExtensions(extensions);
254 } 248 }
255 249
256 const Extension* ExtensionToolbarModelUnitTest::GetExtensionAtIndex( 250 const Extension* ExtensionToolbarModelUnitTest::GetExtensionAtIndex(
257 size_t index) const { 251 size_t index) const {
258 return index < toolbar_model_->toolbar_items().size() ? 252 return index < toolbar_model_->toolbar_items().size()
259 toolbar_model_->toolbar_items()[index] : NULL; 253 ? toolbar_model_->toolbar_items()[index].get()
254 : NULL;
260 } 255 }
261 256
262 testing::AssertionResult ExtensionToolbarModelUnitTest::AddAndVerifyExtensions( 257 testing::AssertionResult ExtensionToolbarModelUnitTest::AddAndVerifyExtensions(
263 const ExtensionList& extensions) { 258 const ExtensionList& extensions) {
264 for (ExtensionList::const_iterator iter = extensions.begin(); 259 for (ExtensionList::const_iterator iter = extensions.begin();
265 iter != extensions.end(); ++iter) { 260 iter != extensions.end(); ++iter) {
266 if (!AddExtension(*iter)) { 261 if (!AddExtension(*iter)) {
267 return testing::AssertionFailure() << "Failed to install extension: " << 262 return testing::AssertionFailure() << "Failed to install extension: " <<
268 (*iter)->name(); 263 (*iter)->name();
269 } 264 }
(...skipping 19 matching lines...) Expand all
289 scoped_refptr<const Extension> extension2 = 284 scoped_refptr<const Extension> extension2 =
290 GetActionExtension("browser_action", manifest_keys::kBrowserAction); 285 GetActionExtension("browser_action", manifest_keys::kBrowserAction);
291 ASSERT_TRUE(AddExtension(extension2)); 286 ASSERT_TRUE(AddExtension(extension2));
292 287
293 // We should now find our extension in the model. 288 // We should now find our extension in the model.
294 EXPECT_EQ(1u, observer()->inserted_count()); 289 EXPECT_EQ(1u, observer()->inserted_count());
295 EXPECT_EQ(1u, num_toolbar_items()); 290 EXPECT_EQ(1u, num_toolbar_items());
296 EXPECT_EQ(extension2, GetExtensionAtIndex(0u)); 291 EXPECT_EQ(extension2, GetExtensionAtIndex(0u));
297 292
298 // Should be a no-op, but still fires the events. 293 // Should be a no-op, but still fires the events.
299 toolbar_model()->MoveExtensionIcon(extension2, 0); 294 toolbar_model()->MoveExtensionIcon(extension2.get(), 0);
300 EXPECT_EQ(1u, observer()->moved_count()); 295 EXPECT_EQ(1u, observer()->moved_count());
301 EXPECT_EQ(1u, num_toolbar_items()); 296 EXPECT_EQ(1u, num_toolbar_items());
302 EXPECT_EQ(extension2, GetExtensionAtIndex(0u)); 297 EXPECT_EQ(extension2, GetExtensionAtIndex(0u));
303 298
304 // Remove the extension and verify. 299 // Remove the extension and verify.
305 ASSERT_TRUE(RemoveExtension(extension2)); 300 ASSERT_TRUE(RemoveExtension(extension2));
306 EXPECT_EQ(1u, observer()->removed_count()); 301 EXPECT_EQ(1u, observer()->removed_count());
307 EXPECT_EQ(0u, num_toolbar_items()); 302 EXPECT_EQ(0u, num_toolbar_items());
308 EXPECT_EQ(NULL, GetExtensionAtIndex(0u)); 303 EXPECT_EQ(NULL, GetExtensionAtIndex(0u));
309 } 304 }
(...skipping 501 matching lines...) Expand 10 before | Expand all | Expand 10 after
811 ExtensionActionAPI::SetBrowserActionVisibility( 806 ExtensionActionAPI::SetBrowserActionVisibility(
812 prefs, extension_b->id(), true); 807 prefs, extension_b->id(), true);
813 EXPECT_EQ(3u, num_toolbar_items()); 808 EXPECT_EQ(3u, num_toolbar_items());
814 EXPECT_EQ(-1, toolbar_model()->GetVisibleIconCount()); // -1 = 'all' 809 EXPECT_EQ(-1, toolbar_model()->GetVisibleIconCount()); // -1 = 'all'
815 EXPECT_EQ(extension_c, GetExtensionAtIndex(0u)); 810 EXPECT_EQ(extension_c, GetExtensionAtIndex(0u));
816 EXPECT_EQ(extension_a, GetExtensionAtIndex(1u)); 811 EXPECT_EQ(extension_a, GetExtensionAtIndex(1u));
817 EXPECT_EQ(extension_b, GetExtensionAtIndex(2u)); 812 EXPECT_EQ(extension_b, GetExtensionAtIndex(2u));
818 } 813 }
819 814
820 } // namespace extensions 815 } // namespace extensions
OLDNEW
« no previous file with comments | « chrome/browser/extensions/extension_service.cc ('k') | chrome/browser/extensions/permissions_updater.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698