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

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

Issue 1752263003: Add LayerTreeImpl end/begin/rend/rbegin (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 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 | « no previous file | cc/trees/layer_tree_impl.h » ('j') | cc/trees/layer_tree_impl.h » ('J')
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 "base/containers/adapters.h"
7 #include "base/memory/scoped_ptr.h" 8 #include "base/memory/scoped_ptr.h"
8 #include "cc/test/fake_impl_task_runner_provider.h" 9 #include "cc/test/fake_impl_task_runner_provider.h"
9 #include "cc/test/fake_layer_tree_host_impl.h" 10 #include "cc/test/fake_layer_tree_host_impl.h"
10 #include "cc/test/fake_output_surface.h" 11 #include "cc/test/fake_output_surface.h"
11 #include "cc/test/test_shared_bitmap_manager.h" 12 #include "cc/test/test_shared_bitmap_manager.h"
12 #include "cc/test/test_task_graph_runner.h" 13 #include "cc/test/test_task_graph_runner.h"
14 #include "cc/trees/layer_tree_impl.h"
13 #include "testing/gtest/include/gtest/gtest.h" 15 #include "testing/gtest/include/gtest/gtest.h"
14 16
15 namespace cc { 17 namespace cc {
16 namespace { 18 namespace {
17 19
18 TEST(LayerListIteratorTest, VerifyTraversalOrder) { 20 TEST(LayerListIteratorTest, VerifyTraversalOrder) {
19 // Unfortunate preamble. 21 // Unfortunate preamble.
20 FakeImplTaskRunnerProvider task_runner_provider; 22 FakeImplTaskRunnerProvider task_runner_provider;
21 TestSharedBitmapManager shared_bitmap_manager; 23 TestSharedBitmapManager shared_bitmap_manager;
22 TestTaskGraphRunner task_graph_runner; 24 TestTaskGraphRunner task_graph_runner;
(...skipping 22 matching lines...) Expand all
45 47
46 layer2->AddChild(std::move(layer3)); 48 layer2->AddChild(std::move(layer3));
47 layer2->AddChild(std::move(layer4)); 49 layer2->AddChild(std::move(layer4));
48 50
49 layer5->AddChild(std::move(layer6)); 51 layer5->AddChild(std::move(layer6));
50 layer5->AddChild(std::move(layer7)); 52 layer5->AddChild(std::move(layer7));
51 53
52 layer1->AddChild(std::move(layer2)); 54 layer1->AddChild(std::move(layer2));
53 layer1->AddChild(std::move(layer5)); 55 layer1->AddChild(std::move(layer5));
54 56
57 host_impl.active_tree()->SetRootLayer(std::move(layer1));
58
55 int i = 1; 59 int i = 1;
56 LayerListIterator it(layer1.get()); 60 for (auto it : *host_impl.active_tree()) {
danakj 2016/03/03 00:35:50 do you mean auto layer? when doing a for loop the
danakj 2016/03/03 00:36:08 Also if it's a pointer, use auto*
Ian Vollick 2016/03/03 04:41:31 Done.
Ian Vollick 2016/03/03 04:41:31 Done.
57 LayerListIterator end(nullptr); 61 EXPECT_EQ(i++, it->id());
58 for (; it != end; ++it, ++i) {
59 EXPECT_EQ(i, it->id());
60 } 62 }
61 EXPECT_EQ(8, i); 63 EXPECT_EQ(8, i);
62 } 64 }
63 65
64 TEST(LayerListIteratorTest, VerifySingleLayer) { 66 TEST(LayerListIteratorTest, VerifySingleLayer) {
65 // Unfortunate preamble. 67 // Unfortunate preamble.
66 FakeImplTaskRunnerProvider task_runner_provider; 68 FakeImplTaskRunnerProvider task_runner_provider;
67 TestSharedBitmapManager shared_bitmap_manager; 69 TestSharedBitmapManager shared_bitmap_manager;
68 TestTaskGraphRunner task_graph_runner; 70 TestTaskGraphRunner task_graph_runner;
69 scoped_ptr<OutputSurface> output_surface = FakeOutputSurface::Create3d(); 71 scoped_ptr<OutputSurface> output_surface = FakeOutputSurface::Create3d();
70 FakeLayerTreeHostImpl host_impl(&task_runner_provider, &shared_bitmap_manager, 72 FakeLayerTreeHostImpl host_impl(&task_runner_provider, &shared_bitmap_manager,
71 &task_graph_runner); 73 &task_graph_runner);
72 host_impl.SetVisible(true); 74 host_impl.SetVisible(true);
73 EXPECT_TRUE(host_impl.InitializeRenderer(output_surface.get())); 75 EXPECT_TRUE(host_impl.InitializeRenderer(output_surface.get()));
74 76
75 // This test constructs a tree consisting of a single layer. 77 // This test constructs a tree consisting of a single layer.
76 scoped_ptr<LayerImpl> layer1 = LayerImpl::Create(host_impl.active_tree(), 1); 78 scoped_ptr<LayerImpl> layer1 = LayerImpl::Create(host_impl.active_tree(), 1);
79 host_impl.active_tree()->SetRootLayer(std::move(layer1));
80
77 int i = 1; 81 int i = 1;
78 LayerListIterator it(layer1.get()); 82 for (auto it : *host_impl.active_tree()) {
danakj 2016/03/03 00:35:50 dittos
Ian Vollick 2016/03/03 04:41:31 Done.
79 LayerListIterator end(nullptr); 83 EXPECT_EQ(i++, it->id());
80 for (; it != end; ++it, ++i) {
81 EXPECT_EQ(i, it->id());
82 } 84 }
83 EXPECT_EQ(2, i); 85 EXPECT_EQ(2, i);
84 } 86 }
85 87
86 TEST(LayerListIteratorTest, VerifyNullFirstLayer) { 88 TEST(LayerListIteratorTest, VerifyNullFirstLayer) {
87 // Ensures that if an iterator is constructed with a nullptr, that it can be 89 // Ensures that if an iterator is constructed with a nullptr, that it can be
88 // iterated without issue and that it remains equal to any other 90 // iterated without issue and that it remains equal to any other
89 // null-initialized iterator. 91 // null-initialized iterator.
90 LayerListIterator it(nullptr); 92 LayerListIterator it(nullptr);
91 LayerListIterator end(nullptr); 93 LayerListIterator end(nullptr);
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
125 127
126 layer2->AddChild(std::move(layer3)); 128 layer2->AddChild(std::move(layer3));
127 layer2->AddChild(std::move(layer4)); 129 layer2->AddChild(std::move(layer4));
128 130
129 layer5->AddChild(std::move(layer6)); 131 layer5->AddChild(std::move(layer6));
130 layer5->AddChild(std::move(layer7)); 132 layer5->AddChild(std::move(layer7));
131 133
132 layer1->AddChild(std::move(layer2)); 134 layer1->AddChild(std::move(layer2));
133 layer1->AddChild(std::move(layer5)); 135 layer1->AddChild(std::move(layer5));
134 136
137 host_impl.active_tree()->SetRootLayer(std::move(layer1));
138
135 int i = 7; 139 int i = 7;
136 LayerListReverseIterator it(layer1.get()); 140
137 LayerListReverseIterator end(nullptr); 141 for (auto it : base::Reversed(*host_impl.active_tree())) {
danakj 2016/03/03 00:35:50 ditto
Ian Vollick 2016/03/03 04:41:31 Done.
138 for (; it != end; ++it, --i) { 142 EXPECT_EQ(i--, it->id());
139 EXPECT_EQ(i, it->id());
140 } 143 }
144
141 EXPECT_EQ(0, i); 145 EXPECT_EQ(0, i);
142 } 146 }
143 147
144 TEST(LayerListReverseIteratorTest, VerifySingleLayer) { 148 TEST(LayerListReverseIteratorTest, VerifySingleLayer) {
145 // Unfortunate preamble. 149 // Unfortunate preamble.
146 FakeImplTaskRunnerProvider task_runner_provider; 150 FakeImplTaskRunnerProvider task_runner_provider;
147 TestSharedBitmapManager shared_bitmap_manager; 151 TestSharedBitmapManager shared_bitmap_manager;
148 TestTaskGraphRunner task_graph_runner; 152 TestTaskGraphRunner task_graph_runner;
149 scoped_ptr<OutputSurface> output_surface = FakeOutputSurface::Create3d(); 153 scoped_ptr<OutputSurface> output_surface = FakeOutputSurface::Create3d();
150 FakeLayerTreeHostImpl host_impl(&task_runner_provider, &shared_bitmap_manager, 154 FakeLayerTreeHostImpl host_impl(&task_runner_provider, &shared_bitmap_manager,
151 &task_graph_runner); 155 &task_graph_runner);
152 host_impl.SetVisible(true); 156 host_impl.SetVisible(true);
153 EXPECT_TRUE(host_impl.InitializeRenderer(output_surface.get())); 157 EXPECT_TRUE(host_impl.InitializeRenderer(output_surface.get()));
154 158
155 // This test constructs a tree consisting of a single layer. 159 // This test constructs a tree consisting of a single layer.
156 scoped_ptr<LayerImpl> layer1 = LayerImpl::Create(host_impl.active_tree(), 1); 160 scoped_ptr<LayerImpl> layer1 = LayerImpl::Create(host_impl.active_tree(), 1);
161 host_impl.active_tree()->SetRootLayer(std::move(layer1));
162
157 int i = 1; 163 int i = 1;
158 LayerListReverseIterator it(layer1.get()); 164 for (auto it : base::Reversed(*host_impl.active_tree())) {
danakj 2016/03/03 00:35:50 ditto
Ian Vollick 2016/03/03 04:41:31 Done.
159 LayerListReverseIterator end(nullptr); 165 EXPECT_EQ(i--, it->id());
160 for (; it != end; ++it, --i) {
161 EXPECT_EQ(i, it->id());
162 } 166 }
163 EXPECT_EQ(0, i); 167 EXPECT_EQ(0, i);
164 } 168 }
165 169
166 TEST(LayerListReverseIteratorTest, VerifyNullFirstLayer) { 170 TEST(LayerListReverseIteratorTest, VerifyNullFirstLayer) {
167 // Ensures that if an iterator is constructed with a nullptr, that it can be 171 // Ensures that if an iterator is constructed with a nullptr, that it can be
168 // iterated without issue and that it remains equal to any other 172 // iterated without issue and that it remains equal to any other
169 // null-initialized iterator. 173 // null-initialized iterator.
170 LayerListReverseIterator it(nullptr); 174 LayerListReverseIterator it(nullptr);
171 LayerListReverseIterator end(nullptr); 175 LayerListReverseIterator end(nullptr);
172 176
173 EXPECT_EQ(it, end); 177 EXPECT_EQ(it, end);
174 ++it; 178 ++it;
175 EXPECT_EQ(it, end); 179 EXPECT_EQ(it, end);
176 } 180 }
177 181
178 } // namespace 182 } // namespace
179 } // namespace cc 183 } // namespace cc
OLDNEW
« no previous file with comments | « no previous file | cc/trees/layer_tree_impl.h » ('j') | cc/trees/layer_tree_impl.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698