toolkit/devtools/server/tests/unit/test_dbgactor.js

Sat, 03 Jan 2015 20:18:00 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Sat, 03 Jan 2015 20:18:00 +0100
branch
TOR_BUG_3246
changeset 7
129ffea94266
permissions
-rw-r--r--

Conditionally enable double key logic according to:
private browsing mode or privacy.thirdparty.isolate preference and
implement in GetCookieStringCommon and FindCookie where it counts...
With some reservations of how to convince FindCookie users to test
condition and pass a nullptr when disabling double key logic.

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 Cu.import("resource://gre/modules/devtools/dbg-server.jsm");
michael@0 5 Cu.import("resource://gre/modules/devtools/dbg-client.jsm");
michael@0 6
michael@0 7 var gClient;
michael@0 8 var gDebuggee;
michael@0 9
michael@0 10 const xpcInspector = Cc["@mozilla.org/jsinspector;1"].getService(Ci.nsIJSInspector);
michael@0 11
michael@0 12 function run_test()
michael@0 13 {
michael@0 14 initTestDebuggerServer();
michael@0 15 gDebuggee = testGlobal("test-1");
michael@0 16 DebuggerServer.addTestGlobal(gDebuggee);
michael@0 17
michael@0 18 let transport = DebuggerServer.connectPipe();
michael@0 19 gClient = new DebuggerClient(transport);
michael@0 20 gClient.addListener("connected", function(aEvent, aType, aTraits) {
michael@0 21 gClient.listTabs((aResponse) => {
michael@0 22 do_check_true('tabs' in aResponse);
michael@0 23 for (let tab of aResponse.tabs) {
michael@0 24 if (tab.title == "test-1") {
michael@0 25 test_attach_tab(tab.actor);
michael@0 26 return false;
michael@0 27 }
michael@0 28 }
michael@0 29 do_check_true(false); // We should have found our tab in the list.
michael@0 30 return undefined;
michael@0 31 });
michael@0 32 });
michael@0 33
michael@0 34 gClient.connect();
michael@0 35
michael@0 36 do_test_pending();
michael@0 37 }
michael@0 38
michael@0 39 // Attach to |aTabActor|, and check the response.
michael@0 40 function test_attach_tab(aTabActor)
michael@0 41 {
michael@0 42 gClient.request({ to: aTabActor, type: "attach" }, function(aResponse) {
michael@0 43 do_check_false("error" in aResponse);
michael@0 44 do_check_eq(aResponse.from, aTabActor);
michael@0 45 do_check_eq(aResponse.type, "tabAttached");
michael@0 46 do_check_true(typeof aResponse.threadActor === "string");
michael@0 47
michael@0 48 test_attach_thread(aResponse.threadActor);
michael@0 49 });
michael@0 50 }
michael@0 51
michael@0 52 // Attach to |aThreadActor|, check the response, and resume it.
michael@0 53 function test_attach_thread(aThreadActor)
michael@0 54 {
michael@0 55 gClient.request({ to: aThreadActor, type: "attach" }, function(aResponse) {
michael@0 56 do_check_false("error" in aResponse);
michael@0 57 do_check_eq(aResponse.from, aThreadActor);
michael@0 58 do_check_eq(aResponse.type, "paused");
michael@0 59 do_check_true("why" in aResponse);
michael@0 60 do_check_eq(aResponse.why.type, "attached");
michael@0 61
michael@0 62 test_resume_thread(aThreadActor);
michael@0 63 });
michael@0 64 }
michael@0 65
michael@0 66 // Resume |aThreadActor|, and see that it stops at the 'debugger'
michael@0 67 // statement.
michael@0 68 function test_resume_thread(aThreadActor)
michael@0 69 {
michael@0 70 // Allow the client to resume execution.
michael@0 71 gClient.request({ to: aThreadActor, type: "resume" }, function (aResponse) {
michael@0 72 do_check_false("error" in aResponse);
michael@0 73 do_check_eq(aResponse.from, aThreadActor);
michael@0 74 do_check_eq(aResponse.type, "resumed");
michael@0 75
michael@0 76 do_check_eq(xpcInspector.eventLoopNestLevel, 0);
michael@0 77
michael@0 78 // Now that we know we're resumed, we can make the debuggee do something.
michael@0 79 Cu.evalInSandbox("var a = true; var b = false; debugger; var b = true;", gDebuggee);
michael@0 80 // Now make sure that we've run the code after the debugger statement...
michael@0 81 do_check_true(gDebuggee.b);
michael@0 82 });
michael@0 83
michael@0 84 gClient.addListener("paused", function(aName, aPacket) {
michael@0 85 do_check_eq(aName, "paused");
michael@0 86 do_check_false("error" in aPacket);
michael@0 87 do_check_eq(aPacket.from, aThreadActor);
michael@0 88 do_check_eq(aPacket.type, "paused");
michael@0 89 do_check_true("actor" in aPacket);
michael@0 90 do_check_true("why" in aPacket)
michael@0 91 do_check_eq(aPacket.why.type, "debuggerStatement");
michael@0 92
michael@0 93 // Reach around the protocol to check that the debuggee is in the state
michael@0 94 // we expect.
michael@0 95 do_check_true(gDebuggee.a);
michael@0 96 do_check_false(gDebuggee.b);
michael@0 97
michael@0 98 do_check_eq(xpcInspector.eventLoopNestLevel, 1);
michael@0 99
michael@0 100 // Let the debuggee continue execution.
michael@0 101 gClient.request({ to: aThreadActor, type: "resume" }, cleanup);
michael@0 102 });
michael@0 103 }
michael@0 104
michael@0 105 function cleanup()
michael@0 106 {
michael@0 107 gClient.addListener("closed", function(aEvent, aResult) {
michael@0 108 do_test_finished();
michael@0 109 });
michael@0 110
michael@0 111 try {
michael@0 112 let xpcInspector = Cc["@mozilla.org/jsinspector;1"].getService(Ci.nsIJSInspector);
michael@0 113 do_check_eq(xpcInspector.eventLoopNestLevel, 0);
michael@0 114 } catch(e) {
michael@0 115 dump(e);
michael@0 116 }
michael@0 117
michael@0 118 gClient.close();
michael@0 119 }

mercurial