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