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

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

Issue 23126008: WebCrypto: refactor layout tests. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 7 years, 4 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
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
11 <script> 11 <script>
12 description("Tests cypto.subtle.digest."); 12 description("Tests cypto.subtle.digest.");
13 13
14 jsTestIsAsync = true; 14 jsTestIsAsync = true;
15 15
16 // Each sub-test run in this file is asynchronous. Chaining them together 16 function printRejectedResult(value)
17 // manually leads to very unreadable code, due to having closures within
18 // closures within closures. Instead of doing that, each subtest calls
19 // "startNextTest()" once it has completed.
20
21 currentTestIndex = 0;
22
23 function startNextTest()
24 { 17 {
25 var currentTest = allTests[currentTestIndex++]; 18 debug(" rejected with value of " + value);
26
27 if (!currentTest) {
28 finishJSTest();
29 return;
30 }
31
32 currentTest();
33 } 19 }
34 20
35 function rejectHandler(value, justPrint) 21 function printAcceptedResult(result)
36 { 22 {
37 debug(" rejected with value of " + value); 23 debug(" = " + byteArrayToHexString(new Uint8Array(result)));
38 if (!justPrint)
39 startNextTest();
40 } 24 }
41 25
42 function resultHandler(buffer, justPrint) 26 Promise.fulfill(null).then(function() {
43 { 27 debug("SHA1 of []");
44 debug(" = " + byteArrayToHexString(new Uint8Array(buffer))); 28 return crypto.subtle.digest({name: 'sha-1'}, new Uint8Array([]));
45 if (!justPrint) 29 }).then(function(result) {
46 startNextTest(); 30 printAcceptedResult(result);
47 }
48 31
49 function failHandler(value) 32 debug("SHA1 of [0x0]")
50 { 33 return crypto.subtle.digest({name: 'sha-1'}, new Uint8Array([0]));
51 testFailed(value); 34 }).then(function(result) {
52 startNextTest(); 35 printAcceptedResult(result);
53 }
54 36
55 allTests = [ 37 debug("SHA-256 rejects (dummy implementation)");
56 function() 38 return crypto.subtle.digest({name: 'sha-256'}, new Uint8Array([]));
57 {
58 debug("SHA1 of []")
59 crypto.subtle.digest({name: 'sha-1'}, new Uint8Array([])).then(resultHan dler, rejectHandler);
60 },
61 39
62 function() 40 }).then(undefined, function(result) {
63 { 41 printRejectedResult(result);
64 debug("SHA1 of [0x0]")
65 crypto.subtle.digest({name: 'sha-1'}, new Uint8Array([0])).then(resultHa ndler, rejectHandler);
66 },
67 42
68 function() 43 debug("Error (dummy implementation rejects this input)");
69 { 44 var data = new Uint8Array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]);
70 debug("SHA-256 rejects (dummy implementation)"); 45 return crypto.subtle.digest({name: 'sha-1'}, data);
71 crypto.subtle.digest({name: 'sha-256'}, new Uint8Array([])).then(resultH andler, rejectHandler); 46 }).then(undefined, function(result) {
72 }, 47 printRejectedResult(result);
73 48
74 function() 49 // Pass invalid data to digeset()
75 { 50 shouldThrow("crypto.subtle.digest({name: 'sha-1'})");
76 debug("Error (dummy implementation rejects this input)"); 51 shouldThrow("crypto.subtle.digest({name: 'sha-1'}, null)");
77 var data = new Uint8Array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]); 52 shouldThrow("crypto.subtle.digest({name: 'sha-1'}, 10)");
78 crypto.subtle.digest({name: 'sha-1'}, data).then(resultHandler, rejectHa ndler);
79 },
80 53
81 function() 54 // Pass invalid algorithmIdentifiers to digest()
82 { 55 data = new Uint8Array([0]);
83 shouldThrow("crypto.subtle.digest({name: 'sha-1'})"); 56 shouldThrow("crypto.subtle.digest({name: 'sha'}, data)");
84 shouldThrow("crypto.subtle.digest({name: 'sha-1'}, null)"); 57 shouldThrow("crypto.subtle.digest(null, data)");
85 shouldThrow("crypto.subtle.digest({name: 'sha-1'}, 10)"); 58 shouldThrow("crypto.subtle.digest({}, data)");
86 startNextTest(); 59 }).then(finishJSTest, failAndFinishJSTest);
87 },
88 ];
89
90 // Begin!
91 startNextTest();
92 60
93 </script> 61 </script>
94 62
95 <script src="../fast/js/resources/js-test-post.js"></script> 63 <script src="../fast/js/resources/js-test-post.js"></script>
96 </body> 64 </body>
97 </html> 65 </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