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

Unified Diff: extensions/test/data/web_view/apitest/main.js

Issue 2702503002: Block renderer-initiated main frame navigations to data URLs (Closed)
Patch Set: nasko comments, fix most tests Created 3 years, 9 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: extensions/test/data/web_view/apitest/main.js
diff --git a/extensions/test/data/web_view/apitest/main.js b/extensions/test/data/web_view/apitest/main.js
index b6c734f6c3bc6e5266b33e6f7fc69a0a84ed9165..2489bbf45c0c6d2df8c7f09c13c8a4c718ea48c0 100644
--- a/extensions/test/data/web_view/apitest/main.js
+++ b/extensions/test/data/web_view/apitest/main.js
@@ -19,6 +19,8 @@ embedder.setUp_ = function(config) {
embedder.redirectGuestURLDest =
embedder.baseGuestURL + '/guest_redirect.html';
embedder.windowOpenGuestURL = embedder.baseGuestURL + '/guest.html';
+ embedder.windowOpenGuestDataURL =
+ embedder.baseGuestURL + '/guest_data_url.html';
embedder.sameDocumentNavigationURL =
embedder.baseGuestURL + '/guest_same_document_navigation.html';
};
@@ -1133,6 +1135,48 @@ function testNavigationToExternalProtocol() {
document.body.appendChild(webview);
}
+// This test verifies that redirecting a webview to a data URL is blocked.
+function testRedirectToDataUrlBlocked() {
+ var webview = document.createElement('webview');
+ webview.addEventListener('consolemessage', function(e) {
+ window.console.log('consolemessage: ' + e.message);
+ if (e.message.startsWith(
+ 'Not allowed to top-level navigate to resource:')) {
+ embedder.test.succeed();
+ }
+ });
+ webview.addEventListener('loadstop', function(e) {
+ if (webview.getAttribute('src').startsWith("data:"))
+ embedder.test.fail();
+ });
+ webview.setAttribute('src', embedder.windowOpenGuestDataURL);
+ document.body.appendChild(webview);
+}
+
+// This test verifies that redirecting a webview to a data URL is allowed if the
+// current URL is already a data URL.
+function testRedirectToDataUrlFromDataUrlAllowed() {
+ var webview = document.createElement('webview');
+ webview.addEventListener('loadstop', function(e) {
+ if (webview.getAttribute('src').startsWith("data:text/html")) {
+ webview.executeScript({
+ code: 'window.location.href = "data:text/plain, success";'
+ }, function(results) {});
+ } else if (webview.getAttribute('src').startsWith("data:text/plain")) {
+ embedder.test.succeed();
+ }
+ });
+ webview.addEventListener('consolemessage', function(e) {
+ window.console.log('consolemessage: ' + e.message);
+ if (e.message.startsWith(
+ 'Not allowed to top-level navigate to resource:')) {
+ embedder.test.fail();
+ }
+ });
+ webview.setAttribute('src', 'data:text/html,navigate to another data url');
+ document.body.appendChild(webview);
+}
+
// This test ensures if the guest isn't there and we resize the guest (from JS),
// it remembers the size correctly.
function testNavigateAfterResize() {
@@ -1229,6 +1273,12 @@ function testNavOnSrcAttributeChange() {
}
// This test verifies that new window attachment functions as expected.
+//
+// TODO(crbug.com/594215) Test that opening a new window with a data URL is
+// blocked. There is currently no way to test this, as the block message is
+// printed on the new window which never gets created, so the message is lost.
+// Also test that opening a new window with a data URL when the webview is
+// already on a data URL is allowed.
function testNewWindow() {
var webview = document.createElement('webview');
webview.addEventListener('newwindow', function(e) {
@@ -1785,6 +1835,9 @@ embedder.test.testList = {
'testLoadStartLoadRedirect': testLoadStartLoadRedirect,
'testNavigateAfterResize': testNavigateAfterResize,
'testNavigationToExternalProtocol': testNavigationToExternalProtocol,
+ 'testRedirectToDataUrlBlocked': testRedirectToDataUrlBlocked,
+ 'testRedirectToDataUrlFromDataUrlAllowed':
+ testRedirectToDataUrlFromDataUrlAllowed,
'testNavOnConsecutiveSrcAttributeChanges':
testNavOnConsecutiveSrcAttributeChanges,
'testNavOnSrcAttributeChange': testNavOnSrcAttributeChange,

Powered by Google App Engine
This is Rietveld 408576698