summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/FileAPI/fileReader.any.js
blob: 2876dcb4ce314e3441e1e61a37505235209f4e2e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
// META: title=FileReader States

'use strict';

test(function () {
  assert_true(
    "FileReader" in globalThis,
    "globalThis should have a FileReader property.",
  );
}, "FileReader interface object");

test(function () {
  var fileReader = new FileReader();
  assert_true(fileReader instanceof FileReader);
}, "no-argument FileReader constructor");

var t_abort = async_test("FileReader States -- abort");
t_abort.step(function () {
  var fileReader = new FileReader();
  assert_equals(fileReader.readyState, 0);
  assert_equals(fileReader.readyState, FileReader.EMPTY);

  var blob = new Blob();
  fileReader.readAsArrayBuffer(blob);
  assert_equals(fileReader.readyState, 1);
  assert_equals(fileReader.readyState, FileReader.LOADING);

  fileReader.onabort = this.step_func(function (e) {
    assert_equals(fileReader.readyState, 2);
    assert_equals(fileReader.readyState, FileReader.DONE);
    t_abort.done();
  });
  fileReader.abort();
  fileReader.onabort = this.unreached_func("abort event should fire sync");
});

var t_event = async_test("FileReader States -- events");
t_event.step(function () {
  var fileReader = new FileReader();

  var blob = new Blob();
  fileReader.readAsArrayBuffer(blob);

  fileReader.onloadstart = this.step_func(function (e) {
    assert_equals(fileReader.readyState, 1);
    assert_equals(fileReader.readyState, FileReader.LOADING);
  });

  fileReader.onprogress = this.step_func(function (e) {
    assert_equals(fileReader.readyState, 1);
    assert_equals(fileReader.readyState, FileReader.LOADING);
  });

  fileReader.onloadend = this.step_func(function (e) {
    assert_equals(fileReader.readyState, 2);
    assert_equals(fileReader.readyState, FileReader.DONE);
    t_event.done();
  });
});