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