| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include <string> | 5 #include <string> |
| 6 | 6 |
| 7 #include "base/memory/scoped_ptr.h" | 7 #include "base/memory/scoped_ptr.h" |
| 8 #include "base/string16.h" | 8 #include "base/string16.h" |
| 9 #include "base/utf_string_conversions.h" | 9 #include "base/utf_string_conversions.h" |
| 10 #include "chrome/app/chrome_command_ids.h" | 10 #include "chrome/app/chrome_command_ids.h" |
| (...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 159 // in the message loop to delete itself, which frees the Browser object | 159 // in the message loop to delete itself, which frees the Browser object |
| 160 // which fires this event. | 160 // which fires this event. |
| 161 AutoreleasePool()->Recycle(); | 161 AutoreleasePool()->Recycle(); |
| 162 #endif | 162 #endif |
| 163 | 163 |
| 164 signal.Wait(); | 164 signal.Wait(); |
| 165 EXPECT_FALSE(clipboard->IsFormatAvailable( | 165 EXPECT_FALSE(clipboard->IsFormatAvailable( |
| 166 ui::Clipboard::GetPlainTextFormatType(), ui::Clipboard::BUFFER_STANDARD)); | 166 ui::Clipboard::GetPlainTextFormatType(), ui::Clipboard::BUFFER_STANDARD)); |
| 167 } | 167 } |
| 168 | 168 |
| 169 // Verify that "Open Link in New Tab" doesn't send URL fragment as referrer. |
| 170 IN_PROC_BROWSER_TEST_F(ContextMenuBrowserTest, OpenInNewTabReferrer) { |
| 171 ui_test_utils::WindowedTabAddedNotificationObserver tab_observer( |
| 172 content::NotificationService::AllSources()); |
| 173 |
| 174 ASSERT_TRUE(test_server()->Start()); |
| 175 GURL echoheader(test_server()->GetURL("echoheader?Referer")); |
| 176 |
| 177 // Go to a |page| with a link to echoheader URL. |
| 178 GURL page("data:text/html,<a href='" + echoheader.spec() + "'>link</a>"); |
| 179 ui_test_utils::NavigateToURL(browser(), page); |
| 180 |
| 181 // Set up referrer URL with fragment. |
| 182 const GURL kReferrerWithFragment("http://foo.com/test#fragment"); |
| 183 const std::string kCorrectReferrer("http://foo.com/test"); |
| 184 |
| 185 // Set up menu with link URL. |
| 186 content::ContextMenuParams context_menu_params; |
| 187 context_menu_params.page_url = kReferrerWithFragment; |
| 188 context_menu_params.link_url = echoheader; |
| 189 |
| 190 // Select "Open Link in New Tab" and wait for the new tab to be added. |
| 191 TestRenderViewContextMenu menu( |
| 192 browser()->tab_strip_model()->GetActiveWebContents(), |
| 193 context_menu_params); |
| 194 menu.Init(); |
| 195 menu.ExecuteCommand(IDC_CONTENT_CONTEXT_OPENLINKNEWTAB, 0); |
| 196 |
| 197 tab_observer.Wait(); |
| 198 content::WebContents* tab = tab_observer.GetTab(); |
| 199 content::WaitForLoadStop(tab); |
| 200 |
| 201 // Verify that it's the correct tab. |
| 202 ASSERT_EQ(echoheader, tab->GetURL()); |
| 203 // Verify that the text on the page matches |kCorrectReferrer|. |
| 204 std::string actual_referrer; |
| 205 ASSERT_TRUE(content::ExecuteScriptAndExtractString( |
| 206 tab, |
| 207 "window.domAutomationController.send(window.document.body.textContent);", |
| 208 &actual_referrer)); |
| 209 ASSERT_EQ(kCorrectReferrer, actual_referrer); |
| 210 |
| 211 // Verify that the referrer on the page matches |kCorrectReferrer|. |
| 212 std::string page_referrer; |
| 213 ASSERT_TRUE(content::ExecuteScriptAndExtractString( |
| 214 tab, |
| 215 "window.domAutomationController.send(window.document.referrer);", |
| 216 &page_referrer)); |
| 217 ASSERT_EQ(kCorrectReferrer, page_referrer); |
| 218 } |
| 219 |
| 220 // Verify that "Open Link in Incognito Window " doesn't send referrer URL. |
| 221 IN_PROC_BROWSER_TEST_F(ContextMenuBrowserTest, OpenIncognitoNoneReferrer) { |
| 222 ui_test_utils::WindowedTabAddedNotificationObserver tab_observer( |
| 223 content::NotificationService::AllSources()); |
| 224 |
| 225 ASSERT_TRUE(test_server()->Start()); |
| 226 GURL echoheader(test_server()->GetURL("echoheader?Referer")); |
| 227 |
| 228 // Go to a |page| with a link to echoheader URL. |
| 229 GURL page("data:text/html,<a href='" + echoheader.spec() + "'>link</a>"); |
| 230 ui_test_utils::NavigateToURL(browser(), page); |
| 231 |
| 232 // Set up referrer URL with fragment. |
| 233 const GURL kReferrerWithFragment("http://foo.com/test#fragment"); |
| 234 const std::string kNoneReferrer("None"); |
| 235 const std::string kEmptyReferrer(""); |
| 236 |
| 237 // Set up menu with link URL. |
| 238 content::ContextMenuParams context_menu_params; |
| 239 context_menu_params.page_url = kReferrerWithFragment; |
| 240 context_menu_params.link_url = echoheader; |
| 241 |
| 242 // Select "Open Link in Incognito Window" and wait for window to be added. |
| 243 TestRenderViewContextMenu menu( |
| 244 browser()->tab_strip_model()->GetActiveWebContents(), |
| 245 context_menu_params); |
| 246 menu.Init(); |
| 247 menu.ExecuteCommand(IDC_CONTENT_CONTEXT_OPENLINKOFFTHERECORD, 0); |
| 248 |
| 249 tab_observer.Wait(); |
| 250 content::WebContents* tab = tab_observer.GetTab(); |
| 251 content::WaitForLoadStop(tab); |
| 252 |
| 253 // Verify that it's the correct tab. |
| 254 ASSERT_EQ(echoheader, tab->GetURL()); |
| 255 // Verify that the text on the page matches |kNoneReferrer|. |
| 256 std::string actual_referrer; |
| 257 ASSERT_TRUE(content::ExecuteScriptAndExtractString( |
| 258 tab, |
| 259 "window.domAutomationController.send(window.document.body.textContent);", |
| 260 &actual_referrer)); |
| 261 ASSERT_EQ(kNoneReferrer, actual_referrer); |
| 262 |
| 263 // Verify that the referrer on the page matches |kEmptyReferrer|. |
| 264 std::string page_referrer; |
| 265 ASSERT_TRUE(content::ExecuteScriptAndExtractString( |
| 266 tab, |
| 267 "window.domAutomationController.send(window.document.referrer);", |
| 268 &page_referrer)); |
| 269 ASSERT_EQ(kEmptyReferrer, page_referrer); |
| 270 } |
| 271 |
| 169 } // namespace | 272 } // namespace |
| OLD | NEW |