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/api/extension_action/extension_action_api.h" | 5 #include "chrome/browser/extensions/api/extension_action/extension_action_api.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_action_runner.h" |
9 #include "chrome/browser/extensions/extension_action_test_util.h" | 10 #include "chrome/browser/extensions/extension_action_test_util.h" |
10 #include "chrome/browser/extensions/extension_apitest.h" | 11 #include "chrome/browser/extensions/extension_apitest.h" |
11 #include "chrome/browser/extensions/extension_service.h" | 12 #include "chrome/browser/extensions/extension_service.h" |
12 #include "chrome/browser/extensions/extension_tab_util.h" | 13 #include "chrome/browser/extensions/extension_tab_util.h" |
13 #include "chrome/browser/profiles/profile.h" | 14 #include "chrome/browser/profiles/profile.h" |
14 #include "chrome/browser/sessions/session_tab_helper.h" | 15 #include "chrome/browser/sessions/session_tab_helper.h" |
15 #include "chrome/browser/ui/browser.h" | 16 #include "chrome/browser/ui/browser.h" |
16 #include "chrome/browser/ui/browser_commands.h" | 17 #include "chrome/browser/ui/browser_commands.h" |
17 #include "chrome/browser/ui/browser_window.h" | 18 #include "chrome/browser/ui/browser_window.h" |
18 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 19 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
53 // Test that we received the changes. | 54 // Test that we received the changes. |
54 int tab_id = SessionTabHelper::FromWebContents( | 55 int tab_id = SessionTabHelper::FromWebContents( |
55 browser()->tab_strip_model()->GetActiveWebContents())->session_id().id(); | 56 browser()->tab_strip_model()->GetActiveWebContents())->session_id().id(); |
56 ExtensionAction* action = GetPageAction(*extension); | 57 ExtensionAction* action = GetPageAction(*extension); |
57 ASSERT_TRUE(action); | 58 ASSERT_TRUE(action); |
58 EXPECT_EQ("Modified", action->GetTitle(tab_id)); | 59 EXPECT_EQ("Modified", action->GetTitle(tab_id)); |
59 | 60 |
60 { | 61 { |
61 // Simulate the page action being clicked. | 62 // Simulate the page action being clicked. |
62 ResultCatcher catcher; | 63 ResultCatcher catcher; |
63 ExtensionActionAPI::Get(browser()->profile())->ExecuteExtensionAction( | 64 ExtensionActionRunner::GetForWebContents( |
64 extension, browser(), true); | 65 browser()->tab_strip_model()->GetActiveWebContents()) |
| 66 ->RunAction(extension, true); |
65 EXPECT_TRUE(catcher.GetNextResult()); | 67 EXPECT_TRUE(catcher.GetNextResult()); |
66 } | 68 } |
67 | 69 |
68 { | 70 { |
69 // Tell the extension to update the page action state again. | 71 // Tell the extension to update the page action state again. |
70 ResultCatcher catcher; | 72 ResultCatcher catcher; |
71 ui_test_utils::NavigateToURL(browser(), | 73 ui_test_utils::NavigateToURL(browser(), |
72 GURL(extension->GetResourceURL("update2.html"))); | 74 GURL(extension->GetResourceURL("update2.html"))); |
73 ASSERT_TRUE(catcher.GetNextResult()); | 75 ASSERT_TRUE(catcher.GetNextResult()); |
74 } | 76 } |
(...skipping 21 matching lines...) Expand all Loading... |
96 ExtensionAction* page_action = GetPageAction(*extension); | 98 ExtensionAction* page_action = GetPageAction(*extension); |
97 ASSERT_TRUE(page_action) | 99 ASSERT_TRUE(page_action) |
98 << "Page action test extension should have a page action."; | 100 << "Page action test extension should have a page action."; |
99 | 101 |
100 ASSERT_FALSE(page_action->HasPopup(tab_id)); | 102 ASSERT_FALSE(page_action->HasPopup(tab_id)); |
101 | 103 |
102 // Simulate the page action being clicked. The resulting event should | 104 // Simulate the page action being clicked. The resulting event should |
103 // install a page action popup. | 105 // install a page action popup. |
104 { | 106 { |
105 ResultCatcher catcher; | 107 ResultCatcher catcher; |
106 ExtensionActionAPI::Get(browser()->profile())->ExecuteExtensionAction( | 108 ExtensionActionRunner::GetForWebContents( |
107 extension, browser(), true); | 109 browser()->tab_strip_model()->GetActiveWebContents()) |
| 110 ->RunAction(extension, true); |
108 ASSERT_TRUE(catcher.GetNextResult()); | 111 ASSERT_TRUE(catcher.GetNextResult()); |
109 } | 112 } |
110 | 113 |
111 ASSERT_TRUE(page_action->HasPopup(tab_id)) | 114 ASSERT_TRUE(page_action->HasPopup(tab_id)) |
112 << "Clicking on the page action should have caused a popup to be added."; | 115 << "Clicking on the page action should have caused a popup to be added."; |
113 | 116 |
114 ASSERT_STREQ("/a_popup.html", | 117 ASSERT_STREQ("/a_popup.html", |
115 page_action->GetPopupUrl(tab_id).path().c_str()); | 118 page_action->GetPopupUrl(tab_id).path().c_str()); |
116 | 119 |
117 // Now change the popup from a_popup.html to a_second_popup.html . | 120 // Now change the popup from a_popup.html to a_second_popup.html . |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
222 | 225 |
223 WebContents* tab = | 226 WebContents* tab = |
224 browser()->tab_strip_model()->GetActiveWebContents(); | 227 browser()->tab_strip_model()->GetActiveWebContents(); |
225 ASSERT_TRUE(tab); | 228 ASSERT_TRUE(tab); |
226 | 229 |
227 EXPECT_TRUE(page_action->GetIsVisible(ExtensionTabUtil::GetTabId(tab))); | 230 EXPECT_TRUE(page_action->GetIsVisible(ExtensionTabUtil::GetTabId(tab))); |
228 | 231 |
229 { | 232 { |
230 // Simulate the page action being clicked. | 233 // Simulate the page action being clicked. |
231 ResultCatcher catcher; | 234 ResultCatcher catcher; |
232 ExtensionActionAPI::Get(browser()->profile())->ExecuteExtensionAction( | 235 ExtensionActionRunner::GetForWebContents( |
233 extension, browser(), true); | 236 browser()->tab_strip_model()->GetActiveWebContents()) |
| 237 ->RunAction(extension, true); |
234 EXPECT_TRUE(catcher.GetNextResult()); | 238 EXPECT_TRUE(catcher.GetNextResult()); |
235 } | 239 } |
236 | 240 |
237 // Verify that the browser action turned the background color red. | 241 // Verify that the browser action turned the background color red. |
238 const std::string script = | 242 const std::string script = |
239 "window.domAutomationController.send(document.body.style." | 243 "window.domAutomationController.send(document.body.style." |
240 "backgroundColor);"; | 244 "backgroundColor);"; |
241 std::string result; | 245 std::string result; |
242 EXPECT_TRUE(content::ExecuteScriptAndExtractString(tab, script, &result)); | 246 EXPECT_TRUE(content::ExecuteScriptAndExtractString(tab, script, &result)); |
243 EXPECT_EQ(result, "red"); | 247 EXPECT_EQ(result, "red"); |
244 } | 248 } |
245 | 249 |
246 } // namespace | 250 } // namespace |
247 } // namespace extensions | 251 } // namespace extensions |
OLD | NEW |