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

Unified Diff: chrome/browser/extensions/api/extension_action/browser_action_apitest.cc

Issue 1214243003: [Extensions UI] Clean up extension icon generation (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: s/skia/ImageSkia Created 5 years, 5 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | chrome/browser/extensions/extension_action.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/extensions/api/extension_action/browser_action_apitest.cc
diff --git a/chrome/browser/extensions/api/extension_action/browser_action_apitest.cc b/chrome/browser/extensions/api/extension_action/browser_action_apitest.cc
index 6322c6a53a7a54ec3fe1db58a869836db73329cd..cd53e30f99da44e3e2e106c5600385098d728f5c 100644
--- a/chrome/browser/extensions/api/extension_action/browser_action_apitest.cc
+++ b/chrome/browser/extensions/api/extension_action/browser_action_apitest.cc
@@ -33,6 +33,7 @@
#include "ui/base/resource/resource_bundle.h"
#include "ui/gfx/geometry/rect.h"
#include "ui/gfx/geometry/size.h"
+#include "ui/gfx/image/canvas_image_source.h"
#include "ui/gfx/image/image_skia.h"
#include "ui/gfx/image/image_skia_operations.h"
#include "ui/gfx/skia_util.h"
@@ -42,21 +43,38 @@ using content::WebContents;
namespace extensions {
namespace {
+// An ImageSkia source that will do nothing (i.e., have a blank skia). We need
Avi (use Gerrit) 2015/07/06 23:20:06 ... have a blank what? You could totally just omi
+// this because we need a blank canvas at a certain size, and that can't be done
+// by just using a null ImageSkia.
+class BlankImageSource : public gfx::CanvasImageSource {
+ public:
+ explicit BlankImageSource(const gfx::Size& size)
+ : gfx::CanvasImageSource(size, false) {}
+ ~BlankImageSource() override {}
+
+ void Draw(gfx::Canvas* canvas) override {}
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(BlankImageSource);
+};
+
const char kEmptyImageDataError[] =
"The imageData property must contain an ImageData object or dictionary "
"of ImageData objects.";
const char kEmptyPathError[] = "The path property must not be empty.";
-// Views implementation of browser action button will return icon whose
-// background will be set.
-gfx::ImageSkia AddBackgroundForViews(const gfx::ImageSkia& icon) {
+// Views platforms have the icon superimposed over a button's background.
+// Macs don't, but still need a 29x29-sized image (and the easiest way to do
+// that is to superimpose the icon over a blank background).
+gfx::ImageSkia AddBackground(const gfx::ImageSkia& icon) {
#if !defined(OS_MACOSX)
ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
gfx::ImageSkia bg = *rb.GetImageSkiaNamed(IDR_BROWSER_ACTION);
- return gfx::ImageSkiaOperations::CreateSuperimposedImage(bg, icon);
#else
- return icon;
+ const gfx::Size size(29, 29); // Size of browser actions buttons.
+ gfx::ImageSkia bg(new BlankImageSource(size), size);
#endif
+ return gfx::ImageSkiaOperations::CreateSuperimposedImage(bg, icon);
}
bool ImagesAreEqualAtScale(const gfx::ImageSkia& i1,
@@ -182,7 +200,7 @@ IN_PROC_BROWSER_TEST_F(BrowserActionApiTest, DynamicBrowserAction) {
EXPECT_FALSE(action_icon.ToImageSkia()->HasRepresentation(2.0f));
EXPECT_TRUE(
- ImagesAreEqualAtScale(AddBackgroundForViews(*action_icon.ToImageSkia()),
+ ImagesAreEqualAtScale(AddBackground(*action_icon.ToImageSkia()),
*GetBrowserActionsBar()->GetIcon(0).ToImageSkia(),
1.0f));
@@ -200,7 +218,7 @@ IN_PROC_BROWSER_TEST_F(BrowserActionApiTest, DynamicBrowserAction) {
action_icon.ToImageSkia()->HasRepresentation(2.0f));
EXPECT_TRUE(
- ImagesAreEqualAtScale(AddBackgroundForViews(*action_icon.ToImageSkia()),
+ ImagesAreEqualAtScale(AddBackground(*action_icon.ToImageSkia()),
*GetBrowserActionsBar()->GetIcon(0).ToImageSkia(),
1.0f));
@@ -218,7 +236,7 @@ IN_PROC_BROWSER_TEST_F(BrowserActionApiTest, DynamicBrowserAction) {
EXPECT_TRUE(action_icon.ToImageSkia()->HasRepresentation(2.0f));
EXPECT_TRUE(
- ImagesAreEqualAtScale(AddBackgroundForViews(*action_icon.ToImageSkia()),
+ ImagesAreEqualAtScale(AddBackground(*action_icon.ToImageSkia()),
*GetBrowserActionsBar()->GetIcon(0).ToImageSkia(),
1.0f));
@@ -235,7 +253,7 @@ IN_PROC_BROWSER_TEST_F(BrowserActionApiTest, DynamicBrowserAction) {
EXPECT_TRUE(action_icon.ToImageSkia()->HasRepresentation(2.0f));
EXPECT_TRUE(
- ImagesAreEqualAtScale(AddBackgroundForViews(*action_icon.ToImageSkia()),
+ ImagesAreEqualAtScale(AddBackground(*action_icon.ToImageSkia()),
*GetBrowserActionsBar()->GetIcon(0).ToImageSkia(),
1.0f));
@@ -253,7 +271,7 @@ IN_PROC_BROWSER_TEST_F(BrowserActionApiTest, DynamicBrowserAction) {
EXPECT_FALSE(action_icon.ToImageSkia()->HasRepresentation(2.0f));
EXPECT_TRUE(
- ImagesAreEqualAtScale(AddBackgroundForViews(*action_icon.ToImageSkia()),
+ ImagesAreEqualAtScale(AddBackground(*action_icon.ToImageSkia()),
*GetBrowserActionsBar()->GetIcon(0).ToImageSkia(),
1.0f));
@@ -271,7 +289,7 @@ IN_PROC_BROWSER_TEST_F(BrowserActionApiTest, DynamicBrowserAction) {
EXPECT_FALSE(action_icon.ToImageSkia()->HasRepresentation(2.0f));
EXPECT_TRUE(
- ImagesAreEqualAtScale(AddBackgroundForViews(*action_icon.ToImageSkia()),
+ ImagesAreEqualAtScale(AddBackground(*action_icon.ToImageSkia()),
*GetBrowserActionsBar()->GetIcon(0).ToImageSkia(),
1.0f));
@@ -296,7 +314,7 @@ IN_PROC_BROWSER_TEST_F(BrowserActionApiTest, DynamicBrowserAction) {
action_icon_skia->GetRepresentation(2.0f).sk_bitmap()));
EXPECT_TRUE(
- ImagesAreEqualAtScale(AddBackgroundForViews(*action_icon_skia),
+ ImagesAreEqualAtScale(AddBackground(*action_icon_skia),
*GetBrowserActionsBar()->GetIcon(0).ToImageSkia(),
2.0f));
« no previous file with comments | « no previous file | chrome/browser/extensions/extension_action.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698