11cb0ef41Sopenharmony_ci<!DOCTYPE html>
21cb0ef41Sopenharmony_ci<html>
31cb0ef41Sopenharmony_ci  <head>
41cb0ef41Sopenharmony_ci    <meta charset="utf-8">
51cb0ef41Sopenharmony_ci    <title>FileAPI Test: filereader_result</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/#filedata-attr">
81cb0ef41Sopenharmony_ci    <script src="/resources/testharness.js"></script>
91cb0ef41Sopenharmony_ci    <script src="/resources/testharnessreport.js"></script>
101cb0ef41Sopenharmony_ci  </head>
111cb0ef41Sopenharmony_ci  <body>
121cb0ef41Sopenharmony_ci    <div id="log"></div>
131cb0ef41Sopenharmony_ci
141cb0ef41Sopenharmony_ci    <script>
151cb0ef41Sopenharmony_ci    var blob, blob2;
161cb0ef41Sopenharmony_ci    setup(function() {
171cb0ef41Sopenharmony_ci      blob = new Blob(["This test the result attribute"]);
181cb0ef41Sopenharmony_ci      blob2 = new Blob(["This is a second blob"]);
191cb0ef41Sopenharmony_ci    });
201cb0ef41Sopenharmony_ci
211cb0ef41Sopenharmony_ci    async_test(function() {
221cb0ef41Sopenharmony_ci      var readText = new FileReader();
231cb0ef41Sopenharmony_ci      assert_equals(readText.result, null);
241cb0ef41Sopenharmony_ci
251cb0ef41Sopenharmony_ci      readText.onloadend = this.step_func(function(evt) {
261cb0ef41Sopenharmony_ci        assert_equals(typeof readText.result, "string", "The result type is string");
271cb0ef41Sopenharmony_ci        assert_equals(readText.result, "This test the result attribute", "The result is correct");
281cb0ef41Sopenharmony_ci        this.done();
291cb0ef41Sopenharmony_ci      });
301cb0ef41Sopenharmony_ci
311cb0ef41Sopenharmony_ci      readText.readAsText(blob);
321cb0ef41Sopenharmony_ci    }, "readAsText");
331cb0ef41Sopenharmony_ci
341cb0ef41Sopenharmony_ci    async_test(function() {
351cb0ef41Sopenharmony_ci      var readDataURL = new FileReader();
361cb0ef41Sopenharmony_ci      assert_equals(readDataURL.result, null);
371cb0ef41Sopenharmony_ci
381cb0ef41Sopenharmony_ci      readDataURL.onloadend = this.step_func(function(evt) {
391cb0ef41Sopenharmony_ci        assert_equals(typeof readDataURL.result, "string", "The result type is string");
401cb0ef41Sopenharmony_ci        assert_true(readDataURL.result.indexOf("VGhpcyB0ZXN0IHRoZSByZXN1bHQgYXR0cmlidXRl") != -1, "return the right base64 string");
411cb0ef41Sopenharmony_ci        this.done();
421cb0ef41Sopenharmony_ci      });
431cb0ef41Sopenharmony_ci
441cb0ef41Sopenharmony_ci      readDataURL.readAsDataURL(blob);
451cb0ef41Sopenharmony_ci    }, "readAsDataURL");
461cb0ef41Sopenharmony_ci
471cb0ef41Sopenharmony_ci    async_test(function() {
481cb0ef41Sopenharmony_ci      var readArrayBuffer = new FileReader();
491cb0ef41Sopenharmony_ci      assert_equals(readArrayBuffer.result, null);
501cb0ef41Sopenharmony_ci
511cb0ef41Sopenharmony_ci      readArrayBuffer.onloadend = this.step_func(function(evt) {
521cb0ef41Sopenharmony_ci        assert_true(readArrayBuffer.result instanceof ArrayBuffer, "The result is instanceof ArrayBuffer");
531cb0ef41Sopenharmony_ci        this.done();
541cb0ef41Sopenharmony_ci      });
551cb0ef41Sopenharmony_ci
561cb0ef41Sopenharmony_ci      readArrayBuffer.readAsArrayBuffer(blob);
571cb0ef41Sopenharmony_ci    }, "readAsArrayBuffer");
581cb0ef41Sopenharmony_ci
591cb0ef41Sopenharmony_ci    async_test(function() {
601cb0ef41Sopenharmony_ci      var readBinaryString = new FileReader();
611cb0ef41Sopenharmony_ci      assert_equals(readBinaryString.result, null);
621cb0ef41Sopenharmony_ci
631cb0ef41Sopenharmony_ci      readBinaryString.onloadend = this.step_func(function(evt) {
641cb0ef41Sopenharmony_ci        assert_equals(typeof readBinaryString.result, "string", "The result type is string");
651cb0ef41Sopenharmony_ci        assert_equals(readBinaryString.result, "This test the result attribute", "The result is correct");
661cb0ef41Sopenharmony_ci        this.done();
671cb0ef41Sopenharmony_ci      });
681cb0ef41Sopenharmony_ci
691cb0ef41Sopenharmony_ci      readBinaryString.readAsBinaryString(blob);
701cb0ef41Sopenharmony_ci    }, "readAsBinaryString");
711cb0ef41Sopenharmony_ci
721cb0ef41Sopenharmony_ci
731cb0ef41Sopenharmony_ci    for (let event of ['loadstart', 'progress']) {
741cb0ef41Sopenharmony_ci      for (let method of ['readAsText', 'readAsDataURL', 'readAsArrayBuffer', 'readAsBinaryString']) {
751cb0ef41Sopenharmony_ci        promise_test(async function(t) {
761cb0ef41Sopenharmony_ci          var reader = new FileReader();
771cb0ef41Sopenharmony_ci          assert_equals(reader.result, null, 'result is null before read');
781cb0ef41Sopenharmony_ci
791cb0ef41Sopenharmony_ci          var eventWatcher = new EventWatcher(t, reader,
801cb0ef41Sopenharmony_ci              [event, 'loadend']);
811cb0ef41Sopenharmony_ci
821cb0ef41Sopenharmony_ci          reader[method](blob);
831cb0ef41Sopenharmony_ci          assert_equals(reader.result, null, 'result is null after first read call');
841cb0ef41Sopenharmony_ci          await eventWatcher.wait_for(event);
851cb0ef41Sopenharmony_ci          assert_equals(reader.result, null, 'result is null during event');
861cb0ef41Sopenharmony_ci          await eventWatcher.wait_for('loadend');
871cb0ef41Sopenharmony_ci          assert_not_equals(reader.result, null);
881cb0ef41Sopenharmony_ci          reader[method](blob);
891cb0ef41Sopenharmony_ci          assert_equals(reader.result, null, 'result is null after second read call');
901cb0ef41Sopenharmony_ci          await eventWatcher.wait_for(event);
911cb0ef41Sopenharmony_ci          assert_equals(reader.result, null, 'result is null during second read event');
921cb0ef41Sopenharmony_ci        }, 'result is null during "' + event + '" event for ' + method);
931cb0ef41Sopenharmony_ci      }
941cb0ef41Sopenharmony_ci    }
951cb0ef41Sopenharmony_ci    </script>
961cb0ef41Sopenharmony_ci  </body>
971cb0ef41Sopenharmony_ci</html>
98