Bug 1032878 - Fix for various failing mochitest-plain/-chrome tests. r=jmaher, r=akachkach, r=surkov, r=cpearce
☠☠ backed out by 8db38d415e20 ☠ ☠
authorMartijn Wargers <mwargers@mozilla.com>
Sun, 10 Aug 2014 20:03:50 -0700
changeset 213292 f54984be223e92e93298fd09cd802c72a9a775b2
parent 213291 abe747ee0aca6ae8fff459e28abb951084738ccf
child 213293 991f8d5da382b1710952675f8a5793e588982d1d
push idunknown
push userunknown
push dateunknown
reviewersjmaher, akachkach, surkov, cpearce
bugs1032878
milestone34.0a1
Bug 1032878 - Fix for various failing mochitest-plain/-chrome tests. r=jmaher, r=akachkach, r=surkov, r=cpearce
accessible/tests/mochitest/attributes/test_obj_group.html
accessible/tests/mochitest/events.js
browser/base/content/test/general/test_offline_gzip.html
content/base/test/csp/test_CSP_bug888172.html
content/media/test/test_autoplay_contentEditable.html
dom/base/test/test_domcursor.html
dom/browser-element/mochitest/browserElement_KeyEvents.js
dom/browser-element/mochitest/browserElement_TopBarrier.js
dom/inputmethod/mochitest/test_bug960946.html
dom/tests/mochitest/chrome/test_docshell_swap.xul
dom/workers/test/test_bug883784.jsm
layout/base/tests/test_bug607529.html
--- a/accessible/tests/mochitest/attributes/test_obj_group.html
+++ b/accessible/tests/mochitest/attributes/test_obj_group.html
@@ -188,19 +188,19 @@
 
       // Test that group position information updates after deleting node.
       testGroupAttrs("tree4_ti1", 1, 2, 1);
       testGroupAttrs("tree4_ti2", 2, 2, 1);
       var tree4element = document.getElementById("tree4_ti1");
       var tree4acc = getAccessible("tree4");
       tree4element.parentNode.removeChild(tree4element);
       waitForEvent(EVENT_REORDER, tree4acc, function() {
-        testGroupAttrs("tree4_ti2", 1, 1, 1); });
-
-      SimpleTest.finish();
+        testGroupAttrs("tree4_ti2", 1, 1, 1);
+        SimpleTest.finish();
+      });
     }
 
     SimpleTest.waitForExplicitFinish();
     addA11yLoadEvent(doTest);
   </script>
 </head>
 <body>
 
--- a/accessible/tests/mochitest/events.js
+++ b/accessible/tests/mochitest/events.js
@@ -384,17 +384,17 @@ function eventQueue(aEventType)
     this.clearEventHandler();
 
     // Check if need to stop the test.
     if (testFailed || this.mIndex == this.mInvokers.length - 1) {
       listenA11yEvents(false);
 
       var res = this.onFinish();
       if (res != DO_NOT_FINISH_TEST)
-        SimpleTest.finish();
+        SimpleTest.executeSoon(SimpleTest.finish);
 
       return;
     }
 
     // Start processing of next invoker.
     invoker = this.getNextInvoker();
 
     // Set up event listeners. Process a next invoker if no events were added.
--- a/browser/base/content/test/general/test_offline_gzip.html
+++ b/browser/base/content/test/general/test_offline_gzip.html
@@ -84,16 +84,17 @@ function handleMessageEvents(event) {
           if (cacheCount != 2) {
             finishTest();
           }
         }
       }, 100);
       break;
     case 2:    
       is(event.data, "onupdate", "Child was successfully updated.");
+      clearInterval(intervalID);
       finishTest();
       break;
     default:
       // how'd we get here?
       ok(false, "cacheCount not 1 or 2");
   }
 }
 
--- a/content/base/test/csp/test_CSP_bug888172.html
+++ b/content/base/test/csp/test_CSP_bug888172.html
@@ -30,44 +30,44 @@ function getElementColorById(doc, id) {
 
 // We test both script and style execution by observing changes in computed styles
 function checkDefaultSrcOnly() {
   var testframe = document.getElementById('testframe1');
 
   ok(getElementColorById(testframe, 'unsafe-inline-script') === green, "Inline script should be allowed");
   ok(getElementColorById(testframe, 'unsafe-eval-script')  === green, "Eval should be allowed");
   ok(getElementColorById(testframe, 'unsafe-inline-style') === green, "Inline style should be allowed");
+
+  document.getElementById('testframe2').src = 'file_CSP_bug888172.sjs?csp=' +
+    escape("default-src 'self' 'unsafe-inline' 'unsafe-eval'; script-src 'self'");
+  document.getElementById('testframe2').addEventListener('load', checkDefaultSrcWithScriptSrc, false);
 }
 
 function checkDefaultSrcWithScriptSrc() {
   var testframe = document.getElementById('testframe2');
 
   ok(getElementColorById(testframe, 'unsafe-inline-script') === black, "Inline script should be blocked");
   ok(getElementColorById(testframe, 'unsafe-eval-script')  === black, "Eval should be blocked");
   ok(getElementColorById(testframe, 'unsafe-inline-style') === green, "Inline style should be allowed");
+
+  document.getElementById('testframe3').src = 'file_CSP_bug888172.sjs?csp=' +
+    escape("default-src 'self' 'unsafe-inline' 'unsafe-eval'; style-src 'self'");
+  document.getElementById('testframe3').addEventListener('load', checkDefaultSrcWithStyleSrc, false);
 }
 
 function checkDefaultSrcWithStyleSrc() {
   var testframe = document.getElementById('testframe3');
 
   ok(getElementColorById(testframe, 'unsafe-inline-script') === green, "Inline script should be allowed");
   ok(getElementColorById(testframe, 'unsafe-eval-script')  === green, "Eval should be allowed");
   ok(getElementColorById(testframe, 'unsafe-inline-style') === black, "Inline style should be blocked");
 
   // last test calls finish
   SimpleTest.finish();
 }
 
 document.getElementById('testframe1').src = 'file_CSP_bug888172.sjs?csp=' +
   escape("default-src 'self' 'unsafe-inline' 'unsafe-eval'");
 document.getElementById('testframe1').addEventListener('load', checkDefaultSrcOnly, false);
-
-document.getElementById('testframe2').src = 'file_CSP_bug888172.sjs?csp=' +
-  escape("default-src 'self' 'unsafe-inline' 'unsafe-eval'; script-src 'self'");
-document.getElementById('testframe2').addEventListener('load', checkDefaultSrcWithScriptSrc, false);
-
-document.getElementById('testframe3').src = 'file_CSP_bug888172.sjs?csp=' +
-  escape("default-src 'self' 'unsafe-inline' 'unsafe-eval'; style-src 'self'");
-document.getElementById('testframe3').addEventListener('load', checkDefaultSrcWithStyleSrc, false);
 </script>
 </pre>
 </body>
 </html>
--- a/content/media/test/test_autoplay_contentEditable.html
+++ b/content/media/test/test_autoplay_contentEditable.html
@@ -23,16 +23,22 @@ function gotPlayEvent(event) {
   var v = event.target;
   ok(tokens[v._state].indexOf(event.type) >= 0,
      "Check expected event got " + event.type + " at " + v._state + " for " + v.src +
      " uneval(event.type)=" + uneval(event.type) + " typeof(event.type)=" + typeof(event.type) +
      " uneval(v._state)=" + uneval(v._state) + " typeof(v._state)=" + typeof(v._state) + 
      " tokens["+v._state+"]=" + tokens[v._state] +
      " tokens["+v._state+"].indexOf(event.type)=" + tokens[v._state].indexOf(event.type));
   v._state = event.type;
+  if (event.type == 'canplaythrough') {
+    //canplaythrough event can fire multiple times on Windows
+    v.removeEventListener('canplaythrough', gotPlayEvent, false);
+    v.pause();
+    goToNext(v);
+  }
 }
 
 function goToNext(v) {
   v.parentNode.removeChild(v);
   manager.finished(v.token);
 }
 
 function initTest(test, token) {
@@ -41,18 +47,16 @@ function initTest(test, token) {
   v.token = token;
   manager.started(token);
   v._state = 0;
  
   ["play", "canplay", "playing", "canplaythrough", "ended"].forEach(function (e) {
     v.addEventListener(e, gotPlayEvent, false);
   });
 
-  setTimeout(function() goToNext(v), 500);
-
   v.src = test.name;
   v.autoplay = true;
   document.body.appendChild(v); // Causes load.
 }
 
 manager.runTests(gSmallTests, initTest);
 
 </script>
--- a/dom/base/test/test_domcursor.html
+++ b/dom/base/test/test_domcursor.html
@@ -80,22 +80,16 @@ var tests = [
       is(e.target, req, "correct target during continue");
       is(req.readyState, "done", "correct readyState after continue");
       is(req.error, null, "correct error after continue");
       is(req.result, "next result", "correct result after continue");
       is(req.done, false, "cursor is not done after continue")
       next();
     }
     req.continue();
-    try {
-      req.continue();
-      ok(false, "calling continue twice should fail");
-    } catch (e) {
-      ok(true, "calling continue twice should fail");
-    }
   },
   function() {
     // FireDone
     req.onsuccess = function(e) {
       ok(e, "got success event after continue");
       is(e.type, "success", "correct type during continue");
       is(e.target, req, "correct target during continue");
       is(req.readyState, "done", "correct readyState after continue");
--- a/dom/browser-element/mochitest/browserElement_KeyEvents.js
+++ b/dom/browser-element/mochitest/browserElement_KeyEvents.js
@@ -77,16 +77,21 @@ function eventHandler(e) {
   nbEvents--;
 
   // Prevent default for F5 because on desktop that reloads the page.
   if (e.keyCode === Ci.nsIDOMKeyEvent.DOM_VK_F5) {
     e.preventDefault();
   }
 
   if (nbEvents == 0) {
+    //removeEventListener, otherwise a key event is fired
+    //for some reason, with keyCode 95
+    removeEventListener('keydown', eventHandler);
+    removeEventListener('keypress', eventHandler);
+    removeEventListener('keyup', eventHandler);
     SimpleTest.finish();
     return;
   }
 
   if (nbEvents < 0 && !finished) {
     ok(false, "got an unexpected event! " + e.type + " " + e.keyCode);
   }
 }
--- a/dom/browser-element/mochitest/browserElement_TopBarrier.js
+++ b/dom/browser-element/mochitest/browserElement_TopBarrier.js
@@ -23,16 +23,18 @@ function runTest() {
   // For kicks, this test uses a display:none iframe.  This shouldn't make a
   // difference in anything.
   iframe.style.display = 'none';
   document.body.appendChild(iframe);
 }
 
 var numMsgReceived = 0;
 function outerIframeLoaded() {
+  // If you're changing the amount of is() calls in injectedScript,
+  // also change the number in waitForMessages accordingly
   var injectedScript =
     "data:,function is(a, b, desc) {                                     \
       if (a == b) {                                                      \
         sendAsyncMessage('test:test-pass', desc);                        \
       } else {                                                           \
         sendAsyncMessage('test:test-fail', desc + ' ' + a + ' != ' + b); \
       }                                                                  \
     }                                                                    \
@@ -58,17 +60,18 @@ function outerIframeLoaded() {
   function onRecvTestFail(msg) {
     numMsgReceived++;
     ok(false, msg.json);
   }
   mm.addMessageListener('test:test-fail', onRecvTestFail);
 
   mm.loadFrameScript(injectedScript, /* allowDelayedLoad = */ false);
 
-  waitForMessages(6);
+  // 8 is the number of is() calls in injectedScript
+  waitForMessages(8);
 }
 
 function waitForMessages(num) {
   if (numMsgReceived < num) {
     SimpleTest.executeSoon(function() { waitForMessages(num); });
     return;
   }
 
--- a/dom/inputmethod/mochitest/test_bug960946.html
+++ b/dom/inputmethod/mochitest/test_bug960946.html
@@ -13,29 +13,31 @@ https://bugzilla.mozilla.org/show_bug.cg
 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=960946">Mozilla Bug 960946</a>
 <p id="display"></p>
 <pre id="test">
 <script class="testbody" type="application/javascript;version=1.7">
 
 // The input context.
 var gContext = null;
 var gCounter = 0;
+var gBackSpaceCounter = 0;
 var result = ["keydown", "keypress", "keydown","keypress",
               "keydown", "keypress", "keyup"
              ];
 
 inputmethod_setup(function() {
   runTest();
 });
 
+var input;
 // The frame script running in file_test_backspace_event.html.
 function appFrameScript() {
   let input = content.document.getElementById('test-input');
   input.onkeydown = input.onkeypress = input.onkeyup = function(event) {
-    dump('key event was fired in file_test_backspace_event.html.\n');
+    dump('key event was fired in file_test_backspace_event.html: ' + event.type +'\n');
     sendAsyncMessage('test:KeyBoard:keyEvent', {'type':event.type});
   };
 }
 
 function runTest() {
   let im = navigator.mozInputMethod;
 
   im.oninputcontextchange = function() {
@@ -62,19 +64,16 @@ function runTest() {
   document.body.appendChild(app);
   app.addEventListener('mozbrowserloadend', function() {
     let mm = SpecialPowers.getBrowserFrameMessageManager(app);
     mm.loadFrameScript('data:,(' + appFrameScript.toString() + ')();', false);
     mm.addMessageListener("test:KeyBoard:keyEvent", function(event) {
       ok(true, 'Keyboard input was received.');
       is(SpecialPowers.wrap(event).json.type, result[gCounter], "expected event");
       gCounter++;
-      if (gCounter == 7) {
-        inputmethod_cleanup();
-      }
     });
   });
 }
 
 function test_sendKey() {
   // Move cursor position to 4.
   gContext.setSelectionRange(4, 0).then(function() {
     is(gContext.selectionStart, 4, 'selectionStart was set successfully.');
@@ -88,16 +87,20 @@ function test_sendKey() {
     inputmethod_cleanup();
   });
 }
 
 function test_sendBackspace(repeat) {
   // Send backspace
   gContext.sendKey(KeyEvent.DOM_VK_BACK_SPACE, 0, 0, repeat).then(function() {
     ok(true, 'sendKey success');
+    gBackSpaceCounter++;
+    if (gBackSpaceCounter == 3) {
+      inputmethod_cleanup();
+    }
   }, function(e) {
     ok(false, 'sendKey failed:' + e.name);
     inputmethod_cleanup();
   });
 }
 </script>
 </pre>
 </body>
--- a/dom/tests/mochitest/chrome/test_docshell_swap.xul
+++ b/dom/tests/mochitest/chrome/test_docshell_swap.xul
@@ -41,18 +41,16 @@
         win1.close();
         win2.close();
         SimpleTest.finish();
       }
     }
 
     let mm1 = flo1.frameLoader.messageManager;
     let mm2 = flo2.frameLoader.messageManager;
-    mm1.addMessageListener("pong", () => { gotPong(true); });
-    mm2.addMessageListener("pong", () => { gotPong(false); });
 
     // Swap docshells. Everything should be identical to before, since there was nothing to
     // distinguish these docshells.
     flo1.swapFrameLoaders(flo2);
 
     // mm1 shouldn't change here, but we update it in case it does due to a bug.
     mm1 = flo1.frameLoader.messageManager;
 
--- a/dom/workers/test/test_bug883784.jsm
+++ b/dom/workers/test/test_bug883784.jsm
@@ -1,28 +1,30 @@
 this.EXPORTED_SYMBOLS = ["Test"];
 
 this.Test = {
   start: function(ok, is, finish) {
     let worker = new ChromeWorker("jsm_url_worker.js");
     worker.onmessage = function(event) {
-
-      if (event.data.type == 'finish') {
-        finish();
-      } else if (event.data.type == 'status') {
+      if (event.data.type == 'status') {
         ok(event.data.status, event.data.msg);
       } else if (event.data.type == 'url') {
         var xhr = Components.classes["@mozilla.org/xmlextras/xmlhttprequest;1"]
                   .createInstance(Components.interfaces.nsIXMLHttpRequest);
         xhr.open('GET', event.data.url, false);
         xhr.onreadystatechange = function() {
           if (xhr.readyState == 4) {
             ok(true, "Blob readable!");
+            finish();
           }
         }
+        xhr.onerror = function() {
+          ok(true, "Blob unreadable, should not happen!");
+          finish();
+        }
         xhr.send();
       }
     };
 
     var self = this;
     worker.onerror = function(event) {
       is(event.target, worker);
       ok(false, "Worker had an error: " + event.data);
--- a/layout/base/tests/test_bug607529.html
+++ b/layout/base/tests/test_bug607529.html
@@ -40,16 +40,17 @@ https://bugzilla.mozilla.org/show_bug.cg
       w.postMessage("report", "*");
     }
     else if (e.data == "callbackHappened") {
       // We might get this message more than once, if the other page queues up
       // more than one callbackHappened message before we manage to close it.
       // Protect against calling SimpleTest.finish() more than once.
       if (!done) {
 	w.close();
+        window.onmessage = null;
 	SimpleTest.finish();
 	done = true;
       }
     } else {
       var msg = JSON.parse(e.data);
       if (msg.error) {
         window.onerror(msg.msg, msg.url, msg.line);
       }