gecko-dev/testing/web-platform/tests/WebCryptoAPI/test_getRandomValues.html

48 lines
2.1 KiB
HTML

<!DOCTYPE HTML>
<meta charset=utf-8>
<title>WebCryptoAPI: getRandomValues()</title>
<link rel="author" title="Sunil Yoo" href="mailto:usuanday83@gmail.com">
<link rel="help" href="https://dvcs.w3.org/hg/webcrypto-api/raw-file/tip/spec/Overview.html#dfn-Crypto-method-getRandomValues">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<div id="log"></div>
<script>
// Step 1.
test(function() {
assert_throws("TypeMismatchError", function() {
window.crypto.getRandomValues(new Float32Array(6))
}, "Float32Array")
assert_throws("TypeMismatchError", function() {
window.crypto.getRandomValues(new Float64Array(6))
}, "Float64Array")
assert_throws("TypeMismatchError", function() {
window.crypto.getRandomValues(new Float32Array(65537))
}, "Float32Array (too long)")
assert_throws("TypeMismatchError", function() {
window.crypto.getRandomValues(new Float64Array(65537))
}, "Float64Array (too long)")
}, "Float arrays")
test(function() {
assert_equals(window.crypto.getRandomValues(new Int8Array(8)).constructor,
Int8Array, "crypto.getRandomValues(new Int8Array(8))")
assert_equals(window.crypto.getRandomValues(new Uint8Array(8)).constructor,
Uint8Array, "crypto.getRandomValues(new Uint8Array(8))")
assert_equals(window.crypto.getRandomValues(new Int16Array(8)).constructor,
Int16Array, "crypto.getRandomValues(new Int16Array(8))")
assert_equals(window.crypto.getRandomValues(new Uint16Array(8)).constructor,
Uint16Array, "crypto.getRandomValues(new Uint16Array(8))")
assert_equals(window.crypto.getRandomValues(new Int32Array(8)).constructor,
Int32Array, "crypto.getRandomValues(new Int32Array(8))")
assert_equals(window.crypto.getRandomValues(new Uint32Array(8)).constructor,
Uint32Array, "crypto.getRandomValues(new Uint32Array(8))")
assert_throws("QuotaExceededError", function() {
window.crypto.getRandomValues(new Int8Array(65537))
}, "crypto.getRandomValues length over 65536")
})
</script>