Index: ui/compositor/layer_unittest.cc |
diff --git a/ui/compositor/layer_unittest.cc b/ui/compositor/layer_unittest.cc |
index 70581b6d08ebf5a0e9991d429628aa62a3319b91..df81764b49ea7817e82cde79a1898f958ec61b96 100644 |
--- a/ui/compositor/layer_unittest.cc |
+++ b/ui/compositor/layer_unittest.cc |
@@ -727,7 +727,7 @@ TEST_F(LayerWithNullDelegateTest, SwitchLayerPreservesCCLayerState) { |
EXPECT_TRUE(l1->cc_layer_for_testing()->DrawsContent()); |
EXPECT_TRUE(l1->cc_layer_for_testing()->contents_opaque()); |
EXPECT_TRUE(l1->cc_layer_for_testing()->force_render_surface()); |
- EXPECT_TRUE(l1->cc_layer_for_testing()->hide_layer_and_subtree()); |
+ EXPECT_EQ(l1->cc_layer_for_testing()->opacity(), 0.f); |
EXPECT_EQ(gfx::Size(4, 5), l1->cc_layer_for_testing()->bounds()); |
cc::Layer* before_layer = l1->cc_layer_for_testing(); |
@@ -744,7 +744,7 @@ TEST_F(LayerWithNullDelegateTest, SwitchLayerPreservesCCLayerState) { |
EXPECT_TRUE(l1->cc_layer_for_testing()->DrawsContent()); |
EXPECT_TRUE(l1->cc_layer_for_testing()->contents_opaque()); |
EXPECT_TRUE(l1->cc_layer_for_testing()->force_render_surface()); |
- EXPECT_TRUE(l1->cc_layer_for_testing()->hide_layer_and_subtree()); |
+ EXPECT_EQ(l1->cc_layer_for_testing()->opacity(), 0.f); |
EXPECT_EQ(gfx::Size(4, 5), l1->cc_layer_for_testing()->bounds()); |
EXPECT_FALSE(callback1_run); |
@@ -762,7 +762,7 @@ TEST_F(LayerWithNullDelegateTest, SwitchLayerPreservesCCLayerState) { |
EXPECT_TRUE(l1->cc_layer_for_testing()->DrawsContent()); |
EXPECT_TRUE(l1->cc_layer_for_testing()->contents_opaque()); |
EXPECT_TRUE(l1->cc_layer_for_testing()->force_render_surface()); |
- EXPECT_TRUE(l1->cc_layer_for_testing()->hide_layer_and_subtree()); |
+ EXPECT_EQ(l1->cc_layer_for_testing()->opacity(), 0.f); |
EXPECT_EQ(gfx::Size(4, 5), l1->cc_layer_for_testing()->bounds()); |
EXPECT_TRUE(callback2_run); |
@@ -781,7 +781,7 @@ TEST_F(LayerWithNullDelegateTest, SwitchLayerPreservesCCLayerState) { |
EXPECT_TRUE(l1->cc_layer_for_testing()->DrawsContent()); |
EXPECT_TRUE(l1->cc_layer_for_testing()->contents_opaque()); |
EXPECT_TRUE(l1->cc_layer_for_testing()->force_render_surface()); |
- EXPECT_TRUE(l1->cc_layer_for_testing()->hide_layer_and_subtree()); |
+ EXPECT_EQ(l1->cc_layer_for_testing()->opacity(), 0.f); |
EXPECT_EQ(gfx::Size(4, 5), l1->cc_layer_for_testing()->bounds()); |
EXPECT_FALSE(callback3_run); |
@@ -806,9 +806,9 @@ TEST_F(LayerWithNullDelegateTest, Visibility) { |
EXPECT_TRUE(l1->IsDrawn()); |
EXPECT_TRUE(l2->IsDrawn()); |
EXPECT_TRUE(l3->IsDrawn()); |
- EXPECT_FALSE(l1->cc_layer_for_testing()->hide_layer_and_subtree()); |
- EXPECT_FALSE(l2->cc_layer_for_testing()->hide_layer_and_subtree()); |
- EXPECT_FALSE(l3->cc_layer_for_testing()->hide_layer_and_subtree()); |
+ EXPECT_NE(l1->cc_layer_for_testing()->opacity(), 0.f); |
+ EXPECT_NE(l2->cc_layer_for_testing()->opacity(), 0.f); |
+ EXPECT_NE(l3->cc_layer_for_testing()->opacity(), 0.f); |
compositor()->SetRootLayer(l1.get()); |
@@ -818,25 +818,62 @@ TEST_F(LayerWithNullDelegateTest, Visibility) { |
EXPECT_FALSE(l1->IsDrawn()); |
EXPECT_FALSE(l2->IsDrawn()); |
EXPECT_FALSE(l3->IsDrawn()); |
- EXPECT_TRUE(l1->cc_layer_for_testing()->hide_layer_and_subtree()); |
- EXPECT_FALSE(l2->cc_layer_for_testing()->hide_layer_and_subtree()); |
- EXPECT_FALSE(l3->cc_layer_for_testing()->hide_layer_and_subtree()); |
+ EXPECT_EQ(l1->cc_layer_for_testing()->opacity(), 0.f); |
+ EXPECT_NE(l2->cc_layer_for_testing()->opacity(), 0.f); |
+ EXPECT_NE(l3->cc_layer_for_testing()->opacity(), 0.f); |
l3->SetVisible(false); |
EXPECT_FALSE(l1->IsDrawn()); |
EXPECT_FALSE(l2->IsDrawn()); |
EXPECT_FALSE(l3->IsDrawn()); |
- EXPECT_TRUE(l1->cc_layer_for_testing()->hide_layer_and_subtree()); |
- EXPECT_FALSE(l2->cc_layer_for_testing()->hide_layer_and_subtree()); |
- EXPECT_TRUE(l3->cc_layer_for_testing()->hide_layer_and_subtree()); |
+ EXPECT_EQ(l1->cc_layer_for_testing()->opacity(), 0.f); |
+ EXPECT_NE(l2->cc_layer_for_testing()->opacity(), 0.f); |
+ EXPECT_EQ(l3->cc_layer_for_testing()->opacity(), 0.f); |
l1->SetVisible(true); |
EXPECT_TRUE(l1->IsDrawn()); |
EXPECT_TRUE(l2->IsDrawn()); |
EXPECT_FALSE(l3->IsDrawn()); |
- EXPECT_FALSE(l1->cc_layer_for_testing()->hide_layer_and_subtree()); |
- EXPECT_FALSE(l2->cc_layer_for_testing()->hide_layer_and_subtree()); |
- EXPECT_TRUE(l3->cc_layer_for_testing()->hide_layer_and_subtree()); |
+ EXPECT_NE(l1->cc_layer_for_testing()->opacity(), 0.f); |
+ EXPECT_NE(l2->cc_layer_for_testing()->opacity(), 0.f); |
+ EXPECT_EQ(l3->cc_layer_for_testing()->opacity(), 0.f); |
+} |
+ |
+TEST_F(LayerWithNullDelegateTest, Opacity) { |
weiliangc
2016/01/15 19:30:24
Preferably with more descriptive test name.
jaydasika
2016/01/19 20:02:49
Done.
|
+ scoped_ptr<Layer> l1(new Layer(LAYER_TEXTURED)); |
+ |
+ NullLayerDelegate delegate; |
+ l1->set_delegate(&delegate); |
+ |
+ // Initially, the layer should be fully opaque. |
+ EXPECT_EQ(l1->cc_layer_for_testing()->opacity(), 1.f); |
+ |
+ compositor()->SetRootLayer(l1.get()); |
+ |
+ Draw(); |
+ |
+ // When a layer is invisble, the corresponding cc_layer should be completely |
+ // transparent, but the ui layer should store the original opacity of cc |
+ // layer. |
+ l1->SetVisible(false); |
+ EXPECT_EQ(l1->cc_layer_for_testing()->opacity(), 0.f); |
+ EXPECT_EQ(l1->opacity(), 1.f); |
+ |
+ // Any changes to opacity when the layer is invisble is cached by the ui |
+ // layer and set on the corresponding cc layer only when it becomes visible. |
+ l1->SetOpacity(0.5f); |
+ EXPECT_EQ(l1->cc_layer_for_testing()->opacity(), 0.f); |
+ EXPECT_EQ(l1->opacity(), 0.5f); |
+ l1->SetVisible(true); |
+ EXPECT_EQ(l1->cc_layer_for_testing()->opacity(), 0.5f); |
+ |
+ // The original opacity should be restored when invisible layer becomes |
+ // visible. |
+ l1->SetOpacity(0.2f); |
+ l1->SetVisible(false); |
+ EXPECT_EQ(l1->cc_layer_for_testing()->opacity(), 0.f); |
+ l1->SetVisible(true); |
+ EXPECT_EQ(l1->cc_layer_for_testing()->opacity(), 0.2f); |
} |
// Checks that stacking-related methods behave as advertised. |