[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" |
| 9 | #include "chrome/browser/autocomplete/autocomplete_edit.h" |
[email protected] | 93ad8e1c | 2011-11-08 21:34:05 | [diff] [blame] | 10 | #include "chrome/browser/prefs/incognito_mode_prefs.h" |
| 11 | #include "chrome/browser/prefs/pref_service.h" |
[email protected] | 8ecad5e | 2010-12-02 21:18:33 | [diff] [blame] | 12 | #include "chrome/browser/profiles/profile.h" |
[email protected] | a1feae5 | 2010-10-11 22:14:45 | [diff] [blame] | 13 | #include "chrome/browser/tabs/tab_strip_model.h" |
[email protected] | bb89e748 | 2010-11-17 18:27:04 | [diff] [blame] | 14 | #include "chrome/browser/ui/browser_list.h" |
[email protected] | 339d6dd | 2010-11-12 00:41:58 | [diff] [blame] | 15 | #include "chrome/browser/ui/browser_navigator.h" |
[email protected] | bb89e748 | 2010-11-17 18:27:04 | [diff] [blame] | 16 | #include "chrome/browser/ui/browser_window.h" |
[email protected] | 26c53e66 | 2011-07-09 02:21:02 | [diff] [blame] | 17 | #include "chrome/browser/ui/omnibox/location_bar.h" |
| 18 | #include "chrome/browser/ui/omnibox/omnibox_view.h" |
[email protected] | 6a3ec231 | 2010-12-02 19:30:19 | [diff] [blame] | 19 | #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" |
[email protected] | bb89e748 | 2010-11-17 18:27:04 | [diff] [blame] | 20 | #include "chrome/common/chrome_switches.h" |
[email protected] | 93ad8e1c | 2011-11-08 21:34:05 | [diff] [blame] | 21 | #include "chrome/common/pref_names.h" |
[email protected] | ddddfda | 2011-07-14 23:19:39 | [diff] [blame] | 22 | #include "chrome/common/url_constants.h" |
[email protected] | af44e7fb | 2011-07-29 18:32:32 | [diff] [blame] | 23 | #include "chrome/test/base/ui_test_utils.h" |
[email protected] | ad50def5 | 2011-10-19 23:17:07 | [diff] [blame] | 24 | #include "content/public/browser/notification_service.h" |
[email protected] | 0d6e9bd | 2011-10-18 04:29:16 | [diff] [blame] | 25 | #include "content/public/browser/notification_types.h" |
[email protected] | 83ff91c | 2012-01-05 20:54:13 | [diff] [blame] | 26 | #include "content/public/browser/web_contents.h" |
[email protected] | 8643e6d | 2012-01-18 20:26:10 | [diff] [blame] | 27 | #include "content/public/browser/web_contents_view.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() { |
| 38 | return GURL(chrome::kChromeUISettingsURL); |
| 39 | } |
| 40 | |
| 41 | GURL GetSettingsAdvancedURL() { |
| 42 | return GURL(chrome::kChromeUISettingsURL).Resolve( |
| 43 | chrome::kAdvancedOptionsSubPage); |
| 44 | } |
| 45 | |
| 46 | GURL GetSettingsBrowserURL() { |
| 47 | return GURL(chrome::kChromeUISettingsURL).Resolve( |
| 48 | chrome::kBrowserOptionsSubPage); |
| 49 | } |
| 50 | |
| 51 | GURL GetSettingsPersonalURL() { |
| 52 | return GURL(chrome::kChromeUISettingsURL).Resolve( |
| 53 | chrome::kPersonalOptionsSubPage); |
| 54 | } |
| 55 | |
| 56 | } // namespace |
| 57 | |
| 58 | |
[email protected] | bd817c2 | 2011-02-09 08:16:46 | [diff] [blame] | 59 | browser::NavigateParams BrowserNavigatorTest::MakeNavigateParams() const { |
| 60 | return MakeNavigateParams(browser()); |
| 61 | } |
[email protected] | a1feae5 | 2010-10-11 22:14:45 | [diff] [blame] | 62 | |
[email protected] | bd817c2 | 2011-02-09 08:16:46 | [diff] [blame] | 63 | browser::NavigateParams BrowserNavigatorTest::MakeNavigateParams( |
| 64 | Browser* browser) const { |
| 65 | browser::NavigateParams params(browser, GetGoogleURL(), |
[email protected] | 2905f74 | 2011-10-13 03:51:58 | [diff] [blame] | 66 | content::PAGE_TRANSITION_LINK); |
[email protected] | 7d32999 | 2011-04-15 18:20:02 | [diff] [blame] | 67 | params.window_action = browser::NavigateParams::SHOW_WINDOW; |
[email protected] | bd817c2 | 2011-02-09 08:16:46 | [diff] [blame] | 68 | return params; |
| 69 | } |
[email protected] | a1feae5 | 2010-10-11 22:14:45 | [diff] [blame] | 70 | |
[email protected] | bd817c2 | 2011-02-09 08:16:46 | [diff] [blame] | 71 | Browser* BrowserNavigatorTest::CreateEmptyBrowserForType(Browser::Type type, |
| 72 | Profile* profile) { |
| 73 | Browser* browser = Browser::CreateForType(type, profile); |
| 74 | browser->AddBlankTab(true); |
| 75 | return browser; |
| 76 | } |
[email protected] | a1feae5 | 2010-10-11 22:14:45 | [diff] [blame] | 77 | |
[email protected] | b35b26b3 | 2011-05-05 20:35:14 | [diff] [blame] | 78 | Browser* BrowserNavigatorTest::CreateEmptyBrowserForApp(Browser::Type type, |
| 79 | Profile* profile) { |
| 80 | Browser* browser = Browser::CreateForApp(Browser::TYPE_POPUP, "Test", |
[email protected] | 5c20924 | 2011-06-06 20:36:17 | [diff] [blame] | 81 | gfx::Rect(), profile); |
[email protected] | b35b26b3 | 2011-05-05 20:35:14 | [diff] [blame] | 82 | browser->AddBlankTab(true); |
| 83 | return browser; |
| 84 | } |
| 85 | |
[email protected] | bd817c2 | 2011-02-09 08:16:46 | [diff] [blame] | 86 | TabContentsWrapper* BrowserNavigatorTest::CreateTabContents() { |
| 87 | return Browser::TabContentsFactory( |
| 88 | browser()->profile(), |
| 89 | NULL, |
| 90 | MSG_ROUTING_NONE, |
[email protected] | bb81f38 | 2012-01-03 22:45:44 | [diff] [blame] | 91 | browser()->GetSelectedWebContents(), |
[email protected] | bd817c2 | 2011-02-09 08:16:46 | [diff] [blame] | 92 | NULL); |
| 93 | } |
[email protected] | a1feae5 | 2010-10-11 22:14:45 | [diff] [blame] | 94 | |
[email protected] | bd817c2 | 2011-02-09 08:16:46 | [diff] [blame] | 95 | void BrowserNavigatorTest::RunSuppressTest(WindowOpenDisposition disposition) { |
[email protected] | 4ca1530 | 2012-01-03 05:53:20 | [diff] [blame] | 96 | GURL old_url = browser()->GetSelectedWebContents()->GetURL(); |
[email protected] | bd817c2 | 2011-02-09 08:16:46 | [diff] [blame] | 97 | browser::NavigateParams p(MakeNavigateParams()); |
| 98 | p.disposition = disposition; |
| 99 | browser::Navigate(&p); |
[email protected] | a1feae5 | 2010-10-11 22:14:45 | [diff] [blame] | 100 | |
[email protected] | bd817c2 | 2011-02-09 08:16:46 | [diff] [blame] | 101 | // Nothing should have happened as a result of Navigate(); |
| 102 | EXPECT_EQ(1, browser()->tab_count()); |
| 103 | EXPECT_EQ(1u, BrowserList::size()); |
[email protected] | 4ca1530 | 2012-01-03 05:53:20 | [diff] [blame] | 104 | EXPECT_EQ(old_url, browser()->GetSelectedWebContents()->GetURL()); |
[email protected] | bd817c2 | 2011-02-09 08:16:46 | [diff] [blame] | 105 | } |
[email protected] | bb89e748 | 2010-11-17 18:27:04 | [diff] [blame] | 106 | |
[email protected] | fc0ed30 | 2011-11-29 23:17:19 | [diff] [blame] | 107 | void BrowserNavigatorTest::RunUseNonIncognitoWindowTest(const GURL& url) { |
| 108 | Browser* incognito_browser = CreateIncognitoBrowser(); |
| 109 | |
| 110 | EXPECT_EQ(2u, BrowserList::size()); |
| 111 | EXPECT_EQ(1, browser()->tab_count()); |
| 112 | EXPECT_EQ(1, incognito_browser->tab_count()); |
| 113 | |
| 114 | // Navigate to the page. |
| 115 | browser::NavigateParams p(MakeNavigateParams(incognito_browser)); |
| 116 | p.disposition = SINGLETON_TAB; |
| 117 | p.url = url; |
| 118 | p.window_action = browser::NavigateParams::SHOW_WINDOW; |
| 119 | browser::Navigate(&p); |
| 120 | |
| 121 | // This page should be opened in browser() window. |
| 122 | EXPECT_NE(incognito_browser, p.browser); |
| 123 | EXPECT_EQ(browser(), p.browser); |
| 124 | EXPECT_EQ(2, browser()->tab_count()); |
[email protected] | 4ca1530 | 2012-01-03 05:53:20 | [diff] [blame] | 125 | EXPECT_EQ(url, browser()->GetSelectedWebContents()->GetURL()); |
[email protected] | fc0ed30 | 2011-11-29 23:17:19 | [diff] [blame] | 126 | } |
| 127 | |
| 128 | void BrowserNavigatorTest::RunDoNothingIfIncognitoIsForcedTest( |
| 129 | const GURL& url) { |
| 130 | Browser* browser = CreateIncognitoBrowser(); |
| 131 | |
| 132 | // Set kIncognitoModeAvailability to FORCED. |
| 133 | PrefService* prefs1 = browser->profile()->GetPrefs(); |
| 134 | prefs1->SetInteger(prefs::kIncognitoModeAvailability, |
| 135 | IncognitoModePrefs::FORCED); |
| 136 | PrefService* prefs2 = browser->profile()->GetOriginalProfile()->GetPrefs(); |
| 137 | prefs2->SetInteger(prefs::kIncognitoModeAvailability, |
| 138 | IncognitoModePrefs::FORCED); |
| 139 | |
| 140 | // Navigate to the page. |
| 141 | browser::NavigateParams p(MakeNavigateParams(browser)); |
| 142 | p.disposition = OFF_THE_RECORD; |
| 143 | p.url = url; |
| 144 | p.window_action = browser::NavigateParams::SHOW_WINDOW; |
| 145 | browser::Navigate(&p); |
| 146 | |
| 147 | // The page should not be opened. |
| 148 | EXPECT_EQ(browser, p.browser); |
| 149 | EXPECT_EQ(1, browser->tab_count()); |
| 150 | EXPECT_EQ(GURL(chrome::kAboutBlankURL), |
[email protected] | 4ca1530 | 2012-01-03 05:53:20 | [diff] [blame] | 151 | browser->GetSelectedWebContents()->GetURL()); |
[email protected] | fc0ed30 | 2011-11-29 23:17:19 | [diff] [blame] | 152 | } |
| 153 | |
[email protected] | 6c2381d | 2011-10-19 02:52:53 | [diff] [blame] | 154 | void BrowserNavigatorTest::Observe( |
| 155 | int type, |
| 156 | const content::NotificationSource& source, |
| 157 | const content::NotificationDetails& details) { |
[email protected] | 43211582 | 2011-07-10 15:52:27 | [diff] [blame] | 158 | switch (type) { |
| 159 | case content::NOTIFICATION_RENDER_VIEW_HOST_CREATED_FOR_TAB: { |
[email protected] | bd817c2 | 2011-02-09 08:16:46 | [diff] [blame] | 160 | ++this->created_tab_contents_count_; |
| 161 | break; |
[email protected] | fa7ebe0 | 2010-11-29 23:04:57 | [diff] [blame] | 162 | } |
[email protected] | bd817c2 | 2011-02-09 08:16:46 | [diff] [blame] | 163 | default: |
| 164 | break; |
[email protected] | fa7ebe0 | 2010-11-29 23:04:57 | [diff] [blame] | 165 | } |
[email protected] | bd817c2 | 2011-02-09 08:16:46 | [diff] [blame] | 166 | } |
[email protected] | fa7ebe0 | 2010-11-29 23:04:57 | [diff] [blame] | 167 | |
[email protected] | ddddfda | 2011-07-14 23:19:39 | [diff] [blame] | 168 | |
[email protected] | bd817c2 | 2011-02-09 08:16:46 | [diff] [blame] | 169 | namespace { |
[email protected] | a1feae5 | 2010-10-11 22:14:45 | [diff] [blame] | 170 | |
[email protected] | a1feae5 | 2010-10-11 22:14:45 | [diff] [blame] | 171 | // This test verifies that when a navigation occurs within a tab, the tab count |
| 172 | // of the Browser remains the same and the current tab bears the loaded URL. |
| 173 | IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_CurrentTab) { |
[email protected] | ddddfda | 2011-07-14 23:19:39 | [diff] [blame] | 174 | ui_test_utils::NavigateToURL(browser(), GetGoogleURL()); |
[email protected] | 4ca1530 | 2012-01-03 05:53:20 | [diff] [blame] | 175 | EXPECT_EQ(GetGoogleURL(), browser()->GetSelectedWebContents()->GetURL()); |
[email protected] | a1feae5 | 2010-10-11 22:14:45 | [diff] [blame] | 176 | // We should have one window with one tab. |
| 177 | EXPECT_EQ(1u, BrowserList::size()); |
| 178 | EXPECT_EQ(1, browser()->tab_count()); |
| 179 | } |
| 180 | |
[email protected] | bd817c2 | 2011-02-09 08:16:46 | [diff] [blame] | 181 | // 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] | 182 | // in another or an existing window, or added if it is not. |
| 183 | IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_SingletonTabExisting) { |
[email protected] | 19d9f3a | 2010-10-14 21:49:36 | [diff] [blame] | 184 | GURL singleton_url1("http://maps.google.com/"); |
[email protected] | fa7ebe0 | 2010-11-29 23:04:57 | [diff] [blame] | 185 | |
| 186 | // Register for a notification if an additional tab_contents was instantiated. |
[email protected] | bd817c2 | 2011-02-09 08:16:46 | [diff] [blame] | 187 | // Opening a Singleton tab that is already opened should not be opening a new |
[email protected] | fa7ebe0 | 2010-11-29 23:04:57 | [diff] [blame] | 188 | // tab nor be creating a new TabContents object |
[email protected] | 6c2381d | 2011-10-19 02:52:53 | [diff] [blame] | 189 | content::NotificationRegistrar registrar; |
[email protected] | fa7ebe0 | 2010-11-29 23:04:57 | [diff] [blame] | 190 | |
| 191 | // As the registrar object goes out of scope, this will get unregistered |
[email protected] | 43211582 | 2011-07-10 15:52:27 | [diff] [blame] | 192 | registrar.Add(this, content::NOTIFICATION_RENDER_VIEW_HOST_CREATED_FOR_TAB, |
[email protected] | ad50def5 | 2011-10-19 23:17:07 | [diff] [blame] | 193 | content::NotificationService::AllSources()); |
[email protected] | fa7ebe0 | 2010-11-29 23:04:57 | [diff] [blame] | 194 | |
[email protected] | 2905f74 | 2011-10-13 03:51:58 | [diff] [blame] | 195 | browser()->AddSelectedTabWithURL( |
| 196 | singleton_url1, content::PAGE_TRANSITION_LINK); |
| 197 | browser()->AddSelectedTabWithURL( |
| 198 | GetGoogleURL(), content::PAGE_TRANSITION_LINK); |
[email protected] | 19d9f3a | 2010-10-14 21:49:36 | [diff] [blame] | 199 | |
| 200 | // We should have one browser with 3 tabs, the 3rd selected. |
| 201 | EXPECT_EQ(1u, BrowserList::size()); |
[email protected] | 1ea49d5 | 2011-04-12 17:44:44 | [diff] [blame] | 202 | EXPECT_EQ(2, browser()->active_index()); |
[email protected] | 19d9f3a | 2010-10-14 21:49:36 | [diff] [blame] | 203 | |
[email protected] | fa7ebe0 | 2010-11-29 23:04:57 | [diff] [blame] | 204 | unsigned int previous_tab_contents_count = |
| 205 | created_tab_contents_count_ = 0; |
| 206 | |
[email protected] | 19d9f3a | 2010-10-14 21:49:36 | [diff] [blame] | 207 | // Navigate to singleton_url1. |
| 208 | browser::NavigateParams p(MakeNavigateParams()); |
| 209 | p.disposition = SINGLETON_TAB; |
| 210 | p.url = singleton_url1; |
| 211 | browser::Navigate(&p); |
| 212 | |
| 213 | // The middle tab should now be selected. |
| 214 | EXPECT_EQ(browser(), p.browser); |
[email protected] | 1ea49d5 | 2011-04-12 17:44:44 | [diff] [blame] | 215 | EXPECT_EQ(1, browser()->active_index()); |
[email protected] | fa7ebe0 | 2010-11-29 23:04:57 | [diff] [blame] | 216 | |
| 217 | // No tab contents should have been created |
| 218 | EXPECT_EQ(previous_tab_contents_count, |
| 219 | created_tab_contents_count_); |
[email protected] | 19d9f3a | 2010-10-14 21:49:36 | [diff] [blame] | 220 | } |
| 221 | |
| 222 | IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, |
[email protected] | 578c696 | 2011-08-24 22:06:40 | [diff] [blame] | 223 | Disposition_SingletonTabRespectingRef) { |
| 224 | GURL singleton_ref_url1("http://maps.google.com/#a"); |
| 225 | GURL singleton_ref_url2("http://maps.google.com/#b"); |
| 226 | GURL singleton_ref_url3("http://maps.google.com/"); |
| 227 | |
[email protected] | 2905f74 | 2011-10-13 03:51:58 | [diff] [blame] | 228 | browser()->AddSelectedTabWithURL( |
| 229 | singleton_ref_url1, content::PAGE_TRANSITION_LINK); |
[email protected] | 578c696 | 2011-08-24 22:06:40 | [diff] [blame] | 230 | |
| 231 | // We should have one browser with 2 tabs, 2nd selected. |
| 232 | EXPECT_EQ(1u, BrowserList::size()); |
| 233 | EXPECT_EQ(2, browser()->tab_count()); |
| 234 | EXPECT_EQ(1, browser()->active_index()); |
| 235 | |
| 236 | // Navigate to singleton_url2. |
| 237 | browser::NavigateParams p(MakeNavigateParams()); |
| 238 | p.disposition = SINGLETON_TAB; |
| 239 | p.url = singleton_ref_url2; |
| 240 | browser::Navigate(&p); |
| 241 | |
| 242 | // We should now have 2 tabs, the 2nd one selected. |
| 243 | EXPECT_EQ(browser(), p.browser); |
| 244 | EXPECT_EQ(2, browser()->tab_count()); |
| 245 | EXPECT_EQ(1, browser()->active_index()); |
| 246 | |
| 247 | // Navigate to singleton_url2, but with respect ref set. |
| 248 | p = MakeNavigateParams(); |
| 249 | p.disposition = SINGLETON_TAB; |
| 250 | p.url = singleton_ref_url2; |
| 251 | p.ref_behavior = browser::NavigateParams::RESPECT_REF; |
| 252 | browser::Navigate(&p); |
| 253 | |
| 254 | // We should now have 3 tabs, the 3th one selected. |
| 255 | EXPECT_EQ(browser(), p.browser); |
| 256 | EXPECT_EQ(3, browser()->tab_count()); |
| 257 | EXPECT_EQ(2, browser()->active_index()); |
| 258 | |
| 259 | // Navigate to singleton_url3. |
| 260 | p = MakeNavigateParams(); |
| 261 | p.disposition = SINGLETON_TAB; |
| 262 | p.url = singleton_ref_url3; |
| 263 | p.ref_behavior = browser::NavigateParams::RESPECT_REF; |
| 264 | browser::Navigate(&p); |
| 265 | |
| 266 | // We should now have 4 tabs, the 4th one selected. |
| 267 | EXPECT_EQ(browser(), p.browser); |
| 268 | EXPECT_EQ(4, browser()->tab_count()); |
| 269 | EXPECT_EQ(3, browser()->active_index()); |
| 270 | } |
| 271 | |
| 272 | IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, |
[email protected] | 19d9f3a | 2010-10-14 21:49:36 | [diff] [blame] | 273 | Disposition_SingletonTabNoneExisting) { |
[email protected] | 19d9f3a | 2010-10-14 21:49:36 | [diff] [blame] | 274 | GURL singleton_url1("http://maps.google.com/"); |
| 275 | |
[email protected] | bd817c2 | 2011-02-09 08:16:46 | [diff] [blame] | 276 | // We should have one browser with 1 tab. |
[email protected] | 19d9f3a | 2010-10-14 21:49:36 | [diff] [blame] | 277 | EXPECT_EQ(1u, BrowserList::size()); |
[email protected] | 1ea49d5 | 2011-04-12 17:44:44 | [diff] [blame] | 278 | EXPECT_EQ(0, browser()->active_index()); |
[email protected] | 19d9f3a | 2010-10-14 21:49:36 | [diff] [blame] | 279 | |
| 280 | // Navigate to singleton_url1. |
| 281 | browser::NavigateParams p(MakeNavigateParams()); |
| 282 | p.disposition = SINGLETON_TAB; |
| 283 | p.url = singleton_url1; |
| 284 | browser::Navigate(&p); |
| 285 | |
| 286 | // We should now have 2 tabs, the 2nd one selected. |
| 287 | EXPECT_EQ(browser(), p.browser); |
| 288 | EXPECT_EQ(2, browser()->tab_count()); |
[email protected] | 1ea49d5 | 2011-04-12 17:44:44 | [diff] [blame] | 289 | EXPECT_EQ(1, browser()->active_index()); |
[email protected] | a1feae5 | 2010-10-11 22:14:45 | [diff] [blame] | 290 | } |
| 291 | |
| 292 | // This test verifies that when a navigation results in a foreground tab, the |
| 293 | // tab count of the Browser increases and the selected tab shifts to the new |
| 294 | // foreground tab. |
| 295 | IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_NewForegroundTab) { |
[email protected] | 4ca1530 | 2012-01-03 05:53:20 | [diff] [blame] | 296 | WebContents* old_contents = browser()->GetSelectedWebContents(); |
[email protected] | a1feae5 | 2010-10-11 22:14:45 | [diff] [blame] | 297 | browser::NavigateParams p(MakeNavigateParams()); |
| 298 | p.disposition = NEW_FOREGROUND_TAB; |
[email protected] | 19d9f3a | 2010-10-14 21:49:36 | [diff] [blame] | 299 | browser::Navigate(&p); |
[email protected] | 4ca1530 | 2012-01-03 05:53:20 | [diff] [blame] | 300 | EXPECT_NE(old_contents, browser()->GetSelectedWebContents()); |
[email protected] | 3c9e187 | 2010-11-18 16:17:49 | [diff] [blame] | 301 | EXPECT_EQ(browser()->GetSelectedTabContentsWrapper(), p.target_contents); |
[email protected] | a1feae5 | 2010-10-11 22:14:45 | [diff] [blame] | 302 | EXPECT_EQ(2, browser()->tab_count()); |
| 303 | } |
| 304 | |
| 305 | // This test verifies that when a navigation results in a background tab, the |
| 306 | // tab count of the Browser increases but the selected tab remains the same. |
| 307 | IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_NewBackgroundTab) { |
[email protected] | 4ca1530 | 2012-01-03 05:53:20 | [diff] [blame] | 308 | WebContents* old_contents = browser()->GetSelectedWebContents(); |
[email protected] | a1feae5 | 2010-10-11 22:14:45 | [diff] [blame] | 309 | browser::NavigateParams p(MakeNavigateParams()); |
| 310 | p.disposition = NEW_BACKGROUND_TAB; |
[email protected] | 19d9f3a | 2010-10-14 21:49:36 | [diff] [blame] | 311 | browser::Navigate(&p); |
[email protected] | 4ca1530 | 2012-01-03 05:53:20 | [diff] [blame] | 312 | WebContents* new_contents = browser()->GetSelectedWebContents(); |
[email protected] | a1feae5 | 2010-10-11 22:14:45 | [diff] [blame] | 313 | // The selected tab should have remained unchanged, since the new tab was |
| 314 | // opened in the background. |
| 315 | EXPECT_EQ(old_contents, new_contents); |
| 316 | EXPECT_EQ(2, browser()->tab_count()); |
| 317 | } |
| 318 | |
| 319 | // This test verifies that when a navigation requiring a new foreground tab |
| 320 | // occurs in a Browser that cannot host multiple tabs, the new foreground tab |
| 321 | // is created in an existing compatible Browser. |
| 322 | IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, |
| 323 | Disposition_IncompatibleWindow_Existing) { |
| 324 | // Open a foreground tab in a window that cannot open popups when there is an |
| 325 | // existing compatible window somewhere else that they can be opened within. |
| 326 | Browser* popup = CreateEmptyBrowserForType(Browser::TYPE_POPUP, |
| 327 | browser()->profile()); |
| 328 | browser::NavigateParams p(MakeNavigateParams(popup)); |
| 329 | p.disposition = NEW_FOREGROUND_TAB; |
[email protected] | 19d9f3a | 2010-10-14 21:49:36 | [diff] [blame] | 330 | browser::Navigate(&p); |
[email protected] | a1feae5 | 2010-10-11 22:14:45 | [diff] [blame] | 331 | |
| 332 | // Navigate() should have opened the tab in a different browser since the |
| 333 | // one we supplied didn't support additional tabs. |
| 334 | EXPECT_NE(popup, p.browser); |
| 335 | |
| 336 | // Since browser() is an existing compatible tabbed browser, it should have |
| 337 | // opened the tab there. |
| 338 | EXPECT_EQ(browser(), p.browser); |
| 339 | |
| 340 | // We should be left with 2 windows, the popup with one tab and the browser() |
| 341 | // provided by the framework with two. |
| 342 | EXPECT_EQ(2u, BrowserList::size()); |
| 343 | EXPECT_EQ(1, popup->tab_count()); |
| 344 | EXPECT_EQ(2, browser()->tab_count()); |
| 345 | } |
| 346 | |
| 347 | // This test verifies that when a navigation requiring a new foreground tab |
| 348 | // occurs in a Browser that cannot host multiple tabs and no compatible Browser |
| 349 | // that can is open, a compatible Browser is created. |
| 350 | IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, |
| 351 | Disposition_IncompatibleWindow_NoExisting) { |
| 352 | // We want to simulate not being able to find an existing window compatible |
| 353 | // with our non-tabbed browser window so Navigate() is forced to create a |
| 354 | // new compatible window. Because browser() supplied by the in-process |
| 355 | // browser testing framework is compatible with browser()->profile(), we |
| 356 | // need a different profile, and creating a popup window with an incognito |
| 357 | // profile is a quick and dirty way of achieving this. |
| 358 | Browser* popup = CreateEmptyBrowserForType( |
[email protected] | b35b26b3 | 2011-05-05 20:35:14 | [diff] [blame] | 359 | Browser::TYPE_POPUP, |
| 360 | browser()->profile()->GetOffTheRecordProfile()); |
[email protected] | a1feae5 | 2010-10-11 22:14:45 | [diff] [blame] | 361 | browser::NavigateParams p(MakeNavigateParams(popup)); |
| 362 | p.disposition = NEW_FOREGROUND_TAB; |
[email protected] | 19d9f3a | 2010-10-14 21:49:36 | [diff] [blame] | 363 | browser::Navigate(&p); |
[email protected] | a1feae5 | 2010-10-11 22:14:45 | [diff] [blame] | 364 | |
| 365 | // Navigate() should have opened the tab in a different browser since the |
| 366 | // one we supplied didn't support additional tabs. |
| 367 | EXPECT_NE(popup, p.browser); |
| 368 | |
| 369 | // This time, browser() is _not_ compatible with popup since it is not an |
| 370 | // incognito window. |
| 371 | EXPECT_NE(browser(), p.browser); |
| 372 | |
| 373 | // We should have three windows, each with one tab: |
| 374 | // 1. the browser() provided by the framework (unchanged in this test) |
| 375 | // 2. the incognito popup we created originally |
| 376 | // 3. the new incognito tabbed browser that was created by Navigate(). |
| 377 | EXPECT_EQ(3u, BrowserList::size()); |
| 378 | EXPECT_EQ(1, browser()->tab_count()); |
| 379 | EXPECT_EQ(1, popup->tab_count()); |
| 380 | EXPECT_EQ(1, p.browser->tab_count()); |
[email protected] | b35b26b3 | 2011-05-05 20:35:14 | [diff] [blame] | 381 | EXPECT_TRUE(p.browser->is_type_tabbed()); |
[email protected] | a1feae5 | 2010-10-11 22:14:45 | [diff] [blame] | 382 | } |
| 383 | |
| 384 | // This test verifies that navigating with WindowOpenDisposition = NEW_POPUP |
| 385 | // from a normal Browser results in a new Browser with TYPE_POPUP. |
| 386 | IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_NewPopup) { |
| 387 | browser::NavigateParams p(MakeNavigateParams()); |
| 388 | p.disposition = NEW_POPUP; |
[email protected] | 588300d | 2011-04-28 21:06:35 | [diff] [blame] | 389 | p.window_bounds = gfx::Rect(0, 0, 200, 200); |
[email protected] | 7d32999 | 2011-04-15 18:20:02 | [diff] [blame] | 390 | // Wait for new popup to to load and gain focus. |
[email protected] | ddddfda | 2011-07-14 23:19:39 | [diff] [blame] | 391 | ui_test_utils::NavigateToURL(&p); |
[email protected] | a1feae5 | 2010-10-11 22:14:45 | [diff] [blame] | 392 | |
[email protected] | 7d32999 | 2011-04-15 18:20:02 | [diff] [blame] | 393 | // Navigate() should have opened a new, focused popup window. |
[email protected] | a1feae5 | 2010-10-11 22:14:45 | [diff] [blame] | 394 | EXPECT_NE(browser(), p.browser); |
[email protected] | 9db263a | 2011-04-15 20:53:47 | [diff] [blame] | 395 | #if 0 |
| 396 | // TODO(stevenjb): Enable this test. See: crbug.com/79493 |
[email protected] | 7d32999 | 2011-04-15 18:20:02 | [diff] [blame] | 397 | EXPECT_TRUE(p.browser->window()->IsActive()); |
| 398 | #endif |
[email protected] | b35b26b3 | 2011-05-05 20:35:14 | [diff] [blame] | 399 | EXPECT_TRUE(p.browser->is_type_popup()); |
| 400 | EXPECT_FALSE(p.browser->is_app()); |
[email protected] | a1feae5 | 2010-10-11 22:14:45 | [diff] [blame] | 401 | |
| 402 | // We should have two windows, the browser() provided by the framework and the |
| 403 | // new popup window. |
| 404 | EXPECT_EQ(2u, BrowserList::size()); |
| 405 | EXPECT_EQ(1, browser()->tab_count()); |
| 406 | EXPECT_EQ(1, p.browser->tab_count()); |
| 407 | } |
| 408 | |
| 409 | // This test verifies that navigating with WindowOpenDisposition = NEW_POPUP |
[email protected] | f112b0f | 2011-05-26 01:53:52 | [diff] [blame] | 410 | // from a normal Browser results in a new Browser with is_app() true. |
| 411 | IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_NewPopup_ExtensionId) { |
| 412 | browser::NavigateParams p(MakeNavigateParams()); |
| 413 | p.disposition = NEW_POPUP; |
| 414 | p.extension_app_id = "extensionappid"; |
| 415 | p.window_bounds = gfx::Rect(0, 0, 200, 200); |
[email protected] | f112b0f | 2011-05-26 01:53:52 | [diff] [blame] | 416 | // Wait for new popup to to load and gain focus. |
[email protected] | ddddfda | 2011-07-14 23:19:39 | [diff] [blame] | 417 | ui_test_utils::NavigateToURL(&p); |
[email protected] | f112b0f | 2011-05-26 01:53:52 | [diff] [blame] | 418 | |
| 419 | // Navigate() should have opened a new, focused popup window. |
| 420 | EXPECT_NE(browser(), p.browser); |
| 421 | EXPECT_TRUE(p.browser->is_type_popup()); |
| 422 | EXPECT_TRUE(p.browser->is_app()); |
| 423 | |
| 424 | // We should have two windows, the browser() provided by the framework and the |
| 425 | // new popup window. |
| 426 | EXPECT_EQ(2u, BrowserList::size()); |
| 427 | EXPECT_EQ(1, browser()->tab_count()); |
| 428 | EXPECT_EQ(1, p.browser->tab_count()); |
| 429 | } |
| 430 | |
| 431 | // This test verifies that navigating with WindowOpenDisposition = NEW_POPUP |
[email protected] | 300d1e5 | 2011-01-19 23:57:57 | [diff] [blame] | 432 | // from a normal popup results in a new Browser with TYPE_POPUP. |
| 433 | IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_NewPopupFromPopup) { |
| 434 | // Open a popup. |
| 435 | browser::NavigateParams p1(MakeNavigateParams()); |
| 436 | p1.disposition = NEW_POPUP; |
[email protected] | 588300d | 2011-04-28 21:06:35 | [diff] [blame] | 437 | p1.window_bounds = gfx::Rect(0, 0, 200, 200); |
[email protected] | 300d1e5 | 2011-01-19 23:57:57 | [diff] [blame] | 438 | browser::Navigate(&p1); |
| 439 | // Open another popup. |
| 440 | browser::NavigateParams p2(MakeNavigateParams(p1.browser)); |
| 441 | p2.disposition = NEW_POPUP; |
[email protected] | 588300d | 2011-04-28 21:06:35 | [diff] [blame] | 442 | p2.window_bounds = gfx::Rect(0, 0, 200, 200); |
[email protected] | 300d1e5 | 2011-01-19 23:57:57 | [diff] [blame] | 443 | browser::Navigate(&p2); |
| 444 | |
| 445 | // Navigate() should have opened a new normal popup window. |
| 446 | EXPECT_NE(p1.browser, p2.browser); |
[email protected] | b35b26b3 | 2011-05-05 20:35:14 | [diff] [blame] | 447 | EXPECT_TRUE(p2.browser->is_type_popup()); |
| 448 | EXPECT_FALSE(p2.browser->is_app()); |
[email protected] | 300d1e5 | 2011-01-19 23:57:57 | [diff] [blame] | 449 | |
| 450 | // We should have three windows, the browser() provided by the framework, |
| 451 | // the first popup window, and the second popup window. |
| 452 | EXPECT_EQ(3u, BrowserList::size()); |
| 453 | EXPECT_EQ(1, browser()->tab_count()); |
| 454 | EXPECT_EQ(1, p1.browser->tab_count()); |
| 455 | EXPECT_EQ(1, p2.browser->tab_count()); |
| 456 | } |
| 457 | |
| 458 | // This test verifies that navigating with WindowOpenDisposition = NEW_POPUP |
[email protected] | a1feae5 | 2010-10-11 22:14:45 | [diff] [blame] | 459 | // from an app frame results in a new Browser with TYPE_APP_POPUP. |
| 460 | IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, |
| 461 | Disposition_NewPopupFromAppWindow) { |
[email protected] | b35b26b3 | 2011-05-05 20:35:14 | [diff] [blame] | 462 | Browser* app_browser = CreateEmptyBrowserForApp(Browser::TYPE_TABBED, |
| 463 | browser()->profile()); |
[email protected] | a1feae5 | 2010-10-11 22:14:45 | [diff] [blame] | 464 | browser::NavigateParams p(MakeNavigateParams(app_browser)); |
| 465 | p.disposition = NEW_POPUP; |
[email protected] | 588300d | 2011-04-28 21:06:35 | [diff] [blame] | 466 | p.window_bounds = gfx::Rect(0, 0, 200, 200); |
[email protected] | 19d9f3a | 2010-10-14 21:49:36 | [diff] [blame] | 467 | browser::Navigate(&p); |
[email protected] | a1feae5 | 2010-10-11 22:14:45 | [diff] [blame] | 468 | |
| 469 | // Navigate() should have opened a new popup app window. |
| 470 | EXPECT_NE(app_browser, p.browser); |
| 471 | EXPECT_NE(browser(), p.browser); |
[email protected] | b35b26b3 | 2011-05-05 20:35:14 | [diff] [blame] | 472 | EXPECT_TRUE(p.browser->is_type_popup()); |
| 473 | EXPECT_TRUE(p.browser->is_app()); |
[email protected] | a1feae5 | 2010-10-11 22:14:45 | [diff] [blame] | 474 | |
| 475 | // We should now have three windows, the app window, the app popup it created, |
| 476 | // and the original browser() provided by the framework. |
| 477 | EXPECT_EQ(3u, BrowserList::size()); |
| 478 | EXPECT_EQ(1, browser()->tab_count()); |
| 479 | EXPECT_EQ(1, app_browser->tab_count()); |
| 480 | EXPECT_EQ(1, p.browser->tab_count()); |
| 481 | } |
| 482 | |
| 483 | // This test verifies that navigating with WindowOpenDisposition = NEW_POPUP |
[email protected] | 300d1e5 | 2011-01-19 23:57:57 | [diff] [blame] | 484 | // from an app popup results in a new Browser also of TYPE_APP_POPUP. |
| 485 | IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, |
| 486 | Disposition_NewPopupFromAppPopup) { |
[email protected] | b35b26b3 | 2011-05-05 20:35:14 | [diff] [blame] | 487 | Browser* app_browser = CreateEmptyBrowserForApp(Browser::TYPE_TABBED, |
| 488 | browser()->profile()); |
[email protected] | 300d1e5 | 2011-01-19 23:57:57 | [diff] [blame] | 489 | // Open an app popup. |
| 490 | browser::NavigateParams p1(MakeNavigateParams(app_browser)); |
| 491 | p1.disposition = NEW_POPUP; |
[email protected] | 588300d | 2011-04-28 21:06:35 | [diff] [blame] | 492 | p1.window_bounds = gfx::Rect(0, 0, 200, 200); |
[email protected] | 300d1e5 | 2011-01-19 23:57:57 | [diff] [blame] | 493 | browser::Navigate(&p1); |
| 494 | // Now open another app popup. |
| 495 | browser::NavigateParams p2(MakeNavigateParams(p1.browser)); |
| 496 | p2.disposition = NEW_POPUP; |
[email protected] | 588300d | 2011-04-28 21:06:35 | [diff] [blame] | 497 | p2.window_bounds = gfx::Rect(0, 0, 200, 200); |
[email protected] | 300d1e5 | 2011-01-19 23:57:57 | [diff] [blame] | 498 | browser::Navigate(&p2); |
| 499 | |
| 500 | // Navigate() should have opened a new popup app window. |
| 501 | EXPECT_NE(browser(), p1.browser); |
| 502 | EXPECT_NE(p1.browser, p2.browser); |
[email protected] | b35b26b3 | 2011-05-05 20:35:14 | [diff] [blame] | 503 | EXPECT_TRUE(p2.browser->is_type_popup()); |
| 504 | EXPECT_TRUE(p2.browser->is_app()); |
[email protected] | 300d1e5 | 2011-01-19 23:57:57 | [diff] [blame] | 505 | |
| 506 | // We should now have four windows, the app window, the first app popup, |
| 507 | // the second app popup, and the original browser() provided by the framework. |
| 508 | EXPECT_EQ(4u, BrowserList::size()); |
| 509 | EXPECT_EQ(1, browser()->tab_count()); |
| 510 | EXPECT_EQ(1, app_browser->tab_count()); |
| 511 | EXPECT_EQ(1, p1.browser->tab_count()); |
| 512 | EXPECT_EQ(1, p2.browser->tab_count()); |
| 513 | } |
| 514 | |
| 515 | // This test verifies that navigating with WindowOpenDisposition = NEW_POPUP |
[email protected] | a1feae5 | 2010-10-11 22:14:45 | [diff] [blame] | 516 | // from an extension app tab results in a new Browser with TYPE_APP_POPUP. |
| 517 | IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, |
| 518 | Disposition_NewPopupFromExtensionApp) { |
| 519 | // TODO(beng): TBD. |
| 520 | } |
| 521 | |
[email protected] | 7d32999 | 2011-04-15 18:20:02 | [diff] [blame] | 522 | // This test verifies that navigating with window_action = SHOW_WINDOW_INACTIVE |
| 523 | // does not focus a new new popup window. |
| 524 | IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_NewPopupUnfocused) { |
| 525 | browser::NavigateParams p(MakeNavigateParams()); |
| 526 | p.disposition = NEW_POPUP; |
[email protected] | 588300d | 2011-04-28 21:06:35 | [diff] [blame] | 527 | p.window_bounds = gfx::Rect(0, 0, 200, 200); |
[email protected] | 7d32999 | 2011-04-15 18:20:02 | [diff] [blame] | 528 | p.window_action = browser::NavigateParams::SHOW_WINDOW_INACTIVE; |
[email protected] | 7d32999 | 2011-04-15 18:20:02 | [diff] [blame] | 529 | // Wait for new popup to load (and gain focus if the test fails). |
[email protected] | ddddfda | 2011-07-14 23:19:39 | [diff] [blame] | 530 | ui_test_utils::NavigateToURL(&p); |
[email protected] | 7d32999 | 2011-04-15 18:20:02 | [diff] [blame] | 531 | |
| 532 | // Navigate() should have opened a new, unfocused, popup window. |
| 533 | EXPECT_NE(browser(), p.browser); |
| 534 | EXPECT_EQ(Browser::TYPE_POPUP, p.browser->type()); |
[email protected] | 9db263a | 2011-04-15 20:53:47 | [diff] [blame] | 535 | #if 0 |
| 536 | // TODO(stevenjb): Enable this test. See: crbug.com/79493 |
[email protected] | 7d32999 | 2011-04-15 18:20:02 | [diff] [blame] | 537 | EXPECT_FALSE(p.browser->window()->IsActive()); |
[email protected] | 7d32999 | 2011-04-15 18:20:02 | [diff] [blame] | 538 | #endif |
[email protected] | 9db263a | 2011-04-15 20:53:47 | [diff] [blame] | 539 | } |
[email protected] | 7d32999 | 2011-04-15 18:20:02 | [diff] [blame] | 540 | |
[email protected] | a1feae5 | 2010-10-11 22:14:45 | [diff] [blame] | 541 | // This test verifies that navigating with WindowOpenDisposition = NEW_WINDOW |
| 542 | // always opens a new window. |
| 543 | IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_NewWindow) { |
| 544 | browser::NavigateParams p(MakeNavigateParams()); |
| 545 | p.disposition = NEW_WINDOW; |
[email protected] | 19d9f3a | 2010-10-14 21:49:36 | [diff] [blame] | 546 | browser::Navigate(&p); |
[email protected] | a1feae5 | 2010-10-11 22:14:45 | [diff] [blame] | 547 | |
| 548 | // Navigate() should have opened a new toplevel window. |
| 549 | EXPECT_NE(browser(), p.browser); |
[email protected] | b35b26b3 | 2011-05-05 20:35:14 | [diff] [blame] | 550 | EXPECT_TRUE(p.browser->is_type_tabbed()); |
[email protected] | a1feae5 | 2010-10-11 22:14:45 | [diff] [blame] | 551 | |
| 552 | // We should now have two windows, the browser() provided by the framework and |
| 553 | // the new normal window. |
| 554 | EXPECT_EQ(2u, BrowserList::size()); |
| 555 | EXPECT_EQ(1, browser()->tab_count()); |
| 556 | EXPECT_EQ(1, p.browser->tab_count()); |
| 557 | } |
| 558 | |
| 559 | // This test verifies that navigating with WindowOpenDisposition = INCOGNITO |
| 560 | // opens a new incognito window if no existing incognito window is present. |
| 561 | IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_Incognito) { |
| 562 | browser::NavigateParams p(MakeNavigateParams()); |
| 563 | p.disposition = OFF_THE_RECORD; |
[email protected] | 19d9f3a | 2010-10-14 21:49:36 | [diff] [blame] | 564 | browser::Navigate(&p); |
[email protected] | a1feae5 | 2010-10-11 22:14:45 | [diff] [blame] | 565 | |
| 566 | // Navigate() should have opened a new toplevel incognito window. |
| 567 | EXPECT_NE(browser(), p.browser); |
| 568 | EXPECT_EQ(browser()->profile()->GetOffTheRecordProfile(), |
| 569 | p.browser->profile()); |
| 570 | |
[email protected] | d7ff359 | 2010-11-30 21:50:46 | [diff] [blame] | 571 | // |source_contents| should be set to NULL because the profile for the new |
| 572 | // page is different from the originating page. |
| 573 | EXPECT_EQ(NULL, p.source_contents); |
| 574 | |
[email protected] | a1feae5 | 2010-10-11 22:14:45 | [diff] [blame] | 575 | // We should now have two windows, the browser() provided by the framework and |
| 576 | // the new incognito window. |
| 577 | EXPECT_EQ(2u, BrowserList::size()); |
| 578 | EXPECT_EQ(1, browser()->tab_count()); |
| 579 | EXPECT_EQ(1, p.browser->tab_count()); |
| 580 | } |
| 581 | |
| 582 | // This test verifies that navigating with WindowOpenDisposition = INCOGNITO |
| 583 | // reuses an existing incognito window when possible. |
| 584 | IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_IncognitoRefocus) { |
| 585 | Browser* incognito_browser = |
[email protected] | b35b26b3 | 2011-05-05 20:35:14 | [diff] [blame] | 586 | CreateEmptyBrowserForType(Browser::TYPE_TABBED, |
[email protected] | a1feae5 | 2010-10-11 22:14:45 | [diff] [blame] | 587 | browser()->profile()->GetOffTheRecordProfile()); |
| 588 | browser::NavigateParams p(MakeNavigateParams()); |
| 589 | p.disposition = OFF_THE_RECORD; |
[email protected] | 19d9f3a | 2010-10-14 21:49:36 | [diff] [blame] | 590 | browser::Navigate(&p); |
[email protected] | a1feae5 | 2010-10-11 22:14:45 | [diff] [blame] | 591 | |
| 592 | // Navigate() should have opened a new tab in the existing incognito window. |
| 593 | EXPECT_NE(browser(), p.browser); |
| 594 | EXPECT_EQ(p.browser, incognito_browser); |
| 595 | |
| 596 | // We should now have two windows, the browser() provided by the framework and |
| 597 | // the incognito window we opened earlier. |
| 598 | EXPECT_EQ(2u, BrowserList::size()); |
| 599 | EXPECT_EQ(1, browser()->tab_count()); |
| 600 | EXPECT_EQ(2, incognito_browser->tab_count()); |
| 601 | } |
| 602 | |
| 603 | // This test verifies that no navigation action occurs when |
| 604 | // WindowOpenDisposition = SUPPRESS_OPEN. |
| 605 | IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_SuppressOpen) { |
| 606 | RunSuppressTest(SUPPRESS_OPEN); |
| 607 | } |
| 608 | |
| 609 | // This test verifies that no navigation action occurs when |
| 610 | // WindowOpenDisposition = SAVE_TO_DISK. |
| 611 | IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_SaveToDisk) { |
| 612 | RunSuppressTest(SAVE_TO_DISK); |
| 613 | } |
| 614 | |
| 615 | // This test verifies that no navigation action occurs when |
| 616 | // WindowOpenDisposition = IGNORE_ACTION. |
| 617 | IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_IgnoreAction) { |
| 618 | RunSuppressTest(IGNORE_ACTION); |
| 619 | } |
| 620 | |
| 621 | // This tests adding a foreground tab with a predefined TabContents. |
| 622 | IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, TargetContents_ForegroundTab) { |
| 623 | browser::NavigateParams p(MakeNavigateParams()); |
| 624 | p.disposition = NEW_FOREGROUND_TAB; |
| 625 | p.target_contents = CreateTabContents(); |
[email protected] | 19d9f3a | 2010-10-14 21:49:36 | [diff] [blame] | 626 | browser::Navigate(&p); |
[email protected] | a1feae5 | 2010-10-11 22:14:45 | [diff] [blame] | 627 | |
| 628 | // Navigate() should have opened the contents in a new foreground in the |
| 629 | // current Browser. |
| 630 | EXPECT_EQ(browser(), p.browser); |
[email protected] | 3c9e187 | 2010-11-18 16:17:49 | [diff] [blame] | 631 | EXPECT_EQ(browser()->GetSelectedTabContentsWrapper(), p.target_contents); |
[email protected] | a1feae5 | 2010-10-11 22:14:45 | [diff] [blame] | 632 | |
| 633 | // We should have one window, with two tabs. |
| 634 | EXPECT_EQ(1u, BrowserList::size()); |
| 635 | EXPECT_EQ(2, browser()->tab_count()); |
| 636 | } |
| 637 | |
| 638 | #if defined(OS_WIN) |
| 639 | // This tests adding a popup with a predefined TabContents. |
[email protected] | 76edb67 | 2011-03-04 21:48:39 | [diff] [blame] | 640 | IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, DISABLED_TargetContents_Popup) { |
[email protected] | a1feae5 | 2010-10-11 22:14:45 | [diff] [blame] | 641 | browser::NavigateParams p(MakeNavigateParams()); |
| 642 | p.disposition = NEW_POPUP; |
| 643 | p.target_contents = CreateTabContents(); |
| 644 | p.window_bounds = gfx::Rect(10, 10, 500, 500); |
[email protected] | 19d9f3a | 2010-10-14 21:49:36 | [diff] [blame] | 645 | browser::Navigate(&p); |
[email protected] | a1feae5 | 2010-10-11 22:14:45 | [diff] [blame] | 646 | |
| 647 | // Navigate() should have opened a new popup window. |
| 648 | EXPECT_NE(browser(), p.browser); |
[email protected] | b35b26b3 | 2011-05-05 20:35:14 | [diff] [blame] | 649 | EXPECT_TRUE(p.browser->is_type_popup()); |
| 650 | EXPECT_FALSE(p.browser->is_app()); |
[email protected] | a1feae5 | 2010-10-11 22:14:45 | [diff] [blame] | 651 | |
| 652 | // The web platform is weird. The window bounds specified in |
| 653 | // |p.window_bounds| are used as follows: |
| 654 | // - the origin is used to position the window |
| 655 | // - the size is used to size the TabContents of the window. |
| 656 | // As such the position of the resulting window will always match |
| 657 | // p.window_bounds.origin(), but its size will not. We need to match |
| 658 | // the size against the selected tab's view's container size. |
| 659 | // Only Windows positions the window according to |p.window_bounds.origin()| - |
| 660 | // on Mac the window is offset from the opener and on Linux it always opens |
| 661 | // at 0,0. |
| 662 | EXPECT_EQ(p.window_bounds.origin(), |
| 663 | p.browser->window()->GetRestoredBounds().origin()); |
| 664 | // All platforms should respect size however provided width > 400 (Mac has a |
| 665 | // minimum window width of 400). |
| 666 | EXPECT_EQ(p.window_bounds.size(), |
[email protected] | 83ff91c | 2012-01-05 20:54:13 | [diff] [blame] | 667 | p.target_contents->web_contents()->GetView()->GetContainerSize()); |
[email protected] | a1feae5 | 2010-10-11 22:14:45 | [diff] [blame] | 668 | |
| 669 | // We should have two windows, the new popup and the browser() provided by the |
| 670 | // framework. |
| 671 | EXPECT_EQ(2u, BrowserList::size()); |
| 672 | EXPECT_EQ(1, browser()->tab_count()); |
| 673 | EXPECT_EQ(1, p.browser->tab_count()); |
| 674 | } |
| 675 | #endif |
| 676 | |
| 677 | // This tests adding a tab at a specific index. |
| 678 | IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Tabstrip_InsertAtIndex) { |
| 679 | // This is not meant to be a comprehensive test of whether or not the tab |
| 680 | // implementation of the browser observes the insertion index. That is |
| 681 | // covered by the unit tests for TabStripModel. This merely verifies that |
| 682 | // insertion index preference is reflected in common cases. |
| 683 | browser::NavigateParams p(MakeNavigateParams()); |
| 684 | p.disposition = NEW_FOREGROUND_TAB; |
| 685 | p.tabstrip_index = 0; |
| 686 | p.tabstrip_add_types = TabStripModel::ADD_FORCE_INDEX; |
[email protected] | 19d9f3a | 2010-10-14 21:49:36 | [diff] [blame] | 687 | browser::Navigate(&p); |
[email protected] | a1feae5 | 2010-10-11 22:14:45 | [diff] [blame] | 688 | |
| 689 | // Navigate() should have inserted a new tab at slot 0 in the tabstrip. |
| 690 | EXPECT_EQ(browser(), p.browser); |
| 691 | EXPECT_EQ(0, browser()->tabstrip_model()->GetIndexOfTabContents( |
[email protected] | 3c9e187 | 2010-11-18 16:17:49 | [diff] [blame] | 692 | static_cast<const TabContentsWrapper*>(p.target_contents))); |
[email protected] | a1feae5 | 2010-10-11 22:14:45 | [diff] [blame] | 693 | |
| 694 | // We should have one window - the browser() provided by the framework. |
| 695 | EXPECT_EQ(1u, BrowserList::size()); |
| 696 | EXPECT_EQ(2, browser()->tab_count()); |
| 697 | } |
| 698 | |
[email protected] | 2dd8548 | 2010-11-06 01:56:47 | [diff] [blame] | 699 | // This test verifies that constructing params with a NULL browser has |
| 700 | // the same result as navigating to a new foreground tab in the (only) |
| 701 | // active browser. Tests are the same as for Disposition_NewForegroundTab. |
| 702 | IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, NullBrowser_NewForegroundTab) { |
[email protected] | 4ca1530 | 2012-01-03 05:53:20 | [diff] [blame] | 703 | WebContents* old_contents = browser()->GetSelectedWebContents(); |
[email protected] | 2dd8548 | 2010-11-06 01:56:47 | [diff] [blame] | 704 | // Navigate with a NULL browser. |
| 705 | browser::NavigateParams p(MakeNavigateParams(NULL)); |
| 706 | p.disposition = NEW_FOREGROUND_TAB; |
| 707 | p.profile = browser()->profile(); |
| 708 | browser::Navigate(&p); |
| 709 | |
| 710 | // Navigate() should have found browser() and create a new tab. |
| 711 | EXPECT_EQ(browser(), p.browser); |
[email protected] | 4ca1530 | 2012-01-03 05:53:20 | [diff] [blame] | 712 | EXPECT_NE(old_contents, browser()->GetSelectedWebContents()); |
[email protected] | 3c9e187 | 2010-11-18 16:17:49 | [diff] [blame] | 713 | EXPECT_EQ(browser()->GetSelectedTabContentsWrapper(), p.target_contents); |
[email protected] | 2dd8548 | 2010-11-06 01:56:47 | [diff] [blame] | 714 | EXPECT_EQ(2, browser()->tab_count()); |
| 715 | } |
| 716 | |
| 717 | // This test verifies that constructing params with a NULL browser and |
| 718 | // a specific profile matches the specified profile. |
[email protected] | c8a31a7 | 2011-09-30 01:53:32 | [diff] [blame] | 719 | IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, NullBrowser_MatchProfile) { |
[email protected] | 2dd8548 | 2010-11-06 01:56:47 | [diff] [blame] | 720 | // Create a new browser with using the incognito profile. |
| 721 | Browser* incognito = |
| 722 | Browser::Create(browser()->profile()->GetOffTheRecordProfile()); |
| 723 | |
| 724 | // Navigate with a NULL browser and the incognito profile. |
| 725 | browser::NavigateParams p(MakeNavigateParams(NULL)); |
| 726 | p.disposition = NEW_FOREGROUND_TAB; |
| 727 | p.profile = incognito->profile(); |
| 728 | browser::Navigate(&p); |
| 729 | |
| 730 | // Navigate() should have found incognito, not browser(). |
| 731 | EXPECT_EQ(incognito, p.browser); |
[email protected] | 3c9e187 | 2010-11-18 16:17:49 | [diff] [blame] | 732 | EXPECT_EQ(incognito->GetSelectedTabContentsWrapper(), p.target_contents); |
[email protected] | 2dd8548 | 2010-11-06 01:56:47 | [diff] [blame] | 733 | EXPECT_EQ(1, incognito->tab_count()); |
| 734 | } |
| 735 | |
| 736 | // This test verifies that constructing params with a NULL browser and |
| 737 | // disposition = NEW_WINDOW always opens exactly one new window. |
| 738 | IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, NullBrowser_NewWindow) { |
| 739 | browser::NavigateParams p(MakeNavigateParams(NULL)); |
| 740 | p.disposition = NEW_WINDOW; |
| 741 | p.profile = browser()->profile(); |
| 742 | browser::Navigate(&p); |
| 743 | |
| 744 | // Navigate() should have created a new browser. |
| 745 | EXPECT_NE(browser(), p.browser); |
[email protected] | b35b26b3 | 2011-05-05 20:35:14 | [diff] [blame] | 746 | EXPECT_TRUE( p.browser->is_type_tabbed()); |
[email protected] | 2dd8548 | 2010-11-06 01:56:47 | [diff] [blame] | 747 | |
| 748 | // We should now have two windows, the browser() provided by the framework and |
| 749 | // the new normal window. |
| 750 | EXPECT_EQ(2u, BrowserList::size()); |
| 751 | EXPECT_EQ(1, browser()->tab_count()); |
| 752 | EXPECT_EQ(1, p.browser->tab_count()); |
| 753 | } |
| 754 | |
[email protected] | bb89e748 | 2010-11-17 18:27:04 | [diff] [blame] | 755 | // This test verifies that constructing params with disposition = SINGLETON_TAB |
[email protected] | fee32054 | 2011-03-02 01:30:49 | [diff] [blame] | 756 | // 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] | 757 | // no previous tab with that URL (minus the path) exists. |
[email protected] | bb89e748 | 2010-11-17 18:27:04 | [diff] [blame] | 758 | IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, |
| 759 | Disposition_SingletonTabNew_IgnorePath) { |
[email protected] | 2905f74 | 2011-10-13 03:51:58 | [diff] [blame] | 760 | browser()->AddSelectedTabWithURL( |
| 761 | GetGoogleURL(), content::PAGE_TRANSITION_LINK); |
[email protected] | bb89e748 | 2010-11-17 18:27:04 | [diff] [blame] | 762 | |
| 763 | // We should have one browser with 2 tabs, the 2nd selected. |
| 764 | EXPECT_EQ(1u, BrowserList::size()); |
| 765 | EXPECT_EQ(2, browser()->tab_count()); |
[email protected] | 1ea49d5 | 2011-04-12 17:44:44 | [diff] [blame] | 766 | EXPECT_EQ(1, browser()->active_index()); |
[email protected] | bb89e748 | 2010-11-17 18:27:04 | [diff] [blame] | 767 | |
| 768 | // Navigate to a new singleton tab with a sub-page. |
| 769 | browser::NavigateParams p(MakeNavigateParams()); |
| 770 | p.disposition = SINGLETON_TAB; |
[email protected] | ddddfda | 2011-07-14 23:19:39 | [diff] [blame] | 771 | p.url = GetSettingsAdvancedURL(); |
[email protected] | 7d32999 | 2011-04-15 18:20:02 | [diff] [blame] | 772 | p.window_action = browser::NavigateParams::SHOW_WINDOW; |
[email protected] | fee32054 | 2011-03-02 01:30:49 | [diff] [blame] | 773 | p.path_behavior = browser::NavigateParams::IGNORE_AND_NAVIGATE; |
[email protected] | bb89e748 | 2010-11-17 18:27:04 | [diff] [blame] | 774 | browser::Navigate(&p); |
| 775 | |
| 776 | // The last tab should now be selected and navigated to the sub-page of the |
| 777 | // URL. |
| 778 | EXPECT_EQ(browser(), p.browser); |
| 779 | EXPECT_EQ(3, browser()->tab_count()); |
[email protected] | 1ea49d5 | 2011-04-12 17:44:44 | [diff] [blame] | 780 | EXPECT_EQ(2, browser()->active_index()); |
[email protected] | ddddfda | 2011-07-14 23:19:39 | [diff] [blame] | 781 | EXPECT_EQ(GetSettingsAdvancedURL(), |
[email protected] | 4ca1530 | 2012-01-03 05:53:20 | [diff] [blame] | 782 | browser()->GetSelectedWebContents()->GetURL()); |
[email protected] | bb89e748 | 2010-11-17 18:27:04 | [diff] [blame] | 783 | } |
| 784 | |
| 785 | // This test verifies that constructing params with disposition = SINGLETON_TAB |
[email protected] | fee32054 | 2011-03-02 01:30:49 | [diff] [blame] | 786 | // and IGNORE_AND_NAVIGATE opens an existing tab with the matching URL (minus |
[email protected] | bb89e748 | 2010-11-17 18:27:04 | [diff] [blame] | 787 | // the path) which is navigated to the specified URL. |
| 788 | IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, |
| 789 | Disposition_SingletonTabExisting_IgnorePath) { |
[email protected] | ddddfda | 2011-07-14 23:19:39 | [diff] [blame] | 790 | GURL singleton_url1(GetSettingsURL()); |
[email protected] | 2905f74 | 2011-10-13 03:51:58 | [diff] [blame] | 791 | browser()->AddSelectedTabWithURL( |
| 792 | singleton_url1, content::PAGE_TRANSITION_LINK); |
| 793 | browser()->AddSelectedTabWithURL( |
| 794 | GetGoogleURL(), content::PAGE_TRANSITION_LINK); |
[email protected] | bb89e748 | 2010-11-17 18:27:04 | [diff] [blame] | 795 | |
| 796 | // We should have one browser with 3 tabs, the 3rd selected. |
| 797 | EXPECT_EQ(1u, BrowserList::size()); |
| 798 | EXPECT_EQ(3, browser()->tab_count()); |
[email protected] | 1ea49d5 | 2011-04-12 17:44:44 | [diff] [blame] | 799 | EXPECT_EQ(2, browser()->active_index()); |
[email protected] | bb89e748 | 2010-11-17 18:27:04 | [diff] [blame] | 800 | |
| 801 | // Navigate to singleton_url1. |
| 802 | browser::NavigateParams p(MakeNavigateParams()); |
| 803 | p.disposition = SINGLETON_TAB; |
[email protected] | ddddfda | 2011-07-14 23:19:39 | [diff] [blame] | 804 | p.url = GetSettingsAdvancedURL(); |
[email protected] | 7d32999 | 2011-04-15 18:20:02 | [diff] [blame] | 805 | p.window_action = browser::NavigateParams::SHOW_WINDOW; |
[email protected] | fee32054 | 2011-03-02 01:30:49 | [diff] [blame] | 806 | p.path_behavior = browser::NavigateParams::IGNORE_AND_NAVIGATE; |
[email protected] | bb89e748 | 2010-11-17 18:27:04 | [diff] [blame] | 807 | browser::Navigate(&p); |
| 808 | |
| 809 | // The middle tab should now be selected and navigated to the sub-page of the |
| 810 | // URL. |
| 811 | EXPECT_EQ(browser(), p.browser); |
| 812 | EXPECT_EQ(3, browser()->tab_count()); |
[email protected] | 1ea49d5 | 2011-04-12 17:44:44 | [diff] [blame] | 813 | EXPECT_EQ(1, browser()->active_index()); |
[email protected] | ddddfda | 2011-07-14 23:19:39 | [diff] [blame] | 814 | EXPECT_EQ(GetSettingsAdvancedURL(), |
[email protected] | 4ca1530 | 2012-01-03 05:53:20 | [diff] [blame] | 815 | browser()->GetSelectedWebContents()->GetURL()); |
[email protected] | bb89e748 | 2010-11-17 18:27:04 | [diff] [blame] | 816 | } |
| 817 | |
| 818 | // This test verifies that constructing params with disposition = SINGLETON_TAB |
[email protected] | fee32054 | 2011-03-02 01:30:49 | [diff] [blame] | 819 | // and IGNORE_AND_NAVIGATE opens an existing tab with the matching URL (minus |
[email protected] | bb89e748 | 2010-11-17 18:27:04 | [diff] [blame] | 820 | // the path) which is navigated to the specified URL. |
| 821 | IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, |
| 822 | Disposition_SingletonTabExistingSubPath_IgnorePath) { |
[email protected] | ddddfda | 2011-07-14 23:19:39 | [diff] [blame] | 823 | GURL singleton_url1(GetSettingsAdvancedURL()); |
[email protected] | 2905f74 | 2011-10-13 03:51:58 | [diff] [blame] | 824 | browser()->AddSelectedTabWithURL( |
| 825 | singleton_url1, content::PAGE_TRANSITION_LINK); |
| 826 | browser()->AddSelectedTabWithURL( |
| 827 | GetGoogleURL(), content::PAGE_TRANSITION_LINK); |
[email protected] | bb89e748 | 2010-11-17 18:27:04 | [diff] [blame] | 828 | |
| 829 | // We should have one browser with 3 tabs, the 3rd selected. |
| 830 | EXPECT_EQ(1u, BrowserList::size()); |
| 831 | EXPECT_EQ(3, browser()->tab_count()); |
[email protected] | 1ea49d5 | 2011-04-12 17:44:44 | [diff] [blame] | 832 | EXPECT_EQ(2, browser()->active_index()); |
[email protected] | bb89e748 | 2010-11-17 18:27:04 | [diff] [blame] | 833 | |
| 834 | // Navigate to singleton_url1. |
| 835 | browser::NavigateParams p(MakeNavigateParams()); |
| 836 | p.disposition = SINGLETON_TAB; |
[email protected] | ddddfda | 2011-07-14 23:19:39 | [diff] [blame] | 837 | p.url = GetSettingsPersonalURL(); |
[email protected] | 7d32999 | 2011-04-15 18:20:02 | [diff] [blame] | 838 | p.window_action = browser::NavigateParams::SHOW_WINDOW; |
[email protected] | fee32054 | 2011-03-02 01:30:49 | [diff] [blame] | 839 | p.path_behavior = browser::NavigateParams::IGNORE_AND_NAVIGATE; |
[email protected] | bb89e748 | 2010-11-17 18:27:04 | [diff] [blame] | 840 | browser::Navigate(&p); |
| 841 | |
| 842 | // The middle tab should now be selected and navigated to the sub-page of the |
| 843 | // URL. |
| 844 | EXPECT_EQ(browser(), p.browser); |
| 845 | EXPECT_EQ(3, browser()->tab_count()); |
[email protected] | 1ea49d5 | 2011-04-12 17:44:44 | [diff] [blame] | 846 | EXPECT_EQ(1, browser()->active_index()); |
[email protected] | ddddfda | 2011-07-14 23:19:39 | [diff] [blame] | 847 | EXPECT_EQ(GetSettingsPersonalURL(), |
[email protected] | 4ca1530 | 2012-01-03 05:53:20 | [diff] [blame] | 848 | browser()->GetSelectedWebContents()->GetURL()); |
[email protected] | bb89e748 | 2010-11-17 18:27:04 | [diff] [blame] | 849 | } |
[email protected] | 2dd8548 | 2010-11-06 01:56:47 | [diff] [blame] | 850 | |
[email protected] | 637b344 | 2011-01-10 23:31:48 | [diff] [blame] | 851 | // This test verifies that constructing params with disposition = SINGLETON_TAB |
[email protected] | fee32054 | 2011-03-02 01:30:49 | [diff] [blame] | 852 | // and IGNORE_AND_STAY_PUT opens an existing tab with the matching URL (minus |
| 853 | // the path). |
| 854 | IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, |
| 855 | Disposition_SingletonTabExistingSubPath_IgnorePath2) { |
[email protected] | ddddfda | 2011-07-14 23:19:39 | [diff] [blame] | 856 | GURL singleton_url1(GetSettingsAdvancedURL()); |
[email protected] | 2905f74 | 2011-10-13 03:51:58 | [diff] [blame] | 857 | browser()->AddSelectedTabWithURL( |
| 858 | singleton_url1, content::PAGE_TRANSITION_LINK); |
| 859 | browser()->AddSelectedTabWithURL( |
| 860 | GetGoogleURL(), content::PAGE_TRANSITION_LINK); |
[email protected] | fee32054 | 2011-03-02 01:30:49 | [diff] [blame] | 861 | |
| 862 | // We should have one browser with 3 tabs, the 3rd selected. |
| 863 | EXPECT_EQ(1u, BrowserList::size()); |
| 864 | EXPECT_EQ(3, browser()->tab_count()); |
[email protected] | 1ea49d5 | 2011-04-12 17:44:44 | [diff] [blame] | 865 | EXPECT_EQ(2, browser()->active_index()); |
[email protected] | fee32054 | 2011-03-02 01:30:49 | [diff] [blame] | 866 | |
| 867 | // Navigate to singleton_url1. |
| 868 | browser::NavigateParams p(MakeNavigateParams()); |
| 869 | p.disposition = SINGLETON_TAB; |
[email protected] | ddddfda | 2011-07-14 23:19:39 | [diff] [blame] | 870 | p.url = GetSettingsPersonalURL(); |
[email protected] | 7d32999 | 2011-04-15 18:20:02 | [diff] [blame] | 871 | p.window_action = browser::NavigateParams::SHOW_WINDOW; |
[email protected] | fee32054 | 2011-03-02 01:30:49 | [diff] [blame] | 872 | p.path_behavior = browser::NavigateParams::IGNORE_AND_STAY_PUT; |
| 873 | browser::Navigate(&p); |
| 874 | |
| 875 | // The middle tab should now be selected. |
| 876 | EXPECT_EQ(browser(), p.browser); |
| 877 | EXPECT_EQ(3, browser()->tab_count()); |
[email protected] | 1ea49d5 | 2011-04-12 17:44:44 | [diff] [blame] | 878 | EXPECT_EQ(1, browser()->active_index()); |
[email protected] | fee32054 | 2011-03-02 01:30:49 | [diff] [blame] | 879 | EXPECT_EQ(singleton_url1, |
[email protected] | 4ca1530 | 2012-01-03 05:53:20 | [diff] [blame] | 880 | browser()->GetSelectedWebContents()->GetURL()); |
[email protected] | fee32054 | 2011-03-02 01:30:49 | [diff] [blame] | 881 | } |
| 882 | |
| 883 | // This test verifies that constructing params with disposition = SINGLETON_TAB |
| 884 | // 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] | 885 | // selected tab is a match but has a different path. |
| 886 | IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, |
| 887 | Disposition_SingletonTabFocused_IgnorePath) { |
[email protected] | ddddfda | 2011-07-14 23:19:39 | [diff] [blame] | 888 | GURL singleton_url_current(GetSettingsAdvancedURL()); |
[email protected] | 2905f74 | 2011-10-13 03:51:58 | [diff] [blame] | 889 | browser()->AddSelectedTabWithURL( |
| 890 | singleton_url_current, content::PAGE_TRANSITION_LINK); |
[email protected] | 637b344 | 2011-01-10 23:31:48 | [diff] [blame] | 891 | |
| 892 | // We should have one browser with 2 tabs, the 2nd selected. |
| 893 | EXPECT_EQ(1u, BrowserList::size()); |
| 894 | EXPECT_EQ(2, browser()->tab_count()); |
[email protected] | 1ea49d5 | 2011-04-12 17:44:44 | [diff] [blame] | 895 | EXPECT_EQ(1, browser()->active_index()); |
[email protected] | 637b344 | 2011-01-10 23:31:48 | [diff] [blame] | 896 | |
| 897 | // Navigate to a different settings path. |
[email protected] | ddddfda | 2011-07-14 23:19:39 | [diff] [blame] | 898 | GURL singleton_url_target(GetSettingsPersonalURL()); |
[email protected] | 637b344 | 2011-01-10 23:31:48 | [diff] [blame] | 899 | browser::NavigateParams p(MakeNavigateParams()); |
| 900 | p.disposition = SINGLETON_TAB; |
| 901 | p.url = singleton_url_target; |
[email protected] | 7d32999 | 2011-04-15 18:20:02 | [diff] [blame] | 902 | p.window_action = browser::NavigateParams::SHOW_WINDOW; |
[email protected] | fee32054 | 2011-03-02 01:30:49 | [diff] [blame] | 903 | p.path_behavior = browser::NavigateParams::IGNORE_AND_NAVIGATE; |
[email protected] | 637b344 | 2011-01-10 23:31:48 | [diff] [blame] | 904 | browser::Navigate(&p); |
| 905 | |
| 906 | // The second tab should still be selected, but navigated to the new path. |
| 907 | EXPECT_EQ(browser(), p.browser); |
| 908 | EXPECT_EQ(2, browser()->tab_count()); |
[email protected] | 1ea49d5 | 2011-04-12 17:44:44 | [diff] [blame] | 909 | EXPECT_EQ(1, browser()->active_index()); |
[email protected] | 637b344 | 2011-01-10 23:31:48 | [diff] [blame] | 910 | EXPECT_EQ(singleton_url_target, |
[email protected] | 4ca1530 | 2012-01-03 05:53:20 | [diff] [blame] | 911 | browser()->GetSelectedWebContents()->GetURL()); |
[email protected] | 637b344 | 2011-01-10 23:31:48 | [diff] [blame] | 912 | } |
| 913 | |
[email protected] | 07afd7c | 2011-02-17 10:07:11 | [diff] [blame] | 914 | // This test verifies that constructing params with disposition = SINGLETON_TAB |
[email protected] | fee32054 | 2011-03-02 01:30:49 | [diff] [blame] | 915 | // and IGNORE_AND_NAVIGATE will open an existing matching tab with a different |
| 916 | // query. |
[email protected] | 07afd7c | 2011-02-17 10:07:11 | [diff] [blame] | 917 | IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, |
| 918 | Disposition_SingletonTabExisting_IgnoreQuery) { |
| 919 | int initial_tab_count = browser()->tab_count(); |
| 920 | GURL singleton_url_current("chrome://settings/internet"); |
[email protected] | 2905f74 | 2011-10-13 03:51:58 | [diff] [blame] | 921 | browser()->AddSelectedTabWithURL( |
| 922 | singleton_url_current, content::PAGE_TRANSITION_LINK); |
[email protected] | 07afd7c | 2011-02-17 10:07:11 | [diff] [blame] | 923 | |
| 924 | EXPECT_EQ(initial_tab_count + 1, browser()->tab_count()); |
[email protected] | 1ea49d5 | 2011-04-12 17:44:44 | [diff] [blame] | 925 | EXPECT_EQ(initial_tab_count, browser()->active_index()); |
[email protected] | 07afd7c | 2011-02-17 10:07:11 | [diff] [blame] | 926 | |
| 927 | // Navigate to a different settings path. |
| 928 | GURL singleton_url_target( |
| 929 | "chrome://settings/internet?" |
| 930 | "servicePath=/profile/ethernet_00aa00aa00aa&networkType=1"); |
| 931 | browser::NavigateParams p(MakeNavigateParams()); |
| 932 | p.disposition = SINGLETON_TAB; |
| 933 | p.url = singleton_url_target; |
[email protected] | 7d32999 | 2011-04-15 18:20:02 | [diff] [blame] | 934 | p.window_action = browser::NavigateParams::SHOW_WINDOW; |
[email protected] | fee32054 | 2011-03-02 01:30:49 | [diff] [blame] | 935 | p.path_behavior = browser::NavigateParams::IGNORE_AND_NAVIGATE; |
[email protected] | 07afd7c | 2011-02-17 10:07:11 | [diff] [blame] | 936 | browser::Navigate(&p); |
| 937 | |
| 938 | // Last tab should still be selected. |
| 939 | EXPECT_EQ(browser(), p.browser); |
| 940 | EXPECT_EQ(initial_tab_count + 1, browser()->tab_count()); |
[email protected] | 1ea49d5 | 2011-04-12 17:44:44 | [diff] [blame] | 941 | EXPECT_EQ(initial_tab_count, browser()->active_index()); |
[email protected] | 07afd7c | 2011-02-17 10:07:11 | [diff] [blame] | 942 | } |
| 943 | |
[email protected] | bd817c2 | 2011-02-09 08:16:46 | [diff] [blame] | 944 | // This test verifies that the settings page isn't opened in the incognito |
| 945 | // window. |
| 946 | IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, |
| 947 | Disposition_Settings_UseNonIncognitoWindow) { |
[email protected] | fc0ed30 | 2011-11-29 23:17:19 | [diff] [blame] | 948 | RunUseNonIncognitoWindowTest(GetSettingsURL()); |
[email protected] | bd817c2 | 2011-02-09 08:16:46 | [diff] [blame] | 949 | } |
| 950 | |
[email protected] | 82404cd | 2011-07-12 19:55:14 | [diff] [blame] | 951 | // This test verifies that the settings page isn't opened in the incognito |
| 952 | // window from a non-incognito window (bookmark open-in-incognito trigger). |
| 953 | IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, |
| 954 | Disposition_Settings_UseNonIncognitoWindowForBookmark) { |
| 955 | browser::NavigateParams params(browser(), GURL("chrome://settings"), |
[email protected] | 2905f74 | 2011-10-13 03:51:58 | [diff] [blame] | 956 | content::PAGE_TRANSITION_AUTO_BOOKMARK); |
[email protected] | 82404cd | 2011-07-12 19:55:14 | [diff] [blame] | 957 | params.disposition = OFF_THE_RECORD; |
| 958 | { |
| 959 | ui_test_utils::WindowedNotificationObserver observer( |
[email protected] | ad50def5 | 2011-10-19 23:17:07 | [diff] [blame] | 960 | content::NOTIFICATION_LOAD_STOP, |
| 961 | content::NotificationService::AllSources()); |
[email protected] | 82404cd | 2011-07-12 19:55:14 | [diff] [blame] | 962 | browser::Navigate(¶ms); |
| 963 | observer.Wait(); |
| 964 | } |
| 965 | |
| 966 | EXPECT_EQ(1u, BrowserList::size()); |
| 967 | EXPECT_EQ(GURL("chrome://settings"), |
[email protected] | 4ca1530 | 2012-01-03 05:53:20 | [diff] [blame] | 968 | browser()->GetSelectedWebContents()->GetURL().GetOrigin()); |
[email protected] | 82404cd | 2011-07-12 19:55:14 | [diff] [blame] | 969 | } |
| 970 | |
[email protected] | 93ad8e1c | 2011-11-08 21:34:05 | [diff] [blame] | 971 | // Settings page is expected to always open in normal mode regardless |
| 972 | // of whether the user is trying to open it in incognito mode or not. |
| 973 | // This test verifies that if incognito mode is forced (by policy), settings |
| 974 | // page doesn't open at all. |
| 975 | IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, |
| 976 | Disposition_Settings_DoNothingIfIncognitoIsForced) { |
[email protected] | fc0ed30 | 2011-11-29 23:17:19 | [diff] [blame] | 977 | RunDoNothingIfIncognitoIsForcedTest(GetSettingsURL()); |
[email protected] | 93ad8e1c | 2011-11-08 21:34:05 | [diff] [blame] | 978 | } |
| 979 | |
[email protected] | bd817c2 | 2011-02-09 08:16:46 | [diff] [blame] | 980 | // This test verifies that the bookmarks page isn't opened in the incognito |
| 981 | // window. |
| 982 | IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, |
| 983 | Disposition_Bookmarks_UseNonIncognitoWindow) { |
[email protected] | fc0ed30 | 2011-11-29 23:17:19 | [diff] [blame] | 984 | RunUseNonIncognitoWindowTest(GURL(chrome::kChromeUIBookmarksURL)); |
[email protected] | bd817c2 | 2011-02-09 08:16:46 | [diff] [blame] | 985 | } |
| 986 | |
[email protected] | 93ad8e1c | 2011-11-08 21:34:05 | [diff] [blame] | 987 | // Bookmark manager is expected to always open in normal mode regardless |
| 988 | // of whether the user is trying to open it in incognito mode or not. |
| 989 | // This test verifies that if incognito mode is forced (by policy), bookmark |
| 990 | // manager doesn't open at all. |
| 991 | IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, |
| 992 | Disposition_Bookmarks_DoNothingIfIncognitoIsForced) { |
[email protected] | fc0ed30 | 2011-11-29 23:17:19 | [diff] [blame] | 993 | RunDoNothingIfIncognitoIsForcedTest(GURL(chrome::kChromeUIBookmarksURL)); |
| 994 | } |
[email protected] | 93ad8e1c | 2011-11-08 21:34:05 | [diff] [blame] | 995 | |
[email protected] | fc0ed30 | 2011-11-29 23:17:19 | [diff] [blame] | 996 | // This test verifies that the sync promo page isn't opened in the incognito |
| 997 | // window. |
| 998 | IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, |
| 999 | Disposition_SyncPromo_UseNonIncognitoWindow) { |
| 1000 | RunUseNonIncognitoWindowTest(GURL(chrome::kChromeUISyncPromoURL)); |
| 1001 | } |
[email protected] | 93ad8e1c | 2011-11-08 21:34:05 | [diff] [blame] | 1002 | |
[email protected] | fc0ed30 | 2011-11-29 23:17:19 | [diff] [blame] | 1003 | // The Sync promo page is expected to always open in normal mode regardless of |
| 1004 | // whether the user is trying to open it in incognito mode or not. This test |
| 1005 | // verifies that if incognito mode is forced (by policy), the sync promo page |
| 1006 | // doesn't open at all. |
| 1007 | IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, |
| 1008 | Disposition_SyncPromo_DoNothingIfIncognitoIsForced) { |
| 1009 | RunDoNothingIfIncognitoIsForcedTest(GURL(chrome::kChromeUISyncPromoURL)); |
[email protected] | 93ad8e1c | 2011-11-08 21:34:05 | [diff] [blame] | 1010 | } |
| 1011 | |
[email protected] | 7de53c6 | 2011-05-13 06:44:16 | [diff] [blame] | 1012 | // This test makes sure a crashed singleton tab reloads from a new navigation. |
| 1013 | IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, |
| 1014 | NavigateToCrashedSingletonTab) { |
[email protected] | ddddfda | 2011-07-14 23:19:39 | [diff] [blame] | 1015 | GURL singleton_url(GetSettingsAdvancedURL()); |
[email protected] | 2905f74 | 2011-10-13 03:51:58 | [diff] [blame] | 1016 | TabContentsWrapper* wrapper = browser()->AddSelectedTabWithURL( |
| 1017 | singleton_url, content::PAGE_TRANSITION_LINK); |
[email protected] | 83ff91c | 2012-01-05 20:54:13 | [diff] [blame] | 1018 | WebContents* web_contents = wrapper->web_contents(); |
[email protected] | 7de53c6 | 2011-05-13 06:44:16 | [diff] [blame] | 1019 | |
| 1020 | // We should have one browser with 2 tabs, the 2nd selected. |
| 1021 | EXPECT_EQ(1u, BrowserList::size()); |
| 1022 | EXPECT_EQ(2, browser()->tab_count()); |
| 1023 | EXPECT_EQ(1, browser()->active_index()); |
| 1024 | |
| 1025 | // Kill the singleton tab. |
[email protected] | 83ff91c | 2012-01-05 20:54:13 | [diff] [blame] | 1026 | web_contents->SetIsCrashed(base::TERMINATION_STATUS_PROCESS_CRASHED, -1); |
| 1027 | EXPECT_TRUE(web_contents->IsCrashed()); |
[email protected] | 7de53c6 | 2011-05-13 06:44:16 | [diff] [blame] | 1028 | |
| 1029 | browser::NavigateParams p(MakeNavigateParams()); |
| 1030 | p.disposition = SINGLETON_TAB; |
| 1031 | p.url = singleton_url; |
| 1032 | p.window_action = browser::NavigateParams::SHOW_WINDOW; |
| 1033 | p.path_behavior = browser::NavigateParams::IGNORE_AND_NAVIGATE; |
[email protected] | ddddfda | 2011-07-14 23:19:39 | [diff] [blame] | 1034 | ui_test_utils::NavigateToURL(&p); |
[email protected] | 7de53c6 | 2011-05-13 06:44:16 | [diff] [blame] | 1035 | |
| 1036 | // The tab should not be sad anymore. |
[email protected] | 83ff91c | 2012-01-05 20:54:13 | [diff] [blame] | 1037 | EXPECT_FALSE(web_contents->IsCrashed()); |
[email protected] | 7de53c6 | 2011-05-13 06:44:16 | [diff] [blame] | 1038 | } |
| 1039 | |
[email protected] | fcca741b | 2011-06-17 22:46:37 | [diff] [blame] | 1040 | IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, |
| 1041 | NavigateFromDefaultToOptionsInSameTab) { |
[email protected] | ddddfda | 2011-07-14 23:19:39 | [diff] [blame] | 1042 | { |
| 1043 | ui_test_utils::WindowedNotificationObserver observer( |
[email protected] | ad50def5 | 2011-10-19 23:17:07 | [diff] [blame] | 1044 | content::NOTIFICATION_LOAD_STOP, |
| 1045 | content::NotificationService::AllSources()); |
[email protected] | ddddfda | 2011-07-14 23:19:39 | [diff] [blame] | 1046 | browser()->OpenOptionsDialog(); |
| 1047 | observer.Wait(); |
| 1048 | } |
[email protected] | fcca741b | 2011-06-17 22:46:37 | [diff] [blame] | 1049 | EXPECT_EQ(1, browser()->tab_count()); |
[email protected] | ddddfda | 2011-07-14 23:19:39 | [diff] [blame] | 1050 | EXPECT_EQ(GetSettingsURL(), |
[email protected] | 4ca1530 | 2012-01-03 05:53:20 | [diff] [blame] | 1051 | browser()->GetSelectedWebContents()->GetURL().GetOrigin()); |
[email protected] | fcca741b | 2011-06-17 22:46:37 | [diff] [blame] | 1052 | } |
| 1053 | |
| 1054 | IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, |
| 1055 | NavigateFromBlankToOptionsInSameTab) { |
| 1056 | browser::NavigateParams p(MakeNavigateParams()); |
[email protected] | ddddfda | 2011-07-14 23:19:39 | [diff] [blame] | 1057 | p.url = GURL(chrome::kAboutBlankURL); |
| 1058 | ui_test_utils::NavigateToURL(&p); |
[email protected] | fcca741b | 2011-06-17 22:46:37 | [diff] [blame] | 1059 | |
[email protected] | ddddfda | 2011-07-14 23:19:39 | [diff] [blame] | 1060 | { |
| 1061 | ui_test_utils::WindowedNotificationObserver observer( |
[email protected] | ad50def5 | 2011-10-19 23:17:07 | [diff] [blame] | 1062 | content::NOTIFICATION_LOAD_STOP, |
| 1063 | content::NotificationService::AllSources()); |
[email protected] | ddddfda | 2011-07-14 23:19:39 | [diff] [blame] | 1064 | browser()->OpenOptionsDialog(); |
| 1065 | observer.Wait(); |
| 1066 | } |
[email protected] | fcca741b | 2011-06-17 22:46:37 | [diff] [blame] | 1067 | EXPECT_EQ(1, browser()->tab_count()); |
[email protected] | ddddfda | 2011-07-14 23:19:39 | [diff] [blame] | 1068 | EXPECT_EQ(GetSettingsURL(), |
[email protected] | 4ca1530 | 2012-01-03 05:53:20 | [diff] [blame] | 1069 | browser()->GetSelectedWebContents()->GetURL().GetOrigin()); |
[email protected] | fcca741b | 2011-06-17 22:46:37 | [diff] [blame] | 1070 | } |
| 1071 | |
| 1072 | IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, |
| 1073 | NavigateFromNTPToOptionsInSameTab) { |
| 1074 | browser::NavigateParams p(MakeNavigateParams()); |
[email protected] | ddddfda | 2011-07-14 23:19:39 | [diff] [blame] | 1075 | p.url = GURL(chrome::kChromeUINewTabURL); |
| 1076 | ui_test_utils::NavigateToURL(&p); |
[email protected] | fcca741b | 2011-06-17 22:46:37 | [diff] [blame] | 1077 | EXPECT_EQ(1, browser()->tab_count()); |
[email protected] | ddddfda | 2011-07-14 23:19:39 | [diff] [blame] | 1078 | EXPECT_EQ(GURL(chrome::kChromeUINewTabURL), |
[email protected] | 4ca1530 | 2012-01-03 05:53:20 | [diff] [blame] | 1079 | browser()->GetSelectedWebContents()->GetURL()); |
[email protected] | fcca741b | 2011-06-17 22:46:37 | [diff] [blame] | 1080 | |
[email protected] | ddddfda | 2011-07-14 23:19:39 | [diff] [blame] | 1081 | { |
| 1082 | ui_test_utils::WindowedNotificationObserver observer( |
[email protected] | ad50def5 | 2011-10-19 23:17:07 | [diff] [blame] | 1083 | content::NOTIFICATION_LOAD_STOP, |
| 1084 | content::NotificationService::AllSources()); |
[email protected] | ddddfda | 2011-07-14 23:19:39 | [diff] [blame] | 1085 | browser()->OpenOptionsDialog(); |
| 1086 | observer.Wait(); |
| 1087 | } |
[email protected] | fcca741b | 2011-06-17 22:46:37 | [diff] [blame] | 1088 | EXPECT_EQ(1, browser()->tab_count()); |
[email protected] | ddddfda | 2011-07-14 23:19:39 | [diff] [blame] | 1089 | EXPECT_EQ(GetSettingsURL(), |
[email protected] | 4ca1530 | 2012-01-03 05:53:20 | [diff] [blame] | 1090 | browser()->GetSelectedWebContents()->GetURL().GetOrigin()); |
[email protected] | fcca741b | 2011-06-17 22:46:37 | [diff] [blame] | 1091 | } |
| 1092 | |
| 1093 | IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, |
| 1094 | NavigateFromPageToOptionsInNewTab) { |
| 1095 | browser::NavigateParams p(MakeNavigateParams()); |
[email protected] | ddddfda | 2011-07-14 23:19:39 | [diff] [blame] | 1096 | ui_test_utils::NavigateToURL(&p); |
[email protected] | 4ca1530 | 2012-01-03 05:53:20 | [diff] [blame] | 1097 | EXPECT_EQ(GetGoogleURL(), browser()->GetSelectedWebContents()->GetURL()); |
[email protected] | fcca741b | 2011-06-17 22:46:37 | [diff] [blame] | 1098 | EXPECT_EQ(1u, BrowserList::size()); |
| 1099 | EXPECT_EQ(1, browser()->tab_count()); |
| 1100 | |
[email protected] | ddddfda | 2011-07-14 23:19:39 | [diff] [blame] | 1101 | { |
| 1102 | ui_test_utils::WindowedNotificationObserver observer( |
[email protected] | ad50def5 | 2011-10-19 23:17:07 | [diff] [blame] | 1103 | content::NOTIFICATION_LOAD_STOP, |
| 1104 | content::NotificationService::AllSources()); |
[email protected] | ddddfda | 2011-07-14 23:19:39 | [diff] [blame] | 1105 | browser()->OpenOptionsDialog(); |
| 1106 | observer.Wait(); |
| 1107 | } |
[email protected] | fcca741b | 2011-06-17 22:46:37 | [diff] [blame] | 1108 | EXPECT_EQ(2, browser()->tab_count()); |
[email protected] | ddddfda | 2011-07-14 23:19:39 | [diff] [blame] | 1109 | EXPECT_EQ(GetSettingsURL(), |
[email protected] | 4ca1530 | 2012-01-03 05:53:20 | [diff] [blame] | 1110 | browser()->GetSelectedWebContents()->GetURL().GetOrigin()); |
[email protected] | fcca741b | 2011-06-17 22:46:37 | [diff] [blame] | 1111 | } |
| 1112 | |
| 1113 | IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, |
| 1114 | NavigateFromNTPToOptionsSingleton) { |
[email protected] | ddddfda | 2011-07-14 23:19:39 | [diff] [blame] | 1115 | { |
| 1116 | ui_test_utils::WindowedNotificationObserver observer( |
[email protected] | ad50def5 | 2011-10-19 23:17:07 | [diff] [blame] | 1117 | content::NOTIFICATION_LOAD_STOP, |
| 1118 | content::NotificationService::AllSources()); |
[email protected] | ddddfda | 2011-07-14 23:19:39 | [diff] [blame] | 1119 | browser()->OpenOptionsDialog(); |
| 1120 | observer.Wait(); |
| 1121 | } |
[email protected] | fcca741b | 2011-06-17 22:46:37 | [diff] [blame] | 1122 | EXPECT_EQ(1, browser()->tab_count()); |
| 1123 | |
| 1124 | browser()->NewTab(); |
| 1125 | EXPECT_EQ(2, browser()->tab_count()); |
| 1126 | |
[email protected] | ddddfda | 2011-07-14 23:19:39 | [diff] [blame] | 1127 | { |
| 1128 | ui_test_utils::WindowedNotificationObserver observer( |
[email protected] | ad50def5 | 2011-10-19 23:17:07 | [diff] [blame] | 1129 | content::NOTIFICATION_LOAD_STOP, |
| 1130 | content::NotificationService::AllSources()); |
[email protected] | ddddfda | 2011-07-14 23:19:39 | [diff] [blame] | 1131 | browser()->OpenOptionsDialog(); |
| 1132 | observer.Wait(); |
| 1133 | } |
[email protected] | fcca741b | 2011-06-17 22:46:37 | [diff] [blame] | 1134 | EXPECT_EQ(2, browser()->tab_count()); |
[email protected] | ddddfda | 2011-07-14 23:19:39 | [diff] [blame] | 1135 | EXPECT_EQ(GetSettingsURL(), |
[email protected] | 4ca1530 | 2012-01-03 05:53:20 | [diff] [blame] | 1136 | browser()->GetSelectedWebContents()->GetURL().GetOrigin()); |
[email protected] | fcca741b | 2011-06-17 22:46:37 | [diff] [blame] | 1137 | } |
| 1138 | |
| 1139 | IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, |
| 1140 | NavigateFromNTPToOptionsPageInSameTab) { |
[email protected] | ddddfda | 2011-07-14 23:19:39 | [diff] [blame] | 1141 | { |
| 1142 | ui_test_utils::WindowedNotificationObserver observer( |
[email protected] | ad50def5 | 2011-10-19 23:17:07 | [diff] [blame] | 1143 | content::NOTIFICATION_LOAD_STOP, |
| 1144 | content::NotificationService::AllSources()); |
[email protected] | ddddfda | 2011-07-14 23:19:39 | [diff] [blame] | 1145 | browser()->ShowOptionsTab(chrome::kPersonalOptionsSubPage); |
| 1146 | observer.Wait(); |
| 1147 | } |
[email protected] | fcca741b | 2011-06-17 22:46:37 | [diff] [blame] | 1148 | EXPECT_EQ(1, browser()->tab_count()); |
[email protected] | ddddfda | 2011-07-14 23:19:39 | [diff] [blame] | 1149 | EXPECT_EQ(GetSettingsPersonalURL(), |
[email protected] | 4ca1530 | 2012-01-03 05:53:20 | [diff] [blame] | 1150 | browser()->GetSelectedWebContents()->GetURL()); |
[email protected] | fcca741b | 2011-06-17 22:46:37 | [diff] [blame] | 1151 | |
| 1152 | browser()->NewTab(); |
| 1153 | EXPECT_EQ(2, browser()->tab_count()); |
| 1154 | |
[email protected] | ddddfda | 2011-07-14 23:19:39 | [diff] [blame] | 1155 | { |
| 1156 | ui_test_utils::WindowedNotificationObserver observer( |
[email protected] | ad50def5 | 2011-10-19 23:17:07 | [diff] [blame] | 1157 | content::NOTIFICATION_LOAD_STOP, |
| 1158 | content::NotificationService::AllSources()); |
[email protected] | ddddfda | 2011-07-14 23:19:39 | [diff] [blame] | 1159 | browser()->ShowOptionsTab(chrome::kPersonalOptionsSubPage); |
| 1160 | observer.Wait(); |
| 1161 | } |
[email protected] | fcca741b | 2011-06-17 22:46:37 | [diff] [blame] | 1162 | EXPECT_EQ(2, browser()->tab_count()); |
[email protected] | ddddfda | 2011-07-14 23:19:39 | [diff] [blame] | 1163 | EXPECT_EQ(GetSettingsPersonalURL(), |
[email protected] | 4ca1530 | 2012-01-03 05:53:20 | [diff] [blame] | 1164 | browser()->GetSelectedWebContents()->GetURL()); |
[email protected] | fcca741b | 2011-06-17 22:46:37 | [diff] [blame] | 1165 | } |
| 1166 | |
| 1167 | IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, |
| 1168 | NavigateFromOtherTabToSingletonOptions) { |
[email protected] | ddddfda | 2011-07-14 23:19:39 | [diff] [blame] | 1169 | { |
| 1170 | ui_test_utils::WindowedNotificationObserver observer( |
[email protected] | ad50def5 | 2011-10-19 23:17:07 | [diff] [blame] | 1171 | content::NOTIFICATION_LOAD_STOP, |
| 1172 | content::NotificationService::AllSources()); |
[email protected] | ddddfda | 2011-07-14 23:19:39 | [diff] [blame] | 1173 | browser()->OpenOptionsDialog(); |
| 1174 | observer.Wait(); |
| 1175 | } |
| 1176 | { |
| 1177 | ui_test_utils::WindowedNotificationObserver observer( |
[email protected] | ad50def5 | 2011-10-19 23:17:07 | [diff] [blame] | 1178 | content::NOTIFICATION_LOAD_STOP, |
| 1179 | content::NotificationService::AllSources()); |
[email protected] | 2905f74 | 2011-10-13 03:51:58 | [diff] [blame] | 1180 | browser()->AddSelectedTabWithURL( |
| 1181 | GetGoogleURL(), content::PAGE_TRANSITION_LINK); |
[email protected] | ddddfda | 2011-07-14 23:19:39 | [diff] [blame] | 1182 | observer.Wait(); |
| 1183 | } |
[email protected] | fcca741b | 2011-06-17 22:46:37 | [diff] [blame] | 1184 | |
[email protected] | ddddfda | 2011-07-14 23:19:39 | [diff] [blame] | 1185 | { |
| 1186 | ui_test_utils::WindowedNotificationObserver observer( |
[email protected] | ad50def5 | 2011-10-19 23:17:07 | [diff] [blame] | 1187 | content::NOTIFICATION_LOAD_STOP, |
| 1188 | content::NotificationService::AllSources()); |
[email protected] | ddddfda | 2011-07-14 23:19:39 | [diff] [blame] | 1189 | browser()->OpenOptionsDialog(); |
| 1190 | observer.Wait(); |
| 1191 | } |
[email protected] | fcca741b | 2011-06-17 22:46:37 | [diff] [blame] | 1192 | EXPECT_EQ(2, browser()->tab_count()); |
[email protected] | ddddfda | 2011-07-14 23:19:39 | [diff] [blame] | 1193 | EXPECT_EQ(GetSettingsURL(), |
[email protected] | 4ca1530 | 2012-01-03 05:53:20 | [diff] [blame] | 1194 | browser()->GetSelectedWebContents()->GetURL().GetOrigin()); |
[email protected] | fcca741b | 2011-06-17 22:46:37 | [diff] [blame] | 1195 | } |
| 1196 | |
[email protected] | 26c53e66 | 2011-07-09 02:21:02 | [diff] [blame] | 1197 | // Tests that when a new tab is opened from the omnibox, the focus is moved from |
| 1198 | // the omnibox for the current tab. |
| 1199 | IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, |
| 1200 | NavigateFromOmniboxIntoNewTab) { |
| 1201 | GURL url("http://www.google.com/"); |
| 1202 | GURL url2("http://maps.google.com/"); |
| 1203 | |
| 1204 | // Navigate to url. |
| 1205 | browser::NavigateParams p(MakeNavigateParams()); |
| 1206 | p.disposition = CURRENT_TAB; |
| 1207 | p.url = url; |
| 1208 | browser::Navigate(&p); |
| 1209 | |
| 1210 | // Focus the omnibox. |
| 1211 | browser()->FocusLocationBar(); |
| 1212 | |
| 1213 | AutocompleteEditController* controller = |
| 1214 | browser()->window()->GetLocationBar()->location_entry()->model()-> |
| 1215 | controller(); |
| 1216 | |
| 1217 | // Simulate an alt-enter. |
| 1218 | controller->OnAutocompleteAccept(url2, NEW_FOREGROUND_TAB, |
[email protected] | 2905f74 | 2011-10-13 03:51:58 | [diff] [blame] | 1219 | content::PAGE_TRANSITION_TYPED, GURL()); |
[email protected] | 26c53e66 | 2011-07-09 02:21:02 | [diff] [blame] | 1220 | |
| 1221 | // Make sure the second tab is selected. |
| 1222 | EXPECT_EQ(1, browser()->active_index()); |
| 1223 | |
| 1224 | // The tab contents should have the focus in the second tab. |
| 1225 | EXPECT_TRUE(ui_test_utils::IsViewFocused(browser(), |
| 1226 | VIEW_ID_TAB_CONTAINER_FOCUS_VIEW)); |
| 1227 | |
| 1228 | // Go back to the first tab. The focus should not be in the omnibox. |
| 1229 | browser()->SelectPreviousTab(); |
| 1230 | EXPECT_EQ(0, browser()->active_index()); |
| 1231 | EXPECT_FALSE(ui_test_utils::IsViewFocused(browser(), |
| 1232 | VIEW_ID_LOCATION_BAR)); |
| 1233 | } |
| 1234 | |
[email protected] | ddddfda | 2011-07-14 23:19:39 | [diff] [blame] | 1235 | IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, |
| 1236 | NavigateFromDefaultToHistoryInSameTab) { |
| 1237 | { |
| 1238 | ui_test_utils::WindowedNotificationObserver observer( |
[email protected] | ad50def5 | 2011-10-19 23:17:07 | [diff] [blame] | 1239 | content::NOTIFICATION_LOAD_STOP, |
| 1240 | content::NotificationService::AllSources()); |
[email protected] | ddddfda | 2011-07-14 23:19:39 | [diff] [blame] | 1241 | browser()->ShowHistoryTab(); |
| 1242 | observer.Wait(); |
| 1243 | } |
| 1244 | EXPECT_EQ(1, browser()->tab_count()); |
[email protected] | 11e03fb | 2012-03-03 19:07:05 | [diff] [blame] | 1245 | // TODO(csilv): Update this for uber page. http://crbug.com/111579. |
| 1246 | EXPECT_EQ(GURL(chrome::kChromeUIHistoryFrameURL), |
[email protected] | 4ca1530 | 2012-01-03 05:53:20 | [diff] [blame] | 1247 | browser()->GetSelectedWebContents()->GetURL()); |
[email protected] | ddddfda | 2011-07-14 23:19:39 | [diff] [blame] | 1248 | } |
| 1249 | |
| 1250 | IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, |
| 1251 | NavigateFromDefaultToBookmarksInSameTab) { |
| 1252 | { |
| 1253 | ui_test_utils::WindowedNotificationObserver observer( |
[email protected] | ad50def5 | 2011-10-19 23:17:07 | [diff] [blame] | 1254 | content::NOTIFICATION_LOAD_STOP, |
| 1255 | content::NotificationService::AllSources()); |
[email protected] | 0af8f13 | 2011-07-16 01:37:02 | [diff] [blame] | 1256 | browser()->OpenBookmarkManager(); |
[email protected] | ddddfda | 2011-07-14 23:19:39 | [diff] [blame] | 1257 | observer.Wait(); |
| 1258 | } |
| 1259 | EXPECT_EQ(1, browser()->tab_count()); |
| 1260 | EXPECT_EQ(GURL(chrome::kChromeUIBookmarksURL), |
[email protected] | 4ca1530 | 2012-01-03 05:53:20 | [diff] [blame] | 1261 | browser()->GetSelectedWebContents()->GetURL()); |
[email protected] | ddddfda | 2011-07-14 23:19:39 | [diff] [blame] | 1262 | } |
| 1263 | |
| 1264 | IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, |
| 1265 | NavigateFromDefaultToDownloadsInSameTab) { |
| 1266 | { |
| 1267 | ui_test_utils::WindowedNotificationObserver observer( |
[email protected] | ad50def5 | 2011-10-19 23:17:07 | [diff] [blame] | 1268 | content::NOTIFICATION_LOAD_STOP, |
| 1269 | content::NotificationService::AllSources()); |
[email protected] | ddddfda | 2011-07-14 23:19:39 | [diff] [blame] | 1270 | browser()->ShowDownloadsTab(); |
| 1271 | observer.Wait(); |
| 1272 | } |
| 1273 | EXPECT_EQ(1, browser()->tab_count()); |
| 1274 | EXPECT_EQ(GURL(chrome::kChromeUIDownloadsURL), |
[email protected] | 4ca1530 | 2012-01-03 05:53:20 | [diff] [blame] | 1275 | browser()->GetSelectedWebContents()->GetURL()); |
[email protected] | ddddfda | 2011-07-14 23:19:39 | [diff] [blame] | 1276 | } |
| 1277 | |
[email protected] | 675e779b | 2012-01-25 23:09:45 | [diff] [blame] | 1278 | // This test makes sure any link in a crashed panel page navigates to a tabbed |
| 1279 | // window. |
| 1280 | class PanelBrowserNavigatorTest : public BrowserNavigatorTest { |
| 1281 | protected: |
| 1282 | virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { |
| 1283 | command_line->AppendSwitch(switches::kEnablePanels); |
| 1284 | } |
| 1285 | }; |
| 1286 | |
| 1287 | IN_PROC_BROWSER_TEST_F(PanelBrowserNavigatorTest, NavigateFromCrashedPanel) { |
| 1288 | GURL url("http://maps.google.com/#a"); |
| 1289 | GURL url2("http://maps.google.com/#b"); |
| 1290 | |
| 1291 | // Create a panel. |
| 1292 | Browser* panel_browser = Browser::CreateForApp(Browser::TYPE_PANEL, |
| 1293 | "Test", gfx::Rect(100, 100), browser()->profile()); |
| 1294 | |
| 1295 | // Navigate to the page. |
| 1296 | browser::NavigateParams p(MakeNavigateParams(panel_browser)); |
| 1297 | p.url = url; |
| 1298 | p.disposition = CURRENT_TAB; |
| 1299 | browser::Navigate(&p); |
| 1300 | |
| 1301 | // Navigate() should have navigated in the existing panel window. |
| 1302 | EXPECT_EQ(panel_browser, p.browser); |
| 1303 | |
| 1304 | // We should now have two windows, the browser() provided by the framework and |
| 1305 | // the panel window we opened earlier. The tabbed browser window has 1 tab. |
| 1306 | EXPECT_EQ(2u, BrowserList::size()); |
| 1307 | EXPECT_EQ(1, browser()->tab_count()); |
| 1308 | EXPECT_EQ(1, panel_browser->tab_count()); |
| 1309 | |
| 1310 | // Kill the panel page. |
| 1311 | WebContents* web_contents = panel_browser->GetSelectedWebContents(); |
| 1312 | web_contents->SetIsCrashed(base::TERMINATION_STATUS_PROCESS_CRASHED, -1); |
| 1313 | EXPECT_TRUE(web_contents->IsCrashed()); |
| 1314 | |
| 1315 | // Navigate to the page. |
| 1316 | browser::NavigateParams p2(MakeNavigateParams(panel_browser)); |
| 1317 | p2.source_contents = panel_browser->GetSelectedTabContentsWrapper(); |
| 1318 | p2.url = url2; |
| 1319 | p2.disposition = CURRENT_TAB; |
| 1320 | browser::Navigate(&p2); |
| 1321 | |
| 1322 | // Navigate() should have opened a new tab in the existing tabbed window. |
| 1323 | EXPECT_EQ(browser(), p2.browser); |
| 1324 | |
| 1325 | // We should now have two windows, the browser() provided by the framework and |
| 1326 | // the panel window we opened earlier. The tabbed browser window has 2 tabs. |
| 1327 | EXPECT_EQ(2u, BrowserList::size()); |
| 1328 | EXPECT_EQ(2, browser()->tab_count()); |
| 1329 | EXPECT_EQ(1, panel_browser->tab_count()); |
| 1330 | } |
| 1331 | |
[email protected] | ddddfda | 2011-07-14 23:19:39 | [diff] [blame] | 1332 | } // namespace |