| 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 4426fa7b827fd06aea84f80f478f5677e12452e5..c54f952b8a93d68a32bd63f1c1a350782f05cd26 100644
|
| --- a/chrome/browser/extensions/api/extension_action/browser_action_apitest.cc
|
| +++ b/chrome/browser/extensions/api/extension_action/browser_action_apitest.cc
|
| @@ -68,28 +68,6 @@ const char kEmptyImageDataError[] =
|
| "of ImageData objects.";
|
| const char kEmptyPathError[] = "The path property must not be empty.";
|
|
|
| -// 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);
|
| -#else
|
| - 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,
|
| - const gfx::ImageSkia& i2,
|
| - float scale) {
|
| - SkBitmap bitmap1 = i1.GetRepresentation(scale).sk_bitmap();
|
| - SkBitmap bitmap2 = i2.GetRepresentation(scale).sk_bitmap();
|
| - return gfx::BitmapsAreEqual(bitmap1, bitmap2);
|
| -}
|
| -
|
| class BrowserActionApiTest : public ExtensionApiTest {
|
| public:
|
| BrowserActionApiTest() {}
|
| @@ -188,140 +166,135 @@ IN_PROC_BROWSER_TEST_F(BrowserActionApiTest, DynamicBrowserAction) {
|
| ASSERT_EQ(action_icon_last_id,
|
| icon_factory.GetIcon(0).ToSkBitmap()->getGenerationID());
|
|
|
| - uint32_t action_icon_current_id = 0;
|
| + gfx::ImageSkia last_bar_icon =
|
| + GetBrowserActionsBar()->GetIcon(0).AsImageSkia();
|
| + EXPECT_TRUE(last_bar_icon.BackedBySameObjectAs(
|
| + GetBrowserActionsBar()->GetIcon(0).AsImageSkia()));
|
|
|
| - ResultCatcher catcher;
|
| + // The reason we don't test more standard scales (like 1x, 2x, etc.) is that
|
| + // these may be generated from the provided scales.
|
| + float kSmallIconScale = 21.f / ExtensionAction::ActionIconSize();
|
| + float kLargeIconScale = 42.f / ExtensionAction::ActionIconSize();
|
| + ASSERT_FALSE(ui::IsSupportedScale(kSmallIconScale));
|
| + ASSERT_FALSE(ui::IsSupportedScale(kLargeIconScale));
|
|
|
| // Tell the extension to update the icon using ImageData object.
|
| + ResultCatcher catcher;
|
| GetBrowserActionsBar()->Press(0);
|
| ASSERT_TRUE(catcher.GetNextResult());
|
|
|
| action_icon = icon_factory.GetIcon(0);
|
| + EXPECT_FALSE(last_bar_icon.BackedBySameObjectAs(
|
| + GetBrowserActionsBar()->GetIcon(0).AsImageSkia()));
|
| + last_bar_icon = GetBrowserActionsBar()->GetIcon(0).AsImageSkia();
|
|
|
| - action_icon_current_id = action_icon.ToSkBitmap()->getGenerationID();
|
| + uint32_t action_icon_current_id = action_icon.ToSkBitmap()->getGenerationID();
|
| EXPECT_GT(action_icon_current_id, action_icon_last_id);
|
| action_icon_last_id = action_icon_current_id;
|
|
|
| - EXPECT_FALSE(action_icon.ToImageSkia()->HasRepresentation(2.0f));
|
| -
|
| - EXPECT_TRUE(
|
| - ImagesAreEqualAtScale(AddBackground(*action_icon.ToImageSkia()),
|
| - *GetBrowserActionsBar()->GetIcon(0).ToImageSkia(),
|
| - 1.0f));
|
| + EXPECT_TRUE(action_icon.ToImageSkia()->HasRepresentation(kSmallIconScale));
|
| + EXPECT_FALSE(action_icon.ToImageSkia()->HasRepresentation(kLargeIconScale));
|
|
|
| // Tell the extension to update the icon using path.
|
| GetBrowserActionsBar()->Press(0);
|
| ASSERT_TRUE(catcher.GetNextResult());
|
|
|
| - action_icon = icon_factory.GetIcon(0);
|
| + // Make sure the browser action bar updated.
|
| + EXPECT_FALSE(last_bar_icon.BackedBySameObjectAs(
|
| + GetBrowserActionsBar()->GetIcon(0).AsImageSkia()));
|
| + last_bar_icon = GetBrowserActionsBar()->GetIcon(0).AsImageSkia();
|
|
|
| + action_icon = icon_factory.GetIcon(0);
|
| action_icon_current_id = action_icon.ToSkBitmap()->getGenerationID();
|
| EXPECT_GT(action_icon_current_id, action_icon_last_id);
|
| action_icon_last_id = action_icon_current_id;
|
|
|
| - EXPECT_FALSE(
|
| - action_icon.ToImageSkia()->HasRepresentation(2.0f));
|
| -
|
| - EXPECT_TRUE(
|
| - ImagesAreEqualAtScale(AddBackground(*action_icon.ToImageSkia()),
|
| - *GetBrowserActionsBar()->GetIcon(0).ToImageSkia(),
|
| - 1.0f));
|
| + EXPECT_TRUE(action_icon.ToImageSkia()->HasRepresentation(kSmallIconScale));
|
| + EXPECT_FALSE(action_icon.ToImageSkia()->HasRepresentation(kLargeIconScale));
|
|
|
| // Tell the extension to update the icon using dictionary of ImageData
|
| // objects.
|
| GetBrowserActionsBar()->Press(0);
|
| ASSERT_TRUE(catcher.GetNextResult());
|
|
|
| - action_icon = icon_factory.GetIcon(0);
|
| + EXPECT_FALSE(last_bar_icon.BackedBySameObjectAs(
|
| + GetBrowserActionsBar()->GetIcon(0).AsImageSkia()));
|
| + last_bar_icon = GetBrowserActionsBar()->GetIcon(0).AsImageSkia();
|
|
|
| + action_icon = icon_factory.GetIcon(0);
|
| action_icon_current_id = action_icon.ToSkBitmap()->getGenerationID();
|
| EXPECT_GT(action_icon_current_id, action_icon_last_id);
|
| action_icon_last_id = action_icon_current_id;
|
|
|
| - EXPECT_TRUE(action_icon.ToImageSkia()->HasRepresentation(2.0f));
|
| -
|
| - EXPECT_TRUE(
|
| - ImagesAreEqualAtScale(AddBackground(*action_icon.ToImageSkia()),
|
| - *GetBrowserActionsBar()->GetIcon(0).ToImageSkia(),
|
| - 1.0f));
|
| + EXPECT_TRUE(action_icon.ToImageSkia()->HasRepresentation(kSmallIconScale));
|
| + EXPECT_TRUE(action_icon.ToImageSkia()->HasRepresentation(kLargeIconScale));
|
|
|
| // Tell the extension to update the icon using dictionary of paths.
|
| GetBrowserActionsBar()->Press(0);
|
| ASSERT_TRUE(catcher.GetNextResult());
|
|
|
| - action_icon = icon_factory.GetIcon(0);
|
| + EXPECT_FALSE(last_bar_icon.BackedBySameObjectAs(
|
| + GetBrowserActionsBar()->GetIcon(0).AsImageSkia()));
|
| + last_bar_icon = GetBrowserActionsBar()->GetIcon(0).AsImageSkia();
|
|
|
| + action_icon = icon_factory.GetIcon(0);
|
| action_icon_current_id = action_icon.ToSkBitmap()->getGenerationID();
|
| EXPECT_GT(action_icon_current_id, action_icon_last_id);
|
| action_icon_last_id = action_icon_current_id;
|
|
|
| - EXPECT_TRUE(action_icon.ToImageSkia()->HasRepresentation(2.0f));
|
| -
|
| - EXPECT_TRUE(
|
| - ImagesAreEqualAtScale(AddBackground(*action_icon.ToImageSkia()),
|
| - *GetBrowserActionsBar()->GetIcon(0).ToImageSkia(),
|
| - 1.0f));
|
| + EXPECT_TRUE(action_icon.ToImageSkia()->HasRepresentation(kSmallIconScale));
|
| + EXPECT_TRUE(action_icon.ToImageSkia()->HasRepresentation(kLargeIconScale));
|
|
|
| // Tell the extension to update the icon using dictionary of ImageData
|
| // objects, but setting only size 19.
|
| GetBrowserActionsBar()->Press(0);
|
| ASSERT_TRUE(catcher.GetNextResult());
|
|
|
| - action_icon = icon_factory.GetIcon(0);
|
| + EXPECT_FALSE(last_bar_icon.BackedBySameObjectAs(
|
| + GetBrowserActionsBar()->GetIcon(0).AsImageSkia()));
|
| + last_bar_icon = GetBrowserActionsBar()->GetIcon(0).AsImageSkia();
|
|
|
| + action_icon = icon_factory.GetIcon(0);
|
| action_icon_current_id = action_icon.ToSkBitmap()->getGenerationID();
|
| EXPECT_GT(action_icon_current_id, action_icon_last_id);
|
| action_icon_last_id = action_icon_current_id;
|
|
|
| - EXPECT_FALSE(action_icon.ToImageSkia()->HasRepresentation(2.0f));
|
| -
|
| - EXPECT_TRUE(
|
| - ImagesAreEqualAtScale(AddBackground(*action_icon.ToImageSkia()),
|
| - *GetBrowserActionsBar()->GetIcon(0).ToImageSkia(),
|
| - 1.0f));
|
| + EXPECT_TRUE(action_icon.ToImageSkia()->HasRepresentation(kSmallIconScale));
|
| + EXPECT_FALSE(action_icon.ToImageSkia()->HasRepresentation(kLargeIconScale));
|
|
|
| // Tell the extension to update the icon using dictionary of paths, but
|
| // setting only size 19.
|
| GetBrowserActionsBar()->Press(0);
|
| ASSERT_TRUE(catcher.GetNextResult());
|
|
|
| - action_icon = icon_factory.GetIcon(0);
|
| + EXPECT_FALSE(last_bar_icon.BackedBySameObjectAs(
|
| + GetBrowserActionsBar()->GetIcon(0).AsImageSkia()));
|
| + last_bar_icon = GetBrowserActionsBar()->GetIcon(0).AsImageSkia();
|
|
|
| + action_icon = icon_factory.GetIcon(0);
|
| action_icon_current_id = action_icon.ToSkBitmap()->getGenerationID();
|
| EXPECT_GT(action_icon_current_id, action_icon_last_id);
|
| action_icon_last_id = action_icon_current_id;
|
|
|
| - EXPECT_FALSE(action_icon.ToImageSkia()->HasRepresentation(2.0f));
|
| -
|
| - EXPECT_TRUE(
|
| - ImagesAreEqualAtScale(AddBackground(*action_icon.ToImageSkia()),
|
| - *GetBrowserActionsBar()->GetIcon(0).ToImageSkia(),
|
| - 1.0f));
|
| + EXPECT_TRUE(action_icon.ToImageSkia()->HasRepresentation(kSmallIconScale));
|
| + EXPECT_FALSE(action_icon.ToImageSkia()->HasRepresentation(kLargeIconScale));
|
|
|
| // Tell the extension to update the icon using dictionary of ImageData
|
| - // objects, but setting only size 38.
|
| + // objects, but setting only size 42.
|
| GetBrowserActionsBar()->Press(0);
|
| ASSERT_TRUE(catcher.GetNextResult());
|
|
|
| - action_icon = icon_factory.GetIcon(0);
|
| -
|
| - const gfx::ImageSkia* action_icon_skia = action_icon.ToImageSkia();
|
| -
|
| - EXPECT_FALSE(action_icon_skia->HasRepresentation(1.0f));
|
| - EXPECT_TRUE(action_icon_skia->HasRepresentation(2.0f));
|
| + EXPECT_FALSE(last_bar_icon.BackedBySameObjectAs(
|
| + GetBrowserActionsBar()->GetIcon(0).AsImageSkia()));
|
| + last_bar_icon = GetBrowserActionsBar()->GetIcon(0).AsImageSkia();
|
|
|
| + action_icon = icon_factory.GetIcon(0);
|
| action_icon_current_id = action_icon.ToSkBitmap()->getGenerationID();
|
| EXPECT_GT(action_icon_current_id, action_icon_last_id);
|
| action_icon_last_id = action_icon_current_id;
|
|
|
| - EXPECT_TRUE(gfx::BitmapsAreEqual(
|
| - *action_icon.ToSkBitmap(),
|
| - action_icon_skia->GetRepresentation(2.0f).sk_bitmap()));
|
| -
|
| - EXPECT_TRUE(
|
| - ImagesAreEqualAtScale(AddBackground(*action_icon_skia),
|
| - *GetBrowserActionsBar()->GetIcon(0).ToImageSkia(),
|
| - 2.0f));
|
| + EXPECT_FALSE(action_icon.ToImageSkia()->HasRepresentation(kSmallIconScale));
|
| + EXPECT_TRUE(action_icon.ToImageSkia()->HasRepresentation(kLargeIconScale));
|
|
|
| // Try setting icon with empty dictionary of ImageData objects.
|
| GetBrowserActionsBar()->Press(0);
|
|
|