blob: e11d8cd28c573dbcb4d1a89fa3c36fa648e84d18 [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]ddddfda2011-07-14 23:19:3919#include "chrome/common/url_constants.h"
[email protected]af44e7fb2011-07-29 18:32:3220#include "chrome/test/base/ui_test_utils.h"
[email protected]299425b2011-03-02 07:45:2021#include "content/browser/tab_contents/tab_contents.h"
[email protected]ddddfda2011-07-14 23:19:3922#include "content/browser/tab_contents/tab_contents_view.h"
[email protected]0d6e9bd2011-10-18 04:29:1623#include "content/public/browser/notification_types.h"
[email protected]a1feae52010-10-11 22:14:4524
[email protected]ddddfda2011-07-14 23:19:3925namespace {
26
27GURL GetGoogleURL() {
[email protected]bd817c22011-02-09 08:16:4628 return GURL("http://www.google.com/");
29}
[email protected]a1feae52010-10-11 22:14:4530
[email protected]ddddfda2011-07-14 23:19:3931GURL GetSettingsURL() {
32 return GURL(chrome::kChromeUISettingsURL);
33}
34
35GURL GetSettingsAdvancedURL() {
36 return GURL(chrome::kChromeUISettingsURL).Resolve(
37 chrome::kAdvancedOptionsSubPage);
38}
39
40GURL GetSettingsBrowserURL() {
41 return GURL(chrome::kChromeUISettingsURL).Resolve(
42 chrome::kBrowserOptionsSubPage);
43}
44
45GURL GetSettingsPersonalURL() {
46 return GURL(chrome::kChromeUISettingsURL).Resolve(
47 chrome::kPersonalOptionsSubPage);
48}
49
50} // namespace
51
52
[email protected]bd817c22011-02-09 08:16:4653browser::NavigateParams BrowserNavigatorTest::MakeNavigateParams() const {
54 return MakeNavigateParams(browser());
55}
[email protected]a1feae52010-10-11 22:14:4556
[email protected]bd817c22011-02-09 08:16:4657browser::NavigateParams BrowserNavigatorTest::MakeNavigateParams(
58 Browser* browser) const {
59 browser::NavigateParams params(browser, GetGoogleURL(),
[email protected]2905f742011-10-13 03:51:5860 content::PAGE_TRANSITION_LINK);
[email protected]7d329992011-04-15 18:20:0261 params.window_action = browser::NavigateParams::SHOW_WINDOW;
[email protected]bd817c22011-02-09 08:16:4662 return params;
63}
[email protected]a1feae52010-10-11 22:14:4564
[email protected]bd817c22011-02-09 08:16:4665Browser* BrowserNavigatorTest::CreateEmptyBrowserForType(Browser::Type type,
66 Profile* profile) {
67 Browser* browser = Browser::CreateForType(type, profile);
68 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) {
74 Browser* browser = Browser::CreateForApp(Browser::TYPE_POPUP, "Test",
[email protected]5c209242011-06-06 20:36:1775 gfx::Rect(), profile);
[email protected]b35b26b32011-05-05 20:35:1476 browser->AddBlankTab(true);
77 return browser;
78}
79
[email protected]bd817c22011-02-09 08:16:4680TabContentsWrapper* BrowserNavigatorTest::CreateTabContents() {
81 return Browser::TabContentsFactory(
82 browser()->profile(),
83 NULL,
84 MSG_ROUTING_NONE,
85 browser()->GetSelectedTabContents(),
86 NULL);
87}
[email protected]a1feae52010-10-11 22:14:4588
[email protected]bd817c22011-02-09 08:16:4689void BrowserNavigatorTest::RunSuppressTest(WindowOpenDisposition disposition) {
90 GURL old_url = browser()->GetSelectedTabContents()->GetURL();
91 browser::NavigateParams p(MakeNavigateParams());
92 p.disposition = disposition;
93 browser::Navigate(&p);
[email protected]a1feae52010-10-11 22:14:4594
[email protected]bd817c22011-02-09 08:16:4695 // Nothing should have happened as a result of Navigate();
96 EXPECT_EQ(1, browser()->tab_count());
97 EXPECT_EQ(1u, BrowserList::size());
98 EXPECT_EQ(old_url, browser()->GetSelectedTabContents()->GetURL());
99}
[email protected]bb89e7482010-11-17 18:27:04100
[email protected]432115822011-07-10 15:52:27101void BrowserNavigatorTest::Observe(int type,
[email protected]bd817c22011-02-09 08:16:46102 const NotificationSource& source,
103 const NotificationDetails& details) {
[email protected]432115822011-07-10 15:52:27104 switch (type) {
105 case content::NOTIFICATION_RENDER_VIEW_HOST_CREATED_FOR_TAB: {
[email protected]bd817c22011-02-09 08:16:46106 ++this->created_tab_contents_count_;
107 break;
[email protected]fa7ebe02010-11-29 23:04:57108 }
[email protected]bd817c22011-02-09 08:16:46109 default:
110 break;
[email protected]fa7ebe02010-11-29 23:04:57111 }
[email protected]bd817c22011-02-09 08:16:46112}
[email protected]fa7ebe02010-11-29 23:04:57113
[email protected]ddddfda2011-07-14 23:19:39114
[email protected]bd817c22011-02-09 08:16:46115namespace {
[email protected]a1feae52010-10-11 22:14:45116
[email protected]a1feae52010-10-11 22:14:45117// This test verifies that when a navigation occurs within a tab, the tab count
118// of the Browser remains the same and the current tab bears the loaded URL.
119IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_CurrentTab) {
[email protected]ddddfda2011-07-14 23:19:39120 ui_test_utils::NavigateToURL(browser(), GetGoogleURL());
[email protected]a1feae52010-10-11 22:14:45121 EXPECT_EQ(GetGoogleURL(), browser()->GetSelectedTabContents()->GetURL());
122 // We should have one window with one tab.
123 EXPECT_EQ(1u, BrowserList::size());
124 EXPECT_EQ(1, browser()->tab_count());
125}
126
[email protected]bd817c22011-02-09 08:16:46127// This test verifies that a singleton tab is refocused if one is already opened
[email protected]19d9f3a2010-10-14 21:49:36128// in another or an existing window, or added if it is not.
129IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_SingletonTabExisting) {
[email protected]19d9f3a2010-10-14 21:49:36130 GURL singleton_url1("http://maps.google.com/");
[email protected]fa7ebe02010-11-29 23:04:57131
132 // Register for a notification if an additional tab_contents was instantiated.
[email protected]bd817c22011-02-09 08:16:46133 // Opening a Singleton tab that is already opened should not be opening a new
[email protected]fa7ebe02010-11-29 23:04:57134 // tab nor be creating a new TabContents object
135 NotificationRegistrar registrar;
136
137 // As the registrar object goes out of scope, this will get unregistered
[email protected]432115822011-07-10 15:52:27138 registrar.Add(this, content::NOTIFICATION_RENDER_VIEW_HOST_CREATED_FOR_TAB,
[email protected]fa7ebe02010-11-29 23:04:57139 NotificationService::AllSources());
140
[email protected]2905f742011-10-13 03:51:58141 browser()->AddSelectedTabWithURL(
142 singleton_url1, content::PAGE_TRANSITION_LINK);
143 browser()->AddSelectedTabWithURL(
144 GetGoogleURL(), content::PAGE_TRANSITION_LINK);
[email protected]19d9f3a2010-10-14 21:49:36145
146 // We should have one browser with 3 tabs, the 3rd selected.
147 EXPECT_EQ(1u, BrowserList::size());
[email protected]1ea49d52011-04-12 17:44:44148 EXPECT_EQ(2, browser()->active_index());
[email protected]19d9f3a2010-10-14 21:49:36149
[email protected]fa7ebe02010-11-29 23:04:57150 unsigned int previous_tab_contents_count =
151 created_tab_contents_count_ = 0;
152
[email protected]19d9f3a2010-10-14 21:49:36153 // Navigate to singleton_url1.
154 browser::NavigateParams p(MakeNavigateParams());
155 p.disposition = SINGLETON_TAB;
156 p.url = singleton_url1;
157 browser::Navigate(&p);
158
159 // The middle tab should now be selected.
160 EXPECT_EQ(browser(), p.browser);
[email protected]1ea49d52011-04-12 17:44:44161 EXPECT_EQ(1, browser()->active_index());
[email protected]fa7ebe02010-11-29 23:04:57162
163 // No tab contents should have been created
164 EXPECT_EQ(previous_tab_contents_count,
165 created_tab_contents_count_);
[email protected]19d9f3a2010-10-14 21:49:36166}
167
168IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
[email protected]578c6962011-08-24 22:06:40169 Disposition_SingletonTabRespectingRef) {
170 GURL singleton_ref_url1("http://maps.google.com/#a");
171 GURL singleton_ref_url2("http://maps.google.com/#b");
172 GURL singleton_ref_url3("http://maps.google.com/");
173
[email protected]2905f742011-10-13 03:51:58174 browser()->AddSelectedTabWithURL(
175 singleton_ref_url1, content::PAGE_TRANSITION_LINK);
[email protected]578c6962011-08-24 22:06:40176
177 // We should have one browser with 2 tabs, 2nd selected.
178 EXPECT_EQ(1u, BrowserList::size());
179 EXPECT_EQ(2, browser()->tab_count());
180 EXPECT_EQ(1, browser()->active_index());
181
182 // Navigate to singleton_url2.
183 browser::NavigateParams p(MakeNavigateParams());
184 p.disposition = SINGLETON_TAB;
185 p.url = singleton_ref_url2;
186 browser::Navigate(&p);
187
188 // We should now have 2 tabs, the 2nd one selected.
189 EXPECT_EQ(browser(), p.browser);
190 EXPECT_EQ(2, browser()->tab_count());
191 EXPECT_EQ(1, browser()->active_index());
192
193 // Navigate to singleton_url2, but with respect ref set.
194 p = MakeNavigateParams();
195 p.disposition = SINGLETON_TAB;
196 p.url = singleton_ref_url2;
197 p.ref_behavior = browser::NavigateParams::RESPECT_REF;
198 browser::Navigate(&p);
199
200 // We should now have 3 tabs, the 3th one selected.
201 EXPECT_EQ(browser(), p.browser);
202 EXPECT_EQ(3, browser()->tab_count());
203 EXPECT_EQ(2, browser()->active_index());
204
205 // Navigate to singleton_url3.
206 p = MakeNavigateParams();
207 p.disposition = SINGLETON_TAB;
208 p.url = singleton_ref_url3;
209 p.ref_behavior = browser::NavigateParams::RESPECT_REF;
210 browser::Navigate(&p);
211
212 // We should now have 4 tabs, the 4th one selected.
213 EXPECT_EQ(browser(), p.browser);
214 EXPECT_EQ(4, browser()->tab_count());
215 EXPECT_EQ(3, browser()->active_index());
216}
217
218IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
[email protected]19d9f3a2010-10-14 21:49:36219 Disposition_SingletonTabNoneExisting) {
[email protected]19d9f3a2010-10-14 21:49:36220 GURL singleton_url1("http://maps.google.com/");
221
[email protected]bd817c22011-02-09 08:16:46222 // We should have one browser with 1 tab.
[email protected]19d9f3a2010-10-14 21:49:36223 EXPECT_EQ(1u, BrowserList::size());
[email protected]1ea49d52011-04-12 17:44:44224 EXPECT_EQ(0, browser()->active_index());
[email protected]19d9f3a2010-10-14 21:49:36225
226 // Navigate to singleton_url1.
227 browser::NavigateParams p(MakeNavigateParams());
228 p.disposition = SINGLETON_TAB;
229 p.url = singleton_url1;
230 browser::Navigate(&p);
231
232 // We should now have 2 tabs, the 2nd one selected.
233 EXPECT_EQ(browser(), p.browser);
234 EXPECT_EQ(2, browser()->tab_count());
[email protected]1ea49d52011-04-12 17:44:44235 EXPECT_EQ(1, browser()->active_index());
[email protected]a1feae52010-10-11 22:14:45236}
237
238// This test verifies that when a navigation results in a foreground tab, the
239// tab count of the Browser increases and the selected tab shifts to the new
240// foreground tab.
241IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_NewForegroundTab) {
242 TabContents* old_contents = browser()->GetSelectedTabContents();
243 browser::NavigateParams p(MakeNavigateParams());
244 p.disposition = NEW_FOREGROUND_TAB;
[email protected]19d9f3a2010-10-14 21:49:36245 browser::Navigate(&p);
[email protected]a1feae52010-10-11 22:14:45246 EXPECT_NE(old_contents, browser()->GetSelectedTabContents());
[email protected]3c9e1872010-11-18 16:17:49247 EXPECT_EQ(browser()->GetSelectedTabContentsWrapper(), p.target_contents);
[email protected]a1feae52010-10-11 22:14:45248 EXPECT_EQ(2, browser()->tab_count());
249}
250
251// This test verifies that when a navigation results in a background tab, the
252// tab count of the Browser increases but the selected tab remains the same.
253IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_NewBackgroundTab) {
254 TabContents* old_contents = browser()->GetSelectedTabContents();
255 browser::NavigateParams p(MakeNavigateParams());
256 p.disposition = NEW_BACKGROUND_TAB;
[email protected]19d9f3a2010-10-14 21:49:36257 browser::Navigate(&p);
[email protected]a1feae52010-10-11 22:14:45258 TabContents* new_contents = browser()->GetSelectedTabContents();
259 // The selected tab should have remained unchanged, since the new tab was
260 // opened in the background.
261 EXPECT_EQ(old_contents, new_contents);
262 EXPECT_EQ(2, browser()->tab_count());
263}
264
265// This test verifies that when a navigation requiring a new foreground tab
266// occurs in a Browser that cannot host multiple tabs, the new foreground tab
267// is created in an existing compatible Browser.
268IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
269 Disposition_IncompatibleWindow_Existing) {
270 // Open a foreground tab in a window that cannot open popups when there is an
271 // existing compatible window somewhere else that they can be opened within.
272 Browser* popup = CreateEmptyBrowserForType(Browser::TYPE_POPUP,
273 browser()->profile());
274 browser::NavigateParams p(MakeNavigateParams(popup));
275 p.disposition = NEW_FOREGROUND_TAB;
[email protected]19d9f3a2010-10-14 21:49:36276 browser::Navigate(&p);
[email protected]a1feae52010-10-11 22:14:45277
278 // Navigate() should have opened the tab in a different browser since the
279 // one we supplied didn't support additional tabs.
280 EXPECT_NE(popup, p.browser);
281
282 // Since browser() is an existing compatible tabbed browser, it should have
283 // opened the tab there.
284 EXPECT_EQ(browser(), p.browser);
285
286 // We should be left with 2 windows, the popup with one tab and the browser()
287 // provided by the framework with two.
288 EXPECT_EQ(2u, BrowserList::size());
289 EXPECT_EQ(1, popup->tab_count());
290 EXPECT_EQ(2, browser()->tab_count());
291}
292
293// This test verifies that when a navigation requiring a new foreground tab
294// occurs in a Browser that cannot host multiple tabs and no compatible Browser
295// that can is open, a compatible Browser is created.
296IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
297 Disposition_IncompatibleWindow_NoExisting) {
298 // We want to simulate not being able to find an existing window compatible
299 // with our non-tabbed browser window so Navigate() is forced to create a
300 // new compatible window. Because browser() supplied by the in-process
301 // browser testing framework is compatible with browser()->profile(), we
302 // need a different profile, and creating a popup window with an incognito
303 // profile is a quick and dirty way of achieving this.
304 Browser* popup = CreateEmptyBrowserForType(
[email protected]b35b26b32011-05-05 20:35:14305 Browser::TYPE_POPUP,
306 browser()->profile()->GetOffTheRecordProfile());
[email protected]a1feae52010-10-11 22:14:45307 browser::NavigateParams p(MakeNavigateParams(popup));
308 p.disposition = NEW_FOREGROUND_TAB;
[email protected]19d9f3a2010-10-14 21:49:36309 browser::Navigate(&p);
[email protected]a1feae52010-10-11 22:14:45310
311 // Navigate() should have opened the tab in a different browser since the
312 // one we supplied didn't support additional tabs.
313 EXPECT_NE(popup, p.browser);
314
315 // This time, browser() is _not_ compatible with popup since it is not an
316 // incognito window.
317 EXPECT_NE(browser(), p.browser);
318
319 // We should have three windows, each with one tab:
320 // 1. the browser() provided by the framework (unchanged in this test)
321 // 2. the incognito popup we created originally
322 // 3. the new incognito tabbed browser that was created by Navigate().
323 EXPECT_EQ(3u, BrowserList::size());
324 EXPECT_EQ(1, browser()->tab_count());
325 EXPECT_EQ(1, popup->tab_count());
326 EXPECT_EQ(1, p.browser->tab_count());
[email protected]b35b26b32011-05-05 20:35:14327 EXPECT_TRUE(p.browser->is_type_tabbed());
[email protected]a1feae52010-10-11 22:14:45328}
329
330// This test verifies that navigating with WindowOpenDisposition = NEW_POPUP
331// from a normal Browser results in a new Browser with TYPE_POPUP.
332IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_NewPopup) {
333 browser::NavigateParams p(MakeNavigateParams());
334 p.disposition = NEW_POPUP;
[email protected]588300d2011-04-28 21:06:35335 p.window_bounds = gfx::Rect(0, 0, 200, 200);
[email protected]7d329992011-04-15 18:20:02336 // Wait for new popup to to load and gain focus.
[email protected]ddddfda2011-07-14 23:19:39337 ui_test_utils::NavigateToURL(&p);
[email protected]a1feae52010-10-11 22:14:45338
[email protected]7d329992011-04-15 18:20:02339 // Navigate() should have opened a new, focused popup window.
[email protected]a1feae52010-10-11 22:14:45340 EXPECT_NE(browser(), p.browser);
[email protected]9db263a2011-04-15 20:53:47341#if 0
342 // TODO(stevenjb): Enable this test. See: crbug.com/79493
[email protected]7d329992011-04-15 18:20:02343 EXPECT_TRUE(p.browser->window()->IsActive());
344#endif
[email protected]b35b26b32011-05-05 20:35:14345 EXPECT_TRUE(p.browser->is_type_popup());
346 EXPECT_FALSE(p.browser->is_app());
[email protected]a1feae52010-10-11 22:14:45347
348 // We should have two windows, the browser() provided by the framework and the
349 // new popup window.
350 EXPECT_EQ(2u, BrowserList::size());
351 EXPECT_EQ(1, browser()->tab_count());
352 EXPECT_EQ(1, p.browser->tab_count());
353}
354
355// This test verifies that navigating with WindowOpenDisposition = NEW_POPUP
[email protected]f112b0f2011-05-26 01:53:52356// from a normal Browser results in a new Browser with is_app() true.
357IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_NewPopup_ExtensionId) {
358 browser::NavigateParams p(MakeNavigateParams());
359 p.disposition = NEW_POPUP;
360 p.extension_app_id = "extensionappid";
361 p.window_bounds = gfx::Rect(0, 0, 200, 200);
[email protected]f112b0f2011-05-26 01:53:52362 // Wait for new popup to to load and gain focus.
[email protected]ddddfda2011-07-14 23:19:39363 ui_test_utils::NavigateToURL(&p);
[email protected]f112b0f2011-05-26 01:53:52364
365 // Navigate() should have opened a new, focused popup window.
366 EXPECT_NE(browser(), p.browser);
367 EXPECT_TRUE(p.browser->is_type_popup());
368 EXPECT_TRUE(p.browser->is_app());
369
370 // We should have two windows, the browser() provided by the framework and the
371 // new popup window.
372 EXPECT_EQ(2u, BrowserList::size());
373 EXPECT_EQ(1, browser()->tab_count());
374 EXPECT_EQ(1, p.browser->tab_count());
375}
376
377// This test verifies that navigating with WindowOpenDisposition = NEW_POPUP
[email protected]300d1e52011-01-19 23:57:57378// from a normal popup results in a new Browser with TYPE_POPUP.
379IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_NewPopupFromPopup) {
380 // Open a popup.
381 browser::NavigateParams p1(MakeNavigateParams());
382 p1.disposition = NEW_POPUP;
[email protected]588300d2011-04-28 21:06:35383 p1.window_bounds = gfx::Rect(0, 0, 200, 200);
[email protected]300d1e52011-01-19 23:57:57384 browser::Navigate(&p1);
385 // Open another popup.
386 browser::NavigateParams p2(MakeNavigateParams(p1.browser));
387 p2.disposition = NEW_POPUP;
[email protected]588300d2011-04-28 21:06:35388 p2.window_bounds = gfx::Rect(0, 0, 200, 200);
[email protected]300d1e52011-01-19 23:57:57389 browser::Navigate(&p2);
390
391 // Navigate() should have opened a new normal popup window.
392 EXPECT_NE(p1.browser, p2.browser);
[email protected]b35b26b32011-05-05 20:35:14393 EXPECT_TRUE(p2.browser->is_type_popup());
394 EXPECT_FALSE(p2.browser->is_app());
[email protected]300d1e52011-01-19 23:57:57395
396 // We should have three windows, the browser() provided by the framework,
397 // the first popup window, and the second popup window.
398 EXPECT_EQ(3u, BrowserList::size());
399 EXPECT_EQ(1, browser()->tab_count());
400 EXPECT_EQ(1, p1.browser->tab_count());
401 EXPECT_EQ(1, p2.browser->tab_count());
402}
403
404// This test verifies that navigating with WindowOpenDisposition = NEW_POPUP
[email protected]a1feae52010-10-11 22:14:45405// from an app frame results in a new Browser with TYPE_APP_POPUP.
406IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
407 Disposition_NewPopupFromAppWindow) {
[email protected]b35b26b32011-05-05 20:35:14408 Browser* app_browser = CreateEmptyBrowserForApp(Browser::TYPE_TABBED,
409 browser()->profile());
[email protected]a1feae52010-10-11 22:14:45410 browser::NavigateParams p(MakeNavigateParams(app_browser));
411 p.disposition = NEW_POPUP;
[email protected]588300d2011-04-28 21:06:35412 p.window_bounds = gfx::Rect(0, 0, 200, 200);
[email protected]19d9f3a2010-10-14 21:49:36413 browser::Navigate(&p);
[email protected]a1feae52010-10-11 22:14:45414
415 // Navigate() should have opened a new popup app window.
416 EXPECT_NE(app_browser, p.browser);
417 EXPECT_NE(browser(), p.browser);
[email protected]b35b26b32011-05-05 20:35:14418 EXPECT_TRUE(p.browser->is_type_popup());
419 EXPECT_TRUE(p.browser->is_app());
[email protected]a1feae52010-10-11 22:14:45420
421 // We should now have three windows, the app window, the app popup it created,
422 // and the original browser() provided by the framework.
423 EXPECT_EQ(3u, BrowserList::size());
424 EXPECT_EQ(1, browser()->tab_count());
425 EXPECT_EQ(1, app_browser->tab_count());
426 EXPECT_EQ(1, p.browser->tab_count());
427}
428
429// This test verifies that navigating with WindowOpenDisposition = NEW_POPUP
[email protected]300d1e52011-01-19 23:57:57430// from an app popup results in a new Browser also of TYPE_APP_POPUP.
431IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
432 Disposition_NewPopupFromAppPopup) {
[email protected]b35b26b32011-05-05 20:35:14433 Browser* app_browser = CreateEmptyBrowserForApp(Browser::TYPE_TABBED,
434 browser()->profile());
[email protected]300d1e52011-01-19 23:57:57435 // Open an app popup.
436 browser::NavigateParams p1(MakeNavigateParams(app_browser));
437 p1.disposition = NEW_POPUP;
[email protected]588300d2011-04-28 21:06:35438 p1.window_bounds = gfx::Rect(0, 0, 200, 200);
[email protected]300d1e52011-01-19 23:57:57439 browser::Navigate(&p1);
440 // Now open another app popup.
441 browser::NavigateParams p2(MakeNavigateParams(p1.browser));
442 p2.disposition = NEW_POPUP;
[email protected]588300d2011-04-28 21:06:35443 p2.window_bounds = gfx::Rect(0, 0, 200, 200);
[email protected]300d1e52011-01-19 23:57:57444 browser::Navigate(&p2);
445
446 // Navigate() should have opened a new popup app window.
447 EXPECT_NE(browser(), p1.browser);
448 EXPECT_NE(p1.browser, p2.browser);
[email protected]b35b26b32011-05-05 20:35:14449 EXPECT_TRUE(p2.browser->is_type_popup());
450 EXPECT_TRUE(p2.browser->is_app());
[email protected]300d1e52011-01-19 23:57:57451
452 // We should now have four windows, the app window, the first app popup,
453 // the second app popup, and the original browser() provided by the framework.
454 EXPECT_EQ(4u, BrowserList::size());
455 EXPECT_EQ(1, browser()->tab_count());
456 EXPECT_EQ(1, app_browser->tab_count());
457 EXPECT_EQ(1, p1.browser->tab_count());
458 EXPECT_EQ(1, p2.browser->tab_count());
459}
460
461// This test verifies that navigating with WindowOpenDisposition = NEW_POPUP
[email protected]a1feae52010-10-11 22:14:45462// from an extension app tab results in a new Browser with TYPE_APP_POPUP.
463IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
464 Disposition_NewPopupFromExtensionApp) {
465 // TODO(beng): TBD.
466}
467
[email protected]7d329992011-04-15 18:20:02468// This test verifies that navigating with window_action = SHOW_WINDOW_INACTIVE
469// does not focus a new new popup window.
470IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_NewPopupUnfocused) {
471 browser::NavigateParams p(MakeNavigateParams());
472 p.disposition = NEW_POPUP;
[email protected]588300d2011-04-28 21:06:35473 p.window_bounds = gfx::Rect(0, 0, 200, 200);
[email protected]7d329992011-04-15 18:20:02474 p.window_action = browser::NavigateParams::SHOW_WINDOW_INACTIVE;
[email protected]7d329992011-04-15 18:20:02475 // Wait for new popup to load (and gain focus if the test fails).
[email protected]ddddfda2011-07-14 23:19:39476 ui_test_utils::NavigateToURL(&p);
[email protected]7d329992011-04-15 18:20:02477
478 // Navigate() should have opened a new, unfocused, popup window.
479 EXPECT_NE(browser(), p.browser);
480 EXPECT_EQ(Browser::TYPE_POPUP, p.browser->type());
[email protected]9db263a2011-04-15 20:53:47481#if 0
482// TODO(stevenjb): Enable this test. See: crbug.com/79493
[email protected]7d329992011-04-15 18:20:02483 EXPECT_FALSE(p.browser->window()->IsActive());
[email protected]7d329992011-04-15 18:20:02484#endif
[email protected]9db263a2011-04-15 20:53:47485}
[email protected]7d329992011-04-15 18:20:02486
[email protected]a1feae52010-10-11 22:14:45487// This test verifies that navigating with WindowOpenDisposition = NEW_WINDOW
488// always opens a new window.
489IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_NewWindow) {
490 browser::NavigateParams p(MakeNavigateParams());
491 p.disposition = NEW_WINDOW;
[email protected]19d9f3a2010-10-14 21:49:36492 browser::Navigate(&p);
[email protected]a1feae52010-10-11 22:14:45493
494 // Navigate() should have opened a new toplevel window.
495 EXPECT_NE(browser(), p.browser);
[email protected]b35b26b32011-05-05 20:35:14496 EXPECT_TRUE(p.browser->is_type_tabbed());
[email protected]a1feae52010-10-11 22:14:45497
498 // We should now have two windows, the browser() provided by the framework and
499 // the new normal window.
500 EXPECT_EQ(2u, BrowserList::size());
501 EXPECT_EQ(1, browser()->tab_count());
502 EXPECT_EQ(1, p.browser->tab_count());
503}
504
505// This test verifies that navigating with WindowOpenDisposition = INCOGNITO
506// opens a new incognito window if no existing incognito window is present.
507IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_Incognito) {
508 browser::NavigateParams p(MakeNavigateParams());
509 p.disposition = OFF_THE_RECORD;
[email protected]19d9f3a2010-10-14 21:49:36510 browser::Navigate(&p);
[email protected]a1feae52010-10-11 22:14:45511
512 // Navigate() should have opened a new toplevel incognito window.
513 EXPECT_NE(browser(), p.browser);
514 EXPECT_EQ(browser()->profile()->GetOffTheRecordProfile(),
515 p.browser->profile());
516
[email protected]d7ff3592010-11-30 21:50:46517 // |source_contents| should be set to NULL because the profile for the new
518 // page is different from the originating page.
519 EXPECT_EQ(NULL, p.source_contents);
520
[email protected]a1feae52010-10-11 22:14:45521 // We should now have two windows, the browser() provided by the framework and
522 // the new incognito window.
523 EXPECT_EQ(2u, BrowserList::size());
524 EXPECT_EQ(1, browser()->tab_count());
525 EXPECT_EQ(1, p.browser->tab_count());
526}
527
528// This test verifies that navigating with WindowOpenDisposition = INCOGNITO
529// reuses an existing incognito window when possible.
530IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_IncognitoRefocus) {
531 Browser* incognito_browser =
[email protected]b35b26b32011-05-05 20:35:14532 CreateEmptyBrowserForType(Browser::TYPE_TABBED,
[email protected]a1feae52010-10-11 22:14:45533 browser()->profile()->GetOffTheRecordProfile());
534 browser::NavigateParams p(MakeNavigateParams());
535 p.disposition = OFF_THE_RECORD;
[email protected]19d9f3a2010-10-14 21:49:36536 browser::Navigate(&p);
[email protected]a1feae52010-10-11 22:14:45537
538 // Navigate() should have opened a new tab in the existing incognito window.
539 EXPECT_NE(browser(), p.browser);
540 EXPECT_EQ(p.browser, incognito_browser);
541
542 // We should now have two windows, the browser() provided by the framework and
543 // the incognito window we opened earlier.
544 EXPECT_EQ(2u, BrowserList::size());
545 EXPECT_EQ(1, browser()->tab_count());
546 EXPECT_EQ(2, incognito_browser->tab_count());
547}
548
549// This test verifies that no navigation action occurs when
550// WindowOpenDisposition = SUPPRESS_OPEN.
551IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_SuppressOpen) {
552 RunSuppressTest(SUPPRESS_OPEN);
553}
554
555// This test verifies that no navigation action occurs when
556// WindowOpenDisposition = SAVE_TO_DISK.
557IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_SaveToDisk) {
558 RunSuppressTest(SAVE_TO_DISK);
559}
560
561// This test verifies that no navigation action occurs when
562// WindowOpenDisposition = IGNORE_ACTION.
563IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_IgnoreAction) {
564 RunSuppressTest(IGNORE_ACTION);
565}
566
567// This tests adding a foreground tab with a predefined TabContents.
568IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, TargetContents_ForegroundTab) {
569 browser::NavigateParams p(MakeNavigateParams());
570 p.disposition = NEW_FOREGROUND_TAB;
571 p.target_contents = CreateTabContents();
[email protected]19d9f3a2010-10-14 21:49:36572 browser::Navigate(&p);
[email protected]a1feae52010-10-11 22:14:45573
574 // Navigate() should have opened the contents in a new foreground in the
575 // current Browser.
576 EXPECT_EQ(browser(), p.browser);
[email protected]3c9e1872010-11-18 16:17:49577 EXPECT_EQ(browser()->GetSelectedTabContentsWrapper(), p.target_contents);
[email protected]a1feae52010-10-11 22:14:45578
579 // We should have one window, with two tabs.
580 EXPECT_EQ(1u, BrowserList::size());
581 EXPECT_EQ(2, browser()->tab_count());
582}
583
584#if defined(OS_WIN)
585// This tests adding a popup with a predefined TabContents.
[email protected]76edb672011-03-04 21:48:39586IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, DISABLED_TargetContents_Popup) {
[email protected]a1feae52010-10-11 22:14:45587 browser::NavigateParams p(MakeNavigateParams());
588 p.disposition = NEW_POPUP;
589 p.target_contents = CreateTabContents();
590 p.window_bounds = gfx::Rect(10, 10, 500, 500);
[email protected]19d9f3a2010-10-14 21:49:36591 browser::Navigate(&p);
[email protected]a1feae52010-10-11 22:14:45592
593 // Navigate() should have opened a new popup window.
594 EXPECT_NE(browser(), p.browser);
[email protected]b35b26b32011-05-05 20:35:14595 EXPECT_TRUE(p.browser->is_type_popup());
596 EXPECT_FALSE(p.browser->is_app());
[email protected]a1feae52010-10-11 22:14:45597
598 // The web platform is weird. The window bounds specified in
599 // |p.window_bounds| are used as follows:
600 // - the origin is used to position the window
601 // - the size is used to size the TabContents of the window.
602 // As such the position of the resulting window will always match
603 // p.window_bounds.origin(), but its size will not. We need to match
604 // the size against the selected tab's view's container size.
605 // Only Windows positions the window according to |p.window_bounds.origin()| -
606 // on Mac the window is offset from the opener and on Linux it always opens
607 // at 0,0.
608 EXPECT_EQ(p.window_bounds.origin(),
609 p.browser->window()->GetRestoredBounds().origin());
610 // All platforms should respect size however provided width > 400 (Mac has a
611 // minimum window width of 400).
612 EXPECT_EQ(p.window_bounds.size(),
[email protected]3c9e1872010-11-18 16:17:49613 p.target_contents->tab_contents()->view()->GetContainerSize());
[email protected]a1feae52010-10-11 22:14:45614
615 // We should have two windows, the new popup and the browser() provided by the
616 // framework.
617 EXPECT_EQ(2u, BrowserList::size());
618 EXPECT_EQ(1, browser()->tab_count());
619 EXPECT_EQ(1, p.browser->tab_count());
620}
621#endif
622
623// This tests adding a tab at a specific index.
624IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Tabstrip_InsertAtIndex) {
625 // This is not meant to be a comprehensive test of whether or not the tab
626 // implementation of the browser observes the insertion index. That is
627 // covered by the unit tests for TabStripModel. This merely verifies that
628 // insertion index preference is reflected in common cases.
629 browser::NavigateParams p(MakeNavigateParams());
630 p.disposition = NEW_FOREGROUND_TAB;
631 p.tabstrip_index = 0;
632 p.tabstrip_add_types = TabStripModel::ADD_FORCE_INDEX;
[email protected]19d9f3a2010-10-14 21:49:36633 browser::Navigate(&p);
[email protected]a1feae52010-10-11 22:14:45634
635 // Navigate() should have inserted a new tab at slot 0 in the tabstrip.
636 EXPECT_EQ(browser(), p.browser);
637 EXPECT_EQ(0, browser()->tabstrip_model()->GetIndexOfTabContents(
[email protected]3c9e1872010-11-18 16:17:49638 static_cast<const TabContentsWrapper*>(p.target_contents)));
[email protected]a1feae52010-10-11 22:14:45639
640 // We should have one window - the browser() provided by the framework.
641 EXPECT_EQ(1u, BrowserList::size());
642 EXPECT_EQ(2, browser()->tab_count());
643}
644
[email protected]2dd85482010-11-06 01:56:47645// This test verifies that constructing params with a NULL browser has
646// the same result as navigating to a new foreground tab in the (only)
647// active browser. Tests are the same as for Disposition_NewForegroundTab.
648IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, NullBrowser_NewForegroundTab) {
649 TabContents* old_contents = browser()->GetSelectedTabContents();
650 // Navigate with a NULL browser.
651 browser::NavigateParams p(MakeNavigateParams(NULL));
652 p.disposition = NEW_FOREGROUND_TAB;
653 p.profile = browser()->profile();
654 browser::Navigate(&p);
655
656 // Navigate() should have found browser() and create a new tab.
657 EXPECT_EQ(browser(), p.browser);
658 EXPECT_NE(old_contents, browser()->GetSelectedTabContents());
[email protected]3c9e1872010-11-18 16:17:49659 EXPECT_EQ(browser()->GetSelectedTabContentsWrapper(), p.target_contents);
[email protected]2dd85482010-11-06 01:56:47660 EXPECT_EQ(2, browser()->tab_count());
661}
662
663// This test verifies that constructing params with a NULL browser and
664// a specific profile matches the specified profile.
[email protected]c8a31a72011-09-30 01:53:32665IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, NullBrowser_MatchProfile) {
[email protected]2dd85482010-11-06 01:56:47666 // Create a new browser with using the incognito profile.
667 Browser* incognito =
668 Browser::Create(browser()->profile()->GetOffTheRecordProfile());
669
670 // Navigate with a NULL browser and the incognito profile.
671 browser::NavigateParams p(MakeNavigateParams(NULL));
672 p.disposition = NEW_FOREGROUND_TAB;
673 p.profile = incognito->profile();
674 browser::Navigate(&p);
675
676 // Navigate() should have found incognito, not browser().
677 EXPECT_EQ(incognito, p.browser);
[email protected]3c9e1872010-11-18 16:17:49678 EXPECT_EQ(incognito->GetSelectedTabContentsWrapper(), p.target_contents);
[email protected]2dd85482010-11-06 01:56:47679 EXPECT_EQ(1, incognito->tab_count());
680}
681
682// This test verifies that constructing params with a NULL browser and
683// disposition = NEW_WINDOW always opens exactly one new window.
684IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, NullBrowser_NewWindow) {
685 browser::NavigateParams p(MakeNavigateParams(NULL));
686 p.disposition = NEW_WINDOW;
687 p.profile = browser()->profile();
688 browser::Navigate(&p);
689
690 // Navigate() should have created a new browser.
691 EXPECT_NE(browser(), p.browser);
[email protected]b35b26b32011-05-05 20:35:14692 EXPECT_TRUE( p.browser->is_type_tabbed());
[email protected]2dd85482010-11-06 01:56:47693
694 // We should now have two windows, the browser() provided by the framework and
695 // the new normal window.
696 EXPECT_EQ(2u, BrowserList::size());
697 EXPECT_EQ(1, browser()->tab_count());
698 EXPECT_EQ(1, p.browser->tab_count());
699}
700
[email protected]bb89e7482010-11-17 18:27:04701// This test verifies that constructing params with disposition = SINGLETON_TAB
[email protected]fee320542011-03-02 01:30:49702// and IGNORE_AND_NAVIGATE opens a new tab navigated to the specified URL if
[email protected]67ed83e2011-01-07 22:54:00703// no previous tab with that URL (minus the path) exists.
[email protected]bb89e7482010-11-17 18:27:04704IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
705 Disposition_SingletonTabNew_IgnorePath) {
[email protected]2905f742011-10-13 03:51:58706 browser()->AddSelectedTabWithURL(
707 GetGoogleURL(), content::PAGE_TRANSITION_LINK);
[email protected]bb89e7482010-11-17 18:27:04708
709 // We should have one browser with 2 tabs, the 2nd selected.
710 EXPECT_EQ(1u, BrowserList::size());
711 EXPECT_EQ(2, browser()->tab_count());
[email protected]1ea49d52011-04-12 17:44:44712 EXPECT_EQ(1, browser()->active_index());
[email protected]bb89e7482010-11-17 18:27:04713
714 // Navigate to a new singleton tab with a sub-page.
715 browser::NavigateParams p(MakeNavigateParams());
716 p.disposition = SINGLETON_TAB;
[email protected]ddddfda2011-07-14 23:19:39717 p.url = GetSettingsAdvancedURL();
[email protected]7d329992011-04-15 18:20:02718 p.window_action = browser::NavigateParams::SHOW_WINDOW;
[email protected]fee320542011-03-02 01:30:49719 p.path_behavior = browser::NavigateParams::IGNORE_AND_NAVIGATE;
[email protected]bb89e7482010-11-17 18:27:04720 browser::Navigate(&p);
721
722 // The last tab should now be selected and navigated to the sub-page of the
723 // URL.
724 EXPECT_EQ(browser(), p.browser);
725 EXPECT_EQ(3, browser()->tab_count());
[email protected]1ea49d52011-04-12 17:44:44726 EXPECT_EQ(2, browser()->active_index());
[email protected]ddddfda2011-07-14 23:19:39727 EXPECT_EQ(GetSettingsAdvancedURL(),
[email protected]bb89e7482010-11-17 18:27:04728 browser()->GetSelectedTabContents()->GetURL());
729}
730
731// This test verifies that constructing params with disposition = SINGLETON_TAB
[email protected]fee320542011-03-02 01:30:49732// and IGNORE_AND_NAVIGATE opens an existing tab with the matching URL (minus
[email protected]bb89e7482010-11-17 18:27:04733// the path) which is navigated to the specified URL.
734IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
735 Disposition_SingletonTabExisting_IgnorePath) {
[email protected]ddddfda2011-07-14 23:19:39736 GURL singleton_url1(GetSettingsURL());
[email protected]2905f742011-10-13 03:51:58737 browser()->AddSelectedTabWithURL(
738 singleton_url1, content::PAGE_TRANSITION_LINK);
739 browser()->AddSelectedTabWithURL(
740 GetGoogleURL(), content::PAGE_TRANSITION_LINK);
[email protected]bb89e7482010-11-17 18:27:04741
742 // We should have one browser with 3 tabs, the 3rd selected.
743 EXPECT_EQ(1u, BrowserList::size());
744 EXPECT_EQ(3, browser()->tab_count());
[email protected]1ea49d52011-04-12 17:44:44745 EXPECT_EQ(2, browser()->active_index());
[email protected]bb89e7482010-11-17 18:27:04746
747 // Navigate to singleton_url1.
748 browser::NavigateParams p(MakeNavigateParams());
749 p.disposition = SINGLETON_TAB;
[email protected]ddddfda2011-07-14 23:19:39750 p.url = GetSettingsAdvancedURL();
[email protected]7d329992011-04-15 18:20:02751 p.window_action = browser::NavigateParams::SHOW_WINDOW;
[email protected]fee320542011-03-02 01:30:49752 p.path_behavior = browser::NavigateParams::IGNORE_AND_NAVIGATE;
[email protected]bb89e7482010-11-17 18:27:04753 browser::Navigate(&p);
754
755 // The middle tab should now be selected and navigated to the sub-page of the
756 // URL.
757 EXPECT_EQ(browser(), p.browser);
758 EXPECT_EQ(3, browser()->tab_count());
[email protected]1ea49d52011-04-12 17:44:44759 EXPECT_EQ(1, browser()->active_index());
[email protected]ddddfda2011-07-14 23:19:39760 EXPECT_EQ(GetSettingsAdvancedURL(),
[email protected]bb89e7482010-11-17 18:27:04761 browser()->GetSelectedTabContents()->GetURL());
762}
763
764// This test verifies that constructing params with disposition = SINGLETON_TAB
[email protected]fee320542011-03-02 01:30:49765// and IGNORE_AND_NAVIGATE opens an existing tab with the matching URL (minus
[email protected]bb89e7482010-11-17 18:27:04766// the path) which is navigated to the specified URL.
767IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
768 Disposition_SingletonTabExistingSubPath_IgnorePath) {
[email protected]ddddfda2011-07-14 23:19:39769 GURL singleton_url1(GetSettingsAdvancedURL());
[email protected]2905f742011-10-13 03:51:58770 browser()->AddSelectedTabWithURL(
771 singleton_url1, content::PAGE_TRANSITION_LINK);
772 browser()->AddSelectedTabWithURL(
773 GetGoogleURL(), content::PAGE_TRANSITION_LINK);
[email protected]bb89e7482010-11-17 18:27:04774
775 // We should have one browser with 3 tabs, the 3rd selected.
776 EXPECT_EQ(1u, BrowserList::size());
777 EXPECT_EQ(3, browser()->tab_count());
[email protected]1ea49d52011-04-12 17:44:44778 EXPECT_EQ(2, browser()->active_index());
[email protected]bb89e7482010-11-17 18:27:04779
780 // Navigate to singleton_url1.
781 browser::NavigateParams p(MakeNavigateParams());
782 p.disposition = SINGLETON_TAB;
[email protected]ddddfda2011-07-14 23:19:39783 p.url = GetSettingsPersonalURL();
[email protected]7d329992011-04-15 18:20:02784 p.window_action = browser::NavigateParams::SHOW_WINDOW;
[email protected]fee320542011-03-02 01:30:49785 p.path_behavior = browser::NavigateParams::IGNORE_AND_NAVIGATE;
[email protected]bb89e7482010-11-17 18:27:04786 browser::Navigate(&p);
787
788 // The middle tab should now be selected and navigated to the sub-page of the
789 // URL.
790 EXPECT_EQ(browser(), p.browser);
791 EXPECT_EQ(3, browser()->tab_count());
[email protected]1ea49d52011-04-12 17:44:44792 EXPECT_EQ(1, browser()->active_index());
[email protected]ddddfda2011-07-14 23:19:39793 EXPECT_EQ(GetSettingsPersonalURL(),
[email protected]bb89e7482010-11-17 18:27:04794 browser()->GetSelectedTabContents()->GetURL());
795}
[email protected]2dd85482010-11-06 01:56:47796
[email protected]637b3442011-01-10 23:31:48797// This test verifies that constructing params with disposition = SINGLETON_TAB
[email protected]fee320542011-03-02 01:30:49798// and IGNORE_AND_STAY_PUT opens an existing tab with the matching URL (minus
799// the path).
800IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
801 Disposition_SingletonTabExistingSubPath_IgnorePath2) {
[email protected]ddddfda2011-07-14 23:19:39802 GURL singleton_url1(GetSettingsAdvancedURL());
[email protected]2905f742011-10-13 03:51:58803 browser()->AddSelectedTabWithURL(
804 singleton_url1, content::PAGE_TRANSITION_LINK);
805 browser()->AddSelectedTabWithURL(
806 GetGoogleURL(), content::PAGE_TRANSITION_LINK);
[email protected]fee320542011-03-02 01:30:49807
808 // We should have one browser with 3 tabs, the 3rd selected.
809 EXPECT_EQ(1u, BrowserList::size());
810 EXPECT_EQ(3, browser()->tab_count());
[email protected]1ea49d52011-04-12 17:44:44811 EXPECT_EQ(2, browser()->active_index());
[email protected]fee320542011-03-02 01:30:49812
813 // Navigate to singleton_url1.
814 browser::NavigateParams p(MakeNavigateParams());
815 p.disposition = SINGLETON_TAB;
[email protected]ddddfda2011-07-14 23:19:39816 p.url = GetSettingsPersonalURL();
[email protected]7d329992011-04-15 18:20:02817 p.window_action = browser::NavigateParams::SHOW_WINDOW;
[email protected]fee320542011-03-02 01:30:49818 p.path_behavior = browser::NavigateParams::IGNORE_AND_STAY_PUT;
819 browser::Navigate(&p);
820
821 // The middle tab should now be selected.
822 EXPECT_EQ(browser(), p.browser);
823 EXPECT_EQ(3, browser()->tab_count());
[email protected]1ea49d52011-04-12 17:44:44824 EXPECT_EQ(1, browser()->active_index());
[email protected]fee320542011-03-02 01:30:49825 EXPECT_EQ(singleton_url1,
826 browser()->GetSelectedTabContents()->GetURL());
827}
828
829// This test verifies that constructing params with disposition = SINGLETON_TAB
830// and IGNORE_AND_NAVIGATE will update the current tab's URL if the currently
[email protected]637b3442011-01-10 23:31:48831// selected tab is a match but has a different path.
832IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
833 Disposition_SingletonTabFocused_IgnorePath) {
[email protected]ddddfda2011-07-14 23:19:39834 GURL singleton_url_current(GetSettingsAdvancedURL());
[email protected]2905f742011-10-13 03:51:58835 browser()->AddSelectedTabWithURL(
836 singleton_url_current, content::PAGE_TRANSITION_LINK);
[email protected]637b3442011-01-10 23:31:48837
838 // We should have one browser with 2 tabs, the 2nd selected.
839 EXPECT_EQ(1u, BrowserList::size());
840 EXPECT_EQ(2, browser()->tab_count());
[email protected]1ea49d52011-04-12 17:44:44841 EXPECT_EQ(1, browser()->active_index());
[email protected]637b3442011-01-10 23:31:48842
843 // Navigate to a different settings path.
[email protected]ddddfda2011-07-14 23:19:39844 GURL singleton_url_target(GetSettingsPersonalURL());
[email protected]637b3442011-01-10 23:31:48845 browser::NavigateParams p(MakeNavigateParams());
846 p.disposition = SINGLETON_TAB;
847 p.url = singleton_url_target;
[email protected]7d329992011-04-15 18:20:02848 p.window_action = browser::NavigateParams::SHOW_WINDOW;
[email protected]fee320542011-03-02 01:30:49849 p.path_behavior = browser::NavigateParams::IGNORE_AND_NAVIGATE;
[email protected]637b3442011-01-10 23:31:48850 browser::Navigate(&p);
851
852 // The second tab should still be selected, but navigated to the new path.
853 EXPECT_EQ(browser(), p.browser);
854 EXPECT_EQ(2, browser()->tab_count());
[email protected]1ea49d52011-04-12 17:44:44855 EXPECT_EQ(1, browser()->active_index());
[email protected]637b3442011-01-10 23:31:48856 EXPECT_EQ(singleton_url_target,
857 browser()->GetSelectedTabContents()->GetURL());
858}
859
[email protected]07afd7c2011-02-17 10:07:11860// This test verifies that constructing params with disposition = SINGLETON_TAB
[email protected]fee320542011-03-02 01:30:49861// and IGNORE_AND_NAVIGATE will open an existing matching tab with a different
862// query.
[email protected]07afd7c2011-02-17 10:07:11863IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
864 Disposition_SingletonTabExisting_IgnoreQuery) {
865 int initial_tab_count = browser()->tab_count();
866 GURL singleton_url_current("chrome://settings/internet");
[email protected]2905f742011-10-13 03:51:58867 browser()->AddSelectedTabWithURL(
868 singleton_url_current, content::PAGE_TRANSITION_LINK);
[email protected]07afd7c2011-02-17 10:07:11869
870 EXPECT_EQ(initial_tab_count + 1, browser()->tab_count());
[email protected]1ea49d52011-04-12 17:44:44871 EXPECT_EQ(initial_tab_count, browser()->active_index());
[email protected]07afd7c2011-02-17 10:07:11872
873 // Navigate to a different settings path.
874 GURL singleton_url_target(
875 "chrome://settings/internet?"
876 "servicePath=/profile/ethernet_00aa00aa00aa&networkType=1");
877 browser::NavigateParams p(MakeNavigateParams());
878 p.disposition = SINGLETON_TAB;
879 p.url = singleton_url_target;
[email protected]7d329992011-04-15 18:20:02880 p.window_action = browser::NavigateParams::SHOW_WINDOW;
[email protected]fee320542011-03-02 01:30:49881 p.path_behavior = browser::NavigateParams::IGNORE_AND_NAVIGATE;
[email protected]07afd7c2011-02-17 10:07:11882 browser::Navigate(&p);
883
884 // Last tab should still be selected.
885 EXPECT_EQ(browser(), p.browser);
886 EXPECT_EQ(initial_tab_count + 1, browser()->tab_count());
[email protected]1ea49d52011-04-12 17:44:44887 EXPECT_EQ(initial_tab_count, browser()->active_index());
[email protected]07afd7c2011-02-17 10:07:11888}
889
[email protected]bd817c22011-02-09 08:16:46890// This test verifies that the settings page isn't opened in the incognito
891// window.
892IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
893 Disposition_Settings_UseNonIncognitoWindow) {
894 Browser* incognito_browser = CreateIncognitoBrowser();
895
896 EXPECT_EQ(2u, BrowserList::size());
897 EXPECT_EQ(1, browser()->tab_count());
898 EXPECT_EQ(1, incognito_browser->tab_count());
899
900 // Navigate to the settings page.
901 browser::NavigateParams p(MakeNavigateParams(incognito_browser));
902 p.disposition = SINGLETON_TAB;
[email protected]ddddfda2011-07-14 23:19:39903 p.url = GetSettingsURL();
[email protected]7d329992011-04-15 18:20:02904 p.window_action = browser::NavigateParams::SHOW_WINDOW;
[email protected]bd817c22011-02-09 08:16:46905 browser::Navigate(&p);
906
907 // The settings page should be opened in browser() window.
908 EXPECT_NE(incognito_browser, p.browser);
909 EXPECT_EQ(browser(), p.browser);
910 EXPECT_EQ(2, browser()->tab_count());
[email protected]ddddfda2011-07-14 23:19:39911 EXPECT_EQ(GetSettingsURL(),
[email protected]bd817c22011-02-09 08:16:46912 browser()->GetSelectedTabContents()->GetURL());
913}
914
[email protected]82404cd2011-07-12 19:55:14915// This test verifies that the settings page isn't opened in the incognito
916// window from a non-incognito window (bookmark open-in-incognito trigger).
917IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
918 Disposition_Settings_UseNonIncognitoWindowForBookmark) {
919 browser::NavigateParams params(browser(), GURL("chrome://settings"),
[email protected]2905f742011-10-13 03:51:58920 content::PAGE_TRANSITION_AUTO_BOOKMARK);
[email protected]82404cd2011-07-12 19:55:14921 params.disposition = OFF_THE_RECORD;
922 {
923 ui_test_utils::WindowedNotificationObserver observer(
924 content::NOTIFICATION_LOAD_STOP, NotificationService::AllSources());
925 browser::Navigate(&params);
926 observer.Wait();
927 }
928
929 EXPECT_EQ(1u, BrowserList::size());
930 EXPECT_EQ(GURL("chrome://settings"),
931 browser()->GetSelectedTabContents()->GetURL().GetOrigin());
932}
933
[email protected]bd817c22011-02-09 08:16:46934// This test verifies that the bookmarks page isn't opened in the incognito
935// window.
936IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
937 Disposition_Bookmarks_UseNonIncognitoWindow) {
938 Browser* incognito_browser = CreateIncognitoBrowser();
939
940 EXPECT_EQ(2u, BrowserList::size());
941 EXPECT_EQ(1, browser()->tab_count());
942 EXPECT_EQ(1, incognito_browser->tab_count());
943
944 // Navigate to the settings page.
945 browser::NavigateParams p(MakeNavigateParams(incognito_browser));
946 p.disposition = SINGLETON_TAB;
[email protected]ddddfda2011-07-14 23:19:39947 p.url = GURL(chrome::kChromeUIBookmarksURL);
[email protected]7d329992011-04-15 18:20:02948 p.window_action = browser::NavigateParams::SHOW_WINDOW;
[email protected]bd817c22011-02-09 08:16:46949 browser::Navigate(&p);
950
951 // The bookmarks page should be opened in browser() window.
952 EXPECT_NE(incognito_browser, p.browser);
953 EXPECT_EQ(browser(), p.browser);
954 EXPECT_EQ(2, browser()->tab_count());
[email protected]ddddfda2011-07-14 23:19:39955 EXPECT_EQ(GURL(chrome::kChromeUIBookmarksURL),
[email protected]bd817c22011-02-09 08:16:46956 browser()->GetSelectedTabContents()->GetURL());
957}
958
[email protected]7de53c62011-05-13 06:44:16959// This test makes sure a crashed singleton tab reloads from a new navigation.
960IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
961 NavigateToCrashedSingletonTab) {
[email protected]ddddfda2011-07-14 23:19:39962 GURL singleton_url(GetSettingsAdvancedURL());
[email protected]2905f742011-10-13 03:51:58963 TabContentsWrapper* wrapper = browser()->AddSelectedTabWithURL(
964 singleton_url, content::PAGE_TRANSITION_LINK);
[email protected]7de53c62011-05-13 06:44:16965 TabContents* tab_contents = wrapper->tab_contents();
966
967 // We should have one browser with 2 tabs, the 2nd selected.
968 EXPECT_EQ(1u, BrowserList::size());
969 EXPECT_EQ(2, browser()->tab_count());
970 EXPECT_EQ(1, browser()->active_index());
971
972 // Kill the singleton tab.
973 tab_contents->SetIsCrashed(base::TERMINATION_STATUS_PROCESS_CRASHED, -1);
974 EXPECT_TRUE(tab_contents->is_crashed());
975
976 browser::NavigateParams p(MakeNavigateParams());
977 p.disposition = SINGLETON_TAB;
978 p.url = singleton_url;
979 p.window_action = browser::NavigateParams::SHOW_WINDOW;
980 p.path_behavior = browser::NavigateParams::IGNORE_AND_NAVIGATE;
[email protected]ddddfda2011-07-14 23:19:39981 ui_test_utils::NavigateToURL(&p);
[email protected]7de53c62011-05-13 06:44:16982
983 // The tab should not be sad anymore.
984 EXPECT_FALSE(tab_contents->is_crashed());
985}
986
[email protected]fcca741b2011-06-17 22:46:37987IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
988 NavigateFromDefaultToOptionsInSameTab) {
[email protected]ddddfda2011-07-14 23:19:39989 {
990 ui_test_utils::WindowedNotificationObserver observer(
991 content::NOTIFICATION_LOAD_STOP, NotificationService::AllSources());
992 browser()->OpenOptionsDialog();
993 observer.Wait();
994 }
[email protected]fcca741b2011-06-17 22:46:37995 EXPECT_EQ(1, browser()->tab_count());
[email protected]ddddfda2011-07-14 23:19:39996 EXPECT_EQ(GetSettingsURL(),
997 browser()->GetSelectedTabContents()->GetURL().GetOrigin());
[email protected]fcca741b2011-06-17 22:46:37998}
999
1000IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
1001 NavigateFromBlankToOptionsInSameTab) {
1002 browser::NavigateParams p(MakeNavigateParams());
[email protected]ddddfda2011-07-14 23:19:391003 p.url = GURL(chrome::kAboutBlankURL);
1004 ui_test_utils::NavigateToURL(&p);
[email protected]fcca741b2011-06-17 22:46:371005
[email protected]ddddfda2011-07-14 23:19:391006 {
1007 ui_test_utils::WindowedNotificationObserver observer(
1008 content::NOTIFICATION_LOAD_STOP, NotificationService::AllSources());
1009 browser()->OpenOptionsDialog();
1010 observer.Wait();
1011 }
[email protected]fcca741b2011-06-17 22:46:371012 EXPECT_EQ(1, browser()->tab_count());
[email protected]ddddfda2011-07-14 23:19:391013 EXPECT_EQ(GetSettingsURL(),
1014 browser()->GetSelectedTabContents()->GetURL().GetOrigin());
[email protected]fcca741b2011-06-17 22:46:371015}
1016
1017IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
1018 NavigateFromNTPToOptionsInSameTab) {
1019 browser::NavigateParams p(MakeNavigateParams());
[email protected]ddddfda2011-07-14 23:19:391020 p.url = GURL(chrome::kChromeUINewTabURL);
1021 ui_test_utils::NavigateToURL(&p);
[email protected]fcca741b2011-06-17 22:46:371022 EXPECT_EQ(1, browser()->tab_count());
[email protected]ddddfda2011-07-14 23:19:391023 EXPECT_EQ(GURL(chrome::kChromeUINewTabURL),
[email protected]fcca741b2011-06-17 22:46:371024 browser()->GetSelectedTabContents()->GetURL());
1025
[email protected]ddddfda2011-07-14 23:19:391026 {
1027 ui_test_utils::WindowedNotificationObserver observer(
1028 content::NOTIFICATION_LOAD_STOP, NotificationService::AllSources());
1029 browser()->OpenOptionsDialog();
1030 observer.Wait();
1031 }
[email protected]fcca741b2011-06-17 22:46:371032 EXPECT_EQ(1, browser()->tab_count());
[email protected]ddddfda2011-07-14 23:19:391033 EXPECT_EQ(GetSettingsURL(),
1034 browser()->GetSelectedTabContents()->GetURL().GetOrigin());
[email protected]fcca741b2011-06-17 22:46:371035}
1036
1037IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
1038 NavigateFromPageToOptionsInNewTab) {
1039 browser::NavigateParams p(MakeNavigateParams());
[email protected]ddddfda2011-07-14 23:19:391040 ui_test_utils::NavigateToURL(&p);
[email protected]fcca741b2011-06-17 22:46:371041 EXPECT_EQ(GetGoogleURL(), browser()->GetSelectedTabContents()->GetURL());
1042 EXPECT_EQ(1u, BrowserList::size());
1043 EXPECT_EQ(1, browser()->tab_count());
1044
[email protected]ddddfda2011-07-14 23:19:391045 {
1046 ui_test_utils::WindowedNotificationObserver observer(
1047 content::NOTIFICATION_LOAD_STOP, NotificationService::AllSources());
1048 browser()->OpenOptionsDialog();
1049 observer.Wait();
1050 }
[email protected]fcca741b2011-06-17 22:46:371051 EXPECT_EQ(2, browser()->tab_count());
[email protected]ddddfda2011-07-14 23:19:391052 EXPECT_EQ(GetSettingsURL(),
1053 browser()->GetSelectedTabContents()->GetURL().GetOrigin());
[email protected]fcca741b2011-06-17 22:46:371054}
1055
1056IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
1057 NavigateFromNTPToOptionsSingleton) {
[email protected]ddddfda2011-07-14 23:19:391058 {
1059 ui_test_utils::WindowedNotificationObserver observer(
1060 content::NOTIFICATION_LOAD_STOP, NotificationService::AllSources());
1061 browser()->OpenOptionsDialog();
1062 observer.Wait();
1063 }
[email protected]fcca741b2011-06-17 22:46:371064 EXPECT_EQ(1, browser()->tab_count());
1065
1066 browser()->NewTab();
1067 EXPECT_EQ(2, browser()->tab_count());
1068
[email protected]ddddfda2011-07-14 23:19:391069 {
1070 ui_test_utils::WindowedNotificationObserver observer(
1071 content::NOTIFICATION_LOAD_STOP, NotificationService::AllSources());
1072 browser()->OpenOptionsDialog();
1073 observer.Wait();
1074 }
[email protected]fcca741b2011-06-17 22:46:371075 EXPECT_EQ(2, browser()->tab_count());
[email protected]ddddfda2011-07-14 23:19:391076 EXPECT_EQ(GetSettingsURL(),
1077 browser()->GetSelectedTabContents()->GetURL().GetOrigin());
[email protected]fcca741b2011-06-17 22:46:371078}
1079
1080IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
1081 NavigateFromNTPToOptionsPageInSameTab) {
[email protected]ddddfda2011-07-14 23:19:391082 {
1083 ui_test_utils::WindowedNotificationObserver observer(
1084 content::NOTIFICATION_LOAD_STOP, NotificationService::AllSources());
1085 browser()->ShowOptionsTab(chrome::kPersonalOptionsSubPage);
1086 observer.Wait();
1087 }
[email protected]fcca741b2011-06-17 22:46:371088 EXPECT_EQ(1, browser()->tab_count());
[email protected]ddddfda2011-07-14 23:19:391089 EXPECT_EQ(GetSettingsPersonalURL(),
[email protected]fcca741b2011-06-17 22:46:371090 browser()->GetSelectedTabContents()->GetURL());
1091
1092 browser()->NewTab();
1093 EXPECT_EQ(2, browser()->tab_count());
1094
[email protected]ddddfda2011-07-14 23:19:391095 {
1096 ui_test_utils::WindowedNotificationObserver observer(
1097 content::NOTIFICATION_LOAD_STOP, NotificationService::AllSources());
1098 browser()->ShowOptionsTab(chrome::kPersonalOptionsSubPage);
1099 observer.Wait();
1100 }
[email protected]fcca741b2011-06-17 22:46:371101 EXPECT_EQ(2, browser()->tab_count());
[email protected]ddddfda2011-07-14 23:19:391102 EXPECT_EQ(GetSettingsPersonalURL(),
[email protected]fcca741b2011-06-17 22:46:371103 browser()->GetSelectedTabContents()->GetURL());
1104}
1105
1106IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
1107 NavigateFromOtherTabToSingletonOptions) {
[email protected]ddddfda2011-07-14 23:19:391108 {
1109 ui_test_utils::WindowedNotificationObserver observer(
1110 content::NOTIFICATION_LOAD_STOP, NotificationService::AllSources());
1111 browser()->OpenOptionsDialog();
1112 observer.Wait();
1113 }
1114 {
1115 ui_test_utils::WindowedNotificationObserver observer(
1116 content::NOTIFICATION_LOAD_STOP, NotificationService::AllSources());
[email protected]2905f742011-10-13 03:51:581117 browser()->AddSelectedTabWithURL(
1118 GetGoogleURL(), content::PAGE_TRANSITION_LINK);
[email protected]ddddfda2011-07-14 23:19:391119 observer.Wait();
1120 }
[email protected]fcca741b2011-06-17 22:46:371121
[email protected]ddddfda2011-07-14 23:19:391122 {
1123 ui_test_utils::WindowedNotificationObserver observer(
1124 content::NOTIFICATION_LOAD_STOP, NotificationService::AllSources());
1125 browser()->OpenOptionsDialog();
1126 observer.Wait();
1127 }
[email protected]fcca741b2011-06-17 22:46:371128 EXPECT_EQ(2, browser()->tab_count());
[email protected]ddddfda2011-07-14 23:19:391129 EXPECT_EQ(GetSettingsURL(),
1130 browser()->GetSelectedTabContents()->GetURL().GetOrigin());
[email protected]fcca741b2011-06-17 22:46:371131}
1132
[email protected]26c53e662011-07-09 02:21:021133// Tests that when a new tab is opened from the omnibox, the focus is moved from
1134// the omnibox for the current tab.
1135IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
1136 NavigateFromOmniboxIntoNewTab) {
1137 GURL url("http://www.google.com/");
1138 GURL url2("http://maps.google.com/");
1139
1140 // Navigate to url.
1141 browser::NavigateParams p(MakeNavigateParams());
1142 p.disposition = CURRENT_TAB;
1143 p.url = url;
1144 browser::Navigate(&p);
1145
1146 // Focus the omnibox.
1147 browser()->FocusLocationBar();
1148
1149 AutocompleteEditController* controller =
1150 browser()->window()->GetLocationBar()->location_entry()->model()->
1151 controller();
1152
1153 // Simulate an alt-enter.
1154 controller->OnAutocompleteAccept(url2, NEW_FOREGROUND_TAB,
[email protected]2905f742011-10-13 03:51:581155 content::PAGE_TRANSITION_TYPED, GURL());
[email protected]26c53e662011-07-09 02:21:021156
1157 // Make sure the second tab is selected.
1158 EXPECT_EQ(1, browser()->active_index());
1159
1160 // The tab contents should have the focus in the second tab.
1161 EXPECT_TRUE(ui_test_utils::IsViewFocused(browser(),
1162 VIEW_ID_TAB_CONTAINER_FOCUS_VIEW));
1163
1164 // Go back to the first tab. The focus should not be in the omnibox.
1165 browser()->SelectPreviousTab();
1166 EXPECT_EQ(0, browser()->active_index());
1167 EXPECT_FALSE(ui_test_utils::IsViewFocused(browser(),
1168 VIEW_ID_LOCATION_BAR));
1169}
1170
[email protected]ddddfda2011-07-14 23:19:391171IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
1172 NavigateFromDefaultToHistoryInSameTab) {
1173 {
1174 ui_test_utils::WindowedNotificationObserver observer(
1175 content::NOTIFICATION_LOAD_STOP, NotificationService::AllSources());
1176 browser()->ShowHistoryTab();
1177 observer.Wait();
1178 }
1179 EXPECT_EQ(1, browser()->tab_count());
1180 EXPECT_EQ(GURL(chrome::kChromeUIHistoryURL),
1181 browser()->GetSelectedTabContents()->GetURL());
1182}
1183
1184IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
1185 NavigateFromDefaultToBookmarksInSameTab) {
1186 {
1187 ui_test_utils::WindowedNotificationObserver observer(
1188 content::NOTIFICATION_LOAD_STOP, NotificationService::AllSources());
[email protected]0af8f132011-07-16 01:37:021189 browser()->OpenBookmarkManager();
[email protected]ddddfda2011-07-14 23:19:391190 observer.Wait();
1191 }
1192 EXPECT_EQ(1, browser()->tab_count());
1193 EXPECT_EQ(GURL(chrome::kChromeUIBookmarksURL),
1194 browser()->GetSelectedTabContents()->GetURL());
1195}
1196
1197IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
1198 NavigateFromDefaultToDownloadsInSameTab) {
1199 {
1200 ui_test_utils::WindowedNotificationObserver observer(
1201 content::NOTIFICATION_LOAD_STOP, NotificationService::AllSources());
1202 browser()->ShowDownloadsTab();
1203 observer.Wait();
1204 }
1205 EXPECT_EQ(1, browser()->tab_count());
1206 EXPECT_EQ(GURL(chrome::kChromeUIDownloadsURL),
1207 browser()->GetSelectedTabContents()->GetURL());
1208}
1209
1210} // namespace