Chromium Code Reviews| Index: LayoutTests/crypto/clone-aesKey.html |
| diff --git a/LayoutTests/crypto/clone-aesKey.html b/LayoutTests/crypto/clone-aesKey.html |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..4899353ae55679c462e8f40f515edfe3e1278fda |
| --- /dev/null |
| +++ b/LayoutTests/crypto/clone-aesKey.html |
| @@ -0,0 +1,81 @@ |
| +<!DOCTYPE html> |
| +<html> |
| +<head> |
| +<script src="../resources/js-test.js"></script> |
| +<script src="resources/common.js"></script> |
| +</head> |
| +<body> |
| +<p id="description"></p> |
| +<div id="console"></div> |
| + |
| +<script> |
| +description("Tests structured cloning of AES keys"); |
| + |
| +jsTestIsAsync = true; |
| + |
| +// Tests the 48 permutations of keys generated by: |
| +// kPossibleAlgorithms x kPossibleExtractable x kPossibleKeyUsages x kPossibleKeyData |
| +// |
| +// For practical reasons these tests are not exhaustive. |
| + |
| +var k128BitData = "30112233445566778899aabbccddeeff" |
| +var k192BitData = "800102030405060708090a0b0c0d0e0f1011121314151617"; |
| +var k256BitData = "00112233445546778899aabbccddeeff000102030405060708090a0b0c0d0e0f"; |
| + |
| +var kPossibleAlgorithms = ['AES-CBC', 'AES-GCM']; |
| +var kPossibleExtractable = [true, false]; |
| +var kPossibleKeyUsages = [[], ['encrypt'], ['decrypt', 'wrapKey'], ['encrypt', 'wrapKey', 'unwrapKey']]; |
| +var kPossibleKeyData = [k128BitData, k192BitData, k256BitData]; |
| + |
| +function runTest(algorithmName, extractable, keyUsages, keyData) |
| +{ |
| + var keyLengthBits = keyData.length * 4; |
| + |
| + return crypto.subtle.importKey('raw', hexStringToUint8Array(keyData), { name: algorithmName }, |
| + extractable, keyUsages).then(function(result) { |
| + importedKey = result; |
| + |
| + shouldBe("importedKey.type", evalWrap("secret")); |
|
jsbell
2014/03/13 20:16:07
This can be shouldBeEqualToString("importedKey.typ
|
| + shouldBe("importedKey.extractable", evalWrap(extractable)); |
|
jsbell
2014/03/13 20:16:07
Using the shouldBe() helpers is a pain with locals
eroman
2014/03/14 05:24:33
I ended up creating a wrapper function shouldEvalu
|
| + shouldBe("importedKey.algorithm.name", evalWrap(algorithmName)); |
| + shouldBe("importedKey.algorithm.length", evalWrap(keyLengthBits)); |
| + shouldBe("importedKey.usages.join(',')", evalWrap(keyUsages.join(","))); |
| + |
| + clonedKey = cloneKeyAndLog(importedKey); |
| + |
| + shouldBe("clonedKey.type", evalWrap("secret")); |
| + shouldBe("clonedKey.extractable", evalWrap(extractable)); |
| + shouldBe("clonedKey.algorithm.name", evalWrap(algorithmName)); |
| + shouldBe("clonedKey.algorithm.length", evalWrap(keyLengthBits)); |
| + shouldBe("clonedKey.usages.join(',')", evalWrap(keyUsages.join(","))); |
| + |
| + // Check the key bytes. |
| + if (extractable) { |
| + return crypto.subtle.exportKey('raw', clonedKey).then(function(result) { |
| + bytesShouldMatchHexString("cloned key data", keyData, result); |
| + }); |
| + } |
| + }); |
| +} |
| + |
| +for (var algorithmIndex = 0; algorithmIndex < kPossibleAlgorithms.length; ++algorithmIndex) { |
|
jsbell
2014/03/13 20:16:07
Might be more readable to write these using forEac
eroman
2014/03/14 05:24:33
Done. You were right, much more readable with forE
|
| + for (var extractableIndex = 0; extractableIndex < kPossibleExtractable.length; ++extractableIndex) { |
| + for (var usagesIndex = 0; usagesIndex < kPossibleKeyUsages.length; ++usagesIndex) { |
| + for (var dataIndex = 0; dataIndex < kPossibleKeyData.length; ++dataIndex) { |
| + var algorithmName = kPossibleAlgorithms[algorithmIndex]; |
| + var extractable = kPossibleExtractable[extractableIndex]; |
| + var keyUsages = kPossibleKeyUsages[usagesIndex]; |
| + var keyData = kPossibleKeyData[dataIndex]; |
| + |
| + addTask(runTest(algorithmName, extractable, keyUsages, keyData)); |
| + } |
| + } |
| + } |
| +} |
| + |
| +completeTestWhenAllTasksDone(); |
| + |
| +</script> |
| + |
| +</body> |
| +</html> |