| 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 calling cypto.subtle.importKey with bad parameters"); | 12 description("Tests calling cypto.subtle.importKey with bad parameters"); |
| 13 | 13 |
| 14 jsTestIsAsync = true; | 14 jsTestIsAsync = true; |
| 15 | 15 |
| 16 var aesCbc = {name: 'aes-cbc'}; | 16 var aesCbc = {name: 'aes-cbc'}; |
| 17 var aesKeyBytes = new Uint8Array(16); | 17 var aesKeyBytes = new Uint8Array(16); |
| 18 var extractable = true; | 18 var extractable = true; |
| 19 | 19 |
| 20 // Undefined key usage. | 20 // Undefined key usage. |
| 21 // FIXME: http://crbug.com/262383 | 21 // FIXME: http://crbug.com/262383 |
| 22 //shouldThrow("crypto.subtle.importKey('raw', aesKeyBytes, aesCbc, extractable,
undefined)"); | 22 //shouldThrow("crypto.subtle.importKey('raw', aesKeyBytes, aesCbc, extractable,
undefined)"); |
| 23 | 23 |
| 24 Promise.resolve(null).then(function() { | 24 Promise.resolve(null).then(function() { |
| 25 // Invalid data | 25 // Invalid data |
| 26 return crypto.subtle.importKey('raw', [], aesCbc, extractable, ['encrypt']); | 26 return crypto.subtle.importKey('raw', [], aesCbc, extractable, ['encrypt']); |
| 27 }).then(failAndFinishJSTest, function(result) { | 27 }).then(failAndFinishJSTest, function(result) { |
| 28 error = result; | 28 logError(result); |
| 29 shouldBeNull("error"); | |
| 30 | 29 |
| 31 // Invalid data | 30 // Invalid data |
| 32 return crypto.subtle.importKey('raw', null, aesCbc, extractable, ['encrypt']
); | 31 return crypto.subtle.importKey('raw', null, aesCbc, extractable, ['encrypt']
); |
| 33 }).then(failAndFinishJSTest, function(result) { | 32 }).then(failAndFinishJSTest, function(result) { |
| 34 error = result; | 33 logError(result); |
| 35 shouldBeNull("error"); | |
| 36 | 34 |
| 37 // Invalid algorithm | 35 // Invalid algorithm |
| 38 return crypto.subtle.importKey('raw', aesKeyBytes, null, extractable, ['encr
ypt']); | 36 return crypto.subtle.importKey('raw', aesKeyBytes, null, extractable, ['encr
ypt']); |
| 39 }).then(failAndFinishJSTest, function(result) { | 37 }).then(failAndFinishJSTest, function(result) { |
| 40 error = result; | 38 logError(result); |
| 41 shouldBeNull("error"); | |
| 42 | 39 |
| 43 // Invalid format. | 40 // Invalid format. |
| 44 return crypto.subtle.importKey('invalid format', aesKeyBytes, aesCbc, extrac
table, ['encrypt']); | 41 return crypto.subtle.importKey('invalid format', aesKeyBytes, aesCbc, extrac
table, ['encrypt']); |
| 45 }).then(failAndFinishJSTest, function(result) { | 42 }).then(failAndFinishJSTest, function(result) { |
| 46 error = result; | 43 logError(result); |
| 47 shouldBeNull("error"); | |
| 48 | 44 |
| 49 // Invalid key usage (case sensitive). | 45 // Invalid key usage (case sensitive). |
| 50 return crypto.subtle.importKey('raw', aesKeyBytes, aesCbc, extractable, ['EN
CRYPT']); | 46 return crypto.subtle.importKey('raw', aesKeyBytes, aesCbc, extractable, ['EN
CRYPT']); |
| 51 }).then(failAndFinishJSTest, function(result) { | 47 }).then(failAndFinishJSTest, function(result) { |
| 52 error = result; | 48 logError(result); |
| 53 shouldBeNull("error"); | |
| 54 | 49 |
| 55 // If both the format and key usage are bogus, should complain about the | 50 // If both the format and key usage are bogus, should complain about the |
| 56 // format first. | 51 // format first. |
| 57 return crypto.subtle.importKey('invalid format', aesKeyBytes, aesCbc, extrac
table, ['ENCRYPT']); | 52 return crypto.subtle.importKey('invalid format', aesKeyBytes, aesCbc, extrac
table, ['ENCRYPT']); |
| 58 }).then(failAndFinishJSTest, function(result) { | 53 }).then(failAndFinishJSTest, function(result) { |
| 59 error = result; | 54 logError(result); |
| 60 shouldBeNull("error"); | |
| 61 | 55 |
| 62 // Missing hash parameter for HMAC. | 56 // Missing hash parameter for HMAC. |
| 63 return crypto.subtle.importKey('raw', new Uint8Array(20), {name: 'hmac'}, ex
tractable, ['sign']); | 57 return crypto.subtle.importKey('raw', new Uint8Array(20), {name: 'hmac'}, ex
tractable, ['sign']); |
| 64 }).then(failAndFinishJSTest, function(result) { | 58 }).then(failAndFinishJSTest, function(result) { |
| 65 error = result; | 59 logError(result); |
| 66 shouldBeNull("error"); | |
| 67 | 60 |
| 68 // SHA-1 doesn't support the importKey operation. | 61 // SHA-1 doesn't support the importKey operation. |
| 69 return crypto.subtle.importKey('raw', new Uint8Array(20), {name: 'sha-1'}, e
xtractable, ['sign']); | 62 return crypto.subtle.importKey('raw', new Uint8Array(20), {name: 'sha-1'}, e
xtractable, ['sign']); |
| 70 }).then(failAndFinishJSTest, function(result) { | 63 }).then(failAndFinishJSTest, function(result) { |
| 71 error = result; | 64 logError(result); |
| 72 shouldBeNull("error"); | |
| 73 }).then(finishJSTest, failAndFinishJSTest); | 65 }).then(finishJSTest, failAndFinishJSTest); |
| 74 | 66 |
| 75 </script> | 67 </script> |
| 76 | 68 |
| 77 </body> | 69 </body> |
| 78 </html> | 70 </html> |
| OLD | NEW |