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