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 +0,0 @@
var test_result = 'test1_OK';

View file

@ -1,25 +0,0 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Test file</title>
<style>
body {
margin: 0;
}
.block {
height: 5000px;
}
</style>
<script>
window.test_result = 'test3_OK';
</script>
</head>
<body>
<a id="block1"></a>
<div class="block"></div>
<a id="block2"></a>
<div class="block"></div>
</body>
</html>

View file

@ -1,122 +0,0 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Blob and File reference URL Test(1)</title>
<link rel=help href="http://dev.w3.org/2006/webapi/FileAPI/#convenienceAPI">
<link rel=author title="Breezewish" href="mailto:me@breeswish.org">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
</head>
<body>
<form name="upload">
<input type="file" id="fileChooser">
</form>
<div>
<p>Test steps:</p>
<ol>
<li>Download the <a href="support/file_test1.js">file</a>.</li>
<li>Select the file in the file inputbox to run the test.</li>
</ol>
</div>
<div id="log"></div>
<script>
var fileChooser = document.querySelector('#fileChooser');
setup({explicit_done: true});
setup({explicit_timeout: true});
//Run the test when user selects a file
on_event(fileChooser, 'change', function() {
var testCount = 10000;
test(function() {
var list = [], file = fileChooser.files[0];
for (var i = 0; i <= testCount; i++) {
list.push(window.URL.createObjectURL(file));
}
list.sort();
for (var i = 0; i < testCount; i++) {
assert_not_equals(list[i], list[i+1], 'generated Blob URL should be unique');
}
}, 'Check whether generated Blob/File URL is unique (Notice: only generate for ' + testCount + ' times)');
async_test(function(t) {
var url = URL.createObjectURL(fileChooser.files[0]);
var expected_file_content = "var test_result = 'test1_OK';";
var xhr = new XMLHttpRequest();
xhr.open('GET', url, true);
xhr.onreadystatechange = t.step_func(function() {
switch (xhr.readyState) {
case xhr.DONE:
assert_equals(xhr.status, 200, 'status code should be 200');
assert_equals(xhr.responseText, expected_file_content);
t.done();
return;
}
});
xhr.send();
}, 'Check whether Blob/File URL could be used in XHR requests and could get expected data');
async_test(function(t) {
var url = URL.createObjectURL(fileChooser.files[0]);
var expected_run_result = "test1_OK";
//expected file content:
// var test_result = 'test1_OK';
var e = document.createElement('script');
e.setAttribute('type', 'text/javascript');
e.setAttribute('src', url);
e.onload = t.step_func_done(function() {
assert_equals(test_result, expected_run_result);
});
document.body.appendChild(e);
}, 'Check whether Blob/File URL could be used in tags src like <script>');
async_test(function(t) {
var url = URL.createObjectURL(fileChooser.files[0]);
URL.revokeObjectURL(url);
var xhr = new XMLHttpRequest();
xhr.open('GET', url, true);
xhr.onreadystatechange = t.step_func(function() {
switch (xhr.readyState) {
case xhr.DONE:
assert_equals(xhr.status, 500, 'status code should be 500 if Blob URI is revoked.');
t.done();
return;
}
});
xhr.send();
}, 'Check whether revokeObjectURL works well');
done();
});
</script>
</body>
</html>

View file

@ -1,71 +0,0 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Blob and File reference URL Test(3)</title>
<link rel=help href="http://dev.w3.org/2006/webapi/FileAPI/#convenienceAPI">
<link rel=author title="Breezewish" href="mailto:me@breeswish.org">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
</head>
<body>
<form name="upload">
<input type="file" id="fileChooser">
</form>
<div>
<p>Test steps:</p>
<ol>
<li>Download the <a href="support/file_test3.html">file</a>.</li>
<li>Select the file in the file inputbox and the test will start.</li>
</ol>
</div>
<div id="log"></div>
<script>
var fileChooser = document.querySelector('#fileChooser');
setup({explicit_done: true});
setup({explicit_timeout: true});
on_event(fileChooser, 'change', function() {
async_test(function(t) {
var url = URL.createObjectURL(fileChooser.files[0]);
var e = document.createElement('iframe');
e.setAttribute('src', url);
e.setAttribute('style', 'display:none;');
document.body.appendChild(e);
e.contentWindow.document.body.onload = t.step_func_done(function() {
assert_equals(e.contentWindow.test_result, 'test3_OK');
});
}, 'Check whether the iframe content could be accessed when using Blob/File URL in the same origin.');
async_test(function(t) {
var url = URL.createObjectURL(fileChooser.files[0]);
url += '#block2';
var e = document.createElement('iframe');
e.setAttribute('src', url);
document.body.appendChild(e);
e.contentWindow.document.body.onload = t.step_func_done(function() {
assert_equals(e.contentWindow.scrollY, 5000);
});
}, 'Check whether the Blob/File URL fragment is implemented.');
done();
});
</script>
</body>
</html>

View file

@ -0,0 +1,42 @@
<!DOCTYPE html>
<meta charset="utf-8">
<title>FileReader NotReadableError Test</title>
<link rel="author" title="Intel" href="http://www.intel.com">
<link rel="help" href="https://w3c.github.io/FileAPI/#dfn-error-codes">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<form name="upload">
<input type="file" id="fileChooser"><br><input type="button" id="start" value="start">
</form>
<div>
<p>Test steps:</p>
<ol>
<li>Download the <a href="support/file_test1.txt">file</a>.</li>
<li>Select the file in the file inputbox.</li>
<li>Delete the file's readable permission.</li>
<li>Click the 'start' button.</li>
</ol>
</div>
<script>
const fileChooser = document.querySelector('#fileChooser');
setup({explicit_done: true});
setup({explicit_timeout: true});
on_event(document.querySelector('#start'), 'click', () => {
async_test(t => {
const reader = new FileReader();
reader.readAsArrayBuffer(fileChooser.files[0]);
reader.onloadend = t.step_func_done(event => {
assert_equals(event.target.readyState, FileReader.DONE);
assert_equals(reader.error.name, "NotReadableError");
});
}, 'FileReader.error should be NotReadableError if the file is unreadable');
done();
});
</script>

View file

@ -0,0 +1,40 @@
<!DOCTYPE html>
<meta charset="utf-8">
<title>FileReader SecurityError Test</title>
<link rel="author" title="Intel" href="http://www.intel.com">
<link rel="help" href="https://w3c.github.io/FileAPI/#dfn-error-codes">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<form name="upload">
<input type="file" id="fileChooser"><br><input type="button" id="start" value="start">
</form>
<div>
<p>Test steps:</p>
<ol>
<li>Select a system sensitive file (e.g. files in /usr/bin, password files,
and other native operating system executables) in the file inputbox.</li>
<li>Click the 'start' button.</li>
</ol>
</div>
<script>
const fileChooser = document.querySelector('#fileChooser');
setup({explicit_done: true});
setup({explicit_timeout: true});
on_event(document.querySelector('#start'), 'click', () => {
async_test(t => {
const reader = new FileReader();
reader.readAsArrayBuffer(fileChooser.files[0]);
reader.onloadend = t.step_func_done(event => {
assert_equals(event.target.readyState, FileReader.DONE);
assert_equals(reader.error.name, "SecurityError");
});
}, 'FileReader.error should be SECURITY_ERROR if the file is a system sensitive file');
done();
});
</script>

View file

@ -1,41 +0,0 @@
<!doctype html>
<title>Revoking blob URL used with Request/fetch</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script>
promise_test(function(t) {
const blob = new Blob(["test"]);
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(request).then(response => response.text()).then(text => {
assert_equals(text, 'test');
});
}, "Revoke blob URL after creating Request, will fetch");
promise_test(function(t) {
const blob = new Blob(["test"]);
const url = URL.createObjectURL(blob);
return fetch(url).then(response => response.text()).then(text => {
assert_equals(text, 'test');
});
// Revoke the object URL. fetch should have already resolved the blob URL.
URL.revokeObjectURL(url);
}, "Revoke blob URL after fetch, will fetch");
promise_test(t => {
const blob = new Blob(["test"]);
const url = URL.createObjectURL(blob);
URL.revokeObjectURL(url);
const request = new Request(url);
return promise_rejects(t, new TypeError, fetch(request));
}, "Revoke blob URL before creating Request, network error (after fetch)")
</script>

View file

@ -1,38 +0,0 @@
<!doctype html>
<title>Revoking blob URL used with XMLHttpRequest</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script>
async_test(function(t) {
var blob = new Blob(["test"]);
var url = URL.createObjectURL(blob);
var 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.send();
xhr.onload = t.step_func_done(function() {
assert_equals(xhr.response, "test");
})
xhr.onerror = t.step_func(function() {
assert_unreached("Got unexpected error event");
})
}, "Revoke blob URL after open(), will fetch");
async_test(t => {
const blob = new Blob(["test"]),
blobURL = URL.createObjectURL(blob),
client = new XMLHttpRequest
URL.revokeObjectURL(blobURL)
client.open("GET", blobURL)
client.onload = t.step_func(() => assert_unreached("Got unexpected load event"))
client.onerror = t.step_func_done()
client.send()
}, "Revoke blob URL before open(), network error (after send())")
</script>

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>