summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/FileAPI/reading-data-section
diff options
context:
space:
mode:
Diffstat (limited to 'testing/web-platform/tests/FileAPI/reading-data-section')
-rw-r--r--testing/web-platform/tests/FileAPI/reading-data-section/Determining-Encoding.any.js81
-rw-r--r--testing/web-platform/tests/FileAPI/reading-data-section/FileReader-event-handler-attributes.any.js17
-rw-r--r--testing/web-platform/tests/FileAPI/reading-data-section/FileReader-multiple-reads.any.js81
-rw-r--r--testing/web-platform/tests/FileAPI/reading-data-section/filereader_abort.any.js38
-rw-r--r--testing/web-platform/tests/FileAPI/reading-data-section/filereader_error.any.js19
-rw-r--r--testing/web-platform/tests/FileAPI/reading-data-section/filereader_events.any.js19
-rw-r--r--testing/web-platform/tests/FileAPI/reading-data-section/filereader_file-manual.html69
-rw-r--r--testing/web-platform/tests/FileAPI/reading-data-section/filereader_file_img-manual.html47
-rw-r--r--testing/web-platform/tests/FileAPI/reading-data-section/filereader_readAsArrayBuffer.any.js23
-rw-r--r--testing/web-platform/tests/FileAPI/reading-data-section/filereader_readAsBinaryString.any.js23
-rw-r--r--testing/web-platform/tests/FileAPI/reading-data-section/filereader_readAsDataURL.any.js54
-rw-r--r--testing/web-platform/tests/FileAPI/reading-data-section/filereader_readAsText.any.js36
-rw-r--r--testing/web-platform/tests/FileAPI/reading-data-section/filereader_readystate.any.js19
-rw-r--r--testing/web-platform/tests/FileAPI/reading-data-section/filereader_result.any.js82
-rw-r--r--testing/web-platform/tests/FileAPI/reading-data-section/support/blue-100x100.pngbin0 -> 227 bytes
15 files changed, 608 insertions, 0 deletions
diff --git a/testing/web-platform/tests/FileAPI/reading-data-section/Determining-Encoding.any.js b/testing/web-platform/tests/FileAPI/reading-data-section/Determining-Encoding.any.js
new file mode 100644
index 0000000000..5b69f7ed98
--- /dev/null
+++ b/testing/web-platform/tests/FileAPI/reading-data-section/Determining-Encoding.any.js
@@ -0,0 +1,81 @@
+// META: title=FileAPI Test: Blob Determining Encoding
+
+var t = async_test("Blob Determing Encoding with encoding argument");
+t.step(function() {
+ // string 'hello'
+ var data = [0xFE,0xFF,0x00,0x68,0x00,0x65,0x00,0x6C,0x00,0x6C,0x00,0x6F];
+ var blob = new Blob([new Uint8Array(data)]);
+ var reader = new FileReader();
+
+ reader.onloadend = t.step_func_done (function(event) {
+ assert_equals(this.result, "hello", "The FileReader should read the ArrayBuffer through UTF-16BE.")
+ }, reader);
+
+ reader.readAsText(blob, "UTF-16BE");
+});
+
+var t = async_test("Blob Determing Encoding with type attribute");
+t.step(function() {
+ var data = [0xFE,0xFF,0x00,0x68,0x00,0x65,0x00,0x6C,0x00,0x6C,0x00,0x6F];
+ var blob = new Blob([new Uint8Array(data)], {type:"text/plain;charset=UTF-16BE"});
+ var reader = new FileReader();
+
+ reader.onloadend = t.step_func_done (function(event) {
+ assert_equals(this.result, "hello", "The FileReader should read the ArrayBuffer through UTF-16BE.")
+ }, reader);
+
+ reader.readAsText(blob);
+});
+
+
+var t = async_test("Blob Determing Encoding with UTF-8 BOM");
+t.step(function() {
+ var data = [0xEF,0xBB,0xBF,0x68,0x65,0x6C,0x6C,0xC3,0xB6];
+ var blob = new Blob([new Uint8Array(data)]);
+ var reader = new FileReader();
+
+ reader.onloadend = t.step_func_done (function(event) {
+ assert_equals(this.result, "hellö", "The FileReader should read the blob with UTF-8.");
+ }, reader);
+
+ reader.readAsText(blob);
+});
+
+var t = async_test("Blob Determing Encoding without anything implying charset.");
+t.step(function() {
+ var data = [0x68,0x65,0x6C,0x6C,0xC3,0xB6];
+ var blob = new Blob([new Uint8Array(data)]);
+ var reader = new FileReader();
+
+ reader.onloadend = t.step_func_done (function(event) {
+ assert_equals(this.result, "hellö", "The FileReader should read the blob by default with UTF-8.");
+ }, reader);
+
+ reader.readAsText(blob);
+});
+
+var t = async_test("Blob Determing Encoding with UTF-16BE BOM");
+t.step(function() {
+ var data = [0xFE,0xFF,0x00,0x68,0x00,0x65,0x00,0x6C,0x00,0x6C,0x00,0x6F];
+ var blob = new Blob([new Uint8Array(data)]);
+ var reader = new FileReader();
+
+ reader.onloadend = t.step_func_done (function(event) {
+ assert_equals(this.result, "hello", "The FileReader should read the ArrayBuffer through UTF-16BE.");
+ }, reader);
+
+ reader.readAsText(blob);
+});
+
+var t = async_test("Blob Determing Encoding with UTF-16LE BOM");
+t.step(function() {
+ var data = [0xFF,0xFE,0x68,0x00,0x65,0x00,0x6C,0x00,0x6C,0x00,0x6F,0x00];
+ var blob = new Blob([new Uint8Array(data)]);
+ var reader = new FileReader();
+
+ reader.onloadend = t.step_func_done (function(event) {
+ assert_equals(this.result, "hello", "The FileReader should read the ArrayBuffer through UTF-16LE.");
+ }, reader);
+
+ reader.readAsText(blob);
+});
diff --git a/testing/web-platform/tests/FileAPI/reading-data-section/FileReader-event-handler-attributes.any.js b/testing/web-platform/tests/FileAPI/reading-data-section/FileReader-event-handler-attributes.any.js
new file mode 100644
index 0000000000..fc71c64348
--- /dev/null
+++ b/testing/web-platform/tests/FileAPI/reading-data-section/FileReader-event-handler-attributes.any.js
@@ -0,0 +1,17 @@
+// META: title=FileReader event handler attributes
+
+var attributes = [
+ "onloadstart",
+ "onprogress",
+ "onload",
+ "onabort",
+ "onerror",
+ "onloadend",
+];
+attributes.forEach(function(a) {
+ test(function() {
+ var reader = new FileReader();
+ assert_equals(reader[a], null,
+ "event handler attribute should initially be null");
+ }, "FileReader." + a + ": initial value");
+});
diff --git a/testing/web-platform/tests/FileAPI/reading-data-section/FileReader-multiple-reads.any.js b/testing/web-platform/tests/FileAPI/reading-data-section/FileReader-multiple-reads.any.js
new file mode 100644
index 0000000000..4b19c69b42
--- /dev/null
+++ b/testing/web-platform/tests/FileAPI/reading-data-section/FileReader-multiple-reads.any.js
@@ -0,0 +1,81 @@
+// META: title=FileReader: starting new reads while one is in progress
+
+test(function() {
+ var blob_1 = new Blob(['TEST000000001'])
+ var blob_2 = new Blob(['TEST000000002'])
+ var reader = new FileReader();
+ reader.readAsText(blob_1)
+ assert_equals(reader.readyState, FileReader.LOADING, "readyState Must be LOADING")
+ assert_throws_dom("InvalidStateError", function () {
+ reader.readAsText(blob_2)
+ })
+}, 'test FileReader InvalidStateError exception for readAsText');
+
+test(function() {
+ var blob_1 = new Blob(['TEST000000001'])
+ var blob_2 = new Blob(['TEST000000002'])
+ var reader = new FileReader();
+ reader.readAsDataURL(blob_1)
+ assert_equals(reader.readyState, FileReader.LOADING, "readyState Must be LOADING")
+ assert_throws_dom("InvalidStateError", function () {
+ reader.readAsDataURL(blob_2)
+ })
+}, 'test FileReader InvalidStateError exception for readAsDataURL');
+
+test(function() {
+ var blob_1 = new Blob(['TEST000000001'])
+ var blob_2 = new Blob(['TEST000000002'])
+ var reader = new FileReader();
+ reader.readAsArrayBuffer(blob_1)
+ assert_equals(reader.readyState, FileReader.LOADING, "readyState Must be LOADING")
+ assert_throws_dom("InvalidStateError", function () {
+ reader.readAsArrayBuffer(blob_2)
+ })
+}, 'test FileReader InvalidStateError exception for readAsArrayBuffer');
+
+async_test(function() {
+ var blob_1 = new Blob(['TEST000000001'])
+ var blob_2 = new Blob(['TEST000000002'])
+ var reader = new FileReader();
+ var triggered = false;
+ reader.onloadstart = this.step_func_done(function() {
+ assert_false(triggered, "Only one loadstart event should be dispatched");
+ triggered = true;
+ assert_equals(reader.readyState, FileReader.LOADING,
+ "readyState must be LOADING")
+ assert_throws_dom("InvalidStateError", function () {
+ reader.readAsArrayBuffer(blob_2)
+ })
+ });
+ reader.readAsArrayBuffer(blob_1)
+ assert_equals(reader.readyState, FileReader.LOADING, "readyState Must be LOADING")
+}, 'test FileReader InvalidStateError exception in onloadstart event for readAsArrayBuffer');
+
+async_test(function() {
+ var blob_1 = new Blob(['TEST000000001'])
+ var blob_2 = new Blob(['TEST000000002'])
+ var reader = new FileReader();
+ reader.onloadend = this.step_func_done(function() {
+ assert_equals(reader.readyState, FileReader.DONE,
+ "readyState must be DONE")
+ reader.readAsArrayBuffer(blob_2)
+ assert_equals(reader.readyState, FileReader.LOADING, "readyState Must be LOADING")
+ });
+ reader.readAsArrayBuffer(blob_1)
+ assert_equals(reader.readyState, FileReader.LOADING, "readyState Must be LOADING")
+}, 'test FileReader no InvalidStateError exception in loadend event handler for readAsArrayBuffer');
+
+async_test(function() {
+ var blob_1 = new Blob([new Uint8Array(0x414141)]);
+ var blob_2 = new Blob(['TEST000000002']);
+ var reader = new FileReader();
+ reader.onloadstart = this.step_func(function() {
+ reader.abort();
+ reader.onloadstart = null;
+ reader.onloadend = this.step_func_done(function() {
+ assert_equals('TEST000000002', reader.result);
+ });
+ reader.readAsText(blob_2);
+ });
+ reader.readAsText(blob_1);
+}, 'test abort and restart in onloadstart event for readAsText');
diff --git a/testing/web-platform/tests/FileAPI/reading-data-section/filereader_abort.any.js b/testing/web-platform/tests/FileAPI/reading-data-section/filereader_abort.any.js
new file mode 100644
index 0000000000..c778ae55bb
--- /dev/null
+++ b/testing/web-platform/tests/FileAPI/reading-data-section/filereader_abort.any.js
@@ -0,0 +1,38 @@
+// META: title=FileAPI Test: filereader_abort
+
+ test(function() {
+ var readerNoRead = new FileReader();
+ readerNoRead.abort();
+ assert_equals(readerNoRead.readyState, readerNoRead.EMPTY);
+ assert_equals(readerNoRead.result, null);
+ }, "Aborting before read");
+
+ promise_test(t => {
+ var blob = new Blob(["TEST THE ABORT METHOD"]);
+ var readerAbort = new FileReader();
+
+ var eventWatcher = new EventWatcher(t, readerAbort,
+ ['abort', 'loadstart', 'loadend', 'error', 'load']);
+
+ // EventWatcher doesn't let us inspect the state after the abort event,
+ // so add an extra event handler for that.
+ readerAbort.addEventListener('abort', t.step_func(e => {
+ assert_equals(readerAbort.readyState, readerAbort.DONE);
+ }));
+
+ readerAbort.readAsText(blob);
+ return eventWatcher.wait_for('loadstart')
+ .then(() => {
+ assert_equals(readerAbort.readyState, readerAbort.LOADING);
+ // 'abort' and 'loadend' events are dispatched synchronously, so
+ // call wait_for before calling abort.
+ var nextEvent = eventWatcher.wait_for(['abort', 'loadend']);
+ readerAbort.abort();
+ return nextEvent;
+ })
+ .then(() => {
+ // https://www.w3.org/Bugs/Public/show_bug.cgi?id=24401
+ assert_equals(readerAbort.result, null);
+ assert_equals(readerAbort.readyState, readerAbort.DONE);
+ });
+ }, "Aborting after read");
diff --git a/testing/web-platform/tests/FileAPI/reading-data-section/filereader_error.any.js b/testing/web-platform/tests/FileAPI/reading-data-section/filereader_error.any.js
new file mode 100644
index 0000000000..9845962090
--- /dev/null
+++ b/testing/web-platform/tests/FileAPI/reading-data-section/filereader_error.any.js
@@ -0,0 +1,19 @@
+// META: title=FileAPI Test: filereader_error
+
+ async_test(function() {
+ var blob = new Blob(["TEST THE ERROR ATTRIBUTE AND ERROR EVENT"]);
+ var reader = new FileReader();
+ assert_equals(reader.error, null, "The error is null when no error occurred");
+
+ reader.onload = this.step_func(function(evt) {
+ assert_unreached("Should not dispatch the load event");
+ });
+
+ reader.onloadend = this.step_func(function(evt) {
+ assert_equals(reader.result, null, "The result is null");
+ this.done();
+ });
+
+ reader.readAsText(blob);
+ reader.abort();
+ });
diff --git a/testing/web-platform/tests/FileAPI/reading-data-section/filereader_events.any.js b/testing/web-platform/tests/FileAPI/reading-data-section/filereader_events.any.js
new file mode 100644
index 0000000000..ac692907d1
--- /dev/null
+++ b/testing/web-platform/tests/FileAPI/reading-data-section/filereader_events.any.js
@@ -0,0 +1,19 @@
+promise_test(async t => {
+ var reader = new FileReader();
+ var eventWatcher = new EventWatcher(t, reader, ['loadstart', 'progress', 'abort', 'error', 'load', 'loadend']);
+ reader.readAsText(new Blob([]));
+ await eventWatcher.wait_for('loadstart');
+ // No progress event for an empty blob, as no data is loaded.
+ await eventWatcher.wait_for('load');
+ await eventWatcher.wait_for('loadend');
+}, 'events are dispatched in the correct order for an empty blob');
+
+promise_test(async t => {
+ var reader = new FileReader();
+ var eventWatcher = new EventWatcher(t, reader, ['loadstart', 'progress', 'abort', 'error', 'load', 'loadend']);
+ reader.readAsText(new Blob(['a']));
+ await eventWatcher.wait_for('loadstart');
+ await eventWatcher.wait_for('progress');
+ await eventWatcher.wait_for('load');
+ await eventWatcher.wait_for('loadend');
+}, 'events are dispatched in the correct order for a non-empty blob');
diff --git a/testing/web-platform/tests/FileAPI/reading-data-section/filereader_file-manual.html b/testing/web-platform/tests/FileAPI/reading-data-section/filereader_file-manual.html
new file mode 100644
index 0000000000..702ca9afd7
--- /dev/null
+++ b/testing/web-platform/tests/FileAPI/reading-data-section/filereader_file-manual.html
@@ -0,0 +1,69 @@
+<!DOCTYPE html>
+<html>
+ <head>
+ <meta charset="utf-8">
+ <title>FileAPI Test: filereader_file</title>
+ <link rel="author" title="Intel" href="http://www.intel.com">
+ <link rel="help" href="http://dev.w3.org/2006/webapi/FileAPI/#FileReader-interface">
+ <link rel="help" href="http://dev.w3.org/2006/webapi/FileAPI/#file">
+ <script src="/resources/testharness.js"></script>
+ <script src="/resources/testharnessreport.js"></script>
+ </head>
+ <body>
+ <div>
+ <p>Test step:</p>
+ <ol>
+ <li>Download <a href="support/blue-100x100.png">blue-100x100.png</a> to local.</li>
+ <li>Select the local file (blue-100x100.png) to run the test.</li>
+ </ol>
+ </div>
+
+ <form name="uploadData">
+ <input type="file" id="fileChooser">
+ </form>
+
+ <div id="log"></div>
+ <script>
+ var fileInput = document.querySelector('#fileChooser');
+ var reader = new FileReader();
+
+ //readType: 1-> ArrayBuffer, 2-> Text, 3-> DataURL
+ var readType = 1;
+
+ setup({
+ explicit_done: true,
+ explicit_timeout: true,
+ });
+
+ on_event(fileInput, "change", function(evt) {
+ reader.readAsArrayBuffer(fileInput.files[0]);
+ });
+
+ on_event(reader, "load", function(evt) {
+ if (readType == 1) {
+ test(function() {
+ assert_true(reader.result instanceof ArrayBuffer, "The result is instanceof ArrayBuffer");
+ }, "Check if the readAsArrayBuffer works");
+
+ readType++;
+ reader.readAsText(fileInput.files[0]);
+ } else if (readType == 2) {
+ test(function() {
+ assert_equals(typeof reader.result, "string", "The result is typeof string");
+ }, "Check if the readAsText works");
+
+ readType++;
+ reader.readAsDataURL(fileInput.files[0]);
+ } else if (readType == 3) {
+ test(function() {
+ assert_equals(typeof reader.result, "string", "The result is typeof string");
+ assert_equals(reader.result.indexOf("data"), 0, "The result starts with 'data'");
+ assert_true(reader.result.indexOf("base64") > 0, "The result contains 'base64'");
+ }, "Check if the readAsDataURL works");
+
+ done();
+ }
+ });
+ </script>
+ </body>
+</html>
diff --git a/testing/web-platform/tests/FileAPI/reading-data-section/filereader_file_img-manual.html b/testing/web-platform/tests/FileAPI/reading-data-section/filereader_file_img-manual.html
new file mode 100644
index 0000000000..fca42c7fce
--- /dev/null
+++ b/testing/web-platform/tests/FileAPI/reading-data-section/filereader_file_img-manual.html
@@ -0,0 +1,47 @@
+<!DOCTYPE html>
+<html>
+ <head>
+ <meta charset="utf-8">
+ <title>FileAPI Test: filereader_file_img</title>
+ <link rel="author" title="Intel" href="http://www.intel.com">
+ <link rel="help" href="http://dev.w3.org/2006/webapi/FileAPI/#FileReader-interface">
+ <link rel="help" href="http://dev.w3.org/2006/webapi/FileAPI/#file">
+ <script src="/resources/testharness.js"></script>
+ <script src="/resources/testharnessreport.js"></script>
+ </head>
+ <body>
+ <div>
+ <p>Test step:</p>
+ <ol>
+ <li>Download <a href="support/blue-100x100.png">blue-100x100.png</a> to local.</li>
+ <li>Select the local file (blue-100x100.png) to run the test.</li>
+ </ol>
+ </div>
+
+ <form name="uploadData">
+ <input type="file" id="fileChooser">
+ </form>
+
+ <div id="log"></div>
+ <script>
+ var fileInput = document.querySelector('#fileChooser');
+ var reader = new FileReader();
+
+ setup({
+ explicit_done: true,
+ explicit_timeout: true,
+ });
+
+ fileInput.addEventListener("change", function(evt) {
+ reader.readAsDataURL(fileInput.files[0]);
+ }, false);
+
+ reader.addEventListener("loadend", function(evt) {
+ test(function () {
+ assert_true(reader.result.indexOf("iVBORw0KGgoAAAANSUhEUgAAAGQAAABkCAYAAABw4pVUAAAAqklEQVR42u3RsREAMAgDMe+/M4E7ZkhBoeI9gJWkWpfaeToTECACAkRAgAgIEAEB4gQgAgJEQIAICBABASIgAgJEQIAICBABASIgAgJEQIAICBABASIgAgJEQIAICBABASIgAgJEQIAICBABASIgAgJEQIAICBABASIgAgJEQIAICBABASIgAgJEQIAICBABASIgAgJEQIAICBABASIgQJwARECACAgQ/W4AQauujc8IdAoAAAAASUVORK5CYII=") != -1, "Encoded image")
+ }, "Check if readAsDataURL returns correct image");
+ done();
+ }, false);
+ </script>
+ </body>
+</html>
diff --git a/testing/web-platform/tests/FileAPI/reading-data-section/filereader_readAsArrayBuffer.any.js b/testing/web-platform/tests/FileAPI/reading-data-section/filereader_readAsArrayBuffer.any.js
new file mode 100644
index 0000000000..d06e317078
--- /dev/null
+++ b/testing/web-platform/tests/FileAPI/reading-data-section/filereader_readAsArrayBuffer.any.js
@@ -0,0 +1,23 @@
+// META: title=FileAPI Test: filereader_readAsArrayBuffer
+
+ async_test(function() {
+ var blob = new Blob(["TEST"]);
+ var reader = new FileReader();
+
+ reader.onload = this.step_func(function(evt) {
+ assert_equals(reader.result.byteLength, 4, "The byteLength is 4");
+ assert_true(reader.result instanceof ArrayBuffer, "The result is instanceof ArrayBuffer");
+ assert_equals(reader.readyState, reader.DONE);
+ this.done();
+ });
+
+ reader.onloadstart = this.step_func(function(evt) {
+ assert_equals(reader.readyState, reader.LOADING);
+ });
+
+ reader.onprogress = this.step_func(function(evt) {
+ assert_equals(reader.readyState, reader.LOADING);
+ });
+
+ reader.readAsArrayBuffer(blob);
+ });
diff --git a/testing/web-platform/tests/FileAPI/reading-data-section/filereader_readAsBinaryString.any.js b/testing/web-platform/tests/FileAPI/reading-data-section/filereader_readAsBinaryString.any.js
new file mode 100644
index 0000000000..e69ff15e75
--- /dev/null
+++ b/testing/web-platform/tests/FileAPI/reading-data-section/filereader_readAsBinaryString.any.js
@@ -0,0 +1,23 @@
+// META: title=FileAPI Test: filereader_readAsBinaryString
+
+async_test(t => {
+ const blob = new Blob(["σ"]);
+ const reader = new FileReader();
+
+ reader.onload = t.step_func_done(() => {
+ assert_equals(typeof reader.result, "string", "The result is string");
+ assert_equals(reader.result.length, 2, "The result length is 2");
+ assert_equals(reader.result, "\xcf\x83", "The result is \xcf\x83");
+ assert_equals(reader.readyState, reader.DONE);
+ });
+
+ reader.onloadstart = t.step_func(() => {
+ assert_equals(reader.readyState, reader.LOADING);
+ });
+
+ reader.onprogress = t.step_func(() => {
+ assert_equals(reader.readyState, reader.LOADING);
+ });
+
+ reader.readAsBinaryString(blob);
+});
diff --git a/testing/web-platform/tests/FileAPI/reading-data-section/filereader_readAsDataURL.any.js b/testing/web-platform/tests/FileAPI/reading-data-section/filereader_readAsDataURL.any.js
new file mode 100644
index 0000000000..4f9dbf7a75
--- /dev/null
+++ b/testing/web-platform/tests/FileAPI/reading-data-section/filereader_readAsDataURL.any.js
@@ -0,0 +1,54 @@
+// META: title=FileAPI Test: FileReader.readAsDataURL
+
+async_test(function(testCase) {
+ var blob = new Blob(["TEST"]);
+ var reader = new FileReader();
+
+ reader.onload = this.step_func(function(evt) {
+ assert_equals(reader.readyState, reader.DONE);
+ testCase.done();
+ });
+ reader.onloadstart = this.step_func(function(evt) {
+ assert_equals(reader.readyState, reader.LOADING);
+ });
+ reader.onprogress = this.step_func(function(evt) {
+ assert_equals(reader.readyState, reader.LOADING);
+ });
+
+ reader.readAsDataURL(blob);
+}, 'FileReader readyState during readAsDataURL');
+
+async_test(function(testCase) {
+ var blob = new Blob(["TEST"], { type: 'text/plain' });
+ var reader = new FileReader();
+
+ reader.onload = this.step_func(function() {
+ assert_equals(reader.result, "data:text/plain;base64,VEVTVA==");
+ testCase.done();
+ });
+ reader.readAsDataURL(blob);
+}, 'readAsDataURL result for Blob with specified MIME type');
+
+async_test(function(testCase) {
+ var blob = new Blob(["TEST"]);
+ var reader = new FileReader();
+
+ reader.onload = this.step_func(function() {
+ assert_equals(reader.result,
+ "data:application/octet-stream;base64,VEVTVA==");
+ testCase.done();
+ });
+ reader.readAsDataURL(blob);
+}, 'readAsDataURL result for Blob with unspecified MIME type');
+
+async_test(function(testCase) {
+ var blob = new Blob([]);
+ var reader = new FileReader();
+
+ reader.onload = this.step_func(function() {
+ assert_equals(reader.result,
+ "data:application/octet-stream;base64,");
+ testCase.done();
+ });
+ reader.readAsDataURL(blob);
+}, 'readAsDataURL result for empty Blob'); \ No newline at end of file
diff --git a/testing/web-platform/tests/FileAPI/reading-data-section/filereader_readAsText.any.js b/testing/web-platform/tests/FileAPI/reading-data-section/filereader_readAsText.any.js
new file mode 100644
index 0000000000..4d0fa11393
--- /dev/null
+++ b/testing/web-platform/tests/FileAPI/reading-data-section/filereader_readAsText.any.js
@@ -0,0 +1,36 @@
+// META: title=FileAPI Test: filereader_readAsText
+
+ async_test(function() {
+ var blob = new Blob(["TEST"]);
+ var reader = new FileReader();
+
+ reader.onload = this.step_func(function(evt) {
+ assert_equals(typeof reader.result, "string", "The result is typeof string");
+ assert_equals(reader.result, "TEST", "The result is TEST");
+ this.done();
+ });
+
+ reader.onloadstart = this.step_func(function(evt) {
+ assert_equals(reader.readyState, reader.LOADING, "The readyState");
+ });
+
+ reader.onprogress = this.step_func(function(evt) {
+ assert_equals(reader.readyState, reader.LOADING);
+ });
+
+ reader.readAsText(blob);
+ }, "readAsText should correctly read UTF-8.");
+
+ async_test(function() {
+ var blob = new Blob(["TEST"]);
+ var reader = new FileReader();
+ var reader_UTF16 = new FileReader();
+ reader_UTF16.onload = this.step_func(function(evt) {
+ // "TEST" in UTF-8 is 0x54 0x45 0x53 0x54.
+ // Decoded as utf-16 (little-endian), we get 0x4554 0x5453.
+ assert_equals(reader_UTF16.readyState, reader.DONE, "The readyState");
+ assert_equals(reader_UTF16.result, "\u4554\u5453", "The result is not TEST");
+ this.done();
+ });
+ reader_UTF16.readAsText(blob, "UTF-16");
+ }, "readAsText should correctly read UTF-16.");
diff --git a/testing/web-platform/tests/FileAPI/reading-data-section/filereader_readystate.any.js b/testing/web-platform/tests/FileAPI/reading-data-section/filereader_readystate.any.js
new file mode 100644
index 0000000000..3cb36ab999
--- /dev/null
+++ b/testing/web-platform/tests/FileAPI/reading-data-section/filereader_readystate.any.js
@@ -0,0 +1,19 @@
+// META: title=FileAPI Test: filereader_readystate
+
+ async_test(function() {
+ var blob = new Blob(["THIS TEST THE READYSTATE WHEN READ BLOB"]);
+ var reader = new FileReader();
+
+ assert_equals(reader.readyState, reader.EMPTY);
+
+ reader.onloadstart = this.step_func(function(evt) {
+ assert_equals(reader.readyState, reader.LOADING);
+ });
+
+ reader.onloadend = this.step_func(function(evt) {
+ assert_equals(reader.readyState, reader.DONE);
+ this.done();
+ });
+
+ reader.readAsDataURL(blob);
+ });
diff --git a/testing/web-platform/tests/FileAPI/reading-data-section/filereader_result.any.js b/testing/web-platform/tests/FileAPI/reading-data-section/filereader_result.any.js
new file mode 100644
index 0000000000..28c068bb34
--- /dev/null
+++ b/testing/web-platform/tests/FileAPI/reading-data-section/filereader_result.any.js
@@ -0,0 +1,82 @@
+// META: title=FileAPI Test: filereader_result
+
+ var blob, blob2;
+ setup(function() {
+ blob = new Blob(["This test the result attribute"]);
+ blob2 = new Blob(["This is a second blob"]);
+ });
+
+ async_test(function() {
+ var readText = new FileReader();
+ assert_equals(readText.result, null);
+
+ readText.onloadend = this.step_func(function(evt) {
+ assert_equals(typeof readText.result, "string", "The result type is string");
+ assert_equals(readText.result, "This test the result attribute", "The result is correct");
+ this.done();
+ });
+
+ readText.readAsText(blob);
+ }, "readAsText");
+
+ async_test(function() {
+ var readDataURL = new FileReader();
+ assert_equals(readDataURL.result, null);
+
+ readDataURL.onloadend = this.step_func(function(evt) {
+ assert_equals(typeof readDataURL.result, "string", "The result type is string");
+ assert_true(readDataURL.result.indexOf("VGhpcyB0ZXN0IHRoZSByZXN1bHQgYXR0cmlidXRl") != -1, "return the right base64 string");
+ this.done();
+ });
+
+ readDataURL.readAsDataURL(blob);
+ }, "readAsDataURL");
+
+ async_test(function() {
+ var readArrayBuffer = new FileReader();
+ assert_equals(readArrayBuffer.result, null);
+
+ readArrayBuffer.onloadend = this.step_func(function(evt) {
+ assert_true(readArrayBuffer.result instanceof ArrayBuffer, "The result is instanceof ArrayBuffer");
+ this.done();
+ });
+
+ readArrayBuffer.readAsArrayBuffer(blob);
+ }, "readAsArrayBuffer");
+
+ async_test(function() {
+ var readBinaryString = new FileReader();
+ assert_equals(readBinaryString.result, null);
+
+ readBinaryString.onloadend = this.step_func(function(evt) {
+ assert_equals(typeof readBinaryString.result, "string", "The result type is string");
+ assert_equals(readBinaryString.result, "This test the result attribute", "The result is correct");
+ this.done();
+ });
+
+ readBinaryString.readAsBinaryString(blob);
+ }, "readAsBinaryString");
+
+
+ for (let event of ['loadstart', 'progress']) {
+ for (let method of ['readAsText', 'readAsDataURL', 'readAsArrayBuffer', 'readAsBinaryString']) {
+ promise_test(async function(t) {
+ var reader = new FileReader();
+ assert_equals(reader.result, null, 'result is null before read');
+
+ var eventWatcher = new EventWatcher(t, reader,
+ [event, 'loadend']);
+
+ reader[method](blob);
+ assert_equals(reader.result, null, 'result is null after first read call');
+ await eventWatcher.wait_for(event);
+ assert_equals(reader.result, null, 'result is null during event');
+ await eventWatcher.wait_for('loadend');
+ assert_not_equals(reader.result, null);
+ reader[method](blob);
+ assert_equals(reader.result, null, 'result is null after second read call');
+ await eventWatcher.wait_for(event);
+ assert_equals(reader.result, null, 'result is null during second read event');
+ }, 'result is null during "' + event + '" event for ' + method);
+ }
+ }
diff --git a/testing/web-platform/tests/FileAPI/reading-data-section/support/blue-100x100.png b/testing/web-platform/tests/FileAPI/reading-data-section/support/blue-100x100.png
new file mode 100644
index 0000000000..5748719ff2
--- /dev/null
+++ b/testing/web-platform/tests/FileAPI/reading-data-section/support/blue-100x100.png
Binary files differ