blob: b13ddb0ccc09fdd0de1d5aea0866ba3691f3f456 [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]26c53e662011-07-09 02:21:029#include "chrome/app/chrome_command_ids.h"
[email protected]93ad8e1c2011-11-08 21:34:0510#include "chrome/browser/prefs/incognito_mode_prefs.h"
[email protected]8ecad5e2010-12-02 21:18:3311#include "chrome/browser/profiles/profile.h"
[email protected]2b09ae552013-02-23 06:38:0312#include "chrome/browser/ui/browser.h"
[email protected]a37d4b02012-06-25 21:56:1013#include "chrome/browser/ui/browser_commands.h"
[email protected]0665ebe2013-02-13 09:53:1914#include "chrome/browser/ui/browser_finder.h"
[email protected]339d6dd2010-11-12 00:41:5815#include "chrome/browser/ui/browser_navigator.h"
[email protected]52877dbc62012-06-29 22:22:0316#include "chrome/browser/ui/browser_tabstrip.h"
[email protected]bb89e7482010-11-17 18:27:0417#include "chrome/browser/ui/browser_window.h"
[email protected]5d9cace72012-06-21 16:07:1218#include "chrome/browser/ui/chrome_pages.h"
[email protected]beb1d1192013-05-14 04:47:5119#include "chrome/browser/ui/singleton_tabs.h"
[email protected]b56e2e32012-05-11 21:18:0420#include "chrome/browser/ui/tabs/tab_strip_model.h"
[email protected]bb89e7482010-11-17 18:27:0421#include "chrome/common/chrome_switches.h"
[email protected]93ad8e1c2011-11-08 21:34:0522#include "chrome/common/pref_names.h"
[email protected]ddddfda2011-07-14 23:19:3923#include "chrome/common/url_constants.h"
[email protected]af44e7fb2011-07-29 18:32:3224#include "chrome/test/base/ui_test_utils.h"
[email protected]ad50def52011-10-19 23:17:0725#include "content/public/browser/notification_service.h"
[email protected]0d6e9bd2011-10-18 04:29:1626#include "content/public/browser/notification_types.h"
[email protected]83ff91c2012-01-05 20:54:1327#include "content/public/browser/web_contents.h"
[email protected]8643e6d2012-01-18 20:26:1028#include "content/public/browser/web_contents_view.h"
[email protected]c47317e2012-06-20 22:35:3129#include "ipc/ipc_message.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
35GURL GetGoogleURL() {
[email protected]bd817c22011-02-09 08:16:4636 return GURL("http://www.google.com/");
37}
[email protected]a1feae52010-10-11 22:14:4538
[email protected]ddddfda2011-07-14 23:19:3939GURL GetSettingsURL() {
[email protected]f8f93eb2012-09-25 03:06:2440 return GURL(chrome::kChromeUISettingsURL);
[email protected]ddddfda2011-07-14 23:19:3941}
42
[email protected]a048ad22012-03-23 04:26:5643GURL GetContentSettingsURL() {
44 return GetSettingsURL().Resolve(chrome::kContentSettingsExceptionsSubPage);
[email protected]ddddfda2011-07-14 23:19:3945}
46
[email protected]a048ad22012-03-23 04:26:5647GURL GetClearBrowsingDataURL() {
48 return GetSettingsURL().Resolve(chrome::kClearBrowserDataSubPage);
[email protected]ddddfda2011-07-14 23:19:3949}
50
[email protected]f8f93eb2012-09-25 03:06:2451// Converts long uber URLs ("chrome://chrome/foo/") to short (virtual) URLs
52// ("chrome://foo/"). This should be used to convert the return value of
53// WebContentsImpl::GetURL before comparison because it can return either the
54// real URL or the virtual URL.
55GURL ShortenUberURL(const GURL& url) {
56 std::string url_string = url.spec();
57 const std::string long_prefix = "chrome://chrome/";
58 const std::string short_prefix = "chrome://";
59 if (url_string.find(long_prefix) != 0)
60 return url;
61 url_string.replace(0, long_prefix.length(), short_prefix);
62 return GURL(url_string);
63}
64
[email protected]ddddfda2011-07-14 23:19:3965} // namespace
66
[email protected]78e2edc2012-07-01 23:32:2867chrome::NavigateParams BrowserNavigatorTest::MakeNavigateParams() const {
[email protected]bd817c22011-02-09 08:16:4668 return MakeNavigateParams(browser());
69}
[email protected]a1feae52010-10-11 22:14:4570
[email protected]78e2edc2012-07-01 23:32:2871chrome::NavigateParams BrowserNavigatorTest::MakeNavigateParams(
[email protected]bd817c22011-02-09 08:16:4672 Browser* browser) const {
[email protected]78e2edc2012-07-01 23:32:2873 chrome::NavigateParams params(browser, GetGoogleURL(),
74 content::PAGE_TRANSITION_LINK);
[email protected]50592b52013-05-02 22:26:2575 params.window_action = chrome::NavigateParams::SHOW_WINDOW;
[email protected]bd817c22011-02-09 08:16:4676 return params;
77}
[email protected]a1feae52010-10-11 22:14:4578
[email protected]bd817c22011-02-09 08:16:4679Browser* BrowserNavigatorTest::CreateEmptyBrowserForType(Browser::Type type,
80 Profile* profile) {
[email protected]2b09ae552013-02-23 06:38:0381 Browser* browser = new Browser(
82 Browser::CreateParams(type, profile, chrome::HOST_DESKTOP_TYPE_NATIVE));
[email protected]686221c2012-11-08 07:30:1083 chrome::AddBlankTabAt(browser, -1, true);
[email protected]bd817c22011-02-09 08:16:4684 return browser;
85}
[email protected]a1feae52010-10-11 22:14:4586
[email protected]b35b26b32011-05-05 20:35:1487Browser* BrowserNavigatorTest::CreateEmptyBrowserForApp(Browser::Type type,
88 Profile* profile) {
[email protected]a4fe67012012-07-25 20:14:2989 Browser* browser = new Browser(
[email protected]da22aa62012-04-04 18:54:3590 Browser::CreateParams::CreateForApp(
[email protected]2b09ae552013-02-23 06:38:0391 Browser::TYPE_POPUP, "Test", gfx::Rect(), profile,
92 chrome::HOST_DESKTOP_TYPE_NATIVE));
[email protected]686221c2012-11-08 07:30:1093 chrome::AddBlankTabAt(browser, -1, true);
[email protected]b35b26b32011-05-05 20:35:1494 return browser;
95}
96
[email protected]e232c992012-12-06 12:43:2097WebContents* BrowserNavigatorTest::CreateWebContents() {
[email protected]54944cde2012-12-09 09:24:5998 content::WebContents::CreateParams create_params(browser()->profile());
[email protected]ed245db2012-12-18 08:00:4599 content::WebContents* base_web_contents =
[email protected]ee496952013-01-10 23:17:33100 browser()->tab_strip_model()->GetActiveWebContents();
[email protected]ed245db2012-12-18 08:00:45101 if (base_web_contents) {
102 create_params.initial_size =
103 base_web_contents->GetView()->GetContainerSize();
104 }
[email protected]54944cde2012-12-09 09:24:59105 return WebContents::Create(create_params);
[email protected]bd817c22011-02-09 08:16:46106}
[email protected]a1feae52010-10-11 22:14:45107
[email protected]bd817c22011-02-09 08:16:46108void BrowserNavigatorTest::RunSuppressTest(WindowOpenDisposition disposition) {
[email protected]ee496952013-01-10 23:17:33109 GURL old_url = browser()->tab_strip_model()->GetActiveWebContents()->GetURL();
[email protected]78e2edc2012-07-01 23:32:28110 chrome::NavigateParams p(MakeNavigateParams());
[email protected]bd817c22011-02-09 08:16:46111 p.disposition = disposition;
[email protected]78e2edc2012-07-01 23:32:28112 chrome::Navigate(&p);
[email protected]a1feae52010-10-11 22:14:45113
[email protected]bd817c22011-02-09 08:16:46114 // Nothing should have happened as a result of Navigate();
[email protected]ee496952013-01-10 23:17:33115 EXPECT_EQ(1, browser()->tab_strip_model()->count());
[email protected]0665ebe2013-02-13 09:53:19116 EXPECT_EQ(1u, chrome::GetTotalBrowserCount());
[email protected]ee496952013-01-10 23:17:33117 EXPECT_EQ(old_url,
118 browser()->tab_strip_model()->GetActiveWebContents()->GetURL());
[email protected]bd817c22011-02-09 08:16:46119}
[email protected]bb89e7482010-11-17 18:27:04120
[email protected]fc0ed302011-11-29 23:17:19121void BrowserNavigatorTest::RunUseNonIncognitoWindowTest(const GURL& url) {
122 Browser* incognito_browser = CreateIncognitoBrowser();
123
[email protected]0665ebe2013-02-13 09:53:19124 EXPECT_EQ(2u, chrome::GetTotalBrowserCount());
[email protected]ee496952013-01-10 23:17:33125 EXPECT_EQ(1, browser()->tab_strip_model()->count());
126 EXPECT_EQ(1, incognito_browser->tab_strip_model()->count());
[email protected]fc0ed302011-11-29 23:17:19127
128 // Navigate to the page.
[email protected]78e2edc2012-07-01 23:32:28129 chrome::NavigateParams p(MakeNavigateParams(incognito_browser));
[email protected]fc0ed302011-11-29 23:17:19130 p.disposition = SINGLETON_TAB;
131 p.url = url;
[email protected]50592b52013-05-02 22:26:25132 p.window_action = chrome::NavigateParams::SHOW_WINDOW;
[email protected]78e2edc2012-07-01 23:32:28133 chrome::Navigate(&p);
[email protected]fc0ed302011-11-29 23:17:19134
[email protected]50592b52013-05-02 22:26:25135 // This page should be opened in browser() window.
[email protected]fc0ed302011-11-29 23:17:19136 EXPECT_NE(incognito_browser, p.browser);
137 EXPECT_EQ(browser(), p.browser);
[email protected]ee496952013-01-10 23:17:33138 EXPECT_EQ(2, browser()->tab_strip_model()->count());
139 EXPECT_EQ(url,
140 browser()->tab_strip_model()->GetActiveWebContents()->GetURL());
[email protected]fc0ed302011-11-29 23:17:19141}
142
143void BrowserNavigatorTest::RunDoNothingIfIncognitoIsForcedTest(
144 const GURL& url) {
145 Browser* browser = CreateIncognitoBrowser();
146
147 // Set kIncognitoModeAvailability to FORCED.
148 PrefService* prefs1 = browser->profile()->GetPrefs();
149 prefs1->SetInteger(prefs::kIncognitoModeAvailability,
150 IncognitoModePrefs::FORCED);
151 PrefService* prefs2 = browser->profile()->GetOriginalProfile()->GetPrefs();
152 prefs2->SetInteger(prefs::kIncognitoModeAvailability,
153 IncognitoModePrefs::FORCED);
154
155 // Navigate to the page.
[email protected]78e2edc2012-07-01 23:32:28156 chrome::NavigateParams p(MakeNavigateParams(browser));
[email protected]fc0ed302011-11-29 23:17:19157 p.disposition = OFF_THE_RECORD;
158 p.url = url;
[email protected]50592b52013-05-02 22:26:25159 p.window_action = chrome::NavigateParams::SHOW_WINDOW;
[email protected]78e2edc2012-07-01 23:32:28160 chrome::Navigate(&p);
[email protected]fc0ed302011-11-29 23:17:19161
162 // The page should not be opened.
163 EXPECT_EQ(browser, p.browser);
[email protected]ee496952013-01-10 23:17:33164 EXPECT_EQ(1, browser->tab_strip_model()->count());
[email protected]081dc522013-05-15 04:59:20165 EXPECT_EQ(GURL(content::kAboutBlankURL),
[email protected]ee496952013-01-10 23:17:33166 browser->tab_strip_model()->GetActiveWebContents()->GetURL());
[email protected]fc0ed302011-11-29 23:17:19167}
168
[email protected]6c2381d2011-10-19 02:52:53169void BrowserNavigatorTest::Observe(
170 int type,
171 const content::NotificationSource& source,
172 const content::NotificationDetails& details) {
[email protected]432115822011-07-10 15:52:27173 switch (type) {
[email protected]d53a08c2012-07-18 20:35:30174 case content::NOTIFICATION_WEB_CONTENTS_RENDER_VIEW_HOST_CREATED: {
[email protected]bd817c22011-02-09 08:16:46175 ++this->created_tab_contents_count_;
176 break;
[email protected]fa7ebe02010-11-29 23:04:57177 }
[email protected]bd817c22011-02-09 08:16:46178 default:
179 break;
[email protected]fa7ebe02010-11-29 23:04:57180 }
[email protected]bd817c22011-02-09 08:16:46181}
[email protected]fa7ebe02010-11-29 23:04:57182
[email protected]ddddfda2011-07-14 23:19:39183
[email protected]bd817c22011-02-09 08:16:46184namespace {
[email protected]a1feae52010-10-11 22:14:45185
[email protected]a1feae52010-10-11 22:14:45186// This test verifies that when a navigation occurs within a tab, the tab count
187// of the Browser remains the same and the current tab bears the loaded URL.
[email protected]59167c22013-06-03 18:07:32188// Note that network URLs are not actually loaded in tests, so this also tests
189// that error pages leave the intended URL in the address bar.
[email protected]a1feae52010-10-11 22:14:45190IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_CurrentTab) {
[email protected]ddddfda2011-07-14 23:19:39191 ui_test_utils::NavigateToURL(browser(), GetGoogleURL());
[email protected]ee496952013-01-10 23:17:33192 EXPECT_EQ(GetGoogleURL(),
193 browser()->tab_strip_model()->GetActiveWebContents()->GetURL());
[email protected]a1feae52010-10-11 22:14:45194 // We should have one window with one tab.
[email protected]0665ebe2013-02-13 09:53:19195 EXPECT_EQ(1u, chrome::GetTotalBrowserCount());
[email protected]ee496952013-01-10 23:17:33196 EXPECT_EQ(1, browser()->tab_strip_model()->count());
[email protected]a1feae52010-10-11 22:14:45197}
198
[email protected]bd817c22011-02-09 08:16:46199// This test verifies that a singleton tab is refocused if one is already opened
[email protected]19d9f3a2010-10-14 21:49:36200// in another or an existing window, or added if it is not.
201IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_SingletonTabExisting) {
[email protected]19d9f3a2010-10-14 21:49:36202 GURL singleton_url1("http://maps.google.com/");
[email protected]fa7ebe02010-11-29 23:04:57203
[email protected]e232c992012-12-06 12:43:20204 // Register for a notification if an additional WebContents was instantiated.
[email protected]bd817c22011-02-09 08:16:46205 // Opening a Singleton tab that is already opened should not be opening a new
[email protected]e232c992012-12-06 12:43:20206 // tab nor be creating a new WebContents object.
[email protected]6c2381d2011-10-19 02:52:53207 content::NotificationRegistrar registrar;
[email protected]fa7ebe02010-11-29 23:04:57208
209 // As the registrar object goes out of scope, this will get unregistered
[email protected]d53a08c2012-07-18 20:35:30210 registrar.Add(this,
211 content::NOTIFICATION_WEB_CONTENTS_RENDER_VIEW_HOST_CREATED,
[email protected]ad50def52011-10-19 23:17:07212 content::NotificationService::AllSources());
[email protected]fa7ebe02010-11-29 23:04:57213
[email protected]52877dbc62012-06-29 22:22:03214 chrome::AddSelectedTabWithURL(browser(), singleton_url1,
215 content::PAGE_TRANSITION_LINK);
216 chrome::AddSelectedTabWithURL(browser(), GetGoogleURL(),
217 content::PAGE_TRANSITION_LINK);
[email protected]19d9f3a2010-10-14 21:49:36218
219 // We should have one browser with 3 tabs, the 3rd selected.
[email protected]0665ebe2013-02-13 09:53:19220 EXPECT_EQ(1u, chrome::GetTotalBrowserCount());
[email protected]ee496952013-01-10 23:17:33221 EXPECT_EQ(2, browser()->tab_strip_model()->active_index());
[email protected]19d9f3a2010-10-14 21:49:36222
[email protected]fa7ebe02010-11-29 23:04:57223 unsigned int previous_tab_contents_count =
224 created_tab_contents_count_ = 0;
225
[email protected]19d9f3a2010-10-14 21:49:36226 // Navigate to singleton_url1.
[email protected]78e2edc2012-07-01 23:32:28227 chrome::NavigateParams p(MakeNavigateParams());
[email protected]19d9f3a2010-10-14 21:49:36228 p.disposition = SINGLETON_TAB;
229 p.url = singleton_url1;
[email protected]78e2edc2012-07-01 23:32:28230 chrome::Navigate(&p);
[email protected]19d9f3a2010-10-14 21:49:36231
232 // The middle tab should now be selected.
233 EXPECT_EQ(browser(), p.browser);
[email protected]ee496952013-01-10 23:17:33234 EXPECT_EQ(1, browser()->tab_strip_model()->active_index());
[email protected]fa7ebe02010-11-29 23:04:57235
236 // No tab contents should have been created
237 EXPECT_EQ(previous_tab_contents_count,
238 created_tab_contents_count_);
[email protected]19d9f3a2010-10-14 21:49:36239}
240
241IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
[email protected]578c6962011-08-24 22:06:40242 Disposition_SingletonTabRespectingRef) {
243 GURL singleton_ref_url1("http://maps.google.com/#a");
244 GURL singleton_ref_url2("http://maps.google.com/#b");
245 GURL singleton_ref_url3("http://maps.google.com/");
246
[email protected]52877dbc62012-06-29 22:22:03247 chrome::AddSelectedTabWithURL(browser(), singleton_ref_url1,
248 content::PAGE_TRANSITION_LINK);
[email protected]578c6962011-08-24 22:06:40249
250 // We should have one browser with 2 tabs, 2nd selected.
[email protected]0665ebe2013-02-13 09:53:19251 EXPECT_EQ(1u, chrome::GetTotalBrowserCount());
[email protected]ee496952013-01-10 23:17:33252 EXPECT_EQ(2, browser()->tab_strip_model()->count());
253 EXPECT_EQ(1, browser()->tab_strip_model()->active_index());
[email protected]578c6962011-08-24 22:06:40254
255 // Navigate to singleton_url2.
[email protected]78e2edc2012-07-01 23:32:28256 chrome::NavigateParams p(MakeNavigateParams());
[email protected]578c6962011-08-24 22:06:40257 p.disposition = SINGLETON_TAB;
258 p.url = singleton_ref_url2;
[email protected]78e2edc2012-07-01 23:32:28259 chrome::Navigate(&p);
[email protected]578c6962011-08-24 22:06:40260
261 // We should now have 2 tabs, the 2nd one selected.
262 EXPECT_EQ(browser(), p.browser);
[email protected]ee496952013-01-10 23:17:33263 EXPECT_EQ(2, browser()->tab_strip_model()->count());
264 EXPECT_EQ(1, browser()->tab_strip_model()->active_index());
[email protected]578c6962011-08-24 22:06:40265
266 // Navigate to singleton_url2, but with respect ref set.
267 p = MakeNavigateParams();
268 p.disposition = SINGLETON_TAB;
269 p.url = singleton_ref_url2;
[email protected]78e2edc2012-07-01 23:32:28270 p.ref_behavior = chrome::NavigateParams::RESPECT_REF;
271 chrome::Navigate(&p);
[email protected]578c6962011-08-24 22:06:40272
273 // We should now have 3 tabs, the 3th one selected.
274 EXPECT_EQ(browser(), p.browser);
[email protected]ee496952013-01-10 23:17:33275 EXPECT_EQ(3, browser()->tab_strip_model()->count());
276 EXPECT_EQ(2, browser()->tab_strip_model()->active_index());
[email protected]578c6962011-08-24 22:06:40277
278 // Navigate to singleton_url3.
279 p = MakeNavigateParams();
280 p.disposition = SINGLETON_TAB;
281 p.url = singleton_ref_url3;
[email protected]78e2edc2012-07-01 23:32:28282 p.ref_behavior = chrome::NavigateParams::RESPECT_REF;
283 chrome::Navigate(&p);
[email protected]578c6962011-08-24 22:06:40284
285 // We should now have 4 tabs, the 4th one selected.
286 EXPECT_EQ(browser(), p.browser);
[email protected]ee496952013-01-10 23:17:33287 EXPECT_EQ(4, browser()->tab_strip_model()->count());
288 EXPECT_EQ(3, browser()->tab_strip_model()->active_index());
[email protected]578c6962011-08-24 22:06:40289}
290
291IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
[email protected]19d9f3a2010-10-14 21:49:36292 Disposition_SingletonTabNoneExisting) {
[email protected]19d9f3a2010-10-14 21:49:36293 GURL singleton_url1("http://maps.google.com/");
294
[email protected]bd817c22011-02-09 08:16:46295 // We should have one browser with 1 tab.
[email protected]0665ebe2013-02-13 09:53:19296 EXPECT_EQ(1u, chrome::GetTotalBrowserCount());
[email protected]ee496952013-01-10 23:17:33297 EXPECT_EQ(0, browser()->tab_strip_model()->active_index());
[email protected]19d9f3a2010-10-14 21:49:36298
299 // Navigate to singleton_url1.
[email protected]78e2edc2012-07-01 23:32:28300 chrome::NavigateParams p(MakeNavigateParams());
[email protected]19d9f3a2010-10-14 21:49:36301 p.disposition = SINGLETON_TAB;
302 p.url = singleton_url1;
[email protected]78e2edc2012-07-01 23:32:28303 chrome::Navigate(&p);
[email protected]19d9f3a2010-10-14 21:49:36304
305 // We should now have 2 tabs, the 2nd one selected.
306 EXPECT_EQ(browser(), p.browser);
[email protected]ee496952013-01-10 23:17:33307 EXPECT_EQ(2, browser()->tab_strip_model()->count());
308 EXPECT_EQ(1, browser()->tab_strip_model()->active_index());
[email protected]a1feae52010-10-11 22:14:45309}
310
311// This test verifies that when a navigation results in a foreground tab, the
312// tab count of the Browser increases and the selected tab shifts to the new
313// foreground tab.
314IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_NewForegroundTab) {
[email protected]ee496952013-01-10 23:17:33315 WebContents* old_contents =
316 browser()->tab_strip_model()->GetActiveWebContents();
[email protected]78e2edc2012-07-01 23:32:28317 chrome::NavigateParams p(MakeNavigateParams());
[email protected]a1feae52010-10-11 22:14:45318 p.disposition = NEW_FOREGROUND_TAB;
[email protected]78e2edc2012-07-01 23:32:28319 chrome::Navigate(&p);
[email protected]ee496952013-01-10 23:17:33320 EXPECT_NE(old_contents,
321 browser()->tab_strip_model()->GetActiveWebContents());
[email protected]e232c992012-12-06 12:43:20322 EXPECT_EQ(browser()->tab_strip_model()->GetActiveWebContents(),
[email protected]59253a652012-11-20 00:17:26323 p.target_contents);
[email protected]ee496952013-01-10 23:17:33324 EXPECT_EQ(2, browser()->tab_strip_model()->count());
[email protected]a1feae52010-10-11 22:14:45325}
326
327// This test verifies that when a navigation results in a background tab, the
328// tab count of the Browser increases but the selected tab remains the same.
329IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_NewBackgroundTab) {
[email protected]ee496952013-01-10 23:17:33330 WebContents* old_contents =
331 browser()->tab_strip_model()->GetActiveWebContents();
[email protected]78e2edc2012-07-01 23:32:28332 chrome::NavigateParams p(MakeNavigateParams());
[email protected]a1feae52010-10-11 22:14:45333 p.disposition = NEW_BACKGROUND_TAB;
[email protected]78e2edc2012-07-01 23:32:28334 chrome::Navigate(&p);
[email protected]ee496952013-01-10 23:17:33335 WebContents* new_contents =
336 browser()->tab_strip_model()->GetActiveWebContents();
[email protected]a1feae52010-10-11 22:14:45337 // The selected tab should have remained unchanged, since the new tab was
338 // opened in the background.
339 EXPECT_EQ(old_contents, new_contents);
[email protected]ee496952013-01-10 23:17:33340 EXPECT_EQ(2, browser()->tab_strip_model()->count());
[email protected]a1feae52010-10-11 22:14:45341}
342
343// This test verifies that when a navigation requiring a new foreground tab
344// occurs in a Browser that cannot host multiple tabs, the new foreground tab
345// is created in an existing compatible Browser.
346IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
347 Disposition_IncompatibleWindow_Existing) {
348 // Open a foreground tab in a window that cannot open popups when there is an
349 // existing compatible window somewhere else that they can be opened within.
350 Browser* popup = CreateEmptyBrowserForType(Browser::TYPE_POPUP,
351 browser()->profile());
[email protected]78e2edc2012-07-01 23:32:28352 chrome::NavigateParams p(MakeNavigateParams(popup));
[email protected]a1feae52010-10-11 22:14:45353 p.disposition = NEW_FOREGROUND_TAB;
[email protected]78e2edc2012-07-01 23:32:28354 chrome::Navigate(&p);
[email protected]a1feae52010-10-11 22:14:45355
356 // Navigate() should have opened the tab in a different browser since the
357 // one we supplied didn't support additional tabs.
358 EXPECT_NE(popup, p.browser);
359
360 // Since browser() is an existing compatible tabbed browser, it should have
361 // opened the tab there.
362 EXPECT_EQ(browser(), p.browser);
363
364 // We should be left with 2 windows, the popup with one tab and the browser()
365 // provided by the framework with two.
[email protected]0665ebe2013-02-13 09:53:19366 EXPECT_EQ(2u, chrome::GetTotalBrowserCount());
[email protected]ee496952013-01-10 23:17:33367 EXPECT_EQ(1, popup->tab_strip_model()->count());
368 EXPECT_EQ(2, browser()->tab_strip_model()->count());
[email protected]a1feae52010-10-11 22:14:45369}
370
371// This test verifies that when a navigation requiring a new foreground tab
372// occurs in a Browser that cannot host multiple tabs and no compatible Browser
373// that can is open, a compatible Browser is created.
374IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
375 Disposition_IncompatibleWindow_NoExisting) {
376 // We want to simulate not being able to find an existing window compatible
377 // with our non-tabbed browser window so Navigate() is forced to create a
378 // new compatible window. Because browser() supplied by the in-process
379 // browser testing framework is compatible with browser()->profile(), we
380 // need a different profile, and creating a popup window with an incognito
381 // profile is a quick and dirty way of achieving this.
382 Browser* popup = CreateEmptyBrowserForType(
[email protected]b35b26b32011-05-05 20:35:14383 Browser::TYPE_POPUP,
384 browser()->profile()->GetOffTheRecordProfile());
[email protected]78e2edc2012-07-01 23:32:28385 chrome::NavigateParams p(MakeNavigateParams(popup));
[email protected]a1feae52010-10-11 22:14:45386 p.disposition = NEW_FOREGROUND_TAB;
[email protected]78e2edc2012-07-01 23:32:28387 chrome::Navigate(&p);
[email protected]a1feae52010-10-11 22:14:45388
389 // Navigate() should have opened the tab in a different browser since the
390 // one we supplied didn't support additional tabs.
391 EXPECT_NE(popup, p.browser);
392
393 // This time, browser() is _not_ compatible with popup since it is not an
394 // incognito window.
395 EXPECT_NE(browser(), p.browser);
396
397 // We should have three windows, each with one tab:
398 // 1. the browser() provided by the framework (unchanged in this test)
399 // 2. the incognito popup we created originally
400 // 3. the new incognito tabbed browser that was created by Navigate().
[email protected]0665ebe2013-02-13 09:53:19401 EXPECT_EQ(3u, chrome::GetTotalBrowserCount());
[email protected]ee496952013-01-10 23:17:33402 EXPECT_EQ(1, browser()->tab_strip_model()->count());
403 EXPECT_EQ(1, popup->tab_strip_model()->count());
404 EXPECT_EQ(1, p.browser->tab_strip_model()->count());
[email protected]b35b26b32011-05-05 20:35:14405 EXPECT_TRUE(p.browser->is_type_tabbed());
[email protected]a1feae52010-10-11 22:14:45406}
407
408// This test verifies that navigating with WindowOpenDisposition = NEW_POPUP
409// from a normal Browser results in a new Browser with TYPE_POPUP.
410IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_NewPopup) {
[email protected]78e2edc2012-07-01 23:32:28411 chrome::NavigateParams p(MakeNavigateParams());
[email protected]a1feae52010-10-11 22:14:45412 p.disposition = NEW_POPUP;
[email protected]588300d2011-04-28 21:06:35413 p.window_bounds = gfx::Rect(0, 0, 200, 200);
[email protected]7d329992011-04-15 18:20:02414 // Wait for new popup to to load and gain focus.
[email protected]ddddfda2011-07-14 23:19:39415 ui_test_utils::NavigateToURL(&p);
[email protected]a1feae52010-10-11 22:14:45416
[email protected]7d329992011-04-15 18:20:02417 // Navigate() should have opened a new, focused popup window.
[email protected]a1feae52010-10-11 22:14:45418 EXPECT_NE(browser(), p.browser);
[email protected]50592b52013-05-02 22:26:25419#if 0
420 // TODO(stevenjb): Enable this test. See: crbug.com/79493
421 EXPECT_TRUE(p.browser->window()->IsActive());
422#endif
[email protected]b35b26b32011-05-05 20:35:14423 EXPECT_TRUE(p.browser->is_type_popup());
424 EXPECT_FALSE(p.browser->is_app());
[email protected]a1feae52010-10-11 22:14:45425
426 // We should have two windows, the browser() provided by the framework and the
427 // new popup window.
[email protected]0665ebe2013-02-13 09:53:19428 EXPECT_EQ(2u, chrome::GetTotalBrowserCount());
[email protected]ee496952013-01-10 23:17:33429 EXPECT_EQ(1, browser()->tab_strip_model()->count());
430 EXPECT_EQ(1, p.browser->tab_strip_model()->count());
[email protected]a1feae52010-10-11 22:14:45431}
432
433// This test verifies that navigating with WindowOpenDisposition = NEW_POPUP
[email protected]f112b0f2011-05-26 01:53:52434// from a normal Browser results in a new Browser with is_app() true.
435IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_NewPopup_ExtensionId) {
[email protected]78e2edc2012-07-01 23:32:28436 chrome::NavigateParams p(MakeNavigateParams());
[email protected]f112b0f2011-05-26 01:53:52437 p.disposition = NEW_POPUP;
438 p.extension_app_id = "extensionappid";
439 p.window_bounds = gfx::Rect(0, 0, 200, 200);
[email protected]f112b0f2011-05-26 01:53:52440 // Wait for new popup to to load and gain focus.
[email protected]ddddfda2011-07-14 23:19:39441 ui_test_utils::NavigateToURL(&p);
[email protected]f112b0f2011-05-26 01:53:52442
443 // Navigate() should have opened a new, focused popup window.
444 EXPECT_NE(browser(), p.browser);
445 EXPECT_TRUE(p.browser->is_type_popup());
446 EXPECT_TRUE(p.browser->is_app());
447
448 // We should have two windows, the browser() provided by the framework and the
449 // new popup window.
[email protected]0665ebe2013-02-13 09:53:19450 EXPECT_EQ(2u, chrome::GetTotalBrowserCount());
[email protected]ee496952013-01-10 23:17:33451 EXPECT_EQ(1, browser()->tab_strip_model()->count());
452 EXPECT_EQ(1, p.browser->tab_strip_model()->count());
[email protected]f112b0f2011-05-26 01:53:52453}
454
455// This test verifies that navigating with WindowOpenDisposition = NEW_POPUP
[email protected]300d1e52011-01-19 23:57:57456// from a normal popup results in a new Browser with TYPE_POPUP.
457IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_NewPopupFromPopup) {
458 // Open a popup.
[email protected]78e2edc2012-07-01 23:32:28459 chrome::NavigateParams p1(MakeNavigateParams());
[email protected]300d1e52011-01-19 23:57:57460 p1.disposition = NEW_POPUP;
[email protected]588300d2011-04-28 21:06:35461 p1.window_bounds = gfx::Rect(0, 0, 200, 200);
[email protected]78e2edc2012-07-01 23:32:28462 chrome::Navigate(&p1);
[email protected]300d1e52011-01-19 23:57:57463 // Open another popup.
[email protected]78e2edc2012-07-01 23:32:28464 chrome::NavigateParams p2(MakeNavigateParams(p1.browser));
[email protected]300d1e52011-01-19 23:57:57465 p2.disposition = NEW_POPUP;
[email protected]588300d2011-04-28 21:06:35466 p2.window_bounds = gfx::Rect(0, 0, 200, 200);
[email protected]78e2edc2012-07-01 23:32:28467 chrome::Navigate(&p2);
[email protected]300d1e52011-01-19 23:57:57468
469 // Navigate() should have opened a new normal popup window.
470 EXPECT_NE(p1.browser, p2.browser);
[email protected]b35b26b32011-05-05 20:35:14471 EXPECT_TRUE(p2.browser->is_type_popup());
472 EXPECT_FALSE(p2.browser->is_app());
[email protected]300d1e52011-01-19 23:57:57473
474 // We should have three windows, the browser() provided by the framework,
475 // the first popup window, and the second popup window.
[email protected]0665ebe2013-02-13 09:53:19476 EXPECT_EQ(3u, chrome::GetTotalBrowserCount());
[email protected]ee496952013-01-10 23:17:33477 EXPECT_EQ(1, browser()->tab_strip_model()->count());
478 EXPECT_EQ(1, p1.browser->tab_strip_model()->count());
479 EXPECT_EQ(1, p2.browser->tab_strip_model()->count());
[email protected]300d1e52011-01-19 23:57:57480}
481
482// This test verifies that navigating with WindowOpenDisposition = NEW_POPUP
[email protected]a1feae52010-10-11 22:14:45483// from an app frame results in a new Browser with TYPE_APP_POPUP.
484IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
485 Disposition_NewPopupFromAppWindow) {
[email protected]b35b26b32011-05-05 20:35:14486 Browser* app_browser = CreateEmptyBrowserForApp(Browser::TYPE_TABBED,
487 browser()->profile());
[email protected]78e2edc2012-07-01 23:32:28488 chrome::NavigateParams p(MakeNavigateParams(app_browser));
[email protected]a1feae52010-10-11 22:14:45489 p.disposition = NEW_POPUP;
[email protected]588300d2011-04-28 21:06:35490 p.window_bounds = gfx::Rect(0, 0, 200, 200);
[email protected]78e2edc2012-07-01 23:32:28491 chrome::Navigate(&p);
[email protected]a1feae52010-10-11 22:14:45492
493 // Navigate() should have opened a new popup app window.
494 EXPECT_NE(app_browser, p.browser);
495 EXPECT_NE(browser(), p.browser);
[email protected]b35b26b32011-05-05 20:35:14496 EXPECT_TRUE(p.browser->is_type_popup());
497 EXPECT_TRUE(p.browser->is_app());
[email protected]a1feae52010-10-11 22:14:45498
499 // We should now have three windows, the app window, the app popup it created,
500 // and the original browser() provided by the framework.
[email protected]0665ebe2013-02-13 09:53:19501 EXPECT_EQ(3u, chrome::GetTotalBrowserCount());
[email protected]ee496952013-01-10 23:17:33502 EXPECT_EQ(1, browser()->tab_strip_model()->count());
503 EXPECT_EQ(1, app_browser->tab_strip_model()->count());
504 EXPECT_EQ(1, p.browser->tab_strip_model()->count());
[email protected]a1feae52010-10-11 22:14:45505}
506
507// This test verifies that navigating with WindowOpenDisposition = NEW_POPUP
[email protected]300d1e52011-01-19 23:57:57508// from an app popup results in a new Browser also of TYPE_APP_POPUP.
509IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
510 Disposition_NewPopupFromAppPopup) {
[email protected]b35b26b32011-05-05 20:35:14511 Browser* app_browser = CreateEmptyBrowserForApp(Browser::TYPE_TABBED,
512 browser()->profile());
[email protected]300d1e52011-01-19 23:57:57513 // Open an app popup.
[email protected]78e2edc2012-07-01 23:32:28514 chrome::NavigateParams p1(MakeNavigateParams(app_browser));
[email protected]300d1e52011-01-19 23:57:57515 p1.disposition = NEW_POPUP;
[email protected]588300d2011-04-28 21:06:35516 p1.window_bounds = gfx::Rect(0, 0, 200, 200);
[email protected]78e2edc2012-07-01 23:32:28517 chrome::Navigate(&p1);
[email protected]300d1e52011-01-19 23:57:57518 // Now open another app popup.
[email protected]78e2edc2012-07-01 23:32:28519 chrome::NavigateParams p2(MakeNavigateParams(p1.browser));
[email protected]300d1e52011-01-19 23:57:57520 p2.disposition = NEW_POPUP;
[email protected]588300d2011-04-28 21:06:35521 p2.window_bounds = gfx::Rect(0, 0, 200, 200);
[email protected]78e2edc2012-07-01 23:32:28522 chrome::Navigate(&p2);
[email protected]300d1e52011-01-19 23:57:57523
524 // Navigate() should have opened a new popup app window.
525 EXPECT_NE(browser(), p1.browser);
526 EXPECT_NE(p1.browser, p2.browser);
[email protected]b35b26b32011-05-05 20:35:14527 EXPECT_TRUE(p2.browser->is_type_popup());
528 EXPECT_TRUE(p2.browser->is_app());
[email protected]300d1e52011-01-19 23:57:57529
530 // We should now have four windows, the app window, the first app popup,
531 // the second app popup, and the original browser() provided by the framework.
[email protected]0665ebe2013-02-13 09:53:19532 EXPECT_EQ(4u, chrome::GetTotalBrowserCount());
[email protected]ee496952013-01-10 23:17:33533 EXPECT_EQ(1, browser()->tab_strip_model()->count());
534 EXPECT_EQ(1, app_browser->tab_strip_model()->count());
535 EXPECT_EQ(1, p1.browser->tab_strip_model()->count());
536 EXPECT_EQ(1, p2.browser->tab_strip_model()->count());
[email protected]300d1e52011-01-19 23:57:57537}
538
539// This test verifies that navigating with WindowOpenDisposition = NEW_POPUP
[email protected]a1feae52010-10-11 22:14:45540// from an extension app tab results in a new Browser with TYPE_APP_POPUP.
541IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
542 Disposition_NewPopupFromExtensionApp) {
543 // TODO(beng): TBD.
544}
545
[email protected]7d329992011-04-15 18:20:02546// This test verifies that navigating with window_action = SHOW_WINDOW_INACTIVE
547// does not focus a new new popup window.
548IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_NewPopupUnfocused) {
[email protected]78e2edc2012-07-01 23:32:28549 chrome::NavigateParams p(MakeNavigateParams());
[email protected]7d329992011-04-15 18:20:02550 p.disposition = NEW_POPUP;
[email protected]588300d2011-04-28 21:06:35551 p.window_bounds = gfx::Rect(0, 0, 200, 200);
[email protected]78e2edc2012-07-01 23:32:28552 p.window_action = chrome::NavigateParams::SHOW_WINDOW_INACTIVE;
[email protected]7d329992011-04-15 18:20:02553 // Wait for new popup to load (and gain focus if the test fails).
[email protected]ddddfda2011-07-14 23:19:39554 ui_test_utils::NavigateToURL(&p);
[email protected]7d329992011-04-15 18:20:02555
556 // Navigate() should have opened a new, unfocused, popup window.
557 EXPECT_NE(browser(), p.browser);
558 EXPECT_EQ(Browser::TYPE_POPUP, p.browser->type());
[email protected]9db263a2011-04-15 20:53:47559#if 0
560// TODO(stevenjb): Enable this test. See: crbug.com/79493
[email protected]7d329992011-04-15 18:20:02561 EXPECT_FALSE(p.browser->window()->IsActive());
[email protected]7d329992011-04-15 18:20:02562#endif
[email protected]9db263a2011-04-15 20:53:47563}
[email protected]7d329992011-04-15 18:20:02564
[email protected]a1feae52010-10-11 22:14:45565// This test verifies that navigating with WindowOpenDisposition = NEW_WINDOW
566// always opens a new window.
567IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_NewWindow) {
[email protected]78e2edc2012-07-01 23:32:28568 chrome::NavigateParams p(MakeNavigateParams());
[email protected]a1feae52010-10-11 22:14:45569 p.disposition = NEW_WINDOW;
[email protected]78e2edc2012-07-01 23:32:28570 chrome::Navigate(&p);
[email protected]a1feae52010-10-11 22:14:45571
572 // Navigate() should have opened a new toplevel window.
573 EXPECT_NE(browser(), p.browser);
[email protected]b35b26b32011-05-05 20:35:14574 EXPECT_TRUE(p.browser->is_type_tabbed());
[email protected]a1feae52010-10-11 22:14:45575
576 // We should now have two windows, the browser() provided by the framework and
577 // the new normal window.
[email protected]0665ebe2013-02-13 09:53:19578 EXPECT_EQ(2u, chrome::GetTotalBrowserCount());
[email protected]ee496952013-01-10 23:17:33579 EXPECT_EQ(1, browser()->tab_strip_model()->count());
580 EXPECT_EQ(1, p.browser->tab_strip_model()->count());
[email protected]a1feae52010-10-11 22:14:45581}
582
583// This test verifies that navigating with WindowOpenDisposition = INCOGNITO
584// opens a new incognito window if no existing incognito window is present.
585IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_Incognito) {
[email protected]78e2edc2012-07-01 23:32:28586 chrome::NavigateParams p(MakeNavigateParams());
[email protected]a1feae52010-10-11 22:14:45587 p.disposition = OFF_THE_RECORD;
[email protected]78e2edc2012-07-01 23:32:28588 chrome::Navigate(&p);
[email protected]a1feae52010-10-11 22:14:45589
590 // Navigate() should have opened a new toplevel incognito window.
591 EXPECT_NE(browser(), p.browser);
592 EXPECT_EQ(browser()->profile()->GetOffTheRecordProfile(),
593 p.browser->profile());
594
[email protected]d7ff3592010-11-30 21:50:46595 // |source_contents| should be set to NULL because the profile for the new
596 // page is different from the originating page.
597 EXPECT_EQ(NULL, p.source_contents);
598
[email protected]a1feae52010-10-11 22:14:45599 // We should now have two windows, the browser() provided by the framework and
600 // the new incognito window.
[email protected]0665ebe2013-02-13 09:53:19601 EXPECT_EQ(2u, chrome::GetTotalBrowserCount());
[email protected]ee496952013-01-10 23:17:33602 EXPECT_EQ(1, browser()->tab_strip_model()->count());
603 EXPECT_EQ(1, p.browser->tab_strip_model()->count());
[email protected]a1feae52010-10-11 22:14:45604}
605
606// This test verifies that navigating with WindowOpenDisposition = INCOGNITO
607// reuses an existing incognito window when possible.
608IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_IncognitoRefocus) {
609 Browser* incognito_browser =
[email protected]b35b26b32011-05-05 20:35:14610 CreateEmptyBrowserForType(Browser::TYPE_TABBED,
[email protected]a1feae52010-10-11 22:14:45611 browser()->profile()->GetOffTheRecordProfile());
[email protected]78e2edc2012-07-01 23:32:28612 chrome::NavigateParams p(MakeNavigateParams());
[email protected]a1feae52010-10-11 22:14:45613 p.disposition = OFF_THE_RECORD;
[email protected]78e2edc2012-07-01 23:32:28614 chrome::Navigate(&p);
[email protected]a1feae52010-10-11 22:14:45615
616 // Navigate() should have opened a new tab in the existing incognito window.
617 EXPECT_NE(browser(), p.browser);
618 EXPECT_EQ(p.browser, incognito_browser);
619
620 // We should now have two windows, the browser() provided by the framework and
621 // the incognito window we opened earlier.
[email protected]0665ebe2013-02-13 09:53:19622 EXPECT_EQ(2u, chrome::GetTotalBrowserCount());
[email protected]ee496952013-01-10 23:17:33623 EXPECT_EQ(1, browser()->tab_strip_model()->count());
624 EXPECT_EQ(2, incognito_browser->tab_strip_model()->count());
[email protected]a1feae52010-10-11 22:14:45625}
626
627// This test verifies that no navigation action occurs when
628// WindowOpenDisposition = SUPPRESS_OPEN.
629IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_SuppressOpen) {
630 RunSuppressTest(SUPPRESS_OPEN);
631}
632
633// This test verifies that no navigation action occurs when
634// WindowOpenDisposition = SAVE_TO_DISK.
635IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_SaveToDisk) {
636 RunSuppressTest(SAVE_TO_DISK);
637}
638
639// This test verifies that no navigation action occurs when
640// WindowOpenDisposition = IGNORE_ACTION.
641IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_IgnoreAction) {
642 RunSuppressTest(IGNORE_ACTION);
643}
644
[email protected]e232c992012-12-06 12:43:20645// This tests adding a foreground tab with a predefined WebContents.
[email protected]a1feae52010-10-11 22:14:45646IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, TargetContents_ForegroundTab) {
[email protected]78e2edc2012-07-01 23:32:28647 chrome::NavigateParams p(MakeNavigateParams());
[email protected]a1feae52010-10-11 22:14:45648 p.disposition = NEW_FOREGROUND_TAB;
[email protected]e232c992012-12-06 12:43:20649 p.target_contents = CreateWebContents();
[email protected]78e2edc2012-07-01 23:32:28650 chrome::Navigate(&p);
[email protected]a1feae52010-10-11 22:14:45651
652 // Navigate() should have opened the contents in a new foreground in the
653 // current Browser.
654 EXPECT_EQ(browser(), p.browser);
[email protected]e232c992012-12-06 12:43:20655 EXPECT_EQ(browser()->tab_strip_model()->GetActiveWebContents(),
[email protected]59253a652012-11-20 00:17:26656 p.target_contents);
[email protected]a1feae52010-10-11 22:14:45657
658 // We should have one window, with two tabs.
[email protected]0665ebe2013-02-13 09:53:19659 EXPECT_EQ(1u, chrome::GetTotalBrowserCount());
[email protected]ee496952013-01-10 23:17:33660 EXPECT_EQ(2, browser()->tab_strip_model()->count());
[email protected]a1feae52010-10-11 22:14:45661}
662
663#if defined(OS_WIN)
[email protected]e232c992012-12-06 12:43:20664// This tests adding a popup with a predefined WebContents.
[email protected]76edb672011-03-04 21:48:39665IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, DISABLED_TargetContents_Popup) {
[email protected]78e2edc2012-07-01 23:32:28666 chrome::NavigateParams p(MakeNavigateParams());
[email protected]a1feae52010-10-11 22:14:45667 p.disposition = NEW_POPUP;
[email protected]e232c992012-12-06 12:43:20668 p.target_contents = CreateWebContents();
[email protected]a1feae52010-10-11 22:14:45669 p.window_bounds = gfx::Rect(10, 10, 500, 500);
[email protected]78e2edc2012-07-01 23:32:28670 chrome::Navigate(&p);
[email protected]a1feae52010-10-11 22:14:45671
672 // Navigate() should have opened a new popup window.
673 EXPECT_NE(browser(), p.browser);
[email protected]b35b26b32011-05-05 20:35:14674 EXPECT_TRUE(p.browser->is_type_popup());
675 EXPECT_FALSE(p.browser->is_app());
[email protected]a1feae52010-10-11 22:14:45676
677 // The web platform is weird. The window bounds specified in
678 // |p.window_bounds| are used as follows:
679 // - the origin is used to position the window
[email protected]e232c992012-12-06 12:43:20680 // - the size is used to size the WebContents of the window.
[email protected]a1feae52010-10-11 22:14:45681 // As such the position of the resulting window will always match
682 // p.window_bounds.origin(), but its size will not. We need to match
683 // the size against the selected tab's view's container size.
684 // Only Windows positions the window according to |p.window_bounds.origin()| -
685 // on Mac the window is offset from the opener and on Linux it always opens
686 // at 0,0.
687 EXPECT_EQ(p.window_bounds.origin(),
688 p.browser->window()->GetRestoredBounds().origin());
689 // All platforms should respect size however provided width > 400 (Mac has a
690 // minimum window width of 400).
691 EXPECT_EQ(p.window_bounds.size(),
[email protected]e232c992012-12-06 12:43:20692 p.target_contents->GetView()->GetContainerSize());
[email protected]a1feae52010-10-11 22:14:45693
694 // We should have two windows, the new popup and the browser() provided by the
695 // framework.
[email protected]0665ebe2013-02-13 09:53:19696 EXPECT_EQ(2u, chrome::GetTotalBrowserCount());
[email protected]ee496952013-01-10 23:17:33697 EXPECT_EQ(1, browser()->tab_strip_model()->count());
698 EXPECT_EQ(1, p.browser->tab_strip_model()->count());
[email protected]a1feae52010-10-11 22:14:45699}
700#endif
701
702// This tests adding a tab at a specific index.
703IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Tabstrip_InsertAtIndex) {
704 // This is not meant to be a comprehensive test of whether or not the tab
705 // implementation of the browser observes the insertion index. That is
706 // covered by the unit tests for TabStripModel. This merely verifies that
707 // insertion index preference is reflected in common cases.
[email protected]78e2edc2012-07-01 23:32:28708 chrome::NavigateParams p(MakeNavigateParams());
[email protected]a1feae52010-10-11 22:14:45709 p.disposition = NEW_FOREGROUND_TAB;
710 p.tabstrip_index = 0;
711 p.tabstrip_add_types = TabStripModel::ADD_FORCE_INDEX;
[email protected]78e2edc2012-07-01 23:32:28712 chrome::Navigate(&p);
[email protected]a1feae52010-10-11 22:14:45713
714 // Navigate() should have inserted a new tab at slot 0 in the tabstrip.
715 EXPECT_EQ(browser(), p.browser);
[email protected]e232c992012-12-06 12:43:20716 EXPECT_EQ(0, browser()->tab_strip_model()->GetIndexOfWebContents(
717 static_cast<const WebContents*>(p.target_contents)));
[email protected]a1feae52010-10-11 22:14:45718
719 // We should have one window - the browser() provided by the framework.
[email protected]0665ebe2013-02-13 09:53:19720 EXPECT_EQ(1u, chrome::GetTotalBrowserCount());
[email protected]ee496952013-01-10 23:17:33721 EXPECT_EQ(2, browser()->tab_strip_model()->count());
[email protected]a1feae52010-10-11 22:14:45722}
723
[email protected]bb89e7482010-11-17 18:27:04724// This test verifies that constructing params with disposition = SINGLETON_TAB
[email protected]fee320542011-03-02 01:30:49725// and IGNORE_AND_NAVIGATE opens a new tab navigated to the specified URL if
[email protected]67ed83e2011-01-07 22:54:00726// no previous tab with that URL (minus the path) exists.
[email protected]bb89e7482010-11-17 18:27:04727IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
728 Disposition_SingletonTabNew_IgnorePath) {
[email protected]52877dbc62012-06-29 22:22:03729 chrome::AddSelectedTabWithURL(browser(), GetGoogleURL(),
730 content::PAGE_TRANSITION_LINK);
[email protected]bb89e7482010-11-17 18:27:04731
732 // We should have one browser with 2 tabs, the 2nd selected.
[email protected]0665ebe2013-02-13 09:53:19733 EXPECT_EQ(1u, chrome::GetTotalBrowserCount());
[email protected]ee496952013-01-10 23:17:33734 EXPECT_EQ(2, browser()->tab_strip_model()->count());
735 EXPECT_EQ(1, browser()->tab_strip_model()->active_index());
[email protected]bb89e7482010-11-17 18:27:04736
737 // Navigate to a new singleton tab with a sub-page.
[email protected]78e2edc2012-07-01 23:32:28738 chrome::NavigateParams p(MakeNavigateParams());
[email protected]bb89e7482010-11-17 18:27:04739 p.disposition = SINGLETON_TAB;
[email protected]a048ad22012-03-23 04:26:56740 p.url = GetContentSettingsURL();
[email protected]50592b52013-05-02 22:26:25741 p.window_action = chrome::NavigateParams::SHOW_WINDOW;
[email protected]78e2edc2012-07-01 23:32:28742 p.path_behavior = chrome::NavigateParams::IGNORE_AND_NAVIGATE;
743 chrome::Navigate(&p);
[email protected]bb89e7482010-11-17 18:27:04744
745 // The last tab should now be selected and navigated to the sub-page of the
[email protected]50592b52013-05-02 22:26:25746 // URL.
[email protected]bb89e7482010-11-17 18:27:04747 EXPECT_EQ(browser(), p.browser);
[email protected]ee496952013-01-10 23:17:33748 EXPECT_EQ(3, browser()->tab_strip_model()->count());
749 EXPECT_EQ(2, browser()->tab_strip_model()->active_index());
[email protected]a048ad22012-03-23 04:26:56750 EXPECT_EQ(GetContentSettingsURL(),
[email protected]ee496952013-01-10 23:17:33751 ShortenUberURL(browser()->tab_strip_model()->
752 GetActiveWebContents()->GetURL()));
[email protected]bb89e7482010-11-17 18:27:04753}
754
755// This test verifies that constructing params with disposition = SINGLETON_TAB
[email protected]fee320542011-03-02 01:30:49756// and IGNORE_AND_NAVIGATE opens an existing tab with the matching URL (minus
[email protected]bb89e7482010-11-17 18:27:04757// the path) which is navigated to the specified URL.
758IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
759 Disposition_SingletonTabExisting_IgnorePath) {
[email protected]ddddfda2011-07-14 23:19:39760 GURL singleton_url1(GetSettingsURL());
[email protected]52877dbc62012-06-29 22:22:03761 chrome::AddSelectedTabWithURL(browser(), singleton_url1,
762 content::PAGE_TRANSITION_LINK);
763 chrome::AddSelectedTabWithURL(browser(), GetGoogleURL(),
764 content::PAGE_TRANSITION_LINK);
[email protected]bb89e7482010-11-17 18:27:04765
766 // We should have one browser with 3 tabs, the 3rd selected.
[email protected]0665ebe2013-02-13 09:53:19767 EXPECT_EQ(1u, chrome::GetTotalBrowserCount());
[email protected]ee496952013-01-10 23:17:33768 EXPECT_EQ(3, browser()->tab_strip_model()->count());
769 EXPECT_EQ(2, browser()->tab_strip_model()->active_index());
[email protected]bb89e7482010-11-17 18:27:04770
771 // Navigate to singleton_url1.
[email protected]78e2edc2012-07-01 23:32:28772 chrome::NavigateParams p(MakeNavigateParams());
[email protected]bb89e7482010-11-17 18:27:04773 p.disposition = SINGLETON_TAB;
[email protected]a048ad22012-03-23 04:26:56774 p.url = GetContentSettingsURL();
[email protected]50592b52013-05-02 22:26:25775 p.window_action = chrome::NavigateParams::SHOW_WINDOW;
[email protected]78e2edc2012-07-01 23:32:28776 p.path_behavior = chrome::NavigateParams::IGNORE_AND_NAVIGATE;
777 chrome::Navigate(&p);
[email protected]bb89e7482010-11-17 18:27:04778
779 // The middle tab should now be selected and navigated to the sub-page of the
780 // URL.
781 EXPECT_EQ(browser(), p.browser);
[email protected]ee496952013-01-10 23:17:33782 EXPECT_EQ(3, browser()->tab_strip_model()->count());
783 EXPECT_EQ(1, browser()->tab_strip_model()->active_index());
[email protected]a048ad22012-03-23 04:26:56784 EXPECT_EQ(GetContentSettingsURL(),
[email protected]ee496952013-01-10 23:17:33785 ShortenUberURL(browser()->tab_strip_model()->
786 GetActiveWebContents()->GetURL()));
[email protected]bb89e7482010-11-17 18:27:04787}
788
789// This test verifies that constructing params with disposition = SINGLETON_TAB
[email protected]fee320542011-03-02 01:30:49790// and IGNORE_AND_NAVIGATE opens an existing tab with the matching URL (minus
[email protected]bb89e7482010-11-17 18:27:04791// the path) which is navigated to the specified URL.
792IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
793 Disposition_SingletonTabExistingSubPath_IgnorePath) {
[email protected]a048ad22012-03-23 04:26:56794 GURL singleton_url1(GetContentSettingsURL());
[email protected]52877dbc62012-06-29 22:22:03795 chrome::AddSelectedTabWithURL(browser(), singleton_url1,
796 content::PAGE_TRANSITION_LINK);
797 chrome::AddSelectedTabWithURL(browser(), GetGoogleURL(),
798 content::PAGE_TRANSITION_LINK);
[email protected]bb89e7482010-11-17 18:27:04799
800 // We should have one browser with 3 tabs, the 3rd selected.
[email protected]0665ebe2013-02-13 09:53:19801 EXPECT_EQ(1u, chrome::GetTotalBrowserCount());
[email protected]ee496952013-01-10 23:17:33802 EXPECT_EQ(3, browser()->tab_strip_model()->count());
803 EXPECT_EQ(2, browser()->tab_strip_model()->active_index());
[email protected]bb89e7482010-11-17 18:27:04804
805 // Navigate to singleton_url1.
[email protected]78e2edc2012-07-01 23:32:28806 chrome::NavigateParams p(MakeNavigateParams());
[email protected]bb89e7482010-11-17 18:27:04807 p.disposition = SINGLETON_TAB;
[email protected]a048ad22012-03-23 04:26:56808 p.url = GetClearBrowsingDataURL();
[email protected]50592b52013-05-02 22:26:25809 p.window_action = chrome::NavigateParams::SHOW_WINDOW;
[email protected]78e2edc2012-07-01 23:32:28810 p.path_behavior = chrome::NavigateParams::IGNORE_AND_NAVIGATE;
811 chrome::Navigate(&p);
[email protected]bb89e7482010-11-17 18:27:04812
813 // The middle tab should now be selected and navigated to the sub-page of the
814 // URL.
815 EXPECT_EQ(browser(), p.browser);
[email protected]ee496952013-01-10 23:17:33816 EXPECT_EQ(3, browser()->tab_strip_model()->count());
817 EXPECT_EQ(1, browser()->tab_strip_model()->active_index());
[email protected]a048ad22012-03-23 04:26:56818 EXPECT_EQ(GetClearBrowsingDataURL(),
[email protected]ee496952013-01-10 23:17:33819 ShortenUberURL(browser()->tab_strip_model()->
820 GetActiveWebContents()->GetURL()));
[email protected]bb89e7482010-11-17 18:27:04821}
[email protected]2dd85482010-11-06 01:56:47822
[email protected]637b3442011-01-10 23:31:48823// This test verifies that constructing params with disposition = SINGLETON_TAB
[email protected]fee320542011-03-02 01:30:49824// and IGNORE_AND_STAY_PUT opens an existing tab with the matching URL (minus
825// the path).
826IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
827 Disposition_SingletonTabExistingSubPath_IgnorePath2) {
[email protected]a048ad22012-03-23 04:26:56828 GURL singleton_url1(GetContentSettingsURL());
[email protected]52877dbc62012-06-29 22:22:03829 chrome::AddSelectedTabWithURL(browser(), singleton_url1,
830 content::PAGE_TRANSITION_LINK);
831 chrome::AddSelectedTabWithURL(browser(), GetGoogleURL(),
832 content::PAGE_TRANSITION_LINK);
[email protected]fee320542011-03-02 01:30:49833
834 // We should have one browser with 3 tabs, the 3rd selected.
[email protected]0665ebe2013-02-13 09:53:19835 EXPECT_EQ(1u, chrome::GetTotalBrowserCount());
[email protected]ee496952013-01-10 23:17:33836 EXPECT_EQ(3, browser()->tab_strip_model()->count());
837 EXPECT_EQ(2, browser()->tab_strip_model()->active_index());
[email protected]fee320542011-03-02 01:30:49838
839 // Navigate to singleton_url1.
[email protected]78e2edc2012-07-01 23:32:28840 chrome::NavigateParams p(MakeNavigateParams());
[email protected]fee320542011-03-02 01:30:49841 p.disposition = SINGLETON_TAB;
[email protected]a048ad22012-03-23 04:26:56842 p.url = GetClearBrowsingDataURL();
[email protected]50592b52013-05-02 22:26:25843 p.window_action = chrome::NavigateParams::SHOW_WINDOW;
[email protected]78e2edc2012-07-01 23:32:28844 p.path_behavior = chrome::NavigateParams::IGNORE_AND_STAY_PUT;
845 chrome::Navigate(&p);
[email protected]fee320542011-03-02 01:30:49846
847 // The middle tab should now be selected.
848 EXPECT_EQ(browser(), p.browser);
[email protected]ee496952013-01-10 23:17:33849 EXPECT_EQ(3, browser()->tab_strip_model()->count());
850 EXPECT_EQ(1, browser()->tab_strip_model()->active_index());
[email protected]fee320542011-03-02 01:30:49851 EXPECT_EQ(singleton_url1,
[email protected]ee496952013-01-10 23:17:33852 ShortenUberURL(browser()->tab_strip_model()->
853 GetActiveWebContents()->GetURL()));
[email protected]fee320542011-03-02 01:30:49854}
855
856// This test verifies that constructing params with disposition = SINGLETON_TAB
857// and IGNORE_AND_NAVIGATE will update the current tab's URL if the currently
[email protected]637b3442011-01-10 23:31:48858// selected tab is a match but has a different path.
859IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
860 Disposition_SingletonTabFocused_IgnorePath) {
[email protected]a048ad22012-03-23 04:26:56861 GURL singleton_url_current(GetContentSettingsURL());
[email protected]52877dbc62012-06-29 22:22:03862 chrome::AddSelectedTabWithURL(browser(), singleton_url_current,
863 content::PAGE_TRANSITION_LINK);
[email protected]637b3442011-01-10 23:31:48864
865 // We should have one browser with 2 tabs, the 2nd selected.
[email protected]0665ebe2013-02-13 09:53:19866 EXPECT_EQ(1u, chrome::GetTotalBrowserCount());
[email protected]ee496952013-01-10 23:17:33867 EXPECT_EQ(2, browser()->tab_strip_model()->count());
868 EXPECT_EQ(1, browser()->tab_strip_model()->active_index());
[email protected]637b3442011-01-10 23:31:48869
870 // Navigate to a different settings path.
[email protected]a048ad22012-03-23 04:26:56871 GURL singleton_url_target(GetClearBrowsingDataURL());
[email protected]78e2edc2012-07-01 23:32:28872 chrome::NavigateParams p(MakeNavigateParams());
[email protected]637b3442011-01-10 23:31:48873 p.disposition = SINGLETON_TAB;
874 p.url = singleton_url_target;
[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_NAVIGATE;
877 chrome::Navigate(&p);
[email protected]637b3442011-01-10 23:31:48878
879 // The second tab should still be selected, but navigated to the new path.
880 EXPECT_EQ(browser(), p.browser);
[email protected]ee496952013-01-10 23:17:33881 EXPECT_EQ(2, browser()->tab_strip_model()->count());
882 EXPECT_EQ(1, browser()->tab_strip_model()->active_index());
[email protected]637b3442011-01-10 23:31:48883 EXPECT_EQ(singleton_url_target,
[email protected]ee496952013-01-10 23:17:33884 ShortenUberURL(browser()->tab_strip_model()->
885 GetActiveWebContents()->GetURL()));
[email protected]637b3442011-01-10 23:31:48886}
887
[email protected]07afd7c2011-02-17 10:07:11888// This test verifies that constructing params with disposition = SINGLETON_TAB
[email protected]fee320542011-03-02 01:30:49889// and IGNORE_AND_NAVIGATE will open an existing matching tab with a different
890// query.
[email protected]07afd7c2011-02-17 10:07:11891IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
892 Disposition_SingletonTabExisting_IgnoreQuery) {
[email protected]ee496952013-01-10 23:17:33893 int initial_tab_count = browser()->tab_strip_model()->count();
[email protected]07afd7c2011-02-17 10:07:11894 GURL singleton_url_current("chrome://settings/internet");
[email protected]52877dbc62012-06-29 22:22:03895 chrome::AddSelectedTabWithURL(browser(), singleton_url_current,
896 content::PAGE_TRANSITION_LINK);
[email protected]07afd7c2011-02-17 10:07:11897
[email protected]ee496952013-01-10 23:17:33898 EXPECT_EQ(initial_tab_count + 1, browser()->tab_strip_model()->count());
899 EXPECT_EQ(initial_tab_count, browser()->tab_strip_model()->active_index());
[email protected]07afd7c2011-02-17 10:07:11900
901 // Navigate to a different settings path.
902 GURL singleton_url_target(
903 "chrome://settings/internet?"
904 "servicePath=/profile/ethernet_00aa00aa00aa&networkType=1");
[email protected]78e2edc2012-07-01 23:32:28905 chrome::NavigateParams p(MakeNavigateParams());
[email protected]07afd7c2011-02-17 10:07:11906 p.disposition = SINGLETON_TAB;
907 p.url = singleton_url_target;
[email protected]50592b52013-05-02 22:26:25908 p.window_action = chrome::NavigateParams::SHOW_WINDOW;
[email protected]78e2edc2012-07-01 23:32:28909 p.path_behavior = chrome::NavigateParams::IGNORE_AND_NAVIGATE;
910 chrome::Navigate(&p);
[email protected]07afd7c2011-02-17 10:07:11911
912 // Last tab should still be selected.
913 EXPECT_EQ(browser(), p.browser);
[email protected]ee496952013-01-10 23:17:33914 EXPECT_EQ(initial_tab_count + 1, browser()->tab_strip_model()->count());
915 EXPECT_EQ(initial_tab_count, browser()->tab_strip_model()->active_index());
[email protected]07afd7c2011-02-17 10:07:11916}
917
[email protected]bd817c22011-02-09 08:16:46918// This test verifies that the settings page isn't opened in the incognito
919// window.
[email protected]a048ad22012-03-23 04:26:56920// Disabled until fixed for uber settings: http://crbug.com/111243
[email protected]bd817c22011-02-09 08:16:46921IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
[email protected]a048ad22012-03-23 04:26:56922 DISABLED_Disposition_Settings_UseNonIncognitoWindow) {
[email protected]fc0ed302011-11-29 23:17:19923 RunUseNonIncognitoWindowTest(GetSettingsURL());
[email protected]bd817c22011-02-09 08:16:46924}
925
[email protected]429e9712013-04-30 09:35:50926// This test verifies that the view-source settings page isn't opened in the
927// incognito window.
928IN_PROC_BROWSER_TEST_F(
929 BrowserNavigatorTest,
930 Disposition_ViewSource_Settings_DoNothingIfIncognitoForced) {
[email protected]dbdda5402013-05-30 22:13:48931 std::string view_source(content::kViewSourceScheme);
[email protected]429e9712013-04-30 09:35:50932 view_source.append(":");
933 view_source.append(chrome::kChromeUISettingsURL);
934 RunDoNothingIfIncognitoIsForcedTest(GURL(view_source));
935}
936
937// This test verifies that the view-source settings page isn't opened in the
938// incognito window even if incognito mode is forced (does nothing in that
939// case).
940IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
941 Disposition_ViewSource_Settings_UseNonIncognitoWindow) {
[email protected]dbdda5402013-05-30 22:13:48942 std::string view_source(content::kViewSourceScheme);
[email protected]429e9712013-04-30 09:35:50943 view_source.append(":");
944 view_source.append(chrome::kChromeUISettingsURL);
945 RunUseNonIncognitoWindowTest(GURL(view_source));
946}
947
[email protected]82404cd2011-07-12 19:55:14948// This test verifies that the settings page isn't opened in the incognito
949// window from a non-incognito window (bookmark open-in-incognito trigger).
[email protected]a048ad22012-03-23 04:26:56950// Disabled until fixed for uber settings: http://crbug.com/111243
[email protected]82404cd2011-07-12 19:55:14951IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
[email protected]a048ad22012-03-23 04:26:56952 DISABLED_Disposition_Settings_UseNonIncognitoWindowForBookmark) {
[email protected]78e2edc2012-07-01 23:32:28953 chrome::NavigateParams params(browser(), GetSettingsURL(),
954 content::PAGE_TRANSITION_AUTO_BOOKMARK);
[email protected]82404cd2011-07-12 19:55:14955 params.disposition = OFF_THE_RECORD;
956 {
[email protected]a7fe9112012-07-20 02:34:45957 content::WindowedNotificationObserver observer(
[email protected]ad50def52011-10-19 23:17:07958 content::NOTIFICATION_LOAD_STOP,
959 content::NotificationService::AllSources());
[email protected]78e2edc2012-07-01 23:32:28960 chrome::Navigate(&params);
[email protected]82404cd2011-07-12 19:55:14961 observer.Wait();
962 }
963
[email protected]0665ebe2013-02-13 09:53:19964 EXPECT_EQ(1u, chrome::GetTotalBrowserCount());
[email protected]52877dbc62012-06-29 22:22:03965 EXPECT_EQ(GetSettingsURL(),
[email protected]ee496952013-01-10 23:17:33966 ShortenUberURL(browser()->tab_strip_model()->
967 GetActiveWebContents()->GetURL()));
[email protected]82404cd2011-07-12 19:55:14968}
969
[email protected]93ad8e1c2011-11-08 21:34:05970// Settings page is expected to always open in normal mode regardless
971// of whether the user is trying to open it in incognito mode or not.
972// This test verifies that if incognito mode is forced (by policy), settings
973// page doesn't open at all.
[email protected]a048ad22012-03-23 04:26:56974// Disabled until fixed for uber settings: http://crbug.com/111243
[email protected]93ad8e1c2011-11-08 21:34:05975IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
[email protected]a048ad22012-03-23 04:26:56976 DISABLED_Disposition_Settings_DoNothingIfIncognitoIsForced) {
[email protected]fc0ed302011-11-29 23:17:19977 RunDoNothingIfIncognitoIsForcedTest(GetSettingsURL());
[email protected]93ad8e1c2011-11-08 21:34:05978}
979
[email protected]bd817c22011-02-09 08:16:46980// This test verifies that the bookmarks page isn't opened in the incognito
981// window.
982IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
983 Disposition_Bookmarks_UseNonIncognitoWindow) {
[email protected]fc0ed302011-11-29 23:17:19984 RunUseNonIncognitoWindowTest(GURL(chrome::kChromeUIBookmarksURL));
[email protected]bd817c22011-02-09 08:16:46985}
986
[email protected]93ad8e1c2011-11-08 21:34:05987// Bookmark manager is expected to always open in normal mode regardless
988// of whether the user is trying to open it in incognito mode or not.
989// This test verifies that if incognito mode is forced (by policy), bookmark
990// manager doesn't open at all.
991IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
992 Disposition_Bookmarks_DoNothingIfIncognitoIsForced) {
[email protected]fc0ed302011-11-29 23:17:19993 RunDoNothingIfIncognitoIsForcedTest(GURL(chrome::kChromeUIBookmarksURL));
994}
[email protected]93ad8e1c2011-11-08 21:34:05995
[email protected]fc0ed302011-11-29 23:17:19996// This test verifies that the sync promo page isn't opened in the incognito
997// window.
998IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
999 Disposition_SyncPromo_UseNonIncognitoWindow) {
1000 RunUseNonIncognitoWindowTest(GURL(chrome::kChromeUISyncPromoURL));
1001}
[email protected]93ad8e1c2011-11-08 21:34:051002
[email protected]fc0ed302011-11-29 23:17:191003// The Sync promo page is expected to always open in normal mode regardless of
1004// whether the user is trying to open it in incognito mode or not. This test
1005// verifies that if incognito mode is forced (by policy), the sync promo page
1006// doesn't open at all.
1007IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
1008 Disposition_SyncPromo_DoNothingIfIncognitoIsForced) {
1009 RunDoNothingIfIncognitoIsForcedTest(GURL(chrome::kChromeUISyncPromoURL));
[email protected]93ad8e1c2011-11-08 21:34:051010}
1011
[email protected]7de53c62011-05-13 06:44:161012// This test makes sure a crashed singleton tab reloads from a new navigation.
1013IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
1014 NavigateToCrashedSingletonTab) {
[email protected]a048ad22012-03-23 04:26:561015 GURL singleton_url(GetContentSettingsURL());
[email protected]5a1a52462012-11-15 03:35:161016 WebContents* web_contents = chrome::AddSelectedTabWithURL(
[email protected]52877dbc62012-06-29 22:22:031017 browser(), singleton_url, content::PAGE_TRANSITION_LINK);
[email protected]7de53c62011-05-13 06:44:161018
1019 // We should have one browser with 2 tabs, the 2nd selected.
[email protected]0665ebe2013-02-13 09:53:191020 EXPECT_EQ(1u, chrome::GetTotalBrowserCount());
[email protected]ee496952013-01-10 23:17:331021 EXPECT_EQ(2, browser()->tab_strip_model()->count());
1022 EXPECT_EQ(1, browser()->tab_strip_model()->active_index());
[email protected]7de53c62011-05-13 06:44:161023
1024 // Kill the singleton tab.
[email protected]83ff91c2012-01-05 20:54:131025 web_contents->SetIsCrashed(base::TERMINATION_STATUS_PROCESS_CRASHED, -1);
1026 EXPECT_TRUE(web_contents->IsCrashed());
[email protected]7de53c62011-05-13 06:44:161027
[email protected]78e2edc2012-07-01 23:32:281028 chrome::NavigateParams p(MakeNavigateParams());
[email protected]7de53c62011-05-13 06:44:161029 p.disposition = SINGLETON_TAB;
1030 p.url = singleton_url;
[email protected]50592b52013-05-02 22:26:251031 p.window_action = chrome::NavigateParams::SHOW_WINDOW;
[email protected]78e2edc2012-07-01 23:32:281032 p.path_behavior = chrome::NavigateParams::IGNORE_AND_NAVIGATE;
[email protected]ddddfda2011-07-14 23:19:391033 ui_test_utils::NavigateToURL(&p);
[email protected]7de53c62011-05-13 06:44:161034
1035 // The tab should not be sad anymore.
[email protected]83ff91c2012-01-05 20:54:131036 EXPECT_FALSE(web_contents->IsCrashed());
[email protected]7de53c62011-05-13 06:44:161037}
1038
[email protected]fcca741b2011-06-17 22:46:371039IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
1040 NavigateFromDefaultToOptionsInSameTab) {
[email protected]ddddfda2011-07-14 23:19:391041 {
[email protected]a7fe9112012-07-20 02:34:451042 content::WindowedNotificationObserver observer(
[email protected]ad50def52011-10-19 23:17:071043 content::NOTIFICATION_LOAD_STOP,
1044 content::NotificationService::AllSources());
[email protected]5d9cace72012-06-21 16:07:121045 chrome::ShowSettings(browser());
[email protected]ddddfda2011-07-14 23:19:391046 observer.Wait();
1047 }
[email protected]ee496952013-01-10 23:17:331048 EXPECT_EQ(1, browser()->tab_strip_model()->count());
[email protected]52877dbc62012-06-29 22:22:031049 EXPECT_EQ(GetSettingsURL(),
[email protected]ee496952013-01-10 23:17:331050 ShortenUberURL(browser()->tab_strip_model()->
1051 GetActiveWebContents()->GetURL()));
[email protected]fcca741b2011-06-17 22:46:371052}
1053
1054IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
1055 NavigateFromBlankToOptionsInSameTab) {
[email protected]78e2edc2012-07-01 23:32:281056 chrome::NavigateParams p(MakeNavigateParams());
[email protected]081dc522013-05-15 04:59:201057 p.url = GURL(content::kAboutBlankURL);
[email protected]ddddfda2011-07-14 23:19:391058 ui_test_utils::NavigateToURL(&p);
[email protected]fcca741b2011-06-17 22:46:371059
[email protected]ddddfda2011-07-14 23:19:391060 {
[email protected]a7fe9112012-07-20 02:34:451061 content::WindowedNotificationObserver observer(
[email protected]ad50def52011-10-19 23:17:071062 content::NOTIFICATION_LOAD_STOP,
1063 content::NotificationService::AllSources());
[email protected]5d9cace72012-06-21 16:07:121064 chrome::ShowSettings(browser());
[email protected]ddddfda2011-07-14 23:19:391065 observer.Wait();
1066 }
[email protected]ee496952013-01-10 23:17:331067 EXPECT_EQ(1, browser()->tab_strip_model()->count());
[email protected]52877dbc62012-06-29 22:22:031068 EXPECT_EQ(GetSettingsURL(),
[email protected]ee496952013-01-10 23:17:331069 ShortenUberURL(browser()->tab_strip_model()->
1070 GetActiveWebContents()->GetURL()));
[email protected]fcca741b2011-06-17 22:46:371071}
1072
1073IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
1074 NavigateFromNTPToOptionsInSameTab) {
[email protected]78e2edc2012-07-01 23:32:281075 chrome::NavigateParams p(MakeNavigateParams());
[email protected]ddddfda2011-07-14 23:19:391076 p.url = GURL(chrome::kChromeUINewTabURL);
1077 ui_test_utils::NavigateToURL(&p);
[email protected]ee496952013-01-10 23:17:331078 EXPECT_EQ(1, browser()->tab_strip_model()->count());
[email protected]ddddfda2011-07-14 23:19:391079 EXPECT_EQ(GURL(chrome::kChromeUINewTabURL),
[email protected]ee496952013-01-10 23:17:331080 browser()->tab_strip_model()->GetActiveWebContents()->GetURL());
[email protected]fcca741b2011-06-17 22:46:371081
[email protected]ddddfda2011-07-14 23:19:391082 {
[email protected]a7fe9112012-07-20 02:34:451083 content::WindowedNotificationObserver observer(
[email protected]ad50def52011-10-19 23:17:071084 content::NOTIFICATION_LOAD_STOP,
1085 content::NotificationService::AllSources());
[email protected]5d9cace72012-06-21 16:07:121086 chrome::ShowSettings(browser());
[email protected]ddddfda2011-07-14 23:19:391087 observer.Wait();
1088 }
[email protected]ee496952013-01-10 23:17:331089 EXPECT_EQ(1, browser()->tab_strip_model()->count());
[email protected]52877dbc62012-06-29 22:22:031090 EXPECT_EQ(GetSettingsURL(),
[email protected]ee496952013-01-10 23:17:331091 ShortenUberURL(browser()->tab_strip_model()->
1092 GetActiveWebContents()->GetURL()));
[email protected]fcca741b2011-06-17 22:46:371093}
1094
1095IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
1096 NavigateFromPageToOptionsInNewTab) {
[email protected]78e2edc2012-07-01 23:32:281097 chrome::NavigateParams p(MakeNavigateParams());
[email protected]ddddfda2011-07-14 23:19:391098 ui_test_utils::NavigateToURL(&p);
[email protected]ee496952013-01-10 23:17:331099 EXPECT_EQ(GetGoogleURL(),
1100 browser()->tab_strip_model()->GetActiveWebContents()->GetURL());
[email protected]0665ebe2013-02-13 09:53:191101 EXPECT_EQ(1u, chrome::GetTotalBrowserCount());
[email protected]ee496952013-01-10 23:17:331102 EXPECT_EQ(1, browser()->tab_strip_model()->count());
[email protected]fcca741b2011-06-17 22:46:371103
[email protected]ddddfda2011-07-14 23:19:391104 {
[email protected]a7fe9112012-07-20 02:34:451105 content::WindowedNotificationObserver observer(
[email protected]ad50def52011-10-19 23:17:071106 content::NOTIFICATION_LOAD_STOP,
1107 content::NotificationService::AllSources());
[email protected]5d9cace72012-06-21 16:07:121108 chrome::ShowSettings(browser());
[email protected]ddddfda2011-07-14 23:19:391109 observer.Wait();
1110 }
[email protected]ee496952013-01-10 23:17:331111 EXPECT_EQ(2, browser()->tab_strip_model()->count());
[email protected]52877dbc62012-06-29 22:22:031112 EXPECT_EQ(GetSettingsURL(),
[email protected]ee496952013-01-10 23:17:331113 ShortenUberURL(browser()->tab_strip_model()->
1114 GetActiveWebContents()->GetURL()));
[email protected]fcca741b2011-06-17 22:46:371115}
1116
1117IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
1118 NavigateFromNTPToOptionsSingleton) {
[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]fcca741b2011-06-17 22:46:371127
[email protected]a37d4b02012-06-25 21:56:101128 chrome::NewTab(browser());
[email protected]ee496952013-01-10 23:17:331129 EXPECT_EQ(2, browser()->tab_strip_model()->count());
[email protected]fcca741b2011-06-17 22:46:371130
[email protected]ddddfda2011-07-14 23:19:391131 {
[email protected]a7fe9112012-07-20 02:34:451132 content::WindowedNotificationObserver observer(
[email protected]ad50def52011-10-19 23:17:071133 content::NOTIFICATION_LOAD_STOP,
1134 content::NotificationService::AllSources());
[email protected]5d9cace72012-06-21 16:07:121135 chrome::ShowSettings(browser());
[email protected]ddddfda2011-07-14 23:19:391136 observer.Wait();
1137 }
[email protected]ee496952013-01-10 23:17:331138 EXPECT_EQ(2, browser()->tab_strip_model()->count());
[email protected]52877dbc62012-06-29 22:22:031139 EXPECT_EQ(GetSettingsURL(),
[email protected]ee496952013-01-10 23:17:331140 ShortenUberURL(browser()->tab_strip_model()->
1141 GetActiveWebContents()->GetURL()));
[email protected]fcca741b2011-06-17 22:46:371142}
1143
1144IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
1145 NavigateFromNTPToOptionsPageInSameTab) {
[email protected]ddddfda2011-07-14 23:19:391146 {
[email protected]a7fe9112012-07-20 02:34:451147 content::WindowedNotificationObserver observer(
[email protected]ad50def52011-10-19 23:17:071148 content::NOTIFICATION_LOAD_STOP,
1149 content::NotificationService::AllSources());
[email protected]5d9cace72012-06-21 16:07:121150 chrome::ShowClearBrowsingDataDialog(browser());
[email protected]ddddfda2011-07-14 23:19:391151 observer.Wait();
1152 }
[email protected]ee496952013-01-10 23:17:331153 EXPECT_EQ(1, browser()->tab_strip_model()->count());
[email protected]a048ad22012-03-23 04:26:561154 EXPECT_EQ(GetClearBrowsingDataURL(),
[email protected]ee496952013-01-10 23:17:331155 browser()->tab_strip_model()->GetActiveWebContents()->GetURL());
[email protected]fcca741b2011-06-17 22:46:371156
[email protected]a37d4b02012-06-25 21:56:101157 chrome::NewTab(browser());
[email protected]ee496952013-01-10 23:17:331158 EXPECT_EQ(2, browser()->tab_strip_model()->count());
[email protected]fcca741b2011-06-17 22:46:371159
[email protected]ddddfda2011-07-14 23:19:391160 {
[email protected]a7fe9112012-07-20 02:34:451161 content::WindowedNotificationObserver observer(
[email protected]ad50def52011-10-19 23:17:071162 content::NOTIFICATION_LOAD_STOP,
1163 content::NotificationService::AllSources());
[email protected]5d9cace72012-06-21 16:07:121164 chrome::ShowClearBrowsingDataDialog(browser());
[email protected]ddddfda2011-07-14 23:19:391165 observer.Wait();
1166 }
[email protected]ee496952013-01-10 23:17:331167 EXPECT_EQ(2, browser()->tab_strip_model()->count());
[email protected]a048ad22012-03-23 04:26:561168 EXPECT_EQ(GetClearBrowsingDataURL(),
[email protected]ee496952013-01-10 23:17:331169 browser()->tab_strip_model()->GetActiveWebContents()->GetURL());
[email protected]fcca741b2011-06-17 22:46:371170}
1171
[email protected]fcca741b2011-06-17 22:46:371172IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
[email protected]05912742013-03-12 00:29:151173 NavigateFromOtherTabToSingletonOptions) {
[email protected]ddddfda2011-07-14 23:19:391174 {
[email protected]a7fe9112012-07-20 02:34:451175 content::WindowedNotificationObserver observer(
[email protected]ad50def52011-10-19 23:17:071176 content::NOTIFICATION_LOAD_STOP,
1177 content::NotificationService::AllSources());
[email protected]5d9cace72012-06-21 16:07:121178 chrome::ShowSettings(browser());
[email protected]ddddfda2011-07-14 23:19:391179 observer.Wait();
1180 }
1181 {
[email protected]a7fe9112012-07-20 02:34:451182 content::WindowedNotificationObserver observer(
[email protected]ad50def52011-10-19 23:17:071183 content::NOTIFICATION_LOAD_STOP,
1184 content::NotificationService::AllSources());
[email protected]52877dbc62012-06-29 22:22:031185 chrome::AddSelectedTabWithURL(browser(), GetGoogleURL(),
1186 content::PAGE_TRANSITION_LINK);
[email protected]ddddfda2011-07-14 23:19:391187 observer.Wait();
1188 }
[email protected]fcca741b2011-06-17 22:46:371189
[email protected]05912742013-03-12 00:29:151190 // This load should simply cause a tab switch.
1191 chrome::ShowSettings(browser());
1192
[email protected]ee496952013-01-10 23:17:331193 EXPECT_EQ(2, browser()->tab_strip_model()->count());
[email protected]ddddfda2011-07-14 23:19:391194 EXPECT_EQ(GetSettingsURL(),
[email protected]ee496952013-01-10 23:17:331195 ShortenUberURL(browser()->tab_strip_model()->
1196 GetActiveWebContents()->GetURL()));
[email protected]fcca741b2011-06-17 22:46:371197}
1198
[email protected]79717cf2013-02-28 18:40:361199IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, CloseSingletonTab) {
1200 for (int i = 0; i < 2; ++i) {
1201 content::WindowedNotificationObserver observer(
1202 content::NOTIFICATION_LOAD_STOP,
1203 content::NotificationService::AllSources());
1204 chrome::AddSelectedTabWithURL(browser(), GetGoogleURL(),
1205 content::PAGE_TRANSITION_TYPED);
1206 observer.Wait();
1207 }
1208
1209 browser()->tab_strip_model()->ActivateTabAt(0, true);
1210
1211 {
1212 content::WindowedNotificationObserver observer(
1213 content::NOTIFICATION_LOAD_STOP,
1214 content::NotificationService::AllSources());
1215 chrome::ShowSettings(browser());
1216 observer.Wait();
1217 }
1218
1219 EXPECT_TRUE(browser()->tab_strip_model()->CloseWebContentsAt(
1220 2, TabStripModel::CLOSE_USER_GESTURE));
1221 EXPECT_EQ(0, browser()->tab_strip_model()->active_index());
1222}
1223
[email protected]a048ad22012-03-23 04:26:561224// TODO(csilv): Update this for uber page. http://crbug.com/111579.
[email protected]ddddfda2011-07-14 23:19:391225IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
[email protected]a048ad22012-03-23 04:26:561226 DISABLED_NavigateFromDefaultToHistoryInSameTab) {
[email protected]ddddfda2011-07-14 23:19:391227 {
[email protected]a7fe9112012-07-20 02:34:451228 content::WindowedNotificationObserver observer(
[email protected]ad50def52011-10-19 23:17:071229 content::NOTIFICATION_LOAD_STOP,
1230 content::NotificationService::AllSources());
[email protected]5d9cace72012-06-21 16:07:121231 chrome::ShowHistory(browser());
[email protected]ddddfda2011-07-14 23:19:391232 observer.Wait();
1233 }
[email protected]ee496952013-01-10 23:17:331234 EXPECT_EQ(1, browser()->tab_strip_model()->count());
[email protected]11e03fb2012-03-03 19:07:051235 EXPECT_EQ(GURL(chrome::kChromeUIHistoryFrameURL),
[email protected]ee496952013-01-10 23:17:331236 browser()->tab_strip_model()->GetActiveWebContents()->GetURL());
[email protected]ddddfda2011-07-14 23:19:391237}
1238
[email protected]953c2132013-02-23 05:56:051239// TODO(linux_aura) http://crbug.com/163931
1240#if defined(OS_LINUX) && !defined(OS_CHROMEOS) && defined(USE_AURA)
1241#define MAYBE_NavigateFromDefaultToBookmarksInSameTab DISABLED_NavigateFromDefaultToBookmarksInSameTab
1242#else
1243#define MAYBE_NavigateFromDefaultToBookmarksInSameTab NavigateFromDefaultToBookmarksInSameTab
1244#endif
[email protected]ddddfda2011-07-14 23:19:391245IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
[email protected]953c2132013-02-23 05:56:051246 MAYBE_NavigateFromDefaultToBookmarksInSameTab) {
[email protected]ddddfda2011-07-14 23:19:391247 {
[email protected]a7fe9112012-07-20 02:34:451248 content::WindowedNotificationObserver observer(
[email protected]ad50def52011-10-19 23:17:071249 content::NOTIFICATION_LOAD_STOP,
1250 content::NotificationService::AllSources());
[email protected]5d9cace72012-06-21 16:07:121251 chrome::ShowBookmarkManager(browser());
[email protected]ddddfda2011-07-14 23:19:391252 observer.Wait();
1253 }
[email protected]ee496952013-01-10 23:17:331254 EXPECT_EQ(1, browser()->tab_strip_model()->count());
[email protected]bc16a252013-01-23 02:21:491255 EXPECT_TRUE(StartsWithASCII(
1256 browser()->tab_strip_model()->GetActiveWebContents()->GetURL().spec(),
1257 chrome::kChromeUIBookmarksURL,
1258 true));
[email protected]ddddfda2011-07-14 23:19:391259}
1260
1261IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
1262 NavigateFromDefaultToDownloadsInSameTab) {
1263 {
[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::ShowDownloads(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]ddddfda2011-07-14 23:19:391271 EXPECT_EQ(GURL(chrome::kChromeUIDownloadsURL),
[email protected]ee496952013-01-10 23:17:331272 browser()->tab_strip_model()->GetActiveWebContents()->GetURL());
[email protected]ddddfda2011-07-14 23:19:391273}
1274
[email protected]8fb16a82012-08-17 02:17:591275IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
1276 NavigateWithoutBrowser) {
1277 // First navigate using the profile of the existing browser window, and
1278 // check that the window is reused.
1279 chrome::NavigateParams params(browser()->profile(), GetGoogleURL(),
1280 content::PAGE_TRANSITION_LINK);
1281 ui_test_utils::NavigateToURL(&params);
[email protected]0665ebe2013-02-13 09:53:191282 EXPECT_EQ(1u, chrome::GetTotalBrowserCount());
[email protected]8fb16a82012-08-17 02:17:591283
1284 // Now navigate using the incognito profile and check that a new window
1285 // is created.
1286 chrome::NavigateParams params_incognito(
1287 browser()->profile()->GetOffTheRecordProfile(),
1288 GetGoogleURL(), content::PAGE_TRANSITION_LINK);
1289 ui_test_utils::NavigateToURL(&params_incognito);
[email protected]0665ebe2013-02-13 09:53:191290 EXPECT_EQ(2u, chrome::GetTotalBrowserCount());
[email protected]8fb16a82012-08-17 02:17:591291}
1292
[email protected]beb1d1192013-05-14 04:47:511293IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, ViewSourceIsntSingleton) {
1294 const std::string viewsource_ntp_url =
[email protected]dbdda5402013-05-30 22:13:481295 std::string(content::kViewSourceScheme) + ":" +
[email protected]beb1d1192013-05-14 04:47:511296 chrome::kChromeUIVersionURL;
1297
1298 chrome::NavigateParams viewsource_params(browser(),
1299 GURL(viewsource_ntp_url),
1300 content::PAGE_TRANSITION_LINK);
1301 ui_test_utils::NavigateToURL(&viewsource_params);
1302
1303 chrome::NavigateParams singleton_params(browser(),
1304 GURL(chrome::kChromeUIVersionURL),
1305 content::PAGE_TRANSITION_LINK);
1306 singleton_params.disposition = SINGLETON_TAB;
1307 EXPECT_EQ(-1, chrome::GetIndexOfSingletonTab(&singleton_params));
1308}
1309
[email protected]ddddfda2011-07-14 23:19:391310} // namespace