Add new certificateProvider extension API.
[chromium-blink-merge.git] / chrome / browser / ui / browser_navigator_browsertest.cc
blob02d5494eacdb91fa01b28c7535077ccb557993cd
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/location_bar/location_bar.h"
22 #include "chrome/browser/ui/singleton_tabs.h"
23 #include "chrome/browser/ui/tabs/tab_strip_model.h"
24 #include "chrome/common/chrome_switches.h"
25 #include "chrome/common/pref_names.h"
26 #include "chrome/common/url_constants.h"
27 #include "chrome/test/base/ui_test_utils.h"
28 #include "components/omnibox/browser/omnibox_view.h"
29 #include "content/public/browser/notification_service.h"
30 #include "content/public/browser/notification_types.h"
31 #include "content/public/browser/web_contents.h"
33 using content::WebContents;
35 namespace {
37 const char kExpectedTitle[] = "PASSED!";
38 const char kEchoTitleCommand[] = "echotitle";
40 GURL GetGoogleURL() {
41 return GURL("http://www.google.com/");
44 GURL GetSettingsURL() {
45 return GURL(chrome::kChromeUISettingsURL);
48 GURL GetContentSettingsURL() {
49 return GetSettingsURL().Resolve(chrome::kContentSettingsExceptionsSubPage);
52 GURL GetClearBrowsingDataURL() {
53 return GetSettingsURL().Resolve(chrome::kClearBrowserDataSubPage);
56 // Converts long uber URLs ("chrome://chrome/foo/") to short (virtual) URLs
57 // ("chrome://foo/"). This should be used to convert the return value of
58 // WebContentsImpl::GetURL before comparison because it can return either the
59 // real URL or the virtual URL.
60 GURL ShortenUberURL(const GURL& url) {
61 std::string url_string = url.spec();
62 const std::string long_prefix = "chrome://chrome/";
63 const std::string short_prefix = "chrome://";
64 if (url_string.find(long_prefix) != 0)
65 return url;
66 url_string.replace(0, long_prefix.length(), short_prefix);
67 return GURL(url_string);
70 } // namespace
72 chrome::NavigateParams BrowserNavigatorTest::MakeNavigateParams() const {
73 return MakeNavigateParams(browser());
76 chrome::NavigateParams BrowserNavigatorTest::MakeNavigateParams(
77 Browser* browser) const {
78 chrome::NavigateParams params(browser, GetGoogleURL(),
79 ui::PAGE_TRANSITION_LINK);
80 params.window_action = chrome::NavigateParams::SHOW_WINDOW;
81 return params;
84 bool BrowserNavigatorTest::OpenPOSTURLInNewForegroundTabAndGetTitle(
85 const GURL& url, const std::string& post_data, bool is_browser_initiated,
86 base::string16* title) {
87 chrome::NavigateParams param(MakeNavigateParams());
88 param.disposition = NEW_FOREGROUND_TAB;
89 param.url = url;
90 param.is_renderer_initiated = !is_browser_initiated;
91 param.uses_post = true;
92 param.browser_initiated_post_data = new base::RefCountedStaticMemory(
93 post_data.data(), post_data.size());
95 ui_test_utils::NavigateToURL(&param);
96 if (!param.target_contents)
97 return false;
99 // Navigate() should have opened the contents in new foreground tab in the
100 // current Browser.
101 EXPECT_EQ(browser(), param.browser);
102 EXPECT_EQ(browser()->tab_strip_model()->GetActiveWebContents(),
103 param.target_contents);
104 // We should have one window, with one tab.
105 EXPECT_EQ(1u, chrome::GetTotalBrowserCount());
106 EXPECT_EQ(2, browser()->tab_strip_model()->count());
108 *title = param.target_contents->GetTitle();
109 return true;
112 Browser* BrowserNavigatorTest::CreateEmptyBrowserForType(Browser::Type type,
113 Profile* profile) {
114 Browser* browser = new Browser(
115 Browser::CreateParams(type, profile, chrome::GetActiveDesktop()));
116 chrome::AddTabAt(browser, GURL(), -1, true);
117 return browser;
120 Browser* BrowserNavigatorTest::CreateEmptyBrowserForApp(Profile* profile) {
121 Browser* browser = new Browser(
122 Browser::CreateParams::CreateForApp(
123 "Test", false /* trusted_source */, gfx::Rect(), profile,
124 chrome::GetActiveDesktop()));
125 chrome::AddTabAt(browser, GURL(), -1, true);
126 return browser;
129 WebContents* BrowserNavigatorTest::CreateWebContents() {
130 content::WebContents::CreateParams create_params(browser()->profile());
131 content::WebContents* base_web_contents =
132 browser()->tab_strip_model()->GetActiveWebContents();
133 if (base_web_contents) {
134 create_params.initial_size =
135 base_web_contents->GetContainerBounds().size();
137 return WebContents::Create(create_params);
140 void BrowserNavigatorTest::RunSuppressTest(WindowOpenDisposition disposition) {
141 GURL old_url = browser()->tab_strip_model()->GetActiveWebContents()->GetURL();
142 chrome::NavigateParams params(MakeNavigateParams());
143 params.disposition = disposition;
144 chrome::Navigate(&params);
146 // Nothing should have happened as a result of Navigate();
147 EXPECT_EQ(1, browser()->tab_strip_model()->count());
148 EXPECT_EQ(1u, chrome::GetTotalBrowserCount());
149 EXPECT_EQ(old_url,
150 browser()->tab_strip_model()->GetActiveWebContents()->GetURL());
153 void BrowserNavigatorTest::RunUseNonIncognitoWindowTest(const GURL& url) {
154 Browser* incognito_browser = CreateIncognitoBrowser();
156 EXPECT_EQ(2u, chrome::GetTotalBrowserCount());
157 EXPECT_EQ(1, browser()->tab_strip_model()->count());
158 EXPECT_EQ(1, incognito_browser->tab_strip_model()->count());
160 // Navigate to the page.
161 chrome::NavigateParams params(MakeNavigateParams(incognito_browser));
162 params.disposition = SINGLETON_TAB;
163 params.url = url;
164 params.window_action = chrome::NavigateParams::SHOW_WINDOW;
165 chrome::Navigate(&params);
167 // This page should be opened in browser() window.
168 EXPECT_NE(incognito_browser, params.browser);
169 EXPECT_EQ(browser(), params.browser);
170 EXPECT_EQ(2, browser()->tab_strip_model()->count());
171 EXPECT_EQ(url,
172 browser()->tab_strip_model()->GetActiveWebContents()->GetURL());
175 void BrowserNavigatorTest::RunDoNothingIfIncognitoIsForcedTest(
176 const GURL& url) {
177 Browser* browser = CreateIncognitoBrowser();
179 // Set kIncognitoModeAvailability to FORCED.
180 PrefService* prefs1 = browser->profile()->GetPrefs();
181 prefs1->SetInteger(prefs::kIncognitoModeAvailability,
182 IncognitoModePrefs::FORCED);
183 PrefService* prefs2 = browser->profile()->GetOriginalProfile()->GetPrefs();
184 prefs2->SetInteger(prefs::kIncognitoModeAvailability,
185 IncognitoModePrefs::FORCED);
187 // Navigate to the page.
188 chrome::NavigateParams params(MakeNavigateParams(browser));
189 params.disposition = OFF_THE_RECORD;
190 params.url = url;
191 params.window_action = chrome::NavigateParams::SHOW_WINDOW;
192 chrome::Navigate(&params);
194 // The page should not be opened.
195 EXPECT_EQ(browser, params.browser);
196 EXPECT_EQ(1, browser->tab_strip_model()->count());
197 EXPECT_EQ(GURL(url::kAboutBlankURL),
198 browser->tab_strip_model()->GetActiveWebContents()->GetURL());
201 void BrowserNavigatorTest::SetUpCommandLine(base::CommandLine* command_line) {
202 // Disable settings-in-a-window so that we can use the settings page and
203 // sub-pages to test browser navigation.
204 command_line->AppendSwitch(::switches::kDisableSettingsWindow);
206 // Disable new downloads UI as it is very very slow. https://crbug.com/526577
207 // TODO(dbeam): remove this once the downloads UI is not slow.
208 command_line->AppendSwitch(switches::kDisableMaterialDesignDownloads);
211 void BrowserNavigatorTest::Observe(
212 int type,
213 const content::NotificationSource& source,
214 const content::NotificationDetails& details) {
215 switch (type) {
216 case content::NOTIFICATION_WEB_CONTENTS_RENDER_VIEW_HOST_CREATED: {
217 ++this->created_tab_contents_count_;
218 break;
220 default:
221 break;
226 namespace {
228 // This test verifies that when a navigation occurs within a tab, the tab count
229 // of the Browser remains the same and the current tab bears the loaded URL.
230 // Note that network URLs are not actually loaded in tests, so this also tests
231 // that error pages leave the intended URL in the address bar.
232 IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_CurrentTab) {
233 ui_test_utils::NavigateToURL(browser(), GetGoogleURL());
234 EXPECT_EQ(GetGoogleURL(),
235 browser()->tab_strip_model()->GetActiveWebContents()->GetURL());
236 // We should have one window with one tab.
237 EXPECT_EQ(1u, chrome::GetTotalBrowserCount());
238 EXPECT_EQ(1, browser()->tab_strip_model()->count());
241 // This test verifies that a singleton tab is refocused if one is already opened
242 // in another or an existing window, or added if it is not.
243 IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_SingletonTabExisting) {
244 GURL singleton_url1("http://maps.google.com/");
246 // Register for a notification if an additional WebContents was instantiated.
247 // Opening a Singleton tab that is already opened should not be opening a new
248 // tab nor be creating a new WebContents object.
249 content::NotificationRegistrar registrar;
251 // As the registrar object goes out of scope, this will get unregistered
252 registrar.Add(this,
253 content::NOTIFICATION_WEB_CONTENTS_RENDER_VIEW_HOST_CREATED,
254 content::NotificationService::AllSources());
256 chrome::AddSelectedTabWithURL(browser(), singleton_url1,
257 ui::PAGE_TRANSITION_LINK);
258 chrome::AddSelectedTabWithURL(browser(), GetGoogleURL(),
259 ui::PAGE_TRANSITION_LINK);
261 // We should have one browser with 3 tabs, the 3rd selected.
262 EXPECT_EQ(1u, chrome::GetTotalBrowserCount());
263 EXPECT_EQ(2, browser()->tab_strip_model()->active_index());
265 unsigned int previous_tab_contents_count =
266 created_tab_contents_count_ = 0;
268 // Navigate to singleton_url1.
269 chrome::NavigateParams params(MakeNavigateParams());
270 params.disposition = SINGLETON_TAB;
271 params.url = singleton_url1;
272 chrome::Navigate(&params);
274 // The middle tab should now be selected.
275 EXPECT_EQ(browser(), params.browser);
276 EXPECT_EQ(1, browser()->tab_strip_model()->active_index());
278 // No tab contents should have been created
279 EXPECT_EQ(previous_tab_contents_count,
280 created_tab_contents_count_);
283 IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
284 Disposition_SingletonTabRespectingRef) {
285 GURL singleton_ref_url1("http://maps.google.com/#a");
286 GURL singleton_ref_url2("http://maps.google.com/#b");
287 GURL singleton_ref_url3("http://maps.google.com/");
289 chrome::AddSelectedTabWithURL(browser(), singleton_ref_url1,
290 ui::PAGE_TRANSITION_LINK);
292 // We should have one browser with 2 tabs, 2nd selected.
293 EXPECT_EQ(1u, chrome::GetTotalBrowserCount());
294 EXPECT_EQ(2, browser()->tab_strip_model()->count());
295 EXPECT_EQ(1, browser()->tab_strip_model()->active_index());
297 // Navigate to singleton_url2.
298 chrome::NavigateParams params(MakeNavigateParams());
299 params.disposition = SINGLETON_TAB;
300 params.url = singleton_ref_url2;
301 chrome::Navigate(&params);
303 // We should now have 2 tabs, the 2nd one selected.
304 EXPECT_EQ(browser(), params.browser);
305 EXPECT_EQ(2, browser()->tab_strip_model()->count());
306 EXPECT_EQ(1, browser()->tab_strip_model()->active_index());
308 // Navigate to singleton_url2, but with respect ref set.
309 params = MakeNavigateParams();
310 params.disposition = SINGLETON_TAB;
311 params.url = singleton_ref_url2;
312 params.ref_behavior = chrome::NavigateParams::RESPECT_REF;
313 chrome::Navigate(&params);
315 // We should now have 3 tabs, the 3th one selected.
316 EXPECT_EQ(browser(), params.browser);
317 EXPECT_EQ(3, browser()->tab_strip_model()->count());
318 EXPECT_EQ(2, browser()->tab_strip_model()->active_index());
320 // Navigate to singleton_url3.
321 params = MakeNavigateParams();
322 params.disposition = SINGLETON_TAB;
323 params.url = singleton_ref_url3;
324 params.ref_behavior = chrome::NavigateParams::RESPECT_REF;
325 chrome::Navigate(&params);
327 // We should now have 4 tabs, the 4th one selected.
328 EXPECT_EQ(browser(), params.browser);
329 EXPECT_EQ(4, browser()->tab_strip_model()->count());
330 EXPECT_EQ(3, browser()->tab_strip_model()->active_index());
333 IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
334 Disposition_SingletonTabNoneExisting) {
335 GURL singleton_url1("http://maps.google.com/");
337 // We should have one browser with 1 tab.
338 EXPECT_EQ(1u, chrome::GetTotalBrowserCount());
339 EXPECT_EQ(0, browser()->tab_strip_model()->active_index());
341 // Navigate to singleton_url1.
342 chrome::NavigateParams params(MakeNavigateParams());
343 params.disposition = SINGLETON_TAB;
344 params.url = singleton_url1;
345 chrome::Navigate(&params);
347 // We should now have 2 tabs, the 2nd one selected.
348 EXPECT_EQ(browser(), params.browser);
349 EXPECT_EQ(2, browser()->tab_strip_model()->count());
350 EXPECT_EQ(1, browser()->tab_strip_model()->active_index());
353 // This test verifies that when a navigation results in a foreground tab, the
354 // tab count of the Browser increases and the selected tab shifts to the new
355 // foreground tab.
356 IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_NewForegroundTab) {
357 WebContents* old_contents =
358 browser()->tab_strip_model()->GetActiveWebContents();
359 chrome::NavigateParams params(MakeNavigateParams());
360 params.disposition = NEW_FOREGROUND_TAB;
361 chrome::Navigate(&params);
362 EXPECT_NE(old_contents,
363 browser()->tab_strip_model()->GetActiveWebContents());
364 EXPECT_EQ(browser()->tab_strip_model()->GetActiveWebContents(),
365 params.target_contents);
366 EXPECT_EQ(2, browser()->tab_strip_model()->count());
369 // This test verifies that when a navigation results in a background tab, the
370 // tab count of the Browser increases but the selected tab remains the same.
371 IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_NewBackgroundTab) {
372 WebContents* old_contents =
373 browser()->tab_strip_model()->GetActiveWebContents();
374 chrome::NavigateParams params(MakeNavigateParams());
375 params.disposition = NEW_BACKGROUND_TAB;
376 chrome::Navigate(&params);
377 WebContents* new_contents =
378 browser()->tab_strip_model()->GetActiveWebContents();
379 // The selected tab should have remained unchanged, since the new tab was
380 // opened in the background.
381 EXPECT_EQ(old_contents, new_contents);
382 EXPECT_EQ(2, browser()->tab_strip_model()->count());
385 // This test verifies that when a navigation requiring a new foreground tab
386 // occurs in a Browser that cannot host multiple tabs, the new foreground tab
387 // is created in an existing compatible Browser.
388 IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
389 Disposition_IncompatibleWindow_Existing) {
390 // Open a foreground tab in a window that cannot open popups when there is an
391 // existing compatible window somewhere else that they can be opened within.
392 Browser* popup = CreateEmptyBrowserForType(Browser::TYPE_POPUP,
393 browser()->profile());
394 chrome::NavigateParams params(MakeNavigateParams(popup));
395 params.disposition = NEW_FOREGROUND_TAB;
396 chrome::Navigate(&params);
398 // Navigate() should have opened the tab in a different browser since the
399 // one we supplied didn't support additional tabs.
400 EXPECT_NE(popup, params.browser);
402 // Since browser() is an existing compatible tabbed browser, it should have
403 // opened the tab there.
404 EXPECT_EQ(browser(), params.browser);
406 // We should be left with 2 windows, the popup with one tab and the browser()
407 // provided by the framework with two.
408 EXPECT_EQ(2u, chrome::GetTotalBrowserCount());
409 EXPECT_EQ(1, popup->tab_strip_model()->count());
410 EXPECT_EQ(2, browser()->tab_strip_model()->count());
413 // This test verifies that when a navigation requiring a new foreground tab
414 // occurs in a Browser that cannot host multiple tabs and no compatible Browser
415 // that can is open, a compatible Browser is created.
416 IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
417 Disposition_IncompatibleWindow_NoExisting) {
418 // We want to simulate not being able to find an existing window compatible
419 // with our non-tabbed browser window so Navigate() is forced to create a
420 // new compatible window. Because browser() supplied by the in-process
421 // browser testing framework is compatible with browser()->profile(), we
422 // need a different profile, and creating a popup window with an incognito
423 // profile is a quick and dirty way of achieving this.
424 Browser* popup = CreateEmptyBrowserForType(
425 Browser::TYPE_POPUP,
426 browser()->profile()->GetOffTheRecordProfile());
427 chrome::NavigateParams params(MakeNavigateParams(popup));
428 params.disposition = NEW_FOREGROUND_TAB;
429 chrome::Navigate(&params);
431 // Navigate() should have opened the tab in a different browser since the
432 // one we supplied didn't support additional tabs.
433 EXPECT_NE(popup, params.browser);
435 // This time, browser() is _not_ compatible with popup since it is not an
436 // incognito window.
437 EXPECT_NE(browser(), params.browser);
439 // We should have three windows, each with one tab:
440 // 1. the browser() provided by the framework (unchanged in this test)
441 // 2. the incognito popup we created originally
442 // 3. the new incognito tabbed browser that was created by Navigate().
443 EXPECT_EQ(3u, chrome::GetTotalBrowserCount());
444 EXPECT_EQ(1, browser()->tab_strip_model()->count());
445 EXPECT_EQ(1, popup->tab_strip_model()->count());
446 EXPECT_EQ(1, params.browser->tab_strip_model()->count());
447 EXPECT_TRUE(params.browser->is_type_tabbed());
450 // This test verifies that navigating with WindowOpenDisposition = NEW_POPUP
451 // from a normal Browser results in a new Browser with TYPE_POPUP.
452 IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_NewPopup) {
453 chrome::NavigateParams params(MakeNavigateParams());
454 params.disposition = NEW_POPUP;
455 params.window_bounds = gfx::Rect(0, 0, 200, 200);
456 // Wait for new popup to to load and gain focus.
457 ui_test_utils::NavigateToURL(&params);
459 // Navigate() should have opened a new, focused popup window.
460 EXPECT_NE(browser(), params.browser);
461 #if 0
462 // TODO(stevenjb): Enable this test. See: crbug.com/79493
463 EXPECT_TRUE(browser->window()->IsActive());
464 #endif
465 EXPECT_TRUE(params.browser->is_type_popup());
466 EXPECT_FALSE(params.browser->is_app());
468 // We should have two windows, the browser() provided by the framework and the
469 // new popup window.
470 EXPECT_EQ(2u, chrome::GetTotalBrowserCount());
471 EXPECT_EQ(1, browser()->tab_strip_model()->count());
472 EXPECT_EQ(1, params.browser->tab_strip_model()->count());
475 // This test verifies that navigating with WindowOpenDisposition = NEW_POPUP
476 // from a normal Browser results in a new Browser with is_app() true.
477 IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_NewPopup_ExtensionId) {
478 chrome::NavigateParams params(MakeNavigateParams());
479 params.disposition = NEW_POPUP;
480 params.extension_app_id = "extensionappid";
481 params.window_bounds = gfx::Rect(0, 0, 200, 200);
482 // Wait for new popup to to load and gain focus.
483 ui_test_utils::NavigateToURL(&params);
485 // Navigate() should have opened a new, focused popup window.
486 EXPECT_NE(browser(), params.browser);
487 EXPECT_TRUE(params.browser->is_type_popup());
488 EXPECT_TRUE(params.browser->is_app());
490 // We should have two windows, the browser() provided by the framework and the
491 // new popup window.
492 EXPECT_EQ(2u, chrome::GetTotalBrowserCount());
493 EXPECT_EQ(1, browser()->tab_strip_model()->count());
494 EXPECT_EQ(1, params.browser->tab_strip_model()->count());
497 // This test verifies that navigating with WindowOpenDisposition = NEW_POPUP
498 // from a normal popup results in a new Browser with TYPE_POPUP.
499 IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_NewPopupFromPopup) {
500 // Open a popup.
501 chrome::NavigateParams params1(MakeNavigateParams());
502 params1.disposition = NEW_POPUP;
503 params1.window_bounds = gfx::Rect(0, 0, 200, 200);
504 chrome::Navigate(&params1);
505 // Open another popup.
506 chrome::NavigateParams params2(MakeNavigateParams(params1.browser));
507 params2.disposition = NEW_POPUP;
508 params2.window_bounds = gfx::Rect(0, 0, 200, 200);
509 chrome::Navigate(&params2);
511 // Navigate() should have opened a new normal popup window.
512 EXPECT_NE(params1.browser, params2.browser);
513 EXPECT_TRUE(params2.browser->is_type_popup());
514 EXPECT_FALSE(params2.browser->is_app());
516 // We should have three windows, the browser() provided by the framework,
517 // the first popup window, and the second popup window.
518 EXPECT_EQ(3u, chrome::GetTotalBrowserCount());
519 EXPECT_EQ(1, browser()->tab_strip_model()->count());
520 EXPECT_EQ(1, params1.browser->tab_strip_model()->count());
521 EXPECT_EQ(1, params2.browser->tab_strip_model()->count());
524 // This test verifies that navigating with WindowOpenDisposition = NEW_POPUP
525 // from an app frame results in a new Browser with TYPE_POPUP.
526 IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
527 Disposition_NewPopupFromAppWindow) {
528 Browser* app_browser = CreateEmptyBrowserForApp(browser()->profile());
529 chrome::NavigateParams params(MakeNavigateParams(app_browser));
530 params.disposition = NEW_POPUP;
531 params.window_bounds = gfx::Rect(0, 0, 200, 200);
532 chrome::Navigate(&params);
534 // Navigate() should have opened a new popup app window.
535 EXPECT_NE(app_browser, params.browser);
536 EXPECT_NE(browser(), params.browser);
537 EXPECT_TRUE(params.browser->is_type_popup());
538 EXPECT_TRUE(params.browser->is_app());
540 // We should now have three windows, the app window, the app popup it created,
541 // and the original browser() provided by the framework.
542 EXPECT_EQ(3u, chrome::GetTotalBrowserCount());
543 EXPECT_EQ(1, browser()->tab_strip_model()->count());
544 EXPECT_EQ(1, app_browser->tab_strip_model()->count());
545 EXPECT_EQ(1, params.browser->tab_strip_model()->count());
548 // This test verifies that navigating with WindowOpenDisposition = NEW_POPUP
549 // from an app popup results in a new Browser also of TYPE_POPUP.
550 IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
551 Disposition_NewPopupFromAppPopup) {
552 Browser* app_browser = CreateEmptyBrowserForApp(browser()->profile());
553 // Open an app popup.
554 chrome::NavigateParams params1(MakeNavigateParams(app_browser));
555 params1.disposition = NEW_POPUP;
556 params1.window_bounds = gfx::Rect(0, 0, 200, 200);
557 chrome::Navigate(&params1);
558 // Now open another app popup.
559 chrome::NavigateParams params2(MakeNavigateParams(params1.browser));
560 params2.disposition = NEW_POPUP;
561 params2.window_bounds = gfx::Rect(0, 0, 200, 200);
562 chrome::Navigate(&params2);
564 // Navigate() should have opened a new popup app window.
565 EXPECT_NE(browser(), params1.browser);
566 EXPECT_NE(params1.browser, params2.browser);
567 EXPECT_TRUE(params2.browser->is_type_popup());
568 EXPECT_TRUE(params2.browser->is_app());
570 // We should now have four windows, the app window, the first app popup,
571 // the second app popup, and the original browser() provided by the framework.
572 EXPECT_EQ(4u, chrome::GetTotalBrowserCount());
573 EXPECT_EQ(1, browser()->tab_strip_model()->count());
574 EXPECT_EQ(1, app_browser->tab_strip_model()->count());
575 EXPECT_EQ(1, params1.browser->tab_strip_model()->count());
576 EXPECT_EQ(1, params2.browser->tab_strip_model()->count());
579 // This test verifies that navigating with WindowOpenDisposition = NEW_POPUP
580 // from an extension app tab results in a new Browser with TYPE_APP_POPUP.
581 IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
582 Disposition_NewPopupFromExtensionApp) {
583 // TODO(beng): TBD.
586 // This test verifies that navigating with window_action = SHOW_WINDOW_INACTIVE
587 // does not focus a new new popup window.
588 IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_NewPopupUnfocused) {
589 chrome::NavigateParams params(MakeNavigateParams());
590 params.disposition = NEW_POPUP;
591 params.window_bounds = gfx::Rect(0, 0, 200, 200);
592 params.window_action = chrome::NavigateParams::SHOW_WINDOW_INACTIVE;
593 // Wait for new popup to load (and gain focus if the test fails).
594 ui_test_utils::NavigateToURL(&params);
596 // Navigate() should have opened a new, unfocused, popup window.
597 EXPECT_NE(browser(), params.browser);
598 EXPECT_EQ(Browser::TYPE_POPUP, params.browser->type());
599 #if 0
600 // TODO(stevenjb): Enable this test. See: crbug.com/79493
601 EXPECT_FALSE(p.browser->window()->IsActive());
602 #endif
605 // This test verifies that navigating with WindowOpenDisposition = NEW_POPUP
606 // and trusted_source = true results in a new Browser where is_trusted_source()
607 // is true.
608 IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_NewPopupTrusted) {
609 chrome::NavigateParams params(MakeNavigateParams());
610 params.disposition = NEW_POPUP;
611 params.trusted_source = true;
612 params.window_bounds = gfx::Rect(0, 0, 200, 200);
613 // Wait for new popup to to load and gain focus.
614 ui_test_utils::NavigateToURL(&params);
616 // Navigate() should have opened a new popup window of TYPE_TRUSTED_POPUP.
617 EXPECT_NE(browser(), params.browser);
618 EXPECT_TRUE(params.browser->is_type_popup());
619 EXPECT_TRUE(params.browser->is_trusted_source());
623 // This test verifies that navigating with WindowOpenDisposition = NEW_WINDOW
624 // always opens a new window.
625 IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_NewWindow) {
626 chrome::NavigateParams params(MakeNavigateParams());
627 params.disposition = NEW_WINDOW;
628 chrome::Navigate(&params);
630 // Navigate() should have opened a new toplevel window.
631 EXPECT_NE(browser(), params.browser);
632 EXPECT_TRUE(params.browser->is_type_tabbed());
634 // We should now have two windows, the browser() provided by the framework and
635 // the new normal window.
636 EXPECT_EQ(2u, chrome::GetTotalBrowserCount());
637 EXPECT_EQ(1, browser()->tab_strip_model()->count());
638 EXPECT_EQ(1, params.browser->tab_strip_model()->count());
641 // This test verifies that navigating with WindowOpenDisposition = INCOGNITO
642 // opens a new incognito window if no existing incognito window is present.
643 IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_Incognito) {
644 chrome::NavigateParams params(MakeNavigateParams());
645 params.disposition = OFF_THE_RECORD;
646 chrome::Navigate(&params);
648 // Navigate() should have opened a new toplevel incognito window.
649 EXPECT_NE(browser(), params.browser);
650 EXPECT_EQ(browser()->profile()->GetOffTheRecordProfile(),
651 params.browser->profile());
653 // |source_contents| should be set to NULL because the profile for the new
654 // page is different from the originating page.
655 EXPECT_EQ(NULL, params.source_contents);
657 // We should now have two windows, the browser() provided by the framework and
658 // the new incognito window.
659 EXPECT_EQ(2u, chrome::GetTotalBrowserCount());
660 EXPECT_EQ(1, browser()->tab_strip_model()->count());
661 EXPECT_EQ(1, params.browser->tab_strip_model()->count());
664 // This test verifies that navigating with WindowOpenDisposition = INCOGNITO
665 // reuses an existing incognito window when possible.
666 IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_IncognitoRefocus) {
667 Browser* incognito_browser =
668 CreateEmptyBrowserForType(Browser::TYPE_TABBED,
669 browser()->profile()->GetOffTheRecordProfile());
670 chrome::NavigateParams params(MakeNavigateParams());
671 params.disposition = OFF_THE_RECORD;
672 chrome::Navigate(&params);
674 // Navigate() should have opened a new tab in the existing incognito window.
675 EXPECT_NE(browser(), params.browser);
676 EXPECT_EQ(params.browser, incognito_browser);
678 // We should now have two windows, the browser() provided by the framework and
679 // the incognito window we opened earlier.
680 EXPECT_EQ(2u, chrome::GetTotalBrowserCount());
681 EXPECT_EQ(1, browser()->tab_strip_model()->count());
682 EXPECT_EQ(2, incognito_browser->tab_strip_model()->count());
685 // This test verifies that no navigation action occurs when
686 // WindowOpenDisposition = SUPPRESS_OPEN.
687 IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_SuppressOpen) {
688 RunSuppressTest(SUPPRESS_OPEN);
691 // This test verifies that no navigation action occurs when
692 // WindowOpenDisposition = SAVE_TO_DISK.
693 IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_SaveToDisk) {
694 RunSuppressTest(SAVE_TO_DISK);
697 // This test verifies that no navigation action occurs when
698 // WindowOpenDisposition = IGNORE_ACTION.
699 IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_IgnoreAction) {
700 RunSuppressTest(IGNORE_ACTION);
703 // This tests adding a foreground tab with a predefined WebContents.
704 IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, TargetContents_ForegroundTab) {
705 chrome::NavigateParams params(MakeNavigateParams());
706 params.disposition = NEW_FOREGROUND_TAB;
707 params.target_contents = CreateWebContents();
708 chrome::Navigate(&params);
710 // Navigate() should have opened the contents in a new foreground in the
711 // current Browser.
712 EXPECT_EQ(browser(), params.browser);
713 EXPECT_EQ(browser()->tab_strip_model()->GetActiveWebContents(),
714 params.target_contents);
716 // We should have one window, with two tabs.
717 EXPECT_EQ(1u, chrome::GetTotalBrowserCount());
718 EXPECT_EQ(2, browser()->tab_strip_model()->count());
721 #if defined(OS_WIN)
722 // This tests adding a popup with a predefined WebContents.
723 IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, DISABLED_TargetContents_Popup) {
724 chrome::NavigateParams params(MakeNavigateParams());
725 params.disposition = NEW_POPUP;
726 params.target_contents = CreateWebContents();
727 params.window_bounds = gfx::Rect(10, 10, 500, 500);
728 chrome::Navigate(&params);
730 // Navigate() should have opened a new popup window.
731 EXPECT_NE(browser(), params.browser);
732 EXPECT_TRUE(params.browser->is_type_popup());
733 EXPECT_FALSE(params.browser->is_app());
735 // The web platform is weird. The window bounds specified in
736 // |params.window_bounds| are used as follows:
737 // - the origin is used to position the window
738 // - the size is used to size the WebContents of the window.
739 // As such the position of the resulting window will always match
740 // params.window_bounds.origin(), but its size will not. We need to match
741 // the size against the selected tab's view's container size.
742 // Only Windows positions the window according to
743 // |params.window_bounds.origin()| - on Mac the window is offset from the
744 // opener and on Linux it always opens at 0,0.
745 EXPECT_EQ(params.window_bounds.origin(),
746 params.browser->window()->GetRestoredBounds().origin());
747 // All platforms should respect size however provided width > 400 (Mac has a
748 // minimum window width of 400).
749 EXPECT_EQ(params.window_bounds.size(),
750 params.target_contents->GetContainerBounds().size());
752 // We should have two windows, the new popup and the browser() provided by the
753 // framework.
754 EXPECT_EQ(2u, chrome::GetTotalBrowserCount());
755 EXPECT_EQ(1, browser()->tab_strip_model()->count());
756 EXPECT_EQ(1, params.browser->tab_strip_model()->count());
758 #endif
760 // This tests adding a tab at a specific index.
761 IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Tabstrip_InsertAtIndex) {
762 // This is not meant to be a comprehensive test of whether or not the tab
763 // implementation of the browser observes the insertion index. That is
764 // covered by the unit tests for TabStripModel. This merely verifies that
765 // insertion index preference is reflected in common cases.
766 chrome::NavigateParams params(MakeNavigateParams());
767 params.disposition = NEW_FOREGROUND_TAB;
768 params.tabstrip_index = 0;
769 params.tabstrip_add_types = TabStripModel::ADD_FORCE_INDEX;
770 chrome::Navigate(&params);
772 // Navigate() should have inserted a new tab at slot 0 in the tabstrip.
773 EXPECT_EQ(browser(), params.browser);
774 EXPECT_EQ(0, browser()->tab_strip_model()->GetIndexOfWebContents(
775 static_cast<const WebContents*>(params.target_contents)));
777 // We should have one window - the browser() provided by the framework.
778 EXPECT_EQ(1u, chrome::GetTotalBrowserCount());
779 EXPECT_EQ(2, browser()->tab_strip_model()->count());
782 // This test verifies that constructing params with disposition = SINGLETON_TAB
783 // and IGNORE_AND_NAVIGATE opens a new tab navigated to the specified URL if
784 // no previous tab with that URL (minus the path) exists.
785 IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
786 Disposition_SingletonTabNew_IgnorePath) {
787 chrome::AddSelectedTabWithURL(browser(), GetGoogleURL(),
788 ui::PAGE_TRANSITION_LINK);
790 // We should have one browser with 2 tabs, the 2nd selected.
791 EXPECT_EQ(1u, chrome::GetTotalBrowserCount());
792 EXPECT_EQ(2, browser()->tab_strip_model()->count());
793 EXPECT_EQ(1, browser()->tab_strip_model()->active_index());
795 // Navigate to a new singleton tab with a sub-page.
796 chrome::NavigateParams params(MakeNavigateParams());
797 params.disposition = SINGLETON_TAB;
798 params.url = GetContentSettingsURL();
799 params.window_action = chrome::NavigateParams::SHOW_WINDOW;
800 params.path_behavior = chrome::NavigateParams::IGNORE_AND_NAVIGATE;
801 chrome::Navigate(&params);
803 // The last tab should now be selected and navigated to the sub-page of the
804 // URL.
805 EXPECT_EQ(browser(), params.browser);
806 EXPECT_EQ(3, browser()->tab_strip_model()->count());
807 EXPECT_EQ(2, browser()->tab_strip_model()->active_index());
808 EXPECT_EQ(GetContentSettingsURL(),
809 ShortenUberURL(browser()->tab_strip_model()->
810 GetActiveWebContents()->GetURL()));
813 // This test verifies that constructing params with disposition = SINGLETON_TAB
814 // and IGNORE_AND_NAVIGATE opens an existing tab with the matching URL (minus
815 // the path) which is navigated to the specified URL.
816 IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
817 Disposition_SingletonTabExisting_IgnorePath) {
818 GURL singleton_url1(GetSettingsURL());
819 chrome::AddSelectedTabWithURL(browser(), singleton_url1,
820 ui::PAGE_TRANSITION_LINK);
821 chrome::AddSelectedTabWithURL(browser(), GetGoogleURL(),
822 ui::PAGE_TRANSITION_LINK);
824 // We should have one browser with 3 tabs, the 3rd selected.
825 EXPECT_EQ(1u, chrome::GetTotalBrowserCount());
826 EXPECT_EQ(3, browser()->tab_strip_model()->count());
827 EXPECT_EQ(2, browser()->tab_strip_model()->active_index());
829 // Navigate to singleton_url1.
830 chrome::NavigateParams params(MakeNavigateParams());
831 params.disposition = SINGLETON_TAB;
832 params.url = GetContentSettingsURL();
833 params.window_action = chrome::NavigateParams::SHOW_WINDOW;
834 params.path_behavior = chrome::NavigateParams::IGNORE_AND_NAVIGATE;
835 chrome::Navigate(&params);
837 // The middle tab should now be selected and navigated to the sub-page of the
838 // URL.
839 EXPECT_EQ(browser(), params.browser);
840 EXPECT_EQ(3, browser()->tab_strip_model()->count());
841 EXPECT_EQ(1, browser()->tab_strip_model()->active_index());
842 EXPECT_EQ(GetContentSettingsURL(),
843 ShortenUberURL(browser()->tab_strip_model()->
844 GetActiveWebContents()->GetURL()));
847 // This test verifies that constructing params with disposition = SINGLETON_TAB
848 // and IGNORE_AND_NAVIGATE opens an existing tab with the matching URL (minus
849 // the path) which is navigated to the specified URL.
850 IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
851 Disposition_SingletonTabExistingSubPath_IgnorePath) {
852 GURL singleton_url1(GetContentSettingsURL());
853 chrome::AddSelectedTabWithURL(browser(), singleton_url1,
854 ui::PAGE_TRANSITION_LINK);
855 chrome::AddSelectedTabWithURL(browser(), GetGoogleURL(),
856 ui::PAGE_TRANSITION_LINK);
858 // We should have one browser with 3 tabs, the 3rd selected.
859 EXPECT_EQ(1u, chrome::GetTotalBrowserCount());
860 EXPECT_EQ(3, browser()->tab_strip_model()->count());
861 EXPECT_EQ(2, browser()->tab_strip_model()->active_index());
863 // Navigate to singleton_url1.
864 chrome::NavigateParams params(MakeNavigateParams());
865 params.disposition = SINGLETON_TAB;
866 params.url = GetClearBrowsingDataURL();
867 params.window_action = chrome::NavigateParams::SHOW_WINDOW;
868 params.path_behavior = chrome::NavigateParams::IGNORE_AND_NAVIGATE;
869 chrome::Navigate(&params);
871 // The middle tab should now be selected and navigated to the sub-page of the
872 // URL.
873 EXPECT_EQ(browser(), params.browser);
874 EXPECT_EQ(3, browser()->tab_strip_model()->count());
875 EXPECT_EQ(1, browser()->tab_strip_model()->active_index());
876 EXPECT_EQ(GetClearBrowsingDataURL(),
877 ShortenUberURL(browser()->tab_strip_model()->
878 GetActiveWebContents()->GetURL()));
881 // This test verifies that constructing params with disposition = SINGLETON_TAB
882 // and IGNORE_AND_STAY_PUT opens an existing tab with the matching URL (minus
883 // the path).
884 IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
885 Disposition_SingletonTabExistingSubPath_IgnorePath2) {
886 GURL singleton_url1(GetContentSettingsURL());
887 chrome::AddSelectedTabWithURL(browser(), singleton_url1,
888 ui::PAGE_TRANSITION_LINK);
889 chrome::AddSelectedTabWithURL(browser(), GetGoogleURL(),
890 ui::PAGE_TRANSITION_LINK);
892 // We should have one browser with 3 tabs, the 3rd selected.
893 EXPECT_EQ(1u, chrome::GetTotalBrowserCount());
894 EXPECT_EQ(3, browser()->tab_strip_model()->count());
895 EXPECT_EQ(2, browser()->tab_strip_model()->active_index());
897 // Navigate to singleton_url1.
898 chrome::NavigateParams params(MakeNavigateParams());
899 params.disposition = SINGLETON_TAB;
900 params.url = GetClearBrowsingDataURL();
901 params.window_action = chrome::NavigateParams::SHOW_WINDOW;
902 params.path_behavior = chrome::NavigateParams::IGNORE_AND_STAY_PUT;
903 chrome::Navigate(&params);
905 // The middle tab should now be selected.
906 EXPECT_EQ(browser(), params.browser);
907 EXPECT_EQ(3, browser()->tab_strip_model()->count());
908 EXPECT_EQ(1, browser()->tab_strip_model()->active_index());
909 EXPECT_EQ(singleton_url1,
910 ShortenUberURL(browser()->tab_strip_model()->
911 GetActiveWebContents()->GetURL()));
914 // This test verifies that constructing params with disposition = SINGLETON_TAB
915 // and IGNORE_AND_NAVIGATE will update the current tab's URL if the currently
916 // selected tab is a match but has a different path.
917 IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
918 Disposition_SingletonTabFocused_IgnorePath) {
919 GURL singleton_url_current(GetContentSettingsURL());
920 chrome::AddSelectedTabWithURL(browser(), singleton_url_current,
921 ui::PAGE_TRANSITION_LINK);
923 // We should have one browser with 2 tabs, the 2nd selected.
924 EXPECT_EQ(1u, chrome::GetTotalBrowserCount());
925 EXPECT_EQ(2, browser()->tab_strip_model()->count());
926 EXPECT_EQ(1, browser()->tab_strip_model()->active_index());
928 // Navigate to a different settings path.
929 GURL singleton_url_target(GetClearBrowsingDataURL());
930 chrome::NavigateParams params(MakeNavigateParams());
931 params.disposition = SINGLETON_TAB;
932 params.url = singleton_url_target;
933 params.window_action = chrome::NavigateParams::SHOW_WINDOW;
934 params.path_behavior = chrome::NavigateParams::IGNORE_AND_NAVIGATE;
935 chrome::Navigate(&params);
937 // The second tab should still be selected, but navigated to the new path.
938 EXPECT_EQ(browser(), params.browser);
939 EXPECT_EQ(2, browser()->tab_strip_model()->count());
940 EXPECT_EQ(1, browser()->tab_strip_model()->active_index());
941 EXPECT_EQ(singleton_url_target,
942 ShortenUberURL(browser()->tab_strip_model()->
943 GetActiveWebContents()->GetURL()));
946 // This test verifies that constructing params with disposition = SINGLETON_TAB
947 // and IGNORE_AND_NAVIGATE will open an existing matching tab with a different
948 // query.
949 IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
950 Disposition_SingletonTabExisting_IgnoreQuery) {
951 int initial_tab_count = browser()->tab_strip_model()->count();
952 GURL singleton_url_current("chrome://settings/internet");
953 chrome::AddSelectedTabWithURL(browser(), singleton_url_current,
954 ui::PAGE_TRANSITION_LINK);
956 EXPECT_EQ(initial_tab_count + 1, browser()->tab_strip_model()->count());
957 EXPECT_EQ(initial_tab_count, browser()->tab_strip_model()->active_index());
959 // Navigate to a different settings path.
960 GURL singleton_url_target(
961 "chrome://settings/internet?"
962 "guid=ethernet_00aa00aa00aa&networkType=1");
963 chrome::NavigateParams params(MakeNavigateParams());
964 params.disposition = SINGLETON_TAB;
965 params.url = singleton_url_target;
966 params.window_action = chrome::NavigateParams::SHOW_WINDOW;
967 params.path_behavior = chrome::NavigateParams::IGNORE_AND_NAVIGATE;
968 chrome::Navigate(&params);
970 // Last tab should still be selected.
971 EXPECT_EQ(browser(), params.browser);
972 EXPECT_EQ(initial_tab_count + 1, browser()->tab_strip_model()->count());
973 EXPECT_EQ(initial_tab_count, browser()->tab_strip_model()->active_index());
976 // This test verifies that the settings page isn't opened in the incognito
977 // window.
978 // Disabled until fixed for uber settings: http://crbug.com/111243
979 IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
980 DISABLED_Disposition_Settings_UseNonIncognitoWindow) {
981 RunUseNonIncognitoWindowTest(GetSettingsURL());
984 // This test verifies that the view-source settings page isn't opened in the
985 // incognito window.
986 IN_PROC_BROWSER_TEST_F(
987 BrowserNavigatorTest,
988 Disposition_ViewSource_Settings_DoNothingIfIncognitoForced) {
989 std::string view_source(content::kViewSourceScheme);
990 view_source.append(":");
991 view_source.append(chrome::kChromeUISettingsURL);
992 RunDoNothingIfIncognitoIsForcedTest(GURL(view_source));
995 // This test verifies that the view-source settings page isn't opened in the
996 // incognito window even if incognito mode is forced (does nothing in that
997 // case).
998 IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
999 Disposition_ViewSource_Settings_UseNonIncognitoWindow) {
1000 std::string view_source(content::kViewSourceScheme);
1001 view_source.append(":");
1002 view_source.append(chrome::kChromeUISettingsURL);
1003 RunUseNonIncognitoWindowTest(GURL(view_source));
1006 // This test verifies that the settings page isn't opened in the incognito
1007 // window from a non-incognito window (bookmark open-in-incognito trigger).
1008 // Disabled until fixed for uber settings: http://crbug.com/111243
1009 IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
1010 DISABLED_Disposition_Settings_UseNonIncognitoWindowForBookmark) {
1011 chrome::NavigateParams params(browser(), GetSettingsURL(),
1012 ui::PAGE_TRANSITION_AUTO_BOOKMARK);
1013 params.disposition = OFF_THE_RECORD;
1015 content::WindowedNotificationObserver observer(
1016 content::NOTIFICATION_LOAD_STOP,
1017 content::NotificationService::AllSources());
1018 chrome::Navigate(&params);
1019 observer.Wait();
1022 EXPECT_EQ(1u, chrome::GetTotalBrowserCount());
1023 EXPECT_EQ(GetSettingsURL(),
1024 ShortenUberURL(browser()->tab_strip_model()->
1025 GetActiveWebContents()->GetURL()));
1028 // Settings page is expected to always open in normal mode regardless
1029 // of whether the user is trying to open it in incognito mode or not.
1030 // This test verifies that if incognito mode is forced (by policy), settings
1031 // page doesn't open at all.
1032 // Disabled until fixed for uber settings: http://crbug.com/111243
1033 IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
1034 DISABLED_Disposition_Settings_DoNothingIfIncognitoIsForced) {
1035 RunDoNothingIfIncognitoIsForcedTest(GetSettingsURL());
1038 // This test verifies that the bookmarks page isn't opened in the incognito
1039 // window.
1040 IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
1041 Disposition_Bookmarks_UseNonIncognitoWindow) {
1042 RunUseNonIncognitoWindowTest(GURL(chrome::kChromeUIBookmarksURL));
1045 // Bookmark manager is expected to always open in normal mode regardless
1046 // of whether the user is trying to open it in incognito mode or not.
1047 // This test verifies that if incognito mode is forced (by policy), bookmark
1048 // manager doesn't open at all.
1049 IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
1050 Disposition_Bookmarks_DoNothingIfIncognitoIsForced) {
1051 RunDoNothingIfIncognitoIsForcedTest(GURL(chrome::kChromeUIBookmarksURL));
1054 // This test makes sure a crashed singleton tab reloads from a new navigation.
1055 // http://crbug.com/396371
1056 IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
1057 DISABLED_NavigateToCrashedSingletonTab) {
1058 GURL singleton_url(GetContentSettingsURL());
1059 WebContents* web_contents = chrome::AddSelectedTabWithURL(
1060 browser(), singleton_url, ui::PAGE_TRANSITION_LINK);
1062 // We should have one browser with 2 tabs, the 2nd selected.
1063 EXPECT_EQ(1u, chrome::GetTotalBrowserCount());
1064 EXPECT_EQ(2, browser()->tab_strip_model()->count());
1065 EXPECT_EQ(1, browser()->tab_strip_model()->active_index());
1067 // Kill the singleton tab.
1068 web_contents->SetIsCrashed(base::TERMINATION_STATUS_PROCESS_CRASHED, -1);
1069 EXPECT_TRUE(web_contents->IsCrashed());
1071 chrome::NavigateParams params(MakeNavigateParams());
1072 params.disposition = SINGLETON_TAB;
1073 params.url = singleton_url;
1074 params.window_action = chrome::NavigateParams::SHOW_WINDOW;
1075 params.path_behavior = chrome::NavigateParams::IGNORE_AND_NAVIGATE;
1076 ui_test_utils::NavigateToURL(&params);
1078 // The tab should not be sad anymore.
1079 EXPECT_FALSE(web_contents->IsCrashed());
1082 IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
1083 NavigateFromDefaultToOptionsInSameTab) {
1085 content::WindowedNotificationObserver observer(
1086 content::NOTIFICATION_LOAD_STOP,
1087 content::NotificationService::AllSources());
1088 chrome::ShowSettings(browser());
1089 observer.Wait();
1091 EXPECT_EQ(1, browser()->tab_strip_model()->count());
1092 EXPECT_EQ(GetSettingsURL(),
1093 ShortenUberURL(browser()->tab_strip_model()->
1094 GetActiveWebContents()->GetURL()));
1097 IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
1098 NavigateFromBlankToOptionsInSameTab) {
1099 chrome::NavigateParams params(MakeNavigateParams());
1100 params.url = GURL(url::kAboutBlankURL);
1101 ui_test_utils::NavigateToURL(&params);
1104 content::WindowedNotificationObserver observer(
1105 content::NOTIFICATION_LOAD_STOP,
1106 content::NotificationService::AllSources());
1107 chrome::ShowSettings(browser());
1108 observer.Wait();
1110 EXPECT_EQ(1, browser()->tab_strip_model()->count());
1111 EXPECT_EQ(GetSettingsURL(),
1112 ShortenUberURL(browser()->tab_strip_model()->
1113 GetActiveWebContents()->GetURL()));
1116 IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
1117 NavigateFromNTPToOptionsInSameTab) {
1118 chrome::NavigateParams params(MakeNavigateParams());
1119 params.url = GURL(chrome::kChromeUINewTabURL);
1120 ui_test_utils::NavigateToURL(&params);
1121 EXPECT_EQ(1, browser()->tab_strip_model()->count());
1122 EXPECT_EQ(GURL(chrome::kChromeUINewTabURL),
1123 browser()->tab_strip_model()->GetActiveWebContents()->GetURL());
1126 content::WindowedNotificationObserver observer(
1127 content::NOTIFICATION_LOAD_STOP,
1128 content::NotificationService::AllSources());
1129 chrome::ShowSettings(browser());
1130 observer.Wait();
1132 EXPECT_EQ(1, browser()->tab_strip_model()->count());
1133 EXPECT_EQ(GetSettingsURL(),
1134 ShortenUberURL(browser()->tab_strip_model()->
1135 GetActiveWebContents()->GetURL()));
1138 IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
1139 NavigateFromPageToOptionsInNewTab) {
1140 chrome::NavigateParams params(MakeNavigateParams());
1141 ui_test_utils::NavigateToURL(&params);
1142 EXPECT_EQ(GetGoogleURL(),
1143 browser()->tab_strip_model()->GetActiveWebContents()->GetURL());
1144 EXPECT_EQ(1u, chrome::GetTotalBrowserCount());
1145 EXPECT_EQ(1, browser()->tab_strip_model()->count());
1148 content::WindowedNotificationObserver observer(
1149 content::NOTIFICATION_LOAD_STOP,
1150 content::NotificationService::AllSources());
1151 chrome::ShowSettings(browser());
1152 observer.Wait();
1154 EXPECT_EQ(2, browser()->tab_strip_model()->count());
1155 EXPECT_EQ(GetSettingsURL(),
1156 ShortenUberURL(browser()->tab_strip_model()->
1157 GetActiveWebContents()->GetURL()));
1160 IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
1161 NavigateFromNTPToOptionsSingleton) {
1163 content::WindowedNotificationObserver observer(
1164 content::NOTIFICATION_LOAD_STOP,
1165 content::NotificationService::AllSources());
1166 chrome::ShowSettings(browser());
1167 observer.Wait();
1169 EXPECT_EQ(1, browser()->tab_strip_model()->count());
1171 chrome::NewTab(browser());
1172 EXPECT_EQ(2, browser()->tab_strip_model()->count());
1175 content::WindowedNotificationObserver observer(
1176 content::NOTIFICATION_LOAD_STOP,
1177 content::NotificationService::AllSources());
1178 chrome::ShowSettings(browser());
1179 observer.Wait();
1181 EXPECT_EQ(2, browser()->tab_strip_model()->count());
1182 EXPECT_EQ(GetSettingsURL(),
1183 ShortenUberURL(browser()->tab_strip_model()->
1184 GetActiveWebContents()->GetURL()));
1187 IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
1188 NavigateFromNTPToOptionsPageInSameTab) {
1190 content::WindowedNotificationObserver observer(
1191 content::NOTIFICATION_LOAD_STOP,
1192 content::NotificationService::AllSources());
1193 chrome::ShowClearBrowsingDataDialog(browser());
1194 observer.Wait();
1196 EXPECT_EQ(1, browser()->tab_strip_model()->count());
1197 EXPECT_EQ(GetClearBrowsingDataURL(),
1198 browser()->tab_strip_model()->GetActiveWebContents()->GetURL());
1200 chrome::NewTab(browser());
1201 EXPECT_EQ(2, browser()->tab_strip_model()->count());
1204 content::WindowedNotificationObserver observer(
1205 content::NOTIFICATION_LOAD_STOP,
1206 content::NotificationService::AllSources());
1207 chrome::ShowClearBrowsingDataDialog(browser());
1208 observer.Wait();
1210 EXPECT_EQ(2, browser()->tab_strip_model()->count());
1211 EXPECT_EQ(GetClearBrowsingDataURL(),
1212 browser()->tab_strip_model()->GetActiveWebContents()->GetURL());
1215 IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
1216 NavigateFromOtherTabToSingletonOptions) {
1218 content::WindowedNotificationObserver observer(
1219 content::NOTIFICATION_LOAD_STOP,
1220 content::NotificationService::AllSources());
1221 chrome::ShowSettings(browser());
1222 observer.Wait();
1225 content::WindowedNotificationObserver observer(
1226 content::NOTIFICATION_LOAD_STOP,
1227 content::NotificationService::AllSources());
1228 chrome::AddSelectedTabWithURL(browser(), GetGoogleURL(),
1229 ui::PAGE_TRANSITION_LINK);
1230 observer.Wait();
1233 // This load should simply cause a tab switch.
1234 chrome::ShowSettings(browser());
1236 EXPECT_EQ(2, browser()->tab_strip_model()->count());
1237 EXPECT_EQ(GetSettingsURL(),
1238 ShortenUberURL(browser()->tab_strip_model()->
1239 GetActiveWebContents()->GetURL()));
1242 IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, CloseSingletonTab) {
1243 for (int i = 0; i < 2; ++i) {
1244 content::WindowedNotificationObserver observer(
1245 content::NOTIFICATION_LOAD_STOP,
1246 content::NotificationService::AllSources());
1247 chrome::AddSelectedTabWithURL(browser(), GetGoogleURL(),
1248 ui::PAGE_TRANSITION_TYPED);
1249 observer.Wait();
1252 browser()->tab_strip_model()->ActivateTabAt(0, true);
1255 content::WindowedNotificationObserver observer(
1256 content::NOTIFICATION_LOAD_STOP,
1257 content::NotificationService::AllSources());
1258 chrome::ShowSettings(browser());
1259 observer.Wait();
1262 EXPECT_TRUE(browser()->tab_strip_model()->CloseWebContentsAt(
1263 2, TabStripModel::CLOSE_USER_GESTURE));
1264 EXPECT_EQ(0, browser()->tab_strip_model()->active_index());
1267 // TODO(csilv): Update this for uber page. http://crbug.com/111579.
1268 IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
1269 DISABLED_NavigateFromDefaultToHistoryInSameTab) {
1271 content::WindowedNotificationObserver observer(
1272 content::NOTIFICATION_LOAD_STOP,
1273 content::NotificationService::AllSources());
1274 chrome::ShowHistory(browser());
1275 observer.Wait();
1277 EXPECT_EQ(1, browser()->tab_strip_model()->count());
1278 EXPECT_EQ(GURL(chrome::kChromeUIHistoryFrameURL),
1279 browser()->tab_strip_model()->GetActiveWebContents()->GetURL());
1282 // TODO(linux_aura) http://crbug.com/163931
1283 #if defined(OS_LINUX) && !defined(OS_CHROMEOS) && defined(USE_AURA)
1284 #define MAYBE_NavigateFromDefaultToBookmarksInSameTab DISABLED_NavigateFromDefaultToBookmarksInSameTab
1285 #else
1286 #define MAYBE_NavigateFromDefaultToBookmarksInSameTab NavigateFromDefaultToBookmarksInSameTab
1287 #endif
1288 IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
1289 MAYBE_NavigateFromDefaultToBookmarksInSameTab) {
1291 content::WindowedNotificationObserver observer(
1292 content::NOTIFICATION_LOAD_STOP,
1293 content::NotificationService::AllSources());
1294 chrome::ShowBookmarkManager(browser());
1295 observer.Wait();
1297 EXPECT_EQ(1, browser()->tab_strip_model()->count());
1298 EXPECT_TRUE(base::StartsWith(
1299 browser()->tab_strip_model()->GetActiveWebContents()->GetURL().spec(),
1300 chrome::kChromeUIBookmarksURL, base::CompareCase::SENSITIVE));
1303 IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
1304 NavigateFromDefaultToDownloadsInSameTab) {
1306 content::WindowedNotificationObserver observer(
1307 content::NOTIFICATION_LOAD_STOP,
1308 content::NotificationService::AllSources());
1309 chrome::ShowDownloads(browser());
1310 observer.Wait();
1312 EXPECT_EQ(1, browser()->tab_strip_model()->count());
1313 EXPECT_EQ(GURL(chrome::kChromeUIDownloadsURL),
1314 browser()->tab_strip_model()->GetActiveWebContents()->GetURL());
1317 IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
1318 NavigateWithoutBrowser) {
1319 // First navigate using the profile of the existing browser window, and
1320 // check that the window is reused.
1321 chrome::NavigateParams params(browser()->profile(), GetGoogleURL(),
1322 ui::PAGE_TRANSITION_LINK);
1323 ui_test_utils::NavigateToURL(&params);
1324 EXPECT_EQ(1u, chrome::GetTotalBrowserCount());
1326 // Now navigate using the incognito profile and check that a new window
1327 // is created.
1328 chrome::NavigateParams params_incognito(
1329 browser()->profile()->GetOffTheRecordProfile(),
1330 GetGoogleURL(), ui::PAGE_TRANSITION_LINK);
1331 ui_test_utils::NavigateToURL(&params_incognito);
1332 EXPECT_EQ(2u, chrome::GetTotalBrowserCount());
1335 IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, ViewSourceIsntSingleton) {
1336 const std::string viewsource_ntp_url =
1337 std::string(content::kViewSourceScheme) + ":" +
1338 chrome::kChromeUIVersionURL;
1340 chrome::NavigateParams viewsource_params(browser(),
1341 GURL(viewsource_ntp_url),
1342 ui::PAGE_TRANSITION_LINK);
1343 ui_test_utils::NavigateToURL(&viewsource_params);
1345 chrome::NavigateParams singleton_params(browser(),
1346 GURL(chrome::kChromeUIVersionURL),
1347 ui::PAGE_TRANSITION_LINK);
1348 singleton_params.disposition = SINGLETON_TAB;
1349 EXPECT_EQ(-1, chrome::GetIndexOfSingletonTab(&singleton_params));
1352 // This test verifies that browser initiated navigations can send requests
1353 // using POST.
1354 IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
1355 SendBrowserInitiatedRequestUsingPOST) {
1356 // Uses a test sever to verify POST request.
1357 ASSERT_TRUE(test_server()->Start());
1359 // Open a browser initiated POST request in new foreground tab.
1360 base::string16 expected_title(base::ASCIIToUTF16(kExpectedTitle));
1361 std::string post_data = kExpectedTitle;
1362 base::string16 title;
1363 ASSERT_TRUE(OpenPOSTURLInNewForegroundTabAndGetTitle(
1364 test_server()->GetURL(kEchoTitleCommand), post_data, true, &title));
1365 EXPECT_EQ(expected_title, title);
1368 // This test verifies that renderer initiated navigations can NOT send requests
1369 // using POST.
1370 IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
1371 SendRendererInitiatedRequestUsingPOST) {
1372 // Uses a test sever to verify POST request.
1373 ASSERT_TRUE(test_server()->Start());
1375 // Open a renderer initiated POST request in new foreground tab.
1376 base::string16 expected_title(base::ASCIIToUTF16(kExpectedTitle));
1377 std::string post_data = kExpectedTitle;
1378 base::string16 title;
1379 ASSERT_TRUE(OpenPOSTURLInNewForegroundTabAndGetTitle(
1380 test_server()->GetURL(kEchoTitleCommand), post_data, false, &title));
1381 EXPECT_NE(expected_title, title);
1384 // This test navigates to a data URL that contains BiDi control
1385 // characters. For security reasons, BiDi control chars should always be
1386 // escaped in the URL but they should be unescaped in the loaded HTML.
1387 IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
1388 NavigateToDataURLWithBiDiControlChars) {
1389 // Text in Arabic.
1390 std::string text = "\xD8\xA7\xD8\xAE\xD8\xAA\xD8\xA8\xD8\xA7\xD8\xB1";
1391 // Page title starts with RTL mark.
1392 std::string unescaped_title = "\xE2\x80\x8F" + text;
1393 std::string data_url = "data:text/html;charset=utf-8,<html><title>" +
1394 unescaped_title + "</title></html>";
1395 // BiDi control chars in URLs are always escaped, so the expected URL should
1396 // have the title with the escaped RTL mark.
1397 std::string escaped_title = "%E2%80%8F" + text;
1398 std::string expected_url = "data:text/html;charset=utf-8,<html><title>" +
1399 escaped_title + "</title></html>";
1401 // Navigate to the page.
1402 chrome::NavigateParams params(MakeNavigateParams());
1403 params.disposition = NEW_FOREGROUND_TAB;
1404 params.url = GURL(data_url);
1405 params.window_action = chrome::NavigateParams::SHOW_WINDOW;
1406 ui_test_utils::NavigateToURL(&params);
1408 base::string16 expected_title(base::UTF8ToUTF16(unescaped_title));
1409 EXPECT_TRUE(params.target_contents);
1410 EXPECT_EQ(expected_title, params.target_contents->GetTitle());
1411 // GURL always keeps non-ASCII characters escaped, but check them anyways.
1412 EXPECT_EQ(GURL(expected_url).spec(), params.target_contents->GetURL().spec());
1413 // Check the omnibox text. It should have escaped RTL with unescaped text.
1414 LocationBar* location_bar = browser()->window()->GetLocationBar();
1415 OmniboxView* omnibox_view = location_bar->GetOmniboxView();
1416 EXPECT_EQ(base::UTF8ToUTF16(expected_url), omnibox_view->GetText());
1419 } // namespace