blob: 57521ffdb22158e6c8a5e40a70846879bcaa0d17 [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]bd817c22011-02-09 08:16:4657browser::NavigateParams BrowserNavigatorTest::MakeNavigateParams() const {
58 return MakeNavigateParams(browser());
59}
[email protected]a1feae52010-10-11 22:14:4560
[email protected]bd817c22011-02-09 08:16:4661browser::NavigateParams BrowserNavigatorTest::MakeNavigateParams(
62 Browser* browser) const {
63 browser::NavigateParams params(browser, GetGoogleURL(),
[email protected]2905f742011-10-13 03:51:5864 content::PAGE_TRANSITION_LINK);
[email protected]7d329992011-04-15 18:20:0265 params.window_action = browser::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]bd817c22011-02-09 08:16:4673 browser->AddBlankTab(true);
74 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]b35b26b32011-05-05 20:35:1482 browser->AddBlankTab(true);
83 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]bd817c22011-02-09 08:16:4697 browser::NavigateParams p(MakeNavigateParams());
98 p.disposition = disposition;
99 browser::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.
115 browser::NavigateParams p(MakeNavigateParams(incognito_browser));
116 p.disposition = SINGLETON_TAB;
117 p.url = url;
118 p.window_action = browser::NavigateParams::SHOW_WINDOW;
119 browser::Navigate(&p);
120
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.
141 browser::NavigateParams p(MakeNavigateParams(browser));
142 p.disposition = OFF_THE_RECORD;
143 p.url = url;
144 p.window_action = browser::NavigateParams::SHOW_WINDOW;
145 browser::Navigate(&p);
146
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) {
159 case content::NOTIFICATION_RENDER_VIEW_HOST_CREATED_FOR_TAB: {
[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]432115822011-07-10 15:52:27192 registrar.Add(this, content::NOTIFICATION_RENDER_VIEW_HOST_CREATED_FOR_TAB,
[email protected]ad50def52011-10-19 23:17:07193 content::NotificationService::AllSources());
[email protected]fa7ebe02010-11-29 23:04:57194
[email protected]52877dbc62012-06-29 22:22:03195 chrome::AddSelectedTabWithURL(browser(), singleton_url1,
196 content::PAGE_TRANSITION_LINK);
197 chrome::AddSelectedTabWithURL(browser(), GetGoogleURL(),
198 content::PAGE_TRANSITION_LINK);
[email protected]19d9f3a2010-10-14 21:49:36199
200 // We should have one browser with 3 tabs, the 3rd selected.
201 EXPECT_EQ(1u, BrowserList::size());
[email protected]1ea49d52011-04-12 17:44:44202 EXPECT_EQ(2, browser()->active_index());
[email protected]19d9f3a2010-10-14 21:49:36203
[email protected]fa7ebe02010-11-29 23:04:57204 unsigned int previous_tab_contents_count =
205 created_tab_contents_count_ = 0;
206
[email protected]19d9f3a2010-10-14 21:49:36207 // Navigate to singleton_url1.
208 browser::NavigateParams p(MakeNavigateParams());
209 p.disposition = SINGLETON_TAB;
210 p.url = singleton_url1;
211 browser::Navigate(&p);
212
213 // The middle tab should now be selected.
214 EXPECT_EQ(browser(), p.browser);
[email protected]1ea49d52011-04-12 17:44:44215 EXPECT_EQ(1, browser()->active_index());
[email protected]fa7ebe02010-11-29 23:04:57216
217 // No tab contents should have been created
218 EXPECT_EQ(previous_tab_contents_count,
219 created_tab_contents_count_);
[email protected]19d9f3a2010-10-14 21:49:36220}
221
222IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
[email protected]578c6962011-08-24 22:06:40223 Disposition_SingletonTabRespectingRef) {
224 GURL singleton_ref_url1("http://maps.google.com/#a");
225 GURL singleton_ref_url2("http://maps.google.com/#b");
226 GURL singleton_ref_url3("http://maps.google.com/");
227
[email protected]52877dbc62012-06-29 22:22:03228 chrome::AddSelectedTabWithURL(browser(), singleton_ref_url1,
229 content::PAGE_TRANSITION_LINK);
[email protected]578c6962011-08-24 22:06:40230
231 // We should have one browser with 2 tabs, 2nd selected.
232 EXPECT_EQ(1u, BrowserList::size());
233 EXPECT_EQ(2, browser()->tab_count());
234 EXPECT_EQ(1, browser()->active_index());
235
236 // Navigate to singleton_url2.
237 browser::NavigateParams p(MakeNavigateParams());
238 p.disposition = SINGLETON_TAB;
239 p.url = singleton_ref_url2;
240 browser::Navigate(&p);
241
242 // We should now have 2 tabs, the 2nd one selected.
243 EXPECT_EQ(browser(), p.browser);
244 EXPECT_EQ(2, browser()->tab_count());
245 EXPECT_EQ(1, browser()->active_index());
246
247 // Navigate to singleton_url2, but with respect ref set.
248 p = MakeNavigateParams();
249 p.disposition = SINGLETON_TAB;
250 p.url = singleton_ref_url2;
251 p.ref_behavior = browser::NavigateParams::RESPECT_REF;
252 browser::Navigate(&p);
253
254 // We should now have 3 tabs, the 3th one selected.
255 EXPECT_EQ(browser(), p.browser);
256 EXPECT_EQ(3, browser()->tab_count());
257 EXPECT_EQ(2, browser()->active_index());
258
259 // Navigate to singleton_url3.
260 p = MakeNavigateParams();
261 p.disposition = SINGLETON_TAB;
262 p.url = singleton_ref_url3;
263 p.ref_behavior = browser::NavigateParams::RESPECT_REF;
264 browser::Navigate(&p);
265
266 // We should now have 4 tabs, the 4th one selected.
267 EXPECT_EQ(browser(), p.browser);
268 EXPECT_EQ(4, browser()->tab_count());
269 EXPECT_EQ(3, browser()->active_index());
270}
271
272IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
[email protected]19d9f3a2010-10-14 21:49:36273 Disposition_SingletonTabNoneExisting) {
[email protected]19d9f3a2010-10-14 21:49:36274 GURL singleton_url1("http://maps.google.com/");
275
[email protected]bd817c22011-02-09 08:16:46276 // We should have one browser with 1 tab.
[email protected]19d9f3a2010-10-14 21:49:36277 EXPECT_EQ(1u, BrowserList::size());
[email protected]1ea49d52011-04-12 17:44:44278 EXPECT_EQ(0, browser()->active_index());
[email protected]19d9f3a2010-10-14 21:49:36279
280 // Navigate to singleton_url1.
281 browser::NavigateParams p(MakeNavigateParams());
282 p.disposition = SINGLETON_TAB;
283 p.url = singleton_url1;
284 browser::Navigate(&p);
285
286 // We should now have 2 tabs, the 2nd one selected.
287 EXPECT_EQ(browser(), p.browser);
288 EXPECT_EQ(2, browser()->tab_count());
[email protected]1ea49d52011-04-12 17:44:44289 EXPECT_EQ(1, browser()->active_index());
[email protected]a1feae52010-10-11 22:14:45290}
291
292// This test verifies that when a navigation results in a foreground tab, the
293// tab count of the Browser increases and the selected tab shifts to the new
294// foreground tab.
295IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_NewForegroundTab) {
[email protected]52877dbc62012-06-29 22:22:03296 WebContents* old_contents = chrome::GetActiveWebContents(browser());
[email protected]a1feae52010-10-11 22:14:45297 browser::NavigateParams p(MakeNavigateParams());
298 p.disposition = NEW_FOREGROUND_TAB;
[email protected]19d9f3a2010-10-14 21:49:36299 browser::Navigate(&p);
[email protected]52877dbc62012-06-29 22:22:03300 EXPECT_NE(old_contents, chrome::GetActiveWebContents(browser()));
301 EXPECT_EQ(chrome::GetActiveTabContents(browser()), p.target_contents);
[email protected]a1feae52010-10-11 22:14:45302 EXPECT_EQ(2, browser()->tab_count());
303}
304
305// This test verifies that when a navigation results in a background tab, the
306// tab count of the Browser increases but the selected tab remains the same.
307IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_NewBackgroundTab) {
[email protected]52877dbc62012-06-29 22:22:03308 WebContents* old_contents = chrome::GetActiveWebContents(browser());
[email protected]a1feae52010-10-11 22:14:45309 browser::NavigateParams p(MakeNavigateParams());
310 p.disposition = NEW_BACKGROUND_TAB;
[email protected]19d9f3a2010-10-14 21:49:36311 browser::Navigate(&p);
[email protected]52877dbc62012-06-29 22:22:03312 WebContents* new_contents = chrome::GetActiveWebContents(browser());
[email protected]a1feae52010-10-11 22:14:45313 // The selected tab should have remained unchanged, since the new tab was
314 // opened in the background.
315 EXPECT_EQ(old_contents, new_contents);
316 EXPECT_EQ(2, browser()->tab_count());
317}
318
319// This test verifies that when a navigation requiring a new foreground tab
320// occurs in a Browser that cannot host multiple tabs, the new foreground tab
321// is created in an existing compatible Browser.
322IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
323 Disposition_IncompatibleWindow_Existing) {
324 // Open a foreground tab in a window that cannot open popups when there is an
325 // existing compatible window somewhere else that they can be opened within.
326 Browser* popup = CreateEmptyBrowserForType(Browser::TYPE_POPUP,
327 browser()->profile());
328 browser::NavigateParams p(MakeNavigateParams(popup));
329 p.disposition = NEW_FOREGROUND_TAB;
[email protected]19d9f3a2010-10-14 21:49:36330 browser::Navigate(&p);
[email protected]a1feae52010-10-11 22:14:45331
332 // Navigate() should have opened the tab in a different browser since the
333 // one we supplied didn't support additional tabs.
334 EXPECT_NE(popup, p.browser);
335
336 // Since browser() is an existing compatible tabbed browser, it should have
337 // opened the tab there.
338 EXPECT_EQ(browser(), p.browser);
339
340 // We should be left with 2 windows, the popup with one tab and the browser()
341 // provided by the framework with two.
342 EXPECT_EQ(2u, BrowserList::size());
343 EXPECT_EQ(1, popup->tab_count());
344 EXPECT_EQ(2, browser()->tab_count());
345}
346
347// This test verifies that when a navigation requiring a new foreground tab
348// occurs in a Browser that cannot host multiple tabs and no compatible Browser
349// that can is open, a compatible Browser is created.
350IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
351 Disposition_IncompatibleWindow_NoExisting) {
352 // We want to simulate not being able to find an existing window compatible
353 // with our non-tabbed browser window so Navigate() is forced to create a
354 // new compatible window. Because browser() supplied by the in-process
355 // browser testing framework is compatible with browser()->profile(), we
356 // need a different profile, and creating a popup window with an incognito
357 // profile is a quick and dirty way of achieving this.
358 Browser* popup = CreateEmptyBrowserForType(
[email protected]b35b26b32011-05-05 20:35:14359 Browser::TYPE_POPUP,
360 browser()->profile()->GetOffTheRecordProfile());
[email protected]a1feae52010-10-11 22:14:45361 browser::NavigateParams p(MakeNavigateParams(popup));
362 p.disposition = NEW_FOREGROUND_TAB;
[email protected]19d9f3a2010-10-14 21:49:36363 browser::Navigate(&p);
[email protected]a1feae52010-10-11 22:14:45364
365 // Navigate() should have opened the tab in a different browser since the
366 // one we supplied didn't support additional tabs.
367 EXPECT_NE(popup, p.browser);
368
369 // This time, browser() is _not_ compatible with popup since it is not an
370 // incognito window.
371 EXPECT_NE(browser(), p.browser);
372
373 // We should have three windows, each with one tab:
374 // 1. the browser() provided by the framework (unchanged in this test)
375 // 2. the incognito popup we created originally
376 // 3. the new incognito tabbed browser that was created by Navigate().
377 EXPECT_EQ(3u, BrowserList::size());
378 EXPECT_EQ(1, browser()->tab_count());
379 EXPECT_EQ(1, popup->tab_count());
380 EXPECT_EQ(1, p.browser->tab_count());
[email protected]b35b26b32011-05-05 20:35:14381 EXPECT_TRUE(p.browser->is_type_tabbed());
[email protected]a1feae52010-10-11 22:14:45382}
383
384// This test verifies that navigating with WindowOpenDisposition = NEW_POPUP
385// from a normal Browser results in a new Browser with TYPE_POPUP.
386IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_NewPopup) {
387 browser::NavigateParams p(MakeNavigateParams());
388 p.disposition = NEW_POPUP;
[email protected]588300d2011-04-28 21:06:35389 p.window_bounds = gfx::Rect(0, 0, 200, 200);
[email protected]7d329992011-04-15 18:20:02390 // Wait for new popup to to load and gain focus.
[email protected]ddddfda2011-07-14 23:19:39391 ui_test_utils::NavigateToURL(&p);
[email protected]a1feae52010-10-11 22:14:45392
[email protected]7d329992011-04-15 18:20:02393 // Navigate() should have opened a new, focused popup window.
[email protected]a1feae52010-10-11 22:14:45394 EXPECT_NE(browser(), p.browser);
[email protected]9db263a2011-04-15 20:53:47395#if 0
396 // TODO(stevenjb): Enable this test. See: crbug.com/79493
[email protected]7d329992011-04-15 18:20:02397 EXPECT_TRUE(p.browser->window()->IsActive());
398#endif
[email protected]b35b26b32011-05-05 20:35:14399 EXPECT_TRUE(p.browser->is_type_popup());
400 EXPECT_FALSE(p.browser->is_app());
[email protected]a1feae52010-10-11 22:14:45401
402 // We should have two windows, the browser() provided by the framework and the
403 // new popup window.
404 EXPECT_EQ(2u, BrowserList::size());
405 EXPECT_EQ(1, browser()->tab_count());
406 EXPECT_EQ(1, p.browser->tab_count());
407}
408
409// This test verifies that navigating with WindowOpenDisposition = NEW_POPUP
[email protected]f112b0f2011-05-26 01:53:52410// from a normal Browser results in a new Browser with is_app() true.
411IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_NewPopup_ExtensionId) {
412 browser::NavigateParams p(MakeNavigateParams());
413 p.disposition = NEW_POPUP;
414 p.extension_app_id = "extensionappid";
415 p.window_bounds = gfx::Rect(0, 0, 200, 200);
[email protected]f112b0f2011-05-26 01:53:52416 // Wait for new popup to to load and gain focus.
[email protected]ddddfda2011-07-14 23:19:39417 ui_test_utils::NavigateToURL(&p);
[email protected]f112b0f2011-05-26 01:53:52418
419 // Navigate() should have opened a new, focused popup window.
420 EXPECT_NE(browser(), p.browser);
421 EXPECT_TRUE(p.browser->is_type_popup());
422 EXPECT_TRUE(p.browser->is_app());
423
424 // We should have two windows, the browser() provided by the framework and the
425 // new popup window.
426 EXPECT_EQ(2u, BrowserList::size());
427 EXPECT_EQ(1, browser()->tab_count());
428 EXPECT_EQ(1, p.browser->tab_count());
429}
430
431// This test verifies that navigating with WindowOpenDisposition = NEW_POPUP
[email protected]300d1e52011-01-19 23:57:57432// from a normal popup results in a new Browser with TYPE_POPUP.
433IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_NewPopupFromPopup) {
434 // Open a popup.
435 browser::NavigateParams p1(MakeNavigateParams());
436 p1.disposition = NEW_POPUP;
[email protected]588300d2011-04-28 21:06:35437 p1.window_bounds = gfx::Rect(0, 0, 200, 200);
[email protected]300d1e52011-01-19 23:57:57438 browser::Navigate(&p1);
439 // Open another popup.
440 browser::NavigateParams p2(MakeNavigateParams(p1.browser));
441 p2.disposition = NEW_POPUP;
[email protected]588300d2011-04-28 21:06:35442 p2.window_bounds = gfx::Rect(0, 0, 200, 200);
[email protected]300d1e52011-01-19 23:57:57443 browser::Navigate(&p2);
444
445 // Navigate() should have opened a new normal popup window.
446 EXPECT_NE(p1.browser, p2.browser);
[email protected]b35b26b32011-05-05 20:35:14447 EXPECT_TRUE(p2.browser->is_type_popup());
448 EXPECT_FALSE(p2.browser->is_app());
[email protected]300d1e52011-01-19 23:57:57449
450 // We should have three windows, the browser() provided by the framework,
451 // the first popup window, and the second popup window.
452 EXPECT_EQ(3u, BrowserList::size());
453 EXPECT_EQ(1, browser()->tab_count());
454 EXPECT_EQ(1, p1.browser->tab_count());
455 EXPECT_EQ(1, p2.browser->tab_count());
456}
457
458// This test verifies that navigating with WindowOpenDisposition = NEW_POPUP
[email protected]a1feae52010-10-11 22:14:45459// from an app frame results in a new Browser with TYPE_APP_POPUP.
460IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
461 Disposition_NewPopupFromAppWindow) {
[email protected]b35b26b32011-05-05 20:35:14462 Browser* app_browser = CreateEmptyBrowserForApp(Browser::TYPE_TABBED,
463 browser()->profile());
[email protected]a1feae52010-10-11 22:14:45464 browser::NavigateParams p(MakeNavigateParams(app_browser));
465 p.disposition = NEW_POPUP;
[email protected]588300d2011-04-28 21:06:35466 p.window_bounds = gfx::Rect(0, 0, 200, 200);
[email protected]19d9f3a2010-10-14 21:49:36467 browser::Navigate(&p);
[email protected]a1feae52010-10-11 22:14:45468
469 // Navigate() should have opened a new popup app window.
470 EXPECT_NE(app_browser, p.browser);
471 EXPECT_NE(browser(), p.browser);
[email protected]b35b26b32011-05-05 20:35:14472 EXPECT_TRUE(p.browser->is_type_popup());
473 EXPECT_TRUE(p.browser->is_app());
[email protected]a1feae52010-10-11 22:14:45474
475 // We should now have three windows, the app window, the app popup it created,
476 // and the original browser() provided by the framework.
477 EXPECT_EQ(3u, BrowserList::size());
478 EXPECT_EQ(1, browser()->tab_count());
479 EXPECT_EQ(1, app_browser->tab_count());
480 EXPECT_EQ(1, p.browser->tab_count());
481}
482
483// This test verifies that navigating with WindowOpenDisposition = NEW_POPUP
[email protected]300d1e52011-01-19 23:57:57484// from an app popup results in a new Browser also of TYPE_APP_POPUP.
485IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
486 Disposition_NewPopupFromAppPopup) {
[email protected]b35b26b32011-05-05 20:35:14487 Browser* app_browser = CreateEmptyBrowserForApp(Browser::TYPE_TABBED,
488 browser()->profile());
[email protected]300d1e52011-01-19 23:57:57489 // Open an app popup.
490 browser::NavigateParams p1(MakeNavigateParams(app_browser));
491 p1.disposition = NEW_POPUP;
[email protected]588300d2011-04-28 21:06:35492 p1.window_bounds = gfx::Rect(0, 0, 200, 200);
[email protected]300d1e52011-01-19 23:57:57493 browser::Navigate(&p1);
494 // Now open another app popup.
495 browser::NavigateParams p2(MakeNavigateParams(p1.browser));
496 p2.disposition = NEW_POPUP;
[email protected]588300d2011-04-28 21:06:35497 p2.window_bounds = gfx::Rect(0, 0, 200, 200);
[email protected]300d1e52011-01-19 23:57:57498 browser::Navigate(&p2);
499
500 // Navigate() should have opened a new popup app window.
501 EXPECT_NE(browser(), p1.browser);
502 EXPECT_NE(p1.browser, p2.browser);
[email protected]b35b26b32011-05-05 20:35:14503 EXPECT_TRUE(p2.browser->is_type_popup());
504 EXPECT_TRUE(p2.browser->is_app());
[email protected]300d1e52011-01-19 23:57:57505
506 // We should now have four windows, the app window, the first app popup,
507 // the second app popup, and the original browser() provided by the framework.
508 EXPECT_EQ(4u, BrowserList::size());
509 EXPECT_EQ(1, browser()->tab_count());
510 EXPECT_EQ(1, app_browser->tab_count());
511 EXPECT_EQ(1, p1.browser->tab_count());
512 EXPECT_EQ(1, p2.browser->tab_count());
513}
514
515// This test verifies that navigating with WindowOpenDisposition = NEW_POPUP
[email protected]a1feae52010-10-11 22:14:45516// from an extension app tab results in a new Browser with TYPE_APP_POPUP.
517IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
518 Disposition_NewPopupFromExtensionApp) {
519 // TODO(beng): TBD.
520}
521
[email protected]7d329992011-04-15 18:20:02522// This test verifies that navigating with window_action = SHOW_WINDOW_INACTIVE
523// does not focus a new new popup window.
524IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_NewPopupUnfocused) {
525 browser::NavigateParams p(MakeNavigateParams());
526 p.disposition = NEW_POPUP;
[email protected]588300d2011-04-28 21:06:35527 p.window_bounds = gfx::Rect(0, 0, 200, 200);
[email protected]7d329992011-04-15 18:20:02528 p.window_action = browser::NavigateParams::SHOW_WINDOW_INACTIVE;
[email protected]7d329992011-04-15 18:20:02529 // Wait for new popup to load (and gain focus if the test fails).
[email protected]ddddfda2011-07-14 23:19:39530 ui_test_utils::NavigateToURL(&p);
[email protected]7d329992011-04-15 18:20:02531
532 // Navigate() should have opened a new, unfocused, popup window.
533 EXPECT_NE(browser(), p.browser);
534 EXPECT_EQ(Browser::TYPE_POPUP, p.browser->type());
[email protected]9db263a2011-04-15 20:53:47535#if 0
536// TODO(stevenjb): Enable this test. See: crbug.com/79493
[email protected]7d329992011-04-15 18:20:02537 EXPECT_FALSE(p.browser->window()->IsActive());
[email protected]7d329992011-04-15 18:20:02538#endif
[email protected]9db263a2011-04-15 20:53:47539}
[email protected]7d329992011-04-15 18:20:02540
[email protected]a1feae52010-10-11 22:14:45541// This test verifies that navigating with WindowOpenDisposition = NEW_WINDOW
542// always opens a new window.
543IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_NewWindow) {
544 browser::NavigateParams p(MakeNavigateParams());
545 p.disposition = NEW_WINDOW;
[email protected]19d9f3a2010-10-14 21:49:36546 browser::Navigate(&p);
[email protected]a1feae52010-10-11 22:14:45547
548 // Navigate() should have opened a new toplevel window.
549 EXPECT_NE(browser(), p.browser);
[email protected]b35b26b32011-05-05 20:35:14550 EXPECT_TRUE(p.browser->is_type_tabbed());
[email protected]a1feae52010-10-11 22:14:45551
552 // We should now have two windows, the browser() provided by the framework and
553 // the new normal window.
554 EXPECT_EQ(2u, BrowserList::size());
555 EXPECT_EQ(1, browser()->tab_count());
556 EXPECT_EQ(1, p.browser->tab_count());
557}
558
559// This test verifies that navigating with WindowOpenDisposition = INCOGNITO
560// opens a new incognito window if no existing incognito window is present.
561IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_Incognito) {
562 browser::NavigateParams p(MakeNavigateParams());
563 p.disposition = OFF_THE_RECORD;
[email protected]19d9f3a2010-10-14 21:49:36564 browser::Navigate(&p);
[email protected]a1feae52010-10-11 22:14:45565
566 // Navigate() should have opened a new toplevel incognito window.
567 EXPECT_NE(browser(), p.browser);
568 EXPECT_EQ(browser()->profile()->GetOffTheRecordProfile(),
569 p.browser->profile());
570
[email protected]d7ff3592010-11-30 21:50:46571 // |source_contents| should be set to NULL because the profile for the new
572 // page is different from the originating page.
573 EXPECT_EQ(NULL, p.source_contents);
574
[email protected]a1feae52010-10-11 22:14:45575 // We should now have two windows, the browser() provided by the framework and
576 // the new incognito window.
577 EXPECT_EQ(2u, BrowserList::size());
578 EXPECT_EQ(1, browser()->tab_count());
579 EXPECT_EQ(1, p.browser->tab_count());
580}
581
582// This test verifies that navigating with WindowOpenDisposition = INCOGNITO
583// reuses an existing incognito window when possible.
584IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_IncognitoRefocus) {
585 Browser* incognito_browser =
[email protected]b35b26b32011-05-05 20:35:14586 CreateEmptyBrowserForType(Browser::TYPE_TABBED,
[email protected]a1feae52010-10-11 22:14:45587 browser()->profile()->GetOffTheRecordProfile());
588 browser::NavigateParams p(MakeNavigateParams());
589 p.disposition = OFF_THE_RECORD;
[email protected]19d9f3a2010-10-14 21:49:36590 browser::Navigate(&p);
[email protected]a1feae52010-10-11 22:14:45591
592 // Navigate() should have opened a new tab in the existing incognito window.
593 EXPECT_NE(browser(), p.browser);
594 EXPECT_EQ(p.browser, incognito_browser);
595
596 // We should now have two windows, the browser() provided by the framework and
597 // the incognito window we opened earlier.
598 EXPECT_EQ(2u, BrowserList::size());
599 EXPECT_EQ(1, browser()->tab_count());
600 EXPECT_EQ(2, incognito_browser->tab_count());
601}
602
603// This test verifies that no navigation action occurs when
604// WindowOpenDisposition = SUPPRESS_OPEN.
605IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_SuppressOpen) {
606 RunSuppressTest(SUPPRESS_OPEN);
607}
608
609// This test verifies that no navigation action occurs when
610// WindowOpenDisposition = SAVE_TO_DISK.
611IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_SaveToDisk) {
612 RunSuppressTest(SAVE_TO_DISK);
613}
614
615// This test verifies that no navigation action occurs when
616// WindowOpenDisposition = IGNORE_ACTION.
617IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_IgnoreAction) {
618 RunSuppressTest(IGNORE_ACTION);
619}
620
[email protected]4ebab8ee2012-06-11 22:52:01621// This tests adding a foreground tab with a predefined TabContents.
[email protected]a1feae52010-10-11 22:14:45622IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, TargetContents_ForegroundTab) {
623 browser::NavigateParams p(MakeNavigateParams());
624 p.disposition = NEW_FOREGROUND_TAB;
625 p.target_contents = CreateTabContents();
[email protected]19d9f3a2010-10-14 21:49:36626 browser::Navigate(&p);
[email protected]a1feae52010-10-11 22:14:45627
628 // Navigate() should have opened the contents in a new foreground in the
629 // current Browser.
630 EXPECT_EQ(browser(), p.browser);
[email protected]52877dbc62012-06-29 22:22:03631 EXPECT_EQ(chrome::GetActiveTabContents(browser()), p.target_contents);
[email protected]a1feae52010-10-11 22:14:45632
633 // We should have one window, with two tabs.
634 EXPECT_EQ(1u, BrowserList::size());
635 EXPECT_EQ(2, browser()->tab_count());
636}
637
638#if defined(OS_WIN)
[email protected]4ebab8ee2012-06-11 22:52:01639// This tests adding a popup with a predefined TabContents.
[email protected]76edb672011-03-04 21:48:39640IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, DISABLED_TargetContents_Popup) {
[email protected]a1feae52010-10-11 22:14:45641 browser::NavigateParams p(MakeNavigateParams());
642 p.disposition = NEW_POPUP;
643 p.target_contents = CreateTabContents();
644 p.window_bounds = gfx::Rect(10, 10, 500, 500);
[email protected]19d9f3a2010-10-14 21:49:36645 browser::Navigate(&p);
[email protected]a1feae52010-10-11 22:14:45646
647 // Navigate() should have opened a new popup window.
648 EXPECT_NE(browser(), p.browser);
[email protected]b35b26b32011-05-05 20:35:14649 EXPECT_TRUE(p.browser->is_type_popup());
650 EXPECT_FALSE(p.browser->is_app());
[email protected]a1feae52010-10-11 22:14:45651
652 // The web platform is weird. The window bounds specified in
653 // |p.window_bounds| are used as follows:
654 // - the origin is used to position the window
[email protected]4ebab8ee2012-06-11 22:52:01655 // - the size is used to size the TabContents of the window.
[email protected]a1feae52010-10-11 22:14:45656 // As such the position of the resulting window will always match
657 // p.window_bounds.origin(), but its size will not. We need to match
658 // the size against the selected tab's view's container size.
659 // Only Windows positions the window according to |p.window_bounds.origin()| -
660 // on Mac the window is offset from the opener and on Linux it always opens
661 // at 0,0.
662 EXPECT_EQ(p.window_bounds.origin(),
663 p.browser->window()->GetRestoredBounds().origin());
664 // All platforms should respect size however provided width > 400 (Mac has a
665 // minimum window width of 400).
666 EXPECT_EQ(p.window_bounds.size(),
[email protected]83ff91c2012-01-05 20:54:13667 p.target_contents->web_contents()->GetView()->GetContainerSize());
[email protected]a1feae52010-10-11 22:14:45668
669 // We should have two windows, the new popup and the browser() provided by the
670 // framework.
671 EXPECT_EQ(2u, BrowserList::size());
672 EXPECT_EQ(1, browser()->tab_count());
673 EXPECT_EQ(1, p.browser->tab_count());
674}
675#endif
676
677// This tests adding a tab at a specific index.
678IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Tabstrip_InsertAtIndex) {
679 // This is not meant to be a comprehensive test of whether or not the tab
680 // implementation of the browser observes the insertion index. That is
681 // covered by the unit tests for TabStripModel. This merely verifies that
682 // insertion index preference is reflected in common cases.
683 browser::NavigateParams p(MakeNavigateParams());
684 p.disposition = NEW_FOREGROUND_TAB;
685 p.tabstrip_index = 0;
686 p.tabstrip_add_types = TabStripModel::ADD_FORCE_INDEX;
[email protected]19d9f3a2010-10-14 21:49:36687 browser::Navigate(&p);
[email protected]a1feae52010-10-11 22:14:45688
689 // Navigate() should have inserted a new tab at slot 0 in the tabstrip.
690 EXPECT_EQ(browser(), p.browser);
[email protected]c0849252012-05-12 13:51:27691 EXPECT_EQ(0, browser()->tab_strip_model()->GetIndexOfTabContents(
[email protected]4ebab8ee2012-06-11 22:52:01692 static_cast<const TabContents*>(p.target_contents)));
[email protected]a1feae52010-10-11 22:14:45693
694 // We should have one window - the browser() provided by the framework.
695 EXPECT_EQ(1u, BrowserList::size());
696 EXPECT_EQ(2, browser()->tab_count());
697}
698
[email protected]2dd85482010-11-06 01:56:47699// This test verifies that constructing params with a NULL browser has
700// the same result as navigating to a new foreground tab in the (only)
701// active browser. Tests are the same as for Disposition_NewForegroundTab.
702IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, NullBrowser_NewForegroundTab) {
[email protected]52877dbc62012-06-29 22:22:03703 WebContents* old_contents = chrome::GetActiveWebContents(browser());
[email protected]2dd85482010-11-06 01:56:47704 // Navigate with a NULL browser.
705 browser::NavigateParams p(MakeNavigateParams(NULL));
706 p.disposition = NEW_FOREGROUND_TAB;
707 p.profile = browser()->profile();
708 browser::Navigate(&p);
709
710 // Navigate() should have found browser() and create a new tab.
711 EXPECT_EQ(browser(), p.browser);
[email protected]52877dbc62012-06-29 22:22:03712 EXPECT_NE(old_contents, chrome::GetActiveWebContents(browser()));
713 EXPECT_EQ(chrome::GetActiveTabContents(browser()), p.target_contents);
[email protected]2dd85482010-11-06 01:56:47714 EXPECT_EQ(2, browser()->tab_count());
715}
716
717// This test verifies that constructing params with a NULL browser and
718// a specific profile matches the specified profile.
[email protected]c8a31a72011-09-30 01:53:32719IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, NullBrowser_MatchProfile) {
[email protected]2dd85482010-11-06 01:56:47720 // Create a new browser with using the incognito profile.
721 Browser* incognito =
722 Browser::Create(browser()->profile()->GetOffTheRecordProfile());
723
724 // Navigate with a NULL browser and the incognito profile.
725 browser::NavigateParams p(MakeNavigateParams(NULL));
726 p.disposition = NEW_FOREGROUND_TAB;
727 p.profile = incognito->profile();
728 browser::Navigate(&p);
729
730 // Navigate() should have found incognito, not browser().
731 EXPECT_EQ(incognito, p.browser);
[email protected]52877dbc62012-06-29 22:22:03732 EXPECT_EQ(chrome::GetActiveTabContents(incognito), p.target_contents);
[email protected]2dd85482010-11-06 01:56:47733 EXPECT_EQ(1, incognito->tab_count());
734}
735
736// This test verifies that constructing params with a NULL browser and
737// disposition = NEW_WINDOW always opens exactly one new window.
738IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, NullBrowser_NewWindow) {
739 browser::NavigateParams p(MakeNavigateParams(NULL));
740 p.disposition = NEW_WINDOW;
741 p.profile = browser()->profile();
742 browser::Navigate(&p);
743
744 // Navigate() should have created a new browser.
745 EXPECT_NE(browser(), p.browser);
[email protected]b35b26b32011-05-05 20:35:14746 EXPECT_TRUE( p.browser->is_type_tabbed());
[email protected]2dd85482010-11-06 01:56:47747
748 // We should now have two windows, the browser() provided by the framework and
749 // the new normal window.
750 EXPECT_EQ(2u, BrowserList::size());
751 EXPECT_EQ(1, browser()->tab_count());
752 EXPECT_EQ(1, p.browser->tab_count());
753}
754
[email protected]bb89e7482010-11-17 18:27:04755// This test verifies that constructing params with disposition = SINGLETON_TAB
[email protected]fee320542011-03-02 01:30:49756// and IGNORE_AND_NAVIGATE opens a new tab navigated to the specified URL if
[email protected]67ed83e2011-01-07 22:54:00757// no previous tab with that URL (minus the path) exists.
[email protected]bb89e7482010-11-17 18:27:04758IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
759 Disposition_SingletonTabNew_IgnorePath) {
[email protected]52877dbc62012-06-29 22:22:03760 chrome::AddSelectedTabWithURL(browser(), GetGoogleURL(),
761 content::PAGE_TRANSITION_LINK);
[email protected]bb89e7482010-11-17 18:27:04762
763 // We should have one browser with 2 tabs, the 2nd selected.
764 EXPECT_EQ(1u, BrowserList::size());
765 EXPECT_EQ(2, browser()->tab_count());
[email protected]1ea49d52011-04-12 17:44:44766 EXPECT_EQ(1, browser()->active_index());
[email protected]bb89e7482010-11-17 18:27:04767
768 // Navigate to a new singleton tab with a sub-page.
769 browser::NavigateParams p(MakeNavigateParams());
770 p.disposition = SINGLETON_TAB;
[email protected]a048ad22012-03-23 04:26:56771 p.url = GetContentSettingsURL();
[email protected]7d329992011-04-15 18:20:02772 p.window_action = browser::NavigateParams::SHOW_WINDOW;
[email protected]fee320542011-03-02 01:30:49773 p.path_behavior = browser::NavigateParams::IGNORE_AND_NAVIGATE;
[email protected]bb89e7482010-11-17 18:27:04774 browser::Navigate(&p);
775
776 // The last tab should now be selected and navigated to the sub-page of the
777 // URL.
778 EXPECT_EQ(browser(), p.browser);
779 EXPECT_EQ(3, browser()->tab_count());
[email protected]1ea49d52011-04-12 17:44:44780 EXPECT_EQ(2, browser()->active_index());
[email protected]a048ad22012-03-23 04:26:56781 EXPECT_EQ(GetContentSettingsURL(),
[email protected]52877dbc62012-06-29 22:22:03782 chrome::GetActiveWebContents(browser())->GetURL());
[email protected]bb89e7482010-11-17 18:27:04783}
784
785// This test verifies that constructing params with disposition = SINGLETON_TAB
[email protected]fee320542011-03-02 01:30:49786// and IGNORE_AND_NAVIGATE opens an existing tab with the matching URL (minus
[email protected]bb89e7482010-11-17 18:27:04787// the path) which is navigated to the specified URL.
788IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
789 Disposition_SingletonTabExisting_IgnorePath) {
[email protected]ddddfda2011-07-14 23:19:39790 GURL singleton_url1(GetSettingsURL());
[email protected]52877dbc62012-06-29 22:22:03791 chrome::AddSelectedTabWithURL(browser(), singleton_url1,
792 content::PAGE_TRANSITION_LINK);
793 chrome::AddSelectedTabWithURL(browser(), GetGoogleURL(),
794 content::PAGE_TRANSITION_LINK);
[email protected]bb89e7482010-11-17 18:27:04795
796 // We should have one browser with 3 tabs, the 3rd selected.
797 EXPECT_EQ(1u, BrowserList::size());
798 EXPECT_EQ(3, browser()->tab_count());
[email protected]1ea49d52011-04-12 17:44:44799 EXPECT_EQ(2, browser()->active_index());
[email protected]bb89e7482010-11-17 18:27:04800
801 // Navigate to singleton_url1.
802 browser::NavigateParams p(MakeNavigateParams());
803 p.disposition = SINGLETON_TAB;
[email protected]a048ad22012-03-23 04:26:56804 p.url = GetContentSettingsURL();
[email protected]7d329992011-04-15 18:20:02805 p.window_action = browser::NavigateParams::SHOW_WINDOW;
[email protected]fee320542011-03-02 01:30:49806 p.path_behavior = browser::NavigateParams::IGNORE_AND_NAVIGATE;
[email protected]bb89e7482010-11-17 18:27:04807 browser::Navigate(&p);
808
809 // The middle tab should now be selected and navigated to the sub-page of the
810 // URL.
811 EXPECT_EQ(browser(), p.browser);
812 EXPECT_EQ(3, browser()->tab_count());
[email protected]1ea49d52011-04-12 17:44:44813 EXPECT_EQ(1, browser()->active_index());
[email protected]a048ad22012-03-23 04:26:56814 EXPECT_EQ(GetContentSettingsURL(),
[email protected]52877dbc62012-06-29 22:22:03815 chrome::GetActiveWebContents(browser())->GetURL());
[email protected]bb89e7482010-11-17 18:27:04816}
817
818// This test verifies that constructing params with disposition = SINGLETON_TAB
[email protected]fee320542011-03-02 01:30:49819// and IGNORE_AND_NAVIGATE opens an existing tab with the matching URL (minus
[email protected]bb89e7482010-11-17 18:27:04820// the path) which is navigated to the specified URL.
821IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
822 Disposition_SingletonTabExistingSubPath_IgnorePath) {
[email protected]a048ad22012-03-23 04:26:56823 GURL singleton_url1(GetContentSettingsURL());
[email protected]52877dbc62012-06-29 22:22:03824 chrome::AddSelectedTabWithURL(browser(), singleton_url1,
825 content::PAGE_TRANSITION_LINK);
826 chrome::AddSelectedTabWithURL(browser(), GetGoogleURL(),
827 content::PAGE_TRANSITION_LINK);
[email protected]bb89e7482010-11-17 18:27:04828
829 // We should have one browser with 3 tabs, the 3rd selected.
830 EXPECT_EQ(1u, BrowserList::size());
831 EXPECT_EQ(3, browser()->tab_count());
[email protected]1ea49d52011-04-12 17:44:44832 EXPECT_EQ(2, browser()->active_index());
[email protected]bb89e7482010-11-17 18:27:04833
834 // Navigate to singleton_url1.
835 browser::NavigateParams p(MakeNavigateParams());
836 p.disposition = SINGLETON_TAB;
[email protected]a048ad22012-03-23 04:26:56837 p.url = GetClearBrowsingDataURL();
[email protected]7d329992011-04-15 18:20:02838 p.window_action = browser::NavigateParams::SHOW_WINDOW;
[email protected]fee320542011-03-02 01:30:49839 p.path_behavior = browser::NavigateParams::IGNORE_AND_NAVIGATE;
[email protected]bb89e7482010-11-17 18:27:04840 browser::Navigate(&p);
841
842 // The middle tab should now be selected and navigated to the sub-page of the
843 // URL.
844 EXPECT_EQ(browser(), p.browser);
845 EXPECT_EQ(3, browser()->tab_count());
[email protected]1ea49d52011-04-12 17:44:44846 EXPECT_EQ(1, browser()->active_index());
[email protected]a048ad22012-03-23 04:26:56847 EXPECT_EQ(GetClearBrowsingDataURL(),
[email protected]52877dbc62012-06-29 22:22:03848 chrome::GetActiveWebContents(browser())->GetURL());
[email protected]bb89e7482010-11-17 18:27:04849}
[email protected]2dd85482010-11-06 01:56:47850
[email protected]637b3442011-01-10 23:31:48851// This test verifies that constructing params with disposition = SINGLETON_TAB
[email protected]fee320542011-03-02 01:30:49852// and IGNORE_AND_STAY_PUT opens an existing tab with the matching URL (minus
853// the path).
854IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
855 Disposition_SingletonTabExistingSubPath_IgnorePath2) {
[email protected]a048ad22012-03-23 04:26:56856 GURL singleton_url1(GetContentSettingsURL());
[email protected]52877dbc62012-06-29 22:22:03857 chrome::AddSelectedTabWithURL(browser(), singleton_url1,
858 content::PAGE_TRANSITION_LINK);
859 chrome::AddSelectedTabWithURL(browser(), GetGoogleURL(),
860 content::PAGE_TRANSITION_LINK);
[email protected]fee320542011-03-02 01:30:49861
862 // We should have one browser with 3 tabs, the 3rd selected.
863 EXPECT_EQ(1u, BrowserList::size());
864 EXPECT_EQ(3, browser()->tab_count());
[email protected]1ea49d52011-04-12 17:44:44865 EXPECT_EQ(2, browser()->active_index());
[email protected]fee320542011-03-02 01:30:49866
867 // Navigate to singleton_url1.
868 browser::NavigateParams p(MakeNavigateParams());
869 p.disposition = SINGLETON_TAB;
[email protected]a048ad22012-03-23 04:26:56870 p.url = GetClearBrowsingDataURL();
[email protected]7d329992011-04-15 18:20:02871 p.window_action = browser::NavigateParams::SHOW_WINDOW;
[email protected]fee320542011-03-02 01:30:49872 p.path_behavior = browser::NavigateParams::IGNORE_AND_STAY_PUT;
873 browser::Navigate(&p);
874
875 // The middle tab should now be selected.
876 EXPECT_EQ(browser(), p.browser);
877 EXPECT_EQ(3, browser()->tab_count());
[email protected]1ea49d52011-04-12 17:44:44878 EXPECT_EQ(1, browser()->active_index());
[email protected]fee320542011-03-02 01:30:49879 EXPECT_EQ(singleton_url1,
[email protected]52877dbc62012-06-29 22:22:03880 chrome::GetActiveWebContents(browser())->GetURL());
[email protected]fee320542011-03-02 01:30:49881}
882
883// This test verifies that constructing params with disposition = SINGLETON_TAB
884// and IGNORE_AND_NAVIGATE will update the current tab's URL if the currently
[email protected]637b3442011-01-10 23:31:48885// selected tab is a match but has a different path.
886IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
887 Disposition_SingletonTabFocused_IgnorePath) {
[email protected]a048ad22012-03-23 04:26:56888 GURL singleton_url_current(GetContentSettingsURL());
[email protected]52877dbc62012-06-29 22:22:03889 chrome::AddSelectedTabWithURL(browser(), singleton_url_current,
890 content::PAGE_TRANSITION_LINK);
[email protected]637b3442011-01-10 23:31:48891
892 // We should have one browser with 2 tabs, the 2nd selected.
893 EXPECT_EQ(1u, BrowserList::size());
894 EXPECT_EQ(2, browser()->tab_count());
[email protected]1ea49d52011-04-12 17:44:44895 EXPECT_EQ(1, browser()->active_index());
[email protected]637b3442011-01-10 23:31:48896
897 // Navigate to a different settings path.
[email protected]a048ad22012-03-23 04:26:56898 GURL singleton_url_target(GetClearBrowsingDataURL());
[email protected]637b3442011-01-10 23:31:48899 browser::NavigateParams p(MakeNavigateParams());
900 p.disposition = SINGLETON_TAB;
901 p.url = singleton_url_target;
[email protected]7d329992011-04-15 18:20:02902 p.window_action = browser::NavigateParams::SHOW_WINDOW;
[email protected]fee320542011-03-02 01:30:49903 p.path_behavior = browser::NavigateParams::IGNORE_AND_NAVIGATE;
[email protected]637b3442011-01-10 23:31:48904 browser::Navigate(&p);
905
906 // The second tab should still be selected, but navigated to the new path.
907 EXPECT_EQ(browser(), p.browser);
908 EXPECT_EQ(2, browser()->tab_count());
[email protected]1ea49d52011-04-12 17:44:44909 EXPECT_EQ(1, browser()->active_index());
[email protected]637b3442011-01-10 23:31:48910 EXPECT_EQ(singleton_url_target,
[email protected]52877dbc62012-06-29 22:22:03911 chrome::GetActiveWebContents(browser())->GetURL());
[email protected]637b3442011-01-10 23:31:48912}
913
[email protected]07afd7c2011-02-17 10:07:11914// This test verifies that constructing params with disposition = SINGLETON_TAB
[email protected]fee320542011-03-02 01:30:49915// and IGNORE_AND_NAVIGATE will open an existing matching tab with a different
916// query.
[email protected]07afd7c2011-02-17 10:07:11917IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
918 Disposition_SingletonTabExisting_IgnoreQuery) {
919 int initial_tab_count = browser()->tab_count();
920 GURL singleton_url_current("chrome://settings/internet");
[email protected]52877dbc62012-06-29 22:22:03921 chrome::AddSelectedTabWithURL(browser(), singleton_url_current,
922 content::PAGE_TRANSITION_LINK);
[email protected]07afd7c2011-02-17 10:07:11923
924 EXPECT_EQ(initial_tab_count + 1, browser()->tab_count());
[email protected]1ea49d52011-04-12 17:44:44925 EXPECT_EQ(initial_tab_count, browser()->active_index());
[email protected]07afd7c2011-02-17 10:07:11926
927 // Navigate to a different settings path.
928 GURL singleton_url_target(
929 "chrome://settings/internet?"
930 "servicePath=/profile/ethernet_00aa00aa00aa&networkType=1");
931 browser::NavigateParams p(MakeNavigateParams());
932 p.disposition = SINGLETON_TAB;
933 p.url = singleton_url_target;
[email protected]7d329992011-04-15 18:20:02934 p.window_action = browser::NavigateParams::SHOW_WINDOW;
[email protected]fee320542011-03-02 01:30:49935 p.path_behavior = browser::NavigateParams::IGNORE_AND_NAVIGATE;
[email protected]07afd7c2011-02-17 10:07:11936 browser::Navigate(&p);
937
938 // Last tab should still be selected.
939 EXPECT_EQ(browser(), p.browser);
940 EXPECT_EQ(initial_tab_count + 1, browser()->tab_count());
[email protected]1ea49d52011-04-12 17:44:44941 EXPECT_EQ(initial_tab_count, browser()->active_index());
[email protected]07afd7c2011-02-17 10:07:11942}
943
[email protected]bd817c22011-02-09 08:16:46944// This test verifies that the settings page isn't opened in the incognito
945// window.
[email protected]a048ad22012-03-23 04:26:56946// Disabled until fixed for uber settings: http://crbug.com/111243
[email protected]bd817c22011-02-09 08:16:46947IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
[email protected]a048ad22012-03-23 04:26:56948 DISABLED_Disposition_Settings_UseNonIncognitoWindow) {
[email protected]fc0ed302011-11-29 23:17:19949 RunUseNonIncognitoWindowTest(GetSettingsURL());
[email protected]bd817c22011-02-09 08:16:46950}
951
[email protected]82404cd2011-07-12 19:55:14952// This test verifies that the settings page isn't opened in the incognito
953// window from a non-incognito window (bookmark open-in-incognito trigger).
[email protected]a048ad22012-03-23 04:26:56954// Disabled until fixed for uber settings: http://crbug.com/111243
[email protected]82404cd2011-07-12 19:55:14955IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
[email protected]a048ad22012-03-23 04:26:56956 DISABLED_Disposition_Settings_UseNonIncognitoWindowForBookmark) {
957 browser::NavigateParams params(browser(), GetSettingsURL(),
[email protected]2905f742011-10-13 03:51:58958 content::PAGE_TRANSITION_AUTO_BOOKMARK);
[email protected]82404cd2011-07-12 19:55:14959 params.disposition = OFF_THE_RECORD;
960 {
961 ui_test_utils::WindowedNotificationObserver observer(
[email protected]ad50def52011-10-19 23:17:07962 content::NOTIFICATION_LOAD_STOP,
963 content::NotificationService::AllSources());
[email protected]82404cd2011-07-12 19:55:14964 browser::Navigate(&params);
965 observer.Wait();
966 }
967
968 EXPECT_EQ(1u, BrowserList::size());
[email protected]52877dbc62012-06-29 22:22:03969 EXPECT_EQ(GetSettingsURL(),
970 chrome::GetActiveWebContents(browser())->GetURL());
[email protected]82404cd2011-07-12 19:55:14971}
972
[email protected]93ad8e1c2011-11-08 21:34:05973// Settings page is expected to always open in normal mode regardless
974// of whether the user is trying to open it in incognito mode or not.
975// This test verifies that if incognito mode is forced (by policy), settings
976// page doesn't open at all.
[email protected]a048ad22012-03-23 04:26:56977// Disabled until fixed for uber settings: http://crbug.com/111243
[email protected]93ad8e1c2011-11-08 21:34:05978IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
[email protected]a048ad22012-03-23 04:26:56979 DISABLED_Disposition_Settings_DoNothingIfIncognitoIsForced) {
[email protected]fc0ed302011-11-29 23:17:19980 RunDoNothingIfIncognitoIsForcedTest(GetSettingsURL());
[email protected]93ad8e1c2011-11-08 21:34:05981}
982
[email protected]bd817c22011-02-09 08:16:46983// This test verifies that the bookmarks page isn't opened in the incognito
984// window.
985IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
986 Disposition_Bookmarks_UseNonIncognitoWindow) {
[email protected]fc0ed302011-11-29 23:17:19987 RunUseNonIncognitoWindowTest(GURL(chrome::kChromeUIBookmarksURL));
[email protected]bd817c22011-02-09 08:16:46988}
989
[email protected]93ad8e1c2011-11-08 21:34:05990// Bookmark manager is expected to always open in normal mode regardless
991// of whether the user is trying to open it in incognito mode or not.
992// This test verifies that if incognito mode is forced (by policy), bookmark
993// manager doesn't open at all.
994IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
995 Disposition_Bookmarks_DoNothingIfIncognitoIsForced) {
[email protected]fc0ed302011-11-29 23:17:19996 RunDoNothingIfIncognitoIsForcedTest(GURL(chrome::kChromeUIBookmarksURL));
997}
[email protected]93ad8e1c2011-11-08 21:34:05998
[email protected]fc0ed302011-11-29 23:17:19999// This test verifies that the sync promo page isn't opened in the incognito
1000// window.
1001IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
1002 Disposition_SyncPromo_UseNonIncognitoWindow) {
1003 RunUseNonIncognitoWindowTest(GURL(chrome::kChromeUISyncPromoURL));
1004}
[email protected]93ad8e1c2011-11-08 21:34:051005
[email protected]fc0ed302011-11-29 23:17:191006// The Sync promo page is expected to always open in normal mode regardless of
1007// whether the user is trying to open it in incognito mode or not. This test
1008// verifies that if incognito mode is forced (by policy), the sync promo page
1009// doesn't open at all.
1010IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
1011 Disposition_SyncPromo_DoNothingIfIncognitoIsForced) {
1012 RunDoNothingIfIncognitoIsForcedTest(GURL(chrome::kChromeUISyncPromoURL));
[email protected]93ad8e1c2011-11-08 21:34:051013}
1014
[email protected]7de53c62011-05-13 06:44:161015// This test makes sure a crashed singleton tab reloads from a new navigation.
1016IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
1017 NavigateToCrashedSingletonTab) {
[email protected]a048ad22012-03-23 04:26:561018 GURL singleton_url(GetContentSettingsURL());
[email protected]52877dbc62012-06-29 22:22:031019 TabContents* tab_contents = chrome::AddSelectedTabWithURL(
1020 browser(), singleton_url, content::PAGE_TRANSITION_LINK);
[email protected]4ebab8ee2012-06-11 22:52:011021 WebContents* web_contents = tab_contents->web_contents();
[email protected]7de53c62011-05-13 06:44:161022
1023 // We should have one browser with 2 tabs, the 2nd selected.
1024 EXPECT_EQ(1u, BrowserList::size());
1025 EXPECT_EQ(2, browser()->tab_count());
1026 EXPECT_EQ(1, browser()->active_index());
1027
1028 // Kill the singleton tab.
[email protected]83ff91c2012-01-05 20:54:131029 web_contents->SetIsCrashed(base::TERMINATION_STATUS_PROCESS_CRASHED, -1);
1030 EXPECT_TRUE(web_contents->IsCrashed());
[email protected]7de53c62011-05-13 06:44:161031
1032 browser::NavigateParams p(MakeNavigateParams());
1033 p.disposition = SINGLETON_TAB;
1034 p.url = singleton_url;
1035 p.window_action = browser::NavigateParams::SHOW_WINDOW;
1036 p.path_behavior = browser::NavigateParams::IGNORE_AND_NAVIGATE;
[email protected]ddddfda2011-07-14 23:19:391037 ui_test_utils::NavigateToURL(&p);
[email protected]7de53c62011-05-13 06:44:161038
1039 // The tab should not be sad anymore.
[email protected]83ff91c2012-01-05 20:54:131040 EXPECT_FALSE(web_contents->IsCrashed());
[email protected]7de53c62011-05-13 06:44:161041}
1042
[email protected]fcca741b2011-06-17 22:46:371043IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
1044 NavigateFromDefaultToOptionsInSameTab) {
[email protected]ddddfda2011-07-14 23:19:391045 {
1046 ui_test_utils::WindowedNotificationObserver observer(
[email protected]ad50def52011-10-19 23:17:071047 content::NOTIFICATION_LOAD_STOP,
1048 content::NotificationService::AllSources());
[email protected]5d9cace72012-06-21 16:07:121049 chrome::ShowSettings(browser());
[email protected]ddddfda2011-07-14 23:19:391050 observer.Wait();
1051 }
[email protected]fcca741b2011-06-17 22:46:371052 EXPECT_EQ(1, browser()->tab_count());
[email protected]52877dbc62012-06-29 22:22:031053 EXPECT_EQ(GetSettingsURL(),
1054 chrome::GetActiveWebContents(browser())->GetURL());
[email protected]fcca741b2011-06-17 22:46:371055}
1056
1057IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
1058 NavigateFromBlankToOptionsInSameTab) {
1059 browser::NavigateParams p(MakeNavigateParams());
[email protected]ddddfda2011-07-14 23:19:391060 p.url = GURL(chrome::kAboutBlankURL);
1061 ui_test_utils::NavigateToURL(&p);
[email protected]fcca741b2011-06-17 22:46:371062
[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());
[email protected]52877dbc62012-06-29 22:22:031071 EXPECT_EQ(GetSettingsURL(),
1072 chrome::GetActiveWebContents(browser())->GetURL());
[email protected]fcca741b2011-06-17 22:46:371073}
1074
1075IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
1076 NavigateFromNTPToOptionsInSameTab) {
1077 browser::NavigateParams p(MakeNavigateParams());
[email protected]ddddfda2011-07-14 23:19:391078 p.url = GURL(chrome::kChromeUINewTabURL);
1079 ui_test_utils::NavigateToURL(&p);
[email protected]fcca741b2011-06-17 22:46:371080 EXPECT_EQ(1, browser()->tab_count());
[email protected]ddddfda2011-07-14 23:19:391081 EXPECT_EQ(GURL(chrome::kChromeUINewTabURL),
[email protected]52877dbc62012-06-29 22:22:031082 chrome::GetActiveWebContents(browser())->GetURL());
[email protected]fcca741b2011-06-17 22:46:371083
[email protected]ddddfda2011-07-14 23:19:391084 {
1085 ui_test_utils::WindowedNotificationObserver observer(
[email protected]ad50def52011-10-19 23:17:071086 content::NOTIFICATION_LOAD_STOP,
1087 content::NotificationService::AllSources());
[email protected]5d9cace72012-06-21 16:07:121088 chrome::ShowSettings(browser());
[email protected]ddddfda2011-07-14 23:19:391089 observer.Wait();
1090 }
[email protected]fcca741b2011-06-17 22:46:371091 EXPECT_EQ(1, browser()->tab_count());
[email protected]52877dbc62012-06-29 22:22:031092 EXPECT_EQ(GetSettingsURL(),
1093 chrome::GetActiveWebContents(browser())->GetURL());
[email protected]fcca741b2011-06-17 22:46:371094}
1095
1096IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
1097 NavigateFromPageToOptionsInNewTab) {
1098 browser::NavigateParams p(MakeNavigateParams());
[email protected]ddddfda2011-07-14 23:19:391099 ui_test_utils::NavigateToURL(&p);
[email protected]52877dbc62012-06-29 22:22:031100 EXPECT_EQ(GetGoogleURL(), chrome::GetActiveWebContents(browser())->GetURL());
[email protected]fcca741b2011-06-17 22:46:371101 EXPECT_EQ(1u, BrowserList::size());
1102 EXPECT_EQ(1, browser()->tab_count());
1103
[email protected]ddddfda2011-07-14 23:19:391104 {
1105 ui_test_utils::WindowedNotificationObserver observer(
[email protected]ad50def52011-10-19 23:17:071106 content::NOTIFICATION_LOAD_STOP,
1107 content::NotificationService::AllSources());
[email protected]5d9cace72012-06-21 16:07:121108 chrome::ShowSettings(browser());
[email protected]ddddfda2011-07-14 23:19:391109 observer.Wait();
1110 }
[email protected]fcca741b2011-06-17 22:46:371111 EXPECT_EQ(2, browser()->tab_count());
[email protected]52877dbc62012-06-29 22:22:031112 EXPECT_EQ(GetSettingsURL(),
1113 chrome::GetActiveWebContents(browser())->GetURL());
[email protected]fcca741b2011-06-17 22:46:371114}
1115
1116IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
1117 NavigateFromNTPToOptionsSingleton) {
[email protected]ddddfda2011-07-14 23:19:391118 {
1119 ui_test_utils::WindowedNotificationObserver observer(
[email protected]ad50def52011-10-19 23:17:071120 content::NOTIFICATION_LOAD_STOP,
1121 content::NotificationService::AllSources());
[email protected]5d9cace72012-06-21 16:07:121122 chrome::ShowSettings(browser());
[email protected]ddddfda2011-07-14 23:19:391123 observer.Wait();
1124 }
[email protected]fcca741b2011-06-17 22:46:371125 EXPECT_EQ(1, browser()->tab_count());
1126
[email protected]a37d4b02012-06-25 21:56:101127 chrome::NewTab(browser());
[email protected]fcca741b2011-06-17 22:46:371128 EXPECT_EQ(2, browser()->tab_count());
1129
[email protected]ddddfda2011-07-14 23:19:391130 {
1131 ui_test_utils::WindowedNotificationObserver observer(
[email protected]ad50def52011-10-19 23:17:071132 content::NOTIFICATION_LOAD_STOP,
1133 content::NotificationService::AllSources());
[email protected]5d9cace72012-06-21 16:07:121134 chrome::ShowSettings(browser());
[email protected]ddddfda2011-07-14 23:19:391135 observer.Wait();
1136 }
[email protected]fcca741b2011-06-17 22:46:371137 EXPECT_EQ(2, browser()->tab_count());
[email protected]52877dbc62012-06-29 22:22:031138 EXPECT_EQ(GetSettingsURL(),
1139 chrome::GetActiveWebContents(browser())->GetURL());
[email protected]fcca741b2011-06-17 22:46:371140}
1141
1142IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
1143 NavigateFromNTPToOptionsPageInSameTab) {
[email protected]ddddfda2011-07-14 23:19:391144 {
1145 ui_test_utils::WindowedNotificationObserver observer(
[email protected]ad50def52011-10-19 23:17:071146 content::NOTIFICATION_LOAD_STOP,
1147 content::NotificationService::AllSources());
[email protected]5d9cace72012-06-21 16:07:121148 chrome::ShowClearBrowsingDataDialog(browser());
[email protected]ddddfda2011-07-14 23:19:391149 observer.Wait();
1150 }
[email protected]fcca741b2011-06-17 22:46:371151 EXPECT_EQ(1, browser()->tab_count());
[email protected]a048ad22012-03-23 04:26:561152 EXPECT_EQ(GetClearBrowsingDataURL(),
[email protected]52877dbc62012-06-29 22:22:031153 chrome::GetActiveWebContents(browser())->GetURL());
[email protected]fcca741b2011-06-17 22:46:371154
[email protected]a37d4b02012-06-25 21:56:101155 chrome::NewTab(browser());
[email protected]fcca741b2011-06-17 22:46:371156 EXPECT_EQ(2, browser()->tab_count());
1157
[email protected]ddddfda2011-07-14 23:19:391158 {
1159 ui_test_utils::WindowedNotificationObserver observer(
[email protected]ad50def52011-10-19 23:17:071160 content::NOTIFICATION_LOAD_STOP,
1161 content::NotificationService::AllSources());
[email protected]5d9cace72012-06-21 16:07:121162 chrome::ShowClearBrowsingDataDialog(browser());
[email protected]ddddfda2011-07-14 23:19:391163 observer.Wait();
1164 }
[email protected]fcca741b2011-06-17 22:46:371165 EXPECT_EQ(2, browser()->tab_count());
[email protected]a048ad22012-03-23 04:26:561166 EXPECT_EQ(GetClearBrowsingDataURL(),
[email protected]52877dbc62012-06-29 22:22:031167 chrome::GetActiveWebContents(browser())->GetURL());
[email protected]fcca741b2011-06-17 22:46:371168}
1169
[email protected]ccb8aac2012-05-21 23:00:161170// Times out on mac, fails on linux.
1171// http://crbug.com/119779
1172#if defined(OS_MACOSX) || defined(OS_LINUX)
[email protected]aac43c72012-03-23 18:41:021173#define MAYBE_NavigateFromOtherTabToSingletonOptions DISABLED_NavigateFromOtherTabToSingletonOptions
1174#else
1175#define MAYBE_NavigateFromOtherTabToSingletonOptions NavigatorFrameOtherTabToSingletonOptions
1176#endif
[email protected]fcca741b2011-06-17 22:46:371177IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
[email protected]aac43c72012-03-23 18:41:021178 MAYBE_NavigateFromOtherTabToSingletonOptions) {
[email protected]ddddfda2011-07-14 23:19:391179 {
1180 ui_test_utils::WindowedNotificationObserver observer(
[email protected]ad50def52011-10-19 23:17:071181 content::NOTIFICATION_LOAD_STOP,
1182 content::NotificationService::AllSources());
[email protected]5d9cace72012-06-21 16:07:121183 chrome::ShowSettings(browser());
[email protected]ddddfda2011-07-14 23:19:391184 observer.Wait();
1185 }
1186 {
1187 ui_test_utils::WindowedNotificationObserver observer(
[email protected]ad50def52011-10-19 23:17:071188 content::NOTIFICATION_LOAD_STOP,
1189 content::NotificationService::AllSources());
[email protected]52877dbc62012-06-29 22:22:031190 chrome::AddSelectedTabWithURL(browser(), GetGoogleURL(),
1191 content::PAGE_TRANSITION_LINK);
[email protected]ddddfda2011-07-14 23:19:391192 observer.Wait();
1193 }
[email protected]fcca741b2011-06-17 22:46:371194
[email protected]ddddfda2011-07-14 23:19:391195 {
1196 ui_test_utils::WindowedNotificationObserver observer(
[email protected]ad50def52011-10-19 23:17:071197 content::NOTIFICATION_LOAD_STOP,
1198 content::NotificationService::AllSources());
[email protected]5d9cace72012-06-21 16:07:121199 chrome::ShowSettings(browser());
[email protected]ddddfda2011-07-14 23:19:391200 observer.Wait();
1201 }
[email protected]fcca741b2011-06-17 22:46:371202 EXPECT_EQ(2, browser()->tab_count());
[email protected]ddddfda2011-07-14 23:19:391203 EXPECT_EQ(GetSettingsURL(),
[email protected]52877dbc62012-06-29 22:22:031204 chrome::GetActiveWebContents(browser())->GetURL());
[email protected]fcca741b2011-06-17 22:46:371205}
1206
[email protected]26c53e662011-07-09 02:21:021207// Tests that when a new tab is opened from the omnibox, the focus is moved from
1208// the omnibox for the current tab.
1209IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
1210 NavigateFromOmniboxIntoNewTab) {
1211 GURL url("http://www.google.com/");
1212 GURL url2("http://maps.google.com/");
1213
1214 // Navigate to url.
1215 browser::NavigateParams p(MakeNavigateParams());
1216 p.disposition = CURRENT_TAB;
1217 p.url = url;
1218 browser::Navigate(&p);
1219
1220 // Focus the omnibox.
[email protected]a37d4b02012-06-25 21:56:101221 chrome::FocusLocationBar(browser());
[email protected]26c53e662011-07-09 02:21:021222
[email protected]fbdc4232012-06-24 15:28:371223 OmniboxEditController* controller =
[email protected]fb8e3a32012-05-10 21:03:521224 browser()->window()->GetLocationBar()->GetLocationEntry()->model()->
[email protected]26c53e662011-07-09 02:21:021225 controller();
1226
1227 // Simulate an alt-enter.
1228 controller->OnAutocompleteAccept(url2, NEW_FOREGROUND_TAB,
[email protected]2905f742011-10-13 03:51:581229 content::PAGE_TRANSITION_TYPED, GURL());
[email protected]26c53e662011-07-09 02:21:021230
1231 // Make sure the second tab is selected.
1232 EXPECT_EQ(1, browser()->active_index());
1233
1234 // The tab contents should have the focus in the second tab.
[email protected]f2159ba2012-04-17 19:13:211235 EXPECT_TRUE(ui_test_utils::IsViewFocused(browser(), VIEW_ID_TAB_CONTAINER));
[email protected]26c53e662011-07-09 02:21:021236
1237 // Go back to the first tab. The focus should not be in the omnibox.
[email protected]a37d4b02012-06-25 21:56:101238 chrome::SelectPreviousTab(browser());
[email protected]26c53e662011-07-09 02:21:021239 EXPECT_EQ(0, browser()->active_index());
1240 EXPECT_FALSE(ui_test_utils::IsViewFocused(browser(),
1241 VIEW_ID_LOCATION_BAR));
1242}
1243
[email protected]a048ad22012-03-23 04:26:561244// TODO(csilv): Update this for uber page. http://crbug.com/111579.
[email protected]ddddfda2011-07-14 23:19:391245IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
[email protected]a048ad22012-03-23 04:26:561246 DISABLED_NavigateFromDefaultToHistoryInSameTab) {
[email protected]ddddfda2011-07-14 23:19:391247 {
1248 ui_test_utils::WindowedNotificationObserver observer(
[email protected]ad50def52011-10-19 23:17:071249 content::NOTIFICATION_LOAD_STOP,
1250 content::NotificationService::AllSources());
[email protected]5d9cace72012-06-21 16:07:121251 chrome::ShowHistory(browser());
[email protected]ddddfda2011-07-14 23:19:391252 observer.Wait();
1253 }
1254 EXPECT_EQ(1, browser()->tab_count());
[email protected]11e03fb2012-03-03 19:07:051255 EXPECT_EQ(GURL(chrome::kChromeUIHistoryFrameURL),
[email protected]52877dbc62012-06-29 22:22:031256 chrome::GetActiveWebContents(browser())->GetURL());
[email protected]ddddfda2011-07-14 23:19:391257}
1258
1259IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
1260 NavigateFromDefaultToBookmarksInSameTab) {
1261 {
1262 ui_test_utils::WindowedNotificationObserver observer(
[email protected]ad50def52011-10-19 23:17:071263 content::NOTIFICATION_LOAD_STOP,
1264 content::NotificationService::AllSources());
[email protected]5d9cace72012-06-21 16:07:121265 chrome::ShowBookmarkManager(browser());
[email protected]ddddfda2011-07-14 23:19:391266 observer.Wait();
1267 }
1268 EXPECT_EQ(1, browser()->tab_count());
1269 EXPECT_EQ(GURL(chrome::kChromeUIBookmarksURL),
[email protected]52877dbc62012-06-29 22:22:031270 chrome::GetActiveWebContents(browser())->GetURL());
[email protected]ddddfda2011-07-14 23:19:391271}
1272
1273IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
1274 NavigateFromDefaultToDownloadsInSameTab) {
1275 {
1276 ui_test_utils::WindowedNotificationObserver observer(
[email protected]ad50def52011-10-19 23:17:071277 content::NOTIFICATION_LOAD_STOP,
1278 content::NotificationService::AllSources());
[email protected]5d9cace72012-06-21 16:07:121279 chrome::ShowDownloads(browser());
[email protected]ddddfda2011-07-14 23:19:391280 observer.Wait();
1281 }
1282 EXPECT_EQ(1, browser()->tab_count());
1283 EXPECT_EQ(GURL(chrome::kChromeUIDownloadsURL),
[email protected]52877dbc62012-06-29 22:22:031284 chrome::GetActiveWebContents(browser())->GetURL());
[email protected]ddddfda2011-07-14 23:19:391285}
1286
[email protected]675e779b2012-01-25 23:09:451287// This test makes sure any link in a crashed panel page navigates to a tabbed
1288// window.
1289class PanelBrowserNavigatorTest : public BrowserNavigatorTest {
1290 protected:
1291 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE {
1292 command_line->AppendSwitch(switches::kEnablePanels);
1293 }
1294};
1295
1296IN_PROC_BROWSER_TEST_F(PanelBrowserNavigatorTest, NavigateFromCrashedPanel) {
1297 GURL url("http://maps.google.com/#a");
1298 GURL url2("http://maps.google.com/#b");
1299
1300 // Create a panel.
[email protected]da22aa62012-04-04 18:54:351301 Browser* panel_browser = Browser::CreateWithParams(
1302 Browser::CreateParams::CreateForApp(
1303 Browser::TYPE_PANEL, "Test", gfx::Rect(100, 100),
1304 browser()->profile()));
[email protected]675e779b2012-01-25 23:09:451305
1306 // Navigate to the page.
1307 browser::NavigateParams p(MakeNavigateParams(panel_browser));
1308 p.url = url;
1309 p.disposition = CURRENT_TAB;
1310 browser::Navigate(&p);
1311
1312 // Navigate() should have navigated in the existing panel window.
1313 EXPECT_EQ(panel_browser, p.browser);
1314
1315 // We should now have two windows, the browser() provided by the framework and
1316 // the panel window we opened earlier. The tabbed browser window has 1 tab.
1317 EXPECT_EQ(2u, BrowserList::size());
1318 EXPECT_EQ(1, browser()->tab_count());
1319 EXPECT_EQ(1, panel_browser->tab_count());
1320
1321 // Kill the panel page.
[email protected]52877dbc62012-06-29 22:22:031322 WebContents* web_contents = chrome::GetActiveWebContents(panel_browser);
[email protected]675e779b2012-01-25 23:09:451323 web_contents->SetIsCrashed(base::TERMINATION_STATUS_PROCESS_CRASHED, -1);
1324 EXPECT_TRUE(web_contents->IsCrashed());
1325
1326 // Navigate to the page.
1327 browser::NavigateParams p2(MakeNavigateParams(panel_browser));
[email protected]52877dbc62012-06-29 22:22:031328 p2.source_contents = chrome::GetActiveTabContents(panel_browser);
[email protected]675e779b2012-01-25 23:09:451329 p2.url = url2;
1330 p2.disposition = CURRENT_TAB;
1331 browser::Navigate(&p2);
1332
1333 // Navigate() should have opened a new tab in the existing tabbed window.
1334 EXPECT_EQ(browser(), p2.browser);
1335
1336 // We should now have two windows, the browser() provided by the framework and
1337 // the panel window we opened earlier. The tabbed browser window has 2 tabs.
1338 EXPECT_EQ(2u, BrowserList::size());
1339 EXPECT_EQ(2, browser()->tab_count());
1340 EXPECT_EQ(1, panel_browser->tab_count());
1341}
1342
[email protected]ddddfda2011-07-14 23:19:391343} // namespace