[email protected] | 8643e6d | 2012-01-18 20:26:10 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
[email protected] | a1feae5 | 2010-10-11 22:14:45 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
[email protected] | bd817c2 | 2011-02-09 08:16:46 | [diff] [blame] | 5 | #include "chrome/browser/ui/browser_navigator_browsertest.h" |
| 6 | |
[email protected] | bb89e748 | 2010-11-17 18:27:04 | [diff] [blame] | 7 | #include "base/command_line.h" |
[email protected] | 26c53e66 | 2011-07-09 02:21:02 | [diff] [blame] | 8 | #include "chrome/app/chrome_command_ids.h" |
[email protected] | 93ad8e1c | 2011-11-08 21:34:05 | [diff] [blame] | 9 | #include "chrome/browser/prefs/incognito_mode_prefs.h" |
| 10 | #include "chrome/browser/prefs/pref_service.h" |
[email protected] | 8ecad5e | 2010-12-02 21:18:33 | [diff] [blame] | 11 | #include "chrome/browser/profiles/profile.h" |
[email protected] | a37d4b0 | 2012-06-25 21:56:10 | [diff] [blame] | 12 | #include "chrome/browser/ui/browser_commands.h" |
[email protected] | bb89e748 | 2010-11-17 18:27:04 | [diff] [blame] | 13 | #include "chrome/browser/ui/browser_list.h" |
[email protected] | 339d6dd | 2010-11-12 00:41:58 | [diff] [blame] | 14 | #include "chrome/browser/ui/browser_navigator.h" |
[email protected] | 52877dbc6 | 2012-06-29 22:22:03 | [diff] [blame] | 15 | #include "chrome/browser/ui/browser_tabstrip.h" |
[email protected] | bb89e748 | 2010-11-17 18:27:04 | [diff] [blame] | 16 | #include "chrome/browser/ui/browser_window.h" |
[email protected] | 5d9cace7 | 2012-06-21 16:07:12 | [diff] [blame] | 17 | #include "chrome/browser/ui/chrome_pages.h" |
[email protected] | b56e2e3 | 2012-05-11 21:18:04 | [diff] [blame] | 18 | #include "chrome/browser/ui/tabs/tab_strip_model.h" |
[email protected] | bb89e748 | 2010-11-17 18:27:04 | [diff] [blame] | 19 | #include "chrome/common/chrome_switches.h" |
[email protected] | 93ad8e1c | 2011-11-08 21:34:05 | [diff] [blame] | 20 | #include "chrome/common/pref_names.h" |
[email protected] | ddddfda | 2011-07-14 23:19:39 | [diff] [blame] | 21 | #include "chrome/common/url_constants.h" |
[email protected] | af44e7fb | 2011-07-29 18:32:32 | [diff] [blame] | 22 | #include "chrome/test/base/ui_test_utils.h" |
[email protected] | ad50def5 | 2011-10-19 23:17:07 | [diff] [blame] | 23 | #include "content/public/browser/notification_service.h" |
[email protected] | 0d6e9bd | 2011-10-18 04:29:16 | [diff] [blame] | 24 | #include "content/public/browser/notification_types.h" |
[email protected] | 83ff91c | 2012-01-05 20:54:13 | [diff] [blame] | 25 | #include "content/public/browser/web_contents.h" |
[email protected] | 8643e6d | 2012-01-18 20:26:10 | [diff] [blame] | 26 | #include "content/public/browser/web_contents_view.h" |
[email protected] | c47317e | 2012-06-20 22:35:31 | [diff] [blame] | 27 | #include "ipc/ipc_message.h" |
[email protected] | a1feae5 | 2010-10-11 22:14:45 | [diff] [blame] | 28 | |
[email protected] | 4ca1530 | 2012-01-03 05:53:20 | [diff] [blame] | 29 | using content::WebContents; |
| 30 | |
[email protected] | ddddfda | 2011-07-14 23:19:39 | [diff] [blame] | 31 | namespace { |
| 32 | |
| 33 | GURL GetGoogleURL() { |
[email protected] | bd817c2 | 2011-02-09 08:16:46 | [diff] [blame] | 34 | return GURL("http://www.google.com/"); |
| 35 | } |
[email protected] | a1feae5 | 2010-10-11 22:14:45 | [diff] [blame] | 36 | |
[email protected] | ddddfda | 2011-07-14 23:19:39 | [diff] [blame] | 37 | GURL GetSettingsURL() { |
[email protected] | f8f93eb | 2012-09-25 03:06:24 | [diff] [blame] | 38 | return GURL(chrome::kChromeUISettingsURL); |
[email protected] | ddddfda | 2011-07-14 23:19:39 | [diff] [blame] | 39 | } |
| 40 | |
[email protected] | a048ad2 | 2012-03-23 04:26:56 | [diff] [blame] | 41 | GURL GetContentSettingsURL() { |
| 42 | return GetSettingsURL().Resolve(chrome::kContentSettingsExceptionsSubPage); |
[email protected] | ddddfda | 2011-07-14 23:19:39 | [diff] [blame] | 43 | } |
| 44 | |
[email protected] | a048ad2 | 2012-03-23 04:26:56 | [diff] [blame] | 45 | GURL GetClearBrowsingDataURL() { |
| 46 | return GetSettingsURL().Resolve(chrome::kClearBrowserDataSubPage); |
[email protected] | ddddfda | 2011-07-14 23:19:39 | [diff] [blame] | 47 | } |
| 48 | |
[email protected] | f8f93eb | 2012-09-25 03:06:24 | [diff] [blame] | 49 | // Converts long uber URLs ("chrome://chrome/foo/") to short (virtual) URLs |
| 50 | // ("chrome://foo/"). This should be used to convert the return value of |
| 51 | // WebContentsImpl::GetURL before comparison because it can return either the |
| 52 | // real URL or the virtual URL. |
| 53 | GURL ShortenUberURL(const GURL& url) { |
| 54 | std::string url_string = url.spec(); |
| 55 | const std::string long_prefix = "chrome://chrome/"; |
| 56 | const std::string short_prefix = "chrome://"; |
| 57 | if (url_string.find(long_prefix) != 0) |
| 58 | return url; |
| 59 | url_string.replace(0, long_prefix.length(), short_prefix); |
| 60 | return GURL(url_string); |
| 61 | } |
| 62 | |
[email protected] | ddddfda | 2011-07-14 23:19:39 | [diff] [blame] | 63 | } // namespace |
| 64 | |
[email protected] | 78e2edc | 2012-07-01 23:32:28 | [diff] [blame] | 65 | chrome::NavigateParams BrowserNavigatorTest::MakeNavigateParams() const { |
[email protected] | bd817c2 | 2011-02-09 08:16:46 | [diff] [blame] | 66 | return MakeNavigateParams(browser()); |
| 67 | } |
[email protected] | a1feae5 | 2010-10-11 22:14:45 | [diff] [blame] | 68 | |
[email protected] | 78e2edc | 2012-07-01 23:32:28 | [diff] [blame] | 69 | chrome::NavigateParams BrowserNavigatorTest::MakeNavigateParams( |
[email protected] | bd817c2 | 2011-02-09 08:16:46 | [diff] [blame] | 70 | Browser* browser) const { |
[email protected] | 78e2edc | 2012-07-01 23:32:28 | [diff] [blame] | 71 | chrome::NavigateParams params(browser, GetGoogleURL(), |
| 72 | content::PAGE_TRANSITION_LINK); |
| 73 | params.window_action = chrome::NavigateParams::SHOW_WINDOW; |
[email protected] | bd817c2 | 2011-02-09 08:16:46 | [diff] [blame] | 74 | return params; |
| 75 | } |
[email protected] | a1feae5 | 2010-10-11 22:14:45 | [diff] [blame] | 76 | |
[email protected] | bd817c2 | 2011-02-09 08:16:46 | [diff] [blame] | 77 | Browser* BrowserNavigatorTest::CreateEmptyBrowserForType(Browser::Type type, |
| 78 | Profile* profile) { |
[email protected] | a4fe6701 | 2012-07-25 20:14:29 | [diff] [blame] | 79 | Browser* browser = new Browser(Browser::CreateParams(type, profile)); |
[email protected] | 686221c | 2012-11-08 07:30:10 | [diff] [blame] | 80 | chrome::AddBlankTabAt(browser, -1, true); |
[email protected] | bd817c2 | 2011-02-09 08:16:46 | [diff] [blame] | 81 | return browser; |
| 82 | } |
[email protected] | a1feae5 | 2010-10-11 22:14:45 | [diff] [blame] | 83 | |
[email protected] | b35b26b3 | 2011-05-05 20:35:14 | [diff] [blame] | 84 | Browser* BrowserNavigatorTest::CreateEmptyBrowserForApp(Browser::Type type, |
| 85 | Profile* profile) { |
[email protected] | a4fe6701 | 2012-07-25 20:14:29 | [diff] [blame] | 86 | Browser* browser = new Browser( |
[email protected] | da22aa6 | 2012-04-04 18:54:35 | [diff] [blame] | 87 | Browser::CreateParams::CreateForApp( |
| 88 | Browser::TYPE_POPUP, "Test", gfx::Rect(), profile)); |
[email protected] | 686221c | 2012-11-08 07:30:10 | [diff] [blame] | 89 | chrome::AddBlankTabAt(browser, -1, true); |
[email protected] | b35b26b3 | 2011-05-05 20:35:14 | [diff] [blame] | 90 | return browser; |
| 91 | } |
| 92 | |
[email protected] | e232c99 | 2012-12-06 12:43:20 | [diff] [blame] | 93 | WebContents* BrowserNavigatorTest::CreateWebContents() { |
[email protected] | 54944cde | 2012-12-09 09:24:59 | [diff] [blame] | 94 | content::WebContents::CreateParams create_params(browser()->profile()); |
[email protected] | ed245db | 2012-12-18 08:00:45 | [diff] [blame^] | 95 | content::WebContents* base_web_contents = |
| 96 | chrome::GetActiveWebContents(browser()); |
| 97 | if (base_web_contents) { |
| 98 | create_params.initial_size = |
| 99 | base_web_contents->GetView()->GetContainerSize(); |
| 100 | } |
[email protected] | 54944cde | 2012-12-09 09:24:59 | [diff] [blame] | 101 | return WebContents::Create(create_params); |
[email protected] | bd817c2 | 2011-02-09 08:16:46 | [diff] [blame] | 102 | } |
[email protected] | a1feae5 | 2010-10-11 22:14:45 | [diff] [blame] | 103 | |
[email protected] | bd817c2 | 2011-02-09 08:16:46 | [diff] [blame] | 104 | void BrowserNavigatorTest::RunSuppressTest(WindowOpenDisposition disposition) { |
[email protected] | 52877dbc6 | 2012-06-29 22:22:03 | [diff] [blame] | 105 | GURL old_url = chrome::GetActiveWebContents(browser())->GetURL(); |
[email protected] | 78e2edc | 2012-07-01 23:32:28 | [diff] [blame] | 106 | chrome::NavigateParams p(MakeNavigateParams()); |
[email protected] | bd817c2 | 2011-02-09 08:16:46 | [diff] [blame] | 107 | p.disposition = disposition; |
[email protected] | 78e2edc | 2012-07-01 23:32:28 | [diff] [blame] | 108 | chrome::Navigate(&p); |
[email protected] | a1feae5 | 2010-10-11 22:14:45 | [diff] [blame] | 109 | |
[email protected] | bd817c2 | 2011-02-09 08:16:46 | [diff] [blame] | 110 | // Nothing should have happened as a result of Navigate(); |
| 111 | EXPECT_EQ(1, browser()->tab_count()); |
| 112 | EXPECT_EQ(1u, BrowserList::size()); |
[email protected] | 52877dbc6 | 2012-06-29 22:22:03 | [diff] [blame] | 113 | EXPECT_EQ(old_url, chrome::GetActiveWebContents(browser())->GetURL()); |
[email protected] | bd817c2 | 2011-02-09 08:16:46 | [diff] [blame] | 114 | } |
[email protected] | bb89e748 | 2010-11-17 18:27:04 | [diff] [blame] | 115 | |
[email protected] | fc0ed30 | 2011-11-29 23:17:19 | [diff] [blame] | 116 | void BrowserNavigatorTest::RunUseNonIncognitoWindowTest(const GURL& url) { |
| 117 | Browser* incognito_browser = CreateIncognitoBrowser(); |
| 118 | |
| 119 | EXPECT_EQ(2u, BrowserList::size()); |
| 120 | EXPECT_EQ(1, browser()->tab_count()); |
| 121 | EXPECT_EQ(1, incognito_browser->tab_count()); |
| 122 | |
| 123 | // Navigate to the page. |
[email protected] | 78e2edc | 2012-07-01 23:32:28 | [diff] [blame] | 124 | chrome::NavigateParams p(MakeNavigateParams(incognito_browser)); |
[email protected] | fc0ed30 | 2011-11-29 23:17:19 | [diff] [blame] | 125 | p.disposition = SINGLETON_TAB; |
| 126 | p.url = url; |
[email protected] | 78e2edc | 2012-07-01 23:32:28 | [diff] [blame] | 127 | p.window_action = chrome::NavigateParams::SHOW_WINDOW; |
| 128 | chrome::Navigate(&p); |
[email protected] | fc0ed30 | 2011-11-29 23:17:19 | [diff] [blame] | 129 | |
| 130 | // This page should be opened in browser() window. |
| 131 | EXPECT_NE(incognito_browser, p.browser); |
| 132 | EXPECT_EQ(browser(), p.browser); |
| 133 | EXPECT_EQ(2, browser()->tab_count()); |
[email protected] | 52877dbc6 | 2012-06-29 22:22:03 | [diff] [blame] | 134 | EXPECT_EQ(url, chrome::GetActiveWebContents(browser())->GetURL()); |
[email protected] | fc0ed30 | 2011-11-29 23:17:19 | [diff] [blame] | 135 | } |
| 136 | |
| 137 | void BrowserNavigatorTest::RunDoNothingIfIncognitoIsForcedTest( |
| 138 | const GURL& url) { |
| 139 | Browser* browser = CreateIncognitoBrowser(); |
| 140 | |
| 141 | // Set kIncognitoModeAvailability to FORCED. |
| 142 | PrefService* prefs1 = browser->profile()->GetPrefs(); |
| 143 | prefs1->SetInteger(prefs::kIncognitoModeAvailability, |
| 144 | IncognitoModePrefs::FORCED); |
| 145 | PrefService* prefs2 = browser->profile()->GetOriginalProfile()->GetPrefs(); |
| 146 | prefs2->SetInteger(prefs::kIncognitoModeAvailability, |
| 147 | IncognitoModePrefs::FORCED); |
| 148 | |
| 149 | // Navigate to the page. |
[email protected] | 78e2edc | 2012-07-01 23:32:28 | [diff] [blame] | 150 | chrome::NavigateParams p(MakeNavigateParams(browser)); |
[email protected] | fc0ed30 | 2011-11-29 23:17:19 | [diff] [blame] | 151 | p.disposition = OFF_THE_RECORD; |
| 152 | p.url = url; |
[email protected] | 78e2edc | 2012-07-01 23:32:28 | [diff] [blame] | 153 | p.window_action = chrome::NavigateParams::SHOW_WINDOW; |
| 154 | chrome::Navigate(&p); |
[email protected] | fc0ed30 | 2011-11-29 23:17:19 | [diff] [blame] | 155 | |
| 156 | // The page should not be opened. |
| 157 | EXPECT_EQ(browser, p.browser); |
| 158 | EXPECT_EQ(1, browser->tab_count()); |
| 159 | EXPECT_EQ(GURL(chrome::kAboutBlankURL), |
[email protected] | 52877dbc6 | 2012-06-29 22:22:03 | [diff] [blame] | 160 | chrome::GetActiveWebContents(browser)->GetURL()); |
[email protected] | fc0ed30 | 2011-11-29 23:17:19 | [diff] [blame] | 161 | } |
| 162 | |
[email protected] | 6c2381d | 2011-10-19 02:52:53 | [diff] [blame] | 163 | void BrowserNavigatorTest::Observe( |
| 164 | int type, |
| 165 | const content::NotificationSource& source, |
| 166 | const content::NotificationDetails& details) { |
[email protected] | 43211582 | 2011-07-10 15:52:27 | [diff] [blame] | 167 | switch (type) { |
[email protected] | d53a08c | 2012-07-18 20:35:30 | [diff] [blame] | 168 | case content::NOTIFICATION_WEB_CONTENTS_RENDER_VIEW_HOST_CREATED: { |
[email protected] | bd817c2 | 2011-02-09 08:16:46 | [diff] [blame] | 169 | ++this->created_tab_contents_count_; |
| 170 | break; |
[email protected] | fa7ebe0 | 2010-11-29 23:04:57 | [diff] [blame] | 171 | } |
[email protected] | bd817c2 | 2011-02-09 08:16:46 | [diff] [blame] | 172 | default: |
| 173 | break; |
[email protected] | fa7ebe0 | 2010-11-29 23:04:57 | [diff] [blame] | 174 | } |
[email protected] | bd817c2 | 2011-02-09 08:16:46 | [diff] [blame] | 175 | } |
[email protected] | fa7ebe0 | 2010-11-29 23:04:57 | [diff] [blame] | 176 | |
[email protected] | ddddfda | 2011-07-14 23:19:39 | [diff] [blame] | 177 | |
[email protected] | bd817c2 | 2011-02-09 08:16:46 | [diff] [blame] | 178 | namespace { |
[email protected] | a1feae5 | 2010-10-11 22:14:45 | [diff] [blame] | 179 | |
[email protected] | a1feae5 | 2010-10-11 22:14:45 | [diff] [blame] | 180 | // This test verifies that when a navigation occurs within a tab, the tab count |
| 181 | // of the Browser remains the same and the current tab bears the loaded URL. |
| 182 | IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_CurrentTab) { |
[email protected] | ddddfda | 2011-07-14 23:19:39 | [diff] [blame] | 183 | ui_test_utils::NavigateToURL(browser(), GetGoogleURL()); |
[email protected] | 52877dbc6 | 2012-06-29 22:22:03 | [diff] [blame] | 184 | EXPECT_EQ(GetGoogleURL(), chrome::GetActiveWebContents(browser())->GetURL()); |
[email protected] | a1feae5 | 2010-10-11 22:14:45 | [diff] [blame] | 185 | // We should have one window with one tab. |
| 186 | EXPECT_EQ(1u, BrowserList::size()); |
| 187 | EXPECT_EQ(1, browser()->tab_count()); |
| 188 | } |
| 189 | |
[email protected] | bd817c2 | 2011-02-09 08:16:46 | [diff] [blame] | 190 | // This test verifies that a singleton tab is refocused if one is already opened |
[email protected] | 19d9f3a | 2010-10-14 21:49:36 | [diff] [blame] | 191 | // in another or an existing window, or added if it is not. |
| 192 | IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_SingletonTabExisting) { |
[email protected] | 19d9f3a | 2010-10-14 21:49:36 | [diff] [blame] | 193 | GURL singleton_url1("http://maps.google.com/"); |
[email protected] | fa7ebe0 | 2010-11-29 23:04:57 | [diff] [blame] | 194 | |
[email protected] | e232c99 | 2012-12-06 12:43:20 | [diff] [blame] | 195 | // Register for a notification if an additional WebContents was instantiated. |
[email protected] | bd817c2 | 2011-02-09 08:16:46 | [diff] [blame] | 196 | // Opening a Singleton tab that is already opened should not be opening a new |
[email protected] | e232c99 | 2012-12-06 12:43:20 | [diff] [blame] | 197 | // tab nor be creating a new WebContents object. |
[email protected] | 6c2381d | 2011-10-19 02:52:53 | [diff] [blame] | 198 | content::NotificationRegistrar registrar; |
[email protected] | fa7ebe0 | 2010-11-29 23:04:57 | [diff] [blame] | 199 | |
| 200 | // As the registrar object goes out of scope, this will get unregistered |
[email protected] | d53a08c | 2012-07-18 20:35:30 | [diff] [blame] | 201 | registrar.Add(this, |
| 202 | content::NOTIFICATION_WEB_CONTENTS_RENDER_VIEW_HOST_CREATED, |
[email protected] | ad50def5 | 2011-10-19 23:17:07 | [diff] [blame] | 203 | content::NotificationService::AllSources()); |
[email protected] | fa7ebe0 | 2010-11-29 23:04:57 | [diff] [blame] | 204 | |
[email protected] | 52877dbc6 | 2012-06-29 22:22:03 | [diff] [blame] | 205 | chrome::AddSelectedTabWithURL(browser(), singleton_url1, |
| 206 | content::PAGE_TRANSITION_LINK); |
| 207 | chrome::AddSelectedTabWithURL(browser(), GetGoogleURL(), |
| 208 | content::PAGE_TRANSITION_LINK); |
[email protected] | 19d9f3a | 2010-10-14 21:49:36 | [diff] [blame] | 209 | |
| 210 | // We should have one browser with 3 tabs, the 3rd selected. |
| 211 | EXPECT_EQ(1u, BrowserList::size()); |
[email protected] | 1ea49d5 | 2011-04-12 17:44:44 | [diff] [blame] | 212 | EXPECT_EQ(2, browser()->active_index()); |
[email protected] | 19d9f3a | 2010-10-14 21:49:36 | [diff] [blame] | 213 | |
[email protected] | fa7ebe0 | 2010-11-29 23:04:57 | [diff] [blame] | 214 | unsigned int previous_tab_contents_count = |
| 215 | created_tab_contents_count_ = 0; |
| 216 | |
[email protected] | 19d9f3a | 2010-10-14 21:49:36 | [diff] [blame] | 217 | // Navigate to singleton_url1. |
[email protected] | 78e2edc | 2012-07-01 23:32:28 | [diff] [blame] | 218 | chrome::NavigateParams p(MakeNavigateParams()); |
[email protected] | 19d9f3a | 2010-10-14 21:49:36 | [diff] [blame] | 219 | p.disposition = SINGLETON_TAB; |
| 220 | p.url = singleton_url1; |
[email protected] | 78e2edc | 2012-07-01 23:32:28 | [diff] [blame] | 221 | chrome::Navigate(&p); |
[email protected] | 19d9f3a | 2010-10-14 21:49:36 | [diff] [blame] | 222 | |
| 223 | // The middle tab should now be selected. |
| 224 | EXPECT_EQ(browser(), p.browser); |
[email protected] | 1ea49d5 | 2011-04-12 17:44:44 | [diff] [blame] | 225 | EXPECT_EQ(1, browser()->active_index()); |
[email protected] | fa7ebe0 | 2010-11-29 23:04:57 | [diff] [blame] | 226 | |
| 227 | // No tab contents should have been created |
| 228 | EXPECT_EQ(previous_tab_contents_count, |
| 229 | created_tab_contents_count_); |
[email protected] | 19d9f3a | 2010-10-14 21:49:36 | [diff] [blame] | 230 | } |
| 231 | |
| 232 | IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, |
[email protected] | 578c696 | 2011-08-24 22:06:40 | [diff] [blame] | 233 | Disposition_SingletonTabRespectingRef) { |
| 234 | GURL singleton_ref_url1("http://maps.google.com/#a"); |
| 235 | GURL singleton_ref_url2("http://maps.google.com/#b"); |
| 236 | GURL singleton_ref_url3("http://maps.google.com/"); |
| 237 | |
[email protected] | 52877dbc6 | 2012-06-29 22:22:03 | [diff] [blame] | 238 | chrome::AddSelectedTabWithURL(browser(), singleton_ref_url1, |
| 239 | content::PAGE_TRANSITION_LINK); |
[email protected] | 578c696 | 2011-08-24 22:06:40 | [diff] [blame] | 240 | |
| 241 | // We should have one browser with 2 tabs, 2nd selected. |
| 242 | EXPECT_EQ(1u, BrowserList::size()); |
| 243 | EXPECT_EQ(2, browser()->tab_count()); |
| 244 | EXPECT_EQ(1, browser()->active_index()); |
| 245 | |
| 246 | // Navigate to singleton_url2. |
[email protected] | 78e2edc | 2012-07-01 23:32:28 | [diff] [blame] | 247 | chrome::NavigateParams p(MakeNavigateParams()); |
[email protected] | 578c696 | 2011-08-24 22:06:40 | [diff] [blame] | 248 | p.disposition = SINGLETON_TAB; |
| 249 | p.url = singleton_ref_url2; |
[email protected] | 78e2edc | 2012-07-01 23:32:28 | [diff] [blame] | 250 | chrome::Navigate(&p); |
[email protected] | 578c696 | 2011-08-24 22:06:40 | [diff] [blame] | 251 | |
| 252 | // We should now have 2 tabs, the 2nd one selected. |
| 253 | EXPECT_EQ(browser(), p.browser); |
| 254 | EXPECT_EQ(2, browser()->tab_count()); |
| 255 | EXPECT_EQ(1, browser()->active_index()); |
| 256 | |
| 257 | // Navigate to singleton_url2, but with respect ref set. |
| 258 | p = MakeNavigateParams(); |
| 259 | p.disposition = SINGLETON_TAB; |
| 260 | p.url = singleton_ref_url2; |
[email protected] | 78e2edc | 2012-07-01 23:32:28 | [diff] [blame] | 261 | p.ref_behavior = chrome::NavigateParams::RESPECT_REF; |
| 262 | chrome::Navigate(&p); |
[email protected] | 578c696 | 2011-08-24 22:06:40 | [diff] [blame] | 263 | |
| 264 | // We should now have 3 tabs, the 3th one selected. |
| 265 | EXPECT_EQ(browser(), p.browser); |
| 266 | EXPECT_EQ(3, browser()->tab_count()); |
| 267 | EXPECT_EQ(2, browser()->active_index()); |
| 268 | |
| 269 | // Navigate to singleton_url3. |
| 270 | p = MakeNavigateParams(); |
| 271 | p.disposition = SINGLETON_TAB; |
| 272 | p.url = singleton_ref_url3; |
[email protected] | 78e2edc | 2012-07-01 23:32:28 | [diff] [blame] | 273 | p.ref_behavior = chrome::NavigateParams::RESPECT_REF; |
| 274 | chrome::Navigate(&p); |
[email protected] | 578c696 | 2011-08-24 22:06:40 | [diff] [blame] | 275 | |
| 276 | // We should now have 4 tabs, the 4th one selected. |
| 277 | EXPECT_EQ(browser(), p.browser); |
| 278 | EXPECT_EQ(4, browser()->tab_count()); |
| 279 | EXPECT_EQ(3, browser()->active_index()); |
| 280 | } |
| 281 | |
| 282 | IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, |
[email protected] | 19d9f3a | 2010-10-14 21:49:36 | [diff] [blame] | 283 | Disposition_SingletonTabNoneExisting) { |
[email protected] | 19d9f3a | 2010-10-14 21:49:36 | [diff] [blame] | 284 | GURL singleton_url1("http://maps.google.com/"); |
| 285 | |
[email protected] | bd817c2 | 2011-02-09 08:16:46 | [diff] [blame] | 286 | // We should have one browser with 1 tab. |
[email protected] | 19d9f3a | 2010-10-14 21:49:36 | [diff] [blame] | 287 | EXPECT_EQ(1u, BrowserList::size()); |
[email protected] | 1ea49d5 | 2011-04-12 17:44:44 | [diff] [blame] | 288 | EXPECT_EQ(0, browser()->active_index()); |
[email protected] | 19d9f3a | 2010-10-14 21:49:36 | [diff] [blame] | 289 | |
| 290 | // Navigate to singleton_url1. |
[email protected] | 78e2edc | 2012-07-01 23:32:28 | [diff] [blame] | 291 | chrome::NavigateParams p(MakeNavigateParams()); |
[email protected] | 19d9f3a | 2010-10-14 21:49:36 | [diff] [blame] | 292 | p.disposition = SINGLETON_TAB; |
| 293 | p.url = singleton_url1; |
[email protected] | 78e2edc | 2012-07-01 23:32:28 | [diff] [blame] | 294 | chrome::Navigate(&p); |
[email protected] | 19d9f3a | 2010-10-14 21:49:36 | [diff] [blame] | 295 | |
| 296 | // We should now have 2 tabs, the 2nd one selected. |
| 297 | EXPECT_EQ(browser(), p.browser); |
| 298 | EXPECT_EQ(2, browser()->tab_count()); |
[email protected] | 1ea49d5 | 2011-04-12 17:44:44 | [diff] [blame] | 299 | EXPECT_EQ(1, browser()->active_index()); |
[email protected] | a1feae5 | 2010-10-11 22:14:45 | [diff] [blame] | 300 | } |
| 301 | |
| 302 | // This test verifies that when a navigation results in a foreground tab, the |
| 303 | // tab count of the Browser increases and the selected tab shifts to the new |
| 304 | // foreground tab. |
| 305 | IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_NewForegroundTab) { |
[email protected] | 52877dbc6 | 2012-06-29 22:22:03 | [diff] [blame] | 306 | WebContents* old_contents = chrome::GetActiveWebContents(browser()); |
[email protected] | 78e2edc | 2012-07-01 23:32:28 | [diff] [blame] | 307 | chrome::NavigateParams p(MakeNavigateParams()); |
[email protected] | a1feae5 | 2010-10-11 22:14:45 | [diff] [blame] | 308 | p.disposition = NEW_FOREGROUND_TAB; |
[email protected] | 78e2edc | 2012-07-01 23:32:28 | [diff] [blame] | 309 | chrome::Navigate(&p); |
[email protected] | 52877dbc6 | 2012-06-29 22:22:03 | [diff] [blame] | 310 | EXPECT_NE(old_contents, chrome::GetActiveWebContents(browser())); |
[email protected] | e232c99 | 2012-12-06 12:43:20 | [diff] [blame] | 311 | EXPECT_EQ(browser()->tab_strip_model()->GetActiveWebContents(), |
[email protected] | 59253a65 | 2012-11-20 00:17:26 | [diff] [blame] | 312 | p.target_contents); |
[email protected] | a1feae5 | 2010-10-11 22:14:45 | [diff] [blame] | 313 | EXPECT_EQ(2, browser()->tab_count()); |
| 314 | } |
| 315 | |
| 316 | // This test verifies that when a navigation results in a background tab, the |
| 317 | // tab count of the Browser increases but the selected tab remains the same. |
| 318 | IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_NewBackgroundTab) { |
[email protected] | 52877dbc6 | 2012-06-29 22:22:03 | [diff] [blame] | 319 | WebContents* old_contents = chrome::GetActiveWebContents(browser()); |
[email protected] | 78e2edc | 2012-07-01 23:32:28 | [diff] [blame] | 320 | chrome::NavigateParams p(MakeNavigateParams()); |
[email protected] | a1feae5 | 2010-10-11 22:14:45 | [diff] [blame] | 321 | p.disposition = NEW_BACKGROUND_TAB; |
[email protected] | 78e2edc | 2012-07-01 23:32:28 | [diff] [blame] | 322 | chrome::Navigate(&p); |
[email protected] | 52877dbc6 | 2012-06-29 22:22:03 | [diff] [blame] | 323 | WebContents* new_contents = chrome::GetActiveWebContents(browser()); |
[email protected] | a1feae5 | 2010-10-11 22:14:45 | [diff] [blame] | 324 | // The selected tab should have remained unchanged, since the new tab was |
| 325 | // opened in the background. |
| 326 | EXPECT_EQ(old_contents, new_contents); |
| 327 | EXPECT_EQ(2, browser()->tab_count()); |
| 328 | } |
| 329 | |
| 330 | // This test verifies that when a navigation requiring a new foreground tab |
| 331 | // occurs in a Browser that cannot host multiple tabs, the new foreground tab |
| 332 | // is created in an existing compatible Browser. |
| 333 | IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, |
| 334 | Disposition_IncompatibleWindow_Existing) { |
| 335 | // Open a foreground tab in a window that cannot open popups when there is an |
| 336 | // existing compatible window somewhere else that they can be opened within. |
| 337 | Browser* popup = CreateEmptyBrowserForType(Browser::TYPE_POPUP, |
| 338 | browser()->profile()); |
[email protected] | 78e2edc | 2012-07-01 23:32:28 | [diff] [blame] | 339 | chrome::NavigateParams p(MakeNavigateParams(popup)); |
[email protected] | a1feae5 | 2010-10-11 22:14:45 | [diff] [blame] | 340 | p.disposition = NEW_FOREGROUND_TAB; |
[email protected] | 78e2edc | 2012-07-01 23:32:28 | [diff] [blame] | 341 | chrome::Navigate(&p); |
[email protected] | a1feae5 | 2010-10-11 22:14:45 | [diff] [blame] | 342 | |
| 343 | // Navigate() should have opened the tab in a different browser since the |
| 344 | // one we supplied didn't support additional tabs. |
| 345 | EXPECT_NE(popup, p.browser); |
| 346 | |
| 347 | // Since browser() is an existing compatible tabbed browser, it should have |
| 348 | // opened the tab there. |
| 349 | EXPECT_EQ(browser(), p.browser); |
| 350 | |
| 351 | // We should be left with 2 windows, the popup with one tab and the browser() |
| 352 | // provided by the framework with two. |
| 353 | EXPECT_EQ(2u, BrowserList::size()); |
| 354 | EXPECT_EQ(1, popup->tab_count()); |
| 355 | EXPECT_EQ(2, browser()->tab_count()); |
| 356 | } |
| 357 | |
| 358 | // This test verifies that when a navigation requiring a new foreground tab |
| 359 | // occurs in a Browser that cannot host multiple tabs and no compatible Browser |
| 360 | // that can is open, a compatible Browser is created. |
| 361 | IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, |
| 362 | Disposition_IncompatibleWindow_NoExisting) { |
| 363 | // We want to simulate not being able to find an existing window compatible |
| 364 | // with our non-tabbed browser window so Navigate() is forced to create a |
| 365 | // new compatible window. Because browser() supplied by the in-process |
| 366 | // browser testing framework is compatible with browser()->profile(), we |
| 367 | // need a different profile, and creating a popup window with an incognito |
| 368 | // profile is a quick and dirty way of achieving this. |
| 369 | Browser* popup = CreateEmptyBrowserForType( |
[email protected] | b35b26b3 | 2011-05-05 20:35:14 | [diff] [blame] | 370 | Browser::TYPE_POPUP, |
| 371 | browser()->profile()->GetOffTheRecordProfile()); |
[email protected] | 78e2edc | 2012-07-01 23:32:28 | [diff] [blame] | 372 | chrome::NavigateParams p(MakeNavigateParams(popup)); |
[email protected] | a1feae5 | 2010-10-11 22:14:45 | [diff] [blame] | 373 | p.disposition = NEW_FOREGROUND_TAB; |
[email protected] | 78e2edc | 2012-07-01 23:32:28 | [diff] [blame] | 374 | chrome::Navigate(&p); |
[email protected] | a1feae5 | 2010-10-11 22:14:45 | [diff] [blame] | 375 | |
| 376 | // Navigate() should have opened the tab in a different browser since the |
| 377 | // one we supplied didn't support additional tabs. |
| 378 | EXPECT_NE(popup, p.browser); |
| 379 | |
| 380 | // This time, browser() is _not_ compatible with popup since it is not an |
| 381 | // incognito window. |
| 382 | EXPECT_NE(browser(), p.browser); |
| 383 | |
| 384 | // We should have three windows, each with one tab: |
| 385 | // 1. the browser() provided by the framework (unchanged in this test) |
| 386 | // 2. the incognito popup we created originally |
| 387 | // 3. the new incognito tabbed browser that was created by Navigate(). |
| 388 | EXPECT_EQ(3u, BrowserList::size()); |
| 389 | EXPECT_EQ(1, browser()->tab_count()); |
| 390 | EXPECT_EQ(1, popup->tab_count()); |
| 391 | EXPECT_EQ(1, p.browser->tab_count()); |
[email protected] | b35b26b3 | 2011-05-05 20:35:14 | [diff] [blame] | 392 | EXPECT_TRUE(p.browser->is_type_tabbed()); |
[email protected] | a1feae5 | 2010-10-11 22:14:45 | [diff] [blame] | 393 | } |
| 394 | |
| 395 | // This test verifies that navigating with WindowOpenDisposition = NEW_POPUP |
| 396 | // from a normal Browser results in a new Browser with TYPE_POPUP. |
| 397 | IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_NewPopup) { |
[email protected] | 78e2edc | 2012-07-01 23:32:28 | [diff] [blame] | 398 | chrome::NavigateParams p(MakeNavigateParams()); |
[email protected] | a1feae5 | 2010-10-11 22:14:45 | [diff] [blame] | 399 | p.disposition = NEW_POPUP; |
[email protected] | 588300d | 2011-04-28 21:06:35 | [diff] [blame] | 400 | p.window_bounds = gfx::Rect(0, 0, 200, 200); |
[email protected] | 7d32999 | 2011-04-15 18:20:02 | [diff] [blame] | 401 | // Wait for new popup to to load and gain focus. |
[email protected] | ddddfda | 2011-07-14 23:19:39 | [diff] [blame] | 402 | ui_test_utils::NavigateToURL(&p); |
[email protected] | a1feae5 | 2010-10-11 22:14:45 | [diff] [blame] | 403 | |
[email protected] | 7d32999 | 2011-04-15 18:20:02 | [diff] [blame] | 404 | // Navigate() should have opened a new, focused popup window. |
[email protected] | a1feae5 | 2010-10-11 22:14:45 | [diff] [blame] | 405 | EXPECT_NE(browser(), p.browser); |
[email protected] | 9db263a | 2011-04-15 20:53:47 | [diff] [blame] | 406 | #if 0 |
| 407 | // TODO(stevenjb): Enable this test. See: crbug.com/79493 |
[email protected] | 7d32999 | 2011-04-15 18:20:02 | [diff] [blame] | 408 | EXPECT_TRUE(p.browser->window()->IsActive()); |
| 409 | #endif |
[email protected] | b35b26b3 | 2011-05-05 20:35:14 | [diff] [blame] | 410 | EXPECT_TRUE(p.browser->is_type_popup()); |
| 411 | EXPECT_FALSE(p.browser->is_app()); |
[email protected] | a1feae5 | 2010-10-11 22:14:45 | [diff] [blame] | 412 | |
| 413 | // We should have two windows, the browser() provided by the framework and the |
| 414 | // new popup window. |
| 415 | EXPECT_EQ(2u, BrowserList::size()); |
| 416 | EXPECT_EQ(1, browser()->tab_count()); |
| 417 | EXPECT_EQ(1, p.browser->tab_count()); |
| 418 | } |
| 419 | |
| 420 | // This test verifies that navigating with WindowOpenDisposition = NEW_POPUP |
[email protected] | f112b0f | 2011-05-26 01:53:52 | [diff] [blame] | 421 | // from a normal Browser results in a new Browser with is_app() true. |
| 422 | IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_NewPopup_ExtensionId) { |
[email protected] | 78e2edc | 2012-07-01 23:32:28 | [diff] [blame] | 423 | chrome::NavigateParams p(MakeNavigateParams()); |
[email protected] | f112b0f | 2011-05-26 01:53:52 | [diff] [blame] | 424 | p.disposition = NEW_POPUP; |
| 425 | p.extension_app_id = "extensionappid"; |
| 426 | p.window_bounds = gfx::Rect(0, 0, 200, 200); |
[email protected] | f112b0f | 2011-05-26 01:53:52 | [diff] [blame] | 427 | // Wait for new popup to to load and gain focus. |
[email protected] | ddddfda | 2011-07-14 23:19:39 | [diff] [blame] | 428 | ui_test_utils::NavigateToURL(&p); |
[email protected] | f112b0f | 2011-05-26 01:53:52 | [diff] [blame] | 429 | |
| 430 | // Navigate() should have opened a new, focused popup window. |
| 431 | EXPECT_NE(browser(), p.browser); |
| 432 | EXPECT_TRUE(p.browser->is_type_popup()); |
| 433 | EXPECT_TRUE(p.browser->is_app()); |
| 434 | |
| 435 | // We should have two windows, the browser() provided by the framework and the |
| 436 | // new popup window. |
| 437 | EXPECT_EQ(2u, BrowserList::size()); |
| 438 | EXPECT_EQ(1, browser()->tab_count()); |
| 439 | EXPECT_EQ(1, p.browser->tab_count()); |
| 440 | } |
| 441 | |
| 442 | // This test verifies that navigating with WindowOpenDisposition = NEW_POPUP |
[email protected] | 300d1e5 | 2011-01-19 23:57:57 | [diff] [blame] | 443 | // from a normal popup results in a new Browser with TYPE_POPUP. |
| 444 | IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_NewPopupFromPopup) { |
| 445 | // Open a popup. |
[email protected] | 78e2edc | 2012-07-01 23:32:28 | [diff] [blame] | 446 | chrome::NavigateParams p1(MakeNavigateParams()); |
[email protected] | 300d1e5 | 2011-01-19 23:57:57 | [diff] [blame] | 447 | p1.disposition = NEW_POPUP; |
[email protected] | 588300d | 2011-04-28 21:06:35 | [diff] [blame] | 448 | p1.window_bounds = gfx::Rect(0, 0, 200, 200); |
[email protected] | 78e2edc | 2012-07-01 23:32:28 | [diff] [blame] | 449 | chrome::Navigate(&p1); |
[email protected] | 300d1e5 | 2011-01-19 23:57:57 | [diff] [blame] | 450 | // Open another popup. |
[email protected] | 78e2edc | 2012-07-01 23:32:28 | [diff] [blame] | 451 | chrome::NavigateParams p2(MakeNavigateParams(p1.browser)); |
[email protected] | 300d1e5 | 2011-01-19 23:57:57 | [diff] [blame] | 452 | p2.disposition = NEW_POPUP; |
[email protected] | 588300d | 2011-04-28 21:06:35 | [diff] [blame] | 453 | p2.window_bounds = gfx::Rect(0, 0, 200, 200); |
[email protected] | 78e2edc | 2012-07-01 23:32:28 | [diff] [blame] | 454 | chrome::Navigate(&p2); |
[email protected] | 300d1e5 | 2011-01-19 23:57:57 | [diff] [blame] | 455 | |
| 456 | // Navigate() should have opened a new normal popup window. |
| 457 | EXPECT_NE(p1.browser, p2.browser); |
[email protected] | b35b26b3 | 2011-05-05 20:35:14 | [diff] [blame] | 458 | EXPECT_TRUE(p2.browser->is_type_popup()); |
| 459 | EXPECT_FALSE(p2.browser->is_app()); |
[email protected] | 300d1e5 | 2011-01-19 23:57:57 | [diff] [blame] | 460 | |
| 461 | // We should have three windows, the browser() provided by the framework, |
| 462 | // the first popup window, and the second popup window. |
| 463 | EXPECT_EQ(3u, BrowserList::size()); |
| 464 | EXPECT_EQ(1, browser()->tab_count()); |
| 465 | EXPECT_EQ(1, p1.browser->tab_count()); |
| 466 | EXPECT_EQ(1, p2.browser->tab_count()); |
| 467 | } |
| 468 | |
| 469 | // This test verifies that navigating with WindowOpenDisposition = NEW_POPUP |
[email protected] | a1feae5 | 2010-10-11 22:14:45 | [diff] [blame] | 470 | // from an app frame results in a new Browser with TYPE_APP_POPUP. |
| 471 | IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, |
| 472 | Disposition_NewPopupFromAppWindow) { |
[email protected] | b35b26b3 | 2011-05-05 20:35:14 | [diff] [blame] | 473 | Browser* app_browser = CreateEmptyBrowserForApp(Browser::TYPE_TABBED, |
| 474 | browser()->profile()); |
[email protected] | 78e2edc | 2012-07-01 23:32:28 | [diff] [blame] | 475 | chrome::NavigateParams p(MakeNavigateParams(app_browser)); |
[email protected] | a1feae5 | 2010-10-11 22:14:45 | [diff] [blame] | 476 | p.disposition = NEW_POPUP; |
[email protected] | 588300d | 2011-04-28 21:06:35 | [diff] [blame] | 477 | p.window_bounds = gfx::Rect(0, 0, 200, 200); |
[email protected] | 78e2edc | 2012-07-01 23:32:28 | [diff] [blame] | 478 | chrome::Navigate(&p); |
[email protected] | a1feae5 | 2010-10-11 22:14:45 | [diff] [blame] | 479 | |
| 480 | // Navigate() should have opened a new popup app window. |
| 481 | EXPECT_NE(app_browser, p.browser); |
| 482 | EXPECT_NE(browser(), p.browser); |
[email protected] | b35b26b3 | 2011-05-05 20:35:14 | [diff] [blame] | 483 | EXPECT_TRUE(p.browser->is_type_popup()); |
| 484 | EXPECT_TRUE(p.browser->is_app()); |
[email protected] | a1feae5 | 2010-10-11 22:14:45 | [diff] [blame] | 485 | |
| 486 | // We should now have three windows, the app window, the app popup it created, |
| 487 | // and the original browser() provided by the framework. |
| 488 | EXPECT_EQ(3u, BrowserList::size()); |
| 489 | EXPECT_EQ(1, browser()->tab_count()); |
| 490 | EXPECT_EQ(1, app_browser->tab_count()); |
| 491 | EXPECT_EQ(1, p.browser->tab_count()); |
| 492 | } |
| 493 | |
| 494 | // This test verifies that navigating with WindowOpenDisposition = NEW_POPUP |
[email protected] | 300d1e5 | 2011-01-19 23:57:57 | [diff] [blame] | 495 | // from an app popup results in a new Browser also of TYPE_APP_POPUP. |
| 496 | IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, |
| 497 | Disposition_NewPopupFromAppPopup) { |
[email protected] | b35b26b3 | 2011-05-05 20:35:14 | [diff] [blame] | 498 | Browser* app_browser = CreateEmptyBrowserForApp(Browser::TYPE_TABBED, |
| 499 | browser()->profile()); |
[email protected] | 300d1e5 | 2011-01-19 23:57:57 | [diff] [blame] | 500 | // Open an app popup. |
[email protected] | 78e2edc | 2012-07-01 23:32:28 | [diff] [blame] | 501 | chrome::NavigateParams p1(MakeNavigateParams(app_browser)); |
[email protected] | 300d1e5 | 2011-01-19 23:57:57 | [diff] [blame] | 502 | p1.disposition = NEW_POPUP; |
[email protected] | 588300d | 2011-04-28 21:06:35 | [diff] [blame] | 503 | p1.window_bounds = gfx::Rect(0, 0, 200, 200); |
[email protected] | 78e2edc | 2012-07-01 23:32:28 | [diff] [blame] | 504 | chrome::Navigate(&p1); |
[email protected] | 300d1e5 | 2011-01-19 23:57:57 | [diff] [blame] | 505 | // Now open another app popup. |
[email protected] | 78e2edc | 2012-07-01 23:32:28 | [diff] [blame] | 506 | chrome::NavigateParams p2(MakeNavigateParams(p1.browser)); |
[email protected] | 300d1e5 | 2011-01-19 23:57:57 | [diff] [blame] | 507 | p2.disposition = NEW_POPUP; |
[email protected] | 588300d | 2011-04-28 21:06:35 | [diff] [blame] | 508 | p2.window_bounds = gfx::Rect(0, 0, 200, 200); |
[email protected] | 78e2edc | 2012-07-01 23:32:28 | [diff] [blame] | 509 | chrome::Navigate(&p2); |
[email protected] | 300d1e5 | 2011-01-19 23:57:57 | [diff] [blame] | 510 | |
| 511 | // Navigate() should have opened a new popup app window. |
| 512 | EXPECT_NE(browser(), p1.browser); |
| 513 | EXPECT_NE(p1.browser, p2.browser); |
[email protected] | b35b26b3 | 2011-05-05 20:35:14 | [diff] [blame] | 514 | EXPECT_TRUE(p2.browser->is_type_popup()); |
| 515 | EXPECT_TRUE(p2.browser->is_app()); |
[email protected] | 300d1e5 | 2011-01-19 23:57:57 | [diff] [blame] | 516 | |
| 517 | // We should now have four windows, the app window, the first app popup, |
| 518 | // the second app popup, and the original browser() provided by the framework. |
| 519 | EXPECT_EQ(4u, BrowserList::size()); |
| 520 | EXPECT_EQ(1, browser()->tab_count()); |
| 521 | EXPECT_EQ(1, app_browser->tab_count()); |
| 522 | EXPECT_EQ(1, p1.browser->tab_count()); |
| 523 | EXPECT_EQ(1, p2.browser->tab_count()); |
| 524 | } |
| 525 | |
| 526 | // This test verifies that navigating with WindowOpenDisposition = NEW_POPUP |
[email protected] | a1feae5 | 2010-10-11 22:14:45 | [diff] [blame] | 527 | // from an extension app tab results in a new Browser with TYPE_APP_POPUP. |
| 528 | IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, |
| 529 | Disposition_NewPopupFromExtensionApp) { |
| 530 | // TODO(beng): TBD. |
| 531 | } |
| 532 | |
[email protected] | 7d32999 | 2011-04-15 18:20:02 | [diff] [blame] | 533 | // This test verifies that navigating with window_action = SHOW_WINDOW_INACTIVE |
| 534 | // does not focus a new new popup window. |
| 535 | IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_NewPopupUnfocused) { |
[email protected] | 78e2edc | 2012-07-01 23:32:28 | [diff] [blame] | 536 | chrome::NavigateParams p(MakeNavigateParams()); |
[email protected] | 7d32999 | 2011-04-15 18:20:02 | [diff] [blame] | 537 | p.disposition = NEW_POPUP; |
[email protected] | 588300d | 2011-04-28 21:06:35 | [diff] [blame] | 538 | p.window_bounds = gfx::Rect(0, 0, 200, 200); |
[email protected] | 78e2edc | 2012-07-01 23:32:28 | [diff] [blame] | 539 | p.window_action = chrome::NavigateParams::SHOW_WINDOW_INACTIVE; |
[email protected] | 7d32999 | 2011-04-15 18:20:02 | [diff] [blame] | 540 | // Wait for new popup to load (and gain focus if the test fails). |
[email protected] | ddddfda | 2011-07-14 23:19:39 | [diff] [blame] | 541 | ui_test_utils::NavigateToURL(&p); |
[email protected] | 7d32999 | 2011-04-15 18:20:02 | [diff] [blame] | 542 | |
| 543 | // Navigate() should have opened a new, unfocused, popup window. |
| 544 | EXPECT_NE(browser(), p.browser); |
| 545 | EXPECT_EQ(Browser::TYPE_POPUP, p.browser->type()); |
[email protected] | 9db263a | 2011-04-15 20:53:47 | [diff] [blame] | 546 | #if 0 |
| 547 | // TODO(stevenjb): Enable this test. See: crbug.com/79493 |
[email protected] | 7d32999 | 2011-04-15 18:20:02 | [diff] [blame] | 548 | EXPECT_FALSE(p.browser->window()->IsActive()); |
[email protected] | 7d32999 | 2011-04-15 18:20:02 | [diff] [blame] | 549 | #endif |
[email protected] | 9db263a | 2011-04-15 20:53:47 | [diff] [blame] | 550 | } |
[email protected] | 7d32999 | 2011-04-15 18:20:02 | [diff] [blame] | 551 | |
[email protected] | a1feae5 | 2010-10-11 22:14:45 | [diff] [blame] | 552 | // This test verifies that navigating with WindowOpenDisposition = NEW_WINDOW |
| 553 | // always opens a new window. |
| 554 | IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_NewWindow) { |
[email protected] | 78e2edc | 2012-07-01 23:32:28 | [diff] [blame] | 555 | chrome::NavigateParams p(MakeNavigateParams()); |
[email protected] | a1feae5 | 2010-10-11 22:14:45 | [diff] [blame] | 556 | p.disposition = NEW_WINDOW; |
[email protected] | 78e2edc | 2012-07-01 23:32:28 | [diff] [blame] | 557 | chrome::Navigate(&p); |
[email protected] | a1feae5 | 2010-10-11 22:14:45 | [diff] [blame] | 558 | |
| 559 | // Navigate() should have opened a new toplevel window. |
| 560 | EXPECT_NE(browser(), p.browser); |
[email protected] | b35b26b3 | 2011-05-05 20:35:14 | [diff] [blame] | 561 | EXPECT_TRUE(p.browser->is_type_tabbed()); |
[email protected] | a1feae5 | 2010-10-11 22:14:45 | [diff] [blame] | 562 | |
| 563 | // We should now have two windows, the browser() provided by the framework and |
| 564 | // the new normal window. |
| 565 | EXPECT_EQ(2u, BrowserList::size()); |
| 566 | EXPECT_EQ(1, browser()->tab_count()); |
| 567 | EXPECT_EQ(1, p.browser->tab_count()); |
| 568 | } |
| 569 | |
| 570 | // This test verifies that navigating with WindowOpenDisposition = INCOGNITO |
| 571 | // opens a new incognito window if no existing incognito window is present. |
| 572 | IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_Incognito) { |
[email protected] | 78e2edc | 2012-07-01 23:32:28 | [diff] [blame] | 573 | chrome::NavigateParams p(MakeNavigateParams()); |
[email protected] | a1feae5 | 2010-10-11 22:14:45 | [diff] [blame] | 574 | p.disposition = OFF_THE_RECORD; |
[email protected] | 78e2edc | 2012-07-01 23:32:28 | [diff] [blame] | 575 | chrome::Navigate(&p); |
[email protected] | a1feae5 | 2010-10-11 22:14:45 | [diff] [blame] | 576 | |
| 577 | // Navigate() should have opened a new toplevel incognito window. |
| 578 | EXPECT_NE(browser(), p.browser); |
| 579 | EXPECT_EQ(browser()->profile()->GetOffTheRecordProfile(), |
| 580 | p.browser->profile()); |
| 581 | |
[email protected] | d7ff359 | 2010-11-30 21:50:46 | [diff] [blame] | 582 | // |source_contents| should be set to NULL because the profile for the new |
| 583 | // page is different from the originating page. |
| 584 | EXPECT_EQ(NULL, p.source_contents); |
| 585 | |
[email protected] | a1feae5 | 2010-10-11 22:14:45 | [diff] [blame] | 586 | // We should now have two windows, the browser() provided by the framework and |
| 587 | // the new incognito window. |
| 588 | EXPECT_EQ(2u, BrowserList::size()); |
| 589 | EXPECT_EQ(1, browser()->tab_count()); |
| 590 | EXPECT_EQ(1, p.browser->tab_count()); |
| 591 | } |
| 592 | |
| 593 | // This test verifies that navigating with WindowOpenDisposition = INCOGNITO |
| 594 | // reuses an existing incognito window when possible. |
| 595 | IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_IncognitoRefocus) { |
| 596 | Browser* incognito_browser = |
[email protected] | b35b26b3 | 2011-05-05 20:35:14 | [diff] [blame] | 597 | CreateEmptyBrowserForType(Browser::TYPE_TABBED, |
[email protected] | a1feae5 | 2010-10-11 22:14:45 | [diff] [blame] | 598 | browser()->profile()->GetOffTheRecordProfile()); |
[email protected] | 78e2edc | 2012-07-01 23:32:28 | [diff] [blame] | 599 | chrome::NavigateParams p(MakeNavigateParams()); |
[email protected] | a1feae5 | 2010-10-11 22:14:45 | [diff] [blame] | 600 | p.disposition = OFF_THE_RECORD; |
[email protected] | 78e2edc | 2012-07-01 23:32:28 | [diff] [blame] | 601 | chrome::Navigate(&p); |
[email protected] | a1feae5 | 2010-10-11 22:14:45 | [diff] [blame] | 602 | |
| 603 | // Navigate() should have opened a new tab in the existing incognito window. |
| 604 | EXPECT_NE(browser(), p.browser); |
| 605 | EXPECT_EQ(p.browser, incognito_browser); |
| 606 | |
| 607 | // We should now have two windows, the browser() provided by the framework and |
| 608 | // the incognito window we opened earlier. |
| 609 | EXPECT_EQ(2u, BrowserList::size()); |
| 610 | EXPECT_EQ(1, browser()->tab_count()); |
| 611 | EXPECT_EQ(2, incognito_browser->tab_count()); |
| 612 | } |
| 613 | |
| 614 | // This test verifies that no navigation action occurs when |
| 615 | // WindowOpenDisposition = SUPPRESS_OPEN. |
| 616 | IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_SuppressOpen) { |
| 617 | RunSuppressTest(SUPPRESS_OPEN); |
| 618 | } |
| 619 | |
| 620 | // This test verifies that no navigation action occurs when |
| 621 | // WindowOpenDisposition = SAVE_TO_DISK. |
| 622 | IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_SaveToDisk) { |
| 623 | RunSuppressTest(SAVE_TO_DISK); |
| 624 | } |
| 625 | |
| 626 | // This test verifies that no navigation action occurs when |
| 627 | // WindowOpenDisposition = IGNORE_ACTION. |
| 628 | IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_IgnoreAction) { |
| 629 | RunSuppressTest(IGNORE_ACTION); |
| 630 | } |
| 631 | |
[email protected] | e232c99 | 2012-12-06 12:43:20 | [diff] [blame] | 632 | // This tests adding a foreground tab with a predefined WebContents. |
[email protected] | a1feae5 | 2010-10-11 22:14:45 | [diff] [blame] | 633 | IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, TargetContents_ForegroundTab) { |
[email protected] | 78e2edc | 2012-07-01 23:32:28 | [diff] [blame] | 634 | chrome::NavigateParams p(MakeNavigateParams()); |
[email protected] | a1feae5 | 2010-10-11 22:14:45 | [diff] [blame] | 635 | p.disposition = NEW_FOREGROUND_TAB; |
[email protected] | e232c99 | 2012-12-06 12:43:20 | [diff] [blame] | 636 | p.target_contents = CreateWebContents(); |
[email protected] | 78e2edc | 2012-07-01 23:32:28 | [diff] [blame] | 637 | chrome::Navigate(&p); |
[email protected] | a1feae5 | 2010-10-11 22:14:45 | [diff] [blame] | 638 | |
| 639 | // Navigate() should have opened the contents in a new foreground in the |
| 640 | // current Browser. |
| 641 | EXPECT_EQ(browser(), p.browser); |
[email protected] | e232c99 | 2012-12-06 12:43:20 | [diff] [blame] | 642 | EXPECT_EQ(browser()->tab_strip_model()->GetActiveWebContents(), |
[email protected] | 59253a65 | 2012-11-20 00:17:26 | [diff] [blame] | 643 | p.target_contents); |
[email protected] | a1feae5 | 2010-10-11 22:14:45 | [diff] [blame] | 644 | |
| 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] | e232c99 | 2012-12-06 12:43:20 | [diff] [blame] | 651 | // This tests adding a popup with a predefined WebContents. |
[email protected] | 76edb67 | 2011-03-04 21:48:39 | [diff] [blame] | 652 | IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, DISABLED_TargetContents_Popup) { |
[email protected] | 78e2edc | 2012-07-01 23:32:28 | [diff] [blame] | 653 | chrome::NavigateParams p(MakeNavigateParams()); |
[email protected] | a1feae5 | 2010-10-11 22:14:45 | [diff] [blame] | 654 | p.disposition = NEW_POPUP; |
[email protected] | e232c99 | 2012-12-06 12:43:20 | [diff] [blame] | 655 | p.target_contents = CreateWebContents(); |
[email protected] | a1feae5 | 2010-10-11 22:14:45 | [diff] [blame] | 656 | p.window_bounds = gfx::Rect(10, 10, 500, 500); |
[email protected] | 78e2edc | 2012-07-01 23:32:28 | [diff] [blame] | 657 | chrome::Navigate(&p); |
[email protected] | a1feae5 | 2010-10-11 22:14:45 | [diff] [blame] | 658 | |
| 659 | // Navigate() should have opened a new popup window. |
| 660 | EXPECT_NE(browser(), p.browser); |
[email protected] | b35b26b3 | 2011-05-05 20:35:14 | [diff] [blame] | 661 | EXPECT_TRUE(p.browser->is_type_popup()); |
| 662 | EXPECT_FALSE(p.browser->is_app()); |
[email protected] | a1feae5 | 2010-10-11 22:14:45 | [diff] [blame] | 663 | |
| 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] | e232c99 | 2012-12-06 12:43:20 | [diff] [blame] | 667 | // - the size is used to size the WebContents of the window. |
[email protected] | a1feae5 | 2010-10-11 22:14:45 | [diff] [blame] | 668 | // 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] | e232c99 | 2012-12-06 12:43:20 | [diff] [blame] | 679 | p.target_contents->GetView()->GetContainerSize()); |
[email protected] | a1feae5 | 2010-10-11 22:14:45 | [diff] [blame] | 680 | |
| 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. |
| 690 | IN_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] | 78e2edc | 2012-07-01 23:32:28 | [diff] [blame] | 695 | chrome::NavigateParams p(MakeNavigateParams()); |
[email protected] | a1feae5 | 2010-10-11 22:14:45 | [diff] [blame] | 696 | p.disposition = NEW_FOREGROUND_TAB; |
| 697 | p.tabstrip_index = 0; |
| 698 | p.tabstrip_add_types = TabStripModel::ADD_FORCE_INDEX; |
[email protected] | 78e2edc | 2012-07-01 23:32:28 | [diff] [blame] | 699 | chrome::Navigate(&p); |
[email protected] | a1feae5 | 2010-10-11 22:14:45 | [diff] [blame] | 700 | |
| 701 | // Navigate() should have inserted a new tab at slot 0 in the tabstrip. |
| 702 | EXPECT_EQ(browser(), p.browser); |
[email protected] | e232c99 | 2012-12-06 12:43:20 | [diff] [blame] | 703 | EXPECT_EQ(0, browser()->tab_strip_model()->GetIndexOfWebContents( |
| 704 | static_cast<const WebContents*>(p.target_contents))); |
[email protected] | a1feae5 | 2010-10-11 22:14:45 | [diff] [blame] | 705 | |
| 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] | bb89e748 | 2010-11-17 18:27:04 | [diff] [blame] | 711 | // This test verifies that constructing params with disposition = SINGLETON_TAB |
[email protected] | fee32054 | 2011-03-02 01:30:49 | [diff] [blame] | 712 | // and IGNORE_AND_NAVIGATE opens a new tab navigated to the specified URL if |
[email protected] | 67ed83e | 2011-01-07 22:54:00 | [diff] [blame] | 713 | // no previous tab with that URL (minus the path) exists. |
[email protected] | bb89e748 | 2010-11-17 18:27:04 | [diff] [blame] | 714 | IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, |
| 715 | Disposition_SingletonTabNew_IgnorePath) { |
[email protected] | 52877dbc6 | 2012-06-29 22:22:03 | [diff] [blame] | 716 | chrome::AddSelectedTabWithURL(browser(), GetGoogleURL(), |
| 717 | content::PAGE_TRANSITION_LINK); |
[email protected] | bb89e748 | 2010-11-17 18:27:04 | [diff] [blame] | 718 | |
| 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] | 1ea49d5 | 2011-04-12 17:44:44 | [diff] [blame] | 722 | EXPECT_EQ(1, browser()->active_index()); |
[email protected] | bb89e748 | 2010-11-17 18:27:04 | [diff] [blame] | 723 | |
| 724 | // Navigate to a new singleton tab with a sub-page. |
[email protected] | 78e2edc | 2012-07-01 23:32:28 | [diff] [blame] | 725 | chrome::NavigateParams p(MakeNavigateParams()); |
[email protected] | bb89e748 | 2010-11-17 18:27:04 | [diff] [blame] | 726 | p.disposition = SINGLETON_TAB; |
[email protected] | a048ad2 | 2012-03-23 04:26:56 | [diff] [blame] | 727 | p.url = GetContentSettingsURL(); |
[email protected] | 78e2edc | 2012-07-01 23:32:28 | [diff] [blame] | 728 | p.window_action = chrome::NavigateParams::SHOW_WINDOW; |
| 729 | p.path_behavior = chrome::NavigateParams::IGNORE_AND_NAVIGATE; |
| 730 | chrome::Navigate(&p); |
[email protected] | bb89e748 | 2010-11-17 18:27:04 | [diff] [blame] | 731 | |
| 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] | 1ea49d5 | 2011-04-12 17:44:44 | [diff] [blame] | 736 | EXPECT_EQ(2, browser()->active_index()); |
[email protected] | a048ad2 | 2012-03-23 04:26:56 | [diff] [blame] | 737 | EXPECT_EQ(GetContentSettingsURL(), |
[email protected] | f8f93eb | 2012-09-25 03:06:24 | [diff] [blame] | 738 | ShortenUberURL(chrome::GetActiveWebContents(browser())->GetURL())); |
[email protected] | bb89e748 | 2010-11-17 18:27:04 | [diff] [blame] | 739 | } |
| 740 | |
| 741 | // This test verifies that constructing params with disposition = SINGLETON_TAB |
[email protected] | fee32054 | 2011-03-02 01:30:49 | [diff] [blame] | 742 | // and IGNORE_AND_NAVIGATE opens an existing tab with the matching URL (minus |
[email protected] | bb89e748 | 2010-11-17 18:27:04 | [diff] [blame] | 743 | // the path) which is navigated to the specified URL. |
| 744 | IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, |
| 745 | Disposition_SingletonTabExisting_IgnorePath) { |
[email protected] | ddddfda | 2011-07-14 23:19:39 | [diff] [blame] | 746 | GURL singleton_url1(GetSettingsURL()); |
[email protected] | 52877dbc6 | 2012-06-29 22:22:03 | [diff] [blame] | 747 | chrome::AddSelectedTabWithURL(browser(), singleton_url1, |
| 748 | content::PAGE_TRANSITION_LINK); |
| 749 | chrome::AddSelectedTabWithURL(browser(), GetGoogleURL(), |
| 750 | content::PAGE_TRANSITION_LINK); |
[email protected] | bb89e748 | 2010-11-17 18:27:04 | [diff] [blame] | 751 | |
| 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] | 1ea49d5 | 2011-04-12 17:44:44 | [diff] [blame] | 755 | EXPECT_EQ(2, browser()->active_index()); |
[email protected] | bb89e748 | 2010-11-17 18:27:04 | [diff] [blame] | 756 | |
| 757 | // Navigate to singleton_url1. |
[email protected] | 78e2edc | 2012-07-01 23:32:28 | [diff] [blame] | 758 | chrome::NavigateParams p(MakeNavigateParams()); |
[email protected] | bb89e748 | 2010-11-17 18:27:04 | [diff] [blame] | 759 | p.disposition = SINGLETON_TAB; |
[email protected] | a048ad2 | 2012-03-23 04:26:56 | [diff] [blame] | 760 | p.url = GetContentSettingsURL(); |
[email protected] | 78e2edc | 2012-07-01 23:32:28 | [diff] [blame] | 761 | p.window_action = chrome::NavigateParams::SHOW_WINDOW; |
| 762 | p.path_behavior = chrome::NavigateParams::IGNORE_AND_NAVIGATE; |
| 763 | chrome::Navigate(&p); |
[email protected] | bb89e748 | 2010-11-17 18:27:04 | [diff] [blame] | 764 | |
| 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] | 1ea49d5 | 2011-04-12 17:44:44 | [diff] [blame] | 769 | EXPECT_EQ(1, browser()->active_index()); |
[email protected] | a048ad2 | 2012-03-23 04:26:56 | [diff] [blame] | 770 | EXPECT_EQ(GetContentSettingsURL(), |
[email protected] | f8f93eb | 2012-09-25 03:06:24 | [diff] [blame] | 771 | ShortenUberURL(chrome::GetActiveWebContents(browser())->GetURL())); |
[email protected] | bb89e748 | 2010-11-17 18:27:04 | [diff] [blame] | 772 | } |
| 773 | |
| 774 | // This test verifies that constructing params with disposition = SINGLETON_TAB |
[email protected] | fee32054 | 2011-03-02 01:30:49 | [diff] [blame] | 775 | // and IGNORE_AND_NAVIGATE opens an existing tab with the matching URL (minus |
[email protected] | bb89e748 | 2010-11-17 18:27:04 | [diff] [blame] | 776 | // the path) which is navigated to the specified URL. |
| 777 | IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, |
| 778 | Disposition_SingletonTabExistingSubPath_IgnorePath) { |
[email protected] | a048ad2 | 2012-03-23 04:26:56 | [diff] [blame] | 779 | GURL singleton_url1(GetContentSettingsURL()); |
[email protected] | 52877dbc6 | 2012-06-29 22:22:03 | [diff] [blame] | 780 | chrome::AddSelectedTabWithURL(browser(), singleton_url1, |
| 781 | content::PAGE_TRANSITION_LINK); |
| 782 | chrome::AddSelectedTabWithURL(browser(), GetGoogleURL(), |
| 783 | content::PAGE_TRANSITION_LINK); |
[email protected] | bb89e748 | 2010-11-17 18:27:04 | [diff] [blame] | 784 | |
| 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] | 1ea49d5 | 2011-04-12 17:44:44 | [diff] [blame] | 788 | EXPECT_EQ(2, browser()->active_index()); |
[email protected] | bb89e748 | 2010-11-17 18:27:04 | [diff] [blame] | 789 | |
| 790 | // Navigate to singleton_url1. |
[email protected] | 78e2edc | 2012-07-01 23:32:28 | [diff] [blame] | 791 | chrome::NavigateParams p(MakeNavigateParams()); |
[email protected] | bb89e748 | 2010-11-17 18:27:04 | [diff] [blame] | 792 | p.disposition = SINGLETON_TAB; |
[email protected] | a048ad2 | 2012-03-23 04:26:56 | [diff] [blame] | 793 | p.url = GetClearBrowsingDataURL(); |
[email protected] | 78e2edc | 2012-07-01 23:32:28 | [diff] [blame] | 794 | p.window_action = chrome::NavigateParams::SHOW_WINDOW; |
| 795 | p.path_behavior = chrome::NavigateParams::IGNORE_AND_NAVIGATE; |
| 796 | chrome::Navigate(&p); |
[email protected] | bb89e748 | 2010-11-17 18:27:04 | [diff] [blame] | 797 | |
| 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] | 1ea49d5 | 2011-04-12 17:44:44 | [diff] [blame] | 802 | EXPECT_EQ(1, browser()->active_index()); |
[email protected] | a048ad2 | 2012-03-23 04:26:56 | [diff] [blame] | 803 | EXPECT_EQ(GetClearBrowsingDataURL(), |
[email protected] | f8f93eb | 2012-09-25 03:06:24 | [diff] [blame] | 804 | ShortenUberURL(chrome::GetActiveWebContents(browser())->GetURL())); |
[email protected] | bb89e748 | 2010-11-17 18:27:04 | [diff] [blame] | 805 | } |
[email protected] | 2dd8548 | 2010-11-06 01:56:47 | [diff] [blame] | 806 | |
[email protected] | 637b344 | 2011-01-10 23:31:48 | [diff] [blame] | 807 | // This test verifies that constructing params with disposition = SINGLETON_TAB |
[email protected] | fee32054 | 2011-03-02 01:30:49 | [diff] [blame] | 808 | // and IGNORE_AND_STAY_PUT opens an existing tab with the matching URL (minus |
| 809 | // the path). |
| 810 | IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, |
| 811 | Disposition_SingletonTabExistingSubPath_IgnorePath2) { |
[email protected] | a048ad2 | 2012-03-23 04:26:56 | [diff] [blame] | 812 | GURL singleton_url1(GetContentSettingsURL()); |
[email protected] | 52877dbc6 | 2012-06-29 22:22:03 | [diff] [blame] | 813 | chrome::AddSelectedTabWithURL(browser(), singleton_url1, |
| 814 | content::PAGE_TRANSITION_LINK); |
| 815 | chrome::AddSelectedTabWithURL(browser(), GetGoogleURL(), |
| 816 | content::PAGE_TRANSITION_LINK); |
[email protected] | fee32054 | 2011-03-02 01:30:49 | [diff] [blame] | 817 | |
| 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] | 1ea49d5 | 2011-04-12 17:44:44 | [diff] [blame] | 821 | EXPECT_EQ(2, browser()->active_index()); |
[email protected] | fee32054 | 2011-03-02 01:30:49 | [diff] [blame] | 822 | |
| 823 | // Navigate to singleton_url1. |
[email protected] | 78e2edc | 2012-07-01 23:32:28 | [diff] [blame] | 824 | chrome::NavigateParams p(MakeNavigateParams()); |
[email protected] | fee32054 | 2011-03-02 01:30:49 | [diff] [blame] | 825 | p.disposition = SINGLETON_TAB; |
[email protected] | a048ad2 | 2012-03-23 04:26:56 | [diff] [blame] | 826 | p.url = GetClearBrowsingDataURL(); |
[email protected] | 78e2edc | 2012-07-01 23:32:28 | [diff] [blame] | 827 | p.window_action = chrome::NavigateParams::SHOW_WINDOW; |
| 828 | p.path_behavior = chrome::NavigateParams::IGNORE_AND_STAY_PUT; |
| 829 | chrome::Navigate(&p); |
[email protected] | fee32054 | 2011-03-02 01:30:49 | [diff] [blame] | 830 | |
| 831 | // The middle tab should now be selected. |
| 832 | EXPECT_EQ(browser(), p.browser); |
| 833 | EXPECT_EQ(3, browser()->tab_count()); |
[email protected] | 1ea49d5 | 2011-04-12 17:44:44 | [diff] [blame] | 834 | EXPECT_EQ(1, browser()->active_index()); |
[email protected] | fee32054 | 2011-03-02 01:30:49 | [diff] [blame] | 835 | EXPECT_EQ(singleton_url1, |
[email protected] | f8f93eb | 2012-09-25 03:06:24 | [diff] [blame] | 836 | ShortenUberURL(chrome::GetActiveWebContents(browser())->GetURL())); |
[email protected] | fee32054 | 2011-03-02 01:30:49 | [diff] [blame] | 837 | } |
| 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] | 637b344 | 2011-01-10 23:31:48 | [diff] [blame] | 841 | // selected tab is a match but has a different path. |
| 842 | IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, |
| 843 | Disposition_SingletonTabFocused_IgnorePath) { |
[email protected] | a048ad2 | 2012-03-23 04:26:56 | [diff] [blame] | 844 | GURL singleton_url_current(GetContentSettingsURL()); |
[email protected] | 52877dbc6 | 2012-06-29 22:22:03 | [diff] [blame] | 845 | chrome::AddSelectedTabWithURL(browser(), singleton_url_current, |
| 846 | content::PAGE_TRANSITION_LINK); |
[email protected] | 637b344 | 2011-01-10 23:31:48 | [diff] [blame] | 847 | |
| 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] | 1ea49d5 | 2011-04-12 17:44:44 | [diff] [blame] | 851 | EXPECT_EQ(1, browser()->active_index()); |
[email protected] | 637b344 | 2011-01-10 23:31:48 | [diff] [blame] | 852 | |
| 853 | // Navigate to a different settings path. |
[email protected] | a048ad2 | 2012-03-23 04:26:56 | [diff] [blame] | 854 | GURL singleton_url_target(GetClearBrowsingDataURL()); |
[email protected] | 78e2edc | 2012-07-01 23:32:28 | [diff] [blame] | 855 | chrome::NavigateParams p(MakeNavigateParams()); |
[email protected] | 637b344 | 2011-01-10 23:31:48 | [diff] [blame] | 856 | p.disposition = SINGLETON_TAB; |
| 857 | p.url = singleton_url_target; |
[email protected] | 78e2edc | 2012-07-01 23:32:28 | [diff] [blame] | 858 | p.window_action = chrome::NavigateParams::SHOW_WINDOW; |
| 859 | p.path_behavior = chrome::NavigateParams::IGNORE_AND_NAVIGATE; |
| 860 | chrome::Navigate(&p); |
[email protected] | 637b344 | 2011-01-10 23:31:48 | [diff] [blame] | 861 | |
| 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] | 1ea49d5 | 2011-04-12 17:44:44 | [diff] [blame] | 865 | EXPECT_EQ(1, browser()->active_index()); |
[email protected] | 637b344 | 2011-01-10 23:31:48 | [diff] [blame] | 866 | EXPECT_EQ(singleton_url_target, |
[email protected] | f8f93eb | 2012-09-25 03:06:24 | [diff] [blame] | 867 | ShortenUberURL(chrome::GetActiveWebContents(browser())->GetURL())); |
[email protected] | 637b344 | 2011-01-10 23:31:48 | [diff] [blame] | 868 | } |
| 869 | |
[email protected] | 07afd7c | 2011-02-17 10:07:11 | [diff] [blame] | 870 | // This test verifies that constructing params with disposition = SINGLETON_TAB |
[email protected] | fee32054 | 2011-03-02 01:30:49 | [diff] [blame] | 871 | // and IGNORE_AND_NAVIGATE will open an existing matching tab with a different |
| 872 | // query. |
[email protected] | 07afd7c | 2011-02-17 10:07:11 | [diff] [blame] | 873 | IN_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] | 52877dbc6 | 2012-06-29 22:22:03 | [diff] [blame] | 877 | chrome::AddSelectedTabWithURL(browser(), singleton_url_current, |
| 878 | content::PAGE_TRANSITION_LINK); |
[email protected] | 07afd7c | 2011-02-17 10:07:11 | [diff] [blame] | 879 | |
| 880 | EXPECT_EQ(initial_tab_count + 1, browser()->tab_count()); |
[email protected] | 1ea49d5 | 2011-04-12 17:44:44 | [diff] [blame] | 881 | EXPECT_EQ(initial_tab_count, browser()->active_index()); |
[email protected] | 07afd7c | 2011-02-17 10:07:11 | [diff] [blame] | 882 | |
| 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] | 78e2edc | 2012-07-01 23:32:28 | [diff] [blame] | 887 | chrome::NavigateParams p(MakeNavigateParams()); |
[email protected] | 07afd7c | 2011-02-17 10:07:11 | [diff] [blame] | 888 | p.disposition = SINGLETON_TAB; |
| 889 | p.url = singleton_url_target; |
[email protected] | 78e2edc | 2012-07-01 23:32:28 | [diff] [blame] | 890 | p.window_action = chrome::NavigateParams::SHOW_WINDOW; |
| 891 | p.path_behavior = chrome::NavigateParams::IGNORE_AND_NAVIGATE; |
| 892 | chrome::Navigate(&p); |
[email protected] | 07afd7c | 2011-02-17 10:07:11 | [diff] [blame] | 893 | |
| 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] | 1ea49d5 | 2011-04-12 17:44:44 | [diff] [blame] | 897 | EXPECT_EQ(initial_tab_count, browser()->active_index()); |
[email protected] | 07afd7c | 2011-02-17 10:07:11 | [diff] [blame] | 898 | } |
| 899 | |
[email protected] | bd817c2 | 2011-02-09 08:16:46 | [diff] [blame] | 900 | // This test verifies that the settings page isn't opened in the incognito |
| 901 | // window. |
[email protected] | a048ad2 | 2012-03-23 04:26:56 | [diff] [blame] | 902 | // Disabled until fixed for uber settings: http://crbug.com/111243 |
[email protected] | bd817c2 | 2011-02-09 08:16:46 | [diff] [blame] | 903 | IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, |
[email protected] | a048ad2 | 2012-03-23 04:26:56 | [diff] [blame] | 904 | DISABLED_Disposition_Settings_UseNonIncognitoWindow) { |
[email protected] | fc0ed30 | 2011-11-29 23:17:19 | [diff] [blame] | 905 | RunUseNonIncognitoWindowTest(GetSettingsURL()); |
[email protected] | bd817c2 | 2011-02-09 08:16:46 | [diff] [blame] | 906 | } |
| 907 | |
[email protected] | 82404cd | 2011-07-12 19:55:14 | [diff] [blame] | 908 | // 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] | a048ad2 | 2012-03-23 04:26:56 | [diff] [blame] | 910 | // Disabled until fixed for uber settings: http://crbug.com/111243 |
[email protected] | 82404cd | 2011-07-12 19:55:14 | [diff] [blame] | 911 | IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, |
[email protected] | a048ad2 | 2012-03-23 04:26:56 | [diff] [blame] | 912 | DISABLED_Disposition_Settings_UseNonIncognitoWindowForBookmark) { |
[email protected] | 78e2edc | 2012-07-01 23:32:28 | [diff] [blame] | 913 | chrome::NavigateParams params(browser(), GetSettingsURL(), |
| 914 | content::PAGE_TRANSITION_AUTO_BOOKMARK); |
[email protected] | 82404cd | 2011-07-12 19:55:14 | [diff] [blame] | 915 | params.disposition = OFF_THE_RECORD; |
| 916 | { |
[email protected] | a7fe911 | 2012-07-20 02:34:45 | [diff] [blame] | 917 | content::WindowedNotificationObserver observer( |
[email protected] | ad50def5 | 2011-10-19 23:17:07 | [diff] [blame] | 918 | content::NOTIFICATION_LOAD_STOP, |
| 919 | content::NotificationService::AllSources()); |
[email protected] | 78e2edc | 2012-07-01 23:32:28 | [diff] [blame] | 920 | chrome::Navigate(¶ms); |
[email protected] | 82404cd | 2011-07-12 19:55:14 | [diff] [blame] | 921 | observer.Wait(); |
| 922 | } |
| 923 | |
| 924 | EXPECT_EQ(1u, BrowserList::size()); |
[email protected] | 52877dbc6 | 2012-06-29 22:22:03 | [diff] [blame] | 925 | EXPECT_EQ(GetSettingsURL(), |
[email protected] | f8f93eb | 2012-09-25 03:06:24 | [diff] [blame] | 926 | ShortenUberURL(chrome::GetActiveWebContents(browser())->GetURL())); |
[email protected] | 82404cd | 2011-07-12 19:55:14 | [diff] [blame] | 927 | } |
| 928 | |
[email protected] | 93ad8e1c | 2011-11-08 21:34:05 | [diff] [blame] | 929 | // 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] | a048ad2 | 2012-03-23 04:26:56 | [diff] [blame] | 933 | // Disabled until fixed for uber settings: http://crbug.com/111243 |
[email protected] | 93ad8e1c | 2011-11-08 21:34:05 | [diff] [blame] | 934 | IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, |
[email protected] | a048ad2 | 2012-03-23 04:26:56 | [diff] [blame] | 935 | DISABLED_Disposition_Settings_DoNothingIfIncognitoIsForced) { |
[email protected] | fc0ed30 | 2011-11-29 23:17:19 | [diff] [blame] | 936 | RunDoNothingIfIncognitoIsForcedTest(GetSettingsURL()); |
[email protected] | 93ad8e1c | 2011-11-08 21:34:05 | [diff] [blame] | 937 | } |
| 938 | |
[email protected] | bd817c2 | 2011-02-09 08:16:46 | [diff] [blame] | 939 | // This test verifies that the bookmarks page isn't opened in the incognito |
| 940 | // window. |
| 941 | IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, |
| 942 | Disposition_Bookmarks_UseNonIncognitoWindow) { |
[email protected] | fc0ed30 | 2011-11-29 23:17:19 | [diff] [blame] | 943 | RunUseNonIncognitoWindowTest(GURL(chrome::kChromeUIBookmarksURL)); |
[email protected] | bd817c2 | 2011-02-09 08:16:46 | [diff] [blame] | 944 | } |
| 945 | |
[email protected] | 93ad8e1c | 2011-11-08 21:34:05 | [diff] [blame] | 946 | // 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. |
| 950 | IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, |
| 951 | Disposition_Bookmarks_DoNothingIfIncognitoIsForced) { |
[email protected] | fc0ed30 | 2011-11-29 23:17:19 | [diff] [blame] | 952 | RunDoNothingIfIncognitoIsForcedTest(GURL(chrome::kChromeUIBookmarksURL)); |
| 953 | } |
[email protected] | 93ad8e1c | 2011-11-08 21:34:05 | [diff] [blame] | 954 | |
[email protected] | fc0ed30 | 2011-11-29 23:17:19 | [diff] [blame] | 955 | // This test verifies that the sync promo page isn't opened in the incognito |
| 956 | // window. |
| 957 | IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, |
| 958 | Disposition_SyncPromo_UseNonIncognitoWindow) { |
| 959 | RunUseNonIncognitoWindowTest(GURL(chrome::kChromeUISyncPromoURL)); |
| 960 | } |
[email protected] | 93ad8e1c | 2011-11-08 21:34:05 | [diff] [blame] | 961 | |
[email protected] | fc0ed30 | 2011-11-29 23:17:19 | [diff] [blame] | 962 | // 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. |
| 966 | IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, |
| 967 | Disposition_SyncPromo_DoNothingIfIncognitoIsForced) { |
| 968 | RunDoNothingIfIncognitoIsForcedTest(GURL(chrome::kChromeUISyncPromoURL)); |
[email protected] | 93ad8e1c | 2011-11-08 21:34:05 | [diff] [blame] | 969 | } |
| 970 | |
[email protected] | 7de53c6 | 2011-05-13 06:44:16 | [diff] [blame] | 971 | // This test makes sure a crashed singleton tab reloads from a new navigation. |
| 972 | IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, |
| 973 | NavigateToCrashedSingletonTab) { |
[email protected] | a048ad2 | 2012-03-23 04:26:56 | [diff] [blame] | 974 | GURL singleton_url(GetContentSettingsURL()); |
[email protected] | 5a1a5246 | 2012-11-15 03:35:16 | [diff] [blame] | 975 | WebContents* web_contents = chrome::AddSelectedTabWithURL( |
[email protected] | 52877dbc6 | 2012-06-29 22:22:03 | [diff] [blame] | 976 | browser(), singleton_url, content::PAGE_TRANSITION_LINK); |
[email protected] | 7de53c6 | 2011-05-13 06:44:16 | [diff] [blame] | 977 | |
| 978 | // We should have one browser with 2 tabs, the 2nd selected. |
| 979 | EXPECT_EQ(1u, BrowserList::size()); |
| 980 | EXPECT_EQ(2, browser()->tab_count()); |
| 981 | EXPECT_EQ(1, browser()->active_index()); |
| 982 | |
| 983 | // Kill the singleton tab. |
[email protected] | 83ff91c | 2012-01-05 20:54:13 | [diff] [blame] | 984 | web_contents->SetIsCrashed(base::TERMINATION_STATUS_PROCESS_CRASHED, -1); |
| 985 | EXPECT_TRUE(web_contents->IsCrashed()); |
[email protected] | 7de53c6 | 2011-05-13 06:44:16 | [diff] [blame] | 986 | |
[email protected] | 78e2edc | 2012-07-01 23:32:28 | [diff] [blame] | 987 | chrome::NavigateParams p(MakeNavigateParams()); |
[email protected] | 7de53c6 | 2011-05-13 06:44:16 | [diff] [blame] | 988 | p.disposition = SINGLETON_TAB; |
| 989 | p.url = singleton_url; |
[email protected] | 78e2edc | 2012-07-01 23:32:28 | [diff] [blame] | 990 | p.window_action = chrome::NavigateParams::SHOW_WINDOW; |
| 991 | p.path_behavior = chrome::NavigateParams::IGNORE_AND_NAVIGATE; |
[email protected] | ddddfda | 2011-07-14 23:19:39 | [diff] [blame] | 992 | ui_test_utils::NavigateToURL(&p); |
[email protected] | 7de53c6 | 2011-05-13 06:44:16 | [diff] [blame] | 993 | |
| 994 | // The tab should not be sad anymore. |
[email protected] | 83ff91c | 2012-01-05 20:54:13 | [diff] [blame] | 995 | EXPECT_FALSE(web_contents->IsCrashed()); |
[email protected] | 7de53c6 | 2011-05-13 06:44:16 | [diff] [blame] | 996 | } |
| 997 | |
[email protected] | fcca741b | 2011-06-17 22:46:37 | [diff] [blame] | 998 | IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, |
| 999 | NavigateFromDefaultToOptionsInSameTab) { |
[email protected] | ddddfda | 2011-07-14 23:19:39 | [diff] [blame] | 1000 | { |
[email protected] | a7fe911 | 2012-07-20 02:34:45 | [diff] [blame] | 1001 | content::WindowedNotificationObserver observer( |
[email protected] | ad50def5 | 2011-10-19 23:17:07 | [diff] [blame] | 1002 | content::NOTIFICATION_LOAD_STOP, |
| 1003 | content::NotificationService::AllSources()); |
[email protected] | 5d9cace7 | 2012-06-21 16:07:12 | [diff] [blame] | 1004 | chrome::ShowSettings(browser()); |
[email protected] | ddddfda | 2011-07-14 23:19:39 | [diff] [blame] | 1005 | observer.Wait(); |
| 1006 | } |
[email protected] | fcca741b | 2011-06-17 22:46:37 | [diff] [blame] | 1007 | EXPECT_EQ(1, browser()->tab_count()); |
[email protected] | 52877dbc6 | 2012-06-29 22:22:03 | [diff] [blame] | 1008 | EXPECT_EQ(GetSettingsURL(), |
[email protected] | f8f93eb | 2012-09-25 03:06:24 | [diff] [blame] | 1009 | ShortenUberURL(chrome::GetActiveWebContents(browser())->GetURL())); |
[email protected] | fcca741b | 2011-06-17 22:46:37 | [diff] [blame] | 1010 | } |
| 1011 | |
| 1012 | IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, |
| 1013 | NavigateFromBlankToOptionsInSameTab) { |
[email protected] | 78e2edc | 2012-07-01 23:32:28 | [diff] [blame] | 1014 | chrome::NavigateParams p(MakeNavigateParams()); |
[email protected] | ddddfda | 2011-07-14 23:19:39 | [diff] [blame] | 1015 | p.url = GURL(chrome::kAboutBlankURL); |
| 1016 | ui_test_utils::NavigateToURL(&p); |
[email protected] | fcca741b | 2011-06-17 22:46:37 | [diff] [blame] | 1017 | |
[email protected] | ddddfda | 2011-07-14 23:19:39 | [diff] [blame] | 1018 | { |
[email protected] | a7fe911 | 2012-07-20 02:34:45 | [diff] [blame] | 1019 | content::WindowedNotificationObserver observer( |
[email protected] | ad50def5 | 2011-10-19 23:17:07 | [diff] [blame] | 1020 | content::NOTIFICATION_LOAD_STOP, |
| 1021 | content::NotificationService::AllSources()); |
[email protected] | 5d9cace7 | 2012-06-21 16:07:12 | [diff] [blame] | 1022 | chrome::ShowSettings(browser()); |
[email protected] | ddddfda | 2011-07-14 23:19:39 | [diff] [blame] | 1023 | observer.Wait(); |
| 1024 | } |
[email protected] | fcca741b | 2011-06-17 22:46:37 | [diff] [blame] | 1025 | EXPECT_EQ(1, browser()->tab_count()); |
[email protected] | 52877dbc6 | 2012-06-29 22:22:03 | [diff] [blame] | 1026 | EXPECT_EQ(GetSettingsURL(), |
[email protected] | f8f93eb | 2012-09-25 03:06:24 | [diff] [blame] | 1027 | ShortenUberURL(chrome::GetActiveWebContents(browser())->GetURL())); |
[email protected] | fcca741b | 2011-06-17 22:46:37 | [diff] [blame] | 1028 | } |
| 1029 | |
| 1030 | IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, |
| 1031 | NavigateFromNTPToOptionsInSameTab) { |
[email protected] | 78e2edc | 2012-07-01 23:32:28 | [diff] [blame] | 1032 | chrome::NavigateParams p(MakeNavigateParams()); |
[email protected] | ddddfda | 2011-07-14 23:19:39 | [diff] [blame] | 1033 | p.url = GURL(chrome::kChromeUINewTabURL); |
| 1034 | ui_test_utils::NavigateToURL(&p); |
[email protected] | fcca741b | 2011-06-17 22:46:37 | [diff] [blame] | 1035 | EXPECT_EQ(1, browser()->tab_count()); |
[email protected] | ddddfda | 2011-07-14 23:19:39 | [diff] [blame] | 1036 | EXPECT_EQ(GURL(chrome::kChromeUINewTabURL), |
[email protected] | 52877dbc6 | 2012-06-29 22:22:03 | [diff] [blame] | 1037 | chrome::GetActiveWebContents(browser())->GetURL()); |
[email protected] | fcca741b | 2011-06-17 22:46:37 | [diff] [blame] | 1038 | |
[email protected] | ddddfda | 2011-07-14 23:19:39 | [diff] [blame] | 1039 | { |
[email protected] | a7fe911 | 2012-07-20 02:34:45 | [diff] [blame] | 1040 | content::WindowedNotificationObserver observer( |
[email protected] | ad50def5 | 2011-10-19 23:17:07 | [diff] [blame] | 1041 | content::NOTIFICATION_LOAD_STOP, |
| 1042 | content::NotificationService::AllSources()); |
[email protected] | 5d9cace7 | 2012-06-21 16:07:12 | [diff] [blame] | 1043 | chrome::ShowSettings(browser()); |
[email protected] | ddddfda | 2011-07-14 23:19:39 | [diff] [blame] | 1044 | observer.Wait(); |
| 1045 | } |
[email protected] | fcca741b | 2011-06-17 22:46:37 | [diff] [blame] | 1046 | EXPECT_EQ(1, browser()->tab_count()); |
[email protected] | 52877dbc6 | 2012-06-29 22:22:03 | [diff] [blame] | 1047 | EXPECT_EQ(GetSettingsURL(), |
[email protected] | f8f93eb | 2012-09-25 03:06:24 | [diff] [blame] | 1048 | ShortenUberURL(chrome::GetActiveWebContents(browser())->GetURL())); |
[email protected] | fcca741b | 2011-06-17 22:46:37 | [diff] [blame] | 1049 | } |
| 1050 | |
| 1051 | IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, |
| 1052 | NavigateFromPageToOptionsInNewTab) { |
[email protected] | 78e2edc | 2012-07-01 23:32:28 | [diff] [blame] | 1053 | chrome::NavigateParams p(MakeNavigateParams()); |
[email protected] | ddddfda | 2011-07-14 23:19:39 | [diff] [blame] | 1054 | ui_test_utils::NavigateToURL(&p); |
[email protected] | 52877dbc6 | 2012-06-29 22:22:03 | [diff] [blame] | 1055 | EXPECT_EQ(GetGoogleURL(), chrome::GetActiveWebContents(browser())->GetURL()); |
[email protected] | fcca741b | 2011-06-17 22:46:37 | [diff] [blame] | 1056 | EXPECT_EQ(1u, BrowserList::size()); |
| 1057 | EXPECT_EQ(1, browser()->tab_count()); |
| 1058 | |
[email protected] | ddddfda | 2011-07-14 23:19:39 | [diff] [blame] | 1059 | { |
[email protected] | a7fe911 | 2012-07-20 02:34:45 | [diff] [blame] | 1060 | content::WindowedNotificationObserver observer( |
[email protected] | ad50def5 | 2011-10-19 23:17:07 | [diff] [blame] | 1061 | content::NOTIFICATION_LOAD_STOP, |
| 1062 | content::NotificationService::AllSources()); |
[email protected] | 5d9cace7 | 2012-06-21 16:07:12 | [diff] [blame] | 1063 | chrome::ShowSettings(browser()); |
[email protected] | ddddfda | 2011-07-14 23:19:39 | [diff] [blame] | 1064 | observer.Wait(); |
| 1065 | } |
[email protected] | fcca741b | 2011-06-17 22:46:37 | [diff] [blame] | 1066 | EXPECT_EQ(2, browser()->tab_count()); |
[email protected] | 52877dbc6 | 2012-06-29 22:22:03 | [diff] [blame] | 1067 | EXPECT_EQ(GetSettingsURL(), |
[email protected] | f8f93eb | 2012-09-25 03:06:24 | [diff] [blame] | 1068 | ShortenUberURL(chrome::GetActiveWebContents(browser())->GetURL())); |
[email protected] | fcca741b | 2011-06-17 22:46:37 | [diff] [blame] | 1069 | } |
| 1070 | |
| 1071 | IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, |
| 1072 | NavigateFromNTPToOptionsSingleton) { |
[email protected] | ddddfda | 2011-07-14 23:19:39 | [diff] [blame] | 1073 | { |
[email protected] | a7fe911 | 2012-07-20 02:34:45 | [diff] [blame] | 1074 | content::WindowedNotificationObserver observer( |
[email protected] | ad50def5 | 2011-10-19 23:17:07 | [diff] [blame] | 1075 | content::NOTIFICATION_LOAD_STOP, |
| 1076 | content::NotificationService::AllSources()); |
[email protected] | 5d9cace7 | 2012-06-21 16:07:12 | [diff] [blame] | 1077 | chrome::ShowSettings(browser()); |
[email protected] | ddddfda | 2011-07-14 23:19:39 | [diff] [blame] | 1078 | observer.Wait(); |
| 1079 | } |
[email protected] | fcca741b | 2011-06-17 22:46:37 | [diff] [blame] | 1080 | EXPECT_EQ(1, browser()->tab_count()); |
| 1081 | |
[email protected] | a37d4b0 | 2012-06-25 21:56:10 | [diff] [blame] | 1082 | chrome::NewTab(browser()); |
[email protected] | fcca741b | 2011-06-17 22:46:37 | [diff] [blame] | 1083 | EXPECT_EQ(2, browser()->tab_count()); |
| 1084 | |
[email protected] | ddddfda | 2011-07-14 23:19:39 | [diff] [blame] | 1085 | { |
[email protected] | a7fe911 | 2012-07-20 02:34:45 | [diff] [blame] | 1086 | content::WindowedNotificationObserver observer( |
[email protected] | ad50def5 | 2011-10-19 23:17:07 | [diff] [blame] | 1087 | content::NOTIFICATION_LOAD_STOP, |
| 1088 | content::NotificationService::AllSources()); |
[email protected] | 5d9cace7 | 2012-06-21 16:07:12 | [diff] [blame] | 1089 | chrome::ShowSettings(browser()); |
[email protected] | ddddfda | 2011-07-14 23:19:39 | [diff] [blame] | 1090 | observer.Wait(); |
| 1091 | } |
[email protected] | fcca741b | 2011-06-17 22:46:37 | [diff] [blame] | 1092 | EXPECT_EQ(2, browser()->tab_count()); |
[email protected] | 52877dbc6 | 2012-06-29 22:22:03 | [diff] [blame] | 1093 | EXPECT_EQ(GetSettingsURL(), |
[email protected] | f8f93eb | 2012-09-25 03:06:24 | [diff] [blame] | 1094 | ShortenUberURL(chrome::GetActiveWebContents(browser())->GetURL())); |
[email protected] | fcca741b | 2011-06-17 22:46:37 | [diff] [blame] | 1095 | } |
| 1096 | |
| 1097 | IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, |
| 1098 | NavigateFromNTPToOptionsPageInSameTab) { |
[email protected] | ddddfda | 2011-07-14 23:19:39 | [diff] [blame] | 1099 | { |
[email protected] | a7fe911 | 2012-07-20 02:34:45 | [diff] [blame] | 1100 | content::WindowedNotificationObserver observer( |
[email protected] | ad50def5 | 2011-10-19 23:17:07 | [diff] [blame] | 1101 | content::NOTIFICATION_LOAD_STOP, |
| 1102 | content::NotificationService::AllSources()); |
[email protected] | 5d9cace7 | 2012-06-21 16:07:12 | [diff] [blame] | 1103 | chrome::ShowClearBrowsingDataDialog(browser()); |
[email protected] | ddddfda | 2011-07-14 23:19:39 | [diff] [blame] | 1104 | observer.Wait(); |
| 1105 | } |
[email protected] | fcca741b | 2011-06-17 22:46:37 | [diff] [blame] | 1106 | EXPECT_EQ(1, browser()->tab_count()); |
[email protected] | a048ad2 | 2012-03-23 04:26:56 | [diff] [blame] | 1107 | EXPECT_EQ(GetClearBrowsingDataURL(), |
[email protected] | 52877dbc6 | 2012-06-29 22:22:03 | [diff] [blame] | 1108 | chrome::GetActiveWebContents(browser())->GetURL()); |
[email protected] | fcca741b | 2011-06-17 22:46:37 | [diff] [blame] | 1109 | |
[email protected] | a37d4b0 | 2012-06-25 21:56:10 | [diff] [blame] | 1110 | chrome::NewTab(browser()); |
[email protected] | fcca741b | 2011-06-17 22:46:37 | [diff] [blame] | 1111 | EXPECT_EQ(2, browser()->tab_count()); |
| 1112 | |
[email protected] | ddddfda | 2011-07-14 23:19:39 | [diff] [blame] | 1113 | { |
[email protected] | a7fe911 | 2012-07-20 02:34:45 | [diff] [blame] | 1114 | content::WindowedNotificationObserver observer( |
[email protected] | ad50def5 | 2011-10-19 23:17:07 | [diff] [blame] | 1115 | content::NOTIFICATION_LOAD_STOP, |
| 1116 | content::NotificationService::AllSources()); |
[email protected] | 5d9cace7 | 2012-06-21 16:07:12 | [diff] [blame] | 1117 | chrome::ShowClearBrowsingDataDialog(browser()); |
[email protected] | ddddfda | 2011-07-14 23:19:39 | [diff] [blame] | 1118 | observer.Wait(); |
| 1119 | } |
[email protected] | fcca741b | 2011-06-17 22:46:37 | [diff] [blame] | 1120 | EXPECT_EQ(2, browser()->tab_count()); |
[email protected] | a048ad2 | 2012-03-23 04:26:56 | [diff] [blame] | 1121 | EXPECT_EQ(GetClearBrowsingDataURL(), |
[email protected] | 52877dbc6 | 2012-06-29 22:22:03 | [diff] [blame] | 1122 | chrome::GetActiveWebContents(browser())->GetURL()); |
[email protected] | fcca741b | 2011-06-17 22:46:37 | [diff] [blame] | 1123 | } |
| 1124 | |
[email protected] | ccb8aac | 2012-05-21 23:00:16 | [diff] [blame] | 1125 | // Times out on mac, fails on linux. |
| 1126 | // http://crbug.com/119779 |
| 1127 | #if defined(OS_MACOSX) || defined(OS_LINUX) |
[email protected] | aac43c7 | 2012-03-23 18:41:02 | [diff] [blame] | 1128 | #define MAYBE_NavigateFromOtherTabToSingletonOptions DISABLED_NavigateFromOtherTabToSingletonOptions |
| 1129 | #else |
| 1130 | #define MAYBE_NavigateFromOtherTabToSingletonOptions NavigatorFrameOtherTabToSingletonOptions |
| 1131 | #endif |
[email protected] | fcca741b | 2011-06-17 22:46:37 | [diff] [blame] | 1132 | IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, |
[email protected] | aac43c7 | 2012-03-23 18:41:02 | [diff] [blame] | 1133 | MAYBE_NavigateFromOtherTabToSingletonOptions) { |
[email protected] | ddddfda | 2011-07-14 23:19:39 | [diff] [blame] | 1134 | { |
[email protected] | a7fe911 | 2012-07-20 02:34:45 | [diff] [blame] | 1135 | content::WindowedNotificationObserver observer( |
[email protected] | ad50def5 | 2011-10-19 23:17:07 | [diff] [blame] | 1136 | content::NOTIFICATION_LOAD_STOP, |
| 1137 | content::NotificationService::AllSources()); |
[email protected] | 5d9cace7 | 2012-06-21 16:07:12 | [diff] [blame] | 1138 | chrome::ShowSettings(browser()); |
[email protected] | ddddfda | 2011-07-14 23:19:39 | [diff] [blame] | 1139 | observer.Wait(); |
| 1140 | } |
| 1141 | { |
[email protected] | a7fe911 | 2012-07-20 02:34:45 | [diff] [blame] | 1142 | content::WindowedNotificationObserver observer( |
[email protected] | ad50def5 | 2011-10-19 23:17:07 | [diff] [blame] | 1143 | content::NOTIFICATION_LOAD_STOP, |
| 1144 | content::NotificationService::AllSources()); |
[email protected] | 52877dbc6 | 2012-06-29 22:22:03 | [diff] [blame] | 1145 | chrome::AddSelectedTabWithURL(browser(), GetGoogleURL(), |
| 1146 | content::PAGE_TRANSITION_LINK); |
[email protected] | ddddfda | 2011-07-14 23:19:39 | [diff] [blame] | 1147 | observer.Wait(); |
| 1148 | } |
[email protected] | fcca741b | 2011-06-17 22:46:37 | [diff] [blame] | 1149 | |
[email protected] | ddddfda | 2011-07-14 23:19:39 | [diff] [blame] | 1150 | { |
[email protected] | a7fe911 | 2012-07-20 02:34:45 | [diff] [blame] | 1151 | content::WindowedNotificationObserver observer( |
[email protected] | ad50def5 | 2011-10-19 23:17:07 | [diff] [blame] | 1152 | content::NOTIFICATION_LOAD_STOP, |
| 1153 | content::NotificationService::AllSources()); |
[email protected] | 5d9cace7 | 2012-06-21 16:07:12 | [diff] [blame] | 1154 | chrome::ShowSettings(browser()); |
[email protected] | ddddfda | 2011-07-14 23:19:39 | [diff] [blame] | 1155 | observer.Wait(); |
| 1156 | } |
[email protected] | fcca741b | 2011-06-17 22:46:37 | [diff] [blame] | 1157 | EXPECT_EQ(2, browser()->tab_count()); |
[email protected] | ddddfda | 2011-07-14 23:19:39 | [diff] [blame] | 1158 | EXPECT_EQ(GetSettingsURL(), |
[email protected] | f8f93eb | 2012-09-25 03:06:24 | [diff] [blame] | 1159 | ShortenUberURL(chrome::GetActiveWebContents(browser())->GetURL())); |
[email protected] | fcca741b | 2011-06-17 22:46:37 | [diff] [blame] | 1160 | } |
| 1161 | |
[email protected] | a048ad2 | 2012-03-23 04:26:56 | [diff] [blame] | 1162 | // TODO(csilv): Update this for uber page. http://crbug.com/111579. |
[email protected] | ddddfda | 2011-07-14 23:19:39 | [diff] [blame] | 1163 | IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, |
[email protected] | a048ad2 | 2012-03-23 04:26:56 | [diff] [blame] | 1164 | DISABLED_NavigateFromDefaultToHistoryInSameTab) { |
[email protected] | ddddfda | 2011-07-14 23:19:39 | [diff] [blame] | 1165 | { |
[email protected] | a7fe911 | 2012-07-20 02:34:45 | [diff] [blame] | 1166 | content::WindowedNotificationObserver observer( |
[email protected] | ad50def5 | 2011-10-19 23:17:07 | [diff] [blame] | 1167 | content::NOTIFICATION_LOAD_STOP, |
| 1168 | content::NotificationService::AllSources()); |
[email protected] | 5d9cace7 | 2012-06-21 16:07:12 | [diff] [blame] | 1169 | chrome::ShowHistory(browser()); |
[email protected] | ddddfda | 2011-07-14 23:19:39 | [diff] [blame] | 1170 | observer.Wait(); |
| 1171 | } |
| 1172 | EXPECT_EQ(1, browser()->tab_count()); |
[email protected] | 11e03fb | 2012-03-03 19:07:05 | [diff] [blame] | 1173 | EXPECT_EQ(GURL(chrome::kChromeUIHistoryFrameURL), |
[email protected] | 52877dbc6 | 2012-06-29 22:22:03 | [diff] [blame] | 1174 | chrome::GetActiveWebContents(browser())->GetURL()); |
[email protected] | ddddfda | 2011-07-14 23:19:39 | [diff] [blame] | 1175 | } |
| 1176 | |
| 1177 | IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, |
| 1178 | NavigateFromDefaultToBookmarksInSameTab) { |
| 1179 | { |
[email protected] | a7fe911 | 2012-07-20 02:34:45 | [diff] [blame] | 1180 | content::WindowedNotificationObserver observer( |
[email protected] | ad50def5 | 2011-10-19 23:17:07 | [diff] [blame] | 1181 | content::NOTIFICATION_LOAD_STOP, |
| 1182 | content::NotificationService::AllSources()); |
[email protected] | 5d9cace7 | 2012-06-21 16:07:12 | [diff] [blame] | 1183 | chrome::ShowBookmarkManager(browser()); |
[email protected] | ddddfda | 2011-07-14 23:19:39 | [diff] [blame] | 1184 | observer.Wait(); |
| 1185 | } |
| 1186 | EXPECT_EQ(1, browser()->tab_count()); |
| 1187 | EXPECT_EQ(GURL(chrome::kChromeUIBookmarksURL), |
[email protected] | 52877dbc6 | 2012-06-29 22:22:03 | [diff] [blame] | 1188 | chrome::GetActiveWebContents(browser())->GetURL()); |
[email protected] | ddddfda | 2011-07-14 23:19:39 | [diff] [blame] | 1189 | } |
| 1190 | |
| 1191 | IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, |
| 1192 | NavigateFromDefaultToDownloadsInSameTab) { |
| 1193 | { |
[email protected] | a7fe911 | 2012-07-20 02:34:45 | [diff] [blame] | 1194 | content::WindowedNotificationObserver observer( |
[email protected] | ad50def5 | 2011-10-19 23:17:07 | [diff] [blame] | 1195 | content::NOTIFICATION_LOAD_STOP, |
| 1196 | content::NotificationService::AllSources()); |
[email protected] | 5d9cace7 | 2012-06-21 16:07:12 | [diff] [blame] | 1197 | chrome::ShowDownloads(browser()); |
[email protected] | ddddfda | 2011-07-14 23:19:39 | [diff] [blame] | 1198 | observer.Wait(); |
| 1199 | } |
| 1200 | EXPECT_EQ(1, browser()->tab_count()); |
| 1201 | EXPECT_EQ(GURL(chrome::kChromeUIDownloadsURL), |
[email protected] | 52877dbc6 | 2012-06-29 22:22:03 | [diff] [blame] | 1202 | chrome::GetActiveWebContents(browser())->GetURL()); |
[email protected] | ddddfda | 2011-07-14 23:19:39 | [diff] [blame] | 1203 | } |
| 1204 | |
[email protected] | 8fb16a8 | 2012-08-17 02:17:59 | [diff] [blame] | 1205 | IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, |
| 1206 | NavigateWithoutBrowser) { |
| 1207 | // First navigate using the profile of the existing browser window, and |
| 1208 | // check that the window is reused. |
| 1209 | chrome::NavigateParams params(browser()->profile(), GetGoogleURL(), |
| 1210 | content::PAGE_TRANSITION_LINK); |
| 1211 | ui_test_utils::NavigateToURL(¶ms); |
| 1212 | EXPECT_EQ(1u, BrowserList::size()); |
| 1213 | |
| 1214 | // Now navigate using the incognito profile and check that a new window |
| 1215 | // is created. |
| 1216 | chrome::NavigateParams params_incognito( |
| 1217 | browser()->profile()->GetOffTheRecordProfile(), |
| 1218 | GetGoogleURL(), content::PAGE_TRANSITION_LINK); |
| 1219 | ui_test_utils::NavigateToURL(¶ms_incognito); |
| 1220 | EXPECT_EQ(2u, BrowserList::size()); |
| 1221 | } |
| 1222 | |
[email protected] | ddddfda | 2011-07-14 23:19:39 | [diff] [blame] | 1223 | } // namespace |