blob: 71a924990b7378412f28896079a24a4b96facc42 [file] [log] [blame]
[email protected]1ea49d52011-04-12 17:44:441// Copyright (c) 2011 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]8ecad5e2010-12-02 21:18:3310#include "chrome/browser/profiles/profile.h"
[email protected]a1feae52010-10-11 22:14:4511#include "chrome/browser/tabs/tab_strip_model.h"
[email protected]bb89e7482010-11-17 18:27:0412#include "chrome/browser/ui/browser_list.h"
[email protected]339d6dd2010-11-12 00:41:5813#include "chrome/browser/ui/browser_navigator.h"
[email protected]bb89e7482010-11-17 18:27:0414#include "chrome/browser/ui/browser_window.h"
[email protected]26c53e662011-07-09 02:21:0215#include "chrome/browser/ui/omnibox/location_bar.h"
16#include "chrome/browser/ui/omnibox/omnibox_view.h"
[email protected]6a3ec2312010-12-02 19:30:1917#include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h"
[email protected]bb89e7482010-11-17 18:27:0418#include "chrome/common/chrome_switches.h"
[email protected]a1feae52010-10-11 22:14:4519#include "chrome/test/ui_test_utils.h"
[email protected]299425b2011-03-02 07:45:2020#include "content/browser/tab_contents/tab_contents.h"
21#include "content/browser/tab_contents/tab_contents_view.h"\
[email protected]a1feae52010-10-11 22:14:4522
[email protected]bd817c22011-02-09 08:16:4623GURL BrowserNavigatorTest::GetGoogleURL() const {
24 return GURL("http://www.google.com/");
25}
[email protected]a1feae52010-10-11 22:14:4526
[email protected]bd817c22011-02-09 08:16:4627browser::NavigateParams BrowserNavigatorTest::MakeNavigateParams() const {
28 return MakeNavigateParams(browser());
29}
[email protected]a1feae52010-10-11 22:14:4530
[email protected]bd817c22011-02-09 08:16:4631browser::NavigateParams BrowserNavigatorTest::MakeNavigateParams(
32 Browser* browser) const {
33 browser::NavigateParams params(browser, GetGoogleURL(),
34 PageTransition::LINK);
[email protected]7d329992011-04-15 18:20:0235 params.window_action = browser::NavigateParams::SHOW_WINDOW;
[email protected]bd817c22011-02-09 08:16:4636 return params;
37}
[email protected]a1feae52010-10-11 22:14:4538
[email protected]bd817c22011-02-09 08:16:4639Browser* BrowserNavigatorTest::CreateEmptyBrowserForType(Browser::Type type,
40 Profile* profile) {
41 Browser* browser = Browser::CreateForType(type, profile);
42 browser->AddBlankTab(true);
43 return browser;
44}
[email protected]a1feae52010-10-11 22:14:4545
[email protected]b35b26b32011-05-05 20:35:1446Browser* BrowserNavigatorTest::CreateEmptyBrowserForApp(Browser::Type type,
47 Profile* profile) {
48 Browser* browser = Browser::CreateForApp(Browser::TYPE_POPUP, "Test",
[email protected]5c209242011-06-06 20:36:1749 gfx::Rect(), profile);
[email protected]b35b26b32011-05-05 20:35:1450 browser->AddBlankTab(true);
51 return browser;
52}
53
[email protected]bd817c22011-02-09 08:16:4654TabContentsWrapper* BrowserNavigatorTest::CreateTabContents() {
55 return Browser::TabContentsFactory(
56 browser()->profile(),
57 NULL,
58 MSG_ROUTING_NONE,
59 browser()->GetSelectedTabContents(),
60 NULL);
61}
[email protected]a1feae52010-10-11 22:14:4562
[email protected]bd817c22011-02-09 08:16:4663void BrowserNavigatorTest::RunSuppressTest(WindowOpenDisposition disposition) {
64 GURL old_url = browser()->GetSelectedTabContents()->GetURL();
65 browser::NavigateParams p(MakeNavigateParams());
66 p.disposition = disposition;
67 browser::Navigate(&p);
[email protected]a1feae52010-10-11 22:14:4568
[email protected]bd817c22011-02-09 08:16:4669 // Nothing should have happened as a result of Navigate();
70 EXPECT_EQ(1, browser()->tab_count());
71 EXPECT_EQ(1u, BrowserList::size());
72 EXPECT_EQ(old_url, browser()->GetSelectedTabContents()->GetURL());
73}
[email protected]bb89e7482010-11-17 18:27:0474
[email protected]432115822011-07-10 15:52:2775void BrowserNavigatorTest::Observe(int type,
[email protected]bd817c22011-02-09 08:16:4676 const NotificationSource& source,
77 const NotificationDetails& details) {
[email protected]432115822011-07-10 15:52:2778 switch (type) {
79 case content::NOTIFICATION_RENDER_VIEW_HOST_CREATED_FOR_TAB: {
[email protected]bd817c22011-02-09 08:16:4680 ++this->created_tab_contents_count_;
81 break;
[email protected]fa7ebe02010-11-29 23:04:5782 }
[email protected]bd817c22011-02-09 08:16:4683 default:
84 break;
[email protected]fa7ebe02010-11-29 23:04:5785 }
[email protected]bd817c22011-02-09 08:16:4686}
[email protected]fa7ebe02010-11-29 23:04:5787
[email protected]bd817c22011-02-09 08:16:4688namespace {
[email protected]a1feae52010-10-11 22:14:4589
[email protected]a1feae52010-10-11 22:14:4590// This test verifies that when a navigation occurs within a tab, the tab count
91// of the Browser remains the same and the current tab bears the loaded URL.
92IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_CurrentTab) {
93 browser::NavigateParams p(MakeNavigateParams());
[email protected]19d9f3a2010-10-14 21:49:3694 browser::Navigate(&p);
[email protected]a1feae52010-10-11 22:14:4595 ui_test_utils::WaitForNavigationInCurrentTab(browser());
96 EXPECT_EQ(GetGoogleURL(), browser()->GetSelectedTabContents()->GetURL());
97 // We should have one window with one tab.
98 EXPECT_EQ(1u, BrowserList::size());
99 EXPECT_EQ(1, browser()->tab_count());
100}
101
[email protected]bd817c22011-02-09 08:16:46102// This test verifies that a singleton tab is refocused if one is already opened
[email protected]19d9f3a2010-10-14 21:49:36103// in another or an existing window, or added if it is not.
104IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_SingletonTabExisting) {
105 GURL url("http://www.google.com/");
106 GURL singleton_url1("http://maps.google.com/");
[email protected]fa7ebe02010-11-29 23:04:57107
108 // Register for a notification if an additional tab_contents was instantiated.
[email protected]bd817c22011-02-09 08:16:46109 // Opening a Singleton tab that is already opened should not be opening a new
[email protected]fa7ebe02010-11-29 23:04:57110 // tab nor be creating a new TabContents object
111 NotificationRegistrar registrar;
112
113 // As the registrar object goes out of scope, this will get unregistered
[email protected]432115822011-07-10 15:52:27114 registrar.Add(this, content::NOTIFICATION_RENDER_VIEW_HOST_CREATED_FOR_TAB,
[email protected]fa7ebe02010-11-29 23:04:57115 NotificationService::AllSources());
116
[email protected]19d9f3a2010-10-14 21:49:36117 browser()->AddSelectedTabWithURL(singleton_url1, PageTransition::LINK);
118 browser()->AddSelectedTabWithURL(url, PageTransition::LINK);
119
120 // We should have one browser with 3 tabs, the 3rd selected.
121 EXPECT_EQ(1u, BrowserList::size());
[email protected]1ea49d52011-04-12 17:44:44122 EXPECT_EQ(2, browser()->active_index());
[email protected]19d9f3a2010-10-14 21:49:36123
[email protected]fa7ebe02010-11-29 23:04:57124 unsigned int previous_tab_contents_count =
125 created_tab_contents_count_ = 0;
126
[email protected]19d9f3a2010-10-14 21:49:36127 // Navigate to singleton_url1.
128 browser::NavigateParams p(MakeNavigateParams());
129 p.disposition = SINGLETON_TAB;
130 p.url = singleton_url1;
131 browser::Navigate(&p);
132
133 // The middle tab should now be selected.
134 EXPECT_EQ(browser(), p.browser);
[email protected]1ea49d52011-04-12 17:44:44135 EXPECT_EQ(1, browser()->active_index());
[email protected]fa7ebe02010-11-29 23:04:57136
137 // No tab contents should have been created
138 EXPECT_EQ(previous_tab_contents_count,
139 created_tab_contents_count_);
[email protected]19d9f3a2010-10-14 21:49:36140}
141
142IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
143 Disposition_SingletonTabNoneExisting) {
144 GURL url("http://www.google.com/");
145 GURL singleton_url1("http://maps.google.com/");
146
[email protected]bd817c22011-02-09 08:16:46147 // We should have one browser with 1 tab.
[email protected]19d9f3a2010-10-14 21:49:36148 EXPECT_EQ(1u, BrowserList::size());
[email protected]1ea49d52011-04-12 17:44:44149 EXPECT_EQ(0, browser()->active_index());
[email protected]19d9f3a2010-10-14 21:49:36150
151 // Navigate to singleton_url1.
152 browser::NavigateParams p(MakeNavigateParams());
153 p.disposition = SINGLETON_TAB;
154 p.url = singleton_url1;
155 browser::Navigate(&p);
156
157 // We should now have 2 tabs, the 2nd one selected.
158 EXPECT_EQ(browser(), p.browser);
159 EXPECT_EQ(2, browser()->tab_count());
[email protected]1ea49d52011-04-12 17:44:44160 EXPECT_EQ(1, browser()->active_index());
[email protected]a1feae52010-10-11 22:14:45161}
162
163// This test verifies that when a navigation results in a foreground tab, the
164// tab count of the Browser increases and the selected tab shifts to the new
165// foreground tab.
166IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_NewForegroundTab) {
167 TabContents* old_contents = browser()->GetSelectedTabContents();
168 browser::NavigateParams p(MakeNavigateParams());
169 p.disposition = NEW_FOREGROUND_TAB;
[email protected]19d9f3a2010-10-14 21:49:36170 browser::Navigate(&p);
[email protected]a1feae52010-10-11 22:14:45171 EXPECT_NE(old_contents, browser()->GetSelectedTabContents());
[email protected]3c9e1872010-11-18 16:17:49172 EXPECT_EQ(browser()->GetSelectedTabContentsWrapper(), p.target_contents);
[email protected]a1feae52010-10-11 22:14:45173 EXPECT_EQ(2, browser()->tab_count());
174}
175
176// This test verifies that when a navigation results in a background tab, the
177// tab count of the Browser increases but the selected tab remains the same.
178IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_NewBackgroundTab) {
179 TabContents* old_contents = browser()->GetSelectedTabContents();
180 browser::NavigateParams p(MakeNavigateParams());
181 p.disposition = NEW_BACKGROUND_TAB;
[email protected]19d9f3a2010-10-14 21:49:36182 browser::Navigate(&p);
[email protected]a1feae52010-10-11 22:14:45183 TabContents* new_contents = browser()->GetSelectedTabContents();
184 // The selected tab should have remained unchanged, since the new tab was
185 // opened in the background.
186 EXPECT_EQ(old_contents, new_contents);
187 EXPECT_EQ(2, browser()->tab_count());
188}
189
190// This test verifies that when a navigation requiring a new foreground tab
191// occurs in a Browser that cannot host multiple tabs, the new foreground tab
192// is created in an existing compatible Browser.
193IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
194 Disposition_IncompatibleWindow_Existing) {
195 // Open a foreground tab in a window that cannot open popups when there is an
196 // existing compatible window somewhere else that they can be opened within.
197 Browser* popup = CreateEmptyBrowserForType(Browser::TYPE_POPUP,
198 browser()->profile());
199 browser::NavigateParams p(MakeNavigateParams(popup));
200 p.disposition = NEW_FOREGROUND_TAB;
[email protected]19d9f3a2010-10-14 21:49:36201 browser::Navigate(&p);
[email protected]a1feae52010-10-11 22:14:45202
203 // Navigate() should have opened the tab in a different browser since the
204 // one we supplied didn't support additional tabs.
205 EXPECT_NE(popup, p.browser);
206
207 // Since browser() is an existing compatible tabbed browser, it should have
208 // opened the tab there.
209 EXPECT_EQ(browser(), p.browser);
210
211 // We should be left with 2 windows, the popup with one tab and the browser()
212 // provided by the framework with two.
213 EXPECT_EQ(2u, BrowserList::size());
214 EXPECT_EQ(1, popup->tab_count());
215 EXPECT_EQ(2, browser()->tab_count());
216}
217
218// This test verifies that when a navigation requiring a new foreground tab
219// occurs in a Browser that cannot host multiple tabs and no compatible Browser
220// that can is open, a compatible Browser is created.
221IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
222 Disposition_IncompatibleWindow_NoExisting) {
223 // We want to simulate not being able to find an existing window compatible
224 // with our non-tabbed browser window so Navigate() is forced to create a
225 // new compatible window. Because browser() supplied by the in-process
226 // browser testing framework is compatible with browser()->profile(), we
227 // need a different profile, and creating a popup window with an incognito
228 // profile is a quick and dirty way of achieving this.
229 Browser* popup = CreateEmptyBrowserForType(
[email protected]b35b26b32011-05-05 20:35:14230 Browser::TYPE_POPUP,
231 browser()->profile()->GetOffTheRecordProfile());
[email protected]a1feae52010-10-11 22:14:45232 browser::NavigateParams p(MakeNavigateParams(popup));
233 p.disposition = NEW_FOREGROUND_TAB;
[email protected]19d9f3a2010-10-14 21:49:36234 browser::Navigate(&p);
[email protected]a1feae52010-10-11 22:14:45235
236 // Navigate() should have opened the tab in a different browser since the
237 // one we supplied didn't support additional tabs.
238 EXPECT_NE(popup, p.browser);
239
240 // This time, browser() is _not_ compatible with popup since it is not an
241 // incognito window.
242 EXPECT_NE(browser(), p.browser);
243
244 // We should have three windows, each with one tab:
245 // 1. the browser() provided by the framework (unchanged in this test)
246 // 2. the incognito popup we created originally
247 // 3. the new incognito tabbed browser that was created by Navigate().
248 EXPECT_EQ(3u, BrowserList::size());
249 EXPECT_EQ(1, browser()->tab_count());
250 EXPECT_EQ(1, popup->tab_count());
251 EXPECT_EQ(1, p.browser->tab_count());
[email protected]b35b26b32011-05-05 20:35:14252 EXPECT_TRUE(p.browser->is_type_tabbed());
[email protected]a1feae52010-10-11 22:14:45253}
254
255// This test verifies that navigating with WindowOpenDisposition = NEW_POPUP
256// from a normal Browser results in a new Browser with TYPE_POPUP.
257IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_NewPopup) {
258 browser::NavigateParams p(MakeNavigateParams());
259 p.disposition = NEW_POPUP;
[email protected]588300d2011-04-28 21:06:35260 p.window_bounds = gfx::Rect(0, 0, 200, 200);
[email protected]19d9f3a2010-10-14 21:49:36261 browser::Navigate(&p);
[email protected]7d329992011-04-15 18:20:02262 // Wait for new popup to to load and gain focus.
263 ui_test_utils::WaitForNavigationInCurrentTab(p.browser);
[email protected]a1feae52010-10-11 22:14:45264
[email protected]7d329992011-04-15 18:20:02265 // Navigate() should have opened a new, focused popup window.
[email protected]a1feae52010-10-11 22:14:45266 EXPECT_NE(browser(), p.browser);
[email protected]9db263a2011-04-15 20:53:47267#if 0
268 // TODO(stevenjb): Enable this test. See: crbug.com/79493
[email protected]7d329992011-04-15 18:20:02269 EXPECT_TRUE(p.browser->window()->IsActive());
270#endif
[email protected]b35b26b32011-05-05 20:35:14271 EXPECT_TRUE(p.browser->is_type_popup());
272 EXPECT_FALSE(p.browser->is_app());
[email protected]a1feae52010-10-11 22:14:45273
274 // We should have two windows, the browser() provided by the framework and the
275 // new popup window.
276 EXPECT_EQ(2u, BrowserList::size());
277 EXPECT_EQ(1, browser()->tab_count());
278 EXPECT_EQ(1, p.browser->tab_count());
279}
280
281// This test verifies that navigating with WindowOpenDisposition = NEW_POPUP
[email protected]f112b0f2011-05-26 01:53:52282// from a normal Browser results in a new Browser with is_app() true.
283IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_NewPopup_ExtensionId) {
284 browser::NavigateParams p(MakeNavigateParams());
285 p.disposition = NEW_POPUP;
286 p.extension_app_id = "extensionappid";
287 p.window_bounds = gfx::Rect(0, 0, 200, 200);
288 browser::Navigate(&p);
289 // Wait for new popup to to load and gain focus.
290 ui_test_utils::WaitForNavigationInCurrentTab(p.browser);
291
292 // Navigate() should have opened a new, focused popup window.
293 EXPECT_NE(browser(), p.browser);
294 EXPECT_TRUE(p.browser->is_type_popup());
295 EXPECT_TRUE(p.browser->is_app());
296
297 // We should have two windows, the browser() provided by the framework and the
298 // new popup window.
299 EXPECT_EQ(2u, BrowserList::size());
300 EXPECT_EQ(1, browser()->tab_count());
301 EXPECT_EQ(1, p.browser->tab_count());
302}
303
304// This test verifies that navigating with WindowOpenDisposition = NEW_POPUP
[email protected]300d1e52011-01-19 23:57:57305// from a normal popup results in a new Browser with TYPE_POPUP.
306IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_NewPopupFromPopup) {
307 // Open a popup.
308 browser::NavigateParams p1(MakeNavigateParams());
309 p1.disposition = NEW_POPUP;
[email protected]588300d2011-04-28 21:06:35310 p1.window_bounds = gfx::Rect(0, 0, 200, 200);
[email protected]300d1e52011-01-19 23:57:57311 browser::Navigate(&p1);
312 // Open another popup.
313 browser::NavigateParams p2(MakeNavigateParams(p1.browser));
314 p2.disposition = NEW_POPUP;
[email protected]588300d2011-04-28 21:06:35315 p2.window_bounds = gfx::Rect(0, 0, 200, 200);
[email protected]300d1e52011-01-19 23:57:57316 browser::Navigate(&p2);
317
318 // Navigate() should have opened a new normal popup window.
319 EXPECT_NE(p1.browser, p2.browser);
[email protected]b35b26b32011-05-05 20:35:14320 EXPECT_TRUE(p2.browser->is_type_popup());
321 EXPECT_FALSE(p2.browser->is_app());
[email protected]300d1e52011-01-19 23:57:57322
323 // We should have three windows, the browser() provided by the framework,
324 // the first popup window, and the second popup window.
325 EXPECT_EQ(3u, BrowserList::size());
326 EXPECT_EQ(1, browser()->tab_count());
327 EXPECT_EQ(1, p1.browser->tab_count());
328 EXPECT_EQ(1, p2.browser->tab_count());
329}
330
331// This test verifies that navigating with WindowOpenDisposition = NEW_POPUP
[email protected]a1feae52010-10-11 22:14:45332// from an app frame results in a new Browser with TYPE_APP_POPUP.
333IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
334 Disposition_NewPopupFromAppWindow) {
[email protected]b35b26b32011-05-05 20:35:14335 Browser* app_browser = CreateEmptyBrowserForApp(Browser::TYPE_TABBED,
336 browser()->profile());
[email protected]a1feae52010-10-11 22:14:45337 browser::NavigateParams p(MakeNavigateParams(app_browser));
338 p.disposition = NEW_POPUP;
[email protected]588300d2011-04-28 21:06:35339 p.window_bounds = gfx::Rect(0, 0, 200, 200);
[email protected]19d9f3a2010-10-14 21:49:36340 browser::Navigate(&p);
[email protected]a1feae52010-10-11 22:14:45341
342 // Navigate() should have opened a new popup app window.
343 EXPECT_NE(app_browser, p.browser);
344 EXPECT_NE(browser(), p.browser);
[email protected]b35b26b32011-05-05 20:35:14345 EXPECT_TRUE(p.browser->is_type_popup());
346 EXPECT_TRUE(p.browser->is_app());
[email protected]a1feae52010-10-11 22:14:45347
348 // We should now have three windows, the app window, the app popup it created,
349 // and the original browser() provided by the framework.
350 EXPECT_EQ(3u, BrowserList::size());
351 EXPECT_EQ(1, browser()->tab_count());
352 EXPECT_EQ(1, app_browser->tab_count());
353 EXPECT_EQ(1, p.browser->tab_count());
354}
355
356// This test verifies that navigating with WindowOpenDisposition = NEW_POPUP
[email protected]300d1e52011-01-19 23:57:57357// from an app popup results in a new Browser also of TYPE_APP_POPUP.
358IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
359 Disposition_NewPopupFromAppPopup) {
[email protected]b35b26b32011-05-05 20:35:14360 Browser* app_browser = CreateEmptyBrowserForApp(Browser::TYPE_TABBED,
361 browser()->profile());
[email protected]300d1e52011-01-19 23:57:57362 // Open an app popup.
363 browser::NavigateParams p1(MakeNavigateParams(app_browser));
364 p1.disposition = NEW_POPUP;
[email protected]588300d2011-04-28 21:06:35365 p1.window_bounds = gfx::Rect(0, 0, 200, 200);
[email protected]300d1e52011-01-19 23:57:57366 browser::Navigate(&p1);
367 // Now open another app popup.
368 browser::NavigateParams p2(MakeNavigateParams(p1.browser));
369 p2.disposition = NEW_POPUP;
[email protected]588300d2011-04-28 21:06:35370 p2.window_bounds = gfx::Rect(0, 0, 200, 200);
[email protected]300d1e52011-01-19 23:57:57371 browser::Navigate(&p2);
372
373 // Navigate() should have opened a new popup app window.
374 EXPECT_NE(browser(), p1.browser);
375 EXPECT_NE(p1.browser, p2.browser);
[email protected]b35b26b32011-05-05 20:35:14376 EXPECT_TRUE(p2.browser->is_type_popup());
377 EXPECT_TRUE(p2.browser->is_app());
[email protected]300d1e52011-01-19 23:57:57378
379 // We should now have four windows, the app window, the first app popup,
380 // the second app popup, and the original browser() provided by the framework.
381 EXPECT_EQ(4u, BrowserList::size());
382 EXPECT_EQ(1, browser()->tab_count());
383 EXPECT_EQ(1, app_browser->tab_count());
384 EXPECT_EQ(1, p1.browser->tab_count());
385 EXPECT_EQ(1, p2.browser->tab_count());
386}
387
388// This test verifies that navigating with WindowOpenDisposition = NEW_POPUP
[email protected]a1feae52010-10-11 22:14:45389// from an extension app tab results in a new Browser with TYPE_APP_POPUP.
390IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
391 Disposition_NewPopupFromExtensionApp) {
392 // TODO(beng): TBD.
393}
394
[email protected]7d329992011-04-15 18:20:02395// This test verifies that navigating with window_action = SHOW_WINDOW_INACTIVE
396// does not focus a new new popup window.
397IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_NewPopupUnfocused) {
398 browser::NavigateParams p(MakeNavigateParams());
399 p.disposition = NEW_POPUP;
[email protected]588300d2011-04-28 21:06:35400 p.window_bounds = gfx::Rect(0, 0, 200, 200);
[email protected]7d329992011-04-15 18:20:02401 p.window_action = browser::NavigateParams::SHOW_WINDOW_INACTIVE;
402 browser::Navigate(&p);
403 // Wait for new popup to load (and gain focus if the test fails).
404 ui_test_utils::WaitForNavigationInCurrentTab(p.browser);
405
406 // Navigate() should have opened a new, unfocused, popup window.
407 EXPECT_NE(browser(), p.browser);
408 EXPECT_EQ(Browser::TYPE_POPUP, p.browser->type());
[email protected]9db263a2011-04-15 20:53:47409#if 0
410// TODO(stevenjb): Enable this test. See: crbug.com/79493
[email protected]7d329992011-04-15 18:20:02411 EXPECT_FALSE(p.browser->window()->IsActive());
[email protected]7d329992011-04-15 18:20:02412#endif
[email protected]9db263a2011-04-15 20:53:47413}
[email protected]7d329992011-04-15 18:20:02414
[email protected]a1feae52010-10-11 22:14:45415// This test verifies that navigating with WindowOpenDisposition = NEW_WINDOW
416// always opens a new window.
417IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_NewWindow) {
418 browser::NavigateParams p(MakeNavigateParams());
419 p.disposition = NEW_WINDOW;
[email protected]19d9f3a2010-10-14 21:49:36420 browser::Navigate(&p);
[email protected]a1feae52010-10-11 22:14:45421
422 // Navigate() should have opened a new toplevel window.
423 EXPECT_NE(browser(), p.browser);
[email protected]b35b26b32011-05-05 20:35:14424 EXPECT_TRUE(p.browser->is_type_tabbed());
[email protected]a1feae52010-10-11 22:14:45425
426 // We should now have two windows, the browser() provided by the framework and
427 // the new normal window.
428 EXPECT_EQ(2u, BrowserList::size());
429 EXPECT_EQ(1, browser()->tab_count());
430 EXPECT_EQ(1, p.browser->tab_count());
431}
432
433// This test verifies that navigating with WindowOpenDisposition = INCOGNITO
434// opens a new incognito window if no existing incognito window is present.
435IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_Incognito) {
436 browser::NavigateParams p(MakeNavigateParams());
437 p.disposition = OFF_THE_RECORD;
[email protected]19d9f3a2010-10-14 21:49:36438 browser::Navigate(&p);
[email protected]a1feae52010-10-11 22:14:45439
440 // Navigate() should have opened a new toplevel incognito window.
441 EXPECT_NE(browser(), p.browser);
442 EXPECT_EQ(browser()->profile()->GetOffTheRecordProfile(),
443 p.browser->profile());
444
[email protected]d7ff3592010-11-30 21:50:46445 // |source_contents| should be set to NULL because the profile for the new
446 // page is different from the originating page.
447 EXPECT_EQ(NULL, p.source_contents);
448
[email protected]a1feae52010-10-11 22:14:45449 // We should now have two windows, the browser() provided by the framework and
450 // the new incognito window.
451 EXPECT_EQ(2u, BrowserList::size());
452 EXPECT_EQ(1, browser()->tab_count());
453 EXPECT_EQ(1, p.browser->tab_count());
454}
455
456// This test verifies that navigating with WindowOpenDisposition = INCOGNITO
457// reuses an existing incognito window when possible.
458IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_IncognitoRefocus) {
459 Browser* incognito_browser =
[email protected]b35b26b32011-05-05 20:35:14460 CreateEmptyBrowserForType(Browser::TYPE_TABBED,
[email protected]a1feae52010-10-11 22:14:45461 browser()->profile()->GetOffTheRecordProfile());
462 browser::NavigateParams p(MakeNavigateParams());
463 p.disposition = OFF_THE_RECORD;
[email protected]19d9f3a2010-10-14 21:49:36464 browser::Navigate(&p);
[email protected]a1feae52010-10-11 22:14:45465
466 // Navigate() should have opened a new tab in the existing incognito window.
467 EXPECT_NE(browser(), p.browser);
468 EXPECT_EQ(p.browser, incognito_browser);
469
470 // We should now have two windows, the browser() provided by the framework and
471 // the incognito window we opened earlier.
472 EXPECT_EQ(2u, BrowserList::size());
473 EXPECT_EQ(1, browser()->tab_count());
474 EXPECT_EQ(2, incognito_browser->tab_count());
475}
476
477// This test verifies that no navigation action occurs when
478// WindowOpenDisposition = SUPPRESS_OPEN.
479IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_SuppressOpen) {
480 RunSuppressTest(SUPPRESS_OPEN);
481}
482
483// This test verifies that no navigation action occurs when
484// WindowOpenDisposition = SAVE_TO_DISK.
485IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_SaveToDisk) {
486 RunSuppressTest(SAVE_TO_DISK);
487}
488
489// This test verifies that no navigation action occurs when
490// WindowOpenDisposition = IGNORE_ACTION.
491IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_IgnoreAction) {
492 RunSuppressTest(IGNORE_ACTION);
493}
494
495// This tests adding a foreground tab with a predefined TabContents.
496IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, TargetContents_ForegroundTab) {
497 browser::NavigateParams p(MakeNavigateParams());
498 p.disposition = NEW_FOREGROUND_TAB;
499 p.target_contents = CreateTabContents();
[email protected]19d9f3a2010-10-14 21:49:36500 browser::Navigate(&p);
[email protected]a1feae52010-10-11 22:14:45501
502 // Navigate() should have opened the contents in a new foreground in the
503 // current Browser.
504 EXPECT_EQ(browser(), p.browser);
[email protected]3c9e1872010-11-18 16:17:49505 EXPECT_EQ(browser()->GetSelectedTabContentsWrapper(), p.target_contents);
[email protected]a1feae52010-10-11 22:14:45506
507 // We should have one window, with two tabs.
508 EXPECT_EQ(1u, BrowserList::size());
509 EXPECT_EQ(2, browser()->tab_count());
510}
511
512#if defined(OS_WIN)
513// This tests adding a popup with a predefined TabContents.
[email protected]76edb672011-03-04 21:48:39514IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, DISABLED_TargetContents_Popup) {
[email protected]a1feae52010-10-11 22:14:45515 browser::NavigateParams p(MakeNavigateParams());
516 p.disposition = NEW_POPUP;
517 p.target_contents = CreateTabContents();
518 p.window_bounds = gfx::Rect(10, 10, 500, 500);
[email protected]19d9f3a2010-10-14 21:49:36519 browser::Navigate(&p);
[email protected]a1feae52010-10-11 22:14:45520
521 // Navigate() should have opened a new popup window.
522 EXPECT_NE(browser(), p.browser);
[email protected]b35b26b32011-05-05 20:35:14523 EXPECT_TRUE(p.browser->is_type_popup());
524 EXPECT_FALSE(p.browser->is_app());
[email protected]a1feae52010-10-11 22:14:45525
526 // The web platform is weird. The window bounds specified in
527 // |p.window_bounds| are used as follows:
528 // - the origin is used to position the window
529 // - the size is used to size the TabContents of the window.
530 // As such the position of the resulting window will always match
531 // p.window_bounds.origin(), but its size will not. We need to match
532 // the size against the selected tab's view's container size.
533 // Only Windows positions the window according to |p.window_bounds.origin()| -
534 // on Mac the window is offset from the opener and on Linux it always opens
535 // at 0,0.
536 EXPECT_EQ(p.window_bounds.origin(),
537 p.browser->window()->GetRestoredBounds().origin());
538 // All platforms should respect size however provided width > 400 (Mac has a
539 // minimum window width of 400).
540 EXPECT_EQ(p.window_bounds.size(),
[email protected]3c9e1872010-11-18 16:17:49541 p.target_contents->tab_contents()->view()->GetContainerSize());
[email protected]a1feae52010-10-11 22:14:45542
543 // We should have two windows, the new popup and the browser() provided by the
544 // framework.
545 EXPECT_EQ(2u, BrowserList::size());
546 EXPECT_EQ(1, browser()->tab_count());
547 EXPECT_EQ(1, p.browser->tab_count());
548}
549#endif
550
551// This tests adding a tab at a specific index.
552IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Tabstrip_InsertAtIndex) {
553 // This is not meant to be a comprehensive test of whether or not the tab
554 // implementation of the browser observes the insertion index. That is
555 // covered by the unit tests for TabStripModel. This merely verifies that
556 // insertion index preference is reflected in common cases.
557 browser::NavigateParams p(MakeNavigateParams());
558 p.disposition = NEW_FOREGROUND_TAB;
559 p.tabstrip_index = 0;
560 p.tabstrip_add_types = TabStripModel::ADD_FORCE_INDEX;
[email protected]19d9f3a2010-10-14 21:49:36561 browser::Navigate(&p);
[email protected]a1feae52010-10-11 22:14:45562
563 // Navigate() should have inserted a new tab at slot 0 in the tabstrip.
564 EXPECT_EQ(browser(), p.browser);
565 EXPECT_EQ(0, browser()->tabstrip_model()->GetIndexOfTabContents(
[email protected]3c9e1872010-11-18 16:17:49566 static_cast<const TabContentsWrapper*>(p.target_contents)));
[email protected]a1feae52010-10-11 22:14:45567
568 // We should have one window - the browser() provided by the framework.
569 EXPECT_EQ(1u, BrowserList::size());
570 EXPECT_EQ(2, browser()->tab_count());
571}
572
[email protected]2dd85482010-11-06 01:56:47573// This test verifies that constructing params with a NULL browser has
574// the same result as navigating to a new foreground tab in the (only)
575// active browser. Tests are the same as for Disposition_NewForegroundTab.
576IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, NullBrowser_NewForegroundTab) {
577 TabContents* old_contents = browser()->GetSelectedTabContents();
578 // Navigate with a NULL browser.
579 browser::NavigateParams p(MakeNavigateParams(NULL));
580 p.disposition = NEW_FOREGROUND_TAB;
581 p.profile = browser()->profile();
582 browser::Navigate(&p);
583
584 // Navigate() should have found browser() and create a new tab.
585 EXPECT_EQ(browser(), p.browser);
586 EXPECT_NE(old_contents, browser()->GetSelectedTabContents());
[email protected]3c9e1872010-11-18 16:17:49587 EXPECT_EQ(browser()->GetSelectedTabContentsWrapper(), p.target_contents);
[email protected]2dd85482010-11-06 01:56:47588 EXPECT_EQ(2, browser()->tab_count());
589}
590
591// This test verifies that constructing params with a NULL browser and
592// a specific profile matches the specified profile.
593IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, NullBrowser_MatchProfile) {
594 // Create a new browser with using the incognito profile.
595 Browser* incognito =
596 Browser::Create(browser()->profile()->GetOffTheRecordProfile());
597
598 // Navigate with a NULL browser and the incognito profile.
599 browser::NavigateParams p(MakeNavigateParams(NULL));
600 p.disposition = NEW_FOREGROUND_TAB;
601 p.profile = incognito->profile();
602 browser::Navigate(&p);
603
604 // Navigate() should have found incognito, not browser().
605 EXPECT_EQ(incognito, p.browser);
[email protected]3c9e1872010-11-18 16:17:49606 EXPECT_EQ(incognito->GetSelectedTabContentsWrapper(), p.target_contents);
[email protected]2dd85482010-11-06 01:56:47607 EXPECT_EQ(1, incognito->tab_count());
608}
609
610// This test verifies that constructing params with a NULL browser and
611// disposition = NEW_WINDOW always opens exactly one new window.
612IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, NullBrowser_NewWindow) {
613 browser::NavigateParams p(MakeNavigateParams(NULL));
614 p.disposition = NEW_WINDOW;
615 p.profile = browser()->profile();
616 browser::Navigate(&p);
617
618 // Navigate() should have created a new browser.
619 EXPECT_NE(browser(), p.browser);
[email protected]b35b26b32011-05-05 20:35:14620 EXPECT_TRUE( p.browser->is_type_tabbed());
[email protected]2dd85482010-11-06 01:56:47621
622 // We should now have two windows, the browser() provided by the framework and
623 // the new normal window.
624 EXPECT_EQ(2u, BrowserList::size());
625 EXPECT_EQ(1, browser()->tab_count());
626 EXPECT_EQ(1, p.browser->tab_count());
627}
628
[email protected]bb89e7482010-11-17 18:27:04629// This test verifies that constructing params with disposition = SINGLETON_TAB
[email protected]fee320542011-03-02 01:30:49630// and IGNORE_AND_NAVIGATE opens a new tab navigated to the specified URL if
[email protected]67ed83e2011-01-07 22:54:00631// no previous tab with that URL (minus the path) exists.
[email protected]bb89e7482010-11-17 18:27:04632IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
633 Disposition_SingletonTabNew_IgnorePath) {
634 GURL url("http://www.google.com/");
635 browser()->AddSelectedTabWithURL(url, PageTransition::LINK);
636
637 // We should have one browser with 2 tabs, the 2nd selected.
638 EXPECT_EQ(1u, BrowserList::size());
639 EXPECT_EQ(2, browser()->tab_count());
[email protected]1ea49d52011-04-12 17:44:44640 EXPECT_EQ(1, browser()->active_index());
[email protected]bb89e7482010-11-17 18:27:04641
642 // Navigate to a new singleton tab with a sub-page.
643 browser::NavigateParams p(MakeNavigateParams());
644 p.disposition = SINGLETON_TAB;
645 p.url = GURL("chrome://settings/advanced");
[email protected]7d329992011-04-15 18:20:02646 p.window_action = browser::NavigateParams::SHOW_WINDOW;
[email protected]fee320542011-03-02 01:30:49647 p.path_behavior = browser::NavigateParams::IGNORE_AND_NAVIGATE;
[email protected]bb89e7482010-11-17 18:27:04648 browser::Navigate(&p);
649
650 // The last tab should now be selected and navigated to the sub-page of the
651 // URL.
652 EXPECT_EQ(browser(), p.browser);
653 EXPECT_EQ(3, browser()->tab_count());
[email protected]1ea49d52011-04-12 17:44:44654 EXPECT_EQ(2, browser()->active_index());
[email protected]bb89e7482010-11-17 18:27:04655 EXPECT_EQ(GURL("chrome://settings/advanced"),
656 browser()->GetSelectedTabContents()->GetURL());
657}
658
659// This test verifies that constructing params with disposition = SINGLETON_TAB
[email protected]fee320542011-03-02 01:30:49660// and IGNORE_AND_NAVIGATE opens an existing tab with the matching URL (minus
[email protected]bb89e7482010-11-17 18:27:04661// the path) which is navigated to the specified URL.
662IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
663 Disposition_SingletonTabExisting_IgnorePath) {
664 GURL singleton_url1("chrome://settings");
665 GURL url("http://www.google.com/");
666 browser()->AddSelectedTabWithURL(singleton_url1, PageTransition::LINK);
667 browser()->AddSelectedTabWithURL(url, PageTransition::LINK);
668
669 // We should have one browser with 3 tabs, the 3rd selected.
670 EXPECT_EQ(1u, BrowserList::size());
671 EXPECT_EQ(3, browser()->tab_count());
[email protected]1ea49d52011-04-12 17:44:44672 EXPECT_EQ(2, browser()->active_index());
[email protected]bb89e7482010-11-17 18:27:04673
674 // Navigate to singleton_url1.
675 browser::NavigateParams p(MakeNavigateParams());
676 p.disposition = SINGLETON_TAB;
677 p.url = GURL("chrome://settings/advanced");
[email protected]7d329992011-04-15 18:20:02678 p.window_action = browser::NavigateParams::SHOW_WINDOW;
[email protected]fee320542011-03-02 01:30:49679 p.path_behavior = browser::NavigateParams::IGNORE_AND_NAVIGATE;
[email protected]bb89e7482010-11-17 18:27:04680 browser::Navigate(&p);
681
682 // The middle tab should now be selected and navigated to the sub-page of the
683 // URL.
684 EXPECT_EQ(browser(), p.browser);
685 EXPECT_EQ(3, browser()->tab_count());
[email protected]1ea49d52011-04-12 17:44:44686 EXPECT_EQ(1, browser()->active_index());
[email protected]bb89e7482010-11-17 18:27:04687 EXPECT_EQ(GURL("chrome://settings/advanced"),
688 browser()->GetSelectedTabContents()->GetURL());
689}
690
691// This test verifies that constructing params with disposition = SINGLETON_TAB
[email protected]fee320542011-03-02 01:30:49692// and IGNORE_AND_NAVIGATE opens an existing tab with the matching URL (minus
[email protected]bb89e7482010-11-17 18:27:04693// the path) which is navigated to the specified URL.
694IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
695 Disposition_SingletonTabExistingSubPath_IgnorePath) {
696 GURL singleton_url1("chrome://settings/advanced");
697 GURL url("http://www.google.com/");
698 browser()->AddSelectedTabWithURL(singleton_url1, PageTransition::LINK);
699 browser()->AddSelectedTabWithURL(url, PageTransition::LINK);
700
701 // We should have one browser with 3 tabs, the 3rd selected.
702 EXPECT_EQ(1u, BrowserList::size());
703 EXPECT_EQ(3, browser()->tab_count());
[email protected]1ea49d52011-04-12 17:44:44704 EXPECT_EQ(2, browser()->active_index());
[email protected]bb89e7482010-11-17 18:27:04705
706 // Navigate to singleton_url1.
707 browser::NavigateParams p(MakeNavigateParams());
708 p.disposition = SINGLETON_TAB;
709 p.url = GURL("chrome://settings/personal");
[email protected]7d329992011-04-15 18:20:02710 p.window_action = browser::NavigateParams::SHOW_WINDOW;
[email protected]fee320542011-03-02 01:30:49711 p.path_behavior = browser::NavigateParams::IGNORE_AND_NAVIGATE;
[email protected]bb89e7482010-11-17 18:27:04712 browser::Navigate(&p);
713
714 // The middle tab should now be selected and navigated to the sub-page of the
715 // URL.
716 EXPECT_EQ(browser(), p.browser);
717 EXPECT_EQ(3, browser()->tab_count());
[email protected]1ea49d52011-04-12 17:44:44718 EXPECT_EQ(1, browser()->active_index());
[email protected]bb89e7482010-11-17 18:27:04719 EXPECT_EQ(GURL("chrome://settings/personal"),
720 browser()->GetSelectedTabContents()->GetURL());
721}
[email protected]2dd85482010-11-06 01:56:47722
[email protected]637b3442011-01-10 23:31:48723// This test verifies that constructing params with disposition = SINGLETON_TAB
[email protected]fee320542011-03-02 01:30:49724// and IGNORE_AND_STAY_PUT opens an existing tab with the matching URL (minus
725// the path).
726IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
727 Disposition_SingletonTabExistingSubPath_IgnorePath2) {
728 GURL singleton_url1("chrome://settings/advanced");
729 GURL url("http://www.google.com/");
730 browser()->AddSelectedTabWithURL(singleton_url1, PageTransition::LINK);
731 browser()->AddSelectedTabWithURL(url, PageTransition::LINK);
732
733 // We should have one browser with 3 tabs, the 3rd selected.
734 EXPECT_EQ(1u, BrowserList::size());
735 EXPECT_EQ(3, browser()->tab_count());
[email protected]1ea49d52011-04-12 17:44:44736 EXPECT_EQ(2, browser()->active_index());
[email protected]fee320542011-03-02 01:30:49737
738 // Navigate to singleton_url1.
739 browser::NavigateParams p(MakeNavigateParams());
740 p.disposition = SINGLETON_TAB;
741 p.url = GURL("chrome://settings/personal");
[email protected]7d329992011-04-15 18:20:02742 p.window_action = browser::NavigateParams::SHOW_WINDOW;
[email protected]fee320542011-03-02 01:30:49743 p.path_behavior = browser::NavigateParams::IGNORE_AND_STAY_PUT;
744 browser::Navigate(&p);
745
746 // The middle tab should now be selected.
747 EXPECT_EQ(browser(), p.browser);
748 EXPECT_EQ(3, browser()->tab_count());
[email protected]1ea49d52011-04-12 17:44:44749 EXPECT_EQ(1, browser()->active_index());
[email protected]fee320542011-03-02 01:30:49750 EXPECT_EQ(singleton_url1,
751 browser()->GetSelectedTabContents()->GetURL());
752}
753
754// This test verifies that constructing params with disposition = SINGLETON_TAB
755// and IGNORE_AND_NAVIGATE will update the current tab's URL if the currently
[email protected]637b3442011-01-10 23:31:48756// selected tab is a match but has a different path.
757IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
758 Disposition_SingletonTabFocused_IgnorePath) {
759 GURL singleton_url_current("chrome://settings/advanced");
760 GURL url("http://www.google.com/");
761 browser()->AddSelectedTabWithURL(singleton_url_current, PageTransition::LINK);
762
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]637b3442011-01-10 23:31:48767
768 // Navigate to a different settings path.
769 GURL singleton_url_target("chrome://settings/personal");
770 browser::NavigateParams p(MakeNavigateParams());
771 p.disposition = SINGLETON_TAB;
772 p.url = singleton_url_target;
[email protected]7d329992011-04-15 18:20:02773 p.window_action = browser::NavigateParams::SHOW_WINDOW;
[email protected]fee320542011-03-02 01:30:49774 p.path_behavior = browser::NavigateParams::IGNORE_AND_NAVIGATE;
[email protected]637b3442011-01-10 23:31:48775 browser::Navigate(&p);
776
777 // The second tab should still be selected, but navigated to the new path.
778 EXPECT_EQ(browser(), p.browser);
779 EXPECT_EQ(2, browser()->tab_count());
[email protected]1ea49d52011-04-12 17:44:44780 EXPECT_EQ(1, browser()->active_index());
[email protected]637b3442011-01-10 23:31:48781 EXPECT_EQ(singleton_url_target,
782 browser()->GetSelectedTabContents()->GetURL());
783}
784
[email protected]07afd7c2011-02-17 10:07:11785// This test verifies that constructing params with disposition = SINGLETON_TAB
[email protected]fee320542011-03-02 01:30:49786// and IGNORE_AND_NAVIGATE will open an existing matching tab with a different
787// query.
[email protected]07afd7c2011-02-17 10:07:11788IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
789 Disposition_SingletonTabExisting_IgnoreQuery) {
790 int initial_tab_count = browser()->tab_count();
791 GURL singleton_url_current("chrome://settings/internet");
792 browser()->AddSelectedTabWithURL(singleton_url_current, PageTransition::LINK);
793
794 EXPECT_EQ(initial_tab_count + 1, browser()->tab_count());
[email protected]1ea49d52011-04-12 17:44:44795 EXPECT_EQ(initial_tab_count, browser()->active_index());
[email protected]07afd7c2011-02-17 10:07:11796
797 // Navigate to a different settings path.
798 GURL singleton_url_target(
799 "chrome://settings/internet?"
800 "servicePath=/profile/ethernet_00aa00aa00aa&networkType=1");
801 browser::NavigateParams p(MakeNavigateParams());
802 p.disposition = SINGLETON_TAB;
803 p.url = singleton_url_target;
[email protected]7d329992011-04-15 18:20:02804 p.window_action = browser::NavigateParams::SHOW_WINDOW;
[email protected]fee320542011-03-02 01:30:49805 p.path_behavior = browser::NavigateParams::IGNORE_AND_NAVIGATE;
[email protected]07afd7c2011-02-17 10:07:11806 browser::Navigate(&p);
807
808 // Last tab should still be selected.
809 EXPECT_EQ(browser(), p.browser);
810 EXPECT_EQ(initial_tab_count + 1, browser()->tab_count());
[email protected]1ea49d52011-04-12 17:44:44811 EXPECT_EQ(initial_tab_count, browser()->active_index());
[email protected]07afd7c2011-02-17 10:07:11812}
813
[email protected]bd817c22011-02-09 08:16:46814// This test verifies that the settings page isn't opened in the incognito
815// window.
816IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
817 Disposition_Settings_UseNonIncognitoWindow) {
818 Browser* incognito_browser = CreateIncognitoBrowser();
819
820 EXPECT_EQ(2u, BrowserList::size());
821 EXPECT_EQ(1, browser()->tab_count());
822 EXPECT_EQ(1, incognito_browser->tab_count());
823
824 // Navigate to the settings page.
825 browser::NavigateParams p(MakeNavigateParams(incognito_browser));
826 p.disposition = SINGLETON_TAB;
827 p.url = GURL("chrome://settings");
[email protected]7d329992011-04-15 18:20:02828 p.window_action = browser::NavigateParams::SHOW_WINDOW;
[email protected]bd817c22011-02-09 08:16:46829 browser::Navigate(&p);
830
831 // The settings page should be opened in browser() window.
832 EXPECT_NE(incognito_browser, p.browser);
833 EXPECT_EQ(browser(), p.browser);
834 EXPECT_EQ(2, browser()->tab_count());
835 EXPECT_EQ(GURL("chrome://settings"),
836 browser()->GetSelectedTabContents()->GetURL());
837}
838
[email protected]82404cd2011-07-12 19:55:14839// This test verifies that the settings page isn't opened in the incognito
840// window from a non-incognito window (bookmark open-in-incognito trigger).
841IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
842 Disposition_Settings_UseNonIncognitoWindowForBookmark) {
843 browser::NavigateParams params(browser(), GURL("chrome://settings"),
844 PageTransition::AUTO_BOOKMARK);
845 params.disposition = OFF_THE_RECORD;
846 {
847 ui_test_utils::WindowedNotificationObserver observer(
848 content::NOTIFICATION_LOAD_STOP, NotificationService::AllSources());
849 browser::Navigate(&params);
850 observer.Wait();
851 }
852
853 EXPECT_EQ(1u, BrowserList::size());
854 EXPECT_EQ(GURL("chrome://settings"),
855 browser()->GetSelectedTabContents()->GetURL().GetOrigin());
856}
857
[email protected]bd817c22011-02-09 08:16:46858// This test verifies that the bookmarks page isn't opened in the incognito
859// window.
860IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
861 Disposition_Bookmarks_UseNonIncognitoWindow) {
862 Browser* incognito_browser = CreateIncognitoBrowser();
863
864 EXPECT_EQ(2u, BrowserList::size());
865 EXPECT_EQ(1, browser()->tab_count());
866 EXPECT_EQ(1, incognito_browser->tab_count());
867
868 // Navigate to the settings page.
869 browser::NavigateParams p(MakeNavigateParams(incognito_browser));
870 p.disposition = SINGLETON_TAB;
871 p.url = GURL("chrome://bookmarks");
[email protected]7d329992011-04-15 18:20:02872 p.window_action = browser::NavigateParams::SHOW_WINDOW;
[email protected]bd817c22011-02-09 08:16:46873 browser::Navigate(&p);
874
875 // The bookmarks page should be opened in browser() window.
876 EXPECT_NE(incognito_browser, p.browser);
877 EXPECT_EQ(browser(), p.browser);
878 EXPECT_EQ(2, browser()->tab_count());
879 EXPECT_EQ(GURL("chrome://bookmarks"),
880 browser()->GetSelectedTabContents()->GetURL());
881}
882
[email protected]7de53c62011-05-13 06:44:16883// This test makes sure a crashed singleton tab reloads from a new navigation.
884IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
885 NavigateToCrashedSingletonTab) {
886 GURL singleton_url("chrome://settings/advanced");
887 TabContentsWrapper* wrapper =
888 browser()->AddSelectedTabWithURL(singleton_url, PageTransition::LINK);
889 TabContents* tab_contents = wrapper->tab_contents();
890
891 // We should have one browser with 2 tabs, the 2nd selected.
892 EXPECT_EQ(1u, BrowserList::size());
893 EXPECT_EQ(2, browser()->tab_count());
894 EXPECT_EQ(1, browser()->active_index());
895
896 // Kill the singleton tab.
897 tab_contents->SetIsCrashed(base::TERMINATION_STATUS_PROCESS_CRASHED, -1);
898 EXPECT_TRUE(tab_contents->is_crashed());
899
900 browser::NavigateParams p(MakeNavigateParams());
901 p.disposition = SINGLETON_TAB;
902 p.url = singleton_url;
903 p.window_action = browser::NavigateParams::SHOW_WINDOW;
904 p.path_behavior = browser::NavigateParams::IGNORE_AND_NAVIGATE;
905 browser::Navigate(&p);
906 ui_test_utils::WaitForNavigationInCurrentTab(browser());
907
908 // The tab should not be sad anymore.
909 EXPECT_FALSE(tab_contents->is_crashed());
910}
911
[email protected]fcca741b2011-06-17 22:46:37912IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
913 NavigateFromDefaultToOptionsInSameTab) {
914 browser()->OpenOptionsDialog();
915 ui_test_utils::WaitForNavigationInCurrentTab(browser());
916 EXPECT_EQ(1, browser()->tab_count());
917 EXPECT_EQ(GURL("chrome://settings/browser"),
918 browser()->GetSelectedTabContents()->GetURL());
919}
920
921IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
922 NavigateFromBlankToOptionsInSameTab) {
923 browser::NavigateParams p(MakeNavigateParams());
924 p.url = GURL("about:blank");
925 browser::Navigate(&p);
926 ui_test_utils::WaitForNavigationInCurrentTab(browser());
927
928 browser()->OpenOptionsDialog();
929 ui_test_utils::WaitForNavigationInCurrentTab(browser());
930 EXPECT_EQ(1, browser()->tab_count());
931 EXPECT_EQ(GURL("chrome://settings/browser"),
932 browser()->GetSelectedTabContents()->GetURL());
933}
934
935IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
936 NavigateFromNTPToOptionsInSameTab) {
937 browser::NavigateParams p(MakeNavigateParams());
938 p.url = GURL("chrome://newtab");
939 browser::Navigate(&p);
940 ui_test_utils::WaitForNavigationInCurrentTab(browser());
941 EXPECT_EQ(1, browser()->tab_count());
942 EXPECT_EQ(GURL("chrome://newtab"),
943 browser()->GetSelectedTabContents()->GetURL());
944
945 browser()->OpenOptionsDialog();
946 ui_test_utils::WaitForNavigationInCurrentTab(browser());
947 EXPECT_EQ(1, browser()->tab_count());
948 EXPECT_EQ(GURL("chrome://settings/browser"),
949 browser()->GetSelectedTabContents()->GetURL());
950}
951
952IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
953 NavigateFromPageToOptionsInNewTab) {
954 browser::NavigateParams p(MakeNavigateParams());
955 browser::Navigate(&p);
956 ui_test_utils::WaitForNavigationInCurrentTab(browser());
957 EXPECT_EQ(GetGoogleURL(), browser()->GetSelectedTabContents()->GetURL());
958 EXPECT_EQ(1u, BrowserList::size());
959 EXPECT_EQ(1, browser()->tab_count());
960
961 browser()->OpenOptionsDialog();
962 ui_test_utils::WaitForNavigationInCurrentTab(browser());
963 EXPECT_EQ(2, browser()->tab_count());
964 EXPECT_EQ(GURL("chrome://settings/browser"),
965 browser()->GetSelectedTabContents()->GetURL());
966}
967
968IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
969 NavigateFromNTPToOptionsSingleton) {
970 browser()->OpenOptionsDialog();
971 ui_test_utils::WaitForNavigationInCurrentTab(browser());
972 EXPECT_EQ(1, browser()->tab_count());
973
974 browser()->NewTab();
975 EXPECT_EQ(2, browser()->tab_count());
976
977 browser()->OpenOptionsDialog();
978 EXPECT_EQ(2, browser()->tab_count());
979 EXPECT_EQ(GURL("chrome://settings"),
980 browser()->GetSelectedTabContents()->GetURL());
981}
982
983IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
984 NavigateFromNTPToOptionsPageInSameTab) {
985 browser()->ShowOptionsTab("personal");
986 ui_test_utils::WaitForNavigationInCurrentTab(browser());
987 EXPECT_EQ(1, browser()->tab_count());
988 EXPECT_EQ(GURL("chrome://settings/personal"),
989 browser()->GetSelectedTabContents()->GetURL());
990
991 browser()->NewTab();
992 EXPECT_EQ(2, browser()->tab_count());
993
994 browser()->ShowOptionsTab("personal");
995 EXPECT_EQ(2, browser()->tab_count());
996 EXPECT_EQ(GURL("chrome://settings/personal"),
997 browser()->GetSelectedTabContents()->GetURL());
998}
999
1000IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
1001 NavigateFromOtherTabToSingletonOptions) {
1002 browser()->OpenOptionsDialog();
1003 ui_test_utils::WaitForNavigationInCurrentTab(browser());
1004 browser()->AddSelectedTabWithURL(GetGoogleURL(), PageTransition::LINK);
1005 ui_test_utils::WaitForNavigationInCurrentTab(browser());
1006
1007 browser()->OpenOptionsDialog();
1008 ui_test_utils::WaitForNavigationInCurrentTab(browser());
1009 EXPECT_EQ(2, browser()->tab_count());
1010 EXPECT_EQ(GURL("chrome://settings/browser"),
1011 browser()->GetSelectedTabContents()->GetURL());
1012}
1013
[email protected]26c53e662011-07-09 02:21:021014// Tests that when a new tab is opened from the omnibox, the focus is moved from
1015// the omnibox for the current tab.
1016IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
1017 NavigateFromOmniboxIntoNewTab) {
1018 GURL url("http://www.google.com/");
1019 GURL url2("http://maps.google.com/");
1020
1021 // Navigate to url.
1022 browser::NavigateParams p(MakeNavigateParams());
1023 p.disposition = CURRENT_TAB;
1024 p.url = url;
1025 browser::Navigate(&p);
1026
1027 // Focus the omnibox.
1028 browser()->FocusLocationBar();
1029
1030 AutocompleteEditController* controller =
1031 browser()->window()->GetLocationBar()->location_entry()->model()->
1032 controller();
1033
1034 // Simulate an alt-enter.
1035 controller->OnAutocompleteAccept(url2, NEW_FOREGROUND_TAB,
1036 PageTransition::TYPED, GURL());
1037
1038 // Make sure the second tab is selected.
1039 EXPECT_EQ(1, browser()->active_index());
1040
1041 // The tab contents should have the focus in the second tab.
1042 EXPECT_TRUE(ui_test_utils::IsViewFocused(browser(),
1043 VIEW_ID_TAB_CONTAINER_FOCUS_VIEW));
1044
1045 // Go back to the first tab. The focus should not be in the omnibox.
1046 browser()->SelectPreviousTab();
1047 EXPECT_EQ(0, browser()->active_index());
1048 EXPECT_FALSE(ui_test_utils::IsViewFocused(browser(),
1049 VIEW_ID_LOCATION_BAR));
1050}
1051
[email protected]83de85e2010-10-12 23:05:161052} // namespace