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