Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

replace FileReader with blobs own methods #32432

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 12 additions & 29 deletions FileAPI/support/Blob.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,50 +5,33 @@ self.test_blob = (fn, expectations) => {
type = expectations.type,
desc = expectations.desc;

var t = async_test(desc);
t.step(function() {
promise_test(async () => {
var blob = fn();
assert_true(blob instanceof Blob);
assert_false(blob instanceof File);
assert_equals(blob.type, type);
assert_equals(blob.size, expected.length);

var fr = new FileReader();
fr.onload = t.step_func_done(function(event) {
assert_equals(this.result, expected);
}, fr);
fr.onerror = t.step_func(function(e) {
assert_unreached("got error event on FileReader");
});
fr.readAsText(blob, "UTF-8");
});
}
assert_equals(await blob.text(), expected);
}, desc);
};

self.test_blob_binary = (fn, expectations) => {
var expected = expectations.expected,
type = expectations.type,
desc = expectations.desc;

var t = async_test(desc);
t.step(function() {
var blob = fn();
promise_test(async () => {
var blob = fn(),
result = await blob.arrayBuffer();
assert_true(blob instanceof Blob);
assert_false(blob instanceof File);
assert_equals(blob.type, type);
assert_equals(blob.size, expected.length);

var fr = new FileReader();
fr.onload = t.step_func_done(function(event) {
assert_true(this.result instanceof ArrayBuffer,
assert_true(result instanceof ArrayBuffer,
"Result should be an ArrayBuffer");
assert_array_equals(new Uint8Array(this.result), expected);
}, fr);
fr.onerror = t.step_func(function(e) {
assert_unreached("got error event on FileReader");
});
fr.readAsArrayBuffer(blob);
});
}
assert_array_equals(new Uint8Array(result), expected);
}, desc);
};

// Assert that two TypedArray objects have the same byte values
self.assert_equals_typed_array = (array1, array2) => {
Expand All @@ -67,4 +50,4 @@ self.assert_equals_typed_array = (array1, array2) => {
assert_equals(view1.getUint8(i), view2.getUint8(i),
`Expect byte at buffer position ${i} to be equal`);
}
}
};