blob: 87291e8276cf815abc2c1ea18f2e794a40d143c2 [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]a2efc35d2013-08-03 23:17:259#include "base/strings/utf_string_conversions.h"
[email protected]26c53e662011-07-09 02:21:0210#include "chrome/app/chrome_command_ids.h"
[email protected]93ad8e1c2011-11-08 21:34:0511#include "chrome/browser/prefs/incognito_mode_prefs.h"
[email protected]8ecad5e2010-12-02 21:18:3312#include "chrome/browser/profiles/profile.h"
[email protected]2b09ae552013-02-23 06:38:0313#include "chrome/browser/ui/browser.h"
[email protected]a37d4b02012-06-25 21:56:1014#include "chrome/browser/ui/browser_commands.h"
[email protected]0665ebe2013-02-13 09:53:1915#include "chrome/browser/ui/browser_finder.h"
[email protected]339d6dd2010-11-12 00:41:5816#include "chrome/browser/ui/browser_navigator.h"
[email protected]52877dbc62012-06-29 22:22:0317#include "chrome/browser/ui/browser_tabstrip.h"
[email protected]bb89e7482010-11-17 18:27:0418#include "chrome/browser/ui/browser_window.h"
[email protected]5d9cace72012-06-21 16:07:1219#include "chrome/browser/ui/chrome_pages.h"
[email protected]beb1d1192013-05-14 04:47:5120#include "chrome/browser/ui/singleton_tabs.h"
[email protected]b56e2e32012-05-11 21:18:0421#include "chrome/browser/ui/tabs/tab_strip_model.h"
[email protected]bb89e7482010-11-17 18:27:0422#include "chrome/common/chrome_switches.h"
[email protected]93ad8e1c2011-11-08 21:34:0523#include "chrome/common/pref_names.h"
[email protected]ddddfda2011-07-14 23:19:3924#include "chrome/common/url_constants.h"
[email protected]af44e7fb2011-07-29 18:32:3225#include "chrome/test/base/ui_test_utils.h"
[email protected]ad50def52011-10-19 23:17:0726#include "content/public/browser/notification_service.h"
[email protected]0d6e9bd2011-10-18 04:29:1627#include "content/public/browser/notification_types.h"
[email protected]83ff91c2012-01-05 20:54:1328#include "content/public/browser/web_contents.h"
[email protected]8643e6d2012-01-18 20:26:1029#include "content/public/browser/web_contents_view.h"
[email protected]c47317e2012-06-20 22:35:3130#include "ipc/ipc_message.h"
[email protected]a1feae52010-10-11 22:14:4531
[email protected]4ca15302012-01-03 05:53:2032using content::WebContents;
33
[email protected]ddddfda2011-07-14 23:19:3934namespace {
35
[email protected]a2efc35d2013-08-03 23:17:2536const char kExpectedTitle[] = "PASSED!";
37const char kEchoTitleCommand[] = "echotitle";
38
[email protected]ddddfda2011-07-14 23:19:3939GURL GetGoogleURL() {
[email protected]bd817c22011-02-09 08:16:4640 return GURL("http://www.google.com/");
41}
[email protected]a1feae52010-10-11 22:14:4542
[email protected]ddddfda2011-07-14 23:19:3943GURL GetSettingsURL() {
[email protected]f8f93eb2012-09-25 03:06:2444 return GURL(chrome::kChromeUISettingsURL);
[email protected]ddddfda2011-07-14 23:19:3945}
46
[email protected]a048ad22012-03-23 04:26:5647GURL GetContentSettingsURL() {
48 return GetSettingsURL().Resolve(chrome::kContentSettingsExceptionsSubPage);
[email protected]ddddfda2011-07-14 23:19:3949}
50
[email protected]a048ad22012-03-23 04:26:5651GURL GetClearBrowsingDataURL() {
52 return GetSettingsURL().Resolve(chrome::kClearBrowserDataSubPage);
[email protected]ddddfda2011-07-14 23:19:3953}
54
[email protected]f8f93eb2012-09-25 03:06:2455// Converts long uber URLs ("chrome://chrome/foo/") to short (virtual) URLs
56// ("chrome://foo/"). This should be used to convert the return value of
57// WebContentsImpl::GetURL before comparison because it can return either the
58// real URL or the virtual URL.
59GURL ShortenUberURL(const GURL& url) {
60 std::string url_string = url.spec();
61 const std::string long_prefix = "chrome://chrome/";
62 const std::string short_prefix = "chrome://";
63 if (url_string.find(long_prefix) != 0)
64 return url;
65 url_string.replace(0, long_prefix.length(), short_prefix);
66 return GURL(url_string);
67}
68
[email protected]a2efc35d2013-08-03 23:17:2569} // namespace
[email protected]ddddfda2011-07-14 23:19:3970
[email protected]78e2edc2012-07-01 23:32:2871chrome::NavigateParams BrowserNavigatorTest::MakeNavigateParams() const {
[email protected]bd817c22011-02-09 08:16:4672 return MakeNavigateParams(browser());
73}
[email protected]a1feae52010-10-11 22:14:4574
[email protected]78e2edc2012-07-01 23:32:2875chrome::NavigateParams BrowserNavigatorTest::MakeNavigateParams(
[email protected]bd817c22011-02-09 08:16:4676 Browser* browser) const {
[email protected]78e2edc2012-07-01 23:32:2877 chrome::NavigateParams params(browser, GetGoogleURL(),
78 content::PAGE_TRANSITION_LINK);
[email protected]50592b52013-05-02 22:26:2579 params.window_action = chrome::NavigateParams::SHOW_WINDOW;
[email protected]bd817c22011-02-09 08:16:4680 return params;
81}
[email protected]a1feae52010-10-11 22:14:4582
[email protected]a2efc35d2013-08-03 23:17:2583bool BrowserNavigatorTest::OpenPOSTURLInNewForegroundTabAndGetTitle(
84 const GURL& url, const std::string& post_data, bool is_browser_initiated,
85 base::string16* title) {
86 chrome::NavigateParams param(MakeNavigateParams());
87 param.disposition = NEW_FOREGROUND_TAB;
88 param.url = url;
89 param.is_renderer_initiated = !is_browser_initiated;
90 param.uses_post = true;
91 param.browser_initiated_post_data = new base::RefCountedStaticMemory(
92 reinterpret_cast<const uint8*>(post_data.data()), post_data.size());
93
94 ui_test_utils::NavigateToURL(&param);
95 if (!param.target_contents)
96 return false;
97
98 // Navigate() should have opened the contents in new foreground tab in the
99 // current Browser.
100 EXPECT_EQ(browser(), param.browser);
101 EXPECT_EQ(browser()->tab_strip_model()->GetActiveWebContents(),
102 param.target_contents);
103 // We should have one window, with one tab.
104 EXPECT_EQ(1u, chrome::GetTotalBrowserCount());
105 EXPECT_EQ(2, browser()->tab_strip_model()->count());
106
107 *title = param.target_contents->GetTitle();
108 return true;
109}
110
[email protected]bd817c22011-02-09 08:16:46111Browser* BrowserNavigatorTest::CreateEmptyBrowserForType(Browser::Type type,
112 Profile* profile) {
[email protected]2b09ae552013-02-23 06:38:03113 Browser* browser = new Browser(
[email protected]ed2fa722013-06-25 20:37:34114 Browser::CreateParams(type, profile, chrome::GetActiveDesktop()));
[email protected]00509a32013-11-17 17:45:37115 chrome::AddTabAt(browser, GURL(), -1, true);
[email protected]bd817c22011-02-09 08:16:46116 return browser;
117}
[email protected]a1feae52010-10-11 22:14:45118
[email protected]b35b26b32011-05-05 20:35:14119Browser* BrowserNavigatorTest::CreateEmptyBrowserForApp(Browser::Type type,
120 Profile* profile) {
[email protected]a4fe67012012-07-25 20:14:29121 Browser* browser = new Browser(
[email protected]da22aa62012-04-04 18:54:35122 Browser::CreateParams::CreateForApp(
[email protected]2b09ae552013-02-23 06:38:03123 Browser::TYPE_POPUP, "Test", gfx::Rect(), profile,
[email protected]ed2fa722013-06-25 20:37:34124 chrome::GetActiveDesktop()));
[email protected]00509a32013-11-17 17:45:37125 chrome::AddTabAt(browser, GURL(), -1, true);
[email protected]b35b26b32011-05-05 20:35:14126 return browser;
127}
128
[email protected]e232c992012-12-06 12:43:20129WebContents* BrowserNavigatorTest::CreateWebContents() {
[email protected]54944cde2012-12-09 09:24:59130 content::WebContents::CreateParams create_params(browser()->profile());
[email protected]ed245db2012-12-18 08:00:45131 content::WebContents* base_web_contents =
[email protected]ee496952013-01-10 23:17:33132 browser()->tab_strip_model()->GetActiveWebContents();
[email protected]ed245db2012-12-18 08:00:45133 if (base_web_contents) {
134 create_params.initial_size =
135 base_web_contents->GetView()->GetContainerSize();
136 }
[email protected]54944cde2012-12-09 09:24:59137 return WebContents::Create(create_params);
[email protected]bd817c22011-02-09 08:16:46138}
[email protected]a1feae52010-10-11 22:14:45139
[email protected]bd817c22011-02-09 08:16:46140void BrowserNavigatorTest::RunSuppressTest(WindowOpenDisposition disposition) {
[email protected]ee496952013-01-10 23:17:33141 GURL old_url = browser()->tab_strip_model()->GetActiveWebContents()->GetURL();
[email protected]78e2edc2012-07-01 23:32:28142 chrome::NavigateParams p(MakeNavigateParams());
[email protected]bd817c22011-02-09 08:16:46143 p.disposition = disposition;
[email protected]78e2edc2012-07-01 23:32:28144 chrome::Navigate(&p);
[email protected]a1feae52010-10-11 22:14:45145
[email protected]bd817c22011-02-09 08:16:46146 // Nothing should have happened as a result of Navigate();
[email protected]ee496952013-01-10 23:17:33147 EXPECT_EQ(1, browser()->tab_strip_model()->count());
[email protected]0665ebe2013-02-13 09:53:19148 EXPECT_EQ(1u, chrome::GetTotalBrowserCount());
[email protected]ee496952013-01-10 23:17:33149 EXPECT_EQ(old_url,
150 browser()->tab_strip_model()->GetActiveWebContents()->GetURL());
[email protected]bd817c22011-02-09 08:16:46151}
[email protected]bb89e7482010-11-17 18:27:04152
[email protected]fc0ed302011-11-29 23:17:19153void BrowserNavigatorTest::RunUseNonIncognitoWindowTest(const GURL& url) {
154 Browser* incognito_browser = CreateIncognitoBrowser();
155
[email protected]0665ebe2013-02-13 09:53:19156 EXPECT_EQ(2u, chrome::GetTotalBrowserCount());
[email protected]ee496952013-01-10 23:17:33157 EXPECT_EQ(1, browser()->tab_strip_model()->count());
158 EXPECT_EQ(1, incognito_browser->tab_strip_model()->count());
[email protected]fc0ed302011-11-29 23:17:19159
160 // Navigate to the page.
[email protected]78e2edc2012-07-01 23:32:28161 chrome::NavigateParams p(MakeNavigateParams(incognito_browser));
[email protected]fc0ed302011-11-29 23:17:19162 p.disposition = SINGLETON_TAB;
163 p.url = url;
[email protected]50592b52013-05-02 22:26:25164 p.window_action = chrome::NavigateParams::SHOW_WINDOW;
[email protected]78e2edc2012-07-01 23:32:28165 chrome::Navigate(&p);
[email protected]fc0ed302011-11-29 23:17:19166
[email protected]50592b52013-05-02 22:26:25167 // This page should be opened in browser() window.
[email protected]fc0ed302011-11-29 23:17:19168 EXPECT_NE(incognito_browser, p.browser);
169 EXPECT_EQ(browser(), p.browser);
[email protected]ee496952013-01-10 23:17:33170 EXPECT_EQ(2, browser()->tab_strip_model()->count());
171 EXPECT_EQ(url,
172 browser()->tab_strip_model()->GetActiveWebContents()->GetURL());
[email protected]fc0ed302011-11-29 23:17:19173}
174
175void BrowserNavigatorTest::RunDoNothingIfIncognitoIsForcedTest(
176 const GURL& url) {
177 Browser* browser = CreateIncognitoBrowser();
178
179 // Set kIncognitoModeAvailability to FORCED.
180 PrefService* prefs1 = browser->profile()->GetPrefs();
181 prefs1->SetInteger(prefs::kIncognitoModeAvailability,
182 IncognitoModePrefs::FORCED);
183 PrefService* prefs2 = browser->profile()->GetOriginalProfile()->GetPrefs();
184 prefs2->SetInteger(prefs::kIncognitoModeAvailability,
185 IncognitoModePrefs::FORCED);
186
187 // Navigate to the page.
[email protected]78e2edc2012-07-01 23:32:28188 chrome::NavigateParams p(MakeNavigateParams(browser));
[email protected]fc0ed302011-11-29 23:17:19189 p.disposition = OFF_THE_RECORD;
190 p.url = url;
[email protected]50592b52013-05-02 22:26:25191 p.window_action = chrome::NavigateParams::SHOW_WINDOW;
[email protected]78e2edc2012-07-01 23:32:28192 chrome::Navigate(&p);
[email protected]fc0ed302011-11-29 23:17:19193
194 // The page should not be opened.
195 EXPECT_EQ(browser, p.browser);
[email protected]ee496952013-01-10 23:17:33196 EXPECT_EQ(1, browser->tab_strip_model()->count());
[email protected]081dc522013-05-15 04:59:20197 EXPECT_EQ(GURL(content::kAboutBlankURL),
[email protected]ee496952013-01-10 23:17:33198 browser->tab_strip_model()->GetActiveWebContents()->GetURL());
[email protected]fc0ed302011-11-29 23:17:19199}
200
[email protected]6c2381d2011-10-19 02:52:53201void BrowserNavigatorTest::Observe(
202 int type,
203 const content::NotificationSource& source,
204 const content::NotificationDetails& details) {
[email protected]432115822011-07-10 15:52:27205 switch (type) {
[email protected]d53a08c2012-07-18 20:35:30206 case content::NOTIFICATION_WEB_CONTENTS_RENDER_VIEW_HOST_CREATED: {
[email protected]bd817c22011-02-09 08:16:46207 ++this->created_tab_contents_count_;
208 break;
[email protected]fa7ebe02010-11-29 23:04:57209 }
[email protected]bd817c22011-02-09 08:16:46210 default:
211 break;
[email protected]fa7ebe02010-11-29 23:04:57212 }
[email protected]bd817c22011-02-09 08:16:46213}
[email protected]fa7ebe02010-11-29 23:04:57214
[email protected]ddddfda2011-07-14 23:19:39215
[email protected]bd817c22011-02-09 08:16:46216namespace {
[email protected]a1feae52010-10-11 22:14:45217
[email protected]a1feae52010-10-11 22:14:45218// This test verifies that when a navigation occurs within a tab, the tab count
219// of the Browser remains the same and the current tab bears the loaded URL.
[email protected]59167c22013-06-03 18:07:32220// Note that network URLs are not actually loaded in tests, so this also tests
221// that error pages leave the intended URL in the address bar.
[email protected]a1feae52010-10-11 22:14:45222IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_CurrentTab) {
[email protected]ddddfda2011-07-14 23:19:39223 ui_test_utils::NavigateToURL(browser(), GetGoogleURL());
[email protected]ee496952013-01-10 23:17:33224 EXPECT_EQ(GetGoogleURL(),
225 browser()->tab_strip_model()->GetActiveWebContents()->GetURL());
[email protected]a1feae52010-10-11 22:14:45226 // We should have one window with one tab.
[email protected]0665ebe2013-02-13 09:53:19227 EXPECT_EQ(1u, chrome::GetTotalBrowserCount());
[email protected]ee496952013-01-10 23:17:33228 EXPECT_EQ(1, browser()->tab_strip_model()->count());
[email protected]a1feae52010-10-11 22:14:45229}
230
[email protected]bd817c22011-02-09 08:16:46231// This test verifies that a singleton tab is refocused if one is already opened
[email protected]19d9f3a2010-10-14 21:49:36232// in another or an existing window, or added if it is not.
233IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_SingletonTabExisting) {
[email protected]19d9f3a2010-10-14 21:49:36234 GURL singleton_url1("http://maps.google.com/");
[email protected]fa7ebe02010-11-29 23:04:57235
[email protected]e232c992012-12-06 12:43:20236 // Register for a notification if an additional WebContents was instantiated.
[email protected]bd817c22011-02-09 08:16:46237 // Opening a Singleton tab that is already opened should not be opening a new
[email protected]e232c992012-12-06 12:43:20238 // tab nor be creating a new WebContents object.
[email protected]6c2381d2011-10-19 02:52:53239 content::NotificationRegistrar registrar;
[email protected]fa7ebe02010-11-29 23:04:57240
241 // As the registrar object goes out of scope, this will get unregistered
[email protected]d53a08c2012-07-18 20:35:30242 registrar.Add(this,
243 content::NOTIFICATION_WEB_CONTENTS_RENDER_VIEW_HOST_CREATED,
[email protected]ad50def52011-10-19 23:17:07244 content::NotificationService::AllSources());
[email protected]fa7ebe02010-11-29 23:04:57245
[email protected]52877dbc62012-06-29 22:22:03246 chrome::AddSelectedTabWithURL(browser(), singleton_url1,
247 content::PAGE_TRANSITION_LINK);
248 chrome::AddSelectedTabWithURL(browser(), GetGoogleURL(),
249 content::PAGE_TRANSITION_LINK);
[email protected]19d9f3a2010-10-14 21:49:36250
251 // We should have one browser with 3 tabs, the 3rd selected.
[email protected]0665ebe2013-02-13 09:53:19252 EXPECT_EQ(1u, chrome::GetTotalBrowserCount());
[email protected]ee496952013-01-10 23:17:33253 EXPECT_EQ(2, browser()->tab_strip_model()->active_index());
[email protected]19d9f3a2010-10-14 21:49:36254
[email protected]fa7ebe02010-11-29 23:04:57255 unsigned int previous_tab_contents_count =
256 created_tab_contents_count_ = 0;
257
[email protected]19d9f3a2010-10-14 21:49:36258 // Navigate to singleton_url1.
[email protected]78e2edc2012-07-01 23:32:28259 chrome::NavigateParams p(MakeNavigateParams());
[email protected]19d9f3a2010-10-14 21:49:36260 p.disposition = SINGLETON_TAB;
261 p.url = singleton_url1;
[email protected]78e2edc2012-07-01 23:32:28262 chrome::Navigate(&p);
[email protected]19d9f3a2010-10-14 21:49:36263
264 // The middle tab should now be selected.
265 EXPECT_EQ(browser(), p.browser);
[email protected]ee496952013-01-10 23:17:33266 EXPECT_EQ(1, browser()->tab_strip_model()->active_index());
[email protected]fa7ebe02010-11-29 23:04:57267
268 // No tab contents should have been created
269 EXPECT_EQ(previous_tab_contents_count,
270 created_tab_contents_count_);
[email protected]19d9f3a2010-10-14 21:49:36271}
272
273IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
[email protected]578c6962011-08-24 22:06:40274 Disposition_SingletonTabRespectingRef) {
275 GURL singleton_ref_url1("http://maps.google.com/#a");
276 GURL singleton_ref_url2("http://maps.google.com/#b");
277 GURL singleton_ref_url3("http://maps.google.com/");
278
[email protected]52877dbc62012-06-29 22:22:03279 chrome::AddSelectedTabWithURL(browser(), singleton_ref_url1,
280 content::PAGE_TRANSITION_LINK);
[email protected]578c6962011-08-24 22:06:40281
282 // We should have one browser with 2 tabs, 2nd selected.
[email protected]0665ebe2013-02-13 09:53:19283 EXPECT_EQ(1u, chrome::GetTotalBrowserCount());
[email protected]ee496952013-01-10 23:17:33284 EXPECT_EQ(2, browser()->tab_strip_model()->count());
285 EXPECT_EQ(1, browser()->tab_strip_model()->active_index());
[email protected]578c6962011-08-24 22:06:40286
287 // Navigate to singleton_url2.
[email protected]78e2edc2012-07-01 23:32:28288 chrome::NavigateParams p(MakeNavigateParams());
[email protected]578c6962011-08-24 22:06:40289 p.disposition = SINGLETON_TAB;
290 p.url = singleton_ref_url2;
[email protected]78e2edc2012-07-01 23:32:28291 chrome::Navigate(&p);
[email protected]578c6962011-08-24 22:06:40292
293 // We should now have 2 tabs, the 2nd one selected.
294 EXPECT_EQ(browser(), p.browser);
[email protected]ee496952013-01-10 23:17:33295 EXPECT_EQ(2, browser()->tab_strip_model()->count());
296 EXPECT_EQ(1, browser()->tab_strip_model()->active_index());
[email protected]578c6962011-08-24 22:06:40297
298 // Navigate to singleton_url2, but with respect ref set.
299 p = MakeNavigateParams();
300 p.disposition = SINGLETON_TAB;
301 p.url = singleton_ref_url2;
[email protected]78e2edc2012-07-01 23:32:28302 p.ref_behavior = chrome::NavigateParams::RESPECT_REF;
303 chrome::Navigate(&p);
[email protected]578c6962011-08-24 22:06:40304
305 // We should now have 3 tabs, the 3th one selected.
306 EXPECT_EQ(browser(), p.browser);
[email protected]ee496952013-01-10 23:17:33307 EXPECT_EQ(3, browser()->tab_strip_model()->count());
308 EXPECT_EQ(2, browser()->tab_strip_model()->active_index());
[email protected]578c6962011-08-24 22:06:40309
310 // Navigate to singleton_url3.
311 p = MakeNavigateParams();
312 p.disposition = SINGLETON_TAB;
313 p.url = singleton_ref_url3;
[email protected]78e2edc2012-07-01 23:32:28314 p.ref_behavior = chrome::NavigateParams::RESPECT_REF;
315 chrome::Navigate(&p);
[email protected]578c6962011-08-24 22:06:40316
317 // We should now have 4 tabs, the 4th one selected.
318 EXPECT_EQ(browser(), p.browser);
[email protected]ee496952013-01-10 23:17:33319 EXPECT_EQ(4, browser()->tab_strip_model()->count());
320 EXPECT_EQ(3, browser()->tab_strip_model()->active_index());
[email protected]578c6962011-08-24 22:06:40321}
322
323IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
[email protected]19d9f3a2010-10-14 21:49:36324 Disposition_SingletonTabNoneExisting) {
[email protected]19d9f3a2010-10-14 21:49:36325 GURL singleton_url1("http://maps.google.com/");
326
[email protected]bd817c22011-02-09 08:16:46327 // We should have one browser with 1 tab.
[email protected]0665ebe2013-02-13 09:53:19328 EXPECT_EQ(1u, chrome::GetTotalBrowserCount());
[email protected]ee496952013-01-10 23:17:33329 EXPECT_EQ(0, browser()->tab_strip_model()->active_index());
[email protected]19d9f3a2010-10-14 21:49:36330
331 // Navigate to singleton_url1.
[email protected]78e2edc2012-07-01 23:32:28332 chrome::NavigateParams p(MakeNavigateParams());
[email protected]19d9f3a2010-10-14 21:49:36333 p.disposition = SINGLETON_TAB;
334 p.url = singleton_url1;
[email protected]78e2edc2012-07-01 23:32:28335 chrome::Navigate(&p);
[email protected]19d9f3a2010-10-14 21:49:36336
337 // We should now have 2 tabs, the 2nd one selected.
338 EXPECT_EQ(browser(), p.browser);
[email protected]ee496952013-01-10 23:17:33339 EXPECT_EQ(2, browser()->tab_strip_model()->count());
340 EXPECT_EQ(1, browser()->tab_strip_model()->active_index());
[email protected]a1feae52010-10-11 22:14:45341}
342
343// This test verifies that when a navigation results in a foreground tab, the
344// tab count of the Browser increases and the selected tab shifts to the new
345// foreground tab.
346IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_NewForegroundTab) {
[email protected]ee496952013-01-10 23:17:33347 WebContents* old_contents =
348 browser()->tab_strip_model()->GetActiveWebContents();
[email protected]78e2edc2012-07-01 23:32:28349 chrome::NavigateParams p(MakeNavigateParams());
[email protected]a1feae52010-10-11 22:14:45350 p.disposition = NEW_FOREGROUND_TAB;
[email protected]78e2edc2012-07-01 23:32:28351 chrome::Navigate(&p);
[email protected]ee496952013-01-10 23:17:33352 EXPECT_NE(old_contents,
353 browser()->tab_strip_model()->GetActiveWebContents());
[email protected]e232c992012-12-06 12:43:20354 EXPECT_EQ(browser()->tab_strip_model()->GetActiveWebContents(),
[email protected]59253a652012-11-20 00:17:26355 p.target_contents);
[email protected]ee496952013-01-10 23:17:33356 EXPECT_EQ(2, browser()->tab_strip_model()->count());
[email protected]a1feae52010-10-11 22:14:45357}
358
359// This test verifies that when a navigation results in a background tab, the
360// tab count of the Browser increases but the selected tab remains the same.
361IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_NewBackgroundTab) {
[email protected]ee496952013-01-10 23:17:33362 WebContents* old_contents =
363 browser()->tab_strip_model()->GetActiveWebContents();
[email protected]78e2edc2012-07-01 23:32:28364 chrome::NavigateParams p(MakeNavigateParams());
[email protected]a1feae52010-10-11 22:14:45365 p.disposition = NEW_BACKGROUND_TAB;
[email protected]78e2edc2012-07-01 23:32:28366 chrome::Navigate(&p);
[email protected]ee496952013-01-10 23:17:33367 WebContents* new_contents =
368 browser()->tab_strip_model()->GetActiveWebContents();
[email protected]a1feae52010-10-11 22:14:45369 // The selected tab should have remained unchanged, since the new tab was
370 // opened in the background.
371 EXPECT_EQ(old_contents, new_contents);
[email protected]ee496952013-01-10 23:17:33372 EXPECT_EQ(2, browser()->tab_strip_model()->count());
[email protected]a1feae52010-10-11 22:14:45373}
374
375// This test verifies that when a navigation requiring a new foreground tab
376// occurs in a Browser that cannot host multiple tabs, the new foreground tab
377// is created in an existing compatible Browser.
378IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
379 Disposition_IncompatibleWindow_Existing) {
380 // Open a foreground tab in a window that cannot open popups when there is an
381 // existing compatible window somewhere else that they can be opened within.
382 Browser* popup = CreateEmptyBrowserForType(Browser::TYPE_POPUP,
383 browser()->profile());
[email protected]78e2edc2012-07-01 23:32:28384 chrome::NavigateParams p(MakeNavigateParams(popup));
[email protected]a1feae52010-10-11 22:14:45385 p.disposition = NEW_FOREGROUND_TAB;
[email protected]78e2edc2012-07-01 23:32:28386 chrome::Navigate(&p);
[email protected]a1feae52010-10-11 22:14:45387
388 // Navigate() should have opened the tab in a different browser since the
389 // one we supplied didn't support additional tabs.
390 EXPECT_NE(popup, p.browser);
391
392 // Since browser() is an existing compatible tabbed browser, it should have
393 // opened the tab there.
394 EXPECT_EQ(browser(), p.browser);
395
396 // We should be left with 2 windows, the popup with one tab and the browser()
397 // provided by the framework with two.
[email protected]0665ebe2013-02-13 09:53:19398 EXPECT_EQ(2u, chrome::GetTotalBrowserCount());
[email protected]ee496952013-01-10 23:17:33399 EXPECT_EQ(1, popup->tab_strip_model()->count());
400 EXPECT_EQ(2, browser()->tab_strip_model()->count());
[email protected]a1feae52010-10-11 22:14:45401}
402
403// This test verifies that when a navigation requiring a new foreground tab
404// occurs in a Browser that cannot host multiple tabs and no compatible Browser
405// that can is open, a compatible Browser is created.
406IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
407 Disposition_IncompatibleWindow_NoExisting) {
408 // We want to simulate not being able to find an existing window compatible
409 // with our non-tabbed browser window so Navigate() is forced to create a
410 // new compatible window. Because browser() supplied by the in-process
411 // browser testing framework is compatible with browser()->profile(), we
412 // need a different profile, and creating a popup window with an incognito
413 // profile is a quick and dirty way of achieving this.
414 Browser* popup = CreateEmptyBrowserForType(
[email protected]b35b26b32011-05-05 20:35:14415 Browser::TYPE_POPUP,
416 browser()->profile()->GetOffTheRecordProfile());
[email protected]78e2edc2012-07-01 23:32:28417 chrome::NavigateParams p(MakeNavigateParams(popup));
[email protected]a1feae52010-10-11 22:14:45418 p.disposition = NEW_FOREGROUND_TAB;
[email protected]78e2edc2012-07-01 23:32:28419 chrome::Navigate(&p);
[email protected]a1feae52010-10-11 22:14:45420
421 // Navigate() should have opened the tab in a different browser since the
422 // one we supplied didn't support additional tabs.
423 EXPECT_NE(popup, p.browser);
424
425 // This time, browser() is _not_ compatible with popup since it is not an
426 // incognito window.
427 EXPECT_NE(browser(), p.browser);
428
429 // We should have three windows, each with one tab:
430 // 1. the browser() provided by the framework (unchanged in this test)
431 // 2. the incognito popup we created originally
432 // 3. the new incognito tabbed browser that was created by Navigate().
[email protected]0665ebe2013-02-13 09:53:19433 EXPECT_EQ(3u, chrome::GetTotalBrowserCount());
[email protected]ee496952013-01-10 23:17:33434 EXPECT_EQ(1, browser()->tab_strip_model()->count());
435 EXPECT_EQ(1, popup->tab_strip_model()->count());
436 EXPECT_EQ(1, p.browser->tab_strip_model()->count());
[email protected]b35b26b32011-05-05 20:35:14437 EXPECT_TRUE(p.browser->is_type_tabbed());
[email protected]a1feae52010-10-11 22:14:45438}
439
440// This test verifies that navigating with WindowOpenDisposition = NEW_POPUP
441// from a normal Browser results in a new Browser with TYPE_POPUP.
442IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_NewPopup) {
[email protected]78e2edc2012-07-01 23:32:28443 chrome::NavigateParams p(MakeNavigateParams());
[email protected]a1feae52010-10-11 22:14:45444 p.disposition = NEW_POPUP;
[email protected]588300d2011-04-28 21:06:35445 p.window_bounds = gfx::Rect(0, 0, 200, 200);
[email protected]7d329992011-04-15 18:20:02446 // Wait for new popup to to load and gain focus.
[email protected]ddddfda2011-07-14 23:19:39447 ui_test_utils::NavigateToURL(&p);
[email protected]a1feae52010-10-11 22:14:45448
[email protected]7d329992011-04-15 18:20:02449 // Navigate() should have opened a new, focused popup window.
[email protected]a1feae52010-10-11 22:14:45450 EXPECT_NE(browser(), p.browser);
[email protected]50592b52013-05-02 22:26:25451#if 0
452 // TODO(stevenjb): Enable this test. See: crbug.com/79493
453 EXPECT_TRUE(p.browser->window()->IsActive());
454#endif
[email protected]b35b26b32011-05-05 20:35:14455 EXPECT_TRUE(p.browser->is_type_popup());
456 EXPECT_FALSE(p.browser->is_app());
[email protected]a1feae52010-10-11 22:14:45457
458 // We should have two windows, the browser() provided by the framework and the
459 // new popup window.
[email protected]0665ebe2013-02-13 09:53:19460 EXPECT_EQ(2u, chrome::GetTotalBrowserCount());
[email protected]ee496952013-01-10 23:17:33461 EXPECT_EQ(1, browser()->tab_strip_model()->count());
462 EXPECT_EQ(1, p.browser->tab_strip_model()->count());
[email protected]a1feae52010-10-11 22:14:45463}
464
465// This test verifies that navigating with WindowOpenDisposition = NEW_POPUP
[email protected]f112b0f2011-05-26 01:53:52466// from a normal Browser results in a new Browser with is_app() true.
467IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_NewPopup_ExtensionId) {
[email protected]78e2edc2012-07-01 23:32:28468 chrome::NavigateParams p(MakeNavigateParams());
[email protected]f112b0f2011-05-26 01:53:52469 p.disposition = NEW_POPUP;
470 p.extension_app_id = "extensionappid";
471 p.window_bounds = gfx::Rect(0, 0, 200, 200);
[email protected]f112b0f2011-05-26 01:53:52472 // Wait for new popup to to load and gain focus.
[email protected]ddddfda2011-07-14 23:19:39473 ui_test_utils::NavigateToURL(&p);
[email protected]f112b0f2011-05-26 01:53:52474
475 // Navigate() should have opened a new, focused popup window.
476 EXPECT_NE(browser(), p.browser);
477 EXPECT_TRUE(p.browser->is_type_popup());
478 EXPECT_TRUE(p.browser->is_app());
479
480 // We should have two windows, the browser() provided by the framework and the
481 // new popup window.
[email protected]0665ebe2013-02-13 09:53:19482 EXPECT_EQ(2u, chrome::GetTotalBrowserCount());
[email protected]ee496952013-01-10 23:17:33483 EXPECT_EQ(1, browser()->tab_strip_model()->count());
484 EXPECT_EQ(1, p.browser->tab_strip_model()->count());
[email protected]f112b0f2011-05-26 01:53:52485}
486
487// This test verifies that navigating with WindowOpenDisposition = NEW_POPUP
[email protected]300d1e52011-01-19 23:57:57488// from a normal popup results in a new Browser with TYPE_POPUP.
489IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_NewPopupFromPopup) {
490 // Open a popup.
[email protected]78e2edc2012-07-01 23:32:28491 chrome::NavigateParams p1(MakeNavigateParams());
[email protected]300d1e52011-01-19 23:57:57492 p1.disposition = NEW_POPUP;
[email protected]588300d2011-04-28 21:06:35493 p1.window_bounds = gfx::Rect(0, 0, 200, 200);
[email protected]78e2edc2012-07-01 23:32:28494 chrome::Navigate(&p1);
[email protected]300d1e52011-01-19 23:57:57495 // Open another popup.
[email protected]78e2edc2012-07-01 23:32:28496 chrome::NavigateParams p2(MakeNavigateParams(p1.browser));
[email protected]300d1e52011-01-19 23:57:57497 p2.disposition = NEW_POPUP;
[email protected]588300d2011-04-28 21:06:35498 p2.window_bounds = gfx::Rect(0, 0, 200, 200);
[email protected]78e2edc2012-07-01 23:32:28499 chrome::Navigate(&p2);
[email protected]300d1e52011-01-19 23:57:57500
501 // Navigate() should have opened a new normal popup window.
502 EXPECT_NE(p1.browser, p2.browser);
[email protected]b35b26b32011-05-05 20:35:14503 EXPECT_TRUE(p2.browser->is_type_popup());
504 EXPECT_FALSE(p2.browser->is_app());
[email protected]300d1e52011-01-19 23:57:57505
506 // We should have three windows, the browser() provided by the framework,
507 // the first popup window, and the second popup window.
[email protected]0665ebe2013-02-13 09:53:19508 EXPECT_EQ(3u, chrome::GetTotalBrowserCount());
[email protected]ee496952013-01-10 23:17:33509 EXPECT_EQ(1, browser()->tab_strip_model()->count());
510 EXPECT_EQ(1, p1.browser->tab_strip_model()->count());
511 EXPECT_EQ(1, p2.browser->tab_strip_model()->count());
[email protected]300d1e52011-01-19 23:57:57512}
513
514// This test verifies that navigating with WindowOpenDisposition = NEW_POPUP
[email protected]a1feae52010-10-11 22:14:45515// from an app frame results in a new Browser with TYPE_APP_POPUP.
516IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
517 Disposition_NewPopupFromAppWindow) {
[email protected]b35b26b32011-05-05 20:35:14518 Browser* app_browser = CreateEmptyBrowserForApp(Browser::TYPE_TABBED,
519 browser()->profile());
[email protected]78e2edc2012-07-01 23:32:28520 chrome::NavigateParams p(MakeNavigateParams(app_browser));
[email protected]a1feae52010-10-11 22:14:45521 p.disposition = NEW_POPUP;
[email protected]588300d2011-04-28 21:06:35522 p.window_bounds = gfx::Rect(0, 0, 200, 200);
[email protected]78e2edc2012-07-01 23:32:28523 chrome::Navigate(&p);
[email protected]a1feae52010-10-11 22:14:45524
525 // Navigate() should have opened a new popup app window.
526 EXPECT_NE(app_browser, p.browser);
527 EXPECT_NE(browser(), p.browser);
[email protected]b35b26b32011-05-05 20:35:14528 EXPECT_TRUE(p.browser->is_type_popup());
529 EXPECT_TRUE(p.browser->is_app());
[email protected]a1feae52010-10-11 22:14:45530
531 // We should now have three windows, the app window, the app popup it created,
532 // and the original browser() provided by the framework.
[email protected]0665ebe2013-02-13 09:53:19533 EXPECT_EQ(3u, chrome::GetTotalBrowserCount());
[email protected]ee496952013-01-10 23:17:33534 EXPECT_EQ(1, browser()->tab_strip_model()->count());
535 EXPECT_EQ(1, app_browser->tab_strip_model()->count());
536 EXPECT_EQ(1, p.browser->tab_strip_model()->count());
[email protected]a1feae52010-10-11 22:14:45537}
538
539// This test verifies that navigating with WindowOpenDisposition = NEW_POPUP
[email protected]300d1e52011-01-19 23:57:57540// from an app popup results in a new Browser also of TYPE_APP_POPUP.
541IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
542 Disposition_NewPopupFromAppPopup) {
[email protected]b35b26b32011-05-05 20:35:14543 Browser* app_browser = CreateEmptyBrowserForApp(Browser::TYPE_TABBED,
544 browser()->profile());
[email protected]300d1e52011-01-19 23:57:57545 // Open an app popup.
[email protected]78e2edc2012-07-01 23:32:28546 chrome::NavigateParams p1(MakeNavigateParams(app_browser));
[email protected]300d1e52011-01-19 23:57:57547 p1.disposition = NEW_POPUP;
[email protected]588300d2011-04-28 21:06:35548 p1.window_bounds = gfx::Rect(0, 0, 200, 200);
[email protected]78e2edc2012-07-01 23:32:28549 chrome::Navigate(&p1);
[email protected]300d1e52011-01-19 23:57:57550 // Now open another app popup.
[email protected]78e2edc2012-07-01 23:32:28551 chrome::NavigateParams p2(MakeNavigateParams(p1.browser));
[email protected]300d1e52011-01-19 23:57:57552 p2.disposition = NEW_POPUP;
[email protected]588300d2011-04-28 21:06:35553 p2.window_bounds = gfx::Rect(0, 0, 200, 200);
[email protected]78e2edc2012-07-01 23:32:28554 chrome::Navigate(&p2);
[email protected]300d1e52011-01-19 23:57:57555
556 // Navigate() should have opened a new popup app window.
557 EXPECT_NE(browser(), p1.browser);
558 EXPECT_NE(p1.browser, p2.browser);
[email protected]b35b26b32011-05-05 20:35:14559 EXPECT_TRUE(p2.browser->is_type_popup());
560 EXPECT_TRUE(p2.browser->is_app());
[email protected]300d1e52011-01-19 23:57:57561
562 // We should now have four windows, the app window, the first app popup,
563 // the second app popup, and the original browser() provided by the framework.
[email protected]0665ebe2013-02-13 09:53:19564 EXPECT_EQ(4u, chrome::GetTotalBrowserCount());
[email protected]ee496952013-01-10 23:17:33565 EXPECT_EQ(1, browser()->tab_strip_model()->count());
566 EXPECT_EQ(1, app_browser->tab_strip_model()->count());
567 EXPECT_EQ(1, p1.browser->tab_strip_model()->count());
568 EXPECT_EQ(1, p2.browser->tab_strip_model()->count());
[email protected]300d1e52011-01-19 23:57:57569}
570
571// This test verifies that navigating with WindowOpenDisposition = NEW_POPUP
[email protected]a1feae52010-10-11 22:14:45572// from an extension app tab results in a new Browser with TYPE_APP_POPUP.
573IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
574 Disposition_NewPopupFromExtensionApp) {
575 // TODO(beng): TBD.
576}
577
[email protected]7d329992011-04-15 18:20:02578// This test verifies that navigating with window_action = SHOW_WINDOW_INACTIVE
579// does not focus a new new popup window.
580IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_NewPopupUnfocused) {
[email protected]78e2edc2012-07-01 23:32:28581 chrome::NavigateParams p(MakeNavigateParams());
[email protected]7d329992011-04-15 18:20:02582 p.disposition = NEW_POPUP;
[email protected]588300d2011-04-28 21:06:35583 p.window_bounds = gfx::Rect(0, 0, 200, 200);
[email protected]78e2edc2012-07-01 23:32:28584 p.window_action = chrome::NavigateParams::SHOW_WINDOW_INACTIVE;
[email protected]7d329992011-04-15 18:20:02585 // Wait for new popup to load (and gain focus if the test fails).
[email protected]ddddfda2011-07-14 23:19:39586 ui_test_utils::NavigateToURL(&p);
[email protected]7d329992011-04-15 18:20:02587
588 // Navigate() should have opened a new, unfocused, popup window.
589 EXPECT_NE(browser(), p.browser);
590 EXPECT_EQ(Browser::TYPE_POPUP, p.browser->type());
[email protected]9db263a2011-04-15 20:53:47591#if 0
592// TODO(stevenjb): Enable this test. See: crbug.com/79493
[email protected]7d329992011-04-15 18:20:02593 EXPECT_FALSE(p.browser->window()->IsActive());
[email protected]7d329992011-04-15 18:20:02594#endif
[email protected]9db263a2011-04-15 20:53:47595}
[email protected]7d329992011-04-15 18:20:02596
[email protected]a1feae52010-10-11 22:14:45597// This test verifies that navigating with WindowOpenDisposition = NEW_WINDOW
598// always opens a new window.
599IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_NewWindow) {
[email protected]78e2edc2012-07-01 23:32:28600 chrome::NavigateParams p(MakeNavigateParams());
[email protected]a1feae52010-10-11 22:14:45601 p.disposition = NEW_WINDOW;
[email protected]78e2edc2012-07-01 23:32:28602 chrome::Navigate(&p);
[email protected]a1feae52010-10-11 22:14:45603
604 // Navigate() should have opened a new toplevel window.
605 EXPECT_NE(browser(), p.browser);
[email protected]b35b26b32011-05-05 20:35:14606 EXPECT_TRUE(p.browser->is_type_tabbed());
[email protected]a1feae52010-10-11 22:14:45607
608 // We should now have two windows, the browser() provided by the framework and
609 // the new normal window.
[email protected]0665ebe2013-02-13 09:53:19610 EXPECT_EQ(2u, chrome::GetTotalBrowserCount());
[email protected]ee496952013-01-10 23:17:33611 EXPECT_EQ(1, browser()->tab_strip_model()->count());
612 EXPECT_EQ(1, p.browser->tab_strip_model()->count());
[email protected]a1feae52010-10-11 22:14:45613}
614
615// This test verifies that navigating with WindowOpenDisposition = INCOGNITO
616// opens a new incognito window if no existing incognito window is present.
617IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_Incognito) {
[email protected]78e2edc2012-07-01 23:32:28618 chrome::NavigateParams p(MakeNavigateParams());
[email protected]a1feae52010-10-11 22:14:45619 p.disposition = OFF_THE_RECORD;
[email protected]78e2edc2012-07-01 23:32:28620 chrome::Navigate(&p);
[email protected]a1feae52010-10-11 22:14:45621
622 // Navigate() should have opened a new toplevel incognito window.
623 EXPECT_NE(browser(), p.browser);
624 EXPECT_EQ(browser()->profile()->GetOffTheRecordProfile(),
625 p.browser->profile());
626
[email protected]d7ff3592010-11-30 21:50:46627 // |source_contents| should be set to NULL because the profile for the new
628 // page is different from the originating page.
629 EXPECT_EQ(NULL, p.source_contents);
630
[email protected]a1feae52010-10-11 22:14:45631 // We should now have two windows, the browser() provided by the framework and
632 // the new incognito window.
[email protected]0665ebe2013-02-13 09:53:19633 EXPECT_EQ(2u, chrome::GetTotalBrowserCount());
[email protected]ee496952013-01-10 23:17:33634 EXPECT_EQ(1, browser()->tab_strip_model()->count());
635 EXPECT_EQ(1, p.browser->tab_strip_model()->count());
[email protected]a1feae52010-10-11 22:14:45636}
637
638// This test verifies that navigating with WindowOpenDisposition = INCOGNITO
639// reuses an existing incognito window when possible.
640IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_IncognitoRefocus) {
641 Browser* incognito_browser =
[email protected]b35b26b32011-05-05 20:35:14642 CreateEmptyBrowserForType(Browser::TYPE_TABBED,
[email protected]a1feae52010-10-11 22:14:45643 browser()->profile()->GetOffTheRecordProfile());
[email protected]78e2edc2012-07-01 23:32:28644 chrome::NavigateParams p(MakeNavigateParams());
[email protected]a1feae52010-10-11 22:14:45645 p.disposition = OFF_THE_RECORD;
[email protected]78e2edc2012-07-01 23:32:28646 chrome::Navigate(&p);
[email protected]a1feae52010-10-11 22:14:45647
648 // Navigate() should have opened a new tab in the existing incognito window.
649 EXPECT_NE(browser(), p.browser);
650 EXPECT_EQ(p.browser, incognito_browser);
651
652 // We should now have two windows, the browser() provided by the framework and
653 // the incognito window we opened earlier.
[email protected]0665ebe2013-02-13 09:53:19654 EXPECT_EQ(2u, chrome::GetTotalBrowserCount());
[email protected]ee496952013-01-10 23:17:33655 EXPECT_EQ(1, browser()->tab_strip_model()->count());
656 EXPECT_EQ(2, incognito_browser->tab_strip_model()->count());
[email protected]a1feae52010-10-11 22:14:45657}
658
659// This test verifies that no navigation action occurs when
660// WindowOpenDisposition = SUPPRESS_OPEN.
661IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_SuppressOpen) {
662 RunSuppressTest(SUPPRESS_OPEN);
663}
664
665// This test verifies that no navigation action occurs when
666// WindowOpenDisposition = SAVE_TO_DISK.
667IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_SaveToDisk) {
668 RunSuppressTest(SAVE_TO_DISK);
669}
670
671// This test verifies that no navigation action occurs when
672// WindowOpenDisposition = IGNORE_ACTION.
673IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_IgnoreAction) {
674 RunSuppressTest(IGNORE_ACTION);
675}
676
[email protected]e232c992012-12-06 12:43:20677// This tests adding a foreground tab with a predefined WebContents.
[email protected]a1feae52010-10-11 22:14:45678IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, TargetContents_ForegroundTab) {
[email protected]78e2edc2012-07-01 23:32:28679 chrome::NavigateParams p(MakeNavigateParams());
[email protected]a1feae52010-10-11 22:14:45680 p.disposition = NEW_FOREGROUND_TAB;
[email protected]e232c992012-12-06 12:43:20681 p.target_contents = CreateWebContents();
[email protected]78e2edc2012-07-01 23:32:28682 chrome::Navigate(&p);
[email protected]a1feae52010-10-11 22:14:45683
684 // Navigate() should have opened the contents in a new foreground in the
685 // current Browser.
686 EXPECT_EQ(browser(), p.browser);
[email protected]e232c992012-12-06 12:43:20687 EXPECT_EQ(browser()->tab_strip_model()->GetActiveWebContents(),
[email protected]59253a652012-11-20 00:17:26688 p.target_contents);
[email protected]a1feae52010-10-11 22:14:45689
690 // We should have one window, with two tabs.
[email protected]0665ebe2013-02-13 09:53:19691 EXPECT_EQ(1u, chrome::GetTotalBrowserCount());
[email protected]ee496952013-01-10 23:17:33692 EXPECT_EQ(2, browser()->tab_strip_model()->count());
[email protected]a1feae52010-10-11 22:14:45693}
694
695#if defined(OS_WIN)
[email protected]e232c992012-12-06 12:43:20696// This tests adding a popup with a predefined WebContents.
[email protected]76edb672011-03-04 21:48:39697IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, DISABLED_TargetContents_Popup) {
[email protected]78e2edc2012-07-01 23:32:28698 chrome::NavigateParams p(MakeNavigateParams());
[email protected]a1feae52010-10-11 22:14:45699 p.disposition = NEW_POPUP;
[email protected]e232c992012-12-06 12:43:20700 p.target_contents = CreateWebContents();
[email protected]a1feae52010-10-11 22:14:45701 p.window_bounds = gfx::Rect(10, 10, 500, 500);
[email protected]78e2edc2012-07-01 23:32:28702 chrome::Navigate(&p);
[email protected]a1feae52010-10-11 22:14:45703
704 // Navigate() should have opened a new popup window.
705 EXPECT_NE(browser(), p.browser);
[email protected]b35b26b32011-05-05 20:35:14706 EXPECT_TRUE(p.browser->is_type_popup());
707 EXPECT_FALSE(p.browser->is_app());
[email protected]a1feae52010-10-11 22:14:45708
709 // The web platform is weird. The window bounds specified in
710 // |p.window_bounds| are used as follows:
711 // - the origin is used to position the window
[email protected]e232c992012-12-06 12:43:20712 // - the size is used to size the WebContents of the window.
[email protected]a1feae52010-10-11 22:14:45713 // As such the position of the resulting window will always match
714 // p.window_bounds.origin(), but its size will not. We need to match
715 // the size against the selected tab's view's container size.
716 // Only Windows positions the window according to |p.window_bounds.origin()| -
717 // on Mac the window is offset from the opener and on Linux it always opens
718 // at 0,0.
719 EXPECT_EQ(p.window_bounds.origin(),
720 p.browser->window()->GetRestoredBounds().origin());
721 // All platforms should respect size however provided width > 400 (Mac has a
722 // minimum window width of 400).
723 EXPECT_EQ(p.window_bounds.size(),
[email protected]e232c992012-12-06 12:43:20724 p.target_contents->GetView()->GetContainerSize());
[email protected]a1feae52010-10-11 22:14:45725
726 // We should have two windows, the new popup and the browser() provided by the
727 // framework.
[email protected]0665ebe2013-02-13 09:53:19728 EXPECT_EQ(2u, chrome::GetTotalBrowserCount());
[email protected]ee496952013-01-10 23:17:33729 EXPECT_EQ(1, browser()->tab_strip_model()->count());
730 EXPECT_EQ(1, p.browser->tab_strip_model()->count());
[email protected]a1feae52010-10-11 22:14:45731}
732#endif
733
734// This tests adding a tab at a specific index.
735IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Tabstrip_InsertAtIndex) {
736 // This is not meant to be a comprehensive test of whether or not the tab
737 // implementation of the browser observes the insertion index. That is
738 // covered by the unit tests for TabStripModel. This merely verifies that
739 // insertion index preference is reflected in common cases.
[email protected]78e2edc2012-07-01 23:32:28740 chrome::NavigateParams p(MakeNavigateParams());
[email protected]a1feae52010-10-11 22:14:45741 p.disposition = NEW_FOREGROUND_TAB;
742 p.tabstrip_index = 0;
743 p.tabstrip_add_types = TabStripModel::ADD_FORCE_INDEX;
[email protected]78e2edc2012-07-01 23:32:28744 chrome::Navigate(&p);
[email protected]a1feae52010-10-11 22:14:45745
746 // Navigate() should have inserted a new tab at slot 0 in the tabstrip.
747 EXPECT_EQ(browser(), p.browser);
[email protected]e232c992012-12-06 12:43:20748 EXPECT_EQ(0, browser()->tab_strip_model()->GetIndexOfWebContents(
749 static_cast<const WebContents*>(p.target_contents)));
[email protected]a1feae52010-10-11 22:14:45750
751 // We should have one window - the browser() provided by the framework.
[email protected]0665ebe2013-02-13 09:53:19752 EXPECT_EQ(1u, chrome::GetTotalBrowserCount());
[email protected]ee496952013-01-10 23:17:33753 EXPECT_EQ(2, browser()->tab_strip_model()->count());
[email protected]a1feae52010-10-11 22:14:45754}
755
[email protected]bb89e7482010-11-17 18:27:04756// This test verifies that constructing params with disposition = SINGLETON_TAB
[email protected]fee320542011-03-02 01:30:49757// and IGNORE_AND_NAVIGATE opens a new tab navigated to the specified URL if
[email protected]67ed83e2011-01-07 22:54:00758// no previous tab with that URL (minus the path) exists.
[email protected]bb89e7482010-11-17 18:27:04759IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
760 Disposition_SingletonTabNew_IgnorePath) {
[email protected]52877dbc62012-06-29 22:22:03761 chrome::AddSelectedTabWithURL(browser(), GetGoogleURL(),
762 content::PAGE_TRANSITION_LINK);
[email protected]bb89e7482010-11-17 18:27:04763
764 // We should have one browser with 2 tabs, the 2nd selected.
[email protected]0665ebe2013-02-13 09:53:19765 EXPECT_EQ(1u, chrome::GetTotalBrowserCount());
[email protected]ee496952013-01-10 23:17:33766 EXPECT_EQ(2, browser()->tab_strip_model()->count());
767 EXPECT_EQ(1, browser()->tab_strip_model()->active_index());
[email protected]bb89e7482010-11-17 18:27:04768
769 // Navigate to a new singleton tab with a sub-page.
[email protected]78e2edc2012-07-01 23:32:28770 chrome::NavigateParams p(MakeNavigateParams());
[email protected]bb89e7482010-11-17 18:27:04771 p.disposition = SINGLETON_TAB;
[email protected]a048ad22012-03-23 04:26:56772 p.url = GetContentSettingsURL();
[email protected]50592b52013-05-02 22:26:25773 p.window_action = chrome::NavigateParams::SHOW_WINDOW;
[email protected]78e2edc2012-07-01 23:32:28774 p.path_behavior = chrome::NavigateParams::IGNORE_AND_NAVIGATE;
775 chrome::Navigate(&p);
[email protected]bb89e7482010-11-17 18:27:04776
777 // The last tab should now be selected and navigated to the sub-page of the
[email protected]50592b52013-05-02 22:26:25778 // URL.
[email protected]bb89e7482010-11-17 18:27:04779 EXPECT_EQ(browser(), p.browser);
[email protected]ee496952013-01-10 23:17:33780 EXPECT_EQ(3, browser()->tab_strip_model()->count());
781 EXPECT_EQ(2, browser()->tab_strip_model()->active_index());
[email protected]a048ad22012-03-23 04:26:56782 EXPECT_EQ(GetContentSettingsURL(),
[email protected]ee496952013-01-10 23:17:33783 ShortenUberURL(browser()->tab_strip_model()->
784 GetActiveWebContents()->GetURL()));
[email protected]bb89e7482010-11-17 18:27:04785}
786
787// This test verifies that constructing params with disposition = SINGLETON_TAB
[email protected]fee320542011-03-02 01:30:49788// and IGNORE_AND_NAVIGATE opens an existing tab with the matching URL (minus
[email protected]bb89e7482010-11-17 18:27:04789// the path) which is navigated to the specified URL.
790IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
791 Disposition_SingletonTabExisting_IgnorePath) {
[email protected]ddddfda2011-07-14 23:19:39792 GURL singleton_url1(GetSettingsURL());
[email protected]52877dbc62012-06-29 22:22:03793 chrome::AddSelectedTabWithURL(browser(), singleton_url1,
794 content::PAGE_TRANSITION_LINK);
795 chrome::AddSelectedTabWithURL(browser(), GetGoogleURL(),
796 content::PAGE_TRANSITION_LINK);
[email protected]bb89e7482010-11-17 18:27:04797
798 // We should have one browser with 3 tabs, the 3rd selected.
[email protected]0665ebe2013-02-13 09:53:19799 EXPECT_EQ(1u, chrome::GetTotalBrowserCount());
[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]bb89e7482010-11-17 18:27:04802
803 // Navigate to singleton_url1.
[email protected]78e2edc2012-07-01 23:32:28804 chrome::NavigateParams p(MakeNavigateParams());
[email protected]bb89e7482010-11-17 18:27:04805 p.disposition = SINGLETON_TAB;
[email protected]a048ad22012-03-23 04:26:56806 p.url = GetContentSettingsURL();
[email protected]50592b52013-05-02 22:26:25807 p.window_action = chrome::NavigateParams::SHOW_WINDOW;
[email protected]78e2edc2012-07-01 23:32:28808 p.path_behavior = chrome::NavigateParams::IGNORE_AND_NAVIGATE;
809 chrome::Navigate(&p);
[email protected]bb89e7482010-11-17 18:27:04810
811 // The middle tab should now be selected and navigated to the sub-page of the
812 // URL.
813 EXPECT_EQ(browser(), p.browser);
[email protected]ee496952013-01-10 23:17:33814 EXPECT_EQ(3, browser()->tab_strip_model()->count());
815 EXPECT_EQ(1, browser()->tab_strip_model()->active_index());
[email protected]a048ad22012-03-23 04:26:56816 EXPECT_EQ(GetContentSettingsURL(),
[email protected]ee496952013-01-10 23:17:33817 ShortenUberURL(browser()->tab_strip_model()->
818 GetActiveWebContents()->GetURL()));
[email protected]bb89e7482010-11-17 18:27:04819}
820
821// This test verifies that constructing params with disposition = SINGLETON_TAB
[email protected]fee320542011-03-02 01:30:49822// and IGNORE_AND_NAVIGATE opens an existing tab with the matching URL (minus
[email protected]bb89e7482010-11-17 18:27:04823// the path) which is navigated to the specified URL.
824IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
825 Disposition_SingletonTabExistingSubPath_IgnorePath) {
[email protected]a048ad22012-03-23 04:26:56826 GURL singleton_url1(GetContentSettingsURL());
[email protected]52877dbc62012-06-29 22:22:03827 chrome::AddSelectedTabWithURL(browser(), singleton_url1,
828 content::PAGE_TRANSITION_LINK);
829 chrome::AddSelectedTabWithURL(browser(), GetGoogleURL(),
830 content::PAGE_TRANSITION_LINK);
[email protected]bb89e7482010-11-17 18:27:04831
832 // We should have one browser with 3 tabs, the 3rd selected.
[email protected]0665ebe2013-02-13 09:53:19833 EXPECT_EQ(1u, chrome::GetTotalBrowserCount());
[email protected]ee496952013-01-10 23:17:33834 EXPECT_EQ(3, browser()->tab_strip_model()->count());
835 EXPECT_EQ(2, browser()->tab_strip_model()->active_index());
[email protected]bb89e7482010-11-17 18:27:04836
837 // Navigate to singleton_url1.
[email protected]78e2edc2012-07-01 23:32:28838 chrome::NavigateParams p(MakeNavigateParams());
[email protected]bb89e7482010-11-17 18:27:04839 p.disposition = SINGLETON_TAB;
[email protected]a048ad22012-03-23 04:26:56840 p.url = GetClearBrowsingDataURL();
[email protected]50592b52013-05-02 22:26:25841 p.window_action = chrome::NavigateParams::SHOW_WINDOW;
[email protected]78e2edc2012-07-01 23:32:28842 p.path_behavior = chrome::NavigateParams::IGNORE_AND_NAVIGATE;
843 chrome::Navigate(&p);
[email protected]bb89e7482010-11-17 18:27:04844
845 // The middle tab should now be selected and navigated to the sub-page of the
846 // URL.
847 EXPECT_EQ(browser(), p.browser);
[email protected]ee496952013-01-10 23:17:33848 EXPECT_EQ(3, browser()->tab_strip_model()->count());
849 EXPECT_EQ(1, browser()->tab_strip_model()->active_index());
[email protected]a048ad22012-03-23 04:26:56850 EXPECT_EQ(GetClearBrowsingDataURL(),
[email protected]ee496952013-01-10 23:17:33851 ShortenUberURL(browser()->tab_strip_model()->
852 GetActiveWebContents()->GetURL()));
[email protected]bb89e7482010-11-17 18:27:04853}
[email protected]2dd85482010-11-06 01:56:47854
[email protected]637b3442011-01-10 23:31:48855// This test verifies that constructing params with disposition = SINGLETON_TAB
[email protected]fee320542011-03-02 01:30:49856// and IGNORE_AND_STAY_PUT opens an existing tab with the matching URL (minus
857// the path).
858IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
859 Disposition_SingletonTabExistingSubPath_IgnorePath2) {
[email protected]a048ad22012-03-23 04:26:56860 GURL singleton_url1(GetContentSettingsURL());
[email protected]52877dbc62012-06-29 22:22:03861 chrome::AddSelectedTabWithURL(browser(), singleton_url1,
862 content::PAGE_TRANSITION_LINK);
863 chrome::AddSelectedTabWithURL(browser(), GetGoogleURL(),
864 content::PAGE_TRANSITION_LINK);
[email protected]fee320542011-03-02 01:30:49865
866 // We should have one browser with 3 tabs, the 3rd selected.
[email protected]0665ebe2013-02-13 09:53:19867 EXPECT_EQ(1u, chrome::GetTotalBrowserCount());
[email protected]ee496952013-01-10 23:17:33868 EXPECT_EQ(3, browser()->tab_strip_model()->count());
869 EXPECT_EQ(2, browser()->tab_strip_model()->active_index());
[email protected]fee320542011-03-02 01:30:49870
871 // Navigate to singleton_url1.
[email protected]78e2edc2012-07-01 23:32:28872 chrome::NavigateParams p(MakeNavigateParams());
[email protected]fee320542011-03-02 01:30:49873 p.disposition = SINGLETON_TAB;
[email protected]a048ad22012-03-23 04:26:56874 p.url = GetClearBrowsingDataURL();
[email protected]50592b52013-05-02 22:26:25875 p.window_action = chrome::NavigateParams::SHOW_WINDOW;
[email protected]78e2edc2012-07-01 23:32:28876 p.path_behavior = chrome::NavigateParams::IGNORE_AND_STAY_PUT;
877 chrome::Navigate(&p);
[email protected]fee320542011-03-02 01:30:49878
879 // The middle tab should now be selected.
880 EXPECT_EQ(browser(), p.browser);
[email protected]ee496952013-01-10 23:17:33881 EXPECT_EQ(3, browser()->tab_strip_model()->count());
882 EXPECT_EQ(1, browser()->tab_strip_model()->active_index());
[email protected]fee320542011-03-02 01:30:49883 EXPECT_EQ(singleton_url1,
[email protected]ee496952013-01-10 23:17:33884 ShortenUberURL(browser()->tab_strip_model()->
885 GetActiveWebContents()->GetURL()));
[email protected]fee320542011-03-02 01:30:49886}
887
888// This test verifies that constructing params with disposition = SINGLETON_TAB
889// and IGNORE_AND_NAVIGATE will update the current tab's URL if the currently
[email protected]637b3442011-01-10 23:31:48890// selected tab is a match but has a different path.
891IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
892 Disposition_SingletonTabFocused_IgnorePath) {
[email protected]a048ad22012-03-23 04:26:56893 GURL singleton_url_current(GetContentSettingsURL());
[email protected]52877dbc62012-06-29 22:22:03894 chrome::AddSelectedTabWithURL(browser(), singleton_url_current,
895 content::PAGE_TRANSITION_LINK);
[email protected]637b3442011-01-10 23:31:48896
897 // We should have one browser with 2 tabs, the 2nd selected.
[email protected]0665ebe2013-02-13 09:53:19898 EXPECT_EQ(1u, chrome::GetTotalBrowserCount());
[email protected]ee496952013-01-10 23:17:33899 EXPECT_EQ(2, browser()->tab_strip_model()->count());
900 EXPECT_EQ(1, browser()->tab_strip_model()->active_index());
[email protected]637b3442011-01-10 23:31:48901
902 // Navigate to a different settings path.
[email protected]a048ad22012-03-23 04:26:56903 GURL singleton_url_target(GetClearBrowsingDataURL());
[email protected]78e2edc2012-07-01 23:32:28904 chrome::NavigateParams p(MakeNavigateParams());
[email protected]637b3442011-01-10 23:31:48905 p.disposition = SINGLETON_TAB;
906 p.url = singleton_url_target;
[email protected]50592b52013-05-02 22:26:25907 p.window_action = chrome::NavigateParams::SHOW_WINDOW;
[email protected]78e2edc2012-07-01 23:32:28908 p.path_behavior = chrome::NavigateParams::IGNORE_AND_NAVIGATE;
909 chrome::Navigate(&p);
[email protected]637b3442011-01-10 23:31:48910
911 // The second tab should still be selected, but navigated to the new path.
912 EXPECT_EQ(browser(), p.browser);
[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 EXPECT_EQ(singleton_url_target,
[email protected]ee496952013-01-10 23:17:33916 ShortenUberURL(browser()->tab_strip_model()->
917 GetActiveWebContents()->GetURL()));
[email protected]637b3442011-01-10 23:31:48918}
919
[email protected]07afd7c2011-02-17 10:07:11920// This test verifies that constructing params with disposition = SINGLETON_TAB
[email protected]fee320542011-03-02 01:30:49921// and IGNORE_AND_NAVIGATE will open an existing matching tab with a different
922// query.
[email protected]07afd7c2011-02-17 10:07:11923IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
924 Disposition_SingletonTabExisting_IgnoreQuery) {
[email protected]ee496952013-01-10 23:17:33925 int initial_tab_count = browser()->tab_strip_model()->count();
[email protected]07afd7c2011-02-17 10:07:11926 GURL singleton_url_current("chrome://settings/internet");
[email protected]52877dbc62012-06-29 22:22:03927 chrome::AddSelectedTabWithURL(browser(), singleton_url_current,
928 content::PAGE_TRANSITION_LINK);
[email protected]07afd7c2011-02-17 10:07:11929
[email protected]ee496952013-01-10 23:17:33930 EXPECT_EQ(initial_tab_count + 1, browser()->tab_strip_model()->count());
931 EXPECT_EQ(initial_tab_count, browser()->tab_strip_model()->active_index());
[email protected]07afd7c2011-02-17 10:07:11932
933 // Navigate to a different settings path.
934 GURL singleton_url_target(
935 "chrome://settings/internet?"
936 "servicePath=/profile/ethernet_00aa00aa00aa&networkType=1");
[email protected]78e2edc2012-07-01 23:32:28937 chrome::NavigateParams p(MakeNavigateParams());
[email protected]07afd7c2011-02-17 10:07:11938 p.disposition = SINGLETON_TAB;
939 p.url = singleton_url_target;
[email protected]50592b52013-05-02 22:26:25940 p.window_action = chrome::NavigateParams::SHOW_WINDOW;
[email protected]78e2edc2012-07-01 23:32:28941 p.path_behavior = chrome::NavigateParams::IGNORE_AND_NAVIGATE;
942 chrome::Navigate(&p);
[email protected]07afd7c2011-02-17 10:07:11943
944 // Last tab should still be selected.
945 EXPECT_EQ(browser(), p.browser);
[email protected]ee496952013-01-10 23:17:33946 EXPECT_EQ(initial_tab_count + 1, browser()->tab_strip_model()->count());
947 EXPECT_EQ(initial_tab_count, browser()->tab_strip_model()->active_index());
[email protected]07afd7c2011-02-17 10:07:11948}
949
[email protected]bd817c22011-02-09 08:16:46950// This test verifies that the settings page isn't opened in the incognito
951// window.
[email protected]a048ad22012-03-23 04:26:56952// Disabled until fixed for uber settings: http://crbug.com/111243
[email protected]bd817c22011-02-09 08:16:46953IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
[email protected]a048ad22012-03-23 04:26:56954 DISABLED_Disposition_Settings_UseNonIncognitoWindow) {
[email protected]fc0ed302011-11-29 23:17:19955 RunUseNonIncognitoWindowTest(GetSettingsURL());
[email protected]bd817c22011-02-09 08:16:46956}
957
[email protected]429e9712013-04-30 09:35:50958// This test verifies that the view-source settings page isn't opened in the
959// incognito window.
960IN_PROC_BROWSER_TEST_F(
961 BrowserNavigatorTest,
962 Disposition_ViewSource_Settings_DoNothingIfIncognitoForced) {
[email protected]dbdda5402013-05-30 22:13:48963 std::string view_source(content::kViewSourceScheme);
[email protected]429e9712013-04-30 09:35:50964 view_source.append(":");
965 view_source.append(chrome::kChromeUISettingsURL);
966 RunDoNothingIfIncognitoIsForcedTest(GURL(view_source));
967}
968
969// This test verifies that the view-source settings page isn't opened in the
970// incognito window even if incognito mode is forced (does nothing in that
971// case).
972IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
973 Disposition_ViewSource_Settings_UseNonIncognitoWindow) {
[email protected]dbdda5402013-05-30 22:13:48974 std::string view_source(content::kViewSourceScheme);
[email protected]429e9712013-04-30 09:35:50975 view_source.append(":");
976 view_source.append(chrome::kChromeUISettingsURL);
977 RunUseNonIncognitoWindowTest(GURL(view_source));
978}
979
[email protected]82404cd2011-07-12 19:55:14980// This test verifies that the settings page isn't opened in the incognito
981// window from a non-incognito window (bookmark open-in-incognito trigger).
[email protected]a048ad22012-03-23 04:26:56982// Disabled until fixed for uber settings: http://crbug.com/111243
[email protected]82404cd2011-07-12 19:55:14983IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
[email protected]a048ad22012-03-23 04:26:56984 DISABLED_Disposition_Settings_UseNonIncognitoWindowForBookmark) {
[email protected]78e2edc2012-07-01 23:32:28985 chrome::NavigateParams params(browser(), GetSettingsURL(),
986 content::PAGE_TRANSITION_AUTO_BOOKMARK);
[email protected]82404cd2011-07-12 19:55:14987 params.disposition = OFF_THE_RECORD;
988 {
[email protected]a7fe9112012-07-20 02:34:45989 content::WindowedNotificationObserver observer(
[email protected]ad50def52011-10-19 23:17:07990 content::NOTIFICATION_LOAD_STOP,
991 content::NotificationService::AllSources());
[email protected]78e2edc2012-07-01 23:32:28992 chrome::Navigate(&params);
[email protected]82404cd2011-07-12 19:55:14993 observer.Wait();
994 }
995
[email protected]0665ebe2013-02-13 09:53:19996 EXPECT_EQ(1u, chrome::GetTotalBrowserCount());
[email protected]52877dbc62012-06-29 22:22:03997 EXPECT_EQ(GetSettingsURL(),
[email protected]ee496952013-01-10 23:17:33998 ShortenUberURL(browser()->tab_strip_model()->
999 GetActiveWebContents()->GetURL()));
[email protected]82404cd2011-07-12 19:55:141000}
1001
[email protected]93ad8e1c2011-11-08 21:34:051002// Settings page is expected to always open in normal mode regardless
1003// of whether the user is trying to open it in incognito mode or not.
1004// This test verifies that if incognito mode is forced (by policy), settings
1005// page doesn't open at all.
[email protected]a048ad22012-03-23 04:26:561006// Disabled until fixed for uber settings: http://crbug.com/111243
[email protected]93ad8e1c2011-11-08 21:34:051007IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
[email protected]a048ad22012-03-23 04:26:561008 DISABLED_Disposition_Settings_DoNothingIfIncognitoIsForced) {
[email protected]fc0ed302011-11-29 23:17:191009 RunDoNothingIfIncognitoIsForcedTest(GetSettingsURL());
[email protected]93ad8e1c2011-11-08 21:34:051010}
1011
[email protected]bd817c22011-02-09 08:16:461012// This test verifies that the bookmarks page isn't opened in the incognito
1013// window.
1014IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
1015 Disposition_Bookmarks_UseNonIncognitoWindow) {
[email protected]fc0ed302011-11-29 23:17:191016 RunUseNonIncognitoWindowTest(GURL(chrome::kChromeUIBookmarksURL));
[email protected]bd817c22011-02-09 08:16:461017}
1018
[email protected]93ad8e1c2011-11-08 21:34:051019// Bookmark manager is expected to always open in normal mode regardless
1020// of whether the user is trying to open it in incognito mode or not.
1021// This test verifies that if incognito mode is forced (by policy), bookmark
1022// manager doesn't open at all.
1023IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
1024 Disposition_Bookmarks_DoNothingIfIncognitoIsForced) {
[email protected]fc0ed302011-11-29 23:17:191025 RunDoNothingIfIncognitoIsForcedTest(GURL(chrome::kChromeUIBookmarksURL));
1026}
[email protected]93ad8e1c2011-11-08 21:34:051027
[email protected]7de53c62011-05-13 06:44:161028// This test makes sure a crashed singleton tab reloads from a new navigation.
1029IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
1030 NavigateToCrashedSingletonTab) {
[email protected]a048ad22012-03-23 04:26:561031 GURL singleton_url(GetContentSettingsURL());
[email protected]5a1a52462012-11-15 03:35:161032 WebContents* web_contents = chrome::AddSelectedTabWithURL(
[email protected]52877dbc62012-06-29 22:22:031033 browser(), singleton_url, content::PAGE_TRANSITION_LINK);
[email protected]7de53c62011-05-13 06:44:161034
1035 // We should have one browser with 2 tabs, the 2nd selected.
[email protected]0665ebe2013-02-13 09:53:191036 EXPECT_EQ(1u, chrome::GetTotalBrowserCount());
[email protected]ee496952013-01-10 23:17:331037 EXPECT_EQ(2, browser()->tab_strip_model()->count());
1038 EXPECT_EQ(1, browser()->tab_strip_model()->active_index());
[email protected]7de53c62011-05-13 06:44:161039
1040 // Kill the singleton tab.
[email protected]83ff91c2012-01-05 20:54:131041 web_contents->SetIsCrashed(base::TERMINATION_STATUS_PROCESS_CRASHED, -1);
1042 EXPECT_TRUE(web_contents->IsCrashed());
[email protected]7de53c62011-05-13 06:44:161043
[email protected]78e2edc2012-07-01 23:32:281044 chrome::NavigateParams p(MakeNavigateParams());
[email protected]7de53c62011-05-13 06:44:161045 p.disposition = SINGLETON_TAB;
1046 p.url = singleton_url;
[email protected]50592b52013-05-02 22:26:251047 p.window_action = chrome::NavigateParams::SHOW_WINDOW;
[email protected]78e2edc2012-07-01 23:32:281048 p.path_behavior = chrome::NavigateParams::IGNORE_AND_NAVIGATE;
[email protected]ddddfda2011-07-14 23:19:391049 ui_test_utils::NavigateToURL(&p);
[email protected]7de53c62011-05-13 06:44:161050
1051 // The tab should not be sad anymore.
[email protected]83ff91c2012-01-05 20:54:131052 EXPECT_FALSE(web_contents->IsCrashed());
[email protected]7de53c62011-05-13 06:44:161053}
1054
[email protected]fcca741b2011-06-17 22:46:371055IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
1056 NavigateFromDefaultToOptionsInSameTab) {
[email protected]ddddfda2011-07-14 23:19:391057 {
[email protected]a7fe9112012-07-20 02:34:451058 content::WindowedNotificationObserver observer(
[email protected]ad50def52011-10-19 23:17:071059 content::NOTIFICATION_LOAD_STOP,
1060 content::NotificationService::AllSources());
[email protected]5d9cace72012-06-21 16:07:121061 chrome::ShowSettings(browser());
[email protected]ddddfda2011-07-14 23:19:391062 observer.Wait();
1063 }
[email protected]ee496952013-01-10 23:17:331064 EXPECT_EQ(1, browser()->tab_strip_model()->count());
[email protected]52877dbc62012-06-29 22:22:031065 EXPECT_EQ(GetSettingsURL(),
[email protected]ee496952013-01-10 23:17:331066 ShortenUberURL(browser()->tab_strip_model()->
1067 GetActiveWebContents()->GetURL()));
[email protected]fcca741b2011-06-17 22:46:371068}
1069
1070IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
1071 NavigateFromBlankToOptionsInSameTab) {
[email protected]78e2edc2012-07-01 23:32:281072 chrome::NavigateParams p(MakeNavigateParams());
[email protected]081dc522013-05-15 04:59:201073 p.url = GURL(content::kAboutBlankURL);
[email protected]ddddfda2011-07-14 23:19:391074 ui_test_utils::NavigateToURL(&p);
[email protected]fcca741b2011-06-17 22:46:371075
[email protected]ddddfda2011-07-14 23:19:391076 {
[email protected]a7fe9112012-07-20 02:34:451077 content::WindowedNotificationObserver observer(
[email protected]ad50def52011-10-19 23:17:071078 content::NOTIFICATION_LOAD_STOP,
1079 content::NotificationService::AllSources());
[email protected]5d9cace72012-06-21 16:07:121080 chrome::ShowSettings(browser());
[email protected]ddddfda2011-07-14 23:19:391081 observer.Wait();
1082 }
[email protected]ee496952013-01-10 23:17:331083 EXPECT_EQ(1, browser()->tab_strip_model()->count());
[email protected]52877dbc62012-06-29 22:22:031084 EXPECT_EQ(GetSettingsURL(),
[email protected]ee496952013-01-10 23:17:331085 ShortenUberURL(browser()->tab_strip_model()->
1086 GetActiveWebContents()->GetURL()));
[email protected]fcca741b2011-06-17 22:46:371087}
1088
1089IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
1090 NavigateFromNTPToOptionsInSameTab) {
[email protected]78e2edc2012-07-01 23:32:281091 chrome::NavigateParams p(MakeNavigateParams());
[email protected]ddddfda2011-07-14 23:19:391092 p.url = GURL(chrome::kChromeUINewTabURL);
1093 ui_test_utils::NavigateToURL(&p);
[email protected]ee496952013-01-10 23:17:331094 EXPECT_EQ(1, browser()->tab_strip_model()->count());
[email protected]27658f32013-11-14 03:20:371095 EXPECT_EQ(GURL(chrome::kChromeUINewTabURL),
1096 browser()->tab_strip_model()->GetActiveWebContents()->GetURL());
[email protected]fcca741b2011-06-17 22:46:371097
[email protected]ddddfda2011-07-14 23:19:391098 {
[email protected]a7fe9112012-07-20 02:34:451099 content::WindowedNotificationObserver observer(
[email protected]ad50def52011-10-19 23:17:071100 content::NOTIFICATION_LOAD_STOP,
1101 content::NotificationService::AllSources());
[email protected]5d9cace72012-06-21 16:07:121102 chrome::ShowSettings(browser());
[email protected]ddddfda2011-07-14 23:19:391103 observer.Wait();
1104 }
[email protected]ee496952013-01-10 23:17:331105 EXPECT_EQ(1, browser()->tab_strip_model()->count());
[email protected]52877dbc62012-06-29 22:22:031106 EXPECT_EQ(GetSettingsURL(),
[email protected]ee496952013-01-10 23:17:331107 ShortenUberURL(browser()->tab_strip_model()->
1108 GetActiveWebContents()->GetURL()));
[email protected]fcca741b2011-06-17 22:46:371109}
1110
1111IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
1112 NavigateFromPageToOptionsInNewTab) {
[email protected]78e2edc2012-07-01 23:32:281113 chrome::NavigateParams p(MakeNavigateParams());
[email protected]ddddfda2011-07-14 23:19:391114 ui_test_utils::NavigateToURL(&p);
[email protected]ee496952013-01-10 23:17:331115 EXPECT_EQ(GetGoogleURL(),
1116 browser()->tab_strip_model()->GetActiveWebContents()->GetURL());
[email protected]0665ebe2013-02-13 09:53:191117 EXPECT_EQ(1u, chrome::GetTotalBrowserCount());
[email protected]ee496952013-01-10 23:17:331118 EXPECT_EQ(1, browser()->tab_strip_model()->count());
[email protected]fcca741b2011-06-17 22:46:371119
[email protected]ddddfda2011-07-14 23:19:391120 {
[email protected]a7fe9112012-07-20 02:34:451121 content::WindowedNotificationObserver observer(
[email protected]ad50def52011-10-19 23:17:071122 content::NOTIFICATION_LOAD_STOP,
1123 content::NotificationService::AllSources());
[email protected]5d9cace72012-06-21 16:07:121124 chrome::ShowSettings(browser());
[email protected]ddddfda2011-07-14 23:19:391125 observer.Wait();
1126 }
[email protected]ee496952013-01-10 23:17:331127 EXPECT_EQ(2, browser()->tab_strip_model()->count());
[email protected]52877dbc62012-06-29 22:22:031128 EXPECT_EQ(GetSettingsURL(),
[email protected]ee496952013-01-10 23:17:331129 ShortenUberURL(browser()->tab_strip_model()->
1130 GetActiveWebContents()->GetURL()));
[email protected]fcca741b2011-06-17 22:46:371131}
1132
1133IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
1134 NavigateFromNTPToOptionsSingleton) {
[email protected]ddddfda2011-07-14 23:19:391135 {
[email protected]a7fe9112012-07-20 02:34:451136 content::WindowedNotificationObserver observer(
[email protected]ad50def52011-10-19 23:17:071137 content::NOTIFICATION_LOAD_STOP,
1138 content::NotificationService::AllSources());
[email protected]5d9cace72012-06-21 16:07:121139 chrome::ShowSettings(browser());
[email protected]ddddfda2011-07-14 23:19:391140 observer.Wait();
1141 }
[email protected]ee496952013-01-10 23:17:331142 EXPECT_EQ(1, browser()->tab_strip_model()->count());
[email protected]fcca741b2011-06-17 22:46:371143
[email protected]a37d4b02012-06-25 21:56:101144 chrome::NewTab(browser());
[email protected]ee496952013-01-10 23:17:331145 EXPECT_EQ(2, browser()->tab_strip_model()->count());
[email protected]fcca741b2011-06-17 22:46:371146
[email protected]ddddfda2011-07-14 23:19:391147 {
[email protected]a7fe9112012-07-20 02:34:451148 content::WindowedNotificationObserver observer(
[email protected]ad50def52011-10-19 23:17:071149 content::NOTIFICATION_LOAD_STOP,
1150 content::NotificationService::AllSources());
[email protected]5d9cace72012-06-21 16:07:121151 chrome::ShowSettings(browser());
[email protected]ddddfda2011-07-14 23:19:391152 observer.Wait();
1153 }
[email protected]ee496952013-01-10 23:17:331154 EXPECT_EQ(2, browser()->tab_strip_model()->count());
[email protected]52877dbc62012-06-29 22:22:031155 EXPECT_EQ(GetSettingsURL(),
[email protected]ee496952013-01-10 23:17:331156 ShortenUberURL(browser()->tab_strip_model()->
1157 GetActiveWebContents()->GetURL()));
[email protected]fcca741b2011-06-17 22:46:371158}
1159
1160IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
1161 NavigateFromNTPToOptionsPageInSameTab) {
[email protected]ddddfda2011-07-14 23:19:391162 {
[email protected]a7fe9112012-07-20 02:34:451163 content::WindowedNotificationObserver observer(
[email protected]ad50def52011-10-19 23:17:071164 content::NOTIFICATION_LOAD_STOP,
1165 content::NotificationService::AllSources());
[email protected]5d9cace72012-06-21 16:07:121166 chrome::ShowClearBrowsingDataDialog(browser());
[email protected]ddddfda2011-07-14 23:19:391167 observer.Wait();
1168 }
[email protected]ee496952013-01-10 23:17:331169 EXPECT_EQ(1, browser()->tab_strip_model()->count());
[email protected]a048ad22012-03-23 04:26:561170 EXPECT_EQ(GetClearBrowsingDataURL(),
[email protected]ee496952013-01-10 23:17:331171 browser()->tab_strip_model()->GetActiveWebContents()->GetURL());
[email protected]fcca741b2011-06-17 22:46:371172
[email protected]a37d4b02012-06-25 21:56:101173 chrome::NewTab(browser());
[email protected]ee496952013-01-10 23:17:331174 EXPECT_EQ(2, browser()->tab_strip_model()->count());
[email protected]fcca741b2011-06-17 22:46:371175
[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(2, 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}
1187
[email protected]fcca741b2011-06-17 22:46:371188IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
[email protected]05912742013-03-12 00:29:151189 NavigateFromOtherTabToSingletonOptions) {
[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::ShowSettings(browser());
[email protected]ddddfda2011-07-14 23:19:391195 observer.Wait();
1196 }
1197 {
[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]52877dbc62012-06-29 22:22:031201 chrome::AddSelectedTabWithURL(browser(), GetGoogleURL(),
1202 content::PAGE_TRANSITION_LINK);
[email protected]ddddfda2011-07-14 23:19:391203 observer.Wait();
1204 }
[email protected]fcca741b2011-06-17 22:46:371205
[email protected]05912742013-03-12 00:29:151206 // This load should simply cause a tab switch.
1207 chrome::ShowSettings(browser());
1208
[email protected]ee496952013-01-10 23:17:331209 EXPECT_EQ(2, browser()->tab_strip_model()->count());
[email protected]ddddfda2011-07-14 23:19:391210 EXPECT_EQ(GetSettingsURL(),
[email protected]ee496952013-01-10 23:17:331211 ShortenUberURL(browser()->tab_strip_model()->
1212 GetActiveWebContents()->GetURL()));
[email protected]fcca741b2011-06-17 22:46:371213}
1214
[email protected]4e78b2d2013-06-12 16:46:171215IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, CloseSingletonTab) {
[email protected]79717cf2013-02-28 18:40:361216 for (int i = 0; i < 2; ++i) {
1217 content::WindowedNotificationObserver observer(
1218 content::NOTIFICATION_LOAD_STOP,
1219 content::NotificationService::AllSources());
1220 chrome::AddSelectedTabWithURL(browser(), GetGoogleURL(),
1221 content::PAGE_TRANSITION_TYPED);
1222 observer.Wait();
1223 }
1224
1225 browser()->tab_strip_model()->ActivateTabAt(0, true);
1226
1227 {
1228 content::WindowedNotificationObserver observer(
1229 content::NOTIFICATION_LOAD_STOP,
1230 content::NotificationService::AllSources());
1231 chrome::ShowSettings(browser());
1232 observer.Wait();
1233 }
1234
1235 EXPECT_TRUE(browser()->tab_strip_model()->CloseWebContentsAt(
1236 2, TabStripModel::CLOSE_USER_GESTURE));
1237 EXPECT_EQ(0, browser()->tab_strip_model()->active_index());
1238}
1239
[email protected]a048ad22012-03-23 04:26:561240// TODO(csilv): Update this for uber page. http://crbug.com/111579.
[email protected]ddddfda2011-07-14 23:19:391241IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
[email protected]a048ad22012-03-23 04:26:561242 DISABLED_NavigateFromDefaultToHistoryInSameTab) {
[email protected]ddddfda2011-07-14 23:19:391243 {
[email protected]a7fe9112012-07-20 02:34:451244 content::WindowedNotificationObserver observer(
[email protected]ad50def52011-10-19 23:17:071245 content::NOTIFICATION_LOAD_STOP,
1246 content::NotificationService::AllSources());
[email protected]5d9cace72012-06-21 16:07:121247 chrome::ShowHistory(browser());
[email protected]ddddfda2011-07-14 23:19:391248 observer.Wait();
1249 }
[email protected]ee496952013-01-10 23:17:331250 EXPECT_EQ(1, browser()->tab_strip_model()->count());
[email protected]11e03fb2012-03-03 19:07:051251 EXPECT_EQ(GURL(chrome::kChromeUIHistoryFrameURL),
[email protected]ee496952013-01-10 23:17:331252 browser()->tab_strip_model()->GetActiveWebContents()->GetURL());
[email protected]ddddfda2011-07-14 23:19:391253}
1254
[email protected]953c2132013-02-23 05:56:051255// TODO(linux_aura) http://crbug.com/163931
1256#if defined(OS_LINUX) && !defined(OS_CHROMEOS) && defined(USE_AURA)
1257#define MAYBE_NavigateFromDefaultToBookmarksInSameTab DISABLED_NavigateFromDefaultToBookmarksInSameTab
1258#else
1259#define MAYBE_NavigateFromDefaultToBookmarksInSameTab NavigateFromDefaultToBookmarksInSameTab
1260#endif
[email protected]ddddfda2011-07-14 23:19:391261IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
[email protected]953c2132013-02-23 05:56:051262 MAYBE_NavigateFromDefaultToBookmarksInSameTab) {
[email protected]ddddfda2011-07-14 23:19:391263 {
[email protected]a7fe9112012-07-20 02:34:451264 content::WindowedNotificationObserver observer(
[email protected]ad50def52011-10-19 23:17:071265 content::NOTIFICATION_LOAD_STOP,
1266 content::NotificationService::AllSources());
[email protected]5d9cace72012-06-21 16:07:121267 chrome::ShowBookmarkManager(browser());
[email protected]ddddfda2011-07-14 23:19:391268 observer.Wait();
1269 }
[email protected]ee496952013-01-10 23:17:331270 EXPECT_EQ(1, browser()->tab_strip_model()->count());
[email protected]bc16a252013-01-23 02:21:491271 EXPECT_TRUE(StartsWithASCII(
1272 browser()->tab_strip_model()->GetActiveWebContents()->GetURL().spec(),
1273 chrome::kChromeUIBookmarksURL,
1274 true));
[email protected]ddddfda2011-07-14 23:19:391275}
1276
1277IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
1278 NavigateFromDefaultToDownloadsInSameTab) {
1279 {
[email protected]a7fe9112012-07-20 02:34:451280 content::WindowedNotificationObserver observer(
[email protected]ad50def52011-10-19 23:17:071281 content::NOTIFICATION_LOAD_STOP,
1282 content::NotificationService::AllSources());
[email protected]5d9cace72012-06-21 16:07:121283 chrome::ShowDownloads(browser());
[email protected]ddddfda2011-07-14 23:19:391284 observer.Wait();
1285 }
[email protected]ee496952013-01-10 23:17:331286 EXPECT_EQ(1, browser()->tab_strip_model()->count());
[email protected]ddddfda2011-07-14 23:19:391287 EXPECT_EQ(GURL(chrome::kChromeUIDownloadsURL),
[email protected]ee496952013-01-10 23:17:331288 browser()->tab_strip_model()->GetActiveWebContents()->GetURL());
[email protected]ddddfda2011-07-14 23:19:391289}
1290
[email protected]8fb16a82012-08-17 02:17:591291IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
1292 NavigateWithoutBrowser) {
1293 // First navigate using the profile of the existing browser window, and
1294 // check that the window is reused.
1295 chrome::NavigateParams params(browser()->profile(), GetGoogleURL(),
1296 content::PAGE_TRANSITION_LINK);
1297 ui_test_utils::NavigateToURL(&params);
[email protected]0665ebe2013-02-13 09:53:191298 EXPECT_EQ(1u, chrome::GetTotalBrowserCount());
[email protected]8fb16a82012-08-17 02:17:591299
1300 // Now navigate using the incognito profile and check that a new window
1301 // is created.
1302 chrome::NavigateParams params_incognito(
1303 browser()->profile()->GetOffTheRecordProfile(),
1304 GetGoogleURL(), content::PAGE_TRANSITION_LINK);
1305 ui_test_utils::NavigateToURL(&params_incognito);
[email protected]0665ebe2013-02-13 09:53:191306 EXPECT_EQ(2u, chrome::GetTotalBrowserCount());
[email protected]8fb16a82012-08-17 02:17:591307}
1308
[email protected]beb1d1192013-05-14 04:47:511309IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, ViewSourceIsntSingleton) {
1310 const std::string viewsource_ntp_url =
[email protected]dbdda5402013-05-30 22:13:481311 std::string(content::kViewSourceScheme) + ":" +
[email protected]beb1d1192013-05-14 04:47:511312 chrome::kChromeUIVersionURL;
1313
1314 chrome::NavigateParams viewsource_params(browser(),
1315 GURL(viewsource_ntp_url),
1316 content::PAGE_TRANSITION_LINK);
1317 ui_test_utils::NavigateToURL(&viewsource_params);
1318
1319 chrome::NavigateParams singleton_params(browser(),
1320 GURL(chrome::kChromeUIVersionURL),
1321 content::PAGE_TRANSITION_LINK);
1322 singleton_params.disposition = SINGLETON_TAB;
1323 EXPECT_EQ(-1, chrome::GetIndexOfSingletonTab(&singleton_params));
1324}
1325
[email protected]a2efc35d2013-08-03 23:17:251326// This test verifies that browser initiated navigations can send requests
1327// using POST.
1328IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
1329 SendBrowserInitiatedRequestUsingPOST) {
1330 // Uses a test sever to verify POST request.
1331 ASSERT_TRUE(test_server()->Start());
1332
1333 // Open a browser initiated POST request in new foreground tab.
[email protected]e9273e192013-12-11 17:51:491334 base::string16 expected_title(base::ASCIIToUTF16(kExpectedTitle));
[email protected]a2efc35d2013-08-03 23:17:251335 std::string post_data = kExpectedTitle;
[email protected]e9273e192013-12-11 17:51:491336 base::string16 title;
[email protected]a2efc35d2013-08-03 23:17:251337 ASSERT_TRUE(OpenPOSTURLInNewForegroundTabAndGetTitle(
1338 test_server()->GetURL(kEchoTitleCommand), post_data, true, &title));
1339 EXPECT_EQ(expected_title, title);
1340}
1341
1342// This test verifies that renderer initiated navigations can NOT send requests
1343// using POST.
1344IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
1345 SendRendererInitiatedRequestUsingPOST) {
1346 // Uses a test sever to verify POST request.
1347 ASSERT_TRUE(test_server()->Start());
1348
1349 // Open a renderer initiated POST request in new foreground tab.
[email protected]e9273e192013-12-11 17:51:491350 base::string16 expected_title(base::ASCIIToUTF16(kExpectedTitle));
[email protected]a2efc35d2013-08-03 23:17:251351 std::string post_data = kExpectedTitle;
[email protected]e9273e192013-12-11 17:51:491352 base::string16 title;
[email protected]a2efc35d2013-08-03 23:17:251353 ASSERT_TRUE(OpenPOSTURLInNewForegroundTabAndGetTitle(
1354 test_server()->GetURL(kEchoTitleCommand), post_data, false, &title));
1355 EXPECT_NE(expected_title, title);
1356}
1357
1358} // namespace