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

Side by Side Diff: ui/compositor/layer_owner_unittest.cc

Issue 987043004: Relanding "Reset the root layer on the compositor when recreating a root layer." (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Changed LayerOwnerTestWithCompositor::compositor_'s access from protected to private. Created 5 years, 9 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 unified diff | Download patch
« no previous file with comments | « ui/compositor/layer_owner.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "ui/compositor/layer_owner.h" 5 #include "ui/compositor/layer_owner.h"
6 6
7 #include "base/test/null_task_runner.h"
7 #include "testing/gtest/include/gtest/gtest.h" 8 #include "testing/gtest/include/gtest/gtest.h"
9 #include "ui/compositor/compositor.h"
8 #include "ui/compositor/layer.h" 10 #include "ui/compositor/layer.h"
9 #include "ui/compositor/layer_animator.h" 11 #include "ui/compositor/layer_animator.h"
10 #include "ui/compositor/scoped_layer_animation_settings.h" 12 #include "ui/compositor/scoped_layer_animation_settings.h"
13 #include "ui/compositor/test/context_factories_for_test.h"
14 #include "ui/gfx/native_widget_types.h"
11 15
12 namespace ui { 16 namespace ui {
17 namespace {
18
19 // Test fixture for LayerOwner tests that require a ui::Compositor.
20 class LayerOwnerTestWithCompositor : public testing::Test {
21 public:
22 LayerOwnerTestWithCompositor();
23 ~LayerOwnerTestWithCompositor() override;
24
25 void SetUp() override;
26 void TearDown() override;
27
28 protected:
29 ui::Compositor* compositor() { return compositor_.get(); }
30
31 private:
32 scoped_ptr<ui::Compositor> compositor_;
33
34 DISALLOW_COPY_AND_ASSIGN(LayerOwnerTestWithCompositor);
35 };
36
37 LayerOwnerTestWithCompositor::LayerOwnerTestWithCompositor() {
38 }
39
40 LayerOwnerTestWithCompositor::~LayerOwnerTestWithCompositor() {
41 }
42
43 void LayerOwnerTestWithCompositor::SetUp() {
44 scoped_refptr<base::SingleThreadTaskRunner> task_runner =
45 new base::NullTaskRunner();
46
47 ui::ContextFactory* context_factory =
48 ui::InitializeContextFactoryForTests(false);
49
50 compositor_.reset(new ui::Compositor(gfx::kNullAcceleratedWidget,
51 context_factory, task_runner));
52 }
53
54 void LayerOwnerTestWithCompositor::TearDown() {
55 compositor_.reset();
56 ui::TerminateContextFactoryForTests();
57 }
58
59 } // namespace
13 60
14 TEST(LayerOwnerTest, RecreateLayerHonorsTargetVisibilityAndOpacity) { 61 TEST(LayerOwnerTest, RecreateLayerHonorsTargetVisibilityAndOpacity) {
15 LayerOwner owner; 62 LayerOwner owner;
16 Layer* layer = new Layer; 63 Layer* layer = new Layer;
17 layer->SetVisible(true); 64 layer->SetVisible(true);
18 layer->SetOpacity(1.0f); 65 layer->SetOpacity(1.0f);
19 66
20 owner.SetLayer(layer); 67 owner.SetLayer(layer);
21 68
22 ScopedLayerAnimationSettings settings(layer->GetAnimator()); 69 ScopedLayerAnimationSettings settings(layer->GetAnimator());
23 layer->SetVisible(false); 70 layer->SetVisible(false);
24 layer->SetOpacity(0.0f); 71 layer->SetOpacity(0.0f);
25 EXPECT_TRUE(layer->visible()); 72 EXPECT_TRUE(layer->visible());
26 EXPECT_EQ(1.0f, layer->opacity()); 73 EXPECT_EQ(1.0f, layer->opacity());
27 74
28 scoped_ptr<Layer> old_layer(owner.RecreateLayer()); 75 scoped_ptr<Layer> old_layer(owner.RecreateLayer());
29 EXPECT_FALSE(owner.layer()->visible()); 76 EXPECT_FALSE(owner.layer()->visible());
30 EXPECT_EQ(0.0f, owner.layer()->opacity()); 77 EXPECT_EQ(0.0f, owner.layer()->opacity());
31 } 78 }
32 79
80 TEST(LayerOwnerTest, RecreateRootLayerWithNullCompositor) {
81 LayerOwner owner;
82 Layer* layer = new Layer;
83 owner.SetLayer(layer);
84
85 scoped_ptr<Layer> layer_copy = owner.RecreateLayer();
86
87 EXPECT_EQ(nullptr, owner.layer()->GetCompositor());
88 EXPECT_EQ(nullptr, layer_copy->GetCompositor());
89 }
90
91 TEST_F(LayerOwnerTestWithCompositor, RecreateRootLayerWithCompositor) {
92 LayerOwner owner;
93 Layer* layer = new Layer;
94 owner.SetLayer(layer);
95
96 compositor()->SetRootLayer(layer);
97
98 scoped_ptr<Layer> layer_copy = owner.RecreateLayer();
99
100 EXPECT_EQ(compositor(), owner.layer()->GetCompositor());
101 EXPECT_EQ(owner.layer(), compositor()->root_layer());
102 EXPECT_EQ(nullptr, layer_copy->GetCompositor());
103 }
104
33 } // namespace ui 105 } // namespace ui
OLDNEW
« no previous file with comments | « ui/compositor/layer_owner.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698