Chromium Code Reviews| Index: ui/views/view_unittest.cc |
| diff --git a/ui/views/view_unittest.cc b/ui/views/view_unittest.cc |
| index 8e424762e5b90ceca860753442827c318616689b..b1903f0fa803378008cca01e99e1910fb7b0ed42 100644 |
| --- a/ui/views/view_unittest.cc |
| +++ b/ui/views/view_unittest.cc |
| @@ -528,6 +528,76 @@ TEST_F(ViewTest, PaintEmptyView) { |
| EXPECT_TRUE(v2->did_paint_); |
| } |
| +static void TestPaintWithMovedViewUsesCache( |
| + ViewTest* test, |
| + const gfx::Rect& visual_rect_in_layer_space) { |
|
danakj
2015/11/25 00:30:56
expected_vis...
wkorman
2015/11/25 00:44:51
Done.
|
| + ScopedTestPaintWidget widget( |
| + test->CreateParams(Widget::InitParams::TYPE_POPUP)); |
| + View* root_view = widget->GetRootView(); |
| + TestView* v1 = new TestView; |
| + v1->SetBounds(10, 11, 12, 13); |
| + root_view->AddChildView(v1); |
| + |
| + // Paint everything once, since it has to build its cache. Then we can test |
| + // invalidation. |
| + gfx::Rect pixel_rect = gfx::Rect(1, 1); |
| + float device_scale_factor = 1.f; |
| + scoped_refptr<cc::DisplayItemList> list = |
| + cc::DisplayItemList::Create(pixel_rect, cc::DisplayItemListSettings()); |
| + root_view->Paint( |
| + ui::PaintContext(list.get(), device_scale_factor, pixel_rect)); |
| + EXPECT_TRUE(v1->did_paint_); |
| + v1->Reset(); |
| + // The visual rects for (clip, drawing, transform) should be in layer space. |
| + int item_index = 3; |
| + EXPECT_EQ(visual_rect_in_layer_space, |
| + list->VisualRectForTesting(item_index++)); |
| + EXPECT_EQ(visual_rect_in_layer_space, |
| + list->VisualRectForTesting(item_index++)); |
| + EXPECT_EQ(visual_rect_in_layer_space, list->VisualRectForTesting(item_index)); |
| + |
| + // If invalidation doesn't intersect v1, we paint with the cache. |
| + list = cc::DisplayItemList::Create(pixel_rect, cc::DisplayItemListSettings()); |
| + root_view->Paint( |
| + ui::PaintContext(list.get(), device_scale_factor, pixel_rect)); |
| + EXPECT_FALSE(v1->did_paint_); |
| + v1->Reset(); |
| + |
| + // If invalidation does intersect v1, we don't paint with the cache. |
| + list = cc::DisplayItemList::Create(pixel_rect, cc::DisplayItemListSettings()); |
| + root_view->Paint( |
| + ui::PaintContext(list.get(), device_scale_factor, v1->bounds())); |
| + EXPECT_TRUE(v1->did_paint_); |
| + v1->Reset(); |
| + |
| + // Moving the view should still use the cache when the invalidation doesn't |
| + // intersect v1. |
| + list = cc::DisplayItemList::Create(pixel_rect, cc::DisplayItemListSettings()); |
| + v1->SetX(9); |
| + root_view->Paint( |
| + ui::PaintContext(list.get(), device_scale_factor, pixel_rect)); |
| + EXPECT_FALSE(v1->did_paint_); |
| + v1->Reset(); |
| + |
|
danakj
2015/11/25 00:30:56
check the visual rects after moving, both with and
wkorman
2015/11/25 00:44:51
Done.
|
| + // Moving the view should not use the cache when there is no invalidation. |
| + list = cc::DisplayItemList::Create(pixel_rect, cc::DisplayItemListSettings()); |
| + v1->SetX(8); |
| + root_view->Paint(ui::PaintContext( |
| + ui::PaintContext(list.get(), device_scale_factor, pixel_rect), |
| + ui::PaintContext::CLONE_WITHOUT_INVALIDATION)); |
| + EXPECT_TRUE(v1->did_paint_); |
| + v1->Reset(); |
| +} |
| + |
| +TEST_F(ViewTest, PaintWithMovedViewUsesCache) { |
| + TestPaintWithMovedViewUsesCache(this, gfx::Rect(10, 11, 12, 13)); |
| +} |
| + |
| +TEST_F(ViewTest, PaintWithMovedViewUsesCacheInRTL) { |
| + ScopedRTL rtl; |
| + TestPaintWithMovedViewUsesCache(this, gfx::Rect(3, 11, 12, 13)); |
| +} |
| + |
| TEST_F(ViewTest, PaintWithUnknownInvalidation) { |
| ScopedTestPaintWidget widget(CreateParams(Widget::InitParams::TYPE_POPUP)); |
| View* root_view = widget->GetRootView(); |