Move parseFontFaceDescriptor to CSSPropertyParser.cpp
[chromium-blink-merge.git] / third_party / WebKit / LayoutTests / crypto / subtle / aes-generateKey.html
blobbae4b0911879501235c7085413ccd251d8dadefe
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 generating AES keys");
14 jsTestIsAsync = true;
16 // Tests the 24 permutations of keys generated by:
17 // kPossibleAlgorithms x kPossibleExtractable x kPossibleKeyUsages x kPossibleKeyLengths
19 // For practical reasons these tests are not exhaustive.
21 var kPossibleAlgorithms = ['AES-CBC', 'AES-GCM'];
22 var kPossibleExtractable = [true, false];
23 var kPossibleKeyUsages = [['encrypt'], ['decrypt', 'wrapKey'], ['encrypt', 'wrapKey', 'unwrapKey']];
24 var kPossibleKeyLengths = [128, 256];
26 // Set of all key data generated so far.
27 var allKeyDataGenerated = {};
29 function runTest(algorithmName, extractable, keyUsages, keyLengthBits)
31 var genAlgorithm = { name: algorithmName, length: keyLengthBits };
33 var results = {};
35 var promise = crypto.subtle.generateKey(genAlgorithm, extractable, keyUsages).then(function(result) {
36 generatedKey = result;
38 shouldEvaluateAs("generatedKey.extractable", extractable);
39 shouldEvaluateAs("generatedKey.algorithm.name", algorithmName);
40 shouldEvaluateAs("generatedKey.algorithm.length", keyLengthBits);
41 shouldEvaluateAs("generatedKey.usages.join(',')", keyUsages.join(","));
43 if (extractable)
44 return crypto.subtle.exportKey('raw', generatedKey);
45 });
47 if (extractable) {
48 promise = promise.then(function(result) {
49 keyData = result;
50 shouldEvaluateAs("keyData.byteLength", keyLengthBits / 8);
52 var keyDataHex = bytesToHexString(keyData);
54 // It is very unlikely to generate two identical keys, so
55 // assume if that happens something is broken.
56 // (8 extractable keys are generated for each bit length).
57 if (allKeyDataGenerated[keyDataHex]) {
58 testFailed("Generated identical key data: " + keyDataHex);
59 } else {
60 allKeyDataGenerated[keyDataHex] = true;
61 testPassed("Generated unique key data of length: " + (keyData.byteLength * 8) + " bits");
63 });
66 return promise;
69 var lastPromise = Promise.resolve(null);
71 kPossibleAlgorithms.forEach(function(algorithmName) {
72 kPossibleExtractable.forEach(function(extractable) {
73 kPossibleKeyUsages.forEach(function(keyUsages) {
74 kPossibleKeyLengths.forEach(function(keyLengthBits) {
75 lastPromise = lastPromise.then(runTest.bind(null, algorithmName, extractable, keyUsages, keyLengthBits));
76 });
77 });
78 });
79 });
81 lastPromise.then(finishJSTest, failAndFinishJSTest);
83 </script>
85 </body>
86 </html>