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