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

Unified 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 side-by-side diff with in-line comments
Download patch
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>

Powered by Google App Engine
This is Rietveld 408576698