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 | |
3599 private: | 3595 private: |
3600 Widget* widget_; | 3596 Widget* widget_; |
3601 }; | 3597 }; |
3602 | 3598 |
3603 | 3599 |
3604 TEST_F(ViewLayerTest, LayerToggling) { | 3600 TEST_F(ViewLayerTest, LayerToggling) { |
3605 // Because we lazily create textures the calls to DrawTree are necessary to | 3601 // Because we lazily create textures the calls to DrawTree are necessary to |
3606 // ensure we trigger creation of textures. | 3602 // ensure we trigger creation of textures. |
3607 ui::Layer* root_layer = widget()->GetLayer(); | 3603 ui::Layer* root_layer = widget()->GetLayer(); |
3608 View* content_view = new View; | 3604 View* content_view = new View; |
(...skipping 372 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3981 | 3977 |
3982 // Make content_view have a dirty rect, paint the layers and make sure | 3978 // Make content_view have a dirty rect, paint the layers and make sure |
3983 // PaintTrackingView is painted. | 3979 // PaintTrackingView is painted. |
3984 content_view->layer()->SchedulePaint(gfx::Rect(0, 0, 10, 10)); | 3980 content_view->layer()->SchedulePaint(gfx::Rect(0, 0, 10, 10)); |
3985 GetRootLayer()->GetCompositor()->ScheduleDraw(); | 3981 GetRootLayer()->GetCompositor()->ScheduleDraw(); |
3986 ui::DrawWaiterForTest::WaitForCompositingEnded( | 3982 ui::DrawWaiterForTest::WaitForCompositingEnded( |
3987 GetRootLayer()->GetCompositor()); | 3983 GetRootLayer()->GetCompositor()); |
3988 EXPECT_TRUE(content_view->painted()); | 3984 EXPECT_TRUE(content_view->painted()); |
3989 } | 3985 } |
3990 | 3986 |
3991 TEST_F(ViewLayerTest, NoCrashWhenParentlessViewSchedulesPaintOnParent) { | |
3992 TestView* v = new TestView; | |
Dan Beam
2016/01/05 18:06:08
TestView v;
SchedulePaintOnParent(&v);
would prob
| |
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 // Tests that the visibility of child layers are updated correctly when a View's | 3987 // Tests that the visibility of child layers are updated correctly when a View's |
4035 // visibility changes. | 3988 // visibility changes. |
4036 TEST_F(ViewLayerTest, VisibilityChildLayers) { | 3989 TEST_F(ViewLayerTest, VisibilityChildLayers) { |
4037 View* v1 = new View; | 3990 View* v1 = new View; |
4038 v1->SetPaintToLayer(true); | 3991 v1->SetPaintToLayer(true); |
4039 widget()->SetContentsView(v1); | 3992 widget()->SetContentsView(v1); |
4040 | 3993 |
4041 View* v2 = new View; | 3994 View* v2 = new View; |
4042 v1->AddChildView(v2); | 3995 v1->AddChildView(v2); |
4043 | 3996 |
(...skipping 348 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
4392 | 4345 |
4393 // The View should continue receiving events after the |handler| is deleted. | 4346 // The View should continue receiving events after the |handler| is deleted. |
4394 v->Reset(); | 4347 v->Reset(); |
4395 ui::MouseEvent released(ui::ET_MOUSE_RELEASED, gfx::Point(), gfx::Point(), | 4348 ui::MouseEvent released(ui::ET_MOUSE_RELEASED, gfx::Point(), gfx::Point(), |
4396 ui::EventTimeForNow(), 0, 0); | 4349 ui::EventTimeForNow(), 0, 0); |
4397 root->OnMouseReleased(released); | 4350 root->OnMouseReleased(released); |
4398 EXPECT_EQ(ui::ET_MOUSE_RELEASED, v->last_mouse_event_type_); | 4351 EXPECT_EQ(ui::ET_MOUSE_RELEASED, v->last_mouse_event_type_); |
4399 } | 4352 } |
4400 | 4353 |
4401 } // namespace views | 4354 } // namespace views |
OLD | NEW |