blob: 3a72fb6911678ce5ead739fc2ae9de4dbe357234 [file] [log] [blame]
[email protected]8643e6d2012-01-18 20:26:101// Copyright (c) 2012 The Chromium Authors. All rights reserved.
[email protected]a1feae52010-10-11 22:14:452// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
[email protected]bd817c22011-02-09 08:16:465#include "chrome/browser/ui/browser_navigator_browsertest.h"
6
[email protected]fc2b46b2014-05-03 16:33:457#include "base/strings/string_util.h"
[email protected]a2efc35d2013-08-03 23:17:258#include "base/strings/utf_string_conversions.h"
avi655876a2015-12-25 07:18:159#include "build/build_config.h"
[email protected]26c53e662011-07-09 02:21:0210#include "chrome/app/chrome_command_ids.h"
[email protected]93ad8e1c2011-11-08 21:34:0511#include "chrome/browser/prefs/incognito_mode_prefs.h"
[email protected]8ecad5e2010-12-02 21:18:3312#include "chrome/browser/profiles/profile.h"
[email protected]2b09ae552013-02-23 06:38:0313#include "chrome/browser/ui/browser.h"
[email protected]a37d4b02012-06-25 21:56:1014#include "chrome/browser/ui/browser_commands.h"
[email protected]0665ebe2013-02-13 09:53:1915#include "chrome/browser/ui/browser_finder.h"
[email protected]339d6dd2010-11-12 00:41:5816#include "chrome/browser/ui/browser_navigator.h"
thestige80821242015-09-30 23:46:0817#include "chrome/browser/ui/browser_navigator_params.h"
[email protected]52877dbc62012-06-29 22:22:0318#include "chrome/browser/ui/browser_tabstrip.h"
[email protected]bb89e7482010-11-17 18:27:0419#include "chrome/browser/ui/browser_window.h"
[email protected]5d9cace72012-06-21 16:07:1220#include "chrome/browser/ui/chrome_pages.h"
meacerc62e2ee2014-10-22 00:44:5221#include "chrome/browser/ui/location_bar/location_bar.h"
[email protected]beb1d1192013-05-14 04:47:5122#include "chrome/browser/ui/singleton_tabs.h"
[email protected]b56e2e32012-05-11 21:18:0423#include "chrome/browser/ui/tabs/tab_strip_model.h"
[email protected]93ad8e1c2011-11-08 21:34:0524#include "chrome/common/pref_names.h"
[email protected]ddddfda2011-07-14 23:19:3925#include "chrome/common/url_constants.h"
[email protected]af44e7fb2011-07-29 18:32:3226#include "chrome/test/base/ui_test_utils.h"
blundell7dbd3792015-08-05 15:14:1927#include "components/omnibox/browser/omnibox_view.h"
brettwb1fc1b82016-02-02 00:19:0828#include "components/prefs/pref_service.h"
[email protected]ad50def52011-10-19 23:17:0729#include "content/public/browser/notification_service.h"
[email protected]0d6e9bd2011-10-18 04:29:1630#include "content/public/browser/notification_types.h"
lof84501da082016-05-23 21:22:5431#include "content/public/browser/render_frame_host.h"
32#include "content/public/browser/render_process_host.h"
alexmos78d09c902016-11-17 05:15:1333#include "content/public/browser/render_view_host.h"
[email protected]83ff91c2012-01-05 20:54:1334#include "content/public/browser/web_contents.h"
alexmos78d09c902016-11-17 05:15:1335#include "content/public/common/bindings_policy.h"
lukasza477a5a22016-06-16 18:28:4336#include "content/public/common/resource_request_body.h"
lof84501da082016-05-23 21:22:5437#include "content/public/test/browser_test_utils.h"
alexmos78d09c902016-11-17 05:15:1338#include "content/public/test/test_navigation_observer.h"
svaldeza01f7d92015-11-18 17:47:5639#include "net/test/embedded_test_server/embedded_test_server.h"
[email protected]a1feae52010-10-11 22:14:4540
[email protected]4ca15302012-01-03 05:53:2041using content::WebContents;
42
[email protected]ddddfda2011-07-14 23:19:3943namespace {
44
[email protected]a2efc35d2013-08-03 23:17:2545const char kExpectedTitle[] = "PASSED!";
svaldeza01f7d92015-11-18 17:47:5646const char kEchoTitleCommand[] = "/echotitle";
[email protected]a2efc35d2013-08-03 23:17:2547
[email protected]ddddfda2011-07-14 23:19:3948GURL GetGoogleURL() {
[email protected]bd817c22011-02-09 08:16:4649 return GURL("http://www.google.com/");
50}
[email protected]a1feae52010-10-11 22:14:4551
[email protected]ddddfda2011-07-14 23:19:3952GURL GetSettingsURL() {
[email protected]f8f93eb2012-09-25 03:06:2453 return GURL(chrome::kChromeUISettingsURL);
[email protected]ddddfda2011-07-14 23:19:3954}
55
[email protected]a048ad22012-03-23 04:26:5656GURL GetContentSettingsURL() {
tommycli654a66e2016-10-29 00:37:0357 return GetSettingsURL().Resolve(chrome::kContentSettingsSubPage);
[email protected]ddddfda2011-07-14 23:19:3958}
59
[email protected]a048ad22012-03-23 04:26:5660GURL GetClearBrowsingDataURL() {
61 return GetSettingsURL().Resolve(chrome::kClearBrowserDataSubPage);
[email protected]ddddfda2011-07-14 23:19:3962}
63
[email protected]f8f93eb2012-09-25 03:06:2464// Converts long uber URLs ("chrome://chrome/foo/") to short (virtual) URLs
65// ("chrome://foo/"). This should be used to convert the return value of
66// WebContentsImpl::GetURL before comparison because it can return either the
67// real URL or the virtual URL.
68GURL ShortenUberURL(const GURL& url) {
69 std::string url_string = url.spec();
70 const std::string long_prefix = "chrome://chrome/";
71 const std::string short_prefix = "chrome://";
markusheintz74e10b22016-07-08 13:19:3672 if (!base::StartsWith(url_string, long_prefix, base::CompareCase::SENSITIVE))
[email protected]f8f93eb2012-09-25 03:06:2473 return url;
74 url_string.replace(0, long_prefix.length(), short_prefix);
75 return GURL(url_string);
76}
77
Steven Bennettsc406dd22017-07-28 00:32:3678void ShowSettings(Browser* browser) {
79 // chrome::ShowSettings just calls ShowSettingsSubPageInTabbedBrowser on
80 // non chromeos, but we want to test tab navigation here so call
81 // ShowSettingsSubPageInTabbedBrowser directly.
82 chrome::ShowSettingsSubPageInTabbedBrowser(browser, std::string());
83}
84
[email protected]a2efc35d2013-08-03 23:17:2585} // namespace
[email protected]ddddfda2011-07-14 23:19:3986
[email protected]78e2edc2012-07-01 23:32:2887chrome::NavigateParams BrowserNavigatorTest::MakeNavigateParams() const {
[email protected]bd817c22011-02-09 08:16:4688 return MakeNavigateParams(browser());
89}
[email protected]a1feae52010-10-11 22:14:4590
[email protected]78e2edc2012-07-01 23:32:2891chrome::NavigateParams BrowserNavigatorTest::MakeNavigateParams(
[email protected]bd817c22011-02-09 08:16:4692 Browser* browser) const {
[email protected]78e2edc2012-07-01 23:32:2893 chrome::NavigateParams params(browser, GetGoogleURL(),
Sylvain Defresnec6ccc77d2014-09-19 10:19:3594 ui::PAGE_TRANSITION_LINK);
[email protected]50592b52013-05-02 22:26:2595 params.window_action = chrome::NavigateParams::SHOW_WINDOW;
[email protected]bd817c22011-02-09 08:16:4696 return params;
97}
[email protected]a1feae52010-10-11 22:14:4598
[email protected]a2efc35d2013-08-03 23:17:2599bool BrowserNavigatorTest::OpenPOSTURLInNewForegroundTabAndGetTitle(
100 const GURL& url, const std::string& post_data, bool is_browser_initiated,
101 base::string16* title) {
102 chrome::NavigateParams param(MakeNavigateParams());
nick3b04f322016-08-31 19:29:19103 param.disposition = WindowOpenDisposition::NEW_FOREGROUND_TAB;
[email protected]a2efc35d2013-08-03 23:17:25104 param.url = url;
105 param.is_renderer_initiated = !is_browser_initiated;
106 param.uses_post = true;
lukasza477a5a22016-06-16 18:28:43107 param.post_data = content::ResourceRequestBody::CreateFromBytes(
[email protected]8df08cf2014-02-12 22:34:08108 post_data.data(), post_data.size());
[email protected]a2efc35d2013-08-03 23:17:25109
110 ui_test_utils::NavigateToURL(&param);
111 if (!param.target_contents)
112 return false;
113
114 // Navigate() should have opened the contents in new foreground tab in the
115 // current Browser.
116 EXPECT_EQ(browser(), param.browser);
117 EXPECT_EQ(browser()->tab_strip_model()->GetActiveWebContents(),
118 param.target_contents);
119 // We should have one window, with one tab.
120 EXPECT_EQ(1u, chrome::GetTotalBrowserCount());
121 EXPECT_EQ(2, browser()->tab_strip_model()->count());
122
123 *title = param.target_contents->GetTitle();
124 return true;
125}
126
[email protected]bd817c22011-02-09 08:16:46127Browser* BrowserNavigatorTest::CreateEmptyBrowserForType(Browser::Type type,
128 Profile* profile) {
erg7b01d692017-02-22 21:57:35129 Browser* browser = new Browser(Browser::CreateParams(type, profile, true));
[email protected]00509a32013-11-17 17:45:37130 chrome::AddTabAt(browser, GURL(), -1, true);
[email protected]bd817c22011-02-09 08:16:46131 return browser;
132}
[email protected]a1feae52010-10-11 22:14:45133
[email protected]d2202e22014-04-14 20:20:53134Browser* BrowserNavigatorTest::CreateEmptyBrowserForApp(Profile* profile) {
scottmg851949002016-02-09 20:09:44135 Browser* browser = new Browser(Browser::CreateParams::CreateForApp(
erg7b01d692017-02-22 21:57:35136 "Test", false /* trusted_source */, gfx::Rect(), profile, true));
[email protected]00509a32013-11-17 17:45:37137 chrome::AddTabAt(browser, GURL(), -1, true);
[email protected]b35b26b32011-05-05 20:35:14138 return browser;
139}
140
lof84501da082016-05-23 21:22:54141WebContents* BrowserNavigatorTest::CreateWebContents(bool initialize_renderer) {
[email protected]54944cde2012-12-09 09:24:59142 content::WebContents::CreateParams create_params(browser()->profile());
lof84501da082016-05-23 21:22:54143 create_params.initialize_renderer = initialize_renderer;
[email protected]ed245db2012-12-18 08:00:45144 content::WebContents* base_web_contents =
[email protected]ee496952013-01-10 23:17:33145 browser()->tab_strip_model()->GetActiveWebContents();
[email protected]ed245db2012-12-18 08:00:45146 if (base_web_contents) {
147 create_params.initial_size =
[email protected]fc2b46b2014-05-03 16:33:45148 base_web_contents->GetContainerBounds().size();
[email protected]ed245db2012-12-18 08:00:45149 }
[email protected]54944cde2012-12-09 09:24:59150 return WebContents::Create(create_params);
[email protected]bd817c22011-02-09 08:16:46151}
[email protected]a1feae52010-10-11 22:14:45152
[email protected]bd817c22011-02-09 08:16:46153void BrowserNavigatorTest::RunSuppressTest(WindowOpenDisposition disposition) {
[email protected]ee496952013-01-10 23:17:33154 GURL old_url = browser()->tab_strip_model()->GetActiveWebContents()->GetURL();
meacerc62e2ee2014-10-22 00:44:52155 chrome::NavigateParams params(MakeNavigateParams());
156 params.disposition = disposition;
157 chrome::Navigate(&params);
[email protected]a1feae52010-10-11 22:14:45158
[email protected]bd817c22011-02-09 08:16:46159 // Nothing should have happened as a result of Navigate();
[email protected]ee496952013-01-10 23:17:33160 EXPECT_EQ(1, browser()->tab_strip_model()->count());
[email protected]0665ebe2013-02-13 09:53:19161 EXPECT_EQ(1u, chrome::GetTotalBrowserCount());
[email protected]ee496952013-01-10 23:17:33162 EXPECT_EQ(old_url,
163 browser()->tab_strip_model()->GetActiveWebContents()->GetURL());
[email protected]bd817c22011-02-09 08:16:46164}
[email protected]bb89e7482010-11-17 18:27:04165
[email protected]fc0ed302011-11-29 23:17:19166void BrowserNavigatorTest::RunUseNonIncognitoWindowTest(const GURL& url) {
167 Browser* incognito_browser = CreateIncognitoBrowser();
168
[email protected]0665ebe2013-02-13 09:53:19169 EXPECT_EQ(2u, chrome::GetTotalBrowserCount());
[email protected]ee496952013-01-10 23:17:33170 EXPECT_EQ(1, browser()->tab_strip_model()->count());
171 EXPECT_EQ(1, incognito_browser->tab_strip_model()->count());
[email protected]fc0ed302011-11-29 23:17:19172
173 // Navigate to the page.
meacerc62e2ee2014-10-22 00:44:52174 chrome::NavigateParams params(MakeNavigateParams(incognito_browser));
nick3b04f322016-08-31 19:29:19175 params.disposition = WindowOpenDisposition::SINGLETON_TAB;
meacerc62e2ee2014-10-22 00:44:52176 params.url = url;
177 params.window_action = chrome::NavigateParams::SHOW_WINDOW;
178 chrome::Navigate(&params);
[email protected]fc0ed302011-11-29 23:17:19179
[email protected]50592b52013-05-02 22:26:25180 // This page should be opened in browser() window.
meacerc62e2ee2014-10-22 00:44:52181 EXPECT_NE(incognito_browser, params.browser);
182 EXPECT_EQ(browser(), params.browser);
[email protected]ee496952013-01-10 23:17:33183 EXPECT_EQ(2, browser()->tab_strip_model()->count());
184 EXPECT_EQ(url,
185 browser()->tab_strip_model()->GetActiveWebContents()->GetURL());
[email protected]fc0ed302011-11-29 23:17:19186}
187
188void BrowserNavigatorTest::RunDoNothingIfIncognitoIsForcedTest(
189 const GURL& url) {
190 Browser* browser = CreateIncognitoBrowser();
191
192 // Set kIncognitoModeAvailability to FORCED.
193 PrefService* prefs1 = browser->profile()->GetPrefs();
194 prefs1->SetInteger(prefs::kIncognitoModeAvailability,
195 IncognitoModePrefs::FORCED);
196 PrefService* prefs2 = browser->profile()->GetOriginalProfile()->GetPrefs();
197 prefs2->SetInteger(prefs::kIncognitoModeAvailability,
198 IncognitoModePrefs::FORCED);
199
200 // Navigate to the page.
meacerc62e2ee2014-10-22 00:44:52201 chrome::NavigateParams params(MakeNavigateParams(browser));
nick3b04f322016-08-31 19:29:19202 params.disposition = WindowOpenDisposition::OFF_THE_RECORD;
meacerc62e2ee2014-10-22 00:44:52203 params.url = url;
204 params.window_action = chrome::NavigateParams::SHOW_WINDOW;
205 chrome::Navigate(&params);
[email protected]fc0ed302011-11-29 23:17:19206
207 // The page should not be opened.
meacerc62e2ee2014-10-22 00:44:52208 EXPECT_EQ(browser, params.browser);
[email protected]ee496952013-01-10 23:17:33209 EXPECT_EQ(1, browser->tab_strip_model()->count());
[email protected]8e09c7af2014-06-10 11:46:17210 EXPECT_EQ(GURL(url::kAboutBlankURL),
[email protected]ee496952013-01-10 23:17:33211 browser->tab_strip_model()->GetActiveWebContents()->GetURL());
[email protected]fc0ed302011-11-29 23:17:19212}
213
[email protected]6c2381d2011-10-19 02:52:53214void BrowserNavigatorTest::Observe(
215 int type,
216 const content::NotificationSource& source,
217 const content::NotificationDetails& details) {
thestig1d619242016-06-13 22:24:52218 DCHECK_EQ(content::NOTIFICATION_WEB_CONTENTS_RENDER_VIEW_HOST_CREATED, type);
219 ++created_tab_contents_count_;
[email protected]bd817c22011-02-09 08:16:46220}
[email protected]fa7ebe02010-11-29 23:04:57221
[email protected]bd817c22011-02-09 08:16:46222namespace {
[email protected]a1feae52010-10-11 22:14:45223
[email protected]a1feae52010-10-11 22:14:45224// This test verifies that when a navigation occurs within a tab, the tab count
225// of the Browser remains the same and the current tab bears the loaded URL.
[email protected]59167c22013-06-03 18:07:32226// Note that network URLs are not actually loaded in tests, so this also tests
227// that error pages leave the intended URL in the address bar.
[email protected]a1feae52010-10-11 22:14:45228IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_CurrentTab) {
[email protected]ddddfda2011-07-14 23:19:39229 ui_test_utils::NavigateToURL(browser(), GetGoogleURL());
[email protected]ee496952013-01-10 23:17:33230 EXPECT_EQ(GetGoogleURL(),
231 browser()->tab_strip_model()->GetActiveWebContents()->GetURL());
[email protected]a1feae52010-10-11 22:14:45232 // We should have one window with one tab.
[email protected]0665ebe2013-02-13 09:53:19233 EXPECT_EQ(1u, chrome::GetTotalBrowserCount());
[email protected]ee496952013-01-10 23:17:33234 EXPECT_EQ(1, browser()->tab_strip_model()->count());
[email protected]a1feae52010-10-11 22:14:45235}
236
[email protected]bd817c22011-02-09 08:16:46237// This test verifies that a singleton tab is refocused if one is already opened
[email protected]19d9f3a2010-10-14 21:49:36238// in another or an existing window, or added if it is not.
239IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_SingletonTabExisting) {
[email protected]19d9f3a2010-10-14 21:49:36240 GURL singleton_url1("http://maps.google.com/");
[email protected]fa7ebe02010-11-29 23:04:57241
[email protected]e232c992012-12-06 12:43:20242 // Register for a notification if an additional WebContents was instantiated.
[email protected]bd817c22011-02-09 08:16:46243 // Opening a Singleton tab that is already opened should not be opening a new
[email protected]e232c992012-12-06 12:43:20244 // tab nor be creating a new WebContents object.
[email protected]6c2381d2011-10-19 02:52:53245 content::NotificationRegistrar registrar;
[email protected]fa7ebe02010-11-29 23:04:57246
247 // As the registrar object goes out of scope, this will get unregistered
[email protected]d53a08c2012-07-18 20:35:30248 registrar.Add(this,
249 content::NOTIFICATION_WEB_CONTENTS_RENDER_VIEW_HOST_CREATED,
[email protected]ad50def52011-10-19 23:17:07250 content::NotificationService::AllSources());
[email protected]fa7ebe02010-11-29 23:04:57251
[email protected]52877dbc62012-06-29 22:22:03252 chrome::AddSelectedTabWithURL(browser(), singleton_url1,
Sylvain Defresnec6ccc77d2014-09-19 10:19:35253 ui::PAGE_TRANSITION_LINK);
[email protected]52877dbc62012-06-29 22:22:03254 chrome::AddSelectedTabWithURL(browser(), GetGoogleURL(),
Sylvain Defresnec6ccc77d2014-09-19 10:19:35255 ui::PAGE_TRANSITION_LINK);
[email protected]19d9f3a2010-10-14 21:49:36256
257 // We should have one browser with 3 tabs, the 3rd selected.
[email protected]0665ebe2013-02-13 09:53:19258 EXPECT_EQ(1u, chrome::GetTotalBrowserCount());
[email protected]ee496952013-01-10 23:17:33259 EXPECT_EQ(2, browser()->tab_strip_model()->active_index());
[email protected]19d9f3a2010-10-14 21:49:36260
[email protected]fa7ebe02010-11-29 23:04:57261 unsigned int previous_tab_contents_count =
262 created_tab_contents_count_ = 0;
263
[email protected]19d9f3a2010-10-14 21:49:36264 // Navigate to singleton_url1.
meacerc62e2ee2014-10-22 00:44:52265 chrome::NavigateParams params(MakeNavigateParams());
nick3b04f322016-08-31 19:29:19266 params.disposition = WindowOpenDisposition::SINGLETON_TAB;
meacerc62e2ee2014-10-22 00:44:52267 params.url = singleton_url1;
268 chrome::Navigate(&params);
[email protected]19d9f3a2010-10-14 21:49:36269
270 // The middle tab should now be selected.
meacerc62e2ee2014-10-22 00:44:52271 EXPECT_EQ(browser(), params.browser);
[email protected]ee496952013-01-10 23:17:33272 EXPECT_EQ(1, browser()->tab_strip_model()->active_index());
[email protected]fa7ebe02010-11-29 23:04:57273
274 // No tab contents should have been created
275 EXPECT_EQ(previous_tab_contents_count,
276 created_tab_contents_count_);
[email protected]19d9f3a2010-10-14 21:49:36277}
278
279IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
[email protected]578c6962011-08-24 22:06:40280 Disposition_SingletonTabRespectingRef) {
281 GURL singleton_ref_url1("http://maps.google.com/#a");
282 GURL singleton_ref_url2("http://maps.google.com/#b");
283 GURL singleton_ref_url3("http://maps.google.com/");
284
[email protected]52877dbc62012-06-29 22:22:03285 chrome::AddSelectedTabWithURL(browser(), singleton_ref_url1,
Sylvain Defresnec6ccc77d2014-09-19 10:19:35286 ui::PAGE_TRANSITION_LINK);
[email protected]578c6962011-08-24 22:06:40287
288 // We should have one browser with 2 tabs, 2nd selected.
[email protected]0665ebe2013-02-13 09:53:19289 EXPECT_EQ(1u, chrome::GetTotalBrowserCount());
[email protected]ee496952013-01-10 23:17:33290 EXPECT_EQ(2, browser()->tab_strip_model()->count());
291 EXPECT_EQ(1, browser()->tab_strip_model()->active_index());
[email protected]578c6962011-08-24 22:06:40292
293 // Navigate to singleton_url2.
meacerc62e2ee2014-10-22 00:44:52294 chrome::NavigateParams params(MakeNavigateParams());
nick3b04f322016-08-31 19:29:19295 params.disposition = WindowOpenDisposition::SINGLETON_TAB;
meacerc62e2ee2014-10-22 00:44:52296 params.url = singleton_ref_url2;
297 chrome::Navigate(&params);
[email protected]578c6962011-08-24 22:06:40298
299 // We should now have 2 tabs, the 2nd one selected.
meacerc62e2ee2014-10-22 00:44:52300 EXPECT_EQ(browser(), params.browser);
[email protected]ee496952013-01-10 23:17:33301 EXPECT_EQ(2, browser()->tab_strip_model()->count());
302 EXPECT_EQ(1, browser()->tab_strip_model()->active_index());
[email protected]578c6962011-08-24 22:06:40303
304 // Navigate to singleton_url2, but with respect ref set.
meacerc62e2ee2014-10-22 00:44:52305 params = MakeNavigateParams();
nick3b04f322016-08-31 19:29:19306 params.disposition = WindowOpenDisposition::SINGLETON_TAB;
meacerc62e2ee2014-10-22 00:44:52307 params.url = singleton_ref_url2;
308 params.ref_behavior = chrome::NavigateParams::RESPECT_REF;
309 chrome::Navigate(&params);
[email protected]578c6962011-08-24 22:06:40310
311 // We should now have 3 tabs, the 3th one selected.
meacerc62e2ee2014-10-22 00:44:52312 EXPECT_EQ(browser(), params.browser);
[email protected]ee496952013-01-10 23:17:33313 EXPECT_EQ(3, browser()->tab_strip_model()->count());
314 EXPECT_EQ(2, browser()->tab_strip_model()->active_index());
[email protected]578c6962011-08-24 22:06:40315
316 // Navigate to singleton_url3.
meacerc62e2ee2014-10-22 00:44:52317 params = MakeNavigateParams();
nick3b04f322016-08-31 19:29:19318 params.disposition = WindowOpenDisposition::SINGLETON_TAB;
meacerc62e2ee2014-10-22 00:44:52319 params.url = singleton_ref_url3;
320 params.ref_behavior = chrome::NavigateParams::RESPECT_REF;
321 chrome::Navigate(&params);
[email protected]578c6962011-08-24 22:06:40322
323 // We should now have 4 tabs, the 4th one selected.
meacerc62e2ee2014-10-22 00:44:52324 EXPECT_EQ(browser(), params.browser);
[email protected]ee496952013-01-10 23:17:33325 EXPECT_EQ(4, browser()->tab_strip_model()->count());
326 EXPECT_EQ(3, browser()->tab_strip_model()->active_index());
[email protected]578c6962011-08-24 22:06:40327}
328
329IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
[email protected]19d9f3a2010-10-14 21:49:36330 Disposition_SingletonTabNoneExisting) {
[email protected]19d9f3a2010-10-14 21:49:36331 GURL singleton_url1("http://maps.google.com/");
332
[email protected]bd817c22011-02-09 08:16:46333 // We should have one browser with 1 tab.
[email protected]0665ebe2013-02-13 09:53:19334 EXPECT_EQ(1u, chrome::GetTotalBrowserCount());
[email protected]ee496952013-01-10 23:17:33335 EXPECT_EQ(0, browser()->tab_strip_model()->active_index());
[email protected]19d9f3a2010-10-14 21:49:36336
337 // Navigate to singleton_url1.
meacerc62e2ee2014-10-22 00:44:52338 chrome::NavigateParams params(MakeNavigateParams());
nick3b04f322016-08-31 19:29:19339 params.disposition = WindowOpenDisposition::SINGLETON_TAB;
meacerc62e2ee2014-10-22 00:44:52340 params.url = singleton_url1;
341 chrome::Navigate(&params);
[email protected]19d9f3a2010-10-14 21:49:36342
343 // We should now have 2 tabs, the 2nd one selected.
meacerc62e2ee2014-10-22 00:44:52344 EXPECT_EQ(browser(), params.browser);
[email protected]ee496952013-01-10 23:17:33345 EXPECT_EQ(2, browser()->tab_strip_model()->count());
346 EXPECT_EQ(1, browser()->tab_strip_model()->active_index());
[email protected]a1feae52010-10-11 22:14:45347}
348
349// This test verifies that when a navigation results in a foreground tab, the
350// tab count of the Browser increases and the selected tab shifts to the new
351// foreground tab.
352IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_NewForegroundTab) {
[email protected]ee496952013-01-10 23:17:33353 WebContents* old_contents =
354 browser()->tab_strip_model()->GetActiveWebContents();
meacerc62e2ee2014-10-22 00:44:52355 chrome::NavigateParams params(MakeNavigateParams());
nick3b04f322016-08-31 19:29:19356 params.disposition = WindowOpenDisposition::NEW_FOREGROUND_TAB;
meacerc62e2ee2014-10-22 00:44:52357 chrome::Navigate(&params);
[email protected]ee496952013-01-10 23:17:33358 EXPECT_NE(old_contents,
359 browser()->tab_strip_model()->GetActiveWebContents());
[email protected]e232c992012-12-06 12:43:20360 EXPECT_EQ(browser()->tab_strip_model()->GetActiveWebContents(),
meacerc62e2ee2014-10-22 00:44:52361 params.target_contents);
[email protected]ee496952013-01-10 23:17:33362 EXPECT_EQ(2, browser()->tab_strip_model()->count());
[email protected]a1feae52010-10-11 22:14:45363}
364
365// This test verifies that when a navigation results in a background tab, the
366// tab count of the Browser increases but the selected tab remains the same.
367IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_NewBackgroundTab) {
[email protected]ee496952013-01-10 23:17:33368 WebContents* old_contents =
369 browser()->tab_strip_model()->GetActiveWebContents();
meacerc62e2ee2014-10-22 00:44:52370 chrome::NavigateParams params(MakeNavigateParams());
nick3b04f322016-08-31 19:29:19371 params.disposition = WindowOpenDisposition::NEW_BACKGROUND_TAB;
meacerc62e2ee2014-10-22 00:44:52372 chrome::Navigate(&params);
[email protected]ee496952013-01-10 23:17:33373 WebContents* new_contents =
374 browser()->tab_strip_model()->GetActiveWebContents();
[email protected]a1feae52010-10-11 22:14:45375 // The selected tab should have remained unchanged, since the new tab was
376 // opened in the background.
377 EXPECT_EQ(old_contents, new_contents);
[email protected]ee496952013-01-10 23:17:33378 EXPECT_EQ(2, browser()->tab_strip_model()->count());
[email protected]a1feae52010-10-11 22:14:45379}
380
381// This test verifies that when a navigation requiring a new foreground tab
382// occurs in a Browser that cannot host multiple tabs, the new foreground tab
383// is created in an existing compatible Browser.
384IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
385 Disposition_IncompatibleWindow_Existing) {
386 // Open a foreground tab in a window that cannot open popups when there is an
387 // existing compatible window somewhere else that they can be opened within.
388 Browser* popup = CreateEmptyBrowserForType(Browser::TYPE_POPUP,
389 browser()->profile());
meacerc62e2ee2014-10-22 00:44:52390 chrome::NavigateParams params(MakeNavigateParams(popup));
nick3b04f322016-08-31 19:29:19391 params.disposition = WindowOpenDisposition::NEW_FOREGROUND_TAB;
meacerc62e2ee2014-10-22 00:44:52392 chrome::Navigate(&params);
[email protected]a1feae52010-10-11 22:14:45393
394 // Navigate() should have opened the tab in a different browser since the
395 // one we supplied didn't support additional tabs.
meacerc62e2ee2014-10-22 00:44:52396 EXPECT_NE(popup, params.browser);
[email protected]a1feae52010-10-11 22:14:45397
398 // Since browser() is an existing compatible tabbed browser, it should have
399 // opened the tab there.
meacerc62e2ee2014-10-22 00:44:52400 EXPECT_EQ(browser(), params.browser);
[email protected]a1feae52010-10-11 22:14:45401
402 // We should be left with 2 windows, the popup with one tab and the browser()
403 // provided by the framework with two.
[email protected]0665ebe2013-02-13 09:53:19404 EXPECT_EQ(2u, chrome::GetTotalBrowserCount());
[email protected]ee496952013-01-10 23:17:33405 EXPECT_EQ(1, popup->tab_strip_model()->count());
406 EXPECT_EQ(2, browser()->tab_strip_model()->count());
[email protected]a1feae52010-10-11 22:14:45407}
408
409// This test verifies that when a navigation requiring a new foreground tab
410// occurs in a Browser that cannot host multiple tabs and no compatible Browser
411// that can is open, a compatible Browser is created.
412IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
413 Disposition_IncompatibleWindow_NoExisting) {
414 // We want to simulate not being able to find an existing window compatible
415 // with our non-tabbed browser window so Navigate() is forced to create a
416 // new compatible window. Because browser() supplied by the in-process
417 // browser testing framework is compatible with browser()->profile(), we
418 // need a different profile, and creating a popup window with an incognito
419 // profile is a quick and dirty way of achieving this.
420 Browser* popup = CreateEmptyBrowserForType(
[email protected]b35b26b32011-05-05 20:35:14421 Browser::TYPE_POPUP,
422 browser()->profile()->GetOffTheRecordProfile());
meacerc62e2ee2014-10-22 00:44:52423 chrome::NavigateParams params(MakeNavigateParams(popup));
nick3b04f322016-08-31 19:29:19424 params.disposition = WindowOpenDisposition::NEW_FOREGROUND_TAB;
meacerc62e2ee2014-10-22 00:44:52425 chrome::Navigate(&params);
[email protected]a1feae52010-10-11 22:14:45426
427 // Navigate() should have opened the tab in a different browser since the
428 // one we supplied didn't support additional tabs.
meacerc62e2ee2014-10-22 00:44:52429 EXPECT_NE(popup, params.browser);
[email protected]a1feae52010-10-11 22:14:45430
431 // This time, browser() is _not_ compatible with popup since it is not an
432 // incognito window.
meacerc62e2ee2014-10-22 00:44:52433 EXPECT_NE(browser(), params.browser);
[email protected]a1feae52010-10-11 22:14:45434
435 // We should have three windows, each with one tab:
436 // 1. the browser() provided by the framework (unchanged in this test)
437 // 2. the incognito popup we created originally
438 // 3. the new incognito tabbed browser that was created by Navigate().
[email protected]0665ebe2013-02-13 09:53:19439 EXPECT_EQ(3u, chrome::GetTotalBrowserCount());
[email protected]ee496952013-01-10 23:17:33440 EXPECT_EQ(1, browser()->tab_strip_model()->count());
441 EXPECT_EQ(1, popup->tab_strip_model()->count());
meacerc62e2ee2014-10-22 00:44:52442 EXPECT_EQ(1, params.browser->tab_strip_model()->count());
443 EXPECT_TRUE(params.browser->is_type_tabbed());
[email protected]a1feae52010-10-11 22:14:45444}
445
446// This test verifies that navigating with WindowOpenDisposition = NEW_POPUP
447// from a normal Browser results in a new Browser with TYPE_POPUP.
448IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_NewPopup) {
meacerc62e2ee2014-10-22 00:44:52449 chrome::NavigateParams params(MakeNavigateParams());
nick3b04f322016-08-31 19:29:19450 params.disposition = WindowOpenDisposition::NEW_POPUP;
meacerc62e2ee2014-10-22 00:44:52451 params.window_bounds = gfx::Rect(0, 0, 200, 200);
[email protected]7d329992011-04-15 18:20:02452 // Wait for new popup to to load and gain focus.
meacerc62e2ee2014-10-22 00:44:52453 ui_test_utils::NavigateToURL(&params);
[email protected]a1feae52010-10-11 22:14:45454
[email protected]7d329992011-04-15 18:20:02455 // Navigate() should have opened a new, focused popup window.
meacerc62e2ee2014-10-22 00:44:52456 EXPECT_NE(browser(), params.browser);
[email protected]50592b52013-05-02 22:26:25457#if 0
458 // TODO(stevenjb): Enable this test. See: crbug.com/79493
meacerc62e2ee2014-10-22 00:44:52459 EXPECT_TRUE(browser->window()->IsActive());
[email protected]50592b52013-05-02 22:26:25460#endif
meacerc62e2ee2014-10-22 00:44:52461 EXPECT_TRUE(params.browser->is_type_popup());
462 EXPECT_FALSE(params.browser->is_app());
[email protected]a1feae52010-10-11 22:14:45463
464 // We should have two windows, the browser() provided by the framework and the
465 // new popup window.
[email protected]0665ebe2013-02-13 09:53:19466 EXPECT_EQ(2u, chrome::GetTotalBrowserCount());
[email protected]ee496952013-01-10 23:17:33467 EXPECT_EQ(1, browser()->tab_strip_model()->count());
meacerc62e2ee2014-10-22 00:44:52468 EXPECT_EQ(1, params.browser->tab_strip_model()->count());
[email protected]a1feae52010-10-11 22:14:45469}
470
471// This test verifies that navigating with WindowOpenDisposition = NEW_POPUP
[email protected]f112b0f2011-05-26 01:53:52472// from a normal Browser results in a new Browser with is_app() true.
473IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_NewPopup_ExtensionId) {
meacerc62e2ee2014-10-22 00:44:52474 chrome::NavigateParams params(MakeNavigateParams());
nick3b04f322016-08-31 19:29:19475 params.disposition = WindowOpenDisposition::NEW_POPUP;
meacerc62e2ee2014-10-22 00:44:52476 params.extension_app_id = "extensionappid";
477 params.window_bounds = gfx::Rect(0, 0, 200, 200);
[email protected]f112b0f2011-05-26 01:53:52478 // Wait for new popup to to load and gain focus.
meacerc62e2ee2014-10-22 00:44:52479 ui_test_utils::NavigateToURL(&params);
[email protected]f112b0f2011-05-26 01:53:52480
481 // Navigate() should have opened a new, focused popup window.
meacerc62e2ee2014-10-22 00:44:52482 EXPECT_NE(browser(), params.browser);
483 EXPECT_TRUE(params.browser->is_type_popup());
484 EXPECT_TRUE(params.browser->is_app());
[email protected]f112b0f2011-05-26 01:53:52485
486 // We should have two windows, the browser() provided by the framework and the
487 // new popup window.
[email protected]0665ebe2013-02-13 09:53:19488 EXPECT_EQ(2u, chrome::GetTotalBrowserCount());
[email protected]ee496952013-01-10 23:17:33489 EXPECT_EQ(1, browser()->tab_strip_model()->count());
meacerc62e2ee2014-10-22 00:44:52490 EXPECT_EQ(1, params.browser->tab_strip_model()->count());
[email protected]f112b0f2011-05-26 01:53:52491}
492
493// This test verifies that navigating with WindowOpenDisposition = NEW_POPUP
[email protected]300d1e52011-01-19 23:57:57494// from a normal popup results in a new Browser with TYPE_POPUP.
495IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_NewPopupFromPopup) {
496 // Open a popup.
meacerc62e2ee2014-10-22 00:44:52497 chrome::NavigateParams params1(MakeNavigateParams());
nick3b04f322016-08-31 19:29:19498 params1.disposition = WindowOpenDisposition::NEW_POPUP;
meacerc62e2ee2014-10-22 00:44:52499 params1.window_bounds = gfx::Rect(0, 0, 200, 200);
500 chrome::Navigate(&params1);
[email protected]300d1e52011-01-19 23:57:57501 // Open another popup.
meacerc62e2ee2014-10-22 00:44:52502 chrome::NavigateParams params2(MakeNavigateParams(params1.browser));
nick3b04f322016-08-31 19:29:19503 params2.disposition = WindowOpenDisposition::NEW_POPUP;
meacerc62e2ee2014-10-22 00:44:52504 params2.window_bounds = gfx::Rect(0, 0, 200, 200);
505 chrome::Navigate(&params2);
[email protected]300d1e52011-01-19 23:57:57506
507 // Navigate() should have opened a new normal popup window.
meacerc62e2ee2014-10-22 00:44:52508 EXPECT_NE(params1.browser, params2.browser);
509 EXPECT_TRUE(params2.browser->is_type_popup());
510 EXPECT_FALSE(params2.browser->is_app());
[email protected]300d1e52011-01-19 23:57:57511
512 // We should have three windows, the browser() provided by the framework,
513 // the first popup window, and the second popup window.
[email protected]0665ebe2013-02-13 09:53:19514 EXPECT_EQ(3u, chrome::GetTotalBrowserCount());
[email protected]ee496952013-01-10 23:17:33515 EXPECT_EQ(1, browser()->tab_strip_model()->count());
meacerc62e2ee2014-10-22 00:44:52516 EXPECT_EQ(1, params1.browser->tab_strip_model()->count());
517 EXPECT_EQ(1, params2.browser->tab_strip_model()->count());
[email protected]300d1e52011-01-19 23:57:57518}
519
520// This test verifies that navigating with WindowOpenDisposition = NEW_POPUP
[email protected]d2202e22014-04-14 20:20:53521// from an app frame results in a new Browser with TYPE_POPUP.
[email protected]a1feae52010-10-11 22:14:45522IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
523 Disposition_NewPopupFromAppWindow) {
[email protected]d2202e22014-04-14 20:20:53524 Browser* app_browser = CreateEmptyBrowserForApp(browser()->profile());
meacerc62e2ee2014-10-22 00:44:52525 chrome::NavigateParams params(MakeNavigateParams(app_browser));
nick3b04f322016-08-31 19:29:19526 params.disposition = WindowOpenDisposition::NEW_POPUP;
meacerc62e2ee2014-10-22 00:44:52527 params.window_bounds = gfx::Rect(0, 0, 200, 200);
528 chrome::Navigate(&params);
[email protected]a1feae52010-10-11 22:14:45529
530 // Navigate() should have opened a new popup app window.
meacerc62e2ee2014-10-22 00:44:52531 EXPECT_NE(app_browser, params.browser);
532 EXPECT_NE(browser(), params.browser);
533 EXPECT_TRUE(params.browser->is_type_popup());
534 EXPECT_TRUE(params.browser->is_app());
[email protected]a1feae52010-10-11 22:14:45535
536 // We should now have three windows, the app window, the app popup it created,
537 // and the original browser() provided by the framework.
[email protected]0665ebe2013-02-13 09:53:19538 EXPECT_EQ(3u, chrome::GetTotalBrowserCount());
[email protected]ee496952013-01-10 23:17:33539 EXPECT_EQ(1, browser()->tab_strip_model()->count());
540 EXPECT_EQ(1, app_browser->tab_strip_model()->count());
meacerc62e2ee2014-10-22 00:44:52541 EXPECT_EQ(1, params.browser->tab_strip_model()->count());
[email protected]a1feae52010-10-11 22:14:45542}
543
544// This test verifies that navigating with WindowOpenDisposition = NEW_POPUP
[email protected]d2202e22014-04-14 20:20:53545// from an app popup results in a new Browser also of TYPE_POPUP.
[email protected]300d1e52011-01-19 23:57:57546IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
547 Disposition_NewPopupFromAppPopup) {
[email protected]d2202e22014-04-14 20:20:53548 Browser* app_browser = CreateEmptyBrowserForApp(browser()->profile());
[email protected]300d1e52011-01-19 23:57:57549 // Open an app popup.
meacerc62e2ee2014-10-22 00:44:52550 chrome::NavigateParams params1(MakeNavigateParams(app_browser));
nick3b04f322016-08-31 19:29:19551 params1.disposition = WindowOpenDisposition::NEW_POPUP;
meacerc62e2ee2014-10-22 00:44:52552 params1.window_bounds = gfx::Rect(0, 0, 200, 200);
553 chrome::Navigate(&params1);
[email protected]300d1e52011-01-19 23:57:57554 // Now open another app popup.
meacerc62e2ee2014-10-22 00:44:52555 chrome::NavigateParams params2(MakeNavigateParams(params1.browser));
nick3b04f322016-08-31 19:29:19556 params2.disposition = WindowOpenDisposition::NEW_POPUP;
meacerc62e2ee2014-10-22 00:44:52557 params2.window_bounds = gfx::Rect(0, 0, 200, 200);
558 chrome::Navigate(&params2);
[email protected]300d1e52011-01-19 23:57:57559
560 // Navigate() should have opened a new popup app window.
meacerc62e2ee2014-10-22 00:44:52561 EXPECT_NE(browser(), params1.browser);
562 EXPECT_NE(params1.browser, params2.browser);
563 EXPECT_TRUE(params2.browser->is_type_popup());
564 EXPECT_TRUE(params2.browser->is_app());
[email protected]300d1e52011-01-19 23:57:57565
566 // We should now have four windows, the app window, the first app popup,
567 // the second app popup, and the original browser() provided by the framework.
[email protected]0665ebe2013-02-13 09:53:19568 EXPECT_EQ(4u, chrome::GetTotalBrowserCount());
[email protected]ee496952013-01-10 23:17:33569 EXPECT_EQ(1, browser()->tab_strip_model()->count());
570 EXPECT_EQ(1, app_browser->tab_strip_model()->count());
meacerc62e2ee2014-10-22 00:44:52571 EXPECT_EQ(1, params1.browser->tab_strip_model()->count());
572 EXPECT_EQ(1, params2.browser->tab_strip_model()->count());
[email protected]300d1e52011-01-19 23:57:57573}
574
575// This test verifies that navigating with WindowOpenDisposition = NEW_POPUP
[email protected]a1feae52010-10-11 22:14:45576// from an extension app tab results in a new Browser with TYPE_APP_POPUP.
577IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
578 Disposition_NewPopupFromExtensionApp) {
579 // TODO(beng): TBD.
580}
581
[email protected]7d329992011-04-15 18:20:02582// This test verifies that navigating with window_action = SHOW_WINDOW_INACTIVE
583// does not focus a new new popup window.
584IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_NewPopupUnfocused) {
meacerc62e2ee2014-10-22 00:44:52585 chrome::NavigateParams params(MakeNavigateParams());
nick3b04f322016-08-31 19:29:19586 params.disposition = WindowOpenDisposition::NEW_POPUP;
meacerc62e2ee2014-10-22 00:44:52587 params.window_bounds = gfx::Rect(0, 0, 200, 200);
588 params.window_action = chrome::NavigateParams::SHOW_WINDOW_INACTIVE;
[email protected]7d329992011-04-15 18:20:02589 // Wait for new popup to load (and gain focus if the test fails).
meacerc62e2ee2014-10-22 00:44:52590 ui_test_utils::NavigateToURL(&params);
[email protected]7d329992011-04-15 18:20:02591
592 // Navigate() should have opened a new, unfocused, popup window.
meacerc62e2ee2014-10-22 00:44:52593 EXPECT_NE(browser(), params.browser);
594 EXPECT_EQ(Browser::TYPE_POPUP, params.browser->type());
[email protected]9db263a2011-04-15 20:53:47595#if 0
596// TODO(stevenjb): Enable this test. See: crbug.com/79493
[email protected]7d329992011-04-15 18:20:02597 EXPECT_FALSE(p.browser->window()->IsActive());
[email protected]7d329992011-04-15 18:20:02598#endif
[email protected]9db263a2011-04-15 20:53:47599}
[email protected]7d329992011-04-15 18:20:02600
[email protected]d2202e22014-04-14 20:20:53601// This test verifies that navigating with WindowOpenDisposition = NEW_POPUP
602// and trusted_source = true results in a new Browser where is_trusted_source()
603// is true.
604IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_NewPopupTrusted) {
meacerc62e2ee2014-10-22 00:44:52605 chrome::NavigateParams params(MakeNavigateParams());
nick3b04f322016-08-31 19:29:19606 params.disposition = WindowOpenDisposition::NEW_POPUP;
meacerc62e2ee2014-10-22 00:44:52607 params.trusted_source = true;
608 params.window_bounds = gfx::Rect(0, 0, 200, 200);
[email protected]d2202e22014-04-14 20:20:53609 // Wait for new popup to to load and gain focus.
meacerc62e2ee2014-10-22 00:44:52610 ui_test_utils::NavigateToURL(&params);
[email protected]d2202e22014-04-14 20:20:53611
612 // Navigate() should have opened a new popup window of TYPE_TRUSTED_POPUP.
meacerc62e2ee2014-10-22 00:44:52613 EXPECT_NE(browser(), params.browser);
614 EXPECT_TRUE(params.browser->is_type_popup());
615 EXPECT_TRUE(params.browser->is_trusted_source());
[email protected]d2202e22014-04-14 20:20:53616}
617
618
[email protected]a1feae52010-10-11 22:14:45619// This test verifies that navigating with WindowOpenDisposition = NEW_WINDOW
620// always opens a new window.
621IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_NewWindow) {
meacerc62e2ee2014-10-22 00:44:52622 chrome::NavigateParams params(MakeNavigateParams());
nick3b04f322016-08-31 19:29:19623 params.disposition = WindowOpenDisposition::NEW_WINDOW;
meacerc62e2ee2014-10-22 00:44:52624 chrome::Navigate(&params);
[email protected]a1feae52010-10-11 22:14:45625
626 // Navigate() should have opened a new toplevel window.
meacerc62e2ee2014-10-22 00:44:52627 EXPECT_NE(browser(), params.browser);
628 EXPECT_TRUE(params.browser->is_type_tabbed());
[email protected]a1feae52010-10-11 22:14:45629
630 // We should now have two windows, the browser() provided by the framework and
631 // the new normal window.
[email protected]0665ebe2013-02-13 09:53:19632 EXPECT_EQ(2u, chrome::GetTotalBrowserCount());
[email protected]ee496952013-01-10 23:17:33633 EXPECT_EQ(1, browser()->tab_strip_model()->count());
meacerc62e2ee2014-10-22 00:44:52634 EXPECT_EQ(1, params.browser->tab_strip_model()->count());
[email protected]a1feae52010-10-11 22:14:45635}
636
guidou5732a1e2016-12-15 17:03:14637#if defined(OS_MACOSX) && defined(ADDRESS_SANITIZER)
638// Flaky on ASAN on Mac. See https://crbug.com/674497.
639#define MAYBE_Disposition_Incognito DISABLED_Disposition_Incognito
640#else
641#define MAYBE_Disposition_Incognito Disposition_Incognito
642#endif
[email protected]a1feae52010-10-11 22:14:45643// This test verifies that navigating with WindowOpenDisposition = INCOGNITO
644// opens a new incognito window if no existing incognito window is present.
guidou5732a1e2016-12-15 17:03:14645IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, MAYBE_Disposition_Incognito) {
meacerc62e2ee2014-10-22 00:44:52646 chrome::NavigateParams params(MakeNavigateParams());
nick3b04f322016-08-31 19:29:19647 params.disposition = WindowOpenDisposition::OFF_THE_RECORD;
meacerc62e2ee2014-10-22 00:44:52648 chrome::Navigate(&params);
[email protected]a1feae52010-10-11 22:14:45649
650 // Navigate() should have opened a new toplevel incognito window.
meacerc62e2ee2014-10-22 00:44:52651 EXPECT_NE(browser(), params.browser);
[email protected]a1feae52010-10-11 22:14:45652 EXPECT_EQ(browser()->profile()->GetOffTheRecordProfile(),
meacerc62e2ee2014-10-22 00:44:52653 params.browser->profile());
[email protected]a1feae52010-10-11 22:14:45654
[email protected]d7ff3592010-11-30 21:50:46655 // |source_contents| should be set to NULL because the profile for the new
656 // page is different from the originating page.
meacerc62e2ee2014-10-22 00:44:52657 EXPECT_EQ(NULL, params.source_contents);
[email protected]d7ff3592010-11-30 21:50:46658
[email protected]a1feae52010-10-11 22:14:45659 // We should now have two windows, the browser() provided by the framework and
660 // the new incognito window.
[email protected]0665ebe2013-02-13 09:53:19661 EXPECT_EQ(2u, chrome::GetTotalBrowserCount());
[email protected]ee496952013-01-10 23:17:33662 EXPECT_EQ(1, browser()->tab_strip_model()->count());
meacerc62e2ee2014-10-22 00:44:52663 EXPECT_EQ(1, params.browser->tab_strip_model()->count());
[email protected]a1feae52010-10-11 22:14:45664}
665
666// This test verifies that navigating with WindowOpenDisposition = INCOGNITO
667// reuses an existing incognito window when possible.
668IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_IncognitoRefocus) {
669 Browser* incognito_browser =
[email protected]b35b26b32011-05-05 20:35:14670 CreateEmptyBrowserForType(Browser::TYPE_TABBED,
[email protected]a1feae52010-10-11 22:14:45671 browser()->profile()->GetOffTheRecordProfile());
meacerc62e2ee2014-10-22 00:44:52672 chrome::NavigateParams params(MakeNavigateParams());
nick3b04f322016-08-31 19:29:19673 params.disposition = WindowOpenDisposition::OFF_THE_RECORD;
meacerc62e2ee2014-10-22 00:44:52674 chrome::Navigate(&params);
[email protected]a1feae52010-10-11 22:14:45675
676 // Navigate() should have opened a new tab in the existing incognito window.
meacerc62e2ee2014-10-22 00:44:52677 EXPECT_NE(browser(), params.browser);
678 EXPECT_EQ(params.browser, incognito_browser);
[email protected]a1feae52010-10-11 22:14:45679
680 // We should now have two windows, the browser() provided by the framework and
681 // the incognito window we opened earlier.
[email protected]0665ebe2013-02-13 09:53:19682 EXPECT_EQ(2u, chrome::GetTotalBrowserCount());
[email protected]ee496952013-01-10 23:17:33683 EXPECT_EQ(1, browser()->tab_strip_model()->count());
684 EXPECT_EQ(2, incognito_browser->tab_strip_model()->count());
[email protected]a1feae52010-10-11 22:14:45685}
686
687// This test verifies that no navigation action occurs when
[email protected]a1feae52010-10-11 22:14:45688// WindowOpenDisposition = SAVE_TO_DISK.
689IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_SaveToDisk) {
nick3b04f322016-08-31 19:29:19690 RunSuppressTest(WindowOpenDisposition::SAVE_TO_DISK);
[email protected]a1feae52010-10-11 22:14:45691}
692
693// This test verifies that no navigation action occurs when
694// WindowOpenDisposition = IGNORE_ACTION.
695IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_IgnoreAction) {
nick3b04f322016-08-31 19:29:19696 RunSuppressTest(WindowOpenDisposition::IGNORE_ACTION);
[email protected]a1feae52010-10-11 22:14:45697}
698
[email protected]e232c992012-12-06 12:43:20699// This tests adding a foreground tab with a predefined WebContents.
[email protected]a1feae52010-10-11 22:14:45700IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, TargetContents_ForegroundTab) {
meacerc62e2ee2014-10-22 00:44:52701 chrome::NavigateParams params(MakeNavigateParams());
nick3b04f322016-08-31 19:29:19702 params.disposition = WindowOpenDisposition::NEW_FOREGROUND_TAB;
lof84501da082016-05-23 21:22:54703 params.target_contents = CreateWebContents(false);
meacerc62e2ee2014-10-22 00:44:52704 chrome::Navigate(&params);
[email protected]a1feae52010-10-11 22:14:45705
lof84501da082016-05-23 21:22:54706 // Navigate() should have opened the contents in a new foreground tab in the
[email protected]a1feae52010-10-11 22:14:45707 // current Browser.
meacerc62e2ee2014-10-22 00:44:52708 EXPECT_EQ(browser(), params.browser);
[email protected]e232c992012-12-06 12:43:20709 EXPECT_EQ(browser()->tab_strip_model()->GetActiveWebContents(),
meacerc62e2ee2014-10-22 00:44:52710 params.target_contents);
[email protected]a1feae52010-10-11 22:14:45711
712 // We should have one window, with two tabs.
[email protected]0665ebe2013-02-13 09:53:19713 EXPECT_EQ(1u, chrome::GetTotalBrowserCount());
[email protected]ee496952013-01-10 23:17:33714 EXPECT_EQ(2, browser()->tab_strip_model()->count());
[email protected]a1feae52010-10-11 22:14:45715}
716
717#if defined(OS_WIN)
[email protected]e232c992012-12-06 12:43:20718// This tests adding a popup with a predefined WebContents.
[email protected]76edb672011-03-04 21:48:39719IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, DISABLED_TargetContents_Popup) {
meacerc62e2ee2014-10-22 00:44:52720 chrome::NavigateParams params(MakeNavigateParams());
nick3b04f322016-08-31 19:29:19721 params.disposition = WindowOpenDisposition::NEW_POPUP;
lof84501da082016-05-23 21:22:54722 params.target_contents = CreateWebContents(false);
meacerc62e2ee2014-10-22 00:44:52723 params.window_bounds = gfx::Rect(10, 10, 500, 500);
724 chrome::Navigate(&params);
[email protected]a1feae52010-10-11 22:14:45725
726 // Navigate() should have opened a new popup window.
meacerc62e2ee2014-10-22 00:44:52727 EXPECT_NE(browser(), params.browser);
728 EXPECT_TRUE(params.browser->is_type_popup());
729 EXPECT_FALSE(params.browser->is_app());
[email protected]a1feae52010-10-11 22:14:45730
731 // The web platform is weird. The window bounds specified in
meacerc62e2ee2014-10-22 00:44:52732 // |params.window_bounds| are used as follows:
[email protected]a1feae52010-10-11 22:14:45733 // - the origin is used to position the window
[email protected]e232c992012-12-06 12:43:20734 // - the size is used to size the WebContents of the window.
[email protected]a1feae52010-10-11 22:14:45735 // As such the position of the resulting window will always match
meacerc62e2ee2014-10-22 00:44:52736 // params.window_bounds.origin(), but its size will not. We need to match
[email protected]a1feae52010-10-11 22:14:45737 // the size against the selected tab's view's container size.
meacerc62e2ee2014-10-22 00:44:52738 // Only Windows positions the window according to
739 // |params.window_bounds.origin()| - on Mac the window is offset from the
740 // opener and on Linux it always opens at 0,0.
741 EXPECT_EQ(params.window_bounds.origin(),
742 params.browser->window()->GetRestoredBounds().origin());
[email protected]a1feae52010-10-11 22:14:45743 // All platforms should respect size however provided width > 400 (Mac has a
744 // minimum window width of 400).
meacerc62e2ee2014-10-22 00:44:52745 EXPECT_EQ(params.window_bounds.size(),
746 params.target_contents->GetContainerBounds().size());
[email protected]a1feae52010-10-11 22:14:45747
748 // We should have two windows, the new popup and the browser() provided by the
749 // framework.
[email protected]0665ebe2013-02-13 09:53:19750 EXPECT_EQ(2u, chrome::GetTotalBrowserCount());
[email protected]ee496952013-01-10 23:17:33751 EXPECT_EQ(1, browser()->tab_strip_model()->count());
meacerc62e2ee2014-10-22 00:44:52752 EXPECT_EQ(1, params.browser->tab_strip_model()->count());
[email protected]a1feae52010-10-11 22:14:45753}
754#endif
755
lof84501da082016-05-23 21:22:54756// This test checks that we can create WebContents with renderer process and
757// RenderFrame without navigating it.
758IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
759 CreateWebContentsWithRendererProcess) {
760 chrome::NavigateParams params(MakeNavigateParams());
nick3b04f322016-08-31 19:29:19761 params.disposition = WindowOpenDisposition::NEW_FOREGROUND_TAB;
lof84501da082016-05-23 21:22:54762 params.target_contents = CreateWebContents(true);
763 ASSERT_TRUE(params.target_contents);
764
765 // There is no navigation (to about:blank or something like that).
766 EXPECT_FALSE(params.target_contents->IsLoading());
767
768 ASSERT_TRUE(params.target_contents->GetMainFrame());
769 EXPECT_TRUE(params.target_contents->GetMainFrame()->IsRenderFrameLive());
770 EXPECT_TRUE(
771 params.target_contents->GetController().IsInitialBlankNavigation());
Lukasz Anforowicz2ff2d152017-09-28 15:59:51772 int renderer_id =
773 params.target_contents->GetMainFrame()->GetProcess()->GetID();
lof84501da082016-05-23 21:22:54774
775 // We should have one window, with one tab of WebContents differ from
776 // params.target_contents.
777 EXPECT_EQ(1u, chrome::GetTotalBrowserCount());
778 EXPECT_EQ(1, browser()->tab_strip_model()->count());
779 EXPECT_NE(browser()->tab_strip_model()->GetActiveWebContents(),
780 params.target_contents);
781
782 chrome::Navigate(&params);
783
784 // Navigate() should have opened the contents in a new foreground tab in the
785 // current Browser, without changing the renderer process of target_contents.
786 EXPECT_EQ(browser(), params.browser);
787 EXPECT_EQ(browser()->tab_strip_model()->GetActiveWebContents(),
788 params.target_contents);
789 EXPECT_EQ(renderer_id,
Lukasz Anforowicz2ff2d152017-09-28 15:59:51790 params.target_contents->GetMainFrame()->GetProcess()->GetID());
lof84501da082016-05-23 21:22:54791
792 // We should have one window, with two tabs.
793 EXPECT_EQ(1u, chrome::GetTotalBrowserCount());
794 EXPECT_EQ(2, browser()->tab_strip_model()->count());
795}
796
[email protected]a1feae52010-10-11 22:14:45797// This tests adding a tab at a specific index.
798IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Tabstrip_InsertAtIndex) {
799 // This is not meant to be a comprehensive test of whether or not the tab
800 // implementation of the browser observes the insertion index. That is
801 // covered by the unit tests for TabStripModel. This merely verifies that
802 // insertion index preference is reflected in common cases.
meacerc62e2ee2014-10-22 00:44:52803 chrome::NavigateParams params(MakeNavigateParams());
nick3b04f322016-08-31 19:29:19804 params.disposition = WindowOpenDisposition::NEW_FOREGROUND_TAB;
meacerc62e2ee2014-10-22 00:44:52805 params.tabstrip_index = 0;
806 params.tabstrip_add_types = TabStripModel::ADD_FORCE_INDEX;
807 chrome::Navigate(&params);
[email protected]a1feae52010-10-11 22:14:45808
809 // Navigate() should have inserted a new tab at slot 0 in the tabstrip.
meacerc62e2ee2014-10-22 00:44:52810 EXPECT_EQ(browser(), params.browser);
[email protected]e232c992012-12-06 12:43:20811 EXPECT_EQ(0, browser()->tab_strip_model()->GetIndexOfWebContents(
meacerc62e2ee2014-10-22 00:44:52812 static_cast<const WebContents*>(params.target_contents)));
[email protected]a1feae52010-10-11 22:14:45813
814 // We should have one window - the browser() provided by the framework.
[email protected]0665ebe2013-02-13 09:53:19815 EXPECT_EQ(1u, chrome::GetTotalBrowserCount());
[email protected]ee496952013-01-10 23:17:33816 EXPECT_EQ(2, browser()->tab_strip_model()->count());
[email protected]a1feae52010-10-11 22:14:45817}
818
[email protected]bb89e7482010-11-17 18:27:04819// This test verifies that constructing params with disposition = SINGLETON_TAB
[email protected]fee320542011-03-02 01:30:49820// and IGNORE_AND_NAVIGATE opens a new tab navigated to the specified URL if
[email protected]67ed83e2011-01-07 22:54:00821// no previous tab with that URL (minus the path) exists.
[email protected]bb89e7482010-11-17 18:27:04822IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
823 Disposition_SingletonTabNew_IgnorePath) {
[email protected]52877dbc62012-06-29 22:22:03824 chrome::AddSelectedTabWithURL(browser(), GetGoogleURL(),
Sylvain Defresnec6ccc77d2014-09-19 10:19:35825 ui::PAGE_TRANSITION_LINK);
[email protected]bb89e7482010-11-17 18:27:04826
827 // We should have one browser with 2 tabs, the 2nd selected.
[email protected]0665ebe2013-02-13 09:53:19828 EXPECT_EQ(1u, chrome::GetTotalBrowserCount());
[email protected]ee496952013-01-10 23:17:33829 EXPECT_EQ(2, browser()->tab_strip_model()->count());
830 EXPECT_EQ(1, browser()->tab_strip_model()->active_index());
[email protected]bb89e7482010-11-17 18:27:04831
832 // Navigate to a new singleton tab with a sub-page.
meacerc62e2ee2014-10-22 00:44:52833 chrome::NavigateParams params(MakeNavigateParams());
nick3b04f322016-08-31 19:29:19834 params.disposition = WindowOpenDisposition::SINGLETON_TAB;
meacerc62e2ee2014-10-22 00:44:52835 params.url = GetContentSettingsURL();
836 params.window_action = chrome::NavigateParams::SHOW_WINDOW;
837 params.path_behavior = chrome::NavigateParams::IGNORE_AND_NAVIGATE;
838 chrome::Navigate(&params);
[email protected]bb89e7482010-11-17 18:27:04839
840 // The last tab should now be selected and navigated to the sub-page of the
[email protected]50592b52013-05-02 22:26:25841 // URL.
meacerc62e2ee2014-10-22 00:44:52842 EXPECT_EQ(browser(), params.browser);
[email protected]ee496952013-01-10 23:17:33843 EXPECT_EQ(3, browser()->tab_strip_model()->count());
844 EXPECT_EQ(2, browser()->tab_strip_model()->active_index());
[email protected]a048ad22012-03-23 04:26:56845 EXPECT_EQ(GetContentSettingsURL(),
[email protected]ee496952013-01-10 23:17:33846 ShortenUberURL(browser()->tab_strip_model()->
847 GetActiveWebContents()->GetURL()));
[email protected]bb89e7482010-11-17 18:27:04848}
849
850// This test verifies that constructing params with disposition = SINGLETON_TAB
[email protected]fee320542011-03-02 01:30:49851// and IGNORE_AND_NAVIGATE opens an existing tab with the matching URL (minus
[email protected]bb89e7482010-11-17 18:27:04852// the path) which is navigated to the specified URL.
853IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
854 Disposition_SingletonTabExisting_IgnorePath) {
[email protected]ddddfda2011-07-14 23:19:39855 GURL singleton_url1(GetSettingsURL());
[email protected]52877dbc62012-06-29 22:22:03856 chrome::AddSelectedTabWithURL(browser(), singleton_url1,
Sylvain Defresnec6ccc77d2014-09-19 10:19:35857 ui::PAGE_TRANSITION_LINK);
[email protected]52877dbc62012-06-29 22:22:03858 chrome::AddSelectedTabWithURL(browser(), GetGoogleURL(),
Sylvain Defresnec6ccc77d2014-09-19 10:19:35859 ui::PAGE_TRANSITION_LINK);
[email protected]bb89e7482010-11-17 18:27:04860
861 // We should have one browser with 3 tabs, the 3rd selected.
[email protected]0665ebe2013-02-13 09:53:19862 EXPECT_EQ(1u, chrome::GetTotalBrowserCount());
[email protected]ee496952013-01-10 23:17:33863 EXPECT_EQ(3, browser()->tab_strip_model()->count());
864 EXPECT_EQ(2, browser()->tab_strip_model()->active_index());
[email protected]bb89e7482010-11-17 18:27:04865
866 // Navigate to singleton_url1.
meacerc62e2ee2014-10-22 00:44:52867 chrome::NavigateParams params(MakeNavigateParams());
nick3b04f322016-08-31 19:29:19868 params.disposition = WindowOpenDisposition::SINGLETON_TAB;
meacerc62e2ee2014-10-22 00:44:52869 params.url = GetContentSettingsURL();
870 params.window_action = chrome::NavigateParams::SHOW_WINDOW;
871 params.path_behavior = chrome::NavigateParams::IGNORE_AND_NAVIGATE;
872 chrome::Navigate(&params);
[email protected]bb89e7482010-11-17 18:27:04873
874 // The middle tab should now be selected and navigated to the sub-page of the
875 // URL.
meacerc62e2ee2014-10-22 00:44:52876 EXPECT_EQ(browser(), params.browser);
[email protected]ee496952013-01-10 23:17:33877 EXPECT_EQ(3, browser()->tab_strip_model()->count());
878 EXPECT_EQ(1, browser()->tab_strip_model()->active_index());
[email protected]a048ad22012-03-23 04:26:56879 EXPECT_EQ(GetContentSettingsURL(),
[email protected]ee496952013-01-10 23:17:33880 ShortenUberURL(browser()->tab_strip_model()->
881 GetActiveWebContents()->GetURL()));
[email protected]bb89e7482010-11-17 18:27:04882}
883
884// This test verifies that constructing params with disposition = SINGLETON_TAB
[email protected]fee320542011-03-02 01:30:49885// and IGNORE_AND_NAVIGATE opens an existing tab with the matching URL (minus
[email protected]bb89e7482010-11-17 18:27:04886// the path) which is navigated to the specified URL.
887IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
888 Disposition_SingletonTabExistingSubPath_IgnorePath) {
[email protected]a048ad22012-03-23 04:26:56889 GURL singleton_url1(GetContentSettingsURL());
[email protected]52877dbc62012-06-29 22:22:03890 chrome::AddSelectedTabWithURL(browser(), singleton_url1,
Sylvain Defresnec6ccc77d2014-09-19 10:19:35891 ui::PAGE_TRANSITION_LINK);
[email protected]52877dbc62012-06-29 22:22:03892 chrome::AddSelectedTabWithURL(browser(), GetGoogleURL(),
Sylvain Defresnec6ccc77d2014-09-19 10:19:35893 ui::PAGE_TRANSITION_LINK);
[email protected]bb89e7482010-11-17 18:27:04894
895 // We should have one browser with 3 tabs, the 3rd selected.
[email protected]0665ebe2013-02-13 09:53:19896 EXPECT_EQ(1u, chrome::GetTotalBrowserCount());
[email protected]ee496952013-01-10 23:17:33897 EXPECT_EQ(3, browser()->tab_strip_model()->count());
898 EXPECT_EQ(2, browser()->tab_strip_model()->active_index());
[email protected]bb89e7482010-11-17 18:27:04899
900 // Navigate to singleton_url1.
meacerc62e2ee2014-10-22 00:44:52901 chrome::NavigateParams params(MakeNavigateParams());
nick3b04f322016-08-31 19:29:19902 params.disposition = WindowOpenDisposition::SINGLETON_TAB;
meacerc62e2ee2014-10-22 00:44:52903 params.url = GetClearBrowsingDataURL();
904 params.window_action = chrome::NavigateParams::SHOW_WINDOW;
905 params.path_behavior = chrome::NavigateParams::IGNORE_AND_NAVIGATE;
906 chrome::Navigate(&params);
[email protected]bb89e7482010-11-17 18:27:04907
908 // The middle tab should now be selected and navigated to the sub-page of the
909 // URL.
meacerc62e2ee2014-10-22 00:44:52910 EXPECT_EQ(browser(), params.browser);
[email protected]ee496952013-01-10 23:17:33911 EXPECT_EQ(3, browser()->tab_strip_model()->count());
912 EXPECT_EQ(1, browser()->tab_strip_model()->active_index());
[email protected]a048ad22012-03-23 04:26:56913 EXPECT_EQ(GetClearBrowsingDataURL(),
[email protected]ee496952013-01-10 23:17:33914 ShortenUberURL(browser()->tab_strip_model()->
915 GetActiveWebContents()->GetURL()));
[email protected]bb89e7482010-11-17 18:27:04916}
[email protected]2dd85482010-11-06 01:56:47917
[email protected]637b3442011-01-10 23:31:48918// This test verifies that constructing params with disposition = SINGLETON_TAB
[email protected]fee320542011-03-02 01:30:49919// and IGNORE_AND_STAY_PUT opens an existing tab with the matching URL (minus
920// the path).
921IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
922 Disposition_SingletonTabExistingSubPath_IgnorePath2) {
[email protected]a048ad22012-03-23 04:26:56923 GURL singleton_url1(GetContentSettingsURL());
[email protected]52877dbc62012-06-29 22:22:03924 chrome::AddSelectedTabWithURL(browser(), singleton_url1,
Sylvain Defresnec6ccc77d2014-09-19 10:19:35925 ui::PAGE_TRANSITION_LINK);
[email protected]52877dbc62012-06-29 22:22:03926 chrome::AddSelectedTabWithURL(browser(), GetGoogleURL(),
Sylvain Defresnec6ccc77d2014-09-19 10:19:35927 ui::PAGE_TRANSITION_LINK);
[email protected]fee320542011-03-02 01:30:49928
929 // We should have one browser with 3 tabs, the 3rd selected.
[email protected]0665ebe2013-02-13 09:53:19930 EXPECT_EQ(1u, chrome::GetTotalBrowserCount());
[email protected]ee496952013-01-10 23:17:33931 EXPECT_EQ(3, browser()->tab_strip_model()->count());
932 EXPECT_EQ(2, browser()->tab_strip_model()->active_index());
[email protected]fee320542011-03-02 01:30:49933
934 // Navigate to singleton_url1.
meacerc62e2ee2014-10-22 00:44:52935 chrome::NavigateParams params(MakeNavigateParams());
nick3b04f322016-08-31 19:29:19936 params.disposition = WindowOpenDisposition::SINGLETON_TAB;
meacerc62e2ee2014-10-22 00:44:52937 params.url = GetClearBrowsingDataURL();
938 params.window_action = chrome::NavigateParams::SHOW_WINDOW;
939 params.path_behavior = chrome::NavigateParams::IGNORE_AND_STAY_PUT;
940 chrome::Navigate(&params);
[email protected]fee320542011-03-02 01:30:49941
942 // The middle tab should now be selected.
meacerc62e2ee2014-10-22 00:44:52943 EXPECT_EQ(browser(), params.browser);
[email protected]ee496952013-01-10 23:17:33944 EXPECT_EQ(3, browser()->tab_strip_model()->count());
945 EXPECT_EQ(1, browser()->tab_strip_model()->active_index());
[email protected]fee320542011-03-02 01:30:49946 EXPECT_EQ(singleton_url1,
[email protected]ee496952013-01-10 23:17:33947 ShortenUberURL(browser()->tab_strip_model()->
948 GetActiveWebContents()->GetURL()));
[email protected]fee320542011-03-02 01:30:49949}
950
951// This test verifies that constructing params with disposition = SINGLETON_TAB
952// and IGNORE_AND_NAVIGATE will update the current tab's URL if the currently
[email protected]637b3442011-01-10 23:31:48953// selected tab is a match but has a different path.
954IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
955 Disposition_SingletonTabFocused_IgnorePath) {
[email protected]a048ad22012-03-23 04:26:56956 GURL singleton_url_current(GetContentSettingsURL());
[email protected]52877dbc62012-06-29 22:22:03957 chrome::AddSelectedTabWithURL(browser(), singleton_url_current,
Sylvain Defresnec6ccc77d2014-09-19 10:19:35958 ui::PAGE_TRANSITION_LINK);
[email protected]637b3442011-01-10 23:31:48959
960 // We should have one browser with 2 tabs, the 2nd selected.
[email protected]0665ebe2013-02-13 09:53:19961 EXPECT_EQ(1u, chrome::GetTotalBrowserCount());
[email protected]ee496952013-01-10 23:17:33962 EXPECT_EQ(2, browser()->tab_strip_model()->count());
963 EXPECT_EQ(1, browser()->tab_strip_model()->active_index());
[email protected]637b3442011-01-10 23:31:48964
965 // Navigate to a different settings path.
[email protected]a048ad22012-03-23 04:26:56966 GURL singleton_url_target(GetClearBrowsingDataURL());
meacerc62e2ee2014-10-22 00:44:52967 chrome::NavigateParams params(MakeNavigateParams());
nick3b04f322016-08-31 19:29:19968 params.disposition = WindowOpenDisposition::SINGLETON_TAB;
meacerc62e2ee2014-10-22 00:44:52969 params.url = singleton_url_target;
970 params.window_action = chrome::NavigateParams::SHOW_WINDOW;
971 params.path_behavior = chrome::NavigateParams::IGNORE_AND_NAVIGATE;
972 chrome::Navigate(&params);
[email protected]637b3442011-01-10 23:31:48973
974 // The second tab should still be selected, but navigated to the new path.
meacerc62e2ee2014-10-22 00:44:52975 EXPECT_EQ(browser(), params.browser);
[email protected]ee496952013-01-10 23:17:33976 EXPECT_EQ(2, browser()->tab_strip_model()->count());
977 EXPECT_EQ(1, browser()->tab_strip_model()->active_index());
[email protected]637b3442011-01-10 23:31:48978 EXPECT_EQ(singleton_url_target,
[email protected]ee496952013-01-10 23:17:33979 ShortenUberURL(browser()->tab_strip_model()->
980 GetActiveWebContents()->GetURL()));
[email protected]637b3442011-01-10 23:31:48981}
982
[email protected]07afd7c2011-02-17 10:07:11983// This test verifies that constructing params with disposition = SINGLETON_TAB
[email protected]fee320542011-03-02 01:30:49984// and IGNORE_AND_NAVIGATE will open an existing matching tab with a different
985// query.
[email protected]07afd7c2011-02-17 10:07:11986IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
987 Disposition_SingletonTabExisting_IgnoreQuery) {
[email protected]ee496952013-01-10 23:17:33988 int initial_tab_count = browser()->tab_strip_model()->count();
[email protected]07afd7c2011-02-17 10:07:11989 GURL singleton_url_current("chrome://settings/internet");
[email protected]52877dbc62012-06-29 22:22:03990 chrome::AddSelectedTabWithURL(browser(), singleton_url_current,
Sylvain Defresnec6ccc77d2014-09-19 10:19:35991 ui::PAGE_TRANSITION_LINK);
[email protected]07afd7c2011-02-17 10:07:11992
[email protected]ee496952013-01-10 23:17:33993 EXPECT_EQ(initial_tab_count + 1, browser()->tab_strip_model()->count());
994 EXPECT_EQ(initial_tab_count, browser()->tab_strip_model()->active_index());
[email protected]07afd7c2011-02-17 10:07:11995
996 // Navigate to a different settings path.
997 GURL singleton_url_target(
998 "chrome://settings/internet?"
stevenjb82dbc53092015-03-14 18:32:24999 "guid=ethernet_00aa00aa00aa&networkType=1");
meacerc62e2ee2014-10-22 00:44:521000 chrome::NavigateParams params(MakeNavigateParams());
nick3b04f322016-08-31 19:29:191001 params.disposition = WindowOpenDisposition::SINGLETON_TAB;
meacerc62e2ee2014-10-22 00:44:521002 params.url = singleton_url_target;
1003 params.window_action = chrome::NavigateParams::SHOW_WINDOW;
1004 params.path_behavior = chrome::NavigateParams::IGNORE_AND_NAVIGATE;
1005 chrome::Navigate(&params);
[email protected]07afd7c2011-02-17 10:07:111006
1007 // Last tab should still be selected.
meacerc62e2ee2014-10-22 00:44:521008 EXPECT_EQ(browser(), params.browser);
[email protected]ee496952013-01-10 23:17:331009 EXPECT_EQ(initial_tab_count + 1, browser()->tab_strip_model()->count());
1010 EXPECT_EQ(initial_tab_count, browser()->tab_strip_model()->active_index());
[email protected]07afd7c2011-02-17 10:07:111011}
1012
[email protected]bd817c22011-02-09 08:16:461013// This test verifies that the settings page isn't opened in the incognito
1014// window.
[email protected]a048ad22012-03-23 04:26:561015// Disabled until fixed for uber settings: http://crbug.com/111243
[email protected]bd817c22011-02-09 08:16:461016IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
[email protected]a048ad22012-03-23 04:26:561017 DISABLED_Disposition_Settings_UseNonIncognitoWindow) {
[email protected]fc0ed302011-11-29 23:17:191018 RunUseNonIncognitoWindowTest(GetSettingsURL());
[email protected]bd817c22011-02-09 08:16:461019}
1020
[email protected]429e9712013-04-30 09:35:501021// This test verifies that the view-source settings page isn't opened in the
1022// incognito window.
1023IN_PROC_BROWSER_TEST_F(
1024 BrowserNavigatorTest,
1025 Disposition_ViewSource_Settings_DoNothingIfIncognitoForced) {
[email protected]dbdda5402013-05-30 22:13:481026 std::string view_source(content::kViewSourceScheme);
[email protected]429e9712013-04-30 09:35:501027 view_source.append(":");
1028 view_source.append(chrome::kChromeUISettingsURL);
1029 RunDoNothingIfIncognitoIsForcedTest(GURL(view_source));
1030}
1031
1032// This test verifies that the view-source settings page isn't opened in the
1033// incognito window even if incognito mode is forced (does nothing in that
1034// case).
1035IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
1036 Disposition_ViewSource_Settings_UseNonIncognitoWindow) {
[email protected]dbdda5402013-05-30 22:13:481037 std::string view_source(content::kViewSourceScheme);
[email protected]429e9712013-04-30 09:35:501038 view_source.append(":");
1039 view_source.append(chrome::kChromeUISettingsURL);
1040 RunUseNonIncognitoWindowTest(GURL(view_source));
1041}
1042
[email protected]82404cd2011-07-12 19:55:141043// This test verifies that the settings page isn't opened in the incognito
1044// window from a non-incognito window (bookmark open-in-incognito trigger).
[email protected]a048ad22012-03-23 04:26:561045// Disabled until fixed for uber settings: http://crbug.com/111243
[email protected]82404cd2011-07-12 19:55:141046IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
[email protected]a048ad22012-03-23 04:26:561047 DISABLED_Disposition_Settings_UseNonIncognitoWindowForBookmark) {
[email protected]78e2edc2012-07-01 23:32:281048 chrome::NavigateParams params(browser(), GetSettingsURL(),
Sylvain Defresnec6ccc77d2014-09-19 10:19:351049 ui::PAGE_TRANSITION_AUTO_BOOKMARK);
nick3b04f322016-08-31 19:29:191050 params.disposition = WindowOpenDisposition::OFF_THE_RECORD;
[email protected]82404cd2011-07-12 19:55:141051 {
[email protected]a7fe9112012-07-20 02:34:451052 content::WindowedNotificationObserver observer(
[email protected]ad50def52011-10-19 23:17:071053 content::NOTIFICATION_LOAD_STOP,
1054 content::NotificationService::AllSources());
[email protected]78e2edc2012-07-01 23:32:281055 chrome::Navigate(&params);
[email protected]82404cd2011-07-12 19:55:141056 observer.Wait();
1057 }
1058
[email protected]0665ebe2013-02-13 09:53:191059 EXPECT_EQ(1u, chrome::GetTotalBrowserCount());
[email protected]52877dbc62012-06-29 22:22:031060 EXPECT_EQ(GetSettingsURL(),
[email protected]ee496952013-01-10 23:17:331061 ShortenUberURL(browser()->tab_strip_model()->
1062 GetActiveWebContents()->GetURL()));
[email protected]82404cd2011-07-12 19:55:141063}
1064
[email protected]93ad8e1c2011-11-08 21:34:051065// Settings page is expected to always open in normal mode regardless
1066// of whether the user is trying to open it in incognito mode or not.
1067// This test verifies that if incognito mode is forced (by policy), settings
1068// page doesn't open at all.
[email protected]a048ad22012-03-23 04:26:561069// Disabled until fixed for uber settings: http://crbug.com/111243
[email protected]93ad8e1c2011-11-08 21:34:051070IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
[email protected]a048ad22012-03-23 04:26:561071 DISABLED_Disposition_Settings_DoNothingIfIncognitoIsForced) {
[email protected]fc0ed302011-11-29 23:17:191072 RunDoNothingIfIncognitoIsForcedTest(GetSettingsURL());
[email protected]93ad8e1c2011-11-08 21:34:051073}
1074
[email protected]bd817c22011-02-09 08:16:461075// This test verifies that the bookmarks page isn't opened in the incognito
1076// window.
1077IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
1078 Disposition_Bookmarks_UseNonIncognitoWindow) {
[email protected]fc0ed302011-11-29 23:17:191079 RunUseNonIncognitoWindowTest(GURL(chrome::kChromeUIBookmarksURL));
[email protected]bd817c22011-02-09 08:16:461080}
1081
[email protected]93ad8e1c2011-11-08 21:34:051082// Bookmark manager is expected to always open in normal mode regardless
1083// of whether the user is trying to open it in incognito mode or not.
1084// This test verifies that if incognito mode is forced (by policy), bookmark
1085// manager doesn't open at all.
1086IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
1087 Disposition_Bookmarks_DoNothingIfIncognitoIsForced) {
[email protected]fc0ed302011-11-29 23:17:191088 RunDoNothingIfIncognitoIsForcedTest(GURL(chrome::kChromeUIBookmarksURL));
1089}
[email protected]93ad8e1c2011-11-08 21:34:051090
[email protected]7de53c62011-05-13 06:44:161091// This test makes sure a crashed singleton tab reloads from a new navigation.
[email protected]c4c0c0a12014-07-23 17:06:021092// http://crbug.com/396371
[email protected]7de53c62011-05-13 06:44:161093IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
[email protected]c4c0c0a12014-07-23 17:06:021094 DISABLED_NavigateToCrashedSingletonTab) {
[email protected]a048ad22012-03-23 04:26:561095 GURL singleton_url(GetContentSettingsURL());
[email protected]5a1a52462012-11-15 03:35:161096 WebContents* web_contents = chrome::AddSelectedTabWithURL(
Sylvain Defresnec6ccc77d2014-09-19 10:19:351097 browser(), singleton_url, ui::PAGE_TRANSITION_LINK);
[email protected]7de53c62011-05-13 06:44:161098
1099 // We should have one browser with 2 tabs, the 2nd selected.
[email protected]0665ebe2013-02-13 09:53:191100 EXPECT_EQ(1u, chrome::GetTotalBrowserCount());
[email protected]ee496952013-01-10 23:17:331101 EXPECT_EQ(2, browser()->tab_strip_model()->count());
1102 EXPECT_EQ(1, browser()->tab_strip_model()->active_index());
[email protected]7de53c62011-05-13 06:44:161103
1104 // Kill the singleton tab.
[email protected]83ff91c2012-01-05 20:54:131105 web_contents->SetIsCrashed(base::TERMINATION_STATUS_PROCESS_CRASHED, -1);
1106 EXPECT_TRUE(web_contents->IsCrashed());
[email protected]7de53c62011-05-13 06:44:161107
meacerc62e2ee2014-10-22 00:44:521108 chrome::NavigateParams params(MakeNavigateParams());
nick3b04f322016-08-31 19:29:191109 params.disposition = WindowOpenDisposition::SINGLETON_TAB;
meacerc62e2ee2014-10-22 00:44:521110 params.url = singleton_url;
1111 params.window_action = chrome::NavigateParams::SHOW_WINDOW;
1112 params.path_behavior = chrome::NavigateParams::IGNORE_AND_NAVIGATE;
1113 ui_test_utils::NavigateToURL(&params);
[email protected]7de53c62011-05-13 06:44:161114
1115 // The tab should not be sad anymore.
[email protected]83ff91c2012-01-05 20:54:131116 EXPECT_FALSE(web_contents->IsCrashed());
[email protected]7de53c62011-05-13 06:44:161117}
1118
[email protected]fcca741b2011-06-17 22:46:371119IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
1120 NavigateFromDefaultToOptionsInSameTab) {
[email protected]ddddfda2011-07-14 23:19:391121 {
[email protected]a7fe9112012-07-20 02:34:451122 content::WindowedNotificationObserver observer(
[email protected]ad50def52011-10-19 23:17:071123 content::NOTIFICATION_LOAD_STOP,
1124 content::NotificationService::AllSources());
Steven Bennettsc406dd22017-07-28 00:32:361125 ShowSettings(browser());
[email protected]ddddfda2011-07-14 23:19:391126 observer.Wait();
1127 }
[email protected]ee496952013-01-10 23:17:331128 EXPECT_EQ(1, browser()->tab_strip_model()->count());
[email protected]52877dbc62012-06-29 22:22:031129 EXPECT_EQ(GetSettingsURL(),
[email protected]ee496952013-01-10 23:17:331130 ShortenUberURL(browser()->tab_strip_model()->
1131 GetActiveWebContents()->GetURL()));
[email protected]fcca741b2011-06-17 22:46:371132}
1133
1134IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
1135 NavigateFromBlankToOptionsInSameTab) {
meacerc62e2ee2014-10-22 00:44:521136 chrome::NavigateParams params(MakeNavigateParams());
1137 params.url = GURL(url::kAboutBlankURL);
1138 ui_test_utils::NavigateToURL(&params);
[email protected]fcca741b2011-06-17 22:46:371139
[email protected]ddddfda2011-07-14 23:19:391140 {
[email protected]a7fe9112012-07-20 02:34:451141 content::WindowedNotificationObserver observer(
[email protected]ad50def52011-10-19 23:17:071142 content::NOTIFICATION_LOAD_STOP,
1143 content::NotificationService::AllSources());
Steven Bennettsc406dd22017-07-28 00:32:361144 ShowSettings(browser());
[email protected]ddddfda2011-07-14 23:19:391145 observer.Wait();
1146 }
[email protected]ee496952013-01-10 23:17:331147 EXPECT_EQ(1, browser()->tab_strip_model()->count());
[email protected]52877dbc62012-06-29 22:22:031148 EXPECT_EQ(GetSettingsURL(),
[email protected]ee496952013-01-10 23:17:331149 ShortenUberURL(browser()->tab_strip_model()->
1150 GetActiveWebContents()->GetURL()));
[email protected]fcca741b2011-06-17 22:46:371151}
1152
1153IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
1154 NavigateFromNTPToOptionsInSameTab) {
meacerc62e2ee2014-10-22 00:44:521155 chrome::NavigateParams params(MakeNavigateParams());
1156 params.url = GURL(chrome::kChromeUINewTabURL);
1157 ui_test_utils::NavigateToURL(&params);
[email protected]ee496952013-01-10 23:17:331158 EXPECT_EQ(1, browser()->tab_strip_model()->count());
[email protected]27658f32013-11-14 03:20:371159 EXPECT_EQ(GURL(chrome::kChromeUINewTabURL),
1160 browser()->tab_strip_model()->GetActiveWebContents()->GetURL());
[email protected]fcca741b2011-06-17 22:46:371161
[email protected]ddddfda2011-07-14 23:19:391162 {
[email protected]a7fe9112012-07-20 02:34:451163 content::WindowedNotificationObserver observer(
[email protected]ad50def52011-10-19 23:17:071164 content::NOTIFICATION_LOAD_STOP,
1165 content::NotificationService::AllSources());
Steven Bennettsc406dd22017-07-28 00:32:361166 ShowSettings(browser());
[email protected]ddddfda2011-07-14 23:19:391167 observer.Wait();
1168 }
[email protected]ee496952013-01-10 23:17:331169 EXPECT_EQ(1, browser()->tab_strip_model()->count());
[email protected]52877dbc62012-06-29 22:22:031170 EXPECT_EQ(GetSettingsURL(),
[email protected]ee496952013-01-10 23:17:331171 ShortenUberURL(browser()->tab_strip_model()->
1172 GetActiveWebContents()->GetURL()));
[email protected]fcca741b2011-06-17 22:46:371173}
1174
1175IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
1176 NavigateFromPageToOptionsInNewTab) {
meacerc62e2ee2014-10-22 00:44:521177 chrome::NavigateParams params(MakeNavigateParams());
1178 ui_test_utils::NavigateToURL(&params);
[email protected]ee496952013-01-10 23:17:331179 EXPECT_EQ(GetGoogleURL(),
1180 browser()->tab_strip_model()->GetActiveWebContents()->GetURL());
[email protected]0665ebe2013-02-13 09:53:191181 EXPECT_EQ(1u, chrome::GetTotalBrowserCount());
[email protected]ee496952013-01-10 23:17:331182 EXPECT_EQ(1, browser()->tab_strip_model()->count());
[email protected]fcca741b2011-06-17 22:46:371183
[email protected]ddddfda2011-07-14 23:19:391184 {
[email protected]a7fe9112012-07-20 02:34:451185 content::WindowedNotificationObserver observer(
[email protected]ad50def52011-10-19 23:17:071186 content::NOTIFICATION_LOAD_STOP,
1187 content::NotificationService::AllSources());
Steven Bennettsc406dd22017-07-28 00:32:361188 ShowSettings(browser());
[email protected]ddddfda2011-07-14 23:19:391189 observer.Wait();
1190 }
[email protected]ee496952013-01-10 23:17:331191 EXPECT_EQ(2, browser()->tab_strip_model()->count());
[email protected]52877dbc62012-06-29 22:22:031192 EXPECT_EQ(GetSettingsURL(),
[email protected]ee496952013-01-10 23:17:331193 ShortenUberURL(browser()->tab_strip_model()->
1194 GetActiveWebContents()->GetURL()));
[email protected]fcca741b2011-06-17 22:46:371195}
1196
1197IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
1198 NavigateFromNTPToOptionsSingleton) {
[email protected]ddddfda2011-07-14 23:19:391199 {
[email protected]a7fe9112012-07-20 02:34:451200 content::WindowedNotificationObserver observer(
[email protected]ad50def52011-10-19 23:17:071201 content::NOTIFICATION_LOAD_STOP,
1202 content::NotificationService::AllSources());
Steven Bennettsc406dd22017-07-28 00:32:361203 ShowSettings(browser());
[email protected]ddddfda2011-07-14 23:19:391204 observer.Wait();
1205 }
[email protected]ee496952013-01-10 23:17:331206 EXPECT_EQ(1, browser()->tab_strip_model()->count());
[email protected]fcca741b2011-06-17 22:46:371207
[email protected]a37d4b02012-06-25 21:56:101208 chrome::NewTab(browser());
[email protected]ee496952013-01-10 23:17:331209 EXPECT_EQ(2, browser()->tab_strip_model()->count());
[email protected]fcca741b2011-06-17 22:46:371210
[email protected]ddddfda2011-07-14 23:19:391211 {
[email protected]a7fe9112012-07-20 02:34:451212 content::WindowedNotificationObserver observer(
[email protected]ad50def52011-10-19 23:17:071213 content::NOTIFICATION_LOAD_STOP,
1214 content::NotificationService::AllSources());
Steven Bennettsc406dd22017-07-28 00:32:361215 ShowSettings(browser());
[email protected]ddddfda2011-07-14 23:19:391216 observer.Wait();
1217 }
[email protected]ee496952013-01-10 23:17:331218 EXPECT_EQ(2, browser()->tab_strip_model()->count());
[email protected]52877dbc62012-06-29 22:22:031219 EXPECT_EQ(GetSettingsURL(),
[email protected]ee496952013-01-10 23:17:331220 ShortenUberURL(browser()->tab_strip_model()->
1221 GetActiveWebContents()->GetURL()));
[email protected]fcca741b2011-06-17 22:46:371222}
1223
1224IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
1225 NavigateFromNTPToOptionsPageInSameTab) {
[email protected]ddddfda2011-07-14 23:19:391226 {
[email protected]a7fe9112012-07-20 02:34:451227 content::WindowedNotificationObserver observer(
[email protected]ad50def52011-10-19 23:17:071228 content::NOTIFICATION_LOAD_STOP,
1229 content::NotificationService::AllSources());
Steven Bennettsc406dd22017-07-28 00:32:361230 chrome::ShowSettingsSubPageInTabbedBrowser(
1231 browser(), chrome::kClearBrowserDataSubPage);
[email protected]ddddfda2011-07-14 23:19:391232 observer.Wait();
1233 }
[email protected]ee496952013-01-10 23:17:331234 EXPECT_EQ(1, browser()->tab_strip_model()->count());
[email protected]a048ad22012-03-23 04:26:561235 EXPECT_EQ(GetClearBrowsingDataURL(),
[email protected]ee496952013-01-10 23:17:331236 browser()->tab_strip_model()->GetActiveWebContents()->GetURL());
[email protected]fcca741b2011-06-17 22:46:371237
[email protected]a37d4b02012-06-25 21:56:101238 chrome::NewTab(browser());
[email protected]ee496952013-01-10 23:17:331239 EXPECT_EQ(2, browser()->tab_strip_model()->count());
[email protected]fcca741b2011-06-17 22:46:371240
[email protected]ddddfda2011-07-14 23:19:391241 {
[email protected]a7fe9112012-07-20 02:34:451242 content::WindowedNotificationObserver observer(
[email protected]ad50def52011-10-19 23:17:071243 content::NOTIFICATION_LOAD_STOP,
1244 content::NotificationService::AllSources());
Steven Bennettsc406dd22017-07-28 00:32:361245 chrome::ShowSettingsSubPageInTabbedBrowser(
1246 browser(), chrome::kClearBrowserDataSubPage);
[email protected]ddddfda2011-07-14 23:19:391247 observer.Wait();
1248 }
[email protected]ee496952013-01-10 23:17:331249 EXPECT_EQ(2, browser()->tab_strip_model()->count());
[email protected]a048ad22012-03-23 04:26:561250 EXPECT_EQ(GetClearBrowsingDataURL(),
[email protected]ee496952013-01-10 23:17:331251 browser()->tab_strip_model()->GetActiveWebContents()->GetURL());
[email protected]fcca741b2011-06-17 22:46:371252}
1253
1254IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
[email protected]05912742013-03-12 00:29:151255 NavigateFromOtherTabToSingletonOptions) {
[email protected]ddddfda2011-07-14 23:19:391256 {
[email protected]a7fe9112012-07-20 02:34:451257 content::WindowedNotificationObserver observer(
[email protected]ad50def52011-10-19 23:17:071258 content::NOTIFICATION_LOAD_STOP,
1259 content::NotificationService::AllSources());
Steven Bennettsc406dd22017-07-28 00:32:361260 ShowSettings(browser());
[email protected]ddddfda2011-07-14 23:19:391261 observer.Wait();
1262 }
1263 {
[email protected]a7fe9112012-07-20 02:34:451264 content::WindowedNotificationObserver observer(
[email protected]ad50def52011-10-19 23:17:071265 content::NOTIFICATION_LOAD_STOP,
1266 content::NotificationService::AllSources());
[email protected]52877dbc62012-06-29 22:22:031267 chrome::AddSelectedTabWithURL(browser(), GetGoogleURL(),
Sylvain Defresnec6ccc77d2014-09-19 10:19:351268 ui::PAGE_TRANSITION_LINK);
[email protected]ddddfda2011-07-14 23:19:391269 observer.Wait();
1270 }
[email protected]fcca741b2011-06-17 22:46:371271
[email protected]05912742013-03-12 00:29:151272 // This load should simply cause a tab switch.
Steven Bennettsc406dd22017-07-28 00:32:361273 ShowSettings(browser());
[email protected]05912742013-03-12 00:29:151274
[email protected]ee496952013-01-10 23:17:331275 EXPECT_EQ(2, browser()->tab_strip_model()->count());
[email protected]ddddfda2011-07-14 23:19:391276 EXPECT_EQ(GetSettingsURL(),
[email protected]ee496952013-01-10 23:17:331277 ShortenUberURL(browser()->tab_strip_model()->
1278 GetActiveWebContents()->GetURL()));
[email protected]fcca741b2011-06-17 22:46:371279}
1280
[email protected]4e78b2d2013-06-12 16:46:171281IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, CloseSingletonTab) {
[email protected]79717cf2013-02-28 18:40:361282 for (int i = 0; i < 2; ++i) {
1283 content::WindowedNotificationObserver observer(
1284 content::NOTIFICATION_LOAD_STOP,
1285 content::NotificationService::AllSources());
1286 chrome::AddSelectedTabWithURL(browser(), GetGoogleURL(),
Sylvain Defresnec6ccc77d2014-09-19 10:19:351287 ui::PAGE_TRANSITION_TYPED);
[email protected]79717cf2013-02-28 18:40:361288 observer.Wait();
1289 }
1290
1291 browser()->tab_strip_model()->ActivateTabAt(0, true);
1292
1293 {
1294 content::WindowedNotificationObserver observer(
1295 content::NOTIFICATION_LOAD_STOP,
1296 content::NotificationService::AllSources());
Steven Bennettsc406dd22017-07-28 00:32:361297 ShowSettings(browser());
[email protected]79717cf2013-02-28 18:40:361298 observer.Wait();
1299 }
1300
1301 EXPECT_TRUE(browser()->tab_strip_model()->CloseWebContentsAt(
1302 2, TabStripModel::CLOSE_USER_GESTURE));
1303 EXPECT_EQ(0, browser()->tab_strip_model()->active_index());
1304}
1305
[email protected]ddddfda2011-07-14 23:19:391306IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
dbeam25b548f2017-05-05 18:05:241307 NavigateFromDefaultToHistoryInSameTab) {
[email protected]ddddfda2011-07-14 23:19:391308 {
[email protected]a7fe9112012-07-20 02:34:451309 content::WindowedNotificationObserver observer(
[email protected]ad50def52011-10-19 23:17:071310 content::NOTIFICATION_LOAD_STOP,
1311 content::NotificationService::AllSources());
[email protected]5d9cace72012-06-21 16:07:121312 chrome::ShowHistory(browser());
[email protected]ddddfda2011-07-14 23:19:391313 observer.Wait();
1314 }
[email protected]ee496952013-01-10 23:17:331315 EXPECT_EQ(1, browser()->tab_strip_model()->count());
dbeam25b548f2017-05-05 18:05:241316 EXPECT_EQ(GURL(chrome::kChromeUIHistoryURL),
[email protected]ee496952013-01-10 23:17:331317 browser()->tab_strip_model()->GetActiveWebContents()->GetURL());
[email protected]ddddfda2011-07-14 23:19:391318}
1319
[email protected]953c2132013-02-23 05:56:051320// TODO(linux_aura) http://crbug.com/163931
1321#if defined(OS_LINUX) && !defined(OS_CHROMEOS) && defined(USE_AURA)
dbeam2b4fc3562016-02-23 01:43:271322#define MAYBE_NavigateFromDefaultToBookmarksInSameTab \
1323 DISABLED_NavigateFromDefaultToBookmarksInSameTab
[email protected]953c2132013-02-23 05:56:051324#else
dbeam2b4fc3562016-02-23 01:43:271325#define MAYBE_NavigateFromDefaultToBookmarksInSameTab \
1326 NavigateFromDefaultToBookmarksInSameTab
[email protected]953c2132013-02-23 05:56:051327#endif
[email protected]ddddfda2011-07-14 23:19:391328IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
[email protected]953c2132013-02-23 05:56:051329 MAYBE_NavigateFromDefaultToBookmarksInSameTab) {
[email protected]ddddfda2011-07-14 23:19:391330 {
[email protected]a7fe9112012-07-20 02:34:451331 content::WindowedNotificationObserver observer(
[email protected]ad50def52011-10-19 23:17:071332 content::NOTIFICATION_LOAD_STOP,
1333 content::NotificationService::AllSources());
[email protected]5d9cace72012-06-21 16:07:121334 chrome::ShowBookmarkManager(browser());
[email protected]ddddfda2011-07-14 23:19:391335 observer.Wait();
1336 }
[email protected]ee496952013-01-10 23:17:331337 EXPECT_EQ(1, browser()->tab_strip_model()->count());
brettw66d1b81b2015-07-06 19:29:401338 EXPECT_TRUE(base::StartsWith(
[email protected]bc16a252013-01-23 02:21:491339 browser()->tab_strip_model()->GetActiveWebContents()->GetURL().spec(),
brettw66d1b81b2015-07-06 19:29:401340 chrome::kChromeUIBookmarksURL, base::CompareCase::SENSITIVE));
[email protected]ddddfda2011-07-14 23:19:391341}
1342
1343IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
1344 NavigateFromDefaultToDownloadsInSameTab) {
1345 {
[email protected]a7fe9112012-07-20 02:34:451346 content::WindowedNotificationObserver observer(
[email protected]ad50def52011-10-19 23:17:071347 content::NOTIFICATION_LOAD_STOP,
1348 content::NotificationService::AllSources());
[email protected]5d9cace72012-06-21 16:07:121349 chrome::ShowDownloads(browser());
[email protected]ddddfda2011-07-14 23:19:391350 observer.Wait();
1351 }
[email protected]ee496952013-01-10 23:17:331352 EXPECT_EQ(1, browser()->tab_strip_model()->count());
[email protected]ddddfda2011-07-14 23:19:391353 EXPECT_EQ(GURL(chrome::kChromeUIDownloadsURL),
[email protected]ee496952013-01-10 23:17:331354 browser()->tab_strip_model()->GetActiveWebContents()->GetURL());
[email protected]ddddfda2011-07-14 23:19:391355}
1356
[email protected]8fb16a82012-08-17 02:17:591357IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
1358 NavigateWithoutBrowser) {
1359 // First navigate using the profile of the existing browser window, and
1360 // check that the window is reused.
1361 chrome::NavigateParams params(browser()->profile(), GetGoogleURL(),
Sylvain Defresnec6ccc77d2014-09-19 10:19:351362 ui::PAGE_TRANSITION_LINK);
[email protected]8fb16a82012-08-17 02:17:591363 ui_test_utils::NavigateToURL(&params);
[email protected]0665ebe2013-02-13 09:53:191364 EXPECT_EQ(1u, chrome::GetTotalBrowserCount());
[email protected]8fb16a82012-08-17 02:17:591365
1366 // Now navigate using the incognito profile and check that a new window
1367 // is created.
1368 chrome::NavigateParams params_incognito(
1369 browser()->profile()->GetOffTheRecordProfile(),
Sylvain Defresnec6ccc77d2014-09-19 10:19:351370 GetGoogleURL(), ui::PAGE_TRANSITION_LINK);
[email protected]8fb16a82012-08-17 02:17:591371 ui_test_utils::NavigateToURL(&params_incognito);
[email protected]0665ebe2013-02-13 09:53:191372 EXPECT_EQ(2u, chrome::GetTotalBrowserCount());
[email protected]8fb16a82012-08-17 02:17:591373}
1374
[email protected]beb1d1192013-05-14 04:47:511375IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, ViewSourceIsntSingleton) {
1376 const std::string viewsource_ntp_url =
[email protected]dbdda5402013-05-30 22:13:481377 std::string(content::kViewSourceScheme) + ":" +
[email protected]beb1d1192013-05-14 04:47:511378 chrome::kChromeUIVersionURL;
1379
1380 chrome::NavigateParams viewsource_params(browser(),
1381 GURL(viewsource_ntp_url),
Sylvain Defresnec6ccc77d2014-09-19 10:19:351382 ui::PAGE_TRANSITION_LINK);
[email protected]beb1d1192013-05-14 04:47:511383 ui_test_utils::NavigateToURL(&viewsource_params);
1384
1385 chrome::NavigateParams singleton_params(browser(),
1386 GURL(chrome::kChromeUIVersionURL),
Sylvain Defresnec6ccc77d2014-09-19 10:19:351387 ui::PAGE_TRANSITION_LINK);
nick3b04f322016-08-31 19:29:191388 singleton_params.disposition = WindowOpenDisposition::SINGLETON_TAB;
[email protected]beb1d1192013-05-14 04:47:511389 EXPECT_EQ(-1, chrome::GetIndexOfSingletonTab(&singleton_params));
1390}
1391
[email protected]a2efc35d2013-08-03 23:17:251392// This test verifies that browser initiated navigations can send requests
1393// using POST.
1394IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
1395 SendBrowserInitiatedRequestUsingPOST) {
1396 // Uses a test sever to verify POST request.
svaldeza01f7d92015-11-18 17:47:561397 ASSERT_TRUE(embedded_test_server()->Start());
[email protected]a2efc35d2013-08-03 23:17:251398
1399 // Open a browser initiated POST request in new foreground tab.
[email protected]e9273e192013-12-11 17:51:491400 base::string16 expected_title(base::ASCIIToUTF16(kExpectedTitle));
[email protected]a2efc35d2013-08-03 23:17:251401 std::string post_data = kExpectedTitle;
[email protected]e9273e192013-12-11 17:51:491402 base::string16 title;
[email protected]a2efc35d2013-08-03 23:17:251403 ASSERT_TRUE(OpenPOSTURLInNewForegroundTabAndGetTitle(
svaldeza01f7d92015-11-18 17:47:561404 embedded_test_server()->GetURL(kEchoTitleCommand), post_data, true,
1405 &title));
[email protected]a2efc35d2013-08-03 23:17:251406 EXPECT_EQ(expected_title, title);
1407}
1408
lukasza477a5a22016-06-16 18:28:431409// This test verifies that renderer initiated navigations can also send requests
[email protected]a2efc35d2013-08-03 23:17:251410// using POST.
1411IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
1412 SendRendererInitiatedRequestUsingPOST) {
1413 // Uses a test sever to verify POST request.
svaldeza01f7d92015-11-18 17:47:561414 ASSERT_TRUE(embedded_test_server()->Start());
[email protected]a2efc35d2013-08-03 23:17:251415
1416 // Open a renderer initiated POST request in new foreground tab.
[email protected]e9273e192013-12-11 17:51:491417 base::string16 expected_title(base::ASCIIToUTF16(kExpectedTitle));
[email protected]a2efc35d2013-08-03 23:17:251418 std::string post_data = kExpectedTitle;
[email protected]e9273e192013-12-11 17:51:491419 base::string16 title;
[email protected]a2efc35d2013-08-03 23:17:251420 ASSERT_TRUE(OpenPOSTURLInNewForegroundTabAndGetTitle(
svaldeza01f7d92015-11-18 17:47:561421 embedded_test_server()->GetURL(kEchoTitleCommand), post_data, false,
1422 &title));
lukasza477a5a22016-06-16 18:28:431423 EXPECT_EQ(expected_title, title);
[email protected]a2efc35d2013-08-03 23:17:251424}
1425
meacerc62e2ee2014-10-22 00:44:521426// This test navigates to a data URL that contains BiDi control
1427// characters. For security reasons, BiDi control chars should always be
1428// escaped in the URL but they should be unescaped in the loaded HTML.
1429IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
1430 NavigateToDataURLWithBiDiControlChars) {
1431 // Text in Arabic.
1432 std::string text = "\xD8\xA7\xD8\xAE\xD8\xAA\xD8\xA8\xD8\xA7\xD8\xB1";
1433 // Page title starts with RTL mark.
1434 std::string unescaped_title = "\xE2\x80\x8F" + text;
1435 std::string data_url = "data:text/html;charset=utf-8,<html><title>" +
1436 unescaped_title + "</title></html>";
1437 // BiDi control chars in URLs are always escaped, so the expected URL should
1438 // have the title with the escaped RTL mark.
1439 std::string escaped_title = "%E2%80%8F" + text;
1440 std::string expected_url = "data:text/html;charset=utf-8,<html><title>" +
1441 escaped_title + "</title></html>";
1442
1443 // Navigate to the page.
1444 chrome::NavigateParams params(MakeNavigateParams());
nick3b04f322016-08-31 19:29:191445 params.disposition = WindowOpenDisposition::NEW_FOREGROUND_TAB;
meacerc62e2ee2014-10-22 00:44:521446 params.url = GURL(data_url);
1447 params.window_action = chrome::NavigateParams::SHOW_WINDOW;
1448 ui_test_utils::NavigateToURL(&params);
1449
1450 base::string16 expected_title(base::UTF8ToUTF16(unescaped_title));
1451 EXPECT_TRUE(params.target_contents);
1452 EXPECT_EQ(expected_title, params.target_contents->GetTitle());
1453 // GURL always keeps non-ASCII characters escaped, but check them anyways.
1454 EXPECT_EQ(GURL(expected_url).spec(), params.target_contents->GetURL().spec());
1455 // Check the omnibox text. It should have escaped RTL with unescaped text.
1456 LocationBar* location_bar = browser()->window()->GetLocationBar();
1457 OmniboxView* omnibox_view = location_bar->GetOmniboxView();
1458 EXPECT_EQ(base::UTF8ToUTF16(expected_url), omnibox_view->GetText());
1459}
1460
alexmos78d09c902016-11-17 05:15:131461// Test that there's no crash when a navigation to a WebUI page reuses an
1462// existing swapped out RenderViewHost. Previously, this led to a browser
1463// process crash in WebUI pages that use MojoWebUIController, which tried to
1464// use the RenderViewHost's GetMainFrame() when it was invalid in
1465// RenderViewCreated(). See https://crbug.com/627027.
1466IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, ReuseRVHWithWebUI) {
1467 ASSERT_TRUE(embedded_test_server()->Start());
1468
1469 // Visit a WebUI page with bindings.
1470 GURL webui_url(chrome::kChromeUIOmniboxURL);
1471 ui_test_utils::NavigateToURL(browser(), webui_url);
1472
1473 // window.open a new tab. This will keep the chrome://omnibox process alive
1474 // once we navigate away from it.
1475 content::WindowedNotificationObserver windowed_observer(
1476 content::NOTIFICATION_LOAD_STOP,
1477 content::NotificationService::AllSources());
1478 ASSERT_TRUE(content::ExecuteScript(
1479 browser()->tab_strip_model()->GetActiveWebContents(),
1480 "window.open('" + webui_url.spec() + "');"));
1481 windowed_observer.Wait();
1482 content::NavigationController* controller =
1483 content::Source<content::NavigationController>(windowed_observer.source())
1484 .ptr();
1485 content::WebContents* popup = controller->GetWebContents();
1486 ASSERT_TRUE(popup);
1487 EXPECT_EQ(2, browser()->tab_strip_model()->count());
1488 content::RenderViewHost* webui_rvh = popup->GetRenderViewHost();
sammc7f6c6a02017-01-30 00:53:511489 content::RenderFrameHost* webui_rfh = popup->GetMainFrame();
1490 EXPECT_EQ(content::BINDINGS_POLICY_WEB_UI, webui_rfh->GetEnabledBindings());
alexmos78d09c902016-11-17 05:15:131491
1492 // Navigate to another page in the popup.
1493 GURL nonwebui_url(embedded_test_server()->GetURL("a.com", "/title1.html"));
1494 ui_test_utils::NavigateToURL(browser(), nonwebui_url);
1495 EXPECT_NE(webui_rvh, popup->GetRenderViewHost());
1496
1497 // Go back in the popup. This should finish without crashing and should
1498 // reuse the old RenderViewHost.
1499 content::TestNavigationObserver back_load_observer(popup);
1500 controller->GoBack();
1501 back_load_observer.Wait();
1502 EXPECT_EQ(webui_rvh, popup->GetRenderViewHost());
1503 EXPECT_TRUE(webui_rvh->IsRenderViewLive());
sammc7f6c6a02017-01-30 00:53:511504 EXPECT_EQ(content::BINDINGS_POLICY_WEB_UI,
1505 webui_rvh->GetMainFrame()->GetEnabledBindings());
alexmos78d09c902016-11-17 05:15:131506}
1507
[email protected]a2efc35d2013-08-03 23:17:251508} // namespace