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 values are correctly serialized and sent in enteredFrame |
michael@0 | 6 | * and exitedFrame packets. |
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 test_enter_exit_frame() |
michael@0 | 30 | { |
michael@0 | 31 | const traceStopped = promise.defer(); |
michael@0 | 32 | |
michael@0 | 33 | gClient.addListener("traces", (aEvent, { traces }) => { |
michael@0 | 34 | for (let t of traces) { |
michael@0 | 35 | check_trace(t); |
michael@0 | 36 | if (t.sequence === 27) { |
michael@0 | 37 | traceStopped.resolve(); |
michael@0 | 38 | } |
michael@0 | 39 | } |
michael@0 | 40 | }); |
michael@0 | 41 | |
michael@0 | 42 | start_trace() |
michael@0 | 43 | .then(eval_code) |
michael@0 | 44 | .then(() => traceStopped.promise) |
michael@0 | 45 | .then(stop_trace) |
michael@0 | 46 | .then(function() { |
michael@0 | 47 | finishClient(gClient); |
michael@0 | 48 | }); |
michael@0 | 49 | } |
michael@0 | 50 | |
michael@0 | 51 | function start_trace() |
michael@0 | 52 | { |
michael@0 | 53 | let deferred = promise.defer(); |
michael@0 | 54 | gTraceClient.startTrace(["arguments", "return"], null, function() { deferred.resolve(); }); |
michael@0 | 55 | return deferred.promise; |
michael@0 | 56 | } |
michael@0 | 57 | |
michael@0 | 58 | function eval_code() |
michael@0 | 59 | { |
michael@0 | 60 | gDebuggee.eval("(" + function() { |
michael@0 | 61 | function identity(x) { |
michael@0 | 62 | return x; |
michael@0 | 63 | } |
michael@0 | 64 | |
michael@0 | 65 | let circular = {}; |
michael@0 | 66 | circular.self = circular; |
michael@0 | 67 | |
michael@0 | 68 | // Make sure there is only 3 properties per object because that is the value |
michael@0 | 69 | // of MAX_PROPERTIES in the server. |
michael@0 | 70 | let obj = { |
michael@0 | 71 | num: 0, |
michael@0 | 72 | str: "foo", |
michael@0 | 73 | bool: false, |
michael@0 | 74 | }; |
michael@0 | 75 | let obj2 = { |
michael@0 | 76 | undef: undefined, |
michael@0 | 77 | nil: null, |
michael@0 | 78 | inf: Infinity |
michael@0 | 79 | }; |
michael@0 | 80 | let obj3 = { |
michael@0 | 81 | ninf: -Infinity, |
michael@0 | 82 | nan: NaN, |
michael@0 | 83 | nzero: -0 |
michael@0 | 84 | }; |
michael@0 | 85 | let obj4 = { |
michael@0 | 86 | obj: circular, |
michael@0 | 87 | arr: [1,2,3,4,5] |
michael@0 | 88 | }; |
michael@0 | 89 | |
michael@0 | 90 | identity(); |
michael@0 | 91 | identity(0); |
michael@0 | 92 | identity(""); |
michael@0 | 93 | identity(false); |
michael@0 | 94 | identity(undefined); |
michael@0 | 95 | identity(null); |
michael@0 | 96 | identity(Infinity); |
michael@0 | 97 | identity(-Infinity); |
michael@0 | 98 | identity(NaN); |
michael@0 | 99 | identity(-0); |
michael@0 | 100 | identity(obj); |
michael@0 | 101 | identity(obj2); |
michael@0 | 102 | identity(obj3); |
michael@0 | 103 | identity(obj4); |
michael@0 | 104 | } + ")()"); |
michael@0 | 105 | } |
michael@0 | 106 | |
michael@0 | 107 | function stop_trace() |
michael@0 | 108 | { |
michael@0 | 109 | let deferred = promise.defer(); |
michael@0 | 110 | gTraceClient.stopTrace(null, function() { deferred.resolve(); }); |
michael@0 | 111 | return deferred.promise; |
michael@0 | 112 | } |
michael@0 | 113 | |
michael@0 | 114 | function check_trace(aTrace) |
michael@0 | 115 | { |
michael@0 | 116 | let value = (aTrace.type === "enteredFrame" && aTrace.arguments) |
michael@0 | 117 | ? aTrace.arguments[0] |
michael@0 | 118 | : aTrace.return; |
michael@0 | 119 | switch(aTrace.sequence) { |
michael@0 | 120 | case 2: |
michael@0 | 121 | do_check_eq(typeof aTrace.arguments, "object"); |
michael@0 | 122 | do_check_eq(aTrace.arguments.length, 0); |
michael@0 | 123 | break; |
michael@0 | 124 | case 3: |
michael@0 | 125 | check_value(value, "object", "undefined"); |
michael@0 | 126 | break; |
michael@0 | 127 | case 4: |
michael@0 | 128 | case 5: |
michael@0 | 129 | check_value(value, "number", 0); |
michael@0 | 130 | break; |
michael@0 | 131 | case 6: |
michael@0 | 132 | case 7: |
michael@0 | 133 | check_value(value, "string", ""); |
michael@0 | 134 | break; |
michael@0 | 135 | case 8: |
michael@0 | 136 | case 9: |
michael@0 | 137 | check_value(value, "boolean", false); |
michael@0 | 138 | break; |
michael@0 | 139 | case 10: |
michael@0 | 140 | case 11: |
michael@0 | 141 | check_value(value, "object", "undefined"); |
michael@0 | 142 | break; |
michael@0 | 143 | case 12: |
michael@0 | 144 | case 13: |
michael@0 | 145 | check_value(value, "object", "null"); |
michael@0 | 146 | break; |
michael@0 | 147 | case 14: |
michael@0 | 148 | case 15: |
michael@0 | 149 | check_value(value, "object", "Infinity"); |
michael@0 | 150 | break; |
michael@0 | 151 | case 16: |
michael@0 | 152 | case 17: |
michael@0 | 153 | check_value(value, "object", "-Infinity"); |
michael@0 | 154 | break; |
michael@0 | 155 | case 18: |
michael@0 | 156 | case 19: |
michael@0 | 157 | check_value(value, "object", "NaN"); |
michael@0 | 158 | break; |
michael@0 | 159 | case 20: |
michael@0 | 160 | case 21: |
michael@0 | 161 | check_value(value, "object", "-0"); |
michael@0 | 162 | break; |
michael@0 | 163 | case 22: |
michael@0 | 164 | case 23: |
michael@0 | 165 | check_obj(aTrace.type, value); |
michael@0 | 166 | break; |
michael@0 | 167 | case 24: |
michael@0 | 168 | case 25: |
michael@0 | 169 | check_obj2(aTrace.type, value); |
michael@0 | 170 | break; |
michael@0 | 171 | case 26: |
michael@0 | 172 | case 27: |
michael@0 | 173 | check_obj3(aTrace.type, value); |
michael@0 | 174 | break; |
michael@0 | 175 | case 28: |
michael@0 | 176 | case 29: |
michael@0 | 177 | check_obj4(aTrace.type, value); |
michael@0 | 178 | break; |
michael@0 | 179 | } |
michael@0 | 180 | } |
michael@0 | 181 | |
michael@0 | 182 | function check_value(aActual, aExpectedType, aExpectedValue) |
michael@0 | 183 | { |
michael@0 | 184 | do_check_eq(typeof aActual, aExpectedType); |
michael@0 | 185 | do_check_eq(aExpectedType === "object" ? aActual.type : aActual, aExpectedValue); |
michael@0 | 186 | } |
michael@0 | 187 | |
michael@0 | 188 | function check_obj(aType, aObj) { |
michael@0 | 189 | do_check_eq(typeof aObj, "object"); |
michael@0 | 190 | do_check_eq(typeof aObj.ownProperties, "object"); |
michael@0 | 191 | |
michael@0 | 192 | do_check_eq(typeof aObj.ownProperties.num, "object"); |
michael@0 | 193 | do_check_eq(aObj.ownProperties.num.value, 0); |
michael@0 | 194 | |
michael@0 | 195 | do_check_eq(typeof aObj.ownProperties.str, "object"); |
michael@0 | 196 | do_check_eq(aObj.ownProperties.str.value, "foo"); |
michael@0 | 197 | |
michael@0 | 198 | do_check_eq(typeof aObj.ownProperties.bool, "object"); |
michael@0 | 199 | do_check_eq(aObj.ownProperties.bool.value, false); |
michael@0 | 200 | } |
michael@0 | 201 | |
michael@0 | 202 | function check_obj2(aType, aObj) { |
michael@0 | 203 | do_check_eq(typeof aObj.ownProperties.undef, "object"); |
michael@0 | 204 | do_check_eq(typeof aObj.ownProperties.undef.value, "object"); |
michael@0 | 205 | do_check_eq(aObj.ownProperties.undef.value.type, "undefined"); |
michael@0 | 206 | |
michael@0 | 207 | do_check_eq(typeof aObj.ownProperties.nil, "object"); |
michael@0 | 208 | do_check_eq(typeof aObj.ownProperties.nil.value, "object"); |
michael@0 | 209 | do_check_eq(aObj.ownProperties.nil.value.type, "null"); |
michael@0 | 210 | |
michael@0 | 211 | do_check_eq(typeof aObj.ownProperties.inf, "object"); |
michael@0 | 212 | do_check_eq(typeof aObj.ownProperties.inf.value, "object"); |
michael@0 | 213 | do_check_eq(aObj.ownProperties.inf.value.type, "Infinity"); |
michael@0 | 214 | } |
michael@0 | 215 | |
michael@0 | 216 | function check_obj3(aType, aObj) { |
michael@0 | 217 | do_check_eq(typeof aObj.ownProperties.ninf, "object"); |
michael@0 | 218 | do_check_eq(typeof aObj.ownProperties.ninf.value, "object"); |
michael@0 | 219 | do_check_eq(aObj.ownProperties.ninf.value.type, "-Infinity"); |
michael@0 | 220 | |
michael@0 | 221 | do_check_eq(typeof aObj.ownProperties.nan, "object"); |
michael@0 | 222 | do_check_eq(typeof aObj.ownProperties.nan.value, "object"); |
michael@0 | 223 | do_check_eq(aObj.ownProperties.nan.value.type, "NaN"); |
michael@0 | 224 | |
michael@0 | 225 | do_check_eq(typeof aObj.ownProperties.nzero, "object"); |
michael@0 | 226 | do_check_eq(typeof aObj.ownProperties.nzero.value, "object"); |
michael@0 | 227 | do_check_eq(aObj.ownProperties.nzero.value.type, "-0"); |
michael@0 | 228 | } |
michael@0 | 229 | |
michael@0 | 230 | function check_obj4(aType, aObj) { |
michael@0 | 231 | // Sub-objects aren't added. |
michael@0 | 232 | do_check_eq(typeof aObj.ownProperties.obj, "undefined"); |
michael@0 | 233 | do_check_eq(typeof aObj.ownProperties.arr, "undefined"); |
michael@0 | 234 | } |