blob: 65379eb466cef1f6dfc59d3cdcb60e8748ab19d4 [file] [log] [blame]
[email protected]8643e6d2012-01-18 20:26:101// Copyright (c) 2012 The Chromium Authors. All rights reserved.
[email protected]a1feae52010-10-11 22:14:452// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
[email protected]bd817c22011-02-09 08:16:465#include "chrome/browser/ui/browser_navigator_browsertest.h"
6
[email protected]bb89e7482010-11-17 18:27:047#include "base/command_line.h"
[email protected]3853a4c2013-02-11 17:15:578#include "base/prefs/pref_service.h"
[email protected]fc2b46b2014-05-03 16:33:459#include "base/strings/string_util.h"
[email protected]a2efc35d2013-08-03 23:17:2510#include "base/strings/utf_string_conversions.h"
[email protected]26c53e662011-07-09 02:21:0211#include "chrome/app/chrome_command_ids.h"
[email protected]93ad8e1c2011-11-08 21:34:0512#include "chrome/browser/prefs/incognito_mode_prefs.h"
[email protected]8ecad5e2010-12-02 21:18:3313#include "chrome/browser/profiles/profile.h"
[email protected]2b09ae552013-02-23 06:38:0314#include "chrome/browser/ui/browser.h"
[email protected]a37d4b02012-06-25 21:56:1015#include "chrome/browser/ui/browser_commands.h"
[email protected]0665ebe2013-02-13 09:53:1916#include "chrome/browser/ui/browser_finder.h"
[email protected]339d6dd2010-11-12 00:41:5817#include "chrome/browser/ui/browser_navigator.h"
[email protected]52877dbc62012-06-29 22:22:0318#include "chrome/browser/ui/browser_tabstrip.h"
[email protected]bb89e7482010-11-17 18:27:0419#include "chrome/browser/ui/browser_window.h"
[email protected]5d9cace72012-06-21 16:07:1220#include "chrome/browser/ui/chrome_pages.h"
meacerc62e2ee2014-10-22 00:44:5221#include "chrome/browser/ui/location_bar/location_bar.h"
[email protected]beb1d1192013-05-14 04:47:5122#include "chrome/browser/ui/singleton_tabs.h"
[email protected]b56e2e32012-05-11 21:18:0423#include "chrome/browser/ui/tabs/tab_strip_model.h"
[email protected]bb89e7482010-11-17 18:27:0424#include "chrome/common/chrome_switches.h"
[email protected]93ad8e1c2011-11-08 21:34:0525#include "chrome/common/pref_names.h"
[email protected]ddddfda2011-07-14 23:19:3926#include "chrome/common/url_constants.h"
[email protected]af44e7fb2011-07-29 18:32:3227#include "chrome/test/base/ui_test_utils.h"
blundell7dbd3792015-08-05 15:14:1928#include "components/omnibox/browser/omnibox_view.h"
[email protected]ad50def52011-10-19 23:17:0729#include "content/public/browser/notification_service.h"
[email protected]0d6e9bd2011-10-18 04:29:1630#include "content/public/browser/notification_types.h"
[email protected]83ff91c2012-01-05 20:54:1331#include "content/public/browser/web_contents.h"
[email protected]a1feae52010-10-11 22:14:4532
[email protected]4ca15302012-01-03 05:53:2033using content::WebContents;
34
[email protected]ddddfda2011-07-14 23:19:3935namespace {
36
[email protected]a2efc35d2013-08-03 23:17:2537const char kExpectedTitle[] = "PASSED!";
38const char kEchoTitleCommand[] = "echotitle";
39
[email protected]ddddfda2011-07-14 23:19:3940GURL GetGoogleURL() {
[email protected]bd817c22011-02-09 08:16:4641 return GURL("http://www.google.com/");
42}
[email protected]a1feae52010-10-11 22:14:4543
[email protected]ddddfda2011-07-14 23:19:3944GURL GetSettingsURL() {
[email protected]f8f93eb2012-09-25 03:06:2445 return GURL(chrome::kChromeUISettingsURL);
[email protected]ddddfda2011-07-14 23:19:3946}
47
[email protected]a048ad22012-03-23 04:26:5648GURL GetContentSettingsURL() {
49 return GetSettingsURL().Resolve(chrome::kContentSettingsExceptionsSubPage);
[email protected]ddddfda2011-07-14 23:19:3950}
51
[email protected]a048ad22012-03-23 04:26:5652GURL GetClearBrowsingDataURL() {
53 return GetSettingsURL().Resolve(chrome::kClearBrowserDataSubPage);
[email protected]ddddfda2011-07-14 23:19:3954}
55
[email protected]f8f93eb2012-09-25 03:06:2456// Converts long uber URLs ("chrome://chrome/foo/") to short (virtual) URLs
57// ("chrome://foo/"). This should be used to convert the return value of
58// WebContentsImpl::GetURL before comparison because it can return either the
59// real URL or the virtual URL.
60GURL ShortenUberURL(const GURL& url) {
61 std::string url_string = url.spec();
62 const std::string long_prefix = "chrome://chrome/";
63 const std::string short_prefix = "chrome://";
64 if (url_string.find(long_prefix) != 0)
65 return url;
66 url_string.replace(0, long_prefix.length(), short_prefix);
67 return GURL(url_string);
68}
69
[email protected]a2efc35d2013-08-03 23:17:2570} // namespace
[email protected]ddddfda2011-07-14 23:19:3971
[email protected]78e2edc2012-07-01 23:32:2872chrome::NavigateParams BrowserNavigatorTest::MakeNavigateParams() const {
[email protected]bd817c22011-02-09 08:16:4673 return MakeNavigateParams(browser());
74}
[email protected]a1feae52010-10-11 22:14:4575
[email protected]78e2edc2012-07-01 23:32:2876chrome::NavigateParams BrowserNavigatorTest::MakeNavigateParams(
[email protected]bd817c22011-02-09 08:16:4677 Browser* browser) const {
[email protected]78e2edc2012-07-01 23:32:2878 chrome::NavigateParams params(browser, GetGoogleURL(),
Sylvain Defresnec6ccc77d2014-09-19 10:19:3579 ui::PAGE_TRANSITION_LINK);
[email protected]50592b52013-05-02 22:26:2580 params.window_action = chrome::NavigateParams::SHOW_WINDOW;
[email protected]bd817c22011-02-09 08:16:4681 return params;
82}
[email protected]a1feae52010-10-11 22:14:4583
[email protected]a2efc35d2013-08-03 23:17:2584bool BrowserNavigatorTest::OpenPOSTURLInNewForegroundTabAndGetTitle(
85 const GURL& url, const std::string& post_data, bool is_browser_initiated,
86 base::string16* title) {
87 chrome::NavigateParams param(MakeNavigateParams());
88 param.disposition = NEW_FOREGROUND_TAB;
89 param.url = url;
90 param.is_renderer_initiated = !is_browser_initiated;
91 param.uses_post = true;
92 param.browser_initiated_post_data = new base::RefCountedStaticMemory(
[email protected]8df08cf2014-02-12 22:34:0893 post_data.data(), post_data.size());
[email protected]a2efc35d2013-08-03 23:17:2594
95 ui_test_utils::NavigateToURL(&param);
96 if (!param.target_contents)
97 return false;
98
99 // Navigate() should have opened the contents in new foreground tab in the
100 // current Browser.
101 EXPECT_EQ(browser(), param.browser);
102 EXPECT_EQ(browser()->tab_strip_model()->GetActiveWebContents(),
103 param.target_contents);
104 // We should have one window, with one tab.
105 EXPECT_EQ(1u, chrome::GetTotalBrowserCount());
106 EXPECT_EQ(2, browser()->tab_strip_model()->count());
107
108 *title = param.target_contents->GetTitle();
109 return true;
110}
111
[email protected]bd817c22011-02-09 08:16:46112Browser* BrowserNavigatorTest::CreateEmptyBrowserForType(Browser::Type type,
113 Profile* profile) {
[email protected]2b09ae552013-02-23 06:38:03114 Browser* browser = new Browser(
[email protected]ed2fa722013-06-25 20:37:34115 Browser::CreateParams(type, profile, chrome::GetActiveDesktop()));
[email protected]00509a32013-11-17 17:45:37116 chrome::AddTabAt(browser, GURL(), -1, true);
[email protected]bd817c22011-02-09 08:16:46117 return browser;
118}
[email protected]a1feae52010-10-11 22:14:45119
[email protected]d2202e22014-04-14 20:20:53120Browser* BrowserNavigatorTest::CreateEmptyBrowserForApp(Profile* profile) {
[email protected]a4fe67012012-07-25 20:14:29121 Browser* browser = new Browser(
[email protected]da22aa62012-04-04 18:54:35122 Browser::CreateParams::CreateForApp(
[email protected]d2202e22014-04-14 20:20:53123 "Test", false /* trusted_source */, gfx::Rect(), profile,
[email protected]ed2fa722013-06-25 20:37:34124 chrome::GetActiveDesktop()));
[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);
205}
206
[email protected]6c2381d2011-10-19 02:52:53207void BrowserNavigatorTest::Observe(
208 int type,
209 const content::NotificationSource& source,
210 const content::NotificationDetails& details) {
[email protected]432115822011-07-10 15:52:27211 switch (type) {
[email protected]d53a08c2012-07-18 20:35:30212 case content::NOTIFICATION_WEB_CONTENTS_RENDER_VIEW_HOST_CREATED: {
[email protected]bd817c22011-02-09 08:16:46213 ++this->created_tab_contents_count_;
214 break;
[email protected]fa7ebe02010-11-29 23:04:57215 }
[email protected]bd817c22011-02-09 08:16:46216 default:
217 break;
[email protected]fa7ebe02010-11-29 23:04:57218 }
[email protected]bd817c22011-02-09 08:16:46219}
[email protected]fa7ebe02010-11-29 23:04:57220
[email protected]ddddfda2011-07-14 23:19:39221
[email protected]bd817c22011-02-09 08:16:46222namespace {
[email protected]a1feae52010-10-11 22:14:45223
[email protected]a1feae52010-10-11 22:14:45224// This test verifies that when a navigation occurs within a tab, the tab count
225// of the Browser remains the same and the current tab bears the loaded URL.
[email protected]59167c22013-06-03 18:07:32226// Note that network URLs are not actually loaded in tests, so this also tests
227// that error pages leave the intended URL in the address bar.
[email protected]a1feae52010-10-11 22:14:45228IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_CurrentTab) {
[email protected]ddddfda2011-07-14 23:19:39229 ui_test_utils::NavigateToURL(browser(), GetGoogleURL());
[email protected]ee496952013-01-10 23:17:33230 EXPECT_EQ(GetGoogleURL(),
231 browser()->tab_strip_model()->GetActiveWebContents()->GetURL());
[email protected]a1feae52010-10-11 22:14:45232 // We should have one window with one tab.
[email protected]0665ebe2013-02-13 09:53:19233 EXPECT_EQ(1u, chrome::GetTotalBrowserCount());
[email protected]ee496952013-01-10 23:17:33234 EXPECT_EQ(1, browser()->tab_strip_model()->count());
[email protected]a1feae52010-10-11 22:14:45235}
236
[email protected]bd817c22011-02-09 08:16:46237// This test verifies that a singleton tab is refocused if one is already opened
[email protected]19d9f3a2010-10-14 21:49:36238// in another or an existing window, or added if it is not.
239IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_SingletonTabExisting) {
[email protected]19d9f3a2010-10-14 21:49:36240 GURL singleton_url1("http://maps.google.com/");
[email protected]fa7ebe02010-11-29 23:04:57241
[email protected]e232c992012-12-06 12:43:20242 // Register for a notification if an additional WebContents was instantiated.
[email protected]bd817c22011-02-09 08:16:46243 // Opening a Singleton tab that is already opened should not be opening a new
[email protected]e232c992012-12-06 12:43:20244 // tab nor be creating a new WebContents object.
[email protected]6c2381d2011-10-19 02:52:53245 content::NotificationRegistrar registrar;
[email protected]fa7ebe02010-11-29 23:04:57246
247 // As the registrar object goes out of scope, this will get unregistered
[email protected]d53a08c2012-07-18 20:35:30248 registrar.Add(this,
249 content::NOTIFICATION_WEB_CONTENTS_RENDER_VIEW_HOST_CREATED,
[email protected]ad50def52011-10-19 23:17:07250 content::NotificationService::AllSources());
[email protected]fa7ebe02010-11-29 23:04:57251
[email protected]52877dbc62012-06-29 22:22:03252 chrome::AddSelectedTabWithURL(browser(), singleton_url1,
Sylvain Defresnec6ccc77d2014-09-19 10:19:35253 ui::PAGE_TRANSITION_LINK);
[email protected]52877dbc62012-06-29 22:22:03254 chrome::AddSelectedTabWithURL(browser(), GetGoogleURL(),
Sylvain Defresnec6ccc77d2014-09-19 10:19:35255 ui::PAGE_TRANSITION_LINK);
[email protected]19d9f3a2010-10-14 21:49:36256
257 // We should have one browser with 3 tabs, the 3rd selected.
[email protected]0665ebe2013-02-13 09:53:19258 EXPECT_EQ(1u, chrome::GetTotalBrowserCount());
[email protected]ee496952013-01-10 23:17:33259 EXPECT_EQ(2, browser()->tab_strip_model()->active_index());
[email protected]19d9f3a2010-10-14 21:49:36260
[email protected]fa7ebe02010-11-29 23:04:57261 unsigned int previous_tab_contents_count =
262 created_tab_contents_count_ = 0;
263
[email protected]19d9f3a2010-10-14 21:49:36264 // Navigate to singleton_url1.
meacerc62e2ee2014-10-22 00:44:52265 chrome::NavigateParams params(MakeNavigateParams());
266 params.disposition = SINGLETON_TAB;
267 params.url = singleton_url1;
268 chrome::Navigate(&params);
[email protected]19d9f3a2010-10-14 21:49:36269
270 // The middle tab should now be selected.
meacerc62e2ee2014-10-22 00:44:52271 EXPECT_EQ(browser(), params.browser);
[email protected]ee496952013-01-10 23:17:33272 EXPECT_EQ(1, browser()->tab_strip_model()->active_index());
[email protected]fa7ebe02010-11-29 23:04:57273
274 // No tab contents should have been created
275 EXPECT_EQ(previous_tab_contents_count,
276 created_tab_contents_count_);
[email protected]19d9f3a2010-10-14 21:49:36277}
278
279IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
[email protected]578c6962011-08-24 22:06:40280 Disposition_SingletonTabRespectingRef) {
281 GURL singleton_ref_url1("http://maps.google.com/#a");
282 GURL singleton_ref_url2("http://maps.google.com/#b");
283 GURL singleton_ref_url3("http://maps.google.com/");
284
[email protected]52877dbc62012-06-29 22:22:03285 chrome::AddSelectedTabWithURL(browser(), singleton_ref_url1,
Sylvain Defresnec6ccc77d2014-09-19 10:19:35286 ui::PAGE_TRANSITION_LINK);
[email protected]578c6962011-08-24 22:06:40287
288 // We should have one browser with 2 tabs, 2nd selected.
[email protected]0665ebe2013-02-13 09:53:19289 EXPECT_EQ(1u, chrome::GetTotalBrowserCount());
[email protected]ee496952013-01-10 23:17:33290 EXPECT_EQ(2, browser()->tab_strip_model()->count());
291 EXPECT_EQ(1, browser()->tab_strip_model()->active_index());
[email protected]578c6962011-08-24 22:06:40292
293 // Navigate to singleton_url2.
meacerc62e2ee2014-10-22 00:44:52294 chrome::NavigateParams params(MakeNavigateParams());
295 params.disposition = SINGLETON_TAB;
296 params.url = singleton_ref_url2;
297 chrome::Navigate(&params);
[email protected]578c6962011-08-24 22:06:40298
299 // We should now have 2 tabs, the 2nd one selected.
meacerc62e2ee2014-10-22 00:44:52300 EXPECT_EQ(browser(), params.browser);
[email protected]ee496952013-01-10 23:17:33301 EXPECT_EQ(2, browser()->tab_strip_model()->count());
302 EXPECT_EQ(1, browser()->tab_strip_model()->active_index());
[email protected]578c6962011-08-24 22:06:40303
304 // Navigate to singleton_url2, but with respect ref set.
meacerc62e2ee2014-10-22 00:44:52305 params = MakeNavigateParams();
306 params.disposition = SINGLETON_TAB;
307 params.url = singleton_ref_url2;
308 params.ref_behavior = chrome::NavigateParams::RESPECT_REF;
309 chrome::Navigate(&params);
[email protected]578c6962011-08-24 22:06:40310
311 // We should now have 3 tabs, the 3th one selected.
meacerc62e2ee2014-10-22 00:44:52312 EXPECT_EQ(browser(), params.browser);
[email protected]ee496952013-01-10 23:17:33313 EXPECT_EQ(3, browser()->tab_strip_model()->count());
314 EXPECT_EQ(2, browser()->tab_strip_model()->active_index());
[email protected]578c6962011-08-24 22:06:40315
316 // Navigate to singleton_url3.
meacerc62e2ee2014-10-22 00:44:52317 params = MakeNavigateParams();
318 params.disposition = SINGLETON_TAB;
319 params.url = singleton_ref_url3;
320 params.ref_behavior = chrome::NavigateParams::RESPECT_REF;
321 chrome::Navigate(&params);
[email protected]578c6962011-08-24 22:06:40322
323 // We should now have 4 tabs, the 4th one selected.
meacerc62e2ee2014-10-22 00:44:52324 EXPECT_EQ(browser(), params.browser);
[email protected]ee496952013-01-10 23:17:33325 EXPECT_EQ(4, browser()->tab_strip_model()->count());
326 EXPECT_EQ(3, browser()->tab_strip_model()->active_index());
[email protected]578c6962011-08-24 22:06:40327}
328
329IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
[email protected]19d9f3a2010-10-14 21:49:36330 Disposition_SingletonTabNoneExisting) {
[email protected]19d9f3a2010-10-14 21:49:36331 GURL singleton_url1("http://maps.google.com/");
332
[email protected]bd817c22011-02-09 08:16:46333 // We should have one browser with 1 tab.
[email protected]0665ebe2013-02-13 09:53:19334 EXPECT_EQ(1u, chrome::GetTotalBrowserCount());
[email protected]ee496952013-01-10 23:17:33335 EXPECT_EQ(0, browser()->tab_strip_model()->active_index());
[email protected]19d9f3a2010-10-14 21:49:36336
337 // Navigate to singleton_url1.
meacerc62e2ee2014-10-22 00:44:52338 chrome::NavigateParams params(MakeNavigateParams());
339 params.disposition = SINGLETON_TAB;
340 params.url = singleton_url1;
341 chrome::Navigate(&params);
[email protected]19d9f3a2010-10-14 21:49:36342
343 // We should now have 2 tabs, the 2nd one selected.
meacerc62e2ee2014-10-22 00:44:52344 EXPECT_EQ(browser(), params.browser);
[email protected]ee496952013-01-10 23:17:33345 EXPECT_EQ(2, browser()->tab_strip_model()->count());
346 EXPECT_EQ(1, browser()->tab_strip_model()->active_index());
[email protected]a1feae52010-10-11 22:14:45347}
348
349// This test verifies that when a navigation results in a foreground tab, the
350// tab count of the Browser increases and the selected tab shifts to the new
351// foreground tab.
352IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_NewForegroundTab) {
[email protected]ee496952013-01-10 23:17:33353 WebContents* old_contents =
354 browser()->tab_strip_model()->GetActiveWebContents();
meacerc62e2ee2014-10-22 00:44:52355 chrome::NavigateParams params(MakeNavigateParams());
356 params.disposition = NEW_FOREGROUND_TAB;
357 chrome::Navigate(&params);
[email protected]ee496952013-01-10 23:17:33358 EXPECT_NE(old_contents,
359 browser()->tab_strip_model()->GetActiveWebContents());
[email protected]e232c992012-12-06 12:43:20360 EXPECT_EQ(browser()->tab_strip_model()->GetActiveWebContents(),
meacerc62e2ee2014-10-22 00:44:52361 params.target_contents);
[email protected]ee496952013-01-10 23:17:33362 EXPECT_EQ(2, browser()->tab_strip_model()->count());
[email protected]a1feae52010-10-11 22:14:45363}
364
365// This test verifies that when a navigation results in a background tab, the
366// tab count of the Browser increases but the selected tab remains the same.
367IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_NewBackgroundTab) {
[email protected]ee496952013-01-10 23:17:33368 WebContents* old_contents =
369 browser()->tab_strip_model()->GetActiveWebContents();
meacerc62e2ee2014-10-22 00:44:52370 chrome::NavigateParams params(MakeNavigateParams());
371 params.disposition = NEW_BACKGROUND_TAB;
372 chrome::Navigate(&params);
[email protected]ee496952013-01-10 23:17:33373 WebContents* new_contents =
374 browser()->tab_strip_model()->GetActiveWebContents();
[email protected]a1feae52010-10-11 22:14:45375 // The selected tab should have remained unchanged, since the new tab was
376 // opened in the background.
377 EXPECT_EQ(old_contents, new_contents);
[email protected]ee496952013-01-10 23:17:33378 EXPECT_EQ(2, browser()->tab_strip_model()->count());
[email protected]a1feae52010-10-11 22:14:45379}
380
381// This test verifies that when a navigation requiring a new foreground tab
382// occurs in a Browser that cannot host multiple tabs, the new foreground tab
383// is created in an existing compatible Browser.
384IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
385 Disposition_IncompatibleWindow_Existing) {
386 // Open a foreground tab in a window that cannot open popups when there is an
387 // existing compatible window somewhere else that they can be opened within.
388 Browser* popup = CreateEmptyBrowserForType(Browser::TYPE_POPUP,
389 browser()->profile());
meacerc62e2ee2014-10-22 00:44:52390 chrome::NavigateParams params(MakeNavigateParams(popup));
391 params.disposition = NEW_FOREGROUND_TAB;
392 chrome::Navigate(&params);
[email protected]a1feae52010-10-11 22:14:45393
394 // Navigate() should have opened the tab in a different browser since the
395 // one we supplied didn't support additional tabs.
meacerc62e2ee2014-10-22 00:44:52396 EXPECT_NE(popup, params.browser);
[email protected]a1feae52010-10-11 22:14:45397
398 // Since browser() is an existing compatible tabbed browser, it should have
399 // opened the tab there.
meacerc62e2ee2014-10-22 00:44:52400 EXPECT_EQ(browser(), params.browser);
[email protected]a1feae52010-10-11 22:14:45401
402 // We should be left with 2 windows, the popup with one tab and the browser()
403 // provided by the framework with two.
[email protected]0665ebe2013-02-13 09:53:19404 EXPECT_EQ(2u, chrome::GetTotalBrowserCount());
[email protected]ee496952013-01-10 23:17:33405 EXPECT_EQ(1, popup->tab_strip_model()->count());
406 EXPECT_EQ(2, browser()->tab_strip_model()->count());
[email protected]a1feae52010-10-11 22:14:45407}
408
409// This test verifies that when a navigation requiring a new foreground tab
410// occurs in a Browser that cannot host multiple tabs and no compatible Browser
411// that can is open, a compatible Browser is created.
412IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
413 Disposition_IncompatibleWindow_NoExisting) {
414 // We want to simulate not being able to find an existing window compatible
415 // with our non-tabbed browser window so Navigate() is forced to create a
416 // new compatible window. Because browser() supplied by the in-process
417 // browser testing framework is compatible with browser()->profile(), we
418 // need a different profile, and creating a popup window with an incognito
419 // profile is a quick and dirty way of achieving this.
420 Browser* popup = CreateEmptyBrowserForType(
[email protected]b35b26b32011-05-05 20:35:14421 Browser::TYPE_POPUP,
422 browser()->profile()->GetOffTheRecordProfile());
meacerc62e2ee2014-10-22 00:44:52423 chrome::NavigateParams params(MakeNavigateParams(popup));
424 params.disposition = NEW_FOREGROUND_TAB;
425 chrome::Navigate(&params);
[email protected]a1feae52010-10-11 22:14:45426
427 // Navigate() should have opened the tab in a different browser since the
428 // one we supplied didn't support additional tabs.
meacerc62e2ee2014-10-22 00:44:52429 EXPECT_NE(popup, params.browser);
[email protected]a1feae52010-10-11 22:14:45430
431 // This time, browser() is _not_ compatible with popup since it is not an
432 // incognito window.
meacerc62e2ee2014-10-22 00:44:52433 EXPECT_NE(browser(), params.browser);
[email protected]a1feae52010-10-11 22:14:45434
435 // We should have three windows, each with one tab:
436 // 1. the browser() provided by the framework (unchanged in this test)
437 // 2. the incognito popup we created originally
438 // 3. the new incognito tabbed browser that was created by Navigate().
[email protected]0665ebe2013-02-13 09:53:19439 EXPECT_EQ(3u, chrome::GetTotalBrowserCount());
[email protected]ee496952013-01-10 23:17:33440 EXPECT_EQ(1, browser()->tab_strip_model()->count());
441 EXPECT_EQ(1, popup->tab_strip_model()->count());
meacerc62e2ee2014-10-22 00:44:52442 EXPECT_EQ(1, params.browser->tab_strip_model()->count());
443 EXPECT_TRUE(params.browser->is_type_tabbed());
[email protected]a1feae52010-10-11 22:14:45444}
445
446// This test verifies that navigating with WindowOpenDisposition = NEW_POPUP
447// from a normal Browser results in a new Browser with TYPE_POPUP.
448IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_NewPopup) {
meacerc62e2ee2014-10-22 00:44:52449 chrome::NavigateParams params(MakeNavigateParams());
450 params.disposition = NEW_POPUP;
451 params.window_bounds = gfx::Rect(0, 0, 200, 200);
[email protected]7d329992011-04-15 18:20:02452 // Wait for new popup to to load and gain focus.
meacerc62e2ee2014-10-22 00:44:52453 ui_test_utils::NavigateToURL(&params);
[email protected]a1feae52010-10-11 22:14:45454
[email protected]7d329992011-04-15 18:20:02455 // Navigate() should have opened a new, focused popup window.
meacerc62e2ee2014-10-22 00:44:52456 EXPECT_NE(browser(), params.browser);
[email protected]50592b52013-05-02 22:26:25457#if 0
458 // TODO(stevenjb): Enable this test. See: crbug.com/79493
meacerc62e2ee2014-10-22 00:44:52459 EXPECT_TRUE(browser->window()->IsActive());
[email protected]50592b52013-05-02 22:26:25460#endif
meacerc62e2ee2014-10-22 00:44:52461 EXPECT_TRUE(params.browser->is_type_popup());
462 EXPECT_FALSE(params.browser->is_app());
[email protected]a1feae52010-10-11 22:14:45463
464 // We should have two windows, the browser() provided by the framework and the
465 // new popup window.
[email protected]0665ebe2013-02-13 09:53:19466 EXPECT_EQ(2u, chrome::GetTotalBrowserCount());
[email protected]ee496952013-01-10 23:17:33467 EXPECT_EQ(1, browser()->tab_strip_model()->count());
meacerc62e2ee2014-10-22 00:44:52468 EXPECT_EQ(1, params.browser->tab_strip_model()->count());
[email protected]a1feae52010-10-11 22:14:45469}
470
471// This test verifies that navigating with WindowOpenDisposition = NEW_POPUP
[email protected]f112b0f2011-05-26 01:53:52472// from a normal Browser results in a new Browser with is_app() true.
473IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_NewPopup_ExtensionId) {
meacerc62e2ee2014-10-22 00:44:52474 chrome::NavigateParams params(MakeNavigateParams());
475 params.disposition = NEW_POPUP;
476 params.extension_app_id = "extensionappid";
477 params.window_bounds = gfx::Rect(0, 0, 200, 200);
[email protected]f112b0f2011-05-26 01:53:52478 // Wait for new popup to to load and gain focus.
meacerc62e2ee2014-10-22 00:44:52479 ui_test_utils::NavigateToURL(&params);
[email protected]f112b0f2011-05-26 01:53:52480
481 // Navigate() should have opened a new, focused popup window.
meacerc62e2ee2014-10-22 00:44:52482 EXPECT_NE(browser(), params.browser);
483 EXPECT_TRUE(params.browser->is_type_popup());
484 EXPECT_TRUE(params.browser->is_app());
[email protected]f112b0f2011-05-26 01:53:52485
486 // We should have two windows, the browser() provided by the framework and the
487 // new popup window.
[email protected]0665ebe2013-02-13 09:53:19488 EXPECT_EQ(2u, chrome::GetTotalBrowserCount());
[email protected]ee496952013-01-10 23:17:33489 EXPECT_EQ(1, browser()->tab_strip_model()->count());
meacerc62e2ee2014-10-22 00:44:52490 EXPECT_EQ(1, params.browser->tab_strip_model()->count());
[email protected]f112b0f2011-05-26 01:53:52491}
492
493// This test verifies that navigating with WindowOpenDisposition = NEW_POPUP
[email protected]300d1e52011-01-19 23:57:57494// from a normal popup results in a new Browser with TYPE_POPUP.
495IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_NewPopupFromPopup) {
496 // Open a popup.
meacerc62e2ee2014-10-22 00:44:52497 chrome::NavigateParams params1(MakeNavigateParams());
498 params1.disposition = NEW_POPUP;
499 params1.window_bounds = gfx::Rect(0, 0, 200, 200);
500 chrome::Navigate(&params1);
[email protected]300d1e52011-01-19 23:57:57501 // Open another popup.
meacerc62e2ee2014-10-22 00:44:52502 chrome::NavigateParams params2(MakeNavigateParams(params1.browser));
503 params2.disposition = NEW_POPUP;
504 params2.window_bounds = gfx::Rect(0, 0, 200, 200);
505 chrome::Navigate(&params2);
[email protected]300d1e52011-01-19 23:57:57506
507 // Navigate() should have opened a new normal popup window.
meacerc62e2ee2014-10-22 00:44:52508 EXPECT_NE(params1.browser, params2.browser);
509 EXPECT_TRUE(params2.browser->is_type_popup());
510 EXPECT_FALSE(params2.browser->is_app());
[email protected]300d1e52011-01-19 23:57:57511
512 // We should have three windows, the browser() provided by the framework,
513 // the first popup window, and the second popup window.
[email protected]0665ebe2013-02-13 09:53:19514 EXPECT_EQ(3u, chrome::GetTotalBrowserCount());
[email protected]ee496952013-01-10 23:17:33515 EXPECT_EQ(1, browser()->tab_strip_model()->count());
meacerc62e2ee2014-10-22 00:44:52516 EXPECT_EQ(1, params1.browser->tab_strip_model()->count());
517 EXPECT_EQ(1, params2.browser->tab_strip_model()->count());
[email protected]300d1e52011-01-19 23:57:57518}
519
520// This test verifies that navigating with WindowOpenDisposition = NEW_POPUP
[email protected]d2202e22014-04-14 20:20:53521// from an app frame results in a new Browser with TYPE_POPUP.
[email protected]a1feae52010-10-11 22:14:45522IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
523 Disposition_NewPopupFromAppWindow) {
[email protected]d2202e22014-04-14 20:20:53524 Browser* app_browser = CreateEmptyBrowserForApp(browser()->profile());
meacerc62e2ee2014-10-22 00:44:52525 chrome::NavigateParams params(MakeNavigateParams(app_browser));
526 params.disposition = NEW_POPUP;
527 params.window_bounds = gfx::Rect(0, 0, 200, 200);
528 chrome::Navigate(&params);
[email protected]a1feae52010-10-11 22:14:45529
530 // Navigate() should have opened a new popup app window.
meacerc62e2ee2014-10-22 00:44:52531 EXPECT_NE(app_browser, params.browser);
532 EXPECT_NE(browser(), params.browser);
533 EXPECT_TRUE(params.browser->is_type_popup());
534 EXPECT_TRUE(params.browser->is_app());
[email protected]a1feae52010-10-11 22:14:45535
536 // We should now have three windows, the app window, the app popup it created,
537 // and the original browser() provided by the framework.
[email protected]0665ebe2013-02-13 09:53:19538 EXPECT_EQ(3u, chrome::GetTotalBrowserCount());
[email protected]ee496952013-01-10 23:17:33539 EXPECT_EQ(1, browser()->tab_strip_model()->count());
540 EXPECT_EQ(1, app_browser->tab_strip_model()->count());
meacerc62e2ee2014-10-22 00:44:52541 EXPECT_EQ(1, params.browser->tab_strip_model()->count());
[email protected]a1feae52010-10-11 22:14:45542}
543
544// This test verifies that navigating with WindowOpenDisposition = NEW_POPUP
[email protected]d2202e22014-04-14 20:20:53545// from an app popup results in a new Browser also of TYPE_POPUP.
[email protected]300d1e52011-01-19 23:57:57546IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
547 Disposition_NewPopupFromAppPopup) {
[email protected]d2202e22014-04-14 20:20:53548 Browser* app_browser = CreateEmptyBrowserForApp(browser()->profile());
[email protected]300d1e52011-01-19 23:57:57549 // Open an app popup.
meacerc62e2ee2014-10-22 00:44:52550 chrome::NavigateParams params1(MakeNavigateParams(app_browser));
551 params1.disposition = NEW_POPUP;
552 params1.window_bounds = gfx::Rect(0, 0, 200, 200);
553 chrome::Navigate(&params1);
[email protected]300d1e52011-01-19 23:57:57554 // Now open another app popup.
meacerc62e2ee2014-10-22 00:44:52555 chrome::NavigateParams params2(MakeNavigateParams(params1.browser));
556 params2.disposition = NEW_POPUP;
557 params2.window_bounds = gfx::Rect(0, 0, 200, 200);
558 chrome::Navigate(&params2);
[email protected]300d1e52011-01-19 23:57:57559
560 // Navigate() should have opened a new popup app window.
meacerc62e2ee2014-10-22 00:44:52561 EXPECT_NE(browser(), params1.browser);
562 EXPECT_NE(params1.browser, params2.browser);
563 EXPECT_TRUE(params2.browser->is_type_popup());
564 EXPECT_TRUE(params2.browser->is_app());
[email protected]300d1e52011-01-19 23:57:57565
566 // We should now have four windows, the app window, the first app popup,
567 // the second app popup, and the original browser() provided by the framework.
[email protected]0665ebe2013-02-13 09:53:19568 EXPECT_EQ(4u, chrome::GetTotalBrowserCount());
[email protected]ee496952013-01-10 23:17:33569 EXPECT_EQ(1, browser()->tab_strip_model()->count());
570 EXPECT_EQ(1, app_browser->tab_strip_model()->count());
meacerc62e2ee2014-10-22 00:44:52571 EXPECT_EQ(1, params1.browser->tab_strip_model()->count());
572 EXPECT_EQ(1, params2.browser->tab_strip_model()->count());
[email protected]300d1e52011-01-19 23:57:57573}
574
575// This test verifies that navigating with WindowOpenDisposition = NEW_POPUP
[email protected]a1feae52010-10-11 22:14:45576// from an extension app tab results in a new Browser with TYPE_APP_POPUP.
577IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
578 Disposition_NewPopupFromExtensionApp) {
579 // TODO(beng): TBD.
580}
581
[email protected]7d329992011-04-15 18:20:02582// This test verifies that navigating with window_action = SHOW_WINDOW_INACTIVE
583// does not focus a new new popup window.
584IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_NewPopupUnfocused) {
meacerc62e2ee2014-10-22 00:44:52585 chrome::NavigateParams params(MakeNavigateParams());
586 params.disposition = NEW_POPUP;
587 params.window_bounds = gfx::Rect(0, 0, 200, 200);
588 params.window_action = chrome::NavigateParams::SHOW_WINDOW_INACTIVE;
[email protected]7d329992011-04-15 18:20:02589 // Wait for new popup to load (and gain focus if the test fails).
meacerc62e2ee2014-10-22 00:44:52590 ui_test_utils::NavigateToURL(&params);
[email protected]7d329992011-04-15 18:20:02591
592 // Navigate() should have opened a new, unfocused, popup window.
meacerc62e2ee2014-10-22 00:44:52593 EXPECT_NE(browser(), params.browser);
594 EXPECT_EQ(Browser::TYPE_POPUP, params.browser->type());
[email protected]9db263a2011-04-15 20:53:47595#if 0
596// TODO(stevenjb): Enable this test. See: crbug.com/79493
[email protected]7d329992011-04-15 18:20:02597 EXPECT_FALSE(p.browser->window()->IsActive());
[email protected]7d329992011-04-15 18:20:02598#endif
[email protected]9db263a2011-04-15 20:53:47599}
[email protected]7d329992011-04-15 18:20:02600
[email protected]d2202e22014-04-14 20:20:53601// This test verifies that navigating with WindowOpenDisposition = NEW_POPUP
602// and trusted_source = true results in a new Browser where is_trusted_source()
603// is true.
604IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_NewPopupTrusted) {
meacerc62e2ee2014-10-22 00:44:52605 chrome::NavigateParams params(MakeNavigateParams());
606 params.disposition = NEW_POPUP;
607 params.trusted_source = true;
608 params.window_bounds = gfx::Rect(0, 0, 200, 200);
[email protected]d2202e22014-04-14 20:20:53609 // Wait for new popup to to load and gain focus.
meacerc62e2ee2014-10-22 00:44:52610 ui_test_utils::NavigateToURL(&params);
[email protected]d2202e22014-04-14 20:20:53611
612 // Navigate() should have opened a new popup window of TYPE_TRUSTED_POPUP.
meacerc62e2ee2014-10-22 00:44:52613 EXPECT_NE(browser(), params.browser);
614 EXPECT_TRUE(params.browser->is_type_popup());
615 EXPECT_TRUE(params.browser->is_trusted_source());
[email protected]d2202e22014-04-14 20:20:53616}
617
618
[email protected]a1feae52010-10-11 22:14:45619// This test verifies that navigating with WindowOpenDisposition = NEW_WINDOW
620// always opens a new window.
621IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_NewWindow) {
meacerc62e2ee2014-10-22 00:44:52622 chrome::NavigateParams params(MakeNavigateParams());
623 params.disposition = NEW_WINDOW;
624 chrome::Navigate(&params);
[email protected]a1feae52010-10-11 22:14:45625
626 // Navigate() should have opened a new toplevel window.
meacerc62e2ee2014-10-22 00:44:52627 EXPECT_NE(browser(), params.browser);
628 EXPECT_TRUE(params.browser->is_type_tabbed());
[email protected]a1feae52010-10-11 22:14:45629
630 // We should now have two windows, the browser() provided by the framework and
631 // the new normal window.
[email protected]0665ebe2013-02-13 09:53:19632 EXPECT_EQ(2u, chrome::GetTotalBrowserCount());
[email protected]ee496952013-01-10 23:17:33633 EXPECT_EQ(1, browser()->tab_strip_model()->count());
meacerc62e2ee2014-10-22 00:44:52634 EXPECT_EQ(1, params.browser->tab_strip_model()->count());
[email protected]a1feae52010-10-11 22:14:45635}
636
637// This test verifies that navigating with WindowOpenDisposition = INCOGNITO
638// opens a new incognito window if no existing incognito window is present.
639IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_Incognito) {
meacerc62e2ee2014-10-22 00:44:52640 chrome::NavigateParams params(MakeNavigateParams());
641 params.disposition = OFF_THE_RECORD;
642 chrome::Navigate(&params);
[email protected]a1feae52010-10-11 22:14:45643
644 // Navigate() should have opened a new toplevel incognito window.
meacerc62e2ee2014-10-22 00:44:52645 EXPECT_NE(browser(), params.browser);
[email protected]a1feae52010-10-11 22:14:45646 EXPECT_EQ(browser()->profile()->GetOffTheRecordProfile(),
meacerc62e2ee2014-10-22 00:44:52647 params.browser->profile());
[email protected]a1feae52010-10-11 22:14:45648
[email protected]d7ff3592010-11-30 21:50:46649 // |source_contents| should be set to NULL because the profile for the new
650 // page is different from the originating page.
meacerc62e2ee2014-10-22 00:44:52651 EXPECT_EQ(NULL, params.source_contents);
[email protected]d7ff3592010-11-30 21:50:46652
[email protected]a1feae52010-10-11 22:14:45653 // We should now have two windows, the browser() provided by the framework and
654 // the new incognito window.
[email protected]0665ebe2013-02-13 09:53:19655 EXPECT_EQ(2u, chrome::GetTotalBrowserCount());
[email protected]ee496952013-01-10 23:17:33656 EXPECT_EQ(1, browser()->tab_strip_model()->count());
meacerc62e2ee2014-10-22 00:44:52657 EXPECT_EQ(1, params.browser->tab_strip_model()->count());
[email protected]a1feae52010-10-11 22:14:45658}
659
660// This test verifies that navigating with WindowOpenDisposition = INCOGNITO
661// reuses an existing incognito window when possible.
662IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_IncognitoRefocus) {
663 Browser* incognito_browser =
[email protected]b35b26b32011-05-05 20:35:14664 CreateEmptyBrowserForType(Browser::TYPE_TABBED,
[email protected]a1feae52010-10-11 22:14:45665 browser()->profile()->GetOffTheRecordProfile());
meacerc62e2ee2014-10-22 00:44:52666 chrome::NavigateParams params(MakeNavigateParams());
667 params.disposition = OFF_THE_RECORD;
668 chrome::Navigate(&params);
[email protected]a1feae52010-10-11 22:14:45669
670 // Navigate() should have opened a new tab in the existing incognito window.
meacerc62e2ee2014-10-22 00:44:52671 EXPECT_NE(browser(), params.browser);
672 EXPECT_EQ(params.browser, incognito_browser);
[email protected]a1feae52010-10-11 22:14:45673
674 // We should now have two windows, the browser() provided by the framework and
675 // the incognito window we opened earlier.
[email protected]0665ebe2013-02-13 09:53:19676 EXPECT_EQ(2u, chrome::GetTotalBrowserCount());
[email protected]ee496952013-01-10 23:17:33677 EXPECT_EQ(1, browser()->tab_strip_model()->count());
678 EXPECT_EQ(2, incognito_browser->tab_strip_model()->count());
[email protected]a1feae52010-10-11 22:14:45679}
680
681// This test verifies that no navigation action occurs when
682// WindowOpenDisposition = SUPPRESS_OPEN.
683IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_SuppressOpen) {
684 RunSuppressTest(SUPPRESS_OPEN);
685}
686
687// This test verifies that no navigation action occurs when
688// WindowOpenDisposition = SAVE_TO_DISK.
689IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_SaveToDisk) {
690 RunSuppressTest(SAVE_TO_DISK);
691}
692
693// This test verifies that no navigation action occurs when
694// WindowOpenDisposition = IGNORE_ACTION.
695IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_IgnoreAction) {
696 RunSuppressTest(IGNORE_ACTION);
697}
698
[email protected]e232c992012-12-06 12:43:20699// This tests adding a foreground tab with a predefined WebContents.
[email protected]a1feae52010-10-11 22:14:45700IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, TargetContents_ForegroundTab) {
meacerc62e2ee2014-10-22 00:44:52701 chrome::NavigateParams params(MakeNavigateParams());
702 params.disposition = NEW_FOREGROUND_TAB;
703 params.target_contents = CreateWebContents();
704 chrome::Navigate(&params);
[email protected]a1feae52010-10-11 22:14:45705
706 // Navigate() should have opened the contents in a new foreground in the
707 // current Browser.
meacerc62e2ee2014-10-22 00:44:52708 EXPECT_EQ(browser(), params.browser);
[email protected]e232c992012-12-06 12:43:20709 EXPECT_EQ(browser()->tab_strip_model()->GetActiveWebContents(),
meacerc62e2ee2014-10-22 00:44:52710 params.target_contents);
[email protected]a1feae52010-10-11 22:14:45711
712 // We should have one window, with two tabs.
[email protected]0665ebe2013-02-13 09:53:19713 EXPECT_EQ(1u, chrome::GetTotalBrowserCount());
[email protected]ee496952013-01-10 23:17:33714 EXPECT_EQ(2, browser()->tab_strip_model()->count());
[email protected]a1feae52010-10-11 22:14:45715}
716
717#if defined(OS_WIN)
[email protected]e232c992012-12-06 12:43:20718// This tests adding a popup with a predefined WebContents.
[email protected]76edb672011-03-04 21:48:39719IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, DISABLED_TargetContents_Popup) {
meacerc62e2ee2014-10-22 00:44:52720 chrome::NavigateParams params(MakeNavigateParams());
721 params.disposition = NEW_POPUP;
722 params.target_contents = CreateWebContents();
723 params.window_bounds = gfx::Rect(10, 10, 500, 500);
724 chrome::Navigate(&params);
[email protected]a1feae52010-10-11 22:14:45725
726 // Navigate() should have opened a new popup window.
meacerc62e2ee2014-10-22 00:44:52727 EXPECT_NE(browser(), params.browser);
728 EXPECT_TRUE(params.browser->is_type_popup());
729 EXPECT_FALSE(params.browser->is_app());
[email protected]a1feae52010-10-11 22:14:45730
731 // The web platform is weird. The window bounds specified in
meacerc62e2ee2014-10-22 00:44:52732 // |params.window_bounds| are used as follows:
[email protected]a1feae52010-10-11 22:14:45733 // - the origin is used to position the window
[email protected]e232c992012-12-06 12:43:20734 // - the size is used to size the WebContents of the window.
[email protected]a1feae52010-10-11 22:14:45735 // As such the position of the resulting window will always match
meacerc62e2ee2014-10-22 00:44:52736 // params.window_bounds.origin(), but its size will not. We need to match
[email protected]a1feae52010-10-11 22:14:45737 // the size against the selected tab's view's container size.
meacerc62e2ee2014-10-22 00:44:52738 // Only Windows positions the window according to
739 // |params.window_bounds.origin()| - on Mac the window is offset from the
740 // opener and on Linux it always opens at 0,0.
741 EXPECT_EQ(params.window_bounds.origin(),
742 params.browser->window()->GetRestoredBounds().origin());
[email protected]a1feae52010-10-11 22:14:45743 // All platforms should respect size however provided width > 400 (Mac has a
744 // minimum window width of 400).
meacerc62e2ee2014-10-22 00:44:52745 EXPECT_EQ(params.window_bounds.size(),
746 params.target_contents->GetContainerBounds().size());
[email protected]a1feae52010-10-11 22:14:45747
748 // We should have two windows, the new popup and the browser() provided by the
749 // framework.
[email protected]0665ebe2013-02-13 09:53:19750 EXPECT_EQ(2u, chrome::GetTotalBrowserCount());
[email protected]ee496952013-01-10 23:17:33751 EXPECT_EQ(1, browser()->tab_strip_model()->count());
meacerc62e2ee2014-10-22 00:44:52752 EXPECT_EQ(1, params.browser->tab_strip_model()->count());
[email protected]a1feae52010-10-11 22:14:45753}
754#endif
755
756// This tests adding a tab at a specific index.
757IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Tabstrip_InsertAtIndex) {
758 // This is not meant to be a comprehensive test of whether or not the tab
759 // implementation of the browser observes the insertion index. That is
760 // covered by the unit tests for TabStripModel. This merely verifies that
761 // insertion index preference is reflected in common cases.
meacerc62e2ee2014-10-22 00:44:52762 chrome::NavigateParams params(MakeNavigateParams());
763 params.disposition = NEW_FOREGROUND_TAB;
764 params.tabstrip_index = 0;
765 params.tabstrip_add_types = TabStripModel::ADD_FORCE_INDEX;
766 chrome::Navigate(&params);
[email protected]a1feae52010-10-11 22:14:45767
768 // Navigate() should have inserted a new tab at slot 0 in the tabstrip.
meacerc62e2ee2014-10-22 00:44:52769 EXPECT_EQ(browser(), params.browser);
[email protected]e232c992012-12-06 12:43:20770 EXPECT_EQ(0, browser()->tab_strip_model()->GetIndexOfWebContents(
meacerc62e2ee2014-10-22 00:44:52771 static_cast<const WebContents*>(params.target_contents)));
[email protected]a1feae52010-10-11 22:14:45772
773 // We should have one window - the browser() provided by the framework.
[email protected]0665ebe2013-02-13 09:53:19774 EXPECT_EQ(1u, chrome::GetTotalBrowserCount());
[email protected]ee496952013-01-10 23:17:33775 EXPECT_EQ(2, browser()->tab_strip_model()->count());
[email protected]a1feae52010-10-11 22:14:45776}
777
[email protected]bb89e7482010-11-17 18:27:04778// This test verifies that constructing params with disposition = SINGLETON_TAB
[email protected]fee320542011-03-02 01:30:49779// and IGNORE_AND_NAVIGATE opens a new tab navigated to the specified URL if
[email protected]67ed83e2011-01-07 22:54:00780// no previous tab with that URL (minus the path) exists.
[email protected]bb89e7482010-11-17 18:27:04781IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
782 Disposition_SingletonTabNew_IgnorePath) {
[email protected]52877dbc62012-06-29 22:22:03783 chrome::AddSelectedTabWithURL(browser(), GetGoogleURL(),
Sylvain Defresnec6ccc77d2014-09-19 10:19:35784 ui::PAGE_TRANSITION_LINK);
[email protected]bb89e7482010-11-17 18:27:04785
786 // We should have one browser with 2 tabs, the 2nd selected.
[email protected]0665ebe2013-02-13 09:53:19787 EXPECT_EQ(1u, chrome::GetTotalBrowserCount());
[email protected]ee496952013-01-10 23:17:33788 EXPECT_EQ(2, browser()->tab_strip_model()->count());
789 EXPECT_EQ(1, browser()->tab_strip_model()->active_index());
[email protected]bb89e7482010-11-17 18:27:04790
791 // Navigate to a new singleton tab with a sub-page.
meacerc62e2ee2014-10-22 00:44:52792 chrome::NavigateParams params(MakeNavigateParams());
793 params.disposition = SINGLETON_TAB;
794 params.url = GetContentSettingsURL();
795 params.window_action = chrome::NavigateParams::SHOW_WINDOW;
796 params.path_behavior = chrome::NavigateParams::IGNORE_AND_NAVIGATE;
797 chrome::Navigate(&params);
[email protected]bb89e7482010-11-17 18:27:04798
799 // The last tab should now be selected and navigated to the sub-page of the
[email protected]50592b52013-05-02 22:26:25800 // URL.
meacerc62e2ee2014-10-22 00:44:52801 EXPECT_EQ(browser(), params.browser);
[email protected]ee496952013-01-10 23:17:33802 EXPECT_EQ(3, browser()->tab_strip_model()->count());
803 EXPECT_EQ(2, browser()->tab_strip_model()->active_index());
[email protected]a048ad22012-03-23 04:26:56804 EXPECT_EQ(GetContentSettingsURL(),
[email protected]ee496952013-01-10 23:17:33805 ShortenUberURL(browser()->tab_strip_model()->
806 GetActiveWebContents()->GetURL()));
[email protected]bb89e7482010-11-17 18:27:04807}
808
809// This test verifies that constructing params with disposition = SINGLETON_TAB
[email protected]fee320542011-03-02 01:30:49810// and IGNORE_AND_NAVIGATE opens an existing tab with the matching URL (minus
[email protected]bb89e7482010-11-17 18:27:04811// the path) which is navigated to the specified URL.
812IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
813 Disposition_SingletonTabExisting_IgnorePath) {
[email protected]ddddfda2011-07-14 23:19:39814 GURL singleton_url1(GetSettingsURL());
[email protected]52877dbc62012-06-29 22:22:03815 chrome::AddSelectedTabWithURL(browser(), singleton_url1,
Sylvain Defresnec6ccc77d2014-09-19 10:19:35816 ui::PAGE_TRANSITION_LINK);
[email protected]52877dbc62012-06-29 22:22:03817 chrome::AddSelectedTabWithURL(browser(), GetGoogleURL(),
Sylvain Defresnec6ccc77d2014-09-19 10:19:35818 ui::PAGE_TRANSITION_LINK);
[email protected]bb89e7482010-11-17 18:27:04819
820 // We should have one browser with 3 tabs, the 3rd selected.
[email protected]0665ebe2013-02-13 09:53:19821 EXPECT_EQ(1u, chrome::GetTotalBrowserCount());
[email protected]ee496952013-01-10 23:17:33822 EXPECT_EQ(3, browser()->tab_strip_model()->count());
823 EXPECT_EQ(2, browser()->tab_strip_model()->active_index());
[email protected]bb89e7482010-11-17 18:27:04824
825 // Navigate to singleton_url1.
meacerc62e2ee2014-10-22 00:44:52826 chrome::NavigateParams params(MakeNavigateParams());
827 params.disposition = SINGLETON_TAB;
828 params.url = GetContentSettingsURL();
829 params.window_action = chrome::NavigateParams::SHOW_WINDOW;
830 params.path_behavior = chrome::NavigateParams::IGNORE_AND_NAVIGATE;
831 chrome::Navigate(&params);
[email protected]bb89e7482010-11-17 18:27:04832
833 // The middle tab should now be selected and navigated to the sub-page of the
834 // URL.
meacerc62e2ee2014-10-22 00:44:52835 EXPECT_EQ(browser(), params.browser);
[email protected]ee496952013-01-10 23:17:33836 EXPECT_EQ(3, browser()->tab_strip_model()->count());
837 EXPECT_EQ(1, browser()->tab_strip_model()->active_index());
[email protected]a048ad22012-03-23 04:26:56838 EXPECT_EQ(GetContentSettingsURL(),
[email protected]ee496952013-01-10 23:17:33839 ShortenUberURL(browser()->tab_strip_model()->
840 GetActiveWebContents()->GetURL()));
[email protected]bb89e7482010-11-17 18:27:04841}
842
843// This test verifies that constructing params with disposition = SINGLETON_TAB
[email protected]fee320542011-03-02 01:30:49844// and IGNORE_AND_NAVIGATE opens an existing tab with the matching URL (minus
[email protected]bb89e7482010-11-17 18:27:04845// the path) which is navigated to the specified URL.
846IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
847 Disposition_SingletonTabExistingSubPath_IgnorePath) {
[email protected]a048ad22012-03-23 04:26:56848 GURL singleton_url1(GetContentSettingsURL());
[email protected]52877dbc62012-06-29 22:22:03849 chrome::AddSelectedTabWithURL(browser(), singleton_url1,
Sylvain Defresnec6ccc77d2014-09-19 10:19:35850 ui::PAGE_TRANSITION_LINK);
[email protected]52877dbc62012-06-29 22:22:03851 chrome::AddSelectedTabWithURL(browser(), GetGoogleURL(),
Sylvain Defresnec6ccc77d2014-09-19 10:19:35852 ui::PAGE_TRANSITION_LINK);
[email protected]bb89e7482010-11-17 18:27:04853
854 // We should have one browser with 3 tabs, the 3rd selected.
[email protected]0665ebe2013-02-13 09:53:19855 EXPECT_EQ(1u, chrome::GetTotalBrowserCount());
[email protected]ee496952013-01-10 23:17:33856 EXPECT_EQ(3, browser()->tab_strip_model()->count());
857 EXPECT_EQ(2, browser()->tab_strip_model()->active_index());
[email protected]bb89e7482010-11-17 18:27:04858
859 // Navigate to singleton_url1.
meacerc62e2ee2014-10-22 00:44:52860 chrome::NavigateParams params(MakeNavigateParams());
861 params.disposition = SINGLETON_TAB;
862 params.url = GetClearBrowsingDataURL();
863 params.window_action = chrome::NavigateParams::SHOW_WINDOW;
864 params.path_behavior = chrome::NavigateParams::IGNORE_AND_NAVIGATE;
865 chrome::Navigate(&params);
[email protected]bb89e7482010-11-17 18:27:04866
867 // The middle tab should now be selected and navigated to the sub-page of the
868 // URL.
meacerc62e2ee2014-10-22 00:44:52869 EXPECT_EQ(browser(), params.browser);
[email protected]ee496952013-01-10 23:17:33870 EXPECT_EQ(3, browser()->tab_strip_model()->count());
871 EXPECT_EQ(1, browser()->tab_strip_model()->active_index());
[email protected]a048ad22012-03-23 04:26:56872 EXPECT_EQ(GetClearBrowsingDataURL(),
[email protected]ee496952013-01-10 23:17:33873 ShortenUberURL(browser()->tab_strip_model()->
874 GetActiveWebContents()->GetURL()));
[email protected]bb89e7482010-11-17 18:27:04875}
[email protected]2dd85482010-11-06 01:56:47876
[email protected]637b3442011-01-10 23:31:48877// This test verifies that constructing params with disposition = SINGLETON_TAB
[email protected]fee320542011-03-02 01:30:49878// and IGNORE_AND_STAY_PUT opens an existing tab with the matching URL (minus
879// the path).
880IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
881 Disposition_SingletonTabExistingSubPath_IgnorePath2) {
[email protected]a048ad22012-03-23 04:26:56882 GURL singleton_url1(GetContentSettingsURL());
[email protected]52877dbc62012-06-29 22:22:03883 chrome::AddSelectedTabWithURL(browser(), singleton_url1,
Sylvain Defresnec6ccc77d2014-09-19 10:19:35884 ui::PAGE_TRANSITION_LINK);
[email protected]52877dbc62012-06-29 22:22:03885 chrome::AddSelectedTabWithURL(browser(), GetGoogleURL(),
Sylvain Defresnec6ccc77d2014-09-19 10:19:35886 ui::PAGE_TRANSITION_LINK);
[email protected]fee320542011-03-02 01:30:49887
888 // We should have one browser with 3 tabs, the 3rd selected.
[email protected]0665ebe2013-02-13 09:53:19889 EXPECT_EQ(1u, chrome::GetTotalBrowserCount());
[email protected]ee496952013-01-10 23:17:33890 EXPECT_EQ(3, browser()->tab_strip_model()->count());
891 EXPECT_EQ(2, browser()->tab_strip_model()->active_index());
[email protected]fee320542011-03-02 01:30:49892
893 // Navigate to singleton_url1.
meacerc62e2ee2014-10-22 00:44:52894 chrome::NavigateParams params(MakeNavigateParams());
895 params.disposition = SINGLETON_TAB;
896 params.url = GetClearBrowsingDataURL();
897 params.window_action = chrome::NavigateParams::SHOW_WINDOW;
898 params.path_behavior = chrome::NavigateParams::IGNORE_AND_STAY_PUT;
899 chrome::Navigate(&params);
[email protected]fee320542011-03-02 01:30:49900
901 // The middle tab should now be selected.
meacerc62e2ee2014-10-22 00:44:52902 EXPECT_EQ(browser(), params.browser);
[email protected]ee496952013-01-10 23:17:33903 EXPECT_EQ(3, browser()->tab_strip_model()->count());
904 EXPECT_EQ(1, browser()->tab_strip_model()->active_index());
[email protected]fee320542011-03-02 01:30:49905 EXPECT_EQ(singleton_url1,
[email protected]ee496952013-01-10 23:17:33906 ShortenUberURL(browser()->tab_strip_model()->
907 GetActiveWebContents()->GetURL()));
[email protected]fee320542011-03-02 01:30:49908}
909
910// This test verifies that constructing params with disposition = SINGLETON_TAB
911// and IGNORE_AND_NAVIGATE will update the current tab's URL if the currently
[email protected]637b3442011-01-10 23:31:48912// selected tab is a match but has a different path.
913IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
914 Disposition_SingletonTabFocused_IgnorePath) {
[email protected]a048ad22012-03-23 04:26:56915 GURL singleton_url_current(GetContentSettingsURL());
[email protected]52877dbc62012-06-29 22:22:03916 chrome::AddSelectedTabWithURL(browser(), singleton_url_current,
Sylvain Defresnec6ccc77d2014-09-19 10:19:35917 ui::PAGE_TRANSITION_LINK);
[email protected]637b3442011-01-10 23:31:48918
919 // We should have one browser with 2 tabs, the 2nd selected.
[email protected]0665ebe2013-02-13 09:53:19920 EXPECT_EQ(1u, chrome::GetTotalBrowserCount());
[email protected]ee496952013-01-10 23:17:33921 EXPECT_EQ(2, browser()->tab_strip_model()->count());
922 EXPECT_EQ(1, browser()->tab_strip_model()->active_index());
[email protected]637b3442011-01-10 23:31:48923
924 // Navigate to a different settings path.
[email protected]a048ad22012-03-23 04:26:56925 GURL singleton_url_target(GetClearBrowsingDataURL());
meacerc62e2ee2014-10-22 00:44:52926 chrome::NavigateParams params(MakeNavigateParams());
927 params.disposition = SINGLETON_TAB;
928 params.url = singleton_url_target;
929 params.window_action = chrome::NavigateParams::SHOW_WINDOW;
930 params.path_behavior = chrome::NavigateParams::IGNORE_AND_NAVIGATE;
931 chrome::Navigate(&params);
[email protected]637b3442011-01-10 23:31:48932
933 // The second tab should still be selected, but navigated to the new path.
meacerc62e2ee2014-10-22 00:44:52934 EXPECT_EQ(browser(), params.browser);
[email protected]ee496952013-01-10 23:17:33935 EXPECT_EQ(2, browser()->tab_strip_model()->count());
936 EXPECT_EQ(1, browser()->tab_strip_model()->active_index());
[email protected]637b3442011-01-10 23:31:48937 EXPECT_EQ(singleton_url_target,
[email protected]ee496952013-01-10 23:17:33938 ShortenUberURL(browser()->tab_strip_model()->
939 GetActiveWebContents()->GetURL()));
[email protected]637b3442011-01-10 23:31:48940}
941
[email protected]07afd7c2011-02-17 10:07:11942// This test verifies that constructing params with disposition = SINGLETON_TAB
[email protected]fee320542011-03-02 01:30:49943// and IGNORE_AND_NAVIGATE will open an existing matching tab with a different
944// query.
[email protected]07afd7c2011-02-17 10:07:11945IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
946 Disposition_SingletonTabExisting_IgnoreQuery) {
[email protected]ee496952013-01-10 23:17:33947 int initial_tab_count = browser()->tab_strip_model()->count();
[email protected]07afd7c2011-02-17 10:07:11948 GURL singleton_url_current("chrome://settings/internet");
[email protected]52877dbc62012-06-29 22:22:03949 chrome::AddSelectedTabWithURL(browser(), singleton_url_current,
Sylvain Defresnec6ccc77d2014-09-19 10:19:35950 ui::PAGE_TRANSITION_LINK);
[email protected]07afd7c2011-02-17 10:07:11951
[email protected]ee496952013-01-10 23:17:33952 EXPECT_EQ(initial_tab_count + 1, browser()->tab_strip_model()->count());
953 EXPECT_EQ(initial_tab_count, browser()->tab_strip_model()->active_index());
[email protected]07afd7c2011-02-17 10:07:11954
955 // Navigate to a different settings path.
956 GURL singleton_url_target(
957 "chrome://settings/internet?"
stevenjb82dbc53092015-03-14 18:32:24958 "guid=ethernet_00aa00aa00aa&networkType=1");
meacerc62e2ee2014-10-22 00:44:52959 chrome::NavigateParams params(MakeNavigateParams());
960 params.disposition = SINGLETON_TAB;
961 params.url = singleton_url_target;
962 params.window_action = chrome::NavigateParams::SHOW_WINDOW;
963 params.path_behavior = chrome::NavigateParams::IGNORE_AND_NAVIGATE;
964 chrome::Navigate(&params);
[email protected]07afd7c2011-02-17 10:07:11965
966 // Last tab should still be selected.
meacerc62e2ee2014-10-22 00:44:52967 EXPECT_EQ(browser(), params.browser);
[email protected]ee496952013-01-10 23:17:33968 EXPECT_EQ(initial_tab_count + 1, browser()->tab_strip_model()->count());
969 EXPECT_EQ(initial_tab_count, browser()->tab_strip_model()->active_index());
[email protected]07afd7c2011-02-17 10:07:11970}
971
[email protected]bd817c22011-02-09 08:16:46972// This test verifies that the settings page isn't opened in the incognito
973// window.
[email protected]a048ad22012-03-23 04:26:56974// Disabled until fixed for uber settings: http://crbug.com/111243
[email protected]bd817c22011-02-09 08:16:46975IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
[email protected]a048ad22012-03-23 04:26:56976 DISABLED_Disposition_Settings_UseNonIncognitoWindow) {
[email protected]fc0ed302011-11-29 23:17:19977 RunUseNonIncognitoWindowTest(GetSettingsURL());
[email protected]bd817c22011-02-09 08:16:46978}
979
[email protected]429e9712013-04-30 09:35:50980// This test verifies that the view-source settings page isn't opened in the
981// incognito window.
982IN_PROC_BROWSER_TEST_F(
983 BrowserNavigatorTest,
984 Disposition_ViewSource_Settings_DoNothingIfIncognitoForced) {
[email protected]dbdda5402013-05-30 22:13:48985 std::string view_source(content::kViewSourceScheme);
[email protected]429e9712013-04-30 09:35:50986 view_source.append(":");
987 view_source.append(chrome::kChromeUISettingsURL);
988 RunDoNothingIfIncognitoIsForcedTest(GURL(view_source));
989}
990
991// This test verifies that the view-source settings page isn't opened in the
992// incognito window even if incognito mode is forced (does nothing in that
993// case).
994IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
995 Disposition_ViewSource_Settings_UseNonIncognitoWindow) {
[email protected]dbdda5402013-05-30 22:13:48996 std::string view_source(content::kViewSourceScheme);
[email protected]429e9712013-04-30 09:35:50997 view_source.append(":");
998 view_source.append(chrome::kChromeUISettingsURL);
999 RunUseNonIncognitoWindowTest(GURL(view_source));
1000}
1001
[email protected]82404cd2011-07-12 19:55:141002// This test verifies that the settings page isn't opened in the incognito
1003// window from a non-incognito window (bookmark open-in-incognito trigger).
[email protected]a048ad22012-03-23 04:26:561004// Disabled until fixed for uber settings: http://crbug.com/111243
[email protected]82404cd2011-07-12 19:55:141005IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
[email protected]a048ad22012-03-23 04:26:561006 DISABLED_Disposition_Settings_UseNonIncognitoWindowForBookmark) {
[email protected]78e2edc2012-07-01 23:32:281007 chrome::NavigateParams params(browser(), GetSettingsURL(),
Sylvain Defresnec6ccc77d2014-09-19 10:19:351008 ui::PAGE_TRANSITION_AUTO_BOOKMARK);
[email protected]82404cd2011-07-12 19:55:141009 params.disposition = OFF_THE_RECORD;
1010 {
[email protected]a7fe9112012-07-20 02:34:451011 content::WindowedNotificationObserver observer(
[email protected]ad50def52011-10-19 23:17:071012 content::NOTIFICATION_LOAD_STOP,
1013 content::NotificationService::AllSources());
[email protected]78e2edc2012-07-01 23:32:281014 chrome::Navigate(&params);
[email protected]82404cd2011-07-12 19:55:141015 observer.Wait();
1016 }
1017
[email protected]0665ebe2013-02-13 09:53:191018 EXPECT_EQ(1u, chrome::GetTotalBrowserCount());
[email protected]52877dbc62012-06-29 22:22:031019 EXPECT_EQ(GetSettingsURL(),
[email protected]ee496952013-01-10 23:17:331020 ShortenUberURL(browser()->tab_strip_model()->
1021 GetActiveWebContents()->GetURL()));
[email protected]82404cd2011-07-12 19:55:141022}
1023
[email protected]93ad8e1c2011-11-08 21:34:051024// Settings page is expected to always open in normal mode regardless
1025// of whether the user is trying to open it in incognito mode or not.
1026// This test verifies that if incognito mode is forced (by policy), settings
1027// page doesn't open at all.
[email protected]a048ad22012-03-23 04:26:561028// Disabled until fixed for uber settings: http://crbug.com/111243
[email protected]93ad8e1c2011-11-08 21:34:051029IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
[email protected]a048ad22012-03-23 04:26:561030 DISABLED_Disposition_Settings_DoNothingIfIncognitoIsForced) {
[email protected]fc0ed302011-11-29 23:17:191031 RunDoNothingIfIncognitoIsForcedTest(GetSettingsURL());
[email protected]93ad8e1c2011-11-08 21:34:051032}
1033
[email protected]bd817c22011-02-09 08:16:461034// This test verifies that the bookmarks page isn't opened in the incognito
1035// window.
1036IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
1037 Disposition_Bookmarks_UseNonIncognitoWindow) {
[email protected]fc0ed302011-11-29 23:17:191038 RunUseNonIncognitoWindowTest(GURL(chrome::kChromeUIBookmarksURL));
[email protected]bd817c22011-02-09 08:16:461039}
1040
[email protected]93ad8e1c2011-11-08 21:34:051041// Bookmark manager is expected to always open in normal mode regardless
1042// of whether the user is trying to open it in incognito mode or not.
1043// This test verifies that if incognito mode is forced (by policy), bookmark
1044// manager doesn't open at all.
1045IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
1046 Disposition_Bookmarks_DoNothingIfIncognitoIsForced) {
[email protected]fc0ed302011-11-29 23:17:191047 RunDoNothingIfIncognitoIsForcedTest(GURL(chrome::kChromeUIBookmarksURL));
1048}
[email protected]93ad8e1c2011-11-08 21:34:051049
[email protected]7de53c62011-05-13 06:44:161050// This test makes sure a crashed singleton tab reloads from a new navigation.
[email protected]c4c0c0a12014-07-23 17:06:021051// http://crbug.com/396371
[email protected]7de53c62011-05-13 06:44:161052IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
[email protected]c4c0c0a12014-07-23 17:06:021053 DISABLED_NavigateToCrashedSingletonTab) {
[email protected]a048ad22012-03-23 04:26:561054 GURL singleton_url(GetContentSettingsURL());
[email protected]5a1a52462012-11-15 03:35:161055 WebContents* web_contents = chrome::AddSelectedTabWithURL(
Sylvain Defresnec6ccc77d2014-09-19 10:19:351056 browser(), singleton_url, ui::PAGE_TRANSITION_LINK);
[email protected]7de53c62011-05-13 06:44:161057
1058 // We should have one browser with 2 tabs, the 2nd selected.
[email protected]0665ebe2013-02-13 09:53:191059 EXPECT_EQ(1u, chrome::GetTotalBrowserCount());
[email protected]ee496952013-01-10 23:17:331060 EXPECT_EQ(2, browser()->tab_strip_model()->count());
1061 EXPECT_EQ(1, browser()->tab_strip_model()->active_index());
[email protected]7de53c62011-05-13 06:44:161062
1063 // Kill the singleton tab.
[email protected]83ff91c2012-01-05 20:54:131064 web_contents->SetIsCrashed(base::TERMINATION_STATUS_PROCESS_CRASHED, -1);
1065 EXPECT_TRUE(web_contents->IsCrashed());
[email protected]7de53c62011-05-13 06:44:161066
meacerc62e2ee2014-10-22 00:44:521067 chrome::NavigateParams params(MakeNavigateParams());
1068 params.disposition = SINGLETON_TAB;
1069 params.url = singleton_url;
1070 params.window_action = chrome::NavigateParams::SHOW_WINDOW;
1071 params.path_behavior = chrome::NavigateParams::IGNORE_AND_NAVIGATE;
1072 ui_test_utils::NavigateToURL(&params);
[email protected]7de53c62011-05-13 06:44:161073
1074 // The tab should not be sad anymore.
[email protected]83ff91c2012-01-05 20:54:131075 EXPECT_FALSE(web_contents->IsCrashed());
[email protected]7de53c62011-05-13 06:44:161076}
1077
[email protected]fcca741b2011-06-17 22:46:371078IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
1079 NavigateFromDefaultToOptionsInSameTab) {
[email protected]ddddfda2011-07-14 23:19:391080 {
[email protected]a7fe9112012-07-20 02:34:451081 content::WindowedNotificationObserver observer(
[email protected]ad50def52011-10-19 23:17:071082 content::NOTIFICATION_LOAD_STOP,
1083 content::NotificationService::AllSources());
[email protected]5d9cace72012-06-21 16:07:121084 chrome::ShowSettings(browser());
[email protected]ddddfda2011-07-14 23:19:391085 observer.Wait();
1086 }
[email protected]ee496952013-01-10 23:17:331087 EXPECT_EQ(1, browser()->tab_strip_model()->count());
[email protected]52877dbc62012-06-29 22:22:031088 EXPECT_EQ(GetSettingsURL(),
[email protected]ee496952013-01-10 23:17:331089 ShortenUberURL(browser()->tab_strip_model()->
1090 GetActiveWebContents()->GetURL()));
[email protected]fcca741b2011-06-17 22:46:371091}
1092
1093IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
1094 NavigateFromBlankToOptionsInSameTab) {
meacerc62e2ee2014-10-22 00:44:521095 chrome::NavigateParams params(MakeNavigateParams());
1096 params.url = GURL(url::kAboutBlankURL);
1097 ui_test_utils::NavigateToURL(&params);
[email protected]fcca741b2011-06-17 22:46:371098
[email protected]ddddfda2011-07-14 23:19:391099 {
[email protected]a7fe9112012-07-20 02:34:451100 content::WindowedNotificationObserver observer(
[email protected]ad50def52011-10-19 23:17:071101 content::NOTIFICATION_LOAD_STOP,
1102 content::NotificationService::AllSources());
[email protected]5d9cace72012-06-21 16:07:121103 chrome::ShowSettings(browser());
[email protected]ddddfda2011-07-14 23:19:391104 observer.Wait();
1105 }
[email protected]ee496952013-01-10 23:17:331106 EXPECT_EQ(1, browser()->tab_strip_model()->count());
[email protected]52877dbc62012-06-29 22:22:031107 EXPECT_EQ(GetSettingsURL(),
[email protected]ee496952013-01-10 23:17:331108 ShortenUberURL(browser()->tab_strip_model()->
1109 GetActiveWebContents()->GetURL()));
[email protected]fcca741b2011-06-17 22:46:371110}
1111
1112IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
1113 NavigateFromNTPToOptionsInSameTab) {
meacerc62e2ee2014-10-22 00:44:521114 chrome::NavigateParams params(MakeNavigateParams());
1115 params.url = GURL(chrome::kChromeUINewTabURL);
1116 ui_test_utils::NavigateToURL(&params);
[email protected]ee496952013-01-10 23:17:331117 EXPECT_EQ(1, browser()->tab_strip_model()->count());
[email protected]27658f32013-11-14 03:20:371118 EXPECT_EQ(GURL(chrome::kChromeUINewTabURL),
1119 browser()->tab_strip_model()->GetActiveWebContents()->GetURL());
[email protected]fcca741b2011-06-17 22:46:371120
[email protected]ddddfda2011-07-14 23:19:391121 {
[email protected]a7fe9112012-07-20 02:34:451122 content::WindowedNotificationObserver observer(
[email protected]ad50def52011-10-19 23:17:071123 content::NOTIFICATION_LOAD_STOP,
1124 content::NotificationService::AllSources());
[email protected]5d9cace72012-06-21 16:07:121125 chrome::ShowSettings(browser());
[email protected]ddddfda2011-07-14 23:19:391126 observer.Wait();
1127 }
[email protected]ee496952013-01-10 23:17:331128 EXPECT_EQ(1, browser()->tab_strip_model()->count());
[email protected]52877dbc62012-06-29 22:22:031129 EXPECT_EQ(GetSettingsURL(),
[email protected]ee496952013-01-10 23:17:331130 ShortenUberURL(browser()->tab_strip_model()->
1131 GetActiveWebContents()->GetURL()));
[email protected]fcca741b2011-06-17 22:46:371132}
1133
1134IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
1135 NavigateFromPageToOptionsInNewTab) {
meacerc62e2ee2014-10-22 00:44:521136 chrome::NavigateParams params(MakeNavigateParams());
1137 ui_test_utils::NavigateToURL(&params);
[email protected]ee496952013-01-10 23:17:331138 EXPECT_EQ(GetGoogleURL(),
1139 browser()->tab_strip_model()->GetActiveWebContents()->GetURL());
[email protected]0665ebe2013-02-13 09:53:191140 EXPECT_EQ(1u, chrome::GetTotalBrowserCount());
[email protected]ee496952013-01-10 23:17:331141 EXPECT_EQ(1, browser()->tab_strip_model()->count());
[email protected]fcca741b2011-06-17 22:46:371142
[email protected]ddddfda2011-07-14 23:19:391143 {
[email protected]a7fe9112012-07-20 02:34:451144 content::WindowedNotificationObserver observer(
[email protected]ad50def52011-10-19 23:17:071145 content::NOTIFICATION_LOAD_STOP,
1146 content::NotificationService::AllSources());
[email protected]5d9cace72012-06-21 16:07:121147 chrome::ShowSettings(browser());
[email protected]ddddfda2011-07-14 23:19:391148 observer.Wait();
1149 }
[email protected]ee496952013-01-10 23:17:331150 EXPECT_EQ(2, browser()->tab_strip_model()->count());
[email protected]52877dbc62012-06-29 22:22:031151 EXPECT_EQ(GetSettingsURL(),
[email protected]ee496952013-01-10 23:17:331152 ShortenUberURL(browser()->tab_strip_model()->
1153 GetActiveWebContents()->GetURL()));
[email protected]fcca741b2011-06-17 22:46:371154}
1155
1156IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
1157 NavigateFromNTPToOptionsSingleton) {
[email protected]ddddfda2011-07-14 23:19:391158 {
[email protected]a7fe9112012-07-20 02:34:451159 content::WindowedNotificationObserver observer(
[email protected]ad50def52011-10-19 23:17:071160 content::NOTIFICATION_LOAD_STOP,
1161 content::NotificationService::AllSources());
[email protected]5d9cace72012-06-21 16:07:121162 chrome::ShowSettings(browser());
[email protected]ddddfda2011-07-14 23:19:391163 observer.Wait();
1164 }
[email protected]ee496952013-01-10 23:17:331165 EXPECT_EQ(1, browser()->tab_strip_model()->count());
[email protected]fcca741b2011-06-17 22:46:371166
[email protected]a37d4b02012-06-25 21:56:101167 chrome::NewTab(browser());
[email protected]ee496952013-01-10 23:17:331168 EXPECT_EQ(2, browser()->tab_strip_model()->count());
[email protected]fcca741b2011-06-17 22:46:371169
[email protected]ddddfda2011-07-14 23:19:391170 {
[email protected]a7fe9112012-07-20 02:34:451171 content::WindowedNotificationObserver observer(
[email protected]ad50def52011-10-19 23:17:071172 content::NOTIFICATION_LOAD_STOP,
1173 content::NotificationService::AllSources());
[email protected]5d9cace72012-06-21 16:07:121174 chrome::ShowSettings(browser());
[email protected]ddddfda2011-07-14 23:19:391175 observer.Wait();
1176 }
[email protected]ee496952013-01-10 23:17:331177 EXPECT_EQ(2, browser()->tab_strip_model()->count());
[email protected]52877dbc62012-06-29 22:22:031178 EXPECT_EQ(GetSettingsURL(),
[email protected]ee496952013-01-10 23:17:331179 ShortenUberURL(browser()->tab_strip_model()->
1180 GetActiveWebContents()->GetURL()));
[email protected]fcca741b2011-06-17 22:46:371181}
1182
1183IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
1184 NavigateFromNTPToOptionsPageInSameTab) {
[email protected]ddddfda2011-07-14 23:19:391185 {
[email protected]a7fe9112012-07-20 02:34:451186 content::WindowedNotificationObserver observer(
[email protected]ad50def52011-10-19 23:17:071187 content::NOTIFICATION_LOAD_STOP,
1188 content::NotificationService::AllSources());
[email protected]5d9cace72012-06-21 16:07:121189 chrome::ShowClearBrowsingDataDialog(browser());
[email protected]ddddfda2011-07-14 23:19:391190 observer.Wait();
1191 }
[email protected]ee496952013-01-10 23:17:331192 EXPECT_EQ(1, browser()->tab_strip_model()->count());
[email protected]a048ad22012-03-23 04:26:561193 EXPECT_EQ(GetClearBrowsingDataURL(),
[email protected]ee496952013-01-10 23:17:331194 browser()->tab_strip_model()->GetActiveWebContents()->GetURL());
[email protected]fcca741b2011-06-17 22:46:371195
[email protected]a37d4b02012-06-25 21:56:101196 chrome::NewTab(browser());
[email protected]ee496952013-01-10 23:17:331197 EXPECT_EQ(2, browser()->tab_strip_model()->count());
[email protected]fcca741b2011-06-17 22:46:371198
[email protected]ddddfda2011-07-14 23:19:391199 {
[email protected]a7fe9112012-07-20 02:34:451200 content::WindowedNotificationObserver observer(
[email protected]ad50def52011-10-19 23:17:071201 content::NOTIFICATION_LOAD_STOP,
1202 content::NotificationService::AllSources());
[email protected]5d9cace72012-06-21 16:07:121203 chrome::ShowClearBrowsingDataDialog(browser());
[email protected]ddddfda2011-07-14 23:19:391204 observer.Wait();
1205 }
[email protected]ee496952013-01-10 23:17:331206 EXPECT_EQ(2, browser()->tab_strip_model()->count());
[email protected]a048ad22012-03-23 04:26:561207 EXPECT_EQ(GetClearBrowsingDataURL(),
[email protected]ee496952013-01-10 23:17:331208 browser()->tab_strip_model()->GetActiveWebContents()->GetURL());
[email protected]fcca741b2011-06-17 22:46:371209}
1210
[email protected]fcca741b2011-06-17 22:46:371211IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
[email protected]05912742013-03-12 00:29:151212 NavigateFromOtherTabToSingletonOptions) {
[email protected]ddddfda2011-07-14 23:19:391213 {
[email protected]a7fe9112012-07-20 02:34:451214 content::WindowedNotificationObserver observer(
[email protected]ad50def52011-10-19 23:17:071215 content::NOTIFICATION_LOAD_STOP,
1216 content::NotificationService::AllSources());
[email protected]5d9cace72012-06-21 16:07:121217 chrome::ShowSettings(browser());
[email protected]ddddfda2011-07-14 23:19:391218 observer.Wait();
1219 }
1220 {
[email protected]a7fe9112012-07-20 02:34:451221 content::WindowedNotificationObserver observer(
[email protected]ad50def52011-10-19 23:17:071222 content::NOTIFICATION_LOAD_STOP,
1223 content::NotificationService::AllSources());
[email protected]52877dbc62012-06-29 22:22:031224 chrome::AddSelectedTabWithURL(browser(), GetGoogleURL(),
Sylvain Defresnec6ccc77d2014-09-19 10:19:351225 ui::PAGE_TRANSITION_LINK);
[email protected]ddddfda2011-07-14 23:19:391226 observer.Wait();
1227 }
[email protected]fcca741b2011-06-17 22:46:371228
[email protected]05912742013-03-12 00:29:151229 // This load should simply cause a tab switch.
1230 chrome::ShowSettings(browser());
1231
[email protected]ee496952013-01-10 23:17:331232 EXPECT_EQ(2, browser()->tab_strip_model()->count());
[email protected]ddddfda2011-07-14 23:19:391233 EXPECT_EQ(GetSettingsURL(),
[email protected]ee496952013-01-10 23:17:331234 ShortenUberURL(browser()->tab_strip_model()->
1235 GetActiveWebContents()->GetURL()));
[email protected]fcca741b2011-06-17 22:46:371236}
1237
[email protected]4e78b2d2013-06-12 16:46:171238IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, CloseSingletonTab) {
[email protected]79717cf2013-02-28 18:40:361239 for (int i = 0; i < 2; ++i) {
1240 content::WindowedNotificationObserver observer(
1241 content::NOTIFICATION_LOAD_STOP,
1242 content::NotificationService::AllSources());
1243 chrome::AddSelectedTabWithURL(browser(), GetGoogleURL(),
Sylvain Defresnec6ccc77d2014-09-19 10:19:351244 ui::PAGE_TRANSITION_TYPED);
[email protected]79717cf2013-02-28 18:40:361245 observer.Wait();
1246 }
1247
1248 browser()->tab_strip_model()->ActivateTabAt(0, true);
1249
1250 {
1251 content::WindowedNotificationObserver observer(
1252 content::NOTIFICATION_LOAD_STOP,
1253 content::NotificationService::AllSources());
1254 chrome::ShowSettings(browser());
1255 observer.Wait();
1256 }
1257
1258 EXPECT_TRUE(browser()->tab_strip_model()->CloseWebContentsAt(
1259 2, TabStripModel::CLOSE_USER_GESTURE));
1260 EXPECT_EQ(0, browser()->tab_strip_model()->active_index());
1261}
1262
[email protected]a048ad22012-03-23 04:26:561263// TODO(csilv): Update this for uber page. http://crbug.com/111579.
[email protected]ddddfda2011-07-14 23:19:391264IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
[email protected]a048ad22012-03-23 04:26:561265 DISABLED_NavigateFromDefaultToHistoryInSameTab) {
[email protected]ddddfda2011-07-14 23:19:391266 {
[email protected]a7fe9112012-07-20 02:34:451267 content::WindowedNotificationObserver observer(
[email protected]ad50def52011-10-19 23:17:071268 content::NOTIFICATION_LOAD_STOP,
1269 content::NotificationService::AllSources());
[email protected]5d9cace72012-06-21 16:07:121270 chrome::ShowHistory(browser());
[email protected]ddddfda2011-07-14 23:19:391271 observer.Wait();
1272 }
[email protected]ee496952013-01-10 23:17:331273 EXPECT_EQ(1, browser()->tab_strip_model()->count());
[email protected]11e03fb2012-03-03 19:07:051274 EXPECT_EQ(GURL(chrome::kChromeUIHistoryFrameURL),
[email protected]ee496952013-01-10 23:17:331275 browser()->tab_strip_model()->GetActiveWebContents()->GetURL());
[email protected]ddddfda2011-07-14 23:19:391276}
1277
[email protected]953c2132013-02-23 05:56:051278// TODO(linux_aura) http://crbug.com/163931
1279#if defined(OS_LINUX) && !defined(OS_CHROMEOS) && defined(USE_AURA)
1280#define MAYBE_NavigateFromDefaultToBookmarksInSameTab DISABLED_NavigateFromDefaultToBookmarksInSameTab
1281#else
1282#define MAYBE_NavigateFromDefaultToBookmarksInSameTab NavigateFromDefaultToBookmarksInSameTab
1283#endif
[email protected]ddddfda2011-07-14 23:19:391284IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
[email protected]953c2132013-02-23 05:56:051285 MAYBE_NavigateFromDefaultToBookmarksInSameTab) {
[email protected]ddddfda2011-07-14 23:19:391286 {
[email protected]a7fe9112012-07-20 02:34:451287 content::WindowedNotificationObserver observer(
[email protected]ad50def52011-10-19 23:17:071288 content::NOTIFICATION_LOAD_STOP,
1289 content::NotificationService::AllSources());
[email protected]5d9cace72012-06-21 16:07:121290 chrome::ShowBookmarkManager(browser());
[email protected]ddddfda2011-07-14 23:19:391291 observer.Wait();
1292 }
[email protected]ee496952013-01-10 23:17:331293 EXPECT_EQ(1, browser()->tab_strip_model()->count());
brettw66d1b81b2015-07-06 19:29:401294 EXPECT_TRUE(base::StartsWith(
[email protected]bc16a252013-01-23 02:21:491295 browser()->tab_strip_model()->GetActiveWebContents()->GetURL().spec(),
brettw66d1b81b2015-07-06 19:29:401296 chrome::kChromeUIBookmarksURL, base::CompareCase::SENSITIVE));
[email protected]ddddfda2011-07-14 23:19:391297}
1298
1299IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
1300 NavigateFromDefaultToDownloadsInSameTab) {
1301 {
[email protected]a7fe9112012-07-20 02:34:451302 content::WindowedNotificationObserver observer(
[email protected]ad50def52011-10-19 23:17:071303 content::NOTIFICATION_LOAD_STOP,
1304 content::NotificationService::AllSources());
[email protected]5d9cace72012-06-21 16:07:121305 chrome::ShowDownloads(browser());
[email protected]ddddfda2011-07-14 23:19:391306 observer.Wait();
1307 }
[email protected]ee496952013-01-10 23:17:331308 EXPECT_EQ(1, browser()->tab_strip_model()->count());
[email protected]ddddfda2011-07-14 23:19:391309 EXPECT_EQ(GURL(chrome::kChromeUIDownloadsURL),
[email protected]ee496952013-01-10 23:17:331310 browser()->tab_strip_model()->GetActiveWebContents()->GetURL());
[email protected]ddddfda2011-07-14 23:19:391311}
1312
[email protected]8fb16a82012-08-17 02:17:591313IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
1314 NavigateWithoutBrowser) {
1315 // First navigate using the profile of the existing browser window, and
1316 // check that the window is reused.
1317 chrome::NavigateParams params(browser()->profile(), GetGoogleURL(),
Sylvain Defresnec6ccc77d2014-09-19 10:19:351318 ui::PAGE_TRANSITION_LINK);
[email protected]8fb16a82012-08-17 02:17:591319 ui_test_utils::NavigateToURL(&params);
[email protected]0665ebe2013-02-13 09:53:191320 EXPECT_EQ(1u, chrome::GetTotalBrowserCount());
[email protected]8fb16a82012-08-17 02:17:591321
1322 // Now navigate using the incognito profile and check that a new window
1323 // is created.
1324 chrome::NavigateParams params_incognito(
1325 browser()->profile()->GetOffTheRecordProfile(),
Sylvain Defresnec6ccc77d2014-09-19 10:19:351326 GetGoogleURL(), ui::PAGE_TRANSITION_LINK);
[email protected]8fb16a82012-08-17 02:17:591327 ui_test_utils::NavigateToURL(&params_incognito);
[email protected]0665ebe2013-02-13 09:53:191328 EXPECT_EQ(2u, chrome::GetTotalBrowserCount());
[email protected]8fb16a82012-08-17 02:17:591329}
1330
[email protected]beb1d1192013-05-14 04:47:511331IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, ViewSourceIsntSingleton) {
1332 const std::string viewsource_ntp_url =
[email protected]dbdda5402013-05-30 22:13:481333 std::string(content::kViewSourceScheme) + ":" +
[email protected]beb1d1192013-05-14 04:47:511334 chrome::kChromeUIVersionURL;
1335
1336 chrome::NavigateParams viewsource_params(browser(),
1337 GURL(viewsource_ntp_url),
Sylvain Defresnec6ccc77d2014-09-19 10:19:351338 ui::PAGE_TRANSITION_LINK);
[email protected]beb1d1192013-05-14 04:47:511339 ui_test_utils::NavigateToURL(&viewsource_params);
1340
1341 chrome::NavigateParams singleton_params(browser(),
1342 GURL(chrome::kChromeUIVersionURL),
Sylvain Defresnec6ccc77d2014-09-19 10:19:351343 ui::PAGE_TRANSITION_LINK);
[email protected]beb1d1192013-05-14 04:47:511344 singleton_params.disposition = SINGLETON_TAB;
1345 EXPECT_EQ(-1, chrome::GetIndexOfSingletonTab(&singleton_params));
1346}
1347
[email protected]a2efc35d2013-08-03 23:17:251348// This test verifies that browser initiated navigations can send requests
1349// using POST.
1350IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
1351 SendBrowserInitiatedRequestUsingPOST) {
1352 // Uses a test sever to verify POST request.
1353 ASSERT_TRUE(test_server()->Start());
1354
1355 // Open a browser initiated POST request in new foreground tab.
[email protected]e9273e192013-12-11 17:51:491356 base::string16 expected_title(base::ASCIIToUTF16(kExpectedTitle));
[email protected]a2efc35d2013-08-03 23:17:251357 std::string post_data = kExpectedTitle;
[email protected]e9273e192013-12-11 17:51:491358 base::string16 title;
[email protected]a2efc35d2013-08-03 23:17:251359 ASSERT_TRUE(OpenPOSTURLInNewForegroundTabAndGetTitle(
1360 test_server()->GetURL(kEchoTitleCommand), post_data, true, &title));
1361 EXPECT_EQ(expected_title, title);
1362}
1363
1364// This test verifies that renderer initiated navigations can NOT send requests
1365// using POST.
1366IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
1367 SendRendererInitiatedRequestUsingPOST) {
1368 // Uses a test sever to verify POST request.
1369 ASSERT_TRUE(test_server()->Start());
1370
1371 // Open a renderer initiated POST request in new foreground tab.
[email protected]e9273e192013-12-11 17:51:491372 base::string16 expected_title(base::ASCIIToUTF16(kExpectedTitle));
[email protected]a2efc35d2013-08-03 23:17:251373 std::string post_data = kExpectedTitle;
[email protected]e9273e192013-12-11 17:51:491374 base::string16 title;
[email protected]a2efc35d2013-08-03 23:17:251375 ASSERT_TRUE(OpenPOSTURLInNewForegroundTabAndGetTitle(
1376 test_server()->GetURL(kEchoTitleCommand), post_data, false, &title));
1377 EXPECT_NE(expected_title, title);
1378}
1379
meacerc62e2ee2014-10-22 00:44:521380// This test navigates to a data URL that contains BiDi control
1381// characters. For security reasons, BiDi control chars should always be
1382// escaped in the URL but they should be unescaped in the loaded HTML.
1383IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
1384 NavigateToDataURLWithBiDiControlChars) {
1385 // Text in Arabic.
1386 std::string text = "\xD8\xA7\xD8\xAE\xD8\xAA\xD8\xA8\xD8\xA7\xD8\xB1";
1387 // Page title starts with RTL mark.
1388 std::string unescaped_title = "\xE2\x80\x8F" + text;
1389 std::string data_url = "data:text/html;charset=utf-8,<html><title>" +
1390 unescaped_title + "</title></html>";
1391 // BiDi control chars in URLs are always escaped, so the expected URL should
1392 // have the title with the escaped RTL mark.
1393 std::string escaped_title = "%E2%80%8F" + text;
1394 std::string expected_url = "data:text/html;charset=utf-8,<html><title>" +
1395 escaped_title + "</title></html>";
1396
1397 // Navigate to the page.
1398 chrome::NavigateParams params(MakeNavigateParams());
1399 params.disposition = NEW_FOREGROUND_TAB;
1400 params.url = GURL(data_url);
1401 params.window_action = chrome::NavigateParams::SHOW_WINDOW;
1402 ui_test_utils::NavigateToURL(&params);
1403
1404 base::string16 expected_title(base::UTF8ToUTF16(unescaped_title));
1405 EXPECT_TRUE(params.target_contents);
1406 EXPECT_EQ(expected_title, params.target_contents->GetTitle());
1407 // GURL always keeps non-ASCII characters escaped, but check them anyways.
1408 EXPECT_EQ(GURL(expected_url).spec(), params.target_contents->GetURL().spec());
1409 // Check the omnibox text. It should have escaped RTL with unescaped text.
1410 LocationBar* location_bar = browser()->window()->GetLocationBar();
1411 OmniboxView* omnibox_view = location_bar->GetOmniboxView();
1412 EXPECT_EQ(base::UTF8ToUTF16(expected_url), omnibox_view->GetText());
1413}
1414
[email protected]a2efc35d2013-08-03 23:17:251415} // namespace