From 320e4fd58a3bd93b844d9596e72027d5f3781f3d Mon Sep 17 00:00:00 2001 From: Jonas Reinwald Date: Thu, 7 Jun 2018 09:01:31 -0400 Subject: [PATCH] Implement read methods on FileReaderSync Upstreamed from https://github.com/servo/servo/pull/19511 [ci skip] --- FileAPI/FileReaderSync.worker.js | 58 +++++++++++++++++++++++--------- 1 file changed, 43 insertions(+), 15 deletions(-) diff --git a/FileAPI/FileReaderSync.worker.js b/FileAPI/FileReaderSync.worker.js index 77af6a7a6a..3d7a0222f3 100644 --- a/FileAPI/FileReaderSync.worker.js +++ b/FileAPI/FileReaderSync.worker.js @@ -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();