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

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

Issue 976923002: Adjust view unittest to work with impl-side-painting (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: not to go thru cc in ui view unittests Created 5 years, 9 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 159 matching lines...) Expand 10 before | Expand all | Expand 10 after
170 view->ReorderChildView(view_b, a); 170 view->ReorderChildView(view_b, a);
171 } 171 }
172 172
173 if (!view->layer() && base::RandDouble() < 0.1) 173 if (!view->layer() && base::RandDouble() < 0.1)
174 view->SetPaintToLayer(true); 174 view->SetPaintToLayer(true);
175 175
176 if (base::RandDouble() < 0.1) 176 if (base::RandDouble() < 0.1)
177 view->SetVisible(!view->visible()); 177 view->SetVisible(!view->visible());
178 } 178 }
179 179
180 void PaintToViewInRect(views::Widget* widget, const gfx::Rect& rect) {
181 float image_scale = 1;
danakj 2015/03/06 18:21:59 1.f
182 bool is_opaque = true;
183 gfx::Canvas gcanvas(widget->GetRootView()->bounds().size(), image_scale,
danakj 2015/03/06 18:21:59 nit: just |canvas| ?
184 is_opaque);
185 gcanvas.ClipRect(rect);
186 widget->GetRootView()->Paint(&gcanvas, views::CullSet());
187 }
188
180 } // namespace 189 } // namespace
181 190
182 namespace views { 191 namespace views {
183 192
184 typedef ViewsTestBase ViewTest; 193 typedef ViewsTestBase ViewTest;
185 194
186 // A derived class for testing purpose. 195 // A derived class for testing purpose.
187 class TestView : public View { 196 class TestView : public View {
188 public: 197 public:
189 TestView() 198 TestView()
(...skipping 3201 matching lines...) Expand 10 before | Expand all | Expand 10 after
3391 3400
3392 View* v1 = new View(); 3401 View* v1 = new View();
3393 v1->SetBoundsRect(gfx::Rect(10, 15, 150, 151)); 3402 v1->SetBoundsRect(gfx::Rect(10, 15, 150, 151));
3394 test_view->AddChildView(v1); 3403 test_view->AddChildView(v1);
3395 3404
3396 View* v2 = new View(); 3405 View* v2 = new View();
3397 v2->SetBoundsRect(gfx::Rect(20, 33, 40, 50)); 3406 v2->SetBoundsRect(gfx::Rect(20, 33, 40, 50));
3398 v1->AddChildView(v2); 3407 v1->AddChildView(v2);
3399 3408
3400 // Schedule a full-view paint to get everyone's rectangles updated. 3409 // Schedule a full-view paint to get everyone's rectangles updated.
3401 test_view->SchedulePaintInRect(test_view->bounds()); 3410 PaintToViewInRect(widget(), test_view->bounds());
3402 GetRootLayer()->GetCompositor()->ScheduleDraw();
3403 ui::DrawWaiterForTest::WaitForCompositingEnded(
3404 GetRootLayer()->GetCompositor());
3405 3411
3406 // Now we have test_view - v1 - v2. Damage to only test_view should only 3412 // Now we have test_view - v1 - v2. Damage to only test_view should only
3407 // return root_view and test_view. 3413 // return root_view and test_view.
3408 test_view->SchedulePaintInRect(gfx::Rect(0, 0, 1, 1)); 3414 PaintToViewInRect(widget(), gfx::Rect(0, 0, 1, 1));
3409 GetRootLayer()->GetCompositor()->ScheduleDraw();
3410 ui::DrawWaiterForTest::WaitForCompositingEnded(
3411 GetRootLayer()->GetCompositor());
3412 EXPECT_EQ(2U, test_view->last_cull_set_.size()); 3415 EXPECT_EQ(2U, test_view->last_cull_set_.size());
3413 EXPECT_EQ(1U, test_view->last_cull_set_.count(widget()->GetRootView())); 3416 EXPECT_EQ(1U, test_view->last_cull_set_.count(widget()->GetRootView()));
3414 EXPECT_EQ(1U, test_view->last_cull_set_.count(test_view)); 3417 EXPECT_EQ(1U, test_view->last_cull_set_.count(test_view));
3415 3418
3416 // Damage to v1 only should only return root_view, test_view, and v1. 3419 // Damage to v1 only should only return root_view, test_view, and v1.
3417 test_view->SchedulePaintInRect(gfx::Rect(11, 16, 1, 1)); 3420 PaintToViewInRect(widget(), gfx::Rect(11, 16, 1, 1));
3418 GetRootLayer()->GetCompositor()->ScheduleDraw();
3419 ui::DrawWaiterForTest::WaitForCompositingEnded(
3420 GetRootLayer()->GetCompositor());
3421 EXPECT_EQ(3U, test_view->last_cull_set_.size()); 3421 EXPECT_EQ(3U, test_view->last_cull_set_.size());
3422 EXPECT_EQ(1U, test_view->last_cull_set_.count(widget()->GetRootView())); 3422 EXPECT_EQ(1U, test_view->last_cull_set_.count(widget()->GetRootView()));
3423 EXPECT_EQ(1U, test_view->last_cull_set_.count(test_view)); 3423 EXPECT_EQ(1U, test_view->last_cull_set_.count(test_view));
3424 EXPECT_EQ(1U, test_view->last_cull_set_.count(v1)); 3424 EXPECT_EQ(1U, test_view->last_cull_set_.count(v1));
3425 3425
3426 // A Damage rect inside v2 should get all 3 views back in the |last_cull_set_| 3426 // A Damage rect inside v2 should get all 3 views back in the |last_cull_set_|
3427 // on call to TestView::Paint(), along with the widget root view. 3427 // on call to TestView::Paint(), along with the widget root view.
3428 test_view->SchedulePaintInRect(gfx::Rect(31, 49, 1, 1)); 3428 PaintToViewInRect(widget(), gfx::Rect(31, 49, 1, 1));
3429 GetRootLayer()->GetCompositor()->ScheduleDraw();
3430 ui::DrawWaiterForTest::WaitForCompositingEnded(
3431 GetRootLayer()->GetCompositor());
3432 EXPECT_EQ(4U, test_view->last_cull_set_.size()); 3429 EXPECT_EQ(4U, test_view->last_cull_set_.size());
3433 EXPECT_EQ(1U, test_view->last_cull_set_.count(widget()->GetRootView())); 3430 EXPECT_EQ(1U, test_view->last_cull_set_.count(widget()->GetRootView()));
3434 EXPECT_EQ(1U, test_view->last_cull_set_.count(test_view)); 3431 EXPECT_EQ(1U, test_view->last_cull_set_.count(test_view));
3435 EXPECT_EQ(1U, test_view->last_cull_set_.count(v1)); 3432 EXPECT_EQ(1U, test_view->last_cull_set_.count(v1));
3436 EXPECT_EQ(1U, test_view->last_cull_set_.count(v2)); 3433 EXPECT_EQ(1U, test_view->last_cull_set_.count(v2));
3437 } 3434 }
3438 3435
3439 TEST_F(ViewLayerTest, BoundsTreeWithRTL) { 3436 TEST_F(ViewLayerTest, BoundsTreeWithRTL) {
3440 std::string locale = l10n_util::GetApplicationLocale(std::string()); 3437 std::string locale = l10n_util::GetApplicationLocale(std::string());
3441 base::i18n::SetICUDefaultLocale("ar"); 3438 base::i18n::SetICUDefaultLocale("ar");
3442 3439
3443 BoundsTreeTestView* test_view = new BoundsTreeTestView; 3440 BoundsTreeTestView* test_view = new BoundsTreeTestView;
3444 widget()->SetContentsView(test_view); 3441 widget()->SetContentsView(test_view);
3445 3442
3446 // Add child views, which should be in RTL coordinate space of parent view. 3443 // Add child views, which should be in RTL coordinate space of parent view.
3447 View* v1 = new View; 3444 View* v1 = new View;
3448 v1->SetBoundsRect(gfx::Rect(10, 12, 25, 26)); 3445 v1->SetBoundsRect(gfx::Rect(10, 12, 25, 26));
3449 test_view->AddChildView(v1); 3446 test_view->AddChildView(v1);
3450 3447
3451 View* v2 = new View; 3448 View* v2 = new View;
3452 v2->SetBoundsRect(gfx::Rect(5, 6, 7, 8)); 3449 v2->SetBoundsRect(gfx::Rect(5, 6, 7, 8));
3453 v1->AddChildView(v2); 3450 v1->AddChildView(v2);
3454 3451
3455 // Schedule a full-view paint to get everyone's rectangles updated. 3452 // Schedule a full-view paint to get everyone's rectangles updated.
3456 test_view->SchedulePaintInRect(test_view->bounds()); 3453 PaintToViewInRect(widget(), test_view->bounds());
3457 GetRootLayer()->GetCompositor()->ScheduleDraw();
3458 ui::DrawWaiterForTest::WaitForCompositingEnded(
3459 GetRootLayer()->GetCompositor());
3460 3454
3461 // Damage to the right side of the parent view should touch both child views. 3455 // Damage to the right side of the parent view should touch both child views.
3462 gfx::Rect rtl_damage(test_view->bounds().width() - 16, 18, 1, 1); 3456 gfx::Rect rtl_damage(test_view->bounds().width() - 16, 18, 1, 1);
3463 test_view->SchedulePaintInRect(rtl_damage); 3457 PaintToViewInRect(widget(), rtl_damage);
3464 GetRootLayer()->GetCompositor()->ScheduleDraw();
3465 ui::DrawWaiterForTest::WaitForCompositingEnded(
3466 GetRootLayer()->GetCompositor());
3467 EXPECT_EQ(4U, test_view->last_cull_set_.size()); 3458 EXPECT_EQ(4U, test_view->last_cull_set_.size());
3468 EXPECT_EQ(1U, test_view->last_cull_set_.count(widget()->GetRootView())); 3459 EXPECT_EQ(1U, test_view->last_cull_set_.count(widget()->GetRootView()));
3469 EXPECT_EQ(1U, test_view->last_cull_set_.count(test_view)); 3460 EXPECT_EQ(1U, test_view->last_cull_set_.count(test_view));
3470 EXPECT_EQ(1U, test_view->last_cull_set_.count(v1)); 3461 EXPECT_EQ(1U, test_view->last_cull_set_.count(v1));
3471 EXPECT_EQ(1U, test_view->last_cull_set_.count(v2)); 3462 EXPECT_EQ(1U, test_view->last_cull_set_.count(v2));
3472 3463
3473 // Damage to the left side of the parent view should only touch the 3464 // Damage to the left side of the parent view should only touch the
3474 // container views. 3465 // container views.
3475 gfx::Rect ltr_damage(16, 18, 1, 1); 3466 gfx::Rect ltr_damage(16, 18, 1, 1);
3476 test_view->SchedulePaintInRect(ltr_damage); 3467 PaintToViewInRect(widget(), ltr_damage);
3477 GetRootLayer()->GetCompositor()->ScheduleDraw();
3478 ui::DrawWaiterForTest::WaitForCompositingEnded(
3479 GetRootLayer()->GetCompositor());
3480 EXPECT_EQ(2U, test_view->last_cull_set_.size()); 3468 EXPECT_EQ(2U, test_view->last_cull_set_.size());
3481 EXPECT_EQ(1U, test_view->last_cull_set_.count(widget()->GetRootView())); 3469 EXPECT_EQ(1U, test_view->last_cull_set_.count(widget()->GetRootView()));
3482 EXPECT_EQ(1U, test_view->last_cull_set_.count(test_view)); 3470 EXPECT_EQ(1U, test_view->last_cull_set_.count(test_view));
3483 3471
3484 // Reset locale. 3472 // Reset locale.
3485 base::i18n::SetICUDefaultLocale(locale); 3473 base::i18n::SetICUDefaultLocale(locale);
3486 } 3474 }
3487 3475
3488 TEST_F(ViewLayerTest, BoundsTreeSetBoundsChangesCullSet) { 3476 TEST_F(ViewLayerTest, BoundsTreeSetBoundsChangesCullSet) {
3489 BoundsTreeTestView* test_view = new BoundsTreeTestView; 3477 BoundsTreeTestView* test_view = new BoundsTreeTestView;
3490 widget()->SetContentsView(test_view); 3478 widget()->SetContentsView(test_view);
3491 3479
3492 View* v1 = new View; 3480 View* v1 = new View;
3493 v1->SetBoundsRect(gfx::Rect(5, 6, 100, 101)); 3481 v1->SetBoundsRect(gfx::Rect(5, 6, 100, 101));
3494 test_view->AddChildView(v1); 3482 test_view->AddChildView(v1);
3495 3483
3496 View* v2 = new View; 3484 View* v2 = new View;
3497 v2->SetBoundsRect(gfx::Rect(20, 33, 40, 50)); 3485 v2->SetBoundsRect(gfx::Rect(20, 33, 40, 50));
3498 v1->AddChildView(v2); 3486 v1->AddChildView(v2);
3499 3487
3500 // Schedule a full-view paint to get everyone's rectangles updated. 3488 // Schedule a full-view paint to get everyone's rectangles updated.
3501 test_view->SchedulePaintInRect(test_view->bounds()); 3489 PaintToViewInRect(widget(), test_view->bounds());
3502 GetRootLayer()->GetCompositor()->ScheduleDraw();
3503 ui::DrawWaiterForTest::WaitForCompositingEnded(
3504 GetRootLayer()->GetCompositor());
3505 3490
3506 // Move v1 to a new origin out of the way of our next query. 3491 // Move v1 to a new origin out of the way of our next query.
3507 v1->SetBoundsRect(gfx::Rect(50, 60, 100, 101)); 3492 v1->SetBoundsRect(gfx::Rect(50, 60, 100, 101));
3508 // The move will force a repaint. 3493 // The move will force a repaint.
3509 GetRootLayer()->GetCompositor()->ScheduleDraw(); 3494 PaintToViewInRect(widget(), test_view->bounds());
3510 ui::DrawWaiterForTest::WaitForCompositingEnded(
3511 GetRootLayer()->GetCompositor());
3512 3495
3513 // Schedule a paint with damage rect where v1 used to be. 3496 // Schedule a paint with damage rect where v1 used to be.
3514 test_view->SchedulePaintInRect(gfx::Rect(5, 6, 10, 11)); 3497 PaintToViewInRect(widget(), gfx::Rect(5, 6, 10, 11));
3515 GetRootLayer()->GetCompositor()->ScheduleDraw();
3516 ui::DrawWaiterForTest::WaitForCompositingEnded(
3517 GetRootLayer()->GetCompositor());
3518 3498
3519 // Should only have picked up root_view and test_view. 3499 // Should only have picked up root_view and test_view.
3520 EXPECT_EQ(2U, test_view->last_cull_set_.size()); 3500 EXPECT_EQ(2U, test_view->last_cull_set_.size());
3521 EXPECT_EQ(1U, test_view->last_cull_set_.count(widget()->GetRootView())); 3501 EXPECT_EQ(1U, test_view->last_cull_set_.count(widget()->GetRootView()));
3522 EXPECT_EQ(1U, test_view->last_cull_set_.count(test_view)); 3502 EXPECT_EQ(1U, test_view->last_cull_set_.count(test_view));
3523 } 3503 }
3524 3504
3525 TEST_F(ViewLayerTest, BoundsTreeLayerChangeMakesNewTree) { 3505 TEST_F(ViewLayerTest, BoundsTreeLayerChangeMakesNewTree) {
3526 BoundsTreeTestView* test_view = new BoundsTreeTestView; 3506 BoundsTreeTestView* test_view = new BoundsTreeTestView;
3527 widget()->SetContentsView(test_view); 3507 widget()->SetContentsView(test_view);
3528 3508
3529 View* v1 = new View; 3509 View* v1 = new View;
3530 v1->SetBoundsRect(gfx::Rect(5, 10, 15, 20)); 3510 v1->SetBoundsRect(gfx::Rect(5, 10, 15, 20));
3531 test_view->AddChildView(v1); 3511 test_view->AddChildView(v1);
3532 3512
3533 View* v2 = new View; 3513 View* v2 = new View;
3534 v2->SetBoundsRect(gfx::Rect(1, 2, 3, 4)); 3514 v2->SetBoundsRect(gfx::Rect(1, 2, 3, 4));
3535 v1->AddChildView(v2); 3515 v1->AddChildView(v2);
3536 3516
3537 // Schedule a full-view paint to get everyone's rectangles updated. 3517 // Schedule a full-view paint to get everyone's rectangles updated.
3538 test_view->SchedulePaintInRect(test_view->bounds()); 3518 PaintToViewInRect(widget(), test_view->bounds());
3539 GetRootLayer()->GetCompositor()->ScheduleDraw();
3540 ui::DrawWaiterForTest::WaitForCompositingEnded(
3541 GetRootLayer()->GetCompositor());
3542 3519
3543 // Set v1 to paint to its own layer, it should remove itself from the 3520 // Set v1 to paint to its own layer, it should remove itself from the
3544 // test_view heiarchy and no longer intersect with damage rects in that cull 3521 // test_view heiarchy and no longer intersect with damage rects in that cull
3545 // set. 3522 // set.
3546 v1->SetPaintToLayer(true); 3523 v1->SetPaintToLayer(true);
3547 3524
3548 // Schedule another full-view paint. 3525 // Schedule another full-view paint.
3549 test_view->SchedulePaintInRect(test_view->bounds()); 3526 PaintToViewInRect(widget(), test_view->bounds());
3550 GetRootLayer()->GetCompositor()->ScheduleDraw();
3551 ui::DrawWaiterForTest::WaitForCompositingEnded(
3552 GetRootLayer()->GetCompositor());
3553 // v1 and v2 should no longer be present in the test_view cull_set. 3527 // v1 and v2 should no longer be present in the test_view cull_set.
3554 EXPECT_EQ(2U, test_view->last_cull_set_.size()); 3528 EXPECT_EQ(2U, test_view->last_cull_set_.size());
3555 EXPECT_EQ(0U, test_view->last_cull_set_.count(v1)); 3529 EXPECT_EQ(0U, test_view->last_cull_set_.count(v1));
3556 EXPECT_EQ(0U, test_view->last_cull_set_.count(v2)); 3530 EXPECT_EQ(0U, test_view->last_cull_set_.count(v2));
3557 3531
3558 // Now set v1 back to not painting to a layer. 3532 // Now set v1 back to not painting to a layer.
3559 v1->SetPaintToLayer(false); 3533 v1->SetPaintToLayer(false);
3560 // Schedule another full-view paint. 3534 // Schedule another full-view paint.
3561 test_view->SchedulePaintInRect(test_view->bounds()); 3535 PaintToViewInRect(widget(), test_view->bounds());
3562 GetRootLayer()->GetCompositor()->ScheduleDraw();
3563 ui::DrawWaiterForTest::WaitForCompositingEnded(
3564 GetRootLayer()->GetCompositor());
3565 // We should be back to the full cull set including v1 and v2. 3536 // We should be back to the full cull set including v1 and v2.
3566 EXPECT_EQ(4U, test_view->last_cull_set_.size()); 3537 EXPECT_EQ(4U, test_view->last_cull_set_.size());
3567 EXPECT_EQ(1U, test_view->last_cull_set_.count(widget()->GetRootView())); 3538 EXPECT_EQ(1U, test_view->last_cull_set_.count(widget()->GetRootView()));
3568 EXPECT_EQ(1U, test_view->last_cull_set_.count(test_view)); 3539 EXPECT_EQ(1U, test_view->last_cull_set_.count(test_view));
3569 EXPECT_EQ(1U, test_view->last_cull_set_.count(v1)); 3540 EXPECT_EQ(1U, test_view->last_cull_set_.count(v1));
3570 EXPECT_EQ(1U, test_view->last_cull_set_.count(v2)); 3541 EXPECT_EQ(1U, test_view->last_cull_set_.count(v2));
3571 } 3542 }
3572 3543
3573 TEST_F(ViewLayerTest, BoundsTreeRemoveChildRemovesBounds) { 3544 TEST_F(ViewLayerTest, BoundsTreeRemoveChildRemovesBounds) {
3574 BoundsTreeTestView* test_view = new BoundsTreeTestView; 3545 BoundsTreeTestView* test_view = new BoundsTreeTestView;
3575 widget()->SetContentsView(test_view); 3546 widget()->SetContentsView(test_view);
3576 3547
3577 View* v1 = new View; 3548 View* v1 = new View;
3578 v1->SetBoundsRect(gfx::Rect(5, 10, 15, 20)); 3549 v1->SetBoundsRect(gfx::Rect(5, 10, 15, 20));
3579 test_view->AddChildView(v1); 3550 test_view->AddChildView(v1);
3580 3551
3581 View* v2 = new View; 3552 View* v2 = new View;
3582 v2->SetBoundsRect(gfx::Rect(1, 2, 3, 4)); 3553 v2->SetBoundsRect(gfx::Rect(1, 2, 3, 4));
3583 v1->AddChildView(v2); 3554 v1->AddChildView(v2);
3584 3555
3585 // Schedule a full-view paint to get everyone's rectangles updated. 3556 // Schedule a full-view paint to get everyone's rectangles updated.
3586 test_view->SchedulePaintInRect(test_view->bounds()); 3557 PaintToViewInRect(widget(), test_view->bounds());
3587 GetRootLayer()->GetCompositor()->ScheduleDraw();
3588 ui::DrawWaiterForTest::WaitForCompositingEnded(
3589 GetRootLayer()->GetCompositor());
3590 3558
3591 // Now remove v1 from the root view. 3559 // Now remove v1 from the root view.
3592 test_view->RemoveChildView(v1); 3560 test_view->RemoveChildView(v1);
3593 3561
3594 // Schedule another full-view paint. 3562 // Schedule another full-view paint.
3595 test_view->SchedulePaintInRect(test_view->bounds()); 3563 PaintToViewInRect(widget(), test_view->bounds());
3596 GetRootLayer()->GetCompositor()->ScheduleDraw();
3597 ui::DrawWaiterForTest::WaitForCompositingEnded(
3598 GetRootLayer()->GetCompositor());
3599 // v1 and v2 should no longer be present in the test_view cull_set. 3564 // v1 and v2 should no longer be present in the test_view cull_set.
3600 EXPECT_EQ(2U, test_view->last_cull_set_.size()); 3565 EXPECT_EQ(2U, test_view->last_cull_set_.size());
3601 EXPECT_EQ(0U, test_view->last_cull_set_.count(v1)); 3566 EXPECT_EQ(0U, test_view->last_cull_set_.count(v1));
3602 EXPECT_EQ(0U, test_view->last_cull_set_.count(v2)); 3567 EXPECT_EQ(0U, test_view->last_cull_set_.count(v2));
3603 3568
3604 // View v1 and v2 are no longer part of view hierarchy and therefore won't be 3569 // View v1 and v2 are no longer part of view hierarchy and therefore won't be
3605 // deleted with that hierarchy. 3570 // deleted with that hierarchy.
3606 delete v1; 3571 delete v1;
3607 } 3572 }
3608 3573
3609 TEST_F(ViewLayerTest, BoundsTreeMoveViewMovesBounds) { 3574 TEST_F(ViewLayerTest, BoundsTreeMoveViewMovesBounds) {
3610 BoundsTreeTestView* test_view = new BoundsTreeTestView; 3575 BoundsTreeTestView* test_view = new BoundsTreeTestView;
3611 widget()->SetContentsView(test_view); 3576 widget()->SetContentsView(test_view);
3612 3577
3613 // Build hierarchy v1 - v2 - v3. 3578 // Build hierarchy v1 - v2 - v3.
3614 View* v1 = new View; 3579 View* v1 = new View;
3615 v1->SetBoundsRect(gfx::Rect(20, 30, 150, 160)); 3580 v1->SetBoundsRect(gfx::Rect(20, 30, 150, 160));
3616 test_view->AddChildView(v1); 3581 test_view->AddChildView(v1);
3617 3582
3618 View* v2 = new View; 3583 View* v2 = new View;
3619 v2->SetBoundsRect(gfx::Rect(5, 10, 40, 50)); 3584 v2->SetBoundsRect(gfx::Rect(5, 10, 40, 50));
3620 v1->AddChildView(v2); 3585 v1->AddChildView(v2);
3621 3586
3622 View* v3 = new View; 3587 View* v3 = new View;
3623 v3->SetBoundsRect(gfx::Rect(1, 2, 3, 4)); 3588 v3->SetBoundsRect(gfx::Rect(1, 2, 3, 4));
3624 v2->AddChildView(v3); 3589 v2->AddChildView(v3);
3625 3590
3626 // Schedule a full-view paint and ensure all views are present in the cull. 3591 // Schedule a full-view paint and ensure all views are present in the cull.
3627 test_view->SchedulePaintInRect(test_view->bounds()); 3592 PaintToViewInRect(widget(), test_view->bounds());
3628 GetRootLayer()->GetCompositor()->ScheduleDraw();
3629 ui::DrawWaiterForTest::WaitForCompositingEnded(
3630 GetRootLayer()->GetCompositor());
3631 EXPECT_EQ(5U, test_view->last_cull_set_.size()); 3593 EXPECT_EQ(5U, test_view->last_cull_set_.size());
3632 EXPECT_EQ(1U, test_view->last_cull_set_.count(widget()->GetRootView())); 3594 EXPECT_EQ(1U, test_view->last_cull_set_.count(widget()->GetRootView()));
3633 EXPECT_EQ(1U, test_view->last_cull_set_.count(test_view)); 3595 EXPECT_EQ(1U, test_view->last_cull_set_.count(test_view));
3634 EXPECT_EQ(1U, test_view->last_cull_set_.count(v1)); 3596 EXPECT_EQ(1U, test_view->last_cull_set_.count(v1));
3635 EXPECT_EQ(1U, test_view->last_cull_set_.count(v2)); 3597 EXPECT_EQ(1U, test_view->last_cull_set_.count(v2));
3636 EXPECT_EQ(1U, test_view->last_cull_set_.count(v3)); 3598 EXPECT_EQ(1U, test_view->last_cull_set_.count(v3));
3637 3599
3638 // Build an unrelated view hierarchy and move v2 in to it. 3600 // Build an unrelated view hierarchy and move v2 in to it.
3639 scoped_ptr<Widget> test_widget(new Widget); 3601 scoped_ptr<Widget> test_widget(new Widget);
3640 Widget::InitParams params = CreateParams(Widget::InitParams::TYPE_POPUP); 3602 Widget::InitParams params = CreateParams(Widget::InitParams::TYPE_POPUP);
3641 params.bounds = gfx::Rect(10, 10, 500, 500); 3603 params.bounds = gfx::Rect(10, 10, 500, 500);
3642 params.ownership = Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; 3604 params.ownership = Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET;
3643 test_widget->Init(params); 3605 test_widget->Init(params);
3644 test_widget->Show(); 3606 test_widget->Show();
3645 BoundsTreeTestView* widget_view = new BoundsTreeTestView; 3607 BoundsTreeTestView* widget_view = new BoundsTreeTestView;
3646 test_widget->SetContentsView(widget_view); 3608 test_widget->SetContentsView(widget_view);
3647 widget_view->AddChildView(v2); 3609 widget_view->AddChildView(v2);
3648 3610
3649 // Now schedule full-view paints in both widgets. 3611 // Now schedule full-view paints in both widgets.
3650 test_view->SchedulePaintInRect(test_view->bounds()); 3612 PaintToViewInRect(widget(), test_view->bounds());
3651 widget_view->SchedulePaintInRect(widget_view->bounds()); 3613 PaintToViewInRect(test_widget.get(), widget_view->bounds());
3652 GetRootLayer()->GetCompositor()->ScheduleDraw();
3653 ui::DrawWaiterForTest::WaitForCompositingEnded(
3654 GetRootLayer()->GetCompositor());
3655 3614
3656 // Only v1 should be present in the first cull set. 3615 // Only v1 should be present in the first cull set.
3657 EXPECT_EQ(3U, test_view->last_cull_set_.size()); 3616 EXPECT_EQ(3U, test_view->last_cull_set_.size());
3658 EXPECT_EQ(1U, test_view->last_cull_set_.count(widget()->GetRootView())); 3617 EXPECT_EQ(1U, test_view->last_cull_set_.count(widget()->GetRootView()));
3659 EXPECT_EQ(1U, test_view->last_cull_set_.count(test_view)); 3618 EXPECT_EQ(1U, test_view->last_cull_set_.count(test_view));
3660 EXPECT_EQ(1U, test_view->last_cull_set_.count(v1)); 3619 EXPECT_EQ(1U, test_view->last_cull_set_.count(v1));
3661 3620
3662 // We should find v2 and v3 in the widget_view cull_set. 3621 // We should find v2 and v3 in the widget_view cull_set.
3663 EXPECT_EQ(4U, widget_view->last_cull_set_.size()); 3622 EXPECT_EQ(4U, widget_view->last_cull_set_.size());
3664 EXPECT_EQ(1U, widget_view->last_cull_set_.count(test_widget->GetRootView())); 3623 EXPECT_EQ(1U, widget_view->last_cull_set_.count(test_widget->GetRootView()));
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
3775 // notification. 3734 // notification.
3776 TestView* test_view_child_2 = new TestView(); 3735 TestView* test_view_child_2 = new TestView();
3777 test_view->AddChildView(test_view_child_2); 3736 test_view->AddChildView(test_view_child_2);
3778 EXPECT_TRUE(test_view_child_2->native_theme_); 3737 EXPECT_TRUE(test_view_child_2->native_theme_);
3779 EXPECT_EQ(widget->GetNativeTheme(), test_view_child_2->native_theme_); 3738 EXPECT_EQ(widget->GetNativeTheme(), test_view_child_2->native_theme_);
3780 3739
3781 widget->CloseNow(); 3740 widget->CloseNow();
3782 } 3741 }
3783 3742
3784 } // namespace views 3743 } // namespace views
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698