blob: e5442d429d4b1eb8e586e0429e2ea9d502bd5975 [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"
[email protected]83ff91c2012-01-05 20:54:1333#include "content/public/browser/web_contents.h"
svaldeza01f7d92015-11-18 17:47:5634#include "net/test/embedded_test_server/embedded_test_server.h"
[email protected]a1feae52010-10-11 22:14:4535
[email protected]4ca15302012-01-03 05:53:2036using content::WebContents;
37
[email protected]ddddfda2011-07-14 23:19:3938namespace {
39
[email protected]a2efc35d2013-08-03 23:17:2540const char kExpectedTitle[] = "PASSED!";
svaldeza01f7d92015-11-18 17:47:5641const char kEchoTitleCommand[] = "/echotitle";
[email protected]a2efc35d2013-08-03 23:17:2542
[email protected]ddddfda2011-07-14 23:19:3943GURL GetGoogleURL() {
[email protected]bd817c22011-02-09 08:16:4644 return GURL("http://www.google.com/");
45}
[email protected]a1feae52010-10-11 22:14:4546
[email protected]ddddfda2011-07-14 23:19:3947GURL GetSettingsURL() {
[email protected]f8f93eb2012-09-25 03:06:2448 return GURL(chrome::kChromeUISettingsURL);
[email protected]ddddfda2011-07-14 23:19:3949}
50
[email protected]a048ad22012-03-23 04:26:5651GURL GetContentSettingsURL() {
52 return GetSettingsURL().Resolve(chrome::kContentSettingsExceptionsSubPage);
[email protected]ddddfda2011-07-14 23:19:3953}
54
[email protected]a048ad22012-03-23 04:26:5655GURL GetClearBrowsingDataURL() {
56 return GetSettingsURL().Resolve(chrome::kClearBrowserDataSubPage);
[email protected]ddddfda2011-07-14 23:19:3957}
58
[email protected]f8f93eb2012-09-25 03:06:2459// Converts long uber URLs ("chrome://chrome/foo/") to short (virtual) URLs
60// ("chrome://foo/"). This should be used to convert the return value of
61// WebContentsImpl::GetURL before comparison because it can return either the
62// real URL or the virtual URL.
63GURL ShortenUberURL(const GURL& url) {
64 std::string url_string = url.spec();
65 const std::string long_prefix = "chrome://chrome/";
66 const std::string short_prefix = "chrome://";
67 if (url_string.find(long_prefix) != 0)
68 return url;
69 url_string.replace(0, long_prefix.length(), short_prefix);
70 return GURL(url_string);
71}
72
[email protected]a2efc35d2013-08-03 23:17:2573} // namespace
[email protected]ddddfda2011-07-14 23:19:3974
[email protected]78e2edc2012-07-01 23:32:2875chrome::NavigateParams BrowserNavigatorTest::MakeNavigateParams() const {
[email protected]bd817c22011-02-09 08:16:4676 return MakeNavigateParams(browser());
77}
[email protected]a1feae52010-10-11 22:14:4578
[email protected]78e2edc2012-07-01 23:32:2879chrome::NavigateParams BrowserNavigatorTest::MakeNavigateParams(
[email protected]bd817c22011-02-09 08:16:4680 Browser* browser) const {
[email protected]78e2edc2012-07-01 23:32:2881 chrome::NavigateParams params(browser, GetGoogleURL(),
Sylvain Defresnec6ccc77d2014-09-19 10:19:3582 ui::PAGE_TRANSITION_LINK);
[email protected]50592b52013-05-02 22:26:2583 params.window_action = chrome::NavigateParams::SHOW_WINDOW;
[email protected]bd817c22011-02-09 08:16:4684 return params;
85}
[email protected]a1feae52010-10-11 22:14:4586
[email protected]a2efc35d2013-08-03 23:17:2587bool BrowserNavigatorTest::OpenPOSTURLInNewForegroundTabAndGetTitle(
88 const GURL& url, const std::string& post_data, bool is_browser_initiated,
89 base::string16* title) {
90 chrome::NavigateParams param(MakeNavigateParams());
91 param.disposition = NEW_FOREGROUND_TAB;
92 param.url = url;
93 param.is_renderer_initiated = !is_browser_initiated;
94 param.uses_post = true;
95 param.browser_initiated_post_data = new base::RefCountedStaticMemory(
[email protected]8df08cf2014-02-12 22:34:0896 post_data.data(), post_data.size());
[email protected]a2efc35d2013-08-03 23:17:2597
98 ui_test_utils::NavigateToURL(&param);
99 if (!param.target_contents)
100 return false;
101
102 // Navigate() should have opened the contents in new foreground tab in the
103 // current Browser.
104 EXPECT_EQ(browser(), param.browser);
105 EXPECT_EQ(browser()->tab_strip_model()->GetActiveWebContents(),
106 param.target_contents);
107 // We should have one window, with one tab.
108 EXPECT_EQ(1u, chrome::GetTotalBrowserCount());
109 EXPECT_EQ(2, browser()->tab_strip_model()->count());
110
111 *title = param.target_contents->GetTitle();
112 return true;
113}
114
[email protected]bd817c22011-02-09 08:16:46115Browser* BrowserNavigatorTest::CreateEmptyBrowserForType(Browser::Type type,
116 Profile* profile) {
scottmg851949002016-02-09 20:09:44117 Browser* browser = new Browser(Browser::CreateParams(type, profile));
[email protected]00509a32013-11-17 17:45:37118 chrome::AddTabAt(browser, GURL(), -1, true);
[email protected]bd817c22011-02-09 08:16:46119 return browser;
120}
[email protected]a1feae52010-10-11 22:14:45121
[email protected]d2202e22014-04-14 20:20:53122Browser* BrowserNavigatorTest::CreateEmptyBrowserForApp(Profile* profile) {
scottmg851949002016-02-09 20:09:44123 Browser* browser = new Browser(Browser::CreateParams::CreateForApp(
124 "Test", false /* trusted_source */, gfx::Rect(), profile));
[email protected]00509a32013-11-17 17:45:37125 chrome::AddTabAt(browser, GURL(), -1, true);
[email protected]b35b26b32011-05-05 20:35:14126 return browser;
127}
128
[email protected]e232c992012-12-06 12:43:20129WebContents* BrowserNavigatorTest::CreateWebContents() {
[email protected]54944cde2012-12-09 09:24:59130 content::WebContents::CreateParams create_params(browser()->profile());
[email protected]ed245db2012-12-18 08:00:45131 content::WebContents* base_web_contents =
[email protected]ee496952013-01-10 23:17:33132 browser()->tab_strip_model()->GetActiveWebContents();
[email protected]ed245db2012-12-18 08:00:45133 if (base_web_contents) {
134 create_params.initial_size =
[email protected]fc2b46b2014-05-03 16:33:45135 base_web_contents->GetContainerBounds().size();
[email protected]ed245db2012-12-18 08:00:45136 }
[email protected]54944cde2012-12-09 09:24:59137 return WebContents::Create(create_params);
[email protected]bd817c22011-02-09 08:16:46138}
[email protected]a1feae52010-10-11 22:14:45139
[email protected]bd817c22011-02-09 08:16:46140void BrowserNavigatorTest::RunSuppressTest(WindowOpenDisposition disposition) {
[email protected]ee496952013-01-10 23:17:33141 GURL old_url = browser()->tab_strip_model()->GetActiveWebContents()->GetURL();
meacerc62e2ee2014-10-22 00:44:52142 chrome::NavigateParams params(MakeNavigateParams());
143 params.disposition = disposition;
144 chrome::Navigate(&params);
[email protected]a1feae52010-10-11 22:14:45145
[email protected]bd817c22011-02-09 08:16:46146 // Nothing should have happened as a result of Navigate();
[email protected]ee496952013-01-10 23:17:33147 EXPECT_EQ(1, browser()->tab_strip_model()->count());
[email protected]0665ebe2013-02-13 09:53:19148 EXPECT_EQ(1u, chrome::GetTotalBrowserCount());
[email protected]ee496952013-01-10 23:17:33149 EXPECT_EQ(old_url,
150 browser()->tab_strip_model()->GetActiveWebContents()->GetURL());
[email protected]bd817c22011-02-09 08:16:46151}
[email protected]bb89e7482010-11-17 18:27:04152
[email protected]fc0ed302011-11-29 23:17:19153void BrowserNavigatorTest::RunUseNonIncognitoWindowTest(const GURL& url) {
154 Browser* incognito_browser = CreateIncognitoBrowser();
155
[email protected]0665ebe2013-02-13 09:53:19156 EXPECT_EQ(2u, chrome::GetTotalBrowserCount());
[email protected]ee496952013-01-10 23:17:33157 EXPECT_EQ(1, browser()->tab_strip_model()->count());
158 EXPECT_EQ(1, incognito_browser->tab_strip_model()->count());
[email protected]fc0ed302011-11-29 23:17:19159
160 // Navigate to the page.
meacerc62e2ee2014-10-22 00:44:52161 chrome::NavigateParams params(MakeNavigateParams(incognito_browser));
162 params.disposition = SINGLETON_TAB;
163 params.url = url;
164 params.window_action = chrome::NavigateParams::SHOW_WINDOW;
165 chrome::Navigate(&params);
[email protected]fc0ed302011-11-29 23:17:19166
[email protected]50592b52013-05-02 22:26:25167 // This page should be opened in browser() window.
meacerc62e2ee2014-10-22 00:44:52168 EXPECT_NE(incognito_browser, params.browser);
169 EXPECT_EQ(browser(), params.browser);
[email protected]ee496952013-01-10 23:17:33170 EXPECT_EQ(2, browser()->tab_strip_model()->count());
171 EXPECT_EQ(url,
172 browser()->tab_strip_model()->GetActiveWebContents()->GetURL());
[email protected]fc0ed302011-11-29 23:17:19173}
174
175void BrowserNavigatorTest::RunDoNothingIfIncognitoIsForcedTest(
176 const GURL& url) {
177 Browser* browser = CreateIncognitoBrowser();
178
179 // Set kIncognitoModeAvailability to FORCED.
180 PrefService* prefs1 = browser->profile()->GetPrefs();
181 prefs1->SetInteger(prefs::kIncognitoModeAvailability,
182 IncognitoModePrefs::FORCED);
183 PrefService* prefs2 = browser->profile()->GetOriginalProfile()->GetPrefs();
184 prefs2->SetInteger(prefs::kIncognitoModeAvailability,
185 IncognitoModePrefs::FORCED);
186
187 // Navigate to the page.
meacerc62e2ee2014-10-22 00:44:52188 chrome::NavigateParams params(MakeNavigateParams(browser));
189 params.disposition = OFF_THE_RECORD;
190 params.url = url;
191 params.window_action = chrome::NavigateParams::SHOW_WINDOW;
192 chrome::Navigate(&params);
[email protected]fc0ed302011-11-29 23:17:19193
194 // The page should not be opened.
meacerc62e2ee2014-10-22 00:44:52195 EXPECT_EQ(browser, params.browser);
[email protected]ee496952013-01-10 23:17:33196 EXPECT_EQ(1, browser->tab_strip_model()->count());
[email protected]8e09c7af2014-06-10 11:46:17197 EXPECT_EQ(GURL(url::kAboutBlankURL),
[email protected]ee496952013-01-10 23:17:33198 browser->tab_strip_model()->GetActiveWebContents()->GetURL());
[email protected]fc0ed302011-11-29 23:17:19199}
200
[email protected]aae79572014-06-13 00:42:58201void BrowserNavigatorTest::SetUpCommandLine(base::CommandLine* command_line) {
202 // Disable settings-in-a-window so that we can use the settings page and
203 // sub-pages to test browser navigation.
204 command_line->AppendSwitch(::switches::kDisableSettingsWindow);
benwellsf3c6fac2015-09-01 23:38:52205
206 // Disable new downloads UI as it is very very slow. https://crbug.com/526577
207 // TODO(dbeam): remove this once the downloads UI is not slow.
208 command_line->AppendSwitch(switches::kDisableMaterialDesignDownloads);
[email protected]aae79572014-06-13 00:42:58209}
210
[email protected]6c2381d2011-10-19 02:52:53211void BrowserNavigatorTest::Observe(
212 int type,
213 const content::NotificationSource& source,
214 const content::NotificationDetails& details) {
[email protected]432115822011-07-10 15:52:27215 switch (type) {
[email protected]d53a08c2012-07-18 20:35:30216 case content::NOTIFICATION_WEB_CONTENTS_RENDER_VIEW_HOST_CREATED: {
[email protected]bd817c22011-02-09 08:16:46217 ++this->created_tab_contents_count_;
218 break;
[email protected]fa7ebe02010-11-29 23:04:57219 }
[email protected]bd817c22011-02-09 08:16:46220 default:
221 break;
[email protected]fa7ebe02010-11-29 23:04:57222 }
[email protected]bd817c22011-02-09 08:16:46223}
[email protected]fa7ebe02010-11-29 23:04:57224
[email protected]ddddfda2011-07-14 23:19:39225
[email protected]bd817c22011-02-09 08:16:46226namespace {
[email protected]a1feae52010-10-11 22:14:45227
[email protected]a1feae52010-10-11 22:14:45228// This test verifies that when a navigation occurs within a tab, the tab count
229// of the Browser remains the same and the current tab bears the loaded URL.
[email protected]59167c22013-06-03 18:07:32230// Note that network URLs are not actually loaded in tests, so this also tests
231// that error pages leave the intended URL in the address bar.
[email protected]a1feae52010-10-11 22:14:45232IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_CurrentTab) {
[email protected]ddddfda2011-07-14 23:19:39233 ui_test_utils::NavigateToURL(browser(), GetGoogleURL());
[email protected]ee496952013-01-10 23:17:33234 EXPECT_EQ(GetGoogleURL(),
235 browser()->tab_strip_model()->GetActiveWebContents()->GetURL());
[email protected]a1feae52010-10-11 22:14:45236 // We should have one window with one tab.
[email protected]0665ebe2013-02-13 09:53:19237 EXPECT_EQ(1u, chrome::GetTotalBrowserCount());
[email protected]ee496952013-01-10 23:17:33238 EXPECT_EQ(1, browser()->tab_strip_model()->count());
[email protected]a1feae52010-10-11 22:14:45239}
240
[email protected]bd817c22011-02-09 08:16:46241// This test verifies that a singleton tab is refocused if one is already opened
[email protected]19d9f3a2010-10-14 21:49:36242// in another or an existing window, or added if it is not.
243IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_SingletonTabExisting) {
[email protected]19d9f3a2010-10-14 21:49:36244 GURL singleton_url1("http://maps.google.com/");
[email protected]fa7ebe02010-11-29 23:04:57245
[email protected]e232c992012-12-06 12:43:20246 // Register for a notification if an additional WebContents was instantiated.
[email protected]bd817c22011-02-09 08:16:46247 // Opening a Singleton tab that is already opened should not be opening a new
[email protected]e232c992012-12-06 12:43:20248 // tab nor be creating a new WebContents object.
[email protected]6c2381d2011-10-19 02:52:53249 content::NotificationRegistrar registrar;
[email protected]fa7ebe02010-11-29 23:04:57250
251 // As the registrar object goes out of scope, this will get unregistered
[email protected]d53a08c2012-07-18 20:35:30252 registrar.Add(this,
253 content::NOTIFICATION_WEB_CONTENTS_RENDER_VIEW_HOST_CREATED,
[email protected]ad50def52011-10-19 23:17:07254 content::NotificationService::AllSources());
[email protected]fa7ebe02010-11-29 23:04:57255
[email protected]52877dbc62012-06-29 22:22:03256 chrome::AddSelectedTabWithURL(browser(), singleton_url1,
Sylvain Defresnec6ccc77d2014-09-19 10:19:35257 ui::PAGE_TRANSITION_LINK);
[email protected]52877dbc62012-06-29 22:22:03258 chrome::AddSelectedTabWithURL(browser(), GetGoogleURL(),
Sylvain Defresnec6ccc77d2014-09-19 10:19:35259 ui::PAGE_TRANSITION_LINK);
[email protected]19d9f3a2010-10-14 21:49:36260
261 // We should have one browser with 3 tabs, the 3rd selected.
[email protected]0665ebe2013-02-13 09:53:19262 EXPECT_EQ(1u, chrome::GetTotalBrowserCount());
[email protected]ee496952013-01-10 23:17:33263 EXPECT_EQ(2, browser()->tab_strip_model()->active_index());
[email protected]19d9f3a2010-10-14 21:49:36264
[email protected]fa7ebe02010-11-29 23:04:57265 unsigned int previous_tab_contents_count =
266 created_tab_contents_count_ = 0;
267
[email protected]19d9f3a2010-10-14 21:49:36268 // Navigate to singleton_url1.
meacerc62e2ee2014-10-22 00:44:52269 chrome::NavigateParams params(MakeNavigateParams());
270 params.disposition = SINGLETON_TAB;
271 params.url = singleton_url1;
272 chrome::Navigate(&params);
[email protected]19d9f3a2010-10-14 21:49:36273
274 // The middle tab should now be selected.
meacerc62e2ee2014-10-22 00:44:52275 EXPECT_EQ(browser(), params.browser);
[email protected]ee496952013-01-10 23:17:33276 EXPECT_EQ(1, browser()->tab_strip_model()->active_index());
[email protected]fa7ebe02010-11-29 23:04:57277
278 // No tab contents should have been created
279 EXPECT_EQ(previous_tab_contents_count,
280 created_tab_contents_count_);
[email protected]19d9f3a2010-10-14 21:49:36281}
282
283IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
[email protected]578c6962011-08-24 22:06:40284 Disposition_SingletonTabRespectingRef) {
285 GURL singleton_ref_url1("http://maps.google.com/#a");
286 GURL singleton_ref_url2("http://maps.google.com/#b");
287 GURL singleton_ref_url3("http://maps.google.com/");
288
[email protected]52877dbc62012-06-29 22:22:03289 chrome::AddSelectedTabWithURL(browser(), singleton_ref_url1,
Sylvain Defresnec6ccc77d2014-09-19 10:19:35290 ui::PAGE_TRANSITION_LINK);
[email protected]578c6962011-08-24 22:06:40291
292 // We should have one browser with 2 tabs, 2nd selected.
[email protected]0665ebe2013-02-13 09:53:19293 EXPECT_EQ(1u, chrome::GetTotalBrowserCount());
[email protected]ee496952013-01-10 23:17:33294 EXPECT_EQ(2, browser()->tab_strip_model()->count());
295 EXPECT_EQ(1, browser()->tab_strip_model()->active_index());
[email protected]578c6962011-08-24 22:06:40296
297 // Navigate to singleton_url2.
meacerc62e2ee2014-10-22 00:44:52298 chrome::NavigateParams params(MakeNavigateParams());
299 params.disposition = SINGLETON_TAB;
300 params.url = singleton_ref_url2;
301 chrome::Navigate(&params);
[email protected]578c6962011-08-24 22:06:40302
303 // We should now have 2 tabs, the 2nd one selected.
meacerc62e2ee2014-10-22 00:44:52304 EXPECT_EQ(browser(), params.browser);
[email protected]ee496952013-01-10 23:17:33305 EXPECT_EQ(2, browser()->tab_strip_model()->count());
306 EXPECT_EQ(1, browser()->tab_strip_model()->active_index());
[email protected]578c6962011-08-24 22:06:40307
308 // Navigate to singleton_url2, but with respect ref set.
meacerc62e2ee2014-10-22 00:44:52309 params = MakeNavigateParams();
310 params.disposition = SINGLETON_TAB;
311 params.url = singleton_ref_url2;
312 params.ref_behavior = chrome::NavigateParams::RESPECT_REF;
313 chrome::Navigate(&params);
[email protected]578c6962011-08-24 22:06:40314
315 // We should now have 3 tabs, the 3th one selected.
meacerc62e2ee2014-10-22 00:44:52316 EXPECT_EQ(browser(), params.browser);
[email protected]ee496952013-01-10 23:17:33317 EXPECT_EQ(3, browser()->tab_strip_model()->count());
318 EXPECT_EQ(2, browser()->tab_strip_model()->active_index());
[email protected]578c6962011-08-24 22:06:40319
320 // Navigate to singleton_url3.
meacerc62e2ee2014-10-22 00:44:52321 params = MakeNavigateParams();
322 params.disposition = SINGLETON_TAB;
323 params.url = singleton_ref_url3;
324 params.ref_behavior = chrome::NavigateParams::RESPECT_REF;
325 chrome::Navigate(&params);
[email protected]578c6962011-08-24 22:06:40326
327 // We should now have 4 tabs, the 4th one selected.
meacerc62e2ee2014-10-22 00:44:52328 EXPECT_EQ(browser(), params.browser);
[email protected]ee496952013-01-10 23:17:33329 EXPECT_EQ(4, browser()->tab_strip_model()->count());
330 EXPECT_EQ(3, browser()->tab_strip_model()->active_index());
[email protected]578c6962011-08-24 22:06:40331}
332
333IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
[email protected]19d9f3a2010-10-14 21:49:36334 Disposition_SingletonTabNoneExisting) {
[email protected]19d9f3a2010-10-14 21:49:36335 GURL singleton_url1("http://maps.google.com/");
336
[email protected]bd817c22011-02-09 08:16:46337 // We should have one browser with 1 tab.
[email protected]0665ebe2013-02-13 09:53:19338 EXPECT_EQ(1u, chrome::GetTotalBrowserCount());
[email protected]ee496952013-01-10 23:17:33339 EXPECT_EQ(0, browser()->tab_strip_model()->active_index());
[email protected]19d9f3a2010-10-14 21:49:36340
341 // Navigate to singleton_url1.
meacerc62e2ee2014-10-22 00:44:52342 chrome::NavigateParams params(MakeNavigateParams());
343 params.disposition = SINGLETON_TAB;
344 params.url = singleton_url1;
345 chrome::Navigate(&params);
[email protected]19d9f3a2010-10-14 21:49:36346
347 // We should now have 2 tabs, the 2nd one selected.
meacerc62e2ee2014-10-22 00:44:52348 EXPECT_EQ(browser(), params.browser);
[email protected]ee496952013-01-10 23:17:33349 EXPECT_EQ(2, browser()->tab_strip_model()->count());
350 EXPECT_EQ(1, browser()->tab_strip_model()->active_index());
[email protected]a1feae52010-10-11 22:14:45351}
352
353// This test verifies that when a navigation results in a foreground tab, the
354// tab count of the Browser increases and the selected tab shifts to the new
355// foreground tab.
356IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_NewForegroundTab) {
[email protected]ee496952013-01-10 23:17:33357 WebContents* old_contents =
358 browser()->tab_strip_model()->GetActiveWebContents();
meacerc62e2ee2014-10-22 00:44:52359 chrome::NavigateParams params(MakeNavigateParams());
360 params.disposition = NEW_FOREGROUND_TAB;
361 chrome::Navigate(&params);
[email protected]ee496952013-01-10 23:17:33362 EXPECT_NE(old_contents,
363 browser()->tab_strip_model()->GetActiveWebContents());
[email protected]e232c992012-12-06 12:43:20364 EXPECT_EQ(browser()->tab_strip_model()->GetActiveWebContents(),
meacerc62e2ee2014-10-22 00:44:52365 params.target_contents);
[email protected]ee496952013-01-10 23:17:33366 EXPECT_EQ(2, browser()->tab_strip_model()->count());
[email protected]a1feae52010-10-11 22:14:45367}
368
369// This test verifies that when a navigation results in a background tab, the
370// tab count of the Browser increases but the selected tab remains the same.
371IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_NewBackgroundTab) {
[email protected]ee496952013-01-10 23:17:33372 WebContents* old_contents =
373 browser()->tab_strip_model()->GetActiveWebContents();
meacerc62e2ee2014-10-22 00:44:52374 chrome::NavigateParams params(MakeNavigateParams());
375 params.disposition = NEW_BACKGROUND_TAB;
376 chrome::Navigate(&params);
[email protected]ee496952013-01-10 23:17:33377 WebContents* new_contents =
378 browser()->tab_strip_model()->GetActiveWebContents();
[email protected]a1feae52010-10-11 22:14:45379 // The selected tab should have remained unchanged, since the new tab was
380 // opened in the background.
381 EXPECT_EQ(old_contents, new_contents);
[email protected]ee496952013-01-10 23:17:33382 EXPECT_EQ(2, browser()->tab_strip_model()->count());
[email protected]a1feae52010-10-11 22:14:45383}
384
385// This test verifies that when a navigation requiring a new foreground tab
386// occurs in a Browser that cannot host multiple tabs, the new foreground tab
387// is created in an existing compatible Browser.
388IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
389 Disposition_IncompatibleWindow_Existing) {
390 // Open a foreground tab in a window that cannot open popups when there is an
391 // existing compatible window somewhere else that they can be opened within.
392 Browser* popup = CreateEmptyBrowserForType(Browser::TYPE_POPUP,
393 browser()->profile());
meacerc62e2ee2014-10-22 00:44:52394 chrome::NavigateParams params(MakeNavigateParams(popup));
395 params.disposition = NEW_FOREGROUND_TAB;
396 chrome::Navigate(&params);
[email protected]a1feae52010-10-11 22:14:45397
398 // Navigate() should have opened the tab in a different browser since the
399 // one we supplied didn't support additional tabs.
meacerc62e2ee2014-10-22 00:44:52400 EXPECT_NE(popup, params.browser);
[email protected]a1feae52010-10-11 22:14:45401
402 // Since browser() is an existing compatible tabbed browser, it should have
403 // opened the tab there.
meacerc62e2ee2014-10-22 00:44:52404 EXPECT_EQ(browser(), params.browser);
[email protected]a1feae52010-10-11 22:14:45405
406 // We should be left with 2 windows, the popup with one tab and the browser()
407 // provided by the framework with two.
[email protected]0665ebe2013-02-13 09:53:19408 EXPECT_EQ(2u, chrome::GetTotalBrowserCount());
[email protected]ee496952013-01-10 23:17:33409 EXPECT_EQ(1, popup->tab_strip_model()->count());
410 EXPECT_EQ(2, browser()->tab_strip_model()->count());
[email protected]a1feae52010-10-11 22:14:45411}
412
413// This test verifies that when a navigation requiring a new foreground tab
414// occurs in a Browser that cannot host multiple tabs and no compatible Browser
415// that can is open, a compatible Browser is created.
416IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
417 Disposition_IncompatibleWindow_NoExisting) {
418 // We want to simulate not being able to find an existing window compatible
419 // with our non-tabbed browser window so Navigate() is forced to create a
420 // new compatible window. Because browser() supplied by the in-process
421 // browser testing framework is compatible with browser()->profile(), we
422 // need a different profile, and creating a popup window with an incognito
423 // profile is a quick and dirty way of achieving this.
424 Browser* popup = CreateEmptyBrowserForType(
[email protected]b35b26b32011-05-05 20:35:14425 Browser::TYPE_POPUP,
426 browser()->profile()->GetOffTheRecordProfile());
meacerc62e2ee2014-10-22 00:44:52427 chrome::NavigateParams params(MakeNavigateParams(popup));
428 params.disposition = NEW_FOREGROUND_TAB;
429 chrome::Navigate(&params);
[email protected]a1feae52010-10-11 22:14:45430
431 // Navigate() should have opened the tab in a different browser since the
432 // one we supplied didn't support additional tabs.
meacerc62e2ee2014-10-22 00:44:52433 EXPECT_NE(popup, params.browser);
[email protected]a1feae52010-10-11 22:14:45434
435 // This time, browser() is _not_ compatible with popup since it is not an
436 // incognito window.
meacerc62e2ee2014-10-22 00:44:52437 EXPECT_NE(browser(), params.browser);
[email protected]a1feae52010-10-11 22:14:45438
439 // We should have three windows, each with one tab:
440 // 1. the browser() provided by the framework (unchanged in this test)
441 // 2. the incognito popup we created originally
442 // 3. the new incognito tabbed browser that was created by Navigate().
[email protected]0665ebe2013-02-13 09:53:19443 EXPECT_EQ(3u, chrome::GetTotalBrowserCount());
[email protected]ee496952013-01-10 23:17:33444 EXPECT_EQ(1, browser()->tab_strip_model()->count());
445 EXPECT_EQ(1, popup->tab_strip_model()->count());
meacerc62e2ee2014-10-22 00:44:52446 EXPECT_EQ(1, params.browser->tab_strip_model()->count());
447 EXPECT_TRUE(params.browser->is_type_tabbed());
[email protected]a1feae52010-10-11 22:14:45448}
449
450// This test verifies that navigating with WindowOpenDisposition = NEW_POPUP
451// from a normal Browser results in a new Browser with TYPE_POPUP.
452IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_NewPopup) {
meacerc62e2ee2014-10-22 00:44:52453 chrome::NavigateParams params(MakeNavigateParams());
454 params.disposition = NEW_POPUP;
455 params.window_bounds = gfx::Rect(0, 0, 200, 200);
[email protected]7d329992011-04-15 18:20:02456 // Wait for new popup to to load and gain focus.
meacerc62e2ee2014-10-22 00:44:52457 ui_test_utils::NavigateToURL(&params);
[email protected]a1feae52010-10-11 22:14:45458
[email protected]7d329992011-04-15 18:20:02459 // Navigate() should have opened a new, focused popup window.
meacerc62e2ee2014-10-22 00:44:52460 EXPECT_NE(browser(), params.browser);
[email protected]50592b52013-05-02 22:26:25461#if 0
462 // TODO(stevenjb): Enable this test. See: crbug.com/79493
meacerc62e2ee2014-10-22 00:44:52463 EXPECT_TRUE(browser->window()->IsActive());
[email protected]50592b52013-05-02 22:26:25464#endif
meacerc62e2ee2014-10-22 00:44:52465 EXPECT_TRUE(params.browser->is_type_popup());
466 EXPECT_FALSE(params.browser->is_app());
[email protected]a1feae52010-10-11 22:14:45467
468 // We should have two windows, the browser() provided by the framework and the
469 // new popup window.
[email protected]0665ebe2013-02-13 09:53:19470 EXPECT_EQ(2u, chrome::GetTotalBrowserCount());
[email protected]ee496952013-01-10 23:17:33471 EXPECT_EQ(1, browser()->tab_strip_model()->count());
meacerc62e2ee2014-10-22 00:44:52472 EXPECT_EQ(1, params.browser->tab_strip_model()->count());
[email protected]a1feae52010-10-11 22:14:45473}
474
475// This test verifies that navigating with WindowOpenDisposition = NEW_POPUP
[email protected]f112b0f2011-05-26 01:53:52476// from a normal Browser results in a new Browser with is_app() true.
477IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_NewPopup_ExtensionId) {
meacerc62e2ee2014-10-22 00:44:52478 chrome::NavigateParams params(MakeNavigateParams());
479 params.disposition = NEW_POPUP;
480 params.extension_app_id = "extensionappid";
481 params.window_bounds = gfx::Rect(0, 0, 200, 200);
[email protected]f112b0f2011-05-26 01:53:52482 // Wait for new popup to to load and gain focus.
meacerc62e2ee2014-10-22 00:44:52483 ui_test_utils::NavigateToURL(&params);
[email protected]f112b0f2011-05-26 01:53:52484
485 // Navigate() should have opened a new, focused popup window.
meacerc62e2ee2014-10-22 00:44:52486 EXPECT_NE(browser(), params.browser);
487 EXPECT_TRUE(params.browser->is_type_popup());
488 EXPECT_TRUE(params.browser->is_app());
[email protected]f112b0f2011-05-26 01:53:52489
490 // We should have two windows, the browser() provided by the framework and the
491 // new popup window.
[email protected]0665ebe2013-02-13 09:53:19492 EXPECT_EQ(2u, chrome::GetTotalBrowserCount());
[email protected]ee496952013-01-10 23:17:33493 EXPECT_EQ(1, browser()->tab_strip_model()->count());
meacerc62e2ee2014-10-22 00:44:52494 EXPECT_EQ(1, params.browser->tab_strip_model()->count());
[email protected]f112b0f2011-05-26 01:53:52495}
496
497// This test verifies that navigating with WindowOpenDisposition = NEW_POPUP
[email protected]300d1e52011-01-19 23:57:57498// from a normal popup results in a new Browser with TYPE_POPUP.
499IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_NewPopupFromPopup) {
500 // Open a popup.
meacerc62e2ee2014-10-22 00:44:52501 chrome::NavigateParams params1(MakeNavigateParams());
502 params1.disposition = NEW_POPUP;
503 params1.window_bounds = gfx::Rect(0, 0, 200, 200);
504 chrome::Navigate(&params1);
[email protected]300d1e52011-01-19 23:57:57505 // Open another popup.
meacerc62e2ee2014-10-22 00:44:52506 chrome::NavigateParams params2(MakeNavigateParams(params1.browser));
507 params2.disposition = NEW_POPUP;
508 params2.window_bounds = gfx::Rect(0, 0, 200, 200);
509 chrome::Navigate(&params2);
[email protected]300d1e52011-01-19 23:57:57510
511 // Navigate() should have opened a new normal popup window.
meacerc62e2ee2014-10-22 00:44:52512 EXPECT_NE(params1.browser, params2.browser);
513 EXPECT_TRUE(params2.browser->is_type_popup());
514 EXPECT_FALSE(params2.browser->is_app());
[email protected]300d1e52011-01-19 23:57:57515
516 // We should have three windows, the browser() provided by the framework,
517 // the first popup window, and the second popup window.
[email protected]0665ebe2013-02-13 09:53:19518 EXPECT_EQ(3u, chrome::GetTotalBrowserCount());
[email protected]ee496952013-01-10 23:17:33519 EXPECT_EQ(1, browser()->tab_strip_model()->count());
meacerc62e2ee2014-10-22 00:44:52520 EXPECT_EQ(1, params1.browser->tab_strip_model()->count());
521 EXPECT_EQ(1, params2.browser->tab_strip_model()->count());
[email protected]300d1e52011-01-19 23:57:57522}
523
524// This test verifies that navigating with WindowOpenDisposition = NEW_POPUP
[email protected]d2202e22014-04-14 20:20:53525// from an app frame results in a new Browser with TYPE_POPUP.
[email protected]a1feae52010-10-11 22:14:45526IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
527 Disposition_NewPopupFromAppWindow) {
[email protected]d2202e22014-04-14 20:20:53528 Browser* app_browser = CreateEmptyBrowserForApp(browser()->profile());
meacerc62e2ee2014-10-22 00:44:52529 chrome::NavigateParams params(MakeNavigateParams(app_browser));
530 params.disposition = NEW_POPUP;
531 params.window_bounds = gfx::Rect(0, 0, 200, 200);
532 chrome::Navigate(&params);
[email protected]a1feae52010-10-11 22:14:45533
534 // Navigate() should have opened a new popup app window.
meacerc62e2ee2014-10-22 00:44:52535 EXPECT_NE(app_browser, params.browser);
536 EXPECT_NE(browser(), params.browser);
537 EXPECT_TRUE(params.browser->is_type_popup());
538 EXPECT_TRUE(params.browser->is_app());
[email protected]a1feae52010-10-11 22:14:45539
540 // We should now have three windows, the app window, the app popup it created,
541 // and the original browser() provided by the framework.
[email protected]0665ebe2013-02-13 09:53:19542 EXPECT_EQ(3u, chrome::GetTotalBrowserCount());
[email protected]ee496952013-01-10 23:17:33543 EXPECT_EQ(1, browser()->tab_strip_model()->count());
544 EXPECT_EQ(1, app_browser->tab_strip_model()->count());
meacerc62e2ee2014-10-22 00:44:52545 EXPECT_EQ(1, params.browser->tab_strip_model()->count());
[email protected]a1feae52010-10-11 22:14:45546}
547
548// This test verifies that navigating with WindowOpenDisposition = NEW_POPUP
[email protected]d2202e22014-04-14 20:20:53549// from an app popup results in a new Browser also of TYPE_POPUP.
[email protected]300d1e52011-01-19 23:57:57550IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
551 Disposition_NewPopupFromAppPopup) {
[email protected]d2202e22014-04-14 20:20:53552 Browser* app_browser = CreateEmptyBrowserForApp(browser()->profile());
[email protected]300d1e52011-01-19 23:57:57553 // Open an app popup.
meacerc62e2ee2014-10-22 00:44:52554 chrome::NavigateParams params1(MakeNavigateParams(app_browser));
555 params1.disposition = NEW_POPUP;
556 params1.window_bounds = gfx::Rect(0, 0, 200, 200);
557 chrome::Navigate(&params1);
[email protected]300d1e52011-01-19 23:57:57558 // Now open another app popup.
meacerc62e2ee2014-10-22 00:44:52559 chrome::NavigateParams params2(MakeNavigateParams(params1.browser));
560 params2.disposition = NEW_POPUP;
561 params2.window_bounds = gfx::Rect(0, 0, 200, 200);
562 chrome::Navigate(&params2);
[email protected]300d1e52011-01-19 23:57:57563
564 // Navigate() should have opened a new popup app window.
meacerc62e2ee2014-10-22 00:44:52565 EXPECT_NE(browser(), params1.browser);
566 EXPECT_NE(params1.browser, params2.browser);
567 EXPECT_TRUE(params2.browser->is_type_popup());
568 EXPECT_TRUE(params2.browser->is_app());
[email protected]300d1e52011-01-19 23:57:57569
570 // We should now have four windows, the app window, the first app popup,
571 // the second app popup, and the original browser() provided by the framework.
[email protected]0665ebe2013-02-13 09:53:19572 EXPECT_EQ(4u, chrome::GetTotalBrowserCount());
[email protected]ee496952013-01-10 23:17:33573 EXPECT_EQ(1, browser()->tab_strip_model()->count());
574 EXPECT_EQ(1, app_browser->tab_strip_model()->count());
meacerc62e2ee2014-10-22 00:44:52575 EXPECT_EQ(1, params1.browser->tab_strip_model()->count());
576 EXPECT_EQ(1, params2.browser->tab_strip_model()->count());
[email protected]300d1e52011-01-19 23:57:57577}
578
579// This test verifies that navigating with WindowOpenDisposition = NEW_POPUP
[email protected]a1feae52010-10-11 22:14:45580// from an extension app tab results in a new Browser with TYPE_APP_POPUP.
581IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
582 Disposition_NewPopupFromExtensionApp) {
583 // TODO(beng): TBD.
584}
585
[email protected]7d329992011-04-15 18:20:02586// This test verifies that navigating with window_action = SHOW_WINDOW_INACTIVE
587// does not focus a new new popup window.
588IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_NewPopupUnfocused) {
meacerc62e2ee2014-10-22 00:44:52589 chrome::NavigateParams params(MakeNavigateParams());
590 params.disposition = NEW_POPUP;
591 params.window_bounds = gfx::Rect(0, 0, 200, 200);
592 params.window_action = chrome::NavigateParams::SHOW_WINDOW_INACTIVE;
[email protected]7d329992011-04-15 18:20:02593 // Wait for new popup to load (and gain focus if the test fails).
meacerc62e2ee2014-10-22 00:44:52594 ui_test_utils::NavigateToURL(&params);
[email protected]7d329992011-04-15 18:20:02595
596 // Navigate() should have opened a new, unfocused, popup window.
meacerc62e2ee2014-10-22 00:44:52597 EXPECT_NE(browser(), params.browser);
598 EXPECT_EQ(Browser::TYPE_POPUP, params.browser->type());
[email protected]9db263a2011-04-15 20:53:47599#if 0
600// TODO(stevenjb): Enable this test. See: crbug.com/79493
[email protected]7d329992011-04-15 18:20:02601 EXPECT_FALSE(p.browser->window()->IsActive());
[email protected]7d329992011-04-15 18:20:02602#endif
[email protected]9db263a2011-04-15 20:53:47603}
[email protected]7d329992011-04-15 18:20:02604
[email protected]d2202e22014-04-14 20:20:53605// This test verifies that navigating with WindowOpenDisposition = NEW_POPUP
606// and trusted_source = true results in a new Browser where is_trusted_source()
607// is true.
608IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_NewPopupTrusted) {
meacerc62e2ee2014-10-22 00:44:52609 chrome::NavigateParams params(MakeNavigateParams());
610 params.disposition = NEW_POPUP;
611 params.trusted_source = true;
612 params.window_bounds = gfx::Rect(0, 0, 200, 200);
[email protected]d2202e22014-04-14 20:20:53613 // Wait for new popup to to load and gain focus.
meacerc62e2ee2014-10-22 00:44:52614 ui_test_utils::NavigateToURL(&params);
[email protected]d2202e22014-04-14 20:20:53615
616 // Navigate() should have opened a new popup window of TYPE_TRUSTED_POPUP.
meacerc62e2ee2014-10-22 00:44:52617 EXPECT_NE(browser(), params.browser);
618 EXPECT_TRUE(params.browser->is_type_popup());
619 EXPECT_TRUE(params.browser->is_trusted_source());
[email protected]d2202e22014-04-14 20:20:53620}
621
622
[email protected]a1feae52010-10-11 22:14:45623// This test verifies that navigating with WindowOpenDisposition = NEW_WINDOW
624// always opens a new window.
625IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_NewWindow) {
meacerc62e2ee2014-10-22 00:44:52626 chrome::NavigateParams params(MakeNavigateParams());
627 params.disposition = NEW_WINDOW;
628 chrome::Navigate(&params);
[email protected]a1feae52010-10-11 22:14:45629
630 // Navigate() should have opened a new toplevel window.
meacerc62e2ee2014-10-22 00:44:52631 EXPECT_NE(browser(), params.browser);
632 EXPECT_TRUE(params.browser->is_type_tabbed());
[email protected]a1feae52010-10-11 22:14:45633
634 // We should now have two windows, the browser() provided by the framework and
635 // the new normal window.
[email protected]0665ebe2013-02-13 09:53:19636 EXPECT_EQ(2u, chrome::GetTotalBrowserCount());
[email protected]ee496952013-01-10 23:17:33637 EXPECT_EQ(1, browser()->tab_strip_model()->count());
meacerc62e2ee2014-10-22 00:44:52638 EXPECT_EQ(1, params.browser->tab_strip_model()->count());
[email protected]a1feae52010-10-11 22:14:45639}
640
641// This test verifies that navigating with WindowOpenDisposition = INCOGNITO
642// opens a new incognito window if no existing incognito window is present.
643IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_Incognito) {
meacerc62e2ee2014-10-22 00:44:52644 chrome::NavigateParams params(MakeNavigateParams());
645 params.disposition = OFF_THE_RECORD;
646 chrome::Navigate(&params);
[email protected]a1feae52010-10-11 22:14:45647
648 // Navigate() should have opened a new toplevel incognito window.
meacerc62e2ee2014-10-22 00:44:52649 EXPECT_NE(browser(), params.browser);
[email protected]a1feae52010-10-11 22:14:45650 EXPECT_EQ(browser()->profile()->GetOffTheRecordProfile(),
meacerc62e2ee2014-10-22 00:44:52651 params.browser->profile());
[email protected]a1feae52010-10-11 22:14:45652
[email protected]d7ff3592010-11-30 21:50:46653 // |source_contents| should be set to NULL because the profile for the new
654 // page is different from the originating page.
meacerc62e2ee2014-10-22 00:44:52655 EXPECT_EQ(NULL, params.source_contents);
[email protected]d7ff3592010-11-30 21:50:46656
[email protected]a1feae52010-10-11 22:14:45657 // We should now have two windows, the browser() provided by the framework and
658 // the new incognito window.
[email protected]0665ebe2013-02-13 09:53:19659 EXPECT_EQ(2u, chrome::GetTotalBrowserCount());
[email protected]ee496952013-01-10 23:17:33660 EXPECT_EQ(1, browser()->tab_strip_model()->count());
meacerc62e2ee2014-10-22 00:44:52661 EXPECT_EQ(1, params.browser->tab_strip_model()->count());
[email protected]a1feae52010-10-11 22:14:45662}
663
664// This test verifies that navigating with WindowOpenDisposition = INCOGNITO
665// reuses an existing incognito window when possible.
666IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_IncognitoRefocus) {
667 Browser* incognito_browser =
[email protected]b35b26b32011-05-05 20:35:14668 CreateEmptyBrowserForType(Browser::TYPE_TABBED,
[email protected]a1feae52010-10-11 22:14:45669 browser()->profile()->GetOffTheRecordProfile());
meacerc62e2ee2014-10-22 00:44:52670 chrome::NavigateParams params(MakeNavigateParams());
671 params.disposition = OFF_THE_RECORD;
672 chrome::Navigate(&params);
[email protected]a1feae52010-10-11 22:14:45673
674 // Navigate() should have opened a new tab in the existing incognito window.
meacerc62e2ee2014-10-22 00:44:52675 EXPECT_NE(browser(), params.browser);
676 EXPECT_EQ(params.browser, incognito_browser);
[email protected]a1feae52010-10-11 22:14:45677
678 // We should now have two windows, the browser() provided by the framework and
679 // the incognito window we opened earlier.
[email protected]0665ebe2013-02-13 09:53:19680 EXPECT_EQ(2u, chrome::GetTotalBrowserCount());
[email protected]ee496952013-01-10 23:17:33681 EXPECT_EQ(1, browser()->tab_strip_model()->count());
682 EXPECT_EQ(2, incognito_browser->tab_strip_model()->count());
[email protected]a1feae52010-10-11 22:14:45683}
684
685// This test verifies that no navigation action occurs when
686// WindowOpenDisposition = SUPPRESS_OPEN.
687IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_SuppressOpen) {
688 RunSuppressTest(SUPPRESS_OPEN);
689}
690
691// This test verifies that no navigation action occurs when
692// WindowOpenDisposition = SAVE_TO_DISK.
693IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_SaveToDisk) {
694 RunSuppressTest(SAVE_TO_DISK);
695}
696
697// This test verifies that no navigation action occurs when
698// WindowOpenDisposition = IGNORE_ACTION.
699IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_IgnoreAction) {
700 RunSuppressTest(IGNORE_ACTION);
701}
702
[email protected]e232c992012-12-06 12:43:20703// This tests adding a foreground tab with a predefined WebContents.
[email protected]a1feae52010-10-11 22:14:45704IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, TargetContents_ForegroundTab) {
meacerc62e2ee2014-10-22 00:44:52705 chrome::NavigateParams params(MakeNavigateParams());
706 params.disposition = NEW_FOREGROUND_TAB;
707 params.target_contents = CreateWebContents();
708 chrome::Navigate(&params);
[email protected]a1feae52010-10-11 22:14:45709
710 // Navigate() should have opened the contents in a new foreground in the
711 // current Browser.
meacerc62e2ee2014-10-22 00:44:52712 EXPECT_EQ(browser(), params.browser);
[email protected]e232c992012-12-06 12:43:20713 EXPECT_EQ(browser()->tab_strip_model()->GetActiveWebContents(),
meacerc62e2ee2014-10-22 00:44:52714 params.target_contents);
[email protected]a1feae52010-10-11 22:14:45715
716 // We should have one window, with two tabs.
[email protected]0665ebe2013-02-13 09:53:19717 EXPECT_EQ(1u, chrome::GetTotalBrowserCount());
[email protected]ee496952013-01-10 23:17:33718 EXPECT_EQ(2, browser()->tab_strip_model()->count());
[email protected]a1feae52010-10-11 22:14:45719}
720
721#if defined(OS_WIN)
[email protected]e232c992012-12-06 12:43:20722// This tests adding a popup with a predefined WebContents.
[email protected]76edb672011-03-04 21:48:39723IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, DISABLED_TargetContents_Popup) {
meacerc62e2ee2014-10-22 00:44:52724 chrome::NavigateParams params(MakeNavigateParams());
725 params.disposition = NEW_POPUP;
726 params.target_contents = CreateWebContents();
727 params.window_bounds = gfx::Rect(10, 10, 500, 500);
728 chrome::Navigate(&params);
[email protected]a1feae52010-10-11 22:14:45729
730 // Navigate() should have opened a new popup window.
meacerc62e2ee2014-10-22 00:44:52731 EXPECT_NE(browser(), params.browser);
732 EXPECT_TRUE(params.browser->is_type_popup());
733 EXPECT_FALSE(params.browser->is_app());
[email protected]a1feae52010-10-11 22:14:45734
735 // The web platform is weird. The window bounds specified in
meacerc62e2ee2014-10-22 00:44:52736 // |params.window_bounds| are used as follows:
[email protected]a1feae52010-10-11 22:14:45737 // - the origin is used to position the window
[email protected]e232c992012-12-06 12:43:20738 // - the size is used to size the WebContents of the window.
[email protected]a1feae52010-10-11 22:14:45739 // As such the position of the resulting window will always match
meacerc62e2ee2014-10-22 00:44:52740 // params.window_bounds.origin(), but its size will not. We need to match
[email protected]a1feae52010-10-11 22:14:45741 // the size against the selected tab's view's container size.
meacerc62e2ee2014-10-22 00:44:52742 // Only Windows positions the window according to
743 // |params.window_bounds.origin()| - on Mac the window is offset from the
744 // opener and on Linux it always opens at 0,0.
745 EXPECT_EQ(params.window_bounds.origin(),
746 params.browser->window()->GetRestoredBounds().origin());
[email protected]a1feae52010-10-11 22:14:45747 // All platforms should respect size however provided width > 400 (Mac has a
748 // minimum window width of 400).
meacerc62e2ee2014-10-22 00:44:52749 EXPECT_EQ(params.window_bounds.size(),
750 params.target_contents->GetContainerBounds().size());
[email protected]a1feae52010-10-11 22:14:45751
752 // We should have two windows, the new popup and the browser() provided by the
753 // framework.
[email protected]0665ebe2013-02-13 09:53:19754 EXPECT_EQ(2u, chrome::GetTotalBrowserCount());
[email protected]ee496952013-01-10 23:17:33755 EXPECT_EQ(1, browser()->tab_strip_model()->count());
meacerc62e2ee2014-10-22 00:44:52756 EXPECT_EQ(1, params.browser->tab_strip_model()->count());
[email protected]a1feae52010-10-11 22:14:45757}
758#endif
759
760// This tests adding a tab at a specific index.
761IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Tabstrip_InsertAtIndex) {
762 // This is not meant to be a comprehensive test of whether or not the tab
763 // implementation of the browser observes the insertion index. That is
764 // covered by the unit tests for TabStripModel. This merely verifies that
765 // insertion index preference is reflected in common cases.
meacerc62e2ee2014-10-22 00:44:52766 chrome::NavigateParams params(MakeNavigateParams());
767 params.disposition = NEW_FOREGROUND_TAB;
768 params.tabstrip_index = 0;
769 params.tabstrip_add_types = TabStripModel::ADD_FORCE_INDEX;
770 chrome::Navigate(&params);
[email protected]a1feae52010-10-11 22:14:45771
772 // Navigate() should have inserted a new tab at slot 0 in the tabstrip.
meacerc62e2ee2014-10-22 00:44:52773 EXPECT_EQ(browser(), params.browser);
[email protected]e232c992012-12-06 12:43:20774 EXPECT_EQ(0, browser()->tab_strip_model()->GetIndexOfWebContents(
meacerc62e2ee2014-10-22 00:44:52775 static_cast<const WebContents*>(params.target_contents)));
[email protected]a1feae52010-10-11 22:14:45776
777 // We should have one window - the browser() provided by the framework.
[email protected]0665ebe2013-02-13 09:53:19778 EXPECT_EQ(1u, chrome::GetTotalBrowserCount());
[email protected]ee496952013-01-10 23:17:33779 EXPECT_EQ(2, browser()->tab_strip_model()->count());
[email protected]a1feae52010-10-11 22:14:45780}
781
[email protected]bb89e7482010-11-17 18:27:04782// This test verifies that constructing params with disposition = SINGLETON_TAB
[email protected]fee320542011-03-02 01:30:49783// and IGNORE_AND_NAVIGATE opens a new tab navigated to the specified URL if
[email protected]67ed83e2011-01-07 22:54:00784// no previous tab with that URL (minus the path) exists.
[email protected]bb89e7482010-11-17 18:27:04785IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
786 Disposition_SingletonTabNew_IgnorePath) {
[email protected]52877dbc62012-06-29 22:22:03787 chrome::AddSelectedTabWithURL(browser(), GetGoogleURL(),
Sylvain Defresnec6ccc77d2014-09-19 10:19:35788 ui::PAGE_TRANSITION_LINK);
[email protected]bb89e7482010-11-17 18:27:04789
790 // We should have one browser with 2 tabs, the 2nd selected.
[email protected]0665ebe2013-02-13 09:53:19791 EXPECT_EQ(1u, chrome::GetTotalBrowserCount());
[email protected]ee496952013-01-10 23:17:33792 EXPECT_EQ(2, browser()->tab_strip_model()->count());
793 EXPECT_EQ(1, browser()->tab_strip_model()->active_index());
[email protected]bb89e7482010-11-17 18:27:04794
795 // Navigate to a new singleton tab with a sub-page.
meacerc62e2ee2014-10-22 00:44:52796 chrome::NavigateParams params(MakeNavigateParams());
797 params.disposition = SINGLETON_TAB;
798 params.url = GetContentSettingsURL();
799 params.window_action = chrome::NavigateParams::SHOW_WINDOW;
800 params.path_behavior = chrome::NavigateParams::IGNORE_AND_NAVIGATE;
801 chrome::Navigate(&params);
[email protected]bb89e7482010-11-17 18:27:04802
803 // The last tab should now be selected and navigated to the sub-page of the
[email protected]50592b52013-05-02 22:26:25804 // URL.
meacerc62e2ee2014-10-22 00:44:52805 EXPECT_EQ(browser(), params.browser);
[email protected]ee496952013-01-10 23:17:33806 EXPECT_EQ(3, browser()->tab_strip_model()->count());
807 EXPECT_EQ(2, browser()->tab_strip_model()->active_index());
[email protected]a048ad22012-03-23 04:26:56808 EXPECT_EQ(GetContentSettingsURL(),
[email protected]ee496952013-01-10 23:17:33809 ShortenUberURL(browser()->tab_strip_model()->
810 GetActiveWebContents()->GetURL()));
[email protected]bb89e7482010-11-17 18:27:04811}
812
813// This test verifies that constructing params with disposition = SINGLETON_TAB
[email protected]fee320542011-03-02 01:30:49814// and IGNORE_AND_NAVIGATE opens an existing tab with the matching URL (minus
[email protected]bb89e7482010-11-17 18:27:04815// the path) which is navigated to the specified URL.
816IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
817 Disposition_SingletonTabExisting_IgnorePath) {
[email protected]ddddfda2011-07-14 23:19:39818 GURL singleton_url1(GetSettingsURL());
[email protected]52877dbc62012-06-29 22:22:03819 chrome::AddSelectedTabWithURL(browser(), singleton_url1,
Sylvain Defresnec6ccc77d2014-09-19 10:19:35820 ui::PAGE_TRANSITION_LINK);
[email protected]52877dbc62012-06-29 22:22:03821 chrome::AddSelectedTabWithURL(browser(), GetGoogleURL(),
Sylvain Defresnec6ccc77d2014-09-19 10:19:35822 ui::PAGE_TRANSITION_LINK);
[email protected]bb89e7482010-11-17 18:27:04823
824 // We should have one browser with 3 tabs, the 3rd selected.
[email protected]0665ebe2013-02-13 09:53:19825 EXPECT_EQ(1u, chrome::GetTotalBrowserCount());
[email protected]ee496952013-01-10 23:17:33826 EXPECT_EQ(3, browser()->tab_strip_model()->count());
827 EXPECT_EQ(2, browser()->tab_strip_model()->active_index());
[email protected]bb89e7482010-11-17 18:27:04828
829 // Navigate to singleton_url1.
meacerc62e2ee2014-10-22 00:44:52830 chrome::NavigateParams params(MakeNavigateParams());
831 params.disposition = SINGLETON_TAB;
832 params.url = GetContentSettingsURL();
833 params.window_action = chrome::NavigateParams::SHOW_WINDOW;
834 params.path_behavior = chrome::NavigateParams::IGNORE_AND_NAVIGATE;
835 chrome::Navigate(&params);
[email protected]bb89e7482010-11-17 18:27:04836
837 // The middle tab should now be selected and navigated to the sub-page of the
838 // URL.
meacerc62e2ee2014-10-22 00:44:52839 EXPECT_EQ(browser(), params.browser);
[email protected]ee496952013-01-10 23:17:33840 EXPECT_EQ(3, browser()->tab_strip_model()->count());
841 EXPECT_EQ(1, browser()->tab_strip_model()->active_index());
[email protected]a048ad22012-03-23 04:26:56842 EXPECT_EQ(GetContentSettingsURL(),
[email protected]ee496952013-01-10 23:17:33843 ShortenUberURL(browser()->tab_strip_model()->
844 GetActiveWebContents()->GetURL()));
[email protected]bb89e7482010-11-17 18:27:04845}
846
847// This test verifies that constructing params with disposition = SINGLETON_TAB
[email protected]fee320542011-03-02 01:30:49848// and IGNORE_AND_NAVIGATE opens an existing tab with the matching URL (minus
[email protected]bb89e7482010-11-17 18:27:04849// the path) which is navigated to the specified URL.
850IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
851 Disposition_SingletonTabExistingSubPath_IgnorePath) {
[email protected]a048ad22012-03-23 04:26:56852 GURL singleton_url1(GetContentSettingsURL());
[email protected]52877dbc62012-06-29 22:22:03853 chrome::AddSelectedTabWithURL(browser(), singleton_url1,
Sylvain Defresnec6ccc77d2014-09-19 10:19:35854 ui::PAGE_TRANSITION_LINK);
[email protected]52877dbc62012-06-29 22:22:03855 chrome::AddSelectedTabWithURL(browser(), GetGoogleURL(),
Sylvain Defresnec6ccc77d2014-09-19 10:19:35856 ui::PAGE_TRANSITION_LINK);
[email protected]bb89e7482010-11-17 18:27:04857
858 // We should have one browser with 3 tabs, the 3rd selected.
[email protected]0665ebe2013-02-13 09:53:19859 EXPECT_EQ(1u, chrome::GetTotalBrowserCount());
[email protected]ee496952013-01-10 23:17:33860 EXPECT_EQ(3, browser()->tab_strip_model()->count());
861 EXPECT_EQ(2, browser()->tab_strip_model()->active_index());
[email protected]bb89e7482010-11-17 18:27:04862
863 // Navigate to singleton_url1.
meacerc62e2ee2014-10-22 00:44:52864 chrome::NavigateParams params(MakeNavigateParams());
865 params.disposition = SINGLETON_TAB;
866 params.url = GetClearBrowsingDataURL();
867 params.window_action = chrome::NavigateParams::SHOW_WINDOW;
868 params.path_behavior = chrome::NavigateParams::IGNORE_AND_NAVIGATE;
869 chrome::Navigate(&params);
[email protected]bb89e7482010-11-17 18:27:04870
871 // The middle tab should now be selected and navigated to the sub-page of the
872 // URL.
meacerc62e2ee2014-10-22 00:44:52873 EXPECT_EQ(browser(), params.browser);
[email protected]ee496952013-01-10 23:17:33874 EXPECT_EQ(3, browser()->tab_strip_model()->count());
875 EXPECT_EQ(1, browser()->tab_strip_model()->active_index());
[email protected]a048ad22012-03-23 04:26:56876 EXPECT_EQ(GetClearBrowsingDataURL(),
[email protected]ee496952013-01-10 23:17:33877 ShortenUberURL(browser()->tab_strip_model()->
878 GetActiveWebContents()->GetURL()));
[email protected]bb89e7482010-11-17 18:27:04879}
[email protected]2dd85482010-11-06 01:56:47880
[email protected]637b3442011-01-10 23:31:48881// This test verifies that constructing params with disposition = SINGLETON_TAB
[email protected]fee320542011-03-02 01:30:49882// and IGNORE_AND_STAY_PUT opens an existing tab with the matching URL (minus
883// the path).
884IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
885 Disposition_SingletonTabExistingSubPath_IgnorePath2) {
[email protected]a048ad22012-03-23 04:26:56886 GURL singleton_url1(GetContentSettingsURL());
[email protected]52877dbc62012-06-29 22:22:03887 chrome::AddSelectedTabWithURL(browser(), singleton_url1,
Sylvain Defresnec6ccc77d2014-09-19 10:19:35888 ui::PAGE_TRANSITION_LINK);
[email protected]52877dbc62012-06-29 22:22:03889 chrome::AddSelectedTabWithURL(browser(), GetGoogleURL(),
Sylvain Defresnec6ccc77d2014-09-19 10:19:35890 ui::PAGE_TRANSITION_LINK);
[email protected]fee320542011-03-02 01:30:49891
892 // We should have one browser with 3 tabs, the 3rd selected.
[email protected]0665ebe2013-02-13 09:53:19893 EXPECT_EQ(1u, chrome::GetTotalBrowserCount());
[email protected]ee496952013-01-10 23:17:33894 EXPECT_EQ(3, browser()->tab_strip_model()->count());
895 EXPECT_EQ(2, browser()->tab_strip_model()->active_index());
[email protected]fee320542011-03-02 01:30:49896
897 // Navigate to singleton_url1.
meacerc62e2ee2014-10-22 00:44:52898 chrome::NavigateParams params(MakeNavigateParams());
899 params.disposition = SINGLETON_TAB;
900 params.url = GetClearBrowsingDataURL();
901 params.window_action = chrome::NavigateParams::SHOW_WINDOW;
902 params.path_behavior = chrome::NavigateParams::IGNORE_AND_STAY_PUT;
903 chrome::Navigate(&params);
[email protected]fee320542011-03-02 01:30:49904
905 // The middle tab should now be selected.
meacerc62e2ee2014-10-22 00:44:52906 EXPECT_EQ(browser(), params.browser);
[email protected]ee496952013-01-10 23:17:33907 EXPECT_EQ(3, browser()->tab_strip_model()->count());
908 EXPECT_EQ(1, browser()->tab_strip_model()->active_index());
[email protected]fee320542011-03-02 01:30:49909 EXPECT_EQ(singleton_url1,
[email protected]ee496952013-01-10 23:17:33910 ShortenUberURL(browser()->tab_strip_model()->
911 GetActiveWebContents()->GetURL()));
[email protected]fee320542011-03-02 01:30:49912}
913
914// This test verifies that constructing params with disposition = SINGLETON_TAB
915// and IGNORE_AND_NAVIGATE will update the current tab's URL if the currently
[email protected]637b3442011-01-10 23:31:48916// selected tab is a match but has a different path.
917IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
918 Disposition_SingletonTabFocused_IgnorePath) {
[email protected]a048ad22012-03-23 04:26:56919 GURL singleton_url_current(GetContentSettingsURL());
[email protected]52877dbc62012-06-29 22:22:03920 chrome::AddSelectedTabWithURL(browser(), singleton_url_current,
Sylvain Defresnec6ccc77d2014-09-19 10:19:35921 ui::PAGE_TRANSITION_LINK);
[email protected]637b3442011-01-10 23:31:48922
923 // We should have one browser with 2 tabs, the 2nd selected.
[email protected]0665ebe2013-02-13 09:53:19924 EXPECT_EQ(1u, chrome::GetTotalBrowserCount());
[email protected]ee496952013-01-10 23:17:33925 EXPECT_EQ(2, browser()->tab_strip_model()->count());
926 EXPECT_EQ(1, browser()->tab_strip_model()->active_index());
[email protected]637b3442011-01-10 23:31:48927
928 // Navigate to a different settings path.
[email protected]a048ad22012-03-23 04:26:56929 GURL singleton_url_target(GetClearBrowsingDataURL());
meacerc62e2ee2014-10-22 00:44:52930 chrome::NavigateParams params(MakeNavigateParams());
931 params.disposition = SINGLETON_TAB;
932 params.url = singleton_url_target;
933 params.window_action = chrome::NavigateParams::SHOW_WINDOW;
934 params.path_behavior = chrome::NavigateParams::IGNORE_AND_NAVIGATE;
935 chrome::Navigate(&params);
[email protected]637b3442011-01-10 23:31:48936
937 // The second tab should still be selected, but navigated to the new path.
meacerc62e2ee2014-10-22 00:44:52938 EXPECT_EQ(browser(), params.browser);
[email protected]ee496952013-01-10 23:17:33939 EXPECT_EQ(2, browser()->tab_strip_model()->count());
940 EXPECT_EQ(1, browser()->tab_strip_model()->active_index());
[email protected]637b3442011-01-10 23:31:48941 EXPECT_EQ(singleton_url_target,
[email protected]ee496952013-01-10 23:17:33942 ShortenUberURL(browser()->tab_strip_model()->
943 GetActiveWebContents()->GetURL()));
[email protected]637b3442011-01-10 23:31:48944}
945
[email protected]07afd7c2011-02-17 10:07:11946// This test verifies that constructing params with disposition = SINGLETON_TAB
[email protected]fee320542011-03-02 01:30:49947// and IGNORE_AND_NAVIGATE will open an existing matching tab with a different
948// query.
[email protected]07afd7c2011-02-17 10:07:11949IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
950 Disposition_SingletonTabExisting_IgnoreQuery) {
[email protected]ee496952013-01-10 23:17:33951 int initial_tab_count = browser()->tab_strip_model()->count();
[email protected]07afd7c2011-02-17 10:07:11952 GURL singleton_url_current("chrome://settings/internet");
[email protected]52877dbc62012-06-29 22:22:03953 chrome::AddSelectedTabWithURL(browser(), singleton_url_current,
Sylvain Defresnec6ccc77d2014-09-19 10:19:35954 ui::PAGE_TRANSITION_LINK);
[email protected]07afd7c2011-02-17 10:07:11955
[email protected]ee496952013-01-10 23:17:33956 EXPECT_EQ(initial_tab_count + 1, browser()->tab_strip_model()->count());
957 EXPECT_EQ(initial_tab_count, browser()->tab_strip_model()->active_index());
[email protected]07afd7c2011-02-17 10:07:11958
959 // Navigate to a different settings path.
960 GURL singleton_url_target(
961 "chrome://settings/internet?"
stevenjb82dbc53092015-03-14 18:32:24962 "guid=ethernet_00aa00aa00aa&networkType=1");
meacerc62e2ee2014-10-22 00:44:52963 chrome::NavigateParams params(MakeNavigateParams());
964 params.disposition = SINGLETON_TAB;
965 params.url = singleton_url_target;
966 params.window_action = chrome::NavigateParams::SHOW_WINDOW;
967 params.path_behavior = chrome::NavigateParams::IGNORE_AND_NAVIGATE;
968 chrome::Navigate(&params);
[email protected]07afd7c2011-02-17 10:07:11969
970 // Last tab should still be selected.
meacerc62e2ee2014-10-22 00:44:52971 EXPECT_EQ(browser(), params.browser);
[email protected]ee496952013-01-10 23:17:33972 EXPECT_EQ(initial_tab_count + 1, browser()->tab_strip_model()->count());
973 EXPECT_EQ(initial_tab_count, browser()->tab_strip_model()->active_index());
[email protected]07afd7c2011-02-17 10:07:11974}
975
[email protected]bd817c22011-02-09 08:16:46976// This test verifies that the settings page isn't opened in the incognito
977// window.
[email protected]a048ad22012-03-23 04:26:56978// Disabled until fixed for uber settings: http://crbug.com/111243
[email protected]bd817c22011-02-09 08:16:46979IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
[email protected]a048ad22012-03-23 04:26:56980 DISABLED_Disposition_Settings_UseNonIncognitoWindow) {
[email protected]fc0ed302011-11-29 23:17:19981 RunUseNonIncognitoWindowTest(GetSettingsURL());
[email protected]bd817c22011-02-09 08:16:46982}
983
[email protected]429e9712013-04-30 09:35:50984// This test verifies that the view-source settings page isn't opened in the
985// incognito window.
986IN_PROC_BROWSER_TEST_F(
987 BrowserNavigatorTest,
988 Disposition_ViewSource_Settings_DoNothingIfIncognitoForced) {
[email protected]dbdda5402013-05-30 22:13:48989 std::string view_source(content::kViewSourceScheme);
[email protected]429e9712013-04-30 09:35:50990 view_source.append(":");
991 view_source.append(chrome::kChromeUISettingsURL);
992 RunDoNothingIfIncognitoIsForcedTest(GURL(view_source));
993}
994
995// This test verifies that the view-source settings page isn't opened in the
996// incognito window even if incognito mode is forced (does nothing in that
997// case).
998IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
999 Disposition_ViewSource_Settings_UseNonIncognitoWindow) {
[email protected]dbdda5402013-05-30 22:13:481000 std::string view_source(content::kViewSourceScheme);
[email protected]429e9712013-04-30 09:35:501001 view_source.append(":");
1002 view_source.append(chrome::kChromeUISettingsURL);
1003 RunUseNonIncognitoWindowTest(GURL(view_source));
1004}
1005
[email protected]82404cd2011-07-12 19:55:141006// This test verifies that the settings page isn't opened in the incognito
1007// window from a non-incognito window (bookmark open-in-incognito trigger).
[email protected]a048ad22012-03-23 04:26:561008// Disabled until fixed for uber settings: http://crbug.com/111243
[email protected]82404cd2011-07-12 19:55:141009IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
[email protected]a048ad22012-03-23 04:26:561010 DISABLED_Disposition_Settings_UseNonIncognitoWindowForBookmark) {
[email protected]78e2edc2012-07-01 23:32:281011 chrome::NavigateParams params(browser(), GetSettingsURL(),
Sylvain Defresnec6ccc77d2014-09-19 10:19:351012 ui::PAGE_TRANSITION_AUTO_BOOKMARK);
[email protected]82404cd2011-07-12 19:55:141013 params.disposition = OFF_THE_RECORD;
1014 {
[email protected]a7fe9112012-07-20 02:34:451015 content::WindowedNotificationObserver observer(
[email protected]ad50def52011-10-19 23:17:071016 content::NOTIFICATION_LOAD_STOP,
1017 content::NotificationService::AllSources());
[email protected]78e2edc2012-07-01 23:32:281018 chrome::Navigate(&params);
[email protected]82404cd2011-07-12 19:55:141019 observer.Wait();
1020 }
1021
[email protected]0665ebe2013-02-13 09:53:191022 EXPECT_EQ(1u, chrome::GetTotalBrowserCount());
[email protected]52877dbc62012-06-29 22:22:031023 EXPECT_EQ(GetSettingsURL(),
[email protected]ee496952013-01-10 23:17:331024 ShortenUberURL(browser()->tab_strip_model()->
1025 GetActiveWebContents()->GetURL()));
[email protected]82404cd2011-07-12 19:55:141026}
1027
[email protected]93ad8e1c2011-11-08 21:34:051028// Settings page is expected to always open in normal mode regardless
1029// of whether the user is trying to open it in incognito mode or not.
1030// This test verifies that if incognito mode is forced (by policy), settings
1031// page doesn't open at all.
[email protected]a048ad22012-03-23 04:26:561032// Disabled until fixed for uber settings: http://crbug.com/111243
[email protected]93ad8e1c2011-11-08 21:34:051033IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
[email protected]a048ad22012-03-23 04:26:561034 DISABLED_Disposition_Settings_DoNothingIfIncognitoIsForced) {
[email protected]fc0ed302011-11-29 23:17:191035 RunDoNothingIfIncognitoIsForcedTest(GetSettingsURL());
[email protected]93ad8e1c2011-11-08 21:34:051036}
1037
[email protected]bd817c22011-02-09 08:16:461038// This test verifies that the bookmarks page isn't opened in the incognito
1039// window.
1040IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
1041 Disposition_Bookmarks_UseNonIncognitoWindow) {
[email protected]fc0ed302011-11-29 23:17:191042 RunUseNonIncognitoWindowTest(GURL(chrome::kChromeUIBookmarksURL));
[email protected]bd817c22011-02-09 08:16:461043}
1044
[email protected]93ad8e1c2011-11-08 21:34:051045// Bookmark manager is expected to always open in normal mode regardless
1046// of whether the user is trying to open it in incognito mode or not.
1047// This test verifies that if incognito mode is forced (by policy), bookmark
1048// manager doesn't open at all.
1049IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
1050 Disposition_Bookmarks_DoNothingIfIncognitoIsForced) {
[email protected]fc0ed302011-11-29 23:17:191051 RunDoNothingIfIncognitoIsForcedTest(GURL(chrome::kChromeUIBookmarksURL));
1052}
[email protected]93ad8e1c2011-11-08 21:34:051053
[email protected]7de53c62011-05-13 06:44:161054// This test makes sure a crashed singleton tab reloads from a new navigation.
[email protected]c4c0c0a12014-07-23 17:06:021055// http://crbug.com/396371
[email protected]7de53c62011-05-13 06:44:161056IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
[email protected]c4c0c0a12014-07-23 17:06:021057 DISABLED_NavigateToCrashedSingletonTab) {
[email protected]a048ad22012-03-23 04:26:561058 GURL singleton_url(GetContentSettingsURL());
[email protected]5a1a52462012-11-15 03:35:161059 WebContents* web_contents = chrome::AddSelectedTabWithURL(
Sylvain Defresnec6ccc77d2014-09-19 10:19:351060 browser(), singleton_url, ui::PAGE_TRANSITION_LINK);
[email protected]7de53c62011-05-13 06:44:161061
1062 // We should have one browser with 2 tabs, the 2nd selected.
[email protected]0665ebe2013-02-13 09:53:191063 EXPECT_EQ(1u, chrome::GetTotalBrowserCount());
[email protected]ee496952013-01-10 23:17:331064 EXPECT_EQ(2, browser()->tab_strip_model()->count());
1065 EXPECT_EQ(1, browser()->tab_strip_model()->active_index());
[email protected]7de53c62011-05-13 06:44:161066
1067 // Kill the singleton tab.
[email protected]83ff91c2012-01-05 20:54:131068 web_contents->SetIsCrashed(base::TERMINATION_STATUS_PROCESS_CRASHED, -1);
1069 EXPECT_TRUE(web_contents->IsCrashed());
[email protected]7de53c62011-05-13 06:44:161070
meacerc62e2ee2014-10-22 00:44:521071 chrome::NavigateParams params(MakeNavigateParams());
1072 params.disposition = SINGLETON_TAB;
1073 params.url = singleton_url;
1074 params.window_action = chrome::NavigateParams::SHOW_WINDOW;
1075 params.path_behavior = chrome::NavigateParams::IGNORE_AND_NAVIGATE;
1076 ui_test_utils::NavigateToURL(&params);
[email protected]7de53c62011-05-13 06:44:161077
1078 // The tab should not be sad anymore.
[email protected]83ff91c2012-01-05 20:54:131079 EXPECT_FALSE(web_contents->IsCrashed());
[email protected]7de53c62011-05-13 06:44:161080}
1081
[email protected]fcca741b2011-06-17 22:46:371082IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
1083 NavigateFromDefaultToOptionsInSameTab) {
[email protected]ddddfda2011-07-14 23:19:391084 {
[email protected]a7fe9112012-07-20 02:34:451085 content::WindowedNotificationObserver observer(
[email protected]ad50def52011-10-19 23:17:071086 content::NOTIFICATION_LOAD_STOP,
1087 content::NotificationService::AllSources());
[email protected]5d9cace72012-06-21 16:07:121088 chrome::ShowSettings(browser());
[email protected]ddddfda2011-07-14 23:19:391089 observer.Wait();
1090 }
[email protected]ee496952013-01-10 23:17:331091 EXPECT_EQ(1, browser()->tab_strip_model()->count());
[email protected]52877dbc62012-06-29 22:22:031092 EXPECT_EQ(GetSettingsURL(),
[email protected]ee496952013-01-10 23:17:331093 ShortenUberURL(browser()->tab_strip_model()->
1094 GetActiveWebContents()->GetURL()));
[email protected]fcca741b2011-06-17 22:46:371095}
1096
1097IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
1098 NavigateFromBlankToOptionsInSameTab) {
meacerc62e2ee2014-10-22 00:44:521099 chrome::NavigateParams params(MakeNavigateParams());
1100 params.url = GURL(url::kAboutBlankURL);
1101 ui_test_utils::NavigateToURL(&params);
[email protected]fcca741b2011-06-17 22:46:371102
[email protected]ddddfda2011-07-14 23:19:391103 {
[email protected]a7fe9112012-07-20 02:34:451104 content::WindowedNotificationObserver observer(
[email protected]ad50def52011-10-19 23:17:071105 content::NOTIFICATION_LOAD_STOP,
1106 content::NotificationService::AllSources());
[email protected]5d9cace72012-06-21 16:07:121107 chrome::ShowSettings(browser());
[email protected]ddddfda2011-07-14 23:19:391108 observer.Wait();
1109 }
[email protected]ee496952013-01-10 23:17:331110 EXPECT_EQ(1, browser()->tab_strip_model()->count());
[email protected]52877dbc62012-06-29 22:22:031111 EXPECT_EQ(GetSettingsURL(),
[email protected]ee496952013-01-10 23:17:331112 ShortenUberURL(browser()->tab_strip_model()->
1113 GetActiveWebContents()->GetURL()));
[email protected]fcca741b2011-06-17 22:46:371114}
1115
1116IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
1117 NavigateFromNTPToOptionsInSameTab) {
meacerc62e2ee2014-10-22 00:44:521118 chrome::NavigateParams params(MakeNavigateParams());
1119 params.url = GURL(chrome::kChromeUINewTabURL);
1120 ui_test_utils::NavigateToURL(&params);
[email protected]ee496952013-01-10 23:17:331121 EXPECT_EQ(1, browser()->tab_strip_model()->count());
[email protected]27658f32013-11-14 03:20:371122 EXPECT_EQ(GURL(chrome::kChromeUINewTabURL),
1123 browser()->tab_strip_model()->GetActiveWebContents()->GetURL());
[email protected]fcca741b2011-06-17 22:46:371124
[email protected]ddddfda2011-07-14 23:19:391125 {
[email protected]a7fe9112012-07-20 02:34:451126 content::WindowedNotificationObserver observer(
[email protected]ad50def52011-10-19 23:17:071127 content::NOTIFICATION_LOAD_STOP,
1128 content::NotificationService::AllSources());
[email protected]5d9cace72012-06-21 16:07:121129 chrome::ShowSettings(browser());
[email protected]ddddfda2011-07-14 23:19:391130 observer.Wait();
1131 }
[email protected]ee496952013-01-10 23:17:331132 EXPECT_EQ(1, browser()->tab_strip_model()->count());
[email protected]52877dbc62012-06-29 22:22:031133 EXPECT_EQ(GetSettingsURL(),
[email protected]ee496952013-01-10 23:17:331134 ShortenUberURL(browser()->tab_strip_model()->
1135 GetActiveWebContents()->GetURL()));
[email protected]fcca741b2011-06-17 22:46:371136}
1137
1138IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
1139 NavigateFromPageToOptionsInNewTab) {
meacerc62e2ee2014-10-22 00:44:521140 chrome::NavigateParams params(MakeNavigateParams());
1141 ui_test_utils::NavigateToURL(&params);
[email protected]ee496952013-01-10 23:17:331142 EXPECT_EQ(GetGoogleURL(),
1143 browser()->tab_strip_model()->GetActiveWebContents()->GetURL());
[email protected]0665ebe2013-02-13 09:53:191144 EXPECT_EQ(1u, chrome::GetTotalBrowserCount());
[email protected]ee496952013-01-10 23:17:331145 EXPECT_EQ(1, browser()->tab_strip_model()->count());
[email protected]fcca741b2011-06-17 22:46:371146
[email protected]ddddfda2011-07-14 23:19:391147 {
[email protected]a7fe9112012-07-20 02:34:451148 content::WindowedNotificationObserver observer(
[email protected]ad50def52011-10-19 23:17:071149 content::NOTIFICATION_LOAD_STOP,
1150 content::NotificationService::AllSources());
[email protected]5d9cace72012-06-21 16:07:121151 chrome::ShowSettings(browser());
[email protected]ddddfda2011-07-14 23:19:391152 observer.Wait();
1153 }
[email protected]ee496952013-01-10 23:17:331154 EXPECT_EQ(2, browser()->tab_strip_model()->count());
[email protected]52877dbc62012-06-29 22:22:031155 EXPECT_EQ(GetSettingsURL(),
[email protected]ee496952013-01-10 23:17:331156 ShortenUberURL(browser()->tab_strip_model()->
1157 GetActiveWebContents()->GetURL()));
[email protected]fcca741b2011-06-17 22:46:371158}
1159
1160IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
1161 NavigateFromNTPToOptionsSingleton) {
[email protected]ddddfda2011-07-14 23:19:391162 {
[email protected]a7fe9112012-07-20 02:34:451163 content::WindowedNotificationObserver observer(
[email protected]ad50def52011-10-19 23:17:071164 content::NOTIFICATION_LOAD_STOP,
1165 content::NotificationService::AllSources());
[email protected]5d9cace72012-06-21 16:07:121166 chrome::ShowSettings(browser());
[email protected]ddddfda2011-07-14 23:19:391167 observer.Wait();
1168 }
[email protected]ee496952013-01-10 23:17:331169 EXPECT_EQ(1, browser()->tab_strip_model()->count());
[email protected]fcca741b2011-06-17 22:46:371170
[email protected]a37d4b02012-06-25 21:56:101171 chrome::NewTab(browser());
[email protected]ee496952013-01-10 23:17:331172 EXPECT_EQ(2, browser()->tab_strip_model()->count());
[email protected]fcca741b2011-06-17 22:46:371173
[email protected]ddddfda2011-07-14 23:19:391174 {
[email protected]a7fe9112012-07-20 02:34:451175 content::WindowedNotificationObserver observer(
[email protected]ad50def52011-10-19 23:17:071176 content::NOTIFICATION_LOAD_STOP,
1177 content::NotificationService::AllSources());
[email protected]5d9cace72012-06-21 16:07:121178 chrome::ShowSettings(browser());
[email protected]ddddfda2011-07-14 23:19:391179 observer.Wait();
1180 }
[email protected]ee496952013-01-10 23:17:331181 EXPECT_EQ(2, browser()->tab_strip_model()->count());
[email protected]52877dbc62012-06-29 22:22:031182 EXPECT_EQ(GetSettingsURL(),
[email protected]ee496952013-01-10 23:17:331183 ShortenUberURL(browser()->tab_strip_model()->
1184 GetActiveWebContents()->GetURL()));
[email protected]fcca741b2011-06-17 22:46:371185}
1186
1187IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
1188 NavigateFromNTPToOptionsPageInSameTab) {
[email protected]ddddfda2011-07-14 23:19:391189 {
[email protected]a7fe9112012-07-20 02:34:451190 content::WindowedNotificationObserver observer(
[email protected]ad50def52011-10-19 23:17:071191 content::NOTIFICATION_LOAD_STOP,
1192 content::NotificationService::AllSources());
[email protected]5d9cace72012-06-21 16:07:121193 chrome::ShowClearBrowsingDataDialog(browser());
[email protected]ddddfda2011-07-14 23:19:391194 observer.Wait();
1195 }
[email protected]ee496952013-01-10 23:17:331196 EXPECT_EQ(1, browser()->tab_strip_model()->count());
[email protected]a048ad22012-03-23 04:26:561197 EXPECT_EQ(GetClearBrowsingDataURL(),
[email protected]ee496952013-01-10 23:17:331198 browser()->tab_strip_model()->GetActiveWebContents()->GetURL());
[email protected]fcca741b2011-06-17 22:46:371199
[email protected]a37d4b02012-06-25 21:56:101200 chrome::NewTab(browser());
[email protected]ee496952013-01-10 23:17:331201 EXPECT_EQ(2, browser()->tab_strip_model()->count());
[email protected]fcca741b2011-06-17 22:46:371202
[email protected]ddddfda2011-07-14 23:19:391203 {
[email protected]a7fe9112012-07-20 02:34:451204 content::WindowedNotificationObserver observer(
[email protected]ad50def52011-10-19 23:17:071205 content::NOTIFICATION_LOAD_STOP,
1206 content::NotificationService::AllSources());
[email protected]5d9cace72012-06-21 16:07:121207 chrome::ShowClearBrowsingDataDialog(browser());
[email protected]ddddfda2011-07-14 23:19:391208 observer.Wait();
1209 }
[email protected]ee496952013-01-10 23:17:331210 EXPECT_EQ(2, browser()->tab_strip_model()->count());
[email protected]a048ad22012-03-23 04:26:561211 EXPECT_EQ(GetClearBrowsingDataURL(),
[email protected]ee496952013-01-10 23:17:331212 browser()->tab_strip_model()->GetActiveWebContents()->GetURL());
[email protected]fcca741b2011-06-17 22:46:371213}
1214
1215IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
[email protected]05912742013-03-12 00:29:151216 NavigateFromOtherTabToSingletonOptions) {
[email protected]ddddfda2011-07-14 23:19:391217 {
[email protected]a7fe9112012-07-20 02:34:451218 content::WindowedNotificationObserver observer(
[email protected]ad50def52011-10-19 23:17:071219 content::NOTIFICATION_LOAD_STOP,
1220 content::NotificationService::AllSources());
[email protected]5d9cace72012-06-21 16:07:121221 chrome::ShowSettings(browser());
[email protected]ddddfda2011-07-14 23:19:391222 observer.Wait();
1223 }
1224 {
[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]52877dbc62012-06-29 22:22:031228 chrome::AddSelectedTabWithURL(browser(), GetGoogleURL(),
Sylvain Defresnec6ccc77d2014-09-19 10:19:351229 ui::PAGE_TRANSITION_LINK);
[email protected]ddddfda2011-07-14 23:19:391230 observer.Wait();
1231 }
[email protected]fcca741b2011-06-17 22:46:371232
[email protected]05912742013-03-12 00:29:151233 // This load should simply cause a tab switch.
1234 chrome::ShowSettings(browser());
1235
[email protected]ee496952013-01-10 23:17:331236 EXPECT_EQ(2, browser()->tab_strip_model()->count());
[email protected]ddddfda2011-07-14 23:19:391237 EXPECT_EQ(GetSettingsURL(),
[email protected]ee496952013-01-10 23:17:331238 ShortenUberURL(browser()->tab_strip_model()->
1239 GetActiveWebContents()->GetURL()));
[email protected]fcca741b2011-06-17 22:46:371240}
1241
[email protected]4e78b2d2013-06-12 16:46:171242IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, CloseSingletonTab) {
[email protected]79717cf2013-02-28 18:40:361243 for (int i = 0; i < 2; ++i) {
1244 content::WindowedNotificationObserver observer(
1245 content::NOTIFICATION_LOAD_STOP,
1246 content::NotificationService::AllSources());
1247 chrome::AddSelectedTabWithURL(browser(), GetGoogleURL(),
Sylvain Defresnec6ccc77d2014-09-19 10:19:351248 ui::PAGE_TRANSITION_TYPED);
[email protected]79717cf2013-02-28 18:40:361249 observer.Wait();
1250 }
1251
1252 browser()->tab_strip_model()->ActivateTabAt(0, true);
1253
1254 {
1255 content::WindowedNotificationObserver observer(
1256 content::NOTIFICATION_LOAD_STOP,
1257 content::NotificationService::AllSources());
1258 chrome::ShowSettings(browser());
1259 observer.Wait();
1260 }
1261
1262 EXPECT_TRUE(browser()->tab_strip_model()->CloseWebContentsAt(
1263 2, TabStripModel::CLOSE_USER_GESTURE));
1264 EXPECT_EQ(0, browser()->tab_strip_model()->active_index());
1265}
1266
[email protected]a048ad22012-03-23 04:26:561267// TODO(csilv): Update this for uber page. http://crbug.com/111579.
[email protected]ddddfda2011-07-14 23:19:391268IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
[email protected]a048ad22012-03-23 04:26:561269 DISABLED_NavigateFromDefaultToHistoryInSameTab) {
[email protected]ddddfda2011-07-14 23:19:391270 {
[email protected]a7fe9112012-07-20 02:34:451271 content::WindowedNotificationObserver observer(
[email protected]ad50def52011-10-19 23:17:071272 content::NOTIFICATION_LOAD_STOP,
1273 content::NotificationService::AllSources());
[email protected]5d9cace72012-06-21 16:07:121274 chrome::ShowHistory(browser());
[email protected]ddddfda2011-07-14 23:19:391275 observer.Wait();
1276 }
[email protected]ee496952013-01-10 23:17:331277 EXPECT_EQ(1, browser()->tab_strip_model()->count());
[email protected]11e03fb2012-03-03 19:07:051278 EXPECT_EQ(GURL(chrome::kChromeUIHistoryFrameURL),
[email protected]ee496952013-01-10 23:17:331279 browser()->tab_strip_model()->GetActiveWebContents()->GetURL());
[email protected]ddddfda2011-07-14 23:19:391280}
1281
[email protected]953c2132013-02-23 05:56:051282// TODO(linux_aura) http://crbug.com/163931
1283#if defined(OS_LINUX) && !defined(OS_CHROMEOS) && defined(USE_AURA)
1284#define MAYBE_NavigateFromDefaultToBookmarksInSameTab DISABLED_NavigateFromDefaultToBookmarksInSameTab
1285#else
1286#define MAYBE_NavigateFromDefaultToBookmarksInSameTab NavigateFromDefaultToBookmarksInSameTab
1287#endif
[email protected]ddddfda2011-07-14 23:19:391288IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
[email protected]953c2132013-02-23 05:56:051289 MAYBE_NavigateFromDefaultToBookmarksInSameTab) {
[email protected]ddddfda2011-07-14 23:19:391290 {
[email protected]a7fe9112012-07-20 02:34:451291 content::WindowedNotificationObserver observer(
[email protected]ad50def52011-10-19 23:17:071292 content::NOTIFICATION_LOAD_STOP,
1293 content::NotificationService::AllSources());
[email protected]5d9cace72012-06-21 16:07:121294 chrome::ShowBookmarkManager(browser());
[email protected]ddddfda2011-07-14 23:19:391295 observer.Wait();
1296 }
[email protected]ee496952013-01-10 23:17:331297 EXPECT_EQ(1, browser()->tab_strip_model()->count());
brettw66d1b81b2015-07-06 19:29:401298 EXPECT_TRUE(base::StartsWith(
[email protected]bc16a252013-01-23 02:21:491299 browser()->tab_strip_model()->GetActiveWebContents()->GetURL().spec(),
brettw66d1b81b2015-07-06 19:29:401300 chrome::kChromeUIBookmarksURL, base::CompareCase::SENSITIVE));
[email protected]ddddfda2011-07-14 23:19:391301}
1302
1303IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
1304 NavigateFromDefaultToDownloadsInSameTab) {
1305 {
[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::ShowDownloads(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]ddddfda2011-07-14 23:19:391313 EXPECT_EQ(GURL(chrome::kChromeUIDownloadsURL),
[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]8fb16a82012-08-17 02:17:591317IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
1318 NavigateWithoutBrowser) {
1319 // First navigate using the profile of the existing browser window, and
1320 // check that the window is reused.
1321 chrome::NavigateParams params(browser()->profile(), GetGoogleURL(),
Sylvain Defresnec6ccc77d2014-09-19 10:19:351322 ui::PAGE_TRANSITION_LINK);
[email protected]8fb16a82012-08-17 02:17:591323 ui_test_utils::NavigateToURL(&params);
[email protected]0665ebe2013-02-13 09:53:191324 EXPECT_EQ(1u, chrome::GetTotalBrowserCount());
[email protected]8fb16a82012-08-17 02:17:591325
1326 // Now navigate using the incognito profile and check that a new window
1327 // is created.
1328 chrome::NavigateParams params_incognito(
1329 browser()->profile()->GetOffTheRecordProfile(),
Sylvain Defresnec6ccc77d2014-09-19 10:19:351330 GetGoogleURL(), ui::PAGE_TRANSITION_LINK);
[email protected]8fb16a82012-08-17 02:17:591331 ui_test_utils::NavigateToURL(&params_incognito);
[email protected]0665ebe2013-02-13 09:53:191332 EXPECT_EQ(2u, chrome::GetTotalBrowserCount());
[email protected]8fb16a82012-08-17 02:17:591333}
1334
[email protected]beb1d1192013-05-14 04:47:511335IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, ViewSourceIsntSingleton) {
1336 const std::string viewsource_ntp_url =
[email protected]dbdda5402013-05-30 22:13:481337 std::string(content::kViewSourceScheme) + ":" +
[email protected]beb1d1192013-05-14 04:47:511338 chrome::kChromeUIVersionURL;
1339
1340 chrome::NavigateParams viewsource_params(browser(),
1341 GURL(viewsource_ntp_url),
Sylvain Defresnec6ccc77d2014-09-19 10:19:351342 ui::PAGE_TRANSITION_LINK);
[email protected]beb1d1192013-05-14 04:47:511343 ui_test_utils::NavigateToURL(&viewsource_params);
1344
1345 chrome::NavigateParams singleton_params(browser(),
1346 GURL(chrome::kChromeUIVersionURL),
Sylvain Defresnec6ccc77d2014-09-19 10:19:351347 ui::PAGE_TRANSITION_LINK);
[email protected]beb1d1192013-05-14 04:47:511348 singleton_params.disposition = SINGLETON_TAB;
1349 EXPECT_EQ(-1, chrome::GetIndexOfSingletonTab(&singleton_params));
1350}
1351
[email protected]a2efc35d2013-08-03 23:17:251352// This test verifies that browser initiated navigations can send requests
1353// using POST.
1354IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
1355 SendBrowserInitiatedRequestUsingPOST) {
1356 // Uses a test sever to verify POST request.
svaldeza01f7d92015-11-18 17:47:561357 ASSERT_TRUE(embedded_test_server()->Start());
[email protected]a2efc35d2013-08-03 23:17:251358
1359 // Open a browser initiated POST request in new foreground tab.
[email protected]e9273e192013-12-11 17:51:491360 base::string16 expected_title(base::ASCIIToUTF16(kExpectedTitle));
[email protected]a2efc35d2013-08-03 23:17:251361 std::string post_data = kExpectedTitle;
[email protected]e9273e192013-12-11 17:51:491362 base::string16 title;
[email protected]a2efc35d2013-08-03 23:17:251363 ASSERT_TRUE(OpenPOSTURLInNewForegroundTabAndGetTitle(
svaldeza01f7d92015-11-18 17:47:561364 embedded_test_server()->GetURL(kEchoTitleCommand), post_data, true,
1365 &title));
[email protected]a2efc35d2013-08-03 23:17:251366 EXPECT_EQ(expected_title, title);
1367}
1368
1369// This test verifies that renderer initiated navigations can NOT send requests
1370// using POST.
1371IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
1372 SendRendererInitiatedRequestUsingPOST) {
1373 // Uses a test sever to verify POST request.
svaldeza01f7d92015-11-18 17:47:561374 ASSERT_TRUE(embedded_test_server()->Start());
[email protected]a2efc35d2013-08-03 23:17:251375
1376 // Open a renderer initiated POST request in new foreground tab.
[email protected]e9273e192013-12-11 17:51:491377 base::string16 expected_title(base::ASCIIToUTF16(kExpectedTitle));
[email protected]a2efc35d2013-08-03 23:17:251378 std::string post_data = kExpectedTitle;
[email protected]e9273e192013-12-11 17:51:491379 base::string16 title;
[email protected]a2efc35d2013-08-03 23:17:251380 ASSERT_TRUE(OpenPOSTURLInNewForegroundTabAndGetTitle(
svaldeza01f7d92015-11-18 17:47:561381 embedded_test_server()->GetURL(kEchoTitleCommand), post_data, false,
1382 &title));
[email protected]a2efc35d2013-08-03 23:17:251383 EXPECT_NE(expected_title, title);
1384}
1385
meacerc62e2ee2014-10-22 00:44:521386// This test navigates to a data URL that contains BiDi control
1387// characters. For security reasons, BiDi control chars should always be
1388// escaped in the URL but they should be unescaped in the loaded HTML.
1389IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
1390 NavigateToDataURLWithBiDiControlChars) {
1391 // Text in Arabic.
1392 std::string text = "\xD8\xA7\xD8\xAE\xD8\xAA\xD8\xA8\xD8\xA7\xD8\xB1";
1393 // Page title starts with RTL mark.
1394 std::string unescaped_title = "\xE2\x80\x8F" + text;
1395 std::string data_url = "data:text/html;charset=utf-8,<html><title>" +
1396 unescaped_title + "</title></html>";
1397 // BiDi control chars in URLs are always escaped, so the expected URL should
1398 // have the title with the escaped RTL mark.
1399 std::string escaped_title = "%E2%80%8F" + text;
1400 std::string expected_url = "data:text/html;charset=utf-8,<html><title>" +
1401 escaped_title + "</title></html>";
1402
1403 // Navigate to the page.
1404 chrome::NavigateParams params(MakeNavigateParams());
1405 params.disposition = NEW_FOREGROUND_TAB;
1406 params.url = GURL(data_url);
1407 params.window_action = chrome::NavigateParams::SHOW_WINDOW;
1408 ui_test_utils::NavigateToURL(&params);
1409
1410 base::string16 expected_title(base::UTF8ToUTF16(unescaped_title));
1411 EXPECT_TRUE(params.target_contents);
1412 EXPECT_EQ(expected_title, params.target_contents->GetTitle());
1413 // GURL always keeps non-ASCII characters escaped, but check them anyways.
1414 EXPECT_EQ(GURL(expected_url).spec(), params.target_contents->GetURL().spec());
1415 // Check the omnibox text. It should have escaped RTL with unescaped text.
1416 LocationBar* location_bar = browser()->window()->GetLocationBar();
1417 OmniboxView* omnibox_view = location_bar->GetOmniboxView();
1418 EXPECT_EQ(base::UTF8ToUTF16(expected_url), omnibox_view->GetText());
1419}
1420
[email protected]a2efc35d2013-08-03 23:17:251421} // namespace