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