Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(4510)

Unified Diff: cc/trees/layer_tree_host_unittest_scroll.cc

Issue 1766053002: Clean LayerImpl's scroll offset callers in unit tests. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: cc/trees/layer_tree_host_unittest_scroll.cc
diff --git a/cc/trees/layer_tree_host_unittest_scroll.cc b/cc/trees/layer_tree_host_unittest_scroll.cc
index c3dc75275aae38a18aec8fde3caf87bc671213e8..afe8cb9293eeec30843abc8455f53847cff6b19f 100644
--- a/cc/trees/layer_tree_host_unittest_scroll.cc
+++ b/cc/trees/layer_tree_host_unittest_scroll.cc
@@ -73,6 +73,11 @@ class LayerTreeHostScrollTest : public LayerTreeTest {
layer_tree_host(),
layer_settings());
}
+
+ public:
+ ScrollTree* scroll_tree(LayerImpl* layer_impl) {
ajuma 2016/03/07 19:10:19 This is probably better off as a helper function d
sunxd 2016/03/09 01:51:21 Done.
+ return &layer_impl->layer_tree_impl()->property_trees()->scroll_tree;
+ }
};
class LayerTreeHostScrollTestScrollSimple : public LayerTreeHostScrollTest {
@@ -115,12 +120,16 @@ class LayerTreeHostScrollTestScrollSimple : public LayerTreeHostScrollTest {
switch (impl->active_tree()->source_frame_number()) {
case 0:
- EXPECT_VECTOR_EQ(initial_scroll_, scroll_layer->BaseScrollOffset());
+ EXPECT_VECTOR_EQ(initial_scroll_, scroll_tree(scroll_layer)
+ ->GetScrollOffsetBaseForTesting(
+ scroll_layer->id()));
EXPECT_VECTOR_EQ(scroll_amount_, scroll_layer->ScrollDelta());
PostSetNeedsCommitToMainThread();
break;
case 1:
- EXPECT_VECTOR_EQ(second_scroll_, scroll_layer->BaseScrollOffset());
+ EXPECT_VECTOR_EQ(second_scroll_, scroll_tree(scroll_layer)
+ ->GetScrollOffsetBaseForTesting(
+ scroll_layer->id()));
EXPECT_VECTOR_EQ(scroll_amount_, scroll_layer->ScrollDelta());
EndTest();
break;
@@ -187,7 +196,9 @@ class LayerTreeHostScrollTestScrollMultipleRedraw
scroll_layer->ScrollBy(scroll_amount_);
EXPECT_VECTOR_EQ(scroll_amount_, scroll_layer->ScrollDelta());
- EXPECT_VECTOR_EQ(initial_scroll_, scroll_layer->BaseScrollOffset());
+ EXPECT_VECTOR_EQ(initial_scroll_,
+ scroll_tree(scroll_layer)
+ ->GetScrollOffsetBaseForTesting(scroll_layer->id()));
PostSetNeedsRedrawToMainThread();
} else if (impl->active_tree()->source_frame_number() == 0 &&
impl->SourceAnimationFrameNumberForTesting() == 2) {
@@ -331,7 +342,9 @@ class LayerTreeHostScrollTestScrollAbortedCommit
EXPECT_VECTOR_EQ(gfx::Vector2d(), root_scroll_layer->ScrollDelta());
root_scroll_layer->ScrollBy(impl_scroll_);
EXPECT_VECTOR_EQ(impl_scroll_, root_scroll_layer->ScrollDelta());
- EXPECT_VECTOR_EQ(initial_scroll_, root_scroll_layer->BaseScrollOffset());
+ EXPECT_VECTOR_EQ(initial_scroll_, scroll_tree(root_scroll_layer)
+ ->GetScrollOffsetBaseForTesting(
+ root_scroll_layer->id()));
EXPECT_EQ(1.f, impl->active_tree()->page_scale_delta());
EXPECT_EQ(1.f, impl->active_tree()->current_page_scale_factor());
@@ -351,7 +364,8 @@ class LayerTreeHostScrollTestScrollAbortedCommit
EXPECT_VECTOR_EQ(impl_scroll_, root_scroll_layer->ScrollDelta());
EXPECT_VECTOR_EQ(
gfx::ScrollOffsetWithDelta(initial_scroll_, impl_scroll_),
- root_scroll_layer->BaseScrollOffset());
+ scroll_tree(root_scroll_layer)
+ ->GetScrollOffsetBaseForTesting(root_scroll_layer->id()));
EXPECT_EQ(1.f, impl->active_tree()->page_scale_delta());
EXPECT_EQ(impl_scale_, impl->active_tree()->current_page_scale_factor());
@@ -372,16 +386,20 @@ class LayerTreeHostScrollTestScrollAbortedCommit
impl->SetNeedsCommit();
EXPECT_VECTOR_EQ(impl_scroll_, root_scroll_layer->ScrollDelta());
gfx::Vector2dF delta = impl_scroll_ + impl_scroll_ + second_main_scroll_;
- EXPECT_VECTOR_EQ(gfx::ScrollOffsetWithDelta(initial_scroll_, delta),
- root_scroll_layer->BaseScrollOffset());
+ EXPECT_VECTOR_EQ(
+ gfx::ScrollOffsetWithDelta(initial_scroll_, delta),
+ scroll_tree(root_scroll_layer)
+ ->GetScrollOffsetBaseForTesting(root_scroll_layer->id()));
} else if (impl->active_tree()->source_frame_number() == 2 &&
impl->SourceAnimationFrameNumberForTesting() == 4) {
// Final draw after the second aborted commit.
EXPECT_VECTOR_EQ(gfx::Vector2d(), root_scroll_layer->ScrollDelta());
gfx::Vector2dF delta =
impl_scroll_ + impl_scroll_ + impl_scroll_ + second_main_scroll_;
- EXPECT_VECTOR_EQ(gfx::ScrollOffsetWithDelta(initial_scroll_, delta),
- root_scroll_layer->BaseScrollOffset());
+ EXPECT_VECTOR_EQ(
+ gfx::ScrollOffsetWithDelta(initial_scroll_, delta),
+ scroll_tree(root_scroll_layer)
+ ->GetScrollOffsetBaseForTesting(root_scroll_layer->id()));
EndTest();
} else {
// Commit for source frame 3 is aborted.
@@ -441,13 +459,18 @@ class LayerTreeHostScrollTestFractionalScroll : public LayerTreeHostScrollTest {
// multiple commits.
switch (impl->active_tree()->source_frame_number()) {
case 0:
- EXPECT_VECTOR_EQ(gfx::Vector2d(0, 0), scroll_layer->BaseScrollOffset());
+ EXPECT_VECTOR_EQ(
+ gfx::Vector2d(0, 0),
+ scroll_tree(scroll_layer)
+ ->GetScrollOffsetBaseForTesting(scroll_layer->id()));
EXPECT_VECTOR_EQ(gfx::Vector2d(0, 0), scroll_layer->ScrollDelta());
PostSetNeedsCommitToMainThread();
break;
case 1:
- EXPECT_VECTOR_EQ(gfx::ToFlooredVector2d(scroll_amount_),
- scroll_layer->BaseScrollOffset());
+ EXPECT_VECTOR_EQ(
+ gfx::ToFlooredVector2d(scroll_amount_),
+ scroll_tree(scroll_layer)
+ ->GetScrollOffsetBaseForTesting(scroll_layer->id()));
EXPECT_VECTOR_EQ(gfx::Vector2dF(fmod(scroll_amount_.x(), 1.0f), 0.0f),
scroll_layer->ScrollDelta());
PostSetNeedsCommitToMainThread();
@@ -455,7 +478,8 @@ class LayerTreeHostScrollTestFractionalScroll : public LayerTreeHostScrollTest {
case 2:
EXPECT_VECTOR_EQ(
gfx::ToFlooredVector2d(scroll_amount_ + scroll_amount_),
- scroll_layer->BaseScrollOffset());
+ scroll_tree(scroll_layer)
+ ->GetScrollOffsetBaseForTesting(scroll_layer->id()));
EXPECT_VECTOR_EQ(
gfx::Vector2dF(fmod(2.0f * scroll_amount_.x(), 1.0f), 0.0f),
scroll_layer->ScrollDelta());
@@ -631,7 +655,9 @@ class LayerTreeHostScrollTestCaseWithChild : public LayerTreeHostScrollTest {
// Check the scroll is applied as a delta.
EXPECT_VECTOR_EQ(initial_offset_,
- expected_scroll_layer_impl->BaseScrollOffset());
+ scroll_tree(expected_scroll_layer_impl)
+ ->GetScrollOffsetBaseForTesting(
+ expected_scroll_layer_impl->id()));
EXPECT_VECTOR_EQ(scroll_amount_,
expected_scroll_layer_impl->ScrollDelta());
break;
@@ -649,7 +675,9 @@ class LayerTreeHostScrollTestCaseWithChild : public LayerTreeHostScrollTest {
// Check the scroll is applied as a delta.
EXPECT_VECTOR_EQ(javascript_scroll_,
- expected_scroll_layer_impl->BaseScrollOffset());
+ scroll_tree(expected_scroll_layer_impl)
+ ->GetScrollOffsetBaseForTesting(
+ expected_scroll_layer_impl->id()));
EXPECT_VECTOR_EQ(scroll_amount_,
expected_scroll_layer_impl->ScrollDelta());
break;
@@ -658,7 +686,9 @@ class LayerTreeHostScrollTestCaseWithChild : public LayerTreeHostScrollTest {
EXPECT_VECTOR_EQ(
gfx::ScrollOffsetWithDelta(javascript_scroll_, scroll_amount_),
- expected_scroll_layer_impl->BaseScrollOffset());
+ scroll_tree(expected_scroll_layer_impl)
+ ->GetScrollOffsetBaseForTesting(
+ expected_scroll_layer_impl->id()));
EXPECT_VECTOR_EQ(gfx::Vector2d(),
expected_scroll_layer_impl->ScrollDelta());
@@ -841,7 +871,9 @@ class LayerTreeHostScrollTestSimple : public LayerTreeHostScrollTest {
EXPECT_VECTOR_EQ(gfx::Vector2d(), scroll_layer->ScrollDelta());
scroll_layer->ScrollBy(impl_thread_scroll1_);
- EXPECT_VECTOR_EQ(initial_scroll_, scroll_layer->BaseScrollOffset());
+ EXPECT_VECTOR_EQ(initial_scroll_, scroll_tree(scroll_layer)
+ ->GetScrollOffsetBaseForTesting(
+ scroll_layer->id()));
EXPECT_VECTOR_EQ(impl_thread_scroll1_, scroll_layer->ScrollDelta());
PostSetNeedsCommitToMainThread();
@@ -853,7 +885,9 @@ class LayerTreeHostScrollTestSimple : public LayerTreeHostScrollTest {
EXPECT_EQ(impl->pending_tree()->source_frame_number(), 1);
scroll_layer->ScrollBy(impl_thread_scroll2_);
- EXPECT_VECTOR_EQ(initial_scroll_, scroll_layer->BaseScrollOffset());
+ EXPECT_VECTOR_EQ(initial_scroll_, scroll_tree(scroll_layer)
+ ->GetScrollOffsetBaseForTesting(
+ scroll_layer->id()));
EXPECT_VECTOR_EQ(impl_thread_scroll1_ + impl_thread_scroll2_,
scroll_layer->ScrollDelta());
@@ -862,7 +896,8 @@ class LayerTreeHostScrollTestSimple : public LayerTreeHostScrollTest {
EXPECT_VECTOR_EQ(
gfx::ScrollOffsetWithDelta(
initial_scroll_, main_thread_scroll_ + impl_thread_scroll1_),
- pending_scroll_layer->BaseScrollOffset());
+ scroll_tree(pending_scroll_layer)
+ ->GetScrollOffsetBaseForTesting(pending_scroll_layer->id()));
EXPECT_VECTOR_EQ(impl_thread_scroll2_,
pending_scroll_layer->ScrollDelta());
}
@@ -872,7 +907,8 @@ class LayerTreeHostScrollTestSimple : public LayerTreeHostScrollTest {
EXPECT_VECTOR_EQ(
gfx::ScrollOffsetWithDelta(
initial_scroll_, main_thread_scroll_ + impl_thread_scroll1_),
- scroll_layer->BaseScrollOffset());
+ scroll_tree(scroll_layer)
+ ->GetScrollOffsetBaseForTesting(scroll_layer->id()));
EXPECT_VECTOR_EQ(impl_thread_scroll2_, scroll_layer->ScrollDelta());
EndTest();
break;
@@ -961,21 +997,24 @@ class LayerTreeHostScrollTestImplOnlyScroll : public LayerTreeHostScrollTest {
ASSERT_TRUE(pending_scroll_layer);
switch (impl->pending_tree()->source_frame_number()) {
case 0:
- EXPECT_VECTOR_EQ(initial_scroll_,
- pending_scroll_layer->BaseScrollOffset());
+ EXPECT_VECTOR_EQ(initial_scroll_, scroll_tree(pending_scroll_layer)
+ ->GetScrollOffsetBaseForTesting(
+ pending_scroll_layer->id()));
EXPECT_VECTOR_EQ(gfx::Vector2d(), pending_scroll_layer->ScrollDelta());
EXPECT_FALSE(active_root);
break;
case 1:
// Even though the scroll happened during the commit, both layers
// should have the appropriate scroll delta.
- EXPECT_VECTOR_EQ(initial_scroll_,
- pending_scroll_layer->BaseScrollOffset());
+ EXPECT_VECTOR_EQ(initial_scroll_, scroll_tree(pending_scroll_layer)
+ ->GetScrollOffsetBaseForTesting(
+ pending_scroll_layer->id()));
EXPECT_VECTOR_EQ(impl_thread_scroll_,
pending_scroll_layer->ScrollDelta());
ASSERT_TRUE(active_root);
- EXPECT_VECTOR_EQ(initial_scroll_,
- active_scroll_layer->BaseScrollOffset());
+ EXPECT_VECTOR_EQ(initial_scroll_, scroll_tree(active_scroll_layer)
+ ->GetScrollOffsetBaseForTesting(
+ active_scroll_layer->id()));
EXPECT_VECTOR_EQ(impl_thread_scroll_,
active_scroll_layer->ScrollDelta());
break;
@@ -983,7 +1022,8 @@ class LayerTreeHostScrollTestImplOnlyScroll : public LayerTreeHostScrollTest {
// On the next commit, this delta should have been sent and applied.
EXPECT_VECTOR_EQ(
gfx::ScrollOffsetWithDelta(initial_scroll_, impl_thread_scroll_),
- pending_scroll_layer->BaseScrollOffset());
+ scroll_tree(pending_scroll_layer)
+ ->GetScrollOffsetBaseForTesting(pending_scroll_layer->id()));
EXPECT_VECTOR_EQ(gfx::Vector2d(), pending_scroll_layer->ScrollDelta());
break;
}
@@ -997,14 +1037,18 @@ class LayerTreeHostScrollTestImplOnlyScroll : public LayerTreeHostScrollTest {
switch (impl->active_tree()->source_frame_number()) {
case 0:
- EXPECT_VECTOR_EQ(initial_scroll_, scroll_layer->BaseScrollOffset());
+ EXPECT_VECTOR_EQ(initial_scroll_, scroll_tree(scroll_layer)
+ ->GetScrollOffsetBaseForTesting(
+ scroll_layer->id()));
EXPECT_VECTOR_EQ(gfx::Vector2d(), scroll_layer->ScrollDelta());
EXPECT_EQ(1.f, impl->active_tree()->page_scale_delta());
EXPECT_EQ(1.f, impl->active_tree()->current_page_scale_factor());
PostSetNeedsCommitToMainThread();
break;
case 1:
- EXPECT_VECTOR_EQ(initial_scroll_, scroll_layer->BaseScrollOffset());
+ EXPECT_VECTOR_EQ(initial_scroll_, scroll_tree(scroll_layer)
+ ->GetScrollOffsetBaseForTesting(
+ scroll_layer->id()));
EXPECT_VECTOR_EQ(impl_thread_scroll_, scroll_layer->ScrollDelta());
EXPECT_EQ(impl_scale_, impl->active_tree()->page_scale_delta());
EXPECT_EQ(impl_scale_,
@@ -1313,9 +1357,10 @@ class LayerTreeHostScrollTestLayerStructureChange
LayerImpl* root = impl->OuterViewportScrollLayer();
switch (impl->active_tree()->source_frame_number()) {
case 0:
- root->child_at(0)->SetScrollDelta(gfx::Vector2dF(5, 5));
- root->child_at(0)->child_at(0)->SetScrollDelta(gfx::Vector2dF(5, 5));
- root->child_at(1)->SetScrollDelta(gfx::Vector2dF(5, 5));
+ SetScrollOffsetDelta(root->child_at(0), gfx::Vector2dF(5, 5));
+ SetScrollOffsetDelta(root->child_at(0)->child_at(0),
+ gfx::Vector2dF(5, 5));
+ SetScrollOffsetDelta(root->child_at(1), gfx::Vector2dF(5, 5));
PostSetNeedsCommitToMainThread();
break;
case 1:
@@ -1363,6 +1408,13 @@ class LayerTreeHostScrollTestLayerStructureChange
return scroll_layer.get();
}
+ void SetScrollOffsetDelta(LayerImpl* layer_impl,
ajuma 2016/03/07 19:10:19 static
sunxd 2016/03/09 01:51:21 Done.
+ const gfx::Vector2dF& delta) {
+ layer_impl->SetCurrentScrollOffset(
+ layer_impl->synced_scroll_offset()->ActiveBase() +
+ gfx::ScrollOffset(delta));
+ }
+
FakeLayerScrollClient root_scroll_layer_client_;
FakeLayerScrollClient sibling_scroll_layer_client_;
FakeLayerScrollClient child_scroll_layer_client_;

Powered by Google App Engine
This is Rietveld 408576698