blob: 67dcf9edd23e5752ca549a1336a83985f0eb8b21 [file] [log] [blame]
<!DOCTYPE html>
<html>
<head>
<script src="../../resources/js-test-pre.js"></script>
<script src="resources/common.js"></script>
</head>
<body>
<p id="description"></p>
<div id="console"></div>
<script>
description("Test crypto.subtle argument conversion");
jsTestIsAsync = true;
Promise.resolve(null).then(function() {
debug("\nPassing algorithm name as a string object...");
return crypto.subtle.digest(new String('sha-1'), new Uint8Array([]));
}).then(function(result) {
testPassed("...succeeded");
debug("\nPassing algorithm name as a string object in a dictionary...");
return crypto.subtle.digest({name: new String('sha-1')}, new Uint8Array([]));
}).then(function(result) {
testPassed("...succeeded");
debug("\nPassing algorithm name as an object with toString");
return crypto.subtle.digest({name: { toString:function() { return 'sha-1' } } }, new Uint8Array([]));
}).then(function(result) {
testPassed("...succeeded");
debug("\nPassing invalid data to digest()");
shouldThrow("crypto.subtle.digest({name: 'sha-1'})");
shouldThrow("crypto.subtle.digest({name: 'sha-1'}, null)");
shouldThrow("crypto.subtle.digest({name: 'sha-1'}, 10)");
shouldThrow("crypto.subtle.digest({name: 'sha-1'}, [10])");
shouldThrow("crypto.subtle.digest({name: 'sha-1'}, [new Uint8Array([0])])");
debug("\nPassing invalid algorithmIdentifiers to digest()");
data = new Uint8Array([0]);
shouldThrow("crypto.subtle.digest({ toString:function() { return 'sha-1' } }, data)"); // Algorithm normalization doesn't attempt to call toString.
shouldThrow("crypto.subtle.digest({name: ''}, data)");
shouldThrow("crypto.subtle.digest({name: null}, data)");
shouldThrow("crypto.subtle.digest({name: undefined}, data)");
shouldThrow("crypto.subtle.digest({name: 'sha'}, data)");
shouldThrow("crypto.subtle.digest({name: 1}, data)");
shouldThrow("crypto.subtle.digest('', data)");
shouldThrow("crypto.subtle.digest(null, data)");
shouldThrow("crypto.subtle.digest(undefined, data)");
shouldThrow("crypto.subtle.digest(1, data)");
shouldThrow("crypto.subtle.digest({}, data)");
}).then(finishJSTest);
</script>
<script src="../../resources/js-test-post.js"></script>
</body>
</html>