Update web-platform-tests to revision c26470dac73f2df9d4822a0d3482f7eb1ebf57d9

This commit is contained in:
Anthony Ramine 2018-01-10 14:28:20 +01:00
parent 7de87c487b
commit 4d3c932c47
648 changed files with 9014 additions and 4821 deletions

View file

@ -1,66 +0,0 @@
<!doctype html>
<meta charset="utf-8">
<title>FileAPI Test: Creating Blob URL with Blob</title>
<link rel="author" title="Victor Costan" href="mailto:pwnall@chromium.org">
<link rel="help" href="https://w3c.github.io/FileAPI/#originOfBlobURL">
<link rel="help" href="https://html.spec.whatwg.org/multipage/browsers.html#concept-origin">
<link rel="help" href="https://url.spec.whatwg.org/#url-parsing">
<link rel="help" href="https://fetch.spec.whatwg.org/#main-fetch">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<style>
iframe { width: 10px; height: 10px; }
</style>
<iframe id="unconstrained-iframe"></iframe>
<iframe id="sandboxed-iframe" sandbox="allow-scripts"></iframe>
<script id="iframe-srcdoc" language="text/html">
<!doctype html>
<script>
'use strict';
window.onload = () => {
const blob = new Blob(['Hello world!']);
const blobUrl = URL.createObjectURL(blob);
fetch(blobUrl).then(response => response.text()).then(text => {
window.parent.postMessage({ blobUrl, text }, '*');
});
};
// The script tag is closed in readBlobFromUrl().
</script>
<script>
// Carries out the test of minting a Blob URL in an iframe, and reading it back.
//
// Returns a promise resolved with an object with properties blobUrl and text
// (the text read back from the Blob URL).
function readBlobFromUrl(t, iframeSelector) {
return new Promise((resolve, reject) => {
window.onmessage = t.step_func((message) => { resolve(message.data); });
const frame = document.querySelector(iframeSelector);
const html = document.querySelector('#iframe-srcdoc').textContent +
'<' + '/script>';
frame.setAttribute('srcdoc', html);
});
}
promise_test(t => readBlobFromUrl(t, '#unconstrained-iframe').then(data => {
assert_true(data.blobUrl.startsWith('blob:'),
"The Blob's URL should use the blob: scheme");
assert_equals(data.text, 'Hello world!',
"The result of reading the Blob's URL should be the Blob's contents");
}), 'reading a Blob URL in an unconstrained iframe');
promise_test(t => readBlobFromUrl(t, '#sandboxed-iframe').then(data => {
assert_true(data.blobUrl.startsWith('blob:'),
"The Blob's URL should use the blob: scheme");
assert_equals(data.text, 'Hello world!',
"The result of reading the Blob's URL should be the Blob's contents");
}), 'reading a Blob URL in a sandboxed iframe without the same-origin flag');
</script>

View file

@ -0,0 +1,61 @@
<!doctype html>
<meta charset="utf-8">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<body>
<script>
async_test(t => {
const blob_contents = 'test blob contents';
const blob = new Blob([blob_contents]);
const url = URL.createObjectURL(blob);
const frame = document.createElement('iframe');
frame.setAttribute('style', 'display:none;');
frame.src = 'resources/revoke-helper.html';
document.body.appendChild(frame);
frame.onload = t.step_func(e => {
frame.contentWindow.postMessage({url: url}, '*');
});
self.addEventListener('message', t.step_func(e => {
if (e.source !== frame.contentWindow) return;
assert_equals(e.data, 'revoked');
promise_rejects(t, new TypeError, fetch(url)).then(t.step_func_done());
}));
}, 'It is possible to revoke same-origin blob URLs from different frames.');
async_test(t => {
const blob_contents = 'test blob contents';
const blob = new Blob([blob_contents]);
const url = URL.createObjectURL(blob);
const worker = new Worker('resources/revoke-helper.js');
worker.onmessage = t.step_func(e => {
assert_equals(e.data, 'revoked');
promise_rejects(t, new TypeError, fetch(url)).then(t.step_func_done());
});
worker.postMessage({url: url});
}, 'It is possible to revoke same-origin blob URLs from a different worker global.');
async_test(t => {
const blob_contents = 'test blob contents';
const blob = new Blob([blob_contents]);
const url = URL.createObjectURL(blob);
const frame = document.createElement('iframe');
frame.setAttribute('style', 'display:none;');
frame.src = '//{{domains[www1]}}:{{location[port]}}/FileAPI/url/resources/revoke-helper.html';
document.body.appendChild(frame);
frame.onload = t.step_func(e => {
frame.contentWindow.postMessage({url: url}, '*');
});
self.addEventListener('message', t.step_func(e => {
if (e.source !== frame.contentWindow) return;
assert_equals(e.data, 'revoked');
fetch(url).then(response => response.text()).then(t.step_func_done(text => {
assert_equals(text, blob_contents);
}), t.unreached_func('Unexpected promise rejection'));
}));
}, 'It is not possible to revoke cross-origin blob URLs.');
</script>

View file

@ -0,0 +1,7 @@
<!doctype html>
<script>
self.addEventListener('message', e => {
let url = URL.createObjectURL(e.data.blob);
e.source.postMessage({url: url}, '*');
});
</script>

View file

@ -0,0 +1,4 @@
self.addEventListener('message', e => {
let url = URL.createObjectURL(e.data.blob);
self.postMessage({url: url});
});

View file

@ -0,0 +1,71 @@
// This method generates a number of tests verifying fetching of blob URLs,
// allowing the same tests to be used both with fetch() and XMLHttpRequest.
//
// |fetch_method| is only used in test names, and should describe the
// (javascript) method being used by the other two arguments (i.e. 'fetch' or 'XHR').
//
// |fetch_should_succeed| is a callback that is called with the Test and a URL.
// Fetching the URL is expected to succeed. The callback should return a promise
// resolved with whatever contents were fetched.
//
// |fetch_should_fail| similarly is a callback that is called with the Test, a URL
// to fetch, and optionally a method to use to do the fetch. If no method is
// specified the callback should use the 'GET' method. Fetching of these URLs is
// expected to fail, and the callback should return a promise that resolves iff
// fetching did indeed fail.
function fetch_tests(fetch_method, fetch_should_succeed, fetch_should_fail) {
const blob_contents = 'test blob contents';
const blob = new Blob([blob_contents]);
promise_test(t => {
const url = URL.createObjectURL(blob);
return fetch_should_succeed(t, url).then(text => {
assert_equals(text, blob_contents);
});
}, 'Blob URLs can be used in ' + fetch_method);
promise_test(t => {
const url = URL.createObjectURL(blob);
return fetch_should_succeed(t, url + '#fragment').then(text => {
assert_equals(text, blob_contents);
});
}, fetch_method + ' with a fragment should succeed');
promise_test(t => {
const url = URL.createObjectURL(blob);
URL.revokeObjectURL(url);
return fetch_should_fail(t, url);
}, fetch_method + ' of a revoked URL should fail');
promise_test(t => {
const url = URL.createObjectURL(blob);
URL.revokeObjectURL(url + '#fragment');
return fetch_should_succeed(t, url).then(text => {
assert_equals(text, blob_contents);
});
}, 'Only exact matches should revoke URLs, using ' + fetch_method);
promise_test(t => {
const url = URL.createObjectURL(blob);
return fetch_should_fail(t, url + '?querystring');
}, 'Appending a query string should cause ' + fetch_method + ' to fail');
promise_test(t => {
const url = URL.createObjectURL(blob);
return fetch_should_fail(t, url + '/path');
}, 'Appending a path should cause ' + fetch_method + ' to fail');
for (const method of ['HEAD', 'POST', 'DELETE', 'OPTIONS', 'PUT', 'CUSTOM']) {
const url = URL.createObjectURL(blob);
promise_test(t => {
return fetch_should_fail(t, url, method);
}, fetch_method + ' with method "' + method + '" should fail');
}
}

View file

@ -0,0 +1,7 @@
<!doctype html>
<script>
self.addEventListener('message', e => {
URL.revokeObjectURL(e.data.url);
e.source.postMessage('revoked', '*');
});
</script>

View file

@ -0,0 +1,4 @@
self.addEventListener('message', e => {
URL.revokeObjectURL(e.data.url);
self.postMessage('revoked');
});

View file

@ -0,0 +1,30 @@
<!doctype html>
<meta charset="utf-8">
<title>FileAPI Test: Verify behavior of Blob URL in unique origins</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<iframe id="sandboxed-iframe" sandbox="allow-scripts"></iframe>
<script>
const iframe_scripts = [
'/resources/testharness.js',
'resources/fetch-tests.js',
'url-format.any.js',
'url-with-xhr.any.js',
'url-with-fetch.any.js',
'url-with-tags.window.js',
];
let html = '<!doctype html>\n<meta charset="utf-8">\n<body>\n';
for (const script of iframe_scripts)
html = html + '<script src="' + script + '"></' + 'script>\n';
const frame = document.querySelector('#sandboxed-iframe');
frame.setAttribute('srcdoc', html);
frame.setAttribute('style', 'display:none;');
fetch_tests_from_window(frame.contentWindow);
</script>

View file

@ -5,14 +5,6 @@
<script src="/resources/testharnessreport.js"></script>
<body>
<script>
test(t => {
const blob = new Blob(["Test Blob"]);
const url = URL.createObjectURL(blob);
assert_equals(new URL(url).origin, location.origin);
assert_true(url.includes(location.origin));
assert_true(url.startsWith('blob:{{location[scheme]}}://'));
}, 'Verify origin of Blob URI matches our origin');
async_test(t => {
const frame = document.createElement('iframe');
self.addEventListener('message', t.step_func(e => {

View file

@ -0,0 +1,63 @@
const blob = new Blob(['test']);
const file = new File(['test'], 'name');
test(() => {
const url_count = 10000;
let list = [];
for (let i = 0; i < url_count; ++i)
list.push(URL.createObjectURL(blob));
list.sort();
for (let i = 1; i < list.length; ++i)
assert_not_equals(list[i], list[i-1], 'generated Blob URLs should be unique');
}, 'Generated Blob URLs are unique');
test(() => {
const url = URL.createObjectURL(blob);
assert_equals(typeof url, 'string');
assert_true(url.startsWith('blob:'));
}, 'Blob URL starts with "blob:"');
test(() => {
const url = URL.createObjectURL(file);
assert_equals(typeof url, 'string');
assert_true(url.startsWith('blob:'));
}, 'Blob URL starts with "blob:" for Files');
test(() => {
const url = URL.createObjectURL(blob);
assert_equals(new URL(url).origin, location.origin);
if (location.origin !== 'null') {
assert_true(url.includes(location.origin));
assert_true(url.startsWith('blob:' + location.protocol));
}
}, 'Origin of Blob URL matches our origin');
test(() => {
const url = URL.createObjectURL(blob);
const url_record = new URL(url);
assert_equals(url_record.protocol, 'blob:');
assert_equals(url_record.origin, location.origin);
assert_equals(url_record.host, '', 'host should be an empty string');
assert_equals(url_record.port, '', 'port should be an empty string');
const uuid_path_re = /\/[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;
assert_true(uuid_path_re.test(url_record.pathname), 'Path must end with a valid UUID');
if (location.origin !== 'null') {
const nested_url = new URL(url_record.pathname);
assert_equals(nested_url.origin, location.origin);
assert_equals(nested_url.pathname.search(uuid_path_re), 0, 'Path must be a valid UUID');
assert_true(url.includes(location.origin));
assert_true(url.startsWith('blob:' + location.protocol));
}
}, 'Blob URL parses correctly');
test(() => {
const url = URL.createObjectURL(file);
assert_equals(new URL(url).origin, location.origin);
if (location.origin !== 'null') {
assert_true(url.includes(location.origin));
assert_true(url.startsWith('blob:' + location.protocol));
}
}, 'Origin of Blob URL matches our origin for Files');

View file

@ -0,0 +1,50 @@
async_test(t => {
const run_result = 'test_script_OK';
const blob_contents = 'window.test_result = "' + run_result + '";';
const blob = new Blob([blob_contents]);
const url = URL.createObjectURL(blob);
const e = document.createElement('script');
e.setAttribute('src', url);
e.onload = t.step_func_done(() => {
assert_equals(window.test_result, run_result);
});
document.body.appendChild(e);
}, 'Blob URLs can be used in <script> tags');
async_test(t => {
const run_result = 'test_frame_OK';
const blob_contents = '<!doctype html>\n<meta charset="utf-8">\n' +
'<script>window.test_result = "' + run_result + '";</script>';
const blob = new Blob([blob_contents], {type: 'text/html'});
const url = URL.createObjectURL(blob);
const frame = document.createElement('iframe');
frame.setAttribute('src', url);
frame.setAttribute('style', 'display:none;');
document.body.appendChild(frame);
frame.onload = t.step_func_done(() => {
assert_equals(frame.contentWindow.test_result, run_result);
});
}, 'Blob URLs can be used in iframes, and are treated same origin');
async_test(t => {
const scroll_position = 5000;
const blob_contents = '<!doctype html>\n<meta charset="utf-8">\n' +
'<style>body { margin: 0; } .block { height: 5000px; }</style>\n' +
'<body>\n' +
'<a id="block1"></a><div class="block"></div>\n' +
'<a id="block2"></a><div class="block"></div>';
const blob = new Blob([blob_contents], {type: 'text/html'});
const url = URL.createObjectURL(blob);
const frame = document.createElement('iframe');
frame.setAttribute('src', url + '#block2');
document.body.appendChild(frame);
frame.onload = t.step_func_done(() => {
assert_equals(frame.contentWindow.scrollY, 5000);
});
}, 'Blob URL fragment is implemented.');

View file

@ -0,0 +1,56 @@
<!doctype html>
<meta charset="utf-8">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<body>
<script>
promise_test(t => {
const blob_contents = 'test blob contents';
const blob = new Blob([blob_contents]);
const worker = new Worker('resources/create-helper.js');
let url;
return new Promise(resolve => {
worker.onmessage = e => resolve(e.data);
worker.postMessage({blob: blob});
}).then(data => {
url = data.url;
let result = fetch(url);
worker.terminate();
return result;
}).then(response => response.text()).then(text => {
assert_equals(text, blob_contents);
return new Promise(resolve => t.step_timeout(resolve, 100));
}).then(() => promise_rejects(t, new TypeError, fetch(url)));
}, 'Terminating worker revokes its URLs');
promise_test(t => {
const blob_contents = 'test blob contents';
const blob = new Blob([blob_contents]);
const frame = document.createElement('iframe');
frame.setAttribute('style', 'display:none;');
frame.src = 'resources/create-helper.html';
document.body.appendChild(frame);
let url;
return new Promise(resolve => {
frame.onload = t.step_func(e => {
resolve(e);
});
}).then(e => {
frame.contentWindow.postMessage({blob: blob}, '*');
return new Promise(resolve => {
self.addEventListener('message', t.step_func(e => {
if (e.source === frame.contentWindow) resolve(e);
}));
});
}).then(e => {
url = e.data.url;
let fetch_result = fetch(url);
document.body.removeChild(frame);
return fetch_result;
}).then(response => response.text()).then(text => {
assert_equals(text, blob_contents);
return new Promise(resolve => t.step_timeout(resolve, 100));
}).then(() => promise_rejects(t, new TypeError, fetch(url)));
}, 'Removing an iframe revokes its URLs');
</script>

View file

@ -0,0 +1,53 @@
// META: script=resources/fetch-tests.js
function fetch_should_succeed(test, request) {
return fetch(request).then(response => response.text());
}
function fetch_should_fail(test, url, method = 'GET') {
return promise_rejects(test, new TypeError, fetch(url, {method: method}));
}
fetch_tests('fetch', fetch_should_succeed, fetch_should_fail);
promise_test(t => {
const blob_contents = 'test blob contents';
const blob_type = 'image/png';
const blob = new Blob([blob_contents], {type: blob_type});
const url = URL.createObjectURL(blob);
return fetch(url).then(response => {
assert_equals(response.headers.get('Content-Type'), blob_type);
});
}, 'fetch should return Content-Type from Blob');
promise_test(t => {
const blob_contents = 'test blob contents';
const blob = new Blob([blob_contents]);
const url = URL.createObjectURL(blob);
const request = new Request(url);
// Revoke the object URL. Request should take a reference to the blob as
// soon as it receives it in open(), so the request succeeds even though we
// revoke the URL before calling fetch().
URL.revokeObjectURL(url);
return fetch_should_succeed(t, request).then(text => {
assert_equals(text, blob_contents);
});
}, 'Revoke blob URL after creating Request, will fetch');
promise_test(function(t) {
const blob_contents = 'test blob contents';
const blob = new Blob([blob_contents]);
const url = URL.createObjectURL(blob);
const result = fetch_should_succeed(t, url).then(text => {
assert_equals(text, blob_contents);
});
// Revoke the object URL. fetch should have already resolved the blob URL.
URL.revokeObjectURL(url);
return result;
}, 'Revoke blob URL after calling fetch, fetch should succeed');

View file

@ -0,0 +1,68 @@
// META: script=resources/fetch-tests.js
function xhr_should_succeed(test, url) {
return new Promise((resolve, reject) => {
const xhr = new XMLHttpRequest();
xhr.open('GET', url);
xhr.onload = test.step_func(() => {
assert_equals(xhr.status, 200);
assert_equals(xhr.statusText, 'OK');
resolve(xhr.response);
});
xhr.onerror = () => reject('Got unexpected error event');
xhr.send();
});
}
function xhr_should_fail(test, url, method = 'GET') {
const xhr = new XMLHttpRequest();
xhr.open(method, url);
const result1 = new Promise((resolve, reject) => {
xhr.onload = () => reject('Got unexpected load event');
xhr.onerror = resolve;
});
const result2 = new Promise(resolve => {
xhr.onreadystatechange = test.step_func(() => {
if (xhr.readyState !== xhr.DONE) return;
assert_equals(xhr.status, 0);
resolve();
});
});
xhr.send();
return Promise.all([result1, result2]);
}
fetch_tests('XHR', xhr_should_succeed, xhr_should_fail);
async_test(t => {
const blob_contents = 'test blob contents';
const blob_type = 'image/png';
const blob = new Blob([blob_contents], {type: blob_type});
const url = URL.createObjectURL(blob);
const xhr = new XMLHttpRequest();
xhr.open('GET', url);
xhr.onloadend = t.step_func_done(() => {
assert_equals(xhr.getResponseHeader('Content-Type'), blob_type);
});
xhr.send();
}, 'XHR should return Content-Type from Blob');
async_test(t => {
const blob_contents = 'test blob contents';
const blob = new Blob([blob_contents]);
const url = URL.createObjectURL(blob);
const xhr = new XMLHttpRequest();
xhr.open('GET', url);
// Revoke the object URL. XHR should take a reference to the blob as soon as
// it receives it in open(), so the request succeeds even though we revoke the
// URL before calling send().
URL.revokeObjectURL(url);
xhr.onload = t.step_func_done(() => {
assert_equals(xhr.response, blob_contents);
});
xhr.onerror = t.unreached_func('Got unexpected error event');
xhr.send();
}, 'Revoke blob URL after open(), will fetch');

View file

@ -1,20 +0,0 @@
<!DOCTYPE html>
<meta charset="utf-8">
<title>FileAPI Test: Creating Blob URL with Blob</title>
<link rel="author" title="Intel" href="http://www.intel.com">
<link rel="author" title="JunChen Xia" href="mailto:xjconlyme@gmail.com">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<div id="log"></div>
<script>
var blob = new Blob(["Test Blob"]);
test(function() {
var testBlob = window.URL.createObjectURL(blob);
assert_equals(typeof testBlob, "string", "Blob URI is typeof string");
assert_equals(testBlob.indexOf("blob"), 0, "Blob URI starts with 'blob'");
}, "Check if the Blob URI starts with 'blob' using createObjectURL()");
</script>

View file

@ -1,29 +0,0 @@
<!DOCTYPE html>
<meta charset="utf-8">
<title>FileAPI Test: Creating Blob URL via XMLHttpRequest</title>
<link rel="author" title="Intel" href="http://www.intel.com">
<link rel="author" title="JunChen Xia" href="mailto:xjconlyme@gmail.com">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<div id="log"></div>
<script>
async_test(function () {
var http = new XMLHttpRequest();
http.open("GET", "/images/blue96x96.png", true);
http.responseType = "blob";
http.onloadend = this.step_func(function(evt) {
var blobURI = window.URL.createObjectURL(http.response);
assert_true(http.response instanceof Blob, "XMLHttpRequest returns instanceof Blob");
assert_equals(typeof blobURI, "string", "Blob URI is typeof string");
assert_equals(blobURI.indexOf("blob"), 0, "Blob URI starts with 'blob'");
assert_equals(http.status, 200, "The status is 200");
assert_equals(http.statusText, "OK", "The status text is OK when XMLHttpRequest returns correct blob");
assert_equals(http.getResponseHeader("Content-Type"), "image/png", "The content type is image/png when set the respnose blob");
this.done();
});
http.send();
});
</script>