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/i18n/rtl.h" | 7 #include "base/i18n/rtl.h" |
8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
9 #include "base/rand_util.h" | 9 #include "base/rand_util.h" |
10 #include "base/strings/string_util.h" | 10 #include "base/strings/string_util.h" |
(...skipping 3574 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3585 widget_->GetRootView()->SetBounds(0, 0, 200, 200); | 3585 widget_->GetRootView()->SetBounds(0, 0, 200, 200); |
3586 } | 3586 } |
3587 | 3587 |
3588 void TearDown() override { | 3588 void TearDown() override { |
3589 widget_->CloseNow(); | 3589 widget_->CloseNow(); |
3590 ViewsTestBase::TearDown(); | 3590 ViewsTestBase::TearDown(); |
3591 } | 3591 } |
3592 | 3592 |
3593 Widget* widget() { return widget_; } | 3593 Widget* widget() { return widget_; } |
3594 | 3594 |
| 3595 protected: |
| 3596 // Accessors to View internals. |
| 3597 void SchedulePaintOnParent(View* view) { view->SchedulePaintOnParent(); } |
| 3598 |
3595 private: | 3599 private: |
3596 Widget* widget_; | 3600 Widget* widget_; |
3597 }; | 3601 }; |
3598 | 3602 |
3599 | 3603 |
3600 TEST_F(ViewLayerTest, LayerToggling) { | 3604 TEST_F(ViewLayerTest, LayerToggling) { |
3601 // Because we lazily create textures the calls to DrawTree are necessary to | 3605 // Because we lazily create textures the calls to DrawTree are necessary to |
3602 // ensure we trigger creation of textures. | 3606 // ensure we trigger creation of textures. |
3603 ui::Layer* root_layer = widget()->GetLayer(); | 3607 ui::Layer* root_layer = widget()->GetLayer(); |
3604 View* content_view = new View; | 3608 View* content_view = new View; |
(...skipping 372 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3977 | 3981 |
3978 // Make content_view have a dirty rect, paint the layers and make sure | 3982 // Make content_view have a dirty rect, paint the layers and make sure |
3979 // PaintTrackingView is painted. | 3983 // PaintTrackingView is painted. |
3980 content_view->layer()->SchedulePaint(gfx::Rect(0, 0, 10, 10)); | 3984 content_view->layer()->SchedulePaint(gfx::Rect(0, 0, 10, 10)); |
3981 GetRootLayer()->GetCompositor()->ScheduleDraw(); | 3985 GetRootLayer()->GetCompositor()->ScheduleDraw(); |
3982 ui::DrawWaiterForTest::WaitForCompositingEnded( | 3986 ui::DrawWaiterForTest::WaitForCompositingEnded( |
3983 GetRootLayer()->GetCompositor()); | 3987 GetRootLayer()->GetCompositor()); |
3984 EXPECT_TRUE(content_view->painted()); | 3988 EXPECT_TRUE(content_view->painted()); |
3985 } | 3989 } |
3986 | 3990 |
| 3991 TEST_F(ViewLayerTest, NoCrashWhenParentlessViewSchedulesPaintOnParent) { |
| 3992 TestView* v = new TestView; |
| 3993 SchedulePaintOnParent(v); |
| 3994 } |
| 3995 |
| 3996 TEST_F(ViewLayerTest, ScheduledRectsInParentAfterSchedulingPaint) { |
| 3997 TestView* v1 = new TestView; |
| 3998 v1->SetBounds(10, 10, 100, 100); |
| 3999 |
| 4000 TestView* v2 = new TestView; |
| 4001 v2->SetBounds(5, 6, 10, 20); |
| 4002 v1->AddChildView(v2); |
| 4003 |
| 4004 v1->scheduled_paint_rects_.clear(); |
| 4005 SchedulePaintOnParent(v2); |
| 4006 ASSERT_EQ(1U, v1->scheduled_paint_rects_.size()); |
| 4007 EXPECT_EQ(gfx::Rect(5, 6, 10, 20), v1->scheduled_paint_rects_.front()); |
| 4008 } |
| 4009 |
| 4010 TEST_F(ViewLayerTest, ParentPaintWhenSwitchingPaintToLayerFromFalseToTrue) { |
| 4011 TestView* v1 = new TestView; |
| 4012 v1->SetBounds(10, 11, 12, 13); |
| 4013 |
| 4014 TestView* v2 = new TestView; |
| 4015 v1->AddChildView(v2); |
| 4016 |
| 4017 v1->scheduled_paint_rects_.clear(); |
| 4018 v2->SetPaintToLayer(true); |
| 4019 EXPECT_EQ(1U, v1->scheduled_paint_rects_.size()); |
| 4020 } |
| 4021 |
| 4022 TEST_F(ViewLayerTest, NoParentPaintWhenSwitchingPaintToLayerFromTrueToTrue) { |
| 4023 TestView* v1 = new TestView; |
| 4024 v1->SetBounds(10, 11, 12, 13); |
| 4025 |
| 4026 TestView* v2 = new TestView; |
| 4027 v2->SetPaintToLayer(true); |
| 4028 v1->AddChildView(v2); |
| 4029 |
| 4030 v1->scheduled_paint_rects_.clear(); |
| 4031 EXPECT_EQ(0U, v1->scheduled_paint_rects_.size()); |
| 4032 } |
| 4033 |
| 4034 TEST_F(ViewLayerTest, |
| 4035 ParentPaintWhenSwitchingFillBoundsOpaquelyFromTrueToFalse) { |
| 4036 TestView* v1 = new TestView; |
| 4037 v1->SetBounds(10, 11, 12, 13); |
| 4038 |
| 4039 TestView* v2 = new TestView; |
| 4040 v2->SetPaintToLayer(true); |
| 4041 v2->SetFillsBoundsOpaquely(true); |
| 4042 v1->AddChildView(v2); |
| 4043 |
| 4044 v1->scheduled_paint_rects_.clear(); |
| 4045 v2->SetFillsBoundsOpaquely(false); |
| 4046 EXPECT_EQ(1U, v1->scheduled_paint_rects_.size()); |
| 4047 } |
| 4048 |
| 4049 TEST_F(ViewLayerTest, |
| 4050 ParentPaintWhenSwitchingFillBoundsOpaquelyFromFalseToTrue) { |
| 4051 TestView* v1 = new TestView; |
| 4052 v1->SetBounds(10, 11, 12, 13); |
| 4053 |
| 4054 TestView* v2 = new TestView; |
| 4055 v2->SetPaintToLayer(true); |
| 4056 v2->SetFillsBoundsOpaquely(false); |
| 4057 v1->AddChildView(v2); |
| 4058 |
| 4059 v1->scheduled_paint_rects_.clear(); |
| 4060 v2->SetFillsBoundsOpaquely(true); |
| 4061 EXPECT_EQ(0U, v1->scheduled_paint_rects_.size()); |
| 4062 } |
| 4063 |
3987 // Tests that the visibility of child layers are updated correctly when a View's | 4064 // Tests that the visibility of child layers are updated correctly when a View's |
3988 // visibility changes. | 4065 // visibility changes. |
3989 TEST_F(ViewLayerTest, VisibilityChildLayers) { | 4066 TEST_F(ViewLayerTest, VisibilityChildLayers) { |
3990 View* v1 = new View; | 4067 View* v1 = new View; |
3991 v1->SetPaintToLayer(true); | 4068 v1->SetPaintToLayer(true); |
3992 widget()->SetContentsView(v1); | 4069 widget()->SetContentsView(v1); |
3993 | 4070 |
3994 View* v2 = new View; | 4071 View* v2 = new View; |
3995 v1->AddChildView(v2); | 4072 v1->AddChildView(v2); |
3996 | 4073 |
(...skipping 348 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4345 | 4422 |
4346 // The View should continue receiving events after the |handler| is deleted. | 4423 // The View should continue receiving events after the |handler| is deleted. |
4347 v->Reset(); | 4424 v->Reset(); |
4348 ui::MouseEvent released(ui::ET_MOUSE_RELEASED, gfx::Point(), gfx::Point(), | 4425 ui::MouseEvent released(ui::ET_MOUSE_RELEASED, gfx::Point(), gfx::Point(), |
4349 ui::EventTimeForNow(), 0, 0); | 4426 ui::EventTimeForNow(), 0, 0); |
4350 root->OnMouseReleased(released); | 4427 root->OnMouseReleased(released); |
4351 EXPECT_EQ(ui::ET_MOUSE_RELEASED, v->last_mouse_event_type_); | 4428 EXPECT_EQ(ui::ET_MOUSE_RELEASED, v->last_mouse_event_type_); |
4352 } | 4429 } |
4353 | 4430 |
4354 } // namespace views | 4431 } // namespace views |
OLD | NEW |