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

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

Issue 16295003: Update chrome/ to use scoped_refptr<T>::get() rather than implicit "operator T*" (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebased Created 7 years, 6 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "chrome/browser/extensions/extension_action_icon_factory.h" 5 #include "chrome/browser/extensions/extension_action_icon_factory.h"
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/file_util.h" 8 #include "base/file_util.h"
9 #include "base/json/json_file_value_serializer.h" 9 #include "base/json/json_file_value_serializer.h"
10 #include "base/message_loop.h" 10 #include "base/message_loop.h"
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
118 if (error_code != 0) 118 if (error_code != 0)
119 return NULL; 119 return NULL;
120 120
121 EXPECT_TRUE(valid_value.get()); 121 EXPECT_TRUE(valid_value.get());
122 if (!valid_value) 122 if (!valid_value)
123 return NULL; 123 return NULL;
124 124
125 scoped_refptr<Extension> extension = 125 scoped_refptr<Extension> extension =
126 Extension::Create(test_file, location, *valid_value, 126 Extension::Create(test_file, location, *valid_value,
127 Extension::NO_FLAGS, &error); 127 Extension::NO_FLAGS, &error);
128 EXPECT_TRUE(extension) << error; 128 EXPECT_TRUE(extension.get()) << error;
129 if (extension) 129 if (extension.get())
130 extension_service_->AddExtension(extension); 130 extension_service_->AddExtension(extension.get());
131 return extension; 131 return extension;
132 } 132 }
133 133
134 // testing::Test overrides: 134 // testing::Test overrides:
135 virtual void SetUp() OVERRIDE { 135 virtual void SetUp() OVERRIDE {
136 file_thread_.Start(); 136 file_thread_.Start();
137 io_thread_.Start(); 137 io_thread_.Start();
138 profile_.reset(new TestingProfile); 138 profile_.reset(new TestingProfile);
139 CommandLine command_line(CommandLine::NO_PROGRAM); 139 CommandLine command_line(CommandLine::NO_PROGRAM);
140 extension_service_ = static_cast<extensions::TestExtensionSystem*>( 140 extension_service_ = static_cast<extensions::TestExtensionSystem*>(
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
183 }; 183 };
184 184
185 // If there is no default icon, and the icon has not been set using |SetIcon|, 185 // If there is no default icon, and the icon has not been set using |SetIcon|,
186 // the factory should return favicon. 186 // the factory should return favicon.
187 TEST_F(ExtensionActionIconFactoryTest, NoIcons) { 187 TEST_F(ExtensionActionIconFactoryTest, NoIcons) {
188 // Load an extension that has browser action without default icon set in the 188 // Load an extension that has browser action without default icon set in the
189 // manifest and does not call |SetIcon| by default. 189 // manifest and does not call |SetIcon| by default.
190 scoped_refptr<Extension> extension(CreateExtension( 190 scoped_refptr<Extension> extension(CreateExtension(
191 "browser_action/no_icon", Manifest::INVALID_LOCATION)); 191 "browser_action/no_icon", Manifest::INVALID_LOCATION));
192 ASSERT_TRUE(extension.get() != NULL); 192 ASSERT_TRUE(extension.get() != NULL);
193 ExtensionAction* browser_action = GetBrowserAction(*extension); 193 ExtensionAction* browser_action = GetBrowserAction(*extension.get());
194 ASSERT_TRUE(browser_action); 194 ASSERT_TRUE(browser_action);
195 ASSERT_FALSE(browser_action->default_icon()); 195 ASSERT_FALSE(browser_action->default_icon());
196 ASSERT_TRUE(browser_action->GetExplicitlySetIcon(0 /*tab id*/).isNull()); 196 ASSERT_TRUE(browser_action->GetExplicitlySetIcon(0 /*tab id*/).isNull());
197 197
198 gfx::ImageSkia favicon = GetFavicon(); 198 gfx::ImageSkia favicon = GetFavicon();
199 199
200 ExtensionActionIconFactory icon_factory( 200 ExtensionActionIconFactory icon_factory(
201 profile(), extension,browser_action, this); 201 profile(), extension.get(), browser_action, this);
202 202
203 gfx::Image icon = icon_factory.GetIcon(0); 203 gfx::Image icon = icon_factory.GetIcon(0);
204 204
205 EXPECT_TRUE(ImageRepsAreEqual( 205 EXPECT_TRUE(ImageRepsAreEqual(
206 favicon.GetRepresentation(ui::SCALE_FACTOR_100P), 206 favicon.GetRepresentation(ui::SCALE_FACTOR_100P),
207 icon.ToImageSkia()->GetRepresentation(ui::SCALE_FACTOR_100P))); 207 icon.ToImageSkia()->GetRepresentation(ui::SCALE_FACTOR_100P)));
208 } 208 }
209 209
210 // If the icon has been set using |SetIcon|, the factory should return that 210 // If the icon has been set using |SetIcon|, the factory should return that
211 // icon. 211 // icon.
212 TEST_F(ExtensionActionIconFactoryTest, AfterSetIcon) { 212 TEST_F(ExtensionActionIconFactoryTest, AfterSetIcon) {
213 // Load an extension that has browser action without default icon set in the 213 // Load an extension that has browser action without default icon set in the
214 // manifest and does not call |SetIcon| by default (but has an browser action 214 // manifest and does not call |SetIcon| by default (but has an browser action
215 // icon resource). 215 // icon resource).
216 scoped_refptr<Extension> extension(CreateExtension( 216 scoped_refptr<Extension> extension(CreateExtension(
217 "browser_action/no_icon", Manifest::INVALID_LOCATION)); 217 "browser_action/no_icon", Manifest::INVALID_LOCATION));
218 ASSERT_TRUE(extension.get() != NULL); 218 ASSERT_TRUE(extension.get() != NULL);
219 ExtensionAction* browser_action = GetBrowserAction(*extension); 219 ExtensionAction* browser_action = GetBrowserAction(*extension.get());
220 ASSERT_TRUE(browser_action); 220 ASSERT_TRUE(browser_action);
221 ASSERT_FALSE(browser_action->default_icon()); 221 ASSERT_FALSE(browser_action->default_icon());
222 ASSERT_TRUE(browser_action->GetExplicitlySetIcon(0 /*tab id*/).isNull()); 222 ASSERT_TRUE(browser_action->GetExplicitlySetIcon(0 /*tab id*/).isNull());
223 223
224 gfx::Image set_icon = LoadIcon("browser_action/no_icon/icon.png"); 224 gfx::Image set_icon = LoadIcon("browser_action/no_icon/icon.png");
225 ASSERT_FALSE(set_icon.IsEmpty()); 225 ASSERT_FALSE(set_icon.IsEmpty());
226 226
227 browser_action->SetIcon(0, set_icon); 227 browser_action->SetIcon(0, set_icon);
228 228
229 ASSERT_FALSE(browser_action->GetExplicitlySetIcon(0 /*tab id*/).isNull()); 229 ASSERT_FALSE(browser_action->GetExplicitlySetIcon(0 /*tab id*/).isNull());
230 230
231 ExtensionActionIconFactory icon_factory( 231 ExtensionActionIconFactory icon_factory(
232 profile(), extension, browser_action, this); 232 profile(), extension.get(), browser_action, this);
233 233
234 gfx::Image icon = icon_factory.GetIcon(0); 234 gfx::Image icon = icon_factory.GetIcon(0);
235 235
236 EXPECT_TRUE(ImageRepsAreEqual( 236 EXPECT_TRUE(ImageRepsAreEqual(
237 set_icon.ToImageSkia()->GetRepresentation(ui::SCALE_FACTOR_100P), 237 set_icon.ToImageSkia()->GetRepresentation(ui::SCALE_FACTOR_100P),
238 icon.ToImageSkia()->GetRepresentation(ui::SCALE_FACTOR_100P))); 238 icon.ToImageSkia()->GetRepresentation(ui::SCALE_FACTOR_100P)));
239 239
240 // It should still return favicon for another tabs. 240 // It should still return favicon for another tabs.
241 icon = icon_factory.GetIcon(1); 241 icon = icon_factory.GetIcon(1);
242 242
243 EXPECT_TRUE(ImageRepsAreEqual( 243 EXPECT_TRUE(ImageRepsAreEqual(
244 GetFavicon().GetRepresentation(ui::SCALE_FACTOR_100P), 244 GetFavicon().GetRepresentation(ui::SCALE_FACTOR_100P),
245 icon.ToImageSkia()->GetRepresentation(ui::SCALE_FACTOR_100P))); 245 icon.ToImageSkia()->GetRepresentation(ui::SCALE_FACTOR_100P)));
246 } 246 }
247 247
248 // If there is a default icon, and the icon has not been set using |SetIcon|, 248 // If there is a default icon, and the icon has not been set using |SetIcon|,
249 // the factory should return the default icon. 249 // the factory should return the default icon.
250 TEST_F(ExtensionActionIconFactoryTest, DefaultIcon) { 250 TEST_F(ExtensionActionIconFactoryTest, DefaultIcon) {
251 // Load an extension that has browser action without default icon set in the 251 // Load an extension that has browser action without default icon set in the
252 // manifest and does not call |SetIcon| by default (but has an browser action 252 // manifest and does not call |SetIcon| by default (but has an browser action
253 // icon resource). 253 // icon resource).
254 scoped_refptr<Extension> extension(CreateExtension( 254 scoped_refptr<Extension> extension(CreateExtension(
255 "browser_action/no_icon", Manifest::INVALID_LOCATION)); 255 "browser_action/no_icon", Manifest::INVALID_LOCATION));
256 ASSERT_TRUE(extension.get() != NULL); 256 ASSERT_TRUE(extension.get() != NULL);
257 ExtensionAction* browser_action = GetBrowserAction(*extension); 257 ExtensionAction* browser_action = GetBrowserAction(*extension.get());
258 ASSERT_TRUE(browser_action); 258 ASSERT_TRUE(browser_action);
259 ASSERT_FALSE(browser_action->default_icon()); 259 ASSERT_FALSE(browser_action->default_icon());
260 ASSERT_TRUE(browser_action->GetExplicitlySetIcon(0 /*tab id*/).isNull()); 260 ASSERT_TRUE(browser_action->GetExplicitlySetIcon(0 /*tab id*/).isNull());
261 261
262 gfx::Image default_icon = 262 gfx::Image default_icon =
263 EnsureImageSize(LoadIcon("browser_action/no_icon/icon.png"), 19); 263 EnsureImageSize(LoadIcon("browser_action/no_icon/icon.png"), 19);
264 ASSERT_FALSE(default_icon.IsEmpty()); 264 ASSERT_FALSE(default_icon.IsEmpty());
265 265
266 scoped_ptr<ExtensionIconSet> default_icon_set(new ExtensionIconSet()); 266 scoped_ptr<ExtensionIconSet> default_icon_set(new ExtensionIconSet());
267 default_icon_set->Add(19, "icon.png"); 267 default_icon_set->Add(19, "icon.png");
268 268
269 browser_action->set_default_icon(default_icon_set.Pass()); 269 browser_action->set_default_icon(default_icon_set.Pass());
270 ASSERT_TRUE(browser_action->default_icon()); 270 ASSERT_TRUE(browser_action->default_icon());
271 271
272 ExtensionActionIconFactory icon_factory( 272 ExtensionActionIconFactory icon_factory(
273 profile(), extension, browser_action, this); 273 profile(), extension.get(), browser_action, this);
274 274
275 gfx::Image icon = icon_factory.GetIcon(0); 275 gfx::Image icon = icon_factory.GetIcon(0);
276 276
277 // The icon should be loaded asynchronously. Initially a transparent icon 277 // The icon should be loaded asynchronously. Initially a transparent icon
278 // should be returned. 278 // should be returned.
279 EXPECT_TRUE(ImageRepsAreEqual( 279 EXPECT_TRUE(ImageRepsAreEqual(
280 CreateBlankRep(19, ui::SCALE_FACTOR_100P), 280 CreateBlankRep(19, ui::SCALE_FACTOR_100P),
281 icon.ToImageSkia()->GetRepresentation(ui::SCALE_FACTOR_100P))); 281 icon.ToImageSkia()->GetRepresentation(ui::SCALE_FACTOR_100P)));
282 282
283 WaitForIconUpdate(); 283 WaitForIconUpdate();
284 284
285 icon = icon_factory.GetIcon(0); 285 icon = icon_factory.GetIcon(0);
286 286
287 // The default icon representation should be loaded at this point. 287 // The default icon representation should be loaded at this point.
288 EXPECT_TRUE(ImageRepsAreEqual( 288 EXPECT_TRUE(ImageRepsAreEqual(
289 default_icon.ToImageSkia()->GetRepresentation(ui::SCALE_FACTOR_100P), 289 default_icon.ToImageSkia()->GetRepresentation(ui::SCALE_FACTOR_100P),
290 icon.ToImageSkia()->GetRepresentation(ui::SCALE_FACTOR_100P))); 290 icon.ToImageSkia()->GetRepresentation(ui::SCALE_FACTOR_100P)));
291 291
292 // The same icon should be returned for the other tabs. 292 // The same icon should be returned for the other tabs.
293 icon = icon_factory.GetIcon(1); 293 icon = icon_factory.GetIcon(1);
294 294
295 EXPECT_TRUE(ImageRepsAreEqual( 295 EXPECT_TRUE(ImageRepsAreEqual(
296 default_icon.ToImageSkia()->GetRepresentation(ui::SCALE_FACTOR_100P), 296 default_icon.ToImageSkia()->GetRepresentation(ui::SCALE_FACTOR_100P),
297 icon.ToImageSkia()->GetRepresentation(ui::SCALE_FACTOR_100P))); 297 icon.ToImageSkia()->GetRepresentation(ui::SCALE_FACTOR_100P)));
298 298
299 } 299 }
300 300
301 } // namespace 301 } // namespace
302 } // namespace extensions 302 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698