Bug 650244: adjust template console tests to avoid failing when other things happen to spam the console; r=ehsan
authorGavin Sharp <gavin@gavinsharp.com>
Thu, 26 May 2011 13:22:27 -0400
changeset 70242 d998c37534b13857ed0f59dc44a5cb03398db136
parent 70241 2280f0d23ce22f2e3741f058e377e5aefa456eda
child 70243 483a694ee31d0d329e5cfe4cc9be77b9cf68c723
push idunknown
push userunknown
push dateunknown
reviewersehsan
bugs650244
milestone7.0a1
Bug 650244: adjust template console tests to avoid failing when other things happen to spam the console; r=ehsan
content/xul/templates/tests/chrome/templates_shared.js
--- a/content/xul/templates/tests/chrome/templates_shared.js
+++ b/content/xul/templates/tests/chrome/templates_shared.js
@@ -427,25 +427,31 @@ function expectConsoleMessage(ref, id, i
                 (ref ? " using ref " + ref : "") + "\n    " +
                 (isNew ? "New " : "Removed ") + (isActive ? "active" : "inactive") +
                 " result for query " + extra + ": " + id;
   expectedConsoleMessages.push(message);
 }
 
 function compareConsoleMessages()
 {
-   var consoleService = Components.classes["@mozilla.org/consoleservice;1"].
-                          getService(Components.interfaces.nsIConsoleService);
-   var out = {};
-   consoleService.getMessageArray(out, {});
-   var messages = out.value || [];
-   is(messages.length, expectedConsoleMessages.length, "correct number of logged messages");
-   for (var m = 0; m < messages.length; m++) {
-     is(messages[m].message, expectedConsoleMessages.shift(), "logged message " + (m + 1));
-   }
+  var consoleService = Components.classes["@mozilla.org/consoleservice;1"].
+                         getService(Components.interfaces.nsIConsoleService);
+  var out = {};
+  consoleService.getMessageArray(out, {});
+  var messages = (out.value || []).map(function (m) m.message);
+  // Copy to avoid modifying expectedConsoleMessages
+  var expect = expectedConsoleMessages.concat();
+  for (var m = 0; m < messages.length; m++) {
+    if (messages[m] == expect[0]) {
+      ok(true, "found message " + expect.shift());
+    }
+  }
+  if (expect.length != 0) {
+    ok(false, "failed to find expected console messages: " + expect);
+  }
 }
 
 function copyToProfile(filename)
 {
   if (Cc === undefined) {
     var Cc = Components.classes;
     var Ci = Components.interfaces;
   }