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 | /** |
michael@0 | 5 | * Check extension-added tab actor lifetimes. |
michael@0 | 6 | */ |
michael@0 | 7 | |
michael@0 | 8 | const CHROME_URL = "chrome://mochitests/content/browser/browser/devtools/debugger/test/" |
michael@0 | 9 | const ACTORS_URL = CHROME_URL + "testactors.js"; |
michael@0 | 10 | const TAB_URL = EXAMPLE_URL + "doc_empty-tab-01.html"; |
michael@0 | 11 | |
michael@0 | 12 | let gClient; |
michael@0 | 13 | |
michael@0 | 14 | function test() { |
michael@0 | 15 | if (!DebuggerServer.initialized) { |
michael@0 | 16 | DebuggerServer.init(() => true); |
michael@0 | 17 | DebuggerServer.addBrowserActors(); |
michael@0 | 18 | } |
michael@0 | 19 | |
michael@0 | 20 | DebuggerServer.addActors(ACTORS_URL); |
michael@0 | 21 | |
michael@0 | 22 | let transport = DebuggerServer.connectPipe(); |
michael@0 | 23 | gClient = new DebuggerClient(transport); |
michael@0 | 24 | gClient.connect((aType, aTraits) => { |
michael@0 | 25 | is(aType, "browser", |
michael@0 | 26 | "Root actor should identify itself as a browser."); |
michael@0 | 27 | |
michael@0 | 28 | addTab(TAB_URL) |
michael@0 | 29 | .then(() => attachTabActorForUrl(gClient, TAB_URL)) |
michael@0 | 30 | .then(testTabActor) |
michael@0 | 31 | .then(closeTab) |
michael@0 | 32 | .then(closeConnection) |
michael@0 | 33 | .then(finish) |
michael@0 | 34 | .then(null, aError => { |
michael@0 | 35 | ok(false, "Got an error: " + aError.message + "\n" + aError.stack); |
michael@0 | 36 | }); |
michael@0 | 37 | }); |
michael@0 | 38 | } |
michael@0 | 39 | |
michael@0 | 40 | function testTabActor([aGrip, aResponse]) { |
michael@0 | 41 | let deferred = promise.defer(); |
michael@0 | 42 | |
michael@0 | 43 | ok(aGrip.testTabActor1, |
michael@0 | 44 | "Found the test tab actor."); |
michael@0 | 45 | ok(aGrip.testTabActor1.contains("test_one"), |
michael@0 | 46 | "testTabActor1's actorPrefix should be used."); |
michael@0 | 47 | |
michael@0 | 48 | gClient.request({ to: aGrip.testTabActor1, type: "ping" }, aResponse => { |
michael@0 | 49 | is(aResponse.pong, "pong", |
michael@0 | 50 | "Actor should respond to requests."); |
michael@0 | 51 | |
michael@0 | 52 | deferred.resolve(aResponse.actor); |
michael@0 | 53 | }); |
michael@0 | 54 | |
michael@0 | 55 | return deferred.promise; |
michael@0 | 56 | } |
michael@0 | 57 | |
michael@0 | 58 | function closeTab(aTestActor) { |
michael@0 | 59 | return removeTab(gBrowser.selectedTab).then(() => { |
michael@0 | 60 | let deferred = promise.defer(); |
michael@0 | 61 | |
michael@0 | 62 | try { |
michael@0 | 63 | gClient.request({ to: aTestActor, type: "ping" }, aResponse => { |
michael@0 | 64 | ok(false, "testTabActor1 didn't go away with the tab."); |
michael@0 | 65 | deferred.reject(aResponse); |
michael@0 | 66 | }); |
michael@0 | 67 | } catch(e) { |
michael@0 | 68 | is(e.message, "'ping' request packet has no destination.", "testTabActor1 went away."); |
michael@0 | 69 | deferred.resolve(); |
michael@0 | 70 | } |
michael@0 | 71 | |
michael@0 | 72 | return deferred.promise; |
michael@0 | 73 | }); |
michael@0 | 74 | } |
michael@0 | 75 | |
michael@0 | 76 | function closeConnection() { |
michael@0 | 77 | let deferred = promise.defer(); |
michael@0 | 78 | gClient.close(deferred.resolve); |
michael@0 | 79 | return deferred.promise; |
michael@0 | 80 | } |
michael@0 | 81 | |
michael@0 | 82 | registerCleanupFunction(function() { |
michael@0 | 83 | gClient = null; |
michael@0 | 84 | }); |