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..15770cca5f916279089ce4d363896b46980b6871 100644 |
--- a/chrome/browser/extensions/api/extension_action/browser_action_apitest.cc |
+++ b/chrome/browser/extensions/api/extension_action/browser_action_apitest.cc |
@@ -8,6 +8,8 @@ |
#include <gtk/gtk.h> |
#endif |
+#include "base/message_loop.h" |
+#include "base/path_service.h" |
#include "chrome/browser/extensions/browser_action_test_util.h" |
#include "chrome/browser/extensions/extension_apitest.h" |
#include "chrome/browser/extensions/extension_service.h" |
@@ -18,17 +20,39 @@ |
#include "chrome/browser/ui/browser_tabstrip.h" |
#include "chrome/browser/ui/browser_window.h" |
#include "chrome/common/chrome_notification_types.h" |
+#include "chrome/common/chrome_paths.h" |
#include "chrome/common/extensions/extension_action.h" |
#include "chrome/common/url_constants.h" |
#include "chrome/test/base/ui_test_utils.h" |
#include "content/public/browser/notification_service.h" |
#include "content/public/browser/web_contents.h" |
#include "content/public/test/browser_test_utils.h" |
+#include "grit/theme_resources.h" |
+#include "testing/gmock/include/gmock/gmock.h" |
+#include "ui/base/resource/resource_bundle.h" |
+#include "ui/gfx/image/image_skia.h" |
+#include "ui/gfx/image/image_skia_operations.h" |
#include "ui/gfx/rect.h" |
#include "ui/gfx/size.h" |
+#include "ui/gfx/skia_util.h" |
+#include "webkit/glue/image_decoder.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 +122,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 +146,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 +157,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()); |
} |