OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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 <map> | 5 #include <map> |
6 | 6 |
7 #include "base/memory/scoped_ptr.h" | 7 #include "base/memory/scoped_ptr.h" |
8 #include "base/rand_util.h" | 8 #include "base/rand_util.h" |
9 #include "base/strings/string_util.h" | 9 #include "base/strings/string_util.h" |
10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
(...skipping 3383 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3394 DISALLOW_COPY_AND_ASSIGN(PaintTrackingView); | 3394 DISALLOW_COPY_AND_ASSIGN(PaintTrackingView); |
3395 }; | 3395 }; |
3396 | 3396 |
3397 // Makes sure child views with layers aren't painted when paint starts at an | 3397 // Makes sure child views with layers aren't painted when paint starts at an |
3398 // ancestor. | 3398 // ancestor. |
3399 TEST_F(ViewLayerTest, DontPaintChildrenWithLayers) { | 3399 TEST_F(ViewLayerTest, DontPaintChildrenWithLayers) { |
3400 PaintTrackingView* content_view = new PaintTrackingView; | 3400 PaintTrackingView* content_view = new PaintTrackingView; |
3401 widget()->SetContentsView(content_view); | 3401 widget()->SetContentsView(content_view); |
3402 content_view->SetPaintToLayer(true); | 3402 content_view->SetPaintToLayer(true); |
3403 GetRootLayer()->GetCompositor()->ScheduleDraw(); | 3403 GetRootLayer()->GetCompositor()->ScheduleDraw(); |
3404 ui::DrawWaiterForTest::Wait(GetRootLayer()->GetCompositor()); | 3404 ui::DrawWaiterForTest::WaitForCompositingEnded( |
| 3405 GetRootLayer()->GetCompositor()); |
3405 GetRootLayer()->SchedulePaint(gfx::Rect(0, 0, 10, 10)); | 3406 GetRootLayer()->SchedulePaint(gfx::Rect(0, 0, 10, 10)); |
3406 content_view->set_painted(false); | 3407 content_view->set_painted(false); |
3407 // content_view no longer has a dirty rect. Paint from the root and make sure | 3408 // content_view no longer has a dirty rect. Paint from the root and make sure |
3408 // PaintTrackingView isn't painted. | 3409 // PaintTrackingView isn't painted. |
3409 GetRootLayer()->GetCompositor()->ScheduleDraw(); | 3410 GetRootLayer()->GetCompositor()->ScheduleDraw(); |
3410 ui::DrawWaiterForTest::Wait(GetRootLayer()->GetCompositor()); | 3411 ui::DrawWaiterForTest::WaitForCompositingEnded( |
| 3412 GetRootLayer()->GetCompositor()); |
3411 EXPECT_FALSE(content_view->painted()); | 3413 EXPECT_FALSE(content_view->painted()); |
3412 | 3414 |
3413 // Make content_view have a dirty rect, paint the layers and make sure | 3415 // Make content_view have a dirty rect, paint the layers and make sure |
3414 // PaintTrackingView is painted. | 3416 // PaintTrackingView is painted. |
3415 content_view->layer()->SchedulePaint(gfx::Rect(0, 0, 10, 10)); | 3417 content_view->layer()->SchedulePaint(gfx::Rect(0, 0, 10, 10)); |
3416 GetRootLayer()->GetCompositor()->ScheduleDraw(); | 3418 GetRootLayer()->GetCompositor()->ScheduleDraw(); |
3417 ui::DrawWaiterForTest::Wait(GetRootLayer()->GetCompositor()); | 3419 ui::DrawWaiterForTest::WaitForCompositingEnded( |
| 3420 GetRootLayer()->GetCompositor()); |
3418 EXPECT_TRUE(content_view->painted()); | 3421 EXPECT_TRUE(content_view->painted()); |
3419 } | 3422 } |
3420 | 3423 |
3421 // Tests that the visibility of child layers are updated correctly when a View's | 3424 // Tests that the visibility of child layers are updated correctly when a View's |
3422 // visibility changes. | 3425 // visibility changes. |
3423 TEST_F(ViewLayerTest, VisibilityChildLayers) { | 3426 TEST_F(ViewLayerTest, VisibilityChildLayers) { |
3424 View* v1 = new View; | 3427 View* v1 = new View; |
3425 v1->SetPaintToLayer(true); | 3428 v1->SetPaintToLayer(true); |
3426 widget()->SetContentsView(v1); | 3429 widget()->SetContentsView(v1); |
3427 | 3430 |
(...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3647 v1->SetBoundsRect(gfx::Rect(10, 15, 150, 151)); | 3650 v1->SetBoundsRect(gfx::Rect(10, 15, 150, 151)); |
3648 test_view->AddChildView(v1); | 3651 test_view->AddChildView(v1); |
3649 | 3652 |
3650 View* v2 = new View(); | 3653 View* v2 = new View(); |
3651 v2->SetBoundsRect(gfx::Rect(20, 33, 40, 50)); | 3654 v2->SetBoundsRect(gfx::Rect(20, 33, 40, 50)); |
3652 v1->AddChildView(v2); | 3655 v1->AddChildView(v2); |
3653 | 3656 |
3654 // Schedule a full-view paint to get everyone's rectangles updated. | 3657 // Schedule a full-view paint to get everyone's rectangles updated. |
3655 test_view->SchedulePaintInRect(test_view->bounds()); | 3658 test_view->SchedulePaintInRect(test_view->bounds()); |
3656 GetRootLayer()->GetCompositor()->ScheduleDraw(); | 3659 GetRootLayer()->GetCompositor()->ScheduleDraw(); |
3657 ui::DrawWaiterForTest::Wait(GetRootLayer()->GetCompositor()); | 3660 ui::DrawWaiterForTest::WaitForCompositingEnded( |
| 3661 GetRootLayer()->GetCompositor()); |
3658 | 3662 |
3659 // Now we have test_view - v1 - v2. Damage to only test_view should only | 3663 // Now we have test_view - v1 - v2. Damage to only test_view should only |
3660 // return root_view and test_view. | 3664 // return root_view and test_view. |
3661 test_view->SchedulePaintInRect(gfx::Rect(0, 0, 1, 1)); | 3665 test_view->SchedulePaintInRect(gfx::Rect(0, 0, 1, 1)); |
3662 GetRootLayer()->GetCompositor()->ScheduleDraw(); | 3666 GetRootLayer()->GetCompositor()->ScheduleDraw(); |
3663 ui::DrawWaiterForTest::Wait(GetRootLayer()->GetCompositor()); | 3667 ui::DrawWaiterForTest::WaitForCompositingEnded( |
| 3668 GetRootLayer()->GetCompositor()); |
3664 EXPECT_EQ(2U, test_view->last_cull_set_.size()); | 3669 EXPECT_EQ(2U, test_view->last_cull_set_.size()); |
3665 EXPECT_EQ(1U, test_view->last_cull_set_.count(widget()->GetRootView())); | 3670 EXPECT_EQ(1U, test_view->last_cull_set_.count(widget()->GetRootView())); |
3666 EXPECT_EQ(1U, test_view->last_cull_set_.count(test_view)); | 3671 EXPECT_EQ(1U, test_view->last_cull_set_.count(test_view)); |
3667 | 3672 |
3668 // Damage to v1 only should only return root_view, test_view, and v1. | 3673 // Damage to v1 only should only return root_view, test_view, and v1. |
3669 test_view->SchedulePaintInRect(gfx::Rect(11, 16, 1, 1)); | 3674 test_view->SchedulePaintInRect(gfx::Rect(11, 16, 1, 1)); |
3670 GetRootLayer()->GetCompositor()->ScheduleDraw(); | 3675 GetRootLayer()->GetCompositor()->ScheduleDraw(); |
3671 ui::DrawWaiterForTest::Wait(GetRootLayer()->GetCompositor()); | 3676 ui::DrawWaiterForTest::WaitForCompositingEnded( |
| 3677 GetRootLayer()->GetCompositor()); |
3672 EXPECT_EQ(3U, test_view->last_cull_set_.size()); | 3678 EXPECT_EQ(3U, test_view->last_cull_set_.size()); |
3673 EXPECT_EQ(1U, test_view->last_cull_set_.count(widget()->GetRootView())); | 3679 EXPECT_EQ(1U, test_view->last_cull_set_.count(widget()->GetRootView())); |
3674 EXPECT_EQ(1U, test_view->last_cull_set_.count(test_view)); | 3680 EXPECT_EQ(1U, test_view->last_cull_set_.count(test_view)); |
3675 EXPECT_EQ(1U, test_view->last_cull_set_.count(v1)); | 3681 EXPECT_EQ(1U, test_view->last_cull_set_.count(v1)); |
3676 | 3682 |
3677 // A Damage rect inside v2 should get all 3 views back in the |last_cull_set_| | 3683 // A Damage rect inside v2 should get all 3 views back in the |last_cull_set_| |
3678 // on call to TestView::Paint(), along with the widget root view. | 3684 // on call to TestView::Paint(), along with the widget root view. |
3679 test_view->SchedulePaintInRect(gfx::Rect(31, 49, 1, 1)); | 3685 test_view->SchedulePaintInRect(gfx::Rect(31, 49, 1, 1)); |
3680 GetRootLayer()->GetCompositor()->ScheduleDraw(); | 3686 GetRootLayer()->GetCompositor()->ScheduleDraw(); |
3681 ui::DrawWaiterForTest::Wait(GetRootLayer()->GetCompositor()); | 3687 ui::DrawWaiterForTest::WaitForCompositingEnded( |
| 3688 GetRootLayer()->GetCompositor()); |
3682 EXPECT_EQ(4U, test_view->last_cull_set_.size()); | 3689 EXPECT_EQ(4U, test_view->last_cull_set_.size()); |
3683 EXPECT_EQ(1U, test_view->last_cull_set_.count(widget()->GetRootView())); | 3690 EXPECT_EQ(1U, test_view->last_cull_set_.count(widget()->GetRootView())); |
3684 EXPECT_EQ(1U, test_view->last_cull_set_.count(test_view)); | 3691 EXPECT_EQ(1U, test_view->last_cull_set_.count(test_view)); |
3685 EXPECT_EQ(1U, test_view->last_cull_set_.count(v1)); | 3692 EXPECT_EQ(1U, test_view->last_cull_set_.count(v1)); |
3686 EXPECT_EQ(1U, test_view->last_cull_set_.count(v2)); | 3693 EXPECT_EQ(1U, test_view->last_cull_set_.count(v2)); |
3687 } | 3694 } |
3688 | 3695 |
3689 TEST_F(ViewLayerTest, BoundsTreeWithRTL) { | 3696 TEST_F(ViewLayerTest, BoundsTreeWithRTL) { |
3690 std::string locale = l10n_util::GetApplicationLocale(std::string()); | 3697 std::string locale = l10n_util::GetApplicationLocale(std::string()); |
3691 base::i18n::SetICUDefaultLocale("ar"); | 3698 base::i18n::SetICUDefaultLocale("ar"); |
3692 | 3699 |
3693 BoundsTreeTestView* test_view = new BoundsTreeTestView; | 3700 BoundsTreeTestView* test_view = new BoundsTreeTestView; |
3694 widget()->SetContentsView(test_view); | 3701 widget()->SetContentsView(test_view); |
3695 | 3702 |
3696 // Add child views, which should be in RTL coordinate space of parent view. | 3703 // Add child views, which should be in RTL coordinate space of parent view. |
3697 View* v1 = new View; | 3704 View* v1 = new View; |
3698 v1->SetBoundsRect(gfx::Rect(10, 12, 25, 26)); | 3705 v1->SetBoundsRect(gfx::Rect(10, 12, 25, 26)); |
3699 test_view->AddChildView(v1); | 3706 test_view->AddChildView(v1); |
3700 | 3707 |
3701 View* v2 = new View; | 3708 View* v2 = new View; |
3702 v2->SetBoundsRect(gfx::Rect(5, 6, 7, 8)); | 3709 v2->SetBoundsRect(gfx::Rect(5, 6, 7, 8)); |
3703 v1->AddChildView(v2); | 3710 v1->AddChildView(v2); |
3704 | 3711 |
3705 // Schedule a full-view paint to get everyone's rectangles updated. | 3712 // Schedule a full-view paint to get everyone's rectangles updated. |
3706 test_view->SchedulePaintInRect(test_view->bounds()); | 3713 test_view->SchedulePaintInRect(test_view->bounds()); |
3707 GetRootLayer()->GetCompositor()->ScheduleDraw(); | 3714 GetRootLayer()->GetCompositor()->ScheduleDraw(); |
3708 ui::DrawWaiterForTest::Wait(GetRootLayer()->GetCompositor()); | 3715 ui::DrawWaiterForTest::WaitForCompositingEnded( |
| 3716 GetRootLayer()->GetCompositor()); |
3709 | 3717 |
3710 // Damage to the right side of the parent view should touch both child views. | 3718 // Damage to the right side of the parent view should touch both child views. |
3711 gfx::Rect rtl_damage(test_view->bounds().width() - 16, 18, 1, 1); | 3719 gfx::Rect rtl_damage(test_view->bounds().width() - 16, 18, 1, 1); |
3712 test_view->SchedulePaintInRect(rtl_damage); | 3720 test_view->SchedulePaintInRect(rtl_damage); |
3713 GetRootLayer()->GetCompositor()->ScheduleDraw(); | 3721 GetRootLayer()->GetCompositor()->ScheduleDraw(); |
3714 ui::DrawWaiterForTest::Wait(GetRootLayer()->GetCompositor()); | 3722 ui::DrawWaiterForTest::WaitForCompositingEnded( |
| 3723 GetRootLayer()->GetCompositor()); |
3715 EXPECT_EQ(4U, test_view->last_cull_set_.size()); | 3724 EXPECT_EQ(4U, test_view->last_cull_set_.size()); |
3716 EXPECT_EQ(1U, test_view->last_cull_set_.count(widget()->GetRootView())); | 3725 EXPECT_EQ(1U, test_view->last_cull_set_.count(widget()->GetRootView())); |
3717 EXPECT_EQ(1U, test_view->last_cull_set_.count(test_view)); | 3726 EXPECT_EQ(1U, test_view->last_cull_set_.count(test_view)); |
3718 EXPECT_EQ(1U, test_view->last_cull_set_.count(v1)); | 3727 EXPECT_EQ(1U, test_view->last_cull_set_.count(v1)); |
3719 EXPECT_EQ(1U, test_view->last_cull_set_.count(v2)); | 3728 EXPECT_EQ(1U, test_view->last_cull_set_.count(v2)); |
3720 | 3729 |
3721 // Damage to the left side of the parent view should only touch the | 3730 // Damage to the left side of the parent view should only touch the |
3722 // container views. | 3731 // container views. |
3723 gfx::Rect ltr_damage(16, 18, 1, 1); | 3732 gfx::Rect ltr_damage(16, 18, 1, 1); |
3724 test_view->SchedulePaintInRect(ltr_damage); | 3733 test_view->SchedulePaintInRect(ltr_damage); |
3725 GetRootLayer()->GetCompositor()->ScheduleDraw(); | 3734 GetRootLayer()->GetCompositor()->ScheduleDraw(); |
3726 ui::DrawWaiterForTest::Wait(GetRootLayer()->GetCompositor()); | 3735 ui::DrawWaiterForTest::WaitForCompositingEnded( |
| 3736 GetRootLayer()->GetCompositor()); |
3727 EXPECT_EQ(2U, test_view->last_cull_set_.size()); | 3737 EXPECT_EQ(2U, test_view->last_cull_set_.size()); |
3728 EXPECT_EQ(1U, test_view->last_cull_set_.count(widget()->GetRootView())); | 3738 EXPECT_EQ(1U, test_view->last_cull_set_.count(widget()->GetRootView())); |
3729 EXPECT_EQ(1U, test_view->last_cull_set_.count(test_view)); | 3739 EXPECT_EQ(1U, test_view->last_cull_set_.count(test_view)); |
3730 | 3740 |
3731 // Reset locale. | 3741 // Reset locale. |
3732 base::i18n::SetICUDefaultLocale(locale); | 3742 base::i18n::SetICUDefaultLocale(locale); |
3733 } | 3743 } |
3734 | 3744 |
3735 TEST_F(ViewLayerTest, BoundsTreeSetBoundsChangesCullSet) { | 3745 TEST_F(ViewLayerTest, BoundsTreeSetBoundsChangesCullSet) { |
3736 BoundsTreeTestView* test_view = new BoundsTreeTestView; | 3746 BoundsTreeTestView* test_view = new BoundsTreeTestView; |
3737 widget()->SetContentsView(test_view); | 3747 widget()->SetContentsView(test_view); |
3738 | 3748 |
3739 View* v1 = new View; | 3749 View* v1 = new View; |
3740 v1->SetBoundsRect(gfx::Rect(5, 6, 100, 101)); | 3750 v1->SetBoundsRect(gfx::Rect(5, 6, 100, 101)); |
3741 test_view->AddChildView(v1); | 3751 test_view->AddChildView(v1); |
3742 | 3752 |
3743 View* v2 = new View; | 3753 View* v2 = new View; |
3744 v2->SetBoundsRect(gfx::Rect(20, 33, 40, 50)); | 3754 v2->SetBoundsRect(gfx::Rect(20, 33, 40, 50)); |
3745 v1->AddChildView(v2); | 3755 v1->AddChildView(v2); |
3746 | 3756 |
3747 // Schedule a full-view paint to get everyone's rectangles updated. | 3757 // Schedule a full-view paint to get everyone's rectangles updated. |
3748 test_view->SchedulePaintInRect(test_view->bounds()); | 3758 test_view->SchedulePaintInRect(test_view->bounds()); |
3749 GetRootLayer()->GetCompositor()->ScheduleDraw(); | 3759 GetRootLayer()->GetCompositor()->ScheduleDraw(); |
3750 ui::DrawWaiterForTest::Wait(GetRootLayer()->GetCompositor()); | 3760 ui::DrawWaiterForTest::WaitForCompositingEnded( |
| 3761 GetRootLayer()->GetCompositor()); |
3751 | 3762 |
3752 // Move v1 to a new origin out of the way of our next query. | 3763 // Move v1 to a new origin out of the way of our next query. |
3753 v1->SetBoundsRect(gfx::Rect(50, 60, 100, 101)); | 3764 v1->SetBoundsRect(gfx::Rect(50, 60, 100, 101)); |
3754 // The move will force a repaint. | 3765 // The move will force a repaint. |
3755 GetRootLayer()->GetCompositor()->ScheduleDraw(); | 3766 GetRootLayer()->GetCompositor()->ScheduleDraw(); |
3756 ui::DrawWaiterForTest::Wait(GetRootLayer()->GetCompositor()); | 3767 ui::DrawWaiterForTest::WaitForCompositingEnded( |
| 3768 GetRootLayer()->GetCompositor()); |
3757 | 3769 |
3758 // Schedule a paint with damage rect where v1 used to be. | 3770 // Schedule a paint with damage rect where v1 used to be. |
3759 test_view->SchedulePaintInRect(gfx::Rect(5, 6, 10, 11)); | 3771 test_view->SchedulePaintInRect(gfx::Rect(5, 6, 10, 11)); |
3760 GetRootLayer()->GetCompositor()->ScheduleDraw(); | 3772 GetRootLayer()->GetCompositor()->ScheduleDraw(); |
3761 ui::DrawWaiterForTest::Wait(GetRootLayer()->GetCompositor()); | 3773 ui::DrawWaiterForTest::WaitForCompositingEnded( |
| 3774 GetRootLayer()->GetCompositor()); |
3762 | 3775 |
3763 // Should only have picked up root_view and test_view. | 3776 // Should only have picked up root_view and test_view. |
3764 EXPECT_EQ(2U, test_view->last_cull_set_.size()); | 3777 EXPECT_EQ(2U, test_view->last_cull_set_.size()); |
3765 EXPECT_EQ(1U, test_view->last_cull_set_.count(widget()->GetRootView())); | 3778 EXPECT_EQ(1U, test_view->last_cull_set_.count(widget()->GetRootView())); |
3766 EXPECT_EQ(1U, test_view->last_cull_set_.count(test_view)); | 3779 EXPECT_EQ(1U, test_view->last_cull_set_.count(test_view)); |
3767 } | 3780 } |
3768 | 3781 |
3769 TEST_F(ViewLayerTest, BoundsTreeLayerChangeMakesNewTree) { | 3782 TEST_F(ViewLayerTest, BoundsTreeLayerChangeMakesNewTree) { |
3770 BoundsTreeTestView* test_view = new BoundsTreeTestView; | 3783 BoundsTreeTestView* test_view = new BoundsTreeTestView; |
3771 widget()->SetContentsView(test_view); | 3784 widget()->SetContentsView(test_view); |
3772 | 3785 |
3773 View* v1 = new View; | 3786 View* v1 = new View; |
3774 v1->SetBoundsRect(gfx::Rect(5, 10, 15, 20)); | 3787 v1->SetBoundsRect(gfx::Rect(5, 10, 15, 20)); |
3775 test_view->AddChildView(v1); | 3788 test_view->AddChildView(v1); |
3776 | 3789 |
3777 View* v2 = new View; | 3790 View* v2 = new View; |
3778 v2->SetBoundsRect(gfx::Rect(1, 2, 3, 4)); | 3791 v2->SetBoundsRect(gfx::Rect(1, 2, 3, 4)); |
3779 v1->AddChildView(v2); | 3792 v1->AddChildView(v2); |
3780 | 3793 |
3781 // Schedule a full-view paint to get everyone's rectangles updated. | 3794 // Schedule a full-view paint to get everyone's rectangles updated. |
3782 test_view->SchedulePaintInRect(test_view->bounds()); | 3795 test_view->SchedulePaintInRect(test_view->bounds()); |
3783 GetRootLayer()->GetCompositor()->ScheduleDraw(); | 3796 GetRootLayer()->GetCompositor()->ScheduleDraw(); |
3784 ui::DrawWaiterForTest::Wait(GetRootLayer()->GetCompositor()); | 3797 ui::DrawWaiterForTest::WaitForCompositingEnded( |
| 3798 GetRootLayer()->GetCompositor()); |
3785 | 3799 |
3786 // Set v1 to paint to its own layer, it should remove itself from the | 3800 // Set v1 to paint to its own layer, it should remove itself from the |
3787 // test_view heiarchy and no longer intersect with damage rects in that cull | 3801 // test_view heiarchy and no longer intersect with damage rects in that cull |
3788 // set. | 3802 // set. |
3789 v1->SetPaintToLayer(true); | 3803 v1->SetPaintToLayer(true); |
3790 | 3804 |
3791 // Schedule another full-view paint. | 3805 // Schedule another full-view paint. |
3792 test_view->SchedulePaintInRect(test_view->bounds()); | 3806 test_view->SchedulePaintInRect(test_view->bounds()); |
3793 GetRootLayer()->GetCompositor()->ScheduleDraw(); | 3807 GetRootLayer()->GetCompositor()->ScheduleDraw(); |
3794 ui::DrawWaiterForTest::Wait(GetRootLayer()->GetCompositor()); | 3808 ui::DrawWaiterForTest::WaitForCompositingEnded( |
| 3809 GetRootLayer()->GetCompositor()); |
3795 // v1 and v2 should no longer be present in the test_view cull_set. | 3810 // v1 and v2 should no longer be present in the test_view cull_set. |
3796 EXPECT_EQ(2U, test_view->last_cull_set_.size()); | 3811 EXPECT_EQ(2U, test_view->last_cull_set_.size()); |
3797 EXPECT_EQ(0U, test_view->last_cull_set_.count(v1)); | 3812 EXPECT_EQ(0U, test_view->last_cull_set_.count(v1)); |
3798 EXPECT_EQ(0U, test_view->last_cull_set_.count(v2)); | 3813 EXPECT_EQ(0U, test_view->last_cull_set_.count(v2)); |
3799 | 3814 |
3800 // Now set v1 back to not painting to a layer. | 3815 // Now set v1 back to not painting to a layer. |
3801 v1->SetPaintToLayer(false); | 3816 v1->SetPaintToLayer(false); |
3802 // Schedule another full-view paint. | 3817 // Schedule another full-view paint. |
3803 test_view->SchedulePaintInRect(test_view->bounds()); | 3818 test_view->SchedulePaintInRect(test_view->bounds()); |
3804 GetRootLayer()->GetCompositor()->ScheduleDraw(); | 3819 GetRootLayer()->GetCompositor()->ScheduleDraw(); |
3805 ui::DrawWaiterForTest::Wait(GetRootLayer()->GetCompositor()); | 3820 ui::DrawWaiterForTest::WaitForCompositingEnded( |
| 3821 GetRootLayer()->GetCompositor()); |
3806 // We should be back to the full cull set including v1 and v2. | 3822 // We should be back to the full cull set including v1 and v2. |
3807 EXPECT_EQ(4U, test_view->last_cull_set_.size()); | 3823 EXPECT_EQ(4U, test_view->last_cull_set_.size()); |
3808 EXPECT_EQ(1U, test_view->last_cull_set_.count(widget()->GetRootView())); | 3824 EXPECT_EQ(1U, test_view->last_cull_set_.count(widget()->GetRootView())); |
3809 EXPECT_EQ(1U, test_view->last_cull_set_.count(test_view)); | 3825 EXPECT_EQ(1U, test_view->last_cull_set_.count(test_view)); |
3810 EXPECT_EQ(1U, test_view->last_cull_set_.count(v1)); | 3826 EXPECT_EQ(1U, test_view->last_cull_set_.count(v1)); |
3811 EXPECT_EQ(1U, test_view->last_cull_set_.count(v2)); | 3827 EXPECT_EQ(1U, test_view->last_cull_set_.count(v2)); |
3812 } | 3828 } |
3813 | 3829 |
3814 TEST_F(ViewLayerTest, BoundsTreeRemoveChildRemovesBounds) { | 3830 TEST_F(ViewLayerTest, BoundsTreeRemoveChildRemovesBounds) { |
3815 BoundsTreeTestView* test_view = new BoundsTreeTestView; | 3831 BoundsTreeTestView* test_view = new BoundsTreeTestView; |
3816 widget()->SetContentsView(test_view); | 3832 widget()->SetContentsView(test_view); |
3817 | 3833 |
3818 View* v1 = new View; | 3834 View* v1 = new View; |
3819 v1->SetBoundsRect(gfx::Rect(5, 10, 15, 20)); | 3835 v1->SetBoundsRect(gfx::Rect(5, 10, 15, 20)); |
3820 test_view->AddChildView(v1); | 3836 test_view->AddChildView(v1); |
3821 | 3837 |
3822 View* v2 = new View; | 3838 View* v2 = new View; |
3823 v2->SetBoundsRect(gfx::Rect(1, 2, 3, 4)); | 3839 v2->SetBoundsRect(gfx::Rect(1, 2, 3, 4)); |
3824 v1->AddChildView(v2); | 3840 v1->AddChildView(v2); |
3825 | 3841 |
3826 // Schedule a full-view paint to get everyone's rectangles updated. | 3842 // Schedule a full-view paint to get everyone's rectangles updated. |
3827 test_view->SchedulePaintInRect(test_view->bounds()); | 3843 test_view->SchedulePaintInRect(test_view->bounds()); |
3828 GetRootLayer()->GetCompositor()->ScheduleDraw(); | 3844 GetRootLayer()->GetCompositor()->ScheduleDraw(); |
3829 ui::DrawWaiterForTest::Wait(GetRootLayer()->GetCompositor()); | 3845 ui::DrawWaiterForTest::WaitForCompositingEnded( |
| 3846 GetRootLayer()->GetCompositor()); |
3830 | 3847 |
3831 // Now remove v1 from the root view. | 3848 // Now remove v1 from the root view. |
3832 test_view->RemoveChildView(v1); | 3849 test_view->RemoveChildView(v1); |
3833 | 3850 |
3834 // Schedule another full-view paint. | 3851 // Schedule another full-view paint. |
3835 test_view->SchedulePaintInRect(test_view->bounds()); | 3852 test_view->SchedulePaintInRect(test_view->bounds()); |
3836 GetRootLayer()->GetCompositor()->ScheduleDraw(); | 3853 GetRootLayer()->GetCompositor()->ScheduleDraw(); |
3837 ui::DrawWaiterForTest::Wait(GetRootLayer()->GetCompositor()); | 3854 ui::DrawWaiterForTest::WaitForCompositingEnded( |
| 3855 GetRootLayer()->GetCompositor()); |
3838 // v1 and v2 should no longer be present in the test_view cull_set. | 3856 // v1 and v2 should no longer be present in the test_view cull_set. |
3839 EXPECT_EQ(2U, test_view->last_cull_set_.size()); | 3857 EXPECT_EQ(2U, test_view->last_cull_set_.size()); |
3840 EXPECT_EQ(0U, test_view->last_cull_set_.count(v1)); | 3858 EXPECT_EQ(0U, test_view->last_cull_set_.count(v1)); |
3841 EXPECT_EQ(0U, test_view->last_cull_set_.count(v2)); | 3859 EXPECT_EQ(0U, test_view->last_cull_set_.count(v2)); |
3842 | 3860 |
3843 // View v1 and v2 are no longer part of view hierarchy and therefore won't be | 3861 // View v1 and v2 are no longer part of view hierarchy and therefore won't be |
3844 // deleted with that hierarchy. | 3862 // deleted with that hierarchy. |
3845 delete v1; | 3863 delete v1; |
3846 } | 3864 } |
3847 | 3865 |
(...skipping 10 matching lines...) Expand all Loading... |
3858 v2->SetBoundsRect(gfx::Rect(5, 10, 40, 50)); | 3876 v2->SetBoundsRect(gfx::Rect(5, 10, 40, 50)); |
3859 v1->AddChildView(v2); | 3877 v1->AddChildView(v2); |
3860 | 3878 |
3861 View* v3 = new View; | 3879 View* v3 = new View; |
3862 v3->SetBoundsRect(gfx::Rect(1, 2, 3, 4)); | 3880 v3->SetBoundsRect(gfx::Rect(1, 2, 3, 4)); |
3863 v2->AddChildView(v3); | 3881 v2->AddChildView(v3); |
3864 | 3882 |
3865 // Schedule a full-view paint and ensure all views are present in the cull. | 3883 // Schedule a full-view paint and ensure all views are present in the cull. |
3866 test_view->SchedulePaintInRect(test_view->bounds()); | 3884 test_view->SchedulePaintInRect(test_view->bounds()); |
3867 GetRootLayer()->GetCompositor()->ScheduleDraw(); | 3885 GetRootLayer()->GetCompositor()->ScheduleDraw(); |
3868 ui::DrawWaiterForTest::Wait(GetRootLayer()->GetCompositor()); | 3886 ui::DrawWaiterForTest::WaitForCompositingEnded( |
| 3887 GetRootLayer()->GetCompositor()); |
3869 EXPECT_EQ(5U, test_view->last_cull_set_.size()); | 3888 EXPECT_EQ(5U, test_view->last_cull_set_.size()); |
3870 EXPECT_EQ(1U, test_view->last_cull_set_.count(widget()->GetRootView())); | 3889 EXPECT_EQ(1U, test_view->last_cull_set_.count(widget()->GetRootView())); |
3871 EXPECT_EQ(1U, test_view->last_cull_set_.count(test_view)); | 3890 EXPECT_EQ(1U, test_view->last_cull_set_.count(test_view)); |
3872 EXPECT_EQ(1U, test_view->last_cull_set_.count(v1)); | 3891 EXPECT_EQ(1U, test_view->last_cull_set_.count(v1)); |
3873 EXPECT_EQ(1U, test_view->last_cull_set_.count(v2)); | 3892 EXPECT_EQ(1U, test_view->last_cull_set_.count(v2)); |
3874 EXPECT_EQ(1U, test_view->last_cull_set_.count(v3)); | 3893 EXPECT_EQ(1U, test_view->last_cull_set_.count(v3)); |
3875 | 3894 |
3876 // Build an unrelated view hierarchy and move v2 in to it. | 3895 // Build an unrelated view hierarchy and move v2 in to it. |
3877 scoped_ptr<Widget> test_widget(new Widget); | 3896 scoped_ptr<Widget> test_widget(new Widget); |
3878 Widget::InitParams params = CreateParams(Widget::InitParams::TYPE_POPUP); | 3897 Widget::InitParams params = CreateParams(Widget::InitParams::TYPE_POPUP); |
3879 params.bounds = gfx::Rect(10, 10, 500, 500); | 3898 params.bounds = gfx::Rect(10, 10, 500, 500); |
3880 params.ownership = Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; | 3899 params.ownership = Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; |
3881 test_widget->Init(params); | 3900 test_widget->Init(params); |
3882 test_widget->Show(); | 3901 test_widget->Show(); |
3883 BoundsTreeTestView* widget_view = new BoundsTreeTestView; | 3902 BoundsTreeTestView* widget_view = new BoundsTreeTestView; |
3884 test_widget->SetContentsView(widget_view); | 3903 test_widget->SetContentsView(widget_view); |
3885 widget_view->AddChildView(v2); | 3904 widget_view->AddChildView(v2); |
3886 | 3905 |
3887 // Now schedule full-view paints in both widgets. | 3906 // Now schedule full-view paints in both widgets. |
3888 test_view->SchedulePaintInRect(test_view->bounds()); | 3907 test_view->SchedulePaintInRect(test_view->bounds()); |
3889 widget_view->SchedulePaintInRect(widget_view->bounds()); | 3908 widget_view->SchedulePaintInRect(widget_view->bounds()); |
3890 GetRootLayer()->GetCompositor()->ScheduleDraw(); | 3909 GetRootLayer()->GetCompositor()->ScheduleDraw(); |
3891 ui::DrawWaiterForTest::Wait(GetRootLayer()->GetCompositor()); | 3910 ui::DrawWaiterForTest::WaitForCompositingEnded( |
| 3911 GetRootLayer()->GetCompositor()); |
3892 | 3912 |
3893 // Only v1 should be present in the first cull set. | 3913 // Only v1 should be present in the first cull set. |
3894 EXPECT_EQ(3U, test_view->last_cull_set_.size()); | 3914 EXPECT_EQ(3U, test_view->last_cull_set_.size()); |
3895 EXPECT_EQ(1U, test_view->last_cull_set_.count(widget()->GetRootView())); | 3915 EXPECT_EQ(1U, test_view->last_cull_set_.count(widget()->GetRootView())); |
3896 EXPECT_EQ(1U, test_view->last_cull_set_.count(test_view)); | 3916 EXPECT_EQ(1U, test_view->last_cull_set_.count(test_view)); |
3897 EXPECT_EQ(1U, test_view->last_cull_set_.count(v1)); | 3917 EXPECT_EQ(1U, test_view->last_cull_set_.count(v1)); |
3898 | 3918 |
3899 // We should find v2 and v3 in the widget_view cull_set. | 3919 // We should find v2 and v3 in the widget_view cull_set. |
3900 EXPECT_EQ(4U, widget_view->last_cull_set_.size()); | 3920 EXPECT_EQ(4U, widget_view->last_cull_set_.size()); |
3901 EXPECT_EQ(1U, widget_view->last_cull_set_.count(test_widget->GetRootView())); | 3921 EXPECT_EQ(1U, widget_view->last_cull_set_.count(test_widget->GetRootView())); |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3964 // notification. | 3984 // notification. |
3965 TestView* test_view_child_2 = new TestView(); | 3985 TestView* test_view_child_2 = new TestView(); |
3966 test_view->AddChildView(test_view_child_2); | 3986 test_view->AddChildView(test_view_child_2); |
3967 EXPECT_TRUE(test_view_child_2->native_theme_); | 3987 EXPECT_TRUE(test_view_child_2->native_theme_); |
3968 EXPECT_EQ(widget->GetNativeTheme(), test_view_child_2->native_theme_); | 3988 EXPECT_EQ(widget->GetNativeTheme(), test_view_child_2->native_theme_); |
3969 | 3989 |
3970 widget->CloseNow(); | 3990 widget->CloseNow(); |
3971 } | 3991 } |
3972 | 3992 |
3973 } // namespace views | 3993 } // namespace views |
OLD | NEW |