Index: LayoutTests/crypto/worker-random-values-concurrent.html |
diff --git a/LayoutTests/crypto/worker-random-values-concurrent.html b/LayoutTests/crypto/worker-random-values-concurrent.html |
new file mode 100644 |
index 0000000000000000000000000000000000000000..5f42f84758dad2412777fe2f365104433bc8ddde |
--- /dev/null |
+++ b/LayoutTests/crypto/worker-random-values-concurrent.html |
@@ -0,0 +1,61 @@ |
+<!DOCTYPE html> |
+<html> |
+<head> |
+<script src="../fast/js/resources/js-test-pre.js"></script> |
+</head> |
+<body> |
+<p id="description"></p> |
+<div id="console"></div> |
+ |
+<script> |
+ description("Tests concurrent calls to crypto.randomValues from workers."); |
+ |
+ // Generate random values from different 10 workers, and wait until they |
+ // have all finished. |
+ var randomValues = {}; |
+ var numRandomValues = 0; |
+ var NUM_WORKERS = 10; |
+ |
+ self.jsTestIsAsync = true; |
+ |
+ // Asserts that each call to receivedRandomValue() contains unique bytes. |
+ // The bytes are 100 randomly generated, and as such have an extremely low |
+ // probability of matching each other. |
+ function workerGeneratedRandomBytes(bytes) |
+ { |
+ if (bytes.length != 100) |
+ throw "bytes is not the right length: " + bytes.length; |
+ |
+ var bytesStr = Array.prototype.join.call(bytes, ''); |
+ |
+ if (bytesStr in randomValues) |
+ debug("Generated a duplicate 'random' number: " + bytesStr); |
+ else |
+ debug("Received random bytes from worker"); |
+ |
+ randomValues[bytesStr] = true; |
+ |
+ if (++numRandomValues == NUM_WORKERS) |
+ finishJSTest(); |
+ } |
+ |
+ for (var i = 0; i < NUM_WORKERS; ++i) { |
+ var worker = new Worker('resources/random-values-concurrent.js'); |
+ worker.onmessage = function(event) |
+ { |
+ if (event.data instanceof Uint8Array) |
+ workerGeneratedRandomBytes(event.data); |
+ else |
+ debug('[Worker] ' + event.data); |
+ } |
+ worker.onerror = function(event) |
+ { |
+ debug('Got error from worker: ' + event.message); |
+ finishJSTest(); |
+ } |
+ } |
+</script> |
+ |
+<script src="../fast/js/resources/js-test-post.js"></script> |
+</body> |
+</html> |