Bug 1146349 - Update DOM mochitests to deal with async native event synthesization. r=smaug
authorKartikaya Gupta <kgupta@mozilla.com>
Tue, 14 Apr 2015 11:36:36 -0400
changeset 239019 45168f9387c7ce77027a199c3bfb773f6984e017
parent 239018 0490493b12e8b58e66b899034f6e5c11b3f50ac1
child 239020 024cf684488b67fd129f15e5a82a0e51304735be
push id58403
push userkgupta@mozilla.com
push dateTue, 14 Apr 2015 15:37:00 +0000
treeherdermozilla-inbound@371a7026a1df [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssmaug
bugs1146349
milestone40.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 1146349 - Update DOM mochitests to deal with async native event synthesization. r=smaug
dom/plugins/test/mochitest/cocoa_focus.html
--- a/dom/plugins/test/mochitest/cocoa_focus.html
+++ b/dom/plugins/test/mochitest/cocoa_focus.html
@@ -9,17 +9,29 @@
     function is(aLeft, aRight, aMessage) {
       window.opener.SimpleTest.is(aLeft, aRight, aMessage);
     }
 
     function ok(aValue, aMessage) {
       window.opener.SimpleTest.ok(aValue, aMessage);
     }
 
-    function runTests() {
+    function synthesizeNativeMouseEvent(aX, aY, aNativeMsg, aModifiers, aElement, aCallback) {
+      var observer = {
+        observe: function(aSubject, aTopic, aData) {
+          if (aCallback && aTopic == "mouseevent") {
+            aCallback(aData);
+          }
+        }
+      };
+      SpecialPowers.DOMWindowUtils.sendNativeMouseEvent(aX, aY, aNativeMsg, aModifiers, aElement, observer);
+      return true;
+    }
+
+    function* runTests() {
       var utils = SpecialPowers.DOMWindowUtils;
       var scale = utils.screenPixelsPerCSSPixel;
 
       var plugin1 = document.getElementById("plugin1"); // What we're testing.
       var plugin2 = document.getElementById("plugin2"); // Dummy.
 
       var plugin1Bounds = plugin1.getBoundingClientRect();
       var plugin2Bounds = plugin2.getBoundingClientRect();
@@ -29,17 +41,16 @@
       var plugin2X = (window.mozInnerScreenX + plugin2Bounds.left + 10);
       var plugin2Y = (window.mozInnerScreenY + plugin2Bounds.top + 10);
 
       const NSLeftMouseDown          = 1,
             NSLeftMouseUp            = 2;
 
       if (plugin1.getEventModel() != 1) {
         window.opener.todo(false, "Skipping this test when not testing the Cocoa event model");
-        window.opener.testsFinished();
         return;
       }
 
       // Initialize to 0 since there is no initial state event,
       // plugins should assume they do not initially have focus.
       var expectedEventCount = 0;
 
       // Make sure initial event count is correct.
@@ -50,18 +61,18 @@
       try {
         plugin1.getFocusState();
       } catch (e) {
         initialStateUnknown = true;
       }
       is(initialStateUnknown, true, "Initial state should be unknown, assumed false.");
 
       // Give the plugin focus (the window is already focused).
-      utils.sendNativeMouseEvent(plugin1X * scale, plugin1Y * scale, NSLeftMouseDown, 0, plugin1);
-      utils.sendNativeMouseEvent(plugin1X * scale, plugin1Y * scale, NSLeftMouseUp, 0, plugin1);
+      yield synthesizeNativeMouseEvent(plugin1X * scale, plugin1Y * scale, NSLeftMouseDown, 0, plugin1, continueTest);
+      yield synthesizeNativeMouseEvent(plugin1X * scale, plugin1Y * scale, NSLeftMouseUp, 0, plugin1, continueTest);
       expectedEventCount++;
 
       is(plugin1.getFocusState(), true, "(1) Plugin should have focus.");
       is(plugin1.getFocusEventCount(), expectedEventCount, "Focus event count should be " + expectedEventCount);
 
       // Make sure window activation state changes don't spontaneously
       // change plugin focus.
 
@@ -73,29 +84,29 @@
 
       // Focus the window.
       SpecialPowers.focus(window);
 
       is(plugin1.getFocusState(), true, "(3) Plugin should still have focus.");
       is(plugin1.getFocusEventCount(), expectedEventCount, "Focus event count should be " + expectedEventCount);
 
       // Take focus from the plugin.
-      utils.sendNativeMouseEvent(plugin2X * scale, plugin2Y * scale, NSLeftMouseDown, 0, plugin2);
-      utils.sendNativeMouseEvent(plugin2X * scale, plugin2Y * scale, NSLeftMouseUp, 0, plugin2);
+      yield synthesizeNativeMouseEvent(plugin2X * scale, plugin2Y * scale, NSLeftMouseDown, 0, plugin2, continueTest);
+      yield synthesizeNativeMouseEvent(plugin2X * scale, plugin2Y * scale, NSLeftMouseUp, 0, plugin2, continueTest);
       expectedEventCount++;
 
       is(plugin1.getFocusState(), false, "(4) Plugin should not have focus.");
       is(plugin1.getFocusEventCount(), expectedEventCount, "Focus event count should be " + expectedEventCount);
 
       // Make sure window activation causes the plugin to be informed of focus
       // changes that took place while the window was inactive.
 
       // Give the plugin focus (the window is already focused).
-      utils.sendNativeMouseEvent(plugin1X * scale, plugin1Y * scale, NSLeftMouseDown, 0, plugin1);
-      utils.sendNativeMouseEvent(plugin1X * scale, plugin1Y * scale, NSLeftMouseUp, 0, plugin1);
+      yield synthesizeNativeMouseEvent(plugin1X * scale, plugin1Y * scale, NSLeftMouseDown, 0, plugin1, continueTest);
+      yield synthesizeNativeMouseEvent(plugin1X * scale, plugin1Y * scale, NSLeftMouseUp, 0, plugin1, continueTest);
       expectedEventCount++;
 
       // Blur the window.
       SpecialPowers.focus(opener);
 
       // Take focus from the plugin while the window is blurred.
       plugin2.focus();
 
@@ -103,18 +114,29 @@
       is(plugin1.getFocusEventCount(), expectedEventCount, "Focus event count should be " + expectedEventCount);
 
       // Focus the window.
       SpecialPowers.focus(window);
       expectedEventCount++;
 
       is(plugin1.getFocusState(), false, "(6) Plugin should not have focus.");
       is(plugin1.getFocusEventCount(), expectedEventCount, "Focus event count should be " + expectedEventCount);
+    }
 
-      window.opener.testsFinished();
+    var gTestContinuation = null;
+    function continueTest() {
+      if (!gTestContinuation) {
+        gTestContinuation = runTests();
+      }
+      var ret = gTestContinuation.next();
+      if (ret.done) {
+        window.opener.testsFinished();
+      } else {
+        is(ret.value, true, "Mouse event successfully synthesized");
+      }
     }
 
     // Onload hander doesn't work for these tests -- no events arrive at the plugin.
-    window.opener.SimpleTest.waitForFocus(runTests, window);
+    window.opener.SimpleTest.waitForFocus(continueTest, window);
 
   </script>
 </body>
 </html>