browser/devtools/debugger/test/browser_dbg_listtabs-03.js

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

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 /**
michael@0 5 * Make sure the listTabs request works as specified.
michael@0 6 */
michael@0 7
michael@0 8 const TAB1_URL = EXAMPLE_URL + "doc_empty-tab-01.html";
michael@0 9
michael@0 10 let gTab1, gTab1Actor, gTab2, gTab2Actor, gClient;
michael@0 11
michael@0 12 function listTabs() {
michael@0 13 let deferred = promise.defer();
michael@0 14
michael@0 15 gClient.listTabs(aResponse => {
michael@0 16 deferred.resolve(aResponse.tabs);
michael@0 17 });
michael@0 18
michael@0 19 return deferred.promise;
michael@0 20 }
michael@0 21
michael@0 22 function request(params) {
michael@0 23 let deferred = promise.defer();
michael@0 24 gClient.request(params, deferred.resolve);
michael@0 25 return deferred.promise;
michael@0 26 }
michael@0 27
michael@0 28 function test() {
michael@0 29 if (!DebuggerServer.initialized) {
michael@0 30 DebuggerServer.init(() => true);
michael@0 31 DebuggerServer.addBrowserActors();
michael@0 32 }
michael@0 33
michael@0 34 let transport = DebuggerServer.connectPipe();
michael@0 35 gClient = new DebuggerClient(transport);
michael@0 36 gClient.connect(Task.async(function*(aType, aTraits) {
michael@0 37 is(aType, "browser",
michael@0 38 "Root actor should identify itself as a browser.");
michael@0 39 let tab = yield addTab(TAB1_URL);
michael@0 40
michael@0 41 let tabs = yield listTabs();
michael@0 42 is(tabs.length, 2, "Should be two tabs");
michael@0 43 let tabGrip = tabs.filter(a => a.url ==TAB1_URL).pop();
michael@0 44 ok(tabGrip, "Should have an actor for the tab");
michael@0 45
michael@0 46 let response = yield request({ to: tabGrip.actor, type: "attach" });
michael@0 47 is(response.type, "tabAttached", "Should have attached");
michael@0 48
michael@0 49 tabs = yield listTabs();
michael@0 50
michael@0 51 response = yield request({ to: tabGrip.actor, type: "detach" });
michael@0 52 is(response.type, "detached", "Should have detached");
michael@0 53
michael@0 54 let newGrip = tabs.filter(a => a.url ==TAB1_URL).pop();
michael@0 55 is(newGrip.actor, tabGrip.actor, "Should have the same actor for the same tab");
michael@0 56
michael@0 57 response = yield request({ to: tabGrip.actor, type: "attach" });
michael@0 58 is(response.type, "tabAttached", "Should have attached");
michael@0 59 response = yield request({ to: tabGrip.actor, type: "detach" });
michael@0 60 is(response.type, "detached", "Should have detached");
michael@0 61
michael@0 62 yield removeTab(tab);
michael@0 63 yield closeConnection();
michael@0 64 finish();
michael@0 65 }));
michael@0 66 }
michael@0 67
michael@0 68 function closeConnection() {
michael@0 69 let deferred = promise.defer();
michael@0 70 gClient.close(deferred.resolve);
michael@0 71 return deferred.promise;
michael@0 72 }
michael@0 73
michael@0 74 registerCleanupFunction(function() {
michael@0 75 gTab1 = null;
michael@0 76 gTab1Actor = null;
michael@0 77 gTab2 = null;
michael@0 78 gTab2Actor = null;
michael@0 79 gClient = null;
michael@0 80 });

mercurial