blob: 006bc00136560c10bc1d2113488ed1e2ac48c22b [file] [log] [blame]
[email protected]8643e6d2012-01-18 20:26:101// Copyright (c) 2012 The Chromium Authors. All rights reserved.
[email protected]a1feae52010-10-11 22:14:452// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
[email protected]bd817c22011-02-09 08:16:465#include "chrome/browser/ui/browser_navigator_browsertest.h"
6
[email protected]bb89e7482010-11-17 18:27:047#include "base/command_line.h"
[email protected]26c53e662011-07-09 02:21:028#include "chrome/app/chrome_command_ids.h"
9#include "chrome/browser/autocomplete/autocomplete_edit.h"
[email protected]93ad8e1c2011-11-08 21:34:0510#include "chrome/browser/prefs/incognito_mode_prefs.h"
11#include "chrome/browser/prefs/pref_service.h"
[email protected]8ecad5e2010-12-02 21:18:3312#include "chrome/browser/profiles/profile.h"
[email protected]a1feae52010-10-11 22:14:4513#include "chrome/browser/tabs/tab_strip_model.h"
[email protected]bb89e7482010-11-17 18:27:0414#include "chrome/browser/ui/browser_list.h"
[email protected]339d6dd2010-11-12 00:41:5815#include "chrome/browser/ui/browser_navigator.h"
[email protected]bb89e7482010-11-17 18:27:0416#include "chrome/browser/ui/browser_window.h"
[email protected]26c53e662011-07-09 02:21:0217#include "chrome/browser/ui/omnibox/location_bar.h"
18#include "chrome/browser/ui/omnibox/omnibox_view.h"
[email protected]6a3ec2312010-12-02 19:30:1919#include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h"
[email protected]bb89e7482010-11-17 18:27:0420#include "chrome/common/chrome_switches.h"
[email protected]93ad8e1c2011-11-08 21:34:0521#include "chrome/common/pref_names.h"
[email protected]ddddfda2011-07-14 23:19:3922#include "chrome/common/url_constants.h"
[email protected]af44e7fb2011-07-29 18:32:3223#include "chrome/test/base/ui_test_utils.h"
[email protected]ad50def52011-10-19 23:17:0724#include "content/public/browser/notification_service.h"
[email protected]0d6e9bd2011-10-18 04:29:1625#include "content/public/browser/notification_types.h"
[email protected]83ff91c2012-01-05 20:54:1326#include "content/public/browser/web_contents.h"
[email protected]8643e6d2012-01-18 20:26:1027#include "content/public/browser/web_contents_view.h"
[email protected]a1feae52010-10-11 22:14:4528
[email protected]4ca15302012-01-03 05:53:2029using content::WebContents;
30
[email protected]ddddfda2011-07-14 23:19:3931namespace {
32
33GURL GetGoogleURL() {
[email protected]bd817c22011-02-09 08:16:4634 return GURL("http://www.google.com/");
35}
[email protected]a1feae52010-10-11 22:14:4536
[email protected]ddddfda2011-07-14 23:19:3937GURL GetSettingsURL() {
[email protected]a048ad22012-03-23 04:26:5638 return GURL(chrome::kChromeUIUberURL).Resolve(
39 chrome::kChromeUISettingsHost + std::string("/"));
[email protected]ddddfda2011-07-14 23:19:3940}
41
[email protected]a048ad22012-03-23 04:26:5642GURL GetContentSettingsURL() {
43 return GetSettingsURL().Resolve(chrome::kContentSettingsExceptionsSubPage);
[email protected]ddddfda2011-07-14 23:19:3944}
45
[email protected]a048ad22012-03-23 04:26:5646GURL GetClearBrowsingDataURL() {
47 return GetSettingsURL().Resolve(chrome::kClearBrowserDataSubPage);
[email protected]ddddfda2011-07-14 23:19:3948}
49
50} // namespace
51
[email protected]bd817c22011-02-09 08:16:4652browser::NavigateParams BrowserNavigatorTest::MakeNavigateParams() const {
53 return MakeNavigateParams(browser());
54}
[email protected]a1feae52010-10-11 22:14:4555
[email protected]bd817c22011-02-09 08:16:4656browser::NavigateParams BrowserNavigatorTest::MakeNavigateParams(
57 Browser* browser) const {
58 browser::NavigateParams params(browser, GetGoogleURL(),
[email protected]2905f742011-10-13 03:51:5859 content::PAGE_TRANSITION_LINK);
[email protected]7d329992011-04-15 18:20:0260 params.window_action = browser::NavigateParams::SHOW_WINDOW;
[email protected]bd817c22011-02-09 08:16:4661 return params;
62}
[email protected]a1feae52010-10-11 22:14:4563
[email protected]bd817c22011-02-09 08:16:4664Browser* BrowserNavigatorTest::CreateEmptyBrowserForType(Browser::Type type,
65 Profile* profile) {
66 Browser* browser = Browser::CreateForType(type, profile);
67 browser->AddBlankTab(true);
68 return browser;
69}
[email protected]a1feae52010-10-11 22:14:4570
[email protected]b35b26b32011-05-05 20:35:1471Browser* BrowserNavigatorTest::CreateEmptyBrowserForApp(Browser::Type type,
72 Profile* profile) {
73 Browser* browser = Browser::CreateForApp(Browser::TYPE_POPUP, "Test",
[email protected]5c209242011-06-06 20:36:1774 gfx::Rect(), profile);
[email protected]b35b26b32011-05-05 20:35:1475 browser->AddBlankTab(true);
76 return browser;
77}
78
[email protected]bd817c22011-02-09 08:16:4679TabContentsWrapper* BrowserNavigatorTest::CreateTabContents() {
80 return Browser::TabContentsFactory(
81 browser()->profile(),
82 NULL,
83 MSG_ROUTING_NONE,
[email protected]bb81f382012-01-03 22:45:4484 browser()->GetSelectedWebContents(),
[email protected]bd817c22011-02-09 08:16:4685 NULL);
86}
[email protected]a1feae52010-10-11 22:14:4587
[email protected]bd817c22011-02-09 08:16:4688void BrowserNavigatorTest::RunSuppressTest(WindowOpenDisposition disposition) {
[email protected]4ca15302012-01-03 05:53:2089 GURL old_url = browser()->GetSelectedWebContents()->GetURL();
[email protected]bd817c22011-02-09 08:16:4690 browser::NavigateParams p(MakeNavigateParams());
91 p.disposition = disposition;
92 browser::Navigate(&p);
[email protected]a1feae52010-10-11 22:14:4593
[email protected]bd817c22011-02-09 08:16:4694 // Nothing should have happened as a result of Navigate();
95 EXPECT_EQ(1, browser()->tab_count());
96 EXPECT_EQ(1u, BrowserList::size());
[email protected]4ca15302012-01-03 05:53:2097 EXPECT_EQ(old_url, browser()->GetSelectedWebContents()->GetURL());
[email protected]bd817c22011-02-09 08:16:4698}
[email protected]bb89e7482010-11-17 18:27:0499
[email protected]fc0ed302011-11-29 23:17:19100void BrowserNavigatorTest::RunUseNonIncognitoWindowTest(const GURL& url) {
101 Browser* incognito_browser = CreateIncognitoBrowser();
102
103 EXPECT_EQ(2u, BrowserList::size());
104 EXPECT_EQ(1, browser()->tab_count());
105 EXPECT_EQ(1, incognito_browser->tab_count());
106
107 // Navigate to the page.
108 browser::NavigateParams p(MakeNavigateParams(incognito_browser));
109 p.disposition = SINGLETON_TAB;
110 p.url = url;
111 p.window_action = browser::NavigateParams::SHOW_WINDOW;
112 browser::Navigate(&p);
113
114 // This page should be opened in browser() window.
115 EXPECT_NE(incognito_browser, p.browser);
116 EXPECT_EQ(browser(), p.browser);
117 EXPECT_EQ(2, browser()->tab_count());
[email protected]4ca15302012-01-03 05:53:20118 EXPECT_EQ(url, browser()->GetSelectedWebContents()->GetURL());
[email protected]fc0ed302011-11-29 23:17:19119}
120
121void BrowserNavigatorTest::RunDoNothingIfIncognitoIsForcedTest(
122 const GURL& url) {
123 Browser* browser = CreateIncognitoBrowser();
124
125 // Set kIncognitoModeAvailability to FORCED.
126 PrefService* prefs1 = browser->profile()->GetPrefs();
127 prefs1->SetInteger(prefs::kIncognitoModeAvailability,
128 IncognitoModePrefs::FORCED);
129 PrefService* prefs2 = browser->profile()->GetOriginalProfile()->GetPrefs();
130 prefs2->SetInteger(prefs::kIncognitoModeAvailability,
131 IncognitoModePrefs::FORCED);
132
133 // Navigate to the page.
134 browser::NavigateParams p(MakeNavigateParams(browser));
135 p.disposition = OFF_THE_RECORD;
136 p.url = url;
137 p.window_action = browser::NavigateParams::SHOW_WINDOW;
138 browser::Navigate(&p);
139
140 // The page should not be opened.
141 EXPECT_EQ(browser, p.browser);
142 EXPECT_EQ(1, browser->tab_count());
143 EXPECT_EQ(GURL(chrome::kAboutBlankURL),
[email protected]4ca15302012-01-03 05:53:20144 browser->GetSelectedWebContents()->GetURL());
[email protected]fc0ed302011-11-29 23:17:19145}
146
[email protected]6c2381d2011-10-19 02:52:53147void BrowserNavigatorTest::Observe(
148 int type,
149 const content::NotificationSource& source,
150 const content::NotificationDetails& details) {
[email protected]432115822011-07-10 15:52:27151 switch (type) {
152 case content::NOTIFICATION_RENDER_VIEW_HOST_CREATED_FOR_TAB: {
[email protected]bd817c22011-02-09 08:16:46153 ++this->created_tab_contents_count_;
154 break;
[email protected]fa7ebe02010-11-29 23:04:57155 }
[email protected]bd817c22011-02-09 08:16:46156 default:
157 break;
[email protected]fa7ebe02010-11-29 23:04:57158 }
[email protected]bd817c22011-02-09 08:16:46159}
[email protected]fa7ebe02010-11-29 23:04:57160
[email protected]ddddfda2011-07-14 23:19:39161
[email protected]bd817c22011-02-09 08:16:46162namespace {
[email protected]a1feae52010-10-11 22:14:45163
[email protected]a1feae52010-10-11 22:14:45164// This test verifies that when a navigation occurs within a tab, the tab count
165// of the Browser remains the same and the current tab bears the loaded URL.
166IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_CurrentTab) {
[email protected]ddddfda2011-07-14 23:19:39167 ui_test_utils::NavigateToURL(browser(), GetGoogleURL());
[email protected]4ca15302012-01-03 05:53:20168 EXPECT_EQ(GetGoogleURL(), browser()->GetSelectedWebContents()->GetURL());
[email protected]a1feae52010-10-11 22:14:45169 // We should have one window with one tab.
170 EXPECT_EQ(1u, BrowserList::size());
171 EXPECT_EQ(1, browser()->tab_count());
172}
173
[email protected]bd817c22011-02-09 08:16:46174// This test verifies that a singleton tab is refocused if one is already opened
[email protected]19d9f3a2010-10-14 21:49:36175// in another or an existing window, or added if it is not.
176IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_SingletonTabExisting) {
[email protected]19d9f3a2010-10-14 21:49:36177 GURL singleton_url1("http://maps.google.com/");
[email protected]fa7ebe02010-11-29 23:04:57178
179 // Register for a notification if an additional tab_contents was instantiated.
[email protected]bd817c22011-02-09 08:16:46180 // Opening a Singleton tab that is already opened should not be opening a new
[email protected]fa7ebe02010-11-29 23:04:57181 // tab nor be creating a new TabContents object
[email protected]6c2381d2011-10-19 02:52:53182 content::NotificationRegistrar registrar;
[email protected]fa7ebe02010-11-29 23:04:57183
184 // As the registrar object goes out of scope, this will get unregistered
[email protected]432115822011-07-10 15:52:27185 registrar.Add(this, content::NOTIFICATION_RENDER_VIEW_HOST_CREATED_FOR_TAB,
[email protected]ad50def52011-10-19 23:17:07186 content::NotificationService::AllSources());
[email protected]fa7ebe02010-11-29 23:04:57187
[email protected]2905f742011-10-13 03:51:58188 browser()->AddSelectedTabWithURL(
189 singleton_url1, content::PAGE_TRANSITION_LINK);
190 browser()->AddSelectedTabWithURL(
191 GetGoogleURL(), content::PAGE_TRANSITION_LINK);
[email protected]19d9f3a2010-10-14 21:49:36192
193 // We should have one browser with 3 tabs, the 3rd selected.
194 EXPECT_EQ(1u, BrowserList::size());
[email protected]1ea49d52011-04-12 17:44:44195 EXPECT_EQ(2, browser()->active_index());
[email protected]19d9f3a2010-10-14 21:49:36196
[email protected]fa7ebe02010-11-29 23:04:57197 unsigned int previous_tab_contents_count =
198 created_tab_contents_count_ = 0;
199
[email protected]19d9f3a2010-10-14 21:49:36200 // Navigate to singleton_url1.
201 browser::NavigateParams p(MakeNavigateParams());
202 p.disposition = SINGLETON_TAB;
203 p.url = singleton_url1;
204 browser::Navigate(&p);
205
206 // The middle tab should now be selected.
207 EXPECT_EQ(browser(), p.browser);
[email protected]1ea49d52011-04-12 17:44:44208 EXPECT_EQ(1, browser()->active_index());
[email protected]fa7ebe02010-11-29 23:04:57209
210 // No tab contents should have been created
211 EXPECT_EQ(previous_tab_contents_count,
212 created_tab_contents_count_);
[email protected]19d9f3a2010-10-14 21:49:36213}
214
215IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
[email protected]578c6962011-08-24 22:06:40216 Disposition_SingletonTabRespectingRef) {
217 GURL singleton_ref_url1("http://maps.google.com/#a");
218 GURL singleton_ref_url2("http://maps.google.com/#b");
219 GURL singleton_ref_url3("http://maps.google.com/");
220
[email protected]2905f742011-10-13 03:51:58221 browser()->AddSelectedTabWithURL(
222 singleton_ref_url1, content::PAGE_TRANSITION_LINK);
[email protected]578c6962011-08-24 22:06:40223
224 // We should have one browser with 2 tabs, 2nd selected.
225 EXPECT_EQ(1u, BrowserList::size());
226 EXPECT_EQ(2, browser()->tab_count());
227 EXPECT_EQ(1, browser()->active_index());
228
229 // Navigate to singleton_url2.
230 browser::NavigateParams p(MakeNavigateParams());
231 p.disposition = SINGLETON_TAB;
232 p.url = singleton_ref_url2;
233 browser::Navigate(&p);
234
235 // We should now have 2 tabs, the 2nd one selected.
236 EXPECT_EQ(browser(), p.browser);
237 EXPECT_EQ(2, browser()->tab_count());
238 EXPECT_EQ(1, browser()->active_index());
239
240 // Navigate to singleton_url2, but with respect ref set.
241 p = MakeNavigateParams();
242 p.disposition = SINGLETON_TAB;
243 p.url = singleton_ref_url2;
244 p.ref_behavior = browser::NavigateParams::RESPECT_REF;
245 browser::Navigate(&p);
246
247 // We should now have 3 tabs, the 3th one selected.
248 EXPECT_EQ(browser(), p.browser);
249 EXPECT_EQ(3, browser()->tab_count());
250 EXPECT_EQ(2, browser()->active_index());
251
252 // Navigate to singleton_url3.
253 p = MakeNavigateParams();
254 p.disposition = SINGLETON_TAB;
255 p.url = singleton_ref_url3;
256 p.ref_behavior = browser::NavigateParams::RESPECT_REF;
257 browser::Navigate(&p);
258
259 // We should now have 4 tabs, the 4th one selected.
260 EXPECT_EQ(browser(), p.browser);
261 EXPECT_EQ(4, browser()->tab_count());
262 EXPECT_EQ(3, browser()->active_index());
263}
264
265IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
[email protected]19d9f3a2010-10-14 21:49:36266 Disposition_SingletonTabNoneExisting) {
[email protected]19d9f3a2010-10-14 21:49:36267 GURL singleton_url1("http://maps.google.com/");
268
[email protected]bd817c22011-02-09 08:16:46269 // We should have one browser with 1 tab.
[email protected]19d9f3a2010-10-14 21:49:36270 EXPECT_EQ(1u, BrowserList::size());
[email protected]1ea49d52011-04-12 17:44:44271 EXPECT_EQ(0, browser()->active_index());
[email protected]19d9f3a2010-10-14 21:49:36272
273 // Navigate to singleton_url1.
274 browser::NavigateParams p(MakeNavigateParams());
275 p.disposition = SINGLETON_TAB;
276 p.url = singleton_url1;
277 browser::Navigate(&p);
278
279 // We should now have 2 tabs, the 2nd one selected.
280 EXPECT_EQ(browser(), p.browser);
281 EXPECT_EQ(2, browser()->tab_count());
[email protected]1ea49d52011-04-12 17:44:44282 EXPECT_EQ(1, browser()->active_index());
[email protected]a1feae52010-10-11 22:14:45283}
284
285// This test verifies that when a navigation results in a foreground tab, the
286// tab count of the Browser increases and the selected tab shifts to the new
287// foreground tab.
288IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_NewForegroundTab) {
[email protected]4ca15302012-01-03 05:53:20289 WebContents* old_contents = browser()->GetSelectedWebContents();
[email protected]a1feae52010-10-11 22:14:45290 browser::NavigateParams p(MakeNavigateParams());
291 p.disposition = NEW_FOREGROUND_TAB;
[email protected]19d9f3a2010-10-14 21:49:36292 browser::Navigate(&p);
[email protected]4ca15302012-01-03 05:53:20293 EXPECT_NE(old_contents, browser()->GetSelectedWebContents());
[email protected]3c9e1872010-11-18 16:17:49294 EXPECT_EQ(browser()->GetSelectedTabContentsWrapper(), p.target_contents);
[email protected]a1feae52010-10-11 22:14:45295 EXPECT_EQ(2, browser()->tab_count());
296}
297
298// This test verifies that when a navigation results in a background tab, the
299// tab count of the Browser increases but the selected tab remains the same.
300IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_NewBackgroundTab) {
[email protected]4ca15302012-01-03 05:53:20301 WebContents* old_contents = browser()->GetSelectedWebContents();
[email protected]a1feae52010-10-11 22:14:45302 browser::NavigateParams p(MakeNavigateParams());
303 p.disposition = NEW_BACKGROUND_TAB;
[email protected]19d9f3a2010-10-14 21:49:36304 browser::Navigate(&p);
[email protected]4ca15302012-01-03 05:53:20305 WebContents* new_contents = browser()->GetSelectedWebContents();
[email protected]a1feae52010-10-11 22:14:45306 // The selected tab should have remained unchanged, since the new tab was
307 // opened in the background.
308 EXPECT_EQ(old_contents, new_contents);
309 EXPECT_EQ(2, browser()->tab_count());
310}
311
312// This test verifies that when a navigation requiring a new foreground tab
313// occurs in a Browser that cannot host multiple tabs, the new foreground tab
314// is created in an existing compatible Browser.
315IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
316 Disposition_IncompatibleWindow_Existing) {
317 // Open a foreground tab in a window that cannot open popups when there is an
318 // existing compatible window somewhere else that they can be opened within.
319 Browser* popup = CreateEmptyBrowserForType(Browser::TYPE_POPUP,
320 browser()->profile());
321 browser::NavigateParams p(MakeNavigateParams(popup));
322 p.disposition = NEW_FOREGROUND_TAB;
[email protected]19d9f3a2010-10-14 21:49:36323 browser::Navigate(&p);
[email protected]a1feae52010-10-11 22:14:45324
325 // Navigate() should have opened the tab in a different browser since the
326 // one we supplied didn't support additional tabs.
327 EXPECT_NE(popup, p.browser);
328
329 // Since browser() is an existing compatible tabbed browser, it should have
330 // opened the tab there.
331 EXPECT_EQ(browser(), p.browser);
332
333 // We should be left with 2 windows, the popup with one tab and the browser()
334 // provided by the framework with two.
335 EXPECT_EQ(2u, BrowserList::size());
336 EXPECT_EQ(1, popup->tab_count());
337 EXPECT_EQ(2, browser()->tab_count());
338}
339
340// This test verifies that when a navigation requiring a new foreground tab
341// occurs in a Browser that cannot host multiple tabs and no compatible Browser
342// that can is open, a compatible Browser is created.
343IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
344 Disposition_IncompatibleWindow_NoExisting) {
345 // We want to simulate not being able to find an existing window compatible
346 // with our non-tabbed browser window so Navigate() is forced to create a
347 // new compatible window. Because browser() supplied by the in-process
348 // browser testing framework is compatible with browser()->profile(), we
349 // need a different profile, and creating a popup window with an incognito
350 // profile is a quick and dirty way of achieving this.
351 Browser* popup = CreateEmptyBrowserForType(
[email protected]b35b26b32011-05-05 20:35:14352 Browser::TYPE_POPUP,
353 browser()->profile()->GetOffTheRecordProfile());
[email protected]a1feae52010-10-11 22:14:45354 browser::NavigateParams p(MakeNavigateParams(popup));
355 p.disposition = NEW_FOREGROUND_TAB;
[email protected]19d9f3a2010-10-14 21:49:36356 browser::Navigate(&p);
[email protected]a1feae52010-10-11 22:14:45357
358 // Navigate() should have opened the tab in a different browser since the
359 // one we supplied didn't support additional tabs.
360 EXPECT_NE(popup, p.browser);
361
362 // This time, browser() is _not_ compatible with popup since it is not an
363 // incognito window.
364 EXPECT_NE(browser(), p.browser);
365
366 // We should have three windows, each with one tab:
367 // 1. the browser() provided by the framework (unchanged in this test)
368 // 2. the incognito popup we created originally
369 // 3. the new incognito tabbed browser that was created by Navigate().
370 EXPECT_EQ(3u, BrowserList::size());
371 EXPECT_EQ(1, browser()->tab_count());
372 EXPECT_EQ(1, popup->tab_count());
373 EXPECT_EQ(1, p.browser->tab_count());
[email protected]b35b26b32011-05-05 20:35:14374 EXPECT_TRUE(p.browser->is_type_tabbed());
[email protected]a1feae52010-10-11 22:14:45375}
376
377// This test verifies that navigating with WindowOpenDisposition = NEW_POPUP
378// from a normal Browser results in a new Browser with TYPE_POPUP.
379IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_NewPopup) {
380 browser::NavigateParams p(MakeNavigateParams());
381 p.disposition = NEW_POPUP;
[email protected]588300d2011-04-28 21:06:35382 p.window_bounds = gfx::Rect(0, 0, 200, 200);
[email protected]7d329992011-04-15 18:20:02383 // Wait for new popup to to load and gain focus.
[email protected]ddddfda2011-07-14 23:19:39384 ui_test_utils::NavigateToURL(&p);
[email protected]a1feae52010-10-11 22:14:45385
[email protected]7d329992011-04-15 18:20:02386 // Navigate() should have opened a new, focused popup window.
[email protected]a1feae52010-10-11 22:14:45387 EXPECT_NE(browser(), p.browser);
[email protected]9db263a2011-04-15 20:53:47388#if 0
389 // TODO(stevenjb): Enable this test. See: crbug.com/79493
[email protected]7d329992011-04-15 18:20:02390 EXPECT_TRUE(p.browser->window()->IsActive());
391#endif
[email protected]b35b26b32011-05-05 20:35:14392 EXPECT_TRUE(p.browser->is_type_popup());
393 EXPECT_FALSE(p.browser->is_app());
[email protected]a1feae52010-10-11 22:14:45394
395 // We should have two windows, the browser() provided by the framework and the
396 // new popup window.
397 EXPECT_EQ(2u, BrowserList::size());
398 EXPECT_EQ(1, browser()->tab_count());
399 EXPECT_EQ(1, p.browser->tab_count());
400}
401
402// This test verifies that navigating with WindowOpenDisposition = NEW_POPUP
[email protected]f112b0f2011-05-26 01:53:52403// from a normal Browser results in a new Browser with is_app() true.
404IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_NewPopup_ExtensionId) {
405 browser::NavigateParams p(MakeNavigateParams());
406 p.disposition = NEW_POPUP;
407 p.extension_app_id = "extensionappid";
408 p.window_bounds = gfx::Rect(0, 0, 200, 200);
[email protected]f112b0f2011-05-26 01:53:52409 // Wait for new popup to to load and gain focus.
[email protected]ddddfda2011-07-14 23:19:39410 ui_test_utils::NavigateToURL(&p);
[email protected]f112b0f2011-05-26 01:53:52411
412 // Navigate() should have opened a new, focused popup window.
413 EXPECT_NE(browser(), p.browser);
414 EXPECT_TRUE(p.browser->is_type_popup());
415 EXPECT_TRUE(p.browser->is_app());
416
417 // We should have two windows, the browser() provided by the framework and the
418 // new popup window.
419 EXPECT_EQ(2u, BrowserList::size());
420 EXPECT_EQ(1, browser()->tab_count());
421 EXPECT_EQ(1, p.browser->tab_count());
422}
423
424// This test verifies that navigating with WindowOpenDisposition = NEW_POPUP
[email protected]300d1e52011-01-19 23:57:57425// from a normal popup results in a new Browser with TYPE_POPUP.
426IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_NewPopupFromPopup) {
427 // Open a popup.
428 browser::NavigateParams p1(MakeNavigateParams());
429 p1.disposition = NEW_POPUP;
[email protected]588300d2011-04-28 21:06:35430 p1.window_bounds = gfx::Rect(0, 0, 200, 200);
[email protected]300d1e52011-01-19 23:57:57431 browser::Navigate(&p1);
432 // Open another popup.
433 browser::NavigateParams p2(MakeNavigateParams(p1.browser));
434 p2.disposition = NEW_POPUP;
[email protected]588300d2011-04-28 21:06:35435 p2.window_bounds = gfx::Rect(0, 0, 200, 200);
[email protected]300d1e52011-01-19 23:57:57436 browser::Navigate(&p2);
437
438 // Navigate() should have opened a new normal popup window.
439 EXPECT_NE(p1.browser, p2.browser);
[email protected]b35b26b32011-05-05 20:35:14440 EXPECT_TRUE(p2.browser->is_type_popup());
441 EXPECT_FALSE(p2.browser->is_app());
[email protected]300d1e52011-01-19 23:57:57442
443 // We should have three windows, the browser() provided by the framework,
444 // the first popup window, and the second popup window.
445 EXPECT_EQ(3u, BrowserList::size());
446 EXPECT_EQ(1, browser()->tab_count());
447 EXPECT_EQ(1, p1.browser->tab_count());
448 EXPECT_EQ(1, p2.browser->tab_count());
449}
450
451// This test verifies that navigating with WindowOpenDisposition = NEW_POPUP
[email protected]a1feae52010-10-11 22:14:45452// from an app frame results in a new Browser with TYPE_APP_POPUP.
453IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
454 Disposition_NewPopupFromAppWindow) {
[email protected]b35b26b32011-05-05 20:35:14455 Browser* app_browser = CreateEmptyBrowserForApp(Browser::TYPE_TABBED,
456 browser()->profile());
[email protected]a1feae52010-10-11 22:14:45457 browser::NavigateParams p(MakeNavigateParams(app_browser));
458 p.disposition = NEW_POPUP;
[email protected]588300d2011-04-28 21:06:35459 p.window_bounds = gfx::Rect(0, 0, 200, 200);
[email protected]19d9f3a2010-10-14 21:49:36460 browser::Navigate(&p);
[email protected]a1feae52010-10-11 22:14:45461
462 // Navigate() should have opened a new popup app window.
463 EXPECT_NE(app_browser, p.browser);
464 EXPECT_NE(browser(), p.browser);
[email protected]b35b26b32011-05-05 20:35:14465 EXPECT_TRUE(p.browser->is_type_popup());
466 EXPECT_TRUE(p.browser->is_app());
[email protected]a1feae52010-10-11 22:14:45467
468 // We should now have three windows, the app window, the app popup it created,
469 // and the original browser() provided by the framework.
470 EXPECT_EQ(3u, BrowserList::size());
471 EXPECT_EQ(1, browser()->tab_count());
472 EXPECT_EQ(1, app_browser->tab_count());
473 EXPECT_EQ(1, p.browser->tab_count());
474}
475
476// This test verifies that navigating with WindowOpenDisposition = NEW_POPUP
[email protected]300d1e52011-01-19 23:57:57477// from an app popup results in a new Browser also of TYPE_APP_POPUP.
478IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
479 Disposition_NewPopupFromAppPopup) {
[email protected]b35b26b32011-05-05 20:35:14480 Browser* app_browser = CreateEmptyBrowserForApp(Browser::TYPE_TABBED,
481 browser()->profile());
[email protected]300d1e52011-01-19 23:57:57482 // Open an app popup.
483 browser::NavigateParams p1(MakeNavigateParams(app_browser));
484 p1.disposition = NEW_POPUP;
[email protected]588300d2011-04-28 21:06:35485 p1.window_bounds = gfx::Rect(0, 0, 200, 200);
[email protected]300d1e52011-01-19 23:57:57486 browser::Navigate(&p1);
487 // Now open another app popup.
488 browser::NavigateParams p2(MakeNavigateParams(p1.browser));
489 p2.disposition = NEW_POPUP;
[email protected]588300d2011-04-28 21:06:35490 p2.window_bounds = gfx::Rect(0, 0, 200, 200);
[email protected]300d1e52011-01-19 23:57:57491 browser::Navigate(&p2);
492
493 // Navigate() should have opened a new popup app window.
494 EXPECT_NE(browser(), p1.browser);
495 EXPECT_NE(p1.browser, p2.browser);
[email protected]b35b26b32011-05-05 20:35:14496 EXPECT_TRUE(p2.browser->is_type_popup());
497 EXPECT_TRUE(p2.browser->is_app());
[email protected]300d1e52011-01-19 23:57:57498
499 // We should now have four windows, the app window, the first app popup,
500 // the second app popup, and the original browser() provided by the framework.
501 EXPECT_EQ(4u, BrowserList::size());
502 EXPECT_EQ(1, browser()->tab_count());
503 EXPECT_EQ(1, app_browser->tab_count());
504 EXPECT_EQ(1, p1.browser->tab_count());
505 EXPECT_EQ(1, p2.browser->tab_count());
506}
507
508// This test verifies that navigating with WindowOpenDisposition = NEW_POPUP
[email protected]a1feae52010-10-11 22:14:45509// from an extension app tab results in a new Browser with TYPE_APP_POPUP.
510IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
511 Disposition_NewPopupFromExtensionApp) {
512 // TODO(beng): TBD.
513}
514
[email protected]7d329992011-04-15 18:20:02515// This test verifies that navigating with window_action = SHOW_WINDOW_INACTIVE
516// does not focus a new new popup window.
517IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_NewPopupUnfocused) {
518 browser::NavigateParams p(MakeNavigateParams());
519 p.disposition = NEW_POPUP;
[email protected]588300d2011-04-28 21:06:35520 p.window_bounds = gfx::Rect(0, 0, 200, 200);
[email protected]7d329992011-04-15 18:20:02521 p.window_action = browser::NavigateParams::SHOW_WINDOW_INACTIVE;
[email protected]7d329992011-04-15 18:20:02522 // Wait for new popup to load (and gain focus if the test fails).
[email protected]ddddfda2011-07-14 23:19:39523 ui_test_utils::NavigateToURL(&p);
[email protected]7d329992011-04-15 18:20:02524
525 // Navigate() should have opened a new, unfocused, popup window.
526 EXPECT_NE(browser(), p.browser);
527 EXPECT_EQ(Browser::TYPE_POPUP, p.browser->type());
[email protected]9db263a2011-04-15 20:53:47528#if 0
529// TODO(stevenjb): Enable this test. See: crbug.com/79493
[email protected]7d329992011-04-15 18:20:02530 EXPECT_FALSE(p.browser->window()->IsActive());
[email protected]7d329992011-04-15 18:20:02531#endif
[email protected]9db263a2011-04-15 20:53:47532}
[email protected]7d329992011-04-15 18:20:02533
[email protected]a1feae52010-10-11 22:14:45534// This test verifies that navigating with WindowOpenDisposition = NEW_WINDOW
535// always opens a new window.
536IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_NewWindow) {
537 browser::NavigateParams p(MakeNavigateParams());
538 p.disposition = NEW_WINDOW;
[email protected]19d9f3a2010-10-14 21:49:36539 browser::Navigate(&p);
[email protected]a1feae52010-10-11 22:14:45540
541 // Navigate() should have opened a new toplevel window.
542 EXPECT_NE(browser(), p.browser);
[email protected]b35b26b32011-05-05 20:35:14543 EXPECT_TRUE(p.browser->is_type_tabbed());
[email protected]a1feae52010-10-11 22:14:45544
545 // We should now have two windows, the browser() provided by the framework and
546 // the new normal window.
547 EXPECT_EQ(2u, BrowserList::size());
548 EXPECT_EQ(1, browser()->tab_count());
549 EXPECT_EQ(1, p.browser->tab_count());
550}
551
552// This test verifies that navigating with WindowOpenDisposition = INCOGNITO
553// opens a new incognito window if no existing incognito window is present.
554IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_Incognito) {
555 browser::NavigateParams p(MakeNavigateParams());
556 p.disposition = OFF_THE_RECORD;
[email protected]19d9f3a2010-10-14 21:49:36557 browser::Navigate(&p);
[email protected]a1feae52010-10-11 22:14:45558
559 // Navigate() should have opened a new toplevel incognito window.
560 EXPECT_NE(browser(), p.browser);
561 EXPECT_EQ(browser()->profile()->GetOffTheRecordProfile(),
562 p.browser->profile());
563
[email protected]d7ff3592010-11-30 21:50:46564 // |source_contents| should be set to NULL because the profile for the new
565 // page is different from the originating page.
566 EXPECT_EQ(NULL, p.source_contents);
567
[email protected]a1feae52010-10-11 22:14:45568 // We should now have two windows, the browser() provided by the framework and
569 // the new incognito window.
570 EXPECT_EQ(2u, BrowserList::size());
571 EXPECT_EQ(1, browser()->tab_count());
572 EXPECT_EQ(1, p.browser->tab_count());
573}
574
575// This test verifies that navigating with WindowOpenDisposition = INCOGNITO
576// reuses an existing incognito window when possible.
577IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_IncognitoRefocus) {
578 Browser* incognito_browser =
[email protected]b35b26b32011-05-05 20:35:14579 CreateEmptyBrowserForType(Browser::TYPE_TABBED,
[email protected]a1feae52010-10-11 22:14:45580 browser()->profile()->GetOffTheRecordProfile());
581 browser::NavigateParams p(MakeNavigateParams());
582 p.disposition = OFF_THE_RECORD;
[email protected]19d9f3a2010-10-14 21:49:36583 browser::Navigate(&p);
[email protected]a1feae52010-10-11 22:14:45584
585 // Navigate() should have opened a new tab in the existing incognito window.
586 EXPECT_NE(browser(), p.browser);
587 EXPECT_EQ(p.browser, incognito_browser);
588
589 // We should now have two windows, the browser() provided by the framework and
590 // the incognito window we opened earlier.
591 EXPECT_EQ(2u, BrowserList::size());
592 EXPECT_EQ(1, browser()->tab_count());
593 EXPECT_EQ(2, incognito_browser->tab_count());
594}
595
596// This test verifies that no navigation action occurs when
597// WindowOpenDisposition = SUPPRESS_OPEN.
598IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_SuppressOpen) {
599 RunSuppressTest(SUPPRESS_OPEN);
600}
601
602// This test verifies that no navigation action occurs when
603// WindowOpenDisposition = SAVE_TO_DISK.
604IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_SaveToDisk) {
605 RunSuppressTest(SAVE_TO_DISK);
606}
607
608// This test verifies that no navigation action occurs when
609// WindowOpenDisposition = IGNORE_ACTION.
610IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_IgnoreAction) {
611 RunSuppressTest(IGNORE_ACTION);
612}
613
614// This tests adding a foreground tab with a predefined TabContents.
615IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, TargetContents_ForegroundTab) {
616 browser::NavigateParams p(MakeNavigateParams());
617 p.disposition = NEW_FOREGROUND_TAB;
618 p.target_contents = CreateTabContents();
[email protected]19d9f3a2010-10-14 21:49:36619 browser::Navigate(&p);
[email protected]a1feae52010-10-11 22:14:45620
621 // Navigate() should have opened the contents in a new foreground in the
622 // current Browser.
623 EXPECT_EQ(browser(), p.browser);
[email protected]3c9e1872010-11-18 16:17:49624 EXPECT_EQ(browser()->GetSelectedTabContentsWrapper(), p.target_contents);
[email protected]a1feae52010-10-11 22:14:45625
626 // We should have one window, with two tabs.
627 EXPECT_EQ(1u, BrowserList::size());
628 EXPECT_EQ(2, browser()->tab_count());
629}
630
631#if defined(OS_WIN)
632// This tests adding a popup with a predefined TabContents.
[email protected]76edb672011-03-04 21:48:39633IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, DISABLED_TargetContents_Popup) {
[email protected]a1feae52010-10-11 22:14:45634 browser::NavigateParams p(MakeNavigateParams());
635 p.disposition = NEW_POPUP;
636 p.target_contents = CreateTabContents();
637 p.window_bounds = gfx::Rect(10, 10, 500, 500);
[email protected]19d9f3a2010-10-14 21:49:36638 browser::Navigate(&p);
[email protected]a1feae52010-10-11 22:14:45639
640 // Navigate() should have opened a new popup window.
641 EXPECT_NE(browser(), p.browser);
[email protected]b35b26b32011-05-05 20:35:14642 EXPECT_TRUE(p.browser->is_type_popup());
643 EXPECT_FALSE(p.browser->is_app());
[email protected]a1feae52010-10-11 22:14:45644
645 // The web platform is weird. The window bounds specified in
646 // |p.window_bounds| are used as follows:
647 // - the origin is used to position the window
648 // - the size is used to size the TabContents of the window.
649 // As such the position of the resulting window will always match
650 // p.window_bounds.origin(), but its size will not. We need to match
651 // the size against the selected tab's view's container size.
652 // Only Windows positions the window according to |p.window_bounds.origin()| -
653 // on Mac the window is offset from the opener and on Linux it always opens
654 // at 0,0.
655 EXPECT_EQ(p.window_bounds.origin(),
656 p.browser->window()->GetRestoredBounds().origin());
657 // All platforms should respect size however provided width > 400 (Mac has a
658 // minimum window width of 400).
659 EXPECT_EQ(p.window_bounds.size(),
[email protected]83ff91c2012-01-05 20:54:13660 p.target_contents->web_contents()->GetView()->GetContainerSize());
[email protected]a1feae52010-10-11 22:14:45661
662 // We should have two windows, the new popup and the browser() provided by the
663 // framework.
664 EXPECT_EQ(2u, BrowserList::size());
665 EXPECT_EQ(1, browser()->tab_count());
666 EXPECT_EQ(1, p.browser->tab_count());
667}
668#endif
669
670// This tests adding a tab at a specific index.
671IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Tabstrip_InsertAtIndex) {
672 // This is not meant to be a comprehensive test of whether or not the tab
673 // implementation of the browser observes the insertion index. That is
674 // covered by the unit tests for TabStripModel. This merely verifies that
675 // insertion index preference is reflected in common cases.
676 browser::NavigateParams p(MakeNavigateParams());
677 p.disposition = NEW_FOREGROUND_TAB;
678 p.tabstrip_index = 0;
679 p.tabstrip_add_types = TabStripModel::ADD_FORCE_INDEX;
[email protected]19d9f3a2010-10-14 21:49:36680 browser::Navigate(&p);
[email protected]a1feae52010-10-11 22:14:45681
682 // Navigate() should have inserted a new tab at slot 0 in the tabstrip.
683 EXPECT_EQ(browser(), p.browser);
684 EXPECT_EQ(0, browser()->tabstrip_model()->GetIndexOfTabContents(
[email protected]3c9e1872010-11-18 16:17:49685 static_cast<const TabContentsWrapper*>(p.target_contents)));
[email protected]a1feae52010-10-11 22:14:45686
687 // We should have one window - the browser() provided by the framework.
688 EXPECT_EQ(1u, BrowserList::size());
689 EXPECT_EQ(2, browser()->tab_count());
690}
691
[email protected]2dd85482010-11-06 01:56:47692// This test verifies that constructing params with a NULL browser has
693// the same result as navigating to a new foreground tab in the (only)
694// active browser. Tests are the same as for Disposition_NewForegroundTab.
695IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, NullBrowser_NewForegroundTab) {
[email protected]4ca15302012-01-03 05:53:20696 WebContents* old_contents = browser()->GetSelectedWebContents();
[email protected]2dd85482010-11-06 01:56:47697 // Navigate with a NULL browser.
698 browser::NavigateParams p(MakeNavigateParams(NULL));
699 p.disposition = NEW_FOREGROUND_TAB;
700 p.profile = browser()->profile();
701 browser::Navigate(&p);
702
703 // Navigate() should have found browser() and create a new tab.
704 EXPECT_EQ(browser(), p.browser);
[email protected]4ca15302012-01-03 05:53:20705 EXPECT_NE(old_contents, browser()->GetSelectedWebContents());
[email protected]3c9e1872010-11-18 16:17:49706 EXPECT_EQ(browser()->GetSelectedTabContentsWrapper(), p.target_contents);
[email protected]2dd85482010-11-06 01:56:47707 EXPECT_EQ(2, browser()->tab_count());
708}
709
710// This test verifies that constructing params with a NULL browser and
711// a specific profile matches the specified profile.
[email protected]c8a31a72011-09-30 01:53:32712IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, NullBrowser_MatchProfile) {
[email protected]2dd85482010-11-06 01:56:47713 // Create a new browser with using the incognito profile.
714 Browser* incognito =
715 Browser::Create(browser()->profile()->GetOffTheRecordProfile());
716
717 // Navigate with a NULL browser and the incognito profile.
718 browser::NavigateParams p(MakeNavigateParams(NULL));
719 p.disposition = NEW_FOREGROUND_TAB;
720 p.profile = incognito->profile();
721 browser::Navigate(&p);
722
723 // Navigate() should have found incognito, not browser().
724 EXPECT_EQ(incognito, p.browser);
[email protected]3c9e1872010-11-18 16:17:49725 EXPECT_EQ(incognito->GetSelectedTabContentsWrapper(), p.target_contents);
[email protected]2dd85482010-11-06 01:56:47726 EXPECT_EQ(1, incognito->tab_count());
727}
728
729// This test verifies that constructing params with a NULL browser and
730// disposition = NEW_WINDOW always opens exactly one new window.
731IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, NullBrowser_NewWindow) {
732 browser::NavigateParams p(MakeNavigateParams(NULL));
733 p.disposition = NEW_WINDOW;
734 p.profile = browser()->profile();
735 browser::Navigate(&p);
736
737 // Navigate() should have created a new browser.
738 EXPECT_NE(browser(), p.browser);
[email protected]b35b26b32011-05-05 20:35:14739 EXPECT_TRUE( p.browser->is_type_tabbed());
[email protected]2dd85482010-11-06 01:56:47740
741 // We should now have two windows, the browser() provided by the framework and
742 // the new normal window.
743 EXPECT_EQ(2u, BrowserList::size());
744 EXPECT_EQ(1, browser()->tab_count());
745 EXPECT_EQ(1, p.browser->tab_count());
746}
747
[email protected]bb89e7482010-11-17 18:27:04748// This test verifies that constructing params with disposition = SINGLETON_TAB
[email protected]fee320542011-03-02 01:30:49749// and IGNORE_AND_NAVIGATE opens a new tab navigated to the specified URL if
[email protected]67ed83e2011-01-07 22:54:00750// no previous tab with that URL (minus the path) exists.
[email protected]bb89e7482010-11-17 18:27:04751IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
752 Disposition_SingletonTabNew_IgnorePath) {
[email protected]2905f742011-10-13 03:51:58753 browser()->AddSelectedTabWithURL(
754 GetGoogleURL(), content::PAGE_TRANSITION_LINK);
[email protected]bb89e7482010-11-17 18:27:04755
756 // We should have one browser with 2 tabs, the 2nd selected.
757 EXPECT_EQ(1u, BrowserList::size());
758 EXPECT_EQ(2, browser()->tab_count());
[email protected]1ea49d52011-04-12 17:44:44759 EXPECT_EQ(1, browser()->active_index());
[email protected]bb89e7482010-11-17 18:27:04760
761 // Navigate to a new singleton tab with a sub-page.
762 browser::NavigateParams p(MakeNavigateParams());
763 p.disposition = SINGLETON_TAB;
[email protected]a048ad22012-03-23 04:26:56764 p.url = GetContentSettingsURL();
[email protected]7d329992011-04-15 18:20:02765 p.window_action = browser::NavigateParams::SHOW_WINDOW;
[email protected]fee320542011-03-02 01:30:49766 p.path_behavior = browser::NavigateParams::IGNORE_AND_NAVIGATE;
[email protected]bb89e7482010-11-17 18:27:04767 browser::Navigate(&p);
768
769 // The last tab should now be selected and navigated to the sub-page of the
770 // URL.
771 EXPECT_EQ(browser(), p.browser);
772 EXPECT_EQ(3, browser()->tab_count());
[email protected]1ea49d52011-04-12 17:44:44773 EXPECT_EQ(2, browser()->active_index());
[email protected]a048ad22012-03-23 04:26:56774 EXPECT_EQ(GetContentSettingsURL(),
[email protected]4ca15302012-01-03 05:53:20775 browser()->GetSelectedWebContents()->GetURL());
[email protected]bb89e7482010-11-17 18:27:04776}
777
778// This test verifies that constructing params with disposition = SINGLETON_TAB
[email protected]fee320542011-03-02 01:30:49779// and IGNORE_AND_NAVIGATE opens an existing tab with the matching URL (minus
[email protected]bb89e7482010-11-17 18:27:04780// the path) which is navigated to the specified URL.
781IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
782 Disposition_SingletonTabExisting_IgnorePath) {
[email protected]ddddfda2011-07-14 23:19:39783 GURL singleton_url1(GetSettingsURL());
[email protected]2905f742011-10-13 03:51:58784 browser()->AddSelectedTabWithURL(
785 singleton_url1, content::PAGE_TRANSITION_LINK);
786 browser()->AddSelectedTabWithURL(
787 GetGoogleURL(), content::PAGE_TRANSITION_LINK);
[email protected]bb89e7482010-11-17 18:27:04788
789 // We should have one browser with 3 tabs, the 3rd selected.
790 EXPECT_EQ(1u, BrowserList::size());
791 EXPECT_EQ(3, browser()->tab_count());
[email protected]1ea49d52011-04-12 17:44:44792 EXPECT_EQ(2, browser()->active_index());
[email protected]bb89e7482010-11-17 18:27:04793
794 // Navigate to singleton_url1.
795 browser::NavigateParams p(MakeNavigateParams());
796 p.disposition = SINGLETON_TAB;
[email protected]a048ad22012-03-23 04:26:56797 p.url = GetContentSettingsURL();
[email protected]7d329992011-04-15 18:20:02798 p.window_action = browser::NavigateParams::SHOW_WINDOW;
[email protected]fee320542011-03-02 01:30:49799 p.path_behavior = browser::NavigateParams::IGNORE_AND_NAVIGATE;
[email protected]bb89e7482010-11-17 18:27:04800 browser::Navigate(&p);
801
802 // The middle tab should now be selected and navigated to the sub-page of the
803 // URL.
804 EXPECT_EQ(browser(), p.browser);
805 EXPECT_EQ(3, browser()->tab_count());
[email protected]1ea49d52011-04-12 17:44:44806 EXPECT_EQ(1, browser()->active_index());
[email protected]a048ad22012-03-23 04:26:56807 EXPECT_EQ(GetContentSettingsURL(),
[email protected]4ca15302012-01-03 05:53:20808 browser()->GetSelectedWebContents()->GetURL());
[email protected]bb89e7482010-11-17 18:27:04809}
810
811// This test verifies that constructing params with disposition = SINGLETON_TAB
[email protected]fee320542011-03-02 01:30:49812// and IGNORE_AND_NAVIGATE opens an existing tab with the matching URL (minus
[email protected]bb89e7482010-11-17 18:27:04813// the path) which is navigated to the specified URL.
814IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
815 Disposition_SingletonTabExistingSubPath_IgnorePath) {
[email protected]a048ad22012-03-23 04:26:56816 GURL singleton_url1(GetContentSettingsURL());
[email protected]2905f742011-10-13 03:51:58817 browser()->AddSelectedTabWithURL(
818 singleton_url1, content::PAGE_TRANSITION_LINK);
819 browser()->AddSelectedTabWithURL(
820 GetGoogleURL(), content::PAGE_TRANSITION_LINK);
[email protected]bb89e7482010-11-17 18:27:04821
822 // We should have one browser with 3 tabs, the 3rd selected.
823 EXPECT_EQ(1u, BrowserList::size());
824 EXPECT_EQ(3, browser()->tab_count());
[email protected]1ea49d52011-04-12 17:44:44825 EXPECT_EQ(2, browser()->active_index());
[email protected]bb89e7482010-11-17 18:27:04826
827 // Navigate to singleton_url1.
828 browser::NavigateParams p(MakeNavigateParams());
829 p.disposition = SINGLETON_TAB;
[email protected]a048ad22012-03-23 04:26:56830 p.url = GetClearBrowsingDataURL();
[email protected]7d329992011-04-15 18:20:02831 p.window_action = browser::NavigateParams::SHOW_WINDOW;
[email protected]fee320542011-03-02 01:30:49832 p.path_behavior = browser::NavigateParams::IGNORE_AND_NAVIGATE;
[email protected]bb89e7482010-11-17 18:27:04833 browser::Navigate(&p);
834
835 // The middle tab should now be selected and navigated to the sub-page of the
836 // URL.
837 EXPECT_EQ(browser(), p.browser);
838 EXPECT_EQ(3, browser()->tab_count());
[email protected]1ea49d52011-04-12 17:44:44839 EXPECT_EQ(1, browser()->active_index());
[email protected]a048ad22012-03-23 04:26:56840 EXPECT_EQ(GetClearBrowsingDataURL(),
[email protected]4ca15302012-01-03 05:53:20841 browser()->GetSelectedWebContents()->GetURL());
[email protected]bb89e7482010-11-17 18:27:04842}
[email protected]2dd85482010-11-06 01:56:47843
[email protected]637b3442011-01-10 23:31:48844// This test verifies that constructing params with disposition = SINGLETON_TAB
[email protected]fee320542011-03-02 01:30:49845// and IGNORE_AND_STAY_PUT opens an existing tab with the matching URL (minus
846// the path).
847IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
848 Disposition_SingletonTabExistingSubPath_IgnorePath2) {
[email protected]a048ad22012-03-23 04:26:56849 GURL singleton_url1(GetContentSettingsURL());
[email protected]2905f742011-10-13 03:51:58850 browser()->AddSelectedTabWithURL(
851 singleton_url1, content::PAGE_TRANSITION_LINK);
852 browser()->AddSelectedTabWithURL(
853 GetGoogleURL(), content::PAGE_TRANSITION_LINK);
[email protected]fee320542011-03-02 01:30:49854
855 // We should have one browser with 3 tabs, the 3rd selected.
856 EXPECT_EQ(1u, BrowserList::size());
857 EXPECT_EQ(3, browser()->tab_count());
[email protected]1ea49d52011-04-12 17:44:44858 EXPECT_EQ(2, browser()->active_index());
[email protected]fee320542011-03-02 01:30:49859
860 // Navigate to singleton_url1.
861 browser::NavigateParams p(MakeNavigateParams());
862 p.disposition = SINGLETON_TAB;
[email protected]a048ad22012-03-23 04:26:56863 p.url = GetClearBrowsingDataURL();
[email protected]7d329992011-04-15 18:20:02864 p.window_action = browser::NavigateParams::SHOW_WINDOW;
[email protected]fee320542011-03-02 01:30:49865 p.path_behavior = browser::NavigateParams::IGNORE_AND_STAY_PUT;
866 browser::Navigate(&p);
867
868 // The middle tab should now be selected.
869 EXPECT_EQ(browser(), p.browser);
870 EXPECT_EQ(3, browser()->tab_count());
[email protected]1ea49d52011-04-12 17:44:44871 EXPECT_EQ(1, browser()->active_index());
[email protected]fee320542011-03-02 01:30:49872 EXPECT_EQ(singleton_url1,
[email protected]4ca15302012-01-03 05:53:20873 browser()->GetSelectedWebContents()->GetURL());
[email protected]fee320542011-03-02 01:30:49874}
875
876// This test verifies that constructing params with disposition = SINGLETON_TAB
877// and IGNORE_AND_NAVIGATE will update the current tab's URL if the currently
[email protected]637b3442011-01-10 23:31:48878// selected tab is a match but has a different path.
879IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
880 Disposition_SingletonTabFocused_IgnorePath) {
[email protected]a048ad22012-03-23 04:26:56881 GURL singleton_url_current(GetContentSettingsURL());
[email protected]2905f742011-10-13 03:51:58882 browser()->AddSelectedTabWithURL(
883 singleton_url_current, content::PAGE_TRANSITION_LINK);
[email protected]637b3442011-01-10 23:31:48884
885 // We should have one browser with 2 tabs, the 2nd selected.
886 EXPECT_EQ(1u, BrowserList::size());
887 EXPECT_EQ(2, browser()->tab_count());
[email protected]1ea49d52011-04-12 17:44:44888 EXPECT_EQ(1, browser()->active_index());
[email protected]637b3442011-01-10 23:31:48889
890 // Navigate to a different settings path.
[email protected]a048ad22012-03-23 04:26:56891 GURL singleton_url_target(GetClearBrowsingDataURL());
[email protected]637b3442011-01-10 23:31:48892 browser::NavigateParams p(MakeNavigateParams());
893 p.disposition = SINGLETON_TAB;
894 p.url = singleton_url_target;
[email protected]7d329992011-04-15 18:20:02895 p.window_action = browser::NavigateParams::SHOW_WINDOW;
[email protected]fee320542011-03-02 01:30:49896 p.path_behavior = browser::NavigateParams::IGNORE_AND_NAVIGATE;
[email protected]637b3442011-01-10 23:31:48897 browser::Navigate(&p);
898
899 // The second tab should still be selected, but navigated to the new path.
900 EXPECT_EQ(browser(), p.browser);
901 EXPECT_EQ(2, browser()->tab_count());
[email protected]1ea49d52011-04-12 17:44:44902 EXPECT_EQ(1, browser()->active_index());
[email protected]637b3442011-01-10 23:31:48903 EXPECT_EQ(singleton_url_target,
[email protected]4ca15302012-01-03 05:53:20904 browser()->GetSelectedWebContents()->GetURL());
[email protected]637b3442011-01-10 23:31:48905}
906
[email protected]07afd7c2011-02-17 10:07:11907// This test verifies that constructing params with disposition = SINGLETON_TAB
[email protected]fee320542011-03-02 01:30:49908// and IGNORE_AND_NAVIGATE will open an existing matching tab with a different
909// query.
[email protected]07afd7c2011-02-17 10:07:11910IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
911 Disposition_SingletonTabExisting_IgnoreQuery) {
912 int initial_tab_count = browser()->tab_count();
913 GURL singleton_url_current("chrome://settings/internet");
[email protected]2905f742011-10-13 03:51:58914 browser()->AddSelectedTabWithURL(
915 singleton_url_current, content::PAGE_TRANSITION_LINK);
[email protected]07afd7c2011-02-17 10:07:11916
917 EXPECT_EQ(initial_tab_count + 1, browser()->tab_count());
[email protected]1ea49d52011-04-12 17:44:44918 EXPECT_EQ(initial_tab_count, browser()->active_index());
[email protected]07afd7c2011-02-17 10:07:11919
920 // Navigate to a different settings path.
921 GURL singleton_url_target(
922 "chrome://settings/internet?"
923 "servicePath=/profile/ethernet_00aa00aa00aa&networkType=1");
924 browser::NavigateParams p(MakeNavigateParams());
925 p.disposition = SINGLETON_TAB;
926 p.url = singleton_url_target;
[email protected]7d329992011-04-15 18:20:02927 p.window_action = browser::NavigateParams::SHOW_WINDOW;
[email protected]fee320542011-03-02 01:30:49928 p.path_behavior = browser::NavigateParams::IGNORE_AND_NAVIGATE;
[email protected]07afd7c2011-02-17 10:07:11929 browser::Navigate(&p);
930
931 // Last tab should still be selected.
932 EXPECT_EQ(browser(), p.browser);
933 EXPECT_EQ(initial_tab_count + 1, browser()->tab_count());
[email protected]1ea49d52011-04-12 17:44:44934 EXPECT_EQ(initial_tab_count, browser()->active_index());
[email protected]07afd7c2011-02-17 10:07:11935}
936
[email protected]bd817c22011-02-09 08:16:46937// This test verifies that the settings page isn't opened in the incognito
938// window.
[email protected]a048ad22012-03-23 04:26:56939// Disabled until fixed for uber settings: http://crbug.com/111243
[email protected]bd817c22011-02-09 08:16:46940IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
[email protected]a048ad22012-03-23 04:26:56941 DISABLED_Disposition_Settings_UseNonIncognitoWindow) {
[email protected]fc0ed302011-11-29 23:17:19942 RunUseNonIncognitoWindowTest(GetSettingsURL());
[email protected]bd817c22011-02-09 08:16:46943}
944
[email protected]82404cd2011-07-12 19:55:14945// This test verifies that the settings page isn't opened in the incognito
946// window from a non-incognito window (bookmark open-in-incognito trigger).
[email protected]a048ad22012-03-23 04:26:56947// Disabled until fixed for uber settings: http://crbug.com/111243
[email protected]82404cd2011-07-12 19:55:14948IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
[email protected]a048ad22012-03-23 04:26:56949 DISABLED_Disposition_Settings_UseNonIncognitoWindowForBookmark) {
950 browser::NavigateParams params(browser(), GetSettingsURL(),
[email protected]2905f742011-10-13 03:51:58951 content::PAGE_TRANSITION_AUTO_BOOKMARK);
[email protected]82404cd2011-07-12 19:55:14952 params.disposition = OFF_THE_RECORD;
953 {
954 ui_test_utils::WindowedNotificationObserver observer(
[email protected]ad50def52011-10-19 23:17:07955 content::NOTIFICATION_LOAD_STOP,
956 content::NotificationService::AllSources());
[email protected]82404cd2011-07-12 19:55:14957 browser::Navigate(&params);
958 observer.Wait();
959 }
960
961 EXPECT_EQ(1u, BrowserList::size());
[email protected]a048ad22012-03-23 04:26:56962 EXPECT_EQ(GetSettingsURL(), browser()->GetSelectedWebContents()->GetURL());
[email protected]82404cd2011-07-12 19:55:14963}
964
[email protected]93ad8e1c2011-11-08 21:34:05965// Settings page is expected to always open in normal mode regardless
966// of whether the user is trying to open it in incognito mode or not.
967// This test verifies that if incognito mode is forced (by policy), settings
968// page doesn't open at all.
[email protected]a048ad22012-03-23 04:26:56969// Disabled until fixed for uber settings: http://crbug.com/111243
[email protected]93ad8e1c2011-11-08 21:34:05970IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
[email protected]a048ad22012-03-23 04:26:56971 DISABLED_Disposition_Settings_DoNothingIfIncognitoIsForced) {
[email protected]fc0ed302011-11-29 23:17:19972 RunDoNothingIfIncognitoIsForcedTest(GetSettingsURL());
[email protected]93ad8e1c2011-11-08 21:34:05973}
974
[email protected]bd817c22011-02-09 08:16:46975// This test verifies that the bookmarks page isn't opened in the incognito
976// window.
977IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
978 Disposition_Bookmarks_UseNonIncognitoWindow) {
[email protected]fc0ed302011-11-29 23:17:19979 RunUseNonIncognitoWindowTest(GURL(chrome::kChromeUIBookmarksURL));
[email protected]bd817c22011-02-09 08:16:46980}
981
[email protected]93ad8e1c2011-11-08 21:34:05982// Bookmark manager is expected to always open in normal mode regardless
983// of whether the user is trying to open it in incognito mode or not.
984// This test verifies that if incognito mode is forced (by policy), bookmark
985// manager doesn't open at all.
986IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
987 Disposition_Bookmarks_DoNothingIfIncognitoIsForced) {
[email protected]fc0ed302011-11-29 23:17:19988 RunDoNothingIfIncognitoIsForcedTest(GURL(chrome::kChromeUIBookmarksURL));
989}
[email protected]93ad8e1c2011-11-08 21:34:05990
[email protected]fc0ed302011-11-29 23:17:19991// This test verifies that the sync promo page isn't opened in the incognito
992// window.
993IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
994 Disposition_SyncPromo_UseNonIncognitoWindow) {
995 RunUseNonIncognitoWindowTest(GURL(chrome::kChromeUISyncPromoURL));
996}
[email protected]93ad8e1c2011-11-08 21:34:05997
[email protected]fc0ed302011-11-29 23:17:19998// The Sync promo page is expected to always open in normal mode regardless of
999// whether the user is trying to open it in incognito mode or not. This test
1000// verifies that if incognito mode is forced (by policy), the sync promo page
1001// doesn't open at all.
1002IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
1003 Disposition_SyncPromo_DoNothingIfIncognitoIsForced) {
1004 RunDoNothingIfIncognitoIsForcedTest(GURL(chrome::kChromeUISyncPromoURL));
[email protected]93ad8e1c2011-11-08 21:34:051005}
1006
[email protected]7de53c62011-05-13 06:44:161007// This test makes sure a crashed singleton tab reloads from a new navigation.
1008IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
1009 NavigateToCrashedSingletonTab) {
[email protected]a048ad22012-03-23 04:26:561010 GURL singleton_url(GetContentSettingsURL());
[email protected]2905f742011-10-13 03:51:581011 TabContentsWrapper* wrapper = browser()->AddSelectedTabWithURL(
1012 singleton_url, content::PAGE_TRANSITION_LINK);
[email protected]83ff91c2012-01-05 20:54:131013 WebContents* web_contents = wrapper->web_contents();
[email protected]7de53c62011-05-13 06:44:161014
1015 // We should have one browser with 2 tabs, the 2nd selected.
1016 EXPECT_EQ(1u, BrowserList::size());
1017 EXPECT_EQ(2, browser()->tab_count());
1018 EXPECT_EQ(1, browser()->active_index());
1019
1020 // Kill the singleton tab.
[email protected]83ff91c2012-01-05 20:54:131021 web_contents->SetIsCrashed(base::TERMINATION_STATUS_PROCESS_CRASHED, -1);
1022 EXPECT_TRUE(web_contents->IsCrashed());
[email protected]7de53c62011-05-13 06:44:161023
1024 browser::NavigateParams p(MakeNavigateParams());
1025 p.disposition = SINGLETON_TAB;
1026 p.url = singleton_url;
1027 p.window_action = browser::NavigateParams::SHOW_WINDOW;
1028 p.path_behavior = browser::NavigateParams::IGNORE_AND_NAVIGATE;
[email protected]ddddfda2011-07-14 23:19:391029 ui_test_utils::NavigateToURL(&p);
[email protected]7de53c62011-05-13 06:44:161030
1031 // The tab should not be sad anymore.
[email protected]83ff91c2012-01-05 20:54:131032 EXPECT_FALSE(web_contents->IsCrashed());
[email protected]7de53c62011-05-13 06:44:161033}
1034
[email protected]fcca741b2011-06-17 22:46:371035IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
1036 NavigateFromDefaultToOptionsInSameTab) {
[email protected]ddddfda2011-07-14 23:19:391037 {
1038 ui_test_utils::WindowedNotificationObserver observer(
[email protected]ad50def52011-10-19 23:17:071039 content::NOTIFICATION_LOAD_STOP,
1040 content::NotificationService::AllSources());
[email protected]ddddfda2011-07-14 23:19:391041 browser()->OpenOptionsDialog();
1042 observer.Wait();
1043 }
[email protected]fcca741b2011-06-17 22:46:371044 EXPECT_EQ(1, browser()->tab_count());
[email protected]a048ad22012-03-23 04:26:561045 EXPECT_EQ(GetSettingsURL(), browser()->GetSelectedWebContents()->GetURL());
[email protected]fcca741b2011-06-17 22:46:371046}
1047
1048IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
1049 NavigateFromBlankToOptionsInSameTab) {
1050 browser::NavigateParams p(MakeNavigateParams());
[email protected]ddddfda2011-07-14 23:19:391051 p.url = GURL(chrome::kAboutBlankURL);
1052 ui_test_utils::NavigateToURL(&p);
[email protected]fcca741b2011-06-17 22:46:371053
[email protected]ddddfda2011-07-14 23:19:391054 {
1055 ui_test_utils::WindowedNotificationObserver observer(
[email protected]ad50def52011-10-19 23:17:071056 content::NOTIFICATION_LOAD_STOP,
1057 content::NotificationService::AllSources());
[email protected]ddddfda2011-07-14 23:19:391058 browser()->OpenOptionsDialog();
1059 observer.Wait();
1060 }
[email protected]fcca741b2011-06-17 22:46:371061 EXPECT_EQ(1, browser()->tab_count());
[email protected]a048ad22012-03-23 04:26:561062 EXPECT_EQ(GetSettingsURL(), browser()->GetSelectedWebContents()->GetURL());
[email protected]fcca741b2011-06-17 22:46:371063}
1064
1065IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
1066 NavigateFromNTPToOptionsInSameTab) {
1067 browser::NavigateParams p(MakeNavigateParams());
[email protected]ddddfda2011-07-14 23:19:391068 p.url = GURL(chrome::kChromeUINewTabURL);
1069 ui_test_utils::NavigateToURL(&p);
[email protected]fcca741b2011-06-17 22:46:371070 EXPECT_EQ(1, browser()->tab_count());
[email protected]ddddfda2011-07-14 23:19:391071 EXPECT_EQ(GURL(chrome::kChromeUINewTabURL),
[email protected]4ca15302012-01-03 05:53:201072 browser()->GetSelectedWebContents()->GetURL());
[email protected]fcca741b2011-06-17 22:46:371073
[email protected]ddddfda2011-07-14 23:19:391074 {
1075 ui_test_utils::WindowedNotificationObserver observer(
[email protected]ad50def52011-10-19 23:17:071076 content::NOTIFICATION_LOAD_STOP,
1077 content::NotificationService::AllSources());
[email protected]ddddfda2011-07-14 23:19:391078 browser()->OpenOptionsDialog();
1079 observer.Wait();
1080 }
[email protected]fcca741b2011-06-17 22:46:371081 EXPECT_EQ(1, browser()->tab_count());
[email protected]a048ad22012-03-23 04:26:561082 EXPECT_EQ(GetSettingsURL(), browser()->GetSelectedWebContents()->GetURL());
[email protected]fcca741b2011-06-17 22:46:371083}
1084
1085IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
1086 NavigateFromPageToOptionsInNewTab) {
1087 browser::NavigateParams p(MakeNavigateParams());
[email protected]ddddfda2011-07-14 23:19:391088 ui_test_utils::NavigateToURL(&p);
[email protected]4ca15302012-01-03 05:53:201089 EXPECT_EQ(GetGoogleURL(), browser()->GetSelectedWebContents()->GetURL());
[email protected]fcca741b2011-06-17 22:46:371090 EXPECT_EQ(1u, BrowserList::size());
1091 EXPECT_EQ(1, browser()->tab_count());
1092
[email protected]ddddfda2011-07-14 23:19:391093 {
1094 ui_test_utils::WindowedNotificationObserver observer(
[email protected]ad50def52011-10-19 23:17:071095 content::NOTIFICATION_LOAD_STOP,
1096 content::NotificationService::AllSources());
[email protected]ddddfda2011-07-14 23:19:391097 browser()->OpenOptionsDialog();
1098 observer.Wait();
1099 }
[email protected]fcca741b2011-06-17 22:46:371100 EXPECT_EQ(2, browser()->tab_count());
[email protected]a048ad22012-03-23 04:26:561101 EXPECT_EQ(GetSettingsURL(), browser()->GetSelectedWebContents()->GetURL());
[email protected]fcca741b2011-06-17 22:46:371102}
1103
1104IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
1105 NavigateFromNTPToOptionsSingleton) {
[email protected]ddddfda2011-07-14 23:19:391106 {
1107 ui_test_utils::WindowedNotificationObserver observer(
[email protected]ad50def52011-10-19 23:17:071108 content::NOTIFICATION_LOAD_STOP,
1109 content::NotificationService::AllSources());
[email protected]ddddfda2011-07-14 23:19:391110 browser()->OpenOptionsDialog();
1111 observer.Wait();
1112 }
[email protected]fcca741b2011-06-17 22:46:371113 EXPECT_EQ(1, browser()->tab_count());
1114
1115 browser()->NewTab();
1116 EXPECT_EQ(2, browser()->tab_count());
1117
[email protected]ddddfda2011-07-14 23:19:391118 {
1119 ui_test_utils::WindowedNotificationObserver observer(
[email protected]ad50def52011-10-19 23:17:071120 content::NOTIFICATION_LOAD_STOP,
1121 content::NotificationService::AllSources());
[email protected]ddddfda2011-07-14 23:19:391122 browser()->OpenOptionsDialog();
1123 observer.Wait();
1124 }
[email protected]fcca741b2011-06-17 22:46:371125 EXPECT_EQ(2, browser()->tab_count());
[email protected]a048ad22012-03-23 04:26:561126 EXPECT_EQ(GetSettingsURL(), browser()->GetSelectedWebContents()->GetURL());
[email protected]fcca741b2011-06-17 22:46:371127}
1128
1129IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
1130 NavigateFromNTPToOptionsPageInSameTab) {
[email protected]ddddfda2011-07-14 23:19:391131 {
1132 ui_test_utils::WindowedNotificationObserver observer(
[email protected]ad50def52011-10-19 23:17:071133 content::NOTIFICATION_LOAD_STOP,
1134 content::NotificationService::AllSources());
[email protected]a048ad22012-03-23 04:26:561135 browser()->OpenClearBrowsingDataDialog();
[email protected]ddddfda2011-07-14 23:19:391136 observer.Wait();
1137 }
[email protected]fcca741b2011-06-17 22:46:371138 EXPECT_EQ(1, browser()->tab_count());
[email protected]a048ad22012-03-23 04:26:561139 EXPECT_EQ(GetClearBrowsingDataURL(),
[email protected]4ca15302012-01-03 05:53:201140 browser()->GetSelectedWebContents()->GetURL());
[email protected]fcca741b2011-06-17 22:46:371141
1142 browser()->NewTab();
1143 EXPECT_EQ(2, browser()->tab_count());
1144
[email protected]ddddfda2011-07-14 23:19:391145 {
1146 ui_test_utils::WindowedNotificationObserver observer(
[email protected]ad50def52011-10-19 23:17:071147 content::NOTIFICATION_LOAD_STOP,
1148 content::NotificationService::AllSources());
[email protected]a048ad22012-03-23 04:26:561149 browser()->OpenClearBrowsingDataDialog();
[email protected]ddddfda2011-07-14 23:19:391150 observer.Wait();
1151 }
[email protected]fcca741b2011-06-17 22:46:371152 EXPECT_EQ(2, browser()->tab_count());
[email protected]a048ad22012-03-23 04:26:561153 EXPECT_EQ(GetClearBrowsingDataURL(),
[email protected]4ca15302012-01-03 05:53:201154 browser()->GetSelectedWebContents()->GetURL());
[email protected]fcca741b2011-06-17 22:46:371155}
1156
1157IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
1158 NavigateFromOtherTabToSingletonOptions) {
[email protected]ddddfda2011-07-14 23:19:391159 {
1160 ui_test_utils::WindowedNotificationObserver observer(
[email protected]ad50def52011-10-19 23:17:071161 content::NOTIFICATION_LOAD_STOP,
1162 content::NotificationService::AllSources());
[email protected]ddddfda2011-07-14 23:19:391163 browser()->OpenOptionsDialog();
1164 observer.Wait();
1165 }
1166 {
1167 ui_test_utils::WindowedNotificationObserver observer(
[email protected]ad50def52011-10-19 23:17:071168 content::NOTIFICATION_LOAD_STOP,
1169 content::NotificationService::AllSources());
[email protected]2905f742011-10-13 03:51:581170 browser()->AddSelectedTabWithURL(
1171 GetGoogleURL(), content::PAGE_TRANSITION_LINK);
[email protected]ddddfda2011-07-14 23:19:391172 observer.Wait();
1173 }
[email protected]fcca741b2011-06-17 22:46:371174
[email protected]ddddfda2011-07-14 23:19:391175 {
1176 ui_test_utils::WindowedNotificationObserver observer(
[email protected]ad50def52011-10-19 23:17:071177 content::NOTIFICATION_LOAD_STOP,
1178 content::NotificationService::AllSources());
[email protected]ddddfda2011-07-14 23:19:391179 browser()->OpenOptionsDialog();
1180 observer.Wait();
1181 }
[email protected]fcca741b2011-06-17 22:46:371182 EXPECT_EQ(2, browser()->tab_count());
[email protected]ddddfda2011-07-14 23:19:391183 EXPECT_EQ(GetSettingsURL(),
[email protected]a048ad22012-03-23 04:26:561184 browser()->GetSelectedWebContents()->GetURL());
[email protected]fcca741b2011-06-17 22:46:371185}
1186
[email protected]26c53e662011-07-09 02:21:021187// Tests that when a new tab is opened from the omnibox, the focus is moved from
1188// the omnibox for the current tab.
1189IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
1190 NavigateFromOmniboxIntoNewTab) {
1191 GURL url("http://www.google.com/");
1192 GURL url2("http://maps.google.com/");
1193
1194 // Navigate to url.
1195 browser::NavigateParams p(MakeNavigateParams());
1196 p.disposition = CURRENT_TAB;
1197 p.url = url;
1198 browser::Navigate(&p);
1199
1200 // Focus the omnibox.
1201 browser()->FocusLocationBar();
1202
1203 AutocompleteEditController* controller =
1204 browser()->window()->GetLocationBar()->location_entry()->model()->
1205 controller();
1206
1207 // Simulate an alt-enter.
1208 controller->OnAutocompleteAccept(url2, NEW_FOREGROUND_TAB,
[email protected]2905f742011-10-13 03:51:581209 content::PAGE_TRANSITION_TYPED, GURL());
[email protected]26c53e662011-07-09 02:21:021210
1211 // Make sure the second tab is selected.
1212 EXPECT_EQ(1, browser()->active_index());
1213
1214 // The tab contents should have the focus in the second tab.
1215 EXPECT_TRUE(ui_test_utils::IsViewFocused(browser(),
1216 VIEW_ID_TAB_CONTAINER_FOCUS_VIEW));
1217
1218 // Go back to the first tab. The focus should not be in the omnibox.
1219 browser()->SelectPreviousTab();
1220 EXPECT_EQ(0, browser()->active_index());
1221 EXPECT_FALSE(ui_test_utils::IsViewFocused(browser(),
1222 VIEW_ID_LOCATION_BAR));
1223}
1224
[email protected]a048ad22012-03-23 04:26:561225// TODO(csilv): Update this for uber page. http://crbug.com/111579.
[email protected]ddddfda2011-07-14 23:19:391226IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
[email protected]a048ad22012-03-23 04:26:561227 DISABLED_NavigateFromDefaultToHistoryInSameTab) {
[email protected]ddddfda2011-07-14 23:19:391228 {
1229 ui_test_utils::WindowedNotificationObserver observer(
[email protected]ad50def52011-10-19 23:17:071230 content::NOTIFICATION_LOAD_STOP,
1231 content::NotificationService::AllSources());
[email protected]ddddfda2011-07-14 23:19:391232 browser()->ShowHistoryTab();
1233 observer.Wait();
1234 }
1235 EXPECT_EQ(1, browser()->tab_count());
[email protected]11e03fb2012-03-03 19:07:051236 EXPECT_EQ(GURL(chrome::kChromeUIHistoryFrameURL),
[email protected]4ca15302012-01-03 05:53:201237 browser()->GetSelectedWebContents()->GetURL());
[email protected]ddddfda2011-07-14 23:19:391238}
1239
1240IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
1241 NavigateFromDefaultToBookmarksInSameTab) {
1242 {
1243 ui_test_utils::WindowedNotificationObserver observer(
[email protected]ad50def52011-10-19 23:17:071244 content::NOTIFICATION_LOAD_STOP,
1245 content::NotificationService::AllSources());
[email protected]0af8f132011-07-16 01:37:021246 browser()->OpenBookmarkManager();
[email protected]ddddfda2011-07-14 23:19:391247 observer.Wait();
1248 }
1249 EXPECT_EQ(1, browser()->tab_count());
1250 EXPECT_EQ(GURL(chrome::kChromeUIBookmarksURL),
[email protected]4ca15302012-01-03 05:53:201251 browser()->GetSelectedWebContents()->GetURL());
[email protected]ddddfda2011-07-14 23:19:391252}
1253
1254IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
1255 NavigateFromDefaultToDownloadsInSameTab) {
1256 {
1257 ui_test_utils::WindowedNotificationObserver observer(
[email protected]ad50def52011-10-19 23:17:071258 content::NOTIFICATION_LOAD_STOP,
1259 content::NotificationService::AllSources());
[email protected]ddddfda2011-07-14 23:19:391260 browser()->ShowDownloadsTab();
1261 observer.Wait();
1262 }
1263 EXPECT_EQ(1, browser()->tab_count());
1264 EXPECT_EQ(GURL(chrome::kChromeUIDownloadsURL),
[email protected]4ca15302012-01-03 05:53:201265 browser()->GetSelectedWebContents()->GetURL());
[email protected]ddddfda2011-07-14 23:19:391266}
1267
[email protected]675e779b2012-01-25 23:09:451268// This test makes sure any link in a crashed panel page navigates to a tabbed
1269// window.
1270class PanelBrowserNavigatorTest : public BrowserNavigatorTest {
1271 protected:
1272 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE {
1273 command_line->AppendSwitch(switches::kEnablePanels);
1274 }
1275};
1276
1277IN_PROC_BROWSER_TEST_F(PanelBrowserNavigatorTest, NavigateFromCrashedPanel) {
1278 GURL url("http://maps.google.com/#a");
1279 GURL url2("http://maps.google.com/#b");
1280
1281 // Create a panel.
1282 Browser* panel_browser = Browser::CreateForApp(Browser::TYPE_PANEL,
1283 "Test", gfx::Rect(100, 100), browser()->profile());
1284
1285 // Navigate to the page.
1286 browser::NavigateParams p(MakeNavigateParams(panel_browser));
1287 p.url = url;
1288 p.disposition = CURRENT_TAB;
1289 browser::Navigate(&p);
1290
1291 // Navigate() should have navigated in the existing panel window.
1292 EXPECT_EQ(panel_browser, p.browser);
1293
1294 // We should now have two windows, the browser() provided by the framework and
1295 // the panel window we opened earlier. The tabbed browser window has 1 tab.
1296 EXPECT_EQ(2u, BrowserList::size());
1297 EXPECT_EQ(1, browser()->tab_count());
1298 EXPECT_EQ(1, panel_browser->tab_count());
1299
1300 // Kill the panel page.
1301 WebContents* web_contents = panel_browser->GetSelectedWebContents();
1302 web_contents->SetIsCrashed(base::TERMINATION_STATUS_PROCESS_CRASHED, -1);
1303 EXPECT_TRUE(web_contents->IsCrashed());
1304
1305 // Navigate to the page.
1306 browser::NavigateParams p2(MakeNavigateParams(panel_browser));
1307 p2.source_contents = panel_browser->GetSelectedTabContentsWrapper();
1308 p2.url = url2;
1309 p2.disposition = CURRENT_TAB;
1310 browser::Navigate(&p2);
1311
1312 // Navigate() should have opened a new tab in the existing tabbed window.
1313 EXPECT_EQ(browser(), p2.browser);
1314
1315 // We should now have two windows, the browser() provided by the framework and
1316 // the panel window we opened earlier. The tabbed browser window has 2 tabs.
1317 EXPECT_EQ(2u, BrowserList::size());
1318 EXPECT_EQ(2, browser()->tab_count());
1319 EXPECT_EQ(1, panel_browser->tab_count());
1320}
1321
[email protected]ddddfda2011-07-14 23:19:391322} // namespace