зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1536000 [wpt PR 7494] - Add more tests for FileReader.result., a=testonly
Automatic update from web-platform-tests Add more tests for FileReader.result. (#7494) In particular this adds tests to verify the value of the attribute during progress and loadstart events. -- wpt-commits: c626cbbceb934eb952bdf15f41b6a76db9ed1a5d wpt-pr: 7494
This commit is contained in:
Родитель
de30de96aa
Коммит
1e833ecc91
|
@ -0,0 +1,19 @@
|
|||
promise_test(async t => {
|
||||
var reader = new FileReader();
|
||||
var eventWatcher = new EventWatcher(t, reader, ['loadstart', 'progress', 'abort', 'error', 'load', 'loadend']);
|
||||
reader.readAsText(new Blob([]));
|
||||
await eventWatcher.wait_for('loadstart');
|
||||
// No progress event for an empty blob, as no data is loaded.
|
||||
await eventWatcher.wait_for('load');
|
||||
await eventWatcher.wait_for('loadend');
|
||||
}, 'events are dispatched in the correct order for an empty blob');
|
||||
|
||||
promise_test(async t => {
|
||||
var reader = new FileReader();
|
||||
var eventWatcher = new EventWatcher(t, reader, ['loadstart', 'progress', 'abort', 'error', 'load', 'loadend']);
|
||||
reader.readAsText(new Blob(['a']));
|
||||
await eventWatcher.wait_for('loadstart');
|
||||
await eventWatcher.wait_for('progress');
|
||||
await eventWatcher.wait_for('load');
|
||||
await eventWatcher.wait_for('loadend');
|
||||
}, 'events are dispatched in the correct order for a non-empty blob');
|
|
@ -12,9 +12,10 @@
|
|||
<div id="log"></div>
|
||||
|
||||
<script>
|
||||
var blob;
|
||||
var blob, blob2;
|
||||
setup(function() {
|
||||
blob = new Blob(["This test the result attribute"]);
|
||||
blob2 = new Blob(["This is a second blob"]);
|
||||
});
|
||||
|
||||
async_test(function() {
|
||||
|
@ -54,6 +55,43 @@
|
|||
|
||||
readArrayBuffer.readAsArrayBuffer(blob);
|
||||
}, "readAsArrayBuffer");
|
||||
|
||||
async_test(function() {
|
||||
var readBinaryString = new FileReader();
|
||||
assert_equals(readBinaryString.result, null);
|
||||
|
||||
readBinaryString.onloadend = this.step_func(function(evt) {
|
||||
assert_equals(typeof readBinaryString.result, "string", "The result type is string");
|
||||
assert_equals(readBinaryString.result, "This test the result attribute", "The result is correct");
|
||||
this.done();
|
||||
});
|
||||
|
||||
readBinaryString.readAsBinaryString(blob);
|
||||
}, "readAsBinaryString");
|
||||
|
||||
|
||||
for (let event of ['loadstart', 'progress']) {
|
||||
for (let method of ['readAsText', 'readAsDataURL', 'readAsArrayBuffer', 'readAsBinaryString']) {
|
||||
promise_test(async function(t) {
|
||||
var reader = new FileReader();
|
||||
assert_equals(reader.result, null, 'result is null before read');
|
||||
|
||||
var eventWatcher = new EventWatcher(t, reader,
|
||||
[event, 'loadend']);
|
||||
|
||||
reader[method](blob);
|
||||
assert_equals(reader.result, null, 'result is null after first read call');
|
||||
await eventWatcher.wait_for(event);
|
||||
assert_equals(reader.result, null, 'result is null during event');
|
||||
await eventWatcher.wait_for('loadend');
|
||||
assert_not_equals(reader.result, null);
|
||||
reader[method](blob);
|
||||
assert_equals(reader.result, null, 'result is null after second read call');
|
||||
await eventWatcher.wait_for(event);
|
||||
assert_equals(reader.result, null, 'result is null during second read event');
|
||||
}, 'result is null during "' + event + '" event for ' + method);
|
||||
}
|
||||
}
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
|
|
Загрузка…
Ссылка в новой задаче