OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "build/build_config.h" | 5 #include "build/build_config.h" |
6 | 6 |
7 #if defined(TOOLKIT_GTK) | 7 #if defined(TOOLKIT_GTK) |
8 #include <gtk/gtk.h> | 8 #include <gtk/gtk.h> |
9 #endif | 9 #endif |
10 | 10 |
11 #include "chrome/browser/extensions/browser_action_test_util.h" | 11 #include "chrome/browser/extensions/browser_action_test_util.h" |
12 #include "chrome/browser/extensions/extension_apitest.h" | 12 #include "chrome/browser/extensions/extension_apitest.h" |
13 #include "chrome/browser/extensions/extension_browser_event_router.h" | 13 #include "chrome/browser/extensions/extension_browser_event_router.h" |
14 #include "chrome/browser/extensions/extension_service.h" | 14 #include "chrome/browser/extensions/extension_service.h" |
15 #include "chrome/browser/extensions/extension_tab_util.h" | 15 #include "chrome/browser/extensions/extension_tab_util.h" |
16 #include "chrome/browser/profiles/profile.h" | 16 #include "chrome/browser/profiles/profile.h" |
17 #include "chrome/browser/ui/browser.h" | 17 #include "chrome/browser/ui/browser.h" |
18 #include "chrome/browser/ui/browser_window.h" | 18 #include "chrome/browser/ui/browser_window.h" |
19 #include "chrome/common/chrome_notification_types.h" | 19 #include "chrome/common/chrome_notification_types.h" |
20 #include "chrome/common/extensions/extension_action.h" | 20 #include "chrome/common/extensions/extension_action.h" |
21 #include "chrome/common/url_constants.h" | 21 #include "chrome/common/url_constants.h" |
22 #include "chrome/test/base/ui_test_utils.h" | 22 #include "chrome/test/base/ui_test_utils.h" |
23 #include "content/browser/tab_contents/tab_contents.h" | 23 #include "content/browser/tab_contents/tab_contents.h" |
24 #include "content/public/browser/notification_service.h" | 24 #include "content/public/browser/notification_service.h" |
25 #include "ui/gfx/rect.h" | 25 #include "ui/gfx/rect.h" |
26 #include "ui/gfx/size.h" | 26 #include "ui/gfx/size.h" |
27 | 27 |
| 28 using content::WebContents; |
| 29 |
28 class BrowserActionApiTest : public ExtensionApiTest { | 30 class BrowserActionApiTest : public ExtensionApiTest { |
29 public: | 31 public: |
30 BrowserActionApiTest() {} | 32 BrowserActionApiTest() {} |
31 virtual ~BrowserActionApiTest() {} | 33 virtual ~BrowserActionApiTest() {} |
32 | 34 |
33 protected: | 35 protected: |
34 BrowserActionTestUtil GetBrowserActionsBar() { | 36 BrowserActionTestUtil GetBrowserActionsBar() { |
35 return BrowserActionTestUtil(browser()); | 37 return BrowserActionTestUtil(browser()); |
36 } | 38 } |
37 | 39 |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
71 | 73 |
72 // Simulate the browser action being clicked. | 74 // Simulate the browser action being clicked. |
73 ui_test_utils::NavigateToURL(browser(), | 75 ui_test_utils::NavigateToURL(browser(), |
74 test_server()->GetURL("files/extensions/test_file.txt")); | 76 test_server()->GetURL("files/extensions/test_file.txt")); |
75 | 77 |
76 ExtensionService* service = browser()->profile()->GetExtensionService(); | 78 ExtensionService* service = browser()->profile()->GetExtensionService(); |
77 service->browser_event_router()->BrowserActionExecuted( | 79 service->browser_event_router()->BrowserActionExecuted( |
78 browser()->profile(), action->extension_id(), browser()); | 80 browser()->profile(), action->extension_id(), browser()); |
79 | 81 |
80 // Verify the command worked. | 82 // Verify the command worked. |
81 TabContents* tab = browser()->GetSelectedTabContents(); | 83 WebContents* tab = browser()->GetSelectedWebContents(); |
82 bool result = false; | 84 bool result = false; |
83 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool( | 85 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool( |
84 tab->GetRenderViewHost(), L"", | 86 tab->GetRenderViewHost(), L"", |
85 L"setInterval(function(){" | 87 L"setInterval(function(){" |
86 L" if(document.body.bgColor == 'red'){" | 88 L" if(document.body.bgColor == 'red'){" |
87 L" window.domAutomationController.send(true)}}, 100)", | 89 L" window.domAutomationController.send(true)}}, 100)", |
88 &result)); | 90 &result)); |
89 ASSERT_TRUE(result); | 91 ASSERT_TRUE(result); |
90 } | 92 } |
91 | 93 |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
184 EXPECT_TRUE(actions_bar.HidePopup()); | 186 EXPECT_TRUE(actions_bar.HidePopup()); |
185 } | 187 } |
186 | 188 |
187 // Test that calling chrome.browserAction.setPopup() can enable and change | 189 // Test that calling chrome.browserAction.setPopup() can enable and change |
188 // a popup. | 190 // a popup. |
189 IN_PROC_BROWSER_TEST_F(BrowserActionApiTest, BrowserActionAddPopup) { | 191 IN_PROC_BROWSER_TEST_F(BrowserActionApiTest, BrowserActionAddPopup) { |
190 ASSERT_TRUE(RunExtensionTest("browser_action/add_popup")) << message_; | 192 ASSERT_TRUE(RunExtensionTest("browser_action/add_popup")) << message_; |
191 const Extension* extension = GetSingleLoadedExtension(); | 193 const Extension* extension = GetSingleLoadedExtension(); |
192 ASSERT_TRUE(extension) << message_; | 194 ASSERT_TRUE(extension) << message_; |
193 | 195 |
194 int tab_id = ExtensionTabUtil::GetTabId(browser()->GetSelectedTabContents()); | 196 int tab_id = ExtensionTabUtil::GetTabId(browser()->GetSelectedWebContents()); |
195 | 197 |
196 ExtensionAction* browser_action = extension->browser_action(); | 198 ExtensionAction* browser_action = extension->browser_action(); |
197 ASSERT_TRUE(browser_action) | 199 ASSERT_TRUE(browser_action) |
198 << "Browser action test extension should have a browser action."; | 200 << "Browser action test extension should have a browser action."; |
199 | 201 |
200 ASSERT_FALSE(browser_action->HasPopup(tab_id)); | 202 ASSERT_FALSE(browser_action->HasPopup(tab_id)); |
201 ASSERT_FALSE(browser_action->HasPopup(ExtensionAction::kDefaultTabId)); | 203 ASSERT_FALSE(browser_action->HasPopup(ExtensionAction::kDefaultTabId)); |
202 | 204 |
203 // Simulate a click on the browser action icon. The onClicked handler | 205 // Simulate a click on the browser action icon. The onClicked handler |
204 // will add a popup. | 206 // will add a popup. |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
239 browser_action->GetPopupUrl(tab_id).path().c_str()); | 241 browser_action->GetPopupUrl(tab_id).path().c_str()); |
240 } | 242 } |
241 | 243 |
242 // Test that calling chrome.browserAction.setPopup() can remove a popup. | 244 // Test that calling chrome.browserAction.setPopup() can remove a popup. |
243 IN_PROC_BROWSER_TEST_F(BrowserActionApiTest, BrowserActionRemovePopup) { | 245 IN_PROC_BROWSER_TEST_F(BrowserActionApiTest, BrowserActionRemovePopup) { |
244 // Load the extension, which has a browser action with a default popup. | 246 // Load the extension, which has a browser action with a default popup. |
245 ASSERT_TRUE(RunExtensionTest("browser_action/remove_popup")) << message_; | 247 ASSERT_TRUE(RunExtensionTest("browser_action/remove_popup")) << message_; |
246 const Extension* extension = GetSingleLoadedExtension(); | 248 const Extension* extension = GetSingleLoadedExtension(); |
247 ASSERT_TRUE(extension) << message_; | 249 ASSERT_TRUE(extension) << message_; |
248 | 250 |
249 int tab_id = ExtensionTabUtil::GetTabId(browser()->GetSelectedTabContents()); | 251 int tab_id = ExtensionTabUtil::GetTabId(browser()->GetSelectedWebContents()); |
250 | 252 |
251 ExtensionAction* browser_action = extension->browser_action(); | 253 ExtensionAction* browser_action = extension->browser_action(); |
252 ASSERT_TRUE(browser_action) | 254 ASSERT_TRUE(browser_action) |
253 << "Browser action test extension should have a browser action."; | 255 << "Browser action test extension should have a browser action."; |
254 | 256 |
255 ASSERT_TRUE(browser_action->HasPopup(tab_id)) | 257 ASSERT_TRUE(browser_action->HasPopup(tab_id)) |
256 << "Expect a browser action popup before the test removes it."; | 258 << "Expect a browser action popup before the test removes it."; |
257 ASSERT_TRUE(browser_action->HasPopup(ExtensionAction::kDefaultTabId)) | 259 ASSERT_TRUE(browser_action->HasPopup(ExtensionAction::kDefaultTabId)) |
258 << "Expect a browser action popup is the default for all tabs."; | 260 << "Expect a browser action popup is the default for all tabs."; |
259 | 261 |
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
399 BrowserActionExecuted( | 401 BrowserActionExecuted( |
400 browser()->profile(), action->extension_id(), browser()); | 402 browser()->profile(), action->extension_id(), browser()); |
401 | 403 |
402 // It can take a moment for the background page to actually get destroyed | 404 // It can take a moment for the background page to actually get destroyed |
403 // so we wait for the notification before checking that it's really gone | 405 // so we wait for the notification before checking that it's really gone |
404 // and the badge text has been set. | 406 // and the badge text has been set. |
405 host_destroyed_observer.Wait(); | 407 host_destroyed_observer.Wait(); |
406 ASSERT_FALSE(manager->GetBackgroundHostForExtension(extension->id())); | 408 ASSERT_FALSE(manager->GetBackgroundHostForExtension(extension->id())); |
407 ASSERT_EQ("X", action->GetBadgeText(ExtensionAction::kDefaultTabId)); | 409 ASSERT_EQ("X", action->GetBadgeText(ExtensionAction::kDefaultTabId)); |
408 } | 410 } |
OLD | NEW |