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 3069 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3080 DISALLOW_COPY_AND_ASSIGN(PaintTrackingView); | 3080 DISALLOW_COPY_AND_ASSIGN(PaintTrackingView); |
3081 }; | 3081 }; |
3082 | 3082 |
3083 // Makes sure child views with layers aren't painted when paint starts at an | 3083 // Makes sure child views with layers aren't painted when paint starts at an |
3084 // ancestor. | 3084 // ancestor. |
3085 TEST_F(ViewLayerTest, DontPaintChildrenWithLayers) { | 3085 TEST_F(ViewLayerTest, DontPaintChildrenWithLayers) { |
3086 PaintTrackingView* content_view = new PaintTrackingView; | 3086 PaintTrackingView* content_view = new PaintTrackingView; |
3087 widget()->SetContentsView(content_view); | 3087 widget()->SetContentsView(content_view); |
3088 content_view->SetPaintToLayer(true); | 3088 content_view->SetPaintToLayer(true); |
3089 GetRootLayer()->GetCompositor()->ScheduleDraw(); | 3089 GetRootLayer()->GetCompositor()->ScheduleDraw(); |
3090 ui::DrawWaiterForTest::WaitForCompositingEnded( | 3090 ui::DrawWaiterForTest::Wait(GetRootLayer()->GetCompositor()); |
3091 GetRootLayer()->GetCompositor()); | |
3092 GetRootLayer()->SchedulePaint(gfx::Rect(0, 0, 10, 10)); | 3091 GetRootLayer()->SchedulePaint(gfx::Rect(0, 0, 10, 10)); |
3093 content_view->set_painted(false); | 3092 content_view->set_painted(false); |
3094 // content_view no longer has a dirty rect. Paint from the root and make sure | 3093 // content_view no longer has a dirty rect. Paint from the root and make sure |
3095 // PaintTrackingView isn't painted. | 3094 // PaintTrackingView isn't painted. |
3096 GetRootLayer()->GetCompositor()->ScheduleDraw(); | 3095 GetRootLayer()->GetCompositor()->ScheduleDraw(); |
3097 ui::DrawWaiterForTest::WaitForCompositingEnded( | 3096 ui::DrawWaiterForTest::Wait(GetRootLayer()->GetCompositor()); |
3098 GetRootLayer()->GetCompositor()); | |
3099 EXPECT_FALSE(content_view->painted()); | 3097 EXPECT_FALSE(content_view->painted()); |
3100 | 3098 |
3101 // Make content_view have a dirty rect, paint the layers and make sure | 3099 // Make content_view have a dirty rect, paint the layers and make sure |
3102 // PaintTrackingView is painted. | 3100 // PaintTrackingView is painted. |
3103 content_view->layer()->SchedulePaint(gfx::Rect(0, 0, 10, 10)); | 3101 content_view->layer()->SchedulePaint(gfx::Rect(0, 0, 10, 10)); |
3104 GetRootLayer()->GetCompositor()->ScheduleDraw(); | 3102 GetRootLayer()->GetCompositor()->ScheduleDraw(); |
3105 ui::DrawWaiterForTest::WaitForCompositingEnded( | 3103 ui::DrawWaiterForTest::Wait(GetRootLayer()->GetCompositor()); |
3106 GetRootLayer()->GetCompositor()); | |
3107 EXPECT_TRUE(content_view->painted()); | 3104 EXPECT_TRUE(content_view->painted()); |
3108 } | 3105 } |
3109 | 3106 |
3110 // Tests that the visibility of child layers are updated correctly when a View's | 3107 // Tests that the visibility of child layers are updated correctly when a View's |
3111 // visibility changes. | 3108 // visibility changes. |
3112 TEST_F(ViewLayerTest, VisibilityChildLayers) { | 3109 TEST_F(ViewLayerTest, VisibilityChildLayers) { |
3113 View* v1 = new View; | 3110 View* v1 = new View; |
3114 v1->SetPaintToLayer(true); | 3111 v1->SetPaintToLayer(true); |
3115 widget()->SetContentsView(v1); | 3112 widget()->SetContentsView(v1); |
3116 | 3113 |
(...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3336 v1->SetBoundsRect(gfx::Rect(10, 15, 150, 151)); | 3333 v1->SetBoundsRect(gfx::Rect(10, 15, 150, 151)); |
3337 test_view->AddChildView(v1); | 3334 test_view->AddChildView(v1); |
3338 | 3335 |
3339 View* v2 = new View(); | 3336 View* v2 = new View(); |
3340 v2->SetBoundsRect(gfx::Rect(20, 33, 40, 50)); | 3337 v2->SetBoundsRect(gfx::Rect(20, 33, 40, 50)); |
3341 v1->AddChildView(v2); | 3338 v1->AddChildView(v2); |
3342 | 3339 |
3343 // Schedule a full-view paint to get everyone's rectangles updated. | 3340 // Schedule a full-view paint to get everyone's rectangles updated. |
3344 test_view->SchedulePaintInRect(test_view->bounds()); | 3341 test_view->SchedulePaintInRect(test_view->bounds()); |
3345 GetRootLayer()->GetCompositor()->ScheduleDraw(); | 3342 GetRootLayer()->GetCompositor()->ScheduleDraw(); |
3346 ui::DrawWaiterForTest::WaitForCompositingEnded( | 3343 ui::DrawWaiterForTest::Wait(GetRootLayer()->GetCompositor()); |
3347 GetRootLayer()->GetCompositor()); | |
3348 | 3344 |
3349 // Now we have test_view - v1 - v2. Damage to only test_view should only | 3345 // Now we have test_view - v1 - v2. Damage to only test_view should only |
3350 // return root_view and test_view. | 3346 // return root_view and test_view. |
3351 test_view->SchedulePaintInRect(gfx::Rect(0, 0, 1, 1)); | 3347 test_view->SchedulePaintInRect(gfx::Rect(0, 0, 1, 1)); |
3352 GetRootLayer()->GetCompositor()->ScheduleDraw(); | 3348 GetRootLayer()->GetCompositor()->ScheduleDraw(); |
3353 ui::DrawWaiterForTest::WaitForCompositingEnded( | 3349 ui::DrawWaiterForTest::Wait(GetRootLayer()->GetCompositor()); |
3354 GetRootLayer()->GetCompositor()); | |
3355 EXPECT_EQ(2U, test_view->last_cull_set_.size()); | 3350 EXPECT_EQ(2U, test_view->last_cull_set_.size()); |
3356 EXPECT_EQ(1U, test_view->last_cull_set_.count(widget()->GetRootView())); | 3351 EXPECT_EQ(1U, test_view->last_cull_set_.count(widget()->GetRootView())); |
3357 EXPECT_EQ(1U, test_view->last_cull_set_.count(test_view)); | 3352 EXPECT_EQ(1U, test_view->last_cull_set_.count(test_view)); |
3358 | 3353 |
3359 // Damage to v1 only should only return root_view, test_view, and v1. | 3354 // Damage to v1 only should only return root_view, test_view, and v1. |
3360 test_view->SchedulePaintInRect(gfx::Rect(11, 16, 1, 1)); | 3355 test_view->SchedulePaintInRect(gfx::Rect(11, 16, 1, 1)); |
3361 GetRootLayer()->GetCompositor()->ScheduleDraw(); | 3356 GetRootLayer()->GetCompositor()->ScheduleDraw(); |
3362 ui::DrawWaiterForTest::WaitForCompositingEnded( | 3357 ui::DrawWaiterForTest::Wait(GetRootLayer()->GetCompositor()); |
3363 GetRootLayer()->GetCompositor()); | |
3364 EXPECT_EQ(3U, test_view->last_cull_set_.size()); | 3358 EXPECT_EQ(3U, test_view->last_cull_set_.size()); |
3365 EXPECT_EQ(1U, test_view->last_cull_set_.count(widget()->GetRootView())); | 3359 EXPECT_EQ(1U, test_view->last_cull_set_.count(widget()->GetRootView())); |
3366 EXPECT_EQ(1U, test_view->last_cull_set_.count(test_view)); | 3360 EXPECT_EQ(1U, test_view->last_cull_set_.count(test_view)); |
3367 EXPECT_EQ(1U, test_view->last_cull_set_.count(v1)); | 3361 EXPECT_EQ(1U, test_view->last_cull_set_.count(v1)); |
3368 | 3362 |
3369 // A Damage rect inside v2 should get all 3 views back in the |last_cull_set_| | 3363 // A Damage rect inside v2 should get all 3 views back in the |last_cull_set_| |
3370 // on call to TestView::Paint(), along with the widget root view. | 3364 // on call to TestView::Paint(), along with the widget root view. |
3371 test_view->SchedulePaintInRect(gfx::Rect(31, 49, 1, 1)); | 3365 test_view->SchedulePaintInRect(gfx::Rect(31, 49, 1, 1)); |
3372 GetRootLayer()->GetCompositor()->ScheduleDraw(); | 3366 GetRootLayer()->GetCompositor()->ScheduleDraw(); |
3373 ui::DrawWaiterForTest::WaitForCompositingEnded( | 3367 ui::DrawWaiterForTest::Wait(GetRootLayer()->GetCompositor()); |
3374 GetRootLayer()->GetCompositor()); | |
3375 EXPECT_EQ(4U, test_view->last_cull_set_.size()); | 3368 EXPECT_EQ(4U, test_view->last_cull_set_.size()); |
3376 EXPECT_EQ(1U, test_view->last_cull_set_.count(widget()->GetRootView())); | 3369 EXPECT_EQ(1U, test_view->last_cull_set_.count(widget()->GetRootView())); |
3377 EXPECT_EQ(1U, test_view->last_cull_set_.count(test_view)); | 3370 EXPECT_EQ(1U, test_view->last_cull_set_.count(test_view)); |
3378 EXPECT_EQ(1U, test_view->last_cull_set_.count(v1)); | 3371 EXPECT_EQ(1U, test_view->last_cull_set_.count(v1)); |
3379 EXPECT_EQ(1U, test_view->last_cull_set_.count(v2)); | 3372 EXPECT_EQ(1U, test_view->last_cull_set_.count(v2)); |
3380 } | 3373 } |
3381 | 3374 |
3382 TEST_F(ViewLayerTest, BoundsTreeWithRTL) { | 3375 TEST_F(ViewLayerTest, BoundsTreeWithRTL) { |
3383 std::string locale = l10n_util::GetApplicationLocale(std::string()); | 3376 std::string locale = l10n_util::GetApplicationLocale(std::string()); |
3384 base::i18n::SetICUDefaultLocale("ar"); | 3377 base::i18n::SetICUDefaultLocale("ar"); |
3385 | 3378 |
3386 BoundsTreeTestView* test_view = new BoundsTreeTestView; | 3379 BoundsTreeTestView* test_view = new BoundsTreeTestView; |
3387 widget()->SetContentsView(test_view); | 3380 widget()->SetContentsView(test_view); |
3388 | 3381 |
3389 // Add child views, which should be in RTL coordinate space of parent view. | 3382 // Add child views, which should be in RTL coordinate space of parent view. |
3390 View* v1 = new View; | 3383 View* v1 = new View; |
3391 v1->SetBoundsRect(gfx::Rect(10, 12, 25, 26)); | 3384 v1->SetBoundsRect(gfx::Rect(10, 12, 25, 26)); |
3392 test_view->AddChildView(v1); | 3385 test_view->AddChildView(v1); |
3393 | 3386 |
3394 View* v2 = new View; | 3387 View* v2 = new View; |
3395 v2->SetBoundsRect(gfx::Rect(5, 6, 7, 8)); | 3388 v2->SetBoundsRect(gfx::Rect(5, 6, 7, 8)); |
3396 v1->AddChildView(v2); | 3389 v1->AddChildView(v2); |
3397 | 3390 |
3398 // Schedule a full-view paint to get everyone's rectangles updated. | 3391 // Schedule a full-view paint to get everyone's rectangles updated. |
3399 test_view->SchedulePaintInRect(test_view->bounds()); | 3392 test_view->SchedulePaintInRect(test_view->bounds()); |
3400 GetRootLayer()->GetCompositor()->ScheduleDraw(); | 3393 GetRootLayer()->GetCompositor()->ScheduleDraw(); |
3401 ui::DrawWaiterForTest::WaitForCompositingEnded( | 3394 ui::DrawWaiterForTest::Wait(GetRootLayer()->GetCompositor()); |
3402 GetRootLayer()->GetCompositor()); | |
3403 | 3395 |
3404 // Damage to the right side of the parent view should touch both child views. | 3396 // Damage to the right side of the parent view should touch both child views. |
3405 gfx::Rect rtl_damage(test_view->bounds().width() - 16, 18, 1, 1); | 3397 gfx::Rect rtl_damage(test_view->bounds().width() - 16, 18, 1, 1); |
3406 test_view->SchedulePaintInRect(rtl_damage); | 3398 test_view->SchedulePaintInRect(rtl_damage); |
3407 GetRootLayer()->GetCompositor()->ScheduleDraw(); | 3399 GetRootLayer()->GetCompositor()->ScheduleDraw(); |
3408 ui::DrawWaiterForTest::WaitForCompositingEnded( | 3400 ui::DrawWaiterForTest::Wait(GetRootLayer()->GetCompositor()); |
3409 GetRootLayer()->GetCompositor()); | |
3410 EXPECT_EQ(4U, test_view->last_cull_set_.size()); | 3401 EXPECT_EQ(4U, test_view->last_cull_set_.size()); |
3411 EXPECT_EQ(1U, test_view->last_cull_set_.count(widget()->GetRootView())); | 3402 EXPECT_EQ(1U, test_view->last_cull_set_.count(widget()->GetRootView())); |
3412 EXPECT_EQ(1U, test_view->last_cull_set_.count(test_view)); | 3403 EXPECT_EQ(1U, test_view->last_cull_set_.count(test_view)); |
3413 EXPECT_EQ(1U, test_view->last_cull_set_.count(v1)); | 3404 EXPECT_EQ(1U, test_view->last_cull_set_.count(v1)); |
3414 EXPECT_EQ(1U, test_view->last_cull_set_.count(v2)); | 3405 EXPECT_EQ(1U, test_view->last_cull_set_.count(v2)); |
3415 | 3406 |
3416 // Damage to the left side of the parent view should only touch the | 3407 // Damage to the left side of the parent view should only touch the |
3417 // container views. | 3408 // container views. |
3418 gfx::Rect ltr_damage(16, 18, 1, 1); | 3409 gfx::Rect ltr_damage(16, 18, 1, 1); |
3419 test_view->SchedulePaintInRect(ltr_damage); | 3410 test_view->SchedulePaintInRect(ltr_damage); |
3420 GetRootLayer()->GetCompositor()->ScheduleDraw(); | 3411 GetRootLayer()->GetCompositor()->ScheduleDraw(); |
3421 ui::DrawWaiterForTest::WaitForCompositingEnded( | 3412 ui::DrawWaiterForTest::Wait(GetRootLayer()->GetCompositor()); |
3422 GetRootLayer()->GetCompositor()); | |
3423 EXPECT_EQ(2U, test_view->last_cull_set_.size()); | 3413 EXPECT_EQ(2U, test_view->last_cull_set_.size()); |
3424 EXPECT_EQ(1U, test_view->last_cull_set_.count(widget()->GetRootView())); | 3414 EXPECT_EQ(1U, test_view->last_cull_set_.count(widget()->GetRootView())); |
3425 EXPECT_EQ(1U, test_view->last_cull_set_.count(test_view)); | 3415 EXPECT_EQ(1U, test_view->last_cull_set_.count(test_view)); |
3426 | 3416 |
3427 // Reset locale. | 3417 // Reset locale. |
3428 base::i18n::SetICUDefaultLocale(locale); | 3418 base::i18n::SetICUDefaultLocale(locale); |
3429 } | 3419 } |
3430 | 3420 |
3431 TEST_F(ViewLayerTest, BoundsTreeSetBoundsChangesCullSet) { | 3421 TEST_F(ViewLayerTest, BoundsTreeSetBoundsChangesCullSet) { |
3432 BoundsTreeTestView* test_view = new BoundsTreeTestView; | 3422 BoundsTreeTestView* test_view = new BoundsTreeTestView; |
3433 widget()->SetContentsView(test_view); | 3423 widget()->SetContentsView(test_view); |
3434 | 3424 |
3435 View* v1 = new View; | 3425 View* v1 = new View; |
3436 v1->SetBoundsRect(gfx::Rect(5, 6, 100, 101)); | 3426 v1->SetBoundsRect(gfx::Rect(5, 6, 100, 101)); |
3437 test_view->AddChildView(v1); | 3427 test_view->AddChildView(v1); |
3438 | 3428 |
3439 View* v2 = new View; | 3429 View* v2 = new View; |
3440 v2->SetBoundsRect(gfx::Rect(20, 33, 40, 50)); | 3430 v2->SetBoundsRect(gfx::Rect(20, 33, 40, 50)); |
3441 v1->AddChildView(v2); | 3431 v1->AddChildView(v2); |
3442 | 3432 |
3443 // Schedule a full-view paint to get everyone's rectangles updated. | 3433 // Schedule a full-view paint to get everyone's rectangles updated. |
3444 test_view->SchedulePaintInRect(test_view->bounds()); | 3434 test_view->SchedulePaintInRect(test_view->bounds()); |
3445 GetRootLayer()->GetCompositor()->ScheduleDraw(); | 3435 GetRootLayer()->GetCompositor()->ScheduleDraw(); |
3446 ui::DrawWaiterForTest::WaitForCompositingEnded( | 3436 ui::DrawWaiterForTest::Wait(GetRootLayer()->GetCompositor()); |
3447 GetRootLayer()->GetCompositor()); | |
3448 | 3437 |
3449 // Move v1 to a new origin out of the way of our next query. | 3438 // Move v1 to a new origin out of the way of our next query. |
3450 v1->SetBoundsRect(gfx::Rect(50, 60, 100, 101)); | 3439 v1->SetBoundsRect(gfx::Rect(50, 60, 100, 101)); |
3451 // The move will force a repaint. | 3440 // The move will force a repaint. |
3452 GetRootLayer()->GetCompositor()->ScheduleDraw(); | 3441 GetRootLayer()->GetCompositor()->ScheduleDraw(); |
3453 ui::DrawWaiterForTest::WaitForCompositingEnded( | 3442 ui::DrawWaiterForTest::Wait(GetRootLayer()->GetCompositor()); |
3454 GetRootLayer()->GetCompositor()); | |
3455 | 3443 |
3456 // Schedule a paint with damage rect where v1 used to be. | 3444 // Schedule a paint with damage rect where v1 used to be. |
3457 test_view->SchedulePaintInRect(gfx::Rect(5, 6, 10, 11)); | 3445 test_view->SchedulePaintInRect(gfx::Rect(5, 6, 10, 11)); |
3458 GetRootLayer()->GetCompositor()->ScheduleDraw(); | 3446 GetRootLayer()->GetCompositor()->ScheduleDraw(); |
3459 ui::DrawWaiterForTest::WaitForCompositingEnded( | 3447 ui::DrawWaiterForTest::Wait(GetRootLayer()->GetCompositor()); |
3460 GetRootLayer()->GetCompositor()); | |
3461 | 3448 |
3462 // Should only have picked up root_view and test_view. | 3449 // Should only have picked up root_view and test_view. |
3463 EXPECT_EQ(2U, test_view->last_cull_set_.size()); | 3450 EXPECT_EQ(2U, test_view->last_cull_set_.size()); |
3464 EXPECT_EQ(1U, test_view->last_cull_set_.count(widget()->GetRootView())); | 3451 EXPECT_EQ(1U, test_view->last_cull_set_.count(widget()->GetRootView())); |
3465 EXPECT_EQ(1U, test_view->last_cull_set_.count(test_view)); | 3452 EXPECT_EQ(1U, test_view->last_cull_set_.count(test_view)); |
3466 } | 3453 } |
3467 | 3454 |
3468 TEST_F(ViewLayerTest, BoundsTreeLayerChangeMakesNewTree) { | 3455 TEST_F(ViewLayerTest, BoundsTreeLayerChangeMakesNewTree) { |
3469 BoundsTreeTestView* test_view = new BoundsTreeTestView; | 3456 BoundsTreeTestView* test_view = new BoundsTreeTestView; |
3470 widget()->SetContentsView(test_view); | 3457 widget()->SetContentsView(test_view); |
3471 | 3458 |
3472 View* v1 = new View; | 3459 View* v1 = new View; |
3473 v1->SetBoundsRect(gfx::Rect(5, 10, 15, 20)); | 3460 v1->SetBoundsRect(gfx::Rect(5, 10, 15, 20)); |
3474 test_view->AddChildView(v1); | 3461 test_view->AddChildView(v1); |
3475 | 3462 |
3476 View* v2 = new View; | 3463 View* v2 = new View; |
3477 v2->SetBoundsRect(gfx::Rect(1, 2, 3, 4)); | 3464 v2->SetBoundsRect(gfx::Rect(1, 2, 3, 4)); |
3478 v1->AddChildView(v2); | 3465 v1->AddChildView(v2); |
3479 | 3466 |
3480 // Schedule a full-view paint to get everyone's rectangles updated. | 3467 // Schedule a full-view paint to get everyone's rectangles updated. |
3481 test_view->SchedulePaintInRect(test_view->bounds()); | 3468 test_view->SchedulePaintInRect(test_view->bounds()); |
3482 GetRootLayer()->GetCompositor()->ScheduleDraw(); | 3469 GetRootLayer()->GetCompositor()->ScheduleDraw(); |
3483 ui::DrawWaiterForTest::WaitForCompositingEnded( | 3470 ui::DrawWaiterForTest::Wait(GetRootLayer()->GetCompositor()); |
3484 GetRootLayer()->GetCompositor()); | |
3485 | 3471 |
3486 // Set v1 to paint to its own layer, it should remove itself from the | 3472 // Set v1 to paint to its own layer, it should remove itself from the |
3487 // test_view heiarchy and no longer intersect with damage rects in that cull | 3473 // test_view heiarchy and no longer intersect with damage rects in that cull |
3488 // set. | 3474 // set. |
3489 v1->SetPaintToLayer(true); | 3475 v1->SetPaintToLayer(true); |
3490 | 3476 |
3491 // Schedule another full-view paint. | 3477 // Schedule another full-view paint. |
3492 test_view->SchedulePaintInRect(test_view->bounds()); | 3478 test_view->SchedulePaintInRect(test_view->bounds()); |
3493 GetRootLayer()->GetCompositor()->ScheduleDraw(); | 3479 GetRootLayer()->GetCompositor()->ScheduleDraw(); |
3494 ui::DrawWaiterForTest::WaitForCompositingEnded( | 3480 ui::DrawWaiterForTest::Wait(GetRootLayer()->GetCompositor()); |
3495 GetRootLayer()->GetCompositor()); | |
3496 // v1 and v2 should no longer be present in the test_view cull_set. | 3481 // v1 and v2 should no longer be present in the test_view cull_set. |
3497 EXPECT_EQ(2U, test_view->last_cull_set_.size()); | 3482 EXPECT_EQ(2U, test_view->last_cull_set_.size()); |
3498 EXPECT_EQ(0U, test_view->last_cull_set_.count(v1)); | 3483 EXPECT_EQ(0U, test_view->last_cull_set_.count(v1)); |
3499 EXPECT_EQ(0U, test_view->last_cull_set_.count(v2)); | 3484 EXPECT_EQ(0U, test_view->last_cull_set_.count(v2)); |
3500 | 3485 |
3501 // Now set v1 back to not painting to a layer. | 3486 // Now set v1 back to not painting to a layer. |
3502 v1->SetPaintToLayer(false); | 3487 v1->SetPaintToLayer(false); |
3503 // Schedule another full-view paint. | 3488 // Schedule another full-view paint. |
3504 test_view->SchedulePaintInRect(test_view->bounds()); | 3489 test_view->SchedulePaintInRect(test_view->bounds()); |
3505 GetRootLayer()->GetCompositor()->ScheduleDraw(); | 3490 GetRootLayer()->GetCompositor()->ScheduleDraw(); |
3506 ui::DrawWaiterForTest::WaitForCompositingEnded( | 3491 ui::DrawWaiterForTest::Wait(GetRootLayer()->GetCompositor()); |
3507 GetRootLayer()->GetCompositor()); | |
3508 // We should be back to the full cull set including v1 and v2. | 3492 // We should be back to the full cull set including v1 and v2. |
3509 EXPECT_EQ(4U, test_view->last_cull_set_.size()); | 3493 EXPECT_EQ(4U, test_view->last_cull_set_.size()); |
3510 EXPECT_EQ(1U, test_view->last_cull_set_.count(widget()->GetRootView())); | 3494 EXPECT_EQ(1U, test_view->last_cull_set_.count(widget()->GetRootView())); |
3511 EXPECT_EQ(1U, test_view->last_cull_set_.count(test_view)); | 3495 EXPECT_EQ(1U, test_view->last_cull_set_.count(test_view)); |
3512 EXPECT_EQ(1U, test_view->last_cull_set_.count(v1)); | 3496 EXPECT_EQ(1U, test_view->last_cull_set_.count(v1)); |
3513 EXPECT_EQ(1U, test_view->last_cull_set_.count(v2)); | 3497 EXPECT_EQ(1U, test_view->last_cull_set_.count(v2)); |
3514 } | 3498 } |
3515 | 3499 |
3516 TEST_F(ViewLayerTest, BoundsTreeRemoveChildRemovesBounds) { | 3500 TEST_F(ViewLayerTest, BoundsTreeRemoveChildRemovesBounds) { |
3517 BoundsTreeTestView* test_view = new BoundsTreeTestView; | 3501 BoundsTreeTestView* test_view = new BoundsTreeTestView; |
3518 widget()->SetContentsView(test_view); | 3502 widget()->SetContentsView(test_view); |
3519 | 3503 |
3520 View* v1 = new View; | 3504 View* v1 = new View; |
3521 v1->SetBoundsRect(gfx::Rect(5, 10, 15, 20)); | 3505 v1->SetBoundsRect(gfx::Rect(5, 10, 15, 20)); |
3522 test_view->AddChildView(v1); | 3506 test_view->AddChildView(v1); |
3523 | 3507 |
3524 View* v2 = new View; | 3508 View* v2 = new View; |
3525 v2->SetBoundsRect(gfx::Rect(1, 2, 3, 4)); | 3509 v2->SetBoundsRect(gfx::Rect(1, 2, 3, 4)); |
3526 v1->AddChildView(v2); | 3510 v1->AddChildView(v2); |
3527 | 3511 |
3528 // Schedule a full-view paint to get everyone's rectangles updated. | 3512 // Schedule a full-view paint to get everyone's rectangles updated. |
3529 test_view->SchedulePaintInRect(test_view->bounds()); | 3513 test_view->SchedulePaintInRect(test_view->bounds()); |
3530 GetRootLayer()->GetCompositor()->ScheduleDraw(); | 3514 GetRootLayer()->GetCompositor()->ScheduleDraw(); |
3531 ui::DrawWaiterForTest::WaitForCompositingEnded( | 3515 ui::DrawWaiterForTest::Wait(GetRootLayer()->GetCompositor()); |
3532 GetRootLayer()->GetCompositor()); | |
3533 | 3516 |
3534 // Now remove v1 from the root view. | 3517 // Now remove v1 from the root view. |
3535 test_view->RemoveChildView(v1); | 3518 test_view->RemoveChildView(v1); |
3536 | 3519 |
3537 // Schedule another full-view paint. | 3520 // Schedule another full-view paint. |
3538 test_view->SchedulePaintInRect(test_view->bounds()); | 3521 test_view->SchedulePaintInRect(test_view->bounds()); |
3539 GetRootLayer()->GetCompositor()->ScheduleDraw(); | 3522 GetRootLayer()->GetCompositor()->ScheduleDraw(); |
3540 ui::DrawWaiterForTest::WaitForCompositingEnded( | 3523 ui::DrawWaiterForTest::Wait(GetRootLayer()->GetCompositor()); |
3541 GetRootLayer()->GetCompositor()); | |
3542 // v1 and v2 should no longer be present in the test_view cull_set. | 3524 // v1 and v2 should no longer be present in the test_view cull_set. |
3543 EXPECT_EQ(2U, test_view->last_cull_set_.size()); | 3525 EXPECT_EQ(2U, test_view->last_cull_set_.size()); |
3544 EXPECT_EQ(0U, test_view->last_cull_set_.count(v1)); | 3526 EXPECT_EQ(0U, test_view->last_cull_set_.count(v1)); |
3545 EXPECT_EQ(0U, test_view->last_cull_set_.count(v2)); | 3527 EXPECT_EQ(0U, test_view->last_cull_set_.count(v2)); |
3546 | 3528 |
3547 // View v1 and v2 are no longer part of view hierarchy and therefore won't be | 3529 // View v1 and v2 are no longer part of view hierarchy and therefore won't be |
3548 // deleted with that hierarchy. | 3530 // deleted with that hierarchy. |
3549 delete v1; | 3531 delete v1; |
3550 } | 3532 } |
3551 | 3533 |
(...skipping 10 matching lines...) Expand all Loading... |
3562 v2->SetBoundsRect(gfx::Rect(5, 10, 40, 50)); | 3544 v2->SetBoundsRect(gfx::Rect(5, 10, 40, 50)); |
3563 v1->AddChildView(v2); | 3545 v1->AddChildView(v2); |
3564 | 3546 |
3565 View* v3 = new View; | 3547 View* v3 = new View; |
3566 v3->SetBoundsRect(gfx::Rect(1, 2, 3, 4)); | 3548 v3->SetBoundsRect(gfx::Rect(1, 2, 3, 4)); |
3567 v2->AddChildView(v3); | 3549 v2->AddChildView(v3); |
3568 | 3550 |
3569 // Schedule a full-view paint and ensure all views are present in the cull. | 3551 // Schedule a full-view paint and ensure all views are present in the cull. |
3570 test_view->SchedulePaintInRect(test_view->bounds()); | 3552 test_view->SchedulePaintInRect(test_view->bounds()); |
3571 GetRootLayer()->GetCompositor()->ScheduleDraw(); | 3553 GetRootLayer()->GetCompositor()->ScheduleDraw(); |
3572 ui::DrawWaiterForTest::WaitForCompositingEnded( | 3554 ui::DrawWaiterForTest::Wait(GetRootLayer()->GetCompositor()); |
3573 GetRootLayer()->GetCompositor()); | |
3574 EXPECT_EQ(5U, test_view->last_cull_set_.size()); | 3555 EXPECT_EQ(5U, test_view->last_cull_set_.size()); |
3575 EXPECT_EQ(1U, test_view->last_cull_set_.count(widget()->GetRootView())); | 3556 EXPECT_EQ(1U, test_view->last_cull_set_.count(widget()->GetRootView())); |
3576 EXPECT_EQ(1U, test_view->last_cull_set_.count(test_view)); | 3557 EXPECT_EQ(1U, test_view->last_cull_set_.count(test_view)); |
3577 EXPECT_EQ(1U, test_view->last_cull_set_.count(v1)); | 3558 EXPECT_EQ(1U, test_view->last_cull_set_.count(v1)); |
3578 EXPECT_EQ(1U, test_view->last_cull_set_.count(v2)); | 3559 EXPECT_EQ(1U, test_view->last_cull_set_.count(v2)); |
3579 EXPECT_EQ(1U, test_view->last_cull_set_.count(v3)); | 3560 EXPECT_EQ(1U, test_view->last_cull_set_.count(v3)); |
3580 | 3561 |
3581 // Build an unrelated view hierarchy and move v2 in to it. | 3562 // Build an unrelated view hierarchy and move v2 in to it. |
3582 scoped_ptr<Widget> test_widget(new Widget); | 3563 scoped_ptr<Widget> test_widget(new Widget); |
3583 Widget::InitParams params = CreateParams(Widget::InitParams::TYPE_POPUP); | 3564 Widget::InitParams params = CreateParams(Widget::InitParams::TYPE_POPUP); |
3584 params.bounds = gfx::Rect(10, 10, 500, 500); | 3565 params.bounds = gfx::Rect(10, 10, 500, 500); |
3585 params.ownership = Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; | 3566 params.ownership = Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; |
3586 test_widget->Init(params); | 3567 test_widget->Init(params); |
3587 test_widget->Show(); | 3568 test_widget->Show(); |
3588 BoundsTreeTestView* widget_view = new BoundsTreeTestView; | 3569 BoundsTreeTestView* widget_view = new BoundsTreeTestView; |
3589 test_widget->SetContentsView(widget_view); | 3570 test_widget->SetContentsView(widget_view); |
3590 widget_view->AddChildView(v2); | 3571 widget_view->AddChildView(v2); |
3591 | 3572 |
3592 // Now schedule full-view paints in both widgets. | 3573 // Now schedule full-view paints in both widgets. |
3593 test_view->SchedulePaintInRect(test_view->bounds()); | 3574 test_view->SchedulePaintInRect(test_view->bounds()); |
3594 widget_view->SchedulePaintInRect(widget_view->bounds()); | 3575 widget_view->SchedulePaintInRect(widget_view->bounds()); |
3595 GetRootLayer()->GetCompositor()->ScheduleDraw(); | 3576 GetRootLayer()->GetCompositor()->ScheduleDraw(); |
3596 ui::DrawWaiterForTest::WaitForCompositingEnded( | 3577 ui::DrawWaiterForTest::Wait(GetRootLayer()->GetCompositor()); |
3597 GetRootLayer()->GetCompositor()); | |
3598 | 3578 |
3599 // Only v1 should be present in the first cull set. | 3579 // Only v1 should be present in the first cull set. |
3600 EXPECT_EQ(3U, test_view->last_cull_set_.size()); | 3580 EXPECT_EQ(3U, test_view->last_cull_set_.size()); |
3601 EXPECT_EQ(1U, test_view->last_cull_set_.count(widget()->GetRootView())); | 3581 EXPECT_EQ(1U, test_view->last_cull_set_.count(widget()->GetRootView())); |
3602 EXPECT_EQ(1U, test_view->last_cull_set_.count(test_view)); | 3582 EXPECT_EQ(1U, test_view->last_cull_set_.count(test_view)); |
3603 EXPECT_EQ(1U, test_view->last_cull_set_.count(v1)); | 3583 EXPECT_EQ(1U, test_view->last_cull_set_.count(v1)); |
3604 | 3584 |
3605 // We should find v2 and v3 in the widget_view cull_set. | 3585 // We should find v2 and v3 in the widget_view cull_set. |
3606 EXPECT_EQ(4U, widget_view->last_cull_set_.size()); | 3586 EXPECT_EQ(4U, widget_view->last_cull_set_.size()); |
3607 EXPECT_EQ(1U, widget_view->last_cull_set_.count(test_widget->GetRootView())); | 3587 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... |
3718 // notification. | 3698 // notification. |
3719 TestView* test_view_child_2 = new TestView(); | 3699 TestView* test_view_child_2 = new TestView(); |
3720 test_view->AddChildView(test_view_child_2); | 3700 test_view->AddChildView(test_view_child_2); |
3721 EXPECT_TRUE(test_view_child_2->native_theme_); | 3701 EXPECT_TRUE(test_view_child_2->native_theme_); |
3722 EXPECT_EQ(widget->GetNativeTheme(), test_view_child_2->native_theme_); | 3702 EXPECT_EQ(widget->GetNativeTheme(), test_view_child_2->native_theme_); |
3723 | 3703 |
3724 widget->CloseNow(); | 3704 widget->CloseNow(); |
3725 } | 3705 } |
3726 | 3706 |
3727 } // namespace views | 3707 } // namespace views |
OLD | NEW |