11cb0ef41Sopenharmony_ci<!DOCTYPE html> 21cb0ef41Sopenharmony_ci<html> 31cb0ef41Sopenharmony_ci <head> 41cb0ef41Sopenharmony_ci <meta charset="utf-8"> 51cb0ef41Sopenharmony_ci <title>FileAPI Test: filereader_readAsText</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/#readAsDataText"> 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 async_test(function() { 161cb0ef41Sopenharmony_ci var blob = new Blob(["TEST"]); 171cb0ef41Sopenharmony_ci var reader = new FileReader(); 181cb0ef41Sopenharmony_ci 191cb0ef41Sopenharmony_ci reader.onload = this.step_func(function(evt) { 201cb0ef41Sopenharmony_ci assert_equals(typeof reader.result, "string", "The result is typeof string"); 211cb0ef41Sopenharmony_ci assert_equals(reader.result, "TEST", "The result is TEST"); 221cb0ef41Sopenharmony_ci this.done(); 231cb0ef41Sopenharmony_ci }); 241cb0ef41Sopenharmony_ci 251cb0ef41Sopenharmony_ci reader.onloadstart = this.step_func(function(evt) { 261cb0ef41Sopenharmony_ci assert_equals(reader.readyState, reader.LOADING, "The readyState"); 271cb0ef41Sopenharmony_ci }); 281cb0ef41Sopenharmony_ci 291cb0ef41Sopenharmony_ci reader.onprogress = this.step_func(function(evt) { 301cb0ef41Sopenharmony_ci assert_equals(reader.readyState, reader.LOADING); 311cb0ef41Sopenharmony_ci }); 321cb0ef41Sopenharmony_ci 331cb0ef41Sopenharmony_ci reader.readAsText(blob); 341cb0ef41Sopenharmony_ci }, "readAsText should correctly read UTF-8."); 351cb0ef41Sopenharmony_ci 361cb0ef41Sopenharmony_ci async_test(function() { 371cb0ef41Sopenharmony_ci var blob = new Blob(["TEST"]); 381cb0ef41Sopenharmony_ci var reader = new FileReader(); 391cb0ef41Sopenharmony_ci var reader_UTF16 = new FileReader(); 401cb0ef41Sopenharmony_ci reader_UTF16.onload = this.step_func(function(evt) { 411cb0ef41Sopenharmony_ci // "TEST" in UTF-8 is 0x54 0x45 0x53 0x54. 421cb0ef41Sopenharmony_ci // Decoded as utf-16 (little-endian), we get 0x4554 0x5453. 431cb0ef41Sopenharmony_ci assert_equals(reader_UTF16.readyState, reader.DONE, "The readyState"); 441cb0ef41Sopenharmony_ci assert_equals(reader_UTF16.result, "\u4554\u5453", "The result is not TEST"); 451cb0ef41Sopenharmony_ci this.done(); 461cb0ef41Sopenharmony_ci }); 471cb0ef41Sopenharmony_ci reader_UTF16.readAsText(blob, "UTF-16"); 481cb0ef41Sopenharmony_ci }, "readAsText should correctly read UTF-16."); 491cb0ef41Sopenharmony_ci </script> 501cb0ef41Sopenharmony_ci </body> 511cb0ef41Sopenharmony_ci</html> 52