Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / third_party / WebKit / LayoutTests / crypto / subtle / exportKey-badParameters.html
blobbc72a1ece69d05637db2ff37592dd0cec212147d
1 <!DOCTYPE html>
2 <html>
3 <head>
4 <script src="../../resources/js-test.js"></script>
5 <script src="resources/common.js"></script>
6 </head>
7 <body>
8 <p id="description"></p>
9 <div id="console"></div>
11 <script>
12 description("Tests exportKey() given bad inputs.");
14 jsTestIsAsync = true;
16 function importAesKey()
18 var keyData = new Uint8Array(16);
19 var usages = ['encrypt'];
20 var extractable = true;
21 var algorithm = {name: 'aes-cbc'};
23 return crypto.subtle.importKey('raw', keyData, algorithm, extractable, usages);
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 logError(result);
32 // 3 is not a valid Key.
33 return crypto.subtle.exportKey('raw', 3);
34 }).then(failAndFinishJSTest, function(result) {
35 logError(result);
37 return importAesKey();
38 }).then(function(result) {
39 key = result;
41 // Invalid export format
42 return crypto.subtle.exportKey(3, key);
43 }).then(failAndFinishJSTest, function(result) {
44 logError(result);
46 // Invalid export format
47 return crypto.subtle.exportKey(null, key);
48 }).then(failAndFinishJSTest, function(result) {
49 logError(result);
51 // Invalid export format
52 return crypto.subtle.exportKey('invalid', key);
53 }).then(failAndFinishJSTest, function(result) {
54 logError(result);
55 }).then(finishJSTest, failAndFinishJSTest);
57 </script>
59 </body>
60 </html>