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

Side by Side Diff: LayoutTests/crypto/resources/subtle-crypto-concurrent.js

Issue 224823003: [webcrypto] Improve the concurrency layout test. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 6 years, 8 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 if (self.importScripts) { 1 if (self.importScripts) {
2 importScripts('../../resources/js-test.js'); 2 importScripts('../../resources/js-test.js');
3 importScripts('common.js'); 3 importScripts('common.js');
4 } 4 }
5 5
6 function shouldEvaluateAsSilent(expressionToEval, expectedResult) 6 function shouldEvaluateAsSilent(expressionToEval, expectedResult)
7 { 7 {
8 var result = eval(expressionToEval); 8 var result = eval(expressionToEval);
9 if (result !== expectedResult) { 9 if (result !== expectedResult) {
10 testFailed(expressionToEval + " evaluated to " + result + " instead of " + expectedResult); 10 testFailed(expressionToEval + " evaluated to " + result + " instead of " + expectedResult);
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
80 // shouldBe() can only resolve variables in global context. 80 // shouldBe() can only resolve variables in global context.
81 tmpKey = key; 81 tmpKey = key;
82 shouldEvaluateAsSilent("tmpKey.type", "secret"); 82 shouldEvaluateAsSilent("tmpKey.type", "secret");
83 shouldEvaluateAsSilent("tmpKey.extractable", true); 83 shouldEvaluateAsSilent("tmpKey.extractable", true);
84 shouldEvaluateAsSilent("tmpKey.algorithm.name", "HMAC"); 84 shouldEvaluateAsSilent("tmpKey.algorithm.name", "HMAC");
85 shouldEvaluateAsSilent("tmpKey.algorithm.hash.name", testCase.hash); 85 shouldEvaluateAsSilent("tmpKey.algorithm.hash.name", testCase.hash);
86 shouldEvaluateAsSilent("tmpKey.algorithm.length", keyData.length * 8); 86 shouldEvaluateAsSilent("tmpKey.algorithm.length", keyData.length * 8);
87 shouldEvaluateAsSilent("tmpKey.usages.join(',')", "sign,verify"); 87 shouldEvaluateAsSilent("tmpKey.usages.join(',')", "sign,verify");
88 88
89 // (2) Sign. 89 // (2) Sign.
90 return crypto.subtle.sign(algorithm, key, hexStringToUint8Array(testCase .message)); 90 var signPromise = crypto.subtle.sign(algorithm, key, hexStringToUint8Arr ay(testCase.message));
91 }).then(function(result) {
92 mac = result;
93 shouldEvaluateAsSilent("bytesToHexString(mac)", testCase.mac);
94 91
95 // (3) Verify 92 // (3) Verify
96 return crypto.subtle.verify(algorithm, key, hexStringToUint8Array(testCa se.mac), hexStringToUint8Array(testCase.message)); 93 var verifyPromise = crypto.subtle.verify(algorithm, key, hexStringToUint 8Array(testCase.mac), hexStringToUint8Array(testCase.message));
97 }).then(function(result) {
98 verifyResult = result;
99 shouldEvaluateAsSilent("verifyResult", true);
100 94
101 // (4) Verify truncated mac (by stripping 1 byte off of it). 95 // (4) Verify truncated mac (by stripping 1 byte off of it).
102 var expectedMac = hexStringToUint8Array(testCase.mac); 96 var expectedMac = hexStringToUint8Array(testCase.mac);
103 return crypto.subtle.verify(algorithm, key, expectedMac.subarray(0, expe ctedMac.byteLength - 1), hexStringToUint8Array(testCase.message)); 97 var verifyTruncatedPromise = crypto.subtle.verify(algorithm, key, expect edMac.subarray(0, expectedMac.byteLength - 1), hexStringToUint8Array(testCase.me ssage));
98
99 var exportKeyPromise = crypto.subtle.exportKey('raw', key);
100
101 return Promise.all([signPromise, verifyPromise, verifyTruncatedPromise, exportKeyPromise]);
104 }).then(function(result) { 102 }).then(function(result) {
105 verifyResult = result; 103 // signPromise
104 mac = result[0];
105 shouldEvaluateAsSilent("bytesToHexString(mac)", testCase.mac);
106
107 // verifyPromise
108 verifyResult = result[1];
109 shouldEvaluateAsSilent("verifyResult", true);
110
111 // verifyTruncatedPromise
112 verifyResult = result[2];
106 shouldEvaluateAsSilent("verifyResult", false); 113 shouldEvaluateAsSilent("verifyResult", false);
107 114
108 return crypto.subtle.exportKey('raw', key); 115 // exportKeyPromise
109 }).then(function(result) { 116 exportedKeyData = result[3];
110 exportedKeyData = result;
111 shouldEvaluateAsSilent("bytesToHexString(exportedKeyData)", testCase.key ); 117 shouldEvaluateAsSilent("bytesToHexString(exportedKeyData)", testCase.key );
112 }); 118 });
113 } 119 }
114 120
115 // Very similar to aes-gcm-encrypt-decrypt.hml 121 // Very similar to aes-gcm-encrypt-decrypt.hml
116 function testAesGcm() 122 function testAesGcm()
117 { 123 {
118 var testCase = { 124 var testCase = {
119 "key": "ae7972c025d7f2ca3dd37dcc3d41c506671765087c6b61b8", 125 "key": "ae7972c025d7f2ca3dd37dcc3d41c506671765087c6b61b8",
120 "iv": "984c1379e6ba961c828d792d", 126 "iv": "984c1379e6ba961c828d792d",
(...skipping 19 matching lines...) Expand all
140 return crypto.subtle.importKey('raw', keyData, algorithm, extractable, usage s).then(function(result) { 146 return crypto.subtle.importKey('raw', keyData, algorithm, extractable, usage s).then(function(result) {
141 key = result; 147 key = result;
142 148
143 // shouldBe() can only resolve variables in global context. 149 // shouldBe() can only resolve variables in global context.
144 tmpKey = key; 150 tmpKey = key;
145 shouldEvaluateAsSilent("tmpKey.type", "secret"); 151 shouldEvaluateAsSilent("tmpKey.type", "secret");
146 shouldEvaluateAsSilent("tmpKey.extractable", false); 152 shouldEvaluateAsSilent("tmpKey.extractable", false);
147 shouldEvaluateAsSilent("tmpKey.algorithm.name", "AES-GCM"); 153 shouldEvaluateAsSilent("tmpKey.algorithm.name", "AES-GCM");
148 shouldEvaluateAsSilent("tmpKey.usages.join(',')", "encrypt,decrypt"); 154 shouldEvaluateAsSilent("tmpKey.usages.join(',')", "encrypt,decrypt");
149 155
150 // (2) Encrypt. 156 // (2) Encrypt
151 return crypto.subtle.encrypt(algorithm, key, hexStringToUint8Array(testC ase.plainText)); 157 var encryptPromise1 = crypto.subtle.encrypt(algorithm, key, hexStringToU int8Array(testCase.plainText));
152 }).then(function(result) { 158 var encryptPromise2 = crypto.subtle.encrypt(algorithm, key, hexStringToU int8Array(testCase.plainText));
153 cipherText = result;
154 shouldEvaluateAsSilent("bytesToHexString(cipherText)", testCase.cipherTe xt + testCase.authenticationTag);
155 159
156 // (3) Decrypt 160 // (3) Decrypt
157 return crypto.subtle.decrypt(algorithm, key, hexStringToUint8Array(testC ase.cipherText + testCase.authenticationTag)); 161 var decryptPromise1 = crypto.subtle.decrypt(algorithm, key, hexStringToU int8Array(testCase.cipherText + testCase.authenticationTag));
162 var decryptPromise2 = crypto.subtle.decrypt(algorithm, key, hexStringToU int8Array(testCase.cipherText + testCase.authenticationTag));
163
164 return Promise.all([encryptPromise1, encryptPromise2, decryptPromise1, d ecryptPromise2]);
158 }).then(function(result) { 165 }).then(function(result) {
159 plainText = result; 166 // encryptPromise1, encryptPromise2
160 shouldEvaluateAsSilent("bytesToHexString(plainText)", testCase.plainText ); 167 for (var i = 0; i < 2; ++i) {
168 cipherText = result[i];
169 shouldEvaluateAsSilent("bytesToHexString(cipherText)", testCase.ciph erText + testCase.authenticationTag);
170 }
171
172 // decryptPromise1, decryptPromise2
173 for (var i = 0; i < 2; ++i) {
174 plainText = result[2 + i];
175 shouldEvaluateAsSilent("bytesToHexString(plainText)", testCase.plain Text);
176 }
161 }); 177 });
162 } 178 }
163 179
164 Promise.all([ 180 Promise.all([
165 testHmac(), 181 testHmac(),
166 testGenerateRsaKey(), 182 testGenerateRsaKey(),
167 testAesGcm(), 183 testAesGcm(),
168 testHmac(), 184 testHmac(),
169 testAesGcm(), 185 testAesGcm(),
170 ]).then(notifySuccess, notifyFailure); 186 ]).then(notifySuccess, notifyFailure);
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698