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 3006 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3017 DISALLOW_COPY_AND_ASSIGN(PaintTrackingView); | 3017 DISALLOW_COPY_AND_ASSIGN(PaintTrackingView); |
3018 }; | 3018 }; |
3019 | 3019 |
3020 // Makes sure child views with layers aren't painted when paint starts at an | 3020 // Makes sure child views with layers aren't painted when paint starts at an |
3021 // ancestor. | 3021 // ancestor. |
3022 TEST_F(ViewLayerTest, DontPaintChildrenWithLayers) { | 3022 TEST_F(ViewLayerTest, DontPaintChildrenWithLayers) { |
3023 PaintTrackingView* content_view = new PaintTrackingView; | 3023 PaintTrackingView* content_view = new PaintTrackingView; |
3024 widget()->SetContentsView(content_view); | 3024 widget()->SetContentsView(content_view); |
3025 content_view->SetPaintToLayer(true); | 3025 content_view->SetPaintToLayer(true); |
3026 GetRootLayer()->GetCompositor()->ScheduleDraw(); | 3026 GetRootLayer()->GetCompositor()->ScheduleDraw(); |
3027 ui::DrawWaiterForTest::Wait(GetRootLayer()->GetCompositor()); | 3027 ui::DrawWaiterForTest::WaitForCompositingEnded( |
| 3028 GetRootLayer()->GetCompositor()); |
3028 GetRootLayer()->SchedulePaint(gfx::Rect(0, 0, 10, 10)); | 3029 GetRootLayer()->SchedulePaint(gfx::Rect(0, 0, 10, 10)); |
3029 content_view->set_painted(false); | 3030 content_view->set_painted(false); |
3030 // content_view no longer has a dirty rect. Paint from the root and make sure | 3031 // content_view no longer has a dirty rect. Paint from the root and make sure |
3031 // PaintTrackingView isn't painted. | 3032 // PaintTrackingView isn't painted. |
3032 GetRootLayer()->GetCompositor()->ScheduleDraw(); | 3033 GetRootLayer()->GetCompositor()->ScheduleDraw(); |
3033 ui::DrawWaiterForTest::Wait(GetRootLayer()->GetCompositor()); | 3034 ui::DrawWaiterForTest::WaitForCompositingEnded( |
| 3035 GetRootLayer()->GetCompositor()); |
3034 EXPECT_FALSE(content_view->painted()); | 3036 EXPECT_FALSE(content_view->painted()); |
3035 | 3037 |
3036 // Make content_view have a dirty rect, paint the layers and make sure | 3038 // Make content_view have a dirty rect, paint the layers and make sure |
3037 // PaintTrackingView is painted. | 3039 // PaintTrackingView is painted. |
3038 content_view->layer()->SchedulePaint(gfx::Rect(0, 0, 10, 10)); | 3040 content_view->layer()->SchedulePaint(gfx::Rect(0, 0, 10, 10)); |
3039 GetRootLayer()->GetCompositor()->ScheduleDraw(); | 3041 GetRootLayer()->GetCompositor()->ScheduleDraw(); |
3040 ui::DrawWaiterForTest::Wait(GetRootLayer()->GetCompositor()); | 3042 ui::DrawWaiterForTest::WaitForCompositingEnded( |
| 3043 GetRootLayer()->GetCompositor()); |
3041 EXPECT_TRUE(content_view->painted()); | 3044 EXPECT_TRUE(content_view->painted()); |
3042 } | 3045 } |
3043 | 3046 |
3044 // Tests that the visibility of child layers are updated correctly when a View's | 3047 // Tests that the visibility of child layers are updated correctly when a View's |
3045 // visibility changes. | 3048 // visibility changes. |
3046 TEST_F(ViewLayerTest, VisibilityChildLayers) { | 3049 TEST_F(ViewLayerTest, VisibilityChildLayers) { |
3047 View* v1 = new View; | 3050 View* v1 = new View; |
3048 v1->SetPaintToLayer(true); | 3051 v1->SetPaintToLayer(true); |
3049 widget()->SetContentsView(v1); | 3052 widget()->SetContentsView(v1); |
3050 | 3053 |
(...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3270 v1->SetBoundsRect(gfx::Rect(10, 15, 150, 151)); | 3273 v1->SetBoundsRect(gfx::Rect(10, 15, 150, 151)); |
3271 test_view->AddChildView(v1); | 3274 test_view->AddChildView(v1); |
3272 | 3275 |
3273 View* v2 = new View(); | 3276 View* v2 = new View(); |
3274 v2->SetBoundsRect(gfx::Rect(20, 33, 40, 50)); | 3277 v2->SetBoundsRect(gfx::Rect(20, 33, 40, 50)); |
3275 v1->AddChildView(v2); | 3278 v1->AddChildView(v2); |
3276 | 3279 |
3277 // Schedule a full-view paint to get everyone's rectangles updated. | 3280 // Schedule a full-view paint to get everyone's rectangles updated. |
3278 test_view->SchedulePaintInRect(test_view->bounds()); | 3281 test_view->SchedulePaintInRect(test_view->bounds()); |
3279 GetRootLayer()->GetCompositor()->ScheduleDraw(); | 3282 GetRootLayer()->GetCompositor()->ScheduleDraw(); |
3280 ui::DrawWaiterForTest::Wait(GetRootLayer()->GetCompositor()); | 3283 ui::DrawWaiterForTest::WaitForCompositingEnded( |
| 3284 GetRootLayer()->GetCompositor()); |
3281 | 3285 |
3282 // Now we have test_view - v1 - v2. Damage to only test_view should only | 3286 // Now we have test_view - v1 - v2. Damage to only test_view should only |
3283 // return root_view and test_view. | 3287 // return root_view and test_view. |
3284 test_view->SchedulePaintInRect(gfx::Rect(0, 0, 1, 1)); | 3288 test_view->SchedulePaintInRect(gfx::Rect(0, 0, 1, 1)); |
3285 GetRootLayer()->GetCompositor()->ScheduleDraw(); | 3289 GetRootLayer()->GetCompositor()->ScheduleDraw(); |
3286 ui::DrawWaiterForTest::Wait(GetRootLayer()->GetCompositor()); | 3290 ui::DrawWaiterForTest::WaitForCompositingEnded( |
| 3291 GetRootLayer()->GetCompositor()); |
3287 EXPECT_EQ(2U, test_view->last_cull_set_.size()); | 3292 EXPECT_EQ(2U, test_view->last_cull_set_.size()); |
3288 EXPECT_EQ(1U, test_view->last_cull_set_.count(widget()->GetRootView())); | 3293 EXPECT_EQ(1U, test_view->last_cull_set_.count(widget()->GetRootView())); |
3289 EXPECT_EQ(1U, test_view->last_cull_set_.count(test_view)); | 3294 EXPECT_EQ(1U, test_view->last_cull_set_.count(test_view)); |
3290 | 3295 |
3291 // Damage to v1 only should only return root_view, test_view, and v1. | 3296 // Damage to v1 only should only return root_view, test_view, and v1. |
3292 test_view->SchedulePaintInRect(gfx::Rect(11, 16, 1, 1)); | 3297 test_view->SchedulePaintInRect(gfx::Rect(11, 16, 1, 1)); |
3293 GetRootLayer()->GetCompositor()->ScheduleDraw(); | 3298 GetRootLayer()->GetCompositor()->ScheduleDraw(); |
3294 ui::DrawWaiterForTest::Wait(GetRootLayer()->GetCompositor()); | 3299 ui::DrawWaiterForTest::WaitForCompositingEnded( |
| 3300 GetRootLayer()->GetCompositor()); |
3295 EXPECT_EQ(3U, test_view->last_cull_set_.size()); | 3301 EXPECT_EQ(3U, test_view->last_cull_set_.size()); |
3296 EXPECT_EQ(1U, test_view->last_cull_set_.count(widget()->GetRootView())); | 3302 EXPECT_EQ(1U, test_view->last_cull_set_.count(widget()->GetRootView())); |
3297 EXPECT_EQ(1U, test_view->last_cull_set_.count(test_view)); | 3303 EXPECT_EQ(1U, test_view->last_cull_set_.count(test_view)); |
3298 EXPECT_EQ(1U, test_view->last_cull_set_.count(v1)); | 3304 EXPECT_EQ(1U, test_view->last_cull_set_.count(v1)); |
3299 | 3305 |
3300 // A Damage rect inside v2 should get all 3 views back in the |last_cull_set_| | 3306 // A Damage rect inside v2 should get all 3 views back in the |last_cull_set_| |
3301 // on call to TestView::Paint(), along with the widget root view. | 3307 // on call to TestView::Paint(), along with the widget root view. |
3302 test_view->SchedulePaintInRect(gfx::Rect(31, 49, 1, 1)); | 3308 test_view->SchedulePaintInRect(gfx::Rect(31, 49, 1, 1)); |
3303 GetRootLayer()->GetCompositor()->ScheduleDraw(); | 3309 GetRootLayer()->GetCompositor()->ScheduleDraw(); |
3304 ui::DrawWaiterForTest::Wait(GetRootLayer()->GetCompositor()); | 3310 ui::DrawWaiterForTest::WaitForCompositingEnded( |
| 3311 GetRootLayer()->GetCompositor()); |
3305 EXPECT_EQ(4U, test_view->last_cull_set_.size()); | 3312 EXPECT_EQ(4U, test_view->last_cull_set_.size()); |
3306 EXPECT_EQ(1U, test_view->last_cull_set_.count(widget()->GetRootView())); | 3313 EXPECT_EQ(1U, test_view->last_cull_set_.count(widget()->GetRootView())); |
3307 EXPECT_EQ(1U, test_view->last_cull_set_.count(test_view)); | 3314 EXPECT_EQ(1U, test_view->last_cull_set_.count(test_view)); |
3308 EXPECT_EQ(1U, test_view->last_cull_set_.count(v1)); | 3315 EXPECT_EQ(1U, test_view->last_cull_set_.count(v1)); |
3309 EXPECT_EQ(1U, test_view->last_cull_set_.count(v2)); | 3316 EXPECT_EQ(1U, test_view->last_cull_set_.count(v2)); |
3310 } | 3317 } |
3311 | 3318 |
3312 TEST_F(ViewLayerTest, BoundsTreeWithRTL) { | 3319 TEST_F(ViewLayerTest, BoundsTreeWithRTL) { |
3313 std::string locale = l10n_util::GetApplicationLocale(std::string()); | 3320 std::string locale = l10n_util::GetApplicationLocale(std::string()); |
3314 base::i18n::SetICUDefaultLocale("ar"); | 3321 base::i18n::SetICUDefaultLocale("ar"); |
3315 | 3322 |
3316 BoundsTreeTestView* test_view = new BoundsTreeTestView; | 3323 BoundsTreeTestView* test_view = new BoundsTreeTestView; |
3317 widget()->SetContentsView(test_view); | 3324 widget()->SetContentsView(test_view); |
3318 | 3325 |
3319 // Add child views, which should be in RTL coordinate space of parent view. | 3326 // Add child views, which should be in RTL coordinate space of parent view. |
3320 View* v1 = new View; | 3327 View* v1 = new View; |
3321 v1->SetBoundsRect(gfx::Rect(10, 12, 25, 26)); | 3328 v1->SetBoundsRect(gfx::Rect(10, 12, 25, 26)); |
3322 test_view->AddChildView(v1); | 3329 test_view->AddChildView(v1); |
3323 | 3330 |
3324 View* v2 = new View; | 3331 View* v2 = new View; |
3325 v2->SetBoundsRect(gfx::Rect(5, 6, 7, 8)); | 3332 v2->SetBoundsRect(gfx::Rect(5, 6, 7, 8)); |
3326 v1->AddChildView(v2); | 3333 v1->AddChildView(v2); |
3327 | 3334 |
3328 // Schedule a full-view paint to get everyone's rectangles updated. | 3335 // Schedule a full-view paint to get everyone's rectangles updated. |
3329 test_view->SchedulePaintInRect(test_view->bounds()); | 3336 test_view->SchedulePaintInRect(test_view->bounds()); |
3330 GetRootLayer()->GetCompositor()->ScheduleDraw(); | 3337 GetRootLayer()->GetCompositor()->ScheduleDraw(); |
3331 ui::DrawWaiterForTest::Wait(GetRootLayer()->GetCompositor()); | 3338 ui::DrawWaiterForTest::WaitForCompositingEnded( |
| 3339 GetRootLayer()->GetCompositor()); |
3332 | 3340 |
3333 // Damage to the right side of the parent view should touch both child views. | 3341 // Damage to the right side of the parent view should touch both child views. |
3334 gfx::Rect rtl_damage(test_view->bounds().width() - 16, 18, 1, 1); | 3342 gfx::Rect rtl_damage(test_view->bounds().width() - 16, 18, 1, 1); |
3335 test_view->SchedulePaintInRect(rtl_damage); | 3343 test_view->SchedulePaintInRect(rtl_damage); |
3336 GetRootLayer()->GetCompositor()->ScheduleDraw(); | 3344 GetRootLayer()->GetCompositor()->ScheduleDraw(); |
3337 ui::DrawWaiterForTest::Wait(GetRootLayer()->GetCompositor()); | 3345 ui::DrawWaiterForTest::WaitForCompositingEnded( |
| 3346 GetRootLayer()->GetCompositor()); |
3338 EXPECT_EQ(4U, test_view->last_cull_set_.size()); | 3347 EXPECT_EQ(4U, test_view->last_cull_set_.size()); |
3339 EXPECT_EQ(1U, test_view->last_cull_set_.count(widget()->GetRootView())); | 3348 EXPECT_EQ(1U, test_view->last_cull_set_.count(widget()->GetRootView())); |
3340 EXPECT_EQ(1U, test_view->last_cull_set_.count(test_view)); | 3349 EXPECT_EQ(1U, test_view->last_cull_set_.count(test_view)); |
3341 EXPECT_EQ(1U, test_view->last_cull_set_.count(v1)); | 3350 EXPECT_EQ(1U, test_view->last_cull_set_.count(v1)); |
3342 EXPECT_EQ(1U, test_view->last_cull_set_.count(v2)); | 3351 EXPECT_EQ(1U, test_view->last_cull_set_.count(v2)); |
3343 | 3352 |
3344 // Damage to the left side of the parent view should only touch the | 3353 // Damage to the left side of the parent view should only touch the |
3345 // container views. | 3354 // container views. |
3346 gfx::Rect ltr_damage(16, 18, 1, 1); | 3355 gfx::Rect ltr_damage(16, 18, 1, 1); |
3347 test_view->SchedulePaintInRect(ltr_damage); | 3356 test_view->SchedulePaintInRect(ltr_damage); |
3348 GetRootLayer()->GetCompositor()->ScheduleDraw(); | 3357 GetRootLayer()->GetCompositor()->ScheduleDraw(); |
3349 ui::DrawWaiterForTest::Wait(GetRootLayer()->GetCompositor()); | 3358 ui::DrawWaiterForTest::WaitForCompositingEnded( |
| 3359 GetRootLayer()->GetCompositor()); |
3350 EXPECT_EQ(2U, test_view->last_cull_set_.size()); | 3360 EXPECT_EQ(2U, test_view->last_cull_set_.size()); |
3351 EXPECT_EQ(1U, test_view->last_cull_set_.count(widget()->GetRootView())); | 3361 EXPECT_EQ(1U, test_view->last_cull_set_.count(widget()->GetRootView())); |
3352 EXPECT_EQ(1U, test_view->last_cull_set_.count(test_view)); | 3362 EXPECT_EQ(1U, test_view->last_cull_set_.count(test_view)); |
3353 | 3363 |
3354 // Reset locale. | 3364 // Reset locale. |
3355 base::i18n::SetICUDefaultLocale(locale); | 3365 base::i18n::SetICUDefaultLocale(locale); |
3356 } | 3366 } |
3357 | 3367 |
3358 TEST_F(ViewLayerTest, BoundsTreeSetBoundsChangesCullSet) { | 3368 TEST_F(ViewLayerTest, BoundsTreeSetBoundsChangesCullSet) { |
3359 BoundsTreeTestView* test_view = new BoundsTreeTestView; | 3369 BoundsTreeTestView* test_view = new BoundsTreeTestView; |
3360 widget()->SetContentsView(test_view); | 3370 widget()->SetContentsView(test_view); |
3361 | 3371 |
3362 View* v1 = new View; | 3372 View* v1 = new View; |
3363 v1->SetBoundsRect(gfx::Rect(5, 6, 100, 101)); | 3373 v1->SetBoundsRect(gfx::Rect(5, 6, 100, 101)); |
3364 test_view->AddChildView(v1); | 3374 test_view->AddChildView(v1); |
3365 | 3375 |
3366 View* v2 = new View; | 3376 View* v2 = new View; |
3367 v2->SetBoundsRect(gfx::Rect(20, 33, 40, 50)); | 3377 v2->SetBoundsRect(gfx::Rect(20, 33, 40, 50)); |
3368 v1->AddChildView(v2); | 3378 v1->AddChildView(v2); |
3369 | 3379 |
3370 // Schedule a full-view paint to get everyone's rectangles updated. | 3380 // Schedule a full-view paint to get everyone's rectangles updated. |
3371 test_view->SchedulePaintInRect(test_view->bounds()); | 3381 test_view->SchedulePaintInRect(test_view->bounds()); |
3372 GetRootLayer()->GetCompositor()->ScheduleDraw(); | 3382 GetRootLayer()->GetCompositor()->ScheduleDraw(); |
3373 ui::DrawWaiterForTest::Wait(GetRootLayer()->GetCompositor()); | 3383 ui::DrawWaiterForTest::WaitForCompositingEnded( |
| 3384 GetRootLayer()->GetCompositor()); |
3374 | 3385 |
3375 // Move v1 to a new origin out of the way of our next query. | 3386 // Move v1 to a new origin out of the way of our next query. |
3376 v1->SetBoundsRect(gfx::Rect(50, 60, 100, 101)); | 3387 v1->SetBoundsRect(gfx::Rect(50, 60, 100, 101)); |
3377 // The move will force a repaint. | 3388 // The move will force a repaint. |
3378 GetRootLayer()->GetCompositor()->ScheduleDraw(); | 3389 GetRootLayer()->GetCompositor()->ScheduleDraw(); |
3379 ui::DrawWaiterForTest::Wait(GetRootLayer()->GetCompositor()); | 3390 ui::DrawWaiterForTest::WaitForCompositingEnded( |
| 3391 GetRootLayer()->GetCompositor()); |
3380 | 3392 |
3381 // Schedule a paint with damage rect where v1 used to be. | 3393 // Schedule a paint with damage rect where v1 used to be. |
3382 test_view->SchedulePaintInRect(gfx::Rect(5, 6, 10, 11)); | 3394 test_view->SchedulePaintInRect(gfx::Rect(5, 6, 10, 11)); |
3383 GetRootLayer()->GetCompositor()->ScheduleDraw(); | 3395 GetRootLayer()->GetCompositor()->ScheduleDraw(); |
3384 ui::DrawWaiterForTest::Wait(GetRootLayer()->GetCompositor()); | 3396 ui::DrawWaiterForTest::WaitForCompositingEnded( |
| 3397 GetRootLayer()->GetCompositor()); |
3385 | 3398 |
3386 // Should only have picked up root_view and test_view. | 3399 // Should only have picked up root_view and test_view. |
3387 EXPECT_EQ(2U, test_view->last_cull_set_.size()); | 3400 EXPECT_EQ(2U, test_view->last_cull_set_.size()); |
3388 EXPECT_EQ(1U, test_view->last_cull_set_.count(widget()->GetRootView())); | 3401 EXPECT_EQ(1U, test_view->last_cull_set_.count(widget()->GetRootView())); |
3389 EXPECT_EQ(1U, test_view->last_cull_set_.count(test_view)); | 3402 EXPECT_EQ(1U, test_view->last_cull_set_.count(test_view)); |
3390 } | 3403 } |
3391 | 3404 |
3392 TEST_F(ViewLayerTest, BoundsTreeLayerChangeMakesNewTree) { | 3405 TEST_F(ViewLayerTest, BoundsTreeLayerChangeMakesNewTree) { |
3393 BoundsTreeTestView* test_view = new BoundsTreeTestView; | 3406 BoundsTreeTestView* test_view = new BoundsTreeTestView; |
3394 widget()->SetContentsView(test_view); | 3407 widget()->SetContentsView(test_view); |
3395 | 3408 |
3396 View* v1 = new View; | 3409 View* v1 = new View; |
3397 v1->SetBoundsRect(gfx::Rect(5, 10, 15, 20)); | 3410 v1->SetBoundsRect(gfx::Rect(5, 10, 15, 20)); |
3398 test_view->AddChildView(v1); | 3411 test_view->AddChildView(v1); |
3399 | 3412 |
3400 View* v2 = new View; | 3413 View* v2 = new View; |
3401 v2->SetBoundsRect(gfx::Rect(1, 2, 3, 4)); | 3414 v2->SetBoundsRect(gfx::Rect(1, 2, 3, 4)); |
3402 v1->AddChildView(v2); | 3415 v1->AddChildView(v2); |
3403 | 3416 |
3404 // Schedule a full-view paint to get everyone's rectangles updated. | 3417 // Schedule a full-view paint to get everyone's rectangles updated. |
3405 test_view->SchedulePaintInRect(test_view->bounds()); | 3418 test_view->SchedulePaintInRect(test_view->bounds()); |
3406 GetRootLayer()->GetCompositor()->ScheduleDraw(); | 3419 GetRootLayer()->GetCompositor()->ScheduleDraw(); |
3407 ui::DrawWaiterForTest::Wait(GetRootLayer()->GetCompositor()); | 3420 ui::DrawWaiterForTest::WaitForCompositingEnded( |
| 3421 GetRootLayer()->GetCompositor()); |
3408 | 3422 |
3409 // Set v1 to paint to its own layer, it should remove itself from the | 3423 // Set v1 to paint to its own layer, it should remove itself from the |
3410 // test_view heiarchy and no longer intersect with damage rects in that cull | 3424 // test_view heiarchy and no longer intersect with damage rects in that cull |
3411 // set. | 3425 // set. |
3412 v1->SetPaintToLayer(true); | 3426 v1->SetPaintToLayer(true); |
3413 | 3427 |
3414 // Schedule another full-view paint. | 3428 // Schedule another full-view paint. |
3415 test_view->SchedulePaintInRect(test_view->bounds()); | 3429 test_view->SchedulePaintInRect(test_view->bounds()); |
3416 GetRootLayer()->GetCompositor()->ScheduleDraw(); | 3430 GetRootLayer()->GetCompositor()->ScheduleDraw(); |
3417 ui::DrawWaiterForTest::Wait(GetRootLayer()->GetCompositor()); | 3431 ui::DrawWaiterForTest::WaitForCompositingEnded( |
| 3432 GetRootLayer()->GetCompositor()); |
3418 // v1 and v2 should no longer be present in the test_view cull_set. | 3433 // v1 and v2 should no longer be present in the test_view cull_set. |
3419 EXPECT_EQ(2U, test_view->last_cull_set_.size()); | 3434 EXPECT_EQ(2U, test_view->last_cull_set_.size()); |
3420 EXPECT_EQ(0U, test_view->last_cull_set_.count(v1)); | 3435 EXPECT_EQ(0U, test_view->last_cull_set_.count(v1)); |
3421 EXPECT_EQ(0U, test_view->last_cull_set_.count(v2)); | 3436 EXPECT_EQ(0U, test_view->last_cull_set_.count(v2)); |
3422 | 3437 |
3423 // Now set v1 back to not painting to a layer. | 3438 // Now set v1 back to not painting to a layer. |
3424 v1->SetPaintToLayer(false); | 3439 v1->SetPaintToLayer(false); |
3425 // Schedule another full-view paint. | 3440 // Schedule another full-view paint. |
3426 test_view->SchedulePaintInRect(test_view->bounds()); | 3441 test_view->SchedulePaintInRect(test_view->bounds()); |
3427 GetRootLayer()->GetCompositor()->ScheduleDraw(); | 3442 GetRootLayer()->GetCompositor()->ScheduleDraw(); |
3428 ui::DrawWaiterForTest::Wait(GetRootLayer()->GetCompositor()); | 3443 ui::DrawWaiterForTest::WaitForCompositingEnded( |
| 3444 GetRootLayer()->GetCompositor()); |
3429 // We should be back to the full cull set including v1 and v2. | 3445 // We should be back to the full cull set including v1 and v2. |
3430 EXPECT_EQ(4U, test_view->last_cull_set_.size()); | 3446 EXPECT_EQ(4U, test_view->last_cull_set_.size()); |
3431 EXPECT_EQ(1U, test_view->last_cull_set_.count(widget()->GetRootView())); | 3447 EXPECT_EQ(1U, test_view->last_cull_set_.count(widget()->GetRootView())); |
3432 EXPECT_EQ(1U, test_view->last_cull_set_.count(test_view)); | 3448 EXPECT_EQ(1U, test_view->last_cull_set_.count(test_view)); |
3433 EXPECT_EQ(1U, test_view->last_cull_set_.count(v1)); | 3449 EXPECT_EQ(1U, test_view->last_cull_set_.count(v1)); |
3434 EXPECT_EQ(1U, test_view->last_cull_set_.count(v2)); | 3450 EXPECT_EQ(1U, test_view->last_cull_set_.count(v2)); |
3435 } | 3451 } |
3436 | 3452 |
3437 TEST_F(ViewLayerTest, BoundsTreeRemoveChildRemovesBounds) { | 3453 TEST_F(ViewLayerTest, BoundsTreeRemoveChildRemovesBounds) { |
3438 BoundsTreeTestView* test_view = new BoundsTreeTestView; | 3454 BoundsTreeTestView* test_view = new BoundsTreeTestView; |
3439 widget()->SetContentsView(test_view); | 3455 widget()->SetContentsView(test_view); |
3440 | 3456 |
3441 View* v1 = new View; | 3457 View* v1 = new View; |
3442 v1->SetBoundsRect(gfx::Rect(5, 10, 15, 20)); | 3458 v1->SetBoundsRect(gfx::Rect(5, 10, 15, 20)); |
3443 test_view->AddChildView(v1); | 3459 test_view->AddChildView(v1); |
3444 | 3460 |
3445 View* v2 = new View; | 3461 View* v2 = new View; |
3446 v2->SetBoundsRect(gfx::Rect(1, 2, 3, 4)); | 3462 v2->SetBoundsRect(gfx::Rect(1, 2, 3, 4)); |
3447 v1->AddChildView(v2); | 3463 v1->AddChildView(v2); |
3448 | 3464 |
3449 // Schedule a full-view paint to get everyone's rectangles updated. | 3465 // Schedule a full-view paint to get everyone's rectangles updated. |
3450 test_view->SchedulePaintInRect(test_view->bounds()); | 3466 test_view->SchedulePaintInRect(test_view->bounds()); |
3451 GetRootLayer()->GetCompositor()->ScheduleDraw(); | 3467 GetRootLayer()->GetCompositor()->ScheduleDraw(); |
3452 ui::DrawWaiterForTest::Wait(GetRootLayer()->GetCompositor()); | 3468 ui::DrawWaiterForTest::WaitForCompositingEnded( |
| 3469 GetRootLayer()->GetCompositor()); |
3453 | 3470 |
3454 // Now remove v1 from the root view. | 3471 // Now remove v1 from the root view. |
3455 test_view->RemoveChildView(v1); | 3472 test_view->RemoveChildView(v1); |
3456 | 3473 |
3457 // Schedule another full-view paint. | 3474 // Schedule another full-view paint. |
3458 test_view->SchedulePaintInRect(test_view->bounds()); | 3475 test_view->SchedulePaintInRect(test_view->bounds()); |
3459 GetRootLayer()->GetCompositor()->ScheduleDraw(); | 3476 GetRootLayer()->GetCompositor()->ScheduleDraw(); |
3460 ui::DrawWaiterForTest::Wait(GetRootLayer()->GetCompositor()); | 3477 ui::DrawWaiterForTest::WaitForCompositingEnded( |
| 3478 GetRootLayer()->GetCompositor()); |
3461 // v1 and v2 should no longer be present in the test_view cull_set. | 3479 // v1 and v2 should no longer be present in the test_view cull_set. |
3462 EXPECT_EQ(2U, test_view->last_cull_set_.size()); | 3480 EXPECT_EQ(2U, test_view->last_cull_set_.size()); |
3463 EXPECT_EQ(0U, test_view->last_cull_set_.count(v1)); | 3481 EXPECT_EQ(0U, test_view->last_cull_set_.count(v1)); |
3464 EXPECT_EQ(0U, test_view->last_cull_set_.count(v2)); | 3482 EXPECT_EQ(0U, test_view->last_cull_set_.count(v2)); |
3465 | 3483 |
3466 // View v1 and v2 are no longer part of view hierarchy and therefore won't be | 3484 // View v1 and v2 are no longer part of view hierarchy and therefore won't be |
3467 // deleted with that hierarchy. | 3485 // deleted with that hierarchy. |
3468 delete v1; | 3486 delete v1; |
3469 } | 3487 } |
3470 | 3488 |
(...skipping 10 matching lines...) Expand all Loading... |
3481 v2->SetBoundsRect(gfx::Rect(5, 10, 40, 50)); | 3499 v2->SetBoundsRect(gfx::Rect(5, 10, 40, 50)); |
3482 v1->AddChildView(v2); | 3500 v1->AddChildView(v2); |
3483 | 3501 |
3484 View* v3 = new View; | 3502 View* v3 = new View; |
3485 v3->SetBoundsRect(gfx::Rect(1, 2, 3, 4)); | 3503 v3->SetBoundsRect(gfx::Rect(1, 2, 3, 4)); |
3486 v2->AddChildView(v3); | 3504 v2->AddChildView(v3); |
3487 | 3505 |
3488 // Schedule a full-view paint and ensure all views are present in the cull. | 3506 // Schedule a full-view paint and ensure all views are present in the cull. |
3489 test_view->SchedulePaintInRect(test_view->bounds()); | 3507 test_view->SchedulePaintInRect(test_view->bounds()); |
3490 GetRootLayer()->GetCompositor()->ScheduleDraw(); | 3508 GetRootLayer()->GetCompositor()->ScheduleDraw(); |
3491 ui::DrawWaiterForTest::Wait(GetRootLayer()->GetCompositor()); | 3509 ui::DrawWaiterForTest::WaitForCompositingEnded( |
| 3510 GetRootLayer()->GetCompositor()); |
3492 EXPECT_EQ(5U, test_view->last_cull_set_.size()); | 3511 EXPECT_EQ(5U, test_view->last_cull_set_.size()); |
3493 EXPECT_EQ(1U, test_view->last_cull_set_.count(widget()->GetRootView())); | 3512 EXPECT_EQ(1U, test_view->last_cull_set_.count(widget()->GetRootView())); |
3494 EXPECT_EQ(1U, test_view->last_cull_set_.count(test_view)); | 3513 EXPECT_EQ(1U, test_view->last_cull_set_.count(test_view)); |
3495 EXPECT_EQ(1U, test_view->last_cull_set_.count(v1)); | 3514 EXPECT_EQ(1U, test_view->last_cull_set_.count(v1)); |
3496 EXPECT_EQ(1U, test_view->last_cull_set_.count(v2)); | 3515 EXPECT_EQ(1U, test_view->last_cull_set_.count(v2)); |
3497 EXPECT_EQ(1U, test_view->last_cull_set_.count(v3)); | 3516 EXPECT_EQ(1U, test_view->last_cull_set_.count(v3)); |
3498 | 3517 |
3499 // Build an unrelated view hierarchy and move v2 in to it. | 3518 // Build an unrelated view hierarchy and move v2 in to it. |
3500 scoped_ptr<Widget> test_widget(new Widget); | 3519 scoped_ptr<Widget> test_widget(new Widget); |
3501 Widget::InitParams params = CreateParams(Widget::InitParams::TYPE_POPUP); | 3520 Widget::InitParams params = CreateParams(Widget::InitParams::TYPE_POPUP); |
3502 params.bounds = gfx::Rect(10, 10, 500, 500); | 3521 params.bounds = gfx::Rect(10, 10, 500, 500); |
3503 params.ownership = Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; | 3522 params.ownership = Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; |
3504 test_widget->Init(params); | 3523 test_widget->Init(params); |
3505 test_widget->Show(); | 3524 test_widget->Show(); |
3506 BoundsTreeTestView* widget_view = new BoundsTreeTestView; | 3525 BoundsTreeTestView* widget_view = new BoundsTreeTestView; |
3507 test_widget->SetContentsView(widget_view); | 3526 test_widget->SetContentsView(widget_view); |
3508 widget_view->AddChildView(v2); | 3527 widget_view->AddChildView(v2); |
3509 | 3528 |
3510 // Now schedule full-view paints in both widgets. | 3529 // Now schedule full-view paints in both widgets. |
3511 test_view->SchedulePaintInRect(test_view->bounds()); | 3530 test_view->SchedulePaintInRect(test_view->bounds()); |
3512 widget_view->SchedulePaintInRect(widget_view->bounds()); | 3531 widget_view->SchedulePaintInRect(widget_view->bounds()); |
3513 GetRootLayer()->GetCompositor()->ScheduleDraw(); | 3532 GetRootLayer()->GetCompositor()->ScheduleDraw(); |
3514 ui::DrawWaiterForTest::Wait(GetRootLayer()->GetCompositor()); | 3533 ui::DrawWaiterForTest::WaitForCompositingEnded( |
| 3534 GetRootLayer()->GetCompositor()); |
3515 | 3535 |
3516 // Only v1 should be present in the first cull set. | 3536 // Only v1 should be present in the first cull set. |
3517 EXPECT_EQ(3U, test_view->last_cull_set_.size()); | 3537 EXPECT_EQ(3U, test_view->last_cull_set_.size()); |
3518 EXPECT_EQ(1U, test_view->last_cull_set_.count(widget()->GetRootView())); | 3538 EXPECT_EQ(1U, test_view->last_cull_set_.count(widget()->GetRootView())); |
3519 EXPECT_EQ(1U, test_view->last_cull_set_.count(test_view)); | 3539 EXPECT_EQ(1U, test_view->last_cull_set_.count(test_view)); |
3520 EXPECT_EQ(1U, test_view->last_cull_set_.count(v1)); | 3540 EXPECT_EQ(1U, test_view->last_cull_set_.count(v1)); |
3521 | 3541 |
3522 // We should find v2 and v3 in the widget_view cull_set. | 3542 // We should find v2 and v3 in the widget_view cull_set. |
3523 EXPECT_EQ(4U, widget_view->last_cull_set_.size()); | 3543 EXPECT_EQ(4U, widget_view->last_cull_set_.size()); |
3524 EXPECT_EQ(1U, widget_view->last_cull_set_.count(test_widget->GetRootView())); | 3544 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... |
3635 // notification. | 3655 // notification. |
3636 TestView* test_view_child_2 = new TestView(); | 3656 TestView* test_view_child_2 = new TestView(); |
3637 test_view->AddChildView(test_view_child_2); | 3657 test_view->AddChildView(test_view_child_2); |
3638 EXPECT_TRUE(test_view_child_2->native_theme_); | 3658 EXPECT_TRUE(test_view_child_2->native_theme_); |
3639 EXPECT_EQ(widget->GetNativeTheme(), test_view_child_2->native_theme_); | 3659 EXPECT_EQ(widget->GetNativeTheme(), test_view_child_2->native_theme_); |
3640 | 3660 |
3641 widget->CloseNow(); | 3661 widget->CloseNow(); |
3642 } | 3662 } |
3643 | 3663 |
3644 } // namespace views | 3664 } // namespace views |
OLD | NEW |