tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

Determining-Encoding.any.js (2891B)


      1 // META: title=FileAPI Test: Blob Determining Encoding
      2 
      3 var t = async_test("Blob Determing Encoding with encoding argument");
      4 t.step(function() {
      5    // string 'hello'
      6    var data = [0xFE,0xFF,0x00,0x68,0x00,0x65,0x00,0x6C,0x00,0x6C,0x00,0x6F];
      7    var blob = new Blob([new Uint8Array(data)]);
      8    var reader = new FileReader();
      9 
     10    reader.onloadend = t.step_func_done (function(event) {
     11        assert_equals(this.result, "hello", "The FileReader should read the ArrayBuffer through UTF-16BE.")
     12    }, reader);
     13 
     14    reader.readAsText(blob, "UTF-16BE");
     15 });
     16 
     17 var t = async_test("Blob Determing Encoding with type attribute");
     18 t.step(function() {
     19    var data = [0xFE,0xFF,0x00,0x68,0x00,0x65,0x00,0x6C,0x00,0x6C,0x00,0x6F];
     20    var blob = new Blob([new Uint8Array(data)], {type:"text/plain;charset=UTF-16BE"});
     21    var reader = new FileReader();
     22 
     23    reader.onloadend = t.step_func_done (function(event) {
     24        assert_equals(this.result, "hello", "The FileReader should read the ArrayBuffer through UTF-16BE.")
     25    }, reader);
     26 
     27    reader.readAsText(blob);
     28 });
     29 
     30 
     31 var t = async_test("Blob Determing Encoding with UTF-8 BOM");
     32 t.step(function() {
     33    var data = [0xEF,0xBB,0xBF,0x68,0x65,0x6C,0x6C,0xC3,0xB6];
     34    var blob = new Blob([new Uint8Array(data)]);
     35    var reader = new FileReader();
     36 
     37    reader.onloadend = t.step_func_done (function(event) {
     38        assert_equals(this.result, "hellö", "The FileReader should read the blob with UTF-8.");
     39    }, reader);
     40 
     41    reader.readAsText(blob);
     42 });
     43 
     44 var t = async_test("Blob Determing Encoding without anything implying charset.");
     45 t.step(function() {
     46    var data = [0x68,0x65,0x6C,0x6C,0xC3,0xB6];
     47    var blob = new Blob([new Uint8Array(data)]);
     48    var reader = new FileReader();
     49 
     50    reader.onloadend = t.step_func_done (function(event) {
     51        assert_equals(this.result, "hellö", "The FileReader should read the blob by default with UTF-8.");
     52    }, reader);
     53 
     54    reader.readAsText(blob);
     55 });
     56 
     57 var t = async_test("Blob Determing Encoding with UTF-16BE BOM");
     58 t.step(function() {
     59    var data = [0xFE,0xFF,0x00,0x68,0x00,0x65,0x00,0x6C,0x00,0x6C,0x00,0x6F];
     60    var blob = new Blob([new Uint8Array(data)]);
     61    var reader = new FileReader();
     62 
     63    reader.onloadend = t.step_func_done (function(event) {
     64        assert_equals(this.result, "hello", "The FileReader should read the ArrayBuffer through UTF-16BE.");
     65    }, reader);
     66 
     67    reader.readAsText(blob);
     68 });
     69 
     70 var t = async_test("Blob Determing Encoding with UTF-16LE BOM");
     71 t.step(function() {
     72    var data = [0xFF,0xFE,0x68,0x00,0x65,0x00,0x6C,0x00,0x6C,0x00,0x6F,0x00];
     73    var blob = new Blob([new Uint8Array(data)]);
     74    var reader = new FileReader();
     75 
     76    reader.onloadend = t.step_func_done (function(event) {
     77        assert_equals(this.result, "hello", "The FileReader should read the ArrayBuffer through UTF-16LE.");
     78    }, reader);
     79 
     80    reader.readAsText(blob);
     81 });