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

Unified Diff: LayoutTests/crypto/subtle/resources/symmetric-cloneKey.js

Issue 958353003: [WebCrypto] Move cloneKey test to respective algorithm directory (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 5 years, 10 months 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 side-by-side diff with in-line comments
Download patch
Index: LayoutTests/crypto/subtle/resources/symmetric-cloneKey.js
diff --git a/LayoutTests/crypto/subtle/clone-aesKey.html b/LayoutTests/crypto/subtle/resources/symmetric-cloneKey.js
similarity index 50%
rename from LayoutTests/crypto/subtle/clone-aesKey.html
rename to LayoutTests/crypto/subtle/resources/symmetric-cloneKey.js
index e682369b3cb639b423a14a2cb5f4a508da63bc79..20511b250221216449944149e9bafc32cb5af498 100644
--- a/LayoutTests/crypto/subtle/clone-aesKey.html
+++ b/LayoutTests/crypto/subtle/resources/symmetric-cloneKey.js
@@ -1,35 +1,13 @@
-<!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 32 permutations of keys generated by:
-// kPossibleAlgorithms x kPossibleExtractable x kPossibleKeyUsages x kPossibleKeyData
-//
-// For practical reasons these tests are not exhaustive.
-
-var k128BitData = "30112233445566778899aabbccddeeff"
-var k256BitData = "00112233445546778899aabbccddeeff000102030405060708090a0b0c0d0e0f";
-
-var kPossibleAlgorithms = ['AES-CBC', 'AES-GCM'];
-var kPossibleExtractable = [true, false];
-var kPossibleKeyUsages = [['encrypt'], ['decrypt', 'wrapKey'], ['encrypt', 'wrapKey', 'unwrapKey']];
-var kPossibleKeyData = [k128BitData, k256BitData];
+if (self.importScripts) {
+ importScripts('common.js');
+}
-function runTest(algorithmName, extractable, keyUsages, keyData)
+function runCloneSymmetricTests(algorithmName, extractable, keyUsages, keyData, hashName)
{
var importData = hexStringToUint8Array(keyData);
var importAlgorithm = { name: algorithmName };
+ if (hashName)
eroman 2015/03/05 19:58:50 I agree, this is a good tradeoff (having hash as a
+ importAlgorithm.hash = { name: hashName };
var results = {};
@@ -50,7 +28,7 @@ function runTest(algorithmName, extractable, keyUsages, keyData)
shouldEvaluateAs("importedKey.type", "secret");
shouldEvaluateAs("importedKey.extractable", extractable);
shouldEvaluateAs("importedKey.algorithm.name", algorithmName);
- shouldEvaluateAs("importedKey.algorithm.length", importData.length * 8);
+ testAlgorithmSpecificParameter(algorithmName, importedKey, importData, hashName);
shouldEvaluateAs("importedKey.usages.join(',')", keyUsages.join(","));
shouldNotBe("importedKey", "clonedKey");
@@ -59,7 +37,7 @@ function runTest(algorithmName, extractable, keyUsages, keyData)
shouldEvaluateAs("clonedKey.type", "secret");
shouldEvaluateAs("clonedKey.extractable", extractable);
shouldEvaluateAs("clonedKey.algorithm.name", algorithmName);
- shouldEvaluateAs("clonedKey.algorithm.length", importData.length * 8);
+ testAlgorithmSpecificParameter(algorithmName, clonedKey, importData, hashName);
shouldEvaluateAs("clonedKey.usages.join(',')", keyUsages.join(","));
logSerializedKey(importedKey);
@@ -71,21 +49,37 @@ function runTest(algorithmName, extractable, keyUsages, keyData)
});
}
-var lastPromise = Promise.resolve(null);
-
-kPossibleAlgorithms.forEach(function(algorithmName) {
- kPossibleExtractable.forEach(function(extractable) {
- kPossibleKeyUsages.forEach(function(keyUsages) {
- kPossibleKeyData.forEach(function(keyData) {
- lastPromise = lastPromise.then(runTest.bind(null, algorithmName, extractable, keyUsages, keyData));
+function testCloneSymmetricKeys(algorithmName, possibleHashAlgorithms, possibleExtractable, possibleKeyUsages, possibleKeyData)
eroman 2015/03/05 20:22:49 I believe we can remove the parameter "possibleExt
+{
+ var lastPromise = Promise.resolve(null);
+
+ possibleHashAlgorithms.forEach(function(hashName) {
+ possibleExtractable.forEach(function(extractable) {
+ possibleKeyUsages.forEach(function(keyUsages) {
+ possibleKeyData.forEach(function(keyData) {
+ lastPromise = lastPromise.then(runCloneSymmetricTests.bind(null, algorithmName, extractable, keyUsages, keyData, hashName));
+ });
});
});
});
-});
-
-lastPromise.then(finishJSTest, failAndFinishJSTest);
-</script>
+ return lastPromise;
+}
-</body>
-</html>
+function testAlgorithmSpecificParameter(algorithmName, keyParams, importData, hashName)
+{
+ key = keyParams;
+ switch (algorithmName)
eroman 2015/03/05 19:58:51 I do not like this, since I would like to avoid ha
+ {
+ case 'AES-CBC':
+ case 'AES-GCM':
+ case 'AES-CTR':
+ case 'AES-KW':
+ shouldEvaluateAs("key.algorithm.length", importData.length * 8);
+ break;
+ case 'HMAC':
+ shouldEvaluateAs("key.algorithm.length", importData.length * 8);
+ shouldEvaluateAs("key.algorithm.hash.name", hashName);
+ break;
+ }
+}

Powered by Google App Engine
This is Rietveld 408576698