Bug 1257288 - Improve the APZ gtest infrastructure to make writing multi-FrameMetrics tests easier. r=kats draft
authorBotond Ballo <botond@mozilla.com>
Wed, 20 Apr 2016 18:37:45 -0400
changeset 354444 8b5a5fca7f26c78b53280647a88de285a2208fd8
parent 354443 a2e336bf5b80b94e90ed3d9c9b0f12f1c85cd86f
child 354445 f435fa574a52bdf90690c1ede739f248d2f0d99f
push id16081
push userbballo@mozilla.com
push dateWed, 20 Apr 2016 22:37:55 +0000
reviewerskats
bugs1257288
milestone48.0a1
Bug 1257288 - Improve the APZ gtest infrastructure to make writing multi-FrameMetrics tests easier. r=kats MozReview-Commit-ID: L9QN0FhLwRU
gfx/layers/apz/test/gtest/APZCTreeManagerTester.h
--- a/gfx/layers/apz/test/gtest/APZCTreeManagerTester.h
+++ b/gfx/layers/apz/test/gtest/APZCTreeManagerTester.h
@@ -52,56 +52,80 @@ protected:
 
   nsTArray<RefPtr<Layer> > layers;
   RefPtr<LayerManager> lm;
   RefPtr<Layer> root;
 
   RefPtr<TestAPZCTreeManager> manager;
 
 protected:
-  static void SetScrollableFrameMetrics(Layer* aLayer, FrameMetrics::ViewID aScrollId,
-                                        CSSRect aScrollableRect = CSSRect(-1, -1, -1, -1)) {
+  static ScrollMetadata BuildScrollMetadata(FrameMetrics::ViewID aScrollId,
+                                            const CSSRect& aScrollableRect,
+                                            const ParentLayerRect& aCompositionBounds)
+  {
     ScrollMetadata metadata;
     FrameMetrics& metrics = metadata.GetMetrics();
     metrics.SetScrollId(aScrollId);
     // By convention in this test file, START_SCROLL_ID is the root, so mark it as such.
     if (aScrollId == FrameMetrics::START_SCROLL_ID) {
       metrics.SetIsLayersIdRoot(true);
     }
-    IntRect layerBound = aLayer->GetVisibleRegion().ToUnknownRegion().GetBounds();
-    metrics.SetCompositionBounds(ParentLayerRect(layerBound.x, layerBound.y,
-                                                 layerBound.width, layerBound.height));
+    metrics.SetCompositionBounds(aCompositionBounds);
     metrics.SetScrollableRect(aScrollableRect);
     metrics.SetScrollOffset(CSSPoint(0, 0));
     metrics.SetPageScrollAmount(LayoutDeviceIntSize(50, 100));
     metrics.SetAllowVerticalScrollWithWheel(true);
-    aLayer->SetScrollMetadata(metadata);
-    aLayer->SetClipRect(Some(ViewAs<ParentLayerPixel>(layerBound)));
-    if (!aScrollableRect.IsEqualEdges(CSSRect(-1, -1, -1, -1))) {
+    return metadata;
+  }
+
+  static void SetEventRegionsBasedOnBottommostMetrics(Layer* aLayer)
+  {
+    const FrameMetrics& metrics = aLayer->GetScrollMetadata(0).GetMetrics();
+    CSSRect scrollableRect = metrics.GetScrollableRect();
+    if (!scrollableRect.IsEqualEdges(CSSRect(-1, -1, -1, -1))) {
       // The purpose of this is to roughly mimic what layout would do in the
       // case of a scrollable frame with the event regions and clip. This lets
       // us exercise the hit-testing code in APZCTreeManager
       EventRegions er = aLayer->GetEventRegions();
-      IntRect scrollRect = RoundedToInt(aScrollableRect * metrics.LayersPixelsPerCSSPixel()).ToUnknownRect();
-      er.mHitRegion = nsIntRegion(IntRect(layerBound.TopLeft(), scrollRect.Size()));
+      IntRect scrollRect = RoundedToInt(
+          scrollableRect * metrics.LayersPixelsPerCSSPixel()).ToUnknownRect();
+      er.mHitRegion = nsIntRegion(IntRect(
+          RoundedToInt(metrics.GetCompositionBounds().TopLeft().ToUnknownPoint()),
+          scrollRect.Size()));
       aLayer->SetEventRegions(er);
     }
   }
 
+  static void SetScrollableFrameMetrics(Layer* aLayer, FrameMetrics::ViewID aScrollId,
+                                        CSSRect aScrollableRect = CSSRect(-1, -1, -1, -1)) {
+    ParentLayerIntRect compositionBounds = ViewAs<ParentLayerPixel>(
+        aLayer->GetVisibleRegion().ToUnknownRegion().GetBounds());
+    ScrollMetadata metadata = BuildScrollMetadata(aScrollId, aScrollableRect,
+        ParentLayerRect(compositionBounds));
+    aLayer->SetScrollMetadata(metadata);
+    aLayer->SetClipRect(Some(compositionBounds));
+    SetEventRegionsBasedOnBottommostMetrics(aLayer);
+  }
+
   void SetScrollHandoff(Layer* aChild, Layer* aParent) {
     ScrollMetadata metadata = aChild->GetScrollMetadata(0);
     metadata.GetMetrics().SetScrollParentId(aParent->GetFrameMetrics(0).GetScrollId());
     aChild->SetScrollMetadata(metadata);
   }
 
   static TestAsyncPanZoomController* ApzcOf(Layer* aLayer) {
     EXPECT_EQ(1u, aLayer->GetScrollMetadataCount());
     return (TestAsyncPanZoomController*)aLayer->GetAsyncPanZoomController(0);
   }
 
+  static TestAsyncPanZoomController* ApzcOf(Layer* aLayer, uint32_t aIndex) {
+    EXPECT_LT(aIndex, aLayer->GetScrollMetadataCount());
+    return (TestAsyncPanZoomController*)aLayer->GetAsyncPanZoomController(aIndex);
+  }
+
   void CreateSimpleScrollingLayer() {
     const char* layerTreeSyntax = "t";
     nsIntRegion layerVisibleRegion[] = {
       nsIntRegion(IntRect(0,0,200,200)),
     };
     root = CreateLayerTree(layerTreeSyntax, layerVisibleRegion, nullptr, lm, layers);
     SetScrollableFrameMetrics(root, FrameMetrics::START_SCROLL_ID, CSSRect(0, 0, 500, 500));
   }