michael@0: /* Any copyright is dedicated to the Public Domain. michael@0: http://creativecommons.org/publicdomain/zero/1.0/ */ michael@0: michael@0: /** michael@0: * Make sure the listTabs request works as specified. michael@0: */ michael@0: michael@0: const TAB1_URL = EXAMPLE_URL + "doc_empty-tab-01.html"; michael@0: michael@0: let gTab1, gTab1Actor, gTab2, gTab2Actor, gClient; michael@0: michael@0: function listTabs() { michael@0: let deferred = promise.defer(); michael@0: michael@0: gClient.listTabs(aResponse => { michael@0: deferred.resolve(aResponse.tabs); michael@0: }); michael@0: michael@0: return deferred.promise; michael@0: } michael@0: michael@0: function request(params) { michael@0: let deferred = promise.defer(); michael@0: gClient.request(params, deferred.resolve); michael@0: return deferred.promise; michael@0: } michael@0: michael@0: function test() { michael@0: if (!DebuggerServer.initialized) { michael@0: DebuggerServer.init(() => true); michael@0: DebuggerServer.addBrowserActors(); michael@0: } michael@0: michael@0: let transport = DebuggerServer.connectPipe(); michael@0: gClient = new DebuggerClient(transport); michael@0: gClient.connect(Task.async(function*(aType, aTraits) { michael@0: is(aType, "browser", michael@0: "Root actor should identify itself as a browser."); michael@0: let tab = yield addTab(TAB1_URL); michael@0: michael@0: let tabs = yield listTabs(); michael@0: is(tabs.length, 2, "Should be two tabs"); michael@0: let tabGrip = tabs.filter(a => a.url ==TAB1_URL).pop(); michael@0: ok(tabGrip, "Should have an actor for the tab"); michael@0: michael@0: let response = yield request({ to: tabGrip.actor, type: "attach" }); michael@0: is(response.type, "tabAttached", "Should have attached"); michael@0: michael@0: tabs = yield listTabs(); michael@0: michael@0: response = yield request({ to: tabGrip.actor, type: "detach" }); michael@0: is(response.type, "detached", "Should have detached"); michael@0: michael@0: let newGrip = tabs.filter(a => a.url ==TAB1_URL).pop(); michael@0: is(newGrip.actor, tabGrip.actor, "Should have the same actor for the same tab"); michael@0: michael@0: response = yield request({ to: tabGrip.actor, type: "attach" }); michael@0: is(response.type, "tabAttached", "Should have attached"); michael@0: response = yield request({ to: tabGrip.actor, type: "detach" }); michael@0: is(response.type, "detached", "Should have detached"); michael@0: michael@0: yield removeTab(tab); michael@0: yield closeConnection(); michael@0: finish(); michael@0: })); michael@0: } michael@0: michael@0: function closeConnection() { michael@0: let deferred = promise.defer(); michael@0: gClient.close(deferred.resolve); michael@0: return deferred.promise; michael@0: } michael@0: michael@0: registerCleanupFunction(function() { michael@0: gTab1 = null; michael@0: gTab1Actor = null; michael@0: gTab2 = null; michael@0: gTab2Actor = null; michael@0: gClient = null; michael@0: });