blob: ba50af6eb40eb7614eef59226b8749f8f23047ac [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"
[email protected]a1feae52010-10-11 22:14:4533
[email protected]4ca15302012-01-03 05:53:2034using content::WebContents;
35
[email protected]ddddfda2011-07-14 23:19:3936namespace {
37
[email protected]a2efc35d2013-08-03 23:17:2538const char kExpectedTitle[] = "PASSED!";
39const char kEchoTitleCommand[] = "echotitle";
40
[email protected]ddddfda2011-07-14 23:19:3941GURL GetGoogleURL() {
[email protected]bd817c22011-02-09 08:16:4642 return GURL("http://www.google.com/");
43}
[email protected]a1feae52010-10-11 22:14:4544
[email protected]ddddfda2011-07-14 23:19:3945GURL GetSettingsURL() {
[email protected]f8f93eb2012-09-25 03:06:2446 return GURL(chrome::kChromeUISettingsURL);
[email protected]ddddfda2011-07-14 23:19:3947}
48
[email protected]a048ad22012-03-23 04:26:5649GURL GetContentSettingsURL() {
50 return GetSettingsURL().Resolve(chrome::kContentSettingsExceptionsSubPage);
[email protected]ddddfda2011-07-14 23:19:3951}
52
[email protected]a048ad22012-03-23 04:26:5653GURL GetClearBrowsingDataURL() {
54 return GetSettingsURL().Resolve(chrome::kClearBrowserDataSubPage);
[email protected]ddddfda2011-07-14 23:19:3955}
56
[email protected]f8f93eb2012-09-25 03:06:2457// Converts long uber URLs ("chrome://chrome/foo/") to short (virtual) URLs
58// ("chrome://foo/"). This should be used to convert the return value of
59// WebContentsImpl::GetURL before comparison because it can return either the
60// real URL or the virtual URL.
61GURL ShortenUberURL(const GURL& url) {
62 std::string url_string = url.spec();
63 const std::string long_prefix = "chrome://chrome/";
64 const std::string short_prefix = "chrome://";
65 if (url_string.find(long_prefix) != 0)
66 return url;
67 url_string.replace(0, long_prefix.length(), short_prefix);
68 return GURL(url_string);
69}
70
[email protected]a2efc35d2013-08-03 23:17:2571} // namespace
[email protected]ddddfda2011-07-14 23:19:3972
[email protected]78e2edc2012-07-01 23:32:2873chrome::NavigateParams BrowserNavigatorTest::MakeNavigateParams() const {
[email protected]bd817c22011-02-09 08:16:4674 return MakeNavigateParams(browser());
75}
[email protected]a1feae52010-10-11 22:14:4576
[email protected]78e2edc2012-07-01 23:32:2877chrome::NavigateParams BrowserNavigatorTest::MakeNavigateParams(
[email protected]bd817c22011-02-09 08:16:4678 Browser* browser) const {
[email protected]78e2edc2012-07-01 23:32:2879 chrome::NavigateParams params(browser, GetGoogleURL(),
Sylvain Defresnec6ccc77d2014-09-19 10:19:3580 ui::PAGE_TRANSITION_LINK);
[email protected]50592b52013-05-02 22:26:2581 params.window_action = chrome::NavigateParams::SHOW_WINDOW;
[email protected]bd817c22011-02-09 08:16:4682 return params;
83}
[email protected]a1feae52010-10-11 22:14:4584
[email protected]a2efc35d2013-08-03 23:17:2585bool BrowserNavigatorTest::OpenPOSTURLInNewForegroundTabAndGetTitle(
86 const GURL& url, const std::string& post_data, bool is_browser_initiated,
87 base::string16* title) {
88 chrome::NavigateParams param(MakeNavigateParams());
89 param.disposition = NEW_FOREGROUND_TAB;
90 param.url = url;
91 param.is_renderer_initiated = !is_browser_initiated;
92 param.uses_post = true;
93 param.browser_initiated_post_data = new base::RefCountedStaticMemory(
[email protected]8df08cf2014-02-12 22:34:0894 post_data.data(), post_data.size());
[email protected]a2efc35d2013-08-03 23:17:2595
96 ui_test_utils::NavigateToURL(&param);
97 if (!param.target_contents)
98 return false;
99
100 // Navigate() should have opened the contents in new foreground tab in the
101 // current Browser.
102 EXPECT_EQ(browser(), param.browser);
103 EXPECT_EQ(browser()->tab_strip_model()->GetActiveWebContents(),
104 param.target_contents);
105 // We should have one window, with one tab.
106 EXPECT_EQ(1u, chrome::GetTotalBrowserCount());
107 EXPECT_EQ(2, browser()->tab_strip_model()->count());
108
109 *title = param.target_contents->GetTitle();
110 return true;
111}
112
[email protected]bd817c22011-02-09 08:16:46113Browser* BrowserNavigatorTest::CreateEmptyBrowserForType(Browser::Type type,
114 Profile* profile) {
[email protected]2b09ae552013-02-23 06:38:03115 Browser* browser = new Browser(
[email protected]ed2fa722013-06-25 20:37:34116 Browser::CreateParams(type, profile, chrome::GetActiveDesktop()));
[email protected]00509a32013-11-17 17:45:37117 chrome::AddTabAt(browser, GURL(), -1, true);
[email protected]bd817c22011-02-09 08:16:46118 return browser;
119}
[email protected]a1feae52010-10-11 22:14:45120
[email protected]d2202e22014-04-14 20:20:53121Browser* BrowserNavigatorTest::CreateEmptyBrowserForApp(Profile* profile) {
[email protected]a4fe67012012-07-25 20:14:29122 Browser* browser = new Browser(
[email protected]da22aa62012-04-04 18:54:35123 Browser::CreateParams::CreateForApp(
[email protected]d2202e22014-04-14 20:20:53124 "Test", false /* trusted_source */, gfx::Rect(), profile,
[email protected]ed2fa722013-06-25 20:37:34125 chrome::GetActiveDesktop()));
[email protected]00509a32013-11-17 17:45:37126 chrome::AddTabAt(browser, GURL(), -1, true);
[email protected]b35b26b32011-05-05 20:35:14127 return browser;
128}
129
[email protected]e232c992012-12-06 12:43:20130WebContents* BrowserNavigatorTest::CreateWebContents() {
[email protected]54944cde2012-12-09 09:24:59131 content::WebContents::CreateParams create_params(browser()->profile());
[email protected]ed245db2012-12-18 08:00:45132 content::WebContents* base_web_contents =
[email protected]ee496952013-01-10 23:17:33133 browser()->tab_strip_model()->GetActiveWebContents();
[email protected]ed245db2012-12-18 08:00:45134 if (base_web_contents) {
135 create_params.initial_size =
[email protected]fc2b46b2014-05-03 16:33:45136 base_web_contents->GetContainerBounds().size();
[email protected]ed245db2012-12-18 08:00:45137 }
[email protected]54944cde2012-12-09 09:24:59138 return WebContents::Create(create_params);
[email protected]bd817c22011-02-09 08:16:46139}
[email protected]a1feae52010-10-11 22:14:45140
[email protected]bd817c22011-02-09 08:16:46141void BrowserNavigatorTest::RunSuppressTest(WindowOpenDisposition disposition) {
[email protected]ee496952013-01-10 23:17:33142 GURL old_url = browser()->tab_strip_model()->GetActiveWebContents()->GetURL();
meacerc62e2ee2014-10-22 00:44:52143 chrome::NavigateParams params(MakeNavigateParams());
144 params.disposition = disposition;
145 chrome::Navigate(&params);
[email protected]a1feae52010-10-11 22:14:45146
[email protected]bd817c22011-02-09 08:16:46147 // Nothing should have happened as a result of Navigate();
[email protected]ee496952013-01-10 23:17:33148 EXPECT_EQ(1, browser()->tab_strip_model()->count());
[email protected]0665ebe2013-02-13 09:53:19149 EXPECT_EQ(1u, chrome::GetTotalBrowserCount());
[email protected]ee496952013-01-10 23:17:33150 EXPECT_EQ(old_url,
151 browser()->tab_strip_model()->GetActiveWebContents()->GetURL());
[email protected]bd817c22011-02-09 08:16:46152}
[email protected]bb89e7482010-11-17 18:27:04153
[email protected]fc0ed302011-11-29 23:17:19154void BrowserNavigatorTest::RunUseNonIncognitoWindowTest(const GURL& url) {
155 Browser* incognito_browser = CreateIncognitoBrowser();
156
[email protected]0665ebe2013-02-13 09:53:19157 EXPECT_EQ(2u, chrome::GetTotalBrowserCount());
[email protected]ee496952013-01-10 23:17:33158 EXPECT_EQ(1, browser()->tab_strip_model()->count());
159 EXPECT_EQ(1, incognito_browser->tab_strip_model()->count());
[email protected]fc0ed302011-11-29 23:17:19160
161 // Navigate to the page.
meacerc62e2ee2014-10-22 00:44:52162 chrome::NavigateParams params(MakeNavigateParams(incognito_browser));
163 params.disposition = SINGLETON_TAB;
164 params.url = url;
165 params.window_action = chrome::NavigateParams::SHOW_WINDOW;
166 chrome::Navigate(&params);
[email protected]fc0ed302011-11-29 23:17:19167
[email protected]50592b52013-05-02 22:26:25168 // This page should be opened in browser() window.
meacerc62e2ee2014-10-22 00:44:52169 EXPECT_NE(incognito_browser, params.browser);
170 EXPECT_EQ(browser(), params.browser);
[email protected]ee496952013-01-10 23:17:33171 EXPECT_EQ(2, browser()->tab_strip_model()->count());
172 EXPECT_EQ(url,
173 browser()->tab_strip_model()->GetActiveWebContents()->GetURL());
[email protected]fc0ed302011-11-29 23:17:19174}
175
176void BrowserNavigatorTest::RunDoNothingIfIncognitoIsForcedTest(
177 const GURL& url) {
178 Browser* browser = CreateIncognitoBrowser();
179
180 // Set kIncognitoModeAvailability to FORCED.
181 PrefService* prefs1 = browser->profile()->GetPrefs();
182 prefs1->SetInteger(prefs::kIncognitoModeAvailability,
183 IncognitoModePrefs::FORCED);
184 PrefService* prefs2 = browser->profile()->GetOriginalProfile()->GetPrefs();
185 prefs2->SetInteger(prefs::kIncognitoModeAvailability,
186 IncognitoModePrefs::FORCED);
187
188 // Navigate to the page.
meacerc62e2ee2014-10-22 00:44:52189 chrome::NavigateParams params(MakeNavigateParams(browser));
190 params.disposition = OFF_THE_RECORD;
191 params.url = url;
192 params.window_action = chrome::NavigateParams::SHOW_WINDOW;
193 chrome::Navigate(&params);
[email protected]fc0ed302011-11-29 23:17:19194
195 // The page should not be opened.
meacerc62e2ee2014-10-22 00:44:52196 EXPECT_EQ(browser, params.browser);
[email protected]ee496952013-01-10 23:17:33197 EXPECT_EQ(1, browser->tab_strip_model()->count());
[email protected]8e09c7af2014-06-10 11:46:17198 EXPECT_EQ(GURL(url::kAboutBlankURL),
[email protected]ee496952013-01-10 23:17:33199 browser->tab_strip_model()->GetActiveWebContents()->GetURL());
[email protected]fc0ed302011-11-29 23:17:19200}
201
[email protected]aae79572014-06-13 00:42:58202void BrowserNavigatorTest::SetUpCommandLine(base::CommandLine* command_line) {
203 // Disable settings-in-a-window so that we can use the settings page and
204 // sub-pages to test browser navigation.
205 command_line->AppendSwitch(::switches::kDisableSettingsWindow);
benwellsf3c6fac2015-09-01 23:38:52206
207 // Disable new downloads UI as it is very very slow. https://crbug.com/526577
208 // TODO(dbeam): remove this once the downloads UI is not slow.
209 command_line->AppendSwitch(switches::kDisableMaterialDesignDownloads);
[email protected]aae79572014-06-13 00:42:58210}
211
[email protected]6c2381d2011-10-19 02:52:53212void BrowserNavigatorTest::Observe(
213 int type,
214 const content::NotificationSource& source,
215 const content::NotificationDetails& details) {
[email protected]432115822011-07-10 15:52:27216 switch (type) {
[email protected]d53a08c2012-07-18 20:35:30217 case content::NOTIFICATION_WEB_CONTENTS_RENDER_VIEW_HOST_CREATED: {
[email protected]bd817c22011-02-09 08:16:46218 ++this->created_tab_contents_count_;
219 break;
[email protected]fa7ebe02010-11-29 23:04:57220 }
[email protected]bd817c22011-02-09 08:16:46221 default:
222 break;
[email protected]fa7ebe02010-11-29 23:04:57223 }
[email protected]bd817c22011-02-09 08:16:46224}
[email protected]fa7ebe02010-11-29 23:04:57225
[email protected]ddddfda2011-07-14 23:19:39226
[email protected]bd817c22011-02-09 08:16:46227namespace {
[email protected]a1feae52010-10-11 22:14:45228
[email protected]a1feae52010-10-11 22:14:45229// This test verifies that when a navigation occurs within a tab, the tab count
230// of the Browser remains the same and the current tab bears the loaded URL.
[email protected]59167c22013-06-03 18:07:32231// Note that network URLs are not actually loaded in tests, so this also tests
232// that error pages leave the intended URL in the address bar.
[email protected]a1feae52010-10-11 22:14:45233IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_CurrentTab) {
[email protected]ddddfda2011-07-14 23:19:39234 ui_test_utils::NavigateToURL(browser(), GetGoogleURL());
[email protected]ee496952013-01-10 23:17:33235 EXPECT_EQ(GetGoogleURL(),
236 browser()->tab_strip_model()->GetActiveWebContents()->GetURL());
[email protected]a1feae52010-10-11 22:14:45237 // We should have one window with one tab.
[email protected]0665ebe2013-02-13 09:53:19238 EXPECT_EQ(1u, chrome::GetTotalBrowserCount());
[email protected]ee496952013-01-10 23:17:33239 EXPECT_EQ(1, browser()->tab_strip_model()->count());
[email protected]a1feae52010-10-11 22:14:45240}
241
[email protected]bd817c22011-02-09 08:16:46242// This test verifies that a singleton tab is refocused if one is already opened
[email protected]19d9f3a2010-10-14 21:49:36243// in another or an existing window, or added if it is not.
244IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_SingletonTabExisting) {
[email protected]19d9f3a2010-10-14 21:49:36245 GURL singleton_url1("http://maps.google.com/");
[email protected]fa7ebe02010-11-29 23:04:57246
[email protected]e232c992012-12-06 12:43:20247 // Register for a notification if an additional WebContents was instantiated.
[email protected]bd817c22011-02-09 08:16:46248 // Opening a Singleton tab that is already opened should not be opening a new
[email protected]e232c992012-12-06 12:43:20249 // tab nor be creating a new WebContents object.
[email protected]6c2381d2011-10-19 02:52:53250 content::NotificationRegistrar registrar;
[email protected]fa7ebe02010-11-29 23:04:57251
252 // As the registrar object goes out of scope, this will get unregistered
[email protected]d53a08c2012-07-18 20:35:30253 registrar.Add(this,
254 content::NOTIFICATION_WEB_CONTENTS_RENDER_VIEW_HOST_CREATED,
[email protected]ad50def52011-10-19 23:17:07255 content::NotificationService::AllSources());
[email protected]fa7ebe02010-11-29 23:04:57256
[email protected]52877dbc62012-06-29 22:22:03257 chrome::AddSelectedTabWithURL(browser(), singleton_url1,
Sylvain Defresnec6ccc77d2014-09-19 10:19:35258 ui::PAGE_TRANSITION_LINK);
[email protected]52877dbc62012-06-29 22:22:03259 chrome::AddSelectedTabWithURL(browser(), GetGoogleURL(),
Sylvain Defresnec6ccc77d2014-09-19 10:19:35260 ui::PAGE_TRANSITION_LINK);
[email protected]19d9f3a2010-10-14 21:49:36261
262 // We should have one browser with 3 tabs, the 3rd selected.
[email protected]0665ebe2013-02-13 09:53:19263 EXPECT_EQ(1u, chrome::GetTotalBrowserCount());
[email protected]ee496952013-01-10 23:17:33264 EXPECT_EQ(2, browser()->tab_strip_model()->active_index());
[email protected]19d9f3a2010-10-14 21:49:36265
[email protected]fa7ebe02010-11-29 23:04:57266 unsigned int previous_tab_contents_count =
267 created_tab_contents_count_ = 0;
268
[email protected]19d9f3a2010-10-14 21:49:36269 // Navigate to singleton_url1.
meacerc62e2ee2014-10-22 00:44:52270 chrome::NavigateParams params(MakeNavigateParams());
271 params.disposition = SINGLETON_TAB;
272 params.url = singleton_url1;
273 chrome::Navigate(&params);
[email protected]19d9f3a2010-10-14 21:49:36274
275 // The middle tab should now be selected.
meacerc62e2ee2014-10-22 00:44:52276 EXPECT_EQ(browser(), params.browser);
[email protected]ee496952013-01-10 23:17:33277 EXPECT_EQ(1, browser()->tab_strip_model()->active_index());
[email protected]fa7ebe02010-11-29 23:04:57278
279 // No tab contents should have been created
280 EXPECT_EQ(previous_tab_contents_count,
281 created_tab_contents_count_);
[email protected]19d9f3a2010-10-14 21:49:36282}
283
284IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
[email protected]578c6962011-08-24 22:06:40285 Disposition_SingletonTabRespectingRef) {
286 GURL singleton_ref_url1("http://maps.google.com/#a");
287 GURL singleton_ref_url2("http://maps.google.com/#b");
288 GURL singleton_ref_url3("http://maps.google.com/");
289
[email protected]52877dbc62012-06-29 22:22:03290 chrome::AddSelectedTabWithURL(browser(), singleton_ref_url1,
Sylvain Defresnec6ccc77d2014-09-19 10:19:35291 ui::PAGE_TRANSITION_LINK);
[email protected]578c6962011-08-24 22:06:40292
293 // We should have one browser with 2 tabs, 2nd selected.
[email protected]0665ebe2013-02-13 09:53:19294 EXPECT_EQ(1u, chrome::GetTotalBrowserCount());
[email protected]ee496952013-01-10 23:17:33295 EXPECT_EQ(2, browser()->tab_strip_model()->count());
296 EXPECT_EQ(1, browser()->tab_strip_model()->active_index());
[email protected]578c6962011-08-24 22:06:40297
298 // Navigate to singleton_url2.
meacerc62e2ee2014-10-22 00:44:52299 chrome::NavigateParams params(MakeNavigateParams());
300 params.disposition = SINGLETON_TAB;
301 params.url = singleton_ref_url2;
302 chrome::Navigate(&params);
[email protected]578c6962011-08-24 22:06:40303
304 // We should now have 2 tabs, the 2nd one selected.
meacerc62e2ee2014-10-22 00:44:52305 EXPECT_EQ(browser(), params.browser);
[email protected]ee496952013-01-10 23:17:33306 EXPECT_EQ(2, browser()->tab_strip_model()->count());
307 EXPECT_EQ(1, browser()->tab_strip_model()->active_index());
[email protected]578c6962011-08-24 22:06:40308
309 // Navigate to singleton_url2, but with respect ref set.
meacerc62e2ee2014-10-22 00:44:52310 params = MakeNavigateParams();
311 params.disposition = SINGLETON_TAB;
312 params.url = singleton_ref_url2;
313 params.ref_behavior = chrome::NavigateParams::RESPECT_REF;
314 chrome::Navigate(&params);
[email protected]578c6962011-08-24 22:06:40315
316 // We should now have 3 tabs, the 3th one selected.
meacerc62e2ee2014-10-22 00:44:52317 EXPECT_EQ(browser(), params.browser);
[email protected]ee496952013-01-10 23:17:33318 EXPECT_EQ(3, browser()->tab_strip_model()->count());
319 EXPECT_EQ(2, browser()->tab_strip_model()->active_index());
[email protected]578c6962011-08-24 22:06:40320
321 // Navigate to singleton_url3.
meacerc62e2ee2014-10-22 00:44:52322 params = MakeNavigateParams();
323 params.disposition = SINGLETON_TAB;
324 params.url = singleton_ref_url3;
325 params.ref_behavior = chrome::NavigateParams::RESPECT_REF;
326 chrome::Navigate(&params);
[email protected]578c6962011-08-24 22:06:40327
328 // We should now have 4 tabs, the 4th one selected.
meacerc62e2ee2014-10-22 00:44:52329 EXPECT_EQ(browser(), params.browser);
[email protected]ee496952013-01-10 23:17:33330 EXPECT_EQ(4, browser()->tab_strip_model()->count());
331 EXPECT_EQ(3, browser()->tab_strip_model()->active_index());
[email protected]578c6962011-08-24 22:06:40332}
333
334IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
[email protected]19d9f3a2010-10-14 21:49:36335 Disposition_SingletonTabNoneExisting) {
[email protected]19d9f3a2010-10-14 21:49:36336 GURL singleton_url1("http://maps.google.com/");
337
[email protected]bd817c22011-02-09 08:16:46338 // We should have one browser with 1 tab.
[email protected]0665ebe2013-02-13 09:53:19339 EXPECT_EQ(1u, chrome::GetTotalBrowserCount());
[email protected]ee496952013-01-10 23:17:33340 EXPECT_EQ(0, browser()->tab_strip_model()->active_index());
[email protected]19d9f3a2010-10-14 21:49:36341
342 // Navigate to singleton_url1.
meacerc62e2ee2014-10-22 00:44:52343 chrome::NavigateParams params(MakeNavigateParams());
344 params.disposition = SINGLETON_TAB;
345 params.url = singleton_url1;
346 chrome::Navigate(&params);
[email protected]19d9f3a2010-10-14 21:49:36347
348 // We should now have 2 tabs, the 2nd one selected.
meacerc62e2ee2014-10-22 00:44:52349 EXPECT_EQ(browser(), params.browser);
[email protected]ee496952013-01-10 23:17:33350 EXPECT_EQ(2, browser()->tab_strip_model()->count());
351 EXPECT_EQ(1, browser()->tab_strip_model()->active_index());
[email protected]a1feae52010-10-11 22:14:45352}
353
354// This test verifies that when a navigation results in a foreground tab, the
355// tab count of the Browser increases and the selected tab shifts to the new
356// foreground tab.
357IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_NewForegroundTab) {
[email protected]ee496952013-01-10 23:17:33358 WebContents* old_contents =
359 browser()->tab_strip_model()->GetActiveWebContents();
meacerc62e2ee2014-10-22 00:44:52360 chrome::NavigateParams params(MakeNavigateParams());
361 params.disposition = NEW_FOREGROUND_TAB;
362 chrome::Navigate(&params);
[email protected]ee496952013-01-10 23:17:33363 EXPECT_NE(old_contents,
364 browser()->tab_strip_model()->GetActiveWebContents());
[email protected]e232c992012-12-06 12:43:20365 EXPECT_EQ(browser()->tab_strip_model()->GetActiveWebContents(),
meacerc62e2ee2014-10-22 00:44:52366 params.target_contents);
[email protected]ee496952013-01-10 23:17:33367 EXPECT_EQ(2, browser()->tab_strip_model()->count());
[email protected]a1feae52010-10-11 22:14:45368}
369
370// This test verifies that when a navigation results in a background tab, the
371// tab count of the Browser increases but the selected tab remains the same.
372IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_NewBackgroundTab) {
[email protected]ee496952013-01-10 23:17:33373 WebContents* old_contents =
374 browser()->tab_strip_model()->GetActiveWebContents();
meacerc62e2ee2014-10-22 00:44:52375 chrome::NavigateParams params(MakeNavigateParams());
376 params.disposition = NEW_BACKGROUND_TAB;
377 chrome::Navigate(&params);
[email protected]ee496952013-01-10 23:17:33378 WebContents* new_contents =
379 browser()->tab_strip_model()->GetActiveWebContents();
[email protected]a1feae52010-10-11 22:14:45380 // The selected tab should have remained unchanged, since the new tab was
381 // opened in the background.
382 EXPECT_EQ(old_contents, new_contents);
[email protected]ee496952013-01-10 23:17:33383 EXPECT_EQ(2, browser()->tab_strip_model()->count());
[email protected]a1feae52010-10-11 22:14:45384}
385
386// This test verifies that when a navigation requiring a new foreground tab
387// occurs in a Browser that cannot host multiple tabs, the new foreground tab
388// is created in an existing compatible Browser.
389IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
390 Disposition_IncompatibleWindow_Existing) {
391 // Open a foreground tab in a window that cannot open popups when there is an
392 // existing compatible window somewhere else that they can be opened within.
393 Browser* popup = CreateEmptyBrowserForType(Browser::TYPE_POPUP,
394 browser()->profile());
meacerc62e2ee2014-10-22 00:44:52395 chrome::NavigateParams params(MakeNavigateParams(popup));
396 params.disposition = NEW_FOREGROUND_TAB;
397 chrome::Navigate(&params);
[email protected]a1feae52010-10-11 22:14:45398
399 // Navigate() should have opened the tab in a different browser since the
400 // one we supplied didn't support additional tabs.
meacerc62e2ee2014-10-22 00:44:52401 EXPECT_NE(popup, params.browser);
[email protected]a1feae52010-10-11 22:14:45402
403 // Since browser() is an existing compatible tabbed browser, it should have
404 // opened the tab there.
meacerc62e2ee2014-10-22 00:44:52405 EXPECT_EQ(browser(), params.browser);
[email protected]a1feae52010-10-11 22:14:45406
407 // We should be left with 2 windows, the popup with one tab and the browser()
408 // provided by the framework with two.
[email protected]0665ebe2013-02-13 09:53:19409 EXPECT_EQ(2u, chrome::GetTotalBrowserCount());
[email protected]ee496952013-01-10 23:17:33410 EXPECT_EQ(1, popup->tab_strip_model()->count());
411 EXPECT_EQ(2, browser()->tab_strip_model()->count());
[email protected]a1feae52010-10-11 22:14:45412}
413
414// This test verifies that when a navigation requiring a new foreground tab
415// occurs in a Browser that cannot host multiple tabs and no compatible Browser
416// that can is open, a compatible Browser is created.
417IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
418 Disposition_IncompatibleWindow_NoExisting) {
419 // We want to simulate not being able to find an existing window compatible
420 // with our non-tabbed browser window so Navigate() is forced to create a
421 // new compatible window. Because browser() supplied by the in-process
422 // browser testing framework is compatible with browser()->profile(), we
423 // need a different profile, and creating a popup window with an incognito
424 // profile is a quick and dirty way of achieving this.
425 Browser* popup = CreateEmptyBrowserForType(
[email protected]b35b26b32011-05-05 20:35:14426 Browser::TYPE_POPUP,
427 browser()->profile()->GetOffTheRecordProfile());
meacerc62e2ee2014-10-22 00:44:52428 chrome::NavigateParams params(MakeNavigateParams(popup));
429 params.disposition = NEW_FOREGROUND_TAB;
430 chrome::Navigate(&params);
[email protected]a1feae52010-10-11 22:14:45431
432 // Navigate() should have opened the tab in a different browser since the
433 // one we supplied didn't support additional tabs.
meacerc62e2ee2014-10-22 00:44:52434 EXPECT_NE(popup, params.browser);
[email protected]a1feae52010-10-11 22:14:45435
436 // This time, browser() is _not_ compatible with popup since it is not an
437 // incognito window.
meacerc62e2ee2014-10-22 00:44:52438 EXPECT_NE(browser(), params.browser);
[email protected]a1feae52010-10-11 22:14:45439
440 // We should have three windows, each with one tab:
441 // 1. the browser() provided by the framework (unchanged in this test)
442 // 2. the incognito popup we created originally
443 // 3. the new incognito tabbed browser that was created by Navigate().
[email protected]0665ebe2013-02-13 09:53:19444 EXPECT_EQ(3u, chrome::GetTotalBrowserCount());
[email protected]ee496952013-01-10 23:17:33445 EXPECT_EQ(1, browser()->tab_strip_model()->count());
446 EXPECT_EQ(1, popup->tab_strip_model()->count());
meacerc62e2ee2014-10-22 00:44:52447 EXPECT_EQ(1, params.browser->tab_strip_model()->count());
448 EXPECT_TRUE(params.browser->is_type_tabbed());
[email protected]a1feae52010-10-11 22:14:45449}
450
451// This test verifies that navigating with WindowOpenDisposition = NEW_POPUP
452// from a normal Browser results in a new Browser with TYPE_POPUP.
453IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_NewPopup) {
meacerc62e2ee2014-10-22 00:44:52454 chrome::NavigateParams params(MakeNavigateParams());
455 params.disposition = NEW_POPUP;
456 params.window_bounds = gfx::Rect(0, 0, 200, 200);
[email protected]7d329992011-04-15 18:20:02457 // Wait for new popup to to load and gain focus.
meacerc62e2ee2014-10-22 00:44:52458 ui_test_utils::NavigateToURL(&params);
[email protected]a1feae52010-10-11 22:14:45459
[email protected]7d329992011-04-15 18:20:02460 // Navigate() should have opened a new, focused popup window.
meacerc62e2ee2014-10-22 00:44:52461 EXPECT_NE(browser(), params.browser);
[email protected]50592b52013-05-02 22:26:25462#if 0
463 // TODO(stevenjb): Enable this test. See: crbug.com/79493
meacerc62e2ee2014-10-22 00:44:52464 EXPECT_TRUE(browser->window()->IsActive());
[email protected]50592b52013-05-02 22:26:25465#endif
meacerc62e2ee2014-10-22 00:44:52466 EXPECT_TRUE(params.browser->is_type_popup());
467 EXPECT_FALSE(params.browser->is_app());
[email protected]a1feae52010-10-11 22:14:45468
469 // We should have two windows, the browser() provided by the framework and the
470 // new popup window.
[email protected]0665ebe2013-02-13 09:53:19471 EXPECT_EQ(2u, chrome::GetTotalBrowserCount());
[email protected]ee496952013-01-10 23:17:33472 EXPECT_EQ(1, browser()->tab_strip_model()->count());
meacerc62e2ee2014-10-22 00:44:52473 EXPECT_EQ(1, params.browser->tab_strip_model()->count());
[email protected]a1feae52010-10-11 22:14:45474}
475
476// This test verifies that navigating with WindowOpenDisposition = NEW_POPUP
[email protected]f112b0f2011-05-26 01:53:52477// from a normal Browser results in a new Browser with is_app() true.
478IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_NewPopup_ExtensionId) {
meacerc62e2ee2014-10-22 00:44:52479 chrome::NavigateParams params(MakeNavigateParams());
480 params.disposition = NEW_POPUP;
481 params.extension_app_id = "extensionappid";
482 params.window_bounds = gfx::Rect(0, 0, 200, 200);
[email protected]f112b0f2011-05-26 01:53:52483 // Wait for new popup to to load and gain focus.
meacerc62e2ee2014-10-22 00:44:52484 ui_test_utils::NavigateToURL(&params);
[email protected]f112b0f2011-05-26 01:53:52485
486 // Navigate() should have opened a new, focused popup window.
meacerc62e2ee2014-10-22 00:44:52487 EXPECT_NE(browser(), params.browser);
488 EXPECT_TRUE(params.browser->is_type_popup());
489 EXPECT_TRUE(params.browser->is_app());
[email protected]f112b0f2011-05-26 01:53:52490
491 // We should have two windows, the browser() provided by the framework and the
492 // new popup window.
[email protected]0665ebe2013-02-13 09:53:19493 EXPECT_EQ(2u, chrome::GetTotalBrowserCount());
[email protected]ee496952013-01-10 23:17:33494 EXPECT_EQ(1, browser()->tab_strip_model()->count());
meacerc62e2ee2014-10-22 00:44:52495 EXPECT_EQ(1, params.browser->tab_strip_model()->count());
[email protected]f112b0f2011-05-26 01:53:52496}
497
498// This test verifies that navigating with WindowOpenDisposition = NEW_POPUP
[email protected]300d1e52011-01-19 23:57:57499// from a normal popup results in a new Browser with TYPE_POPUP.
500IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_NewPopupFromPopup) {
501 // Open a popup.
meacerc62e2ee2014-10-22 00:44:52502 chrome::NavigateParams params1(MakeNavigateParams());
503 params1.disposition = NEW_POPUP;
504 params1.window_bounds = gfx::Rect(0, 0, 200, 200);
505 chrome::Navigate(&params1);
[email protected]300d1e52011-01-19 23:57:57506 // Open another popup.
meacerc62e2ee2014-10-22 00:44:52507 chrome::NavigateParams params2(MakeNavigateParams(params1.browser));
508 params2.disposition = NEW_POPUP;
509 params2.window_bounds = gfx::Rect(0, 0, 200, 200);
510 chrome::Navigate(&params2);
[email protected]300d1e52011-01-19 23:57:57511
512 // Navigate() should have opened a new normal popup window.
meacerc62e2ee2014-10-22 00:44:52513 EXPECT_NE(params1.browser, params2.browser);
514 EXPECT_TRUE(params2.browser->is_type_popup());
515 EXPECT_FALSE(params2.browser->is_app());
[email protected]300d1e52011-01-19 23:57:57516
517 // We should have three windows, the browser() provided by the framework,
518 // the first popup window, and the second popup window.
[email protected]0665ebe2013-02-13 09:53:19519 EXPECT_EQ(3u, chrome::GetTotalBrowserCount());
[email protected]ee496952013-01-10 23:17:33520 EXPECT_EQ(1, browser()->tab_strip_model()->count());
meacerc62e2ee2014-10-22 00:44:52521 EXPECT_EQ(1, params1.browser->tab_strip_model()->count());
522 EXPECT_EQ(1, params2.browser->tab_strip_model()->count());
[email protected]300d1e52011-01-19 23:57:57523}
524
525// This test verifies that navigating with WindowOpenDisposition = NEW_POPUP
[email protected]d2202e22014-04-14 20:20:53526// from an app frame results in a new Browser with TYPE_POPUP.
[email protected]a1feae52010-10-11 22:14:45527IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
528 Disposition_NewPopupFromAppWindow) {
[email protected]d2202e22014-04-14 20:20:53529 Browser* app_browser = CreateEmptyBrowserForApp(browser()->profile());
meacerc62e2ee2014-10-22 00:44:52530 chrome::NavigateParams params(MakeNavigateParams(app_browser));
531 params.disposition = NEW_POPUP;
532 params.window_bounds = gfx::Rect(0, 0, 200, 200);
533 chrome::Navigate(&params);
[email protected]a1feae52010-10-11 22:14:45534
535 // Navigate() should have opened a new popup app window.
meacerc62e2ee2014-10-22 00:44:52536 EXPECT_NE(app_browser, params.browser);
537 EXPECT_NE(browser(), params.browser);
538 EXPECT_TRUE(params.browser->is_type_popup());
539 EXPECT_TRUE(params.browser->is_app());
[email protected]a1feae52010-10-11 22:14:45540
541 // We should now have three windows, the app window, the app popup it created,
542 // and the original browser() provided by the framework.
[email protected]0665ebe2013-02-13 09:53:19543 EXPECT_EQ(3u, chrome::GetTotalBrowserCount());
[email protected]ee496952013-01-10 23:17:33544 EXPECT_EQ(1, browser()->tab_strip_model()->count());
545 EXPECT_EQ(1, app_browser->tab_strip_model()->count());
meacerc62e2ee2014-10-22 00:44:52546 EXPECT_EQ(1, params.browser->tab_strip_model()->count());
[email protected]a1feae52010-10-11 22:14:45547}
548
549// This test verifies that navigating with WindowOpenDisposition = NEW_POPUP
[email protected]d2202e22014-04-14 20:20:53550// from an app popup results in a new Browser also of TYPE_POPUP.
[email protected]300d1e52011-01-19 23:57:57551IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
552 Disposition_NewPopupFromAppPopup) {
[email protected]d2202e22014-04-14 20:20:53553 Browser* app_browser = CreateEmptyBrowserForApp(browser()->profile());
[email protected]300d1e52011-01-19 23:57:57554 // Open an app popup.
meacerc62e2ee2014-10-22 00:44:52555 chrome::NavigateParams params1(MakeNavigateParams(app_browser));
556 params1.disposition = NEW_POPUP;
557 params1.window_bounds = gfx::Rect(0, 0, 200, 200);
558 chrome::Navigate(&params1);
[email protected]300d1e52011-01-19 23:57:57559 // Now open another app popup.
meacerc62e2ee2014-10-22 00:44:52560 chrome::NavigateParams params2(MakeNavigateParams(params1.browser));
561 params2.disposition = NEW_POPUP;
562 params2.window_bounds = gfx::Rect(0, 0, 200, 200);
563 chrome::Navigate(&params2);
[email protected]300d1e52011-01-19 23:57:57564
565 // Navigate() should have opened a new popup app window.
meacerc62e2ee2014-10-22 00:44:52566 EXPECT_NE(browser(), params1.browser);
567 EXPECT_NE(params1.browser, params2.browser);
568 EXPECT_TRUE(params2.browser->is_type_popup());
569 EXPECT_TRUE(params2.browser->is_app());
[email protected]300d1e52011-01-19 23:57:57570
571 // We should now have four windows, the app window, the first app popup,
572 // the second app popup, and the original browser() provided by the framework.
[email protected]0665ebe2013-02-13 09:53:19573 EXPECT_EQ(4u, chrome::GetTotalBrowserCount());
[email protected]ee496952013-01-10 23:17:33574 EXPECT_EQ(1, browser()->tab_strip_model()->count());
575 EXPECT_EQ(1, app_browser->tab_strip_model()->count());
meacerc62e2ee2014-10-22 00:44:52576 EXPECT_EQ(1, params1.browser->tab_strip_model()->count());
577 EXPECT_EQ(1, params2.browser->tab_strip_model()->count());
[email protected]300d1e52011-01-19 23:57:57578}
579
580// This test verifies that navigating with WindowOpenDisposition = NEW_POPUP
[email protected]a1feae52010-10-11 22:14:45581// from an extension app tab results in a new Browser with TYPE_APP_POPUP.
582IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
583 Disposition_NewPopupFromExtensionApp) {
584 // TODO(beng): TBD.
585}
586
[email protected]7d329992011-04-15 18:20:02587// This test verifies that navigating with window_action = SHOW_WINDOW_INACTIVE
588// does not focus a new new popup window.
589IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_NewPopupUnfocused) {
meacerc62e2ee2014-10-22 00:44:52590 chrome::NavigateParams params(MakeNavigateParams());
591 params.disposition = NEW_POPUP;
592 params.window_bounds = gfx::Rect(0, 0, 200, 200);
593 params.window_action = chrome::NavigateParams::SHOW_WINDOW_INACTIVE;
[email protected]7d329992011-04-15 18:20:02594 // Wait for new popup to load (and gain focus if the test fails).
meacerc62e2ee2014-10-22 00:44:52595 ui_test_utils::NavigateToURL(&params);
[email protected]7d329992011-04-15 18:20:02596
597 // Navigate() should have opened a new, unfocused, popup window.
meacerc62e2ee2014-10-22 00:44:52598 EXPECT_NE(browser(), params.browser);
599 EXPECT_EQ(Browser::TYPE_POPUP, params.browser->type());
[email protected]9db263a2011-04-15 20:53:47600#if 0
601// TODO(stevenjb): Enable this test. See: crbug.com/79493
[email protected]7d329992011-04-15 18:20:02602 EXPECT_FALSE(p.browser->window()->IsActive());
[email protected]7d329992011-04-15 18:20:02603#endif
[email protected]9db263a2011-04-15 20:53:47604}
[email protected]7d329992011-04-15 18:20:02605
[email protected]d2202e22014-04-14 20:20:53606// This test verifies that navigating with WindowOpenDisposition = NEW_POPUP
607// and trusted_source = true results in a new Browser where is_trusted_source()
608// is true.
609IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_NewPopupTrusted) {
meacerc62e2ee2014-10-22 00:44:52610 chrome::NavigateParams params(MakeNavigateParams());
611 params.disposition = NEW_POPUP;
612 params.trusted_source = true;
613 params.window_bounds = gfx::Rect(0, 0, 200, 200);
[email protected]d2202e22014-04-14 20:20:53614 // Wait for new popup to to load and gain focus.
meacerc62e2ee2014-10-22 00:44:52615 ui_test_utils::NavigateToURL(&params);
[email protected]d2202e22014-04-14 20:20:53616
617 // Navigate() should have opened a new popup window of TYPE_TRUSTED_POPUP.
meacerc62e2ee2014-10-22 00:44:52618 EXPECT_NE(browser(), params.browser);
619 EXPECT_TRUE(params.browser->is_type_popup());
620 EXPECT_TRUE(params.browser->is_trusted_source());
[email protected]d2202e22014-04-14 20:20:53621}
622
623
[email protected]a1feae52010-10-11 22:14:45624// This test verifies that navigating with WindowOpenDisposition = NEW_WINDOW
625// always opens a new window.
626IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_NewWindow) {
meacerc62e2ee2014-10-22 00:44:52627 chrome::NavigateParams params(MakeNavigateParams());
628 params.disposition = NEW_WINDOW;
629 chrome::Navigate(&params);
[email protected]a1feae52010-10-11 22:14:45630
631 // Navigate() should have opened a new toplevel window.
meacerc62e2ee2014-10-22 00:44:52632 EXPECT_NE(browser(), params.browser);
633 EXPECT_TRUE(params.browser->is_type_tabbed());
[email protected]a1feae52010-10-11 22:14:45634
635 // We should now have two windows, the browser() provided by the framework and
636 // the new normal window.
[email protected]0665ebe2013-02-13 09:53:19637 EXPECT_EQ(2u, chrome::GetTotalBrowserCount());
[email protected]ee496952013-01-10 23:17:33638 EXPECT_EQ(1, browser()->tab_strip_model()->count());
meacerc62e2ee2014-10-22 00:44:52639 EXPECT_EQ(1, params.browser->tab_strip_model()->count());
[email protected]a1feae52010-10-11 22:14:45640}
641
642// This test verifies that navigating with WindowOpenDisposition = INCOGNITO
643// opens a new incognito window if no existing incognito window is present.
644IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_Incognito) {
meacerc62e2ee2014-10-22 00:44:52645 chrome::NavigateParams params(MakeNavigateParams());
646 params.disposition = OFF_THE_RECORD;
647 chrome::Navigate(&params);
[email protected]a1feae52010-10-11 22:14:45648
649 // Navigate() should have opened a new toplevel incognito window.
meacerc62e2ee2014-10-22 00:44:52650 EXPECT_NE(browser(), params.browser);
[email protected]a1feae52010-10-11 22:14:45651 EXPECT_EQ(browser()->profile()->GetOffTheRecordProfile(),
meacerc62e2ee2014-10-22 00:44:52652 params.browser->profile());
[email protected]a1feae52010-10-11 22:14:45653
[email protected]d7ff3592010-11-30 21:50:46654 // |source_contents| should be set to NULL because the profile for the new
655 // page is different from the originating page.
meacerc62e2ee2014-10-22 00:44:52656 EXPECT_EQ(NULL, params.source_contents);
[email protected]d7ff3592010-11-30 21:50:46657
[email protected]a1feae52010-10-11 22:14:45658 // We should now have two windows, the browser() provided by the framework and
659 // the new incognito window.
[email protected]0665ebe2013-02-13 09:53:19660 EXPECT_EQ(2u, chrome::GetTotalBrowserCount());
[email protected]ee496952013-01-10 23:17:33661 EXPECT_EQ(1, browser()->tab_strip_model()->count());
meacerc62e2ee2014-10-22 00:44:52662 EXPECT_EQ(1, params.browser->tab_strip_model()->count());
[email protected]a1feae52010-10-11 22:14:45663}
664
665// This test verifies that navigating with WindowOpenDisposition = INCOGNITO
666// reuses an existing incognito window when possible.
667IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_IncognitoRefocus) {
668 Browser* incognito_browser =
[email protected]b35b26b32011-05-05 20:35:14669 CreateEmptyBrowserForType(Browser::TYPE_TABBED,
[email protected]a1feae52010-10-11 22:14:45670 browser()->profile()->GetOffTheRecordProfile());
meacerc62e2ee2014-10-22 00:44:52671 chrome::NavigateParams params(MakeNavigateParams());
672 params.disposition = OFF_THE_RECORD;
673 chrome::Navigate(&params);
[email protected]a1feae52010-10-11 22:14:45674
675 // Navigate() should have opened a new tab in the existing incognito window.
meacerc62e2ee2014-10-22 00:44:52676 EXPECT_NE(browser(), params.browser);
677 EXPECT_EQ(params.browser, incognito_browser);
[email protected]a1feae52010-10-11 22:14:45678
679 // We should now have two windows, the browser() provided by the framework and
680 // the incognito window we opened earlier.
[email protected]0665ebe2013-02-13 09:53:19681 EXPECT_EQ(2u, chrome::GetTotalBrowserCount());
[email protected]ee496952013-01-10 23:17:33682 EXPECT_EQ(1, browser()->tab_strip_model()->count());
683 EXPECT_EQ(2, incognito_browser->tab_strip_model()->count());
[email protected]a1feae52010-10-11 22:14:45684}
685
686// This test verifies that no navigation action occurs when
687// WindowOpenDisposition = SUPPRESS_OPEN.
688IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_SuppressOpen) {
689 RunSuppressTest(SUPPRESS_OPEN);
690}
691
692// This test verifies that no navigation action occurs when
693// WindowOpenDisposition = SAVE_TO_DISK.
694IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_SaveToDisk) {
695 RunSuppressTest(SAVE_TO_DISK);
696}
697
698// This test verifies that no navigation action occurs when
699// WindowOpenDisposition = IGNORE_ACTION.
700IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_IgnoreAction) {
701 RunSuppressTest(IGNORE_ACTION);
702}
703
[email protected]e232c992012-12-06 12:43:20704// This tests adding a foreground tab with a predefined WebContents.
[email protected]a1feae52010-10-11 22:14:45705IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, TargetContents_ForegroundTab) {
meacerc62e2ee2014-10-22 00:44:52706 chrome::NavigateParams params(MakeNavigateParams());
707 params.disposition = NEW_FOREGROUND_TAB;
708 params.target_contents = CreateWebContents();
709 chrome::Navigate(&params);
[email protected]a1feae52010-10-11 22:14:45710
711 // Navigate() should have opened the contents in a new foreground in the
712 // current Browser.
meacerc62e2ee2014-10-22 00:44:52713 EXPECT_EQ(browser(), params.browser);
[email protected]e232c992012-12-06 12:43:20714 EXPECT_EQ(browser()->tab_strip_model()->GetActiveWebContents(),
meacerc62e2ee2014-10-22 00:44:52715 params.target_contents);
[email protected]a1feae52010-10-11 22:14:45716
717 // We should have one window, with two tabs.
[email protected]0665ebe2013-02-13 09:53:19718 EXPECT_EQ(1u, chrome::GetTotalBrowserCount());
[email protected]ee496952013-01-10 23:17:33719 EXPECT_EQ(2, browser()->tab_strip_model()->count());
[email protected]a1feae52010-10-11 22:14:45720}
721
722#if defined(OS_WIN)
[email protected]e232c992012-12-06 12:43:20723// This tests adding a popup with a predefined WebContents.
[email protected]76edb672011-03-04 21:48:39724IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, DISABLED_TargetContents_Popup) {
meacerc62e2ee2014-10-22 00:44:52725 chrome::NavigateParams params(MakeNavigateParams());
726 params.disposition = NEW_POPUP;
727 params.target_contents = CreateWebContents();
728 params.window_bounds = gfx::Rect(10, 10, 500, 500);
729 chrome::Navigate(&params);
[email protected]a1feae52010-10-11 22:14:45730
731 // Navigate() should have opened a new popup window.
meacerc62e2ee2014-10-22 00:44:52732 EXPECT_NE(browser(), params.browser);
733 EXPECT_TRUE(params.browser->is_type_popup());
734 EXPECT_FALSE(params.browser->is_app());
[email protected]a1feae52010-10-11 22:14:45735
736 // The web platform is weird. The window bounds specified in
meacerc62e2ee2014-10-22 00:44:52737 // |params.window_bounds| are used as follows:
[email protected]a1feae52010-10-11 22:14:45738 // - the origin is used to position the window
[email protected]e232c992012-12-06 12:43:20739 // - the size is used to size the WebContents of the window.
[email protected]a1feae52010-10-11 22:14:45740 // As such the position of the resulting window will always match
meacerc62e2ee2014-10-22 00:44:52741 // params.window_bounds.origin(), but its size will not. We need to match
[email protected]a1feae52010-10-11 22:14:45742 // the size against the selected tab's view's container size.
meacerc62e2ee2014-10-22 00:44:52743 // Only Windows positions the window according to
744 // |params.window_bounds.origin()| - on Mac the window is offset from the
745 // opener and on Linux it always opens at 0,0.
746 EXPECT_EQ(params.window_bounds.origin(),
747 params.browser->window()->GetRestoredBounds().origin());
[email protected]a1feae52010-10-11 22:14:45748 // All platforms should respect size however provided width > 400 (Mac has a
749 // minimum window width of 400).
meacerc62e2ee2014-10-22 00:44:52750 EXPECT_EQ(params.window_bounds.size(),
751 params.target_contents->GetContainerBounds().size());
[email protected]a1feae52010-10-11 22:14:45752
753 // We should have two windows, the new popup and the browser() provided by the
754 // framework.
[email protected]0665ebe2013-02-13 09:53:19755 EXPECT_EQ(2u, chrome::GetTotalBrowserCount());
[email protected]ee496952013-01-10 23:17:33756 EXPECT_EQ(1, browser()->tab_strip_model()->count());
meacerc62e2ee2014-10-22 00:44:52757 EXPECT_EQ(1, params.browser->tab_strip_model()->count());
[email protected]a1feae52010-10-11 22:14:45758}
759#endif
760
761// This tests adding a tab at a specific index.
762IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Tabstrip_InsertAtIndex) {
763 // This is not meant to be a comprehensive test of whether or not the tab
764 // implementation of the browser observes the insertion index. That is
765 // covered by the unit tests for TabStripModel. This merely verifies that
766 // insertion index preference is reflected in common cases.
meacerc62e2ee2014-10-22 00:44:52767 chrome::NavigateParams params(MakeNavigateParams());
768 params.disposition = NEW_FOREGROUND_TAB;
769 params.tabstrip_index = 0;
770 params.tabstrip_add_types = TabStripModel::ADD_FORCE_INDEX;
771 chrome::Navigate(&params);
[email protected]a1feae52010-10-11 22:14:45772
773 // Navigate() should have inserted a new tab at slot 0 in the tabstrip.
meacerc62e2ee2014-10-22 00:44:52774 EXPECT_EQ(browser(), params.browser);
[email protected]e232c992012-12-06 12:43:20775 EXPECT_EQ(0, browser()->tab_strip_model()->GetIndexOfWebContents(
meacerc62e2ee2014-10-22 00:44:52776 static_cast<const WebContents*>(params.target_contents)));
[email protected]a1feae52010-10-11 22:14:45777
778 // We should have one window - the browser() provided by the framework.
[email protected]0665ebe2013-02-13 09:53:19779 EXPECT_EQ(1u, chrome::GetTotalBrowserCount());
[email protected]ee496952013-01-10 23:17:33780 EXPECT_EQ(2, browser()->tab_strip_model()->count());
[email protected]a1feae52010-10-11 22:14:45781}
782
[email protected]bb89e7482010-11-17 18:27:04783// This test verifies that constructing params with disposition = SINGLETON_TAB
[email protected]fee320542011-03-02 01:30:49784// and IGNORE_AND_NAVIGATE opens a new tab navigated to the specified URL if
[email protected]67ed83e2011-01-07 22:54:00785// no previous tab with that URL (minus the path) exists.
[email protected]bb89e7482010-11-17 18:27:04786IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
787 Disposition_SingletonTabNew_IgnorePath) {
[email protected]52877dbc62012-06-29 22:22:03788 chrome::AddSelectedTabWithURL(browser(), GetGoogleURL(),
Sylvain Defresnec6ccc77d2014-09-19 10:19:35789 ui::PAGE_TRANSITION_LINK);
[email protected]bb89e7482010-11-17 18:27:04790
791 // We should have one browser with 2 tabs, the 2nd selected.
[email protected]0665ebe2013-02-13 09:53:19792 EXPECT_EQ(1u, chrome::GetTotalBrowserCount());
[email protected]ee496952013-01-10 23:17:33793 EXPECT_EQ(2, browser()->tab_strip_model()->count());
794 EXPECT_EQ(1, browser()->tab_strip_model()->active_index());
[email protected]bb89e7482010-11-17 18:27:04795
796 // Navigate to a new singleton tab with a sub-page.
meacerc62e2ee2014-10-22 00:44:52797 chrome::NavigateParams params(MakeNavigateParams());
798 params.disposition = SINGLETON_TAB;
799 params.url = GetContentSettingsURL();
800 params.window_action = chrome::NavigateParams::SHOW_WINDOW;
801 params.path_behavior = chrome::NavigateParams::IGNORE_AND_NAVIGATE;
802 chrome::Navigate(&params);
[email protected]bb89e7482010-11-17 18:27:04803
804 // The last tab should now be selected and navigated to the sub-page of the
[email protected]50592b52013-05-02 22:26:25805 // URL.
meacerc62e2ee2014-10-22 00:44:52806 EXPECT_EQ(browser(), params.browser);
[email protected]ee496952013-01-10 23:17:33807 EXPECT_EQ(3, browser()->tab_strip_model()->count());
808 EXPECT_EQ(2, browser()->tab_strip_model()->active_index());
[email protected]a048ad22012-03-23 04:26:56809 EXPECT_EQ(GetContentSettingsURL(),
[email protected]ee496952013-01-10 23:17:33810 ShortenUberURL(browser()->tab_strip_model()->
811 GetActiveWebContents()->GetURL()));
[email protected]bb89e7482010-11-17 18:27:04812}
813
814// This test verifies that constructing params with disposition = SINGLETON_TAB
[email protected]fee320542011-03-02 01:30:49815// and IGNORE_AND_NAVIGATE opens an existing tab with the matching URL (minus
[email protected]bb89e7482010-11-17 18:27:04816// the path) which is navigated to the specified URL.
817IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
818 Disposition_SingletonTabExisting_IgnorePath) {
[email protected]ddddfda2011-07-14 23:19:39819 GURL singleton_url1(GetSettingsURL());
[email protected]52877dbc62012-06-29 22:22:03820 chrome::AddSelectedTabWithURL(browser(), singleton_url1,
Sylvain Defresnec6ccc77d2014-09-19 10:19:35821 ui::PAGE_TRANSITION_LINK);
[email protected]52877dbc62012-06-29 22:22:03822 chrome::AddSelectedTabWithURL(browser(), GetGoogleURL(),
Sylvain Defresnec6ccc77d2014-09-19 10:19:35823 ui::PAGE_TRANSITION_LINK);
[email protected]bb89e7482010-11-17 18:27:04824
825 // We should have one browser with 3 tabs, the 3rd selected.
[email protected]0665ebe2013-02-13 09:53:19826 EXPECT_EQ(1u, chrome::GetTotalBrowserCount());
[email protected]ee496952013-01-10 23:17:33827 EXPECT_EQ(3, browser()->tab_strip_model()->count());
828 EXPECT_EQ(2, browser()->tab_strip_model()->active_index());
[email protected]bb89e7482010-11-17 18:27:04829
830 // Navigate to singleton_url1.
meacerc62e2ee2014-10-22 00:44:52831 chrome::NavigateParams params(MakeNavigateParams());
832 params.disposition = SINGLETON_TAB;
833 params.url = GetContentSettingsURL();
834 params.window_action = chrome::NavigateParams::SHOW_WINDOW;
835 params.path_behavior = chrome::NavigateParams::IGNORE_AND_NAVIGATE;
836 chrome::Navigate(&params);
[email protected]bb89e7482010-11-17 18:27:04837
838 // The middle tab should now be selected and navigated to the sub-page of the
839 // URL.
meacerc62e2ee2014-10-22 00:44:52840 EXPECT_EQ(browser(), params.browser);
[email protected]ee496952013-01-10 23:17:33841 EXPECT_EQ(3, browser()->tab_strip_model()->count());
842 EXPECT_EQ(1, browser()->tab_strip_model()->active_index());
[email protected]a048ad22012-03-23 04:26:56843 EXPECT_EQ(GetContentSettingsURL(),
[email protected]ee496952013-01-10 23:17:33844 ShortenUberURL(browser()->tab_strip_model()->
845 GetActiveWebContents()->GetURL()));
[email protected]bb89e7482010-11-17 18:27:04846}
847
848// This test verifies that constructing params with disposition = SINGLETON_TAB
[email protected]fee320542011-03-02 01:30:49849// and IGNORE_AND_NAVIGATE opens an existing tab with the matching URL (minus
[email protected]bb89e7482010-11-17 18:27:04850// the path) which is navigated to the specified URL.
851IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
852 Disposition_SingletonTabExistingSubPath_IgnorePath) {
[email protected]a048ad22012-03-23 04:26:56853 GURL singleton_url1(GetContentSettingsURL());
[email protected]52877dbc62012-06-29 22:22:03854 chrome::AddSelectedTabWithURL(browser(), singleton_url1,
Sylvain Defresnec6ccc77d2014-09-19 10:19:35855 ui::PAGE_TRANSITION_LINK);
[email protected]52877dbc62012-06-29 22:22:03856 chrome::AddSelectedTabWithURL(browser(), GetGoogleURL(),
Sylvain Defresnec6ccc77d2014-09-19 10:19:35857 ui::PAGE_TRANSITION_LINK);
[email protected]bb89e7482010-11-17 18:27:04858
859 // We should have one browser with 3 tabs, the 3rd selected.
[email protected]0665ebe2013-02-13 09:53:19860 EXPECT_EQ(1u, chrome::GetTotalBrowserCount());
[email protected]ee496952013-01-10 23:17:33861 EXPECT_EQ(3, browser()->tab_strip_model()->count());
862 EXPECT_EQ(2, browser()->tab_strip_model()->active_index());
[email protected]bb89e7482010-11-17 18:27:04863
864 // Navigate to singleton_url1.
meacerc62e2ee2014-10-22 00:44:52865 chrome::NavigateParams params(MakeNavigateParams());
866 params.disposition = SINGLETON_TAB;
867 params.url = GetClearBrowsingDataURL();
868 params.window_action = chrome::NavigateParams::SHOW_WINDOW;
869 params.path_behavior = chrome::NavigateParams::IGNORE_AND_NAVIGATE;
870 chrome::Navigate(&params);
[email protected]bb89e7482010-11-17 18:27:04871
872 // The middle tab should now be selected and navigated to the sub-page of the
873 // URL.
meacerc62e2ee2014-10-22 00:44:52874 EXPECT_EQ(browser(), params.browser);
[email protected]ee496952013-01-10 23:17:33875 EXPECT_EQ(3, browser()->tab_strip_model()->count());
876 EXPECT_EQ(1, browser()->tab_strip_model()->active_index());
[email protected]a048ad22012-03-23 04:26:56877 EXPECT_EQ(GetClearBrowsingDataURL(),
[email protected]ee496952013-01-10 23:17:33878 ShortenUberURL(browser()->tab_strip_model()->
879 GetActiveWebContents()->GetURL()));
[email protected]bb89e7482010-11-17 18:27:04880}
[email protected]2dd85482010-11-06 01:56:47881
[email protected]637b3442011-01-10 23:31:48882// This test verifies that constructing params with disposition = SINGLETON_TAB
[email protected]fee320542011-03-02 01:30:49883// and IGNORE_AND_STAY_PUT opens an existing tab with the matching URL (minus
884// the path).
885IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
886 Disposition_SingletonTabExistingSubPath_IgnorePath2) {
[email protected]a048ad22012-03-23 04:26:56887 GURL singleton_url1(GetContentSettingsURL());
[email protected]52877dbc62012-06-29 22:22:03888 chrome::AddSelectedTabWithURL(browser(), singleton_url1,
Sylvain Defresnec6ccc77d2014-09-19 10:19:35889 ui::PAGE_TRANSITION_LINK);
[email protected]52877dbc62012-06-29 22:22:03890 chrome::AddSelectedTabWithURL(browser(), GetGoogleURL(),
Sylvain Defresnec6ccc77d2014-09-19 10:19:35891 ui::PAGE_TRANSITION_LINK);
[email protected]fee320542011-03-02 01:30:49892
893 // We should have one browser with 3 tabs, the 3rd selected.
[email protected]0665ebe2013-02-13 09:53:19894 EXPECT_EQ(1u, chrome::GetTotalBrowserCount());
[email protected]ee496952013-01-10 23:17:33895 EXPECT_EQ(3, browser()->tab_strip_model()->count());
896 EXPECT_EQ(2, browser()->tab_strip_model()->active_index());
[email protected]fee320542011-03-02 01:30:49897
898 // Navigate to singleton_url1.
meacerc62e2ee2014-10-22 00:44:52899 chrome::NavigateParams params(MakeNavigateParams());
900 params.disposition = SINGLETON_TAB;
901 params.url = GetClearBrowsingDataURL();
902 params.window_action = chrome::NavigateParams::SHOW_WINDOW;
903 params.path_behavior = chrome::NavigateParams::IGNORE_AND_STAY_PUT;
904 chrome::Navigate(&params);
[email protected]fee320542011-03-02 01:30:49905
906 // The middle tab should now be selected.
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]fee320542011-03-02 01:30:49910 EXPECT_EQ(singleton_url1,
[email protected]ee496952013-01-10 23:17:33911 ShortenUberURL(browser()->tab_strip_model()->
912 GetActiveWebContents()->GetURL()));
[email protected]fee320542011-03-02 01:30:49913}
914
915// This test verifies that constructing params with disposition = SINGLETON_TAB
916// and IGNORE_AND_NAVIGATE will update the current tab's URL if the currently
[email protected]637b3442011-01-10 23:31:48917// selected tab is a match but has a different path.
918IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
919 Disposition_SingletonTabFocused_IgnorePath) {
[email protected]a048ad22012-03-23 04:26:56920 GURL singleton_url_current(GetContentSettingsURL());
[email protected]52877dbc62012-06-29 22:22:03921 chrome::AddSelectedTabWithURL(browser(), singleton_url_current,
Sylvain Defresnec6ccc77d2014-09-19 10:19:35922 ui::PAGE_TRANSITION_LINK);
[email protected]637b3442011-01-10 23:31:48923
924 // We should have one browser with 2 tabs, the 2nd selected.
[email protected]0665ebe2013-02-13 09:53:19925 EXPECT_EQ(1u, chrome::GetTotalBrowserCount());
[email protected]ee496952013-01-10 23:17:33926 EXPECT_EQ(2, browser()->tab_strip_model()->count());
927 EXPECT_EQ(1, browser()->tab_strip_model()->active_index());
[email protected]637b3442011-01-10 23:31:48928
929 // Navigate to a different settings path.
[email protected]a048ad22012-03-23 04:26:56930 GURL singleton_url_target(GetClearBrowsingDataURL());
meacerc62e2ee2014-10-22 00:44:52931 chrome::NavigateParams params(MakeNavigateParams());
932 params.disposition = SINGLETON_TAB;
933 params.url = singleton_url_target;
934 params.window_action = chrome::NavigateParams::SHOW_WINDOW;
935 params.path_behavior = chrome::NavigateParams::IGNORE_AND_NAVIGATE;
936 chrome::Navigate(&params);
[email protected]637b3442011-01-10 23:31:48937
938 // The second tab should still be selected, but navigated to the new path.
meacerc62e2ee2014-10-22 00:44:52939 EXPECT_EQ(browser(), params.browser);
[email protected]ee496952013-01-10 23:17:33940 EXPECT_EQ(2, browser()->tab_strip_model()->count());
941 EXPECT_EQ(1, browser()->tab_strip_model()->active_index());
[email protected]637b3442011-01-10 23:31:48942 EXPECT_EQ(singleton_url_target,
[email protected]ee496952013-01-10 23:17:33943 ShortenUberURL(browser()->tab_strip_model()->
944 GetActiveWebContents()->GetURL()));
[email protected]637b3442011-01-10 23:31:48945}
946
[email protected]07afd7c2011-02-17 10:07:11947// This test verifies that constructing params with disposition = SINGLETON_TAB
[email protected]fee320542011-03-02 01:30:49948// and IGNORE_AND_NAVIGATE will open an existing matching tab with a different
949// query.
[email protected]07afd7c2011-02-17 10:07:11950IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
951 Disposition_SingletonTabExisting_IgnoreQuery) {
[email protected]ee496952013-01-10 23:17:33952 int initial_tab_count = browser()->tab_strip_model()->count();
[email protected]07afd7c2011-02-17 10:07:11953 GURL singleton_url_current("chrome://settings/internet");
[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]07afd7c2011-02-17 10:07:11956
[email protected]ee496952013-01-10 23:17:33957 EXPECT_EQ(initial_tab_count + 1, browser()->tab_strip_model()->count());
958 EXPECT_EQ(initial_tab_count, browser()->tab_strip_model()->active_index());
[email protected]07afd7c2011-02-17 10:07:11959
960 // Navigate to a different settings path.
961 GURL singleton_url_target(
962 "chrome://settings/internet?"
stevenjb82dbc53092015-03-14 18:32:24963 "guid=ethernet_00aa00aa00aa&networkType=1");
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]07afd7c2011-02-17 10:07:11970
971 // Last tab should still be selected.
meacerc62e2ee2014-10-22 00:44:52972 EXPECT_EQ(browser(), params.browser);
[email protected]ee496952013-01-10 23:17:33973 EXPECT_EQ(initial_tab_count + 1, browser()->tab_strip_model()->count());
974 EXPECT_EQ(initial_tab_count, browser()->tab_strip_model()->active_index());
[email protected]07afd7c2011-02-17 10:07:11975}
976
[email protected]bd817c22011-02-09 08:16:46977// This test verifies that the settings page isn't opened in the incognito
978// window.
[email protected]a048ad22012-03-23 04:26:56979// Disabled until fixed for uber settings: http://crbug.com/111243
[email protected]bd817c22011-02-09 08:16:46980IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
[email protected]a048ad22012-03-23 04:26:56981 DISABLED_Disposition_Settings_UseNonIncognitoWindow) {
[email protected]fc0ed302011-11-29 23:17:19982 RunUseNonIncognitoWindowTest(GetSettingsURL());
[email protected]bd817c22011-02-09 08:16:46983}
984
[email protected]429e9712013-04-30 09:35:50985// This test verifies that the view-source settings page isn't opened in the
986// incognito window.
987IN_PROC_BROWSER_TEST_F(
988 BrowserNavigatorTest,
989 Disposition_ViewSource_Settings_DoNothingIfIncognitoForced) {
[email protected]dbdda5402013-05-30 22:13:48990 std::string view_source(content::kViewSourceScheme);
[email protected]429e9712013-04-30 09:35:50991 view_source.append(":");
992 view_source.append(chrome::kChromeUISettingsURL);
993 RunDoNothingIfIncognitoIsForcedTest(GURL(view_source));
994}
995
996// This test verifies that the view-source settings page isn't opened in the
997// incognito window even if incognito mode is forced (does nothing in that
998// case).
999IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
1000 Disposition_ViewSource_Settings_UseNonIncognitoWindow) {
[email protected]dbdda5402013-05-30 22:13:481001 std::string view_source(content::kViewSourceScheme);
[email protected]429e9712013-04-30 09:35:501002 view_source.append(":");
1003 view_source.append(chrome::kChromeUISettingsURL);
1004 RunUseNonIncognitoWindowTest(GURL(view_source));
1005}
1006
[email protected]82404cd2011-07-12 19:55:141007// This test verifies that the settings page isn't opened in the incognito
1008// window from a non-incognito window (bookmark open-in-incognito trigger).
[email protected]a048ad22012-03-23 04:26:561009// Disabled until fixed for uber settings: http://crbug.com/111243
[email protected]82404cd2011-07-12 19:55:141010IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
[email protected]a048ad22012-03-23 04:26:561011 DISABLED_Disposition_Settings_UseNonIncognitoWindowForBookmark) {
[email protected]78e2edc2012-07-01 23:32:281012 chrome::NavigateParams params(browser(), GetSettingsURL(),
Sylvain Defresnec6ccc77d2014-09-19 10:19:351013 ui::PAGE_TRANSITION_AUTO_BOOKMARK);
[email protected]82404cd2011-07-12 19:55:141014 params.disposition = OFF_THE_RECORD;
1015 {
[email protected]a7fe9112012-07-20 02:34:451016 content::WindowedNotificationObserver observer(
[email protected]ad50def52011-10-19 23:17:071017 content::NOTIFICATION_LOAD_STOP,
1018 content::NotificationService::AllSources());
[email protected]78e2edc2012-07-01 23:32:281019 chrome::Navigate(&params);
[email protected]82404cd2011-07-12 19:55:141020 observer.Wait();
1021 }
1022
[email protected]0665ebe2013-02-13 09:53:191023 EXPECT_EQ(1u, chrome::GetTotalBrowserCount());
[email protected]52877dbc62012-06-29 22:22:031024 EXPECT_EQ(GetSettingsURL(),
[email protected]ee496952013-01-10 23:17:331025 ShortenUberURL(browser()->tab_strip_model()->
1026 GetActiveWebContents()->GetURL()));
[email protected]82404cd2011-07-12 19:55:141027}
1028
[email protected]93ad8e1c2011-11-08 21:34:051029// Settings page is expected to always open in normal mode regardless
1030// of whether the user is trying to open it in incognito mode or not.
1031// This test verifies that if incognito mode is forced (by policy), settings
1032// page doesn't open at all.
[email protected]a048ad22012-03-23 04:26:561033// Disabled until fixed for uber settings: http://crbug.com/111243
[email protected]93ad8e1c2011-11-08 21:34:051034IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
[email protected]a048ad22012-03-23 04:26:561035 DISABLED_Disposition_Settings_DoNothingIfIncognitoIsForced) {
[email protected]fc0ed302011-11-29 23:17:191036 RunDoNothingIfIncognitoIsForcedTest(GetSettingsURL());
[email protected]93ad8e1c2011-11-08 21:34:051037}
1038
[email protected]bd817c22011-02-09 08:16:461039// This test verifies that the bookmarks page isn't opened in the incognito
1040// window.
1041IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
1042 Disposition_Bookmarks_UseNonIncognitoWindow) {
[email protected]fc0ed302011-11-29 23:17:191043 RunUseNonIncognitoWindowTest(GURL(chrome::kChromeUIBookmarksURL));
[email protected]bd817c22011-02-09 08:16:461044}
1045
[email protected]93ad8e1c2011-11-08 21:34:051046// Bookmark manager is expected to always open in normal mode regardless
1047// of whether the user is trying to open it in incognito mode or not.
1048// This test verifies that if incognito mode is forced (by policy), bookmark
1049// manager doesn't open at all.
1050IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
1051 Disposition_Bookmarks_DoNothingIfIncognitoIsForced) {
[email protected]fc0ed302011-11-29 23:17:191052 RunDoNothingIfIncognitoIsForcedTest(GURL(chrome::kChromeUIBookmarksURL));
1053}
[email protected]93ad8e1c2011-11-08 21:34:051054
[email protected]7de53c62011-05-13 06:44:161055// This test makes sure a crashed singleton tab reloads from a new navigation.
[email protected]c4c0c0a12014-07-23 17:06:021056// http://crbug.com/396371
[email protected]7de53c62011-05-13 06:44:161057IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
[email protected]c4c0c0a12014-07-23 17:06:021058 DISABLED_NavigateToCrashedSingletonTab) {
[email protected]a048ad22012-03-23 04:26:561059 GURL singleton_url(GetContentSettingsURL());
[email protected]5a1a52462012-11-15 03:35:161060 WebContents* web_contents = chrome::AddSelectedTabWithURL(
Sylvain Defresnec6ccc77d2014-09-19 10:19:351061 browser(), singleton_url, ui::PAGE_TRANSITION_LINK);
[email protected]7de53c62011-05-13 06:44:161062
1063 // We should have one browser with 2 tabs, the 2nd selected.
[email protected]0665ebe2013-02-13 09:53:191064 EXPECT_EQ(1u, chrome::GetTotalBrowserCount());
[email protected]ee496952013-01-10 23:17:331065 EXPECT_EQ(2, browser()->tab_strip_model()->count());
1066 EXPECT_EQ(1, browser()->tab_strip_model()->active_index());
[email protected]7de53c62011-05-13 06:44:161067
1068 // Kill the singleton tab.
[email protected]83ff91c2012-01-05 20:54:131069 web_contents->SetIsCrashed(base::TERMINATION_STATUS_PROCESS_CRASHED, -1);
1070 EXPECT_TRUE(web_contents->IsCrashed());
[email protected]7de53c62011-05-13 06:44:161071
meacerc62e2ee2014-10-22 00:44:521072 chrome::NavigateParams params(MakeNavigateParams());
1073 params.disposition = SINGLETON_TAB;
1074 params.url = singleton_url;
1075 params.window_action = chrome::NavigateParams::SHOW_WINDOW;
1076 params.path_behavior = chrome::NavigateParams::IGNORE_AND_NAVIGATE;
1077 ui_test_utils::NavigateToURL(&params);
[email protected]7de53c62011-05-13 06:44:161078
1079 // The tab should not be sad anymore.
[email protected]83ff91c2012-01-05 20:54:131080 EXPECT_FALSE(web_contents->IsCrashed());
[email protected]7de53c62011-05-13 06:44:161081}
1082
[email protected]fcca741b2011-06-17 22:46:371083IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
1084 NavigateFromDefaultToOptionsInSameTab) {
[email protected]ddddfda2011-07-14 23:19:391085 {
[email protected]a7fe9112012-07-20 02:34:451086 content::WindowedNotificationObserver observer(
[email protected]ad50def52011-10-19 23:17:071087 content::NOTIFICATION_LOAD_STOP,
1088 content::NotificationService::AllSources());
[email protected]5d9cace72012-06-21 16:07:121089 chrome::ShowSettings(browser());
[email protected]ddddfda2011-07-14 23:19:391090 observer.Wait();
1091 }
[email protected]ee496952013-01-10 23:17:331092 EXPECT_EQ(1, browser()->tab_strip_model()->count());
[email protected]52877dbc62012-06-29 22:22:031093 EXPECT_EQ(GetSettingsURL(),
[email protected]ee496952013-01-10 23:17:331094 ShortenUberURL(browser()->tab_strip_model()->
1095 GetActiveWebContents()->GetURL()));
[email protected]fcca741b2011-06-17 22:46:371096}
1097
1098IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
1099 NavigateFromBlankToOptionsInSameTab) {
meacerc62e2ee2014-10-22 00:44:521100 chrome::NavigateParams params(MakeNavigateParams());
1101 params.url = GURL(url::kAboutBlankURL);
1102 ui_test_utils::NavigateToURL(&params);
[email protected]fcca741b2011-06-17 22:46:371103
[email protected]ddddfda2011-07-14 23:19:391104 {
[email protected]a7fe9112012-07-20 02:34:451105 content::WindowedNotificationObserver observer(
[email protected]ad50def52011-10-19 23:17:071106 content::NOTIFICATION_LOAD_STOP,
1107 content::NotificationService::AllSources());
[email protected]5d9cace72012-06-21 16:07:121108 chrome::ShowSettings(browser());
[email protected]ddddfda2011-07-14 23:19:391109 observer.Wait();
1110 }
[email protected]ee496952013-01-10 23:17:331111 EXPECT_EQ(1, browser()->tab_strip_model()->count());
[email protected]52877dbc62012-06-29 22:22:031112 EXPECT_EQ(GetSettingsURL(),
[email protected]ee496952013-01-10 23:17:331113 ShortenUberURL(browser()->tab_strip_model()->
1114 GetActiveWebContents()->GetURL()));
[email protected]fcca741b2011-06-17 22:46:371115}
1116
1117IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
1118 NavigateFromNTPToOptionsInSameTab) {
meacerc62e2ee2014-10-22 00:44:521119 chrome::NavigateParams params(MakeNavigateParams());
1120 params.url = GURL(chrome::kChromeUINewTabURL);
1121 ui_test_utils::NavigateToURL(&params);
[email protected]ee496952013-01-10 23:17:331122 EXPECT_EQ(1, browser()->tab_strip_model()->count());
[email protected]27658f32013-11-14 03:20:371123 EXPECT_EQ(GURL(chrome::kChromeUINewTabURL),
1124 browser()->tab_strip_model()->GetActiveWebContents()->GetURL());
[email protected]fcca741b2011-06-17 22:46:371125
[email protected]ddddfda2011-07-14 23:19:391126 {
[email protected]a7fe9112012-07-20 02:34:451127 content::WindowedNotificationObserver observer(
[email protected]ad50def52011-10-19 23:17:071128 content::NOTIFICATION_LOAD_STOP,
1129 content::NotificationService::AllSources());
[email protected]5d9cace72012-06-21 16:07:121130 chrome::ShowSettings(browser());
[email protected]ddddfda2011-07-14 23:19:391131 observer.Wait();
1132 }
[email protected]ee496952013-01-10 23:17:331133 EXPECT_EQ(1, browser()->tab_strip_model()->count());
[email protected]52877dbc62012-06-29 22:22:031134 EXPECT_EQ(GetSettingsURL(),
[email protected]ee496952013-01-10 23:17:331135 ShortenUberURL(browser()->tab_strip_model()->
1136 GetActiveWebContents()->GetURL()));
[email protected]fcca741b2011-06-17 22:46:371137}
1138
1139IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
1140 NavigateFromPageToOptionsInNewTab) {
meacerc62e2ee2014-10-22 00:44:521141 chrome::NavigateParams params(MakeNavigateParams());
1142 ui_test_utils::NavigateToURL(&params);
[email protected]ee496952013-01-10 23:17:331143 EXPECT_EQ(GetGoogleURL(),
1144 browser()->tab_strip_model()->GetActiveWebContents()->GetURL());
[email protected]0665ebe2013-02-13 09:53:191145 EXPECT_EQ(1u, chrome::GetTotalBrowserCount());
[email protected]ee496952013-01-10 23:17:331146 EXPECT_EQ(1, browser()->tab_strip_model()->count());
[email protected]fcca741b2011-06-17 22:46:371147
[email protected]ddddfda2011-07-14 23:19:391148 {
[email protected]a7fe9112012-07-20 02:34:451149 content::WindowedNotificationObserver observer(
[email protected]ad50def52011-10-19 23:17:071150 content::NOTIFICATION_LOAD_STOP,
1151 content::NotificationService::AllSources());
[email protected]5d9cace72012-06-21 16:07:121152 chrome::ShowSettings(browser());
[email protected]ddddfda2011-07-14 23:19:391153 observer.Wait();
1154 }
[email protected]ee496952013-01-10 23:17:331155 EXPECT_EQ(2, browser()->tab_strip_model()->count());
[email protected]52877dbc62012-06-29 22:22:031156 EXPECT_EQ(GetSettingsURL(),
[email protected]ee496952013-01-10 23:17:331157 ShortenUberURL(browser()->tab_strip_model()->
1158 GetActiveWebContents()->GetURL()));
[email protected]fcca741b2011-06-17 22:46:371159}
1160
1161IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
1162 NavigateFromNTPToOptionsSingleton) {
[email protected]ddddfda2011-07-14 23:19:391163 {
[email protected]a7fe9112012-07-20 02:34:451164 content::WindowedNotificationObserver observer(
[email protected]ad50def52011-10-19 23:17:071165 content::NOTIFICATION_LOAD_STOP,
1166 content::NotificationService::AllSources());
[email protected]5d9cace72012-06-21 16:07:121167 chrome::ShowSettings(browser());
[email protected]ddddfda2011-07-14 23:19:391168 observer.Wait();
1169 }
[email protected]ee496952013-01-10 23:17:331170 EXPECT_EQ(1, browser()->tab_strip_model()->count());
[email protected]fcca741b2011-06-17 22:46:371171
[email protected]a37d4b02012-06-25 21:56:101172 chrome::NewTab(browser());
[email protected]ee496952013-01-10 23:17:331173 EXPECT_EQ(2, browser()->tab_strip_model()->count());
[email protected]fcca741b2011-06-17 22:46:371174
[email protected]ddddfda2011-07-14 23:19:391175 {
[email protected]a7fe9112012-07-20 02:34:451176 content::WindowedNotificationObserver observer(
[email protected]ad50def52011-10-19 23:17:071177 content::NOTIFICATION_LOAD_STOP,
1178 content::NotificationService::AllSources());
[email protected]5d9cace72012-06-21 16:07:121179 chrome::ShowSettings(browser());
[email protected]ddddfda2011-07-14 23:19:391180 observer.Wait();
1181 }
[email protected]ee496952013-01-10 23:17:331182 EXPECT_EQ(2, browser()->tab_strip_model()->count());
[email protected]52877dbc62012-06-29 22:22:031183 EXPECT_EQ(GetSettingsURL(),
[email protected]ee496952013-01-10 23:17:331184 ShortenUberURL(browser()->tab_strip_model()->
1185 GetActiveWebContents()->GetURL()));
[email protected]fcca741b2011-06-17 22:46:371186}
1187
1188IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
1189 NavigateFromNTPToOptionsPageInSameTab) {
[email protected]ddddfda2011-07-14 23:19:391190 {
[email protected]a7fe9112012-07-20 02:34:451191 content::WindowedNotificationObserver observer(
[email protected]ad50def52011-10-19 23:17:071192 content::NOTIFICATION_LOAD_STOP,
1193 content::NotificationService::AllSources());
[email protected]5d9cace72012-06-21 16:07:121194 chrome::ShowClearBrowsingDataDialog(browser());
[email protected]ddddfda2011-07-14 23:19:391195 observer.Wait();
1196 }
[email protected]ee496952013-01-10 23:17:331197 EXPECT_EQ(1, browser()->tab_strip_model()->count());
[email protected]a048ad22012-03-23 04:26:561198 EXPECT_EQ(GetClearBrowsingDataURL(),
[email protected]ee496952013-01-10 23:17:331199 browser()->tab_strip_model()->GetActiveWebContents()->GetURL());
[email protected]fcca741b2011-06-17 22:46:371200
[email protected]a37d4b02012-06-25 21:56:101201 chrome::NewTab(browser());
[email protected]ee496952013-01-10 23:17:331202 EXPECT_EQ(2, browser()->tab_strip_model()->count());
[email protected]fcca741b2011-06-17 22:46:371203
[email protected]ddddfda2011-07-14 23:19:391204 {
[email protected]a7fe9112012-07-20 02:34:451205 content::WindowedNotificationObserver observer(
[email protected]ad50def52011-10-19 23:17:071206 content::NOTIFICATION_LOAD_STOP,
1207 content::NotificationService::AllSources());
[email protected]5d9cace72012-06-21 16:07:121208 chrome::ShowClearBrowsingDataDialog(browser());
[email protected]ddddfda2011-07-14 23:19:391209 observer.Wait();
1210 }
[email protected]ee496952013-01-10 23:17:331211 EXPECT_EQ(2, browser()->tab_strip_model()->count());
[email protected]a048ad22012-03-23 04:26:561212 EXPECT_EQ(GetClearBrowsingDataURL(),
[email protected]ee496952013-01-10 23:17:331213 browser()->tab_strip_model()->GetActiveWebContents()->GetURL());
[email protected]fcca741b2011-06-17 22:46:371214}
1215
1216IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
[email protected]05912742013-03-12 00:29:151217 NavigateFromOtherTabToSingletonOptions) {
[email protected]ddddfda2011-07-14 23:19:391218 {
[email protected]a7fe9112012-07-20 02:34:451219 content::WindowedNotificationObserver observer(
[email protected]ad50def52011-10-19 23:17:071220 content::NOTIFICATION_LOAD_STOP,
1221 content::NotificationService::AllSources());
[email protected]5d9cace72012-06-21 16:07:121222 chrome::ShowSettings(browser());
[email protected]ddddfda2011-07-14 23:19:391223 observer.Wait();
1224 }
1225 {
[email protected]a7fe9112012-07-20 02:34:451226 content::WindowedNotificationObserver observer(
[email protected]ad50def52011-10-19 23:17:071227 content::NOTIFICATION_LOAD_STOP,
1228 content::NotificationService::AllSources());
[email protected]52877dbc62012-06-29 22:22:031229 chrome::AddSelectedTabWithURL(browser(), GetGoogleURL(),
Sylvain Defresnec6ccc77d2014-09-19 10:19:351230 ui::PAGE_TRANSITION_LINK);
[email protected]ddddfda2011-07-14 23:19:391231 observer.Wait();
1232 }
[email protected]fcca741b2011-06-17 22:46:371233
[email protected]05912742013-03-12 00:29:151234 // This load should simply cause a tab switch.
1235 chrome::ShowSettings(browser());
1236
[email protected]ee496952013-01-10 23:17:331237 EXPECT_EQ(2, browser()->tab_strip_model()->count());
[email protected]ddddfda2011-07-14 23:19:391238 EXPECT_EQ(GetSettingsURL(),
[email protected]ee496952013-01-10 23:17:331239 ShortenUberURL(browser()->tab_strip_model()->
1240 GetActiveWebContents()->GetURL()));
[email protected]fcca741b2011-06-17 22:46:371241}
1242
[email protected]4e78b2d2013-06-12 16:46:171243IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, CloseSingletonTab) {
[email protected]79717cf2013-02-28 18:40:361244 for (int i = 0; i < 2; ++i) {
1245 content::WindowedNotificationObserver observer(
1246 content::NOTIFICATION_LOAD_STOP,
1247 content::NotificationService::AllSources());
1248 chrome::AddSelectedTabWithURL(browser(), GetGoogleURL(),
Sylvain Defresnec6ccc77d2014-09-19 10:19:351249 ui::PAGE_TRANSITION_TYPED);
[email protected]79717cf2013-02-28 18:40:361250 observer.Wait();
1251 }
1252
1253 browser()->tab_strip_model()->ActivateTabAt(0, true);
1254
1255 {
1256 content::WindowedNotificationObserver observer(
1257 content::NOTIFICATION_LOAD_STOP,
1258 content::NotificationService::AllSources());
1259 chrome::ShowSettings(browser());
1260 observer.Wait();
1261 }
1262
1263 EXPECT_TRUE(browser()->tab_strip_model()->CloseWebContentsAt(
1264 2, TabStripModel::CLOSE_USER_GESTURE));
1265 EXPECT_EQ(0, browser()->tab_strip_model()->active_index());
1266}
1267
[email protected]a048ad22012-03-23 04:26:561268// TODO(csilv): Update this for uber page. http://crbug.com/111579.
[email protected]ddddfda2011-07-14 23:19:391269IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
[email protected]a048ad22012-03-23 04:26:561270 DISABLED_NavigateFromDefaultToHistoryInSameTab) {
[email protected]ddddfda2011-07-14 23:19:391271 {
[email protected]a7fe9112012-07-20 02:34:451272 content::WindowedNotificationObserver observer(
[email protected]ad50def52011-10-19 23:17:071273 content::NOTIFICATION_LOAD_STOP,
1274 content::NotificationService::AllSources());
[email protected]5d9cace72012-06-21 16:07:121275 chrome::ShowHistory(browser());
[email protected]ddddfda2011-07-14 23:19:391276 observer.Wait();
1277 }
[email protected]ee496952013-01-10 23:17:331278 EXPECT_EQ(1, browser()->tab_strip_model()->count());
[email protected]11e03fb2012-03-03 19:07:051279 EXPECT_EQ(GURL(chrome::kChromeUIHistoryFrameURL),
[email protected]ee496952013-01-10 23:17:331280 browser()->tab_strip_model()->GetActiveWebContents()->GetURL());
[email protected]ddddfda2011-07-14 23:19:391281}
1282
[email protected]953c2132013-02-23 05:56:051283// TODO(linux_aura) http://crbug.com/163931
1284#if defined(OS_LINUX) && !defined(OS_CHROMEOS) && defined(USE_AURA)
1285#define MAYBE_NavigateFromDefaultToBookmarksInSameTab DISABLED_NavigateFromDefaultToBookmarksInSameTab
1286#else
1287#define MAYBE_NavigateFromDefaultToBookmarksInSameTab NavigateFromDefaultToBookmarksInSameTab
1288#endif
[email protected]ddddfda2011-07-14 23:19:391289IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
[email protected]953c2132013-02-23 05:56:051290 MAYBE_NavigateFromDefaultToBookmarksInSameTab) {
[email protected]ddddfda2011-07-14 23:19:391291 {
[email protected]a7fe9112012-07-20 02:34:451292 content::WindowedNotificationObserver observer(
[email protected]ad50def52011-10-19 23:17:071293 content::NOTIFICATION_LOAD_STOP,
1294 content::NotificationService::AllSources());
[email protected]5d9cace72012-06-21 16:07:121295 chrome::ShowBookmarkManager(browser());
[email protected]ddddfda2011-07-14 23:19:391296 observer.Wait();
1297 }
[email protected]ee496952013-01-10 23:17:331298 EXPECT_EQ(1, browser()->tab_strip_model()->count());
brettw66d1b81b2015-07-06 19:29:401299 EXPECT_TRUE(base::StartsWith(
[email protected]bc16a252013-01-23 02:21:491300 browser()->tab_strip_model()->GetActiveWebContents()->GetURL().spec(),
brettw66d1b81b2015-07-06 19:29:401301 chrome::kChromeUIBookmarksURL, base::CompareCase::SENSITIVE));
[email protected]ddddfda2011-07-14 23:19:391302}
1303
1304IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
1305 NavigateFromDefaultToDownloadsInSameTab) {
1306 {
[email protected]a7fe9112012-07-20 02:34:451307 content::WindowedNotificationObserver observer(
[email protected]ad50def52011-10-19 23:17:071308 content::NOTIFICATION_LOAD_STOP,
1309 content::NotificationService::AllSources());
[email protected]5d9cace72012-06-21 16:07:121310 chrome::ShowDownloads(browser());
[email protected]ddddfda2011-07-14 23:19:391311 observer.Wait();
1312 }
[email protected]ee496952013-01-10 23:17:331313 EXPECT_EQ(1, browser()->tab_strip_model()->count());
[email protected]ddddfda2011-07-14 23:19:391314 EXPECT_EQ(GURL(chrome::kChromeUIDownloadsURL),
[email protected]ee496952013-01-10 23:17:331315 browser()->tab_strip_model()->GetActiveWebContents()->GetURL());
[email protected]ddddfda2011-07-14 23:19:391316}
1317
[email protected]8fb16a82012-08-17 02:17:591318IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
1319 NavigateWithoutBrowser) {
1320 // First navigate using the profile of the existing browser window, and
1321 // check that the window is reused.
1322 chrome::NavigateParams params(browser()->profile(), GetGoogleURL(),
Sylvain Defresnec6ccc77d2014-09-19 10:19:351323 ui::PAGE_TRANSITION_LINK);
[email protected]8fb16a82012-08-17 02:17:591324 ui_test_utils::NavigateToURL(&params);
[email protected]0665ebe2013-02-13 09:53:191325 EXPECT_EQ(1u, chrome::GetTotalBrowserCount());
[email protected]8fb16a82012-08-17 02:17:591326
1327 // Now navigate using the incognito profile and check that a new window
1328 // is created.
1329 chrome::NavigateParams params_incognito(
1330 browser()->profile()->GetOffTheRecordProfile(),
Sylvain Defresnec6ccc77d2014-09-19 10:19:351331 GetGoogleURL(), ui::PAGE_TRANSITION_LINK);
[email protected]8fb16a82012-08-17 02:17:591332 ui_test_utils::NavigateToURL(&params_incognito);
[email protected]0665ebe2013-02-13 09:53:191333 EXPECT_EQ(2u, chrome::GetTotalBrowserCount());
[email protected]8fb16a82012-08-17 02:17:591334}
1335
[email protected]beb1d1192013-05-14 04:47:511336IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, ViewSourceIsntSingleton) {
1337 const std::string viewsource_ntp_url =
[email protected]dbdda5402013-05-30 22:13:481338 std::string(content::kViewSourceScheme) + ":" +
[email protected]beb1d1192013-05-14 04:47:511339 chrome::kChromeUIVersionURL;
1340
1341 chrome::NavigateParams viewsource_params(browser(),
1342 GURL(viewsource_ntp_url),
Sylvain Defresnec6ccc77d2014-09-19 10:19:351343 ui::PAGE_TRANSITION_LINK);
[email protected]beb1d1192013-05-14 04:47:511344 ui_test_utils::NavigateToURL(&viewsource_params);
1345
1346 chrome::NavigateParams singleton_params(browser(),
1347 GURL(chrome::kChromeUIVersionURL),
Sylvain Defresnec6ccc77d2014-09-19 10:19:351348 ui::PAGE_TRANSITION_LINK);
[email protected]beb1d1192013-05-14 04:47:511349 singleton_params.disposition = SINGLETON_TAB;
1350 EXPECT_EQ(-1, chrome::GetIndexOfSingletonTab(&singleton_params));
1351}
1352
[email protected]a2efc35d2013-08-03 23:17:251353// This test verifies that browser initiated navigations can send requests
1354// using POST.
1355IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
1356 SendBrowserInitiatedRequestUsingPOST) {
1357 // Uses a test sever to verify POST request.
1358 ASSERT_TRUE(test_server()->Start());
1359
1360 // Open a browser initiated POST request in new foreground tab.
[email protected]e9273e192013-12-11 17:51:491361 base::string16 expected_title(base::ASCIIToUTF16(kExpectedTitle));
[email protected]a2efc35d2013-08-03 23:17:251362 std::string post_data = kExpectedTitle;
[email protected]e9273e192013-12-11 17:51:491363 base::string16 title;
[email protected]a2efc35d2013-08-03 23:17:251364 ASSERT_TRUE(OpenPOSTURLInNewForegroundTabAndGetTitle(
1365 test_server()->GetURL(kEchoTitleCommand), post_data, true, &title));
1366 EXPECT_EQ(expected_title, title);
1367}
1368
1369// This test verifies that renderer initiated navigations can NOT send requests
1370// using POST.
1371IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
1372 SendRendererInitiatedRequestUsingPOST) {
1373 // Uses a test sever to verify POST request.
1374 ASSERT_TRUE(test_server()->Start());
1375
1376 // Open a renderer initiated POST request in new foreground tab.
[email protected]e9273e192013-12-11 17:51:491377 base::string16 expected_title(base::ASCIIToUTF16(kExpectedTitle));
[email protected]a2efc35d2013-08-03 23:17:251378 std::string post_data = kExpectedTitle;
[email protected]e9273e192013-12-11 17:51:491379 base::string16 title;
[email protected]a2efc35d2013-08-03 23:17:251380 ASSERT_TRUE(OpenPOSTURLInNewForegroundTabAndGetTitle(
1381 test_server()->GetURL(kEchoTitleCommand), post_data, false, &title));
1382 EXPECT_NE(expected_title, title);
1383}
1384
meacerc62e2ee2014-10-22 00:44:521385// This test navigates to a data URL that contains BiDi control
1386// characters. For security reasons, BiDi control chars should always be
1387// escaped in the URL but they should be unescaped in the loaded HTML.
1388IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
1389 NavigateToDataURLWithBiDiControlChars) {
1390 // Text in Arabic.
1391 std::string text = "\xD8\xA7\xD8\xAE\xD8\xAA\xD8\xA8\xD8\xA7\xD8\xB1";
1392 // Page title starts with RTL mark.
1393 std::string unescaped_title = "\xE2\x80\x8F" + text;
1394 std::string data_url = "data:text/html;charset=utf-8,<html><title>" +
1395 unescaped_title + "</title></html>";
1396 // BiDi control chars in URLs are always escaped, so the expected URL should
1397 // have the title with the escaped RTL mark.
1398 std::string escaped_title = "%E2%80%8F" + text;
1399 std::string expected_url = "data:text/html;charset=utf-8,<html><title>" +
1400 escaped_title + "</title></html>";
1401
1402 // Navigate to the page.
1403 chrome::NavigateParams params(MakeNavigateParams());
1404 params.disposition = NEW_FOREGROUND_TAB;
1405 params.url = GURL(data_url);
1406 params.window_action = chrome::NavigateParams::SHOW_WINDOW;
1407 ui_test_utils::NavigateToURL(&params);
1408
1409 base::string16 expected_title(base::UTF8ToUTF16(unescaped_title));
1410 EXPECT_TRUE(params.target_contents);
1411 EXPECT_EQ(expected_title, params.target_contents->GetTitle());
1412 // GURL always keeps non-ASCII characters escaped, but check them anyways.
1413 EXPECT_EQ(GURL(expected_url).spec(), params.target_contents->GetURL().spec());
1414 // Check the omnibox text. It should have escaped RTL with unescaped text.
1415 LocationBar* location_bar = browser()->window()->GetLocationBar();
1416 OmniboxView* omnibox_view = location_bar->GetOmniboxView();
1417 EXPECT_EQ(base::UTF8ToUTF16(expected_url), omnibox_view->GetText());
1418}
1419
[email protected]a2efc35d2013-08-03 23:17:251420} // namespace