Skip to content

Commit

Permalink
Implement read methods on FileReaderSync
Browse files Browse the repository at this point in the history
Upstreamed from servo/servo#19511 [ci skip]
  • Loading branch information
DonatJR authored and jdm committed Jun 7, 2018
1 parent 9069371 commit 320e4fd
Showing 1 changed file with 43 additions and 15 deletions.
58 changes: 43 additions & 15 deletions FileAPI/FileReaderSync.worker.js
Original file line number Diff line number Diff line change
@@ -1,28 +1,56 @@
importScripts("/resources/testharness.js");

var blob, readerSync;
setup(function() {
readerSync = new FileReaderSync();
blob = new Blob(["test"]);
var blob, empty_blob, readerSync;
setup(() => {
readerSync = new FileReaderSync();
blob = new Blob(["test"]);
empty_blob = new Blob();
});

test(function() {
assert_true(readerSync instanceof FileReaderSync);
test(() => {
assert_true(readerSync instanceof FileReaderSync);
}, "Interface");

test(function() {
var text = readerSync.readAsText(blob);
assert_equals(text, "test");
test(() => {
var text = readerSync.readAsText(blob);
assert_equals(text, "test");
}, "readAsText");

test(function() {
var data = readerSync.readAsDataURL(blob);
assert_equals(data.indexOf("data:"), 0);
test(() => {
var text = readerSync.readAsText(empty_blob);
assert_equals(text, "");
}, "readAsText with empty blob");

test(() => {
var data = readerSync.readAsDataURL(blob);
assert_equals(data.indexOf("data:"), 0);
}, "readAsDataURL");

test(function() {
var data = readerSync.readAsArrayBuffer(blob);
assert_true(data instanceof ArrayBuffer);
test(() => {
var data = readerSync.readAsDataURL(empty_blob);
assert_equals(data.indexOf("data:"), 0);
}, "readAsDataURL with empty blob");

test(() => {
var data = readerSync.readAsBinaryString(blob);
assert_equals(data, "test");
}, "readAsBinaryString");

test(() => {
var data = readerSync.readAsBinaryString(empty_blob);
assert_equals(data, "");
}, "readAsBinaryString with empty blob");

test(() => {
var data = readerSync.readAsArrayBuffer(blob);
assert_true(data instanceof ArrayBuffer);
assert_equals(data.byteLength, "test".length);
}, "readAsArrayBuffer");

test(() => {
var data = readerSync.readAsArrayBuffer(empty_blob);
assert_true(data instanceof ArrayBuffer);
assert_equals(data.byteLength, 0);
}, "readAsArrayBuffer with empty blob");

done();

0 comments on commit 320e4fd

Please sign in to comment.