OLD | NEW |
| (Empty) |
1 if (self.importScripts) | |
2 importScripts('../../resources/js-test.js'); | |
3 | |
4 description("Tests which types are valid for crypto.randomValues."); | |
5 | |
6 if (!self.ArrayBuffer) | |
7 debug("This test requres ArrayBuffers to run!"); | |
8 | |
9 shouldBe("'crypto' in self", "true"); | |
10 shouldBe("'getRandomValues' in self.crypto", "true"); | |
11 | |
12 function checkIntegerTypes() { | |
13 var integerTypes = [ | |
14 "Uint8Array", "Int8Array", "Uint8ClampedArray", | |
15 "Uint16Array", "Int16Array", | |
16 "Uint32Array", "Int32Array", | |
17 ]; | |
18 integerTypes.forEach(function(arrayType) { | |
19 shouldBeDefined("random = crypto.getRandomValues(new "+arrayType+"(3))")
; | |
20 shouldBeType("random", arrayType); | |
21 | |
22 shouldBeDefined("view = new "+arrayType+"(3)"); | |
23 shouldBeDefined("random = crypto.getRandomValues(view)"); | |
24 shouldBe("random", "view"); | |
25 }); | |
26 } | |
27 | |
28 function checkNonIntegerTypes() { | |
29 var floatTypes = [ | |
30 "Float32Array", "Float64Array", | |
31 ]; | |
32 floatTypes.forEach(function(arrayType) { | |
33 shouldThrow("crypto.getRandomValues(new "+arrayType+"(3))"); | |
34 }); | |
35 | |
36 shouldBeDefined("buffer = new Uint8Array(32)"); | |
37 shouldBeDefined("buffer.buffer"); | |
38 shouldBeDefined("view = new DataView(buffer.buffer)"); | |
39 shouldThrow("crypto.getRandomValues(view)"); | |
40 } | |
41 | |
42 shouldThrow("crypto.getRandomValues()"); | |
43 shouldThrow("crypto.getRandomValues(undefined)"); | |
44 shouldThrow("crypto.getRandomValues(null)"); | |
45 checkIntegerTypes(); | |
46 checkNonIntegerTypes(); | |
47 | |
48 finishJSTest(); | |
OLD | NEW |