| Index: LayoutTests/crypto/digest.html
|
| diff --git a/LayoutTests/crypto/digest.html b/LayoutTests/crypto/digest.html
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..838efeac34c11014e9c66634aa3593676991df6d
|
| --- /dev/null
|
| +++ b/LayoutTests/crypto/digest.html
|
| @@ -0,0 +1,205 @@
|
| +<!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)
|
| +{
|
| + debug(" rejected with value of " + value);
|
| + startNextTest();
|
| +}
|
| +
|
| +function resultHandler(buffer)
|
| +{
|
| + debug(" = " + byteArrayToHexString(new Uint8Array(buffer)));
|
| + startNextTest();
|
| +}
|
| +
|
| +allTests = [
|
| + function()
|
| + {
|
| + debug("SHA1 of [] -- with empty process()")
|
| + op = crypto.subtle.digest({name: 'sha-1'});
|
| + op.process(new Uint8Array([]));
|
| + op.finish();
|
| + op.promise().then(resultHandler, rejectHandler);
|
| + },
|
| +
|
| + function()
|
| + {
|
| + debug("SHA1 of [] -- without calling process()")
|
| + op = crypto.subtle.digest({name: 'sha-1'});
|
| + op.finish();
|
| + op.promise().then(resultHandler, rejectHandler);
|
| + },
|
| +
|
| + function()
|
| + {
|
| + debug("SHA1 of [0x0]")
|
| + op = crypto.subtle.digest({name: 'sha-1'});
|
| + op.process(new Uint8Array([0]));
|
| + op.finish();
|
| + op.promise().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();
|
| + op.promise().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();
|
| + op.promise().then(resultHandler, rejectHandler);
|
| + },
|
| +
|
| + function()
|
| + {
|
| + debug("Call process() after finish()");
|
| + op = crypto.subtle.digest({name: 'sha-1'});
|
| + op.finish();
|
| + // 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]));
|
| + op.promise().then(resultHandler, rejectHandler);
|
| + },
|
| +
|
| + function()
|
| + {
|
| + debug("abort()");
|
| + op = crypto.subtle.digest({name: 'sha-1'});
|
| + op.abort();
|
| + op.promise().then(resultHandler, rejectHandler);
|
| + },
|
| +
|
| + function()
|
| + {
|
| + debug("abort() and then abort()");
|
| + op = crypto.subtle.digest({name: 'sha-1'});
|
| + op.abort();
|
| + op.abort();
|
| + op.promise().then(resultHandler, rejectHandler);
|
| + },
|
| +
|
| + function()
|
| + {
|
| + debug("process() and then abort()");
|
| + op = crypto.subtle.digest({name: 'sha-1'});
|
| + op.process(new Uint8Array([0]));
|
| + op.abort();
|
| + op.promise().then(resultHandler, rejectHandler);
|
| + },
|
| +
|
| + function()
|
| + {
|
| + debug("finish() and then abort()");
|
| + op = crypto.subtle.digest({name: 'sha-1'});
|
| + op.finish();
|
| + op.abort();
|
| + op.promise().then(resultHandler, rejectHandler);
|
| + },
|
| +
|
| + function()
|
| + {
|
| + debug("finish() and then process()");
|
| + op = crypto.subtle.digest({name: 'sha-1'});
|
| + op.finish();
|
| + op.process(new Uint8Array([0]));
|
| + op.promise().then(resultHandler, rejectHandler);
|
| + },
|
| +
|
| + function()
|
| + {
|
| + debug("finish() and then abort()");
|
| + op = crypto.subtle.digest({name: 'sha-1'});
|
| + op.finish();
|
| + op.abort();
|
| + op.promise().then(resultHandler, rejectHandler);
|
| + },
|
| +
|
| + function()
|
| + {
|
| + debug("finish() and then finish()");
|
| + op = crypto.subtle.digest({name: 'sha-1'});
|
| + op.finish();
|
| + op.finish();
|
| + op.promise().then(resultHandler, rejectHandler);
|
| + },
|
| +
|
| + 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>
|
|
|