1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/toolkit/devtools/server/tests/unit/test_objectgrips-12.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,145 @@ 1.4 +/* Any copyright is dedicated to the Public Domain. 1.5 + http://creativecommons.org/publicdomain/zero/1.0/ */ 1.6 + 1.7 +// Test getDisplayString. 1.8 + 1.9 +var gDebuggee; 1.10 +var gClient; 1.11 +var gThreadClient; 1.12 + 1.13 +function run_test() 1.14 +{ 1.15 + initTestDebuggerServer(); 1.16 + gDebuggee = addTestGlobal("test-grips"); 1.17 + gDebuggee.eval(function stopMe(arg1) { 1.18 + debugger; 1.19 + }.toString()); 1.20 + 1.21 + gClient = new DebuggerClient(DebuggerServer.connectPipe()); 1.22 + gClient.connect(function() { 1.23 + attachTestTabAndResume(gClient, "test-grips", function(aResponse, aTabClient, aThreadClient) { 1.24 + gThreadClient = aThreadClient; 1.25 + test_display_string(); 1.26 + }); 1.27 + }); 1.28 + do_test_pending(); 1.29 +} 1.30 + 1.31 +function test_display_string() 1.32 +{ 1.33 + const testCases = [ 1.34 + { 1.35 + input: "new Boolean(true)", 1.36 + output: "true" 1.37 + }, 1.38 + { 1.39 + input: "new Number(5)", 1.40 + output: "5" 1.41 + }, 1.42 + { 1.43 + input: "new String('foo')", 1.44 + output: "foo" 1.45 + }, 1.46 + { 1.47 + input: "new Map()", 1.48 + output: "[object Map]" 1.49 + }, 1.50 + { 1.51 + input: "[,,,,,,,]", 1.52 + output: ",,,,,," 1.53 + }, 1.54 + { 1.55 + input: "[1, 2, 3]", 1.56 + output: "1,2,3" 1.57 + }, 1.58 + { 1.59 + input: "[undefined, null, true, 'foo', 5]", 1.60 + output: ",,true,foo,5" 1.61 + }, 1.62 + { 1.63 + input: "[{},{}]", 1.64 + output: "[object Object],[object Object]" 1.65 + }, 1.66 + { 1.67 + input: "(" + function() { 1.68 + const arr = [1]; 1.69 + arr.push(arr); 1.70 + return arr; 1.71 + } + ")()", 1.72 + output: "1," 1.73 + }, 1.74 + { 1.75 + input: "{}", 1.76 + output: "[object Object]" 1.77 + }, 1.78 + { 1.79 + input: "Object.create(null)", 1.80 + output: "[object Object]" 1.81 + }, 1.82 + { 1.83 + input: "new Error('foo')", 1.84 + output: "Error: foo" 1.85 + }, 1.86 + { 1.87 + input: "new SyntaxError()", 1.88 + output: "SyntaxError" 1.89 + }, 1.90 + { 1.91 + input: "new ReferenceError('')", 1.92 + output: "ReferenceError" 1.93 + }, 1.94 + { 1.95 + input: "(" + function() { 1.96 + const err = new Error("bar"); 1.97 + err.name = "foo"; 1.98 + return err; 1.99 + } + ")()", 1.100 + output: "foo: bar" 1.101 + }, 1.102 + { 1.103 + input: "() => {}", 1.104 + output: "() => {}" 1.105 + }, 1.106 + { 1.107 + input: "function (foo, bar) {}", 1.108 + output: "function (foo, bar) {}" 1.109 + }, 1.110 + { 1.111 + input: "function foo(bar) {}", 1.112 + output: "function foo(bar) {}" 1.113 + }, 1.114 + { 1.115 + input: "Array", 1.116 + output: Array + "" 1.117 + }, 1.118 + { 1.119 + input: "/foo[bar]/g", 1.120 + output: "/foo[bar]/g" 1.121 + }, 1.122 + { 1.123 + input: "new Proxy({}, {})", 1.124 + output: "[object Object]" 1.125 + } 1.126 + ]; 1.127 + 1.128 + gThreadClient.addOneTimeListener("paused", function(aEvent, aPacket) { 1.129 + const args = aPacket.frame.arguments; 1.130 + 1.131 + (function loop() { 1.132 + const objClient = gThreadClient.pauseGrip(args.pop()); 1.133 + objClient.getDisplayString(function({ displayString }) { 1.134 + do_check_eq(displayString, testCases.pop().output); 1.135 + if (args.length) { 1.136 + loop(); 1.137 + } else { 1.138 + gThreadClient.resume(function() { 1.139 + finishClient(gClient); 1.140 + }); 1.141 + } 1.142 + }); 1.143 + })(); 1.144 + }); 1.145 + 1.146 + const inputs = testCases.map(({ input }) => input).join(","); 1.147 + gDebuggee.eval("stopMe(" + inputs + ")"); 1.148 +}