| 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 "base/command_line.h" | 5 #include "base/command_line.h" |
| 6 #include "chrome/browser/extensions/browser_action_test_util.h" | 6 #include "chrome/browser/extensions/browser_action_test_util.h" |
| 7 #include "chrome/browser/extensions/extension_apitest.h" | 7 #include "chrome/browser/extensions/extension_apitest.h" |
| 8 #include "chrome/browser/extensions/extension_browser_event_router.h" | 8 #include "chrome/browser/extensions/extension_browser_event_router.h" |
| 9 #include "chrome/browser/extensions/extension_prefs.h" | 9 #include "chrome/browser/extensions/extension_prefs.h" |
| 10 #include "chrome/browser/extensions/extension_service.h" | 10 #include "chrome/browser/extensions/extension_service.h" |
| 11 #include "chrome/browser/extensions/extension_tab_util.h" | 11 #include "chrome/browser/extensions/extension_tab_util.h" |
| 12 #include "chrome/browser/profiles/profile.h" | 12 #include "chrome/browser/profiles/profile.h" |
| 13 #include "chrome/browser/sessions/restore_tab_helper.h" | 13 #include "chrome/browser/sessions/restore_tab_helper.h" |
| 14 #include "chrome/browser/ui/browser.h" | 14 #include "chrome/browser/ui/browser.h" |
| 15 #include "chrome/browser/ui/browser_window.h" | 15 #include "chrome/browser/ui/browser_window.h" |
| 16 #include "chrome/browser/ui/omnibox/location_bar.h" | 16 #include "chrome/browser/ui/omnibox/location_bar.h" |
| 17 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" | 17 #include "chrome/browser/ui/tab_contents/tab_contents.h" |
| 18 #include "chrome/common/chrome_switches.h" | 18 #include "chrome/common/chrome_switches.h" |
| 19 #include "chrome/common/extensions/extension.h" | 19 #include "chrome/common/extensions/extension.h" |
| 20 #include "chrome/common/extensions/extension_action.h" | 20 #include "chrome/common/extensions/extension_action.h" |
| 21 #include "chrome/test/base/ui_test_utils.h" | 21 #include "chrome/test/base/ui_test_utils.h" |
| 22 #include "content/public/browser/web_contents.h" | 22 #include "content/public/browser/web_contents.h" |
| 23 | 23 |
| 24 // These are a mash-up of the tests from from page_actions_apitest.cc and | 24 // These are a mash-up of the tests from from page_actions_apitest.cc and |
| 25 // browser_actions_apitest.cc. | 25 // browser_actions_apitest.cc. |
| 26 | 26 |
| 27 using extensions::Extension; | 27 using extensions::Extension; |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 65 | 65 |
| 66 { | 66 { |
| 67 // Tell the extension to update the page action state. | 67 // Tell the extension to update the page action state. |
| 68 ResultCatcher catcher; | 68 ResultCatcher catcher; |
| 69 ui_test_utils::NavigateToURL(browser(), | 69 ui_test_utils::NavigateToURL(browser(), |
| 70 GURL(extension->GetResourceURL("update.html"))); | 70 GURL(extension->GetResourceURL("update.html"))); |
| 71 ASSERT_TRUE(catcher.GetNextResult()); | 71 ASSERT_TRUE(catcher.GetNextResult()); |
| 72 } | 72 } |
| 73 | 73 |
| 74 // Test that we received the changes. | 74 // Test that we received the changes. |
| 75 int tab_id = ExtensionTabUtil::GetTabId(browser()->GetSelectedWebContents()); | 75 int tab_id = ExtensionTabUtil::GetTabId(browser()->GetActiveWebContents()); |
| 76 ExtensionAction* action = extension->browser_action(); | 76 ExtensionAction* action = extension->browser_action(); |
| 77 ASSERT_TRUE(action); | 77 ASSERT_TRUE(action); |
| 78 EXPECT_EQ("Modified", action->GetTitle(tab_id)); | 78 EXPECT_EQ("Modified", action->GetTitle(tab_id)); |
| 79 | 79 |
| 80 { | 80 { |
| 81 // Simulate the page action being clicked. | 81 // Simulate the page action being clicked. |
| 82 ResultCatcher catcher; | 82 ResultCatcher catcher; |
| 83 ExtensionService* service = browser()->profile()->GetExtensionService(); | 83 ExtensionService* service = browser()->profile()->GetExtensionService(); |
| 84 service->toolbar_model()->ExecuteBrowserAction(extension, browser(), NULL); | 84 service->toolbar_model()->ExecuteBrowserAction(extension, browser(), NULL); |
| 85 EXPECT_TRUE(catcher.GetNextResult()); | 85 EXPECT_TRUE(catcher.GetNextResult()); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 97 EXPECT_FALSE(action->GetIcon(tab_id).isNull()); | 97 EXPECT_FALSE(action->GetIcon(tab_id).isNull()); |
| 98 } | 98 } |
| 99 | 99 |
| 100 // Test that calling chrome.pageAction.setPopup() can enable a popup. | 100 // Test that calling chrome.pageAction.setPopup() can enable a popup. |
| 101 IN_PROC_BROWSER_TEST_F(PageAsBrowserActionApiTest, AddPopup) { | 101 IN_PROC_BROWSER_TEST_F(PageAsBrowserActionApiTest, AddPopup) { |
| 102 // Load the extension, which has no default popup. | 102 // Load the extension, which has no default popup. |
| 103 ASSERT_TRUE(RunExtensionTest("page_action/add_popup")) << message_; | 103 ASSERT_TRUE(RunExtensionTest("page_action/add_popup")) << message_; |
| 104 const Extension* extension = GetSingleLoadedExtension(); | 104 const Extension* extension = GetSingleLoadedExtension(); |
| 105 ASSERT_TRUE(extension) << message_; | 105 ASSERT_TRUE(extension) << message_; |
| 106 | 106 |
| 107 int tab_id = ExtensionTabUtil::GetTabId(browser()->GetSelectedWebContents()); | 107 int tab_id = ExtensionTabUtil::GetTabId(browser()->GetActiveWebContents()); |
| 108 | 108 |
| 109 ExtensionAction* page_action = extension->browser_action(); | 109 ExtensionAction* page_action = extension->browser_action(); |
| 110 ASSERT_TRUE(page_action) | 110 ASSERT_TRUE(page_action) |
| 111 << "Page action test extension should have a page action."; | 111 << "Page action test extension should have a page action."; |
| 112 | 112 |
| 113 ASSERT_FALSE(page_action->HasPopup(tab_id)); | 113 ASSERT_FALSE(page_action->HasPopup(tab_id)); |
| 114 | 114 |
| 115 // Simulate the page action being clicked. The resulting event should | 115 // Simulate the page action being clicked. The resulting event should |
| 116 // install a page action popup. | 116 // install a page action popup. |
| 117 { | 117 { |
| (...skipping 24 matching lines...) Expand all Loading... |
| 142 page_action->GetPopupUrl(tab_id).path().c_str()); | 142 page_action->GetPopupUrl(tab_id).path().c_str()); |
| 143 } | 143 } |
| 144 | 144 |
| 145 // Test that calling chrome.pageAction.setPopup() can remove a popup. | 145 // Test that calling chrome.pageAction.setPopup() can remove a popup. |
| 146 IN_PROC_BROWSER_TEST_F(PageAsBrowserActionApiTest, RemovePopup) { | 146 IN_PROC_BROWSER_TEST_F(PageAsBrowserActionApiTest, RemovePopup) { |
| 147 // Load the extension, which has a page action with a default popup. | 147 // Load the extension, which has a page action with a default popup. |
| 148 ASSERT_TRUE(RunExtensionTest("page_action/remove_popup")) << message_; | 148 ASSERT_TRUE(RunExtensionTest("page_action/remove_popup")) << message_; |
| 149 const Extension* extension = GetSingleLoadedExtension(); | 149 const Extension* extension = GetSingleLoadedExtension(); |
| 150 ASSERT_TRUE(extension) << message_; | 150 ASSERT_TRUE(extension) << message_; |
| 151 | 151 |
| 152 int tab_id = ExtensionTabUtil::GetTabId(browser()->GetSelectedWebContents()); | 152 int tab_id = ExtensionTabUtil::GetTabId(browser()->GetActiveWebContents()); |
| 153 | 153 |
| 154 ExtensionAction* page_action = extension->browser_action(); | 154 ExtensionAction* page_action = extension->browser_action(); |
| 155 ASSERT_TRUE(page_action) | 155 ASSERT_TRUE(page_action) |
| 156 << "Page action test extension should have a page action."; | 156 << "Page action test extension should have a page action."; |
| 157 | 157 |
| 158 ASSERT_TRUE(page_action->HasPopup(tab_id)) | 158 ASSERT_TRUE(page_action->HasPopup(tab_id)) |
| 159 << "Expect a page action popup before the test removes it."; | 159 << "Expect a page action popup before the test removes it."; |
| 160 | 160 |
| 161 // Load a page which removes the popup using chrome.pageAction.setPopup(). | 161 // Load a page which removes the popup using chrome.pageAction.setPopup(). |
| 162 { | 162 { |
| (...skipping 13 matching lines...) Expand all Loading... |
| 176 const Extension* extension = GetSingleLoadedExtension(); | 176 const Extension* extension = GetSingleLoadedExtension(); |
| 177 ASSERT_TRUE(extension) << message_; | 177 ASSERT_TRUE(extension) << message_; |
| 178 | 178 |
| 179 ResultCatcher catcher; | 179 ResultCatcher catcher; |
| 180 ui_test_utils::NavigateToURL(browser(), | 180 ui_test_utils::NavigateToURL(browser(), |
| 181 GURL(extension->GetResourceURL("update.html"))); | 181 GURL(extension->GetResourceURL("update.html"))); |
| 182 ASSERT_TRUE(catcher.GetNextResult()); | 182 ASSERT_TRUE(catcher.GetNextResult()); |
| 183 } | 183 } |
| 184 | 184 |
| 185 } | 185 } |
| OLD | NEW |