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