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