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/string_util.h"
10 #include "base/strings/utf_string_conversions.h"
11 #include "chrome/app/chrome_command_ids.h"
12 #include "chrome/browser/prefs/incognito_mode_prefs.h"
13 #include "chrome/browser/profiles/profile.h"
14 #include "chrome/browser/ui/browser.h"
15 #include "chrome/browser/ui/browser_commands.h"
16 #include "chrome/browser/ui/browser_finder.h"
17 #include "chrome/browser/ui/browser_navigator.h"
18 #include "chrome/browser/ui/browser_tabstrip.h"
19 #include "chrome/browser/ui/browser_window.h"
20 #include "chrome/browser/ui/chrome_pages.h"
21 #include "chrome/browser/ui/singleton_tabs.h"
22 #include "chrome/browser/ui/tabs/tab_strip_model.h"
23 #include "chrome/common/chrome_switches.h"
24 #include "chrome/common/pref_names.h"
25 #include "chrome/common/url_constants.h"
26 #include "chrome/test/base/ui_test_utils.h"
27 #include "content/public/browser/notification_service.h"
28 #include "content/public/browser/notification_types.h"
29 #include "content/public/browser/web_contents.h"
31 using content::WebContents
;
35 const char kExpectedTitle
[] = "PASSED!";
36 const char kEchoTitleCommand
[] = "echotitle";
39 return GURL("http://www.google.com/");
42 GURL
GetSettingsURL() {
43 return GURL(chrome::kChromeUISettingsURL
);
46 GURL
GetContentSettingsURL() {
47 return GetSettingsURL().Resolve(chrome::kContentSettingsExceptionsSubPage
);
50 GURL
GetClearBrowsingDataURL() {
51 return GetSettingsURL().Resolve(chrome::kClearBrowserDataSubPage
);
54 // Converts long uber URLs ("chrome://chrome/foo/") to short (virtual) URLs
55 // ("chrome://foo/"). This should be used to convert the return value of
56 // WebContentsImpl::GetURL before comparison because it can return either the
57 // real URL or the virtual URL.
58 GURL
ShortenUberURL(const GURL
& url
) {
59 std::string url_string
= url
.spec();
60 const std::string long_prefix
= "chrome://chrome/";
61 const std::string short_prefix
= "chrome://";
62 if (url_string
.find(long_prefix
) != 0)
64 url_string
.replace(0, long_prefix
.length(), short_prefix
);
65 return GURL(url_string
);
70 chrome::NavigateParams
BrowserNavigatorTest::MakeNavigateParams() const {
71 return MakeNavigateParams(browser());
74 chrome::NavigateParams
BrowserNavigatorTest::MakeNavigateParams(
75 Browser
* browser
) const {
76 chrome::NavigateParams
params(browser
, GetGoogleURL(),
77 content::PAGE_TRANSITION_LINK
);
78 params
.window_action
= chrome::NavigateParams::SHOW_WINDOW
;
82 bool BrowserNavigatorTest::OpenPOSTURLInNewForegroundTabAndGetTitle(
83 const GURL
& url
, const std::string
& post_data
, bool is_browser_initiated
,
84 base::string16
* title
) {
85 chrome::NavigateParams
param(MakeNavigateParams());
86 param
.disposition
= NEW_FOREGROUND_TAB
;
88 param
.is_renderer_initiated
= !is_browser_initiated
;
89 param
.uses_post
= true;
90 param
.browser_initiated_post_data
= new base::RefCountedStaticMemory(
91 post_data
.data(), post_data
.size());
93 ui_test_utils::NavigateToURL(¶m
);
94 if (!param
.target_contents
)
97 // Navigate() should have opened the contents in new foreground tab in the
99 EXPECT_EQ(browser(), param
.browser
);
100 EXPECT_EQ(browser()->tab_strip_model()->GetActiveWebContents(),
101 param
.target_contents
);
102 // We should have one window, with one tab.
103 EXPECT_EQ(1u, chrome::GetTotalBrowserCount());
104 EXPECT_EQ(2, browser()->tab_strip_model()->count());
106 *title
= param
.target_contents
->GetTitle();
110 Browser
* BrowserNavigatorTest::CreateEmptyBrowserForType(Browser::Type type
,
112 Browser
* browser
= new Browser(
113 Browser::CreateParams(type
, profile
, chrome::GetActiveDesktop()));
114 chrome::AddTabAt(browser
, GURL(), -1, true);
118 Browser
* BrowserNavigatorTest::CreateEmptyBrowserForApp(Profile
* profile
) {
119 Browser
* browser
= new Browser(
120 Browser::CreateParams::CreateForApp(
121 "Test", false /* trusted_source */, gfx::Rect(), profile
,
122 chrome::GetActiveDesktop()));
123 chrome::AddTabAt(browser
, GURL(), -1, true);
127 WebContents
* BrowserNavigatorTest::CreateWebContents() {
128 content::WebContents::CreateParams
create_params(browser()->profile());
129 content::WebContents
* base_web_contents
=
130 browser()->tab_strip_model()->GetActiveWebContents();
131 if (base_web_contents
) {
132 create_params
.initial_size
=
133 base_web_contents
->GetContainerBounds().size();
135 return WebContents::Create(create_params
);
138 void BrowserNavigatorTest::RunSuppressTest(WindowOpenDisposition disposition
) {
139 GURL old_url
= browser()->tab_strip_model()->GetActiveWebContents()->GetURL();
140 chrome::NavigateParams
p(MakeNavigateParams());
141 p
.disposition
= disposition
;
142 chrome::Navigate(&p
);
144 // Nothing should have happened as a result of Navigate();
145 EXPECT_EQ(1, browser()->tab_strip_model()->count());
146 EXPECT_EQ(1u, chrome::GetTotalBrowserCount());
148 browser()->tab_strip_model()->GetActiveWebContents()->GetURL());
151 void BrowserNavigatorTest::RunUseNonIncognitoWindowTest(const GURL
& url
) {
152 Browser
* incognito_browser
= CreateIncognitoBrowser();
154 EXPECT_EQ(2u, chrome::GetTotalBrowserCount());
155 EXPECT_EQ(1, browser()->tab_strip_model()->count());
156 EXPECT_EQ(1, incognito_browser
->tab_strip_model()->count());
158 // Navigate to the page.
159 chrome::NavigateParams
p(MakeNavigateParams(incognito_browser
));
160 p
.disposition
= SINGLETON_TAB
;
162 p
.window_action
= chrome::NavigateParams::SHOW_WINDOW
;
163 chrome::Navigate(&p
);
165 // This page should be opened in browser() window.
166 EXPECT_NE(incognito_browser
, p
.browser
);
167 EXPECT_EQ(browser(), p
.browser
);
168 EXPECT_EQ(2, browser()->tab_strip_model()->count());
170 browser()->tab_strip_model()->GetActiveWebContents()->GetURL());
173 void BrowserNavigatorTest::RunDoNothingIfIncognitoIsForcedTest(
175 Browser
* browser
= CreateIncognitoBrowser();
177 // Set kIncognitoModeAvailability to FORCED.
178 PrefService
* prefs1
= browser
->profile()->GetPrefs();
179 prefs1
->SetInteger(prefs::kIncognitoModeAvailability
,
180 IncognitoModePrefs::FORCED
);
181 PrefService
* prefs2
= browser
->profile()->GetOriginalProfile()->GetPrefs();
182 prefs2
->SetInteger(prefs::kIncognitoModeAvailability
,
183 IncognitoModePrefs::FORCED
);
185 // Navigate to the page.
186 chrome::NavigateParams
p(MakeNavigateParams(browser
));
187 p
.disposition
= OFF_THE_RECORD
;
189 p
.window_action
= chrome::NavigateParams::SHOW_WINDOW
;
190 chrome::Navigate(&p
);
192 // The page should not be opened.
193 EXPECT_EQ(browser
, p
.browser
);
194 EXPECT_EQ(1, browser
->tab_strip_model()->count());
195 EXPECT_EQ(GURL(content::kAboutBlankURL
),
196 browser
->tab_strip_model()->GetActiveWebContents()->GetURL());
199 void BrowserNavigatorTest::Observe(
201 const content::NotificationSource
& source
,
202 const content::NotificationDetails
& details
) {
204 case content::NOTIFICATION_WEB_CONTENTS_RENDER_VIEW_HOST_CREATED
: {
205 ++this->created_tab_contents_count_
;
216 // This test verifies that when a navigation occurs within a tab, the tab count
217 // of the Browser remains the same and the current tab bears the loaded URL.
218 // Note that network URLs are not actually loaded in tests, so this also tests
219 // that error pages leave the intended URL in the address bar.
220 IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest
, Disposition_CurrentTab
) {
221 ui_test_utils::NavigateToURL(browser(), GetGoogleURL());
222 EXPECT_EQ(GetGoogleURL(),
223 browser()->tab_strip_model()->GetActiveWebContents()->GetURL());
224 // We should have one window with one tab.
225 EXPECT_EQ(1u, chrome::GetTotalBrowserCount());
226 EXPECT_EQ(1, browser()->tab_strip_model()->count());
229 // This test verifies that a singleton tab is refocused if one is already opened
230 // in another or an existing window, or added if it is not.
231 IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest
, Disposition_SingletonTabExisting
) {
232 GURL
singleton_url1("http://maps.google.com/");
234 // Register for a notification if an additional WebContents was instantiated.
235 // Opening a Singleton tab that is already opened should not be opening a new
236 // tab nor be creating a new WebContents object.
237 content::NotificationRegistrar registrar
;
239 // As the registrar object goes out of scope, this will get unregistered
241 content::NOTIFICATION_WEB_CONTENTS_RENDER_VIEW_HOST_CREATED
,
242 content::NotificationService::AllSources());
244 chrome::AddSelectedTabWithURL(browser(), singleton_url1
,
245 content::PAGE_TRANSITION_LINK
);
246 chrome::AddSelectedTabWithURL(browser(), GetGoogleURL(),
247 content::PAGE_TRANSITION_LINK
);
249 // We should have one browser with 3 tabs, the 3rd selected.
250 EXPECT_EQ(1u, chrome::GetTotalBrowserCount());
251 EXPECT_EQ(2, browser()->tab_strip_model()->active_index());
253 unsigned int previous_tab_contents_count
=
254 created_tab_contents_count_
= 0;
256 // Navigate to singleton_url1.
257 chrome::NavigateParams
p(MakeNavigateParams());
258 p
.disposition
= SINGLETON_TAB
;
259 p
.url
= singleton_url1
;
260 chrome::Navigate(&p
);
262 // The middle tab should now be selected.
263 EXPECT_EQ(browser(), p
.browser
);
264 EXPECT_EQ(1, browser()->tab_strip_model()->active_index());
266 // No tab contents should have been created
267 EXPECT_EQ(previous_tab_contents_count
,
268 created_tab_contents_count_
);
271 IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest
,
272 Disposition_SingletonTabRespectingRef
) {
273 GURL
singleton_ref_url1("http://maps.google.com/#a");
274 GURL
singleton_ref_url2("http://maps.google.com/#b");
275 GURL
singleton_ref_url3("http://maps.google.com/");
277 chrome::AddSelectedTabWithURL(browser(), singleton_ref_url1
,
278 content::PAGE_TRANSITION_LINK
);
280 // We should have one browser with 2 tabs, 2nd selected.
281 EXPECT_EQ(1u, chrome::GetTotalBrowserCount());
282 EXPECT_EQ(2, browser()->tab_strip_model()->count());
283 EXPECT_EQ(1, browser()->tab_strip_model()->active_index());
285 // Navigate to singleton_url2.
286 chrome::NavigateParams
p(MakeNavigateParams());
287 p
.disposition
= SINGLETON_TAB
;
288 p
.url
= singleton_ref_url2
;
289 chrome::Navigate(&p
);
291 // We should now have 2 tabs, the 2nd one selected.
292 EXPECT_EQ(browser(), p
.browser
);
293 EXPECT_EQ(2, browser()->tab_strip_model()->count());
294 EXPECT_EQ(1, browser()->tab_strip_model()->active_index());
296 // Navigate to singleton_url2, but with respect ref set.
297 p
= MakeNavigateParams();
298 p
.disposition
= SINGLETON_TAB
;
299 p
.url
= singleton_ref_url2
;
300 p
.ref_behavior
= chrome::NavigateParams::RESPECT_REF
;
301 chrome::Navigate(&p
);
303 // We should now have 3 tabs, the 3th one selected.
304 EXPECT_EQ(browser(), p
.browser
);
305 EXPECT_EQ(3, browser()->tab_strip_model()->count());
306 EXPECT_EQ(2, browser()->tab_strip_model()->active_index());
308 // Navigate to singleton_url3.
309 p
= MakeNavigateParams();
310 p
.disposition
= SINGLETON_TAB
;
311 p
.url
= singleton_ref_url3
;
312 p
.ref_behavior
= chrome::NavigateParams::RESPECT_REF
;
313 chrome::Navigate(&p
);
315 // We should now have 4 tabs, the 4th one selected.
316 EXPECT_EQ(browser(), p
.browser
);
317 EXPECT_EQ(4, browser()->tab_strip_model()->count());
318 EXPECT_EQ(3, browser()->tab_strip_model()->active_index());
321 IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest
,
322 Disposition_SingletonTabNoneExisting
) {
323 GURL
singleton_url1("http://maps.google.com/");
325 // We should have one browser with 1 tab.
326 EXPECT_EQ(1u, chrome::GetTotalBrowserCount());
327 EXPECT_EQ(0, browser()->tab_strip_model()->active_index());
329 // Navigate to singleton_url1.
330 chrome::NavigateParams
p(MakeNavigateParams());
331 p
.disposition
= SINGLETON_TAB
;
332 p
.url
= singleton_url1
;
333 chrome::Navigate(&p
);
335 // We should now have 2 tabs, the 2nd one selected.
336 EXPECT_EQ(browser(), p
.browser
);
337 EXPECT_EQ(2, browser()->tab_strip_model()->count());
338 EXPECT_EQ(1, browser()->tab_strip_model()->active_index());
341 // This test verifies that when a navigation results in a foreground tab, the
342 // tab count of the Browser increases and the selected tab shifts to the new
344 IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest
, Disposition_NewForegroundTab
) {
345 WebContents
* old_contents
=
346 browser()->tab_strip_model()->GetActiveWebContents();
347 chrome::NavigateParams
p(MakeNavigateParams());
348 p
.disposition
= NEW_FOREGROUND_TAB
;
349 chrome::Navigate(&p
);
350 EXPECT_NE(old_contents
,
351 browser()->tab_strip_model()->GetActiveWebContents());
352 EXPECT_EQ(browser()->tab_strip_model()->GetActiveWebContents(),
354 EXPECT_EQ(2, browser()->tab_strip_model()->count());
357 // This test verifies that when a navigation results in a background tab, the
358 // tab count of the Browser increases but the selected tab remains the same.
359 IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest
, Disposition_NewBackgroundTab
) {
360 WebContents
* old_contents
=
361 browser()->tab_strip_model()->GetActiveWebContents();
362 chrome::NavigateParams
p(MakeNavigateParams());
363 p
.disposition
= NEW_BACKGROUND_TAB
;
364 chrome::Navigate(&p
);
365 WebContents
* new_contents
=
366 browser()->tab_strip_model()->GetActiveWebContents();
367 // The selected tab should have remained unchanged, since the new tab was
368 // opened in the background.
369 EXPECT_EQ(old_contents
, new_contents
);
370 EXPECT_EQ(2, browser()->tab_strip_model()->count());
373 // This test verifies that when a navigation requiring a new foreground tab
374 // occurs in a Browser that cannot host multiple tabs, the new foreground tab
375 // is created in an existing compatible Browser.
376 IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest
,
377 Disposition_IncompatibleWindow_Existing
) {
378 // Open a foreground tab in a window that cannot open popups when there is an
379 // existing compatible window somewhere else that they can be opened within.
380 Browser
* popup
= CreateEmptyBrowserForType(Browser::TYPE_POPUP
,
381 browser()->profile());
382 chrome::NavigateParams
p(MakeNavigateParams(popup
));
383 p
.disposition
= NEW_FOREGROUND_TAB
;
384 chrome::Navigate(&p
);
386 // Navigate() should have opened the tab in a different browser since the
387 // one we supplied didn't support additional tabs.
388 EXPECT_NE(popup
, p
.browser
);
390 // Since browser() is an existing compatible tabbed browser, it should have
391 // opened the tab there.
392 EXPECT_EQ(browser(), p
.browser
);
394 // We should be left with 2 windows, the popup with one tab and the browser()
395 // provided by the framework with two.
396 EXPECT_EQ(2u, chrome::GetTotalBrowserCount());
397 EXPECT_EQ(1, popup
->tab_strip_model()->count());
398 EXPECT_EQ(2, browser()->tab_strip_model()->count());
401 // This test verifies that when a navigation requiring a new foreground tab
402 // occurs in a Browser that cannot host multiple tabs and no compatible Browser
403 // that can is open, a compatible Browser is created.
404 IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest
,
405 Disposition_IncompatibleWindow_NoExisting
) {
406 // We want to simulate not being able to find an existing window compatible
407 // with our non-tabbed browser window so Navigate() is forced to create a
408 // new compatible window. Because browser() supplied by the in-process
409 // browser testing framework is compatible with browser()->profile(), we
410 // need a different profile, and creating a popup window with an incognito
411 // profile is a quick and dirty way of achieving this.
412 Browser
* popup
= CreateEmptyBrowserForType(
414 browser()->profile()->GetOffTheRecordProfile());
415 chrome::NavigateParams
p(MakeNavigateParams(popup
));
416 p
.disposition
= NEW_FOREGROUND_TAB
;
417 chrome::Navigate(&p
);
419 // Navigate() should have opened the tab in a different browser since the
420 // one we supplied didn't support additional tabs.
421 EXPECT_NE(popup
, p
.browser
);
423 // This time, browser() is _not_ compatible with popup since it is not an
425 EXPECT_NE(browser(), p
.browser
);
427 // We should have three windows, each with one tab:
428 // 1. the browser() provided by the framework (unchanged in this test)
429 // 2. the incognito popup we created originally
430 // 3. the new incognito tabbed browser that was created by Navigate().
431 EXPECT_EQ(3u, chrome::GetTotalBrowserCount());
432 EXPECT_EQ(1, browser()->tab_strip_model()->count());
433 EXPECT_EQ(1, popup
->tab_strip_model()->count());
434 EXPECT_EQ(1, p
.browser
->tab_strip_model()->count());
435 EXPECT_TRUE(p
.browser
->is_type_tabbed());
438 // This test verifies that navigating with WindowOpenDisposition = NEW_POPUP
439 // from a normal Browser results in a new Browser with TYPE_POPUP.
440 IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest
, Disposition_NewPopup
) {
441 chrome::NavigateParams
p(MakeNavigateParams());
442 p
.disposition
= NEW_POPUP
;
443 p
.window_bounds
= gfx::Rect(0, 0, 200, 200);
444 // Wait for new popup to to load and gain focus.
445 ui_test_utils::NavigateToURL(&p
);
447 // Navigate() should have opened a new, focused popup window.
448 EXPECT_NE(browser(), p
.browser
);
450 // TODO(stevenjb): Enable this test. See: crbug.com/79493
451 EXPECT_TRUE(p
.browser
->window()->IsActive());
453 EXPECT_TRUE(p
.browser
->is_type_popup());
454 EXPECT_FALSE(p
.browser
->is_app());
456 // We should have two windows, the browser() provided by the framework and the
458 EXPECT_EQ(2u, chrome::GetTotalBrowserCount());
459 EXPECT_EQ(1, browser()->tab_strip_model()->count());
460 EXPECT_EQ(1, p
.browser
->tab_strip_model()->count());
463 // This test verifies that navigating with WindowOpenDisposition = NEW_POPUP
464 // from a normal Browser results in a new Browser with is_app() true.
465 IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest
, Disposition_NewPopup_ExtensionId
) {
466 chrome::NavigateParams
p(MakeNavigateParams());
467 p
.disposition
= NEW_POPUP
;
468 p
.extension_app_id
= "extensionappid";
469 p
.window_bounds
= gfx::Rect(0, 0, 200, 200);
470 // Wait for new popup to to load and gain focus.
471 ui_test_utils::NavigateToURL(&p
);
473 // Navigate() should have opened a new, focused popup window.
474 EXPECT_NE(browser(), p
.browser
);
475 EXPECT_TRUE(p
.browser
->is_type_popup());
476 EXPECT_TRUE(p
.browser
->is_app());
478 // We should have two windows, the browser() provided by the framework and the
480 EXPECT_EQ(2u, chrome::GetTotalBrowserCount());
481 EXPECT_EQ(1, browser()->tab_strip_model()->count());
482 EXPECT_EQ(1, p
.browser
->tab_strip_model()->count());
485 // This test verifies that navigating with WindowOpenDisposition = NEW_POPUP
486 // from a normal popup results in a new Browser with TYPE_POPUP.
487 IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest
, Disposition_NewPopupFromPopup
) {
489 chrome::NavigateParams
p1(MakeNavigateParams());
490 p1
.disposition
= NEW_POPUP
;
491 p1
.window_bounds
= gfx::Rect(0, 0, 200, 200);
492 chrome::Navigate(&p1
);
493 // Open another popup.
494 chrome::NavigateParams
p2(MakeNavigateParams(p1
.browser
));
495 p2
.disposition
= NEW_POPUP
;
496 p2
.window_bounds
= gfx::Rect(0, 0, 200, 200);
497 chrome::Navigate(&p2
);
499 // Navigate() should have opened a new normal popup window.
500 EXPECT_NE(p1
.browser
, p2
.browser
);
501 EXPECT_TRUE(p2
.browser
->is_type_popup());
502 EXPECT_FALSE(p2
.browser
->is_app());
504 // We should have three windows, the browser() provided by the framework,
505 // the first popup window, and the second popup window.
506 EXPECT_EQ(3u, chrome::GetTotalBrowserCount());
507 EXPECT_EQ(1, browser()->tab_strip_model()->count());
508 EXPECT_EQ(1, p1
.browser
->tab_strip_model()->count());
509 EXPECT_EQ(1, p2
.browser
->tab_strip_model()->count());
512 // This test verifies that navigating with WindowOpenDisposition = NEW_POPUP
513 // from an app frame results in a new Browser with TYPE_POPUP.
514 IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest
,
515 Disposition_NewPopupFromAppWindow
) {
516 Browser
* app_browser
= CreateEmptyBrowserForApp(browser()->profile());
517 chrome::NavigateParams
p(MakeNavigateParams(app_browser
));
518 p
.disposition
= NEW_POPUP
;
519 p
.window_bounds
= gfx::Rect(0, 0, 200, 200);
520 chrome::Navigate(&p
);
522 // Navigate() should have opened a new popup app window.
523 EXPECT_NE(app_browser
, p
.browser
);
524 EXPECT_NE(browser(), p
.browser
);
525 EXPECT_TRUE(p
.browser
->is_type_popup());
526 EXPECT_TRUE(p
.browser
->is_app());
528 // We should now have three windows, the app window, the app popup it created,
529 // and the original browser() provided by the framework.
530 EXPECT_EQ(3u, chrome::GetTotalBrowserCount());
531 EXPECT_EQ(1, browser()->tab_strip_model()->count());
532 EXPECT_EQ(1, app_browser
->tab_strip_model()->count());
533 EXPECT_EQ(1, p
.browser
->tab_strip_model()->count());
536 // This test verifies that navigating with WindowOpenDisposition = NEW_POPUP
537 // from an app popup results in a new Browser also of TYPE_POPUP.
538 IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest
,
539 Disposition_NewPopupFromAppPopup
) {
540 Browser
* app_browser
= CreateEmptyBrowserForApp(browser()->profile());
541 // Open an app popup.
542 chrome::NavigateParams
p1(MakeNavigateParams(app_browser
));
543 p1
.disposition
= NEW_POPUP
;
544 p1
.window_bounds
= gfx::Rect(0, 0, 200, 200);
545 chrome::Navigate(&p1
);
546 // Now open another app popup.
547 chrome::NavigateParams
p2(MakeNavigateParams(p1
.browser
));
548 p2
.disposition
= NEW_POPUP
;
549 p2
.window_bounds
= gfx::Rect(0, 0, 200, 200);
550 chrome::Navigate(&p2
);
552 // Navigate() should have opened a new popup app window.
553 EXPECT_NE(browser(), p1
.browser
);
554 EXPECT_NE(p1
.browser
, p2
.browser
);
555 EXPECT_TRUE(p2
.browser
->is_type_popup());
556 EXPECT_TRUE(p2
.browser
->is_app());
558 // We should now have four windows, the app window, the first app popup,
559 // the second app popup, and the original browser() provided by the framework.
560 EXPECT_EQ(4u, chrome::GetTotalBrowserCount());
561 EXPECT_EQ(1, browser()->tab_strip_model()->count());
562 EXPECT_EQ(1, app_browser
->tab_strip_model()->count());
563 EXPECT_EQ(1, p1
.browser
->tab_strip_model()->count());
564 EXPECT_EQ(1, p2
.browser
->tab_strip_model()->count());
567 // This test verifies that navigating with WindowOpenDisposition = NEW_POPUP
568 // from an extension app tab results in a new Browser with TYPE_APP_POPUP.
569 IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest
,
570 Disposition_NewPopupFromExtensionApp
) {
574 // This test verifies that navigating with window_action = SHOW_WINDOW_INACTIVE
575 // does not focus a new new popup window.
576 IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest
, Disposition_NewPopupUnfocused
) {
577 chrome::NavigateParams
p(MakeNavigateParams());
578 p
.disposition
= NEW_POPUP
;
579 p
.window_bounds
= gfx::Rect(0, 0, 200, 200);
580 p
.window_action
= chrome::NavigateParams::SHOW_WINDOW_INACTIVE
;
581 // Wait for new popup to load (and gain focus if the test fails).
582 ui_test_utils::NavigateToURL(&p
);
584 // Navigate() should have opened a new, unfocused, popup window.
585 EXPECT_NE(browser(), p
.browser
);
586 EXPECT_EQ(Browser::TYPE_POPUP
, p
.browser
->type());
588 // TODO(stevenjb): Enable this test. See: crbug.com/79493
589 EXPECT_FALSE(p
.browser
->window()->IsActive());
593 // This test verifies that navigating with WindowOpenDisposition = NEW_POPUP
594 // and trusted_source = true results in a new Browser where is_trusted_source()
596 IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest
, Disposition_NewPopupTrusted
) {
597 chrome::NavigateParams
p(MakeNavigateParams());
598 p
.disposition
= NEW_POPUP
;
599 p
.trusted_source
= true;
600 p
.window_bounds
= gfx::Rect(0, 0, 200, 200);
601 // Wait for new popup to to load and gain focus.
602 ui_test_utils::NavigateToURL(&p
);
604 // Navigate() should have opened a new popup window of TYPE_TRUSTED_POPUP.
605 EXPECT_NE(browser(), p
.browser
);
606 EXPECT_TRUE(p
.browser
->is_type_popup());
607 EXPECT_TRUE(p
.browser
->is_trusted_source());
611 // This test verifies that navigating with WindowOpenDisposition = NEW_WINDOW
612 // always opens a new window.
613 IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest
, Disposition_NewWindow
) {
614 chrome::NavigateParams
p(MakeNavigateParams());
615 p
.disposition
= NEW_WINDOW
;
616 chrome::Navigate(&p
);
618 // Navigate() should have opened a new toplevel window.
619 EXPECT_NE(browser(), p
.browser
);
620 EXPECT_TRUE(p
.browser
->is_type_tabbed());
622 // We should now have two windows, the browser() provided by the framework and
623 // the new normal window.
624 EXPECT_EQ(2u, chrome::GetTotalBrowserCount());
625 EXPECT_EQ(1, browser()->tab_strip_model()->count());
626 EXPECT_EQ(1, p
.browser
->tab_strip_model()->count());
629 // This test verifies that navigating with WindowOpenDisposition = INCOGNITO
630 // opens a new incognito window if no existing incognito window is present.
631 IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest
, Disposition_Incognito
) {
632 chrome::NavigateParams
p(MakeNavigateParams());
633 p
.disposition
= OFF_THE_RECORD
;
634 chrome::Navigate(&p
);
636 // Navigate() should have opened a new toplevel incognito window.
637 EXPECT_NE(browser(), p
.browser
);
638 EXPECT_EQ(browser()->profile()->GetOffTheRecordProfile(),
639 p
.browser
->profile());
641 // |source_contents| should be set to NULL because the profile for the new
642 // page is different from the originating page.
643 EXPECT_EQ(NULL
, p
.source_contents
);
645 // We should now have two windows, the browser() provided by the framework and
646 // the new incognito window.
647 EXPECT_EQ(2u, chrome::GetTotalBrowserCount());
648 EXPECT_EQ(1, browser()->tab_strip_model()->count());
649 EXPECT_EQ(1, p
.browser
->tab_strip_model()->count());
652 // This test verifies that navigating with WindowOpenDisposition = INCOGNITO
653 // reuses an existing incognito window when possible.
654 IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest
, Disposition_IncognitoRefocus
) {
655 Browser
* incognito_browser
=
656 CreateEmptyBrowserForType(Browser::TYPE_TABBED
,
657 browser()->profile()->GetOffTheRecordProfile());
658 chrome::NavigateParams
p(MakeNavigateParams());
659 p
.disposition
= OFF_THE_RECORD
;
660 chrome::Navigate(&p
);
662 // Navigate() should have opened a new tab in the existing incognito window.
663 EXPECT_NE(browser(), p
.browser
);
664 EXPECT_EQ(p
.browser
, incognito_browser
);
666 // We should now have two windows, the browser() provided by the framework and
667 // the incognito window we opened earlier.
668 EXPECT_EQ(2u, chrome::GetTotalBrowserCount());
669 EXPECT_EQ(1, browser()->tab_strip_model()->count());
670 EXPECT_EQ(2, incognito_browser
->tab_strip_model()->count());
673 // This test verifies that no navigation action occurs when
674 // WindowOpenDisposition = SUPPRESS_OPEN.
675 IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest
, Disposition_SuppressOpen
) {
676 RunSuppressTest(SUPPRESS_OPEN
);
679 // This test verifies that no navigation action occurs when
680 // WindowOpenDisposition = SAVE_TO_DISK.
681 IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest
, Disposition_SaveToDisk
) {
682 RunSuppressTest(SAVE_TO_DISK
);
685 // This test verifies that no navigation action occurs when
686 // WindowOpenDisposition = IGNORE_ACTION.
687 IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest
, Disposition_IgnoreAction
) {
688 RunSuppressTest(IGNORE_ACTION
);
691 // This tests adding a foreground tab with a predefined WebContents.
692 IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest
, TargetContents_ForegroundTab
) {
693 chrome::NavigateParams
p(MakeNavigateParams());
694 p
.disposition
= NEW_FOREGROUND_TAB
;
695 p
.target_contents
= CreateWebContents();
696 chrome::Navigate(&p
);
698 // Navigate() should have opened the contents in a new foreground in the
700 EXPECT_EQ(browser(), p
.browser
);
701 EXPECT_EQ(browser()->tab_strip_model()->GetActiveWebContents(),
704 // We should have one window, with two tabs.
705 EXPECT_EQ(1u, chrome::GetTotalBrowserCount());
706 EXPECT_EQ(2, browser()->tab_strip_model()->count());
710 // This tests adding a popup with a predefined WebContents.
711 IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest
, DISABLED_TargetContents_Popup
) {
712 chrome::NavigateParams
p(MakeNavigateParams());
713 p
.disposition
= NEW_POPUP
;
714 p
.target_contents
= CreateWebContents();
715 p
.window_bounds
= gfx::Rect(10, 10, 500, 500);
716 chrome::Navigate(&p
);
718 // Navigate() should have opened a new popup window.
719 EXPECT_NE(browser(), p
.browser
);
720 EXPECT_TRUE(p
.browser
->is_type_popup());
721 EXPECT_FALSE(p
.browser
->is_app());
723 // The web platform is weird. The window bounds specified in
724 // |p.window_bounds| are used as follows:
725 // - the origin is used to position the window
726 // - the size is used to size the WebContents of the window.
727 // As such the position of the resulting window will always match
728 // p.window_bounds.origin(), but its size will not. We need to match
729 // the size against the selected tab's view's container size.
730 // Only Windows positions the window according to |p.window_bounds.origin()| -
731 // on Mac the window is offset from the opener and on Linux it always opens
733 EXPECT_EQ(p
.window_bounds
.origin(),
734 p
.browser
->window()->GetRestoredBounds().origin());
735 // All platforms should respect size however provided width > 400 (Mac has a
736 // minimum window width of 400).
737 EXPECT_EQ(p
.window_bounds
.size(),
738 p
.target_contents
->GetContainerBounds().size());
740 // We should have two windows, the new popup and the browser() provided by the
742 EXPECT_EQ(2u, chrome::GetTotalBrowserCount());
743 EXPECT_EQ(1, browser()->tab_strip_model()->count());
744 EXPECT_EQ(1, p
.browser
->tab_strip_model()->count());
748 // This tests adding a tab at a specific index.
749 IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest
, Tabstrip_InsertAtIndex
) {
750 // This is not meant to be a comprehensive test of whether or not the tab
751 // implementation of the browser observes the insertion index. That is
752 // covered by the unit tests for TabStripModel. This merely verifies that
753 // insertion index preference is reflected in common cases.
754 chrome::NavigateParams
p(MakeNavigateParams());
755 p
.disposition
= NEW_FOREGROUND_TAB
;
756 p
.tabstrip_index
= 0;
757 p
.tabstrip_add_types
= TabStripModel::ADD_FORCE_INDEX
;
758 chrome::Navigate(&p
);
760 // Navigate() should have inserted a new tab at slot 0 in the tabstrip.
761 EXPECT_EQ(browser(), p
.browser
);
762 EXPECT_EQ(0, browser()->tab_strip_model()->GetIndexOfWebContents(
763 static_cast<const WebContents
*>(p
.target_contents
)));
765 // We should have one window - the browser() provided by the framework.
766 EXPECT_EQ(1u, chrome::GetTotalBrowserCount());
767 EXPECT_EQ(2, browser()->tab_strip_model()->count());
770 // This test verifies that constructing params with disposition = SINGLETON_TAB
771 // and IGNORE_AND_NAVIGATE opens a new tab navigated to the specified URL if
772 // no previous tab with that URL (minus the path) exists.
773 IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest
,
774 Disposition_SingletonTabNew_IgnorePath
) {
775 chrome::AddSelectedTabWithURL(browser(), GetGoogleURL(),
776 content::PAGE_TRANSITION_LINK
);
778 // We should have one browser with 2 tabs, the 2nd selected.
779 EXPECT_EQ(1u, chrome::GetTotalBrowserCount());
780 EXPECT_EQ(2, browser()->tab_strip_model()->count());
781 EXPECT_EQ(1, browser()->tab_strip_model()->active_index());
783 // Navigate to a new singleton tab with a sub-page.
784 chrome::NavigateParams
p(MakeNavigateParams());
785 p
.disposition
= SINGLETON_TAB
;
786 p
.url
= GetContentSettingsURL();
787 p
.window_action
= chrome::NavigateParams::SHOW_WINDOW
;
788 p
.path_behavior
= chrome::NavigateParams::IGNORE_AND_NAVIGATE
;
789 chrome::Navigate(&p
);
791 // The last tab should now be selected and navigated to the sub-page of the
793 EXPECT_EQ(browser(), p
.browser
);
794 EXPECT_EQ(3, browser()->tab_strip_model()->count());
795 EXPECT_EQ(2, browser()->tab_strip_model()->active_index());
796 EXPECT_EQ(GetContentSettingsURL(),
797 ShortenUberURL(browser()->tab_strip_model()->
798 GetActiveWebContents()->GetURL()));
801 // This test verifies that constructing params with disposition = SINGLETON_TAB
802 // and IGNORE_AND_NAVIGATE opens an existing tab with the matching URL (minus
803 // the path) which is navigated to the specified URL.
804 IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest
,
805 Disposition_SingletonTabExisting_IgnorePath
) {
806 GURL
singleton_url1(GetSettingsURL());
807 chrome::AddSelectedTabWithURL(browser(), singleton_url1
,
808 content::PAGE_TRANSITION_LINK
);
809 chrome::AddSelectedTabWithURL(browser(), GetGoogleURL(),
810 content::PAGE_TRANSITION_LINK
);
812 // We should have one browser with 3 tabs, the 3rd selected.
813 EXPECT_EQ(1u, chrome::GetTotalBrowserCount());
814 EXPECT_EQ(3, browser()->tab_strip_model()->count());
815 EXPECT_EQ(2, browser()->tab_strip_model()->active_index());
817 // Navigate to singleton_url1.
818 chrome::NavigateParams
p(MakeNavigateParams());
819 p
.disposition
= SINGLETON_TAB
;
820 p
.url
= GetContentSettingsURL();
821 p
.window_action
= chrome::NavigateParams::SHOW_WINDOW
;
822 p
.path_behavior
= chrome::NavigateParams::IGNORE_AND_NAVIGATE
;
823 chrome::Navigate(&p
);
825 // The middle tab should now be selected and navigated to the sub-page of the
827 EXPECT_EQ(browser(), p
.browser
);
828 EXPECT_EQ(3, browser()->tab_strip_model()->count());
829 EXPECT_EQ(1, browser()->tab_strip_model()->active_index());
830 EXPECT_EQ(GetContentSettingsURL(),
831 ShortenUberURL(browser()->tab_strip_model()->
832 GetActiveWebContents()->GetURL()));
835 // This test verifies that constructing params with disposition = SINGLETON_TAB
836 // and IGNORE_AND_NAVIGATE opens an existing tab with the matching URL (minus
837 // the path) which is navigated to the specified URL.
838 IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest
,
839 Disposition_SingletonTabExistingSubPath_IgnorePath
) {
840 GURL
singleton_url1(GetContentSettingsURL());
841 chrome::AddSelectedTabWithURL(browser(), singleton_url1
,
842 content::PAGE_TRANSITION_LINK
);
843 chrome::AddSelectedTabWithURL(browser(), GetGoogleURL(),
844 content::PAGE_TRANSITION_LINK
);
846 // We should have one browser with 3 tabs, the 3rd selected.
847 EXPECT_EQ(1u, chrome::GetTotalBrowserCount());
848 EXPECT_EQ(3, browser()->tab_strip_model()->count());
849 EXPECT_EQ(2, browser()->tab_strip_model()->active_index());
851 // Navigate to singleton_url1.
852 chrome::NavigateParams
p(MakeNavigateParams());
853 p
.disposition
= SINGLETON_TAB
;
854 p
.url
= GetClearBrowsingDataURL();
855 p
.window_action
= chrome::NavigateParams::SHOW_WINDOW
;
856 p
.path_behavior
= chrome::NavigateParams::IGNORE_AND_NAVIGATE
;
857 chrome::Navigate(&p
);
859 // The middle tab should now be selected and navigated to the sub-page of the
861 EXPECT_EQ(browser(), p
.browser
);
862 EXPECT_EQ(3, browser()->tab_strip_model()->count());
863 EXPECT_EQ(1, browser()->tab_strip_model()->active_index());
864 EXPECT_EQ(GetClearBrowsingDataURL(),
865 ShortenUberURL(browser()->tab_strip_model()->
866 GetActiveWebContents()->GetURL()));
869 // This test verifies that constructing params with disposition = SINGLETON_TAB
870 // and IGNORE_AND_STAY_PUT opens an existing tab with the matching URL (minus
872 IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest
,
873 Disposition_SingletonTabExistingSubPath_IgnorePath2
) {
874 GURL
singleton_url1(GetContentSettingsURL());
875 chrome::AddSelectedTabWithURL(browser(), singleton_url1
,
876 content::PAGE_TRANSITION_LINK
);
877 chrome::AddSelectedTabWithURL(browser(), GetGoogleURL(),
878 content::PAGE_TRANSITION_LINK
);
880 // We should have one browser with 3 tabs, the 3rd selected.
881 EXPECT_EQ(1u, chrome::GetTotalBrowserCount());
882 EXPECT_EQ(3, browser()->tab_strip_model()->count());
883 EXPECT_EQ(2, browser()->tab_strip_model()->active_index());
885 // Navigate to singleton_url1.
886 chrome::NavigateParams
p(MakeNavigateParams());
887 p
.disposition
= SINGLETON_TAB
;
888 p
.url
= GetClearBrowsingDataURL();
889 p
.window_action
= chrome::NavigateParams::SHOW_WINDOW
;
890 p
.path_behavior
= chrome::NavigateParams::IGNORE_AND_STAY_PUT
;
891 chrome::Navigate(&p
);
893 // The middle tab should now be selected.
894 EXPECT_EQ(browser(), p
.browser
);
895 EXPECT_EQ(3, browser()->tab_strip_model()->count());
896 EXPECT_EQ(1, browser()->tab_strip_model()->active_index());
897 EXPECT_EQ(singleton_url1
,
898 ShortenUberURL(browser()->tab_strip_model()->
899 GetActiveWebContents()->GetURL()));
902 // This test verifies that constructing params with disposition = SINGLETON_TAB
903 // and IGNORE_AND_NAVIGATE will update the current tab's URL if the currently
904 // selected tab is a match but has a different path.
905 IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest
,
906 Disposition_SingletonTabFocused_IgnorePath
) {
907 GURL
singleton_url_current(GetContentSettingsURL());
908 chrome::AddSelectedTabWithURL(browser(), singleton_url_current
,
909 content::PAGE_TRANSITION_LINK
);
911 // We should have one browser with 2 tabs, the 2nd selected.
912 EXPECT_EQ(1u, chrome::GetTotalBrowserCount());
913 EXPECT_EQ(2, browser()->tab_strip_model()->count());
914 EXPECT_EQ(1, browser()->tab_strip_model()->active_index());
916 // Navigate to a different settings path.
917 GURL
singleton_url_target(GetClearBrowsingDataURL());
918 chrome::NavigateParams
p(MakeNavigateParams());
919 p
.disposition
= SINGLETON_TAB
;
920 p
.url
= singleton_url_target
;
921 p
.window_action
= chrome::NavigateParams::SHOW_WINDOW
;
922 p
.path_behavior
= chrome::NavigateParams::IGNORE_AND_NAVIGATE
;
923 chrome::Navigate(&p
);
925 // The second tab should still be selected, but navigated to the new path.
926 EXPECT_EQ(browser(), p
.browser
);
927 EXPECT_EQ(2, browser()->tab_strip_model()->count());
928 EXPECT_EQ(1, browser()->tab_strip_model()->active_index());
929 EXPECT_EQ(singleton_url_target
,
930 ShortenUberURL(browser()->tab_strip_model()->
931 GetActiveWebContents()->GetURL()));
934 // This test verifies that constructing params with disposition = SINGLETON_TAB
935 // and IGNORE_AND_NAVIGATE will open an existing matching tab with a different
937 IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest
,
938 Disposition_SingletonTabExisting_IgnoreQuery
) {
939 int initial_tab_count
= browser()->tab_strip_model()->count();
940 GURL
singleton_url_current("chrome://settings/internet");
941 chrome::AddSelectedTabWithURL(browser(), singleton_url_current
,
942 content::PAGE_TRANSITION_LINK
);
944 EXPECT_EQ(initial_tab_count
+ 1, browser()->tab_strip_model()->count());
945 EXPECT_EQ(initial_tab_count
, browser()->tab_strip_model()->active_index());
947 // Navigate to a different settings path.
948 GURL
singleton_url_target(
949 "chrome://settings/internet?"
950 "servicePath=/profile/ethernet_00aa00aa00aa&networkType=1");
951 chrome::NavigateParams
p(MakeNavigateParams());
952 p
.disposition
= SINGLETON_TAB
;
953 p
.url
= singleton_url_target
;
954 p
.window_action
= chrome::NavigateParams::SHOW_WINDOW
;
955 p
.path_behavior
= chrome::NavigateParams::IGNORE_AND_NAVIGATE
;
956 chrome::Navigate(&p
);
958 // Last tab should still be selected.
959 EXPECT_EQ(browser(), p
.browser
);
960 EXPECT_EQ(initial_tab_count
+ 1, browser()->tab_strip_model()->count());
961 EXPECT_EQ(initial_tab_count
, browser()->tab_strip_model()->active_index());
964 // This test verifies that the settings page isn't opened in the incognito
966 // Disabled until fixed for uber settings: http://crbug.com/111243
967 IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest
,
968 DISABLED_Disposition_Settings_UseNonIncognitoWindow
) {
969 RunUseNonIncognitoWindowTest(GetSettingsURL());
972 // This test verifies that the view-source settings page isn't opened in the
974 IN_PROC_BROWSER_TEST_F(
975 BrowserNavigatorTest
,
976 Disposition_ViewSource_Settings_DoNothingIfIncognitoForced
) {
977 std::string
view_source(content::kViewSourceScheme
);
978 view_source
.append(":");
979 view_source
.append(chrome::kChromeUISettingsURL
);
980 RunDoNothingIfIncognitoIsForcedTest(GURL(view_source
));
983 // This test verifies that the view-source settings page isn't opened in the
984 // incognito window even if incognito mode is forced (does nothing in that
986 IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest
,
987 Disposition_ViewSource_Settings_UseNonIncognitoWindow
) {
988 std::string
view_source(content::kViewSourceScheme
);
989 view_source
.append(":");
990 view_source
.append(chrome::kChromeUISettingsURL
);
991 RunUseNonIncognitoWindowTest(GURL(view_source
));
994 // This test verifies that the settings page isn't opened in the incognito
995 // window from a non-incognito window (bookmark open-in-incognito trigger).
996 // Disabled until fixed for uber settings: http://crbug.com/111243
997 IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest
,
998 DISABLED_Disposition_Settings_UseNonIncognitoWindowForBookmark
) {
999 chrome::NavigateParams
params(browser(), GetSettingsURL(),
1000 content::PAGE_TRANSITION_AUTO_BOOKMARK
);
1001 params
.disposition
= OFF_THE_RECORD
;
1003 content::WindowedNotificationObserver
observer(
1004 content::NOTIFICATION_LOAD_STOP
,
1005 content::NotificationService::AllSources());
1006 chrome::Navigate(¶ms
);
1010 EXPECT_EQ(1u, chrome::GetTotalBrowserCount());
1011 EXPECT_EQ(GetSettingsURL(),
1012 ShortenUberURL(browser()->tab_strip_model()->
1013 GetActiveWebContents()->GetURL()));
1016 // Settings page is expected to always open in normal mode regardless
1017 // of whether the user is trying to open it in incognito mode or not.
1018 // This test verifies that if incognito mode is forced (by policy), settings
1019 // page doesn't open at all.
1020 // Disabled until fixed for uber settings: http://crbug.com/111243
1021 IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest
,
1022 DISABLED_Disposition_Settings_DoNothingIfIncognitoIsForced
) {
1023 RunDoNothingIfIncognitoIsForcedTest(GetSettingsURL());
1026 // This test verifies that the bookmarks page isn't opened in the incognito
1028 IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest
,
1029 Disposition_Bookmarks_UseNonIncognitoWindow
) {
1030 RunUseNonIncognitoWindowTest(GURL(chrome::kChromeUIBookmarksURL
));
1033 // Bookmark manager is expected to always open in normal mode regardless
1034 // of whether the user is trying to open it in incognito mode or not.
1035 // This test verifies that if incognito mode is forced (by policy), bookmark
1036 // manager doesn't open at all.
1037 IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest
,
1038 Disposition_Bookmarks_DoNothingIfIncognitoIsForced
) {
1039 RunDoNothingIfIncognitoIsForcedTest(GURL(chrome::kChromeUIBookmarksURL
));
1042 // This test makes sure a crashed singleton tab reloads from a new navigation.
1043 IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest
,
1044 NavigateToCrashedSingletonTab
) {
1045 GURL
singleton_url(GetContentSettingsURL());
1046 WebContents
* web_contents
= chrome::AddSelectedTabWithURL(
1047 browser(), singleton_url
, content::PAGE_TRANSITION_LINK
);
1049 // We should have one browser with 2 tabs, the 2nd selected.
1050 EXPECT_EQ(1u, chrome::GetTotalBrowserCount());
1051 EXPECT_EQ(2, browser()->tab_strip_model()->count());
1052 EXPECT_EQ(1, browser()->tab_strip_model()->active_index());
1054 // Kill the singleton tab.
1055 web_contents
->SetIsCrashed(base::TERMINATION_STATUS_PROCESS_CRASHED
, -1);
1056 EXPECT_TRUE(web_contents
->IsCrashed());
1058 chrome::NavigateParams
p(MakeNavigateParams());
1059 p
.disposition
= SINGLETON_TAB
;
1060 p
.url
= singleton_url
;
1061 p
.window_action
= chrome::NavigateParams::SHOW_WINDOW
;
1062 p
.path_behavior
= chrome::NavigateParams::IGNORE_AND_NAVIGATE
;
1063 ui_test_utils::NavigateToURL(&p
);
1065 // The tab should not be sad anymore.
1066 EXPECT_FALSE(web_contents
->IsCrashed());
1069 IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest
,
1070 NavigateFromDefaultToOptionsInSameTab
) {
1072 content::WindowedNotificationObserver
observer(
1073 content::NOTIFICATION_LOAD_STOP
,
1074 content::NotificationService::AllSources());
1075 chrome::ShowSettings(browser());
1078 EXPECT_EQ(1, browser()->tab_strip_model()->count());
1079 EXPECT_EQ(GetSettingsURL(),
1080 ShortenUberURL(browser()->tab_strip_model()->
1081 GetActiveWebContents()->GetURL()));
1084 IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest
,
1085 NavigateFromBlankToOptionsInSameTab
) {
1086 chrome::NavigateParams
p(MakeNavigateParams());
1087 p
.url
= GURL(content::kAboutBlankURL
);
1088 ui_test_utils::NavigateToURL(&p
);
1091 content::WindowedNotificationObserver
observer(
1092 content::NOTIFICATION_LOAD_STOP
,
1093 content::NotificationService::AllSources());
1094 chrome::ShowSettings(browser());
1097 EXPECT_EQ(1, browser()->tab_strip_model()->count());
1098 EXPECT_EQ(GetSettingsURL(),
1099 ShortenUberURL(browser()->tab_strip_model()->
1100 GetActiveWebContents()->GetURL()));
1103 IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest
,
1104 NavigateFromNTPToOptionsInSameTab
) {
1105 chrome::NavigateParams
p(MakeNavigateParams());
1106 p
.url
= GURL(chrome::kChromeUINewTabURL
);
1107 ui_test_utils::NavigateToURL(&p
);
1108 EXPECT_EQ(1, browser()->tab_strip_model()->count());
1109 EXPECT_EQ(GURL(chrome::kChromeUINewTabURL
),
1110 browser()->tab_strip_model()->GetActiveWebContents()->GetURL());
1113 content::WindowedNotificationObserver
observer(
1114 content::NOTIFICATION_LOAD_STOP
,
1115 content::NotificationService::AllSources());
1116 chrome::ShowSettings(browser());
1119 EXPECT_EQ(1, browser()->tab_strip_model()->count());
1120 EXPECT_EQ(GetSettingsURL(),
1121 ShortenUberURL(browser()->tab_strip_model()->
1122 GetActiveWebContents()->GetURL()));
1125 IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest
,
1126 NavigateFromPageToOptionsInNewTab
) {
1127 chrome::NavigateParams
p(MakeNavigateParams());
1128 ui_test_utils::NavigateToURL(&p
);
1129 EXPECT_EQ(GetGoogleURL(),
1130 browser()->tab_strip_model()->GetActiveWebContents()->GetURL());
1131 EXPECT_EQ(1u, chrome::GetTotalBrowserCount());
1132 EXPECT_EQ(1, browser()->tab_strip_model()->count());
1135 content::WindowedNotificationObserver
observer(
1136 content::NOTIFICATION_LOAD_STOP
,
1137 content::NotificationService::AllSources());
1138 chrome::ShowSettings(browser());
1141 EXPECT_EQ(2, browser()->tab_strip_model()->count());
1142 EXPECT_EQ(GetSettingsURL(),
1143 ShortenUberURL(browser()->tab_strip_model()->
1144 GetActiveWebContents()->GetURL()));
1147 IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest
,
1148 NavigateFromNTPToOptionsSingleton
) {
1150 content::WindowedNotificationObserver
observer(
1151 content::NOTIFICATION_LOAD_STOP
,
1152 content::NotificationService::AllSources());
1153 chrome::ShowSettings(browser());
1156 EXPECT_EQ(1, browser()->tab_strip_model()->count());
1158 chrome::NewTab(browser());
1159 EXPECT_EQ(2, browser()->tab_strip_model()->count());
1162 content::WindowedNotificationObserver
observer(
1163 content::NOTIFICATION_LOAD_STOP
,
1164 content::NotificationService::AllSources());
1165 chrome::ShowSettings(browser());
1168 EXPECT_EQ(2, browser()->tab_strip_model()->count());
1169 EXPECT_EQ(GetSettingsURL(),
1170 ShortenUberURL(browser()->tab_strip_model()->
1171 GetActiveWebContents()->GetURL()));
1174 IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest
,
1175 NavigateFromNTPToOptionsPageInSameTab
) {
1177 content::WindowedNotificationObserver
observer(
1178 content::NOTIFICATION_LOAD_STOP
,
1179 content::NotificationService::AllSources());
1180 chrome::ShowClearBrowsingDataDialog(browser());
1183 EXPECT_EQ(1, browser()->tab_strip_model()->count());
1184 EXPECT_EQ(GetClearBrowsingDataURL(),
1185 browser()->tab_strip_model()->GetActiveWebContents()->GetURL());
1187 chrome::NewTab(browser());
1188 EXPECT_EQ(2, browser()->tab_strip_model()->count());
1191 content::WindowedNotificationObserver
observer(
1192 content::NOTIFICATION_LOAD_STOP
,
1193 content::NotificationService::AllSources());
1194 chrome::ShowClearBrowsingDataDialog(browser());
1197 EXPECT_EQ(2, browser()->tab_strip_model()->count());
1198 EXPECT_EQ(GetClearBrowsingDataURL(),
1199 browser()->tab_strip_model()->GetActiveWebContents()->GetURL());
1202 IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest
,
1203 NavigateFromOtherTabToSingletonOptions
) {
1205 content::WindowedNotificationObserver
observer(
1206 content::NOTIFICATION_LOAD_STOP
,
1207 content::NotificationService::AllSources());
1208 chrome::ShowSettings(browser());
1212 content::WindowedNotificationObserver
observer(
1213 content::NOTIFICATION_LOAD_STOP
,
1214 content::NotificationService::AllSources());
1215 chrome::AddSelectedTabWithURL(browser(), GetGoogleURL(),
1216 content::PAGE_TRANSITION_LINK
);
1220 // This load should simply cause a tab switch.
1221 chrome::ShowSettings(browser());
1223 EXPECT_EQ(2, browser()->tab_strip_model()->count());
1224 EXPECT_EQ(GetSettingsURL(),
1225 ShortenUberURL(browser()->tab_strip_model()->
1226 GetActiveWebContents()->GetURL()));
1229 IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest
, CloseSingletonTab
) {
1230 for (int i
= 0; i
< 2; ++i
) {
1231 content::WindowedNotificationObserver
observer(
1232 content::NOTIFICATION_LOAD_STOP
,
1233 content::NotificationService::AllSources());
1234 chrome::AddSelectedTabWithURL(browser(), GetGoogleURL(),
1235 content::PAGE_TRANSITION_TYPED
);
1239 browser()->tab_strip_model()->ActivateTabAt(0, true);
1242 content::WindowedNotificationObserver
observer(
1243 content::NOTIFICATION_LOAD_STOP
,
1244 content::NotificationService::AllSources());
1245 chrome::ShowSettings(browser());
1249 EXPECT_TRUE(browser()->tab_strip_model()->CloseWebContentsAt(
1250 2, TabStripModel::CLOSE_USER_GESTURE
));
1251 EXPECT_EQ(0, browser()->tab_strip_model()->active_index());
1254 // TODO(csilv): Update this for uber page. http://crbug.com/111579.
1255 IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest
,
1256 DISABLED_NavigateFromDefaultToHistoryInSameTab
) {
1258 content::WindowedNotificationObserver
observer(
1259 content::NOTIFICATION_LOAD_STOP
,
1260 content::NotificationService::AllSources());
1261 chrome::ShowHistory(browser());
1264 EXPECT_EQ(1, browser()->tab_strip_model()->count());
1265 EXPECT_EQ(GURL(chrome::kChromeUIHistoryFrameURL
),
1266 browser()->tab_strip_model()->GetActiveWebContents()->GetURL());
1269 // TODO(linux_aura) http://crbug.com/163931
1270 #if defined(OS_LINUX) && !defined(OS_CHROMEOS) && defined(USE_AURA)
1271 #define MAYBE_NavigateFromDefaultToBookmarksInSameTab DISABLED_NavigateFromDefaultToBookmarksInSameTab
1273 #define MAYBE_NavigateFromDefaultToBookmarksInSameTab NavigateFromDefaultToBookmarksInSameTab
1275 IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest
,
1276 MAYBE_NavigateFromDefaultToBookmarksInSameTab
) {
1278 content::WindowedNotificationObserver
observer(
1279 content::NOTIFICATION_LOAD_STOP
,
1280 content::NotificationService::AllSources());
1281 chrome::ShowBookmarkManager(browser());
1284 EXPECT_EQ(1, browser()->tab_strip_model()->count());
1285 EXPECT_TRUE(StartsWithASCII(
1286 browser()->tab_strip_model()->GetActiveWebContents()->GetURL().spec(),
1287 chrome::kChromeUIBookmarksURL
,
1291 IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest
,
1292 NavigateFromDefaultToDownloadsInSameTab
) {
1294 content::WindowedNotificationObserver
observer(
1295 content::NOTIFICATION_LOAD_STOP
,
1296 content::NotificationService::AllSources());
1297 chrome::ShowDownloads(browser());
1300 EXPECT_EQ(1, browser()->tab_strip_model()->count());
1301 EXPECT_EQ(GURL(chrome::kChromeUIDownloadsURL
),
1302 browser()->tab_strip_model()->GetActiveWebContents()->GetURL());
1305 IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest
,
1306 NavigateWithoutBrowser
) {
1307 // First navigate using the profile of the existing browser window, and
1308 // check that the window is reused.
1309 chrome::NavigateParams
params(browser()->profile(), GetGoogleURL(),
1310 content::PAGE_TRANSITION_LINK
);
1311 ui_test_utils::NavigateToURL(¶ms
);
1312 EXPECT_EQ(1u, chrome::GetTotalBrowserCount());
1314 // Now navigate using the incognito profile and check that a new window
1316 chrome::NavigateParams
params_incognito(
1317 browser()->profile()->GetOffTheRecordProfile(),
1318 GetGoogleURL(), content::PAGE_TRANSITION_LINK
);
1319 ui_test_utils::NavigateToURL(¶ms_incognito
);
1320 EXPECT_EQ(2u, chrome::GetTotalBrowserCount());
1323 IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest
, ViewSourceIsntSingleton
) {
1324 const std::string viewsource_ntp_url
=
1325 std::string(content::kViewSourceScheme
) + ":" +
1326 chrome::kChromeUIVersionURL
;
1328 chrome::NavigateParams
viewsource_params(browser(),
1329 GURL(viewsource_ntp_url
),
1330 content::PAGE_TRANSITION_LINK
);
1331 ui_test_utils::NavigateToURL(&viewsource_params
);
1333 chrome::NavigateParams
singleton_params(browser(),
1334 GURL(chrome::kChromeUIVersionURL
),
1335 content::PAGE_TRANSITION_LINK
);
1336 singleton_params
.disposition
= SINGLETON_TAB
;
1337 EXPECT_EQ(-1, chrome::GetIndexOfSingletonTab(&singleton_params
));
1340 // This test verifies that browser initiated navigations can send requests
1342 IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest
,
1343 SendBrowserInitiatedRequestUsingPOST
) {
1344 // Uses a test sever to verify POST request.
1345 ASSERT_TRUE(test_server()->Start());
1347 // Open a browser initiated POST request in new foreground tab.
1348 base::string16
expected_title(base::ASCIIToUTF16(kExpectedTitle
));
1349 std::string post_data
= kExpectedTitle
;
1350 base::string16 title
;
1351 ASSERT_TRUE(OpenPOSTURLInNewForegroundTabAndGetTitle(
1352 test_server()->GetURL(kEchoTitleCommand
), post_data
, true, &title
));
1353 EXPECT_EQ(expected_title
, title
);
1356 // This test verifies that renderer initiated navigations can NOT send requests
1358 IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest
,
1359 SendRendererInitiatedRequestUsingPOST
) {
1360 // Uses a test sever to verify POST request.
1361 ASSERT_TRUE(test_server()->Start());
1363 // Open a renderer initiated POST request in new foreground tab.
1364 base::string16
expected_title(base::ASCIIToUTF16(kExpectedTitle
));
1365 std::string post_data
= kExpectedTitle
;
1366 base::string16 title
;
1367 ASSERT_TRUE(OpenPOSTURLInNewForegroundTabAndGetTitle(
1368 test_server()->GetURL(kEchoTitleCommand
), post_data
, false, &title
));
1369 EXPECT_NE(expected_title
, title
);