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/stringprintf.h" | 10 #include "base/strings/stringprintf.h" |
(...skipping 3123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3134 DISALLOW_COPY_AND_ASSIGN(PaintTrackingView); | 3134 DISALLOW_COPY_AND_ASSIGN(PaintTrackingView); |
3135 }; | 3135 }; |
3136 | 3136 |
3137 // Makes sure child views with layers aren't painted when paint starts at an | 3137 // Makes sure child views with layers aren't painted when paint starts at an |
3138 // ancestor. | 3138 // ancestor. |
3139 TEST_F(ViewLayerTest, DontPaintChildrenWithLayers) { | 3139 TEST_F(ViewLayerTest, DontPaintChildrenWithLayers) { |
3140 PaintTrackingView* content_view = new PaintTrackingView; | 3140 PaintTrackingView* content_view = new PaintTrackingView; |
3141 widget()->SetContentsView(content_view); | 3141 widget()->SetContentsView(content_view); |
3142 content_view->SetPaintToLayer(true); | 3142 content_view->SetPaintToLayer(true); |
3143 GetRootLayer()->GetCompositor()->ScheduleDraw(); | 3143 GetRootLayer()->GetCompositor()->ScheduleDraw(); |
3144 ui::DrawWaiterForTest::Wait(GetRootLayer()->GetCompositor()); | 3144 ui::DrawWaiterForTest::WaitForCompositingEnded( |
| 3145 GetRootLayer()->GetCompositor()); |
3145 GetRootLayer()->SchedulePaint(gfx::Rect(0, 0, 10, 10)); | 3146 GetRootLayer()->SchedulePaint(gfx::Rect(0, 0, 10, 10)); |
3146 content_view->set_painted(false); | 3147 content_view->set_painted(false); |
3147 // content_view no longer has a dirty rect. Paint from the root and make sure | 3148 // content_view no longer has a dirty rect. Paint from the root and make sure |
3148 // PaintTrackingView isn't painted. | 3149 // PaintTrackingView isn't painted. |
3149 GetRootLayer()->GetCompositor()->ScheduleDraw(); | 3150 GetRootLayer()->GetCompositor()->ScheduleDraw(); |
3150 ui::DrawWaiterForTest::Wait(GetRootLayer()->GetCompositor()); | 3151 ui::DrawWaiterForTest::WaitForCompositingEnded( |
| 3152 GetRootLayer()->GetCompositor()); |
3151 EXPECT_FALSE(content_view->painted()); | 3153 EXPECT_FALSE(content_view->painted()); |
3152 | 3154 |
3153 // Make content_view have a dirty rect, paint the layers and make sure | 3155 // Make content_view have a dirty rect, paint the layers and make sure |
3154 // PaintTrackingView is painted. | 3156 // PaintTrackingView is painted. |
3155 content_view->layer()->SchedulePaint(gfx::Rect(0, 0, 10, 10)); | 3157 content_view->layer()->SchedulePaint(gfx::Rect(0, 0, 10, 10)); |
3156 GetRootLayer()->GetCompositor()->ScheduleDraw(); | 3158 GetRootLayer()->GetCompositor()->ScheduleDraw(); |
3157 ui::DrawWaiterForTest::Wait(GetRootLayer()->GetCompositor()); | 3159 ui::DrawWaiterForTest::WaitForCompositingEnded( |
| 3160 GetRootLayer()->GetCompositor()); |
3158 EXPECT_TRUE(content_view->painted()); | 3161 EXPECT_TRUE(content_view->painted()); |
3159 } | 3162 } |
3160 | 3163 |
3161 // Tests that the visibility of child layers are updated correctly when a View's | 3164 // Tests that the visibility of child layers are updated correctly when a View's |
3162 // visibility changes. | 3165 // visibility changes. |
3163 TEST_F(ViewLayerTest, VisibilityChildLayers) { | 3166 TEST_F(ViewLayerTest, VisibilityChildLayers) { |
3164 View* v1 = new View; | 3167 View* v1 = new View; |
3165 v1->SetPaintToLayer(true); | 3168 v1->SetPaintToLayer(true); |
3166 widget()->SetContentsView(v1); | 3169 widget()->SetContentsView(v1); |
3167 | 3170 |
(...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3386 v1->SetBoundsRect(gfx::Rect(10, 15, 150, 151)); | 3389 v1->SetBoundsRect(gfx::Rect(10, 15, 150, 151)); |
3387 test_view->AddChildView(v1); | 3390 test_view->AddChildView(v1); |
3388 | 3391 |
3389 View* v2 = new View(); | 3392 View* v2 = new View(); |
3390 v2->SetBoundsRect(gfx::Rect(20, 33, 40, 50)); | 3393 v2->SetBoundsRect(gfx::Rect(20, 33, 40, 50)); |
3391 v1->AddChildView(v2); | 3394 v1->AddChildView(v2); |
3392 | 3395 |
3393 // Schedule a full-view paint to get everyone's rectangles updated. | 3396 // Schedule a full-view paint to get everyone's rectangles updated. |
3394 test_view->SchedulePaintInRect(test_view->bounds()); | 3397 test_view->SchedulePaintInRect(test_view->bounds()); |
3395 GetRootLayer()->GetCompositor()->ScheduleDraw(); | 3398 GetRootLayer()->GetCompositor()->ScheduleDraw(); |
3396 ui::DrawWaiterForTest::Wait(GetRootLayer()->GetCompositor()); | 3399 ui::DrawWaiterForTest::WaitForCompositingEnded( |
| 3400 GetRootLayer()->GetCompositor()); |
3397 | 3401 |
3398 // Now we have test_view - v1 - v2. Damage to only test_view should only | 3402 // Now we have test_view - v1 - v2. Damage to only test_view should only |
3399 // return root_view and test_view. | 3403 // return root_view and test_view. |
3400 test_view->SchedulePaintInRect(gfx::Rect(0, 0, 1, 1)); | 3404 test_view->SchedulePaintInRect(gfx::Rect(0, 0, 1, 1)); |
3401 GetRootLayer()->GetCompositor()->ScheduleDraw(); | 3405 GetRootLayer()->GetCompositor()->ScheduleDraw(); |
3402 ui::DrawWaiterForTest::Wait(GetRootLayer()->GetCompositor()); | 3406 ui::DrawWaiterForTest::WaitForCompositingEnded( |
| 3407 GetRootLayer()->GetCompositor()); |
3403 EXPECT_EQ(2U, test_view->last_cull_set_.size()); | 3408 EXPECT_EQ(2U, test_view->last_cull_set_.size()); |
3404 EXPECT_EQ(1U, test_view->last_cull_set_.count(widget()->GetRootView())); | 3409 EXPECT_EQ(1U, test_view->last_cull_set_.count(widget()->GetRootView())); |
3405 EXPECT_EQ(1U, test_view->last_cull_set_.count(test_view)); | 3410 EXPECT_EQ(1U, test_view->last_cull_set_.count(test_view)); |
3406 | 3411 |
3407 // Damage to v1 only should only return root_view, test_view, and v1. | 3412 // Damage to v1 only should only return root_view, test_view, and v1. |
3408 test_view->SchedulePaintInRect(gfx::Rect(11, 16, 1, 1)); | 3413 test_view->SchedulePaintInRect(gfx::Rect(11, 16, 1, 1)); |
3409 GetRootLayer()->GetCompositor()->ScheduleDraw(); | 3414 GetRootLayer()->GetCompositor()->ScheduleDraw(); |
3410 ui::DrawWaiterForTest::Wait(GetRootLayer()->GetCompositor()); | 3415 ui::DrawWaiterForTest::WaitForCompositingEnded( |
| 3416 GetRootLayer()->GetCompositor()); |
3411 EXPECT_EQ(3U, test_view->last_cull_set_.size()); | 3417 EXPECT_EQ(3U, test_view->last_cull_set_.size()); |
3412 EXPECT_EQ(1U, test_view->last_cull_set_.count(widget()->GetRootView())); | 3418 EXPECT_EQ(1U, test_view->last_cull_set_.count(widget()->GetRootView())); |
3413 EXPECT_EQ(1U, test_view->last_cull_set_.count(test_view)); | 3419 EXPECT_EQ(1U, test_view->last_cull_set_.count(test_view)); |
3414 EXPECT_EQ(1U, test_view->last_cull_set_.count(v1)); | 3420 EXPECT_EQ(1U, test_view->last_cull_set_.count(v1)); |
3415 | 3421 |
3416 // A Damage rect inside v2 should get all 3 views back in the |last_cull_set_| | 3422 // A Damage rect inside v2 should get all 3 views back in the |last_cull_set_| |
3417 // on call to TestView::Paint(), along with the widget root view. | 3423 // on call to TestView::Paint(), along with the widget root view. |
3418 test_view->SchedulePaintInRect(gfx::Rect(31, 49, 1, 1)); | 3424 test_view->SchedulePaintInRect(gfx::Rect(31, 49, 1, 1)); |
3419 GetRootLayer()->GetCompositor()->ScheduleDraw(); | 3425 GetRootLayer()->GetCompositor()->ScheduleDraw(); |
3420 ui::DrawWaiterForTest::Wait(GetRootLayer()->GetCompositor()); | 3426 ui::DrawWaiterForTest::WaitForCompositingEnded( |
| 3427 GetRootLayer()->GetCompositor()); |
3421 EXPECT_EQ(4U, test_view->last_cull_set_.size()); | 3428 EXPECT_EQ(4U, test_view->last_cull_set_.size()); |
3422 EXPECT_EQ(1U, test_view->last_cull_set_.count(widget()->GetRootView())); | 3429 EXPECT_EQ(1U, test_view->last_cull_set_.count(widget()->GetRootView())); |
3423 EXPECT_EQ(1U, test_view->last_cull_set_.count(test_view)); | 3430 EXPECT_EQ(1U, test_view->last_cull_set_.count(test_view)); |
3424 EXPECT_EQ(1U, test_view->last_cull_set_.count(v1)); | 3431 EXPECT_EQ(1U, test_view->last_cull_set_.count(v1)); |
3425 EXPECT_EQ(1U, test_view->last_cull_set_.count(v2)); | 3432 EXPECT_EQ(1U, test_view->last_cull_set_.count(v2)); |
3426 } | 3433 } |
3427 | 3434 |
3428 TEST_F(ViewLayerTest, BoundsTreeWithRTL) { | 3435 TEST_F(ViewLayerTest, BoundsTreeWithRTL) { |
3429 std::string locale = l10n_util::GetApplicationLocale(std::string()); | 3436 std::string locale = l10n_util::GetApplicationLocale(std::string()); |
3430 base::i18n::SetICUDefaultLocale("ar"); | 3437 base::i18n::SetICUDefaultLocale("ar"); |
3431 | 3438 |
3432 BoundsTreeTestView* test_view = new BoundsTreeTestView; | 3439 BoundsTreeTestView* test_view = new BoundsTreeTestView; |
3433 widget()->SetContentsView(test_view); | 3440 widget()->SetContentsView(test_view); |
3434 | 3441 |
3435 // Add child views, which should be in RTL coordinate space of parent view. | 3442 // Add child views, which should be in RTL coordinate space of parent view. |
3436 View* v1 = new View; | 3443 View* v1 = new View; |
3437 v1->SetBoundsRect(gfx::Rect(10, 12, 25, 26)); | 3444 v1->SetBoundsRect(gfx::Rect(10, 12, 25, 26)); |
3438 test_view->AddChildView(v1); | 3445 test_view->AddChildView(v1); |
3439 | 3446 |
3440 View* v2 = new View; | 3447 View* v2 = new View; |
3441 v2->SetBoundsRect(gfx::Rect(5, 6, 7, 8)); | 3448 v2->SetBoundsRect(gfx::Rect(5, 6, 7, 8)); |
3442 v1->AddChildView(v2); | 3449 v1->AddChildView(v2); |
3443 | 3450 |
3444 // Schedule a full-view paint to get everyone's rectangles updated. | 3451 // Schedule a full-view paint to get everyone's rectangles updated. |
3445 test_view->SchedulePaintInRect(test_view->bounds()); | 3452 test_view->SchedulePaintInRect(test_view->bounds()); |
3446 GetRootLayer()->GetCompositor()->ScheduleDraw(); | 3453 GetRootLayer()->GetCompositor()->ScheduleDraw(); |
3447 ui::DrawWaiterForTest::Wait(GetRootLayer()->GetCompositor()); | 3454 ui::DrawWaiterForTest::WaitForCompositingEnded( |
| 3455 GetRootLayer()->GetCompositor()); |
3448 | 3456 |
3449 // Damage to the right side of the parent view should touch both child views. | 3457 // Damage to the right side of the parent view should touch both child views. |
3450 gfx::Rect rtl_damage(test_view->bounds().width() - 16, 18, 1, 1); | 3458 gfx::Rect rtl_damage(test_view->bounds().width() - 16, 18, 1, 1); |
3451 test_view->SchedulePaintInRect(rtl_damage); | 3459 test_view->SchedulePaintInRect(rtl_damage); |
3452 GetRootLayer()->GetCompositor()->ScheduleDraw(); | 3460 GetRootLayer()->GetCompositor()->ScheduleDraw(); |
3453 ui::DrawWaiterForTest::Wait(GetRootLayer()->GetCompositor()); | 3461 ui::DrawWaiterForTest::WaitForCompositingEnded( |
| 3462 GetRootLayer()->GetCompositor()); |
3454 EXPECT_EQ(4U, test_view->last_cull_set_.size()); | 3463 EXPECT_EQ(4U, test_view->last_cull_set_.size()); |
3455 EXPECT_EQ(1U, test_view->last_cull_set_.count(widget()->GetRootView())); | 3464 EXPECT_EQ(1U, test_view->last_cull_set_.count(widget()->GetRootView())); |
3456 EXPECT_EQ(1U, test_view->last_cull_set_.count(test_view)); | 3465 EXPECT_EQ(1U, test_view->last_cull_set_.count(test_view)); |
3457 EXPECT_EQ(1U, test_view->last_cull_set_.count(v1)); | 3466 EXPECT_EQ(1U, test_view->last_cull_set_.count(v1)); |
3458 EXPECT_EQ(1U, test_view->last_cull_set_.count(v2)); | 3467 EXPECT_EQ(1U, test_view->last_cull_set_.count(v2)); |
3459 | 3468 |
3460 // Damage to the left side of the parent view should only touch the | 3469 // Damage to the left side of the parent view should only touch the |
3461 // container views. | 3470 // container views. |
3462 gfx::Rect ltr_damage(16, 18, 1, 1); | 3471 gfx::Rect ltr_damage(16, 18, 1, 1); |
3463 test_view->SchedulePaintInRect(ltr_damage); | 3472 test_view->SchedulePaintInRect(ltr_damage); |
3464 GetRootLayer()->GetCompositor()->ScheduleDraw(); | 3473 GetRootLayer()->GetCompositor()->ScheduleDraw(); |
3465 ui::DrawWaiterForTest::Wait(GetRootLayer()->GetCompositor()); | 3474 ui::DrawWaiterForTest::WaitForCompositingEnded( |
| 3475 GetRootLayer()->GetCompositor()); |
3466 EXPECT_EQ(2U, test_view->last_cull_set_.size()); | 3476 EXPECT_EQ(2U, test_view->last_cull_set_.size()); |
3467 EXPECT_EQ(1U, test_view->last_cull_set_.count(widget()->GetRootView())); | 3477 EXPECT_EQ(1U, test_view->last_cull_set_.count(widget()->GetRootView())); |
3468 EXPECT_EQ(1U, test_view->last_cull_set_.count(test_view)); | 3478 EXPECT_EQ(1U, test_view->last_cull_set_.count(test_view)); |
3469 | 3479 |
3470 // Reset locale. | 3480 // Reset locale. |
3471 base::i18n::SetICUDefaultLocale(locale); | 3481 base::i18n::SetICUDefaultLocale(locale); |
3472 } | 3482 } |
3473 | 3483 |
3474 TEST_F(ViewLayerTest, BoundsTreeSetBoundsChangesCullSet) { | 3484 TEST_F(ViewLayerTest, BoundsTreeSetBoundsChangesCullSet) { |
3475 BoundsTreeTestView* test_view = new BoundsTreeTestView; | 3485 BoundsTreeTestView* test_view = new BoundsTreeTestView; |
3476 widget()->SetContentsView(test_view); | 3486 widget()->SetContentsView(test_view); |
3477 | 3487 |
3478 View* v1 = new View; | 3488 View* v1 = new View; |
3479 v1->SetBoundsRect(gfx::Rect(5, 6, 100, 101)); | 3489 v1->SetBoundsRect(gfx::Rect(5, 6, 100, 101)); |
3480 test_view->AddChildView(v1); | 3490 test_view->AddChildView(v1); |
3481 | 3491 |
3482 View* v2 = new View; | 3492 View* v2 = new View; |
3483 v2->SetBoundsRect(gfx::Rect(20, 33, 40, 50)); | 3493 v2->SetBoundsRect(gfx::Rect(20, 33, 40, 50)); |
3484 v1->AddChildView(v2); | 3494 v1->AddChildView(v2); |
3485 | 3495 |
3486 // Schedule a full-view paint to get everyone's rectangles updated. | 3496 // Schedule a full-view paint to get everyone's rectangles updated. |
3487 test_view->SchedulePaintInRect(test_view->bounds()); | 3497 test_view->SchedulePaintInRect(test_view->bounds()); |
3488 GetRootLayer()->GetCompositor()->ScheduleDraw(); | 3498 GetRootLayer()->GetCompositor()->ScheduleDraw(); |
3489 ui::DrawWaiterForTest::Wait(GetRootLayer()->GetCompositor()); | 3499 ui::DrawWaiterForTest::WaitForCompositingEnded( |
| 3500 GetRootLayer()->GetCompositor()); |
3490 | 3501 |
3491 // Move v1 to a new origin out of the way of our next query. | 3502 // Move v1 to a new origin out of the way of our next query. |
3492 v1->SetBoundsRect(gfx::Rect(50, 60, 100, 101)); | 3503 v1->SetBoundsRect(gfx::Rect(50, 60, 100, 101)); |
3493 // The move will force a repaint. | 3504 // The move will force a repaint. |
3494 GetRootLayer()->GetCompositor()->ScheduleDraw(); | 3505 GetRootLayer()->GetCompositor()->ScheduleDraw(); |
3495 ui::DrawWaiterForTest::Wait(GetRootLayer()->GetCompositor()); | 3506 ui::DrawWaiterForTest::WaitForCompositingEnded( |
| 3507 GetRootLayer()->GetCompositor()); |
3496 | 3508 |
3497 // Schedule a paint with damage rect where v1 used to be. | 3509 // Schedule a paint with damage rect where v1 used to be. |
3498 test_view->SchedulePaintInRect(gfx::Rect(5, 6, 10, 11)); | 3510 test_view->SchedulePaintInRect(gfx::Rect(5, 6, 10, 11)); |
3499 GetRootLayer()->GetCompositor()->ScheduleDraw(); | 3511 GetRootLayer()->GetCompositor()->ScheduleDraw(); |
3500 ui::DrawWaiterForTest::Wait(GetRootLayer()->GetCompositor()); | 3512 ui::DrawWaiterForTest::WaitForCompositingEnded( |
| 3513 GetRootLayer()->GetCompositor()); |
3501 | 3514 |
3502 // Should only have picked up root_view and test_view. | 3515 // Should only have picked up root_view and test_view. |
3503 EXPECT_EQ(2U, test_view->last_cull_set_.size()); | 3516 EXPECT_EQ(2U, test_view->last_cull_set_.size()); |
3504 EXPECT_EQ(1U, test_view->last_cull_set_.count(widget()->GetRootView())); | 3517 EXPECT_EQ(1U, test_view->last_cull_set_.count(widget()->GetRootView())); |
3505 EXPECT_EQ(1U, test_view->last_cull_set_.count(test_view)); | 3518 EXPECT_EQ(1U, test_view->last_cull_set_.count(test_view)); |
3506 } | 3519 } |
3507 | 3520 |
3508 TEST_F(ViewLayerTest, BoundsTreeLayerChangeMakesNewTree) { | 3521 TEST_F(ViewLayerTest, BoundsTreeLayerChangeMakesNewTree) { |
3509 BoundsTreeTestView* test_view = new BoundsTreeTestView; | 3522 BoundsTreeTestView* test_view = new BoundsTreeTestView; |
3510 widget()->SetContentsView(test_view); | 3523 widget()->SetContentsView(test_view); |
3511 | 3524 |
3512 View* v1 = new View; | 3525 View* v1 = new View; |
3513 v1->SetBoundsRect(gfx::Rect(5, 10, 15, 20)); | 3526 v1->SetBoundsRect(gfx::Rect(5, 10, 15, 20)); |
3514 test_view->AddChildView(v1); | 3527 test_view->AddChildView(v1); |
3515 | 3528 |
3516 View* v2 = new View; | 3529 View* v2 = new View; |
3517 v2->SetBoundsRect(gfx::Rect(1, 2, 3, 4)); | 3530 v2->SetBoundsRect(gfx::Rect(1, 2, 3, 4)); |
3518 v1->AddChildView(v2); | 3531 v1->AddChildView(v2); |
3519 | 3532 |
3520 // Schedule a full-view paint to get everyone's rectangles updated. | 3533 // Schedule a full-view paint to get everyone's rectangles updated. |
3521 test_view->SchedulePaintInRect(test_view->bounds()); | 3534 test_view->SchedulePaintInRect(test_view->bounds()); |
3522 GetRootLayer()->GetCompositor()->ScheduleDraw(); | 3535 GetRootLayer()->GetCompositor()->ScheduleDraw(); |
3523 ui::DrawWaiterForTest::Wait(GetRootLayer()->GetCompositor()); | 3536 ui::DrawWaiterForTest::WaitForCompositingEnded( |
| 3537 GetRootLayer()->GetCompositor()); |
3524 | 3538 |
3525 // Set v1 to paint to its own layer, it should remove itself from the | 3539 // Set v1 to paint to its own layer, it should remove itself from the |
3526 // test_view heiarchy and no longer intersect with damage rects in that cull | 3540 // test_view heiarchy and no longer intersect with damage rects in that cull |
3527 // set. | 3541 // set. |
3528 v1->SetPaintToLayer(true); | 3542 v1->SetPaintToLayer(true); |
3529 | 3543 |
3530 // Schedule another full-view paint. | 3544 // Schedule another full-view paint. |
3531 test_view->SchedulePaintInRect(test_view->bounds()); | 3545 test_view->SchedulePaintInRect(test_view->bounds()); |
3532 GetRootLayer()->GetCompositor()->ScheduleDraw(); | 3546 GetRootLayer()->GetCompositor()->ScheduleDraw(); |
3533 ui::DrawWaiterForTest::Wait(GetRootLayer()->GetCompositor()); | 3547 ui::DrawWaiterForTest::WaitForCompositingEnded( |
| 3548 GetRootLayer()->GetCompositor()); |
3534 // v1 and v2 should no longer be present in the test_view cull_set. | 3549 // v1 and v2 should no longer be present in the test_view cull_set. |
3535 EXPECT_EQ(2U, test_view->last_cull_set_.size()); | 3550 EXPECT_EQ(2U, test_view->last_cull_set_.size()); |
3536 EXPECT_EQ(0U, test_view->last_cull_set_.count(v1)); | 3551 EXPECT_EQ(0U, test_view->last_cull_set_.count(v1)); |
3537 EXPECT_EQ(0U, test_view->last_cull_set_.count(v2)); | 3552 EXPECT_EQ(0U, test_view->last_cull_set_.count(v2)); |
3538 | 3553 |
3539 // Now set v1 back to not painting to a layer. | 3554 // Now set v1 back to not painting to a layer. |
3540 v1->SetPaintToLayer(false); | 3555 v1->SetPaintToLayer(false); |
3541 // Schedule another full-view paint. | 3556 // Schedule another full-view paint. |
3542 test_view->SchedulePaintInRect(test_view->bounds()); | 3557 test_view->SchedulePaintInRect(test_view->bounds()); |
3543 GetRootLayer()->GetCompositor()->ScheduleDraw(); | 3558 GetRootLayer()->GetCompositor()->ScheduleDraw(); |
3544 ui::DrawWaiterForTest::Wait(GetRootLayer()->GetCompositor()); | 3559 ui::DrawWaiterForTest::WaitForCompositingEnded( |
| 3560 GetRootLayer()->GetCompositor()); |
3545 // We should be back to the full cull set including v1 and v2. | 3561 // We should be back to the full cull set including v1 and v2. |
3546 EXPECT_EQ(4U, test_view->last_cull_set_.size()); | 3562 EXPECT_EQ(4U, test_view->last_cull_set_.size()); |
3547 EXPECT_EQ(1U, test_view->last_cull_set_.count(widget()->GetRootView())); | 3563 EXPECT_EQ(1U, test_view->last_cull_set_.count(widget()->GetRootView())); |
3548 EXPECT_EQ(1U, test_view->last_cull_set_.count(test_view)); | 3564 EXPECT_EQ(1U, test_view->last_cull_set_.count(test_view)); |
3549 EXPECT_EQ(1U, test_view->last_cull_set_.count(v1)); | 3565 EXPECT_EQ(1U, test_view->last_cull_set_.count(v1)); |
3550 EXPECT_EQ(1U, test_view->last_cull_set_.count(v2)); | 3566 EXPECT_EQ(1U, test_view->last_cull_set_.count(v2)); |
3551 } | 3567 } |
3552 | 3568 |
3553 TEST_F(ViewLayerTest, BoundsTreeRemoveChildRemovesBounds) { | 3569 TEST_F(ViewLayerTest, BoundsTreeRemoveChildRemovesBounds) { |
3554 BoundsTreeTestView* test_view = new BoundsTreeTestView; | 3570 BoundsTreeTestView* test_view = new BoundsTreeTestView; |
3555 widget()->SetContentsView(test_view); | 3571 widget()->SetContentsView(test_view); |
3556 | 3572 |
3557 View* v1 = new View; | 3573 View* v1 = new View; |
3558 v1->SetBoundsRect(gfx::Rect(5, 10, 15, 20)); | 3574 v1->SetBoundsRect(gfx::Rect(5, 10, 15, 20)); |
3559 test_view->AddChildView(v1); | 3575 test_view->AddChildView(v1); |
3560 | 3576 |
3561 View* v2 = new View; | 3577 View* v2 = new View; |
3562 v2->SetBoundsRect(gfx::Rect(1, 2, 3, 4)); | 3578 v2->SetBoundsRect(gfx::Rect(1, 2, 3, 4)); |
3563 v1->AddChildView(v2); | 3579 v1->AddChildView(v2); |
3564 | 3580 |
3565 // Schedule a full-view paint to get everyone's rectangles updated. | 3581 // Schedule a full-view paint to get everyone's rectangles updated. |
3566 test_view->SchedulePaintInRect(test_view->bounds()); | 3582 test_view->SchedulePaintInRect(test_view->bounds()); |
3567 GetRootLayer()->GetCompositor()->ScheduleDraw(); | 3583 GetRootLayer()->GetCompositor()->ScheduleDraw(); |
3568 ui::DrawWaiterForTest::Wait(GetRootLayer()->GetCompositor()); | 3584 ui::DrawWaiterForTest::WaitForCompositingEnded( |
| 3585 GetRootLayer()->GetCompositor()); |
3569 | 3586 |
3570 // Now remove v1 from the root view. | 3587 // Now remove v1 from the root view. |
3571 test_view->RemoveChildView(v1); | 3588 test_view->RemoveChildView(v1); |
3572 | 3589 |
3573 // Schedule another full-view paint. | 3590 // Schedule another full-view paint. |
3574 test_view->SchedulePaintInRect(test_view->bounds()); | 3591 test_view->SchedulePaintInRect(test_view->bounds()); |
3575 GetRootLayer()->GetCompositor()->ScheduleDraw(); | 3592 GetRootLayer()->GetCompositor()->ScheduleDraw(); |
3576 ui::DrawWaiterForTest::Wait(GetRootLayer()->GetCompositor()); | 3593 ui::DrawWaiterForTest::WaitForCompositingEnded( |
| 3594 GetRootLayer()->GetCompositor()); |
3577 // v1 and v2 should no longer be present in the test_view cull_set. | 3595 // v1 and v2 should no longer be present in the test_view cull_set. |
3578 EXPECT_EQ(2U, test_view->last_cull_set_.size()); | 3596 EXPECT_EQ(2U, test_view->last_cull_set_.size()); |
3579 EXPECT_EQ(0U, test_view->last_cull_set_.count(v1)); | 3597 EXPECT_EQ(0U, test_view->last_cull_set_.count(v1)); |
3580 EXPECT_EQ(0U, test_view->last_cull_set_.count(v2)); | 3598 EXPECT_EQ(0U, test_view->last_cull_set_.count(v2)); |
3581 | 3599 |
3582 // View v1 and v2 are no longer part of view hierarchy and therefore won't be | 3600 // View v1 and v2 are no longer part of view hierarchy and therefore won't be |
3583 // deleted with that hierarchy. | 3601 // deleted with that hierarchy. |
3584 delete v1; | 3602 delete v1; |
3585 } | 3603 } |
3586 | 3604 |
(...skipping 10 matching lines...) Expand all Loading... |
3597 v2->SetBoundsRect(gfx::Rect(5, 10, 40, 50)); | 3615 v2->SetBoundsRect(gfx::Rect(5, 10, 40, 50)); |
3598 v1->AddChildView(v2); | 3616 v1->AddChildView(v2); |
3599 | 3617 |
3600 View* v3 = new View; | 3618 View* v3 = new View; |
3601 v3->SetBoundsRect(gfx::Rect(1, 2, 3, 4)); | 3619 v3->SetBoundsRect(gfx::Rect(1, 2, 3, 4)); |
3602 v2->AddChildView(v3); | 3620 v2->AddChildView(v3); |
3603 | 3621 |
3604 // Schedule a full-view paint and ensure all views are present in the cull. | 3622 // Schedule a full-view paint and ensure all views are present in the cull. |
3605 test_view->SchedulePaintInRect(test_view->bounds()); | 3623 test_view->SchedulePaintInRect(test_view->bounds()); |
3606 GetRootLayer()->GetCompositor()->ScheduleDraw(); | 3624 GetRootLayer()->GetCompositor()->ScheduleDraw(); |
3607 ui::DrawWaiterForTest::Wait(GetRootLayer()->GetCompositor()); | 3625 ui::DrawWaiterForTest::WaitForCompositingEnded( |
| 3626 GetRootLayer()->GetCompositor()); |
3608 EXPECT_EQ(5U, test_view->last_cull_set_.size()); | 3627 EXPECT_EQ(5U, test_view->last_cull_set_.size()); |
3609 EXPECT_EQ(1U, test_view->last_cull_set_.count(widget()->GetRootView())); | 3628 EXPECT_EQ(1U, test_view->last_cull_set_.count(widget()->GetRootView())); |
3610 EXPECT_EQ(1U, test_view->last_cull_set_.count(test_view)); | 3629 EXPECT_EQ(1U, test_view->last_cull_set_.count(test_view)); |
3611 EXPECT_EQ(1U, test_view->last_cull_set_.count(v1)); | 3630 EXPECT_EQ(1U, test_view->last_cull_set_.count(v1)); |
3612 EXPECT_EQ(1U, test_view->last_cull_set_.count(v2)); | 3631 EXPECT_EQ(1U, test_view->last_cull_set_.count(v2)); |
3613 EXPECT_EQ(1U, test_view->last_cull_set_.count(v3)); | 3632 EXPECT_EQ(1U, test_view->last_cull_set_.count(v3)); |
3614 | 3633 |
3615 // Build an unrelated view hierarchy and move v2 in to it. | 3634 // Build an unrelated view hierarchy and move v2 in to it. |
3616 scoped_ptr<Widget> test_widget(new Widget); | 3635 scoped_ptr<Widget> test_widget(new Widget); |
3617 Widget::InitParams params = CreateParams(Widget::InitParams::TYPE_POPUP); | 3636 Widget::InitParams params = CreateParams(Widget::InitParams::TYPE_POPUP); |
3618 params.bounds = gfx::Rect(10, 10, 500, 500); | 3637 params.bounds = gfx::Rect(10, 10, 500, 500); |
3619 params.ownership = Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; | 3638 params.ownership = Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; |
3620 test_widget->Init(params); | 3639 test_widget->Init(params); |
3621 test_widget->Show(); | 3640 test_widget->Show(); |
3622 BoundsTreeTestView* widget_view = new BoundsTreeTestView; | 3641 BoundsTreeTestView* widget_view = new BoundsTreeTestView; |
3623 test_widget->SetContentsView(widget_view); | 3642 test_widget->SetContentsView(widget_view); |
3624 widget_view->AddChildView(v2); | 3643 widget_view->AddChildView(v2); |
3625 | 3644 |
3626 // Now schedule full-view paints in both widgets. | 3645 // Now schedule full-view paints in both widgets. |
3627 test_view->SchedulePaintInRect(test_view->bounds()); | 3646 test_view->SchedulePaintInRect(test_view->bounds()); |
3628 widget_view->SchedulePaintInRect(widget_view->bounds()); | 3647 widget_view->SchedulePaintInRect(widget_view->bounds()); |
3629 GetRootLayer()->GetCompositor()->ScheduleDraw(); | 3648 GetRootLayer()->GetCompositor()->ScheduleDraw(); |
3630 ui::DrawWaiterForTest::Wait(GetRootLayer()->GetCompositor()); | 3649 ui::DrawWaiterForTest::WaitForCompositingEnded( |
| 3650 GetRootLayer()->GetCompositor()); |
3631 | 3651 |
3632 // Only v1 should be present in the first cull set. | 3652 // Only v1 should be present in the first cull set. |
3633 EXPECT_EQ(3U, test_view->last_cull_set_.size()); | 3653 EXPECT_EQ(3U, test_view->last_cull_set_.size()); |
3634 EXPECT_EQ(1U, test_view->last_cull_set_.count(widget()->GetRootView())); | 3654 EXPECT_EQ(1U, test_view->last_cull_set_.count(widget()->GetRootView())); |
3635 EXPECT_EQ(1U, test_view->last_cull_set_.count(test_view)); | 3655 EXPECT_EQ(1U, test_view->last_cull_set_.count(test_view)); |
3636 EXPECT_EQ(1U, test_view->last_cull_set_.count(v1)); | 3656 EXPECT_EQ(1U, test_view->last_cull_set_.count(v1)); |
3637 | 3657 |
3638 // We should find v2 and v3 in the widget_view cull_set. | 3658 // We should find v2 and v3 in the widget_view cull_set. |
3639 EXPECT_EQ(4U, widget_view->last_cull_set_.size()); | 3659 EXPECT_EQ(4U, widget_view->last_cull_set_.size()); |
3640 EXPECT_EQ(1U, widget_view->last_cull_set_.count(test_widget->GetRootView())); | 3660 EXPECT_EQ(1U, widget_view->last_cull_set_.count(test_widget->GetRootView())); |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3751 // notification. | 3771 // notification. |
3752 TestView* test_view_child_2 = new TestView(); | 3772 TestView* test_view_child_2 = new TestView(); |
3753 test_view->AddChildView(test_view_child_2); | 3773 test_view->AddChildView(test_view_child_2); |
3754 EXPECT_TRUE(test_view_child_2->native_theme_); | 3774 EXPECT_TRUE(test_view_child_2->native_theme_); |
3755 EXPECT_EQ(widget->GetNativeTheme(), test_view_child_2->native_theme_); | 3775 EXPECT_EQ(widget->GetNativeTheme(), test_view_child_2->native_theme_); |
3756 | 3776 |
3757 widget->CloseNow(); | 3777 widget->CloseNow(); |
3758 } | 3778 } |
3759 | 3779 |
3760 } // namespace views | 3780 } // namespace views |
OLD | NEW |