blob: 037bf35b3681e16143e04cb995a10e34118e0228 [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]8e09c7af2014-06-10 11:46:17195 EXPECT_EQ(GURL(url::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]aae79572014-06-13 00:42:58199void BrowserNavigatorTest::SetUpCommandLine(base::CommandLine* command_line) {
200 // Disable settings-in-a-window so that we can use the settings page and
201 // sub-pages to test browser navigation.
202 command_line->AppendSwitch(::switches::kDisableSettingsWindow);
203}
204
[email protected]6c2381d2011-10-19 02:52:53205void BrowserNavigatorTest::Observe(
206 int type,
207 const content::NotificationSource& source,
208 const content::NotificationDetails& details) {
[email protected]432115822011-07-10 15:52:27209 switch (type) {
[email protected]d53a08c2012-07-18 20:35:30210 case content::NOTIFICATION_WEB_CONTENTS_RENDER_VIEW_HOST_CREATED: {
[email protected]bd817c22011-02-09 08:16:46211 ++this->created_tab_contents_count_;
212 break;
[email protected]fa7ebe02010-11-29 23:04:57213 }
[email protected]bd817c22011-02-09 08:16:46214 default:
215 break;
[email protected]fa7ebe02010-11-29 23:04:57216 }
[email protected]bd817c22011-02-09 08:16:46217}
[email protected]fa7ebe02010-11-29 23:04:57218
[email protected]ddddfda2011-07-14 23:19:39219
[email protected]bd817c22011-02-09 08:16:46220namespace {
[email protected]a1feae52010-10-11 22:14:45221
[email protected]a1feae52010-10-11 22:14:45222// This test verifies that when a navigation occurs within a tab, the tab count
223// of the Browser remains the same and the current tab bears the loaded URL.
[email protected]59167c22013-06-03 18:07:32224// Note that network URLs are not actually loaded in tests, so this also tests
225// that error pages leave the intended URL in the address bar.
[email protected]a1feae52010-10-11 22:14:45226IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_CurrentTab) {
[email protected]ddddfda2011-07-14 23:19:39227 ui_test_utils::NavigateToURL(browser(), GetGoogleURL());
[email protected]ee496952013-01-10 23:17:33228 EXPECT_EQ(GetGoogleURL(),
229 browser()->tab_strip_model()->GetActiveWebContents()->GetURL());
[email protected]a1feae52010-10-11 22:14:45230 // We should have one window with one tab.
[email protected]0665ebe2013-02-13 09:53:19231 EXPECT_EQ(1u, chrome::GetTotalBrowserCount());
[email protected]ee496952013-01-10 23:17:33232 EXPECT_EQ(1, browser()->tab_strip_model()->count());
[email protected]a1feae52010-10-11 22:14:45233}
234
[email protected]bd817c22011-02-09 08:16:46235// This test verifies that a singleton tab is refocused if one is already opened
[email protected]19d9f3a2010-10-14 21:49:36236// in another or an existing window, or added if it is not.
237IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_SingletonTabExisting) {
[email protected]19d9f3a2010-10-14 21:49:36238 GURL singleton_url1("http://maps.google.com/");
[email protected]fa7ebe02010-11-29 23:04:57239
[email protected]e232c992012-12-06 12:43:20240 // Register for a notification if an additional WebContents was instantiated.
[email protected]bd817c22011-02-09 08:16:46241 // Opening a Singleton tab that is already opened should not be opening a new
[email protected]e232c992012-12-06 12:43:20242 // tab nor be creating a new WebContents object.
[email protected]6c2381d2011-10-19 02:52:53243 content::NotificationRegistrar registrar;
[email protected]fa7ebe02010-11-29 23:04:57244
245 // As the registrar object goes out of scope, this will get unregistered
[email protected]d53a08c2012-07-18 20:35:30246 registrar.Add(this,
247 content::NOTIFICATION_WEB_CONTENTS_RENDER_VIEW_HOST_CREATED,
[email protected]ad50def52011-10-19 23:17:07248 content::NotificationService::AllSources());
[email protected]fa7ebe02010-11-29 23:04:57249
[email protected]52877dbc62012-06-29 22:22:03250 chrome::AddSelectedTabWithURL(browser(), singleton_url1,
251 content::PAGE_TRANSITION_LINK);
252 chrome::AddSelectedTabWithURL(browser(), GetGoogleURL(),
253 content::PAGE_TRANSITION_LINK);
[email protected]19d9f3a2010-10-14 21:49:36254
255 // We should have one browser with 3 tabs, the 3rd selected.
[email protected]0665ebe2013-02-13 09:53:19256 EXPECT_EQ(1u, chrome::GetTotalBrowserCount());
[email protected]ee496952013-01-10 23:17:33257 EXPECT_EQ(2, browser()->tab_strip_model()->active_index());
[email protected]19d9f3a2010-10-14 21:49:36258
[email protected]fa7ebe02010-11-29 23:04:57259 unsigned int previous_tab_contents_count =
260 created_tab_contents_count_ = 0;
261
[email protected]19d9f3a2010-10-14 21:49:36262 // Navigate to singleton_url1.
[email protected]78e2edc2012-07-01 23:32:28263 chrome::NavigateParams p(MakeNavigateParams());
[email protected]19d9f3a2010-10-14 21:49:36264 p.disposition = SINGLETON_TAB;
265 p.url = singleton_url1;
[email protected]78e2edc2012-07-01 23:32:28266 chrome::Navigate(&p);
[email protected]19d9f3a2010-10-14 21:49:36267
268 // The middle tab should now be selected.
269 EXPECT_EQ(browser(), p.browser);
[email protected]ee496952013-01-10 23:17:33270 EXPECT_EQ(1, browser()->tab_strip_model()->active_index());
[email protected]fa7ebe02010-11-29 23:04:57271
272 // No tab contents should have been created
273 EXPECT_EQ(previous_tab_contents_count,
274 created_tab_contents_count_);
[email protected]19d9f3a2010-10-14 21:49:36275}
276
277IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
[email protected]578c6962011-08-24 22:06:40278 Disposition_SingletonTabRespectingRef) {
279 GURL singleton_ref_url1("http://maps.google.com/#a");
280 GURL singleton_ref_url2("http://maps.google.com/#b");
281 GURL singleton_ref_url3("http://maps.google.com/");
282
[email protected]52877dbc62012-06-29 22:22:03283 chrome::AddSelectedTabWithURL(browser(), singleton_ref_url1,
284 content::PAGE_TRANSITION_LINK);
[email protected]578c6962011-08-24 22:06:40285
286 // We should have one browser with 2 tabs, 2nd selected.
[email protected]0665ebe2013-02-13 09:53:19287 EXPECT_EQ(1u, chrome::GetTotalBrowserCount());
[email protected]ee496952013-01-10 23:17:33288 EXPECT_EQ(2, browser()->tab_strip_model()->count());
289 EXPECT_EQ(1, browser()->tab_strip_model()->active_index());
[email protected]578c6962011-08-24 22:06:40290
291 // Navigate to singleton_url2.
[email protected]78e2edc2012-07-01 23:32:28292 chrome::NavigateParams p(MakeNavigateParams());
[email protected]578c6962011-08-24 22:06:40293 p.disposition = SINGLETON_TAB;
294 p.url = singleton_ref_url2;
[email protected]78e2edc2012-07-01 23:32:28295 chrome::Navigate(&p);
[email protected]578c6962011-08-24 22:06:40296
297 // We should now have 2 tabs, the 2nd one selected.
298 EXPECT_EQ(browser(), p.browser);
[email protected]ee496952013-01-10 23:17:33299 EXPECT_EQ(2, browser()->tab_strip_model()->count());
300 EXPECT_EQ(1, browser()->tab_strip_model()->active_index());
[email protected]578c6962011-08-24 22:06:40301
302 // Navigate to singleton_url2, but with respect ref set.
303 p = MakeNavigateParams();
304 p.disposition = SINGLETON_TAB;
305 p.url = singleton_ref_url2;
[email protected]78e2edc2012-07-01 23:32:28306 p.ref_behavior = chrome::NavigateParams::RESPECT_REF;
307 chrome::Navigate(&p);
[email protected]578c6962011-08-24 22:06:40308
309 // We should now have 3 tabs, the 3th one selected.
310 EXPECT_EQ(browser(), p.browser);
[email protected]ee496952013-01-10 23:17:33311 EXPECT_EQ(3, browser()->tab_strip_model()->count());
312 EXPECT_EQ(2, browser()->tab_strip_model()->active_index());
[email protected]578c6962011-08-24 22:06:40313
314 // Navigate to singleton_url3.
315 p = MakeNavigateParams();
316 p.disposition = SINGLETON_TAB;
317 p.url = singleton_ref_url3;
[email protected]78e2edc2012-07-01 23:32:28318 p.ref_behavior = chrome::NavigateParams::RESPECT_REF;
319 chrome::Navigate(&p);
[email protected]578c6962011-08-24 22:06:40320
321 // We should now have 4 tabs, the 4th one selected.
322 EXPECT_EQ(browser(), p.browser);
[email protected]ee496952013-01-10 23:17:33323 EXPECT_EQ(4, browser()->tab_strip_model()->count());
324 EXPECT_EQ(3, browser()->tab_strip_model()->active_index());
[email protected]578c6962011-08-24 22:06:40325}
326
327IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
[email protected]19d9f3a2010-10-14 21:49:36328 Disposition_SingletonTabNoneExisting) {
[email protected]19d9f3a2010-10-14 21:49:36329 GURL singleton_url1("http://maps.google.com/");
330
[email protected]bd817c22011-02-09 08:16:46331 // We should have one browser with 1 tab.
[email protected]0665ebe2013-02-13 09:53:19332 EXPECT_EQ(1u, chrome::GetTotalBrowserCount());
[email protected]ee496952013-01-10 23:17:33333 EXPECT_EQ(0, browser()->tab_strip_model()->active_index());
[email protected]19d9f3a2010-10-14 21:49:36334
335 // Navigate to singleton_url1.
[email protected]78e2edc2012-07-01 23:32:28336 chrome::NavigateParams p(MakeNavigateParams());
[email protected]19d9f3a2010-10-14 21:49:36337 p.disposition = SINGLETON_TAB;
338 p.url = singleton_url1;
[email protected]78e2edc2012-07-01 23:32:28339 chrome::Navigate(&p);
[email protected]19d9f3a2010-10-14 21:49:36340
341 // We should now have 2 tabs, the 2nd one selected.
342 EXPECT_EQ(browser(), p.browser);
[email protected]ee496952013-01-10 23:17:33343 EXPECT_EQ(2, browser()->tab_strip_model()->count());
344 EXPECT_EQ(1, browser()->tab_strip_model()->active_index());
[email protected]a1feae52010-10-11 22:14:45345}
346
347// This test verifies that when a navigation results in a foreground tab, the
348// tab count of the Browser increases and the selected tab shifts to the new
349// foreground tab.
350IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_NewForegroundTab) {
[email protected]ee496952013-01-10 23:17:33351 WebContents* old_contents =
352 browser()->tab_strip_model()->GetActiveWebContents();
[email protected]78e2edc2012-07-01 23:32:28353 chrome::NavigateParams p(MakeNavigateParams());
[email protected]a1feae52010-10-11 22:14:45354 p.disposition = NEW_FOREGROUND_TAB;
[email protected]78e2edc2012-07-01 23:32:28355 chrome::Navigate(&p);
[email protected]ee496952013-01-10 23:17:33356 EXPECT_NE(old_contents,
357 browser()->tab_strip_model()->GetActiveWebContents());
[email protected]e232c992012-12-06 12:43:20358 EXPECT_EQ(browser()->tab_strip_model()->GetActiveWebContents(),
[email protected]59253a652012-11-20 00:17:26359 p.target_contents);
[email protected]ee496952013-01-10 23:17:33360 EXPECT_EQ(2, browser()->tab_strip_model()->count());
[email protected]a1feae52010-10-11 22:14:45361}
362
363// This test verifies that when a navigation results in a background tab, the
364// tab count of the Browser increases but the selected tab remains the same.
365IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_NewBackgroundTab) {
[email protected]ee496952013-01-10 23:17:33366 WebContents* old_contents =
367 browser()->tab_strip_model()->GetActiveWebContents();
[email protected]78e2edc2012-07-01 23:32:28368 chrome::NavigateParams p(MakeNavigateParams());
[email protected]a1feae52010-10-11 22:14:45369 p.disposition = NEW_BACKGROUND_TAB;
[email protected]78e2edc2012-07-01 23:32:28370 chrome::Navigate(&p);
[email protected]ee496952013-01-10 23:17:33371 WebContents* new_contents =
372 browser()->tab_strip_model()->GetActiveWebContents();
[email protected]a1feae52010-10-11 22:14:45373 // The selected tab should have remained unchanged, since the new tab was
374 // opened in the background.
375 EXPECT_EQ(old_contents, new_contents);
[email protected]ee496952013-01-10 23:17:33376 EXPECT_EQ(2, browser()->tab_strip_model()->count());
[email protected]a1feae52010-10-11 22:14:45377}
378
379// This test verifies that when a navigation requiring a new foreground tab
380// occurs in a Browser that cannot host multiple tabs, the new foreground tab
381// is created in an existing compatible Browser.
382IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
383 Disposition_IncompatibleWindow_Existing) {
384 // Open a foreground tab in a window that cannot open popups when there is an
385 // existing compatible window somewhere else that they can be opened within.
386 Browser* popup = CreateEmptyBrowserForType(Browser::TYPE_POPUP,
387 browser()->profile());
[email protected]78e2edc2012-07-01 23:32:28388 chrome::NavigateParams p(MakeNavigateParams(popup));
[email protected]a1feae52010-10-11 22:14:45389 p.disposition = NEW_FOREGROUND_TAB;
[email protected]78e2edc2012-07-01 23:32:28390 chrome::Navigate(&p);
[email protected]a1feae52010-10-11 22:14:45391
392 // Navigate() should have opened the tab in a different browser since the
393 // one we supplied didn't support additional tabs.
394 EXPECT_NE(popup, p.browser);
395
396 // Since browser() is an existing compatible tabbed browser, it should have
397 // opened the tab there.
398 EXPECT_EQ(browser(), p.browser);
399
400 // We should be left with 2 windows, the popup with one tab and the browser()
401 // provided by the framework with two.
[email protected]0665ebe2013-02-13 09:53:19402 EXPECT_EQ(2u, chrome::GetTotalBrowserCount());
[email protected]ee496952013-01-10 23:17:33403 EXPECT_EQ(1, popup->tab_strip_model()->count());
404 EXPECT_EQ(2, browser()->tab_strip_model()->count());
[email protected]a1feae52010-10-11 22:14:45405}
406
407// This test verifies that when a navigation requiring a new foreground tab
408// occurs in a Browser that cannot host multiple tabs and no compatible Browser
409// that can is open, a compatible Browser is created.
410IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
411 Disposition_IncompatibleWindow_NoExisting) {
412 // We want to simulate not being able to find an existing window compatible
413 // with our non-tabbed browser window so Navigate() is forced to create a
414 // new compatible window. Because browser() supplied by the in-process
415 // browser testing framework is compatible with browser()->profile(), we
416 // need a different profile, and creating a popup window with an incognito
417 // profile is a quick and dirty way of achieving this.
418 Browser* popup = CreateEmptyBrowserForType(
[email protected]b35b26b32011-05-05 20:35:14419 Browser::TYPE_POPUP,
420 browser()->profile()->GetOffTheRecordProfile());
[email protected]78e2edc2012-07-01 23:32:28421 chrome::NavigateParams p(MakeNavigateParams(popup));
[email protected]a1feae52010-10-11 22:14:45422 p.disposition = NEW_FOREGROUND_TAB;
[email protected]78e2edc2012-07-01 23:32:28423 chrome::Navigate(&p);
[email protected]a1feae52010-10-11 22:14:45424
425 // Navigate() should have opened the tab in a different browser since the
426 // one we supplied didn't support additional tabs.
427 EXPECT_NE(popup, p.browser);
428
429 // This time, browser() is _not_ compatible with popup since it is not an
430 // incognito window.
431 EXPECT_NE(browser(), p.browser);
432
433 // We should have three windows, each with one tab:
434 // 1. the browser() provided by the framework (unchanged in this test)
435 // 2. the incognito popup we created originally
436 // 3. the new incognito tabbed browser that was created by Navigate().
[email protected]0665ebe2013-02-13 09:53:19437 EXPECT_EQ(3u, chrome::GetTotalBrowserCount());
[email protected]ee496952013-01-10 23:17:33438 EXPECT_EQ(1, browser()->tab_strip_model()->count());
439 EXPECT_EQ(1, popup->tab_strip_model()->count());
440 EXPECT_EQ(1, p.browser->tab_strip_model()->count());
[email protected]b35b26b32011-05-05 20:35:14441 EXPECT_TRUE(p.browser->is_type_tabbed());
[email protected]a1feae52010-10-11 22:14:45442}
443
444// This test verifies that navigating with WindowOpenDisposition = NEW_POPUP
445// from a normal Browser results in a new Browser with TYPE_POPUP.
446IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_NewPopup) {
[email protected]78e2edc2012-07-01 23:32:28447 chrome::NavigateParams p(MakeNavigateParams());
[email protected]a1feae52010-10-11 22:14:45448 p.disposition = NEW_POPUP;
[email protected]588300d2011-04-28 21:06:35449 p.window_bounds = gfx::Rect(0, 0, 200, 200);
[email protected]7d329992011-04-15 18:20:02450 // Wait for new popup to to load and gain focus.
[email protected]ddddfda2011-07-14 23:19:39451 ui_test_utils::NavigateToURL(&p);
[email protected]a1feae52010-10-11 22:14:45452
[email protected]7d329992011-04-15 18:20:02453 // Navigate() should have opened a new, focused popup window.
[email protected]a1feae52010-10-11 22:14:45454 EXPECT_NE(browser(), p.browser);
[email protected]50592b52013-05-02 22:26:25455#if 0
456 // TODO(stevenjb): Enable this test. See: crbug.com/79493
457 EXPECT_TRUE(p.browser->window()->IsActive());
458#endif
[email protected]b35b26b32011-05-05 20:35:14459 EXPECT_TRUE(p.browser->is_type_popup());
460 EXPECT_FALSE(p.browser->is_app());
[email protected]a1feae52010-10-11 22:14:45461
462 // We should have two windows, the browser() provided by the framework and the
463 // new popup window.
[email protected]0665ebe2013-02-13 09:53:19464 EXPECT_EQ(2u, chrome::GetTotalBrowserCount());
[email protected]ee496952013-01-10 23:17:33465 EXPECT_EQ(1, browser()->tab_strip_model()->count());
466 EXPECT_EQ(1, p.browser->tab_strip_model()->count());
[email protected]a1feae52010-10-11 22:14:45467}
468
469// This test verifies that navigating with WindowOpenDisposition = NEW_POPUP
[email protected]f112b0f2011-05-26 01:53:52470// from a normal Browser results in a new Browser with is_app() true.
471IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_NewPopup_ExtensionId) {
[email protected]78e2edc2012-07-01 23:32:28472 chrome::NavigateParams p(MakeNavigateParams());
[email protected]f112b0f2011-05-26 01:53:52473 p.disposition = NEW_POPUP;
474 p.extension_app_id = "extensionappid";
475 p.window_bounds = gfx::Rect(0, 0, 200, 200);
[email protected]f112b0f2011-05-26 01:53:52476 // Wait for new popup to to load and gain focus.
[email protected]ddddfda2011-07-14 23:19:39477 ui_test_utils::NavigateToURL(&p);
[email protected]f112b0f2011-05-26 01:53:52478
479 // Navigate() should have opened a new, focused popup window.
480 EXPECT_NE(browser(), p.browser);
481 EXPECT_TRUE(p.browser->is_type_popup());
482 EXPECT_TRUE(p.browser->is_app());
483
484 // We should have two windows, the browser() provided by the framework and the
485 // new popup window.
[email protected]0665ebe2013-02-13 09:53:19486 EXPECT_EQ(2u, chrome::GetTotalBrowserCount());
[email protected]ee496952013-01-10 23:17:33487 EXPECT_EQ(1, browser()->tab_strip_model()->count());
488 EXPECT_EQ(1, p.browser->tab_strip_model()->count());
[email protected]f112b0f2011-05-26 01:53:52489}
490
491// This test verifies that navigating with WindowOpenDisposition = NEW_POPUP
[email protected]300d1e52011-01-19 23:57:57492// from a normal popup results in a new Browser with TYPE_POPUP.
493IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_NewPopupFromPopup) {
494 // Open a popup.
[email protected]78e2edc2012-07-01 23:32:28495 chrome::NavigateParams p1(MakeNavigateParams());
[email protected]300d1e52011-01-19 23:57:57496 p1.disposition = NEW_POPUP;
[email protected]588300d2011-04-28 21:06:35497 p1.window_bounds = gfx::Rect(0, 0, 200, 200);
[email protected]78e2edc2012-07-01 23:32:28498 chrome::Navigate(&p1);
[email protected]300d1e52011-01-19 23:57:57499 // Open another popup.
[email protected]78e2edc2012-07-01 23:32:28500 chrome::NavigateParams p2(MakeNavigateParams(p1.browser));
[email protected]300d1e52011-01-19 23:57:57501 p2.disposition = NEW_POPUP;
[email protected]588300d2011-04-28 21:06:35502 p2.window_bounds = gfx::Rect(0, 0, 200, 200);
[email protected]78e2edc2012-07-01 23:32:28503 chrome::Navigate(&p2);
[email protected]300d1e52011-01-19 23:57:57504
505 // Navigate() should have opened a new normal popup window.
506 EXPECT_NE(p1.browser, p2.browser);
[email protected]b35b26b32011-05-05 20:35:14507 EXPECT_TRUE(p2.browser->is_type_popup());
508 EXPECT_FALSE(p2.browser->is_app());
[email protected]300d1e52011-01-19 23:57:57509
510 // We should have three windows, the browser() provided by the framework,
511 // the first popup window, and the second popup window.
[email protected]0665ebe2013-02-13 09:53:19512 EXPECT_EQ(3u, chrome::GetTotalBrowserCount());
[email protected]ee496952013-01-10 23:17:33513 EXPECT_EQ(1, browser()->tab_strip_model()->count());
514 EXPECT_EQ(1, p1.browser->tab_strip_model()->count());
515 EXPECT_EQ(1, p2.browser->tab_strip_model()->count());
[email protected]300d1e52011-01-19 23:57:57516}
517
518// This test verifies that navigating with WindowOpenDisposition = NEW_POPUP
[email protected]d2202e22014-04-14 20:20:53519// from an app frame results in a new Browser with TYPE_POPUP.
[email protected]a1feae52010-10-11 22:14:45520IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
521 Disposition_NewPopupFromAppWindow) {
[email protected]d2202e22014-04-14 20:20:53522 Browser* app_browser = CreateEmptyBrowserForApp(browser()->profile());
[email protected]78e2edc2012-07-01 23:32:28523 chrome::NavigateParams p(MakeNavigateParams(app_browser));
[email protected]a1feae52010-10-11 22:14:45524 p.disposition = NEW_POPUP;
[email protected]588300d2011-04-28 21:06:35525 p.window_bounds = gfx::Rect(0, 0, 200, 200);
[email protected]78e2edc2012-07-01 23:32:28526 chrome::Navigate(&p);
[email protected]a1feae52010-10-11 22:14:45527
528 // Navigate() should have opened a new popup app window.
529 EXPECT_NE(app_browser, p.browser);
530 EXPECT_NE(browser(), p.browser);
[email protected]b35b26b32011-05-05 20:35:14531 EXPECT_TRUE(p.browser->is_type_popup());
532 EXPECT_TRUE(p.browser->is_app());
[email protected]a1feae52010-10-11 22:14:45533
534 // We should now have three windows, the app window, the app popup it created,
535 // and the original browser() provided by the framework.
[email protected]0665ebe2013-02-13 09:53:19536 EXPECT_EQ(3u, chrome::GetTotalBrowserCount());
[email protected]ee496952013-01-10 23:17:33537 EXPECT_EQ(1, browser()->tab_strip_model()->count());
538 EXPECT_EQ(1, app_browser->tab_strip_model()->count());
539 EXPECT_EQ(1, p.browser->tab_strip_model()->count());
[email protected]a1feae52010-10-11 22:14:45540}
541
542// This test verifies that navigating with WindowOpenDisposition = NEW_POPUP
[email protected]d2202e22014-04-14 20:20:53543// from an app popup results in a new Browser also of TYPE_POPUP.
[email protected]300d1e52011-01-19 23:57:57544IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
545 Disposition_NewPopupFromAppPopup) {
[email protected]d2202e22014-04-14 20:20:53546 Browser* app_browser = CreateEmptyBrowserForApp(browser()->profile());
[email protected]300d1e52011-01-19 23:57:57547 // Open an app popup.
[email protected]78e2edc2012-07-01 23:32:28548 chrome::NavigateParams p1(MakeNavigateParams(app_browser));
[email protected]300d1e52011-01-19 23:57:57549 p1.disposition = NEW_POPUP;
[email protected]588300d2011-04-28 21:06:35550 p1.window_bounds = gfx::Rect(0, 0, 200, 200);
[email protected]78e2edc2012-07-01 23:32:28551 chrome::Navigate(&p1);
[email protected]300d1e52011-01-19 23:57:57552 // Now open another app popup.
[email protected]78e2edc2012-07-01 23:32:28553 chrome::NavigateParams p2(MakeNavigateParams(p1.browser));
[email protected]300d1e52011-01-19 23:57:57554 p2.disposition = NEW_POPUP;
[email protected]588300d2011-04-28 21:06:35555 p2.window_bounds = gfx::Rect(0, 0, 200, 200);
[email protected]78e2edc2012-07-01 23:32:28556 chrome::Navigate(&p2);
[email protected]300d1e52011-01-19 23:57:57557
558 // Navigate() should have opened a new popup app window.
559 EXPECT_NE(browser(), p1.browser);
560 EXPECT_NE(p1.browser, p2.browser);
[email protected]b35b26b32011-05-05 20:35:14561 EXPECT_TRUE(p2.browser->is_type_popup());
562 EXPECT_TRUE(p2.browser->is_app());
[email protected]300d1e52011-01-19 23:57:57563
564 // We should now have four windows, the app window, the first app popup,
565 // the second app popup, and the original browser() provided by the framework.
[email protected]0665ebe2013-02-13 09:53:19566 EXPECT_EQ(4u, chrome::GetTotalBrowserCount());
[email protected]ee496952013-01-10 23:17:33567 EXPECT_EQ(1, browser()->tab_strip_model()->count());
568 EXPECT_EQ(1, app_browser->tab_strip_model()->count());
569 EXPECT_EQ(1, p1.browser->tab_strip_model()->count());
570 EXPECT_EQ(1, p2.browser->tab_strip_model()->count());
[email protected]300d1e52011-01-19 23:57:57571}
572
573// This test verifies that navigating with WindowOpenDisposition = NEW_POPUP
[email protected]a1feae52010-10-11 22:14:45574// from an extension app tab results in a new Browser with TYPE_APP_POPUP.
575IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
576 Disposition_NewPopupFromExtensionApp) {
577 // TODO(beng): TBD.
578}
579
[email protected]7d329992011-04-15 18:20:02580// This test verifies that navigating with window_action = SHOW_WINDOW_INACTIVE
581// does not focus a new new popup window.
582IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_NewPopupUnfocused) {
[email protected]78e2edc2012-07-01 23:32:28583 chrome::NavigateParams p(MakeNavigateParams());
[email protected]7d329992011-04-15 18:20:02584 p.disposition = NEW_POPUP;
[email protected]588300d2011-04-28 21:06:35585 p.window_bounds = gfx::Rect(0, 0, 200, 200);
[email protected]78e2edc2012-07-01 23:32:28586 p.window_action = chrome::NavigateParams::SHOW_WINDOW_INACTIVE;
[email protected]7d329992011-04-15 18:20:02587 // Wait for new popup to load (and gain focus if the test fails).
[email protected]ddddfda2011-07-14 23:19:39588 ui_test_utils::NavigateToURL(&p);
[email protected]7d329992011-04-15 18:20:02589
590 // Navigate() should have opened a new, unfocused, popup window.
591 EXPECT_NE(browser(), p.browser);
592 EXPECT_EQ(Browser::TYPE_POPUP, p.browser->type());
[email protected]9db263a2011-04-15 20:53:47593#if 0
594// TODO(stevenjb): Enable this test. See: crbug.com/79493
[email protected]7d329992011-04-15 18:20:02595 EXPECT_FALSE(p.browser->window()->IsActive());
[email protected]7d329992011-04-15 18:20:02596#endif
[email protected]9db263a2011-04-15 20:53:47597}
[email protected]7d329992011-04-15 18:20:02598
[email protected]d2202e22014-04-14 20:20:53599// This test verifies that navigating with WindowOpenDisposition = NEW_POPUP
600// and trusted_source = true results in a new Browser where is_trusted_source()
601// is true.
602IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_NewPopupTrusted) {
603 chrome::NavigateParams p(MakeNavigateParams());
604 p.disposition = NEW_POPUP;
605 p.trusted_source = true;
606 p.window_bounds = gfx::Rect(0, 0, 200, 200);
607 // Wait for new popup to to load and gain focus.
608 ui_test_utils::NavigateToURL(&p);
609
610 // Navigate() should have opened a new popup window of TYPE_TRUSTED_POPUP.
611 EXPECT_NE(browser(), p.browser);
612 EXPECT_TRUE(p.browser->is_type_popup());
613 EXPECT_TRUE(p.browser->is_trusted_source());
614}
615
616
[email protected]a1feae52010-10-11 22:14:45617// This test verifies that navigating with WindowOpenDisposition = NEW_WINDOW
618// always opens a new window.
619IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_NewWindow) {
[email protected]78e2edc2012-07-01 23:32:28620 chrome::NavigateParams p(MakeNavigateParams());
[email protected]a1feae52010-10-11 22:14:45621 p.disposition = NEW_WINDOW;
[email protected]78e2edc2012-07-01 23:32:28622 chrome::Navigate(&p);
[email protected]a1feae52010-10-11 22:14:45623
624 // Navigate() should have opened a new toplevel window.
625 EXPECT_NE(browser(), p.browser);
[email protected]b35b26b32011-05-05 20:35:14626 EXPECT_TRUE(p.browser->is_type_tabbed());
[email protected]a1feae52010-10-11 22:14:45627
628 // We should now have two windows, the browser() provided by the framework and
629 // the new normal window.
[email protected]0665ebe2013-02-13 09:53:19630 EXPECT_EQ(2u, chrome::GetTotalBrowserCount());
[email protected]ee496952013-01-10 23:17:33631 EXPECT_EQ(1, browser()->tab_strip_model()->count());
632 EXPECT_EQ(1, p.browser->tab_strip_model()->count());
[email protected]a1feae52010-10-11 22:14:45633}
634
635// This test verifies that navigating with WindowOpenDisposition = INCOGNITO
636// opens a new incognito window if no existing incognito window is present.
637IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_Incognito) {
[email protected]78e2edc2012-07-01 23:32:28638 chrome::NavigateParams p(MakeNavigateParams());
[email protected]a1feae52010-10-11 22:14:45639 p.disposition = OFF_THE_RECORD;
[email protected]78e2edc2012-07-01 23:32:28640 chrome::Navigate(&p);
[email protected]a1feae52010-10-11 22:14:45641
642 // Navigate() should have opened a new toplevel incognito window.
643 EXPECT_NE(browser(), p.browser);
644 EXPECT_EQ(browser()->profile()->GetOffTheRecordProfile(),
645 p.browser->profile());
646
[email protected]d7ff3592010-11-30 21:50:46647 // |source_contents| should be set to NULL because the profile for the new
648 // page is different from the originating page.
649 EXPECT_EQ(NULL, p.source_contents);
650
[email protected]a1feae52010-10-11 22:14:45651 // We should now have two windows, the browser() provided by the framework and
652 // the new incognito window.
[email protected]0665ebe2013-02-13 09:53:19653 EXPECT_EQ(2u, chrome::GetTotalBrowserCount());
[email protected]ee496952013-01-10 23:17:33654 EXPECT_EQ(1, browser()->tab_strip_model()->count());
655 EXPECT_EQ(1, p.browser->tab_strip_model()->count());
[email protected]a1feae52010-10-11 22:14:45656}
657
658// This test verifies that navigating with WindowOpenDisposition = INCOGNITO
659// reuses an existing incognito window when possible.
660IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_IncognitoRefocus) {
661 Browser* incognito_browser =
[email protected]b35b26b32011-05-05 20:35:14662 CreateEmptyBrowserForType(Browser::TYPE_TABBED,
[email protected]a1feae52010-10-11 22:14:45663 browser()->profile()->GetOffTheRecordProfile());
[email protected]78e2edc2012-07-01 23:32:28664 chrome::NavigateParams p(MakeNavigateParams());
[email protected]a1feae52010-10-11 22:14:45665 p.disposition = OFF_THE_RECORD;
[email protected]78e2edc2012-07-01 23:32:28666 chrome::Navigate(&p);
[email protected]a1feae52010-10-11 22:14:45667
668 // Navigate() should have opened a new tab in the existing incognito window.
669 EXPECT_NE(browser(), p.browser);
670 EXPECT_EQ(p.browser, incognito_browser);
671
672 // We should now have two windows, the browser() provided by the framework and
673 // the incognito window we opened earlier.
[email protected]0665ebe2013-02-13 09:53:19674 EXPECT_EQ(2u, chrome::GetTotalBrowserCount());
[email protected]ee496952013-01-10 23:17:33675 EXPECT_EQ(1, browser()->tab_strip_model()->count());
676 EXPECT_EQ(2, incognito_browser->tab_strip_model()->count());
[email protected]a1feae52010-10-11 22:14:45677}
678
679// This test verifies that no navigation action occurs when
680// WindowOpenDisposition = SUPPRESS_OPEN.
681IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_SuppressOpen) {
682 RunSuppressTest(SUPPRESS_OPEN);
683}
684
685// This test verifies that no navigation action occurs when
686// WindowOpenDisposition = SAVE_TO_DISK.
687IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_SaveToDisk) {
688 RunSuppressTest(SAVE_TO_DISK);
689}
690
691// This test verifies that no navigation action occurs when
692// WindowOpenDisposition = IGNORE_ACTION.
693IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_IgnoreAction) {
694 RunSuppressTest(IGNORE_ACTION);
695}
696
[email protected]e232c992012-12-06 12:43:20697// This tests adding a foreground tab with a predefined WebContents.
[email protected]a1feae52010-10-11 22:14:45698IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, TargetContents_ForegroundTab) {
[email protected]78e2edc2012-07-01 23:32:28699 chrome::NavigateParams p(MakeNavigateParams());
[email protected]a1feae52010-10-11 22:14:45700 p.disposition = NEW_FOREGROUND_TAB;
[email protected]e232c992012-12-06 12:43:20701 p.target_contents = CreateWebContents();
[email protected]78e2edc2012-07-01 23:32:28702 chrome::Navigate(&p);
[email protected]a1feae52010-10-11 22:14:45703
704 // Navigate() should have opened the contents in a new foreground in the
705 // current Browser.
706 EXPECT_EQ(browser(), p.browser);
[email protected]e232c992012-12-06 12:43:20707 EXPECT_EQ(browser()->tab_strip_model()->GetActiveWebContents(),
[email protected]59253a652012-11-20 00:17:26708 p.target_contents);
[email protected]a1feae52010-10-11 22:14:45709
710 // We should have one window, with two tabs.
[email protected]0665ebe2013-02-13 09:53:19711 EXPECT_EQ(1u, chrome::GetTotalBrowserCount());
[email protected]ee496952013-01-10 23:17:33712 EXPECT_EQ(2, browser()->tab_strip_model()->count());
[email protected]a1feae52010-10-11 22:14:45713}
714
715#if defined(OS_WIN)
[email protected]e232c992012-12-06 12:43:20716// This tests adding a popup with a predefined WebContents.
[email protected]76edb672011-03-04 21:48:39717IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, DISABLED_TargetContents_Popup) {
[email protected]78e2edc2012-07-01 23:32:28718 chrome::NavigateParams p(MakeNavigateParams());
[email protected]a1feae52010-10-11 22:14:45719 p.disposition = NEW_POPUP;
[email protected]e232c992012-12-06 12:43:20720 p.target_contents = CreateWebContents();
[email protected]a1feae52010-10-11 22:14:45721 p.window_bounds = gfx::Rect(10, 10, 500, 500);
[email protected]78e2edc2012-07-01 23:32:28722 chrome::Navigate(&p);
[email protected]a1feae52010-10-11 22:14:45723
724 // Navigate() should have opened a new popup window.
725 EXPECT_NE(browser(), p.browser);
[email protected]b35b26b32011-05-05 20:35:14726 EXPECT_TRUE(p.browser->is_type_popup());
727 EXPECT_FALSE(p.browser->is_app());
[email protected]a1feae52010-10-11 22:14:45728
729 // The web platform is weird. The window bounds specified in
730 // |p.window_bounds| are used as follows:
731 // - the origin is used to position the window
[email protected]e232c992012-12-06 12:43:20732 // - the size is used to size the WebContents of the window.
[email protected]a1feae52010-10-11 22:14:45733 // As such the position of the resulting window will always match
734 // p.window_bounds.origin(), but its size will not. We need to match
735 // the size against the selected tab's view's container size.
736 // Only Windows positions the window according to |p.window_bounds.origin()| -
737 // on Mac the window is offset from the opener and on Linux it always opens
738 // at 0,0.
739 EXPECT_EQ(p.window_bounds.origin(),
740 p.browser->window()->GetRestoredBounds().origin());
741 // All platforms should respect size however provided width > 400 (Mac has a
742 // minimum window width of 400).
743 EXPECT_EQ(p.window_bounds.size(),
[email protected]fc2b46b2014-05-03 16:33:45744 p.target_contents->GetContainerBounds().size());
[email protected]a1feae52010-10-11 22:14:45745
746 // We should have two windows, the new popup and the browser() provided by the
747 // framework.
[email protected]0665ebe2013-02-13 09:53:19748 EXPECT_EQ(2u, chrome::GetTotalBrowserCount());
[email protected]ee496952013-01-10 23:17:33749 EXPECT_EQ(1, browser()->tab_strip_model()->count());
750 EXPECT_EQ(1, p.browser->tab_strip_model()->count());
[email protected]a1feae52010-10-11 22:14:45751}
752#endif
753
754// This tests adding a tab at a specific index.
755IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Tabstrip_InsertAtIndex) {
756 // This is not meant to be a comprehensive test of whether or not the tab
757 // implementation of the browser observes the insertion index. That is
758 // covered by the unit tests for TabStripModel. This merely verifies that
759 // insertion index preference is reflected in common cases.
[email protected]78e2edc2012-07-01 23:32:28760 chrome::NavigateParams p(MakeNavigateParams());
[email protected]a1feae52010-10-11 22:14:45761 p.disposition = NEW_FOREGROUND_TAB;
762 p.tabstrip_index = 0;
763 p.tabstrip_add_types = TabStripModel::ADD_FORCE_INDEX;
[email protected]78e2edc2012-07-01 23:32:28764 chrome::Navigate(&p);
[email protected]a1feae52010-10-11 22:14:45765
766 // Navigate() should have inserted a new tab at slot 0 in the tabstrip.
767 EXPECT_EQ(browser(), p.browser);
[email protected]e232c992012-12-06 12:43:20768 EXPECT_EQ(0, browser()->tab_strip_model()->GetIndexOfWebContents(
769 static_cast<const WebContents*>(p.target_contents)));
[email protected]a1feae52010-10-11 22:14:45770
771 // We should have one window - the browser() provided by the framework.
[email protected]0665ebe2013-02-13 09:53:19772 EXPECT_EQ(1u, chrome::GetTotalBrowserCount());
[email protected]ee496952013-01-10 23:17:33773 EXPECT_EQ(2, browser()->tab_strip_model()->count());
[email protected]a1feae52010-10-11 22:14:45774}
775
[email protected]bb89e7482010-11-17 18:27:04776// This test verifies that constructing params with disposition = SINGLETON_TAB
[email protected]fee320542011-03-02 01:30:49777// and IGNORE_AND_NAVIGATE opens a new tab navigated to the specified URL if
[email protected]67ed83e2011-01-07 22:54:00778// no previous tab with that URL (minus the path) exists.
[email protected]bb89e7482010-11-17 18:27:04779IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
780 Disposition_SingletonTabNew_IgnorePath) {
[email protected]52877dbc62012-06-29 22:22:03781 chrome::AddSelectedTabWithURL(browser(), GetGoogleURL(),
782 content::PAGE_TRANSITION_LINK);
[email protected]bb89e7482010-11-17 18:27:04783
784 // We should have one browser with 2 tabs, the 2nd selected.
[email protected]0665ebe2013-02-13 09:53:19785 EXPECT_EQ(1u, chrome::GetTotalBrowserCount());
[email protected]ee496952013-01-10 23:17:33786 EXPECT_EQ(2, browser()->tab_strip_model()->count());
787 EXPECT_EQ(1, browser()->tab_strip_model()->active_index());
[email protected]bb89e7482010-11-17 18:27:04788
789 // Navigate to a new singleton tab with a sub-page.
[email protected]78e2edc2012-07-01 23:32:28790 chrome::NavigateParams p(MakeNavigateParams());
[email protected]bb89e7482010-11-17 18:27:04791 p.disposition = SINGLETON_TAB;
[email protected]a048ad22012-03-23 04:26:56792 p.url = GetContentSettingsURL();
[email protected]50592b52013-05-02 22:26:25793 p.window_action = chrome::NavigateParams::SHOW_WINDOW;
[email protected]78e2edc2012-07-01 23:32:28794 p.path_behavior = chrome::NavigateParams::IGNORE_AND_NAVIGATE;
795 chrome::Navigate(&p);
[email protected]bb89e7482010-11-17 18:27:04796
797 // The last tab should now be selected and navigated to the sub-page of the
[email protected]50592b52013-05-02 22:26:25798 // URL.
[email protected]bb89e7482010-11-17 18:27:04799 EXPECT_EQ(browser(), p.browser);
[email protected]ee496952013-01-10 23:17:33800 EXPECT_EQ(3, browser()->tab_strip_model()->count());
801 EXPECT_EQ(2, browser()->tab_strip_model()->active_index());
[email protected]a048ad22012-03-23 04:26:56802 EXPECT_EQ(GetContentSettingsURL(),
[email protected]ee496952013-01-10 23:17:33803 ShortenUberURL(browser()->tab_strip_model()->
804 GetActiveWebContents()->GetURL()));
[email protected]bb89e7482010-11-17 18:27:04805}
806
807// This test verifies that constructing params with disposition = SINGLETON_TAB
[email protected]fee320542011-03-02 01:30:49808// and IGNORE_AND_NAVIGATE opens an existing tab with the matching URL (minus
[email protected]bb89e7482010-11-17 18:27:04809// the path) which is navigated to the specified URL.
810IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
811 Disposition_SingletonTabExisting_IgnorePath) {
[email protected]ddddfda2011-07-14 23:19:39812 GURL singleton_url1(GetSettingsURL());
[email protected]52877dbc62012-06-29 22:22:03813 chrome::AddSelectedTabWithURL(browser(), singleton_url1,
814 content::PAGE_TRANSITION_LINK);
815 chrome::AddSelectedTabWithURL(browser(), GetGoogleURL(),
816 content::PAGE_TRANSITION_LINK);
[email protected]bb89e7482010-11-17 18:27:04817
818 // We should have one browser with 3 tabs, the 3rd selected.
[email protected]0665ebe2013-02-13 09:53:19819 EXPECT_EQ(1u, chrome::GetTotalBrowserCount());
[email protected]ee496952013-01-10 23:17:33820 EXPECT_EQ(3, browser()->tab_strip_model()->count());
821 EXPECT_EQ(2, browser()->tab_strip_model()->active_index());
[email protected]bb89e7482010-11-17 18:27:04822
823 // Navigate to singleton_url1.
[email protected]78e2edc2012-07-01 23:32:28824 chrome::NavigateParams p(MakeNavigateParams());
[email protected]bb89e7482010-11-17 18:27:04825 p.disposition = SINGLETON_TAB;
[email protected]a048ad22012-03-23 04:26:56826 p.url = GetContentSettingsURL();
[email protected]50592b52013-05-02 22:26:25827 p.window_action = chrome::NavigateParams::SHOW_WINDOW;
[email protected]78e2edc2012-07-01 23:32:28828 p.path_behavior = chrome::NavigateParams::IGNORE_AND_NAVIGATE;
829 chrome::Navigate(&p);
[email protected]bb89e7482010-11-17 18:27:04830
831 // The middle tab should now be selected and navigated to the sub-page of the
832 // URL.
833 EXPECT_EQ(browser(), p.browser);
[email protected]ee496952013-01-10 23:17:33834 EXPECT_EQ(3, browser()->tab_strip_model()->count());
835 EXPECT_EQ(1, browser()->tab_strip_model()->active_index());
[email protected]a048ad22012-03-23 04:26:56836 EXPECT_EQ(GetContentSettingsURL(),
[email protected]ee496952013-01-10 23:17:33837 ShortenUberURL(browser()->tab_strip_model()->
838 GetActiveWebContents()->GetURL()));
[email protected]bb89e7482010-11-17 18:27:04839}
840
841// This test verifies that constructing params with disposition = SINGLETON_TAB
[email protected]fee320542011-03-02 01:30:49842// and IGNORE_AND_NAVIGATE opens an existing tab with the matching URL (minus
[email protected]bb89e7482010-11-17 18:27:04843// the path) which is navigated to the specified URL.
844IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
845 Disposition_SingletonTabExistingSubPath_IgnorePath) {
[email protected]a048ad22012-03-23 04:26:56846 GURL singleton_url1(GetContentSettingsURL());
[email protected]52877dbc62012-06-29 22:22:03847 chrome::AddSelectedTabWithURL(browser(), singleton_url1,
848 content::PAGE_TRANSITION_LINK);
849 chrome::AddSelectedTabWithURL(browser(), GetGoogleURL(),
850 content::PAGE_TRANSITION_LINK);
[email protected]bb89e7482010-11-17 18:27:04851
852 // We should have one browser with 3 tabs, the 3rd selected.
[email protected]0665ebe2013-02-13 09:53:19853 EXPECT_EQ(1u, chrome::GetTotalBrowserCount());
[email protected]ee496952013-01-10 23:17:33854 EXPECT_EQ(3, browser()->tab_strip_model()->count());
855 EXPECT_EQ(2, browser()->tab_strip_model()->active_index());
[email protected]bb89e7482010-11-17 18:27:04856
857 // Navigate to singleton_url1.
[email protected]78e2edc2012-07-01 23:32:28858 chrome::NavigateParams p(MakeNavigateParams());
[email protected]bb89e7482010-11-17 18:27:04859 p.disposition = SINGLETON_TAB;
[email protected]a048ad22012-03-23 04:26:56860 p.url = GetClearBrowsingDataURL();
[email protected]50592b52013-05-02 22:26:25861 p.window_action = chrome::NavigateParams::SHOW_WINDOW;
[email protected]78e2edc2012-07-01 23:32:28862 p.path_behavior = chrome::NavigateParams::IGNORE_AND_NAVIGATE;
863 chrome::Navigate(&p);
[email protected]bb89e7482010-11-17 18:27:04864
865 // The middle tab should now be selected and navigated to the sub-page of the
866 // URL.
867 EXPECT_EQ(browser(), p.browser);
[email protected]ee496952013-01-10 23:17:33868 EXPECT_EQ(3, browser()->tab_strip_model()->count());
869 EXPECT_EQ(1, browser()->tab_strip_model()->active_index());
[email protected]a048ad22012-03-23 04:26:56870 EXPECT_EQ(GetClearBrowsingDataURL(),
[email protected]ee496952013-01-10 23:17:33871 ShortenUberURL(browser()->tab_strip_model()->
872 GetActiveWebContents()->GetURL()));
[email protected]bb89e7482010-11-17 18:27:04873}
[email protected]2dd85482010-11-06 01:56:47874
[email protected]637b3442011-01-10 23:31:48875// This test verifies that constructing params with disposition = SINGLETON_TAB
[email protected]fee320542011-03-02 01:30:49876// and IGNORE_AND_STAY_PUT opens an existing tab with the matching URL (minus
877// the path).
878IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
879 Disposition_SingletonTabExistingSubPath_IgnorePath2) {
[email protected]a048ad22012-03-23 04:26:56880 GURL singleton_url1(GetContentSettingsURL());
[email protected]52877dbc62012-06-29 22:22:03881 chrome::AddSelectedTabWithURL(browser(), singleton_url1,
882 content::PAGE_TRANSITION_LINK);
883 chrome::AddSelectedTabWithURL(browser(), GetGoogleURL(),
884 content::PAGE_TRANSITION_LINK);
[email protected]fee320542011-03-02 01:30:49885
886 // We should have one browser with 3 tabs, the 3rd selected.
[email protected]0665ebe2013-02-13 09:53:19887 EXPECT_EQ(1u, chrome::GetTotalBrowserCount());
[email protected]ee496952013-01-10 23:17:33888 EXPECT_EQ(3, browser()->tab_strip_model()->count());
889 EXPECT_EQ(2, browser()->tab_strip_model()->active_index());
[email protected]fee320542011-03-02 01:30:49890
891 // Navigate to singleton_url1.
[email protected]78e2edc2012-07-01 23:32:28892 chrome::NavigateParams p(MakeNavigateParams());
[email protected]fee320542011-03-02 01:30:49893 p.disposition = SINGLETON_TAB;
[email protected]a048ad22012-03-23 04:26:56894 p.url = GetClearBrowsingDataURL();
[email protected]50592b52013-05-02 22:26:25895 p.window_action = chrome::NavigateParams::SHOW_WINDOW;
[email protected]78e2edc2012-07-01 23:32:28896 p.path_behavior = chrome::NavigateParams::IGNORE_AND_STAY_PUT;
897 chrome::Navigate(&p);
[email protected]fee320542011-03-02 01:30:49898
899 // The middle tab should now be selected.
900 EXPECT_EQ(browser(), p.browser);
[email protected]ee496952013-01-10 23:17:33901 EXPECT_EQ(3, browser()->tab_strip_model()->count());
902 EXPECT_EQ(1, browser()->tab_strip_model()->active_index());
[email protected]fee320542011-03-02 01:30:49903 EXPECT_EQ(singleton_url1,
[email protected]ee496952013-01-10 23:17:33904 ShortenUberURL(browser()->tab_strip_model()->
905 GetActiveWebContents()->GetURL()));
[email protected]fee320542011-03-02 01:30:49906}
907
908// This test verifies that constructing params with disposition = SINGLETON_TAB
909// and IGNORE_AND_NAVIGATE will update the current tab's URL if the currently
[email protected]637b3442011-01-10 23:31:48910// selected tab is a match but has a different path.
911IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
912 Disposition_SingletonTabFocused_IgnorePath) {
[email protected]a048ad22012-03-23 04:26:56913 GURL singleton_url_current(GetContentSettingsURL());
[email protected]52877dbc62012-06-29 22:22:03914 chrome::AddSelectedTabWithURL(browser(), singleton_url_current,
915 content::PAGE_TRANSITION_LINK);
[email protected]637b3442011-01-10 23:31:48916
917 // We should have one browser with 2 tabs, the 2nd selected.
[email protected]0665ebe2013-02-13 09:53:19918 EXPECT_EQ(1u, chrome::GetTotalBrowserCount());
[email protected]ee496952013-01-10 23:17:33919 EXPECT_EQ(2, browser()->tab_strip_model()->count());
920 EXPECT_EQ(1, browser()->tab_strip_model()->active_index());
[email protected]637b3442011-01-10 23:31:48921
922 // Navigate to a different settings path.
[email protected]a048ad22012-03-23 04:26:56923 GURL singleton_url_target(GetClearBrowsingDataURL());
[email protected]78e2edc2012-07-01 23:32:28924 chrome::NavigateParams p(MakeNavigateParams());
[email protected]637b3442011-01-10 23:31:48925 p.disposition = SINGLETON_TAB;
926 p.url = singleton_url_target;
[email protected]50592b52013-05-02 22:26:25927 p.window_action = chrome::NavigateParams::SHOW_WINDOW;
[email protected]78e2edc2012-07-01 23:32:28928 p.path_behavior = chrome::NavigateParams::IGNORE_AND_NAVIGATE;
929 chrome::Navigate(&p);
[email protected]637b3442011-01-10 23:31:48930
931 // The second tab should still be selected, but navigated to the new path.
932 EXPECT_EQ(browser(), p.browser);
[email protected]ee496952013-01-10 23:17:33933 EXPECT_EQ(2, browser()->tab_strip_model()->count());
934 EXPECT_EQ(1, browser()->tab_strip_model()->active_index());
[email protected]637b3442011-01-10 23:31:48935 EXPECT_EQ(singleton_url_target,
[email protected]ee496952013-01-10 23:17:33936 ShortenUberURL(browser()->tab_strip_model()->
937 GetActiveWebContents()->GetURL()));
[email protected]637b3442011-01-10 23:31:48938}
939
[email protected]07afd7c2011-02-17 10:07:11940// This test verifies that constructing params with disposition = SINGLETON_TAB
[email protected]fee320542011-03-02 01:30:49941// and IGNORE_AND_NAVIGATE will open an existing matching tab with a different
942// query.
[email protected]07afd7c2011-02-17 10:07:11943IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
944 Disposition_SingletonTabExisting_IgnoreQuery) {
[email protected]ee496952013-01-10 23:17:33945 int initial_tab_count = browser()->tab_strip_model()->count();
[email protected]07afd7c2011-02-17 10:07:11946 GURL singleton_url_current("chrome://settings/internet");
[email protected]52877dbc62012-06-29 22:22:03947 chrome::AddSelectedTabWithURL(browser(), singleton_url_current,
948 content::PAGE_TRANSITION_LINK);
[email protected]07afd7c2011-02-17 10:07:11949
[email protected]ee496952013-01-10 23:17:33950 EXPECT_EQ(initial_tab_count + 1, browser()->tab_strip_model()->count());
951 EXPECT_EQ(initial_tab_count, browser()->tab_strip_model()->active_index());
[email protected]07afd7c2011-02-17 10:07:11952
953 // Navigate to a different settings path.
954 GURL singleton_url_target(
955 "chrome://settings/internet?"
956 "servicePath=/profile/ethernet_00aa00aa00aa&networkType=1");
[email protected]78e2edc2012-07-01 23:32:28957 chrome::NavigateParams p(MakeNavigateParams());
[email protected]07afd7c2011-02-17 10:07:11958 p.disposition = SINGLETON_TAB;
959 p.url = singleton_url_target;
[email protected]50592b52013-05-02 22:26:25960 p.window_action = chrome::NavigateParams::SHOW_WINDOW;
[email protected]78e2edc2012-07-01 23:32:28961 p.path_behavior = chrome::NavigateParams::IGNORE_AND_NAVIGATE;
962 chrome::Navigate(&p);
[email protected]07afd7c2011-02-17 10:07:11963
964 // Last tab should still be selected.
965 EXPECT_EQ(browser(), p.browser);
[email protected]ee496952013-01-10 23:17:33966 EXPECT_EQ(initial_tab_count + 1, browser()->tab_strip_model()->count());
967 EXPECT_EQ(initial_tab_count, browser()->tab_strip_model()->active_index());
[email protected]07afd7c2011-02-17 10:07:11968}
969
[email protected]bd817c22011-02-09 08:16:46970// This test verifies that the settings page isn't opened in the incognito
971// window.
[email protected]a048ad22012-03-23 04:26:56972// Disabled until fixed for uber settings: http://crbug.com/111243
[email protected]bd817c22011-02-09 08:16:46973IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
[email protected]a048ad22012-03-23 04:26:56974 DISABLED_Disposition_Settings_UseNonIncognitoWindow) {
[email protected]fc0ed302011-11-29 23:17:19975 RunUseNonIncognitoWindowTest(GetSettingsURL());
[email protected]bd817c22011-02-09 08:16:46976}
977
[email protected]429e9712013-04-30 09:35:50978// This test verifies that the view-source settings page isn't opened in the
979// incognito window.
980IN_PROC_BROWSER_TEST_F(
981 BrowserNavigatorTest,
982 Disposition_ViewSource_Settings_DoNothingIfIncognitoForced) {
[email protected]dbdda5402013-05-30 22:13:48983 std::string view_source(content::kViewSourceScheme);
[email protected]429e9712013-04-30 09:35:50984 view_source.append(":");
985 view_source.append(chrome::kChromeUISettingsURL);
986 RunDoNothingIfIncognitoIsForcedTest(GURL(view_source));
987}
988
989// This test verifies that the view-source settings page isn't opened in the
990// incognito window even if incognito mode is forced (does nothing in that
991// case).
992IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
993 Disposition_ViewSource_Settings_UseNonIncognitoWindow) {
[email protected]dbdda5402013-05-30 22:13:48994 std::string view_source(content::kViewSourceScheme);
[email protected]429e9712013-04-30 09:35:50995 view_source.append(":");
996 view_source.append(chrome::kChromeUISettingsURL);
997 RunUseNonIncognitoWindowTest(GURL(view_source));
998}
999
[email protected]82404cd2011-07-12 19:55:141000// This test verifies that the settings page isn't opened in the incognito
1001// window from a non-incognito window (bookmark open-in-incognito trigger).
[email protected]a048ad22012-03-23 04:26:561002// Disabled until fixed for uber settings: http://crbug.com/111243
[email protected]82404cd2011-07-12 19:55:141003IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
[email protected]a048ad22012-03-23 04:26:561004 DISABLED_Disposition_Settings_UseNonIncognitoWindowForBookmark) {
[email protected]78e2edc2012-07-01 23:32:281005 chrome::NavigateParams params(browser(), GetSettingsURL(),
1006 content::PAGE_TRANSITION_AUTO_BOOKMARK);
[email protected]82404cd2011-07-12 19:55:141007 params.disposition = OFF_THE_RECORD;
1008 {
[email protected]a7fe9112012-07-20 02:34:451009 content::WindowedNotificationObserver observer(
[email protected]ad50def52011-10-19 23:17:071010 content::NOTIFICATION_LOAD_STOP,
1011 content::NotificationService::AllSources());
[email protected]78e2edc2012-07-01 23:32:281012 chrome::Navigate(&params);
[email protected]82404cd2011-07-12 19:55:141013 observer.Wait();
1014 }
1015
[email protected]0665ebe2013-02-13 09:53:191016 EXPECT_EQ(1u, chrome::GetTotalBrowserCount());
[email protected]52877dbc62012-06-29 22:22:031017 EXPECT_EQ(GetSettingsURL(),
[email protected]ee496952013-01-10 23:17:331018 ShortenUberURL(browser()->tab_strip_model()->
1019 GetActiveWebContents()->GetURL()));
[email protected]82404cd2011-07-12 19:55:141020}
1021
[email protected]93ad8e1c2011-11-08 21:34:051022// Settings page is expected to always open in normal mode regardless
1023// of whether the user is trying to open it in incognito mode or not.
1024// This test verifies that if incognito mode is forced (by policy), settings
1025// page doesn't open at all.
[email protected]a048ad22012-03-23 04:26:561026// Disabled until fixed for uber settings: http://crbug.com/111243
[email protected]93ad8e1c2011-11-08 21:34:051027IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
[email protected]a048ad22012-03-23 04:26:561028 DISABLED_Disposition_Settings_DoNothingIfIncognitoIsForced) {
[email protected]fc0ed302011-11-29 23:17:191029 RunDoNothingIfIncognitoIsForcedTest(GetSettingsURL());
[email protected]93ad8e1c2011-11-08 21:34:051030}
1031
[email protected]bd817c22011-02-09 08:16:461032// This test verifies that the bookmarks page isn't opened in the incognito
1033// window.
1034IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
1035 Disposition_Bookmarks_UseNonIncognitoWindow) {
[email protected]fc0ed302011-11-29 23:17:191036 RunUseNonIncognitoWindowTest(GURL(chrome::kChromeUIBookmarksURL));
[email protected]bd817c22011-02-09 08:16:461037}
1038
[email protected]93ad8e1c2011-11-08 21:34:051039// Bookmark manager is expected to always open in normal mode regardless
1040// of whether the user is trying to open it in incognito mode or not.
1041// This test verifies that if incognito mode is forced (by policy), bookmark
1042// manager doesn't open at all.
1043IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
1044 Disposition_Bookmarks_DoNothingIfIncognitoIsForced) {
[email protected]fc0ed302011-11-29 23:17:191045 RunDoNothingIfIncognitoIsForcedTest(GURL(chrome::kChromeUIBookmarksURL));
1046}
[email protected]93ad8e1c2011-11-08 21:34:051047
[email protected]7de53c62011-05-13 06:44:161048// This test makes sure a crashed singleton tab reloads from a new navigation.
[email protected]c4c0c0a12014-07-23 17:06:021049// http://crbug.com/396371
[email protected]7de53c62011-05-13 06:44:161050IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
[email protected]c4c0c0a12014-07-23 17:06:021051 DISABLED_NavigateToCrashedSingletonTab) {
[email protected]a048ad22012-03-23 04:26:561052 GURL singleton_url(GetContentSettingsURL());
[email protected]5a1a52462012-11-15 03:35:161053 WebContents* web_contents = chrome::AddSelectedTabWithURL(
[email protected]52877dbc62012-06-29 22:22:031054 browser(), singleton_url, content::PAGE_TRANSITION_LINK);
[email protected]7de53c62011-05-13 06:44:161055
1056 // We should have one browser with 2 tabs, the 2nd selected.
[email protected]0665ebe2013-02-13 09:53:191057 EXPECT_EQ(1u, chrome::GetTotalBrowserCount());
[email protected]ee496952013-01-10 23:17:331058 EXPECT_EQ(2, browser()->tab_strip_model()->count());
1059 EXPECT_EQ(1, browser()->tab_strip_model()->active_index());
[email protected]7de53c62011-05-13 06:44:161060
1061 // Kill the singleton tab.
[email protected]83ff91c2012-01-05 20:54:131062 web_contents->SetIsCrashed(base::TERMINATION_STATUS_PROCESS_CRASHED, -1);
1063 EXPECT_TRUE(web_contents->IsCrashed());
[email protected]7de53c62011-05-13 06:44:161064
[email protected]78e2edc2012-07-01 23:32:281065 chrome::NavigateParams p(MakeNavigateParams());
[email protected]7de53c62011-05-13 06:44:161066 p.disposition = SINGLETON_TAB;
1067 p.url = singleton_url;
[email protected]50592b52013-05-02 22:26:251068 p.window_action = chrome::NavigateParams::SHOW_WINDOW;
[email protected]78e2edc2012-07-01 23:32:281069 p.path_behavior = chrome::NavigateParams::IGNORE_AND_NAVIGATE;
[email protected]ddddfda2011-07-14 23:19:391070 ui_test_utils::NavigateToURL(&p);
[email protected]7de53c62011-05-13 06:44:161071
1072 // The tab should not be sad anymore.
[email protected]83ff91c2012-01-05 20:54:131073 EXPECT_FALSE(web_contents->IsCrashed());
[email protected]7de53c62011-05-13 06:44:161074}
1075
[email protected]fcca741b2011-06-17 22:46:371076IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
1077 NavigateFromDefaultToOptionsInSameTab) {
[email protected]ddddfda2011-07-14 23:19:391078 {
[email protected]a7fe9112012-07-20 02:34:451079 content::WindowedNotificationObserver observer(
[email protected]ad50def52011-10-19 23:17:071080 content::NOTIFICATION_LOAD_STOP,
1081 content::NotificationService::AllSources());
[email protected]5d9cace72012-06-21 16:07:121082 chrome::ShowSettings(browser());
[email protected]ddddfda2011-07-14 23:19:391083 observer.Wait();
1084 }
[email protected]ee496952013-01-10 23:17:331085 EXPECT_EQ(1, browser()->tab_strip_model()->count());
[email protected]52877dbc62012-06-29 22:22:031086 EXPECT_EQ(GetSettingsURL(),
[email protected]ee496952013-01-10 23:17:331087 ShortenUberURL(browser()->tab_strip_model()->
1088 GetActiveWebContents()->GetURL()));
[email protected]fcca741b2011-06-17 22:46:371089}
1090
1091IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
1092 NavigateFromBlankToOptionsInSameTab) {
[email protected]78e2edc2012-07-01 23:32:281093 chrome::NavigateParams p(MakeNavigateParams());
[email protected]8e09c7af2014-06-10 11:46:171094 p.url = GURL(url::kAboutBlankURL);
[email protected]ddddfda2011-07-14 23:19:391095 ui_test_utils::NavigateToURL(&p);
[email protected]fcca741b2011-06-17 22:46:371096
[email protected]ddddfda2011-07-14 23:19:391097 {
[email protected]a7fe9112012-07-20 02:34:451098 content::WindowedNotificationObserver observer(
[email protected]ad50def52011-10-19 23:17:071099 content::NOTIFICATION_LOAD_STOP,
1100 content::NotificationService::AllSources());
[email protected]5d9cace72012-06-21 16:07:121101 chrome::ShowSettings(browser());
[email protected]ddddfda2011-07-14 23:19:391102 observer.Wait();
1103 }
[email protected]ee496952013-01-10 23:17:331104 EXPECT_EQ(1, browser()->tab_strip_model()->count());
[email protected]52877dbc62012-06-29 22:22:031105 EXPECT_EQ(GetSettingsURL(),
[email protected]ee496952013-01-10 23:17:331106 ShortenUberURL(browser()->tab_strip_model()->
1107 GetActiveWebContents()->GetURL()));
[email protected]fcca741b2011-06-17 22:46:371108}
1109
1110IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
1111 NavigateFromNTPToOptionsInSameTab) {
[email protected]78e2edc2012-07-01 23:32:281112 chrome::NavigateParams p(MakeNavigateParams());
[email protected]ddddfda2011-07-14 23:19:391113 p.url = GURL(chrome::kChromeUINewTabURL);
1114 ui_test_utils::NavigateToURL(&p);
[email protected]ee496952013-01-10 23:17:331115 EXPECT_EQ(1, browser()->tab_strip_model()->count());
[email protected]27658f32013-11-14 03:20:371116 EXPECT_EQ(GURL(chrome::kChromeUINewTabURL),
1117 browser()->tab_strip_model()->GetActiveWebContents()->GetURL());
[email protected]fcca741b2011-06-17 22:46:371118
[email protected]ddddfda2011-07-14 23:19:391119 {
[email protected]a7fe9112012-07-20 02:34:451120 content::WindowedNotificationObserver observer(
[email protected]ad50def52011-10-19 23:17:071121 content::NOTIFICATION_LOAD_STOP,
1122 content::NotificationService::AllSources());
[email protected]5d9cace72012-06-21 16:07:121123 chrome::ShowSettings(browser());
[email protected]ddddfda2011-07-14 23:19:391124 observer.Wait();
1125 }
[email protected]ee496952013-01-10 23:17:331126 EXPECT_EQ(1, browser()->tab_strip_model()->count());
[email protected]52877dbc62012-06-29 22:22:031127 EXPECT_EQ(GetSettingsURL(),
[email protected]ee496952013-01-10 23:17:331128 ShortenUberURL(browser()->tab_strip_model()->
1129 GetActiveWebContents()->GetURL()));
[email protected]fcca741b2011-06-17 22:46:371130}
1131
1132IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
1133 NavigateFromPageToOptionsInNewTab) {
[email protected]78e2edc2012-07-01 23:32:281134 chrome::NavigateParams p(MakeNavigateParams());
[email protected]ddddfda2011-07-14 23:19:391135 ui_test_utils::NavigateToURL(&p);
[email protected]ee496952013-01-10 23:17:331136 EXPECT_EQ(GetGoogleURL(),
1137 browser()->tab_strip_model()->GetActiveWebContents()->GetURL());
[email protected]0665ebe2013-02-13 09:53:191138 EXPECT_EQ(1u, chrome::GetTotalBrowserCount());
[email protected]ee496952013-01-10 23:17:331139 EXPECT_EQ(1, browser()->tab_strip_model()->count());
[email protected]fcca741b2011-06-17 22:46:371140
[email protected]ddddfda2011-07-14 23:19:391141 {
[email protected]a7fe9112012-07-20 02:34:451142 content::WindowedNotificationObserver observer(
[email protected]ad50def52011-10-19 23:17:071143 content::NOTIFICATION_LOAD_STOP,
1144 content::NotificationService::AllSources());
[email protected]5d9cace72012-06-21 16:07:121145 chrome::ShowSettings(browser());
[email protected]ddddfda2011-07-14 23:19:391146 observer.Wait();
1147 }
[email protected]ee496952013-01-10 23:17:331148 EXPECT_EQ(2, browser()->tab_strip_model()->count());
[email protected]52877dbc62012-06-29 22:22:031149 EXPECT_EQ(GetSettingsURL(),
[email protected]ee496952013-01-10 23:17:331150 ShortenUberURL(browser()->tab_strip_model()->
1151 GetActiveWebContents()->GetURL()));
[email protected]fcca741b2011-06-17 22:46:371152}
1153
1154IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
1155 NavigateFromNTPToOptionsSingleton) {
[email protected]ddddfda2011-07-14 23:19:391156 {
[email protected]a7fe9112012-07-20 02:34:451157 content::WindowedNotificationObserver observer(
[email protected]ad50def52011-10-19 23:17:071158 content::NOTIFICATION_LOAD_STOP,
1159 content::NotificationService::AllSources());
[email protected]5d9cace72012-06-21 16:07:121160 chrome::ShowSettings(browser());
[email protected]ddddfda2011-07-14 23:19:391161 observer.Wait();
1162 }
[email protected]ee496952013-01-10 23:17:331163 EXPECT_EQ(1, browser()->tab_strip_model()->count());
[email protected]fcca741b2011-06-17 22:46:371164
[email protected]a37d4b02012-06-25 21:56:101165 chrome::NewTab(browser());
[email protected]ee496952013-01-10 23:17:331166 EXPECT_EQ(2, browser()->tab_strip_model()->count());
[email protected]fcca741b2011-06-17 22:46:371167
[email protected]ddddfda2011-07-14 23:19:391168 {
[email protected]a7fe9112012-07-20 02:34:451169 content::WindowedNotificationObserver observer(
[email protected]ad50def52011-10-19 23:17:071170 content::NOTIFICATION_LOAD_STOP,
1171 content::NotificationService::AllSources());
[email protected]5d9cace72012-06-21 16:07:121172 chrome::ShowSettings(browser());
[email protected]ddddfda2011-07-14 23:19:391173 observer.Wait();
1174 }
[email protected]ee496952013-01-10 23:17:331175 EXPECT_EQ(2, browser()->tab_strip_model()->count());
[email protected]52877dbc62012-06-29 22:22:031176 EXPECT_EQ(GetSettingsURL(),
[email protected]ee496952013-01-10 23:17:331177 ShortenUberURL(browser()->tab_strip_model()->
1178 GetActiveWebContents()->GetURL()));
[email protected]fcca741b2011-06-17 22:46:371179}
1180
1181IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
1182 NavigateFromNTPToOptionsPageInSameTab) {
[email protected]ddddfda2011-07-14 23:19:391183 {
[email protected]a7fe9112012-07-20 02:34:451184 content::WindowedNotificationObserver observer(
[email protected]ad50def52011-10-19 23:17:071185 content::NOTIFICATION_LOAD_STOP,
1186 content::NotificationService::AllSources());
[email protected]5d9cace72012-06-21 16:07:121187 chrome::ShowClearBrowsingDataDialog(browser());
[email protected]ddddfda2011-07-14 23:19:391188 observer.Wait();
1189 }
[email protected]ee496952013-01-10 23:17:331190 EXPECT_EQ(1, browser()->tab_strip_model()->count());
[email protected]a048ad22012-03-23 04:26:561191 EXPECT_EQ(GetClearBrowsingDataURL(),
[email protected]ee496952013-01-10 23:17:331192 browser()->tab_strip_model()->GetActiveWebContents()->GetURL());
[email protected]fcca741b2011-06-17 22:46:371193
[email protected]a37d4b02012-06-25 21:56:101194 chrome::NewTab(browser());
[email protected]ee496952013-01-10 23:17:331195 EXPECT_EQ(2, browser()->tab_strip_model()->count());
[email protected]fcca741b2011-06-17 22:46:371196
[email protected]ddddfda2011-07-14 23:19:391197 {
[email protected]a7fe9112012-07-20 02:34:451198 content::WindowedNotificationObserver observer(
[email protected]ad50def52011-10-19 23:17:071199 content::NOTIFICATION_LOAD_STOP,
1200 content::NotificationService::AllSources());
[email protected]5d9cace72012-06-21 16:07:121201 chrome::ShowClearBrowsingDataDialog(browser());
[email protected]ddddfda2011-07-14 23:19:391202 observer.Wait();
1203 }
[email protected]ee496952013-01-10 23:17:331204 EXPECT_EQ(2, browser()->tab_strip_model()->count());
[email protected]a048ad22012-03-23 04:26:561205 EXPECT_EQ(GetClearBrowsingDataURL(),
[email protected]ee496952013-01-10 23:17:331206 browser()->tab_strip_model()->GetActiveWebContents()->GetURL());
[email protected]fcca741b2011-06-17 22:46:371207}
1208
[email protected]fcca741b2011-06-17 22:46:371209IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
[email protected]05912742013-03-12 00:29:151210 NavigateFromOtherTabToSingletonOptions) {
[email protected]ddddfda2011-07-14 23:19:391211 {
[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]5d9cace72012-06-21 16:07:121215 chrome::ShowSettings(browser());
[email protected]ddddfda2011-07-14 23:19:391216 observer.Wait();
1217 }
1218 {
[email protected]a7fe9112012-07-20 02:34:451219 content::WindowedNotificationObserver observer(
[email protected]ad50def52011-10-19 23:17:071220 content::NOTIFICATION_LOAD_STOP,
1221 content::NotificationService::AllSources());
[email protected]52877dbc62012-06-29 22:22:031222 chrome::AddSelectedTabWithURL(browser(), GetGoogleURL(),
1223 content::PAGE_TRANSITION_LINK);
[email protected]ddddfda2011-07-14 23:19:391224 observer.Wait();
1225 }
[email protected]fcca741b2011-06-17 22:46:371226
[email protected]05912742013-03-12 00:29:151227 // This load should simply cause a tab switch.
1228 chrome::ShowSettings(browser());
1229
[email protected]ee496952013-01-10 23:17:331230 EXPECT_EQ(2, browser()->tab_strip_model()->count());
[email protected]ddddfda2011-07-14 23:19:391231 EXPECT_EQ(GetSettingsURL(),
[email protected]ee496952013-01-10 23:17:331232 ShortenUberURL(browser()->tab_strip_model()->
1233 GetActiveWebContents()->GetURL()));
[email protected]fcca741b2011-06-17 22:46:371234}
1235
[email protected]4e78b2d2013-06-12 16:46:171236IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, CloseSingletonTab) {
[email protected]79717cf2013-02-28 18:40:361237 for (int i = 0; i < 2; ++i) {
1238 content::WindowedNotificationObserver observer(
1239 content::NOTIFICATION_LOAD_STOP,
1240 content::NotificationService::AllSources());
1241 chrome::AddSelectedTabWithURL(browser(), GetGoogleURL(),
1242 content::PAGE_TRANSITION_TYPED);
1243 observer.Wait();
1244 }
1245
1246 browser()->tab_strip_model()->ActivateTabAt(0, true);
1247
1248 {
1249 content::WindowedNotificationObserver observer(
1250 content::NOTIFICATION_LOAD_STOP,
1251 content::NotificationService::AllSources());
1252 chrome::ShowSettings(browser());
1253 observer.Wait();
1254 }
1255
1256 EXPECT_TRUE(browser()->tab_strip_model()->CloseWebContentsAt(
1257 2, TabStripModel::CLOSE_USER_GESTURE));
1258 EXPECT_EQ(0, browser()->tab_strip_model()->active_index());
1259}
1260
[email protected]a048ad22012-03-23 04:26:561261// TODO(csilv): Update this for uber page. http://crbug.com/111579.
[email protected]ddddfda2011-07-14 23:19:391262IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
[email protected]a048ad22012-03-23 04:26:561263 DISABLED_NavigateFromDefaultToHistoryInSameTab) {
[email protected]ddddfda2011-07-14 23:19:391264 {
[email protected]a7fe9112012-07-20 02:34:451265 content::WindowedNotificationObserver observer(
[email protected]ad50def52011-10-19 23:17:071266 content::NOTIFICATION_LOAD_STOP,
1267 content::NotificationService::AllSources());
[email protected]5d9cace72012-06-21 16:07:121268 chrome::ShowHistory(browser());
[email protected]ddddfda2011-07-14 23:19:391269 observer.Wait();
1270 }
[email protected]ee496952013-01-10 23:17:331271 EXPECT_EQ(1, browser()->tab_strip_model()->count());
[email protected]11e03fb2012-03-03 19:07:051272 EXPECT_EQ(GURL(chrome::kChromeUIHistoryFrameURL),
[email protected]ee496952013-01-10 23:17:331273 browser()->tab_strip_model()->GetActiveWebContents()->GetURL());
[email protected]ddddfda2011-07-14 23:19:391274}
1275
[email protected]953c2132013-02-23 05:56:051276// TODO(linux_aura) http://crbug.com/163931
1277#if defined(OS_LINUX) && !defined(OS_CHROMEOS) && defined(USE_AURA)
1278#define MAYBE_NavigateFromDefaultToBookmarksInSameTab DISABLED_NavigateFromDefaultToBookmarksInSameTab
1279#else
1280#define MAYBE_NavigateFromDefaultToBookmarksInSameTab NavigateFromDefaultToBookmarksInSameTab
1281#endif
[email protected]ddddfda2011-07-14 23:19:391282IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
[email protected]953c2132013-02-23 05:56:051283 MAYBE_NavigateFromDefaultToBookmarksInSameTab) {
[email protected]ddddfda2011-07-14 23:19:391284 {
[email protected]a7fe9112012-07-20 02:34:451285 content::WindowedNotificationObserver observer(
[email protected]ad50def52011-10-19 23:17:071286 content::NOTIFICATION_LOAD_STOP,
1287 content::NotificationService::AllSources());
[email protected]5d9cace72012-06-21 16:07:121288 chrome::ShowBookmarkManager(browser());
[email protected]ddddfda2011-07-14 23:19:391289 observer.Wait();
1290 }
[email protected]ee496952013-01-10 23:17:331291 EXPECT_EQ(1, browser()->tab_strip_model()->count());
[email protected]bc16a252013-01-23 02:21:491292 EXPECT_TRUE(StartsWithASCII(
1293 browser()->tab_strip_model()->GetActiveWebContents()->GetURL().spec(),
1294 chrome::kChromeUIBookmarksURL,
1295 true));
[email protected]ddddfda2011-07-14 23:19:391296}
1297
1298IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
1299 NavigateFromDefaultToDownloadsInSameTab) {
1300 {
[email protected]a7fe9112012-07-20 02:34:451301 content::WindowedNotificationObserver observer(
[email protected]ad50def52011-10-19 23:17:071302 content::NOTIFICATION_LOAD_STOP,
1303 content::NotificationService::AllSources());
[email protected]5d9cace72012-06-21 16:07:121304 chrome::ShowDownloads(browser());
[email protected]ddddfda2011-07-14 23:19:391305 observer.Wait();
1306 }
[email protected]ee496952013-01-10 23:17:331307 EXPECT_EQ(1, browser()->tab_strip_model()->count());
[email protected]ddddfda2011-07-14 23:19:391308 EXPECT_EQ(GURL(chrome::kChromeUIDownloadsURL),
[email protected]ee496952013-01-10 23:17:331309 browser()->tab_strip_model()->GetActiveWebContents()->GetURL());
[email protected]ddddfda2011-07-14 23:19:391310}
1311
[email protected]8fb16a82012-08-17 02:17:591312IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
1313 NavigateWithoutBrowser) {
1314 // First navigate using the profile of the existing browser window, and
1315 // check that the window is reused.
1316 chrome::NavigateParams params(browser()->profile(), GetGoogleURL(),
1317 content::PAGE_TRANSITION_LINK);
1318 ui_test_utils::NavigateToURL(&params);
[email protected]0665ebe2013-02-13 09:53:191319 EXPECT_EQ(1u, chrome::GetTotalBrowserCount());
[email protected]8fb16a82012-08-17 02:17:591320
1321 // Now navigate using the incognito profile and check that a new window
1322 // is created.
1323 chrome::NavigateParams params_incognito(
1324 browser()->profile()->GetOffTheRecordProfile(),
1325 GetGoogleURL(), content::PAGE_TRANSITION_LINK);
1326 ui_test_utils::NavigateToURL(&params_incognito);
[email protected]0665ebe2013-02-13 09:53:191327 EXPECT_EQ(2u, chrome::GetTotalBrowserCount());
[email protected]8fb16a82012-08-17 02:17:591328}
1329
[email protected]beb1d1192013-05-14 04:47:511330IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, ViewSourceIsntSingleton) {
1331 const std::string viewsource_ntp_url =
[email protected]dbdda5402013-05-30 22:13:481332 std::string(content::kViewSourceScheme) + ":" +
[email protected]beb1d1192013-05-14 04:47:511333 chrome::kChromeUIVersionURL;
1334
1335 chrome::NavigateParams viewsource_params(browser(),
1336 GURL(viewsource_ntp_url),
1337 content::PAGE_TRANSITION_LINK);
1338 ui_test_utils::NavigateToURL(&viewsource_params);
1339
1340 chrome::NavigateParams singleton_params(browser(),
1341 GURL(chrome::kChromeUIVersionURL),
1342 content::PAGE_TRANSITION_LINK);
1343 singleton_params.disposition = SINGLETON_TAB;
1344 EXPECT_EQ(-1, chrome::GetIndexOfSingletonTab(&singleton_params));
1345}
1346
[email protected]a2efc35d2013-08-03 23:17:251347// This test verifies that browser initiated navigations can send requests
1348// using POST.
1349IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
1350 SendBrowserInitiatedRequestUsingPOST) {
1351 // Uses a test sever to verify POST request.
1352 ASSERT_TRUE(test_server()->Start());
1353
1354 // Open a browser initiated POST request in new foreground tab.
[email protected]e9273e192013-12-11 17:51:491355 base::string16 expected_title(base::ASCIIToUTF16(kExpectedTitle));
[email protected]a2efc35d2013-08-03 23:17:251356 std::string post_data = kExpectedTitle;
[email protected]e9273e192013-12-11 17:51:491357 base::string16 title;
[email protected]a2efc35d2013-08-03 23:17:251358 ASSERT_TRUE(OpenPOSTURLInNewForegroundTabAndGetTitle(
1359 test_server()->GetURL(kEchoTitleCommand), post_data, true, &title));
1360 EXPECT_EQ(expected_title, title);
1361}
1362
1363// This test verifies that renderer initiated navigations can NOT send requests
1364// using POST.
1365IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
1366 SendRendererInitiatedRequestUsingPOST) {
1367 // Uses a test sever to verify POST request.
1368 ASSERT_TRUE(test_server()->Start());
1369
1370 // Open a renderer initiated POST request in new foreground tab.
[email protected]e9273e192013-12-11 17:51:491371 base::string16 expected_title(base::ASCIIToUTF16(kExpectedTitle));
[email protected]a2efc35d2013-08-03 23:17:251372 std::string post_data = kExpectedTitle;
[email protected]e9273e192013-12-11 17:51:491373 base::string16 title;
[email protected]a2efc35d2013-08-03 23:17:251374 ASSERT_TRUE(OpenPOSTURLInNewForegroundTabAndGetTitle(
1375 test_server()->GetURL(kEchoTitleCommand), post_data, false, &title));
1376 EXPECT_NE(expected_title, title);
1377}
1378
1379} // namespace