Bug 877953 - Fix for intermittent test_cached_messages.html | number of cached page errors - got n, expected 2; r=me
authorMihai Sucan <mihai.sucan@gmail.com>
Tue, 04 Jun 2013 22:12:11 +0300
changeset 134235 151ae3dcc6b05c27256ccb6ef1d10b2586db5cac
parent 134234 5e07d25dbd876254c66341b119d911587e896043
child 134236 15738f337df2acbcff66f87b7dad74c59ae1ba81
push id29108
push usermihai.sucan@gmail.com
push dateThu, 06 Jun 2013 12:11:12 +0000
treeherdermozilla-inbound@151ae3dcc6b0 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersme
bugs877953
milestone24.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 877953 - Fix for intermittent test_cached_messages.html | number of cached page errors - got n, expected 2; r=me
toolkit/devtools/webconsole/test/common.js
toolkit/devtools/webconsole/test/test_cached_messages.html
toolkit/devtools/webconsole/test/test_nsiconsolemessage.html
--- a/toolkit/devtools/webconsole/test/common.js
+++ b/toolkit/devtools/webconsole/test/common.js
@@ -3,16 +3,17 @@
 
 "use strict";
 
 const {classes: Cc, interfaces: Ci, utils: Cu} = Components;
 
 const XHTML_NS = "http://www.w3.org/1999/xhtml";
 
 Cu.import("resource://gre/modules/Services.jsm");
+Cu.import("resource://gre/modules/ConsoleAPIStorage.jsm");
 Cu.import("resource://gre/modules/devtools/WebConsoleUtils.jsm");
 
 function initCommon()
 {
   //Services.prefs.setBoolPref("devtools.debugger.log", true);
 
   Cu.import("resource://gre/modules/devtools/dbg-server.jsm");
   Cu.import("resource://gre/modules/devtools/dbg-client.jsm");
--- a/toolkit/devtools/webconsole/test/test_cached_messages.html
+++ b/toolkit/devtools/webconsole/test/test_cached_messages.html
@@ -54,16 +54,18 @@ function doPageErrors()
   container = document.createElement("script");
   document.body.appendChild(container);
   container.textContent = "document.doTheImpossible();";
   document.body.removeChild(container);
 }
 
 function doConsoleCalls()
 {
+  ConsoleAPIStorage.clearEvents();
+
   top.console.log("foobarBaz-log", undefined);
   top.console.info("foobarBaz-info", null);
   top.console.warn("foobarBaz-warn", document.body);
 
   expectedConsoleCalls = [
     {
       _type: "ConsoleAPI",
       level: "log",
@@ -95,27 +97,42 @@ function doConsoleCalls()
 <script class="testbody" type="text/javascript;version=1.8">
 SimpleTest.waitForExplicitFinish();
 
 let consoleAPIListener, consoleServiceListener;
 let consoleAPICalls = 0;
 let pageErrors = 0;
 
 let handlers = {
-  onConsoleAPICall: function onConsoleAPICall()
+  onConsoleAPICall: function onConsoleAPICall(aMessage)
   {
-    consoleAPICalls++;
+    for (let msg of expectedConsoleCalls) {
+      if (msg.functionName == aMessage.functionName &&
+          msg.filename.test(aMessage.filename)) {
+        consoleAPICalls++;
+        break;
+      }
+    }
     if (consoleAPICalls == expectedConsoleCalls.length) {
       checkConsoleAPICache();
     }
   },
 
-  onConsoleServiceMessage: function onConsoleServiceMessage()
+  onConsoleServiceMessage: function onConsoleServiceMessage(aMessage)
   {
-    pageErrors++;
+    if (!(aMessage instanceof Ci.nsIScriptError)) {
+      return;
+    }
+    for (let msg of expectedPageErrors) {
+      if (msg.category == aMessage.category &&
+          msg.errorMessage.test(aMessage.errorMessage)) {
+        pageErrors++;
+        break;
+      }
+    }
     if (pageErrors == expectedPageErrors.length) {
       testPageErrors();
     }
   },
 };
 
 function startTest()
 {
@@ -138,24 +155,33 @@ function onAttach1(aState, aResponse)
 {
   aState.client.getCachedMessages(["ConsoleAPI"],
                                   onCachedConsoleAPI.bind(null, aState));
 }
 
 function onCachedConsoleAPI(aState, aResponse)
 {
   let msgs = aResponse.messages;
+  info("cached console messages: " + msgs.length);
 
-  is(msgs.length, expectedConsoleCalls.length,
+  ok(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]);
-  });
+  for (let msg of msgs) {
+    for (let expected of expectedConsoleCalls) {
+      if (expected.functionName == msg.functionName &&
+          expected.filename.test(msg.filename)) {
+        expectedConsoleCalls.splice(expectedConsoleCalls.indexOf(expected));
+        checkConsoleAPICall(msg, expected);
+        break;
+      }
+    }
+  }
+
+  is(expectedConsoleCalls.length, 0, "all expected messages have been found");
 
   closeDebugger(aState, function() {
     consoleServiceListener = new ConsoleServiceListener(null, handlers);
     consoleServiceListener.init();
     doPageErrors();
   });
 }
 
@@ -170,24 +196,33 @@ function onAttach2(aState, aResponse)
 {
   aState.client.getCachedMessages(["PageError"],
                                   onCachedPageErrors.bind(null, aState));
 }
 
 function onCachedPageErrors(aState, aResponse)
 {
   let msgs = aResponse.messages;
+  info("cached page errors: " + msgs.length);
 
-  is(msgs.length, expectedPageErrors.length,
+  ok(msgs.length >= expectedPageErrors.length,
      "number of cached page errors");
 
-  expectedPageErrors.forEach(function(aMessage, aIndex) {
-    info("checking received cached message #" + aIndex);
-    checkObject(msgs[aIndex], expectedPageErrors[aIndex]);
-  });
+  for (let msg of msgs) {
+    for (let expected of expectedPageErrors) {
+      if (expected.category == msg.category &&
+          expected.errorMessage.test(msg.errorMessage)) {
+        expectedPageErrors.splice(expectedPageErrors.indexOf(expected));
+        checkObject(msg, expected);
+        break;
+      }
+    }
+  }
+
+  is(expectedPageErrors.length, 0, "all expected messages have been found");
 
   closeDebugger(aState, function() {
     SimpleTest.finish();
   });
 }
 
 addEventListener("load", startTest);
 </script>
--- a/toolkit/devtools/webconsole/test/test_nsiconsolemessage.html
+++ b/toolkit/devtools/webconsole/test/test_nsiconsolemessage.html
@@ -38,16 +38,28 @@ function onAttach(aState, aResponse)
   info("waiting for messages");
 }
 
 let receivedMessages = [];
 
 function onLogMessage(aState, aType, aPacket)
 {
   is(aPacket.from, aState.actor, "packet actor");
+  info("received message: " + aPacket.message);
+
+  let found = false;
+  for (let expected of expectedMessages) {
+    if (expected.message == aPacket.message) {
+      found = true;
+      break;
+    }
+  }
+  if (!found) {
+    return;
+  }
 
   receivedMessages.push(aPacket);
   if (receivedMessages.length != expectedMessages.length) {
     return;
   }
 
   aState.dbgClient.removeListener("logMessage", onLogMessage);