toolkit/devtools/server/tests/unit/test_objectgrips-12.js

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

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 // Test getDisplayString.
michael@0 5
michael@0 6 var gDebuggee;
michael@0 7 var gClient;
michael@0 8 var gThreadClient;
michael@0 9
michael@0 10 function run_test()
michael@0 11 {
michael@0 12 initTestDebuggerServer();
michael@0 13 gDebuggee = addTestGlobal("test-grips");
michael@0 14 gDebuggee.eval(function stopMe(arg1) {
michael@0 15 debugger;
michael@0 16 }.toString());
michael@0 17
michael@0 18 gClient = new DebuggerClient(DebuggerServer.connectPipe());
michael@0 19 gClient.connect(function() {
michael@0 20 attachTestTabAndResume(gClient, "test-grips", function(aResponse, aTabClient, aThreadClient) {
michael@0 21 gThreadClient = aThreadClient;
michael@0 22 test_display_string();
michael@0 23 });
michael@0 24 });
michael@0 25 do_test_pending();
michael@0 26 }
michael@0 27
michael@0 28 function test_display_string()
michael@0 29 {
michael@0 30 const testCases = [
michael@0 31 {
michael@0 32 input: "new Boolean(true)",
michael@0 33 output: "true"
michael@0 34 },
michael@0 35 {
michael@0 36 input: "new Number(5)",
michael@0 37 output: "5"
michael@0 38 },
michael@0 39 {
michael@0 40 input: "new String('foo')",
michael@0 41 output: "foo"
michael@0 42 },
michael@0 43 {
michael@0 44 input: "new Map()",
michael@0 45 output: "[object Map]"
michael@0 46 },
michael@0 47 {
michael@0 48 input: "[,,,,,,,]",
michael@0 49 output: ",,,,,,"
michael@0 50 },
michael@0 51 {
michael@0 52 input: "[1, 2, 3]",
michael@0 53 output: "1,2,3"
michael@0 54 },
michael@0 55 {
michael@0 56 input: "[undefined, null, true, 'foo', 5]",
michael@0 57 output: ",,true,foo,5"
michael@0 58 },
michael@0 59 {
michael@0 60 input: "[{},{}]",
michael@0 61 output: "[object Object],[object Object]"
michael@0 62 },
michael@0 63 {
michael@0 64 input: "(" + function() {
michael@0 65 const arr = [1];
michael@0 66 arr.push(arr);
michael@0 67 return arr;
michael@0 68 } + ")()",
michael@0 69 output: "1,"
michael@0 70 },
michael@0 71 {
michael@0 72 input: "{}",
michael@0 73 output: "[object Object]"
michael@0 74 },
michael@0 75 {
michael@0 76 input: "Object.create(null)",
michael@0 77 output: "[object Object]"
michael@0 78 },
michael@0 79 {
michael@0 80 input: "new Error('foo')",
michael@0 81 output: "Error: foo"
michael@0 82 },
michael@0 83 {
michael@0 84 input: "new SyntaxError()",
michael@0 85 output: "SyntaxError"
michael@0 86 },
michael@0 87 {
michael@0 88 input: "new ReferenceError('')",
michael@0 89 output: "ReferenceError"
michael@0 90 },
michael@0 91 {
michael@0 92 input: "(" + function() {
michael@0 93 const err = new Error("bar");
michael@0 94 err.name = "foo";
michael@0 95 return err;
michael@0 96 } + ")()",
michael@0 97 output: "foo: bar"
michael@0 98 },
michael@0 99 {
michael@0 100 input: "() => {}",
michael@0 101 output: "() => {}"
michael@0 102 },
michael@0 103 {
michael@0 104 input: "function (foo, bar) {}",
michael@0 105 output: "function (foo, bar) {}"
michael@0 106 },
michael@0 107 {
michael@0 108 input: "function foo(bar) {}",
michael@0 109 output: "function foo(bar) {}"
michael@0 110 },
michael@0 111 {
michael@0 112 input: "Array",
michael@0 113 output: Array + ""
michael@0 114 },
michael@0 115 {
michael@0 116 input: "/foo[bar]/g",
michael@0 117 output: "/foo[bar]/g"
michael@0 118 },
michael@0 119 {
michael@0 120 input: "new Proxy({}, {})",
michael@0 121 output: "[object Object]"
michael@0 122 }
michael@0 123 ];
michael@0 124
michael@0 125 gThreadClient.addOneTimeListener("paused", function(aEvent, aPacket) {
michael@0 126 const args = aPacket.frame.arguments;
michael@0 127
michael@0 128 (function loop() {
michael@0 129 const objClient = gThreadClient.pauseGrip(args.pop());
michael@0 130 objClient.getDisplayString(function({ displayString }) {
michael@0 131 do_check_eq(displayString, testCases.pop().output);
michael@0 132 if (args.length) {
michael@0 133 loop();
michael@0 134 } else {
michael@0 135 gThreadClient.resume(function() {
michael@0 136 finishClient(gClient);
michael@0 137 });
michael@0 138 }
michael@0 139 });
michael@0 140 })();
michael@0 141 });
michael@0 142
michael@0 143 const inputs = testCases.map(({ input }) => input).join(",");
michael@0 144 gDebuggee.eval("stopMe(" + inputs + ")");
michael@0 145 }

mercurial