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

Side by Side Diff: cc/layers/layer_impl_unittest.cc

Issue 584503005: Make scroll offset type of float in cc (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: link crbug to TODO Created 6 years, 2 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
« no previous file with comments | « cc/layers/layer_impl.cc ('k') | cc/layers/layer_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2011 The Chromium Authors. All rights reserved. 1 // Copyright 2011 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/layers/layer_impl.h" 5 #include "cc/layers/layer_impl.h"
6 6
7 #include "cc/layers/painted_scrollbar_layer_impl.h" 7 #include "cc/layers/painted_scrollbar_layer_impl.h"
8 #include "cc/output/filter_operation.h" 8 #include "cc/output/filter_operation.h"
9 #include "cc/output/filter_operations.h" 9 #include "cc/output/filter_operations.h"
10 #include "cc/test/fake_impl_proxy.h" 10 #include "cc/test/fake_impl_proxy.h"
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after
153 EXECUTE_AND_VERIFY_SUBTREE_CHANGED(root->SetContentsOpaque(true)); 153 EXECUTE_AND_VERIFY_SUBTREE_CHANGED(root->SetContentsOpaque(true));
154 EXECUTE_AND_VERIFY_SUBTREE_CHANGED( 154 EXECUTE_AND_VERIFY_SUBTREE_CHANGED(
155 root->SetReplicaLayer(LayerImpl::Create(host_impl.active_tree(), 10))); 155 root->SetReplicaLayer(LayerImpl::Create(host_impl.active_tree(), 10)));
156 EXECUTE_AND_VERIFY_SUBTREE_CHANGED(root->SetPosition(arbitrary_point_f)); 156 EXECUTE_AND_VERIFY_SUBTREE_CHANGED(root->SetPosition(arbitrary_point_f));
157 EXECUTE_AND_VERIFY_SUBTREE_CHANGED(root->SetShouldFlattenTransform(false)); 157 EXECUTE_AND_VERIFY_SUBTREE_CHANGED(root->SetShouldFlattenTransform(false));
158 EXECUTE_AND_VERIFY_SUBTREE_CHANGED(root->Set3dSortingContextId(1)); 158 EXECUTE_AND_VERIFY_SUBTREE_CHANGED(root->Set3dSortingContextId(1));
159 EXECUTE_AND_VERIFY_SUBTREE_CHANGED( 159 EXECUTE_AND_VERIFY_SUBTREE_CHANGED(
160 root->SetDoubleSided(false)); // constructor initializes it to "true". 160 root->SetDoubleSided(false)); // constructor initializes it to "true".
161 EXECUTE_AND_VERIFY_SUBTREE_CHANGED(root->ScrollBy(arbitrary_vector2d)); 161 EXECUTE_AND_VERIFY_SUBTREE_CHANGED(root->ScrollBy(arbitrary_vector2d));
162 EXECUTE_AND_VERIFY_SUBTREE_CHANGED(root->SetScrollDelta(gfx::Vector2d())); 162 EXECUTE_AND_VERIFY_SUBTREE_CHANGED(root->SetScrollDelta(gfx::Vector2d()));
163 EXECUTE_AND_VERIFY_SUBTREE_CHANGED(root->SetScrollOffset(arbitrary_vector2d)); 163 EXECUTE_AND_VERIFY_SUBTREE_CHANGED(
164 root->SetScrollOffset(gfx::ScrollOffset(arbitrary_vector2d)));
164 EXECUTE_AND_VERIFY_SUBTREE_CHANGED(root->SetHideLayerAndSubtree(true)); 165 EXECUTE_AND_VERIFY_SUBTREE_CHANGED(root->SetHideLayerAndSubtree(true));
165 EXECUTE_AND_VERIFY_SUBTREE_CHANGED(root->SetOpacity(arbitrary_number)); 166 EXECUTE_AND_VERIFY_SUBTREE_CHANGED(root->SetOpacity(arbitrary_number));
166 EXECUTE_AND_VERIFY_SUBTREE_CHANGED(root->SetBlendMode(arbitrary_blend_mode)); 167 EXECUTE_AND_VERIFY_SUBTREE_CHANGED(root->SetBlendMode(arbitrary_blend_mode));
167 EXECUTE_AND_VERIFY_SUBTREE_CHANGED(root->SetTransform(arbitrary_transform)); 168 EXECUTE_AND_VERIFY_SUBTREE_CHANGED(root->SetTransform(arbitrary_transform));
168 169
169 // Changing these properties only affects the layer itself. 170 // Changing these properties only affects the layer itself.
170 EXECUTE_AND_VERIFY_ONLY_LAYER_CHANGED(root->SetContentBounds(arbitrary_size)); 171 EXECUTE_AND_VERIFY_ONLY_LAYER_CHANGED(root->SetContentBounds(arbitrary_size));
171 EXECUTE_AND_VERIFY_ONLY_LAYER_CHANGED( 172 EXECUTE_AND_VERIFY_ONLY_LAYER_CHANGED(
172 root->SetContentsScale(arbitrary_number, arbitrary_number)); 173 root->SetContentsScale(arbitrary_number, arbitrary_number));
173 EXECUTE_AND_VERIFY_ONLY_LAYER_CHANGED(root->SetDrawsContent(true)); 174 EXECUTE_AND_VERIFY_ONLY_LAYER_CHANGED(root->SetDrawsContent(true));
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
212 EXECUTE_AND_VERIFY_SUBTREE_DID_NOT_CHANGE( 213 EXECUTE_AND_VERIFY_SUBTREE_DID_NOT_CHANGE(
213 root->SetShouldFlattenTransform(false)); 214 root->SetShouldFlattenTransform(false));
214 EXECUTE_AND_VERIFY_SUBTREE_DID_NOT_CHANGE(root->Set3dSortingContextId(1)); 215 EXECUTE_AND_VERIFY_SUBTREE_DID_NOT_CHANGE(root->Set3dSortingContextId(1));
215 EXECUTE_AND_VERIFY_SUBTREE_DID_NOT_CHANGE( 216 EXECUTE_AND_VERIFY_SUBTREE_DID_NOT_CHANGE(
216 root->SetTransform(arbitrary_transform)); 217 root->SetTransform(arbitrary_transform));
217 EXECUTE_AND_VERIFY_SUBTREE_DID_NOT_CHANGE( 218 EXECUTE_AND_VERIFY_SUBTREE_DID_NOT_CHANGE(
218 root->SetDoubleSided(false)); // constructor initializes it to "true". 219 root->SetDoubleSided(false)); // constructor initializes it to "true".
219 EXECUTE_AND_VERIFY_SUBTREE_DID_NOT_CHANGE( 220 EXECUTE_AND_VERIFY_SUBTREE_DID_NOT_CHANGE(
220 root->SetScrollDelta(gfx::Vector2d())); 221 root->SetScrollDelta(gfx::Vector2d()));
221 EXECUTE_AND_VERIFY_SUBTREE_DID_NOT_CHANGE( 222 EXECUTE_AND_VERIFY_SUBTREE_DID_NOT_CHANGE(
222 root->SetScrollOffset(arbitrary_vector2d)); 223 root->SetScrollOffset(gfx::ScrollOffset(arbitrary_vector2d)));
223 EXECUTE_AND_VERIFY_SUBTREE_DID_NOT_CHANGE( 224 EXECUTE_AND_VERIFY_SUBTREE_DID_NOT_CHANGE(
224 root->SetContentBounds(arbitrary_size)); 225 root->SetContentBounds(arbitrary_size));
225 EXECUTE_AND_VERIFY_SUBTREE_DID_NOT_CHANGE( 226 EXECUTE_AND_VERIFY_SUBTREE_DID_NOT_CHANGE(
226 root->SetContentsScale(arbitrary_number, arbitrary_number)); 227 root->SetContentsScale(arbitrary_number, arbitrary_number));
227 EXECUTE_AND_VERIFY_SUBTREE_DID_NOT_CHANGE(root->SetContentsOpaque(true)); 228 EXECUTE_AND_VERIFY_SUBTREE_DID_NOT_CHANGE(root->SetContentsOpaque(true));
228 EXECUTE_AND_VERIFY_SUBTREE_DID_NOT_CHANGE(root->SetOpacity(arbitrary_number)); 229 EXECUTE_AND_VERIFY_SUBTREE_DID_NOT_CHANGE(root->SetOpacity(arbitrary_number));
229 EXECUTE_AND_VERIFY_SUBTREE_DID_NOT_CHANGE( 230 EXECUTE_AND_VERIFY_SUBTREE_DID_NOT_CHANGE(
230 root->SetBlendMode(arbitrary_blend_mode)); 231 root->SetBlendMode(arbitrary_blend_mode));
231 EXECUTE_AND_VERIFY_SUBTREE_DID_NOT_CHANGE( 232 EXECUTE_AND_VERIFY_SUBTREE_DID_NOT_CHANGE(
232 root->SetIsRootForIsolatedGroup(true)); 233 root->SetIsRootForIsolatedGroup(true));
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
284 VERIFY_NO_NEEDS_UPDATE_DRAW_PROPERTIES(layer->SetBounds(large_size)); 285 VERIFY_NO_NEEDS_UPDATE_DRAW_PROPERTIES(layer->SetBounds(large_size));
285 VERIFY_NEEDS_UPDATE_DRAW_PROPERTIES(layer->ScrollBy(arbitrary_vector2d)); 286 VERIFY_NEEDS_UPDATE_DRAW_PROPERTIES(layer->ScrollBy(arbitrary_vector2d));
286 VERIFY_NO_NEEDS_UPDATE_DRAW_PROPERTIES(layer->ScrollBy(gfx::Vector2d())); 287 VERIFY_NO_NEEDS_UPDATE_DRAW_PROPERTIES(layer->ScrollBy(gfx::Vector2d()));
287 layer->SetScrollDelta(gfx::Vector2d(0, 0)); 288 layer->SetScrollDelta(gfx::Vector2d(0, 0));
288 host_impl.ForcePrepareToDraw(); 289 host_impl.ForcePrepareToDraw();
289 VERIFY_NEEDS_UPDATE_DRAW_PROPERTIES( 290 VERIFY_NEEDS_UPDATE_DRAW_PROPERTIES(
290 layer->SetScrollDelta(arbitrary_vector2d)); 291 layer->SetScrollDelta(arbitrary_vector2d));
291 VERIFY_NO_NEEDS_UPDATE_DRAW_PROPERTIES( 292 VERIFY_NO_NEEDS_UPDATE_DRAW_PROPERTIES(
292 layer->SetScrollDelta(arbitrary_vector2d)); 293 layer->SetScrollDelta(arbitrary_vector2d));
293 VERIFY_NEEDS_UPDATE_DRAW_PROPERTIES( 294 VERIFY_NEEDS_UPDATE_DRAW_PROPERTIES(
294 layer->SetScrollOffset(arbitrary_vector2d)); 295 layer->SetScrollOffset(gfx::ScrollOffset(arbitrary_vector2d)));
295 VERIFY_NO_NEEDS_UPDATE_DRAW_PROPERTIES( 296 VERIFY_NO_NEEDS_UPDATE_DRAW_PROPERTIES(
296 layer->SetScrollOffset(arbitrary_vector2d)); 297 layer->SetScrollOffset(gfx::ScrollOffset(arbitrary_vector2d)));
297 298
298 // Unrelated functions, always set to new values, always set needs update. 299 // Unrelated functions, always set to new values, always set needs update.
299 VERIFY_NEEDS_UPDATE_DRAW_PROPERTIES( 300 VERIFY_NEEDS_UPDATE_DRAW_PROPERTIES(
300 layer->SetMaskLayer(LayerImpl::Create(host_impl.active_tree(), 4))); 301 layer->SetMaskLayer(LayerImpl::Create(host_impl.active_tree(), 4)));
301 VERIFY_NEEDS_UPDATE_DRAW_PROPERTIES(layer->SetMasksToBounds(true)); 302 VERIFY_NEEDS_UPDATE_DRAW_PROPERTIES(layer->SetMasksToBounds(true));
302 VERIFY_NEEDS_UPDATE_DRAW_PROPERTIES(layer->SetContentsOpaque(true)); 303 VERIFY_NEEDS_UPDATE_DRAW_PROPERTIES(layer->SetContentsOpaque(true));
303 VERIFY_NEEDS_UPDATE_DRAW_PROPERTIES( 304 VERIFY_NEEDS_UPDATE_DRAW_PROPERTIES(
304 layer->SetReplicaLayer(LayerImpl::Create(host_impl.active_tree(), 5))); 305 layer->SetReplicaLayer(LayerImpl::Create(host_impl.active_tree(), 5)));
305 VERIFY_NEEDS_UPDATE_DRAW_PROPERTIES(layer->SetPosition(arbitrary_point_f)); 306 VERIFY_NEEDS_UPDATE_DRAW_PROPERTIES(layer->SetPosition(arbitrary_point_f));
306 VERIFY_NEEDS_UPDATE_DRAW_PROPERTIES(layer->SetShouldFlattenTransform(false)); 307 VERIFY_NEEDS_UPDATE_DRAW_PROPERTIES(layer->SetShouldFlattenTransform(false));
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after
457 EXPECT_VECTOR_EQ(gfx::Vector2dF(), layer()->scroll_offset()); 458 EXPECT_VECTOR_EQ(gfx::Vector2dF(), layer()->scroll_offset());
458 459
459 layer()->ScrollBy(gfx::Vector2dF(100, -100)); 460 layer()->ScrollBy(gfx::Vector2dF(100, -100));
460 EXPECT_VECTOR_EQ(gfx::Vector2dF(50, 0), layer()->TotalScrollOffset()); 461 EXPECT_VECTOR_EQ(gfx::Vector2dF(50, 0), layer()->TotalScrollOffset());
461 462
462 EXPECT_VECTOR_EQ(layer()->ScrollDelta(), layer()->TotalScrollOffset()); 463 EXPECT_VECTOR_EQ(layer()->ScrollDelta(), layer()->TotalScrollOffset());
463 EXPECT_VECTOR_EQ(gfx::Vector2dF(), layer()->scroll_offset()); 464 EXPECT_VECTOR_EQ(gfx::Vector2dF(), layer()->scroll_offset());
464 } 465 }
465 466
466 TEST_F(LayerImplScrollTest, ScrollByWithNonZeroOffset) { 467 TEST_F(LayerImplScrollTest, ScrollByWithNonZeroOffset) {
467 gfx::Vector2d scroll_offset(10, 5); 468 gfx::ScrollOffset scroll_offset(10, 5);
468 layer()->SetScrollOffset(scroll_offset); 469 layer()->SetScrollOffset(scroll_offset);
469 470
470 EXPECT_VECTOR_EQ(scroll_offset, layer()->TotalScrollOffset()); 471 EXPECT_VECTOR_EQ(scroll_offset, layer()->TotalScrollOffset());
471 EXPECT_VECTOR_EQ(scroll_offset, layer()->scroll_offset()); 472 EXPECT_VECTOR_EQ(scroll_offset, layer()->scroll_offset());
472 EXPECT_VECTOR_EQ(gfx::Vector2dF(), layer()->ScrollDelta()); 473 EXPECT_VECTOR_EQ(gfx::Vector2dF(), layer()->ScrollDelta());
473 474
474 layer()->ScrollBy(gfx::Vector2dF(-100, 100)); 475 layer()->ScrollBy(gfx::Vector2dF(-100, 100));
475 EXPECT_VECTOR_EQ(gfx::Vector2dF(0, 80), layer()->TotalScrollOffset()); 476 EXPECT_VECTOR_EQ(gfx::Vector2dF(0, 80), layer()->TotalScrollOffset());
476 477
477 EXPECT_VECTOR_EQ(layer()->ScrollDelta() + scroll_offset, 478 EXPECT_VECTOR_EQ(gfx::ScrollOffsetWithDelta(scroll_offset,
479 layer()->ScrollDelta()),
478 layer()->TotalScrollOffset()); 480 layer()->TotalScrollOffset());
479 EXPECT_VECTOR_EQ(scroll_offset, layer()->scroll_offset()); 481 EXPECT_VECTOR_EQ(scroll_offset, layer()->scroll_offset());
480 482
481 layer()->ScrollBy(gfx::Vector2dF(100, -100)); 483 layer()->ScrollBy(gfx::Vector2dF(100, -100));
482 EXPECT_VECTOR_EQ(gfx::Vector2dF(50, 0), layer()->TotalScrollOffset()); 484 EXPECT_VECTOR_EQ(gfx::Vector2dF(50, 0), layer()->TotalScrollOffset());
483 485
484 EXPECT_VECTOR_EQ(layer()->ScrollDelta() + scroll_offset, 486 EXPECT_VECTOR_EQ(gfx::ScrollOffsetWithDelta(scroll_offset,
487 layer()->ScrollDelta()),
485 layer()->TotalScrollOffset()); 488 layer()->TotalScrollOffset());
486 EXPECT_VECTOR_EQ(scroll_offset, layer()->scroll_offset()); 489 EXPECT_VECTOR_EQ(scroll_offset, layer()->scroll_offset());
487 } 490 }
488 491
489 class ScrollDelegateIgnore : public LayerImpl::ScrollOffsetDelegate { 492 class ScrollDelegateIgnore : public LayerImpl::ScrollOffsetDelegate {
490 public: 493 public:
491 virtual void SetTotalScrollOffset(const gfx::Vector2dF& new_value) OVERRIDE {} 494 virtual void SetTotalScrollOffset(
492 virtual gfx::Vector2dF GetTotalScrollOffset() OVERRIDE { 495 const gfx::ScrollOffset& new_value) OVERRIDE {}
493 return fixed_offset_; 496 virtual gfx::ScrollOffset GetTotalScrollOffset() OVERRIDE {
497 return gfx::ScrollOffset(fixed_offset_);
494 } 498 }
495 virtual bool IsExternalFlingActive() const OVERRIDE { return false; } 499 virtual bool IsExternalFlingActive() const OVERRIDE { return false; }
496 500
497 void set_fixed_offset(const gfx::Vector2dF& fixed_offset) { 501 void set_fixed_offset(const gfx::Vector2dF& fixed_offset) {
498 fixed_offset_ = fixed_offset; 502 fixed_offset_ = fixed_offset;
499 } 503 }
500 504
501 private: 505 private:
502 gfx::Vector2dF fixed_offset_; 506 gfx::Vector2dF fixed_offset_;
503 }; 507 };
504 508
505 TEST_F(LayerImplScrollTest, ScrollByWithIgnoringDelegate) { 509 TEST_F(LayerImplScrollTest, ScrollByWithIgnoringDelegate) {
506 gfx::Vector2d scroll_offset(10, 5); 510 gfx::ScrollOffset scroll_offset(10, 5);
507 layer()->SetScrollOffset(scroll_offset); 511 layer()->SetScrollOffset(scroll_offset);
508 512
509 EXPECT_VECTOR_EQ(scroll_offset, layer()->TotalScrollOffset()); 513 EXPECT_VECTOR_EQ(scroll_offset, layer()->TotalScrollOffset());
510 EXPECT_VECTOR_EQ(scroll_offset, layer()->scroll_offset()); 514 EXPECT_VECTOR_EQ(scroll_offset, layer()->scroll_offset());
511 EXPECT_VECTOR_EQ(gfx::Vector2dF(), layer()->ScrollDelta()); 515 EXPECT_VECTOR_EQ(gfx::Vector2dF(), layer()->ScrollDelta());
512 516
513 ScrollDelegateIgnore delegate; 517 ScrollDelegateIgnore delegate;
514 gfx::Vector2dF fixed_offset(32, 12); 518 gfx::Vector2dF fixed_offset(32, 12);
515 delegate.set_fixed_offset(fixed_offset); 519 delegate.set_fixed_offset(fixed_offset);
516 layer()->SetScrollOffsetDelegate(&delegate); 520 layer()->SetScrollOffsetDelegate(&delegate);
(...skipping 13 matching lines...) Expand all
530 534
531 gfx::Vector2dF scroll_delta(1, 1); 535 gfx::Vector2dF scroll_delta(1, 1);
532 layer()->ScrollBy(scroll_delta); 536 layer()->ScrollBy(scroll_delta);
533 537
534 EXPECT_VECTOR_EQ(fixed_offset + scroll_delta, layer()->TotalScrollOffset()); 538 EXPECT_VECTOR_EQ(fixed_offset + scroll_delta, layer()->TotalScrollOffset());
535 EXPECT_VECTOR_EQ(scroll_offset, layer()->scroll_offset()); 539 EXPECT_VECTOR_EQ(scroll_offset, layer()->scroll_offset());
536 } 540 }
537 541
538 class ScrollDelegateAccept : public LayerImpl::ScrollOffsetDelegate { 542 class ScrollDelegateAccept : public LayerImpl::ScrollOffsetDelegate {
539 public: 543 public:
540 virtual void SetTotalScrollOffset(const gfx::Vector2dF& new_value) OVERRIDE { 544 virtual void SetTotalScrollOffset(
545 const gfx::ScrollOffset& new_value) OVERRIDE {
541 current_offset_ = new_value; 546 current_offset_ = new_value;
542 } 547 }
543 virtual gfx::Vector2dF GetTotalScrollOffset() OVERRIDE { 548 virtual gfx::ScrollOffset GetTotalScrollOffset() OVERRIDE {
544 return current_offset_; 549 return current_offset_;
545 } 550 }
546 virtual bool IsExternalFlingActive() const OVERRIDE { return false; } 551 virtual bool IsExternalFlingActive() const OVERRIDE { return false; }
547 552
548 private: 553 private:
549 gfx::Vector2dF current_offset_; 554 gfx::ScrollOffset current_offset_;
550 }; 555 };
551 556
552 TEST_F(LayerImplScrollTest, ScrollByWithAcceptingDelegate) { 557 TEST_F(LayerImplScrollTest, ScrollByWithAcceptingDelegate) {
553 gfx::Vector2d scroll_offset(10, 5); 558 gfx::ScrollOffset scroll_offset(10, 5);
554 layer()->SetScrollOffset(scroll_offset); 559 layer()->SetScrollOffset(scroll_offset);
555 560
556 EXPECT_VECTOR_EQ(scroll_offset, layer()->TotalScrollOffset()); 561 EXPECT_VECTOR_EQ(scroll_offset, layer()->TotalScrollOffset());
557 EXPECT_VECTOR_EQ(scroll_offset, layer()->scroll_offset()); 562 EXPECT_VECTOR_EQ(scroll_offset, layer()->scroll_offset());
558 EXPECT_VECTOR_EQ(gfx::Vector2dF(), layer()->ScrollDelta()); 563 EXPECT_VECTOR_EQ(gfx::Vector2dF(), layer()->ScrollDelta());
559 564
560 ScrollDelegateAccept delegate; 565 ScrollDelegateAccept delegate;
561 layer()->SetScrollOffsetDelegate(&delegate); 566 layer()->SetScrollOffsetDelegate(&delegate);
562 567
563 EXPECT_VECTOR_EQ(scroll_offset, layer()->TotalScrollOffset()); 568 EXPECT_VECTOR_EQ(scroll_offset, layer()->TotalScrollOffset());
(...skipping 11 matching lines...) Expand all
575 EXPECT_VECTOR_EQ(scroll_offset, layer()->scroll_offset()); 580 EXPECT_VECTOR_EQ(scroll_offset, layer()->scroll_offset());
576 581
577 gfx::Vector2dF scroll_delta(1, 1); 582 gfx::Vector2dF scroll_delta(1, 1);
578 layer()->ScrollBy(scroll_delta); 583 layer()->ScrollBy(scroll_delta);
579 584
580 EXPECT_VECTOR_EQ(gfx::Vector2dF(1, 80), layer()->TotalScrollOffset()); 585 EXPECT_VECTOR_EQ(gfx::Vector2dF(1, 80), layer()->TotalScrollOffset());
581 EXPECT_VECTOR_EQ(scroll_offset, layer()->scroll_offset()); 586 EXPECT_VECTOR_EQ(scroll_offset, layer()->scroll_offset());
582 } 587 }
583 588
584 TEST_F(LayerImplScrollTest, ApplySentScrollsNoDelegate) { 589 TEST_F(LayerImplScrollTest, ApplySentScrollsNoDelegate) {
585 gfx::Vector2d scroll_offset(10, 5); 590 gfx::ScrollOffset scroll_offset(10, 5);
586 gfx::Vector2dF scroll_delta(20.5f, 8.5f); 591 gfx::Vector2dF scroll_delta(20.5f, 8.5f);
587 gfx::Vector2d sent_scroll_delta(12, -3); 592 gfx::Vector2d sent_scroll_delta(12, -3);
588 593
589 layer()->SetScrollOffset(scroll_offset); 594 layer()->SetScrollOffset(scroll_offset);
590 layer()->ScrollBy(scroll_delta); 595 layer()->ScrollBy(scroll_delta);
591 layer()->SetSentScrollDelta(sent_scroll_delta); 596 layer()->SetSentScrollDelta(sent_scroll_delta);
592 597
593 EXPECT_VECTOR_EQ(scroll_offset + scroll_delta, layer()->TotalScrollOffset()); 598 EXPECT_VECTOR_EQ(gfx::ScrollOffsetWithDelta(scroll_offset, scroll_delta),
599 layer()->TotalScrollOffset());
594 EXPECT_VECTOR_EQ(scroll_delta, layer()->ScrollDelta()); 600 EXPECT_VECTOR_EQ(scroll_delta, layer()->ScrollDelta());
595 EXPECT_VECTOR_EQ(scroll_offset, layer()->scroll_offset()); 601 EXPECT_VECTOR_EQ(scroll_offset, layer()->scroll_offset());
596 EXPECT_VECTOR_EQ(sent_scroll_delta, layer()->sent_scroll_delta()); 602 EXPECT_VECTOR_EQ(sent_scroll_delta, layer()->sent_scroll_delta());
597 603
598 layer()->ApplySentScrollDeltasFromAbortedCommit(); 604 layer()->ApplySentScrollDeltasFromAbortedCommit();
599 605
600 EXPECT_VECTOR_EQ(scroll_offset + scroll_delta, layer()->TotalScrollOffset()); 606 EXPECT_VECTOR_EQ(gfx::ScrollOffsetWithDelta(scroll_offset, scroll_delta),
607 layer()->TotalScrollOffset());
601 EXPECT_VECTOR_EQ(scroll_delta - sent_scroll_delta, layer()->ScrollDelta()); 608 EXPECT_VECTOR_EQ(scroll_delta - sent_scroll_delta, layer()->ScrollDelta());
602 EXPECT_VECTOR_EQ(scroll_offset + sent_scroll_delta, layer()->scroll_offset()); 609 EXPECT_VECTOR_EQ(gfx::ScrollOffsetWithDelta(scroll_offset, sent_scroll_delta),
610 layer()->scroll_offset());
603 EXPECT_VECTOR_EQ(gfx::Vector2d(), layer()->sent_scroll_delta()); 611 EXPECT_VECTOR_EQ(gfx::Vector2d(), layer()->sent_scroll_delta());
604 } 612 }
605 613
606 TEST_F(LayerImplScrollTest, ApplySentScrollsWithIgnoringDelegate) { 614 TEST_F(LayerImplScrollTest, ApplySentScrollsWithIgnoringDelegate) {
607 gfx::Vector2d scroll_offset(10, 5); 615 gfx::ScrollOffset scroll_offset(10, 5);
608 gfx::Vector2d sent_scroll_delta(12, -3); 616 gfx::Vector2d sent_scroll_delta(12, -3);
609 gfx::Vector2dF fixed_offset(32, 12); 617 gfx::Vector2dF fixed_offset(32, 12);
610 618
611 layer()->SetScrollOffset(scroll_offset); 619 layer()->SetScrollOffset(scroll_offset);
612 ScrollDelegateIgnore delegate; 620 ScrollDelegateIgnore delegate;
613 delegate.set_fixed_offset(fixed_offset); 621 delegate.set_fixed_offset(fixed_offset);
614 layer()->SetScrollOffsetDelegate(&delegate); 622 layer()->SetScrollOffsetDelegate(&delegate);
615 layer()->SetSentScrollDelta(sent_scroll_delta); 623 layer()->SetSentScrollDelta(sent_scroll_delta);
616 624
617 EXPECT_VECTOR_EQ(fixed_offset, layer()->TotalScrollOffset()); 625 EXPECT_VECTOR_EQ(fixed_offset, layer()->TotalScrollOffset());
618 EXPECT_VECTOR_EQ(scroll_offset, layer()->scroll_offset()); 626 EXPECT_VECTOR_EQ(scroll_offset, layer()->scroll_offset());
619 EXPECT_VECTOR_EQ(sent_scroll_delta, layer()->sent_scroll_delta()); 627 EXPECT_VECTOR_EQ(sent_scroll_delta, layer()->sent_scroll_delta());
620 628
621 layer()->ApplySentScrollDeltasFromAbortedCommit(); 629 layer()->ApplySentScrollDeltasFromAbortedCommit();
622 630
623 EXPECT_VECTOR_EQ(fixed_offset, layer()->TotalScrollOffset()); 631 EXPECT_VECTOR_EQ(fixed_offset, layer()->TotalScrollOffset());
624 EXPECT_VECTOR_EQ(scroll_offset + sent_scroll_delta, layer()->scroll_offset()); 632 EXPECT_VECTOR_EQ(gfx::ScrollOffsetWithDelta(scroll_offset, sent_scroll_delta),
633 layer()->scroll_offset());
625 EXPECT_VECTOR_EQ(gfx::Vector2d(), layer()->sent_scroll_delta()); 634 EXPECT_VECTOR_EQ(gfx::Vector2d(), layer()->sent_scroll_delta());
626 } 635 }
627 636
628 TEST_F(LayerImplScrollTest, ApplySentScrollsWithAcceptingDelegate) { 637 TEST_F(LayerImplScrollTest, ApplySentScrollsWithAcceptingDelegate) {
629 gfx::Vector2d scroll_offset(10, 5); 638 gfx::ScrollOffset scroll_offset(10, 5);
630 gfx::Vector2d sent_scroll_delta(12, -3); 639 gfx::Vector2d sent_scroll_delta(12, -3);
631 gfx::Vector2dF scroll_delta(20.5f, 8.5f); 640 gfx::Vector2dF scroll_delta(20.5f, 8.5f);
632 641
633 layer()->SetScrollOffset(scroll_offset); 642 layer()->SetScrollOffset(scroll_offset);
634 ScrollDelegateAccept delegate; 643 ScrollDelegateAccept delegate;
635 layer()->SetScrollOffsetDelegate(&delegate); 644 layer()->SetScrollOffsetDelegate(&delegate);
636 layer()->ScrollBy(scroll_delta); 645 layer()->ScrollBy(scroll_delta);
637 layer()->SetSentScrollDelta(sent_scroll_delta); 646 layer()->SetSentScrollDelta(sent_scroll_delta);
638 647
639 EXPECT_VECTOR_EQ(scroll_offset + scroll_delta, layer()->TotalScrollOffset()); 648 EXPECT_VECTOR_EQ(gfx::ScrollOffsetWithDelta(scroll_offset, scroll_delta),
649 layer()->TotalScrollOffset());
640 EXPECT_VECTOR_EQ(scroll_offset, layer()->scroll_offset()); 650 EXPECT_VECTOR_EQ(scroll_offset, layer()->scroll_offset());
641 EXPECT_VECTOR_EQ(sent_scroll_delta, layer()->sent_scroll_delta()); 651 EXPECT_VECTOR_EQ(sent_scroll_delta, layer()->sent_scroll_delta());
642 652
643 layer()->ApplySentScrollDeltasFromAbortedCommit(); 653 layer()->ApplySentScrollDeltasFromAbortedCommit();
644 654
645 EXPECT_VECTOR_EQ(scroll_offset + scroll_delta, layer()->TotalScrollOffset()); 655 EXPECT_VECTOR_EQ(gfx::ScrollOffsetWithDelta(scroll_offset, scroll_delta),
646 EXPECT_VECTOR_EQ(scroll_offset + sent_scroll_delta, layer()->scroll_offset()); 656 layer()->TotalScrollOffset());
657 EXPECT_VECTOR_EQ(gfx::ScrollOffsetWithDelta(scroll_offset, sent_scroll_delta),
658 layer()->scroll_offset());
647 EXPECT_VECTOR_EQ(gfx::Vector2d(), layer()->sent_scroll_delta()); 659 EXPECT_VECTOR_EQ(gfx::Vector2d(), layer()->sent_scroll_delta());
648 } 660 }
649 661
650 // The user-scrollability breaks for zoomed-in pages. So disable this. 662 // The user-scrollability breaks for zoomed-in pages. So disable this.
651 // http://crbug.com/322223 663 // http://crbug.com/322223
652 TEST_F(LayerImplScrollTest, DISABLED_ScrollUserUnscrollableLayer) { 664 TEST_F(LayerImplScrollTest, DISABLED_ScrollUserUnscrollableLayer) {
653 gfx::Vector2d scroll_offset(10, 5); 665 gfx::ScrollOffset scroll_offset(10, 5);
654 gfx::Vector2dF scroll_delta(20.5f, 8.5f); 666 gfx::Vector2dF scroll_delta(20.5f, 8.5f);
655 667
656 layer()->set_user_scrollable_vertical(false); 668 layer()->set_user_scrollable_vertical(false);
657 layer()->SetScrollOffset(scroll_offset); 669 layer()->SetScrollOffset(scroll_offset);
658 gfx::Vector2dF unscrolled = layer()->ScrollBy(scroll_delta); 670 gfx::Vector2dF unscrolled = layer()->ScrollBy(scroll_delta);
659 671
660 EXPECT_VECTOR_EQ(gfx::Vector2dF(0, 8.5f), unscrolled); 672 EXPECT_VECTOR_EQ(gfx::Vector2dF(0, 8.5f), unscrolled);
661 EXPECT_VECTOR_EQ(gfx::Vector2dF(30.5f, 5), layer()->TotalScrollOffset()); 673 EXPECT_VECTOR_EQ(gfx::Vector2dF(30.5f, 5), layer()->TotalScrollOffset());
662 } 674 }
663 675
664 TEST_F(LayerImplScrollTest, SetNewScrollbarParameters) { 676 TEST_F(LayerImplScrollTest, SetNewScrollbarParameters) {
665 gfx::Vector2d scroll_offset(10, 5); 677 gfx::ScrollOffset scroll_offset(10, 5);
666 layer()->SetScrollOffset(scroll_offset); 678 layer()->SetScrollOffset(scroll_offset);
667 679
668 scoped_ptr<PaintedScrollbarLayerImpl> vertical_scrollbar( 680 scoped_ptr<PaintedScrollbarLayerImpl> vertical_scrollbar(
669 PaintedScrollbarLayerImpl::Create(tree(), 100, VERTICAL)); 681 PaintedScrollbarLayerImpl::Create(tree(), 100, VERTICAL));
670 vertical_scrollbar->SetScrollLayerAndClipLayerByIds( 682 vertical_scrollbar->SetScrollLayerAndClipLayerByIds(
671 layer()->id(), tree()->root_layer()->id()); 683 layer()->id(), tree()->root_layer()->id());
672 684
673 int expected_vertical_maximum = 685 int expected_vertical_maximum =
674 layer()->bounds().height() - tree()->root_layer()->bounds().height(); 686 layer()->bounds().height() - tree()->root_layer()->bounds().height();
675 EXPECT_EQ(expected_vertical_maximum, vertical_scrollbar->maximum()); 687 EXPECT_EQ(expected_vertical_maximum, vertical_scrollbar->maximum());
676 EXPECT_EQ(scroll_offset.y(), vertical_scrollbar->current_pos()); 688 EXPECT_EQ(scroll_offset.y(), vertical_scrollbar->current_pos());
677 689
678 scoped_ptr<PaintedScrollbarLayerImpl> horizontal_scrollbar( 690 scoped_ptr<PaintedScrollbarLayerImpl> horizontal_scrollbar(
679 PaintedScrollbarLayerImpl::Create(tree(), 101, HORIZONTAL)); 691 PaintedScrollbarLayerImpl::Create(tree(), 101, HORIZONTAL));
680 horizontal_scrollbar->SetScrollLayerAndClipLayerByIds( 692 horizontal_scrollbar->SetScrollLayerAndClipLayerByIds(
681 layer()->id(), tree()->root_layer()->id()); 693 layer()->id(), tree()->root_layer()->id());
682 694
683 int expected_horizontal_maximum = 695 int expected_horizontal_maximum =
684 layer()->bounds().width() - tree()->root_layer()->bounds().width(); 696 layer()->bounds().width() - tree()->root_layer()->bounds().width();
685 EXPECT_EQ(expected_horizontal_maximum, horizontal_scrollbar->maximum()); 697 EXPECT_EQ(expected_horizontal_maximum, horizontal_scrollbar->maximum());
686 EXPECT_EQ(scroll_offset.x(), horizontal_scrollbar->current_pos()); 698 EXPECT_EQ(scroll_offset.x(), horizontal_scrollbar->current_pos());
687 } 699 }
688 700
689 } // namespace 701 } // namespace
690 } // namespace cc 702 } // namespace cc
OLDNEW
« no previous file with comments | « cc/layers/layer_impl.cc ('k') | cc/layers/layer_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698