| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "build/build_config.h" | 5 #include "build/build_config.h" |
| 6 | 6 |
| 7 #if defined(TOOLKIT_GTK) | 7 #if defined(TOOLKIT_GTK) |
| 8 #include <gtk/gtk.h> | 8 #include <gtk/gtk.h> |
| 9 #endif | 9 #endif |
| 10 | 10 |
| 11 #include "chrome/browser/extensions/browser_action_test_util.h" | 11 #include "chrome/browser/extensions/browser_action_test_util.h" |
| 12 #include "chrome/browser/extensions/extension_apitest.h" | 12 #include "chrome/browser/extensions/extension_apitest.h" |
| 13 #include "chrome/browser/extensions/extension_service.h" | 13 #include "chrome/browser/extensions/extension_service.h" |
| 14 #include "chrome/browser/extensions/extension_tab_util.h" | 14 #include "chrome/browser/extensions/extension_tab_util.h" |
| 15 #include "chrome/browser/profiles/profile.h" | 15 #include "chrome/browser/profiles/profile.h" |
| 16 #include "chrome/browser/ui/browser.h" | 16 #include "chrome/browser/ui/browser.h" |
| 17 #include "chrome/browser/ui/browser_commands.h" | 17 #include "chrome/browser/ui/browser_commands.h" |
| 18 #include "chrome/browser/ui/browser_tabstrip.h" | 18 #include "chrome/browser/ui/browser_tabstrip.h" |
| 19 #include "chrome/browser/ui/browser_window.h" | 19 #include "chrome/browser/ui/browser_window.h" |
| 20 #include "chrome/common/chrome_notification_types.h" | 20 #include "chrome/common/chrome_notification_types.h" |
| 21 #include "chrome/common/extensions/extension_action.h" | 21 #include "chrome/common/extensions/extension_action.h" |
| 22 #include "chrome/common/url_constants.h" | 22 #include "chrome/common/url_constants.h" |
| 23 #include "chrome/test/base/ui_test_utils.h" | 23 #include "chrome/test/base/ui_test_utils.h" |
| 24 #include "content/public/browser/notification_service.h" | 24 #include "content/public/browser/notification_service.h" |
| 25 #include "content/public/browser/web_contents.h" | 25 #include "content/public/browser/web_contents.h" |
| 26 #include "content/public/test/browser_test_utils.h" | 26 #include "content/public/test/browser_test_utils.h" |
| 27 #include "testing/gmock/include/gmock/gmock.h" |
| 27 #include "ui/gfx/rect.h" | 28 #include "ui/gfx/rect.h" |
| 28 #include "ui/gfx/size.h" | 29 #include "ui/gfx/size.h" |
| 29 | 30 |
| 31 using content::BrowserThread; |
| 30 using content::WebContents; | 32 using content::WebContents; |
| 31 using extensions::Extension; | 33 using extensions::Extension; |
| 34 using ::testing::_; |
| 35 |
| 36 namespace { |
| 37 |
| 38 class MockActionIconFactory : public ExtensionAction::IconFactory { |
| 39 public: |
| 40 virtual ~MockActionIconFactory() {} |
| 41 |
| 42 MOCK_METHOD2(GetIcon, gfx::ImageSkia(const ExtensionIconSet* icon_set, |
| 43 ExtensionAction::Type type)); |
| 44 }; |
| 45 |
| 46 } // namespace |
| 32 | 47 |
| 33 class BrowserActionApiTest : public ExtensionApiTest { | 48 class BrowserActionApiTest : public ExtensionApiTest { |
| 34 public: | 49 public: |
| 35 BrowserActionApiTest() {} | 50 BrowserActionApiTest() {} |
| 36 virtual ~BrowserActionApiTest() {} | 51 virtual ~BrowserActionApiTest() {} |
| 37 | 52 |
| 38 protected: | 53 protected: |
| 39 BrowserActionTestUtil GetBrowserActionsBar() { | 54 BrowserActionTestUtil GetBrowserActionsBar() { |
| 40 return BrowserActionTestUtil(browser()); | 55 return BrowserActionTestUtil(browser()); |
| 41 } | 56 } |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 91 L" window.domAutomationController.send(true)}}, 100)", | 106 L" window.domAutomationController.send(true)}}, 100)", |
| 92 &result)); | 107 &result)); |
| 93 ASSERT_TRUE(result); | 108 ASSERT_TRUE(result); |
| 94 } | 109 } |
| 95 | 110 |
| 96 IN_PROC_BROWSER_TEST_F(BrowserActionApiTest, DynamicBrowserAction) { | 111 IN_PROC_BROWSER_TEST_F(BrowserActionApiTest, DynamicBrowserAction) { |
| 97 ASSERT_TRUE(RunExtensionTest("browser_action/no_icon")) << message_; | 112 ASSERT_TRUE(RunExtensionTest("browser_action/no_icon")) << message_; |
| 98 const Extension* extension = GetSingleLoadedExtension(); | 113 const Extension* extension = GetSingleLoadedExtension(); |
| 99 ASSERT_TRUE(extension) << message_; | 114 ASSERT_TRUE(extension) << message_; |
| 100 | 115 |
| 116 MockActionIconFactory mock_icon_factory; |
| 117 EXPECT_CALL(mock_icon_factory, GetIcon(_, _)).Times(0); |
| 118 |
| 101 // Test that there is a browser action in the toolbar. | 119 // Test that there is a browser action in the toolbar. |
| 102 ASSERT_EQ(1, GetBrowserActionsBar().NumberOfBrowserActions()); | 120 ASSERT_EQ(1, GetBrowserActionsBar().NumberOfBrowserActions()); |
| 103 EXPECT_TRUE(GetBrowserActionsBar().HasIcon(0)); | 121 EXPECT_TRUE(GetBrowserActionsBar().HasIcon(0)); |
| 104 | 122 |
| 105 // Set prev_id which holds the id of the previous image, and use it in the | 123 // Set prev_id which holds the id of the previous image, and use it in the |
| 106 // next test to see if the image changes. | 124 // next test to see if the image changes. |
| 107 uint32_t prev_id = extension->browser_action()->GetIcon(0). | 125 // The extension should not have default icon defined in its manifest |
| 108 ToSkBitmap()->getGenerationID(); | 126 // (default icon is loaded asynchronously, so it may change even without the |
| 127 // update step). |
| 128 uint32_t prev_id = extension->browser_action()-> |
| 129 GetIcon(0, &mock_icon_factory).ToSkBitmap()->getGenerationID(); |
| 109 | 130 |
| 110 // Tell the extension to update the icon using setIcon({imageData:...}). | 131 // Tell the extension to update the icon using setIcon({imageData:...}). |
| 111 ResultCatcher catcher; | 132 ResultCatcher catcher; |
| 112 ui_test_utils::NavigateToURL(browser(), | 133 ui_test_utils::NavigateToURL(browser(), |
| 113 GURL(extension->GetResourceURL("update.html"))); | 134 GURL(extension->GetResourceURL("update.html"))); |
| 114 ASSERT_TRUE(catcher.GetNextResult()); | 135 ASSERT_TRUE(catcher.GetNextResult()); |
| 115 | 136 |
| 116 // Test that we received the changes. | 137 // Test that we received the changes. |
| 117 EXPECT_TRUE(GetBrowserActionsBar().HasIcon(0)); | 138 EXPECT_TRUE(GetBrowserActionsBar().HasIcon(0)); |
| 118 EXPECT_NE(prev_id, | 139 EXPECT_NE(prev_id, |
| 119 extension->browser_action()->GetIcon(0). | 140 extension->browser_action()->GetIcon(0, &mock_icon_factory). |
| 120 ToSkBitmap()->getGenerationID()); | 141 ToSkBitmap()->getGenerationID()); |
| 121 prev_id = extension->browser_action()->GetIcon(0). | 142 prev_id = extension->browser_action()->GetIcon(0, &mock_icon_factory). |
| 122 ToSkBitmap()->getGenerationID(); | 143 ToSkBitmap()->getGenerationID(); |
| 123 | 144 |
| 124 // Tell the extension to update the icon using setIcon({path:...}). | 145 // Tell the extension to update the icon using setIcon({path:...}). |
| 125 ui_test_utils::NavigateToURL(browser(), | 146 ui_test_utils::NavigateToURL(browser(), |
| 126 GURL(extension->GetResourceURL("update2.html"))); | 147 GURL(extension->GetResourceURL("update2.html"))); |
| 127 ASSERT_TRUE(catcher.GetNextResult()); | 148 ASSERT_TRUE(catcher.GetNextResult()); |
| 128 EXPECT_TRUE(GetBrowserActionsBar().HasIcon(0)); | 149 EXPECT_TRUE(GetBrowserActionsBar().HasIcon(0)); |
| 129 EXPECT_NE(prev_id, | 150 EXPECT_NE(prev_id, |
| 130 extension->browser_action()->GetIcon(0). | 151 extension->browser_action()->GetIcon(0, &mock_icon_factory). |
| 131 ToSkBitmap()->getGenerationID()); | 152 ToSkBitmap()->getGenerationID()); |
| 132 } | 153 } |
| 133 | 154 |
| 134 // This test is flaky as per http://crbug.com/74557. | 155 // This test is flaky as per http://crbug.com/74557. |
| 135 IN_PROC_BROWSER_TEST_F(BrowserActionApiTest, | 156 IN_PROC_BROWSER_TEST_F(BrowserActionApiTest, |
| 136 DISABLED_TabSpecificBrowserActionState) { | 157 DISABLED_TabSpecificBrowserActionState) { |
| 137 ASSERT_TRUE(RunExtensionTest("browser_action/tab_specific_state")) << | 158 ASSERT_TRUE(RunExtensionTest("browser_action/tab_specific_state")) << |
| 138 message_; | 159 message_; |
| 139 const Extension* extension = GetSingleLoadedExtension(); | 160 const Extension* extension = GetSingleLoadedExtension(); |
| 140 ASSERT_TRUE(extension) << message_; | 161 ASSERT_TRUE(extension) << message_; |
| (...skipping 329 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 470 ResultCatcher catcher; | 491 ResultCatcher catcher; |
| 471 ui_test_utils::NavigateToURL(browser(), | 492 ui_test_utils::NavigateToURL(browser(), |
| 472 GURL(extension->GetResourceURL("update.html"))); | 493 GURL(extension->GetResourceURL("update.html"))); |
| 473 ASSERT_TRUE(catcher.GetNextResult()); | 494 ASSERT_TRUE(catcher.GetNextResult()); |
| 474 | 495 |
| 475 // Test the getters for a specific tab. | 496 // Test the getters for a specific tab. |
| 476 ui_test_utils::NavigateToURL(browser(), | 497 ui_test_utils::NavigateToURL(browser(), |
| 477 GURL(extension->GetResourceURL("update2.html"))); | 498 GURL(extension->GetResourceURL("update2.html"))); |
| 478 ASSERT_TRUE(catcher.GetNextResult()); | 499 ASSERT_TRUE(catcher.GetNextResult()); |
| 479 } | 500 } |
| OLD | NEW |