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