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