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 | * Tests that chrome debugging works. |
michael@0 | 6 | */ |
michael@0 | 7 | |
michael@0 | 8 | const TAB_URL = EXAMPLE_URL + "doc_inline-debugger-statement.html"; |
michael@0 | 9 | |
michael@0 | 10 | let gClient, gThreadClient; |
michael@0 | 11 | let gAttached = promise.defer(); |
michael@0 | 12 | let gNewGlobal = promise.defer() |
michael@0 | 13 | let gNewChromeSource = promise.defer() |
michael@0 | 14 | |
michael@0 | 15 | let { DevToolsLoader } = Cu.import("resource://gre/modules/devtools/Loader.jsm", {}); |
michael@0 | 16 | let loader = new DevToolsLoader(); |
michael@0 | 17 | loader.invisibleToDebugger = true; |
michael@0 | 18 | loader.main("devtools/server/main"); |
michael@0 | 19 | let DebuggerServer = loader.DebuggerServer; |
michael@0 | 20 | |
michael@0 | 21 | function test() { |
michael@0 | 22 | if (!DebuggerServer.initialized) { |
michael@0 | 23 | DebuggerServer.init(() => true); |
michael@0 | 24 | DebuggerServer.addBrowserActors(); |
michael@0 | 25 | } |
michael@0 | 26 | |
michael@0 | 27 | let transport = DebuggerServer.connectPipe(); |
michael@0 | 28 | gClient = new DebuggerClient(transport); |
michael@0 | 29 | gClient.connect((aType, aTraits) => { |
michael@0 | 30 | is(aType, "browser", |
michael@0 | 31 | "Root actor should identify itself as a browser."); |
michael@0 | 32 | |
michael@0 | 33 | promise.all([gAttached.promise, gNewGlobal.promise, gNewChromeSource.promise]) |
michael@0 | 34 | .then(resumeAndCloseConnection) |
michael@0 | 35 | .then(finish) |
michael@0 | 36 | .then(null, aError => { |
michael@0 | 37 | ok(false, "Got an error: " + aError.message + "\n" + aError.stack); |
michael@0 | 38 | }); |
michael@0 | 39 | |
michael@0 | 40 | testChromeActor(); |
michael@0 | 41 | }); |
michael@0 | 42 | } |
michael@0 | 43 | |
michael@0 | 44 | function testChromeActor() { |
michael@0 | 45 | gClient.listTabs(aResponse => { |
michael@0 | 46 | ok(aResponse.chromeDebugger.contains("chromeDebugger"), |
michael@0 | 47 | "Chrome debugger actor should identify itself accordingly."); |
michael@0 | 48 | |
michael@0 | 49 | gClient.addListener("newGlobal", onNewGlobal); |
michael@0 | 50 | gClient.addListener("newSource", onNewSource); |
michael@0 | 51 | |
michael@0 | 52 | gClient.attachThread(aResponse.chromeDebugger, (aResponse, aThreadClient) => { |
michael@0 | 53 | gThreadClient = aThreadClient; |
michael@0 | 54 | |
michael@0 | 55 | if (aResponse.error) { |
michael@0 | 56 | ok(false, "Couldn't attach to the chrome debugger."); |
michael@0 | 57 | gAttached.reject(); |
michael@0 | 58 | } else { |
michael@0 | 59 | ok(true, "Attached to the chrome debugger."); |
michael@0 | 60 | gAttached.resolve(); |
michael@0 | 61 | |
michael@0 | 62 | // Ensure that a new chrome global will be created. |
michael@0 | 63 | gBrowser.selectedTab = gBrowser.addTab("about:mozilla"); |
michael@0 | 64 | } |
michael@0 | 65 | }); |
michael@0 | 66 | }); |
michael@0 | 67 | } |
michael@0 | 68 | |
michael@0 | 69 | function onNewGlobal() { |
michael@0 | 70 | ok(true, "Received a new chrome global."); |
michael@0 | 71 | |
michael@0 | 72 | gClient.removeListener("newGlobal", onNewGlobal); |
michael@0 | 73 | gNewGlobal.resolve(); |
michael@0 | 74 | } |
michael@0 | 75 | |
michael@0 | 76 | function onNewSource(aEvent, aPacket) { |
michael@0 | 77 | if (aPacket.source.url.startsWith("chrome:")) { |
michael@0 | 78 | ok(true, "Received a new chrome source: " + aPacket.source.url); |
michael@0 | 79 | |
michael@0 | 80 | gClient.removeListener("newSource", onNewSource); |
michael@0 | 81 | gNewChromeSource.resolve(); |
michael@0 | 82 | } |
michael@0 | 83 | } |
michael@0 | 84 | |
michael@0 | 85 | function resumeAndCloseConnection() { |
michael@0 | 86 | let deferred = promise.defer(); |
michael@0 | 87 | gThreadClient.resume(() => gClient.close(deferred.resolve)); |
michael@0 | 88 | return deferred.promise; |
michael@0 | 89 | } |
michael@0 | 90 | |
michael@0 | 91 | registerCleanupFunction(function() { |
michael@0 | 92 | removeTab(gBrowser.selectedTab); |
michael@0 | 93 | gClient = null; |
michael@0 | 94 | gThreadClient = null; |
michael@0 | 95 | gAttached = null; |
michael@0 | 96 | gNewGlobal = null; |
michael@0 | 97 | gNewChromeSource = null; |
michael@0 | 98 | |
michael@0 | 99 | loader = null; |
michael@0 | 100 | DebuggerServer = null; |
michael@0 | 101 | }); |