1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/toolkit/devtools/webconsole/test/test_consoleapi_innerID.html Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,164 @@ 1.4 +<!DOCTYPE HTML> 1.5 +<html lang="en"> 1.6 +<head> 1.7 + <meta charset="utf8"> 1.8 + <title>Test for the innerID property of the Console API</title> 1.9 + <script type="text/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script> 1.10 + <script type="text/javascript;version=1.8" src="common.js"></script> 1.11 + <!-- Any copyright is dedicated to the Public Domain. 1.12 + - http://creativecommons.org/publicdomain/zero/1.0/ --> 1.13 +</head> 1.14 +<body> 1.15 +<p>Test for the Console API</p> 1.16 + 1.17 +<script class="testbody" type="text/javascript;version=1.8"> 1.18 +SimpleTest.waitForExplicitFinish(); 1.19 + 1.20 +let expectedConsoleCalls = []; 1.21 + 1.22 +function doConsoleCalls(aState) 1.23 +{ 1.24 + let { ConsoleAPI } = Cu.import("resource://gre/modules/devtools/Console.jsm", {}); 1.25 + let console = new ConsoleAPI({ 1.26 + innerID: window.QueryInterface(Ci.nsIInterfaceRequestor) 1.27 + .getInterface(Ci.nsIDOMWindowUtils) 1.28 + .currentInnerWindowID 1.29 + }); 1.30 + 1.31 + let longString = (new Array(DebuggerServer.LONG_STRING_LENGTH + 2)).join("a"); 1.32 + 1.33 + console.log("foobarBaz-log", undefined); 1.34 + console.info("foobarBaz-info", null); 1.35 + console.warn("foobarBaz-warn", top.document.documentElement); 1.36 + console.debug(null); 1.37 + console.trace(); 1.38 + console.dir(top.document, top.location); 1.39 + console.log("foo", longString); 1.40 + 1.41 + expectedConsoleCalls = [ 1.42 + { 1.43 + level: "log", 1.44 + filename: /test_consoleapi/, 1.45 + functionName: "doConsoleCalls", 1.46 + timeStamp: /^\d+$/, 1.47 + arguments: ["foobarBaz-log", { type: "undefined" }], 1.48 + }, 1.49 + { 1.50 + level: "info", 1.51 + filename: /test_consoleapi/, 1.52 + functionName: "doConsoleCalls", 1.53 + timeStamp: /^\d+$/, 1.54 + arguments: ["foobarBaz-info", { type: "null" }], 1.55 + }, 1.56 + { 1.57 + level: "warn", 1.58 + filename: /test_consoleapi/, 1.59 + functionName: "doConsoleCalls", 1.60 + timeStamp: /^\d+$/, 1.61 + arguments: ["foobarBaz-warn", { type: "object", actor: /[a-z]/ }], 1.62 + }, 1.63 + { 1.64 + level: "debug", 1.65 + filename: /test_consoleapi/, 1.66 + functionName: "doConsoleCalls", 1.67 + timeStamp: /^\d+$/, 1.68 + arguments: [{ type: "null" }], 1.69 + }, 1.70 + { 1.71 + level: "trace", 1.72 + filename: /test_consoleapi/, 1.73 + functionName: "doConsoleCalls", 1.74 + timeStamp: /^\d+$/, 1.75 + stacktrace: [ 1.76 + { 1.77 + filename: /test_consoleapi/, 1.78 + functionName: "doConsoleCalls", 1.79 + }, 1.80 + { 1.81 + filename: /test_consoleapi/, 1.82 + functionName: "onAttach", 1.83 + }, 1.84 + ], 1.85 + }, 1.86 + { 1.87 + level: "dir", 1.88 + filename: /test_consoleapi/, 1.89 + functionName: "doConsoleCalls", 1.90 + timeStamp: /^\d+$/, 1.91 + arguments: [ 1.92 + { 1.93 + type: "object", 1.94 + actor: /[a-z]/, 1.95 + class: "XULDocument", 1.96 + }, 1.97 + { 1.98 + type: "object", 1.99 + actor: /[a-z]/, 1.100 + class: "Location", 1.101 + } 1.102 + ], 1.103 + }, 1.104 + { 1.105 + level: "log", 1.106 + filename: /test_consoleapi/, 1.107 + functionName: "doConsoleCalls", 1.108 + timeStamp: /^\d+$/, 1.109 + arguments: [ 1.110 + "foo", 1.111 + { 1.112 + type: "longString", 1.113 + initial: longString.substring(0, 1.114 + DebuggerServer.LONG_STRING_INITIAL_LENGTH), 1.115 + length: longString.length, 1.116 + actor: /[a-z]/, 1.117 + }, 1.118 + ], 1.119 + }, 1.120 + ]; 1.121 +} 1.122 + 1.123 +function startTest() 1.124 +{ 1.125 + removeEventListener("load", startTest); 1.126 + 1.127 + attachConsole(["ConsoleAPI"], onAttach, true); 1.128 +} 1.129 + 1.130 +function onAttach(aState, aResponse) 1.131 +{ 1.132 + onConsoleAPICall = onConsoleAPICall.bind(null, aState); 1.133 + aState.dbgClient.addListener("consoleAPICall", onConsoleAPICall); 1.134 + doConsoleCalls(aState.actor); 1.135 +} 1.136 + 1.137 +let consoleCalls = []; 1.138 + 1.139 +function onConsoleAPICall(aState, aType, aPacket) 1.140 +{ 1.141 + info("received message level: " + aPacket.message.level); 1.142 + is(aPacket.from, aState.actor, "console API call actor"); 1.143 + 1.144 + consoleCalls.push(aPacket.message); 1.145 + if (consoleCalls.length != expectedConsoleCalls.length) { 1.146 + return; 1.147 + } 1.148 + 1.149 + aState.dbgClient.removeListener("consoleAPICall", onConsoleAPICall); 1.150 + 1.151 + expectedConsoleCalls.forEach(function(aMessage, aIndex) { 1.152 + info("checking received console call #" + aIndex); 1.153 + checkConsoleAPICall(consoleCalls[aIndex], expectedConsoleCalls[aIndex]); 1.154 + }); 1.155 + 1.156 + 1.157 + consoleCalls = []; 1.158 + 1.159 + closeDebugger(aState, function() { 1.160 + SimpleTest.finish(); 1.161 + }); 1.162 +} 1.163 + 1.164 +addEventListener("load", startTest); 1.165 +</script> 1.166 +</body> 1.167 +</html>