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

Side by Side Diff: ui/wm/core/window_util_unittest.cc

Issue 2383263002: Generalize layer mirroring for phantom windows (Closed)
Patch Set: Revert layer renaming Created 4 years, 2 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
« ui/wm/core/window_util.h ('K') | « ui/wm/core/window_util.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/wm/core/window_util.h" 5 #include "ui/wm/core/window_util.h"
6 6
7 #include <memory> 7 #include <memory>
8 8
9 #include "ui/aura/test/aura_test_base.h" 9 #include "ui/aura/test/aura_test_base.h"
10 #include "ui/aura/test/test_windows.h" 10 #include "ui/aura/test/test_windows.h"
11 #include "ui/aura/window.h" 11 #include "ui/aura/window.h"
12 #include "ui/compositor/layer.h" 12 #include "ui/compositor/layer.h"
13 #include "ui/compositor/layer_tree_owner.h" 13 #include "ui/compositor/layer_tree_owner.h"
14 #include "ui/compositor/paint_context.h"
15 14
16 namespace wm { 15 namespace wm {
17 namespace {
18
19 // Used to check if the delegate for recreated layer is created for
20 // the correct delegate.
21 class TestLayerDelegate : public ui::LayerDelegate {
22 public:
23 explicit TestLayerDelegate(ui::Layer* original_layer)
24 : original_layer_(original_layer) {}
25 ~TestLayerDelegate() override = default;
26
27 // ui::LayerDelegate:
28 void OnPaintLayer(const ui::PaintContext& context) override {}
29 void OnDelegatedFrameDamage(const gfx::Rect& damage_rect_in_dip) override {}
30 void OnDeviceScaleFactorChanged(float device_scale_factor) override {}
31
32 ui::Layer* original_layer() { return original_layer_; }
33
34 private:
35 ui::Layer* original_layer_;
36
37 DISALLOW_COPY_AND_ASSIGN(TestLayerDelegate);
38 };
39
40 // Used to create a TestLayerDelegate for recreated layers.
41 class TestLayerDelegateFactory : public ::wm::LayerDelegateFactory {
42 public:
43 TestLayerDelegateFactory() = default;
44 ~TestLayerDelegateFactory() override = default;
45
46 // ::wm::LayerDelegateFactory:
47 ui::LayerDelegate* CreateDelegate(ui::Layer* new_layer,
48 ui::Layer* original_layer) override {
49 delegates_.push_back(base::MakeUnique<TestLayerDelegate>(original_layer));
50 return delegates_.back().get();
51 }
52
53 size_t delegate_count() const { return delegates_.size(); }
54
55 TestLayerDelegate* GetDelegateAt(int index) {
56 return delegates_[index].get();
57 }
58
59 private:
60 std::vector<std::unique_ptr<TestLayerDelegate>> delegates_;
61
62 DISALLOW_COPY_AND_ASSIGN(TestLayerDelegateFactory);
63 };
64
65 } // namespace
66 16
67 typedef aura::test::AuraTestBase WindowUtilTest; 17 typedef aura::test::AuraTestBase WindowUtilTest;
68 18
69 // Test if the recreate layers does not recreate layers that have 19 // Test if the recreate layers does not recreate layers that have
70 // already been acquired. 20 // already been acquired.
71 TEST_F(WindowUtilTest, RecreateLayers) { 21 TEST_F(WindowUtilTest, RecreateLayers) {
72 std::unique_ptr<aura::Window> window1( 22 std::unique_ptr<aura::Window> window1(
73 aura::test::CreateTestWindowWithId(0, NULL)); 23 aura::test::CreateTestWindowWithId(0, NULL));
74 std::unique_ptr<aura::Window> window11( 24 std::unique_ptr<aura::Window> window11(
75 aura::test::CreateTestWindowWithId(1, window1.get())); 25 aura::test::CreateTestWindowWithId(1, window1.get()));
76 std::unique_ptr<aura::Window> window12( 26 std::unique_ptr<aura::Window> window12(
77 aura::test::CreateTestWindowWithId(2, window1.get())); 27 aura::test::CreateTestWindowWithId(2, window1.get()));
78 28
79 ASSERT_EQ(2u, window1->layer()->children().size()); 29 ASSERT_EQ(2u, window1->layer()->children().size());
80 30
81 std::unique_ptr<ui::Layer> acquired(window11->AcquireLayer()); 31 std::unique_ptr<ui::Layer> acquired(window11->AcquireLayer());
82 EXPECT_TRUE(acquired.get()); 32 EXPECT_TRUE(acquired.get());
83 EXPECT_EQ(acquired.get(), window11->layer()); 33 EXPECT_EQ(acquired.get(), window11->layer());
84 34
85 std::unique_ptr<ui::LayerTreeOwner> tree = 35 std::unique_ptr<ui::LayerTreeOwner> tree = wm::RecreateLayers(window1.get());
86 wm::RecreateLayers(window1.get(), nullptr);
87 36
88 // The detached layer should not have the layer that has 37 // The detached layer should not have the layer that has
89 // already been detached. 38 // already been detached.
90 ASSERT_EQ(1u, tree->root()->children().size()); 39 ASSERT_EQ(1u, tree->root()->children().size());
91 // Child layer is new instance. 40 // Child layer is new instance.
92 EXPECT_NE(window11->layer(), tree->root()->children()[0]); 41 EXPECT_NE(window11->layer(), tree->root()->children()[0]);
93 EXPECT_NE(window12->layer(), tree->root()->children()[0]); 42 EXPECT_NE(window12->layer(), tree->root()->children()[0]);
94 43
95 // The original window should have both. 44 // The original window should have both.
96 ASSERT_EQ(2u, window1->layer()->children().size()); 45 ASSERT_EQ(2u, window1->layer()->children().size());
97 EXPECT_EQ(window11->layer(), window1->layer()->children()[0]); 46 EXPECT_EQ(window11->layer(), window1->layer()->children()[0]);
98 EXPECT_EQ(window12->layer(), window1->layer()->children()[1]); 47 EXPECT_EQ(window12->layer(), window1->layer()->children()[1]);
99 48
100 // Delete the window before the acquired layer is deleted. 49 // Delete the window before the acquired layer is deleted.
101 window11.reset(); 50 window11.reset();
102 } 51 }
103 52
104 // Test if the LayerDelegateFactory creates new delegates for
105 // recreated layers correctly.
106 TEST_F(WindowUtilTest, RecreateLayersWithDelegate) {
107 TestLayerDelegateFactory factory;
108 std::unique_ptr<aura::Window> window1(
109 aura::test::CreateTestWindowWithId(0, NULL));
110 std::unique_ptr<aura::Window> window11(
111 aura::test::CreateTestWindowWithId(1, window1.get()));
112 std::unique_ptr<aura::Window> window12(
113 aura::test::CreateTestWindowWithId(2, window1.get()));
114
115 std::unique_ptr<ui::LayerTreeOwner> tree =
116 wm::RecreateLayers(window1.get(), &factory);
117
118 ASSERT_EQ(3u, factory.delegate_count());
119
120 TestLayerDelegate* new_delegate_1 = factory.GetDelegateAt(0);
121 TestLayerDelegate* new_delegate_11 = factory.GetDelegateAt(1);
122 TestLayerDelegate* new_delegate_12 = factory.GetDelegateAt(2);
123
124 EXPECT_EQ(window1->layer(), new_delegate_1->original_layer());
125 EXPECT_EQ(window11->layer(),
126 new_delegate_11->original_layer());
127 EXPECT_EQ(window12->layer(),
128 new_delegate_12->original_layer());
129
130 EXPECT_EQ(tree->root()->delegate(), new_delegate_1);
131 EXPECT_EQ(tree->root()->children()[0]->delegate(), new_delegate_11);
132 EXPECT_EQ(tree->root()->children()[1]->delegate(), new_delegate_12);
133 }
134
135 } // namespace wm 53 } // namespace wm
OLDNEW
« ui/wm/core/window_util.h ('K') | « ui/wm/core/window_util.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698