| 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 "chrome/browser/extensions/browser_event_router.h" | 5 #include "chrome/browser/extensions/browser_event_router.h" |
| 6 #include "chrome/browser/extensions/extension_apitest.h" | 6 #include "chrome/browser/extensions/extension_apitest.h" |
| 7 #include "chrome/browser/extensions/extension_service.h" | 7 #include "chrome/browser/extensions/extension_service.h" |
| 8 #include "chrome/browser/extensions/extension_tab_util.h" | 8 #include "chrome/browser/extensions/extension_tab_util.h" |
| 9 #include "chrome/browser/profiles/profile.h" | 9 #include "chrome/browser/profiles/profile.h" |
| 10 #include "chrome/browser/sessions/restore_tab_helper.h" | 10 #include "chrome/browser/sessions/restore_tab_helper.h" |
| 11 #include "chrome/browser/ui/browser.h" | 11 #include "chrome/browser/ui/browser.h" |
| 12 #include "chrome/browser/ui/browser_tabstrip.h" | 12 #include "chrome/browser/ui/browser_tabstrip.h" |
| 13 #include "chrome/browser/ui/browser_window.h" | 13 #include "chrome/browser/ui/browser_window.h" |
| 14 #include "chrome/browser/ui/omnibox/location_bar.h" | 14 #include "chrome/browser/ui/omnibox/location_bar.h" |
| 15 #include "chrome/browser/ui/tab_contents/tab_contents.h" | 15 #include "chrome/browser/ui/tab_contents/tab_contents.h" |
| 16 #include "chrome/common/extensions/extension.h" | 16 #include "chrome/common/extensions/extension.h" |
| 17 #include "chrome/common/extensions/extension_action.h" | 17 #include "chrome/common/extensions/extension_action.h" |
| 18 #include "chrome/test/base/ui_test_utils.h" | 18 #include "chrome/test/base/ui_test_utils.h" |
| 19 #include "content/public/browser/web_contents.h" | 19 #include "content/public/browser/web_contents.h" |
| 20 #include "ui/gfx/image/image_skia.h" |
| 20 | 21 |
| 21 using extensions::Extension; | 22 using extensions::Extension; |
| 22 | 23 |
| 24 namespace { |
| 25 |
| 26 gfx::Image CreateNonEmptyImage() { |
| 27 SkBitmap bitmap; |
| 28 bitmap.setConfig(SkBitmap::kARGB_8888_Config, 16, 16); |
| 29 bitmap.allocPixels(); |
| 30 return gfx::Image(bitmap); |
| 31 } |
| 32 |
| 33 } // namespace |
| 34 |
| 23 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, PageAction) { | 35 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, PageAction) { |
| 24 ASSERT_TRUE(test_server()->Start()); | 36 ASSERT_TRUE(test_server()->Start()); |
| 25 ASSERT_TRUE(RunExtensionTest("page_action/basics")) << message_; | 37 ASSERT_TRUE(RunExtensionTest("page_action/basics")) << message_; |
| 26 const Extension* extension = GetSingleLoadedExtension(); | 38 const Extension* extension = GetSingleLoadedExtension(); |
| 27 ASSERT_TRUE(extension) << message_; | 39 ASSERT_TRUE(extension) << message_; |
| 28 { | 40 { |
| 29 // Tell the extension to update the page action state. | 41 // Tell the extension to update the page action state. |
| 30 ResultCatcher catcher; | 42 ResultCatcher catcher; |
| 31 ui_test_utils::NavigateToURL(browser(), | 43 ui_test_utils::NavigateToURL(browser(), |
| 32 GURL(extension->GetResourceURL("update.html"))); | 44 GURL(extension->GetResourceURL("update.html"))); |
| (...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 161 // Simulate the page action being clicked. | 173 // Simulate the page action being clicked. |
| 162 { | 174 { |
| 163 ResultCatcher catcher; | 175 ResultCatcher catcher; |
| 164 int tab_id = | 176 int tab_id = |
| 165 ExtensionTabUtil::GetTabId(chrome::GetActiveWebContents(browser())); | 177 ExtensionTabUtil::GetTabId(chrome::GetActiveWebContents(browser())); |
| 166 ExtensionService* service = browser()->profile()->GetExtensionService(); | 178 ExtensionService* service = browser()->profile()->GetExtensionService(); |
| 167 service->browser_event_router()->PageActionExecuted( | 179 service->browser_event_router()->PageActionExecuted( |
| 168 browser()->profile(), *extension->page_action(), tab_id, "", 1); | 180 browser()->profile(), *extension->page_action(), tab_id, "", 1); |
| 169 EXPECT_TRUE(catcher.GetNextResult()); | 181 EXPECT_TRUE(catcher.GetNextResult()); |
| 170 } | 182 } |
| 183 |
| 184 // Set icon by its index. |
| 185 { |
| 186 int tab_id = |
| 187 ExtensionTabUtil::GetTabId(chrome::GetActiveWebContents(browser())); |
| 188 |
| 189 // Set some icon so we can verify it gets cleaned up by setIconIndex. |
| 190 extension->page_action()->SetIcon(tab_id, CreateNonEmptyImage()); |
| 191 ASSERT_FALSE( |
| 192 extension->page_action()->GetExplicitlySetIcon(tab_id).empty()); |
| 193 |
| 194 // Currently, icon index should be set to 0. |
| 195 ASSERT_EQ(0, extension->page_action()->GetIconIndex(tab_id)); |
| 196 |
| 197 ResultCatcher catcher; |
| 198 ui_test_utils::NavigateToURL(browser(), |
| 199 GURL(extension->GetResourceURL("set_icon_index.html"))); |
| 200 ASSERT_TRUE(catcher.GetNextResult()); |
| 201 |
| 202 // Check new value of icon index is as expected. |
| 203 EXPECT_EQ(1, extension->page_action()->GetIconIndex(tab_id)); |
| 204 // Explicitly set icon should have been reset. |
| 205 ASSERT_TRUE( |
| 206 extension->page_action()->GetExplicitlySetIcon(tab_id).empty()); |
| 207 } |
| 171 } | 208 } |
| 172 | 209 |
| 173 // Tests popups in page actions. | 210 // Tests popups in page actions. |
| 174 // Flaky on the trybots. See http://crbug.com/96725. | 211 // Flaky on the trybots. See http://crbug.com/96725. |
| 175 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, DISABLED_ShowPageActionPopup) { | 212 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, DISABLED_ShowPageActionPopup) { |
| 176 ASSERT_TRUE(RunExtensionTest("page_action/popup")) << message_; | 213 ASSERT_TRUE(RunExtensionTest("page_action/popup")) << message_; |
| 177 const Extension* extension = GetSingleLoadedExtension(); | 214 const Extension* extension = GetSingleLoadedExtension(); |
| 178 ASSERT_TRUE(extension) << message_; | 215 ASSERT_TRUE(extension) << message_; |
| 179 | 216 |
| 180 ASSERT_TRUE(WaitForPageActionVisibilityChangeTo(1)); | 217 ASSERT_TRUE(WaitForPageActionVisibilityChangeTo(1)); |
| (...skipping 23 matching lines...) Expand all Loading... |
| 204 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, Getters) { | 241 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, Getters) { |
| 205 ASSERT_TRUE(RunExtensionTest("page_action/getters")) << message_; | 242 ASSERT_TRUE(RunExtensionTest("page_action/getters")) << message_; |
| 206 const Extension* extension = GetSingleLoadedExtension(); | 243 const Extension* extension = GetSingleLoadedExtension(); |
| 207 ASSERT_TRUE(extension) << message_; | 244 ASSERT_TRUE(extension) << message_; |
| 208 | 245 |
| 209 ResultCatcher catcher; | 246 ResultCatcher catcher; |
| 210 ui_test_utils::NavigateToURL(browser(), | 247 ui_test_utils::NavigateToURL(browser(), |
| 211 GURL(extension->GetResourceURL("update.html"))); | 248 GURL(extension->GetResourceURL("update.html"))); |
| 212 ASSERT_TRUE(catcher.GetNextResult()); | 249 ASSERT_TRUE(catcher.GetNextResult()); |
| 213 } | 250 } |
| OLD | NEW |