tor-browser

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

Blob-text.any.js (2206B)


      1 // META: title=Blob Text
      2 // META: script=../support/Blob.js
      3 'use strict';
      4 
      5 promise_test(async () => {
      6  const blob = new Blob(["PASS"]);
      7  const text = await blob.text();
      8  assert_equals(text, "PASS");
      9 }, "Blob.text()")
     10 
     11 promise_test(async () => {
     12  const blob = new Blob();
     13  const text = await blob.text();
     14  assert_equals(text, "");
     15 }, "Blob.text() empty blob data")
     16 
     17 promise_test(async () => {
     18  const blob = new Blob(["P", "A", "SS"]);
     19  const text = await blob.text();
     20  assert_equals(text, "PASS");
     21 }, "Blob.text() multi-element array in constructor")
     22 
     23 promise_test(async () => {
     24  const non_unicode = "\u0061\u030A";
     25  const input_arr = new TextEncoder().encode(non_unicode);
     26  const blob = new Blob([input_arr]);
     27  const text = await blob.text();
     28  assert_equals(text, non_unicode);
     29 }, "Blob.text() non-unicode")
     30 
     31 promise_test(async () => {
     32  const blob = new Blob(["PASS"], { type: "text/plain;charset=utf-16le" });
     33  const text = await blob.text();
     34  assert_equals(text, "PASS");
     35 }, "Blob.text() different charset param in type option")
     36 
     37 promise_test(async () => {
     38  const non_unicode = "\u0061\u030A";
     39  const input_arr = new TextEncoder().encode(non_unicode);
     40  const blob = new Blob([input_arr], { type: "text/plain;charset=utf-16le" });
     41  const text = await blob.text();
     42  assert_equals(text, non_unicode);
     43 }, "Blob.text() different charset param with non-ascii input")
     44 
     45 promise_test(async () => {
     46  const input_arr = new Uint8Array([192, 193, 245, 246, 247, 248, 249, 250, 251,
     47      252, 253, 254, 255]);
     48  const blob = new Blob([input_arr]);
     49  const text = await blob.text();
     50  assert_equals(text, "\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd" +
     51      "\ufffd\ufffd\ufffd\ufffd");
     52 }, "Blob.text() invalid utf-8 input")
     53 
     54 promise_test(async () => {
     55  const input_arr = new Uint8Array([192, 193, 245, 246, 247, 248, 249, 250, 251,
     56      252, 253, 254, 255]);
     57  const blob = new Blob([input_arr]);
     58  const text_results = await Promise.all([blob.text(), blob.text(),
     59      blob.text()]);
     60  for (let text of text_results) {
     61    assert_equals(text, "\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd" +
     62        "\ufffd\ufffd\ufffd\ufffd");
     63  }
     64 }, "Blob.text() concurrent reads")