Skip to content

Commit e69c4a9

Browse files
targosruyadorno
authored andcommitted
test: add wpt tests for Blob
PR-URL: #36811 Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
1 parent 775b34b commit e69c4a9

File tree

92 files changed

+5272
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

92 files changed

+5272
-0
lines changed

test/fixtures/wpt/FileAPI/BlobURL/support/file_test2.txt

Whitespace-only changes.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<meta charset="utf-8">
5+
<title>Blob and File reference URL Test(2)</title>
6+
<link rel=help href="http://dev.w3.org/2006/webapi/FileAPI/#convenienceAPI">
7+
<link rel=author title="Breezewish" href="mailto:me@breeswish.org">
8+
<script src="/resources/testharness.js"></script>
9+
<script src="/resources/testharnessreport.js"></script>
10+
</head>
11+
<body>
12+
<form name="upload">
13+
<input type="file" id="fileChooser"><br><input type="button" id="start" value="start">
14+
</form>
15+
16+
<div>
17+
<p>Test steps:</p>
18+
<ol>
19+
<li>Download the <a href="support/file_test2.txt">file</a>.</li>
20+
<li>Select the file in the file inputbox.</li>
21+
<li>Delete the file.</li>
22+
<li>Click the 'start' button.</li>
23+
</ol>
24+
</div>
25+
26+
<div id="log"></div>
27+
28+
<script>
29+
30+
var fileChooser = document.querySelector('#fileChooser');
31+
32+
setup({explicit_done: true});
33+
setup({explicit_timeout: true});
34+
35+
on_event(document.querySelector('#start'), 'click', function() {
36+
37+
async_test(function(t) {
38+
39+
var url = URL.createObjectURL(fileChooser.files[0]);
40+
41+
var xhr = new XMLHttpRequest();
42+
xhr.open('GET', url, true);
43+
xhr.onreadystatechange = t.step_func(function() {
44+
switch (xhr.readyState) {
45+
case xhr.DONE:
46+
assert_equals(xhr.status, 500, 'status code should be 500.');
47+
t.done();
48+
return;
49+
}
50+
});
51+
52+
xhr.send();
53+
54+
}, 'Check whether the browser response 500 in XHR if the selected file which File/Blob URL refered is not found');
55+
56+
done();
57+
58+
});
59+
60+
</script>
61+
</body>
62+
</html>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<!DOCTYPE html>
2+
<meta charset="utf-8">
3+
<title>File API Test: Progress Event - bubbles, cancelable</title>
4+
<link rel="author" title="Intel" href="http://www.intel.com">
5+
<link rel="help" href="http://www.w3.org/TR/FileAPI/#events">
6+
<script src="/resources/testharness.js"></script>
7+
<script src="/resources/testharnessreport.js"></script>
8+
<div id="log"></div>
9+
<script>
10+
async_test(function(){
11+
var blob = new Blob(["TEST"]);
12+
var reader = new FileReader();
13+
14+
reader.onloadstart = this.step_func(function(evt) {
15+
assert_false(evt.bubbles, "The bubbles must be false when the event is dispatched");
16+
assert_false(evt.cancelable, "The cancelable must be false when the event is dispatched");
17+
});
18+
19+
reader.onload = this.step_func(function(evt) {
20+
assert_false(evt.bubbles, "The bubbles must be false when the event is dispatched");
21+
assert_false(evt.cancelable, "The cancelable must be false when the event is dispatched");
22+
});
23+
24+
reader.onloadend = this.step_func(function(evt) {
25+
assert_false(evt.bubbles, "The bubbles must be false when the event is dispatched");
26+
assert_false(evt.cancelable, "The cancelable must be false when the event is dispatched");
27+
this.done();
28+
});
29+
30+
reader.readAsText(blob);
31+
}, "Check the values of bubbles and cancelable are false when the progress event is dispatched");
32+
</script>
33+

test/fixtures/wpt/FileAPI/FileReader/support/file_test1.txt

Whitespace-only changes.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<meta charset="utf-8">
5+
<title>FileReader Errors Test</title>
6+
<link rel=help href="http://dev.w3.org/2006/webapi/FileAPI/#convenienceAPI">
7+
<link rel=author title="Breezewish" href="mailto:me@breeswish.org">
8+
<script src="/resources/testharness.js"></script>
9+
<script src="/resources/testharnessreport.js"></script>
10+
</head>
11+
<body>
12+
<form name="upload">
13+
<input type="file" id="fileChooser"><br><input type="button" id="start" value="start">
14+
</form>
15+
16+
<div>
17+
<p>Test steps:</p>
18+
<ol>
19+
<li>Download the <a href="support/file_test1.txt">file</a>.</li>
20+
<li>Select the file in the file inputbox.</li>
21+
<li>Delete the file.</li>
22+
<li>Click the 'start' button.</li>
23+
</ol>
24+
</div>
25+
26+
<div id="log"></div>
27+
28+
<script>
29+
30+
var fileChooser = document.querySelector('#fileChooser');
31+
32+
setup({explicit_done: true});
33+
setup({explicit_timeout: true});
34+
35+
on_event(fileChooser, 'change', function() {
36+
37+
async_test(function(t) {
38+
39+
var reader = new FileReader();
40+
reader.readAsArrayBuffer(fileChooser.files[0]);
41+
42+
reader.onloadend = t.step_func_done(function(event) {
43+
assert_equals(event.target.readyState, FileReader.DONE);
44+
assert_equals(reader.error, null);
45+
});
46+
47+
}, 'FileReader.error should be null if there are no errors when reading');
48+
49+
});
50+
51+
on_event(document.querySelector('#start'), 'click', function() {
52+
53+
async_test(function(t) {
54+
55+
var reader = new FileReader();
56+
reader.readAsArrayBuffer(fileChooser.files[0]);
57+
58+
reader.onloadend = t.step_func_done(function(event) {
59+
assert_equals(event.target.readyState, FileReader.DONE);
60+
assert_equals(reader.error.code, 8);
61+
assert_true(reader.error instanceof DOMException);
62+
});
63+
64+
}, 'FileReader.error should be NOT_FOUND_ERR if the file is not found when reading');
65+
66+
done();
67+
68+
});
69+
70+
</script>
71+
</body>
72+
</html>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<!DOCTYPE html>
2+
<meta charset="utf-8">
3+
<title>FileReader NotReadableError Test</title>
4+
<link rel="author" title="Intel" href="http://www.intel.com">
5+
<link rel="help" href="https://w3c.github.io/FileAPI/#dfn-error-codes">
6+
<script src="/resources/testharness.js"></script>
7+
<script src="/resources/testharnessreport.js"></script>
8+
<form name="upload">
9+
<input type="file" id="fileChooser"><br><input type="button" id="start" value="start">
10+
</form>
11+
12+
<div>
13+
<p>Test steps:</p>
14+
<ol>
15+
<li>Download the <a href="support/file_test1.txt">file</a>.</li>
16+
<li>Select the file in the file inputbox.</li>
17+
<li>Delete the file's readable permission.</li>
18+
<li>Click the 'start' button.</li>
19+
</ol>
20+
</div>
21+
22+
<script>
23+
24+
const fileChooser = document.querySelector('#fileChooser');
25+
26+
setup({explicit_done: true});
27+
setup({explicit_timeout: true});
28+
29+
on_event(document.querySelector('#start'), 'click', () => {
30+
async_test(t => {
31+
const reader = new FileReader();
32+
reader.readAsArrayBuffer(fileChooser.files[0]);
33+
reader.onloadend = t.step_func_done(event => {
34+
assert_equals(event.target.readyState, FileReader.DONE);
35+
assert_equals(reader.error.name, "NotReadableError");
36+
});
37+
}, 'FileReader.error should be NotReadableError if the file is unreadable');
38+
done();
39+
});
40+
41+
</script>
42+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<!DOCTYPE html>
2+
<meta charset="utf-8">
3+
<title>FileReader SecurityError Test</title>
4+
<link rel="author" title="Intel" href="http://www.intel.com">
5+
<link rel="help" href="https://w3c.github.io/FileAPI/#dfn-error-codes">
6+
<script src="/resources/testharness.js"></script>
7+
<script src="/resources/testharnessreport.js"></script>
8+
<form name="upload">
9+
<input type="file" id="fileChooser"><br><input type="button" id="start" value="start">
10+
</form>
11+
12+
<div>
13+
<p>Test steps:</p>
14+
<ol>
15+
<li>Select a system sensitive file (e.g. files in /usr/bin, password files,
16+
and other native operating system executables) in the file inputbox.</li>
17+
<li>Click the 'start' button.</li>
18+
</ol>
19+
</div>
20+
21+
<script>
22+
23+
const fileChooser = document.querySelector('#fileChooser');
24+
25+
setup({explicit_done: true});
26+
setup({explicit_timeout: true});
27+
28+
on_event(document.querySelector('#start'), 'click', () => {
29+
async_test(t => {
30+
const reader = new FileReader();
31+
reader.readAsArrayBuffer(fileChooser.files[0]);
32+
reader.onloadend = t.step_func_done(event => {
33+
assert_equals(event.target.readyState, FileReader.DONE);
34+
assert_equals(reader.error.name, "SecurityError");
35+
});
36+
}, 'FileReader.error should be SECURITY_ERROR if the file is a system sensitive file');
37+
done();
38+
});
39+
40+
</script>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<!DOCTYPE html>
2+
<meta charset=utf-8>
3+
<script src="/resources/testharness.js"></script>
4+
<script src="/resources/testharnessreport.js"></script>
5+
<script>
6+
7+
async_test(t => {
8+
function workerCode() {
9+
close();
10+
var blob = new Blob([123]);
11+
var fr = new FileReader();
12+
fr.readAsText(blob);
13+
fr.abort()
14+
fr.readAsArrayBuffer(blob);
15+
postMessage(true);
16+
}
17+
18+
var workerBlob = new Blob([workerCode.toString() + ";workerCode();"], {type:"application/javascript"});
19+
20+
var w = new Worker(URL.createObjectURL(workerBlob));
21+
w.onmessage = function(e) {
22+
assert_true(e.data, "FileReader created during worker shutdown.");
23+
t.done();
24+
}
25+
}, 'FileReader created after a worker self.close()');
26+
27+
</script>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
importScripts("/resources/testharness.js");
2+
3+
var blob, empty_blob, readerSync;
4+
setup(() => {
5+
readerSync = new FileReaderSync();
6+
blob = new Blob(["test"]);
7+
empty_blob = new Blob();
8+
});
9+
10+
test(() => {
11+
assert_true(readerSync instanceof FileReaderSync);
12+
}, "Interface");
13+
14+
test(() => {
15+
var text = readerSync.readAsText(blob);
16+
assert_equals(text, "test");
17+
}, "readAsText");
18+
19+
test(() => {
20+
var text = readerSync.readAsText(empty_blob);
21+
assert_equals(text, "");
22+
}, "readAsText with empty blob");
23+
24+
test(() => {
25+
var data = readerSync.readAsDataURL(blob);
26+
assert_equals(data.indexOf("data:"), 0);
27+
}, "readAsDataURL");
28+
29+
test(() => {
30+
var data = readerSync.readAsDataURL(empty_blob);
31+
assert_equals(data.indexOf("data:"), 0);
32+
}, "readAsDataURL with empty blob");
33+
34+
test(() => {
35+
var data = readerSync.readAsBinaryString(blob);
36+
assert_equals(data, "test");
37+
}, "readAsBinaryString");
38+
39+
test(() => {
40+
var data = readerSync.readAsBinaryString(empty_blob);
41+
assert_equals(data, "");
42+
}, "readAsBinaryString with empty blob");
43+
44+
test(() => {
45+
var data = readerSync.readAsArrayBuffer(blob);
46+
assert_true(data instanceof ArrayBuffer);
47+
assert_equals(data.byteLength, "test".length);
48+
}, "readAsArrayBuffer");
49+
50+
test(() => {
51+
var data = readerSync.readAsArrayBuffer(empty_blob);
52+
assert_true(data instanceof ArrayBuffer);
53+
assert_equals(data.byteLength, 0);
54+
}, "readAsArrayBuffer with empty blob");
55+
56+
done();

test/fixtures/wpt/FileAPI/META.yml

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
spec: https://w3c.github.io/FileAPI/
2+
suggested_reviewers:
3+
- inexorabletash
4+
- zqzhang
5+
- jdm
6+
- mkruisselbrink
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
// META: title=Blob Array Buffer
2+
// META: script=../support/Blob.js
3+
'use strict';
4+
5+
promise_test(async () => {
6+
const input_arr = new TextEncoder().encode("PASS");
7+
const blob = new Blob([input_arr]);
8+
const array_buffer = await blob.arrayBuffer();
9+
assert_true(array_buffer instanceof ArrayBuffer);
10+
assert_equals_typed_array(new Uint8Array(array_buffer), input_arr);
11+
}, "Blob.arrayBuffer()")
12+
13+
promise_test(async () => {
14+
const input_arr = new TextEncoder().encode("");
15+
const blob = new Blob([input_arr]);
16+
const array_buffer = await blob.arrayBuffer();
17+
assert_true(array_buffer instanceof ArrayBuffer);
18+
assert_equals_typed_array(new Uint8Array(array_buffer), input_arr);
19+
}, "Blob.arrayBuffer() empty Blob data")
20+
21+
promise_test(async () => {
22+
const input_arr = new TextEncoder().encode("\u08B8\u000a");
23+
const blob = new Blob([input_arr]);
24+
const array_buffer = await blob.arrayBuffer();
25+
assert_equals_typed_array(new Uint8Array(array_buffer), input_arr);
26+
}, "Blob.arrayBuffer() non-ascii input")
27+
28+
promise_test(async () => {
29+
const input_arr = [8, 241, 48, 123, 151];
30+
const typed_arr = new Uint8Array(input_arr);
31+
const blob = new Blob([typed_arr]);
32+
const array_buffer = await blob.arrayBuffer();
33+
assert_equals_typed_array(new Uint8Array(array_buffer), typed_arr);
34+
}, "Blob.arrayBuffer() non-unicode input")
35+
36+
promise_test(async () => {
37+
const input_arr = new TextEncoder().encode("PASS");
38+
const blob = new Blob([input_arr]);
39+
const array_buffer_results = await Promise.all([blob.arrayBuffer(),
40+
blob.arrayBuffer(), blob.arrayBuffer()]);
41+
for (let array_buffer of array_buffer_results) {
42+
assert_true(array_buffer instanceof ArrayBuffer);
43+
assert_equals_typed_array(new Uint8Array(array_buffer), input_arr);
44+
}
45+
}, "Blob.arrayBuffer() concurrent reads")

0 commit comments

Comments
 (0)