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

Side by Side Diff: cc/layers/layer_list_iterator_unittest.cc

Issue 2661523003: cc: Merge LayerTree into the LayerTreeHost. (Closed)
Patch Set: auto Created 3 years, 10 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 | « cc/layers/layer.cc ('k') | cc/layers/layer_position_constraint_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 "cc/layers/layer_list_iterator.h" 5 #include "cc/layers/layer_list_iterator.h"
6 6
7 #include <memory> 7 #include <memory>
8 8
9 #include "base/containers/adapters.h" 9 #include "base/containers/adapters.h"
10 #include "cc/animation/animation_host.h" 10 #include "cc/animation/animation_host.h"
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
61 61
62 layer5->AddChild(std::move(layer6)); 62 layer5->AddChild(std::move(layer6));
63 layer5->AddChild(std::move(layer7)); 63 layer5->AddChild(std::move(layer7));
64 64
65 layer1->AddChild(std::move(layer2)); 65 layer1->AddChild(std::move(layer2));
66 layer1->AddChild(std::move(layer5)); 66 layer1->AddChild(std::move(layer5));
67 67
68 host->SetRootLayer(std::move(layer1)); 68 host->SetRootLayer(std::move(layer1));
69 69
70 int i = 1; 70 int i = 1;
71 for (auto* layer : *host->GetLayerTree()) { 71 for (auto* layer : *host) {
72 EXPECT_EQ(i++, layer_id_to_order[layer->id()]); 72 EXPECT_EQ(i++, layer_id_to_order[layer->id()]);
73 } 73 }
74 EXPECT_EQ(8, i); 74 EXPECT_EQ(8, i);
75 } 75 }
76 76
77 TEST(LayerListIteratorTest, VerifySingleLayer) { 77 TEST(LayerListIteratorTest, VerifySingleLayer) {
78 // Unfortunate preamble. 78 // Unfortunate preamble.
79 FakeLayerTreeHostClient client; 79 FakeLayerTreeHostClient client;
80 TestTaskGraphRunner task_graph_runner; 80 TestTaskGraphRunner task_graph_runner;
81 auto animation_host = AnimationHost::CreateForTesting(ThreadInstance::MAIN); 81 auto animation_host = AnimationHost::CreateForTesting(ThreadInstance::MAIN);
82 std::unique_ptr<FakeLayerTreeHost> host_ptr = FakeLayerTreeHost::Create( 82 std::unique_ptr<FakeLayerTreeHost> host_ptr = FakeLayerTreeHost::Create(
83 &client, &task_graph_runner, animation_host.get()); 83 &client, &task_graph_runner, animation_host.get());
84 FakeLayerTreeHost* host = host_ptr.get(); 84 FakeLayerTreeHost* host = host_ptr.get();
85 85
86 // This test constructs a tree consisting of a single layer. 86 // This test constructs a tree consisting of a single layer.
87 scoped_refptr<Layer> layer1 = Layer::Create(); 87 scoped_refptr<Layer> layer1 = Layer::Create();
88 std::unordered_map<int, int> layer_id_to_order; 88 std::unordered_map<int, int> layer_id_to_order;
89 layer_id_to_order[layer1->id()] = 1; 89 layer_id_to_order[layer1->id()] = 1;
90 host->SetRootLayer(std::move(layer1)); 90 host->SetRootLayer(std::move(layer1));
91 91
92 int i = 1; 92 int i = 1;
93 for (auto* layer : *host->GetLayerTree()) { 93 for (auto* layer : *host) {
94 EXPECT_EQ(i++, layer_id_to_order[layer->id()]); 94 EXPECT_EQ(i++, layer_id_to_order[layer->id()]);
95 } 95 }
96 EXPECT_EQ(2, i); 96 EXPECT_EQ(2, i);
97 } 97 }
98 98
99 TEST(LayerListIteratorTest, VerifyNullFirstLayer) { 99 TEST(LayerListIteratorTest, VerifyNullFirstLayer) {
100 // Ensures that if an iterator is constructed with a nullptr, that it can be 100 // Ensures that if an iterator is constructed with a nullptr, that it can be
101 // iterated without issue and that it remains equal to any other 101 // iterated without issue and that it remains equal to any other
102 // null-initialized iterator. 102 // null-initialized iterator.
103 LayerListIterator<Layer> it(nullptr); 103 LayerListIterator<Layer> it(nullptr);
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
149 layer5->AddChild(std::move(layer6)); 149 layer5->AddChild(std::move(layer6));
150 layer5->AddChild(std::move(layer7)); 150 layer5->AddChild(std::move(layer7));
151 151
152 layer1->AddChild(std::move(layer2)); 152 layer1->AddChild(std::move(layer2));
153 layer1->AddChild(std::move(layer5)); 153 layer1->AddChild(std::move(layer5));
154 154
155 host->SetRootLayer(std::move(layer1)); 155 host->SetRootLayer(std::move(layer1));
156 156
157 int i = 7; 157 int i = 7;
158 158
159 for (auto* layer : base::Reversed(*host->GetLayerTree())) { 159 for (auto* layer : base::Reversed(*host)) {
160 EXPECT_EQ(i--, layer_id_to_order[layer->id()]); 160 EXPECT_EQ(i--, layer_id_to_order[layer->id()]);
161 } 161 }
162 162
163 EXPECT_EQ(0, i); 163 EXPECT_EQ(0, i);
164 } 164 }
165 165
166 TEST(LayerListReverseIteratorTest, VerifySingleLayer) { 166 TEST(LayerListReverseIteratorTest, VerifySingleLayer) {
167 // Unfortunate preamble. 167 // Unfortunate preamble.
168 FakeLayerTreeHostClient client; 168 FakeLayerTreeHostClient client;
169 TestTaskGraphRunner task_graph_runner; 169 TestTaskGraphRunner task_graph_runner;
170 auto animation_host = AnimationHost::CreateForTesting(ThreadInstance::MAIN); 170 auto animation_host = AnimationHost::CreateForTesting(ThreadInstance::MAIN);
171 std::unique_ptr<FakeLayerTreeHost> host_ptr = FakeLayerTreeHost::Create( 171 std::unique_ptr<FakeLayerTreeHost> host_ptr = FakeLayerTreeHost::Create(
172 &client, &task_graph_runner, animation_host.get()); 172 &client, &task_graph_runner, animation_host.get());
173 FakeLayerTreeHost* host = host_ptr.get(); 173 FakeLayerTreeHost* host = host_ptr.get();
174 174
175 // This test constructs a tree consisting of a single layer. 175 // This test constructs a tree consisting of a single layer.
176 scoped_refptr<Layer> layer1 = Layer::Create(); 176 scoped_refptr<Layer> layer1 = Layer::Create();
177 std::unordered_map<int, int> layer_id_to_order; 177 std::unordered_map<int, int> layer_id_to_order;
178 layer_id_to_order[layer1->id()] = 1; 178 layer_id_to_order[layer1->id()] = 1;
179 host->SetRootLayer(std::move(layer1)); 179 host->SetRootLayer(std::move(layer1));
180 180
181 int i = 1; 181 int i = 1;
182 for (auto* layer : base::Reversed(*host->GetLayerTree())) { 182 for (auto* layer : base::Reversed(*host)) {
183 EXPECT_EQ(i--, layer_id_to_order[layer->id()]); 183 EXPECT_EQ(i--, layer_id_to_order[layer->id()]);
184 } 184 }
185 EXPECT_EQ(0, i); 185 EXPECT_EQ(0, i);
186 } 186 }
187 187
188 TEST(LayerListReverseIteratorTest, VerifyNullFirstLayer) { 188 TEST(LayerListReverseIteratorTest, VerifyNullFirstLayer) {
189 // Ensures that if an iterator is constructed with a nullptr, that it can be 189 // Ensures that if an iterator is constructed with a nullptr, that it can be
190 // iterated without issue and that it remains equal to any other 190 // iterated without issue and that it remains equal to any other
191 // null-initialized iterator. 191 // null-initialized iterator.
192 LayerListReverseIterator<Layer> it(nullptr); 192 LayerListReverseIterator<Layer> it(nullptr);
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after
372 LayerListReverseIterator<LayerImpl> it(nullptr); 372 LayerListReverseIterator<LayerImpl> it(nullptr);
373 LayerListReverseIterator<LayerImpl> end(nullptr); 373 LayerListReverseIterator<LayerImpl> end(nullptr);
374 374
375 EXPECT_EQ(it, end); 375 EXPECT_EQ(it, end);
376 ++it; 376 ++it;
377 EXPECT_EQ(it, end); 377 EXPECT_EQ(it, end);
378 } 378 }
379 379
380 } // namespace 380 } // namespace
381 } // namespace cc 381 } // namespace cc
OLDNEW
« no previous file with comments | « cc/layers/layer.cc ('k') | cc/layers/layer_position_constraint_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698