Bug 802013 - Intermittent test_cached_messages.html | number of cached page errors - got 6, expected 2; r=robcee
authorMihai Sucan <mihai.sucan@gmail.com>
Tue, 23 Oct 2012 18:37:01 +0300
changeset 111484 3b363ef96fadbaeec6806d239a10a2fbe3afc900
parent 111483 9f2ef525135b589df9d6e43af5f3352c17a007f3
child 111485 6bc7e598cad0ac0c5d7acf8dbde60c26a8f12274
push id93
push usernmatsakis@mozilla.com
push dateWed, 31 Oct 2012 21:26:57 +0000
reviewersrobcee
bugs802013
milestone19.0a1
Bug 802013 - Intermittent test_cached_messages.html | number of cached page errors - got 6, expected 2; r=robcee
toolkit/devtools/webconsole/test/test_cached_messages.html
--- a/toolkit/devtools/webconsole/test/test_cached_messages.html
+++ b/toolkit/devtools/webconsole/test/test_cached_messages.html
@@ -10,17 +10,18 @@
 </head>
 <body>
 <p>Test for cached messages</p>
 
 <script class="testbody" type="application/javascript;version=1.8">
 let expectedConsoleCalls = [];
 let expectedPageErrors = [];
 
-(function() {
+function doPageErrors()
+{
   Services.console.reset();
 
   expectedPageErrors = [
     {
       _type: "PageError",
       errorMessage: /fooColor/,
       sourceName: /.+/,
       category: "CSS Parser",
@@ -48,17 +49,17 @@ let expectedPageErrors = [];
   body.appendChild(container);
   container.textContent = "document.documentElement.style.color = 'fooColor';";
   body.removeChild(container);
 
   container = top.document.createElementNS(XHTML_NS, "script");
   body.appendChild(container);
   container.textContent = "document.doTheImpossible();";
   body.removeChild(container);
-})();
+}
 
 function doConsoleCalls()
 {
   top.console.log("foobarBaz-log", undefined);
   top.console.info("foobarBaz-info", null);
   top.console.warn("foobarBaz-warn", document.body);
 
   expectedConsoleCalls = [
@@ -88,28 +89,36 @@ function doConsoleCalls()
     },
   ];
 }
 </script>
 
 <script class="testbody" type="text/javascript;version=1.8">
 SimpleTest.waitForExplicitFinish();
 
-let consoleAPIListener;
-
+let consoleAPIListener, pageErrorListener;
 let consoleAPICalls = 0;
+let pageErrors = 0;
 
 let handlers = {
   onConsoleAPICall: function onConsoleAPICall()
   {
     consoleAPICalls++;
     if (consoleAPICalls == expectedConsoleCalls.length) {
       checkConsoleAPICache();
     }
   },
+
+  onPageError: function onPageError()
+  {
+    pageErrors++;
+    if (pageErrors == expectedPageErrors.length) {
+      testPageErrors();
+    }
+  },
 };
 
 function startTest()
 {
   removeEventListener("load", startTest);
 
   consoleAPIListener = new ConsoleAPIListener(top, handlers);
   consoleAPIListener.init();
@@ -137,21 +146,27 @@ function onCachedConsoleAPI(aState, aRes
   is(msgs.length, expectedConsoleCalls.length,
      "number of cached console messages");
 
   expectedConsoleCalls.forEach(function(aMessage, aIndex) {
     info("checking received cached message #" + aIndex);
     checkConsoleAPICall(msgs[aIndex], expectedConsoleCalls[aIndex]);
   });
 
-  closeDebugger(aState, testPageErrors);
+  closeDebugger(aState, function() {
+    pageErrorListener = new PageErrorListener(null, handlers);
+    pageErrorListener.init();
+    doPageErrors();
+  });
 }
 
 function testPageErrors()
 {
+  pageErrorListener.destroy();
+  pageErrorListener = null;
   attachConsole(["PageError"], onAttach2);
 }
 
 function onAttach2(aState, aResponse)
 {
   aState.client.getCachedMessages(["PageError"],
                                   onCachedPageErrors.bind(null, aState));
 }