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, |