toolkit/devtools/webconsole/test/test_page_errors.html
author Phil Ringnalda <philringnalda@gmail.com>
Sat, 13 Sep 2014 09:59:06 -0700
changeset 205205 d070787de8f7b56e32bf5800b30f143c4d02d474
parent 109672 246011521d45d57dc457bc8331cafaf44eeaa2dd
child 234502 4a81d45f61991925e01dda62c6ac0cefbcd9fb6d
permissions -rw-r--r--
Merge b-i to m-c

<!DOCTYPE HTML>
<html lang="en">
<head>
  <meta charset="utf8">
  <title>Test for page errors</title>
  <script type="text/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
  <script type="text/javascript;version=1.8" src="common.js"></script>
  <!-- Any copyright is dedicated to the Public Domain.
     - http://creativecommons.org/publicdomain/zero/1.0/ -->
</head>
<body>
<p>Test for page errors</p>

<script class="testbody" type="text/javascript;version=1.8">
SimpleTest.waitForExplicitFinish();

let expectedPageErrors = [];

function doPageErrors()
{
  expectedPageErrors = [
    {
      errorMessage: /fooColor/,
      sourceName: /test_page_errors/,
      category: "CSS Parser",
      timeStamp: /^\d+$/,
      error: false,
      warning: true,
      exception: false,
      strict: false,
    },
    {
      errorMessage: /doTheImpossible/,
      sourceName: /test_page_errors/,
      category: "chrome javascript",
      timeStamp: /^\d+$/,
      error: false,
      warning: false,
      exception: true,
      strict: false,
    },
  ];

  let container = document.createElement("script");
  document.body.appendChild(container);
  container.textContent = "document.body.style.color = 'fooColor';";
  document.body.removeChild(container);

  SimpleTest.expectUncaughtException();

  container = document.createElement("script");
  document.body.appendChild(container);
  container.textContent = "document.doTheImpossible();";
  document.body.removeChild(container);
}

function startTest()
{
  removeEventListener("load", startTest);

  attachConsole(["PageError"], onAttach);
}

function onAttach(aState, aResponse)
{
  onPageError = onPageError.bind(null, aState);
  aState.dbgClient.addListener("pageError", onPageError);
  doPageErrors();
}

let pageErrors = [];

function onPageError(aState, aType, aPacket)
{
  is(aPacket.from, aState.actor, "page error actor");

  pageErrors.push(aPacket.pageError);
  if (pageErrors.length != expectedPageErrors.length) {
    return;
  }

  aState.dbgClient.removeListener("pageError", onPageError);

  expectedPageErrors.forEach(function(aMessage, aIndex) {
    info("checking received page error #" + aIndex);
    checkObject(pageErrors[aIndex], expectedPageErrors[aIndex]);
  });

  closeDebugger(aState, function() {
    SimpleTest.finish();
  });
}

addEventListener("load", startTest);
</script>
</body>
</html>