forked from chromium/chromium
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlayer_list_iterator_unittest.cc
183 lines (153 loc) · 6.36 KB
/
layer_list_iterator_unittest.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
// Copyright 2016 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "cc/layers/layer_list_iterator.h"
#include "base/containers/adapters.h"
#include "base/memory/scoped_ptr.h"
#include "cc/test/fake_impl_task_runner_provider.h"
#include "cc/test/fake_layer_tree_host_impl.h"
#include "cc/test/fake_output_surface.h"
#include "cc/test/test_shared_bitmap_manager.h"
#include "cc/test/test_task_graph_runner.h"
#include "cc/trees/layer_tree_impl.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace cc {
namespace {
TEST(LayerListIteratorTest, VerifyTraversalOrder) {
// Unfortunate preamble.
FakeImplTaskRunnerProvider task_runner_provider;
TestSharedBitmapManager shared_bitmap_manager;
TestTaskGraphRunner task_graph_runner;
scoped_ptr<OutputSurface> output_surface = FakeOutputSurface::Create3d();
FakeLayerTreeHostImpl host_impl(&task_runner_provider, &shared_bitmap_manager,
&task_graph_runner);
host_impl.SetVisible(true);
EXPECT_TRUE(host_impl.InitializeRenderer(output_surface.get()));
// This test constructs the following tree.
// 1
// +-2
// | +-3
// | +-4
// + 5
// +-6
// +-7
// We expect to visit all seven layers in that order.
scoped_ptr<LayerImpl> layer1 = LayerImpl::Create(host_impl.active_tree(), 1);
scoped_ptr<LayerImpl> layer2 = LayerImpl::Create(host_impl.active_tree(), 2);
scoped_ptr<LayerImpl> layer3 = LayerImpl::Create(host_impl.active_tree(), 3);
scoped_ptr<LayerImpl> layer4 = LayerImpl::Create(host_impl.active_tree(), 4);
scoped_ptr<LayerImpl> layer5 = LayerImpl::Create(host_impl.active_tree(), 5);
scoped_ptr<LayerImpl> layer6 = LayerImpl::Create(host_impl.active_tree(), 6);
scoped_ptr<LayerImpl> layer7 = LayerImpl::Create(host_impl.active_tree(), 7);
layer2->AddChild(std::move(layer3));
layer2->AddChild(std::move(layer4));
layer5->AddChild(std::move(layer6));
layer5->AddChild(std::move(layer7));
layer1->AddChild(std::move(layer2));
layer1->AddChild(std::move(layer5));
host_impl.active_tree()->SetRootLayer(std::move(layer1));
int i = 1;
for (auto* layer : *host_impl.active_tree()) {
EXPECT_EQ(i++, layer->id());
}
EXPECT_EQ(8, i);
}
TEST(LayerListIteratorTest, VerifySingleLayer) {
// Unfortunate preamble.
FakeImplTaskRunnerProvider task_runner_provider;
TestSharedBitmapManager shared_bitmap_manager;
TestTaskGraphRunner task_graph_runner;
scoped_ptr<OutputSurface> output_surface = FakeOutputSurface::Create3d();
FakeLayerTreeHostImpl host_impl(&task_runner_provider, &shared_bitmap_manager,
&task_graph_runner);
host_impl.SetVisible(true);
EXPECT_TRUE(host_impl.InitializeRenderer(output_surface.get()));
// This test constructs a tree consisting of a single layer.
scoped_ptr<LayerImpl> layer1 = LayerImpl::Create(host_impl.active_tree(), 1);
host_impl.active_tree()->SetRootLayer(std::move(layer1));
int i = 1;
for (auto* layer : *host_impl.active_tree()) {
EXPECT_EQ(i++, layer->id());
}
EXPECT_EQ(2, i);
}
TEST(LayerListIteratorTest, VerifyNullFirstLayer) {
// Ensures that if an iterator is constructed with a nullptr, that it can be
// iterated without issue and that it remains equal to any other
// null-initialized iterator.
LayerListIterator it(nullptr);
LayerListIterator end(nullptr);
EXPECT_EQ(it, end);
++it;
EXPECT_EQ(it, end);
}
TEST(LayerListReverseIteratorTest, VerifyTraversalOrder) {
// Unfortunate preamble.
FakeImplTaskRunnerProvider task_runner_provider;
TestSharedBitmapManager shared_bitmap_manager;
TestTaskGraphRunner task_graph_runner;
scoped_ptr<OutputSurface> output_surface = FakeOutputSurface::Create3d();
FakeLayerTreeHostImpl host_impl(&task_runner_provider, &shared_bitmap_manager,
&task_graph_runner);
host_impl.SetVisible(true);
EXPECT_TRUE(host_impl.InitializeRenderer(output_surface.get()));
// This test constructs the following tree.
// 1
// +-2
// | +-3
// | +-4
// + 5
// +-6
// +-7
// We expect to visit all seven layers in reverse order.
scoped_ptr<LayerImpl> layer1 = LayerImpl::Create(host_impl.active_tree(), 1);
scoped_ptr<LayerImpl> layer2 = LayerImpl::Create(host_impl.active_tree(), 2);
scoped_ptr<LayerImpl> layer3 = LayerImpl::Create(host_impl.active_tree(), 3);
scoped_ptr<LayerImpl> layer4 = LayerImpl::Create(host_impl.active_tree(), 4);
scoped_ptr<LayerImpl> layer5 = LayerImpl::Create(host_impl.active_tree(), 5);
scoped_ptr<LayerImpl> layer6 = LayerImpl::Create(host_impl.active_tree(), 6);
scoped_ptr<LayerImpl> layer7 = LayerImpl::Create(host_impl.active_tree(), 7);
layer2->AddChild(std::move(layer3));
layer2->AddChild(std::move(layer4));
layer5->AddChild(std::move(layer6));
layer5->AddChild(std::move(layer7));
layer1->AddChild(std::move(layer2));
layer1->AddChild(std::move(layer5));
host_impl.active_tree()->SetRootLayer(std::move(layer1));
int i = 7;
for (auto* layer : base::Reversed(*host_impl.active_tree())) {
EXPECT_EQ(i--, layer->id());
}
EXPECT_EQ(0, i);
}
TEST(LayerListReverseIteratorTest, VerifySingleLayer) {
// Unfortunate preamble.
FakeImplTaskRunnerProvider task_runner_provider;
TestSharedBitmapManager shared_bitmap_manager;
TestTaskGraphRunner task_graph_runner;
scoped_ptr<OutputSurface> output_surface = FakeOutputSurface::Create3d();
FakeLayerTreeHostImpl host_impl(&task_runner_provider, &shared_bitmap_manager,
&task_graph_runner);
host_impl.SetVisible(true);
EXPECT_TRUE(host_impl.InitializeRenderer(output_surface.get()));
// This test constructs a tree consisting of a single layer.
scoped_ptr<LayerImpl> layer1 = LayerImpl::Create(host_impl.active_tree(), 1);
host_impl.active_tree()->SetRootLayer(std::move(layer1));
int i = 1;
for (auto* layer : base::Reversed(*host_impl.active_tree())) {
EXPECT_EQ(i--, layer->id());
}
EXPECT_EQ(0, i);
}
TEST(LayerListReverseIteratorTest, VerifyNullFirstLayer) {
// Ensures that if an iterator is constructed with a nullptr, that it can be
// iterated without issue and that it remains equal to any other
// null-initialized iterator.
LayerListReverseIterator it(nullptr);
LayerListReverseIterator end(nullptr);
EXPECT_EQ(it, end);
++it;
EXPECT_EQ(it, end);
}
} // namespace
} // namespace cc