blob: d85f2a6bdc4d5403980470f2c8e05828b216c6b5 [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]93ad8e1c2011-11-08 21:34:0510#include "chrome/browser/prefs/incognito_mode_prefs.h"
11#include "chrome/browser/prefs/pref_service.h"
[email protected]8ecad5e2010-12-02 21:18:3312#include "chrome/browser/profiles/profile.h"
[email protected]a1feae52010-10-11 22:14:4513#include "chrome/browser/tabs/tab_strip_model.h"
[email protected]bb89e7482010-11-17 18:27:0414#include "chrome/browser/ui/browser_list.h"
[email protected]339d6dd2010-11-12 00:41:5815#include "chrome/browser/ui/browser_navigator.h"
[email protected]bb89e7482010-11-17 18:27:0416#include "chrome/browser/ui/browser_window.h"
[email protected]26c53e662011-07-09 02:21:0217#include "chrome/browser/ui/omnibox/location_bar.h"
18#include "chrome/browser/ui/omnibox/omnibox_view.h"
[email protected]6a3ec2312010-12-02 19:30:1919#include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h"
[email protected]bb89e7482010-11-17 18:27:0420#include "chrome/common/chrome_switches.h"
[email protected]93ad8e1c2011-11-08 21:34:0521#include "chrome/common/pref_names.h"
[email protected]ddddfda2011-07-14 23:19:3922#include "chrome/common/url_constants.h"
[email protected]af44e7fb2011-07-29 18:32:3223#include "chrome/test/base/ui_test_utils.h"
[email protected]299425b2011-03-02 07:45:2024#include "content/browser/tab_contents/tab_contents.h"
[email protected]ddddfda2011-07-14 23:19:3925#include "content/browser/tab_contents/tab_contents_view.h"
[email protected]ad50def52011-10-19 23:17:0726#include "content/public/browser/notification_service.h"
[email protected]0d6e9bd2011-10-18 04:29:1627#include "content/public/browser/notification_types.h"
[email protected]a1feae52010-10-11 22:14:4528
[email protected]ddddfda2011-07-14 23:19:3929namespace {
30
31GURL GetGoogleURL() {
[email protected]bd817c22011-02-09 08:16:4632 return GURL("http://www.google.com/");
33}
[email protected]a1feae52010-10-11 22:14:4534
[email protected]ddddfda2011-07-14 23:19:3935GURL GetSettingsURL() {
36 return GURL(chrome::kChromeUISettingsURL);
37}
38
39GURL GetSettingsAdvancedURL() {
40 return GURL(chrome::kChromeUISettingsURL).Resolve(
41 chrome::kAdvancedOptionsSubPage);
42}
43
44GURL GetSettingsBrowserURL() {
45 return GURL(chrome::kChromeUISettingsURL).Resolve(
46 chrome::kBrowserOptionsSubPage);
47}
48
49GURL GetSettingsPersonalURL() {
50 return GURL(chrome::kChromeUISettingsURL).Resolve(
51 chrome::kPersonalOptionsSubPage);
52}
53
54} // namespace
55
56
[email protected]bd817c22011-02-09 08:16:4657browser::NavigateParams BrowserNavigatorTest::MakeNavigateParams() const {
58 return MakeNavigateParams(browser());
59}
[email protected]a1feae52010-10-11 22:14:4560
[email protected]bd817c22011-02-09 08:16:4661browser::NavigateParams BrowserNavigatorTest::MakeNavigateParams(
62 Browser* browser) const {
63 browser::NavigateParams params(browser, GetGoogleURL(),
[email protected]2905f742011-10-13 03:51:5864 content::PAGE_TRANSITION_LINK);
[email protected]7d329992011-04-15 18:20:0265 params.window_action = browser::NavigateParams::SHOW_WINDOW;
[email protected]bd817c22011-02-09 08:16:4666 return params;
67}
[email protected]a1feae52010-10-11 22:14:4568
[email protected]bd817c22011-02-09 08:16:4669Browser* BrowserNavigatorTest::CreateEmptyBrowserForType(Browser::Type type,
70 Profile* profile) {
71 Browser* browser = Browser::CreateForType(type, profile);
72 browser->AddBlankTab(true);
73 return browser;
74}
[email protected]a1feae52010-10-11 22:14:4575
[email protected]b35b26b32011-05-05 20:35:1476Browser* BrowserNavigatorTest::CreateEmptyBrowserForApp(Browser::Type type,
77 Profile* profile) {
78 Browser* browser = Browser::CreateForApp(Browser::TYPE_POPUP, "Test",
[email protected]5c209242011-06-06 20:36:1779 gfx::Rect(), profile);
[email protected]b35b26b32011-05-05 20:35:1480 browser->AddBlankTab(true);
81 return browser;
82}
83
[email protected]bd817c22011-02-09 08:16:4684TabContentsWrapper* BrowserNavigatorTest::CreateTabContents() {
85 return Browser::TabContentsFactory(
86 browser()->profile(),
87 NULL,
88 MSG_ROUTING_NONE,
89 browser()->GetSelectedTabContents(),
90 NULL);
91}
[email protected]a1feae52010-10-11 22:14:4592
[email protected]bd817c22011-02-09 08:16:4693void BrowserNavigatorTest::RunSuppressTest(WindowOpenDisposition disposition) {
94 GURL old_url = browser()->GetSelectedTabContents()->GetURL();
95 browser::NavigateParams p(MakeNavigateParams());
96 p.disposition = disposition;
97 browser::Navigate(&p);
[email protected]a1feae52010-10-11 22:14:4598
[email protected]bd817c22011-02-09 08:16:4699 // Nothing should have happened as a result of Navigate();
100 EXPECT_EQ(1, browser()->tab_count());
101 EXPECT_EQ(1u, BrowserList::size());
102 EXPECT_EQ(old_url, browser()->GetSelectedTabContents()->GetURL());
103}
[email protected]bb89e7482010-11-17 18:27:04104
[email protected]6c2381d2011-10-19 02:52:53105void BrowserNavigatorTest::Observe(
106 int type,
107 const content::NotificationSource& source,
108 const content::NotificationDetails& details) {
[email protected]432115822011-07-10 15:52:27109 switch (type) {
110 case content::NOTIFICATION_RENDER_VIEW_HOST_CREATED_FOR_TAB: {
[email protected]bd817c22011-02-09 08:16:46111 ++this->created_tab_contents_count_;
112 break;
[email protected]fa7ebe02010-11-29 23:04:57113 }
[email protected]bd817c22011-02-09 08:16:46114 default:
115 break;
[email protected]fa7ebe02010-11-29 23:04:57116 }
[email protected]bd817c22011-02-09 08:16:46117}
[email protected]fa7ebe02010-11-29 23:04:57118
[email protected]ddddfda2011-07-14 23:19:39119
[email protected]bd817c22011-02-09 08:16:46120namespace {
[email protected]a1feae52010-10-11 22:14:45121
[email protected]a1feae52010-10-11 22:14:45122// This test verifies that when a navigation occurs within a tab, the tab count
123// of the Browser remains the same and the current tab bears the loaded URL.
124IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_CurrentTab) {
[email protected]ddddfda2011-07-14 23:19:39125 ui_test_utils::NavigateToURL(browser(), GetGoogleURL());
[email protected]a1feae52010-10-11 22:14:45126 EXPECT_EQ(GetGoogleURL(), browser()->GetSelectedTabContents()->GetURL());
127 // We should have one window with one tab.
128 EXPECT_EQ(1u, BrowserList::size());
129 EXPECT_EQ(1, browser()->tab_count());
130}
131
[email protected]bd817c22011-02-09 08:16:46132// This test verifies that a singleton tab is refocused if one is already opened
[email protected]19d9f3a2010-10-14 21:49:36133// in another or an existing window, or added if it is not.
134IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_SingletonTabExisting) {
[email protected]19d9f3a2010-10-14 21:49:36135 GURL singleton_url1("http://maps.google.com/");
[email protected]fa7ebe02010-11-29 23:04:57136
137 // Register for a notification if an additional tab_contents was instantiated.
[email protected]bd817c22011-02-09 08:16:46138 // Opening a Singleton tab that is already opened should not be opening a new
[email protected]fa7ebe02010-11-29 23:04:57139 // tab nor be creating a new TabContents object
[email protected]6c2381d2011-10-19 02:52:53140 content::NotificationRegistrar registrar;
[email protected]fa7ebe02010-11-29 23:04:57141
142 // As the registrar object goes out of scope, this will get unregistered
[email protected]432115822011-07-10 15:52:27143 registrar.Add(this, content::NOTIFICATION_RENDER_VIEW_HOST_CREATED_FOR_TAB,
[email protected]ad50def52011-10-19 23:17:07144 content::NotificationService::AllSources());
[email protected]fa7ebe02010-11-29 23:04:57145
[email protected]2905f742011-10-13 03:51:58146 browser()->AddSelectedTabWithURL(
147 singleton_url1, content::PAGE_TRANSITION_LINK);
148 browser()->AddSelectedTabWithURL(
149 GetGoogleURL(), content::PAGE_TRANSITION_LINK);
[email protected]19d9f3a2010-10-14 21:49:36150
151 // We should have one browser with 3 tabs, the 3rd selected.
152 EXPECT_EQ(1u, BrowserList::size());
[email protected]1ea49d52011-04-12 17:44:44153 EXPECT_EQ(2, browser()->active_index());
[email protected]19d9f3a2010-10-14 21:49:36154
[email protected]fa7ebe02010-11-29 23:04:57155 unsigned int previous_tab_contents_count =
156 created_tab_contents_count_ = 0;
157
[email protected]19d9f3a2010-10-14 21:49:36158 // Navigate to singleton_url1.
159 browser::NavigateParams p(MakeNavigateParams());
160 p.disposition = SINGLETON_TAB;
161 p.url = singleton_url1;
162 browser::Navigate(&p);
163
164 // The middle tab should now be selected.
165 EXPECT_EQ(browser(), p.browser);
[email protected]1ea49d52011-04-12 17:44:44166 EXPECT_EQ(1, browser()->active_index());
[email protected]fa7ebe02010-11-29 23:04:57167
168 // No tab contents should have been created
169 EXPECT_EQ(previous_tab_contents_count,
170 created_tab_contents_count_);
[email protected]19d9f3a2010-10-14 21:49:36171}
172
173IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
[email protected]578c6962011-08-24 22:06:40174 Disposition_SingletonTabRespectingRef) {
175 GURL singleton_ref_url1("http://maps.google.com/#a");
176 GURL singleton_ref_url2("http://maps.google.com/#b");
177 GURL singleton_ref_url3("http://maps.google.com/");
178
[email protected]2905f742011-10-13 03:51:58179 browser()->AddSelectedTabWithURL(
180 singleton_ref_url1, content::PAGE_TRANSITION_LINK);
[email protected]578c6962011-08-24 22:06:40181
182 // We should have one browser with 2 tabs, 2nd selected.
183 EXPECT_EQ(1u, BrowserList::size());
184 EXPECT_EQ(2, browser()->tab_count());
185 EXPECT_EQ(1, browser()->active_index());
186
187 // Navigate to singleton_url2.
188 browser::NavigateParams p(MakeNavigateParams());
189 p.disposition = SINGLETON_TAB;
190 p.url = singleton_ref_url2;
191 browser::Navigate(&p);
192
193 // We should now have 2 tabs, the 2nd one selected.
194 EXPECT_EQ(browser(), p.browser);
195 EXPECT_EQ(2, browser()->tab_count());
196 EXPECT_EQ(1, browser()->active_index());
197
198 // Navigate to singleton_url2, but with respect ref set.
199 p = MakeNavigateParams();
200 p.disposition = SINGLETON_TAB;
201 p.url = singleton_ref_url2;
202 p.ref_behavior = browser::NavigateParams::RESPECT_REF;
203 browser::Navigate(&p);
204
205 // We should now have 3 tabs, the 3th one selected.
206 EXPECT_EQ(browser(), p.browser);
207 EXPECT_EQ(3, browser()->tab_count());
208 EXPECT_EQ(2, browser()->active_index());
209
210 // Navigate to singleton_url3.
211 p = MakeNavigateParams();
212 p.disposition = SINGLETON_TAB;
213 p.url = singleton_ref_url3;
214 p.ref_behavior = browser::NavigateParams::RESPECT_REF;
215 browser::Navigate(&p);
216
217 // We should now have 4 tabs, the 4th one selected.
218 EXPECT_EQ(browser(), p.browser);
219 EXPECT_EQ(4, browser()->tab_count());
220 EXPECT_EQ(3, browser()->active_index());
221}
222
223IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
[email protected]19d9f3a2010-10-14 21:49:36224 Disposition_SingletonTabNoneExisting) {
[email protected]19d9f3a2010-10-14 21:49:36225 GURL singleton_url1("http://maps.google.com/");
226
[email protected]bd817c22011-02-09 08:16:46227 // We should have one browser with 1 tab.
[email protected]19d9f3a2010-10-14 21:49:36228 EXPECT_EQ(1u, BrowserList::size());
[email protected]1ea49d52011-04-12 17:44:44229 EXPECT_EQ(0, browser()->active_index());
[email protected]19d9f3a2010-10-14 21:49:36230
231 // Navigate to singleton_url1.
232 browser::NavigateParams p(MakeNavigateParams());
233 p.disposition = SINGLETON_TAB;
234 p.url = singleton_url1;
235 browser::Navigate(&p);
236
237 // We should now have 2 tabs, the 2nd one selected.
238 EXPECT_EQ(browser(), p.browser);
239 EXPECT_EQ(2, browser()->tab_count());
[email protected]1ea49d52011-04-12 17:44:44240 EXPECT_EQ(1, browser()->active_index());
[email protected]a1feae52010-10-11 22:14:45241}
242
243// This test verifies that when a navigation results in a foreground tab, the
244// tab count of the Browser increases and the selected tab shifts to the new
245// foreground tab.
246IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_NewForegroundTab) {
247 TabContents* old_contents = browser()->GetSelectedTabContents();
248 browser::NavigateParams p(MakeNavigateParams());
249 p.disposition = NEW_FOREGROUND_TAB;
[email protected]19d9f3a2010-10-14 21:49:36250 browser::Navigate(&p);
[email protected]a1feae52010-10-11 22:14:45251 EXPECT_NE(old_contents, browser()->GetSelectedTabContents());
[email protected]3c9e1872010-11-18 16:17:49252 EXPECT_EQ(browser()->GetSelectedTabContentsWrapper(), p.target_contents);
[email protected]a1feae52010-10-11 22:14:45253 EXPECT_EQ(2, browser()->tab_count());
254}
255
256// This test verifies that when a navigation results in a background tab, the
257// tab count of the Browser increases but the selected tab remains the same.
258IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_NewBackgroundTab) {
259 TabContents* old_contents = browser()->GetSelectedTabContents();
260 browser::NavigateParams p(MakeNavigateParams());
261 p.disposition = NEW_BACKGROUND_TAB;
[email protected]19d9f3a2010-10-14 21:49:36262 browser::Navigate(&p);
[email protected]a1feae52010-10-11 22:14:45263 TabContents* new_contents = browser()->GetSelectedTabContents();
264 // The selected tab should have remained unchanged, since the new tab was
265 // opened in the background.
266 EXPECT_EQ(old_contents, new_contents);
267 EXPECT_EQ(2, browser()->tab_count());
268}
269
270// This test verifies that when a navigation requiring a new foreground tab
271// occurs in a Browser that cannot host multiple tabs, the new foreground tab
272// is created in an existing compatible Browser.
273IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
274 Disposition_IncompatibleWindow_Existing) {
275 // Open a foreground tab in a window that cannot open popups when there is an
276 // existing compatible window somewhere else that they can be opened within.
277 Browser* popup = CreateEmptyBrowserForType(Browser::TYPE_POPUP,
278 browser()->profile());
279 browser::NavigateParams p(MakeNavigateParams(popup));
280 p.disposition = NEW_FOREGROUND_TAB;
[email protected]19d9f3a2010-10-14 21:49:36281 browser::Navigate(&p);
[email protected]a1feae52010-10-11 22:14:45282
283 // Navigate() should have opened the tab in a different browser since the
284 // one we supplied didn't support additional tabs.
285 EXPECT_NE(popup, p.browser);
286
287 // Since browser() is an existing compatible tabbed browser, it should have
288 // opened the tab there.
289 EXPECT_EQ(browser(), p.browser);
290
291 // We should be left with 2 windows, the popup with one tab and the browser()
292 // provided by the framework with two.
293 EXPECT_EQ(2u, BrowserList::size());
294 EXPECT_EQ(1, popup->tab_count());
295 EXPECT_EQ(2, browser()->tab_count());
296}
297
298// This test verifies that when a navigation requiring a new foreground tab
299// occurs in a Browser that cannot host multiple tabs and no compatible Browser
300// that can is open, a compatible Browser is created.
301IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
302 Disposition_IncompatibleWindow_NoExisting) {
303 // We want to simulate not being able to find an existing window compatible
304 // with our non-tabbed browser window so Navigate() is forced to create a
305 // new compatible window. Because browser() supplied by the in-process
306 // browser testing framework is compatible with browser()->profile(), we
307 // need a different profile, and creating a popup window with an incognito
308 // profile is a quick and dirty way of achieving this.
309 Browser* popup = CreateEmptyBrowserForType(
[email protected]b35b26b32011-05-05 20:35:14310 Browser::TYPE_POPUP,
311 browser()->profile()->GetOffTheRecordProfile());
[email protected]a1feae52010-10-11 22:14:45312 browser::NavigateParams p(MakeNavigateParams(popup));
313 p.disposition = NEW_FOREGROUND_TAB;
[email protected]19d9f3a2010-10-14 21:49:36314 browser::Navigate(&p);
[email protected]a1feae52010-10-11 22:14:45315
316 // Navigate() should have opened the tab in a different browser since the
317 // one we supplied didn't support additional tabs.
318 EXPECT_NE(popup, p.browser);
319
320 // This time, browser() is _not_ compatible with popup since it is not an
321 // incognito window.
322 EXPECT_NE(browser(), p.browser);
323
324 // We should have three windows, each with one tab:
325 // 1. the browser() provided by the framework (unchanged in this test)
326 // 2. the incognito popup we created originally
327 // 3. the new incognito tabbed browser that was created by Navigate().
328 EXPECT_EQ(3u, BrowserList::size());
329 EXPECT_EQ(1, browser()->tab_count());
330 EXPECT_EQ(1, popup->tab_count());
331 EXPECT_EQ(1, p.browser->tab_count());
[email protected]b35b26b32011-05-05 20:35:14332 EXPECT_TRUE(p.browser->is_type_tabbed());
[email protected]a1feae52010-10-11 22:14:45333}
334
335// This test verifies that navigating with WindowOpenDisposition = NEW_POPUP
336// from a normal Browser results in a new Browser with TYPE_POPUP.
337IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_NewPopup) {
338 browser::NavigateParams p(MakeNavigateParams());
339 p.disposition = NEW_POPUP;
[email protected]588300d2011-04-28 21:06:35340 p.window_bounds = gfx::Rect(0, 0, 200, 200);
[email protected]7d329992011-04-15 18:20:02341 // Wait for new popup to to load and gain focus.
[email protected]ddddfda2011-07-14 23:19:39342 ui_test_utils::NavigateToURL(&p);
[email protected]a1feae52010-10-11 22:14:45343
[email protected]7d329992011-04-15 18:20:02344 // Navigate() should have opened a new, focused popup window.
[email protected]a1feae52010-10-11 22:14:45345 EXPECT_NE(browser(), p.browser);
[email protected]9db263a2011-04-15 20:53:47346#if 0
347 // TODO(stevenjb): Enable this test. See: crbug.com/79493
[email protected]7d329992011-04-15 18:20:02348 EXPECT_TRUE(p.browser->window()->IsActive());
349#endif
[email protected]b35b26b32011-05-05 20:35:14350 EXPECT_TRUE(p.browser->is_type_popup());
351 EXPECT_FALSE(p.browser->is_app());
[email protected]a1feae52010-10-11 22:14:45352
353 // We should have two windows, the browser() provided by the framework and the
354 // new popup window.
355 EXPECT_EQ(2u, BrowserList::size());
356 EXPECT_EQ(1, browser()->tab_count());
357 EXPECT_EQ(1, p.browser->tab_count());
358}
359
360// This test verifies that navigating with WindowOpenDisposition = NEW_POPUP
[email protected]f112b0f2011-05-26 01:53:52361// from a normal Browser results in a new Browser with is_app() true.
362IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_NewPopup_ExtensionId) {
363 browser::NavigateParams p(MakeNavigateParams());
364 p.disposition = NEW_POPUP;
365 p.extension_app_id = "extensionappid";
366 p.window_bounds = gfx::Rect(0, 0, 200, 200);
[email protected]f112b0f2011-05-26 01:53:52367 // Wait for new popup to to load and gain focus.
[email protected]ddddfda2011-07-14 23:19:39368 ui_test_utils::NavigateToURL(&p);
[email protected]f112b0f2011-05-26 01:53:52369
370 // Navigate() should have opened a new, focused popup window.
371 EXPECT_NE(browser(), p.browser);
372 EXPECT_TRUE(p.browser->is_type_popup());
373 EXPECT_TRUE(p.browser->is_app());
374
375 // We should have two windows, the browser() provided by the framework and the
376 // new popup window.
377 EXPECT_EQ(2u, BrowserList::size());
378 EXPECT_EQ(1, browser()->tab_count());
379 EXPECT_EQ(1, p.browser->tab_count());
380}
381
382// This test verifies that navigating with WindowOpenDisposition = NEW_POPUP
[email protected]300d1e52011-01-19 23:57:57383// from a normal popup results in a new Browser with TYPE_POPUP.
384IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_NewPopupFromPopup) {
385 // Open a popup.
386 browser::NavigateParams p1(MakeNavigateParams());
387 p1.disposition = NEW_POPUP;
[email protected]588300d2011-04-28 21:06:35388 p1.window_bounds = gfx::Rect(0, 0, 200, 200);
[email protected]300d1e52011-01-19 23:57:57389 browser::Navigate(&p1);
390 // Open another popup.
391 browser::NavigateParams p2(MakeNavigateParams(p1.browser));
392 p2.disposition = NEW_POPUP;
[email protected]588300d2011-04-28 21:06:35393 p2.window_bounds = gfx::Rect(0, 0, 200, 200);
[email protected]300d1e52011-01-19 23:57:57394 browser::Navigate(&p2);
395
396 // Navigate() should have opened a new normal popup window.
397 EXPECT_NE(p1.browser, p2.browser);
[email protected]b35b26b32011-05-05 20:35:14398 EXPECT_TRUE(p2.browser->is_type_popup());
399 EXPECT_FALSE(p2.browser->is_app());
[email protected]300d1e52011-01-19 23:57:57400
401 // We should have three windows, the browser() provided by the framework,
402 // the first popup window, and the second popup window.
403 EXPECT_EQ(3u, BrowserList::size());
404 EXPECT_EQ(1, browser()->tab_count());
405 EXPECT_EQ(1, p1.browser->tab_count());
406 EXPECT_EQ(1, p2.browser->tab_count());
407}
408
409// This test verifies that navigating with WindowOpenDisposition = NEW_POPUP
[email protected]a1feae52010-10-11 22:14:45410// from an app frame results in a new Browser with TYPE_APP_POPUP.
411IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
412 Disposition_NewPopupFromAppWindow) {
[email protected]b35b26b32011-05-05 20:35:14413 Browser* app_browser = CreateEmptyBrowserForApp(Browser::TYPE_TABBED,
414 browser()->profile());
[email protected]a1feae52010-10-11 22:14:45415 browser::NavigateParams p(MakeNavigateParams(app_browser));
416 p.disposition = NEW_POPUP;
[email protected]588300d2011-04-28 21:06:35417 p.window_bounds = gfx::Rect(0, 0, 200, 200);
[email protected]19d9f3a2010-10-14 21:49:36418 browser::Navigate(&p);
[email protected]a1feae52010-10-11 22:14:45419
420 // Navigate() should have opened a new popup app window.
421 EXPECT_NE(app_browser, p.browser);
422 EXPECT_NE(browser(), p.browser);
[email protected]b35b26b32011-05-05 20:35:14423 EXPECT_TRUE(p.browser->is_type_popup());
424 EXPECT_TRUE(p.browser->is_app());
[email protected]a1feae52010-10-11 22:14:45425
426 // We should now have three windows, the app window, the app popup it created,
427 // and the original browser() provided by the framework.
428 EXPECT_EQ(3u, BrowserList::size());
429 EXPECT_EQ(1, browser()->tab_count());
430 EXPECT_EQ(1, app_browser->tab_count());
431 EXPECT_EQ(1, p.browser->tab_count());
432}
433
434// This test verifies that navigating with WindowOpenDisposition = NEW_POPUP
[email protected]300d1e52011-01-19 23:57:57435// from an app popup results in a new Browser also of TYPE_APP_POPUP.
436IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
437 Disposition_NewPopupFromAppPopup) {
[email protected]b35b26b32011-05-05 20:35:14438 Browser* app_browser = CreateEmptyBrowserForApp(Browser::TYPE_TABBED,
439 browser()->profile());
[email protected]300d1e52011-01-19 23:57:57440 // Open an app popup.
441 browser::NavigateParams p1(MakeNavigateParams(app_browser));
442 p1.disposition = NEW_POPUP;
[email protected]588300d2011-04-28 21:06:35443 p1.window_bounds = gfx::Rect(0, 0, 200, 200);
[email protected]300d1e52011-01-19 23:57:57444 browser::Navigate(&p1);
445 // Now open another app popup.
446 browser::NavigateParams p2(MakeNavigateParams(p1.browser));
447 p2.disposition = NEW_POPUP;
[email protected]588300d2011-04-28 21:06:35448 p2.window_bounds = gfx::Rect(0, 0, 200, 200);
[email protected]300d1e52011-01-19 23:57:57449 browser::Navigate(&p2);
450
451 // Navigate() should have opened a new popup app window.
452 EXPECT_NE(browser(), p1.browser);
453 EXPECT_NE(p1.browser, p2.browser);
[email protected]b35b26b32011-05-05 20:35:14454 EXPECT_TRUE(p2.browser->is_type_popup());
455 EXPECT_TRUE(p2.browser->is_app());
[email protected]300d1e52011-01-19 23:57:57456
457 // We should now have four windows, the app window, the first app popup,
458 // the second app popup, and the original browser() provided by the framework.
459 EXPECT_EQ(4u, BrowserList::size());
460 EXPECT_EQ(1, browser()->tab_count());
461 EXPECT_EQ(1, app_browser->tab_count());
462 EXPECT_EQ(1, p1.browser->tab_count());
463 EXPECT_EQ(1, p2.browser->tab_count());
464}
465
466// This test verifies that navigating with WindowOpenDisposition = NEW_POPUP
[email protected]a1feae52010-10-11 22:14:45467// from an extension app tab results in a new Browser with TYPE_APP_POPUP.
468IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
469 Disposition_NewPopupFromExtensionApp) {
470 // TODO(beng): TBD.
471}
472
[email protected]7d329992011-04-15 18:20:02473// This test verifies that navigating with window_action = SHOW_WINDOW_INACTIVE
474// does not focus a new new popup window.
475IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_NewPopupUnfocused) {
476 browser::NavigateParams p(MakeNavigateParams());
477 p.disposition = NEW_POPUP;
[email protected]588300d2011-04-28 21:06:35478 p.window_bounds = gfx::Rect(0, 0, 200, 200);
[email protected]7d329992011-04-15 18:20:02479 p.window_action = browser::NavigateParams::SHOW_WINDOW_INACTIVE;
[email protected]7d329992011-04-15 18:20:02480 // Wait for new popup to load (and gain focus if the test fails).
[email protected]ddddfda2011-07-14 23:19:39481 ui_test_utils::NavigateToURL(&p);
[email protected]7d329992011-04-15 18:20:02482
483 // Navigate() should have opened a new, unfocused, popup window.
484 EXPECT_NE(browser(), p.browser);
485 EXPECT_EQ(Browser::TYPE_POPUP, p.browser->type());
[email protected]9db263a2011-04-15 20:53:47486#if 0
487// TODO(stevenjb): Enable this test. See: crbug.com/79493
[email protected]7d329992011-04-15 18:20:02488 EXPECT_FALSE(p.browser->window()->IsActive());
[email protected]7d329992011-04-15 18:20:02489#endif
[email protected]9db263a2011-04-15 20:53:47490}
[email protected]7d329992011-04-15 18:20:02491
[email protected]a1feae52010-10-11 22:14:45492// This test verifies that navigating with WindowOpenDisposition = NEW_WINDOW
493// always opens a new window.
494IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_NewWindow) {
495 browser::NavigateParams p(MakeNavigateParams());
496 p.disposition = NEW_WINDOW;
[email protected]19d9f3a2010-10-14 21:49:36497 browser::Navigate(&p);
[email protected]a1feae52010-10-11 22:14:45498
499 // Navigate() should have opened a new toplevel window.
500 EXPECT_NE(browser(), p.browser);
[email protected]b35b26b32011-05-05 20:35:14501 EXPECT_TRUE(p.browser->is_type_tabbed());
[email protected]a1feae52010-10-11 22:14:45502
503 // We should now have two windows, the browser() provided by the framework and
504 // the new normal window.
505 EXPECT_EQ(2u, BrowserList::size());
506 EXPECT_EQ(1, browser()->tab_count());
507 EXPECT_EQ(1, p.browser->tab_count());
508}
509
510// This test verifies that navigating with WindowOpenDisposition = INCOGNITO
511// opens a new incognito window if no existing incognito window is present.
512IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_Incognito) {
513 browser::NavigateParams p(MakeNavigateParams());
514 p.disposition = OFF_THE_RECORD;
[email protected]19d9f3a2010-10-14 21:49:36515 browser::Navigate(&p);
[email protected]a1feae52010-10-11 22:14:45516
517 // Navigate() should have opened a new toplevel incognito window.
518 EXPECT_NE(browser(), p.browser);
519 EXPECT_EQ(browser()->profile()->GetOffTheRecordProfile(),
520 p.browser->profile());
521
[email protected]d7ff3592010-11-30 21:50:46522 // |source_contents| should be set to NULL because the profile for the new
523 // page is different from the originating page.
524 EXPECT_EQ(NULL, p.source_contents);
525
[email protected]a1feae52010-10-11 22:14:45526 // We should now have two windows, the browser() provided by the framework and
527 // the new incognito window.
528 EXPECT_EQ(2u, BrowserList::size());
529 EXPECT_EQ(1, browser()->tab_count());
530 EXPECT_EQ(1, p.browser->tab_count());
531}
532
533// This test verifies that navigating with WindowOpenDisposition = INCOGNITO
534// reuses an existing incognito window when possible.
535IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_IncognitoRefocus) {
536 Browser* incognito_browser =
[email protected]b35b26b32011-05-05 20:35:14537 CreateEmptyBrowserForType(Browser::TYPE_TABBED,
[email protected]a1feae52010-10-11 22:14:45538 browser()->profile()->GetOffTheRecordProfile());
539 browser::NavigateParams p(MakeNavigateParams());
540 p.disposition = OFF_THE_RECORD;
[email protected]19d9f3a2010-10-14 21:49:36541 browser::Navigate(&p);
[email protected]a1feae52010-10-11 22:14:45542
543 // Navigate() should have opened a new tab in the existing incognito window.
544 EXPECT_NE(browser(), p.browser);
545 EXPECT_EQ(p.browser, incognito_browser);
546
547 // We should now have two windows, the browser() provided by the framework and
548 // the incognito window we opened earlier.
549 EXPECT_EQ(2u, BrowserList::size());
550 EXPECT_EQ(1, browser()->tab_count());
551 EXPECT_EQ(2, incognito_browser->tab_count());
552}
553
554// This test verifies that no navigation action occurs when
555// WindowOpenDisposition = SUPPRESS_OPEN.
556IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_SuppressOpen) {
557 RunSuppressTest(SUPPRESS_OPEN);
558}
559
560// This test verifies that no navigation action occurs when
561// WindowOpenDisposition = SAVE_TO_DISK.
562IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_SaveToDisk) {
563 RunSuppressTest(SAVE_TO_DISK);
564}
565
566// This test verifies that no navigation action occurs when
567// WindowOpenDisposition = IGNORE_ACTION.
568IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_IgnoreAction) {
569 RunSuppressTest(IGNORE_ACTION);
570}
571
572// This tests adding a foreground tab with a predefined TabContents.
573IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, TargetContents_ForegroundTab) {
574 browser::NavigateParams p(MakeNavigateParams());
575 p.disposition = NEW_FOREGROUND_TAB;
576 p.target_contents = CreateTabContents();
[email protected]19d9f3a2010-10-14 21:49:36577 browser::Navigate(&p);
[email protected]a1feae52010-10-11 22:14:45578
579 // Navigate() should have opened the contents in a new foreground in the
580 // current Browser.
581 EXPECT_EQ(browser(), p.browser);
[email protected]3c9e1872010-11-18 16:17:49582 EXPECT_EQ(browser()->GetSelectedTabContentsWrapper(), p.target_contents);
[email protected]a1feae52010-10-11 22:14:45583
584 // We should have one window, with two tabs.
585 EXPECT_EQ(1u, BrowserList::size());
586 EXPECT_EQ(2, browser()->tab_count());
587}
588
589#if defined(OS_WIN)
590// This tests adding a popup with a predefined TabContents.
[email protected]76edb672011-03-04 21:48:39591IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, DISABLED_TargetContents_Popup) {
[email protected]a1feae52010-10-11 22:14:45592 browser::NavigateParams p(MakeNavigateParams());
593 p.disposition = NEW_POPUP;
594 p.target_contents = CreateTabContents();
595 p.window_bounds = gfx::Rect(10, 10, 500, 500);
[email protected]19d9f3a2010-10-14 21:49:36596 browser::Navigate(&p);
[email protected]a1feae52010-10-11 22:14:45597
598 // Navigate() should have opened a new popup window.
599 EXPECT_NE(browser(), p.browser);
[email protected]b35b26b32011-05-05 20:35:14600 EXPECT_TRUE(p.browser->is_type_popup());
601 EXPECT_FALSE(p.browser->is_app());
[email protected]a1feae52010-10-11 22:14:45602
603 // The web platform is weird. The window bounds specified in
604 // |p.window_bounds| are used as follows:
605 // - the origin is used to position the window
606 // - the size is used to size the TabContents of the window.
607 // As such the position of the resulting window will always match
608 // p.window_bounds.origin(), but its size will not. We need to match
609 // the size against the selected tab's view's container size.
610 // Only Windows positions the window according to |p.window_bounds.origin()| -
611 // on Mac the window is offset from the opener and on Linux it always opens
612 // at 0,0.
613 EXPECT_EQ(p.window_bounds.origin(),
614 p.browser->window()->GetRestoredBounds().origin());
615 // All platforms should respect size however provided width > 400 (Mac has a
616 // minimum window width of 400).
617 EXPECT_EQ(p.window_bounds.size(),
[email protected]3c9e1872010-11-18 16:17:49618 p.target_contents->tab_contents()->view()->GetContainerSize());
[email protected]a1feae52010-10-11 22:14:45619
620 // We should have two windows, the new popup and the browser() provided by the
621 // framework.
622 EXPECT_EQ(2u, BrowserList::size());
623 EXPECT_EQ(1, browser()->tab_count());
624 EXPECT_EQ(1, p.browser->tab_count());
625}
626#endif
627
628// This tests adding a tab at a specific index.
629IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Tabstrip_InsertAtIndex) {
630 // This is not meant to be a comprehensive test of whether or not the tab
631 // implementation of the browser observes the insertion index. That is
632 // covered by the unit tests for TabStripModel. This merely verifies that
633 // insertion index preference is reflected in common cases.
634 browser::NavigateParams p(MakeNavigateParams());
635 p.disposition = NEW_FOREGROUND_TAB;
636 p.tabstrip_index = 0;
637 p.tabstrip_add_types = TabStripModel::ADD_FORCE_INDEX;
[email protected]19d9f3a2010-10-14 21:49:36638 browser::Navigate(&p);
[email protected]a1feae52010-10-11 22:14:45639
640 // Navigate() should have inserted a new tab at slot 0 in the tabstrip.
641 EXPECT_EQ(browser(), p.browser);
642 EXPECT_EQ(0, browser()->tabstrip_model()->GetIndexOfTabContents(
[email protected]3c9e1872010-11-18 16:17:49643 static_cast<const TabContentsWrapper*>(p.target_contents)));
[email protected]a1feae52010-10-11 22:14:45644
645 // We should have one window - the browser() provided by the framework.
646 EXPECT_EQ(1u, BrowserList::size());
647 EXPECT_EQ(2, browser()->tab_count());
648}
649
[email protected]2dd85482010-11-06 01:56:47650// This test verifies that constructing params with a NULL browser has
651// the same result as navigating to a new foreground tab in the (only)
652// active browser. Tests are the same as for Disposition_NewForegroundTab.
653IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, NullBrowser_NewForegroundTab) {
654 TabContents* old_contents = browser()->GetSelectedTabContents();
655 // Navigate with a NULL browser.
656 browser::NavigateParams p(MakeNavigateParams(NULL));
657 p.disposition = NEW_FOREGROUND_TAB;
658 p.profile = browser()->profile();
659 browser::Navigate(&p);
660
661 // Navigate() should have found browser() and create a new tab.
662 EXPECT_EQ(browser(), p.browser);
663 EXPECT_NE(old_contents, browser()->GetSelectedTabContents());
[email protected]3c9e1872010-11-18 16:17:49664 EXPECT_EQ(browser()->GetSelectedTabContentsWrapper(), p.target_contents);
[email protected]2dd85482010-11-06 01:56:47665 EXPECT_EQ(2, browser()->tab_count());
666}
667
668// This test verifies that constructing params with a NULL browser and
669// a specific profile matches the specified profile.
[email protected]c8a31a72011-09-30 01:53:32670IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, NullBrowser_MatchProfile) {
[email protected]2dd85482010-11-06 01:56:47671 // Create a new browser with using the incognito profile.
672 Browser* incognito =
673 Browser::Create(browser()->profile()->GetOffTheRecordProfile());
674
675 // Navigate with a NULL browser and the incognito profile.
676 browser::NavigateParams p(MakeNavigateParams(NULL));
677 p.disposition = NEW_FOREGROUND_TAB;
678 p.profile = incognito->profile();
679 browser::Navigate(&p);
680
681 // Navigate() should have found incognito, not browser().
682 EXPECT_EQ(incognito, p.browser);
[email protected]3c9e1872010-11-18 16:17:49683 EXPECT_EQ(incognito->GetSelectedTabContentsWrapper(), p.target_contents);
[email protected]2dd85482010-11-06 01:56:47684 EXPECT_EQ(1, incognito->tab_count());
685}
686
687// This test verifies that constructing params with a NULL browser and
688// disposition = NEW_WINDOW always opens exactly one new window.
689IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, NullBrowser_NewWindow) {
690 browser::NavigateParams p(MakeNavigateParams(NULL));
691 p.disposition = NEW_WINDOW;
692 p.profile = browser()->profile();
693 browser::Navigate(&p);
694
695 // Navigate() should have created a new browser.
696 EXPECT_NE(browser(), p.browser);
[email protected]b35b26b32011-05-05 20:35:14697 EXPECT_TRUE( p.browser->is_type_tabbed());
[email protected]2dd85482010-11-06 01:56:47698
699 // We should now have two windows, the browser() provided by the framework and
700 // the new normal window.
701 EXPECT_EQ(2u, BrowserList::size());
702 EXPECT_EQ(1, browser()->tab_count());
703 EXPECT_EQ(1, p.browser->tab_count());
704}
705
[email protected]bb89e7482010-11-17 18:27:04706// This test verifies that constructing params with disposition = SINGLETON_TAB
[email protected]fee320542011-03-02 01:30:49707// and IGNORE_AND_NAVIGATE opens a new tab navigated to the specified URL if
[email protected]67ed83e2011-01-07 22:54:00708// no previous tab with that URL (minus the path) exists.
[email protected]bb89e7482010-11-17 18:27:04709IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
710 Disposition_SingletonTabNew_IgnorePath) {
[email protected]2905f742011-10-13 03:51:58711 browser()->AddSelectedTabWithURL(
712 GetGoogleURL(), content::PAGE_TRANSITION_LINK);
[email protected]bb89e7482010-11-17 18:27:04713
714 // We should have one browser with 2 tabs, the 2nd selected.
715 EXPECT_EQ(1u, BrowserList::size());
716 EXPECT_EQ(2, browser()->tab_count());
[email protected]1ea49d52011-04-12 17:44:44717 EXPECT_EQ(1, browser()->active_index());
[email protected]bb89e7482010-11-17 18:27:04718
719 // Navigate to a new singleton tab with a sub-page.
720 browser::NavigateParams p(MakeNavigateParams());
721 p.disposition = SINGLETON_TAB;
[email protected]ddddfda2011-07-14 23:19:39722 p.url = GetSettingsAdvancedURL();
[email protected]7d329992011-04-15 18:20:02723 p.window_action = browser::NavigateParams::SHOW_WINDOW;
[email protected]fee320542011-03-02 01:30:49724 p.path_behavior = browser::NavigateParams::IGNORE_AND_NAVIGATE;
[email protected]bb89e7482010-11-17 18:27:04725 browser::Navigate(&p);
726
727 // The last tab should now be selected and navigated to the sub-page of the
728 // URL.
729 EXPECT_EQ(browser(), p.browser);
730 EXPECT_EQ(3, browser()->tab_count());
[email protected]1ea49d52011-04-12 17:44:44731 EXPECT_EQ(2, browser()->active_index());
[email protected]ddddfda2011-07-14 23:19:39732 EXPECT_EQ(GetSettingsAdvancedURL(),
[email protected]bb89e7482010-11-17 18:27:04733 browser()->GetSelectedTabContents()->GetURL());
734}
735
736// This test verifies that constructing params with disposition = SINGLETON_TAB
[email protected]fee320542011-03-02 01:30:49737// and IGNORE_AND_NAVIGATE opens an existing tab with the matching URL (minus
[email protected]bb89e7482010-11-17 18:27:04738// the path) which is navigated to the specified URL.
739IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
740 Disposition_SingletonTabExisting_IgnorePath) {
[email protected]ddddfda2011-07-14 23:19:39741 GURL singleton_url1(GetSettingsURL());
[email protected]2905f742011-10-13 03:51:58742 browser()->AddSelectedTabWithURL(
743 singleton_url1, content::PAGE_TRANSITION_LINK);
744 browser()->AddSelectedTabWithURL(
745 GetGoogleURL(), content::PAGE_TRANSITION_LINK);
[email protected]bb89e7482010-11-17 18:27:04746
747 // We should have one browser with 3 tabs, the 3rd selected.
748 EXPECT_EQ(1u, BrowserList::size());
749 EXPECT_EQ(3, browser()->tab_count());
[email protected]1ea49d52011-04-12 17:44:44750 EXPECT_EQ(2, browser()->active_index());
[email protected]bb89e7482010-11-17 18:27:04751
752 // Navigate to singleton_url1.
753 browser::NavigateParams p(MakeNavigateParams());
754 p.disposition = SINGLETON_TAB;
[email protected]ddddfda2011-07-14 23:19:39755 p.url = GetSettingsAdvancedURL();
[email protected]7d329992011-04-15 18:20:02756 p.window_action = browser::NavigateParams::SHOW_WINDOW;
[email protected]fee320542011-03-02 01:30:49757 p.path_behavior = browser::NavigateParams::IGNORE_AND_NAVIGATE;
[email protected]bb89e7482010-11-17 18:27:04758 browser::Navigate(&p);
759
760 // The middle tab should now be selected and navigated to the sub-page of the
761 // URL.
762 EXPECT_EQ(browser(), p.browser);
763 EXPECT_EQ(3, browser()->tab_count());
[email protected]1ea49d52011-04-12 17:44:44764 EXPECT_EQ(1, browser()->active_index());
[email protected]ddddfda2011-07-14 23:19:39765 EXPECT_EQ(GetSettingsAdvancedURL(),
[email protected]bb89e7482010-11-17 18:27:04766 browser()->GetSelectedTabContents()->GetURL());
767}
768
769// This test verifies that constructing params with disposition = SINGLETON_TAB
[email protected]fee320542011-03-02 01:30:49770// and IGNORE_AND_NAVIGATE opens an existing tab with the matching URL (minus
[email protected]bb89e7482010-11-17 18:27:04771// the path) which is navigated to the specified URL.
772IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
773 Disposition_SingletonTabExistingSubPath_IgnorePath) {
[email protected]ddddfda2011-07-14 23:19:39774 GURL singleton_url1(GetSettingsAdvancedURL());
[email protected]2905f742011-10-13 03:51:58775 browser()->AddSelectedTabWithURL(
776 singleton_url1, content::PAGE_TRANSITION_LINK);
777 browser()->AddSelectedTabWithURL(
778 GetGoogleURL(), content::PAGE_TRANSITION_LINK);
[email protected]bb89e7482010-11-17 18:27:04779
780 // We should have one browser with 3 tabs, the 3rd selected.
781 EXPECT_EQ(1u, BrowserList::size());
782 EXPECT_EQ(3, browser()->tab_count());
[email protected]1ea49d52011-04-12 17:44:44783 EXPECT_EQ(2, browser()->active_index());
[email protected]bb89e7482010-11-17 18:27:04784
785 // Navigate to singleton_url1.
786 browser::NavigateParams p(MakeNavigateParams());
787 p.disposition = SINGLETON_TAB;
[email protected]ddddfda2011-07-14 23:19:39788 p.url = GetSettingsPersonalURL();
[email protected]7d329992011-04-15 18:20:02789 p.window_action = browser::NavigateParams::SHOW_WINDOW;
[email protected]fee320542011-03-02 01:30:49790 p.path_behavior = browser::NavigateParams::IGNORE_AND_NAVIGATE;
[email protected]bb89e7482010-11-17 18:27:04791 browser::Navigate(&p);
792
793 // The middle tab should now be selected and navigated to the sub-page of the
794 // URL.
795 EXPECT_EQ(browser(), p.browser);
796 EXPECT_EQ(3, browser()->tab_count());
[email protected]1ea49d52011-04-12 17:44:44797 EXPECT_EQ(1, browser()->active_index());
[email protected]ddddfda2011-07-14 23:19:39798 EXPECT_EQ(GetSettingsPersonalURL(),
[email protected]bb89e7482010-11-17 18:27:04799 browser()->GetSelectedTabContents()->GetURL());
800}
[email protected]2dd85482010-11-06 01:56:47801
[email protected]637b3442011-01-10 23:31:48802// This test verifies that constructing params with disposition = SINGLETON_TAB
[email protected]fee320542011-03-02 01:30:49803// and IGNORE_AND_STAY_PUT opens an existing tab with the matching URL (minus
804// the path).
805IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
806 Disposition_SingletonTabExistingSubPath_IgnorePath2) {
[email protected]ddddfda2011-07-14 23:19:39807 GURL singleton_url1(GetSettingsAdvancedURL());
[email protected]2905f742011-10-13 03:51:58808 browser()->AddSelectedTabWithURL(
809 singleton_url1, content::PAGE_TRANSITION_LINK);
810 browser()->AddSelectedTabWithURL(
811 GetGoogleURL(), content::PAGE_TRANSITION_LINK);
[email protected]fee320542011-03-02 01:30:49812
813 // We should have one browser with 3 tabs, the 3rd selected.
814 EXPECT_EQ(1u, BrowserList::size());
815 EXPECT_EQ(3, browser()->tab_count());
[email protected]1ea49d52011-04-12 17:44:44816 EXPECT_EQ(2, browser()->active_index());
[email protected]fee320542011-03-02 01:30:49817
818 // Navigate to singleton_url1.
819 browser::NavigateParams p(MakeNavigateParams());
820 p.disposition = SINGLETON_TAB;
[email protected]ddddfda2011-07-14 23:19:39821 p.url = GetSettingsPersonalURL();
[email protected]7d329992011-04-15 18:20:02822 p.window_action = browser::NavigateParams::SHOW_WINDOW;
[email protected]fee320542011-03-02 01:30:49823 p.path_behavior = browser::NavigateParams::IGNORE_AND_STAY_PUT;
824 browser::Navigate(&p);
825
826 // The middle tab should now be selected.
827 EXPECT_EQ(browser(), p.browser);
828 EXPECT_EQ(3, browser()->tab_count());
[email protected]1ea49d52011-04-12 17:44:44829 EXPECT_EQ(1, browser()->active_index());
[email protected]fee320542011-03-02 01:30:49830 EXPECT_EQ(singleton_url1,
831 browser()->GetSelectedTabContents()->GetURL());
832}
833
834// This test verifies that constructing params with disposition = SINGLETON_TAB
835// and IGNORE_AND_NAVIGATE will update the current tab's URL if the currently
[email protected]637b3442011-01-10 23:31:48836// selected tab is a match but has a different path.
837IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
838 Disposition_SingletonTabFocused_IgnorePath) {
[email protected]ddddfda2011-07-14 23:19:39839 GURL singleton_url_current(GetSettingsAdvancedURL());
[email protected]2905f742011-10-13 03:51:58840 browser()->AddSelectedTabWithURL(
841 singleton_url_current, content::PAGE_TRANSITION_LINK);
[email protected]637b3442011-01-10 23:31:48842
843 // We should have one browser with 2 tabs, the 2nd selected.
844 EXPECT_EQ(1u, BrowserList::size());
845 EXPECT_EQ(2, browser()->tab_count());
[email protected]1ea49d52011-04-12 17:44:44846 EXPECT_EQ(1, browser()->active_index());
[email protected]637b3442011-01-10 23:31:48847
848 // Navigate to a different settings path.
[email protected]ddddfda2011-07-14 23:19:39849 GURL singleton_url_target(GetSettingsPersonalURL());
[email protected]637b3442011-01-10 23:31:48850 browser::NavigateParams p(MakeNavigateParams());
851 p.disposition = SINGLETON_TAB;
852 p.url = singleton_url_target;
[email protected]7d329992011-04-15 18:20:02853 p.window_action = browser::NavigateParams::SHOW_WINDOW;
[email protected]fee320542011-03-02 01:30:49854 p.path_behavior = browser::NavigateParams::IGNORE_AND_NAVIGATE;
[email protected]637b3442011-01-10 23:31:48855 browser::Navigate(&p);
856
857 // The second tab should still be selected, but navigated to the new path.
858 EXPECT_EQ(browser(), p.browser);
859 EXPECT_EQ(2, browser()->tab_count());
[email protected]1ea49d52011-04-12 17:44:44860 EXPECT_EQ(1, browser()->active_index());
[email protected]637b3442011-01-10 23:31:48861 EXPECT_EQ(singleton_url_target,
862 browser()->GetSelectedTabContents()->GetURL());
863}
864
[email protected]07afd7c2011-02-17 10:07:11865// This test verifies that constructing params with disposition = SINGLETON_TAB
[email protected]fee320542011-03-02 01:30:49866// and IGNORE_AND_NAVIGATE will open an existing matching tab with a different
867// query.
[email protected]07afd7c2011-02-17 10:07:11868IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
869 Disposition_SingletonTabExisting_IgnoreQuery) {
870 int initial_tab_count = browser()->tab_count();
871 GURL singleton_url_current("chrome://settings/internet");
[email protected]2905f742011-10-13 03:51:58872 browser()->AddSelectedTabWithURL(
873 singleton_url_current, content::PAGE_TRANSITION_LINK);
[email protected]07afd7c2011-02-17 10:07:11874
875 EXPECT_EQ(initial_tab_count + 1, browser()->tab_count());
[email protected]1ea49d52011-04-12 17:44:44876 EXPECT_EQ(initial_tab_count, browser()->active_index());
[email protected]07afd7c2011-02-17 10:07:11877
878 // Navigate to a different settings path.
879 GURL singleton_url_target(
880 "chrome://settings/internet?"
881 "servicePath=/profile/ethernet_00aa00aa00aa&networkType=1");
882 browser::NavigateParams p(MakeNavigateParams());
883 p.disposition = SINGLETON_TAB;
884 p.url = singleton_url_target;
[email protected]7d329992011-04-15 18:20:02885 p.window_action = browser::NavigateParams::SHOW_WINDOW;
[email protected]fee320542011-03-02 01:30:49886 p.path_behavior = browser::NavigateParams::IGNORE_AND_NAVIGATE;
[email protected]07afd7c2011-02-17 10:07:11887 browser::Navigate(&p);
888
889 // Last tab should still be selected.
890 EXPECT_EQ(browser(), p.browser);
891 EXPECT_EQ(initial_tab_count + 1, browser()->tab_count());
[email protected]1ea49d52011-04-12 17:44:44892 EXPECT_EQ(initial_tab_count, browser()->active_index());
[email protected]07afd7c2011-02-17 10:07:11893}
894
[email protected]bd817c22011-02-09 08:16:46895// This test verifies that the settings page isn't opened in the incognito
896// window.
897IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
898 Disposition_Settings_UseNonIncognitoWindow) {
899 Browser* incognito_browser = CreateIncognitoBrowser();
900
901 EXPECT_EQ(2u, BrowserList::size());
902 EXPECT_EQ(1, browser()->tab_count());
903 EXPECT_EQ(1, incognito_browser->tab_count());
904
905 // Navigate to the settings page.
906 browser::NavigateParams p(MakeNavigateParams(incognito_browser));
907 p.disposition = SINGLETON_TAB;
[email protected]ddddfda2011-07-14 23:19:39908 p.url = GetSettingsURL();
[email protected]7d329992011-04-15 18:20:02909 p.window_action = browser::NavigateParams::SHOW_WINDOW;
[email protected]bd817c22011-02-09 08:16:46910 browser::Navigate(&p);
911
912 // The settings page should be opened in browser() window.
913 EXPECT_NE(incognito_browser, p.browser);
914 EXPECT_EQ(browser(), p.browser);
915 EXPECT_EQ(2, browser()->tab_count());
[email protected]ddddfda2011-07-14 23:19:39916 EXPECT_EQ(GetSettingsURL(),
[email protected]bd817c22011-02-09 08:16:46917 browser()->GetSelectedTabContents()->GetURL());
918}
919
[email protected]82404cd2011-07-12 19:55:14920// This test verifies that the settings page isn't opened in the incognito
921// window from a non-incognito window (bookmark open-in-incognito trigger).
922IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
923 Disposition_Settings_UseNonIncognitoWindowForBookmark) {
924 browser::NavigateParams params(browser(), GURL("chrome://settings"),
[email protected]2905f742011-10-13 03:51:58925 content::PAGE_TRANSITION_AUTO_BOOKMARK);
[email protected]82404cd2011-07-12 19:55:14926 params.disposition = OFF_THE_RECORD;
927 {
928 ui_test_utils::WindowedNotificationObserver observer(
[email protected]ad50def52011-10-19 23:17:07929 content::NOTIFICATION_LOAD_STOP,
930 content::NotificationService::AllSources());
[email protected]82404cd2011-07-12 19:55:14931 browser::Navigate(&params);
932 observer.Wait();
933 }
934
935 EXPECT_EQ(1u, BrowserList::size());
936 EXPECT_EQ(GURL("chrome://settings"),
937 browser()->GetSelectedTabContents()->GetURL().GetOrigin());
938}
939
[email protected]93ad8e1c2011-11-08 21:34:05940// Settings page is expected to always open in normal mode regardless
941// of whether the user is trying to open it in incognito mode or not.
942// This test verifies that if incognito mode is forced (by policy), settings
943// page doesn't open at all.
944IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
945 Disposition_Settings_DoNothingIfIncognitoIsForced) {
946 Browser* browser = CreateIncognitoBrowser();
947
948 // Set kIncognitoModeAvailability to FORCED.
949 PrefService* prefs1 = browser->profile()->GetPrefs();
950 prefs1->SetInteger(prefs::kIncognitoModeAvailability,
951 IncognitoModePrefs::FORCED);
952 PrefService* prefs2 = browser->profile()->GetOriginalProfile()->GetPrefs();
953 prefs2->SetInteger(prefs::kIncognitoModeAvailability,
954 IncognitoModePrefs::FORCED);
955
956 // Navigate to the settings page.
957 browser::NavigateParams p(MakeNavigateParams(browser));
958 p.disposition = OFF_THE_RECORD;
959 p.url = GURL(chrome::kChromeUISettingsURL);
960 p.window_action = browser::NavigateParams::SHOW_WINDOW;
961 browser::Navigate(&p);
962
963 // The bookmarks page should be opened in browser() window.
964 EXPECT_EQ(browser, p.browser);
965 EXPECT_EQ(1, browser->tab_count());
966 EXPECT_EQ(GURL(chrome::kAboutBlankURL),
967 browser->GetSelectedTabContents()->GetURL());
968}
969
[email protected]bd817c22011-02-09 08:16:46970// This test verifies that the bookmarks page isn't opened in the incognito
971// window.
972IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
973 Disposition_Bookmarks_UseNonIncognitoWindow) {
974 Browser* incognito_browser = CreateIncognitoBrowser();
975
976 EXPECT_EQ(2u, BrowserList::size());
977 EXPECT_EQ(1, browser()->tab_count());
978 EXPECT_EQ(1, incognito_browser->tab_count());
979
980 // Navigate to the settings page.
981 browser::NavigateParams p(MakeNavigateParams(incognito_browser));
982 p.disposition = SINGLETON_TAB;
[email protected]ddddfda2011-07-14 23:19:39983 p.url = GURL(chrome::kChromeUIBookmarksURL);
[email protected]7d329992011-04-15 18:20:02984 p.window_action = browser::NavigateParams::SHOW_WINDOW;
[email protected]bd817c22011-02-09 08:16:46985 browser::Navigate(&p);
986
987 // The bookmarks page should be opened in browser() window.
988 EXPECT_NE(incognito_browser, p.browser);
989 EXPECT_EQ(browser(), p.browser);
990 EXPECT_EQ(2, browser()->tab_count());
[email protected]ddddfda2011-07-14 23:19:39991 EXPECT_EQ(GURL(chrome::kChromeUIBookmarksURL),
[email protected]bd817c22011-02-09 08:16:46992 browser()->GetSelectedTabContents()->GetURL());
993}
994
[email protected]93ad8e1c2011-11-08 21:34:05995// Bookmark manager is expected to always open in normal mode regardless
996// of whether the user is trying to open it in incognito mode or not.
997// This test verifies that if incognito mode is forced (by policy), bookmark
998// manager doesn't open at all.
999IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
1000 Disposition_Bookmarks_DoNothingIfIncognitoIsForced) {
1001 Browser* browser = CreateIncognitoBrowser();
1002
1003 // Set kIncognitoModeAvailability to FORCED.
1004 PrefService* prefs1 = browser->profile()->GetPrefs();
1005 prefs1->SetInteger(prefs::kIncognitoModeAvailability,
1006 IncognitoModePrefs::FORCED);
1007 PrefService* prefs2 = browser->profile()->GetOriginalProfile()->GetPrefs();
1008 prefs2->SetInteger(prefs::kIncognitoModeAvailability,
1009 IncognitoModePrefs::FORCED);
1010
1011 // Navigate to the settings page.
1012 browser::NavigateParams p(MakeNavigateParams(browser));
1013 p.disposition = SINGLETON_TAB;
1014 p.url = GURL(chrome::kChromeUISettingsURL);
1015 p.window_action = browser::NavigateParams::SHOW_WINDOW;
1016 browser::Navigate(&p);
1017
1018 // The bookmarks page should be opened in browser() window.
1019 EXPECT_EQ(browser, p.browser);
1020 EXPECT_EQ(1, browser->tab_count());
1021 EXPECT_EQ(GURL(chrome::kAboutBlankURL),
1022 browser->GetSelectedTabContents()->GetURL());
1023}
1024
[email protected]7de53c62011-05-13 06:44:161025// This test makes sure a crashed singleton tab reloads from a new navigation.
1026IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
1027 NavigateToCrashedSingletonTab) {
[email protected]ddddfda2011-07-14 23:19:391028 GURL singleton_url(GetSettingsAdvancedURL());
[email protected]2905f742011-10-13 03:51:581029 TabContentsWrapper* wrapper = browser()->AddSelectedTabWithURL(
1030 singleton_url, content::PAGE_TRANSITION_LINK);
[email protected]7de53c62011-05-13 06:44:161031 TabContents* tab_contents = wrapper->tab_contents();
1032
1033 // We should have one browser with 2 tabs, the 2nd selected.
1034 EXPECT_EQ(1u, BrowserList::size());
1035 EXPECT_EQ(2, browser()->tab_count());
1036 EXPECT_EQ(1, browser()->active_index());
1037
1038 // Kill the singleton tab.
1039 tab_contents->SetIsCrashed(base::TERMINATION_STATUS_PROCESS_CRASHED, -1);
1040 EXPECT_TRUE(tab_contents->is_crashed());
1041
1042 browser::NavigateParams p(MakeNavigateParams());
1043 p.disposition = SINGLETON_TAB;
1044 p.url = singleton_url;
1045 p.window_action = browser::NavigateParams::SHOW_WINDOW;
1046 p.path_behavior = browser::NavigateParams::IGNORE_AND_NAVIGATE;
[email protected]ddddfda2011-07-14 23:19:391047 ui_test_utils::NavigateToURL(&p);
[email protected]7de53c62011-05-13 06:44:161048
1049 // The tab should not be sad anymore.
1050 EXPECT_FALSE(tab_contents->is_crashed());
1051}
1052
[email protected]fcca741b2011-06-17 22:46:371053IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
1054 NavigateFromDefaultToOptionsInSameTab) {
[email protected]ddddfda2011-07-14 23:19:391055 {
1056 ui_test_utils::WindowedNotificationObserver observer(
[email protected]ad50def52011-10-19 23:17:071057 content::NOTIFICATION_LOAD_STOP,
1058 content::NotificationService::AllSources());
[email protected]ddddfda2011-07-14 23:19:391059 browser()->OpenOptionsDialog();
1060 observer.Wait();
1061 }
[email protected]fcca741b2011-06-17 22:46:371062 EXPECT_EQ(1, browser()->tab_count());
[email protected]ddddfda2011-07-14 23:19:391063 EXPECT_EQ(GetSettingsURL(),
1064 browser()->GetSelectedTabContents()->GetURL().GetOrigin());
[email protected]fcca741b2011-06-17 22:46:371065}
1066
1067IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
1068 NavigateFromBlankToOptionsInSameTab) {
1069 browser::NavigateParams p(MakeNavigateParams());
[email protected]ddddfda2011-07-14 23:19:391070 p.url = GURL(chrome::kAboutBlankURL);
1071 ui_test_utils::NavigateToURL(&p);
[email protected]fcca741b2011-06-17 22:46:371072
[email protected]ddddfda2011-07-14 23:19:391073 {
1074 ui_test_utils::WindowedNotificationObserver observer(
[email protected]ad50def52011-10-19 23:17:071075 content::NOTIFICATION_LOAD_STOP,
1076 content::NotificationService::AllSources());
[email protected]ddddfda2011-07-14 23:19:391077 browser()->OpenOptionsDialog();
1078 observer.Wait();
1079 }
[email protected]fcca741b2011-06-17 22:46:371080 EXPECT_EQ(1, browser()->tab_count());
[email protected]ddddfda2011-07-14 23:19:391081 EXPECT_EQ(GetSettingsURL(),
1082 browser()->GetSelectedTabContents()->GetURL().GetOrigin());
[email protected]fcca741b2011-06-17 22:46:371083}
1084
1085IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
1086 NavigateFromNTPToOptionsInSameTab) {
1087 browser::NavigateParams p(MakeNavigateParams());
[email protected]ddddfda2011-07-14 23:19:391088 p.url = GURL(chrome::kChromeUINewTabURL);
1089 ui_test_utils::NavigateToURL(&p);
[email protected]fcca741b2011-06-17 22:46:371090 EXPECT_EQ(1, browser()->tab_count());
[email protected]ddddfda2011-07-14 23:19:391091 EXPECT_EQ(GURL(chrome::kChromeUINewTabURL),
[email protected]fcca741b2011-06-17 22:46:371092 browser()->GetSelectedTabContents()->GetURL());
1093
[email protected]ddddfda2011-07-14 23:19:391094 {
1095 ui_test_utils::WindowedNotificationObserver observer(
[email protected]ad50def52011-10-19 23:17:071096 content::NOTIFICATION_LOAD_STOP,
1097 content::NotificationService::AllSources());
[email protected]ddddfda2011-07-14 23:19:391098 browser()->OpenOptionsDialog();
1099 observer.Wait();
1100 }
[email protected]fcca741b2011-06-17 22:46:371101 EXPECT_EQ(1, browser()->tab_count());
[email protected]ddddfda2011-07-14 23:19:391102 EXPECT_EQ(GetSettingsURL(),
1103 browser()->GetSelectedTabContents()->GetURL().GetOrigin());
[email protected]fcca741b2011-06-17 22:46:371104}
1105
1106IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
1107 NavigateFromPageToOptionsInNewTab) {
1108 browser::NavigateParams p(MakeNavigateParams());
[email protected]ddddfda2011-07-14 23:19:391109 ui_test_utils::NavigateToURL(&p);
[email protected]fcca741b2011-06-17 22:46:371110 EXPECT_EQ(GetGoogleURL(), browser()->GetSelectedTabContents()->GetURL());
1111 EXPECT_EQ(1u, BrowserList::size());
1112 EXPECT_EQ(1, browser()->tab_count());
1113
[email protected]ddddfda2011-07-14 23:19:391114 {
1115 ui_test_utils::WindowedNotificationObserver observer(
[email protected]ad50def52011-10-19 23:17:071116 content::NOTIFICATION_LOAD_STOP,
1117 content::NotificationService::AllSources());
[email protected]ddddfda2011-07-14 23:19:391118 browser()->OpenOptionsDialog();
1119 observer.Wait();
1120 }
[email protected]fcca741b2011-06-17 22:46:371121 EXPECT_EQ(2, browser()->tab_count());
[email protected]ddddfda2011-07-14 23:19:391122 EXPECT_EQ(GetSettingsURL(),
1123 browser()->GetSelectedTabContents()->GetURL().GetOrigin());
[email protected]fcca741b2011-06-17 22:46:371124}
1125
1126IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
1127 NavigateFromNTPToOptionsSingleton) {
[email protected]ddddfda2011-07-14 23:19:391128 {
1129 ui_test_utils::WindowedNotificationObserver observer(
[email protected]ad50def52011-10-19 23:17:071130 content::NOTIFICATION_LOAD_STOP,
1131 content::NotificationService::AllSources());
[email protected]ddddfda2011-07-14 23:19:391132 browser()->OpenOptionsDialog();
1133 observer.Wait();
1134 }
[email protected]fcca741b2011-06-17 22:46:371135 EXPECT_EQ(1, browser()->tab_count());
1136
1137 browser()->NewTab();
1138 EXPECT_EQ(2, browser()->tab_count());
1139
[email protected]ddddfda2011-07-14 23:19:391140 {
1141 ui_test_utils::WindowedNotificationObserver observer(
[email protected]ad50def52011-10-19 23:17:071142 content::NOTIFICATION_LOAD_STOP,
1143 content::NotificationService::AllSources());
[email protected]ddddfda2011-07-14 23:19:391144 browser()->OpenOptionsDialog();
1145 observer.Wait();
1146 }
[email protected]fcca741b2011-06-17 22:46:371147 EXPECT_EQ(2, browser()->tab_count());
[email protected]ddddfda2011-07-14 23:19:391148 EXPECT_EQ(GetSettingsURL(),
1149 browser()->GetSelectedTabContents()->GetURL().GetOrigin());
[email protected]fcca741b2011-06-17 22:46:371150}
1151
1152IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
1153 NavigateFromNTPToOptionsPageInSameTab) {
[email protected]ddddfda2011-07-14 23:19:391154 {
1155 ui_test_utils::WindowedNotificationObserver observer(
[email protected]ad50def52011-10-19 23:17:071156 content::NOTIFICATION_LOAD_STOP,
1157 content::NotificationService::AllSources());
[email protected]ddddfda2011-07-14 23:19:391158 browser()->ShowOptionsTab(chrome::kPersonalOptionsSubPage);
1159 observer.Wait();
1160 }
[email protected]fcca741b2011-06-17 22:46:371161 EXPECT_EQ(1, browser()->tab_count());
[email protected]ddddfda2011-07-14 23:19:391162 EXPECT_EQ(GetSettingsPersonalURL(),
[email protected]fcca741b2011-06-17 22:46:371163 browser()->GetSelectedTabContents()->GetURL());
1164
1165 browser()->NewTab();
1166 EXPECT_EQ(2, browser()->tab_count());
1167
[email protected]ddddfda2011-07-14 23:19:391168 {
1169 ui_test_utils::WindowedNotificationObserver observer(
[email protected]ad50def52011-10-19 23:17:071170 content::NOTIFICATION_LOAD_STOP,
1171 content::NotificationService::AllSources());
[email protected]ddddfda2011-07-14 23:19:391172 browser()->ShowOptionsTab(chrome::kPersonalOptionsSubPage);
1173 observer.Wait();
1174 }
[email protected]fcca741b2011-06-17 22:46:371175 EXPECT_EQ(2, browser()->tab_count());
[email protected]ddddfda2011-07-14 23:19:391176 EXPECT_EQ(GetSettingsPersonalURL(),
[email protected]fcca741b2011-06-17 22:46:371177 browser()->GetSelectedTabContents()->GetURL());
1178}
1179
1180IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
1181 NavigateFromOtherTabToSingletonOptions) {
[email protected]ddddfda2011-07-14 23:19:391182 {
1183 ui_test_utils::WindowedNotificationObserver observer(
[email protected]ad50def52011-10-19 23:17:071184 content::NOTIFICATION_LOAD_STOP,
1185 content::NotificationService::AllSources());
[email protected]ddddfda2011-07-14 23:19:391186 browser()->OpenOptionsDialog();
1187 observer.Wait();
1188 }
1189 {
1190 ui_test_utils::WindowedNotificationObserver observer(
[email protected]ad50def52011-10-19 23:17:071191 content::NOTIFICATION_LOAD_STOP,
1192 content::NotificationService::AllSources());
[email protected]2905f742011-10-13 03:51:581193 browser()->AddSelectedTabWithURL(
1194 GetGoogleURL(), content::PAGE_TRANSITION_LINK);
[email protected]ddddfda2011-07-14 23:19:391195 observer.Wait();
1196 }
[email protected]fcca741b2011-06-17 22:46:371197
[email protected]ddddfda2011-07-14 23:19:391198 {
1199 ui_test_utils::WindowedNotificationObserver observer(
[email protected]ad50def52011-10-19 23:17:071200 content::NOTIFICATION_LOAD_STOP,
1201 content::NotificationService::AllSources());
[email protected]ddddfda2011-07-14 23:19:391202 browser()->OpenOptionsDialog();
1203 observer.Wait();
1204 }
[email protected]fcca741b2011-06-17 22:46:371205 EXPECT_EQ(2, browser()->tab_count());
[email protected]ddddfda2011-07-14 23:19:391206 EXPECT_EQ(GetSettingsURL(),
1207 browser()->GetSelectedTabContents()->GetURL().GetOrigin());
[email protected]fcca741b2011-06-17 22:46:371208}
1209
[email protected]26c53e662011-07-09 02:21:021210// Tests that when a new tab is opened from the omnibox, the focus is moved from
1211// the omnibox for the current tab.
1212IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
1213 NavigateFromOmniboxIntoNewTab) {
1214 GURL url("http://www.google.com/");
1215 GURL url2("http://maps.google.com/");
1216
1217 // Navigate to url.
1218 browser::NavigateParams p(MakeNavigateParams());
1219 p.disposition = CURRENT_TAB;
1220 p.url = url;
1221 browser::Navigate(&p);
1222
1223 // Focus the omnibox.
1224 browser()->FocusLocationBar();
1225
1226 AutocompleteEditController* controller =
1227 browser()->window()->GetLocationBar()->location_entry()->model()->
1228 controller();
1229
1230 // Simulate an alt-enter.
1231 controller->OnAutocompleteAccept(url2, NEW_FOREGROUND_TAB,
[email protected]2905f742011-10-13 03:51:581232 content::PAGE_TRANSITION_TYPED, GURL());
[email protected]26c53e662011-07-09 02:21:021233
1234 // Make sure the second tab is selected.
1235 EXPECT_EQ(1, browser()->active_index());
1236
1237 // The tab contents should have the focus in the second tab.
1238 EXPECT_TRUE(ui_test_utils::IsViewFocused(browser(),
1239 VIEW_ID_TAB_CONTAINER_FOCUS_VIEW));
1240
1241 // Go back to the first tab. The focus should not be in the omnibox.
1242 browser()->SelectPreviousTab();
1243 EXPECT_EQ(0, browser()->active_index());
1244 EXPECT_FALSE(ui_test_utils::IsViewFocused(browser(),
1245 VIEW_ID_LOCATION_BAR));
1246}
1247
[email protected]ddddfda2011-07-14 23:19:391248IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
1249 NavigateFromDefaultToHistoryInSameTab) {
1250 {
1251 ui_test_utils::WindowedNotificationObserver observer(
[email protected]ad50def52011-10-19 23:17:071252 content::NOTIFICATION_LOAD_STOP,
1253 content::NotificationService::AllSources());
[email protected]ddddfda2011-07-14 23:19:391254 browser()->ShowHistoryTab();
1255 observer.Wait();
1256 }
1257 EXPECT_EQ(1, browser()->tab_count());
1258 EXPECT_EQ(GURL(chrome::kChromeUIHistoryURL),
1259 browser()->GetSelectedTabContents()->GetURL());
1260}
1261
1262IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
1263 NavigateFromDefaultToBookmarksInSameTab) {
1264 {
1265 ui_test_utils::WindowedNotificationObserver observer(
[email protected]ad50def52011-10-19 23:17:071266 content::NOTIFICATION_LOAD_STOP,
1267 content::NotificationService::AllSources());
[email protected]0af8f132011-07-16 01:37:021268 browser()->OpenBookmarkManager();
[email protected]ddddfda2011-07-14 23:19:391269 observer.Wait();
1270 }
1271 EXPECT_EQ(1, browser()->tab_count());
1272 EXPECT_EQ(GURL(chrome::kChromeUIBookmarksURL),
1273 browser()->GetSelectedTabContents()->GetURL());
1274}
1275
1276IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
1277 NavigateFromDefaultToDownloadsInSameTab) {
1278 {
1279 ui_test_utils::WindowedNotificationObserver observer(
[email protected]ad50def52011-10-19 23:17:071280 content::NOTIFICATION_LOAD_STOP,
1281 content::NotificationService::AllSources());
[email protected]ddddfda2011-07-14 23:19:391282 browser()->ShowDownloadsTab();
1283 observer.Wait();
1284 }
1285 EXPECT_EQ(1, browser()->tab_count());
1286 EXPECT_EQ(GURL(chrome::kChromeUIDownloadsURL),
1287 browser()->GetSelectedTabContents()->GetURL());
1288}
1289
1290} // namespace