blob: 8cd4af5f401c8c10a583655ead08ef8d08c26b05 [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]52877dbc62012-06-29 22:22:0315#include "chrome/browser/ui/browser_tabstrip.h"
[email protected]bb89e7482010-11-17 18:27:0416#include "chrome/browser/ui/browser_window.h"
[email protected]5d9cace72012-06-21 16:07:1217#include "chrome/browser/ui/chrome_pages.h"
[email protected]26c53e662011-07-09 02:21:0218#include "chrome/browser/ui/omnibox/location_bar.h"
[email protected]fbdc4232012-06-24 15:28:3719#include "chrome/browser/ui/omnibox/omnibox_edit_controller.h"
20#include "chrome/browser/ui/omnibox/omnibox_edit_model.h"
[email protected]26c53e662011-07-09 02:21:0221#include "chrome/browser/ui/omnibox/omnibox_view.h"
[email protected]4ebab8ee2012-06-11 22:52:0122#include "chrome/browser/ui/tab_contents/tab_contents.h"
[email protected]b56e2e32012-05-11 21:18:0423#include "chrome/browser/ui/tabs/tab_strip_model.h"
[email protected]bb89e7482010-11-17 18:27:0424#include "chrome/common/chrome_switches.h"
[email protected]93ad8e1c2011-11-08 21:34:0525#include "chrome/common/pref_names.h"
[email protected]ddddfda2011-07-14 23:19:3926#include "chrome/common/url_constants.h"
[email protected]af44e7fb2011-07-29 18:32:3227#include "chrome/test/base/ui_test_utils.h"
[email protected]ad50def52011-10-19 23:17:0728#include "content/public/browser/notification_service.h"
[email protected]0d6e9bd2011-10-18 04:29:1629#include "content/public/browser/notification_types.h"
[email protected]83ff91c2012-01-05 20:54:1330#include "content/public/browser/web_contents.h"
[email protected]8643e6d2012-01-18 20:26:1031#include "content/public/browser/web_contents_view.h"
[email protected]c47317e2012-06-20 22:35:3132#include "ipc/ipc_message.h"
[email protected]a1feae52010-10-11 22:14:4533
[email protected]4ca15302012-01-03 05:53:2034using content::WebContents;
35
[email protected]ddddfda2011-07-14 23:19:3936namespace {
37
38GURL GetGoogleURL() {
[email protected]bd817c22011-02-09 08:16:4639 return GURL("http://www.google.com/");
40}
[email protected]a1feae52010-10-11 22:14:4541
[email protected]ddddfda2011-07-14 23:19:3942GURL GetSettingsURL() {
[email protected]f8f93eb2012-09-25 03:06:2443 return GURL(chrome::kChromeUISettingsURL);
[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
[email protected]f8f93eb2012-09-25 03:06:2454// Converts long uber URLs ("chrome://chrome/foo/") to short (virtual) URLs
55// ("chrome://foo/"). This should be used to convert the return value of
56// WebContentsImpl::GetURL before comparison because it can return either the
57// real URL or the virtual URL.
58GURL ShortenUberURL(const GURL& url) {
59 std::string url_string = url.spec();
60 const std::string long_prefix = "chrome://chrome/";
61 const std::string short_prefix = "chrome://";
62 if (url_string.find(long_prefix) != 0)
63 return url;
64 url_string.replace(0, long_prefix.length(), short_prefix);
65 return GURL(url_string);
66}
67
[email protected]ddddfda2011-07-14 23:19:3968} // namespace
69
[email protected]78e2edc2012-07-01 23:32:2870chrome::NavigateParams BrowserNavigatorTest::MakeNavigateParams() const {
[email protected]bd817c22011-02-09 08:16:4671 return MakeNavigateParams(browser());
72}
[email protected]a1feae52010-10-11 22:14:4573
[email protected]78e2edc2012-07-01 23:32:2874chrome::NavigateParams BrowserNavigatorTest::MakeNavigateParams(
[email protected]bd817c22011-02-09 08:16:4675 Browser* browser) const {
[email protected]78e2edc2012-07-01 23:32:2876 chrome::NavigateParams params(browser, GetGoogleURL(),
77 content::PAGE_TRANSITION_LINK);
78 params.window_action = chrome::NavigateParams::SHOW_WINDOW;
[email protected]bd817c22011-02-09 08:16:4679 return params;
80}
[email protected]a1feae52010-10-11 22:14:4581
[email protected]bd817c22011-02-09 08:16:4682Browser* BrowserNavigatorTest::CreateEmptyBrowserForType(Browser::Type type,
83 Profile* profile) {
[email protected]a4fe67012012-07-25 20:14:2984 Browser* browser = new Browser(Browser::CreateParams(type, profile));
[email protected]686221c2012-11-08 07:30:1085 chrome::AddBlankTabAt(browser, -1, true);
[email protected]bd817c22011-02-09 08:16:4686 return browser;
87}
[email protected]a1feae52010-10-11 22:14:4588
[email protected]b35b26b32011-05-05 20:35:1489Browser* BrowserNavigatorTest::CreateEmptyBrowserForApp(Browser::Type type,
90 Profile* profile) {
[email protected]a4fe67012012-07-25 20:14:2991 Browser* browser = new Browser(
[email protected]da22aa62012-04-04 18:54:3592 Browser::CreateParams::CreateForApp(
93 Browser::TYPE_POPUP, "Test", gfx::Rect(), profile));
[email protected]686221c2012-11-08 07:30:1094 chrome::AddBlankTabAt(browser, -1, true);
[email protected]b35b26b32011-05-05 20:35:1495 return browser;
96}
97
[email protected]4ebab8ee2012-06-11 22:52:0198TabContents* BrowserNavigatorTest::CreateTabContents() {
[email protected]52877dbc62012-06-29 22:22:0399 return chrome::TabContentsFactory(
[email protected]bd817c22011-02-09 08:16:46100 browser()->profile(),
101 NULL,
102 MSG_ROUTING_NONE,
[email protected]d1198fd2012-08-13 22:50:19103 chrome::GetActiveWebContents(browser()));
[email protected]bd817c22011-02-09 08:16:46104}
[email protected]a1feae52010-10-11 22:14:45105
[email protected]bd817c22011-02-09 08:16:46106void BrowserNavigatorTest::RunSuppressTest(WindowOpenDisposition disposition) {
[email protected]52877dbc62012-06-29 22:22:03107 GURL old_url = chrome::GetActiveWebContents(browser())->GetURL();
[email protected]78e2edc2012-07-01 23:32:28108 chrome::NavigateParams p(MakeNavigateParams());
[email protected]bd817c22011-02-09 08:16:46109 p.disposition = disposition;
[email protected]78e2edc2012-07-01 23:32:28110 chrome::Navigate(&p);
[email protected]a1feae52010-10-11 22:14:45111
[email protected]bd817c22011-02-09 08:16:46112 // Nothing should have happened as a result of Navigate();
113 EXPECT_EQ(1, browser()->tab_count());
114 EXPECT_EQ(1u, BrowserList::size());
[email protected]52877dbc62012-06-29 22:22:03115 EXPECT_EQ(old_url, chrome::GetActiveWebContents(browser())->GetURL());
[email protected]bd817c22011-02-09 08:16:46116}
[email protected]bb89e7482010-11-17 18:27:04117
[email protected]fc0ed302011-11-29 23:17:19118void BrowserNavigatorTest::RunUseNonIncognitoWindowTest(const GURL& url) {
119 Browser* incognito_browser = CreateIncognitoBrowser();
120
121 EXPECT_EQ(2u, BrowserList::size());
122 EXPECT_EQ(1, browser()->tab_count());
123 EXPECT_EQ(1, incognito_browser->tab_count());
124
125 // Navigate to the page.
[email protected]78e2edc2012-07-01 23:32:28126 chrome::NavigateParams p(MakeNavigateParams(incognito_browser));
[email protected]fc0ed302011-11-29 23:17:19127 p.disposition = SINGLETON_TAB;
128 p.url = url;
[email protected]78e2edc2012-07-01 23:32:28129 p.window_action = chrome::NavigateParams::SHOW_WINDOW;
130 chrome::Navigate(&p);
[email protected]fc0ed302011-11-29 23:17:19131
132 // This page should be opened in browser() window.
133 EXPECT_NE(incognito_browser, p.browser);
134 EXPECT_EQ(browser(), p.browser);
135 EXPECT_EQ(2, browser()->tab_count());
[email protected]52877dbc62012-06-29 22:22:03136 EXPECT_EQ(url, chrome::GetActiveWebContents(browser())->GetURL());
[email protected]fc0ed302011-11-29 23:17:19137}
138
139void BrowserNavigatorTest::RunDoNothingIfIncognitoIsForcedTest(
140 const GURL& url) {
141 Browser* browser = CreateIncognitoBrowser();
142
143 // Set kIncognitoModeAvailability to FORCED.
144 PrefService* prefs1 = browser->profile()->GetPrefs();
145 prefs1->SetInteger(prefs::kIncognitoModeAvailability,
146 IncognitoModePrefs::FORCED);
147 PrefService* prefs2 = browser->profile()->GetOriginalProfile()->GetPrefs();
148 prefs2->SetInteger(prefs::kIncognitoModeAvailability,
149 IncognitoModePrefs::FORCED);
150
151 // Navigate to the page.
[email protected]78e2edc2012-07-01 23:32:28152 chrome::NavigateParams p(MakeNavigateParams(browser));
[email protected]fc0ed302011-11-29 23:17:19153 p.disposition = OFF_THE_RECORD;
154 p.url = url;
[email protected]78e2edc2012-07-01 23:32:28155 p.window_action = chrome::NavigateParams::SHOW_WINDOW;
156 chrome::Navigate(&p);
[email protected]fc0ed302011-11-29 23:17:19157
158 // The page should not be opened.
159 EXPECT_EQ(browser, p.browser);
160 EXPECT_EQ(1, browser->tab_count());
161 EXPECT_EQ(GURL(chrome::kAboutBlankURL),
[email protected]52877dbc62012-06-29 22:22:03162 chrome::GetActiveWebContents(browser)->GetURL());
[email protected]fc0ed302011-11-29 23:17:19163}
164
[email protected]6c2381d2011-10-19 02:52:53165void BrowserNavigatorTest::Observe(
166 int type,
167 const content::NotificationSource& source,
168 const content::NotificationDetails& details) {
[email protected]432115822011-07-10 15:52:27169 switch (type) {
[email protected]d53a08c2012-07-18 20:35:30170 case content::NOTIFICATION_WEB_CONTENTS_RENDER_VIEW_HOST_CREATED: {
[email protected]bd817c22011-02-09 08:16:46171 ++this->created_tab_contents_count_;
172 break;
[email protected]fa7ebe02010-11-29 23:04:57173 }
[email protected]bd817c22011-02-09 08:16:46174 default:
175 break;
[email protected]fa7ebe02010-11-29 23:04:57176 }
[email protected]bd817c22011-02-09 08:16:46177}
[email protected]fa7ebe02010-11-29 23:04:57178
[email protected]ddddfda2011-07-14 23:19:39179
[email protected]bd817c22011-02-09 08:16:46180namespace {
[email protected]a1feae52010-10-11 22:14:45181
[email protected]a1feae52010-10-11 22:14:45182// This test verifies that when a navigation occurs within a tab, the tab count
183// of the Browser remains the same and the current tab bears the loaded URL.
184IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_CurrentTab) {
[email protected]ddddfda2011-07-14 23:19:39185 ui_test_utils::NavigateToURL(browser(), GetGoogleURL());
[email protected]52877dbc62012-06-29 22:22:03186 EXPECT_EQ(GetGoogleURL(), chrome::GetActiveWebContents(browser())->GetURL());
[email protected]a1feae52010-10-11 22:14:45187 // We should have one window with one tab.
188 EXPECT_EQ(1u, BrowserList::size());
189 EXPECT_EQ(1, browser()->tab_count());
190}
191
[email protected]bd817c22011-02-09 08:16:46192// This test verifies that a singleton tab is refocused if one is already opened
[email protected]19d9f3a2010-10-14 21:49:36193// in another or an existing window, or added if it is not.
194IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_SingletonTabExisting) {
[email protected]19d9f3a2010-10-14 21:49:36195 GURL singleton_url1("http://maps.google.com/");
[email protected]fa7ebe02010-11-29 23:04:57196
197 // Register for a notification if an additional tab_contents was instantiated.
[email protected]bd817c22011-02-09 08:16:46198 // Opening a Singleton tab that is already opened should not be opening a new
[email protected]4ebab8ee2012-06-11 22:52:01199 // tab nor be creating a new TabContents object.
[email protected]6c2381d2011-10-19 02:52:53200 content::NotificationRegistrar registrar;
[email protected]fa7ebe02010-11-29 23:04:57201
202 // As the registrar object goes out of scope, this will get unregistered
[email protected]d53a08c2012-07-18 20:35:30203 registrar.Add(this,
204 content::NOTIFICATION_WEB_CONTENTS_RENDER_VIEW_HOST_CREATED,
[email protected]ad50def52011-10-19 23:17:07205 content::NotificationService::AllSources());
[email protected]fa7ebe02010-11-29 23:04:57206
[email protected]52877dbc62012-06-29 22:22:03207 chrome::AddSelectedTabWithURL(browser(), singleton_url1,
208 content::PAGE_TRANSITION_LINK);
209 chrome::AddSelectedTabWithURL(browser(), GetGoogleURL(),
210 content::PAGE_TRANSITION_LINK);
[email protected]19d9f3a2010-10-14 21:49:36211
212 // We should have one browser with 3 tabs, the 3rd selected.
213 EXPECT_EQ(1u, BrowserList::size());
[email protected]1ea49d52011-04-12 17:44:44214 EXPECT_EQ(2, browser()->active_index());
[email protected]19d9f3a2010-10-14 21:49:36215
[email protected]fa7ebe02010-11-29 23:04:57216 unsigned int previous_tab_contents_count =
217 created_tab_contents_count_ = 0;
218
[email protected]19d9f3a2010-10-14 21:49:36219 // Navigate to singleton_url1.
[email protected]78e2edc2012-07-01 23:32:28220 chrome::NavigateParams p(MakeNavigateParams());
[email protected]19d9f3a2010-10-14 21:49:36221 p.disposition = SINGLETON_TAB;
222 p.url = singleton_url1;
[email protected]78e2edc2012-07-01 23:32:28223 chrome::Navigate(&p);
[email protected]19d9f3a2010-10-14 21:49:36224
225 // The middle tab should now be selected.
226 EXPECT_EQ(browser(), p.browser);
[email protected]1ea49d52011-04-12 17:44:44227 EXPECT_EQ(1, browser()->active_index());
[email protected]fa7ebe02010-11-29 23:04:57228
229 // No tab contents should have been created
230 EXPECT_EQ(previous_tab_contents_count,
231 created_tab_contents_count_);
[email protected]19d9f3a2010-10-14 21:49:36232}
233
234IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
[email protected]578c6962011-08-24 22:06:40235 Disposition_SingletonTabRespectingRef) {
236 GURL singleton_ref_url1("http://maps.google.com/#a");
237 GURL singleton_ref_url2("http://maps.google.com/#b");
238 GURL singleton_ref_url3("http://maps.google.com/");
239
[email protected]52877dbc62012-06-29 22:22:03240 chrome::AddSelectedTabWithURL(browser(), singleton_ref_url1,
241 content::PAGE_TRANSITION_LINK);
[email protected]578c6962011-08-24 22:06:40242
243 // We should have one browser with 2 tabs, 2nd selected.
244 EXPECT_EQ(1u, BrowserList::size());
245 EXPECT_EQ(2, browser()->tab_count());
246 EXPECT_EQ(1, browser()->active_index());
247
248 // Navigate to singleton_url2.
[email protected]78e2edc2012-07-01 23:32:28249 chrome::NavigateParams p(MakeNavigateParams());
[email protected]578c6962011-08-24 22:06:40250 p.disposition = SINGLETON_TAB;
251 p.url = singleton_ref_url2;
[email protected]78e2edc2012-07-01 23:32:28252 chrome::Navigate(&p);
[email protected]578c6962011-08-24 22:06:40253
254 // We should now have 2 tabs, the 2nd one selected.
255 EXPECT_EQ(browser(), p.browser);
256 EXPECT_EQ(2, browser()->tab_count());
257 EXPECT_EQ(1, browser()->active_index());
258
259 // Navigate to singleton_url2, but with respect ref set.
260 p = MakeNavigateParams();
261 p.disposition = SINGLETON_TAB;
262 p.url = singleton_ref_url2;
[email protected]78e2edc2012-07-01 23:32:28263 p.ref_behavior = chrome::NavigateParams::RESPECT_REF;
264 chrome::Navigate(&p);
[email protected]578c6962011-08-24 22:06:40265
266 // We should now have 3 tabs, the 3th one selected.
267 EXPECT_EQ(browser(), p.browser);
268 EXPECT_EQ(3, browser()->tab_count());
269 EXPECT_EQ(2, browser()->active_index());
270
271 // Navigate to singleton_url3.
272 p = MakeNavigateParams();
273 p.disposition = SINGLETON_TAB;
274 p.url = singleton_ref_url3;
[email protected]78e2edc2012-07-01 23:32:28275 p.ref_behavior = chrome::NavigateParams::RESPECT_REF;
276 chrome::Navigate(&p);
[email protected]578c6962011-08-24 22:06:40277
278 // We should now have 4 tabs, the 4th one selected.
279 EXPECT_EQ(browser(), p.browser);
280 EXPECT_EQ(4, browser()->tab_count());
281 EXPECT_EQ(3, browser()->active_index());
282}
283
284IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
[email protected]19d9f3a2010-10-14 21:49:36285 Disposition_SingletonTabNoneExisting) {
[email protected]19d9f3a2010-10-14 21:49:36286 GURL singleton_url1("http://maps.google.com/");
287
[email protected]bd817c22011-02-09 08:16:46288 // We should have one browser with 1 tab.
[email protected]19d9f3a2010-10-14 21:49:36289 EXPECT_EQ(1u, BrowserList::size());
[email protected]1ea49d52011-04-12 17:44:44290 EXPECT_EQ(0, browser()->active_index());
[email protected]19d9f3a2010-10-14 21:49:36291
292 // Navigate to singleton_url1.
[email protected]78e2edc2012-07-01 23:32:28293 chrome::NavigateParams p(MakeNavigateParams());
[email protected]19d9f3a2010-10-14 21:49:36294 p.disposition = SINGLETON_TAB;
295 p.url = singleton_url1;
[email protected]78e2edc2012-07-01 23:32:28296 chrome::Navigate(&p);
[email protected]19d9f3a2010-10-14 21:49:36297
298 // We should now have 2 tabs, the 2nd one selected.
299 EXPECT_EQ(browser(), p.browser);
300 EXPECT_EQ(2, browser()->tab_count());
[email protected]1ea49d52011-04-12 17:44:44301 EXPECT_EQ(1, browser()->active_index());
[email protected]a1feae52010-10-11 22:14:45302}
303
304// This test verifies that when a navigation results in a foreground tab, the
305// tab count of the Browser increases and the selected tab shifts to the new
306// foreground tab.
307IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_NewForegroundTab) {
[email protected]52877dbc62012-06-29 22:22:03308 WebContents* old_contents = chrome::GetActiveWebContents(browser());
[email protected]78e2edc2012-07-01 23:32:28309 chrome::NavigateParams p(MakeNavigateParams());
[email protected]a1feae52010-10-11 22:14:45310 p.disposition = NEW_FOREGROUND_TAB;
[email protected]78e2edc2012-07-01 23:32:28311 chrome::Navigate(&p);
[email protected]52877dbc62012-06-29 22:22:03312 EXPECT_NE(old_contents, chrome::GetActiveWebContents(browser()));
313 EXPECT_EQ(chrome::GetActiveTabContents(browser()), p.target_contents);
[email protected]a1feae52010-10-11 22:14:45314 EXPECT_EQ(2, browser()->tab_count());
315}
316
317// This test verifies that when a navigation results in a background tab, the
318// tab count of the Browser increases but the selected tab remains the same.
319IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_NewBackgroundTab) {
[email protected]52877dbc62012-06-29 22:22:03320 WebContents* old_contents = chrome::GetActiveWebContents(browser());
[email protected]78e2edc2012-07-01 23:32:28321 chrome::NavigateParams p(MakeNavigateParams());
[email protected]a1feae52010-10-11 22:14:45322 p.disposition = NEW_BACKGROUND_TAB;
[email protected]78e2edc2012-07-01 23:32:28323 chrome::Navigate(&p);
[email protected]52877dbc62012-06-29 22:22:03324 WebContents* new_contents = chrome::GetActiveWebContents(browser());
[email protected]a1feae52010-10-11 22:14:45325 // The selected tab should have remained unchanged, since the new tab was
326 // opened in the background.
327 EXPECT_EQ(old_contents, new_contents);
328 EXPECT_EQ(2, browser()->tab_count());
329}
330
331// This test verifies that when a navigation requiring a new foreground tab
332// occurs in a Browser that cannot host multiple tabs, the new foreground tab
333// is created in an existing compatible Browser.
334IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
335 Disposition_IncompatibleWindow_Existing) {
336 // Open a foreground tab in a window that cannot open popups when there is an
337 // existing compatible window somewhere else that they can be opened within.
338 Browser* popup = CreateEmptyBrowserForType(Browser::TYPE_POPUP,
339 browser()->profile());
[email protected]78e2edc2012-07-01 23:32:28340 chrome::NavigateParams p(MakeNavigateParams(popup));
[email protected]a1feae52010-10-11 22:14:45341 p.disposition = NEW_FOREGROUND_TAB;
[email protected]78e2edc2012-07-01 23:32:28342 chrome::Navigate(&p);
[email protected]a1feae52010-10-11 22:14:45343
344 // Navigate() should have opened the tab in a different browser since the
345 // one we supplied didn't support additional tabs.
346 EXPECT_NE(popup, p.browser);
347
348 // Since browser() is an existing compatible tabbed browser, it should have
349 // opened the tab there.
350 EXPECT_EQ(browser(), p.browser);
351
352 // We should be left with 2 windows, the popup with one tab and the browser()
353 // provided by the framework with two.
354 EXPECT_EQ(2u, BrowserList::size());
355 EXPECT_EQ(1, popup->tab_count());
356 EXPECT_EQ(2, browser()->tab_count());
357}
358
359// This test verifies that when a navigation requiring a new foreground tab
360// occurs in a Browser that cannot host multiple tabs and no compatible Browser
361// that can is open, a compatible Browser is created.
362IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
363 Disposition_IncompatibleWindow_NoExisting) {
364 // We want to simulate not being able to find an existing window compatible
365 // with our non-tabbed browser window so Navigate() is forced to create a
366 // new compatible window. Because browser() supplied by the in-process
367 // browser testing framework is compatible with browser()->profile(), we
368 // need a different profile, and creating a popup window with an incognito
369 // profile is a quick and dirty way of achieving this.
370 Browser* popup = CreateEmptyBrowserForType(
[email protected]b35b26b32011-05-05 20:35:14371 Browser::TYPE_POPUP,
372 browser()->profile()->GetOffTheRecordProfile());
[email protected]78e2edc2012-07-01 23:32:28373 chrome::NavigateParams p(MakeNavigateParams(popup));
[email protected]a1feae52010-10-11 22:14:45374 p.disposition = NEW_FOREGROUND_TAB;
[email protected]78e2edc2012-07-01 23:32:28375 chrome::Navigate(&p);
[email protected]a1feae52010-10-11 22:14:45376
377 // Navigate() should have opened the tab in a different browser since the
378 // one we supplied didn't support additional tabs.
379 EXPECT_NE(popup, p.browser);
380
381 // This time, browser() is _not_ compatible with popup since it is not an
382 // incognito window.
383 EXPECT_NE(browser(), p.browser);
384
385 // We should have three windows, each with one tab:
386 // 1. the browser() provided by the framework (unchanged in this test)
387 // 2. the incognito popup we created originally
388 // 3. the new incognito tabbed browser that was created by Navigate().
389 EXPECT_EQ(3u, BrowserList::size());
390 EXPECT_EQ(1, browser()->tab_count());
391 EXPECT_EQ(1, popup->tab_count());
392 EXPECT_EQ(1, p.browser->tab_count());
[email protected]b35b26b32011-05-05 20:35:14393 EXPECT_TRUE(p.browser->is_type_tabbed());
[email protected]a1feae52010-10-11 22:14:45394}
395
396// This test verifies that navigating with WindowOpenDisposition = NEW_POPUP
397// from a normal Browser results in a new Browser with TYPE_POPUP.
398IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_NewPopup) {
[email protected]78e2edc2012-07-01 23:32:28399 chrome::NavigateParams p(MakeNavigateParams());
[email protected]a1feae52010-10-11 22:14:45400 p.disposition = NEW_POPUP;
[email protected]588300d2011-04-28 21:06:35401 p.window_bounds = gfx::Rect(0, 0, 200, 200);
[email protected]7d329992011-04-15 18:20:02402 // Wait for new popup to to load and gain focus.
[email protected]ddddfda2011-07-14 23:19:39403 ui_test_utils::NavigateToURL(&p);
[email protected]a1feae52010-10-11 22:14:45404
[email protected]7d329992011-04-15 18:20:02405 // Navigate() should have opened a new, focused popup window.
[email protected]a1feae52010-10-11 22:14:45406 EXPECT_NE(browser(), p.browser);
[email protected]9db263a2011-04-15 20:53:47407#if 0
408 // TODO(stevenjb): Enable this test. See: crbug.com/79493
[email protected]7d329992011-04-15 18:20:02409 EXPECT_TRUE(p.browser->window()->IsActive());
410#endif
[email protected]b35b26b32011-05-05 20:35:14411 EXPECT_TRUE(p.browser->is_type_popup());
412 EXPECT_FALSE(p.browser->is_app());
[email protected]a1feae52010-10-11 22:14:45413
414 // We should have two windows, the browser() provided by the framework and the
415 // new popup window.
416 EXPECT_EQ(2u, BrowserList::size());
417 EXPECT_EQ(1, browser()->tab_count());
418 EXPECT_EQ(1, p.browser->tab_count());
419}
420
421// This test verifies that navigating with WindowOpenDisposition = NEW_POPUP
[email protected]f112b0f2011-05-26 01:53:52422// from a normal Browser results in a new Browser with is_app() true.
423IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_NewPopup_ExtensionId) {
[email protected]78e2edc2012-07-01 23:32:28424 chrome::NavigateParams p(MakeNavigateParams());
[email protected]f112b0f2011-05-26 01:53:52425 p.disposition = NEW_POPUP;
426 p.extension_app_id = "extensionappid";
427 p.window_bounds = gfx::Rect(0, 0, 200, 200);
[email protected]f112b0f2011-05-26 01:53:52428 // Wait for new popup to to load and gain focus.
[email protected]ddddfda2011-07-14 23:19:39429 ui_test_utils::NavigateToURL(&p);
[email protected]f112b0f2011-05-26 01:53:52430
431 // Navigate() should have opened a new, focused popup window.
432 EXPECT_NE(browser(), p.browser);
433 EXPECT_TRUE(p.browser->is_type_popup());
434 EXPECT_TRUE(p.browser->is_app());
435
436 // We should have two windows, the browser() provided by the framework and the
437 // new popup window.
438 EXPECT_EQ(2u, BrowserList::size());
439 EXPECT_EQ(1, browser()->tab_count());
440 EXPECT_EQ(1, p.browser->tab_count());
441}
442
443// This test verifies that navigating with WindowOpenDisposition = NEW_POPUP
[email protected]300d1e52011-01-19 23:57:57444// from a normal popup results in a new Browser with TYPE_POPUP.
445IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_NewPopupFromPopup) {
446 // Open a popup.
[email protected]78e2edc2012-07-01 23:32:28447 chrome::NavigateParams p1(MakeNavigateParams());
[email protected]300d1e52011-01-19 23:57:57448 p1.disposition = NEW_POPUP;
[email protected]588300d2011-04-28 21:06:35449 p1.window_bounds = gfx::Rect(0, 0, 200, 200);
[email protected]78e2edc2012-07-01 23:32:28450 chrome::Navigate(&p1);
[email protected]300d1e52011-01-19 23:57:57451 // Open another popup.
[email protected]78e2edc2012-07-01 23:32:28452 chrome::NavigateParams p2(MakeNavigateParams(p1.browser));
[email protected]300d1e52011-01-19 23:57:57453 p2.disposition = NEW_POPUP;
[email protected]588300d2011-04-28 21:06:35454 p2.window_bounds = gfx::Rect(0, 0, 200, 200);
[email protected]78e2edc2012-07-01 23:32:28455 chrome::Navigate(&p2);
[email protected]300d1e52011-01-19 23:57:57456
457 // Navigate() should have opened a new normal popup window.
458 EXPECT_NE(p1.browser, p2.browser);
[email protected]b35b26b32011-05-05 20:35:14459 EXPECT_TRUE(p2.browser->is_type_popup());
460 EXPECT_FALSE(p2.browser->is_app());
[email protected]300d1e52011-01-19 23:57:57461
462 // We should have three windows, the browser() provided by the framework,
463 // the first popup window, and the second popup window.
464 EXPECT_EQ(3u, BrowserList::size());
465 EXPECT_EQ(1, browser()->tab_count());
466 EXPECT_EQ(1, p1.browser->tab_count());
467 EXPECT_EQ(1, p2.browser->tab_count());
468}
469
470// This test verifies that navigating with WindowOpenDisposition = NEW_POPUP
[email protected]a1feae52010-10-11 22:14:45471// from an app frame results in a new Browser with TYPE_APP_POPUP.
472IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
473 Disposition_NewPopupFromAppWindow) {
[email protected]b35b26b32011-05-05 20:35:14474 Browser* app_browser = CreateEmptyBrowserForApp(Browser::TYPE_TABBED,
475 browser()->profile());
[email protected]78e2edc2012-07-01 23:32:28476 chrome::NavigateParams p(MakeNavigateParams(app_browser));
[email protected]a1feae52010-10-11 22:14:45477 p.disposition = NEW_POPUP;
[email protected]588300d2011-04-28 21:06:35478 p.window_bounds = gfx::Rect(0, 0, 200, 200);
[email protected]78e2edc2012-07-01 23:32:28479 chrome::Navigate(&p);
[email protected]a1feae52010-10-11 22:14:45480
481 // Navigate() should have opened a new popup app window.
482 EXPECT_NE(app_browser, p.browser);
483 EXPECT_NE(browser(), p.browser);
[email protected]b35b26b32011-05-05 20:35:14484 EXPECT_TRUE(p.browser->is_type_popup());
485 EXPECT_TRUE(p.browser->is_app());
[email protected]a1feae52010-10-11 22:14:45486
487 // We should now have three windows, the app window, the app popup it created,
488 // and the original browser() provided by the framework.
489 EXPECT_EQ(3u, BrowserList::size());
490 EXPECT_EQ(1, browser()->tab_count());
491 EXPECT_EQ(1, app_browser->tab_count());
492 EXPECT_EQ(1, p.browser->tab_count());
493}
494
495// This test verifies that navigating with WindowOpenDisposition = NEW_POPUP
[email protected]300d1e52011-01-19 23:57:57496// from an app popup results in a new Browser also of TYPE_APP_POPUP.
497IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
498 Disposition_NewPopupFromAppPopup) {
[email protected]b35b26b32011-05-05 20:35:14499 Browser* app_browser = CreateEmptyBrowserForApp(Browser::TYPE_TABBED,
500 browser()->profile());
[email protected]300d1e52011-01-19 23:57:57501 // Open an app popup.
[email protected]78e2edc2012-07-01 23:32:28502 chrome::NavigateParams p1(MakeNavigateParams(app_browser));
[email protected]300d1e52011-01-19 23:57:57503 p1.disposition = NEW_POPUP;
[email protected]588300d2011-04-28 21:06:35504 p1.window_bounds = gfx::Rect(0, 0, 200, 200);
[email protected]78e2edc2012-07-01 23:32:28505 chrome::Navigate(&p1);
[email protected]300d1e52011-01-19 23:57:57506 // Now open another app popup.
[email protected]78e2edc2012-07-01 23:32:28507 chrome::NavigateParams p2(MakeNavigateParams(p1.browser));
[email protected]300d1e52011-01-19 23:57:57508 p2.disposition = NEW_POPUP;
[email protected]588300d2011-04-28 21:06:35509 p2.window_bounds = gfx::Rect(0, 0, 200, 200);
[email protected]78e2edc2012-07-01 23:32:28510 chrome::Navigate(&p2);
[email protected]300d1e52011-01-19 23:57:57511
512 // Navigate() should have opened a new popup app window.
513 EXPECT_NE(browser(), p1.browser);
514 EXPECT_NE(p1.browser, p2.browser);
[email protected]b35b26b32011-05-05 20:35:14515 EXPECT_TRUE(p2.browser->is_type_popup());
516 EXPECT_TRUE(p2.browser->is_app());
[email protected]300d1e52011-01-19 23:57:57517
518 // We should now have four windows, the app window, the first app popup,
519 // the second app popup, and the original browser() provided by the framework.
520 EXPECT_EQ(4u, BrowserList::size());
521 EXPECT_EQ(1, browser()->tab_count());
522 EXPECT_EQ(1, app_browser->tab_count());
523 EXPECT_EQ(1, p1.browser->tab_count());
524 EXPECT_EQ(1, p2.browser->tab_count());
525}
526
527// This test verifies that navigating with WindowOpenDisposition = NEW_POPUP
[email protected]a1feae52010-10-11 22:14:45528// from an extension app tab results in a new Browser with TYPE_APP_POPUP.
529IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
530 Disposition_NewPopupFromExtensionApp) {
531 // TODO(beng): TBD.
532}
533
[email protected]7d329992011-04-15 18:20:02534// This test verifies that navigating with window_action = SHOW_WINDOW_INACTIVE
535// does not focus a new new popup window.
536IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_NewPopupUnfocused) {
[email protected]78e2edc2012-07-01 23:32:28537 chrome::NavigateParams p(MakeNavigateParams());
[email protected]7d329992011-04-15 18:20:02538 p.disposition = NEW_POPUP;
[email protected]588300d2011-04-28 21:06:35539 p.window_bounds = gfx::Rect(0, 0, 200, 200);
[email protected]78e2edc2012-07-01 23:32:28540 p.window_action = chrome::NavigateParams::SHOW_WINDOW_INACTIVE;
[email protected]7d329992011-04-15 18:20:02541 // Wait for new popup to load (and gain focus if the test fails).
[email protected]ddddfda2011-07-14 23:19:39542 ui_test_utils::NavigateToURL(&p);
[email protected]7d329992011-04-15 18:20:02543
544 // Navigate() should have opened a new, unfocused, popup window.
545 EXPECT_NE(browser(), p.browser);
546 EXPECT_EQ(Browser::TYPE_POPUP, p.browser->type());
[email protected]9db263a2011-04-15 20:53:47547#if 0
548// TODO(stevenjb): Enable this test. See: crbug.com/79493
[email protected]7d329992011-04-15 18:20:02549 EXPECT_FALSE(p.browser->window()->IsActive());
[email protected]7d329992011-04-15 18:20:02550#endif
[email protected]9db263a2011-04-15 20:53:47551}
[email protected]7d329992011-04-15 18:20:02552
[email protected]a1feae52010-10-11 22:14:45553// This test verifies that navigating with WindowOpenDisposition = NEW_WINDOW
554// always opens a new window.
555IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_NewWindow) {
[email protected]78e2edc2012-07-01 23:32:28556 chrome::NavigateParams p(MakeNavigateParams());
[email protected]a1feae52010-10-11 22:14:45557 p.disposition = NEW_WINDOW;
[email protected]78e2edc2012-07-01 23:32:28558 chrome::Navigate(&p);
[email protected]a1feae52010-10-11 22:14:45559
560 // Navigate() should have opened a new toplevel window.
561 EXPECT_NE(browser(), p.browser);
[email protected]b35b26b32011-05-05 20:35:14562 EXPECT_TRUE(p.browser->is_type_tabbed());
[email protected]a1feae52010-10-11 22:14:45563
564 // We should now have two windows, the browser() provided by the framework and
565 // the new normal window.
566 EXPECT_EQ(2u, BrowserList::size());
567 EXPECT_EQ(1, browser()->tab_count());
568 EXPECT_EQ(1, p.browser->tab_count());
569}
570
571// This test verifies that navigating with WindowOpenDisposition = INCOGNITO
572// opens a new incognito window if no existing incognito window is present.
573IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_Incognito) {
[email protected]78e2edc2012-07-01 23:32:28574 chrome::NavigateParams p(MakeNavigateParams());
[email protected]a1feae52010-10-11 22:14:45575 p.disposition = OFF_THE_RECORD;
[email protected]78e2edc2012-07-01 23:32:28576 chrome::Navigate(&p);
[email protected]a1feae52010-10-11 22:14:45577
578 // Navigate() should have opened a new toplevel incognito window.
579 EXPECT_NE(browser(), p.browser);
580 EXPECT_EQ(browser()->profile()->GetOffTheRecordProfile(),
581 p.browser->profile());
582
[email protected]d7ff3592010-11-30 21:50:46583 // |source_contents| should be set to NULL because the profile for the new
584 // page is different from the originating page.
585 EXPECT_EQ(NULL, p.source_contents);
586
[email protected]a1feae52010-10-11 22:14:45587 // We should now have two windows, the browser() provided by the framework and
588 // the new incognito window.
589 EXPECT_EQ(2u, BrowserList::size());
590 EXPECT_EQ(1, browser()->tab_count());
591 EXPECT_EQ(1, p.browser->tab_count());
592}
593
594// This test verifies that navigating with WindowOpenDisposition = INCOGNITO
595// reuses an existing incognito window when possible.
596IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_IncognitoRefocus) {
597 Browser* incognito_browser =
[email protected]b35b26b32011-05-05 20:35:14598 CreateEmptyBrowserForType(Browser::TYPE_TABBED,
[email protected]a1feae52010-10-11 22:14:45599 browser()->profile()->GetOffTheRecordProfile());
[email protected]78e2edc2012-07-01 23:32:28600 chrome::NavigateParams p(MakeNavigateParams());
[email protected]a1feae52010-10-11 22:14:45601 p.disposition = OFF_THE_RECORD;
[email protected]78e2edc2012-07-01 23:32:28602 chrome::Navigate(&p);
[email protected]a1feae52010-10-11 22:14:45603
604 // Navigate() should have opened a new tab in the existing incognito window.
605 EXPECT_NE(browser(), p.browser);
606 EXPECT_EQ(p.browser, incognito_browser);
607
608 // We should now have two windows, the browser() provided by the framework and
609 // the incognito window we opened earlier.
610 EXPECT_EQ(2u, BrowserList::size());
611 EXPECT_EQ(1, browser()->tab_count());
612 EXPECT_EQ(2, incognito_browser->tab_count());
613}
614
615// This test verifies that no navigation action occurs when
616// WindowOpenDisposition = SUPPRESS_OPEN.
617IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_SuppressOpen) {
618 RunSuppressTest(SUPPRESS_OPEN);
619}
620
621// This test verifies that no navigation action occurs when
622// WindowOpenDisposition = SAVE_TO_DISK.
623IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_SaveToDisk) {
624 RunSuppressTest(SAVE_TO_DISK);
625}
626
627// This test verifies that no navigation action occurs when
628// WindowOpenDisposition = IGNORE_ACTION.
629IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_IgnoreAction) {
630 RunSuppressTest(IGNORE_ACTION);
631}
632
[email protected]4ebab8ee2012-06-11 22:52:01633// This tests adding a foreground tab with a predefined TabContents.
[email protected]a1feae52010-10-11 22:14:45634IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, TargetContents_ForegroundTab) {
[email protected]78e2edc2012-07-01 23:32:28635 chrome::NavigateParams p(MakeNavigateParams());
[email protected]a1feae52010-10-11 22:14:45636 p.disposition = NEW_FOREGROUND_TAB;
637 p.target_contents = CreateTabContents();
[email protected]78e2edc2012-07-01 23:32:28638 chrome::Navigate(&p);
[email protected]a1feae52010-10-11 22:14:45639
640 // Navigate() should have opened the contents in a new foreground in the
641 // current Browser.
642 EXPECT_EQ(browser(), p.browser);
[email protected]52877dbc62012-06-29 22:22:03643 EXPECT_EQ(chrome::GetActiveTabContents(browser()), p.target_contents);
[email protected]a1feae52010-10-11 22:14:45644
645 // We should have one window, with two tabs.
646 EXPECT_EQ(1u, BrowserList::size());
647 EXPECT_EQ(2, browser()->tab_count());
648}
649
650#if defined(OS_WIN)
[email protected]4ebab8ee2012-06-11 22:52:01651// This tests adding a popup with a predefined TabContents.
[email protected]76edb672011-03-04 21:48:39652IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, DISABLED_TargetContents_Popup) {
[email protected]78e2edc2012-07-01 23:32:28653 chrome::NavigateParams p(MakeNavigateParams());
[email protected]a1feae52010-10-11 22:14:45654 p.disposition = NEW_POPUP;
655 p.target_contents = CreateTabContents();
656 p.window_bounds = gfx::Rect(10, 10, 500, 500);
[email protected]78e2edc2012-07-01 23:32:28657 chrome::Navigate(&p);
[email protected]a1feae52010-10-11 22:14:45658
659 // Navigate() should have opened a new popup window.
660 EXPECT_NE(browser(), p.browser);
[email protected]b35b26b32011-05-05 20:35:14661 EXPECT_TRUE(p.browser->is_type_popup());
662 EXPECT_FALSE(p.browser->is_app());
[email protected]a1feae52010-10-11 22:14:45663
664 // The web platform is weird. The window bounds specified in
665 // |p.window_bounds| are used as follows:
666 // - the origin is used to position the window
[email protected]4ebab8ee2012-06-11 22:52:01667 // - the size is used to size the TabContents of the window.
[email protected]a1feae52010-10-11 22:14:45668 // As such the position of the resulting window will always match
669 // p.window_bounds.origin(), but its size will not. We need to match
670 // the size against the selected tab's view's container size.
671 // Only Windows positions the window according to |p.window_bounds.origin()| -
672 // on Mac the window is offset from the opener and on Linux it always opens
673 // at 0,0.
674 EXPECT_EQ(p.window_bounds.origin(),
675 p.browser->window()->GetRestoredBounds().origin());
676 // All platforms should respect size however provided width > 400 (Mac has a
677 // minimum window width of 400).
678 EXPECT_EQ(p.window_bounds.size(),
[email protected]83ff91c2012-01-05 20:54:13679 p.target_contents->web_contents()->GetView()->GetContainerSize());
[email protected]a1feae52010-10-11 22:14:45680
681 // We should have two windows, the new popup and the browser() provided by the
682 // framework.
683 EXPECT_EQ(2u, BrowserList::size());
684 EXPECT_EQ(1, browser()->tab_count());
685 EXPECT_EQ(1, p.browser->tab_count());
686}
687#endif
688
689// This tests adding a tab at a specific index.
690IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Tabstrip_InsertAtIndex) {
691 // This is not meant to be a comprehensive test of whether or not the tab
692 // implementation of the browser observes the insertion index. That is
693 // covered by the unit tests for TabStripModel. This merely verifies that
694 // insertion index preference is reflected in common cases.
[email protected]78e2edc2012-07-01 23:32:28695 chrome::NavigateParams p(MakeNavigateParams());
[email protected]a1feae52010-10-11 22:14:45696 p.disposition = NEW_FOREGROUND_TAB;
697 p.tabstrip_index = 0;
698 p.tabstrip_add_types = TabStripModel::ADD_FORCE_INDEX;
[email protected]78e2edc2012-07-01 23:32:28699 chrome::Navigate(&p);
[email protected]a1feae52010-10-11 22:14:45700
701 // Navigate() should have inserted a new tab at slot 0 in the tabstrip.
702 EXPECT_EQ(browser(), p.browser);
[email protected]c0849252012-05-12 13:51:27703 EXPECT_EQ(0, browser()->tab_strip_model()->GetIndexOfTabContents(
[email protected]4ebab8ee2012-06-11 22:52:01704 static_cast<const TabContents*>(p.target_contents)));
[email protected]a1feae52010-10-11 22:14:45705
706 // We should have one window - the browser() provided by the framework.
707 EXPECT_EQ(1u, BrowserList::size());
708 EXPECT_EQ(2, browser()->tab_count());
709}
710
[email protected]bb89e7482010-11-17 18:27:04711// This test verifies that constructing params with disposition = SINGLETON_TAB
[email protected]fee320542011-03-02 01:30:49712// and IGNORE_AND_NAVIGATE opens a new tab navigated to the specified URL if
[email protected]67ed83e2011-01-07 22:54:00713// no previous tab with that URL (minus the path) exists.
[email protected]bb89e7482010-11-17 18:27:04714IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
715 Disposition_SingletonTabNew_IgnorePath) {
[email protected]52877dbc62012-06-29 22:22:03716 chrome::AddSelectedTabWithURL(browser(), GetGoogleURL(),
717 content::PAGE_TRANSITION_LINK);
[email protected]bb89e7482010-11-17 18:27:04718
719 // We should have one browser with 2 tabs, the 2nd selected.
720 EXPECT_EQ(1u, BrowserList::size());
721 EXPECT_EQ(2, browser()->tab_count());
[email protected]1ea49d52011-04-12 17:44:44722 EXPECT_EQ(1, browser()->active_index());
[email protected]bb89e7482010-11-17 18:27:04723
724 // Navigate to a new singleton tab with a sub-page.
[email protected]78e2edc2012-07-01 23:32:28725 chrome::NavigateParams p(MakeNavigateParams());
[email protected]bb89e7482010-11-17 18:27:04726 p.disposition = SINGLETON_TAB;
[email protected]a048ad22012-03-23 04:26:56727 p.url = GetContentSettingsURL();
[email protected]78e2edc2012-07-01 23:32:28728 p.window_action = chrome::NavigateParams::SHOW_WINDOW;
729 p.path_behavior = chrome::NavigateParams::IGNORE_AND_NAVIGATE;
730 chrome::Navigate(&p);
[email protected]bb89e7482010-11-17 18:27:04731
732 // The last tab should now be selected and navigated to the sub-page of the
733 // URL.
734 EXPECT_EQ(browser(), p.browser);
735 EXPECT_EQ(3, browser()->tab_count());
[email protected]1ea49d52011-04-12 17:44:44736 EXPECT_EQ(2, browser()->active_index());
[email protected]a048ad22012-03-23 04:26:56737 EXPECT_EQ(GetContentSettingsURL(),
[email protected]f8f93eb2012-09-25 03:06:24738 ShortenUberURL(chrome::GetActiveWebContents(browser())->GetURL()));
[email protected]bb89e7482010-11-17 18:27:04739}
740
741// This test verifies that constructing params with disposition = SINGLETON_TAB
[email protected]fee320542011-03-02 01:30:49742// and IGNORE_AND_NAVIGATE opens an existing tab with the matching URL (minus
[email protected]bb89e7482010-11-17 18:27:04743// the path) which is navigated to the specified URL.
744IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
745 Disposition_SingletonTabExisting_IgnorePath) {
[email protected]ddddfda2011-07-14 23:19:39746 GURL singleton_url1(GetSettingsURL());
[email protected]52877dbc62012-06-29 22:22:03747 chrome::AddSelectedTabWithURL(browser(), singleton_url1,
748 content::PAGE_TRANSITION_LINK);
749 chrome::AddSelectedTabWithURL(browser(), GetGoogleURL(),
750 content::PAGE_TRANSITION_LINK);
[email protected]bb89e7482010-11-17 18:27:04751
752 // We should have one browser with 3 tabs, the 3rd selected.
753 EXPECT_EQ(1u, BrowserList::size());
754 EXPECT_EQ(3, browser()->tab_count());
[email protected]1ea49d52011-04-12 17:44:44755 EXPECT_EQ(2, browser()->active_index());
[email protected]bb89e7482010-11-17 18:27:04756
757 // Navigate to singleton_url1.
[email protected]78e2edc2012-07-01 23:32:28758 chrome::NavigateParams p(MakeNavigateParams());
[email protected]bb89e7482010-11-17 18:27:04759 p.disposition = SINGLETON_TAB;
[email protected]a048ad22012-03-23 04:26:56760 p.url = GetContentSettingsURL();
[email protected]78e2edc2012-07-01 23:32:28761 p.window_action = chrome::NavigateParams::SHOW_WINDOW;
762 p.path_behavior = chrome::NavigateParams::IGNORE_AND_NAVIGATE;
763 chrome::Navigate(&p);
[email protected]bb89e7482010-11-17 18:27:04764
765 // The middle tab should now be selected and navigated to the sub-page of the
766 // URL.
767 EXPECT_EQ(browser(), p.browser);
768 EXPECT_EQ(3, browser()->tab_count());
[email protected]1ea49d52011-04-12 17:44:44769 EXPECT_EQ(1, browser()->active_index());
[email protected]a048ad22012-03-23 04:26:56770 EXPECT_EQ(GetContentSettingsURL(),
[email protected]f8f93eb2012-09-25 03:06:24771 ShortenUberURL(chrome::GetActiveWebContents(browser())->GetURL()));
[email protected]bb89e7482010-11-17 18:27:04772}
773
774// This test verifies that constructing params with disposition = SINGLETON_TAB
[email protected]fee320542011-03-02 01:30:49775// and IGNORE_AND_NAVIGATE opens an existing tab with the matching URL (minus
[email protected]bb89e7482010-11-17 18:27:04776// the path) which is navigated to the specified URL.
777IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
778 Disposition_SingletonTabExistingSubPath_IgnorePath) {
[email protected]a048ad22012-03-23 04:26:56779 GURL singleton_url1(GetContentSettingsURL());
[email protected]52877dbc62012-06-29 22:22:03780 chrome::AddSelectedTabWithURL(browser(), singleton_url1,
781 content::PAGE_TRANSITION_LINK);
782 chrome::AddSelectedTabWithURL(browser(), GetGoogleURL(),
783 content::PAGE_TRANSITION_LINK);
[email protected]bb89e7482010-11-17 18:27:04784
785 // We should have one browser with 3 tabs, the 3rd selected.
786 EXPECT_EQ(1u, BrowserList::size());
787 EXPECT_EQ(3, browser()->tab_count());
[email protected]1ea49d52011-04-12 17:44:44788 EXPECT_EQ(2, browser()->active_index());
[email protected]bb89e7482010-11-17 18:27:04789
790 // Navigate to singleton_url1.
[email protected]78e2edc2012-07-01 23:32:28791 chrome::NavigateParams p(MakeNavigateParams());
[email protected]bb89e7482010-11-17 18:27:04792 p.disposition = SINGLETON_TAB;
[email protected]a048ad22012-03-23 04:26:56793 p.url = GetClearBrowsingDataURL();
[email protected]78e2edc2012-07-01 23:32:28794 p.window_action = chrome::NavigateParams::SHOW_WINDOW;
795 p.path_behavior = chrome::NavigateParams::IGNORE_AND_NAVIGATE;
796 chrome::Navigate(&p);
[email protected]bb89e7482010-11-17 18:27:04797
798 // The middle tab should now be selected and navigated to the sub-page of the
799 // URL.
800 EXPECT_EQ(browser(), p.browser);
801 EXPECT_EQ(3, browser()->tab_count());
[email protected]1ea49d52011-04-12 17:44:44802 EXPECT_EQ(1, browser()->active_index());
[email protected]a048ad22012-03-23 04:26:56803 EXPECT_EQ(GetClearBrowsingDataURL(),
[email protected]f8f93eb2012-09-25 03:06:24804 ShortenUberURL(chrome::GetActiveWebContents(browser())->GetURL()));
[email protected]bb89e7482010-11-17 18:27:04805}
[email protected]2dd85482010-11-06 01:56:47806
[email protected]637b3442011-01-10 23:31:48807// This test verifies that constructing params with disposition = SINGLETON_TAB
[email protected]fee320542011-03-02 01:30:49808// and IGNORE_AND_STAY_PUT opens an existing tab with the matching URL (minus
809// the path).
810IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
811 Disposition_SingletonTabExistingSubPath_IgnorePath2) {
[email protected]a048ad22012-03-23 04:26:56812 GURL singleton_url1(GetContentSettingsURL());
[email protected]52877dbc62012-06-29 22:22:03813 chrome::AddSelectedTabWithURL(browser(), singleton_url1,
814 content::PAGE_TRANSITION_LINK);
815 chrome::AddSelectedTabWithURL(browser(), GetGoogleURL(),
816 content::PAGE_TRANSITION_LINK);
[email protected]fee320542011-03-02 01:30:49817
818 // We should have one browser with 3 tabs, the 3rd selected.
819 EXPECT_EQ(1u, BrowserList::size());
820 EXPECT_EQ(3, browser()->tab_count());
[email protected]1ea49d52011-04-12 17:44:44821 EXPECT_EQ(2, browser()->active_index());
[email protected]fee320542011-03-02 01:30:49822
823 // Navigate to singleton_url1.
[email protected]78e2edc2012-07-01 23:32:28824 chrome::NavigateParams p(MakeNavigateParams());
[email protected]fee320542011-03-02 01:30:49825 p.disposition = SINGLETON_TAB;
[email protected]a048ad22012-03-23 04:26:56826 p.url = GetClearBrowsingDataURL();
[email protected]78e2edc2012-07-01 23:32:28827 p.window_action = chrome::NavigateParams::SHOW_WINDOW;
828 p.path_behavior = chrome::NavigateParams::IGNORE_AND_STAY_PUT;
829 chrome::Navigate(&p);
[email protected]fee320542011-03-02 01:30:49830
831 // The middle tab should now be selected.
832 EXPECT_EQ(browser(), p.browser);
833 EXPECT_EQ(3, browser()->tab_count());
[email protected]1ea49d52011-04-12 17:44:44834 EXPECT_EQ(1, browser()->active_index());
[email protected]fee320542011-03-02 01:30:49835 EXPECT_EQ(singleton_url1,
[email protected]f8f93eb2012-09-25 03:06:24836 ShortenUberURL(chrome::GetActiveWebContents(browser())->GetURL()));
[email protected]fee320542011-03-02 01:30:49837}
838
839// This test verifies that constructing params with disposition = SINGLETON_TAB
840// and IGNORE_AND_NAVIGATE will update the current tab's URL if the currently
[email protected]637b3442011-01-10 23:31:48841// selected tab is a match but has a different path.
842IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
843 Disposition_SingletonTabFocused_IgnorePath) {
[email protected]a048ad22012-03-23 04:26:56844 GURL singleton_url_current(GetContentSettingsURL());
[email protected]52877dbc62012-06-29 22:22:03845 chrome::AddSelectedTabWithURL(browser(), singleton_url_current,
846 content::PAGE_TRANSITION_LINK);
[email protected]637b3442011-01-10 23:31:48847
848 // We should have one browser with 2 tabs, the 2nd selected.
849 EXPECT_EQ(1u, BrowserList::size());
850 EXPECT_EQ(2, browser()->tab_count());
[email protected]1ea49d52011-04-12 17:44:44851 EXPECT_EQ(1, browser()->active_index());
[email protected]637b3442011-01-10 23:31:48852
853 // Navigate to a different settings path.
[email protected]a048ad22012-03-23 04:26:56854 GURL singleton_url_target(GetClearBrowsingDataURL());
[email protected]78e2edc2012-07-01 23:32:28855 chrome::NavigateParams p(MakeNavigateParams());
[email protected]637b3442011-01-10 23:31:48856 p.disposition = SINGLETON_TAB;
857 p.url = singleton_url_target;
[email protected]78e2edc2012-07-01 23:32:28858 p.window_action = chrome::NavigateParams::SHOW_WINDOW;
859 p.path_behavior = chrome::NavigateParams::IGNORE_AND_NAVIGATE;
860 chrome::Navigate(&p);
[email protected]637b3442011-01-10 23:31:48861
862 // The second tab should still be selected, but navigated to the new path.
863 EXPECT_EQ(browser(), p.browser);
864 EXPECT_EQ(2, browser()->tab_count());
[email protected]1ea49d52011-04-12 17:44:44865 EXPECT_EQ(1, browser()->active_index());
[email protected]637b3442011-01-10 23:31:48866 EXPECT_EQ(singleton_url_target,
[email protected]f8f93eb2012-09-25 03:06:24867 ShortenUberURL(chrome::GetActiveWebContents(browser())->GetURL()));
[email protected]637b3442011-01-10 23:31:48868}
869
[email protected]07afd7c2011-02-17 10:07:11870// This test verifies that constructing params with disposition = SINGLETON_TAB
[email protected]fee320542011-03-02 01:30:49871// and IGNORE_AND_NAVIGATE will open an existing matching tab with a different
872// query.
[email protected]07afd7c2011-02-17 10:07:11873IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
874 Disposition_SingletonTabExisting_IgnoreQuery) {
875 int initial_tab_count = browser()->tab_count();
876 GURL singleton_url_current("chrome://settings/internet");
[email protected]52877dbc62012-06-29 22:22:03877 chrome::AddSelectedTabWithURL(browser(), singleton_url_current,
878 content::PAGE_TRANSITION_LINK);
[email protected]07afd7c2011-02-17 10:07:11879
880 EXPECT_EQ(initial_tab_count + 1, browser()->tab_count());
[email protected]1ea49d52011-04-12 17:44:44881 EXPECT_EQ(initial_tab_count, browser()->active_index());
[email protected]07afd7c2011-02-17 10:07:11882
883 // Navigate to a different settings path.
884 GURL singleton_url_target(
885 "chrome://settings/internet?"
886 "servicePath=/profile/ethernet_00aa00aa00aa&networkType=1");
[email protected]78e2edc2012-07-01 23:32:28887 chrome::NavigateParams p(MakeNavigateParams());
[email protected]07afd7c2011-02-17 10:07:11888 p.disposition = SINGLETON_TAB;
889 p.url = singleton_url_target;
[email protected]78e2edc2012-07-01 23:32:28890 p.window_action = chrome::NavigateParams::SHOW_WINDOW;
891 p.path_behavior = chrome::NavigateParams::IGNORE_AND_NAVIGATE;
892 chrome::Navigate(&p);
[email protected]07afd7c2011-02-17 10:07:11893
894 // Last tab should still be selected.
895 EXPECT_EQ(browser(), p.browser);
896 EXPECT_EQ(initial_tab_count + 1, browser()->tab_count());
[email protected]1ea49d52011-04-12 17:44:44897 EXPECT_EQ(initial_tab_count, browser()->active_index());
[email protected]07afd7c2011-02-17 10:07:11898}
899
[email protected]bd817c22011-02-09 08:16:46900// This test verifies that the settings page isn't opened in the incognito
901// window.
[email protected]a048ad22012-03-23 04:26:56902// Disabled until fixed for uber settings: http://crbug.com/111243
[email protected]bd817c22011-02-09 08:16:46903IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
[email protected]a048ad22012-03-23 04:26:56904 DISABLED_Disposition_Settings_UseNonIncognitoWindow) {
[email protected]fc0ed302011-11-29 23:17:19905 RunUseNonIncognitoWindowTest(GetSettingsURL());
[email protected]bd817c22011-02-09 08:16:46906}
907
[email protected]82404cd2011-07-12 19:55:14908// This test verifies that the settings page isn't opened in the incognito
909// window from a non-incognito window (bookmark open-in-incognito trigger).
[email protected]a048ad22012-03-23 04:26:56910// Disabled until fixed for uber settings: http://crbug.com/111243
[email protected]82404cd2011-07-12 19:55:14911IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
[email protected]a048ad22012-03-23 04:26:56912 DISABLED_Disposition_Settings_UseNonIncognitoWindowForBookmark) {
[email protected]78e2edc2012-07-01 23:32:28913 chrome::NavigateParams params(browser(), GetSettingsURL(),
914 content::PAGE_TRANSITION_AUTO_BOOKMARK);
[email protected]82404cd2011-07-12 19:55:14915 params.disposition = OFF_THE_RECORD;
916 {
[email protected]a7fe9112012-07-20 02:34:45917 content::WindowedNotificationObserver observer(
[email protected]ad50def52011-10-19 23:17:07918 content::NOTIFICATION_LOAD_STOP,
919 content::NotificationService::AllSources());
[email protected]78e2edc2012-07-01 23:32:28920 chrome::Navigate(&params);
[email protected]82404cd2011-07-12 19:55:14921 observer.Wait();
922 }
923
924 EXPECT_EQ(1u, BrowserList::size());
[email protected]52877dbc62012-06-29 22:22:03925 EXPECT_EQ(GetSettingsURL(),
[email protected]f8f93eb2012-09-25 03:06:24926 ShortenUberURL(chrome::GetActiveWebContents(browser())->GetURL()));
[email protected]82404cd2011-07-12 19:55:14927}
928
[email protected]93ad8e1c2011-11-08 21:34:05929// Settings page is expected to always open in normal mode regardless
930// of whether the user is trying to open it in incognito mode or not.
931// This test verifies that if incognito mode is forced (by policy), settings
932// page doesn't open at all.
[email protected]a048ad22012-03-23 04:26:56933// Disabled until fixed for uber settings: http://crbug.com/111243
[email protected]93ad8e1c2011-11-08 21:34:05934IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
[email protected]a048ad22012-03-23 04:26:56935 DISABLED_Disposition_Settings_DoNothingIfIncognitoIsForced) {
[email protected]fc0ed302011-11-29 23:17:19936 RunDoNothingIfIncognitoIsForcedTest(GetSettingsURL());
[email protected]93ad8e1c2011-11-08 21:34:05937}
938
[email protected]bd817c22011-02-09 08:16:46939// This test verifies that the bookmarks page isn't opened in the incognito
940// window.
941IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
942 Disposition_Bookmarks_UseNonIncognitoWindow) {
[email protected]fc0ed302011-11-29 23:17:19943 RunUseNonIncognitoWindowTest(GURL(chrome::kChromeUIBookmarksURL));
[email protected]bd817c22011-02-09 08:16:46944}
945
[email protected]93ad8e1c2011-11-08 21:34:05946// Bookmark manager is expected to always open in normal mode regardless
947// of whether the user is trying to open it in incognito mode or not.
948// This test verifies that if incognito mode is forced (by policy), bookmark
949// manager doesn't open at all.
950IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
951 Disposition_Bookmarks_DoNothingIfIncognitoIsForced) {
[email protected]fc0ed302011-11-29 23:17:19952 RunDoNothingIfIncognitoIsForcedTest(GURL(chrome::kChromeUIBookmarksURL));
953}
[email protected]93ad8e1c2011-11-08 21:34:05954
[email protected]fc0ed302011-11-29 23:17:19955// This test verifies that the sync promo page isn't opened in the incognito
956// window.
957IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
958 Disposition_SyncPromo_UseNonIncognitoWindow) {
959 RunUseNonIncognitoWindowTest(GURL(chrome::kChromeUISyncPromoURL));
960}
[email protected]93ad8e1c2011-11-08 21:34:05961
[email protected]fc0ed302011-11-29 23:17:19962// The Sync promo page is expected to always open in normal mode regardless of
963// whether the user is trying to open it in incognito mode or not. This test
964// verifies that if incognito mode is forced (by policy), the sync promo page
965// doesn't open at all.
966IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
967 Disposition_SyncPromo_DoNothingIfIncognitoIsForced) {
968 RunDoNothingIfIncognitoIsForcedTest(GURL(chrome::kChromeUISyncPromoURL));
[email protected]93ad8e1c2011-11-08 21:34:05969}
970
[email protected]7de53c62011-05-13 06:44:16971// This test makes sure a crashed singleton tab reloads from a new navigation.
972IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
973 NavigateToCrashedSingletonTab) {
[email protected]a048ad22012-03-23 04:26:56974 GURL singleton_url(GetContentSettingsURL());
[email protected]52877dbc62012-06-29 22:22:03975 TabContents* tab_contents = chrome::AddSelectedTabWithURL(
976 browser(), singleton_url, content::PAGE_TRANSITION_LINK);
[email protected]4ebab8ee2012-06-11 22:52:01977 WebContents* web_contents = tab_contents->web_contents();
[email protected]7de53c62011-05-13 06:44:16978
979 // We should have one browser with 2 tabs, the 2nd selected.
980 EXPECT_EQ(1u, BrowserList::size());
981 EXPECT_EQ(2, browser()->tab_count());
982 EXPECT_EQ(1, browser()->active_index());
983
984 // Kill the singleton tab.
[email protected]83ff91c2012-01-05 20:54:13985 web_contents->SetIsCrashed(base::TERMINATION_STATUS_PROCESS_CRASHED, -1);
986 EXPECT_TRUE(web_contents->IsCrashed());
[email protected]7de53c62011-05-13 06:44:16987
[email protected]78e2edc2012-07-01 23:32:28988 chrome::NavigateParams p(MakeNavigateParams());
[email protected]7de53c62011-05-13 06:44:16989 p.disposition = SINGLETON_TAB;
990 p.url = singleton_url;
[email protected]78e2edc2012-07-01 23:32:28991 p.window_action = chrome::NavigateParams::SHOW_WINDOW;
992 p.path_behavior = chrome::NavigateParams::IGNORE_AND_NAVIGATE;
[email protected]ddddfda2011-07-14 23:19:39993 ui_test_utils::NavigateToURL(&p);
[email protected]7de53c62011-05-13 06:44:16994
995 // The tab should not be sad anymore.
[email protected]83ff91c2012-01-05 20:54:13996 EXPECT_FALSE(web_contents->IsCrashed());
[email protected]7de53c62011-05-13 06:44:16997}
998
[email protected]fcca741b2011-06-17 22:46:37999IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
1000 NavigateFromDefaultToOptionsInSameTab) {
[email protected]ddddfda2011-07-14 23:19:391001 {
[email protected]a7fe9112012-07-20 02:34:451002 content::WindowedNotificationObserver observer(
[email protected]ad50def52011-10-19 23:17:071003 content::NOTIFICATION_LOAD_STOP,
1004 content::NotificationService::AllSources());
[email protected]5d9cace72012-06-21 16:07:121005 chrome::ShowSettings(browser());
[email protected]ddddfda2011-07-14 23:19:391006 observer.Wait();
1007 }
[email protected]fcca741b2011-06-17 22:46:371008 EXPECT_EQ(1, browser()->tab_count());
[email protected]52877dbc62012-06-29 22:22:031009 EXPECT_EQ(GetSettingsURL(),
[email protected]f8f93eb2012-09-25 03:06:241010 ShortenUberURL(chrome::GetActiveWebContents(browser())->GetURL()));
[email protected]fcca741b2011-06-17 22:46:371011}
1012
1013IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
1014 NavigateFromBlankToOptionsInSameTab) {
[email protected]78e2edc2012-07-01 23:32:281015 chrome::NavigateParams p(MakeNavigateParams());
[email protected]ddddfda2011-07-14 23:19:391016 p.url = GURL(chrome::kAboutBlankURL);
1017 ui_test_utils::NavigateToURL(&p);
[email protected]fcca741b2011-06-17 22:46:371018
[email protected]ddddfda2011-07-14 23:19:391019 {
[email protected]a7fe9112012-07-20 02:34:451020 content::WindowedNotificationObserver observer(
[email protected]ad50def52011-10-19 23:17:071021 content::NOTIFICATION_LOAD_STOP,
1022 content::NotificationService::AllSources());
[email protected]5d9cace72012-06-21 16:07:121023 chrome::ShowSettings(browser());
[email protected]ddddfda2011-07-14 23:19:391024 observer.Wait();
1025 }
[email protected]fcca741b2011-06-17 22:46:371026 EXPECT_EQ(1, browser()->tab_count());
[email protected]52877dbc62012-06-29 22:22:031027 EXPECT_EQ(GetSettingsURL(),
[email protected]f8f93eb2012-09-25 03:06:241028 ShortenUberURL(chrome::GetActiveWebContents(browser())->GetURL()));
[email protected]fcca741b2011-06-17 22:46:371029}
1030
1031IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
1032 NavigateFromNTPToOptionsInSameTab) {
[email protected]78e2edc2012-07-01 23:32:281033 chrome::NavigateParams p(MakeNavigateParams());
[email protected]ddddfda2011-07-14 23:19:391034 p.url = GURL(chrome::kChromeUINewTabURL);
1035 ui_test_utils::NavigateToURL(&p);
[email protected]fcca741b2011-06-17 22:46:371036 EXPECT_EQ(1, browser()->tab_count());
[email protected]ddddfda2011-07-14 23:19:391037 EXPECT_EQ(GURL(chrome::kChromeUINewTabURL),
[email protected]52877dbc62012-06-29 22:22:031038 chrome::GetActiveWebContents(browser())->GetURL());
[email protected]fcca741b2011-06-17 22:46:371039
[email protected]ddddfda2011-07-14 23:19:391040 {
[email protected]a7fe9112012-07-20 02:34:451041 content::WindowedNotificationObserver observer(
[email protected]ad50def52011-10-19 23:17:071042 content::NOTIFICATION_LOAD_STOP,
1043 content::NotificationService::AllSources());
[email protected]5d9cace72012-06-21 16:07:121044 chrome::ShowSettings(browser());
[email protected]ddddfda2011-07-14 23:19:391045 observer.Wait();
1046 }
[email protected]fcca741b2011-06-17 22:46:371047 EXPECT_EQ(1, browser()->tab_count());
[email protected]52877dbc62012-06-29 22:22:031048 EXPECT_EQ(GetSettingsURL(),
[email protected]f8f93eb2012-09-25 03:06:241049 ShortenUberURL(chrome::GetActiveWebContents(browser())->GetURL()));
[email protected]fcca741b2011-06-17 22:46:371050}
1051
1052IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
1053 NavigateFromPageToOptionsInNewTab) {
[email protected]78e2edc2012-07-01 23:32:281054 chrome::NavigateParams p(MakeNavigateParams());
[email protected]ddddfda2011-07-14 23:19:391055 ui_test_utils::NavigateToURL(&p);
[email protected]52877dbc62012-06-29 22:22:031056 EXPECT_EQ(GetGoogleURL(), chrome::GetActiveWebContents(browser())->GetURL());
[email protected]fcca741b2011-06-17 22:46:371057 EXPECT_EQ(1u, BrowserList::size());
1058 EXPECT_EQ(1, browser()->tab_count());
1059
[email protected]ddddfda2011-07-14 23:19:391060 {
[email protected]a7fe9112012-07-20 02:34:451061 content::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(2, browser()->tab_count());
[email protected]52877dbc62012-06-29 22:22:031068 EXPECT_EQ(GetSettingsURL(),
[email protected]f8f93eb2012-09-25 03:06:241069 ShortenUberURL(chrome::GetActiveWebContents(browser())->GetURL()));
[email protected]fcca741b2011-06-17 22:46:371070}
1071
1072IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
1073 NavigateFromNTPToOptionsSingleton) {
[email protected]ddddfda2011-07-14 23:19:391074 {
[email protected]a7fe9112012-07-20 02:34:451075 content::WindowedNotificationObserver observer(
[email protected]ad50def52011-10-19 23:17:071076 content::NOTIFICATION_LOAD_STOP,
1077 content::NotificationService::AllSources());
[email protected]5d9cace72012-06-21 16:07:121078 chrome::ShowSettings(browser());
[email protected]ddddfda2011-07-14 23:19:391079 observer.Wait();
1080 }
[email protected]fcca741b2011-06-17 22:46:371081 EXPECT_EQ(1, browser()->tab_count());
1082
[email protected]a37d4b02012-06-25 21:56:101083 chrome::NewTab(browser());
[email protected]fcca741b2011-06-17 22:46:371084 EXPECT_EQ(2, browser()->tab_count());
1085
[email protected]ddddfda2011-07-14 23:19:391086 {
[email protected]a7fe9112012-07-20 02:34:451087 content::WindowedNotificationObserver observer(
[email protected]ad50def52011-10-19 23:17:071088 content::NOTIFICATION_LOAD_STOP,
1089 content::NotificationService::AllSources());
[email protected]5d9cace72012-06-21 16:07:121090 chrome::ShowSettings(browser());
[email protected]ddddfda2011-07-14 23:19:391091 observer.Wait();
1092 }
[email protected]fcca741b2011-06-17 22:46:371093 EXPECT_EQ(2, browser()->tab_count());
[email protected]52877dbc62012-06-29 22:22:031094 EXPECT_EQ(GetSettingsURL(),
[email protected]f8f93eb2012-09-25 03:06:241095 ShortenUberURL(chrome::GetActiveWebContents(browser())->GetURL()));
[email protected]fcca741b2011-06-17 22:46:371096}
1097
1098IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
1099 NavigateFromNTPToOptionsPageInSameTab) {
[email protected]ddddfda2011-07-14 23:19:391100 {
[email protected]a7fe9112012-07-20 02:34:451101 content::WindowedNotificationObserver observer(
[email protected]ad50def52011-10-19 23:17:071102 content::NOTIFICATION_LOAD_STOP,
1103 content::NotificationService::AllSources());
[email protected]5d9cace72012-06-21 16:07:121104 chrome::ShowClearBrowsingDataDialog(browser());
[email protected]ddddfda2011-07-14 23:19:391105 observer.Wait();
1106 }
[email protected]fcca741b2011-06-17 22:46:371107 EXPECT_EQ(1, browser()->tab_count());
[email protected]a048ad22012-03-23 04:26:561108 EXPECT_EQ(GetClearBrowsingDataURL(),
[email protected]52877dbc62012-06-29 22:22:031109 chrome::GetActiveWebContents(browser())->GetURL());
[email protected]fcca741b2011-06-17 22:46:371110
[email protected]a37d4b02012-06-25 21:56:101111 chrome::NewTab(browser());
[email protected]fcca741b2011-06-17 22:46:371112 EXPECT_EQ(2, browser()->tab_count());
1113
[email protected]ddddfda2011-07-14 23:19:391114 {
[email protected]a7fe9112012-07-20 02:34:451115 content::WindowedNotificationObserver observer(
[email protected]ad50def52011-10-19 23:17:071116 content::NOTIFICATION_LOAD_STOP,
1117 content::NotificationService::AllSources());
[email protected]5d9cace72012-06-21 16:07:121118 chrome::ShowClearBrowsingDataDialog(browser());
[email protected]ddddfda2011-07-14 23:19:391119 observer.Wait();
1120 }
[email protected]fcca741b2011-06-17 22:46:371121 EXPECT_EQ(2, browser()->tab_count());
[email protected]a048ad22012-03-23 04:26:561122 EXPECT_EQ(GetClearBrowsingDataURL(),
[email protected]52877dbc62012-06-29 22:22:031123 chrome::GetActiveWebContents(browser())->GetURL());
[email protected]fcca741b2011-06-17 22:46:371124}
1125
[email protected]ccb8aac2012-05-21 23:00:161126// Times out on mac, fails on linux.
1127// http://crbug.com/119779
1128#if defined(OS_MACOSX) || defined(OS_LINUX)
[email protected]aac43c72012-03-23 18:41:021129#define MAYBE_NavigateFromOtherTabToSingletonOptions DISABLED_NavigateFromOtherTabToSingletonOptions
1130#else
1131#define MAYBE_NavigateFromOtherTabToSingletonOptions NavigatorFrameOtherTabToSingletonOptions
1132#endif
[email protected]fcca741b2011-06-17 22:46:371133IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
[email protected]aac43c72012-03-23 18:41:021134 MAYBE_NavigateFromOtherTabToSingletonOptions) {
[email protected]ddddfda2011-07-14 23:19:391135 {
[email protected]a7fe9112012-07-20 02:34:451136 content::WindowedNotificationObserver observer(
[email protected]ad50def52011-10-19 23:17:071137 content::NOTIFICATION_LOAD_STOP,
1138 content::NotificationService::AllSources());
[email protected]5d9cace72012-06-21 16:07:121139 chrome::ShowSettings(browser());
[email protected]ddddfda2011-07-14 23:19:391140 observer.Wait();
1141 }
1142 {
[email protected]a7fe9112012-07-20 02:34:451143 content::WindowedNotificationObserver observer(
[email protected]ad50def52011-10-19 23:17:071144 content::NOTIFICATION_LOAD_STOP,
1145 content::NotificationService::AllSources());
[email protected]52877dbc62012-06-29 22:22:031146 chrome::AddSelectedTabWithURL(browser(), GetGoogleURL(),
1147 content::PAGE_TRANSITION_LINK);
[email protected]ddddfda2011-07-14 23:19:391148 observer.Wait();
1149 }
[email protected]fcca741b2011-06-17 22:46:371150
[email protected]ddddfda2011-07-14 23:19:391151 {
[email protected]a7fe9112012-07-20 02:34:451152 content::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::ShowSettings(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]ddddfda2011-07-14 23:19:391159 EXPECT_EQ(GetSettingsURL(),
[email protected]f8f93eb2012-09-25 03:06:241160 ShortenUberURL(chrome::GetActiveWebContents(browser())->GetURL()));
[email protected]fcca741b2011-06-17 22:46:371161}
1162
[email protected]26c53e662011-07-09 02:21:021163// Tests that when a new tab is opened from the omnibox, the focus is moved from
1164// the omnibox for the current tab.
1165IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
1166 NavigateFromOmniboxIntoNewTab) {
1167 GURL url("http://www.google.com/");
1168 GURL url2("http://maps.google.com/");
1169
1170 // Navigate to url.
[email protected]78e2edc2012-07-01 23:32:281171 chrome::NavigateParams p(MakeNavigateParams());
[email protected]26c53e662011-07-09 02:21:021172 p.disposition = CURRENT_TAB;
1173 p.url = url;
[email protected]78e2edc2012-07-01 23:32:281174 chrome::Navigate(&p);
[email protected]26c53e662011-07-09 02:21:021175
1176 // Focus the omnibox.
[email protected]a37d4b02012-06-25 21:56:101177 chrome::FocusLocationBar(browser());
[email protected]26c53e662011-07-09 02:21:021178
[email protected]fbdc4232012-06-24 15:28:371179 OmniboxEditController* controller =
[email protected]fb8e3a32012-05-10 21:03:521180 browser()->window()->GetLocationBar()->GetLocationEntry()->model()->
[email protected]26c53e662011-07-09 02:21:021181 controller();
1182
1183 // Simulate an alt-enter.
1184 controller->OnAutocompleteAccept(url2, NEW_FOREGROUND_TAB,
[email protected]2905f742011-10-13 03:51:581185 content::PAGE_TRANSITION_TYPED, GURL());
[email protected]26c53e662011-07-09 02:21:021186
1187 // Make sure the second tab is selected.
1188 EXPECT_EQ(1, browser()->active_index());
1189
1190 // The tab contents should have the focus in the second tab.
[email protected]f2159ba2012-04-17 19:13:211191 EXPECT_TRUE(ui_test_utils::IsViewFocused(browser(), VIEW_ID_TAB_CONTAINER));
[email protected]26c53e662011-07-09 02:21:021192
1193 // Go back to the first tab. The focus should not be in the omnibox.
[email protected]a37d4b02012-06-25 21:56:101194 chrome::SelectPreviousTab(browser());
[email protected]26c53e662011-07-09 02:21:021195 EXPECT_EQ(0, browser()->active_index());
1196 EXPECT_FALSE(ui_test_utils::IsViewFocused(browser(),
1197 VIEW_ID_LOCATION_BAR));
1198}
1199
[email protected]a048ad22012-03-23 04:26:561200// TODO(csilv): Update this for uber page. http://crbug.com/111579.
[email protected]ddddfda2011-07-14 23:19:391201IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
[email protected]a048ad22012-03-23 04:26:561202 DISABLED_NavigateFromDefaultToHistoryInSameTab) {
[email protected]ddddfda2011-07-14 23:19:391203 {
[email protected]a7fe9112012-07-20 02:34:451204 content::WindowedNotificationObserver observer(
[email protected]ad50def52011-10-19 23:17:071205 content::NOTIFICATION_LOAD_STOP,
1206 content::NotificationService::AllSources());
[email protected]5d9cace72012-06-21 16:07:121207 chrome::ShowHistory(browser());
[email protected]ddddfda2011-07-14 23:19:391208 observer.Wait();
1209 }
1210 EXPECT_EQ(1, browser()->tab_count());
[email protected]11e03fb2012-03-03 19:07:051211 EXPECT_EQ(GURL(chrome::kChromeUIHistoryFrameURL),
[email protected]52877dbc62012-06-29 22:22:031212 chrome::GetActiveWebContents(browser())->GetURL());
[email protected]ddddfda2011-07-14 23:19:391213}
1214
1215IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
1216 NavigateFromDefaultToBookmarksInSameTab) {
1217 {
[email protected]a7fe9112012-07-20 02:34:451218 content::WindowedNotificationObserver observer(
[email protected]ad50def52011-10-19 23:17:071219 content::NOTIFICATION_LOAD_STOP,
1220 content::NotificationService::AllSources());
[email protected]5d9cace72012-06-21 16:07:121221 chrome::ShowBookmarkManager(browser());
[email protected]ddddfda2011-07-14 23:19:391222 observer.Wait();
1223 }
1224 EXPECT_EQ(1, browser()->tab_count());
1225 EXPECT_EQ(GURL(chrome::kChromeUIBookmarksURL),
[email protected]52877dbc62012-06-29 22:22:031226 chrome::GetActiveWebContents(browser())->GetURL());
[email protected]ddddfda2011-07-14 23:19:391227}
1228
1229IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
1230 NavigateFromDefaultToDownloadsInSameTab) {
1231 {
[email protected]a7fe9112012-07-20 02:34:451232 content::WindowedNotificationObserver observer(
[email protected]ad50def52011-10-19 23:17:071233 content::NOTIFICATION_LOAD_STOP,
1234 content::NotificationService::AllSources());
[email protected]5d9cace72012-06-21 16:07:121235 chrome::ShowDownloads(browser());
[email protected]ddddfda2011-07-14 23:19:391236 observer.Wait();
1237 }
1238 EXPECT_EQ(1, browser()->tab_count());
1239 EXPECT_EQ(GURL(chrome::kChromeUIDownloadsURL),
[email protected]52877dbc62012-06-29 22:22:031240 chrome::GetActiveWebContents(browser())->GetURL());
[email protected]ddddfda2011-07-14 23:19:391241}
1242
[email protected]8fb16a82012-08-17 02:17:591243IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
1244 NavigateWithoutBrowser) {
1245 // First navigate using the profile of the existing browser window, and
1246 // check that the window is reused.
1247 chrome::NavigateParams params(browser()->profile(), GetGoogleURL(),
1248 content::PAGE_TRANSITION_LINK);
1249 ui_test_utils::NavigateToURL(&params);
1250 EXPECT_EQ(1u, BrowserList::size());
1251
1252 // Now navigate using the incognito profile and check that a new window
1253 // is created.
1254 chrome::NavigateParams params_incognito(
1255 browser()->profile()->GetOffTheRecordProfile(),
1256 GetGoogleURL(), content::PAGE_TRANSITION_LINK);
1257 ui_test_utils::NavigateToURL(&params_incognito);
1258 EXPECT_EQ(2u, BrowserList::size());
1259}
1260
[email protected]ddddfda2011-07-14 23:19:391261} // namespace