blob: a4153ebb57acff6a6145710070671642e232f4d7 [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"
9#include "chrome/browser/autocomplete/autocomplete_edit.h"
[email protected]93ad8e1c2011-11-08 21:34:0510#include "chrome/browser/prefs/incognito_mode_prefs.h"
11#include "chrome/browser/prefs/pref_service.h"
[email protected]8ecad5e2010-12-02 21:18:3312#include "chrome/browser/profiles/profile.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]bb89e7482010-11-17 18:27:0415#include "chrome/browser/ui/browser_window.h"
[email protected]26c53e662011-07-09 02:21:0216#include "chrome/browser/ui/omnibox/location_bar.h"
17#include "chrome/browser/ui/omnibox/omnibox_view.h"
[email protected]4ebab8ee2012-06-11 22:52:0118#include "chrome/browser/ui/tab_contents/tab_contents.h"
[email protected]b56e2e32012-05-11 21:18:0419#include "chrome/browser/ui/tabs/tab_strip_model.h"
[email protected]bb89e7482010-11-17 18:27:0420#include "chrome/common/chrome_switches.h"
[email protected]93ad8e1c2011-11-08 21:34:0521#include "chrome/common/pref_names.h"
[email protected]ddddfda2011-07-14 23:19:3922#include "chrome/common/url_constants.h"
[email protected]af44e7fb2011-07-29 18:32:3223#include "chrome/test/base/ui_test_utils.h"
[email protected]ad50def52011-10-19 23:17:0724#include "content/public/browser/notification_service.h"
[email protected]0d6e9bd2011-10-18 04:29:1625#include "content/public/browser/notification_types.h"
[email protected]83ff91c2012-01-05 20:54:1326#include "content/public/browser/web_contents.h"
[email protected]8643e6d2012-01-18 20:26:1027#include "content/public/browser/web_contents_view.h"
[email protected]a1feae52010-10-11 22:14:4528
[email protected]4ca15302012-01-03 05:53:2029using content::WebContents;
30
[email protected]ddddfda2011-07-14 23:19:3931namespace {
32
33GURL GetGoogleURL() {
[email protected]bd817c22011-02-09 08:16:4634 return GURL("http://www.google.com/");
35}
[email protected]a1feae52010-10-11 22:14:4536
[email protected]ddddfda2011-07-14 23:19:3937GURL GetSettingsURL() {
[email protected]a048ad22012-03-23 04:26:5638 return GURL(chrome::kChromeUIUberURL).Resolve(
39 chrome::kChromeUISettingsHost + std::string("/"));
[email protected]ddddfda2011-07-14 23:19:3940}
41
[email protected]a048ad22012-03-23 04:26:5642GURL GetContentSettingsURL() {
43 return GetSettingsURL().Resolve(chrome::kContentSettingsExceptionsSubPage);
[email protected]ddddfda2011-07-14 23:19:3944}
45
[email protected]a048ad22012-03-23 04:26:5646GURL GetClearBrowsingDataURL() {
47 return GetSettingsURL().Resolve(chrome::kClearBrowserDataSubPage);
[email protected]ddddfda2011-07-14 23:19:3948}
49
50} // namespace
51
[email protected]bd817c22011-02-09 08:16:4652browser::NavigateParams BrowserNavigatorTest::MakeNavigateParams() const {
53 return MakeNavigateParams(browser());
54}
[email protected]a1feae52010-10-11 22:14:4555
[email protected]bd817c22011-02-09 08:16:4656browser::NavigateParams BrowserNavigatorTest::MakeNavigateParams(
57 Browser* browser) const {
58 browser::NavigateParams params(browser, GetGoogleURL(),
[email protected]2905f742011-10-13 03:51:5859 content::PAGE_TRANSITION_LINK);
[email protected]7d329992011-04-15 18:20:0260 params.window_action = browser::NavigateParams::SHOW_WINDOW;
[email protected]bd817c22011-02-09 08:16:4661 return params;
62}
[email protected]a1feae52010-10-11 22:14:4563
[email protected]bd817c22011-02-09 08:16:4664Browser* BrowserNavigatorTest::CreateEmptyBrowserForType(Browser::Type type,
65 Profile* profile) {
[email protected]da22aa62012-04-04 18:54:3566 Browser* browser = Browser::CreateWithParams(
67 Browser::CreateParams(type, profile));
[email protected]bd817c22011-02-09 08:16:4668 browser->AddBlankTab(true);
69 return browser;
70}
[email protected]a1feae52010-10-11 22:14:4571
[email protected]b35b26b32011-05-05 20:35:1472Browser* BrowserNavigatorTest::CreateEmptyBrowserForApp(Browser::Type type,
73 Profile* profile) {
[email protected]da22aa62012-04-04 18:54:3574 Browser* browser = Browser::CreateWithParams(
75 Browser::CreateParams::CreateForApp(
76 Browser::TYPE_POPUP, "Test", gfx::Rect(), profile));
[email protected]b35b26b32011-05-05 20:35:1477 browser->AddBlankTab(true);
78 return browser;
79}
80
[email protected]4ebab8ee2012-06-11 22:52:0181TabContents* BrowserNavigatorTest::CreateTabContents() {
[email protected]bd817c22011-02-09 08:16:4682 return Browser::TabContentsFactory(
83 browser()->profile(),
84 NULL,
85 MSG_ROUTING_NONE,
[email protected]4ebab8ee2012-06-11 22:52:0186 browser()->GetActiveWebContents(),
[email protected]bd817c22011-02-09 08:16:4687 NULL);
88}
[email protected]a1feae52010-10-11 22:14:4589
[email protected]bd817c22011-02-09 08:16:4690void BrowserNavigatorTest::RunSuppressTest(WindowOpenDisposition disposition) {
[email protected]4ebab8ee2012-06-11 22:52:0191 GURL old_url = browser()->GetActiveWebContents()->GetURL();
[email protected]bd817c22011-02-09 08:16:4692 browser::NavigateParams p(MakeNavigateParams());
93 p.disposition = disposition;
94 browser::Navigate(&p);
[email protected]a1feae52010-10-11 22:14:4595
[email protected]bd817c22011-02-09 08:16:4696 // Nothing should have happened as a result of Navigate();
97 EXPECT_EQ(1, browser()->tab_count());
98 EXPECT_EQ(1u, BrowserList::size());
[email protected]4ebab8ee2012-06-11 22:52:0199 EXPECT_EQ(old_url, browser()->GetActiveWebContents()->GetURL());
[email protected]bd817c22011-02-09 08:16:46100}
[email protected]bb89e7482010-11-17 18:27:04101
[email protected]fc0ed302011-11-29 23:17:19102void BrowserNavigatorTest::RunUseNonIncognitoWindowTest(const GURL& url) {
103 Browser* incognito_browser = CreateIncognitoBrowser();
104
105 EXPECT_EQ(2u, BrowserList::size());
106 EXPECT_EQ(1, browser()->tab_count());
107 EXPECT_EQ(1, incognito_browser->tab_count());
108
109 // Navigate to the page.
110 browser::NavigateParams p(MakeNavigateParams(incognito_browser));
111 p.disposition = SINGLETON_TAB;
112 p.url = url;
113 p.window_action = browser::NavigateParams::SHOW_WINDOW;
114 browser::Navigate(&p);
115
116 // This page should be opened in browser() window.
117 EXPECT_NE(incognito_browser, p.browser);
118 EXPECT_EQ(browser(), p.browser);
119 EXPECT_EQ(2, browser()->tab_count());
[email protected]4ebab8ee2012-06-11 22:52:01120 EXPECT_EQ(url, browser()->GetActiveWebContents()->GetURL());
[email protected]fc0ed302011-11-29 23:17:19121}
122
123void BrowserNavigatorTest::RunDoNothingIfIncognitoIsForcedTest(
124 const GURL& url) {
125 Browser* browser = CreateIncognitoBrowser();
126
127 // Set kIncognitoModeAvailability to FORCED.
128 PrefService* prefs1 = browser->profile()->GetPrefs();
129 prefs1->SetInteger(prefs::kIncognitoModeAvailability,
130 IncognitoModePrefs::FORCED);
131 PrefService* prefs2 = browser->profile()->GetOriginalProfile()->GetPrefs();
132 prefs2->SetInteger(prefs::kIncognitoModeAvailability,
133 IncognitoModePrefs::FORCED);
134
135 // Navigate to the page.
136 browser::NavigateParams p(MakeNavigateParams(browser));
137 p.disposition = OFF_THE_RECORD;
138 p.url = url;
139 p.window_action = browser::NavigateParams::SHOW_WINDOW;
140 browser::Navigate(&p);
141
142 // The page should not be opened.
143 EXPECT_EQ(browser, p.browser);
144 EXPECT_EQ(1, browser->tab_count());
145 EXPECT_EQ(GURL(chrome::kAboutBlankURL),
[email protected]4ebab8ee2012-06-11 22:52:01146 browser->GetActiveWebContents()->GetURL());
[email protected]fc0ed302011-11-29 23:17:19147}
148
[email protected]6c2381d2011-10-19 02:52:53149void BrowserNavigatorTest::Observe(
150 int type,
151 const content::NotificationSource& source,
152 const content::NotificationDetails& details) {
[email protected]432115822011-07-10 15:52:27153 switch (type) {
154 case content::NOTIFICATION_RENDER_VIEW_HOST_CREATED_FOR_TAB: {
[email protected]bd817c22011-02-09 08:16:46155 ++this->created_tab_contents_count_;
156 break;
[email protected]fa7ebe02010-11-29 23:04:57157 }
[email protected]bd817c22011-02-09 08:16:46158 default:
159 break;
[email protected]fa7ebe02010-11-29 23:04:57160 }
[email protected]bd817c22011-02-09 08:16:46161}
[email protected]fa7ebe02010-11-29 23:04:57162
[email protected]ddddfda2011-07-14 23:19:39163
[email protected]bd817c22011-02-09 08:16:46164namespace {
[email protected]a1feae52010-10-11 22:14:45165
[email protected]a1feae52010-10-11 22:14:45166// This test verifies that when a navigation occurs within a tab, the tab count
167// of the Browser remains the same and the current tab bears the loaded URL.
168IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_CurrentTab) {
[email protected]ddddfda2011-07-14 23:19:39169 ui_test_utils::NavigateToURL(browser(), GetGoogleURL());
[email protected]4ebab8ee2012-06-11 22:52:01170 EXPECT_EQ(GetGoogleURL(), browser()->GetActiveWebContents()->GetURL());
[email protected]a1feae52010-10-11 22:14:45171 // We should have one window with one tab.
172 EXPECT_EQ(1u, BrowserList::size());
173 EXPECT_EQ(1, browser()->tab_count());
174}
175
[email protected]bd817c22011-02-09 08:16:46176// This test verifies that a singleton tab is refocused if one is already opened
[email protected]19d9f3a2010-10-14 21:49:36177// in another or an existing window, or added if it is not.
178IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_SingletonTabExisting) {
[email protected]19d9f3a2010-10-14 21:49:36179 GURL singleton_url1("http://maps.google.com/");
[email protected]fa7ebe02010-11-29 23:04:57180
181 // Register for a notification if an additional tab_contents was instantiated.
[email protected]bd817c22011-02-09 08:16:46182 // Opening a Singleton tab that is already opened should not be opening a new
[email protected]4ebab8ee2012-06-11 22:52:01183 // tab nor be creating a new TabContents object.
[email protected]6c2381d2011-10-19 02:52:53184 content::NotificationRegistrar registrar;
[email protected]fa7ebe02010-11-29 23:04:57185
186 // As the registrar object goes out of scope, this will get unregistered
[email protected]432115822011-07-10 15:52:27187 registrar.Add(this, content::NOTIFICATION_RENDER_VIEW_HOST_CREATED_FOR_TAB,
[email protected]ad50def52011-10-19 23:17:07188 content::NotificationService::AllSources());
[email protected]fa7ebe02010-11-29 23:04:57189
[email protected]2905f742011-10-13 03:51:58190 browser()->AddSelectedTabWithURL(
191 singleton_url1, content::PAGE_TRANSITION_LINK);
192 browser()->AddSelectedTabWithURL(
193 GetGoogleURL(), content::PAGE_TRANSITION_LINK);
[email protected]19d9f3a2010-10-14 21:49:36194
195 // We should have one browser with 3 tabs, the 3rd selected.
196 EXPECT_EQ(1u, BrowserList::size());
[email protected]1ea49d52011-04-12 17:44:44197 EXPECT_EQ(2, browser()->active_index());
[email protected]19d9f3a2010-10-14 21:49:36198
[email protected]fa7ebe02010-11-29 23:04:57199 unsigned int previous_tab_contents_count =
200 created_tab_contents_count_ = 0;
201
[email protected]19d9f3a2010-10-14 21:49:36202 // Navigate to singleton_url1.
203 browser::NavigateParams p(MakeNavigateParams());
204 p.disposition = SINGLETON_TAB;
205 p.url = singleton_url1;
206 browser::Navigate(&p);
207
208 // The middle tab should now be selected.
209 EXPECT_EQ(browser(), p.browser);
[email protected]1ea49d52011-04-12 17:44:44210 EXPECT_EQ(1, browser()->active_index());
[email protected]fa7ebe02010-11-29 23:04:57211
212 // No tab contents should have been created
213 EXPECT_EQ(previous_tab_contents_count,
214 created_tab_contents_count_);
[email protected]19d9f3a2010-10-14 21:49:36215}
216
217IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
[email protected]578c6962011-08-24 22:06:40218 Disposition_SingletonTabRespectingRef) {
219 GURL singleton_ref_url1("http://maps.google.com/#a");
220 GURL singleton_ref_url2("http://maps.google.com/#b");
221 GURL singleton_ref_url3("http://maps.google.com/");
222
[email protected]2905f742011-10-13 03:51:58223 browser()->AddSelectedTabWithURL(
224 singleton_ref_url1, content::PAGE_TRANSITION_LINK);
[email protected]578c6962011-08-24 22:06:40225
226 // We should have one browser with 2 tabs, 2nd selected.
227 EXPECT_EQ(1u, BrowserList::size());
228 EXPECT_EQ(2, browser()->tab_count());
229 EXPECT_EQ(1, browser()->active_index());
230
231 // Navigate to singleton_url2.
232 browser::NavigateParams p(MakeNavigateParams());
233 p.disposition = SINGLETON_TAB;
234 p.url = singleton_ref_url2;
235 browser::Navigate(&p);
236
237 // We should now have 2 tabs, the 2nd one selected.
238 EXPECT_EQ(browser(), p.browser);
239 EXPECT_EQ(2, browser()->tab_count());
240 EXPECT_EQ(1, browser()->active_index());
241
242 // Navigate to singleton_url2, but with respect ref set.
243 p = MakeNavigateParams();
244 p.disposition = SINGLETON_TAB;
245 p.url = singleton_ref_url2;
246 p.ref_behavior = browser::NavigateParams::RESPECT_REF;
247 browser::Navigate(&p);
248
249 // We should now have 3 tabs, the 3th one selected.
250 EXPECT_EQ(browser(), p.browser);
251 EXPECT_EQ(3, browser()->tab_count());
252 EXPECT_EQ(2, browser()->active_index());
253
254 // Navigate to singleton_url3.
255 p = MakeNavigateParams();
256 p.disposition = SINGLETON_TAB;
257 p.url = singleton_ref_url3;
258 p.ref_behavior = browser::NavigateParams::RESPECT_REF;
259 browser::Navigate(&p);
260
261 // We should now have 4 tabs, the 4th one selected.
262 EXPECT_EQ(browser(), p.browser);
263 EXPECT_EQ(4, browser()->tab_count());
264 EXPECT_EQ(3, browser()->active_index());
265}
266
267IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
[email protected]19d9f3a2010-10-14 21:49:36268 Disposition_SingletonTabNoneExisting) {
[email protected]19d9f3a2010-10-14 21:49:36269 GURL singleton_url1("http://maps.google.com/");
270
[email protected]bd817c22011-02-09 08:16:46271 // We should have one browser with 1 tab.
[email protected]19d9f3a2010-10-14 21:49:36272 EXPECT_EQ(1u, BrowserList::size());
[email protected]1ea49d52011-04-12 17:44:44273 EXPECT_EQ(0, browser()->active_index());
[email protected]19d9f3a2010-10-14 21:49:36274
275 // Navigate to singleton_url1.
276 browser::NavigateParams p(MakeNavigateParams());
277 p.disposition = SINGLETON_TAB;
278 p.url = singleton_url1;
279 browser::Navigate(&p);
280
281 // We should now have 2 tabs, the 2nd one selected.
282 EXPECT_EQ(browser(), p.browser);
283 EXPECT_EQ(2, browser()->tab_count());
[email protected]1ea49d52011-04-12 17:44:44284 EXPECT_EQ(1, browser()->active_index());
[email protected]a1feae52010-10-11 22:14:45285}
286
287// This test verifies that when a navigation results in a foreground tab, the
288// tab count of the Browser increases and the selected tab shifts to the new
289// foreground tab.
290IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_NewForegroundTab) {
[email protected]4ebab8ee2012-06-11 22:52:01291 WebContents* old_contents = browser()->GetActiveWebContents();
[email protected]a1feae52010-10-11 22:14:45292 browser::NavigateParams p(MakeNavigateParams());
293 p.disposition = NEW_FOREGROUND_TAB;
[email protected]19d9f3a2010-10-14 21:49:36294 browser::Navigate(&p);
[email protected]4ebab8ee2012-06-11 22:52:01295 EXPECT_NE(old_contents, browser()->GetActiveWebContents());
296 EXPECT_EQ(browser()->GetActiveTabContents(), p.target_contents);
[email protected]a1feae52010-10-11 22:14:45297 EXPECT_EQ(2, browser()->tab_count());
298}
299
300// This test verifies that when a navigation results in a background tab, the
301// tab count of the Browser increases but the selected tab remains the same.
302IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_NewBackgroundTab) {
[email protected]4ebab8ee2012-06-11 22:52:01303 WebContents* old_contents = browser()->GetActiveWebContents();
[email protected]a1feae52010-10-11 22:14:45304 browser::NavigateParams p(MakeNavigateParams());
305 p.disposition = NEW_BACKGROUND_TAB;
[email protected]19d9f3a2010-10-14 21:49:36306 browser::Navigate(&p);
[email protected]4ebab8ee2012-06-11 22:52:01307 WebContents* new_contents = browser()->GetActiveWebContents();
[email protected]a1feae52010-10-11 22:14:45308 // The selected tab should have remained unchanged, since the new tab was
309 // opened in the background.
310 EXPECT_EQ(old_contents, new_contents);
311 EXPECT_EQ(2, browser()->tab_count());
312}
313
314// This test verifies that when a navigation requiring a new foreground tab
315// occurs in a Browser that cannot host multiple tabs, the new foreground tab
316// is created in an existing compatible Browser.
317IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
318 Disposition_IncompatibleWindow_Existing) {
319 // Open a foreground tab in a window that cannot open popups when there is an
320 // existing compatible window somewhere else that they can be opened within.
321 Browser* popup = CreateEmptyBrowserForType(Browser::TYPE_POPUP,
322 browser()->profile());
323 browser::NavigateParams p(MakeNavigateParams(popup));
324 p.disposition = NEW_FOREGROUND_TAB;
[email protected]19d9f3a2010-10-14 21:49:36325 browser::Navigate(&p);
[email protected]a1feae52010-10-11 22:14:45326
327 // Navigate() should have opened the tab in a different browser since the
328 // one we supplied didn't support additional tabs.
329 EXPECT_NE(popup, p.browser);
330
331 // Since browser() is an existing compatible tabbed browser, it should have
332 // opened the tab there.
333 EXPECT_EQ(browser(), p.browser);
334
335 // We should be left with 2 windows, the popup with one tab and the browser()
336 // provided by the framework with two.
337 EXPECT_EQ(2u, BrowserList::size());
338 EXPECT_EQ(1, popup->tab_count());
339 EXPECT_EQ(2, browser()->tab_count());
340}
341
342// This test verifies that when a navigation requiring a new foreground tab
343// occurs in a Browser that cannot host multiple tabs and no compatible Browser
344// that can is open, a compatible Browser is created.
345IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
346 Disposition_IncompatibleWindow_NoExisting) {
347 // We want to simulate not being able to find an existing window compatible
348 // with our non-tabbed browser window so Navigate() is forced to create a
349 // new compatible window. Because browser() supplied by the in-process
350 // browser testing framework is compatible with browser()->profile(), we
351 // need a different profile, and creating a popup window with an incognito
352 // profile is a quick and dirty way of achieving this.
353 Browser* popup = CreateEmptyBrowserForType(
[email protected]b35b26b32011-05-05 20:35:14354 Browser::TYPE_POPUP,
355 browser()->profile()->GetOffTheRecordProfile());
[email protected]a1feae52010-10-11 22:14:45356 browser::NavigateParams p(MakeNavigateParams(popup));
357 p.disposition = NEW_FOREGROUND_TAB;
[email protected]19d9f3a2010-10-14 21:49:36358 browser::Navigate(&p);
[email protected]a1feae52010-10-11 22:14:45359
360 // Navigate() should have opened the tab in a different browser since the
361 // one we supplied didn't support additional tabs.
362 EXPECT_NE(popup, p.browser);
363
364 // This time, browser() is _not_ compatible with popup since it is not an
365 // incognito window.
366 EXPECT_NE(browser(), p.browser);
367
368 // We should have three windows, each with one tab:
369 // 1. the browser() provided by the framework (unchanged in this test)
370 // 2. the incognito popup we created originally
371 // 3. the new incognito tabbed browser that was created by Navigate().
372 EXPECT_EQ(3u, BrowserList::size());
373 EXPECT_EQ(1, browser()->tab_count());
374 EXPECT_EQ(1, popup->tab_count());
375 EXPECT_EQ(1, p.browser->tab_count());
[email protected]b35b26b32011-05-05 20:35:14376 EXPECT_TRUE(p.browser->is_type_tabbed());
[email protected]a1feae52010-10-11 22:14:45377}
378
379// This test verifies that navigating with WindowOpenDisposition = NEW_POPUP
380// from a normal Browser results in a new Browser with TYPE_POPUP.
381IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_NewPopup) {
382 browser::NavigateParams p(MakeNavigateParams());
383 p.disposition = NEW_POPUP;
[email protected]588300d2011-04-28 21:06:35384 p.window_bounds = gfx::Rect(0, 0, 200, 200);
[email protected]7d329992011-04-15 18:20:02385 // Wait for new popup to to load and gain focus.
[email protected]ddddfda2011-07-14 23:19:39386 ui_test_utils::NavigateToURL(&p);
[email protected]a1feae52010-10-11 22:14:45387
[email protected]7d329992011-04-15 18:20:02388 // Navigate() should have opened a new, focused popup window.
[email protected]a1feae52010-10-11 22:14:45389 EXPECT_NE(browser(), p.browser);
[email protected]9db263a2011-04-15 20:53:47390#if 0
391 // TODO(stevenjb): Enable this test. See: crbug.com/79493
[email protected]7d329992011-04-15 18:20:02392 EXPECT_TRUE(p.browser->window()->IsActive());
393#endif
[email protected]b35b26b32011-05-05 20:35:14394 EXPECT_TRUE(p.browser->is_type_popup());
395 EXPECT_FALSE(p.browser->is_app());
[email protected]a1feae52010-10-11 22:14:45396
397 // We should have two windows, the browser() provided by the framework and the
398 // new popup window.
399 EXPECT_EQ(2u, BrowserList::size());
400 EXPECT_EQ(1, browser()->tab_count());
401 EXPECT_EQ(1, p.browser->tab_count());
402}
403
404// This test verifies that navigating with WindowOpenDisposition = NEW_POPUP
[email protected]f112b0f2011-05-26 01:53:52405// from a normal Browser results in a new Browser with is_app() true.
406IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_NewPopup_ExtensionId) {
407 browser::NavigateParams p(MakeNavigateParams());
408 p.disposition = NEW_POPUP;
409 p.extension_app_id = "extensionappid";
410 p.window_bounds = gfx::Rect(0, 0, 200, 200);
[email protected]f112b0f2011-05-26 01:53:52411 // Wait for new popup to to load and gain focus.
[email protected]ddddfda2011-07-14 23:19:39412 ui_test_utils::NavigateToURL(&p);
[email protected]f112b0f2011-05-26 01:53:52413
414 // Navigate() should have opened a new, focused popup window.
415 EXPECT_NE(browser(), p.browser);
416 EXPECT_TRUE(p.browser->is_type_popup());
417 EXPECT_TRUE(p.browser->is_app());
418
419 // We should have two windows, the browser() provided by the framework and the
420 // new popup window.
421 EXPECT_EQ(2u, BrowserList::size());
422 EXPECT_EQ(1, browser()->tab_count());
423 EXPECT_EQ(1, p.browser->tab_count());
424}
425
426// This test verifies that navigating with WindowOpenDisposition = NEW_POPUP
[email protected]300d1e52011-01-19 23:57:57427// from a normal popup results in a new Browser with TYPE_POPUP.
428IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_NewPopupFromPopup) {
429 // Open a popup.
430 browser::NavigateParams p1(MakeNavigateParams());
431 p1.disposition = NEW_POPUP;
[email protected]588300d2011-04-28 21:06:35432 p1.window_bounds = gfx::Rect(0, 0, 200, 200);
[email protected]300d1e52011-01-19 23:57:57433 browser::Navigate(&p1);
434 // Open another popup.
435 browser::NavigateParams p2(MakeNavigateParams(p1.browser));
436 p2.disposition = NEW_POPUP;
[email protected]588300d2011-04-28 21:06:35437 p2.window_bounds = gfx::Rect(0, 0, 200, 200);
[email protected]300d1e52011-01-19 23:57:57438 browser::Navigate(&p2);
439
440 // Navigate() should have opened a new normal popup window.
441 EXPECT_NE(p1.browser, p2.browser);
[email protected]b35b26b32011-05-05 20:35:14442 EXPECT_TRUE(p2.browser->is_type_popup());
443 EXPECT_FALSE(p2.browser->is_app());
[email protected]300d1e52011-01-19 23:57:57444
445 // We should have three windows, the browser() provided by the framework,
446 // the first popup window, and the second popup window.
447 EXPECT_EQ(3u, BrowserList::size());
448 EXPECT_EQ(1, browser()->tab_count());
449 EXPECT_EQ(1, p1.browser->tab_count());
450 EXPECT_EQ(1, p2.browser->tab_count());
451}
452
453// This test verifies that navigating with WindowOpenDisposition = NEW_POPUP
[email protected]a1feae52010-10-11 22:14:45454// from an app frame results in a new Browser with TYPE_APP_POPUP.
455IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
456 Disposition_NewPopupFromAppWindow) {
[email protected]b35b26b32011-05-05 20:35:14457 Browser* app_browser = CreateEmptyBrowserForApp(Browser::TYPE_TABBED,
458 browser()->profile());
[email protected]a1feae52010-10-11 22:14:45459 browser::NavigateParams p(MakeNavigateParams(app_browser));
460 p.disposition = NEW_POPUP;
[email protected]588300d2011-04-28 21:06:35461 p.window_bounds = gfx::Rect(0, 0, 200, 200);
[email protected]19d9f3a2010-10-14 21:49:36462 browser::Navigate(&p);
[email protected]a1feae52010-10-11 22:14:45463
464 // Navigate() should have opened a new popup app window.
465 EXPECT_NE(app_browser, p.browser);
466 EXPECT_NE(browser(), p.browser);
[email protected]b35b26b32011-05-05 20:35:14467 EXPECT_TRUE(p.browser->is_type_popup());
468 EXPECT_TRUE(p.browser->is_app());
[email protected]a1feae52010-10-11 22:14:45469
470 // We should now have three windows, the app window, the app popup it created,
471 // and the original browser() provided by the framework.
472 EXPECT_EQ(3u, BrowserList::size());
473 EXPECT_EQ(1, browser()->tab_count());
474 EXPECT_EQ(1, app_browser->tab_count());
475 EXPECT_EQ(1, p.browser->tab_count());
476}
477
478// This test verifies that navigating with WindowOpenDisposition = NEW_POPUP
[email protected]300d1e52011-01-19 23:57:57479// from an app popup results in a new Browser also of TYPE_APP_POPUP.
480IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
481 Disposition_NewPopupFromAppPopup) {
[email protected]b35b26b32011-05-05 20:35:14482 Browser* app_browser = CreateEmptyBrowserForApp(Browser::TYPE_TABBED,
483 browser()->profile());
[email protected]300d1e52011-01-19 23:57:57484 // Open an app popup.
485 browser::NavigateParams p1(MakeNavigateParams(app_browser));
486 p1.disposition = NEW_POPUP;
[email protected]588300d2011-04-28 21:06:35487 p1.window_bounds = gfx::Rect(0, 0, 200, 200);
[email protected]300d1e52011-01-19 23:57:57488 browser::Navigate(&p1);
489 // Now open another app popup.
490 browser::NavigateParams p2(MakeNavigateParams(p1.browser));
491 p2.disposition = NEW_POPUP;
[email protected]588300d2011-04-28 21:06:35492 p2.window_bounds = gfx::Rect(0, 0, 200, 200);
[email protected]300d1e52011-01-19 23:57:57493 browser::Navigate(&p2);
494
495 // Navigate() should have opened a new popup app window.
496 EXPECT_NE(browser(), p1.browser);
497 EXPECT_NE(p1.browser, p2.browser);
[email protected]b35b26b32011-05-05 20:35:14498 EXPECT_TRUE(p2.browser->is_type_popup());
499 EXPECT_TRUE(p2.browser->is_app());
[email protected]300d1e52011-01-19 23:57:57500
501 // We should now have four windows, the app window, the first app popup,
502 // the second app popup, and the original browser() provided by the framework.
503 EXPECT_EQ(4u, BrowserList::size());
504 EXPECT_EQ(1, browser()->tab_count());
505 EXPECT_EQ(1, app_browser->tab_count());
506 EXPECT_EQ(1, p1.browser->tab_count());
507 EXPECT_EQ(1, p2.browser->tab_count());
508}
509
510// This test verifies that navigating with WindowOpenDisposition = NEW_POPUP
[email protected]a1feae52010-10-11 22:14:45511// from an extension app tab results in a new Browser with TYPE_APP_POPUP.
512IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
513 Disposition_NewPopupFromExtensionApp) {
514 // TODO(beng): TBD.
515}
516
[email protected]7d329992011-04-15 18:20:02517// This test verifies that navigating with window_action = SHOW_WINDOW_INACTIVE
518// does not focus a new new popup window.
519IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_NewPopupUnfocused) {
520 browser::NavigateParams p(MakeNavigateParams());
521 p.disposition = NEW_POPUP;
[email protected]588300d2011-04-28 21:06:35522 p.window_bounds = gfx::Rect(0, 0, 200, 200);
[email protected]7d329992011-04-15 18:20:02523 p.window_action = browser::NavigateParams::SHOW_WINDOW_INACTIVE;
[email protected]7d329992011-04-15 18:20:02524 // Wait for new popup to load (and gain focus if the test fails).
[email protected]ddddfda2011-07-14 23:19:39525 ui_test_utils::NavigateToURL(&p);
[email protected]7d329992011-04-15 18:20:02526
527 // Navigate() should have opened a new, unfocused, popup window.
528 EXPECT_NE(browser(), p.browser);
529 EXPECT_EQ(Browser::TYPE_POPUP, p.browser->type());
[email protected]9db263a2011-04-15 20:53:47530#if 0
531// TODO(stevenjb): Enable this test. See: crbug.com/79493
[email protected]7d329992011-04-15 18:20:02532 EXPECT_FALSE(p.browser->window()->IsActive());
[email protected]7d329992011-04-15 18:20:02533#endif
[email protected]9db263a2011-04-15 20:53:47534}
[email protected]7d329992011-04-15 18:20:02535
[email protected]a1feae52010-10-11 22:14:45536// This test verifies that navigating with WindowOpenDisposition = NEW_WINDOW
537// always opens a new window.
538IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_NewWindow) {
539 browser::NavigateParams p(MakeNavigateParams());
540 p.disposition = NEW_WINDOW;
[email protected]19d9f3a2010-10-14 21:49:36541 browser::Navigate(&p);
[email protected]a1feae52010-10-11 22:14:45542
543 // Navigate() should have opened a new toplevel window.
544 EXPECT_NE(browser(), p.browser);
[email protected]b35b26b32011-05-05 20:35:14545 EXPECT_TRUE(p.browser->is_type_tabbed());
[email protected]a1feae52010-10-11 22:14:45546
547 // We should now have two windows, the browser() provided by the framework and
548 // the new normal window.
549 EXPECT_EQ(2u, BrowserList::size());
550 EXPECT_EQ(1, browser()->tab_count());
551 EXPECT_EQ(1, p.browser->tab_count());
552}
553
554// This test verifies that navigating with WindowOpenDisposition = INCOGNITO
555// opens a new incognito window if no existing incognito window is present.
556IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_Incognito) {
557 browser::NavigateParams p(MakeNavigateParams());
558 p.disposition = OFF_THE_RECORD;
[email protected]19d9f3a2010-10-14 21:49:36559 browser::Navigate(&p);
[email protected]a1feae52010-10-11 22:14:45560
561 // Navigate() should have opened a new toplevel incognito window.
562 EXPECT_NE(browser(), p.browser);
563 EXPECT_EQ(browser()->profile()->GetOffTheRecordProfile(),
564 p.browser->profile());
565
[email protected]d7ff3592010-11-30 21:50:46566 // |source_contents| should be set to NULL because the profile for the new
567 // page is different from the originating page.
568 EXPECT_EQ(NULL, p.source_contents);
569
[email protected]a1feae52010-10-11 22:14:45570 // We should now have two windows, the browser() provided by the framework and
571 // the new incognito window.
572 EXPECT_EQ(2u, BrowserList::size());
573 EXPECT_EQ(1, browser()->tab_count());
574 EXPECT_EQ(1, p.browser->tab_count());
575}
576
577// This test verifies that navigating with WindowOpenDisposition = INCOGNITO
578// reuses an existing incognito window when possible.
579IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_IncognitoRefocus) {
580 Browser* incognito_browser =
[email protected]b35b26b32011-05-05 20:35:14581 CreateEmptyBrowserForType(Browser::TYPE_TABBED,
[email protected]a1feae52010-10-11 22:14:45582 browser()->profile()->GetOffTheRecordProfile());
583 browser::NavigateParams p(MakeNavigateParams());
584 p.disposition = OFF_THE_RECORD;
[email protected]19d9f3a2010-10-14 21:49:36585 browser::Navigate(&p);
[email protected]a1feae52010-10-11 22:14:45586
587 // Navigate() should have opened a new tab in the existing incognito window.
588 EXPECT_NE(browser(), p.browser);
589 EXPECT_EQ(p.browser, incognito_browser);
590
591 // We should now have two windows, the browser() provided by the framework and
592 // the incognito window we opened earlier.
593 EXPECT_EQ(2u, BrowserList::size());
594 EXPECT_EQ(1, browser()->tab_count());
595 EXPECT_EQ(2, incognito_browser->tab_count());
596}
597
598// This test verifies that no navigation action occurs when
599// WindowOpenDisposition = SUPPRESS_OPEN.
600IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_SuppressOpen) {
601 RunSuppressTest(SUPPRESS_OPEN);
602}
603
604// This test verifies that no navigation action occurs when
605// WindowOpenDisposition = SAVE_TO_DISK.
606IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_SaveToDisk) {
607 RunSuppressTest(SAVE_TO_DISK);
608}
609
610// This test verifies that no navigation action occurs when
611// WindowOpenDisposition = IGNORE_ACTION.
612IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_IgnoreAction) {
613 RunSuppressTest(IGNORE_ACTION);
614}
615
[email protected]4ebab8ee2012-06-11 22:52:01616// This tests adding a foreground tab with a predefined TabContents.
[email protected]a1feae52010-10-11 22:14:45617IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, TargetContents_ForegroundTab) {
618 browser::NavigateParams p(MakeNavigateParams());
619 p.disposition = NEW_FOREGROUND_TAB;
620 p.target_contents = CreateTabContents();
[email protected]19d9f3a2010-10-14 21:49:36621 browser::Navigate(&p);
[email protected]a1feae52010-10-11 22:14:45622
623 // Navigate() should have opened the contents in a new foreground in the
624 // current Browser.
625 EXPECT_EQ(browser(), p.browser);
[email protected]4ebab8ee2012-06-11 22:52:01626 EXPECT_EQ(browser()->GetActiveTabContents(), p.target_contents);
[email protected]a1feae52010-10-11 22:14:45627
628 // We should have one window, with two tabs.
629 EXPECT_EQ(1u, BrowserList::size());
630 EXPECT_EQ(2, browser()->tab_count());
631}
632
633#if defined(OS_WIN)
[email protected]4ebab8ee2012-06-11 22:52:01634// This tests adding a popup with a predefined TabContents.
[email protected]76edb672011-03-04 21:48:39635IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, DISABLED_TargetContents_Popup) {
[email protected]a1feae52010-10-11 22:14:45636 browser::NavigateParams p(MakeNavigateParams());
637 p.disposition = NEW_POPUP;
638 p.target_contents = CreateTabContents();
639 p.window_bounds = gfx::Rect(10, 10, 500, 500);
[email protected]19d9f3a2010-10-14 21:49:36640 browser::Navigate(&p);
[email protected]a1feae52010-10-11 22:14:45641
642 // Navigate() should have opened a new popup window.
643 EXPECT_NE(browser(), p.browser);
[email protected]b35b26b32011-05-05 20:35:14644 EXPECT_TRUE(p.browser->is_type_popup());
645 EXPECT_FALSE(p.browser->is_app());
[email protected]a1feae52010-10-11 22:14:45646
647 // The web platform is weird. The window bounds specified in
648 // |p.window_bounds| are used as follows:
649 // - the origin is used to position the window
[email protected]4ebab8ee2012-06-11 22:52:01650 // - the size is used to size the TabContents of the window.
[email protected]a1feae52010-10-11 22:14:45651 // As such the position of the resulting window will always match
652 // p.window_bounds.origin(), but its size will not. We need to match
653 // the size against the selected tab's view's container size.
654 // Only Windows positions the window according to |p.window_bounds.origin()| -
655 // on Mac the window is offset from the opener and on Linux it always opens
656 // at 0,0.
657 EXPECT_EQ(p.window_bounds.origin(),
658 p.browser->window()->GetRestoredBounds().origin());
659 // All platforms should respect size however provided width > 400 (Mac has a
660 // minimum window width of 400).
661 EXPECT_EQ(p.window_bounds.size(),
[email protected]83ff91c2012-01-05 20:54:13662 p.target_contents->web_contents()->GetView()->GetContainerSize());
[email protected]a1feae52010-10-11 22:14:45663
664 // We should have two windows, the new popup and the browser() provided by the
665 // framework.
666 EXPECT_EQ(2u, BrowserList::size());
667 EXPECT_EQ(1, browser()->tab_count());
668 EXPECT_EQ(1, p.browser->tab_count());
669}
670#endif
671
672// This tests adding a tab at a specific index.
673IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Tabstrip_InsertAtIndex) {
674 // This is not meant to be a comprehensive test of whether or not the tab
675 // implementation of the browser observes the insertion index. That is
676 // covered by the unit tests for TabStripModel. This merely verifies that
677 // insertion index preference is reflected in common cases.
678 browser::NavigateParams p(MakeNavigateParams());
679 p.disposition = NEW_FOREGROUND_TAB;
680 p.tabstrip_index = 0;
681 p.tabstrip_add_types = TabStripModel::ADD_FORCE_INDEX;
[email protected]19d9f3a2010-10-14 21:49:36682 browser::Navigate(&p);
[email protected]a1feae52010-10-11 22:14:45683
684 // Navigate() should have inserted a new tab at slot 0 in the tabstrip.
685 EXPECT_EQ(browser(), p.browser);
[email protected]c0849252012-05-12 13:51:27686 EXPECT_EQ(0, browser()->tab_strip_model()->GetIndexOfTabContents(
[email protected]4ebab8ee2012-06-11 22:52:01687 static_cast<const TabContents*>(p.target_contents)));
[email protected]a1feae52010-10-11 22:14:45688
689 // We should have one window - the browser() provided by the framework.
690 EXPECT_EQ(1u, BrowserList::size());
691 EXPECT_EQ(2, browser()->tab_count());
692}
693
[email protected]2dd85482010-11-06 01:56:47694// This test verifies that constructing params with a NULL browser has
695// the same result as navigating to a new foreground tab in the (only)
696// active browser. Tests are the same as for Disposition_NewForegroundTab.
697IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, NullBrowser_NewForegroundTab) {
[email protected]4ebab8ee2012-06-11 22:52:01698 WebContents* old_contents = browser()->GetActiveWebContents();
[email protected]2dd85482010-11-06 01:56:47699 // Navigate with a NULL browser.
700 browser::NavigateParams p(MakeNavigateParams(NULL));
701 p.disposition = NEW_FOREGROUND_TAB;
702 p.profile = browser()->profile();
703 browser::Navigate(&p);
704
705 // Navigate() should have found browser() and create a new tab.
706 EXPECT_EQ(browser(), p.browser);
[email protected]4ebab8ee2012-06-11 22:52:01707 EXPECT_NE(old_contents, browser()->GetActiveWebContents());
708 EXPECT_EQ(browser()->GetActiveTabContents(), p.target_contents);
[email protected]2dd85482010-11-06 01:56:47709 EXPECT_EQ(2, browser()->tab_count());
710}
711
712// This test verifies that constructing params with a NULL browser and
713// a specific profile matches the specified profile.
[email protected]c8a31a72011-09-30 01:53:32714IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, NullBrowser_MatchProfile) {
[email protected]2dd85482010-11-06 01:56:47715 // Create a new browser with using the incognito profile.
716 Browser* incognito =
717 Browser::Create(browser()->profile()->GetOffTheRecordProfile());
718
719 // Navigate with a NULL browser and the incognito profile.
720 browser::NavigateParams p(MakeNavigateParams(NULL));
721 p.disposition = NEW_FOREGROUND_TAB;
722 p.profile = incognito->profile();
723 browser::Navigate(&p);
724
725 // Navigate() should have found incognito, not browser().
726 EXPECT_EQ(incognito, p.browser);
[email protected]4ebab8ee2012-06-11 22:52:01727 EXPECT_EQ(incognito->GetActiveTabContents(), p.target_contents);
[email protected]2dd85482010-11-06 01:56:47728 EXPECT_EQ(1, incognito->tab_count());
729}
730
731// This test verifies that constructing params with a NULL browser and
732// disposition = NEW_WINDOW always opens exactly one new window.
733IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, NullBrowser_NewWindow) {
734 browser::NavigateParams p(MakeNavigateParams(NULL));
735 p.disposition = NEW_WINDOW;
736 p.profile = browser()->profile();
737 browser::Navigate(&p);
738
739 // Navigate() should have created a new browser.
740 EXPECT_NE(browser(), p.browser);
[email protected]b35b26b32011-05-05 20:35:14741 EXPECT_TRUE( p.browser->is_type_tabbed());
[email protected]2dd85482010-11-06 01:56:47742
743 // We should now have two windows, the browser() provided by the framework and
744 // the new normal window.
745 EXPECT_EQ(2u, BrowserList::size());
746 EXPECT_EQ(1, browser()->tab_count());
747 EXPECT_EQ(1, p.browser->tab_count());
748}
749
[email protected]bb89e7482010-11-17 18:27:04750// This test verifies that constructing params with disposition = SINGLETON_TAB
[email protected]fee320542011-03-02 01:30:49751// and IGNORE_AND_NAVIGATE opens a new tab navigated to the specified URL if
[email protected]67ed83e2011-01-07 22:54:00752// no previous tab with that URL (minus the path) exists.
[email protected]bb89e7482010-11-17 18:27:04753IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
754 Disposition_SingletonTabNew_IgnorePath) {
[email protected]2905f742011-10-13 03:51:58755 browser()->AddSelectedTabWithURL(
756 GetGoogleURL(), content::PAGE_TRANSITION_LINK);
[email protected]bb89e7482010-11-17 18:27:04757
758 // We should have one browser with 2 tabs, the 2nd selected.
759 EXPECT_EQ(1u, BrowserList::size());
760 EXPECT_EQ(2, browser()->tab_count());
[email protected]1ea49d52011-04-12 17:44:44761 EXPECT_EQ(1, browser()->active_index());
[email protected]bb89e7482010-11-17 18:27:04762
763 // Navigate to a new singleton tab with a sub-page.
764 browser::NavigateParams p(MakeNavigateParams());
765 p.disposition = SINGLETON_TAB;
[email protected]a048ad22012-03-23 04:26:56766 p.url = GetContentSettingsURL();
[email protected]7d329992011-04-15 18:20:02767 p.window_action = browser::NavigateParams::SHOW_WINDOW;
[email protected]fee320542011-03-02 01:30:49768 p.path_behavior = browser::NavigateParams::IGNORE_AND_NAVIGATE;
[email protected]bb89e7482010-11-17 18:27:04769 browser::Navigate(&p);
770
771 // The last tab should now be selected and navigated to the sub-page of the
772 // URL.
773 EXPECT_EQ(browser(), p.browser);
774 EXPECT_EQ(3, browser()->tab_count());
[email protected]1ea49d52011-04-12 17:44:44775 EXPECT_EQ(2, browser()->active_index());
[email protected]a048ad22012-03-23 04:26:56776 EXPECT_EQ(GetContentSettingsURL(),
[email protected]4ebab8ee2012-06-11 22:52:01777 browser()->GetActiveWebContents()->GetURL());
[email protected]bb89e7482010-11-17 18:27:04778}
779
780// This test verifies that constructing params with disposition = SINGLETON_TAB
[email protected]fee320542011-03-02 01:30:49781// and IGNORE_AND_NAVIGATE opens an existing tab with the matching URL (minus
[email protected]bb89e7482010-11-17 18:27:04782// the path) which is navigated to the specified URL.
783IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
784 Disposition_SingletonTabExisting_IgnorePath) {
[email protected]ddddfda2011-07-14 23:19:39785 GURL singleton_url1(GetSettingsURL());
[email protected]2905f742011-10-13 03:51:58786 browser()->AddSelectedTabWithURL(
787 singleton_url1, content::PAGE_TRANSITION_LINK);
788 browser()->AddSelectedTabWithURL(
789 GetGoogleURL(), content::PAGE_TRANSITION_LINK);
[email protected]bb89e7482010-11-17 18:27:04790
791 // We should have one browser with 3 tabs, the 3rd selected.
792 EXPECT_EQ(1u, BrowserList::size());
793 EXPECT_EQ(3, browser()->tab_count());
[email protected]1ea49d52011-04-12 17:44:44794 EXPECT_EQ(2, browser()->active_index());
[email protected]bb89e7482010-11-17 18:27:04795
796 // Navigate to singleton_url1.
797 browser::NavigateParams p(MakeNavigateParams());
798 p.disposition = SINGLETON_TAB;
[email protected]a048ad22012-03-23 04:26:56799 p.url = GetContentSettingsURL();
[email protected]7d329992011-04-15 18:20:02800 p.window_action = browser::NavigateParams::SHOW_WINDOW;
[email protected]fee320542011-03-02 01:30:49801 p.path_behavior = browser::NavigateParams::IGNORE_AND_NAVIGATE;
[email protected]bb89e7482010-11-17 18:27:04802 browser::Navigate(&p);
803
804 // The middle tab should now be selected and navigated to the sub-page of the
805 // URL.
806 EXPECT_EQ(browser(), p.browser);
807 EXPECT_EQ(3, browser()->tab_count());
[email protected]1ea49d52011-04-12 17:44:44808 EXPECT_EQ(1, browser()->active_index());
[email protected]a048ad22012-03-23 04:26:56809 EXPECT_EQ(GetContentSettingsURL(),
[email protected]4ebab8ee2012-06-11 22:52:01810 browser()->GetActiveWebContents()->GetURL());
[email protected]bb89e7482010-11-17 18:27:04811}
812
813// This test verifies that constructing params with disposition = SINGLETON_TAB
[email protected]fee320542011-03-02 01:30:49814// and IGNORE_AND_NAVIGATE opens an existing tab with the matching URL (minus
[email protected]bb89e7482010-11-17 18:27:04815// the path) which is navigated to the specified URL.
816IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
817 Disposition_SingletonTabExistingSubPath_IgnorePath) {
[email protected]a048ad22012-03-23 04:26:56818 GURL singleton_url1(GetContentSettingsURL());
[email protected]2905f742011-10-13 03:51:58819 browser()->AddSelectedTabWithURL(
820 singleton_url1, content::PAGE_TRANSITION_LINK);
821 browser()->AddSelectedTabWithURL(
822 GetGoogleURL(), content::PAGE_TRANSITION_LINK);
[email protected]bb89e7482010-11-17 18:27:04823
824 // We should have one browser with 3 tabs, the 3rd selected.
825 EXPECT_EQ(1u, BrowserList::size());
826 EXPECT_EQ(3, browser()->tab_count());
[email protected]1ea49d52011-04-12 17:44:44827 EXPECT_EQ(2, browser()->active_index());
[email protected]bb89e7482010-11-17 18:27:04828
829 // Navigate to singleton_url1.
830 browser::NavigateParams p(MakeNavigateParams());
831 p.disposition = SINGLETON_TAB;
[email protected]a048ad22012-03-23 04:26:56832 p.url = GetClearBrowsingDataURL();
[email protected]7d329992011-04-15 18:20:02833 p.window_action = browser::NavigateParams::SHOW_WINDOW;
[email protected]fee320542011-03-02 01:30:49834 p.path_behavior = browser::NavigateParams::IGNORE_AND_NAVIGATE;
[email protected]bb89e7482010-11-17 18:27:04835 browser::Navigate(&p);
836
837 // The middle tab should now be selected and navigated to the sub-page of the
838 // URL.
839 EXPECT_EQ(browser(), p.browser);
840 EXPECT_EQ(3, browser()->tab_count());
[email protected]1ea49d52011-04-12 17:44:44841 EXPECT_EQ(1, browser()->active_index());
[email protected]a048ad22012-03-23 04:26:56842 EXPECT_EQ(GetClearBrowsingDataURL(),
[email protected]4ebab8ee2012-06-11 22:52:01843 browser()->GetActiveWebContents()->GetURL());
[email protected]bb89e7482010-11-17 18:27:04844}
[email protected]2dd85482010-11-06 01:56:47845
[email protected]637b3442011-01-10 23:31:48846// This test verifies that constructing params with disposition = SINGLETON_TAB
[email protected]fee320542011-03-02 01:30:49847// and IGNORE_AND_STAY_PUT opens an existing tab with the matching URL (minus
848// the path).
849IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
850 Disposition_SingletonTabExistingSubPath_IgnorePath2) {
[email protected]a048ad22012-03-23 04:26:56851 GURL singleton_url1(GetContentSettingsURL());
[email protected]2905f742011-10-13 03:51:58852 browser()->AddSelectedTabWithURL(
853 singleton_url1, content::PAGE_TRANSITION_LINK);
854 browser()->AddSelectedTabWithURL(
855 GetGoogleURL(), content::PAGE_TRANSITION_LINK);
[email protected]fee320542011-03-02 01:30:49856
857 // We should have one browser with 3 tabs, the 3rd selected.
858 EXPECT_EQ(1u, BrowserList::size());
859 EXPECT_EQ(3, browser()->tab_count());
[email protected]1ea49d52011-04-12 17:44:44860 EXPECT_EQ(2, browser()->active_index());
[email protected]fee320542011-03-02 01:30:49861
862 // Navigate to singleton_url1.
863 browser::NavigateParams p(MakeNavigateParams());
864 p.disposition = SINGLETON_TAB;
[email protected]a048ad22012-03-23 04:26:56865 p.url = GetClearBrowsingDataURL();
[email protected]7d329992011-04-15 18:20:02866 p.window_action = browser::NavigateParams::SHOW_WINDOW;
[email protected]fee320542011-03-02 01:30:49867 p.path_behavior = browser::NavigateParams::IGNORE_AND_STAY_PUT;
868 browser::Navigate(&p);
869
870 // The middle tab should now be selected.
871 EXPECT_EQ(browser(), p.browser);
872 EXPECT_EQ(3, browser()->tab_count());
[email protected]1ea49d52011-04-12 17:44:44873 EXPECT_EQ(1, browser()->active_index());
[email protected]fee320542011-03-02 01:30:49874 EXPECT_EQ(singleton_url1,
[email protected]4ebab8ee2012-06-11 22:52:01875 browser()->GetActiveWebContents()->GetURL());
[email protected]fee320542011-03-02 01:30:49876}
877
878// This test verifies that constructing params with disposition = SINGLETON_TAB
879// and IGNORE_AND_NAVIGATE will update the current tab's URL if the currently
[email protected]637b3442011-01-10 23:31:48880// selected tab is a match but has a different path.
881IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
882 Disposition_SingletonTabFocused_IgnorePath) {
[email protected]a048ad22012-03-23 04:26:56883 GURL singleton_url_current(GetContentSettingsURL());
[email protected]2905f742011-10-13 03:51:58884 browser()->AddSelectedTabWithURL(
885 singleton_url_current, content::PAGE_TRANSITION_LINK);
[email protected]637b3442011-01-10 23:31:48886
887 // We should have one browser with 2 tabs, the 2nd selected.
888 EXPECT_EQ(1u, BrowserList::size());
889 EXPECT_EQ(2, browser()->tab_count());
[email protected]1ea49d52011-04-12 17:44:44890 EXPECT_EQ(1, browser()->active_index());
[email protected]637b3442011-01-10 23:31:48891
892 // Navigate to a different settings path.
[email protected]a048ad22012-03-23 04:26:56893 GURL singleton_url_target(GetClearBrowsingDataURL());
[email protected]637b3442011-01-10 23:31:48894 browser::NavigateParams p(MakeNavigateParams());
895 p.disposition = SINGLETON_TAB;
896 p.url = singleton_url_target;
[email protected]7d329992011-04-15 18:20:02897 p.window_action = browser::NavigateParams::SHOW_WINDOW;
[email protected]fee320542011-03-02 01:30:49898 p.path_behavior = browser::NavigateParams::IGNORE_AND_NAVIGATE;
[email protected]637b3442011-01-10 23:31:48899 browser::Navigate(&p);
900
901 // The second tab should still be selected, but navigated to the new path.
902 EXPECT_EQ(browser(), p.browser);
903 EXPECT_EQ(2, browser()->tab_count());
[email protected]1ea49d52011-04-12 17:44:44904 EXPECT_EQ(1, browser()->active_index());
[email protected]637b3442011-01-10 23:31:48905 EXPECT_EQ(singleton_url_target,
[email protected]4ebab8ee2012-06-11 22:52:01906 browser()->GetActiveWebContents()->GetURL());
[email protected]637b3442011-01-10 23:31:48907}
908
[email protected]07afd7c2011-02-17 10:07:11909// This test verifies that constructing params with disposition = SINGLETON_TAB
[email protected]fee320542011-03-02 01:30:49910// and IGNORE_AND_NAVIGATE will open an existing matching tab with a different
911// query.
[email protected]07afd7c2011-02-17 10:07:11912IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
913 Disposition_SingletonTabExisting_IgnoreQuery) {
914 int initial_tab_count = browser()->tab_count();
915 GURL singleton_url_current("chrome://settings/internet");
[email protected]2905f742011-10-13 03:51:58916 browser()->AddSelectedTabWithURL(
917 singleton_url_current, content::PAGE_TRANSITION_LINK);
[email protected]07afd7c2011-02-17 10:07:11918
919 EXPECT_EQ(initial_tab_count + 1, browser()->tab_count());
[email protected]1ea49d52011-04-12 17:44:44920 EXPECT_EQ(initial_tab_count, browser()->active_index());
[email protected]07afd7c2011-02-17 10:07:11921
922 // Navigate to a different settings path.
923 GURL singleton_url_target(
924 "chrome://settings/internet?"
925 "servicePath=/profile/ethernet_00aa00aa00aa&networkType=1");
926 browser::NavigateParams p(MakeNavigateParams());
927 p.disposition = SINGLETON_TAB;
928 p.url = singleton_url_target;
[email protected]7d329992011-04-15 18:20:02929 p.window_action = browser::NavigateParams::SHOW_WINDOW;
[email protected]fee320542011-03-02 01:30:49930 p.path_behavior = browser::NavigateParams::IGNORE_AND_NAVIGATE;
[email protected]07afd7c2011-02-17 10:07:11931 browser::Navigate(&p);
932
933 // Last tab should still be selected.
934 EXPECT_EQ(browser(), p.browser);
935 EXPECT_EQ(initial_tab_count + 1, browser()->tab_count());
[email protected]1ea49d52011-04-12 17:44:44936 EXPECT_EQ(initial_tab_count, browser()->active_index());
[email protected]07afd7c2011-02-17 10:07:11937}
938
[email protected]bd817c22011-02-09 08:16:46939// This test verifies that the settings page isn't opened in the incognito
940// window.
[email protected]a048ad22012-03-23 04:26:56941// Disabled until fixed for uber settings: http://crbug.com/111243
[email protected]bd817c22011-02-09 08:16:46942IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
[email protected]a048ad22012-03-23 04:26:56943 DISABLED_Disposition_Settings_UseNonIncognitoWindow) {
[email protected]fc0ed302011-11-29 23:17:19944 RunUseNonIncognitoWindowTest(GetSettingsURL());
[email protected]bd817c22011-02-09 08:16:46945}
946
[email protected]82404cd2011-07-12 19:55:14947// This test verifies that the settings page isn't opened in the incognito
948// window from a non-incognito window (bookmark open-in-incognito trigger).
[email protected]a048ad22012-03-23 04:26:56949// Disabled until fixed for uber settings: http://crbug.com/111243
[email protected]82404cd2011-07-12 19:55:14950IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
[email protected]a048ad22012-03-23 04:26:56951 DISABLED_Disposition_Settings_UseNonIncognitoWindowForBookmark) {
952 browser::NavigateParams params(browser(), GetSettingsURL(),
[email protected]2905f742011-10-13 03:51:58953 content::PAGE_TRANSITION_AUTO_BOOKMARK);
[email protected]82404cd2011-07-12 19:55:14954 params.disposition = OFF_THE_RECORD;
955 {
956 ui_test_utils::WindowedNotificationObserver observer(
[email protected]ad50def52011-10-19 23:17:07957 content::NOTIFICATION_LOAD_STOP,
958 content::NotificationService::AllSources());
[email protected]82404cd2011-07-12 19:55:14959 browser::Navigate(&params);
960 observer.Wait();
961 }
962
963 EXPECT_EQ(1u, BrowserList::size());
[email protected]4ebab8ee2012-06-11 22:52:01964 EXPECT_EQ(GetSettingsURL(), browser()->GetActiveWebContents()->GetURL());
[email protected]82404cd2011-07-12 19:55:14965}
966
[email protected]93ad8e1c2011-11-08 21:34:05967// Settings page is expected to always open in normal mode regardless
968// of whether the user is trying to open it in incognito mode or not.
969// This test verifies that if incognito mode is forced (by policy), settings
970// page doesn't open at all.
[email protected]a048ad22012-03-23 04:26:56971// Disabled until fixed for uber settings: http://crbug.com/111243
[email protected]93ad8e1c2011-11-08 21:34:05972IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
[email protected]a048ad22012-03-23 04:26:56973 DISABLED_Disposition_Settings_DoNothingIfIncognitoIsForced) {
[email protected]fc0ed302011-11-29 23:17:19974 RunDoNothingIfIncognitoIsForcedTest(GetSettingsURL());
[email protected]93ad8e1c2011-11-08 21:34:05975}
976
[email protected]bd817c22011-02-09 08:16:46977// This test verifies that the bookmarks page isn't opened in the incognito
978// window.
979IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
980 Disposition_Bookmarks_UseNonIncognitoWindow) {
[email protected]fc0ed302011-11-29 23:17:19981 RunUseNonIncognitoWindowTest(GURL(chrome::kChromeUIBookmarksURL));
[email protected]bd817c22011-02-09 08:16:46982}
983
[email protected]93ad8e1c2011-11-08 21:34:05984// Bookmark manager is expected to always open in normal mode regardless
985// of whether the user is trying to open it in incognito mode or not.
986// This test verifies that if incognito mode is forced (by policy), bookmark
987// manager doesn't open at all.
988IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
989 Disposition_Bookmarks_DoNothingIfIncognitoIsForced) {
[email protected]fc0ed302011-11-29 23:17:19990 RunDoNothingIfIncognitoIsForcedTest(GURL(chrome::kChromeUIBookmarksURL));
991}
[email protected]93ad8e1c2011-11-08 21:34:05992
[email protected]fc0ed302011-11-29 23:17:19993// This test verifies that the sync promo page isn't opened in the incognito
994// window.
995IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
996 Disposition_SyncPromo_UseNonIncognitoWindow) {
997 RunUseNonIncognitoWindowTest(GURL(chrome::kChromeUISyncPromoURL));
998}
[email protected]93ad8e1c2011-11-08 21:34:05999
[email protected]fc0ed302011-11-29 23:17:191000// The Sync promo page is expected to always open in normal mode regardless of
1001// whether the user is trying to open it in incognito mode or not. This test
1002// verifies that if incognito mode is forced (by policy), the sync promo page
1003// doesn't open at all.
1004IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
1005 Disposition_SyncPromo_DoNothingIfIncognitoIsForced) {
1006 RunDoNothingIfIncognitoIsForcedTest(GURL(chrome::kChromeUISyncPromoURL));
[email protected]93ad8e1c2011-11-08 21:34:051007}
1008
[email protected]7de53c62011-05-13 06:44:161009// This test makes sure a crashed singleton tab reloads from a new navigation.
1010IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
1011 NavigateToCrashedSingletonTab) {
[email protected]a048ad22012-03-23 04:26:561012 GURL singleton_url(GetContentSettingsURL());
[email protected]4ebab8ee2012-06-11 22:52:011013 TabContents* tab_contents = browser()->AddSelectedTabWithURL(
[email protected]2905f742011-10-13 03:51:581014 singleton_url, content::PAGE_TRANSITION_LINK);
[email protected]4ebab8ee2012-06-11 22:52:011015 WebContents* web_contents = tab_contents->web_contents();
[email protected]7de53c62011-05-13 06:44:161016
1017 // We should have one browser with 2 tabs, the 2nd selected.
1018 EXPECT_EQ(1u, BrowserList::size());
1019 EXPECT_EQ(2, browser()->tab_count());
1020 EXPECT_EQ(1, browser()->active_index());
1021
1022 // Kill the singleton tab.
[email protected]83ff91c2012-01-05 20:54:131023 web_contents->SetIsCrashed(base::TERMINATION_STATUS_PROCESS_CRASHED, -1);
1024 EXPECT_TRUE(web_contents->IsCrashed());
[email protected]7de53c62011-05-13 06:44:161025
1026 browser::NavigateParams p(MakeNavigateParams());
1027 p.disposition = SINGLETON_TAB;
1028 p.url = singleton_url;
1029 p.window_action = browser::NavigateParams::SHOW_WINDOW;
1030 p.path_behavior = browser::NavigateParams::IGNORE_AND_NAVIGATE;
[email protected]ddddfda2011-07-14 23:19:391031 ui_test_utils::NavigateToURL(&p);
[email protected]7de53c62011-05-13 06:44:161032
1033 // The tab should not be sad anymore.
[email protected]83ff91c2012-01-05 20:54:131034 EXPECT_FALSE(web_contents->IsCrashed());
[email protected]7de53c62011-05-13 06:44:161035}
1036
[email protected]fcca741b2011-06-17 22:46:371037IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
1038 NavigateFromDefaultToOptionsInSameTab) {
[email protected]ddddfda2011-07-14 23:19:391039 {
1040 ui_test_utils::WindowedNotificationObserver observer(
[email protected]ad50def52011-10-19 23:17:071041 content::NOTIFICATION_LOAD_STOP,
1042 content::NotificationService::AllSources());
[email protected]ddddfda2011-07-14 23:19:391043 browser()->OpenOptionsDialog();
1044 observer.Wait();
1045 }
[email protected]fcca741b2011-06-17 22:46:371046 EXPECT_EQ(1, browser()->tab_count());
[email protected]4ebab8ee2012-06-11 22:52:011047 EXPECT_EQ(GetSettingsURL(), browser()->GetActiveWebContents()->GetURL());
[email protected]fcca741b2011-06-17 22:46:371048}
1049
1050IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
1051 NavigateFromBlankToOptionsInSameTab) {
1052 browser::NavigateParams p(MakeNavigateParams());
[email protected]ddddfda2011-07-14 23:19:391053 p.url = GURL(chrome::kAboutBlankURL);
1054 ui_test_utils::NavigateToURL(&p);
[email protected]fcca741b2011-06-17 22:46:371055
[email protected]ddddfda2011-07-14 23:19:391056 {
1057 ui_test_utils::WindowedNotificationObserver observer(
[email protected]ad50def52011-10-19 23:17:071058 content::NOTIFICATION_LOAD_STOP,
1059 content::NotificationService::AllSources());
[email protected]ddddfda2011-07-14 23:19:391060 browser()->OpenOptionsDialog();
1061 observer.Wait();
1062 }
[email protected]fcca741b2011-06-17 22:46:371063 EXPECT_EQ(1, browser()->tab_count());
[email protected]4ebab8ee2012-06-11 22:52:011064 EXPECT_EQ(GetSettingsURL(), browser()->GetActiveWebContents()->GetURL());
[email protected]fcca741b2011-06-17 22:46:371065}
1066
1067IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
1068 NavigateFromNTPToOptionsInSameTab) {
1069 browser::NavigateParams p(MakeNavigateParams());
[email protected]ddddfda2011-07-14 23:19:391070 p.url = GURL(chrome::kChromeUINewTabURL);
1071 ui_test_utils::NavigateToURL(&p);
[email protected]fcca741b2011-06-17 22:46:371072 EXPECT_EQ(1, browser()->tab_count());
[email protected]ddddfda2011-07-14 23:19:391073 EXPECT_EQ(GURL(chrome::kChromeUINewTabURL),
[email protected]4ebab8ee2012-06-11 22:52:011074 browser()->GetActiveWebContents()->GetURL());
[email protected]fcca741b2011-06-17 22:46:371075
[email protected]ddddfda2011-07-14 23:19:391076 {
1077 ui_test_utils::WindowedNotificationObserver observer(
[email protected]ad50def52011-10-19 23:17:071078 content::NOTIFICATION_LOAD_STOP,
1079 content::NotificationService::AllSources());
[email protected]ddddfda2011-07-14 23:19:391080 browser()->OpenOptionsDialog();
1081 observer.Wait();
1082 }
[email protected]fcca741b2011-06-17 22:46:371083 EXPECT_EQ(1, browser()->tab_count());
[email protected]4ebab8ee2012-06-11 22:52:011084 EXPECT_EQ(GetSettingsURL(), browser()->GetActiveWebContents()->GetURL());
[email protected]fcca741b2011-06-17 22:46:371085}
1086
1087IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
1088 NavigateFromPageToOptionsInNewTab) {
1089 browser::NavigateParams p(MakeNavigateParams());
[email protected]ddddfda2011-07-14 23:19:391090 ui_test_utils::NavigateToURL(&p);
[email protected]4ebab8ee2012-06-11 22:52:011091 EXPECT_EQ(GetGoogleURL(), browser()->GetActiveWebContents()->GetURL());
[email protected]fcca741b2011-06-17 22:46:371092 EXPECT_EQ(1u, BrowserList::size());
1093 EXPECT_EQ(1, browser()->tab_count());
1094
[email protected]ddddfda2011-07-14 23:19:391095 {
1096 ui_test_utils::WindowedNotificationObserver observer(
[email protected]ad50def52011-10-19 23:17:071097 content::NOTIFICATION_LOAD_STOP,
1098 content::NotificationService::AllSources());
[email protected]ddddfda2011-07-14 23:19:391099 browser()->OpenOptionsDialog();
1100 observer.Wait();
1101 }
[email protected]fcca741b2011-06-17 22:46:371102 EXPECT_EQ(2, browser()->tab_count());
[email protected]4ebab8ee2012-06-11 22:52:011103 EXPECT_EQ(GetSettingsURL(), browser()->GetActiveWebContents()->GetURL());
[email protected]fcca741b2011-06-17 22:46:371104}
1105
1106IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
1107 NavigateFromNTPToOptionsSingleton) {
[email protected]ddddfda2011-07-14 23:19:391108 {
1109 ui_test_utils::WindowedNotificationObserver observer(
[email protected]ad50def52011-10-19 23:17:071110 content::NOTIFICATION_LOAD_STOP,
1111 content::NotificationService::AllSources());
[email protected]ddddfda2011-07-14 23:19:391112 browser()->OpenOptionsDialog();
1113 observer.Wait();
1114 }
[email protected]fcca741b2011-06-17 22:46:371115 EXPECT_EQ(1, browser()->tab_count());
1116
1117 browser()->NewTab();
1118 EXPECT_EQ(2, browser()->tab_count());
1119
[email protected]ddddfda2011-07-14 23:19:391120 {
1121 ui_test_utils::WindowedNotificationObserver observer(
[email protected]ad50def52011-10-19 23:17:071122 content::NOTIFICATION_LOAD_STOP,
1123 content::NotificationService::AllSources());
[email protected]ddddfda2011-07-14 23:19:391124 browser()->OpenOptionsDialog();
1125 observer.Wait();
1126 }
[email protected]fcca741b2011-06-17 22:46:371127 EXPECT_EQ(2, browser()->tab_count());
[email protected]4ebab8ee2012-06-11 22:52:011128 EXPECT_EQ(GetSettingsURL(), browser()->GetActiveWebContents()->GetURL());
[email protected]fcca741b2011-06-17 22:46:371129}
1130
1131IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
1132 NavigateFromNTPToOptionsPageInSameTab) {
[email protected]ddddfda2011-07-14 23:19:391133 {
1134 ui_test_utils::WindowedNotificationObserver observer(
[email protected]ad50def52011-10-19 23:17:071135 content::NOTIFICATION_LOAD_STOP,
1136 content::NotificationService::AllSources());
[email protected]a048ad22012-03-23 04:26:561137 browser()->OpenClearBrowsingDataDialog();
[email protected]ddddfda2011-07-14 23:19:391138 observer.Wait();
1139 }
[email protected]fcca741b2011-06-17 22:46:371140 EXPECT_EQ(1, browser()->tab_count());
[email protected]a048ad22012-03-23 04:26:561141 EXPECT_EQ(GetClearBrowsingDataURL(),
[email protected]4ebab8ee2012-06-11 22:52:011142 browser()->GetActiveWebContents()->GetURL());
[email protected]fcca741b2011-06-17 22:46:371143
1144 browser()->NewTab();
1145 EXPECT_EQ(2, browser()->tab_count());
1146
[email protected]ddddfda2011-07-14 23:19:391147 {
1148 ui_test_utils::WindowedNotificationObserver observer(
[email protected]ad50def52011-10-19 23:17:071149 content::NOTIFICATION_LOAD_STOP,
1150 content::NotificationService::AllSources());
[email protected]a048ad22012-03-23 04:26:561151 browser()->OpenClearBrowsingDataDialog();
[email protected]ddddfda2011-07-14 23:19:391152 observer.Wait();
1153 }
[email protected]fcca741b2011-06-17 22:46:371154 EXPECT_EQ(2, browser()->tab_count());
[email protected]a048ad22012-03-23 04:26:561155 EXPECT_EQ(GetClearBrowsingDataURL(),
[email protected]4ebab8ee2012-06-11 22:52:011156 browser()->GetActiveWebContents()->GetURL());
[email protected]fcca741b2011-06-17 22:46:371157}
1158
[email protected]ccb8aac2012-05-21 23:00:161159// Times out on mac, fails on linux.
1160// http://crbug.com/119779
1161#if defined(OS_MACOSX) || defined(OS_LINUX)
[email protected]aac43c72012-03-23 18:41:021162#define MAYBE_NavigateFromOtherTabToSingletonOptions DISABLED_NavigateFromOtherTabToSingletonOptions
1163#else
1164#define MAYBE_NavigateFromOtherTabToSingletonOptions NavigatorFrameOtherTabToSingletonOptions
1165#endif
[email protected]fcca741b2011-06-17 22:46:371166IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
[email protected]aac43c72012-03-23 18:41:021167 MAYBE_NavigateFromOtherTabToSingletonOptions) {
[email protected]ddddfda2011-07-14 23:19:391168 {
1169 ui_test_utils::WindowedNotificationObserver observer(
[email protected]ad50def52011-10-19 23:17:071170 content::NOTIFICATION_LOAD_STOP,
1171 content::NotificationService::AllSources());
[email protected]ddddfda2011-07-14 23:19:391172 browser()->OpenOptionsDialog();
1173 observer.Wait();
1174 }
1175 {
1176 ui_test_utils::WindowedNotificationObserver observer(
[email protected]ad50def52011-10-19 23:17:071177 content::NOTIFICATION_LOAD_STOP,
1178 content::NotificationService::AllSources());
[email protected]2905f742011-10-13 03:51:581179 browser()->AddSelectedTabWithURL(
1180 GetGoogleURL(), content::PAGE_TRANSITION_LINK);
[email protected]ddddfda2011-07-14 23:19:391181 observer.Wait();
1182 }
[email protected]fcca741b2011-06-17 22:46:371183
[email protected]ddddfda2011-07-14 23:19:391184 {
1185 ui_test_utils::WindowedNotificationObserver observer(
[email protected]ad50def52011-10-19 23:17:071186 content::NOTIFICATION_LOAD_STOP,
1187 content::NotificationService::AllSources());
[email protected]ddddfda2011-07-14 23:19:391188 browser()->OpenOptionsDialog();
1189 observer.Wait();
1190 }
[email protected]fcca741b2011-06-17 22:46:371191 EXPECT_EQ(2, browser()->tab_count());
[email protected]ddddfda2011-07-14 23:19:391192 EXPECT_EQ(GetSettingsURL(),
[email protected]4ebab8ee2012-06-11 22:52:011193 browser()->GetActiveWebContents()->GetURL());
[email protected]fcca741b2011-06-17 22:46:371194}
1195
[email protected]26c53e662011-07-09 02:21:021196// Tests that when a new tab is opened from the omnibox, the focus is moved from
1197// the omnibox for the current tab.
1198IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
1199 NavigateFromOmniboxIntoNewTab) {
1200 GURL url("http://www.google.com/");
1201 GURL url2("http://maps.google.com/");
1202
1203 // Navigate to url.
1204 browser::NavigateParams p(MakeNavigateParams());
1205 p.disposition = CURRENT_TAB;
1206 p.url = url;
1207 browser::Navigate(&p);
1208
1209 // Focus the omnibox.
1210 browser()->FocusLocationBar();
1211
1212 AutocompleteEditController* controller =
[email protected]fb8e3a32012-05-10 21:03:521213 browser()->window()->GetLocationBar()->GetLocationEntry()->model()->
[email protected]26c53e662011-07-09 02:21:021214 controller();
1215
1216 // Simulate an alt-enter.
1217 controller->OnAutocompleteAccept(url2, NEW_FOREGROUND_TAB,
[email protected]2905f742011-10-13 03:51:581218 content::PAGE_TRANSITION_TYPED, GURL());
[email protected]26c53e662011-07-09 02:21:021219
1220 // Make sure the second tab is selected.
1221 EXPECT_EQ(1, browser()->active_index());
1222
1223 // The tab contents should have the focus in the second tab.
[email protected]f2159ba2012-04-17 19:13:211224 EXPECT_TRUE(ui_test_utils::IsViewFocused(browser(), VIEW_ID_TAB_CONTAINER));
[email protected]26c53e662011-07-09 02:21:021225
1226 // Go back to the first tab. The focus should not be in the omnibox.
1227 browser()->SelectPreviousTab();
1228 EXPECT_EQ(0, browser()->active_index());
1229 EXPECT_FALSE(ui_test_utils::IsViewFocused(browser(),
1230 VIEW_ID_LOCATION_BAR));
1231}
1232
[email protected]a048ad22012-03-23 04:26:561233// TODO(csilv): Update this for uber page. http://crbug.com/111579.
[email protected]ddddfda2011-07-14 23:19:391234IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
[email protected]a048ad22012-03-23 04:26:561235 DISABLED_NavigateFromDefaultToHistoryInSameTab) {
[email protected]ddddfda2011-07-14 23:19:391236 {
1237 ui_test_utils::WindowedNotificationObserver observer(
[email protected]ad50def52011-10-19 23:17:071238 content::NOTIFICATION_LOAD_STOP,
1239 content::NotificationService::AllSources());
[email protected]ddddfda2011-07-14 23:19:391240 browser()->ShowHistoryTab();
1241 observer.Wait();
1242 }
1243 EXPECT_EQ(1, browser()->tab_count());
[email protected]11e03fb2012-03-03 19:07:051244 EXPECT_EQ(GURL(chrome::kChromeUIHistoryFrameURL),
[email protected]4ebab8ee2012-06-11 22:52:011245 browser()->GetActiveWebContents()->GetURL());
[email protected]ddddfda2011-07-14 23:19:391246}
1247
1248IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
1249 NavigateFromDefaultToBookmarksInSameTab) {
1250 {
1251 ui_test_utils::WindowedNotificationObserver observer(
[email protected]ad50def52011-10-19 23:17:071252 content::NOTIFICATION_LOAD_STOP,
1253 content::NotificationService::AllSources());
[email protected]0af8f132011-07-16 01:37:021254 browser()->OpenBookmarkManager();
[email protected]ddddfda2011-07-14 23:19:391255 observer.Wait();
1256 }
1257 EXPECT_EQ(1, browser()->tab_count());
1258 EXPECT_EQ(GURL(chrome::kChromeUIBookmarksURL),
[email protected]4ebab8ee2012-06-11 22:52:011259 browser()->GetActiveWebContents()->GetURL());
[email protected]ddddfda2011-07-14 23:19:391260}
1261
1262IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
1263 NavigateFromDefaultToDownloadsInSameTab) {
1264 {
1265 ui_test_utils::WindowedNotificationObserver observer(
[email protected]ad50def52011-10-19 23:17:071266 content::NOTIFICATION_LOAD_STOP,
1267 content::NotificationService::AllSources());
[email protected]ddddfda2011-07-14 23:19:391268 browser()->ShowDownloadsTab();
1269 observer.Wait();
1270 }
1271 EXPECT_EQ(1, browser()->tab_count());
1272 EXPECT_EQ(GURL(chrome::kChromeUIDownloadsURL),
[email protected]4ebab8ee2012-06-11 22:52:011273 browser()->GetActiveWebContents()->GetURL());
[email protected]ddddfda2011-07-14 23:19:391274}
1275
[email protected]675e779b2012-01-25 23:09:451276// This test makes sure any link in a crashed panel page navigates to a tabbed
1277// window.
1278class PanelBrowserNavigatorTest : public BrowserNavigatorTest {
1279 protected:
1280 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE {
1281 command_line->AppendSwitch(switches::kEnablePanels);
1282 }
1283};
1284
1285IN_PROC_BROWSER_TEST_F(PanelBrowserNavigatorTest, NavigateFromCrashedPanel) {
1286 GURL url("http://maps.google.com/#a");
1287 GURL url2("http://maps.google.com/#b");
1288
1289 // Create a panel.
[email protected]da22aa62012-04-04 18:54:351290 Browser* panel_browser = Browser::CreateWithParams(
1291 Browser::CreateParams::CreateForApp(
1292 Browser::TYPE_PANEL, "Test", gfx::Rect(100, 100),
1293 browser()->profile()));
[email protected]675e779b2012-01-25 23:09:451294
1295 // Navigate to the page.
1296 browser::NavigateParams p(MakeNavigateParams(panel_browser));
1297 p.url = url;
1298 p.disposition = CURRENT_TAB;
1299 browser::Navigate(&p);
1300
1301 // Navigate() should have navigated in the existing panel window.
1302 EXPECT_EQ(panel_browser, p.browser);
1303
1304 // We should now have two windows, the browser() provided by the framework and
1305 // the panel window we opened earlier. The tabbed browser window has 1 tab.
1306 EXPECT_EQ(2u, BrowserList::size());
1307 EXPECT_EQ(1, browser()->tab_count());
1308 EXPECT_EQ(1, panel_browser->tab_count());
1309
1310 // Kill the panel page.
[email protected]4ebab8ee2012-06-11 22:52:011311 WebContents* web_contents = panel_browser->GetActiveWebContents();
[email protected]675e779b2012-01-25 23:09:451312 web_contents->SetIsCrashed(base::TERMINATION_STATUS_PROCESS_CRASHED, -1);
1313 EXPECT_TRUE(web_contents->IsCrashed());
1314
1315 // Navigate to the page.
1316 browser::NavigateParams p2(MakeNavigateParams(panel_browser));
[email protected]4ebab8ee2012-06-11 22:52:011317 p2.source_contents = panel_browser->GetActiveTabContents();
[email protected]675e779b2012-01-25 23:09:451318 p2.url = url2;
1319 p2.disposition = CURRENT_TAB;
1320 browser::Navigate(&p2);
1321
1322 // Navigate() should have opened a new tab in the existing tabbed window.
1323 EXPECT_EQ(browser(), p2.browser);
1324
1325 // We should now have two windows, the browser() provided by the framework and
1326 // the panel window we opened earlier. The tabbed browser window has 2 tabs.
1327 EXPECT_EQ(2u, BrowserList::size());
1328 EXPECT_EQ(2, browser()->tab_count());
1329 EXPECT_EQ(1, panel_browser->tab_count());
1330}
1331
[email protected]ddddfda2011-07-14 23:19:391332} // namespace