Bug 1447131 - Move centerOf() into apz_test_utils.js. r=kats draft
authorBotond Ballo <botond@mozilla.com>
Wed, 28 Mar 2018 14:22:42 -0400
changeset 773959 ad39696f8573e2e5119720c7495ce1b21cf62f82
parent 773958 be2e6a1e3fc651cb26bf90b77077ca0a5de8d80a
child 773960 074ba63d6c4d9a69393cce691988697def556818
push id104359
push userbballo@mozilla.com
push dateWed, 28 Mar 2018 18:25:07 +0000
reviewerskats
bugs1447131
milestone61.0a1
Bug 1447131 - Move centerOf() into apz_test_utils.js. r=kats MozReview-Commit-ID: CwO5SnWmhb9
gfx/layers/apz/test/mochitest/apz_test_utils.js
gfx/layers/apz/test/mochitest/helper_hittest_basic.html
gfx/layers/apz/test/mochitest/helper_hittest_checkerboard.html
--- a/gfx/layers/apz/test/mochitest/apz_test_utils.js
+++ b/gfx/layers/apz/test/mochitest/apz_test_utils.js
@@ -517,16 +517,22 @@ function getHitTestConfig() {
     var utils = SpecialPowers.getDOMWindowUtils(window);
     var isWebRender = (utils.layerManagerType == 'WebRender');
     var isWindows = (getPlatform() == 'windows');
     window.hitTestConfig = { utils, isWebRender, isWindows };
   }
   return window.hitTestConfig;
 }
 
+// Compute the coordinates of the center of the given element.
+function centerOf(element) {
+  var bounds = element.getBoundingClientRect();
+  return { x: bounds.x + (bounds.width / 2), y: bounds.y + (bounds.height / 2) };
+}
+
 // Peform a compositor hit test at the given point and return the result.
 // The returned object has two fields:
 //   hitInfo: a combination of APZHitResultFlags
 //   scrollId: the view-id of the scroll frame that was hit
 function hitTest(point) {
   var utils = getHitTestConfig().utils;
   dump("Hit-testing point (" + point.x + ", " + point.y + ")\n");
   utils.sendMouseEvent("MozMouseHittest", point.x, point.y, 0, 0, 0, true, 0, 0, true, true);
--- a/gfx/layers/apz/test/mochitest/helper_hittest_basic.html
+++ b/gfx/layers/apz/test/mochitest/helper_hittest_basic.html
@@ -12,21 +12,16 @@
   <div id="contents" style="width: 500px; height: 500px; background-image: linear-gradient(blue,red)">
    <div id="apzaware" style="position: relative; width: 100px; height: 100px; top: 300px; background-color: red" onwheel="return false;"></div>
   </div>
  </div>
  <div id="make_root_scrollable" style="height: 5000px"></div>
 </body>
 <script type="application/javascript">
 
-function centerOf(element) {
-  var bounds = element.getBoundingClientRect();
-  return { x: bounds.x + (bounds.width / 2), y: bounds.y + (bounds.height / 2) };
-}
-
 function* test(testDriver) {
   var config = getHitTestConfig();
   var utils = config.utils;
 
   var scroller = document.getElementById('scroller');
   var apzaware = document.getElementById('apzaware');
 
   var {hitInfo, scrollId} = hitTest(centerOf(scroller));
--- a/gfx/layers/apz/test/mochitest/helper_hittest_checkerboard.html
+++ b/gfx/layers/apz/test/mochitest/helper_hittest_checkerboard.html
@@ -12,21 +12,16 @@
   <!-- Make the contents tall enough to be sure we can checkerboard -->
   <div id="contents" style="width: 100%; height: 5000px; background-image: linear-gradient(blue,red)">
   </div>
  </div>
  <div id="make_root_scrollable" style="height: 5000px"></div>
 </body>
 <script type="application/javascript">
 
-function centerOf(element) {
-  var bounds = element.getBoundingClientRect();
-  return { x: bounds.x + (bounds.width / 2), y: bounds.y + (bounds.height / 2) };
-}
-
 function* test(testDriver) {
   var config = getHitTestConfig();
   var utils = config.utils;
 
   var scroller = document.getElementById('scroller');
 
   // Activate the scrollframe but keep the main-thread scroll position at 0.
   // Also apply an async scroll offset in the y-direction such that the