OLD | NEW |
1 <!DOCTYPE html> | 1 <!DOCTYPE html> |
2 <html> | 2 <html> |
3 <head> | 3 <head> |
4 <script src="../fast/js/resources/js-test-pre.js"></script> | 4 <script src="../fast/js/resources/js-test-pre.js"></script> |
5 <script src="resources/common.js"></script> | 5 <script src="resources/common.js"></script> |
6 </head> | 6 </head> |
7 <body> | 7 <body> |
8 <p id="description"></p> | 8 <p id="description"></p> |
9 <div id="console"></div> | 9 <div id="console"></div> |
10 | 10 |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
91 input: "000102030405", | 91 input: "000102030405", |
92 output: "79f4738706fce9650ac60266675c3cd07298b09923850d525604d040e6e448adc7d
c22780d7e1b95bfeaa86a678e4552" | 92 output: "79f4738706fce9650ac60266675c3cd07298b09923850d525604d040e6e448adc7d
c22780d7e1b95bfeaa86a678e4552" |
93 }, | 93 }, |
94 { | 94 { |
95 algorithm: "SHA-512", | 95 algorithm: "SHA-512", |
96 input: "000102030405", | 96 input: "000102030405", |
97 output: "2f3831bccc94cf061bcfa5f8c23c1429d26e3bc6b76edad93d9025cb91c903af6cf
9c935dc37193c04c2c66e7d9de17c358284418218afea2160147aaa912f4c" | 97 output: "2f3831bccc94cf061bcfa5f8c23c1429d26e3bc6b76edad93d9025cb91c903af6cf
9c935dc37193c04c2c66e7d9de17c358284418218afea2160147aaa912f4c" |
98 }, | 98 }, |
99 ]; | 99 ]; |
100 | 100 |
| 101 var allTests = []; |
| 102 |
101 // Run each test. | 103 // Run each test. |
102 for (var i = 0; i < kDigestTestVectors.length; ++i) { | 104 for (var i = 0; i < kDigestTestVectors.length; ++i) { |
103 var testCase = kDigestTestVectors[i]; | 105 allTests.push(runTestCase(kDigestTestVectors[i])); |
104 var promise = crypto.subtle.digest({name: testCase.algorithm}, hexStringToUi
nt8Array(testCase.input)); | |
105 promise.then(onTestCaseComplete.bind(null, testCase), failAndFinishJSTest); | |
106 } | 106 } |
107 | 107 |
108 function onTestCaseComplete(testCase, result) | 108 function runTestCase(testCase) |
109 { | 109 { |
110 var testDescription = testCase.algorithm + " of [" + testCase.input + "]"; | 110 return crypto.subtle.digest({name: testCase.algorithm}, hexStringToUint8Arra
y(testCase.input)).then(function(result) { |
111 bytesShouldMatchHexString(testDescription, testCase.output, result); | 111 var testDescription = testCase.algorithm + " of [" + testCase.input + "]
"; |
| 112 bytesShouldMatchHexString(testDescription, testCase.output, result); |
| 113 }); |
| 114 } |
112 | 115 |
113 // Once the last test has completed, done. | 116 Promise.all(allTests).then(finishJSTest, failAndFinishJSTest); |
114 if (testCase == kDigestTestVectors[kDigestTestVectors.length - 1]) { | |
115 finishJSTest(); | |
116 } | |
117 } | |
118 | 117 |
119 // Pass invalid data to digeset() | 118 // Pass invalid data to digeset() |
120 shouldThrow("crypto.subtle.digest({name: 'sha-1'})"); | 119 shouldThrow("crypto.subtle.digest({name: 'sha-1'})"); |
121 shouldThrow("crypto.subtle.digest({name: 'sha-1'}, null)"); | 120 shouldThrow("crypto.subtle.digest({name: 'sha-1'}, null)"); |
122 shouldThrow("crypto.subtle.digest({name: 'sha-1'}, 10)"); | 121 shouldThrow("crypto.subtle.digest({name: 'sha-1'}, 10)"); |
123 | 122 |
124 // Pass invalid algorithmIdentifiers to digest() | 123 // Pass invalid algorithmIdentifiers to digest() |
125 data = new Uint8Array([0]); | 124 data = new Uint8Array([0]); |
126 shouldThrow("crypto.subtle.digest({name: 'sha'}, data)"); | 125 shouldThrow("crypto.subtle.digest({name: 'sha'}, data)"); |
127 shouldThrow("crypto.subtle.digest(null, data)"); | 126 shouldThrow("crypto.subtle.digest(null, data)"); |
128 shouldThrow("crypto.subtle.digest({}, data)"); | 127 shouldThrow("crypto.subtle.digest({}, data)"); |
129 | 128 |
130 </script> | 129 </script> |
131 | 130 |
132 <script src="../fast/js/resources/js-test-post.js"></script> | 131 <script src="../fast/js/resources/js-test-post.js"></script> |
133 </body> | 132 </body> |
134 </html> | 133 </html> |
OLD | NEW |