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