summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/workers/Worker-simultaneous-errors.html
blob: 4339f2e33436010e0f05ea3d2c5f4ec26039cef0 (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
<!DOCTYPE html>
<title>Test simultaneous errors on workers.</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script>
promise_test(t => {
    var workers = 4;
    var promises = [];

    for (i = 0; i < workers; ++i) {
        var worker = new Worker('support/throw-on-message-Worker.js');
        promises.push(new Promise(function(resolve, reject) {
            var error = 0;
            worker.onmessage = function(event) {
                if (event.data === 'second')
                    resolve(error);
                else if (event.data === 'error')
                    ++error;
            }
        }));
        worker.postMessage('first');
        worker.postMessage('second');
    }

    return Promise.all(promises).then(e => {
        var sum = 0;
        for (var key in e) {
            sum += e[key]
        }
        assert_equals(sum, workers);
    });
});
</script>