Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(285)

Unified Diff: content/browser/web_contents/web_contents_impl_unittest.cc

Issue 1917073002: Block webpages from navigating to view-source URLs (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Delete layout tests Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: content/browser/web_contents/web_contents_impl_unittest.cc
diff --git a/content/browser/web_contents/web_contents_impl_unittest.cc b/content/browser/web_contents/web_contents_impl_unittest.cc
index ede10cfe0ba9abd66b13affe40376ed18086b10c..c0bee905b5406913e5adc49f2221a7860476a395 100644
--- a/content/browser/web_contents/web_contents_impl_unittest.cc
+++ b/content/browser/web_contents/web_contents_impl_unittest.cc
@@ -405,29 +405,36 @@ TEST_F(WebContentsImplTest, UseTitleFromPendingEntryIfSet) {
EXPECT_EQ(title, contents()->GetTitle());
}
-// Test view source mode for a webui page.
-TEST_F(WebContentsImplTest, NTPViewSource) {
+// Browser initiated navigations to view-source URLs of WebUI pages should work.
+TEST_F(WebContentsImplTest, DirectNavigationToViewSourceWebUI) {
NavigationControllerImpl& cont =
static_cast<NavigationControllerImpl&>(controller());
- const char kUrl[] = "view-source:chrome://blah";
- const GURL kGURL(kUrl);
+ const GURL kGURL("view-source:chrome://blah");
+ // NavigationControllerImpl rewrites view-source URLs, simulating that here.
+ const GURL kRewrittenURL("chrome://blah");
process()->sink().ClearMessages();
- cont.LoadURL(
- kGURL, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string());
+ // Use LoadURLWithParams instead of LoadURL, because the former properly
+ // rewrites view-source:chrome://blah URLs to chrome://blah.
+ NavigationController::LoadURLParams load_params(kGURL);
+ load_params.transition_type = ui::PAGE_TRANSITION_TYPED;
+ load_params.extra_headers = "content-type: text/plain";
+ load_params.load_type = NavigationController::LOAD_TYPE_DEFAULT;
+ load_params.is_renderer_initiated = false;
+ controller().LoadURLWithParams(load_params);
+
int entry_id = cont.GetPendingEntry()->GetUniqueID();
// Did we get the expected message?
EXPECT_TRUE(process()->sink().GetFirstMessageMatching(
FrameMsg_EnableViewSourceMode::ID));
FrameHostMsg_DidCommitProvisionalLoad_Params params;
- InitNavigateParams(&params, 0, entry_id, true, kGURL,
+ InitNavigateParams(&params, 0, entry_id, true, kRewrittenURL,
ui::PAGE_TRANSITION_TYPED);
contents()->GetMainFrame()->PrepareForCommit();
contents()->GetMainFrame()->SendNavigateWithParams(&params);
- // Also check title and url.
- EXPECT_EQ(base::ASCIIToUTF16(kUrl), contents()->GetTitle());
+ EXPECT_EQ(base::ASCIIToUTF16("chrome://blah"), contents()->GetTitle());
}
// Test to ensure UpdateMaxPageID is working properly.
« no previous file with comments | « content/browser/web_contents/web_contents_impl_browsertest.cc ('k') | content/public/test/content_browser_test_utils.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698