11cb0ef41Sopenharmony_ci<!DOCTYPE html>
21cb0ef41Sopenharmony_ci<html>
31cb0ef41Sopenharmony_ci  <head>
41cb0ef41Sopenharmony_ci    <meta charset="utf-8">
51cb0ef41Sopenharmony_ci    <title>FileAPI Test: filereader_file</title>
61cb0ef41Sopenharmony_ci    <link rel="author" title="Intel" href="http://www.intel.com">
71cb0ef41Sopenharmony_ci    <link rel="help" href="http://dev.w3.org/2006/webapi/FileAPI/#FileReader-interface">
81cb0ef41Sopenharmony_ci    <link rel="help" href="http://dev.w3.org/2006/webapi/FileAPI/#file">
91cb0ef41Sopenharmony_ci    <script src="/resources/testharness.js"></script>
101cb0ef41Sopenharmony_ci    <script src="/resources/testharnessreport.js"></script>
111cb0ef41Sopenharmony_ci  </head>
121cb0ef41Sopenharmony_ci  <body>
131cb0ef41Sopenharmony_ci    <div>
141cb0ef41Sopenharmony_ci      <p>Test step:</p>
151cb0ef41Sopenharmony_ci      <ol>
161cb0ef41Sopenharmony_ci        <li>Download <a href="support/blue-100x100.png">blue-100x100.png</a> to local.</li>
171cb0ef41Sopenharmony_ci        <li>Select the local file (blue-100x100.png) to run the test.</li>
181cb0ef41Sopenharmony_ci      </ol>
191cb0ef41Sopenharmony_ci    </div>
201cb0ef41Sopenharmony_ci
211cb0ef41Sopenharmony_ci    <form name="uploadData">
221cb0ef41Sopenharmony_ci      <input type="file" id="fileChooser">
231cb0ef41Sopenharmony_ci    </form>
241cb0ef41Sopenharmony_ci
251cb0ef41Sopenharmony_ci    <div id="log"></div>
261cb0ef41Sopenharmony_ci    <script>
271cb0ef41Sopenharmony_ci      var fileInput = document.querySelector('#fileChooser');
281cb0ef41Sopenharmony_ci      var reader = new FileReader();
291cb0ef41Sopenharmony_ci
301cb0ef41Sopenharmony_ci      //readType: 1-> ArrayBuffer, 2-> Text, 3-> DataURL
311cb0ef41Sopenharmony_ci      var readType = 1;
321cb0ef41Sopenharmony_ci
331cb0ef41Sopenharmony_ci      setup({
341cb0ef41Sopenharmony_ci        explicit_done: true,
351cb0ef41Sopenharmony_ci        explicit_timeout: true,
361cb0ef41Sopenharmony_ci      });
371cb0ef41Sopenharmony_ci
381cb0ef41Sopenharmony_ci      on_event(fileInput, "change", function(evt) {
391cb0ef41Sopenharmony_ci        reader.readAsArrayBuffer(fileInput.files[0]);
401cb0ef41Sopenharmony_ci      });
411cb0ef41Sopenharmony_ci
421cb0ef41Sopenharmony_ci      on_event(reader, "load", function(evt) {
431cb0ef41Sopenharmony_ci        if (readType == 1) {
441cb0ef41Sopenharmony_ci          test(function() {
451cb0ef41Sopenharmony_ci            assert_true(reader.result instanceof ArrayBuffer, "The result is instanceof ArrayBuffer");
461cb0ef41Sopenharmony_ci          }, "Check if the readAsArrayBuffer works");
471cb0ef41Sopenharmony_ci
481cb0ef41Sopenharmony_ci          readType++;
491cb0ef41Sopenharmony_ci          reader.readAsText(fileInput.files[0]);
501cb0ef41Sopenharmony_ci        } else if (readType == 2) {
511cb0ef41Sopenharmony_ci          test(function() {
521cb0ef41Sopenharmony_ci            assert_equals(typeof reader.result, "string", "The result is typeof string");
531cb0ef41Sopenharmony_ci          }, "Check if the readAsText works");
541cb0ef41Sopenharmony_ci
551cb0ef41Sopenharmony_ci          readType++;
561cb0ef41Sopenharmony_ci          reader.readAsDataURL(fileInput.files[0]);
571cb0ef41Sopenharmony_ci        } else if (readType == 3) {
581cb0ef41Sopenharmony_ci          test(function() {
591cb0ef41Sopenharmony_ci            assert_equals(typeof reader.result, "string", "The result is typeof string");
601cb0ef41Sopenharmony_ci            assert_equals(reader.result.indexOf("data"), 0, "The result starts with 'data'");
611cb0ef41Sopenharmony_ci            assert_true(reader.result.indexOf("base64") > 0, "The result contains 'base64'");
621cb0ef41Sopenharmony_ci          }, "Check if the readAsDataURL works");
631cb0ef41Sopenharmony_ci
641cb0ef41Sopenharmony_ci          done();
651cb0ef41Sopenharmony_ci        }
661cb0ef41Sopenharmony_ci      });
671cb0ef41Sopenharmony_ci    </script>
681cb0ef41Sopenharmony_ci  </body>
691cb0ef41Sopenharmony_ci</html>
70