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