summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/FileAPI/blob/Blob-text.any.js
blob: d04fa97cffe6a3d81f520f7ac92ac44e699fa004 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
// META: title=Blob Text
// META: script=../support/Blob.js
'use strict';

promise_test(async () => {
  const blob = new Blob(["PASS"]);
  const text = await blob.text();
  assert_equals(text, "PASS");
}, "Blob.text()")

promise_test(async () => {
  const blob = new Blob();
  const text = await blob.text();
  assert_equals(text, "");
}, "Blob.text() empty blob data")

promise_test(async () => {
  const blob = new Blob(["P", "A", "SS"]);
  const text = await blob.text();
  assert_equals(text, "PASS");
}, "Blob.text() multi-element array in constructor")

promise_test(async () => {
  const non_unicode = "\u0061\u030A";
  const input_arr = new TextEncoder().encode(non_unicode);
  const blob = new Blob([input_arr]);
  const text = await blob.text();
  assert_equals(text, non_unicode);
}, "Blob.text() non-unicode")

promise_test(async () => {
  const blob = new Blob(["PASS"], { type: "text/plain;charset=utf-16le" });
  const text = await blob.text();
  assert_equals(text, "PASS");
}, "Blob.text() different charset param in type option")

promise_test(async () => {
  const non_unicode = "\u0061\u030A";
  const input_arr = new TextEncoder().encode(non_unicode);
  const blob = new Blob([input_arr], { type: "text/plain;charset=utf-16le" });
  const text = await blob.text();
  assert_equals(text, non_unicode);
}, "Blob.text() different charset param with non-ascii input")

promise_test(async () => {
  const input_arr = new Uint8Array([192, 193, 245, 246, 247, 248, 249, 250, 251,
      252, 253, 254, 255]);
  const blob = new Blob([input_arr]);
  const text = await blob.text();
  assert_equals(text, "\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd" +
      "\ufffd\ufffd\ufffd\ufffd");
}, "Blob.text() invalid utf-8 input")

promise_test(async () => {
  const input_arr = new Uint8Array([192, 193, 245, 246, 247, 248, 249, 250, 251,
      252, 253, 254, 255]);
  const blob = new Blob([input_arr]);
  const text_results = await Promise.all([blob.text(), blob.text(),
      blob.text()]);
  for (let text of text_results) {
    assert_equals(text, "\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd" +
        "\ufffd\ufffd\ufffd\ufffd");
  }
}, "Blob.text() concurrent reads")