Bug 1055760 - Add some basic gtests for LayerMetricsWrapper tree-walking. r=BenWa
authorKartikaya Gupta <kgupta@mozilla.com>
Wed, 27 Aug 2014 22:13:43 -0400
changeset 223679 4a7c80b9ae9c6ccdf1c84a6ce2605b7c47da910e
parent 223678 4a1907885d78b92db60e116d3804448c927fb333
child 223680 27180d85fe5b315839247e522b280bcc40c5e5ce
push id3979
push userraliiev@mozilla.com
push dateMon, 13 Oct 2014 16:35:44 +0000
treeherdermozilla-beta@30f2cc610691 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersBenWa
bugs1055760
milestone34.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 1055760 - Add some basic gtests for LayerMetricsWrapper tree-walking. r=BenWa
gfx/tests/gtest/TestLayers.cpp
--- a/gfx/tests/gtest/TestLayers.cpp
+++ b/gfx/tests/gtest/TestLayers.cpp
@@ -1,16 +1,17 @@
 /* vim:set ts=2 sw=2 sts=2 et: */
 /* Any copyright is dedicated to the Public Domain.
  * http://creativecommons.org/publicdomain/zero/1.0/
  */
 
 #include "TestLayers.h"
 #include "gtest/gtest.h"
 #include "gmock/gmock.h"
+#include "mozilla/layers/LayerMetricsWrapper.h"
 
 using namespace mozilla;
 using namespace mozilla::gfx;
 using namespace mozilla::layers;
 
 class TestLayerManager: public LayerManager {
 public:
   TestLayerManager()
@@ -317,8 +318,135 @@ TEST(Layers, RepositionChild) {
   ValidateTreePointers(layers);
 
   //   0
   // 3 2 1
   ASSERT_EQ(layers[2], layers[3]->GetNextSibling());
   ASSERT_EQ(layers[1], layers[2]->GetNextSibling());
   ASSERT_EQ(nullptr, layers[1]->GetNextSibling());
 }
+
+TEST(LayerMetricsWrapper, SimpleTree) {
+  nsTArray<nsRefPtr<Layer> > layers;
+  nsRefPtr<LayerManager> lm;
+  nsRefPtr<Layer> root = CreateLayerTree("c(c(c(tt)c(t)))", nullptr, nullptr, lm, layers);
+  LayerMetricsWrapper wrapper(root);
+
+  ASSERT_EQ(root.get(), wrapper.GetLayer());
+  wrapper = wrapper.GetFirstChild();
+  ASSERT_EQ(layers[1].get(), wrapper.GetLayer());
+  ASSERT_FALSE(wrapper.GetNextSibling().IsValid());
+  wrapper = wrapper.GetFirstChild();
+  ASSERT_EQ(layers[2].get(), wrapper.GetLayer());
+  wrapper = wrapper.GetFirstChild();
+  ASSERT_EQ(layers[3].get(), wrapper.GetLayer());
+  ASSERT_FALSE(wrapper.GetFirstChild().IsValid());
+  wrapper = wrapper.GetNextSibling();
+  ASSERT_EQ(layers[4].get(), wrapper.GetLayer());
+  ASSERT_FALSE(wrapper.GetNextSibling().IsValid());
+  wrapper = wrapper.GetParent();
+  ASSERT_EQ(layers[2].get(), wrapper.GetLayer());
+  wrapper = wrapper.GetNextSibling();
+  ASSERT_EQ(layers[5].get(), wrapper.GetLayer());
+  ASSERT_FALSE(wrapper.GetNextSibling().IsValid());
+  wrapper = wrapper.GetLastChild();
+  ASSERT_EQ(layers[6].get(), wrapper.GetLayer());
+  wrapper = wrapper.GetParent();
+  ASSERT_EQ(layers[5].get(), wrapper.GetLayer());
+  LayerMetricsWrapper layer5 = wrapper;
+  wrapper = wrapper.GetPrevSibling();
+  ASSERT_EQ(layers[2].get(), wrapper.GetLayer());
+  wrapper = wrapper.GetParent();
+  ASSERT_EQ(layers[1].get(), wrapper.GetLayer());
+  ASSERT_TRUE(layer5 == wrapper.GetLastChild());
+  LayerMetricsWrapper rootWrapper(root);
+  ASSERT_TRUE(rootWrapper == wrapper.GetParent());
+}
+
+static FrameMetrics
+MakeMetrics(FrameMetrics::ViewID aId) {
+  FrameMetrics metrics;
+  metrics.SetScrollId(aId);
+  return metrics;
+}
+
+TEST(LayerMetricsWrapper, MultiFramemetricsTree) {
+  nsTArray<nsRefPtr<Layer> > layers;
+  nsRefPtr<LayerManager> lm;
+  nsRefPtr<Layer> root = CreateLayerTree("c(c(c(tt)c(t)))", nullptr, nullptr, lm, layers);
+
+  nsTArray<FrameMetrics> metrics;
+  metrics.InsertElementAt(0, MakeMetrics(FrameMetrics::START_SCROLL_ID + 0)); // topmost of root layer
+  metrics.InsertElementAt(0, MakeMetrics(FrameMetrics::NULL_SCROLL_ID));
+  metrics.InsertElementAt(0, MakeMetrics(FrameMetrics::START_SCROLL_ID + 1));
+  metrics.InsertElementAt(0, MakeMetrics(FrameMetrics::START_SCROLL_ID + 2));
+  metrics.InsertElementAt(0, MakeMetrics(FrameMetrics::NULL_SCROLL_ID));
+  metrics.InsertElementAt(0, MakeMetrics(FrameMetrics::NULL_SCROLL_ID));      // bottom of root layer
+  root->SetFrameMetrics(metrics);
+
+  metrics.Clear();
+  metrics.InsertElementAt(0, MakeMetrics(FrameMetrics::START_SCROLL_ID + 3));
+  layers[1]->SetFrameMetrics(metrics);
+
+  metrics.Clear();
+  metrics.InsertElementAt(0, MakeMetrics(FrameMetrics::NULL_SCROLL_ID));
+  metrics.InsertElementAt(0, MakeMetrics(FrameMetrics::START_SCROLL_ID + 4));
+  layers[2]->SetFrameMetrics(metrics);
+
+  metrics.Clear();
+  metrics.InsertElementAt(0, MakeMetrics(FrameMetrics::START_SCROLL_ID + 5));
+  layers[4]->SetFrameMetrics(metrics);
+
+  metrics.Clear();
+  metrics.InsertElementAt(0, MakeMetrics(FrameMetrics::START_SCROLL_ID + 6));
+  layers[5]->SetFrameMetrics(metrics);
+
+  LayerMetricsWrapper wrapper(root, LayerMetricsWrapper::StartAt::TOP);
+  nsTArray<Layer*> expectedLayers;
+  expectedLayers.AppendElement(layers[0].get());
+  expectedLayers.AppendElement(layers[0].get());
+  expectedLayers.AppendElement(layers[0].get());
+  expectedLayers.AppendElement(layers[0].get());
+  expectedLayers.AppendElement(layers[0].get());
+  expectedLayers.AppendElement(layers[0].get());
+  expectedLayers.AppendElement(layers[1].get());
+  expectedLayers.AppendElement(layers[2].get());
+  expectedLayers.AppendElement(layers[2].get());
+  expectedLayers.AppendElement(layers[3].get());
+  nsTArray<FrameMetrics::ViewID> expectedIds;
+  expectedIds.AppendElement(FrameMetrics::START_SCROLL_ID + 0);
+  expectedIds.AppendElement(FrameMetrics::NULL_SCROLL_ID);
+  expectedIds.AppendElement(FrameMetrics::START_SCROLL_ID + 1);
+  expectedIds.AppendElement(FrameMetrics::START_SCROLL_ID + 2);
+  expectedIds.AppendElement(FrameMetrics::NULL_SCROLL_ID);
+  expectedIds.AppendElement(FrameMetrics::NULL_SCROLL_ID);
+  expectedIds.AppendElement(FrameMetrics::START_SCROLL_ID + 3);
+  expectedIds.AppendElement(FrameMetrics::NULL_SCROLL_ID);
+  expectedIds.AppendElement(FrameMetrics::START_SCROLL_ID + 4);
+  expectedIds.AppendElement(FrameMetrics::NULL_SCROLL_ID);
+  for (int i = 0; i < 10; i++) {
+    ASSERT_EQ(expectedLayers[i], wrapper.GetLayer());
+    ASSERT_EQ(expectedIds[i], wrapper.Metrics().GetScrollId());
+    wrapper = wrapper.GetFirstChild();
+  }
+  ASSERT_FALSE(wrapper.IsValid());
+
+  wrapper = LayerMetricsWrapper(root, LayerMetricsWrapper::StartAt::BOTTOM);
+  for (int i = 5; i < 10; i++) {
+    ASSERT_EQ(expectedLayers[i], wrapper.GetLayer());
+    ASSERT_EQ(expectedIds[i], wrapper.Metrics().GetScrollId());
+    wrapper = wrapper.GetFirstChild();
+  }
+  ASSERT_FALSE(wrapper.IsValid());
+
+  wrapper = LayerMetricsWrapper(layers[4], LayerMetricsWrapper::StartAt::BOTTOM);
+  ASSERT_EQ(FrameMetrics::START_SCROLL_ID + 5, wrapper.Metrics().GetScrollId());
+  wrapper = wrapper.GetParent();
+  ASSERT_EQ(FrameMetrics::START_SCROLL_ID + 4, wrapper.Metrics().GetScrollId());
+  ASSERT_EQ(layers[2].get(), wrapper.GetLayer());
+  ASSERT_FALSE(wrapper.GetNextSibling().IsValid());
+  wrapper = wrapper.GetParent();
+  ASSERT_EQ(FrameMetrics::NULL_SCROLL_ID, wrapper.Metrics().GetScrollId());
+  ASSERT_EQ(layers[2].get(), wrapper.GetLayer());
+  wrapper = wrapper.GetNextSibling();
+  ASSERT_EQ(FrameMetrics::START_SCROLL_ID + 6, wrapper.Metrics().GetScrollId());
+  ASSERT_EQ(layers[5].get(), wrapper.GetLayer());
+}