toolkit/devtools/server/tests/unit/test_trace_actor-05.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 /**
michael@0 5 * Simple tests for "location", "callsite", "time", "parameterNames",
michael@0 6 * "arguments", and "return" trace types.
michael@0 7 */
michael@0 8
michael@0 9 var gDebuggee;
michael@0 10 var gClient;
michael@0 11 var gTraceClient;
michael@0 12
michael@0 13 function run_test()
michael@0 14 {
michael@0 15 initTestTracerServer();
michael@0 16 gDebuggee = addTestGlobal("test-tracer-actor");
michael@0 17 gClient = new DebuggerClient(DebuggerServer.connectPipe());
michael@0 18 gClient.connect(function() {
michael@0 19 attachTestTab(gClient, "test-tracer-actor", function(aResponse, aTabClient) {
michael@0 20 gClient.attachTracer(aResponse.traceActor, function(aResponse, aTraceClient) {
michael@0 21 gTraceClient = aTraceClient;
michael@0 22 test_enter_exit_frame();
michael@0 23 });
michael@0 24 });
michael@0 25 });
michael@0 26 do_test_pending();
michael@0 27 }
michael@0 28
michael@0 29 function check_number(value)
michael@0 30 {
michael@0 31 do_check_eq(typeof value, "number");
michael@0 32 do_check_true(!isNaN(value));
michael@0 33 }
michael@0 34
michael@0 35 function check_location(actual, expected)
michael@0 36 {
michael@0 37 do_check_eq(typeof actual, "object");
michael@0 38
michael@0 39 check_number(actual.line);
michael@0 40 check_number(actual.column);
michael@0 41
michael@0 42 do_check_eq(actual.url, expected.url);
michael@0 43 do_check_eq(actual.line, expected.line);
michael@0 44 do_check_eq(actual.column, expected.column);
michael@0 45
michael@0 46 }
michael@0 47
michael@0 48 function test_enter_exit_frame()
michael@0 49 {
michael@0 50 let traces = [];
michael@0 51 let traceStopped = promise.defer();
michael@0 52
michael@0 53 gClient.addListener("traces", function(aEvent, aPacket) {
michael@0 54 for (let t of aPacket.traces) {
michael@0 55 if (t.type == "enteredFrame") {
michael@0 56 do_check_eq(typeof t.name, "string");
michael@0 57 do_check_eq(typeof t.location, "object");
michael@0 58
michael@0 59 check_number(t.sequence);
michael@0 60 check_number(t.time);
michael@0 61 check_number(t.location.line);
michael@0 62 check_number(t.location.column);
michael@0 63 if (t.callsite) {
michael@0 64 check_number(t.callsite.line);
michael@0 65 check_number(t.callsite.column);
michael@0 66 }
michael@0 67 } else {
michael@0 68 check_number(t.sequence);
michael@0 69 check_number(t.time);
michael@0 70 }
michael@0 71
michael@0 72 traces[t.sequence] = t;
michael@0 73 if (traces.length === 4) {
michael@0 74 traceStopped.resolve();
michael@0 75 }
michael@0 76 }
michael@0 77 });
michael@0 78
michael@0 79 start_trace()
michael@0 80 .then(eval_code)
michael@0 81 .then(() => traceStopped.promise)
michael@0 82 .then(stop_trace)
michael@0 83 .then(function() {
michael@0 84 let url = getFileUrl("tracerlocations.js");
michael@0 85
michael@0 86 check_location(traces[0].location, { url: url, line: 1, column: 0 });
michael@0 87
michael@0 88 do_check_eq(traces[1].name, "foo");
michael@0 89
michael@0 90 // XXX: foo's definition is at tracerlocations.js:3:0, but Debugger.Script
michael@0 91 // does not provide complete definition locations (bug 901138). Therefore,
michael@0 92 // we use the first statement in the function (tracerlocations.js:4:2) as
michael@0 93 // an approximation.
michael@0 94 //
michael@0 95 // However, |column| will always be 0 until we can get bug 863089
michael@0 96 // fixed.
michael@0 97 check_location(traces[1].location, { url: url, line: 4, column: 0 });
michael@0 98 check_location(traces[1].callsite, { url: url, line: 8, column: 0 });
michael@0 99
michael@0 100 do_check_eq(typeof traces[1].parameterNames, "object");
michael@0 101 do_check_eq(traces[1].parameterNames.length, 1);
michael@0 102 do_check_eq(traces[1].parameterNames[0], "x");
michael@0 103
michael@0 104 do_check_eq(typeof traces[1].arguments, "object");
michael@0 105 do_check_true(Array.isArray(traces[1].arguments));
michael@0 106 do_check_eq(traces[1].arguments.length, 1);
michael@0 107 do_check_eq(traces[1].arguments[0], 42);
michael@0 108
michael@0 109 do_check_eq(typeof traces[2].return, "string");
michael@0 110 do_check_eq(traces[2].return, "bar");
michael@0 111
michael@0 112 finishClient(gClient);
michael@0 113 }, error => {
michael@0 114 DevToolsUtils.reportException("test_trace_actor-05.js", error);
michael@0 115 do_check_true(false);
michael@0 116 });
michael@0 117 }
michael@0 118
michael@0 119 function start_trace()
michael@0 120 {
michael@0 121 let deferred = promise.defer();
michael@0 122 gTraceClient.startTrace(
michael@0 123 ["name", "location", "callsite", "time", "parameterNames", "arguments", "return"],
michael@0 124 null,
michael@0 125 function() { deferred.resolve(); });
michael@0 126 return deferred.promise;
michael@0 127 }
michael@0 128
michael@0 129 function eval_code()
michael@0 130 {
michael@0 131 let code = readFile("tracerlocations.js");
michael@0 132 Components.utils.evalInSandbox(code, gDebuggee, "1.8",
michael@0 133 getFileUrl("tracerlocations.js"), 1);
michael@0 134 }
michael@0 135
michael@0 136 function stop_trace()
michael@0 137 {
michael@0 138 let deferred = promise.defer();
michael@0 139 gTraceClient.stopTrace(null, function() { deferred.resolve(); });
michael@0 140 return deferred.promise;
michael@0 141 }

mercurial