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
3 // found in the LICENSE file.
5 #include "chrome/browser/ui/browser_navigator_browsertest.h"
7 #include "base/command_line.h"
8 #include "base/prefs/pref_service.h"
9 #include "base/strings/utf_string_conversions.h"
10 #include "chrome/app/chrome_command_ids.h"
11 #include "chrome/browser/prefs/incognito_mode_prefs.h"
12 #include "chrome/browser/profiles/profile.h"
13 #include "chrome/browser/ui/browser.h"
14 #include "chrome/browser/ui/browser_commands.h"
15 #include "chrome/browser/ui/browser_finder.h"
16 #include "chrome/browser/ui/browser_navigator.h"
17 #include "chrome/browser/ui/browser_tabstrip.h"
18 #include "chrome/browser/ui/browser_window.h"
19 #include "chrome/browser/ui/chrome_pages.h"
20 #include "chrome/browser/ui/singleton_tabs.h"
21 #include "chrome/browser/ui/tabs/tab_strip_model.h"
22 #include "chrome/common/chrome_switches.h"
23 #include "chrome/common/pref_names.h"
24 #include "chrome/common/url_constants.h"
25 #include "chrome/test/base/ui_test_utils.h"
26 #include "content/public/browser/notification_service.h"
27 #include "content/public/browser/notification_types.h"
28 #include "content/public/browser/web_contents.h"
29 #include "content/public/browser/web_contents_view.h"
30 #include "ipc/ipc_message.h"
32 using content::WebContents
;
36 const char kExpectedTitle
[] = "PASSED!";
37 const char kEchoTitleCommand
[] = "echotitle";
40 return GURL("http://www.google.com/");
43 GURL
GetSettingsURL() {
44 return GURL(chrome::kChromeUISettingsURL
);
47 GURL
GetContentSettingsURL() {
48 return GetSettingsURL().Resolve(chrome::kContentSettingsExceptionsSubPage
);
51 GURL
GetClearBrowsingDataURL() {
52 return GetSettingsURL().Resolve(chrome::kClearBrowserDataSubPage
);
55 // Converts long uber URLs ("chrome://chrome/foo/") to short (virtual) URLs
56 // ("chrome://foo/"). This should be used to convert the return value of
57 // WebContentsImpl::GetURL before comparison because it can return either the
58 // real URL or the virtual URL.
59 GURL
ShortenUberURL(const GURL
& url
) {
60 std::string url_string
= url
.spec();
61 const std::string long_prefix
= "chrome://chrome/";
62 const std::string short_prefix
= "chrome://";
63 if (url_string
.find(long_prefix
) != 0)
65 url_string
.replace(0, long_prefix
.length(), short_prefix
);
66 return GURL(url_string
);
71 chrome::NavigateParams
BrowserNavigatorTest::MakeNavigateParams() const {
72 return MakeNavigateParams(browser());
75 chrome::NavigateParams
BrowserNavigatorTest::MakeNavigateParams(
76 Browser
* browser
) const {
77 chrome::NavigateParams
params(browser
, GetGoogleURL(),
78 content::PAGE_TRANSITION_LINK
);
79 params
.window_action
= chrome::NavigateParams::SHOW_WINDOW
;
83 bool BrowserNavigatorTest::OpenPOSTURLInNewForegroundTabAndGetTitle(
84 const GURL
& url
, const std::string
& post_data
, bool is_browser_initiated
,
85 base::string16
* title
) {
86 chrome::NavigateParams
param(MakeNavigateParams());
87 param
.disposition
= NEW_FOREGROUND_TAB
;
89 param
.is_renderer_initiated
= !is_browser_initiated
;
90 param
.uses_post
= true;
91 param
.browser_initiated_post_data
= new base::RefCountedStaticMemory(
92 post_data
.data(), post_data
.size());
94 ui_test_utils::NavigateToURL(¶m
);
95 if (!param
.target_contents
)
98 // Navigate() should have opened the contents in new foreground tab in the
100 EXPECT_EQ(browser(), param
.browser
);
101 EXPECT_EQ(browser()->tab_strip_model()->GetActiveWebContents(),
102 param
.target_contents
);
103 // We should have one window, with one tab.
104 EXPECT_EQ(1u, chrome::GetTotalBrowserCount());
105 EXPECT_EQ(2, browser()->tab_strip_model()->count());
107 *title
= param
.target_contents
->GetTitle();
111 Browser
* BrowserNavigatorTest::CreateEmptyBrowserForType(Browser::Type type
,
113 Browser
* browser
= new Browser(
114 Browser::CreateParams(type
, profile
, chrome::GetActiveDesktop()));
115 chrome::AddTabAt(browser
, GURL(), -1, true);
119 Browser
* BrowserNavigatorTest::CreateEmptyBrowserForApp(Profile
* profile
) {
120 Browser
* browser
= new Browser(
121 Browser::CreateParams::CreateForApp(
122 "Test", false /* trusted_source */, gfx::Rect(), profile
,
123 chrome::GetActiveDesktop()));
124 chrome::AddTabAt(browser
, GURL(), -1, true);
128 WebContents
* BrowserNavigatorTest::CreateWebContents() {
129 content::WebContents::CreateParams
create_params(browser()->profile());
130 content::WebContents
* base_web_contents
=
131 browser()->tab_strip_model()->GetActiveWebContents();
132 if (base_web_contents
) {
133 create_params
.initial_size
=
134 base_web_contents
->GetView()->GetContainerSize();
136 return WebContents::Create(create_params
);
139 void BrowserNavigatorTest::RunSuppressTest(WindowOpenDisposition disposition
) {
140 GURL old_url
= browser()->tab_strip_model()->GetActiveWebContents()->GetURL();
141 chrome::NavigateParams
p(MakeNavigateParams());
142 p
.disposition
= disposition
;
143 chrome::Navigate(&p
);
145 // Nothing should have happened as a result of Navigate();
146 EXPECT_EQ(1, browser()->tab_strip_model()->count());
147 EXPECT_EQ(1u, chrome::GetTotalBrowserCount());
149 browser()->tab_strip_model()->GetActiveWebContents()->GetURL());
152 void BrowserNavigatorTest::RunUseNonIncognitoWindowTest(const GURL
& url
) {
153 Browser
* incognito_browser
= CreateIncognitoBrowser();
155 EXPECT_EQ(2u, chrome::GetTotalBrowserCount());
156 EXPECT_EQ(1, browser()->tab_strip_model()->count());
157 EXPECT_EQ(1, incognito_browser
->tab_strip_model()->count());
159 // Navigate to the page.
160 chrome::NavigateParams
p(MakeNavigateParams(incognito_browser
));
161 p
.disposition
= SINGLETON_TAB
;
163 p
.window_action
= chrome::NavigateParams::SHOW_WINDOW
;
164 chrome::Navigate(&p
);
166 // This page should be opened in browser() window.
167 EXPECT_NE(incognito_browser
, p
.browser
);
168 EXPECT_EQ(browser(), p
.browser
);
169 EXPECT_EQ(2, browser()->tab_strip_model()->count());
171 browser()->tab_strip_model()->GetActiveWebContents()->GetURL());
174 void BrowserNavigatorTest::RunDoNothingIfIncognitoIsForcedTest(
176 Browser
* browser
= CreateIncognitoBrowser();
178 // Set kIncognitoModeAvailability to FORCED.
179 PrefService
* prefs1
= browser
->profile()->GetPrefs();
180 prefs1
->SetInteger(prefs::kIncognitoModeAvailability
,
181 IncognitoModePrefs::FORCED
);
182 PrefService
* prefs2
= browser
->profile()->GetOriginalProfile()->GetPrefs();
183 prefs2
->SetInteger(prefs::kIncognitoModeAvailability
,
184 IncognitoModePrefs::FORCED
);
186 // Navigate to the page.
187 chrome::NavigateParams
p(MakeNavigateParams(browser
));
188 p
.disposition
= OFF_THE_RECORD
;
190 p
.window_action
= chrome::NavigateParams::SHOW_WINDOW
;
191 chrome::Navigate(&p
);
193 // The page should not be opened.
194 EXPECT_EQ(browser
, p
.browser
);
195 EXPECT_EQ(1, browser
->tab_strip_model()->count());
196 EXPECT_EQ(GURL(content::kAboutBlankURL
),
197 browser
->tab_strip_model()->GetActiveWebContents()->GetURL());
200 void BrowserNavigatorTest::Observe(
202 const content::NotificationSource
& source
,
203 const content::NotificationDetails
& details
) {
205 case content::NOTIFICATION_WEB_CONTENTS_RENDER_VIEW_HOST_CREATED
: {
206 ++this->created_tab_contents_count_
;
217 // This test verifies that when a navigation occurs within a tab, the tab count
218 // of the Browser remains the same and the current tab bears the loaded URL.
219 // Note that network URLs are not actually loaded in tests, so this also tests
220 // that error pages leave the intended URL in the address bar.
221 IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest
, Disposition_CurrentTab
) {
222 ui_test_utils::NavigateToURL(browser(), GetGoogleURL());
223 EXPECT_EQ(GetGoogleURL(),
224 browser()->tab_strip_model()->GetActiveWebContents()->GetURL());
225 // We should have one window with one tab.
226 EXPECT_EQ(1u, chrome::GetTotalBrowserCount());
227 EXPECT_EQ(1, browser()->tab_strip_model()->count());
230 // This test verifies that a singleton tab is refocused if one is already opened
231 // in another or an existing window, or added if it is not.
232 IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest
, Disposition_SingletonTabExisting
) {
233 GURL
singleton_url1("http://maps.google.com/");
235 // Register for a notification if an additional WebContents was instantiated.
236 // Opening a Singleton tab that is already opened should not be opening a new
237 // tab nor be creating a new WebContents object.
238 content::NotificationRegistrar registrar
;
240 // As the registrar object goes out of scope, this will get unregistered
242 content::NOTIFICATION_WEB_CONTENTS_RENDER_VIEW_HOST_CREATED
,
243 content::NotificationService::AllSources());
245 chrome::AddSelectedTabWithURL(browser(), singleton_url1
,
246 content::PAGE_TRANSITION_LINK
);
247 chrome::AddSelectedTabWithURL(browser(), GetGoogleURL(),
248 content::PAGE_TRANSITION_LINK
);
250 // We should have one browser with 3 tabs, the 3rd selected.
251 EXPECT_EQ(1u, chrome::GetTotalBrowserCount());
252 EXPECT_EQ(2, browser()->tab_strip_model()->active_index());
254 unsigned int previous_tab_contents_count
=
255 created_tab_contents_count_
= 0;
257 // Navigate to singleton_url1.
258 chrome::NavigateParams
p(MakeNavigateParams());
259 p
.disposition
= SINGLETON_TAB
;
260 p
.url
= singleton_url1
;
261 chrome::Navigate(&p
);
263 // The middle tab should now be selected.
264 EXPECT_EQ(browser(), p
.browser
);
265 EXPECT_EQ(1, browser()->tab_strip_model()->active_index());
267 // No tab contents should have been created
268 EXPECT_EQ(previous_tab_contents_count
,
269 created_tab_contents_count_
);
272 IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest
,
273 Disposition_SingletonTabRespectingRef
) {
274 GURL
singleton_ref_url1("http://maps.google.com/#a");
275 GURL
singleton_ref_url2("http://maps.google.com/#b");
276 GURL
singleton_ref_url3("http://maps.google.com/");
278 chrome::AddSelectedTabWithURL(browser(), singleton_ref_url1
,
279 content::PAGE_TRANSITION_LINK
);
281 // We should have one browser with 2 tabs, 2nd selected.
282 EXPECT_EQ(1u, chrome::GetTotalBrowserCount());
283 EXPECT_EQ(2, browser()->tab_strip_model()->count());
284 EXPECT_EQ(1, browser()->tab_strip_model()->active_index());
286 // Navigate to singleton_url2.
287 chrome::NavigateParams
p(MakeNavigateParams());
288 p
.disposition
= SINGLETON_TAB
;
289 p
.url
= singleton_ref_url2
;
290 chrome::Navigate(&p
);
292 // We should now have 2 tabs, the 2nd one selected.
293 EXPECT_EQ(browser(), p
.browser
);
294 EXPECT_EQ(2, browser()->tab_strip_model()->count());
295 EXPECT_EQ(1, browser()->tab_strip_model()->active_index());
297 // Navigate to singleton_url2, but with respect ref set.
298 p
= MakeNavigateParams();
299 p
.disposition
= SINGLETON_TAB
;
300 p
.url
= singleton_ref_url2
;
301 p
.ref_behavior
= chrome::NavigateParams::RESPECT_REF
;
302 chrome::Navigate(&p
);
304 // We should now have 3 tabs, the 3th one selected.
305 EXPECT_EQ(browser(), p
.browser
);
306 EXPECT_EQ(3, browser()->tab_strip_model()->count());
307 EXPECT_EQ(2, browser()->tab_strip_model()->active_index());
309 // Navigate to singleton_url3.
310 p
= MakeNavigateParams();
311 p
.disposition
= SINGLETON_TAB
;
312 p
.url
= singleton_ref_url3
;
313 p
.ref_behavior
= chrome::NavigateParams::RESPECT_REF
;
314 chrome::Navigate(&p
);
316 // We should now have 4 tabs, the 4th one selected.
317 EXPECT_EQ(browser(), p
.browser
);
318 EXPECT_EQ(4, browser()->tab_strip_model()->count());
319 EXPECT_EQ(3, browser()->tab_strip_model()->active_index());
322 IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest
,
323 Disposition_SingletonTabNoneExisting
) {
324 GURL
singleton_url1("http://maps.google.com/");
326 // We should have one browser with 1 tab.
327 EXPECT_EQ(1u, chrome::GetTotalBrowserCount());
328 EXPECT_EQ(0, browser()->tab_strip_model()->active_index());
330 // Navigate to singleton_url1.
331 chrome::NavigateParams
p(MakeNavigateParams());
332 p
.disposition
= SINGLETON_TAB
;
333 p
.url
= singleton_url1
;
334 chrome::Navigate(&p
);
336 // We should now have 2 tabs, the 2nd one selected.
337 EXPECT_EQ(browser(), p
.browser
);
338 EXPECT_EQ(2, browser()->tab_strip_model()->count());
339 EXPECT_EQ(1, browser()->tab_strip_model()->active_index());
342 // This test verifies that when a navigation results in a foreground tab, the
343 // tab count of the Browser increases and the selected tab shifts to the new
345 IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest
, Disposition_NewForegroundTab
) {
346 WebContents
* old_contents
=
347 browser()->tab_strip_model()->GetActiveWebContents();
348 chrome::NavigateParams
p(MakeNavigateParams());
349 p
.disposition
= NEW_FOREGROUND_TAB
;
350 chrome::Navigate(&p
);
351 EXPECT_NE(old_contents
,
352 browser()->tab_strip_model()->GetActiveWebContents());
353 EXPECT_EQ(browser()->tab_strip_model()->GetActiveWebContents(),
355 EXPECT_EQ(2, browser()->tab_strip_model()->count());
358 // This test verifies that when a navigation results in a background tab, the
359 // tab count of the Browser increases but the selected tab remains the same.
360 IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest
, Disposition_NewBackgroundTab
) {
361 WebContents
* old_contents
=
362 browser()->tab_strip_model()->GetActiveWebContents();
363 chrome::NavigateParams
p(MakeNavigateParams());
364 p
.disposition
= NEW_BACKGROUND_TAB
;
365 chrome::Navigate(&p
);
366 WebContents
* new_contents
=
367 browser()->tab_strip_model()->GetActiveWebContents();
368 // The selected tab should have remained unchanged, since the new tab was
369 // opened in the background.
370 EXPECT_EQ(old_contents
, new_contents
);
371 EXPECT_EQ(2, browser()->tab_strip_model()->count());
374 // This test verifies that when a navigation requiring a new foreground tab
375 // occurs in a Browser that cannot host multiple tabs, the new foreground tab
376 // is created in an existing compatible Browser.
377 IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest
,
378 Disposition_IncompatibleWindow_Existing
) {
379 // Open a foreground tab in a window that cannot open popups when there is an
380 // existing compatible window somewhere else that they can be opened within.
381 Browser
* popup
= CreateEmptyBrowserForType(Browser::TYPE_POPUP
,
382 browser()->profile());
383 chrome::NavigateParams
p(MakeNavigateParams(popup
));
384 p
.disposition
= NEW_FOREGROUND_TAB
;
385 chrome::Navigate(&p
);
387 // Navigate() should have opened the tab in a different browser since the
388 // one we supplied didn't support additional tabs.
389 EXPECT_NE(popup
, p
.browser
);
391 // Since browser() is an existing compatible tabbed browser, it should have
392 // opened the tab there.
393 EXPECT_EQ(browser(), p
.browser
);
395 // We should be left with 2 windows, the popup with one tab and the browser()
396 // provided by the framework with two.
397 EXPECT_EQ(2u, chrome::GetTotalBrowserCount());
398 EXPECT_EQ(1, popup
->tab_strip_model()->count());
399 EXPECT_EQ(2, browser()->tab_strip_model()->count());
402 // This test verifies that when a navigation requiring a new foreground tab
403 // occurs in a Browser that cannot host multiple tabs and no compatible Browser
404 // that can is open, a compatible Browser is created.
405 IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest
,
406 Disposition_IncompatibleWindow_NoExisting
) {
407 // We want to simulate not being able to find an existing window compatible
408 // with our non-tabbed browser window so Navigate() is forced to create a
409 // new compatible window. Because browser() supplied by the in-process
410 // browser testing framework is compatible with browser()->profile(), we
411 // need a different profile, and creating a popup window with an incognito
412 // profile is a quick and dirty way of achieving this.
413 Browser
* popup
= CreateEmptyBrowserForType(
415 browser()->profile()->GetOffTheRecordProfile());
416 chrome::NavigateParams
p(MakeNavigateParams(popup
));
417 p
.disposition
= NEW_FOREGROUND_TAB
;
418 chrome::Navigate(&p
);
420 // Navigate() should have opened the tab in a different browser since the
421 // one we supplied didn't support additional tabs.
422 EXPECT_NE(popup
, p
.browser
);
424 // This time, browser() is _not_ compatible with popup since it is not an
426 EXPECT_NE(browser(), p
.browser
);
428 // We should have three windows, each with one tab:
429 // 1. the browser() provided by the framework (unchanged in this test)
430 // 2. the incognito popup we created originally
431 // 3. the new incognito tabbed browser that was created by Navigate().
432 EXPECT_EQ(3u, chrome::GetTotalBrowserCount());
433 EXPECT_EQ(1, browser()->tab_strip_model()->count());
434 EXPECT_EQ(1, popup
->tab_strip_model()->count());
435 EXPECT_EQ(1, p
.browser
->tab_strip_model()->count());
436 EXPECT_TRUE(p
.browser
->is_type_tabbed());
439 // This test verifies that navigating with WindowOpenDisposition = NEW_POPUP
440 // from a normal Browser results in a new Browser with TYPE_POPUP.
441 IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest
, Disposition_NewPopup
) {
442 chrome::NavigateParams
p(MakeNavigateParams());
443 p
.disposition
= NEW_POPUP
;
444 p
.window_bounds
= gfx::Rect(0, 0, 200, 200);
445 // Wait for new popup to to load and gain focus.
446 ui_test_utils::NavigateToURL(&p
);
448 // Navigate() should have opened a new, focused popup window.
449 EXPECT_NE(browser(), p
.browser
);
451 // TODO(stevenjb): Enable this test. See: crbug.com/79493
452 EXPECT_TRUE(p
.browser
->window()->IsActive());
454 EXPECT_TRUE(p
.browser
->is_type_popup());
455 EXPECT_FALSE(p
.browser
->is_app());
457 // We should have two windows, the browser() provided by the framework and the
459 EXPECT_EQ(2u, chrome::GetTotalBrowserCount());
460 EXPECT_EQ(1, browser()->tab_strip_model()->count());
461 EXPECT_EQ(1, p
.browser
->tab_strip_model()->count());
464 // This test verifies that navigating with WindowOpenDisposition = NEW_POPUP
465 // from a normal Browser results in a new Browser with is_app() true.
466 IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest
, Disposition_NewPopup_ExtensionId
) {
467 chrome::NavigateParams
p(MakeNavigateParams());
468 p
.disposition
= NEW_POPUP
;
469 p
.extension_app_id
= "extensionappid";
470 p
.window_bounds
= gfx::Rect(0, 0, 200, 200);
471 // Wait for new popup to to load and gain focus.
472 ui_test_utils::NavigateToURL(&p
);
474 // Navigate() should have opened a new, focused popup window.
475 EXPECT_NE(browser(), p
.browser
);
476 EXPECT_TRUE(p
.browser
->is_type_popup());
477 EXPECT_TRUE(p
.browser
->is_app());
479 // We should have two windows, the browser() provided by the framework and the
481 EXPECT_EQ(2u, chrome::GetTotalBrowserCount());
482 EXPECT_EQ(1, browser()->tab_strip_model()->count());
483 EXPECT_EQ(1, p
.browser
->tab_strip_model()->count());
486 // This test verifies that navigating with WindowOpenDisposition = NEW_POPUP
487 // from a normal popup results in a new Browser with TYPE_POPUP.
488 IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest
, Disposition_NewPopupFromPopup
) {
490 chrome::NavigateParams
p1(MakeNavigateParams());
491 p1
.disposition
= NEW_POPUP
;
492 p1
.window_bounds
= gfx::Rect(0, 0, 200, 200);
493 chrome::Navigate(&p1
);
494 // Open another popup.
495 chrome::NavigateParams
p2(MakeNavigateParams(p1
.browser
));
496 p2
.disposition
= NEW_POPUP
;
497 p2
.window_bounds
= gfx::Rect(0, 0, 200, 200);
498 chrome::Navigate(&p2
);
500 // Navigate() should have opened a new normal popup window.
501 EXPECT_NE(p1
.browser
, p2
.browser
);
502 EXPECT_TRUE(p2
.browser
->is_type_popup());
503 EXPECT_FALSE(p2
.browser
->is_app());
505 // We should have three windows, the browser() provided by the framework,
506 // the first popup window, and the second popup window.
507 EXPECT_EQ(3u, chrome::GetTotalBrowserCount());
508 EXPECT_EQ(1, browser()->tab_strip_model()->count());
509 EXPECT_EQ(1, p1
.browser
->tab_strip_model()->count());
510 EXPECT_EQ(1, p2
.browser
->tab_strip_model()->count());
513 // This test verifies that navigating with WindowOpenDisposition = NEW_POPUP
514 // from an app frame results in a new Browser with TYPE_POPUP.
515 IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest
,
516 Disposition_NewPopupFromAppWindow
) {
517 Browser
* app_browser
= CreateEmptyBrowserForApp(browser()->profile());
518 chrome::NavigateParams
p(MakeNavigateParams(app_browser
));
519 p
.disposition
= NEW_POPUP
;
520 p
.window_bounds
= gfx::Rect(0, 0, 200, 200);
521 chrome::Navigate(&p
);
523 // Navigate() should have opened a new popup app window.
524 EXPECT_NE(app_browser
, p
.browser
);
525 EXPECT_NE(browser(), p
.browser
);
526 EXPECT_TRUE(p
.browser
->is_type_popup());
527 EXPECT_TRUE(p
.browser
->is_app());
529 // We should now have three windows, the app window, the app popup it created,
530 // and the original browser() provided by the framework.
531 EXPECT_EQ(3u, chrome::GetTotalBrowserCount());
532 EXPECT_EQ(1, browser()->tab_strip_model()->count());
533 EXPECT_EQ(1, app_browser
->tab_strip_model()->count());
534 EXPECT_EQ(1, p
.browser
->tab_strip_model()->count());
537 // This test verifies that navigating with WindowOpenDisposition = NEW_POPUP
538 // from an app popup results in a new Browser also of TYPE_POPUP.
539 IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest
,
540 Disposition_NewPopupFromAppPopup
) {
541 Browser
* app_browser
= CreateEmptyBrowserForApp(browser()->profile());
542 // Open an app popup.
543 chrome::NavigateParams
p1(MakeNavigateParams(app_browser
));
544 p1
.disposition
= NEW_POPUP
;
545 p1
.window_bounds
= gfx::Rect(0, 0, 200, 200);
546 chrome::Navigate(&p1
);
547 // Now open another app popup.
548 chrome::NavigateParams
p2(MakeNavigateParams(p1
.browser
));
549 p2
.disposition
= NEW_POPUP
;
550 p2
.window_bounds
= gfx::Rect(0, 0, 200, 200);
551 chrome::Navigate(&p2
);
553 // Navigate() should have opened a new popup app window.
554 EXPECT_NE(browser(), p1
.browser
);
555 EXPECT_NE(p1
.browser
, p2
.browser
);
556 EXPECT_TRUE(p2
.browser
->is_type_popup());
557 EXPECT_TRUE(p2
.browser
->is_app());
559 // We should now have four windows, the app window, the first app popup,
560 // the second app popup, and the original browser() provided by the framework.
561 EXPECT_EQ(4u, chrome::GetTotalBrowserCount());
562 EXPECT_EQ(1, browser()->tab_strip_model()->count());
563 EXPECT_EQ(1, app_browser
->tab_strip_model()->count());
564 EXPECT_EQ(1, p1
.browser
->tab_strip_model()->count());
565 EXPECT_EQ(1, p2
.browser
->tab_strip_model()->count());
568 // This test verifies that navigating with WindowOpenDisposition = NEW_POPUP
569 // from an extension app tab results in a new Browser with TYPE_APP_POPUP.
570 IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest
,
571 Disposition_NewPopupFromExtensionApp
) {
575 // This test verifies that navigating with window_action = SHOW_WINDOW_INACTIVE
576 // does not focus a new new popup window.
577 IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest
, Disposition_NewPopupUnfocused
) {
578 chrome::NavigateParams
p(MakeNavigateParams());
579 p
.disposition
= NEW_POPUP
;
580 p
.window_bounds
= gfx::Rect(0, 0, 200, 200);
581 p
.window_action
= chrome::NavigateParams::SHOW_WINDOW_INACTIVE
;
582 // Wait for new popup to load (and gain focus if the test fails).
583 ui_test_utils::NavigateToURL(&p
);
585 // Navigate() should have opened a new, unfocused, popup window.
586 EXPECT_NE(browser(), p
.browser
);
587 EXPECT_EQ(Browser::TYPE_POPUP
, p
.browser
->type());
589 // TODO(stevenjb): Enable this test. See: crbug.com/79493
590 EXPECT_FALSE(p
.browser
->window()->IsActive());
594 // This test verifies that navigating with WindowOpenDisposition = NEW_POPUP
595 // and trusted_source = true results in a new Browser where is_trusted_source()
597 IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest
, Disposition_NewPopupTrusted
) {
598 chrome::NavigateParams
p(MakeNavigateParams());
599 p
.disposition
= NEW_POPUP
;
600 p
.trusted_source
= true;
601 p
.window_bounds
= gfx::Rect(0, 0, 200, 200);
602 // Wait for new popup to to load and gain focus.
603 ui_test_utils::NavigateToURL(&p
);
605 // Navigate() should have opened a new popup window of TYPE_TRUSTED_POPUP.
606 EXPECT_NE(browser(), p
.browser
);
607 EXPECT_TRUE(p
.browser
->is_type_popup());
608 EXPECT_TRUE(p
.browser
->is_trusted_source());
612 // This test verifies that navigating with WindowOpenDisposition = NEW_WINDOW
613 // always opens a new window.
614 IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest
, Disposition_NewWindow
) {
615 chrome::NavigateParams
p(MakeNavigateParams());
616 p
.disposition
= NEW_WINDOW
;
617 chrome::Navigate(&p
);
619 // Navigate() should have opened a new toplevel window.
620 EXPECT_NE(browser(), p
.browser
);
621 EXPECT_TRUE(p
.browser
->is_type_tabbed());
623 // We should now have two windows, the browser() provided by the framework and
624 // the new normal window.
625 EXPECT_EQ(2u, chrome::GetTotalBrowserCount());
626 EXPECT_EQ(1, browser()->tab_strip_model()->count());
627 EXPECT_EQ(1, p
.browser
->tab_strip_model()->count());
630 // This test verifies that navigating with WindowOpenDisposition = INCOGNITO
631 // opens a new incognito window if no existing incognito window is present.
632 IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest
, Disposition_Incognito
) {
633 chrome::NavigateParams
p(MakeNavigateParams());
634 p
.disposition
= OFF_THE_RECORD
;
635 chrome::Navigate(&p
);
637 // Navigate() should have opened a new toplevel incognito window.
638 EXPECT_NE(browser(), p
.browser
);
639 EXPECT_EQ(browser()->profile()->GetOffTheRecordProfile(),
640 p
.browser
->profile());
642 // |source_contents| should be set to NULL because the profile for the new
643 // page is different from the originating page.
644 EXPECT_EQ(NULL
, p
.source_contents
);
646 // We should now have two windows, the browser() provided by the framework and
647 // the new incognito window.
648 EXPECT_EQ(2u, chrome::GetTotalBrowserCount());
649 EXPECT_EQ(1, browser()->tab_strip_model()->count());
650 EXPECT_EQ(1, p
.browser
->tab_strip_model()->count());
653 // This test verifies that navigating with WindowOpenDisposition = INCOGNITO
654 // reuses an existing incognito window when possible.
655 IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest
, Disposition_IncognitoRefocus
) {
656 Browser
* incognito_browser
=
657 CreateEmptyBrowserForType(Browser::TYPE_TABBED
,
658 browser()->profile()->GetOffTheRecordProfile());
659 chrome::NavigateParams
p(MakeNavigateParams());
660 p
.disposition
= OFF_THE_RECORD
;
661 chrome::Navigate(&p
);
663 // Navigate() should have opened a new tab in the existing incognito window.
664 EXPECT_NE(browser(), p
.browser
);
665 EXPECT_EQ(p
.browser
, incognito_browser
);
667 // We should now have two windows, the browser() provided by the framework and
668 // the incognito window we opened earlier.
669 EXPECT_EQ(2u, chrome::GetTotalBrowserCount());
670 EXPECT_EQ(1, browser()->tab_strip_model()->count());
671 EXPECT_EQ(2, incognito_browser
->tab_strip_model()->count());
674 // This test verifies that no navigation action occurs when
675 // WindowOpenDisposition = SUPPRESS_OPEN.
676 IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest
, Disposition_SuppressOpen
) {
677 RunSuppressTest(SUPPRESS_OPEN
);
680 // This test verifies that no navigation action occurs when
681 // WindowOpenDisposition = SAVE_TO_DISK.
682 IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest
, Disposition_SaveToDisk
) {
683 RunSuppressTest(SAVE_TO_DISK
);
686 // This test verifies that no navigation action occurs when
687 // WindowOpenDisposition = IGNORE_ACTION.
688 IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest
, Disposition_IgnoreAction
) {
689 RunSuppressTest(IGNORE_ACTION
);
692 // This tests adding a foreground tab with a predefined WebContents.
693 IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest
, TargetContents_ForegroundTab
) {
694 chrome::NavigateParams
p(MakeNavigateParams());
695 p
.disposition
= NEW_FOREGROUND_TAB
;
696 p
.target_contents
= CreateWebContents();
697 chrome::Navigate(&p
);
699 // Navigate() should have opened the contents in a new foreground in the
701 EXPECT_EQ(browser(), p
.browser
);
702 EXPECT_EQ(browser()->tab_strip_model()->GetActiveWebContents(),
705 // We should have one window, with two tabs.
706 EXPECT_EQ(1u, chrome::GetTotalBrowserCount());
707 EXPECT_EQ(2, browser()->tab_strip_model()->count());
711 // This tests adding a popup with a predefined WebContents.
712 IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest
, DISABLED_TargetContents_Popup
) {
713 chrome::NavigateParams
p(MakeNavigateParams());
714 p
.disposition
= NEW_POPUP
;
715 p
.target_contents
= CreateWebContents();
716 p
.window_bounds
= gfx::Rect(10, 10, 500, 500);
717 chrome::Navigate(&p
);
719 // Navigate() should have opened a new popup window.
720 EXPECT_NE(browser(), p
.browser
);
721 EXPECT_TRUE(p
.browser
->is_type_popup());
722 EXPECT_FALSE(p
.browser
->is_app());
724 // The web platform is weird. The window bounds specified in
725 // |p.window_bounds| are used as follows:
726 // - the origin is used to position the window
727 // - the size is used to size the WebContents of the window.
728 // As such the position of the resulting window will always match
729 // p.window_bounds.origin(), but its size will not. We need to match
730 // the size against the selected tab's view's container size.
731 // Only Windows positions the window according to |p.window_bounds.origin()| -
732 // on Mac the window is offset from the opener and on Linux it always opens
734 EXPECT_EQ(p
.window_bounds
.origin(),
735 p
.browser
->window()->GetRestoredBounds().origin());
736 // All platforms should respect size however provided width > 400 (Mac has a
737 // minimum window width of 400).
738 EXPECT_EQ(p
.window_bounds
.size(),
739 p
.target_contents
->GetView()->GetContainerSize());
741 // We should have two windows, the new popup and the browser() provided by the
743 EXPECT_EQ(2u, chrome::GetTotalBrowserCount());
744 EXPECT_EQ(1, browser()->tab_strip_model()->count());
745 EXPECT_EQ(1, p
.browser
->tab_strip_model()->count());
749 // This tests adding a tab at a specific index.
750 IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest
, Tabstrip_InsertAtIndex
) {
751 // This is not meant to be a comprehensive test of whether or not the tab
752 // implementation of the browser observes the insertion index. That is
753 // covered by the unit tests for TabStripModel. This merely verifies that
754 // insertion index preference is reflected in common cases.
755 chrome::NavigateParams
p(MakeNavigateParams());
756 p
.disposition
= NEW_FOREGROUND_TAB
;
757 p
.tabstrip_index
= 0;
758 p
.tabstrip_add_types
= TabStripModel::ADD_FORCE_INDEX
;
759 chrome::Navigate(&p
);
761 // Navigate() should have inserted a new tab at slot 0 in the tabstrip.
762 EXPECT_EQ(browser(), p
.browser
);
763 EXPECT_EQ(0, browser()->tab_strip_model()->GetIndexOfWebContents(
764 static_cast<const WebContents
*>(p
.target_contents
)));
766 // We should have one window - the browser() provided by the framework.
767 EXPECT_EQ(1u, chrome::GetTotalBrowserCount());
768 EXPECT_EQ(2, browser()->tab_strip_model()->count());
771 // This test verifies that constructing params with disposition = SINGLETON_TAB
772 // and IGNORE_AND_NAVIGATE opens a new tab navigated to the specified URL if
773 // no previous tab with that URL (minus the path) exists.
774 IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest
,
775 Disposition_SingletonTabNew_IgnorePath
) {
776 chrome::AddSelectedTabWithURL(browser(), GetGoogleURL(),
777 content::PAGE_TRANSITION_LINK
);
779 // We should have one browser with 2 tabs, the 2nd selected.
780 EXPECT_EQ(1u, chrome::GetTotalBrowserCount());
781 EXPECT_EQ(2, browser()->tab_strip_model()->count());
782 EXPECT_EQ(1, browser()->tab_strip_model()->active_index());
784 // Navigate to a new singleton tab with a sub-page.
785 chrome::NavigateParams
p(MakeNavigateParams());
786 p
.disposition
= SINGLETON_TAB
;
787 p
.url
= GetContentSettingsURL();
788 p
.window_action
= chrome::NavigateParams::SHOW_WINDOW
;
789 p
.path_behavior
= chrome::NavigateParams::IGNORE_AND_NAVIGATE
;
790 chrome::Navigate(&p
);
792 // The last tab should now be selected and navigated to the sub-page of the
794 EXPECT_EQ(browser(), p
.browser
);
795 EXPECT_EQ(3, browser()->tab_strip_model()->count());
796 EXPECT_EQ(2, browser()->tab_strip_model()->active_index());
797 EXPECT_EQ(GetContentSettingsURL(),
798 ShortenUberURL(browser()->tab_strip_model()->
799 GetActiveWebContents()->GetURL()));
802 // This test verifies that constructing params with disposition = SINGLETON_TAB
803 // and IGNORE_AND_NAVIGATE opens an existing tab with the matching URL (minus
804 // the path) which is navigated to the specified URL.
805 IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest
,
806 Disposition_SingletonTabExisting_IgnorePath
) {
807 GURL
singleton_url1(GetSettingsURL());
808 chrome::AddSelectedTabWithURL(browser(), singleton_url1
,
809 content::PAGE_TRANSITION_LINK
);
810 chrome::AddSelectedTabWithURL(browser(), GetGoogleURL(),
811 content::PAGE_TRANSITION_LINK
);
813 // We should have one browser with 3 tabs, the 3rd selected.
814 EXPECT_EQ(1u, chrome::GetTotalBrowserCount());
815 EXPECT_EQ(3, browser()->tab_strip_model()->count());
816 EXPECT_EQ(2, browser()->tab_strip_model()->active_index());
818 // Navigate to singleton_url1.
819 chrome::NavigateParams
p(MakeNavigateParams());
820 p
.disposition
= SINGLETON_TAB
;
821 p
.url
= GetContentSettingsURL();
822 p
.window_action
= chrome::NavigateParams::SHOW_WINDOW
;
823 p
.path_behavior
= chrome::NavigateParams::IGNORE_AND_NAVIGATE
;
824 chrome::Navigate(&p
);
826 // The middle tab should now be selected and navigated to the sub-page of the
828 EXPECT_EQ(browser(), p
.browser
);
829 EXPECT_EQ(3, browser()->tab_strip_model()->count());
830 EXPECT_EQ(1, browser()->tab_strip_model()->active_index());
831 EXPECT_EQ(GetContentSettingsURL(),
832 ShortenUberURL(browser()->tab_strip_model()->
833 GetActiveWebContents()->GetURL()));
836 // This test verifies that constructing params with disposition = SINGLETON_TAB
837 // and IGNORE_AND_NAVIGATE opens an existing tab with the matching URL (minus
838 // the path) which is navigated to the specified URL.
839 IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest
,
840 Disposition_SingletonTabExistingSubPath_IgnorePath
) {
841 GURL
singleton_url1(GetContentSettingsURL());
842 chrome::AddSelectedTabWithURL(browser(), singleton_url1
,
843 content::PAGE_TRANSITION_LINK
);
844 chrome::AddSelectedTabWithURL(browser(), GetGoogleURL(),
845 content::PAGE_TRANSITION_LINK
);
847 // We should have one browser with 3 tabs, the 3rd selected.
848 EXPECT_EQ(1u, chrome::GetTotalBrowserCount());
849 EXPECT_EQ(3, browser()->tab_strip_model()->count());
850 EXPECT_EQ(2, browser()->tab_strip_model()->active_index());
852 // Navigate to singleton_url1.
853 chrome::NavigateParams
p(MakeNavigateParams());
854 p
.disposition
= SINGLETON_TAB
;
855 p
.url
= GetClearBrowsingDataURL();
856 p
.window_action
= chrome::NavigateParams::SHOW_WINDOW
;
857 p
.path_behavior
= chrome::NavigateParams::IGNORE_AND_NAVIGATE
;
858 chrome::Navigate(&p
);
860 // The middle tab should now be selected and navigated to the sub-page of the
862 EXPECT_EQ(browser(), p
.browser
);
863 EXPECT_EQ(3, browser()->tab_strip_model()->count());
864 EXPECT_EQ(1, browser()->tab_strip_model()->active_index());
865 EXPECT_EQ(GetClearBrowsingDataURL(),
866 ShortenUberURL(browser()->tab_strip_model()->
867 GetActiveWebContents()->GetURL()));
870 // This test verifies that constructing params with disposition = SINGLETON_TAB
871 // and IGNORE_AND_STAY_PUT opens an existing tab with the matching URL (minus
873 IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest
,
874 Disposition_SingletonTabExistingSubPath_IgnorePath2
) {
875 GURL
singleton_url1(GetContentSettingsURL());
876 chrome::AddSelectedTabWithURL(browser(), singleton_url1
,
877 content::PAGE_TRANSITION_LINK
);
878 chrome::AddSelectedTabWithURL(browser(), GetGoogleURL(),
879 content::PAGE_TRANSITION_LINK
);
881 // We should have one browser with 3 tabs, the 3rd selected.
882 EXPECT_EQ(1u, chrome::GetTotalBrowserCount());
883 EXPECT_EQ(3, browser()->tab_strip_model()->count());
884 EXPECT_EQ(2, browser()->tab_strip_model()->active_index());
886 // Navigate to singleton_url1.
887 chrome::NavigateParams
p(MakeNavigateParams());
888 p
.disposition
= SINGLETON_TAB
;
889 p
.url
= GetClearBrowsingDataURL();
890 p
.window_action
= chrome::NavigateParams::SHOW_WINDOW
;
891 p
.path_behavior
= chrome::NavigateParams::IGNORE_AND_STAY_PUT
;
892 chrome::Navigate(&p
);
894 // The middle tab should now be selected.
895 EXPECT_EQ(browser(), p
.browser
);
896 EXPECT_EQ(3, browser()->tab_strip_model()->count());
897 EXPECT_EQ(1, browser()->tab_strip_model()->active_index());
898 EXPECT_EQ(singleton_url1
,
899 ShortenUberURL(browser()->tab_strip_model()->
900 GetActiveWebContents()->GetURL()));
903 // This test verifies that constructing params with disposition = SINGLETON_TAB
904 // and IGNORE_AND_NAVIGATE will update the current tab's URL if the currently
905 // selected tab is a match but has a different path.
906 IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest
,
907 Disposition_SingletonTabFocused_IgnorePath
) {
908 GURL
singleton_url_current(GetContentSettingsURL());
909 chrome::AddSelectedTabWithURL(browser(), singleton_url_current
,
910 content::PAGE_TRANSITION_LINK
);
912 // We should have one browser with 2 tabs, the 2nd selected.
913 EXPECT_EQ(1u, chrome::GetTotalBrowserCount());
914 EXPECT_EQ(2, browser()->tab_strip_model()->count());
915 EXPECT_EQ(1, browser()->tab_strip_model()->active_index());
917 // Navigate to a different settings path.
918 GURL
singleton_url_target(GetClearBrowsingDataURL());
919 chrome::NavigateParams
p(MakeNavigateParams());
920 p
.disposition
= SINGLETON_TAB
;
921 p
.url
= singleton_url_target
;
922 p
.window_action
= chrome::NavigateParams::SHOW_WINDOW
;
923 p
.path_behavior
= chrome::NavigateParams::IGNORE_AND_NAVIGATE
;
924 chrome::Navigate(&p
);
926 // The second tab should still be selected, but navigated to the new path.
927 EXPECT_EQ(browser(), p
.browser
);
928 EXPECT_EQ(2, browser()->tab_strip_model()->count());
929 EXPECT_EQ(1, browser()->tab_strip_model()->active_index());
930 EXPECT_EQ(singleton_url_target
,
931 ShortenUberURL(browser()->tab_strip_model()->
932 GetActiveWebContents()->GetURL()));
935 // This test verifies that constructing params with disposition = SINGLETON_TAB
936 // and IGNORE_AND_NAVIGATE will open an existing matching tab with a different
938 IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest
,
939 Disposition_SingletonTabExisting_IgnoreQuery
) {
940 int initial_tab_count
= browser()->tab_strip_model()->count();
941 GURL
singleton_url_current("chrome://settings/internet");
942 chrome::AddSelectedTabWithURL(browser(), singleton_url_current
,
943 content::PAGE_TRANSITION_LINK
);
945 EXPECT_EQ(initial_tab_count
+ 1, browser()->tab_strip_model()->count());
946 EXPECT_EQ(initial_tab_count
, browser()->tab_strip_model()->active_index());
948 // Navigate to a different settings path.
949 GURL
singleton_url_target(
950 "chrome://settings/internet?"
951 "servicePath=/profile/ethernet_00aa00aa00aa&networkType=1");
952 chrome::NavigateParams
p(MakeNavigateParams());
953 p
.disposition
= SINGLETON_TAB
;
954 p
.url
= singleton_url_target
;
955 p
.window_action
= chrome::NavigateParams::SHOW_WINDOW
;
956 p
.path_behavior
= chrome::NavigateParams::IGNORE_AND_NAVIGATE
;
957 chrome::Navigate(&p
);
959 // Last tab should still be selected.
960 EXPECT_EQ(browser(), p
.browser
);
961 EXPECT_EQ(initial_tab_count
+ 1, browser()->tab_strip_model()->count());
962 EXPECT_EQ(initial_tab_count
, browser()->tab_strip_model()->active_index());
965 // This test verifies that the settings page isn't opened in the incognito
967 // Disabled until fixed for uber settings: http://crbug.com/111243
968 IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest
,
969 DISABLED_Disposition_Settings_UseNonIncognitoWindow
) {
970 RunUseNonIncognitoWindowTest(GetSettingsURL());
973 // This test verifies that the view-source settings page isn't opened in the
975 IN_PROC_BROWSER_TEST_F(
976 BrowserNavigatorTest
,
977 Disposition_ViewSource_Settings_DoNothingIfIncognitoForced
) {
978 std::string
view_source(content::kViewSourceScheme
);
979 view_source
.append(":");
980 view_source
.append(chrome::kChromeUISettingsURL
);
981 RunDoNothingIfIncognitoIsForcedTest(GURL(view_source
));
984 // This test verifies that the view-source settings page isn't opened in the
985 // incognito window even if incognito mode is forced (does nothing in that
987 IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest
,
988 Disposition_ViewSource_Settings_UseNonIncognitoWindow
) {
989 std::string
view_source(content::kViewSourceScheme
);
990 view_source
.append(":");
991 view_source
.append(chrome::kChromeUISettingsURL
);
992 RunUseNonIncognitoWindowTest(GURL(view_source
));
995 // This test verifies that the settings page isn't opened in the incognito
996 // window from a non-incognito window (bookmark open-in-incognito trigger).
997 // Disabled until fixed for uber settings: http://crbug.com/111243
998 IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest
,
999 DISABLED_Disposition_Settings_UseNonIncognitoWindowForBookmark
) {
1000 chrome::NavigateParams
params(browser(), GetSettingsURL(),
1001 content::PAGE_TRANSITION_AUTO_BOOKMARK
);
1002 params
.disposition
= OFF_THE_RECORD
;
1004 content::WindowedNotificationObserver
observer(
1005 content::NOTIFICATION_LOAD_STOP
,
1006 content::NotificationService::AllSources());
1007 chrome::Navigate(¶ms
);
1011 EXPECT_EQ(1u, chrome::GetTotalBrowserCount());
1012 EXPECT_EQ(GetSettingsURL(),
1013 ShortenUberURL(browser()->tab_strip_model()->
1014 GetActiveWebContents()->GetURL()));
1017 // Settings page is expected to always open in normal mode regardless
1018 // of whether the user is trying to open it in incognito mode or not.
1019 // This test verifies that if incognito mode is forced (by policy), settings
1020 // page doesn't open at all.
1021 // Disabled until fixed for uber settings: http://crbug.com/111243
1022 IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest
,
1023 DISABLED_Disposition_Settings_DoNothingIfIncognitoIsForced
) {
1024 RunDoNothingIfIncognitoIsForcedTest(GetSettingsURL());
1027 // This test verifies that the bookmarks page isn't opened in the incognito
1029 IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest
,
1030 Disposition_Bookmarks_UseNonIncognitoWindow
) {
1031 RunUseNonIncognitoWindowTest(GURL(chrome::kChromeUIBookmarksURL
));
1034 // Bookmark manager is expected to always open in normal mode regardless
1035 // of whether the user is trying to open it in incognito mode or not.
1036 // This test verifies that if incognito mode is forced (by policy), bookmark
1037 // manager doesn't open at all.
1038 IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest
,
1039 Disposition_Bookmarks_DoNothingIfIncognitoIsForced
) {
1040 RunDoNothingIfIncognitoIsForcedTest(GURL(chrome::kChromeUIBookmarksURL
));
1043 // This test makes sure a crashed singleton tab reloads from a new navigation.
1044 IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest
,
1045 NavigateToCrashedSingletonTab
) {
1046 GURL
singleton_url(GetContentSettingsURL());
1047 WebContents
* web_contents
= chrome::AddSelectedTabWithURL(
1048 browser(), singleton_url
, content::PAGE_TRANSITION_LINK
);
1050 // We should have one browser with 2 tabs, the 2nd selected.
1051 EXPECT_EQ(1u, chrome::GetTotalBrowserCount());
1052 EXPECT_EQ(2, browser()->tab_strip_model()->count());
1053 EXPECT_EQ(1, browser()->tab_strip_model()->active_index());
1055 // Kill the singleton tab.
1056 web_contents
->SetIsCrashed(base::TERMINATION_STATUS_PROCESS_CRASHED
, -1);
1057 EXPECT_TRUE(web_contents
->IsCrashed());
1059 chrome::NavigateParams
p(MakeNavigateParams());
1060 p
.disposition
= SINGLETON_TAB
;
1061 p
.url
= singleton_url
;
1062 p
.window_action
= chrome::NavigateParams::SHOW_WINDOW
;
1063 p
.path_behavior
= chrome::NavigateParams::IGNORE_AND_NAVIGATE
;
1064 ui_test_utils::NavigateToURL(&p
);
1066 // The tab should not be sad anymore.
1067 EXPECT_FALSE(web_contents
->IsCrashed());
1070 IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest
,
1071 NavigateFromDefaultToOptionsInSameTab
) {
1073 content::WindowedNotificationObserver
observer(
1074 content::NOTIFICATION_LOAD_STOP
,
1075 content::NotificationService::AllSources());
1076 chrome::ShowSettings(browser());
1079 EXPECT_EQ(1, browser()->tab_strip_model()->count());
1080 EXPECT_EQ(GetSettingsURL(),
1081 ShortenUberURL(browser()->tab_strip_model()->
1082 GetActiveWebContents()->GetURL()));
1085 IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest
,
1086 NavigateFromBlankToOptionsInSameTab
) {
1087 chrome::NavigateParams
p(MakeNavigateParams());
1088 p
.url
= GURL(content::kAboutBlankURL
);
1089 ui_test_utils::NavigateToURL(&p
);
1092 content::WindowedNotificationObserver
observer(
1093 content::NOTIFICATION_LOAD_STOP
,
1094 content::NotificationService::AllSources());
1095 chrome::ShowSettings(browser());
1098 EXPECT_EQ(1, browser()->tab_strip_model()->count());
1099 EXPECT_EQ(GetSettingsURL(),
1100 ShortenUberURL(browser()->tab_strip_model()->
1101 GetActiveWebContents()->GetURL()));
1104 IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest
,
1105 NavigateFromNTPToOptionsInSameTab
) {
1106 chrome::NavigateParams
p(MakeNavigateParams());
1107 p
.url
= GURL(chrome::kChromeUINewTabURL
);
1108 ui_test_utils::NavigateToURL(&p
);
1109 EXPECT_EQ(1, browser()->tab_strip_model()->count());
1110 EXPECT_EQ(GURL(chrome::kChromeUINewTabURL
),
1111 browser()->tab_strip_model()->GetActiveWebContents()->GetURL());
1114 content::WindowedNotificationObserver
observer(
1115 content::NOTIFICATION_LOAD_STOP
,
1116 content::NotificationService::AllSources());
1117 chrome::ShowSettings(browser());
1120 EXPECT_EQ(1, browser()->tab_strip_model()->count());
1121 EXPECT_EQ(GetSettingsURL(),
1122 ShortenUberURL(browser()->tab_strip_model()->
1123 GetActiveWebContents()->GetURL()));
1126 IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest
,
1127 NavigateFromPageToOptionsInNewTab
) {
1128 chrome::NavigateParams
p(MakeNavigateParams());
1129 ui_test_utils::NavigateToURL(&p
);
1130 EXPECT_EQ(GetGoogleURL(),
1131 browser()->tab_strip_model()->GetActiveWebContents()->GetURL());
1132 EXPECT_EQ(1u, chrome::GetTotalBrowserCount());
1133 EXPECT_EQ(1, browser()->tab_strip_model()->count());
1136 content::WindowedNotificationObserver
observer(
1137 content::NOTIFICATION_LOAD_STOP
,
1138 content::NotificationService::AllSources());
1139 chrome::ShowSettings(browser());
1142 EXPECT_EQ(2, browser()->tab_strip_model()->count());
1143 EXPECT_EQ(GetSettingsURL(),
1144 ShortenUberURL(browser()->tab_strip_model()->
1145 GetActiveWebContents()->GetURL()));
1148 IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest
,
1149 NavigateFromNTPToOptionsSingleton
) {
1151 content::WindowedNotificationObserver
observer(
1152 content::NOTIFICATION_LOAD_STOP
,
1153 content::NotificationService::AllSources());
1154 chrome::ShowSettings(browser());
1157 EXPECT_EQ(1, browser()->tab_strip_model()->count());
1159 chrome::NewTab(browser());
1160 EXPECT_EQ(2, browser()->tab_strip_model()->count());
1163 content::WindowedNotificationObserver
observer(
1164 content::NOTIFICATION_LOAD_STOP
,
1165 content::NotificationService::AllSources());
1166 chrome::ShowSettings(browser());
1169 EXPECT_EQ(2, browser()->tab_strip_model()->count());
1170 EXPECT_EQ(GetSettingsURL(),
1171 ShortenUberURL(browser()->tab_strip_model()->
1172 GetActiveWebContents()->GetURL()));
1175 IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest
,
1176 NavigateFromNTPToOptionsPageInSameTab
) {
1178 content::WindowedNotificationObserver
observer(
1179 content::NOTIFICATION_LOAD_STOP
,
1180 content::NotificationService::AllSources());
1181 chrome::ShowClearBrowsingDataDialog(browser());
1184 EXPECT_EQ(1, browser()->tab_strip_model()->count());
1185 EXPECT_EQ(GetClearBrowsingDataURL(),
1186 browser()->tab_strip_model()->GetActiveWebContents()->GetURL());
1188 chrome::NewTab(browser());
1189 EXPECT_EQ(2, browser()->tab_strip_model()->count());
1192 content::WindowedNotificationObserver
observer(
1193 content::NOTIFICATION_LOAD_STOP
,
1194 content::NotificationService::AllSources());
1195 chrome::ShowClearBrowsingDataDialog(browser());
1198 EXPECT_EQ(2, browser()->tab_strip_model()->count());
1199 EXPECT_EQ(GetClearBrowsingDataURL(),
1200 browser()->tab_strip_model()->GetActiveWebContents()->GetURL());
1203 IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest
,
1204 NavigateFromOtherTabToSingletonOptions
) {
1206 content::WindowedNotificationObserver
observer(
1207 content::NOTIFICATION_LOAD_STOP
,
1208 content::NotificationService::AllSources());
1209 chrome::ShowSettings(browser());
1213 content::WindowedNotificationObserver
observer(
1214 content::NOTIFICATION_LOAD_STOP
,
1215 content::NotificationService::AllSources());
1216 chrome::AddSelectedTabWithURL(browser(), GetGoogleURL(),
1217 content::PAGE_TRANSITION_LINK
);
1221 // This load should simply cause a tab switch.
1222 chrome::ShowSettings(browser());
1224 EXPECT_EQ(2, browser()->tab_strip_model()->count());
1225 EXPECT_EQ(GetSettingsURL(),
1226 ShortenUberURL(browser()->tab_strip_model()->
1227 GetActiveWebContents()->GetURL()));
1230 IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest
, CloseSingletonTab
) {
1231 for (int i
= 0; i
< 2; ++i
) {
1232 content::WindowedNotificationObserver
observer(
1233 content::NOTIFICATION_LOAD_STOP
,
1234 content::NotificationService::AllSources());
1235 chrome::AddSelectedTabWithURL(browser(), GetGoogleURL(),
1236 content::PAGE_TRANSITION_TYPED
);
1240 browser()->tab_strip_model()->ActivateTabAt(0, true);
1243 content::WindowedNotificationObserver
observer(
1244 content::NOTIFICATION_LOAD_STOP
,
1245 content::NotificationService::AllSources());
1246 chrome::ShowSettings(browser());
1250 EXPECT_TRUE(browser()->tab_strip_model()->CloseWebContentsAt(
1251 2, TabStripModel::CLOSE_USER_GESTURE
));
1252 EXPECT_EQ(0, browser()->tab_strip_model()->active_index());
1255 // TODO(csilv): Update this for uber page. http://crbug.com/111579.
1256 IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest
,
1257 DISABLED_NavigateFromDefaultToHistoryInSameTab
) {
1259 content::WindowedNotificationObserver
observer(
1260 content::NOTIFICATION_LOAD_STOP
,
1261 content::NotificationService::AllSources());
1262 chrome::ShowHistory(browser());
1265 EXPECT_EQ(1, browser()->tab_strip_model()->count());
1266 EXPECT_EQ(GURL(chrome::kChromeUIHistoryFrameURL
),
1267 browser()->tab_strip_model()->GetActiveWebContents()->GetURL());
1270 // TODO(linux_aura) http://crbug.com/163931
1271 #if defined(OS_LINUX) && !defined(OS_CHROMEOS) && defined(USE_AURA)
1272 #define MAYBE_NavigateFromDefaultToBookmarksInSameTab DISABLED_NavigateFromDefaultToBookmarksInSameTab
1274 #define MAYBE_NavigateFromDefaultToBookmarksInSameTab NavigateFromDefaultToBookmarksInSameTab
1276 IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest
,
1277 MAYBE_NavigateFromDefaultToBookmarksInSameTab
) {
1279 content::WindowedNotificationObserver
observer(
1280 content::NOTIFICATION_LOAD_STOP
,
1281 content::NotificationService::AllSources());
1282 chrome::ShowBookmarkManager(browser());
1285 EXPECT_EQ(1, browser()->tab_strip_model()->count());
1286 EXPECT_TRUE(StartsWithASCII(
1287 browser()->tab_strip_model()->GetActiveWebContents()->GetURL().spec(),
1288 chrome::kChromeUIBookmarksURL
,
1292 IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest
,
1293 NavigateFromDefaultToDownloadsInSameTab
) {
1295 content::WindowedNotificationObserver
observer(
1296 content::NOTIFICATION_LOAD_STOP
,
1297 content::NotificationService::AllSources());
1298 chrome::ShowDownloads(browser());
1301 EXPECT_EQ(1, browser()->tab_strip_model()->count());
1302 EXPECT_EQ(GURL(chrome::kChromeUIDownloadsURL
),
1303 browser()->tab_strip_model()->GetActiveWebContents()->GetURL());
1306 IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest
,
1307 NavigateWithoutBrowser
) {
1308 // First navigate using the profile of the existing browser window, and
1309 // check that the window is reused.
1310 chrome::NavigateParams
params(browser()->profile(), GetGoogleURL(),
1311 content::PAGE_TRANSITION_LINK
);
1312 ui_test_utils::NavigateToURL(¶ms
);
1313 EXPECT_EQ(1u, chrome::GetTotalBrowserCount());
1315 // Now navigate using the incognito profile and check that a new window
1317 chrome::NavigateParams
params_incognito(
1318 browser()->profile()->GetOffTheRecordProfile(),
1319 GetGoogleURL(), content::PAGE_TRANSITION_LINK
);
1320 ui_test_utils::NavigateToURL(¶ms_incognito
);
1321 EXPECT_EQ(2u, chrome::GetTotalBrowserCount());
1324 IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest
, ViewSourceIsntSingleton
) {
1325 const std::string viewsource_ntp_url
=
1326 std::string(content::kViewSourceScheme
) + ":" +
1327 chrome::kChromeUIVersionURL
;
1329 chrome::NavigateParams
viewsource_params(browser(),
1330 GURL(viewsource_ntp_url
),
1331 content::PAGE_TRANSITION_LINK
);
1332 ui_test_utils::NavigateToURL(&viewsource_params
);
1334 chrome::NavigateParams
singleton_params(browser(),
1335 GURL(chrome::kChromeUIVersionURL
),
1336 content::PAGE_TRANSITION_LINK
);
1337 singleton_params
.disposition
= SINGLETON_TAB
;
1338 EXPECT_EQ(-1, chrome::GetIndexOfSingletonTab(&singleton_params
));
1341 // This test verifies that browser initiated navigations can send requests
1343 IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest
,
1344 SendBrowserInitiatedRequestUsingPOST
) {
1345 // Uses a test sever to verify POST request.
1346 ASSERT_TRUE(test_server()->Start());
1348 // Open a browser initiated POST request in new foreground tab.
1349 base::string16
expected_title(base::ASCIIToUTF16(kExpectedTitle
));
1350 std::string post_data
= kExpectedTitle
;
1351 base::string16 title
;
1352 ASSERT_TRUE(OpenPOSTURLInNewForegroundTabAndGetTitle(
1353 test_server()->GetURL(kEchoTitleCommand
), post_data
, true, &title
));
1354 EXPECT_EQ(expected_title
, title
);
1357 // This test verifies that renderer initiated navigations can NOT send requests
1359 IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest
,
1360 SendRendererInitiatedRequestUsingPOST
) {
1361 // Uses a test sever to verify POST request.
1362 ASSERT_TRUE(test_server()->Start());
1364 // Open a renderer initiated POST request in new foreground tab.
1365 base::string16
expected_title(base::ASCIIToUTF16(kExpectedTitle
));
1366 std::string post_data
= kExpectedTitle
;
1367 base::string16 title
;
1368 ASSERT_TRUE(OpenPOSTURLInNewForegroundTabAndGetTitle(
1369 test_server()->GetURL(kEchoTitleCommand
), post_data
, false, &title
));
1370 EXPECT_NE(expected_title
, title
);