OLD | NEW |
1 <!DOCTYPE html> | 1 <!DOCTYPE html> |
2 <html> | 2 <html> |
3 <head> | 3 <head> |
4 <script src="../resources/js-test.js"></script> | 4 <script src="../resources/js-test.js"></script> |
5 <script src="resources/common.js"></script> | 5 <script src="resources/common.js"></script> |
6 </head> | 6 </head> |
7 <body> | 7 <body> |
8 <p id="description"></p> | 8 <p id="description"></p> |
9 <div id="console"></div> | 9 <div id="console"></div> |
10 | 10 |
11 <script> | 11 <script> |
12 description("Tests incorrect calls to crypto.subtle.digest()"); | 12 description("Tests incorrect calls to crypto.subtle.digest()"); |
13 | 13 |
14 jsTestIsAsync = true; | 14 jsTestIsAsync = true; |
15 | 15 |
16 // Pass invalid data to digest() | 16 // Called with too few parameters. |
17 shouldThrow("crypto.subtle.digest({name: 'sha-1'})"); | 17 shouldThrow("crypto.subtle.digest({name: 'sha-1'})"); |
18 shouldThrow("crypto.subtle.digest({name: 'sha-1'}, null)"); | |
19 shouldThrow("crypto.subtle.digest({name: 'sha-1'}, 10)"); | |
20 | |
21 // Pass invalid algorithmIdentifiers to digest() | |
22 data = new Uint8Array([0]); | |
23 shouldThrow("crypto.subtle.digest(null, data)"); | |
24 | 18 |
25 Promise.resolve(null).then(function(result) { | 19 Promise.resolve(null).then(function(result) { |
| 20 // "null" is not a valid data argument. |
| 21 return crypto.subtle.digest({name: 'sha-1'}, null); |
| 22 }).then(failAndFinishJSTest, function(result) { |
| 23 error = result; |
| 24 shouldBeNull("error"); |
| 25 |
| 26 // 10 is not a valid data argument. |
| 27 return crypto.subtle.digest({name: 'sha-1'}, 10); |
| 28 }).then(failAndFinishJSTest, function(result) { |
| 29 error = result; |
| 30 shouldBeNull("error"); |
| 31 |
| 32 // null is not a valid algorithm argument. |
| 33 data = new Uint8Array([0]); |
| 34 return crypto.subtle.digest(null, data); |
| 35 }).then(failAndFinishJSTest, function(result) { |
| 36 error = result; |
| 37 shouldBeNull("error"); |
| 38 |
26 // "sha" is not a recognized algorithm name | 39 // "sha" is not a recognized algorithm name |
27 return crypto.subtle.digest({name: 'sha'}, data); | 40 return crypto.subtle.digest({name: 'sha'}, data); |
28 }).then(failAndFinishJSTest, function(result) { | 41 }).then(failAndFinishJSTest, function(result) { |
29 error = result; | 42 error = result; |
30 shouldBeNull("error"); | 43 shouldBeNull("error"); |
31 | 44 |
32 // Algorithm lacks a name. | 45 // Algorithm lacks a name. |
33 return crypto.subtle.digest({}, data); | 46 return crypto.subtle.digest({}, data); |
34 }).then(failAndFinishJSTest, function(result) { | 47 }).then(failAndFinishJSTest, function(result) { |
35 error = result; | 48 error = result; |
36 shouldBeNull("error"); | 49 shouldBeNull("error"); |
37 | 50 |
38 }).then(finishJSTest, failAndFinishJSTest); | 51 }).then(finishJSTest, failAndFinishJSTest); |
39 | 52 |
40 </script> | 53 </script> |
41 | 54 |
42 </body> | 55 </body> |
43 </html> | 56 </html> |
OLD | NEW |