Commit 4d116bd4 authored by afakhry's avatar afakhry Committed by Commit bot

Fix View Frame Source for iframe of a file:// URL shows main frame's filename

View Frame Source for iframe of a file:// URL used to show the main frame's
filename instead of the expected title derived from the iframe's page URL in
the form of "view-source:url". This CL fixes this and adds a browser test.

BUG=659040
TEST=browser_tests --gtest_filter=ChromeNavigationBrowserTest.TestViewFrameSource

Review-Url: https://codereview.chromium.org/2501083004
Cr-Commit-Position: refs/heads/master@{#435021}
parent 2f4e2293
......@@ -7,13 +7,18 @@
#include "chrome/browser/chrome_notification_types.h"
#include "chrome/browser/renderer_context_menu/render_view_context_menu_test_util.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_commands.h"
#include "chrome/browser/ui/tabs/tab_strip_model.h"
#include "chrome/test/base/in_process_browser_test.h"
#include "chrome/test/base/ui_test_utils.h"
#include "components/url_formatter/url_formatter.h"
#include "content/public/browser/navigation_entry.h"
#include "content/public/browser/navigation_handle.h"
#include "content/public/browser/notification_service.h"
#include "content/public/browser/render_frame_host.h"
#include "content/public/browser/web_contents_observer.h"
#include "content/public/common/context_menu_params.h"
#include "content/public/common/url_constants.h"
#include "content/public/test/browser_test_utils.h"
#include "content/public/test/test_navigation_observer.h"
#include "net/dns/mock_host_resolver.h"
......@@ -132,6 +137,52 @@ IN_PROC_BROWSER_TEST_F(
}
}
// Tests that viewing frame source on a local file:// page with an iframe
// with a remote URL shows the correct tab title.
IN_PROC_BROWSER_TEST_F(ChromeNavigationBrowserTest, TestViewFrameSource) {
// The local page file:// URL.
GURL local_page_with_iframe_url = ui_test_utils::GetTestUrl(
base::FilePath(base::FilePath::kCurrentDirectory),
base::FilePath(FILE_PATH_LITERAL("iframe.html")));
// The non-file:// URL of the page to load in the iframe.
GURL iframe_target_url = embedded_test_server()->GetURL("/title1.html");
ui_test_utils::NavigateToURL(browser(), local_page_with_iframe_url);
content::WebContents* web_contents =
browser()->tab_strip_model()->GetActiveWebContents();
content::TestNavigationObserver observer(web_contents);
ASSERT_TRUE(content::ExecuteScript(
web_contents->GetMainFrame(),
base::StringPrintf("var iframe = document.getElementById('test');\n"
"iframe.setAttribute('src', '%s');\n",
iframe_target_url.spec().c_str())));
observer.Wait();
content::RenderFrameHost* frame =
content::ChildFrameAt(web_contents->GetMainFrame(), 0);
ASSERT_TRUE(frame);
ASSERT_NE(frame, web_contents->GetMainFrame());
content::ContextMenuParams params;
params.page_url = local_page_with_iframe_url;
params.frame_url = frame->GetLastCommittedURL();
params.frame_page_state = content::PageState::CreateFromURL(params.frame_url);
TestRenderViewContextMenu menu(frame, params);
menu.Init();
menu.ExecuteCommand(IDC_CONTENT_CONTEXT_VIEWFRAMESOURCE, 0);
ASSERT_EQ(browser()->tab_strip_model()->count(), 2);
content::WebContents* new_web_contents =
browser()->tab_strip_model()->GetWebContentsAt(1);
ASSERT_NE(new_web_contents, web_contents);
WaitForLoadStop(new_web_contents);
GURL view_frame_source_url(content::kViewSourceScheme + std::string(":") +
iframe_target_url.spec());
EXPECT_EQ(url_formatter::FormatUrl(view_frame_source_url),
new_web_contents->GetTitle());
}
class ChromeNavigationPortMappedBrowserTest : public InProcessBrowserTest {
public:
ChromeNavigationPortMappedBrowserTest() {}
......
......@@ -1234,6 +1234,7 @@ void ViewSource(Browser* browser,
GURL view_source_url =
GURL(content::kViewSourceScheme + std::string(":") + url.spec());
last_committed_entry->SetVirtualURL(view_source_url);
last_committed_entry->SetURL(url);
// Do not restore scroller position.
last_committed_entry->SetPageState(page_state.RemoveScrollOffset());
......
......@@ -15,3 +15,6 @@
-IsolatedAppTest.CrossProcessClientRedirect
-IsolatedAppTest.IsolatedAppProcessModel
-IsolatedAppTest.SubresourceCookieIsolation
# crbug.com/669299: Wrong view frame source with --site-per-process
-ChromeNavigationBrowserTest.TestViewFrameSource
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment