DXR is a code search and navigation tool aimed at making sense of large projects. It supports full-text and regex searches as well as structural queries.

Mercurial (c68fe15a81fc)

VCS Links

Line Code
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 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89
<!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_dom("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_dom("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_dom("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_dom("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.DONE,
                  "readyState must be DONE")
    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 loadend event handler for readAsArrayBuffer');

async_test(function() {
  var blob_1 = new Blob([new Uint8Array(0x414141)]);
  var blob_2 = new Blob(['TEST000000002']);
  var reader = new FileReader();
  reader.onloadstart = this.step_func(function() {
    reader.abort();
    reader.onloadstart = null;
    reader.onloadend = this.step_func_done(function() {
      assert_equals('TEST000000002', reader.result);
    });
    reader.readAsText(blob_2);
  });
  reader.readAsText(blob_1);
}, 'test abort and restart in onloadstart event for readAsText');

</script>