Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(190)

Side by Side Diff: LayoutTests/crypto/clone-hmacKey.html

Issue 806913006: [WebCrypto] Move LayoutTests from crypto to crypto/subtle (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Update path for deserialize legacy tests Created 6 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
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>
10
11 <script>
12 description("Tests structured cloning of HMAC keys");
13
14 jsTestIsAsync = true;
15
16 // Tests the 48 permutations of keys generated by:
17 // kPossibleHashAlgorithms x kPossibleExtractable x kPossibleKeyUsages x kPoss ibleKeyData
18 //
19 // For practical reasons these tests are not exhaustive.
20
21 var k128BitData = "30112233445566778899aabbccddeeff"
22 var k256BitData = "00112233445546778899aabbccddeeff000102030405060708090a0b0c0d0 e0f";
23
24 var kPossibleHashAlgorithms = ['SHA-1', 'SHA-256', 'SHA-512'];
25 var kPossibleExtractable = [true, false];
26 var kPossibleKeyUsages = [['sign'], ['verify'], ['sign', 'verify']];
27 var kPossibleKeyData = [
28 k128BitData,
29 k256BitData
30 ];
31
32 function runTest(hashName, extractable, keyUsages, keyData)
33 {
34 var importData = hexStringToUint8Array(keyData);
35 var importAlgorithm = { name: 'HMAC', hash: {name: hashName } };
36
37 var results = {};
38
39 return crypto.subtle.importKey('raw', importData, importAlgorithm, extractab le, keyUsages).then(function(importedKey) {
40 results.importedKey = importedKey;
41 importedKey.extraProperty = 'hi';
42 return cloneKey(importedKey);
43 }).then(function(clonedKey) {
44 results.clonedKey = clonedKey;
45 if (extractable)
46 return crypto.subtle.exportKey('raw', clonedKey);
47 return null;
48 }).then(function(clonedKeyData) {
49 importedKey = results.importedKey;
50 clonedKey = results.clonedKey;
51
52 shouldEvaluateAs("importedKey.extraProperty", "hi");
53 shouldEvaluateAs("importedKey.type", "secret");
54 shouldEvaluateAs("importedKey.extractable", extractable);
55 shouldEvaluateAs("importedKey.algorithm.name", "HMAC");
56 shouldEvaluateAs("importedKey.algorithm.length", importData.length * 8);
57 shouldEvaluateAs("importedKey.algorithm.hash.name", hashName);
58 shouldEvaluateAs("importedKey.usages.join(',')", keyUsages.join(","));
59
60 shouldNotBe("importedKey", "clonedKey");
61
62 shouldBeUndefined("clonedKey.extraProperty");
63 shouldEvaluateAs("clonedKey.type", "secret");
64 shouldEvaluateAs("clonedKey.extractable", extractable);
65 shouldEvaluateAs("clonedKey.algorithm.name", "HMAC");
66 shouldEvaluateAs("clonedKey.algorithm.length", importData.length * 8);
67 shouldEvaluateAs("clonedKey.algorithm.hash.name", hashName);
68 shouldEvaluateAs("clonedKey.usages.join(',')", keyUsages.join(","));
69
70 logSerializedKey(importedKey);
71
72 if (extractable)
73 bytesShouldMatchHexString("Cloned key exported data", keyData, clone dKeyData);
74
75 debug("");
76 });
77 }
78
79 var lastPromise = Promise.resolve(null);
80
81 kPossibleHashAlgorithms.forEach(function(hashName) {
82 kPossibleExtractable.forEach(function(extractable) {
83 kPossibleKeyUsages.forEach(function(keyUsages) {
84 kPossibleKeyData.forEach(function(keyData) {
85 lastPromise = lastPromise.then(runTest.bind(null, hashName, extr actable, keyUsages, keyData));
86 });
87 });
88 });
89 });
90
91 lastPromise.then(finishJSTest, failAndFinishJSTest);
92
93 </script>
94
95 </body>
96 </html>
OLDNEW
« no previous file with comments | « LayoutTests/crypto/clone-ecKey-public-expected.txt ('k') | LayoutTests/crypto/clone-hmacKey-empty.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698