blob: d59acf005b08d3a1509c506d68a749af0001174e [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() {
[email protected]54944cde2012-12-09 09:24:5994 content::WebContents::CreateParams create_params(browser()->profile());
95 create_params.base_web_contents = chrome::GetActiveWebContents(browser());
96 return WebContents::Create(create_params);
[email protected]bd817c22011-02-09 08:16:4697}
[email protected]a1feae52010-10-11 22:14:4598
[email protected]bd817c22011-02-09 08:16:4699void BrowserNavigatorTest::RunSuppressTest(WindowOpenDisposition disposition) {
[email protected]52877dbc62012-06-29 22:22:03100 GURL old_url = chrome::GetActiveWebContents(browser())->GetURL();
[email protected]78e2edc2012-07-01 23:32:28101 chrome::NavigateParams p(MakeNavigateParams());
[email protected]bd817c22011-02-09 08:16:46102 p.disposition = disposition;
[email protected]78e2edc2012-07-01 23:32:28103 chrome::Navigate(&p);
[email protected]a1feae52010-10-11 22:14:45104
[email protected]bd817c22011-02-09 08:16:46105 // Nothing should have happened as a result of Navigate();
106 EXPECT_EQ(1, browser()->tab_count());
107 EXPECT_EQ(1u, BrowserList::size());
[email protected]52877dbc62012-06-29 22:22:03108 EXPECT_EQ(old_url, chrome::GetActiveWebContents(browser())->GetURL());
[email protected]bd817c22011-02-09 08:16:46109}
[email protected]bb89e7482010-11-17 18:27:04110
[email protected]fc0ed302011-11-29 23:17:19111void BrowserNavigatorTest::RunUseNonIncognitoWindowTest(const GURL& url) {
112 Browser* incognito_browser = CreateIncognitoBrowser();
113
114 EXPECT_EQ(2u, BrowserList::size());
115 EXPECT_EQ(1, browser()->tab_count());
116 EXPECT_EQ(1, incognito_browser->tab_count());
117
118 // Navigate to the page.
[email protected]78e2edc2012-07-01 23:32:28119 chrome::NavigateParams p(MakeNavigateParams(incognito_browser));
[email protected]fc0ed302011-11-29 23:17:19120 p.disposition = SINGLETON_TAB;
121 p.url = url;
[email protected]78e2edc2012-07-01 23:32:28122 p.window_action = chrome::NavigateParams::SHOW_WINDOW;
123 chrome::Navigate(&p);
[email protected]fc0ed302011-11-29 23:17:19124
125 // This page should be opened in browser() window.
126 EXPECT_NE(incognito_browser, p.browser);
127 EXPECT_EQ(browser(), p.browser);
128 EXPECT_EQ(2, browser()->tab_count());
[email protected]52877dbc62012-06-29 22:22:03129 EXPECT_EQ(url, chrome::GetActiveWebContents(browser())->GetURL());
[email protected]fc0ed302011-11-29 23:17:19130}
131
132void BrowserNavigatorTest::RunDoNothingIfIncognitoIsForcedTest(
133 const GURL& url) {
134 Browser* browser = CreateIncognitoBrowser();
135
136 // Set kIncognitoModeAvailability to FORCED.
137 PrefService* prefs1 = browser->profile()->GetPrefs();
138 prefs1->SetInteger(prefs::kIncognitoModeAvailability,
139 IncognitoModePrefs::FORCED);
140 PrefService* prefs2 = browser->profile()->GetOriginalProfile()->GetPrefs();
141 prefs2->SetInteger(prefs::kIncognitoModeAvailability,
142 IncognitoModePrefs::FORCED);
143
144 // Navigate to the page.
[email protected]78e2edc2012-07-01 23:32:28145 chrome::NavigateParams p(MakeNavigateParams(browser));
[email protected]fc0ed302011-11-29 23:17:19146 p.disposition = OFF_THE_RECORD;
147 p.url = url;
[email protected]78e2edc2012-07-01 23:32:28148 p.window_action = chrome::NavigateParams::SHOW_WINDOW;
149 chrome::Navigate(&p);
[email protected]fc0ed302011-11-29 23:17:19150
151 // The page should not be opened.
152 EXPECT_EQ(browser, p.browser);
153 EXPECT_EQ(1, browser->tab_count());
154 EXPECT_EQ(GURL(chrome::kAboutBlankURL),
[email protected]52877dbc62012-06-29 22:22:03155 chrome::GetActiveWebContents(browser)->GetURL());
[email protected]fc0ed302011-11-29 23:17:19156}
157
[email protected]6c2381d2011-10-19 02:52:53158void BrowserNavigatorTest::Observe(
159 int type,
160 const content::NotificationSource& source,
161 const content::NotificationDetails& details) {
[email protected]432115822011-07-10 15:52:27162 switch (type) {
[email protected]d53a08c2012-07-18 20:35:30163 case content::NOTIFICATION_WEB_CONTENTS_RENDER_VIEW_HOST_CREATED: {
[email protected]bd817c22011-02-09 08:16:46164 ++this->created_tab_contents_count_;
165 break;
[email protected]fa7ebe02010-11-29 23:04:57166 }
[email protected]bd817c22011-02-09 08:16:46167 default:
168 break;
[email protected]fa7ebe02010-11-29 23:04:57169 }
[email protected]bd817c22011-02-09 08:16:46170}
[email protected]fa7ebe02010-11-29 23:04:57171
[email protected]ddddfda2011-07-14 23:19:39172
[email protected]bd817c22011-02-09 08:16:46173namespace {
[email protected]a1feae52010-10-11 22:14:45174
[email protected]a1feae52010-10-11 22:14:45175// This test verifies that when a navigation occurs within a tab, the tab count
176// of the Browser remains the same and the current tab bears the loaded URL.
177IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_CurrentTab) {
[email protected]ddddfda2011-07-14 23:19:39178 ui_test_utils::NavigateToURL(browser(), GetGoogleURL());
[email protected]52877dbc62012-06-29 22:22:03179 EXPECT_EQ(GetGoogleURL(), chrome::GetActiveWebContents(browser())->GetURL());
[email protected]a1feae52010-10-11 22:14:45180 // We should have one window with one tab.
181 EXPECT_EQ(1u, BrowserList::size());
182 EXPECT_EQ(1, browser()->tab_count());
183}
184
[email protected]bd817c22011-02-09 08:16:46185// This test verifies that a singleton tab is refocused if one is already opened
[email protected]19d9f3a2010-10-14 21:49:36186// in another or an existing window, or added if it is not.
187IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_SingletonTabExisting) {
[email protected]19d9f3a2010-10-14 21:49:36188 GURL singleton_url1("http://maps.google.com/");
[email protected]fa7ebe02010-11-29 23:04:57189
[email protected]e232c992012-12-06 12:43:20190 // Register for a notification if an additional WebContents was instantiated.
[email protected]bd817c22011-02-09 08:16:46191 // Opening a Singleton tab that is already opened should not be opening a new
[email protected]e232c992012-12-06 12:43:20192 // tab nor be creating a new WebContents object.
[email protected]6c2381d2011-10-19 02:52:53193 content::NotificationRegistrar registrar;
[email protected]fa7ebe02010-11-29 23:04:57194
195 // As the registrar object goes out of scope, this will get unregistered
[email protected]d53a08c2012-07-18 20:35:30196 registrar.Add(this,
197 content::NOTIFICATION_WEB_CONTENTS_RENDER_VIEW_HOST_CREATED,
[email protected]ad50def52011-10-19 23:17:07198 content::NotificationService::AllSources());
[email protected]fa7ebe02010-11-29 23:04:57199
[email protected]52877dbc62012-06-29 22:22:03200 chrome::AddSelectedTabWithURL(browser(), singleton_url1,
201 content::PAGE_TRANSITION_LINK);
202 chrome::AddSelectedTabWithURL(browser(), GetGoogleURL(),
203 content::PAGE_TRANSITION_LINK);
[email protected]19d9f3a2010-10-14 21:49:36204
205 // We should have one browser with 3 tabs, the 3rd selected.
206 EXPECT_EQ(1u, BrowserList::size());
[email protected]1ea49d52011-04-12 17:44:44207 EXPECT_EQ(2, browser()->active_index());
[email protected]19d9f3a2010-10-14 21:49:36208
[email protected]fa7ebe02010-11-29 23:04:57209 unsigned int previous_tab_contents_count =
210 created_tab_contents_count_ = 0;
211
[email protected]19d9f3a2010-10-14 21:49:36212 // Navigate to singleton_url1.
[email protected]78e2edc2012-07-01 23:32:28213 chrome::NavigateParams p(MakeNavigateParams());
[email protected]19d9f3a2010-10-14 21:49:36214 p.disposition = SINGLETON_TAB;
215 p.url = singleton_url1;
[email protected]78e2edc2012-07-01 23:32:28216 chrome::Navigate(&p);
[email protected]19d9f3a2010-10-14 21:49:36217
218 // The middle tab should now be selected.
219 EXPECT_EQ(browser(), p.browser);
[email protected]1ea49d52011-04-12 17:44:44220 EXPECT_EQ(1, browser()->active_index());
[email protected]fa7ebe02010-11-29 23:04:57221
222 // No tab contents should have been created
223 EXPECT_EQ(previous_tab_contents_count,
224 created_tab_contents_count_);
[email protected]19d9f3a2010-10-14 21:49:36225}
226
227IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
[email protected]578c6962011-08-24 22:06:40228 Disposition_SingletonTabRespectingRef) {
229 GURL singleton_ref_url1("http://maps.google.com/#a");
230 GURL singleton_ref_url2("http://maps.google.com/#b");
231 GURL singleton_ref_url3("http://maps.google.com/");
232
[email protected]52877dbc62012-06-29 22:22:03233 chrome::AddSelectedTabWithURL(browser(), singleton_ref_url1,
234 content::PAGE_TRANSITION_LINK);
[email protected]578c6962011-08-24 22:06:40235
236 // We should have one browser with 2 tabs, 2nd selected.
237 EXPECT_EQ(1u, BrowserList::size());
238 EXPECT_EQ(2, browser()->tab_count());
239 EXPECT_EQ(1, browser()->active_index());
240
241 // Navigate to singleton_url2.
[email protected]78e2edc2012-07-01 23:32:28242 chrome::NavigateParams p(MakeNavigateParams());
[email protected]578c6962011-08-24 22:06:40243 p.disposition = SINGLETON_TAB;
244 p.url = singleton_ref_url2;
[email protected]78e2edc2012-07-01 23:32:28245 chrome::Navigate(&p);
[email protected]578c6962011-08-24 22:06:40246
247 // We should now have 2 tabs, the 2nd one selected.
248 EXPECT_EQ(browser(), p.browser);
249 EXPECT_EQ(2, browser()->tab_count());
250 EXPECT_EQ(1, browser()->active_index());
251
252 // Navigate to singleton_url2, but with respect ref set.
253 p = MakeNavigateParams();
254 p.disposition = SINGLETON_TAB;
255 p.url = singleton_ref_url2;
[email protected]78e2edc2012-07-01 23:32:28256 p.ref_behavior = chrome::NavigateParams::RESPECT_REF;
257 chrome::Navigate(&p);
[email protected]578c6962011-08-24 22:06:40258
259 // We should now have 3 tabs, the 3th one selected.
260 EXPECT_EQ(browser(), p.browser);
261 EXPECT_EQ(3, browser()->tab_count());
262 EXPECT_EQ(2, browser()->active_index());
263
264 // Navigate to singleton_url3.
265 p = MakeNavigateParams();
266 p.disposition = SINGLETON_TAB;
267 p.url = singleton_ref_url3;
[email protected]78e2edc2012-07-01 23:32:28268 p.ref_behavior = chrome::NavigateParams::RESPECT_REF;
269 chrome::Navigate(&p);
[email protected]578c6962011-08-24 22:06:40270
271 // We should now have 4 tabs, the 4th one selected.
272 EXPECT_EQ(browser(), p.browser);
273 EXPECT_EQ(4, browser()->tab_count());
274 EXPECT_EQ(3, browser()->active_index());
275}
276
277IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
[email protected]19d9f3a2010-10-14 21:49:36278 Disposition_SingletonTabNoneExisting) {
[email protected]19d9f3a2010-10-14 21:49:36279 GURL singleton_url1("http://maps.google.com/");
280
[email protected]bd817c22011-02-09 08:16:46281 // We should have one browser with 1 tab.
[email protected]19d9f3a2010-10-14 21:49:36282 EXPECT_EQ(1u, BrowserList::size());
[email protected]1ea49d52011-04-12 17:44:44283 EXPECT_EQ(0, browser()->active_index());
[email protected]19d9f3a2010-10-14 21:49:36284
285 // Navigate to singleton_url1.
[email protected]78e2edc2012-07-01 23:32:28286 chrome::NavigateParams p(MakeNavigateParams());
[email protected]19d9f3a2010-10-14 21:49:36287 p.disposition = SINGLETON_TAB;
288 p.url = singleton_url1;
[email protected]78e2edc2012-07-01 23:32:28289 chrome::Navigate(&p);
[email protected]19d9f3a2010-10-14 21:49:36290
291 // We should now have 2 tabs, the 2nd one selected.
292 EXPECT_EQ(browser(), p.browser);
293 EXPECT_EQ(2, browser()->tab_count());
[email protected]1ea49d52011-04-12 17:44:44294 EXPECT_EQ(1, browser()->active_index());
[email protected]a1feae52010-10-11 22:14:45295}
296
297// This test verifies that when a navigation results in a foreground tab, the
298// tab count of the Browser increases and the selected tab shifts to the new
299// foreground tab.
300IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_NewForegroundTab) {
[email protected]52877dbc62012-06-29 22:22:03301 WebContents* old_contents = chrome::GetActiveWebContents(browser());
[email protected]78e2edc2012-07-01 23:32:28302 chrome::NavigateParams p(MakeNavigateParams());
[email protected]a1feae52010-10-11 22:14:45303 p.disposition = NEW_FOREGROUND_TAB;
[email protected]78e2edc2012-07-01 23:32:28304 chrome::Navigate(&p);
[email protected]52877dbc62012-06-29 22:22:03305 EXPECT_NE(old_contents, chrome::GetActiveWebContents(browser()));
[email protected]e232c992012-12-06 12:43:20306 EXPECT_EQ(browser()->tab_strip_model()->GetActiveWebContents(),
[email protected]59253a652012-11-20 00:17:26307 p.target_contents);
[email protected]a1feae52010-10-11 22:14:45308 EXPECT_EQ(2, browser()->tab_count());
309}
310
311// This test verifies that when a navigation results in a background tab, the
312// tab count of the Browser increases but the selected tab remains the same.
313IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_NewBackgroundTab) {
[email protected]52877dbc62012-06-29 22:22:03314 WebContents* old_contents = chrome::GetActiveWebContents(browser());
[email protected]78e2edc2012-07-01 23:32:28315 chrome::NavigateParams p(MakeNavigateParams());
[email protected]a1feae52010-10-11 22:14:45316 p.disposition = NEW_BACKGROUND_TAB;
[email protected]78e2edc2012-07-01 23:32:28317 chrome::Navigate(&p);
[email protected]52877dbc62012-06-29 22:22:03318 WebContents* new_contents = chrome::GetActiveWebContents(browser());
[email protected]a1feae52010-10-11 22:14:45319 // The selected tab should have remained unchanged, since the new tab was
320 // opened in the background.
321 EXPECT_EQ(old_contents, new_contents);
322 EXPECT_EQ(2, browser()->tab_count());
323}
324
325// This test verifies that when a navigation requiring a new foreground tab
326// occurs in a Browser that cannot host multiple tabs, the new foreground tab
327// is created in an existing compatible Browser.
328IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
329 Disposition_IncompatibleWindow_Existing) {
330 // Open a foreground tab in a window that cannot open popups when there is an
331 // existing compatible window somewhere else that they can be opened within.
332 Browser* popup = CreateEmptyBrowserForType(Browser::TYPE_POPUP,
333 browser()->profile());
[email protected]78e2edc2012-07-01 23:32:28334 chrome::NavigateParams p(MakeNavigateParams(popup));
[email protected]a1feae52010-10-11 22:14:45335 p.disposition = NEW_FOREGROUND_TAB;
[email protected]78e2edc2012-07-01 23:32:28336 chrome::Navigate(&p);
[email protected]a1feae52010-10-11 22:14:45337
338 // Navigate() should have opened the tab in a different browser since the
339 // one we supplied didn't support additional tabs.
340 EXPECT_NE(popup, p.browser);
341
342 // Since browser() is an existing compatible tabbed browser, it should have
343 // opened the tab there.
344 EXPECT_EQ(browser(), p.browser);
345
346 // We should be left with 2 windows, the popup with one tab and the browser()
347 // provided by the framework with two.
348 EXPECT_EQ(2u, BrowserList::size());
349 EXPECT_EQ(1, popup->tab_count());
350 EXPECT_EQ(2, browser()->tab_count());
351}
352
353// This test verifies that when a navigation requiring a new foreground tab
354// occurs in a Browser that cannot host multiple tabs and no compatible Browser
355// that can is open, a compatible Browser is created.
356IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
357 Disposition_IncompatibleWindow_NoExisting) {
358 // We want to simulate not being able to find an existing window compatible
359 // with our non-tabbed browser window so Navigate() is forced to create a
360 // new compatible window. Because browser() supplied by the in-process
361 // browser testing framework is compatible with browser()->profile(), we
362 // need a different profile, and creating a popup window with an incognito
363 // profile is a quick and dirty way of achieving this.
364 Browser* popup = CreateEmptyBrowserForType(
[email protected]b35b26b32011-05-05 20:35:14365 Browser::TYPE_POPUP,
366 browser()->profile()->GetOffTheRecordProfile());
[email protected]78e2edc2012-07-01 23:32:28367 chrome::NavigateParams p(MakeNavigateParams(popup));
[email protected]a1feae52010-10-11 22:14:45368 p.disposition = NEW_FOREGROUND_TAB;
[email protected]78e2edc2012-07-01 23:32:28369 chrome::Navigate(&p);
[email protected]a1feae52010-10-11 22:14:45370
371 // Navigate() should have opened the tab in a different browser since the
372 // one we supplied didn't support additional tabs.
373 EXPECT_NE(popup, p.browser);
374
375 // This time, browser() is _not_ compatible with popup since it is not an
376 // incognito window.
377 EXPECT_NE(browser(), p.browser);
378
379 // We should have three windows, each with one tab:
380 // 1. the browser() provided by the framework (unchanged in this test)
381 // 2. the incognito popup we created originally
382 // 3. the new incognito tabbed browser that was created by Navigate().
383 EXPECT_EQ(3u, BrowserList::size());
384 EXPECT_EQ(1, browser()->tab_count());
385 EXPECT_EQ(1, popup->tab_count());
386 EXPECT_EQ(1, p.browser->tab_count());
[email protected]b35b26b32011-05-05 20:35:14387 EXPECT_TRUE(p.browser->is_type_tabbed());
[email protected]a1feae52010-10-11 22:14:45388}
389
390// This test verifies that navigating with WindowOpenDisposition = NEW_POPUP
391// from a normal Browser results in a new Browser with TYPE_POPUP.
392IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_NewPopup) {
[email protected]78e2edc2012-07-01 23:32:28393 chrome::NavigateParams p(MakeNavigateParams());
[email protected]a1feae52010-10-11 22:14:45394 p.disposition = NEW_POPUP;
[email protected]588300d2011-04-28 21:06:35395 p.window_bounds = gfx::Rect(0, 0, 200, 200);
[email protected]7d329992011-04-15 18:20:02396 // Wait for new popup to to load and gain focus.
[email protected]ddddfda2011-07-14 23:19:39397 ui_test_utils::NavigateToURL(&p);
[email protected]a1feae52010-10-11 22:14:45398
[email protected]7d329992011-04-15 18:20:02399 // Navigate() should have opened a new, focused popup window.
[email protected]a1feae52010-10-11 22:14:45400 EXPECT_NE(browser(), p.browser);
[email protected]9db263a2011-04-15 20:53:47401#if 0
402 // TODO(stevenjb): Enable this test. See: crbug.com/79493
[email protected]7d329992011-04-15 18:20:02403 EXPECT_TRUE(p.browser->window()->IsActive());
404#endif
[email protected]b35b26b32011-05-05 20:35:14405 EXPECT_TRUE(p.browser->is_type_popup());
406 EXPECT_FALSE(p.browser->is_app());
[email protected]a1feae52010-10-11 22:14:45407
408 // We should have two windows, the browser() provided by the framework and the
409 // new popup window.
410 EXPECT_EQ(2u, BrowserList::size());
411 EXPECT_EQ(1, browser()->tab_count());
412 EXPECT_EQ(1, p.browser->tab_count());
413}
414
415// This test verifies that navigating with WindowOpenDisposition = NEW_POPUP
[email protected]f112b0f2011-05-26 01:53:52416// from a normal Browser results in a new Browser with is_app() true.
417IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_NewPopup_ExtensionId) {
[email protected]78e2edc2012-07-01 23:32:28418 chrome::NavigateParams p(MakeNavigateParams());
[email protected]f112b0f2011-05-26 01:53:52419 p.disposition = NEW_POPUP;
420 p.extension_app_id = "extensionappid";
421 p.window_bounds = gfx::Rect(0, 0, 200, 200);
[email protected]f112b0f2011-05-26 01:53:52422 // Wait for new popup to to load and gain focus.
[email protected]ddddfda2011-07-14 23:19:39423 ui_test_utils::NavigateToURL(&p);
[email protected]f112b0f2011-05-26 01:53:52424
425 // Navigate() should have opened a new, focused popup window.
426 EXPECT_NE(browser(), p.browser);
427 EXPECT_TRUE(p.browser->is_type_popup());
428 EXPECT_TRUE(p.browser->is_app());
429
430 // We should have two windows, the browser() provided by the framework and the
431 // new popup window.
432 EXPECT_EQ(2u, BrowserList::size());
433 EXPECT_EQ(1, browser()->tab_count());
434 EXPECT_EQ(1, p.browser->tab_count());
435}
436
437// This test verifies that navigating with WindowOpenDisposition = NEW_POPUP
[email protected]300d1e52011-01-19 23:57:57438// from a normal popup results in a new Browser with TYPE_POPUP.
439IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_NewPopupFromPopup) {
440 // Open a popup.
[email protected]78e2edc2012-07-01 23:32:28441 chrome::NavigateParams p1(MakeNavigateParams());
[email protected]300d1e52011-01-19 23:57:57442 p1.disposition = NEW_POPUP;
[email protected]588300d2011-04-28 21:06:35443 p1.window_bounds = gfx::Rect(0, 0, 200, 200);
[email protected]78e2edc2012-07-01 23:32:28444 chrome::Navigate(&p1);
[email protected]300d1e52011-01-19 23:57:57445 // Open another popup.
[email protected]78e2edc2012-07-01 23:32:28446 chrome::NavigateParams p2(MakeNavigateParams(p1.browser));
[email protected]300d1e52011-01-19 23:57:57447 p2.disposition = NEW_POPUP;
[email protected]588300d2011-04-28 21:06:35448 p2.window_bounds = gfx::Rect(0, 0, 200, 200);
[email protected]78e2edc2012-07-01 23:32:28449 chrome::Navigate(&p2);
[email protected]300d1e52011-01-19 23:57:57450
451 // Navigate() should have opened a new normal popup window.
452 EXPECT_NE(p1.browser, p2.browser);
[email protected]b35b26b32011-05-05 20:35:14453 EXPECT_TRUE(p2.browser->is_type_popup());
454 EXPECT_FALSE(p2.browser->is_app());
[email protected]300d1e52011-01-19 23:57:57455
456 // We should have three windows, the browser() provided by the framework,
457 // the first popup window, and the second popup window.
458 EXPECT_EQ(3u, BrowserList::size());
459 EXPECT_EQ(1, browser()->tab_count());
460 EXPECT_EQ(1, p1.browser->tab_count());
461 EXPECT_EQ(1, p2.browser->tab_count());
462}
463
464// This test verifies that navigating with WindowOpenDisposition = NEW_POPUP
[email protected]a1feae52010-10-11 22:14:45465// from an app frame results in a new Browser with TYPE_APP_POPUP.
466IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
467 Disposition_NewPopupFromAppWindow) {
[email protected]b35b26b32011-05-05 20:35:14468 Browser* app_browser = CreateEmptyBrowserForApp(Browser::TYPE_TABBED,
469 browser()->profile());
[email protected]78e2edc2012-07-01 23:32:28470 chrome::NavigateParams p(MakeNavigateParams(app_browser));
[email protected]a1feae52010-10-11 22:14:45471 p.disposition = NEW_POPUP;
[email protected]588300d2011-04-28 21:06:35472 p.window_bounds = gfx::Rect(0, 0, 200, 200);
[email protected]78e2edc2012-07-01 23:32:28473 chrome::Navigate(&p);
[email protected]a1feae52010-10-11 22:14:45474
475 // Navigate() should have opened a new popup app window.
476 EXPECT_NE(app_browser, p.browser);
477 EXPECT_NE(browser(), p.browser);
[email protected]b35b26b32011-05-05 20:35:14478 EXPECT_TRUE(p.browser->is_type_popup());
479 EXPECT_TRUE(p.browser->is_app());
[email protected]a1feae52010-10-11 22:14:45480
481 // We should now have three windows, the app window, the app popup it created,
482 // and the original browser() provided by the framework.
483 EXPECT_EQ(3u, BrowserList::size());
484 EXPECT_EQ(1, browser()->tab_count());
485 EXPECT_EQ(1, app_browser->tab_count());
486 EXPECT_EQ(1, p.browser->tab_count());
487}
488
489// This test verifies that navigating with WindowOpenDisposition = NEW_POPUP
[email protected]300d1e52011-01-19 23:57:57490// from an app popup results in a new Browser also of TYPE_APP_POPUP.
491IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
492 Disposition_NewPopupFromAppPopup) {
[email protected]b35b26b32011-05-05 20:35:14493 Browser* app_browser = CreateEmptyBrowserForApp(Browser::TYPE_TABBED,
494 browser()->profile());
[email protected]300d1e52011-01-19 23:57:57495 // Open an app popup.
[email protected]78e2edc2012-07-01 23:32:28496 chrome::NavigateParams p1(MakeNavigateParams(app_browser));
[email protected]300d1e52011-01-19 23:57:57497 p1.disposition = NEW_POPUP;
[email protected]588300d2011-04-28 21:06:35498 p1.window_bounds = gfx::Rect(0, 0, 200, 200);
[email protected]78e2edc2012-07-01 23:32:28499 chrome::Navigate(&p1);
[email protected]300d1e52011-01-19 23:57:57500 // Now open another app popup.
[email protected]78e2edc2012-07-01 23:32:28501 chrome::NavigateParams p2(MakeNavigateParams(p1.browser));
[email protected]300d1e52011-01-19 23:57:57502 p2.disposition = NEW_POPUP;
[email protected]588300d2011-04-28 21:06:35503 p2.window_bounds = gfx::Rect(0, 0, 200, 200);
[email protected]78e2edc2012-07-01 23:32:28504 chrome::Navigate(&p2);
[email protected]300d1e52011-01-19 23:57:57505
506 // Navigate() should have opened a new popup app window.
507 EXPECT_NE(browser(), p1.browser);
508 EXPECT_NE(p1.browser, p2.browser);
[email protected]b35b26b32011-05-05 20:35:14509 EXPECT_TRUE(p2.browser->is_type_popup());
510 EXPECT_TRUE(p2.browser->is_app());
[email protected]300d1e52011-01-19 23:57:57511
512 // We should now have four windows, the app window, the first app popup,
513 // the second app popup, and the original browser() provided by the framework.
514 EXPECT_EQ(4u, BrowserList::size());
515 EXPECT_EQ(1, browser()->tab_count());
516 EXPECT_EQ(1, app_browser->tab_count());
517 EXPECT_EQ(1, p1.browser->tab_count());
518 EXPECT_EQ(1, p2.browser->tab_count());
519}
520
521// This test verifies that navigating with WindowOpenDisposition = NEW_POPUP
[email protected]a1feae52010-10-11 22:14:45522// from an extension app tab results in a new Browser with TYPE_APP_POPUP.
523IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
524 Disposition_NewPopupFromExtensionApp) {
525 // TODO(beng): TBD.
526}
527
[email protected]7d329992011-04-15 18:20:02528// This test verifies that navigating with window_action = SHOW_WINDOW_INACTIVE
529// does not focus a new new popup window.
530IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_NewPopupUnfocused) {
[email protected]78e2edc2012-07-01 23:32:28531 chrome::NavigateParams p(MakeNavigateParams());
[email protected]7d329992011-04-15 18:20:02532 p.disposition = NEW_POPUP;
[email protected]588300d2011-04-28 21:06:35533 p.window_bounds = gfx::Rect(0, 0, 200, 200);
[email protected]78e2edc2012-07-01 23:32:28534 p.window_action = chrome::NavigateParams::SHOW_WINDOW_INACTIVE;
[email protected]7d329992011-04-15 18:20:02535 // Wait for new popup to load (and gain focus if the test fails).
[email protected]ddddfda2011-07-14 23:19:39536 ui_test_utils::NavigateToURL(&p);
[email protected]7d329992011-04-15 18:20:02537
538 // Navigate() should have opened a new, unfocused, popup window.
539 EXPECT_NE(browser(), p.browser);
540 EXPECT_EQ(Browser::TYPE_POPUP, p.browser->type());
[email protected]9db263a2011-04-15 20:53:47541#if 0
542// TODO(stevenjb): Enable this test. See: crbug.com/79493
[email protected]7d329992011-04-15 18:20:02543 EXPECT_FALSE(p.browser->window()->IsActive());
[email protected]7d329992011-04-15 18:20:02544#endif
[email protected]9db263a2011-04-15 20:53:47545}
[email protected]7d329992011-04-15 18:20:02546
[email protected]a1feae52010-10-11 22:14:45547// This test verifies that navigating with WindowOpenDisposition = NEW_WINDOW
548// always opens a new window.
549IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_NewWindow) {
[email protected]78e2edc2012-07-01 23:32:28550 chrome::NavigateParams p(MakeNavigateParams());
[email protected]a1feae52010-10-11 22:14:45551 p.disposition = NEW_WINDOW;
[email protected]78e2edc2012-07-01 23:32:28552 chrome::Navigate(&p);
[email protected]a1feae52010-10-11 22:14:45553
554 // Navigate() should have opened a new toplevel window.
555 EXPECT_NE(browser(), p.browser);
[email protected]b35b26b32011-05-05 20:35:14556 EXPECT_TRUE(p.browser->is_type_tabbed());
[email protected]a1feae52010-10-11 22:14:45557
558 // We should now have two windows, the browser() provided by the framework and
559 // the new normal window.
560 EXPECT_EQ(2u, BrowserList::size());
561 EXPECT_EQ(1, browser()->tab_count());
562 EXPECT_EQ(1, p.browser->tab_count());
563}
564
565// This test verifies that navigating with WindowOpenDisposition = INCOGNITO
566// opens a new incognito window if no existing incognito window is present.
567IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_Incognito) {
[email protected]78e2edc2012-07-01 23:32:28568 chrome::NavigateParams p(MakeNavigateParams());
[email protected]a1feae52010-10-11 22:14:45569 p.disposition = OFF_THE_RECORD;
[email protected]78e2edc2012-07-01 23:32:28570 chrome::Navigate(&p);
[email protected]a1feae52010-10-11 22:14:45571
572 // Navigate() should have opened a new toplevel incognito window.
573 EXPECT_NE(browser(), p.browser);
574 EXPECT_EQ(browser()->profile()->GetOffTheRecordProfile(),
575 p.browser->profile());
576
[email protected]d7ff3592010-11-30 21:50:46577 // |source_contents| should be set to NULL because the profile for the new
578 // page is different from the originating page.
579 EXPECT_EQ(NULL, p.source_contents);
580
[email protected]a1feae52010-10-11 22:14:45581 // We should now have two windows, the browser() provided by the framework and
582 // the new incognito window.
583 EXPECT_EQ(2u, BrowserList::size());
584 EXPECT_EQ(1, browser()->tab_count());
585 EXPECT_EQ(1, p.browser->tab_count());
586}
587
588// This test verifies that navigating with WindowOpenDisposition = INCOGNITO
589// reuses an existing incognito window when possible.
590IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_IncognitoRefocus) {
591 Browser* incognito_browser =
[email protected]b35b26b32011-05-05 20:35:14592 CreateEmptyBrowserForType(Browser::TYPE_TABBED,
[email protected]a1feae52010-10-11 22:14:45593 browser()->profile()->GetOffTheRecordProfile());
[email protected]78e2edc2012-07-01 23:32:28594 chrome::NavigateParams p(MakeNavigateParams());
[email protected]a1feae52010-10-11 22:14:45595 p.disposition = OFF_THE_RECORD;
[email protected]78e2edc2012-07-01 23:32:28596 chrome::Navigate(&p);
[email protected]a1feae52010-10-11 22:14:45597
598 // Navigate() should have opened a new tab in the existing incognito window.
599 EXPECT_NE(browser(), p.browser);
600 EXPECT_EQ(p.browser, incognito_browser);
601
602 // We should now have two windows, the browser() provided by the framework and
603 // the incognito window we opened earlier.
604 EXPECT_EQ(2u, BrowserList::size());
605 EXPECT_EQ(1, browser()->tab_count());
606 EXPECT_EQ(2, incognito_browser->tab_count());
607}
608
609// This test verifies that no navigation action occurs when
610// WindowOpenDisposition = SUPPRESS_OPEN.
611IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_SuppressOpen) {
612 RunSuppressTest(SUPPRESS_OPEN);
613}
614
615// This test verifies that no navigation action occurs when
616// WindowOpenDisposition = SAVE_TO_DISK.
617IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_SaveToDisk) {
618 RunSuppressTest(SAVE_TO_DISK);
619}
620
621// This test verifies that no navigation action occurs when
622// WindowOpenDisposition = IGNORE_ACTION.
623IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_IgnoreAction) {
624 RunSuppressTest(IGNORE_ACTION);
625}
626
[email protected]e232c992012-12-06 12:43:20627// This tests adding a foreground tab with a predefined WebContents.
[email protected]a1feae52010-10-11 22:14:45628IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, TargetContents_ForegroundTab) {
[email protected]78e2edc2012-07-01 23:32:28629 chrome::NavigateParams p(MakeNavigateParams());
[email protected]a1feae52010-10-11 22:14:45630 p.disposition = NEW_FOREGROUND_TAB;
[email protected]e232c992012-12-06 12:43:20631 p.target_contents = CreateWebContents();
[email protected]78e2edc2012-07-01 23:32:28632 chrome::Navigate(&p);
[email protected]a1feae52010-10-11 22:14:45633
634 // Navigate() should have opened the contents in a new foreground in the
635 // current Browser.
636 EXPECT_EQ(browser(), p.browser);
[email protected]e232c992012-12-06 12:43:20637 EXPECT_EQ(browser()->tab_strip_model()->GetActiveWebContents(),
[email protected]59253a652012-11-20 00:17:26638 p.target_contents);
[email protected]a1feae52010-10-11 22:14:45639
640 // We should have one window, with two tabs.
641 EXPECT_EQ(1u, BrowserList::size());
642 EXPECT_EQ(2, browser()->tab_count());
643}
644
645#if defined(OS_WIN)
[email protected]e232c992012-12-06 12:43:20646// This tests adding a popup with a predefined WebContents.
[email protected]76edb672011-03-04 21:48:39647IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, DISABLED_TargetContents_Popup) {
[email protected]78e2edc2012-07-01 23:32:28648 chrome::NavigateParams p(MakeNavigateParams());
[email protected]a1feae52010-10-11 22:14:45649 p.disposition = NEW_POPUP;
[email protected]e232c992012-12-06 12:43:20650 p.target_contents = CreateWebContents();
[email protected]a1feae52010-10-11 22:14:45651 p.window_bounds = gfx::Rect(10, 10, 500, 500);
[email protected]78e2edc2012-07-01 23:32:28652 chrome::Navigate(&p);
[email protected]a1feae52010-10-11 22:14:45653
654 // Navigate() should have opened a new popup window.
655 EXPECT_NE(browser(), p.browser);
[email protected]b35b26b32011-05-05 20:35:14656 EXPECT_TRUE(p.browser->is_type_popup());
657 EXPECT_FALSE(p.browser->is_app());
[email protected]a1feae52010-10-11 22:14:45658
659 // The web platform is weird. The window bounds specified in
660 // |p.window_bounds| are used as follows:
661 // - the origin is used to position the window
[email protected]e232c992012-12-06 12:43:20662 // - the size is used to size the WebContents of the window.
[email protected]a1feae52010-10-11 22:14:45663 // As such the position of the resulting window will always match
664 // p.window_bounds.origin(), but its size will not. We need to match
665 // the size against the selected tab's view's container size.
666 // Only Windows positions the window according to |p.window_bounds.origin()| -
667 // on Mac the window is offset from the opener and on Linux it always opens
668 // at 0,0.
669 EXPECT_EQ(p.window_bounds.origin(),
670 p.browser->window()->GetRestoredBounds().origin());
671 // All platforms should respect size however provided width > 400 (Mac has a
672 // minimum window width of 400).
673 EXPECT_EQ(p.window_bounds.size(),
[email protected]e232c992012-12-06 12:43:20674 p.target_contents->GetView()->GetContainerSize());
[email protected]a1feae52010-10-11 22:14:45675
676 // We should have two windows, the new popup and the browser() provided by the
677 // framework.
678 EXPECT_EQ(2u, BrowserList::size());
679 EXPECT_EQ(1, browser()->tab_count());
680 EXPECT_EQ(1, p.browser->tab_count());
681}
682#endif
683
684// This tests adding a tab at a specific index.
685IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Tabstrip_InsertAtIndex) {
686 // This is not meant to be a comprehensive test of whether or not the tab
687 // implementation of the browser observes the insertion index. That is
688 // covered by the unit tests for TabStripModel. This merely verifies that
689 // insertion index preference is reflected in common cases.
[email protected]78e2edc2012-07-01 23:32:28690 chrome::NavigateParams p(MakeNavigateParams());
[email protected]a1feae52010-10-11 22:14:45691 p.disposition = NEW_FOREGROUND_TAB;
692 p.tabstrip_index = 0;
693 p.tabstrip_add_types = TabStripModel::ADD_FORCE_INDEX;
[email protected]78e2edc2012-07-01 23:32:28694 chrome::Navigate(&p);
[email protected]a1feae52010-10-11 22:14:45695
696 // Navigate() should have inserted a new tab at slot 0 in the tabstrip.
697 EXPECT_EQ(browser(), p.browser);
[email protected]e232c992012-12-06 12:43:20698 EXPECT_EQ(0, browser()->tab_strip_model()->GetIndexOfWebContents(
699 static_cast<const WebContents*>(p.target_contents)));
[email protected]a1feae52010-10-11 22:14:45700
701 // We should have one window - the browser() provided by the framework.
702 EXPECT_EQ(1u, BrowserList::size());
703 EXPECT_EQ(2, browser()->tab_count());
704}
705
[email protected]bb89e7482010-11-17 18:27:04706// This test verifies that constructing params with disposition = SINGLETON_TAB
[email protected]fee320542011-03-02 01:30:49707// and IGNORE_AND_NAVIGATE opens a new tab navigated to the specified URL if
[email protected]67ed83e2011-01-07 22:54:00708// no previous tab with that URL (minus the path) exists.
[email protected]bb89e7482010-11-17 18:27:04709IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
710 Disposition_SingletonTabNew_IgnorePath) {
[email protected]52877dbc62012-06-29 22:22:03711 chrome::AddSelectedTabWithURL(browser(), GetGoogleURL(),
712 content::PAGE_TRANSITION_LINK);
[email protected]bb89e7482010-11-17 18:27:04713
714 // We should have one browser with 2 tabs, the 2nd selected.
715 EXPECT_EQ(1u, BrowserList::size());
716 EXPECT_EQ(2, browser()->tab_count());
[email protected]1ea49d52011-04-12 17:44:44717 EXPECT_EQ(1, browser()->active_index());
[email protected]bb89e7482010-11-17 18:27:04718
719 // Navigate to a new singleton tab with a sub-page.
[email protected]78e2edc2012-07-01 23:32:28720 chrome::NavigateParams p(MakeNavigateParams());
[email protected]bb89e7482010-11-17 18:27:04721 p.disposition = SINGLETON_TAB;
[email protected]a048ad22012-03-23 04:26:56722 p.url = GetContentSettingsURL();
[email protected]78e2edc2012-07-01 23:32:28723 p.window_action = chrome::NavigateParams::SHOW_WINDOW;
724 p.path_behavior = chrome::NavigateParams::IGNORE_AND_NAVIGATE;
725 chrome::Navigate(&p);
[email protected]bb89e7482010-11-17 18:27:04726
727 // The last tab should now be selected and navigated to the sub-page of the
728 // URL.
729 EXPECT_EQ(browser(), p.browser);
730 EXPECT_EQ(3, browser()->tab_count());
[email protected]1ea49d52011-04-12 17:44:44731 EXPECT_EQ(2, browser()->active_index());
[email protected]a048ad22012-03-23 04:26:56732 EXPECT_EQ(GetContentSettingsURL(),
[email protected]f8f93eb2012-09-25 03:06:24733 ShortenUberURL(chrome::GetActiveWebContents(browser())->GetURL()));
[email protected]bb89e7482010-11-17 18:27:04734}
735
736// This test verifies that constructing params with disposition = SINGLETON_TAB
[email protected]fee320542011-03-02 01:30:49737// and IGNORE_AND_NAVIGATE opens an existing tab with the matching URL (minus
[email protected]bb89e7482010-11-17 18:27:04738// the path) which is navigated to the specified URL.
739IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
740 Disposition_SingletonTabExisting_IgnorePath) {
[email protected]ddddfda2011-07-14 23:19:39741 GURL singleton_url1(GetSettingsURL());
[email protected]52877dbc62012-06-29 22:22:03742 chrome::AddSelectedTabWithURL(browser(), singleton_url1,
743 content::PAGE_TRANSITION_LINK);
744 chrome::AddSelectedTabWithURL(browser(), GetGoogleURL(),
745 content::PAGE_TRANSITION_LINK);
[email protected]bb89e7482010-11-17 18:27:04746
747 // We should have one browser with 3 tabs, the 3rd selected.
748 EXPECT_EQ(1u, BrowserList::size());
749 EXPECT_EQ(3, browser()->tab_count());
[email protected]1ea49d52011-04-12 17:44:44750 EXPECT_EQ(2, browser()->active_index());
[email protected]bb89e7482010-11-17 18:27:04751
752 // Navigate to singleton_url1.
[email protected]78e2edc2012-07-01 23:32:28753 chrome::NavigateParams p(MakeNavigateParams());
[email protected]bb89e7482010-11-17 18:27:04754 p.disposition = SINGLETON_TAB;
[email protected]a048ad22012-03-23 04:26:56755 p.url = GetContentSettingsURL();
[email protected]78e2edc2012-07-01 23:32:28756 p.window_action = chrome::NavigateParams::SHOW_WINDOW;
757 p.path_behavior = chrome::NavigateParams::IGNORE_AND_NAVIGATE;
758 chrome::Navigate(&p);
[email protected]bb89e7482010-11-17 18:27:04759
760 // The middle tab should now be selected and navigated to the sub-page of the
761 // URL.
762 EXPECT_EQ(browser(), p.browser);
763 EXPECT_EQ(3, browser()->tab_count());
[email protected]1ea49d52011-04-12 17:44:44764 EXPECT_EQ(1, browser()->active_index());
[email protected]a048ad22012-03-23 04:26:56765 EXPECT_EQ(GetContentSettingsURL(),
[email protected]f8f93eb2012-09-25 03:06:24766 ShortenUberURL(chrome::GetActiveWebContents(browser())->GetURL()));
[email protected]bb89e7482010-11-17 18:27:04767}
768
769// This test verifies that constructing params with disposition = SINGLETON_TAB
[email protected]fee320542011-03-02 01:30:49770// and IGNORE_AND_NAVIGATE opens an existing tab with the matching URL (minus
[email protected]bb89e7482010-11-17 18:27:04771// the path) which is navigated to the specified URL.
772IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
773 Disposition_SingletonTabExistingSubPath_IgnorePath) {
[email protected]a048ad22012-03-23 04:26:56774 GURL singleton_url1(GetContentSettingsURL());
[email protected]52877dbc62012-06-29 22:22:03775 chrome::AddSelectedTabWithURL(browser(), singleton_url1,
776 content::PAGE_TRANSITION_LINK);
777 chrome::AddSelectedTabWithURL(browser(), GetGoogleURL(),
778 content::PAGE_TRANSITION_LINK);
[email protected]bb89e7482010-11-17 18:27:04779
780 // We should have one browser with 3 tabs, the 3rd selected.
781 EXPECT_EQ(1u, BrowserList::size());
782 EXPECT_EQ(3, browser()->tab_count());
[email protected]1ea49d52011-04-12 17:44:44783 EXPECT_EQ(2, browser()->active_index());
[email protected]bb89e7482010-11-17 18:27:04784
785 // Navigate to singleton_url1.
[email protected]78e2edc2012-07-01 23:32:28786 chrome::NavigateParams p(MakeNavigateParams());
[email protected]bb89e7482010-11-17 18:27:04787 p.disposition = SINGLETON_TAB;
[email protected]a048ad22012-03-23 04:26:56788 p.url = GetClearBrowsingDataURL();
[email protected]78e2edc2012-07-01 23:32:28789 p.window_action = chrome::NavigateParams::SHOW_WINDOW;
790 p.path_behavior = chrome::NavigateParams::IGNORE_AND_NAVIGATE;
791 chrome::Navigate(&p);
[email protected]bb89e7482010-11-17 18:27:04792
793 // The middle tab should now be selected and navigated to the sub-page of the
794 // URL.
795 EXPECT_EQ(browser(), p.browser);
796 EXPECT_EQ(3, browser()->tab_count());
[email protected]1ea49d52011-04-12 17:44:44797 EXPECT_EQ(1, browser()->active_index());
[email protected]a048ad22012-03-23 04:26:56798 EXPECT_EQ(GetClearBrowsingDataURL(),
[email protected]f8f93eb2012-09-25 03:06:24799 ShortenUberURL(chrome::GetActiveWebContents(browser())->GetURL()));
[email protected]bb89e7482010-11-17 18:27:04800}
[email protected]2dd85482010-11-06 01:56:47801
[email protected]637b3442011-01-10 23:31:48802// This test verifies that constructing params with disposition = SINGLETON_TAB
[email protected]fee320542011-03-02 01:30:49803// and IGNORE_AND_STAY_PUT opens an existing tab with the matching URL (minus
804// the path).
805IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
806 Disposition_SingletonTabExistingSubPath_IgnorePath2) {
[email protected]a048ad22012-03-23 04:26:56807 GURL singleton_url1(GetContentSettingsURL());
[email protected]52877dbc62012-06-29 22:22:03808 chrome::AddSelectedTabWithURL(browser(), singleton_url1,
809 content::PAGE_TRANSITION_LINK);
810 chrome::AddSelectedTabWithURL(browser(), GetGoogleURL(),
811 content::PAGE_TRANSITION_LINK);
[email protected]fee320542011-03-02 01:30:49812
813 // We should have one browser with 3 tabs, the 3rd selected.
814 EXPECT_EQ(1u, BrowserList::size());
815 EXPECT_EQ(3, browser()->tab_count());
[email protected]1ea49d52011-04-12 17:44:44816 EXPECT_EQ(2, browser()->active_index());
[email protected]fee320542011-03-02 01:30:49817
818 // Navigate to singleton_url1.
[email protected]78e2edc2012-07-01 23:32:28819 chrome::NavigateParams p(MakeNavigateParams());
[email protected]fee320542011-03-02 01:30:49820 p.disposition = SINGLETON_TAB;
[email protected]a048ad22012-03-23 04:26:56821 p.url = GetClearBrowsingDataURL();
[email protected]78e2edc2012-07-01 23:32:28822 p.window_action = chrome::NavigateParams::SHOW_WINDOW;
823 p.path_behavior = chrome::NavigateParams::IGNORE_AND_STAY_PUT;
824 chrome::Navigate(&p);
[email protected]fee320542011-03-02 01:30:49825
826 // The middle tab should now be selected.
827 EXPECT_EQ(browser(), p.browser);
828 EXPECT_EQ(3, browser()->tab_count());
[email protected]1ea49d52011-04-12 17:44:44829 EXPECT_EQ(1, browser()->active_index());
[email protected]fee320542011-03-02 01:30:49830 EXPECT_EQ(singleton_url1,
[email protected]f8f93eb2012-09-25 03:06:24831 ShortenUberURL(chrome::GetActiveWebContents(browser())->GetURL()));
[email protected]fee320542011-03-02 01:30:49832}
833
834// This test verifies that constructing params with disposition = SINGLETON_TAB
835// and IGNORE_AND_NAVIGATE will update the current tab's URL if the currently
[email protected]637b3442011-01-10 23:31:48836// selected tab is a match but has a different path.
837IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
838 Disposition_SingletonTabFocused_IgnorePath) {
[email protected]a048ad22012-03-23 04:26:56839 GURL singleton_url_current(GetContentSettingsURL());
[email protected]52877dbc62012-06-29 22:22:03840 chrome::AddSelectedTabWithURL(browser(), singleton_url_current,
841 content::PAGE_TRANSITION_LINK);
[email protected]637b3442011-01-10 23:31:48842
843 // We should have one browser with 2 tabs, the 2nd selected.
844 EXPECT_EQ(1u, BrowserList::size());
845 EXPECT_EQ(2, browser()->tab_count());
[email protected]1ea49d52011-04-12 17:44:44846 EXPECT_EQ(1, browser()->active_index());
[email protected]637b3442011-01-10 23:31:48847
848 // Navigate to a different settings path.
[email protected]a048ad22012-03-23 04:26:56849 GURL singleton_url_target(GetClearBrowsingDataURL());
[email protected]78e2edc2012-07-01 23:32:28850 chrome::NavigateParams p(MakeNavigateParams());
[email protected]637b3442011-01-10 23:31:48851 p.disposition = SINGLETON_TAB;
852 p.url = singleton_url_target;
[email protected]78e2edc2012-07-01 23:32:28853 p.window_action = chrome::NavigateParams::SHOW_WINDOW;
854 p.path_behavior = chrome::NavigateParams::IGNORE_AND_NAVIGATE;
855 chrome::Navigate(&p);
[email protected]637b3442011-01-10 23:31:48856
857 // The second tab should still be selected, but navigated to the new path.
858 EXPECT_EQ(browser(), p.browser);
859 EXPECT_EQ(2, browser()->tab_count());
[email protected]1ea49d52011-04-12 17:44:44860 EXPECT_EQ(1, browser()->active_index());
[email protected]637b3442011-01-10 23:31:48861 EXPECT_EQ(singleton_url_target,
[email protected]f8f93eb2012-09-25 03:06:24862 ShortenUberURL(chrome::GetActiveWebContents(browser())->GetURL()));
[email protected]637b3442011-01-10 23:31:48863}
864
[email protected]07afd7c2011-02-17 10:07:11865// This test verifies that constructing params with disposition = SINGLETON_TAB
[email protected]fee320542011-03-02 01:30:49866// and IGNORE_AND_NAVIGATE will open an existing matching tab with a different
867// query.
[email protected]07afd7c2011-02-17 10:07:11868IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
869 Disposition_SingletonTabExisting_IgnoreQuery) {
870 int initial_tab_count = browser()->tab_count();
871 GURL singleton_url_current("chrome://settings/internet");
[email protected]52877dbc62012-06-29 22:22:03872 chrome::AddSelectedTabWithURL(browser(), singleton_url_current,
873 content::PAGE_TRANSITION_LINK);
[email protected]07afd7c2011-02-17 10:07:11874
875 EXPECT_EQ(initial_tab_count + 1, browser()->tab_count());
[email protected]1ea49d52011-04-12 17:44:44876 EXPECT_EQ(initial_tab_count, browser()->active_index());
[email protected]07afd7c2011-02-17 10:07:11877
878 // Navigate to a different settings path.
879 GURL singleton_url_target(
880 "chrome://settings/internet?"
881 "servicePath=/profile/ethernet_00aa00aa00aa&networkType=1");
[email protected]78e2edc2012-07-01 23:32:28882 chrome::NavigateParams p(MakeNavigateParams());
[email protected]07afd7c2011-02-17 10:07:11883 p.disposition = SINGLETON_TAB;
884 p.url = singleton_url_target;
[email protected]78e2edc2012-07-01 23:32:28885 p.window_action = chrome::NavigateParams::SHOW_WINDOW;
886 p.path_behavior = chrome::NavigateParams::IGNORE_AND_NAVIGATE;
887 chrome::Navigate(&p);
[email protected]07afd7c2011-02-17 10:07:11888
889 // Last tab should still be selected.
890 EXPECT_EQ(browser(), p.browser);
891 EXPECT_EQ(initial_tab_count + 1, browser()->tab_count());
[email protected]1ea49d52011-04-12 17:44:44892 EXPECT_EQ(initial_tab_count, browser()->active_index());
[email protected]07afd7c2011-02-17 10:07:11893}
894
[email protected]bd817c22011-02-09 08:16:46895// This test verifies that the settings page isn't opened in the incognito
896// window.
[email protected]a048ad22012-03-23 04:26:56897// Disabled until fixed for uber settings: http://crbug.com/111243
[email protected]bd817c22011-02-09 08:16:46898IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
[email protected]a048ad22012-03-23 04:26:56899 DISABLED_Disposition_Settings_UseNonIncognitoWindow) {
[email protected]fc0ed302011-11-29 23:17:19900 RunUseNonIncognitoWindowTest(GetSettingsURL());
[email protected]bd817c22011-02-09 08:16:46901}
902
[email protected]82404cd2011-07-12 19:55:14903// This test verifies that the settings page isn't opened in the incognito
904// window from a non-incognito window (bookmark open-in-incognito trigger).
[email protected]a048ad22012-03-23 04:26:56905// Disabled until fixed for uber settings: http://crbug.com/111243
[email protected]82404cd2011-07-12 19:55:14906IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
[email protected]a048ad22012-03-23 04:26:56907 DISABLED_Disposition_Settings_UseNonIncognitoWindowForBookmark) {
[email protected]78e2edc2012-07-01 23:32:28908 chrome::NavigateParams params(browser(), GetSettingsURL(),
909 content::PAGE_TRANSITION_AUTO_BOOKMARK);
[email protected]82404cd2011-07-12 19:55:14910 params.disposition = OFF_THE_RECORD;
911 {
[email protected]a7fe9112012-07-20 02:34:45912 content::WindowedNotificationObserver observer(
[email protected]ad50def52011-10-19 23:17:07913 content::NOTIFICATION_LOAD_STOP,
914 content::NotificationService::AllSources());
[email protected]78e2edc2012-07-01 23:32:28915 chrome::Navigate(&params);
[email protected]82404cd2011-07-12 19:55:14916 observer.Wait();
917 }
918
919 EXPECT_EQ(1u, BrowserList::size());
[email protected]52877dbc62012-06-29 22:22:03920 EXPECT_EQ(GetSettingsURL(),
[email protected]f8f93eb2012-09-25 03:06:24921 ShortenUberURL(chrome::GetActiveWebContents(browser())->GetURL()));
[email protected]82404cd2011-07-12 19:55:14922}
923
[email protected]93ad8e1c2011-11-08 21:34:05924// Settings page is expected to always open in normal mode regardless
925// of whether the user is trying to open it in incognito mode or not.
926// This test verifies that if incognito mode is forced (by policy), settings
927// page doesn't open at all.
[email protected]a048ad22012-03-23 04:26:56928// Disabled until fixed for uber settings: http://crbug.com/111243
[email protected]93ad8e1c2011-11-08 21:34:05929IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
[email protected]a048ad22012-03-23 04:26:56930 DISABLED_Disposition_Settings_DoNothingIfIncognitoIsForced) {
[email protected]fc0ed302011-11-29 23:17:19931 RunDoNothingIfIncognitoIsForcedTest(GetSettingsURL());
[email protected]93ad8e1c2011-11-08 21:34:05932}
933
[email protected]bd817c22011-02-09 08:16:46934// This test verifies that the bookmarks page isn't opened in the incognito
935// window.
936IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
937 Disposition_Bookmarks_UseNonIncognitoWindow) {
[email protected]fc0ed302011-11-29 23:17:19938 RunUseNonIncognitoWindowTest(GURL(chrome::kChromeUIBookmarksURL));
[email protected]bd817c22011-02-09 08:16:46939}
940
[email protected]93ad8e1c2011-11-08 21:34:05941// Bookmark manager is expected to always open in normal mode regardless
942// of whether the user is trying to open it in incognito mode or not.
943// This test verifies that if incognito mode is forced (by policy), bookmark
944// manager doesn't open at all.
945IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
946 Disposition_Bookmarks_DoNothingIfIncognitoIsForced) {
[email protected]fc0ed302011-11-29 23:17:19947 RunDoNothingIfIncognitoIsForcedTest(GURL(chrome::kChromeUIBookmarksURL));
948}
[email protected]93ad8e1c2011-11-08 21:34:05949
[email protected]fc0ed302011-11-29 23:17:19950// This test verifies that the sync promo page isn't opened in the incognito
951// window.
952IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
953 Disposition_SyncPromo_UseNonIncognitoWindow) {
954 RunUseNonIncognitoWindowTest(GURL(chrome::kChromeUISyncPromoURL));
955}
[email protected]93ad8e1c2011-11-08 21:34:05956
[email protected]fc0ed302011-11-29 23:17:19957// The Sync promo page is expected to always open in normal mode regardless of
958// whether the user is trying to open it in incognito mode or not. This test
959// verifies that if incognito mode is forced (by policy), the sync promo page
960// doesn't open at all.
961IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
962 Disposition_SyncPromo_DoNothingIfIncognitoIsForced) {
963 RunDoNothingIfIncognitoIsForcedTest(GURL(chrome::kChromeUISyncPromoURL));
[email protected]93ad8e1c2011-11-08 21:34:05964}
965
[email protected]7de53c62011-05-13 06:44:16966// This test makes sure a crashed singleton tab reloads from a new navigation.
967IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
968 NavigateToCrashedSingletonTab) {
[email protected]a048ad22012-03-23 04:26:56969 GURL singleton_url(GetContentSettingsURL());
[email protected]5a1a52462012-11-15 03:35:16970 WebContents* web_contents = chrome::AddSelectedTabWithURL(
[email protected]52877dbc62012-06-29 22:22:03971 browser(), singleton_url, content::PAGE_TRANSITION_LINK);
[email protected]7de53c62011-05-13 06:44:16972
973 // We should have one browser with 2 tabs, the 2nd selected.
974 EXPECT_EQ(1u, BrowserList::size());
975 EXPECT_EQ(2, browser()->tab_count());
976 EXPECT_EQ(1, browser()->active_index());
977
978 // Kill the singleton tab.
[email protected]83ff91c2012-01-05 20:54:13979 web_contents->SetIsCrashed(base::TERMINATION_STATUS_PROCESS_CRASHED, -1);
980 EXPECT_TRUE(web_contents->IsCrashed());
[email protected]7de53c62011-05-13 06:44:16981
[email protected]78e2edc2012-07-01 23:32:28982 chrome::NavigateParams p(MakeNavigateParams());
[email protected]7de53c62011-05-13 06:44:16983 p.disposition = SINGLETON_TAB;
984 p.url = singleton_url;
[email protected]78e2edc2012-07-01 23:32:28985 p.window_action = chrome::NavigateParams::SHOW_WINDOW;
986 p.path_behavior = chrome::NavigateParams::IGNORE_AND_NAVIGATE;
[email protected]ddddfda2011-07-14 23:19:39987 ui_test_utils::NavigateToURL(&p);
[email protected]7de53c62011-05-13 06:44:16988
989 // The tab should not be sad anymore.
[email protected]83ff91c2012-01-05 20:54:13990 EXPECT_FALSE(web_contents->IsCrashed());
[email protected]7de53c62011-05-13 06:44:16991}
992
[email protected]fcca741b2011-06-17 22:46:37993IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
994 NavigateFromDefaultToOptionsInSameTab) {
[email protected]ddddfda2011-07-14 23:19:39995 {
[email protected]a7fe9112012-07-20 02:34:45996 content::WindowedNotificationObserver observer(
[email protected]ad50def52011-10-19 23:17:07997 content::NOTIFICATION_LOAD_STOP,
998 content::NotificationService::AllSources());
[email protected]5d9cace72012-06-21 16:07:12999 chrome::ShowSettings(browser());
[email protected]ddddfda2011-07-14 23:19:391000 observer.Wait();
1001 }
[email protected]fcca741b2011-06-17 22:46:371002 EXPECT_EQ(1, browser()->tab_count());
[email protected]52877dbc62012-06-29 22:22:031003 EXPECT_EQ(GetSettingsURL(),
[email protected]f8f93eb2012-09-25 03:06:241004 ShortenUberURL(chrome::GetActiveWebContents(browser())->GetURL()));
[email protected]fcca741b2011-06-17 22:46:371005}
1006
1007IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
1008 NavigateFromBlankToOptionsInSameTab) {
[email protected]78e2edc2012-07-01 23:32:281009 chrome::NavigateParams p(MakeNavigateParams());
[email protected]ddddfda2011-07-14 23:19:391010 p.url = GURL(chrome::kAboutBlankURL);
1011 ui_test_utils::NavigateToURL(&p);
[email protected]fcca741b2011-06-17 22:46:371012
[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]fcca741b2011-06-17 22:46:371020 EXPECT_EQ(1, browser()->tab_count());
[email protected]52877dbc62012-06-29 22:22:031021 EXPECT_EQ(GetSettingsURL(),
[email protected]f8f93eb2012-09-25 03:06:241022 ShortenUberURL(chrome::GetActiveWebContents(browser())->GetURL()));
[email protected]fcca741b2011-06-17 22:46:371023}
1024
1025IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
1026 NavigateFromNTPToOptionsInSameTab) {
[email protected]78e2edc2012-07-01 23:32:281027 chrome::NavigateParams p(MakeNavigateParams());
[email protected]ddddfda2011-07-14 23:19:391028 p.url = GURL(chrome::kChromeUINewTabURL);
1029 ui_test_utils::NavigateToURL(&p);
[email protected]fcca741b2011-06-17 22:46:371030 EXPECT_EQ(1, browser()->tab_count());
[email protected]ddddfda2011-07-14 23:19:391031 EXPECT_EQ(GURL(chrome::kChromeUINewTabURL),
[email protected]52877dbc62012-06-29 22:22:031032 chrome::GetActiveWebContents(browser())->GetURL());
[email protected]fcca741b2011-06-17 22:46:371033
[email protected]ddddfda2011-07-14 23:19:391034 {
[email protected]a7fe9112012-07-20 02:34:451035 content::WindowedNotificationObserver observer(
[email protected]ad50def52011-10-19 23:17:071036 content::NOTIFICATION_LOAD_STOP,
1037 content::NotificationService::AllSources());
[email protected]5d9cace72012-06-21 16:07:121038 chrome::ShowSettings(browser());
[email protected]ddddfda2011-07-14 23:19:391039 observer.Wait();
1040 }
[email protected]fcca741b2011-06-17 22:46:371041 EXPECT_EQ(1, browser()->tab_count());
[email protected]52877dbc62012-06-29 22:22:031042 EXPECT_EQ(GetSettingsURL(),
[email protected]f8f93eb2012-09-25 03:06:241043 ShortenUberURL(chrome::GetActiveWebContents(browser())->GetURL()));
[email protected]fcca741b2011-06-17 22:46:371044}
1045
1046IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
1047 NavigateFromPageToOptionsInNewTab) {
[email protected]78e2edc2012-07-01 23:32:281048 chrome::NavigateParams p(MakeNavigateParams());
[email protected]ddddfda2011-07-14 23:19:391049 ui_test_utils::NavigateToURL(&p);
[email protected]52877dbc62012-06-29 22:22:031050 EXPECT_EQ(GetGoogleURL(), chrome::GetActiveWebContents(browser())->GetURL());
[email protected]fcca741b2011-06-17 22:46:371051 EXPECT_EQ(1u, BrowserList::size());
1052 EXPECT_EQ(1, browser()->tab_count());
1053
[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]fcca741b2011-06-17 22:46:371061 EXPECT_EQ(2, browser()->tab_count());
[email protected]52877dbc62012-06-29 22:22:031062 EXPECT_EQ(GetSettingsURL(),
[email protected]f8f93eb2012-09-25 03:06:241063 ShortenUberURL(chrome::GetActiveWebContents(browser())->GetURL()));
[email protected]fcca741b2011-06-17 22:46:371064}
1065
1066IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
1067 NavigateFromNTPToOptionsSingleton) {
[email protected]ddddfda2011-07-14 23:19:391068 {
[email protected]a7fe9112012-07-20 02:34:451069 content::WindowedNotificationObserver observer(
[email protected]ad50def52011-10-19 23:17:071070 content::NOTIFICATION_LOAD_STOP,
1071 content::NotificationService::AllSources());
[email protected]5d9cace72012-06-21 16:07:121072 chrome::ShowSettings(browser());
[email protected]ddddfda2011-07-14 23:19:391073 observer.Wait();
1074 }
[email protected]fcca741b2011-06-17 22:46:371075 EXPECT_EQ(1, browser()->tab_count());
1076
[email protected]a37d4b02012-06-25 21:56:101077 chrome::NewTab(browser());
[email protected]fcca741b2011-06-17 22:46:371078 EXPECT_EQ(2, browser()->tab_count());
1079
[email protected]ddddfda2011-07-14 23:19:391080 {
[email protected]a7fe9112012-07-20 02:34:451081 content::WindowedNotificationObserver observer(
[email protected]ad50def52011-10-19 23:17:071082 content::NOTIFICATION_LOAD_STOP,
1083 content::NotificationService::AllSources());
[email protected]5d9cace72012-06-21 16:07:121084 chrome::ShowSettings(browser());
[email protected]ddddfda2011-07-14 23:19:391085 observer.Wait();
1086 }
[email protected]fcca741b2011-06-17 22:46:371087 EXPECT_EQ(2, browser()->tab_count());
[email protected]52877dbc62012-06-29 22:22:031088 EXPECT_EQ(GetSettingsURL(),
[email protected]f8f93eb2012-09-25 03:06:241089 ShortenUberURL(chrome::GetActiveWebContents(browser())->GetURL()));
[email protected]fcca741b2011-06-17 22:46:371090}
1091
1092IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
1093 NavigateFromNTPToOptionsPageInSameTab) {
[email protected]ddddfda2011-07-14 23:19:391094 {
[email protected]a7fe9112012-07-20 02:34:451095 content::WindowedNotificationObserver observer(
[email protected]ad50def52011-10-19 23:17:071096 content::NOTIFICATION_LOAD_STOP,
1097 content::NotificationService::AllSources());
[email protected]5d9cace72012-06-21 16:07:121098 chrome::ShowClearBrowsingDataDialog(browser());
[email protected]ddddfda2011-07-14 23:19:391099 observer.Wait();
1100 }
[email protected]fcca741b2011-06-17 22:46:371101 EXPECT_EQ(1, browser()->tab_count());
[email protected]a048ad22012-03-23 04:26:561102 EXPECT_EQ(GetClearBrowsingDataURL(),
[email protected]52877dbc62012-06-29 22:22:031103 chrome::GetActiveWebContents(browser())->GetURL());
[email protected]fcca741b2011-06-17 22:46:371104
[email protected]a37d4b02012-06-25 21:56:101105 chrome::NewTab(browser());
[email protected]fcca741b2011-06-17 22:46:371106 EXPECT_EQ(2, browser()->tab_count());
1107
[email protected]ddddfda2011-07-14 23:19:391108 {
[email protected]a7fe9112012-07-20 02:34:451109 content::WindowedNotificationObserver observer(
[email protected]ad50def52011-10-19 23:17:071110 content::NOTIFICATION_LOAD_STOP,
1111 content::NotificationService::AllSources());
[email protected]5d9cace72012-06-21 16:07:121112 chrome::ShowClearBrowsingDataDialog(browser());
[email protected]ddddfda2011-07-14 23:19:391113 observer.Wait();
1114 }
[email protected]fcca741b2011-06-17 22:46:371115 EXPECT_EQ(2, browser()->tab_count());
[email protected]a048ad22012-03-23 04:26:561116 EXPECT_EQ(GetClearBrowsingDataURL(),
[email protected]52877dbc62012-06-29 22:22:031117 chrome::GetActiveWebContents(browser())->GetURL());
[email protected]fcca741b2011-06-17 22:46:371118}
1119
[email protected]ccb8aac2012-05-21 23:00:161120// Times out on mac, fails on linux.
1121// http://crbug.com/119779
1122#if defined(OS_MACOSX) || defined(OS_LINUX)
[email protected]aac43c72012-03-23 18:41:021123#define MAYBE_NavigateFromOtherTabToSingletonOptions DISABLED_NavigateFromOtherTabToSingletonOptions
1124#else
1125#define MAYBE_NavigateFromOtherTabToSingletonOptions NavigatorFrameOtherTabToSingletonOptions
1126#endif
[email protected]fcca741b2011-06-17 22:46:371127IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
[email protected]aac43c72012-03-23 18:41:021128 MAYBE_NavigateFromOtherTabToSingletonOptions) {
[email protected]ddddfda2011-07-14 23:19:391129 {
[email protected]a7fe9112012-07-20 02:34:451130 content::WindowedNotificationObserver observer(
[email protected]ad50def52011-10-19 23:17:071131 content::NOTIFICATION_LOAD_STOP,
1132 content::NotificationService::AllSources());
[email protected]5d9cace72012-06-21 16:07:121133 chrome::ShowSettings(browser());
[email protected]ddddfda2011-07-14 23:19:391134 observer.Wait();
1135 }
1136 {
[email protected]a7fe9112012-07-20 02:34:451137 content::WindowedNotificationObserver observer(
[email protected]ad50def52011-10-19 23:17:071138 content::NOTIFICATION_LOAD_STOP,
1139 content::NotificationService::AllSources());
[email protected]52877dbc62012-06-29 22:22:031140 chrome::AddSelectedTabWithURL(browser(), GetGoogleURL(),
1141 content::PAGE_TRANSITION_LINK);
[email protected]ddddfda2011-07-14 23:19:391142 observer.Wait();
1143 }
[email protected]fcca741b2011-06-17 22:46:371144
[email protected]ddddfda2011-07-14 23:19:391145 {
[email protected]a7fe9112012-07-20 02:34:451146 content::WindowedNotificationObserver observer(
[email protected]ad50def52011-10-19 23:17:071147 content::NOTIFICATION_LOAD_STOP,
1148 content::NotificationService::AllSources());
[email protected]5d9cace72012-06-21 16:07:121149 chrome::ShowSettings(browser());
[email protected]ddddfda2011-07-14 23:19:391150 observer.Wait();
1151 }
[email protected]fcca741b2011-06-17 22:46:371152 EXPECT_EQ(2, browser()->tab_count());
[email protected]ddddfda2011-07-14 23:19:391153 EXPECT_EQ(GetSettingsURL(),
[email protected]f8f93eb2012-09-25 03:06:241154 ShortenUberURL(chrome::GetActiveWebContents(browser())->GetURL()));
[email protected]fcca741b2011-06-17 22:46:371155}
1156
[email protected]a048ad22012-03-23 04:26:561157// TODO(csilv): Update this for uber page. http://crbug.com/111579.
[email protected]ddddfda2011-07-14 23:19:391158IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
[email protected]a048ad22012-03-23 04:26:561159 DISABLED_NavigateFromDefaultToHistoryInSameTab) {
[email protected]ddddfda2011-07-14 23:19:391160 {
[email protected]a7fe9112012-07-20 02:34:451161 content::WindowedNotificationObserver observer(
[email protected]ad50def52011-10-19 23:17:071162 content::NOTIFICATION_LOAD_STOP,
1163 content::NotificationService::AllSources());
[email protected]5d9cace72012-06-21 16:07:121164 chrome::ShowHistory(browser());
[email protected]ddddfda2011-07-14 23:19:391165 observer.Wait();
1166 }
1167 EXPECT_EQ(1, browser()->tab_count());
[email protected]11e03fb2012-03-03 19:07:051168 EXPECT_EQ(GURL(chrome::kChromeUIHistoryFrameURL),
[email protected]52877dbc62012-06-29 22:22:031169 chrome::GetActiveWebContents(browser())->GetURL());
[email protected]ddddfda2011-07-14 23:19:391170}
1171
1172IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
1173 NavigateFromDefaultToBookmarksInSameTab) {
1174 {
[email protected]a7fe9112012-07-20 02:34:451175 content::WindowedNotificationObserver observer(
[email protected]ad50def52011-10-19 23:17:071176 content::NOTIFICATION_LOAD_STOP,
1177 content::NotificationService::AllSources());
[email protected]5d9cace72012-06-21 16:07:121178 chrome::ShowBookmarkManager(browser());
[email protected]ddddfda2011-07-14 23:19:391179 observer.Wait();
1180 }
1181 EXPECT_EQ(1, browser()->tab_count());
1182 EXPECT_EQ(GURL(chrome::kChromeUIBookmarksURL),
[email protected]52877dbc62012-06-29 22:22:031183 chrome::GetActiveWebContents(browser())->GetURL());
[email protected]ddddfda2011-07-14 23:19:391184}
1185
1186IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
1187 NavigateFromDefaultToDownloadsInSameTab) {
1188 {
[email protected]a7fe9112012-07-20 02:34:451189 content::WindowedNotificationObserver observer(
[email protected]ad50def52011-10-19 23:17:071190 content::NOTIFICATION_LOAD_STOP,
1191 content::NotificationService::AllSources());
[email protected]5d9cace72012-06-21 16:07:121192 chrome::ShowDownloads(browser());
[email protected]ddddfda2011-07-14 23:19:391193 observer.Wait();
1194 }
1195 EXPECT_EQ(1, browser()->tab_count());
1196 EXPECT_EQ(GURL(chrome::kChromeUIDownloadsURL),
[email protected]52877dbc62012-06-29 22:22:031197 chrome::GetActiveWebContents(browser())->GetURL());
[email protected]ddddfda2011-07-14 23:19:391198}
1199
[email protected]8fb16a82012-08-17 02:17:591200IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
1201 NavigateWithoutBrowser) {
1202 // First navigate using the profile of the existing browser window, and
1203 // check that the window is reused.
1204 chrome::NavigateParams params(browser()->profile(), GetGoogleURL(),
1205 content::PAGE_TRANSITION_LINK);
1206 ui_test_utils::NavigateToURL(&params);
1207 EXPECT_EQ(1u, BrowserList::size());
1208
1209 // Now navigate using the incognito profile and check that a new window
1210 // is created.
1211 chrome::NavigateParams params_incognito(
1212 browser()->profile()->GetOffTheRecordProfile(),
1213 GetGoogleURL(), content::PAGE_TRANSITION_LINK);
1214 ui_test_utils::NavigateToURL(&params_incognito);
1215 EXPECT_EQ(2u, BrowserList::size());
1216}
1217
[email protected]ddddfda2011-07-14 23:19:391218} // namespace