| 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/extension_apitest.h" | 5 #include "chrome/browser/extensions/extension_apitest.h" |
| 6 #include "chrome/browser/extensions/extension_browser_event_router.h" | 6 #include "chrome/browser/extensions/extension_browser_event_router.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_window.h" | 12 #include "chrome/browser/ui/browser_window.h" |
| 13 #include "chrome/browser/ui/omnibox/location_bar.h" | 13 #include "chrome/browser/ui/omnibox/location_bar.h" |
| 14 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" | 14 #include "chrome/browser/ui/tab_contents/tab_contents.h" |
| 15 #include "chrome/common/extensions/extension.h" | 15 #include "chrome/common/extensions/extension.h" |
| 16 #include "chrome/common/extensions/extension_action.h" | 16 #include "chrome/common/extensions/extension_action.h" |
| 17 #include "chrome/test/base/ui_test_utils.h" | 17 #include "chrome/test/base/ui_test_utils.h" |
| 18 #include "content/public/browser/web_contents.h" | 18 #include "content/public/browser/web_contents.h" |
| 19 | 19 |
| 20 using extensions::Extension; | 20 using extensions::Extension; |
| 21 | 21 |
| 22 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, PageAction) { | 22 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, PageAction) { |
| 23 ASSERT_TRUE(test_server()->Start()); | 23 ASSERT_TRUE(test_server()->Start()); |
| 24 ASSERT_TRUE(RunExtensionTest("page_action/basics")) << message_; | 24 ASSERT_TRUE(RunExtensionTest("page_action/basics")) << message_; |
| 25 const Extension* extension = GetSingleLoadedExtension(); | 25 const Extension* extension = GetSingleLoadedExtension(); |
| 26 ASSERT_TRUE(extension) << message_; | 26 ASSERT_TRUE(extension) << message_; |
| 27 { | 27 { |
| 28 // Tell the extension to update the page action state. | 28 // Tell the extension to update the page action state. |
| 29 ResultCatcher catcher; | 29 ResultCatcher catcher; |
| 30 ui_test_utils::NavigateToURL(browser(), | 30 ui_test_utils::NavigateToURL(browser(), |
| 31 GURL(extension->GetResourceURL("update.html"))); | 31 GURL(extension->GetResourceURL("update.html"))); |
| 32 ASSERT_TRUE(catcher.GetNextResult()); | 32 ASSERT_TRUE(catcher.GetNextResult()); |
| 33 } | 33 } |
| 34 | 34 |
| 35 // Test that we received the changes. | 35 // Test that we received the changes. |
| 36 int tab_id = browser()->GetSelectedTabContentsWrapper()-> | 36 int tab_id = browser()->GetActiveTabContents()-> |
| 37 restore_tab_helper()->session_id().id(); | 37 restore_tab_helper()->session_id().id(); |
| 38 ExtensionAction* action = extension->page_action(); | 38 ExtensionAction* action = extension->page_action(); |
| 39 ASSERT_TRUE(action); | 39 ASSERT_TRUE(action); |
| 40 EXPECT_EQ("Modified", action->GetTitle(tab_id)); | 40 EXPECT_EQ("Modified", action->GetTitle(tab_id)); |
| 41 | 41 |
| 42 { | 42 { |
| 43 // Simulate the page action being clicked. | 43 // Simulate the page action being clicked. |
| 44 ResultCatcher catcher; | 44 ResultCatcher catcher; |
| 45 int tab_id = | 45 int tab_id = |
| 46 ExtensionTabUtil::GetTabId(browser()->GetSelectedWebContents()); | 46 ExtensionTabUtil::GetTabId(browser()->GetActiveWebContents()); |
| 47 ExtensionService* service = browser()->profile()->GetExtensionService(); | 47 ExtensionService* service = browser()->profile()->GetExtensionService(); |
| 48 service->browser_event_router()->PageActionExecuted( | 48 service->browser_event_router()->PageActionExecuted( |
| 49 browser()->profile(), extension->id(), "", tab_id, "", 0); | 49 browser()->profile(), extension->id(), "", tab_id, "", 0); |
| 50 EXPECT_TRUE(catcher.GetNextResult()); | 50 EXPECT_TRUE(catcher.GetNextResult()); |
| 51 } | 51 } |
| 52 | 52 |
| 53 { | 53 { |
| 54 // Tell the extension to update the page action state again. | 54 // Tell the extension to update the page action state again. |
| 55 ResultCatcher catcher; | 55 ResultCatcher catcher; |
| 56 ui_test_utils::NavigateToURL(browser(), | 56 ui_test_utils::NavigateToURL(browser(), |
| 57 GURL(extension->GetResourceURL("update2.html"))); | 57 GURL(extension->GetResourceURL("update2.html"))); |
| 58 ASSERT_TRUE(catcher.GetNextResult()); | 58 ASSERT_TRUE(catcher.GetNextResult()); |
| 59 } | 59 } |
| 60 | 60 |
| 61 // Test that we received the changes. | 61 // Test that we received the changes. |
| 62 tab_id = browser()->GetSelectedTabContentsWrapper()->restore_tab_helper()-> | 62 tab_id = browser()->GetActiveTabContents()->restore_tab_helper()-> |
| 63 session_id().id(); | 63 session_id().id(); |
| 64 EXPECT_FALSE(action->GetIcon(tab_id).isNull()); | 64 EXPECT_FALSE(action->GetIcon(tab_id).isNull()); |
| 65 } | 65 } |
| 66 | 66 |
| 67 // Test that calling chrome.pageAction.setPopup() can enable a popup. | 67 // Test that calling chrome.pageAction.setPopup() can enable a popup. |
| 68 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, PageActionAddPopup) { | 68 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, PageActionAddPopup) { |
| 69 // Load the extension, which has no default popup. | 69 // Load the extension, which has no default popup. |
| 70 ASSERT_TRUE(RunExtensionTest("page_action/add_popup")) << message_; | 70 ASSERT_TRUE(RunExtensionTest("page_action/add_popup")) << message_; |
| 71 const Extension* extension = GetSingleLoadedExtension(); | 71 const Extension* extension = GetSingleLoadedExtension(); |
| 72 ASSERT_TRUE(extension) << message_; | 72 ASSERT_TRUE(extension) << message_; |
| 73 | 73 |
| 74 int tab_id = ExtensionTabUtil::GetTabId(browser()->GetSelectedWebContents()); | 74 int tab_id = ExtensionTabUtil::GetTabId(browser()->GetActiveWebContents()); |
| 75 | 75 |
| 76 ExtensionAction* page_action = extension->page_action(); | 76 ExtensionAction* page_action = extension->page_action(); |
| 77 ASSERT_TRUE(page_action) | 77 ASSERT_TRUE(page_action) |
| 78 << "Page action test extension should have a page action."; | 78 << "Page action test extension should have a page action."; |
| 79 | 79 |
| 80 ASSERT_FALSE(page_action->HasPopup(tab_id)); | 80 ASSERT_FALSE(page_action->HasPopup(tab_id)); |
| 81 | 81 |
| 82 // Simulate the page action being clicked. The resulting event should | 82 // Simulate the page action being clicked. The resulting event should |
| 83 // install a page action popup. | 83 // install a page action popup. |
| 84 { | 84 { |
| (...skipping 25 matching lines...) Expand all Loading... |
| 110 page_action->GetPopupUrl(tab_id).path().c_str()); | 110 page_action->GetPopupUrl(tab_id).path().c_str()); |
| 111 } | 111 } |
| 112 | 112 |
| 113 // Test that calling chrome.pageAction.setPopup() can remove a popup. | 113 // Test that calling chrome.pageAction.setPopup() can remove a popup. |
| 114 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, PageActionRemovePopup) { | 114 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, PageActionRemovePopup) { |
| 115 // Load the extension, which has a page action with a default popup. | 115 // Load the extension, which has a page action with a default popup. |
| 116 ASSERT_TRUE(RunExtensionTest("page_action/remove_popup")) << message_; | 116 ASSERT_TRUE(RunExtensionTest("page_action/remove_popup")) << message_; |
| 117 const Extension* extension = GetSingleLoadedExtension(); | 117 const Extension* extension = GetSingleLoadedExtension(); |
| 118 ASSERT_TRUE(extension) << message_; | 118 ASSERT_TRUE(extension) << message_; |
| 119 | 119 |
| 120 int tab_id = ExtensionTabUtil::GetTabId(browser()->GetSelectedWebContents()); | 120 int tab_id = ExtensionTabUtil::GetTabId(browser()->GetActiveWebContents()); |
| 121 | 121 |
| 122 ExtensionAction* page_action = extension->page_action(); | 122 ExtensionAction* page_action = extension->page_action(); |
| 123 ASSERT_TRUE(page_action) | 123 ASSERT_TRUE(page_action) |
| 124 << "Page action test extension should have a page action."; | 124 << "Page action test extension should have a page action."; |
| 125 | 125 |
| 126 ASSERT_TRUE(page_action->HasPopup(tab_id)) | 126 ASSERT_TRUE(page_action->HasPopup(tab_id)) |
| 127 << "Expect a page action popup before the test removes it."; | 127 << "Expect a page action popup before the test removes it."; |
| 128 | 128 |
| 129 // Load a page which removes the popup using chrome.pageAction.setPopup(). | 129 // Load a page which removes the popup using chrome.pageAction.setPopup(). |
| 130 { | 130 { |
| (...skipping 20 matching lines...) Expand all Loading... |
| 151 ResultCatcher catcher; | 151 ResultCatcher catcher; |
| 152 ui_test_utils::NavigateToURL(browser(), | 152 ui_test_utils::NavigateToURL(browser(), |
| 153 GURL(extension->GetResourceURL("page.html"))); | 153 GURL(extension->GetResourceURL("page.html"))); |
| 154 ASSERT_TRUE(catcher.GetNextResult()); | 154 ASSERT_TRUE(catcher.GetNextResult()); |
| 155 } | 155 } |
| 156 | 156 |
| 157 // Simulate the page action being clicked. | 157 // Simulate the page action being clicked. |
| 158 { | 158 { |
| 159 ResultCatcher catcher; | 159 ResultCatcher catcher; |
| 160 int tab_id = | 160 int tab_id = |
| 161 ExtensionTabUtil::GetTabId(browser()->GetSelectedWebContents()); | 161 ExtensionTabUtil::GetTabId(browser()->GetActiveWebContents()); |
| 162 ExtensionService* service = browser()->profile()->GetExtensionService(); | 162 ExtensionService* service = browser()->profile()->GetExtensionService(); |
| 163 service->browser_event_router()->PageActionExecuted( | 163 service->browser_event_router()->PageActionExecuted( |
| 164 browser()->profile(), extension->id(), "action", tab_id, "", 1); | 164 browser()->profile(), extension->id(), "action", tab_id, "", 1); |
| 165 EXPECT_TRUE(catcher.GetNextResult()); | 165 EXPECT_TRUE(catcher.GetNextResult()); |
| 166 } | 166 } |
| 167 } | 167 } |
| 168 | 168 |
| 169 // Tests popups in page actions. | 169 // Tests popups in page actions. |
| 170 // Flaky on the trybots. See http://crbug.com/96725. | 170 // Flaky on the trybots. See http://crbug.com/96725. |
| 171 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, DISABLED_ShowPageActionPopup) { | 171 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, DISABLED_ShowPageActionPopup) { |
| (...skipping 28 matching lines...) Expand all Loading... |
| 200 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, Getters) { | 200 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, Getters) { |
| 201 ASSERT_TRUE(RunExtensionTest("page_action/getters")) << message_; | 201 ASSERT_TRUE(RunExtensionTest("page_action/getters")) << message_; |
| 202 const Extension* extension = GetSingleLoadedExtension(); | 202 const Extension* extension = GetSingleLoadedExtension(); |
| 203 ASSERT_TRUE(extension) << message_; | 203 ASSERT_TRUE(extension) << message_; |
| 204 | 204 |
| 205 ResultCatcher catcher; | 205 ResultCatcher catcher; |
| 206 ui_test_utils::NavigateToURL(browser(), | 206 ui_test_utils::NavigateToURL(browser(), |
| 207 GURL(extension->GetResourceURL("update.html"))); | 207 GURL(extension->GetResourceURL("update.html"))); |
| 208 ASSERT_TRUE(catcher.GetNextResult()); | 208 ASSERT_TRUE(catcher.GetNextResult()); |
| 209 } | 209 } |
| OLD | NEW |