GeezerVison is showing github.com — test: add wpt tests for Blob · nodejs/node@d73d58d
File treeExpand file treeCollapse file tree Open diff view settings Some content is hiddenLarge Commits have some content hidden by default. Use the searchbox below for content that may be hidden. Dismiss bannerExpand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: test/fixtures/wpt/FileAPI/BlobURL/support/file_test2.txt Collapse file Copy file name to clipboard +62Lines changed: 62 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| | 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 | + | | 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> |
Collapse file Copy file name to clipboard +33Lines changed: 33 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| | 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 | + |
Collapse file Copy file name to clipboardExpand all lines: test/fixtures/wpt/FileAPI/FileReader/support/file_test1.txt Collapse file Copy file name to clipboard +72Lines changed: 72 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| | 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 | + | | 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> |
Collapse file Copy file name to clipboard +42Lines changed: 42 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| | 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 | + |
Collapse file Copy file name to clipboard +40Lines changed: 40 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| | 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> |
Collapse file Copy file name to clipboard +27Lines changed: 27 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| | 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> |
Collapse file Copy file name to clipboard +56Lines changed: 56 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| | 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(); |
Collapse file Copy file name to clipboard +6Lines changed: 6 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| | 1 | +spec: https://w3c.github.io/FileAPI/ | | 2 | +suggested_reviewers: | | 3 | + - inexorabletash | | 4 | + - zqzhang | | 5 | + - jdm | | 6 | + - mkruisselbrink |
|