|
1 /* Any copyright is dedicated to the Public Domain. |
|
2 http://creativecommons.org/publicdomain/zero/1.0/ */ |
|
3 |
|
4 var gTestGlobals = []; |
|
5 DebuggerServer.addTestGlobal = function(aGlobal) { |
|
6 gTestGlobals.push(aGlobal); |
|
7 }; |
|
8 |
|
9 // A mock tab list, for use by tests. This simply presents each global in |
|
10 // gTestGlobals as a tab, and the list is fixed: it never calls its |
|
11 // onListChanged handler. |
|
12 // |
|
13 // As implemented now, we consult gTestGlobals when we're constructed, not |
|
14 // when we're iterated over, so tests have to add their globals before the |
|
15 // root actor is created. |
|
16 function TestTabList(aConnection) { |
|
17 this.conn = aConnection; |
|
18 |
|
19 // An array of actors for each global added with |
|
20 // DebuggerServer.addTestGlobal. |
|
21 this._tabActors = []; |
|
22 |
|
23 // A pool mapping those actors' names to the actors. |
|
24 this._tabActorPool = new ActorPool(aConnection); |
|
25 |
|
26 for (let global of gTestGlobals) { |
|
27 let actor = new TestTabActor(aConnection, global); |
|
28 actor.selected = false; |
|
29 this._tabActors.push(actor); |
|
30 this._tabActorPool.addActor(actor); |
|
31 } |
|
32 if (this._tabActors.length > 0) { |
|
33 this._tabActors[0].selected = true; |
|
34 } |
|
35 |
|
36 aConnection.addActorPool(this._tabActorPool); |
|
37 } |
|
38 |
|
39 TestTabList.prototype = { |
|
40 constructor: TestTabList, |
|
41 getList: function () { |
|
42 return promise.resolve([tabActor for (tabActor of this._tabActors)]); |
|
43 } |
|
44 }; |
|
45 |
|
46 function createRootActor(aConnection) |
|
47 { |
|
48 let root = new RootActor(aConnection, |
|
49 { tabList: new TestTabList(aConnection) }); |
|
50 root.applicationType = "xpcshell-tests"; |
|
51 return root; |
|
52 } |
|
53 |
|
54 function TestTabActor(aConnection, aGlobal) |
|
55 { |
|
56 this.conn = aConnection; |
|
57 this._global = aGlobal; |
|
58 this._global.wrappedJSObject = aGlobal; |
|
59 this._threadActor = new ThreadActor(this, this._global); |
|
60 this.conn.addActor(this._threadActor); |
|
61 this._attached = false; |
|
62 this._extraActors = {}; |
|
63 } |
|
64 |
|
65 TestTabActor.prototype = { |
|
66 constructor: TestTabActor, |
|
67 actorPrefix: "TestTabActor", |
|
68 |
|
69 get window() { |
|
70 return { wrappedJSObject: this._global }; |
|
71 }, |
|
72 |
|
73 get url() { |
|
74 return this._global.__name; |
|
75 }, |
|
76 |
|
77 form: function() { |
|
78 let response = { actor: this.actorID, title: this._global.__name }; |
|
79 |
|
80 // Walk over tab actors added by extensions and add them to a new ActorPool. |
|
81 let actorPool = new ActorPool(this.conn); |
|
82 this._createExtraActors(DebuggerServer.tabActorFactories, actorPool); |
|
83 if (!actorPool.isEmpty()) { |
|
84 this._tabActorPool = actorPool; |
|
85 this.conn.addActorPool(this._tabActorPool); |
|
86 } |
|
87 |
|
88 this._appendExtraActors(response); |
|
89 |
|
90 return response; |
|
91 }, |
|
92 |
|
93 onAttach: function(aRequest) { |
|
94 this._attached = true; |
|
95 |
|
96 let response = { type: "tabAttached", threadActor: this._threadActor.actorID }; |
|
97 this._appendExtraActors(response); |
|
98 |
|
99 return response; |
|
100 }, |
|
101 |
|
102 onDetach: function(aRequest) { |
|
103 if (!this._attached) { |
|
104 return { "error":"wrongState" }; |
|
105 } |
|
106 return { type: "detached" }; |
|
107 }, |
|
108 |
|
109 /* Support for DebuggerServer.addTabActor. */ |
|
110 _createExtraActors: createExtraActors, |
|
111 _appendExtraActors: appendExtraActors |
|
112 }; |
|
113 |
|
114 TestTabActor.prototype.requestTypes = { |
|
115 "attach": TestTabActor.prototype.onAttach, |
|
116 "detach": TestTabActor.prototype.onDetach |
|
117 }; |