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

Side by Side Diff: LayoutTests/crypto/digest.html

Issue 19082002: WebCrypto: Add SHA-1 support to crypto.subtle.digest(). (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Remove an extra newline Created 7 years, 5 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 | LayoutTests/crypto/digest-expected.txt » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 <!DOCTYPE html>
2 <html>
3 <head>
4 <script src="../fast/js/resources/js-test-pre.js"></script>
5 </head>
6 <body>
7 <p id="description"></p>
8 <div id="console"></div>
9
10 <script>
11 description("Tests cypto.subtle.digest.");
12
13 jsTestIsAsync = true;
14
15 // Builds a hex string representation of any array-like input (array or
16 // ArrayBufferView). The output looks like this:
17 // [ab 03 4c 99]
18 function byteArrayToHexString(bytes)
19 {
20 var hexBytes = [];
21
22 for (var i = 0; i < bytes.length; ++i) {
23 var byteString = bytes[i].toString(16);
24 if (byteString.length < 2)
25 byteString = "0" + byteString;
26 hexBytes.push(byteString);
27 }
28
29 return "[" + hexBytes.join(" ") + "]";
30 }
31
32 // Each sub-test run in this file is asynchronous. Chaining them together
33 // manually leads to very unreadable code, due to having closures within
34 // closures within closures. Instead of doing that, each subtest calls
35 // "startNextTest()" once it has completed.
36
37 currentTestIndex = 0;
38
39 function startNextTest()
40 {
41 var currentTest = allTests[currentTestIndex++];
42
43 if (!currentTest) {
44 finishJSTest();
45 return;
46 }
47
48 currentTest();
49 }
50
51 function rejectHandler(value, justPrint)
52 {
53 debug(" rejected with value of " + value);
54 if (!justPrint)
55 startNextTest();
56 }
57
58 function resultHandler(buffer, justPrint)
59 {
60 debug(" = " + byteArrayToHexString(new Uint8Array(buffer)));
61 if (!justPrint)
62 startNextTest();
63 }
64
65 function failHandler(value)
66 {
67 testFailed(value);
68 startNextTest();
69 }
70
71 allTests = [
72 function()
73 {
74 debug("SHA1 of [] -- with empty process()")
75 op = crypto.subtle.digest({name: 'sha-1'});
76 op.process(new Uint8Array([]));
77 op.finish().then(resultHandler, rejectHandler);
78 },
79
80 function()
81 {
82 debug("SHA1 of [] -- without calling process()")
83 op = crypto.subtle.digest({name: 'sha-1'});
84 op.finish().then(resultHandler, rejectHandler);
85 },
86
87 function()
88 {
89 debug("SHA1 of [0x0]")
90 op = crypto.subtle.digest({name: 'sha-1'});
91 op.process(new Uint8Array([0]));
92 op.finish().then(resultHandler, rejectHandler);
93 },
94
95 function()
96 {
97 debug("SHA1 of [0x0] -- as an ArrayBuffer")
98 op = crypto.subtle.digest({name: 'sha-1'});
99 op.process(new Uint8Array([0]).buffer);
100 op.finish().then(resultHandler, rejectHandler);
101 },
102
103 function()
104 {
105 debug("SHA1 of [0, 1, 2, 3, 4, 5] -- multipart")
106 op = crypto.subtle.digest({name: 'sha-1'});
107 op.process(new Uint8Array([0]));
108 op.process(new Uint8Array([1]));
109 op.process(new Uint8Array([2]));
110 op.process(new Uint8Array([3]));
111 op.process(new Uint8Array([4]));
112 op.process(new Uint8Array([5]));
113 op.finish().then(resultHandler, rejectHandler);
114 },
115
116 function()
117 {
118 debug("Call process() after finish()");
119 op = crypto.subtle.digest({name: 'sha-1'});
120 op.finish().then(resultHandler, rejectHandler);
121 // These should all be no-ops, since has already finished.
122 op.process(new Uint8Array([0]));
123 op.process(new Uint8Array([1]));
124 op.process(new Uint8Array([2]));
125 op.process(new Uint8Array([3]));
126 },
127
128 function()
129 {
130 debug("abort()");
131 op = crypto.subtle.digest({name: 'sha-1'});
132 op.abort().then(resultHandler, rejectHandler);
133 },
134
135 function()
136 {
137 debug("abort() and then abort()");
138 op = crypto.subtle.digest({name: 'sha-1'});
139 op.abort().then(failHandler, function(value) {
140 rejectHandler(value, true);
141 op.abort().then(resultHandler, rejectHandler);
142 });
143 },
144
145 function()
146 {
147 debug("process() and then abort()");
148 op = crypto.subtle.digest({name: 'sha-1'});
149 op.process(new Uint8Array([0]));
150 op.abort().then(resultHandler, rejectHandler);
151 },
152
153 function()
154 {
155 debug("finish() and then abort()");
156 op = crypto.subtle.digest({name: 'sha-1'});
157 op.finish().then(function(value) {
158 resultHandler(value, true);
159 op.abort().then(resultHandler, rejectHandler);
160 }, failHandler);
161 },
162
163 function()
164 {
165 debug("finish() and then process()");
166 op = crypto.subtle.digest({name: 'sha-1'});
167 op.finish().then(resultHandler, rejectHandler);
168 op.process(new Uint8Array([0]));
169 },
170
171 function()
172 {
173 debug("finish() and then finish()");
174 op = crypto.subtle.digest({name: 'sha-1'});
175 op.finish().then(function(value) {
176 resultHandler(value, true);
177 op.finish().then(resultHandler, rejectHandler);
178 }, failHandler);
179 },
180
181 function()
182 {
183 op = crypto.subtle.digest({name: 'sha-1'});
184 shouldThrow("op.process(null)");
185 shouldThrow("op.process()");
186 shouldThrow("op.process(-1)");
187 startNextTest();
188 },
189 ];
190
191 // Begin!
192 startNextTest();
193
194 </script>
195
196 <script src="../fast/js/resources/js-test-post.js"></script>
197 </body>
198 </html>
OLDNEW
« no previous file with comments | « no previous file | LayoutTests/crypto/digest-expected.txt » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698