Chromium Code Reviews| Index: chrome/browser/tab_contents/render_view_context_menu_browsertest.cc |
| diff --git a/chrome/browser/tab_contents/render_view_context_menu_browsertest.cc b/chrome/browser/tab_contents/render_view_context_menu_browsertest.cc |
| index a3db8e8c27572fdc49f78e87fb71ebb5b75eb62e..7596663f5e71fd1d7473904d6458d11e09cec3c2 100644 |
| --- a/chrome/browser/tab_contents/render_view_context_menu_browsertest.cc |
| +++ b/chrome/browser/tab_contents/render_view_context_menu_browsertest.cc |
| @@ -166,4 +166,54 @@ IN_PROC_BROWSER_TEST_F(ContextMenuBrowserTest, CopyLinkFromIncognito) { |
| ui::Clipboard::GetPlainTextFormatType(), ui::Clipboard::BUFFER_STANDARD)); |
| } |
| +// Verify that "Open Link in New Tab" doesn't send URL fragment as referrer. |
| +IN_PROC_BROWSER_TEST_F(ContextMenuBrowserTest, OpenInNewTabReferrer) { |
|
mmenke
2013/03/20 16:33:51
Optional: Just for completeness, may want to add
mef
2013/03/20 18:25:31
Done. Expectantly (I think) this case is slightly
|
| + ui_test_utils::WindowedTabAddedNotificationObserver tab_observer( |
| + content::NotificationService::AllSources()); |
| + |
| + ASSERT_TRUE(test_server()->Start()); |
| + GURL echoheader(test_server()->GetURL("echoheader?Referer")); |
| + |
| + // Go to a |page| with a link to echoheader URL. |
| + GURL page("data:text/html,<a href='" + echoheader.spec() + "'>link</a>"); |
| + ui_test_utils::NavigateToURL(browser(), page); |
| + |
| + // Set up referrer URL with fragment. |
| + GURL referrer_with_fragment("http://foo.com/test#fragment"); |
| + std::string correct_referrer("http://foo.com/test"); |
|
mmenke
2013/03/20 16:33:51
nit: Since these are both hard-coded constants, I
mef
2013/03/20 18:25:31
Done.
|
| + |
| + // Set up menu with link URL. |
| + content::ContextMenuParams context_menu_params; |
| + context_menu_params.page_url = referrer_with_fragment; |
| + context_menu_params.link_url = echoheader; |
| + |
| + // Select "Open Link in New Tab" and wait for the new tab to be added. |
| + TestRenderViewContextMenu menu( |
| + browser()->tab_strip_model()->GetActiveWebContents(), |
| + context_menu_params); |
| + menu.Init(); |
| + menu.ExecuteCommand(IDC_CONTENT_CONTEXT_OPENLINKNEWTAB, 0); |
| + |
| + tab_observer.Wait(); |
| + content::WebContents* tab = tab_observer.GetTab(); |
| + content::WaitForLoadStop(tab); |
| + |
| + // Verify that it's the correct tab. |
| + ASSERT_EQ(echoheader, tab->GetURL()); |
| + // Verify that the text on the page matches |correct_referrer|. |
| + std::string actual_referrer; |
| + ASSERT_TRUE(content::ExecuteScriptAndExtractString( |
| + tab, |
| + "window.domAutomationController.send(window.document.body.textContent);", |
| + &actual_referrer)); |
| + ASSERT_EQ(correct_referrer, actual_referrer); |
| + // Verify that the referrer on the page matches |correct_referrer|. |
|
mmenke
2013/03/20 16:33:51
optional nit: May want a line break above the com
mef
2013/03/20 18:25:31
Done.
|
| + std::string page_referrer; |
| + ASSERT_TRUE(content::ExecuteScriptAndExtractString( |
| + tab, |
| + "window.domAutomationController.send(window.document.referrer);", |
| + &page_referrer)); |
| + ASSERT_EQ(correct_referrer, page_referrer); |
| +} |
| + |
| } // namespace |