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

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

Issue 10855154: Update browserAction.setIcon and pageAction.setIcon for hidpi (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: nits Created 8 years, 4 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
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 737b94c248cf4ec7c8a9a8c3f8a1f55ce760b212..a3145f30c9df4bfc3df7f80bb5f41238190f5d84 100644
--- a/chrome/browser/extensions/api/extension_action/browser_action_apitest.cc
+++ b/chrome/browser/extensions/api/extension_action/browser_action_apitest.cc
@@ -26,6 +26,7 @@
#include "content/public/test/browser_test_utils.h"
#include "ui/gfx/rect.h"
#include "ui/gfx/size.h"
+#include "ui/gfx/image/image_skia.h"
using content::WebContents;
using extensions::Extension;
@@ -50,6 +51,35 @@ class BrowserActionApiTest : public ExtensionApiTest {
EXPECT_TRUE(catcher.GetNextResult()) << catcher.message();
return GetBrowserActionsBar().HasPopup();
}
+
+ // Verifies that icons gotten from actions bar and browser action have
+ // changed. Also checks if action icon has icon representation for 2x as
+ // expected.
+ void VerifyIconState(const Extension* extension,
Jeffrey Yasskin 2012/08/17 23:20:28 Please use descriptive assertion names, so people
tbarzic 2012/08/21 00:22:07 ok, got rid of this function..
+ bool has_2x_icon,
+ uint32_t* last_bar_icon_id,
+ uint32_t* last_action_icon_id) {
+ gfx::ImageSkia action_icon =
+ extension->browser_action()->GetIcon(0).AsImageSkia();
+
+ EXPECT_EQ(has_2x_icon,
+ action_icon.HasRepresentation(ui::SCALE_FACTOR_200P));
+
+ SkBitmap action_icon_bitmap =
+ action_icon.GetRepresentation(ui::SCALE_FACTOR_100P).sk_bitmap();
+
+ uint32_t bar_icon_id = GetBrowserActionsBar().GetIconID(0);
+
+ if (*last_action_icon_id > 0)
+ EXPECT_GT(action_icon_bitmap.getGenerationID(), *last_action_icon_id);
Jeffrey Yasskin 2012/08/17 23:20:28 Please include a test that checks for icon equalit
tbarzic 2012/08/21 00:22:07 yeah, I've stumbled upon that function on Friday,
+ if (*last_bar_icon_id > 0)
+ EXPECT_GT(bar_icon_id, *last_bar_icon_id);
+
+ // Update last icon ids so we can test next icons' ids against current
+ // icons.
+ *last_action_icon_id = action_icon_bitmap.getGenerationID();
+ *last_bar_icon_id = bar_icon_id;
+ }
};
IN_PROC_BROWSER_TEST_F(BrowserActionApiTest, Basic) {
@@ -102,33 +132,40 @@ IN_PROC_BROWSER_TEST_F(BrowserActionApiTest, DynamicBrowserAction) {
ASSERT_EQ(1, GetBrowserActionsBar().NumberOfBrowserActions());
EXPECT_TRUE(GetBrowserActionsBar().HasIcon(0));
- // Set prev_id which holds the id of the previous image, and use it in the
- // next test to see if the image changes.
- uint32_t prev_id = extension->browser_action()->GetIcon(0).
- ToSkBitmap()->getGenerationID();
+ uint32_t action_icon_last_id = 0;
+ uint32_t bar_icon_last_id = 0;
- // Tell the extension to update the icon using setIcon({imageData:...}).
ResultCatcher catcher;
- ui_test_utils::NavigateToURL(browser(),
- GURL(extension->GetResourceURL("update.html")));
+
+ // First, let's setup icon ids to some valid values..
+ GetBrowserActionsBar().Press(0);
ASSERT_TRUE(catcher.GetNextResult());
- // Test that we received the changes.
- EXPECT_TRUE(GetBrowserActionsBar().HasIcon(0));
- EXPECT_NE(prev_id,
- extension->browser_action()->GetIcon(0).
- ToSkBitmap()->getGenerationID());
- prev_id = extension->browser_action()->GetIcon(0).
- ToSkBitmap()->getGenerationID();
+ VerifyIconState(extension, false, &bar_icon_last_id, &action_icon_last_id);
+
+ // Tell the extension to update the icon using setIcon({imageData:...}).
+ GetBrowserActionsBar().Press(0);
+ ASSERT_TRUE(catcher.GetNextResult());
+
+ VerifyIconState(extension, false, &bar_icon_last_id, &action_icon_last_id);
// Tell the extension to update the icon using setIcon({path:...}).
- ui_test_utils::NavigateToURL(browser(),
- GURL(extension->GetResourceURL("update2.html")));
+ GetBrowserActionsBar().Press(0);
ASSERT_TRUE(catcher.GetNextResult());
- EXPECT_TRUE(GetBrowserActionsBar().HasIcon(0));
- EXPECT_NE(prev_id,
- extension->browser_action()->GetIcon(0).
- ToSkBitmap()->getGenerationID());
+
+ VerifyIconState(extension, false, &bar_icon_last_id, &action_icon_last_id);
+
+ // Tell the extension to update the icon using setIcon({imageDataSet:...}).
+ GetBrowserActionsBar().Press(0);
+ ASSERT_TRUE(catcher.GetNextResult());
+
+ VerifyIconState(extension, true, &bar_icon_last_id, &action_icon_last_id);
+
+ // Tell the extension to update the icon using setIcon({pathSet:...}).
+ GetBrowserActionsBar().Press(0);
+ ASSERT_TRUE(catcher.GetNextResult());
+
+ VerifyIconState(extension, true, &bar_icon_last_id, &action_icon_last_id);
}
// This test is flaky as per http://crbug.com/74557.

Powered by Google App Engine
This is Rietveld 408576698