1<!DOCTYPE html> 2<html> 3 <head> 4 <meta charset="utf-8"> 5 <title>FileAPI Test: filereader_readAsText</title> 6 <link rel="author" title="Intel" href="http://www.intel.com"> 7 <link rel="help" href="http://dev.w3.org/2006/webapi/FileAPI/#readAsDataText"> 8 <script src="/resources/testharness.js"></script> 9 <script src="/resources/testharnessreport.js"></script> 10 </head> 11 <body> 12 <div id="log"></div> 13 14 <script> 15 async_test(function() { 16 var blob = new Blob(["TEST"]); 17 var reader = new FileReader(); 18 19 reader.onload = this.step_func(function(evt) { 20 assert_equals(typeof reader.result, "string", "The result is typeof string"); 21 assert_equals(reader.result, "TEST", "The result is TEST"); 22 this.done(); 23 }); 24 25 reader.onloadstart = this.step_func(function(evt) { 26 assert_equals(reader.readyState, reader.LOADING, "The readyState"); 27 }); 28 29 reader.onprogress = this.step_func(function(evt) { 30 assert_equals(reader.readyState, reader.LOADING); 31 }); 32 33 reader.readAsText(blob); 34 }, "readAsText should correctly read UTF-8."); 35 36 async_test(function() { 37 var blob = new Blob(["TEST"]); 38 var reader = new FileReader(); 39 var reader_UTF16 = new FileReader(); 40 reader_UTF16.onload = this.step_func(function(evt) { 41 // "TEST" in UTF-8 is 0x54 0x45 0x53 0x54. 42 // Decoded as utf-16 (little-endian), we get 0x4554 0x5453. 43 assert_equals(reader_UTF16.readyState, reader.DONE, "The readyState"); 44 assert_equals(reader_UTF16.result, "\u4554\u5453", "The result is not TEST"); 45 this.done(); 46 }); 47 reader_UTF16.readAsText(blob, "UTF-16"); 48 }, "readAsText should correctly read UTF-16."); 49 </script> 50 </body> 51</html> 52