• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1<!DOCTYPE html>
2<html>
3  <head>
4    <meta charset="utf-8">
5    <title>FileAPI Test: filereader_file_img</title>
6    <link rel="author" title="Intel" href="http://www.intel.com">
7    <link rel="help" href="http://dev.w3.org/2006/webapi/FileAPI/#FileReader-interface">
8    <link rel="help" href="http://dev.w3.org/2006/webapi/FileAPI/#file">
9    <script src="/resources/testharness.js"></script>
10    <script src="/resources/testharnessreport.js"></script>
11  </head>
12  <body>
13    <div>
14      <p>Test step:</p>
15      <ol>
16        <li>Download <a href="support/blue-100x100.png">blue-100x100.png</a> to local.</li>
17        <li>Select the local file (blue-100x100.png) to run the test.</li>
18      </ol>
19    </div>
20
21    <form name="uploadData">
22      <input type="file" id="fileChooser">
23    </form>
24
25    <div id="log"></div>
26    <script>
27      var fileInput = document.querySelector('#fileChooser');
28      var reader = new FileReader();
29
30      setup({
31        explicit_done: true,
32        explicit_timeout: true,
33      });
34
35      fileInput.addEventListener("change", function(evt) {
36        reader.readAsDataURL(fileInput.files[0]);
37      }, false);
38
39      reader.addEventListener("loadend", function(evt) {
40        test(function () {
41          assert_true(reader.result.indexOf("iVBORw0KGgoAAAANSUhEUgAAAGQAAABkCAYAAABw4pVUAAAAqklEQVR42u3RsREAMAgDMe+/M4E7ZkhBoeI9gJWkWpfaeToTECACAkRAgAgIEAEB4gQgAgJEQIAICBABASIgAgJEQIAICBABASIgAgJEQIAICBABASIgAgJEQIAICBABASIgAgJEQIAICBABASIgAgJEQIAICBABASIgAgJEQIAICBABASIgAgJEQIAICBABASIgAgJEQIAICBABASIgQJwARECACAgQ/W4AQauujc8IdAoAAAAASUVORK5CYII=") != -1, "Encoded image")
42        }, "Check if readAsDataURL returns correct image");
43        done();
44      }, false);
45    </script>
46  </body>
47</html>
48