Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / third_party / WebKit / LayoutTests / crypto / worker-random-values-concurrent.html
blob23ca6b4e3a8de10494df5233a742e616d9bfe922
1 <!DOCTYPE html>
2 <html>
3 <head>
4 <script src="../resources/js-test.js"></script>
5 </head>
6 <body>
7 <p id="description"></p>
8 <div id="console"></div>
10 <script>
11 description("Tests concurrent calls to crypto.randomValues from workers.");
13 // Generate random values from different 10 workers, and wait until they
14 // have all finished.
15 var randomValues = {};
16 var numRandomValues = 0;
17 var NUM_WORKERS = 10;
19 self.jsTestIsAsync = true;
21 // Asserts that each call to receivedRandomValue() contains unique bytes.
22 // The bytes are 100 randomly generated, and as such have an extremely low
23 // probability of matching each other.
24 function workerGeneratedRandomBytes(bytes)
26 if (bytes.length != 100)
27 throw "bytes is not the right length: " + bytes.length;
29 var bytesStr = Array.prototype.join.call(bytes, '');
31 if (bytesStr in randomValues)
32 debug("Generated a duplicate 'random' number: " + bytesStr);
33 else
34 debug("Received random bytes from worker");
36 randomValues[bytesStr] = true;
38 if (++numRandomValues == NUM_WORKERS)
39 finishJSTest();
42 for (var i = 0; i < NUM_WORKERS; ++i) {
43 var worker = new Worker('random-values-concurrent.js');
44 worker.onmessage = function(event)
46 if (event.data instanceof Uint8Array)
47 workerGeneratedRandomBytes(event.data);
48 else
49 debug('[Worker] ' + event.data);
51 worker.onerror = function(event)
53 debug('Got error from worker: ' + event.message);
54 finishJSTest();
57 </script>
59 </body>
60 </html>