Fix build break
[chromium-blink-merge.git] / cc / trees / layer_tree_host_unittest_scroll.cc
blob76a369b9aa9048ec6934d9105b631acd4e17fd14
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
3 // found in the LICENSE file.
5 #include "cc/trees/layer_tree_host.h"
7 #include "cc/layers/content_layer.h"
8 #include "cc/layers/layer.h"
9 #include "cc/layers/layer_impl.h"
10 #include "cc/test/fake_content_layer_client.h"
11 #include "cc/test/geometry_test_utils.h"
12 #include "cc/test/layer_tree_test.h"
13 #include "cc/trees/layer_tree_impl.h"
14 #include "third_party/WebKit/Source/Platform/chromium/public/WebLayerScrollClient.h"
15 #include "ui/gfx/point_conversions.h"
16 #include "ui/gfx/size_conversions.h"
17 #include "ui/gfx/vector2d_conversions.h"
19 namespace cc {
20 namespace {
22 class LayerTreeHostScrollTest : public LayerTreeTest {};
24 class LayerTreeHostScrollTestScrollSimple : public LayerTreeHostScrollTest {
25 public:
26 LayerTreeHostScrollTestScrollSimple()
27 : initial_scroll_(10, 20),
28 second_scroll_(40, 5),
29 scroll_amount_(2, -1),
30 num_scrolls_(0) {
33 virtual void BeginTest() OVERRIDE {
34 layer_tree_host()->root_layer()->SetScrollable(true);
35 layer_tree_host()->root_layer()->SetScrollOffset(initial_scroll_);
36 PostSetNeedsCommitToMainThread();
39 virtual void Layout() OVERRIDE {
40 Layer* root = layer_tree_host()->root_layer();
41 if (!layer_tree_host()->commit_number()) {
42 EXPECT_VECTOR_EQ(initial_scroll_, root->scroll_offset());
43 } else {
44 EXPECT_VECTOR_EQ(initial_scroll_ + scroll_amount_, root->scroll_offset());
46 // Pretend like Javascript updated the scroll position itself.
47 root->SetScrollOffset(second_scroll_);
51 virtual void DrawLayersOnThread(LayerTreeHostImpl* impl) OVERRIDE {
52 LayerImpl* root = impl->active_tree()->root_layer();
53 EXPECT_VECTOR_EQ(gfx::Vector2d(), root->scroll_delta());
55 root->SetScrollable(true);
56 root->SetMaxScrollOffset(gfx::Vector2d(100, 100));
57 root->ScrollBy(scroll_amount_);
59 switch (impl->active_tree()->source_frame_number()) {
60 case 0:
61 EXPECT_VECTOR_EQ(initial_scroll_, root->scroll_offset());
62 EXPECT_VECTOR_EQ(scroll_amount_, root->scroll_delta());
63 PostSetNeedsCommitToMainThread();
64 break;
65 case 1:
66 EXPECT_VECTOR_EQ(root->scroll_offset(), second_scroll_);
67 EXPECT_VECTOR_EQ(root->scroll_delta(), scroll_amount_);
68 EndTest();
69 break;
73 virtual void ApplyScrollAndScale(
74 gfx::Vector2d scroll_delta, float scale) OVERRIDE {
75 gfx::Vector2d offset = layer_tree_host()->root_layer()->scroll_offset();
76 layer_tree_host()->root_layer()->SetScrollOffset(offset + scroll_delta);
77 num_scrolls_++;
80 virtual void AfterTest() OVERRIDE {
81 EXPECT_EQ(1, num_scrolls_);
84 private:
85 gfx::Vector2d initial_scroll_;
86 gfx::Vector2d second_scroll_;
87 gfx::Vector2d scroll_amount_;
88 int num_scrolls_;
91 MULTI_THREAD_TEST_F(LayerTreeHostScrollTestScrollSimple);
93 class LayerTreeHostScrollTestScrollMultipleRedraw
94 : public LayerTreeHostScrollTest {
95 public:
96 LayerTreeHostScrollTestScrollMultipleRedraw()
97 : initial_scroll_(40, 10),
98 scroll_amount_(-3, 17),
99 num_scrolls_(0) {
102 virtual void BeginTest() OVERRIDE {
103 layer_tree_host()->root_layer()->SetScrollable(true);
104 layer_tree_host()->root_layer()->SetScrollOffset(initial_scroll_);
105 PostSetNeedsCommitToMainThread();
108 virtual void BeginCommitOnThread(LayerTreeHostImpl* impl) OVERRIDE {
109 Layer* root = layer_tree_host()->root_layer();
110 switch (layer_tree_host()->commit_number()) {
111 case 0:
112 EXPECT_VECTOR_EQ(root->scroll_offset(), initial_scroll_);
113 break;
114 case 1:
115 EXPECT_VECTOR_EQ(
116 root->scroll_offset(),
117 initial_scroll_ + scroll_amount_ + scroll_amount_);
118 case 2:
119 EXPECT_VECTOR_EQ(
120 root->scroll_offset(),
121 initial_scroll_ + scroll_amount_ + scroll_amount_);
122 break;
126 virtual void DrawLayersOnThread(LayerTreeHostImpl* impl) OVERRIDE {
127 LayerImpl* root = impl->active_tree()->root_layer();
128 root->SetScrollable(true);
129 root->SetMaxScrollOffset(gfx::Vector2d(100, 100));
131 if (impl->active_tree()->source_frame_number() == 0 &&
132 impl->SourceAnimationFrameNumber() == 1) {
133 // First draw after first commit.
134 EXPECT_VECTOR_EQ(root->scroll_delta(), gfx::Vector2d());
135 root->ScrollBy(scroll_amount_);
136 EXPECT_VECTOR_EQ(root->scroll_delta(), scroll_amount_);
138 EXPECT_VECTOR_EQ(root->scroll_offset(), initial_scroll_);
139 PostSetNeedsRedrawToMainThread();
140 } else if (impl->active_tree()->source_frame_number() == 0 &&
141 impl->SourceAnimationFrameNumber() == 2) {
142 // Second draw after first commit.
143 EXPECT_EQ(root->scroll_delta(), scroll_amount_);
144 root->ScrollBy(scroll_amount_);
145 EXPECT_VECTOR_EQ(root->scroll_delta(), scroll_amount_ + scroll_amount_);
147 EXPECT_VECTOR_EQ(root->scroll_offset(), initial_scroll_);
148 PostSetNeedsCommitToMainThread();
149 } else if (impl->active_tree()->source_frame_number() == 1) {
150 // Third or later draw after second commit.
151 EXPECT_GE(impl->SourceAnimationFrameNumber(), 3);
152 EXPECT_VECTOR_EQ(root->scroll_delta(), gfx::Vector2d());
153 EXPECT_VECTOR_EQ(
154 root->scroll_offset(),
155 initial_scroll_ + scroll_amount_ + scroll_amount_);
156 EndTest();
160 virtual void ApplyScrollAndScale(
161 gfx::Vector2d scroll_delta, float scale) OVERRIDE {
162 gfx::Vector2d offset = layer_tree_host()->root_layer()->scroll_offset();
163 layer_tree_host()->root_layer()->SetScrollOffset(offset + scroll_delta);
164 num_scrolls_++;
167 virtual void AfterTest() OVERRIDE {
168 EXPECT_EQ(1, num_scrolls_);
170 private:
171 gfx::Vector2d initial_scroll_;
172 gfx::Vector2d scroll_amount_;
173 int num_scrolls_;
176 MULTI_THREAD_TEST_F(LayerTreeHostScrollTestScrollMultipleRedraw);
178 class LayerTreeHostScrollTestFractionalScroll : public LayerTreeHostScrollTest {
179 public:
180 LayerTreeHostScrollTestFractionalScroll()
181 : scroll_amount_(1.75, 0) {
184 virtual void BeginTest() OVERRIDE {
185 layer_tree_host()->root_layer()->SetScrollable(true);
186 PostSetNeedsCommitToMainThread();
189 virtual void DrawLayersOnThread(LayerTreeHostImpl* impl) OVERRIDE {
190 LayerImpl* root = impl->active_tree()->root_layer();
191 root->SetMaxScrollOffset(gfx::Vector2d(100, 100));
193 // Check that a fractional scroll delta is correctly accumulated over
194 // multiple commits.
195 switch (impl->active_tree()->source_frame_number()) {
196 case 0:
197 EXPECT_VECTOR_EQ(root->scroll_offset(), gfx::Vector2d(0, 0));
198 EXPECT_VECTOR_EQ(root->scroll_delta(), gfx::Vector2d(0, 0));
199 PostSetNeedsCommitToMainThread();
200 break;
201 case 1:
202 EXPECT_VECTOR_EQ(
203 root->scroll_offset(),
204 gfx::ToFlooredVector2d(scroll_amount_));
205 EXPECT_VECTOR_EQ(
206 root->scroll_delta(),
207 gfx::Vector2dF(fmod(scroll_amount_.x(), 1.0f), 0.0f));
208 PostSetNeedsCommitToMainThread();
209 break;
210 case 2:
211 EXPECT_VECTOR_EQ(
212 root->scroll_offset(),
213 gfx::ToFlooredVector2d(scroll_amount_ + scroll_amount_));
214 EXPECT_VECTOR_EQ(
215 root->scroll_delta(),
216 gfx::Vector2dF(fmod(2.0f * scroll_amount_.x(), 1.0f), 0.0f));
217 EndTest();
218 break;
220 root->ScrollBy(scroll_amount_);
223 virtual void ApplyScrollAndScale(
224 gfx::Vector2d scroll_delta, float scale) OVERRIDE {
225 gfx::Vector2d offset = layer_tree_host()->root_layer()->scroll_offset();
226 layer_tree_host()->root_layer()->SetScrollOffset(offset + scroll_delta);
229 virtual void AfterTest() OVERRIDE {}
231 private:
232 gfx::Vector2dF scroll_amount_;
235 MULTI_THREAD_TEST_F(LayerTreeHostScrollTestFractionalScroll);
237 class LayerTreeHostScrollTestCaseWithChild
238 : public LayerTreeHostScrollTest,
239 public WebKit::WebLayerScrollClient {
240 public:
241 LayerTreeHostScrollTestCaseWithChild()
242 : initial_offset_(10, 20),
243 javascript_scroll_(40, 5),
244 scroll_amount_(2, -1),
245 num_scrolls_(0) {
248 virtual void SetupTree() OVERRIDE {
249 layer_tree_host()->SetDeviceScaleFactor(device_scale_factor_);
251 scoped_refptr<Layer> root_layer = Layer::Create();
252 root_layer->SetBounds(gfx::Size(10, 10));
254 root_scroll_layer_ = ContentLayer::Create(&fake_content_layer_client_);
255 root_scroll_layer_->SetBounds(gfx::Size(110, 110));
257 root_scroll_layer_->SetPosition(gfx::Point(0, 0));
258 root_scroll_layer_->SetAnchorPoint(gfx::PointF());
260 root_scroll_layer_->SetIsDrawable(true);
261 root_scroll_layer_->SetScrollable(true);
262 root_scroll_layer_->SetMaxScrollOffset(gfx::Vector2d(100, 100));
263 root_layer->AddChild(root_scroll_layer_);
265 child_layer_ = ContentLayer::Create(&fake_content_layer_client_);
266 child_layer_->set_layer_scroll_client(this);
267 child_layer_->SetBounds(gfx::Size(110, 110));
269 // Scrolls on the child layer will happen at 5, 5. If they are treated
270 // like device pixels, and device scale factor is 2, then they will
271 // be considered at 2.5, 2.5 in logical pixels, and will miss this layer.
272 child_layer_->SetPosition(gfx::Point(5, 5));
273 child_layer_->SetAnchorPoint(gfx::PointF());
275 child_layer_->SetIsDrawable(true);
276 child_layer_->SetScrollable(true);
277 child_layer_->SetMaxScrollOffset(gfx::Vector2d(100, 100));
278 root_scroll_layer_->AddChild(child_layer_);
280 if (scroll_child_layer_) {
281 expected_scroll_layer_ = child_layer_;
282 expected_no_scroll_layer_ = root_scroll_layer_;
283 } else {
284 expected_scroll_layer_ = root_scroll_layer_;
285 expected_no_scroll_layer_ = child_layer_;
288 expected_scroll_layer_->SetScrollOffset(initial_offset_);
290 layer_tree_host()->SetRootLayer(root_layer);
291 LayerTreeHostScrollTest::SetupTree();
294 virtual void BeginTest() OVERRIDE {
295 PostSetNeedsCommitToMainThread();
298 virtual void didScroll() OVERRIDE {
299 final_scroll_offset_ = expected_scroll_layer_->scroll_offset();
302 virtual void ApplyScrollAndScale(
303 gfx::Vector2d scroll_delta, float scale) OVERRIDE {
304 gfx::Vector2d offset = root_scroll_layer_->scroll_offset();
305 root_scroll_layer_->SetScrollOffset(offset + scroll_delta);
306 num_scrolls_++;
309 virtual void Layout() OVERRIDE {
310 EXPECT_VECTOR_EQ(
311 gfx::Vector2d(), expected_no_scroll_layer_->scroll_offset());
313 switch (layer_tree_host()->commit_number()) {
314 case 0:
315 EXPECT_VECTOR_EQ(
316 initial_offset_,
317 expected_scroll_layer_->scroll_offset());
318 break;
319 case 1:
320 EXPECT_VECTOR_EQ(
321 initial_offset_ + scroll_amount_,
322 expected_scroll_layer_->scroll_offset());
324 // Pretend like Javascript updated the scroll position itself.
325 expected_scroll_layer_->SetScrollOffset(javascript_scroll_);
326 break;
327 case 2:
328 EXPECT_VECTOR_EQ(
329 javascript_scroll_ + scroll_amount_,
330 expected_scroll_layer_->scroll_offset());
331 break;
335 virtual void CommitCompleteOnThread(LayerTreeHostImpl* impl) OVERRIDE {
336 LayerImpl* root_impl = impl->active_tree()->root_layer();
337 LayerImpl* root_scroll_layer_impl = root_impl->children()[0];
338 LayerImpl* child_layer_impl = root_scroll_layer_impl->children()[0];
340 LayerImpl* expected_scroll_layer_impl = NULL;
341 LayerImpl* expected_no_scroll_layer_impl = NULL;
342 if (scroll_child_layer_) {
343 expected_scroll_layer_impl = child_layer_impl;
344 expected_no_scroll_layer_impl = root_scroll_layer_impl;
345 } else {
346 expected_scroll_layer_impl = root_scroll_layer_impl;
347 expected_no_scroll_layer_impl = child_layer_impl;
350 EXPECT_VECTOR_EQ(gfx::Vector2d(), root_impl->scroll_delta());
351 EXPECT_VECTOR_EQ(
352 gfx::Vector2d(),
353 expected_no_scroll_layer_impl->scroll_delta());
355 // Ensure device scale factor is affecting the layers.
356 gfx::Size expected_content_bounds = gfx::ToCeiledSize(
357 gfx::ScaleSize(root_scroll_layer_impl->bounds(), device_scale_factor_));
358 EXPECT_SIZE_EQ(
359 expected_content_bounds,
360 root_scroll_layer_->content_bounds());
362 expected_content_bounds = gfx::ToCeiledSize(
363 gfx::ScaleSize(child_layer_impl->bounds(), device_scale_factor_));
364 EXPECT_SIZE_EQ(expected_content_bounds, child_layer_->content_bounds());
366 switch (impl->active_tree()->source_frame_number()) {
367 case 0: {
368 // Gesture scroll on impl thread.
369 InputHandlerClient::ScrollStatus status = impl->ScrollBegin(
370 gfx::ToCeiledPoint(
371 expected_scroll_layer_impl->position() +
372 gfx::Vector2dF(0.5f, 0.5f)),
373 InputHandlerClient::Gesture);
374 EXPECT_EQ(InputHandlerClient::ScrollStarted, status);
375 impl->ScrollBy(gfx::Point(), scroll_amount_);
376 impl->ScrollEnd();
378 // Check the scroll is applied as a delta.
379 EXPECT_VECTOR_EQ(
380 initial_offset_,
381 expected_scroll_layer_impl->scroll_offset());
382 EXPECT_VECTOR_EQ(
383 scroll_amount_,
384 expected_scroll_layer_impl->scroll_delta());
385 break;
387 case 1: {
388 // Wheel scroll on impl thread.
389 InputHandlerClient::ScrollStatus status = impl->ScrollBegin(
390 gfx::ToCeiledPoint(
391 expected_scroll_layer_impl->position() +
392 gfx::Vector2dF(0.5f, 0.5f)),
393 InputHandlerClient::Wheel);
394 EXPECT_EQ(InputHandlerClient::ScrollStarted, status);
395 impl->ScrollBy(gfx::Point(), scroll_amount_);
396 impl->ScrollEnd();
398 // Check the scroll is applied as a delta.
399 EXPECT_VECTOR_EQ(
400 javascript_scroll_,
401 expected_scroll_layer_impl->scroll_offset());
402 EXPECT_VECTOR_EQ(
403 scroll_amount_,
404 expected_scroll_layer_impl->scroll_delta());
405 break;
407 case 2:
409 EXPECT_VECTOR_EQ(
410 javascript_scroll_ + scroll_amount_,
411 expected_scroll_layer_impl->scroll_offset());
412 EXPECT_VECTOR_EQ(
413 gfx::Vector2d(),
414 expected_scroll_layer_impl->scroll_delta());
416 EndTest();
417 break;
421 virtual void AfterTest() OVERRIDE {
422 if (scroll_child_layer_) {
423 EXPECT_EQ(0, num_scrolls_);
424 EXPECT_VECTOR_EQ(
425 javascript_scroll_ + scroll_amount_,
426 final_scroll_offset_);
427 } else {
428 EXPECT_EQ(2, num_scrolls_);
429 EXPECT_VECTOR_EQ(gfx::Vector2d(), final_scroll_offset_);
433 protected:
434 float device_scale_factor_;
435 bool scroll_child_layer_;
437 gfx::Vector2d initial_offset_;
438 gfx::Vector2d javascript_scroll_;
439 gfx::Vector2d scroll_amount_;
440 int num_scrolls_;
441 gfx::Vector2d final_scroll_offset_;
443 FakeContentLayerClient fake_content_layer_client_;
445 scoped_refptr<Layer> root_scroll_layer_;
446 scoped_refptr<Layer> child_layer_;
447 scoped_refptr<Layer> expected_scroll_layer_;
448 scoped_refptr<Layer> expected_no_scroll_layer_;
451 TEST_F(LayerTreeHostScrollTestCaseWithChild, DeviceScaleFactor1_ScrollChild) {
452 device_scale_factor_ = 1.f;
453 scroll_child_layer_ = true;
454 RunTest(true);
457 TEST_F(LayerTreeHostScrollTestCaseWithChild, DeviceScaleFactor15_ScrollChild) {
458 device_scale_factor_ = 1.5f;
459 scroll_child_layer_ = true;
460 RunTest(true);
463 TEST_F(LayerTreeHostScrollTestCaseWithChild, DeviceScaleFactor2_ScrollChild) {
464 device_scale_factor_ = 2.f;
465 scroll_child_layer_ = true;
466 RunTest(true);
469 TEST_F(LayerTreeHostScrollTestCaseWithChild,
470 DeviceScaleFactor1_ScrollRootScrollLayer) {
471 device_scale_factor_ = 1.f;
472 scroll_child_layer_ = false;
473 RunTest(true);
476 TEST_F(LayerTreeHostScrollTestCaseWithChild,
477 DeviceScaleFactor15_ScrollRootScrollLayer) {
478 device_scale_factor_ = 1.5f;
479 scroll_child_layer_ = false;
480 RunTest(true);
483 TEST_F(LayerTreeHostScrollTestCaseWithChild,
484 DeviceScaleFactor2_ScrollRootScrollLayer) {
485 device_scale_factor_ = 2.f;
486 scroll_child_layer_ = false;
487 RunTest(true);
490 class ImplSidePaintingScrollTest : public LayerTreeHostScrollTest {
491 public:
492 virtual void InitializeSettings(LayerTreeSettings* settings) OVERRIDE {
493 settings->impl_side_painting = true;
496 virtual void DrawLayersOnThread(LayerTreeHostImpl* impl) OVERRIDE {
497 // Manual vsync tick.
498 if (impl->pending_tree())
499 impl->SetNeedsRedraw();
503 class ImplSidePaintingScrollTestSimple : public ImplSidePaintingScrollTest {
504 public:
505 ImplSidePaintingScrollTestSimple()
506 : initial_scroll_(10, 20),
507 main_thread_scroll_(40, 5),
508 impl_thread_scroll1_(2, -1),
509 impl_thread_scroll2_(-3, 10),
510 num_scrolls_(0),
511 can_activate_(true) {
514 virtual void BeginTest() OVERRIDE {
515 layer_tree_host()->root_layer()->SetScrollable(true);
516 layer_tree_host()->root_layer()->SetScrollOffset(initial_scroll_);
517 PostSetNeedsCommitToMainThread();
520 virtual void Layout() OVERRIDE {
521 Layer* root = layer_tree_host()->root_layer();
522 if (!layer_tree_host()->commit_number()) {
523 EXPECT_VECTOR_EQ(root->scroll_offset(), initial_scroll_);
524 } else {
525 EXPECT_VECTOR_EQ(root->scroll_offset(),
526 initial_scroll_ + impl_thread_scroll1_);
528 // Pretend like Javascript updated the scroll position itself with a
529 // change of main_thread_scroll.
530 root->SetScrollOffset(initial_scroll_ +
531 main_thread_scroll_ +
532 impl_thread_scroll1_);
536 virtual bool CanActivatePendingTree() OVERRIDE {
537 return can_activate_;
540 virtual void CommitCompleteOnThread(LayerTreeHostImpl* impl) OVERRIDE {
541 // We force a second draw here of the first commit before activating
542 // the second commit.
543 if (impl->active_tree()->source_frame_number() == 0)
544 impl->SetNeedsRedraw();
547 virtual void DrawLayersOnThread(LayerTreeHostImpl* impl) OVERRIDE {
548 ImplSidePaintingScrollTest::DrawLayersOnThread(impl);
550 LayerImpl* root = impl->active_tree()->root_layer();
551 root->SetScrollable(true);
552 root->SetMaxScrollOffset(gfx::Vector2d(100, 100));
554 LayerImpl* pending_root =
555 impl->active_tree()->FindPendingTreeLayerById(root->id());
557 switch (impl->active_tree()->source_frame_number()) {
558 case 0:
559 if (!impl->pending_tree()) {
560 can_activate_ = false;
561 EXPECT_VECTOR_EQ(root->scroll_delta(), gfx::Vector2d());
562 root->ScrollBy(impl_thread_scroll1_);
564 EXPECT_VECTOR_EQ(root->scroll_offset(), initial_scroll_);
565 EXPECT_VECTOR_EQ(root->scroll_delta(), impl_thread_scroll1_);
566 EXPECT_VECTOR_EQ(root->sent_scroll_delta(), gfx::Vector2d());
567 PostSetNeedsCommitToMainThread();
569 // CommitCompleteOnThread will trigger this function again
570 // and cause us to take the else clause.
571 } else {
572 can_activate_ = true;
573 ASSERT_TRUE(pending_root);
574 EXPECT_EQ(impl->pending_tree()->source_frame_number(), 1);
576 root->ScrollBy(impl_thread_scroll2_);
577 EXPECT_VECTOR_EQ(root->scroll_offset(), initial_scroll_);
578 EXPECT_VECTOR_EQ(root->scroll_delta(),
579 impl_thread_scroll1_ + impl_thread_scroll2_);
580 EXPECT_VECTOR_EQ(root->sent_scroll_delta(), impl_thread_scroll1_);
582 EXPECT_VECTOR_EQ(pending_root->scroll_offset(),
583 initial_scroll_ + main_thread_scroll_ + impl_thread_scroll1_);
584 EXPECT_VECTOR_EQ(pending_root->scroll_delta(), impl_thread_scroll2_);
585 EXPECT_VECTOR_EQ(pending_root->sent_scroll_delta(), gfx::Vector2d());
587 break;
588 case 1:
589 EXPECT_FALSE(impl->pending_tree());
590 EXPECT_VECTOR_EQ(root->scroll_offset(),
591 initial_scroll_ + main_thread_scroll_ + impl_thread_scroll1_);
592 EXPECT_VECTOR_EQ(root->scroll_delta(), impl_thread_scroll2_);
593 EXPECT_VECTOR_EQ(root->sent_scroll_delta(), gfx::Vector2d());
594 EndTest();
595 break;
599 virtual void ApplyScrollAndScale(
600 gfx::Vector2d scroll_delta, float scale) OVERRIDE {
601 gfx::Vector2d offset = layer_tree_host()->root_layer()->scroll_offset();
602 layer_tree_host()->root_layer()->SetScrollOffset(offset + scroll_delta);
603 num_scrolls_++;
606 virtual void AfterTest() OVERRIDE {
607 EXPECT_EQ(1, num_scrolls_);
610 private:
611 gfx::Vector2d initial_scroll_;
612 gfx::Vector2d main_thread_scroll_;
613 gfx::Vector2d impl_thread_scroll1_;
614 gfx::Vector2d impl_thread_scroll2_;
615 int num_scrolls_;
616 bool can_activate_;
619 MULTI_THREAD_TEST_F(ImplSidePaintingScrollTestSimple);
621 class LayerTreeHostScrollTestScrollZeroMaxScrollOffset
622 : public LayerTreeHostScrollTest {
623 public:
624 LayerTreeHostScrollTestScrollZeroMaxScrollOffset() {}
626 virtual void BeginTest() OVERRIDE {
627 PostSetNeedsCommitToMainThread();
630 virtual void DrawLayersOnThread(LayerTreeHostImpl* impl) OVERRIDE {
631 LayerImpl* root = impl->active_tree()->root_layer();
632 root->SetScrollable(true);
634 root->SetMaxScrollOffset(gfx::Vector2d(100, 100));
635 EXPECT_EQ(
636 InputHandlerClient::ScrollStarted,
637 root->TryScroll(
638 gfx::PointF(0.0f, 1.0f),
639 InputHandlerClient::Gesture));
641 root->SetMaxScrollOffset(gfx::Vector2d(0, 0));
642 EXPECT_EQ(
643 InputHandlerClient::ScrollIgnored,
644 root->TryScroll(
645 gfx::PointF(0.0f, 1.0f),
646 InputHandlerClient::Gesture));
648 root->SetMaxScrollOffset(gfx::Vector2d(-100, -100));
649 EXPECT_EQ(
650 InputHandlerClient::ScrollIgnored,
651 root->TryScroll(
652 gfx::PointF(0.0f, 1.0f),
653 InputHandlerClient::Gesture));
655 EndTest();
658 virtual void AfterTest() OVERRIDE {}
661 SINGLE_AND_MULTI_THREAD_TEST_F(
662 LayerTreeHostScrollTestScrollZeroMaxScrollOffset);
664 } // namespace
665 } // namespace cc