Bug 1915045 Ensure decode tasks are scheduled on BufferingState::Enter() r=media...
[gecko.git] / js / xpconnect / tests / unit / test_crypto.js
blob228701d182bacd3d91a6679d3f5e63b8cd712ef9
1 /* Any copyright is dedicated to the Public Domain.
2  * http://creativecommons.org/publicdomain/zero/1.0/ */
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);
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));
26   do_test_pending();
27   Promise.all([innerPromise, outerPromise]).then(() => do_test_finished());