Bug 1728059 [wpt PR 30223] - Add Subresource Web Bundle tests for non utf-8 encoding...
[gecko.git] / toolkit / actors / TestProcessActorChild.jsm
blob1d621b7dc8904aa150f403882db3ebde974daf54
1 /* vim: set ts=2 sw=2 sts=2 et tw=80: */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3  * License, v. 2.0. If a copy of the MPL was not distributed with this
4  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5 "use strict";
7 const { Services } = ChromeUtils.import("resource://gre/modules/Services.jsm");
9 var EXPORTED_SYMBOLS = ["TestProcessActorChild"];
11 class TestProcessActorChild extends JSProcessActorChild {
12   constructor() {
13     super();
14     this.sawActorCreated = false;
15   }
17   actorCreated() {
18     this.sawActorCreated = true;
19   }
21   receiveMessage(aMessage) {
22     switch (aMessage.name) {
23       case "toChild":
24         aMessage.data.toChild = true;
25         this.sendAsyncMessage("toParent", aMessage.data);
26         break;
27       case "asyncAdd":
28         let { a, b } = aMessage.data;
29         return new Promise(resolve => {
30           resolve({ result: a + b });
31         });
32       case "error":
33         return Promise.reject(new SyntaxError(aMessage.data.message));
34       case "exception":
35         return Promise.reject(
36           Components.Exception(aMessage.data.message, aMessage.data.result)
37         );
38       case "done":
39         this.done(aMessage.data);
40         break;
41     }
43     return undefined;
44   }
46   observe(subject, topic, data) {
47     this.lastObserved = { subject, topic, data };
48   }
50   show() {
51     return "TestProcessActorChild";
52   }
54   didDestroy() {
55     Services.obs.notifyObservers(
56       this,
57       "test-js-content-actor-diddestroy",
58       true
59     );
60   }