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

Unified Diff: chrome/test/data/extensions/platform_apps/web_view/shim/main.js

Issue 2702503002: Block renderer-initiated main frame navigations to data URLs (Closed)
Patch Set: nasko comments Created 3 years, 8 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: chrome/test/data/extensions/platform_apps/web_view/shim/main.js
diff --git a/chrome/test/data/extensions/platform_apps/web_view/shim/main.js b/chrome/test/data/extensions/platform_apps/web_view/shim/main.js
index ddabbcd9030fb80066bfd819e024afe440da5e38..dfab8b9877ae4f55b3df9df78114624268c72d3a 100644
--- a/chrome/test/data/extensions/platform_apps/web_view/shim/main.js
+++ b/chrome/test/data/extensions/platform_apps/web_view/shim/main.js
@@ -430,6 +430,28 @@ function testChromeExtensionRelativePath() {
document.body.appendChild(webview);
}
+// This test verifies that guests are blocked from navigating the webview to a
+// data URL.
+function testContentInitiatedNavigationToDataUrlBlocked() {
+ var navUrl = "data:text/html,foo";
+ var webview = document.createElement('webview');
+ webview.addEventListener('consolemessage', function(e) {
+ if (e.message.startsWith(
+ 'Not allowed to top-level navigate to resource:')) {
+ embedder.test.succeed();
+ }
+ });
+ webview.addEventListener('loadstop', function(e) {
+ if (webview.getAttribute('src') == navUrl) {
+ embedder.test.fail();
+ }
+ });
+ webview.setAttribute('src',
+ 'data:text/html,<script>window.location.href = "' + navUrl +
+ '";</scr' + 'ipt>');
+ document.body.appendChild(webview);
+}
+
// Tests that a <webview> that starts with "display: none" style loads
// properly.
function testDisplayNoneWebviewLoad() {
@@ -1313,7 +1335,7 @@ function testExecuteScriptIsAbortedWhenWebViewSourceIsChanged() {
webview.addEventListener('loadstop', function onLoadStop(e) {
window.console.log('2. Inject script to trigger a guest-initiated ' +
'navigation.');
- var navUrl = 'data:text/html,trigger nav';
+ var navUrl = embedder.baseGuestURL + "/empty.html";
webview.executeScript({
code: 'window.location.href = "' + navUrl + '";'
});
@@ -3052,6 +3074,8 @@ embedder.test.testList = {
'testAPIMethodExistence': testAPIMethodExistence,
'testChromeExtensionURL': testChromeExtensionURL,
'testChromeExtensionRelativePath': testChromeExtensionRelativePath,
+ 'testContentInitiatedNavigationToDataUrlBlocked':
+ testContentInitiatedNavigationToDataUrlBlocked,
'testDisplayNoneWebviewLoad': testDisplayNoneWebviewLoad,
'testDisplayNoneWebviewRemoveChild': testDisplayNoneWebviewRemoveChild,
'testInlineScriptFromAccessibleResources':

Powered by Google App Engine
This is Rietveld 408576698