Commit d59ef5f8 authored by Makoto Shimazu's avatar Makoto Shimazu Committed by Commit Bot

Refactor tests for sandbox iframes controlled by service worker

This patch is to split sandboxed-iframe-fetch-event.https.html into small
chunks. Each promise_test has smaller number of assertions, so that now we can
see the results for each situation.

Bug: 771815
Change-Id: I75cdd67f92bbb07d6b538b209e1f0819752c3bc8
Reviewed-on: https://chromium-review.googlesource.com/923901
Commit-Queue: Makoto Shimazu <shimazu@chromium.org>
Reviewed-by: default avatarMatt Falkenhagen <falken@chromium.org>
Cr-Commit-Position: refs/heads/master@{#537606}
parent db67b537
<script> <script>
function with_iframe(url) { function with_iframe(url) {
return new Promise(function(resolve) { return new Promise(resolve => {
var frame = document.createElement('iframe'); let frame = document.createElement('iframe');
frame.src = url; frame.src = url;
frame.onload = function() { resolve(frame); }; frame.onload = () => { resolve(frame); };
document.body.appendChild(frame); document.body.appendChild(frame);
}); });
} }
function with_sandboxed_iframe(url, sandbox) { function with_sandboxed_iframe(url, sandbox) {
return new Promise(function(resolve) { return new Promise(resolve => {
var frame = document.createElement('iframe'); let frame = document.createElement('iframe');
frame.sandbox = sandbox; frame.sandbox = sandbox;
frame.src = url; frame.src = url;
frame.onload = function() { resolve(frame); }; frame.onload = () => { resolve(frame); };
document.body.appendChild(frame); document.body.appendChild(frame);
}); });
} }
function fetch_in_worker() { function fetch_from_worker(url) {
return new Promise((resolve) => { return new Promise(resolve => {
var blob = new Blob([ let blob = new Blob([
"fetch('" + location.href + "_workerfetch', {mode: 'no-cors'})" + `fetch('${url}', {mode: 'no-cors'})` +
" .then(() => { self.postMessage('OK'); });"]); " .then(() => { self.postMessage('OK'); });"]);
var url = URL.createObjectURL(blob); let worker_url = URL.createObjectURL(blob);
var worker = new Worker(url); let worker = new Worker(worker_url);
worker.onmessage = resolve; worker.onmessage = resolve;
}); });
} }
window.onmessage = function (e) { function run_test(type) {
var id = e.data['id']; const base_path = location.href;
fetch(location.href + "_fetch", {mode: 'no-cors'}) switch (type) {
.then(function() { case 'fetch':
return fetch_in_worker(); return fetch(`${base_path}&test=fetch`, {mode: 'no-cors'});
}) case 'fetch-from-worker':
.then(function() { return fetch_from_worker(`${base_path}&test=fetch-from-worker`);
return with_iframe(location.href + "_iframe"); case 'iframe':
}) return with_iframe(`${base_path}&test=iframe`);
.then(function() { case 'sandboxed-iframe':
return with_sandboxed_iframe(location.href + "_script", return with_sandboxed_iframe(`${base_path}&test=sandboxed-iframe`,
"allow-scripts"); "allow-scripts");
}) case 'sandboxed-iframe-same-origin':
.then(function() { return with_sandboxed_iframe(
return with_sandboxed_iframe(location.href + "_script-origin", `${base_path}&test=sandboxed-iframe-same-origin`,
"allow-scripts allow-same-origin"); "allow-scripts allow-same-origin");
}) default:
.then(function() { return Promise.reject(`Unknown type: ${type}`);
}
}
window.onmessage = event => {
let id = event.data['id'];
run_test(event.data['type'])
.then(() => {
window.top.postMessage({id: id, result: 'done'}, '*'); window.top.postMessage({id: id, result: 'done'}, '*');
}) })
.catch(function(e) { .catch(e => {
window.top.postMessage({id: id, result: 'error: ' + e.toString()}, '*'); window.top.postMessage({id: id, result: 'error: ' + e.toString()}, '*');
}); });
}; };
......
import os.path
def main(request, response):
header = [('Content-Type', 'text/html')]
if 'test' in request.GET:
with open(os.path.join(os.path.dirname(__file__),'blank.html'), 'r') as f:
body = f.read()
return (header, body)
with open(os.path.join(os.path.dirname(__file__),
'sandboxed-iframe-fetch-event-iframe.html'), 'r') as f:
body = f.read()
return (header, body)
...@@ -10,6 +10,7 @@ self.addEventListener('message', function(event) { ...@@ -10,6 +10,7 @@ self.addEventListener('message', function(event) {
client_urls = client_urls.sort(); client_urls = client_urls.sort();
event.data.port.postMessage( event.data.port.postMessage(
{clients: client_urls, requests: requests}); {clients: client_urls, requests: requests});
requests = [];
})); }));
}); });
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment