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..2cbf69289877a2bf6b210426c008b887339567d9 100644 |
--- a/chrome/browser/extensions/api/extension_action/browser_action_apitest.cc |
+++ b/chrome/browser/extensions/api/extension_action/browser_action_apitest.cc |
@@ -24,11 +24,26 @@ |
#include "content/public/browser/notification_service.h" |
#include "content/public/browser/web_contents.h" |
#include "content/public/test/browser_test_utils.h" |
+#include "testing/gmock/include/gmock/gmock.h" |
#include "ui/gfx/rect.h" |
#include "ui/gfx/size.h" |
+using content::BrowserThread; |
using content::WebContents; |
using extensions::Extension; |
+using ::testing::_; |
+ |
+namespace { |
+ |
+class MockActionIconFactory : public ExtensionAction::IconFactory { |
+ public: |
+ virtual ~MockActionIconFactory() {} |
+ |
+ MOCK_METHOD2(GetIcon, gfx::ImageSkia(const ExtensionIconSet* icon_set, |
+ ExtensionAction::Type type)); |
+}; |
+ |
+} // namespace |
class BrowserActionApiTest : public ExtensionApiTest { |
public: |
@@ -98,14 +113,20 @@ IN_PROC_BROWSER_TEST_F(BrowserActionApiTest, DynamicBrowserAction) { |
const Extension* extension = GetSingleLoadedExtension(); |
ASSERT_TRUE(extension) << message_; |
+ MockActionIconFactory mock_icon_factory; |
+ EXPECT_CALL(mock_icon_factory, GetIcon(_, _)).Times(0); |
+ |
// Test that there is a browser action in the toolbar. |
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(); |
+ // The extension should not have default icon defined in its manifest |
+ // (default icon is loaded asynchronously, so it may change even without the |
+ // update step). |
+ uint32_t prev_id = extension->browser_action()-> |
+ GetIcon(0, &mock_icon_factory).ToSkBitmap()->getGenerationID(); |
// Tell the extension to update the icon using setIcon({imageData:...}). |
ResultCatcher catcher; |
@@ -116,9 +137,9 @@ IN_PROC_BROWSER_TEST_F(BrowserActionApiTest, DynamicBrowserAction) { |
// Test that we received the changes. |
EXPECT_TRUE(GetBrowserActionsBar().HasIcon(0)); |
EXPECT_NE(prev_id, |
- extension->browser_action()->GetIcon(0). |
+ extension->browser_action()->GetIcon(0, &mock_icon_factory). |
ToSkBitmap()->getGenerationID()); |
- prev_id = extension->browser_action()->GetIcon(0). |
+ prev_id = extension->browser_action()->GetIcon(0, &mock_icon_factory). |
ToSkBitmap()->getGenerationID(); |
// Tell the extension to update the icon using setIcon({path:...}). |
@@ -127,7 +148,7 @@ IN_PROC_BROWSER_TEST_F(BrowserActionApiTest, DynamicBrowserAction) { |
ASSERT_TRUE(catcher.GetNextResult()); |
EXPECT_TRUE(GetBrowserActionsBar().HasIcon(0)); |
EXPECT_NE(prev_id, |
- extension->browser_action()->GetIcon(0). |
+ extension->browser_action()->GetIcon(0, &mock_icon_factory). |
ToSkBitmap()->getGenerationID()); |
} |