4 <script src=
"../../resources/js-test.js"></script>
5 <script src=
"resources/common.js"></script>
8 <p id=
"description"></p>
9 <div id=
"console"></div>
12 description("Tests calling cypto.subtle.importKey with bad parameters");
16 var aesCbc
= {name
: 'aes-cbc'};
17 var aesKeyBytes
= new Uint8Array(16);
18 var extractable
= true;
20 // Undefined key usage.
21 // FIXME: http://crbug.com/262383
22 //shouldThrow("crypto.subtle.importKey('raw', aesKeyBytes, aesCbc, extractable, undefined)");
24 Promise
.resolve(null).then(function() {
26 return crypto
.subtle
.importKey('raw', [], aesCbc
, extractable
, ['encrypt']);
27 }).then(failAndFinishJSTest
, function(result
) {
30 // 'null' treated as a Dictionary with default values - an empty dictionary
31 return crypto
.subtle
.importKey('raw', null, aesCbc
, extractable
, ['encrypt']);
32 }).then(failAndFinishJSTest
, function(result
) {
36 return crypto
.subtle
.importKey('raw', aesKeyBytes
, null, extractable
, ['encrypt']);
37 }).then(failAndFinishJSTest
, function(result
) {
41 return crypto
.subtle
.importKey('invalid format', aesKeyBytes
, aesCbc
, extractable
, ['encrypt']);
42 }).then(failAndFinishJSTest
, function(result
) {
45 // Invalid key usage (case sensitive).
46 return crypto
.subtle
.importKey('raw', aesKeyBytes
, aesCbc
, extractable
, ['ENCRYPT']);
47 }).then(failAndFinishJSTest
, function(result
) {
50 // If both the format and key usage are bogus, should complain about the
52 return crypto
.subtle
.importKey('invalid format', aesKeyBytes
, aesCbc
, extractable
, ['ENCRYPT']);
53 }).then(failAndFinishJSTest
, function(result
) {
56 // Missing hash parameter for HMAC.
57 return crypto
.subtle
.importKey('raw', new Uint8Array(20), {name
: 'hmac'}, extractable
, ['sign']);
58 }).then(failAndFinishJSTest
, function(result
) {
61 // SHA-1 doesn't support the importKey operation.
62 return crypto
.subtle
.importKey('raw', new Uint8Array(20), {name
: 'sha-1'}, extractable
, ['sign']);
63 }).then(failAndFinishJSTest
, function(result
) {
65 }).then(finishJSTest
, failAndFinishJSTest
);