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 "base/message_loop.h" |
| 12 #include "base/path_service.h" |
11 #include "chrome/browser/extensions/browser_action_test_util.h" | 13 #include "chrome/browser/extensions/browser_action_test_util.h" |
12 #include "chrome/browser/extensions/extension_apitest.h" | 14 #include "chrome/browser/extensions/extension_apitest.h" |
13 #include "chrome/browser/extensions/extension_service.h" | 15 #include "chrome/browser/extensions/extension_service.h" |
14 #include "chrome/browser/extensions/extension_tab_util.h" | 16 #include "chrome/browser/extensions/extension_tab_util.h" |
15 #include "chrome/browser/profiles/profile.h" | 17 #include "chrome/browser/profiles/profile.h" |
16 #include "chrome/browser/ui/browser.h" | 18 #include "chrome/browser/ui/browser.h" |
17 #include "chrome/browser/ui/browser_commands.h" | 19 #include "chrome/browser/ui/browser_commands.h" |
18 #include "chrome/browser/ui/browser_tabstrip.h" | 20 #include "chrome/browser/ui/browser_tabstrip.h" |
19 #include "chrome/browser/ui/browser_window.h" | 21 #include "chrome/browser/ui/browser_window.h" |
20 #include "chrome/common/chrome_notification_types.h" | 22 #include "chrome/common/chrome_notification_types.h" |
| 23 #include "chrome/common/chrome_paths.h" |
21 #include "chrome/common/extensions/extension_action.h" | 24 #include "chrome/common/extensions/extension_action.h" |
22 #include "chrome/common/url_constants.h" | 25 #include "chrome/common/url_constants.h" |
23 #include "chrome/test/base/ui_test_utils.h" | 26 #include "chrome/test/base/ui_test_utils.h" |
24 #include "content/public/browser/notification_service.h" | 27 #include "content/public/browser/notification_service.h" |
25 #include "content/public/browser/web_contents.h" | 28 #include "content/public/browser/web_contents.h" |
26 #include "content/public/test/browser_test_utils.h" | 29 #include "content/public/test/browser_test_utils.h" |
| 30 #include "grit/theme_resources.h" |
| 31 #include "testing/gmock/include/gmock/gmock.h" |
| 32 #include "ui/base/resource/resource_bundle.h" |
| 33 #include "ui/gfx/image/image_skia.h" |
| 34 #include "ui/gfx/image/image_skia_operations.h" |
27 #include "ui/gfx/rect.h" | 35 #include "ui/gfx/rect.h" |
28 #include "ui/gfx/size.h" | 36 #include "ui/gfx/size.h" |
| 37 #include "ui/gfx/skia_util.h" |
| 38 #include "webkit/glue/image_decoder.h" |
29 | 39 |
| 40 using content::BrowserThread; |
30 using content::WebContents; | 41 using content::WebContents; |
31 using extensions::Extension; | 42 using extensions::Extension; |
| 43 using ::testing::_; |
| 44 |
| 45 namespace { |
| 46 |
| 47 class MockActionIconFactory : public ExtensionAction::IconFactory { |
| 48 public: |
| 49 virtual ~MockActionIconFactory() {} |
| 50 |
| 51 MOCK_METHOD2(GetIcon, gfx::ImageSkia(const ExtensionIconSet* icon_set, |
| 52 ExtensionAction::Type type)); |
| 53 }; |
| 54 |
| 55 } // namespace |
32 | 56 |
33 class BrowserActionApiTest : public ExtensionApiTest { | 57 class BrowserActionApiTest : public ExtensionApiTest { |
34 public: | 58 public: |
35 BrowserActionApiTest() {} | 59 BrowserActionApiTest() {} |
36 virtual ~BrowserActionApiTest() {} | 60 virtual ~BrowserActionApiTest() {} |
37 | 61 |
38 protected: | 62 protected: |
39 BrowserActionTestUtil GetBrowserActionsBar() { | 63 BrowserActionTestUtil GetBrowserActionsBar() { |
40 return BrowserActionTestUtil(browser()); | 64 return BrowserActionTestUtil(browser()); |
41 } | 65 } |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
91 L" window.domAutomationController.send(true)}}, 100)", | 115 L" window.domAutomationController.send(true)}}, 100)", |
92 &result)); | 116 &result)); |
93 ASSERT_TRUE(result); | 117 ASSERT_TRUE(result); |
94 } | 118 } |
95 | 119 |
96 IN_PROC_BROWSER_TEST_F(BrowserActionApiTest, DynamicBrowserAction) { | 120 IN_PROC_BROWSER_TEST_F(BrowserActionApiTest, DynamicBrowserAction) { |
97 ASSERT_TRUE(RunExtensionTest("browser_action/no_icon")) << message_; | 121 ASSERT_TRUE(RunExtensionTest("browser_action/no_icon")) << message_; |
98 const Extension* extension = GetSingleLoadedExtension(); | 122 const Extension* extension = GetSingleLoadedExtension(); |
99 ASSERT_TRUE(extension) << message_; | 123 ASSERT_TRUE(extension) << message_; |
100 | 124 |
| 125 MockActionIconFactory mock_icon_factory; |
| 126 EXPECT_CALL(mock_icon_factory, GetIcon(_, _)).Times(0); |
| 127 |
101 // Test that there is a browser action in the toolbar. | 128 // Test that there is a browser action in the toolbar. |
102 ASSERT_EQ(1, GetBrowserActionsBar().NumberOfBrowserActions()); | 129 ASSERT_EQ(1, GetBrowserActionsBar().NumberOfBrowserActions()); |
103 EXPECT_TRUE(GetBrowserActionsBar().HasIcon(0)); | 130 EXPECT_TRUE(GetBrowserActionsBar().HasIcon(0)); |
104 | 131 |
105 // Set prev_id which holds the id of the previous image, and use it in the | 132 // 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. | 133 // next test to see if the image changes. |
107 uint32_t prev_id = extension->browser_action()->GetIcon(0). | 134 // The extension should not have default icon defined in its manifest |
108 ToSkBitmap()->getGenerationID(); | 135 // (default icon is loaded asynchronously, so it may change even without the |
| 136 // update step). |
| 137 uint32_t prev_id = extension->browser_action()-> |
| 138 GetIcon(0, &mock_icon_factory).ToSkBitmap()->getGenerationID(); |
109 | 139 |
110 // Tell the extension to update the icon using setIcon({imageData:...}). | 140 // Tell the extension to update the icon using setIcon({imageData:...}). |
111 ResultCatcher catcher; | 141 ResultCatcher catcher; |
112 ui_test_utils::NavigateToURL(browser(), | 142 ui_test_utils::NavigateToURL(browser(), |
113 GURL(extension->GetResourceURL("update.html"))); | 143 GURL(extension->GetResourceURL("update.html"))); |
114 ASSERT_TRUE(catcher.GetNextResult()); | 144 ASSERT_TRUE(catcher.GetNextResult()); |
115 | 145 |
116 // Test that we received the changes. | 146 // Test that we received the changes. |
117 EXPECT_TRUE(GetBrowserActionsBar().HasIcon(0)); | 147 EXPECT_TRUE(GetBrowserActionsBar().HasIcon(0)); |
118 EXPECT_NE(prev_id, | 148 EXPECT_NE(prev_id, |
119 extension->browser_action()->GetIcon(0). | 149 extension->browser_action()->GetIcon(0, &mock_icon_factory). |
120 ToSkBitmap()->getGenerationID()); | 150 ToSkBitmap()->getGenerationID()); |
121 prev_id = extension->browser_action()->GetIcon(0). | 151 prev_id = extension->browser_action()->GetIcon(0, &mock_icon_factory). |
122 ToSkBitmap()->getGenerationID(); | 152 ToSkBitmap()->getGenerationID(); |
123 | 153 |
124 // Tell the extension to update the icon using setIcon({path:...}). | 154 // Tell the extension to update the icon using setIcon({path:...}). |
125 ui_test_utils::NavigateToURL(browser(), | 155 ui_test_utils::NavigateToURL(browser(), |
126 GURL(extension->GetResourceURL("update2.html"))); | 156 GURL(extension->GetResourceURL("update2.html"))); |
127 ASSERT_TRUE(catcher.GetNextResult()); | 157 ASSERT_TRUE(catcher.GetNextResult()); |
128 EXPECT_TRUE(GetBrowserActionsBar().HasIcon(0)); | 158 EXPECT_TRUE(GetBrowserActionsBar().HasIcon(0)); |
129 EXPECT_NE(prev_id, | 159 EXPECT_NE(prev_id, |
130 extension->browser_action()->GetIcon(0). | 160 extension->browser_action()->GetIcon(0, &mock_icon_factory). |
131 ToSkBitmap()->getGenerationID()); | 161 ToSkBitmap()->getGenerationID()); |
132 } | 162 } |
133 | 163 |
134 // This test is flaky as per http://crbug.com/74557. | 164 // This test is flaky as per http://crbug.com/74557. |
135 IN_PROC_BROWSER_TEST_F(BrowserActionApiTest, | 165 IN_PROC_BROWSER_TEST_F(BrowserActionApiTest, |
136 DISABLED_TabSpecificBrowserActionState) { | 166 DISABLED_TabSpecificBrowserActionState) { |
137 ASSERT_TRUE(RunExtensionTest("browser_action/tab_specific_state")) << | 167 ASSERT_TRUE(RunExtensionTest("browser_action/tab_specific_state")) << |
138 message_; | 168 message_; |
139 const Extension* extension = GetSingleLoadedExtension(); | 169 const Extension* extension = GetSingleLoadedExtension(); |
140 ASSERT_TRUE(extension) << message_; | 170 ASSERT_TRUE(extension) << message_; |
(...skipping 329 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
470 ResultCatcher catcher; | 500 ResultCatcher catcher; |
471 ui_test_utils::NavigateToURL(browser(), | 501 ui_test_utils::NavigateToURL(browser(), |
472 GURL(extension->GetResourceURL("update.html"))); | 502 GURL(extension->GetResourceURL("update.html"))); |
473 ASSERT_TRUE(catcher.GetNextResult()); | 503 ASSERT_TRUE(catcher.GetNextResult()); |
474 | 504 |
475 // Test the getters for a specific tab. | 505 // Test the getters for a specific tab. |
476 ui_test_utils::NavigateToURL(browser(), | 506 ui_test_utils::NavigateToURL(browser(), |
477 GURL(extension->GetResourceURL("update2.html"))); | 507 GURL(extension->GetResourceURL("update2.html"))); |
478 ASSERT_TRUE(catcher.GetNextResult()); | 508 ASSERT_TRUE(catcher.GetNextResult()); |
479 } | 509 } |
OLD | NEW |