Bug 1247519 - Trigger mouse click twice in case the first click is overlooked. r=smaug, a=test-only
authorTooru Fujisawa <arai_a@mac.com>
Wed, 15 Mar 2017 00:27:26 +0900
changeset 379067 8eefcde96334ddb87f76ce97cb21d18b7096f017
parent 379066 dee74fdbfbeedcd56517b90366c7b48e5abe6697
child 379068 7c80fd53c63940df375009ae109807cd88b0c021
push id1419
push userjlund@mozilla.com
push dateMon, 10 Apr 2017 20:44:07 +0000
treeherdermozilla-release@5e6801b73ef6 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssmaug, test-only
bugs1247519
milestone53.0
Bug 1247519 - Trigger mouse click twice in case the first click is overlooked. r=smaug, a=test-only
dom/tests/mochitest/chrome/test_bug1224790-1.xul
dom/tests/mochitest/chrome/test_bug1224790-2.xul
--- a/dom/tests/mochitest/chrome/test_bug1224790-1.xul
+++ b/dom/tests/mochitest/chrome/test_bug1224790-1.xul
@@ -25,26 +25,39 @@ https://bugzilla.mozilla.org/show_bug.cg
   function startTest() {
     window.openDialog('file_bug1224790-1_modal.xul', '', 'modal');
   }
 
   function modalClosed() {
     SimpleTest.waitForFocus(gotFocus);
   }
 
+  var timer = null;
   function gotFocus() {
     var button = document.getElementById('button');
     synthesizeMouseAtCenter(button, { type: 'mousemove' }, window);
-    // The bug is not reproducible with synthesizeMouseAtCenter.
-    // Need to emulate native mouse event.
-    synthesizeNativeOSXClick(button.boxObject.screenX + button.boxObject.width / 2,
-                             button.boxObject.screenY + button.boxObject.height / 2);
+    function click() {
+      // The bug is not reproducible with synthesizeMouseAtCenter.
+      // Need to emulate native mouse event.
+      synthesizeNativeOSXClick(button.boxObject.screenX + button.boxObject.width / 2,
+                               button.boxObject.screenY + button.boxObject.height / 2);
+    }
+    click();
+    // On debug build, it's possible that the click event handler is not
+    // triggered by the first click in case the click is dispatched too early
+    // before Firefox gets ready for input.
+    // Click the button again after 1 sec when we don't get click event.
+    timer = setTimeout(click, 1000);
   }
 
   function onClick() {
+    if (timer) {
+      // Avoid clicking unrelated thing.
+      clearTimeout(timer);
+    }
     ok(true, "Click event should be fired");
     SimpleTest.finish();
   }
 
   SimpleTest.waitForExplicitFinish();
   SimpleTest.waitForFocus(startTest);
   ]]>
   </script>
--- a/dom/tests/mochitest/chrome/test_bug1224790-2.xul
+++ b/dom/tests/mochitest/chrome/test_bug1224790-2.xul
@@ -26,26 +26,39 @@ https://bugzilla.mozilla.org/show_bug.cg
   function startTest() {
     window.openDialog('file_bug1224790-2_modal.xul', '', 'modal');
   }
 
   function nonModalClosed() {
     SimpleTest.waitForFocus(gotFocus);
   }
 
+  var timer = null;
   function gotFocus() {
     var button = document.getElementById('button');
     synthesizeMouseAtCenter(button, { type: 'mousemove' }, window);
-    // The bug is not reproducible with synthesizeMouseAtCenter.
-    // Need to emulate native mouse event.
-    synthesizeNativeOSXClick(button.boxObject.screenX + button.boxObject.width / 2,
-                             button.boxObject.screenY + button.boxObject.height / 2);
+    function click() {
+      // The bug is not reproducible with synthesizeMouseAtCenter.
+      // Need to emulate native mouse event.
+      synthesizeNativeOSXClick(button.boxObject.screenX + button.boxObject.width / 2,
+                               button.boxObject.screenY + button.boxObject.height / 2);
+    }
+    click();
+    // On debug build, it's possible that the click event handler is not
+    // triggered by the first click in case the click is dispatched too early
+    // before Firefox gets ready for input.
+    // Click the button again after 1 sec when we don't get click event.
+    timer = setTimeout(click, 1000);
   }
 
   function onClick() {
+    if (timer) {
+      // Avoid clicking unrelated thing.
+      clearTimeout(timer);
+    }
     ok(true, "Click event should be fired");
     SimpleTest.finish();
   }
 
   SimpleTest.waitForExplicitFinish();
   SimpleTest.waitForFocus(startTest);
   ]]>
   </script>