| 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/session_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 | 20 |
| 21 using extensions::Extension; | 21 using extensions::Extension; |
| 22 | 22 |
| 23 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, PageAction) { | 23 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, PageAction) { |
| 24 ASSERT_TRUE(test_server()->Start()); | 24 ASSERT_TRUE(test_server()->Start()); |
| 25 ASSERT_TRUE(RunExtensionTest("page_action/basics")) << message_; | 25 ASSERT_TRUE(RunExtensionTest("page_action/basics")) << message_; |
| 26 const Extension* extension = GetSingleLoadedExtension(); | 26 const Extension* extension = GetSingleLoadedExtension(); |
| 27 ASSERT_TRUE(extension) << message_; | 27 ASSERT_TRUE(extension) << message_; |
| 28 { | 28 { |
| 29 // Tell the extension to update the page action state. | 29 // Tell the extension to update the page action state. |
| 30 ResultCatcher catcher; | 30 ResultCatcher catcher; |
| 31 ui_test_utils::NavigateToURL(browser(), | 31 ui_test_utils::NavigateToURL(browser(), |
| 32 GURL(extension->GetResourceURL("update.html"))); | 32 GURL(extension->GetResourceURL("update.html"))); |
| 33 ASSERT_TRUE(catcher.GetNextResult()); | 33 ASSERT_TRUE(catcher.GetNextResult()); |
| 34 } | 34 } |
| 35 | 35 |
| 36 // Test that we received the changes. | 36 // Test that we received the changes. |
| 37 int tab_id = chrome::GetActiveTabContents(browser())->restore_tab_helper()-> | 37 int tab_id = chrome::GetActiveTabContents(browser())->session_tab_helper()-> |
| 38 session_id().id(); | 38 session_id().id(); |
| 39 ExtensionAction* action = extension->page_action(); | 39 ExtensionAction* action = extension->page_action(); |
| 40 ASSERT_TRUE(action); | 40 ASSERT_TRUE(action); |
| 41 EXPECT_EQ("Modified", action->GetTitle(tab_id)); | 41 EXPECT_EQ("Modified", action->GetTitle(tab_id)); |
| 42 | 42 |
| 43 { | 43 { |
| 44 // Simulate the page action being clicked. | 44 // Simulate the page action being clicked. |
| 45 ResultCatcher catcher; | 45 ResultCatcher catcher; |
| 46 int tab_id = | 46 int tab_id = |
| 47 ExtensionTabUtil::GetTabId(chrome::GetActiveWebContents(browser())); | 47 ExtensionTabUtil::GetTabId(chrome::GetActiveWebContents(browser())); |
| 48 ExtensionService* service = browser()->profile()->GetExtensionService(); | 48 ExtensionService* service = browser()->profile()->GetExtensionService(); |
| 49 service->browser_event_router()->PageActionExecuted( | 49 service->browser_event_router()->PageActionExecuted( |
| 50 browser()->profile(), *action, tab_id, "", 0); | 50 browser()->profile(), *action, tab_id, "", 0); |
| 51 EXPECT_TRUE(catcher.GetNextResult()); | 51 EXPECT_TRUE(catcher.GetNextResult()); |
| 52 } | 52 } |
| 53 | 53 |
| 54 { | 54 { |
| 55 // Tell the extension to update the page action state again. | 55 // Tell the extension to update the page action state again. |
| 56 ResultCatcher catcher; | 56 ResultCatcher catcher; |
| 57 ui_test_utils::NavigateToURL(browser(), | 57 ui_test_utils::NavigateToURL(browser(), |
| 58 GURL(extension->GetResourceURL("update2.html"))); | 58 GURL(extension->GetResourceURL("update2.html"))); |
| 59 ASSERT_TRUE(catcher.GetNextResult()); | 59 ASSERT_TRUE(catcher.GetNextResult()); |
| 60 } | 60 } |
| 61 | 61 |
| 62 // Test that we received the changes. | 62 // Test that we received the changes. |
| 63 tab_id = chrome::GetActiveTabContents(browser())->restore_tab_helper()-> | 63 tab_id = chrome::GetActiveTabContents(browser())->session_tab_helper()-> |
| 64 session_id().id(); | 64 session_id().id(); |
| 65 EXPECT_FALSE(action->GetIcon(tab_id).IsEmpty()); | 65 EXPECT_FALSE(action->GetIcon(tab_id).IsEmpty()); |
| 66 } | 66 } |
| 67 | 67 |
| 68 // Test that calling chrome.pageAction.setPopup() can enable a popup. | 68 // Test that calling chrome.pageAction.setPopup() can enable a popup. |
| 69 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, PageActionAddPopup) { | 69 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, PageActionAddPopup) { |
| 70 // Load the extension, which has no default popup. | 70 // Load the extension, which has no default popup. |
| 71 ASSERT_TRUE(RunExtensionTest("page_action/add_popup")) << message_; | 71 ASSERT_TRUE(RunExtensionTest("page_action/add_popup")) << message_; |
| 72 const Extension* extension = GetSingleLoadedExtension(); | 72 const Extension* extension = GetSingleLoadedExtension(); |
| 73 ASSERT_TRUE(extension) << message_; | 73 ASSERT_TRUE(extension) << message_; |
| (...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 204 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, Getters) { | 204 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, Getters) { |
| 205 ASSERT_TRUE(RunExtensionTest("page_action/getters")) << message_; | 205 ASSERT_TRUE(RunExtensionTest("page_action/getters")) << message_; |
| 206 const Extension* extension = GetSingleLoadedExtension(); | 206 const Extension* extension = GetSingleLoadedExtension(); |
| 207 ASSERT_TRUE(extension) << message_; | 207 ASSERT_TRUE(extension) << message_; |
| 208 | 208 |
| 209 ResultCatcher catcher; | 209 ResultCatcher catcher; |
| 210 ui_test_utils::NavigateToURL(browser(), | 210 ui_test_utils::NavigateToURL(browser(), |
| 211 GURL(extension->GetResourceURL("update.html"))); | 211 GURL(extension->GetResourceURL("update.html"))); |
| 212 ASSERT_TRUE(catcher.GetNextResult()); | 212 ASSERT_TRUE(catcher.GetNextResult()); |
| 213 } | 213 } |
| OLD | NEW |