blob: 4af97b93b0eba92cf7bbbeffca60ad7a4a397aed [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"
[email protected]beb1d1192013-05-14 04:47:5121#include "chrome/browser/ui/singleton_tabs.h"
[email protected]b56e2e32012-05-11 21:18:0422#include "chrome/browser/ui/tabs/tab_strip_model.h"
[email protected]bb89e7482010-11-17 18:27:0423#include "chrome/common/chrome_switches.h"
[email protected]93ad8e1c2011-11-08 21:34:0524#include "chrome/common/pref_names.h"
[email protected]ddddfda2011-07-14 23:19:3925#include "chrome/common/url_constants.h"
[email protected]af44e7fb2011-07-29 18:32:3226#include "chrome/test/base/ui_test_utils.h"
[email protected]ad50def52011-10-19 23:17:0727#include "content/public/browser/notification_service.h"
[email protected]0d6e9bd2011-10-18 04:29:1628#include "content/public/browser/notification_types.h"
[email protected]83ff91c2012-01-05 20:54:1329#include "content/public/browser/web_contents.h"
[email protected]a1feae52010-10-11 22:14:4530
[email protected]4ca15302012-01-03 05:53:2031using content::WebContents;
32
[email protected]ddddfda2011-07-14 23:19:3933namespace {
34
[email protected]a2efc35d2013-08-03 23:17:2535const char kExpectedTitle[] = "PASSED!";
36const char kEchoTitleCommand[] = "echotitle";
37
[email protected]ddddfda2011-07-14 23:19:3938GURL GetGoogleURL() {
[email protected]bd817c22011-02-09 08:16:4639 return GURL("http://www.google.com/");
40}
[email protected]a1feae52010-10-11 22:14:4541
[email protected]ddddfda2011-07-14 23:19:3942GURL GetSettingsURL() {
[email protected]f8f93eb2012-09-25 03:06:2443 return GURL(chrome::kChromeUISettingsURL);
[email protected]ddddfda2011-07-14 23:19:3944}
45
[email protected]a048ad22012-03-23 04:26:5646GURL GetContentSettingsURL() {
47 return GetSettingsURL().Resolve(chrome::kContentSettingsExceptionsSubPage);
[email protected]ddddfda2011-07-14 23:19:3948}
49
[email protected]a048ad22012-03-23 04:26:5650GURL GetClearBrowsingDataURL() {
51 return GetSettingsURL().Resolve(chrome::kClearBrowserDataSubPage);
[email protected]ddddfda2011-07-14 23:19:3952}
53
[email protected]f8f93eb2012-09-25 03:06:2454// Converts long uber URLs ("chrome://chrome/foo/") to short (virtual) URLs
55// ("chrome://foo/"). This should be used to convert the return value of
56// WebContentsImpl::GetURL before comparison because it can return either the
57// real URL or the virtual URL.
58GURL ShortenUberURL(const GURL& url) {
59 std::string url_string = url.spec();
60 const std::string long_prefix = "chrome://chrome/";
61 const std::string short_prefix = "chrome://";
62 if (url_string.find(long_prefix) != 0)
63 return url;
64 url_string.replace(0, long_prefix.length(), short_prefix);
65 return GURL(url_string);
66}
67
[email protected]a2efc35d2013-08-03 23:17:2568} // namespace
[email protected]ddddfda2011-07-14 23:19:3969
[email protected]78e2edc2012-07-01 23:32:2870chrome::NavigateParams BrowserNavigatorTest::MakeNavigateParams() const {
[email protected]bd817c22011-02-09 08:16:4671 return MakeNavigateParams(browser());
72}
[email protected]a1feae52010-10-11 22:14:4573
[email protected]78e2edc2012-07-01 23:32:2874chrome::NavigateParams BrowserNavigatorTest::MakeNavigateParams(
[email protected]bd817c22011-02-09 08:16:4675 Browser* browser) const {
[email protected]78e2edc2012-07-01 23:32:2876 chrome::NavigateParams params(browser, GetGoogleURL(),
77 content::PAGE_TRANSITION_LINK);
[email protected]50592b52013-05-02 22:26:2578 params.window_action = chrome::NavigateParams::SHOW_WINDOW;
[email protected]bd817c22011-02-09 08:16:4679 return params;
80}
[email protected]a1feae52010-10-11 22:14:4581
[email protected]a2efc35d2013-08-03 23:17:2582bool BrowserNavigatorTest::OpenPOSTURLInNewForegroundTabAndGetTitle(
83 const GURL& url, const std::string& post_data, bool is_browser_initiated,
84 base::string16* title) {
85 chrome::NavigateParams param(MakeNavigateParams());
86 param.disposition = NEW_FOREGROUND_TAB;
87 param.url = url;
88 param.is_renderer_initiated = !is_browser_initiated;
89 param.uses_post = true;
90 param.browser_initiated_post_data = new base::RefCountedStaticMemory(
[email protected]8df08cf2014-02-12 22:34:0891 post_data.data(), post_data.size());
[email protected]a2efc35d2013-08-03 23:17:2592
93 ui_test_utils::NavigateToURL(&param);
94 if (!param.target_contents)
95 return false;
96
97 // Navigate() should have opened the contents in new foreground tab in the
98 // current Browser.
99 EXPECT_EQ(browser(), param.browser);
100 EXPECT_EQ(browser()->tab_strip_model()->GetActiveWebContents(),
101 param.target_contents);
102 // We should have one window, with one tab.
103 EXPECT_EQ(1u, chrome::GetTotalBrowserCount());
104 EXPECT_EQ(2, browser()->tab_strip_model()->count());
105
106 *title = param.target_contents->GetTitle();
107 return true;
108}
109
[email protected]bd817c22011-02-09 08:16:46110Browser* BrowserNavigatorTest::CreateEmptyBrowserForType(Browser::Type type,
111 Profile* profile) {
[email protected]2b09ae552013-02-23 06:38:03112 Browser* browser = new Browser(
[email protected]ed2fa722013-06-25 20:37:34113 Browser::CreateParams(type, profile, chrome::GetActiveDesktop()));
[email protected]00509a32013-11-17 17:45:37114 chrome::AddTabAt(browser, GURL(), -1, true);
[email protected]bd817c22011-02-09 08:16:46115 return browser;
116}
[email protected]a1feae52010-10-11 22:14:45117
[email protected]d2202e22014-04-14 20:20:53118Browser* BrowserNavigatorTest::CreateEmptyBrowserForApp(Profile* profile) {
[email protected]a4fe67012012-07-25 20:14:29119 Browser* browser = new Browser(
[email protected]da22aa62012-04-04 18:54:35120 Browser::CreateParams::CreateForApp(
[email protected]d2202e22014-04-14 20:20:53121 "Test", false /* trusted_source */, gfx::Rect(), profile,
[email protected]ed2fa722013-06-25 20:37:34122 chrome::GetActiveDesktop()));
[email protected]00509a32013-11-17 17:45:37123 chrome::AddTabAt(browser, GURL(), -1, true);
[email protected]b35b26b32011-05-05 20:35:14124 return browser;
125}
126
[email protected]e232c992012-12-06 12:43:20127WebContents* BrowserNavigatorTest::CreateWebContents() {
[email protected]54944cde2012-12-09 09:24:59128 content::WebContents::CreateParams create_params(browser()->profile());
[email protected]ed245db2012-12-18 08:00:45129 content::WebContents* base_web_contents =
[email protected]ee496952013-01-10 23:17:33130 browser()->tab_strip_model()->GetActiveWebContents();
[email protected]ed245db2012-12-18 08:00:45131 if (base_web_contents) {
132 create_params.initial_size =
[email protected]fc2b46b2014-05-03 16:33:45133 base_web_contents->GetContainerBounds().size();
[email protected]ed245db2012-12-18 08:00:45134 }
[email protected]54944cde2012-12-09 09:24:59135 return WebContents::Create(create_params);
[email protected]bd817c22011-02-09 08:16:46136}
[email protected]a1feae52010-10-11 22:14:45137
[email protected]bd817c22011-02-09 08:16:46138void BrowserNavigatorTest::RunSuppressTest(WindowOpenDisposition disposition) {
[email protected]ee496952013-01-10 23:17:33139 GURL old_url = browser()->tab_strip_model()->GetActiveWebContents()->GetURL();
[email protected]78e2edc2012-07-01 23:32:28140 chrome::NavigateParams p(MakeNavigateParams());
[email protected]bd817c22011-02-09 08:16:46141 p.disposition = disposition;
[email protected]78e2edc2012-07-01 23:32:28142 chrome::Navigate(&p);
[email protected]a1feae52010-10-11 22:14:45143
[email protected]bd817c22011-02-09 08:16:46144 // Nothing should have happened as a result of Navigate();
[email protected]ee496952013-01-10 23:17:33145 EXPECT_EQ(1, browser()->tab_strip_model()->count());
[email protected]0665ebe2013-02-13 09:53:19146 EXPECT_EQ(1u, chrome::GetTotalBrowserCount());
[email protected]ee496952013-01-10 23:17:33147 EXPECT_EQ(old_url,
148 browser()->tab_strip_model()->GetActiveWebContents()->GetURL());
[email protected]bd817c22011-02-09 08:16:46149}
[email protected]bb89e7482010-11-17 18:27:04150
[email protected]fc0ed302011-11-29 23:17:19151void BrowserNavigatorTest::RunUseNonIncognitoWindowTest(const GURL& url) {
152 Browser* incognito_browser = CreateIncognitoBrowser();
153
[email protected]0665ebe2013-02-13 09:53:19154 EXPECT_EQ(2u, chrome::GetTotalBrowserCount());
[email protected]ee496952013-01-10 23:17:33155 EXPECT_EQ(1, browser()->tab_strip_model()->count());
156 EXPECT_EQ(1, incognito_browser->tab_strip_model()->count());
[email protected]fc0ed302011-11-29 23:17:19157
158 // Navigate to the page.
[email protected]78e2edc2012-07-01 23:32:28159 chrome::NavigateParams p(MakeNavigateParams(incognito_browser));
[email protected]fc0ed302011-11-29 23:17:19160 p.disposition = SINGLETON_TAB;
161 p.url = url;
[email protected]50592b52013-05-02 22:26:25162 p.window_action = chrome::NavigateParams::SHOW_WINDOW;
[email protected]78e2edc2012-07-01 23:32:28163 chrome::Navigate(&p);
[email protected]fc0ed302011-11-29 23:17:19164
[email protected]50592b52013-05-02 22:26:25165 // This page should be opened in browser() window.
[email protected]fc0ed302011-11-29 23:17:19166 EXPECT_NE(incognito_browser, p.browser);
167 EXPECT_EQ(browser(), p.browser);
[email protected]ee496952013-01-10 23:17:33168 EXPECT_EQ(2, browser()->tab_strip_model()->count());
169 EXPECT_EQ(url,
170 browser()->tab_strip_model()->GetActiveWebContents()->GetURL());
[email protected]fc0ed302011-11-29 23:17:19171}
172
173void BrowserNavigatorTest::RunDoNothingIfIncognitoIsForcedTest(
174 const GURL& url) {
175 Browser* browser = CreateIncognitoBrowser();
176
177 // Set kIncognitoModeAvailability to FORCED.
178 PrefService* prefs1 = browser->profile()->GetPrefs();
179 prefs1->SetInteger(prefs::kIncognitoModeAvailability,
180 IncognitoModePrefs::FORCED);
181 PrefService* prefs2 = browser->profile()->GetOriginalProfile()->GetPrefs();
182 prefs2->SetInteger(prefs::kIncognitoModeAvailability,
183 IncognitoModePrefs::FORCED);
184
185 // Navigate to the page.
[email protected]78e2edc2012-07-01 23:32:28186 chrome::NavigateParams p(MakeNavigateParams(browser));
[email protected]fc0ed302011-11-29 23:17:19187 p.disposition = OFF_THE_RECORD;
188 p.url = url;
[email protected]50592b52013-05-02 22:26:25189 p.window_action = chrome::NavigateParams::SHOW_WINDOW;
[email protected]78e2edc2012-07-01 23:32:28190 chrome::Navigate(&p);
[email protected]fc0ed302011-11-29 23:17:19191
192 // The page should not be opened.
193 EXPECT_EQ(browser, p.browser);
[email protected]ee496952013-01-10 23:17:33194 EXPECT_EQ(1, browser->tab_strip_model()->count());
[email protected]081dc522013-05-15 04:59:20195 EXPECT_EQ(GURL(content::kAboutBlankURL),
[email protected]ee496952013-01-10 23:17:33196 browser->tab_strip_model()->GetActiveWebContents()->GetURL());
[email protected]fc0ed302011-11-29 23:17:19197}
198
[email protected]6c2381d2011-10-19 02:52:53199void BrowserNavigatorTest::Observe(
200 int type,
201 const content::NotificationSource& source,
202 const content::NotificationDetails& details) {
[email protected]432115822011-07-10 15:52:27203 switch (type) {
[email protected]d53a08c2012-07-18 20:35:30204 case content::NOTIFICATION_WEB_CONTENTS_RENDER_VIEW_HOST_CREATED: {
[email protected]bd817c22011-02-09 08:16:46205 ++this->created_tab_contents_count_;
206 break;
[email protected]fa7ebe02010-11-29 23:04:57207 }
[email protected]bd817c22011-02-09 08:16:46208 default:
209 break;
[email protected]fa7ebe02010-11-29 23:04:57210 }
[email protected]bd817c22011-02-09 08:16:46211}
[email protected]fa7ebe02010-11-29 23:04:57212
[email protected]ddddfda2011-07-14 23:19:39213
[email protected]bd817c22011-02-09 08:16:46214namespace {
[email protected]a1feae52010-10-11 22:14:45215
[email protected]a1feae52010-10-11 22:14:45216// This test verifies that when a navigation occurs within a tab, the tab count
217// of the Browser remains the same and the current tab bears the loaded URL.
[email protected]59167c22013-06-03 18:07:32218// Note that network URLs are not actually loaded in tests, so this also tests
219// that error pages leave the intended URL in the address bar.
[email protected]a1feae52010-10-11 22:14:45220IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_CurrentTab) {
[email protected]ddddfda2011-07-14 23:19:39221 ui_test_utils::NavigateToURL(browser(), GetGoogleURL());
[email protected]ee496952013-01-10 23:17:33222 EXPECT_EQ(GetGoogleURL(),
223 browser()->tab_strip_model()->GetActiveWebContents()->GetURL());
[email protected]a1feae52010-10-11 22:14:45224 // We should have one window with one tab.
[email protected]0665ebe2013-02-13 09:53:19225 EXPECT_EQ(1u, chrome::GetTotalBrowserCount());
[email protected]ee496952013-01-10 23:17:33226 EXPECT_EQ(1, browser()->tab_strip_model()->count());
[email protected]a1feae52010-10-11 22:14:45227}
228
[email protected]bd817c22011-02-09 08:16:46229// This test verifies that a singleton tab is refocused if one is already opened
[email protected]19d9f3a2010-10-14 21:49:36230// in another or an existing window, or added if it is not.
231IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_SingletonTabExisting) {
[email protected]19d9f3a2010-10-14 21:49:36232 GURL singleton_url1("http://maps.google.com/");
[email protected]fa7ebe02010-11-29 23:04:57233
[email protected]e232c992012-12-06 12:43:20234 // Register for a notification if an additional WebContents was instantiated.
[email protected]bd817c22011-02-09 08:16:46235 // Opening a Singleton tab that is already opened should not be opening a new
[email protected]e232c992012-12-06 12:43:20236 // tab nor be creating a new WebContents object.
[email protected]6c2381d2011-10-19 02:52:53237 content::NotificationRegistrar registrar;
[email protected]fa7ebe02010-11-29 23:04:57238
239 // As the registrar object goes out of scope, this will get unregistered
[email protected]d53a08c2012-07-18 20:35:30240 registrar.Add(this,
241 content::NOTIFICATION_WEB_CONTENTS_RENDER_VIEW_HOST_CREATED,
[email protected]ad50def52011-10-19 23:17:07242 content::NotificationService::AllSources());
[email protected]fa7ebe02010-11-29 23:04:57243
[email protected]52877dbc62012-06-29 22:22:03244 chrome::AddSelectedTabWithURL(browser(), singleton_url1,
245 content::PAGE_TRANSITION_LINK);
246 chrome::AddSelectedTabWithURL(browser(), GetGoogleURL(),
247 content::PAGE_TRANSITION_LINK);
[email protected]19d9f3a2010-10-14 21:49:36248
249 // We should have one browser with 3 tabs, the 3rd selected.
[email protected]0665ebe2013-02-13 09:53:19250 EXPECT_EQ(1u, chrome::GetTotalBrowserCount());
[email protected]ee496952013-01-10 23:17:33251 EXPECT_EQ(2, browser()->tab_strip_model()->active_index());
[email protected]19d9f3a2010-10-14 21:49:36252
[email protected]fa7ebe02010-11-29 23:04:57253 unsigned int previous_tab_contents_count =
254 created_tab_contents_count_ = 0;
255
[email protected]19d9f3a2010-10-14 21:49:36256 // Navigate to singleton_url1.
[email protected]78e2edc2012-07-01 23:32:28257 chrome::NavigateParams p(MakeNavigateParams());
[email protected]19d9f3a2010-10-14 21:49:36258 p.disposition = SINGLETON_TAB;
259 p.url = singleton_url1;
[email protected]78e2edc2012-07-01 23:32:28260 chrome::Navigate(&p);
[email protected]19d9f3a2010-10-14 21:49:36261
262 // The middle tab should now be selected.
263 EXPECT_EQ(browser(), p.browser);
[email protected]ee496952013-01-10 23:17:33264 EXPECT_EQ(1, browser()->tab_strip_model()->active_index());
[email protected]fa7ebe02010-11-29 23:04:57265
266 // No tab contents should have been created
267 EXPECT_EQ(previous_tab_contents_count,
268 created_tab_contents_count_);
[email protected]19d9f3a2010-10-14 21:49:36269}
270
271IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
[email protected]578c6962011-08-24 22:06:40272 Disposition_SingletonTabRespectingRef) {
273 GURL singleton_ref_url1("http://maps.google.com/#a");
274 GURL singleton_ref_url2("http://maps.google.com/#b");
275 GURL singleton_ref_url3("http://maps.google.com/");
276
[email protected]52877dbc62012-06-29 22:22:03277 chrome::AddSelectedTabWithURL(browser(), singleton_ref_url1,
278 content::PAGE_TRANSITION_LINK);
[email protected]578c6962011-08-24 22:06:40279
280 // We should have one browser with 2 tabs, 2nd selected.
[email protected]0665ebe2013-02-13 09:53:19281 EXPECT_EQ(1u, chrome::GetTotalBrowserCount());
[email protected]ee496952013-01-10 23:17:33282 EXPECT_EQ(2, browser()->tab_strip_model()->count());
283 EXPECT_EQ(1, browser()->tab_strip_model()->active_index());
[email protected]578c6962011-08-24 22:06:40284
285 // Navigate to singleton_url2.
[email protected]78e2edc2012-07-01 23:32:28286 chrome::NavigateParams p(MakeNavigateParams());
[email protected]578c6962011-08-24 22:06:40287 p.disposition = SINGLETON_TAB;
288 p.url = singleton_ref_url2;
[email protected]78e2edc2012-07-01 23:32:28289 chrome::Navigate(&p);
[email protected]578c6962011-08-24 22:06:40290
291 // We should now have 2 tabs, the 2nd one selected.
292 EXPECT_EQ(browser(), p.browser);
[email protected]ee496952013-01-10 23:17:33293 EXPECT_EQ(2, browser()->tab_strip_model()->count());
294 EXPECT_EQ(1, browser()->tab_strip_model()->active_index());
[email protected]578c6962011-08-24 22:06:40295
296 // Navigate to singleton_url2, but with respect ref set.
297 p = MakeNavigateParams();
298 p.disposition = SINGLETON_TAB;
299 p.url = singleton_ref_url2;
[email protected]78e2edc2012-07-01 23:32:28300 p.ref_behavior = chrome::NavigateParams::RESPECT_REF;
301 chrome::Navigate(&p);
[email protected]578c6962011-08-24 22:06:40302
303 // We should now have 3 tabs, the 3th one selected.
304 EXPECT_EQ(browser(), p.browser);
[email protected]ee496952013-01-10 23:17:33305 EXPECT_EQ(3, browser()->tab_strip_model()->count());
306 EXPECT_EQ(2, browser()->tab_strip_model()->active_index());
[email protected]578c6962011-08-24 22:06:40307
308 // Navigate to singleton_url3.
309 p = MakeNavigateParams();
310 p.disposition = SINGLETON_TAB;
311 p.url = singleton_ref_url3;
[email protected]78e2edc2012-07-01 23:32:28312 p.ref_behavior = chrome::NavigateParams::RESPECT_REF;
313 chrome::Navigate(&p);
[email protected]578c6962011-08-24 22:06:40314
315 // We should now have 4 tabs, the 4th one selected.
316 EXPECT_EQ(browser(), p.browser);
[email protected]ee496952013-01-10 23:17:33317 EXPECT_EQ(4, browser()->tab_strip_model()->count());
318 EXPECT_EQ(3, browser()->tab_strip_model()->active_index());
[email protected]578c6962011-08-24 22:06:40319}
320
321IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
[email protected]19d9f3a2010-10-14 21:49:36322 Disposition_SingletonTabNoneExisting) {
[email protected]19d9f3a2010-10-14 21:49:36323 GURL singleton_url1("http://maps.google.com/");
324
[email protected]bd817c22011-02-09 08:16:46325 // We should have one browser with 1 tab.
[email protected]0665ebe2013-02-13 09:53:19326 EXPECT_EQ(1u, chrome::GetTotalBrowserCount());
[email protected]ee496952013-01-10 23:17:33327 EXPECT_EQ(0, browser()->tab_strip_model()->active_index());
[email protected]19d9f3a2010-10-14 21:49:36328
329 // Navigate to singleton_url1.
[email protected]78e2edc2012-07-01 23:32:28330 chrome::NavigateParams p(MakeNavigateParams());
[email protected]19d9f3a2010-10-14 21:49:36331 p.disposition = SINGLETON_TAB;
332 p.url = singleton_url1;
[email protected]78e2edc2012-07-01 23:32:28333 chrome::Navigate(&p);
[email protected]19d9f3a2010-10-14 21:49:36334
335 // We should now have 2 tabs, the 2nd one selected.
336 EXPECT_EQ(browser(), p.browser);
[email protected]ee496952013-01-10 23:17:33337 EXPECT_EQ(2, browser()->tab_strip_model()->count());
338 EXPECT_EQ(1, browser()->tab_strip_model()->active_index());
[email protected]a1feae52010-10-11 22:14:45339}
340
341// This test verifies that when a navigation results in a foreground tab, the
342// tab count of the Browser increases and the selected tab shifts to the new
343// foreground tab.
344IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_NewForegroundTab) {
[email protected]ee496952013-01-10 23:17:33345 WebContents* old_contents =
346 browser()->tab_strip_model()->GetActiveWebContents();
[email protected]78e2edc2012-07-01 23:32:28347 chrome::NavigateParams p(MakeNavigateParams());
[email protected]a1feae52010-10-11 22:14:45348 p.disposition = NEW_FOREGROUND_TAB;
[email protected]78e2edc2012-07-01 23:32:28349 chrome::Navigate(&p);
[email protected]ee496952013-01-10 23:17:33350 EXPECT_NE(old_contents,
351 browser()->tab_strip_model()->GetActiveWebContents());
[email protected]e232c992012-12-06 12:43:20352 EXPECT_EQ(browser()->tab_strip_model()->GetActiveWebContents(),
[email protected]59253a652012-11-20 00:17:26353 p.target_contents);
[email protected]ee496952013-01-10 23:17:33354 EXPECT_EQ(2, browser()->tab_strip_model()->count());
[email protected]a1feae52010-10-11 22:14:45355}
356
357// This test verifies that when a navigation results in a background tab, the
358// tab count of the Browser increases but the selected tab remains the same.
359IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_NewBackgroundTab) {
[email protected]ee496952013-01-10 23:17:33360 WebContents* old_contents =
361 browser()->tab_strip_model()->GetActiveWebContents();
[email protected]78e2edc2012-07-01 23:32:28362 chrome::NavigateParams p(MakeNavigateParams());
[email protected]a1feae52010-10-11 22:14:45363 p.disposition = NEW_BACKGROUND_TAB;
[email protected]78e2edc2012-07-01 23:32:28364 chrome::Navigate(&p);
[email protected]ee496952013-01-10 23:17:33365 WebContents* new_contents =
366 browser()->tab_strip_model()->GetActiveWebContents();
[email protected]a1feae52010-10-11 22:14:45367 // The selected tab should have remained unchanged, since the new tab was
368 // opened in the background.
369 EXPECT_EQ(old_contents, new_contents);
[email protected]ee496952013-01-10 23:17:33370 EXPECT_EQ(2, browser()->tab_strip_model()->count());
[email protected]a1feae52010-10-11 22:14:45371}
372
373// This test verifies that when a navigation requiring a new foreground tab
374// occurs in a Browser that cannot host multiple tabs, the new foreground tab
375// is created in an existing compatible Browser.
376IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
377 Disposition_IncompatibleWindow_Existing) {
378 // Open a foreground tab in a window that cannot open popups when there is an
379 // existing compatible window somewhere else that they can be opened within.
380 Browser* popup = CreateEmptyBrowserForType(Browser::TYPE_POPUP,
381 browser()->profile());
[email protected]78e2edc2012-07-01 23:32:28382 chrome::NavigateParams p(MakeNavigateParams(popup));
[email protected]a1feae52010-10-11 22:14:45383 p.disposition = NEW_FOREGROUND_TAB;
[email protected]78e2edc2012-07-01 23:32:28384 chrome::Navigate(&p);
[email protected]a1feae52010-10-11 22:14:45385
386 // Navigate() should have opened the tab in a different browser since the
387 // one we supplied didn't support additional tabs.
388 EXPECT_NE(popup, p.browser);
389
390 // Since browser() is an existing compatible tabbed browser, it should have
391 // opened the tab there.
392 EXPECT_EQ(browser(), p.browser);
393
394 // We should be left with 2 windows, the popup with one tab and the browser()
395 // provided by the framework with two.
[email protected]0665ebe2013-02-13 09:53:19396 EXPECT_EQ(2u, chrome::GetTotalBrowserCount());
[email protected]ee496952013-01-10 23:17:33397 EXPECT_EQ(1, popup->tab_strip_model()->count());
398 EXPECT_EQ(2, browser()->tab_strip_model()->count());
[email protected]a1feae52010-10-11 22:14:45399}
400
401// This test verifies that when a navigation requiring a new foreground tab
402// occurs in a Browser that cannot host multiple tabs and no compatible Browser
403// that can is open, a compatible Browser is created.
404IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
405 Disposition_IncompatibleWindow_NoExisting) {
406 // We want to simulate not being able to find an existing window compatible
407 // with our non-tabbed browser window so Navigate() is forced to create a
408 // new compatible window. Because browser() supplied by the in-process
409 // browser testing framework is compatible with browser()->profile(), we
410 // need a different profile, and creating a popup window with an incognito
411 // profile is a quick and dirty way of achieving this.
412 Browser* popup = CreateEmptyBrowserForType(
[email protected]b35b26b32011-05-05 20:35:14413 Browser::TYPE_POPUP,
414 browser()->profile()->GetOffTheRecordProfile());
[email protected]78e2edc2012-07-01 23:32:28415 chrome::NavigateParams p(MakeNavigateParams(popup));
[email protected]a1feae52010-10-11 22:14:45416 p.disposition = NEW_FOREGROUND_TAB;
[email protected]78e2edc2012-07-01 23:32:28417 chrome::Navigate(&p);
[email protected]a1feae52010-10-11 22:14:45418
419 // Navigate() should have opened the tab in a different browser since the
420 // one we supplied didn't support additional tabs.
421 EXPECT_NE(popup, p.browser);
422
423 // This time, browser() is _not_ compatible with popup since it is not an
424 // incognito window.
425 EXPECT_NE(browser(), p.browser);
426
427 // We should have three windows, each with one tab:
428 // 1. the browser() provided by the framework (unchanged in this test)
429 // 2. the incognito popup we created originally
430 // 3. the new incognito tabbed browser that was created by Navigate().
[email protected]0665ebe2013-02-13 09:53:19431 EXPECT_EQ(3u, chrome::GetTotalBrowserCount());
[email protected]ee496952013-01-10 23:17:33432 EXPECT_EQ(1, browser()->tab_strip_model()->count());
433 EXPECT_EQ(1, popup->tab_strip_model()->count());
434 EXPECT_EQ(1, p.browser->tab_strip_model()->count());
[email protected]b35b26b32011-05-05 20:35:14435 EXPECT_TRUE(p.browser->is_type_tabbed());
[email protected]a1feae52010-10-11 22:14:45436}
437
438// This test verifies that navigating with WindowOpenDisposition = NEW_POPUP
439// from a normal Browser results in a new Browser with TYPE_POPUP.
440IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_NewPopup) {
[email protected]78e2edc2012-07-01 23:32:28441 chrome::NavigateParams p(MakeNavigateParams());
[email protected]a1feae52010-10-11 22:14:45442 p.disposition = NEW_POPUP;
[email protected]588300d2011-04-28 21:06:35443 p.window_bounds = gfx::Rect(0, 0, 200, 200);
[email protected]7d329992011-04-15 18:20:02444 // Wait for new popup to to load and gain focus.
[email protected]ddddfda2011-07-14 23:19:39445 ui_test_utils::NavigateToURL(&p);
[email protected]a1feae52010-10-11 22:14:45446
[email protected]7d329992011-04-15 18:20:02447 // Navigate() should have opened a new, focused popup window.
[email protected]a1feae52010-10-11 22:14:45448 EXPECT_NE(browser(), p.browser);
[email protected]50592b52013-05-02 22:26:25449#if 0
450 // TODO(stevenjb): Enable this test. See: crbug.com/79493
451 EXPECT_TRUE(p.browser->window()->IsActive());
452#endif
[email protected]b35b26b32011-05-05 20:35:14453 EXPECT_TRUE(p.browser->is_type_popup());
454 EXPECT_FALSE(p.browser->is_app());
[email protected]a1feae52010-10-11 22:14:45455
456 // We should have two windows, the browser() provided by the framework and the
457 // new popup window.
[email protected]0665ebe2013-02-13 09:53:19458 EXPECT_EQ(2u, chrome::GetTotalBrowserCount());
[email protected]ee496952013-01-10 23:17:33459 EXPECT_EQ(1, browser()->tab_strip_model()->count());
460 EXPECT_EQ(1, p.browser->tab_strip_model()->count());
[email protected]a1feae52010-10-11 22:14:45461}
462
463// This test verifies that navigating with WindowOpenDisposition = NEW_POPUP
[email protected]f112b0f2011-05-26 01:53:52464// from a normal Browser results in a new Browser with is_app() true.
465IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_NewPopup_ExtensionId) {
[email protected]78e2edc2012-07-01 23:32:28466 chrome::NavigateParams p(MakeNavigateParams());
[email protected]f112b0f2011-05-26 01:53:52467 p.disposition = NEW_POPUP;
468 p.extension_app_id = "extensionappid";
469 p.window_bounds = gfx::Rect(0, 0, 200, 200);
[email protected]f112b0f2011-05-26 01:53:52470 // Wait for new popup to to load and gain focus.
[email protected]ddddfda2011-07-14 23:19:39471 ui_test_utils::NavigateToURL(&p);
[email protected]f112b0f2011-05-26 01:53:52472
473 // Navigate() should have opened a new, focused popup window.
474 EXPECT_NE(browser(), p.browser);
475 EXPECT_TRUE(p.browser->is_type_popup());
476 EXPECT_TRUE(p.browser->is_app());
477
478 // We should have two windows, the browser() provided by the framework and the
479 // new popup window.
[email protected]0665ebe2013-02-13 09:53:19480 EXPECT_EQ(2u, chrome::GetTotalBrowserCount());
[email protected]ee496952013-01-10 23:17:33481 EXPECT_EQ(1, browser()->tab_strip_model()->count());
482 EXPECT_EQ(1, p.browser->tab_strip_model()->count());
[email protected]f112b0f2011-05-26 01:53:52483}
484
485// This test verifies that navigating with WindowOpenDisposition = NEW_POPUP
[email protected]300d1e52011-01-19 23:57:57486// from a normal popup results in a new Browser with TYPE_POPUP.
487IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_NewPopupFromPopup) {
488 // Open a popup.
[email protected]78e2edc2012-07-01 23:32:28489 chrome::NavigateParams p1(MakeNavigateParams());
[email protected]300d1e52011-01-19 23:57:57490 p1.disposition = NEW_POPUP;
[email protected]588300d2011-04-28 21:06:35491 p1.window_bounds = gfx::Rect(0, 0, 200, 200);
[email protected]78e2edc2012-07-01 23:32:28492 chrome::Navigate(&p1);
[email protected]300d1e52011-01-19 23:57:57493 // Open another popup.
[email protected]78e2edc2012-07-01 23:32:28494 chrome::NavigateParams p2(MakeNavigateParams(p1.browser));
[email protected]300d1e52011-01-19 23:57:57495 p2.disposition = NEW_POPUP;
[email protected]588300d2011-04-28 21:06:35496 p2.window_bounds = gfx::Rect(0, 0, 200, 200);
[email protected]78e2edc2012-07-01 23:32:28497 chrome::Navigate(&p2);
[email protected]300d1e52011-01-19 23:57:57498
499 // Navigate() should have opened a new normal popup window.
500 EXPECT_NE(p1.browser, p2.browser);
[email protected]b35b26b32011-05-05 20:35:14501 EXPECT_TRUE(p2.browser->is_type_popup());
502 EXPECT_FALSE(p2.browser->is_app());
[email protected]300d1e52011-01-19 23:57:57503
504 // We should have three windows, the browser() provided by the framework,
505 // the first popup window, and the second popup window.
[email protected]0665ebe2013-02-13 09:53:19506 EXPECT_EQ(3u, chrome::GetTotalBrowserCount());
[email protected]ee496952013-01-10 23:17:33507 EXPECT_EQ(1, browser()->tab_strip_model()->count());
508 EXPECT_EQ(1, p1.browser->tab_strip_model()->count());
509 EXPECT_EQ(1, p2.browser->tab_strip_model()->count());
[email protected]300d1e52011-01-19 23:57:57510}
511
512// This test verifies that navigating with WindowOpenDisposition = NEW_POPUP
[email protected]d2202e22014-04-14 20:20:53513// from an app frame results in a new Browser with TYPE_POPUP.
[email protected]a1feae52010-10-11 22:14:45514IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
515 Disposition_NewPopupFromAppWindow) {
[email protected]d2202e22014-04-14 20:20:53516 Browser* app_browser = CreateEmptyBrowserForApp(browser()->profile());
[email protected]78e2edc2012-07-01 23:32:28517 chrome::NavigateParams p(MakeNavigateParams(app_browser));
[email protected]a1feae52010-10-11 22:14:45518 p.disposition = NEW_POPUP;
[email protected]588300d2011-04-28 21:06:35519 p.window_bounds = gfx::Rect(0, 0, 200, 200);
[email protected]78e2edc2012-07-01 23:32:28520 chrome::Navigate(&p);
[email protected]a1feae52010-10-11 22:14:45521
522 // Navigate() should have opened a new popup app window.
523 EXPECT_NE(app_browser, p.browser);
524 EXPECT_NE(browser(), p.browser);
[email protected]b35b26b32011-05-05 20:35:14525 EXPECT_TRUE(p.browser->is_type_popup());
526 EXPECT_TRUE(p.browser->is_app());
[email protected]a1feae52010-10-11 22:14:45527
528 // We should now have three windows, the app window, the app popup it created,
529 // and the original browser() provided by the framework.
[email protected]0665ebe2013-02-13 09:53:19530 EXPECT_EQ(3u, chrome::GetTotalBrowserCount());
[email protected]ee496952013-01-10 23:17:33531 EXPECT_EQ(1, browser()->tab_strip_model()->count());
532 EXPECT_EQ(1, app_browser->tab_strip_model()->count());
533 EXPECT_EQ(1, p.browser->tab_strip_model()->count());
[email protected]a1feae52010-10-11 22:14:45534}
535
536// This test verifies that navigating with WindowOpenDisposition = NEW_POPUP
[email protected]d2202e22014-04-14 20:20:53537// from an app popup results in a new Browser also of TYPE_POPUP.
[email protected]300d1e52011-01-19 23:57:57538IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
539 Disposition_NewPopupFromAppPopup) {
[email protected]d2202e22014-04-14 20:20:53540 Browser* app_browser = CreateEmptyBrowserForApp(browser()->profile());
[email protected]300d1e52011-01-19 23:57:57541 // Open an app popup.
[email protected]78e2edc2012-07-01 23:32:28542 chrome::NavigateParams p1(MakeNavigateParams(app_browser));
[email protected]300d1e52011-01-19 23:57:57543 p1.disposition = NEW_POPUP;
[email protected]588300d2011-04-28 21:06:35544 p1.window_bounds = gfx::Rect(0, 0, 200, 200);
[email protected]78e2edc2012-07-01 23:32:28545 chrome::Navigate(&p1);
[email protected]300d1e52011-01-19 23:57:57546 // Now open another app popup.
[email protected]78e2edc2012-07-01 23:32:28547 chrome::NavigateParams p2(MakeNavigateParams(p1.browser));
[email protected]300d1e52011-01-19 23:57:57548 p2.disposition = NEW_POPUP;
[email protected]588300d2011-04-28 21:06:35549 p2.window_bounds = gfx::Rect(0, 0, 200, 200);
[email protected]78e2edc2012-07-01 23:32:28550 chrome::Navigate(&p2);
[email protected]300d1e52011-01-19 23:57:57551
552 // Navigate() should have opened a new popup app window.
553 EXPECT_NE(browser(), p1.browser);
554 EXPECT_NE(p1.browser, p2.browser);
[email protected]b35b26b32011-05-05 20:35:14555 EXPECT_TRUE(p2.browser->is_type_popup());
556 EXPECT_TRUE(p2.browser->is_app());
[email protected]300d1e52011-01-19 23:57:57557
558 // We should now have four windows, the app window, the first app popup,
559 // the second app popup, and the original browser() provided by the framework.
[email protected]0665ebe2013-02-13 09:53:19560 EXPECT_EQ(4u, chrome::GetTotalBrowserCount());
[email protected]ee496952013-01-10 23:17:33561 EXPECT_EQ(1, browser()->tab_strip_model()->count());
562 EXPECT_EQ(1, app_browser->tab_strip_model()->count());
563 EXPECT_EQ(1, p1.browser->tab_strip_model()->count());
564 EXPECT_EQ(1, p2.browser->tab_strip_model()->count());
[email protected]300d1e52011-01-19 23:57:57565}
566
567// This test verifies that navigating with WindowOpenDisposition = NEW_POPUP
[email protected]a1feae52010-10-11 22:14:45568// from an extension app tab results in a new Browser with TYPE_APP_POPUP.
569IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
570 Disposition_NewPopupFromExtensionApp) {
571 // TODO(beng): TBD.
572}
573
[email protected]7d329992011-04-15 18:20:02574// This test verifies that navigating with window_action = SHOW_WINDOW_INACTIVE
575// does not focus a new new popup window.
576IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_NewPopupUnfocused) {
[email protected]78e2edc2012-07-01 23:32:28577 chrome::NavigateParams p(MakeNavigateParams());
[email protected]7d329992011-04-15 18:20:02578 p.disposition = NEW_POPUP;
[email protected]588300d2011-04-28 21:06:35579 p.window_bounds = gfx::Rect(0, 0, 200, 200);
[email protected]78e2edc2012-07-01 23:32:28580 p.window_action = chrome::NavigateParams::SHOW_WINDOW_INACTIVE;
[email protected]7d329992011-04-15 18:20:02581 // Wait for new popup to load (and gain focus if the test fails).
[email protected]ddddfda2011-07-14 23:19:39582 ui_test_utils::NavigateToURL(&p);
[email protected]7d329992011-04-15 18:20:02583
584 // Navigate() should have opened a new, unfocused, popup window.
585 EXPECT_NE(browser(), p.browser);
586 EXPECT_EQ(Browser::TYPE_POPUP, p.browser->type());
[email protected]9db263a2011-04-15 20:53:47587#if 0
588// TODO(stevenjb): Enable this test. See: crbug.com/79493
[email protected]7d329992011-04-15 18:20:02589 EXPECT_FALSE(p.browser->window()->IsActive());
[email protected]7d329992011-04-15 18:20:02590#endif
[email protected]9db263a2011-04-15 20:53:47591}
[email protected]7d329992011-04-15 18:20:02592
[email protected]d2202e22014-04-14 20:20:53593// This test verifies that navigating with WindowOpenDisposition = NEW_POPUP
594// and trusted_source = true results in a new Browser where is_trusted_source()
595// is true.
596IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_NewPopupTrusted) {
597 chrome::NavigateParams p(MakeNavigateParams());
598 p.disposition = NEW_POPUP;
599 p.trusted_source = true;
600 p.window_bounds = gfx::Rect(0, 0, 200, 200);
601 // Wait for new popup to to load and gain focus.
602 ui_test_utils::NavigateToURL(&p);
603
604 // Navigate() should have opened a new popup window of TYPE_TRUSTED_POPUP.
605 EXPECT_NE(browser(), p.browser);
606 EXPECT_TRUE(p.browser->is_type_popup());
607 EXPECT_TRUE(p.browser->is_trusted_source());
608}
609
610
[email protected]a1feae52010-10-11 22:14:45611// This test verifies that navigating with WindowOpenDisposition = NEW_WINDOW
612// always opens a new window.
613IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_NewWindow) {
[email protected]78e2edc2012-07-01 23:32:28614 chrome::NavigateParams p(MakeNavigateParams());
[email protected]a1feae52010-10-11 22:14:45615 p.disposition = NEW_WINDOW;
[email protected]78e2edc2012-07-01 23:32:28616 chrome::Navigate(&p);
[email protected]a1feae52010-10-11 22:14:45617
618 // Navigate() should have opened a new toplevel window.
619 EXPECT_NE(browser(), p.browser);
[email protected]b35b26b32011-05-05 20:35:14620 EXPECT_TRUE(p.browser->is_type_tabbed());
[email protected]a1feae52010-10-11 22:14:45621
622 // We should now have two windows, the browser() provided by the framework and
623 // the new normal window.
[email protected]0665ebe2013-02-13 09:53:19624 EXPECT_EQ(2u, chrome::GetTotalBrowserCount());
[email protected]ee496952013-01-10 23:17:33625 EXPECT_EQ(1, browser()->tab_strip_model()->count());
626 EXPECT_EQ(1, p.browser->tab_strip_model()->count());
[email protected]a1feae52010-10-11 22:14:45627}
628
629// This test verifies that navigating with WindowOpenDisposition = INCOGNITO
630// opens a new incognito window if no existing incognito window is present.
631IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_Incognito) {
[email protected]78e2edc2012-07-01 23:32:28632 chrome::NavigateParams p(MakeNavigateParams());
[email protected]a1feae52010-10-11 22:14:45633 p.disposition = OFF_THE_RECORD;
[email protected]78e2edc2012-07-01 23:32:28634 chrome::Navigate(&p);
[email protected]a1feae52010-10-11 22:14:45635
636 // Navigate() should have opened a new toplevel incognito window.
637 EXPECT_NE(browser(), p.browser);
638 EXPECT_EQ(browser()->profile()->GetOffTheRecordProfile(),
639 p.browser->profile());
640
[email protected]d7ff3592010-11-30 21:50:46641 // |source_contents| should be set to NULL because the profile for the new
642 // page is different from the originating page.
643 EXPECT_EQ(NULL, p.source_contents);
644
[email protected]a1feae52010-10-11 22:14:45645 // We should now have two windows, the browser() provided by the framework and
646 // the new incognito window.
[email protected]0665ebe2013-02-13 09:53:19647 EXPECT_EQ(2u, chrome::GetTotalBrowserCount());
[email protected]ee496952013-01-10 23:17:33648 EXPECT_EQ(1, browser()->tab_strip_model()->count());
649 EXPECT_EQ(1, p.browser->tab_strip_model()->count());
[email protected]a1feae52010-10-11 22:14:45650}
651
652// This test verifies that navigating with WindowOpenDisposition = INCOGNITO
653// reuses an existing incognito window when possible.
654IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_IncognitoRefocus) {
655 Browser* incognito_browser =
[email protected]b35b26b32011-05-05 20:35:14656 CreateEmptyBrowserForType(Browser::TYPE_TABBED,
[email protected]a1feae52010-10-11 22:14:45657 browser()->profile()->GetOffTheRecordProfile());
[email protected]78e2edc2012-07-01 23:32:28658 chrome::NavigateParams p(MakeNavigateParams());
[email protected]a1feae52010-10-11 22:14:45659 p.disposition = OFF_THE_RECORD;
[email protected]78e2edc2012-07-01 23:32:28660 chrome::Navigate(&p);
[email protected]a1feae52010-10-11 22:14:45661
662 // Navigate() should have opened a new tab in the existing incognito window.
663 EXPECT_NE(browser(), p.browser);
664 EXPECT_EQ(p.browser, incognito_browser);
665
666 // We should now have two windows, the browser() provided by the framework and
667 // the incognito window we opened earlier.
[email protected]0665ebe2013-02-13 09:53:19668 EXPECT_EQ(2u, chrome::GetTotalBrowserCount());
[email protected]ee496952013-01-10 23:17:33669 EXPECT_EQ(1, browser()->tab_strip_model()->count());
670 EXPECT_EQ(2, incognito_browser->tab_strip_model()->count());
[email protected]a1feae52010-10-11 22:14:45671}
672
673// This test verifies that no navigation action occurs when
674// WindowOpenDisposition = SUPPRESS_OPEN.
675IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_SuppressOpen) {
676 RunSuppressTest(SUPPRESS_OPEN);
677}
678
679// This test verifies that no navigation action occurs when
680// WindowOpenDisposition = SAVE_TO_DISK.
681IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_SaveToDisk) {
682 RunSuppressTest(SAVE_TO_DISK);
683}
684
685// This test verifies that no navigation action occurs when
686// WindowOpenDisposition = IGNORE_ACTION.
687IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_IgnoreAction) {
688 RunSuppressTest(IGNORE_ACTION);
689}
690
[email protected]e232c992012-12-06 12:43:20691// This tests adding a foreground tab with a predefined WebContents.
[email protected]a1feae52010-10-11 22:14:45692IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, TargetContents_ForegroundTab) {
[email protected]78e2edc2012-07-01 23:32:28693 chrome::NavigateParams p(MakeNavigateParams());
[email protected]a1feae52010-10-11 22:14:45694 p.disposition = NEW_FOREGROUND_TAB;
[email protected]e232c992012-12-06 12:43:20695 p.target_contents = CreateWebContents();
[email protected]78e2edc2012-07-01 23:32:28696 chrome::Navigate(&p);
[email protected]a1feae52010-10-11 22:14:45697
698 // Navigate() should have opened the contents in a new foreground in the
699 // current Browser.
700 EXPECT_EQ(browser(), p.browser);
[email protected]e232c992012-12-06 12:43:20701 EXPECT_EQ(browser()->tab_strip_model()->GetActiveWebContents(),
[email protected]59253a652012-11-20 00:17:26702 p.target_contents);
[email protected]a1feae52010-10-11 22:14:45703
704 // We should have one window, with two tabs.
[email protected]0665ebe2013-02-13 09:53:19705 EXPECT_EQ(1u, chrome::GetTotalBrowserCount());
[email protected]ee496952013-01-10 23:17:33706 EXPECT_EQ(2, browser()->tab_strip_model()->count());
[email protected]a1feae52010-10-11 22:14:45707}
708
709#if defined(OS_WIN)
[email protected]e232c992012-12-06 12:43:20710// This tests adding a popup with a predefined WebContents.
[email protected]76edb672011-03-04 21:48:39711IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, DISABLED_TargetContents_Popup) {
[email protected]78e2edc2012-07-01 23:32:28712 chrome::NavigateParams p(MakeNavigateParams());
[email protected]a1feae52010-10-11 22:14:45713 p.disposition = NEW_POPUP;
[email protected]e232c992012-12-06 12:43:20714 p.target_contents = CreateWebContents();
[email protected]a1feae52010-10-11 22:14:45715 p.window_bounds = gfx::Rect(10, 10, 500, 500);
[email protected]78e2edc2012-07-01 23:32:28716 chrome::Navigate(&p);
[email protected]a1feae52010-10-11 22:14:45717
718 // Navigate() should have opened a new popup window.
719 EXPECT_NE(browser(), p.browser);
[email protected]b35b26b32011-05-05 20:35:14720 EXPECT_TRUE(p.browser->is_type_popup());
721 EXPECT_FALSE(p.browser->is_app());
[email protected]a1feae52010-10-11 22:14:45722
723 // The web platform is weird. The window bounds specified in
724 // |p.window_bounds| are used as follows:
725 // - the origin is used to position the window
[email protected]e232c992012-12-06 12:43:20726 // - the size is used to size the WebContents of the window.
[email protected]a1feae52010-10-11 22:14:45727 // As such the position of the resulting window will always match
728 // p.window_bounds.origin(), but its size will not. We need to match
729 // the size against the selected tab's view's container size.
730 // Only Windows positions the window according to |p.window_bounds.origin()| -
731 // on Mac the window is offset from the opener and on Linux it always opens
732 // at 0,0.
733 EXPECT_EQ(p.window_bounds.origin(),
734 p.browser->window()->GetRestoredBounds().origin());
735 // All platforms should respect size however provided width > 400 (Mac has a
736 // minimum window width of 400).
737 EXPECT_EQ(p.window_bounds.size(),
[email protected]fc2b46b2014-05-03 16:33:45738 p.target_contents->GetContainerBounds().size());
[email protected]a1feae52010-10-11 22:14:45739
740 // We should have two windows, the new popup and the browser() provided by the
741 // framework.
[email protected]0665ebe2013-02-13 09:53:19742 EXPECT_EQ(2u, chrome::GetTotalBrowserCount());
[email protected]ee496952013-01-10 23:17:33743 EXPECT_EQ(1, browser()->tab_strip_model()->count());
744 EXPECT_EQ(1, p.browser->tab_strip_model()->count());
[email protected]a1feae52010-10-11 22:14:45745}
746#endif
747
748// This tests adding a tab at a specific index.
749IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Tabstrip_InsertAtIndex) {
750 // This is not meant to be a comprehensive test of whether or not the tab
751 // implementation of the browser observes the insertion index. That is
752 // covered by the unit tests for TabStripModel. This merely verifies that
753 // insertion index preference is reflected in common cases.
[email protected]78e2edc2012-07-01 23:32:28754 chrome::NavigateParams p(MakeNavigateParams());
[email protected]a1feae52010-10-11 22:14:45755 p.disposition = NEW_FOREGROUND_TAB;
756 p.tabstrip_index = 0;
757 p.tabstrip_add_types = TabStripModel::ADD_FORCE_INDEX;
[email protected]78e2edc2012-07-01 23:32:28758 chrome::Navigate(&p);
[email protected]a1feae52010-10-11 22:14:45759
760 // Navigate() should have inserted a new tab at slot 0 in the tabstrip.
761 EXPECT_EQ(browser(), p.browser);
[email protected]e232c992012-12-06 12:43:20762 EXPECT_EQ(0, browser()->tab_strip_model()->GetIndexOfWebContents(
763 static_cast<const WebContents*>(p.target_contents)));
[email protected]a1feae52010-10-11 22:14:45764
765 // We should have one window - the browser() provided by the framework.
[email protected]0665ebe2013-02-13 09:53:19766 EXPECT_EQ(1u, chrome::GetTotalBrowserCount());
[email protected]ee496952013-01-10 23:17:33767 EXPECT_EQ(2, browser()->tab_strip_model()->count());
[email protected]a1feae52010-10-11 22:14:45768}
769
[email protected]bb89e7482010-11-17 18:27:04770// This test verifies that constructing params with disposition = SINGLETON_TAB
[email protected]fee320542011-03-02 01:30:49771// and IGNORE_AND_NAVIGATE opens a new tab navigated to the specified URL if
[email protected]67ed83e2011-01-07 22:54:00772// no previous tab with that URL (minus the path) exists.
[email protected]bb89e7482010-11-17 18:27:04773IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
774 Disposition_SingletonTabNew_IgnorePath) {
[email protected]52877dbc62012-06-29 22:22:03775 chrome::AddSelectedTabWithURL(browser(), GetGoogleURL(),
776 content::PAGE_TRANSITION_LINK);
[email protected]bb89e7482010-11-17 18:27:04777
778 // We should have one browser with 2 tabs, the 2nd selected.
[email protected]0665ebe2013-02-13 09:53:19779 EXPECT_EQ(1u, chrome::GetTotalBrowserCount());
[email protected]ee496952013-01-10 23:17:33780 EXPECT_EQ(2, browser()->tab_strip_model()->count());
781 EXPECT_EQ(1, browser()->tab_strip_model()->active_index());
[email protected]bb89e7482010-11-17 18:27:04782
783 // Navigate to a new singleton tab with a sub-page.
[email protected]78e2edc2012-07-01 23:32:28784 chrome::NavigateParams p(MakeNavigateParams());
[email protected]bb89e7482010-11-17 18:27:04785 p.disposition = SINGLETON_TAB;
[email protected]a048ad22012-03-23 04:26:56786 p.url = GetContentSettingsURL();
[email protected]50592b52013-05-02 22:26:25787 p.window_action = chrome::NavigateParams::SHOW_WINDOW;
[email protected]78e2edc2012-07-01 23:32:28788 p.path_behavior = chrome::NavigateParams::IGNORE_AND_NAVIGATE;
789 chrome::Navigate(&p);
[email protected]bb89e7482010-11-17 18:27:04790
791 // The last tab should now be selected and navigated to the sub-page of the
[email protected]50592b52013-05-02 22:26:25792 // URL.
[email protected]bb89e7482010-11-17 18:27:04793 EXPECT_EQ(browser(), p.browser);
[email protected]ee496952013-01-10 23:17:33794 EXPECT_EQ(3, browser()->tab_strip_model()->count());
795 EXPECT_EQ(2, browser()->tab_strip_model()->active_index());
[email protected]a048ad22012-03-23 04:26:56796 EXPECT_EQ(GetContentSettingsURL(),
[email protected]ee496952013-01-10 23:17:33797 ShortenUberURL(browser()->tab_strip_model()->
798 GetActiveWebContents()->GetURL()));
[email protected]bb89e7482010-11-17 18:27:04799}
800
801// This test verifies that constructing params with disposition = SINGLETON_TAB
[email protected]fee320542011-03-02 01:30:49802// and IGNORE_AND_NAVIGATE opens an existing tab with the matching URL (minus
[email protected]bb89e7482010-11-17 18:27:04803// the path) which is navigated to the specified URL.
804IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
805 Disposition_SingletonTabExisting_IgnorePath) {
[email protected]ddddfda2011-07-14 23:19:39806 GURL singleton_url1(GetSettingsURL());
[email protected]52877dbc62012-06-29 22:22:03807 chrome::AddSelectedTabWithURL(browser(), singleton_url1,
808 content::PAGE_TRANSITION_LINK);
809 chrome::AddSelectedTabWithURL(browser(), GetGoogleURL(),
810 content::PAGE_TRANSITION_LINK);
[email protected]bb89e7482010-11-17 18:27:04811
812 // We should have one browser with 3 tabs, the 3rd selected.
[email protected]0665ebe2013-02-13 09:53:19813 EXPECT_EQ(1u, chrome::GetTotalBrowserCount());
[email protected]ee496952013-01-10 23:17:33814 EXPECT_EQ(3, browser()->tab_strip_model()->count());
815 EXPECT_EQ(2, browser()->tab_strip_model()->active_index());
[email protected]bb89e7482010-11-17 18:27:04816
817 // Navigate to singleton_url1.
[email protected]78e2edc2012-07-01 23:32:28818 chrome::NavigateParams p(MakeNavigateParams());
[email protected]bb89e7482010-11-17 18:27:04819 p.disposition = SINGLETON_TAB;
[email protected]a048ad22012-03-23 04:26:56820 p.url = GetContentSettingsURL();
[email protected]50592b52013-05-02 22:26:25821 p.window_action = chrome::NavigateParams::SHOW_WINDOW;
[email protected]78e2edc2012-07-01 23:32:28822 p.path_behavior = chrome::NavigateParams::IGNORE_AND_NAVIGATE;
823 chrome::Navigate(&p);
[email protected]bb89e7482010-11-17 18:27:04824
825 // The middle tab should now be selected and navigated to the sub-page of the
826 // URL.
827 EXPECT_EQ(browser(), p.browser);
[email protected]ee496952013-01-10 23:17:33828 EXPECT_EQ(3, browser()->tab_strip_model()->count());
829 EXPECT_EQ(1, browser()->tab_strip_model()->active_index());
[email protected]a048ad22012-03-23 04:26:56830 EXPECT_EQ(GetContentSettingsURL(),
[email protected]ee496952013-01-10 23:17:33831 ShortenUberURL(browser()->tab_strip_model()->
832 GetActiveWebContents()->GetURL()));
[email protected]bb89e7482010-11-17 18:27:04833}
834
835// This test verifies that constructing params with disposition = SINGLETON_TAB
[email protected]fee320542011-03-02 01:30:49836// and IGNORE_AND_NAVIGATE opens an existing tab with the matching URL (minus
[email protected]bb89e7482010-11-17 18:27:04837// the path) which is navigated to the specified URL.
838IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
839 Disposition_SingletonTabExistingSubPath_IgnorePath) {
[email protected]a048ad22012-03-23 04:26:56840 GURL singleton_url1(GetContentSettingsURL());
[email protected]52877dbc62012-06-29 22:22:03841 chrome::AddSelectedTabWithURL(browser(), singleton_url1,
842 content::PAGE_TRANSITION_LINK);
843 chrome::AddSelectedTabWithURL(browser(), GetGoogleURL(),
844 content::PAGE_TRANSITION_LINK);
[email protected]bb89e7482010-11-17 18:27:04845
846 // We should have one browser with 3 tabs, the 3rd selected.
[email protected]0665ebe2013-02-13 09:53:19847 EXPECT_EQ(1u, chrome::GetTotalBrowserCount());
[email protected]ee496952013-01-10 23:17:33848 EXPECT_EQ(3, browser()->tab_strip_model()->count());
849 EXPECT_EQ(2, browser()->tab_strip_model()->active_index());
[email protected]bb89e7482010-11-17 18:27:04850
851 // Navigate to singleton_url1.
[email protected]78e2edc2012-07-01 23:32:28852 chrome::NavigateParams p(MakeNavigateParams());
[email protected]bb89e7482010-11-17 18:27:04853 p.disposition = SINGLETON_TAB;
[email protected]a048ad22012-03-23 04:26:56854 p.url = GetClearBrowsingDataURL();
[email protected]50592b52013-05-02 22:26:25855 p.window_action = chrome::NavigateParams::SHOW_WINDOW;
[email protected]78e2edc2012-07-01 23:32:28856 p.path_behavior = chrome::NavigateParams::IGNORE_AND_NAVIGATE;
857 chrome::Navigate(&p);
[email protected]bb89e7482010-11-17 18:27:04858
859 // The middle tab should now be selected and navigated to the sub-page of the
860 // URL.
861 EXPECT_EQ(browser(), p.browser);
[email protected]ee496952013-01-10 23:17:33862 EXPECT_EQ(3, browser()->tab_strip_model()->count());
863 EXPECT_EQ(1, browser()->tab_strip_model()->active_index());
[email protected]a048ad22012-03-23 04:26:56864 EXPECT_EQ(GetClearBrowsingDataURL(),
[email protected]ee496952013-01-10 23:17:33865 ShortenUberURL(browser()->tab_strip_model()->
866 GetActiveWebContents()->GetURL()));
[email protected]bb89e7482010-11-17 18:27:04867}
[email protected]2dd85482010-11-06 01:56:47868
[email protected]637b3442011-01-10 23:31:48869// This test verifies that constructing params with disposition = SINGLETON_TAB
[email protected]fee320542011-03-02 01:30:49870// and IGNORE_AND_STAY_PUT opens an existing tab with the matching URL (minus
871// the path).
872IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
873 Disposition_SingletonTabExistingSubPath_IgnorePath2) {
[email protected]a048ad22012-03-23 04:26:56874 GURL singleton_url1(GetContentSettingsURL());
[email protected]52877dbc62012-06-29 22:22:03875 chrome::AddSelectedTabWithURL(browser(), singleton_url1,
876 content::PAGE_TRANSITION_LINK);
877 chrome::AddSelectedTabWithURL(browser(), GetGoogleURL(),
878 content::PAGE_TRANSITION_LINK);
[email protected]fee320542011-03-02 01:30:49879
880 // We should have one browser with 3 tabs, the 3rd selected.
[email protected]0665ebe2013-02-13 09:53:19881 EXPECT_EQ(1u, chrome::GetTotalBrowserCount());
[email protected]ee496952013-01-10 23:17:33882 EXPECT_EQ(3, browser()->tab_strip_model()->count());
883 EXPECT_EQ(2, browser()->tab_strip_model()->active_index());
[email protected]fee320542011-03-02 01:30:49884
885 // Navigate to singleton_url1.
[email protected]78e2edc2012-07-01 23:32:28886 chrome::NavigateParams p(MakeNavigateParams());
[email protected]fee320542011-03-02 01:30:49887 p.disposition = SINGLETON_TAB;
[email protected]a048ad22012-03-23 04:26:56888 p.url = GetClearBrowsingDataURL();
[email protected]50592b52013-05-02 22:26:25889 p.window_action = chrome::NavigateParams::SHOW_WINDOW;
[email protected]78e2edc2012-07-01 23:32:28890 p.path_behavior = chrome::NavigateParams::IGNORE_AND_STAY_PUT;
891 chrome::Navigate(&p);
[email protected]fee320542011-03-02 01:30:49892
893 // The middle tab should now be selected.
894 EXPECT_EQ(browser(), p.browser);
[email protected]ee496952013-01-10 23:17:33895 EXPECT_EQ(3, browser()->tab_strip_model()->count());
896 EXPECT_EQ(1, browser()->tab_strip_model()->active_index());
[email protected]fee320542011-03-02 01:30:49897 EXPECT_EQ(singleton_url1,
[email protected]ee496952013-01-10 23:17:33898 ShortenUberURL(browser()->tab_strip_model()->
899 GetActiveWebContents()->GetURL()));
[email protected]fee320542011-03-02 01:30:49900}
901
902// This test verifies that constructing params with disposition = SINGLETON_TAB
903// and IGNORE_AND_NAVIGATE will update the current tab's URL if the currently
[email protected]637b3442011-01-10 23:31:48904// selected tab is a match but has a different path.
905IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
906 Disposition_SingletonTabFocused_IgnorePath) {
[email protected]a048ad22012-03-23 04:26:56907 GURL singleton_url_current(GetContentSettingsURL());
[email protected]52877dbc62012-06-29 22:22:03908 chrome::AddSelectedTabWithURL(browser(), singleton_url_current,
909 content::PAGE_TRANSITION_LINK);
[email protected]637b3442011-01-10 23:31:48910
911 // We should have one browser with 2 tabs, the 2nd selected.
[email protected]0665ebe2013-02-13 09:53:19912 EXPECT_EQ(1u, chrome::GetTotalBrowserCount());
[email protected]ee496952013-01-10 23:17:33913 EXPECT_EQ(2, browser()->tab_strip_model()->count());
914 EXPECT_EQ(1, browser()->tab_strip_model()->active_index());
[email protected]637b3442011-01-10 23:31:48915
916 // Navigate to a different settings path.
[email protected]a048ad22012-03-23 04:26:56917 GURL singleton_url_target(GetClearBrowsingDataURL());
[email protected]78e2edc2012-07-01 23:32:28918 chrome::NavigateParams p(MakeNavigateParams());
[email protected]637b3442011-01-10 23:31:48919 p.disposition = SINGLETON_TAB;
920 p.url = singleton_url_target;
[email protected]50592b52013-05-02 22:26:25921 p.window_action = chrome::NavigateParams::SHOW_WINDOW;
[email protected]78e2edc2012-07-01 23:32:28922 p.path_behavior = chrome::NavigateParams::IGNORE_AND_NAVIGATE;
923 chrome::Navigate(&p);
[email protected]637b3442011-01-10 23:31:48924
925 // The second tab should still be selected, but navigated to the new path.
926 EXPECT_EQ(browser(), p.browser);
[email protected]ee496952013-01-10 23:17:33927 EXPECT_EQ(2, browser()->tab_strip_model()->count());
928 EXPECT_EQ(1, browser()->tab_strip_model()->active_index());
[email protected]637b3442011-01-10 23:31:48929 EXPECT_EQ(singleton_url_target,
[email protected]ee496952013-01-10 23:17:33930 ShortenUberURL(browser()->tab_strip_model()->
931 GetActiveWebContents()->GetURL()));
[email protected]637b3442011-01-10 23:31:48932}
933
[email protected]07afd7c2011-02-17 10:07:11934// This test verifies that constructing params with disposition = SINGLETON_TAB
[email protected]fee320542011-03-02 01:30:49935// and IGNORE_AND_NAVIGATE will open an existing matching tab with a different
936// query.
[email protected]07afd7c2011-02-17 10:07:11937IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
938 Disposition_SingletonTabExisting_IgnoreQuery) {
[email protected]ee496952013-01-10 23:17:33939 int initial_tab_count = browser()->tab_strip_model()->count();
[email protected]07afd7c2011-02-17 10:07:11940 GURL singleton_url_current("chrome://settings/internet");
[email protected]52877dbc62012-06-29 22:22:03941 chrome::AddSelectedTabWithURL(browser(), singleton_url_current,
942 content::PAGE_TRANSITION_LINK);
[email protected]07afd7c2011-02-17 10:07:11943
[email protected]ee496952013-01-10 23:17:33944 EXPECT_EQ(initial_tab_count + 1, browser()->tab_strip_model()->count());
945 EXPECT_EQ(initial_tab_count, browser()->tab_strip_model()->active_index());
[email protected]07afd7c2011-02-17 10:07:11946
947 // Navigate to a different settings path.
948 GURL singleton_url_target(
949 "chrome://settings/internet?"
950 "servicePath=/profile/ethernet_00aa00aa00aa&networkType=1");
[email protected]78e2edc2012-07-01 23:32:28951 chrome::NavigateParams p(MakeNavigateParams());
[email protected]07afd7c2011-02-17 10:07:11952 p.disposition = SINGLETON_TAB;
953 p.url = singleton_url_target;
[email protected]50592b52013-05-02 22:26:25954 p.window_action = chrome::NavigateParams::SHOW_WINDOW;
[email protected]78e2edc2012-07-01 23:32:28955 p.path_behavior = chrome::NavigateParams::IGNORE_AND_NAVIGATE;
956 chrome::Navigate(&p);
[email protected]07afd7c2011-02-17 10:07:11957
958 // Last tab should still be selected.
959 EXPECT_EQ(browser(), p.browser);
[email protected]ee496952013-01-10 23:17:33960 EXPECT_EQ(initial_tab_count + 1, browser()->tab_strip_model()->count());
961 EXPECT_EQ(initial_tab_count, browser()->tab_strip_model()->active_index());
[email protected]07afd7c2011-02-17 10:07:11962}
963
[email protected]bd817c22011-02-09 08:16:46964// This test verifies that the settings page isn't opened in the incognito
965// window.
[email protected]a048ad22012-03-23 04:26:56966// Disabled until fixed for uber settings: http://crbug.com/111243
[email protected]bd817c22011-02-09 08:16:46967IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
[email protected]a048ad22012-03-23 04:26:56968 DISABLED_Disposition_Settings_UseNonIncognitoWindow) {
[email protected]fc0ed302011-11-29 23:17:19969 RunUseNonIncognitoWindowTest(GetSettingsURL());
[email protected]bd817c22011-02-09 08:16:46970}
971
[email protected]429e9712013-04-30 09:35:50972// This test verifies that the view-source settings page isn't opened in the
973// incognito window.
974IN_PROC_BROWSER_TEST_F(
975 BrowserNavigatorTest,
976 Disposition_ViewSource_Settings_DoNothingIfIncognitoForced) {
[email protected]dbdda5402013-05-30 22:13:48977 std::string view_source(content::kViewSourceScheme);
[email protected]429e9712013-04-30 09:35:50978 view_source.append(":");
979 view_source.append(chrome::kChromeUISettingsURL);
980 RunDoNothingIfIncognitoIsForcedTest(GURL(view_source));
981}
982
983// This test verifies that the view-source settings page isn't opened in the
984// incognito window even if incognito mode is forced (does nothing in that
985// case).
986IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
987 Disposition_ViewSource_Settings_UseNonIncognitoWindow) {
[email protected]dbdda5402013-05-30 22:13:48988 std::string view_source(content::kViewSourceScheme);
[email protected]429e9712013-04-30 09:35:50989 view_source.append(":");
990 view_source.append(chrome::kChromeUISettingsURL);
991 RunUseNonIncognitoWindowTest(GURL(view_source));
992}
993
[email protected]82404cd2011-07-12 19:55:14994// This test verifies that the settings page isn't opened in the incognito
995// window from a non-incognito window (bookmark open-in-incognito trigger).
[email protected]a048ad22012-03-23 04:26:56996// Disabled until fixed for uber settings: http://crbug.com/111243
[email protected]82404cd2011-07-12 19:55:14997IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
[email protected]a048ad22012-03-23 04:26:56998 DISABLED_Disposition_Settings_UseNonIncognitoWindowForBookmark) {
[email protected]78e2edc2012-07-01 23:32:28999 chrome::NavigateParams params(browser(), GetSettingsURL(),
1000 content::PAGE_TRANSITION_AUTO_BOOKMARK);
[email protected]82404cd2011-07-12 19:55:141001 params.disposition = OFF_THE_RECORD;
1002 {
[email protected]a7fe9112012-07-20 02:34:451003 content::WindowedNotificationObserver observer(
[email protected]ad50def52011-10-19 23:17:071004 content::NOTIFICATION_LOAD_STOP,
1005 content::NotificationService::AllSources());
[email protected]78e2edc2012-07-01 23:32:281006 chrome::Navigate(&params);
[email protected]82404cd2011-07-12 19:55:141007 observer.Wait();
1008 }
1009
[email protected]0665ebe2013-02-13 09:53:191010 EXPECT_EQ(1u, chrome::GetTotalBrowserCount());
[email protected]52877dbc62012-06-29 22:22:031011 EXPECT_EQ(GetSettingsURL(),
[email protected]ee496952013-01-10 23:17:331012 ShortenUberURL(browser()->tab_strip_model()->
1013 GetActiveWebContents()->GetURL()));
[email protected]82404cd2011-07-12 19:55:141014}
1015
[email protected]93ad8e1c2011-11-08 21:34:051016// Settings page is expected to always open in normal mode regardless
1017// of whether the user is trying to open it in incognito mode or not.
1018// This test verifies that if incognito mode is forced (by policy), settings
1019// page doesn't open at all.
[email protected]a048ad22012-03-23 04:26:561020// Disabled until fixed for uber settings: http://crbug.com/111243
[email protected]93ad8e1c2011-11-08 21:34:051021IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
[email protected]a048ad22012-03-23 04:26:561022 DISABLED_Disposition_Settings_DoNothingIfIncognitoIsForced) {
[email protected]fc0ed302011-11-29 23:17:191023 RunDoNothingIfIncognitoIsForcedTest(GetSettingsURL());
[email protected]93ad8e1c2011-11-08 21:34:051024}
1025
[email protected]bd817c22011-02-09 08:16:461026// This test verifies that the bookmarks page isn't opened in the incognito
1027// window.
1028IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
1029 Disposition_Bookmarks_UseNonIncognitoWindow) {
[email protected]fc0ed302011-11-29 23:17:191030 RunUseNonIncognitoWindowTest(GURL(chrome::kChromeUIBookmarksURL));
[email protected]bd817c22011-02-09 08:16:461031}
1032
[email protected]93ad8e1c2011-11-08 21:34:051033// Bookmark manager is expected to always open in normal mode regardless
1034// of whether the user is trying to open it in incognito mode or not.
1035// This test verifies that if incognito mode is forced (by policy), bookmark
1036// manager doesn't open at all.
1037IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
1038 Disposition_Bookmarks_DoNothingIfIncognitoIsForced) {
[email protected]fc0ed302011-11-29 23:17:191039 RunDoNothingIfIncognitoIsForcedTest(GURL(chrome::kChromeUIBookmarksURL));
1040}
[email protected]93ad8e1c2011-11-08 21:34:051041
[email protected]7de53c62011-05-13 06:44:161042// This test makes sure a crashed singleton tab reloads from a new navigation.
1043IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
1044 NavigateToCrashedSingletonTab) {
[email protected]a048ad22012-03-23 04:26:561045 GURL singleton_url(GetContentSettingsURL());
[email protected]5a1a52462012-11-15 03:35:161046 WebContents* web_contents = chrome::AddSelectedTabWithURL(
[email protected]52877dbc62012-06-29 22:22:031047 browser(), singleton_url, content::PAGE_TRANSITION_LINK);
[email protected]7de53c62011-05-13 06:44:161048
1049 // We should have one browser with 2 tabs, the 2nd selected.
[email protected]0665ebe2013-02-13 09:53:191050 EXPECT_EQ(1u, chrome::GetTotalBrowserCount());
[email protected]ee496952013-01-10 23:17:331051 EXPECT_EQ(2, browser()->tab_strip_model()->count());
1052 EXPECT_EQ(1, browser()->tab_strip_model()->active_index());
[email protected]7de53c62011-05-13 06:44:161053
1054 // Kill the singleton tab.
[email protected]83ff91c2012-01-05 20:54:131055 web_contents->SetIsCrashed(base::TERMINATION_STATUS_PROCESS_CRASHED, -1);
1056 EXPECT_TRUE(web_contents->IsCrashed());
[email protected]7de53c62011-05-13 06:44:161057
[email protected]78e2edc2012-07-01 23:32:281058 chrome::NavigateParams p(MakeNavigateParams());
[email protected]7de53c62011-05-13 06:44:161059 p.disposition = SINGLETON_TAB;
1060 p.url = singleton_url;
[email protected]50592b52013-05-02 22:26:251061 p.window_action = chrome::NavigateParams::SHOW_WINDOW;
[email protected]78e2edc2012-07-01 23:32:281062 p.path_behavior = chrome::NavigateParams::IGNORE_AND_NAVIGATE;
[email protected]ddddfda2011-07-14 23:19:391063 ui_test_utils::NavigateToURL(&p);
[email protected]7de53c62011-05-13 06:44:161064
1065 // The tab should not be sad anymore.
[email protected]83ff91c2012-01-05 20:54:131066 EXPECT_FALSE(web_contents->IsCrashed());
[email protected]7de53c62011-05-13 06:44:161067}
1068
[email protected]fcca741b2011-06-17 22:46:371069IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
1070 NavigateFromDefaultToOptionsInSameTab) {
[email protected]ddddfda2011-07-14 23:19:391071 {
[email protected]a7fe9112012-07-20 02:34:451072 content::WindowedNotificationObserver observer(
[email protected]ad50def52011-10-19 23:17:071073 content::NOTIFICATION_LOAD_STOP,
1074 content::NotificationService::AllSources());
[email protected]5d9cace72012-06-21 16:07:121075 chrome::ShowSettings(browser());
[email protected]ddddfda2011-07-14 23:19:391076 observer.Wait();
1077 }
[email protected]ee496952013-01-10 23:17:331078 EXPECT_EQ(1, browser()->tab_strip_model()->count());
[email protected]52877dbc62012-06-29 22:22:031079 EXPECT_EQ(GetSettingsURL(),
[email protected]ee496952013-01-10 23:17:331080 ShortenUberURL(browser()->tab_strip_model()->
1081 GetActiveWebContents()->GetURL()));
[email protected]fcca741b2011-06-17 22:46:371082}
1083
1084IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
1085 NavigateFromBlankToOptionsInSameTab) {
[email protected]78e2edc2012-07-01 23:32:281086 chrome::NavigateParams p(MakeNavigateParams());
[email protected]081dc522013-05-15 04:59:201087 p.url = GURL(content::kAboutBlankURL);
[email protected]ddddfda2011-07-14 23:19:391088 ui_test_utils::NavigateToURL(&p);
[email protected]fcca741b2011-06-17 22:46:371089
[email protected]ddddfda2011-07-14 23:19:391090 {
[email protected]a7fe9112012-07-20 02:34:451091 content::WindowedNotificationObserver observer(
[email protected]ad50def52011-10-19 23:17:071092 content::NOTIFICATION_LOAD_STOP,
1093 content::NotificationService::AllSources());
[email protected]5d9cace72012-06-21 16:07:121094 chrome::ShowSettings(browser());
[email protected]ddddfda2011-07-14 23:19:391095 observer.Wait();
1096 }
[email protected]ee496952013-01-10 23:17:331097 EXPECT_EQ(1, browser()->tab_strip_model()->count());
[email protected]52877dbc62012-06-29 22:22:031098 EXPECT_EQ(GetSettingsURL(),
[email protected]ee496952013-01-10 23:17:331099 ShortenUberURL(browser()->tab_strip_model()->
1100 GetActiveWebContents()->GetURL()));
[email protected]fcca741b2011-06-17 22:46:371101}
1102
1103IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
1104 NavigateFromNTPToOptionsInSameTab) {
[email protected]78e2edc2012-07-01 23:32:281105 chrome::NavigateParams p(MakeNavigateParams());
[email protected]ddddfda2011-07-14 23:19:391106 p.url = GURL(chrome::kChromeUINewTabURL);
1107 ui_test_utils::NavigateToURL(&p);
[email protected]ee496952013-01-10 23:17:331108 EXPECT_EQ(1, browser()->tab_strip_model()->count());
[email protected]27658f32013-11-14 03:20:371109 EXPECT_EQ(GURL(chrome::kChromeUINewTabURL),
1110 browser()->tab_strip_model()->GetActiveWebContents()->GetURL());
[email protected]fcca741b2011-06-17 22:46:371111
[email protected]ddddfda2011-07-14 23:19:391112 {
[email protected]a7fe9112012-07-20 02:34:451113 content::WindowedNotificationObserver observer(
[email protected]ad50def52011-10-19 23:17:071114 content::NOTIFICATION_LOAD_STOP,
1115 content::NotificationService::AllSources());
[email protected]5d9cace72012-06-21 16:07:121116 chrome::ShowSettings(browser());
[email protected]ddddfda2011-07-14 23:19:391117 observer.Wait();
1118 }
[email protected]ee496952013-01-10 23:17:331119 EXPECT_EQ(1, browser()->tab_strip_model()->count());
[email protected]52877dbc62012-06-29 22:22:031120 EXPECT_EQ(GetSettingsURL(),
[email protected]ee496952013-01-10 23:17:331121 ShortenUberURL(browser()->tab_strip_model()->
1122 GetActiveWebContents()->GetURL()));
[email protected]fcca741b2011-06-17 22:46:371123}
1124
1125IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
1126 NavigateFromPageToOptionsInNewTab) {
[email protected]78e2edc2012-07-01 23:32:281127 chrome::NavigateParams p(MakeNavigateParams());
[email protected]ddddfda2011-07-14 23:19:391128 ui_test_utils::NavigateToURL(&p);
[email protected]ee496952013-01-10 23:17:331129 EXPECT_EQ(GetGoogleURL(),
1130 browser()->tab_strip_model()->GetActiveWebContents()->GetURL());
[email protected]0665ebe2013-02-13 09:53:191131 EXPECT_EQ(1u, chrome::GetTotalBrowserCount());
[email protected]ee496952013-01-10 23:17:331132 EXPECT_EQ(1, browser()->tab_strip_model()->count());
[email protected]fcca741b2011-06-17 22:46:371133
[email protected]ddddfda2011-07-14 23:19:391134 {
[email protected]a7fe9112012-07-20 02:34:451135 content::WindowedNotificationObserver observer(
[email protected]ad50def52011-10-19 23:17:071136 content::NOTIFICATION_LOAD_STOP,
1137 content::NotificationService::AllSources());
[email protected]5d9cace72012-06-21 16:07:121138 chrome::ShowSettings(browser());
[email protected]ddddfda2011-07-14 23:19:391139 observer.Wait();
1140 }
[email protected]ee496952013-01-10 23:17:331141 EXPECT_EQ(2, browser()->tab_strip_model()->count());
[email protected]52877dbc62012-06-29 22:22:031142 EXPECT_EQ(GetSettingsURL(),
[email protected]ee496952013-01-10 23:17:331143 ShortenUberURL(browser()->tab_strip_model()->
1144 GetActiveWebContents()->GetURL()));
[email protected]fcca741b2011-06-17 22:46:371145}
1146
1147IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
1148 NavigateFromNTPToOptionsSingleton) {
[email protected]ddddfda2011-07-14 23:19:391149 {
[email protected]a7fe9112012-07-20 02:34:451150 content::WindowedNotificationObserver observer(
[email protected]ad50def52011-10-19 23:17:071151 content::NOTIFICATION_LOAD_STOP,
1152 content::NotificationService::AllSources());
[email protected]5d9cace72012-06-21 16:07:121153 chrome::ShowSettings(browser());
[email protected]ddddfda2011-07-14 23:19:391154 observer.Wait();
1155 }
[email protected]ee496952013-01-10 23:17:331156 EXPECT_EQ(1, browser()->tab_strip_model()->count());
[email protected]fcca741b2011-06-17 22:46:371157
[email protected]a37d4b02012-06-25 21:56:101158 chrome::NewTab(browser());
[email protected]ee496952013-01-10 23:17:331159 EXPECT_EQ(2, browser()->tab_strip_model()->count());
[email protected]fcca741b2011-06-17 22:46:371160
[email protected]ddddfda2011-07-14 23:19:391161 {
[email protected]a7fe9112012-07-20 02:34:451162 content::WindowedNotificationObserver observer(
[email protected]ad50def52011-10-19 23:17:071163 content::NOTIFICATION_LOAD_STOP,
1164 content::NotificationService::AllSources());
[email protected]5d9cace72012-06-21 16:07:121165 chrome::ShowSettings(browser());
[email protected]ddddfda2011-07-14 23:19:391166 observer.Wait();
1167 }
[email protected]ee496952013-01-10 23:17:331168 EXPECT_EQ(2, browser()->tab_strip_model()->count());
[email protected]52877dbc62012-06-29 22:22:031169 EXPECT_EQ(GetSettingsURL(),
[email protected]ee496952013-01-10 23:17:331170 ShortenUberURL(browser()->tab_strip_model()->
1171 GetActiveWebContents()->GetURL()));
[email protected]fcca741b2011-06-17 22:46:371172}
1173
1174IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
1175 NavigateFromNTPToOptionsPageInSameTab) {
[email protected]ddddfda2011-07-14 23:19:391176 {
[email protected]a7fe9112012-07-20 02:34:451177 content::WindowedNotificationObserver observer(
[email protected]ad50def52011-10-19 23:17:071178 content::NOTIFICATION_LOAD_STOP,
1179 content::NotificationService::AllSources());
[email protected]5d9cace72012-06-21 16:07:121180 chrome::ShowClearBrowsingDataDialog(browser());
[email protected]ddddfda2011-07-14 23:19:391181 observer.Wait();
1182 }
[email protected]ee496952013-01-10 23:17:331183 EXPECT_EQ(1, browser()->tab_strip_model()->count());
[email protected]a048ad22012-03-23 04:26:561184 EXPECT_EQ(GetClearBrowsingDataURL(),
[email protected]ee496952013-01-10 23:17:331185 browser()->tab_strip_model()->GetActiveWebContents()->GetURL());
[email protected]fcca741b2011-06-17 22:46:371186
[email protected]a37d4b02012-06-25 21:56:101187 chrome::NewTab(browser());
[email protected]ee496952013-01-10 23:17:331188 EXPECT_EQ(2, browser()->tab_strip_model()->count());
[email protected]fcca741b2011-06-17 22:46:371189
[email protected]ddddfda2011-07-14 23:19:391190 {
[email protected]a7fe9112012-07-20 02:34:451191 content::WindowedNotificationObserver observer(
[email protected]ad50def52011-10-19 23:17:071192 content::NOTIFICATION_LOAD_STOP,
1193 content::NotificationService::AllSources());
[email protected]5d9cace72012-06-21 16:07:121194 chrome::ShowClearBrowsingDataDialog(browser());
[email protected]ddddfda2011-07-14 23:19:391195 observer.Wait();
1196 }
[email protected]ee496952013-01-10 23:17:331197 EXPECT_EQ(2, browser()->tab_strip_model()->count());
[email protected]a048ad22012-03-23 04:26:561198 EXPECT_EQ(GetClearBrowsingDataURL(),
[email protected]ee496952013-01-10 23:17:331199 browser()->tab_strip_model()->GetActiveWebContents()->GetURL());
[email protected]fcca741b2011-06-17 22:46:371200}
1201
[email protected]fcca741b2011-06-17 22:46:371202IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
[email protected]05912742013-03-12 00:29:151203 NavigateFromOtherTabToSingletonOptions) {
[email protected]ddddfda2011-07-14 23:19:391204 {
[email protected]a7fe9112012-07-20 02:34:451205 content::WindowedNotificationObserver observer(
[email protected]ad50def52011-10-19 23:17:071206 content::NOTIFICATION_LOAD_STOP,
1207 content::NotificationService::AllSources());
[email protected]5d9cace72012-06-21 16:07:121208 chrome::ShowSettings(browser());
[email protected]ddddfda2011-07-14 23:19:391209 observer.Wait();
1210 }
1211 {
[email protected]a7fe9112012-07-20 02:34:451212 content::WindowedNotificationObserver observer(
[email protected]ad50def52011-10-19 23:17:071213 content::NOTIFICATION_LOAD_STOP,
1214 content::NotificationService::AllSources());
[email protected]52877dbc62012-06-29 22:22:031215 chrome::AddSelectedTabWithURL(browser(), GetGoogleURL(),
1216 content::PAGE_TRANSITION_LINK);
[email protected]ddddfda2011-07-14 23:19:391217 observer.Wait();
1218 }
[email protected]fcca741b2011-06-17 22:46:371219
[email protected]05912742013-03-12 00:29:151220 // This load should simply cause a tab switch.
1221 chrome::ShowSettings(browser());
1222
[email protected]ee496952013-01-10 23:17:331223 EXPECT_EQ(2, browser()->tab_strip_model()->count());
[email protected]ddddfda2011-07-14 23:19:391224 EXPECT_EQ(GetSettingsURL(),
[email protected]ee496952013-01-10 23:17:331225 ShortenUberURL(browser()->tab_strip_model()->
1226 GetActiveWebContents()->GetURL()));
[email protected]fcca741b2011-06-17 22:46:371227}
1228
[email protected]4e78b2d2013-06-12 16:46:171229IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, CloseSingletonTab) {
[email protected]79717cf2013-02-28 18:40:361230 for (int i = 0; i < 2; ++i) {
1231 content::WindowedNotificationObserver observer(
1232 content::NOTIFICATION_LOAD_STOP,
1233 content::NotificationService::AllSources());
1234 chrome::AddSelectedTabWithURL(browser(), GetGoogleURL(),
1235 content::PAGE_TRANSITION_TYPED);
1236 observer.Wait();
1237 }
1238
1239 browser()->tab_strip_model()->ActivateTabAt(0, true);
1240
1241 {
1242 content::WindowedNotificationObserver observer(
1243 content::NOTIFICATION_LOAD_STOP,
1244 content::NotificationService::AllSources());
1245 chrome::ShowSettings(browser());
1246 observer.Wait();
1247 }
1248
1249 EXPECT_TRUE(browser()->tab_strip_model()->CloseWebContentsAt(
1250 2, TabStripModel::CLOSE_USER_GESTURE));
1251 EXPECT_EQ(0, browser()->tab_strip_model()->active_index());
1252}
1253
[email protected]a048ad22012-03-23 04:26:561254// TODO(csilv): Update this for uber page. http://crbug.com/111579.
[email protected]ddddfda2011-07-14 23:19:391255IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
[email protected]a048ad22012-03-23 04:26:561256 DISABLED_NavigateFromDefaultToHistoryInSameTab) {
[email protected]ddddfda2011-07-14 23:19:391257 {
[email protected]a7fe9112012-07-20 02:34:451258 content::WindowedNotificationObserver observer(
[email protected]ad50def52011-10-19 23:17:071259 content::NOTIFICATION_LOAD_STOP,
1260 content::NotificationService::AllSources());
[email protected]5d9cace72012-06-21 16:07:121261 chrome::ShowHistory(browser());
[email protected]ddddfda2011-07-14 23:19:391262 observer.Wait();
1263 }
[email protected]ee496952013-01-10 23:17:331264 EXPECT_EQ(1, browser()->tab_strip_model()->count());
[email protected]11e03fb2012-03-03 19:07:051265 EXPECT_EQ(GURL(chrome::kChromeUIHistoryFrameURL),
[email protected]ee496952013-01-10 23:17:331266 browser()->tab_strip_model()->GetActiveWebContents()->GetURL());
[email protected]ddddfda2011-07-14 23:19:391267}
1268
[email protected]953c2132013-02-23 05:56:051269// TODO(linux_aura) http://crbug.com/163931
1270#if defined(OS_LINUX) && !defined(OS_CHROMEOS) && defined(USE_AURA)
1271#define MAYBE_NavigateFromDefaultToBookmarksInSameTab DISABLED_NavigateFromDefaultToBookmarksInSameTab
1272#else
1273#define MAYBE_NavigateFromDefaultToBookmarksInSameTab NavigateFromDefaultToBookmarksInSameTab
1274#endif
[email protected]ddddfda2011-07-14 23:19:391275IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
[email protected]953c2132013-02-23 05:56:051276 MAYBE_NavigateFromDefaultToBookmarksInSameTab) {
[email protected]ddddfda2011-07-14 23:19:391277 {
[email protected]a7fe9112012-07-20 02:34:451278 content::WindowedNotificationObserver observer(
[email protected]ad50def52011-10-19 23:17:071279 content::NOTIFICATION_LOAD_STOP,
1280 content::NotificationService::AllSources());
[email protected]5d9cace72012-06-21 16:07:121281 chrome::ShowBookmarkManager(browser());
[email protected]ddddfda2011-07-14 23:19:391282 observer.Wait();
1283 }
[email protected]ee496952013-01-10 23:17:331284 EXPECT_EQ(1, browser()->tab_strip_model()->count());
[email protected]bc16a252013-01-23 02:21:491285 EXPECT_TRUE(StartsWithASCII(
1286 browser()->tab_strip_model()->GetActiveWebContents()->GetURL().spec(),
1287 chrome::kChromeUIBookmarksURL,
1288 true));
[email protected]ddddfda2011-07-14 23:19:391289}
1290
1291IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
1292 NavigateFromDefaultToDownloadsInSameTab) {
1293 {
[email protected]a7fe9112012-07-20 02:34:451294 content::WindowedNotificationObserver observer(
[email protected]ad50def52011-10-19 23:17:071295 content::NOTIFICATION_LOAD_STOP,
1296 content::NotificationService::AllSources());
[email protected]5d9cace72012-06-21 16:07:121297 chrome::ShowDownloads(browser());
[email protected]ddddfda2011-07-14 23:19:391298 observer.Wait();
1299 }
[email protected]ee496952013-01-10 23:17:331300 EXPECT_EQ(1, browser()->tab_strip_model()->count());
[email protected]ddddfda2011-07-14 23:19:391301 EXPECT_EQ(GURL(chrome::kChromeUIDownloadsURL),
[email protected]ee496952013-01-10 23:17:331302 browser()->tab_strip_model()->GetActiveWebContents()->GetURL());
[email protected]ddddfda2011-07-14 23:19:391303}
1304
[email protected]8fb16a82012-08-17 02:17:591305IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
1306 NavigateWithoutBrowser) {
1307 // First navigate using the profile of the existing browser window, and
1308 // check that the window is reused.
1309 chrome::NavigateParams params(browser()->profile(), GetGoogleURL(),
1310 content::PAGE_TRANSITION_LINK);
1311 ui_test_utils::NavigateToURL(&params);
[email protected]0665ebe2013-02-13 09:53:191312 EXPECT_EQ(1u, chrome::GetTotalBrowserCount());
[email protected]8fb16a82012-08-17 02:17:591313
1314 // Now navigate using the incognito profile and check that a new window
1315 // is created.
1316 chrome::NavigateParams params_incognito(
1317 browser()->profile()->GetOffTheRecordProfile(),
1318 GetGoogleURL(), content::PAGE_TRANSITION_LINK);
1319 ui_test_utils::NavigateToURL(&params_incognito);
[email protected]0665ebe2013-02-13 09:53:191320 EXPECT_EQ(2u, chrome::GetTotalBrowserCount());
[email protected]8fb16a82012-08-17 02:17:591321}
1322
[email protected]beb1d1192013-05-14 04:47:511323IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, ViewSourceIsntSingleton) {
1324 const std::string viewsource_ntp_url =
[email protected]dbdda5402013-05-30 22:13:481325 std::string(content::kViewSourceScheme) + ":" +
[email protected]beb1d1192013-05-14 04:47:511326 chrome::kChromeUIVersionURL;
1327
1328 chrome::NavigateParams viewsource_params(browser(),
1329 GURL(viewsource_ntp_url),
1330 content::PAGE_TRANSITION_LINK);
1331 ui_test_utils::NavigateToURL(&viewsource_params);
1332
1333 chrome::NavigateParams singleton_params(browser(),
1334 GURL(chrome::kChromeUIVersionURL),
1335 content::PAGE_TRANSITION_LINK);
1336 singleton_params.disposition = SINGLETON_TAB;
1337 EXPECT_EQ(-1, chrome::GetIndexOfSingletonTab(&singleton_params));
1338}
1339
[email protected]a2efc35d2013-08-03 23:17:251340// This test verifies that browser initiated navigations can send requests
1341// using POST.
1342IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
1343 SendBrowserInitiatedRequestUsingPOST) {
1344 // Uses a test sever to verify POST request.
1345 ASSERT_TRUE(test_server()->Start());
1346
1347 // Open a browser initiated POST request in new foreground tab.
[email protected]e9273e192013-12-11 17:51:491348 base::string16 expected_title(base::ASCIIToUTF16(kExpectedTitle));
[email protected]a2efc35d2013-08-03 23:17:251349 std::string post_data = kExpectedTitle;
[email protected]e9273e192013-12-11 17:51:491350 base::string16 title;
[email protected]a2efc35d2013-08-03 23:17:251351 ASSERT_TRUE(OpenPOSTURLInNewForegroundTabAndGetTitle(
1352 test_server()->GetURL(kEchoTitleCommand), post_data, true, &title));
1353 EXPECT_EQ(expected_title, title);
1354}
1355
1356// This test verifies that renderer initiated navigations can NOT send requests
1357// using POST.
1358IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
1359 SendRendererInitiatedRequestUsingPOST) {
1360 // Uses a test sever to verify POST request.
1361 ASSERT_TRUE(test_server()->Start());
1362
1363 // Open a renderer initiated POST request in new foreground tab.
[email protected]e9273e192013-12-11 17:51:491364 base::string16 expected_title(base::ASCIIToUTF16(kExpectedTitle));
[email protected]a2efc35d2013-08-03 23:17:251365 std::string post_data = kExpectedTitle;
[email protected]e9273e192013-12-11 17:51:491366 base::string16 title;
[email protected]a2efc35d2013-08-03 23:17:251367 ASSERT_TRUE(OpenPOSTURLInNewForegroundTabAndGetTitle(
1368 test_server()->GetURL(kEchoTitleCommand), post_data, false, &title));
1369 EXPECT_NE(expected_title, title);
1370}
1371
1372} // namespace