Bug 868432 - Alter tests to be aware of delayed changes in scrolling. r=roc, a=lsblakk
authorJosiahOne <josiah@programmer.net>
Wed, 08 May 2013 22:25:09 -0400
changeset 142710 72fbaf2bef120c9310efedd43f22c3d81725965f
parent 142709 8f706537a36015e3807de470da3f592753781a91
child 142711 401338d98748d419bdfdb9d186bb6bcf3d8c773e
push id2579
push userakeybl@mozilla.com
push dateMon, 24 Jun 2013 18:52:47 +0000
treeherdermozilla-beta@b69b7de8a05a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersroc, lsblakk
bugs868432
milestone23.0a2
Bug 868432 - Alter tests to be aware of delayed changes in scrolling. r=roc, a=lsblakk
editor/libeditor/base/tests/test_selection_move_commands.xul
toolkit/content/tests/chrome/test_showcaret.xul
--- a/editor/libeditor/base/tests/test_selection_move_commands.xul
+++ b/editor/libeditor/base/tests/test_selection_move_commands.xul
@@ -118,18 +118,20 @@ function execTests() {
     while (i > 0) {
       n = n.nextSibling;
       --i;
     }
     return n;
   }
 
   doCommand("cmd_scrollBottom");
+  yield;
   testScrollCommand("cmd_scrollBottom", root.scrollHeight - 100);
   doCommand("cmd_scrollTop");
+  yield;
   testScrollCommand("cmd_scrollTop", 0);
 
   doCommand("cmd_scrollPageDown");
   yield;
   var pageHeight = -root.getBoundingClientRect().top;
   ok(pageHeight > 0, "cmd_scrollPageDown works");
   ok(pageHeight <= 100, "cmd_scrollPageDown doesn't scroll too much");
   doCommand("cmd_scrollBottom");
--- a/toolkit/content/tests/chrome/test_showcaret.xul
+++ b/toolkit/content/tests/chrome/test_showcaret.xul
@@ -28,32 +28,46 @@ 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");
-
-  ok(frames[0].scrollY > 0, "scrollY for non-showcaret");
   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");
 
   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"].
@@ -68,16 +82,29 @@ 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>