File: blobs.html

package info (click to toggle)
firefox 143.0.3-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 4,617,328 kB
  • sloc: cpp: 7,478,492; javascript: 6,417,157; ansic: 3,720,058; python: 1,396,372; xml: 627,523; asm: 438,677; java: 186,156; sh: 63,477; makefile: 19,171; objc: 13,059; perl: 12,983; yacc: 4,583; cs: 3,846; pascal: 3,405; lex: 1,720; ruby: 1,003; exp: 762; php: 436; lisp: 258; awk: 247; sql: 66; sed: 53; csh: 10
file content (82 lines) | stat: -rw-r--r-- 2,674 bytes parent folder | download | duplicates (20)
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
<!DOCTYPE html>
<meta charset=utf-8>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/common/gc.js"></script>
<script>
async_test(t => {
    const c1 = new BroadcastChannel('blob');
    const c2 = new BroadcastChannel('blob');
    const c3 = new BroadcastChannel('blob');

    let readCount = 0;
    c2.onmessage = t.step_func(e => {
        // check blob
        assert_true('blob' in e.data);
        assert_true(e.data.blob instanceof Blob);
        assert_equals(e.data.blob.size, 6);
        const reader = new FileReader();
        reader.onerror = t.unreached_func();
        reader.onload = t.step_func(() => {
            assert_equals(reader.result, 'foobar');
            if (++readCount == 2)
              t.done();
          });
        reader.readAsText(e.data.blob);
      });
    c3.onmessage = c2.onmessage;
    (() => {
      c1.postMessage({blob: new Blob(['foo', 'bar'])});
    })();
    garbageCollect();
  }, 'Blobs work on BroadcastChannel');

async_test(t => {
    const c1 = new BroadcastChannel('blobworker');
    const c2 = new BroadcastChannel('blobworker');
    const events = [];

    const verifyEvents = function() {
        assert_equals(events.length, 5);
        assert_equals(events[0], 'from worker');
        assert_equals(events[1], 'from worker');
        assert_true(events[2].blob instanceof Blob);
        assert_equals(events[2].blob.size, 11);
        assert_true(events[3].blob instanceof Blob);
        assert_equals(events[3].blob.size, 11);
        assert_equals(events[4], 'done');
        const reader = new FileReader();
        reader.onerror = t.unreached_func();
        reader.onload = t.step_func(() => {
            assert_equals(reader.result, 'hello-world');
            t.done();
          });
        reader.readAsText(events[3].blob);
    };

    let receivedDone = false;
    let receivedWorkerDone = false;

    c1.onmessage = e => events.push(e.data);
    c2.onmessage = e => events.push(e.data);
    c2.addEventListener('message', t.step_func(e => {
        if (e.data.blob)
          c1.postMessage('done');
        if (e.data === 'done')
          receivedDone = true;
        if (receivedDone && receivedWorkerDone)
          verifyEvents();
      }));

    const worker = new Worker('resources/worker.js');
    worker.onmessage = t.step_func(e => {
        receivedWorkerDone = true;
        if (receivedDone && receivedWorkerDone)
          verifyEvents();
      });
    worker.postMessage({channel: 'blobworker'});
    worker.postMessage({blob: ['hello-world']});

  }, 'Blobs work with workers on BroadcastChannel');

</script>