blob: 7b1362d34f1611ba805afc4dbf2fe52d5a034867 [file] [log] [blame]
[email protected]8643e6d2012-01-18 20:26:101// Copyright (c) 2012 The Chromium Authors. All rights reserved.
[email protected]a1feae52010-10-11 22:14:452// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
[email protected]bd817c22011-02-09 08:16:465#include "chrome/browser/ui/browser_navigator_browsertest.h"
6
[email protected]bb89e7482010-11-17 18:27:047#include "base/command_line.h"
[email protected]fc2b46b2014-05-03 16:33:458#include "base/strings/string_util.h"
[email protected]a2efc35d2013-08-03 23:17:259#include "base/strings/utf_string_conversions.h"
avi655876a2015-12-25 07:18:1510#include "build/build_config.h"
[email protected]26c53e662011-07-09 02:21:0211#include "chrome/app/chrome_command_ids.h"
[email protected]93ad8e1c2011-11-08 21:34:0512#include "chrome/browser/prefs/incognito_mode_prefs.h"
[email protected]8ecad5e2010-12-02 21:18:3313#include "chrome/browser/profiles/profile.h"
[email protected]2b09ae552013-02-23 06:38:0314#include "chrome/browser/ui/browser.h"
[email protected]a37d4b02012-06-25 21:56:1015#include "chrome/browser/ui/browser_commands.h"
[email protected]0665ebe2013-02-13 09:53:1916#include "chrome/browser/ui/browser_finder.h"
[email protected]339d6dd2010-11-12 00:41:5817#include "chrome/browser/ui/browser_navigator.h"
thestige80821242015-09-30 23:46:0818#include "chrome/browser/ui/browser_navigator_params.h"
[email protected]52877dbc62012-06-29 22:22:0319#include "chrome/browser/ui/browser_tabstrip.h"
[email protected]bb89e7482010-11-17 18:27:0420#include "chrome/browser/ui/browser_window.h"
[email protected]5d9cace72012-06-21 16:07:1221#include "chrome/browser/ui/chrome_pages.h"
meacerc62e2ee2014-10-22 00:44:5222#include "chrome/browser/ui/location_bar/location_bar.h"
[email protected]beb1d1192013-05-14 04:47:5123#include "chrome/browser/ui/singleton_tabs.h"
[email protected]b56e2e32012-05-11 21:18:0424#include "chrome/browser/ui/tabs/tab_strip_model.h"
[email protected]bb89e7482010-11-17 18:27:0425#include "chrome/common/chrome_switches.h"
[email protected]93ad8e1c2011-11-08 21:34:0526#include "chrome/common/pref_names.h"
[email protected]ddddfda2011-07-14 23:19:3927#include "chrome/common/url_constants.h"
[email protected]af44e7fb2011-07-29 18:32:3228#include "chrome/test/base/ui_test_utils.h"
blundell7dbd3792015-08-05 15:14:1929#include "components/omnibox/browser/omnibox_view.h"
brettwb1fc1b82016-02-02 00:19:0830#include "components/prefs/pref_service.h"
[email protected]ad50def52011-10-19 23:17:0731#include "content/public/browser/notification_service.h"
[email protected]0d6e9bd2011-10-18 04:29:1632#include "content/public/browser/notification_types.h"
lof84501da082016-05-23 21:22:5433#include "content/public/browser/render_frame_host.h"
34#include "content/public/browser/render_process_host.h"
[email protected]83ff91c2012-01-05 20:54:1335#include "content/public/browser/web_contents.h"
lof84501da082016-05-23 21:22:5436#include "content/public/test/browser_test_utils.h"
svaldeza01f7d92015-11-18 17:47:5637#include "net/test/embedded_test_server/embedded_test_server.h"
[email protected]a1feae52010-10-11 22:14:4538
[email protected]4ca15302012-01-03 05:53:2039using content::WebContents;
40
[email protected]ddddfda2011-07-14 23:19:3941namespace {
42
[email protected]a2efc35d2013-08-03 23:17:2543const char kExpectedTitle[] = "PASSED!";
svaldeza01f7d92015-11-18 17:47:5644const char kEchoTitleCommand[] = "/echotitle";
[email protected]a2efc35d2013-08-03 23:17:2545
[email protected]ddddfda2011-07-14 23:19:3946GURL GetGoogleURL() {
[email protected]bd817c22011-02-09 08:16:4647 return GURL("http://www.google.com/");
48}
[email protected]a1feae52010-10-11 22:14:4549
[email protected]ddddfda2011-07-14 23:19:3950GURL GetSettingsURL() {
[email protected]f8f93eb2012-09-25 03:06:2451 return GURL(chrome::kChromeUISettingsURL);
[email protected]ddddfda2011-07-14 23:19:3952}
53
[email protected]a048ad22012-03-23 04:26:5654GURL GetContentSettingsURL() {
55 return GetSettingsURL().Resolve(chrome::kContentSettingsExceptionsSubPage);
[email protected]ddddfda2011-07-14 23:19:3956}
57
[email protected]a048ad22012-03-23 04:26:5658GURL GetClearBrowsingDataURL() {
59 return GetSettingsURL().Resolve(chrome::kClearBrowserDataSubPage);
[email protected]ddddfda2011-07-14 23:19:3960}
61
[email protected]f8f93eb2012-09-25 03:06:2462// Converts long uber URLs ("chrome://chrome/foo/") to short (virtual) URLs
63// ("chrome://foo/"). This should be used to convert the return value of
64// WebContentsImpl::GetURL before comparison because it can return either the
65// real URL or the virtual URL.
66GURL ShortenUberURL(const GURL& url) {
67 std::string url_string = url.spec();
68 const std::string long_prefix = "chrome://chrome/";
69 const std::string short_prefix = "chrome://";
70 if (url_string.find(long_prefix) != 0)
71 return url;
72 url_string.replace(0, long_prefix.length(), short_prefix);
73 return GURL(url_string);
74}
75
[email protected]a2efc35d2013-08-03 23:17:2576} // namespace
[email protected]ddddfda2011-07-14 23:19:3977
[email protected]78e2edc2012-07-01 23:32:2878chrome::NavigateParams BrowserNavigatorTest::MakeNavigateParams() const {
[email protected]bd817c22011-02-09 08:16:4679 return MakeNavigateParams(browser());
80}
[email protected]a1feae52010-10-11 22:14:4581
[email protected]78e2edc2012-07-01 23:32:2882chrome::NavigateParams BrowserNavigatorTest::MakeNavigateParams(
[email protected]bd817c22011-02-09 08:16:4683 Browser* browser) const {
[email protected]78e2edc2012-07-01 23:32:2884 chrome::NavigateParams params(browser, GetGoogleURL(),
Sylvain Defresnec6ccc77d2014-09-19 10:19:3585 ui::PAGE_TRANSITION_LINK);
[email protected]50592b52013-05-02 22:26:2586 params.window_action = chrome::NavigateParams::SHOW_WINDOW;
[email protected]bd817c22011-02-09 08:16:4687 return params;
88}
[email protected]a1feae52010-10-11 22:14:4589
[email protected]a2efc35d2013-08-03 23:17:2590bool BrowserNavigatorTest::OpenPOSTURLInNewForegroundTabAndGetTitle(
91 const GURL& url, const std::string& post_data, bool is_browser_initiated,
92 base::string16* title) {
93 chrome::NavigateParams param(MakeNavigateParams());
94 param.disposition = NEW_FOREGROUND_TAB;
95 param.url = url;
96 param.is_renderer_initiated = !is_browser_initiated;
97 param.uses_post = true;
98 param.browser_initiated_post_data = new base::RefCountedStaticMemory(
[email protected]8df08cf2014-02-12 22:34:0899 post_data.data(), post_data.size());
[email protected]a2efc35d2013-08-03 23:17:25100
101 ui_test_utils::NavigateToURL(&param);
102 if (!param.target_contents)
103 return false;
104
105 // Navigate() should have opened the contents in new foreground tab in the
106 // current Browser.
107 EXPECT_EQ(browser(), param.browser);
108 EXPECT_EQ(browser()->tab_strip_model()->GetActiveWebContents(),
109 param.target_contents);
110 // We should have one window, with one tab.
111 EXPECT_EQ(1u, chrome::GetTotalBrowserCount());
112 EXPECT_EQ(2, browser()->tab_strip_model()->count());
113
114 *title = param.target_contents->GetTitle();
115 return true;
116}
117
[email protected]bd817c22011-02-09 08:16:46118Browser* BrowserNavigatorTest::CreateEmptyBrowserForType(Browser::Type type,
119 Profile* profile) {
scottmg851949002016-02-09 20:09:44120 Browser* browser = new Browser(Browser::CreateParams(type, profile));
[email protected]00509a32013-11-17 17:45:37121 chrome::AddTabAt(browser, GURL(), -1, true);
[email protected]bd817c22011-02-09 08:16:46122 return browser;
123}
[email protected]a1feae52010-10-11 22:14:45124
[email protected]d2202e22014-04-14 20:20:53125Browser* BrowserNavigatorTest::CreateEmptyBrowserForApp(Profile* profile) {
scottmg851949002016-02-09 20:09:44126 Browser* browser = new Browser(Browser::CreateParams::CreateForApp(
127 "Test", false /* trusted_source */, gfx::Rect(), profile));
[email protected]00509a32013-11-17 17:45:37128 chrome::AddTabAt(browser, GURL(), -1, true);
[email protected]b35b26b32011-05-05 20:35:14129 return browser;
130}
131
lof84501da082016-05-23 21:22:54132WebContents* BrowserNavigatorTest::CreateWebContents(bool initialize_renderer) {
[email protected]54944cde2012-12-09 09:24:59133 content::WebContents::CreateParams create_params(browser()->profile());
lof84501da082016-05-23 21:22:54134 create_params.initialize_renderer = initialize_renderer;
[email protected]ed245db2012-12-18 08:00:45135 content::WebContents* base_web_contents =
[email protected]ee496952013-01-10 23:17:33136 browser()->tab_strip_model()->GetActiveWebContents();
[email protected]ed245db2012-12-18 08:00:45137 if (base_web_contents) {
138 create_params.initial_size =
[email protected]fc2b46b2014-05-03 16:33:45139 base_web_contents->GetContainerBounds().size();
[email protected]ed245db2012-12-18 08:00:45140 }
[email protected]54944cde2012-12-09 09:24:59141 return WebContents::Create(create_params);
[email protected]bd817c22011-02-09 08:16:46142}
[email protected]a1feae52010-10-11 22:14:45143
[email protected]bd817c22011-02-09 08:16:46144void BrowserNavigatorTest::RunSuppressTest(WindowOpenDisposition disposition) {
[email protected]ee496952013-01-10 23:17:33145 GURL old_url = browser()->tab_strip_model()->GetActiveWebContents()->GetURL();
meacerc62e2ee2014-10-22 00:44:52146 chrome::NavigateParams params(MakeNavigateParams());
147 params.disposition = disposition;
148 chrome::Navigate(&params);
[email protected]a1feae52010-10-11 22:14:45149
[email protected]bd817c22011-02-09 08:16:46150 // Nothing should have happened as a result of Navigate();
[email protected]ee496952013-01-10 23:17:33151 EXPECT_EQ(1, browser()->tab_strip_model()->count());
[email protected]0665ebe2013-02-13 09:53:19152 EXPECT_EQ(1u, chrome::GetTotalBrowserCount());
[email protected]ee496952013-01-10 23:17:33153 EXPECT_EQ(old_url,
154 browser()->tab_strip_model()->GetActiveWebContents()->GetURL());
[email protected]bd817c22011-02-09 08:16:46155}
[email protected]bb89e7482010-11-17 18:27:04156
[email protected]fc0ed302011-11-29 23:17:19157void BrowserNavigatorTest::RunUseNonIncognitoWindowTest(const GURL& url) {
158 Browser* incognito_browser = CreateIncognitoBrowser();
159
[email protected]0665ebe2013-02-13 09:53:19160 EXPECT_EQ(2u, chrome::GetTotalBrowserCount());
[email protected]ee496952013-01-10 23:17:33161 EXPECT_EQ(1, browser()->tab_strip_model()->count());
162 EXPECT_EQ(1, incognito_browser->tab_strip_model()->count());
[email protected]fc0ed302011-11-29 23:17:19163
164 // Navigate to the page.
meacerc62e2ee2014-10-22 00:44:52165 chrome::NavigateParams params(MakeNavigateParams(incognito_browser));
166 params.disposition = SINGLETON_TAB;
167 params.url = url;
168 params.window_action = chrome::NavigateParams::SHOW_WINDOW;
169 chrome::Navigate(&params);
[email protected]fc0ed302011-11-29 23:17:19170
[email protected]50592b52013-05-02 22:26:25171 // This page should be opened in browser() window.
meacerc62e2ee2014-10-22 00:44:52172 EXPECT_NE(incognito_browser, params.browser);
173 EXPECT_EQ(browser(), params.browser);
[email protected]ee496952013-01-10 23:17:33174 EXPECT_EQ(2, browser()->tab_strip_model()->count());
175 EXPECT_EQ(url,
176 browser()->tab_strip_model()->GetActiveWebContents()->GetURL());
[email protected]fc0ed302011-11-29 23:17:19177}
178
179void BrowserNavigatorTest::RunDoNothingIfIncognitoIsForcedTest(
180 const GURL& url) {
181 Browser* browser = CreateIncognitoBrowser();
182
183 // Set kIncognitoModeAvailability to FORCED.
184 PrefService* prefs1 = browser->profile()->GetPrefs();
185 prefs1->SetInteger(prefs::kIncognitoModeAvailability,
186 IncognitoModePrefs::FORCED);
187 PrefService* prefs2 = browser->profile()->GetOriginalProfile()->GetPrefs();
188 prefs2->SetInteger(prefs::kIncognitoModeAvailability,
189 IncognitoModePrefs::FORCED);
190
191 // Navigate to the page.
meacerc62e2ee2014-10-22 00:44:52192 chrome::NavigateParams params(MakeNavigateParams(browser));
193 params.disposition = OFF_THE_RECORD;
194 params.url = url;
195 params.window_action = chrome::NavigateParams::SHOW_WINDOW;
196 chrome::Navigate(&params);
[email protected]fc0ed302011-11-29 23:17:19197
198 // The page should not be opened.
meacerc62e2ee2014-10-22 00:44:52199 EXPECT_EQ(browser, params.browser);
[email protected]ee496952013-01-10 23:17:33200 EXPECT_EQ(1, browser->tab_strip_model()->count());
[email protected]8e09c7af2014-06-10 11:46:17201 EXPECT_EQ(GURL(url::kAboutBlankURL),
[email protected]ee496952013-01-10 23:17:33202 browser->tab_strip_model()->GetActiveWebContents()->GetURL());
[email protected]fc0ed302011-11-29 23:17:19203}
204
[email protected]aae79572014-06-13 00:42:58205void BrowserNavigatorTest::SetUpCommandLine(base::CommandLine* command_line) {
206 // Disable settings-in-a-window so that we can use the settings page and
207 // sub-pages to test browser navigation.
208 command_line->AppendSwitch(::switches::kDisableSettingsWindow);
[email protected]aae79572014-06-13 00:42:58209}
210
[email protected]6c2381d2011-10-19 02:52:53211void BrowserNavigatorTest::Observe(
212 int type,
213 const content::NotificationSource& source,
214 const content::NotificationDetails& details) {
thestig1d619242016-06-13 22:24:52215 DCHECK_EQ(content::NOTIFICATION_WEB_CONTENTS_RENDER_VIEW_HOST_CREATED, type);
216 ++created_tab_contents_count_;
[email protected]bd817c22011-02-09 08:16:46217}
[email protected]fa7ebe02010-11-29 23:04:57218
[email protected]ddddfda2011-07-14 23:19:39219
[email protected]bd817c22011-02-09 08:16:46220namespace {
[email protected]a1feae52010-10-11 22:14:45221
[email protected]a1feae52010-10-11 22:14:45222// This test verifies that when a navigation occurs within a tab, the tab count
223// of the Browser remains the same and the current tab bears the loaded URL.
[email protected]59167c22013-06-03 18:07:32224// Note that network URLs are not actually loaded in tests, so this also tests
225// that error pages leave the intended URL in the address bar.
[email protected]a1feae52010-10-11 22:14:45226IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_CurrentTab) {
[email protected]ddddfda2011-07-14 23:19:39227 ui_test_utils::NavigateToURL(browser(), GetGoogleURL());
[email protected]ee496952013-01-10 23:17:33228 EXPECT_EQ(GetGoogleURL(),
229 browser()->tab_strip_model()->GetActiveWebContents()->GetURL());
[email protected]a1feae52010-10-11 22:14:45230 // We should have one window with one tab.
[email protected]0665ebe2013-02-13 09:53:19231 EXPECT_EQ(1u, chrome::GetTotalBrowserCount());
[email protected]ee496952013-01-10 23:17:33232 EXPECT_EQ(1, browser()->tab_strip_model()->count());
[email protected]a1feae52010-10-11 22:14:45233}
234
[email protected]bd817c22011-02-09 08:16:46235// This test verifies that a singleton tab is refocused if one is already opened
[email protected]19d9f3a2010-10-14 21:49:36236// in another or an existing window, or added if it is not.
237IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_SingletonTabExisting) {
[email protected]19d9f3a2010-10-14 21:49:36238 GURL singleton_url1("http://maps.google.com/");
[email protected]fa7ebe02010-11-29 23:04:57239
[email protected]e232c992012-12-06 12:43:20240 // Register for a notification if an additional WebContents was instantiated.
[email protected]bd817c22011-02-09 08:16:46241 // Opening a Singleton tab that is already opened should not be opening a new
[email protected]e232c992012-12-06 12:43:20242 // tab nor be creating a new WebContents object.
[email protected]6c2381d2011-10-19 02:52:53243 content::NotificationRegistrar registrar;
[email protected]fa7ebe02010-11-29 23:04:57244
245 // As the registrar object goes out of scope, this will get unregistered
[email protected]d53a08c2012-07-18 20:35:30246 registrar.Add(this,
247 content::NOTIFICATION_WEB_CONTENTS_RENDER_VIEW_HOST_CREATED,
[email protected]ad50def52011-10-19 23:17:07248 content::NotificationService::AllSources());
[email protected]fa7ebe02010-11-29 23:04:57249
[email protected]52877dbc62012-06-29 22:22:03250 chrome::AddSelectedTabWithURL(browser(), singleton_url1,
Sylvain Defresnec6ccc77d2014-09-19 10:19:35251 ui::PAGE_TRANSITION_LINK);
[email protected]52877dbc62012-06-29 22:22:03252 chrome::AddSelectedTabWithURL(browser(), GetGoogleURL(),
Sylvain Defresnec6ccc77d2014-09-19 10:19:35253 ui::PAGE_TRANSITION_LINK);
[email protected]19d9f3a2010-10-14 21:49:36254
255 // We should have one browser with 3 tabs, the 3rd selected.
[email protected]0665ebe2013-02-13 09:53:19256 EXPECT_EQ(1u, chrome::GetTotalBrowserCount());
[email protected]ee496952013-01-10 23:17:33257 EXPECT_EQ(2, browser()->tab_strip_model()->active_index());
[email protected]19d9f3a2010-10-14 21:49:36258
[email protected]fa7ebe02010-11-29 23:04:57259 unsigned int previous_tab_contents_count =
260 created_tab_contents_count_ = 0;
261
[email protected]19d9f3a2010-10-14 21:49:36262 // Navigate to singleton_url1.
meacerc62e2ee2014-10-22 00:44:52263 chrome::NavigateParams params(MakeNavigateParams());
264 params.disposition = SINGLETON_TAB;
265 params.url = singleton_url1;
266 chrome::Navigate(&params);
[email protected]19d9f3a2010-10-14 21:49:36267
268 // The middle tab should now be selected.
meacerc62e2ee2014-10-22 00:44:52269 EXPECT_EQ(browser(), params.browser);
[email protected]ee496952013-01-10 23:17:33270 EXPECT_EQ(1, browser()->tab_strip_model()->active_index());
[email protected]fa7ebe02010-11-29 23:04:57271
272 // No tab contents should have been created
273 EXPECT_EQ(previous_tab_contents_count,
274 created_tab_contents_count_);
[email protected]19d9f3a2010-10-14 21:49:36275}
276
277IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
[email protected]578c6962011-08-24 22:06:40278 Disposition_SingletonTabRespectingRef) {
279 GURL singleton_ref_url1("http://maps.google.com/#a");
280 GURL singleton_ref_url2("http://maps.google.com/#b");
281 GURL singleton_ref_url3("http://maps.google.com/");
282
[email protected]52877dbc62012-06-29 22:22:03283 chrome::AddSelectedTabWithURL(browser(), singleton_ref_url1,
Sylvain Defresnec6ccc77d2014-09-19 10:19:35284 ui::PAGE_TRANSITION_LINK);
[email protected]578c6962011-08-24 22:06:40285
286 // We should have one browser with 2 tabs, 2nd selected.
[email protected]0665ebe2013-02-13 09:53:19287 EXPECT_EQ(1u, chrome::GetTotalBrowserCount());
[email protected]ee496952013-01-10 23:17:33288 EXPECT_EQ(2, browser()->tab_strip_model()->count());
289 EXPECT_EQ(1, browser()->tab_strip_model()->active_index());
[email protected]578c6962011-08-24 22:06:40290
291 // Navigate to singleton_url2.
meacerc62e2ee2014-10-22 00:44:52292 chrome::NavigateParams params(MakeNavigateParams());
293 params.disposition = SINGLETON_TAB;
294 params.url = singleton_ref_url2;
295 chrome::Navigate(&params);
[email protected]578c6962011-08-24 22:06:40296
297 // We should now have 2 tabs, the 2nd one selected.
meacerc62e2ee2014-10-22 00:44:52298 EXPECT_EQ(browser(), params.browser);
[email protected]ee496952013-01-10 23:17:33299 EXPECT_EQ(2, browser()->tab_strip_model()->count());
300 EXPECT_EQ(1, browser()->tab_strip_model()->active_index());
[email protected]578c6962011-08-24 22:06:40301
302 // Navigate to singleton_url2, but with respect ref set.
meacerc62e2ee2014-10-22 00:44:52303 params = MakeNavigateParams();
304 params.disposition = SINGLETON_TAB;
305 params.url = singleton_ref_url2;
306 params.ref_behavior = chrome::NavigateParams::RESPECT_REF;
307 chrome::Navigate(&params);
[email protected]578c6962011-08-24 22:06:40308
309 // We should now have 3 tabs, the 3th one selected.
meacerc62e2ee2014-10-22 00:44:52310 EXPECT_EQ(browser(), params.browser);
[email protected]ee496952013-01-10 23:17:33311 EXPECT_EQ(3, browser()->tab_strip_model()->count());
312 EXPECT_EQ(2, browser()->tab_strip_model()->active_index());
[email protected]578c6962011-08-24 22:06:40313
314 // Navigate to singleton_url3.
meacerc62e2ee2014-10-22 00:44:52315 params = MakeNavigateParams();
316 params.disposition = SINGLETON_TAB;
317 params.url = singleton_ref_url3;
318 params.ref_behavior = chrome::NavigateParams::RESPECT_REF;
319 chrome::Navigate(&params);
[email protected]578c6962011-08-24 22:06:40320
321 // We should now have 4 tabs, the 4th one selected.
meacerc62e2ee2014-10-22 00:44:52322 EXPECT_EQ(browser(), params.browser);
[email protected]ee496952013-01-10 23:17:33323 EXPECT_EQ(4, browser()->tab_strip_model()->count());
324 EXPECT_EQ(3, browser()->tab_strip_model()->active_index());
[email protected]578c6962011-08-24 22:06:40325}
326
327IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
[email protected]19d9f3a2010-10-14 21:49:36328 Disposition_SingletonTabNoneExisting) {
[email protected]19d9f3a2010-10-14 21:49:36329 GURL singleton_url1("http://maps.google.com/");
330
[email protected]bd817c22011-02-09 08:16:46331 // We should have one browser with 1 tab.
[email protected]0665ebe2013-02-13 09:53:19332 EXPECT_EQ(1u, chrome::GetTotalBrowserCount());
[email protected]ee496952013-01-10 23:17:33333 EXPECT_EQ(0, browser()->tab_strip_model()->active_index());
[email protected]19d9f3a2010-10-14 21:49:36334
335 // Navigate to singleton_url1.
meacerc62e2ee2014-10-22 00:44:52336 chrome::NavigateParams params(MakeNavigateParams());
337 params.disposition = SINGLETON_TAB;
338 params.url = singleton_url1;
339 chrome::Navigate(&params);
[email protected]19d9f3a2010-10-14 21:49:36340
341 // We should now have 2 tabs, the 2nd one selected.
meacerc62e2ee2014-10-22 00:44:52342 EXPECT_EQ(browser(), params.browser);
[email protected]ee496952013-01-10 23:17:33343 EXPECT_EQ(2, browser()->tab_strip_model()->count());
344 EXPECT_EQ(1, browser()->tab_strip_model()->active_index());
[email protected]a1feae52010-10-11 22:14:45345}
346
347// This test verifies that when a navigation results in a foreground tab, the
348// tab count of the Browser increases and the selected tab shifts to the new
349// foreground tab.
350IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_NewForegroundTab) {
[email protected]ee496952013-01-10 23:17:33351 WebContents* old_contents =
352 browser()->tab_strip_model()->GetActiveWebContents();
meacerc62e2ee2014-10-22 00:44:52353 chrome::NavigateParams params(MakeNavigateParams());
354 params.disposition = NEW_FOREGROUND_TAB;
355 chrome::Navigate(&params);
[email protected]ee496952013-01-10 23:17:33356 EXPECT_NE(old_contents,
357 browser()->tab_strip_model()->GetActiveWebContents());
[email protected]e232c992012-12-06 12:43:20358 EXPECT_EQ(browser()->tab_strip_model()->GetActiveWebContents(),
meacerc62e2ee2014-10-22 00:44:52359 params.target_contents);
[email protected]ee496952013-01-10 23:17:33360 EXPECT_EQ(2, browser()->tab_strip_model()->count());
[email protected]a1feae52010-10-11 22:14:45361}
362
363// This test verifies that when a navigation results in a background tab, the
364// tab count of the Browser increases but the selected tab remains the same.
365IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_NewBackgroundTab) {
[email protected]ee496952013-01-10 23:17:33366 WebContents* old_contents =
367 browser()->tab_strip_model()->GetActiveWebContents();
meacerc62e2ee2014-10-22 00:44:52368 chrome::NavigateParams params(MakeNavigateParams());
369 params.disposition = NEW_BACKGROUND_TAB;
370 chrome::Navigate(&params);
[email protected]ee496952013-01-10 23:17:33371 WebContents* new_contents =
372 browser()->tab_strip_model()->GetActiveWebContents();
[email protected]a1feae52010-10-11 22:14:45373 // The selected tab should have remained unchanged, since the new tab was
374 // opened in the background.
375 EXPECT_EQ(old_contents, new_contents);
[email protected]ee496952013-01-10 23:17:33376 EXPECT_EQ(2, browser()->tab_strip_model()->count());
[email protected]a1feae52010-10-11 22:14:45377}
378
379// This test verifies that when a navigation requiring a new foreground tab
380// occurs in a Browser that cannot host multiple tabs, the new foreground tab
381// is created in an existing compatible Browser.
382IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
383 Disposition_IncompatibleWindow_Existing) {
384 // Open a foreground tab in a window that cannot open popups when there is an
385 // existing compatible window somewhere else that they can be opened within.
386 Browser* popup = CreateEmptyBrowserForType(Browser::TYPE_POPUP,
387 browser()->profile());
meacerc62e2ee2014-10-22 00:44:52388 chrome::NavigateParams params(MakeNavigateParams(popup));
389 params.disposition = NEW_FOREGROUND_TAB;
390 chrome::Navigate(&params);
[email protected]a1feae52010-10-11 22:14:45391
392 // Navigate() should have opened the tab in a different browser since the
393 // one we supplied didn't support additional tabs.
meacerc62e2ee2014-10-22 00:44:52394 EXPECT_NE(popup, params.browser);
[email protected]a1feae52010-10-11 22:14:45395
396 // Since browser() is an existing compatible tabbed browser, it should have
397 // opened the tab there.
meacerc62e2ee2014-10-22 00:44:52398 EXPECT_EQ(browser(), params.browser);
[email protected]a1feae52010-10-11 22:14:45399
400 // We should be left with 2 windows, the popup with one tab and the browser()
401 // provided by the framework with two.
[email protected]0665ebe2013-02-13 09:53:19402 EXPECT_EQ(2u, chrome::GetTotalBrowserCount());
[email protected]ee496952013-01-10 23:17:33403 EXPECT_EQ(1, popup->tab_strip_model()->count());
404 EXPECT_EQ(2, browser()->tab_strip_model()->count());
[email protected]a1feae52010-10-11 22:14:45405}
406
407// This test verifies that when a navigation requiring a new foreground tab
408// occurs in a Browser that cannot host multiple tabs and no compatible Browser
409// that can is open, a compatible Browser is created.
410IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
411 Disposition_IncompatibleWindow_NoExisting) {
412 // We want to simulate not being able to find an existing window compatible
413 // with our non-tabbed browser window so Navigate() is forced to create a
414 // new compatible window. Because browser() supplied by the in-process
415 // browser testing framework is compatible with browser()->profile(), we
416 // need a different profile, and creating a popup window with an incognito
417 // profile is a quick and dirty way of achieving this.
418 Browser* popup = CreateEmptyBrowserForType(
[email protected]b35b26b32011-05-05 20:35:14419 Browser::TYPE_POPUP,
420 browser()->profile()->GetOffTheRecordProfile());
meacerc62e2ee2014-10-22 00:44:52421 chrome::NavigateParams params(MakeNavigateParams(popup));
422 params.disposition = NEW_FOREGROUND_TAB;
423 chrome::Navigate(&params);
[email protected]a1feae52010-10-11 22:14:45424
425 // Navigate() should have opened the tab in a different browser since the
426 // one we supplied didn't support additional tabs.
meacerc62e2ee2014-10-22 00:44:52427 EXPECT_NE(popup, params.browser);
[email protected]a1feae52010-10-11 22:14:45428
429 // This time, browser() is _not_ compatible with popup since it is not an
430 // incognito window.
meacerc62e2ee2014-10-22 00:44:52431 EXPECT_NE(browser(), params.browser);
[email protected]a1feae52010-10-11 22:14:45432
433 // We should have three windows, each with one tab:
434 // 1. the browser() provided by the framework (unchanged in this test)
435 // 2. the incognito popup we created originally
436 // 3. the new incognito tabbed browser that was created by Navigate().
[email protected]0665ebe2013-02-13 09:53:19437 EXPECT_EQ(3u, chrome::GetTotalBrowserCount());
[email protected]ee496952013-01-10 23:17:33438 EXPECT_EQ(1, browser()->tab_strip_model()->count());
439 EXPECT_EQ(1, popup->tab_strip_model()->count());
meacerc62e2ee2014-10-22 00:44:52440 EXPECT_EQ(1, params.browser->tab_strip_model()->count());
441 EXPECT_TRUE(params.browser->is_type_tabbed());
[email protected]a1feae52010-10-11 22:14:45442}
443
444// This test verifies that navigating with WindowOpenDisposition = NEW_POPUP
445// from a normal Browser results in a new Browser with TYPE_POPUP.
446IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_NewPopup) {
meacerc62e2ee2014-10-22 00:44:52447 chrome::NavigateParams params(MakeNavigateParams());
448 params.disposition = NEW_POPUP;
449 params.window_bounds = gfx::Rect(0, 0, 200, 200);
[email protected]7d329992011-04-15 18:20:02450 // Wait for new popup to to load and gain focus.
meacerc62e2ee2014-10-22 00:44:52451 ui_test_utils::NavigateToURL(&params);
[email protected]a1feae52010-10-11 22:14:45452
[email protected]7d329992011-04-15 18:20:02453 // Navigate() should have opened a new, focused popup window.
meacerc62e2ee2014-10-22 00:44:52454 EXPECT_NE(browser(), params.browser);
[email protected]50592b52013-05-02 22:26:25455#if 0
456 // TODO(stevenjb): Enable this test. See: crbug.com/79493
meacerc62e2ee2014-10-22 00:44:52457 EXPECT_TRUE(browser->window()->IsActive());
[email protected]50592b52013-05-02 22:26:25458#endif
meacerc62e2ee2014-10-22 00:44:52459 EXPECT_TRUE(params.browser->is_type_popup());
460 EXPECT_FALSE(params.browser->is_app());
[email protected]a1feae52010-10-11 22:14:45461
462 // We should have two windows, the browser() provided by the framework and the
463 // new popup window.
[email protected]0665ebe2013-02-13 09:53:19464 EXPECT_EQ(2u, chrome::GetTotalBrowserCount());
[email protected]ee496952013-01-10 23:17:33465 EXPECT_EQ(1, browser()->tab_strip_model()->count());
meacerc62e2ee2014-10-22 00:44:52466 EXPECT_EQ(1, params.browser->tab_strip_model()->count());
[email protected]a1feae52010-10-11 22:14:45467}
468
469// This test verifies that navigating with WindowOpenDisposition = NEW_POPUP
[email protected]f112b0f2011-05-26 01:53:52470// from a normal Browser results in a new Browser with is_app() true.
471IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_NewPopup_ExtensionId) {
meacerc62e2ee2014-10-22 00:44:52472 chrome::NavigateParams params(MakeNavigateParams());
473 params.disposition = NEW_POPUP;
474 params.extension_app_id = "extensionappid";
475 params.window_bounds = gfx::Rect(0, 0, 200, 200);
[email protected]f112b0f2011-05-26 01:53:52476 // Wait for new popup to to load and gain focus.
meacerc62e2ee2014-10-22 00:44:52477 ui_test_utils::NavigateToURL(&params);
[email protected]f112b0f2011-05-26 01:53:52478
479 // Navigate() should have opened a new, focused popup window.
meacerc62e2ee2014-10-22 00:44:52480 EXPECT_NE(browser(), params.browser);
481 EXPECT_TRUE(params.browser->is_type_popup());
482 EXPECT_TRUE(params.browser->is_app());
[email protected]f112b0f2011-05-26 01:53:52483
484 // We should have two windows, the browser() provided by the framework and the
485 // new popup window.
[email protected]0665ebe2013-02-13 09:53:19486 EXPECT_EQ(2u, chrome::GetTotalBrowserCount());
[email protected]ee496952013-01-10 23:17:33487 EXPECT_EQ(1, browser()->tab_strip_model()->count());
meacerc62e2ee2014-10-22 00:44:52488 EXPECT_EQ(1, params.browser->tab_strip_model()->count());
[email protected]f112b0f2011-05-26 01:53:52489}
490
491// This test verifies that navigating with WindowOpenDisposition = NEW_POPUP
[email protected]300d1e52011-01-19 23:57:57492// from a normal popup results in a new Browser with TYPE_POPUP.
493IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_NewPopupFromPopup) {
494 // Open a popup.
meacerc62e2ee2014-10-22 00:44:52495 chrome::NavigateParams params1(MakeNavigateParams());
496 params1.disposition = NEW_POPUP;
497 params1.window_bounds = gfx::Rect(0, 0, 200, 200);
498 chrome::Navigate(&params1);
[email protected]300d1e52011-01-19 23:57:57499 // Open another popup.
meacerc62e2ee2014-10-22 00:44:52500 chrome::NavigateParams params2(MakeNavigateParams(params1.browser));
501 params2.disposition = NEW_POPUP;
502 params2.window_bounds = gfx::Rect(0, 0, 200, 200);
503 chrome::Navigate(&params2);
[email protected]300d1e52011-01-19 23:57:57504
505 // Navigate() should have opened a new normal popup window.
meacerc62e2ee2014-10-22 00:44:52506 EXPECT_NE(params1.browser, params2.browser);
507 EXPECT_TRUE(params2.browser->is_type_popup());
508 EXPECT_FALSE(params2.browser->is_app());
[email protected]300d1e52011-01-19 23:57:57509
510 // We should have three windows, the browser() provided by the framework,
511 // the first popup window, and the second popup window.
[email protected]0665ebe2013-02-13 09:53:19512 EXPECT_EQ(3u, chrome::GetTotalBrowserCount());
[email protected]ee496952013-01-10 23:17:33513 EXPECT_EQ(1, browser()->tab_strip_model()->count());
meacerc62e2ee2014-10-22 00:44:52514 EXPECT_EQ(1, params1.browser->tab_strip_model()->count());
515 EXPECT_EQ(1, params2.browser->tab_strip_model()->count());
[email protected]300d1e52011-01-19 23:57:57516}
517
518// This test verifies that navigating with WindowOpenDisposition = NEW_POPUP
[email protected]d2202e22014-04-14 20:20:53519// from an app frame results in a new Browser with TYPE_POPUP.
[email protected]a1feae52010-10-11 22:14:45520IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
521 Disposition_NewPopupFromAppWindow) {
[email protected]d2202e22014-04-14 20:20:53522 Browser* app_browser = CreateEmptyBrowserForApp(browser()->profile());
meacerc62e2ee2014-10-22 00:44:52523 chrome::NavigateParams params(MakeNavigateParams(app_browser));
524 params.disposition = NEW_POPUP;
525 params.window_bounds = gfx::Rect(0, 0, 200, 200);
526 chrome::Navigate(&params);
[email protected]a1feae52010-10-11 22:14:45527
528 // Navigate() should have opened a new popup app window.
meacerc62e2ee2014-10-22 00:44:52529 EXPECT_NE(app_browser, params.browser);
530 EXPECT_NE(browser(), params.browser);
531 EXPECT_TRUE(params.browser->is_type_popup());
532 EXPECT_TRUE(params.browser->is_app());
[email protected]a1feae52010-10-11 22:14:45533
534 // We should now have three windows, the app window, the app popup it created,
535 // and the original browser() provided by the framework.
[email protected]0665ebe2013-02-13 09:53:19536 EXPECT_EQ(3u, chrome::GetTotalBrowserCount());
[email protected]ee496952013-01-10 23:17:33537 EXPECT_EQ(1, browser()->tab_strip_model()->count());
538 EXPECT_EQ(1, app_browser->tab_strip_model()->count());
meacerc62e2ee2014-10-22 00:44:52539 EXPECT_EQ(1, params.browser->tab_strip_model()->count());
[email protected]a1feae52010-10-11 22:14:45540}
541
542// This test verifies that navigating with WindowOpenDisposition = NEW_POPUP
[email protected]d2202e22014-04-14 20:20:53543// from an app popup results in a new Browser also of TYPE_POPUP.
[email protected]300d1e52011-01-19 23:57:57544IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
545 Disposition_NewPopupFromAppPopup) {
[email protected]d2202e22014-04-14 20:20:53546 Browser* app_browser = CreateEmptyBrowserForApp(browser()->profile());
[email protected]300d1e52011-01-19 23:57:57547 // Open an app popup.
meacerc62e2ee2014-10-22 00:44:52548 chrome::NavigateParams params1(MakeNavigateParams(app_browser));
549 params1.disposition = NEW_POPUP;
550 params1.window_bounds = gfx::Rect(0, 0, 200, 200);
551 chrome::Navigate(&params1);
[email protected]300d1e52011-01-19 23:57:57552 // Now open another app popup.
meacerc62e2ee2014-10-22 00:44:52553 chrome::NavigateParams params2(MakeNavigateParams(params1.browser));
554 params2.disposition = NEW_POPUP;
555 params2.window_bounds = gfx::Rect(0, 0, 200, 200);
556 chrome::Navigate(&params2);
[email protected]300d1e52011-01-19 23:57:57557
558 // Navigate() should have opened a new popup app window.
meacerc62e2ee2014-10-22 00:44:52559 EXPECT_NE(browser(), params1.browser);
560 EXPECT_NE(params1.browser, params2.browser);
561 EXPECT_TRUE(params2.browser->is_type_popup());
562 EXPECT_TRUE(params2.browser->is_app());
[email protected]300d1e52011-01-19 23:57:57563
564 // We should now have four windows, the app window, the first app popup,
565 // the second app popup, and the original browser() provided by the framework.
[email protected]0665ebe2013-02-13 09:53:19566 EXPECT_EQ(4u, chrome::GetTotalBrowserCount());
[email protected]ee496952013-01-10 23:17:33567 EXPECT_EQ(1, browser()->tab_strip_model()->count());
568 EXPECT_EQ(1, app_browser->tab_strip_model()->count());
meacerc62e2ee2014-10-22 00:44:52569 EXPECT_EQ(1, params1.browser->tab_strip_model()->count());
570 EXPECT_EQ(1, params2.browser->tab_strip_model()->count());
[email protected]300d1e52011-01-19 23:57:57571}
572
573// This test verifies that navigating with WindowOpenDisposition = NEW_POPUP
[email protected]a1feae52010-10-11 22:14:45574// from an extension app tab results in a new Browser with TYPE_APP_POPUP.
575IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
576 Disposition_NewPopupFromExtensionApp) {
577 // TODO(beng): TBD.
578}
579
[email protected]7d329992011-04-15 18:20:02580// This test verifies that navigating with window_action = SHOW_WINDOW_INACTIVE
581// does not focus a new new popup window.
582IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_NewPopupUnfocused) {
meacerc62e2ee2014-10-22 00:44:52583 chrome::NavigateParams params(MakeNavigateParams());
584 params.disposition = NEW_POPUP;
585 params.window_bounds = gfx::Rect(0, 0, 200, 200);
586 params.window_action = chrome::NavigateParams::SHOW_WINDOW_INACTIVE;
[email protected]7d329992011-04-15 18:20:02587 // Wait for new popup to load (and gain focus if the test fails).
meacerc62e2ee2014-10-22 00:44:52588 ui_test_utils::NavigateToURL(&params);
[email protected]7d329992011-04-15 18:20:02589
590 // Navigate() should have opened a new, unfocused, popup window.
meacerc62e2ee2014-10-22 00:44:52591 EXPECT_NE(browser(), params.browser);
592 EXPECT_EQ(Browser::TYPE_POPUP, params.browser->type());
[email protected]9db263a2011-04-15 20:53:47593#if 0
594// TODO(stevenjb): Enable this test. See: crbug.com/79493
[email protected]7d329992011-04-15 18:20:02595 EXPECT_FALSE(p.browser->window()->IsActive());
[email protected]7d329992011-04-15 18:20:02596#endif
[email protected]9db263a2011-04-15 20:53:47597}
[email protected]7d329992011-04-15 18:20:02598
[email protected]d2202e22014-04-14 20:20:53599// This test verifies that navigating with WindowOpenDisposition = NEW_POPUP
600// and trusted_source = true results in a new Browser where is_trusted_source()
601// is true.
602IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_NewPopupTrusted) {
meacerc62e2ee2014-10-22 00:44:52603 chrome::NavigateParams params(MakeNavigateParams());
604 params.disposition = NEW_POPUP;
605 params.trusted_source = true;
606 params.window_bounds = gfx::Rect(0, 0, 200, 200);
[email protected]d2202e22014-04-14 20:20:53607 // Wait for new popup to to load and gain focus.
meacerc62e2ee2014-10-22 00:44:52608 ui_test_utils::NavigateToURL(&params);
[email protected]d2202e22014-04-14 20:20:53609
610 // Navigate() should have opened a new popup window of TYPE_TRUSTED_POPUP.
meacerc62e2ee2014-10-22 00:44:52611 EXPECT_NE(browser(), params.browser);
612 EXPECT_TRUE(params.browser->is_type_popup());
613 EXPECT_TRUE(params.browser->is_trusted_source());
[email protected]d2202e22014-04-14 20:20:53614}
615
616
[email protected]a1feae52010-10-11 22:14:45617// This test verifies that navigating with WindowOpenDisposition = NEW_WINDOW
618// always opens a new window.
619IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_NewWindow) {
meacerc62e2ee2014-10-22 00:44:52620 chrome::NavigateParams params(MakeNavigateParams());
621 params.disposition = NEW_WINDOW;
622 chrome::Navigate(&params);
[email protected]a1feae52010-10-11 22:14:45623
624 // Navigate() should have opened a new toplevel window.
meacerc62e2ee2014-10-22 00:44:52625 EXPECT_NE(browser(), params.browser);
626 EXPECT_TRUE(params.browser->is_type_tabbed());
[email protected]a1feae52010-10-11 22:14:45627
628 // We should now have two windows, the browser() provided by the framework and
629 // the new normal window.
[email protected]0665ebe2013-02-13 09:53:19630 EXPECT_EQ(2u, chrome::GetTotalBrowserCount());
[email protected]ee496952013-01-10 23:17:33631 EXPECT_EQ(1, browser()->tab_strip_model()->count());
meacerc62e2ee2014-10-22 00:44:52632 EXPECT_EQ(1, params.browser->tab_strip_model()->count());
[email protected]a1feae52010-10-11 22:14:45633}
634
635// This test verifies that navigating with WindowOpenDisposition = INCOGNITO
636// opens a new incognito window if no existing incognito window is present.
637IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_Incognito) {
meacerc62e2ee2014-10-22 00:44:52638 chrome::NavigateParams params(MakeNavigateParams());
639 params.disposition = OFF_THE_RECORD;
640 chrome::Navigate(&params);
[email protected]a1feae52010-10-11 22:14:45641
642 // Navigate() should have opened a new toplevel incognito window.
meacerc62e2ee2014-10-22 00:44:52643 EXPECT_NE(browser(), params.browser);
[email protected]a1feae52010-10-11 22:14:45644 EXPECT_EQ(browser()->profile()->GetOffTheRecordProfile(),
meacerc62e2ee2014-10-22 00:44:52645 params.browser->profile());
[email protected]a1feae52010-10-11 22:14:45646
[email protected]d7ff3592010-11-30 21:50:46647 // |source_contents| should be set to NULL because the profile for the new
648 // page is different from the originating page.
meacerc62e2ee2014-10-22 00:44:52649 EXPECT_EQ(NULL, params.source_contents);
[email protected]d7ff3592010-11-30 21:50:46650
[email protected]a1feae52010-10-11 22:14:45651 // We should now have two windows, the browser() provided by the framework and
652 // the new incognito window.
[email protected]0665ebe2013-02-13 09:53:19653 EXPECT_EQ(2u, chrome::GetTotalBrowserCount());
[email protected]ee496952013-01-10 23:17:33654 EXPECT_EQ(1, browser()->tab_strip_model()->count());
meacerc62e2ee2014-10-22 00:44:52655 EXPECT_EQ(1, params.browser->tab_strip_model()->count());
[email protected]a1feae52010-10-11 22:14:45656}
657
658// This test verifies that navigating with WindowOpenDisposition = INCOGNITO
659// reuses an existing incognito window when possible.
660IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_IncognitoRefocus) {
661 Browser* incognito_browser =
[email protected]b35b26b32011-05-05 20:35:14662 CreateEmptyBrowserForType(Browser::TYPE_TABBED,
[email protected]a1feae52010-10-11 22:14:45663 browser()->profile()->GetOffTheRecordProfile());
meacerc62e2ee2014-10-22 00:44:52664 chrome::NavigateParams params(MakeNavigateParams());
665 params.disposition = OFF_THE_RECORD;
666 chrome::Navigate(&params);
[email protected]a1feae52010-10-11 22:14:45667
668 // Navigate() should have opened a new tab in the existing incognito window.
meacerc62e2ee2014-10-22 00:44:52669 EXPECT_NE(browser(), params.browser);
670 EXPECT_EQ(params.browser, incognito_browser);
[email protected]a1feae52010-10-11 22:14:45671
672 // We should now have two windows, the browser() provided by the framework and
673 // the incognito window we opened earlier.
[email protected]0665ebe2013-02-13 09:53:19674 EXPECT_EQ(2u, chrome::GetTotalBrowserCount());
[email protected]ee496952013-01-10 23:17:33675 EXPECT_EQ(1, browser()->tab_strip_model()->count());
676 EXPECT_EQ(2, incognito_browser->tab_strip_model()->count());
[email protected]a1feae52010-10-11 22:14:45677}
678
679// This test verifies that no navigation action occurs when
680// WindowOpenDisposition = SUPPRESS_OPEN.
681IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_SuppressOpen) {
682 RunSuppressTest(SUPPRESS_OPEN);
683}
684
685// This test verifies that no navigation action occurs when
686// WindowOpenDisposition = SAVE_TO_DISK.
687IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_SaveToDisk) {
688 RunSuppressTest(SAVE_TO_DISK);
689}
690
691// This test verifies that no navigation action occurs when
692// WindowOpenDisposition = IGNORE_ACTION.
693IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_IgnoreAction) {
694 RunSuppressTest(IGNORE_ACTION);
695}
696
[email protected]e232c992012-12-06 12:43:20697// This tests adding a foreground tab with a predefined WebContents.
[email protected]a1feae52010-10-11 22:14:45698IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, TargetContents_ForegroundTab) {
meacerc62e2ee2014-10-22 00:44:52699 chrome::NavigateParams params(MakeNavigateParams());
700 params.disposition = NEW_FOREGROUND_TAB;
lof84501da082016-05-23 21:22:54701 params.target_contents = CreateWebContents(false);
meacerc62e2ee2014-10-22 00:44:52702 chrome::Navigate(&params);
[email protected]a1feae52010-10-11 22:14:45703
lof84501da082016-05-23 21:22:54704 // Navigate() should have opened the contents in a new foreground tab in the
[email protected]a1feae52010-10-11 22:14:45705 // current Browser.
meacerc62e2ee2014-10-22 00:44:52706 EXPECT_EQ(browser(), params.browser);
[email protected]e232c992012-12-06 12:43:20707 EXPECT_EQ(browser()->tab_strip_model()->GetActiveWebContents(),
meacerc62e2ee2014-10-22 00:44:52708 params.target_contents);
[email protected]a1feae52010-10-11 22:14:45709
710 // We should have one window, with two tabs.
[email protected]0665ebe2013-02-13 09:53:19711 EXPECT_EQ(1u, chrome::GetTotalBrowserCount());
[email protected]ee496952013-01-10 23:17:33712 EXPECT_EQ(2, browser()->tab_strip_model()->count());
[email protected]a1feae52010-10-11 22:14:45713}
714
715#if defined(OS_WIN)
[email protected]e232c992012-12-06 12:43:20716// This tests adding a popup with a predefined WebContents.
[email protected]76edb672011-03-04 21:48:39717IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, DISABLED_TargetContents_Popup) {
meacerc62e2ee2014-10-22 00:44:52718 chrome::NavigateParams params(MakeNavigateParams());
719 params.disposition = NEW_POPUP;
lof84501da082016-05-23 21:22:54720 params.target_contents = CreateWebContents(false);
meacerc62e2ee2014-10-22 00:44:52721 params.window_bounds = gfx::Rect(10, 10, 500, 500);
722 chrome::Navigate(&params);
[email protected]a1feae52010-10-11 22:14:45723
724 // Navigate() should have opened a new popup window.
meacerc62e2ee2014-10-22 00:44:52725 EXPECT_NE(browser(), params.browser);
726 EXPECT_TRUE(params.browser->is_type_popup());
727 EXPECT_FALSE(params.browser->is_app());
[email protected]a1feae52010-10-11 22:14:45728
729 // The web platform is weird. The window bounds specified in
meacerc62e2ee2014-10-22 00:44:52730 // |params.window_bounds| are used as follows:
[email protected]a1feae52010-10-11 22:14:45731 // - the origin is used to position the window
[email protected]e232c992012-12-06 12:43:20732 // - the size is used to size the WebContents of the window.
[email protected]a1feae52010-10-11 22:14:45733 // As such the position of the resulting window will always match
meacerc62e2ee2014-10-22 00:44:52734 // params.window_bounds.origin(), but its size will not. We need to match
[email protected]a1feae52010-10-11 22:14:45735 // the size against the selected tab's view's container size.
meacerc62e2ee2014-10-22 00:44:52736 // Only Windows positions the window according to
737 // |params.window_bounds.origin()| - on Mac the window is offset from the
738 // opener and on Linux it always opens at 0,0.
739 EXPECT_EQ(params.window_bounds.origin(),
740 params.browser->window()->GetRestoredBounds().origin());
[email protected]a1feae52010-10-11 22:14:45741 // All platforms should respect size however provided width > 400 (Mac has a
742 // minimum window width of 400).
meacerc62e2ee2014-10-22 00:44:52743 EXPECT_EQ(params.window_bounds.size(),
744 params.target_contents->GetContainerBounds().size());
[email protected]a1feae52010-10-11 22:14:45745
746 // We should have two windows, the new popup and the browser() provided by the
747 // framework.
[email protected]0665ebe2013-02-13 09:53:19748 EXPECT_EQ(2u, chrome::GetTotalBrowserCount());
[email protected]ee496952013-01-10 23:17:33749 EXPECT_EQ(1, browser()->tab_strip_model()->count());
meacerc62e2ee2014-10-22 00:44:52750 EXPECT_EQ(1, params.browser->tab_strip_model()->count());
[email protected]a1feae52010-10-11 22:14:45751}
752#endif
753
lof84501da082016-05-23 21:22:54754// This test checks that we can create WebContents with renderer process and
755// RenderFrame without navigating it.
756IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
757 CreateWebContentsWithRendererProcess) {
758 chrome::NavigateParams params(MakeNavigateParams());
759 params.disposition = NEW_FOREGROUND_TAB;
760 params.target_contents = CreateWebContents(true);
761 ASSERT_TRUE(params.target_contents);
762
763 // There is no navigation (to about:blank or something like that).
764 EXPECT_FALSE(params.target_contents->IsLoading());
765
766 ASSERT_TRUE(params.target_contents->GetMainFrame());
767 EXPECT_TRUE(params.target_contents->GetMainFrame()->IsRenderFrameLive());
768 EXPECT_TRUE(
769 params.target_contents->GetController().IsInitialBlankNavigation());
770 int renderer_id = params.target_contents->GetRenderProcessHost()->GetID();
771
772 // We should have one window, with one tab of WebContents differ from
773 // params.target_contents.
774 EXPECT_EQ(1u, chrome::GetTotalBrowserCount());
775 EXPECT_EQ(1, browser()->tab_strip_model()->count());
776 EXPECT_NE(browser()->tab_strip_model()->GetActiveWebContents(),
777 params.target_contents);
778
779 chrome::Navigate(&params);
780
781 // Navigate() should have opened the contents in a new foreground tab in the
782 // current Browser, without changing the renderer process of target_contents.
783 EXPECT_EQ(browser(), params.browser);
784 EXPECT_EQ(browser()->tab_strip_model()->GetActiveWebContents(),
785 params.target_contents);
786 EXPECT_EQ(renderer_id,
787 params.target_contents->GetRenderProcessHost()->GetID());
788
789 // We should have one window, with two tabs.
790 EXPECT_EQ(1u, chrome::GetTotalBrowserCount());
791 EXPECT_EQ(2, browser()->tab_strip_model()->count());
792}
793
[email protected]a1feae52010-10-11 22:14:45794// This tests adding a tab at a specific index.
795IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Tabstrip_InsertAtIndex) {
796 // This is not meant to be a comprehensive test of whether or not the tab
797 // implementation of the browser observes the insertion index. That is
798 // covered by the unit tests for TabStripModel. This merely verifies that
799 // insertion index preference is reflected in common cases.
meacerc62e2ee2014-10-22 00:44:52800 chrome::NavigateParams params(MakeNavigateParams());
801 params.disposition = NEW_FOREGROUND_TAB;
802 params.tabstrip_index = 0;
803 params.tabstrip_add_types = TabStripModel::ADD_FORCE_INDEX;
804 chrome::Navigate(&params);
[email protected]a1feae52010-10-11 22:14:45805
806 // Navigate() should have inserted a new tab at slot 0 in the tabstrip.
meacerc62e2ee2014-10-22 00:44:52807 EXPECT_EQ(browser(), params.browser);
[email protected]e232c992012-12-06 12:43:20808 EXPECT_EQ(0, browser()->tab_strip_model()->GetIndexOfWebContents(
meacerc62e2ee2014-10-22 00:44:52809 static_cast<const WebContents*>(params.target_contents)));
[email protected]a1feae52010-10-11 22:14:45810
811 // We should have one window - the browser() provided by the framework.
[email protected]0665ebe2013-02-13 09:53:19812 EXPECT_EQ(1u, chrome::GetTotalBrowserCount());
[email protected]ee496952013-01-10 23:17:33813 EXPECT_EQ(2, browser()->tab_strip_model()->count());
[email protected]a1feae52010-10-11 22:14:45814}
815
[email protected]bb89e7482010-11-17 18:27:04816// This test verifies that constructing params with disposition = SINGLETON_TAB
[email protected]fee320542011-03-02 01:30:49817// and IGNORE_AND_NAVIGATE opens a new tab navigated to the specified URL if
[email protected]67ed83e2011-01-07 22:54:00818// no previous tab with that URL (minus the path) exists.
[email protected]bb89e7482010-11-17 18:27:04819IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
820 Disposition_SingletonTabNew_IgnorePath) {
[email protected]52877dbc62012-06-29 22:22:03821 chrome::AddSelectedTabWithURL(browser(), GetGoogleURL(),
Sylvain Defresnec6ccc77d2014-09-19 10:19:35822 ui::PAGE_TRANSITION_LINK);
[email protected]bb89e7482010-11-17 18:27:04823
824 // We should have one browser with 2 tabs, the 2nd selected.
[email protected]0665ebe2013-02-13 09:53:19825 EXPECT_EQ(1u, chrome::GetTotalBrowserCount());
[email protected]ee496952013-01-10 23:17:33826 EXPECT_EQ(2, browser()->tab_strip_model()->count());
827 EXPECT_EQ(1, browser()->tab_strip_model()->active_index());
[email protected]bb89e7482010-11-17 18:27:04828
829 // Navigate to a new singleton tab with a sub-page.
meacerc62e2ee2014-10-22 00:44:52830 chrome::NavigateParams params(MakeNavigateParams());
831 params.disposition = SINGLETON_TAB;
832 params.url = GetContentSettingsURL();
833 params.window_action = chrome::NavigateParams::SHOW_WINDOW;
834 params.path_behavior = chrome::NavigateParams::IGNORE_AND_NAVIGATE;
835 chrome::Navigate(&params);
[email protected]bb89e7482010-11-17 18:27:04836
837 // The last tab should now be selected and navigated to the sub-page of the
[email protected]50592b52013-05-02 22:26:25838 // URL.
meacerc62e2ee2014-10-22 00:44:52839 EXPECT_EQ(browser(), params.browser);
[email protected]ee496952013-01-10 23:17:33840 EXPECT_EQ(3, browser()->tab_strip_model()->count());
841 EXPECT_EQ(2, browser()->tab_strip_model()->active_index());
[email protected]a048ad22012-03-23 04:26:56842 EXPECT_EQ(GetContentSettingsURL(),
[email protected]ee496952013-01-10 23:17:33843 ShortenUberURL(browser()->tab_strip_model()->
844 GetActiveWebContents()->GetURL()));
[email protected]bb89e7482010-11-17 18:27:04845}
846
847// This test verifies that constructing params with disposition = SINGLETON_TAB
[email protected]fee320542011-03-02 01:30:49848// and IGNORE_AND_NAVIGATE opens an existing tab with the matching URL (minus
[email protected]bb89e7482010-11-17 18:27:04849// the path) which is navigated to the specified URL.
850IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
851 Disposition_SingletonTabExisting_IgnorePath) {
[email protected]ddddfda2011-07-14 23:19:39852 GURL singleton_url1(GetSettingsURL());
[email protected]52877dbc62012-06-29 22:22:03853 chrome::AddSelectedTabWithURL(browser(), singleton_url1,
Sylvain Defresnec6ccc77d2014-09-19 10:19:35854 ui::PAGE_TRANSITION_LINK);
[email protected]52877dbc62012-06-29 22:22:03855 chrome::AddSelectedTabWithURL(browser(), GetGoogleURL(),
Sylvain Defresnec6ccc77d2014-09-19 10:19:35856 ui::PAGE_TRANSITION_LINK);
[email protected]bb89e7482010-11-17 18:27:04857
858 // We should have one browser with 3 tabs, the 3rd selected.
[email protected]0665ebe2013-02-13 09:53:19859 EXPECT_EQ(1u, chrome::GetTotalBrowserCount());
[email protected]ee496952013-01-10 23:17:33860 EXPECT_EQ(3, browser()->tab_strip_model()->count());
861 EXPECT_EQ(2, browser()->tab_strip_model()->active_index());
[email protected]bb89e7482010-11-17 18:27:04862
863 // Navigate to singleton_url1.
meacerc62e2ee2014-10-22 00:44:52864 chrome::NavigateParams params(MakeNavigateParams());
865 params.disposition = SINGLETON_TAB;
866 params.url = GetContentSettingsURL();
867 params.window_action = chrome::NavigateParams::SHOW_WINDOW;
868 params.path_behavior = chrome::NavigateParams::IGNORE_AND_NAVIGATE;
869 chrome::Navigate(&params);
[email protected]bb89e7482010-11-17 18:27:04870
871 // The middle tab should now be selected and navigated to the sub-page of the
872 // URL.
meacerc62e2ee2014-10-22 00:44:52873 EXPECT_EQ(browser(), params.browser);
[email protected]ee496952013-01-10 23:17:33874 EXPECT_EQ(3, browser()->tab_strip_model()->count());
875 EXPECT_EQ(1, browser()->tab_strip_model()->active_index());
[email protected]a048ad22012-03-23 04:26:56876 EXPECT_EQ(GetContentSettingsURL(),
[email protected]ee496952013-01-10 23:17:33877 ShortenUberURL(browser()->tab_strip_model()->
878 GetActiveWebContents()->GetURL()));
[email protected]bb89e7482010-11-17 18:27:04879}
880
881// This test verifies that constructing params with disposition = SINGLETON_TAB
[email protected]fee320542011-03-02 01:30:49882// and IGNORE_AND_NAVIGATE opens an existing tab with the matching URL (minus
[email protected]bb89e7482010-11-17 18:27:04883// the path) which is navigated to the specified URL.
884IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
885 Disposition_SingletonTabExistingSubPath_IgnorePath) {
[email protected]a048ad22012-03-23 04:26:56886 GURL singleton_url1(GetContentSettingsURL());
[email protected]52877dbc62012-06-29 22:22:03887 chrome::AddSelectedTabWithURL(browser(), singleton_url1,
Sylvain Defresnec6ccc77d2014-09-19 10:19:35888 ui::PAGE_TRANSITION_LINK);
[email protected]52877dbc62012-06-29 22:22:03889 chrome::AddSelectedTabWithURL(browser(), GetGoogleURL(),
Sylvain Defresnec6ccc77d2014-09-19 10:19:35890 ui::PAGE_TRANSITION_LINK);
[email protected]bb89e7482010-11-17 18:27:04891
892 // We should have one browser with 3 tabs, the 3rd selected.
[email protected]0665ebe2013-02-13 09:53:19893 EXPECT_EQ(1u, chrome::GetTotalBrowserCount());
[email protected]ee496952013-01-10 23:17:33894 EXPECT_EQ(3, browser()->tab_strip_model()->count());
895 EXPECT_EQ(2, browser()->tab_strip_model()->active_index());
[email protected]bb89e7482010-11-17 18:27:04896
897 // Navigate to singleton_url1.
meacerc62e2ee2014-10-22 00:44:52898 chrome::NavigateParams params(MakeNavigateParams());
899 params.disposition = SINGLETON_TAB;
900 params.url = GetClearBrowsingDataURL();
901 params.window_action = chrome::NavigateParams::SHOW_WINDOW;
902 params.path_behavior = chrome::NavigateParams::IGNORE_AND_NAVIGATE;
903 chrome::Navigate(&params);
[email protected]bb89e7482010-11-17 18:27:04904
905 // The middle tab should now be selected and navigated to the sub-page of the
906 // URL.
meacerc62e2ee2014-10-22 00:44:52907 EXPECT_EQ(browser(), params.browser);
[email protected]ee496952013-01-10 23:17:33908 EXPECT_EQ(3, browser()->tab_strip_model()->count());
909 EXPECT_EQ(1, browser()->tab_strip_model()->active_index());
[email protected]a048ad22012-03-23 04:26:56910 EXPECT_EQ(GetClearBrowsingDataURL(),
[email protected]ee496952013-01-10 23:17:33911 ShortenUberURL(browser()->tab_strip_model()->
912 GetActiveWebContents()->GetURL()));
[email protected]bb89e7482010-11-17 18:27:04913}
[email protected]2dd85482010-11-06 01:56:47914
[email protected]637b3442011-01-10 23:31:48915// This test verifies that constructing params with disposition = SINGLETON_TAB
[email protected]fee320542011-03-02 01:30:49916// and IGNORE_AND_STAY_PUT opens an existing tab with the matching URL (minus
917// the path).
918IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
919 Disposition_SingletonTabExistingSubPath_IgnorePath2) {
[email protected]a048ad22012-03-23 04:26:56920 GURL singleton_url1(GetContentSettingsURL());
[email protected]52877dbc62012-06-29 22:22:03921 chrome::AddSelectedTabWithURL(browser(), singleton_url1,
Sylvain Defresnec6ccc77d2014-09-19 10:19:35922 ui::PAGE_TRANSITION_LINK);
[email protected]52877dbc62012-06-29 22:22:03923 chrome::AddSelectedTabWithURL(browser(), GetGoogleURL(),
Sylvain Defresnec6ccc77d2014-09-19 10:19:35924 ui::PAGE_TRANSITION_LINK);
[email protected]fee320542011-03-02 01:30:49925
926 // We should have one browser with 3 tabs, the 3rd selected.
[email protected]0665ebe2013-02-13 09:53:19927 EXPECT_EQ(1u, chrome::GetTotalBrowserCount());
[email protected]ee496952013-01-10 23:17:33928 EXPECT_EQ(3, browser()->tab_strip_model()->count());
929 EXPECT_EQ(2, browser()->tab_strip_model()->active_index());
[email protected]fee320542011-03-02 01:30:49930
931 // Navigate to singleton_url1.
meacerc62e2ee2014-10-22 00:44:52932 chrome::NavigateParams params(MakeNavigateParams());
933 params.disposition = SINGLETON_TAB;
934 params.url = GetClearBrowsingDataURL();
935 params.window_action = chrome::NavigateParams::SHOW_WINDOW;
936 params.path_behavior = chrome::NavigateParams::IGNORE_AND_STAY_PUT;
937 chrome::Navigate(&params);
[email protected]fee320542011-03-02 01:30:49938
939 // The middle tab should now be selected.
meacerc62e2ee2014-10-22 00:44:52940 EXPECT_EQ(browser(), params.browser);
[email protected]ee496952013-01-10 23:17:33941 EXPECT_EQ(3, browser()->tab_strip_model()->count());
942 EXPECT_EQ(1, browser()->tab_strip_model()->active_index());
[email protected]fee320542011-03-02 01:30:49943 EXPECT_EQ(singleton_url1,
[email protected]ee496952013-01-10 23:17:33944 ShortenUberURL(browser()->tab_strip_model()->
945 GetActiveWebContents()->GetURL()));
[email protected]fee320542011-03-02 01:30:49946}
947
948// This test verifies that constructing params with disposition = SINGLETON_TAB
949// and IGNORE_AND_NAVIGATE will update the current tab's URL if the currently
[email protected]637b3442011-01-10 23:31:48950// selected tab is a match but has a different path.
951IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
952 Disposition_SingletonTabFocused_IgnorePath) {
[email protected]a048ad22012-03-23 04:26:56953 GURL singleton_url_current(GetContentSettingsURL());
[email protected]52877dbc62012-06-29 22:22:03954 chrome::AddSelectedTabWithURL(browser(), singleton_url_current,
Sylvain Defresnec6ccc77d2014-09-19 10:19:35955 ui::PAGE_TRANSITION_LINK);
[email protected]637b3442011-01-10 23:31:48956
957 // We should have one browser with 2 tabs, the 2nd selected.
[email protected]0665ebe2013-02-13 09:53:19958 EXPECT_EQ(1u, chrome::GetTotalBrowserCount());
[email protected]ee496952013-01-10 23:17:33959 EXPECT_EQ(2, browser()->tab_strip_model()->count());
960 EXPECT_EQ(1, browser()->tab_strip_model()->active_index());
[email protected]637b3442011-01-10 23:31:48961
962 // Navigate to a different settings path.
[email protected]a048ad22012-03-23 04:26:56963 GURL singleton_url_target(GetClearBrowsingDataURL());
meacerc62e2ee2014-10-22 00:44:52964 chrome::NavigateParams params(MakeNavigateParams());
965 params.disposition = SINGLETON_TAB;
966 params.url = singleton_url_target;
967 params.window_action = chrome::NavigateParams::SHOW_WINDOW;
968 params.path_behavior = chrome::NavigateParams::IGNORE_AND_NAVIGATE;
969 chrome::Navigate(&params);
[email protected]637b3442011-01-10 23:31:48970
971 // The second tab should still be selected, but navigated to the new path.
meacerc62e2ee2014-10-22 00:44:52972 EXPECT_EQ(browser(), params.browser);
[email protected]ee496952013-01-10 23:17:33973 EXPECT_EQ(2, browser()->tab_strip_model()->count());
974 EXPECT_EQ(1, browser()->tab_strip_model()->active_index());
[email protected]637b3442011-01-10 23:31:48975 EXPECT_EQ(singleton_url_target,
[email protected]ee496952013-01-10 23:17:33976 ShortenUberURL(browser()->tab_strip_model()->
977 GetActiveWebContents()->GetURL()));
[email protected]637b3442011-01-10 23:31:48978}
979
[email protected]07afd7c2011-02-17 10:07:11980// This test verifies that constructing params with disposition = SINGLETON_TAB
[email protected]fee320542011-03-02 01:30:49981// and IGNORE_AND_NAVIGATE will open an existing matching tab with a different
982// query.
[email protected]07afd7c2011-02-17 10:07:11983IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
984 Disposition_SingletonTabExisting_IgnoreQuery) {
[email protected]ee496952013-01-10 23:17:33985 int initial_tab_count = browser()->tab_strip_model()->count();
[email protected]07afd7c2011-02-17 10:07:11986 GURL singleton_url_current("chrome://settings/internet");
[email protected]52877dbc62012-06-29 22:22:03987 chrome::AddSelectedTabWithURL(browser(), singleton_url_current,
Sylvain Defresnec6ccc77d2014-09-19 10:19:35988 ui::PAGE_TRANSITION_LINK);
[email protected]07afd7c2011-02-17 10:07:11989
[email protected]ee496952013-01-10 23:17:33990 EXPECT_EQ(initial_tab_count + 1, browser()->tab_strip_model()->count());
991 EXPECT_EQ(initial_tab_count, browser()->tab_strip_model()->active_index());
[email protected]07afd7c2011-02-17 10:07:11992
993 // Navigate to a different settings path.
994 GURL singleton_url_target(
995 "chrome://settings/internet?"
stevenjb82dbc53092015-03-14 18:32:24996 "guid=ethernet_00aa00aa00aa&networkType=1");
meacerc62e2ee2014-10-22 00:44:52997 chrome::NavigateParams params(MakeNavigateParams());
998 params.disposition = SINGLETON_TAB;
999 params.url = singleton_url_target;
1000 params.window_action = chrome::NavigateParams::SHOW_WINDOW;
1001 params.path_behavior = chrome::NavigateParams::IGNORE_AND_NAVIGATE;
1002 chrome::Navigate(&params);
[email protected]07afd7c2011-02-17 10:07:111003
1004 // Last tab should still be selected.
meacerc62e2ee2014-10-22 00:44:521005 EXPECT_EQ(browser(), params.browser);
[email protected]ee496952013-01-10 23:17:331006 EXPECT_EQ(initial_tab_count + 1, browser()->tab_strip_model()->count());
1007 EXPECT_EQ(initial_tab_count, browser()->tab_strip_model()->active_index());
[email protected]07afd7c2011-02-17 10:07:111008}
1009
[email protected]bd817c22011-02-09 08:16:461010// This test verifies that the settings page isn't opened in the incognito
1011// window.
[email protected]a048ad22012-03-23 04:26:561012// Disabled until fixed for uber settings: http://crbug.com/111243
[email protected]bd817c22011-02-09 08:16:461013IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
[email protected]a048ad22012-03-23 04:26:561014 DISABLED_Disposition_Settings_UseNonIncognitoWindow) {
[email protected]fc0ed302011-11-29 23:17:191015 RunUseNonIncognitoWindowTest(GetSettingsURL());
[email protected]bd817c22011-02-09 08:16:461016}
1017
[email protected]429e9712013-04-30 09:35:501018// This test verifies that the view-source settings page isn't opened in the
1019// incognito window.
1020IN_PROC_BROWSER_TEST_F(
1021 BrowserNavigatorTest,
1022 Disposition_ViewSource_Settings_DoNothingIfIncognitoForced) {
[email protected]dbdda5402013-05-30 22:13:481023 std::string view_source(content::kViewSourceScheme);
[email protected]429e9712013-04-30 09:35:501024 view_source.append(":");
1025 view_source.append(chrome::kChromeUISettingsURL);
1026 RunDoNothingIfIncognitoIsForcedTest(GURL(view_source));
1027}
1028
1029// This test verifies that the view-source settings page isn't opened in the
1030// incognito window even if incognito mode is forced (does nothing in that
1031// case).
1032IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
1033 Disposition_ViewSource_Settings_UseNonIncognitoWindow) {
[email protected]dbdda5402013-05-30 22:13:481034 std::string view_source(content::kViewSourceScheme);
[email protected]429e9712013-04-30 09:35:501035 view_source.append(":");
1036 view_source.append(chrome::kChromeUISettingsURL);
1037 RunUseNonIncognitoWindowTest(GURL(view_source));
1038}
1039
[email protected]82404cd2011-07-12 19:55:141040// This test verifies that the settings page isn't opened in the incognito
1041// window from a non-incognito window (bookmark open-in-incognito trigger).
[email protected]a048ad22012-03-23 04:26:561042// Disabled until fixed for uber settings: http://crbug.com/111243
[email protected]82404cd2011-07-12 19:55:141043IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
[email protected]a048ad22012-03-23 04:26:561044 DISABLED_Disposition_Settings_UseNonIncognitoWindowForBookmark) {
[email protected]78e2edc2012-07-01 23:32:281045 chrome::NavigateParams params(browser(), GetSettingsURL(),
Sylvain Defresnec6ccc77d2014-09-19 10:19:351046 ui::PAGE_TRANSITION_AUTO_BOOKMARK);
[email protected]82404cd2011-07-12 19:55:141047 params.disposition = OFF_THE_RECORD;
1048 {
[email protected]a7fe9112012-07-20 02:34:451049 content::WindowedNotificationObserver observer(
[email protected]ad50def52011-10-19 23:17:071050 content::NOTIFICATION_LOAD_STOP,
1051 content::NotificationService::AllSources());
[email protected]78e2edc2012-07-01 23:32:281052 chrome::Navigate(&params);
[email protected]82404cd2011-07-12 19:55:141053 observer.Wait();
1054 }
1055
[email protected]0665ebe2013-02-13 09:53:191056 EXPECT_EQ(1u, chrome::GetTotalBrowserCount());
[email protected]52877dbc62012-06-29 22:22:031057 EXPECT_EQ(GetSettingsURL(),
[email protected]ee496952013-01-10 23:17:331058 ShortenUberURL(browser()->tab_strip_model()->
1059 GetActiveWebContents()->GetURL()));
[email protected]82404cd2011-07-12 19:55:141060}
1061
[email protected]93ad8e1c2011-11-08 21:34:051062// Settings page is expected to always open in normal mode regardless
1063// of whether the user is trying to open it in incognito mode or not.
1064// This test verifies that if incognito mode is forced (by policy), settings
1065// page doesn't open at all.
[email protected]a048ad22012-03-23 04:26:561066// Disabled until fixed for uber settings: http://crbug.com/111243
[email protected]93ad8e1c2011-11-08 21:34:051067IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
[email protected]a048ad22012-03-23 04:26:561068 DISABLED_Disposition_Settings_DoNothingIfIncognitoIsForced) {
[email protected]fc0ed302011-11-29 23:17:191069 RunDoNothingIfIncognitoIsForcedTest(GetSettingsURL());
[email protected]93ad8e1c2011-11-08 21:34:051070}
1071
[email protected]bd817c22011-02-09 08:16:461072// This test verifies that the bookmarks page isn't opened in the incognito
1073// window.
1074IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
1075 Disposition_Bookmarks_UseNonIncognitoWindow) {
[email protected]fc0ed302011-11-29 23:17:191076 RunUseNonIncognitoWindowTest(GURL(chrome::kChromeUIBookmarksURL));
[email protected]bd817c22011-02-09 08:16:461077}
1078
[email protected]93ad8e1c2011-11-08 21:34:051079// Bookmark manager is expected to always open in normal mode regardless
1080// of whether the user is trying to open it in incognito mode or not.
1081// This test verifies that if incognito mode is forced (by policy), bookmark
1082// manager doesn't open at all.
1083IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
1084 Disposition_Bookmarks_DoNothingIfIncognitoIsForced) {
[email protected]fc0ed302011-11-29 23:17:191085 RunDoNothingIfIncognitoIsForcedTest(GURL(chrome::kChromeUIBookmarksURL));
1086}
[email protected]93ad8e1c2011-11-08 21:34:051087
[email protected]7de53c62011-05-13 06:44:161088// This test makes sure a crashed singleton tab reloads from a new navigation.
[email protected]c4c0c0a12014-07-23 17:06:021089// http://crbug.com/396371
[email protected]7de53c62011-05-13 06:44:161090IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
[email protected]c4c0c0a12014-07-23 17:06:021091 DISABLED_NavigateToCrashedSingletonTab) {
[email protected]a048ad22012-03-23 04:26:561092 GURL singleton_url(GetContentSettingsURL());
[email protected]5a1a52462012-11-15 03:35:161093 WebContents* web_contents = chrome::AddSelectedTabWithURL(
Sylvain Defresnec6ccc77d2014-09-19 10:19:351094 browser(), singleton_url, ui::PAGE_TRANSITION_LINK);
[email protected]7de53c62011-05-13 06:44:161095
1096 // We should have one browser with 2 tabs, the 2nd selected.
[email protected]0665ebe2013-02-13 09:53:191097 EXPECT_EQ(1u, chrome::GetTotalBrowserCount());
[email protected]ee496952013-01-10 23:17:331098 EXPECT_EQ(2, browser()->tab_strip_model()->count());
1099 EXPECT_EQ(1, browser()->tab_strip_model()->active_index());
[email protected]7de53c62011-05-13 06:44:161100
1101 // Kill the singleton tab.
[email protected]83ff91c2012-01-05 20:54:131102 web_contents->SetIsCrashed(base::TERMINATION_STATUS_PROCESS_CRASHED, -1);
1103 EXPECT_TRUE(web_contents->IsCrashed());
[email protected]7de53c62011-05-13 06:44:161104
meacerc62e2ee2014-10-22 00:44:521105 chrome::NavigateParams params(MakeNavigateParams());
1106 params.disposition = SINGLETON_TAB;
1107 params.url = singleton_url;
1108 params.window_action = chrome::NavigateParams::SHOW_WINDOW;
1109 params.path_behavior = chrome::NavigateParams::IGNORE_AND_NAVIGATE;
1110 ui_test_utils::NavigateToURL(&params);
[email protected]7de53c62011-05-13 06:44:161111
1112 // The tab should not be sad anymore.
[email protected]83ff91c2012-01-05 20:54:131113 EXPECT_FALSE(web_contents->IsCrashed());
[email protected]7de53c62011-05-13 06:44:161114}
1115
[email protected]fcca741b2011-06-17 22:46:371116IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
1117 NavigateFromDefaultToOptionsInSameTab) {
[email protected]ddddfda2011-07-14 23:19:391118 {
[email protected]a7fe9112012-07-20 02:34:451119 content::WindowedNotificationObserver observer(
[email protected]ad50def52011-10-19 23:17:071120 content::NOTIFICATION_LOAD_STOP,
1121 content::NotificationService::AllSources());
[email protected]5d9cace72012-06-21 16:07:121122 chrome::ShowSettings(browser());
[email protected]ddddfda2011-07-14 23:19:391123 observer.Wait();
1124 }
[email protected]ee496952013-01-10 23:17:331125 EXPECT_EQ(1, browser()->tab_strip_model()->count());
[email protected]52877dbc62012-06-29 22:22:031126 EXPECT_EQ(GetSettingsURL(),
[email protected]ee496952013-01-10 23:17:331127 ShortenUberURL(browser()->tab_strip_model()->
1128 GetActiveWebContents()->GetURL()));
[email protected]fcca741b2011-06-17 22:46:371129}
1130
1131IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
1132 NavigateFromBlankToOptionsInSameTab) {
meacerc62e2ee2014-10-22 00:44:521133 chrome::NavigateParams params(MakeNavigateParams());
1134 params.url = GURL(url::kAboutBlankURL);
1135 ui_test_utils::NavigateToURL(&params);
[email protected]fcca741b2011-06-17 22:46:371136
[email protected]ddddfda2011-07-14 23:19:391137 {
[email protected]a7fe9112012-07-20 02:34:451138 content::WindowedNotificationObserver observer(
[email protected]ad50def52011-10-19 23:17:071139 content::NOTIFICATION_LOAD_STOP,
1140 content::NotificationService::AllSources());
[email protected]5d9cace72012-06-21 16:07:121141 chrome::ShowSettings(browser());
[email protected]ddddfda2011-07-14 23:19:391142 observer.Wait();
1143 }
[email protected]ee496952013-01-10 23:17:331144 EXPECT_EQ(1, browser()->tab_strip_model()->count());
[email protected]52877dbc62012-06-29 22:22:031145 EXPECT_EQ(GetSettingsURL(),
[email protected]ee496952013-01-10 23:17:331146 ShortenUberURL(browser()->tab_strip_model()->
1147 GetActiveWebContents()->GetURL()));
[email protected]fcca741b2011-06-17 22:46:371148}
1149
1150IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
1151 NavigateFromNTPToOptionsInSameTab) {
meacerc62e2ee2014-10-22 00:44:521152 chrome::NavigateParams params(MakeNavigateParams());
1153 params.url = GURL(chrome::kChromeUINewTabURL);
1154 ui_test_utils::NavigateToURL(&params);
[email protected]ee496952013-01-10 23:17:331155 EXPECT_EQ(1, browser()->tab_strip_model()->count());
[email protected]27658f32013-11-14 03:20:371156 EXPECT_EQ(GURL(chrome::kChromeUINewTabURL),
1157 browser()->tab_strip_model()->GetActiveWebContents()->GetURL());
[email protected]fcca741b2011-06-17 22:46:371158
[email protected]ddddfda2011-07-14 23:19:391159 {
[email protected]a7fe9112012-07-20 02:34:451160 content::WindowedNotificationObserver observer(
[email protected]ad50def52011-10-19 23:17:071161 content::NOTIFICATION_LOAD_STOP,
1162 content::NotificationService::AllSources());
[email protected]5d9cace72012-06-21 16:07:121163 chrome::ShowSettings(browser());
[email protected]ddddfda2011-07-14 23:19:391164 observer.Wait();
1165 }
[email protected]ee496952013-01-10 23:17:331166 EXPECT_EQ(1, browser()->tab_strip_model()->count());
[email protected]52877dbc62012-06-29 22:22:031167 EXPECT_EQ(GetSettingsURL(),
[email protected]ee496952013-01-10 23:17:331168 ShortenUberURL(browser()->tab_strip_model()->
1169 GetActiveWebContents()->GetURL()));
[email protected]fcca741b2011-06-17 22:46:371170}
1171
1172IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
1173 NavigateFromPageToOptionsInNewTab) {
meacerc62e2ee2014-10-22 00:44:521174 chrome::NavigateParams params(MakeNavigateParams());
1175 ui_test_utils::NavigateToURL(&params);
[email protected]ee496952013-01-10 23:17:331176 EXPECT_EQ(GetGoogleURL(),
1177 browser()->tab_strip_model()->GetActiveWebContents()->GetURL());
[email protected]0665ebe2013-02-13 09:53:191178 EXPECT_EQ(1u, chrome::GetTotalBrowserCount());
[email protected]ee496952013-01-10 23:17:331179 EXPECT_EQ(1, browser()->tab_strip_model()->count());
[email protected]fcca741b2011-06-17 22:46:371180
[email protected]ddddfda2011-07-14 23:19:391181 {
[email protected]a7fe9112012-07-20 02:34:451182 content::WindowedNotificationObserver observer(
[email protected]ad50def52011-10-19 23:17:071183 content::NOTIFICATION_LOAD_STOP,
1184 content::NotificationService::AllSources());
[email protected]5d9cace72012-06-21 16:07:121185 chrome::ShowSettings(browser());
[email protected]ddddfda2011-07-14 23:19:391186 observer.Wait();
1187 }
[email protected]ee496952013-01-10 23:17:331188 EXPECT_EQ(2, browser()->tab_strip_model()->count());
[email protected]52877dbc62012-06-29 22:22:031189 EXPECT_EQ(GetSettingsURL(),
[email protected]ee496952013-01-10 23:17:331190 ShortenUberURL(browser()->tab_strip_model()->
1191 GetActiveWebContents()->GetURL()));
[email protected]fcca741b2011-06-17 22:46:371192}
1193
1194IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
1195 NavigateFromNTPToOptionsSingleton) {
[email protected]ddddfda2011-07-14 23:19:391196 {
[email protected]a7fe9112012-07-20 02:34:451197 content::WindowedNotificationObserver observer(
[email protected]ad50def52011-10-19 23:17:071198 content::NOTIFICATION_LOAD_STOP,
1199 content::NotificationService::AllSources());
[email protected]5d9cace72012-06-21 16:07:121200 chrome::ShowSettings(browser());
[email protected]ddddfda2011-07-14 23:19:391201 observer.Wait();
1202 }
[email protected]ee496952013-01-10 23:17:331203 EXPECT_EQ(1, browser()->tab_strip_model()->count());
[email protected]fcca741b2011-06-17 22:46:371204
[email protected]a37d4b02012-06-25 21:56:101205 chrome::NewTab(browser());
[email protected]ee496952013-01-10 23:17:331206 EXPECT_EQ(2, browser()->tab_strip_model()->count());
[email protected]fcca741b2011-06-17 22:46:371207
[email protected]ddddfda2011-07-14 23:19:391208 {
[email protected]a7fe9112012-07-20 02:34:451209 content::WindowedNotificationObserver observer(
[email protected]ad50def52011-10-19 23:17:071210 content::NOTIFICATION_LOAD_STOP,
1211 content::NotificationService::AllSources());
[email protected]5d9cace72012-06-21 16:07:121212 chrome::ShowSettings(browser());
[email protected]ddddfda2011-07-14 23:19:391213 observer.Wait();
1214 }
[email protected]ee496952013-01-10 23:17:331215 EXPECT_EQ(2, browser()->tab_strip_model()->count());
[email protected]52877dbc62012-06-29 22:22:031216 EXPECT_EQ(GetSettingsURL(),
[email protected]ee496952013-01-10 23:17:331217 ShortenUberURL(browser()->tab_strip_model()->
1218 GetActiveWebContents()->GetURL()));
[email protected]fcca741b2011-06-17 22:46:371219}
1220
1221IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
1222 NavigateFromNTPToOptionsPageInSameTab) {
[email protected]ddddfda2011-07-14 23:19:391223 {
[email protected]a7fe9112012-07-20 02:34:451224 content::WindowedNotificationObserver observer(
[email protected]ad50def52011-10-19 23:17:071225 content::NOTIFICATION_LOAD_STOP,
1226 content::NotificationService::AllSources());
[email protected]5d9cace72012-06-21 16:07:121227 chrome::ShowClearBrowsingDataDialog(browser());
[email protected]ddddfda2011-07-14 23:19:391228 observer.Wait();
1229 }
[email protected]ee496952013-01-10 23:17:331230 EXPECT_EQ(1, browser()->tab_strip_model()->count());
[email protected]a048ad22012-03-23 04:26:561231 EXPECT_EQ(GetClearBrowsingDataURL(),
[email protected]ee496952013-01-10 23:17:331232 browser()->tab_strip_model()->GetActiveWebContents()->GetURL());
[email protected]fcca741b2011-06-17 22:46:371233
[email protected]a37d4b02012-06-25 21:56:101234 chrome::NewTab(browser());
[email protected]ee496952013-01-10 23:17:331235 EXPECT_EQ(2, browser()->tab_strip_model()->count());
[email protected]fcca741b2011-06-17 22:46:371236
[email protected]ddddfda2011-07-14 23:19:391237 {
[email protected]a7fe9112012-07-20 02:34:451238 content::WindowedNotificationObserver observer(
[email protected]ad50def52011-10-19 23:17:071239 content::NOTIFICATION_LOAD_STOP,
1240 content::NotificationService::AllSources());
[email protected]5d9cace72012-06-21 16:07:121241 chrome::ShowClearBrowsingDataDialog(browser());
[email protected]ddddfda2011-07-14 23:19:391242 observer.Wait();
1243 }
[email protected]ee496952013-01-10 23:17:331244 EXPECT_EQ(2, browser()->tab_strip_model()->count());
[email protected]a048ad22012-03-23 04:26:561245 EXPECT_EQ(GetClearBrowsingDataURL(),
[email protected]ee496952013-01-10 23:17:331246 browser()->tab_strip_model()->GetActiveWebContents()->GetURL());
[email protected]fcca741b2011-06-17 22:46:371247}
1248
1249IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
[email protected]05912742013-03-12 00:29:151250 NavigateFromOtherTabToSingletonOptions) {
[email protected]ddddfda2011-07-14 23:19:391251 {
[email protected]a7fe9112012-07-20 02:34:451252 content::WindowedNotificationObserver observer(
[email protected]ad50def52011-10-19 23:17:071253 content::NOTIFICATION_LOAD_STOP,
1254 content::NotificationService::AllSources());
[email protected]5d9cace72012-06-21 16:07:121255 chrome::ShowSettings(browser());
[email protected]ddddfda2011-07-14 23:19:391256 observer.Wait();
1257 }
1258 {
[email protected]a7fe9112012-07-20 02:34:451259 content::WindowedNotificationObserver observer(
[email protected]ad50def52011-10-19 23:17:071260 content::NOTIFICATION_LOAD_STOP,
1261 content::NotificationService::AllSources());
[email protected]52877dbc62012-06-29 22:22:031262 chrome::AddSelectedTabWithURL(browser(), GetGoogleURL(),
Sylvain Defresnec6ccc77d2014-09-19 10:19:351263 ui::PAGE_TRANSITION_LINK);
[email protected]ddddfda2011-07-14 23:19:391264 observer.Wait();
1265 }
[email protected]fcca741b2011-06-17 22:46:371266
[email protected]05912742013-03-12 00:29:151267 // This load should simply cause a tab switch.
1268 chrome::ShowSettings(browser());
1269
[email protected]ee496952013-01-10 23:17:331270 EXPECT_EQ(2, browser()->tab_strip_model()->count());
[email protected]ddddfda2011-07-14 23:19:391271 EXPECT_EQ(GetSettingsURL(),
[email protected]ee496952013-01-10 23:17:331272 ShortenUberURL(browser()->tab_strip_model()->
1273 GetActiveWebContents()->GetURL()));
[email protected]fcca741b2011-06-17 22:46:371274}
1275
[email protected]4e78b2d2013-06-12 16:46:171276IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, CloseSingletonTab) {
[email protected]79717cf2013-02-28 18:40:361277 for (int i = 0; i < 2; ++i) {
1278 content::WindowedNotificationObserver observer(
1279 content::NOTIFICATION_LOAD_STOP,
1280 content::NotificationService::AllSources());
1281 chrome::AddSelectedTabWithURL(browser(), GetGoogleURL(),
Sylvain Defresnec6ccc77d2014-09-19 10:19:351282 ui::PAGE_TRANSITION_TYPED);
[email protected]79717cf2013-02-28 18:40:361283 observer.Wait();
1284 }
1285
1286 browser()->tab_strip_model()->ActivateTabAt(0, true);
1287
1288 {
1289 content::WindowedNotificationObserver observer(
1290 content::NOTIFICATION_LOAD_STOP,
1291 content::NotificationService::AllSources());
1292 chrome::ShowSettings(browser());
1293 observer.Wait();
1294 }
1295
1296 EXPECT_TRUE(browser()->tab_strip_model()->CloseWebContentsAt(
1297 2, TabStripModel::CLOSE_USER_GESTURE));
1298 EXPECT_EQ(0, browser()->tab_strip_model()->active_index());
1299}
1300
[email protected]a048ad22012-03-23 04:26:561301// TODO(csilv): Update this for uber page. http://crbug.com/111579.
[email protected]ddddfda2011-07-14 23:19:391302IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
[email protected]a048ad22012-03-23 04:26:561303 DISABLED_NavigateFromDefaultToHistoryInSameTab) {
[email protected]ddddfda2011-07-14 23:19:391304 {
[email protected]a7fe9112012-07-20 02:34:451305 content::WindowedNotificationObserver observer(
[email protected]ad50def52011-10-19 23:17:071306 content::NOTIFICATION_LOAD_STOP,
1307 content::NotificationService::AllSources());
[email protected]5d9cace72012-06-21 16:07:121308 chrome::ShowHistory(browser());
[email protected]ddddfda2011-07-14 23:19:391309 observer.Wait();
1310 }
[email protected]ee496952013-01-10 23:17:331311 EXPECT_EQ(1, browser()->tab_strip_model()->count());
[email protected]11e03fb2012-03-03 19:07:051312 EXPECT_EQ(GURL(chrome::kChromeUIHistoryFrameURL),
[email protected]ee496952013-01-10 23:17:331313 browser()->tab_strip_model()->GetActiveWebContents()->GetURL());
[email protected]ddddfda2011-07-14 23:19:391314}
1315
[email protected]953c2132013-02-23 05:56:051316// TODO(linux_aura) http://crbug.com/163931
1317#if defined(OS_LINUX) && !defined(OS_CHROMEOS) && defined(USE_AURA)
dbeam2b4fc3562016-02-23 01:43:271318#define MAYBE_NavigateFromDefaultToBookmarksInSameTab \
1319 DISABLED_NavigateFromDefaultToBookmarksInSameTab
[email protected]953c2132013-02-23 05:56:051320#else
dbeam2b4fc3562016-02-23 01:43:271321#define MAYBE_NavigateFromDefaultToBookmarksInSameTab \
1322 NavigateFromDefaultToBookmarksInSameTab
[email protected]953c2132013-02-23 05:56:051323#endif
[email protected]ddddfda2011-07-14 23:19:391324IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
[email protected]953c2132013-02-23 05:56:051325 MAYBE_NavigateFromDefaultToBookmarksInSameTab) {
[email protected]ddddfda2011-07-14 23:19:391326 {
[email protected]a7fe9112012-07-20 02:34:451327 content::WindowedNotificationObserver observer(
[email protected]ad50def52011-10-19 23:17:071328 content::NOTIFICATION_LOAD_STOP,
1329 content::NotificationService::AllSources());
[email protected]5d9cace72012-06-21 16:07:121330 chrome::ShowBookmarkManager(browser());
[email protected]ddddfda2011-07-14 23:19:391331 observer.Wait();
1332 }
[email protected]ee496952013-01-10 23:17:331333 EXPECT_EQ(1, browser()->tab_strip_model()->count());
brettw66d1b81b2015-07-06 19:29:401334 EXPECT_TRUE(base::StartsWith(
[email protected]bc16a252013-01-23 02:21:491335 browser()->tab_strip_model()->GetActiveWebContents()->GetURL().spec(),
brettw66d1b81b2015-07-06 19:29:401336 chrome::kChromeUIBookmarksURL, base::CompareCase::SENSITIVE));
[email protected]ddddfda2011-07-14 23:19:391337}
1338
1339IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
1340 NavigateFromDefaultToDownloadsInSameTab) {
1341 {
[email protected]a7fe9112012-07-20 02:34:451342 content::WindowedNotificationObserver observer(
[email protected]ad50def52011-10-19 23:17:071343 content::NOTIFICATION_LOAD_STOP,
1344 content::NotificationService::AllSources());
[email protected]5d9cace72012-06-21 16:07:121345 chrome::ShowDownloads(browser());
[email protected]ddddfda2011-07-14 23:19:391346 observer.Wait();
1347 }
[email protected]ee496952013-01-10 23:17:331348 EXPECT_EQ(1, browser()->tab_strip_model()->count());
[email protected]ddddfda2011-07-14 23:19:391349 EXPECT_EQ(GURL(chrome::kChromeUIDownloadsURL),
[email protected]ee496952013-01-10 23:17:331350 browser()->tab_strip_model()->GetActiveWebContents()->GetURL());
[email protected]ddddfda2011-07-14 23:19:391351}
1352
[email protected]8fb16a82012-08-17 02:17:591353IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
1354 NavigateWithoutBrowser) {
1355 // First navigate using the profile of the existing browser window, and
1356 // check that the window is reused.
1357 chrome::NavigateParams params(browser()->profile(), GetGoogleURL(),
Sylvain Defresnec6ccc77d2014-09-19 10:19:351358 ui::PAGE_TRANSITION_LINK);
[email protected]8fb16a82012-08-17 02:17:591359 ui_test_utils::NavigateToURL(&params);
[email protected]0665ebe2013-02-13 09:53:191360 EXPECT_EQ(1u, chrome::GetTotalBrowserCount());
[email protected]8fb16a82012-08-17 02:17:591361
1362 // Now navigate using the incognito profile and check that a new window
1363 // is created.
1364 chrome::NavigateParams params_incognito(
1365 browser()->profile()->GetOffTheRecordProfile(),
Sylvain Defresnec6ccc77d2014-09-19 10:19:351366 GetGoogleURL(), ui::PAGE_TRANSITION_LINK);
[email protected]8fb16a82012-08-17 02:17:591367 ui_test_utils::NavigateToURL(&params_incognito);
[email protected]0665ebe2013-02-13 09:53:191368 EXPECT_EQ(2u, chrome::GetTotalBrowserCount());
[email protected]8fb16a82012-08-17 02:17:591369}
1370
[email protected]beb1d1192013-05-14 04:47:511371IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, ViewSourceIsntSingleton) {
1372 const std::string viewsource_ntp_url =
[email protected]dbdda5402013-05-30 22:13:481373 std::string(content::kViewSourceScheme) + ":" +
[email protected]beb1d1192013-05-14 04:47:511374 chrome::kChromeUIVersionURL;
1375
1376 chrome::NavigateParams viewsource_params(browser(),
1377 GURL(viewsource_ntp_url),
Sylvain Defresnec6ccc77d2014-09-19 10:19:351378 ui::PAGE_TRANSITION_LINK);
[email protected]beb1d1192013-05-14 04:47:511379 ui_test_utils::NavigateToURL(&viewsource_params);
1380
1381 chrome::NavigateParams singleton_params(browser(),
1382 GURL(chrome::kChromeUIVersionURL),
Sylvain Defresnec6ccc77d2014-09-19 10:19:351383 ui::PAGE_TRANSITION_LINK);
[email protected]beb1d1192013-05-14 04:47:511384 singleton_params.disposition = SINGLETON_TAB;
1385 EXPECT_EQ(-1, chrome::GetIndexOfSingletonTab(&singleton_params));
1386}
1387
[email protected]a2efc35d2013-08-03 23:17:251388// This test verifies that browser initiated navigations can send requests
1389// using POST.
1390IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
1391 SendBrowserInitiatedRequestUsingPOST) {
1392 // Uses a test sever to verify POST request.
svaldeza01f7d92015-11-18 17:47:561393 ASSERT_TRUE(embedded_test_server()->Start());
[email protected]a2efc35d2013-08-03 23:17:251394
1395 // Open a browser initiated POST request in new foreground tab.
[email protected]e9273e192013-12-11 17:51:491396 base::string16 expected_title(base::ASCIIToUTF16(kExpectedTitle));
[email protected]a2efc35d2013-08-03 23:17:251397 std::string post_data = kExpectedTitle;
[email protected]e9273e192013-12-11 17:51:491398 base::string16 title;
[email protected]a2efc35d2013-08-03 23:17:251399 ASSERT_TRUE(OpenPOSTURLInNewForegroundTabAndGetTitle(
svaldeza01f7d92015-11-18 17:47:561400 embedded_test_server()->GetURL(kEchoTitleCommand), post_data, true,
1401 &title));
[email protected]a2efc35d2013-08-03 23:17:251402 EXPECT_EQ(expected_title, title);
1403}
1404
1405// This test verifies that renderer initiated navigations can NOT send requests
1406// using POST.
1407IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
1408 SendRendererInitiatedRequestUsingPOST) {
1409 // Uses a test sever to verify POST request.
svaldeza01f7d92015-11-18 17:47:561410 ASSERT_TRUE(embedded_test_server()->Start());
[email protected]a2efc35d2013-08-03 23:17:251411
1412 // Open a renderer initiated POST request in new foreground tab.
[email protected]e9273e192013-12-11 17:51:491413 base::string16 expected_title(base::ASCIIToUTF16(kExpectedTitle));
[email protected]a2efc35d2013-08-03 23:17:251414 std::string post_data = kExpectedTitle;
[email protected]e9273e192013-12-11 17:51:491415 base::string16 title;
[email protected]a2efc35d2013-08-03 23:17:251416 ASSERT_TRUE(OpenPOSTURLInNewForegroundTabAndGetTitle(
svaldeza01f7d92015-11-18 17:47:561417 embedded_test_server()->GetURL(kEchoTitleCommand), post_data, false,
1418 &title));
[email protected]a2efc35d2013-08-03 23:17:251419 EXPECT_NE(expected_title, title);
1420}
1421
meacerc62e2ee2014-10-22 00:44:521422// This test navigates to a data URL that contains BiDi control
1423// characters. For security reasons, BiDi control chars should always be
1424// escaped in the URL but they should be unescaped in the loaded HTML.
1425IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
1426 NavigateToDataURLWithBiDiControlChars) {
1427 // Text in Arabic.
1428 std::string text = "\xD8\xA7\xD8\xAE\xD8\xAA\xD8\xA8\xD8\xA7\xD8\xB1";
1429 // Page title starts with RTL mark.
1430 std::string unescaped_title = "\xE2\x80\x8F" + text;
1431 std::string data_url = "data:text/html;charset=utf-8,<html><title>" +
1432 unescaped_title + "</title></html>";
1433 // BiDi control chars in URLs are always escaped, so the expected URL should
1434 // have the title with the escaped RTL mark.
1435 std::string escaped_title = "%E2%80%8F" + text;
1436 std::string expected_url = "data:text/html;charset=utf-8,<html><title>" +
1437 escaped_title + "</title></html>";
1438
1439 // Navigate to the page.
1440 chrome::NavigateParams params(MakeNavigateParams());
1441 params.disposition = NEW_FOREGROUND_TAB;
1442 params.url = GURL(data_url);
1443 params.window_action = chrome::NavigateParams::SHOW_WINDOW;
1444 ui_test_utils::NavigateToURL(&params);
1445
1446 base::string16 expected_title(base::UTF8ToUTF16(unescaped_title));
1447 EXPECT_TRUE(params.target_contents);
1448 EXPECT_EQ(expected_title, params.target_contents->GetTitle());
1449 // GURL always keeps non-ASCII characters escaped, but check them anyways.
1450 EXPECT_EQ(GURL(expected_url).spec(), params.target_contents->GetURL().spec());
1451 // Check the omnibox text. It should have escaped RTL with unescaped text.
1452 LocationBar* location_bar = browser()->window()->GetLocationBar();
1453 OmniboxView* omnibox_view = location_bar->GetOmniboxView();
1454 EXPECT_EQ(base::UTF8ToUTF16(expected_url), omnibox_view->GetText());
1455}
1456
[email protected]a2efc35d2013-08-03 23:17:251457} // namespace