11cb0ef41Sopenharmony_ci<!DOCTYPE html>
21cb0ef41Sopenharmony_ci<meta charset=utf-8>
31cb0ef41Sopenharmony_ci<title>FileAPI Test: Blob Determining Encoding</title>
41cb0ef41Sopenharmony_ci<link ref="author" title="march1993" href="mailto:march511@gmail.com">
51cb0ef41Sopenharmony_ci<link rel=help href="http://dev.w3.org/2006/webapi/FileAPI/#enctype">
61cb0ef41Sopenharmony_ci<link rel=help href="http://encoding.spec.whatwg.org/#decode">
71cb0ef41Sopenharmony_ci<script src="/resources/testharness.js"></script>
81cb0ef41Sopenharmony_ci<script src="/resources/testharnessreport.js"></script>
91cb0ef41Sopenharmony_ci<div id="log"></div>
101cb0ef41Sopenharmony_ci<script>
111cb0ef41Sopenharmony_civar t = async_test("Blob Determing Encoding with encoding argument");
121cb0ef41Sopenharmony_cit.step(function() {
131cb0ef41Sopenharmony_ci    // string 'hello'
141cb0ef41Sopenharmony_ci    var data = [0xFE,0xFF,0x00,0x68,0x00,0x65,0x00,0x6C,0x00,0x6C,0x00,0x6F];
151cb0ef41Sopenharmony_ci    var blob = new Blob([new Uint8Array(data)]);
161cb0ef41Sopenharmony_ci    var reader = new FileReader();
171cb0ef41Sopenharmony_ci
181cb0ef41Sopenharmony_ci    reader.onloadend = t.step_func_done (function(event) {
191cb0ef41Sopenharmony_ci        assert_equals(this.result, "hello", "The FileReader should read the ArrayBuffer through UTF-16BE.")
201cb0ef41Sopenharmony_ci    }, reader);
211cb0ef41Sopenharmony_ci
221cb0ef41Sopenharmony_ci    reader.readAsText(blob, "UTF-16BE");
231cb0ef41Sopenharmony_ci});
241cb0ef41Sopenharmony_ci
251cb0ef41Sopenharmony_civar t = async_test("Blob Determing Encoding with type attribute");
261cb0ef41Sopenharmony_cit.step(function() {
271cb0ef41Sopenharmony_ci    var data = [0xFE,0xFF,0x00,0x68,0x00,0x65,0x00,0x6C,0x00,0x6C,0x00,0x6F];
281cb0ef41Sopenharmony_ci    var blob = new Blob([new Uint8Array(data)], {type:"text/plain;charset=UTF-16BE"});
291cb0ef41Sopenharmony_ci    var reader = new FileReader();
301cb0ef41Sopenharmony_ci
311cb0ef41Sopenharmony_ci    reader.onloadend = t.step_func_done (function(event) {
321cb0ef41Sopenharmony_ci        assert_equals(this.result, "hello", "The FileReader should read the ArrayBuffer through UTF-16BE.")
331cb0ef41Sopenharmony_ci    }, reader);
341cb0ef41Sopenharmony_ci
351cb0ef41Sopenharmony_ci    reader.readAsText(blob);
361cb0ef41Sopenharmony_ci});
371cb0ef41Sopenharmony_ci
381cb0ef41Sopenharmony_ci
391cb0ef41Sopenharmony_civar t = async_test("Blob Determing Encoding with UTF-8 BOM");
401cb0ef41Sopenharmony_cit.step(function() {
411cb0ef41Sopenharmony_ci    var data = [0xEF,0xBB,0xBF,0x68,0x65,0x6C,0x6C,0xC3,0xB6];
421cb0ef41Sopenharmony_ci    var blob = new Blob([new Uint8Array(data)]);
431cb0ef41Sopenharmony_ci    var reader = new FileReader();
441cb0ef41Sopenharmony_ci
451cb0ef41Sopenharmony_ci    reader.onloadend = t.step_func_done (function(event) {
461cb0ef41Sopenharmony_ci        assert_equals(this.result, "hellö", "The FileReader should read the blob with UTF-8.");
471cb0ef41Sopenharmony_ci    }, reader);
481cb0ef41Sopenharmony_ci
491cb0ef41Sopenharmony_ci    reader.readAsText(blob);
501cb0ef41Sopenharmony_ci});
511cb0ef41Sopenharmony_ci
521cb0ef41Sopenharmony_civar t = async_test("Blob Determing Encoding without anything implying charset.");
531cb0ef41Sopenharmony_cit.step(function() {
541cb0ef41Sopenharmony_ci    var data = [0x68,0x65,0x6C,0x6C,0xC3,0xB6];
551cb0ef41Sopenharmony_ci    var blob = new Blob([new Uint8Array(data)]);
561cb0ef41Sopenharmony_ci    var reader = new FileReader();
571cb0ef41Sopenharmony_ci
581cb0ef41Sopenharmony_ci    reader.onloadend = t.step_func_done (function(event) {
591cb0ef41Sopenharmony_ci        assert_equals(this.result, "hellö", "The FileReader should read the blob by default with UTF-8.");
601cb0ef41Sopenharmony_ci    }, reader);
611cb0ef41Sopenharmony_ci
621cb0ef41Sopenharmony_ci    reader.readAsText(blob);
631cb0ef41Sopenharmony_ci});
641cb0ef41Sopenharmony_ci
651cb0ef41Sopenharmony_civar t = async_test("Blob Determing Encoding with UTF-16BE BOM");
661cb0ef41Sopenharmony_cit.step(function() {
671cb0ef41Sopenharmony_ci    var data = [0xFE,0xFF,0x00,0x68,0x00,0x65,0x00,0x6C,0x00,0x6C,0x00,0x6F];
681cb0ef41Sopenharmony_ci    var blob = new Blob([new Uint8Array(data)]);
691cb0ef41Sopenharmony_ci    var reader = new FileReader();
701cb0ef41Sopenharmony_ci
711cb0ef41Sopenharmony_ci    reader.onloadend = t.step_func_done (function(event) {
721cb0ef41Sopenharmony_ci        assert_equals(this.result, "hello", "The FileReader should read the ArrayBuffer through UTF-16BE.");
731cb0ef41Sopenharmony_ci    }, reader);
741cb0ef41Sopenharmony_ci
751cb0ef41Sopenharmony_ci    reader.readAsText(blob);
761cb0ef41Sopenharmony_ci});
771cb0ef41Sopenharmony_ci
781cb0ef41Sopenharmony_civar t = async_test("Blob Determing Encoding with UTF-16LE BOM");
791cb0ef41Sopenharmony_cit.step(function() {
801cb0ef41Sopenharmony_ci    var data = [0xFF,0xFE,0x68,0x00,0x65,0x00,0x6C,0x00,0x6C,0x00,0x6F,0x00];
811cb0ef41Sopenharmony_ci    var blob = new Blob([new Uint8Array(data)]);
821cb0ef41Sopenharmony_ci    var reader = new FileReader();
831cb0ef41Sopenharmony_ci
841cb0ef41Sopenharmony_ci    reader.onloadend = t.step_func_done (function(event) {
851cb0ef41Sopenharmony_ci        assert_equals(this.result, "hello", "The FileReader should read the ArrayBuffer through UTF-16LE.");
861cb0ef41Sopenharmony_ci    }, reader);
871cb0ef41Sopenharmony_ci
881cb0ef41Sopenharmony_ci    reader.readAsText(blob);
891cb0ef41Sopenharmony_ci});
901cb0ef41Sopenharmony_ci
911cb0ef41Sopenharmony_ci</script>
92