diff options
author | bors-servo <lbergstrom+bors@mozilla.com> | 2019-04-16 04:38:39 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-04-16 04:38:39 -0400 |
commit | b9d625f16e31be71eb493f0cb38c07a713b4fe86 (patch) | |
tree | b3c70f44fe9e5676aef3301909790c71c2a785c4 /tests/wpt/web-platform-tests/FileAPI/blob/Blob-stream.any.js | |
parent | a16110682b512d56c5691ffedbd380233e57117c (diff) | |
parent | c8202ddbe16fdb3894b8f725310096a345d6b37d (diff) | |
download | servo-b9d625f16e31be71eb493f0cb38c07a713b4fe86.tar.gz servo-b9d625f16e31be71eb493f0cb38c07a713b4fe86.zip |
Auto merge of #23206 - servo-wpt-sync:wpt_update_16-04-2019, r=servo-wpt-sync
Sync WPT with upstream (16-04-2019)
Automated downstream sync of changes from upstream as of 16-04-2019.
[no-wpt-sync]
<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/23206)
<!-- Reviewable:end -->
Diffstat (limited to 'tests/wpt/web-platform-tests/FileAPI/blob/Blob-stream.any.js')
-rw-r--r-- | tests/wpt/web-platform-tests/FileAPI/blob/Blob-stream.any.js | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/tests/wpt/web-platform-tests/FileAPI/blob/Blob-stream.any.js b/tests/wpt/web-platform-tests/FileAPI/blob/Blob-stream.any.js new file mode 100644 index 00000000000..894f09f8ece --- /dev/null +++ b/tests/wpt/web-platform-tests/FileAPI/blob/Blob-stream.any.js @@ -0,0 +1,50 @@ +// META: title=Blob Stream +// META: script=../support/Blob.js +'use strict'; + +// Takes in a ReadableStream and reads from it until it is done, returning +// an array that contains the results of each read operation +async function read_all_chunks(stream) { + assert_true(stream instanceof ReadableStream); + assert_true('getReader' in stream); + const reader = stream.getReader(); + + assert_true('read' in reader); + let read_value = await reader.read(); + + let out = []; + let i = 0; + while (!read_value.done) { + for (let val of read_value.value) { + out[i++] = val; + } + read_value = await reader.read(); + } + return out; +} + +promise_test(async () => { + const blob = new Blob(["PASS"]); + const stream = await blob.stream() + const chunks = await read_all_chunks(stream); + for (let [index, value] of chunks.entries()) { + assert_equals(value, "PASS".charCodeAt(index)); + } +}, "Blob.stream()") + +promise_test(async () => { + const blob = new Blob(); + const stream = await blob.stream() + const chunks = await read_all_chunks(stream); + + assert_array_equals(chunks, []); +}, "Blob.stream() empty Blob") + +promise_test(async () => { + const input_arr = [8, 241, 48, 123, 151]; + const typed_arr = new Uint8Array(input_arr); + const blob = new Blob([typed_arr]); + const stream = await blob.stream() + const chunks = await read_all_chunks(stream); + assert_array_equals(chunks, input_arr) +}, "Blob.stream() non-unicode input") |