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

Unified 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 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
index 3544599f9159ffcb071fc2f35d446ad75cd8ba54..21704006bea4221abc74c19cfe0bae4d535b3fea 100644
--- a/LayoutTests/crypto/digest.html
+++ b/LayoutTests/crypto/digest.html
@@ -13,82 +13,50 @@ description("Tests cypto.subtle.digest.");
jsTestIsAsync = true;
-// 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)
+function printRejectedResult(value)
{
debug(" rejected with value of " + value);
- if (!justPrint)
- startNextTest();
}
-function resultHandler(buffer, justPrint)
+function printAcceptedResult(result)
{
- debug(" = " + byteArrayToHexString(new Uint8Array(buffer)));
- if (!justPrint)
- startNextTest();
+ debug(" = " + byteArrayToHexString(new Uint8Array(result)));
}
-function failHandler(value)
-{
- testFailed(value);
- startNextTest();
-}
-
-allTests = [
- function()
- {
- debug("SHA1 of []")
- crypto.subtle.digest({name: 'sha-1'}, new Uint8Array([])).then(resultHandler, rejectHandler);
- },
-
- function()
- {
- debug("SHA1 of [0x0]")
- crypto.subtle.digest({name: 'sha-1'}, new Uint8Array([0])).then(resultHandler, rejectHandler);
- },
-
- function()
- {
- debug("SHA-256 rejects (dummy implementation)");
- crypto.subtle.digest({name: 'sha-256'}, new Uint8Array([])).then(resultHandler, rejectHandler);
- },
-
- function()
- {
- debug("Error (dummy implementation rejects this input)");
- var data = new Uint8Array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]);
- crypto.subtle.digest({name: 'sha-1'}, data).then(resultHandler, rejectHandler);
- },
-
- function()
- {
- shouldThrow("crypto.subtle.digest({name: 'sha-1'})");
- shouldThrow("crypto.subtle.digest({name: 'sha-1'}, null)");
- shouldThrow("crypto.subtle.digest({name: 'sha-1'}, 10)");
- startNextTest();
- },
-];
-
-// Begin!
-startNextTest();
+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>
« 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