Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(115)

Side by Side Diff: ui/views/view_unittest.cc

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

Powered by Google App Engine
This is Rietveld 408576698