blob: 588b09eb41e2f0205635222fc22c7e6eec870e4f [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.
188IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_CurrentTab) {
[email protected]ddddfda2011-07-14 23:19:39189 ui_test_utils::NavigateToURL(browser(), GetGoogleURL());
[email protected]ee496952013-01-10 23:17:33190 EXPECT_EQ(GetGoogleURL(),
191 browser()->tab_strip_model()->GetActiveWebContents()->GetURL());
[email protected]a1feae52010-10-11 22:14:45192 // We should have one window with one tab.
[email protected]0665ebe2013-02-13 09:53:19193 EXPECT_EQ(1u, chrome::GetTotalBrowserCount());
[email protected]ee496952013-01-10 23:17:33194 EXPECT_EQ(1, browser()->tab_strip_model()->count());
[email protected]a1feae52010-10-11 22:14:45195}
196
[email protected]bd817c22011-02-09 08:16:46197// This test verifies that a singleton tab is refocused if one is already opened
[email protected]19d9f3a2010-10-14 21:49:36198// in another or an existing window, or added if it is not.
199IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_SingletonTabExisting) {
[email protected]19d9f3a2010-10-14 21:49:36200 GURL singleton_url1("http://maps.google.com/");
[email protected]fa7ebe02010-11-29 23:04:57201
[email protected]e232c992012-12-06 12:43:20202 // Register for a notification if an additional WebContents was instantiated.
[email protected]bd817c22011-02-09 08:16:46203 // Opening a Singleton tab that is already opened should not be opening a new
[email protected]e232c992012-12-06 12:43:20204 // tab nor be creating a new WebContents object.
[email protected]6c2381d2011-10-19 02:52:53205 content::NotificationRegistrar registrar;
[email protected]fa7ebe02010-11-29 23:04:57206
207 // As the registrar object goes out of scope, this will get unregistered
[email protected]d53a08c2012-07-18 20:35:30208 registrar.Add(this,
209 content::NOTIFICATION_WEB_CONTENTS_RENDER_VIEW_HOST_CREATED,
[email protected]ad50def52011-10-19 23:17:07210 content::NotificationService::AllSources());
[email protected]fa7ebe02010-11-29 23:04:57211
[email protected]52877dbc62012-06-29 22:22:03212 chrome::AddSelectedTabWithURL(browser(), singleton_url1,
213 content::PAGE_TRANSITION_LINK);
214 chrome::AddSelectedTabWithURL(browser(), GetGoogleURL(),
215 content::PAGE_TRANSITION_LINK);
[email protected]19d9f3a2010-10-14 21:49:36216
217 // We should have one browser with 3 tabs, the 3rd selected.
[email protected]0665ebe2013-02-13 09:53:19218 EXPECT_EQ(1u, chrome::GetTotalBrowserCount());
[email protected]ee496952013-01-10 23:17:33219 EXPECT_EQ(2, browser()->tab_strip_model()->active_index());
[email protected]19d9f3a2010-10-14 21:49:36220
[email protected]fa7ebe02010-11-29 23:04:57221 unsigned int previous_tab_contents_count =
222 created_tab_contents_count_ = 0;
223
[email protected]19d9f3a2010-10-14 21:49:36224 // Navigate to singleton_url1.
[email protected]78e2edc2012-07-01 23:32:28225 chrome::NavigateParams p(MakeNavigateParams());
[email protected]19d9f3a2010-10-14 21:49:36226 p.disposition = SINGLETON_TAB;
227 p.url = singleton_url1;
[email protected]78e2edc2012-07-01 23:32:28228 chrome::Navigate(&p);
[email protected]19d9f3a2010-10-14 21:49:36229
230 // The middle tab should now be selected.
231 EXPECT_EQ(browser(), p.browser);
[email protected]ee496952013-01-10 23:17:33232 EXPECT_EQ(1, browser()->tab_strip_model()->active_index());
[email protected]fa7ebe02010-11-29 23:04:57233
234 // No tab contents should have been created
235 EXPECT_EQ(previous_tab_contents_count,
236 created_tab_contents_count_);
[email protected]19d9f3a2010-10-14 21:49:36237}
238
239IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
[email protected]578c6962011-08-24 22:06:40240 Disposition_SingletonTabRespectingRef) {
241 GURL singleton_ref_url1("http://maps.google.com/#a");
242 GURL singleton_ref_url2("http://maps.google.com/#b");
243 GURL singleton_ref_url3("http://maps.google.com/");
244
[email protected]52877dbc62012-06-29 22:22:03245 chrome::AddSelectedTabWithURL(browser(), singleton_ref_url1,
246 content::PAGE_TRANSITION_LINK);
[email protected]578c6962011-08-24 22:06:40247
248 // We should have one browser with 2 tabs, 2nd selected.
[email protected]0665ebe2013-02-13 09:53:19249 EXPECT_EQ(1u, chrome::GetTotalBrowserCount());
[email protected]ee496952013-01-10 23:17:33250 EXPECT_EQ(2, browser()->tab_strip_model()->count());
251 EXPECT_EQ(1, browser()->tab_strip_model()->active_index());
[email protected]578c6962011-08-24 22:06:40252
253 // Navigate to singleton_url2.
[email protected]78e2edc2012-07-01 23:32:28254 chrome::NavigateParams p(MakeNavigateParams());
[email protected]578c6962011-08-24 22:06:40255 p.disposition = SINGLETON_TAB;
256 p.url = singleton_ref_url2;
[email protected]78e2edc2012-07-01 23:32:28257 chrome::Navigate(&p);
[email protected]578c6962011-08-24 22:06:40258
259 // We should now have 2 tabs, the 2nd one selected.
260 EXPECT_EQ(browser(), p.browser);
[email protected]ee496952013-01-10 23:17:33261 EXPECT_EQ(2, browser()->tab_strip_model()->count());
262 EXPECT_EQ(1, browser()->tab_strip_model()->active_index());
[email protected]578c6962011-08-24 22:06:40263
264 // Navigate to singleton_url2, but with respect ref set.
265 p = MakeNavigateParams();
266 p.disposition = SINGLETON_TAB;
267 p.url = singleton_ref_url2;
[email protected]78e2edc2012-07-01 23:32:28268 p.ref_behavior = chrome::NavigateParams::RESPECT_REF;
269 chrome::Navigate(&p);
[email protected]578c6962011-08-24 22:06:40270
271 // We should now have 3 tabs, the 3th one selected.
272 EXPECT_EQ(browser(), p.browser);
[email protected]ee496952013-01-10 23:17:33273 EXPECT_EQ(3, browser()->tab_strip_model()->count());
274 EXPECT_EQ(2, browser()->tab_strip_model()->active_index());
[email protected]578c6962011-08-24 22:06:40275
276 // Navigate to singleton_url3.
277 p = MakeNavigateParams();
278 p.disposition = SINGLETON_TAB;
279 p.url = singleton_ref_url3;
[email protected]78e2edc2012-07-01 23:32:28280 p.ref_behavior = chrome::NavigateParams::RESPECT_REF;
281 chrome::Navigate(&p);
[email protected]578c6962011-08-24 22:06:40282
283 // We should now have 4 tabs, the 4th one selected.
284 EXPECT_EQ(browser(), p.browser);
[email protected]ee496952013-01-10 23:17:33285 EXPECT_EQ(4, browser()->tab_strip_model()->count());
286 EXPECT_EQ(3, browser()->tab_strip_model()->active_index());
[email protected]578c6962011-08-24 22:06:40287}
288
289IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
[email protected]19d9f3a2010-10-14 21:49:36290 Disposition_SingletonTabNoneExisting) {
[email protected]19d9f3a2010-10-14 21:49:36291 GURL singleton_url1("http://maps.google.com/");
292
[email protected]bd817c22011-02-09 08:16:46293 // We should have one browser with 1 tab.
[email protected]0665ebe2013-02-13 09:53:19294 EXPECT_EQ(1u, chrome::GetTotalBrowserCount());
[email protected]ee496952013-01-10 23:17:33295 EXPECT_EQ(0, browser()->tab_strip_model()->active_index());
[email protected]19d9f3a2010-10-14 21:49:36296
297 // Navigate to singleton_url1.
[email protected]78e2edc2012-07-01 23:32:28298 chrome::NavigateParams p(MakeNavigateParams());
[email protected]19d9f3a2010-10-14 21:49:36299 p.disposition = SINGLETON_TAB;
300 p.url = singleton_url1;
[email protected]78e2edc2012-07-01 23:32:28301 chrome::Navigate(&p);
[email protected]19d9f3a2010-10-14 21:49:36302
303 // We should now have 2 tabs, the 2nd one selected.
304 EXPECT_EQ(browser(), p.browser);
[email protected]ee496952013-01-10 23:17:33305 EXPECT_EQ(2, browser()->tab_strip_model()->count());
306 EXPECT_EQ(1, browser()->tab_strip_model()->active_index());
[email protected]a1feae52010-10-11 22:14:45307}
308
309// This test verifies that when a navigation results in a foreground tab, the
310// tab count of the Browser increases and the selected tab shifts to the new
311// foreground tab.
312IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_NewForegroundTab) {
[email protected]ee496952013-01-10 23:17:33313 WebContents* old_contents =
314 browser()->tab_strip_model()->GetActiveWebContents();
[email protected]78e2edc2012-07-01 23:32:28315 chrome::NavigateParams p(MakeNavigateParams());
[email protected]a1feae52010-10-11 22:14:45316 p.disposition = NEW_FOREGROUND_TAB;
[email protected]78e2edc2012-07-01 23:32:28317 chrome::Navigate(&p);
[email protected]ee496952013-01-10 23:17:33318 EXPECT_NE(old_contents,
319 browser()->tab_strip_model()->GetActiveWebContents());
[email protected]e232c992012-12-06 12:43:20320 EXPECT_EQ(browser()->tab_strip_model()->GetActiveWebContents(),
[email protected]59253a652012-11-20 00:17:26321 p.target_contents);
[email protected]ee496952013-01-10 23:17:33322 EXPECT_EQ(2, browser()->tab_strip_model()->count());
[email protected]a1feae52010-10-11 22:14:45323}
324
325// This test verifies that when a navigation results in a background tab, the
326// tab count of the Browser increases but the selected tab remains the same.
327IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_NewBackgroundTab) {
[email protected]ee496952013-01-10 23:17:33328 WebContents* old_contents =
329 browser()->tab_strip_model()->GetActiveWebContents();
[email protected]78e2edc2012-07-01 23:32:28330 chrome::NavigateParams p(MakeNavigateParams());
[email protected]a1feae52010-10-11 22:14:45331 p.disposition = NEW_BACKGROUND_TAB;
[email protected]78e2edc2012-07-01 23:32:28332 chrome::Navigate(&p);
[email protected]ee496952013-01-10 23:17:33333 WebContents* new_contents =
334 browser()->tab_strip_model()->GetActiveWebContents();
[email protected]a1feae52010-10-11 22:14:45335 // The selected tab should have remained unchanged, since the new tab was
336 // opened in the background.
337 EXPECT_EQ(old_contents, new_contents);
[email protected]ee496952013-01-10 23:17:33338 EXPECT_EQ(2, browser()->tab_strip_model()->count());
[email protected]a1feae52010-10-11 22:14:45339}
340
341// This test verifies that when a navigation requiring a new foreground tab
342// occurs in a Browser that cannot host multiple tabs, the new foreground tab
343// is created in an existing compatible Browser.
344IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
345 Disposition_IncompatibleWindow_Existing) {
346 // Open a foreground tab in a window that cannot open popups when there is an
347 // existing compatible window somewhere else that they can be opened within.
348 Browser* popup = CreateEmptyBrowserForType(Browser::TYPE_POPUP,
349 browser()->profile());
[email protected]78e2edc2012-07-01 23:32:28350 chrome::NavigateParams p(MakeNavigateParams(popup));
[email protected]a1feae52010-10-11 22:14:45351 p.disposition = NEW_FOREGROUND_TAB;
[email protected]78e2edc2012-07-01 23:32:28352 chrome::Navigate(&p);
[email protected]a1feae52010-10-11 22:14:45353
354 // Navigate() should have opened the tab in a different browser since the
355 // one we supplied didn't support additional tabs.
356 EXPECT_NE(popup, p.browser);
357
358 // Since browser() is an existing compatible tabbed browser, it should have
359 // opened the tab there.
360 EXPECT_EQ(browser(), p.browser);
361
362 // We should be left with 2 windows, the popup with one tab and the browser()
363 // provided by the framework with two.
[email protected]0665ebe2013-02-13 09:53:19364 EXPECT_EQ(2u, chrome::GetTotalBrowserCount());
[email protected]ee496952013-01-10 23:17:33365 EXPECT_EQ(1, popup->tab_strip_model()->count());
366 EXPECT_EQ(2, browser()->tab_strip_model()->count());
[email protected]a1feae52010-10-11 22:14:45367}
368
369// This test verifies that when a navigation requiring a new foreground tab
370// occurs in a Browser that cannot host multiple tabs and no compatible Browser
371// that can is open, a compatible Browser is created.
372IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
373 Disposition_IncompatibleWindow_NoExisting) {
374 // We want to simulate not being able to find an existing window compatible
375 // with our non-tabbed browser window so Navigate() is forced to create a
376 // new compatible window. Because browser() supplied by the in-process
377 // browser testing framework is compatible with browser()->profile(), we
378 // need a different profile, and creating a popup window with an incognito
379 // profile is a quick and dirty way of achieving this.
380 Browser* popup = CreateEmptyBrowserForType(
[email protected]b35b26b32011-05-05 20:35:14381 Browser::TYPE_POPUP,
382 browser()->profile()->GetOffTheRecordProfile());
[email protected]78e2edc2012-07-01 23:32:28383 chrome::NavigateParams p(MakeNavigateParams(popup));
[email protected]a1feae52010-10-11 22:14:45384 p.disposition = NEW_FOREGROUND_TAB;
[email protected]78e2edc2012-07-01 23:32:28385 chrome::Navigate(&p);
[email protected]a1feae52010-10-11 22:14:45386
387 // Navigate() should have opened the tab in a different browser since the
388 // one we supplied didn't support additional tabs.
389 EXPECT_NE(popup, p.browser);
390
391 // This time, browser() is _not_ compatible with popup since it is not an
392 // incognito window.
393 EXPECT_NE(browser(), p.browser);
394
395 // We should have three windows, each with one tab:
396 // 1. the browser() provided by the framework (unchanged in this test)
397 // 2. the incognito popup we created originally
398 // 3. the new incognito tabbed browser that was created by Navigate().
[email protected]0665ebe2013-02-13 09:53:19399 EXPECT_EQ(3u, chrome::GetTotalBrowserCount());
[email protected]ee496952013-01-10 23:17:33400 EXPECT_EQ(1, browser()->tab_strip_model()->count());
401 EXPECT_EQ(1, popup->tab_strip_model()->count());
402 EXPECT_EQ(1, p.browser->tab_strip_model()->count());
[email protected]b35b26b32011-05-05 20:35:14403 EXPECT_TRUE(p.browser->is_type_tabbed());
[email protected]a1feae52010-10-11 22:14:45404}
405
406// This test verifies that navigating with WindowOpenDisposition = NEW_POPUP
407// from a normal Browser results in a new Browser with TYPE_POPUP.
408IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_NewPopup) {
[email protected]78e2edc2012-07-01 23:32:28409 chrome::NavigateParams p(MakeNavigateParams());
[email protected]a1feae52010-10-11 22:14:45410 p.disposition = NEW_POPUP;
[email protected]588300d2011-04-28 21:06:35411 p.window_bounds = gfx::Rect(0, 0, 200, 200);
[email protected]7d329992011-04-15 18:20:02412 // Wait for new popup to to load and gain focus.
[email protected]ddddfda2011-07-14 23:19:39413 ui_test_utils::NavigateToURL(&p);
[email protected]a1feae52010-10-11 22:14:45414
[email protected]7d329992011-04-15 18:20:02415 // Navigate() should have opened a new, focused popup window.
[email protected]a1feae52010-10-11 22:14:45416 EXPECT_NE(browser(), p.browser);
[email protected]50592b52013-05-02 22:26:25417#if 0
418 // TODO(stevenjb): Enable this test. See: crbug.com/79493
419 EXPECT_TRUE(p.browser->window()->IsActive());
420#endif
[email protected]b35b26b32011-05-05 20:35:14421 EXPECT_TRUE(p.browser->is_type_popup());
422 EXPECT_FALSE(p.browser->is_app());
[email protected]a1feae52010-10-11 22:14:45423
424 // We should have two windows, the browser() provided by the framework and the
425 // new popup window.
[email protected]0665ebe2013-02-13 09:53:19426 EXPECT_EQ(2u, chrome::GetTotalBrowserCount());
[email protected]ee496952013-01-10 23:17:33427 EXPECT_EQ(1, browser()->tab_strip_model()->count());
428 EXPECT_EQ(1, p.browser->tab_strip_model()->count());
[email protected]a1feae52010-10-11 22:14:45429}
430
431// This test verifies that navigating with WindowOpenDisposition = NEW_POPUP
[email protected]f112b0f2011-05-26 01:53:52432// from a normal Browser results in a new Browser with is_app() true.
433IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_NewPopup_ExtensionId) {
[email protected]78e2edc2012-07-01 23:32:28434 chrome::NavigateParams p(MakeNavigateParams());
[email protected]f112b0f2011-05-26 01:53:52435 p.disposition = NEW_POPUP;
436 p.extension_app_id = "extensionappid";
437 p.window_bounds = gfx::Rect(0, 0, 200, 200);
[email protected]f112b0f2011-05-26 01:53:52438 // Wait for new popup to to load and gain focus.
[email protected]ddddfda2011-07-14 23:19:39439 ui_test_utils::NavigateToURL(&p);
[email protected]f112b0f2011-05-26 01:53:52440
441 // Navigate() should have opened a new, focused popup window.
442 EXPECT_NE(browser(), p.browser);
443 EXPECT_TRUE(p.browser->is_type_popup());
444 EXPECT_TRUE(p.browser->is_app());
445
446 // We should have two windows, the browser() provided by the framework and the
447 // new popup window.
[email protected]0665ebe2013-02-13 09:53:19448 EXPECT_EQ(2u, chrome::GetTotalBrowserCount());
[email protected]ee496952013-01-10 23:17:33449 EXPECT_EQ(1, browser()->tab_strip_model()->count());
450 EXPECT_EQ(1, p.browser->tab_strip_model()->count());
[email protected]f112b0f2011-05-26 01:53:52451}
452
453// This test verifies that navigating with WindowOpenDisposition = NEW_POPUP
[email protected]300d1e52011-01-19 23:57:57454// from a normal popup results in a new Browser with TYPE_POPUP.
455IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_NewPopupFromPopup) {
456 // Open a popup.
[email protected]78e2edc2012-07-01 23:32:28457 chrome::NavigateParams p1(MakeNavigateParams());
[email protected]300d1e52011-01-19 23:57:57458 p1.disposition = NEW_POPUP;
[email protected]588300d2011-04-28 21:06:35459 p1.window_bounds = gfx::Rect(0, 0, 200, 200);
[email protected]78e2edc2012-07-01 23:32:28460 chrome::Navigate(&p1);
[email protected]300d1e52011-01-19 23:57:57461 // Open another popup.
[email protected]78e2edc2012-07-01 23:32:28462 chrome::NavigateParams p2(MakeNavigateParams(p1.browser));
[email protected]300d1e52011-01-19 23:57:57463 p2.disposition = NEW_POPUP;
[email protected]588300d2011-04-28 21:06:35464 p2.window_bounds = gfx::Rect(0, 0, 200, 200);
[email protected]78e2edc2012-07-01 23:32:28465 chrome::Navigate(&p2);
[email protected]300d1e52011-01-19 23:57:57466
467 // Navigate() should have opened a new normal popup window.
468 EXPECT_NE(p1.browser, p2.browser);
[email protected]b35b26b32011-05-05 20:35:14469 EXPECT_TRUE(p2.browser->is_type_popup());
470 EXPECT_FALSE(p2.browser->is_app());
[email protected]300d1e52011-01-19 23:57:57471
472 // We should have three windows, the browser() provided by the framework,
473 // the first popup window, and the second popup window.
[email protected]0665ebe2013-02-13 09:53:19474 EXPECT_EQ(3u, chrome::GetTotalBrowserCount());
[email protected]ee496952013-01-10 23:17:33475 EXPECT_EQ(1, browser()->tab_strip_model()->count());
476 EXPECT_EQ(1, p1.browser->tab_strip_model()->count());
477 EXPECT_EQ(1, p2.browser->tab_strip_model()->count());
[email protected]300d1e52011-01-19 23:57:57478}
479
480// This test verifies that navigating with WindowOpenDisposition = NEW_POPUP
[email protected]a1feae52010-10-11 22:14:45481// from an app frame results in a new Browser with TYPE_APP_POPUP.
482IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
483 Disposition_NewPopupFromAppWindow) {
[email protected]b35b26b32011-05-05 20:35:14484 Browser* app_browser = CreateEmptyBrowserForApp(Browser::TYPE_TABBED,
485 browser()->profile());
[email protected]78e2edc2012-07-01 23:32:28486 chrome::NavigateParams p(MakeNavigateParams(app_browser));
[email protected]a1feae52010-10-11 22:14:45487 p.disposition = NEW_POPUP;
[email protected]588300d2011-04-28 21:06:35488 p.window_bounds = gfx::Rect(0, 0, 200, 200);
[email protected]78e2edc2012-07-01 23:32:28489 chrome::Navigate(&p);
[email protected]a1feae52010-10-11 22:14:45490
491 // Navigate() should have opened a new popup app window.
492 EXPECT_NE(app_browser, p.browser);
493 EXPECT_NE(browser(), p.browser);
[email protected]b35b26b32011-05-05 20:35:14494 EXPECT_TRUE(p.browser->is_type_popup());
495 EXPECT_TRUE(p.browser->is_app());
[email protected]a1feae52010-10-11 22:14:45496
497 // We should now have three windows, the app window, the app popup it created,
498 // and the original browser() provided by the framework.
[email protected]0665ebe2013-02-13 09:53:19499 EXPECT_EQ(3u, chrome::GetTotalBrowserCount());
[email protected]ee496952013-01-10 23:17:33500 EXPECT_EQ(1, browser()->tab_strip_model()->count());
501 EXPECT_EQ(1, app_browser->tab_strip_model()->count());
502 EXPECT_EQ(1, p.browser->tab_strip_model()->count());
[email protected]a1feae52010-10-11 22:14:45503}
504
505// This test verifies that navigating with WindowOpenDisposition = NEW_POPUP
[email protected]300d1e52011-01-19 23:57:57506// from an app popup results in a new Browser also of TYPE_APP_POPUP.
507IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
508 Disposition_NewPopupFromAppPopup) {
[email protected]b35b26b32011-05-05 20:35:14509 Browser* app_browser = CreateEmptyBrowserForApp(Browser::TYPE_TABBED,
510 browser()->profile());
[email protected]300d1e52011-01-19 23:57:57511 // Open an app popup.
[email protected]78e2edc2012-07-01 23:32:28512 chrome::NavigateParams p1(MakeNavigateParams(app_browser));
[email protected]300d1e52011-01-19 23:57:57513 p1.disposition = NEW_POPUP;
[email protected]588300d2011-04-28 21:06:35514 p1.window_bounds = gfx::Rect(0, 0, 200, 200);
[email protected]78e2edc2012-07-01 23:32:28515 chrome::Navigate(&p1);
[email protected]300d1e52011-01-19 23:57:57516 // Now open another app popup.
[email protected]78e2edc2012-07-01 23:32:28517 chrome::NavigateParams p2(MakeNavigateParams(p1.browser));
[email protected]300d1e52011-01-19 23:57:57518 p2.disposition = NEW_POPUP;
[email protected]588300d2011-04-28 21:06:35519 p2.window_bounds = gfx::Rect(0, 0, 200, 200);
[email protected]78e2edc2012-07-01 23:32:28520 chrome::Navigate(&p2);
[email protected]300d1e52011-01-19 23:57:57521
522 // Navigate() should have opened a new popup app window.
523 EXPECT_NE(browser(), p1.browser);
524 EXPECT_NE(p1.browser, p2.browser);
[email protected]b35b26b32011-05-05 20:35:14525 EXPECT_TRUE(p2.browser->is_type_popup());
526 EXPECT_TRUE(p2.browser->is_app());
[email protected]300d1e52011-01-19 23:57:57527
528 // We should now have four windows, the app window, the first app popup,
529 // the second app popup, and the original browser() provided by the framework.
[email protected]0665ebe2013-02-13 09:53:19530 EXPECT_EQ(4u, chrome::GetTotalBrowserCount());
[email protected]ee496952013-01-10 23:17:33531 EXPECT_EQ(1, browser()->tab_strip_model()->count());
532 EXPECT_EQ(1, app_browser->tab_strip_model()->count());
533 EXPECT_EQ(1, p1.browser->tab_strip_model()->count());
534 EXPECT_EQ(1, p2.browser->tab_strip_model()->count());
[email protected]300d1e52011-01-19 23:57:57535}
536
537// This test verifies that navigating with WindowOpenDisposition = NEW_POPUP
[email protected]a1feae52010-10-11 22:14:45538// from an extension app tab results in a new Browser with TYPE_APP_POPUP.
539IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
540 Disposition_NewPopupFromExtensionApp) {
541 // TODO(beng): TBD.
542}
543
[email protected]7d329992011-04-15 18:20:02544// This test verifies that navigating with window_action = SHOW_WINDOW_INACTIVE
545// does not focus a new new popup window.
546IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_NewPopupUnfocused) {
[email protected]78e2edc2012-07-01 23:32:28547 chrome::NavigateParams p(MakeNavigateParams());
[email protected]7d329992011-04-15 18:20:02548 p.disposition = NEW_POPUP;
[email protected]588300d2011-04-28 21:06:35549 p.window_bounds = gfx::Rect(0, 0, 200, 200);
[email protected]78e2edc2012-07-01 23:32:28550 p.window_action = chrome::NavigateParams::SHOW_WINDOW_INACTIVE;
[email protected]7d329992011-04-15 18:20:02551 // Wait for new popup to load (and gain focus if the test fails).
[email protected]ddddfda2011-07-14 23:19:39552 ui_test_utils::NavigateToURL(&p);
[email protected]7d329992011-04-15 18:20:02553
554 // Navigate() should have opened a new, unfocused, popup window.
555 EXPECT_NE(browser(), p.browser);
556 EXPECT_EQ(Browser::TYPE_POPUP, p.browser->type());
[email protected]9db263a2011-04-15 20:53:47557#if 0
558// TODO(stevenjb): Enable this test. See: crbug.com/79493
[email protected]7d329992011-04-15 18:20:02559 EXPECT_FALSE(p.browser->window()->IsActive());
[email protected]7d329992011-04-15 18:20:02560#endif
[email protected]9db263a2011-04-15 20:53:47561}
[email protected]7d329992011-04-15 18:20:02562
[email protected]a1feae52010-10-11 22:14:45563// This test verifies that navigating with WindowOpenDisposition = NEW_WINDOW
564// always opens a new window.
565IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_NewWindow) {
[email protected]78e2edc2012-07-01 23:32:28566 chrome::NavigateParams p(MakeNavigateParams());
[email protected]a1feae52010-10-11 22:14:45567 p.disposition = NEW_WINDOW;
[email protected]78e2edc2012-07-01 23:32:28568 chrome::Navigate(&p);
[email protected]a1feae52010-10-11 22:14:45569
570 // Navigate() should have opened a new toplevel window.
571 EXPECT_NE(browser(), p.browser);
[email protected]b35b26b32011-05-05 20:35:14572 EXPECT_TRUE(p.browser->is_type_tabbed());
[email protected]a1feae52010-10-11 22:14:45573
574 // We should now have two windows, the browser() provided by the framework and
575 // the new normal window.
[email protected]0665ebe2013-02-13 09:53:19576 EXPECT_EQ(2u, chrome::GetTotalBrowserCount());
[email protected]ee496952013-01-10 23:17:33577 EXPECT_EQ(1, browser()->tab_strip_model()->count());
578 EXPECT_EQ(1, p.browser->tab_strip_model()->count());
[email protected]a1feae52010-10-11 22:14:45579}
580
581// This test verifies that navigating with WindowOpenDisposition = INCOGNITO
582// opens a new incognito window if no existing incognito window is present.
583IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_Incognito) {
[email protected]78e2edc2012-07-01 23:32:28584 chrome::NavigateParams p(MakeNavigateParams());
[email protected]a1feae52010-10-11 22:14:45585 p.disposition = OFF_THE_RECORD;
[email protected]78e2edc2012-07-01 23:32:28586 chrome::Navigate(&p);
[email protected]a1feae52010-10-11 22:14:45587
588 // Navigate() should have opened a new toplevel incognito window.
589 EXPECT_NE(browser(), p.browser);
590 EXPECT_EQ(browser()->profile()->GetOffTheRecordProfile(),
591 p.browser->profile());
592
[email protected]d7ff3592010-11-30 21:50:46593 // |source_contents| should be set to NULL because the profile for the new
594 // page is different from the originating page.
595 EXPECT_EQ(NULL, p.source_contents);
596
[email protected]a1feae52010-10-11 22:14:45597 // We should now have two windows, the browser() provided by the framework and
598 // the new incognito window.
[email protected]0665ebe2013-02-13 09:53:19599 EXPECT_EQ(2u, chrome::GetTotalBrowserCount());
[email protected]ee496952013-01-10 23:17:33600 EXPECT_EQ(1, browser()->tab_strip_model()->count());
601 EXPECT_EQ(1, p.browser->tab_strip_model()->count());
[email protected]a1feae52010-10-11 22:14:45602}
603
604// This test verifies that navigating with WindowOpenDisposition = INCOGNITO
605// reuses an existing incognito window when possible.
606IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_IncognitoRefocus) {
607 Browser* incognito_browser =
[email protected]b35b26b32011-05-05 20:35:14608 CreateEmptyBrowserForType(Browser::TYPE_TABBED,
[email protected]a1feae52010-10-11 22:14:45609 browser()->profile()->GetOffTheRecordProfile());
[email protected]78e2edc2012-07-01 23:32:28610 chrome::NavigateParams p(MakeNavigateParams());
[email protected]a1feae52010-10-11 22:14:45611 p.disposition = OFF_THE_RECORD;
[email protected]78e2edc2012-07-01 23:32:28612 chrome::Navigate(&p);
[email protected]a1feae52010-10-11 22:14:45613
614 // Navigate() should have opened a new tab in the existing incognito window.
615 EXPECT_NE(browser(), p.browser);
616 EXPECT_EQ(p.browser, incognito_browser);
617
618 // We should now have two windows, the browser() provided by the framework and
619 // the incognito window we opened earlier.
[email protected]0665ebe2013-02-13 09:53:19620 EXPECT_EQ(2u, chrome::GetTotalBrowserCount());
[email protected]ee496952013-01-10 23:17:33621 EXPECT_EQ(1, browser()->tab_strip_model()->count());
622 EXPECT_EQ(2, incognito_browser->tab_strip_model()->count());
[email protected]a1feae52010-10-11 22:14:45623}
624
625// This test verifies that no navigation action occurs when
626// WindowOpenDisposition = SUPPRESS_OPEN.
627IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_SuppressOpen) {
628 RunSuppressTest(SUPPRESS_OPEN);
629}
630
631// This test verifies that no navigation action occurs when
632// WindowOpenDisposition = SAVE_TO_DISK.
633IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_SaveToDisk) {
634 RunSuppressTest(SAVE_TO_DISK);
635}
636
637// This test verifies that no navigation action occurs when
638// WindowOpenDisposition = IGNORE_ACTION.
639IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_IgnoreAction) {
640 RunSuppressTest(IGNORE_ACTION);
641}
642
[email protected]e232c992012-12-06 12:43:20643// This tests adding a foreground tab with a predefined WebContents.
[email protected]a1feae52010-10-11 22:14:45644IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, TargetContents_ForegroundTab) {
[email protected]78e2edc2012-07-01 23:32:28645 chrome::NavigateParams p(MakeNavigateParams());
[email protected]a1feae52010-10-11 22:14:45646 p.disposition = NEW_FOREGROUND_TAB;
[email protected]e232c992012-12-06 12:43:20647 p.target_contents = CreateWebContents();
[email protected]78e2edc2012-07-01 23:32:28648 chrome::Navigate(&p);
[email protected]a1feae52010-10-11 22:14:45649
650 // Navigate() should have opened the contents in a new foreground in the
651 // current Browser.
652 EXPECT_EQ(browser(), p.browser);
[email protected]e232c992012-12-06 12:43:20653 EXPECT_EQ(browser()->tab_strip_model()->GetActiveWebContents(),
[email protected]59253a652012-11-20 00:17:26654 p.target_contents);
[email protected]a1feae52010-10-11 22:14:45655
656 // We should have one window, with two tabs.
[email protected]0665ebe2013-02-13 09:53:19657 EXPECT_EQ(1u, chrome::GetTotalBrowserCount());
[email protected]ee496952013-01-10 23:17:33658 EXPECT_EQ(2, browser()->tab_strip_model()->count());
[email protected]a1feae52010-10-11 22:14:45659}
660
661#if defined(OS_WIN)
[email protected]e232c992012-12-06 12:43:20662// This tests adding a popup with a predefined WebContents.
[email protected]76edb672011-03-04 21:48:39663IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, DISABLED_TargetContents_Popup) {
[email protected]78e2edc2012-07-01 23:32:28664 chrome::NavigateParams p(MakeNavigateParams());
[email protected]a1feae52010-10-11 22:14:45665 p.disposition = NEW_POPUP;
[email protected]e232c992012-12-06 12:43:20666 p.target_contents = CreateWebContents();
[email protected]a1feae52010-10-11 22:14:45667 p.window_bounds = gfx::Rect(10, 10, 500, 500);
[email protected]78e2edc2012-07-01 23:32:28668 chrome::Navigate(&p);
[email protected]a1feae52010-10-11 22:14:45669
670 // Navigate() should have opened a new popup window.
671 EXPECT_NE(browser(), p.browser);
[email protected]b35b26b32011-05-05 20:35:14672 EXPECT_TRUE(p.browser->is_type_popup());
673 EXPECT_FALSE(p.browser->is_app());
[email protected]a1feae52010-10-11 22:14:45674
675 // The web platform is weird. The window bounds specified in
676 // |p.window_bounds| are used as follows:
677 // - the origin is used to position the window
[email protected]e232c992012-12-06 12:43:20678 // - the size is used to size the WebContents of the window.
[email protected]a1feae52010-10-11 22:14:45679 // As such the position of the resulting window will always match
680 // p.window_bounds.origin(), but its size will not. We need to match
681 // the size against the selected tab's view's container size.
682 // Only Windows positions the window according to |p.window_bounds.origin()| -
683 // on Mac the window is offset from the opener and on Linux it always opens
684 // at 0,0.
685 EXPECT_EQ(p.window_bounds.origin(),
686 p.browser->window()->GetRestoredBounds().origin());
687 // All platforms should respect size however provided width > 400 (Mac has a
688 // minimum window width of 400).
689 EXPECT_EQ(p.window_bounds.size(),
[email protected]e232c992012-12-06 12:43:20690 p.target_contents->GetView()->GetContainerSize());
[email protected]a1feae52010-10-11 22:14:45691
692 // We should have two windows, the new popup and the browser() provided by the
693 // framework.
[email protected]0665ebe2013-02-13 09:53:19694 EXPECT_EQ(2u, chrome::GetTotalBrowserCount());
[email protected]ee496952013-01-10 23:17:33695 EXPECT_EQ(1, browser()->tab_strip_model()->count());
696 EXPECT_EQ(1, p.browser->tab_strip_model()->count());
[email protected]a1feae52010-10-11 22:14:45697}
698#endif
699
700// This tests adding a tab at a specific index.
701IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Tabstrip_InsertAtIndex) {
702 // This is not meant to be a comprehensive test of whether or not the tab
703 // implementation of the browser observes the insertion index. That is
704 // covered by the unit tests for TabStripModel. This merely verifies that
705 // insertion index preference is reflected in common cases.
[email protected]78e2edc2012-07-01 23:32:28706 chrome::NavigateParams p(MakeNavigateParams());
[email protected]a1feae52010-10-11 22:14:45707 p.disposition = NEW_FOREGROUND_TAB;
708 p.tabstrip_index = 0;
709 p.tabstrip_add_types = TabStripModel::ADD_FORCE_INDEX;
[email protected]78e2edc2012-07-01 23:32:28710 chrome::Navigate(&p);
[email protected]a1feae52010-10-11 22:14:45711
712 // Navigate() should have inserted a new tab at slot 0 in the tabstrip.
713 EXPECT_EQ(browser(), p.browser);
[email protected]e232c992012-12-06 12:43:20714 EXPECT_EQ(0, browser()->tab_strip_model()->GetIndexOfWebContents(
715 static_cast<const WebContents*>(p.target_contents)));
[email protected]a1feae52010-10-11 22:14:45716
717 // We should have one window - the browser() provided by the framework.
[email protected]0665ebe2013-02-13 09:53:19718 EXPECT_EQ(1u, chrome::GetTotalBrowserCount());
[email protected]ee496952013-01-10 23:17:33719 EXPECT_EQ(2, browser()->tab_strip_model()->count());
[email protected]a1feae52010-10-11 22:14:45720}
721
[email protected]bb89e7482010-11-17 18:27:04722// This test verifies that constructing params with disposition = SINGLETON_TAB
[email protected]fee320542011-03-02 01:30:49723// and IGNORE_AND_NAVIGATE opens a new tab navigated to the specified URL if
[email protected]67ed83e2011-01-07 22:54:00724// no previous tab with that URL (minus the path) exists.
[email protected]bb89e7482010-11-17 18:27:04725IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
726 Disposition_SingletonTabNew_IgnorePath) {
[email protected]52877dbc62012-06-29 22:22:03727 chrome::AddSelectedTabWithURL(browser(), GetGoogleURL(),
728 content::PAGE_TRANSITION_LINK);
[email protected]bb89e7482010-11-17 18:27:04729
730 // We should have one browser with 2 tabs, the 2nd selected.
[email protected]0665ebe2013-02-13 09:53:19731 EXPECT_EQ(1u, chrome::GetTotalBrowserCount());
[email protected]ee496952013-01-10 23:17:33732 EXPECT_EQ(2, browser()->tab_strip_model()->count());
733 EXPECT_EQ(1, browser()->tab_strip_model()->active_index());
[email protected]bb89e7482010-11-17 18:27:04734
735 // Navigate to a new singleton tab with a sub-page.
[email protected]78e2edc2012-07-01 23:32:28736 chrome::NavigateParams p(MakeNavigateParams());
[email protected]bb89e7482010-11-17 18:27:04737 p.disposition = SINGLETON_TAB;
[email protected]a048ad22012-03-23 04:26:56738 p.url = GetContentSettingsURL();
[email protected]50592b52013-05-02 22:26:25739 p.window_action = chrome::NavigateParams::SHOW_WINDOW;
[email protected]78e2edc2012-07-01 23:32:28740 p.path_behavior = chrome::NavigateParams::IGNORE_AND_NAVIGATE;
741 chrome::Navigate(&p);
[email protected]bb89e7482010-11-17 18:27:04742
743 // The last tab should now be selected and navigated to the sub-page of the
[email protected]50592b52013-05-02 22:26:25744 // URL.
[email protected]bb89e7482010-11-17 18:27:04745 EXPECT_EQ(browser(), p.browser);
[email protected]ee496952013-01-10 23:17:33746 EXPECT_EQ(3, browser()->tab_strip_model()->count());
747 EXPECT_EQ(2, browser()->tab_strip_model()->active_index());
[email protected]a048ad22012-03-23 04:26:56748 EXPECT_EQ(GetContentSettingsURL(),
[email protected]ee496952013-01-10 23:17:33749 ShortenUberURL(browser()->tab_strip_model()->
750 GetActiveWebContents()->GetURL()));
[email protected]bb89e7482010-11-17 18:27:04751}
752
753// This test verifies that constructing params with disposition = SINGLETON_TAB
[email protected]fee320542011-03-02 01:30:49754// and IGNORE_AND_NAVIGATE opens an existing tab with the matching URL (minus
[email protected]bb89e7482010-11-17 18:27:04755// the path) which is navigated to the specified URL.
756IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
757 Disposition_SingletonTabExisting_IgnorePath) {
[email protected]ddddfda2011-07-14 23:19:39758 GURL singleton_url1(GetSettingsURL());
[email protected]52877dbc62012-06-29 22:22:03759 chrome::AddSelectedTabWithURL(browser(), singleton_url1,
760 content::PAGE_TRANSITION_LINK);
761 chrome::AddSelectedTabWithURL(browser(), GetGoogleURL(),
762 content::PAGE_TRANSITION_LINK);
[email protected]bb89e7482010-11-17 18:27:04763
764 // We should have one browser with 3 tabs, the 3rd selected.
[email protected]0665ebe2013-02-13 09:53:19765 EXPECT_EQ(1u, chrome::GetTotalBrowserCount());
[email protected]ee496952013-01-10 23:17:33766 EXPECT_EQ(3, browser()->tab_strip_model()->count());
767 EXPECT_EQ(2, browser()->tab_strip_model()->active_index());
[email protected]bb89e7482010-11-17 18:27:04768
769 // Navigate to singleton_url1.
[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 middle tab should now be selected and navigated to the sub-page of the
778 // URL.
779 EXPECT_EQ(browser(), p.browser);
[email protected]ee496952013-01-10 23:17:33780 EXPECT_EQ(3, browser()->tab_strip_model()->count());
781 EXPECT_EQ(1, 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_SingletonTabExistingSubPath_IgnorePath) {
[email protected]a048ad22012-03-23 04:26:56792 GURL singleton_url1(GetContentSettingsURL());
[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 = GetClearBrowsingDataURL();
[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(GetClearBrowsingDataURL(),
[email protected]ee496952013-01-10 23:17:33817 ShortenUberURL(browser()->tab_strip_model()->
818 GetActiveWebContents()->GetURL()));
[email protected]bb89e7482010-11-17 18:27:04819}
[email protected]2dd85482010-11-06 01:56:47820
[email protected]637b3442011-01-10 23:31:48821// This test verifies that constructing params with disposition = SINGLETON_TAB
[email protected]fee320542011-03-02 01:30:49822// and IGNORE_AND_STAY_PUT opens an existing tab with the matching URL (minus
823// the path).
824IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
825 Disposition_SingletonTabExistingSubPath_IgnorePath2) {
[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]fee320542011-03-02 01:30:49831
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]fee320542011-03-02 01:30:49836
837 // Navigate to singleton_url1.
[email protected]78e2edc2012-07-01 23:32:28838 chrome::NavigateParams p(MakeNavigateParams());
[email protected]fee320542011-03-02 01:30:49839 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_STAY_PUT;
843 chrome::Navigate(&p);
[email protected]fee320542011-03-02 01:30:49844
845 // The middle tab should now be selected.
846 EXPECT_EQ(browser(), p.browser);
[email protected]ee496952013-01-10 23:17:33847 EXPECT_EQ(3, browser()->tab_strip_model()->count());
848 EXPECT_EQ(1, browser()->tab_strip_model()->active_index());
[email protected]fee320542011-03-02 01:30:49849 EXPECT_EQ(singleton_url1,
[email protected]ee496952013-01-10 23:17:33850 ShortenUberURL(browser()->tab_strip_model()->
851 GetActiveWebContents()->GetURL()));
[email protected]fee320542011-03-02 01:30:49852}
853
854// This test verifies that constructing params with disposition = SINGLETON_TAB
855// and IGNORE_AND_NAVIGATE will update the current tab's URL if the currently
[email protected]637b3442011-01-10 23:31:48856// selected tab is a match but has a different path.
857IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
858 Disposition_SingletonTabFocused_IgnorePath) {
[email protected]a048ad22012-03-23 04:26:56859 GURL singleton_url_current(GetContentSettingsURL());
[email protected]52877dbc62012-06-29 22:22:03860 chrome::AddSelectedTabWithURL(browser(), singleton_url_current,
861 content::PAGE_TRANSITION_LINK);
[email protected]637b3442011-01-10 23:31:48862
863 // We should have one browser with 2 tabs, the 2nd selected.
[email protected]0665ebe2013-02-13 09:53:19864 EXPECT_EQ(1u, chrome::GetTotalBrowserCount());
[email protected]ee496952013-01-10 23:17:33865 EXPECT_EQ(2, browser()->tab_strip_model()->count());
866 EXPECT_EQ(1, browser()->tab_strip_model()->active_index());
[email protected]637b3442011-01-10 23:31:48867
868 // Navigate to a different settings path.
[email protected]a048ad22012-03-23 04:26:56869 GURL singleton_url_target(GetClearBrowsingDataURL());
[email protected]78e2edc2012-07-01 23:32:28870 chrome::NavigateParams p(MakeNavigateParams());
[email protected]637b3442011-01-10 23:31:48871 p.disposition = SINGLETON_TAB;
872 p.url = singleton_url_target;
[email protected]50592b52013-05-02 22:26:25873 p.window_action = chrome::NavigateParams::SHOW_WINDOW;
[email protected]78e2edc2012-07-01 23:32:28874 p.path_behavior = chrome::NavigateParams::IGNORE_AND_NAVIGATE;
875 chrome::Navigate(&p);
[email protected]637b3442011-01-10 23:31:48876
877 // The second tab should still be selected, but navigated to the new path.
878 EXPECT_EQ(browser(), p.browser);
[email protected]ee496952013-01-10 23:17:33879 EXPECT_EQ(2, browser()->tab_strip_model()->count());
880 EXPECT_EQ(1, browser()->tab_strip_model()->active_index());
[email protected]637b3442011-01-10 23:31:48881 EXPECT_EQ(singleton_url_target,
[email protected]ee496952013-01-10 23:17:33882 ShortenUberURL(browser()->tab_strip_model()->
883 GetActiveWebContents()->GetURL()));
[email protected]637b3442011-01-10 23:31:48884}
885
[email protected]07afd7c2011-02-17 10:07:11886// This test verifies that constructing params with disposition = SINGLETON_TAB
[email protected]fee320542011-03-02 01:30:49887// and IGNORE_AND_NAVIGATE will open an existing matching tab with a different
888// query.
[email protected]07afd7c2011-02-17 10:07:11889IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
890 Disposition_SingletonTabExisting_IgnoreQuery) {
[email protected]ee496952013-01-10 23:17:33891 int initial_tab_count = browser()->tab_strip_model()->count();
[email protected]07afd7c2011-02-17 10:07:11892 GURL singleton_url_current("chrome://settings/internet");
[email protected]52877dbc62012-06-29 22:22:03893 chrome::AddSelectedTabWithURL(browser(), singleton_url_current,
894 content::PAGE_TRANSITION_LINK);
[email protected]07afd7c2011-02-17 10:07:11895
[email protected]ee496952013-01-10 23:17:33896 EXPECT_EQ(initial_tab_count + 1, browser()->tab_strip_model()->count());
897 EXPECT_EQ(initial_tab_count, browser()->tab_strip_model()->active_index());
[email protected]07afd7c2011-02-17 10:07:11898
899 // Navigate to a different settings path.
900 GURL singleton_url_target(
901 "chrome://settings/internet?"
902 "servicePath=/profile/ethernet_00aa00aa00aa&networkType=1");
[email protected]78e2edc2012-07-01 23:32:28903 chrome::NavigateParams p(MakeNavigateParams());
[email protected]07afd7c2011-02-17 10:07:11904 p.disposition = SINGLETON_TAB;
905 p.url = singleton_url_target;
[email protected]50592b52013-05-02 22:26:25906 p.window_action = chrome::NavigateParams::SHOW_WINDOW;
[email protected]78e2edc2012-07-01 23:32:28907 p.path_behavior = chrome::NavigateParams::IGNORE_AND_NAVIGATE;
908 chrome::Navigate(&p);
[email protected]07afd7c2011-02-17 10:07:11909
910 // Last tab should still be selected.
911 EXPECT_EQ(browser(), p.browser);
[email protected]ee496952013-01-10 23:17:33912 EXPECT_EQ(initial_tab_count + 1, browser()->tab_strip_model()->count());
913 EXPECT_EQ(initial_tab_count, browser()->tab_strip_model()->active_index());
[email protected]07afd7c2011-02-17 10:07:11914}
915
[email protected]bd817c22011-02-09 08:16:46916// This test verifies that the settings page isn't opened in the incognito
917// window.
[email protected]a048ad22012-03-23 04:26:56918// Disabled until fixed for uber settings: http://crbug.com/111243
[email protected]bd817c22011-02-09 08:16:46919IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
[email protected]a048ad22012-03-23 04:26:56920 DISABLED_Disposition_Settings_UseNonIncognitoWindow) {
[email protected]fc0ed302011-11-29 23:17:19921 RunUseNonIncognitoWindowTest(GetSettingsURL());
[email protected]bd817c22011-02-09 08:16:46922}
923
[email protected]429e9712013-04-30 09:35:50924// This test verifies that the view-source settings page isn't opened in the
925// incognito window.
926IN_PROC_BROWSER_TEST_F(
927 BrowserNavigatorTest,
928 Disposition_ViewSource_Settings_DoNothingIfIncognitoForced) {
929 std::string view_source(chrome::kViewSourceScheme);
930 view_source.append(":");
931 view_source.append(chrome::kChromeUISettingsURL);
932 RunDoNothingIfIncognitoIsForcedTest(GURL(view_source));
933}
934
935// This test verifies that the view-source settings page isn't opened in the
936// incognito window even if incognito mode is forced (does nothing in that
937// case).
938IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
939 Disposition_ViewSource_Settings_UseNonIncognitoWindow) {
940 std::string view_source(chrome::kViewSourceScheme);
941 view_source.append(":");
942 view_source.append(chrome::kChromeUISettingsURL);
943 RunUseNonIncognitoWindowTest(GURL(view_source));
944}
945
[email protected]82404cd2011-07-12 19:55:14946// This test verifies that the settings page isn't opened in the incognito
947// window from a non-incognito window (bookmark open-in-incognito trigger).
[email protected]a048ad22012-03-23 04:26:56948// Disabled until fixed for uber settings: http://crbug.com/111243
[email protected]82404cd2011-07-12 19:55:14949IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
[email protected]a048ad22012-03-23 04:26:56950 DISABLED_Disposition_Settings_UseNonIncognitoWindowForBookmark) {
[email protected]78e2edc2012-07-01 23:32:28951 chrome::NavigateParams params(browser(), GetSettingsURL(),
952 content::PAGE_TRANSITION_AUTO_BOOKMARK);
[email protected]82404cd2011-07-12 19:55:14953 params.disposition = OFF_THE_RECORD;
954 {
[email protected]a7fe9112012-07-20 02:34:45955 content::WindowedNotificationObserver observer(
[email protected]ad50def52011-10-19 23:17:07956 content::NOTIFICATION_LOAD_STOP,
957 content::NotificationService::AllSources());
[email protected]78e2edc2012-07-01 23:32:28958 chrome::Navigate(&params);
[email protected]82404cd2011-07-12 19:55:14959 observer.Wait();
960 }
961
[email protected]0665ebe2013-02-13 09:53:19962 EXPECT_EQ(1u, chrome::GetTotalBrowserCount());
[email protected]52877dbc62012-06-29 22:22:03963 EXPECT_EQ(GetSettingsURL(),
[email protected]ee496952013-01-10 23:17:33964 ShortenUberURL(browser()->tab_strip_model()->
965 GetActiveWebContents()->GetURL()));
[email protected]82404cd2011-07-12 19:55:14966}
967
[email protected]93ad8e1c2011-11-08 21:34:05968// Settings page is expected to always open in normal mode regardless
969// of whether the user is trying to open it in incognito mode or not.
970// This test verifies that if incognito mode is forced (by policy), settings
971// page doesn't open at all.
[email protected]a048ad22012-03-23 04:26:56972// Disabled until fixed for uber settings: http://crbug.com/111243
[email protected]93ad8e1c2011-11-08 21:34:05973IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
[email protected]a048ad22012-03-23 04:26:56974 DISABLED_Disposition_Settings_DoNothingIfIncognitoIsForced) {
[email protected]fc0ed302011-11-29 23:17:19975 RunDoNothingIfIncognitoIsForcedTest(GetSettingsURL());
[email protected]93ad8e1c2011-11-08 21:34:05976}
977
[email protected]bd817c22011-02-09 08:16:46978// This test verifies that the bookmarks page isn't opened in the incognito
979// window.
980IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
981 Disposition_Bookmarks_UseNonIncognitoWindow) {
[email protected]fc0ed302011-11-29 23:17:19982 RunUseNonIncognitoWindowTest(GURL(chrome::kChromeUIBookmarksURL));
[email protected]bd817c22011-02-09 08:16:46983}
984
[email protected]93ad8e1c2011-11-08 21:34:05985// Bookmark manager is expected to always open in normal mode regardless
986// of whether the user is trying to open it in incognito mode or not.
987// This test verifies that if incognito mode is forced (by policy), bookmark
988// manager doesn't open at all.
989IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
990 Disposition_Bookmarks_DoNothingIfIncognitoIsForced) {
[email protected]fc0ed302011-11-29 23:17:19991 RunDoNothingIfIncognitoIsForcedTest(GURL(chrome::kChromeUIBookmarksURL));
992}
[email protected]93ad8e1c2011-11-08 21:34:05993
[email protected]fc0ed302011-11-29 23:17:19994// This test verifies that the sync promo page isn't opened in the incognito
995// window.
996IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
997 Disposition_SyncPromo_UseNonIncognitoWindow) {
998 RunUseNonIncognitoWindowTest(GURL(chrome::kChromeUISyncPromoURL));
999}
[email protected]93ad8e1c2011-11-08 21:34:051000
[email protected]fc0ed302011-11-29 23:17:191001// The Sync promo page is expected to always open in normal mode regardless of
1002// whether the user is trying to open it in incognito mode or not. This test
1003// verifies that if incognito mode is forced (by policy), the sync promo page
1004// doesn't open at all.
1005IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
1006 Disposition_SyncPromo_DoNothingIfIncognitoIsForced) {
1007 RunDoNothingIfIncognitoIsForcedTest(GURL(chrome::kChromeUISyncPromoURL));
[email protected]93ad8e1c2011-11-08 21:34:051008}
1009
[email protected]7de53c62011-05-13 06:44:161010// This test makes sure a crashed singleton tab reloads from a new navigation.
1011IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
1012 NavigateToCrashedSingletonTab) {
[email protected]a048ad22012-03-23 04:26:561013 GURL singleton_url(GetContentSettingsURL());
[email protected]5a1a52462012-11-15 03:35:161014 WebContents* web_contents = chrome::AddSelectedTabWithURL(
[email protected]52877dbc62012-06-29 22:22:031015 browser(), singleton_url, content::PAGE_TRANSITION_LINK);
[email protected]7de53c62011-05-13 06:44:161016
1017 // We should have one browser with 2 tabs, the 2nd selected.
[email protected]0665ebe2013-02-13 09:53:191018 EXPECT_EQ(1u, chrome::GetTotalBrowserCount());
[email protected]ee496952013-01-10 23:17:331019 EXPECT_EQ(2, browser()->tab_strip_model()->count());
1020 EXPECT_EQ(1, browser()->tab_strip_model()->active_index());
[email protected]7de53c62011-05-13 06:44:161021
1022 // Kill the singleton tab.
[email protected]83ff91c2012-01-05 20:54:131023 web_contents->SetIsCrashed(base::TERMINATION_STATUS_PROCESS_CRASHED, -1);
1024 EXPECT_TRUE(web_contents->IsCrashed());
[email protected]7de53c62011-05-13 06:44:161025
[email protected]78e2edc2012-07-01 23:32:281026 chrome::NavigateParams p(MakeNavigateParams());
[email protected]7de53c62011-05-13 06:44:161027 p.disposition = SINGLETON_TAB;
1028 p.url = singleton_url;
[email protected]50592b52013-05-02 22:26:251029 p.window_action = chrome::NavigateParams::SHOW_WINDOW;
[email protected]78e2edc2012-07-01 23:32:281030 p.path_behavior = chrome::NavigateParams::IGNORE_AND_NAVIGATE;
[email protected]ddddfda2011-07-14 23:19:391031 ui_test_utils::NavigateToURL(&p);
[email protected]7de53c62011-05-13 06:44:161032
1033 // The tab should not be sad anymore.
[email protected]83ff91c2012-01-05 20:54:131034 EXPECT_FALSE(web_contents->IsCrashed());
[email protected]7de53c62011-05-13 06:44:161035}
1036
[email protected]fcca741b2011-06-17 22:46:371037IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
1038 NavigateFromDefaultToOptionsInSameTab) {
[email protected]ddddfda2011-07-14 23:19:391039 {
[email protected]a7fe9112012-07-20 02:34:451040 content::WindowedNotificationObserver observer(
[email protected]ad50def52011-10-19 23:17:071041 content::NOTIFICATION_LOAD_STOP,
1042 content::NotificationService::AllSources());
[email protected]5d9cace72012-06-21 16:07:121043 chrome::ShowSettings(browser());
[email protected]ddddfda2011-07-14 23:19:391044 observer.Wait();
1045 }
[email protected]ee496952013-01-10 23:17:331046 EXPECT_EQ(1, browser()->tab_strip_model()->count());
[email protected]52877dbc62012-06-29 22:22:031047 EXPECT_EQ(GetSettingsURL(),
[email protected]ee496952013-01-10 23:17:331048 ShortenUberURL(browser()->tab_strip_model()->
1049 GetActiveWebContents()->GetURL()));
[email protected]fcca741b2011-06-17 22:46:371050}
1051
1052IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
1053 NavigateFromBlankToOptionsInSameTab) {
[email protected]78e2edc2012-07-01 23:32:281054 chrome::NavigateParams p(MakeNavigateParams());
[email protected]081dc522013-05-15 04:59:201055 p.url = GURL(content::kAboutBlankURL);
[email protected]ddddfda2011-07-14 23:19:391056 ui_test_utils::NavigateToURL(&p);
[email protected]fcca741b2011-06-17 22:46:371057
[email protected]ddddfda2011-07-14 23:19:391058 {
[email protected]a7fe9112012-07-20 02:34:451059 content::WindowedNotificationObserver observer(
[email protected]ad50def52011-10-19 23:17:071060 content::NOTIFICATION_LOAD_STOP,
1061 content::NotificationService::AllSources());
[email protected]5d9cace72012-06-21 16:07:121062 chrome::ShowSettings(browser());
[email protected]ddddfda2011-07-14 23:19:391063 observer.Wait();
1064 }
[email protected]ee496952013-01-10 23:17:331065 EXPECT_EQ(1, browser()->tab_strip_model()->count());
[email protected]52877dbc62012-06-29 22:22:031066 EXPECT_EQ(GetSettingsURL(),
[email protected]ee496952013-01-10 23:17:331067 ShortenUberURL(browser()->tab_strip_model()->
1068 GetActiveWebContents()->GetURL()));
[email protected]fcca741b2011-06-17 22:46:371069}
1070
1071IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
1072 NavigateFromNTPToOptionsInSameTab) {
[email protected]78e2edc2012-07-01 23:32:281073 chrome::NavigateParams p(MakeNavigateParams());
[email protected]ddddfda2011-07-14 23:19:391074 p.url = GURL(chrome::kChromeUINewTabURL);
1075 ui_test_utils::NavigateToURL(&p);
[email protected]ee496952013-01-10 23:17:331076 EXPECT_EQ(1, browser()->tab_strip_model()->count());
[email protected]ddddfda2011-07-14 23:19:391077 EXPECT_EQ(GURL(chrome::kChromeUINewTabURL),
[email protected]ee496952013-01-10 23:17:331078 browser()->tab_strip_model()->GetActiveWebContents()->GetURL());
[email protected]fcca741b2011-06-17 22:46:371079
[email protected]ddddfda2011-07-14 23:19:391080 {
[email protected]a7fe9112012-07-20 02:34:451081 content::WindowedNotificationObserver observer(
[email protected]ad50def52011-10-19 23:17:071082 content::NOTIFICATION_LOAD_STOP,
1083 content::NotificationService::AllSources());
[email protected]5d9cace72012-06-21 16:07:121084 chrome::ShowSettings(browser());
[email protected]ddddfda2011-07-14 23:19:391085 observer.Wait();
1086 }
[email protected]ee496952013-01-10 23:17:331087 EXPECT_EQ(1, browser()->tab_strip_model()->count());
[email protected]52877dbc62012-06-29 22:22:031088 EXPECT_EQ(GetSettingsURL(),
[email protected]ee496952013-01-10 23:17:331089 ShortenUberURL(browser()->tab_strip_model()->
1090 GetActiveWebContents()->GetURL()));
[email protected]fcca741b2011-06-17 22:46:371091}
1092
1093IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
1094 NavigateFromPageToOptionsInNewTab) {
[email protected]78e2edc2012-07-01 23:32:281095 chrome::NavigateParams p(MakeNavigateParams());
[email protected]ddddfda2011-07-14 23:19:391096 ui_test_utils::NavigateToURL(&p);
[email protected]ee496952013-01-10 23:17:331097 EXPECT_EQ(GetGoogleURL(),
1098 browser()->tab_strip_model()->GetActiveWebContents()->GetURL());
[email protected]0665ebe2013-02-13 09:53:191099 EXPECT_EQ(1u, chrome::GetTotalBrowserCount());
[email protected]ee496952013-01-10 23:17:331100 EXPECT_EQ(1, browser()->tab_strip_model()->count());
[email protected]fcca741b2011-06-17 22:46:371101
[email protected]ddddfda2011-07-14 23:19:391102 {
[email protected]a7fe9112012-07-20 02:34:451103 content::WindowedNotificationObserver observer(
[email protected]ad50def52011-10-19 23:17:071104 content::NOTIFICATION_LOAD_STOP,
1105 content::NotificationService::AllSources());
[email protected]5d9cace72012-06-21 16:07:121106 chrome::ShowSettings(browser());
[email protected]ddddfda2011-07-14 23:19:391107 observer.Wait();
1108 }
[email protected]ee496952013-01-10 23:17:331109 EXPECT_EQ(2, browser()->tab_strip_model()->count());
[email protected]52877dbc62012-06-29 22:22:031110 EXPECT_EQ(GetSettingsURL(),
[email protected]ee496952013-01-10 23:17:331111 ShortenUberURL(browser()->tab_strip_model()->
1112 GetActiveWebContents()->GetURL()));
[email protected]fcca741b2011-06-17 22:46:371113}
1114
1115IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
1116 NavigateFromNTPToOptionsSingleton) {
[email protected]ddddfda2011-07-14 23:19:391117 {
[email protected]a7fe9112012-07-20 02:34:451118 content::WindowedNotificationObserver observer(
[email protected]ad50def52011-10-19 23:17:071119 content::NOTIFICATION_LOAD_STOP,
1120 content::NotificationService::AllSources());
[email protected]5d9cace72012-06-21 16:07:121121 chrome::ShowSettings(browser());
[email protected]ddddfda2011-07-14 23:19:391122 observer.Wait();
1123 }
[email protected]ee496952013-01-10 23:17:331124 EXPECT_EQ(1, browser()->tab_strip_model()->count());
[email protected]fcca741b2011-06-17 22:46:371125
[email protected]a37d4b02012-06-25 21:56:101126 chrome::NewTab(browser());
[email protected]ee496952013-01-10 23:17:331127 EXPECT_EQ(2, browser()->tab_strip_model()->count());
[email protected]fcca741b2011-06-17 22:46:371128
[email protected]ddddfda2011-07-14 23:19:391129 {
[email protected]a7fe9112012-07-20 02:34:451130 content::WindowedNotificationObserver observer(
[email protected]ad50def52011-10-19 23:17:071131 content::NOTIFICATION_LOAD_STOP,
1132 content::NotificationService::AllSources());
[email protected]5d9cace72012-06-21 16:07:121133 chrome::ShowSettings(browser());
[email protected]ddddfda2011-07-14 23:19:391134 observer.Wait();
1135 }
[email protected]ee496952013-01-10 23:17:331136 EXPECT_EQ(2, browser()->tab_strip_model()->count());
[email protected]52877dbc62012-06-29 22:22:031137 EXPECT_EQ(GetSettingsURL(),
[email protected]ee496952013-01-10 23:17:331138 ShortenUberURL(browser()->tab_strip_model()->
1139 GetActiveWebContents()->GetURL()));
[email protected]fcca741b2011-06-17 22:46:371140}
1141
1142IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
1143 NavigateFromNTPToOptionsPageInSameTab) {
[email protected]ddddfda2011-07-14 23:19:391144 {
[email protected]a7fe9112012-07-20 02:34:451145 content::WindowedNotificationObserver observer(
[email protected]ad50def52011-10-19 23:17:071146 content::NOTIFICATION_LOAD_STOP,
1147 content::NotificationService::AllSources());
[email protected]5d9cace72012-06-21 16:07:121148 chrome::ShowClearBrowsingDataDialog(browser());
[email protected]ddddfda2011-07-14 23:19:391149 observer.Wait();
1150 }
[email protected]ee496952013-01-10 23:17:331151 EXPECT_EQ(1, browser()->tab_strip_model()->count());
[email protected]a048ad22012-03-23 04:26:561152 EXPECT_EQ(GetClearBrowsingDataURL(),
[email protected]ee496952013-01-10 23:17:331153 browser()->tab_strip_model()->GetActiveWebContents()->GetURL());
[email protected]fcca741b2011-06-17 22:46:371154
[email protected]a37d4b02012-06-25 21:56:101155 chrome::NewTab(browser());
[email protected]ee496952013-01-10 23:17:331156 EXPECT_EQ(2, browser()->tab_strip_model()->count());
[email protected]fcca741b2011-06-17 22:46:371157
[email protected]ddddfda2011-07-14 23:19:391158 {
[email protected]a7fe9112012-07-20 02:34:451159 content::WindowedNotificationObserver observer(
[email protected]ad50def52011-10-19 23:17:071160 content::NOTIFICATION_LOAD_STOP,
1161 content::NotificationService::AllSources());
[email protected]5d9cace72012-06-21 16:07:121162 chrome::ShowClearBrowsingDataDialog(browser());
[email protected]ddddfda2011-07-14 23:19:391163 observer.Wait();
1164 }
[email protected]ee496952013-01-10 23:17:331165 EXPECT_EQ(2, browser()->tab_strip_model()->count());
[email protected]a048ad22012-03-23 04:26:561166 EXPECT_EQ(GetClearBrowsingDataURL(),
[email protected]ee496952013-01-10 23:17:331167 browser()->tab_strip_model()->GetActiveWebContents()->GetURL());
[email protected]fcca741b2011-06-17 22:46:371168}
1169
[email protected]fcca741b2011-06-17 22:46:371170IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
[email protected]05912742013-03-12 00:29:151171 NavigateFromOtherTabToSingletonOptions) {
[email protected]ddddfda2011-07-14 23:19:391172 {
[email protected]a7fe9112012-07-20 02:34:451173 content::WindowedNotificationObserver observer(
[email protected]ad50def52011-10-19 23:17:071174 content::NOTIFICATION_LOAD_STOP,
1175 content::NotificationService::AllSources());
[email protected]5d9cace72012-06-21 16:07:121176 chrome::ShowSettings(browser());
[email protected]ddddfda2011-07-14 23:19:391177 observer.Wait();
1178 }
1179 {
[email protected]a7fe9112012-07-20 02:34:451180 content::WindowedNotificationObserver observer(
[email protected]ad50def52011-10-19 23:17:071181 content::NOTIFICATION_LOAD_STOP,
1182 content::NotificationService::AllSources());
[email protected]52877dbc62012-06-29 22:22:031183 chrome::AddSelectedTabWithURL(browser(), GetGoogleURL(),
1184 content::PAGE_TRANSITION_LINK);
[email protected]ddddfda2011-07-14 23:19:391185 observer.Wait();
1186 }
[email protected]fcca741b2011-06-17 22:46:371187
[email protected]05912742013-03-12 00:29:151188 // This load should simply cause a tab switch.
1189 chrome::ShowSettings(browser());
1190
[email protected]ee496952013-01-10 23:17:331191 EXPECT_EQ(2, browser()->tab_strip_model()->count());
[email protected]ddddfda2011-07-14 23:19:391192 EXPECT_EQ(GetSettingsURL(),
[email protected]ee496952013-01-10 23:17:331193 ShortenUberURL(browser()->tab_strip_model()->
1194 GetActiveWebContents()->GetURL()));
[email protected]fcca741b2011-06-17 22:46:371195}
1196
[email protected]79717cf2013-02-28 18:40:361197IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, CloseSingletonTab) {
1198 for (int i = 0; i < 2; ++i) {
1199 content::WindowedNotificationObserver observer(
1200 content::NOTIFICATION_LOAD_STOP,
1201 content::NotificationService::AllSources());
1202 chrome::AddSelectedTabWithURL(browser(), GetGoogleURL(),
1203 content::PAGE_TRANSITION_TYPED);
1204 observer.Wait();
1205 }
1206
1207 browser()->tab_strip_model()->ActivateTabAt(0, true);
1208
1209 {
1210 content::WindowedNotificationObserver observer(
1211 content::NOTIFICATION_LOAD_STOP,
1212 content::NotificationService::AllSources());
1213 chrome::ShowSettings(browser());
1214 observer.Wait();
1215 }
1216
1217 EXPECT_TRUE(browser()->tab_strip_model()->CloseWebContentsAt(
1218 2, TabStripModel::CLOSE_USER_GESTURE));
1219 EXPECT_EQ(0, browser()->tab_strip_model()->active_index());
1220}
1221
[email protected]a048ad22012-03-23 04:26:561222// TODO(csilv): Update this for uber page. http://crbug.com/111579.
[email protected]ddddfda2011-07-14 23:19:391223IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
[email protected]a048ad22012-03-23 04:26:561224 DISABLED_NavigateFromDefaultToHistoryInSameTab) {
[email protected]ddddfda2011-07-14 23:19:391225 {
[email protected]a7fe9112012-07-20 02:34:451226 content::WindowedNotificationObserver observer(
[email protected]ad50def52011-10-19 23:17:071227 content::NOTIFICATION_LOAD_STOP,
1228 content::NotificationService::AllSources());
[email protected]5d9cace72012-06-21 16:07:121229 chrome::ShowHistory(browser());
[email protected]ddddfda2011-07-14 23:19:391230 observer.Wait();
1231 }
[email protected]ee496952013-01-10 23:17:331232 EXPECT_EQ(1, browser()->tab_strip_model()->count());
[email protected]11e03fb2012-03-03 19:07:051233 EXPECT_EQ(GURL(chrome::kChromeUIHistoryFrameURL),
[email protected]ee496952013-01-10 23:17:331234 browser()->tab_strip_model()->GetActiveWebContents()->GetURL());
[email protected]ddddfda2011-07-14 23:19:391235}
1236
[email protected]953c2132013-02-23 05:56:051237// TODO(linux_aura) http://crbug.com/163931
1238#if defined(OS_LINUX) && !defined(OS_CHROMEOS) && defined(USE_AURA)
1239#define MAYBE_NavigateFromDefaultToBookmarksInSameTab DISABLED_NavigateFromDefaultToBookmarksInSameTab
1240#else
1241#define MAYBE_NavigateFromDefaultToBookmarksInSameTab NavigateFromDefaultToBookmarksInSameTab
1242#endif
[email protected]ddddfda2011-07-14 23:19:391243IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
[email protected]953c2132013-02-23 05:56:051244 MAYBE_NavigateFromDefaultToBookmarksInSameTab) {
[email protected]ddddfda2011-07-14 23:19:391245 {
[email protected]a7fe9112012-07-20 02:34:451246 content::WindowedNotificationObserver observer(
[email protected]ad50def52011-10-19 23:17:071247 content::NOTIFICATION_LOAD_STOP,
1248 content::NotificationService::AllSources());
[email protected]5d9cace72012-06-21 16:07:121249 chrome::ShowBookmarkManager(browser());
[email protected]ddddfda2011-07-14 23:19:391250 observer.Wait();
1251 }
[email protected]ee496952013-01-10 23:17:331252 EXPECT_EQ(1, browser()->tab_strip_model()->count());
[email protected]bc16a252013-01-23 02:21:491253 EXPECT_TRUE(StartsWithASCII(
1254 browser()->tab_strip_model()->GetActiveWebContents()->GetURL().spec(),
1255 chrome::kChromeUIBookmarksURL,
1256 true));
[email protected]ddddfda2011-07-14 23:19:391257}
1258
1259IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
1260 NavigateFromDefaultToDownloadsInSameTab) {
1261 {
[email protected]a7fe9112012-07-20 02:34:451262 content::WindowedNotificationObserver observer(
[email protected]ad50def52011-10-19 23:17:071263 content::NOTIFICATION_LOAD_STOP,
1264 content::NotificationService::AllSources());
[email protected]5d9cace72012-06-21 16:07:121265 chrome::ShowDownloads(browser());
[email protected]ddddfda2011-07-14 23:19:391266 observer.Wait();
1267 }
[email protected]ee496952013-01-10 23:17:331268 EXPECT_EQ(1, browser()->tab_strip_model()->count());
[email protected]ddddfda2011-07-14 23:19:391269 EXPECT_EQ(GURL(chrome::kChromeUIDownloadsURL),
[email protected]ee496952013-01-10 23:17:331270 browser()->tab_strip_model()->GetActiveWebContents()->GetURL());
[email protected]ddddfda2011-07-14 23:19:391271}
1272
[email protected]8fb16a82012-08-17 02:17:591273IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
1274 NavigateWithoutBrowser) {
1275 // First navigate using the profile of the existing browser window, and
1276 // check that the window is reused.
1277 chrome::NavigateParams params(browser()->profile(), GetGoogleURL(),
1278 content::PAGE_TRANSITION_LINK);
1279 ui_test_utils::NavigateToURL(&params);
[email protected]0665ebe2013-02-13 09:53:191280 EXPECT_EQ(1u, chrome::GetTotalBrowserCount());
[email protected]8fb16a82012-08-17 02:17:591281
1282 // Now navigate using the incognito profile and check that a new window
1283 // is created.
1284 chrome::NavigateParams params_incognito(
1285 browser()->profile()->GetOffTheRecordProfile(),
1286 GetGoogleURL(), content::PAGE_TRANSITION_LINK);
1287 ui_test_utils::NavigateToURL(&params_incognito);
[email protected]0665ebe2013-02-13 09:53:191288 EXPECT_EQ(2u, chrome::GetTotalBrowserCount());
[email protected]8fb16a82012-08-17 02:17:591289}
1290
[email protected]beb1d1192013-05-14 04:47:511291IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, ViewSourceIsntSingleton) {
1292 const std::string viewsource_ntp_url =
1293 std::string(chrome::kViewSourceScheme) + ":" +
1294 chrome::kChromeUIVersionURL;
1295
1296 chrome::NavigateParams viewsource_params(browser(),
1297 GURL(viewsource_ntp_url),
1298 content::PAGE_TRANSITION_LINK);
1299 ui_test_utils::NavigateToURL(&viewsource_params);
1300
1301 chrome::NavigateParams singleton_params(browser(),
1302 GURL(chrome::kChromeUIVersionURL),
1303 content::PAGE_TRANSITION_LINK);
1304 singleton_params.disposition = SINGLETON_TAB;
1305 EXPECT_EQ(-1, chrome::GetIndexOfSingletonTab(&singleton_params));
1306}
1307
[email protected]ddddfda2011-07-14 23:19:391308} // namespace