michael@0: /* Any copyright is dedicated to the Public Domain. michael@0: http://creativecommons.org/publicdomain/zero/1.0/ */ michael@0: michael@0: var gTestGlobals = []; michael@0: DebuggerServer.addTestGlobal = function(aGlobal) { michael@0: gTestGlobals.push(aGlobal); michael@0: }; michael@0: michael@0: // A mock tab list, for use by tests. This simply presents each global in michael@0: // gTestGlobals as a tab, and the list is fixed: it never calls its michael@0: // onListChanged handler. michael@0: // michael@0: // As implemented now, we consult gTestGlobals when we're constructed, not michael@0: // when we're iterated over, so tests have to add their globals before the michael@0: // root actor is created. michael@0: function TestTabList(aConnection) { michael@0: this.conn = aConnection; michael@0: michael@0: // An array of actors for each global added with michael@0: // DebuggerServer.addTestGlobal. michael@0: this._tabActors = []; michael@0: michael@0: // A pool mapping those actors' names to the actors. michael@0: this._tabActorPool = new ActorPool(aConnection); michael@0: michael@0: for (let global of gTestGlobals) { michael@0: let actor = new TestTabActor(aConnection, global); michael@0: actor.selected = false; michael@0: this._tabActors.push(actor); michael@0: this._tabActorPool.addActor(actor); michael@0: } michael@0: if (this._tabActors.length > 0) { michael@0: this._tabActors[0].selected = true; michael@0: } michael@0: michael@0: aConnection.addActorPool(this._tabActorPool); michael@0: } michael@0: michael@0: TestTabList.prototype = { michael@0: constructor: TestTabList, michael@0: getList: function () { michael@0: return promise.resolve([tabActor for (tabActor of this._tabActors)]); michael@0: } michael@0: }; michael@0: michael@0: function createRootActor(aConnection) michael@0: { michael@0: let root = new RootActor(aConnection, michael@0: { tabList: new TestTabList(aConnection) }); michael@0: root.applicationType = "xpcshell-tests"; michael@0: return root; michael@0: } michael@0: michael@0: function TestTabActor(aConnection, aGlobal) michael@0: { michael@0: this.conn = aConnection; michael@0: this._global = aGlobal; michael@0: this._global.wrappedJSObject = aGlobal; michael@0: this._threadActor = new ThreadActor(this, this._global); michael@0: this.conn.addActor(this._threadActor); michael@0: this._attached = false; michael@0: this._extraActors = {}; michael@0: } michael@0: michael@0: TestTabActor.prototype = { michael@0: constructor: TestTabActor, michael@0: actorPrefix: "TestTabActor", michael@0: michael@0: get window() { michael@0: return { wrappedJSObject: this._global }; michael@0: }, michael@0: michael@0: get url() { michael@0: return this._global.__name; michael@0: }, michael@0: michael@0: form: function() { michael@0: let response = { actor: this.actorID, title: this._global.__name }; michael@0: michael@0: // Walk over tab actors added by extensions and add them to a new ActorPool. michael@0: let actorPool = new ActorPool(this.conn); michael@0: this._createExtraActors(DebuggerServer.tabActorFactories, actorPool); michael@0: if (!actorPool.isEmpty()) { michael@0: this._tabActorPool = actorPool; michael@0: this.conn.addActorPool(this._tabActorPool); michael@0: } michael@0: michael@0: this._appendExtraActors(response); michael@0: michael@0: return response; michael@0: }, michael@0: michael@0: onAttach: function(aRequest) { michael@0: this._attached = true; michael@0: michael@0: let response = { type: "tabAttached", threadActor: this._threadActor.actorID }; michael@0: this._appendExtraActors(response); michael@0: michael@0: return response; michael@0: }, michael@0: michael@0: onDetach: function(aRequest) { michael@0: if (!this._attached) { michael@0: return { "error":"wrongState" }; michael@0: } michael@0: return { type: "detached" }; michael@0: }, michael@0: michael@0: /* Support for DebuggerServer.addTabActor. */ michael@0: _createExtraActors: createExtraActors, michael@0: _appendExtraActors: appendExtraActors michael@0: }; michael@0: michael@0: TestTabActor.prototype.requestTypes = { michael@0: "attach": TestTabActor.prototype.onAttach, michael@0: "detach": TestTabActor.prototype.onDetach michael@0: };