Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(525)

Side by Side Diff: chrome/browser/extensions/api/extension_action/browser_action_apitest.cc

Issue 10702029: Move tab functions off Browser into browser_tabstrip and browser_tabrestore. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 "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_commands.h" 18 #include "chrome/browser/ui/browser_commands.h"
19 #include "chrome/browser/ui/browser_tabstrip.h"
19 #include "chrome/browser/ui/browser_window.h" 20 #include "chrome/browser/ui/browser_window.h"
20 #include "chrome/common/chrome_notification_types.h" 21 #include "chrome/common/chrome_notification_types.h"
21 #include "chrome/common/extensions/extension_action.h" 22 #include "chrome/common/extensions/extension_action.h"
22 #include "chrome/common/url_constants.h" 23 #include "chrome/common/url_constants.h"
23 #include "chrome/test/base/ui_test_utils.h" 24 #include "chrome/test/base/ui_test_utils.h"
24 #include "content/public/browser/notification_service.h" 25 #include "content/public/browser/notification_service.h"
25 #include "content/public/browser/web_contents.h" 26 #include "content/public/browser/web_contents.h"
26 #include "ui/gfx/rect.h" 27 #include "ui/gfx/rect.h"
27 #include "ui/gfx/size.h" 28 #include "ui/gfx/size.h"
28 29
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
74 action->GetBadgeBackgroundColor(ExtensionAction::kDefaultTabId)); 75 action->GetBadgeBackgroundColor(ExtensionAction::kDefaultTabId));
75 76
76 // Simulate the browser action being clicked. 77 // Simulate the browser action being clicked.
77 ui_test_utils::NavigateToURL(browser(), 78 ui_test_utils::NavigateToURL(browser(),
78 test_server()->GetURL("files/extensions/test_file.txt")); 79 test_server()->GetURL("files/extensions/test_file.txt"));
79 80
80 ExtensionService* service = browser()->profile()->GetExtensionService(); 81 ExtensionService* service = browser()->profile()->GetExtensionService();
81 service->toolbar_model()->ExecuteBrowserAction(extension, browser(), NULL); 82 service->toolbar_model()->ExecuteBrowserAction(extension, browser(), NULL);
82 83
83 // Verify the command worked. 84 // Verify the command worked.
84 WebContents* tab = browser()->GetActiveWebContents(); 85 WebContents* tab = chrome::GetActiveWebContents(browser());
85 bool result = false; 86 bool result = false;
86 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool( 87 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool(
87 tab->GetRenderViewHost(), L"", 88 tab->GetRenderViewHost(), L"",
88 L"setInterval(function(){" 89 L"setInterval(function(){"
89 L" if(document.body.bgColor == 'red'){" 90 L" if(document.body.bgColor == 'red'){"
90 L" window.domAutomationController.send(true)}}, 100)", 91 L" window.domAutomationController.send(true)}}, 100)",
91 &result)); 92 &result));
92 ASSERT_TRUE(result); 93 ASSERT_TRUE(result);
93 } 94 }
94 95
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
140 ResultCatcher catcher; 141 ResultCatcher catcher;
141 GetBrowserActionsBar().Press(0); 142 GetBrowserActionsBar().Press(0);
142 ASSERT_TRUE(catcher.GetNextResult()); 143 ASSERT_TRUE(catcher.GetNextResult());
143 EXPECT_EQ("Showing icon 2", GetBrowserActionsBar().GetTooltip(0)); 144 EXPECT_EQ("Showing icon 2", GetBrowserActionsBar().GetTooltip(0));
144 145
145 // Open a new tab, the title should go back. 146 // Open a new tab, the title should go back.
146 chrome::NewTab(browser()); 147 chrome::NewTab(browser());
147 EXPECT_EQ("hi!", GetBrowserActionsBar().GetTooltip(0)); 148 EXPECT_EQ("hi!", GetBrowserActionsBar().GetTooltip(0));
148 149
149 // Go back to first tab, changed title should reappear. 150 // Go back to first tab, changed title should reappear.
150 browser()->ActivateTabAt(0, true); 151 chrome::ActivateTabAt(browser(), 0, true);
151 EXPECT_EQ("Showing icon 2", GetBrowserActionsBar().GetTooltip(0)); 152 EXPECT_EQ("Showing icon 2", GetBrowserActionsBar().GetTooltip(0));
152 153
153 // Reload that tab, default title should come back. 154 // Reload that tab, default title should come back.
154 ui_test_utils::NavigateToURL(browser(), GURL("about:blank")); 155 ui_test_utils::NavigateToURL(browser(), GURL("about:blank"));
155 EXPECT_EQ("hi!", GetBrowserActionsBar().GetTooltip(0)); 156 EXPECT_EQ("hi!", GetBrowserActionsBar().GetTooltip(0));
156 } 157 }
157 158
158 // http://code.google.com/p/chromium/issues/detail?id=70829 159 // http://code.google.com/p/chromium/issues/detail?id=70829
159 // Mac used to be ok, but then mac 10.5 started failing too. =( 160 // Mac used to be ok, but then mac 10.5 started failing too. =(
160 IN_PROC_BROWSER_TEST_F(BrowserActionApiTest, DISABLED_BrowserActionPopup) { 161 IN_PROC_BROWSER_TEST_F(BrowserActionApiTest, DISABLED_BrowserActionPopup) {
(...skipping 29 matching lines...) Expand all
190 EXPECT_TRUE(actions_bar.HidePopup()); 191 EXPECT_TRUE(actions_bar.HidePopup());
191 } 192 }
192 193
193 // Test that calling chrome.browserAction.setPopup() can enable and change 194 // Test that calling chrome.browserAction.setPopup() can enable and change
194 // a popup. 195 // a popup.
195 IN_PROC_BROWSER_TEST_F(BrowserActionApiTest, BrowserActionAddPopup) { 196 IN_PROC_BROWSER_TEST_F(BrowserActionApiTest, BrowserActionAddPopup) {
196 ASSERT_TRUE(RunExtensionTest("browser_action/add_popup")) << message_; 197 ASSERT_TRUE(RunExtensionTest("browser_action/add_popup")) << message_;
197 const Extension* extension = GetSingleLoadedExtension(); 198 const Extension* extension = GetSingleLoadedExtension();
198 ASSERT_TRUE(extension) << message_; 199 ASSERT_TRUE(extension) << message_;
199 200
200 int tab_id = ExtensionTabUtil::GetTabId(browser()->GetActiveWebContents()); 201 int tab_id = ExtensionTabUtil::GetTabId(
202 chrome::GetActiveWebContents(browser()));
201 203
202 ExtensionAction* browser_action = extension->browser_action(); 204 ExtensionAction* browser_action = extension->browser_action();
203 ASSERT_TRUE(browser_action) 205 ASSERT_TRUE(browser_action)
204 << "Browser action test extension should have a browser action."; 206 << "Browser action test extension should have a browser action.";
205 207
206 ASSERT_FALSE(browser_action->HasPopup(tab_id)); 208 ASSERT_FALSE(browser_action->HasPopup(tab_id));
207 ASSERT_FALSE(browser_action->HasPopup(ExtensionAction::kDefaultTabId)); 209 ASSERT_FALSE(browser_action->HasPopup(ExtensionAction::kDefaultTabId));
208 210
209 // Simulate a click on the browser action icon. The onClicked handler 211 // Simulate a click on the browser action icon. The onClicked handler
210 // will add a popup. 212 // will add a popup.
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
245 browser_action->GetPopupUrl(tab_id).path().c_str()); 247 browser_action->GetPopupUrl(tab_id).path().c_str());
246 } 248 }
247 249
248 // Test that calling chrome.browserAction.setPopup() can remove a popup. 250 // Test that calling chrome.browserAction.setPopup() can remove a popup.
249 IN_PROC_BROWSER_TEST_F(BrowserActionApiTest, BrowserActionRemovePopup) { 251 IN_PROC_BROWSER_TEST_F(BrowserActionApiTest, BrowserActionRemovePopup) {
250 // Load the extension, which has a browser action with a default popup. 252 // Load the extension, which has a browser action with a default popup.
251 ASSERT_TRUE(RunExtensionTest("browser_action/remove_popup")) << message_; 253 ASSERT_TRUE(RunExtensionTest("browser_action/remove_popup")) << message_;
252 const Extension* extension = GetSingleLoadedExtension(); 254 const Extension* extension = GetSingleLoadedExtension();
253 ASSERT_TRUE(extension) << message_; 255 ASSERT_TRUE(extension) << message_;
254 256
255 int tab_id = ExtensionTabUtil::GetTabId(browser()->GetActiveWebContents()); 257 int tab_id = ExtensionTabUtil::GetTabId(
258 chrome::GetActiveWebContents(browser()));
256 259
257 ExtensionAction* browser_action = extension->browser_action(); 260 ExtensionAction* browser_action = extension->browser_action();
258 ASSERT_TRUE(browser_action) 261 ASSERT_TRUE(browser_action)
259 << "Browser action test extension should have a browser action."; 262 << "Browser action test extension should have a browser action.";
260 263
261 ASSERT_TRUE(browser_action->HasPopup(tab_id)) 264 ASSERT_TRUE(browser_action->HasPopup(tab_id))
262 << "Expect a browser action popup before the test removes it."; 265 << "Expect a browser action popup before the test removes it.";
263 ASSERT_TRUE(browser_action->HasPopup(ExtensionAction::kDefaultTabId)) 266 ASSERT_TRUE(browser_action->HasPopup(ExtensionAction::kDefaultTabId))
264 << "Expect a browser action popup is the default for all tabs."; 267 << "Expect a browser action popup is the default for all tabs.";
265 268
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after
459 ResultCatcher catcher; 462 ResultCatcher catcher;
460 ui_test_utils::NavigateToURL(browser(), 463 ui_test_utils::NavigateToURL(browser(),
461 GURL(extension->GetResourceURL("update.html"))); 464 GURL(extension->GetResourceURL("update.html")));
462 ASSERT_TRUE(catcher.GetNextResult()); 465 ASSERT_TRUE(catcher.GetNextResult());
463 466
464 // Test the getters for a specific tab. 467 // Test the getters for a specific tab.
465 ui_test_utils::NavigateToURL(browser(), 468 ui_test_utils::NavigateToURL(browser(),
466 GURL(extension->GetResourceURL("update2.html"))); 469 GURL(extension->GetResourceURL("update2.html")));
467 ASSERT_TRUE(catcher.GetNextResult()); 470 ASSERT_TRUE(catcher.GetNextResult());
468 } 471 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698