Bug 1106720 - Intermittent test_bug1096146.html | verify result - got 3, expected 1. r=smaug, a=test-only
authorGina Yeh <gyeh@mozilla.com>
Mon, 15 Dec 2014 18:18:55 +0800
changeset 242457 0a8761cd24cff24312155badc8f16b8c0f4ed7fc
parent 242456 63f7bbd24da3d620d9c0d076e01826a64aa7d268
child 242458 68f54ed7e2ac12446e7c03a7daaad61d347ebd0b
push id4311
push userraliiev@mozilla.com
push dateMon, 12 Jan 2015 19:37:41 +0000
treeherdermozilla-beta@150c9fed433b [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssmaug, test-only
bugs1106720, 1096146
milestone36.0a2
Bug 1106720 - Intermittent test_bug1096146.html | verify result - got 3, expected 1. r=smaug, a=test-only
dom/events/test/test_bug1096146.html
--- a/dom/events/test/test_bug1096146.html
+++ b/dom/events/test/test_bug1096146.html
@@ -17,16 +17,17 @@ https://bugzilla.mozilla.org/show_bug.cg
 </div>
 <pre id="test">
 <script type="application/javascript">
 
 const kKeydownEvent = 0x1;
 const kScrollEvent  = 0x2;
 
 var gCurrentTest = 0;
+var gNumEvents = 0;
 var kTests = [
   {
     description: "no preventDefault at 'mozbrowserbeforekeydown'",
     expectedEvents: kKeydownEvent | kScrollEvent,
     resultEvents: 0x0,
     doPreventDefault: false
   },
   {
@@ -41,29 +42,39 @@ function frameScript()
 {
   function handler(e) {
     sendSyncMessage("forwardevent", { type: e.type });
   }
   addEventListener('keydown', handler);
   addEventListener('scroll', handler);
 }
 
+
+function waitAndVerifyResult(count) {
+  if (gNumEvents >= 3 || count > 10) {
+    is(kTests[gCurrentTest].resultEvents,
+       kTests[gCurrentTest].expectedEvents,
+       "verify result");
+    runTests();
+	} else {
+    // We must delay to wait for scroll/keydown events
+    setTimeout(function () waitAndVerifyResult(count + 1), 100);
+  }
+}
+
 function testDefaultAction()
 {
   synthesizeKey('VK_END', {}, document.getElementById("embedded").contentWindow);
-  setTimeout(function () {
-    is(kTests[gCurrentTest].expectedEvents,
-       kTests[gCurrentTest].resultEvents,
-       "verify result");
-    runTests();
-  }, 500);
+  waitAndVerifyResult(0);
 }
 
 function prepareTest()
 {
+  gNumEvents = 0;
+
   var handler;
   if (kTests[gCurrentTest].doPreventDefault) {
     handler = preventDefaultHandler;
   } else {
     handler = noPreventDefaultHandler;
   }
   window.addEventListener("mozbrowserbeforekeydown", handler);
 
@@ -76,19 +87,21 @@ function prepareTest()
   iframe.addEventListener("mozbrowserloadend", function onloadend() {
     iframe.removeEventListener("mozbrowserloadend", onloadend);
     iframe.focus();
     var mm = SpecialPowers.getBrowserFrameMessageManager(iframe);
     mm.addMessageListener("forwardevent", function(msg) {
       var value = 0;
       switch(msg.json.type) {
         case "scroll":
+          ++gNumEvents;
           value = kScrollEvent;
           break;
         case "keydown":
+          ++gNumEvents;
           value = kKeydownEvent;
           break;
         default:
           ok(false, "unexpected event");
       }
 
       kTests[gCurrentTest].resultEvents =
         kTests[gCurrentTest].resultEvents | value;
@@ -99,33 +112,36 @@ function prepareTest()
   });
 
   document.body.appendChild(iframe);
 }
 
 function preventDefaultHandler(evt)
 {
   ok(true, "receive " + evt.type + " and do preventDefault.");
+	++gNumEvents;
   evt.preventDefault();
 }
 
 function noPreventDefaultHandler(evt)
 {
   ok(true, "receive " + evt.type + ".");
+	++gNumEvents;
 }
 
 function teardownHandler()
 {
   var handler;
   if (kTests[gCurrentTest].doPreventDefault) {
     handler = preventDefaultHandler;
   } else {
     handler = noPreventDefaultHandler;
   }
   window.removeEventListener("mozbrowserbeforekeydown", handler);
+  document.body.removeChild(document.getElementById("embedded"));
 
   runTests();
 }
 
 var tests = [
   function addPermissions() {
     SpecialPowers.pushPermissions(
       [{ type: "before-after-keyboard-event", allow: true, context: document },