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 exportKey() given bad inputs."); | 12 description("Tests exportKey() given bad inputs."); |
13 | 13 |
14 jsTestIsAsync = true; | 14 jsTestIsAsync = true; |
15 | 15 |
16 // Not keys | |
17 shouldThrow("crypto.subtle.exportKey('raw', null)"); | |
18 shouldThrow("crypto.subtle.exportKey('raw', 3)"); | |
19 | |
20 function importAesKey() | 16 function importAesKey() |
21 { | 17 { |
22 var keyData = new Uint8Array(16); | 18 var keyData = new Uint8Array(16); |
23 var usages = ['encrypt']; | 19 var usages = ['encrypt']; |
24 var extractable = true; | 20 var extractable = true; |
25 var algorithm = {name: 'aes-cbc'}; | 21 var algorithm = {name: 'aes-cbc'}; |
26 | 22 |
27 return crypto.subtle.importKey('raw', keyData, algorithm, extractable, usage
s); | 23 return crypto.subtle.importKey('raw', keyData, algorithm, extractable, usage
s); |
28 } | 24 } |
29 | 25 |
30 importAesKey().then(function(result) { | 26 Promise.resolve(null).then(function(result) { |
| 27 // null is not a valid Key. |
| 28 return crypto.subtle.exportKey('raw', null); |
| 29 }).then(failAndFinishJSTest, function(result) { |
| 30 error = result; |
| 31 shouldBeNull("error"); |
| 32 |
| 33 // 3 is not a valid Key. |
| 34 return crypto.subtle.exportKey('raw', 3); |
| 35 }).then(failAndFinishJSTest, function(result) { |
| 36 error = result; |
| 37 shouldBeNull("error"); |
| 38 |
| 39 return importAesKey(); |
| 40 }).then(function(result) { |
31 key = result; | 41 key = result; |
32 | 42 |
33 // Invalid export format | 43 // Invalid export format |
34 return crypto.subtle.exportKey(3, key); | 44 return crypto.subtle.exportKey(3, key); |
35 }).then(failAndFinishJSTest, function(result) { | 45 }).then(failAndFinishJSTest, function(result) { |
36 error = result; | 46 error = result; |
37 shouldBeNull("error"); | 47 shouldBeNull("error"); |
38 | 48 |
39 // Invalid export format | 49 // Invalid export format |
40 return crypto.subtle.exportKey(null, key); | 50 return crypto.subtle.exportKey(null, key); |
41 }).then(failAndFinishJSTest, function(result) { | 51 }).then(failAndFinishJSTest, function(result) { |
42 error = result; | 52 error = result; |
43 shouldBeNull("error"); | 53 shouldBeNull("error"); |
44 | 54 |
45 // Invalid export format | 55 // Invalid export format |
46 return crypto.subtle.exportKey('invalid', key); | 56 return crypto.subtle.exportKey('invalid', key); |
47 }).then(failAndFinishJSTest, function(result) { | 57 }).then(failAndFinishJSTest, function(result) { |
48 error = result; | 58 error = result; |
49 shouldBeNull("error"); | 59 shouldBeNull("error"); |
50 }).then(finishJSTest, failAndFinishJSTest); | 60 }).then(finishJSTest, failAndFinishJSTest); |
51 | 61 |
52 </script> | 62 </script> |
53 | 63 |
54 </body> | 64 </body> |
55 </html> | 65 </html> |
OLD | NEW |