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

Side by Side Diff: content/browser/browser_side_navigation_browsertest.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, 6 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 unified diff | Download patch
« no previous file with comments | « no previous file | content/browser/child_process_security_policy_impl.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 <stdint.h> 5 #include <stdint.h>
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/strings/stringprintf.h" 8 #include "base/strings/stringprintf.h"
9 #include "base/strings/utf_string_conversions.h" 9 #include "base/strings/utf_string_conversions.h"
10 #include "content/browser/web_contents/web_contents_impl.h" 10 #include "content/browser/web_contents/web_contents_impl.h"
11 #include "content/common/site_isolation_policy.h" 11 #include "content/common/site_isolation_policy.h"
12 #include "content/public/browser/web_contents.h" 12 #include "content/public/browser/web_contents.h"
13 #include "content/public/common/content_switches.h" 13 #include "content/public/common/content_switches.h"
14 #include "content/public/common/url_constants.h"
14 #include "content/public/test/browser_test_utils.h" 15 #include "content/public/test/browser_test_utils.h"
15 #include "content/public/test/content_browser_test.h" 16 #include "content/public/test/content_browser_test.h"
16 #include "content/public/test/content_browser_test_utils.h" 17 #include "content/public/test/content_browser_test_utils.h"
17 #include "content/public/test/test_navigation_observer.h" 18 #include "content/public/test/test_navigation_observer.h"
18 #include "content/shell/browser/shell.h" 19 #include "content/shell/browser/shell.h"
19 #include "net/dns/mock_host_resolver.h" 20 #include "net/dns/mock_host_resolver.h"
20 #include "net/test/embedded_test_server/embedded_test_server.h" 21 #include "net/test/embedded_test_server/embedded_test_server.h"
21 #include "net/test/url_request/url_request_failed_job.h" 22 #include "net/test/url_request/url_request_failed_job.h"
22 #include "url/gurl.h" 23 #include "url/gurl.h"
23 24
(...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after
221 EXPECT_EQ("text=&select=a", 222 EXPECT_EQ("text=&select=a",
222 base::UTF16ToASCII(shell()->web_contents()->GetTitle())); 223 base::UTF16ToASCII(shell()->web_contents()->GetTitle()));
223 EXPECT_EQ(post_url, shell()->web_contents()->GetLastCommittedURL()); 224 EXPECT_EQ(post_url, shell()->web_contents()->GetLastCommittedURL());
224 EXPECT_TRUE(shell() 225 EXPECT_TRUE(shell()
225 ->web_contents() 226 ->web_contents()
226 ->GetController() 227 ->GetController()
227 .GetActiveEntry() 228 .GetActiveEntry()
228 ->GetHasPostData()); 229 ->GetHasPostData());
229 } 230 }
230 231
232 // Ensure that browser side navigation can load browser initiated navigations
233 // to view-source URLs.
234 IN_PROC_BROWSER_TEST_F(BrowserSideNavigationBrowserTest,
235 ViewSourceNavigation_BrowserInitiated) {
236 TestNavigationObserver observer(shell()->web_contents());
237 GURL url(embedded_test_server()->GetURL("/title1.html"));
238 GURL view_source_url(content::kViewSourceScheme + std::string(":") +
239 url.spec());
240 NavigateToURL(shell(), view_source_url);
241 EXPECT_EQ(url, observer.last_navigation_url());
242 EXPECT_TRUE(observer.last_navigation_succeeded());
243 }
244
245 // Ensure that browser side navigation blocks content initiated navigations to
246 // view-source URLs.
247 IN_PROC_BROWSER_TEST_F(BrowserSideNavigationBrowserTest,
248 ViewSourceNavigation_RendererInitiated) {
249 TestNavigationObserver observer(shell()->web_contents());
250 GURL kUrl(embedded_test_server()->GetURL("/simple_links.html"));
251 NavigateToURL(shell(), kUrl);
252 EXPECT_EQ(kUrl, observer.last_navigation_url());
253 EXPECT_TRUE(observer.last_navigation_succeeded());
254
255 std::unique_ptr<ConsoleObserverDelegate> console_delegate(
256 new ConsoleObserverDelegate(
257 shell()->web_contents(),
258 "Not allowed to load local resource: view-source:about:blank"));
259 shell()->web_contents()->SetDelegate(console_delegate.get());
260
261 bool success = false;
262 EXPECT_TRUE(ExecuteScriptAndExtractBool(
263 shell()->web_contents(),
264 "window.domAutomationController.send(clickViewSourceLink());", &success));
265 EXPECT_TRUE(success);
266 console_delegate->Wait();
267 // Original page shouldn't navigate away.
268 EXPECT_EQ(kUrl, shell()->web_contents()->GetURL());
269 EXPECT_FALSE(shell()
270 ->web_contents()
271 ->GetController()
272 .GetLastCommittedEntry()
273 ->IsViewSourceMode());
274 }
275
231 } // namespace content 276 } // namespace content
OLDNEW
« no previous file with comments | « no previous file | content/browser/child_process_security_policy_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698