diff options
author | Matt A. Tobin <mattatobin@localhost.localdomain> | 2018-02-02 04:16:08 -0500 |
---|---|---|
committer | Matt A. Tobin <mattatobin@localhost.localdomain> | 2018-02-02 04:16:08 -0500 |
commit | 5f8de423f190bbb79a62f804151bc24824fa32d8 (patch) | |
tree | 10027f336435511475e392454359edea8e25895d /dom/crypto/test/file_indexedDB.html | |
parent | 49ee0794b5d912db1f95dce6eb52d781dc210db5 (diff) | |
download | UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.gz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.lz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.xz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.zip |
Add m-esr52 at 52.6.0
Diffstat (limited to 'dom/crypto/test/file_indexedDB.html')
-rw-r--r-- | dom/crypto/test/file_indexedDB.html | 82 |
1 files changed, 82 insertions, 0 deletions
diff --git a/dom/crypto/test/file_indexedDB.html b/dom/crypto/test/file_indexedDB.html new file mode 100644 index 000000000..09e95b18f --- /dev/null +++ b/dom/crypto/test/file_indexedDB.html @@ -0,0 +1,82 @@ +<!DOCTYPE html> +<html> +<head> + <meta charset="utf-8"> + <title>Bug 1188750 - WebCrypto must ensure NSS is initialized before deserializing</title> +</head> +<body> + <script type="application/javascript;version=1.8"> + let db; + + function err(resolve) { + return e => resolve(e.target.error.message); + } + + function openDatabase() { + return new Promise((resolve, reject) => { + let request = indexedDB.open("keystore", 1); + + request.onerror = err(reject); + request.onsuccess = function (event) { + db = event.target.result; + resolve(); + }; + + request.onupgradeneeded = function(event) { + db = event.target.result; + let objectStore = db.createObjectStore("keys", {autoIncrement: true}); + objectStore.transaction.oncomplete = resolve; + }; + }); + } + + function storeKey(key) { + return new Promise((resolve, reject) => { + let transaction = db.transaction("keys", "readwrite"); + transaction.objectStore("keys").put(key, key.type); + + transaction.onabort = err(reject); + transaction.onerror = err(reject); + + transaction.oncomplete = function () { + resolve(key); + }; + }); + }; + + function retrieveKey() { + return new Promise((resolve, reject) => { + let transaction = db.transaction("keys", "readonly"); + let cursor = transaction.objectStore("keys").openCursor(); + + cursor.onerror = err(reject); + cursor.onabort = err(reject); + + cursor.onsuccess = function (event) { + try { + let result = event.target.result; + resolve(result && result.value); + } catch (e) { + reject(e.message); + } + }; + }); + } + + function generateKey() { + let algorithm = { + name: "RSASSA-PKCS1-v1_5", + hash: "SHA-256", + modulusLength: 1024, + publicExponent: new Uint8Array([0x01, 0x00, 0x01]) + }; + + return crypto.subtle.generateKey(algorithm, true, ["sign", "verify"]); + } + + openDatabase() + .then(retrieveKey).then(generateKey).then(storeKey) + .then(() => alert("ok")).catch(alert); + </script> +</body> +</html> |