blob: bc2fc35a8d029e46ec8b6c81882c41605ed19353 [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]3853a4c2013-02-11 17:15:578#include "base/prefs/pref_service.h"
[email protected]fc2b46b2014-05-03 16:33:459#include "base/strings/string_util.h"
[email protected]a2efc35d2013-08-03 23:17:2510#include "base/strings/utf_string_conversions.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"
[email protected]ad50def52011-10-19 23:17:0730#include "content/public/browser/notification_service.h"
[email protected]0d6e9bd2011-10-18 04:29:1631#include "content/public/browser/notification_types.h"
[email protected]83ff91c2012-01-05 20:54:1332#include "content/public/browser/web_contents.h"
svaldeza01f7d92015-11-18 17:47:5633#include "net/test/embedded_test_server/embedded_test_server.h"
[email protected]a1feae52010-10-11 22:14:4534
[email protected]4ca15302012-01-03 05:53:2035using content::WebContents;
36
[email protected]ddddfda2011-07-14 23:19:3937namespace {
38
[email protected]a2efc35d2013-08-03 23:17:2539const char kExpectedTitle[] = "PASSED!";
svaldeza01f7d92015-11-18 17:47:5640const char kEchoTitleCommand[] = "/echotitle";
[email protected]a2efc35d2013-08-03 23:17:2541
[email protected]ddddfda2011-07-14 23:19:3942GURL GetGoogleURL() {
[email protected]bd817c22011-02-09 08:16:4643 return GURL("http://www.google.com/");
44}
[email protected]a1feae52010-10-11 22:14:4545
[email protected]ddddfda2011-07-14 23:19:3946GURL GetSettingsURL() {
[email protected]f8f93eb2012-09-25 03:06:2447 return GURL(chrome::kChromeUISettingsURL);
[email protected]ddddfda2011-07-14 23:19:3948}
49
[email protected]a048ad22012-03-23 04:26:5650GURL GetContentSettingsURL() {
51 return GetSettingsURL().Resolve(chrome::kContentSettingsExceptionsSubPage);
[email protected]ddddfda2011-07-14 23:19:3952}
53
[email protected]a048ad22012-03-23 04:26:5654GURL GetClearBrowsingDataURL() {
55 return GetSettingsURL().Resolve(chrome::kClearBrowserDataSubPage);
[email protected]ddddfda2011-07-14 23:19:3956}
57
[email protected]f8f93eb2012-09-25 03:06:2458// Converts long uber URLs ("chrome://chrome/foo/") to short (virtual) URLs
59// ("chrome://foo/"). This should be used to convert the return value of
60// WebContentsImpl::GetURL before comparison because it can return either the
61// real URL or the virtual URL.
62GURL ShortenUberURL(const GURL& url) {
63 std::string url_string = url.spec();
64 const std::string long_prefix = "chrome://chrome/";
65 const std::string short_prefix = "chrome://";
66 if (url_string.find(long_prefix) != 0)
67 return url;
68 url_string.replace(0, long_prefix.length(), short_prefix);
69 return GURL(url_string);
70}
71
[email protected]a2efc35d2013-08-03 23:17:2572} // namespace
[email protected]ddddfda2011-07-14 23:19:3973
[email protected]78e2edc2012-07-01 23:32:2874chrome::NavigateParams BrowserNavigatorTest::MakeNavigateParams() const {
[email protected]bd817c22011-02-09 08:16:4675 return MakeNavigateParams(browser());
76}
[email protected]a1feae52010-10-11 22:14:4577
[email protected]78e2edc2012-07-01 23:32:2878chrome::NavigateParams BrowserNavigatorTest::MakeNavigateParams(
[email protected]bd817c22011-02-09 08:16:4679 Browser* browser) const {
[email protected]78e2edc2012-07-01 23:32:2880 chrome::NavigateParams params(browser, GetGoogleURL(),
Sylvain Defresnec6ccc77d2014-09-19 10:19:3581 ui::PAGE_TRANSITION_LINK);
[email protected]50592b52013-05-02 22:26:2582 params.window_action = chrome::NavigateParams::SHOW_WINDOW;
[email protected]bd817c22011-02-09 08:16:4683 return params;
84}
[email protected]a1feae52010-10-11 22:14:4585
[email protected]a2efc35d2013-08-03 23:17:2586bool BrowserNavigatorTest::OpenPOSTURLInNewForegroundTabAndGetTitle(
87 const GURL& url, const std::string& post_data, bool is_browser_initiated,
88 base::string16* title) {
89 chrome::NavigateParams param(MakeNavigateParams());
90 param.disposition = NEW_FOREGROUND_TAB;
91 param.url = url;
92 param.is_renderer_initiated = !is_browser_initiated;
93 param.uses_post = true;
94 param.browser_initiated_post_data = new base::RefCountedStaticMemory(
[email protected]8df08cf2014-02-12 22:34:0895 post_data.data(), post_data.size());
[email protected]a2efc35d2013-08-03 23:17:2596
97 ui_test_utils::NavigateToURL(&param);
98 if (!param.target_contents)
99 return false;
100
101 // Navigate() should have opened the contents in new foreground tab in the
102 // current Browser.
103 EXPECT_EQ(browser(), param.browser);
104 EXPECT_EQ(browser()->tab_strip_model()->GetActiveWebContents(),
105 param.target_contents);
106 // We should have one window, with one tab.
107 EXPECT_EQ(1u, chrome::GetTotalBrowserCount());
108 EXPECT_EQ(2, browser()->tab_strip_model()->count());
109
110 *title = param.target_contents->GetTitle();
111 return true;
112}
113
[email protected]bd817c22011-02-09 08:16:46114Browser* BrowserNavigatorTest::CreateEmptyBrowserForType(Browser::Type type,
115 Profile* profile) {
[email protected]2b09ae552013-02-23 06:38:03116 Browser* browser = new Browser(
[email protected]ed2fa722013-06-25 20:37:34117 Browser::CreateParams(type, profile, chrome::GetActiveDesktop()));
[email protected]00509a32013-11-17 17:45:37118 chrome::AddTabAt(browser, GURL(), -1, true);
[email protected]bd817c22011-02-09 08:16:46119 return browser;
120}
[email protected]a1feae52010-10-11 22:14:45121
[email protected]d2202e22014-04-14 20:20:53122Browser* BrowserNavigatorTest::CreateEmptyBrowserForApp(Profile* profile) {
[email protected]a4fe67012012-07-25 20:14:29123 Browser* browser = new Browser(
[email protected]da22aa62012-04-04 18:54:35124 Browser::CreateParams::CreateForApp(
[email protected]d2202e22014-04-14 20:20:53125 "Test", false /* trusted_source */, gfx::Rect(), profile,
[email protected]ed2fa722013-06-25 20:37:34126 chrome::GetActiveDesktop()));
[email protected]00509a32013-11-17 17:45:37127 chrome::AddTabAt(browser, GURL(), -1, true);
[email protected]b35b26b32011-05-05 20:35:14128 return browser;
129}
130
[email protected]e232c992012-12-06 12:43:20131WebContents* BrowserNavigatorTest::CreateWebContents() {
[email protected]54944cde2012-12-09 09:24:59132 content::WebContents::CreateParams create_params(browser()->profile());
[email protected]ed245db2012-12-18 08:00:45133 content::WebContents* base_web_contents =
[email protected]ee496952013-01-10 23:17:33134 browser()->tab_strip_model()->GetActiveWebContents();
[email protected]ed245db2012-12-18 08:00:45135 if (base_web_contents) {
136 create_params.initial_size =
[email protected]fc2b46b2014-05-03 16:33:45137 base_web_contents->GetContainerBounds().size();
[email protected]ed245db2012-12-18 08:00:45138 }
[email protected]54944cde2012-12-09 09:24:59139 return WebContents::Create(create_params);
[email protected]bd817c22011-02-09 08:16:46140}
[email protected]a1feae52010-10-11 22:14:45141
[email protected]bd817c22011-02-09 08:16:46142void BrowserNavigatorTest::RunSuppressTest(WindowOpenDisposition disposition) {
[email protected]ee496952013-01-10 23:17:33143 GURL old_url = browser()->tab_strip_model()->GetActiveWebContents()->GetURL();
meacerc62e2ee2014-10-22 00:44:52144 chrome::NavigateParams params(MakeNavigateParams());
145 params.disposition = disposition;
146 chrome::Navigate(&params);
[email protected]a1feae52010-10-11 22:14:45147
[email protected]bd817c22011-02-09 08:16:46148 // Nothing should have happened as a result of Navigate();
[email protected]ee496952013-01-10 23:17:33149 EXPECT_EQ(1, browser()->tab_strip_model()->count());
[email protected]0665ebe2013-02-13 09:53:19150 EXPECT_EQ(1u, chrome::GetTotalBrowserCount());
[email protected]ee496952013-01-10 23:17:33151 EXPECT_EQ(old_url,
152 browser()->tab_strip_model()->GetActiveWebContents()->GetURL());
[email protected]bd817c22011-02-09 08:16:46153}
[email protected]bb89e7482010-11-17 18:27:04154
[email protected]fc0ed302011-11-29 23:17:19155void BrowserNavigatorTest::RunUseNonIncognitoWindowTest(const GURL& url) {
156 Browser* incognito_browser = CreateIncognitoBrowser();
157
[email protected]0665ebe2013-02-13 09:53:19158 EXPECT_EQ(2u, chrome::GetTotalBrowserCount());
[email protected]ee496952013-01-10 23:17:33159 EXPECT_EQ(1, browser()->tab_strip_model()->count());
160 EXPECT_EQ(1, incognito_browser->tab_strip_model()->count());
[email protected]fc0ed302011-11-29 23:17:19161
162 // Navigate to the page.
meacerc62e2ee2014-10-22 00:44:52163 chrome::NavigateParams params(MakeNavigateParams(incognito_browser));
164 params.disposition = SINGLETON_TAB;
165 params.url = url;
166 params.window_action = chrome::NavigateParams::SHOW_WINDOW;
167 chrome::Navigate(&params);
[email protected]fc0ed302011-11-29 23:17:19168
[email protected]50592b52013-05-02 22:26:25169 // This page should be opened in browser() window.
meacerc62e2ee2014-10-22 00:44:52170 EXPECT_NE(incognito_browser, params.browser);
171 EXPECT_EQ(browser(), params.browser);
[email protected]ee496952013-01-10 23:17:33172 EXPECT_EQ(2, browser()->tab_strip_model()->count());
173 EXPECT_EQ(url,
174 browser()->tab_strip_model()->GetActiveWebContents()->GetURL());
[email protected]fc0ed302011-11-29 23:17:19175}
176
177void BrowserNavigatorTest::RunDoNothingIfIncognitoIsForcedTest(
178 const GURL& url) {
179 Browser* browser = CreateIncognitoBrowser();
180
181 // Set kIncognitoModeAvailability to FORCED.
182 PrefService* prefs1 = browser->profile()->GetPrefs();
183 prefs1->SetInteger(prefs::kIncognitoModeAvailability,
184 IncognitoModePrefs::FORCED);
185 PrefService* prefs2 = browser->profile()->GetOriginalProfile()->GetPrefs();
186 prefs2->SetInteger(prefs::kIncognitoModeAvailability,
187 IncognitoModePrefs::FORCED);
188
189 // Navigate to the page.
meacerc62e2ee2014-10-22 00:44:52190 chrome::NavigateParams params(MakeNavigateParams(browser));
191 params.disposition = OFF_THE_RECORD;
192 params.url = url;
193 params.window_action = chrome::NavigateParams::SHOW_WINDOW;
194 chrome::Navigate(&params);
[email protected]fc0ed302011-11-29 23:17:19195
196 // The page should not be opened.
meacerc62e2ee2014-10-22 00:44:52197 EXPECT_EQ(browser, params.browser);
[email protected]ee496952013-01-10 23:17:33198 EXPECT_EQ(1, browser->tab_strip_model()->count());
[email protected]8e09c7af2014-06-10 11:46:17199 EXPECT_EQ(GURL(url::kAboutBlankURL),
[email protected]ee496952013-01-10 23:17:33200 browser->tab_strip_model()->GetActiveWebContents()->GetURL());
[email protected]fc0ed302011-11-29 23:17:19201}
202
[email protected]aae79572014-06-13 00:42:58203void BrowserNavigatorTest::SetUpCommandLine(base::CommandLine* command_line) {
204 // Disable settings-in-a-window so that we can use the settings page and
205 // sub-pages to test browser navigation.
206 command_line->AppendSwitch(::switches::kDisableSettingsWindow);
benwellsf3c6fac2015-09-01 23:38:52207
208 // Disable new downloads UI as it is very very slow. https://crbug.com/526577
209 // TODO(dbeam): remove this once the downloads UI is not slow.
210 command_line->AppendSwitch(switches::kDisableMaterialDesignDownloads);
[email protected]aae79572014-06-13 00:42:58211}
212
[email protected]6c2381d2011-10-19 02:52:53213void BrowserNavigatorTest::Observe(
214 int type,
215 const content::NotificationSource& source,
216 const content::NotificationDetails& details) {
[email protected]432115822011-07-10 15:52:27217 switch (type) {
[email protected]d53a08c2012-07-18 20:35:30218 case content::NOTIFICATION_WEB_CONTENTS_RENDER_VIEW_HOST_CREATED: {
[email protected]bd817c22011-02-09 08:16:46219 ++this->created_tab_contents_count_;
220 break;
[email protected]fa7ebe02010-11-29 23:04:57221 }
[email protected]bd817c22011-02-09 08:16:46222 default:
223 break;
[email protected]fa7ebe02010-11-29 23:04:57224 }
[email protected]bd817c22011-02-09 08:16:46225}
[email protected]fa7ebe02010-11-29 23:04:57226
[email protected]ddddfda2011-07-14 23:19:39227
[email protected]bd817c22011-02-09 08:16:46228namespace {
[email protected]a1feae52010-10-11 22:14:45229
[email protected]a1feae52010-10-11 22:14:45230// This test verifies that when a navigation occurs within a tab, the tab count
231// of the Browser remains the same and the current tab bears the loaded URL.
[email protected]59167c22013-06-03 18:07:32232// Note that network URLs are not actually loaded in tests, so this also tests
233// that error pages leave the intended URL in the address bar.
[email protected]a1feae52010-10-11 22:14:45234IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_CurrentTab) {
[email protected]ddddfda2011-07-14 23:19:39235 ui_test_utils::NavigateToURL(browser(), GetGoogleURL());
[email protected]ee496952013-01-10 23:17:33236 EXPECT_EQ(GetGoogleURL(),
237 browser()->tab_strip_model()->GetActiveWebContents()->GetURL());
[email protected]a1feae52010-10-11 22:14:45238 // We should have one window with one tab.
[email protected]0665ebe2013-02-13 09:53:19239 EXPECT_EQ(1u, chrome::GetTotalBrowserCount());
[email protected]ee496952013-01-10 23:17:33240 EXPECT_EQ(1, browser()->tab_strip_model()->count());
[email protected]a1feae52010-10-11 22:14:45241}
242
[email protected]bd817c22011-02-09 08:16:46243// This test verifies that a singleton tab is refocused if one is already opened
[email protected]19d9f3a2010-10-14 21:49:36244// in another or an existing window, or added if it is not.
245IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_SingletonTabExisting) {
[email protected]19d9f3a2010-10-14 21:49:36246 GURL singleton_url1("http://maps.google.com/");
[email protected]fa7ebe02010-11-29 23:04:57247
[email protected]e232c992012-12-06 12:43:20248 // Register for a notification if an additional WebContents was instantiated.
[email protected]bd817c22011-02-09 08:16:46249 // Opening a Singleton tab that is already opened should not be opening a new
[email protected]e232c992012-12-06 12:43:20250 // tab nor be creating a new WebContents object.
[email protected]6c2381d2011-10-19 02:52:53251 content::NotificationRegistrar registrar;
[email protected]fa7ebe02010-11-29 23:04:57252
253 // As the registrar object goes out of scope, this will get unregistered
[email protected]d53a08c2012-07-18 20:35:30254 registrar.Add(this,
255 content::NOTIFICATION_WEB_CONTENTS_RENDER_VIEW_HOST_CREATED,
[email protected]ad50def52011-10-19 23:17:07256 content::NotificationService::AllSources());
[email protected]fa7ebe02010-11-29 23:04:57257
[email protected]52877dbc62012-06-29 22:22:03258 chrome::AddSelectedTabWithURL(browser(), singleton_url1,
Sylvain Defresnec6ccc77d2014-09-19 10:19:35259 ui::PAGE_TRANSITION_LINK);
[email protected]52877dbc62012-06-29 22:22:03260 chrome::AddSelectedTabWithURL(browser(), GetGoogleURL(),
Sylvain Defresnec6ccc77d2014-09-19 10:19:35261 ui::PAGE_TRANSITION_LINK);
[email protected]19d9f3a2010-10-14 21:49:36262
263 // We should have one browser with 3 tabs, the 3rd selected.
[email protected]0665ebe2013-02-13 09:53:19264 EXPECT_EQ(1u, chrome::GetTotalBrowserCount());
[email protected]ee496952013-01-10 23:17:33265 EXPECT_EQ(2, browser()->tab_strip_model()->active_index());
[email protected]19d9f3a2010-10-14 21:49:36266
[email protected]fa7ebe02010-11-29 23:04:57267 unsigned int previous_tab_contents_count =
268 created_tab_contents_count_ = 0;
269
[email protected]19d9f3a2010-10-14 21:49:36270 // Navigate to singleton_url1.
meacerc62e2ee2014-10-22 00:44:52271 chrome::NavigateParams params(MakeNavigateParams());
272 params.disposition = SINGLETON_TAB;
273 params.url = singleton_url1;
274 chrome::Navigate(&params);
[email protected]19d9f3a2010-10-14 21:49:36275
276 // The middle tab should now be selected.
meacerc62e2ee2014-10-22 00:44:52277 EXPECT_EQ(browser(), params.browser);
[email protected]ee496952013-01-10 23:17:33278 EXPECT_EQ(1, browser()->tab_strip_model()->active_index());
[email protected]fa7ebe02010-11-29 23:04:57279
280 // No tab contents should have been created
281 EXPECT_EQ(previous_tab_contents_count,
282 created_tab_contents_count_);
[email protected]19d9f3a2010-10-14 21:49:36283}
284
285IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
[email protected]578c6962011-08-24 22:06:40286 Disposition_SingletonTabRespectingRef) {
287 GURL singleton_ref_url1("http://maps.google.com/#a");
288 GURL singleton_ref_url2("http://maps.google.com/#b");
289 GURL singleton_ref_url3("http://maps.google.com/");
290
[email protected]52877dbc62012-06-29 22:22:03291 chrome::AddSelectedTabWithURL(browser(), singleton_ref_url1,
Sylvain Defresnec6ccc77d2014-09-19 10:19:35292 ui::PAGE_TRANSITION_LINK);
[email protected]578c6962011-08-24 22:06:40293
294 // We should have one browser with 2 tabs, 2nd selected.
[email protected]0665ebe2013-02-13 09:53:19295 EXPECT_EQ(1u, chrome::GetTotalBrowserCount());
[email protected]ee496952013-01-10 23:17:33296 EXPECT_EQ(2, browser()->tab_strip_model()->count());
297 EXPECT_EQ(1, browser()->tab_strip_model()->active_index());
[email protected]578c6962011-08-24 22:06:40298
299 // Navigate to singleton_url2.
meacerc62e2ee2014-10-22 00:44:52300 chrome::NavigateParams params(MakeNavigateParams());
301 params.disposition = SINGLETON_TAB;
302 params.url = singleton_ref_url2;
303 chrome::Navigate(&params);
[email protected]578c6962011-08-24 22:06:40304
305 // We should now have 2 tabs, the 2nd one selected.
meacerc62e2ee2014-10-22 00:44:52306 EXPECT_EQ(browser(), params.browser);
[email protected]ee496952013-01-10 23:17:33307 EXPECT_EQ(2, browser()->tab_strip_model()->count());
308 EXPECT_EQ(1, browser()->tab_strip_model()->active_index());
[email protected]578c6962011-08-24 22:06:40309
310 // Navigate to singleton_url2, but with respect ref set.
meacerc62e2ee2014-10-22 00:44:52311 params = MakeNavigateParams();
312 params.disposition = SINGLETON_TAB;
313 params.url = singleton_ref_url2;
314 params.ref_behavior = chrome::NavigateParams::RESPECT_REF;
315 chrome::Navigate(&params);
[email protected]578c6962011-08-24 22:06:40316
317 // We should now have 3 tabs, the 3th one selected.
meacerc62e2ee2014-10-22 00:44:52318 EXPECT_EQ(browser(), params.browser);
[email protected]ee496952013-01-10 23:17:33319 EXPECT_EQ(3, browser()->tab_strip_model()->count());
320 EXPECT_EQ(2, browser()->tab_strip_model()->active_index());
[email protected]578c6962011-08-24 22:06:40321
322 // Navigate to singleton_url3.
meacerc62e2ee2014-10-22 00:44:52323 params = MakeNavigateParams();
324 params.disposition = SINGLETON_TAB;
325 params.url = singleton_ref_url3;
326 params.ref_behavior = chrome::NavigateParams::RESPECT_REF;
327 chrome::Navigate(&params);
[email protected]578c6962011-08-24 22:06:40328
329 // We should now have 4 tabs, the 4th one selected.
meacerc62e2ee2014-10-22 00:44:52330 EXPECT_EQ(browser(), params.browser);
[email protected]ee496952013-01-10 23:17:33331 EXPECT_EQ(4, browser()->tab_strip_model()->count());
332 EXPECT_EQ(3, browser()->tab_strip_model()->active_index());
[email protected]578c6962011-08-24 22:06:40333}
334
335IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
[email protected]19d9f3a2010-10-14 21:49:36336 Disposition_SingletonTabNoneExisting) {
[email protected]19d9f3a2010-10-14 21:49:36337 GURL singleton_url1("http://maps.google.com/");
338
[email protected]bd817c22011-02-09 08:16:46339 // We should have one browser with 1 tab.
[email protected]0665ebe2013-02-13 09:53:19340 EXPECT_EQ(1u, chrome::GetTotalBrowserCount());
[email protected]ee496952013-01-10 23:17:33341 EXPECT_EQ(0, browser()->tab_strip_model()->active_index());
[email protected]19d9f3a2010-10-14 21:49:36342
343 // Navigate to singleton_url1.
meacerc62e2ee2014-10-22 00:44:52344 chrome::NavigateParams params(MakeNavigateParams());
345 params.disposition = SINGLETON_TAB;
346 params.url = singleton_url1;
347 chrome::Navigate(&params);
[email protected]19d9f3a2010-10-14 21:49:36348
349 // We should now have 2 tabs, the 2nd one selected.
meacerc62e2ee2014-10-22 00:44:52350 EXPECT_EQ(browser(), params.browser);
[email protected]ee496952013-01-10 23:17:33351 EXPECT_EQ(2, browser()->tab_strip_model()->count());
352 EXPECT_EQ(1, browser()->tab_strip_model()->active_index());
[email protected]a1feae52010-10-11 22:14:45353}
354
355// This test verifies that when a navigation results in a foreground tab, the
356// tab count of the Browser increases and the selected tab shifts to the new
357// foreground tab.
358IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_NewForegroundTab) {
[email protected]ee496952013-01-10 23:17:33359 WebContents* old_contents =
360 browser()->tab_strip_model()->GetActiveWebContents();
meacerc62e2ee2014-10-22 00:44:52361 chrome::NavigateParams params(MakeNavigateParams());
362 params.disposition = NEW_FOREGROUND_TAB;
363 chrome::Navigate(&params);
[email protected]ee496952013-01-10 23:17:33364 EXPECT_NE(old_contents,
365 browser()->tab_strip_model()->GetActiveWebContents());
[email protected]e232c992012-12-06 12:43:20366 EXPECT_EQ(browser()->tab_strip_model()->GetActiveWebContents(),
meacerc62e2ee2014-10-22 00:44:52367 params.target_contents);
[email protected]ee496952013-01-10 23:17:33368 EXPECT_EQ(2, browser()->tab_strip_model()->count());
[email protected]a1feae52010-10-11 22:14:45369}
370
371// This test verifies that when a navigation results in a background tab, the
372// tab count of the Browser increases but the selected tab remains the same.
373IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_NewBackgroundTab) {
[email protected]ee496952013-01-10 23:17:33374 WebContents* old_contents =
375 browser()->tab_strip_model()->GetActiveWebContents();
meacerc62e2ee2014-10-22 00:44:52376 chrome::NavigateParams params(MakeNavigateParams());
377 params.disposition = NEW_BACKGROUND_TAB;
378 chrome::Navigate(&params);
[email protected]ee496952013-01-10 23:17:33379 WebContents* new_contents =
380 browser()->tab_strip_model()->GetActiveWebContents();
[email protected]a1feae52010-10-11 22:14:45381 // The selected tab should have remained unchanged, since the new tab was
382 // opened in the background.
383 EXPECT_EQ(old_contents, new_contents);
[email protected]ee496952013-01-10 23:17:33384 EXPECT_EQ(2, browser()->tab_strip_model()->count());
[email protected]a1feae52010-10-11 22:14:45385}
386
387// This test verifies that when a navigation requiring a new foreground tab
388// occurs in a Browser that cannot host multiple tabs, the new foreground tab
389// is created in an existing compatible Browser.
390IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
391 Disposition_IncompatibleWindow_Existing) {
392 // Open a foreground tab in a window that cannot open popups when there is an
393 // existing compatible window somewhere else that they can be opened within.
394 Browser* popup = CreateEmptyBrowserForType(Browser::TYPE_POPUP,
395 browser()->profile());
meacerc62e2ee2014-10-22 00:44:52396 chrome::NavigateParams params(MakeNavigateParams(popup));
397 params.disposition = NEW_FOREGROUND_TAB;
398 chrome::Navigate(&params);
[email protected]a1feae52010-10-11 22:14:45399
400 // Navigate() should have opened the tab in a different browser since the
401 // one we supplied didn't support additional tabs.
meacerc62e2ee2014-10-22 00:44:52402 EXPECT_NE(popup, params.browser);
[email protected]a1feae52010-10-11 22:14:45403
404 // Since browser() is an existing compatible tabbed browser, it should have
405 // opened the tab there.
meacerc62e2ee2014-10-22 00:44:52406 EXPECT_EQ(browser(), params.browser);
[email protected]a1feae52010-10-11 22:14:45407
408 // We should be left with 2 windows, the popup with one tab and the browser()
409 // provided by the framework with two.
[email protected]0665ebe2013-02-13 09:53:19410 EXPECT_EQ(2u, chrome::GetTotalBrowserCount());
[email protected]ee496952013-01-10 23:17:33411 EXPECT_EQ(1, popup->tab_strip_model()->count());
412 EXPECT_EQ(2, browser()->tab_strip_model()->count());
[email protected]a1feae52010-10-11 22:14:45413}
414
415// This test verifies that when a navigation requiring a new foreground tab
416// occurs in a Browser that cannot host multiple tabs and no compatible Browser
417// that can is open, a compatible Browser is created.
418IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
419 Disposition_IncompatibleWindow_NoExisting) {
420 // We want to simulate not being able to find an existing window compatible
421 // with our non-tabbed browser window so Navigate() is forced to create a
422 // new compatible window. Because browser() supplied by the in-process
423 // browser testing framework is compatible with browser()->profile(), we
424 // need a different profile, and creating a popup window with an incognito
425 // profile is a quick and dirty way of achieving this.
426 Browser* popup = CreateEmptyBrowserForType(
[email protected]b35b26b32011-05-05 20:35:14427 Browser::TYPE_POPUP,
428 browser()->profile()->GetOffTheRecordProfile());
meacerc62e2ee2014-10-22 00:44:52429 chrome::NavigateParams params(MakeNavigateParams(popup));
430 params.disposition = NEW_FOREGROUND_TAB;
431 chrome::Navigate(&params);
[email protected]a1feae52010-10-11 22:14:45432
433 // Navigate() should have opened the tab in a different browser since the
434 // one we supplied didn't support additional tabs.
meacerc62e2ee2014-10-22 00:44:52435 EXPECT_NE(popup, params.browser);
[email protected]a1feae52010-10-11 22:14:45436
437 // This time, browser() is _not_ compatible with popup since it is not an
438 // incognito window.
meacerc62e2ee2014-10-22 00:44:52439 EXPECT_NE(browser(), params.browser);
[email protected]a1feae52010-10-11 22:14:45440
441 // We should have three windows, each with one tab:
442 // 1. the browser() provided by the framework (unchanged in this test)
443 // 2. the incognito popup we created originally
444 // 3. the new incognito tabbed browser that was created by Navigate().
[email protected]0665ebe2013-02-13 09:53:19445 EXPECT_EQ(3u, chrome::GetTotalBrowserCount());
[email protected]ee496952013-01-10 23:17:33446 EXPECT_EQ(1, browser()->tab_strip_model()->count());
447 EXPECT_EQ(1, popup->tab_strip_model()->count());
meacerc62e2ee2014-10-22 00:44:52448 EXPECT_EQ(1, params.browser->tab_strip_model()->count());
449 EXPECT_TRUE(params.browser->is_type_tabbed());
[email protected]a1feae52010-10-11 22:14:45450}
451
452// This test verifies that navigating with WindowOpenDisposition = NEW_POPUP
453// from a normal Browser results in a new Browser with TYPE_POPUP.
454IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_NewPopup) {
meacerc62e2ee2014-10-22 00:44:52455 chrome::NavigateParams params(MakeNavigateParams());
456 params.disposition = NEW_POPUP;
457 params.window_bounds = gfx::Rect(0, 0, 200, 200);
[email protected]7d329992011-04-15 18:20:02458 // Wait for new popup to to load and gain focus.
meacerc62e2ee2014-10-22 00:44:52459 ui_test_utils::NavigateToURL(&params);
[email protected]a1feae52010-10-11 22:14:45460
[email protected]7d329992011-04-15 18:20:02461 // Navigate() should have opened a new, focused popup window.
meacerc62e2ee2014-10-22 00:44:52462 EXPECT_NE(browser(), params.browser);
[email protected]50592b52013-05-02 22:26:25463#if 0
464 // TODO(stevenjb): Enable this test. See: crbug.com/79493
meacerc62e2ee2014-10-22 00:44:52465 EXPECT_TRUE(browser->window()->IsActive());
[email protected]50592b52013-05-02 22:26:25466#endif
meacerc62e2ee2014-10-22 00:44:52467 EXPECT_TRUE(params.browser->is_type_popup());
468 EXPECT_FALSE(params.browser->is_app());
[email protected]a1feae52010-10-11 22:14:45469
470 // We should have two windows, the browser() provided by the framework and the
471 // new popup window.
[email protected]0665ebe2013-02-13 09:53:19472 EXPECT_EQ(2u, chrome::GetTotalBrowserCount());
[email protected]ee496952013-01-10 23:17:33473 EXPECT_EQ(1, browser()->tab_strip_model()->count());
meacerc62e2ee2014-10-22 00:44:52474 EXPECT_EQ(1, params.browser->tab_strip_model()->count());
[email protected]a1feae52010-10-11 22:14:45475}
476
477// This test verifies that navigating with WindowOpenDisposition = NEW_POPUP
[email protected]f112b0f2011-05-26 01:53:52478// from a normal Browser results in a new Browser with is_app() true.
479IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_NewPopup_ExtensionId) {
meacerc62e2ee2014-10-22 00:44:52480 chrome::NavigateParams params(MakeNavigateParams());
481 params.disposition = NEW_POPUP;
482 params.extension_app_id = "extensionappid";
483 params.window_bounds = gfx::Rect(0, 0, 200, 200);
[email protected]f112b0f2011-05-26 01:53:52484 // Wait for new popup to to load and gain focus.
meacerc62e2ee2014-10-22 00:44:52485 ui_test_utils::NavigateToURL(&params);
[email protected]f112b0f2011-05-26 01:53:52486
487 // Navigate() should have opened a new, focused popup window.
meacerc62e2ee2014-10-22 00:44:52488 EXPECT_NE(browser(), params.browser);
489 EXPECT_TRUE(params.browser->is_type_popup());
490 EXPECT_TRUE(params.browser->is_app());
[email protected]f112b0f2011-05-26 01:53:52491
492 // We should have two windows, the browser() provided by the framework and the
493 // new popup window.
[email protected]0665ebe2013-02-13 09:53:19494 EXPECT_EQ(2u, chrome::GetTotalBrowserCount());
[email protected]ee496952013-01-10 23:17:33495 EXPECT_EQ(1, browser()->tab_strip_model()->count());
meacerc62e2ee2014-10-22 00:44:52496 EXPECT_EQ(1, params.browser->tab_strip_model()->count());
[email protected]f112b0f2011-05-26 01:53:52497}
498
499// This test verifies that navigating with WindowOpenDisposition = NEW_POPUP
[email protected]300d1e52011-01-19 23:57:57500// from a normal popup results in a new Browser with TYPE_POPUP.
501IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_NewPopupFromPopup) {
502 // Open a popup.
meacerc62e2ee2014-10-22 00:44:52503 chrome::NavigateParams params1(MakeNavigateParams());
504 params1.disposition = NEW_POPUP;
505 params1.window_bounds = gfx::Rect(0, 0, 200, 200);
506 chrome::Navigate(&params1);
[email protected]300d1e52011-01-19 23:57:57507 // Open another popup.
meacerc62e2ee2014-10-22 00:44:52508 chrome::NavigateParams params2(MakeNavigateParams(params1.browser));
509 params2.disposition = NEW_POPUP;
510 params2.window_bounds = gfx::Rect(0, 0, 200, 200);
511 chrome::Navigate(&params2);
[email protected]300d1e52011-01-19 23:57:57512
513 // Navigate() should have opened a new normal popup window.
meacerc62e2ee2014-10-22 00:44:52514 EXPECT_NE(params1.browser, params2.browser);
515 EXPECT_TRUE(params2.browser->is_type_popup());
516 EXPECT_FALSE(params2.browser->is_app());
[email protected]300d1e52011-01-19 23:57:57517
518 // We should have three windows, the browser() provided by the framework,
519 // the first popup window, and the second popup window.
[email protected]0665ebe2013-02-13 09:53:19520 EXPECT_EQ(3u, chrome::GetTotalBrowserCount());
[email protected]ee496952013-01-10 23:17:33521 EXPECT_EQ(1, browser()->tab_strip_model()->count());
meacerc62e2ee2014-10-22 00:44:52522 EXPECT_EQ(1, params1.browser->tab_strip_model()->count());
523 EXPECT_EQ(1, params2.browser->tab_strip_model()->count());
[email protected]300d1e52011-01-19 23:57:57524}
525
526// This test verifies that navigating with WindowOpenDisposition = NEW_POPUP
[email protected]d2202e22014-04-14 20:20:53527// from an app frame results in a new Browser with TYPE_POPUP.
[email protected]a1feae52010-10-11 22:14:45528IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
529 Disposition_NewPopupFromAppWindow) {
[email protected]d2202e22014-04-14 20:20:53530 Browser* app_browser = CreateEmptyBrowserForApp(browser()->profile());
meacerc62e2ee2014-10-22 00:44:52531 chrome::NavigateParams params(MakeNavigateParams(app_browser));
532 params.disposition = NEW_POPUP;
533 params.window_bounds = gfx::Rect(0, 0, 200, 200);
534 chrome::Navigate(&params);
[email protected]a1feae52010-10-11 22:14:45535
536 // Navigate() should have opened a new popup app window.
meacerc62e2ee2014-10-22 00:44:52537 EXPECT_NE(app_browser, params.browser);
538 EXPECT_NE(browser(), params.browser);
539 EXPECT_TRUE(params.browser->is_type_popup());
540 EXPECT_TRUE(params.browser->is_app());
[email protected]a1feae52010-10-11 22:14:45541
542 // We should now have three windows, the app window, the app popup it created,
543 // and the original browser() provided by the framework.
[email protected]0665ebe2013-02-13 09:53:19544 EXPECT_EQ(3u, chrome::GetTotalBrowserCount());
[email protected]ee496952013-01-10 23:17:33545 EXPECT_EQ(1, browser()->tab_strip_model()->count());
546 EXPECT_EQ(1, app_browser->tab_strip_model()->count());
meacerc62e2ee2014-10-22 00:44:52547 EXPECT_EQ(1, params.browser->tab_strip_model()->count());
[email protected]a1feae52010-10-11 22:14:45548}
549
550// This test verifies that navigating with WindowOpenDisposition = NEW_POPUP
[email protected]d2202e22014-04-14 20:20:53551// from an app popup results in a new Browser also of TYPE_POPUP.
[email protected]300d1e52011-01-19 23:57:57552IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
553 Disposition_NewPopupFromAppPopup) {
[email protected]d2202e22014-04-14 20:20:53554 Browser* app_browser = CreateEmptyBrowserForApp(browser()->profile());
[email protected]300d1e52011-01-19 23:57:57555 // Open an app popup.
meacerc62e2ee2014-10-22 00:44:52556 chrome::NavigateParams params1(MakeNavigateParams(app_browser));
557 params1.disposition = NEW_POPUP;
558 params1.window_bounds = gfx::Rect(0, 0, 200, 200);
559 chrome::Navigate(&params1);
[email protected]300d1e52011-01-19 23:57:57560 // Now open another app popup.
meacerc62e2ee2014-10-22 00:44:52561 chrome::NavigateParams params2(MakeNavigateParams(params1.browser));
562 params2.disposition = NEW_POPUP;
563 params2.window_bounds = gfx::Rect(0, 0, 200, 200);
564 chrome::Navigate(&params2);
[email protected]300d1e52011-01-19 23:57:57565
566 // Navigate() should have opened a new popup app window.
meacerc62e2ee2014-10-22 00:44:52567 EXPECT_NE(browser(), params1.browser);
568 EXPECT_NE(params1.browser, params2.browser);
569 EXPECT_TRUE(params2.browser->is_type_popup());
570 EXPECT_TRUE(params2.browser->is_app());
[email protected]300d1e52011-01-19 23:57:57571
572 // We should now have four windows, the app window, the first app popup,
573 // the second app popup, and the original browser() provided by the framework.
[email protected]0665ebe2013-02-13 09:53:19574 EXPECT_EQ(4u, chrome::GetTotalBrowserCount());
[email protected]ee496952013-01-10 23:17:33575 EXPECT_EQ(1, browser()->tab_strip_model()->count());
576 EXPECT_EQ(1, app_browser->tab_strip_model()->count());
meacerc62e2ee2014-10-22 00:44:52577 EXPECT_EQ(1, params1.browser->tab_strip_model()->count());
578 EXPECT_EQ(1, params2.browser->tab_strip_model()->count());
[email protected]300d1e52011-01-19 23:57:57579}
580
581// This test verifies that navigating with WindowOpenDisposition = NEW_POPUP
[email protected]a1feae52010-10-11 22:14:45582// from an extension app tab results in a new Browser with TYPE_APP_POPUP.
583IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
584 Disposition_NewPopupFromExtensionApp) {
585 // TODO(beng): TBD.
586}
587
[email protected]7d329992011-04-15 18:20:02588// This test verifies that navigating with window_action = SHOW_WINDOW_INACTIVE
589// does not focus a new new popup window.
590IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_NewPopupUnfocused) {
meacerc62e2ee2014-10-22 00:44:52591 chrome::NavigateParams params(MakeNavigateParams());
592 params.disposition = NEW_POPUP;
593 params.window_bounds = gfx::Rect(0, 0, 200, 200);
594 params.window_action = chrome::NavigateParams::SHOW_WINDOW_INACTIVE;
[email protected]7d329992011-04-15 18:20:02595 // Wait for new popup to load (and gain focus if the test fails).
meacerc62e2ee2014-10-22 00:44:52596 ui_test_utils::NavigateToURL(&params);
[email protected]7d329992011-04-15 18:20:02597
598 // Navigate() should have opened a new, unfocused, popup window.
meacerc62e2ee2014-10-22 00:44:52599 EXPECT_NE(browser(), params.browser);
600 EXPECT_EQ(Browser::TYPE_POPUP, params.browser->type());
[email protected]9db263a2011-04-15 20:53:47601#if 0
602// TODO(stevenjb): Enable this test. See: crbug.com/79493
[email protected]7d329992011-04-15 18:20:02603 EXPECT_FALSE(p.browser->window()->IsActive());
[email protected]7d329992011-04-15 18:20:02604#endif
[email protected]9db263a2011-04-15 20:53:47605}
[email protected]7d329992011-04-15 18:20:02606
[email protected]d2202e22014-04-14 20:20:53607// This test verifies that navigating with WindowOpenDisposition = NEW_POPUP
608// and trusted_source = true results in a new Browser where is_trusted_source()
609// is true.
610IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_NewPopupTrusted) {
meacerc62e2ee2014-10-22 00:44:52611 chrome::NavigateParams params(MakeNavigateParams());
612 params.disposition = NEW_POPUP;
613 params.trusted_source = true;
614 params.window_bounds = gfx::Rect(0, 0, 200, 200);
[email protected]d2202e22014-04-14 20:20:53615 // Wait for new popup to to load and gain focus.
meacerc62e2ee2014-10-22 00:44:52616 ui_test_utils::NavigateToURL(&params);
[email protected]d2202e22014-04-14 20:20:53617
618 // Navigate() should have opened a new popup window of TYPE_TRUSTED_POPUP.
meacerc62e2ee2014-10-22 00:44:52619 EXPECT_NE(browser(), params.browser);
620 EXPECT_TRUE(params.browser->is_type_popup());
621 EXPECT_TRUE(params.browser->is_trusted_source());
[email protected]d2202e22014-04-14 20:20:53622}
623
624
[email protected]a1feae52010-10-11 22:14:45625// This test verifies that navigating with WindowOpenDisposition = NEW_WINDOW
626// always opens a new window.
627IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_NewWindow) {
meacerc62e2ee2014-10-22 00:44:52628 chrome::NavigateParams params(MakeNavigateParams());
629 params.disposition = NEW_WINDOW;
630 chrome::Navigate(&params);
[email protected]a1feae52010-10-11 22:14:45631
632 // Navigate() should have opened a new toplevel window.
meacerc62e2ee2014-10-22 00:44:52633 EXPECT_NE(browser(), params.browser);
634 EXPECT_TRUE(params.browser->is_type_tabbed());
[email protected]a1feae52010-10-11 22:14:45635
636 // We should now have two windows, the browser() provided by the framework and
637 // the new normal window.
[email protected]0665ebe2013-02-13 09:53:19638 EXPECT_EQ(2u, chrome::GetTotalBrowserCount());
[email protected]ee496952013-01-10 23:17:33639 EXPECT_EQ(1, browser()->tab_strip_model()->count());
meacerc62e2ee2014-10-22 00:44:52640 EXPECT_EQ(1, params.browser->tab_strip_model()->count());
[email protected]a1feae52010-10-11 22:14:45641}
642
643// This test verifies that navigating with WindowOpenDisposition = INCOGNITO
644// opens a new incognito window if no existing incognito window is present.
645IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_Incognito) {
meacerc62e2ee2014-10-22 00:44:52646 chrome::NavigateParams params(MakeNavigateParams());
647 params.disposition = OFF_THE_RECORD;
648 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());
673 params.disposition = OFF_THE_RECORD;
674 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
688// WindowOpenDisposition = SUPPRESS_OPEN.
689IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_SuppressOpen) {
690 RunSuppressTest(SUPPRESS_OPEN);
691}
692
693// This test verifies that no navigation action occurs when
694// WindowOpenDisposition = SAVE_TO_DISK.
695IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_SaveToDisk) {
696 RunSuppressTest(SAVE_TO_DISK);
697}
698
699// This test verifies that no navigation action occurs when
700// WindowOpenDisposition = IGNORE_ACTION.
701IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_IgnoreAction) {
702 RunSuppressTest(IGNORE_ACTION);
703}
704
[email protected]e232c992012-12-06 12:43:20705// This tests adding a foreground tab with a predefined WebContents.
[email protected]a1feae52010-10-11 22:14:45706IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, TargetContents_ForegroundTab) {
meacerc62e2ee2014-10-22 00:44:52707 chrome::NavigateParams params(MakeNavigateParams());
708 params.disposition = NEW_FOREGROUND_TAB;
709 params.target_contents = CreateWebContents();
710 chrome::Navigate(&params);
[email protected]a1feae52010-10-11 22:14:45711
712 // Navigate() should have opened the contents in a new foreground in the
713 // current Browser.
meacerc62e2ee2014-10-22 00:44:52714 EXPECT_EQ(browser(), params.browser);
[email protected]e232c992012-12-06 12:43:20715 EXPECT_EQ(browser()->tab_strip_model()->GetActiveWebContents(),
meacerc62e2ee2014-10-22 00:44:52716 params.target_contents);
[email protected]a1feae52010-10-11 22:14:45717
718 // We should have one window, with two tabs.
[email protected]0665ebe2013-02-13 09:53:19719 EXPECT_EQ(1u, chrome::GetTotalBrowserCount());
[email protected]ee496952013-01-10 23:17:33720 EXPECT_EQ(2, browser()->tab_strip_model()->count());
[email protected]a1feae52010-10-11 22:14:45721}
722
723#if defined(OS_WIN)
[email protected]e232c992012-12-06 12:43:20724// This tests adding a popup with a predefined WebContents.
[email protected]76edb672011-03-04 21:48:39725IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, DISABLED_TargetContents_Popup) {
meacerc62e2ee2014-10-22 00:44:52726 chrome::NavigateParams params(MakeNavigateParams());
727 params.disposition = NEW_POPUP;
728 params.target_contents = CreateWebContents();
729 params.window_bounds = gfx::Rect(10, 10, 500, 500);
730 chrome::Navigate(&params);
[email protected]a1feae52010-10-11 22:14:45731
732 // Navigate() should have opened a new popup window.
meacerc62e2ee2014-10-22 00:44:52733 EXPECT_NE(browser(), params.browser);
734 EXPECT_TRUE(params.browser->is_type_popup());
735 EXPECT_FALSE(params.browser->is_app());
[email protected]a1feae52010-10-11 22:14:45736
737 // The web platform is weird. The window bounds specified in
meacerc62e2ee2014-10-22 00:44:52738 // |params.window_bounds| are used as follows:
[email protected]a1feae52010-10-11 22:14:45739 // - the origin is used to position the window
[email protected]e232c992012-12-06 12:43:20740 // - the size is used to size the WebContents of the window.
[email protected]a1feae52010-10-11 22:14:45741 // As such the position of the resulting window will always match
meacerc62e2ee2014-10-22 00:44:52742 // params.window_bounds.origin(), but its size will not. We need to match
[email protected]a1feae52010-10-11 22:14:45743 // the size against the selected tab's view's container size.
meacerc62e2ee2014-10-22 00:44:52744 // Only Windows positions the window according to
745 // |params.window_bounds.origin()| - on Mac the window is offset from the
746 // opener and on Linux it always opens at 0,0.
747 EXPECT_EQ(params.window_bounds.origin(),
748 params.browser->window()->GetRestoredBounds().origin());
[email protected]a1feae52010-10-11 22:14:45749 // All platforms should respect size however provided width > 400 (Mac has a
750 // minimum window width of 400).
meacerc62e2ee2014-10-22 00:44:52751 EXPECT_EQ(params.window_bounds.size(),
752 params.target_contents->GetContainerBounds().size());
[email protected]a1feae52010-10-11 22:14:45753
754 // We should have two windows, the new popup and the browser() provided by the
755 // framework.
[email protected]0665ebe2013-02-13 09:53:19756 EXPECT_EQ(2u, chrome::GetTotalBrowserCount());
[email protected]ee496952013-01-10 23:17:33757 EXPECT_EQ(1, browser()->tab_strip_model()->count());
meacerc62e2ee2014-10-22 00:44:52758 EXPECT_EQ(1, params.browser->tab_strip_model()->count());
[email protected]a1feae52010-10-11 22:14:45759}
760#endif
761
762// This tests adding a tab at a specific index.
763IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Tabstrip_InsertAtIndex) {
764 // This is not meant to be a comprehensive test of whether or not the tab
765 // implementation of the browser observes the insertion index. That is
766 // covered by the unit tests for TabStripModel. This merely verifies that
767 // insertion index preference is reflected in common cases.
meacerc62e2ee2014-10-22 00:44:52768 chrome::NavigateParams params(MakeNavigateParams());
769 params.disposition = NEW_FOREGROUND_TAB;
770 params.tabstrip_index = 0;
771 params.tabstrip_add_types = TabStripModel::ADD_FORCE_INDEX;
772 chrome::Navigate(&params);
[email protected]a1feae52010-10-11 22:14:45773
774 // Navigate() should have inserted a new tab at slot 0 in the tabstrip.
meacerc62e2ee2014-10-22 00:44:52775 EXPECT_EQ(browser(), params.browser);
[email protected]e232c992012-12-06 12:43:20776 EXPECT_EQ(0, browser()->tab_strip_model()->GetIndexOfWebContents(
meacerc62e2ee2014-10-22 00:44:52777 static_cast<const WebContents*>(params.target_contents)));
[email protected]a1feae52010-10-11 22:14:45778
779 // We should have one window - the browser() provided by the framework.
[email protected]0665ebe2013-02-13 09:53:19780 EXPECT_EQ(1u, chrome::GetTotalBrowserCount());
[email protected]ee496952013-01-10 23:17:33781 EXPECT_EQ(2, browser()->tab_strip_model()->count());
[email protected]a1feae52010-10-11 22:14:45782}
783
[email protected]bb89e7482010-11-17 18:27:04784// This test verifies that constructing params with disposition = SINGLETON_TAB
[email protected]fee320542011-03-02 01:30:49785// and IGNORE_AND_NAVIGATE opens a new tab navigated to the specified URL if
[email protected]67ed83e2011-01-07 22:54:00786// no previous tab with that URL (minus the path) exists.
[email protected]bb89e7482010-11-17 18:27:04787IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
788 Disposition_SingletonTabNew_IgnorePath) {
[email protected]52877dbc62012-06-29 22:22:03789 chrome::AddSelectedTabWithURL(browser(), GetGoogleURL(),
Sylvain Defresnec6ccc77d2014-09-19 10:19:35790 ui::PAGE_TRANSITION_LINK);
[email protected]bb89e7482010-11-17 18:27:04791
792 // We should have one browser with 2 tabs, the 2nd selected.
[email protected]0665ebe2013-02-13 09:53:19793 EXPECT_EQ(1u, chrome::GetTotalBrowserCount());
[email protected]ee496952013-01-10 23:17:33794 EXPECT_EQ(2, browser()->tab_strip_model()->count());
795 EXPECT_EQ(1, browser()->tab_strip_model()->active_index());
[email protected]bb89e7482010-11-17 18:27:04796
797 // Navigate to a new singleton tab with a sub-page.
meacerc62e2ee2014-10-22 00:44:52798 chrome::NavigateParams params(MakeNavigateParams());
799 params.disposition = SINGLETON_TAB;
800 params.url = GetContentSettingsURL();
801 params.window_action = chrome::NavigateParams::SHOW_WINDOW;
802 params.path_behavior = chrome::NavigateParams::IGNORE_AND_NAVIGATE;
803 chrome::Navigate(&params);
[email protected]bb89e7482010-11-17 18:27:04804
805 // The last tab should now be selected and navigated to the sub-page of the
[email protected]50592b52013-05-02 22:26:25806 // URL.
meacerc62e2ee2014-10-22 00:44:52807 EXPECT_EQ(browser(), params.browser);
[email protected]ee496952013-01-10 23:17:33808 EXPECT_EQ(3, browser()->tab_strip_model()->count());
809 EXPECT_EQ(2, browser()->tab_strip_model()->active_index());
[email protected]a048ad22012-03-23 04:26:56810 EXPECT_EQ(GetContentSettingsURL(),
[email protected]ee496952013-01-10 23:17:33811 ShortenUberURL(browser()->tab_strip_model()->
812 GetActiveWebContents()->GetURL()));
[email protected]bb89e7482010-11-17 18:27:04813}
814
815// This test verifies that constructing params with disposition = SINGLETON_TAB
[email protected]fee320542011-03-02 01:30:49816// and IGNORE_AND_NAVIGATE opens an existing tab with the matching URL (minus
[email protected]bb89e7482010-11-17 18:27:04817// the path) which is navigated to the specified URL.
818IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
819 Disposition_SingletonTabExisting_IgnorePath) {
[email protected]ddddfda2011-07-14 23:19:39820 GURL singleton_url1(GetSettingsURL());
[email protected]52877dbc62012-06-29 22:22:03821 chrome::AddSelectedTabWithURL(browser(), singleton_url1,
Sylvain Defresnec6ccc77d2014-09-19 10:19:35822 ui::PAGE_TRANSITION_LINK);
[email protected]52877dbc62012-06-29 22:22:03823 chrome::AddSelectedTabWithURL(browser(), GetGoogleURL(),
Sylvain Defresnec6ccc77d2014-09-19 10:19:35824 ui::PAGE_TRANSITION_LINK);
[email protected]bb89e7482010-11-17 18:27:04825
826 // We should have one browser with 3 tabs, the 3rd selected.
[email protected]0665ebe2013-02-13 09:53:19827 EXPECT_EQ(1u, chrome::GetTotalBrowserCount());
[email protected]ee496952013-01-10 23:17:33828 EXPECT_EQ(3, browser()->tab_strip_model()->count());
829 EXPECT_EQ(2, browser()->tab_strip_model()->active_index());
[email protected]bb89e7482010-11-17 18:27:04830
831 // Navigate to singleton_url1.
meacerc62e2ee2014-10-22 00:44:52832 chrome::NavigateParams params(MakeNavigateParams());
833 params.disposition = SINGLETON_TAB;
834 params.url = GetContentSettingsURL();
835 params.window_action = chrome::NavigateParams::SHOW_WINDOW;
836 params.path_behavior = chrome::NavigateParams::IGNORE_AND_NAVIGATE;
837 chrome::Navigate(&params);
[email protected]bb89e7482010-11-17 18:27:04838
839 // The middle tab should now be selected and navigated to the sub-page of the
840 // URL.
meacerc62e2ee2014-10-22 00:44:52841 EXPECT_EQ(browser(), params.browser);
[email protected]ee496952013-01-10 23:17:33842 EXPECT_EQ(3, browser()->tab_strip_model()->count());
843 EXPECT_EQ(1, browser()->tab_strip_model()->active_index());
[email protected]a048ad22012-03-23 04:26:56844 EXPECT_EQ(GetContentSettingsURL(),
[email protected]ee496952013-01-10 23:17:33845 ShortenUberURL(browser()->tab_strip_model()->
846 GetActiveWebContents()->GetURL()));
[email protected]bb89e7482010-11-17 18:27:04847}
848
849// This test verifies that constructing params with disposition = SINGLETON_TAB
[email protected]fee320542011-03-02 01:30:49850// and IGNORE_AND_NAVIGATE opens an existing tab with the matching URL (minus
[email protected]bb89e7482010-11-17 18:27:04851// the path) which is navigated to the specified URL.
852IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
853 Disposition_SingletonTabExistingSubPath_IgnorePath) {
[email protected]a048ad22012-03-23 04:26:56854 GURL singleton_url1(GetContentSettingsURL());
[email protected]52877dbc62012-06-29 22:22:03855 chrome::AddSelectedTabWithURL(browser(), singleton_url1,
Sylvain Defresnec6ccc77d2014-09-19 10:19:35856 ui::PAGE_TRANSITION_LINK);
[email protected]52877dbc62012-06-29 22:22:03857 chrome::AddSelectedTabWithURL(browser(), GetGoogleURL(),
Sylvain Defresnec6ccc77d2014-09-19 10:19:35858 ui::PAGE_TRANSITION_LINK);
[email protected]bb89e7482010-11-17 18:27:04859
860 // We should have one browser with 3 tabs, the 3rd selected.
[email protected]0665ebe2013-02-13 09:53:19861 EXPECT_EQ(1u, chrome::GetTotalBrowserCount());
[email protected]ee496952013-01-10 23:17:33862 EXPECT_EQ(3, browser()->tab_strip_model()->count());
863 EXPECT_EQ(2, browser()->tab_strip_model()->active_index());
[email protected]bb89e7482010-11-17 18:27:04864
865 // Navigate to singleton_url1.
meacerc62e2ee2014-10-22 00:44:52866 chrome::NavigateParams params(MakeNavigateParams());
867 params.disposition = SINGLETON_TAB;
868 params.url = GetClearBrowsingDataURL();
869 params.window_action = chrome::NavigateParams::SHOW_WINDOW;
870 params.path_behavior = chrome::NavigateParams::IGNORE_AND_NAVIGATE;
871 chrome::Navigate(&params);
[email protected]bb89e7482010-11-17 18:27:04872
873 // The middle tab should now be selected and navigated to the sub-page of the
874 // URL.
meacerc62e2ee2014-10-22 00:44:52875 EXPECT_EQ(browser(), params.browser);
[email protected]ee496952013-01-10 23:17:33876 EXPECT_EQ(3, browser()->tab_strip_model()->count());
877 EXPECT_EQ(1, browser()->tab_strip_model()->active_index());
[email protected]a048ad22012-03-23 04:26:56878 EXPECT_EQ(GetClearBrowsingDataURL(),
[email protected]ee496952013-01-10 23:17:33879 ShortenUberURL(browser()->tab_strip_model()->
880 GetActiveWebContents()->GetURL()));
[email protected]bb89e7482010-11-17 18:27:04881}
[email protected]2dd85482010-11-06 01:56:47882
[email protected]637b3442011-01-10 23:31:48883// This test verifies that constructing params with disposition = SINGLETON_TAB
[email protected]fee320542011-03-02 01:30:49884// and IGNORE_AND_STAY_PUT opens an existing tab with the matching URL (minus
885// the path).
886IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
887 Disposition_SingletonTabExistingSubPath_IgnorePath2) {
[email protected]a048ad22012-03-23 04:26:56888 GURL singleton_url1(GetContentSettingsURL());
[email protected]52877dbc62012-06-29 22:22:03889 chrome::AddSelectedTabWithURL(browser(), singleton_url1,
Sylvain Defresnec6ccc77d2014-09-19 10:19:35890 ui::PAGE_TRANSITION_LINK);
[email protected]52877dbc62012-06-29 22:22:03891 chrome::AddSelectedTabWithURL(browser(), GetGoogleURL(),
Sylvain Defresnec6ccc77d2014-09-19 10:19:35892 ui::PAGE_TRANSITION_LINK);
[email protected]fee320542011-03-02 01:30:49893
894 // We should have one browser with 3 tabs, the 3rd selected.
[email protected]0665ebe2013-02-13 09:53:19895 EXPECT_EQ(1u, chrome::GetTotalBrowserCount());
[email protected]ee496952013-01-10 23:17:33896 EXPECT_EQ(3, browser()->tab_strip_model()->count());
897 EXPECT_EQ(2, browser()->tab_strip_model()->active_index());
[email protected]fee320542011-03-02 01:30:49898
899 // Navigate to singleton_url1.
meacerc62e2ee2014-10-22 00:44:52900 chrome::NavigateParams params(MakeNavigateParams());
901 params.disposition = SINGLETON_TAB;
902 params.url = GetClearBrowsingDataURL();
903 params.window_action = chrome::NavigateParams::SHOW_WINDOW;
904 params.path_behavior = chrome::NavigateParams::IGNORE_AND_STAY_PUT;
905 chrome::Navigate(&params);
[email protected]fee320542011-03-02 01:30:49906
907 // The middle tab should now be selected.
meacerc62e2ee2014-10-22 00:44:52908 EXPECT_EQ(browser(), params.browser);
[email protected]ee496952013-01-10 23:17:33909 EXPECT_EQ(3, browser()->tab_strip_model()->count());
910 EXPECT_EQ(1, browser()->tab_strip_model()->active_index());
[email protected]fee320542011-03-02 01:30:49911 EXPECT_EQ(singleton_url1,
[email protected]ee496952013-01-10 23:17:33912 ShortenUberURL(browser()->tab_strip_model()->
913 GetActiveWebContents()->GetURL()));
[email protected]fee320542011-03-02 01:30:49914}
915
916// This test verifies that constructing params with disposition = SINGLETON_TAB
917// and IGNORE_AND_NAVIGATE will update the current tab's URL if the currently
[email protected]637b3442011-01-10 23:31:48918// selected tab is a match but has a different path.
919IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
920 Disposition_SingletonTabFocused_IgnorePath) {
[email protected]a048ad22012-03-23 04:26:56921 GURL singleton_url_current(GetContentSettingsURL());
[email protected]52877dbc62012-06-29 22:22:03922 chrome::AddSelectedTabWithURL(browser(), singleton_url_current,
Sylvain Defresnec6ccc77d2014-09-19 10:19:35923 ui::PAGE_TRANSITION_LINK);
[email protected]637b3442011-01-10 23:31:48924
925 // We should have one browser with 2 tabs, the 2nd selected.
[email protected]0665ebe2013-02-13 09:53:19926 EXPECT_EQ(1u, chrome::GetTotalBrowserCount());
[email protected]ee496952013-01-10 23:17:33927 EXPECT_EQ(2, browser()->tab_strip_model()->count());
928 EXPECT_EQ(1, browser()->tab_strip_model()->active_index());
[email protected]637b3442011-01-10 23:31:48929
930 // Navigate to a different settings path.
[email protected]a048ad22012-03-23 04:26:56931 GURL singleton_url_target(GetClearBrowsingDataURL());
meacerc62e2ee2014-10-22 00:44:52932 chrome::NavigateParams params(MakeNavigateParams());
933 params.disposition = SINGLETON_TAB;
934 params.url = singleton_url_target;
935 params.window_action = chrome::NavigateParams::SHOW_WINDOW;
936 params.path_behavior = chrome::NavigateParams::IGNORE_AND_NAVIGATE;
937 chrome::Navigate(&params);
[email protected]637b3442011-01-10 23:31:48938
939 // The second tab should still be selected, but navigated to the new path.
meacerc62e2ee2014-10-22 00:44:52940 EXPECT_EQ(browser(), params.browser);
[email protected]ee496952013-01-10 23:17:33941 EXPECT_EQ(2, browser()->tab_strip_model()->count());
942 EXPECT_EQ(1, browser()->tab_strip_model()->active_index());
[email protected]637b3442011-01-10 23:31:48943 EXPECT_EQ(singleton_url_target,
[email protected]ee496952013-01-10 23:17:33944 ShortenUberURL(browser()->tab_strip_model()->
945 GetActiveWebContents()->GetURL()));
[email protected]637b3442011-01-10 23:31:48946}
947
[email protected]07afd7c2011-02-17 10:07:11948// This test verifies that constructing params with disposition = SINGLETON_TAB
[email protected]fee320542011-03-02 01:30:49949// and IGNORE_AND_NAVIGATE will open an existing matching tab with a different
950// query.
[email protected]07afd7c2011-02-17 10:07:11951IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
952 Disposition_SingletonTabExisting_IgnoreQuery) {
[email protected]ee496952013-01-10 23:17:33953 int initial_tab_count = browser()->tab_strip_model()->count();
[email protected]07afd7c2011-02-17 10:07:11954 GURL singleton_url_current("chrome://settings/internet");
[email protected]52877dbc62012-06-29 22:22:03955 chrome::AddSelectedTabWithURL(browser(), singleton_url_current,
Sylvain Defresnec6ccc77d2014-09-19 10:19:35956 ui::PAGE_TRANSITION_LINK);
[email protected]07afd7c2011-02-17 10:07:11957
[email protected]ee496952013-01-10 23:17:33958 EXPECT_EQ(initial_tab_count + 1, browser()->tab_strip_model()->count());
959 EXPECT_EQ(initial_tab_count, browser()->tab_strip_model()->active_index());
[email protected]07afd7c2011-02-17 10:07:11960
961 // Navigate to a different settings path.
962 GURL singleton_url_target(
963 "chrome://settings/internet?"
stevenjb82dbc53092015-03-14 18:32:24964 "guid=ethernet_00aa00aa00aa&networkType=1");
meacerc62e2ee2014-10-22 00:44:52965 chrome::NavigateParams params(MakeNavigateParams());
966 params.disposition = SINGLETON_TAB;
967 params.url = singleton_url_target;
968 params.window_action = chrome::NavigateParams::SHOW_WINDOW;
969 params.path_behavior = chrome::NavigateParams::IGNORE_AND_NAVIGATE;
970 chrome::Navigate(&params);
[email protected]07afd7c2011-02-17 10:07:11971
972 // Last tab should still be selected.
meacerc62e2ee2014-10-22 00:44:52973 EXPECT_EQ(browser(), params.browser);
[email protected]ee496952013-01-10 23:17:33974 EXPECT_EQ(initial_tab_count + 1, browser()->tab_strip_model()->count());
975 EXPECT_EQ(initial_tab_count, browser()->tab_strip_model()->active_index());
[email protected]07afd7c2011-02-17 10:07:11976}
977
[email protected]bd817c22011-02-09 08:16:46978// This test verifies that the settings page isn't opened in the incognito
979// window.
[email protected]a048ad22012-03-23 04:26:56980// Disabled until fixed for uber settings: http://crbug.com/111243
[email protected]bd817c22011-02-09 08:16:46981IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
[email protected]a048ad22012-03-23 04:26:56982 DISABLED_Disposition_Settings_UseNonIncognitoWindow) {
[email protected]fc0ed302011-11-29 23:17:19983 RunUseNonIncognitoWindowTest(GetSettingsURL());
[email protected]bd817c22011-02-09 08:16:46984}
985
[email protected]429e9712013-04-30 09:35:50986// This test verifies that the view-source settings page isn't opened in the
987// incognito window.
988IN_PROC_BROWSER_TEST_F(
989 BrowserNavigatorTest,
990 Disposition_ViewSource_Settings_DoNothingIfIncognitoForced) {
[email protected]dbdda5402013-05-30 22:13:48991 std::string view_source(content::kViewSourceScheme);
[email protected]429e9712013-04-30 09:35:50992 view_source.append(":");
993 view_source.append(chrome::kChromeUISettingsURL);
994 RunDoNothingIfIncognitoIsForcedTest(GURL(view_source));
995}
996
997// This test verifies that the view-source settings page isn't opened in the
998// incognito window even if incognito mode is forced (does nothing in that
999// case).
1000IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
1001 Disposition_ViewSource_Settings_UseNonIncognitoWindow) {
[email protected]dbdda5402013-05-30 22:13:481002 std::string view_source(content::kViewSourceScheme);
[email protected]429e9712013-04-30 09:35:501003 view_source.append(":");
1004 view_source.append(chrome::kChromeUISettingsURL);
1005 RunUseNonIncognitoWindowTest(GURL(view_source));
1006}
1007
[email protected]82404cd2011-07-12 19:55:141008// This test verifies that the settings page isn't opened in the incognito
1009// window from a non-incognito window (bookmark open-in-incognito trigger).
[email protected]a048ad22012-03-23 04:26:561010// Disabled until fixed for uber settings: http://crbug.com/111243
[email protected]82404cd2011-07-12 19:55:141011IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
[email protected]a048ad22012-03-23 04:26:561012 DISABLED_Disposition_Settings_UseNonIncognitoWindowForBookmark) {
[email protected]78e2edc2012-07-01 23:32:281013 chrome::NavigateParams params(browser(), GetSettingsURL(),
Sylvain Defresnec6ccc77d2014-09-19 10:19:351014 ui::PAGE_TRANSITION_AUTO_BOOKMARK);
[email protected]82404cd2011-07-12 19:55:141015 params.disposition = OFF_THE_RECORD;
1016 {
[email protected]a7fe9112012-07-20 02:34:451017 content::WindowedNotificationObserver observer(
[email protected]ad50def52011-10-19 23:17:071018 content::NOTIFICATION_LOAD_STOP,
1019 content::NotificationService::AllSources());
[email protected]78e2edc2012-07-01 23:32:281020 chrome::Navigate(&params);
[email protected]82404cd2011-07-12 19:55:141021 observer.Wait();
1022 }
1023
[email protected]0665ebe2013-02-13 09:53:191024 EXPECT_EQ(1u, chrome::GetTotalBrowserCount());
[email protected]52877dbc62012-06-29 22:22:031025 EXPECT_EQ(GetSettingsURL(),
[email protected]ee496952013-01-10 23:17:331026 ShortenUberURL(browser()->tab_strip_model()->
1027 GetActiveWebContents()->GetURL()));
[email protected]82404cd2011-07-12 19:55:141028}
1029
[email protected]93ad8e1c2011-11-08 21:34:051030// Settings page is expected to always open in normal mode regardless
1031// of whether the user is trying to open it in incognito mode or not.
1032// This test verifies that if incognito mode is forced (by policy), settings
1033// page doesn't open at all.
[email protected]a048ad22012-03-23 04:26:561034// Disabled until fixed for uber settings: http://crbug.com/111243
[email protected]93ad8e1c2011-11-08 21:34:051035IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
[email protected]a048ad22012-03-23 04:26:561036 DISABLED_Disposition_Settings_DoNothingIfIncognitoIsForced) {
[email protected]fc0ed302011-11-29 23:17:191037 RunDoNothingIfIncognitoIsForcedTest(GetSettingsURL());
[email protected]93ad8e1c2011-11-08 21:34:051038}
1039
[email protected]bd817c22011-02-09 08:16:461040// This test verifies that the bookmarks page isn't opened in the incognito
1041// window.
1042IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
1043 Disposition_Bookmarks_UseNonIncognitoWindow) {
[email protected]fc0ed302011-11-29 23:17:191044 RunUseNonIncognitoWindowTest(GURL(chrome::kChromeUIBookmarksURL));
[email protected]bd817c22011-02-09 08:16:461045}
1046
[email protected]93ad8e1c2011-11-08 21:34:051047// Bookmark manager is expected to always open in normal mode regardless
1048// of whether the user is trying to open it in incognito mode or not.
1049// This test verifies that if incognito mode is forced (by policy), bookmark
1050// manager doesn't open at all.
1051IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
1052 Disposition_Bookmarks_DoNothingIfIncognitoIsForced) {
[email protected]fc0ed302011-11-29 23:17:191053 RunDoNothingIfIncognitoIsForcedTest(GURL(chrome::kChromeUIBookmarksURL));
1054}
[email protected]93ad8e1c2011-11-08 21:34:051055
[email protected]7de53c62011-05-13 06:44:161056// This test makes sure a crashed singleton tab reloads from a new navigation.
[email protected]c4c0c0a12014-07-23 17:06:021057// http://crbug.com/396371
[email protected]7de53c62011-05-13 06:44:161058IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
[email protected]c4c0c0a12014-07-23 17:06:021059 DISABLED_NavigateToCrashedSingletonTab) {
[email protected]a048ad22012-03-23 04:26:561060 GURL singleton_url(GetContentSettingsURL());
[email protected]5a1a52462012-11-15 03:35:161061 WebContents* web_contents = chrome::AddSelectedTabWithURL(
Sylvain Defresnec6ccc77d2014-09-19 10:19:351062 browser(), singleton_url, ui::PAGE_TRANSITION_LINK);
[email protected]7de53c62011-05-13 06:44:161063
1064 // We should have one browser with 2 tabs, the 2nd selected.
[email protected]0665ebe2013-02-13 09:53:191065 EXPECT_EQ(1u, chrome::GetTotalBrowserCount());
[email protected]ee496952013-01-10 23:17:331066 EXPECT_EQ(2, browser()->tab_strip_model()->count());
1067 EXPECT_EQ(1, browser()->tab_strip_model()->active_index());
[email protected]7de53c62011-05-13 06:44:161068
1069 // Kill the singleton tab.
[email protected]83ff91c2012-01-05 20:54:131070 web_contents->SetIsCrashed(base::TERMINATION_STATUS_PROCESS_CRASHED, -1);
1071 EXPECT_TRUE(web_contents->IsCrashed());
[email protected]7de53c62011-05-13 06:44:161072
meacerc62e2ee2014-10-22 00:44:521073 chrome::NavigateParams params(MakeNavigateParams());
1074 params.disposition = SINGLETON_TAB;
1075 params.url = singleton_url;
1076 params.window_action = chrome::NavigateParams::SHOW_WINDOW;
1077 params.path_behavior = chrome::NavigateParams::IGNORE_AND_NAVIGATE;
1078 ui_test_utils::NavigateToURL(&params);
[email protected]7de53c62011-05-13 06:44:161079
1080 // The tab should not be sad anymore.
[email protected]83ff91c2012-01-05 20:54:131081 EXPECT_FALSE(web_contents->IsCrashed());
[email protected]7de53c62011-05-13 06:44:161082}
1083
[email protected]fcca741b2011-06-17 22:46:371084IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
1085 NavigateFromDefaultToOptionsInSameTab) {
[email protected]ddddfda2011-07-14 23:19:391086 {
[email protected]a7fe9112012-07-20 02:34:451087 content::WindowedNotificationObserver observer(
[email protected]ad50def52011-10-19 23:17:071088 content::NOTIFICATION_LOAD_STOP,
1089 content::NotificationService::AllSources());
[email protected]5d9cace72012-06-21 16:07:121090 chrome::ShowSettings(browser());
[email protected]ddddfda2011-07-14 23:19:391091 observer.Wait();
1092 }
[email protected]ee496952013-01-10 23:17:331093 EXPECT_EQ(1, browser()->tab_strip_model()->count());
[email protected]52877dbc62012-06-29 22:22:031094 EXPECT_EQ(GetSettingsURL(),
[email protected]ee496952013-01-10 23:17:331095 ShortenUberURL(browser()->tab_strip_model()->
1096 GetActiveWebContents()->GetURL()));
[email protected]fcca741b2011-06-17 22:46:371097}
1098
1099IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
1100 NavigateFromBlankToOptionsInSameTab) {
meacerc62e2ee2014-10-22 00:44:521101 chrome::NavigateParams params(MakeNavigateParams());
1102 params.url = GURL(url::kAboutBlankURL);
1103 ui_test_utils::NavigateToURL(&params);
[email protected]fcca741b2011-06-17 22:46:371104
[email protected]ddddfda2011-07-14 23:19:391105 {
[email protected]a7fe9112012-07-20 02:34:451106 content::WindowedNotificationObserver observer(
[email protected]ad50def52011-10-19 23:17:071107 content::NOTIFICATION_LOAD_STOP,
1108 content::NotificationService::AllSources());
[email protected]5d9cace72012-06-21 16:07:121109 chrome::ShowSettings(browser());
[email protected]ddddfda2011-07-14 23:19:391110 observer.Wait();
1111 }
[email protected]ee496952013-01-10 23:17:331112 EXPECT_EQ(1, browser()->tab_strip_model()->count());
[email protected]52877dbc62012-06-29 22:22:031113 EXPECT_EQ(GetSettingsURL(),
[email protected]ee496952013-01-10 23:17:331114 ShortenUberURL(browser()->tab_strip_model()->
1115 GetActiveWebContents()->GetURL()));
[email protected]fcca741b2011-06-17 22:46:371116}
1117
1118IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
1119 NavigateFromNTPToOptionsInSameTab) {
meacerc62e2ee2014-10-22 00:44:521120 chrome::NavigateParams params(MakeNavigateParams());
1121 params.url = GURL(chrome::kChromeUINewTabURL);
1122 ui_test_utils::NavigateToURL(&params);
[email protected]ee496952013-01-10 23:17:331123 EXPECT_EQ(1, browser()->tab_strip_model()->count());
[email protected]27658f32013-11-14 03:20:371124 EXPECT_EQ(GURL(chrome::kChromeUINewTabURL),
1125 browser()->tab_strip_model()->GetActiveWebContents()->GetURL());
[email protected]fcca741b2011-06-17 22:46:371126
[email protected]ddddfda2011-07-14 23:19:391127 {
[email protected]a7fe9112012-07-20 02:34:451128 content::WindowedNotificationObserver observer(
[email protected]ad50def52011-10-19 23:17:071129 content::NOTIFICATION_LOAD_STOP,
1130 content::NotificationService::AllSources());
[email protected]5d9cace72012-06-21 16:07:121131 chrome::ShowSettings(browser());
[email protected]ddddfda2011-07-14 23:19:391132 observer.Wait();
1133 }
[email protected]ee496952013-01-10 23:17:331134 EXPECT_EQ(1, browser()->tab_strip_model()->count());
[email protected]52877dbc62012-06-29 22:22:031135 EXPECT_EQ(GetSettingsURL(),
[email protected]ee496952013-01-10 23:17:331136 ShortenUberURL(browser()->tab_strip_model()->
1137 GetActiveWebContents()->GetURL()));
[email protected]fcca741b2011-06-17 22:46:371138}
1139
1140IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
1141 NavigateFromPageToOptionsInNewTab) {
meacerc62e2ee2014-10-22 00:44:521142 chrome::NavigateParams params(MakeNavigateParams());
1143 ui_test_utils::NavigateToURL(&params);
[email protected]ee496952013-01-10 23:17:331144 EXPECT_EQ(GetGoogleURL(),
1145 browser()->tab_strip_model()->GetActiveWebContents()->GetURL());
[email protected]0665ebe2013-02-13 09:53:191146 EXPECT_EQ(1u, chrome::GetTotalBrowserCount());
[email protected]ee496952013-01-10 23:17:331147 EXPECT_EQ(1, browser()->tab_strip_model()->count());
[email protected]fcca741b2011-06-17 22:46:371148
[email protected]ddddfda2011-07-14 23:19:391149 {
[email protected]a7fe9112012-07-20 02:34:451150 content::WindowedNotificationObserver observer(
[email protected]ad50def52011-10-19 23:17:071151 content::NOTIFICATION_LOAD_STOP,
1152 content::NotificationService::AllSources());
[email protected]5d9cace72012-06-21 16:07:121153 chrome::ShowSettings(browser());
[email protected]ddddfda2011-07-14 23:19:391154 observer.Wait();
1155 }
[email protected]ee496952013-01-10 23:17:331156 EXPECT_EQ(2, browser()->tab_strip_model()->count());
[email protected]52877dbc62012-06-29 22:22:031157 EXPECT_EQ(GetSettingsURL(),
[email protected]ee496952013-01-10 23:17:331158 ShortenUberURL(browser()->tab_strip_model()->
1159 GetActiveWebContents()->GetURL()));
[email protected]fcca741b2011-06-17 22:46:371160}
1161
1162IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
1163 NavigateFromNTPToOptionsSingleton) {
[email protected]ddddfda2011-07-14 23:19:391164 {
[email protected]a7fe9112012-07-20 02:34:451165 content::WindowedNotificationObserver observer(
[email protected]ad50def52011-10-19 23:17:071166 content::NOTIFICATION_LOAD_STOP,
1167 content::NotificationService::AllSources());
[email protected]5d9cace72012-06-21 16:07:121168 chrome::ShowSettings(browser());
[email protected]ddddfda2011-07-14 23:19:391169 observer.Wait();
1170 }
[email protected]ee496952013-01-10 23:17:331171 EXPECT_EQ(1, browser()->tab_strip_model()->count());
[email protected]fcca741b2011-06-17 22:46:371172
[email protected]a37d4b02012-06-25 21:56:101173 chrome::NewTab(browser());
[email protected]ee496952013-01-10 23:17:331174 EXPECT_EQ(2, browser()->tab_strip_model()->count());
[email protected]fcca741b2011-06-17 22:46:371175
[email protected]ddddfda2011-07-14 23:19:391176 {
[email protected]a7fe9112012-07-20 02:34:451177 content::WindowedNotificationObserver observer(
[email protected]ad50def52011-10-19 23:17:071178 content::NOTIFICATION_LOAD_STOP,
1179 content::NotificationService::AllSources());
[email protected]5d9cace72012-06-21 16:07:121180 chrome::ShowSettings(browser());
[email protected]ddddfda2011-07-14 23:19:391181 observer.Wait();
1182 }
[email protected]ee496952013-01-10 23:17:331183 EXPECT_EQ(2, browser()->tab_strip_model()->count());
[email protected]52877dbc62012-06-29 22:22:031184 EXPECT_EQ(GetSettingsURL(),
[email protected]ee496952013-01-10 23:17:331185 ShortenUberURL(browser()->tab_strip_model()->
1186 GetActiveWebContents()->GetURL()));
[email protected]fcca741b2011-06-17 22:46:371187}
1188
1189IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
1190 NavigateFromNTPToOptionsPageInSameTab) {
[email protected]ddddfda2011-07-14 23:19:391191 {
[email protected]a7fe9112012-07-20 02:34:451192 content::WindowedNotificationObserver observer(
[email protected]ad50def52011-10-19 23:17:071193 content::NOTIFICATION_LOAD_STOP,
1194 content::NotificationService::AllSources());
[email protected]5d9cace72012-06-21 16:07:121195 chrome::ShowClearBrowsingDataDialog(browser());
[email protected]ddddfda2011-07-14 23:19:391196 observer.Wait();
1197 }
[email protected]ee496952013-01-10 23:17:331198 EXPECT_EQ(1, browser()->tab_strip_model()->count());
[email protected]a048ad22012-03-23 04:26:561199 EXPECT_EQ(GetClearBrowsingDataURL(),
[email protected]ee496952013-01-10 23:17:331200 browser()->tab_strip_model()->GetActiveWebContents()->GetURL());
[email protected]fcca741b2011-06-17 22:46:371201
[email protected]a37d4b02012-06-25 21:56:101202 chrome::NewTab(browser());
[email protected]ee496952013-01-10 23:17:331203 EXPECT_EQ(2, browser()->tab_strip_model()->count());
[email protected]fcca741b2011-06-17 22:46:371204
[email protected]ddddfda2011-07-14 23:19:391205 {
[email protected]a7fe9112012-07-20 02:34:451206 content::WindowedNotificationObserver observer(
[email protected]ad50def52011-10-19 23:17:071207 content::NOTIFICATION_LOAD_STOP,
1208 content::NotificationService::AllSources());
[email protected]5d9cace72012-06-21 16:07:121209 chrome::ShowClearBrowsingDataDialog(browser());
[email protected]ddddfda2011-07-14 23:19:391210 observer.Wait();
1211 }
[email protected]ee496952013-01-10 23:17:331212 EXPECT_EQ(2, browser()->tab_strip_model()->count());
[email protected]a048ad22012-03-23 04:26:561213 EXPECT_EQ(GetClearBrowsingDataURL(),
[email protected]ee496952013-01-10 23:17:331214 browser()->tab_strip_model()->GetActiveWebContents()->GetURL());
[email protected]fcca741b2011-06-17 22:46:371215}
1216
1217IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
[email protected]05912742013-03-12 00:29:151218 NavigateFromOtherTabToSingletonOptions) {
[email protected]ddddfda2011-07-14 23:19:391219 {
[email protected]a7fe9112012-07-20 02:34:451220 content::WindowedNotificationObserver observer(
[email protected]ad50def52011-10-19 23:17:071221 content::NOTIFICATION_LOAD_STOP,
1222 content::NotificationService::AllSources());
[email protected]5d9cace72012-06-21 16:07:121223 chrome::ShowSettings(browser());
[email protected]ddddfda2011-07-14 23:19:391224 observer.Wait();
1225 }
1226 {
[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());
[email protected]52877dbc62012-06-29 22:22:031230 chrome::AddSelectedTabWithURL(browser(), GetGoogleURL(),
Sylvain Defresnec6ccc77d2014-09-19 10:19:351231 ui::PAGE_TRANSITION_LINK);
[email protected]ddddfda2011-07-14 23:19:391232 observer.Wait();
1233 }
[email protected]fcca741b2011-06-17 22:46:371234
[email protected]05912742013-03-12 00:29:151235 // This load should simply cause a tab switch.
1236 chrome::ShowSettings(browser());
1237
[email protected]ee496952013-01-10 23:17:331238 EXPECT_EQ(2, browser()->tab_strip_model()->count());
[email protected]ddddfda2011-07-14 23:19:391239 EXPECT_EQ(GetSettingsURL(),
[email protected]ee496952013-01-10 23:17:331240 ShortenUberURL(browser()->tab_strip_model()->
1241 GetActiveWebContents()->GetURL()));
[email protected]fcca741b2011-06-17 22:46:371242}
1243
[email protected]4e78b2d2013-06-12 16:46:171244IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, CloseSingletonTab) {
[email protected]79717cf2013-02-28 18:40:361245 for (int i = 0; i < 2; ++i) {
1246 content::WindowedNotificationObserver observer(
1247 content::NOTIFICATION_LOAD_STOP,
1248 content::NotificationService::AllSources());
1249 chrome::AddSelectedTabWithURL(browser(), GetGoogleURL(),
Sylvain Defresnec6ccc77d2014-09-19 10:19:351250 ui::PAGE_TRANSITION_TYPED);
[email protected]79717cf2013-02-28 18:40:361251 observer.Wait();
1252 }
1253
1254 browser()->tab_strip_model()->ActivateTabAt(0, true);
1255
1256 {
1257 content::WindowedNotificationObserver observer(
1258 content::NOTIFICATION_LOAD_STOP,
1259 content::NotificationService::AllSources());
1260 chrome::ShowSettings(browser());
1261 observer.Wait();
1262 }
1263
1264 EXPECT_TRUE(browser()->tab_strip_model()->CloseWebContentsAt(
1265 2, TabStripModel::CLOSE_USER_GESTURE));
1266 EXPECT_EQ(0, browser()->tab_strip_model()->active_index());
1267}
1268
[email protected]a048ad22012-03-23 04:26:561269// TODO(csilv): Update this for uber page. http://crbug.com/111579.
[email protected]ddddfda2011-07-14 23:19:391270IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
[email protected]a048ad22012-03-23 04:26:561271 DISABLED_NavigateFromDefaultToHistoryInSameTab) {
[email protected]ddddfda2011-07-14 23:19:391272 {
[email protected]a7fe9112012-07-20 02:34:451273 content::WindowedNotificationObserver observer(
[email protected]ad50def52011-10-19 23:17:071274 content::NOTIFICATION_LOAD_STOP,
1275 content::NotificationService::AllSources());
[email protected]5d9cace72012-06-21 16:07:121276 chrome::ShowHistory(browser());
[email protected]ddddfda2011-07-14 23:19:391277 observer.Wait();
1278 }
[email protected]ee496952013-01-10 23:17:331279 EXPECT_EQ(1, browser()->tab_strip_model()->count());
[email protected]11e03fb2012-03-03 19:07:051280 EXPECT_EQ(GURL(chrome::kChromeUIHistoryFrameURL),
[email protected]ee496952013-01-10 23:17:331281 browser()->tab_strip_model()->GetActiveWebContents()->GetURL());
[email protected]ddddfda2011-07-14 23:19:391282}
1283
[email protected]953c2132013-02-23 05:56:051284// TODO(linux_aura) http://crbug.com/163931
1285#if defined(OS_LINUX) && !defined(OS_CHROMEOS) && defined(USE_AURA)
1286#define MAYBE_NavigateFromDefaultToBookmarksInSameTab DISABLED_NavigateFromDefaultToBookmarksInSameTab
1287#else
1288#define MAYBE_NavigateFromDefaultToBookmarksInSameTab NavigateFromDefaultToBookmarksInSameTab
1289#endif
[email protected]ddddfda2011-07-14 23:19:391290IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
[email protected]953c2132013-02-23 05:56:051291 MAYBE_NavigateFromDefaultToBookmarksInSameTab) {
[email protected]ddddfda2011-07-14 23:19:391292 {
[email protected]a7fe9112012-07-20 02:34:451293 content::WindowedNotificationObserver observer(
[email protected]ad50def52011-10-19 23:17:071294 content::NOTIFICATION_LOAD_STOP,
1295 content::NotificationService::AllSources());
[email protected]5d9cace72012-06-21 16:07:121296 chrome::ShowBookmarkManager(browser());
[email protected]ddddfda2011-07-14 23:19:391297 observer.Wait();
1298 }
[email protected]ee496952013-01-10 23:17:331299 EXPECT_EQ(1, browser()->tab_strip_model()->count());
brettw66d1b81b2015-07-06 19:29:401300 EXPECT_TRUE(base::StartsWith(
[email protected]bc16a252013-01-23 02:21:491301 browser()->tab_strip_model()->GetActiveWebContents()->GetURL().spec(),
brettw66d1b81b2015-07-06 19:29:401302 chrome::kChromeUIBookmarksURL, base::CompareCase::SENSITIVE));
[email protected]ddddfda2011-07-14 23:19:391303}
1304
1305IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
1306 NavigateFromDefaultToDownloadsInSameTab) {
1307 {
[email protected]a7fe9112012-07-20 02:34:451308 content::WindowedNotificationObserver observer(
[email protected]ad50def52011-10-19 23:17:071309 content::NOTIFICATION_LOAD_STOP,
1310 content::NotificationService::AllSources());
[email protected]5d9cace72012-06-21 16:07:121311 chrome::ShowDownloads(browser());
[email protected]ddddfda2011-07-14 23:19:391312 observer.Wait();
1313 }
[email protected]ee496952013-01-10 23:17:331314 EXPECT_EQ(1, browser()->tab_strip_model()->count());
[email protected]ddddfda2011-07-14 23:19:391315 EXPECT_EQ(GURL(chrome::kChromeUIDownloadsURL),
[email protected]ee496952013-01-10 23:17:331316 browser()->tab_strip_model()->GetActiveWebContents()->GetURL());
[email protected]ddddfda2011-07-14 23:19:391317}
1318
[email protected]8fb16a82012-08-17 02:17:591319IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
1320 NavigateWithoutBrowser) {
1321 // First navigate using the profile of the existing browser window, and
1322 // check that the window is reused.
1323 chrome::NavigateParams params(browser()->profile(), GetGoogleURL(),
Sylvain Defresnec6ccc77d2014-09-19 10:19:351324 ui::PAGE_TRANSITION_LINK);
[email protected]8fb16a82012-08-17 02:17:591325 ui_test_utils::NavigateToURL(&params);
[email protected]0665ebe2013-02-13 09:53:191326 EXPECT_EQ(1u, chrome::GetTotalBrowserCount());
[email protected]8fb16a82012-08-17 02:17:591327
1328 // Now navigate using the incognito profile and check that a new window
1329 // is created.
1330 chrome::NavigateParams params_incognito(
1331 browser()->profile()->GetOffTheRecordProfile(),
Sylvain Defresnec6ccc77d2014-09-19 10:19:351332 GetGoogleURL(), ui::PAGE_TRANSITION_LINK);
[email protected]8fb16a82012-08-17 02:17:591333 ui_test_utils::NavigateToURL(&params_incognito);
[email protected]0665ebe2013-02-13 09:53:191334 EXPECT_EQ(2u, chrome::GetTotalBrowserCount());
[email protected]8fb16a82012-08-17 02:17:591335}
1336
[email protected]beb1d1192013-05-14 04:47:511337IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, ViewSourceIsntSingleton) {
1338 const std::string viewsource_ntp_url =
[email protected]dbdda5402013-05-30 22:13:481339 std::string(content::kViewSourceScheme) + ":" +
[email protected]beb1d1192013-05-14 04:47:511340 chrome::kChromeUIVersionURL;
1341
1342 chrome::NavigateParams viewsource_params(browser(),
1343 GURL(viewsource_ntp_url),
Sylvain Defresnec6ccc77d2014-09-19 10:19:351344 ui::PAGE_TRANSITION_LINK);
[email protected]beb1d1192013-05-14 04:47:511345 ui_test_utils::NavigateToURL(&viewsource_params);
1346
1347 chrome::NavigateParams singleton_params(browser(),
1348 GURL(chrome::kChromeUIVersionURL),
Sylvain Defresnec6ccc77d2014-09-19 10:19:351349 ui::PAGE_TRANSITION_LINK);
[email protected]beb1d1192013-05-14 04:47:511350 singleton_params.disposition = SINGLETON_TAB;
1351 EXPECT_EQ(-1, chrome::GetIndexOfSingletonTab(&singleton_params));
1352}
1353
[email protected]a2efc35d2013-08-03 23:17:251354// This test verifies that browser initiated navigations can send requests
1355// using POST.
1356IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
1357 SendBrowserInitiatedRequestUsingPOST) {
1358 // Uses a test sever to verify POST request.
svaldeza01f7d92015-11-18 17:47:561359 ASSERT_TRUE(embedded_test_server()->Start());
[email protected]a2efc35d2013-08-03 23:17:251360
1361 // Open a browser initiated POST request in new foreground tab.
[email protected]e9273e192013-12-11 17:51:491362 base::string16 expected_title(base::ASCIIToUTF16(kExpectedTitle));
[email protected]a2efc35d2013-08-03 23:17:251363 std::string post_data = kExpectedTitle;
[email protected]e9273e192013-12-11 17:51:491364 base::string16 title;
[email protected]a2efc35d2013-08-03 23:17:251365 ASSERT_TRUE(OpenPOSTURLInNewForegroundTabAndGetTitle(
svaldeza01f7d92015-11-18 17:47:561366 embedded_test_server()->GetURL(kEchoTitleCommand), post_data, true,
1367 &title));
[email protected]a2efc35d2013-08-03 23:17:251368 EXPECT_EQ(expected_title, title);
1369}
1370
1371// This test verifies that renderer initiated navigations can NOT send requests
1372// using POST.
1373IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
1374 SendRendererInitiatedRequestUsingPOST) {
1375 // Uses a test sever to verify POST request.
svaldeza01f7d92015-11-18 17:47:561376 ASSERT_TRUE(embedded_test_server()->Start());
[email protected]a2efc35d2013-08-03 23:17:251377
1378 // Open a renderer initiated POST request in new foreground tab.
[email protected]e9273e192013-12-11 17:51:491379 base::string16 expected_title(base::ASCIIToUTF16(kExpectedTitle));
[email protected]a2efc35d2013-08-03 23:17:251380 std::string post_data = kExpectedTitle;
[email protected]e9273e192013-12-11 17:51:491381 base::string16 title;
[email protected]a2efc35d2013-08-03 23:17:251382 ASSERT_TRUE(OpenPOSTURLInNewForegroundTabAndGetTitle(
svaldeza01f7d92015-11-18 17:47:561383 embedded_test_server()->GetURL(kEchoTitleCommand), post_data, false,
1384 &title));
[email protected]a2efc35d2013-08-03 23:17:251385 EXPECT_NE(expected_title, title);
1386}
1387
meacerc62e2ee2014-10-22 00:44:521388// This test navigates to a data URL that contains BiDi control
1389// characters. For security reasons, BiDi control chars should always be
1390// escaped in the URL but they should be unescaped in the loaded HTML.
1391IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
1392 NavigateToDataURLWithBiDiControlChars) {
1393 // Text in Arabic.
1394 std::string text = "\xD8\xA7\xD8\xAE\xD8\xAA\xD8\xA8\xD8\xA7\xD8\xB1";
1395 // Page title starts with RTL mark.
1396 std::string unescaped_title = "\xE2\x80\x8F" + text;
1397 std::string data_url = "data:text/html;charset=utf-8,<html><title>" +
1398 unescaped_title + "</title></html>";
1399 // BiDi control chars in URLs are always escaped, so the expected URL should
1400 // have the title with the escaped RTL mark.
1401 std::string escaped_title = "%E2%80%8F" + text;
1402 std::string expected_url = "data:text/html;charset=utf-8,<html><title>" +
1403 escaped_title + "</title></html>";
1404
1405 // Navigate to the page.
1406 chrome::NavigateParams params(MakeNavigateParams());
1407 params.disposition = NEW_FOREGROUND_TAB;
1408 params.url = GURL(data_url);
1409 params.window_action = chrome::NavigateParams::SHOW_WINDOW;
1410 ui_test_utils::NavigateToURL(&params);
1411
1412 base::string16 expected_title(base::UTF8ToUTF16(unescaped_title));
1413 EXPECT_TRUE(params.target_contents);
1414 EXPECT_EQ(expected_title, params.target_contents->GetTitle());
1415 // GURL always keeps non-ASCII characters escaped, but check them anyways.
1416 EXPECT_EQ(GURL(expected_url).spec(), params.target_contents->GetURL().spec());
1417 // Check the omnibox text. It should have escaped RTL with unescaped text.
1418 LocationBar* location_bar = browser()->window()->GetLocationBar();
1419 OmniboxView* omnibox_view = location_bar->GetOmniboxView();
1420 EXPECT_EQ(base::UTF8ToUTF16(expected_url), omnibox_view->GetText());
1421}
1422
[email protected]a2efc35d2013-08-03 23:17:251423} // namespace