test_crypto.js (1173B)
1 /* Any copyright is dedicated to the Public Domain. 2 * http://creativecommons.org/publicdomain/zero/1.0/ */ 3 4 function run_test() { 5 let sb = new Cu.Sandbox('https://www.example.com', 6 { wantGlobalProperties: 7 ["crypto", "TextEncoder", "TextDecoder", "isSecureContext"], 8 forceSecureContext: true, 9 }); 10 sb.ok = ok; 11 Cu.evalInSandbox('ok(this.crypto);', sb); 12 Cu.evalInSandbox('ok(this.crypto.subtle);', sb); 13 sb.equal = equal; 14 let innerPromise = new Promise(r => (sb.test_done = r)); 15 Cu.evalInSandbox('crypto.subtle.digest("SHA-256", ' + 16 ' new TextEncoder().encode("abc"))' + 17 ' .then(h => equal(new Uint16Array(h)[0], 30906))' + 18 ' .then(test_done);', sb); 19 20 Cu.importGlobalProperties(["crypto"]); 21 ok(crypto); 22 ok(crypto.subtle); 23 let outerPromise = crypto.subtle.digest("SHA-256", new TextEncoder().encode("abc")) 24 .then(h => Assert.equal(new Uint16Array(h)[0], 30906)); 25 26 do_test_pending(); 27 Promise.all([innerPromise, outerPromise]).then(() => do_test_finished()); 28 }