blob: e936a6c4d2e6332ec0de1da22c019509d0bf6cbb [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]b56e2e32012-05-11 21:18:0419#include "chrome/browser/ui/tabs/tab_strip_model.h"
[email protected]bb89e7482010-11-17 18:27:0420#include "chrome/common/chrome_switches.h"
[email protected]93ad8e1c2011-11-08 21:34:0521#include "chrome/common/pref_names.h"
[email protected]ddddfda2011-07-14 23:19:3922#include "chrome/common/url_constants.h"
[email protected]af44e7fb2011-07-29 18:32:3223#include "chrome/test/base/ui_test_utils.h"
[email protected]ad50def52011-10-19 23:17:0724#include "content/public/browser/notification_service.h"
[email protected]0d6e9bd2011-10-18 04:29:1625#include "content/public/browser/notification_types.h"
[email protected]83ff91c2012-01-05 20:54:1326#include "content/public/browser/web_contents.h"
[email protected]8643e6d2012-01-18 20:26:1027#include "content/public/browser/web_contents_view.h"
[email protected]c47317e2012-06-20 22:35:3128#include "ipc/ipc_message.h"
[email protected]a1feae52010-10-11 22:14:4529
[email protected]4ca15302012-01-03 05:53:2030using content::WebContents;
31
[email protected]ddddfda2011-07-14 23:19:3932namespace {
33
34GURL GetGoogleURL() {
[email protected]bd817c22011-02-09 08:16:4635 return GURL("http://www.google.com/");
36}
[email protected]a1feae52010-10-11 22:14:4537
[email protected]ddddfda2011-07-14 23:19:3938GURL GetSettingsURL() {
[email protected]f8f93eb2012-09-25 03:06:2439 return GURL(chrome::kChromeUISettingsURL);
[email protected]ddddfda2011-07-14 23:19:3940}
41
[email protected]a048ad22012-03-23 04:26:5642GURL GetContentSettingsURL() {
43 return GetSettingsURL().Resolve(chrome::kContentSettingsExceptionsSubPage);
[email protected]ddddfda2011-07-14 23:19:3944}
45
[email protected]a048ad22012-03-23 04:26:5646GURL GetClearBrowsingDataURL() {
47 return GetSettingsURL().Resolve(chrome::kClearBrowserDataSubPage);
[email protected]ddddfda2011-07-14 23:19:3948}
49
[email protected]f8f93eb2012-09-25 03:06:2450// Converts long uber URLs ("chrome://chrome/foo/") to short (virtual) URLs
51// ("chrome://foo/"). This should be used to convert the return value of
52// WebContentsImpl::GetURL before comparison because it can return either the
53// real URL or the virtual URL.
54GURL ShortenUberURL(const GURL& url) {
55 std::string url_string = url.spec();
56 const std::string long_prefix = "chrome://chrome/";
57 const std::string short_prefix = "chrome://";
58 if (url_string.find(long_prefix) != 0)
59 return url;
60 url_string.replace(0, long_prefix.length(), short_prefix);
61 return GURL(url_string);
62}
63
[email protected]ddddfda2011-07-14 23:19:3964} // namespace
65
[email protected]78e2edc2012-07-01 23:32:2866chrome::NavigateParams BrowserNavigatorTest::MakeNavigateParams() const {
[email protected]bd817c22011-02-09 08:16:4667 return MakeNavigateParams(browser());
68}
[email protected]a1feae52010-10-11 22:14:4569
[email protected]78e2edc2012-07-01 23:32:2870chrome::NavigateParams BrowserNavigatorTest::MakeNavigateParams(
[email protected]bd817c22011-02-09 08:16:4671 Browser* browser) const {
[email protected]78e2edc2012-07-01 23:32:2872 chrome::NavigateParams params(browser, GetGoogleURL(),
73 content::PAGE_TRANSITION_LINK);
74 params.window_action = chrome::NavigateParams::SHOW_WINDOW;
[email protected]bd817c22011-02-09 08:16:4675 return params;
76}
[email protected]a1feae52010-10-11 22:14:4577
[email protected]bd817c22011-02-09 08:16:4678Browser* BrowserNavigatorTest::CreateEmptyBrowserForType(Browser::Type type,
79 Profile* profile) {
[email protected]2b09ae552013-02-23 06:38:0380 Browser* browser = new Browser(
81 Browser::CreateParams(type, profile, chrome::HOST_DESKTOP_TYPE_NATIVE));
[email protected]686221c2012-11-08 07:30:1082 chrome::AddBlankTabAt(browser, -1, true);
[email protected]bd817c22011-02-09 08:16:4683 return browser;
84}
[email protected]a1feae52010-10-11 22:14:4585
[email protected]b35b26b32011-05-05 20:35:1486Browser* BrowserNavigatorTest::CreateEmptyBrowserForApp(Browser::Type type,
87 Profile* profile) {
[email protected]a4fe67012012-07-25 20:14:2988 Browser* browser = new Browser(
[email protected]da22aa62012-04-04 18:54:3589 Browser::CreateParams::CreateForApp(
[email protected]2b09ae552013-02-23 06:38:0390 Browser::TYPE_POPUP, "Test", gfx::Rect(), profile,
91 chrome::HOST_DESKTOP_TYPE_NATIVE));
[email protected]686221c2012-11-08 07:30:1092 chrome::AddBlankTabAt(browser, -1, true);
[email protected]b35b26b32011-05-05 20:35:1493 return browser;
94}
95
[email protected]e232c992012-12-06 12:43:2096WebContents* BrowserNavigatorTest::CreateWebContents() {
[email protected]54944cde2012-12-09 09:24:5997 content::WebContents::CreateParams create_params(browser()->profile());
[email protected]ed245db2012-12-18 08:00:4598 content::WebContents* base_web_contents =
[email protected]ee496952013-01-10 23:17:3399 browser()->tab_strip_model()->GetActiveWebContents();
[email protected]ed245db2012-12-18 08:00:45100 if (base_web_contents) {
101 create_params.initial_size =
102 base_web_contents->GetView()->GetContainerSize();
103 }
[email protected]54944cde2012-12-09 09:24:59104 return WebContents::Create(create_params);
[email protected]bd817c22011-02-09 08:16:46105}
[email protected]a1feae52010-10-11 22:14:45106
[email protected]bd817c22011-02-09 08:16:46107void BrowserNavigatorTest::RunSuppressTest(WindowOpenDisposition disposition) {
[email protected]ee496952013-01-10 23:17:33108 GURL old_url = browser()->tab_strip_model()->GetActiveWebContents()->GetURL();
[email protected]78e2edc2012-07-01 23:32:28109 chrome::NavigateParams p(MakeNavigateParams());
[email protected]bd817c22011-02-09 08:16:46110 p.disposition = disposition;
[email protected]78e2edc2012-07-01 23:32:28111 chrome::Navigate(&p);
[email protected]a1feae52010-10-11 22:14:45112
[email protected]bd817c22011-02-09 08:16:46113 // Nothing should have happened as a result of Navigate();
[email protected]ee496952013-01-10 23:17:33114 EXPECT_EQ(1, browser()->tab_strip_model()->count());
[email protected]0665ebe2013-02-13 09:53:19115 EXPECT_EQ(1u, chrome::GetTotalBrowserCount());
[email protected]ee496952013-01-10 23:17:33116 EXPECT_EQ(old_url,
117 browser()->tab_strip_model()->GetActiveWebContents()->GetURL());
[email protected]bd817c22011-02-09 08:16:46118}
[email protected]bb89e7482010-11-17 18:27:04119
[email protected]fc0ed302011-11-29 23:17:19120void BrowserNavigatorTest::RunUseNonIncognitoWindowTest(const GURL& url) {
121 Browser* incognito_browser = CreateIncognitoBrowser();
122
[email protected]0665ebe2013-02-13 09:53:19123 EXPECT_EQ(2u, chrome::GetTotalBrowserCount());
[email protected]ee496952013-01-10 23:17:33124 EXPECT_EQ(1, browser()->tab_strip_model()->count());
125 EXPECT_EQ(1, incognito_browser->tab_strip_model()->count());
[email protected]fc0ed302011-11-29 23:17:19126
127 // Navigate to the page.
[email protected]78e2edc2012-07-01 23:32:28128 chrome::NavigateParams p(MakeNavigateParams(incognito_browser));
[email protected]fc0ed302011-11-29 23:17:19129 p.disposition = SINGLETON_TAB;
130 p.url = url;
[email protected]78e2edc2012-07-01 23:32:28131 p.window_action = chrome::NavigateParams::SHOW_WINDOW;
132 chrome::Navigate(&p);
[email protected]fc0ed302011-11-29 23:17:19133
134 // This page should be opened in browser() window.
135 EXPECT_NE(incognito_browser, p.browser);
136 EXPECT_EQ(browser(), p.browser);
[email protected]ee496952013-01-10 23:17:33137 EXPECT_EQ(2, browser()->tab_strip_model()->count());
138 EXPECT_EQ(url,
139 browser()->tab_strip_model()->GetActiveWebContents()->GetURL());
[email protected]fc0ed302011-11-29 23:17:19140}
141
142void BrowserNavigatorTest::RunDoNothingIfIncognitoIsForcedTest(
143 const GURL& url) {
144 Browser* browser = CreateIncognitoBrowser();
145
146 // Set kIncognitoModeAvailability to FORCED.
147 PrefService* prefs1 = browser->profile()->GetPrefs();
148 prefs1->SetInteger(prefs::kIncognitoModeAvailability,
149 IncognitoModePrefs::FORCED);
150 PrefService* prefs2 = browser->profile()->GetOriginalProfile()->GetPrefs();
151 prefs2->SetInteger(prefs::kIncognitoModeAvailability,
152 IncognitoModePrefs::FORCED);
153
154 // Navigate to the page.
[email protected]78e2edc2012-07-01 23:32:28155 chrome::NavigateParams p(MakeNavigateParams(browser));
[email protected]fc0ed302011-11-29 23:17:19156 p.disposition = OFF_THE_RECORD;
157 p.url = url;
[email protected]78e2edc2012-07-01 23:32:28158 p.window_action = chrome::NavigateParams::SHOW_WINDOW;
159 chrome::Navigate(&p);
[email protected]fc0ed302011-11-29 23:17:19160
161 // The page should not be opened.
162 EXPECT_EQ(browser, p.browser);
[email protected]ee496952013-01-10 23:17:33163 EXPECT_EQ(1, browser->tab_strip_model()->count());
[email protected]fc0ed302011-11-29 23:17:19164 EXPECT_EQ(GURL(chrome::kAboutBlankURL),
[email protected]ee496952013-01-10 23:17:33165 browser->tab_strip_model()->GetActiveWebContents()->GetURL());
[email protected]fc0ed302011-11-29 23:17:19166}
167
[email protected]6c2381d2011-10-19 02:52:53168void BrowserNavigatorTest::Observe(
169 int type,
170 const content::NotificationSource& source,
171 const content::NotificationDetails& details) {
[email protected]432115822011-07-10 15:52:27172 switch (type) {
[email protected]d53a08c2012-07-18 20:35:30173 case content::NOTIFICATION_WEB_CONTENTS_RENDER_VIEW_HOST_CREATED: {
[email protected]bd817c22011-02-09 08:16:46174 ++this->created_tab_contents_count_;
175 break;
[email protected]fa7ebe02010-11-29 23:04:57176 }
[email protected]bd817c22011-02-09 08:16:46177 default:
178 break;
[email protected]fa7ebe02010-11-29 23:04:57179 }
[email protected]bd817c22011-02-09 08:16:46180}
[email protected]fa7ebe02010-11-29 23:04:57181
[email protected]ddddfda2011-07-14 23:19:39182
[email protected]bd817c22011-02-09 08:16:46183namespace {
[email protected]a1feae52010-10-11 22:14:45184
[email protected]a1feae52010-10-11 22:14:45185// This test verifies that when a navigation occurs within a tab, the tab count
186// of the Browser remains the same and the current tab bears the loaded URL.
187IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_CurrentTab) {
[email protected]ddddfda2011-07-14 23:19:39188 ui_test_utils::NavigateToURL(browser(), GetGoogleURL());
[email protected]ee496952013-01-10 23:17:33189 EXPECT_EQ(GetGoogleURL(),
190 browser()->tab_strip_model()->GetActiveWebContents()->GetURL());
[email protected]a1feae52010-10-11 22:14:45191 // We should have one window with one tab.
[email protected]0665ebe2013-02-13 09:53:19192 EXPECT_EQ(1u, chrome::GetTotalBrowserCount());
[email protected]ee496952013-01-10 23:17:33193 EXPECT_EQ(1, browser()->tab_strip_model()->count());
[email protected]a1feae52010-10-11 22:14:45194}
195
[email protected]bd817c22011-02-09 08:16:46196// This test verifies that a singleton tab is refocused if one is already opened
[email protected]19d9f3a2010-10-14 21:49:36197// in another or an existing window, or added if it is not.
198IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_SingletonTabExisting) {
[email protected]19d9f3a2010-10-14 21:49:36199 GURL singleton_url1("http://maps.google.com/");
[email protected]fa7ebe02010-11-29 23:04:57200
[email protected]e232c992012-12-06 12:43:20201 // Register for a notification if an additional WebContents was instantiated.
[email protected]bd817c22011-02-09 08:16:46202 // Opening a Singleton tab that is already opened should not be opening a new
[email protected]e232c992012-12-06 12:43:20203 // tab nor be creating a new WebContents object.
[email protected]6c2381d2011-10-19 02:52:53204 content::NotificationRegistrar registrar;
[email protected]fa7ebe02010-11-29 23:04:57205
206 // As the registrar object goes out of scope, this will get unregistered
[email protected]d53a08c2012-07-18 20:35:30207 registrar.Add(this,
208 content::NOTIFICATION_WEB_CONTENTS_RENDER_VIEW_HOST_CREATED,
[email protected]ad50def52011-10-19 23:17:07209 content::NotificationService::AllSources());
[email protected]fa7ebe02010-11-29 23:04:57210
[email protected]52877dbc62012-06-29 22:22:03211 chrome::AddSelectedTabWithURL(browser(), singleton_url1,
212 content::PAGE_TRANSITION_LINK);
213 chrome::AddSelectedTabWithURL(browser(), GetGoogleURL(),
214 content::PAGE_TRANSITION_LINK);
[email protected]19d9f3a2010-10-14 21:49:36215
216 // We should have one browser with 3 tabs, the 3rd selected.
[email protected]0665ebe2013-02-13 09:53:19217 EXPECT_EQ(1u, chrome::GetTotalBrowserCount());
[email protected]ee496952013-01-10 23:17:33218 EXPECT_EQ(2, browser()->tab_strip_model()->active_index());
[email protected]19d9f3a2010-10-14 21:49:36219
[email protected]fa7ebe02010-11-29 23:04:57220 unsigned int previous_tab_contents_count =
221 created_tab_contents_count_ = 0;
222
[email protected]19d9f3a2010-10-14 21:49:36223 // Navigate to singleton_url1.
[email protected]78e2edc2012-07-01 23:32:28224 chrome::NavigateParams p(MakeNavigateParams());
[email protected]19d9f3a2010-10-14 21:49:36225 p.disposition = SINGLETON_TAB;
226 p.url = singleton_url1;
[email protected]78e2edc2012-07-01 23:32:28227 chrome::Navigate(&p);
[email protected]19d9f3a2010-10-14 21:49:36228
229 // The middle tab should now be selected.
230 EXPECT_EQ(browser(), p.browser);
[email protected]ee496952013-01-10 23:17:33231 EXPECT_EQ(1, browser()->tab_strip_model()->active_index());
[email protected]fa7ebe02010-11-29 23:04:57232
233 // No tab contents should have been created
234 EXPECT_EQ(previous_tab_contents_count,
235 created_tab_contents_count_);
[email protected]19d9f3a2010-10-14 21:49:36236}
237
238IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
[email protected]578c6962011-08-24 22:06:40239 Disposition_SingletonTabRespectingRef) {
240 GURL singleton_ref_url1("http://maps.google.com/#a");
241 GURL singleton_ref_url2("http://maps.google.com/#b");
242 GURL singleton_ref_url3("http://maps.google.com/");
243
[email protected]52877dbc62012-06-29 22:22:03244 chrome::AddSelectedTabWithURL(browser(), singleton_ref_url1,
245 content::PAGE_TRANSITION_LINK);
[email protected]578c6962011-08-24 22:06:40246
247 // We should have one browser with 2 tabs, 2nd selected.
[email protected]0665ebe2013-02-13 09:53:19248 EXPECT_EQ(1u, chrome::GetTotalBrowserCount());
[email protected]ee496952013-01-10 23:17:33249 EXPECT_EQ(2, browser()->tab_strip_model()->count());
250 EXPECT_EQ(1, browser()->tab_strip_model()->active_index());
[email protected]578c6962011-08-24 22:06:40251
252 // Navigate to singleton_url2.
[email protected]78e2edc2012-07-01 23:32:28253 chrome::NavigateParams p(MakeNavigateParams());
[email protected]578c6962011-08-24 22:06:40254 p.disposition = SINGLETON_TAB;
255 p.url = singleton_ref_url2;
[email protected]78e2edc2012-07-01 23:32:28256 chrome::Navigate(&p);
[email protected]578c6962011-08-24 22:06:40257
258 // We should now have 2 tabs, the 2nd one selected.
259 EXPECT_EQ(browser(), p.browser);
[email protected]ee496952013-01-10 23:17:33260 EXPECT_EQ(2, browser()->tab_strip_model()->count());
261 EXPECT_EQ(1, browser()->tab_strip_model()->active_index());
[email protected]578c6962011-08-24 22:06:40262
263 // Navigate to singleton_url2, but with respect ref set.
264 p = MakeNavigateParams();
265 p.disposition = SINGLETON_TAB;
266 p.url = singleton_ref_url2;
[email protected]78e2edc2012-07-01 23:32:28267 p.ref_behavior = chrome::NavigateParams::RESPECT_REF;
268 chrome::Navigate(&p);
[email protected]578c6962011-08-24 22:06:40269
270 // We should now have 3 tabs, the 3th one selected.
271 EXPECT_EQ(browser(), p.browser);
[email protected]ee496952013-01-10 23:17:33272 EXPECT_EQ(3, browser()->tab_strip_model()->count());
273 EXPECT_EQ(2, browser()->tab_strip_model()->active_index());
[email protected]578c6962011-08-24 22:06:40274
275 // Navigate to singleton_url3.
276 p = MakeNavigateParams();
277 p.disposition = SINGLETON_TAB;
278 p.url = singleton_ref_url3;
[email protected]78e2edc2012-07-01 23:32:28279 p.ref_behavior = chrome::NavigateParams::RESPECT_REF;
280 chrome::Navigate(&p);
[email protected]578c6962011-08-24 22:06:40281
282 // We should now have 4 tabs, the 4th one selected.
283 EXPECT_EQ(browser(), p.browser);
[email protected]ee496952013-01-10 23:17:33284 EXPECT_EQ(4, browser()->tab_strip_model()->count());
285 EXPECT_EQ(3, browser()->tab_strip_model()->active_index());
[email protected]578c6962011-08-24 22:06:40286}
287
288IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
[email protected]19d9f3a2010-10-14 21:49:36289 Disposition_SingletonTabNoneExisting) {
[email protected]19d9f3a2010-10-14 21:49:36290 GURL singleton_url1("http://maps.google.com/");
291
[email protected]bd817c22011-02-09 08:16:46292 // We should have one browser with 1 tab.
[email protected]0665ebe2013-02-13 09:53:19293 EXPECT_EQ(1u, chrome::GetTotalBrowserCount());
[email protected]ee496952013-01-10 23:17:33294 EXPECT_EQ(0, browser()->tab_strip_model()->active_index());
[email protected]19d9f3a2010-10-14 21:49:36295
296 // Navigate to singleton_url1.
[email protected]78e2edc2012-07-01 23:32:28297 chrome::NavigateParams p(MakeNavigateParams());
[email protected]19d9f3a2010-10-14 21:49:36298 p.disposition = SINGLETON_TAB;
299 p.url = singleton_url1;
[email protected]78e2edc2012-07-01 23:32:28300 chrome::Navigate(&p);
[email protected]19d9f3a2010-10-14 21:49:36301
302 // We should now have 2 tabs, the 2nd one selected.
303 EXPECT_EQ(browser(), p.browser);
[email protected]ee496952013-01-10 23:17:33304 EXPECT_EQ(2, browser()->tab_strip_model()->count());
305 EXPECT_EQ(1, browser()->tab_strip_model()->active_index());
[email protected]a1feae52010-10-11 22:14:45306}
307
308// This test verifies that when a navigation results in a foreground tab, the
309// tab count of the Browser increases and the selected tab shifts to the new
310// foreground tab.
311IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_NewForegroundTab) {
[email protected]ee496952013-01-10 23:17:33312 WebContents* old_contents =
313 browser()->tab_strip_model()->GetActiveWebContents();
[email protected]78e2edc2012-07-01 23:32:28314 chrome::NavigateParams p(MakeNavigateParams());
[email protected]a1feae52010-10-11 22:14:45315 p.disposition = NEW_FOREGROUND_TAB;
[email protected]78e2edc2012-07-01 23:32:28316 chrome::Navigate(&p);
[email protected]ee496952013-01-10 23:17:33317 EXPECT_NE(old_contents,
318 browser()->tab_strip_model()->GetActiveWebContents());
[email protected]e232c992012-12-06 12:43:20319 EXPECT_EQ(browser()->tab_strip_model()->GetActiveWebContents(),
[email protected]59253a652012-11-20 00:17:26320 p.target_contents);
[email protected]ee496952013-01-10 23:17:33321 EXPECT_EQ(2, browser()->tab_strip_model()->count());
[email protected]a1feae52010-10-11 22:14:45322}
323
324// This test verifies that when a navigation results in a background tab, the
325// tab count of the Browser increases but the selected tab remains the same.
326IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_NewBackgroundTab) {
[email protected]ee496952013-01-10 23:17:33327 WebContents* old_contents =
328 browser()->tab_strip_model()->GetActiveWebContents();
[email protected]78e2edc2012-07-01 23:32:28329 chrome::NavigateParams p(MakeNavigateParams());
[email protected]a1feae52010-10-11 22:14:45330 p.disposition = NEW_BACKGROUND_TAB;
[email protected]78e2edc2012-07-01 23:32:28331 chrome::Navigate(&p);
[email protected]ee496952013-01-10 23:17:33332 WebContents* new_contents =
333 browser()->tab_strip_model()->GetActiveWebContents();
[email protected]a1feae52010-10-11 22:14:45334 // The selected tab should have remained unchanged, since the new tab was
335 // opened in the background.
336 EXPECT_EQ(old_contents, new_contents);
[email protected]ee496952013-01-10 23:17:33337 EXPECT_EQ(2, browser()->tab_strip_model()->count());
[email protected]a1feae52010-10-11 22:14:45338}
339
340// This test verifies that when a navigation requiring a new foreground tab
341// occurs in a Browser that cannot host multiple tabs, the new foreground tab
342// is created in an existing compatible Browser.
343IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
344 Disposition_IncompatibleWindow_Existing) {
345 // Open a foreground tab in a window that cannot open popups when there is an
346 // existing compatible window somewhere else that they can be opened within.
347 Browser* popup = CreateEmptyBrowserForType(Browser::TYPE_POPUP,
348 browser()->profile());
[email protected]78e2edc2012-07-01 23:32:28349 chrome::NavigateParams p(MakeNavigateParams(popup));
[email protected]a1feae52010-10-11 22:14:45350 p.disposition = NEW_FOREGROUND_TAB;
[email protected]78e2edc2012-07-01 23:32:28351 chrome::Navigate(&p);
[email protected]a1feae52010-10-11 22:14:45352
353 // Navigate() should have opened the tab in a different browser since the
354 // one we supplied didn't support additional tabs.
355 EXPECT_NE(popup, p.browser);
356
357 // Since browser() is an existing compatible tabbed browser, it should have
358 // opened the tab there.
359 EXPECT_EQ(browser(), p.browser);
360
361 // We should be left with 2 windows, the popup with one tab and the browser()
362 // provided by the framework with two.
[email protected]0665ebe2013-02-13 09:53:19363 EXPECT_EQ(2u, chrome::GetTotalBrowserCount());
[email protected]ee496952013-01-10 23:17:33364 EXPECT_EQ(1, popup->tab_strip_model()->count());
365 EXPECT_EQ(2, browser()->tab_strip_model()->count());
[email protected]a1feae52010-10-11 22:14:45366}
367
368// This test verifies that when a navigation requiring a new foreground tab
369// occurs in a Browser that cannot host multiple tabs and no compatible Browser
370// that can is open, a compatible Browser is created.
371IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
372 Disposition_IncompatibleWindow_NoExisting) {
373 // We want to simulate not being able to find an existing window compatible
374 // with our non-tabbed browser window so Navigate() is forced to create a
375 // new compatible window. Because browser() supplied by the in-process
376 // browser testing framework is compatible with browser()->profile(), we
377 // need a different profile, and creating a popup window with an incognito
378 // profile is a quick and dirty way of achieving this.
379 Browser* popup = CreateEmptyBrowserForType(
[email protected]b35b26b32011-05-05 20:35:14380 Browser::TYPE_POPUP,
381 browser()->profile()->GetOffTheRecordProfile());
[email protected]78e2edc2012-07-01 23:32:28382 chrome::NavigateParams p(MakeNavigateParams(popup));
[email protected]a1feae52010-10-11 22:14:45383 p.disposition = NEW_FOREGROUND_TAB;
[email protected]78e2edc2012-07-01 23:32:28384 chrome::Navigate(&p);
[email protected]a1feae52010-10-11 22:14:45385
386 // Navigate() should have opened the tab in a different browser since the
387 // one we supplied didn't support additional tabs.
388 EXPECT_NE(popup, p.browser);
389
390 // This time, browser() is _not_ compatible with popup since it is not an
391 // incognito window.
392 EXPECT_NE(browser(), p.browser);
393
394 // We should have three windows, each with one tab:
395 // 1. the browser() provided by the framework (unchanged in this test)
396 // 2. the incognito popup we created originally
397 // 3. the new incognito tabbed browser that was created by Navigate().
[email protected]0665ebe2013-02-13 09:53:19398 EXPECT_EQ(3u, chrome::GetTotalBrowserCount());
[email protected]ee496952013-01-10 23:17:33399 EXPECT_EQ(1, browser()->tab_strip_model()->count());
400 EXPECT_EQ(1, popup->tab_strip_model()->count());
401 EXPECT_EQ(1, p.browser->tab_strip_model()->count());
[email protected]b35b26b32011-05-05 20:35:14402 EXPECT_TRUE(p.browser->is_type_tabbed());
[email protected]a1feae52010-10-11 22:14:45403}
404
405// This test verifies that navigating with WindowOpenDisposition = NEW_POPUP
406// from a normal Browser results in a new Browser with TYPE_POPUP.
407IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_NewPopup) {
[email protected]78e2edc2012-07-01 23:32:28408 chrome::NavigateParams p(MakeNavigateParams());
[email protected]a1feae52010-10-11 22:14:45409 p.disposition = NEW_POPUP;
[email protected]588300d2011-04-28 21:06:35410 p.window_bounds = gfx::Rect(0, 0, 200, 200);
[email protected]7d329992011-04-15 18:20:02411 // Wait for new popup to to load and gain focus.
[email protected]ddddfda2011-07-14 23:19:39412 ui_test_utils::NavigateToURL(&p);
[email protected]a1feae52010-10-11 22:14:45413
[email protected]7d329992011-04-15 18:20:02414 // Navigate() should have opened a new, focused popup window.
[email protected]a1feae52010-10-11 22:14:45415 EXPECT_NE(browser(), p.browser);
[email protected]9db263a2011-04-15 20:53:47416#if 0
417 // TODO(stevenjb): Enable this test. See: crbug.com/79493
[email protected]7d329992011-04-15 18:20:02418 EXPECT_TRUE(p.browser->window()->IsActive());
419#endif
[email protected]b35b26b32011-05-05 20:35:14420 EXPECT_TRUE(p.browser->is_type_popup());
421 EXPECT_FALSE(p.browser->is_app());
[email protected]a1feae52010-10-11 22:14:45422
423 // We should have two windows, the browser() provided by the framework and the
424 // new popup window.
[email protected]0665ebe2013-02-13 09:53:19425 EXPECT_EQ(2u, chrome::GetTotalBrowserCount());
[email protected]ee496952013-01-10 23:17:33426 EXPECT_EQ(1, browser()->tab_strip_model()->count());
427 EXPECT_EQ(1, p.browser->tab_strip_model()->count());
[email protected]a1feae52010-10-11 22:14:45428}
429
430// This test verifies that navigating with WindowOpenDisposition = NEW_POPUP
[email protected]f112b0f2011-05-26 01:53:52431// from a normal Browser results in a new Browser with is_app() true.
432IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_NewPopup_ExtensionId) {
[email protected]78e2edc2012-07-01 23:32:28433 chrome::NavigateParams p(MakeNavigateParams());
[email protected]f112b0f2011-05-26 01:53:52434 p.disposition = NEW_POPUP;
435 p.extension_app_id = "extensionappid";
436 p.window_bounds = gfx::Rect(0, 0, 200, 200);
[email protected]f112b0f2011-05-26 01:53:52437 // Wait for new popup to to load and gain focus.
[email protected]ddddfda2011-07-14 23:19:39438 ui_test_utils::NavigateToURL(&p);
[email protected]f112b0f2011-05-26 01:53:52439
440 // Navigate() should have opened a new, focused popup window.
441 EXPECT_NE(browser(), p.browser);
442 EXPECT_TRUE(p.browser->is_type_popup());
443 EXPECT_TRUE(p.browser->is_app());
444
445 // We should have two windows, the browser() provided by the framework and the
446 // new popup window.
[email protected]0665ebe2013-02-13 09:53:19447 EXPECT_EQ(2u, chrome::GetTotalBrowserCount());
[email protected]ee496952013-01-10 23:17:33448 EXPECT_EQ(1, browser()->tab_strip_model()->count());
449 EXPECT_EQ(1, p.browser->tab_strip_model()->count());
[email protected]f112b0f2011-05-26 01:53:52450}
451
452// This test verifies that navigating with WindowOpenDisposition = NEW_POPUP
[email protected]300d1e52011-01-19 23:57:57453// from a normal popup results in a new Browser with TYPE_POPUP.
454IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_NewPopupFromPopup) {
455 // Open a popup.
[email protected]78e2edc2012-07-01 23:32:28456 chrome::NavigateParams p1(MakeNavigateParams());
[email protected]300d1e52011-01-19 23:57:57457 p1.disposition = NEW_POPUP;
[email protected]588300d2011-04-28 21:06:35458 p1.window_bounds = gfx::Rect(0, 0, 200, 200);
[email protected]78e2edc2012-07-01 23:32:28459 chrome::Navigate(&p1);
[email protected]300d1e52011-01-19 23:57:57460 // Open another popup.
[email protected]78e2edc2012-07-01 23:32:28461 chrome::NavigateParams p2(MakeNavigateParams(p1.browser));
[email protected]300d1e52011-01-19 23:57:57462 p2.disposition = NEW_POPUP;
[email protected]588300d2011-04-28 21:06:35463 p2.window_bounds = gfx::Rect(0, 0, 200, 200);
[email protected]78e2edc2012-07-01 23:32:28464 chrome::Navigate(&p2);
[email protected]300d1e52011-01-19 23:57:57465
466 // Navigate() should have opened a new normal popup window.
467 EXPECT_NE(p1.browser, p2.browser);
[email protected]b35b26b32011-05-05 20:35:14468 EXPECT_TRUE(p2.browser->is_type_popup());
469 EXPECT_FALSE(p2.browser->is_app());
[email protected]300d1e52011-01-19 23:57:57470
471 // We should have three windows, the browser() provided by the framework,
472 // the first popup window, and the second popup window.
[email protected]0665ebe2013-02-13 09:53:19473 EXPECT_EQ(3u, chrome::GetTotalBrowserCount());
[email protected]ee496952013-01-10 23:17:33474 EXPECT_EQ(1, browser()->tab_strip_model()->count());
475 EXPECT_EQ(1, p1.browser->tab_strip_model()->count());
476 EXPECT_EQ(1, p2.browser->tab_strip_model()->count());
[email protected]300d1e52011-01-19 23:57:57477}
478
479// This test verifies that navigating with WindowOpenDisposition = NEW_POPUP
[email protected]a1feae52010-10-11 22:14:45480// from an app frame results in a new Browser with TYPE_APP_POPUP.
481IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
482 Disposition_NewPopupFromAppWindow) {
[email protected]b35b26b32011-05-05 20:35:14483 Browser* app_browser = CreateEmptyBrowserForApp(Browser::TYPE_TABBED,
484 browser()->profile());
[email protected]78e2edc2012-07-01 23:32:28485 chrome::NavigateParams p(MakeNavigateParams(app_browser));
[email protected]a1feae52010-10-11 22:14:45486 p.disposition = NEW_POPUP;
[email protected]588300d2011-04-28 21:06:35487 p.window_bounds = gfx::Rect(0, 0, 200, 200);
[email protected]78e2edc2012-07-01 23:32:28488 chrome::Navigate(&p);
[email protected]a1feae52010-10-11 22:14:45489
490 // Navigate() should have opened a new popup app window.
491 EXPECT_NE(app_browser, p.browser);
492 EXPECT_NE(browser(), p.browser);
[email protected]b35b26b32011-05-05 20:35:14493 EXPECT_TRUE(p.browser->is_type_popup());
494 EXPECT_TRUE(p.browser->is_app());
[email protected]a1feae52010-10-11 22:14:45495
496 // We should now have three windows, the app window, the app popup it created,
497 // and the original browser() provided by the framework.
[email protected]0665ebe2013-02-13 09:53:19498 EXPECT_EQ(3u, chrome::GetTotalBrowserCount());
[email protected]ee496952013-01-10 23:17:33499 EXPECT_EQ(1, browser()->tab_strip_model()->count());
500 EXPECT_EQ(1, app_browser->tab_strip_model()->count());
501 EXPECT_EQ(1, p.browser->tab_strip_model()->count());
[email protected]a1feae52010-10-11 22:14:45502}
503
504// This test verifies that navigating with WindowOpenDisposition = NEW_POPUP
[email protected]300d1e52011-01-19 23:57:57505// from an app popup results in a new Browser also of TYPE_APP_POPUP.
506IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
507 Disposition_NewPopupFromAppPopup) {
[email protected]b35b26b32011-05-05 20:35:14508 Browser* app_browser = CreateEmptyBrowserForApp(Browser::TYPE_TABBED,
509 browser()->profile());
[email protected]300d1e52011-01-19 23:57:57510 // Open an app popup.
[email protected]78e2edc2012-07-01 23:32:28511 chrome::NavigateParams p1(MakeNavigateParams(app_browser));
[email protected]300d1e52011-01-19 23:57:57512 p1.disposition = NEW_POPUP;
[email protected]588300d2011-04-28 21:06:35513 p1.window_bounds = gfx::Rect(0, 0, 200, 200);
[email protected]78e2edc2012-07-01 23:32:28514 chrome::Navigate(&p1);
[email protected]300d1e52011-01-19 23:57:57515 // Now open another app popup.
[email protected]78e2edc2012-07-01 23:32:28516 chrome::NavigateParams p2(MakeNavigateParams(p1.browser));
[email protected]300d1e52011-01-19 23:57:57517 p2.disposition = NEW_POPUP;
[email protected]588300d2011-04-28 21:06:35518 p2.window_bounds = gfx::Rect(0, 0, 200, 200);
[email protected]78e2edc2012-07-01 23:32:28519 chrome::Navigate(&p2);
[email protected]300d1e52011-01-19 23:57:57520
521 // Navigate() should have opened a new popup app window.
522 EXPECT_NE(browser(), p1.browser);
523 EXPECT_NE(p1.browser, p2.browser);
[email protected]b35b26b32011-05-05 20:35:14524 EXPECT_TRUE(p2.browser->is_type_popup());
525 EXPECT_TRUE(p2.browser->is_app());
[email protected]300d1e52011-01-19 23:57:57526
527 // We should now have four windows, the app window, the first app popup,
528 // the second app popup, and the original browser() provided by the framework.
[email protected]0665ebe2013-02-13 09:53:19529 EXPECT_EQ(4u, chrome::GetTotalBrowserCount());
[email protected]ee496952013-01-10 23:17:33530 EXPECT_EQ(1, browser()->tab_strip_model()->count());
531 EXPECT_EQ(1, app_browser->tab_strip_model()->count());
532 EXPECT_EQ(1, p1.browser->tab_strip_model()->count());
533 EXPECT_EQ(1, p2.browser->tab_strip_model()->count());
[email protected]300d1e52011-01-19 23:57:57534}
535
536// This test verifies that navigating with WindowOpenDisposition = NEW_POPUP
[email protected]a1feae52010-10-11 22:14:45537// from an extension app tab results in a new Browser with TYPE_APP_POPUP.
538IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
539 Disposition_NewPopupFromExtensionApp) {
540 // TODO(beng): TBD.
541}
542
[email protected]7d329992011-04-15 18:20:02543// This test verifies that navigating with window_action = SHOW_WINDOW_INACTIVE
544// does not focus a new new popup window.
545IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_NewPopupUnfocused) {
[email protected]78e2edc2012-07-01 23:32:28546 chrome::NavigateParams p(MakeNavigateParams());
[email protected]7d329992011-04-15 18:20:02547 p.disposition = NEW_POPUP;
[email protected]588300d2011-04-28 21:06:35548 p.window_bounds = gfx::Rect(0, 0, 200, 200);
[email protected]78e2edc2012-07-01 23:32:28549 p.window_action = chrome::NavigateParams::SHOW_WINDOW_INACTIVE;
[email protected]7d329992011-04-15 18:20:02550 // Wait for new popup to load (and gain focus if the test fails).
[email protected]ddddfda2011-07-14 23:19:39551 ui_test_utils::NavigateToURL(&p);
[email protected]7d329992011-04-15 18:20:02552
553 // Navigate() should have opened a new, unfocused, popup window.
554 EXPECT_NE(browser(), p.browser);
555 EXPECT_EQ(Browser::TYPE_POPUP, p.browser->type());
[email protected]9db263a2011-04-15 20:53:47556#if 0
557// TODO(stevenjb): Enable this test. See: crbug.com/79493
[email protected]7d329992011-04-15 18:20:02558 EXPECT_FALSE(p.browser->window()->IsActive());
[email protected]7d329992011-04-15 18:20:02559#endif
[email protected]9db263a2011-04-15 20:53:47560}
[email protected]7d329992011-04-15 18:20:02561
[email protected]a1feae52010-10-11 22:14:45562// This test verifies that navigating with WindowOpenDisposition = NEW_WINDOW
563// always opens a new window.
564IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_NewWindow) {
[email protected]78e2edc2012-07-01 23:32:28565 chrome::NavigateParams p(MakeNavigateParams());
[email protected]a1feae52010-10-11 22:14:45566 p.disposition = NEW_WINDOW;
[email protected]78e2edc2012-07-01 23:32:28567 chrome::Navigate(&p);
[email protected]a1feae52010-10-11 22:14:45568
569 // Navigate() should have opened a new toplevel window.
570 EXPECT_NE(browser(), p.browser);
[email protected]b35b26b32011-05-05 20:35:14571 EXPECT_TRUE(p.browser->is_type_tabbed());
[email protected]a1feae52010-10-11 22:14:45572
573 // We should now have two windows, the browser() provided by the framework and
574 // the new normal window.
[email protected]0665ebe2013-02-13 09:53:19575 EXPECT_EQ(2u, chrome::GetTotalBrowserCount());
[email protected]ee496952013-01-10 23:17:33576 EXPECT_EQ(1, browser()->tab_strip_model()->count());
577 EXPECT_EQ(1, p.browser->tab_strip_model()->count());
[email protected]a1feae52010-10-11 22:14:45578}
579
580// This test verifies that navigating with WindowOpenDisposition = INCOGNITO
581// opens a new incognito window if no existing incognito window is present.
582IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_Incognito) {
[email protected]78e2edc2012-07-01 23:32:28583 chrome::NavigateParams p(MakeNavigateParams());
[email protected]a1feae52010-10-11 22:14:45584 p.disposition = OFF_THE_RECORD;
[email protected]78e2edc2012-07-01 23:32:28585 chrome::Navigate(&p);
[email protected]a1feae52010-10-11 22:14:45586
587 // Navigate() should have opened a new toplevel incognito window.
588 EXPECT_NE(browser(), p.browser);
589 EXPECT_EQ(browser()->profile()->GetOffTheRecordProfile(),
590 p.browser->profile());
591
[email protected]d7ff3592010-11-30 21:50:46592 // |source_contents| should be set to NULL because the profile for the new
593 // page is different from the originating page.
594 EXPECT_EQ(NULL, p.source_contents);
595
[email protected]a1feae52010-10-11 22:14:45596 // We should now have two windows, the browser() provided by the framework and
597 // the new incognito window.
[email protected]0665ebe2013-02-13 09:53:19598 EXPECT_EQ(2u, chrome::GetTotalBrowserCount());
[email protected]ee496952013-01-10 23:17:33599 EXPECT_EQ(1, browser()->tab_strip_model()->count());
600 EXPECT_EQ(1, p.browser->tab_strip_model()->count());
[email protected]a1feae52010-10-11 22:14:45601}
602
603// This test verifies that navigating with WindowOpenDisposition = INCOGNITO
604// reuses an existing incognito window when possible.
605IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_IncognitoRefocus) {
606 Browser* incognito_browser =
[email protected]b35b26b32011-05-05 20:35:14607 CreateEmptyBrowserForType(Browser::TYPE_TABBED,
[email protected]a1feae52010-10-11 22:14:45608 browser()->profile()->GetOffTheRecordProfile());
[email protected]78e2edc2012-07-01 23:32:28609 chrome::NavigateParams p(MakeNavigateParams());
[email protected]a1feae52010-10-11 22:14:45610 p.disposition = OFF_THE_RECORD;
[email protected]78e2edc2012-07-01 23:32:28611 chrome::Navigate(&p);
[email protected]a1feae52010-10-11 22:14:45612
613 // Navigate() should have opened a new tab in the existing incognito window.
614 EXPECT_NE(browser(), p.browser);
615 EXPECT_EQ(p.browser, incognito_browser);
616
617 // We should now have two windows, the browser() provided by the framework and
618 // the incognito window we opened earlier.
[email protected]0665ebe2013-02-13 09:53:19619 EXPECT_EQ(2u, chrome::GetTotalBrowserCount());
[email protected]ee496952013-01-10 23:17:33620 EXPECT_EQ(1, browser()->tab_strip_model()->count());
621 EXPECT_EQ(2, incognito_browser->tab_strip_model()->count());
[email protected]a1feae52010-10-11 22:14:45622}
623
624// This test verifies that no navigation action occurs when
625// WindowOpenDisposition = SUPPRESS_OPEN.
626IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_SuppressOpen) {
627 RunSuppressTest(SUPPRESS_OPEN);
628}
629
630// This test verifies that no navigation action occurs when
631// WindowOpenDisposition = SAVE_TO_DISK.
632IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_SaveToDisk) {
633 RunSuppressTest(SAVE_TO_DISK);
634}
635
636// This test verifies that no navigation action occurs when
637// WindowOpenDisposition = IGNORE_ACTION.
638IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_IgnoreAction) {
639 RunSuppressTest(IGNORE_ACTION);
640}
641
[email protected]e232c992012-12-06 12:43:20642// This tests adding a foreground tab with a predefined WebContents.
[email protected]a1feae52010-10-11 22:14:45643IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, TargetContents_ForegroundTab) {
[email protected]78e2edc2012-07-01 23:32:28644 chrome::NavigateParams p(MakeNavigateParams());
[email protected]a1feae52010-10-11 22:14:45645 p.disposition = NEW_FOREGROUND_TAB;
[email protected]e232c992012-12-06 12:43:20646 p.target_contents = CreateWebContents();
[email protected]78e2edc2012-07-01 23:32:28647 chrome::Navigate(&p);
[email protected]a1feae52010-10-11 22:14:45648
649 // Navigate() should have opened the contents in a new foreground in the
650 // current Browser.
651 EXPECT_EQ(browser(), p.browser);
[email protected]e232c992012-12-06 12:43:20652 EXPECT_EQ(browser()->tab_strip_model()->GetActiveWebContents(),
[email protected]59253a652012-11-20 00:17:26653 p.target_contents);
[email protected]a1feae52010-10-11 22:14:45654
655 // We should have one window, with two tabs.
[email protected]0665ebe2013-02-13 09:53:19656 EXPECT_EQ(1u, chrome::GetTotalBrowserCount());
[email protected]ee496952013-01-10 23:17:33657 EXPECT_EQ(2, browser()->tab_strip_model()->count());
[email protected]a1feae52010-10-11 22:14:45658}
659
660#if defined(OS_WIN)
[email protected]e232c992012-12-06 12:43:20661// This tests adding a popup with a predefined WebContents.
[email protected]76edb672011-03-04 21:48:39662IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, DISABLED_TargetContents_Popup) {
[email protected]78e2edc2012-07-01 23:32:28663 chrome::NavigateParams p(MakeNavigateParams());
[email protected]a1feae52010-10-11 22:14:45664 p.disposition = NEW_POPUP;
[email protected]e232c992012-12-06 12:43:20665 p.target_contents = CreateWebContents();
[email protected]a1feae52010-10-11 22:14:45666 p.window_bounds = gfx::Rect(10, 10, 500, 500);
[email protected]78e2edc2012-07-01 23:32:28667 chrome::Navigate(&p);
[email protected]a1feae52010-10-11 22:14:45668
669 // Navigate() should have opened a new popup window.
670 EXPECT_NE(browser(), p.browser);
[email protected]b35b26b32011-05-05 20:35:14671 EXPECT_TRUE(p.browser->is_type_popup());
672 EXPECT_FALSE(p.browser->is_app());
[email protected]a1feae52010-10-11 22:14:45673
674 // The web platform is weird. The window bounds specified in
675 // |p.window_bounds| are used as follows:
676 // - the origin is used to position the window
[email protected]e232c992012-12-06 12:43:20677 // - the size is used to size the WebContents of the window.
[email protected]a1feae52010-10-11 22:14:45678 // As such the position of the resulting window will always match
679 // p.window_bounds.origin(), but its size will not. We need to match
680 // the size against the selected tab's view's container size.
681 // Only Windows positions the window according to |p.window_bounds.origin()| -
682 // on Mac the window is offset from the opener and on Linux it always opens
683 // at 0,0.
684 EXPECT_EQ(p.window_bounds.origin(),
685 p.browser->window()->GetRestoredBounds().origin());
686 // All platforms should respect size however provided width > 400 (Mac has a
687 // minimum window width of 400).
688 EXPECT_EQ(p.window_bounds.size(),
[email protected]e232c992012-12-06 12:43:20689 p.target_contents->GetView()->GetContainerSize());
[email protected]a1feae52010-10-11 22:14:45690
691 // We should have two windows, the new popup and the browser() provided by the
692 // framework.
[email protected]0665ebe2013-02-13 09:53:19693 EXPECT_EQ(2u, chrome::GetTotalBrowserCount());
[email protected]ee496952013-01-10 23:17:33694 EXPECT_EQ(1, browser()->tab_strip_model()->count());
695 EXPECT_EQ(1, p.browser->tab_strip_model()->count());
[email protected]a1feae52010-10-11 22:14:45696}
697#endif
698
699// This tests adding a tab at a specific index.
700IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Tabstrip_InsertAtIndex) {
701 // This is not meant to be a comprehensive test of whether or not the tab
702 // implementation of the browser observes the insertion index. That is
703 // covered by the unit tests for TabStripModel. This merely verifies that
704 // insertion index preference is reflected in common cases.
[email protected]78e2edc2012-07-01 23:32:28705 chrome::NavigateParams p(MakeNavigateParams());
[email protected]a1feae52010-10-11 22:14:45706 p.disposition = NEW_FOREGROUND_TAB;
707 p.tabstrip_index = 0;
708 p.tabstrip_add_types = TabStripModel::ADD_FORCE_INDEX;
[email protected]78e2edc2012-07-01 23:32:28709 chrome::Navigate(&p);
[email protected]a1feae52010-10-11 22:14:45710
711 // Navigate() should have inserted a new tab at slot 0 in the tabstrip.
712 EXPECT_EQ(browser(), p.browser);
[email protected]e232c992012-12-06 12:43:20713 EXPECT_EQ(0, browser()->tab_strip_model()->GetIndexOfWebContents(
714 static_cast<const WebContents*>(p.target_contents)));
[email protected]a1feae52010-10-11 22:14:45715
716 // We should have one window - the browser() provided by the framework.
[email protected]0665ebe2013-02-13 09:53:19717 EXPECT_EQ(1u, chrome::GetTotalBrowserCount());
[email protected]ee496952013-01-10 23:17:33718 EXPECT_EQ(2, browser()->tab_strip_model()->count());
[email protected]a1feae52010-10-11 22:14:45719}
720
[email protected]bb89e7482010-11-17 18:27:04721// This test verifies that constructing params with disposition = SINGLETON_TAB
[email protected]fee320542011-03-02 01:30:49722// and IGNORE_AND_NAVIGATE opens a new tab navigated to the specified URL if
[email protected]67ed83e2011-01-07 22:54:00723// no previous tab with that URL (minus the path) exists.
[email protected]bb89e7482010-11-17 18:27:04724IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
725 Disposition_SingletonTabNew_IgnorePath) {
[email protected]52877dbc62012-06-29 22:22:03726 chrome::AddSelectedTabWithURL(browser(), GetGoogleURL(),
727 content::PAGE_TRANSITION_LINK);
[email protected]bb89e7482010-11-17 18:27:04728
729 // We should have one browser with 2 tabs, the 2nd selected.
[email protected]0665ebe2013-02-13 09:53:19730 EXPECT_EQ(1u, chrome::GetTotalBrowserCount());
[email protected]ee496952013-01-10 23:17:33731 EXPECT_EQ(2, browser()->tab_strip_model()->count());
732 EXPECT_EQ(1, browser()->tab_strip_model()->active_index());
[email protected]bb89e7482010-11-17 18:27:04733
734 // Navigate to a new singleton tab with a sub-page.
[email protected]78e2edc2012-07-01 23:32:28735 chrome::NavigateParams p(MakeNavigateParams());
[email protected]bb89e7482010-11-17 18:27:04736 p.disposition = SINGLETON_TAB;
[email protected]a048ad22012-03-23 04:26:56737 p.url = GetContentSettingsURL();
[email protected]78e2edc2012-07-01 23:32:28738 p.window_action = chrome::NavigateParams::SHOW_WINDOW;
739 p.path_behavior = chrome::NavigateParams::IGNORE_AND_NAVIGATE;
740 chrome::Navigate(&p);
[email protected]bb89e7482010-11-17 18:27:04741
742 // The last tab should now be selected and navigated to the sub-page of the
743 // URL.
744 EXPECT_EQ(browser(), p.browser);
[email protected]ee496952013-01-10 23:17:33745 EXPECT_EQ(3, browser()->tab_strip_model()->count());
746 EXPECT_EQ(2, browser()->tab_strip_model()->active_index());
[email protected]a048ad22012-03-23 04:26:56747 EXPECT_EQ(GetContentSettingsURL(),
[email protected]ee496952013-01-10 23:17:33748 ShortenUberURL(browser()->tab_strip_model()->
749 GetActiveWebContents()->GetURL()));
[email protected]bb89e7482010-11-17 18:27:04750}
751
752// This test verifies that constructing params with disposition = SINGLETON_TAB
[email protected]fee320542011-03-02 01:30:49753// and IGNORE_AND_NAVIGATE opens an existing tab with the matching URL (minus
[email protected]bb89e7482010-11-17 18:27:04754// the path) which is navigated to the specified URL.
755IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
756 Disposition_SingletonTabExisting_IgnorePath) {
[email protected]ddddfda2011-07-14 23:19:39757 GURL singleton_url1(GetSettingsURL());
[email protected]52877dbc62012-06-29 22:22:03758 chrome::AddSelectedTabWithURL(browser(), singleton_url1,
759 content::PAGE_TRANSITION_LINK);
760 chrome::AddSelectedTabWithURL(browser(), GetGoogleURL(),
761 content::PAGE_TRANSITION_LINK);
[email protected]bb89e7482010-11-17 18:27:04762
763 // We should have one browser with 3 tabs, the 3rd selected.
[email protected]0665ebe2013-02-13 09:53:19764 EXPECT_EQ(1u, chrome::GetTotalBrowserCount());
[email protected]ee496952013-01-10 23:17:33765 EXPECT_EQ(3, browser()->tab_strip_model()->count());
766 EXPECT_EQ(2, browser()->tab_strip_model()->active_index());
[email protected]bb89e7482010-11-17 18:27:04767
768 // Navigate to singleton_url1.
[email protected]78e2edc2012-07-01 23:32:28769 chrome::NavigateParams p(MakeNavigateParams());
[email protected]bb89e7482010-11-17 18:27:04770 p.disposition = SINGLETON_TAB;
[email protected]a048ad22012-03-23 04:26:56771 p.url = GetContentSettingsURL();
[email protected]78e2edc2012-07-01 23:32:28772 p.window_action = chrome::NavigateParams::SHOW_WINDOW;
773 p.path_behavior = chrome::NavigateParams::IGNORE_AND_NAVIGATE;
774 chrome::Navigate(&p);
[email protected]bb89e7482010-11-17 18:27:04775
776 // The middle tab should now be selected and navigated to the sub-page of the
777 // URL.
778 EXPECT_EQ(browser(), p.browser);
[email protected]ee496952013-01-10 23:17:33779 EXPECT_EQ(3, browser()->tab_strip_model()->count());
780 EXPECT_EQ(1, browser()->tab_strip_model()->active_index());
[email protected]a048ad22012-03-23 04:26:56781 EXPECT_EQ(GetContentSettingsURL(),
[email protected]ee496952013-01-10 23:17:33782 ShortenUberURL(browser()->tab_strip_model()->
783 GetActiveWebContents()->GetURL()));
[email protected]bb89e7482010-11-17 18:27:04784}
785
786// This test verifies that constructing params with disposition = SINGLETON_TAB
[email protected]fee320542011-03-02 01:30:49787// and IGNORE_AND_NAVIGATE opens an existing tab with the matching URL (minus
[email protected]bb89e7482010-11-17 18:27:04788// the path) which is navigated to the specified URL.
789IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
790 Disposition_SingletonTabExistingSubPath_IgnorePath) {
[email protected]a048ad22012-03-23 04:26:56791 GURL singleton_url1(GetContentSettingsURL());
[email protected]52877dbc62012-06-29 22:22:03792 chrome::AddSelectedTabWithURL(browser(), singleton_url1,
793 content::PAGE_TRANSITION_LINK);
794 chrome::AddSelectedTabWithURL(browser(), GetGoogleURL(),
795 content::PAGE_TRANSITION_LINK);
[email protected]bb89e7482010-11-17 18:27:04796
797 // We should have one browser with 3 tabs, the 3rd selected.
[email protected]0665ebe2013-02-13 09:53:19798 EXPECT_EQ(1u, chrome::GetTotalBrowserCount());
[email protected]ee496952013-01-10 23:17:33799 EXPECT_EQ(3, browser()->tab_strip_model()->count());
800 EXPECT_EQ(2, browser()->tab_strip_model()->active_index());
[email protected]bb89e7482010-11-17 18:27:04801
802 // Navigate to singleton_url1.
[email protected]78e2edc2012-07-01 23:32:28803 chrome::NavigateParams p(MakeNavigateParams());
[email protected]bb89e7482010-11-17 18:27:04804 p.disposition = SINGLETON_TAB;
[email protected]a048ad22012-03-23 04:26:56805 p.url = GetClearBrowsingDataURL();
[email protected]78e2edc2012-07-01 23:32:28806 p.window_action = chrome::NavigateParams::SHOW_WINDOW;
807 p.path_behavior = chrome::NavigateParams::IGNORE_AND_NAVIGATE;
808 chrome::Navigate(&p);
[email protected]bb89e7482010-11-17 18:27:04809
810 // The middle tab should now be selected and navigated to the sub-page of the
811 // URL.
812 EXPECT_EQ(browser(), p.browser);
[email protected]ee496952013-01-10 23:17:33813 EXPECT_EQ(3, browser()->tab_strip_model()->count());
814 EXPECT_EQ(1, browser()->tab_strip_model()->active_index());
[email protected]a048ad22012-03-23 04:26:56815 EXPECT_EQ(GetClearBrowsingDataURL(),
[email protected]ee496952013-01-10 23:17:33816 ShortenUberURL(browser()->tab_strip_model()->
817 GetActiveWebContents()->GetURL()));
[email protected]bb89e7482010-11-17 18:27:04818}
[email protected]2dd85482010-11-06 01:56:47819
[email protected]637b3442011-01-10 23:31:48820// This test verifies that constructing params with disposition = SINGLETON_TAB
[email protected]fee320542011-03-02 01:30:49821// and IGNORE_AND_STAY_PUT opens an existing tab with the matching URL (minus
822// the path).
823IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
824 Disposition_SingletonTabExistingSubPath_IgnorePath2) {
[email protected]a048ad22012-03-23 04:26:56825 GURL singleton_url1(GetContentSettingsURL());
[email protected]52877dbc62012-06-29 22:22:03826 chrome::AddSelectedTabWithURL(browser(), singleton_url1,
827 content::PAGE_TRANSITION_LINK);
828 chrome::AddSelectedTabWithURL(browser(), GetGoogleURL(),
829 content::PAGE_TRANSITION_LINK);
[email protected]fee320542011-03-02 01:30:49830
831 // We should have one browser with 3 tabs, the 3rd selected.
[email protected]0665ebe2013-02-13 09:53:19832 EXPECT_EQ(1u, chrome::GetTotalBrowserCount());
[email protected]ee496952013-01-10 23:17:33833 EXPECT_EQ(3, browser()->tab_strip_model()->count());
834 EXPECT_EQ(2, browser()->tab_strip_model()->active_index());
[email protected]fee320542011-03-02 01:30:49835
836 // Navigate to singleton_url1.
[email protected]78e2edc2012-07-01 23:32:28837 chrome::NavigateParams p(MakeNavigateParams());
[email protected]fee320542011-03-02 01:30:49838 p.disposition = SINGLETON_TAB;
[email protected]a048ad22012-03-23 04:26:56839 p.url = GetClearBrowsingDataURL();
[email protected]78e2edc2012-07-01 23:32:28840 p.window_action = chrome::NavigateParams::SHOW_WINDOW;
841 p.path_behavior = chrome::NavigateParams::IGNORE_AND_STAY_PUT;
842 chrome::Navigate(&p);
[email protected]fee320542011-03-02 01:30:49843
844 // The middle tab should now be selected.
845 EXPECT_EQ(browser(), p.browser);
[email protected]ee496952013-01-10 23:17:33846 EXPECT_EQ(3, browser()->tab_strip_model()->count());
847 EXPECT_EQ(1, browser()->tab_strip_model()->active_index());
[email protected]fee320542011-03-02 01:30:49848 EXPECT_EQ(singleton_url1,
[email protected]ee496952013-01-10 23:17:33849 ShortenUberURL(browser()->tab_strip_model()->
850 GetActiveWebContents()->GetURL()));
[email protected]fee320542011-03-02 01:30:49851}
852
853// This test verifies that constructing params with disposition = SINGLETON_TAB
854// and IGNORE_AND_NAVIGATE will update the current tab's URL if the currently
[email protected]637b3442011-01-10 23:31:48855// selected tab is a match but has a different path.
856IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
857 Disposition_SingletonTabFocused_IgnorePath) {
[email protected]a048ad22012-03-23 04:26:56858 GURL singleton_url_current(GetContentSettingsURL());
[email protected]52877dbc62012-06-29 22:22:03859 chrome::AddSelectedTabWithURL(browser(), singleton_url_current,
860 content::PAGE_TRANSITION_LINK);
[email protected]637b3442011-01-10 23:31:48861
862 // We should have one browser with 2 tabs, the 2nd selected.
[email protected]0665ebe2013-02-13 09:53:19863 EXPECT_EQ(1u, chrome::GetTotalBrowserCount());
[email protected]ee496952013-01-10 23:17:33864 EXPECT_EQ(2, browser()->tab_strip_model()->count());
865 EXPECT_EQ(1, browser()->tab_strip_model()->active_index());
[email protected]637b3442011-01-10 23:31:48866
867 // Navigate to a different settings path.
[email protected]a048ad22012-03-23 04:26:56868 GURL singleton_url_target(GetClearBrowsingDataURL());
[email protected]78e2edc2012-07-01 23:32:28869 chrome::NavigateParams p(MakeNavigateParams());
[email protected]637b3442011-01-10 23:31:48870 p.disposition = SINGLETON_TAB;
871 p.url = singleton_url_target;
[email protected]78e2edc2012-07-01 23:32:28872 p.window_action = chrome::NavigateParams::SHOW_WINDOW;
873 p.path_behavior = chrome::NavigateParams::IGNORE_AND_NAVIGATE;
874 chrome::Navigate(&p);
[email protected]637b3442011-01-10 23:31:48875
876 // The second tab should still be selected, but navigated to the new path.
877 EXPECT_EQ(browser(), p.browser);
[email protected]ee496952013-01-10 23:17:33878 EXPECT_EQ(2, browser()->tab_strip_model()->count());
879 EXPECT_EQ(1, browser()->tab_strip_model()->active_index());
[email protected]637b3442011-01-10 23:31:48880 EXPECT_EQ(singleton_url_target,
[email protected]ee496952013-01-10 23:17:33881 ShortenUberURL(browser()->tab_strip_model()->
882 GetActiveWebContents()->GetURL()));
[email protected]637b3442011-01-10 23:31:48883}
884
[email protected]07afd7c2011-02-17 10:07:11885// This test verifies that constructing params with disposition = SINGLETON_TAB
[email protected]fee320542011-03-02 01:30:49886// and IGNORE_AND_NAVIGATE will open an existing matching tab with a different
887// query.
[email protected]07afd7c2011-02-17 10:07:11888IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
889 Disposition_SingletonTabExisting_IgnoreQuery) {
[email protected]ee496952013-01-10 23:17:33890 int initial_tab_count = browser()->tab_strip_model()->count();
[email protected]07afd7c2011-02-17 10:07:11891 GURL singleton_url_current("chrome://settings/internet");
[email protected]52877dbc62012-06-29 22:22:03892 chrome::AddSelectedTabWithURL(browser(), singleton_url_current,
893 content::PAGE_TRANSITION_LINK);
[email protected]07afd7c2011-02-17 10:07:11894
[email protected]ee496952013-01-10 23:17:33895 EXPECT_EQ(initial_tab_count + 1, browser()->tab_strip_model()->count());
896 EXPECT_EQ(initial_tab_count, browser()->tab_strip_model()->active_index());
[email protected]07afd7c2011-02-17 10:07:11897
898 // Navigate to a different settings path.
899 GURL singleton_url_target(
900 "chrome://settings/internet?"
901 "servicePath=/profile/ethernet_00aa00aa00aa&networkType=1");
[email protected]78e2edc2012-07-01 23:32:28902 chrome::NavigateParams p(MakeNavigateParams());
[email protected]07afd7c2011-02-17 10:07:11903 p.disposition = SINGLETON_TAB;
904 p.url = singleton_url_target;
[email protected]78e2edc2012-07-01 23:32:28905 p.window_action = chrome::NavigateParams::SHOW_WINDOW;
906 p.path_behavior = chrome::NavigateParams::IGNORE_AND_NAVIGATE;
907 chrome::Navigate(&p);
[email protected]07afd7c2011-02-17 10:07:11908
909 // Last tab should still be selected.
910 EXPECT_EQ(browser(), p.browser);
[email protected]ee496952013-01-10 23:17:33911 EXPECT_EQ(initial_tab_count + 1, browser()->tab_strip_model()->count());
912 EXPECT_EQ(initial_tab_count, browser()->tab_strip_model()->active_index());
[email protected]07afd7c2011-02-17 10:07:11913}
914
[email protected]bd817c22011-02-09 08:16:46915// This test verifies that the settings page isn't opened in the incognito
916// window.
[email protected]a048ad22012-03-23 04:26:56917// Disabled until fixed for uber settings: http://crbug.com/111243
[email protected]bd817c22011-02-09 08:16:46918IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
[email protected]a048ad22012-03-23 04:26:56919 DISABLED_Disposition_Settings_UseNonIncognitoWindow) {
[email protected]fc0ed302011-11-29 23:17:19920 RunUseNonIncognitoWindowTest(GetSettingsURL());
[email protected]bd817c22011-02-09 08:16:46921}
922
[email protected]82404cd2011-07-12 19:55:14923// This test verifies that the settings page isn't opened in the incognito
924// window from a non-incognito window (bookmark open-in-incognito trigger).
[email protected]a048ad22012-03-23 04:26:56925// Disabled until fixed for uber settings: http://crbug.com/111243
[email protected]82404cd2011-07-12 19:55:14926IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
[email protected]a048ad22012-03-23 04:26:56927 DISABLED_Disposition_Settings_UseNonIncognitoWindowForBookmark) {
[email protected]78e2edc2012-07-01 23:32:28928 chrome::NavigateParams params(browser(), GetSettingsURL(),
929 content::PAGE_TRANSITION_AUTO_BOOKMARK);
[email protected]82404cd2011-07-12 19:55:14930 params.disposition = OFF_THE_RECORD;
931 {
[email protected]a7fe9112012-07-20 02:34:45932 content::WindowedNotificationObserver observer(
[email protected]ad50def52011-10-19 23:17:07933 content::NOTIFICATION_LOAD_STOP,
934 content::NotificationService::AllSources());
[email protected]78e2edc2012-07-01 23:32:28935 chrome::Navigate(&params);
[email protected]82404cd2011-07-12 19:55:14936 observer.Wait();
937 }
938
[email protected]0665ebe2013-02-13 09:53:19939 EXPECT_EQ(1u, chrome::GetTotalBrowserCount());
[email protected]52877dbc62012-06-29 22:22:03940 EXPECT_EQ(GetSettingsURL(),
[email protected]ee496952013-01-10 23:17:33941 ShortenUberURL(browser()->tab_strip_model()->
942 GetActiveWebContents()->GetURL()));
[email protected]82404cd2011-07-12 19:55:14943}
944
[email protected]93ad8e1c2011-11-08 21:34:05945// Settings page is expected to always open in normal mode regardless
946// of whether the user is trying to open it in incognito mode or not.
947// This test verifies that if incognito mode is forced (by policy), settings
948// page doesn't open at all.
[email protected]a048ad22012-03-23 04:26:56949// Disabled until fixed for uber settings: http://crbug.com/111243
[email protected]93ad8e1c2011-11-08 21:34:05950IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
[email protected]a048ad22012-03-23 04:26:56951 DISABLED_Disposition_Settings_DoNothingIfIncognitoIsForced) {
[email protected]fc0ed302011-11-29 23:17:19952 RunDoNothingIfIncognitoIsForcedTest(GetSettingsURL());
[email protected]93ad8e1c2011-11-08 21:34:05953}
954
[email protected]bd817c22011-02-09 08:16:46955// This test verifies that the bookmarks page isn't opened in the incognito
956// window.
957IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
958 Disposition_Bookmarks_UseNonIncognitoWindow) {
[email protected]fc0ed302011-11-29 23:17:19959 RunUseNonIncognitoWindowTest(GURL(chrome::kChromeUIBookmarksURL));
[email protected]bd817c22011-02-09 08:16:46960}
961
[email protected]93ad8e1c2011-11-08 21:34:05962// Bookmark manager is expected to always open in normal mode regardless
963// of whether the user is trying to open it in incognito mode or not.
964// This test verifies that if incognito mode is forced (by policy), bookmark
965// manager doesn't open at all.
966IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
967 Disposition_Bookmarks_DoNothingIfIncognitoIsForced) {
[email protected]fc0ed302011-11-29 23:17:19968 RunDoNothingIfIncognitoIsForcedTest(GURL(chrome::kChromeUIBookmarksURL));
969}
[email protected]93ad8e1c2011-11-08 21:34:05970
[email protected]fc0ed302011-11-29 23:17:19971// This test verifies that the sync promo page isn't opened in the incognito
972// window.
973IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
974 Disposition_SyncPromo_UseNonIncognitoWindow) {
975 RunUseNonIncognitoWindowTest(GURL(chrome::kChromeUISyncPromoURL));
976}
[email protected]93ad8e1c2011-11-08 21:34:05977
[email protected]fc0ed302011-11-29 23:17:19978// The Sync promo page is expected to always open in normal mode regardless of
979// whether the user is trying to open it in incognito mode or not. This test
980// verifies that if incognito mode is forced (by policy), the sync promo page
981// doesn't open at all.
982IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
983 Disposition_SyncPromo_DoNothingIfIncognitoIsForced) {
984 RunDoNothingIfIncognitoIsForcedTest(GURL(chrome::kChromeUISyncPromoURL));
[email protected]93ad8e1c2011-11-08 21:34:05985}
986
[email protected]7de53c62011-05-13 06:44:16987// This test makes sure a crashed singleton tab reloads from a new navigation.
988IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
989 NavigateToCrashedSingletonTab) {
[email protected]a048ad22012-03-23 04:26:56990 GURL singleton_url(GetContentSettingsURL());
[email protected]5a1a52462012-11-15 03:35:16991 WebContents* web_contents = chrome::AddSelectedTabWithURL(
[email protected]52877dbc62012-06-29 22:22:03992 browser(), singleton_url, content::PAGE_TRANSITION_LINK);
[email protected]7de53c62011-05-13 06:44:16993
994 // We should have one browser with 2 tabs, the 2nd selected.
[email protected]0665ebe2013-02-13 09:53:19995 EXPECT_EQ(1u, chrome::GetTotalBrowserCount());
[email protected]ee496952013-01-10 23:17:33996 EXPECT_EQ(2, browser()->tab_strip_model()->count());
997 EXPECT_EQ(1, browser()->tab_strip_model()->active_index());
[email protected]7de53c62011-05-13 06:44:16998
999 // Kill the singleton tab.
[email protected]83ff91c2012-01-05 20:54:131000 web_contents->SetIsCrashed(base::TERMINATION_STATUS_PROCESS_CRASHED, -1);
1001 EXPECT_TRUE(web_contents->IsCrashed());
[email protected]7de53c62011-05-13 06:44:161002
[email protected]78e2edc2012-07-01 23:32:281003 chrome::NavigateParams p(MakeNavigateParams());
[email protected]7de53c62011-05-13 06:44:161004 p.disposition = SINGLETON_TAB;
1005 p.url = singleton_url;
[email protected]78e2edc2012-07-01 23:32:281006 p.window_action = chrome::NavigateParams::SHOW_WINDOW;
1007 p.path_behavior = chrome::NavigateParams::IGNORE_AND_NAVIGATE;
[email protected]ddddfda2011-07-14 23:19:391008 ui_test_utils::NavigateToURL(&p);
[email protected]7de53c62011-05-13 06:44:161009
1010 // The tab should not be sad anymore.
[email protected]83ff91c2012-01-05 20:54:131011 EXPECT_FALSE(web_contents->IsCrashed());
[email protected]7de53c62011-05-13 06:44:161012}
1013
[email protected]fcca741b2011-06-17 22:46:371014IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
1015 NavigateFromDefaultToOptionsInSameTab) {
[email protected]ddddfda2011-07-14 23:19:391016 {
[email protected]a7fe9112012-07-20 02:34:451017 content::WindowedNotificationObserver observer(
[email protected]ad50def52011-10-19 23:17:071018 content::NOTIFICATION_LOAD_STOP,
1019 content::NotificationService::AllSources());
[email protected]5d9cace72012-06-21 16:07:121020 chrome::ShowSettings(browser());
[email protected]ddddfda2011-07-14 23:19:391021 observer.Wait();
1022 }
[email protected]ee496952013-01-10 23:17:331023 EXPECT_EQ(1, browser()->tab_strip_model()->count());
[email protected]52877dbc62012-06-29 22:22:031024 EXPECT_EQ(GetSettingsURL(),
[email protected]ee496952013-01-10 23:17:331025 ShortenUberURL(browser()->tab_strip_model()->
1026 GetActiveWebContents()->GetURL()));
[email protected]fcca741b2011-06-17 22:46:371027}
1028
1029IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
1030 NavigateFromBlankToOptionsInSameTab) {
[email protected]78e2edc2012-07-01 23:32:281031 chrome::NavigateParams p(MakeNavigateParams());
[email protected]ddddfda2011-07-14 23:19:391032 p.url = GURL(chrome::kAboutBlankURL);
1033 ui_test_utils::NavigateToURL(&p);
[email protected]fcca741b2011-06-17 22:46:371034
[email protected]ddddfda2011-07-14 23:19:391035 {
[email protected]a7fe9112012-07-20 02:34:451036 content::WindowedNotificationObserver observer(
[email protected]ad50def52011-10-19 23:17:071037 content::NOTIFICATION_LOAD_STOP,
1038 content::NotificationService::AllSources());
[email protected]5d9cace72012-06-21 16:07:121039 chrome::ShowSettings(browser());
[email protected]ddddfda2011-07-14 23:19:391040 observer.Wait();
1041 }
[email protected]ee496952013-01-10 23:17:331042 EXPECT_EQ(1, browser()->tab_strip_model()->count());
[email protected]52877dbc62012-06-29 22:22:031043 EXPECT_EQ(GetSettingsURL(),
[email protected]ee496952013-01-10 23:17:331044 ShortenUberURL(browser()->tab_strip_model()->
1045 GetActiveWebContents()->GetURL()));
[email protected]fcca741b2011-06-17 22:46:371046}
1047
1048IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
1049 NavigateFromNTPToOptionsInSameTab) {
[email protected]78e2edc2012-07-01 23:32:281050 chrome::NavigateParams p(MakeNavigateParams());
[email protected]ddddfda2011-07-14 23:19:391051 p.url = GURL(chrome::kChromeUINewTabURL);
1052 ui_test_utils::NavigateToURL(&p);
[email protected]ee496952013-01-10 23:17:331053 EXPECT_EQ(1, browser()->tab_strip_model()->count());
[email protected]ddddfda2011-07-14 23:19:391054 EXPECT_EQ(GURL(chrome::kChromeUINewTabURL),
[email protected]ee496952013-01-10 23:17:331055 browser()->tab_strip_model()->GetActiveWebContents()->GetURL());
[email protected]fcca741b2011-06-17 22:46:371056
[email protected]ddddfda2011-07-14 23:19:391057 {
[email protected]a7fe9112012-07-20 02:34:451058 content::WindowedNotificationObserver observer(
[email protected]ad50def52011-10-19 23:17:071059 content::NOTIFICATION_LOAD_STOP,
1060 content::NotificationService::AllSources());
[email protected]5d9cace72012-06-21 16:07:121061 chrome::ShowSettings(browser());
[email protected]ddddfda2011-07-14 23:19:391062 observer.Wait();
1063 }
[email protected]ee496952013-01-10 23:17:331064 EXPECT_EQ(1, browser()->tab_strip_model()->count());
[email protected]52877dbc62012-06-29 22:22:031065 EXPECT_EQ(GetSettingsURL(),
[email protected]ee496952013-01-10 23:17:331066 ShortenUberURL(browser()->tab_strip_model()->
1067 GetActiveWebContents()->GetURL()));
[email protected]fcca741b2011-06-17 22:46:371068}
1069
1070IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
1071 NavigateFromPageToOptionsInNewTab) {
[email protected]78e2edc2012-07-01 23:32:281072 chrome::NavigateParams p(MakeNavigateParams());
[email protected]ddddfda2011-07-14 23:19:391073 ui_test_utils::NavigateToURL(&p);
[email protected]ee496952013-01-10 23:17:331074 EXPECT_EQ(GetGoogleURL(),
1075 browser()->tab_strip_model()->GetActiveWebContents()->GetURL());
[email protected]0665ebe2013-02-13 09:53:191076 EXPECT_EQ(1u, chrome::GetTotalBrowserCount());
[email protected]ee496952013-01-10 23:17:331077 EXPECT_EQ(1, browser()->tab_strip_model()->count());
[email protected]fcca741b2011-06-17 22:46:371078
[email protected]ddddfda2011-07-14 23:19:391079 {
[email protected]a7fe9112012-07-20 02:34:451080 content::WindowedNotificationObserver observer(
[email protected]ad50def52011-10-19 23:17:071081 content::NOTIFICATION_LOAD_STOP,
1082 content::NotificationService::AllSources());
[email protected]5d9cace72012-06-21 16:07:121083 chrome::ShowSettings(browser());
[email protected]ddddfda2011-07-14 23:19:391084 observer.Wait();
1085 }
[email protected]ee496952013-01-10 23:17:331086 EXPECT_EQ(2, browser()->tab_strip_model()->count());
[email protected]52877dbc62012-06-29 22:22:031087 EXPECT_EQ(GetSettingsURL(),
[email protected]ee496952013-01-10 23:17:331088 ShortenUberURL(browser()->tab_strip_model()->
1089 GetActiveWebContents()->GetURL()));
[email protected]fcca741b2011-06-17 22:46:371090}
1091
1092IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
1093 NavigateFromNTPToOptionsSingleton) {
[email protected]ddddfda2011-07-14 23:19:391094 {
[email protected]a7fe9112012-07-20 02:34:451095 content::WindowedNotificationObserver observer(
[email protected]ad50def52011-10-19 23:17:071096 content::NOTIFICATION_LOAD_STOP,
1097 content::NotificationService::AllSources());
[email protected]5d9cace72012-06-21 16:07:121098 chrome::ShowSettings(browser());
[email protected]ddddfda2011-07-14 23:19:391099 observer.Wait();
1100 }
[email protected]ee496952013-01-10 23:17:331101 EXPECT_EQ(1, browser()->tab_strip_model()->count());
[email protected]fcca741b2011-06-17 22:46:371102
[email protected]a37d4b02012-06-25 21:56:101103 chrome::NewTab(browser());
[email protected]ee496952013-01-10 23:17:331104 EXPECT_EQ(2, browser()->tab_strip_model()->count());
[email protected]fcca741b2011-06-17 22:46:371105
[email protected]ddddfda2011-07-14 23:19:391106 {
[email protected]a7fe9112012-07-20 02:34:451107 content::WindowedNotificationObserver observer(
[email protected]ad50def52011-10-19 23:17:071108 content::NOTIFICATION_LOAD_STOP,
1109 content::NotificationService::AllSources());
[email protected]5d9cace72012-06-21 16:07:121110 chrome::ShowSettings(browser());
[email protected]ddddfda2011-07-14 23:19:391111 observer.Wait();
1112 }
[email protected]ee496952013-01-10 23:17:331113 EXPECT_EQ(2, browser()->tab_strip_model()->count());
[email protected]52877dbc62012-06-29 22:22:031114 EXPECT_EQ(GetSettingsURL(),
[email protected]ee496952013-01-10 23:17:331115 ShortenUberURL(browser()->tab_strip_model()->
1116 GetActiveWebContents()->GetURL()));
[email protected]fcca741b2011-06-17 22:46:371117}
1118
1119IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
1120 NavigateFromNTPToOptionsPageInSameTab) {
[email protected]ddddfda2011-07-14 23:19:391121 {
[email protected]a7fe9112012-07-20 02:34:451122 content::WindowedNotificationObserver observer(
[email protected]ad50def52011-10-19 23:17:071123 content::NOTIFICATION_LOAD_STOP,
1124 content::NotificationService::AllSources());
[email protected]5d9cace72012-06-21 16:07:121125 chrome::ShowClearBrowsingDataDialog(browser());
[email protected]ddddfda2011-07-14 23:19:391126 observer.Wait();
1127 }
[email protected]ee496952013-01-10 23:17:331128 EXPECT_EQ(1, browser()->tab_strip_model()->count());
[email protected]a048ad22012-03-23 04:26:561129 EXPECT_EQ(GetClearBrowsingDataURL(),
[email protected]ee496952013-01-10 23:17:331130 browser()->tab_strip_model()->GetActiveWebContents()->GetURL());
[email protected]fcca741b2011-06-17 22:46:371131
[email protected]a37d4b02012-06-25 21:56:101132 chrome::NewTab(browser());
[email protected]ee496952013-01-10 23:17:331133 EXPECT_EQ(2, browser()->tab_strip_model()->count());
[email protected]fcca741b2011-06-17 22:46:371134
[email protected]ddddfda2011-07-14 23:19:391135 {
[email protected]a7fe9112012-07-20 02:34:451136 content::WindowedNotificationObserver observer(
[email protected]ad50def52011-10-19 23:17:071137 content::NOTIFICATION_LOAD_STOP,
1138 content::NotificationService::AllSources());
[email protected]5d9cace72012-06-21 16:07:121139 chrome::ShowClearBrowsingDataDialog(browser());
[email protected]ddddfda2011-07-14 23:19:391140 observer.Wait();
1141 }
[email protected]ee496952013-01-10 23:17:331142 EXPECT_EQ(2, browser()->tab_strip_model()->count());
[email protected]a048ad22012-03-23 04:26:561143 EXPECT_EQ(GetClearBrowsingDataURL(),
[email protected]ee496952013-01-10 23:17:331144 browser()->tab_strip_model()->GetActiveWebContents()->GetURL());
[email protected]fcca741b2011-06-17 22:46:371145}
1146
[email protected]ccb8aac2012-05-21 23:00:161147// Times out on mac, fails on linux.
1148// http://crbug.com/119779
1149#if defined(OS_MACOSX) || defined(OS_LINUX)
[email protected]aac43c72012-03-23 18:41:021150#define MAYBE_NavigateFromOtherTabToSingletonOptions DISABLED_NavigateFromOtherTabToSingletonOptions
1151#else
1152#define MAYBE_NavigateFromOtherTabToSingletonOptions NavigatorFrameOtherTabToSingletonOptions
1153#endif
[email protected]fcca741b2011-06-17 22:46:371154IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
[email protected]aac43c72012-03-23 18:41:021155 MAYBE_NavigateFromOtherTabToSingletonOptions) {
[email protected]ddddfda2011-07-14 23:19:391156 {
[email protected]a7fe9112012-07-20 02:34:451157 content::WindowedNotificationObserver observer(
[email protected]ad50def52011-10-19 23:17:071158 content::NOTIFICATION_LOAD_STOP,
1159 content::NotificationService::AllSources());
[email protected]5d9cace72012-06-21 16:07:121160 chrome::ShowSettings(browser());
[email protected]ddddfda2011-07-14 23:19:391161 observer.Wait();
1162 }
1163 {
[email protected]a7fe9112012-07-20 02:34:451164 content::WindowedNotificationObserver observer(
[email protected]ad50def52011-10-19 23:17:071165 content::NOTIFICATION_LOAD_STOP,
1166 content::NotificationService::AllSources());
[email protected]52877dbc62012-06-29 22:22:031167 chrome::AddSelectedTabWithURL(browser(), GetGoogleURL(),
1168 content::PAGE_TRANSITION_LINK);
[email protected]ddddfda2011-07-14 23:19:391169 observer.Wait();
1170 }
[email protected]fcca741b2011-06-17 22:46:371171
[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 }
[email protected]ee496952013-01-10 23:17:331179 EXPECT_EQ(2, browser()->tab_strip_model()->count());
[email protected]ddddfda2011-07-14 23:19:391180 EXPECT_EQ(GetSettingsURL(),
[email protected]ee496952013-01-10 23:17:331181 ShortenUberURL(browser()->tab_strip_model()->
1182 GetActiveWebContents()->GetURL()));
[email protected]fcca741b2011-06-17 22:46:371183}
1184
[email protected]a048ad22012-03-23 04:26:561185// TODO(csilv): Update this for uber page. http://crbug.com/111579.
[email protected]ddddfda2011-07-14 23:19:391186IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
[email protected]a048ad22012-03-23 04:26:561187 DISABLED_NavigateFromDefaultToHistoryInSameTab) {
[email protected]ddddfda2011-07-14 23:19:391188 {
[email protected]a7fe9112012-07-20 02:34:451189 content::WindowedNotificationObserver observer(
[email protected]ad50def52011-10-19 23:17:071190 content::NOTIFICATION_LOAD_STOP,
1191 content::NotificationService::AllSources());
[email protected]5d9cace72012-06-21 16:07:121192 chrome::ShowHistory(browser());
[email protected]ddddfda2011-07-14 23:19:391193 observer.Wait();
1194 }
[email protected]ee496952013-01-10 23:17:331195 EXPECT_EQ(1, browser()->tab_strip_model()->count());
[email protected]11e03fb2012-03-03 19:07:051196 EXPECT_EQ(GURL(chrome::kChromeUIHistoryFrameURL),
[email protected]ee496952013-01-10 23:17:331197 browser()->tab_strip_model()->GetActiveWebContents()->GetURL());
[email protected]ddddfda2011-07-14 23:19:391198}
1199
[email protected]953c2132013-02-23 05:56:051200// TODO(linux_aura) http://crbug.com/163931
1201#if defined(OS_LINUX) && !defined(OS_CHROMEOS) && defined(USE_AURA)
1202#define MAYBE_NavigateFromDefaultToBookmarksInSameTab DISABLED_NavigateFromDefaultToBookmarksInSameTab
1203#else
1204#define MAYBE_NavigateFromDefaultToBookmarksInSameTab NavigateFromDefaultToBookmarksInSameTab
1205#endif
[email protected]ddddfda2011-07-14 23:19:391206IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
[email protected]953c2132013-02-23 05:56:051207 MAYBE_NavigateFromDefaultToBookmarksInSameTab) {
[email protected]ddddfda2011-07-14 23:19:391208 {
[email protected]a7fe9112012-07-20 02:34:451209 content::WindowedNotificationObserver observer(
[email protected]ad50def52011-10-19 23:17:071210 content::NOTIFICATION_LOAD_STOP,
1211 content::NotificationService::AllSources());
[email protected]5d9cace72012-06-21 16:07:121212 chrome::ShowBookmarkManager(browser());
[email protected]ddddfda2011-07-14 23:19:391213 observer.Wait();
1214 }
[email protected]ee496952013-01-10 23:17:331215 EXPECT_EQ(1, browser()->tab_strip_model()->count());
[email protected]bc16a252013-01-23 02:21:491216 EXPECT_TRUE(StartsWithASCII(
1217 browser()->tab_strip_model()->GetActiveWebContents()->GetURL().spec(),
1218 chrome::kChromeUIBookmarksURL,
1219 true));
[email protected]ddddfda2011-07-14 23:19:391220}
1221
1222IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
1223 NavigateFromDefaultToDownloadsInSameTab) {
1224 {
[email protected]a7fe9112012-07-20 02:34:451225 content::WindowedNotificationObserver observer(
[email protected]ad50def52011-10-19 23:17:071226 content::NOTIFICATION_LOAD_STOP,
1227 content::NotificationService::AllSources());
[email protected]5d9cace72012-06-21 16:07:121228 chrome::ShowDownloads(browser());
[email protected]ddddfda2011-07-14 23:19:391229 observer.Wait();
1230 }
[email protected]ee496952013-01-10 23:17:331231 EXPECT_EQ(1, browser()->tab_strip_model()->count());
[email protected]ddddfda2011-07-14 23:19:391232 EXPECT_EQ(GURL(chrome::kChromeUIDownloadsURL),
[email protected]ee496952013-01-10 23:17:331233 browser()->tab_strip_model()->GetActiveWebContents()->GetURL());
[email protected]ddddfda2011-07-14 23:19:391234}
1235
[email protected]8fb16a82012-08-17 02:17:591236IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
1237 NavigateWithoutBrowser) {
1238 // First navigate using the profile of the existing browser window, and
1239 // check that the window is reused.
1240 chrome::NavigateParams params(browser()->profile(), GetGoogleURL(),
1241 content::PAGE_TRANSITION_LINK);
1242 ui_test_utils::NavigateToURL(&params);
[email protected]0665ebe2013-02-13 09:53:191243 EXPECT_EQ(1u, chrome::GetTotalBrowserCount());
[email protected]8fb16a82012-08-17 02:17:591244
1245 // Now navigate using the incognito profile and check that a new window
1246 // is created.
1247 chrome::NavigateParams params_incognito(
1248 browser()->profile()->GetOffTheRecordProfile(),
1249 GetGoogleURL(), content::PAGE_TRANSITION_LINK);
1250 ui_test_utils::NavigateToURL(&params_incognito);
[email protected]0665ebe2013-02-13 09:53:191251 EXPECT_EQ(2u, chrome::GetTotalBrowserCount());
[email protected]8fb16a82012-08-17 02:17:591252}
1253
[email protected]ddddfda2011-07-14 23:19:391254} // namespace