Bug 1915045 Ensure decode tasks are scheduled on BufferingState::Enter() r=media...
[gecko.git] / js / xpconnect / tests / unit / test_messageChannel.js
blob685aa10e437591194fdfd2bff9f83474431a84e8
1 /* Any copyright is dedicated to the Public Domain.
2  * http://creativecommons.org/publicdomain/zero/1.0/ */
4 add_task(async function() {
5   let sb = new Cu.Sandbox('http://www.example.com',
6                           { wantGlobalProperties: ["MessageChannel"] });
7   sb.ok = ok;
8   Cu.evalInSandbox('ok((new MessageChannel()) instanceof MessageChannel);',
9                    sb);
10   Cu.evalInSandbox('ok((new MessageChannel()).port1 instanceof MessagePort);',
11                    sb);
13   Cu.importGlobalProperties(["MessageChannel"]);
15   let mc = new MessageChannel();
16   Assert.ok(mc instanceof MessageChannel);
17   Assert.ok(mc.port1 instanceof MessagePort);
18   Assert.ok(mc.port2 instanceof MessagePort);
20   mc.port1.postMessage(42);
22   let result = await new Promise(resolve => {
23     mc.port2.onmessage = e => {
24       resolve(e.data);
25     }
26   });
28   Assert.equal(result, 42);
29 });