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

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: reorder headers even though it violates style 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
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)
52 {
53 debug(" rejected with value of " + value);
54 startNextTest();
55 }
56
57 function resultHandler(buffer)
58 {
59 debug(" = " + byteArrayToHexString(new Uint8Array(buffer)));
60 startNextTest();
61 }
62
63 allTests = [
64 function()
65 {
66 debug("SHA1 of [] -- with empty process()")
67 op = crypto.subtle.digest({name: 'sha-1'});
68 op.process(new Uint8Array([]));
69 op.finish();
70 op.promise().then(resultHandler, rejectHandler);
71 },
72
73 function()
74 {
75 debug("SHA1 of [] -- without calling process()")
76 op = crypto.subtle.digest({name: 'sha-1'});
77 op.finish();
78 op.promise().then(resultHandler, rejectHandler);
79 },
80
81 function()
82 {
83 debug("SHA1 of [0x0]")
84 op = crypto.subtle.digest({name: 'sha-1'});
85 op.process(new Uint8Array([0]));
86 op.finish();
87 op.promise().then(resultHandler, rejectHandler);
88 },
89
90 function()
91 {
92 debug("SHA1 of [0x0] -- as an ArrayBuffer")
93 op = crypto.subtle.digest({name: 'sha-1'});
94 op.process(new Uint8Array([0]).buffer);
95 op.finish();
96 op.promise().then(resultHandler, rejectHandler);
97 },
98
99 function()
100 {
101 debug("SHA1 of [0, 1, 2, 3, 4, 5] -- multipart")
102 op = crypto.subtle.digest({name: 'sha-1'});
103 op.process(new Uint8Array([0]));
104 op.process(new Uint8Array([1]));
105 op.process(new Uint8Array([2]));
106 op.process(new Uint8Array([3]));
107 op.process(new Uint8Array([4]));
108 op.process(new Uint8Array([5]));
109 op.finish();
110 op.promise().then(resultHandler, rejectHandler);
111 },
112
113 function()
114 {
115 debug("Call process() after finish()");
116 op = crypto.subtle.digest({name: 'sha-1'});
117 op.finish();
118 // These should all be no-ops, since has already finished.
119 op.process(new Uint8Array([0]));
120 op.process(new Uint8Array([1]));
121 op.process(new Uint8Array([2]));
122 op.process(new Uint8Array([3]));
123 op.promise().then(resultHandler, rejectHandler);
124 },
125
126 function()
127 {
128 debug("abort()");
129 op = crypto.subtle.digest({name: 'sha-1'});
130 op.abort();
131 op.promise().then(resultHandler, rejectHandler);
132 },
133
134 function()
135 {
136 debug("abort() and then abort()");
137 op = crypto.subtle.digest({name: 'sha-1'});
138 op.abort();
139 op.abort();
140 op.promise().then(resultHandler, rejectHandler);
141 },
142
143 function()
144 {
145 debug("process() and then abort()");
146 op = crypto.subtle.digest({name: 'sha-1'});
147 op.process(new Uint8Array([0]));
148 op.abort();
149 op.promise().then(resultHandler, rejectHandler);
150 },
151
152 function()
153 {
154 debug("finish() and then abort()");
155 op = crypto.subtle.digest({name: 'sha-1'});
156 op.finish();
157 op.abort();
158 op.promise().then(resultHandler, rejectHandler);
159 },
160
161 function()
162 {
163 debug("finish() and then process()");
164 op = crypto.subtle.digest({name: 'sha-1'});
165 op.finish();
166 op.process(new Uint8Array([0]));
167 op.promise().then(resultHandler, rejectHandler);
168 },
169
170 function()
171 {
172 debug("finish() and then abort()");
173 op = crypto.subtle.digest({name: 'sha-1'});
174 op.finish();
175 op.abort();
176 op.promise().then(resultHandler, rejectHandler);
177 },
178
179 function()
180 {
181 debug("finish() and then finish()");
182 op = crypto.subtle.digest({name: 'sha-1'});
183 op.finish();
184 op.finish();
185 op.promise().then(resultHandler, rejectHandler);
186 },
187
188 function()
189 {
190 op = crypto.subtle.digest({name: 'sha-1'});
191 shouldThrow("op.process(null)");
192 shouldThrow("op.process()");
193 shouldThrow("op.process(-1)");
194 startNextTest();
195 },
196 ];
197
198 // Begin!
199 startNextTest();
200
201 </script>
202
203 <script src="../fast/js/resources/js-test-post.js"></script>
204 </body>
205 </html>
OLDNEW
« no previous file with comments | « no previous file | LayoutTests/crypto/digest-expected.txt » ('j') | Source/modules/crypto/CryptoOperation.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698