Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(30)

Side by Side Diff: LayoutTests/crypto/worker-random-values-concurrent.html

Issue 16820007: Expose crypto.getRandomValues() to workers. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Rebase on master Created 7 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 <!DOCTYPE html>
2 <html>
3 <head>
4 <script src="../fast/js/resources/js-test-pre.js"></script>
5 </head>
6 <body>
7 <p id="description"></p>
8 <div id="console"></div>
9
10 <script>
11 description("Tests concurrent calls to crypto.randomValues from workers.");
12
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;
18
19 self.jsTestIsAsync = true;
20
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)
25 {
26 if (bytes.length != 100)
27 throw "bytes is not the right length: " + bytes.length;
28
29 var bytesStr = Array.prototype.join.call(bytes, '');
30
31 if (bytesStr in randomValues)
32 debug("Generated a duplicate 'random' number: " + bytesStr);
33 else
34 debug("Received random bytes from worker");
35
36 randomValues[bytesStr] = true;
37
38 if (++numRandomValues == NUM_WORKERS)
39 finishJSTest();
40 }
41
42 for (var i = 0; i < NUM_WORKERS; ++i) {
43 var worker = new Worker('resources/random-values-concurrent.js');
44 worker.onmessage = function(event)
45 {
46 if (event.data instanceof Uint8Array)
47 workerGeneratedRandomBytes(event.data);
48 else
49 debug('[Worker] ' + event.data);
50 }
51 worker.onerror = function(event)
52 {
53 debug('Got error from worker: ' + event.message);
54 finishJSTest();
55 }
56 }
57 </script>
58
59 <script src="../fast/js/resources/js-test-post.js"></script>
60 </body>
61 </html>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698