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