Bug 873727 - Use a listener instead of timers to fix intermittent failures. r=roc
authorJosiahOne <josiah@programmer.net>
Wed, 19 Jun 2013 13:20:38 -0400
changeset 147235 77e0dd13bb1e14ef9020f672f0b0ae22b0960ca1
parent 147234 82161c9015ab152766a1995ad7f66214fa8ed08a
child 147236 c1596bee956c700875d972f4d20bb462603cfb76
push id2697
push userbbajaj@mozilla.com
push dateMon, 05 Aug 2013 18:49:53 +0000
treeherdermozilla-beta@dfec938c7b63 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersroc
bugs873727
milestone24.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 873727 - Use a listener instead of timers to fix intermittent failures. r=roc
toolkit/content/tests/chrome/test_showcaret.xul
--- a/toolkit/content/tests/chrome/test_showcaret.xul
+++ b/toolkit/content/tests/chrome/test_showcaret.xul
@@ -25,16 +25,31 @@ function frameLoaded() { if (++framesLoa
 SimpleTest.waitForExplicitFinish();
 function runTest()
 {
   var sel1 = frames[0].getSelection();
   sel1.collapse(frames[0].document.body, 0);
 
   var sel2 = frames[1].getSelection();
   sel2.collapse(frames[1].document.body, 0);
+  window.frames[0].focus();
+  document.commandDispatcher.getControllerForCommand("cmd_moveBottom").doCommand("cmd_moveBottom");
+
+  var listener = function() {
+    if (!(frames[0].scrollY > 0)) {
+      window.content.removeEventListener("scroll", listener, false);
+    }
+  }
+  window.frames[0].addEventListener("scroll", listener, false);
+
+  var sel1 = frames[0].getSelection();
+  sel1.collapse(frames[0].document.body, 0);
+
+  var sel2 = frames[1].getSelection();
+  sel2.collapse(frames[1].document.body, 0);
 
   window.frames[0].focus();
   document.commandDispatcher.getControllerForCommand("cmd_moveBottom").doCommand("cmd_moveBottom");
   is(sel1.focusNode, frames[0].document.body, "focusNode for non-showcaret");
   is(sel1.focusOffset, 0, "focusOffset for non-showcaret");
 
   window.frames[1].focus();
   document.commandDispatcher.getControllerForCommand("cmd_moveBottom").doCommand("cmd_moveBottom");
@@ -42,32 +57,16 @@ function runTest()
   ok(frames[1].scrollY <
        frames[1].document.getElementById('s').getBoundingClientRect().top,
      "scrollY for showcaret");
   isnot(sel2.focusNode, frames[1].document.body, "focusNode for showcaret");
   ok(sel2.anchorOffset > 0, "focusOffset for showcaret");
 
   otherWindow = window.open("window_showcaret.xul", "_blank", "chrome,width=400,height=200");
   otherWindow.addEventListener("focus", otherWindowFocused, false);
-
-  var sel1 = frames[0].getSelection();
-  sel1.collapse(frames[0].document.body, 0);
-
-  var sel2 = frames[1].getSelection();
-  sel2.collapse(frames[1].document.body, 0);
-  window.frames[0].focus();
-  document.commandDispatcher.getControllerForCommand("cmd_moveBottom").doCommand("cmd_moveBottom");
-
-  /* We aren't sure exactly how long the cmd_moveBottom will take.
-   * Therefore, check for success every second. If we don't have success within 10 seconds, assume the scroll
-   * will never pass the test and fail it.
-   */
-
-  var timeoutUntilFail = window.setTimeout(scrollYTimeout, 10000);
-  var testScroll = self.setInterval(function(){continueTest()}, 10);
 }
 
 function otherWindowFocused()
 {
   otherWindow.removeEventListener("focus", otherWindowFocused, false);
 
   // enable caret browsing temporarily to test caret movement
   var prefs = Components.classes["@mozilla.org/preferences-service;1"].
@@ -82,29 +81,16 @@ function otherWindowFocused()
   is(otherWindow.document.activeElement, hbox, "hbox still focused in other window after down movement");
 
   prefs.setBoolPref("accessibility.browsewithcaret", false);
 
   otherWindow.close();
   SimpleTest.finish();
 }
 
-function continueTest() {
-  if (frames[0].scrollY > 0) {
-    return;
-  }
-  testScroll = window.clearInterval(testScroll);
-  window.clearTimeout(timeoutUntilFail);
-  return;
-}
-
-function scrollYTimeout() {
-  ok(frames[0].scrollY > 0, "scrollY for non-showcaret");
-}
-
 ]]>
 </script>
 
 <body xmlns="http://www.w3.org/1999/xhtml">
 <p id="display">
 </p>
 <div id="content" style="display: none">
 </div>