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 | * Test the "depth" trace type. |
michael@0 | 6 | */ |
michael@0 | 7 | |
michael@0 | 8 | var gDebuggee; |
michael@0 | 9 | var gClient; |
michael@0 | 10 | var gTraceClient; |
michael@0 | 11 | |
michael@0 | 12 | function run_test() |
michael@0 | 13 | { |
michael@0 | 14 | initTestTracerServer(); |
michael@0 | 15 | gDebuggee = addTestGlobal("test-tracer-actor"); |
michael@0 | 16 | gClient = new DebuggerClient(DebuggerServer.connectPipe()); |
michael@0 | 17 | gClient.connect(function() { |
michael@0 | 18 | attachTestTab(gClient, "test-tracer-actor", function(aResponse, aTabClient) { |
michael@0 | 19 | gClient.attachTracer(aResponse.traceActor, function(aResponse, aTraceClient) { |
michael@0 | 20 | gTraceClient = aTraceClient; |
michael@0 | 21 | test_frame_depths(); |
michael@0 | 22 | }); |
michael@0 | 23 | }); |
michael@0 | 24 | }); |
michael@0 | 25 | do_test_pending(); |
michael@0 | 26 | } |
michael@0 | 27 | |
michael@0 | 28 | function test_frame_depths() |
michael@0 | 29 | { |
michael@0 | 30 | const tracesStopped = promise.defer(); |
michael@0 | 31 | gClient.addListener("traces", (aEvent, { traces }) => { |
michael@0 | 32 | for (let t of traces) { |
michael@0 | 33 | check_trace(t); |
michael@0 | 34 | } |
michael@0 | 35 | tracesStopped.resolve(); |
michael@0 | 36 | }); |
michael@0 | 37 | |
michael@0 | 38 | start_trace() |
michael@0 | 39 | .then(eval_code) |
michael@0 | 40 | .then(() => tracesStopped.promise) |
michael@0 | 41 | .then(stop_trace) |
michael@0 | 42 | .then(function() { |
michael@0 | 43 | finishClient(gClient); |
michael@0 | 44 | }).then(null, error => { |
michael@0 | 45 | do_check_true(false, "Should not get an error, got: " + error); |
michael@0 | 46 | }); |
michael@0 | 47 | } |
michael@0 | 48 | |
michael@0 | 49 | function start_trace() |
michael@0 | 50 | { |
michael@0 | 51 | let deferred = promise.defer(); |
michael@0 | 52 | gTraceClient.startTrace(["depth", "name"], null, function() { deferred.resolve(); }); |
michael@0 | 53 | return deferred.promise; |
michael@0 | 54 | } |
michael@0 | 55 | |
michael@0 | 56 | function eval_code() |
michael@0 | 57 | { |
michael@0 | 58 | gDebuggee.eval("(" + function iife() { |
michael@0 | 59 | function first() { |
michael@0 | 60 | second(); |
michael@0 | 61 | } |
michael@0 | 62 | |
michael@0 | 63 | function second() { |
michael@0 | 64 | third(); |
michael@0 | 65 | } |
michael@0 | 66 | |
michael@0 | 67 | function third() { |
michael@0 | 68 | } |
michael@0 | 69 | |
michael@0 | 70 | first(); |
michael@0 | 71 | } + ")()"); |
michael@0 | 72 | } |
michael@0 | 73 | |
michael@0 | 74 | function stop_trace() |
michael@0 | 75 | { |
michael@0 | 76 | let deferred = promise.defer(); |
michael@0 | 77 | gTraceClient.stopTrace(null, function() { deferred.resolve(); }); |
michael@0 | 78 | return deferred.promise; |
michael@0 | 79 | } |
michael@0 | 80 | |
michael@0 | 81 | function check_trace({ sequence, depth, name }) |
michael@0 | 82 | { |
michael@0 | 83 | switch(sequence) { |
michael@0 | 84 | case 0: |
michael@0 | 85 | do_check_eq(name, "(eval)"); |
michael@0 | 86 | // Fall through |
michael@0 | 87 | case 9: |
michael@0 | 88 | do_check_eq(depth, 0); |
michael@0 | 89 | break; |
michael@0 | 90 | |
michael@0 | 91 | case 1: |
michael@0 | 92 | do_check_eq(name, "iife"); |
michael@0 | 93 | // Fall through |
michael@0 | 94 | case 8: |
michael@0 | 95 | do_check_eq(depth, 1); |
michael@0 | 96 | break; |
michael@0 | 97 | |
michael@0 | 98 | case 2: |
michael@0 | 99 | do_check_eq(name, "first"); |
michael@0 | 100 | // Fall through |
michael@0 | 101 | case 7: |
michael@0 | 102 | do_check_eq(depth, 2); |
michael@0 | 103 | break; |
michael@0 | 104 | |
michael@0 | 105 | case 3: |
michael@0 | 106 | do_check_eq(name, "second"); |
michael@0 | 107 | // Fall through |
michael@0 | 108 | case 6: |
michael@0 | 109 | do_check_eq(depth, 3); |
michael@0 | 110 | break; |
michael@0 | 111 | |
michael@0 | 112 | case 4: |
michael@0 | 113 | do_check_eq(name, "third"); |
michael@0 | 114 | // Fall through |
michael@0 | 115 | case 5: |
michael@0 | 116 | do_check_eq(depth, 4); |
michael@0 | 117 | break; |
michael@0 | 118 | |
michael@0 | 119 | default: |
michael@0 | 120 | // Should have covered all sequences. |
michael@0 | 121 | do_check_true(false); |
michael@0 | 122 | } |
michael@0 | 123 | } |