dom/src/threads/test/test_threadErrors.html
author Serge Gautherie <sgautherie.bz@free.fr>
Sat, 21 Mar 2009 00:38:52 +0100
changeset 26437 ecb3f8997a38979a44faa24de5471d56827cf0b0
parent 21376 9f77a26afd904f4349f40df51eda194e31b50b6b
child 28048 8f7b73d88f6bbedec99c6c8ef48b243ab922d05c
permissions -rw-r--r--
Bug 483633 - Mochitest test_threadErrors.html runs fine but needs to check/report success; (Av1) Add |ok(true, ...);|; r+sr=jst

<!DOCTYPE HTML>
<html>
<!--
Tests of DOM Worker Threads (Bug 437152)
-->
<head>
  <title>Test for DOM Worker Threads (Bug 437152)</title>
  <script type="text/javascript" src="/MochiKit/MochiKit.js"></script>
  <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
</head>
<body>
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=437152">DOM Worker Threads Bug 437152</a>
<p id="display"></p>
<div id="content" style="display: none">
  
</div>
<pre id="test">
<script class="testbody" type="text/javascript">

  const expectedErrorCount = 4;

  function messageListener(event) {
    ok(false, "Unexpected message: " + event.data);
    SimpleTest.finish();
  };

  var actualErrorCount = 0;
  var failedWorkers = [];

  function errorListener(event) {
    if (failedWorkers.indexOf(event.target) != -1) {
      ok(false, "Seen an extra error from this worker");
      SimpleTest.finish();
      return;
    }

    failedWorkers.push(event.target);
    actualErrorCount++;

    if (actualErrorCount == expectedErrorCount) {
      ok(true, "all errors correctly detected");
      SimpleTest.finish();
    }
  };

  for (var i = 1; i <= expectedErrorCount; i++) {
    var worker = new Worker("threadErrors_worker" + i + ".js");
    worker.onmessage = messageListener;
    worker.onerror = errorListener;
    worker.postMessage("Hi");
  }

  SimpleTest.waitForExplicitFinish();

</script>
</pre>
</body>
</html>