blob: 281d33bd5edd7a45b6cff8f2d2942a47e711a7ad [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]26c53e662011-07-09 02:21:028#include "chrome/app/chrome_command_ids.h"
[email protected]93ad8e1c2011-11-08 21:34:059#include "chrome/browser/prefs/incognito_mode_prefs.h"
10#include "chrome/browser/prefs/pref_service.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]bb89e7482010-11-17 18:27:0413#include "chrome/browser/ui/browser_list.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() {
94 return WebContents::Create(
[email protected]bd817c22011-02-09 08:16:4695 browser()->profile(),
96 NULL,
97 MSG_ROUTING_NONE,
[email protected]d1198fd2012-08-13 22:50:1998 chrome::GetActiveWebContents(browser()));
[email protected]bd817c22011-02-09 08:16:4699}
[email protected]a1feae52010-10-11 22:14:45100
[email protected]bd817c22011-02-09 08:16:46101void BrowserNavigatorTest::RunSuppressTest(WindowOpenDisposition disposition) {
[email protected]52877dbc62012-06-29 22:22:03102 GURL old_url = chrome::GetActiveWebContents(browser())->GetURL();
[email protected]78e2edc2012-07-01 23:32:28103 chrome::NavigateParams p(MakeNavigateParams());
[email protected]bd817c22011-02-09 08:16:46104 p.disposition = disposition;
[email protected]78e2edc2012-07-01 23:32:28105 chrome::Navigate(&p);
[email protected]a1feae52010-10-11 22:14:45106
[email protected]bd817c22011-02-09 08:16:46107 // Nothing should have happened as a result of Navigate();
108 EXPECT_EQ(1, browser()->tab_count());
109 EXPECT_EQ(1u, BrowserList::size());
[email protected]52877dbc62012-06-29 22:22:03110 EXPECT_EQ(old_url, chrome::GetActiveWebContents(browser())->GetURL());
[email protected]bd817c22011-02-09 08:16:46111}
[email protected]bb89e7482010-11-17 18:27:04112
[email protected]fc0ed302011-11-29 23:17:19113void BrowserNavigatorTest::RunUseNonIncognitoWindowTest(const GURL& url) {
114 Browser* incognito_browser = CreateIncognitoBrowser();
115
116 EXPECT_EQ(2u, BrowserList::size());
117 EXPECT_EQ(1, browser()->tab_count());
118 EXPECT_EQ(1, incognito_browser->tab_count());
119
120 // Navigate to the page.
[email protected]78e2edc2012-07-01 23:32:28121 chrome::NavigateParams p(MakeNavigateParams(incognito_browser));
[email protected]fc0ed302011-11-29 23:17:19122 p.disposition = SINGLETON_TAB;
123 p.url = url;
[email protected]78e2edc2012-07-01 23:32:28124 p.window_action = chrome::NavigateParams::SHOW_WINDOW;
125 chrome::Navigate(&p);
[email protected]fc0ed302011-11-29 23:17:19126
127 // This page should be opened in browser() window.
128 EXPECT_NE(incognito_browser, p.browser);
129 EXPECT_EQ(browser(), p.browser);
130 EXPECT_EQ(2, browser()->tab_count());
[email protected]52877dbc62012-06-29 22:22:03131 EXPECT_EQ(url, chrome::GetActiveWebContents(browser())->GetURL());
[email protected]fc0ed302011-11-29 23:17:19132}
133
134void BrowserNavigatorTest::RunDoNothingIfIncognitoIsForcedTest(
135 const GURL& url) {
136 Browser* browser = CreateIncognitoBrowser();
137
138 // Set kIncognitoModeAvailability to FORCED.
139 PrefService* prefs1 = browser->profile()->GetPrefs();
140 prefs1->SetInteger(prefs::kIncognitoModeAvailability,
141 IncognitoModePrefs::FORCED);
142 PrefService* prefs2 = browser->profile()->GetOriginalProfile()->GetPrefs();
143 prefs2->SetInteger(prefs::kIncognitoModeAvailability,
144 IncognitoModePrefs::FORCED);
145
146 // Navigate to the page.
[email protected]78e2edc2012-07-01 23:32:28147 chrome::NavigateParams p(MakeNavigateParams(browser));
[email protected]fc0ed302011-11-29 23:17:19148 p.disposition = OFF_THE_RECORD;
149 p.url = url;
[email protected]78e2edc2012-07-01 23:32:28150 p.window_action = chrome::NavigateParams::SHOW_WINDOW;
151 chrome::Navigate(&p);
[email protected]fc0ed302011-11-29 23:17:19152
153 // The page should not be opened.
154 EXPECT_EQ(browser, p.browser);
155 EXPECT_EQ(1, browser->tab_count());
156 EXPECT_EQ(GURL(chrome::kAboutBlankURL),
[email protected]52877dbc62012-06-29 22:22:03157 chrome::GetActiveWebContents(browser)->GetURL());
[email protected]fc0ed302011-11-29 23:17:19158}
159
[email protected]6c2381d2011-10-19 02:52:53160void BrowserNavigatorTest::Observe(
161 int type,
162 const content::NotificationSource& source,
163 const content::NotificationDetails& details) {
[email protected]432115822011-07-10 15:52:27164 switch (type) {
[email protected]d53a08c2012-07-18 20:35:30165 case content::NOTIFICATION_WEB_CONTENTS_RENDER_VIEW_HOST_CREATED: {
[email protected]bd817c22011-02-09 08:16:46166 ++this->created_tab_contents_count_;
167 break;
[email protected]fa7ebe02010-11-29 23:04:57168 }
[email protected]bd817c22011-02-09 08:16:46169 default:
170 break;
[email protected]fa7ebe02010-11-29 23:04:57171 }
[email protected]bd817c22011-02-09 08:16:46172}
[email protected]fa7ebe02010-11-29 23:04:57173
[email protected]ddddfda2011-07-14 23:19:39174
[email protected]bd817c22011-02-09 08:16:46175namespace {
[email protected]a1feae52010-10-11 22:14:45176
[email protected]a1feae52010-10-11 22:14:45177// This test verifies that when a navigation occurs within a tab, the tab count
178// of the Browser remains the same and the current tab bears the loaded URL.
179IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_CurrentTab) {
[email protected]ddddfda2011-07-14 23:19:39180 ui_test_utils::NavigateToURL(browser(), GetGoogleURL());
[email protected]52877dbc62012-06-29 22:22:03181 EXPECT_EQ(GetGoogleURL(), chrome::GetActiveWebContents(browser())->GetURL());
[email protected]a1feae52010-10-11 22:14:45182 // We should have one window with one tab.
183 EXPECT_EQ(1u, BrowserList::size());
184 EXPECT_EQ(1, browser()->tab_count());
185}
186
[email protected]bd817c22011-02-09 08:16:46187// This test verifies that a singleton tab is refocused if one is already opened
[email protected]19d9f3a2010-10-14 21:49:36188// in another or an existing window, or added if it is not.
189IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_SingletonTabExisting) {
[email protected]19d9f3a2010-10-14 21:49:36190 GURL singleton_url1("http://maps.google.com/");
[email protected]fa7ebe02010-11-29 23:04:57191
[email protected]e232c992012-12-06 12:43:20192 // Register for a notification if an additional WebContents was instantiated.
[email protected]bd817c22011-02-09 08:16:46193 // Opening a Singleton tab that is already opened should not be opening a new
[email protected]e232c992012-12-06 12:43:20194 // tab nor be creating a new WebContents object.
[email protected]6c2381d2011-10-19 02:52:53195 content::NotificationRegistrar registrar;
[email protected]fa7ebe02010-11-29 23:04:57196
197 // As the registrar object goes out of scope, this will get unregistered
[email protected]d53a08c2012-07-18 20:35:30198 registrar.Add(this,
199 content::NOTIFICATION_WEB_CONTENTS_RENDER_VIEW_HOST_CREATED,
[email protected]ad50def52011-10-19 23:17:07200 content::NotificationService::AllSources());
[email protected]fa7ebe02010-11-29 23:04:57201
[email protected]52877dbc62012-06-29 22:22:03202 chrome::AddSelectedTabWithURL(browser(), singleton_url1,
203 content::PAGE_TRANSITION_LINK);
204 chrome::AddSelectedTabWithURL(browser(), GetGoogleURL(),
205 content::PAGE_TRANSITION_LINK);
[email protected]19d9f3a2010-10-14 21:49:36206
207 // We should have one browser with 3 tabs, the 3rd selected.
208 EXPECT_EQ(1u, BrowserList::size());
[email protected]1ea49d52011-04-12 17:44:44209 EXPECT_EQ(2, browser()->active_index());
[email protected]19d9f3a2010-10-14 21:49:36210
[email protected]fa7ebe02010-11-29 23:04:57211 unsigned int previous_tab_contents_count =
212 created_tab_contents_count_ = 0;
213
[email protected]19d9f3a2010-10-14 21:49:36214 // Navigate to singleton_url1.
[email protected]78e2edc2012-07-01 23:32:28215 chrome::NavigateParams p(MakeNavigateParams());
[email protected]19d9f3a2010-10-14 21:49:36216 p.disposition = SINGLETON_TAB;
217 p.url = singleton_url1;
[email protected]78e2edc2012-07-01 23:32:28218 chrome::Navigate(&p);
[email protected]19d9f3a2010-10-14 21:49:36219
220 // The middle tab should now be selected.
221 EXPECT_EQ(browser(), p.browser);
[email protected]1ea49d52011-04-12 17:44:44222 EXPECT_EQ(1, browser()->active_index());
[email protected]fa7ebe02010-11-29 23:04:57223
224 // No tab contents should have been created
225 EXPECT_EQ(previous_tab_contents_count,
226 created_tab_contents_count_);
[email protected]19d9f3a2010-10-14 21:49:36227}
228
229IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
[email protected]578c6962011-08-24 22:06:40230 Disposition_SingletonTabRespectingRef) {
231 GURL singleton_ref_url1("http://maps.google.com/#a");
232 GURL singleton_ref_url2("http://maps.google.com/#b");
233 GURL singleton_ref_url3("http://maps.google.com/");
234
[email protected]52877dbc62012-06-29 22:22:03235 chrome::AddSelectedTabWithURL(browser(), singleton_ref_url1,
236 content::PAGE_TRANSITION_LINK);
[email protected]578c6962011-08-24 22:06:40237
238 // We should have one browser with 2 tabs, 2nd selected.
239 EXPECT_EQ(1u, BrowserList::size());
240 EXPECT_EQ(2, browser()->tab_count());
241 EXPECT_EQ(1, browser()->active_index());
242
243 // Navigate to singleton_url2.
[email protected]78e2edc2012-07-01 23:32:28244 chrome::NavigateParams p(MakeNavigateParams());
[email protected]578c6962011-08-24 22:06:40245 p.disposition = SINGLETON_TAB;
246 p.url = singleton_ref_url2;
[email protected]78e2edc2012-07-01 23:32:28247 chrome::Navigate(&p);
[email protected]578c6962011-08-24 22:06:40248
249 // We should now have 2 tabs, the 2nd one selected.
250 EXPECT_EQ(browser(), p.browser);
251 EXPECT_EQ(2, browser()->tab_count());
252 EXPECT_EQ(1, browser()->active_index());
253
254 // Navigate to singleton_url2, but with respect ref set.
255 p = MakeNavigateParams();
256 p.disposition = SINGLETON_TAB;
257 p.url = singleton_ref_url2;
[email protected]78e2edc2012-07-01 23:32:28258 p.ref_behavior = chrome::NavigateParams::RESPECT_REF;
259 chrome::Navigate(&p);
[email protected]578c6962011-08-24 22:06:40260
261 // We should now have 3 tabs, the 3th one selected.
262 EXPECT_EQ(browser(), p.browser);
263 EXPECT_EQ(3, browser()->tab_count());
264 EXPECT_EQ(2, browser()->active_index());
265
266 // Navigate to singleton_url3.
267 p = MakeNavigateParams();
268 p.disposition = SINGLETON_TAB;
269 p.url = singleton_ref_url3;
[email protected]78e2edc2012-07-01 23:32:28270 p.ref_behavior = chrome::NavigateParams::RESPECT_REF;
271 chrome::Navigate(&p);
[email protected]578c6962011-08-24 22:06:40272
273 // We should now have 4 tabs, the 4th one selected.
274 EXPECT_EQ(browser(), p.browser);
275 EXPECT_EQ(4, browser()->tab_count());
276 EXPECT_EQ(3, browser()->active_index());
277}
278
279IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
[email protected]19d9f3a2010-10-14 21:49:36280 Disposition_SingletonTabNoneExisting) {
[email protected]19d9f3a2010-10-14 21:49:36281 GURL singleton_url1("http://maps.google.com/");
282
[email protected]bd817c22011-02-09 08:16:46283 // We should have one browser with 1 tab.
[email protected]19d9f3a2010-10-14 21:49:36284 EXPECT_EQ(1u, BrowserList::size());
[email protected]1ea49d52011-04-12 17:44:44285 EXPECT_EQ(0, browser()->active_index());
[email protected]19d9f3a2010-10-14 21:49:36286
287 // Navigate to singleton_url1.
[email protected]78e2edc2012-07-01 23:32:28288 chrome::NavigateParams p(MakeNavigateParams());
[email protected]19d9f3a2010-10-14 21:49:36289 p.disposition = SINGLETON_TAB;
290 p.url = singleton_url1;
[email protected]78e2edc2012-07-01 23:32:28291 chrome::Navigate(&p);
[email protected]19d9f3a2010-10-14 21:49:36292
293 // We should now have 2 tabs, the 2nd one selected.
294 EXPECT_EQ(browser(), p.browser);
295 EXPECT_EQ(2, browser()->tab_count());
[email protected]1ea49d52011-04-12 17:44:44296 EXPECT_EQ(1, browser()->active_index());
[email protected]a1feae52010-10-11 22:14:45297}
298
299// This test verifies that when a navigation results in a foreground tab, the
300// tab count of the Browser increases and the selected tab shifts to the new
301// foreground tab.
302IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_NewForegroundTab) {
[email protected]52877dbc62012-06-29 22:22:03303 WebContents* old_contents = chrome::GetActiveWebContents(browser());
[email protected]78e2edc2012-07-01 23:32:28304 chrome::NavigateParams p(MakeNavigateParams());
[email protected]a1feae52010-10-11 22:14:45305 p.disposition = NEW_FOREGROUND_TAB;
[email protected]78e2edc2012-07-01 23:32:28306 chrome::Navigate(&p);
[email protected]52877dbc62012-06-29 22:22:03307 EXPECT_NE(old_contents, chrome::GetActiveWebContents(browser()));
[email protected]e232c992012-12-06 12:43:20308 EXPECT_EQ(browser()->tab_strip_model()->GetActiveWebContents(),
[email protected]59253a652012-11-20 00:17:26309 p.target_contents);
[email protected]a1feae52010-10-11 22:14:45310 EXPECT_EQ(2, browser()->tab_count());
311}
312
313// This test verifies that when a navigation results in a background tab, the
314// tab count of the Browser increases but the selected tab remains the same.
315IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_NewBackgroundTab) {
[email protected]52877dbc62012-06-29 22:22:03316 WebContents* old_contents = chrome::GetActiveWebContents(browser());
[email protected]78e2edc2012-07-01 23:32:28317 chrome::NavigateParams p(MakeNavigateParams());
[email protected]a1feae52010-10-11 22:14:45318 p.disposition = NEW_BACKGROUND_TAB;
[email protected]78e2edc2012-07-01 23:32:28319 chrome::Navigate(&p);
[email protected]52877dbc62012-06-29 22:22:03320 WebContents* new_contents = chrome::GetActiveWebContents(browser());
[email protected]a1feae52010-10-11 22:14:45321 // The selected tab should have remained unchanged, since the new tab was
322 // opened in the background.
323 EXPECT_EQ(old_contents, new_contents);
324 EXPECT_EQ(2, browser()->tab_count());
325}
326
327// This test verifies that when a navigation requiring a new foreground tab
328// occurs in a Browser that cannot host multiple tabs, the new foreground tab
329// is created in an existing compatible Browser.
330IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
331 Disposition_IncompatibleWindow_Existing) {
332 // Open a foreground tab in a window that cannot open popups when there is an
333 // existing compatible window somewhere else that they can be opened within.
334 Browser* popup = CreateEmptyBrowserForType(Browser::TYPE_POPUP,
335 browser()->profile());
[email protected]78e2edc2012-07-01 23:32:28336 chrome::NavigateParams p(MakeNavigateParams(popup));
[email protected]a1feae52010-10-11 22:14:45337 p.disposition = NEW_FOREGROUND_TAB;
[email protected]78e2edc2012-07-01 23:32:28338 chrome::Navigate(&p);
[email protected]a1feae52010-10-11 22:14:45339
340 // Navigate() should have opened the tab in a different browser since the
341 // one we supplied didn't support additional tabs.
342 EXPECT_NE(popup, p.browser);
343
344 // Since browser() is an existing compatible tabbed browser, it should have
345 // opened the tab there.
346 EXPECT_EQ(browser(), p.browser);
347
348 // We should be left with 2 windows, the popup with one tab and the browser()
349 // provided by the framework with two.
350 EXPECT_EQ(2u, BrowserList::size());
351 EXPECT_EQ(1, popup->tab_count());
352 EXPECT_EQ(2, browser()->tab_count());
353}
354
355// This test verifies that when a navigation requiring a new foreground tab
356// occurs in a Browser that cannot host multiple tabs and no compatible Browser
357// that can is open, a compatible Browser is created.
358IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
359 Disposition_IncompatibleWindow_NoExisting) {
360 // We want to simulate not being able to find an existing window compatible
361 // with our non-tabbed browser window so Navigate() is forced to create a
362 // new compatible window. Because browser() supplied by the in-process
363 // browser testing framework is compatible with browser()->profile(), we
364 // need a different profile, and creating a popup window with an incognito
365 // profile is a quick and dirty way of achieving this.
366 Browser* popup = CreateEmptyBrowserForType(
[email protected]b35b26b32011-05-05 20:35:14367 Browser::TYPE_POPUP,
368 browser()->profile()->GetOffTheRecordProfile());
[email protected]78e2edc2012-07-01 23:32:28369 chrome::NavigateParams p(MakeNavigateParams(popup));
[email protected]a1feae52010-10-11 22:14:45370 p.disposition = NEW_FOREGROUND_TAB;
[email protected]78e2edc2012-07-01 23:32:28371 chrome::Navigate(&p);
[email protected]a1feae52010-10-11 22:14:45372
373 // Navigate() should have opened the tab in a different browser since the
374 // one we supplied didn't support additional tabs.
375 EXPECT_NE(popup, p.browser);
376
377 // This time, browser() is _not_ compatible with popup since it is not an
378 // incognito window.
379 EXPECT_NE(browser(), p.browser);
380
381 // We should have three windows, each with one tab:
382 // 1. the browser() provided by the framework (unchanged in this test)
383 // 2. the incognito popup we created originally
384 // 3. the new incognito tabbed browser that was created by Navigate().
385 EXPECT_EQ(3u, BrowserList::size());
386 EXPECT_EQ(1, browser()->tab_count());
387 EXPECT_EQ(1, popup->tab_count());
388 EXPECT_EQ(1, p.browser->tab_count());
[email protected]b35b26b32011-05-05 20:35:14389 EXPECT_TRUE(p.browser->is_type_tabbed());
[email protected]a1feae52010-10-11 22:14:45390}
391
392// This test verifies that navigating with WindowOpenDisposition = NEW_POPUP
393// from a normal Browser results in a new Browser with TYPE_POPUP.
394IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_NewPopup) {
[email protected]78e2edc2012-07-01 23:32:28395 chrome::NavigateParams p(MakeNavigateParams());
[email protected]a1feae52010-10-11 22:14:45396 p.disposition = NEW_POPUP;
[email protected]588300d2011-04-28 21:06:35397 p.window_bounds = gfx::Rect(0, 0, 200, 200);
[email protected]7d329992011-04-15 18:20:02398 // Wait for new popup to to load and gain focus.
[email protected]ddddfda2011-07-14 23:19:39399 ui_test_utils::NavigateToURL(&p);
[email protected]a1feae52010-10-11 22:14:45400
[email protected]7d329992011-04-15 18:20:02401 // Navigate() should have opened a new, focused popup window.
[email protected]a1feae52010-10-11 22:14:45402 EXPECT_NE(browser(), p.browser);
[email protected]9db263a2011-04-15 20:53:47403#if 0
404 // TODO(stevenjb): Enable this test. See: crbug.com/79493
[email protected]7d329992011-04-15 18:20:02405 EXPECT_TRUE(p.browser->window()->IsActive());
406#endif
[email protected]b35b26b32011-05-05 20:35:14407 EXPECT_TRUE(p.browser->is_type_popup());
408 EXPECT_FALSE(p.browser->is_app());
[email protected]a1feae52010-10-11 22:14:45409
410 // We should have two windows, the browser() provided by the framework and the
411 // new popup window.
412 EXPECT_EQ(2u, BrowserList::size());
413 EXPECT_EQ(1, browser()->tab_count());
414 EXPECT_EQ(1, p.browser->tab_count());
415}
416
417// This test verifies that navigating with WindowOpenDisposition = NEW_POPUP
[email protected]f112b0f2011-05-26 01:53:52418// from a normal Browser results in a new Browser with is_app() true.
419IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_NewPopup_ExtensionId) {
[email protected]78e2edc2012-07-01 23:32:28420 chrome::NavigateParams p(MakeNavigateParams());
[email protected]f112b0f2011-05-26 01:53:52421 p.disposition = NEW_POPUP;
422 p.extension_app_id = "extensionappid";
423 p.window_bounds = gfx::Rect(0, 0, 200, 200);
[email protected]f112b0f2011-05-26 01:53:52424 // Wait for new popup to to load and gain focus.
[email protected]ddddfda2011-07-14 23:19:39425 ui_test_utils::NavigateToURL(&p);
[email protected]f112b0f2011-05-26 01:53:52426
427 // Navigate() should have opened a new, focused popup window.
428 EXPECT_NE(browser(), p.browser);
429 EXPECT_TRUE(p.browser->is_type_popup());
430 EXPECT_TRUE(p.browser->is_app());
431
432 // We should have two windows, the browser() provided by the framework and the
433 // new popup window.
434 EXPECT_EQ(2u, BrowserList::size());
435 EXPECT_EQ(1, browser()->tab_count());
436 EXPECT_EQ(1, p.browser->tab_count());
437}
438
439// This test verifies that navigating with WindowOpenDisposition = NEW_POPUP
[email protected]300d1e52011-01-19 23:57:57440// from a normal popup results in a new Browser with TYPE_POPUP.
441IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_NewPopupFromPopup) {
442 // Open a popup.
[email protected]78e2edc2012-07-01 23:32:28443 chrome::NavigateParams p1(MakeNavigateParams());
[email protected]300d1e52011-01-19 23:57:57444 p1.disposition = NEW_POPUP;
[email protected]588300d2011-04-28 21:06:35445 p1.window_bounds = gfx::Rect(0, 0, 200, 200);
[email protected]78e2edc2012-07-01 23:32:28446 chrome::Navigate(&p1);
[email protected]300d1e52011-01-19 23:57:57447 // Open another popup.
[email protected]78e2edc2012-07-01 23:32:28448 chrome::NavigateParams p2(MakeNavigateParams(p1.browser));
[email protected]300d1e52011-01-19 23:57:57449 p2.disposition = NEW_POPUP;
[email protected]588300d2011-04-28 21:06:35450 p2.window_bounds = gfx::Rect(0, 0, 200, 200);
[email protected]78e2edc2012-07-01 23:32:28451 chrome::Navigate(&p2);
[email protected]300d1e52011-01-19 23:57:57452
453 // Navigate() should have opened a new normal popup window.
454 EXPECT_NE(p1.browser, p2.browser);
[email protected]b35b26b32011-05-05 20:35:14455 EXPECT_TRUE(p2.browser->is_type_popup());
456 EXPECT_FALSE(p2.browser->is_app());
[email protected]300d1e52011-01-19 23:57:57457
458 // We should have three windows, the browser() provided by the framework,
459 // the first popup window, and the second popup window.
460 EXPECT_EQ(3u, BrowserList::size());
461 EXPECT_EQ(1, browser()->tab_count());
462 EXPECT_EQ(1, p1.browser->tab_count());
463 EXPECT_EQ(1, p2.browser->tab_count());
464}
465
466// This test verifies that navigating with WindowOpenDisposition = NEW_POPUP
[email protected]a1feae52010-10-11 22:14:45467// from an app frame results in a new Browser with TYPE_APP_POPUP.
468IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
469 Disposition_NewPopupFromAppWindow) {
[email protected]b35b26b32011-05-05 20:35:14470 Browser* app_browser = CreateEmptyBrowserForApp(Browser::TYPE_TABBED,
471 browser()->profile());
[email protected]78e2edc2012-07-01 23:32:28472 chrome::NavigateParams p(MakeNavigateParams(app_browser));
[email protected]a1feae52010-10-11 22:14:45473 p.disposition = NEW_POPUP;
[email protected]588300d2011-04-28 21:06:35474 p.window_bounds = gfx::Rect(0, 0, 200, 200);
[email protected]78e2edc2012-07-01 23:32:28475 chrome::Navigate(&p);
[email protected]a1feae52010-10-11 22:14:45476
477 // Navigate() should have opened a new popup app window.
478 EXPECT_NE(app_browser, p.browser);
479 EXPECT_NE(browser(), p.browser);
[email protected]b35b26b32011-05-05 20:35:14480 EXPECT_TRUE(p.browser->is_type_popup());
481 EXPECT_TRUE(p.browser->is_app());
[email protected]a1feae52010-10-11 22:14:45482
483 // We should now have three windows, the app window, the app popup it created,
484 // and the original browser() provided by the framework.
485 EXPECT_EQ(3u, BrowserList::size());
486 EXPECT_EQ(1, browser()->tab_count());
487 EXPECT_EQ(1, app_browser->tab_count());
488 EXPECT_EQ(1, p.browser->tab_count());
489}
490
491// This test verifies that navigating with WindowOpenDisposition = NEW_POPUP
[email protected]300d1e52011-01-19 23:57:57492// from an app popup results in a new Browser also of TYPE_APP_POPUP.
493IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
494 Disposition_NewPopupFromAppPopup) {
[email protected]b35b26b32011-05-05 20:35:14495 Browser* app_browser = CreateEmptyBrowserForApp(Browser::TYPE_TABBED,
496 browser()->profile());
[email protected]300d1e52011-01-19 23:57:57497 // Open an app popup.
[email protected]78e2edc2012-07-01 23:32:28498 chrome::NavigateParams p1(MakeNavigateParams(app_browser));
[email protected]300d1e52011-01-19 23:57:57499 p1.disposition = NEW_POPUP;
[email protected]588300d2011-04-28 21:06:35500 p1.window_bounds = gfx::Rect(0, 0, 200, 200);
[email protected]78e2edc2012-07-01 23:32:28501 chrome::Navigate(&p1);
[email protected]300d1e52011-01-19 23:57:57502 // Now open another app popup.
[email protected]78e2edc2012-07-01 23:32:28503 chrome::NavigateParams p2(MakeNavigateParams(p1.browser));
[email protected]300d1e52011-01-19 23:57:57504 p2.disposition = NEW_POPUP;
[email protected]588300d2011-04-28 21:06:35505 p2.window_bounds = gfx::Rect(0, 0, 200, 200);
[email protected]78e2edc2012-07-01 23:32:28506 chrome::Navigate(&p2);
[email protected]300d1e52011-01-19 23:57:57507
508 // Navigate() should have opened a new popup app window.
509 EXPECT_NE(browser(), p1.browser);
510 EXPECT_NE(p1.browser, p2.browser);
[email protected]b35b26b32011-05-05 20:35:14511 EXPECT_TRUE(p2.browser->is_type_popup());
512 EXPECT_TRUE(p2.browser->is_app());
[email protected]300d1e52011-01-19 23:57:57513
514 // We should now have four windows, the app window, the first app popup,
515 // the second app popup, and the original browser() provided by the framework.
516 EXPECT_EQ(4u, BrowserList::size());
517 EXPECT_EQ(1, browser()->tab_count());
518 EXPECT_EQ(1, app_browser->tab_count());
519 EXPECT_EQ(1, p1.browser->tab_count());
520 EXPECT_EQ(1, p2.browser->tab_count());
521}
522
523// This test verifies that navigating with WindowOpenDisposition = NEW_POPUP
[email protected]a1feae52010-10-11 22:14:45524// from an extension app tab results in a new Browser with TYPE_APP_POPUP.
525IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
526 Disposition_NewPopupFromExtensionApp) {
527 // TODO(beng): TBD.
528}
529
[email protected]7d329992011-04-15 18:20:02530// This test verifies that navigating with window_action = SHOW_WINDOW_INACTIVE
531// does not focus a new new popup window.
532IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_NewPopupUnfocused) {
[email protected]78e2edc2012-07-01 23:32:28533 chrome::NavigateParams p(MakeNavigateParams());
[email protected]7d329992011-04-15 18:20:02534 p.disposition = NEW_POPUP;
[email protected]588300d2011-04-28 21:06:35535 p.window_bounds = gfx::Rect(0, 0, 200, 200);
[email protected]78e2edc2012-07-01 23:32:28536 p.window_action = chrome::NavigateParams::SHOW_WINDOW_INACTIVE;
[email protected]7d329992011-04-15 18:20:02537 // Wait for new popup to load (and gain focus if the test fails).
[email protected]ddddfda2011-07-14 23:19:39538 ui_test_utils::NavigateToURL(&p);
[email protected]7d329992011-04-15 18:20:02539
540 // Navigate() should have opened a new, unfocused, popup window.
541 EXPECT_NE(browser(), p.browser);
542 EXPECT_EQ(Browser::TYPE_POPUP, p.browser->type());
[email protected]9db263a2011-04-15 20:53:47543#if 0
544// TODO(stevenjb): Enable this test. See: crbug.com/79493
[email protected]7d329992011-04-15 18:20:02545 EXPECT_FALSE(p.browser->window()->IsActive());
[email protected]7d329992011-04-15 18:20:02546#endif
[email protected]9db263a2011-04-15 20:53:47547}
[email protected]7d329992011-04-15 18:20:02548
[email protected]a1feae52010-10-11 22:14:45549// This test verifies that navigating with WindowOpenDisposition = NEW_WINDOW
550// always opens a new window.
551IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_NewWindow) {
[email protected]78e2edc2012-07-01 23:32:28552 chrome::NavigateParams p(MakeNavigateParams());
[email protected]a1feae52010-10-11 22:14:45553 p.disposition = NEW_WINDOW;
[email protected]78e2edc2012-07-01 23:32:28554 chrome::Navigate(&p);
[email protected]a1feae52010-10-11 22:14:45555
556 // Navigate() should have opened a new toplevel window.
557 EXPECT_NE(browser(), p.browser);
[email protected]b35b26b32011-05-05 20:35:14558 EXPECT_TRUE(p.browser->is_type_tabbed());
[email protected]a1feae52010-10-11 22:14:45559
560 // We should now have two windows, the browser() provided by the framework and
561 // the new normal window.
562 EXPECT_EQ(2u, BrowserList::size());
563 EXPECT_EQ(1, browser()->tab_count());
564 EXPECT_EQ(1, p.browser->tab_count());
565}
566
567// This test verifies that navigating with WindowOpenDisposition = INCOGNITO
568// opens a new incognito window if no existing incognito window is present.
569IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_Incognito) {
[email protected]78e2edc2012-07-01 23:32:28570 chrome::NavigateParams p(MakeNavigateParams());
[email protected]a1feae52010-10-11 22:14:45571 p.disposition = OFF_THE_RECORD;
[email protected]78e2edc2012-07-01 23:32:28572 chrome::Navigate(&p);
[email protected]a1feae52010-10-11 22:14:45573
574 // Navigate() should have opened a new toplevel incognito window.
575 EXPECT_NE(browser(), p.browser);
576 EXPECT_EQ(browser()->profile()->GetOffTheRecordProfile(),
577 p.browser->profile());
578
[email protected]d7ff3592010-11-30 21:50:46579 // |source_contents| should be set to NULL because the profile for the new
580 // page is different from the originating page.
581 EXPECT_EQ(NULL, p.source_contents);
582
[email protected]a1feae52010-10-11 22:14:45583 // We should now have two windows, the browser() provided by the framework and
584 // the new incognito window.
585 EXPECT_EQ(2u, BrowserList::size());
586 EXPECT_EQ(1, browser()->tab_count());
587 EXPECT_EQ(1, p.browser->tab_count());
588}
589
590// This test verifies that navigating with WindowOpenDisposition = INCOGNITO
591// reuses an existing incognito window when possible.
592IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_IncognitoRefocus) {
593 Browser* incognito_browser =
[email protected]b35b26b32011-05-05 20:35:14594 CreateEmptyBrowserForType(Browser::TYPE_TABBED,
[email protected]a1feae52010-10-11 22:14:45595 browser()->profile()->GetOffTheRecordProfile());
[email protected]78e2edc2012-07-01 23:32:28596 chrome::NavigateParams p(MakeNavigateParams());
[email protected]a1feae52010-10-11 22:14:45597 p.disposition = OFF_THE_RECORD;
[email protected]78e2edc2012-07-01 23:32:28598 chrome::Navigate(&p);
[email protected]a1feae52010-10-11 22:14:45599
600 // Navigate() should have opened a new tab in the existing incognito window.
601 EXPECT_NE(browser(), p.browser);
602 EXPECT_EQ(p.browser, incognito_browser);
603
604 // We should now have two windows, the browser() provided by the framework and
605 // the incognito window we opened earlier.
606 EXPECT_EQ(2u, BrowserList::size());
607 EXPECT_EQ(1, browser()->tab_count());
608 EXPECT_EQ(2, incognito_browser->tab_count());
609}
610
611// This test verifies that no navigation action occurs when
612// WindowOpenDisposition = SUPPRESS_OPEN.
613IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_SuppressOpen) {
614 RunSuppressTest(SUPPRESS_OPEN);
615}
616
617// This test verifies that no navigation action occurs when
618// WindowOpenDisposition = SAVE_TO_DISK.
619IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_SaveToDisk) {
620 RunSuppressTest(SAVE_TO_DISK);
621}
622
623// This test verifies that no navigation action occurs when
624// WindowOpenDisposition = IGNORE_ACTION.
625IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_IgnoreAction) {
626 RunSuppressTest(IGNORE_ACTION);
627}
628
[email protected]e232c992012-12-06 12:43:20629// This tests adding a foreground tab with a predefined WebContents.
[email protected]a1feae52010-10-11 22:14:45630IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, TargetContents_ForegroundTab) {
[email protected]78e2edc2012-07-01 23:32:28631 chrome::NavigateParams p(MakeNavigateParams());
[email protected]a1feae52010-10-11 22:14:45632 p.disposition = NEW_FOREGROUND_TAB;
[email protected]e232c992012-12-06 12:43:20633 p.target_contents = CreateWebContents();
[email protected]78e2edc2012-07-01 23:32:28634 chrome::Navigate(&p);
[email protected]a1feae52010-10-11 22:14:45635
636 // Navigate() should have opened the contents in a new foreground in the
637 // current Browser.
638 EXPECT_EQ(browser(), p.browser);
[email protected]e232c992012-12-06 12:43:20639 EXPECT_EQ(browser()->tab_strip_model()->GetActiveWebContents(),
[email protected]59253a652012-11-20 00:17:26640 p.target_contents);
[email protected]a1feae52010-10-11 22:14:45641
642 // We should have one window, with two tabs.
643 EXPECT_EQ(1u, BrowserList::size());
644 EXPECT_EQ(2, browser()->tab_count());
645}
646
647#if defined(OS_WIN)
[email protected]e232c992012-12-06 12:43:20648// This tests adding a popup with a predefined WebContents.
[email protected]76edb672011-03-04 21:48:39649IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, DISABLED_TargetContents_Popup) {
[email protected]78e2edc2012-07-01 23:32:28650 chrome::NavigateParams p(MakeNavigateParams());
[email protected]a1feae52010-10-11 22:14:45651 p.disposition = NEW_POPUP;
[email protected]e232c992012-12-06 12:43:20652 p.target_contents = CreateWebContents();
[email protected]a1feae52010-10-11 22:14:45653 p.window_bounds = gfx::Rect(10, 10, 500, 500);
[email protected]78e2edc2012-07-01 23:32:28654 chrome::Navigate(&p);
[email protected]a1feae52010-10-11 22:14:45655
656 // Navigate() should have opened a new popup window.
657 EXPECT_NE(browser(), p.browser);
[email protected]b35b26b32011-05-05 20:35:14658 EXPECT_TRUE(p.browser->is_type_popup());
659 EXPECT_FALSE(p.browser->is_app());
[email protected]a1feae52010-10-11 22:14:45660
661 // The web platform is weird. The window bounds specified in
662 // |p.window_bounds| are used as follows:
663 // - the origin is used to position the window
[email protected]e232c992012-12-06 12:43:20664 // - the size is used to size the WebContents of the window.
[email protected]a1feae52010-10-11 22:14:45665 // As such the position of the resulting window will always match
666 // p.window_bounds.origin(), but its size will not. We need to match
667 // the size against the selected tab's view's container size.
668 // Only Windows positions the window according to |p.window_bounds.origin()| -
669 // on Mac the window is offset from the opener and on Linux it always opens
670 // at 0,0.
671 EXPECT_EQ(p.window_bounds.origin(),
672 p.browser->window()->GetRestoredBounds().origin());
673 // All platforms should respect size however provided width > 400 (Mac has a
674 // minimum window width of 400).
675 EXPECT_EQ(p.window_bounds.size(),
[email protected]e232c992012-12-06 12:43:20676 p.target_contents->GetView()->GetContainerSize());
[email protected]a1feae52010-10-11 22:14:45677
678 // We should have two windows, the new popup and the browser() provided by the
679 // framework.
680 EXPECT_EQ(2u, BrowserList::size());
681 EXPECT_EQ(1, browser()->tab_count());
682 EXPECT_EQ(1, p.browser->tab_count());
683}
684#endif
685
686// This tests adding a tab at a specific index.
687IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Tabstrip_InsertAtIndex) {
688 // This is not meant to be a comprehensive test of whether or not the tab
689 // implementation of the browser observes the insertion index. That is
690 // covered by the unit tests for TabStripModel. This merely verifies that
691 // insertion index preference is reflected in common cases.
[email protected]78e2edc2012-07-01 23:32:28692 chrome::NavigateParams p(MakeNavigateParams());
[email protected]a1feae52010-10-11 22:14:45693 p.disposition = NEW_FOREGROUND_TAB;
694 p.tabstrip_index = 0;
695 p.tabstrip_add_types = TabStripModel::ADD_FORCE_INDEX;
[email protected]78e2edc2012-07-01 23:32:28696 chrome::Navigate(&p);
[email protected]a1feae52010-10-11 22:14:45697
698 // Navigate() should have inserted a new tab at slot 0 in the tabstrip.
699 EXPECT_EQ(browser(), p.browser);
[email protected]e232c992012-12-06 12:43:20700 EXPECT_EQ(0, browser()->tab_strip_model()->GetIndexOfWebContents(
701 static_cast<const WebContents*>(p.target_contents)));
[email protected]a1feae52010-10-11 22:14:45702
703 // We should have one window - the browser() provided by the framework.
704 EXPECT_EQ(1u, BrowserList::size());
705 EXPECT_EQ(2, browser()->tab_count());
706}
707
[email protected]bb89e7482010-11-17 18:27:04708// This test verifies that constructing params with disposition = SINGLETON_TAB
[email protected]fee320542011-03-02 01:30:49709// and IGNORE_AND_NAVIGATE opens a new tab navigated to the specified URL if
[email protected]67ed83e2011-01-07 22:54:00710// no previous tab with that URL (minus the path) exists.
[email protected]bb89e7482010-11-17 18:27:04711IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
712 Disposition_SingletonTabNew_IgnorePath) {
[email protected]52877dbc62012-06-29 22:22:03713 chrome::AddSelectedTabWithURL(browser(), GetGoogleURL(),
714 content::PAGE_TRANSITION_LINK);
[email protected]bb89e7482010-11-17 18:27:04715
716 // We should have one browser with 2 tabs, the 2nd selected.
717 EXPECT_EQ(1u, BrowserList::size());
718 EXPECT_EQ(2, browser()->tab_count());
[email protected]1ea49d52011-04-12 17:44:44719 EXPECT_EQ(1, browser()->active_index());
[email protected]bb89e7482010-11-17 18:27:04720
721 // Navigate to a new singleton tab with a sub-page.
[email protected]78e2edc2012-07-01 23:32:28722 chrome::NavigateParams p(MakeNavigateParams());
[email protected]bb89e7482010-11-17 18:27:04723 p.disposition = SINGLETON_TAB;
[email protected]a048ad22012-03-23 04:26:56724 p.url = GetContentSettingsURL();
[email protected]78e2edc2012-07-01 23:32:28725 p.window_action = chrome::NavigateParams::SHOW_WINDOW;
726 p.path_behavior = chrome::NavigateParams::IGNORE_AND_NAVIGATE;
727 chrome::Navigate(&p);
[email protected]bb89e7482010-11-17 18:27:04728
729 // The last tab should now be selected and navigated to the sub-page of the
730 // URL.
731 EXPECT_EQ(browser(), p.browser);
732 EXPECT_EQ(3, browser()->tab_count());
[email protected]1ea49d52011-04-12 17:44:44733 EXPECT_EQ(2, browser()->active_index());
[email protected]a048ad22012-03-23 04:26:56734 EXPECT_EQ(GetContentSettingsURL(),
[email protected]f8f93eb2012-09-25 03:06:24735 ShortenUberURL(chrome::GetActiveWebContents(browser())->GetURL()));
[email protected]bb89e7482010-11-17 18:27:04736}
737
738// This test verifies that constructing params with disposition = SINGLETON_TAB
[email protected]fee320542011-03-02 01:30:49739// and IGNORE_AND_NAVIGATE opens an existing tab with the matching URL (minus
[email protected]bb89e7482010-11-17 18:27:04740// the path) which is navigated to the specified URL.
741IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
742 Disposition_SingletonTabExisting_IgnorePath) {
[email protected]ddddfda2011-07-14 23:19:39743 GURL singleton_url1(GetSettingsURL());
[email protected]52877dbc62012-06-29 22:22:03744 chrome::AddSelectedTabWithURL(browser(), singleton_url1,
745 content::PAGE_TRANSITION_LINK);
746 chrome::AddSelectedTabWithURL(browser(), GetGoogleURL(),
747 content::PAGE_TRANSITION_LINK);
[email protected]bb89e7482010-11-17 18:27:04748
749 // We should have one browser with 3 tabs, the 3rd selected.
750 EXPECT_EQ(1u, BrowserList::size());
751 EXPECT_EQ(3, browser()->tab_count());
[email protected]1ea49d52011-04-12 17:44:44752 EXPECT_EQ(2, browser()->active_index());
[email protected]bb89e7482010-11-17 18:27:04753
754 // Navigate to singleton_url1.
[email protected]78e2edc2012-07-01 23:32:28755 chrome::NavigateParams p(MakeNavigateParams());
[email protected]bb89e7482010-11-17 18:27:04756 p.disposition = SINGLETON_TAB;
[email protected]a048ad22012-03-23 04:26:56757 p.url = GetContentSettingsURL();
[email protected]78e2edc2012-07-01 23:32:28758 p.window_action = chrome::NavigateParams::SHOW_WINDOW;
759 p.path_behavior = chrome::NavigateParams::IGNORE_AND_NAVIGATE;
760 chrome::Navigate(&p);
[email protected]bb89e7482010-11-17 18:27:04761
762 // The middle tab should now be selected and navigated to the sub-page of the
763 // URL.
764 EXPECT_EQ(browser(), p.browser);
765 EXPECT_EQ(3, browser()->tab_count());
[email protected]1ea49d52011-04-12 17:44:44766 EXPECT_EQ(1, browser()->active_index());
[email protected]a048ad22012-03-23 04:26:56767 EXPECT_EQ(GetContentSettingsURL(),
[email protected]f8f93eb2012-09-25 03:06:24768 ShortenUberURL(chrome::GetActiveWebContents(browser())->GetURL()));
[email protected]bb89e7482010-11-17 18:27:04769}
770
771// This test verifies that constructing params with disposition = SINGLETON_TAB
[email protected]fee320542011-03-02 01:30:49772// and IGNORE_AND_NAVIGATE opens an existing tab with the matching URL (minus
[email protected]bb89e7482010-11-17 18:27:04773// the path) which is navigated to the specified URL.
774IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
775 Disposition_SingletonTabExistingSubPath_IgnorePath) {
[email protected]a048ad22012-03-23 04:26:56776 GURL singleton_url1(GetContentSettingsURL());
[email protected]52877dbc62012-06-29 22:22:03777 chrome::AddSelectedTabWithURL(browser(), singleton_url1,
778 content::PAGE_TRANSITION_LINK);
779 chrome::AddSelectedTabWithURL(browser(), GetGoogleURL(),
780 content::PAGE_TRANSITION_LINK);
[email protected]bb89e7482010-11-17 18:27:04781
782 // We should have one browser with 3 tabs, the 3rd selected.
783 EXPECT_EQ(1u, BrowserList::size());
784 EXPECT_EQ(3, browser()->tab_count());
[email protected]1ea49d52011-04-12 17:44:44785 EXPECT_EQ(2, browser()->active_index());
[email protected]bb89e7482010-11-17 18:27:04786
787 // Navigate to singleton_url1.
[email protected]78e2edc2012-07-01 23:32:28788 chrome::NavigateParams p(MakeNavigateParams());
[email protected]bb89e7482010-11-17 18:27:04789 p.disposition = SINGLETON_TAB;
[email protected]a048ad22012-03-23 04:26:56790 p.url = GetClearBrowsingDataURL();
[email protected]78e2edc2012-07-01 23:32:28791 p.window_action = chrome::NavigateParams::SHOW_WINDOW;
792 p.path_behavior = chrome::NavigateParams::IGNORE_AND_NAVIGATE;
793 chrome::Navigate(&p);
[email protected]bb89e7482010-11-17 18:27:04794
795 // The middle tab should now be selected and navigated to the sub-page of the
796 // URL.
797 EXPECT_EQ(browser(), p.browser);
798 EXPECT_EQ(3, browser()->tab_count());
[email protected]1ea49d52011-04-12 17:44:44799 EXPECT_EQ(1, browser()->active_index());
[email protected]a048ad22012-03-23 04:26:56800 EXPECT_EQ(GetClearBrowsingDataURL(),
[email protected]f8f93eb2012-09-25 03:06:24801 ShortenUberURL(chrome::GetActiveWebContents(browser())->GetURL()));
[email protected]bb89e7482010-11-17 18:27:04802}
[email protected]2dd85482010-11-06 01:56:47803
[email protected]637b3442011-01-10 23:31:48804// This test verifies that constructing params with disposition = SINGLETON_TAB
[email protected]fee320542011-03-02 01:30:49805// and IGNORE_AND_STAY_PUT opens an existing tab with the matching URL (minus
806// the path).
807IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
808 Disposition_SingletonTabExistingSubPath_IgnorePath2) {
[email protected]a048ad22012-03-23 04:26:56809 GURL singleton_url1(GetContentSettingsURL());
[email protected]52877dbc62012-06-29 22:22:03810 chrome::AddSelectedTabWithURL(browser(), singleton_url1,
811 content::PAGE_TRANSITION_LINK);
812 chrome::AddSelectedTabWithURL(browser(), GetGoogleURL(),
813 content::PAGE_TRANSITION_LINK);
[email protected]fee320542011-03-02 01:30:49814
815 // We should have one browser with 3 tabs, the 3rd selected.
816 EXPECT_EQ(1u, BrowserList::size());
817 EXPECT_EQ(3, browser()->tab_count());
[email protected]1ea49d52011-04-12 17:44:44818 EXPECT_EQ(2, browser()->active_index());
[email protected]fee320542011-03-02 01:30:49819
820 // Navigate to singleton_url1.
[email protected]78e2edc2012-07-01 23:32:28821 chrome::NavigateParams p(MakeNavigateParams());
[email protected]fee320542011-03-02 01:30:49822 p.disposition = SINGLETON_TAB;
[email protected]a048ad22012-03-23 04:26:56823 p.url = GetClearBrowsingDataURL();
[email protected]78e2edc2012-07-01 23:32:28824 p.window_action = chrome::NavigateParams::SHOW_WINDOW;
825 p.path_behavior = chrome::NavigateParams::IGNORE_AND_STAY_PUT;
826 chrome::Navigate(&p);
[email protected]fee320542011-03-02 01:30:49827
828 // The middle tab should now be selected.
829 EXPECT_EQ(browser(), p.browser);
830 EXPECT_EQ(3, browser()->tab_count());
[email protected]1ea49d52011-04-12 17:44:44831 EXPECT_EQ(1, browser()->active_index());
[email protected]fee320542011-03-02 01:30:49832 EXPECT_EQ(singleton_url1,
[email protected]f8f93eb2012-09-25 03:06:24833 ShortenUberURL(chrome::GetActiveWebContents(browser())->GetURL()));
[email protected]fee320542011-03-02 01:30:49834}
835
836// This test verifies that constructing params with disposition = SINGLETON_TAB
837// and IGNORE_AND_NAVIGATE will update the current tab's URL if the currently
[email protected]637b3442011-01-10 23:31:48838// selected tab is a match but has a different path.
839IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
840 Disposition_SingletonTabFocused_IgnorePath) {
[email protected]a048ad22012-03-23 04:26:56841 GURL singleton_url_current(GetContentSettingsURL());
[email protected]52877dbc62012-06-29 22:22:03842 chrome::AddSelectedTabWithURL(browser(), singleton_url_current,
843 content::PAGE_TRANSITION_LINK);
[email protected]637b3442011-01-10 23:31:48844
845 // We should have one browser with 2 tabs, the 2nd selected.
846 EXPECT_EQ(1u, BrowserList::size());
847 EXPECT_EQ(2, browser()->tab_count());
[email protected]1ea49d52011-04-12 17:44:44848 EXPECT_EQ(1, browser()->active_index());
[email protected]637b3442011-01-10 23:31:48849
850 // Navigate to a different settings path.
[email protected]a048ad22012-03-23 04:26:56851 GURL singleton_url_target(GetClearBrowsingDataURL());
[email protected]78e2edc2012-07-01 23:32:28852 chrome::NavigateParams p(MakeNavigateParams());
[email protected]637b3442011-01-10 23:31:48853 p.disposition = SINGLETON_TAB;
854 p.url = singleton_url_target;
[email protected]78e2edc2012-07-01 23:32:28855 p.window_action = chrome::NavigateParams::SHOW_WINDOW;
856 p.path_behavior = chrome::NavigateParams::IGNORE_AND_NAVIGATE;
857 chrome::Navigate(&p);
[email protected]637b3442011-01-10 23:31:48858
859 // The second tab should still be selected, but navigated to the new path.
860 EXPECT_EQ(browser(), p.browser);
861 EXPECT_EQ(2, browser()->tab_count());
[email protected]1ea49d52011-04-12 17:44:44862 EXPECT_EQ(1, browser()->active_index());
[email protected]637b3442011-01-10 23:31:48863 EXPECT_EQ(singleton_url_target,
[email protected]f8f93eb2012-09-25 03:06:24864 ShortenUberURL(chrome::GetActiveWebContents(browser())->GetURL()));
[email protected]637b3442011-01-10 23:31:48865}
866
[email protected]07afd7c2011-02-17 10:07:11867// This test verifies that constructing params with disposition = SINGLETON_TAB
[email protected]fee320542011-03-02 01:30:49868// and IGNORE_AND_NAVIGATE will open an existing matching tab with a different
869// query.
[email protected]07afd7c2011-02-17 10:07:11870IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
871 Disposition_SingletonTabExisting_IgnoreQuery) {
872 int initial_tab_count = browser()->tab_count();
873 GURL singleton_url_current("chrome://settings/internet");
[email protected]52877dbc62012-06-29 22:22:03874 chrome::AddSelectedTabWithURL(browser(), singleton_url_current,
875 content::PAGE_TRANSITION_LINK);
[email protected]07afd7c2011-02-17 10:07:11876
877 EXPECT_EQ(initial_tab_count + 1, browser()->tab_count());
[email protected]1ea49d52011-04-12 17:44:44878 EXPECT_EQ(initial_tab_count, browser()->active_index());
[email protected]07afd7c2011-02-17 10:07:11879
880 // Navigate to a different settings path.
881 GURL singleton_url_target(
882 "chrome://settings/internet?"
883 "servicePath=/profile/ethernet_00aa00aa00aa&networkType=1");
[email protected]78e2edc2012-07-01 23:32:28884 chrome::NavigateParams p(MakeNavigateParams());
[email protected]07afd7c2011-02-17 10:07:11885 p.disposition = SINGLETON_TAB;
886 p.url = singleton_url_target;
[email protected]78e2edc2012-07-01 23:32:28887 p.window_action = chrome::NavigateParams::SHOW_WINDOW;
888 p.path_behavior = chrome::NavigateParams::IGNORE_AND_NAVIGATE;
889 chrome::Navigate(&p);
[email protected]07afd7c2011-02-17 10:07:11890
891 // Last tab should still be selected.
892 EXPECT_EQ(browser(), p.browser);
893 EXPECT_EQ(initial_tab_count + 1, browser()->tab_count());
[email protected]1ea49d52011-04-12 17:44:44894 EXPECT_EQ(initial_tab_count, browser()->active_index());
[email protected]07afd7c2011-02-17 10:07:11895}
896
[email protected]bd817c22011-02-09 08:16:46897// This test verifies that the settings page isn't opened in the incognito
898// window.
[email protected]a048ad22012-03-23 04:26:56899// Disabled until fixed for uber settings: http://crbug.com/111243
[email protected]bd817c22011-02-09 08:16:46900IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
[email protected]a048ad22012-03-23 04:26:56901 DISABLED_Disposition_Settings_UseNonIncognitoWindow) {
[email protected]fc0ed302011-11-29 23:17:19902 RunUseNonIncognitoWindowTest(GetSettingsURL());
[email protected]bd817c22011-02-09 08:16:46903}
904
[email protected]82404cd2011-07-12 19:55:14905// This test verifies that the settings page isn't opened in the incognito
906// window from a non-incognito window (bookmark open-in-incognito trigger).
[email protected]a048ad22012-03-23 04:26:56907// Disabled until fixed for uber settings: http://crbug.com/111243
[email protected]82404cd2011-07-12 19:55:14908IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
[email protected]a048ad22012-03-23 04:26:56909 DISABLED_Disposition_Settings_UseNonIncognitoWindowForBookmark) {
[email protected]78e2edc2012-07-01 23:32:28910 chrome::NavigateParams params(browser(), GetSettingsURL(),
911 content::PAGE_TRANSITION_AUTO_BOOKMARK);
[email protected]82404cd2011-07-12 19:55:14912 params.disposition = OFF_THE_RECORD;
913 {
[email protected]a7fe9112012-07-20 02:34:45914 content::WindowedNotificationObserver observer(
[email protected]ad50def52011-10-19 23:17:07915 content::NOTIFICATION_LOAD_STOP,
916 content::NotificationService::AllSources());
[email protected]78e2edc2012-07-01 23:32:28917 chrome::Navigate(&params);
[email protected]82404cd2011-07-12 19:55:14918 observer.Wait();
919 }
920
921 EXPECT_EQ(1u, BrowserList::size());
[email protected]52877dbc62012-06-29 22:22:03922 EXPECT_EQ(GetSettingsURL(),
[email protected]f8f93eb2012-09-25 03:06:24923 ShortenUberURL(chrome::GetActiveWebContents(browser())->GetURL()));
[email protected]82404cd2011-07-12 19:55:14924}
925
[email protected]93ad8e1c2011-11-08 21:34:05926// Settings page is expected to always open in normal mode regardless
927// of whether the user is trying to open it in incognito mode or not.
928// This test verifies that if incognito mode is forced (by policy), settings
929// page doesn't open at all.
[email protected]a048ad22012-03-23 04:26:56930// Disabled until fixed for uber settings: http://crbug.com/111243
[email protected]93ad8e1c2011-11-08 21:34:05931IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
[email protected]a048ad22012-03-23 04:26:56932 DISABLED_Disposition_Settings_DoNothingIfIncognitoIsForced) {
[email protected]fc0ed302011-11-29 23:17:19933 RunDoNothingIfIncognitoIsForcedTest(GetSettingsURL());
[email protected]93ad8e1c2011-11-08 21:34:05934}
935
[email protected]bd817c22011-02-09 08:16:46936// This test verifies that the bookmarks page isn't opened in the incognito
937// window.
938IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
939 Disposition_Bookmarks_UseNonIncognitoWindow) {
[email protected]fc0ed302011-11-29 23:17:19940 RunUseNonIncognitoWindowTest(GURL(chrome::kChromeUIBookmarksURL));
[email protected]bd817c22011-02-09 08:16:46941}
942
[email protected]93ad8e1c2011-11-08 21:34:05943// Bookmark manager is expected to always open in normal mode regardless
944// of whether the user is trying to open it in incognito mode or not.
945// This test verifies that if incognito mode is forced (by policy), bookmark
946// manager doesn't open at all.
947IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
948 Disposition_Bookmarks_DoNothingIfIncognitoIsForced) {
[email protected]fc0ed302011-11-29 23:17:19949 RunDoNothingIfIncognitoIsForcedTest(GURL(chrome::kChromeUIBookmarksURL));
950}
[email protected]93ad8e1c2011-11-08 21:34:05951
[email protected]fc0ed302011-11-29 23:17:19952// This test verifies that the sync promo page isn't opened in the incognito
953// window.
954IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
955 Disposition_SyncPromo_UseNonIncognitoWindow) {
956 RunUseNonIncognitoWindowTest(GURL(chrome::kChromeUISyncPromoURL));
957}
[email protected]93ad8e1c2011-11-08 21:34:05958
[email protected]fc0ed302011-11-29 23:17:19959// The Sync promo page is expected to always open in normal mode regardless of
960// whether the user is trying to open it in incognito mode or not. This test
961// verifies that if incognito mode is forced (by policy), the sync promo page
962// doesn't open at all.
963IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
964 Disposition_SyncPromo_DoNothingIfIncognitoIsForced) {
965 RunDoNothingIfIncognitoIsForcedTest(GURL(chrome::kChromeUISyncPromoURL));
[email protected]93ad8e1c2011-11-08 21:34:05966}
967
[email protected]7de53c62011-05-13 06:44:16968// This test makes sure a crashed singleton tab reloads from a new navigation.
969IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
970 NavigateToCrashedSingletonTab) {
[email protected]a048ad22012-03-23 04:26:56971 GURL singleton_url(GetContentSettingsURL());
[email protected]5a1a52462012-11-15 03:35:16972 WebContents* web_contents = chrome::AddSelectedTabWithURL(
[email protected]52877dbc62012-06-29 22:22:03973 browser(), singleton_url, content::PAGE_TRANSITION_LINK);
[email protected]7de53c62011-05-13 06:44:16974
975 // We should have one browser with 2 tabs, the 2nd selected.
976 EXPECT_EQ(1u, BrowserList::size());
977 EXPECT_EQ(2, browser()->tab_count());
978 EXPECT_EQ(1, browser()->active_index());
979
980 // Kill the singleton tab.
[email protected]83ff91c2012-01-05 20:54:13981 web_contents->SetIsCrashed(base::TERMINATION_STATUS_PROCESS_CRASHED, -1);
982 EXPECT_TRUE(web_contents->IsCrashed());
[email protected]7de53c62011-05-13 06:44:16983
[email protected]78e2edc2012-07-01 23:32:28984 chrome::NavigateParams p(MakeNavigateParams());
[email protected]7de53c62011-05-13 06:44:16985 p.disposition = SINGLETON_TAB;
986 p.url = singleton_url;
[email protected]78e2edc2012-07-01 23:32:28987 p.window_action = chrome::NavigateParams::SHOW_WINDOW;
988 p.path_behavior = chrome::NavigateParams::IGNORE_AND_NAVIGATE;
[email protected]ddddfda2011-07-14 23:19:39989 ui_test_utils::NavigateToURL(&p);
[email protected]7de53c62011-05-13 06:44:16990
991 // The tab should not be sad anymore.
[email protected]83ff91c2012-01-05 20:54:13992 EXPECT_FALSE(web_contents->IsCrashed());
[email protected]7de53c62011-05-13 06:44:16993}
994
[email protected]fcca741b2011-06-17 22:46:37995IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
996 NavigateFromDefaultToOptionsInSameTab) {
[email protected]ddddfda2011-07-14 23:19:39997 {
[email protected]a7fe9112012-07-20 02:34:45998 content::WindowedNotificationObserver observer(
[email protected]ad50def52011-10-19 23:17:07999 content::NOTIFICATION_LOAD_STOP,
1000 content::NotificationService::AllSources());
[email protected]5d9cace72012-06-21 16:07:121001 chrome::ShowSettings(browser());
[email protected]ddddfda2011-07-14 23:19:391002 observer.Wait();
1003 }
[email protected]fcca741b2011-06-17 22:46:371004 EXPECT_EQ(1, browser()->tab_count());
[email protected]52877dbc62012-06-29 22:22:031005 EXPECT_EQ(GetSettingsURL(),
[email protected]f8f93eb2012-09-25 03:06:241006 ShortenUberURL(chrome::GetActiveWebContents(browser())->GetURL()));
[email protected]fcca741b2011-06-17 22:46:371007}
1008
1009IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
1010 NavigateFromBlankToOptionsInSameTab) {
[email protected]78e2edc2012-07-01 23:32:281011 chrome::NavigateParams p(MakeNavigateParams());
[email protected]ddddfda2011-07-14 23:19:391012 p.url = GURL(chrome::kAboutBlankURL);
1013 ui_test_utils::NavigateToURL(&p);
[email protected]fcca741b2011-06-17 22:46:371014
[email protected]ddddfda2011-07-14 23:19:391015 {
[email protected]a7fe9112012-07-20 02:34:451016 content::WindowedNotificationObserver observer(
[email protected]ad50def52011-10-19 23:17:071017 content::NOTIFICATION_LOAD_STOP,
1018 content::NotificationService::AllSources());
[email protected]5d9cace72012-06-21 16:07:121019 chrome::ShowSettings(browser());
[email protected]ddddfda2011-07-14 23:19:391020 observer.Wait();
1021 }
[email protected]fcca741b2011-06-17 22:46:371022 EXPECT_EQ(1, browser()->tab_count());
[email protected]52877dbc62012-06-29 22:22:031023 EXPECT_EQ(GetSettingsURL(),
[email protected]f8f93eb2012-09-25 03:06:241024 ShortenUberURL(chrome::GetActiveWebContents(browser())->GetURL()));
[email protected]fcca741b2011-06-17 22:46:371025}
1026
1027IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
1028 NavigateFromNTPToOptionsInSameTab) {
[email protected]78e2edc2012-07-01 23:32:281029 chrome::NavigateParams p(MakeNavigateParams());
[email protected]ddddfda2011-07-14 23:19:391030 p.url = GURL(chrome::kChromeUINewTabURL);
1031 ui_test_utils::NavigateToURL(&p);
[email protected]fcca741b2011-06-17 22:46:371032 EXPECT_EQ(1, browser()->tab_count());
[email protected]ddddfda2011-07-14 23:19:391033 EXPECT_EQ(GURL(chrome::kChromeUINewTabURL),
[email protected]52877dbc62012-06-29 22:22:031034 chrome::GetActiveWebContents(browser())->GetURL());
[email protected]fcca741b2011-06-17 22:46:371035
[email protected]ddddfda2011-07-14 23:19:391036 {
[email protected]a7fe9112012-07-20 02:34:451037 content::WindowedNotificationObserver observer(
[email protected]ad50def52011-10-19 23:17:071038 content::NOTIFICATION_LOAD_STOP,
1039 content::NotificationService::AllSources());
[email protected]5d9cace72012-06-21 16:07:121040 chrome::ShowSettings(browser());
[email protected]ddddfda2011-07-14 23:19:391041 observer.Wait();
1042 }
[email protected]fcca741b2011-06-17 22:46:371043 EXPECT_EQ(1, browser()->tab_count());
[email protected]52877dbc62012-06-29 22:22:031044 EXPECT_EQ(GetSettingsURL(),
[email protected]f8f93eb2012-09-25 03:06:241045 ShortenUberURL(chrome::GetActiveWebContents(browser())->GetURL()));
[email protected]fcca741b2011-06-17 22:46:371046}
1047
1048IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
1049 NavigateFromPageToOptionsInNewTab) {
[email protected]78e2edc2012-07-01 23:32:281050 chrome::NavigateParams p(MakeNavigateParams());
[email protected]ddddfda2011-07-14 23:19:391051 ui_test_utils::NavigateToURL(&p);
[email protected]52877dbc62012-06-29 22:22:031052 EXPECT_EQ(GetGoogleURL(), chrome::GetActiveWebContents(browser())->GetURL());
[email protected]fcca741b2011-06-17 22:46:371053 EXPECT_EQ(1u, BrowserList::size());
1054 EXPECT_EQ(1, browser()->tab_count());
1055
[email protected]ddddfda2011-07-14 23:19:391056 {
[email protected]a7fe9112012-07-20 02:34:451057 content::WindowedNotificationObserver observer(
[email protected]ad50def52011-10-19 23:17:071058 content::NOTIFICATION_LOAD_STOP,
1059 content::NotificationService::AllSources());
[email protected]5d9cace72012-06-21 16:07:121060 chrome::ShowSettings(browser());
[email protected]ddddfda2011-07-14 23:19:391061 observer.Wait();
1062 }
[email protected]fcca741b2011-06-17 22:46:371063 EXPECT_EQ(2, browser()->tab_count());
[email protected]52877dbc62012-06-29 22:22:031064 EXPECT_EQ(GetSettingsURL(),
[email protected]f8f93eb2012-09-25 03:06:241065 ShortenUberURL(chrome::GetActiveWebContents(browser())->GetURL()));
[email protected]fcca741b2011-06-17 22:46:371066}
1067
1068IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
1069 NavigateFromNTPToOptionsSingleton) {
[email protected]ddddfda2011-07-14 23:19:391070 {
[email protected]a7fe9112012-07-20 02:34:451071 content::WindowedNotificationObserver observer(
[email protected]ad50def52011-10-19 23:17:071072 content::NOTIFICATION_LOAD_STOP,
1073 content::NotificationService::AllSources());
[email protected]5d9cace72012-06-21 16:07:121074 chrome::ShowSettings(browser());
[email protected]ddddfda2011-07-14 23:19:391075 observer.Wait();
1076 }
[email protected]fcca741b2011-06-17 22:46:371077 EXPECT_EQ(1, browser()->tab_count());
1078
[email protected]a37d4b02012-06-25 21:56:101079 chrome::NewTab(browser());
[email protected]fcca741b2011-06-17 22:46:371080 EXPECT_EQ(2, browser()->tab_count());
1081
[email protected]ddddfda2011-07-14 23:19:391082 {
[email protected]a7fe9112012-07-20 02:34:451083 content::WindowedNotificationObserver observer(
[email protected]ad50def52011-10-19 23:17:071084 content::NOTIFICATION_LOAD_STOP,
1085 content::NotificationService::AllSources());
[email protected]5d9cace72012-06-21 16:07:121086 chrome::ShowSettings(browser());
[email protected]ddddfda2011-07-14 23:19:391087 observer.Wait();
1088 }
[email protected]fcca741b2011-06-17 22:46:371089 EXPECT_EQ(2, browser()->tab_count());
[email protected]52877dbc62012-06-29 22:22:031090 EXPECT_EQ(GetSettingsURL(),
[email protected]f8f93eb2012-09-25 03:06:241091 ShortenUberURL(chrome::GetActiveWebContents(browser())->GetURL()));
[email protected]fcca741b2011-06-17 22:46:371092}
1093
1094IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
1095 NavigateFromNTPToOptionsPageInSameTab) {
[email protected]ddddfda2011-07-14 23:19:391096 {
[email protected]a7fe9112012-07-20 02:34:451097 content::WindowedNotificationObserver observer(
[email protected]ad50def52011-10-19 23:17:071098 content::NOTIFICATION_LOAD_STOP,
1099 content::NotificationService::AllSources());
[email protected]5d9cace72012-06-21 16:07:121100 chrome::ShowClearBrowsingDataDialog(browser());
[email protected]ddddfda2011-07-14 23:19:391101 observer.Wait();
1102 }
[email protected]fcca741b2011-06-17 22:46:371103 EXPECT_EQ(1, browser()->tab_count());
[email protected]a048ad22012-03-23 04:26:561104 EXPECT_EQ(GetClearBrowsingDataURL(),
[email protected]52877dbc62012-06-29 22:22:031105 chrome::GetActiveWebContents(browser())->GetURL());
[email protected]fcca741b2011-06-17 22:46:371106
[email protected]a37d4b02012-06-25 21:56:101107 chrome::NewTab(browser());
[email protected]fcca741b2011-06-17 22:46:371108 EXPECT_EQ(2, browser()->tab_count());
1109
[email protected]ddddfda2011-07-14 23:19:391110 {
[email protected]a7fe9112012-07-20 02:34:451111 content::WindowedNotificationObserver observer(
[email protected]ad50def52011-10-19 23:17:071112 content::NOTIFICATION_LOAD_STOP,
1113 content::NotificationService::AllSources());
[email protected]5d9cace72012-06-21 16:07:121114 chrome::ShowClearBrowsingDataDialog(browser());
[email protected]ddddfda2011-07-14 23:19:391115 observer.Wait();
1116 }
[email protected]fcca741b2011-06-17 22:46:371117 EXPECT_EQ(2, browser()->tab_count());
[email protected]a048ad22012-03-23 04:26:561118 EXPECT_EQ(GetClearBrowsingDataURL(),
[email protected]52877dbc62012-06-29 22:22:031119 chrome::GetActiveWebContents(browser())->GetURL());
[email protected]fcca741b2011-06-17 22:46:371120}
1121
[email protected]ccb8aac2012-05-21 23:00:161122// Times out on mac, fails on linux.
1123// http://crbug.com/119779
1124#if defined(OS_MACOSX) || defined(OS_LINUX)
[email protected]aac43c72012-03-23 18:41:021125#define MAYBE_NavigateFromOtherTabToSingletonOptions DISABLED_NavigateFromOtherTabToSingletonOptions
1126#else
1127#define MAYBE_NavigateFromOtherTabToSingletonOptions NavigatorFrameOtherTabToSingletonOptions
1128#endif
[email protected]fcca741b2011-06-17 22:46:371129IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
[email protected]aac43c72012-03-23 18:41:021130 MAYBE_NavigateFromOtherTabToSingletonOptions) {
[email protected]ddddfda2011-07-14 23:19:391131 {
[email protected]a7fe9112012-07-20 02:34:451132 content::WindowedNotificationObserver observer(
[email protected]ad50def52011-10-19 23:17:071133 content::NOTIFICATION_LOAD_STOP,
1134 content::NotificationService::AllSources());
[email protected]5d9cace72012-06-21 16:07:121135 chrome::ShowSettings(browser());
[email protected]ddddfda2011-07-14 23:19:391136 observer.Wait();
1137 }
1138 {
[email protected]a7fe9112012-07-20 02:34:451139 content::WindowedNotificationObserver observer(
[email protected]ad50def52011-10-19 23:17:071140 content::NOTIFICATION_LOAD_STOP,
1141 content::NotificationService::AllSources());
[email protected]52877dbc62012-06-29 22:22:031142 chrome::AddSelectedTabWithURL(browser(), GetGoogleURL(),
1143 content::PAGE_TRANSITION_LINK);
[email protected]ddddfda2011-07-14 23:19:391144 observer.Wait();
1145 }
[email protected]fcca741b2011-06-17 22:46:371146
[email protected]ddddfda2011-07-14 23:19:391147 {
[email protected]a7fe9112012-07-20 02:34:451148 content::WindowedNotificationObserver observer(
[email protected]ad50def52011-10-19 23:17:071149 content::NOTIFICATION_LOAD_STOP,
1150 content::NotificationService::AllSources());
[email protected]5d9cace72012-06-21 16:07:121151 chrome::ShowSettings(browser());
[email protected]ddddfda2011-07-14 23:19:391152 observer.Wait();
1153 }
[email protected]fcca741b2011-06-17 22:46:371154 EXPECT_EQ(2, browser()->tab_count());
[email protected]ddddfda2011-07-14 23:19:391155 EXPECT_EQ(GetSettingsURL(),
[email protected]f8f93eb2012-09-25 03:06:241156 ShortenUberURL(chrome::GetActiveWebContents(browser())->GetURL()));
[email protected]fcca741b2011-06-17 22:46:371157}
1158
[email protected]a048ad22012-03-23 04:26:561159// TODO(csilv): Update this for uber page. http://crbug.com/111579.
[email protected]ddddfda2011-07-14 23:19:391160IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
[email protected]a048ad22012-03-23 04:26:561161 DISABLED_NavigateFromDefaultToHistoryInSameTab) {
[email protected]ddddfda2011-07-14 23:19:391162 {
[email protected]a7fe9112012-07-20 02:34:451163 content::WindowedNotificationObserver observer(
[email protected]ad50def52011-10-19 23:17:071164 content::NOTIFICATION_LOAD_STOP,
1165 content::NotificationService::AllSources());
[email protected]5d9cace72012-06-21 16:07:121166 chrome::ShowHistory(browser());
[email protected]ddddfda2011-07-14 23:19:391167 observer.Wait();
1168 }
1169 EXPECT_EQ(1, browser()->tab_count());
[email protected]11e03fb2012-03-03 19:07:051170 EXPECT_EQ(GURL(chrome::kChromeUIHistoryFrameURL),
[email protected]52877dbc62012-06-29 22:22:031171 chrome::GetActiveWebContents(browser())->GetURL());
[email protected]ddddfda2011-07-14 23:19:391172}
1173
1174IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
1175 NavigateFromDefaultToBookmarksInSameTab) {
1176 {
[email protected]a7fe9112012-07-20 02:34:451177 content::WindowedNotificationObserver observer(
[email protected]ad50def52011-10-19 23:17:071178 content::NOTIFICATION_LOAD_STOP,
1179 content::NotificationService::AllSources());
[email protected]5d9cace72012-06-21 16:07:121180 chrome::ShowBookmarkManager(browser());
[email protected]ddddfda2011-07-14 23:19:391181 observer.Wait();
1182 }
1183 EXPECT_EQ(1, browser()->tab_count());
1184 EXPECT_EQ(GURL(chrome::kChromeUIBookmarksURL),
[email protected]52877dbc62012-06-29 22:22:031185 chrome::GetActiveWebContents(browser())->GetURL());
[email protected]ddddfda2011-07-14 23:19:391186}
1187
1188IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
1189 NavigateFromDefaultToDownloadsInSameTab) {
1190 {
[email protected]a7fe9112012-07-20 02:34:451191 content::WindowedNotificationObserver observer(
[email protected]ad50def52011-10-19 23:17:071192 content::NOTIFICATION_LOAD_STOP,
1193 content::NotificationService::AllSources());
[email protected]5d9cace72012-06-21 16:07:121194 chrome::ShowDownloads(browser());
[email protected]ddddfda2011-07-14 23:19:391195 observer.Wait();
1196 }
1197 EXPECT_EQ(1, browser()->tab_count());
1198 EXPECT_EQ(GURL(chrome::kChromeUIDownloadsURL),
[email protected]52877dbc62012-06-29 22:22:031199 chrome::GetActiveWebContents(browser())->GetURL());
[email protected]ddddfda2011-07-14 23:19:391200}
1201
[email protected]8fb16a82012-08-17 02:17:591202IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
1203 NavigateWithoutBrowser) {
1204 // First navigate using the profile of the existing browser window, and
1205 // check that the window is reused.
1206 chrome::NavigateParams params(browser()->profile(), GetGoogleURL(),
1207 content::PAGE_TRANSITION_LINK);
1208 ui_test_utils::NavigateToURL(&params);
1209 EXPECT_EQ(1u, BrowserList::size());
1210
1211 // Now navigate using the incognito profile and check that a new window
1212 // is created.
1213 chrome::NavigateParams params_incognito(
1214 browser()->profile()->GetOffTheRecordProfile(),
1215 GetGoogleURL(), content::PAGE_TRANSITION_LINK);
1216 ui_test_utils::NavigateToURL(&params_incognito);
1217 EXPECT_EQ(2u, BrowserList::size());
1218}
1219
[email protected]ddddfda2011-07-14 23:19:391220} // namespace