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

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

Issue 2537263003: [Extensions] Fix lifetime bug in ExtensionAction/IconImage (Closed)
Patch Set: Created 4 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
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 <utility> 7 #include <utility>
8 8
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/files/file_util.h" 10 #include "base/files/file_util.h"
(...skipping 257 matching lines...) Expand 10 before | Expand all | Expand 10 after
268 // manifest and does not call |SetIcon| by default (but has an browser action 268 // manifest and does not call |SetIcon| by default (but has an browser action
269 // icon resource). 269 // icon resource).
270 scoped_refptr<Extension> extension(CreateExtension( 270 scoped_refptr<Extension> extension(CreateExtension(
271 "browser_action/no_icon", Manifest::INVALID_LOCATION)); 271 "browser_action/no_icon", Manifest::INVALID_LOCATION));
272 ASSERT_TRUE(extension.get() != NULL); 272 ASSERT_TRUE(extension.get() != NULL);
273 ExtensionAction* browser_action = GetBrowserAction(*extension); 273 ExtensionAction* browser_action = GetBrowserAction(*extension);
274 ASSERT_TRUE(browser_action); 274 ASSERT_TRUE(browser_action);
275 ASSERT_FALSE(browser_action->default_icon()); 275 ASSERT_FALSE(browser_action->default_icon());
276 ASSERT_TRUE(browser_action->GetExplicitlySetIcon(0 /*tab id*/).IsEmpty()); 276 ASSERT_TRUE(browser_action->GetExplicitlySetIcon(0 /*tab id*/).IsEmpty());
277 277
278 scoped_refptr<const Extension> extension_with_icon =
279 CreateExtension("browser_action_with_icon", Manifest::INVALID_LOCATION);
280 ASSERT_TRUE(extension_with_icon);
281
278 int icon_size = ExtensionAction::ActionIconSize(); 282 int icon_size = ExtensionAction::ActionIconSize();
279 gfx::Image default_icon = 283 gfx::Image default_icon =
280 EnsureImageSize(LoadIcon("browser_action/no_icon/icon.png"), icon_size); 284 EnsureImageSize(LoadIcon("browser_action_with_icon/icon.png"), icon_size);
281 ASSERT_FALSE(default_icon.IsEmpty()); 285 ASSERT_FALSE(default_icon.IsEmpty());
282 286
283 std::unique_ptr<ExtensionIconSet> default_icon_set(new ExtensionIconSet()); 287 browser_action = GetBrowserAction(*extension_with_icon);
284 default_icon_set->Add(icon_size, "icon.png");
285
286 browser_action->SetDefaultIconForTest(std::move(default_icon_set));
287 ASSERT_TRUE(browser_action->default_icon()); 288 ASSERT_TRUE(browser_action->default_icon());
288 289
289 ExtensionActionIconFactory icon_factory( 290 ExtensionActionIconFactory icon_factory(
290 profile(), extension.get(), browser_action, this); 291 profile(), extension_with_icon.get(), browser_action, this);
291 292
292 gfx::Image icon = icon_factory.GetIcon(0); 293 gfx::Image icon = icon_factory.GetIcon(0);
293 294
294 // The icon should be loaded asynchronously. Initially a transparent icon 295 // The icon should be loaded asynchronously. Initially a transparent icon
295 // should be returned. 296 // should be returned.
296 EXPECT_TRUE(ImageRepsAreEqual( 297 EXPECT_TRUE(ImageRepsAreEqual(
297 CreateBlankRep(icon_size, 1.0f), 298 CreateBlankRep(icon_size, 1.0f),
298 icon.ToImageSkia()->GetRepresentation(1.0f))); 299 icon.ToImageSkia()->GetRepresentation(1.0f)));
299 300
300 WaitForIconUpdate(); 301 WaitForIconUpdate();
301 302
302 icon = icon_factory.GetIcon(0); 303 icon = icon_factory.GetIcon(0);
303 304
304 // The default icon representation should be loaded at this point. 305 // The default icon representation should be loaded at this point.
305 EXPECT_TRUE(ImageRepsAreEqual( 306 EXPECT_TRUE(ImageRepsAreEqual(
306 default_icon.ToImageSkia()->GetRepresentation(1.0f), 307 default_icon.ToImageSkia()->GetRepresentation(1.0f),
307 icon.ToImageSkia()->GetRepresentation(1.0f))); 308 icon.ToImageSkia()->GetRepresentation(1.0f)));
308 309
309 // The same icon should be returned for the other tabs. 310 // The same icon should be returned for the other tabs.
310 icon = icon_factory.GetIcon(1); 311 icon = icon_factory.GetIcon(1);
311 312
312 EXPECT_TRUE(ImageRepsAreEqual( 313 EXPECT_TRUE(ImageRepsAreEqual(
313 default_icon.ToImageSkia()->GetRepresentation(1.0f), 314 default_icon.ToImageSkia()->GetRepresentation(1.0f),
314 icon.ToImageSkia()->GetRepresentation(1.0f))); 315 icon.ToImageSkia()->GetRepresentation(1.0f)));
315 316
316 } 317 }
317 318
318 } // namespace 319 } // namespace
319 } // namespace extensions 320 } // namespace extensions
OLDNEW
« no previous file with comments | « chrome/browser/extensions/extension_action_icon_factory.cc ('k') | chrome/browser/extensions/extension_action_manager.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698