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

Side by Side Diff: cc/trees/layer_tree_host_unittest_scroll.cc

Issue 23983047: Pinch/Zoom Infrastructure & Plumbing CL (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Remove content_bounds() usage, fix unit test. Created 6 years, 11 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright 2012 The Chromium Authors. All rights reserved. 1 // Copyright 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "cc/trees/layer_tree_host.h" 5 #include "cc/trees/layer_tree_host.h"
6 6
7 #include "base/memory/weak_ptr.h" 7 #include "base/memory/weak_ptr.h"
8 #include "cc/layers/content_layer.h" 8 #include "cc/layers/content_layer.h"
9 #include "cc/layers/layer.h" 9 #include "cc/layers/layer.h"
10 #include "cc/layers/layer_impl.h" 10 #include "cc/layers/layer_impl.h"
(...skipping 13 matching lines...) Expand all
24 24
25 class LayerTreeHostScrollTestScrollSimple : public LayerTreeHostScrollTest { 25 class LayerTreeHostScrollTestScrollSimple : public LayerTreeHostScrollTest {
26 public: 26 public:
27 LayerTreeHostScrollTestScrollSimple() 27 LayerTreeHostScrollTestScrollSimple()
28 : initial_scroll_(10, 20), 28 : initial_scroll_(10, 20),
29 second_scroll_(40, 5), 29 second_scroll_(40, 5),
30 scroll_amount_(2, -1), 30 scroll_amount_(2, -1),
31 num_scrolls_(0) {} 31 num_scrolls_(0) {}
32 32
33 virtual void BeginTest() OVERRIDE { 33 virtual void BeginTest() OVERRIDE {
34 layer_tree_host()->root_layer()->SetScrollable(true); 34 Layer* root_layer = layer_tree_host()->root_layer();
35 layer_tree_host()->root_layer() 35 scoped_refptr<Layer> scroll_layer = Layer::Create();
36 ->SetMaxScrollOffset(gfx::Vector2d(100, 100)); 36 root_layer->AddChild(scroll_layer);
37 layer_tree_host()->root_layer()->SetScrollOffset(initial_scroll_); 37 // Create an effective max_scroll_offset of (100, 100).
38 scroll_layer->SetBounds(gfx::Size(root_layer->bounds().width() + 100,
39 root_layer->bounds().height() + 100));
40 scroll_layer->SetIsDrawable(true);
41 scroll_layer->SetIsContainerForFixedPositionLayers(true);
42 scroll_layer->SetScrollClipLayer(root_layer);
43 scroll_layer->SetScrollOffset(initial_scroll_);
44 layer_tree_host()->RegisterViewportLayers(root_layer, scroll_layer, NULL);
38 PostSetNeedsCommitToMainThread(); 45 PostSetNeedsCommitToMainThread();
39 } 46 }
40 47
41 virtual void Layout() OVERRIDE { 48 virtual void Layout() OVERRIDE {
42 Layer* root = layer_tree_host()->root_layer(); 49 Layer* root = layer_tree_host()->root_layer();
50 Layer* scroll_layer = root->children()[0];
43 if (!layer_tree_host()->source_frame_number()) { 51 if (!layer_tree_host()->source_frame_number()) {
44 EXPECT_VECTOR_EQ(initial_scroll_, root->scroll_offset()); 52 EXPECT_VECTOR_EQ(initial_scroll_, scroll_layer->scroll_offset());
45 } else { 53 } else {
46 EXPECT_VECTOR_EQ(initial_scroll_ + scroll_amount_, root->scroll_offset()); 54 EXPECT_VECTOR_EQ(initial_scroll_ + scroll_amount_,
55 scroll_layer->scroll_offset());
47 56
48 // Pretend like Javascript updated the scroll position itself. 57 // Pretend like Javascript updated the scroll position itself.
49 root->SetScrollOffset(second_scroll_); 58 scroll_layer->SetScrollOffset(second_scroll_);
50 } 59 }
51 } 60 }
52 61
53 virtual void DrawLayersOnThread(LayerTreeHostImpl* impl) OVERRIDE { 62 virtual void DrawLayersOnThread(LayerTreeHostImpl* impl) OVERRIDE {
54 LayerImpl* root = impl->active_tree()->root_layer(); 63 LayerImpl* root = impl->active_tree()->root_layer();
55 EXPECT_VECTOR_EQ(gfx::Vector2d(), root->ScrollDelta()); 64 LayerImpl* scroll_layer = root->children()[0];
65 EXPECT_VECTOR_EQ(gfx::Vector2d(), scroll_layer->ScrollDelta());
56 66
57 root->SetScrollable(true); 67 scroll_layer->SetScrollClipLayer(root->id());
58 root->SetMaxScrollOffset(gfx::Vector2d(100, 100)); 68 scroll_layer->SetBounds(
59 root->ScrollBy(scroll_amount_); 69 gfx::Size(root->bounds().width() + 100, root->bounds().height() + 100));
70 scroll_layer->ScrollBy(scroll_amount_);
60 71
61 switch (impl->active_tree()->source_frame_number()) { 72 switch (impl->active_tree()->source_frame_number()) {
62 case 0: 73 case 0:
63 EXPECT_VECTOR_EQ(initial_scroll_, root->scroll_offset()); 74 EXPECT_VECTOR_EQ(initial_scroll_, scroll_layer->scroll_offset());
64 EXPECT_VECTOR_EQ(scroll_amount_, root->ScrollDelta()); 75 EXPECT_VECTOR_EQ(scroll_amount_, scroll_layer->ScrollDelta());
65 PostSetNeedsCommitToMainThread(); 76 PostSetNeedsCommitToMainThread();
66 break; 77 break;
67 case 1: 78 case 1:
68 EXPECT_VECTOR_EQ(root->scroll_offset(), second_scroll_); 79 EXPECT_VECTOR_EQ(scroll_layer->scroll_offset(), second_scroll_);
69 EXPECT_VECTOR_EQ(root->ScrollDelta(), scroll_amount_); 80 EXPECT_VECTOR_EQ(scroll_layer->ScrollDelta(), scroll_amount_);
70 EndTest(); 81 EndTest();
71 break; 82 break;
72 } 83 }
73 } 84 }
74 85
75 virtual void ApplyScrollAndScale(gfx::Vector2d scroll_delta, 86 virtual void ApplyScrollAndScale(gfx::Vector2d scroll_delta,
76 float scale) OVERRIDE { 87 float scale) OVERRIDE {
77 num_scrolls_++; 88 num_scrolls_++;
78 } 89 }
79 90
80 virtual void AfterTest() OVERRIDE { EXPECT_EQ(1, num_scrolls_); } 91 virtual void AfterTest() OVERRIDE { EXPECT_EQ(1, num_scrolls_); }
81 92
82 private: 93 private:
83 gfx::Vector2d initial_scroll_; 94 gfx::Vector2d initial_scroll_;
84 gfx::Vector2d second_scroll_; 95 gfx::Vector2d second_scroll_;
85 gfx::Vector2d scroll_amount_; 96 gfx::Vector2d scroll_amount_;
86 int num_scrolls_; 97 int num_scrolls_;
87 }; 98 };
88 99
89 MULTI_THREAD_TEST_F(LayerTreeHostScrollTestScrollSimple); 100 MULTI_THREAD_TEST_F(LayerTreeHostScrollTestScrollSimple);
90 101
91 class LayerTreeHostScrollTestScrollMultipleRedraw 102 class LayerTreeHostScrollTestScrollMultipleRedraw
92 : public LayerTreeHostScrollTest { 103 : public LayerTreeHostScrollTest {
93 public: 104 public:
94 LayerTreeHostScrollTestScrollMultipleRedraw() 105 LayerTreeHostScrollTestScrollMultipleRedraw()
95 : initial_scroll_(40, 10), scroll_amount_(-3, 17), num_scrolls_(0) {} 106 : initial_scroll_(40, 10), scroll_amount_(-3, 17), num_scrolls_(0) {}
96 107
97 virtual void BeginTest() OVERRIDE { 108 virtual void BeginTest() OVERRIDE {
98 layer_tree_host()->root_layer()->SetScrollable(true); 109 Layer* root_layer = layer_tree_host()->root_layer();
99 layer_tree_host()->root_layer()->SetScrollOffset(initial_scroll_); 110 scoped_refptr<Layer> scroll_layer = Layer::Create();
100 layer_tree_host()->root_layer()->SetBounds(gfx::Size(200, 200)); 111 root_layer->AddChild(scroll_layer);
101 layer_tree_host()->root_layer() 112 // Create an effective max_scroll_offset of (100, 100).
102 ->SetMaxScrollOffset(gfx::Vector2d(100, 100)); 113 scroll_layer->SetBounds(gfx::Size(root_layer->bounds().width() + 100,
114 root_layer->bounds().height() + 100));
115 scroll_layer->SetIsDrawable(true);
116 scroll_layer->SetIsContainerForFixedPositionLayers(true);
117 scroll_layer->SetScrollClipLayer(root_layer);
118 scroll_layer->SetScrollOffset(initial_scroll_);
119 layer_tree_host()->RegisterViewportLayers(root_layer, scroll_layer, NULL);
103 PostSetNeedsCommitToMainThread(); 120 PostSetNeedsCommitToMainThread();
104 } 121 }
105 122
106 virtual void BeginCommitOnThread(LayerTreeHostImpl* impl) OVERRIDE { 123 virtual void BeginCommitOnThread(LayerTreeHostImpl* impl) OVERRIDE {
107 Layer* root = layer_tree_host()->root_layer(); 124 Layer* root = layer_tree_host()->root_layer();
125 Layer* scroll_layer = root->children()[0];
enne (OOO) 2014/01/21 19:00:06 What about an accessor function for the scroll lay
wjmaclean 2014/01/21 22:37:27 Done. I made the Layer scroll_layer var a member
108 switch (layer_tree_host()->source_frame_number()) { 126 switch (layer_tree_host()->source_frame_number()) {
109 case 0: 127 case 0:
110 EXPECT_VECTOR_EQ(root->scroll_offset(), initial_scroll_); 128 EXPECT_VECTOR_EQ(scroll_layer->scroll_offset(), initial_scroll_);
111 break; 129 break;
112 case 1: 130 case 1:
113 EXPECT_VECTOR_EQ(root->scroll_offset(), 131 EXPECT_VECTOR_EQ(scroll_layer->scroll_offset(),
114 initial_scroll_ + scroll_amount_ + scroll_amount_); 132 initial_scroll_ + scroll_amount_ + scroll_amount_);
115 case 2: 133 case 2:
116 EXPECT_VECTOR_EQ(root->scroll_offset(), 134 EXPECT_VECTOR_EQ(scroll_layer->scroll_offset(),
117 initial_scroll_ + scroll_amount_ + scroll_amount_); 135 initial_scroll_ + scroll_amount_ + scroll_amount_);
118 break; 136 break;
119 } 137 }
120 } 138 }
121 139
122 virtual void DrawLayersOnThread(LayerTreeHostImpl* impl) OVERRIDE { 140 virtual void DrawLayersOnThread(LayerTreeHostImpl* impl) OVERRIDE {
123 LayerImpl* root = impl->active_tree()->root_layer(); 141 LayerImpl* root = impl->active_tree()->root_layer();
142 LayerImpl* scroll_layer = root->children()[0];
124 if (impl->active_tree()->source_frame_number() == 0 && 143 if (impl->active_tree()->source_frame_number() == 0 &&
125 impl->SourceAnimationFrameNumber() == 1) { 144 impl->SourceAnimationFrameNumber() == 1) {
126 // First draw after first commit. 145 // First draw after first commit.
127 EXPECT_VECTOR_EQ(root->ScrollDelta(), gfx::Vector2d()); 146 EXPECT_VECTOR_EQ(scroll_layer->ScrollDelta(), gfx::Vector2d());
128 root->ScrollBy(scroll_amount_); 147 scroll_layer->ScrollBy(scroll_amount_);
129 EXPECT_VECTOR_EQ(root->ScrollDelta(), scroll_amount_); 148 EXPECT_VECTOR_EQ(scroll_layer->ScrollDelta(), scroll_amount_);
130 149
131 EXPECT_VECTOR_EQ(root->scroll_offset(), initial_scroll_); 150 EXPECT_VECTOR_EQ(scroll_layer->scroll_offset(), initial_scroll_);
132 PostSetNeedsRedrawToMainThread(); 151 PostSetNeedsRedrawToMainThread();
133 } else if (impl->active_tree()->source_frame_number() == 0 && 152 } else if (impl->active_tree()->source_frame_number() == 0 &&
134 impl->SourceAnimationFrameNumber() == 2) { 153 impl->SourceAnimationFrameNumber() == 2) {
135 // Second draw after first commit. 154 // Second draw after first commit.
136 EXPECT_EQ(root->ScrollDelta(), scroll_amount_); 155 EXPECT_EQ(scroll_layer->ScrollDelta(), scroll_amount_);
137 root->ScrollBy(scroll_amount_); 156 scroll_layer->ScrollBy(scroll_amount_);
138 EXPECT_VECTOR_EQ(root->ScrollDelta(), scroll_amount_ + scroll_amount_); 157 EXPECT_VECTOR_EQ(scroll_layer->ScrollDelta(),
158 scroll_amount_ + scroll_amount_);
139 159
140 EXPECT_VECTOR_EQ(root->scroll_offset(), initial_scroll_); 160 EXPECT_VECTOR_EQ(scroll_layer->scroll_offset(), initial_scroll_);
141 PostSetNeedsCommitToMainThread(); 161 PostSetNeedsCommitToMainThread();
142 } else if (impl->active_tree()->source_frame_number() == 1) { 162 } else if (impl->active_tree()->source_frame_number() == 1) {
143 // Third or later draw after second commit. 163 // Third or later draw after second commit.
144 EXPECT_GE(impl->SourceAnimationFrameNumber(), 3); 164 EXPECT_GE(impl->SourceAnimationFrameNumber(), 3);
145 EXPECT_VECTOR_EQ(root->ScrollDelta(), gfx::Vector2d()); 165 EXPECT_VECTOR_EQ(scroll_layer->ScrollDelta(), gfx::Vector2d());
146 EXPECT_VECTOR_EQ(root->scroll_offset(), 166 EXPECT_VECTOR_EQ(scroll_layer->scroll_offset(),
147 initial_scroll_ + scroll_amount_ + scroll_amount_); 167 initial_scroll_ + scroll_amount_ + scroll_amount_);
148 EndTest(); 168 EndTest();
149 } 169 }
150 } 170 }
151 171
152 virtual void ApplyScrollAndScale(gfx::Vector2d scroll_delta, 172 virtual void ApplyScrollAndScale(gfx::Vector2d scroll_delta,
153 float scale) OVERRIDE { 173 float scale) OVERRIDE {
154 num_scrolls_++; 174 num_scrolls_++;
155 } 175 }
156 176
(...skipping 19 matching lines...) Expand all
176 num_did_begin_main_frames_(0), 196 num_did_begin_main_frames_(0),
177 num_will_commits_(0), 197 num_will_commits_(0),
178 num_did_commits_(0), 198 num_did_commits_(0),
179 num_impl_commits_(0), 199 num_impl_commits_(0),
180 num_impl_scrolls_(0) {} 200 num_impl_scrolls_(0) {}
181 201
182 virtual void BeginTest() OVERRIDE { PostSetNeedsCommitToMainThread(); } 202 virtual void BeginTest() OVERRIDE { PostSetNeedsCommitToMainThread(); }
183 203
184 virtual void SetupTree() OVERRIDE { 204 virtual void SetupTree() OVERRIDE {
185 LayerTreeHostScrollTest::SetupTree(); 205 LayerTreeHostScrollTest::SetupTree();
206 Layer* root_layer = layer_tree_host()->root_layer();
186 scoped_refptr<Layer> root_scroll_layer = Layer::Create(); 207 scoped_refptr<Layer> root_scroll_layer = Layer::Create();
187 root_scroll_layer->SetScrollable(true); 208 root_scroll_layer->SetScrollClipLayer(root_layer);
188 root_scroll_layer->SetScrollOffset(initial_scroll_); 209 root_scroll_layer->SetScrollOffset(initial_scroll_);
189 root_scroll_layer->SetBounds(gfx::Size(200, 200)); 210 root_scroll_layer->SetBounds(gfx::Size(200, 200));
190 root_scroll_layer->SetMaxScrollOffset(gfx::Vector2d(100, 100));
191 root_scroll_layer->SetIsDrawable(true); 211 root_scroll_layer->SetIsDrawable(true);
192 layer_tree_host()->root_layer()->AddChild(root_scroll_layer); 212 root_scroll_layer->SetIsContainerForFixedPositionLayers(true);
213 root_layer->AddChild(root_scroll_layer);
193 214
215 layer_tree_host()->RegisterViewportLayers(
216 root_layer, root_scroll_layer, NULL);
194 layer_tree_host()->SetPageScaleFactorAndLimits(1.f, 0.01f, 100.f); 217 layer_tree_host()->SetPageScaleFactorAndLimits(1.f, 0.01f, 100.f);
195 } 218 }
196 219
197 virtual void WillBeginMainFrame() OVERRIDE { 220 virtual void WillBeginMainFrame() OVERRIDE {
198 num_will_begin_main_frames_++; 221 num_will_begin_main_frames_++;
199 Layer* root_scroll_layer = layer_tree_host()->root_layer()->children()[0]; 222 Layer* root_scroll_layer = layer_tree_host()->root_layer()->children()[0];
200 switch (num_will_begin_main_frames_) { 223 switch (num_will_begin_main_frames_) {
201 case 1: 224 case 1:
202 // This will not be aborted because of the initial prop changes. 225 // This will not be aborted because of the initial prop changes.
203 EXPECT_EQ(0, num_impl_scrolls_); 226 EXPECT_EQ(0, num_impl_scrolls_);
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
337 int num_impl_commits_; 360 int num_impl_commits_;
338 int num_impl_scrolls_; 361 int num_impl_scrolls_;
339 }; 362 };
340 363
341 MULTI_THREAD_TEST_F(LayerTreeHostScrollTestScrollAbortedCommit); 364 MULTI_THREAD_TEST_F(LayerTreeHostScrollTestScrollAbortedCommit);
342 365
343 class LayerTreeHostScrollTestFractionalScroll : public LayerTreeHostScrollTest { 366 class LayerTreeHostScrollTestFractionalScroll : public LayerTreeHostScrollTest {
344 public: 367 public:
345 LayerTreeHostScrollTestFractionalScroll() : scroll_amount_(1.75, 0) {} 368 LayerTreeHostScrollTestFractionalScroll() : scroll_amount_(1.75, 0) {}
346 369
370 virtual void SetupTree() OVERRIDE {
371 LayerTreeHostScrollTest::SetupTree();
372 Layer* root_layer = layer_tree_host()->root_layer();
373 scoped_refptr<Layer> root_scroll_layer = Layer::Create();
374 root_scroll_layer->SetScrollClipLayer(root_layer);
375 root_scroll_layer->SetBounds(
376 gfx::Size(root_layer->bounds().width() + 100,
377 root_layer->bounds().height() + 100));
378 root_scroll_layer->SetIsDrawable(true);
379 root_scroll_layer->SetIsContainerForFixedPositionLayers(true);
380 root_layer->AddChild(root_scroll_layer);
381
382 layer_tree_host()->RegisterViewportLayers(
383 root_layer, root_scroll_layer, NULL);
384 layer_tree_host()->SetPageScaleFactorAndLimits(1.f, 0.01f, 100.f);
385 }
386
347 virtual void BeginTest() OVERRIDE { 387 virtual void BeginTest() OVERRIDE {
348 layer_tree_host()->root_layer()->SetScrollable(true);
349 layer_tree_host()->root_layer()
350 ->SetMaxScrollOffset(gfx::Vector2d(100, 100));
351 PostSetNeedsCommitToMainThread(); 388 PostSetNeedsCommitToMainThread();
352 } 389 }
353 390
354 virtual void DrawLayersOnThread(LayerTreeHostImpl* impl) OVERRIDE { 391 virtual void DrawLayersOnThread(LayerTreeHostImpl* impl) OVERRIDE {
355 LayerImpl* root = impl->active_tree()->root_layer(); 392 LayerImpl* root = impl->active_tree()->root_layer();
393 LayerImpl* scroll_layer = root->children()[0];
356 394
357 // Check that a fractional scroll delta is correctly accumulated over 395 // Check that a fractional scroll delta is correctly accumulated over
358 // multiple commits. 396 // multiple commits.
359 switch (impl->active_tree()->source_frame_number()) { 397 switch (impl->active_tree()->source_frame_number()) {
360 case 0: 398 case 0:
361 EXPECT_VECTOR_EQ(root->scroll_offset(), gfx::Vector2d(0, 0)); 399 EXPECT_VECTOR_EQ(scroll_layer->scroll_offset(), gfx::Vector2d(0, 0));
362 EXPECT_VECTOR_EQ(root->ScrollDelta(), gfx::Vector2d(0, 0)); 400 EXPECT_VECTOR_EQ(scroll_layer->ScrollDelta(), gfx::Vector2d(0, 0));
363 PostSetNeedsCommitToMainThread(); 401 PostSetNeedsCommitToMainThread();
364 break; 402 break;
365 case 1: 403 case 1:
366 EXPECT_VECTOR_EQ(root->scroll_offset(), 404 EXPECT_VECTOR_EQ(scroll_layer->scroll_offset(),
367 gfx::ToFlooredVector2d(scroll_amount_)); 405 gfx::ToFlooredVector2d(scroll_amount_));
368 EXPECT_VECTOR_EQ(root->ScrollDelta(), 406 EXPECT_VECTOR_EQ(scroll_layer->ScrollDelta(),
369 gfx::Vector2dF(fmod(scroll_amount_.x(), 1.0f), 0.0f)); 407 gfx::Vector2dF(fmod(scroll_amount_.x(), 1.0f), 0.0f));
370 PostSetNeedsCommitToMainThread(); 408 PostSetNeedsCommitToMainThread();
371 break; 409 break;
372 case 2: 410 case 2:
373 EXPECT_VECTOR_EQ( 411 EXPECT_VECTOR_EQ(
374 root->scroll_offset(), 412 scroll_layer->scroll_offset(),
375 gfx::ToFlooredVector2d(scroll_amount_ + scroll_amount_)); 413 gfx::ToFlooredVector2d(scroll_amount_ + scroll_amount_));
376 EXPECT_VECTOR_EQ( 414 EXPECT_VECTOR_EQ(
377 root->ScrollDelta(), 415 scroll_layer->ScrollDelta(),
378 gfx::Vector2dF(fmod(2.0f * scroll_amount_.x(), 1.0f), 0.0f)); 416 gfx::Vector2dF(fmod(2.0f * scroll_amount_.x(), 1.0f), 0.0f));
379 EndTest(); 417 EndTest();
380 break; 418 break;
381 } 419 }
382 root->ScrollBy(scroll_amount_); 420 scroll_layer->ScrollBy(scroll_amount_);
383 } 421 }
384 422
385 virtual void AfterTest() OVERRIDE {} 423 virtual void AfterTest() OVERRIDE {}
386 424
387 private: 425 private:
388 gfx::Vector2dF scroll_amount_; 426 gfx::Vector2dF scroll_amount_;
389 }; 427 };
390 428
391 MULTI_THREAD_TEST_F(LayerTreeHostScrollTestFractionalScroll); 429 MULTI_THREAD_TEST_F(LayerTreeHostScrollTestFractionalScroll);
392 430
(...skipping 11 matching lines...) Expand all
404 scoped_refptr<Layer> root_layer = Layer::Create(); 442 scoped_refptr<Layer> root_layer = Layer::Create();
405 root_layer->SetBounds(gfx::Size(10, 10)); 443 root_layer->SetBounds(gfx::Size(10, 10));
406 444
407 root_scroll_layer_ = ContentLayer::Create(&fake_content_layer_client_); 445 root_scroll_layer_ = ContentLayer::Create(&fake_content_layer_client_);
408 root_scroll_layer_->SetBounds(gfx::Size(110, 110)); 446 root_scroll_layer_->SetBounds(gfx::Size(110, 110));
409 447
410 root_scroll_layer_->SetPosition(gfx::Point()); 448 root_scroll_layer_->SetPosition(gfx::Point());
411 root_scroll_layer_->SetAnchorPoint(gfx::PointF()); 449 root_scroll_layer_->SetAnchorPoint(gfx::PointF());
412 450
413 root_scroll_layer_->SetIsDrawable(true); 451 root_scroll_layer_->SetIsDrawable(true);
414 root_scroll_layer_->SetScrollable(true); 452 root_scroll_layer_->SetScrollClipLayer(root_layer);
415 root_scroll_layer_->SetMaxScrollOffset(gfx::Vector2d(100, 100)); 453 root_scroll_layer_->SetIsContainerForFixedPositionLayers(true);
416 root_layer->AddChild(root_scroll_layer_); 454 root_layer->AddChild(root_scroll_layer_);
417 455
418 child_layer_ = ContentLayer::Create(&fake_content_layer_client_); 456 child_layer_ = ContentLayer::Create(&fake_content_layer_client_);
419 child_layer_->set_did_scroll_callback( 457 child_layer_->set_did_scroll_callback(
420 base::Bind(&LayerTreeHostScrollTestCaseWithChild::DidScroll, 458 base::Bind(&LayerTreeHostScrollTestCaseWithChild::DidScroll,
421 base::Unretained(this))); 459 base::Unretained(this)));
422 child_layer_->SetBounds(gfx::Size(110, 110)); 460 child_layer_->SetBounds(gfx::Size(110, 110));
423 461
424 if (scroll_child_layer_) { 462 if (scroll_child_layer_) {
425 // Scrolls on the child layer will happen at 5, 5. If they are treated 463 // Scrolls on the child layer will happen at 5, 5. If they are treated
426 // like device pixels, and device scale factor is 2, then they will 464 // like device pixels, and device scale factor is 2, then they will
427 // be considered at 2.5, 2.5 in logical pixels, and will miss this layer. 465 // be considered at 2.5, 2.5 in logical pixels, and will miss this layer.
428 child_layer_->SetPosition(gfx::Point(5, 5)); 466 child_layer_->SetPosition(gfx::Point(5, 5));
429 } else { 467 } else {
430 // Adjust the child layer horizontally so that scrolls will never hit it. 468 // Adjust the child layer horizontally so that scrolls will never hit it.
431 child_layer_->SetPosition(gfx::Point(60, 5)); 469 child_layer_->SetPosition(gfx::Point(60, 5));
432 } 470 }
433 child_layer_->SetAnchorPoint(gfx::PointF()); 471 child_layer_->SetAnchorPoint(gfx::PointF());
434 472
435 child_layer_->SetIsDrawable(true); 473 child_layer_->SetIsDrawable(true);
436 child_layer_->SetScrollable(true); 474 child_layer_->SetScrollClipLayer(root_layer);
437 child_layer_->SetMaxScrollOffset(gfx::Vector2d(100, 100)); 475 child_layer_->SetBounds(root_scroll_layer_->bounds());
438 root_scroll_layer_->AddChild(child_layer_); 476 root_scroll_layer_->AddChild(child_layer_);
439 477
440 if (scroll_child_layer_) { 478 if (scroll_child_layer_) {
441 expected_scroll_layer_ = child_layer_; 479 expected_scroll_layer_ = child_layer_;
442 expected_no_scroll_layer_ = root_scroll_layer_; 480 expected_no_scroll_layer_ = root_scroll_layer_;
443 } else { 481 } else {
444 expected_scroll_layer_ = root_scroll_layer_; 482 expected_scroll_layer_ = root_scroll_layer_;
445 expected_no_scroll_layer_ = child_layer_; 483 expected_no_scroll_layer_ = child_layer_;
446 } 484 }
447 485
448 expected_scroll_layer_->SetScrollOffset(initial_offset_); 486 expected_scroll_layer_->SetScrollOffset(initial_offset_);
449 487
450 layer_tree_host()->SetRootLayer(root_layer); 488 layer_tree_host()->SetRootLayer(root_layer);
489 layer_tree_host()->RegisterViewportLayers(
490 root_layer, root_scroll_layer_, NULL);
451 LayerTreeHostScrollTest::SetupTree(); 491 LayerTreeHostScrollTest::SetupTree();
452 } 492 }
453 493
454 virtual void BeginTest() OVERRIDE { PostSetNeedsCommitToMainThread(); } 494 virtual void BeginTest() OVERRIDE { PostSetNeedsCommitToMainThread(); }
455 495
456 virtual void WillCommit() OVERRIDE { 496 virtual void WillCommit() OVERRIDE {
457 // Keep the test committing (otherwise the early out for no update 497 // Keep the test committing (otherwise the early out for no update
458 // will stall the test). 498 // will stall the test).
459 if (layer_tree_host()->source_frame_number() < 2) { 499 if (layer_tree_host()->source_frame_number() < 2) {
460 layer_tree_host()->SetNeedsCommit(); 500 layer_tree_host()->SetNeedsCommit();
(...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after
717 757
718 class ImplSidePaintingScrollTestSimple : public ImplSidePaintingScrollTest { 758 class ImplSidePaintingScrollTestSimple : public ImplSidePaintingScrollTest {
719 public: 759 public:
720 ImplSidePaintingScrollTestSimple() 760 ImplSidePaintingScrollTestSimple()
721 : initial_scroll_(10, 20), 761 : initial_scroll_(10, 20),
722 main_thread_scroll_(40, 5), 762 main_thread_scroll_(40, 5),
723 impl_thread_scroll1_(2, -1), 763 impl_thread_scroll1_(2, -1),
724 impl_thread_scroll2_(-3, 10), 764 impl_thread_scroll2_(-3, 10),
725 num_scrolls_(0) {} 765 num_scrolls_(0) {}
726 766
767 virtual void SetupTree() OVERRIDE {
768 LayerTreeHostScrollTest::SetupTree();
769 Layer* root_layer = layer_tree_host()->root_layer();
770 scoped_refptr<Layer> root_scroll_layer = Layer::Create();
771 root_scroll_layer->SetScrollClipLayer(root_layer);
772 root_scroll_layer->SetScrollOffset(initial_scroll_);
773 root_scroll_layer->SetBounds(
774 gfx::Size(root_layer->bounds().width() + 100,
775 root_layer->bounds().height() + 100));
776 root_scroll_layer->SetIsDrawable(true);
777 root_scroll_layer->SetIsContainerForFixedPositionLayers(true);
778 root_layer->AddChild(root_scroll_layer);
779
780 layer_tree_host()->RegisterViewportLayers(
781 root_layer, root_scroll_layer, NULL);
782 layer_tree_host()->SetPageScaleFactorAndLimits(1.f, 0.01f, 100.f);
783 }
784
727 virtual void BeginTest() OVERRIDE { 785 virtual void BeginTest() OVERRIDE {
728 layer_tree_host()->root_layer()->SetScrollable(true);
729 layer_tree_host()->root_layer()
730 ->SetMaxScrollOffset(gfx::Vector2d(100, 100));
731 layer_tree_host()->root_layer()->SetScrollOffset(initial_scroll_);
732 PostSetNeedsCommitToMainThread(); 786 PostSetNeedsCommitToMainThread();
733 } 787 }
734 788
735 virtual void Layout() OVERRIDE { 789 virtual void Layout() OVERRIDE {
736 Layer* root = layer_tree_host()->root_layer(); 790 Layer* root = layer_tree_host()->root_layer();
791 Layer* scroll_layer = root->children()[0];
737 if (!layer_tree_host()->source_frame_number()) { 792 if (!layer_tree_host()->source_frame_number()) {
738 EXPECT_VECTOR_EQ(root->scroll_offset(), initial_scroll_); 793 EXPECT_VECTOR_EQ(scroll_layer->scroll_offset(), initial_scroll_);
739 } else { 794 } else {
740 EXPECT_VECTOR_EQ(root->scroll_offset(), 795 EXPECT_VECTOR_EQ(scroll_layer->scroll_offset(),
741 initial_scroll_ + impl_thread_scroll1_); 796 initial_scroll_ + impl_thread_scroll1_);
742 797
743 // Pretend like Javascript updated the scroll position itself with a 798 // Pretend like Javascript updated the scroll position itself with a
744 // change of main_thread_scroll. 799 // change of main_thread_scroll.
745 root->SetScrollOffset(initial_scroll_ + main_thread_scroll_ + 800 scroll_layer->SetScrollOffset(initial_scroll_ + main_thread_scroll_ +
746 impl_thread_scroll1_); 801 impl_thread_scroll1_);
747 } 802 }
748 } 803 }
749 804
750 virtual void CommitCompleteOnThread(LayerTreeHostImpl* impl) OVERRIDE { 805 virtual void CommitCompleteOnThread(LayerTreeHostImpl* impl) OVERRIDE {
751 // We force a second draw here of the first commit before activating 806 // We force a second draw here of the first commit before activating
752 // the second commit. 807 // the second commit.
753 if (impl->active_tree()->source_frame_number() == 0) 808 if (impl->active_tree()->source_frame_number() == 0)
754 impl->SetNeedsRedraw(); 809 impl->SetNeedsRedraw();
755 } 810 }
756 811
757 virtual void DrawLayersOnThread(LayerTreeHostImpl* impl) OVERRIDE { 812 virtual void DrawLayersOnThread(LayerTreeHostImpl* impl) OVERRIDE {
758 ImplSidePaintingScrollTest::DrawLayersOnThread(impl); 813 ImplSidePaintingScrollTest::DrawLayersOnThread(impl);
759 814
760 LayerImpl* root = impl->active_tree()->root_layer(); 815 LayerImpl* root = impl->active_tree()->root_layer();
816 LayerImpl* scroll_layer = root->children()[0];
761 LayerImpl* pending_root = 817 LayerImpl* pending_root =
762 impl->active_tree()->FindPendingTreeLayerById(root->id()); 818 impl->active_tree()->FindPendingTreeLayerById(root->id());
763 819
764 switch (impl->active_tree()->source_frame_number()) { 820 switch (impl->active_tree()->source_frame_number()) {
765 case 0: 821 case 0:
766 if (!impl->pending_tree()) { 822 if (!impl->pending_tree()) {
767 impl->BlockNotifyReadyToActivateForTesting(true); 823 impl->BlockNotifyReadyToActivateForTesting(true);
768 EXPECT_VECTOR_EQ(root->ScrollDelta(), gfx::Vector2d()); 824 EXPECT_VECTOR_EQ(scroll_layer->ScrollDelta(), gfx::Vector2d());
769 root->ScrollBy(impl_thread_scroll1_); 825 scroll_layer->ScrollBy(impl_thread_scroll1_);
770 826
771 EXPECT_VECTOR_EQ(root->scroll_offset(), initial_scroll_); 827 EXPECT_VECTOR_EQ(scroll_layer->scroll_offset(), initial_scroll_);
772 EXPECT_VECTOR_EQ(root->ScrollDelta(), impl_thread_scroll1_); 828 EXPECT_VECTOR_EQ(scroll_layer->ScrollDelta(), impl_thread_scroll1_);
773 EXPECT_VECTOR_EQ(root->sent_scroll_delta(), gfx::Vector2d()); 829 EXPECT_VECTOR_EQ(scroll_layer->sent_scroll_delta(), gfx::Vector2d());
774 PostSetNeedsCommitToMainThread(); 830 PostSetNeedsCommitToMainThread();
775 831
776 // CommitCompleteOnThread will trigger this function again 832 // CommitCompleteOnThread will trigger this function again
777 // and cause us to take the else clause. 833 // and cause us to take the else clause.
778 } else { 834 } else {
779 impl->BlockNotifyReadyToActivateForTesting(false); 835 impl->BlockNotifyReadyToActivateForTesting(false);
780 ASSERT_TRUE(pending_root); 836 ASSERT_TRUE(pending_root);
781 EXPECT_EQ(impl->pending_tree()->source_frame_number(), 1); 837 EXPECT_EQ(impl->pending_tree()->source_frame_number(), 1);
782 838
783 root->ScrollBy(impl_thread_scroll2_); 839 scroll_layer->ScrollBy(impl_thread_scroll2_);
784 EXPECT_VECTOR_EQ(root->scroll_offset(), initial_scroll_); 840 EXPECT_VECTOR_EQ(scroll_layer->scroll_offset(), initial_scroll_);
785 EXPECT_VECTOR_EQ(root->ScrollDelta(), 841 EXPECT_VECTOR_EQ(scroll_layer->ScrollDelta(),
786 impl_thread_scroll1_ + impl_thread_scroll2_); 842 impl_thread_scroll1_ + impl_thread_scroll2_);
787 EXPECT_VECTOR_EQ(root->sent_scroll_delta(), impl_thread_scroll1_); 843 EXPECT_VECTOR_EQ(scroll_layer->sent_scroll_delta(),
844 impl_thread_scroll1_);
788 845
846 LayerImpl* pending_scroll_layer = pending_root->children()[0];
789 EXPECT_VECTOR_EQ( 847 EXPECT_VECTOR_EQ(
790 pending_root->scroll_offset(), 848 pending_scroll_layer->scroll_offset(),
791 initial_scroll_ + main_thread_scroll_ + impl_thread_scroll1_); 849 initial_scroll_ + main_thread_scroll_ + impl_thread_scroll1_);
792 EXPECT_VECTOR_EQ(pending_root->ScrollDelta(), impl_thread_scroll2_); 850 EXPECT_VECTOR_EQ(pending_scroll_layer->ScrollDelta(),
793 EXPECT_VECTOR_EQ(pending_root->sent_scroll_delta(), gfx::Vector2d()); 851 impl_thread_scroll2_);
852 EXPECT_VECTOR_EQ(pending_scroll_layer->sent_scroll_delta(),
853 gfx::Vector2d());
794 } 854 }
795 break; 855 break;
796 case 1: 856 case 1:
797 EXPECT_FALSE(impl->pending_tree()); 857 EXPECT_FALSE(impl->pending_tree());
798 EXPECT_VECTOR_EQ( 858 EXPECT_VECTOR_EQ(
799 root->scroll_offset(), 859 scroll_layer->scroll_offset(),
800 initial_scroll_ + main_thread_scroll_ + impl_thread_scroll1_); 860 initial_scroll_ + main_thread_scroll_ + impl_thread_scroll1_);
801 EXPECT_VECTOR_EQ(root->ScrollDelta(), impl_thread_scroll2_); 861 EXPECT_VECTOR_EQ(scroll_layer->ScrollDelta(), impl_thread_scroll2_);
802 EXPECT_VECTOR_EQ(root->sent_scroll_delta(), gfx::Vector2d()); 862 EXPECT_VECTOR_EQ(scroll_layer->sent_scroll_delta(), gfx::Vector2d());
803 EndTest(); 863 EndTest();
804 break; 864 break;
805 } 865 }
806 } 866 }
807 867
808 virtual void ApplyScrollAndScale(gfx::Vector2d scroll_delta, 868 virtual void ApplyScrollAndScale(gfx::Vector2d scroll_delta,
809 float scale) OVERRIDE { 869 float scale) OVERRIDE {
810 num_scrolls_++; 870 num_scrolls_++;
811 } 871 }
812 872
(...skipping 12 matching lines...) Expand all
825 // This test makes sure that layers pick up scrolls that occur between 885 // This test makes sure that layers pick up scrolls that occur between
826 // beginning a commit and finishing a commit (aka scroll deltas not 886 // beginning a commit and finishing a commit (aka scroll deltas not
827 // included in sent scroll delta) still apply to layers that don't 887 // included in sent scroll delta) still apply to layers that don't
828 // push properties. 888 // push properties.
829 class ImplSidePaintingScrollTestImplOnlyScroll 889 class ImplSidePaintingScrollTestImplOnlyScroll
830 : public ImplSidePaintingScrollTest { 890 : public ImplSidePaintingScrollTest {
831 public: 891 public:
832 ImplSidePaintingScrollTestImplOnlyScroll() 892 ImplSidePaintingScrollTestImplOnlyScroll()
833 : initial_scroll_(20, 10), impl_thread_scroll_(-2, 3) {} 893 : initial_scroll_(20, 10), impl_thread_scroll_(-2, 3) {}
834 894
895 virtual void SetupTree() OVERRIDE {
896 LayerTreeHostScrollTest::SetupTree();
897 Layer* root_layer = layer_tree_host()->root_layer();
898 scoped_refptr<Layer> root_scroll_layer = Layer::Create();
899 root_scroll_layer->SetScrollClipLayer(root_layer);
900 root_scroll_layer->SetScrollOffset(initial_scroll_);
901 root_scroll_layer->SetBounds(
902 gfx::Size(root_layer->bounds().width() + 100,
903 root_layer->bounds().height() + 100));
904 root_scroll_layer->SetIsDrawable(true);
905 root_scroll_layer->SetIsContainerForFixedPositionLayers(true);
906 root_layer->AddChild(root_scroll_layer);
907
908 layer_tree_host()->RegisterViewportLayers(
909 root_layer, root_scroll_layer, NULL);
910 layer_tree_host()->SetPageScaleFactorAndLimits(1.f, 0.01f, 100.f);
911 }
912
835 virtual void BeginTest() OVERRIDE { 913 virtual void BeginTest() OVERRIDE {
836 layer_tree_host()->root_layer()->SetScrollable(true);
837 layer_tree_host()->root_layer()->SetMaxScrollOffset(
838 gfx::Vector2d(100, 100));
839 layer_tree_host()->root_layer()->SetScrollOffset(initial_scroll_);
840 PostSetNeedsCommitToMainThread(); 914 PostSetNeedsCommitToMainThread();
841 } 915 }
842 916
843 virtual void WillCommit() OVERRIDE { 917 virtual void WillCommit() OVERRIDE {
844 Layer* root = layer_tree_host()->root_layer(); 918 Layer* root = layer_tree_host()->root_layer();
919 Layer* scroll_layer = root->children()[0];
845 switch (layer_tree_host()->source_frame_number()) { 920 switch (layer_tree_host()->source_frame_number()) {
846 case 0: 921 case 0:
847 EXPECT_TRUE(root->needs_push_properties()); 922 EXPECT_TRUE(scroll_layer->needs_push_properties());
848 break; 923 break;
849 case 1: 924 case 1:
850 // Even if this layer doesn't need push properties, it should 925 // Even if this layer doesn't need push properties, it should
851 // still pick up scrolls that happen on the active layer during 926 // still pick up scrolls that happen on the active layer during
852 // commit. 927 // commit.
853 EXPECT_FALSE(root->needs_push_properties()); 928 EXPECT_FALSE(scroll_layer->needs_push_properties());
854 break; 929 break;
855 } 930 }
856 } 931 }
857 932
858 virtual void BeginCommitOnThread(LayerTreeHostImpl* impl) OVERRIDE { 933 virtual void BeginCommitOnThread(LayerTreeHostImpl* impl) OVERRIDE {
859 // Scroll after the 2nd commit has started. 934 // Scroll after the 2nd commit has started.
860 if (impl->active_tree()->source_frame_number() == 0) { 935 if (impl->active_tree()->source_frame_number() == 0) {
861 LayerImpl* active_root = impl->active_tree()->root_layer(); 936 LayerImpl* active_root = impl->active_tree()->root_layer();
937 LayerImpl* active_scroll_layer = active_root->children()[0];
862 ASSERT_TRUE(active_root); 938 ASSERT_TRUE(active_root);
863 active_root->ScrollBy(impl_thread_scroll_); 939 ASSERT_TRUE(active_scroll_layer);
940 active_scroll_layer->ScrollBy(impl_thread_scroll_);
864 } 941 }
865 } 942 }
866 943
867 virtual void CommitCompleteOnThread(LayerTreeHostImpl* impl) OVERRIDE { 944 virtual void CommitCompleteOnThread(LayerTreeHostImpl* impl) OVERRIDE {
868 // We force a second draw here of the first commit before activating 945 // We force a second draw here of the first commit before activating
869 // the second commit. 946 // the second commit.
870 LayerImpl* active_root = impl->active_tree()->root_layer(); 947 LayerImpl* active_root = impl->active_tree()->root_layer();
948 LayerImpl* active_scroll_layer =
949 active_root ? active_root->children()[0] : NULL;
871 LayerImpl* pending_root = impl->pending_tree()->root_layer(); 950 LayerImpl* pending_root = impl->pending_tree()->root_layer();
951 LayerImpl* pending_scroll_layer = pending_root->children()[0];
872 952
873 ASSERT_TRUE(pending_root); 953 ASSERT_TRUE(pending_root);
954 ASSERT_TRUE(pending_scroll_layer);
874 switch (impl->pending_tree()->source_frame_number()) { 955 switch (impl->pending_tree()->source_frame_number()) {
875 case 0: 956 case 0:
876 EXPECT_VECTOR_EQ(pending_root->scroll_offset(), initial_scroll_); 957 EXPECT_VECTOR_EQ(pending_scroll_layer->scroll_offset(),
877 EXPECT_VECTOR_EQ(pending_root->ScrollDelta(), gfx::Vector2d()); 958 initial_scroll_);
878 EXPECT_VECTOR_EQ(pending_root->sent_scroll_delta(), gfx::Vector2d()); 959 EXPECT_VECTOR_EQ(pending_scroll_layer->ScrollDelta(), gfx::Vector2d());
960 EXPECT_VECTOR_EQ(pending_scroll_layer->sent_scroll_delta(),
961 gfx::Vector2d());
879 EXPECT_FALSE(active_root); 962 EXPECT_FALSE(active_root);
880 break; 963 break;
881 case 1: 964 case 1:
882 // Even though the scroll happened during the commit, both layers 965 // Even though the scroll happened during the commit, both layers
883 // should have the appropriate scroll delta. 966 // should have the appropriate scroll delta.
884 EXPECT_VECTOR_EQ(pending_root->scroll_offset(), initial_scroll_); 967 EXPECT_VECTOR_EQ(pending_scroll_layer->scroll_offset(),
885 EXPECT_VECTOR_EQ(pending_root->ScrollDelta(), impl_thread_scroll_); 968 initial_scroll_);
886 EXPECT_VECTOR_EQ(pending_root->sent_scroll_delta(), gfx::Vector2d()); 969 EXPECT_VECTOR_EQ(pending_scroll_layer->ScrollDelta(),
970 impl_thread_scroll_);
971 EXPECT_VECTOR_EQ(pending_scroll_layer->sent_scroll_delta(),
972 gfx::Vector2d());
887 ASSERT_TRUE(active_root); 973 ASSERT_TRUE(active_root);
888 EXPECT_VECTOR_EQ(active_root->scroll_offset(), initial_scroll_); 974 EXPECT_VECTOR_EQ(active_scroll_layer->scroll_offset(), initial_scroll_);
889 EXPECT_VECTOR_EQ(active_root->ScrollDelta(), impl_thread_scroll_); 975 EXPECT_VECTOR_EQ(active_scroll_layer->ScrollDelta(),
890 EXPECT_VECTOR_EQ(active_root->sent_scroll_delta(), gfx::Vector2d()); 976 impl_thread_scroll_);
977 EXPECT_VECTOR_EQ(active_scroll_layer->sent_scroll_delta(),
978 gfx::Vector2d());
891 break; 979 break;
892 case 2: 980 case 2:
893 // On the next commit, this delta should have been sent and applied. 981 // On the next commit, this delta should have been sent and applied.
894 EXPECT_VECTOR_EQ(pending_root->scroll_offset(), 982 EXPECT_VECTOR_EQ(pending_scroll_layer->scroll_offset(),
895 initial_scroll_ + impl_thread_scroll_); 983 initial_scroll_ + impl_thread_scroll_);
896 EXPECT_VECTOR_EQ(pending_root->ScrollDelta(), gfx::Vector2d()); 984 EXPECT_VECTOR_EQ(pending_scroll_layer->ScrollDelta(), gfx::Vector2d());
897 EXPECT_VECTOR_EQ(pending_root->sent_scroll_delta(), gfx::Vector2d()); 985 EXPECT_VECTOR_EQ(pending_scroll_layer->sent_scroll_delta(),
986 gfx::Vector2d());
898 EndTest(); 987 EndTest();
899 break; 988 break;
900 } 989 }
901 } 990 }
902 991
903 virtual void DrawLayersOnThread(LayerTreeHostImpl* impl) OVERRIDE { 992 virtual void DrawLayersOnThread(LayerTreeHostImpl* impl) OVERRIDE {
904 ImplSidePaintingScrollTest::DrawLayersOnThread(impl); 993 ImplSidePaintingScrollTest::DrawLayersOnThread(impl);
905 994
906 LayerImpl* root = impl->active_tree()->root_layer(); 995 LayerImpl* root = impl->active_tree()->root_layer();
996 LayerImpl* scroll_layer = root->children()[0];
907 997
908 switch (impl->active_tree()->source_frame_number()) { 998 switch (impl->active_tree()->source_frame_number()) {
909 case 0: 999 case 0:
910 EXPECT_VECTOR_EQ(root->scroll_offset(), initial_scroll_); 1000 EXPECT_VECTOR_EQ(scroll_layer->scroll_offset(), initial_scroll_);
911 EXPECT_VECTOR_EQ(root->ScrollDelta(), gfx::Vector2d()); 1001 EXPECT_VECTOR_EQ(scroll_layer->ScrollDelta(), gfx::Vector2d());
912 EXPECT_VECTOR_EQ(root->sent_scroll_delta(), gfx::Vector2d()); 1002 EXPECT_VECTOR_EQ(scroll_layer->sent_scroll_delta(), gfx::Vector2d());
913 PostSetNeedsCommitToMainThread(); 1003 PostSetNeedsCommitToMainThread();
914 break; 1004 break;
915 case 1: 1005 case 1:
916 EXPECT_VECTOR_EQ(root->scroll_offset(), initial_scroll_); 1006 EXPECT_VECTOR_EQ(scroll_layer->scroll_offset(), initial_scroll_);
917 EXPECT_VECTOR_EQ(root->ScrollDelta(), impl_thread_scroll_); 1007 EXPECT_VECTOR_EQ(scroll_layer->ScrollDelta(), impl_thread_scroll_);
918 EXPECT_VECTOR_EQ(root->sent_scroll_delta(), gfx::Vector2d()); 1008 EXPECT_VECTOR_EQ(scroll_layer->sent_scroll_delta(), gfx::Vector2d());
919 PostSetNeedsCommitToMainThread(); 1009 PostSetNeedsCommitToMainThread();
920 break; 1010 break;
921 } 1011 }
922 } 1012 }
923 1013
924 virtual void AfterTest() OVERRIDE {} 1014 virtual void AfterTest() OVERRIDE {}
925 1015
926 private: 1016 private:
927 gfx::Vector2d initial_scroll_; 1017 gfx::Vector2d initial_scroll_;
928 gfx::Vector2d impl_thread_scroll_; 1018 gfx::Vector2d impl_thread_scroll_;
929 }; 1019 };
930 1020
931 MULTI_THREAD_TEST_F(ImplSidePaintingScrollTestImplOnlyScroll); 1021 MULTI_THREAD_TEST_F(ImplSidePaintingScrollTestImplOnlyScroll);
932 1022
933 class LayerTreeHostScrollTestScrollZeroMaxScrollOffset 1023 class LayerTreeHostScrollTestScrollZeroMaxScrollOffset
934 : public LayerTreeHostScrollTest { 1024 : public LayerTreeHostScrollTest {
935 public: 1025 public:
936 LayerTreeHostScrollTestScrollZeroMaxScrollOffset() {} 1026 LayerTreeHostScrollTestScrollZeroMaxScrollOffset() {}
937 1027
1028 virtual void SetupTree() OVERRIDE {
1029 LayerTreeTest::SetupTree();
1030 scoped_refptr<Layer> scroll_layer = Layer::Create();
1031 layer_tree_host()->root_layer()->AddChild(scroll_layer);
1032 }
1033
938 virtual void BeginTest() OVERRIDE { PostSetNeedsCommitToMainThread(); } 1034 virtual void BeginTest() OVERRIDE { PostSetNeedsCommitToMainThread(); }
939 1035
940 virtual void DrawLayersOnThread(LayerTreeHostImpl* impl) OVERRIDE { 1036 virtual void DrawLayersOnThread(LayerTreeHostImpl* impl) OVERRIDE {
941 LayerImpl* root = impl->active_tree()->root_layer(); 1037 LayerImpl* root = impl->active_tree()->root_layer();
942 root->SetScrollable(true); 1038 LayerImpl* scroll_layer = root->children()[0];
1039 scroll_layer->SetScrollClipLayer(root->id());
943 1040
944 root->SetMaxScrollOffset(gfx::Vector2d(100, 100)); 1041 // Set max_scroll_offset = (100, 100).
1042 scroll_layer->SetBounds(
1043 gfx::Size(root->bounds().width() + 100, root->bounds().height() + 100));
945 EXPECT_EQ(InputHandler::ScrollStarted, 1044 EXPECT_EQ(InputHandler::ScrollStarted,
946 root->TryScroll(gfx::PointF(0.0f, 1.0f), InputHandler::Gesture)); 1045 scroll_layer->TryScroll(gfx::PointF(0.0f, 1.0f),
1046 InputHandler::Gesture));
947 1047
948 root->SetMaxScrollOffset(gfx::Vector2d(0, 0)); 1048 // Set max_scroll_offset = (0, 0).
1049 scroll_layer->SetBounds(root->bounds());
949 EXPECT_EQ(InputHandler::ScrollIgnored, 1050 EXPECT_EQ(InputHandler::ScrollIgnored,
950 root->TryScroll(gfx::PointF(0.0f, 1.0f), InputHandler::Gesture)); 1051 scroll_layer->TryScroll(gfx::PointF(0.0f, 1.0f),
1052 InputHandler::Gesture));
951 1053
952 root->SetMaxScrollOffset(gfx::Vector2d(-100, -100)); 1054 // Set max_scroll_offset = (-100, -100).
1055 scroll_layer->SetBounds(gfx::Size());
953 EXPECT_EQ(InputHandler::ScrollIgnored, 1056 EXPECT_EQ(InputHandler::ScrollIgnored,
954 root->TryScroll(gfx::PointF(0.0f, 1.0f), InputHandler::Gesture)); 1057 scroll_layer->TryScroll(gfx::PointF(0.0f, 1.0f),
1058 InputHandler::Gesture));
955 1059
956 EndTest(); 1060 EndTest();
957 } 1061 }
958 1062
959 virtual void AfterTest() OVERRIDE {} 1063 virtual void AfterTest() OVERRIDE {}
960 }; 1064 };
961 1065
962 SINGLE_AND_MULTI_THREAD_TEST_F( 1066 SINGLE_AND_MULTI_THREAD_TEST_F(
963 LayerTreeHostScrollTestScrollZeroMaxScrollOffset); 1067 LayerTreeHostScrollTestScrollZeroMaxScrollOffset);
964 1068
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
1086 Layer* layer_; 1190 Layer* layer_;
1087 }; 1191 };
1088 1192
1089 Layer* CreateScrollLayer(Layer* parent, FakeLayerScrollClient* client) { 1193 Layer* CreateScrollLayer(Layer* parent, FakeLayerScrollClient* client) {
1090 scoped_refptr<Layer> scroll_layer = 1194 scoped_refptr<Layer> scroll_layer =
1091 ContentLayer::Create(&fake_content_layer_client_); 1195 ContentLayer::Create(&fake_content_layer_client_);
1092 scroll_layer->SetBounds(gfx::Size(110, 110)); 1196 scroll_layer->SetBounds(gfx::Size(110, 110));
1093 scroll_layer->SetPosition(gfx::Point(0, 0)); 1197 scroll_layer->SetPosition(gfx::Point(0, 0));
1094 scroll_layer->SetAnchorPoint(gfx::PointF()); 1198 scroll_layer->SetAnchorPoint(gfx::PointF());
1095 scroll_layer->SetIsDrawable(true); 1199 scroll_layer->SetIsDrawable(true);
1096 scroll_layer->SetScrollable(true); 1200 scroll_layer->SetScrollClipLayer(parent);
1097 scroll_layer->SetMaxScrollOffset(gfx::Vector2d(100, 100)); 1201 scroll_layer->SetBounds(gfx::Size(parent->bounds().width() + 100,
1202 parent->bounds().height() + 100));
1098 scroll_layer->set_did_scroll_callback(base::Bind( 1203 scroll_layer->set_did_scroll_callback(base::Bind(
1099 &FakeLayerScrollClient::DidScroll, base::Unretained(client))); 1204 &FakeLayerScrollClient::DidScroll, base::Unretained(client)));
1100 client->owner_ = this; 1205 client->owner_ = this;
1101 client->layer_ = scroll_layer.get(); 1206 client->layer_ = scroll_layer.get();
1102 parent->AddChild(scroll_layer); 1207 parent->AddChild(scroll_layer);
1103 return scroll_layer.get(); 1208 return scroll_layer.get();
1104 } 1209 }
1105 1210
1106 FakeLayerScrollClient root_scroll_layer_client_; 1211 FakeLayerScrollClient root_scroll_layer_client_;
1107 FakeLayerScrollClient sibling_scroll_layer_client_; 1212 FakeLayerScrollClient sibling_scroll_layer_client_;
1108 FakeLayerScrollClient child_scroll_layer_client_; 1213 FakeLayerScrollClient child_scroll_layer_client_;
1109 1214
1110 FakeContentLayerClient fake_content_layer_client_; 1215 FakeContentLayerClient fake_content_layer_client_;
1111 1216
1112 bool scroll_destroy_whole_tree_; 1217 bool scroll_destroy_whole_tree_;
1113 }; 1218 };
1114 1219
1115 TEST_F(LayerTreeHostScrollTestLayerStructureChange, ScrollDestroyLayer) { 1220 TEST_F(LayerTreeHostScrollTestLayerStructureChange, ScrollDestroyLayer) {
1116 RunTest(true, false, false); 1221 RunTest(true, false, false);
1117 } 1222 }
1118 1223
1119 TEST_F(LayerTreeHostScrollTestLayerStructureChange, ScrollDestroyWholeTree) { 1224 TEST_F(LayerTreeHostScrollTestLayerStructureChange, ScrollDestroyWholeTree) {
1120 scroll_destroy_whole_tree_ = true; 1225 scroll_destroy_whole_tree_ = true;
1121 RunTest(true, false, false); 1226 RunTest(true, false, false);
1122 } 1227 }
1123 1228
1124 } // namespace 1229 } // namespace
1125 } // namespace cc 1230 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698