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