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 the behavior of the debugger statement. |
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; |
michael@0 | 11 | |
michael@0 | 12 | function test() { |
michael@0 | 13 | if (!DebuggerServer.initialized) { |
michael@0 | 14 | DebuggerServer.init(() => true); |
michael@0 | 15 | DebuggerServer.addBrowserActors(); |
michael@0 | 16 | } |
michael@0 | 17 | |
michael@0 | 18 | let transport = DebuggerServer.connectPipe(); |
michael@0 | 19 | gClient = new DebuggerClient(transport); |
michael@0 | 20 | gClient.connect((aType, aTraits) => { |
michael@0 | 21 | is(aType, "browser", |
michael@0 | 22 | "Root actor should identify itself as a browser."); |
michael@0 | 23 | |
michael@0 | 24 | addTab(TAB_URL) |
michael@0 | 25 | .then(() => attachTabActorForUrl(gClient, TAB_URL)) |
michael@0 | 26 | .then(testEarlyDebuggerStatement) |
michael@0 | 27 | .then(testDebuggerStatement) |
michael@0 | 28 | .then(closeConnection) |
michael@0 | 29 | .then(finish) |
michael@0 | 30 | .then(null, aError => { |
michael@0 | 31 | ok(false, "Got an error: " + aError.message + "\n" + aError.stack); |
michael@0 | 32 | }); |
michael@0 | 33 | }); |
michael@0 | 34 | } |
michael@0 | 35 | |
michael@0 | 36 | function testEarlyDebuggerStatement([aGrip, aResponse]) { |
michael@0 | 37 | let deferred = promise.defer(); |
michael@0 | 38 | |
michael@0 | 39 | let onPaused = function(aEvent, aPacket) { |
michael@0 | 40 | ok(false, "Pause shouldn't be called before we've attached!"); |
michael@0 | 41 | deferred.reject(); |
michael@0 | 42 | }; |
michael@0 | 43 | |
michael@0 | 44 | gClient.addListener("paused", onPaused); |
michael@0 | 45 | |
michael@0 | 46 | // This should continue without nesting an event loop and calling |
michael@0 | 47 | // the onPaused hook, because we haven't attached yet. |
michael@0 | 48 | let debuggee = gBrowser.selectedTab.linkedBrowser.contentWindow.wrappedJSObject; |
michael@0 | 49 | debuggee.runDebuggerStatement(); |
michael@0 | 50 | |
michael@0 | 51 | gClient.removeListener("paused", onPaused); |
michael@0 | 52 | |
michael@0 | 53 | // Now attach and resume... |
michael@0 | 54 | gClient.request({ to: aResponse.threadActor, type: "attach" }, () => { |
michael@0 | 55 | gClient.request({ to: aResponse.threadActor, type: "resume" }, () => { |
michael@0 | 56 | ok(true, "Pause wasn't called before we've attached."); |
michael@0 | 57 | deferred.resolve([aGrip, aResponse]); |
michael@0 | 58 | }); |
michael@0 | 59 | }); |
michael@0 | 60 | |
michael@0 | 61 | return deferred.promise; |
michael@0 | 62 | } |
michael@0 | 63 | |
michael@0 | 64 | function testDebuggerStatement([aGrip, aResponse]) { |
michael@0 | 65 | let deferred = promise.defer(); |
michael@0 | 66 | |
michael@0 | 67 | gClient.addListener("paused", (aEvent, aPacket) => { |
michael@0 | 68 | gClient.request({ to: aResponse.threadActor, type: "resume" }, () => { |
michael@0 | 69 | ok(true, "The pause handler was triggered on a debugger statement."); |
michael@0 | 70 | deferred.resolve(); |
michael@0 | 71 | }); |
michael@0 | 72 | }); |
michael@0 | 73 | |
michael@0 | 74 | // Reach around the debugging protocol and execute the debugger statement. |
michael@0 | 75 | let debuggee = gBrowser.selectedTab.linkedBrowser.contentWindow.wrappedJSObject; |
michael@0 | 76 | debuggee.runDebuggerStatement(); |
michael@0 | 77 | } |
michael@0 | 78 | |
michael@0 | 79 | function closeConnection() { |
michael@0 | 80 | let deferred = promise.defer(); |
michael@0 | 81 | gClient.close(deferred.resolve); |
michael@0 | 82 | return deferred.promise; |
michael@0 | 83 | } |
michael@0 | 84 | |
michael@0 | 85 | registerCleanupFunction(function() { |
michael@0 | 86 | removeTab(gBrowser.selectedTab); |
michael@0 | 87 | gClient = null; |
michael@0 | 88 | }); |
michael@0 | 89 |