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

Unified Diff: ui/views/view_unittest.cc

Issue 2639203007: Update SetPaintToLayer to accept LayerType (Closed)
Patch Set: Refactor Created 3 years, 11 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 side-by-side diff with in-line comments
Download patch
Index: ui/views/view_unittest.cc
diff --git a/ui/views/view_unittest.cc b/ui/views/view_unittest.cc
index bb71337326da40184c6090bd7ed46186cad96138..c3910d848194bade2817f394fbe8d9547885f669 100644
--- a/ui/views/view_unittest.cc
+++ b/ui/views/view_unittest.cc
@@ -25,6 +25,7 @@
#include "ui/compositor/compositor.h"
#include "ui/compositor/layer.h"
#include "ui/compositor/layer_animator.h"
+#include "ui/compositor/layer_type.h"
#include "ui/compositor/paint_context.h"
#include "ui/compositor/test/draw_waiter_for_test.h"
#include "ui/events/event.h"
@@ -157,7 +158,7 @@ void ConstructTree(views::View* view, int depth) {
views::View* v = new views::View;
view->AddChildView(v);
if (base::RandDouble() > 0.5)
- v->SetPaintToLayer(true);
+ v->SetPaintToLayer(ui::LAYER_TEXTURED);
if (base::RandDouble() < 0.2)
v->SetVisible(false);
@@ -184,7 +185,7 @@ void ScrambleTree(views::View* view) {
}
if (!view->layer() && base::RandDouble() < 0.1)
- view->SetPaintToLayer(true);
+ view->SetPaintToLayer(ui::LAYER_TEXTURED);
if (base::RandDouble() < 0.1)
view->SetVisible(!view->visible());
@@ -783,15 +784,15 @@ TEST_F(ViewTest, PaintContainsChildrenInRTL) {
v1->AddChildView(v2);
// Verify where the layers actually appear.
- v1->SetPaintToLayer(true);
+ v1->SetPaintToLayer(ui::LAYER_TEXTURED);
// x: 25 - 10(x) - 12(width) = 3
EXPECT_EQ(gfx::Rect(3, 11, 12, 13), v1->layer()->bounds());
- v1->SetPaintToLayer(false);
+ v1->SetPaintToLayer(ui::LAYER_NOT_DRAWN);
- v2->SetPaintToLayer(true);
+ v2->SetPaintToLayer(ui::LAYER_TEXTURED);
// x: 25 - 10(parent x) - 3(x) - 6(width) = 6
EXPECT_EQ(gfx::Rect(6, 15, 6, 5), v2->layer()->bounds());
- v2->SetPaintToLayer(false);
+ v2->SetPaintToLayer(ui::LAYER_NOT_DRAWN);
// Paint everything once, since it has to build its cache. Then we can test
// invalidation.
@@ -859,15 +860,15 @@ TEST_F(ViewTest, PaintIntersectsChildrenInRTL) {
v1->AddChildView(v2);
// Verify where the layers actually appear.
- v1->SetPaintToLayer(true);
+ v1->SetPaintToLayer(ui::LAYER_TEXTURED);
// x: 25 - 10(x) - 12(width) = 3
EXPECT_EQ(gfx::Rect(3, 11, 12, 13), v1->layer()->bounds());
- v1->SetPaintToLayer(false);
+ v1->SetPaintToLayer(ui::LAYER_NOT_DRAWN);
- v2->SetPaintToLayer(true);
+ v2->SetPaintToLayer(ui::LAYER_TEXTURED);
// x: 25 - 10(parent x) - 3(x) - 6(width) = 6
EXPECT_EQ(gfx::Rect(6, 15, 6, 5), v2->layer()->bounds());
- v2->SetPaintToLayer(false);
+ v2->SetPaintToLayer(ui::LAYER_NOT_DRAWN);
// Paint everything once, since it has to build its cache. Then we can test
// invalidation.
@@ -935,15 +936,15 @@ TEST_F(ViewTest, PaintIntersectsChildButNotGrandChildInRTL) {
v1->AddChildView(v2);
// Verify where the layers actually appear.
- v1->SetPaintToLayer(true);
+ v1->SetPaintToLayer(ui::LAYER_TEXTURED);
// x: 25 - 10(x) - 12(width) = 3
EXPECT_EQ(gfx::Rect(3, 11, 12, 13), v1->layer()->bounds());
- v1->SetPaintToLayer(false);
+ v1->SetPaintToLayer(ui::LAYER_NOT_DRAWN);
- v2->SetPaintToLayer(true);
+ v2->SetPaintToLayer(ui::LAYER_TEXTURED);
// x: 25 - 10(parent x) - 3(x) - 6(width) = 6
EXPECT_EQ(gfx::Rect(6, 15, 6, 5), v2->layer()->bounds());
- v2->SetPaintToLayer(false);
+ v2->SetPaintToLayer(ui::LAYER_NOT_DRAWN);
// Paint everything once, since it has to build its cache. Then we can test
// invalidation.
@@ -1011,15 +1012,15 @@ TEST_F(ViewTest, PaintIntersectsNoChildrenInRTL) {
v1->AddChildView(v2);
// Verify where the layers actually appear.
- v1->SetPaintToLayer(true);
+ v1->SetPaintToLayer(ui::LAYER_TEXTURED);
// x: 25 - 10(x) - 12(width) = 3
EXPECT_EQ(gfx::Rect(3, 11, 12, 13), v1->layer()->bounds());
- v1->SetPaintToLayer(false);
+ v1->SetPaintToLayer(ui::LAYER_NOT_DRAWN);
- v2->SetPaintToLayer(true);
+ v2->SetPaintToLayer(ui::LAYER_TEXTURED);
// x: 25 - 10(parent x) - 3(x) - 6(width) = 6
EXPECT_EQ(gfx::Rect(6, 15, 6, 5), v2->layer()->bounds());
- v2->SetPaintToLayer(false);
+ v2->SetPaintToLayer(ui::LAYER_NOT_DRAWN);
// Paint everything once, since it has to build its cache. Then we can test
// invalidation.
@@ -1099,15 +1100,15 @@ TEST_F(ViewTest, PaintIntersectsOneChildInRTL) {
root_view->AddChildView(v2);
// Verify where the layers actually appear.
- v1->SetPaintToLayer(true);
+ v1->SetPaintToLayer(ui::LAYER_TEXTURED);
// x: 25 - 10(x) - 12(width) = 3
EXPECT_EQ(gfx::Rect(3, 11, 12, 13), v1->layer()->bounds());
- v1->SetPaintToLayer(false);
+ v1->SetPaintToLayer(ui::LAYER_NOT_DRAWN);
- v2->SetPaintToLayer(true);
+ v2->SetPaintToLayer(ui::LAYER_TEXTURED);
// x: 25 - 3(x) - 6(width) = 16
EXPECT_EQ(gfx::Rect(16, 4, 6, 5), v2->layer()->bounds());
- v2->SetPaintToLayer(false);
+ v2->SetPaintToLayer(ui::LAYER_NOT_DRAWN);
// Paint everything once, since it has to build its cache. Then we can test
// invalidation.
@@ -1146,7 +1147,7 @@ TEST_F(ViewTest, PaintInPromotedToLayer) {
View* root_view = widget->GetRootView();
TestView* v1 = new TestView;
- v1->SetPaintToLayer(true);
+ v1->SetPaintToLayer(ui::LAYER_TEXTURED);
v1->SetBounds(10, 11, 12, 13);
root_view->AddChildView(v1);
@@ -1230,7 +1231,7 @@ TEST_F(ViewTest, PaintLocalBounds) {
root_view->SetBounds(0, 0, 200, 200);
TestPaintView* v1 = new TestPaintView;
- v1->SetPaintToLayer(true);
+ v1->SetPaintToLayer(ui::LAYER_TEXTURED);
// Set bounds for |v1| such that it has an offset to its parent and only part
// of it is visible. The visible bounds does not intersect with |root_view|'s
@@ -3733,7 +3734,7 @@ TEST_F(ViewLayerTest, LayerToggling) {
// Create v1, give it a bounds and verify everything is set up correctly.
View* v1 = new View;
- v1->SetPaintToLayer(true);
+ v1->SetPaintToLayer(ui::LAYER_TEXTURED);
EXPECT_TRUE(v1->layer() != NULL);
v1->SetBoundsRect(gfx::Rect(20, 30, 140, 150));
content_view->AddChildView(v1);
@@ -3746,14 +3747,14 @@ TEST_F(ViewLayerTest, LayerToggling) {
v1->AddChildView(v2);
EXPECT_TRUE(v2->layer() == NULL);
v2->SetBoundsRect(gfx::Rect(10, 20, 30, 40));
- v2->SetPaintToLayer(true);
+ v2->SetPaintToLayer(ui::LAYER_TEXTURED);
ASSERT_TRUE(v2->layer() != NULL);
EXPECT_EQ(v1->layer(), v2->layer()->parent());
EXPECT_EQ(gfx::Rect(10, 20, 30, 40), v2->layer()->bounds());
// Turn off v1s layer. v2 should still have a layer but its parent should have
// changed.
- v1->SetPaintToLayer(false);
+ v1->SetPaintToLayer(ui::LAYER_NOT_DRAWN);
EXPECT_TRUE(v1->layer() == NULL);
EXPECT_TRUE(v2->layer() != NULL);
EXPECT_EQ(root_layer, v2->layer()->parent());
@@ -3792,13 +3793,13 @@ TEST_F(ViewLayerTest, NestedLayerToggling) {
v1->AddChildView(v2);
View* v3 = new View;
- v3->SetPaintToLayer(true);
+ v3->SetPaintToLayer(ui::LAYER_TEXTURED);
v2->AddChildView(v3);
ASSERT_TRUE(v3->layer() != NULL);
// At this point we have v1-v2-v3. v3 has a layer, v1 and v2 don't.
- v1->SetPaintToLayer(true);
+ v1->SetPaintToLayer(ui::LAYER_TEXTURED);
EXPECT_EQ(v1->layer(), v3->layer()->parent());
}
@@ -3808,7 +3809,7 @@ TEST_F(ViewLayerTest, LayerAnimator) {
View* v1 = new View;
content_view->AddChildView(v1);
- v1->SetPaintToLayer(true);
+ v1->SetPaintToLayer(ui::LAYER_TEXTURED);
EXPECT_TRUE(v1->layer() != NULL);
TestLayerAnimator* animator = new TestLayerAnimator();
@@ -3834,7 +3835,7 @@ TEST_F(ViewLayerTest, BoundsChangeWithLayer) {
View* v2 = new View;
v2->SetBoundsRect(gfx::Rect(10, 11, 40, 50));
v1->AddChildView(v2);
- v2->SetPaintToLayer(true);
+ v2->SetPaintToLayer(ui::LAYER_TEXTURED);
ASSERT_TRUE(v2->layer() != NULL);
EXPECT_EQ(gfx::Rect(30, 41, 40, 50), v2->layer()->bounds());
@@ -3866,7 +3867,7 @@ TEST_F(ViewLayerTest, BoundInRTL) {
// |v1| is initially not attached to anything. So its layer will have the same
// bounds as the view.
View* v1 = new View;
- v1->SetPaintToLayer(true);
+ v1->SetPaintToLayer(ui::LAYER_TEXTURED);
v1->SetBounds(10, 10, 20, 10);
EXPECT_EQ(gfx::Rect(10, 10, 20, 10),
v1->layer()->bounds());
@@ -3884,12 +3885,12 @@ TEST_F(ViewLayerTest, BoundInRTL) {
v2->SetBounds(50, 10, 30, 10);
EXPECT_FALSE(v2->layer());
view->AddChildView(v2);
- v2->SetPaintToLayer(true);
+ v2->SetPaintToLayer(ui::LAYER_TEXTURED);
EXPECT_EQ(gfx::Rect(content_width - 80, 10, 30, 10),
v2->layer()->bounds());
gfx::Rect l2bounds = v2->layer()->bounds();
- view->SetPaintToLayer(true);
+ view->SetPaintToLayer(ui::LAYER_TEXTURED);
EXPECT_EQ(l1bounds, v1->layer()->bounds());
EXPECT_EQ(l2bounds, v2->layer()->bounds());
@@ -3899,7 +3900,7 @@ TEST_F(ViewLayerTest, BoundInRTL) {
l1bounds.set_x(l1bounds.x() + 5);
EXPECT_EQ(l1bounds, v1->layer()->bounds());
- view->SetPaintToLayer(false);
+ view->SetPaintToLayer(ui::LAYER_NOT_DRAWN);
EXPECT_EQ(l1bounds, v1->layer()->bounds());
EXPECT_EQ(l2bounds, v2->layer()->bounds());
@@ -3920,7 +3921,7 @@ TEST_F(ViewLayerTest, ResizeParentInRTL) {
// Create a paints-to-layer view |v1|.
View* v1 = new View;
- v1->SetPaintToLayer(true);
+ v1->SetPaintToLayer(ui::LAYER_TEXTURED);
v1->SetBounds(10, 10, 20, 10);
view->AddChildView(v1);
EXPECT_EQ(gfx::Rect(content_width - 30, 10, 20, 10),
@@ -3928,7 +3929,7 @@ TEST_F(ViewLayerTest, ResizeParentInRTL) {
// Attach a paints-to-layer child view to |v1|.
View* v2 = new View;
- v2->SetPaintToLayer(true);
+ v2->SetPaintToLayer(ui::LAYER_TEXTURED);
v2->SetBounds(3, 5, 6, 4);
EXPECT_EQ(gfx::Rect(3, 5, 6, 4),
v2->layer()->bounds());
@@ -3941,7 +3942,7 @@ TEST_F(ViewLayerTest, ResizeParentInRTL) {
View* v3 = new View;
v3->SetBounds(1, 1, 18, 8);
View* v4 = new View;
- v4->SetPaintToLayer(true);
+ v4->SetPaintToLayer(ui::LAYER_TEXTURED);
v4->SetBounds(2, 4, 6, 4);
EXPECT_EQ(gfx::Rect(2, 4, 6, 4),
v4->layer()->bounds());
@@ -4013,7 +4014,7 @@ TEST_F(ViewLayerTest, ToggleVisibilityWithLayer) {
// still have a layer, but the layer should not be attached to the root
// layer.
View* v1 = new View;
- v1->SetPaintToLayer(true);
+ v1->SetPaintToLayer(ui::LAYER_TEXTURED);
EXPECT_TRUE(v1->layer());
EXPECT_FALSE(LayerIsAncestor(widget()->GetCompositor()->root_layer(),
v1->layer()));
@@ -4049,7 +4050,7 @@ TEST_F(ViewLayerTest, OrphanLayerAfterViewRemove) {
View* v2 = new View;
v1->AddChildView(v2);
- v2->SetPaintToLayer(true);
+ v2->SetPaintToLayer(ui::LAYER_TEXTURED);
EXPECT_TRUE(LayerIsAncestor(widget()->GetCompositor()->root_layer(),
v2->layer()));
EXPECT_TRUE(v2->layer()->IsDrawn());
@@ -4092,7 +4093,7 @@ TEST_F(ViewLayerTest, DontPaintChildrenWithLayers) {
return;
PaintTrackingView* content_view = new PaintTrackingView;
widget()->SetContentsView(content_view);
- content_view->SetPaintToLayer(true);
+ content_view->SetPaintToLayer(ui::LAYER_TEXTURED);
GetRootLayer()->GetCompositor()->ScheduleDraw();
ui::DrawWaiterForTest::WaitForCompositingEnded(
GetRootLayer()->GetCompositor());
@@ -4142,7 +4143,7 @@ TEST_F(ViewLayerTest, ParentPaintWhenSwitchingPaintToLayerFromFalseToTrue) {
parent_view.AddChildView(child_view);
parent_view.scheduled_paint_rects_.clear();
- child_view->SetPaintToLayer(true);
+ child_view->SetPaintToLayer(ui::LAYER_TEXTURED);
EXPECT_EQ(1U, parent_view.scheduled_paint_rects_.size());
}
@@ -4151,7 +4152,7 @@ TEST_F(ViewLayerTest, NoParentPaintWhenSwitchingPaintToLayerFromTrueToTrue) {
parent_view.SetBounds(10, 11, 12, 13);
TestView* child_view = new TestView;
- child_view->SetPaintToLayer(true);
+ child_view->SetPaintToLayer(ui::LAYER_TEXTURED);
parent_view.AddChildView(child_view);
parent_view.scheduled_paint_rects_.clear();
@@ -4162,7 +4163,7 @@ TEST_F(ViewLayerTest, NoParentPaintWhenSwitchingPaintToLayerFromTrueToTrue) {
// visibility changes.
TEST_F(ViewLayerTest, VisibilityChildLayers) {
View* v1 = new View;
- v1->SetPaintToLayer(true);
+ v1->SetPaintToLayer(ui::LAYER_TEXTURED);
widget()->SetContentsView(v1);
View* v2 = new View;
@@ -4173,7 +4174,7 @@ TEST_F(ViewLayerTest, VisibilityChildLayers) {
v3->SetVisible(false);
View* v4 = new View;
- v4->SetPaintToLayer(true);
+ v4->SetPaintToLayer(ui::LAYER_TEXTURED);
v3->AddChildView(v4);
EXPECT_TRUE(v1->layer()->IsDrawn());
@@ -4209,7 +4210,7 @@ TEST_F(ViewLayerTest, VisibilityChildLayers) {
// marking this as FLAKY.
TEST_F(ViewLayerTest, DISABLED_ViewLayerTreesInSync) {
View* content = new View;
- content->SetPaintToLayer(true);
+ content->SetPaintToLayer(ui::LAYER_TEXTURED);
widget()->SetContentsView(content);
widget()->Show();
@@ -4232,10 +4233,10 @@ TEST_F(ViewLayerTest, ReorderUnderWidget) {
View* content = new View;
widget()->SetContentsView(content);
View* c1 = new View;
- c1->SetPaintToLayer(true);
+ c1->SetPaintToLayer(ui::LAYER_TEXTURED);
content->AddChildView(c1);
View* c2 = new View;
- c2->SetPaintToLayer(true);
+ c2->SetPaintToLayer(ui::LAYER_TEXTURED);
content->AddChildView(c2);
ui::Layer* parent_layer = c1->layer()->parent();
@@ -4255,7 +4256,7 @@ TEST_F(ViewLayerTest, AcquireLayer) {
View* content = new View;
widget()->SetContentsView(content);
std::unique_ptr<View> c1(new View);
- c1->SetPaintToLayer(true);
+ c1->SetPaintToLayer(ui::LAYER_TEXTURED);
EXPECT_TRUE(c1->layer());
content->AddChildView(c1.get());
@@ -4272,13 +4273,13 @@ TEST_F(ViewLayerTest, AcquireLayer) {
// Verify the z-order of the layers as a result of calling RecreateLayer().
TEST_F(ViewLayerTest, RecreateLayerZOrder) {
std::unique_ptr<View> v(new View());
- v->SetPaintToLayer(true);
+ v->SetPaintToLayer(ui::LAYER_TEXTURED);
View* v1 = new View();
- v1->SetPaintToLayer(true);
+ v1->SetPaintToLayer(ui::LAYER_TEXTURED);
v->AddChildView(v1);
View* v2 = new View();
- v2->SetPaintToLayer(true);
+ v2->SetPaintToLayer(ui::LAYER_TEXTURED);
v->AddChildView(v2);
// Test the initial z-order.
@@ -4305,10 +4306,10 @@ TEST_F(ViewLayerTest, RecreateLayerZOrderWidgetParent) {
widget()->SetContentsView(v);
View* v1 = new View();
- v1->SetPaintToLayer(true);
+ v1->SetPaintToLayer(ui::LAYER_TEXTURED);
v->AddChildView(v1);
View* v2 = new View();
- v2->SetPaintToLayer(true);
+ v2->SetPaintToLayer(ui::LAYER_TEXTURED);
v->AddChildView(v2);
ui::Layer* root_layer = GetRootLayer();
@@ -4333,9 +4334,9 @@ TEST_F(ViewLayerTest, RecreateLayerZOrderWidgetParent) {
// a View.
TEST_F(ViewLayerTest, RecreateLayerMovesNonViewChildren) {
View v;
- v.SetPaintToLayer(true);
+ v.SetPaintToLayer(ui::LAYER_TEXTURED);
View child;
- child.SetPaintToLayer(true);
+ child.SetPaintToLayer(ui::LAYER_TEXTURED);
v.AddChildView(&child);
ASSERT_TRUE(v.layer() != NULL);
ASSERT_EQ(1u, v.layer()->children().size());
@@ -4379,12 +4380,12 @@ TEST_F(ViewLayerTest, SnapLayerToPixel) {
v11->SetBoundsRect(gfx::Rect(1, 1, 10, 10));
v1->SetBoundsRect(gfx::Rect(1, 1, 10, 10));
- v11->SetPaintToLayer(true);
+ v11->SetPaintToLayer(ui::LAYER_TEXTURED);
EXPECT_EQ("0.40 0.40", ToString(v11->layer()->subpixel_position_offset()));
// Creating a layer in parent should update the child view's layer offset.
- v1->SetPaintToLayer(true);
+ v1->SetPaintToLayer(ui::LAYER_TEXTURED);
EXPECT_EQ("-0.20 -0.20", ToString(v1->layer()->subpixel_position_offset()));
EXPECT_EQ("-0.20 -0.20", ToString(v11->layer()->subpixel_position_offset()));
@@ -4394,7 +4395,7 @@ TEST_F(ViewLayerTest, SnapLayerToPixel) {
EXPECT_EQ("0.33 0.33", ToString(v11->layer()->subpixel_position_offset()));
// Deleting parent's layer should update the child view's layer's offset.
- v1->SetPaintToLayer(false);
+ v1->SetPaintToLayer(ui::LAYER_NOT_DRAWN);
EXPECT_EQ("0.00 0.00", ToString(v11->layer()->subpixel_position_offset()));
// Setting parent view should update the child view's layer's offset.
@@ -4545,7 +4546,9 @@ class WidgetWithCustomTheme : public Widget {
// See comment above test for details.
class ViewThatAddsViewInOnNativeThemeChanged : public View {
public:
- ViewThatAddsViewInOnNativeThemeChanged() { SetPaintToLayer(true); }
+ ViewThatAddsViewInOnNativeThemeChanged() {
+ SetPaintToLayer(ui::LAYER_TEXTURED);
+ }
~ViewThatAddsViewInOnNativeThemeChanged() override {}
bool on_native_theme_changed_called() const {
@@ -4592,7 +4595,7 @@ class TestNativeTheme : public ui::NativeTheme {
// Creates and adds a new child view to |parent| that has a layer.
void AddViewWithChildLayer(View* parent) {
View* child = new View;
- child->SetPaintToLayer(true);
+ child->SetPaintToLayer(ui::LAYER_TEXTURED);
parent->AddChildView(child);
}
@@ -4623,7 +4626,7 @@ TEST_F(ViewTest, CrashOnAddFromFromOnNativeThemeChanged) {
class NoLayerWhenHiddenView : public View {
public:
NoLayerWhenHiddenView() {
- SetPaintToLayer(true);
+ SetPaintToLayer(ui::LAYER_TEXTURED);
set_owned_by_client();
SetBounds(0, 0, 100, 100);
}
@@ -4634,7 +4637,7 @@ class NoLayerWhenHiddenView : public View {
void VisibilityChanged(View* starting_from, bool is_visible) override {
if (!is_visible) {
was_hidden_ = true;
- SetPaintToLayer(false);
+ SetPaintToLayer(ui::LAYER_NOT_DRAWN);
}
}
@@ -4701,7 +4704,7 @@ class OrderableView : public View {
TEST_F(ViewTest, ChildViewZOrderChanged) {
const int kChildrenCount = 4;
std::unique_ptr<View> view(new OrderableView());
- view->SetPaintToLayer(true);
+ view->SetPaintToLayer(ui::LAYER_TEXTURED);
for (int i = 0; i < kChildrenCount; ++i)
AddViewWithChildLayer(view.get());
View::Views children = view->GetChildrenInZOrder();
« ui/views/view.cc ('K') | « ui/views/view.cc ('k') | ui/views/view_unittest_aura.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698