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

Unified 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | LayoutTests/crypto/digest-expected.txt » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: LayoutTests/crypto/digest.html
diff --git a/LayoutTests/crypto/digest.html b/LayoutTests/crypto/digest.html
new file mode 100644
index 0000000000000000000000000000000000000000..2357bad4ea870e7d70f998158c84d949e3c39b53
--- /dev/null
+++ b/LayoutTests/crypto/digest.html
@@ -0,0 +1,198 @@
+<!DOCTYPE html>
+<html>
+<head>
+<script src="../fast/js/resources/js-test-pre.js"></script>
+</head>
+<body>
+<p id="description"></p>
+<div id="console"></div>
+
+<script>
+description("Tests cypto.subtle.digest.");
+
+jsTestIsAsync = true;
+
+// Builds a hex string representation of any array-like input (array or
+// ArrayBufferView). The output looks like this:
+// [ab 03 4c 99]
+function byteArrayToHexString(bytes)
+{
+ var hexBytes = [];
+
+ for (var i = 0; i < bytes.length; ++i) {
+ var byteString = bytes[i].toString(16);
+ if (byteString.length < 2)
+ byteString = "0" + byteString;
+ hexBytes.push(byteString);
+ }
+
+ return "[" + hexBytes.join(" ") + "]";
+}
+
+// Each sub-test run in this file is asynchronous. Chaining them together
+// manually leads to very unreadable code, due to having closures within
+// closures within closures. Instead of doing that, each subtest calls
+// "startNextTest()" once it has completed.
+
+currentTestIndex = 0;
+
+function startNextTest()
+{
+ var currentTest = allTests[currentTestIndex++];
+
+ if (!currentTest) {
+ finishJSTest();
+ return;
+ }
+
+ currentTest();
+}
+
+function rejectHandler(value, justPrint)
+{
+ debug(" rejected with value of " + value);
+ if (!justPrint)
+ startNextTest();
+}
+
+function resultHandler(buffer, justPrint)
+{
+ debug(" = " + byteArrayToHexString(new Uint8Array(buffer)));
+ if (!justPrint)
+ startNextTest();
+}
+
+function failHandler(value)
+{
+ testFailed(value);
+ startNextTest();
+}
+
+allTests = [
+ function()
+ {
+ debug("SHA1 of [] -- with empty process()")
+ op = crypto.subtle.digest({name: 'sha-1'});
+ op.process(new Uint8Array([]));
+ op.finish().then(resultHandler, rejectHandler);
+ },
+
+ function()
+ {
+ debug("SHA1 of [] -- without calling process()")
+ op = crypto.subtle.digest({name: 'sha-1'});
+ op.finish().then(resultHandler, rejectHandler);
+ },
+
+ function()
+ {
+ debug("SHA1 of [0x0]")
+ op = crypto.subtle.digest({name: 'sha-1'});
+ op.process(new Uint8Array([0]));
+ op.finish().then(resultHandler, rejectHandler);
+ },
+
+ function()
+ {
+ debug("SHA1 of [0x0] -- as an ArrayBuffer")
+ op = crypto.subtle.digest({name: 'sha-1'});
+ op.process(new Uint8Array([0]).buffer);
+ op.finish().then(resultHandler, rejectHandler);
+ },
+
+ function()
+ {
+ debug("SHA1 of [0, 1, 2, 3, 4, 5] -- multipart")
+ op = crypto.subtle.digest({name: 'sha-1'});
+ op.process(new Uint8Array([0]));
+ op.process(new Uint8Array([1]));
+ op.process(new Uint8Array([2]));
+ op.process(new Uint8Array([3]));
+ op.process(new Uint8Array([4]));
+ op.process(new Uint8Array([5]));
+ op.finish().then(resultHandler, rejectHandler);
+ },
+
+ function()
+ {
+ debug("Call process() after finish()");
+ op = crypto.subtle.digest({name: 'sha-1'});
+ op.finish().then(resultHandler, rejectHandler);
+ // These should all be no-ops, since has already finished.
+ op.process(new Uint8Array([0]));
+ op.process(new Uint8Array([1]));
+ op.process(new Uint8Array([2]));
+ op.process(new Uint8Array([3]));
+ },
+
+ function()
+ {
+ debug("abort()");
+ op = crypto.subtle.digest({name: 'sha-1'});
+ op.abort().then(resultHandler, rejectHandler);
+ },
+
+ function()
+ {
+ debug("abort() and then abort()");
+ op = crypto.subtle.digest({name: 'sha-1'});
+ op.abort().then(failHandler, function(value) {
+ rejectHandler(value, true);
+ op.abort().then(resultHandler, rejectHandler);
+ });
+ },
+
+ function()
+ {
+ debug("process() and then abort()");
+ op = crypto.subtle.digest({name: 'sha-1'});
+ op.process(new Uint8Array([0]));
+ op.abort().then(resultHandler, rejectHandler);
+ },
+
+ function()
+ {
+ debug("finish() and then abort()");
+ op = crypto.subtle.digest({name: 'sha-1'});
+ op.finish().then(function(value) {
+ resultHandler(value, true);
+ op.abort().then(resultHandler, rejectHandler);
+ }, failHandler);
+ },
+
+ function()
+ {
+ debug("finish() and then process()");
+ op = crypto.subtle.digest({name: 'sha-1'});
+ op.finish().then(resultHandler, rejectHandler);
+ op.process(new Uint8Array([0]));
+ },
+
+ function()
+ {
+ debug("finish() and then finish()");
+ op = crypto.subtle.digest({name: 'sha-1'});
+ op.finish().then(function(value) {
+ resultHandler(value, true);
+ op.finish().then(resultHandler, rejectHandler);
+ }, failHandler);
+ },
+
+ function()
+ {
+ op = crypto.subtle.digest({name: 'sha-1'});
+ shouldThrow("op.process(null)");
+ shouldThrow("op.process()");
+ shouldThrow("op.process(-1)");
+ startNextTest();
+ },
+];
+
+// Begin!
+startNextTest();
+
+</script>
+
+<script src="../fast/js/resources/js-test-post.js"></script>
+</body>
+</html>
« 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