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

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

Issue 2775953002: Some cleanup of app and extension CSP tests.
Patch Set: 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
« no previous file with comments | « chrome/test/data/extensions/api_test/sandboxed_pages_csp/sandboxed.html ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/test/data/extensions/platform_apps/iframes/main.js
diff --git a/chrome/test/data/extensions/platform_apps/iframes/main.js b/chrome/test/data/extensions/platform_apps/iframes/main.js
index 4634b7252beb35b8c7c8feb4f85d36c5663848b2..7d47a4affd7ffe11405b51187d9cf2408b49aea2 100644
--- a/chrome/test/data/extensions/platform_apps/iframes/main.js
+++ b/chrome/test/data/extensions/platform_apps/iframes/main.js
@@ -8,30 +8,55 @@ chrome.test.getConfig(function(config) {
var REMOTE_URL = 'http://localhost:' + config.testServer.port
'/extensions/platform_apps/iframes/remote-iframe.html';
+ function onEvent(target, event_name) {
+ return new Promise((resolve, reject) => {
+ target.addEventListener(event_name, resolve);
+ });
+ }
+
+ function onCspViolation(url) {
+ return onEvent(window, 'securitypolicyviolation').then(event => {
+ chrome.test.assertEq(url, event.blockedURI);
+ });
+ }
+
chrome.test.runTests([
function localIframe() {
var iframe = document.createElement('iframe');
- iframe.onload = chrome.test.callbackPass(function() {
+ iframe.src = LOCAL_URL;
+
+ // Expect this to load normally.
+ onEvent(iframe, 'load').then(() => {
console.log('Local iframe loaded');
+ chrome.test.succeed();
});
- iframe.src = LOCAL_URL;
+
document.body.appendChild(iframe);
},
function dataUrlIframe() {
var iframe = document.createElement('iframe');
- iframe.onload = chrome.test.callbackPass(function() {
+ iframe.src = DATA_URL;
+
+ // Expect this to load normally.
+ onEvent(iframe, 'load').then(() => {
console.log('data: URL iframe loaded');
+ chrome.test.succeed();
});
- iframe.src = DATA_URL;
+
document.body.appendChild(iframe);
},
function filesystemUrlIframe() {
var iframe = document.createElement('iframe');
- iframe.onload = chrome.test.callbackPass(function() {
- console.log('filesystem: URL iframe loaded');
- });
+
+ // The filesystem: document should load and postMessage back.
+ Promise.all([onEvent(iframe, 'load'), onEvent(window, 'message')])
+ .then(chrome.test.succeed);
+
+ var blob = new Blob(['This filesystem: frame should be displayed',
+ '<script src="', document.origin, '/post_to_parent.js"></scri',
+ 'pt>'], {type: 'text/html'});
webkitRequestFileSystem(
window.TEMPORARY,
@@ -49,8 +74,6 @@ chrome.test.getConfig(function(config) {
document.body.appendChild(iframe);
};
- var blob = new Blob(['This frame should be displayed'],
- {type: 'text/html'});
fileWriter.write(blob);
});
});
@@ -58,13 +81,17 @@ chrome.test.getConfig(function(config) {
},
function blobUrlIframe() {
- var blob = new Blob(['This frame should be displayed'],
- {type: 'text/html'});
- var blobUrl = window.URL.createObjectURL(blob);
var iframe = document.createElement('iframe');
- iframe.onload = chrome.test.callbackPass(function() {
- console.log('blob: URL iframe loaded');
- });
+
+ // The blob: document should load and postMessage back.
+ Promise.all([onEvent(iframe, 'load'), onEvent(window, 'message')])
+ .then(chrome.test.succeed);
+
+ var blob = new Blob(['This blob: frame should be displayed',
+ '<script src="', document.origin, '/post_to_parent.js"></scri',
+ 'pt>'], {type: 'text/html'});
+ var blobUrl = window.URL.createObjectURL(blob);
+
iframe.src = blobUrl;
document.body.appendChild(iframe);
},
@@ -72,11 +99,11 @@ chrome.test.getConfig(function(config) {
function remoteIframe() {
var iframe = document.createElement('iframe');
iframe.src = REMOTE_URL;
- document.body.appendChild(iframe);
- // Load failure should happen synchronously, but wait a bit before
- // declaring success.
- setTimeout(chrome.test.succeed, 500);
- }
+ // Expect this to be blocked by the CSP.
+ onCspViolation(REMOTE_URL).then(chrome.test.succeed);
+
+ document.body.appendChild(iframe);
+ },
]);
});
« no previous file with comments | « chrome/test/data/extensions/api_test/sandboxed_pages_csp/sandboxed.html ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698