blob: 21704006bea4221abc74c19cfe0bae4d535b3fea [file] [log] [blame]
<!DOCTYPE html>
<html>
<head>
<script src="../fast/js/resources/js-test-pre.js"></script>
<script src="resources/common.js"></script>
</head>
<body>
<p id="description"></p>
<div id="console"></div>
<script>
description("Tests cypto.subtle.digest.");
jsTestIsAsync = true;
function printRejectedResult(value)
{
debug(" rejected with value of " + value);
}
function printAcceptedResult(result)
{
debug(" = " + byteArrayToHexString(new Uint8Array(result)));
}
Promise.fulfill(null).then(function() {
debug("SHA1 of []");
return crypto.subtle.digest({name: 'sha-1'}, new Uint8Array([]));
}).then(function(result) {
printAcceptedResult(result);
debug("SHA1 of [0x0]")
return crypto.subtle.digest({name: 'sha-1'}, new Uint8Array([0]));
}).then(function(result) {
printAcceptedResult(result);
debug("SHA-256 rejects (dummy implementation)");
return crypto.subtle.digest({name: 'sha-256'}, new Uint8Array([]));
}).then(undefined, function(result) {
printRejectedResult(result);
debug("Error (dummy implementation rejects this input)");
var data = new Uint8Array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]);
return crypto.subtle.digest({name: 'sha-1'}, data);
}).then(undefined, function(result) {
printRejectedResult(result);
// Pass invalid data to digeset()
shouldThrow("crypto.subtle.digest({name: 'sha-1'})");
shouldThrow("crypto.subtle.digest({name: 'sha-1'}, null)");
shouldThrow("crypto.subtle.digest({name: 'sha-1'}, 10)");
// Pass invalid algorithmIdentifiers to digest()
data = new Uint8Array([0]);
shouldThrow("crypto.subtle.digest({name: 'sha'}, data)");
shouldThrow("crypto.subtle.digest(null, data)");
shouldThrow("crypto.subtle.digest({}, data)");
}).then(finishJSTest, failAndFinishJSTest);
</script>
<script src="../fast/js/resources/js-test-post.js"></script>
</body>
</html>