blob: 8debfe8d880d14fb762c4951f8a0147d7a4f1a6f [file] [log] [blame]
[email protected]8643e6d2012-01-18 20:26:101// Copyright (c) 2012 The Chromium Authors. All rights reserved.
[email protected]a1feae52010-10-11 22:14:452// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
[email protected]bd817c22011-02-09 08:16:465#include "chrome/browser/ui/browser_navigator_browsertest.h"
6
[email protected]bb89e7482010-11-17 18:27:047#include "base/command_line.h"
[email protected]fc2b46b2014-05-03 16:33:458#include "base/strings/string_util.h"
[email protected]a2efc35d2013-08-03 23:17:259#include "base/strings/utf_string_conversions.h"
avi655876a2015-12-25 07:18:1510#include "build/build_config.h"
[email protected]26c53e662011-07-09 02:21:0211#include "chrome/app/chrome_command_ids.h"
[email protected]93ad8e1c2011-11-08 21:34:0512#include "chrome/browser/prefs/incognito_mode_prefs.h"
[email protected]8ecad5e2010-12-02 21:18:3313#include "chrome/browser/profiles/profile.h"
[email protected]2b09ae552013-02-23 06:38:0314#include "chrome/browser/ui/browser.h"
[email protected]a37d4b02012-06-25 21:56:1015#include "chrome/browser/ui/browser_commands.h"
[email protected]0665ebe2013-02-13 09:53:1916#include "chrome/browser/ui/browser_finder.h"
[email protected]339d6dd2010-11-12 00:41:5817#include "chrome/browser/ui/browser_navigator.h"
thestige80821242015-09-30 23:46:0818#include "chrome/browser/ui/browser_navigator_params.h"
[email protected]52877dbc62012-06-29 22:22:0319#include "chrome/browser/ui/browser_tabstrip.h"
[email protected]bb89e7482010-11-17 18:27:0420#include "chrome/browser/ui/browser_window.h"
[email protected]5d9cace72012-06-21 16:07:1221#include "chrome/browser/ui/chrome_pages.h"
meacerc62e2ee2014-10-22 00:44:5222#include "chrome/browser/ui/location_bar/location_bar.h"
[email protected]beb1d1192013-05-14 04:47:5123#include "chrome/browser/ui/singleton_tabs.h"
[email protected]b56e2e32012-05-11 21:18:0424#include "chrome/browser/ui/tabs/tab_strip_model.h"
[email protected]bb89e7482010-11-17 18:27:0425#include "chrome/common/chrome_switches.h"
[email protected]93ad8e1c2011-11-08 21:34:0526#include "chrome/common/pref_names.h"
[email protected]ddddfda2011-07-14 23:19:3927#include "chrome/common/url_constants.h"
[email protected]af44e7fb2011-07-29 18:32:3228#include "chrome/test/base/ui_test_utils.h"
blundell7dbd3792015-08-05 15:14:1929#include "components/omnibox/browser/omnibox_view.h"
brettwb1fc1b82016-02-02 00:19:0830#include "components/prefs/pref_service.h"
[email protected]ad50def52011-10-19 23:17:0731#include "content/public/browser/notification_service.h"
[email protected]0d6e9bd2011-10-18 04:29:1632#include "content/public/browser/notification_types.h"
lof84501da082016-05-23 21:22:5433#include "content/public/browser/render_frame_host.h"
34#include "content/public/browser/render_process_host.h"
[email protected]83ff91c2012-01-05 20:54:1335#include "content/public/browser/web_contents.h"
lukasza477a5a22016-06-16 18:28:4336#include "content/public/common/resource_request_body.h"
lof84501da082016-05-23 21:22:5437#include "content/public/test/browser_test_utils.h"
svaldeza01f7d92015-11-18 17:47:5638#include "net/test/embedded_test_server/embedded_test_server.h"
[email protected]a1feae52010-10-11 22:14:4539
[email protected]4ca15302012-01-03 05:53:2040using content::WebContents;
41
[email protected]ddddfda2011-07-14 23:19:3942namespace {
43
[email protected]a2efc35d2013-08-03 23:17:2544const char kExpectedTitle[] = "PASSED!";
svaldeza01f7d92015-11-18 17:47:5645const char kEchoTitleCommand[] = "/echotitle";
[email protected]a2efc35d2013-08-03 23:17:2546
[email protected]ddddfda2011-07-14 23:19:3947GURL GetGoogleURL() {
[email protected]bd817c22011-02-09 08:16:4648 return GURL("http://www.google.com/");
49}
[email protected]a1feae52010-10-11 22:14:4550
[email protected]ddddfda2011-07-14 23:19:3951GURL GetSettingsURL() {
[email protected]f8f93eb2012-09-25 03:06:2452 return GURL(chrome::kChromeUISettingsURL);
[email protected]ddddfda2011-07-14 23:19:3953}
54
[email protected]a048ad22012-03-23 04:26:5655GURL GetContentSettingsURL() {
56 return GetSettingsURL().Resolve(chrome::kContentSettingsExceptionsSubPage);
[email protected]ddddfda2011-07-14 23:19:3957}
58
[email protected]a048ad22012-03-23 04:26:5659GURL GetClearBrowsingDataURL() {
60 return GetSettingsURL().Resolve(chrome::kClearBrowserDataSubPage);
[email protected]ddddfda2011-07-14 23:19:3961}
62
[email protected]f8f93eb2012-09-25 03:06:2463// Converts long uber URLs ("chrome://chrome/foo/") to short (virtual) URLs
64// ("chrome://foo/"). This should be used to convert the return value of
65// WebContentsImpl::GetURL before comparison because it can return either the
66// real URL or the virtual URL.
67GURL ShortenUberURL(const GURL& url) {
68 std::string url_string = url.spec();
69 const std::string long_prefix = "chrome://chrome/";
70 const std::string short_prefix = "chrome://";
71 if (url_string.find(long_prefix) != 0)
72 return url;
73 url_string.replace(0, long_prefix.length(), short_prefix);
74 return GURL(url_string);
75}
76
[email protected]a2efc35d2013-08-03 23:17:2577} // namespace
[email protected]ddddfda2011-07-14 23:19:3978
[email protected]78e2edc2012-07-01 23:32:2879chrome::NavigateParams BrowserNavigatorTest::MakeNavigateParams() const {
[email protected]bd817c22011-02-09 08:16:4680 return MakeNavigateParams(browser());
81}
[email protected]a1feae52010-10-11 22:14:4582
[email protected]78e2edc2012-07-01 23:32:2883chrome::NavigateParams BrowserNavigatorTest::MakeNavigateParams(
[email protected]bd817c22011-02-09 08:16:4684 Browser* browser) const {
[email protected]78e2edc2012-07-01 23:32:2885 chrome::NavigateParams params(browser, GetGoogleURL(),
Sylvain Defresnec6ccc77d2014-09-19 10:19:3586 ui::PAGE_TRANSITION_LINK);
[email protected]50592b52013-05-02 22:26:2587 params.window_action = chrome::NavigateParams::SHOW_WINDOW;
[email protected]bd817c22011-02-09 08:16:4688 return params;
89}
[email protected]a1feae52010-10-11 22:14:4590
[email protected]a2efc35d2013-08-03 23:17:2591bool BrowserNavigatorTest::OpenPOSTURLInNewForegroundTabAndGetTitle(
92 const GURL& url, const std::string& post_data, bool is_browser_initiated,
93 base::string16* title) {
94 chrome::NavigateParams param(MakeNavigateParams());
95 param.disposition = NEW_FOREGROUND_TAB;
96 param.url = url;
97 param.is_renderer_initiated = !is_browser_initiated;
98 param.uses_post = true;
lukasza477a5a22016-06-16 18:28:4399 param.post_data = content::ResourceRequestBody::CreateFromBytes(
[email protected]8df08cf2014-02-12 22:34:08100 post_data.data(), post_data.size());
[email protected]a2efc35d2013-08-03 23:17:25101
102 ui_test_utils::NavigateToURL(&param);
103 if (!param.target_contents)
104 return false;
105
106 // Navigate() should have opened the contents in new foreground tab in the
107 // current Browser.
108 EXPECT_EQ(browser(), param.browser);
109 EXPECT_EQ(browser()->tab_strip_model()->GetActiveWebContents(),
110 param.target_contents);
111 // We should have one window, with one tab.
112 EXPECT_EQ(1u, chrome::GetTotalBrowserCount());
113 EXPECT_EQ(2, browser()->tab_strip_model()->count());
114
115 *title = param.target_contents->GetTitle();
116 return true;
117}
118
[email protected]bd817c22011-02-09 08:16:46119Browser* BrowserNavigatorTest::CreateEmptyBrowserForType(Browser::Type type,
120 Profile* profile) {
scottmg851949002016-02-09 20:09:44121 Browser* browser = new Browser(Browser::CreateParams(type, profile));
[email protected]00509a32013-11-17 17:45:37122 chrome::AddTabAt(browser, GURL(), -1, true);
[email protected]bd817c22011-02-09 08:16:46123 return browser;
124}
[email protected]a1feae52010-10-11 22:14:45125
[email protected]d2202e22014-04-14 20:20:53126Browser* BrowserNavigatorTest::CreateEmptyBrowserForApp(Profile* profile) {
scottmg851949002016-02-09 20:09:44127 Browser* browser = new Browser(Browser::CreateParams::CreateForApp(
128 "Test", false /* trusted_source */, gfx::Rect(), profile));
[email protected]00509a32013-11-17 17:45:37129 chrome::AddTabAt(browser, GURL(), -1, true);
[email protected]b35b26b32011-05-05 20:35:14130 return browser;
131}
132
lof84501da082016-05-23 21:22:54133WebContents* BrowserNavigatorTest::CreateWebContents(bool initialize_renderer) {
[email protected]54944cde2012-12-09 09:24:59134 content::WebContents::CreateParams create_params(browser()->profile());
lof84501da082016-05-23 21:22:54135 create_params.initialize_renderer = initialize_renderer;
[email protected]ed245db2012-12-18 08:00:45136 content::WebContents* base_web_contents =
[email protected]ee496952013-01-10 23:17:33137 browser()->tab_strip_model()->GetActiveWebContents();
[email protected]ed245db2012-12-18 08:00:45138 if (base_web_contents) {
139 create_params.initial_size =
[email protected]fc2b46b2014-05-03 16:33:45140 base_web_contents->GetContainerBounds().size();
[email protected]ed245db2012-12-18 08:00:45141 }
[email protected]54944cde2012-12-09 09:24:59142 return WebContents::Create(create_params);
[email protected]bd817c22011-02-09 08:16:46143}
[email protected]a1feae52010-10-11 22:14:45144
[email protected]bd817c22011-02-09 08:16:46145void BrowserNavigatorTest::RunSuppressTest(WindowOpenDisposition disposition) {
[email protected]ee496952013-01-10 23:17:33146 GURL old_url = browser()->tab_strip_model()->GetActiveWebContents()->GetURL();
meacerc62e2ee2014-10-22 00:44:52147 chrome::NavigateParams params(MakeNavigateParams());
148 params.disposition = disposition;
149 chrome::Navigate(&params);
[email protected]a1feae52010-10-11 22:14:45150
[email protected]bd817c22011-02-09 08:16:46151 // Nothing should have happened as a result of Navigate();
[email protected]ee496952013-01-10 23:17:33152 EXPECT_EQ(1, browser()->tab_strip_model()->count());
[email protected]0665ebe2013-02-13 09:53:19153 EXPECT_EQ(1u, chrome::GetTotalBrowserCount());
[email protected]ee496952013-01-10 23:17:33154 EXPECT_EQ(old_url,
155 browser()->tab_strip_model()->GetActiveWebContents()->GetURL());
[email protected]bd817c22011-02-09 08:16:46156}
[email protected]bb89e7482010-11-17 18:27:04157
[email protected]fc0ed302011-11-29 23:17:19158void BrowserNavigatorTest::RunUseNonIncognitoWindowTest(const GURL& url) {
159 Browser* incognito_browser = CreateIncognitoBrowser();
160
[email protected]0665ebe2013-02-13 09:53:19161 EXPECT_EQ(2u, chrome::GetTotalBrowserCount());
[email protected]ee496952013-01-10 23:17:33162 EXPECT_EQ(1, browser()->tab_strip_model()->count());
163 EXPECT_EQ(1, incognito_browser->tab_strip_model()->count());
[email protected]fc0ed302011-11-29 23:17:19164
165 // Navigate to the page.
meacerc62e2ee2014-10-22 00:44:52166 chrome::NavigateParams params(MakeNavigateParams(incognito_browser));
167 params.disposition = SINGLETON_TAB;
168 params.url = url;
169 params.window_action = chrome::NavigateParams::SHOW_WINDOW;
170 chrome::Navigate(&params);
[email protected]fc0ed302011-11-29 23:17:19171
[email protected]50592b52013-05-02 22:26:25172 // This page should be opened in browser() window.
meacerc62e2ee2014-10-22 00:44:52173 EXPECT_NE(incognito_browser, params.browser);
174 EXPECT_EQ(browser(), params.browser);
[email protected]ee496952013-01-10 23:17:33175 EXPECT_EQ(2, browser()->tab_strip_model()->count());
176 EXPECT_EQ(url,
177 browser()->tab_strip_model()->GetActiveWebContents()->GetURL());
[email protected]fc0ed302011-11-29 23:17:19178}
179
180void BrowserNavigatorTest::RunDoNothingIfIncognitoIsForcedTest(
181 const GURL& url) {
182 Browser* browser = CreateIncognitoBrowser();
183
184 // Set kIncognitoModeAvailability to FORCED.
185 PrefService* prefs1 = browser->profile()->GetPrefs();
186 prefs1->SetInteger(prefs::kIncognitoModeAvailability,
187 IncognitoModePrefs::FORCED);
188 PrefService* prefs2 = browser->profile()->GetOriginalProfile()->GetPrefs();
189 prefs2->SetInteger(prefs::kIncognitoModeAvailability,
190 IncognitoModePrefs::FORCED);
191
192 // Navigate to the page.
meacerc62e2ee2014-10-22 00:44:52193 chrome::NavigateParams params(MakeNavigateParams(browser));
194 params.disposition = OFF_THE_RECORD;
195 params.url = url;
196 params.window_action = chrome::NavigateParams::SHOW_WINDOW;
197 chrome::Navigate(&params);
[email protected]fc0ed302011-11-29 23:17:19198
199 // The page should not be opened.
meacerc62e2ee2014-10-22 00:44:52200 EXPECT_EQ(browser, params.browser);
[email protected]ee496952013-01-10 23:17:33201 EXPECT_EQ(1, browser->tab_strip_model()->count());
[email protected]8e09c7af2014-06-10 11:46:17202 EXPECT_EQ(GURL(url::kAboutBlankURL),
[email protected]ee496952013-01-10 23:17:33203 browser->tab_strip_model()->GetActiveWebContents()->GetURL());
[email protected]fc0ed302011-11-29 23:17:19204}
205
[email protected]aae79572014-06-13 00:42:58206void BrowserNavigatorTest::SetUpCommandLine(base::CommandLine* command_line) {
207 // Disable settings-in-a-window so that we can use the settings page and
208 // sub-pages to test browser navigation.
209 command_line->AppendSwitch(::switches::kDisableSettingsWindow);
[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) {
thestig1d619242016-06-13 22:24:52216 DCHECK_EQ(content::NOTIFICATION_WEB_CONTENTS_RENDER_VIEW_HOST_CREATED, type);
217 ++created_tab_contents_count_;
[email protected]bd817c22011-02-09 08:16:46218}
[email protected]fa7ebe02010-11-29 23:04:57219
[email protected]ddddfda2011-07-14 23:19:39220
[email protected]bd817c22011-02-09 08:16:46221namespace {
[email protected]a1feae52010-10-11 22:14:45222
[email protected]a1feae52010-10-11 22:14:45223// This test verifies that when a navigation occurs within a tab, the tab count
224// of the Browser remains the same and the current tab bears the loaded URL.
[email protected]59167c22013-06-03 18:07:32225// Note that network URLs are not actually loaded in tests, so this also tests
226// that error pages leave the intended URL in the address bar.
[email protected]a1feae52010-10-11 22:14:45227IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_CurrentTab) {
[email protected]ddddfda2011-07-14 23:19:39228 ui_test_utils::NavigateToURL(browser(), GetGoogleURL());
[email protected]ee496952013-01-10 23:17:33229 EXPECT_EQ(GetGoogleURL(),
230 browser()->tab_strip_model()->GetActiveWebContents()->GetURL());
[email protected]a1feae52010-10-11 22:14:45231 // We should have one window with one tab.
[email protected]0665ebe2013-02-13 09:53:19232 EXPECT_EQ(1u, chrome::GetTotalBrowserCount());
[email protected]ee496952013-01-10 23:17:33233 EXPECT_EQ(1, browser()->tab_strip_model()->count());
[email protected]a1feae52010-10-11 22:14:45234}
235
[email protected]bd817c22011-02-09 08:16:46236// This test verifies that a singleton tab is refocused if one is already opened
[email protected]19d9f3a2010-10-14 21:49:36237// in another or an existing window, or added if it is not.
238IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_SingletonTabExisting) {
[email protected]19d9f3a2010-10-14 21:49:36239 GURL singleton_url1("http://maps.google.com/");
[email protected]fa7ebe02010-11-29 23:04:57240
[email protected]e232c992012-12-06 12:43:20241 // Register for a notification if an additional WebContents was instantiated.
[email protected]bd817c22011-02-09 08:16:46242 // Opening a Singleton tab that is already opened should not be opening a new
[email protected]e232c992012-12-06 12:43:20243 // tab nor be creating a new WebContents object.
[email protected]6c2381d2011-10-19 02:52:53244 content::NotificationRegistrar registrar;
[email protected]fa7ebe02010-11-29 23:04:57245
246 // As the registrar object goes out of scope, this will get unregistered
[email protected]d53a08c2012-07-18 20:35:30247 registrar.Add(this,
248 content::NOTIFICATION_WEB_CONTENTS_RENDER_VIEW_HOST_CREATED,
[email protected]ad50def52011-10-19 23:17:07249 content::NotificationService::AllSources());
[email protected]fa7ebe02010-11-29 23:04:57250
[email protected]52877dbc62012-06-29 22:22:03251 chrome::AddSelectedTabWithURL(browser(), singleton_url1,
Sylvain Defresnec6ccc77d2014-09-19 10:19:35252 ui::PAGE_TRANSITION_LINK);
[email protected]52877dbc62012-06-29 22:22:03253 chrome::AddSelectedTabWithURL(browser(), GetGoogleURL(),
Sylvain Defresnec6ccc77d2014-09-19 10:19:35254 ui::PAGE_TRANSITION_LINK);
[email protected]19d9f3a2010-10-14 21:49:36255
256 // We should have one browser with 3 tabs, the 3rd selected.
[email protected]0665ebe2013-02-13 09:53:19257 EXPECT_EQ(1u, chrome::GetTotalBrowserCount());
[email protected]ee496952013-01-10 23:17:33258 EXPECT_EQ(2, browser()->tab_strip_model()->active_index());
[email protected]19d9f3a2010-10-14 21:49:36259
[email protected]fa7ebe02010-11-29 23:04:57260 unsigned int previous_tab_contents_count =
261 created_tab_contents_count_ = 0;
262
[email protected]19d9f3a2010-10-14 21:49:36263 // Navigate to singleton_url1.
meacerc62e2ee2014-10-22 00:44:52264 chrome::NavigateParams params(MakeNavigateParams());
265 params.disposition = SINGLETON_TAB;
266 params.url = singleton_url1;
267 chrome::Navigate(&params);
[email protected]19d9f3a2010-10-14 21:49:36268
269 // The middle tab should now be selected.
meacerc62e2ee2014-10-22 00:44:52270 EXPECT_EQ(browser(), params.browser);
[email protected]ee496952013-01-10 23:17:33271 EXPECT_EQ(1, browser()->tab_strip_model()->active_index());
[email protected]fa7ebe02010-11-29 23:04:57272
273 // No tab contents should have been created
274 EXPECT_EQ(previous_tab_contents_count,
275 created_tab_contents_count_);
[email protected]19d9f3a2010-10-14 21:49:36276}
277
278IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
[email protected]578c6962011-08-24 22:06:40279 Disposition_SingletonTabRespectingRef) {
280 GURL singleton_ref_url1("http://maps.google.com/#a");
281 GURL singleton_ref_url2("http://maps.google.com/#b");
282 GURL singleton_ref_url3("http://maps.google.com/");
283
[email protected]52877dbc62012-06-29 22:22:03284 chrome::AddSelectedTabWithURL(browser(), singleton_ref_url1,
Sylvain Defresnec6ccc77d2014-09-19 10:19:35285 ui::PAGE_TRANSITION_LINK);
[email protected]578c6962011-08-24 22:06:40286
287 // We should have one browser with 2 tabs, 2nd selected.
[email protected]0665ebe2013-02-13 09:53:19288 EXPECT_EQ(1u, chrome::GetTotalBrowserCount());
[email protected]ee496952013-01-10 23:17:33289 EXPECT_EQ(2, browser()->tab_strip_model()->count());
290 EXPECT_EQ(1, browser()->tab_strip_model()->active_index());
[email protected]578c6962011-08-24 22:06:40291
292 // Navigate to singleton_url2.
meacerc62e2ee2014-10-22 00:44:52293 chrome::NavigateParams params(MakeNavigateParams());
294 params.disposition = SINGLETON_TAB;
295 params.url = singleton_ref_url2;
296 chrome::Navigate(&params);
[email protected]578c6962011-08-24 22:06:40297
298 // We should now have 2 tabs, the 2nd one selected.
meacerc62e2ee2014-10-22 00:44:52299 EXPECT_EQ(browser(), params.browser);
[email protected]ee496952013-01-10 23:17:33300 EXPECT_EQ(2, browser()->tab_strip_model()->count());
301 EXPECT_EQ(1, browser()->tab_strip_model()->active_index());
[email protected]578c6962011-08-24 22:06:40302
303 // Navigate to singleton_url2, but with respect ref set.
meacerc62e2ee2014-10-22 00:44:52304 params = MakeNavigateParams();
305 params.disposition = SINGLETON_TAB;
306 params.url = singleton_ref_url2;
307 params.ref_behavior = chrome::NavigateParams::RESPECT_REF;
308 chrome::Navigate(&params);
[email protected]578c6962011-08-24 22:06:40309
310 // We should now have 3 tabs, the 3th one selected.
meacerc62e2ee2014-10-22 00:44:52311 EXPECT_EQ(browser(), params.browser);
[email protected]ee496952013-01-10 23:17:33312 EXPECT_EQ(3, browser()->tab_strip_model()->count());
313 EXPECT_EQ(2, browser()->tab_strip_model()->active_index());
[email protected]578c6962011-08-24 22:06:40314
315 // Navigate to singleton_url3.
meacerc62e2ee2014-10-22 00:44:52316 params = MakeNavigateParams();
317 params.disposition = SINGLETON_TAB;
318 params.url = singleton_ref_url3;
319 params.ref_behavior = chrome::NavigateParams::RESPECT_REF;
320 chrome::Navigate(&params);
[email protected]578c6962011-08-24 22:06:40321
322 // We should now have 4 tabs, the 4th one selected.
meacerc62e2ee2014-10-22 00:44:52323 EXPECT_EQ(browser(), params.browser);
[email protected]ee496952013-01-10 23:17:33324 EXPECT_EQ(4, browser()->tab_strip_model()->count());
325 EXPECT_EQ(3, browser()->tab_strip_model()->active_index());
[email protected]578c6962011-08-24 22:06:40326}
327
328IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
[email protected]19d9f3a2010-10-14 21:49:36329 Disposition_SingletonTabNoneExisting) {
[email protected]19d9f3a2010-10-14 21:49:36330 GURL singleton_url1("http://maps.google.com/");
331
[email protected]bd817c22011-02-09 08:16:46332 // We should have one browser with 1 tab.
[email protected]0665ebe2013-02-13 09:53:19333 EXPECT_EQ(1u, chrome::GetTotalBrowserCount());
[email protected]ee496952013-01-10 23:17:33334 EXPECT_EQ(0, browser()->tab_strip_model()->active_index());
[email protected]19d9f3a2010-10-14 21:49:36335
336 // Navigate to singleton_url1.
meacerc62e2ee2014-10-22 00:44:52337 chrome::NavigateParams params(MakeNavigateParams());
338 params.disposition = SINGLETON_TAB;
339 params.url = singleton_url1;
340 chrome::Navigate(&params);
[email protected]19d9f3a2010-10-14 21:49:36341
342 // We should now have 2 tabs, the 2nd one selected.
meacerc62e2ee2014-10-22 00:44:52343 EXPECT_EQ(browser(), params.browser);
[email protected]ee496952013-01-10 23:17:33344 EXPECT_EQ(2, browser()->tab_strip_model()->count());
345 EXPECT_EQ(1, browser()->tab_strip_model()->active_index());
[email protected]a1feae52010-10-11 22:14:45346}
347
348// This test verifies that when a navigation results in a foreground tab, the
349// tab count of the Browser increases and the selected tab shifts to the new
350// foreground tab.
351IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_NewForegroundTab) {
[email protected]ee496952013-01-10 23:17:33352 WebContents* old_contents =
353 browser()->tab_strip_model()->GetActiveWebContents();
meacerc62e2ee2014-10-22 00:44:52354 chrome::NavigateParams params(MakeNavigateParams());
355 params.disposition = NEW_FOREGROUND_TAB;
356 chrome::Navigate(&params);
[email protected]ee496952013-01-10 23:17:33357 EXPECT_NE(old_contents,
358 browser()->tab_strip_model()->GetActiveWebContents());
[email protected]e232c992012-12-06 12:43:20359 EXPECT_EQ(browser()->tab_strip_model()->GetActiveWebContents(),
meacerc62e2ee2014-10-22 00:44:52360 params.target_contents);
[email protected]ee496952013-01-10 23:17:33361 EXPECT_EQ(2, browser()->tab_strip_model()->count());
[email protected]a1feae52010-10-11 22:14:45362}
363
364// This test verifies that when a navigation results in a background tab, the
365// tab count of the Browser increases but the selected tab remains the same.
366IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_NewBackgroundTab) {
[email protected]ee496952013-01-10 23:17:33367 WebContents* old_contents =
368 browser()->tab_strip_model()->GetActiveWebContents();
meacerc62e2ee2014-10-22 00:44:52369 chrome::NavigateParams params(MakeNavigateParams());
370 params.disposition = NEW_BACKGROUND_TAB;
371 chrome::Navigate(&params);
[email protected]ee496952013-01-10 23:17:33372 WebContents* new_contents =
373 browser()->tab_strip_model()->GetActiveWebContents();
[email protected]a1feae52010-10-11 22:14:45374 // The selected tab should have remained unchanged, since the new tab was
375 // opened in the background.
376 EXPECT_EQ(old_contents, new_contents);
[email protected]ee496952013-01-10 23:17:33377 EXPECT_EQ(2, browser()->tab_strip_model()->count());
[email protected]a1feae52010-10-11 22:14:45378}
379
380// This test verifies that when a navigation requiring a new foreground tab
381// occurs in a Browser that cannot host multiple tabs, the new foreground tab
382// is created in an existing compatible Browser.
383IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
384 Disposition_IncompatibleWindow_Existing) {
385 // Open a foreground tab in a window that cannot open popups when there is an
386 // existing compatible window somewhere else that they can be opened within.
387 Browser* popup = CreateEmptyBrowserForType(Browser::TYPE_POPUP,
388 browser()->profile());
meacerc62e2ee2014-10-22 00:44:52389 chrome::NavigateParams params(MakeNavigateParams(popup));
390 params.disposition = NEW_FOREGROUND_TAB;
391 chrome::Navigate(&params);
[email protected]a1feae52010-10-11 22:14:45392
393 // Navigate() should have opened the tab in a different browser since the
394 // one we supplied didn't support additional tabs.
meacerc62e2ee2014-10-22 00:44:52395 EXPECT_NE(popup, params.browser);
[email protected]a1feae52010-10-11 22:14:45396
397 // Since browser() is an existing compatible tabbed browser, it should have
398 // opened the tab there.
meacerc62e2ee2014-10-22 00:44:52399 EXPECT_EQ(browser(), params.browser);
[email protected]a1feae52010-10-11 22:14:45400
401 // We should be left with 2 windows, the popup with one tab and the browser()
402 // provided by the framework with two.
[email protected]0665ebe2013-02-13 09:53:19403 EXPECT_EQ(2u, chrome::GetTotalBrowserCount());
[email protected]ee496952013-01-10 23:17:33404 EXPECT_EQ(1, popup->tab_strip_model()->count());
405 EXPECT_EQ(2, browser()->tab_strip_model()->count());
[email protected]a1feae52010-10-11 22:14:45406}
407
408// This test verifies that when a navigation requiring a new foreground tab
409// occurs in a Browser that cannot host multiple tabs and no compatible Browser
410// that can is open, a compatible Browser is created.
411IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
412 Disposition_IncompatibleWindow_NoExisting) {
413 // We want to simulate not being able to find an existing window compatible
414 // with our non-tabbed browser window so Navigate() is forced to create a
415 // new compatible window. Because browser() supplied by the in-process
416 // browser testing framework is compatible with browser()->profile(), we
417 // need a different profile, and creating a popup window with an incognito
418 // profile is a quick and dirty way of achieving this.
419 Browser* popup = CreateEmptyBrowserForType(
[email protected]b35b26b32011-05-05 20:35:14420 Browser::TYPE_POPUP,
421 browser()->profile()->GetOffTheRecordProfile());
meacerc62e2ee2014-10-22 00:44:52422 chrome::NavigateParams params(MakeNavigateParams(popup));
423 params.disposition = NEW_FOREGROUND_TAB;
424 chrome::Navigate(&params);
[email protected]a1feae52010-10-11 22:14:45425
426 // Navigate() should have opened the tab in a different browser since the
427 // one we supplied didn't support additional tabs.
meacerc62e2ee2014-10-22 00:44:52428 EXPECT_NE(popup, params.browser);
[email protected]a1feae52010-10-11 22:14:45429
430 // This time, browser() is _not_ compatible with popup since it is not an
431 // incognito window.
meacerc62e2ee2014-10-22 00:44:52432 EXPECT_NE(browser(), params.browser);
[email protected]a1feae52010-10-11 22:14:45433
434 // We should have three windows, each with one tab:
435 // 1. the browser() provided by the framework (unchanged in this test)
436 // 2. the incognito popup we created originally
437 // 3. the new incognito tabbed browser that was created by Navigate().
[email protected]0665ebe2013-02-13 09:53:19438 EXPECT_EQ(3u, chrome::GetTotalBrowserCount());
[email protected]ee496952013-01-10 23:17:33439 EXPECT_EQ(1, browser()->tab_strip_model()->count());
440 EXPECT_EQ(1, popup->tab_strip_model()->count());
meacerc62e2ee2014-10-22 00:44:52441 EXPECT_EQ(1, params.browser->tab_strip_model()->count());
442 EXPECT_TRUE(params.browser->is_type_tabbed());
[email protected]a1feae52010-10-11 22:14:45443}
444
445// This test verifies that navigating with WindowOpenDisposition = NEW_POPUP
446// from a normal Browser results in a new Browser with TYPE_POPUP.
447IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_NewPopup) {
meacerc62e2ee2014-10-22 00:44:52448 chrome::NavigateParams params(MakeNavigateParams());
449 params.disposition = NEW_POPUP;
450 params.window_bounds = gfx::Rect(0, 0, 200, 200);
[email protected]7d329992011-04-15 18:20:02451 // Wait for new popup to to load and gain focus.
meacerc62e2ee2014-10-22 00:44:52452 ui_test_utils::NavigateToURL(&params);
[email protected]a1feae52010-10-11 22:14:45453
[email protected]7d329992011-04-15 18:20:02454 // Navigate() should have opened a new, focused popup window.
meacerc62e2ee2014-10-22 00:44:52455 EXPECT_NE(browser(), params.browser);
[email protected]50592b52013-05-02 22:26:25456#if 0
457 // TODO(stevenjb): Enable this test. See: crbug.com/79493
meacerc62e2ee2014-10-22 00:44:52458 EXPECT_TRUE(browser->window()->IsActive());
[email protected]50592b52013-05-02 22:26:25459#endif
meacerc62e2ee2014-10-22 00:44:52460 EXPECT_TRUE(params.browser->is_type_popup());
461 EXPECT_FALSE(params.browser->is_app());
[email protected]a1feae52010-10-11 22:14:45462
463 // We should have two windows, the browser() provided by the framework and the
464 // new popup window.
[email protected]0665ebe2013-02-13 09:53:19465 EXPECT_EQ(2u, chrome::GetTotalBrowserCount());
[email protected]ee496952013-01-10 23:17:33466 EXPECT_EQ(1, browser()->tab_strip_model()->count());
meacerc62e2ee2014-10-22 00:44:52467 EXPECT_EQ(1, params.browser->tab_strip_model()->count());
[email protected]a1feae52010-10-11 22:14:45468}
469
470// This test verifies that navigating with WindowOpenDisposition = NEW_POPUP
[email protected]f112b0f2011-05-26 01:53:52471// from a normal Browser results in a new Browser with is_app() true.
472IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_NewPopup_ExtensionId) {
meacerc62e2ee2014-10-22 00:44:52473 chrome::NavigateParams params(MakeNavigateParams());
474 params.disposition = NEW_POPUP;
475 params.extension_app_id = "extensionappid";
476 params.window_bounds = gfx::Rect(0, 0, 200, 200);
[email protected]f112b0f2011-05-26 01:53:52477 // Wait for new popup to to load and gain focus.
meacerc62e2ee2014-10-22 00:44:52478 ui_test_utils::NavigateToURL(&params);
[email protected]f112b0f2011-05-26 01:53:52479
480 // Navigate() should have opened a new, focused popup window.
meacerc62e2ee2014-10-22 00:44:52481 EXPECT_NE(browser(), params.browser);
482 EXPECT_TRUE(params.browser->is_type_popup());
483 EXPECT_TRUE(params.browser->is_app());
[email protected]f112b0f2011-05-26 01:53:52484
485 // We should have two windows, the browser() provided by the framework and the
486 // new popup window.
[email protected]0665ebe2013-02-13 09:53:19487 EXPECT_EQ(2u, chrome::GetTotalBrowserCount());
[email protected]ee496952013-01-10 23:17:33488 EXPECT_EQ(1, browser()->tab_strip_model()->count());
meacerc62e2ee2014-10-22 00:44:52489 EXPECT_EQ(1, params.browser->tab_strip_model()->count());
[email protected]f112b0f2011-05-26 01:53:52490}
491
492// This test verifies that navigating with WindowOpenDisposition = NEW_POPUP
[email protected]300d1e52011-01-19 23:57:57493// from a normal popup results in a new Browser with TYPE_POPUP.
494IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_NewPopupFromPopup) {
495 // Open a popup.
meacerc62e2ee2014-10-22 00:44:52496 chrome::NavigateParams params1(MakeNavigateParams());
497 params1.disposition = NEW_POPUP;
498 params1.window_bounds = gfx::Rect(0, 0, 200, 200);
499 chrome::Navigate(&params1);
[email protected]300d1e52011-01-19 23:57:57500 // Open another popup.
meacerc62e2ee2014-10-22 00:44:52501 chrome::NavigateParams params2(MakeNavigateParams(params1.browser));
502 params2.disposition = NEW_POPUP;
503 params2.window_bounds = gfx::Rect(0, 0, 200, 200);
504 chrome::Navigate(&params2);
[email protected]300d1e52011-01-19 23:57:57505
506 // Navigate() should have opened a new normal popup window.
meacerc62e2ee2014-10-22 00:44:52507 EXPECT_NE(params1.browser, params2.browser);
508 EXPECT_TRUE(params2.browser->is_type_popup());
509 EXPECT_FALSE(params2.browser->is_app());
[email protected]300d1e52011-01-19 23:57:57510
511 // We should have three windows, the browser() provided by the framework,
512 // the first popup window, and the second popup window.
[email protected]0665ebe2013-02-13 09:53:19513 EXPECT_EQ(3u, chrome::GetTotalBrowserCount());
[email protected]ee496952013-01-10 23:17:33514 EXPECT_EQ(1, browser()->tab_strip_model()->count());
meacerc62e2ee2014-10-22 00:44:52515 EXPECT_EQ(1, params1.browser->tab_strip_model()->count());
516 EXPECT_EQ(1, params2.browser->tab_strip_model()->count());
[email protected]300d1e52011-01-19 23:57:57517}
518
519// This test verifies that navigating with WindowOpenDisposition = NEW_POPUP
[email protected]d2202e22014-04-14 20:20:53520// from an app frame results in a new Browser with TYPE_POPUP.
[email protected]a1feae52010-10-11 22:14:45521IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
522 Disposition_NewPopupFromAppWindow) {
[email protected]d2202e22014-04-14 20:20:53523 Browser* app_browser = CreateEmptyBrowserForApp(browser()->profile());
meacerc62e2ee2014-10-22 00:44:52524 chrome::NavigateParams params(MakeNavigateParams(app_browser));
525 params.disposition = NEW_POPUP;
526 params.window_bounds = gfx::Rect(0, 0, 200, 200);
527 chrome::Navigate(&params);
[email protected]a1feae52010-10-11 22:14:45528
529 // Navigate() should have opened a new popup app window.
meacerc62e2ee2014-10-22 00:44:52530 EXPECT_NE(app_browser, params.browser);
531 EXPECT_NE(browser(), params.browser);
532 EXPECT_TRUE(params.browser->is_type_popup());
533 EXPECT_TRUE(params.browser->is_app());
[email protected]a1feae52010-10-11 22:14:45534
535 // We should now have three windows, the app window, the app popup it created,
536 // and the original browser() provided by the framework.
[email protected]0665ebe2013-02-13 09:53:19537 EXPECT_EQ(3u, chrome::GetTotalBrowserCount());
[email protected]ee496952013-01-10 23:17:33538 EXPECT_EQ(1, browser()->tab_strip_model()->count());
539 EXPECT_EQ(1, app_browser->tab_strip_model()->count());
meacerc62e2ee2014-10-22 00:44:52540 EXPECT_EQ(1, params.browser->tab_strip_model()->count());
[email protected]a1feae52010-10-11 22:14:45541}
542
543// This test verifies that navigating with WindowOpenDisposition = NEW_POPUP
[email protected]d2202e22014-04-14 20:20:53544// from an app popup results in a new Browser also of TYPE_POPUP.
[email protected]300d1e52011-01-19 23:57:57545IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
546 Disposition_NewPopupFromAppPopup) {
[email protected]d2202e22014-04-14 20:20:53547 Browser* app_browser = CreateEmptyBrowserForApp(browser()->profile());
[email protected]300d1e52011-01-19 23:57:57548 // Open an app popup.
meacerc62e2ee2014-10-22 00:44:52549 chrome::NavigateParams params1(MakeNavigateParams(app_browser));
550 params1.disposition = NEW_POPUP;
551 params1.window_bounds = gfx::Rect(0, 0, 200, 200);
552 chrome::Navigate(&params1);
[email protected]300d1e52011-01-19 23:57:57553 // Now open another app popup.
meacerc62e2ee2014-10-22 00:44:52554 chrome::NavigateParams params2(MakeNavigateParams(params1.browser));
555 params2.disposition = NEW_POPUP;
556 params2.window_bounds = gfx::Rect(0, 0, 200, 200);
557 chrome::Navigate(&params2);
[email protected]300d1e52011-01-19 23:57:57558
559 // Navigate() should have opened a new popup app window.
meacerc62e2ee2014-10-22 00:44:52560 EXPECT_NE(browser(), params1.browser);
561 EXPECT_NE(params1.browser, params2.browser);
562 EXPECT_TRUE(params2.browser->is_type_popup());
563 EXPECT_TRUE(params2.browser->is_app());
[email protected]300d1e52011-01-19 23:57:57564
565 // We should now have four windows, the app window, the first app popup,
566 // the second app popup, and the original browser() provided by the framework.
[email protected]0665ebe2013-02-13 09:53:19567 EXPECT_EQ(4u, chrome::GetTotalBrowserCount());
[email protected]ee496952013-01-10 23:17:33568 EXPECT_EQ(1, browser()->tab_strip_model()->count());
569 EXPECT_EQ(1, app_browser->tab_strip_model()->count());
meacerc62e2ee2014-10-22 00:44:52570 EXPECT_EQ(1, params1.browser->tab_strip_model()->count());
571 EXPECT_EQ(1, params2.browser->tab_strip_model()->count());
[email protected]300d1e52011-01-19 23:57:57572}
573
574// This test verifies that navigating with WindowOpenDisposition = NEW_POPUP
[email protected]a1feae52010-10-11 22:14:45575// from an extension app tab results in a new Browser with TYPE_APP_POPUP.
576IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
577 Disposition_NewPopupFromExtensionApp) {
578 // TODO(beng): TBD.
579}
580
[email protected]7d329992011-04-15 18:20:02581// This test verifies that navigating with window_action = SHOW_WINDOW_INACTIVE
582// does not focus a new new popup window.
583IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_NewPopupUnfocused) {
meacerc62e2ee2014-10-22 00:44:52584 chrome::NavigateParams params(MakeNavigateParams());
585 params.disposition = NEW_POPUP;
586 params.window_bounds = gfx::Rect(0, 0, 200, 200);
587 params.window_action = chrome::NavigateParams::SHOW_WINDOW_INACTIVE;
[email protected]7d329992011-04-15 18:20:02588 // Wait for new popup to load (and gain focus if the test fails).
meacerc62e2ee2014-10-22 00:44:52589 ui_test_utils::NavigateToURL(&params);
[email protected]7d329992011-04-15 18:20:02590
591 // Navigate() should have opened a new, unfocused, popup window.
meacerc62e2ee2014-10-22 00:44:52592 EXPECT_NE(browser(), params.browser);
593 EXPECT_EQ(Browser::TYPE_POPUP, params.browser->type());
[email protected]9db263a2011-04-15 20:53:47594#if 0
595// TODO(stevenjb): Enable this test. See: crbug.com/79493
[email protected]7d329992011-04-15 18:20:02596 EXPECT_FALSE(p.browser->window()->IsActive());
[email protected]7d329992011-04-15 18:20:02597#endif
[email protected]9db263a2011-04-15 20:53:47598}
[email protected]7d329992011-04-15 18:20:02599
[email protected]d2202e22014-04-14 20:20:53600// This test verifies that navigating with WindowOpenDisposition = NEW_POPUP
601// and trusted_source = true results in a new Browser where is_trusted_source()
602// is true.
603IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_NewPopupTrusted) {
meacerc62e2ee2014-10-22 00:44:52604 chrome::NavigateParams params(MakeNavigateParams());
605 params.disposition = NEW_POPUP;
606 params.trusted_source = true;
607 params.window_bounds = gfx::Rect(0, 0, 200, 200);
[email protected]d2202e22014-04-14 20:20:53608 // Wait for new popup to to load and gain focus.
meacerc62e2ee2014-10-22 00:44:52609 ui_test_utils::NavigateToURL(&params);
[email protected]d2202e22014-04-14 20:20:53610
611 // Navigate() should have opened a new popup window of TYPE_TRUSTED_POPUP.
meacerc62e2ee2014-10-22 00:44:52612 EXPECT_NE(browser(), params.browser);
613 EXPECT_TRUE(params.browser->is_type_popup());
614 EXPECT_TRUE(params.browser->is_trusted_source());
[email protected]d2202e22014-04-14 20:20:53615}
616
617
[email protected]a1feae52010-10-11 22:14:45618// This test verifies that navigating with WindowOpenDisposition = NEW_WINDOW
619// always opens a new window.
620IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_NewWindow) {
meacerc62e2ee2014-10-22 00:44:52621 chrome::NavigateParams params(MakeNavigateParams());
622 params.disposition = NEW_WINDOW;
623 chrome::Navigate(&params);
[email protected]a1feae52010-10-11 22:14:45624
625 // Navigate() should have opened a new toplevel window.
meacerc62e2ee2014-10-22 00:44:52626 EXPECT_NE(browser(), params.browser);
627 EXPECT_TRUE(params.browser->is_type_tabbed());
[email protected]a1feae52010-10-11 22:14:45628
629 // We should now have two windows, the browser() provided by the framework and
630 // the new normal window.
[email protected]0665ebe2013-02-13 09:53:19631 EXPECT_EQ(2u, chrome::GetTotalBrowserCount());
[email protected]ee496952013-01-10 23:17:33632 EXPECT_EQ(1, browser()->tab_strip_model()->count());
meacerc62e2ee2014-10-22 00:44:52633 EXPECT_EQ(1, params.browser->tab_strip_model()->count());
[email protected]a1feae52010-10-11 22:14:45634}
635
636// This test verifies that navigating with WindowOpenDisposition = INCOGNITO
637// opens a new incognito window if no existing incognito window is present.
638IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_Incognito) {
meacerc62e2ee2014-10-22 00:44:52639 chrome::NavigateParams params(MakeNavigateParams());
640 params.disposition = OFF_THE_RECORD;
641 chrome::Navigate(&params);
[email protected]a1feae52010-10-11 22:14:45642
643 // Navigate() should have opened a new toplevel incognito window.
meacerc62e2ee2014-10-22 00:44:52644 EXPECT_NE(browser(), params.browser);
[email protected]a1feae52010-10-11 22:14:45645 EXPECT_EQ(browser()->profile()->GetOffTheRecordProfile(),
meacerc62e2ee2014-10-22 00:44:52646 params.browser->profile());
[email protected]a1feae52010-10-11 22:14:45647
[email protected]d7ff3592010-11-30 21:50:46648 // |source_contents| should be set to NULL because the profile for the new
649 // page is different from the originating page.
meacerc62e2ee2014-10-22 00:44:52650 EXPECT_EQ(NULL, params.source_contents);
[email protected]d7ff3592010-11-30 21:50:46651
[email protected]a1feae52010-10-11 22:14:45652 // We should now have two windows, the browser() provided by the framework and
653 // the new incognito window.
[email protected]0665ebe2013-02-13 09:53:19654 EXPECT_EQ(2u, chrome::GetTotalBrowserCount());
[email protected]ee496952013-01-10 23:17:33655 EXPECT_EQ(1, browser()->tab_strip_model()->count());
meacerc62e2ee2014-10-22 00:44:52656 EXPECT_EQ(1, params.browser->tab_strip_model()->count());
[email protected]a1feae52010-10-11 22:14:45657}
658
659// This test verifies that navigating with WindowOpenDisposition = INCOGNITO
660// reuses an existing incognito window when possible.
661IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_IncognitoRefocus) {
662 Browser* incognito_browser =
[email protected]b35b26b32011-05-05 20:35:14663 CreateEmptyBrowserForType(Browser::TYPE_TABBED,
[email protected]a1feae52010-10-11 22:14:45664 browser()->profile()->GetOffTheRecordProfile());
meacerc62e2ee2014-10-22 00:44:52665 chrome::NavigateParams params(MakeNavigateParams());
666 params.disposition = OFF_THE_RECORD;
667 chrome::Navigate(&params);
[email protected]a1feae52010-10-11 22:14:45668
669 // Navigate() should have opened a new tab in the existing incognito window.
meacerc62e2ee2014-10-22 00:44:52670 EXPECT_NE(browser(), params.browser);
671 EXPECT_EQ(params.browser, incognito_browser);
[email protected]a1feae52010-10-11 22:14:45672
673 // We should now have two windows, the browser() provided by the framework and
674 // the incognito window we opened earlier.
[email protected]0665ebe2013-02-13 09:53:19675 EXPECT_EQ(2u, chrome::GetTotalBrowserCount());
[email protected]ee496952013-01-10 23:17:33676 EXPECT_EQ(1, browser()->tab_strip_model()->count());
677 EXPECT_EQ(2, incognito_browser->tab_strip_model()->count());
[email protected]a1feae52010-10-11 22:14:45678}
679
680// This test verifies that no navigation action occurs when
681// WindowOpenDisposition = SUPPRESS_OPEN.
682IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_SuppressOpen) {
683 RunSuppressTest(SUPPRESS_OPEN);
684}
685
686// This test verifies that no navigation action occurs when
687// WindowOpenDisposition = SAVE_TO_DISK.
688IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_SaveToDisk) {
689 RunSuppressTest(SAVE_TO_DISK);
690}
691
692// This test verifies that no navigation action occurs when
693// WindowOpenDisposition = IGNORE_ACTION.
694IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_IgnoreAction) {
695 RunSuppressTest(IGNORE_ACTION);
696}
697
[email protected]e232c992012-12-06 12:43:20698// This tests adding a foreground tab with a predefined WebContents.
[email protected]a1feae52010-10-11 22:14:45699IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, TargetContents_ForegroundTab) {
meacerc62e2ee2014-10-22 00:44:52700 chrome::NavigateParams params(MakeNavigateParams());
701 params.disposition = NEW_FOREGROUND_TAB;
lof84501da082016-05-23 21:22:54702 params.target_contents = CreateWebContents(false);
meacerc62e2ee2014-10-22 00:44:52703 chrome::Navigate(&params);
[email protected]a1feae52010-10-11 22:14:45704
lof84501da082016-05-23 21:22:54705 // Navigate() should have opened the contents in a new foreground tab in the
[email protected]a1feae52010-10-11 22:14:45706 // current Browser.
meacerc62e2ee2014-10-22 00:44:52707 EXPECT_EQ(browser(), params.browser);
[email protected]e232c992012-12-06 12:43:20708 EXPECT_EQ(browser()->tab_strip_model()->GetActiveWebContents(),
meacerc62e2ee2014-10-22 00:44:52709 params.target_contents);
[email protected]a1feae52010-10-11 22:14:45710
711 // We should have one window, with two tabs.
[email protected]0665ebe2013-02-13 09:53:19712 EXPECT_EQ(1u, chrome::GetTotalBrowserCount());
[email protected]ee496952013-01-10 23:17:33713 EXPECT_EQ(2, browser()->tab_strip_model()->count());
[email protected]a1feae52010-10-11 22:14:45714}
715
716#if defined(OS_WIN)
[email protected]e232c992012-12-06 12:43:20717// This tests adding a popup with a predefined WebContents.
[email protected]76edb672011-03-04 21:48:39718IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, DISABLED_TargetContents_Popup) {
meacerc62e2ee2014-10-22 00:44:52719 chrome::NavigateParams params(MakeNavigateParams());
720 params.disposition = NEW_POPUP;
lof84501da082016-05-23 21:22:54721 params.target_contents = CreateWebContents(false);
meacerc62e2ee2014-10-22 00:44:52722 params.window_bounds = gfx::Rect(10, 10, 500, 500);
723 chrome::Navigate(&params);
[email protected]a1feae52010-10-11 22:14:45724
725 // Navigate() should have opened a new popup window.
meacerc62e2ee2014-10-22 00:44:52726 EXPECT_NE(browser(), params.browser);
727 EXPECT_TRUE(params.browser->is_type_popup());
728 EXPECT_FALSE(params.browser->is_app());
[email protected]a1feae52010-10-11 22:14:45729
730 // The web platform is weird. The window bounds specified in
meacerc62e2ee2014-10-22 00:44:52731 // |params.window_bounds| are used as follows:
[email protected]a1feae52010-10-11 22:14:45732 // - the origin is used to position the window
[email protected]e232c992012-12-06 12:43:20733 // - the size is used to size the WebContents of the window.
[email protected]a1feae52010-10-11 22:14:45734 // As such the position of the resulting window will always match
meacerc62e2ee2014-10-22 00:44:52735 // params.window_bounds.origin(), but its size will not. We need to match
[email protected]a1feae52010-10-11 22:14:45736 // the size against the selected tab's view's container size.
meacerc62e2ee2014-10-22 00:44:52737 // Only Windows positions the window according to
738 // |params.window_bounds.origin()| - on Mac the window is offset from the
739 // opener and on Linux it always opens at 0,0.
740 EXPECT_EQ(params.window_bounds.origin(),
741 params.browser->window()->GetRestoredBounds().origin());
[email protected]a1feae52010-10-11 22:14:45742 // All platforms should respect size however provided width > 400 (Mac has a
743 // minimum window width of 400).
meacerc62e2ee2014-10-22 00:44:52744 EXPECT_EQ(params.window_bounds.size(),
745 params.target_contents->GetContainerBounds().size());
[email protected]a1feae52010-10-11 22:14:45746
747 // We should have two windows, the new popup and the browser() provided by the
748 // framework.
[email protected]0665ebe2013-02-13 09:53:19749 EXPECT_EQ(2u, chrome::GetTotalBrowserCount());
[email protected]ee496952013-01-10 23:17:33750 EXPECT_EQ(1, browser()->tab_strip_model()->count());
meacerc62e2ee2014-10-22 00:44:52751 EXPECT_EQ(1, params.browser->tab_strip_model()->count());
[email protected]a1feae52010-10-11 22:14:45752}
753#endif
754
lof84501da082016-05-23 21:22:54755// This test checks that we can create WebContents with renderer process and
756// RenderFrame without navigating it.
757IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
758 CreateWebContentsWithRendererProcess) {
759 chrome::NavigateParams params(MakeNavigateParams());
760 params.disposition = NEW_FOREGROUND_TAB;
761 params.target_contents = CreateWebContents(true);
762 ASSERT_TRUE(params.target_contents);
763
764 // There is no navigation (to about:blank or something like that).
765 EXPECT_FALSE(params.target_contents->IsLoading());
766
767 ASSERT_TRUE(params.target_contents->GetMainFrame());
768 EXPECT_TRUE(params.target_contents->GetMainFrame()->IsRenderFrameLive());
769 EXPECT_TRUE(
770 params.target_contents->GetController().IsInitialBlankNavigation());
771 int renderer_id = params.target_contents->GetRenderProcessHost()->GetID();
772
773 // We should have one window, with one tab of WebContents differ from
774 // params.target_contents.
775 EXPECT_EQ(1u, chrome::GetTotalBrowserCount());
776 EXPECT_EQ(1, browser()->tab_strip_model()->count());
777 EXPECT_NE(browser()->tab_strip_model()->GetActiveWebContents(),
778 params.target_contents);
779
780 chrome::Navigate(&params);
781
782 // Navigate() should have opened the contents in a new foreground tab in the
783 // current Browser, without changing the renderer process of target_contents.
784 EXPECT_EQ(browser(), params.browser);
785 EXPECT_EQ(browser()->tab_strip_model()->GetActiveWebContents(),
786 params.target_contents);
787 EXPECT_EQ(renderer_id,
788 params.target_contents->GetRenderProcessHost()->GetID());
789
790 // We should have one window, with two tabs.
791 EXPECT_EQ(1u, chrome::GetTotalBrowserCount());
792 EXPECT_EQ(2, browser()->tab_strip_model()->count());
793}
794
[email protected]a1feae52010-10-11 22:14:45795// This tests adding a tab at a specific index.
796IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Tabstrip_InsertAtIndex) {
797 // This is not meant to be a comprehensive test of whether or not the tab
798 // implementation of the browser observes the insertion index. That is
799 // covered by the unit tests for TabStripModel. This merely verifies that
800 // insertion index preference is reflected in common cases.
meacerc62e2ee2014-10-22 00:44:52801 chrome::NavigateParams params(MakeNavigateParams());
802 params.disposition = NEW_FOREGROUND_TAB;
803 params.tabstrip_index = 0;
804 params.tabstrip_add_types = TabStripModel::ADD_FORCE_INDEX;
805 chrome::Navigate(&params);
[email protected]a1feae52010-10-11 22:14:45806
807 // Navigate() should have inserted a new tab at slot 0 in the tabstrip.
meacerc62e2ee2014-10-22 00:44:52808 EXPECT_EQ(browser(), params.browser);
[email protected]e232c992012-12-06 12:43:20809 EXPECT_EQ(0, browser()->tab_strip_model()->GetIndexOfWebContents(
meacerc62e2ee2014-10-22 00:44:52810 static_cast<const WebContents*>(params.target_contents)));
[email protected]a1feae52010-10-11 22:14:45811
812 // We should have one window - the browser() provided by the framework.
[email protected]0665ebe2013-02-13 09:53:19813 EXPECT_EQ(1u, chrome::GetTotalBrowserCount());
[email protected]ee496952013-01-10 23:17:33814 EXPECT_EQ(2, browser()->tab_strip_model()->count());
[email protected]a1feae52010-10-11 22:14:45815}
816
[email protected]bb89e7482010-11-17 18:27:04817// This test verifies that constructing params with disposition = SINGLETON_TAB
[email protected]fee320542011-03-02 01:30:49818// and IGNORE_AND_NAVIGATE opens a new tab navigated to the specified URL if
[email protected]67ed83e2011-01-07 22:54:00819// no previous tab with that URL (minus the path) exists.
[email protected]bb89e7482010-11-17 18:27:04820IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
821 Disposition_SingletonTabNew_IgnorePath) {
[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 2 tabs, the 2nd selected.
[email protected]0665ebe2013-02-13 09:53:19826 EXPECT_EQ(1u, chrome::GetTotalBrowserCount());
[email protected]ee496952013-01-10 23:17:33827 EXPECT_EQ(2, browser()->tab_strip_model()->count());
828 EXPECT_EQ(1, browser()->tab_strip_model()->active_index());
[email protected]bb89e7482010-11-17 18:27:04829
830 // Navigate to a new singleton tab with a sub-page.
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 last tab should now be selected and navigated to the sub-page of the
[email protected]50592b52013-05-02 22:26:25839 // 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(2, 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_SingletonTabExisting_IgnorePath) {
[email protected]ddddfda2011-07-14 23:19:39853 GURL singleton_url1(GetSettingsURL());
[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 = GetContentSettingsURL();
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(GetContentSettingsURL(),
[email protected]ee496952013-01-10 23:17:33878 ShortenUberURL(browser()->tab_strip_model()->
879 GetActiveWebContents()->GetURL()));
[email protected]bb89e7482010-11-17 18:27:04880}
881
882// This test verifies that constructing params with disposition = SINGLETON_TAB
[email protected]fee320542011-03-02 01:30:49883// and IGNORE_AND_NAVIGATE opens an existing tab with the matching URL (minus
[email protected]bb89e7482010-11-17 18:27:04884// the path) which is navigated to the specified URL.
885IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
886 Disposition_SingletonTabExistingSubPath_IgnorePath) {
[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]bb89e7482010-11-17 18:27:04892
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]bb89e7482010-11-17 18:27:04897
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_NAVIGATE;
904 chrome::Navigate(&params);
[email protected]bb89e7482010-11-17 18:27:04905
906 // The middle tab should now be selected and navigated to the sub-page of the
907 // URL.
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]a048ad22012-03-23 04:26:56911 EXPECT_EQ(GetClearBrowsingDataURL(),
[email protected]ee496952013-01-10 23:17:33912 ShortenUberURL(browser()->tab_strip_model()->
913 GetActiveWebContents()->GetURL()));
[email protected]bb89e7482010-11-17 18:27:04914}
[email protected]2dd85482010-11-06 01:56:47915
[email protected]637b3442011-01-10 23:31:48916// This test verifies that constructing params with disposition = SINGLETON_TAB
[email protected]fee320542011-03-02 01:30:49917// and IGNORE_AND_STAY_PUT opens an existing tab with the matching URL (minus
918// the path).
919IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
920 Disposition_SingletonTabExistingSubPath_IgnorePath2) {
[email protected]a048ad22012-03-23 04:26:56921 GURL singleton_url1(GetContentSettingsURL());
[email protected]52877dbc62012-06-29 22:22:03922 chrome::AddSelectedTabWithURL(browser(), singleton_url1,
Sylvain Defresnec6ccc77d2014-09-19 10:19:35923 ui::PAGE_TRANSITION_LINK);
[email protected]52877dbc62012-06-29 22:22:03924 chrome::AddSelectedTabWithURL(browser(), GetGoogleURL(),
Sylvain Defresnec6ccc77d2014-09-19 10:19:35925 ui::PAGE_TRANSITION_LINK);
[email protected]fee320542011-03-02 01:30:49926
927 // We should have one browser with 3 tabs, the 3rd selected.
[email protected]0665ebe2013-02-13 09:53:19928 EXPECT_EQ(1u, chrome::GetTotalBrowserCount());
[email protected]ee496952013-01-10 23:17:33929 EXPECT_EQ(3, browser()->tab_strip_model()->count());
930 EXPECT_EQ(2, browser()->tab_strip_model()->active_index());
[email protected]fee320542011-03-02 01:30:49931
932 // Navigate to singleton_url1.
meacerc62e2ee2014-10-22 00:44:52933 chrome::NavigateParams params(MakeNavigateParams());
934 params.disposition = SINGLETON_TAB;
935 params.url = GetClearBrowsingDataURL();
936 params.window_action = chrome::NavigateParams::SHOW_WINDOW;
937 params.path_behavior = chrome::NavigateParams::IGNORE_AND_STAY_PUT;
938 chrome::Navigate(&params);
[email protected]fee320542011-03-02 01:30:49939
940 // The middle tab should now be selected.
meacerc62e2ee2014-10-22 00:44:52941 EXPECT_EQ(browser(), params.browser);
[email protected]ee496952013-01-10 23:17:33942 EXPECT_EQ(3, browser()->tab_strip_model()->count());
943 EXPECT_EQ(1, browser()->tab_strip_model()->active_index());
[email protected]fee320542011-03-02 01:30:49944 EXPECT_EQ(singleton_url1,
[email protected]ee496952013-01-10 23:17:33945 ShortenUberURL(browser()->tab_strip_model()->
946 GetActiveWebContents()->GetURL()));
[email protected]fee320542011-03-02 01:30:49947}
948
949// This test verifies that constructing params with disposition = SINGLETON_TAB
950// and IGNORE_AND_NAVIGATE will update the current tab's URL if the currently
[email protected]637b3442011-01-10 23:31:48951// selected tab is a match but has a different path.
952IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
953 Disposition_SingletonTabFocused_IgnorePath) {
[email protected]a048ad22012-03-23 04:26:56954 GURL singleton_url_current(GetContentSettingsURL());
[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]637b3442011-01-10 23:31:48957
958 // We should have one browser with 2 tabs, the 2nd selected.
[email protected]0665ebe2013-02-13 09:53:19959 EXPECT_EQ(1u, chrome::GetTotalBrowserCount());
[email protected]ee496952013-01-10 23:17:33960 EXPECT_EQ(2, browser()->tab_strip_model()->count());
961 EXPECT_EQ(1, browser()->tab_strip_model()->active_index());
[email protected]637b3442011-01-10 23:31:48962
963 // Navigate to a different settings path.
[email protected]a048ad22012-03-23 04:26:56964 GURL singleton_url_target(GetClearBrowsingDataURL());
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]637b3442011-01-10 23:31:48971
972 // The second tab should still be selected, but navigated to the new path.
meacerc62e2ee2014-10-22 00:44:52973 EXPECT_EQ(browser(), params.browser);
[email protected]ee496952013-01-10 23:17:33974 EXPECT_EQ(2, browser()->tab_strip_model()->count());
975 EXPECT_EQ(1, browser()->tab_strip_model()->active_index());
[email protected]637b3442011-01-10 23:31:48976 EXPECT_EQ(singleton_url_target,
[email protected]ee496952013-01-10 23:17:33977 ShortenUberURL(browser()->tab_strip_model()->
978 GetActiveWebContents()->GetURL()));
[email protected]637b3442011-01-10 23:31:48979}
980
[email protected]07afd7c2011-02-17 10:07:11981// This test verifies that constructing params with disposition = SINGLETON_TAB
[email protected]fee320542011-03-02 01:30:49982// and IGNORE_AND_NAVIGATE will open an existing matching tab with a different
983// query.
[email protected]07afd7c2011-02-17 10:07:11984IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
985 Disposition_SingletonTabExisting_IgnoreQuery) {
[email protected]ee496952013-01-10 23:17:33986 int initial_tab_count = browser()->tab_strip_model()->count();
[email protected]07afd7c2011-02-17 10:07:11987 GURL singleton_url_current("chrome://settings/internet");
[email protected]52877dbc62012-06-29 22:22:03988 chrome::AddSelectedTabWithURL(browser(), singleton_url_current,
Sylvain Defresnec6ccc77d2014-09-19 10:19:35989 ui::PAGE_TRANSITION_LINK);
[email protected]07afd7c2011-02-17 10:07:11990
[email protected]ee496952013-01-10 23:17:33991 EXPECT_EQ(initial_tab_count + 1, browser()->tab_strip_model()->count());
992 EXPECT_EQ(initial_tab_count, browser()->tab_strip_model()->active_index());
[email protected]07afd7c2011-02-17 10:07:11993
994 // Navigate to a different settings path.
995 GURL singleton_url_target(
996 "chrome://settings/internet?"
stevenjb82dbc53092015-03-14 18:32:24997 "guid=ethernet_00aa00aa00aa&networkType=1");
meacerc62e2ee2014-10-22 00:44:52998 chrome::NavigateParams params(MakeNavigateParams());
999 params.disposition = SINGLETON_TAB;
1000 params.url = singleton_url_target;
1001 params.window_action = chrome::NavigateParams::SHOW_WINDOW;
1002 params.path_behavior = chrome::NavigateParams::IGNORE_AND_NAVIGATE;
1003 chrome::Navigate(&params);
[email protected]07afd7c2011-02-17 10:07:111004
1005 // Last tab should still be selected.
meacerc62e2ee2014-10-22 00:44:521006 EXPECT_EQ(browser(), params.browser);
[email protected]ee496952013-01-10 23:17:331007 EXPECT_EQ(initial_tab_count + 1, browser()->tab_strip_model()->count());
1008 EXPECT_EQ(initial_tab_count, browser()->tab_strip_model()->active_index());
[email protected]07afd7c2011-02-17 10:07:111009}
1010
[email protected]bd817c22011-02-09 08:16:461011// This test verifies that the settings page isn't opened in the incognito
1012// window.
[email protected]a048ad22012-03-23 04:26:561013// Disabled until fixed for uber settings: http://crbug.com/111243
[email protected]bd817c22011-02-09 08:16:461014IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
[email protected]a048ad22012-03-23 04:26:561015 DISABLED_Disposition_Settings_UseNonIncognitoWindow) {
[email protected]fc0ed302011-11-29 23:17:191016 RunUseNonIncognitoWindowTest(GetSettingsURL());
[email protected]bd817c22011-02-09 08:16:461017}
1018
[email protected]429e9712013-04-30 09:35:501019// This test verifies that the view-source settings page isn't opened in the
1020// incognito window.
1021IN_PROC_BROWSER_TEST_F(
1022 BrowserNavigatorTest,
1023 Disposition_ViewSource_Settings_DoNothingIfIncognitoForced) {
[email protected]dbdda5402013-05-30 22:13:481024 std::string view_source(content::kViewSourceScheme);
[email protected]429e9712013-04-30 09:35:501025 view_source.append(":");
1026 view_source.append(chrome::kChromeUISettingsURL);
1027 RunDoNothingIfIncognitoIsForcedTest(GURL(view_source));
1028}
1029
1030// This test verifies that the view-source settings page isn't opened in the
1031// incognito window even if incognito mode is forced (does nothing in that
1032// case).
1033IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
1034 Disposition_ViewSource_Settings_UseNonIncognitoWindow) {
[email protected]dbdda5402013-05-30 22:13:481035 std::string view_source(content::kViewSourceScheme);
[email protected]429e9712013-04-30 09:35:501036 view_source.append(":");
1037 view_source.append(chrome::kChromeUISettingsURL);
1038 RunUseNonIncognitoWindowTest(GURL(view_source));
1039}
1040
[email protected]82404cd2011-07-12 19:55:141041// This test verifies that the settings page isn't opened in the incognito
1042// window from a non-incognito window (bookmark open-in-incognito trigger).
[email protected]a048ad22012-03-23 04:26:561043// Disabled until fixed for uber settings: http://crbug.com/111243
[email protected]82404cd2011-07-12 19:55:141044IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
[email protected]a048ad22012-03-23 04:26:561045 DISABLED_Disposition_Settings_UseNonIncognitoWindowForBookmark) {
[email protected]78e2edc2012-07-01 23:32:281046 chrome::NavigateParams params(browser(), GetSettingsURL(),
Sylvain Defresnec6ccc77d2014-09-19 10:19:351047 ui::PAGE_TRANSITION_AUTO_BOOKMARK);
[email protected]82404cd2011-07-12 19:55:141048 params.disposition = OFF_THE_RECORD;
1049 {
[email protected]a7fe9112012-07-20 02:34:451050 content::WindowedNotificationObserver observer(
[email protected]ad50def52011-10-19 23:17:071051 content::NOTIFICATION_LOAD_STOP,
1052 content::NotificationService::AllSources());
[email protected]78e2edc2012-07-01 23:32:281053 chrome::Navigate(&params);
[email protected]82404cd2011-07-12 19:55:141054 observer.Wait();
1055 }
1056
[email protected]0665ebe2013-02-13 09:53:191057 EXPECT_EQ(1u, chrome::GetTotalBrowserCount());
[email protected]52877dbc62012-06-29 22:22:031058 EXPECT_EQ(GetSettingsURL(),
[email protected]ee496952013-01-10 23:17:331059 ShortenUberURL(browser()->tab_strip_model()->
1060 GetActiveWebContents()->GetURL()));
[email protected]82404cd2011-07-12 19:55:141061}
1062
[email protected]93ad8e1c2011-11-08 21:34:051063// Settings page is expected to always open in normal mode regardless
1064// of whether the user is trying to open it in incognito mode or not.
1065// This test verifies that if incognito mode is forced (by policy), settings
1066// page doesn't open at all.
[email protected]a048ad22012-03-23 04:26:561067// Disabled until fixed for uber settings: http://crbug.com/111243
[email protected]93ad8e1c2011-11-08 21:34:051068IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
[email protected]a048ad22012-03-23 04:26:561069 DISABLED_Disposition_Settings_DoNothingIfIncognitoIsForced) {
[email protected]fc0ed302011-11-29 23:17:191070 RunDoNothingIfIncognitoIsForcedTest(GetSettingsURL());
[email protected]93ad8e1c2011-11-08 21:34:051071}
1072
[email protected]bd817c22011-02-09 08:16:461073// This test verifies that the bookmarks page isn't opened in the incognito
1074// window.
1075IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
1076 Disposition_Bookmarks_UseNonIncognitoWindow) {
[email protected]fc0ed302011-11-29 23:17:191077 RunUseNonIncognitoWindowTest(GURL(chrome::kChromeUIBookmarksURL));
[email protected]bd817c22011-02-09 08:16:461078}
1079
[email protected]93ad8e1c2011-11-08 21:34:051080// Bookmark manager is expected to always open in normal mode regardless
1081// of whether the user is trying to open it in incognito mode or not.
1082// This test verifies that if incognito mode is forced (by policy), bookmark
1083// manager doesn't open at all.
1084IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
1085 Disposition_Bookmarks_DoNothingIfIncognitoIsForced) {
[email protected]fc0ed302011-11-29 23:17:191086 RunDoNothingIfIncognitoIsForcedTest(GURL(chrome::kChromeUIBookmarksURL));
1087}
[email protected]93ad8e1c2011-11-08 21:34:051088
[email protected]7de53c62011-05-13 06:44:161089// This test makes sure a crashed singleton tab reloads from a new navigation.
[email protected]c4c0c0a12014-07-23 17:06:021090// http://crbug.com/396371
[email protected]7de53c62011-05-13 06:44:161091IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
[email protected]c4c0c0a12014-07-23 17:06:021092 DISABLED_NavigateToCrashedSingletonTab) {
[email protected]a048ad22012-03-23 04:26:561093 GURL singleton_url(GetContentSettingsURL());
[email protected]5a1a52462012-11-15 03:35:161094 WebContents* web_contents = chrome::AddSelectedTabWithURL(
Sylvain Defresnec6ccc77d2014-09-19 10:19:351095 browser(), singleton_url, ui::PAGE_TRANSITION_LINK);
[email protected]7de53c62011-05-13 06:44:161096
1097 // We should have one browser with 2 tabs, the 2nd selected.
[email protected]0665ebe2013-02-13 09:53:191098 EXPECT_EQ(1u, chrome::GetTotalBrowserCount());
[email protected]ee496952013-01-10 23:17:331099 EXPECT_EQ(2, browser()->tab_strip_model()->count());
1100 EXPECT_EQ(1, browser()->tab_strip_model()->active_index());
[email protected]7de53c62011-05-13 06:44:161101
1102 // Kill the singleton tab.
[email protected]83ff91c2012-01-05 20:54:131103 web_contents->SetIsCrashed(base::TERMINATION_STATUS_PROCESS_CRASHED, -1);
1104 EXPECT_TRUE(web_contents->IsCrashed());
[email protected]7de53c62011-05-13 06:44:161105
meacerc62e2ee2014-10-22 00:44:521106 chrome::NavigateParams params(MakeNavigateParams());
1107 params.disposition = SINGLETON_TAB;
1108 params.url = singleton_url;
1109 params.window_action = chrome::NavigateParams::SHOW_WINDOW;
1110 params.path_behavior = chrome::NavigateParams::IGNORE_AND_NAVIGATE;
1111 ui_test_utils::NavigateToURL(&params);
[email protected]7de53c62011-05-13 06:44:161112
1113 // The tab should not be sad anymore.
[email protected]83ff91c2012-01-05 20:54:131114 EXPECT_FALSE(web_contents->IsCrashed());
[email protected]7de53c62011-05-13 06:44:161115}
1116
[email protected]fcca741b2011-06-17 22:46:371117IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
1118 NavigateFromDefaultToOptionsInSameTab) {
[email protected]ddddfda2011-07-14 23:19:391119 {
[email protected]a7fe9112012-07-20 02:34:451120 content::WindowedNotificationObserver observer(
[email protected]ad50def52011-10-19 23:17:071121 content::NOTIFICATION_LOAD_STOP,
1122 content::NotificationService::AllSources());
[email protected]5d9cace72012-06-21 16:07:121123 chrome::ShowSettings(browser());
[email protected]ddddfda2011-07-14 23:19:391124 observer.Wait();
1125 }
[email protected]ee496952013-01-10 23:17:331126 EXPECT_EQ(1, browser()->tab_strip_model()->count());
[email protected]52877dbc62012-06-29 22:22:031127 EXPECT_EQ(GetSettingsURL(),
[email protected]ee496952013-01-10 23:17:331128 ShortenUberURL(browser()->tab_strip_model()->
1129 GetActiveWebContents()->GetURL()));
[email protected]fcca741b2011-06-17 22:46:371130}
1131
1132IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
1133 NavigateFromBlankToOptionsInSameTab) {
meacerc62e2ee2014-10-22 00:44:521134 chrome::NavigateParams params(MakeNavigateParams());
1135 params.url = GURL(url::kAboutBlankURL);
1136 ui_test_utils::NavigateToURL(&params);
[email protected]fcca741b2011-06-17 22:46:371137
[email protected]ddddfda2011-07-14 23:19:391138 {
[email protected]a7fe9112012-07-20 02:34:451139 content::WindowedNotificationObserver observer(
[email protected]ad50def52011-10-19 23:17:071140 content::NOTIFICATION_LOAD_STOP,
1141 content::NotificationService::AllSources());
[email protected]5d9cace72012-06-21 16:07:121142 chrome::ShowSettings(browser());
[email protected]ddddfda2011-07-14 23:19:391143 observer.Wait();
1144 }
[email protected]ee496952013-01-10 23:17:331145 EXPECT_EQ(1, browser()->tab_strip_model()->count());
[email protected]52877dbc62012-06-29 22:22:031146 EXPECT_EQ(GetSettingsURL(),
[email protected]ee496952013-01-10 23:17:331147 ShortenUberURL(browser()->tab_strip_model()->
1148 GetActiveWebContents()->GetURL()));
[email protected]fcca741b2011-06-17 22:46:371149}
1150
1151IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
1152 NavigateFromNTPToOptionsInSameTab) {
meacerc62e2ee2014-10-22 00:44:521153 chrome::NavigateParams params(MakeNavigateParams());
1154 params.url = GURL(chrome::kChromeUINewTabURL);
1155 ui_test_utils::NavigateToURL(&params);
[email protected]ee496952013-01-10 23:17:331156 EXPECT_EQ(1, browser()->tab_strip_model()->count());
[email protected]27658f32013-11-14 03:20:371157 EXPECT_EQ(GURL(chrome::kChromeUINewTabURL),
1158 browser()->tab_strip_model()->GetActiveWebContents()->GetURL());
[email protected]fcca741b2011-06-17 22:46:371159
[email protected]ddddfda2011-07-14 23:19:391160 {
[email protected]a7fe9112012-07-20 02:34:451161 content::WindowedNotificationObserver observer(
[email protected]ad50def52011-10-19 23:17:071162 content::NOTIFICATION_LOAD_STOP,
1163 content::NotificationService::AllSources());
[email protected]5d9cace72012-06-21 16:07:121164 chrome::ShowSettings(browser());
[email protected]ddddfda2011-07-14 23:19:391165 observer.Wait();
1166 }
[email protected]ee496952013-01-10 23:17:331167 EXPECT_EQ(1, browser()->tab_strip_model()->count());
[email protected]52877dbc62012-06-29 22:22:031168 EXPECT_EQ(GetSettingsURL(),
[email protected]ee496952013-01-10 23:17:331169 ShortenUberURL(browser()->tab_strip_model()->
1170 GetActiveWebContents()->GetURL()));
[email protected]fcca741b2011-06-17 22:46:371171}
1172
1173IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
1174 NavigateFromPageToOptionsInNewTab) {
meacerc62e2ee2014-10-22 00:44:521175 chrome::NavigateParams params(MakeNavigateParams());
1176 ui_test_utils::NavigateToURL(&params);
[email protected]ee496952013-01-10 23:17:331177 EXPECT_EQ(GetGoogleURL(),
1178 browser()->tab_strip_model()->GetActiveWebContents()->GetURL());
[email protected]0665ebe2013-02-13 09:53:191179 EXPECT_EQ(1u, chrome::GetTotalBrowserCount());
[email protected]ee496952013-01-10 23:17:331180 EXPECT_EQ(1, browser()->tab_strip_model()->count());
[email protected]fcca741b2011-06-17 22:46:371181
[email protected]ddddfda2011-07-14 23:19:391182 {
[email protected]a7fe9112012-07-20 02:34:451183 content::WindowedNotificationObserver observer(
[email protected]ad50def52011-10-19 23:17:071184 content::NOTIFICATION_LOAD_STOP,
1185 content::NotificationService::AllSources());
[email protected]5d9cace72012-06-21 16:07:121186 chrome::ShowSettings(browser());
[email protected]ddddfda2011-07-14 23:19:391187 observer.Wait();
1188 }
[email protected]ee496952013-01-10 23:17:331189 EXPECT_EQ(2, browser()->tab_strip_model()->count());
[email protected]52877dbc62012-06-29 22:22:031190 EXPECT_EQ(GetSettingsURL(),
[email protected]ee496952013-01-10 23:17:331191 ShortenUberURL(browser()->tab_strip_model()->
1192 GetActiveWebContents()->GetURL()));
[email protected]fcca741b2011-06-17 22:46:371193}
1194
1195IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
1196 NavigateFromNTPToOptionsSingleton) {
[email protected]ddddfda2011-07-14 23:19:391197 {
[email protected]a7fe9112012-07-20 02:34:451198 content::WindowedNotificationObserver observer(
[email protected]ad50def52011-10-19 23:17:071199 content::NOTIFICATION_LOAD_STOP,
1200 content::NotificationService::AllSources());
[email protected]5d9cace72012-06-21 16:07:121201 chrome::ShowSettings(browser());
[email protected]ddddfda2011-07-14 23:19:391202 observer.Wait();
1203 }
[email protected]ee496952013-01-10 23:17:331204 EXPECT_EQ(1, browser()->tab_strip_model()->count());
[email protected]fcca741b2011-06-17 22:46:371205
[email protected]a37d4b02012-06-25 21:56:101206 chrome::NewTab(browser());
[email protected]ee496952013-01-10 23:17:331207 EXPECT_EQ(2, browser()->tab_strip_model()->count());
[email protected]fcca741b2011-06-17 22:46:371208
[email protected]ddddfda2011-07-14 23:19:391209 {
[email protected]a7fe9112012-07-20 02:34:451210 content::WindowedNotificationObserver observer(
[email protected]ad50def52011-10-19 23:17:071211 content::NOTIFICATION_LOAD_STOP,
1212 content::NotificationService::AllSources());
[email protected]5d9cace72012-06-21 16:07:121213 chrome::ShowSettings(browser());
[email protected]ddddfda2011-07-14 23:19:391214 observer.Wait();
1215 }
[email protected]ee496952013-01-10 23:17:331216 EXPECT_EQ(2, browser()->tab_strip_model()->count());
[email protected]52877dbc62012-06-29 22:22:031217 EXPECT_EQ(GetSettingsURL(),
[email protected]ee496952013-01-10 23:17:331218 ShortenUberURL(browser()->tab_strip_model()->
1219 GetActiveWebContents()->GetURL()));
[email protected]fcca741b2011-06-17 22:46:371220}
1221
1222IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
1223 NavigateFromNTPToOptionsPageInSameTab) {
[email protected]ddddfda2011-07-14 23:19:391224 {
[email protected]a7fe9112012-07-20 02:34:451225 content::WindowedNotificationObserver observer(
[email protected]ad50def52011-10-19 23:17:071226 content::NOTIFICATION_LOAD_STOP,
1227 content::NotificationService::AllSources());
[email protected]5d9cace72012-06-21 16:07:121228 chrome::ShowClearBrowsingDataDialog(browser());
[email protected]ddddfda2011-07-14 23:19:391229 observer.Wait();
1230 }
[email protected]ee496952013-01-10 23:17:331231 EXPECT_EQ(1, browser()->tab_strip_model()->count());
[email protected]a048ad22012-03-23 04:26:561232 EXPECT_EQ(GetClearBrowsingDataURL(),
[email protected]ee496952013-01-10 23:17:331233 browser()->tab_strip_model()->GetActiveWebContents()->GetURL());
[email protected]fcca741b2011-06-17 22:46:371234
[email protected]a37d4b02012-06-25 21:56:101235 chrome::NewTab(browser());
[email protected]ee496952013-01-10 23:17:331236 EXPECT_EQ(2, browser()->tab_strip_model()->count());
[email protected]fcca741b2011-06-17 22:46:371237
[email protected]ddddfda2011-07-14 23:19:391238 {
[email protected]a7fe9112012-07-20 02:34:451239 content::WindowedNotificationObserver observer(
[email protected]ad50def52011-10-19 23:17:071240 content::NOTIFICATION_LOAD_STOP,
1241 content::NotificationService::AllSources());
[email protected]5d9cace72012-06-21 16:07:121242 chrome::ShowClearBrowsingDataDialog(browser());
[email protected]ddddfda2011-07-14 23:19:391243 observer.Wait();
1244 }
[email protected]ee496952013-01-10 23:17:331245 EXPECT_EQ(2, browser()->tab_strip_model()->count());
[email protected]a048ad22012-03-23 04:26:561246 EXPECT_EQ(GetClearBrowsingDataURL(),
[email protected]ee496952013-01-10 23:17:331247 browser()->tab_strip_model()->GetActiveWebContents()->GetURL());
[email protected]fcca741b2011-06-17 22:46:371248}
1249
1250IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
[email protected]05912742013-03-12 00:29:151251 NavigateFromOtherTabToSingletonOptions) {
[email protected]ddddfda2011-07-14 23:19:391252 {
[email protected]a7fe9112012-07-20 02:34:451253 content::WindowedNotificationObserver observer(
[email protected]ad50def52011-10-19 23:17:071254 content::NOTIFICATION_LOAD_STOP,
1255 content::NotificationService::AllSources());
[email protected]5d9cace72012-06-21 16:07:121256 chrome::ShowSettings(browser());
[email protected]ddddfda2011-07-14 23:19:391257 observer.Wait();
1258 }
1259 {
[email protected]a7fe9112012-07-20 02:34:451260 content::WindowedNotificationObserver observer(
[email protected]ad50def52011-10-19 23:17:071261 content::NOTIFICATION_LOAD_STOP,
1262 content::NotificationService::AllSources());
[email protected]52877dbc62012-06-29 22:22:031263 chrome::AddSelectedTabWithURL(browser(), GetGoogleURL(),
Sylvain Defresnec6ccc77d2014-09-19 10:19:351264 ui::PAGE_TRANSITION_LINK);
[email protected]ddddfda2011-07-14 23:19:391265 observer.Wait();
1266 }
[email protected]fcca741b2011-06-17 22:46:371267
[email protected]05912742013-03-12 00:29:151268 // This load should simply cause a tab switch.
1269 chrome::ShowSettings(browser());
1270
[email protected]ee496952013-01-10 23:17:331271 EXPECT_EQ(2, browser()->tab_strip_model()->count());
[email protected]ddddfda2011-07-14 23:19:391272 EXPECT_EQ(GetSettingsURL(),
[email protected]ee496952013-01-10 23:17:331273 ShortenUberURL(browser()->tab_strip_model()->
1274 GetActiveWebContents()->GetURL()));
[email protected]fcca741b2011-06-17 22:46:371275}
1276
[email protected]4e78b2d2013-06-12 16:46:171277IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, CloseSingletonTab) {
[email protected]79717cf2013-02-28 18:40:361278 for (int i = 0; i < 2; ++i) {
1279 content::WindowedNotificationObserver observer(
1280 content::NOTIFICATION_LOAD_STOP,
1281 content::NotificationService::AllSources());
1282 chrome::AddSelectedTabWithURL(browser(), GetGoogleURL(),
Sylvain Defresnec6ccc77d2014-09-19 10:19:351283 ui::PAGE_TRANSITION_TYPED);
[email protected]79717cf2013-02-28 18:40:361284 observer.Wait();
1285 }
1286
1287 browser()->tab_strip_model()->ActivateTabAt(0, true);
1288
1289 {
1290 content::WindowedNotificationObserver observer(
1291 content::NOTIFICATION_LOAD_STOP,
1292 content::NotificationService::AllSources());
1293 chrome::ShowSettings(browser());
1294 observer.Wait();
1295 }
1296
1297 EXPECT_TRUE(browser()->tab_strip_model()->CloseWebContentsAt(
1298 2, TabStripModel::CLOSE_USER_GESTURE));
1299 EXPECT_EQ(0, browser()->tab_strip_model()->active_index());
1300}
1301
[email protected]a048ad22012-03-23 04:26:561302// TODO(csilv): Update this for uber page. http://crbug.com/111579.
[email protected]ddddfda2011-07-14 23:19:391303IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
[email protected]a048ad22012-03-23 04:26:561304 DISABLED_NavigateFromDefaultToHistoryInSameTab) {
[email protected]ddddfda2011-07-14 23:19:391305 {
[email protected]a7fe9112012-07-20 02:34:451306 content::WindowedNotificationObserver observer(
[email protected]ad50def52011-10-19 23:17:071307 content::NOTIFICATION_LOAD_STOP,
1308 content::NotificationService::AllSources());
[email protected]5d9cace72012-06-21 16:07:121309 chrome::ShowHistory(browser());
[email protected]ddddfda2011-07-14 23:19:391310 observer.Wait();
1311 }
[email protected]ee496952013-01-10 23:17:331312 EXPECT_EQ(1, browser()->tab_strip_model()->count());
[email protected]11e03fb2012-03-03 19:07:051313 EXPECT_EQ(GURL(chrome::kChromeUIHistoryFrameURL),
[email protected]ee496952013-01-10 23:17:331314 browser()->tab_strip_model()->GetActiveWebContents()->GetURL());
[email protected]ddddfda2011-07-14 23:19:391315}
1316
[email protected]953c2132013-02-23 05:56:051317// TODO(linux_aura) http://crbug.com/163931
1318#if defined(OS_LINUX) && !defined(OS_CHROMEOS) && defined(USE_AURA)
dbeam2b4fc3562016-02-23 01:43:271319#define MAYBE_NavigateFromDefaultToBookmarksInSameTab \
1320 DISABLED_NavigateFromDefaultToBookmarksInSameTab
[email protected]953c2132013-02-23 05:56:051321#else
dbeam2b4fc3562016-02-23 01:43:271322#define MAYBE_NavigateFromDefaultToBookmarksInSameTab \
1323 NavigateFromDefaultToBookmarksInSameTab
[email protected]953c2132013-02-23 05:56:051324#endif
[email protected]ddddfda2011-07-14 23:19:391325IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
[email protected]953c2132013-02-23 05:56:051326 MAYBE_NavigateFromDefaultToBookmarksInSameTab) {
[email protected]ddddfda2011-07-14 23:19:391327 {
[email protected]a7fe9112012-07-20 02:34:451328 content::WindowedNotificationObserver observer(
[email protected]ad50def52011-10-19 23:17:071329 content::NOTIFICATION_LOAD_STOP,
1330 content::NotificationService::AllSources());
[email protected]5d9cace72012-06-21 16:07:121331 chrome::ShowBookmarkManager(browser());
[email protected]ddddfda2011-07-14 23:19:391332 observer.Wait();
1333 }
[email protected]ee496952013-01-10 23:17:331334 EXPECT_EQ(1, browser()->tab_strip_model()->count());
brettw66d1b81b2015-07-06 19:29:401335 EXPECT_TRUE(base::StartsWith(
[email protected]bc16a252013-01-23 02:21:491336 browser()->tab_strip_model()->GetActiveWebContents()->GetURL().spec(),
brettw66d1b81b2015-07-06 19:29:401337 chrome::kChromeUIBookmarksURL, base::CompareCase::SENSITIVE));
[email protected]ddddfda2011-07-14 23:19:391338}
1339
1340IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
1341 NavigateFromDefaultToDownloadsInSameTab) {
1342 {
[email protected]a7fe9112012-07-20 02:34:451343 content::WindowedNotificationObserver observer(
[email protected]ad50def52011-10-19 23:17:071344 content::NOTIFICATION_LOAD_STOP,
1345 content::NotificationService::AllSources());
[email protected]5d9cace72012-06-21 16:07:121346 chrome::ShowDownloads(browser());
[email protected]ddddfda2011-07-14 23:19:391347 observer.Wait();
1348 }
[email protected]ee496952013-01-10 23:17:331349 EXPECT_EQ(1, browser()->tab_strip_model()->count());
[email protected]ddddfda2011-07-14 23:19:391350 EXPECT_EQ(GURL(chrome::kChromeUIDownloadsURL),
[email protected]ee496952013-01-10 23:17:331351 browser()->tab_strip_model()->GetActiveWebContents()->GetURL());
[email protected]ddddfda2011-07-14 23:19:391352}
1353
[email protected]8fb16a82012-08-17 02:17:591354IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
1355 NavigateWithoutBrowser) {
1356 // First navigate using the profile of the existing browser window, and
1357 // check that the window is reused.
1358 chrome::NavigateParams params(browser()->profile(), GetGoogleURL(),
Sylvain Defresnec6ccc77d2014-09-19 10:19:351359 ui::PAGE_TRANSITION_LINK);
[email protected]8fb16a82012-08-17 02:17:591360 ui_test_utils::NavigateToURL(&params);
[email protected]0665ebe2013-02-13 09:53:191361 EXPECT_EQ(1u, chrome::GetTotalBrowserCount());
[email protected]8fb16a82012-08-17 02:17:591362
1363 // Now navigate using the incognito profile and check that a new window
1364 // is created.
1365 chrome::NavigateParams params_incognito(
1366 browser()->profile()->GetOffTheRecordProfile(),
Sylvain Defresnec6ccc77d2014-09-19 10:19:351367 GetGoogleURL(), ui::PAGE_TRANSITION_LINK);
[email protected]8fb16a82012-08-17 02:17:591368 ui_test_utils::NavigateToURL(&params_incognito);
[email protected]0665ebe2013-02-13 09:53:191369 EXPECT_EQ(2u, chrome::GetTotalBrowserCount());
[email protected]8fb16a82012-08-17 02:17:591370}
1371
[email protected]beb1d1192013-05-14 04:47:511372IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, ViewSourceIsntSingleton) {
1373 const std::string viewsource_ntp_url =
[email protected]dbdda5402013-05-30 22:13:481374 std::string(content::kViewSourceScheme) + ":" +
[email protected]beb1d1192013-05-14 04:47:511375 chrome::kChromeUIVersionURL;
1376
1377 chrome::NavigateParams viewsource_params(browser(),
1378 GURL(viewsource_ntp_url),
Sylvain Defresnec6ccc77d2014-09-19 10:19:351379 ui::PAGE_TRANSITION_LINK);
[email protected]beb1d1192013-05-14 04:47:511380 ui_test_utils::NavigateToURL(&viewsource_params);
1381
1382 chrome::NavigateParams singleton_params(browser(),
1383 GURL(chrome::kChromeUIVersionURL),
Sylvain Defresnec6ccc77d2014-09-19 10:19:351384 ui::PAGE_TRANSITION_LINK);
[email protected]beb1d1192013-05-14 04:47:511385 singleton_params.disposition = SINGLETON_TAB;
1386 EXPECT_EQ(-1, chrome::GetIndexOfSingletonTab(&singleton_params));
1387}
1388
[email protected]a2efc35d2013-08-03 23:17:251389// This test verifies that browser initiated navigations can send requests
1390// using POST.
1391IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
1392 SendBrowserInitiatedRequestUsingPOST) {
1393 // Uses a test sever to verify POST request.
svaldeza01f7d92015-11-18 17:47:561394 ASSERT_TRUE(embedded_test_server()->Start());
[email protected]a2efc35d2013-08-03 23:17:251395
1396 // Open a browser initiated POST request in new foreground tab.
[email protected]e9273e192013-12-11 17:51:491397 base::string16 expected_title(base::ASCIIToUTF16(kExpectedTitle));
[email protected]a2efc35d2013-08-03 23:17:251398 std::string post_data = kExpectedTitle;
[email protected]e9273e192013-12-11 17:51:491399 base::string16 title;
[email protected]a2efc35d2013-08-03 23:17:251400 ASSERT_TRUE(OpenPOSTURLInNewForegroundTabAndGetTitle(
svaldeza01f7d92015-11-18 17:47:561401 embedded_test_server()->GetURL(kEchoTitleCommand), post_data, true,
1402 &title));
[email protected]a2efc35d2013-08-03 23:17:251403 EXPECT_EQ(expected_title, title);
1404}
1405
lukasza477a5a22016-06-16 18:28:431406// This test verifies that renderer initiated navigations can also send requests
[email protected]a2efc35d2013-08-03 23:17:251407// using POST.
1408IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
1409 SendRendererInitiatedRequestUsingPOST) {
1410 // Uses a test sever to verify POST request.
svaldeza01f7d92015-11-18 17:47:561411 ASSERT_TRUE(embedded_test_server()->Start());
[email protected]a2efc35d2013-08-03 23:17:251412
1413 // Open a renderer initiated POST request in new foreground tab.
[email protected]e9273e192013-12-11 17:51:491414 base::string16 expected_title(base::ASCIIToUTF16(kExpectedTitle));
[email protected]a2efc35d2013-08-03 23:17:251415 std::string post_data = kExpectedTitle;
[email protected]e9273e192013-12-11 17:51:491416 base::string16 title;
[email protected]a2efc35d2013-08-03 23:17:251417 ASSERT_TRUE(OpenPOSTURLInNewForegroundTabAndGetTitle(
svaldeza01f7d92015-11-18 17:47:561418 embedded_test_server()->GetURL(kEchoTitleCommand), post_data, false,
1419 &title));
lukasza477a5a22016-06-16 18:28:431420 EXPECT_EQ(expected_title, title);
[email protected]a2efc35d2013-08-03 23:17:251421}
1422
meacerc62e2ee2014-10-22 00:44:521423// This test navigates to a data URL that contains BiDi control
1424// characters. For security reasons, BiDi control chars should always be
1425// escaped in the URL but they should be unescaped in the loaded HTML.
1426IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
1427 NavigateToDataURLWithBiDiControlChars) {
1428 // Text in Arabic.
1429 std::string text = "\xD8\xA7\xD8\xAE\xD8\xAA\xD8\xA8\xD8\xA7\xD8\xB1";
1430 // Page title starts with RTL mark.
1431 std::string unescaped_title = "\xE2\x80\x8F" + text;
1432 std::string data_url = "data:text/html;charset=utf-8,<html><title>" +
1433 unescaped_title + "</title></html>";
1434 // BiDi control chars in URLs are always escaped, so the expected URL should
1435 // have the title with the escaped RTL mark.
1436 std::string escaped_title = "%E2%80%8F" + text;
1437 std::string expected_url = "data:text/html;charset=utf-8,<html><title>" +
1438 escaped_title + "</title></html>";
1439
1440 // Navigate to the page.
1441 chrome::NavigateParams params(MakeNavigateParams());
1442 params.disposition = NEW_FOREGROUND_TAB;
1443 params.url = GURL(data_url);
1444 params.window_action = chrome::NavigateParams::SHOW_WINDOW;
1445 ui_test_utils::NavigateToURL(&params);
1446
1447 base::string16 expected_title(base::UTF8ToUTF16(unescaped_title));
1448 EXPECT_TRUE(params.target_contents);
1449 EXPECT_EQ(expected_title, params.target_contents->GetTitle());
1450 // GURL always keeps non-ASCII characters escaped, but check them anyways.
1451 EXPECT_EQ(GURL(expected_url).spec(), params.target_contents->GetURL().spec());
1452 // Check the omnibox text. It should have escaped RTL with unescaped text.
1453 LocationBar* location_bar = browser()->window()->GetLocationBar();
1454 OmniboxView* omnibox_view = location_bar->GetOmniboxView();
1455 EXPECT_EQ(base::UTF8ToUTF16(expected_url), omnibox_view->GetText());
1456}
1457
[email protected]a2efc35d2013-08-03 23:17:251458} // namespace