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