summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/FileAPI/reading-data-section/FileReader-multiple-reads.html
blob: 86a29d187b5274bfd8ca76c10f360ba16139e13c (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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
<!DOCTYPE html>
<title>FileReader: starting new reads while one is in progress</title>
<link rel="author" title="Yinkan Li" href="mailto:liyinkan.biz@gmail.com">
<link rel="help" href="http://dev.w3.org/2006/webapi/FileAPI/#MultipleReads">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<div id="log"></div>
<script>
test(function() {
  var blob_1 = new Blob(['TEST000000001'])
  var blob_2 = new Blob(['TEST000000002'])
  var reader = new FileReader();
  reader.readAsText(blob_1)
  assert_equals(reader.readyState, FileReader.LOADING, "readyState Must be LOADING")
  assert_throws("InvalidStateError", function () {
    reader.readAsText(blob_2)
  })
}, 'test FileReader InvalidStateError exception for readAsText');

test(function() {
  var blob_1 = new Blob(['TEST000000001'])
  var blob_2 = new Blob(['TEST000000002'])
  var reader = new FileReader();
  reader.readAsDataURL(blob_1)
  assert_equals(reader.readyState, FileReader.LOADING, "readyState Must be LOADING")
  assert_throws("InvalidStateError", function () {
    reader.readAsDataURL(blob_2)
  })
}, 'test FileReader InvalidStateError exception for readAsDataURL');

test(function() {
  var blob_1 = new Blob(['TEST000000001'])
  var blob_2 = new Blob(['TEST000000002'])
  var reader = new FileReader();
  reader.readAsArrayBuffer(blob_1)
  assert_equals(reader.readyState, FileReader.LOADING, "readyState Must be LOADING")
  assert_throws("InvalidStateError", function () {
    reader.readAsArrayBuffer(blob_2)
  })
}, 'test FileReader InvalidStateError exception for readAsArrayBuffer');

async_test(function() {
  var blob_1 = new Blob(['TEST000000001'])
  var blob_2 = new Blob(['TEST000000002'])
  var reader = new FileReader();
  var triggered = false;
  reader.onloadstart = this.step_func_done(function() {
    assert_false(triggered, "Only one loadstart event should be dispatched");
    triggered = true;
    assert_equals(reader.readyState, FileReader.LOADING,
                  "readyState must be LOADING")
    assert_throws("InvalidStateError", function () {
      reader.readAsArrayBuffer(blob_2)
    })
  });
  reader.readAsArrayBuffer(blob_1)
  assert_equals(reader.readyState, FileReader.LOADING, "readyState Must be LOADING")
}, 'test FileReader InvalidStateError exception in onloadstart event for readAsArrayBuffer');

async_test(function() {
  var blob_1 = new Blob(['TEST000000001'])
  var blob_2 = new Blob(['TEST000000002'])
  var reader = new FileReader();
  reader.onloadend = this.step_func_done(function() {
    assert_equals(reader.readyState, FileReader.LOADING,
                  "readyState must be LOADING")
    reader.readAsArrayBuffer(blob_2)
    assert_equals(reader.readyState, FileReader.LOADING, "readyState Must be LOADING")
  });
  reader.readAsArrayBuffer(blob_1)
  assert_equals(reader.readyState, FileReader.LOADING, "readyState Must be LOADING")
}, 'test FileReader no InvalidStateError exception in onloadstart event for readAsArrayBuffer');
</script>