blob: 1fd1cda732fcb9e1abb358bed61b3b3dc782d16f [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]a37d4b02012-06-25 21:56:1012#include "chrome/browser/ui/browser_commands.h"
[email protected]0665ebe2013-02-13 09:53:1913#include "chrome/browser/ui/browser_finder.h"
[email protected]339d6dd2010-11-12 00:41:5814#include "chrome/browser/ui/browser_navigator.h"
[email protected]52877dbc62012-06-29 22:22:0315#include "chrome/browser/ui/browser_tabstrip.h"
[email protected]bb89e7482010-11-17 18:27:0416#include "chrome/browser/ui/browser_window.h"
[email protected]5d9cace72012-06-21 16:07:1217#include "chrome/browser/ui/chrome_pages.h"
[email protected]b56e2e32012-05-11 21:18:0418#include "chrome/browser/ui/tabs/tab_strip_model.h"
[email protected]bb89e7482010-11-17 18:27:0419#include "chrome/common/chrome_switches.h"
[email protected]93ad8e1c2011-11-08 21:34:0520#include "chrome/common/pref_names.h"
[email protected]ddddfda2011-07-14 23:19:3921#include "chrome/common/url_constants.h"
[email protected]af44e7fb2011-07-29 18:32:3222#include "chrome/test/base/ui_test_utils.h"
[email protected]ad50def52011-10-19 23:17:0723#include "content/public/browser/notification_service.h"
[email protected]0d6e9bd2011-10-18 04:29:1624#include "content/public/browser/notification_types.h"
[email protected]83ff91c2012-01-05 20:54:1325#include "content/public/browser/web_contents.h"
[email protected]8643e6d2012-01-18 20:26:1026#include "content/public/browser/web_contents_view.h"
[email protected]c47317e2012-06-20 22:35:3127#include "ipc/ipc_message.h"
[email protected]a1feae52010-10-11 22:14:4528
[email protected]4ca15302012-01-03 05:53:2029using content::WebContents;
30
[email protected]ddddfda2011-07-14 23:19:3931namespace {
32
33GURL GetGoogleURL() {
[email protected]bd817c22011-02-09 08:16:4634 return GURL("http://www.google.com/");
35}
[email protected]a1feae52010-10-11 22:14:4536
[email protected]ddddfda2011-07-14 23:19:3937GURL GetSettingsURL() {
[email protected]f8f93eb2012-09-25 03:06:2438 return GURL(chrome::kChromeUISettingsURL);
[email protected]ddddfda2011-07-14 23:19:3939}
40
[email protected]a048ad22012-03-23 04:26:5641GURL GetContentSettingsURL() {
42 return GetSettingsURL().Resolve(chrome::kContentSettingsExceptionsSubPage);
[email protected]ddddfda2011-07-14 23:19:3943}
44
[email protected]a048ad22012-03-23 04:26:5645GURL GetClearBrowsingDataURL() {
46 return GetSettingsURL().Resolve(chrome::kClearBrowserDataSubPage);
[email protected]ddddfda2011-07-14 23:19:3947}
48
[email protected]f8f93eb2012-09-25 03:06:2449// Converts long uber URLs ("chrome://chrome/foo/") to short (virtual) URLs
50// ("chrome://foo/"). This should be used to convert the return value of
51// WebContentsImpl::GetURL before comparison because it can return either the
52// real URL or the virtual URL.
53GURL ShortenUberURL(const GURL& url) {
54 std::string url_string = url.spec();
55 const std::string long_prefix = "chrome://chrome/";
56 const std::string short_prefix = "chrome://";
57 if (url_string.find(long_prefix) != 0)
58 return url;
59 url_string.replace(0, long_prefix.length(), short_prefix);
60 return GURL(url_string);
61}
62
[email protected]ddddfda2011-07-14 23:19:3963} // namespace
64
[email protected]78e2edc2012-07-01 23:32:2865chrome::NavigateParams BrowserNavigatorTest::MakeNavigateParams() const {
[email protected]bd817c22011-02-09 08:16:4666 return MakeNavigateParams(browser());
67}
[email protected]a1feae52010-10-11 22:14:4568
[email protected]78e2edc2012-07-01 23:32:2869chrome::NavigateParams BrowserNavigatorTest::MakeNavigateParams(
[email protected]bd817c22011-02-09 08:16:4670 Browser* browser) const {
[email protected]78e2edc2012-07-01 23:32:2871 chrome::NavigateParams params(browser, GetGoogleURL(),
72 content::PAGE_TRANSITION_LINK);
73 params.window_action = chrome::NavigateParams::SHOW_WINDOW;
[email protected]bd817c22011-02-09 08:16:4674 return params;
75}
[email protected]a1feae52010-10-11 22:14:4576
[email protected]bd817c22011-02-09 08:16:4677Browser* BrowserNavigatorTest::CreateEmptyBrowserForType(Browser::Type type,
78 Profile* profile) {
[email protected]a4fe67012012-07-25 20:14:2979 Browser* browser = new Browser(Browser::CreateParams(type, profile));
[email protected]686221c2012-11-08 07:30:1080 chrome::AddBlankTabAt(browser, -1, true);
[email protected]bd817c22011-02-09 08:16:4681 return browser;
82}
[email protected]a1feae52010-10-11 22:14:4583
[email protected]b35b26b32011-05-05 20:35:1484Browser* BrowserNavigatorTest::CreateEmptyBrowserForApp(Browser::Type type,
85 Profile* profile) {
[email protected]a4fe67012012-07-25 20:14:2986 Browser* browser = new Browser(
[email protected]da22aa62012-04-04 18:54:3587 Browser::CreateParams::CreateForApp(
88 Browser::TYPE_POPUP, "Test", gfx::Rect(), profile));
[email protected]686221c2012-11-08 07:30:1089 chrome::AddBlankTabAt(browser, -1, true);
[email protected]b35b26b32011-05-05 20:35:1490 return browser;
91}
92
[email protected]e232c992012-12-06 12:43:2093WebContents* BrowserNavigatorTest::CreateWebContents() {
[email protected]54944cde2012-12-09 09:24:5994 content::WebContents::CreateParams create_params(browser()->profile());
[email protected]ed245db2012-12-18 08:00:4595 content::WebContents* base_web_contents =
[email protected]ee496952013-01-10 23:17:3396 browser()->tab_strip_model()->GetActiveWebContents();
[email protected]ed245db2012-12-18 08:00:4597 if (base_web_contents) {
98 create_params.initial_size =
99 base_web_contents->GetView()->GetContainerSize();
100 }
[email protected]54944cde2012-12-09 09:24:59101 return WebContents::Create(create_params);
[email protected]bd817c22011-02-09 08:16:46102}
[email protected]a1feae52010-10-11 22:14:45103
[email protected]bd817c22011-02-09 08:16:46104void BrowserNavigatorTest::RunSuppressTest(WindowOpenDisposition disposition) {
[email protected]ee496952013-01-10 23:17:33105 GURL old_url = browser()->tab_strip_model()->GetActiveWebContents()->GetURL();
[email protected]78e2edc2012-07-01 23:32:28106 chrome::NavigateParams p(MakeNavigateParams());
[email protected]bd817c22011-02-09 08:16:46107 p.disposition = disposition;
[email protected]78e2edc2012-07-01 23:32:28108 chrome::Navigate(&p);
[email protected]a1feae52010-10-11 22:14:45109
[email protected]bd817c22011-02-09 08:16:46110 // Nothing should have happened as a result of Navigate();
[email protected]ee496952013-01-10 23:17:33111 EXPECT_EQ(1, browser()->tab_strip_model()->count());
[email protected]0665ebe2013-02-13 09:53:19112 EXPECT_EQ(1u, chrome::GetTotalBrowserCount());
[email protected]ee496952013-01-10 23:17:33113 EXPECT_EQ(old_url,
114 browser()->tab_strip_model()->GetActiveWebContents()->GetURL());
[email protected]bd817c22011-02-09 08:16:46115}
[email protected]bb89e7482010-11-17 18:27:04116
[email protected]fc0ed302011-11-29 23:17:19117void BrowserNavigatorTest::RunUseNonIncognitoWindowTest(const GURL& url) {
118 Browser* incognito_browser = CreateIncognitoBrowser();
119
[email protected]0665ebe2013-02-13 09:53:19120 EXPECT_EQ(2u, chrome::GetTotalBrowserCount());
[email protected]ee496952013-01-10 23:17:33121 EXPECT_EQ(1, browser()->tab_strip_model()->count());
122 EXPECT_EQ(1, incognito_browser->tab_strip_model()->count());
[email protected]fc0ed302011-11-29 23:17:19123
124 // Navigate to the page.
[email protected]78e2edc2012-07-01 23:32:28125 chrome::NavigateParams p(MakeNavigateParams(incognito_browser));
[email protected]fc0ed302011-11-29 23:17:19126 p.disposition = SINGLETON_TAB;
127 p.url = url;
[email protected]78e2edc2012-07-01 23:32:28128 p.window_action = chrome::NavigateParams::SHOW_WINDOW;
129 chrome::Navigate(&p);
[email protected]fc0ed302011-11-29 23:17:19130
131 // This page should be opened in browser() window.
132 EXPECT_NE(incognito_browser, p.browser);
133 EXPECT_EQ(browser(), p.browser);
[email protected]ee496952013-01-10 23:17:33134 EXPECT_EQ(2, browser()->tab_strip_model()->count());
135 EXPECT_EQ(url,
136 browser()->tab_strip_model()->GetActiveWebContents()->GetURL());
[email protected]fc0ed302011-11-29 23:17:19137}
138
139void BrowserNavigatorTest::RunDoNothingIfIncognitoIsForcedTest(
140 const GURL& url) {
141 Browser* browser = CreateIncognitoBrowser();
142
143 // Set kIncognitoModeAvailability to FORCED.
144 PrefService* prefs1 = browser->profile()->GetPrefs();
145 prefs1->SetInteger(prefs::kIncognitoModeAvailability,
146 IncognitoModePrefs::FORCED);
147 PrefService* prefs2 = browser->profile()->GetOriginalProfile()->GetPrefs();
148 prefs2->SetInteger(prefs::kIncognitoModeAvailability,
149 IncognitoModePrefs::FORCED);
150
151 // Navigate to the page.
[email protected]78e2edc2012-07-01 23:32:28152 chrome::NavigateParams p(MakeNavigateParams(browser));
[email protected]fc0ed302011-11-29 23:17:19153 p.disposition = OFF_THE_RECORD;
154 p.url = url;
[email protected]78e2edc2012-07-01 23:32:28155 p.window_action = chrome::NavigateParams::SHOW_WINDOW;
156 chrome::Navigate(&p);
[email protected]fc0ed302011-11-29 23:17:19157
158 // The page should not be opened.
159 EXPECT_EQ(browser, p.browser);
[email protected]ee496952013-01-10 23:17:33160 EXPECT_EQ(1, browser->tab_strip_model()->count());
[email protected]fc0ed302011-11-29 23:17:19161 EXPECT_EQ(GURL(chrome::kAboutBlankURL),
[email protected]ee496952013-01-10 23:17:33162 browser->tab_strip_model()->GetActiveWebContents()->GetURL());
[email protected]fc0ed302011-11-29 23:17:19163}
164
[email protected]6c2381d2011-10-19 02:52:53165void BrowserNavigatorTest::Observe(
166 int type,
167 const content::NotificationSource& source,
168 const content::NotificationDetails& details) {
[email protected]432115822011-07-10 15:52:27169 switch (type) {
[email protected]d53a08c2012-07-18 20:35:30170 case content::NOTIFICATION_WEB_CONTENTS_RENDER_VIEW_HOST_CREATED: {
[email protected]bd817c22011-02-09 08:16:46171 ++this->created_tab_contents_count_;
172 break;
[email protected]fa7ebe02010-11-29 23:04:57173 }
[email protected]bd817c22011-02-09 08:16:46174 default:
175 break;
[email protected]fa7ebe02010-11-29 23:04:57176 }
[email protected]bd817c22011-02-09 08:16:46177}
[email protected]fa7ebe02010-11-29 23:04:57178
[email protected]ddddfda2011-07-14 23:19:39179
[email protected]bd817c22011-02-09 08:16:46180namespace {
[email protected]a1feae52010-10-11 22:14:45181
[email protected]a1feae52010-10-11 22:14:45182// This test verifies that when a navigation occurs within a tab, the tab count
183// of the Browser remains the same and the current tab bears the loaded URL.
184IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_CurrentTab) {
[email protected]ddddfda2011-07-14 23:19:39185 ui_test_utils::NavigateToURL(browser(), GetGoogleURL());
[email protected]ee496952013-01-10 23:17:33186 EXPECT_EQ(GetGoogleURL(),
187 browser()->tab_strip_model()->GetActiveWebContents()->GetURL());
[email protected]a1feae52010-10-11 22:14:45188 // We should have one window with one tab.
[email protected]0665ebe2013-02-13 09:53:19189 EXPECT_EQ(1u, chrome::GetTotalBrowserCount());
[email protected]ee496952013-01-10 23:17:33190 EXPECT_EQ(1, browser()->tab_strip_model()->count());
[email protected]a1feae52010-10-11 22:14:45191}
192
[email protected]bd817c22011-02-09 08:16:46193// This test verifies that a singleton tab is refocused if one is already opened
[email protected]19d9f3a2010-10-14 21:49:36194// in another or an existing window, or added if it is not.
195IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_SingletonTabExisting) {
[email protected]19d9f3a2010-10-14 21:49:36196 GURL singleton_url1("http://maps.google.com/");
[email protected]fa7ebe02010-11-29 23:04:57197
[email protected]e232c992012-12-06 12:43:20198 // Register for a notification if an additional WebContents was instantiated.
[email protected]bd817c22011-02-09 08:16:46199 // Opening a Singleton tab that is already opened should not be opening a new
[email protected]e232c992012-12-06 12:43:20200 // tab nor be creating a new WebContents object.
[email protected]6c2381d2011-10-19 02:52:53201 content::NotificationRegistrar registrar;
[email protected]fa7ebe02010-11-29 23:04:57202
203 // As the registrar object goes out of scope, this will get unregistered
[email protected]d53a08c2012-07-18 20:35:30204 registrar.Add(this,
205 content::NOTIFICATION_WEB_CONTENTS_RENDER_VIEW_HOST_CREATED,
[email protected]ad50def52011-10-19 23:17:07206 content::NotificationService::AllSources());
[email protected]fa7ebe02010-11-29 23:04:57207
[email protected]52877dbc62012-06-29 22:22:03208 chrome::AddSelectedTabWithURL(browser(), singleton_url1,
209 content::PAGE_TRANSITION_LINK);
210 chrome::AddSelectedTabWithURL(browser(), GetGoogleURL(),
211 content::PAGE_TRANSITION_LINK);
[email protected]19d9f3a2010-10-14 21:49:36212
213 // We should have one browser with 3 tabs, the 3rd selected.
[email protected]0665ebe2013-02-13 09:53:19214 EXPECT_EQ(1u, chrome::GetTotalBrowserCount());
[email protected]ee496952013-01-10 23:17:33215 EXPECT_EQ(2, browser()->tab_strip_model()->active_index());
[email protected]19d9f3a2010-10-14 21:49:36216
[email protected]fa7ebe02010-11-29 23:04:57217 unsigned int previous_tab_contents_count =
218 created_tab_contents_count_ = 0;
219
[email protected]19d9f3a2010-10-14 21:49:36220 // Navigate to singleton_url1.
[email protected]78e2edc2012-07-01 23:32:28221 chrome::NavigateParams p(MakeNavigateParams());
[email protected]19d9f3a2010-10-14 21:49:36222 p.disposition = SINGLETON_TAB;
223 p.url = singleton_url1;
[email protected]78e2edc2012-07-01 23:32:28224 chrome::Navigate(&p);
[email protected]19d9f3a2010-10-14 21:49:36225
226 // The middle tab should now be selected.
227 EXPECT_EQ(browser(), p.browser);
[email protected]ee496952013-01-10 23:17:33228 EXPECT_EQ(1, browser()->tab_strip_model()->active_index());
[email protected]fa7ebe02010-11-29 23:04:57229
230 // No tab contents should have been created
231 EXPECT_EQ(previous_tab_contents_count,
232 created_tab_contents_count_);
[email protected]19d9f3a2010-10-14 21:49:36233}
234
235IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
[email protected]578c6962011-08-24 22:06:40236 Disposition_SingletonTabRespectingRef) {
237 GURL singleton_ref_url1("http://maps.google.com/#a");
238 GURL singleton_ref_url2("http://maps.google.com/#b");
239 GURL singleton_ref_url3("http://maps.google.com/");
240
[email protected]52877dbc62012-06-29 22:22:03241 chrome::AddSelectedTabWithURL(browser(), singleton_ref_url1,
242 content::PAGE_TRANSITION_LINK);
[email protected]578c6962011-08-24 22:06:40243
244 // We should have one browser with 2 tabs, 2nd selected.
[email protected]0665ebe2013-02-13 09:53:19245 EXPECT_EQ(1u, chrome::GetTotalBrowserCount());
[email protected]ee496952013-01-10 23:17:33246 EXPECT_EQ(2, browser()->tab_strip_model()->count());
247 EXPECT_EQ(1, browser()->tab_strip_model()->active_index());
[email protected]578c6962011-08-24 22:06:40248
249 // Navigate to singleton_url2.
[email protected]78e2edc2012-07-01 23:32:28250 chrome::NavigateParams p(MakeNavigateParams());
[email protected]578c6962011-08-24 22:06:40251 p.disposition = SINGLETON_TAB;
252 p.url = singleton_ref_url2;
[email protected]78e2edc2012-07-01 23:32:28253 chrome::Navigate(&p);
[email protected]578c6962011-08-24 22:06:40254
255 // We should now have 2 tabs, the 2nd one selected.
256 EXPECT_EQ(browser(), p.browser);
[email protected]ee496952013-01-10 23:17:33257 EXPECT_EQ(2, browser()->tab_strip_model()->count());
258 EXPECT_EQ(1, browser()->tab_strip_model()->active_index());
[email protected]578c6962011-08-24 22:06:40259
260 // Navigate to singleton_url2, but with respect ref set.
261 p = MakeNavigateParams();
262 p.disposition = SINGLETON_TAB;
263 p.url = singleton_ref_url2;
[email protected]78e2edc2012-07-01 23:32:28264 p.ref_behavior = chrome::NavigateParams::RESPECT_REF;
265 chrome::Navigate(&p);
[email protected]578c6962011-08-24 22:06:40266
267 // We should now have 3 tabs, the 3th one selected.
268 EXPECT_EQ(browser(), p.browser);
[email protected]ee496952013-01-10 23:17:33269 EXPECT_EQ(3, browser()->tab_strip_model()->count());
270 EXPECT_EQ(2, browser()->tab_strip_model()->active_index());
[email protected]578c6962011-08-24 22:06:40271
272 // Navigate to singleton_url3.
273 p = MakeNavigateParams();
274 p.disposition = SINGLETON_TAB;
275 p.url = singleton_ref_url3;
[email protected]78e2edc2012-07-01 23:32:28276 p.ref_behavior = chrome::NavigateParams::RESPECT_REF;
277 chrome::Navigate(&p);
[email protected]578c6962011-08-24 22:06:40278
279 // We should now have 4 tabs, the 4th one selected.
280 EXPECT_EQ(browser(), p.browser);
[email protected]ee496952013-01-10 23:17:33281 EXPECT_EQ(4, browser()->tab_strip_model()->count());
282 EXPECT_EQ(3, browser()->tab_strip_model()->active_index());
[email protected]578c6962011-08-24 22:06:40283}
284
285IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
[email protected]19d9f3a2010-10-14 21:49:36286 Disposition_SingletonTabNoneExisting) {
[email protected]19d9f3a2010-10-14 21:49:36287 GURL singleton_url1("http://maps.google.com/");
288
[email protected]bd817c22011-02-09 08:16:46289 // We should have one browser with 1 tab.
[email protected]0665ebe2013-02-13 09:53:19290 EXPECT_EQ(1u, chrome::GetTotalBrowserCount());
[email protected]ee496952013-01-10 23:17:33291 EXPECT_EQ(0, browser()->tab_strip_model()->active_index());
[email protected]19d9f3a2010-10-14 21:49:36292
293 // Navigate to singleton_url1.
[email protected]78e2edc2012-07-01 23:32:28294 chrome::NavigateParams p(MakeNavigateParams());
[email protected]19d9f3a2010-10-14 21:49:36295 p.disposition = SINGLETON_TAB;
296 p.url = singleton_url1;
[email protected]78e2edc2012-07-01 23:32:28297 chrome::Navigate(&p);
[email protected]19d9f3a2010-10-14 21:49:36298
299 // We should now have 2 tabs, the 2nd one selected.
300 EXPECT_EQ(browser(), p.browser);
[email protected]ee496952013-01-10 23:17:33301 EXPECT_EQ(2, browser()->tab_strip_model()->count());
302 EXPECT_EQ(1, browser()->tab_strip_model()->active_index());
[email protected]a1feae52010-10-11 22:14:45303}
304
305// This test verifies that when a navigation results in a foreground tab, the
306// tab count of the Browser increases and the selected tab shifts to the new
307// foreground tab.
308IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_NewForegroundTab) {
[email protected]ee496952013-01-10 23:17:33309 WebContents* old_contents =
310 browser()->tab_strip_model()->GetActiveWebContents();
[email protected]78e2edc2012-07-01 23:32:28311 chrome::NavigateParams p(MakeNavigateParams());
[email protected]a1feae52010-10-11 22:14:45312 p.disposition = NEW_FOREGROUND_TAB;
[email protected]78e2edc2012-07-01 23:32:28313 chrome::Navigate(&p);
[email protected]ee496952013-01-10 23:17:33314 EXPECT_NE(old_contents,
315 browser()->tab_strip_model()->GetActiveWebContents());
[email protected]e232c992012-12-06 12:43:20316 EXPECT_EQ(browser()->tab_strip_model()->GetActiveWebContents(),
[email protected]59253a652012-11-20 00:17:26317 p.target_contents);
[email protected]ee496952013-01-10 23:17:33318 EXPECT_EQ(2, browser()->tab_strip_model()->count());
[email protected]a1feae52010-10-11 22:14:45319}
320
321// This test verifies that when a navigation results in a background tab, the
322// tab count of the Browser increases but the selected tab remains the same.
323IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_NewBackgroundTab) {
[email protected]ee496952013-01-10 23:17:33324 WebContents* old_contents =
325 browser()->tab_strip_model()->GetActiveWebContents();
[email protected]78e2edc2012-07-01 23:32:28326 chrome::NavigateParams p(MakeNavigateParams());
[email protected]a1feae52010-10-11 22:14:45327 p.disposition = NEW_BACKGROUND_TAB;
[email protected]78e2edc2012-07-01 23:32:28328 chrome::Navigate(&p);
[email protected]ee496952013-01-10 23:17:33329 WebContents* new_contents =
330 browser()->tab_strip_model()->GetActiveWebContents();
[email protected]a1feae52010-10-11 22:14:45331 // The selected tab should have remained unchanged, since the new tab was
332 // opened in the background.
333 EXPECT_EQ(old_contents, new_contents);
[email protected]ee496952013-01-10 23:17:33334 EXPECT_EQ(2, browser()->tab_strip_model()->count());
[email protected]a1feae52010-10-11 22:14:45335}
336
337// This test verifies that when a navigation requiring a new foreground tab
338// occurs in a Browser that cannot host multiple tabs, the new foreground tab
339// is created in an existing compatible Browser.
340IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
341 Disposition_IncompatibleWindow_Existing) {
342 // Open a foreground tab in a window that cannot open popups when there is an
343 // existing compatible window somewhere else that they can be opened within.
344 Browser* popup = CreateEmptyBrowserForType(Browser::TYPE_POPUP,
345 browser()->profile());
[email protected]78e2edc2012-07-01 23:32:28346 chrome::NavigateParams p(MakeNavigateParams(popup));
[email protected]a1feae52010-10-11 22:14:45347 p.disposition = NEW_FOREGROUND_TAB;
[email protected]78e2edc2012-07-01 23:32:28348 chrome::Navigate(&p);
[email protected]a1feae52010-10-11 22:14:45349
350 // Navigate() should have opened the tab in a different browser since the
351 // one we supplied didn't support additional tabs.
352 EXPECT_NE(popup, p.browser);
353
354 // Since browser() is an existing compatible tabbed browser, it should have
355 // opened the tab there.
356 EXPECT_EQ(browser(), p.browser);
357
358 // We should be left with 2 windows, the popup with one tab and the browser()
359 // provided by the framework with two.
[email protected]0665ebe2013-02-13 09:53:19360 EXPECT_EQ(2u, chrome::GetTotalBrowserCount());
[email protected]ee496952013-01-10 23:17:33361 EXPECT_EQ(1, popup->tab_strip_model()->count());
362 EXPECT_EQ(2, browser()->tab_strip_model()->count());
[email protected]a1feae52010-10-11 22:14:45363}
364
365// This test verifies that when a navigation requiring a new foreground tab
366// occurs in a Browser that cannot host multiple tabs and no compatible Browser
367// that can is open, a compatible Browser is created.
368IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
369 Disposition_IncompatibleWindow_NoExisting) {
370 // We want to simulate not being able to find an existing window compatible
371 // with our non-tabbed browser window so Navigate() is forced to create a
372 // new compatible window. Because browser() supplied by the in-process
373 // browser testing framework is compatible with browser()->profile(), we
374 // need a different profile, and creating a popup window with an incognito
375 // profile is a quick and dirty way of achieving this.
376 Browser* popup = CreateEmptyBrowserForType(
[email protected]b35b26b32011-05-05 20:35:14377 Browser::TYPE_POPUP,
378 browser()->profile()->GetOffTheRecordProfile());
[email protected]78e2edc2012-07-01 23:32:28379 chrome::NavigateParams p(MakeNavigateParams(popup));
[email protected]a1feae52010-10-11 22:14:45380 p.disposition = NEW_FOREGROUND_TAB;
[email protected]78e2edc2012-07-01 23:32:28381 chrome::Navigate(&p);
[email protected]a1feae52010-10-11 22:14:45382
383 // Navigate() should have opened the tab in a different browser since the
384 // one we supplied didn't support additional tabs.
385 EXPECT_NE(popup, p.browser);
386
387 // This time, browser() is _not_ compatible with popup since it is not an
388 // incognito window.
389 EXPECT_NE(browser(), p.browser);
390
391 // We should have three windows, each with one tab:
392 // 1. the browser() provided by the framework (unchanged in this test)
393 // 2. the incognito popup we created originally
394 // 3. the new incognito tabbed browser that was created by Navigate().
[email protected]0665ebe2013-02-13 09:53:19395 EXPECT_EQ(3u, chrome::GetTotalBrowserCount());
[email protected]ee496952013-01-10 23:17:33396 EXPECT_EQ(1, browser()->tab_strip_model()->count());
397 EXPECT_EQ(1, popup->tab_strip_model()->count());
398 EXPECT_EQ(1, p.browser->tab_strip_model()->count());
[email protected]b35b26b32011-05-05 20:35:14399 EXPECT_TRUE(p.browser->is_type_tabbed());
[email protected]a1feae52010-10-11 22:14:45400}
401
402// This test verifies that navigating with WindowOpenDisposition = NEW_POPUP
403// from a normal Browser results in a new Browser with TYPE_POPUP.
404IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_NewPopup) {
[email protected]78e2edc2012-07-01 23:32:28405 chrome::NavigateParams p(MakeNavigateParams());
[email protected]a1feae52010-10-11 22:14:45406 p.disposition = NEW_POPUP;
[email protected]588300d2011-04-28 21:06:35407 p.window_bounds = gfx::Rect(0, 0, 200, 200);
[email protected]7d329992011-04-15 18:20:02408 // Wait for new popup to to load and gain focus.
[email protected]ddddfda2011-07-14 23:19:39409 ui_test_utils::NavigateToURL(&p);
[email protected]a1feae52010-10-11 22:14:45410
[email protected]7d329992011-04-15 18:20:02411 // Navigate() should have opened a new, focused popup window.
[email protected]a1feae52010-10-11 22:14:45412 EXPECT_NE(browser(), p.browser);
[email protected]9db263a2011-04-15 20:53:47413#if 0
414 // TODO(stevenjb): Enable this test. See: crbug.com/79493
[email protected]7d329992011-04-15 18:20:02415 EXPECT_TRUE(p.browser->window()->IsActive());
416#endif
[email protected]b35b26b32011-05-05 20:35:14417 EXPECT_TRUE(p.browser->is_type_popup());
418 EXPECT_FALSE(p.browser->is_app());
[email protected]a1feae52010-10-11 22:14:45419
420 // We should have two windows, the browser() provided by the framework and the
421 // new popup window.
[email protected]0665ebe2013-02-13 09:53:19422 EXPECT_EQ(2u, chrome::GetTotalBrowserCount());
[email protected]ee496952013-01-10 23:17:33423 EXPECT_EQ(1, browser()->tab_strip_model()->count());
424 EXPECT_EQ(1, p.browser->tab_strip_model()->count());
[email protected]a1feae52010-10-11 22:14:45425}
426
427// This test verifies that navigating with WindowOpenDisposition = NEW_POPUP
[email protected]f112b0f2011-05-26 01:53:52428// from a normal Browser results in a new Browser with is_app() true.
429IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_NewPopup_ExtensionId) {
[email protected]78e2edc2012-07-01 23:32:28430 chrome::NavigateParams p(MakeNavigateParams());
[email protected]f112b0f2011-05-26 01:53:52431 p.disposition = NEW_POPUP;
432 p.extension_app_id = "extensionappid";
433 p.window_bounds = gfx::Rect(0, 0, 200, 200);
[email protected]f112b0f2011-05-26 01:53:52434 // Wait for new popup to to load and gain focus.
[email protected]ddddfda2011-07-14 23:19:39435 ui_test_utils::NavigateToURL(&p);
[email protected]f112b0f2011-05-26 01:53:52436
437 // Navigate() should have opened a new, focused popup window.
438 EXPECT_NE(browser(), p.browser);
439 EXPECT_TRUE(p.browser->is_type_popup());
440 EXPECT_TRUE(p.browser->is_app());
441
442 // We should have two windows, the browser() provided by the framework and the
443 // new popup window.
[email protected]0665ebe2013-02-13 09:53:19444 EXPECT_EQ(2u, chrome::GetTotalBrowserCount());
[email protected]ee496952013-01-10 23:17:33445 EXPECT_EQ(1, browser()->tab_strip_model()->count());
446 EXPECT_EQ(1, p.browser->tab_strip_model()->count());
[email protected]f112b0f2011-05-26 01:53:52447}
448
449// This test verifies that navigating with WindowOpenDisposition = NEW_POPUP
[email protected]300d1e52011-01-19 23:57:57450// from a normal popup results in a new Browser with TYPE_POPUP.
451IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_NewPopupFromPopup) {
452 // Open a popup.
[email protected]78e2edc2012-07-01 23:32:28453 chrome::NavigateParams p1(MakeNavigateParams());
[email protected]300d1e52011-01-19 23:57:57454 p1.disposition = NEW_POPUP;
[email protected]588300d2011-04-28 21:06:35455 p1.window_bounds = gfx::Rect(0, 0, 200, 200);
[email protected]78e2edc2012-07-01 23:32:28456 chrome::Navigate(&p1);
[email protected]300d1e52011-01-19 23:57:57457 // Open another popup.
[email protected]78e2edc2012-07-01 23:32:28458 chrome::NavigateParams p2(MakeNavigateParams(p1.browser));
[email protected]300d1e52011-01-19 23:57:57459 p2.disposition = NEW_POPUP;
[email protected]588300d2011-04-28 21:06:35460 p2.window_bounds = gfx::Rect(0, 0, 200, 200);
[email protected]78e2edc2012-07-01 23:32:28461 chrome::Navigate(&p2);
[email protected]300d1e52011-01-19 23:57:57462
463 // Navigate() should have opened a new normal popup window.
464 EXPECT_NE(p1.browser, p2.browser);
[email protected]b35b26b32011-05-05 20:35:14465 EXPECT_TRUE(p2.browser->is_type_popup());
466 EXPECT_FALSE(p2.browser->is_app());
[email protected]300d1e52011-01-19 23:57:57467
468 // We should have three windows, the browser() provided by the framework,
469 // the first popup window, and the second popup window.
[email protected]0665ebe2013-02-13 09:53:19470 EXPECT_EQ(3u, chrome::GetTotalBrowserCount());
[email protected]ee496952013-01-10 23:17:33471 EXPECT_EQ(1, browser()->tab_strip_model()->count());
472 EXPECT_EQ(1, p1.browser->tab_strip_model()->count());
473 EXPECT_EQ(1, p2.browser->tab_strip_model()->count());
[email protected]300d1e52011-01-19 23:57:57474}
475
476// This test verifies that navigating with WindowOpenDisposition = NEW_POPUP
[email protected]a1feae52010-10-11 22:14:45477// from an app frame results in a new Browser with TYPE_APP_POPUP.
478IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
479 Disposition_NewPopupFromAppWindow) {
[email protected]b35b26b32011-05-05 20:35:14480 Browser* app_browser = CreateEmptyBrowserForApp(Browser::TYPE_TABBED,
481 browser()->profile());
[email protected]78e2edc2012-07-01 23:32:28482 chrome::NavigateParams p(MakeNavigateParams(app_browser));
[email protected]a1feae52010-10-11 22:14:45483 p.disposition = NEW_POPUP;
[email protected]588300d2011-04-28 21:06:35484 p.window_bounds = gfx::Rect(0, 0, 200, 200);
[email protected]78e2edc2012-07-01 23:32:28485 chrome::Navigate(&p);
[email protected]a1feae52010-10-11 22:14:45486
487 // Navigate() should have opened a new popup app window.
488 EXPECT_NE(app_browser, p.browser);
489 EXPECT_NE(browser(), p.browser);
[email protected]b35b26b32011-05-05 20:35:14490 EXPECT_TRUE(p.browser->is_type_popup());
491 EXPECT_TRUE(p.browser->is_app());
[email protected]a1feae52010-10-11 22:14:45492
493 // We should now have three windows, the app window, the app popup it created,
494 // and the original browser() provided by the framework.
[email protected]0665ebe2013-02-13 09:53:19495 EXPECT_EQ(3u, chrome::GetTotalBrowserCount());
[email protected]ee496952013-01-10 23:17:33496 EXPECT_EQ(1, browser()->tab_strip_model()->count());
497 EXPECT_EQ(1, app_browser->tab_strip_model()->count());
498 EXPECT_EQ(1, p.browser->tab_strip_model()->count());
[email protected]a1feae52010-10-11 22:14:45499}
500
501// This test verifies that navigating with WindowOpenDisposition = NEW_POPUP
[email protected]300d1e52011-01-19 23:57:57502// from an app popup results in a new Browser also of TYPE_APP_POPUP.
503IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
504 Disposition_NewPopupFromAppPopup) {
[email protected]b35b26b32011-05-05 20:35:14505 Browser* app_browser = CreateEmptyBrowserForApp(Browser::TYPE_TABBED,
506 browser()->profile());
[email protected]300d1e52011-01-19 23:57:57507 // Open an app popup.
[email protected]78e2edc2012-07-01 23:32:28508 chrome::NavigateParams p1(MakeNavigateParams(app_browser));
[email protected]300d1e52011-01-19 23:57:57509 p1.disposition = NEW_POPUP;
[email protected]588300d2011-04-28 21:06:35510 p1.window_bounds = gfx::Rect(0, 0, 200, 200);
[email protected]78e2edc2012-07-01 23:32:28511 chrome::Navigate(&p1);
[email protected]300d1e52011-01-19 23:57:57512 // Now open another app popup.
[email protected]78e2edc2012-07-01 23:32:28513 chrome::NavigateParams p2(MakeNavigateParams(p1.browser));
[email protected]300d1e52011-01-19 23:57:57514 p2.disposition = NEW_POPUP;
[email protected]588300d2011-04-28 21:06:35515 p2.window_bounds = gfx::Rect(0, 0, 200, 200);
[email protected]78e2edc2012-07-01 23:32:28516 chrome::Navigate(&p2);
[email protected]300d1e52011-01-19 23:57:57517
518 // Navigate() should have opened a new popup app window.
519 EXPECT_NE(browser(), p1.browser);
520 EXPECT_NE(p1.browser, p2.browser);
[email protected]b35b26b32011-05-05 20:35:14521 EXPECT_TRUE(p2.browser->is_type_popup());
522 EXPECT_TRUE(p2.browser->is_app());
[email protected]300d1e52011-01-19 23:57:57523
524 // We should now have four windows, the app window, the first app popup,
525 // the second app popup, and the original browser() provided by the framework.
[email protected]0665ebe2013-02-13 09:53:19526 EXPECT_EQ(4u, chrome::GetTotalBrowserCount());
[email protected]ee496952013-01-10 23:17:33527 EXPECT_EQ(1, browser()->tab_strip_model()->count());
528 EXPECT_EQ(1, app_browser->tab_strip_model()->count());
529 EXPECT_EQ(1, p1.browser->tab_strip_model()->count());
530 EXPECT_EQ(1, p2.browser->tab_strip_model()->count());
[email protected]300d1e52011-01-19 23:57:57531}
532
533// This test verifies that navigating with WindowOpenDisposition = NEW_POPUP
[email protected]a1feae52010-10-11 22:14:45534// from an extension app tab results in a new Browser with TYPE_APP_POPUP.
535IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
536 Disposition_NewPopupFromExtensionApp) {
537 // TODO(beng): TBD.
538}
539
[email protected]7d329992011-04-15 18:20:02540// This test verifies that navigating with window_action = SHOW_WINDOW_INACTIVE
541// does not focus a new new popup window.
542IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_NewPopupUnfocused) {
[email protected]78e2edc2012-07-01 23:32:28543 chrome::NavigateParams p(MakeNavigateParams());
[email protected]7d329992011-04-15 18:20:02544 p.disposition = NEW_POPUP;
[email protected]588300d2011-04-28 21:06:35545 p.window_bounds = gfx::Rect(0, 0, 200, 200);
[email protected]78e2edc2012-07-01 23:32:28546 p.window_action = chrome::NavigateParams::SHOW_WINDOW_INACTIVE;
[email protected]7d329992011-04-15 18:20:02547 // Wait for new popup to load (and gain focus if the test fails).
[email protected]ddddfda2011-07-14 23:19:39548 ui_test_utils::NavigateToURL(&p);
[email protected]7d329992011-04-15 18:20:02549
550 // Navigate() should have opened a new, unfocused, popup window.
551 EXPECT_NE(browser(), p.browser);
552 EXPECT_EQ(Browser::TYPE_POPUP, p.browser->type());
[email protected]9db263a2011-04-15 20:53:47553#if 0
554// TODO(stevenjb): Enable this test. See: crbug.com/79493
[email protected]7d329992011-04-15 18:20:02555 EXPECT_FALSE(p.browser->window()->IsActive());
[email protected]7d329992011-04-15 18:20:02556#endif
[email protected]9db263a2011-04-15 20:53:47557}
[email protected]7d329992011-04-15 18:20:02558
[email protected]a1feae52010-10-11 22:14:45559// This test verifies that navigating with WindowOpenDisposition = NEW_WINDOW
560// always opens a new window.
561IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_NewWindow) {
[email protected]78e2edc2012-07-01 23:32:28562 chrome::NavigateParams p(MakeNavigateParams());
[email protected]a1feae52010-10-11 22:14:45563 p.disposition = NEW_WINDOW;
[email protected]78e2edc2012-07-01 23:32:28564 chrome::Navigate(&p);
[email protected]a1feae52010-10-11 22:14:45565
566 // Navigate() should have opened a new toplevel window.
567 EXPECT_NE(browser(), p.browser);
[email protected]b35b26b32011-05-05 20:35:14568 EXPECT_TRUE(p.browser->is_type_tabbed());
[email protected]a1feae52010-10-11 22:14:45569
570 // We should now have two windows, the browser() provided by the framework and
571 // the new normal window.
[email protected]0665ebe2013-02-13 09:53:19572 EXPECT_EQ(2u, chrome::GetTotalBrowserCount());
[email protected]ee496952013-01-10 23:17:33573 EXPECT_EQ(1, browser()->tab_strip_model()->count());
574 EXPECT_EQ(1, p.browser->tab_strip_model()->count());
[email protected]a1feae52010-10-11 22:14:45575}
576
577// This test verifies that navigating with WindowOpenDisposition = INCOGNITO
578// opens a new incognito window if no existing incognito window is present.
579IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_Incognito) {
[email protected]78e2edc2012-07-01 23:32:28580 chrome::NavigateParams p(MakeNavigateParams());
[email protected]a1feae52010-10-11 22:14:45581 p.disposition = OFF_THE_RECORD;
[email protected]78e2edc2012-07-01 23:32:28582 chrome::Navigate(&p);
[email protected]a1feae52010-10-11 22:14:45583
584 // Navigate() should have opened a new toplevel incognito window.
585 EXPECT_NE(browser(), p.browser);
586 EXPECT_EQ(browser()->profile()->GetOffTheRecordProfile(),
587 p.browser->profile());
588
[email protected]d7ff3592010-11-30 21:50:46589 // |source_contents| should be set to NULL because the profile for the new
590 // page is different from the originating page.
591 EXPECT_EQ(NULL, p.source_contents);
592
[email protected]a1feae52010-10-11 22:14:45593 // We should now have two windows, the browser() provided by the framework and
594 // the new incognito window.
[email protected]0665ebe2013-02-13 09:53:19595 EXPECT_EQ(2u, chrome::GetTotalBrowserCount());
[email protected]ee496952013-01-10 23:17:33596 EXPECT_EQ(1, browser()->tab_strip_model()->count());
597 EXPECT_EQ(1, p.browser->tab_strip_model()->count());
[email protected]a1feae52010-10-11 22:14:45598}
599
600// This test verifies that navigating with WindowOpenDisposition = INCOGNITO
601// reuses an existing incognito window when possible.
602IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_IncognitoRefocus) {
603 Browser* incognito_browser =
[email protected]b35b26b32011-05-05 20:35:14604 CreateEmptyBrowserForType(Browser::TYPE_TABBED,
[email protected]a1feae52010-10-11 22:14:45605 browser()->profile()->GetOffTheRecordProfile());
[email protected]78e2edc2012-07-01 23:32:28606 chrome::NavigateParams p(MakeNavigateParams());
[email protected]a1feae52010-10-11 22:14:45607 p.disposition = OFF_THE_RECORD;
[email protected]78e2edc2012-07-01 23:32:28608 chrome::Navigate(&p);
[email protected]a1feae52010-10-11 22:14:45609
610 // Navigate() should have opened a new tab in the existing incognito window.
611 EXPECT_NE(browser(), p.browser);
612 EXPECT_EQ(p.browser, incognito_browser);
613
614 // We should now have two windows, the browser() provided by the framework and
615 // the incognito window we opened earlier.
[email protected]0665ebe2013-02-13 09:53:19616 EXPECT_EQ(2u, chrome::GetTotalBrowserCount());
[email protected]ee496952013-01-10 23:17:33617 EXPECT_EQ(1, browser()->tab_strip_model()->count());
618 EXPECT_EQ(2, incognito_browser->tab_strip_model()->count());
[email protected]a1feae52010-10-11 22:14:45619}
620
621// This test verifies that no navigation action occurs when
622// WindowOpenDisposition = SUPPRESS_OPEN.
623IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_SuppressOpen) {
624 RunSuppressTest(SUPPRESS_OPEN);
625}
626
627// This test verifies that no navigation action occurs when
628// WindowOpenDisposition = SAVE_TO_DISK.
629IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_SaveToDisk) {
630 RunSuppressTest(SAVE_TO_DISK);
631}
632
633// This test verifies that no navigation action occurs when
634// WindowOpenDisposition = IGNORE_ACTION.
635IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_IgnoreAction) {
636 RunSuppressTest(IGNORE_ACTION);
637}
638
[email protected]e232c992012-12-06 12:43:20639// This tests adding a foreground tab with a predefined WebContents.
[email protected]a1feae52010-10-11 22:14:45640IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, TargetContents_ForegroundTab) {
[email protected]78e2edc2012-07-01 23:32:28641 chrome::NavigateParams p(MakeNavigateParams());
[email protected]a1feae52010-10-11 22:14:45642 p.disposition = NEW_FOREGROUND_TAB;
[email protected]e232c992012-12-06 12:43:20643 p.target_contents = CreateWebContents();
[email protected]78e2edc2012-07-01 23:32:28644 chrome::Navigate(&p);
[email protected]a1feae52010-10-11 22:14:45645
646 // Navigate() should have opened the contents in a new foreground in the
647 // current Browser.
648 EXPECT_EQ(browser(), p.browser);
[email protected]e232c992012-12-06 12:43:20649 EXPECT_EQ(browser()->tab_strip_model()->GetActiveWebContents(),
[email protected]59253a652012-11-20 00:17:26650 p.target_contents);
[email protected]a1feae52010-10-11 22:14:45651
652 // We should have one window, with two tabs.
[email protected]0665ebe2013-02-13 09:53:19653 EXPECT_EQ(1u, chrome::GetTotalBrowserCount());
[email protected]ee496952013-01-10 23:17:33654 EXPECT_EQ(2, browser()->tab_strip_model()->count());
[email protected]a1feae52010-10-11 22:14:45655}
656
657#if defined(OS_WIN)
[email protected]e232c992012-12-06 12:43:20658// This tests adding a popup with a predefined WebContents.
[email protected]76edb672011-03-04 21:48:39659IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, DISABLED_TargetContents_Popup) {
[email protected]78e2edc2012-07-01 23:32:28660 chrome::NavigateParams p(MakeNavigateParams());
[email protected]a1feae52010-10-11 22:14:45661 p.disposition = NEW_POPUP;
[email protected]e232c992012-12-06 12:43:20662 p.target_contents = CreateWebContents();
[email protected]a1feae52010-10-11 22:14:45663 p.window_bounds = gfx::Rect(10, 10, 500, 500);
[email protected]78e2edc2012-07-01 23:32:28664 chrome::Navigate(&p);
[email protected]a1feae52010-10-11 22:14:45665
666 // Navigate() should have opened a new popup window.
667 EXPECT_NE(browser(), p.browser);
[email protected]b35b26b32011-05-05 20:35:14668 EXPECT_TRUE(p.browser->is_type_popup());
669 EXPECT_FALSE(p.browser->is_app());
[email protected]a1feae52010-10-11 22:14:45670
671 // The web platform is weird. The window bounds specified in
672 // |p.window_bounds| are used as follows:
673 // - the origin is used to position the window
[email protected]e232c992012-12-06 12:43:20674 // - the size is used to size the WebContents of the window.
[email protected]a1feae52010-10-11 22:14:45675 // As such the position of the resulting window will always match
676 // p.window_bounds.origin(), but its size will not. We need to match
677 // the size against the selected tab's view's container size.
678 // Only Windows positions the window according to |p.window_bounds.origin()| -
679 // on Mac the window is offset from the opener and on Linux it always opens
680 // at 0,0.
681 EXPECT_EQ(p.window_bounds.origin(),
682 p.browser->window()->GetRestoredBounds().origin());
683 // All platforms should respect size however provided width > 400 (Mac has a
684 // minimum window width of 400).
685 EXPECT_EQ(p.window_bounds.size(),
[email protected]e232c992012-12-06 12:43:20686 p.target_contents->GetView()->GetContainerSize());
[email protected]a1feae52010-10-11 22:14:45687
688 // We should have two windows, the new popup and the browser() provided by the
689 // framework.
[email protected]0665ebe2013-02-13 09:53:19690 EXPECT_EQ(2u, chrome::GetTotalBrowserCount());
[email protected]ee496952013-01-10 23:17:33691 EXPECT_EQ(1, browser()->tab_strip_model()->count());
692 EXPECT_EQ(1, p.browser->tab_strip_model()->count());
[email protected]a1feae52010-10-11 22:14:45693}
694#endif
695
696// This tests adding a tab at a specific index.
697IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Tabstrip_InsertAtIndex) {
698 // This is not meant to be a comprehensive test of whether or not the tab
699 // implementation of the browser observes the insertion index. That is
700 // covered by the unit tests for TabStripModel. This merely verifies that
701 // insertion index preference is reflected in common cases.
[email protected]78e2edc2012-07-01 23:32:28702 chrome::NavigateParams p(MakeNavigateParams());
[email protected]a1feae52010-10-11 22:14:45703 p.disposition = NEW_FOREGROUND_TAB;
704 p.tabstrip_index = 0;
705 p.tabstrip_add_types = TabStripModel::ADD_FORCE_INDEX;
[email protected]78e2edc2012-07-01 23:32:28706 chrome::Navigate(&p);
[email protected]a1feae52010-10-11 22:14:45707
708 // Navigate() should have inserted a new tab at slot 0 in the tabstrip.
709 EXPECT_EQ(browser(), p.browser);
[email protected]e232c992012-12-06 12:43:20710 EXPECT_EQ(0, browser()->tab_strip_model()->GetIndexOfWebContents(
711 static_cast<const WebContents*>(p.target_contents)));
[email protected]a1feae52010-10-11 22:14:45712
713 // We should have one window - the browser() provided by the framework.
[email protected]0665ebe2013-02-13 09:53:19714 EXPECT_EQ(1u, chrome::GetTotalBrowserCount());
[email protected]ee496952013-01-10 23:17:33715 EXPECT_EQ(2, browser()->tab_strip_model()->count());
[email protected]a1feae52010-10-11 22:14:45716}
717
[email protected]bb89e7482010-11-17 18:27:04718// This test verifies that constructing params with disposition = SINGLETON_TAB
[email protected]fee320542011-03-02 01:30:49719// and IGNORE_AND_NAVIGATE opens a new tab navigated to the specified URL if
[email protected]67ed83e2011-01-07 22:54:00720// no previous tab with that URL (minus the path) exists.
[email protected]bb89e7482010-11-17 18:27:04721IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
722 Disposition_SingletonTabNew_IgnorePath) {
[email protected]52877dbc62012-06-29 22:22:03723 chrome::AddSelectedTabWithURL(browser(), GetGoogleURL(),
724 content::PAGE_TRANSITION_LINK);
[email protected]bb89e7482010-11-17 18:27:04725
726 // We should have one browser with 2 tabs, the 2nd selected.
[email protected]0665ebe2013-02-13 09:53:19727 EXPECT_EQ(1u, chrome::GetTotalBrowserCount());
[email protected]ee496952013-01-10 23:17:33728 EXPECT_EQ(2, browser()->tab_strip_model()->count());
729 EXPECT_EQ(1, browser()->tab_strip_model()->active_index());
[email protected]bb89e7482010-11-17 18:27:04730
731 // Navigate to a new singleton tab with a sub-page.
[email protected]78e2edc2012-07-01 23:32:28732 chrome::NavigateParams p(MakeNavigateParams());
[email protected]bb89e7482010-11-17 18:27:04733 p.disposition = SINGLETON_TAB;
[email protected]a048ad22012-03-23 04:26:56734 p.url = GetContentSettingsURL();
[email protected]78e2edc2012-07-01 23:32:28735 p.window_action = chrome::NavigateParams::SHOW_WINDOW;
736 p.path_behavior = chrome::NavigateParams::IGNORE_AND_NAVIGATE;
737 chrome::Navigate(&p);
[email protected]bb89e7482010-11-17 18:27:04738
739 // The last tab should now be selected and navigated to the sub-page of the
740 // URL.
741 EXPECT_EQ(browser(), p.browser);
[email protected]ee496952013-01-10 23:17:33742 EXPECT_EQ(3, browser()->tab_strip_model()->count());
743 EXPECT_EQ(2, browser()->tab_strip_model()->active_index());
[email protected]a048ad22012-03-23 04:26:56744 EXPECT_EQ(GetContentSettingsURL(),
[email protected]ee496952013-01-10 23:17:33745 ShortenUberURL(browser()->tab_strip_model()->
746 GetActiveWebContents()->GetURL()));
[email protected]bb89e7482010-11-17 18:27:04747}
748
749// This test verifies that constructing params with disposition = SINGLETON_TAB
[email protected]fee320542011-03-02 01:30:49750// and IGNORE_AND_NAVIGATE opens an existing tab with the matching URL (minus
[email protected]bb89e7482010-11-17 18:27:04751// the path) which is navigated to the specified URL.
752IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
753 Disposition_SingletonTabExisting_IgnorePath) {
[email protected]ddddfda2011-07-14 23:19:39754 GURL singleton_url1(GetSettingsURL());
[email protected]52877dbc62012-06-29 22:22:03755 chrome::AddSelectedTabWithURL(browser(), singleton_url1,
756 content::PAGE_TRANSITION_LINK);
757 chrome::AddSelectedTabWithURL(browser(), GetGoogleURL(),
758 content::PAGE_TRANSITION_LINK);
[email protected]bb89e7482010-11-17 18:27:04759
760 // We should have one browser with 3 tabs, the 3rd selected.
[email protected]0665ebe2013-02-13 09:53:19761 EXPECT_EQ(1u, chrome::GetTotalBrowserCount());
[email protected]ee496952013-01-10 23:17:33762 EXPECT_EQ(3, browser()->tab_strip_model()->count());
763 EXPECT_EQ(2, browser()->tab_strip_model()->active_index());
[email protected]bb89e7482010-11-17 18:27:04764
765 // Navigate to singleton_url1.
[email protected]78e2edc2012-07-01 23:32:28766 chrome::NavigateParams p(MakeNavigateParams());
[email protected]bb89e7482010-11-17 18:27:04767 p.disposition = SINGLETON_TAB;
[email protected]a048ad22012-03-23 04:26:56768 p.url = GetContentSettingsURL();
[email protected]78e2edc2012-07-01 23:32:28769 p.window_action = chrome::NavigateParams::SHOW_WINDOW;
770 p.path_behavior = chrome::NavigateParams::IGNORE_AND_NAVIGATE;
771 chrome::Navigate(&p);
[email protected]bb89e7482010-11-17 18:27:04772
773 // The middle tab should now be selected and navigated to the sub-page of the
774 // URL.
775 EXPECT_EQ(browser(), p.browser);
[email protected]ee496952013-01-10 23:17:33776 EXPECT_EQ(3, browser()->tab_strip_model()->count());
777 EXPECT_EQ(1, browser()->tab_strip_model()->active_index());
[email protected]a048ad22012-03-23 04:26:56778 EXPECT_EQ(GetContentSettingsURL(),
[email protected]ee496952013-01-10 23:17:33779 ShortenUberURL(browser()->tab_strip_model()->
780 GetActiveWebContents()->GetURL()));
[email protected]bb89e7482010-11-17 18:27:04781}
782
783// This test verifies that constructing params with disposition = SINGLETON_TAB
[email protected]fee320542011-03-02 01:30:49784// and IGNORE_AND_NAVIGATE opens an existing tab with the matching URL (minus
[email protected]bb89e7482010-11-17 18:27:04785// the path) which is navigated to the specified URL.
786IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
787 Disposition_SingletonTabExistingSubPath_IgnorePath) {
[email protected]a048ad22012-03-23 04:26:56788 GURL singleton_url1(GetContentSettingsURL());
[email protected]52877dbc62012-06-29 22:22:03789 chrome::AddSelectedTabWithURL(browser(), singleton_url1,
790 content::PAGE_TRANSITION_LINK);
791 chrome::AddSelectedTabWithURL(browser(), GetGoogleURL(),
792 content::PAGE_TRANSITION_LINK);
[email protected]bb89e7482010-11-17 18:27:04793
794 // We should have one browser with 3 tabs, the 3rd selected.
[email protected]0665ebe2013-02-13 09:53:19795 EXPECT_EQ(1u, chrome::GetTotalBrowserCount());
[email protected]ee496952013-01-10 23:17:33796 EXPECT_EQ(3, browser()->tab_strip_model()->count());
797 EXPECT_EQ(2, browser()->tab_strip_model()->active_index());
[email protected]bb89e7482010-11-17 18:27:04798
799 // Navigate to singleton_url1.
[email protected]78e2edc2012-07-01 23:32:28800 chrome::NavigateParams p(MakeNavigateParams());
[email protected]bb89e7482010-11-17 18:27:04801 p.disposition = SINGLETON_TAB;
[email protected]a048ad22012-03-23 04:26:56802 p.url = GetClearBrowsingDataURL();
[email protected]78e2edc2012-07-01 23:32:28803 p.window_action = chrome::NavigateParams::SHOW_WINDOW;
804 p.path_behavior = chrome::NavigateParams::IGNORE_AND_NAVIGATE;
805 chrome::Navigate(&p);
[email protected]bb89e7482010-11-17 18:27:04806
807 // The middle tab should now be selected and navigated to the sub-page of the
808 // URL.
809 EXPECT_EQ(browser(), p.browser);
[email protected]ee496952013-01-10 23:17:33810 EXPECT_EQ(3, browser()->tab_strip_model()->count());
811 EXPECT_EQ(1, browser()->tab_strip_model()->active_index());
[email protected]a048ad22012-03-23 04:26:56812 EXPECT_EQ(GetClearBrowsingDataURL(),
[email protected]ee496952013-01-10 23:17:33813 ShortenUberURL(browser()->tab_strip_model()->
814 GetActiveWebContents()->GetURL()));
[email protected]bb89e7482010-11-17 18:27:04815}
[email protected]2dd85482010-11-06 01:56:47816
[email protected]637b3442011-01-10 23:31:48817// This test verifies that constructing params with disposition = SINGLETON_TAB
[email protected]fee320542011-03-02 01:30:49818// and IGNORE_AND_STAY_PUT opens an existing tab with the matching URL (minus
819// the path).
820IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
821 Disposition_SingletonTabExistingSubPath_IgnorePath2) {
[email protected]a048ad22012-03-23 04:26:56822 GURL singleton_url1(GetContentSettingsURL());
[email protected]52877dbc62012-06-29 22:22:03823 chrome::AddSelectedTabWithURL(browser(), singleton_url1,
824 content::PAGE_TRANSITION_LINK);
825 chrome::AddSelectedTabWithURL(browser(), GetGoogleURL(),
826 content::PAGE_TRANSITION_LINK);
[email protected]fee320542011-03-02 01:30:49827
828 // We should have one browser with 3 tabs, the 3rd selected.
[email protected]0665ebe2013-02-13 09:53:19829 EXPECT_EQ(1u, chrome::GetTotalBrowserCount());
[email protected]ee496952013-01-10 23:17:33830 EXPECT_EQ(3, browser()->tab_strip_model()->count());
831 EXPECT_EQ(2, browser()->tab_strip_model()->active_index());
[email protected]fee320542011-03-02 01:30:49832
833 // Navigate to singleton_url1.
[email protected]78e2edc2012-07-01 23:32:28834 chrome::NavigateParams p(MakeNavigateParams());
[email protected]fee320542011-03-02 01:30:49835 p.disposition = SINGLETON_TAB;
[email protected]a048ad22012-03-23 04:26:56836 p.url = GetClearBrowsingDataURL();
[email protected]78e2edc2012-07-01 23:32:28837 p.window_action = chrome::NavigateParams::SHOW_WINDOW;
838 p.path_behavior = chrome::NavigateParams::IGNORE_AND_STAY_PUT;
839 chrome::Navigate(&p);
[email protected]fee320542011-03-02 01:30:49840
841 // The middle tab should now be selected.
842 EXPECT_EQ(browser(), p.browser);
[email protected]ee496952013-01-10 23:17:33843 EXPECT_EQ(3, browser()->tab_strip_model()->count());
844 EXPECT_EQ(1, browser()->tab_strip_model()->active_index());
[email protected]fee320542011-03-02 01:30:49845 EXPECT_EQ(singleton_url1,
[email protected]ee496952013-01-10 23:17:33846 ShortenUberURL(browser()->tab_strip_model()->
847 GetActiveWebContents()->GetURL()));
[email protected]fee320542011-03-02 01:30:49848}
849
850// This test verifies that constructing params with disposition = SINGLETON_TAB
851// and IGNORE_AND_NAVIGATE will update the current tab's URL if the currently
[email protected]637b3442011-01-10 23:31:48852// selected tab is a match but has a different path.
853IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
854 Disposition_SingletonTabFocused_IgnorePath) {
[email protected]a048ad22012-03-23 04:26:56855 GURL singleton_url_current(GetContentSettingsURL());
[email protected]52877dbc62012-06-29 22:22:03856 chrome::AddSelectedTabWithURL(browser(), singleton_url_current,
857 content::PAGE_TRANSITION_LINK);
[email protected]637b3442011-01-10 23:31:48858
859 // We should have one browser with 2 tabs, the 2nd selected.
[email protected]0665ebe2013-02-13 09:53:19860 EXPECT_EQ(1u, chrome::GetTotalBrowserCount());
[email protected]ee496952013-01-10 23:17:33861 EXPECT_EQ(2, browser()->tab_strip_model()->count());
862 EXPECT_EQ(1, browser()->tab_strip_model()->active_index());
[email protected]637b3442011-01-10 23:31:48863
864 // Navigate to a different settings path.
[email protected]a048ad22012-03-23 04:26:56865 GURL singleton_url_target(GetClearBrowsingDataURL());
[email protected]78e2edc2012-07-01 23:32:28866 chrome::NavigateParams p(MakeNavigateParams());
[email protected]637b3442011-01-10 23:31:48867 p.disposition = SINGLETON_TAB;
868 p.url = singleton_url_target;
[email protected]78e2edc2012-07-01 23:32:28869 p.window_action = chrome::NavigateParams::SHOW_WINDOW;
870 p.path_behavior = chrome::NavigateParams::IGNORE_AND_NAVIGATE;
871 chrome::Navigate(&p);
[email protected]637b3442011-01-10 23:31:48872
873 // The second tab should still be selected, but navigated to the new path.
874 EXPECT_EQ(browser(), p.browser);
[email protected]ee496952013-01-10 23:17:33875 EXPECT_EQ(2, browser()->tab_strip_model()->count());
876 EXPECT_EQ(1, browser()->tab_strip_model()->active_index());
[email protected]637b3442011-01-10 23:31:48877 EXPECT_EQ(singleton_url_target,
[email protected]ee496952013-01-10 23:17:33878 ShortenUberURL(browser()->tab_strip_model()->
879 GetActiveWebContents()->GetURL()));
[email protected]637b3442011-01-10 23:31:48880}
881
[email protected]07afd7c2011-02-17 10:07:11882// This test verifies that constructing params with disposition = SINGLETON_TAB
[email protected]fee320542011-03-02 01:30:49883// and IGNORE_AND_NAVIGATE will open an existing matching tab with a different
884// query.
[email protected]07afd7c2011-02-17 10:07:11885IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
886 Disposition_SingletonTabExisting_IgnoreQuery) {
[email protected]ee496952013-01-10 23:17:33887 int initial_tab_count = browser()->tab_strip_model()->count();
[email protected]07afd7c2011-02-17 10:07:11888 GURL singleton_url_current("chrome://settings/internet");
[email protected]52877dbc62012-06-29 22:22:03889 chrome::AddSelectedTabWithURL(browser(), singleton_url_current,
890 content::PAGE_TRANSITION_LINK);
[email protected]07afd7c2011-02-17 10:07:11891
[email protected]ee496952013-01-10 23:17:33892 EXPECT_EQ(initial_tab_count + 1, browser()->tab_strip_model()->count());
893 EXPECT_EQ(initial_tab_count, browser()->tab_strip_model()->active_index());
[email protected]07afd7c2011-02-17 10:07:11894
895 // Navigate to a different settings path.
896 GURL singleton_url_target(
897 "chrome://settings/internet?"
898 "servicePath=/profile/ethernet_00aa00aa00aa&networkType=1");
[email protected]78e2edc2012-07-01 23:32:28899 chrome::NavigateParams p(MakeNavigateParams());
[email protected]07afd7c2011-02-17 10:07:11900 p.disposition = SINGLETON_TAB;
901 p.url = singleton_url_target;
[email protected]78e2edc2012-07-01 23:32:28902 p.window_action = chrome::NavigateParams::SHOW_WINDOW;
903 p.path_behavior = chrome::NavigateParams::IGNORE_AND_NAVIGATE;
904 chrome::Navigate(&p);
[email protected]07afd7c2011-02-17 10:07:11905
906 // Last tab should still be selected.
907 EXPECT_EQ(browser(), p.browser);
[email protected]ee496952013-01-10 23:17:33908 EXPECT_EQ(initial_tab_count + 1, browser()->tab_strip_model()->count());
909 EXPECT_EQ(initial_tab_count, browser()->tab_strip_model()->active_index());
[email protected]07afd7c2011-02-17 10:07:11910}
911
[email protected]bd817c22011-02-09 08:16:46912// This test verifies that the settings page isn't opened in the incognito
913// window.
[email protected]a048ad22012-03-23 04:26:56914// Disabled until fixed for uber settings: http://crbug.com/111243
[email protected]bd817c22011-02-09 08:16:46915IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
[email protected]a048ad22012-03-23 04:26:56916 DISABLED_Disposition_Settings_UseNonIncognitoWindow) {
[email protected]fc0ed302011-11-29 23:17:19917 RunUseNonIncognitoWindowTest(GetSettingsURL());
[email protected]bd817c22011-02-09 08:16:46918}
919
[email protected]82404cd2011-07-12 19:55:14920// This test verifies that the settings page isn't opened in the incognito
921// window from a non-incognito window (bookmark open-in-incognito trigger).
[email protected]a048ad22012-03-23 04:26:56922// Disabled until fixed for uber settings: http://crbug.com/111243
[email protected]82404cd2011-07-12 19:55:14923IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
[email protected]a048ad22012-03-23 04:26:56924 DISABLED_Disposition_Settings_UseNonIncognitoWindowForBookmark) {
[email protected]78e2edc2012-07-01 23:32:28925 chrome::NavigateParams params(browser(), GetSettingsURL(),
926 content::PAGE_TRANSITION_AUTO_BOOKMARK);
[email protected]82404cd2011-07-12 19:55:14927 params.disposition = OFF_THE_RECORD;
928 {
[email protected]a7fe9112012-07-20 02:34:45929 content::WindowedNotificationObserver observer(
[email protected]ad50def52011-10-19 23:17:07930 content::NOTIFICATION_LOAD_STOP,
931 content::NotificationService::AllSources());
[email protected]78e2edc2012-07-01 23:32:28932 chrome::Navigate(&params);
[email protected]82404cd2011-07-12 19:55:14933 observer.Wait();
934 }
935
[email protected]0665ebe2013-02-13 09:53:19936 EXPECT_EQ(1u, chrome::GetTotalBrowserCount());
[email protected]52877dbc62012-06-29 22:22:03937 EXPECT_EQ(GetSettingsURL(),
[email protected]ee496952013-01-10 23:17:33938 ShortenUberURL(browser()->tab_strip_model()->
939 GetActiveWebContents()->GetURL()));
[email protected]82404cd2011-07-12 19:55:14940}
941
[email protected]93ad8e1c2011-11-08 21:34:05942// Settings page is expected to always open in normal mode regardless
943// of whether the user is trying to open it in incognito mode or not.
944// This test verifies that if incognito mode is forced (by policy), settings
945// page doesn't open at all.
[email protected]a048ad22012-03-23 04:26:56946// Disabled until fixed for uber settings: http://crbug.com/111243
[email protected]93ad8e1c2011-11-08 21:34:05947IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
[email protected]a048ad22012-03-23 04:26:56948 DISABLED_Disposition_Settings_DoNothingIfIncognitoIsForced) {
[email protected]fc0ed302011-11-29 23:17:19949 RunDoNothingIfIncognitoIsForcedTest(GetSettingsURL());
[email protected]93ad8e1c2011-11-08 21:34:05950}
951
[email protected]bd817c22011-02-09 08:16:46952// This test verifies that the bookmarks page isn't opened in the incognito
953// window.
954IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
955 Disposition_Bookmarks_UseNonIncognitoWindow) {
[email protected]fc0ed302011-11-29 23:17:19956 RunUseNonIncognitoWindowTest(GURL(chrome::kChromeUIBookmarksURL));
[email protected]bd817c22011-02-09 08:16:46957}
958
[email protected]93ad8e1c2011-11-08 21:34:05959// Bookmark manager is expected to always open in normal mode regardless
960// of whether the user is trying to open it in incognito mode or not.
961// This test verifies that if incognito mode is forced (by policy), bookmark
962// manager doesn't open at all.
963IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
964 Disposition_Bookmarks_DoNothingIfIncognitoIsForced) {
[email protected]fc0ed302011-11-29 23:17:19965 RunDoNothingIfIncognitoIsForcedTest(GURL(chrome::kChromeUIBookmarksURL));
966}
[email protected]93ad8e1c2011-11-08 21:34:05967
[email protected]fc0ed302011-11-29 23:17:19968// This test verifies that the sync promo page isn't opened in the incognito
969// window.
970IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
971 Disposition_SyncPromo_UseNonIncognitoWindow) {
972 RunUseNonIncognitoWindowTest(GURL(chrome::kChromeUISyncPromoURL));
973}
[email protected]93ad8e1c2011-11-08 21:34:05974
[email protected]fc0ed302011-11-29 23:17:19975// The Sync promo page is expected to always open in normal mode regardless of
976// whether the user is trying to open it in incognito mode or not. This test
977// verifies that if incognito mode is forced (by policy), the sync promo page
978// doesn't open at all.
979IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
980 Disposition_SyncPromo_DoNothingIfIncognitoIsForced) {
981 RunDoNothingIfIncognitoIsForcedTest(GURL(chrome::kChromeUISyncPromoURL));
[email protected]93ad8e1c2011-11-08 21:34:05982}
983
[email protected]7de53c62011-05-13 06:44:16984// This test makes sure a crashed singleton tab reloads from a new navigation.
985IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
986 NavigateToCrashedSingletonTab) {
[email protected]a048ad22012-03-23 04:26:56987 GURL singleton_url(GetContentSettingsURL());
[email protected]5a1a52462012-11-15 03:35:16988 WebContents* web_contents = chrome::AddSelectedTabWithURL(
[email protected]52877dbc62012-06-29 22:22:03989 browser(), singleton_url, content::PAGE_TRANSITION_LINK);
[email protected]7de53c62011-05-13 06:44:16990
991 // We should have one browser with 2 tabs, the 2nd selected.
[email protected]0665ebe2013-02-13 09:53:19992 EXPECT_EQ(1u, chrome::GetTotalBrowserCount());
[email protected]ee496952013-01-10 23:17:33993 EXPECT_EQ(2, browser()->tab_strip_model()->count());
994 EXPECT_EQ(1, browser()->tab_strip_model()->active_index());
[email protected]7de53c62011-05-13 06:44:16995
996 // Kill the singleton tab.
[email protected]83ff91c2012-01-05 20:54:13997 web_contents->SetIsCrashed(base::TERMINATION_STATUS_PROCESS_CRASHED, -1);
998 EXPECT_TRUE(web_contents->IsCrashed());
[email protected]7de53c62011-05-13 06:44:16999
[email protected]78e2edc2012-07-01 23:32:281000 chrome::NavigateParams p(MakeNavigateParams());
[email protected]7de53c62011-05-13 06:44:161001 p.disposition = SINGLETON_TAB;
1002 p.url = singleton_url;
[email protected]78e2edc2012-07-01 23:32:281003 p.window_action = chrome::NavigateParams::SHOW_WINDOW;
1004 p.path_behavior = chrome::NavigateParams::IGNORE_AND_NAVIGATE;
[email protected]ddddfda2011-07-14 23:19:391005 ui_test_utils::NavigateToURL(&p);
[email protected]7de53c62011-05-13 06:44:161006
1007 // The tab should not be sad anymore.
[email protected]83ff91c2012-01-05 20:54:131008 EXPECT_FALSE(web_contents->IsCrashed());
[email protected]7de53c62011-05-13 06:44:161009}
1010
[email protected]fcca741b2011-06-17 22:46:371011IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
1012 NavigateFromDefaultToOptionsInSameTab) {
[email protected]ddddfda2011-07-14 23:19:391013 {
[email protected]a7fe9112012-07-20 02:34:451014 content::WindowedNotificationObserver observer(
[email protected]ad50def52011-10-19 23:17:071015 content::NOTIFICATION_LOAD_STOP,
1016 content::NotificationService::AllSources());
[email protected]5d9cace72012-06-21 16:07:121017 chrome::ShowSettings(browser());
[email protected]ddddfda2011-07-14 23:19:391018 observer.Wait();
1019 }
[email protected]ee496952013-01-10 23:17:331020 EXPECT_EQ(1, browser()->tab_strip_model()->count());
[email protected]52877dbc62012-06-29 22:22:031021 EXPECT_EQ(GetSettingsURL(),
[email protected]ee496952013-01-10 23:17:331022 ShortenUberURL(browser()->tab_strip_model()->
1023 GetActiveWebContents()->GetURL()));
[email protected]fcca741b2011-06-17 22:46:371024}
1025
1026IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
1027 NavigateFromBlankToOptionsInSameTab) {
[email protected]78e2edc2012-07-01 23:32:281028 chrome::NavigateParams p(MakeNavigateParams());
[email protected]ddddfda2011-07-14 23:19:391029 p.url = GURL(chrome::kAboutBlankURL);
1030 ui_test_utils::NavigateToURL(&p);
[email protected]fcca741b2011-06-17 22:46:371031
[email protected]ddddfda2011-07-14 23:19:391032 {
[email protected]a7fe9112012-07-20 02:34:451033 content::WindowedNotificationObserver observer(
[email protected]ad50def52011-10-19 23:17:071034 content::NOTIFICATION_LOAD_STOP,
1035 content::NotificationService::AllSources());
[email protected]5d9cace72012-06-21 16:07:121036 chrome::ShowSettings(browser());
[email protected]ddddfda2011-07-14 23:19:391037 observer.Wait();
1038 }
[email protected]ee496952013-01-10 23:17:331039 EXPECT_EQ(1, browser()->tab_strip_model()->count());
[email protected]52877dbc62012-06-29 22:22:031040 EXPECT_EQ(GetSettingsURL(),
[email protected]ee496952013-01-10 23:17:331041 ShortenUberURL(browser()->tab_strip_model()->
1042 GetActiveWebContents()->GetURL()));
[email protected]fcca741b2011-06-17 22:46:371043}
1044
1045IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
1046 NavigateFromNTPToOptionsInSameTab) {
[email protected]78e2edc2012-07-01 23:32:281047 chrome::NavigateParams p(MakeNavigateParams());
[email protected]ddddfda2011-07-14 23:19:391048 p.url = GURL(chrome::kChromeUINewTabURL);
1049 ui_test_utils::NavigateToURL(&p);
[email protected]ee496952013-01-10 23:17:331050 EXPECT_EQ(1, browser()->tab_strip_model()->count());
[email protected]ddddfda2011-07-14 23:19:391051 EXPECT_EQ(GURL(chrome::kChromeUINewTabURL),
[email protected]ee496952013-01-10 23:17:331052 browser()->tab_strip_model()->GetActiveWebContents()->GetURL());
[email protected]fcca741b2011-06-17 22:46:371053
[email protected]ddddfda2011-07-14 23:19:391054 {
[email protected]a7fe9112012-07-20 02:34:451055 content::WindowedNotificationObserver observer(
[email protected]ad50def52011-10-19 23:17:071056 content::NOTIFICATION_LOAD_STOP,
1057 content::NotificationService::AllSources());
[email protected]5d9cace72012-06-21 16:07:121058 chrome::ShowSettings(browser());
[email protected]ddddfda2011-07-14 23:19:391059 observer.Wait();
1060 }
[email protected]ee496952013-01-10 23:17:331061 EXPECT_EQ(1, browser()->tab_strip_model()->count());
[email protected]52877dbc62012-06-29 22:22:031062 EXPECT_EQ(GetSettingsURL(),
[email protected]ee496952013-01-10 23:17:331063 ShortenUberURL(browser()->tab_strip_model()->
1064 GetActiveWebContents()->GetURL()));
[email protected]fcca741b2011-06-17 22:46:371065}
1066
1067IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
1068 NavigateFromPageToOptionsInNewTab) {
[email protected]78e2edc2012-07-01 23:32:281069 chrome::NavigateParams p(MakeNavigateParams());
[email protected]ddddfda2011-07-14 23:19:391070 ui_test_utils::NavigateToURL(&p);
[email protected]ee496952013-01-10 23:17:331071 EXPECT_EQ(GetGoogleURL(),
1072 browser()->tab_strip_model()->GetActiveWebContents()->GetURL());
[email protected]0665ebe2013-02-13 09:53:191073 EXPECT_EQ(1u, chrome::GetTotalBrowserCount());
[email protected]ee496952013-01-10 23:17:331074 EXPECT_EQ(1, browser()->tab_strip_model()->count());
[email protected]fcca741b2011-06-17 22:46:371075
[email protected]ddddfda2011-07-14 23:19:391076 {
[email protected]a7fe9112012-07-20 02:34:451077 content::WindowedNotificationObserver observer(
[email protected]ad50def52011-10-19 23:17:071078 content::NOTIFICATION_LOAD_STOP,
1079 content::NotificationService::AllSources());
[email protected]5d9cace72012-06-21 16:07:121080 chrome::ShowSettings(browser());
[email protected]ddddfda2011-07-14 23:19:391081 observer.Wait();
1082 }
[email protected]ee496952013-01-10 23:17:331083 EXPECT_EQ(2, browser()->tab_strip_model()->count());
[email protected]52877dbc62012-06-29 22:22:031084 EXPECT_EQ(GetSettingsURL(),
[email protected]ee496952013-01-10 23:17:331085 ShortenUberURL(browser()->tab_strip_model()->
1086 GetActiveWebContents()->GetURL()));
[email protected]fcca741b2011-06-17 22:46:371087}
1088
1089IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
1090 NavigateFromNTPToOptionsSingleton) {
[email protected]ddddfda2011-07-14 23:19:391091 {
[email protected]a7fe9112012-07-20 02:34:451092 content::WindowedNotificationObserver observer(
[email protected]ad50def52011-10-19 23:17:071093 content::NOTIFICATION_LOAD_STOP,
1094 content::NotificationService::AllSources());
[email protected]5d9cace72012-06-21 16:07:121095 chrome::ShowSettings(browser());
[email protected]ddddfda2011-07-14 23:19:391096 observer.Wait();
1097 }
[email protected]ee496952013-01-10 23:17:331098 EXPECT_EQ(1, browser()->tab_strip_model()->count());
[email protected]fcca741b2011-06-17 22:46:371099
[email protected]a37d4b02012-06-25 21:56:101100 chrome::NewTab(browser());
[email protected]ee496952013-01-10 23:17:331101 EXPECT_EQ(2, browser()->tab_strip_model()->count());
[email protected]fcca741b2011-06-17 22:46:371102
[email protected]ddddfda2011-07-14 23:19:391103 {
[email protected]a7fe9112012-07-20 02:34:451104 content::WindowedNotificationObserver observer(
[email protected]ad50def52011-10-19 23:17:071105 content::NOTIFICATION_LOAD_STOP,
1106 content::NotificationService::AllSources());
[email protected]5d9cace72012-06-21 16:07:121107 chrome::ShowSettings(browser());
[email protected]ddddfda2011-07-14 23:19:391108 observer.Wait();
1109 }
[email protected]ee496952013-01-10 23:17:331110 EXPECT_EQ(2, browser()->tab_strip_model()->count());
[email protected]52877dbc62012-06-29 22:22:031111 EXPECT_EQ(GetSettingsURL(),
[email protected]ee496952013-01-10 23:17:331112 ShortenUberURL(browser()->tab_strip_model()->
1113 GetActiveWebContents()->GetURL()));
[email protected]fcca741b2011-06-17 22:46:371114}
1115
1116IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
1117 NavigateFromNTPToOptionsPageInSameTab) {
[email protected]ddddfda2011-07-14 23:19:391118 {
[email protected]a7fe9112012-07-20 02:34:451119 content::WindowedNotificationObserver observer(
[email protected]ad50def52011-10-19 23:17:071120 content::NOTIFICATION_LOAD_STOP,
1121 content::NotificationService::AllSources());
[email protected]5d9cace72012-06-21 16:07:121122 chrome::ShowClearBrowsingDataDialog(browser());
[email protected]ddddfda2011-07-14 23:19:391123 observer.Wait();
1124 }
[email protected]ee496952013-01-10 23:17:331125 EXPECT_EQ(1, browser()->tab_strip_model()->count());
[email protected]a048ad22012-03-23 04:26:561126 EXPECT_EQ(GetClearBrowsingDataURL(),
[email protected]ee496952013-01-10 23:17:331127 browser()->tab_strip_model()->GetActiveWebContents()->GetURL());
[email protected]fcca741b2011-06-17 22:46:371128
[email protected]a37d4b02012-06-25 21:56:101129 chrome::NewTab(browser());
[email protected]ee496952013-01-10 23:17:331130 EXPECT_EQ(2, browser()->tab_strip_model()->count());
[email protected]fcca741b2011-06-17 22:46:371131
[email protected]ddddfda2011-07-14 23:19:391132 {
[email protected]a7fe9112012-07-20 02:34:451133 content::WindowedNotificationObserver observer(
[email protected]ad50def52011-10-19 23:17:071134 content::NOTIFICATION_LOAD_STOP,
1135 content::NotificationService::AllSources());
[email protected]5d9cace72012-06-21 16:07:121136 chrome::ShowClearBrowsingDataDialog(browser());
[email protected]ddddfda2011-07-14 23:19:391137 observer.Wait();
1138 }
[email protected]ee496952013-01-10 23:17:331139 EXPECT_EQ(2, browser()->tab_strip_model()->count());
[email protected]a048ad22012-03-23 04:26:561140 EXPECT_EQ(GetClearBrowsingDataURL(),
[email protected]ee496952013-01-10 23:17:331141 browser()->tab_strip_model()->GetActiveWebContents()->GetURL());
[email protected]fcca741b2011-06-17 22:46:371142}
1143
[email protected]ccb8aac2012-05-21 23:00:161144// Times out on mac, fails on linux.
1145// http://crbug.com/119779
1146#if defined(OS_MACOSX) || defined(OS_LINUX)
[email protected]aac43c72012-03-23 18:41:021147#define MAYBE_NavigateFromOtherTabToSingletonOptions DISABLED_NavigateFromOtherTabToSingletonOptions
1148#else
1149#define MAYBE_NavigateFromOtherTabToSingletonOptions NavigatorFrameOtherTabToSingletonOptions
1150#endif
[email protected]fcca741b2011-06-17 22:46:371151IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
[email protected]aac43c72012-03-23 18:41:021152 MAYBE_NavigateFromOtherTabToSingletonOptions) {
[email protected]ddddfda2011-07-14 23:19:391153 {
[email protected]a7fe9112012-07-20 02:34:451154 content::WindowedNotificationObserver observer(
[email protected]ad50def52011-10-19 23:17:071155 content::NOTIFICATION_LOAD_STOP,
1156 content::NotificationService::AllSources());
[email protected]5d9cace72012-06-21 16:07:121157 chrome::ShowSettings(browser());
[email protected]ddddfda2011-07-14 23:19:391158 observer.Wait();
1159 }
1160 {
[email protected]a7fe9112012-07-20 02:34:451161 content::WindowedNotificationObserver observer(
[email protected]ad50def52011-10-19 23:17:071162 content::NOTIFICATION_LOAD_STOP,
1163 content::NotificationService::AllSources());
[email protected]52877dbc62012-06-29 22:22:031164 chrome::AddSelectedTabWithURL(browser(), GetGoogleURL(),
1165 content::PAGE_TRANSITION_LINK);
[email protected]ddddfda2011-07-14 23:19:391166 observer.Wait();
1167 }
[email protected]fcca741b2011-06-17 22:46:371168
[email protected]ddddfda2011-07-14 23:19:391169 {
[email protected]a7fe9112012-07-20 02:34:451170 content::WindowedNotificationObserver observer(
[email protected]ad50def52011-10-19 23:17:071171 content::NOTIFICATION_LOAD_STOP,
1172 content::NotificationService::AllSources());
[email protected]5d9cace72012-06-21 16:07:121173 chrome::ShowSettings(browser());
[email protected]ddddfda2011-07-14 23:19:391174 observer.Wait();
1175 }
[email protected]ee496952013-01-10 23:17:331176 EXPECT_EQ(2, browser()->tab_strip_model()->count());
[email protected]ddddfda2011-07-14 23:19:391177 EXPECT_EQ(GetSettingsURL(),
[email protected]ee496952013-01-10 23:17:331178 ShortenUberURL(browser()->tab_strip_model()->
1179 GetActiveWebContents()->GetURL()));
[email protected]fcca741b2011-06-17 22:46:371180}
1181
[email protected]a048ad22012-03-23 04:26:561182// TODO(csilv): Update this for uber page. http://crbug.com/111579.
[email protected]ddddfda2011-07-14 23:19:391183IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
[email protected]a048ad22012-03-23 04:26:561184 DISABLED_NavigateFromDefaultToHistoryInSameTab) {
[email protected]ddddfda2011-07-14 23:19:391185 {
[email protected]a7fe9112012-07-20 02:34:451186 content::WindowedNotificationObserver observer(
[email protected]ad50def52011-10-19 23:17:071187 content::NOTIFICATION_LOAD_STOP,
1188 content::NotificationService::AllSources());
[email protected]5d9cace72012-06-21 16:07:121189 chrome::ShowHistory(browser());
[email protected]ddddfda2011-07-14 23:19:391190 observer.Wait();
1191 }
[email protected]ee496952013-01-10 23:17:331192 EXPECT_EQ(1, browser()->tab_strip_model()->count());
[email protected]11e03fb2012-03-03 19:07:051193 EXPECT_EQ(GURL(chrome::kChromeUIHistoryFrameURL),
[email protected]ee496952013-01-10 23:17:331194 browser()->tab_strip_model()->GetActiveWebContents()->GetURL());
[email protected]ddddfda2011-07-14 23:19:391195}
1196
1197IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
1198 NavigateFromDefaultToBookmarksInSameTab) {
1199 {
[email protected]a7fe9112012-07-20 02:34:451200 content::WindowedNotificationObserver observer(
[email protected]ad50def52011-10-19 23:17:071201 content::NOTIFICATION_LOAD_STOP,
1202 content::NotificationService::AllSources());
[email protected]5d9cace72012-06-21 16:07:121203 chrome::ShowBookmarkManager(browser());
[email protected]ddddfda2011-07-14 23:19:391204 observer.Wait();
1205 }
[email protected]ee496952013-01-10 23:17:331206 EXPECT_EQ(1, browser()->tab_strip_model()->count());
[email protected]bc16a252013-01-23 02:21:491207 EXPECT_TRUE(StartsWithASCII(
1208 browser()->tab_strip_model()->GetActiveWebContents()->GetURL().spec(),
1209 chrome::kChromeUIBookmarksURL,
1210 true));
[email protected]ddddfda2011-07-14 23:19:391211}
1212
1213IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
1214 NavigateFromDefaultToDownloadsInSameTab) {
1215 {
[email protected]a7fe9112012-07-20 02:34:451216 content::WindowedNotificationObserver observer(
[email protected]ad50def52011-10-19 23:17:071217 content::NOTIFICATION_LOAD_STOP,
1218 content::NotificationService::AllSources());
[email protected]5d9cace72012-06-21 16:07:121219 chrome::ShowDownloads(browser());
[email protected]ddddfda2011-07-14 23:19:391220 observer.Wait();
1221 }
[email protected]ee496952013-01-10 23:17:331222 EXPECT_EQ(1, browser()->tab_strip_model()->count());
[email protected]ddddfda2011-07-14 23:19:391223 EXPECT_EQ(GURL(chrome::kChromeUIDownloadsURL),
[email protected]ee496952013-01-10 23:17:331224 browser()->tab_strip_model()->GetActiveWebContents()->GetURL());
[email protected]ddddfda2011-07-14 23:19:391225}
1226
[email protected]8fb16a82012-08-17 02:17:591227IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
1228 NavigateWithoutBrowser) {
1229 // First navigate using the profile of the existing browser window, and
1230 // check that the window is reused.
1231 chrome::NavigateParams params(browser()->profile(), GetGoogleURL(),
1232 content::PAGE_TRANSITION_LINK);
1233 ui_test_utils::NavigateToURL(&params);
[email protected]0665ebe2013-02-13 09:53:191234 EXPECT_EQ(1u, chrome::GetTotalBrowserCount());
[email protected]8fb16a82012-08-17 02:17:591235
1236 // Now navigate using the incognito profile and check that a new window
1237 // is created.
1238 chrome::NavigateParams params_incognito(
1239 browser()->profile()->GetOffTheRecordProfile(),
1240 GetGoogleURL(), content::PAGE_TRANSITION_LINK);
1241 ui_test_utils::NavigateToURL(&params_incognito);
[email protected]0665ebe2013-02-13 09:53:191242 EXPECT_EQ(2u, chrome::GetTotalBrowserCount());
[email protected]8fb16a82012-08-17 02:17:591243}
1244
[email protected]ddddfda2011-07-14 23:19:391245} // namespace