blob: e44ad7b1956c3017f83e3aff071a6df02f05be4e [file] [log] [blame]
[email protected]8643e6d2012-01-18 20:26:101// Copyright (c) 2012 The Chromium Authors. All rights reserved.
[email protected]a1feae52010-10-11 22:14:452// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
[email protected]bd817c22011-02-09 08:16:465#include "chrome/browser/ui/browser_navigator_browsertest.h"
6
[email protected]bb89e7482010-11-17 18:27:047#include "base/command_line.h"
[email protected]26c53e662011-07-09 02:21:028#include "chrome/app/chrome_command_ids.h"
[email protected]93ad8e1c2011-11-08 21:34:059#include "chrome/browser/prefs/incognito_mode_prefs.h"
10#include "chrome/browser/prefs/pref_service.h"
[email protected]8ecad5e2010-12-02 21:18:3311#include "chrome/browser/profiles/profile.h"
[email protected]a37d4b02012-06-25 21:56:1012#include "chrome/browser/ui/browser_commands.h"
[email protected]bb89e7482010-11-17 18:27:0413#include "chrome/browser/ui/browser_list.h"
[email protected]339d6dd2010-11-12 00:41:5814#include "chrome/browser/ui/browser_navigator.h"
[email protected]bb89e7482010-11-17 18:27:0415#include "chrome/browser/ui/browser_window.h"
[email protected]5d9cace72012-06-21 16:07:1216#include "chrome/browser/ui/chrome_pages.h"
[email protected]26c53e662011-07-09 02:21:0217#include "chrome/browser/ui/omnibox/location_bar.h"
[email protected]fbdc4232012-06-24 15:28:3718#include "chrome/browser/ui/omnibox/omnibox_edit_controller.h"
19#include "chrome/browser/ui/omnibox/omnibox_edit_model.h"
[email protected]26c53e662011-07-09 02:21:0220#include "chrome/browser/ui/omnibox/omnibox_view.h"
[email protected]4ebab8ee2012-06-11 22:52:0121#include "chrome/browser/ui/tab_contents/tab_contents.h"
[email protected]b56e2e32012-05-11 21:18:0422#include "chrome/browser/ui/tabs/tab_strip_model.h"
[email protected]bb89e7482010-11-17 18:27:0423#include "chrome/common/chrome_switches.h"
[email protected]93ad8e1c2011-11-08 21:34:0524#include "chrome/common/pref_names.h"
[email protected]ddddfda2011-07-14 23:19:3925#include "chrome/common/url_constants.h"
[email protected]af44e7fb2011-07-29 18:32:3226#include "chrome/test/base/ui_test_utils.h"
[email protected]ad50def52011-10-19 23:17:0727#include "content/public/browser/notification_service.h"
[email protected]0d6e9bd2011-10-18 04:29:1628#include "content/public/browser/notification_types.h"
[email protected]83ff91c2012-01-05 20:54:1329#include "content/public/browser/web_contents.h"
[email protected]8643e6d2012-01-18 20:26:1030#include "content/public/browser/web_contents_view.h"
[email protected]c47317e2012-06-20 22:35:3131#include "ipc/ipc_message.h"
[email protected]a1feae52010-10-11 22:14:4532
[email protected]4ca15302012-01-03 05:53:2033using content::WebContents;
34
[email protected]ddddfda2011-07-14 23:19:3935namespace {
36
37GURL GetGoogleURL() {
[email protected]bd817c22011-02-09 08:16:4638 return GURL("http://www.google.com/");
39}
[email protected]a1feae52010-10-11 22:14:4540
[email protected]ddddfda2011-07-14 23:19:3941GURL GetSettingsURL() {
[email protected]a048ad22012-03-23 04:26:5642 return GURL(chrome::kChromeUIUberURL).Resolve(
43 chrome::kChromeUISettingsHost + std::string("/"));
[email protected]ddddfda2011-07-14 23:19:3944}
45
[email protected]a048ad22012-03-23 04:26:5646GURL GetContentSettingsURL() {
47 return GetSettingsURL().Resolve(chrome::kContentSettingsExceptionsSubPage);
[email protected]ddddfda2011-07-14 23:19:3948}
49
[email protected]a048ad22012-03-23 04:26:5650GURL GetClearBrowsingDataURL() {
51 return GetSettingsURL().Resolve(chrome::kClearBrowserDataSubPage);
[email protected]ddddfda2011-07-14 23:19:3952}
53
54} // namespace
55
[email protected]bd817c22011-02-09 08:16:4656browser::NavigateParams BrowserNavigatorTest::MakeNavigateParams() const {
57 return MakeNavigateParams(browser());
58}
[email protected]a1feae52010-10-11 22:14:4559
[email protected]bd817c22011-02-09 08:16:4660browser::NavigateParams BrowserNavigatorTest::MakeNavigateParams(
61 Browser* browser) const {
62 browser::NavigateParams params(browser, GetGoogleURL(),
[email protected]2905f742011-10-13 03:51:5863 content::PAGE_TRANSITION_LINK);
[email protected]7d329992011-04-15 18:20:0264 params.window_action = browser::NavigateParams::SHOW_WINDOW;
[email protected]bd817c22011-02-09 08:16:4665 return params;
66}
[email protected]a1feae52010-10-11 22:14:4567
[email protected]bd817c22011-02-09 08:16:4668Browser* BrowserNavigatorTest::CreateEmptyBrowserForType(Browser::Type type,
69 Profile* profile) {
[email protected]da22aa62012-04-04 18:54:3570 Browser* browser = Browser::CreateWithParams(
71 Browser::CreateParams(type, profile));
[email protected]bd817c22011-02-09 08:16:4672 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) {
[email protected]da22aa62012-04-04 18:54:3578 Browser* browser = Browser::CreateWithParams(
79 Browser::CreateParams::CreateForApp(
80 Browser::TYPE_POPUP, "Test", gfx::Rect(), profile));
[email protected]b35b26b32011-05-05 20:35:1481 browser->AddBlankTab(true);
82 return browser;
83}
84
[email protected]4ebab8ee2012-06-11 22:52:0185TabContents* BrowserNavigatorTest::CreateTabContents() {
[email protected]bd817c22011-02-09 08:16:4686 return Browser::TabContentsFactory(
87 browser()->profile(),
88 NULL,
89 MSG_ROUTING_NONE,
[email protected]4ebab8ee2012-06-11 22:52:0190 browser()->GetActiveWebContents(),
[email protected]bd817c22011-02-09 08:16:4691 NULL);
92}
[email protected]a1feae52010-10-11 22:14:4593
[email protected]bd817c22011-02-09 08:16:4694void BrowserNavigatorTest::RunSuppressTest(WindowOpenDisposition disposition) {
[email protected]4ebab8ee2012-06-11 22:52:0195 GURL old_url = browser()->GetActiveWebContents()->GetURL();
[email protected]bd817c22011-02-09 08:16:4696 browser::NavigateParams p(MakeNavigateParams());
97 p.disposition = disposition;
98 browser::Navigate(&p);
[email protected]a1feae52010-10-11 22:14:4599
[email protected]bd817c22011-02-09 08:16:46100 // Nothing should have happened as a result of Navigate();
101 EXPECT_EQ(1, browser()->tab_count());
102 EXPECT_EQ(1u, BrowserList::size());
[email protected]4ebab8ee2012-06-11 22:52:01103 EXPECT_EQ(old_url, browser()->GetActiveWebContents()->GetURL());
[email protected]bd817c22011-02-09 08:16:46104}
[email protected]bb89e7482010-11-17 18:27:04105
[email protected]fc0ed302011-11-29 23:17:19106void BrowserNavigatorTest::RunUseNonIncognitoWindowTest(const GURL& url) {
107 Browser* incognito_browser = CreateIncognitoBrowser();
108
109 EXPECT_EQ(2u, BrowserList::size());
110 EXPECT_EQ(1, browser()->tab_count());
111 EXPECT_EQ(1, incognito_browser->tab_count());
112
113 // Navigate to the page.
114 browser::NavigateParams p(MakeNavigateParams(incognito_browser));
115 p.disposition = SINGLETON_TAB;
116 p.url = url;
117 p.window_action = browser::NavigateParams::SHOW_WINDOW;
118 browser::Navigate(&p);
119
120 // This page should be opened in browser() window.
121 EXPECT_NE(incognito_browser, p.browser);
122 EXPECT_EQ(browser(), p.browser);
123 EXPECT_EQ(2, browser()->tab_count());
[email protected]4ebab8ee2012-06-11 22:52:01124 EXPECT_EQ(url, browser()->GetActiveWebContents()->GetURL());
[email protected]fc0ed302011-11-29 23:17:19125}
126
127void BrowserNavigatorTest::RunDoNothingIfIncognitoIsForcedTest(
128 const GURL& url) {
129 Browser* browser = CreateIncognitoBrowser();
130
131 // Set kIncognitoModeAvailability to FORCED.
132 PrefService* prefs1 = browser->profile()->GetPrefs();
133 prefs1->SetInteger(prefs::kIncognitoModeAvailability,
134 IncognitoModePrefs::FORCED);
135 PrefService* prefs2 = browser->profile()->GetOriginalProfile()->GetPrefs();
136 prefs2->SetInteger(prefs::kIncognitoModeAvailability,
137 IncognitoModePrefs::FORCED);
138
139 // Navigate to the page.
140 browser::NavigateParams p(MakeNavigateParams(browser));
141 p.disposition = OFF_THE_RECORD;
142 p.url = url;
143 p.window_action = browser::NavigateParams::SHOW_WINDOW;
144 browser::Navigate(&p);
145
146 // The page should not be opened.
147 EXPECT_EQ(browser, p.browser);
148 EXPECT_EQ(1, browser->tab_count());
149 EXPECT_EQ(GURL(chrome::kAboutBlankURL),
[email protected]4ebab8ee2012-06-11 22:52:01150 browser->GetActiveWebContents()->GetURL());
[email protected]fc0ed302011-11-29 23:17:19151}
152
[email protected]6c2381d2011-10-19 02:52:53153void BrowserNavigatorTest::Observe(
154 int type,
155 const content::NotificationSource& source,
156 const content::NotificationDetails& details) {
[email protected]432115822011-07-10 15:52:27157 switch (type) {
158 case content::NOTIFICATION_RENDER_VIEW_HOST_CREATED_FOR_TAB: {
[email protected]bd817c22011-02-09 08:16:46159 ++this->created_tab_contents_count_;
160 break;
[email protected]fa7ebe02010-11-29 23:04:57161 }
[email protected]bd817c22011-02-09 08:16:46162 default:
163 break;
[email protected]fa7ebe02010-11-29 23:04:57164 }
[email protected]bd817c22011-02-09 08:16:46165}
[email protected]fa7ebe02010-11-29 23:04:57166
[email protected]ddddfda2011-07-14 23:19:39167
[email protected]bd817c22011-02-09 08:16:46168namespace {
[email protected]a1feae52010-10-11 22:14:45169
[email protected]a1feae52010-10-11 22:14:45170// This test verifies that when a navigation occurs within a tab, the tab count
171// of the Browser remains the same and the current tab bears the loaded URL.
172IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_CurrentTab) {
[email protected]ddddfda2011-07-14 23:19:39173 ui_test_utils::NavigateToURL(browser(), GetGoogleURL());
[email protected]4ebab8ee2012-06-11 22:52:01174 EXPECT_EQ(GetGoogleURL(), browser()->GetActiveWebContents()->GetURL());
[email protected]a1feae52010-10-11 22:14:45175 // We should have one window with one tab.
176 EXPECT_EQ(1u, BrowserList::size());
177 EXPECT_EQ(1, browser()->tab_count());
178}
179
[email protected]bd817c22011-02-09 08:16:46180// This test verifies that a singleton tab is refocused if one is already opened
[email protected]19d9f3a2010-10-14 21:49:36181// in another or an existing window, or added if it is not.
182IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_SingletonTabExisting) {
[email protected]19d9f3a2010-10-14 21:49:36183 GURL singleton_url1("http://maps.google.com/");
[email protected]fa7ebe02010-11-29 23:04:57184
185 // Register for a notification if an additional tab_contents was instantiated.
[email protected]bd817c22011-02-09 08:16:46186 // Opening a Singleton tab that is already opened should not be opening a new
[email protected]4ebab8ee2012-06-11 22:52:01187 // tab nor be creating a new TabContents object.
[email protected]6c2381d2011-10-19 02:52:53188 content::NotificationRegistrar registrar;
[email protected]fa7ebe02010-11-29 23:04:57189
190 // As the registrar object goes out of scope, this will get unregistered
[email protected]432115822011-07-10 15:52:27191 registrar.Add(this, content::NOTIFICATION_RENDER_VIEW_HOST_CREATED_FOR_TAB,
[email protected]ad50def52011-10-19 23:17:07192 content::NotificationService::AllSources());
[email protected]fa7ebe02010-11-29 23:04:57193
[email protected]2905f742011-10-13 03:51:58194 browser()->AddSelectedTabWithURL(
195 singleton_url1, content::PAGE_TRANSITION_LINK);
196 browser()->AddSelectedTabWithURL(
197 GetGoogleURL(), content::PAGE_TRANSITION_LINK);
[email protected]19d9f3a2010-10-14 21:49:36198
199 // We should have one browser with 3 tabs, the 3rd selected.
200 EXPECT_EQ(1u, BrowserList::size());
[email protected]1ea49d52011-04-12 17:44:44201 EXPECT_EQ(2, browser()->active_index());
[email protected]19d9f3a2010-10-14 21:49:36202
[email protected]fa7ebe02010-11-29 23:04:57203 unsigned int previous_tab_contents_count =
204 created_tab_contents_count_ = 0;
205
[email protected]19d9f3a2010-10-14 21:49:36206 // Navigate to singleton_url1.
207 browser::NavigateParams p(MakeNavigateParams());
208 p.disposition = SINGLETON_TAB;
209 p.url = singleton_url1;
210 browser::Navigate(&p);
211
212 // The middle tab should now be selected.
213 EXPECT_EQ(browser(), p.browser);
[email protected]1ea49d52011-04-12 17:44:44214 EXPECT_EQ(1, browser()->active_index());
[email protected]fa7ebe02010-11-29 23:04:57215
216 // No tab contents should have been created
217 EXPECT_EQ(previous_tab_contents_count,
218 created_tab_contents_count_);
[email protected]19d9f3a2010-10-14 21:49:36219}
220
221IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
[email protected]578c6962011-08-24 22:06:40222 Disposition_SingletonTabRespectingRef) {
223 GURL singleton_ref_url1("http://maps.google.com/#a");
224 GURL singleton_ref_url2("http://maps.google.com/#b");
225 GURL singleton_ref_url3("http://maps.google.com/");
226
[email protected]2905f742011-10-13 03:51:58227 browser()->AddSelectedTabWithURL(
228 singleton_ref_url1, content::PAGE_TRANSITION_LINK);
[email protected]578c6962011-08-24 22:06:40229
230 // We should have one browser with 2 tabs, 2nd selected.
231 EXPECT_EQ(1u, BrowserList::size());
232 EXPECT_EQ(2, browser()->tab_count());
233 EXPECT_EQ(1, browser()->active_index());
234
235 // Navigate to singleton_url2.
236 browser::NavigateParams p(MakeNavigateParams());
237 p.disposition = SINGLETON_TAB;
238 p.url = singleton_ref_url2;
239 browser::Navigate(&p);
240
241 // We should now have 2 tabs, the 2nd one selected.
242 EXPECT_EQ(browser(), p.browser);
243 EXPECT_EQ(2, browser()->tab_count());
244 EXPECT_EQ(1, browser()->active_index());
245
246 // Navigate to singleton_url2, but with respect ref set.
247 p = MakeNavigateParams();
248 p.disposition = SINGLETON_TAB;
249 p.url = singleton_ref_url2;
250 p.ref_behavior = browser::NavigateParams::RESPECT_REF;
251 browser::Navigate(&p);
252
253 // We should now have 3 tabs, the 3th one selected.
254 EXPECT_EQ(browser(), p.browser);
255 EXPECT_EQ(3, browser()->tab_count());
256 EXPECT_EQ(2, browser()->active_index());
257
258 // Navigate to singleton_url3.
259 p = MakeNavigateParams();
260 p.disposition = SINGLETON_TAB;
261 p.url = singleton_ref_url3;
262 p.ref_behavior = browser::NavigateParams::RESPECT_REF;
263 browser::Navigate(&p);
264
265 // We should now have 4 tabs, the 4th one selected.
266 EXPECT_EQ(browser(), p.browser);
267 EXPECT_EQ(4, browser()->tab_count());
268 EXPECT_EQ(3, browser()->active_index());
269}
270
271IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
[email protected]19d9f3a2010-10-14 21:49:36272 Disposition_SingletonTabNoneExisting) {
[email protected]19d9f3a2010-10-14 21:49:36273 GURL singleton_url1("http://maps.google.com/");
274
[email protected]bd817c22011-02-09 08:16:46275 // We should have one browser with 1 tab.
[email protected]19d9f3a2010-10-14 21:49:36276 EXPECT_EQ(1u, BrowserList::size());
[email protected]1ea49d52011-04-12 17:44:44277 EXPECT_EQ(0, browser()->active_index());
[email protected]19d9f3a2010-10-14 21:49:36278
279 // Navigate to singleton_url1.
280 browser::NavigateParams p(MakeNavigateParams());
281 p.disposition = SINGLETON_TAB;
282 p.url = singleton_url1;
283 browser::Navigate(&p);
284
285 // We should now have 2 tabs, the 2nd one selected.
286 EXPECT_EQ(browser(), p.browser);
287 EXPECT_EQ(2, browser()->tab_count());
[email protected]1ea49d52011-04-12 17:44:44288 EXPECT_EQ(1, browser()->active_index());
[email protected]a1feae52010-10-11 22:14:45289}
290
291// This test verifies that when a navigation results in a foreground tab, the
292// tab count of the Browser increases and the selected tab shifts to the new
293// foreground tab.
294IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_NewForegroundTab) {
[email protected]4ebab8ee2012-06-11 22:52:01295 WebContents* old_contents = browser()->GetActiveWebContents();
[email protected]a1feae52010-10-11 22:14:45296 browser::NavigateParams p(MakeNavigateParams());
297 p.disposition = NEW_FOREGROUND_TAB;
[email protected]19d9f3a2010-10-14 21:49:36298 browser::Navigate(&p);
[email protected]4ebab8ee2012-06-11 22:52:01299 EXPECT_NE(old_contents, browser()->GetActiveWebContents());
300 EXPECT_EQ(browser()->GetActiveTabContents(), p.target_contents);
[email protected]a1feae52010-10-11 22:14:45301 EXPECT_EQ(2, browser()->tab_count());
302}
303
304// This test verifies that when a navigation results in a background tab, the
305// tab count of the Browser increases but the selected tab remains the same.
306IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_NewBackgroundTab) {
[email protected]4ebab8ee2012-06-11 22:52:01307 WebContents* old_contents = browser()->GetActiveWebContents();
[email protected]a1feae52010-10-11 22:14:45308 browser::NavigateParams p(MakeNavigateParams());
309 p.disposition = NEW_BACKGROUND_TAB;
[email protected]19d9f3a2010-10-14 21:49:36310 browser::Navigate(&p);
[email protected]4ebab8ee2012-06-11 22:52:01311 WebContents* new_contents = browser()->GetActiveWebContents();
[email protected]a1feae52010-10-11 22:14:45312 // The selected tab should have remained unchanged, since the new tab was
313 // opened in the background.
314 EXPECT_EQ(old_contents, new_contents);
315 EXPECT_EQ(2, browser()->tab_count());
316}
317
318// This test verifies that when a navigation requiring a new foreground tab
319// occurs in a Browser that cannot host multiple tabs, the new foreground tab
320// is created in an existing compatible Browser.
321IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
322 Disposition_IncompatibleWindow_Existing) {
323 // Open a foreground tab in a window that cannot open popups when there is an
324 // existing compatible window somewhere else that they can be opened within.
325 Browser* popup = CreateEmptyBrowserForType(Browser::TYPE_POPUP,
326 browser()->profile());
327 browser::NavigateParams p(MakeNavigateParams(popup));
328 p.disposition = NEW_FOREGROUND_TAB;
[email protected]19d9f3a2010-10-14 21:49:36329 browser::Navigate(&p);
[email protected]a1feae52010-10-11 22:14:45330
331 // Navigate() should have opened the tab in a different browser since the
332 // one we supplied didn't support additional tabs.
333 EXPECT_NE(popup, p.browser);
334
335 // Since browser() is an existing compatible tabbed browser, it should have
336 // opened the tab there.
337 EXPECT_EQ(browser(), p.browser);
338
339 // We should be left with 2 windows, the popup with one tab and the browser()
340 // provided by the framework with two.
341 EXPECT_EQ(2u, BrowserList::size());
342 EXPECT_EQ(1, popup->tab_count());
343 EXPECT_EQ(2, browser()->tab_count());
344}
345
346// This test verifies that when a navigation requiring a new foreground tab
347// occurs in a Browser that cannot host multiple tabs and no compatible Browser
348// that can is open, a compatible Browser is created.
349IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
350 Disposition_IncompatibleWindow_NoExisting) {
351 // We want to simulate not being able to find an existing window compatible
352 // with our non-tabbed browser window so Navigate() is forced to create a
353 // new compatible window. Because browser() supplied by the in-process
354 // browser testing framework is compatible with browser()->profile(), we
355 // need a different profile, and creating a popup window with an incognito
356 // profile is a quick and dirty way of achieving this.
357 Browser* popup = CreateEmptyBrowserForType(
[email protected]b35b26b32011-05-05 20:35:14358 Browser::TYPE_POPUP,
359 browser()->profile()->GetOffTheRecordProfile());
[email protected]a1feae52010-10-11 22:14:45360 browser::NavigateParams p(MakeNavigateParams(popup));
361 p.disposition = NEW_FOREGROUND_TAB;
[email protected]19d9f3a2010-10-14 21:49:36362 browser::Navigate(&p);
[email protected]a1feae52010-10-11 22:14:45363
364 // Navigate() should have opened the tab in a different browser since the
365 // one we supplied didn't support additional tabs.
366 EXPECT_NE(popup, p.browser);
367
368 // This time, browser() is _not_ compatible with popup since it is not an
369 // incognito window.
370 EXPECT_NE(browser(), p.browser);
371
372 // We should have three windows, each with one tab:
373 // 1. the browser() provided by the framework (unchanged in this test)
374 // 2. the incognito popup we created originally
375 // 3. the new incognito tabbed browser that was created by Navigate().
376 EXPECT_EQ(3u, BrowserList::size());
377 EXPECT_EQ(1, browser()->tab_count());
378 EXPECT_EQ(1, popup->tab_count());
379 EXPECT_EQ(1, p.browser->tab_count());
[email protected]b35b26b32011-05-05 20:35:14380 EXPECT_TRUE(p.browser->is_type_tabbed());
[email protected]a1feae52010-10-11 22:14:45381}
382
383// This test verifies that navigating with WindowOpenDisposition = NEW_POPUP
384// from a normal Browser results in a new Browser with TYPE_POPUP.
385IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_NewPopup) {
386 browser::NavigateParams p(MakeNavigateParams());
387 p.disposition = NEW_POPUP;
[email protected]588300d2011-04-28 21:06:35388 p.window_bounds = gfx::Rect(0, 0, 200, 200);
[email protected]7d329992011-04-15 18:20:02389 // Wait for new popup to to load and gain focus.
[email protected]ddddfda2011-07-14 23:19:39390 ui_test_utils::NavigateToURL(&p);
[email protected]a1feae52010-10-11 22:14:45391
[email protected]7d329992011-04-15 18:20:02392 // Navigate() should have opened a new, focused popup window.
[email protected]a1feae52010-10-11 22:14:45393 EXPECT_NE(browser(), p.browser);
[email protected]9db263a2011-04-15 20:53:47394#if 0
395 // TODO(stevenjb): Enable this test. See: crbug.com/79493
[email protected]7d329992011-04-15 18:20:02396 EXPECT_TRUE(p.browser->window()->IsActive());
397#endif
[email protected]b35b26b32011-05-05 20:35:14398 EXPECT_TRUE(p.browser->is_type_popup());
399 EXPECT_FALSE(p.browser->is_app());
[email protected]a1feae52010-10-11 22:14:45400
401 // We should have two windows, the browser() provided by the framework and the
402 // new popup window.
403 EXPECT_EQ(2u, BrowserList::size());
404 EXPECT_EQ(1, browser()->tab_count());
405 EXPECT_EQ(1, p.browser->tab_count());
406}
407
408// This test verifies that navigating with WindowOpenDisposition = NEW_POPUP
[email protected]f112b0f2011-05-26 01:53:52409// from a normal Browser results in a new Browser with is_app() true.
410IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_NewPopup_ExtensionId) {
411 browser::NavigateParams p(MakeNavigateParams());
412 p.disposition = NEW_POPUP;
413 p.extension_app_id = "extensionappid";
414 p.window_bounds = gfx::Rect(0, 0, 200, 200);
[email protected]f112b0f2011-05-26 01:53:52415 // Wait for new popup to to load and gain focus.
[email protected]ddddfda2011-07-14 23:19:39416 ui_test_utils::NavigateToURL(&p);
[email protected]f112b0f2011-05-26 01:53:52417
418 // Navigate() should have opened a new, focused popup window.
419 EXPECT_NE(browser(), p.browser);
420 EXPECT_TRUE(p.browser->is_type_popup());
421 EXPECT_TRUE(p.browser->is_app());
422
423 // We should have two windows, the browser() provided by the framework and the
424 // new popup window.
425 EXPECT_EQ(2u, BrowserList::size());
426 EXPECT_EQ(1, browser()->tab_count());
427 EXPECT_EQ(1, p.browser->tab_count());
428}
429
430// This test verifies that navigating with WindowOpenDisposition = NEW_POPUP
[email protected]300d1e52011-01-19 23:57:57431// from a normal popup results in a new Browser with TYPE_POPUP.
432IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_NewPopupFromPopup) {
433 // Open a popup.
434 browser::NavigateParams p1(MakeNavigateParams());
435 p1.disposition = NEW_POPUP;
[email protected]588300d2011-04-28 21:06:35436 p1.window_bounds = gfx::Rect(0, 0, 200, 200);
[email protected]300d1e52011-01-19 23:57:57437 browser::Navigate(&p1);
438 // Open another popup.
439 browser::NavigateParams p2(MakeNavigateParams(p1.browser));
440 p2.disposition = NEW_POPUP;
[email protected]588300d2011-04-28 21:06:35441 p2.window_bounds = gfx::Rect(0, 0, 200, 200);
[email protected]300d1e52011-01-19 23:57:57442 browser::Navigate(&p2);
443
444 // Navigate() should have opened a new normal popup window.
445 EXPECT_NE(p1.browser, p2.browser);
[email protected]b35b26b32011-05-05 20:35:14446 EXPECT_TRUE(p2.browser->is_type_popup());
447 EXPECT_FALSE(p2.browser->is_app());
[email protected]300d1e52011-01-19 23:57:57448
449 // We should have three windows, the browser() provided by the framework,
450 // the first popup window, and the second popup window.
451 EXPECT_EQ(3u, BrowserList::size());
452 EXPECT_EQ(1, browser()->tab_count());
453 EXPECT_EQ(1, p1.browser->tab_count());
454 EXPECT_EQ(1, p2.browser->tab_count());
455}
456
457// This test verifies that navigating with WindowOpenDisposition = NEW_POPUP
[email protected]a1feae52010-10-11 22:14:45458// from an app frame results in a new Browser with TYPE_APP_POPUP.
459IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
460 Disposition_NewPopupFromAppWindow) {
[email protected]b35b26b32011-05-05 20:35:14461 Browser* app_browser = CreateEmptyBrowserForApp(Browser::TYPE_TABBED,
462 browser()->profile());
[email protected]a1feae52010-10-11 22:14:45463 browser::NavigateParams p(MakeNavigateParams(app_browser));
464 p.disposition = NEW_POPUP;
[email protected]588300d2011-04-28 21:06:35465 p.window_bounds = gfx::Rect(0, 0, 200, 200);
[email protected]19d9f3a2010-10-14 21:49:36466 browser::Navigate(&p);
[email protected]a1feae52010-10-11 22:14:45467
468 // Navigate() should have opened a new popup app window.
469 EXPECT_NE(app_browser, p.browser);
470 EXPECT_NE(browser(), p.browser);
[email protected]b35b26b32011-05-05 20:35:14471 EXPECT_TRUE(p.browser->is_type_popup());
472 EXPECT_TRUE(p.browser->is_app());
[email protected]a1feae52010-10-11 22:14:45473
474 // We should now have three windows, the app window, the app popup it created,
475 // and the original browser() provided by the framework.
476 EXPECT_EQ(3u, BrowserList::size());
477 EXPECT_EQ(1, browser()->tab_count());
478 EXPECT_EQ(1, app_browser->tab_count());
479 EXPECT_EQ(1, p.browser->tab_count());
480}
481
482// This test verifies that navigating with WindowOpenDisposition = NEW_POPUP
[email protected]300d1e52011-01-19 23:57:57483// from an app popup results in a new Browser also of TYPE_APP_POPUP.
484IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
485 Disposition_NewPopupFromAppPopup) {
[email protected]b35b26b32011-05-05 20:35:14486 Browser* app_browser = CreateEmptyBrowserForApp(Browser::TYPE_TABBED,
487 browser()->profile());
[email protected]300d1e52011-01-19 23:57:57488 // Open an app popup.
489 browser::NavigateParams p1(MakeNavigateParams(app_browser));
490 p1.disposition = NEW_POPUP;
[email protected]588300d2011-04-28 21:06:35491 p1.window_bounds = gfx::Rect(0, 0, 200, 200);
[email protected]300d1e52011-01-19 23:57:57492 browser::Navigate(&p1);
493 // Now open another app popup.
494 browser::NavigateParams p2(MakeNavigateParams(p1.browser));
495 p2.disposition = NEW_POPUP;
[email protected]588300d2011-04-28 21:06:35496 p2.window_bounds = gfx::Rect(0, 0, 200, 200);
[email protected]300d1e52011-01-19 23:57:57497 browser::Navigate(&p2);
498
499 // Navigate() should have opened a new popup app window.
500 EXPECT_NE(browser(), p1.browser);
501 EXPECT_NE(p1.browser, p2.browser);
[email protected]b35b26b32011-05-05 20:35:14502 EXPECT_TRUE(p2.browser->is_type_popup());
503 EXPECT_TRUE(p2.browser->is_app());
[email protected]300d1e52011-01-19 23:57:57504
505 // We should now have four windows, the app window, the first app popup,
506 // the second app popup, and the original browser() provided by the framework.
507 EXPECT_EQ(4u, BrowserList::size());
508 EXPECT_EQ(1, browser()->tab_count());
509 EXPECT_EQ(1, app_browser->tab_count());
510 EXPECT_EQ(1, p1.browser->tab_count());
511 EXPECT_EQ(1, p2.browser->tab_count());
512}
513
514// This test verifies that navigating with WindowOpenDisposition = NEW_POPUP
[email protected]a1feae52010-10-11 22:14:45515// from an extension app tab results in a new Browser with TYPE_APP_POPUP.
516IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
517 Disposition_NewPopupFromExtensionApp) {
518 // TODO(beng): TBD.
519}
520
[email protected]7d329992011-04-15 18:20:02521// This test verifies that navigating with window_action = SHOW_WINDOW_INACTIVE
522// does not focus a new new popup window.
523IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_NewPopupUnfocused) {
524 browser::NavigateParams p(MakeNavigateParams());
525 p.disposition = NEW_POPUP;
[email protected]588300d2011-04-28 21:06:35526 p.window_bounds = gfx::Rect(0, 0, 200, 200);
[email protected]7d329992011-04-15 18:20:02527 p.window_action = browser::NavigateParams::SHOW_WINDOW_INACTIVE;
[email protected]7d329992011-04-15 18:20:02528 // Wait for new popup to load (and gain focus if the test fails).
[email protected]ddddfda2011-07-14 23:19:39529 ui_test_utils::NavigateToURL(&p);
[email protected]7d329992011-04-15 18:20:02530
531 // Navigate() should have opened a new, unfocused, popup window.
532 EXPECT_NE(browser(), p.browser);
533 EXPECT_EQ(Browser::TYPE_POPUP, p.browser->type());
[email protected]9db263a2011-04-15 20:53:47534#if 0
535// TODO(stevenjb): Enable this test. See: crbug.com/79493
[email protected]7d329992011-04-15 18:20:02536 EXPECT_FALSE(p.browser->window()->IsActive());
[email protected]7d329992011-04-15 18:20:02537#endif
[email protected]9db263a2011-04-15 20:53:47538}
[email protected]7d329992011-04-15 18:20:02539
[email protected]a1feae52010-10-11 22:14:45540// This test verifies that navigating with WindowOpenDisposition = NEW_WINDOW
541// always opens a new window.
542IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_NewWindow) {
543 browser::NavigateParams p(MakeNavigateParams());
544 p.disposition = NEW_WINDOW;
[email protected]19d9f3a2010-10-14 21:49:36545 browser::Navigate(&p);
[email protected]a1feae52010-10-11 22:14:45546
547 // Navigate() should have opened a new toplevel window.
548 EXPECT_NE(browser(), p.browser);
[email protected]b35b26b32011-05-05 20:35:14549 EXPECT_TRUE(p.browser->is_type_tabbed());
[email protected]a1feae52010-10-11 22:14:45550
551 // We should now have two windows, the browser() provided by the framework and
552 // the new normal window.
553 EXPECT_EQ(2u, BrowserList::size());
554 EXPECT_EQ(1, browser()->tab_count());
555 EXPECT_EQ(1, p.browser->tab_count());
556}
557
558// This test verifies that navigating with WindowOpenDisposition = INCOGNITO
559// opens a new incognito window if no existing incognito window is present.
560IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_Incognito) {
561 browser::NavigateParams p(MakeNavigateParams());
562 p.disposition = OFF_THE_RECORD;
[email protected]19d9f3a2010-10-14 21:49:36563 browser::Navigate(&p);
[email protected]a1feae52010-10-11 22:14:45564
565 // Navigate() should have opened a new toplevel incognito window.
566 EXPECT_NE(browser(), p.browser);
567 EXPECT_EQ(browser()->profile()->GetOffTheRecordProfile(),
568 p.browser->profile());
569
[email protected]d7ff3592010-11-30 21:50:46570 // |source_contents| should be set to NULL because the profile for the new
571 // page is different from the originating page.
572 EXPECT_EQ(NULL, p.source_contents);
573
[email protected]a1feae52010-10-11 22:14:45574 // We should now have two windows, the browser() provided by the framework and
575 // the new incognito window.
576 EXPECT_EQ(2u, BrowserList::size());
577 EXPECT_EQ(1, browser()->tab_count());
578 EXPECT_EQ(1, p.browser->tab_count());
579}
580
581// This test verifies that navigating with WindowOpenDisposition = INCOGNITO
582// reuses an existing incognito window when possible.
583IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_IncognitoRefocus) {
584 Browser* incognito_browser =
[email protected]b35b26b32011-05-05 20:35:14585 CreateEmptyBrowserForType(Browser::TYPE_TABBED,
[email protected]a1feae52010-10-11 22:14:45586 browser()->profile()->GetOffTheRecordProfile());
587 browser::NavigateParams p(MakeNavigateParams());
588 p.disposition = OFF_THE_RECORD;
[email protected]19d9f3a2010-10-14 21:49:36589 browser::Navigate(&p);
[email protected]a1feae52010-10-11 22:14:45590
591 // Navigate() should have opened a new tab in the existing incognito window.
592 EXPECT_NE(browser(), p.browser);
593 EXPECT_EQ(p.browser, incognito_browser);
594
595 // We should now have two windows, the browser() provided by the framework and
596 // the incognito window we opened earlier.
597 EXPECT_EQ(2u, BrowserList::size());
598 EXPECT_EQ(1, browser()->tab_count());
599 EXPECT_EQ(2, incognito_browser->tab_count());
600}
601
602// This test verifies that no navigation action occurs when
603// WindowOpenDisposition = SUPPRESS_OPEN.
604IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_SuppressOpen) {
605 RunSuppressTest(SUPPRESS_OPEN);
606}
607
608// This test verifies that no navigation action occurs when
609// WindowOpenDisposition = SAVE_TO_DISK.
610IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_SaveToDisk) {
611 RunSuppressTest(SAVE_TO_DISK);
612}
613
614// This test verifies that no navigation action occurs when
615// WindowOpenDisposition = IGNORE_ACTION.
616IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_IgnoreAction) {
617 RunSuppressTest(IGNORE_ACTION);
618}
619
[email protected]4ebab8ee2012-06-11 22:52:01620// This tests adding a foreground tab with a predefined TabContents.
[email protected]a1feae52010-10-11 22:14:45621IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, TargetContents_ForegroundTab) {
622 browser::NavigateParams p(MakeNavigateParams());
623 p.disposition = NEW_FOREGROUND_TAB;
624 p.target_contents = CreateTabContents();
[email protected]19d9f3a2010-10-14 21:49:36625 browser::Navigate(&p);
[email protected]a1feae52010-10-11 22:14:45626
627 // Navigate() should have opened the contents in a new foreground in the
628 // current Browser.
629 EXPECT_EQ(browser(), p.browser);
[email protected]4ebab8ee2012-06-11 22:52:01630 EXPECT_EQ(browser()->GetActiveTabContents(), p.target_contents);
[email protected]a1feae52010-10-11 22:14:45631
632 // We should have one window, with two tabs.
633 EXPECT_EQ(1u, BrowserList::size());
634 EXPECT_EQ(2, browser()->tab_count());
635}
636
637#if defined(OS_WIN)
[email protected]4ebab8ee2012-06-11 22:52:01638// This tests adding a popup with a predefined TabContents.
[email protected]76edb672011-03-04 21:48:39639IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, DISABLED_TargetContents_Popup) {
[email protected]a1feae52010-10-11 22:14:45640 browser::NavigateParams p(MakeNavigateParams());
641 p.disposition = NEW_POPUP;
642 p.target_contents = CreateTabContents();
643 p.window_bounds = gfx::Rect(10, 10, 500, 500);
[email protected]19d9f3a2010-10-14 21:49:36644 browser::Navigate(&p);
[email protected]a1feae52010-10-11 22:14:45645
646 // Navigate() should have opened a new popup window.
647 EXPECT_NE(browser(), p.browser);
[email protected]b35b26b32011-05-05 20:35:14648 EXPECT_TRUE(p.browser->is_type_popup());
649 EXPECT_FALSE(p.browser->is_app());
[email protected]a1feae52010-10-11 22:14:45650
651 // The web platform is weird. The window bounds specified in
652 // |p.window_bounds| are used as follows:
653 // - the origin is used to position the window
[email protected]4ebab8ee2012-06-11 22:52:01654 // - the size is used to size the TabContents of the window.
[email protected]a1feae52010-10-11 22:14:45655 // As such the position of the resulting window will always match
656 // p.window_bounds.origin(), but its size will not. We need to match
657 // the size against the selected tab's view's container size.
658 // Only Windows positions the window according to |p.window_bounds.origin()| -
659 // on Mac the window is offset from the opener and on Linux it always opens
660 // at 0,0.
661 EXPECT_EQ(p.window_bounds.origin(),
662 p.browser->window()->GetRestoredBounds().origin());
663 // All platforms should respect size however provided width > 400 (Mac has a
664 // minimum window width of 400).
665 EXPECT_EQ(p.window_bounds.size(),
[email protected]83ff91c2012-01-05 20:54:13666 p.target_contents->web_contents()->GetView()->GetContainerSize());
[email protected]a1feae52010-10-11 22:14:45667
668 // We should have two windows, the new popup and the browser() provided by the
669 // framework.
670 EXPECT_EQ(2u, BrowserList::size());
671 EXPECT_EQ(1, browser()->tab_count());
672 EXPECT_EQ(1, p.browser->tab_count());
673}
674#endif
675
676// This tests adding a tab at a specific index.
677IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Tabstrip_InsertAtIndex) {
678 // This is not meant to be a comprehensive test of whether or not the tab
679 // implementation of the browser observes the insertion index. That is
680 // covered by the unit tests for TabStripModel. This merely verifies that
681 // insertion index preference is reflected in common cases.
682 browser::NavigateParams p(MakeNavigateParams());
683 p.disposition = NEW_FOREGROUND_TAB;
684 p.tabstrip_index = 0;
685 p.tabstrip_add_types = TabStripModel::ADD_FORCE_INDEX;
[email protected]19d9f3a2010-10-14 21:49:36686 browser::Navigate(&p);
[email protected]a1feae52010-10-11 22:14:45687
688 // Navigate() should have inserted a new tab at slot 0 in the tabstrip.
689 EXPECT_EQ(browser(), p.browser);
[email protected]c0849252012-05-12 13:51:27690 EXPECT_EQ(0, browser()->tab_strip_model()->GetIndexOfTabContents(
[email protected]4ebab8ee2012-06-11 22:52:01691 static_cast<const TabContents*>(p.target_contents)));
[email protected]a1feae52010-10-11 22:14:45692
693 // We should have one window - the browser() provided by the framework.
694 EXPECT_EQ(1u, BrowserList::size());
695 EXPECT_EQ(2, browser()->tab_count());
696}
697
[email protected]2dd85482010-11-06 01:56:47698// This test verifies that constructing params with a NULL browser has
699// the same result as navigating to a new foreground tab in the (only)
700// active browser. Tests are the same as for Disposition_NewForegroundTab.
701IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, NullBrowser_NewForegroundTab) {
[email protected]4ebab8ee2012-06-11 22:52:01702 WebContents* old_contents = browser()->GetActiveWebContents();
[email protected]2dd85482010-11-06 01:56:47703 // Navigate with a NULL browser.
704 browser::NavigateParams p(MakeNavigateParams(NULL));
705 p.disposition = NEW_FOREGROUND_TAB;
706 p.profile = browser()->profile();
707 browser::Navigate(&p);
708
709 // Navigate() should have found browser() and create a new tab.
710 EXPECT_EQ(browser(), p.browser);
[email protected]4ebab8ee2012-06-11 22:52:01711 EXPECT_NE(old_contents, browser()->GetActiveWebContents());
712 EXPECT_EQ(browser()->GetActiveTabContents(), p.target_contents);
[email protected]2dd85482010-11-06 01:56:47713 EXPECT_EQ(2, browser()->tab_count());
714}
715
716// This test verifies that constructing params with a NULL browser and
717// a specific profile matches the specified profile.
[email protected]c8a31a72011-09-30 01:53:32718IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, NullBrowser_MatchProfile) {
[email protected]2dd85482010-11-06 01:56:47719 // Create a new browser with using the incognito profile.
720 Browser* incognito =
721 Browser::Create(browser()->profile()->GetOffTheRecordProfile());
722
723 // Navigate with a NULL browser and the incognito profile.
724 browser::NavigateParams p(MakeNavigateParams(NULL));
725 p.disposition = NEW_FOREGROUND_TAB;
726 p.profile = incognito->profile();
727 browser::Navigate(&p);
728
729 // Navigate() should have found incognito, not browser().
730 EXPECT_EQ(incognito, p.browser);
[email protected]4ebab8ee2012-06-11 22:52:01731 EXPECT_EQ(incognito->GetActiveTabContents(), p.target_contents);
[email protected]2dd85482010-11-06 01:56:47732 EXPECT_EQ(1, incognito->tab_count());
733}
734
735// This test verifies that constructing params with a NULL browser and
736// disposition = NEW_WINDOW always opens exactly one new window.
737IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, NullBrowser_NewWindow) {
738 browser::NavigateParams p(MakeNavigateParams(NULL));
739 p.disposition = NEW_WINDOW;
740 p.profile = browser()->profile();
741 browser::Navigate(&p);
742
743 // Navigate() should have created a new browser.
744 EXPECT_NE(browser(), p.browser);
[email protected]b35b26b32011-05-05 20:35:14745 EXPECT_TRUE( p.browser->is_type_tabbed());
[email protected]2dd85482010-11-06 01:56:47746
747 // We should now have two windows, the browser() provided by the framework and
748 // the new normal window.
749 EXPECT_EQ(2u, BrowserList::size());
750 EXPECT_EQ(1, browser()->tab_count());
751 EXPECT_EQ(1, p.browser->tab_count());
752}
753
[email protected]bb89e7482010-11-17 18:27:04754// This test verifies that constructing params with disposition = SINGLETON_TAB
[email protected]fee320542011-03-02 01:30:49755// and IGNORE_AND_NAVIGATE opens a new tab navigated to the specified URL if
[email protected]67ed83e2011-01-07 22:54:00756// no previous tab with that URL (minus the path) exists.
[email protected]bb89e7482010-11-17 18:27:04757IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
758 Disposition_SingletonTabNew_IgnorePath) {
[email protected]2905f742011-10-13 03:51:58759 browser()->AddSelectedTabWithURL(
760 GetGoogleURL(), content::PAGE_TRANSITION_LINK);
[email protected]bb89e7482010-11-17 18:27:04761
762 // We should have one browser with 2 tabs, the 2nd selected.
763 EXPECT_EQ(1u, BrowserList::size());
764 EXPECT_EQ(2, browser()->tab_count());
[email protected]1ea49d52011-04-12 17:44:44765 EXPECT_EQ(1, browser()->active_index());
[email protected]bb89e7482010-11-17 18:27:04766
767 // Navigate to a new singleton tab with a sub-page.
768 browser::NavigateParams p(MakeNavigateParams());
769 p.disposition = SINGLETON_TAB;
[email protected]a048ad22012-03-23 04:26:56770 p.url = GetContentSettingsURL();
[email protected]7d329992011-04-15 18:20:02771 p.window_action = browser::NavigateParams::SHOW_WINDOW;
[email protected]fee320542011-03-02 01:30:49772 p.path_behavior = browser::NavigateParams::IGNORE_AND_NAVIGATE;
[email protected]bb89e7482010-11-17 18:27:04773 browser::Navigate(&p);
774
775 // The last tab should now be selected and navigated to the sub-page of the
776 // URL.
777 EXPECT_EQ(browser(), p.browser);
778 EXPECT_EQ(3, browser()->tab_count());
[email protected]1ea49d52011-04-12 17:44:44779 EXPECT_EQ(2, browser()->active_index());
[email protected]a048ad22012-03-23 04:26:56780 EXPECT_EQ(GetContentSettingsURL(),
[email protected]4ebab8ee2012-06-11 22:52:01781 browser()->GetActiveWebContents()->GetURL());
[email protected]bb89e7482010-11-17 18:27:04782}
783
784// This test verifies that constructing params with disposition = SINGLETON_TAB
[email protected]fee320542011-03-02 01:30:49785// and IGNORE_AND_NAVIGATE opens an existing tab with the matching URL (minus
[email protected]bb89e7482010-11-17 18:27:04786// the path) which is navigated to the specified URL.
787IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
788 Disposition_SingletonTabExisting_IgnorePath) {
[email protected]ddddfda2011-07-14 23:19:39789 GURL singleton_url1(GetSettingsURL());
[email protected]2905f742011-10-13 03:51:58790 browser()->AddSelectedTabWithURL(
791 singleton_url1, content::PAGE_TRANSITION_LINK);
792 browser()->AddSelectedTabWithURL(
793 GetGoogleURL(), content::PAGE_TRANSITION_LINK);
[email protected]bb89e7482010-11-17 18:27:04794
795 // We should have one browser with 3 tabs, the 3rd selected.
796 EXPECT_EQ(1u, BrowserList::size());
797 EXPECT_EQ(3, browser()->tab_count());
[email protected]1ea49d52011-04-12 17:44:44798 EXPECT_EQ(2, browser()->active_index());
[email protected]bb89e7482010-11-17 18:27:04799
800 // Navigate to singleton_url1.
801 browser::NavigateParams p(MakeNavigateParams());
802 p.disposition = SINGLETON_TAB;
[email protected]a048ad22012-03-23 04:26:56803 p.url = GetContentSettingsURL();
[email protected]7d329992011-04-15 18:20:02804 p.window_action = browser::NavigateParams::SHOW_WINDOW;
[email protected]fee320542011-03-02 01:30:49805 p.path_behavior = browser::NavigateParams::IGNORE_AND_NAVIGATE;
[email protected]bb89e7482010-11-17 18:27:04806 browser::Navigate(&p);
807
808 // The middle tab should now be selected and navigated to the sub-page of the
809 // URL.
810 EXPECT_EQ(browser(), p.browser);
811 EXPECT_EQ(3, browser()->tab_count());
[email protected]1ea49d52011-04-12 17:44:44812 EXPECT_EQ(1, browser()->active_index());
[email protected]a048ad22012-03-23 04:26:56813 EXPECT_EQ(GetContentSettingsURL(),
[email protected]4ebab8ee2012-06-11 22:52:01814 browser()->GetActiveWebContents()->GetURL());
[email protected]bb89e7482010-11-17 18:27:04815}
816
817// This test verifies that constructing params with disposition = SINGLETON_TAB
[email protected]fee320542011-03-02 01:30:49818// and IGNORE_AND_NAVIGATE opens an existing tab with the matching URL (minus
[email protected]bb89e7482010-11-17 18:27:04819// the path) which is navigated to the specified URL.
820IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
821 Disposition_SingletonTabExistingSubPath_IgnorePath) {
[email protected]a048ad22012-03-23 04:26:56822 GURL singleton_url1(GetContentSettingsURL());
[email protected]2905f742011-10-13 03:51:58823 browser()->AddSelectedTabWithURL(
824 singleton_url1, content::PAGE_TRANSITION_LINK);
825 browser()->AddSelectedTabWithURL(
826 GetGoogleURL(), content::PAGE_TRANSITION_LINK);
[email protected]bb89e7482010-11-17 18:27:04827
828 // We should have one browser with 3 tabs, the 3rd selected.
829 EXPECT_EQ(1u, BrowserList::size());
830 EXPECT_EQ(3, browser()->tab_count());
[email protected]1ea49d52011-04-12 17:44:44831 EXPECT_EQ(2, browser()->active_index());
[email protected]bb89e7482010-11-17 18:27:04832
833 // Navigate to singleton_url1.
834 browser::NavigateParams p(MakeNavigateParams());
835 p.disposition = SINGLETON_TAB;
[email protected]a048ad22012-03-23 04:26:56836 p.url = GetClearBrowsingDataURL();
[email protected]7d329992011-04-15 18:20:02837 p.window_action = browser::NavigateParams::SHOW_WINDOW;
[email protected]fee320542011-03-02 01:30:49838 p.path_behavior = browser::NavigateParams::IGNORE_AND_NAVIGATE;
[email protected]bb89e7482010-11-17 18:27:04839 browser::Navigate(&p);
840
841 // The middle tab should now be selected and navigated to the sub-page of the
842 // URL.
843 EXPECT_EQ(browser(), p.browser);
844 EXPECT_EQ(3, browser()->tab_count());
[email protected]1ea49d52011-04-12 17:44:44845 EXPECT_EQ(1, browser()->active_index());
[email protected]a048ad22012-03-23 04:26:56846 EXPECT_EQ(GetClearBrowsingDataURL(),
[email protected]4ebab8ee2012-06-11 22:52:01847 browser()->GetActiveWebContents()->GetURL());
[email protected]bb89e7482010-11-17 18:27:04848}
[email protected]2dd85482010-11-06 01:56:47849
[email protected]637b3442011-01-10 23:31:48850// This test verifies that constructing params with disposition = SINGLETON_TAB
[email protected]fee320542011-03-02 01:30:49851// and IGNORE_AND_STAY_PUT opens an existing tab with the matching URL (minus
852// the path).
853IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
854 Disposition_SingletonTabExistingSubPath_IgnorePath2) {
[email protected]a048ad22012-03-23 04:26:56855 GURL singleton_url1(GetContentSettingsURL());
[email protected]2905f742011-10-13 03:51:58856 browser()->AddSelectedTabWithURL(
857 singleton_url1, content::PAGE_TRANSITION_LINK);
858 browser()->AddSelectedTabWithURL(
859 GetGoogleURL(), content::PAGE_TRANSITION_LINK);
[email protected]fee320542011-03-02 01:30:49860
861 // We should have one browser with 3 tabs, the 3rd selected.
862 EXPECT_EQ(1u, BrowserList::size());
863 EXPECT_EQ(3, browser()->tab_count());
[email protected]1ea49d52011-04-12 17:44:44864 EXPECT_EQ(2, browser()->active_index());
[email protected]fee320542011-03-02 01:30:49865
866 // Navigate to singleton_url1.
867 browser::NavigateParams p(MakeNavigateParams());
868 p.disposition = SINGLETON_TAB;
[email protected]a048ad22012-03-23 04:26:56869 p.url = GetClearBrowsingDataURL();
[email protected]7d329992011-04-15 18:20:02870 p.window_action = browser::NavigateParams::SHOW_WINDOW;
[email protected]fee320542011-03-02 01:30:49871 p.path_behavior = browser::NavigateParams::IGNORE_AND_STAY_PUT;
872 browser::Navigate(&p);
873
874 // The middle tab should now be selected.
875 EXPECT_EQ(browser(), p.browser);
876 EXPECT_EQ(3, browser()->tab_count());
[email protected]1ea49d52011-04-12 17:44:44877 EXPECT_EQ(1, browser()->active_index());
[email protected]fee320542011-03-02 01:30:49878 EXPECT_EQ(singleton_url1,
[email protected]4ebab8ee2012-06-11 22:52:01879 browser()->GetActiveWebContents()->GetURL());
[email protected]fee320542011-03-02 01:30:49880}
881
882// This test verifies that constructing params with disposition = SINGLETON_TAB
883// and IGNORE_AND_NAVIGATE will update the current tab's URL if the currently
[email protected]637b3442011-01-10 23:31:48884// selected tab is a match but has a different path.
885IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
886 Disposition_SingletonTabFocused_IgnorePath) {
[email protected]a048ad22012-03-23 04:26:56887 GURL singleton_url_current(GetContentSettingsURL());
[email protected]2905f742011-10-13 03:51:58888 browser()->AddSelectedTabWithURL(
889 singleton_url_current, content::PAGE_TRANSITION_LINK);
[email protected]637b3442011-01-10 23:31:48890
891 // We should have one browser with 2 tabs, the 2nd selected.
892 EXPECT_EQ(1u, BrowserList::size());
893 EXPECT_EQ(2, browser()->tab_count());
[email protected]1ea49d52011-04-12 17:44:44894 EXPECT_EQ(1, browser()->active_index());
[email protected]637b3442011-01-10 23:31:48895
896 // Navigate to a different settings path.
[email protected]a048ad22012-03-23 04:26:56897 GURL singleton_url_target(GetClearBrowsingDataURL());
[email protected]637b3442011-01-10 23:31:48898 browser::NavigateParams p(MakeNavigateParams());
899 p.disposition = SINGLETON_TAB;
900 p.url = singleton_url_target;
[email protected]7d329992011-04-15 18:20:02901 p.window_action = browser::NavigateParams::SHOW_WINDOW;
[email protected]fee320542011-03-02 01:30:49902 p.path_behavior = browser::NavigateParams::IGNORE_AND_NAVIGATE;
[email protected]637b3442011-01-10 23:31:48903 browser::Navigate(&p);
904
905 // The second tab should still be selected, but navigated to the new path.
906 EXPECT_EQ(browser(), p.browser);
907 EXPECT_EQ(2, browser()->tab_count());
[email protected]1ea49d52011-04-12 17:44:44908 EXPECT_EQ(1, browser()->active_index());
[email protected]637b3442011-01-10 23:31:48909 EXPECT_EQ(singleton_url_target,
[email protected]4ebab8ee2012-06-11 22:52:01910 browser()->GetActiveWebContents()->GetURL());
[email protected]637b3442011-01-10 23:31:48911}
912
[email protected]07afd7c2011-02-17 10:07:11913// This test verifies that constructing params with disposition = SINGLETON_TAB
[email protected]fee320542011-03-02 01:30:49914// and IGNORE_AND_NAVIGATE will open an existing matching tab with a different
915// query.
[email protected]07afd7c2011-02-17 10:07:11916IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
917 Disposition_SingletonTabExisting_IgnoreQuery) {
918 int initial_tab_count = browser()->tab_count();
919 GURL singleton_url_current("chrome://settings/internet");
[email protected]2905f742011-10-13 03:51:58920 browser()->AddSelectedTabWithURL(
921 singleton_url_current, content::PAGE_TRANSITION_LINK);
[email protected]07afd7c2011-02-17 10:07:11922
923 EXPECT_EQ(initial_tab_count + 1, browser()->tab_count());
[email protected]1ea49d52011-04-12 17:44:44924 EXPECT_EQ(initial_tab_count, browser()->active_index());
[email protected]07afd7c2011-02-17 10:07:11925
926 // Navigate to a different settings path.
927 GURL singleton_url_target(
928 "chrome://settings/internet?"
929 "servicePath=/profile/ethernet_00aa00aa00aa&networkType=1");
930 browser::NavigateParams p(MakeNavigateParams());
931 p.disposition = SINGLETON_TAB;
932 p.url = singleton_url_target;
[email protected]7d329992011-04-15 18:20:02933 p.window_action = browser::NavigateParams::SHOW_WINDOW;
[email protected]fee320542011-03-02 01:30:49934 p.path_behavior = browser::NavigateParams::IGNORE_AND_NAVIGATE;
[email protected]07afd7c2011-02-17 10:07:11935 browser::Navigate(&p);
936
937 // Last tab should still be selected.
938 EXPECT_EQ(browser(), p.browser);
939 EXPECT_EQ(initial_tab_count + 1, browser()->tab_count());
[email protected]1ea49d52011-04-12 17:44:44940 EXPECT_EQ(initial_tab_count, browser()->active_index());
[email protected]07afd7c2011-02-17 10:07:11941}
942
[email protected]bd817c22011-02-09 08:16:46943// This test verifies that the settings page isn't opened in the incognito
944// window.
[email protected]a048ad22012-03-23 04:26:56945// Disabled until fixed for uber settings: http://crbug.com/111243
[email protected]bd817c22011-02-09 08:16:46946IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
[email protected]a048ad22012-03-23 04:26:56947 DISABLED_Disposition_Settings_UseNonIncognitoWindow) {
[email protected]fc0ed302011-11-29 23:17:19948 RunUseNonIncognitoWindowTest(GetSettingsURL());
[email protected]bd817c22011-02-09 08:16:46949}
950
[email protected]82404cd2011-07-12 19:55:14951// This test verifies that the settings page isn't opened in the incognito
952// window from a non-incognito window (bookmark open-in-incognito trigger).
[email protected]a048ad22012-03-23 04:26:56953// Disabled until fixed for uber settings: http://crbug.com/111243
[email protected]82404cd2011-07-12 19:55:14954IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
[email protected]a048ad22012-03-23 04:26:56955 DISABLED_Disposition_Settings_UseNonIncognitoWindowForBookmark) {
956 browser::NavigateParams params(browser(), GetSettingsURL(),
[email protected]2905f742011-10-13 03:51:58957 content::PAGE_TRANSITION_AUTO_BOOKMARK);
[email protected]82404cd2011-07-12 19:55:14958 params.disposition = OFF_THE_RECORD;
959 {
960 ui_test_utils::WindowedNotificationObserver observer(
[email protected]ad50def52011-10-19 23:17:07961 content::NOTIFICATION_LOAD_STOP,
962 content::NotificationService::AllSources());
[email protected]82404cd2011-07-12 19:55:14963 browser::Navigate(&params);
964 observer.Wait();
965 }
966
967 EXPECT_EQ(1u, BrowserList::size());
[email protected]4ebab8ee2012-06-11 22:52:01968 EXPECT_EQ(GetSettingsURL(), browser()->GetActiveWebContents()->GetURL());
[email protected]82404cd2011-07-12 19:55:14969}
970
[email protected]93ad8e1c2011-11-08 21:34:05971// Settings page is expected to always open in normal mode regardless
972// of whether the user is trying to open it in incognito mode or not.
973// This test verifies that if incognito mode is forced (by policy), settings
974// page doesn't open at all.
[email protected]a048ad22012-03-23 04:26:56975// Disabled until fixed for uber settings: http://crbug.com/111243
[email protected]93ad8e1c2011-11-08 21:34:05976IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
[email protected]a048ad22012-03-23 04:26:56977 DISABLED_Disposition_Settings_DoNothingIfIncognitoIsForced) {
[email protected]fc0ed302011-11-29 23:17:19978 RunDoNothingIfIncognitoIsForcedTest(GetSettingsURL());
[email protected]93ad8e1c2011-11-08 21:34:05979}
980
[email protected]bd817c22011-02-09 08:16:46981// This test verifies that the bookmarks page isn't opened in the incognito
982// window.
983IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
984 Disposition_Bookmarks_UseNonIncognitoWindow) {
[email protected]fc0ed302011-11-29 23:17:19985 RunUseNonIncognitoWindowTest(GURL(chrome::kChromeUIBookmarksURL));
[email protected]bd817c22011-02-09 08:16:46986}
987
[email protected]93ad8e1c2011-11-08 21:34:05988// Bookmark manager is expected to always open in normal mode regardless
989// of whether the user is trying to open it in incognito mode or not.
990// This test verifies that if incognito mode is forced (by policy), bookmark
991// manager doesn't open at all.
992IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
993 Disposition_Bookmarks_DoNothingIfIncognitoIsForced) {
[email protected]fc0ed302011-11-29 23:17:19994 RunDoNothingIfIncognitoIsForcedTest(GURL(chrome::kChromeUIBookmarksURL));
995}
[email protected]93ad8e1c2011-11-08 21:34:05996
[email protected]fc0ed302011-11-29 23:17:19997// This test verifies that the sync promo page isn't opened in the incognito
998// window.
999IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
1000 Disposition_SyncPromo_UseNonIncognitoWindow) {
1001 RunUseNonIncognitoWindowTest(GURL(chrome::kChromeUISyncPromoURL));
1002}
[email protected]93ad8e1c2011-11-08 21:34:051003
[email protected]fc0ed302011-11-29 23:17:191004// The Sync promo page is expected to always open in normal mode regardless of
1005// whether the user is trying to open it in incognito mode or not. This test
1006// verifies that if incognito mode is forced (by policy), the sync promo page
1007// doesn't open at all.
1008IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
1009 Disposition_SyncPromo_DoNothingIfIncognitoIsForced) {
1010 RunDoNothingIfIncognitoIsForcedTest(GURL(chrome::kChromeUISyncPromoURL));
[email protected]93ad8e1c2011-11-08 21:34:051011}
1012
[email protected]7de53c62011-05-13 06:44:161013// This test makes sure a crashed singleton tab reloads from a new navigation.
1014IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
1015 NavigateToCrashedSingletonTab) {
[email protected]a048ad22012-03-23 04:26:561016 GURL singleton_url(GetContentSettingsURL());
[email protected]4ebab8ee2012-06-11 22:52:011017 TabContents* tab_contents = browser()->AddSelectedTabWithURL(
[email protected]2905f742011-10-13 03:51:581018 singleton_url, content::PAGE_TRANSITION_LINK);
[email protected]4ebab8ee2012-06-11 22:52:011019 WebContents* web_contents = tab_contents->web_contents();
[email protected]7de53c62011-05-13 06:44:161020
1021 // We should have one browser with 2 tabs, the 2nd selected.
1022 EXPECT_EQ(1u, BrowserList::size());
1023 EXPECT_EQ(2, browser()->tab_count());
1024 EXPECT_EQ(1, browser()->active_index());
1025
1026 // Kill the singleton tab.
[email protected]83ff91c2012-01-05 20:54:131027 web_contents->SetIsCrashed(base::TERMINATION_STATUS_PROCESS_CRASHED, -1);
1028 EXPECT_TRUE(web_contents->IsCrashed());
[email protected]7de53c62011-05-13 06:44:161029
1030 browser::NavigateParams p(MakeNavigateParams());
1031 p.disposition = SINGLETON_TAB;
1032 p.url = singleton_url;
1033 p.window_action = browser::NavigateParams::SHOW_WINDOW;
1034 p.path_behavior = browser::NavigateParams::IGNORE_AND_NAVIGATE;
[email protected]ddddfda2011-07-14 23:19:391035 ui_test_utils::NavigateToURL(&p);
[email protected]7de53c62011-05-13 06:44:161036
1037 // The tab should not be sad anymore.
[email protected]83ff91c2012-01-05 20:54:131038 EXPECT_FALSE(web_contents->IsCrashed());
[email protected]7de53c62011-05-13 06:44:161039}
1040
[email protected]fcca741b2011-06-17 22:46:371041IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
1042 NavigateFromDefaultToOptionsInSameTab) {
[email protected]ddddfda2011-07-14 23:19:391043 {
1044 ui_test_utils::WindowedNotificationObserver observer(
[email protected]ad50def52011-10-19 23:17:071045 content::NOTIFICATION_LOAD_STOP,
1046 content::NotificationService::AllSources());
[email protected]5d9cace72012-06-21 16:07:121047 chrome::ShowSettings(browser());
[email protected]ddddfda2011-07-14 23:19:391048 observer.Wait();
1049 }
[email protected]fcca741b2011-06-17 22:46:371050 EXPECT_EQ(1, browser()->tab_count());
[email protected]4ebab8ee2012-06-11 22:52:011051 EXPECT_EQ(GetSettingsURL(), browser()->GetActiveWebContents()->GetURL());
[email protected]fcca741b2011-06-17 22:46:371052}
1053
1054IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
1055 NavigateFromBlankToOptionsInSameTab) {
1056 browser::NavigateParams p(MakeNavigateParams());
[email protected]ddddfda2011-07-14 23:19:391057 p.url = GURL(chrome::kAboutBlankURL);
1058 ui_test_utils::NavigateToURL(&p);
[email protected]fcca741b2011-06-17 22:46:371059
[email protected]ddddfda2011-07-14 23:19:391060 {
1061 ui_test_utils::WindowedNotificationObserver observer(
[email protected]ad50def52011-10-19 23:17:071062 content::NOTIFICATION_LOAD_STOP,
1063 content::NotificationService::AllSources());
[email protected]5d9cace72012-06-21 16:07:121064 chrome::ShowSettings(browser());
[email protected]ddddfda2011-07-14 23:19:391065 observer.Wait();
1066 }
[email protected]fcca741b2011-06-17 22:46:371067 EXPECT_EQ(1, browser()->tab_count());
[email protected]4ebab8ee2012-06-11 22:52:011068 EXPECT_EQ(GetSettingsURL(), browser()->GetActiveWebContents()->GetURL());
[email protected]fcca741b2011-06-17 22:46:371069}
1070
1071IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
1072 NavigateFromNTPToOptionsInSameTab) {
1073 browser::NavigateParams p(MakeNavigateParams());
[email protected]ddddfda2011-07-14 23:19:391074 p.url = GURL(chrome::kChromeUINewTabURL);
1075 ui_test_utils::NavigateToURL(&p);
[email protected]fcca741b2011-06-17 22:46:371076 EXPECT_EQ(1, browser()->tab_count());
[email protected]ddddfda2011-07-14 23:19:391077 EXPECT_EQ(GURL(chrome::kChromeUINewTabURL),
[email protected]4ebab8ee2012-06-11 22:52:011078 browser()->GetActiveWebContents()->GetURL());
[email protected]fcca741b2011-06-17 22:46:371079
[email protected]ddddfda2011-07-14 23:19:391080 {
1081 ui_test_utils::WindowedNotificationObserver observer(
[email protected]ad50def52011-10-19 23:17:071082 content::NOTIFICATION_LOAD_STOP,
1083 content::NotificationService::AllSources());
[email protected]5d9cace72012-06-21 16:07:121084 chrome::ShowSettings(browser());
[email protected]ddddfda2011-07-14 23:19:391085 observer.Wait();
1086 }
[email protected]fcca741b2011-06-17 22:46:371087 EXPECT_EQ(1, browser()->tab_count());
[email protected]4ebab8ee2012-06-11 22:52:011088 EXPECT_EQ(GetSettingsURL(), browser()->GetActiveWebContents()->GetURL());
[email protected]fcca741b2011-06-17 22:46:371089}
1090
1091IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
1092 NavigateFromPageToOptionsInNewTab) {
1093 browser::NavigateParams p(MakeNavigateParams());
[email protected]ddddfda2011-07-14 23:19:391094 ui_test_utils::NavigateToURL(&p);
[email protected]4ebab8ee2012-06-11 22:52:011095 EXPECT_EQ(GetGoogleURL(), browser()->GetActiveWebContents()->GetURL());
[email protected]fcca741b2011-06-17 22:46:371096 EXPECT_EQ(1u, BrowserList::size());
1097 EXPECT_EQ(1, browser()->tab_count());
1098
[email protected]ddddfda2011-07-14 23:19:391099 {
1100 ui_test_utils::WindowedNotificationObserver observer(
[email protected]ad50def52011-10-19 23:17:071101 content::NOTIFICATION_LOAD_STOP,
1102 content::NotificationService::AllSources());
[email protected]5d9cace72012-06-21 16:07:121103 chrome::ShowSettings(browser());
[email protected]ddddfda2011-07-14 23:19:391104 observer.Wait();
1105 }
[email protected]fcca741b2011-06-17 22:46:371106 EXPECT_EQ(2, browser()->tab_count());
[email protected]4ebab8ee2012-06-11 22:52:011107 EXPECT_EQ(GetSettingsURL(), browser()->GetActiveWebContents()->GetURL());
[email protected]fcca741b2011-06-17 22:46:371108}
1109
1110IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
1111 NavigateFromNTPToOptionsSingleton) {
[email protected]ddddfda2011-07-14 23:19:391112 {
1113 ui_test_utils::WindowedNotificationObserver observer(
[email protected]ad50def52011-10-19 23:17:071114 content::NOTIFICATION_LOAD_STOP,
1115 content::NotificationService::AllSources());
[email protected]5d9cace72012-06-21 16:07:121116 chrome::ShowSettings(browser());
[email protected]ddddfda2011-07-14 23:19:391117 observer.Wait();
1118 }
[email protected]fcca741b2011-06-17 22:46:371119 EXPECT_EQ(1, browser()->tab_count());
1120
[email protected]a37d4b02012-06-25 21:56:101121 chrome::NewTab(browser());
[email protected]fcca741b2011-06-17 22:46:371122 EXPECT_EQ(2, browser()->tab_count());
1123
[email protected]ddddfda2011-07-14 23:19:391124 {
1125 ui_test_utils::WindowedNotificationObserver observer(
[email protected]ad50def52011-10-19 23:17:071126 content::NOTIFICATION_LOAD_STOP,
1127 content::NotificationService::AllSources());
[email protected]5d9cace72012-06-21 16:07:121128 chrome::ShowSettings(browser());
[email protected]ddddfda2011-07-14 23:19:391129 observer.Wait();
1130 }
[email protected]fcca741b2011-06-17 22:46:371131 EXPECT_EQ(2, browser()->tab_count());
[email protected]4ebab8ee2012-06-11 22:52:011132 EXPECT_EQ(GetSettingsURL(), browser()->GetActiveWebContents()->GetURL());
[email protected]fcca741b2011-06-17 22:46:371133}
1134
1135IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
1136 NavigateFromNTPToOptionsPageInSameTab) {
[email protected]ddddfda2011-07-14 23:19:391137 {
1138 ui_test_utils::WindowedNotificationObserver observer(
[email protected]ad50def52011-10-19 23:17:071139 content::NOTIFICATION_LOAD_STOP,
1140 content::NotificationService::AllSources());
[email protected]5d9cace72012-06-21 16:07:121141 chrome::ShowClearBrowsingDataDialog(browser());
[email protected]ddddfda2011-07-14 23:19:391142 observer.Wait();
1143 }
[email protected]fcca741b2011-06-17 22:46:371144 EXPECT_EQ(1, browser()->tab_count());
[email protected]a048ad22012-03-23 04:26:561145 EXPECT_EQ(GetClearBrowsingDataURL(),
[email protected]4ebab8ee2012-06-11 22:52:011146 browser()->GetActiveWebContents()->GetURL());
[email protected]fcca741b2011-06-17 22:46:371147
[email protected]a37d4b02012-06-25 21:56:101148 chrome::NewTab(browser());
[email protected]fcca741b2011-06-17 22:46:371149 EXPECT_EQ(2, browser()->tab_count());
1150
[email protected]ddddfda2011-07-14 23:19:391151 {
1152 ui_test_utils::WindowedNotificationObserver observer(
[email protected]ad50def52011-10-19 23:17:071153 content::NOTIFICATION_LOAD_STOP,
1154 content::NotificationService::AllSources());
[email protected]5d9cace72012-06-21 16:07:121155 chrome::ShowClearBrowsingDataDialog(browser());
[email protected]ddddfda2011-07-14 23:19:391156 observer.Wait();
1157 }
[email protected]fcca741b2011-06-17 22:46:371158 EXPECT_EQ(2, browser()->tab_count());
[email protected]a048ad22012-03-23 04:26:561159 EXPECT_EQ(GetClearBrowsingDataURL(),
[email protected]4ebab8ee2012-06-11 22:52:011160 browser()->GetActiveWebContents()->GetURL());
[email protected]fcca741b2011-06-17 22:46:371161}
1162
[email protected]ccb8aac2012-05-21 23:00:161163// Times out on mac, fails on linux.
1164// http://crbug.com/119779
1165#if defined(OS_MACOSX) || defined(OS_LINUX)
[email protected]aac43c72012-03-23 18:41:021166#define MAYBE_NavigateFromOtherTabToSingletonOptions DISABLED_NavigateFromOtherTabToSingletonOptions
1167#else
1168#define MAYBE_NavigateFromOtherTabToSingletonOptions NavigatorFrameOtherTabToSingletonOptions
1169#endif
[email protected]fcca741b2011-06-17 22:46:371170IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
[email protected]aac43c72012-03-23 18:41:021171 MAYBE_NavigateFromOtherTabToSingletonOptions) {
[email protected]ddddfda2011-07-14 23:19:391172 {
1173 ui_test_utils::WindowedNotificationObserver observer(
[email protected]ad50def52011-10-19 23:17:071174 content::NOTIFICATION_LOAD_STOP,
1175 content::NotificationService::AllSources());
[email protected]5d9cace72012-06-21 16:07:121176 chrome::ShowSettings(browser());
[email protected]ddddfda2011-07-14 23:19:391177 observer.Wait();
1178 }
1179 {
1180 ui_test_utils::WindowedNotificationObserver observer(
[email protected]ad50def52011-10-19 23:17:071181 content::NOTIFICATION_LOAD_STOP,
1182 content::NotificationService::AllSources());
[email protected]2905f742011-10-13 03:51:581183 browser()->AddSelectedTabWithURL(
1184 GetGoogleURL(), content::PAGE_TRANSITION_LINK);
[email protected]ddddfda2011-07-14 23:19:391185 observer.Wait();
1186 }
[email protected]fcca741b2011-06-17 22:46:371187
[email protected]ddddfda2011-07-14 23:19:391188 {
1189 ui_test_utils::WindowedNotificationObserver observer(
[email protected]ad50def52011-10-19 23:17:071190 content::NOTIFICATION_LOAD_STOP,
1191 content::NotificationService::AllSources());
[email protected]5d9cace72012-06-21 16:07:121192 chrome::ShowSettings(browser());
[email protected]ddddfda2011-07-14 23:19:391193 observer.Wait();
1194 }
[email protected]fcca741b2011-06-17 22:46:371195 EXPECT_EQ(2, browser()->tab_count());
[email protected]ddddfda2011-07-14 23:19:391196 EXPECT_EQ(GetSettingsURL(),
[email protected]4ebab8ee2012-06-11 22:52:011197 browser()->GetActiveWebContents()->GetURL());
[email protected]fcca741b2011-06-17 22:46:371198}
1199
[email protected]26c53e662011-07-09 02:21:021200// Tests that when a new tab is opened from the omnibox, the focus is moved from
1201// the omnibox for the current tab.
1202IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
1203 NavigateFromOmniboxIntoNewTab) {
1204 GURL url("http://www.google.com/");
1205 GURL url2("http://maps.google.com/");
1206
1207 // Navigate to url.
1208 browser::NavigateParams p(MakeNavigateParams());
1209 p.disposition = CURRENT_TAB;
1210 p.url = url;
1211 browser::Navigate(&p);
1212
1213 // Focus the omnibox.
[email protected]a37d4b02012-06-25 21:56:101214 chrome::FocusLocationBar(browser());
[email protected]26c53e662011-07-09 02:21:021215
[email protected]fbdc4232012-06-24 15:28:371216 OmniboxEditController* controller =
[email protected]fb8e3a32012-05-10 21:03:521217 browser()->window()->GetLocationBar()->GetLocationEntry()->model()->
[email protected]26c53e662011-07-09 02:21:021218 controller();
1219
1220 // Simulate an alt-enter.
1221 controller->OnAutocompleteAccept(url2, NEW_FOREGROUND_TAB,
[email protected]2905f742011-10-13 03:51:581222 content::PAGE_TRANSITION_TYPED, GURL());
[email protected]26c53e662011-07-09 02:21:021223
1224 // Make sure the second tab is selected.
1225 EXPECT_EQ(1, browser()->active_index());
1226
1227 // The tab contents should have the focus in the second tab.
[email protected]f2159ba2012-04-17 19:13:211228 EXPECT_TRUE(ui_test_utils::IsViewFocused(browser(), VIEW_ID_TAB_CONTAINER));
[email protected]26c53e662011-07-09 02:21:021229
1230 // Go back to the first tab. The focus should not be in the omnibox.
[email protected]a37d4b02012-06-25 21:56:101231 chrome::SelectPreviousTab(browser());
[email protected]26c53e662011-07-09 02:21:021232 EXPECT_EQ(0, browser()->active_index());
1233 EXPECT_FALSE(ui_test_utils::IsViewFocused(browser(),
1234 VIEW_ID_LOCATION_BAR));
1235}
1236
[email protected]a048ad22012-03-23 04:26:561237// TODO(csilv): Update this for uber page. http://crbug.com/111579.
[email protected]ddddfda2011-07-14 23:19:391238IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
[email protected]a048ad22012-03-23 04:26:561239 DISABLED_NavigateFromDefaultToHistoryInSameTab) {
[email protected]ddddfda2011-07-14 23:19:391240 {
1241 ui_test_utils::WindowedNotificationObserver observer(
[email protected]ad50def52011-10-19 23:17:071242 content::NOTIFICATION_LOAD_STOP,
1243 content::NotificationService::AllSources());
[email protected]5d9cace72012-06-21 16:07:121244 chrome::ShowHistory(browser());
[email protected]ddddfda2011-07-14 23:19:391245 observer.Wait();
1246 }
1247 EXPECT_EQ(1, browser()->tab_count());
[email protected]11e03fb2012-03-03 19:07:051248 EXPECT_EQ(GURL(chrome::kChromeUIHistoryFrameURL),
[email protected]4ebab8ee2012-06-11 22:52:011249 browser()->GetActiveWebContents()->GetURL());
[email protected]ddddfda2011-07-14 23:19:391250}
1251
1252IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
1253 NavigateFromDefaultToBookmarksInSameTab) {
1254 {
1255 ui_test_utils::WindowedNotificationObserver observer(
[email protected]ad50def52011-10-19 23:17:071256 content::NOTIFICATION_LOAD_STOP,
1257 content::NotificationService::AllSources());
[email protected]5d9cace72012-06-21 16:07:121258 chrome::ShowBookmarkManager(browser());
[email protected]ddddfda2011-07-14 23:19:391259 observer.Wait();
1260 }
1261 EXPECT_EQ(1, browser()->tab_count());
1262 EXPECT_EQ(GURL(chrome::kChromeUIBookmarksURL),
[email protected]4ebab8ee2012-06-11 22:52:011263 browser()->GetActiveWebContents()->GetURL());
[email protected]ddddfda2011-07-14 23:19:391264}
1265
1266IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
1267 NavigateFromDefaultToDownloadsInSameTab) {
1268 {
1269 ui_test_utils::WindowedNotificationObserver observer(
[email protected]ad50def52011-10-19 23:17:071270 content::NOTIFICATION_LOAD_STOP,
1271 content::NotificationService::AllSources());
[email protected]5d9cace72012-06-21 16:07:121272 chrome::ShowDownloads(browser());
[email protected]ddddfda2011-07-14 23:19:391273 observer.Wait();
1274 }
1275 EXPECT_EQ(1, browser()->tab_count());
1276 EXPECT_EQ(GURL(chrome::kChromeUIDownloadsURL),
[email protected]4ebab8ee2012-06-11 22:52:011277 browser()->GetActiveWebContents()->GetURL());
[email protected]ddddfda2011-07-14 23:19:391278}
1279
[email protected]675e779b2012-01-25 23:09:451280// This test makes sure any link in a crashed panel page navigates to a tabbed
1281// window.
1282class PanelBrowserNavigatorTest : public BrowserNavigatorTest {
1283 protected:
1284 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE {
1285 command_line->AppendSwitch(switches::kEnablePanels);
1286 }
1287};
1288
1289IN_PROC_BROWSER_TEST_F(PanelBrowserNavigatorTest, NavigateFromCrashedPanel) {
1290 GURL url("http://maps.google.com/#a");
1291 GURL url2("http://maps.google.com/#b");
1292
1293 // Create a panel.
[email protected]da22aa62012-04-04 18:54:351294 Browser* panel_browser = Browser::CreateWithParams(
1295 Browser::CreateParams::CreateForApp(
1296 Browser::TYPE_PANEL, "Test", gfx::Rect(100, 100),
1297 browser()->profile()));
[email protected]675e779b2012-01-25 23:09:451298
1299 // Navigate to the page.
1300 browser::NavigateParams p(MakeNavigateParams(panel_browser));
1301 p.url = url;
1302 p.disposition = CURRENT_TAB;
1303 browser::Navigate(&p);
1304
1305 // Navigate() should have navigated in the existing panel window.
1306 EXPECT_EQ(panel_browser, p.browser);
1307
1308 // We should now have two windows, the browser() provided by the framework and
1309 // the panel window we opened earlier. The tabbed browser window has 1 tab.
1310 EXPECT_EQ(2u, BrowserList::size());
1311 EXPECT_EQ(1, browser()->tab_count());
1312 EXPECT_EQ(1, panel_browser->tab_count());
1313
1314 // Kill the panel page.
[email protected]4ebab8ee2012-06-11 22:52:011315 WebContents* web_contents = panel_browser->GetActiveWebContents();
[email protected]675e779b2012-01-25 23:09:451316 web_contents->SetIsCrashed(base::TERMINATION_STATUS_PROCESS_CRASHED, -1);
1317 EXPECT_TRUE(web_contents->IsCrashed());
1318
1319 // Navigate to the page.
1320 browser::NavigateParams p2(MakeNavigateParams(panel_browser));
[email protected]4ebab8ee2012-06-11 22:52:011321 p2.source_contents = panel_browser->GetActiveTabContents();
[email protected]675e779b2012-01-25 23:09:451322 p2.url = url2;
1323 p2.disposition = CURRENT_TAB;
1324 browser::Navigate(&p2);
1325
1326 // Navigate() should have opened a new tab in the existing tabbed window.
1327 EXPECT_EQ(browser(), p2.browser);
1328
1329 // We should now have two windows, the browser() provided by the framework and
1330 // the panel window we opened earlier. The tabbed browser window has 2 tabs.
1331 EXPECT_EQ(2u, BrowserList::size());
1332 EXPECT_EQ(2, browser()->tab_count());
1333 EXPECT_EQ(1, panel_browser->tab_count());
1334}
1335
[email protected]ddddfda2011-07-14 23:19:391336} // namespace