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