1importScripts("/resources/testharness.js"); 2 3var blob, empty_blob, readerSync; 4setup(() => { 5 readerSync = new FileReaderSync(); 6 blob = new Blob(["test"]); 7 empty_blob = new Blob(); 8}); 9 10test(() => { 11 assert_true(readerSync instanceof FileReaderSync); 12}, "Interface"); 13 14test(() => { 15 var text = readerSync.readAsText(blob); 16 assert_equals(text, "test"); 17}, "readAsText"); 18 19test(() => { 20 var text = readerSync.readAsText(empty_blob); 21 assert_equals(text, ""); 22}, "readAsText with empty blob"); 23 24test(() => { 25 var data = readerSync.readAsDataURL(blob); 26 assert_equals(data.indexOf("data:"), 0); 27}, "readAsDataURL"); 28 29test(() => { 30 var data = readerSync.readAsDataURL(empty_blob); 31 assert_equals(data.indexOf("data:"), 0); 32}, "readAsDataURL with empty blob"); 33 34test(() => { 35 var data = readerSync.readAsBinaryString(blob); 36 assert_equals(data, "test"); 37}, "readAsBinaryString"); 38 39test(() => { 40 var data = readerSync.readAsBinaryString(empty_blob); 41 assert_equals(data, ""); 42}, "readAsBinaryString with empty blob"); 43 44test(() => { 45 var data = readerSync.readAsArrayBuffer(blob); 46 assert_true(data instanceof ArrayBuffer); 47 assert_equals(data.byteLength, "test".length); 48}, "readAsArrayBuffer"); 49 50test(() => { 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 56done(); 57