| 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_action.h" | 6 #include "chrome/browser/extensions/extension_action.h" |
| 7 #include "chrome/browser/extensions/extension_action_icon_factory.h" | 7 #include "chrome/browser/extensions/extension_action_icon_factory.h" |
| 8 #include "chrome/browser/extensions/extension_action_manager.h" | 8 #include "chrome/browser/extensions/extension_action_manager.h" |
| 9 #include "chrome/browser/extensions/extension_apitest.h" | 9 #include "chrome/browser/extensions/extension_apitest.h" |
| 10 #include "chrome/browser/extensions/extension_service.h" | 10 #include "chrome/browser/extensions/extension_service.h" |
| 11 #include "chrome/browser/extensions/extension_system.h" |
| 11 #include "chrome/browser/extensions/extension_tab_util.h" | 12 #include "chrome/browser/extensions/extension_tab_util.h" |
| 12 #include "chrome/browser/profiles/profile.h" | 13 #include "chrome/browser/profiles/profile.h" |
| 13 #include "chrome/browser/sessions/session_tab_helper.h" | 14 #include "chrome/browser/sessions/session_tab_helper.h" |
| 14 #include "chrome/browser/ui/browser.h" | 15 #include "chrome/browser/ui/browser.h" |
| 15 #include "chrome/browser/ui/browser_tabstrip.h" | 16 #include "chrome/browser/ui/browser_tabstrip.h" |
| 16 #include "chrome/browser/ui/browser_window.h" | 17 #include "chrome/browser/ui/browser_window.h" |
| 17 #include "chrome/browser/ui/omnibox/location_bar.h" | 18 #include "chrome/browser/ui/omnibox/location_bar.h" |
| 18 #include "chrome/browser/ui/tab_contents/tab_contents.h" | 19 #include "chrome/browser/ui/tab_contents/tab_contents.h" |
| 19 #include "chrome/common/extensions/extension.h" | 20 #include "chrome/common/extensions/extension.h" |
| 20 #include "chrome/test/base/ui_test_utils.h" | 21 #include "chrome/test/base/ui_test_utils.h" |
| (...skipping 28 matching lines...) Expand all Loading... |
| 49 chrome::GetActiveWebContents(browser()))->session_id().id(); | 50 chrome::GetActiveWebContents(browser()))->session_id().id(); |
| 50 ExtensionAction* action = GetPageAction(*extension); | 51 ExtensionAction* action = GetPageAction(*extension); |
| 51 ASSERT_TRUE(action); | 52 ASSERT_TRUE(action); |
| 52 EXPECT_EQ("Modified", action->GetTitle(tab_id)); | 53 EXPECT_EQ("Modified", action->GetTitle(tab_id)); |
| 53 | 54 |
| 54 { | 55 { |
| 55 // Simulate the page action being clicked. | 56 // Simulate the page action being clicked. |
| 56 ResultCatcher catcher; | 57 ResultCatcher catcher; |
| 57 int tab_id = | 58 int tab_id = |
| 58 ExtensionTabUtil::GetTabId(chrome::GetActiveWebContents(browser())); | 59 ExtensionTabUtil::GetTabId(chrome::GetActiveWebContents(browser())); |
| 59 ExtensionService* service = browser()->profile()->GetExtensionService(); | 60 ExtensionService* service = extensions::ExtensionSystem::Get( |
| 61 browser()->profile())->extension_service(); |
| 60 service->browser_event_router()->PageActionExecuted( | 62 service->browser_event_router()->PageActionExecuted( |
| 61 browser()->profile(), *action, tab_id, "", 0); | 63 browser()->profile(), *action, tab_id, "", 0); |
| 62 EXPECT_TRUE(catcher.GetNextResult()); | 64 EXPECT_TRUE(catcher.GetNextResult()); |
| 63 } | 65 } |
| 64 | 66 |
| 65 { | 67 { |
| 66 // Tell the extension to update the page action state again. | 68 // Tell the extension to update the page action state again. |
| 67 ResultCatcher catcher; | 69 ResultCatcher catcher; |
| 68 ui_test_utils::NavigateToURL(browser(), | 70 ui_test_utils::NavigateToURL(browser(), |
| 69 GURL(extension->GetResourceURL("update2.html"))); | 71 GURL(extension->GetResourceURL("update2.html"))); |
| (...skipping 23 matching lines...) Expand all Loading... |
| 93 ExtensionAction* page_action = GetPageAction(*extension); | 95 ExtensionAction* page_action = GetPageAction(*extension); |
| 94 ASSERT_TRUE(page_action) | 96 ASSERT_TRUE(page_action) |
| 95 << "Page action test extension should have a page action."; | 97 << "Page action test extension should have a page action."; |
| 96 | 98 |
| 97 ASSERT_FALSE(page_action->HasPopup(tab_id)); | 99 ASSERT_FALSE(page_action->HasPopup(tab_id)); |
| 98 | 100 |
| 99 // Simulate the page action being clicked. The resulting event should | 101 // Simulate the page action being clicked. The resulting event should |
| 100 // install a page action popup. | 102 // install a page action popup. |
| 101 { | 103 { |
| 102 ResultCatcher catcher; | 104 ResultCatcher catcher; |
| 103 ExtensionService* service = browser()->profile()->GetExtensionService(); | 105 ExtensionService* service = extensions::ExtensionSystem::Get( |
| 106 browser()->profile())->extension_service(); |
| 104 service->browser_event_router()->PageActionExecuted( | 107 service->browser_event_router()->PageActionExecuted( |
| 105 browser()->profile(), *page_action, tab_id, "", 1); | 108 browser()->profile(), *page_action, tab_id, "", 1); |
| 106 ASSERT_TRUE(catcher.GetNextResult()); | 109 ASSERT_TRUE(catcher.GetNextResult()); |
| 107 } | 110 } |
| 108 | 111 |
| 109 ASSERT_TRUE(page_action->HasPopup(tab_id)) | 112 ASSERT_TRUE(page_action->HasPopup(tab_id)) |
| 110 << "Clicking on the page action should have caused a popup to be added."; | 113 << "Clicking on the page action should have caused a popup to be added."; |
| 111 | 114 |
| 112 ASSERT_STREQ("/a_popup.html", | 115 ASSERT_STREQ("/a_popup.html", |
| 113 page_action->GetPopupUrl(tab_id).path().c_str()); | 116 page_action->GetPopupUrl(tab_id).path().c_str()); |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 171 ui_test_utils::NavigateToURL(browser(), | 174 ui_test_utils::NavigateToURL(browser(), |
| 172 GURL(extension->GetResourceURL("page.html"))); | 175 GURL(extension->GetResourceURL("page.html"))); |
| 173 ASSERT_TRUE(catcher.GetNextResult()); | 176 ASSERT_TRUE(catcher.GetNextResult()); |
| 174 } | 177 } |
| 175 | 178 |
| 176 // Simulate the page action being clicked. | 179 // Simulate the page action being clicked. |
| 177 { | 180 { |
| 178 ResultCatcher catcher; | 181 ResultCatcher catcher; |
| 179 int tab_id = | 182 int tab_id = |
| 180 ExtensionTabUtil::GetTabId(chrome::GetActiveWebContents(browser())); | 183 ExtensionTabUtil::GetTabId(chrome::GetActiveWebContents(browser())); |
| 181 ExtensionService* service = browser()->profile()->GetExtensionService(); | 184 ExtensionService* service = extensions::ExtensionSystem::Get( |
| 185 browser()->profile())->extension_service(); |
| 182 ExtensionAction* page_action = GetPageAction(*extension); | 186 ExtensionAction* page_action = GetPageAction(*extension); |
| 183 service->browser_event_router()->PageActionExecuted( | 187 service->browser_event_router()->PageActionExecuted( |
| 184 browser()->profile(), *page_action, tab_id, "", 1); | 188 browser()->profile(), *page_action, tab_id, "", 1); |
| 185 EXPECT_TRUE(catcher.GetNextResult()); | 189 EXPECT_TRUE(catcher.GetNextResult()); |
| 186 } | 190 } |
| 187 } | 191 } |
| 188 | 192 |
| 189 // Tests popups in page actions. | 193 // Tests popups in page actions. |
| 190 // Flaky on the trybots. See http://crbug.com/96725. | 194 // Flaky on the trybots. See http://crbug.com/96725. |
| 191 IN_PROC_BROWSER_TEST_F(PageActionApiTest, DISABLED_ShowPageActionPopup) { | 195 IN_PROC_BROWSER_TEST_F(PageActionApiTest, DISABLED_ShowPageActionPopup) { |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 223 ASSERT_TRUE(extension) << message_; | 227 ASSERT_TRUE(extension) << message_; |
| 224 | 228 |
| 225 ResultCatcher catcher; | 229 ResultCatcher catcher; |
| 226 ui_test_utils::NavigateToURL(browser(), | 230 ui_test_utils::NavigateToURL(browser(), |
| 227 GURL(extension->GetResourceURL("update.html"))); | 231 GURL(extension->GetResourceURL("update.html"))); |
| 228 ASSERT_TRUE(catcher.GetNextResult()); | 232 ASSERT_TRUE(catcher.GetNextResult()); |
| 229 } | 233 } |
| 230 | 234 |
| 231 } // namespace | 235 } // namespace |
| 232 } // namespace extensions | 236 } // namespace extensions |
| OLD | NEW |