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

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

Issue 1992853002: Create a LayerDelegate for recreated layers to draw when their content is invalidated. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 7 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"
14 15
15 namespace wm { 16 namespace wm {
17 namespace {
18 class TestLayerDelegate : public ui::LayerDelegate {
sky 2016/05/19 20:06:49 nit: newline between 17/18, and description.
oshima 2016/05/19 23:32:21 Done.
19 public:
20 TestLayerDelegate(ui::LayerDelegate* original_delegate)
sky 2016/05/19 20:06:49 explicit
oshima 2016/05/19 23:32:22 Done.
21 : original_delegate_(original_delegate) {}
22 ~TestLayerDelegate() override = default;
23
24 void OnPaintLayer(const ui::PaintContext& context) override {}
sky 2016/05/19 20:06:49 nit: // ui::LayerDelegate: (or some other prefix)
oshima 2016/05/19 23:32:22 Done.
25 void OnDelegatedFrameDamage(const gfx::Rect& damage_rect_in_dip) override {}
26 void OnDeviceScaleFactorChanged(float device_scale_factor) override {}
27 base::Closure PrepareForLayerBoundsChange() override {
28 return base::Closure();
29 }
30
31 ui::LayerDelegate* original_delegate() { return original_delegate_; }
32
33 private:
34 ui::LayerDelegate* original_delegate_;
35
36 DISALLOW_COPY_AND_ASSIGN(TestLayerDelegate);
37 };
38
39 class TestLayerDelegateFactory : public ::wm::LayerDelegateFactory {
sky 2016/05/19 20:06:49 Description.
oshima 2016/05/19 23:32:22 Done.
40 public:
41 TestLayerDelegateFactory() = default;
42 ~TestLayerDelegateFactory() override = default;
43
44 ui::LayerDelegate* CreateDelegate(ui::LayerDelegate* delegate) override {
45 TestLayerDelegate* new_delegate = new TestLayerDelegate(delegate);
46 delegates_.push_back(base::WrapUnique(new_delegate));
47 return new_delegate;
48 }
49
50 size_t delegate_count() const { return delegates_.size(); }
51
52 TestLayerDelegate* GetDelegateAt(int index) {
53 return delegates_[index].get();
54 }
55
56 private:
57 std::vector<std::unique_ptr<TestLayerDelegate>> delegates_;
58
59 DISALLOW_COPY_AND_ASSIGN(TestLayerDelegateFactory);
60 };
61
62 } // namespace
16 63
17 typedef aura::test::AuraTestBase WindowUtilTest; 64 typedef aura::test::AuraTestBase WindowUtilTest;
18 65
19 // Test if the recreate layers does not recreate layers that have 66 // Test if the recreate layers does not recreate layers that have
20 // already been acquired. 67 // already been acquired.
21 TEST_F(WindowUtilTest, RecreateLayers) { 68 TEST_F(WindowUtilTest, RecreateLayers) {
22 std::unique_ptr<aura::Window> window1( 69 std::unique_ptr<aura::Window> window1(
23 aura::test::CreateTestWindowWithId(0, NULL)); 70 aura::test::CreateTestWindowWithId(0, NULL));
24 std::unique_ptr<aura::Window> window11( 71 std::unique_ptr<aura::Window> window11(
25 aura::test::CreateTestWindowWithId(1, window1.get())); 72 aura::test::CreateTestWindowWithId(1, window1.get()));
26 std::unique_ptr<aura::Window> window12( 73 std::unique_ptr<aura::Window> window12(
27 aura::test::CreateTestWindowWithId(2, window1.get())); 74 aura::test::CreateTestWindowWithId(2, window1.get()));
28 75
29 ASSERT_EQ(2u, window1->layer()->children().size()); 76 ASSERT_EQ(2u, window1->layer()->children().size());
30 77
31 std::unique_ptr<ui::Layer> acquired(window11->AcquireLayer()); 78 std::unique_ptr<ui::Layer> acquired(window11->AcquireLayer());
32 EXPECT_TRUE(acquired.get()); 79 EXPECT_TRUE(acquired.get());
33 EXPECT_EQ(acquired.get(), window11->layer()); 80 EXPECT_EQ(acquired.get(), window11->layer());
34 81
35 std::unique_ptr<ui::LayerTreeOwner> tree = wm::RecreateLayers(window1.get()); 82 std::unique_ptr<ui::LayerTreeOwner> tree =
83 wm::RecreateLayers(window1.get(), nullptr);
36 84
37 // The detached layer should not have the layer that has 85 // The detached layer should not have the layer that has
38 // already been detached. 86 // already been detached.
39 ASSERT_EQ(1u, tree->root()->children().size()); 87 ASSERT_EQ(1u, tree->root()->children().size());
40 // Child layer is new instance. 88 // Child layer is new instance.
41 EXPECT_NE(window11->layer(), tree->root()->children()[0]); 89 EXPECT_NE(window11->layer(), tree->root()->children()[0]);
42 EXPECT_NE(window12->layer(), tree->root()->children()[0]); 90 EXPECT_NE(window12->layer(), tree->root()->children()[0]);
43 91
44 // The original window should have both. 92 // The original window should have both.
45 ASSERT_EQ(2u, window1->layer()->children().size()); 93 ASSERT_EQ(2u, window1->layer()->children().size());
46 EXPECT_EQ(window11->layer(), window1->layer()->children()[0]); 94 EXPECT_EQ(window11->layer(), window1->layer()->children()[0]);
47 EXPECT_EQ(window12->layer(), window1->layer()->children()[1]); 95 EXPECT_EQ(window12->layer(), window1->layer()->children()[1]);
48 96
49 // Delete the window before the acquired layer is deleted. 97 // Delete the window before the acquired layer is deleted.
50 window11.reset(); 98 window11.reset();
51 } 99 }
100
101 // Test if the LayerDelegateFactory creates new delegates for
102 // recreated layers correctly.
103 TEST_F(WindowUtilTest, RecreateLayersWithDelegate) {
104 TestLayerDelegateFactory factory;
105 std::unique_ptr<aura::Window> window1(
106 aura::test::CreateTestWindowWithId(0, NULL));
107 std::unique_ptr<aura::Window> window11(
108 aura::test::CreateTestWindowWithId(1, window1.get()));
109 std::unique_ptr<aura::Window> window12(
110 aura::test::CreateTestWindowWithId(2, window1.get()));
111
112 std::unique_ptr<ui::LayerTreeOwner> tree =
113 wm::RecreateLayers(window1.get(), &factory);
114
115 DCHECK_EQ(3u, factory.delegate_count());
sky 2016/05/19 20:06:49 ASSERT_EQ
oshima 2016/05/19 23:32:22 Done.
116
117 TestLayerDelegate* new_delegate_1 = factory.GetDelegateAt(0);
118 TestLayerDelegate* new_delegate_11 = factory.GetDelegateAt(1);
119 TestLayerDelegate* new_delegate_12 = factory.GetDelegateAt(2);
120
121 DCHECK_EQ(window1->layer()->delegate(), new_delegate_1->original_delegate());
sky 2016/05/19 20:06:49 EXPECT_EQ for all of these
oshima 2016/05/19 23:32:21 Done.
122 DCHECK_EQ(window11->layer()->delegate(),
123 new_delegate_11->original_delegate());
124 DCHECK_EQ(window12->layer()->delegate(),
125 new_delegate_12->original_delegate());
126
127 DCHECK_EQ(tree->root()->delegate(), new_delegate_1);
128 DCHECK_EQ(tree->root()->children()[0]->delegate(), new_delegate_11);
129 DCHECK_EQ(tree->root()->children()[1]->delegate(), new_delegate_12);
130 }
131
52 } // namespace wm 132 } // 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