crypto-random-values.html 1.05 KB
Newer Older
1 2 3
<!DOCTYPE html>
<html>
<head>
4
<script src="../resources/js-test-pre.js"></script>
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 34 35 36 37 38 39 40 41 42
<script src="resources/utilities.js"></script>
</head>
<body>
<p id="description"></p>
<div id="console"></div>
<script>
description("Tests crypto.randomValues.");

if (!window.ArrayBuffer)
    debug("This test requres ArrayBuffers to run!");

shouldBe("'crypto' in window", "true");
shouldBe("'getRandomValues' in window.crypto", "true");

try {
    // FIXME: This test is flaky.  If we ran this test every second since the
    //        beginning of the universe, on average, it would have failed
    //        2^{-748} times.

    var reference = new Uint8Array(100);
    var sample = new Uint8Array(100);

    crypto.getRandomValues(reference);
    crypto.getRandomValues(sample);

    var matchingBytes = 0;

    for (var i = 0; i < reference.length; i++) {
        if (reference[i] == sample[i])
            matchingBytes++;
    }

    shouldBe("matchingBytes < 100", "true");
} catch(ex) {
    debug(ex);
}

</script>
43
<script src="../resources/js-test-post.js"></script>
44 45 46 47
</body>
</html>