blob: e6e4e0e23bcc82e4ad1bf67fcf7b16f2925778cd [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]26c53e662011-07-09 02:21:0218#include "chrome/browser/ui/omnibox/location_bar.h"
[email protected]fbdc4232012-06-24 15:28:3719#include "chrome/browser/ui/omnibox/omnibox_edit_controller.h"
20#include "chrome/browser/ui/omnibox/omnibox_edit_model.h"
[email protected]26c53e662011-07-09 02:21:0221#include "chrome/browser/ui/omnibox/omnibox_view.h"
[email protected]4ebab8ee2012-06-11 22:52:0122#include "chrome/browser/ui/tab_contents/tab_contents.h"
[email protected]b56e2e32012-05-11 21:18:0423#include "chrome/browser/ui/tabs/tab_strip_model.h"
[email protected]bb89e7482010-11-17 18:27:0424#include "chrome/common/chrome_switches.h"
[email protected]93ad8e1c2011-11-08 21:34:0525#include "chrome/common/pref_names.h"
[email protected]ddddfda2011-07-14 23:19:3926#include "chrome/common/url_constants.h"
[email protected]af44e7fb2011-07-29 18:32:3227#include "chrome/test/base/ui_test_utils.h"
[email protected]ad50def52011-10-19 23:17:0728#include "content/public/browser/notification_service.h"
[email protected]0d6e9bd2011-10-18 04:29:1629#include "content/public/browser/notification_types.h"
[email protected]83ff91c2012-01-05 20:54:1330#include "content/public/browser/web_contents.h"
[email protected]8643e6d2012-01-18 20:26:1031#include "content/public/browser/web_contents_view.h"
[email protected]c47317e2012-06-20 22:35:3132#include "ipc/ipc_message.h"
[email protected]a1feae52010-10-11 22:14:4533
[email protected]4ca15302012-01-03 05:53:2034using content::WebContents;
35
[email protected]ddddfda2011-07-14 23:19:3936namespace {
37
38GURL GetGoogleURL() {
[email protected]bd817c22011-02-09 08:16:4639 return GURL("http://www.google.com/");
40}
[email protected]a1feae52010-10-11 22:14:4541
[email protected]ddddfda2011-07-14 23:19:3942GURL GetSettingsURL() {
[email protected]a048ad22012-03-23 04:26:5643 return GURL(chrome::kChromeUIUberURL).Resolve(
44 chrome::kChromeUISettingsHost + std::string("/"));
[email protected]ddddfda2011-07-14 23:19:3945}
46
[email protected]a048ad22012-03-23 04:26:5647GURL GetContentSettingsURL() {
48 return GetSettingsURL().Resolve(chrome::kContentSettingsExceptionsSubPage);
[email protected]ddddfda2011-07-14 23:19:3949}
50
[email protected]a048ad22012-03-23 04:26:5651GURL GetClearBrowsingDataURL() {
52 return GetSettingsURL().Resolve(chrome::kClearBrowserDataSubPage);
[email protected]ddddfda2011-07-14 23:19:3953}
54
55} // namespace
56
[email protected]78e2edc2012-07-01 23:32:2857chrome::NavigateParams BrowserNavigatorTest::MakeNavigateParams() const {
[email protected]bd817c22011-02-09 08:16:4658 return MakeNavigateParams(browser());
59}
[email protected]a1feae52010-10-11 22:14:4560
[email protected]78e2edc2012-07-01 23:32:2861chrome::NavigateParams BrowserNavigatorTest::MakeNavigateParams(
[email protected]bd817c22011-02-09 08:16:4662 Browser* browser) const {
[email protected]78e2edc2012-07-01 23:32:2863 chrome::NavigateParams params(browser, GetGoogleURL(),
64 content::PAGE_TRANSITION_LINK);
65 params.window_action = chrome::NavigateParams::SHOW_WINDOW;
[email protected]bd817c22011-02-09 08:16:4666 return params;
67}
[email protected]a1feae52010-10-11 22:14:4568
[email protected]bd817c22011-02-09 08:16:4669Browser* BrowserNavigatorTest::CreateEmptyBrowserForType(Browser::Type type,
70 Profile* profile) {
[email protected]da22aa62012-04-04 18:54:3571 Browser* browser = Browser::CreateWithParams(
72 Browser::CreateParams(type, profile));
[email protected]855370052012-07-10 19:30:3273 chrome::AddBlankTab(browser, true);
[email protected]bd817c22011-02-09 08:16:4674 return browser;
75}
[email protected]a1feae52010-10-11 22:14:4576
[email protected]b35b26b32011-05-05 20:35:1477Browser* BrowserNavigatorTest::CreateEmptyBrowserForApp(Browser::Type type,
78 Profile* profile) {
[email protected]da22aa62012-04-04 18:54:3579 Browser* browser = Browser::CreateWithParams(
80 Browser::CreateParams::CreateForApp(
81 Browser::TYPE_POPUP, "Test", gfx::Rect(), profile));
[email protected]855370052012-07-10 19:30:3282 chrome::AddBlankTab(browser, true);
[email protected]b35b26b32011-05-05 20:35:1483 return browser;
84}
85
[email protected]4ebab8ee2012-06-11 22:52:0186TabContents* BrowserNavigatorTest::CreateTabContents() {
[email protected]52877dbc62012-06-29 22:22:0387 return chrome::TabContentsFactory(
[email protected]bd817c22011-02-09 08:16:4688 browser()->profile(),
89 NULL,
90 MSG_ROUTING_NONE,
[email protected]52877dbc62012-06-29 22:22:0391 chrome::GetActiveWebContents(browser()),
[email protected]bd817c22011-02-09 08:16:4692 NULL);
93}
[email protected]a1feae52010-10-11 22:14:4594
[email protected]bd817c22011-02-09 08:16:4695void BrowserNavigatorTest::RunSuppressTest(WindowOpenDisposition disposition) {
[email protected]52877dbc62012-06-29 22:22:0396 GURL old_url = chrome::GetActiveWebContents(browser())->GetURL();
[email protected]78e2edc2012-07-01 23:32:2897 chrome::NavigateParams p(MakeNavigateParams());
[email protected]bd817c22011-02-09 08:16:4698 p.disposition = disposition;
[email protected]78e2edc2012-07-01 23:32:2899 chrome::Navigate(&p);
[email protected]a1feae52010-10-11 22:14:45100
[email protected]bd817c22011-02-09 08:16:46101 // Nothing should have happened as a result of Navigate();
102 EXPECT_EQ(1, browser()->tab_count());
103 EXPECT_EQ(1u, BrowserList::size());
[email protected]52877dbc62012-06-29 22:22:03104 EXPECT_EQ(old_url, chrome::GetActiveWebContents(browser())->GetURL());
[email protected]bd817c22011-02-09 08:16:46105}
[email protected]bb89e7482010-11-17 18:27:04106
[email protected]fc0ed302011-11-29 23:17:19107void BrowserNavigatorTest::RunUseNonIncognitoWindowTest(const GURL& url) {
108 Browser* incognito_browser = CreateIncognitoBrowser();
109
110 EXPECT_EQ(2u, BrowserList::size());
111 EXPECT_EQ(1, browser()->tab_count());
112 EXPECT_EQ(1, incognito_browser->tab_count());
113
114 // Navigate to the page.
[email protected]78e2edc2012-07-01 23:32:28115 chrome::NavigateParams p(MakeNavigateParams(incognito_browser));
[email protected]fc0ed302011-11-29 23:17:19116 p.disposition = SINGLETON_TAB;
117 p.url = url;
[email protected]78e2edc2012-07-01 23:32:28118 p.window_action = chrome::NavigateParams::SHOW_WINDOW;
119 chrome::Navigate(&p);
[email protected]fc0ed302011-11-29 23:17:19120
121 // This page should be opened in browser() window.
122 EXPECT_NE(incognito_browser, p.browser);
123 EXPECT_EQ(browser(), p.browser);
124 EXPECT_EQ(2, browser()->tab_count());
[email protected]52877dbc62012-06-29 22:22:03125 EXPECT_EQ(url, chrome::GetActiveWebContents(browser())->GetURL());
[email protected]fc0ed302011-11-29 23:17:19126}
127
128void BrowserNavigatorTest::RunDoNothingIfIncognitoIsForcedTest(
129 const GURL& url) {
130 Browser* browser = CreateIncognitoBrowser();
131
132 // Set kIncognitoModeAvailability to FORCED.
133 PrefService* prefs1 = browser->profile()->GetPrefs();
134 prefs1->SetInteger(prefs::kIncognitoModeAvailability,
135 IncognitoModePrefs::FORCED);
136 PrefService* prefs2 = browser->profile()->GetOriginalProfile()->GetPrefs();
137 prefs2->SetInteger(prefs::kIncognitoModeAvailability,
138 IncognitoModePrefs::FORCED);
139
140 // Navigate to the page.
[email protected]78e2edc2012-07-01 23:32:28141 chrome::NavigateParams p(MakeNavigateParams(browser));
[email protected]fc0ed302011-11-29 23:17:19142 p.disposition = OFF_THE_RECORD;
143 p.url = url;
[email protected]78e2edc2012-07-01 23:32:28144 p.window_action = chrome::NavigateParams::SHOW_WINDOW;
145 chrome::Navigate(&p);
[email protected]fc0ed302011-11-29 23:17:19146
147 // The page should not be opened.
148 EXPECT_EQ(browser, p.browser);
149 EXPECT_EQ(1, browser->tab_count());
150 EXPECT_EQ(GURL(chrome::kAboutBlankURL),
[email protected]52877dbc62012-06-29 22:22:03151 chrome::GetActiveWebContents(browser)->GetURL());
[email protected]fc0ed302011-11-29 23:17:19152}
153
[email protected]6c2381d2011-10-19 02:52:53154void BrowserNavigatorTest::Observe(
155 int type,
156 const content::NotificationSource& source,
157 const content::NotificationDetails& details) {
[email protected]432115822011-07-10 15:52:27158 switch (type) {
[email protected]d53a08c2012-07-18 20:35:30159 case content::NOTIFICATION_WEB_CONTENTS_RENDER_VIEW_HOST_CREATED: {
[email protected]bd817c22011-02-09 08:16:46160 ++this->created_tab_contents_count_;
161 break;
[email protected]fa7ebe02010-11-29 23:04:57162 }
[email protected]bd817c22011-02-09 08:16:46163 default:
164 break;
[email protected]fa7ebe02010-11-29 23:04:57165 }
[email protected]bd817c22011-02-09 08:16:46166}
[email protected]fa7ebe02010-11-29 23:04:57167
[email protected]ddddfda2011-07-14 23:19:39168
[email protected]bd817c22011-02-09 08:16:46169namespace {
[email protected]a1feae52010-10-11 22:14:45170
[email protected]a1feae52010-10-11 22:14:45171// This test verifies that when a navigation occurs within a tab, the tab count
172// of the Browser remains the same and the current tab bears the loaded URL.
173IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_CurrentTab) {
[email protected]ddddfda2011-07-14 23:19:39174 ui_test_utils::NavigateToURL(browser(), GetGoogleURL());
[email protected]52877dbc62012-06-29 22:22:03175 EXPECT_EQ(GetGoogleURL(), chrome::GetActiveWebContents(browser())->GetURL());
[email protected]a1feae52010-10-11 22:14:45176 // We should have one window with one tab.
177 EXPECT_EQ(1u, BrowserList::size());
178 EXPECT_EQ(1, browser()->tab_count());
179}
180
[email protected]bd817c22011-02-09 08:16:46181// This test verifies that a singleton tab is refocused if one is already opened
[email protected]19d9f3a2010-10-14 21:49:36182// in another or an existing window, or added if it is not.
183IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_SingletonTabExisting) {
[email protected]19d9f3a2010-10-14 21:49:36184 GURL singleton_url1("http://maps.google.com/");
[email protected]fa7ebe02010-11-29 23:04:57185
186 // Register for a notification if an additional tab_contents was instantiated.
[email protected]bd817c22011-02-09 08:16:46187 // Opening a Singleton tab that is already opened should not be opening a new
[email protected]4ebab8ee2012-06-11 22:52:01188 // tab nor be creating a new TabContents object.
[email protected]6c2381d2011-10-19 02:52:53189 content::NotificationRegistrar registrar;
[email protected]fa7ebe02010-11-29 23:04:57190
191 // As the registrar object goes out of scope, this will get unregistered
[email protected]d53a08c2012-07-18 20:35:30192 registrar.Add(this,
193 content::NOTIFICATION_WEB_CONTENTS_RENDER_VIEW_HOST_CREATED,
[email protected]ad50def52011-10-19 23:17:07194 content::NotificationService::AllSources());
[email protected]fa7ebe02010-11-29 23:04:57195
[email protected]52877dbc62012-06-29 22:22:03196 chrome::AddSelectedTabWithURL(browser(), singleton_url1,
197 content::PAGE_TRANSITION_LINK);
198 chrome::AddSelectedTabWithURL(browser(), GetGoogleURL(),
199 content::PAGE_TRANSITION_LINK);
[email protected]19d9f3a2010-10-14 21:49:36200
201 // We should have one browser with 3 tabs, the 3rd selected.
202 EXPECT_EQ(1u, BrowserList::size());
[email protected]1ea49d52011-04-12 17:44:44203 EXPECT_EQ(2, browser()->active_index());
[email protected]19d9f3a2010-10-14 21:49:36204
[email protected]fa7ebe02010-11-29 23:04:57205 unsigned int previous_tab_contents_count =
206 created_tab_contents_count_ = 0;
207
[email protected]19d9f3a2010-10-14 21:49:36208 // Navigate to singleton_url1.
[email protected]78e2edc2012-07-01 23:32:28209 chrome::NavigateParams p(MakeNavigateParams());
[email protected]19d9f3a2010-10-14 21:49:36210 p.disposition = SINGLETON_TAB;
211 p.url = singleton_url1;
[email protected]78e2edc2012-07-01 23:32:28212 chrome::Navigate(&p);
[email protected]19d9f3a2010-10-14 21:49:36213
214 // The middle tab should now be selected.
215 EXPECT_EQ(browser(), p.browser);
[email protected]1ea49d52011-04-12 17:44:44216 EXPECT_EQ(1, browser()->active_index());
[email protected]fa7ebe02010-11-29 23:04:57217
218 // No tab contents should have been created
219 EXPECT_EQ(previous_tab_contents_count,
220 created_tab_contents_count_);
[email protected]19d9f3a2010-10-14 21:49:36221}
222
223IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
[email protected]578c6962011-08-24 22:06:40224 Disposition_SingletonTabRespectingRef) {
225 GURL singleton_ref_url1("http://maps.google.com/#a");
226 GURL singleton_ref_url2("http://maps.google.com/#b");
227 GURL singleton_ref_url3("http://maps.google.com/");
228
[email protected]52877dbc62012-06-29 22:22:03229 chrome::AddSelectedTabWithURL(browser(), singleton_ref_url1,
230 content::PAGE_TRANSITION_LINK);
[email protected]578c6962011-08-24 22:06:40231
232 // We should have one browser with 2 tabs, 2nd selected.
233 EXPECT_EQ(1u, BrowserList::size());
234 EXPECT_EQ(2, browser()->tab_count());
235 EXPECT_EQ(1, browser()->active_index());
236
237 // Navigate to singleton_url2.
[email protected]78e2edc2012-07-01 23:32:28238 chrome::NavigateParams p(MakeNavigateParams());
[email protected]578c6962011-08-24 22:06:40239 p.disposition = SINGLETON_TAB;
240 p.url = singleton_ref_url2;
[email protected]78e2edc2012-07-01 23:32:28241 chrome::Navigate(&p);
[email protected]578c6962011-08-24 22:06:40242
243 // We should now have 2 tabs, the 2nd one selected.
244 EXPECT_EQ(browser(), p.browser);
245 EXPECT_EQ(2, browser()->tab_count());
246 EXPECT_EQ(1, browser()->active_index());
247
248 // Navigate to singleton_url2, but with respect ref set.
249 p = MakeNavigateParams();
250 p.disposition = SINGLETON_TAB;
251 p.url = singleton_ref_url2;
[email protected]78e2edc2012-07-01 23:32:28252 p.ref_behavior = chrome::NavigateParams::RESPECT_REF;
253 chrome::Navigate(&p);
[email protected]578c6962011-08-24 22:06:40254
255 // We should now have 3 tabs, the 3th one selected.
256 EXPECT_EQ(browser(), p.browser);
257 EXPECT_EQ(3, browser()->tab_count());
258 EXPECT_EQ(2, browser()->active_index());
259
260 // Navigate to singleton_url3.
261 p = MakeNavigateParams();
262 p.disposition = SINGLETON_TAB;
263 p.url = singleton_ref_url3;
[email protected]78e2edc2012-07-01 23:32:28264 p.ref_behavior = chrome::NavigateParams::RESPECT_REF;
265 chrome::Navigate(&p);
[email protected]578c6962011-08-24 22:06:40266
267 // We should now have 4 tabs, the 4th one selected.
268 EXPECT_EQ(browser(), p.browser);
269 EXPECT_EQ(4, browser()->tab_count());
270 EXPECT_EQ(3, browser()->active_index());
271}
272
273IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
[email protected]19d9f3a2010-10-14 21:49:36274 Disposition_SingletonTabNoneExisting) {
[email protected]19d9f3a2010-10-14 21:49:36275 GURL singleton_url1("http://maps.google.com/");
276
[email protected]bd817c22011-02-09 08:16:46277 // We should have one browser with 1 tab.
[email protected]19d9f3a2010-10-14 21:49:36278 EXPECT_EQ(1u, BrowserList::size());
[email protected]1ea49d52011-04-12 17:44:44279 EXPECT_EQ(0, browser()->active_index());
[email protected]19d9f3a2010-10-14 21:49:36280
281 // Navigate to singleton_url1.
[email protected]78e2edc2012-07-01 23:32:28282 chrome::NavigateParams p(MakeNavigateParams());
[email protected]19d9f3a2010-10-14 21:49:36283 p.disposition = SINGLETON_TAB;
284 p.url = singleton_url1;
[email protected]78e2edc2012-07-01 23:32:28285 chrome::Navigate(&p);
[email protected]19d9f3a2010-10-14 21:49:36286
287 // We should now have 2 tabs, the 2nd one selected.
288 EXPECT_EQ(browser(), p.browser);
289 EXPECT_EQ(2, browser()->tab_count());
[email protected]1ea49d52011-04-12 17:44:44290 EXPECT_EQ(1, browser()->active_index());
[email protected]a1feae52010-10-11 22:14:45291}
292
293// This test verifies that when a navigation results in a foreground tab, the
294// tab count of the Browser increases and the selected tab shifts to the new
295// foreground tab.
296IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_NewForegroundTab) {
[email protected]52877dbc62012-06-29 22:22:03297 WebContents* old_contents = chrome::GetActiveWebContents(browser());
[email protected]78e2edc2012-07-01 23:32:28298 chrome::NavigateParams p(MakeNavigateParams());
[email protected]a1feae52010-10-11 22:14:45299 p.disposition = NEW_FOREGROUND_TAB;
[email protected]78e2edc2012-07-01 23:32:28300 chrome::Navigate(&p);
[email protected]52877dbc62012-06-29 22:22:03301 EXPECT_NE(old_contents, chrome::GetActiveWebContents(browser()));
302 EXPECT_EQ(chrome::GetActiveTabContents(browser()), p.target_contents);
[email protected]a1feae52010-10-11 22:14:45303 EXPECT_EQ(2, browser()->tab_count());
304}
305
306// This test verifies that when a navigation results in a background tab, the
307// tab count of the Browser increases but the selected tab remains the same.
308IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_NewBackgroundTab) {
[email protected]52877dbc62012-06-29 22:22:03309 WebContents* old_contents = chrome::GetActiveWebContents(browser());
[email protected]78e2edc2012-07-01 23:32:28310 chrome::NavigateParams p(MakeNavigateParams());
[email protected]a1feae52010-10-11 22:14:45311 p.disposition = NEW_BACKGROUND_TAB;
[email protected]78e2edc2012-07-01 23:32:28312 chrome::Navigate(&p);
[email protected]52877dbc62012-06-29 22:22:03313 WebContents* new_contents = chrome::GetActiveWebContents(browser());
[email protected]a1feae52010-10-11 22:14:45314 // The selected tab should have remained unchanged, since the new tab was
315 // opened in the background.
316 EXPECT_EQ(old_contents, new_contents);
317 EXPECT_EQ(2, browser()->tab_count());
318}
319
320// This test verifies that when a navigation requiring a new foreground tab
321// occurs in a Browser that cannot host multiple tabs, the new foreground tab
322// is created in an existing compatible Browser.
323IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
324 Disposition_IncompatibleWindow_Existing) {
325 // Open a foreground tab in a window that cannot open popups when there is an
326 // existing compatible window somewhere else that they can be opened within.
327 Browser* popup = CreateEmptyBrowserForType(Browser::TYPE_POPUP,
328 browser()->profile());
[email protected]78e2edc2012-07-01 23:32:28329 chrome::NavigateParams p(MakeNavigateParams(popup));
[email protected]a1feae52010-10-11 22:14:45330 p.disposition = NEW_FOREGROUND_TAB;
[email protected]78e2edc2012-07-01 23:32:28331 chrome::Navigate(&p);
[email protected]a1feae52010-10-11 22:14:45332
333 // Navigate() should have opened the tab in a different browser since the
334 // one we supplied didn't support additional tabs.
335 EXPECT_NE(popup, p.browser);
336
337 // Since browser() is an existing compatible tabbed browser, it should have
338 // opened the tab there.
339 EXPECT_EQ(browser(), p.browser);
340
341 // We should be left with 2 windows, the popup with one tab and the browser()
342 // provided by the framework with two.
343 EXPECT_EQ(2u, BrowserList::size());
344 EXPECT_EQ(1, popup->tab_count());
345 EXPECT_EQ(2, browser()->tab_count());
346}
347
348// This test verifies that when a navigation requiring a new foreground tab
349// occurs in a Browser that cannot host multiple tabs and no compatible Browser
350// that can is open, a compatible Browser is created.
351IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
352 Disposition_IncompatibleWindow_NoExisting) {
353 // We want to simulate not being able to find an existing window compatible
354 // with our non-tabbed browser window so Navigate() is forced to create a
355 // new compatible window. Because browser() supplied by the in-process
356 // browser testing framework is compatible with browser()->profile(), we
357 // need a different profile, and creating a popup window with an incognito
358 // profile is a quick and dirty way of achieving this.
359 Browser* popup = CreateEmptyBrowserForType(
[email protected]b35b26b32011-05-05 20:35:14360 Browser::TYPE_POPUP,
361 browser()->profile()->GetOffTheRecordProfile());
[email protected]78e2edc2012-07-01 23:32:28362 chrome::NavigateParams p(MakeNavigateParams(popup));
[email protected]a1feae52010-10-11 22:14:45363 p.disposition = NEW_FOREGROUND_TAB;
[email protected]78e2edc2012-07-01 23:32:28364 chrome::Navigate(&p);
[email protected]a1feae52010-10-11 22:14:45365
366 // Navigate() should have opened the tab in a different browser since the
367 // one we supplied didn't support additional tabs.
368 EXPECT_NE(popup, p.browser);
369
370 // This time, browser() is _not_ compatible with popup since it is not an
371 // incognito window.
372 EXPECT_NE(browser(), p.browser);
373
374 // We should have three windows, each with one tab:
375 // 1. the browser() provided by the framework (unchanged in this test)
376 // 2. the incognito popup we created originally
377 // 3. the new incognito tabbed browser that was created by Navigate().
378 EXPECT_EQ(3u, BrowserList::size());
379 EXPECT_EQ(1, browser()->tab_count());
380 EXPECT_EQ(1, popup->tab_count());
381 EXPECT_EQ(1, p.browser->tab_count());
[email protected]b35b26b32011-05-05 20:35:14382 EXPECT_TRUE(p.browser->is_type_tabbed());
[email protected]a1feae52010-10-11 22:14:45383}
384
385// This test verifies that navigating with WindowOpenDisposition = NEW_POPUP
386// from a normal Browser results in a new Browser with TYPE_POPUP.
387IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_NewPopup) {
[email protected]78e2edc2012-07-01 23:32:28388 chrome::NavigateParams p(MakeNavigateParams());
[email protected]a1feae52010-10-11 22:14:45389 p.disposition = NEW_POPUP;
[email protected]588300d2011-04-28 21:06:35390 p.window_bounds = gfx::Rect(0, 0, 200, 200);
[email protected]7d329992011-04-15 18:20:02391 // Wait for new popup to to load and gain focus.
[email protected]ddddfda2011-07-14 23:19:39392 ui_test_utils::NavigateToURL(&p);
[email protected]a1feae52010-10-11 22:14:45393
[email protected]7d329992011-04-15 18:20:02394 // Navigate() should have opened a new, focused popup window.
[email protected]a1feae52010-10-11 22:14:45395 EXPECT_NE(browser(), p.browser);
[email protected]9db263a2011-04-15 20:53:47396#if 0
397 // TODO(stevenjb): Enable this test. See: crbug.com/79493
[email protected]7d329992011-04-15 18:20:02398 EXPECT_TRUE(p.browser->window()->IsActive());
399#endif
[email protected]b35b26b32011-05-05 20:35:14400 EXPECT_TRUE(p.browser->is_type_popup());
401 EXPECT_FALSE(p.browser->is_app());
[email protected]a1feae52010-10-11 22:14:45402
403 // We should have two windows, the browser() provided by the framework and the
404 // new popup window.
405 EXPECT_EQ(2u, BrowserList::size());
406 EXPECT_EQ(1, browser()->tab_count());
407 EXPECT_EQ(1, p.browser->tab_count());
408}
409
410// This test verifies that navigating with WindowOpenDisposition = NEW_POPUP
[email protected]f112b0f2011-05-26 01:53:52411// from a normal Browser results in a new Browser with is_app() true.
412IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_NewPopup_ExtensionId) {
[email protected]78e2edc2012-07-01 23:32:28413 chrome::NavigateParams p(MakeNavigateParams());
[email protected]f112b0f2011-05-26 01:53:52414 p.disposition = NEW_POPUP;
415 p.extension_app_id = "extensionappid";
416 p.window_bounds = gfx::Rect(0, 0, 200, 200);
[email protected]f112b0f2011-05-26 01:53:52417 // Wait for new popup to to load and gain focus.
[email protected]ddddfda2011-07-14 23:19:39418 ui_test_utils::NavigateToURL(&p);
[email protected]f112b0f2011-05-26 01:53:52419
420 // Navigate() should have opened a new, focused popup window.
421 EXPECT_NE(browser(), p.browser);
422 EXPECT_TRUE(p.browser->is_type_popup());
423 EXPECT_TRUE(p.browser->is_app());
424
425 // We should have two windows, the browser() provided by the framework and the
426 // new popup window.
427 EXPECT_EQ(2u, BrowserList::size());
428 EXPECT_EQ(1, browser()->tab_count());
429 EXPECT_EQ(1, p.browser->tab_count());
430}
431
432// This test verifies that navigating with WindowOpenDisposition = NEW_POPUP
[email protected]300d1e52011-01-19 23:57:57433// from a normal popup results in a new Browser with TYPE_POPUP.
434IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_NewPopupFromPopup) {
435 // Open a popup.
[email protected]78e2edc2012-07-01 23:32:28436 chrome::NavigateParams p1(MakeNavigateParams());
[email protected]300d1e52011-01-19 23:57:57437 p1.disposition = NEW_POPUP;
[email protected]588300d2011-04-28 21:06:35438 p1.window_bounds = gfx::Rect(0, 0, 200, 200);
[email protected]78e2edc2012-07-01 23:32:28439 chrome::Navigate(&p1);
[email protected]300d1e52011-01-19 23:57:57440 // Open another popup.
[email protected]78e2edc2012-07-01 23:32:28441 chrome::NavigateParams p2(MakeNavigateParams(p1.browser));
[email protected]300d1e52011-01-19 23:57:57442 p2.disposition = NEW_POPUP;
[email protected]588300d2011-04-28 21:06:35443 p2.window_bounds = gfx::Rect(0, 0, 200, 200);
[email protected]78e2edc2012-07-01 23:32:28444 chrome::Navigate(&p2);
[email protected]300d1e52011-01-19 23:57:57445
446 // Navigate() should have opened a new normal popup window.
447 EXPECT_NE(p1.browser, p2.browser);
[email protected]b35b26b32011-05-05 20:35:14448 EXPECT_TRUE(p2.browser->is_type_popup());
449 EXPECT_FALSE(p2.browser->is_app());
[email protected]300d1e52011-01-19 23:57:57450
451 // We should have three windows, the browser() provided by the framework,
452 // the first popup window, and the second popup window.
453 EXPECT_EQ(3u, BrowserList::size());
454 EXPECT_EQ(1, browser()->tab_count());
455 EXPECT_EQ(1, p1.browser->tab_count());
456 EXPECT_EQ(1, p2.browser->tab_count());
457}
458
459// This test verifies that navigating with WindowOpenDisposition = NEW_POPUP
[email protected]a1feae52010-10-11 22:14:45460// from an app frame results in a new Browser with TYPE_APP_POPUP.
461IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
462 Disposition_NewPopupFromAppWindow) {
[email protected]b35b26b32011-05-05 20:35:14463 Browser* app_browser = CreateEmptyBrowserForApp(Browser::TYPE_TABBED,
464 browser()->profile());
[email protected]78e2edc2012-07-01 23:32:28465 chrome::NavigateParams p(MakeNavigateParams(app_browser));
[email protected]a1feae52010-10-11 22:14:45466 p.disposition = NEW_POPUP;
[email protected]588300d2011-04-28 21:06:35467 p.window_bounds = gfx::Rect(0, 0, 200, 200);
[email protected]78e2edc2012-07-01 23:32:28468 chrome::Navigate(&p);
[email protected]a1feae52010-10-11 22:14:45469
470 // Navigate() should have opened a new popup app window.
471 EXPECT_NE(app_browser, p.browser);
472 EXPECT_NE(browser(), p.browser);
[email protected]b35b26b32011-05-05 20:35:14473 EXPECT_TRUE(p.browser->is_type_popup());
474 EXPECT_TRUE(p.browser->is_app());
[email protected]a1feae52010-10-11 22:14:45475
476 // We should now have three windows, the app window, the app popup it created,
477 // and the original browser() provided by the framework.
478 EXPECT_EQ(3u, BrowserList::size());
479 EXPECT_EQ(1, browser()->tab_count());
480 EXPECT_EQ(1, app_browser->tab_count());
481 EXPECT_EQ(1, p.browser->tab_count());
482}
483
484// This test verifies that navigating with WindowOpenDisposition = NEW_POPUP
[email protected]300d1e52011-01-19 23:57:57485// from an app popup results in a new Browser also of TYPE_APP_POPUP.
486IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
487 Disposition_NewPopupFromAppPopup) {
[email protected]b35b26b32011-05-05 20:35:14488 Browser* app_browser = CreateEmptyBrowserForApp(Browser::TYPE_TABBED,
489 browser()->profile());
[email protected]300d1e52011-01-19 23:57:57490 // Open an app popup.
[email protected]78e2edc2012-07-01 23:32:28491 chrome::NavigateParams p1(MakeNavigateParams(app_browser));
[email protected]300d1e52011-01-19 23:57:57492 p1.disposition = NEW_POPUP;
[email protected]588300d2011-04-28 21:06:35493 p1.window_bounds = gfx::Rect(0, 0, 200, 200);
[email protected]78e2edc2012-07-01 23:32:28494 chrome::Navigate(&p1);
[email protected]300d1e52011-01-19 23:57:57495 // Now open another app popup.
[email protected]78e2edc2012-07-01 23:32:28496 chrome::NavigateParams p2(MakeNavigateParams(p1.browser));
[email protected]300d1e52011-01-19 23:57:57497 p2.disposition = NEW_POPUP;
[email protected]588300d2011-04-28 21:06:35498 p2.window_bounds = gfx::Rect(0, 0, 200, 200);
[email protected]78e2edc2012-07-01 23:32:28499 chrome::Navigate(&p2);
[email protected]300d1e52011-01-19 23:57:57500
501 // Navigate() should have opened a new popup app window.
502 EXPECT_NE(browser(), p1.browser);
503 EXPECT_NE(p1.browser, p2.browser);
[email protected]b35b26b32011-05-05 20:35:14504 EXPECT_TRUE(p2.browser->is_type_popup());
505 EXPECT_TRUE(p2.browser->is_app());
[email protected]300d1e52011-01-19 23:57:57506
507 // We should now have four windows, the app window, the first app popup,
508 // the second app popup, and the original browser() provided by the framework.
509 EXPECT_EQ(4u, BrowserList::size());
510 EXPECT_EQ(1, browser()->tab_count());
511 EXPECT_EQ(1, app_browser->tab_count());
512 EXPECT_EQ(1, p1.browser->tab_count());
513 EXPECT_EQ(1, p2.browser->tab_count());
514}
515
516// This test verifies that navigating with WindowOpenDisposition = NEW_POPUP
[email protected]a1feae52010-10-11 22:14:45517// from an extension app tab results in a new Browser with TYPE_APP_POPUP.
518IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
519 Disposition_NewPopupFromExtensionApp) {
520 // TODO(beng): TBD.
521}
522
[email protected]7d329992011-04-15 18:20:02523// This test verifies that navigating with window_action = SHOW_WINDOW_INACTIVE
524// does not focus a new new popup window.
525IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_NewPopupUnfocused) {
[email protected]78e2edc2012-07-01 23:32:28526 chrome::NavigateParams p(MakeNavigateParams());
[email protected]7d329992011-04-15 18:20:02527 p.disposition = NEW_POPUP;
[email protected]588300d2011-04-28 21:06:35528 p.window_bounds = gfx::Rect(0, 0, 200, 200);
[email protected]78e2edc2012-07-01 23:32:28529 p.window_action = chrome::NavigateParams::SHOW_WINDOW_INACTIVE;
[email protected]7d329992011-04-15 18:20:02530 // Wait for new popup to load (and gain focus if the test fails).
[email protected]ddddfda2011-07-14 23:19:39531 ui_test_utils::NavigateToURL(&p);
[email protected]7d329992011-04-15 18:20:02532
533 // Navigate() should have opened a new, unfocused, popup window.
534 EXPECT_NE(browser(), p.browser);
535 EXPECT_EQ(Browser::TYPE_POPUP, p.browser->type());
[email protected]9db263a2011-04-15 20:53:47536#if 0
537// TODO(stevenjb): Enable this test. See: crbug.com/79493
[email protected]7d329992011-04-15 18:20:02538 EXPECT_FALSE(p.browser->window()->IsActive());
[email protected]7d329992011-04-15 18:20:02539#endif
[email protected]9db263a2011-04-15 20:53:47540}
[email protected]7d329992011-04-15 18:20:02541
[email protected]a1feae52010-10-11 22:14:45542// This test verifies that navigating with WindowOpenDisposition = NEW_WINDOW
543// always opens a new window.
544IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_NewWindow) {
[email protected]78e2edc2012-07-01 23:32:28545 chrome::NavigateParams p(MakeNavigateParams());
[email protected]a1feae52010-10-11 22:14:45546 p.disposition = NEW_WINDOW;
[email protected]78e2edc2012-07-01 23:32:28547 chrome::Navigate(&p);
[email protected]a1feae52010-10-11 22:14:45548
549 // Navigate() should have opened a new toplevel window.
550 EXPECT_NE(browser(), p.browser);
[email protected]b35b26b32011-05-05 20:35:14551 EXPECT_TRUE(p.browser->is_type_tabbed());
[email protected]a1feae52010-10-11 22:14:45552
553 // We should now have two windows, the browser() provided by the framework and
554 // the new normal window.
555 EXPECT_EQ(2u, BrowserList::size());
556 EXPECT_EQ(1, browser()->tab_count());
557 EXPECT_EQ(1, p.browser->tab_count());
558}
559
560// This test verifies that navigating with WindowOpenDisposition = INCOGNITO
561// opens a new incognito window if no existing incognito window is present.
562IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_Incognito) {
[email protected]78e2edc2012-07-01 23:32:28563 chrome::NavigateParams p(MakeNavigateParams());
[email protected]a1feae52010-10-11 22:14:45564 p.disposition = OFF_THE_RECORD;
[email protected]78e2edc2012-07-01 23:32:28565 chrome::Navigate(&p);
[email protected]a1feae52010-10-11 22:14:45566
567 // Navigate() should have opened a new toplevel incognito window.
568 EXPECT_NE(browser(), p.browser);
569 EXPECT_EQ(browser()->profile()->GetOffTheRecordProfile(),
570 p.browser->profile());
571
[email protected]d7ff3592010-11-30 21:50:46572 // |source_contents| should be set to NULL because the profile for the new
573 // page is different from the originating page.
574 EXPECT_EQ(NULL, p.source_contents);
575
[email protected]a1feae52010-10-11 22:14:45576 // We should now have two windows, the browser() provided by the framework and
577 // the new incognito window.
578 EXPECT_EQ(2u, BrowserList::size());
579 EXPECT_EQ(1, browser()->tab_count());
580 EXPECT_EQ(1, p.browser->tab_count());
581}
582
583// This test verifies that navigating with WindowOpenDisposition = INCOGNITO
584// reuses an existing incognito window when possible.
585IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_IncognitoRefocus) {
586 Browser* incognito_browser =
[email protected]b35b26b32011-05-05 20:35:14587 CreateEmptyBrowserForType(Browser::TYPE_TABBED,
[email protected]a1feae52010-10-11 22:14:45588 browser()->profile()->GetOffTheRecordProfile());
[email protected]78e2edc2012-07-01 23:32:28589 chrome::NavigateParams p(MakeNavigateParams());
[email protected]a1feae52010-10-11 22:14:45590 p.disposition = OFF_THE_RECORD;
[email protected]78e2edc2012-07-01 23:32:28591 chrome::Navigate(&p);
[email protected]a1feae52010-10-11 22:14:45592
593 // Navigate() should have opened a new tab in the existing incognito window.
594 EXPECT_NE(browser(), p.browser);
595 EXPECT_EQ(p.browser, incognito_browser);
596
597 // We should now have two windows, the browser() provided by the framework and
598 // the incognito window we opened earlier.
599 EXPECT_EQ(2u, BrowserList::size());
600 EXPECT_EQ(1, browser()->tab_count());
601 EXPECT_EQ(2, incognito_browser->tab_count());
602}
603
604// This test verifies that no navigation action occurs when
605// WindowOpenDisposition = SUPPRESS_OPEN.
606IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_SuppressOpen) {
607 RunSuppressTest(SUPPRESS_OPEN);
608}
609
610// This test verifies that no navigation action occurs when
611// WindowOpenDisposition = SAVE_TO_DISK.
612IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_SaveToDisk) {
613 RunSuppressTest(SAVE_TO_DISK);
614}
615
616// This test verifies that no navigation action occurs when
617// WindowOpenDisposition = IGNORE_ACTION.
618IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_IgnoreAction) {
619 RunSuppressTest(IGNORE_ACTION);
620}
621
[email protected]4ebab8ee2012-06-11 22:52:01622// This tests adding a foreground tab with a predefined TabContents.
[email protected]a1feae52010-10-11 22:14:45623IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, TargetContents_ForegroundTab) {
[email protected]78e2edc2012-07-01 23:32:28624 chrome::NavigateParams p(MakeNavigateParams());
[email protected]a1feae52010-10-11 22:14:45625 p.disposition = NEW_FOREGROUND_TAB;
626 p.target_contents = CreateTabContents();
[email protected]78e2edc2012-07-01 23:32:28627 chrome::Navigate(&p);
[email protected]a1feae52010-10-11 22:14:45628
629 // Navigate() should have opened the contents in a new foreground in the
630 // current Browser.
631 EXPECT_EQ(browser(), p.browser);
[email protected]52877dbc62012-06-29 22:22:03632 EXPECT_EQ(chrome::GetActiveTabContents(browser()), p.target_contents);
[email protected]a1feae52010-10-11 22:14:45633
634 // We should have one window, with two tabs.
635 EXPECT_EQ(1u, BrowserList::size());
636 EXPECT_EQ(2, browser()->tab_count());
637}
638
639#if defined(OS_WIN)
[email protected]4ebab8ee2012-06-11 22:52:01640// This tests adding a popup with a predefined TabContents.
[email protected]76edb672011-03-04 21:48:39641IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, DISABLED_TargetContents_Popup) {
[email protected]78e2edc2012-07-01 23:32:28642 chrome::NavigateParams p(MakeNavigateParams());
[email protected]a1feae52010-10-11 22:14:45643 p.disposition = NEW_POPUP;
644 p.target_contents = CreateTabContents();
645 p.window_bounds = gfx::Rect(10, 10, 500, 500);
[email protected]78e2edc2012-07-01 23:32:28646 chrome::Navigate(&p);
[email protected]a1feae52010-10-11 22:14:45647
648 // Navigate() should have opened a new popup window.
649 EXPECT_NE(browser(), p.browser);
[email protected]b35b26b32011-05-05 20:35:14650 EXPECT_TRUE(p.browser->is_type_popup());
651 EXPECT_FALSE(p.browser->is_app());
[email protected]a1feae52010-10-11 22:14:45652
653 // The web platform is weird. The window bounds specified in
654 // |p.window_bounds| are used as follows:
655 // - the origin is used to position the window
[email protected]4ebab8ee2012-06-11 22:52:01656 // - the size is used to size the TabContents of the window.
[email protected]a1feae52010-10-11 22:14:45657 // As such the position of the resulting window will always match
658 // p.window_bounds.origin(), but its size will not. We need to match
659 // the size against the selected tab's view's container size.
660 // Only Windows positions the window according to |p.window_bounds.origin()| -
661 // on Mac the window is offset from the opener and on Linux it always opens
662 // at 0,0.
663 EXPECT_EQ(p.window_bounds.origin(),
664 p.browser->window()->GetRestoredBounds().origin());
665 // All platforms should respect size however provided width > 400 (Mac has a
666 // minimum window width of 400).
667 EXPECT_EQ(p.window_bounds.size(),
[email protected]83ff91c2012-01-05 20:54:13668 p.target_contents->web_contents()->GetView()->GetContainerSize());
[email protected]a1feae52010-10-11 22:14:45669
670 // We should have two windows, the new popup and the browser() provided by the
671 // framework.
672 EXPECT_EQ(2u, BrowserList::size());
673 EXPECT_EQ(1, browser()->tab_count());
674 EXPECT_EQ(1, p.browser->tab_count());
675}
676#endif
677
678// This tests adding a tab at a specific index.
679IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Tabstrip_InsertAtIndex) {
680 // This is not meant to be a comprehensive test of whether or not the tab
681 // implementation of the browser observes the insertion index. That is
682 // covered by the unit tests for TabStripModel. This merely verifies that
683 // insertion index preference is reflected in common cases.
[email protected]78e2edc2012-07-01 23:32:28684 chrome::NavigateParams p(MakeNavigateParams());
[email protected]a1feae52010-10-11 22:14:45685 p.disposition = NEW_FOREGROUND_TAB;
686 p.tabstrip_index = 0;
687 p.tabstrip_add_types = TabStripModel::ADD_FORCE_INDEX;
[email protected]78e2edc2012-07-01 23:32:28688 chrome::Navigate(&p);
[email protected]a1feae52010-10-11 22:14:45689
690 // Navigate() should have inserted a new tab at slot 0 in the tabstrip.
691 EXPECT_EQ(browser(), p.browser);
[email protected]c0849252012-05-12 13:51:27692 EXPECT_EQ(0, browser()->tab_strip_model()->GetIndexOfTabContents(
[email protected]4ebab8ee2012-06-11 22:52:01693 static_cast<const TabContents*>(p.target_contents)));
[email protected]a1feae52010-10-11 22:14:45694
695 // We should have one window - the browser() provided by the framework.
696 EXPECT_EQ(1u, BrowserList::size());
697 EXPECT_EQ(2, browser()->tab_count());
698}
699
[email protected]bb89e7482010-11-17 18:27:04700// This test verifies that constructing params with disposition = SINGLETON_TAB
[email protected]fee320542011-03-02 01:30:49701// and IGNORE_AND_NAVIGATE opens a new tab navigated to the specified URL if
[email protected]67ed83e2011-01-07 22:54:00702// no previous tab with that URL (minus the path) exists.
[email protected]bb89e7482010-11-17 18:27:04703IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
704 Disposition_SingletonTabNew_IgnorePath) {
[email protected]52877dbc62012-06-29 22:22:03705 chrome::AddSelectedTabWithURL(browser(), GetGoogleURL(),
706 content::PAGE_TRANSITION_LINK);
[email protected]bb89e7482010-11-17 18:27:04707
708 // We should have one browser with 2 tabs, the 2nd selected.
709 EXPECT_EQ(1u, BrowserList::size());
710 EXPECT_EQ(2, browser()->tab_count());
[email protected]1ea49d52011-04-12 17:44:44711 EXPECT_EQ(1, browser()->active_index());
[email protected]bb89e7482010-11-17 18:27:04712
713 // Navigate to a new singleton tab with a sub-page.
[email protected]78e2edc2012-07-01 23:32:28714 chrome::NavigateParams p(MakeNavigateParams());
[email protected]bb89e7482010-11-17 18:27:04715 p.disposition = SINGLETON_TAB;
[email protected]a048ad22012-03-23 04:26:56716 p.url = GetContentSettingsURL();
[email protected]78e2edc2012-07-01 23:32:28717 p.window_action = chrome::NavigateParams::SHOW_WINDOW;
718 p.path_behavior = chrome::NavigateParams::IGNORE_AND_NAVIGATE;
719 chrome::Navigate(&p);
[email protected]bb89e7482010-11-17 18:27:04720
721 // The last tab should now be selected and navigated to the sub-page of the
722 // URL.
723 EXPECT_EQ(browser(), p.browser);
724 EXPECT_EQ(3, browser()->tab_count());
[email protected]1ea49d52011-04-12 17:44:44725 EXPECT_EQ(2, browser()->active_index());
[email protected]a048ad22012-03-23 04:26:56726 EXPECT_EQ(GetContentSettingsURL(),
[email protected]52877dbc62012-06-29 22:22:03727 chrome::GetActiveWebContents(browser())->GetURL());
[email protected]bb89e7482010-11-17 18:27:04728}
729
730// This test verifies that constructing params with disposition = SINGLETON_TAB
[email protected]fee320542011-03-02 01:30:49731// and IGNORE_AND_NAVIGATE opens an existing tab with the matching URL (minus
[email protected]bb89e7482010-11-17 18:27:04732// the path) which is navigated to the specified URL.
733IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
734 Disposition_SingletonTabExisting_IgnorePath) {
[email protected]ddddfda2011-07-14 23:19:39735 GURL singleton_url1(GetSettingsURL());
[email protected]52877dbc62012-06-29 22:22:03736 chrome::AddSelectedTabWithURL(browser(), singleton_url1,
737 content::PAGE_TRANSITION_LINK);
738 chrome::AddSelectedTabWithURL(browser(), GetGoogleURL(),
739 content::PAGE_TRANSITION_LINK);
[email protected]bb89e7482010-11-17 18:27:04740
741 // We should have one browser with 3 tabs, the 3rd selected.
742 EXPECT_EQ(1u, BrowserList::size());
743 EXPECT_EQ(3, browser()->tab_count());
[email protected]1ea49d52011-04-12 17:44:44744 EXPECT_EQ(2, browser()->active_index());
[email protected]bb89e7482010-11-17 18:27:04745
746 // Navigate to singleton_url1.
[email protected]78e2edc2012-07-01 23:32:28747 chrome::NavigateParams p(MakeNavigateParams());
[email protected]bb89e7482010-11-17 18:27:04748 p.disposition = SINGLETON_TAB;
[email protected]a048ad22012-03-23 04:26:56749 p.url = GetContentSettingsURL();
[email protected]78e2edc2012-07-01 23:32:28750 p.window_action = chrome::NavigateParams::SHOW_WINDOW;
751 p.path_behavior = chrome::NavigateParams::IGNORE_AND_NAVIGATE;
752 chrome::Navigate(&p);
[email protected]bb89e7482010-11-17 18:27:04753
754 // The middle tab should now be selected and navigated to the sub-page of the
755 // URL.
756 EXPECT_EQ(browser(), p.browser);
757 EXPECT_EQ(3, browser()->tab_count());
[email protected]1ea49d52011-04-12 17:44:44758 EXPECT_EQ(1, browser()->active_index());
[email protected]a048ad22012-03-23 04:26:56759 EXPECT_EQ(GetContentSettingsURL(),
[email protected]52877dbc62012-06-29 22:22:03760 chrome::GetActiveWebContents(browser())->GetURL());
[email protected]bb89e7482010-11-17 18:27:04761}
762
763// This test verifies that constructing params with disposition = SINGLETON_TAB
[email protected]fee320542011-03-02 01:30:49764// and IGNORE_AND_NAVIGATE opens an existing tab with the matching URL (minus
[email protected]bb89e7482010-11-17 18:27:04765// the path) which is navigated to the specified URL.
766IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
767 Disposition_SingletonTabExistingSubPath_IgnorePath) {
[email protected]a048ad22012-03-23 04:26:56768 GURL singleton_url1(GetContentSettingsURL());
[email protected]52877dbc62012-06-29 22:22:03769 chrome::AddSelectedTabWithURL(browser(), singleton_url1,
770 content::PAGE_TRANSITION_LINK);
771 chrome::AddSelectedTabWithURL(browser(), GetGoogleURL(),
772 content::PAGE_TRANSITION_LINK);
[email protected]bb89e7482010-11-17 18:27:04773
774 // We should have one browser with 3 tabs, the 3rd selected.
775 EXPECT_EQ(1u, BrowserList::size());
776 EXPECT_EQ(3, browser()->tab_count());
[email protected]1ea49d52011-04-12 17:44:44777 EXPECT_EQ(2, browser()->active_index());
[email protected]bb89e7482010-11-17 18:27:04778
779 // Navigate to singleton_url1.
[email protected]78e2edc2012-07-01 23:32:28780 chrome::NavigateParams p(MakeNavigateParams());
[email protected]bb89e7482010-11-17 18:27:04781 p.disposition = SINGLETON_TAB;
[email protected]a048ad22012-03-23 04:26:56782 p.url = GetClearBrowsingDataURL();
[email protected]78e2edc2012-07-01 23:32:28783 p.window_action = chrome::NavigateParams::SHOW_WINDOW;
784 p.path_behavior = chrome::NavigateParams::IGNORE_AND_NAVIGATE;
785 chrome::Navigate(&p);
[email protected]bb89e7482010-11-17 18:27:04786
787 // The middle tab should now be selected and navigated to the sub-page of the
788 // URL.
789 EXPECT_EQ(browser(), p.browser);
790 EXPECT_EQ(3, browser()->tab_count());
[email protected]1ea49d52011-04-12 17:44:44791 EXPECT_EQ(1, browser()->active_index());
[email protected]a048ad22012-03-23 04:26:56792 EXPECT_EQ(GetClearBrowsingDataURL(),
[email protected]52877dbc62012-06-29 22:22:03793 chrome::GetActiveWebContents(browser())->GetURL());
[email protected]bb89e7482010-11-17 18:27:04794}
[email protected]2dd85482010-11-06 01:56:47795
[email protected]637b3442011-01-10 23:31:48796// This test verifies that constructing params with disposition = SINGLETON_TAB
[email protected]fee320542011-03-02 01:30:49797// and IGNORE_AND_STAY_PUT opens an existing tab with the matching URL (minus
798// the path).
799IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
800 Disposition_SingletonTabExistingSubPath_IgnorePath2) {
[email protected]a048ad22012-03-23 04:26:56801 GURL singleton_url1(GetContentSettingsURL());
[email protected]52877dbc62012-06-29 22:22:03802 chrome::AddSelectedTabWithURL(browser(), singleton_url1,
803 content::PAGE_TRANSITION_LINK);
804 chrome::AddSelectedTabWithURL(browser(), GetGoogleURL(),
805 content::PAGE_TRANSITION_LINK);
[email protected]fee320542011-03-02 01:30:49806
807 // We should have one browser with 3 tabs, the 3rd selected.
808 EXPECT_EQ(1u, BrowserList::size());
809 EXPECT_EQ(3, browser()->tab_count());
[email protected]1ea49d52011-04-12 17:44:44810 EXPECT_EQ(2, browser()->active_index());
[email protected]fee320542011-03-02 01:30:49811
812 // Navigate to singleton_url1.
[email protected]78e2edc2012-07-01 23:32:28813 chrome::NavigateParams p(MakeNavigateParams());
[email protected]fee320542011-03-02 01:30:49814 p.disposition = SINGLETON_TAB;
[email protected]a048ad22012-03-23 04:26:56815 p.url = GetClearBrowsingDataURL();
[email protected]78e2edc2012-07-01 23:32:28816 p.window_action = chrome::NavigateParams::SHOW_WINDOW;
817 p.path_behavior = chrome::NavigateParams::IGNORE_AND_STAY_PUT;
818 chrome::Navigate(&p);
[email protected]fee320542011-03-02 01:30:49819
820 // The middle tab should now be selected.
821 EXPECT_EQ(browser(), p.browser);
822 EXPECT_EQ(3, browser()->tab_count());
[email protected]1ea49d52011-04-12 17:44:44823 EXPECT_EQ(1, browser()->active_index());
[email protected]fee320542011-03-02 01:30:49824 EXPECT_EQ(singleton_url1,
[email protected]52877dbc62012-06-29 22:22:03825 chrome::GetActiveWebContents(browser())->GetURL());
[email protected]fee320542011-03-02 01:30:49826}
827
828// This test verifies that constructing params with disposition = SINGLETON_TAB
829// and IGNORE_AND_NAVIGATE will update the current tab's URL if the currently
[email protected]637b3442011-01-10 23:31:48830// selected tab is a match but has a different path.
831IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
832 Disposition_SingletonTabFocused_IgnorePath) {
[email protected]a048ad22012-03-23 04:26:56833 GURL singleton_url_current(GetContentSettingsURL());
[email protected]52877dbc62012-06-29 22:22:03834 chrome::AddSelectedTabWithURL(browser(), singleton_url_current,
835 content::PAGE_TRANSITION_LINK);
[email protected]637b3442011-01-10 23:31:48836
837 // We should have one browser with 2 tabs, the 2nd selected.
838 EXPECT_EQ(1u, BrowserList::size());
839 EXPECT_EQ(2, browser()->tab_count());
[email protected]1ea49d52011-04-12 17:44:44840 EXPECT_EQ(1, browser()->active_index());
[email protected]637b3442011-01-10 23:31:48841
842 // Navigate to a different settings path.
[email protected]a048ad22012-03-23 04:26:56843 GURL singleton_url_target(GetClearBrowsingDataURL());
[email protected]78e2edc2012-07-01 23:32:28844 chrome::NavigateParams p(MakeNavigateParams());
[email protected]637b3442011-01-10 23:31:48845 p.disposition = SINGLETON_TAB;
846 p.url = singleton_url_target;
[email protected]78e2edc2012-07-01 23:32:28847 p.window_action = chrome::NavigateParams::SHOW_WINDOW;
848 p.path_behavior = chrome::NavigateParams::IGNORE_AND_NAVIGATE;
849 chrome::Navigate(&p);
[email protected]637b3442011-01-10 23:31:48850
851 // The second tab should still be selected, but navigated to the new path.
852 EXPECT_EQ(browser(), p.browser);
853 EXPECT_EQ(2, browser()->tab_count());
[email protected]1ea49d52011-04-12 17:44:44854 EXPECT_EQ(1, browser()->active_index());
[email protected]637b3442011-01-10 23:31:48855 EXPECT_EQ(singleton_url_target,
[email protected]52877dbc62012-06-29 22:22:03856 chrome::GetActiveWebContents(browser())->GetURL());
[email protected]637b3442011-01-10 23:31:48857}
858
[email protected]07afd7c2011-02-17 10:07:11859// This test verifies that constructing params with disposition = SINGLETON_TAB
[email protected]fee320542011-03-02 01:30:49860// and IGNORE_AND_NAVIGATE will open an existing matching tab with a different
861// query.
[email protected]07afd7c2011-02-17 10:07:11862IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
863 Disposition_SingletonTabExisting_IgnoreQuery) {
864 int initial_tab_count = browser()->tab_count();
865 GURL singleton_url_current("chrome://settings/internet");
[email protected]52877dbc62012-06-29 22:22:03866 chrome::AddSelectedTabWithURL(browser(), singleton_url_current,
867 content::PAGE_TRANSITION_LINK);
[email protected]07afd7c2011-02-17 10:07:11868
869 EXPECT_EQ(initial_tab_count + 1, browser()->tab_count());
[email protected]1ea49d52011-04-12 17:44:44870 EXPECT_EQ(initial_tab_count, browser()->active_index());
[email protected]07afd7c2011-02-17 10:07:11871
872 // Navigate to a different settings path.
873 GURL singleton_url_target(
874 "chrome://settings/internet?"
875 "servicePath=/profile/ethernet_00aa00aa00aa&networkType=1");
[email protected]78e2edc2012-07-01 23:32:28876 chrome::NavigateParams p(MakeNavigateParams());
[email protected]07afd7c2011-02-17 10:07:11877 p.disposition = SINGLETON_TAB;
878 p.url = singleton_url_target;
[email protected]78e2edc2012-07-01 23:32:28879 p.window_action = chrome::NavigateParams::SHOW_WINDOW;
880 p.path_behavior = chrome::NavigateParams::IGNORE_AND_NAVIGATE;
881 chrome::Navigate(&p);
[email protected]07afd7c2011-02-17 10:07:11882
883 // Last tab should still be selected.
884 EXPECT_EQ(browser(), p.browser);
885 EXPECT_EQ(initial_tab_count + 1, browser()->tab_count());
[email protected]1ea49d52011-04-12 17:44:44886 EXPECT_EQ(initial_tab_count, browser()->active_index());
[email protected]07afd7c2011-02-17 10:07:11887}
888
[email protected]bd817c22011-02-09 08:16:46889// This test verifies that the settings page isn't opened in the incognito
890// window.
[email protected]a048ad22012-03-23 04:26:56891// Disabled until fixed for uber settings: http://crbug.com/111243
[email protected]bd817c22011-02-09 08:16:46892IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
[email protected]a048ad22012-03-23 04:26:56893 DISABLED_Disposition_Settings_UseNonIncognitoWindow) {
[email protected]fc0ed302011-11-29 23:17:19894 RunUseNonIncognitoWindowTest(GetSettingsURL());
[email protected]bd817c22011-02-09 08:16:46895}
896
[email protected]82404cd2011-07-12 19:55:14897// This test verifies that the settings page isn't opened in the incognito
898// window from a non-incognito window (bookmark open-in-incognito trigger).
[email protected]a048ad22012-03-23 04:26:56899// Disabled until fixed for uber settings: http://crbug.com/111243
[email protected]82404cd2011-07-12 19:55:14900IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
[email protected]a048ad22012-03-23 04:26:56901 DISABLED_Disposition_Settings_UseNonIncognitoWindowForBookmark) {
[email protected]78e2edc2012-07-01 23:32:28902 chrome::NavigateParams params(browser(), GetSettingsURL(),
903 content::PAGE_TRANSITION_AUTO_BOOKMARK);
[email protected]82404cd2011-07-12 19:55:14904 params.disposition = OFF_THE_RECORD;
905 {
906 ui_test_utils::WindowedNotificationObserver observer(
[email protected]ad50def52011-10-19 23:17:07907 content::NOTIFICATION_LOAD_STOP,
908 content::NotificationService::AllSources());
[email protected]78e2edc2012-07-01 23:32:28909 chrome::Navigate(&params);
[email protected]82404cd2011-07-12 19:55:14910 observer.Wait();
911 }
912
913 EXPECT_EQ(1u, BrowserList::size());
[email protected]52877dbc62012-06-29 22:22:03914 EXPECT_EQ(GetSettingsURL(),
915 chrome::GetActiveWebContents(browser())->GetURL());
[email protected]82404cd2011-07-12 19:55:14916}
917
[email protected]93ad8e1c2011-11-08 21:34:05918// Settings page is expected to always open in normal mode regardless
919// of whether the user is trying to open it in incognito mode or not.
920// This test verifies that if incognito mode is forced (by policy), settings
921// page doesn't open at all.
[email protected]a048ad22012-03-23 04:26:56922// Disabled until fixed for uber settings: http://crbug.com/111243
[email protected]93ad8e1c2011-11-08 21:34:05923IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
[email protected]a048ad22012-03-23 04:26:56924 DISABLED_Disposition_Settings_DoNothingIfIncognitoIsForced) {
[email protected]fc0ed302011-11-29 23:17:19925 RunDoNothingIfIncognitoIsForcedTest(GetSettingsURL());
[email protected]93ad8e1c2011-11-08 21:34:05926}
927
[email protected]bd817c22011-02-09 08:16:46928// This test verifies that the bookmarks page isn't opened in the incognito
929// window.
930IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
931 Disposition_Bookmarks_UseNonIncognitoWindow) {
[email protected]fc0ed302011-11-29 23:17:19932 RunUseNonIncognitoWindowTest(GURL(chrome::kChromeUIBookmarksURL));
[email protected]bd817c22011-02-09 08:16:46933}
934
[email protected]93ad8e1c2011-11-08 21:34:05935// Bookmark manager is expected to always open in normal mode regardless
936// of whether the user is trying to open it in incognito mode or not.
937// This test verifies that if incognito mode is forced (by policy), bookmark
938// manager doesn't open at all.
939IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
940 Disposition_Bookmarks_DoNothingIfIncognitoIsForced) {
[email protected]fc0ed302011-11-29 23:17:19941 RunDoNothingIfIncognitoIsForcedTest(GURL(chrome::kChromeUIBookmarksURL));
942}
[email protected]93ad8e1c2011-11-08 21:34:05943
[email protected]fc0ed302011-11-29 23:17:19944// This test verifies that the sync promo page isn't opened in the incognito
945// window.
946IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
947 Disposition_SyncPromo_UseNonIncognitoWindow) {
948 RunUseNonIncognitoWindowTest(GURL(chrome::kChromeUISyncPromoURL));
949}
[email protected]93ad8e1c2011-11-08 21:34:05950
[email protected]fc0ed302011-11-29 23:17:19951// The Sync promo page is expected to always open in normal mode regardless of
952// whether the user is trying to open it in incognito mode or not. This test
953// verifies that if incognito mode is forced (by policy), the sync promo page
954// doesn't open at all.
955IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
956 Disposition_SyncPromo_DoNothingIfIncognitoIsForced) {
957 RunDoNothingIfIncognitoIsForcedTest(GURL(chrome::kChromeUISyncPromoURL));
[email protected]93ad8e1c2011-11-08 21:34:05958}
959
[email protected]7de53c62011-05-13 06:44:16960// This test makes sure a crashed singleton tab reloads from a new navigation.
961IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
962 NavigateToCrashedSingletonTab) {
[email protected]a048ad22012-03-23 04:26:56963 GURL singleton_url(GetContentSettingsURL());
[email protected]52877dbc62012-06-29 22:22:03964 TabContents* tab_contents = chrome::AddSelectedTabWithURL(
965 browser(), singleton_url, content::PAGE_TRANSITION_LINK);
[email protected]4ebab8ee2012-06-11 22:52:01966 WebContents* web_contents = tab_contents->web_contents();
[email protected]7de53c62011-05-13 06:44:16967
968 // We should have one browser with 2 tabs, the 2nd selected.
969 EXPECT_EQ(1u, BrowserList::size());
970 EXPECT_EQ(2, browser()->tab_count());
971 EXPECT_EQ(1, browser()->active_index());
972
973 // Kill the singleton tab.
[email protected]83ff91c2012-01-05 20:54:13974 web_contents->SetIsCrashed(base::TERMINATION_STATUS_PROCESS_CRASHED, -1);
975 EXPECT_TRUE(web_contents->IsCrashed());
[email protected]7de53c62011-05-13 06:44:16976
[email protected]78e2edc2012-07-01 23:32:28977 chrome::NavigateParams p(MakeNavigateParams());
[email protected]7de53c62011-05-13 06:44:16978 p.disposition = SINGLETON_TAB;
979 p.url = singleton_url;
[email protected]78e2edc2012-07-01 23:32:28980 p.window_action = chrome::NavigateParams::SHOW_WINDOW;
981 p.path_behavior = chrome::NavigateParams::IGNORE_AND_NAVIGATE;
[email protected]ddddfda2011-07-14 23:19:39982 ui_test_utils::NavigateToURL(&p);
[email protected]7de53c62011-05-13 06:44:16983
984 // The tab should not be sad anymore.
[email protected]83ff91c2012-01-05 20:54:13985 EXPECT_FALSE(web_contents->IsCrashed());
[email protected]7de53c62011-05-13 06:44:16986}
987
[email protected]fcca741b2011-06-17 22:46:37988IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
989 NavigateFromDefaultToOptionsInSameTab) {
[email protected]ddddfda2011-07-14 23:19:39990 {
991 ui_test_utils::WindowedNotificationObserver observer(
[email protected]ad50def52011-10-19 23:17:07992 content::NOTIFICATION_LOAD_STOP,
993 content::NotificationService::AllSources());
[email protected]5d9cace72012-06-21 16:07:12994 chrome::ShowSettings(browser());
[email protected]ddddfda2011-07-14 23:19:39995 observer.Wait();
996 }
[email protected]fcca741b2011-06-17 22:46:37997 EXPECT_EQ(1, browser()->tab_count());
[email protected]52877dbc62012-06-29 22:22:03998 EXPECT_EQ(GetSettingsURL(),
999 chrome::GetActiveWebContents(browser())->GetURL());
[email protected]fcca741b2011-06-17 22:46:371000}
1001
1002IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
1003 NavigateFromBlankToOptionsInSameTab) {
[email protected]78e2edc2012-07-01 23:32:281004 chrome::NavigateParams p(MakeNavigateParams());
[email protected]ddddfda2011-07-14 23:19:391005 p.url = GURL(chrome::kAboutBlankURL);
1006 ui_test_utils::NavigateToURL(&p);
[email protected]fcca741b2011-06-17 22:46:371007
[email protected]ddddfda2011-07-14 23:19:391008 {
1009 ui_test_utils::WindowedNotificationObserver observer(
[email protected]ad50def52011-10-19 23:17:071010 content::NOTIFICATION_LOAD_STOP,
1011 content::NotificationService::AllSources());
[email protected]5d9cace72012-06-21 16:07:121012 chrome::ShowSettings(browser());
[email protected]ddddfda2011-07-14 23:19:391013 observer.Wait();
1014 }
[email protected]fcca741b2011-06-17 22:46:371015 EXPECT_EQ(1, browser()->tab_count());
[email protected]52877dbc62012-06-29 22:22:031016 EXPECT_EQ(GetSettingsURL(),
1017 chrome::GetActiveWebContents(browser())->GetURL());
[email protected]fcca741b2011-06-17 22:46:371018}
1019
1020IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
1021 NavigateFromNTPToOptionsInSameTab) {
[email protected]78e2edc2012-07-01 23:32:281022 chrome::NavigateParams p(MakeNavigateParams());
[email protected]ddddfda2011-07-14 23:19:391023 p.url = GURL(chrome::kChromeUINewTabURL);
1024 ui_test_utils::NavigateToURL(&p);
[email protected]fcca741b2011-06-17 22:46:371025 EXPECT_EQ(1, browser()->tab_count());
[email protected]ddddfda2011-07-14 23:19:391026 EXPECT_EQ(GURL(chrome::kChromeUINewTabURL),
[email protected]52877dbc62012-06-29 22:22:031027 chrome::GetActiveWebContents(browser())->GetURL());
[email protected]fcca741b2011-06-17 22:46:371028
[email protected]ddddfda2011-07-14 23:19:391029 {
1030 ui_test_utils::WindowedNotificationObserver observer(
[email protected]ad50def52011-10-19 23:17:071031 content::NOTIFICATION_LOAD_STOP,
1032 content::NotificationService::AllSources());
[email protected]5d9cace72012-06-21 16:07:121033 chrome::ShowSettings(browser());
[email protected]ddddfda2011-07-14 23:19:391034 observer.Wait();
1035 }
[email protected]fcca741b2011-06-17 22:46:371036 EXPECT_EQ(1, browser()->tab_count());
[email protected]52877dbc62012-06-29 22:22:031037 EXPECT_EQ(GetSettingsURL(),
1038 chrome::GetActiveWebContents(browser())->GetURL());
[email protected]fcca741b2011-06-17 22:46:371039}
1040
1041IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
1042 NavigateFromPageToOptionsInNewTab) {
[email protected]78e2edc2012-07-01 23:32:281043 chrome::NavigateParams p(MakeNavigateParams());
[email protected]ddddfda2011-07-14 23:19:391044 ui_test_utils::NavigateToURL(&p);
[email protected]52877dbc62012-06-29 22:22:031045 EXPECT_EQ(GetGoogleURL(), chrome::GetActiveWebContents(browser())->GetURL());
[email protected]fcca741b2011-06-17 22:46:371046 EXPECT_EQ(1u, BrowserList::size());
1047 EXPECT_EQ(1, browser()->tab_count());
1048
[email protected]ddddfda2011-07-14 23:19:391049 {
1050 ui_test_utils::WindowedNotificationObserver observer(
[email protected]ad50def52011-10-19 23:17:071051 content::NOTIFICATION_LOAD_STOP,
1052 content::NotificationService::AllSources());
[email protected]5d9cace72012-06-21 16:07:121053 chrome::ShowSettings(browser());
[email protected]ddddfda2011-07-14 23:19:391054 observer.Wait();
1055 }
[email protected]fcca741b2011-06-17 22:46:371056 EXPECT_EQ(2, browser()->tab_count());
[email protected]52877dbc62012-06-29 22:22:031057 EXPECT_EQ(GetSettingsURL(),
1058 chrome::GetActiveWebContents(browser())->GetURL());
[email protected]fcca741b2011-06-17 22:46:371059}
1060
1061IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
1062 NavigateFromNTPToOptionsSingleton) {
[email protected]ddddfda2011-07-14 23:19:391063 {
1064 ui_test_utils::WindowedNotificationObserver observer(
[email protected]ad50def52011-10-19 23:17:071065 content::NOTIFICATION_LOAD_STOP,
1066 content::NotificationService::AllSources());
[email protected]5d9cace72012-06-21 16:07:121067 chrome::ShowSettings(browser());
[email protected]ddddfda2011-07-14 23:19:391068 observer.Wait();
1069 }
[email protected]fcca741b2011-06-17 22:46:371070 EXPECT_EQ(1, browser()->tab_count());
1071
[email protected]a37d4b02012-06-25 21:56:101072 chrome::NewTab(browser());
[email protected]fcca741b2011-06-17 22:46:371073 EXPECT_EQ(2, browser()->tab_count());
1074
[email protected]ddddfda2011-07-14 23:19:391075 {
1076 ui_test_utils::WindowedNotificationObserver observer(
[email protected]ad50def52011-10-19 23:17:071077 content::NOTIFICATION_LOAD_STOP,
1078 content::NotificationService::AllSources());
[email protected]5d9cace72012-06-21 16:07:121079 chrome::ShowSettings(browser());
[email protected]ddddfda2011-07-14 23:19:391080 observer.Wait();
1081 }
[email protected]fcca741b2011-06-17 22:46:371082 EXPECT_EQ(2, browser()->tab_count());
[email protected]52877dbc62012-06-29 22:22:031083 EXPECT_EQ(GetSettingsURL(),
1084 chrome::GetActiveWebContents(browser())->GetURL());
[email protected]fcca741b2011-06-17 22:46:371085}
1086
1087IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
1088 NavigateFromNTPToOptionsPageInSameTab) {
[email protected]ddddfda2011-07-14 23:19:391089 {
1090 ui_test_utils::WindowedNotificationObserver observer(
[email protected]ad50def52011-10-19 23:17:071091 content::NOTIFICATION_LOAD_STOP,
1092 content::NotificationService::AllSources());
[email protected]5d9cace72012-06-21 16:07:121093 chrome::ShowClearBrowsingDataDialog(browser());
[email protected]ddddfda2011-07-14 23:19:391094 observer.Wait();
1095 }
[email protected]fcca741b2011-06-17 22:46:371096 EXPECT_EQ(1, browser()->tab_count());
[email protected]a048ad22012-03-23 04:26:561097 EXPECT_EQ(GetClearBrowsingDataURL(),
[email protected]52877dbc62012-06-29 22:22:031098 chrome::GetActiveWebContents(browser())->GetURL());
[email protected]fcca741b2011-06-17 22:46:371099
[email protected]a37d4b02012-06-25 21:56:101100 chrome::NewTab(browser());
[email protected]fcca741b2011-06-17 22:46:371101 EXPECT_EQ(2, browser()->tab_count());
1102
[email protected]ddddfda2011-07-14 23:19:391103 {
1104 ui_test_utils::WindowedNotificationObserver observer(
[email protected]ad50def52011-10-19 23:17:071105 content::NOTIFICATION_LOAD_STOP,
1106 content::NotificationService::AllSources());
[email protected]5d9cace72012-06-21 16:07:121107 chrome::ShowClearBrowsingDataDialog(browser());
[email protected]ddddfda2011-07-14 23:19:391108 observer.Wait();
1109 }
[email protected]fcca741b2011-06-17 22:46:371110 EXPECT_EQ(2, browser()->tab_count());
[email protected]a048ad22012-03-23 04:26:561111 EXPECT_EQ(GetClearBrowsingDataURL(),
[email protected]52877dbc62012-06-29 22:22:031112 chrome::GetActiveWebContents(browser())->GetURL());
[email protected]fcca741b2011-06-17 22:46:371113}
1114
[email protected]ccb8aac2012-05-21 23:00:161115// Times out on mac, fails on linux.
1116// http://crbug.com/119779
1117#if defined(OS_MACOSX) || defined(OS_LINUX)
[email protected]aac43c72012-03-23 18:41:021118#define MAYBE_NavigateFromOtherTabToSingletonOptions DISABLED_NavigateFromOtherTabToSingletonOptions
1119#else
1120#define MAYBE_NavigateFromOtherTabToSingletonOptions NavigatorFrameOtherTabToSingletonOptions
1121#endif
[email protected]fcca741b2011-06-17 22:46:371122IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
[email protected]aac43c72012-03-23 18:41:021123 MAYBE_NavigateFromOtherTabToSingletonOptions) {
[email protected]ddddfda2011-07-14 23:19:391124 {
1125 ui_test_utils::WindowedNotificationObserver observer(
[email protected]ad50def52011-10-19 23:17:071126 content::NOTIFICATION_LOAD_STOP,
1127 content::NotificationService::AllSources());
[email protected]5d9cace72012-06-21 16:07:121128 chrome::ShowSettings(browser());
[email protected]ddddfda2011-07-14 23:19:391129 observer.Wait();
1130 }
1131 {
1132 ui_test_utils::WindowedNotificationObserver observer(
[email protected]ad50def52011-10-19 23:17:071133 content::NOTIFICATION_LOAD_STOP,
1134 content::NotificationService::AllSources());
[email protected]52877dbc62012-06-29 22:22:031135 chrome::AddSelectedTabWithURL(browser(), GetGoogleURL(),
1136 content::PAGE_TRANSITION_LINK);
[email protected]ddddfda2011-07-14 23:19:391137 observer.Wait();
1138 }
[email protected]fcca741b2011-06-17 22:46:371139
[email protected]ddddfda2011-07-14 23:19:391140 {
1141 ui_test_utils::WindowedNotificationObserver observer(
[email protected]ad50def52011-10-19 23:17:071142 content::NOTIFICATION_LOAD_STOP,
1143 content::NotificationService::AllSources());
[email protected]5d9cace72012-06-21 16:07:121144 chrome::ShowSettings(browser());
[email protected]ddddfda2011-07-14 23:19:391145 observer.Wait();
1146 }
[email protected]fcca741b2011-06-17 22:46:371147 EXPECT_EQ(2, browser()->tab_count());
[email protected]ddddfda2011-07-14 23:19:391148 EXPECT_EQ(GetSettingsURL(),
[email protected]52877dbc62012-06-29 22:22:031149 chrome::GetActiveWebContents(browser())->GetURL());
[email protected]fcca741b2011-06-17 22:46:371150}
1151
[email protected]26c53e662011-07-09 02:21:021152// Tests that when a new tab is opened from the omnibox, the focus is moved from
1153// the omnibox for the current tab.
1154IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
1155 NavigateFromOmniboxIntoNewTab) {
1156 GURL url("http://www.google.com/");
1157 GURL url2("http://maps.google.com/");
1158
1159 // Navigate to url.
[email protected]78e2edc2012-07-01 23:32:281160 chrome::NavigateParams p(MakeNavigateParams());
[email protected]26c53e662011-07-09 02:21:021161 p.disposition = CURRENT_TAB;
1162 p.url = url;
[email protected]78e2edc2012-07-01 23:32:281163 chrome::Navigate(&p);
[email protected]26c53e662011-07-09 02:21:021164
1165 // Focus the omnibox.
[email protected]a37d4b02012-06-25 21:56:101166 chrome::FocusLocationBar(browser());
[email protected]26c53e662011-07-09 02:21:021167
[email protected]fbdc4232012-06-24 15:28:371168 OmniboxEditController* controller =
[email protected]fb8e3a32012-05-10 21:03:521169 browser()->window()->GetLocationBar()->GetLocationEntry()->model()->
[email protected]26c53e662011-07-09 02:21:021170 controller();
1171
1172 // Simulate an alt-enter.
1173 controller->OnAutocompleteAccept(url2, NEW_FOREGROUND_TAB,
[email protected]2905f742011-10-13 03:51:581174 content::PAGE_TRANSITION_TYPED, GURL());
[email protected]26c53e662011-07-09 02:21:021175
1176 // Make sure the second tab is selected.
1177 EXPECT_EQ(1, browser()->active_index());
1178
1179 // The tab contents should have the focus in the second tab.
[email protected]f2159ba2012-04-17 19:13:211180 EXPECT_TRUE(ui_test_utils::IsViewFocused(browser(), VIEW_ID_TAB_CONTAINER));
[email protected]26c53e662011-07-09 02:21:021181
1182 // Go back to the first tab. The focus should not be in the omnibox.
[email protected]a37d4b02012-06-25 21:56:101183 chrome::SelectPreviousTab(browser());
[email protected]26c53e662011-07-09 02:21:021184 EXPECT_EQ(0, browser()->active_index());
1185 EXPECT_FALSE(ui_test_utils::IsViewFocused(browser(),
1186 VIEW_ID_LOCATION_BAR));
1187}
1188
[email protected]a048ad22012-03-23 04:26:561189// TODO(csilv): Update this for uber page. http://crbug.com/111579.
[email protected]ddddfda2011-07-14 23:19:391190IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
[email protected]a048ad22012-03-23 04:26:561191 DISABLED_NavigateFromDefaultToHistoryInSameTab) {
[email protected]ddddfda2011-07-14 23:19:391192 {
1193 ui_test_utils::WindowedNotificationObserver observer(
[email protected]ad50def52011-10-19 23:17:071194 content::NOTIFICATION_LOAD_STOP,
1195 content::NotificationService::AllSources());
[email protected]5d9cace72012-06-21 16:07:121196 chrome::ShowHistory(browser());
[email protected]ddddfda2011-07-14 23:19:391197 observer.Wait();
1198 }
1199 EXPECT_EQ(1, browser()->tab_count());
[email protected]11e03fb2012-03-03 19:07:051200 EXPECT_EQ(GURL(chrome::kChromeUIHistoryFrameURL),
[email protected]52877dbc62012-06-29 22:22:031201 chrome::GetActiveWebContents(browser())->GetURL());
[email protected]ddddfda2011-07-14 23:19:391202}
1203
1204IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
1205 NavigateFromDefaultToBookmarksInSameTab) {
1206 {
1207 ui_test_utils::WindowedNotificationObserver observer(
[email protected]ad50def52011-10-19 23:17:071208 content::NOTIFICATION_LOAD_STOP,
1209 content::NotificationService::AllSources());
[email protected]5d9cace72012-06-21 16:07:121210 chrome::ShowBookmarkManager(browser());
[email protected]ddddfda2011-07-14 23:19:391211 observer.Wait();
1212 }
1213 EXPECT_EQ(1, browser()->tab_count());
1214 EXPECT_EQ(GURL(chrome::kChromeUIBookmarksURL),
[email protected]52877dbc62012-06-29 22:22:031215 chrome::GetActiveWebContents(browser())->GetURL());
[email protected]ddddfda2011-07-14 23:19:391216}
1217
1218IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
1219 NavigateFromDefaultToDownloadsInSameTab) {
1220 {
1221 ui_test_utils::WindowedNotificationObserver observer(
[email protected]ad50def52011-10-19 23:17:071222 content::NOTIFICATION_LOAD_STOP,
1223 content::NotificationService::AllSources());
[email protected]5d9cace72012-06-21 16:07:121224 chrome::ShowDownloads(browser());
[email protected]ddddfda2011-07-14 23:19:391225 observer.Wait();
1226 }
1227 EXPECT_EQ(1, browser()->tab_count());
1228 EXPECT_EQ(GURL(chrome::kChromeUIDownloadsURL),
[email protected]52877dbc62012-06-29 22:22:031229 chrome::GetActiveWebContents(browser())->GetURL());
[email protected]ddddfda2011-07-14 23:19:391230}
1231
[email protected]675e779b2012-01-25 23:09:451232// This test makes sure any link in a crashed panel page navigates to a tabbed
1233// window.
1234class PanelBrowserNavigatorTest : public BrowserNavigatorTest {
1235 protected:
1236 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE {
1237 command_line->AppendSwitch(switches::kEnablePanels);
1238 }
1239};
1240
1241IN_PROC_BROWSER_TEST_F(PanelBrowserNavigatorTest, NavigateFromCrashedPanel) {
1242 GURL url("http://maps.google.com/#a");
1243 GURL url2("http://maps.google.com/#b");
1244
1245 // Create a panel.
[email protected]da22aa62012-04-04 18:54:351246 Browser* panel_browser = Browser::CreateWithParams(
1247 Browser::CreateParams::CreateForApp(
1248 Browser::TYPE_PANEL, "Test", gfx::Rect(100, 100),
1249 browser()->profile()));
[email protected]675e779b2012-01-25 23:09:451250
1251 // Navigate to the page.
[email protected]78e2edc2012-07-01 23:32:281252 chrome::NavigateParams p(MakeNavigateParams(panel_browser));
[email protected]675e779b2012-01-25 23:09:451253 p.url = url;
1254 p.disposition = CURRENT_TAB;
[email protected]78e2edc2012-07-01 23:32:281255 chrome::Navigate(&p);
[email protected]675e779b2012-01-25 23:09:451256
1257 // Navigate() should have navigated in the existing panel window.
1258 EXPECT_EQ(panel_browser, p.browser);
1259
1260 // We should now have two windows, the browser() provided by the framework and
1261 // the panel window we opened earlier. The tabbed browser window has 1 tab.
1262 EXPECT_EQ(2u, BrowserList::size());
1263 EXPECT_EQ(1, browser()->tab_count());
1264 EXPECT_EQ(1, panel_browser->tab_count());
1265
1266 // Kill the panel page.
[email protected]52877dbc62012-06-29 22:22:031267 WebContents* web_contents = chrome::GetActiveWebContents(panel_browser);
[email protected]675e779b2012-01-25 23:09:451268 web_contents->SetIsCrashed(base::TERMINATION_STATUS_PROCESS_CRASHED, -1);
1269 EXPECT_TRUE(web_contents->IsCrashed());
1270
1271 // Navigate to the page.
[email protected]78e2edc2012-07-01 23:32:281272 chrome::NavigateParams p2(MakeNavigateParams(panel_browser));
[email protected]52877dbc62012-06-29 22:22:031273 p2.source_contents = chrome::GetActiveTabContents(panel_browser);
[email protected]675e779b2012-01-25 23:09:451274 p2.url = url2;
1275 p2.disposition = CURRENT_TAB;
[email protected]78e2edc2012-07-01 23:32:281276 chrome::Navigate(&p2);
[email protected]675e779b2012-01-25 23:09:451277
1278 // Navigate() should have opened a new tab in the existing tabbed window.
1279 EXPECT_EQ(browser(), p2.browser);
1280
1281 // We should now have two windows, the browser() provided by the framework and
1282 // the panel window we opened earlier. The tabbed browser window has 2 tabs.
1283 EXPECT_EQ(2u, BrowserList::size());
1284 EXPECT_EQ(2, browser()->tab_count());
1285 EXPECT_EQ(1, panel_browser->tab_count());
1286}
1287
[email protected]ddddfda2011-07-14 23:19:391288} // namespace