toolkit/devtools/webconsole/test/test_consoleapi.html

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/toolkit/devtools/webconsole/test/test_consoleapi.html	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,157 @@
     1.4 +<!DOCTYPE HTML>
     1.5 +<html lang="en">
     1.6 +<head>
     1.7 +  <meta charset="utf8">
     1.8 +  <title>Test for 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 longString = (new Array(DebuggerServer.LONG_STRING_LENGTH + 2)).join("a");
    1.25 +
    1.26 +  top.console.log("foobarBaz-log", undefined);
    1.27 +  top.console.info("foobarBaz-info", null);
    1.28 +  top.console.warn("foobarBaz-warn", top.document.documentElement);
    1.29 +  top.console.debug(null);
    1.30 +  top.console.trace();
    1.31 +  top.console.dir(top.document, top.location);
    1.32 +  top.console.log("foo", longString);
    1.33 +
    1.34 +  expectedConsoleCalls = [
    1.35 +    {
    1.36 +      level: "log",
    1.37 +      filename: /test_consoleapi/,
    1.38 +      functionName: "doConsoleCalls",
    1.39 +      timeStamp: /^\d+$/,
    1.40 +      arguments: ["foobarBaz-log", { type: "undefined" }],
    1.41 +    },
    1.42 +    {
    1.43 +      level: "info",
    1.44 +      filename: /test_consoleapi/,
    1.45 +      functionName: "doConsoleCalls",
    1.46 +      timeStamp: /^\d+$/,
    1.47 +      arguments: ["foobarBaz-info", { type: "null" }],
    1.48 +    },
    1.49 +    {
    1.50 +      level: "warn",
    1.51 +      filename: /test_consoleapi/,
    1.52 +      functionName: "doConsoleCalls",
    1.53 +      timeStamp: /^\d+$/,
    1.54 +      arguments: ["foobarBaz-warn", { type: "object", actor: /[a-z]/ }],
    1.55 +    },
    1.56 +    {
    1.57 +      level: "debug",
    1.58 +      filename: /test_consoleapi/,
    1.59 +      functionName: "doConsoleCalls",
    1.60 +      timeStamp: /^\d+$/,
    1.61 +      arguments: [{ type: "null" }],
    1.62 +    },
    1.63 +    {
    1.64 +      level: "trace",
    1.65 +      filename: /test_consoleapi/,
    1.66 +      functionName: "doConsoleCalls",
    1.67 +      timeStamp: /^\d+$/,
    1.68 +      stacktrace: [
    1.69 +        {
    1.70 +          filename: /test_consoleapi/,
    1.71 +          functionName: "doConsoleCalls",
    1.72 +        },
    1.73 +        {
    1.74 +          filename: /test_consoleapi/,
    1.75 +          functionName: "onAttach",
    1.76 +        },
    1.77 +      ],
    1.78 +    },
    1.79 +    {
    1.80 +      level: "dir",
    1.81 +      filename: /test_consoleapi/,
    1.82 +      functionName: "doConsoleCalls",
    1.83 +      timeStamp: /^\d+$/,
    1.84 +      arguments: [
    1.85 +        {
    1.86 +          type: "object",
    1.87 +          actor: /[a-z]/,
    1.88 +          class: "XULDocument",
    1.89 +        },
    1.90 +        {
    1.91 +          type: "object",
    1.92 +          actor: /[a-z]/,
    1.93 +          class: "Location",
    1.94 +        }
    1.95 +      ],
    1.96 +    },
    1.97 +    {
    1.98 +      level: "log",
    1.99 +      filename: /test_consoleapi/,
   1.100 +      functionName: "doConsoleCalls",
   1.101 +      timeStamp: /^\d+$/,
   1.102 +      arguments: [
   1.103 +        "foo",
   1.104 +        {
   1.105 +          type: "longString",
   1.106 +          initial: longString.substring(0,
   1.107 +            DebuggerServer.LONG_STRING_INITIAL_LENGTH),
   1.108 +          length: longString.length,
   1.109 +          actor: /[a-z]/,
   1.110 +        },
   1.111 +      ],
   1.112 +    },
   1.113 +  ];
   1.114 +}
   1.115 +
   1.116 +function startTest()
   1.117 +{
   1.118 +  removeEventListener("load", startTest);
   1.119 +
   1.120 +  attachConsole(["ConsoleAPI"], onAttach, true);
   1.121 +}
   1.122 +
   1.123 +function onAttach(aState, aResponse)
   1.124 +{
   1.125 +  onConsoleAPICall = onConsoleAPICall.bind(null, aState);
   1.126 +  aState.dbgClient.addListener("consoleAPICall", onConsoleAPICall);
   1.127 +  doConsoleCalls(aState.actor);
   1.128 +}
   1.129 +
   1.130 +let consoleCalls = [];
   1.131 +
   1.132 +function onConsoleAPICall(aState, aType, aPacket)
   1.133 +{
   1.134 +  info("received message level: " + aPacket.message.level);
   1.135 +  is(aPacket.from, aState.actor, "console API call actor");
   1.136 +
   1.137 +  consoleCalls.push(aPacket.message);
   1.138 +  if (consoleCalls.length != expectedConsoleCalls.length) {
   1.139 +    return;
   1.140 +  }
   1.141 +
   1.142 +  aState.dbgClient.removeListener("consoleAPICall", onConsoleAPICall);
   1.143 +
   1.144 +  expectedConsoleCalls.forEach(function(aMessage, aIndex) {
   1.145 +    info("checking received console call #" + aIndex);
   1.146 +    checkConsoleAPICall(consoleCalls[aIndex], expectedConsoleCalls[aIndex]);
   1.147 +  });
   1.148 +
   1.149 +
   1.150 +  consoleCalls = [];
   1.151 +
   1.152 +  closeDebugger(aState, function() {
   1.153 +    SimpleTest.finish();
   1.154 +  });
   1.155 +}
   1.156 +
   1.157 +addEventListener("load", startTest);
   1.158 +</script>
   1.159 +</body>
   1.160 +</html>

mercurial