• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1<!doctype html>
2<meta charset="utf-8">
3<title>FileAPI Test: FileReader.readAsDataURL</title>
4<link rel="author" title="Intel" href="http://www.intel.com">
5<link rel="help" href="https://w3c.github.io/FileAPI/#readAsDataURL">
6<script src="/resources/testharness.js"></script>
7<script src="/resources/testharnessreport.js"></script>
8
9<script>
10async_test(function(testCase) {
11  var blob = new Blob(["TEST"]);
12  var reader = new FileReader();
13
14  reader.onload = this.step_func(function(evt) {
15    assert_equals(reader.readyState, reader.DONE);
16    testCase.done();
17  });
18  reader.onloadstart = this.step_func(function(evt) {
19    assert_equals(reader.readyState, reader.LOADING);
20  });
21  reader.onprogress = this.step_func(function(evt) {
22    assert_equals(reader.readyState, reader.LOADING);
23  });
24
25  reader.readAsDataURL(blob);
26}, 'FileReader readyState during readAsDataURL');
27
28async_test(function(testCase) {
29  var blob = new Blob(["TEST"], { type: 'text/plain' });
30  var reader = new FileReader();
31
32  reader.onload = this.step_func(function() {
33    assert_equals(reader.result, "data:text/plain;base64,VEVTVA==");
34    testCase.done();
35  });
36  reader.readAsDataURL(blob);
37}, 'readAsDataURL result for Blob with specified MIME type');
38
39async_test(function(testCase) {
40  var blob = new Blob(["TEST"]);
41  var reader = new FileReader();
42
43  reader.onload = this.step_func(function() {
44    assert_equals(reader.result,
45                  "data:application/octet-stream;base64,VEVTVA==");
46    testCase.done();
47  });
48  reader.readAsDataURL(blob);
49}, 'readAsDataURL result for Blob with unspecified MIME type');
50
51</script>