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

Unified Diff: cc/layers/layer_list_iterator_unittest.cc

Issue 1887703002: cc: Add a main thread LayerListIterator (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: For testing only Created 4 years, 8 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « cc/layers/layer_list_iterator.cc ('k') | cc/trees/layer_tree_host.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: cc/layers/layer_list_iterator_unittest.cc
diff --git a/cc/layers/layer_list_iterator_unittest.cc b/cc/layers/layer_list_iterator_unittest.cc
index d0985096cb822d24e6b552c6234c8346d2ee7dbb..503c1e6d94a9dca3464a97413961ad44fb4c33f6 100644
--- a/cc/layers/layer_list_iterator_unittest.cc
+++ b/cc/layers/layer_list_iterator_unittest.cc
@@ -8,6 +8,7 @@
#include "base/containers/adapters.h"
#include "cc/test/fake_impl_task_runner_provider.h"
+#include "cc/test/fake_layer_tree_host.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"
@@ -18,8 +19,184 @@
namespace cc {
namespace {
+// Layer version unit tests
+
TEST(LayerListIteratorTest, VerifyTraversalOrder) {
// Unfortunate preamble.
+ FakeLayerTreeHostClient client(FakeLayerTreeHostClient::DIRECT_3D);
+ TestTaskGraphRunner task_graph_runner;
+ std::unique_ptr<FakeLayerTreeHost> host_ptr =
+ FakeLayerTreeHost::Create(&client, &task_graph_runner);
+ FakeLayerTreeHost* host = host_ptr.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_refptr<Layer> layer1 = Layer::Create();
+ scoped_refptr<Layer> layer2 = Layer::Create();
+ scoped_refptr<Layer> layer3 = Layer::Create();
+ scoped_refptr<Layer> layer4 = Layer::Create();
+ scoped_refptr<Layer> layer5 = Layer::Create();
+ scoped_refptr<Layer> layer6 = Layer::Create();
+ scoped_refptr<Layer> layer7 = Layer::Create();
+
+ std::unordered_map<int, int> layer_id_to_order;
+ layer_id_to_order[layer1->id()] = 1;
+ layer_id_to_order[layer2->id()] = 2;
+ layer_id_to_order[layer3->id()] = 3;
+ layer_id_to_order[layer4->id()] = 4;
+ layer_id_to_order[layer5->id()] = 5;
+ layer_id_to_order[layer6->id()] = 6;
+ layer_id_to_order[layer7->id()] = 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->SetRootLayer(std::move(layer1));
+
+ int i = 1;
+ for (auto* layer : *host) {
+ EXPECT_EQ(i++, layer_id_to_order[layer->id()]);
+ }
+ EXPECT_EQ(8, i);
+}
+
+TEST(LayerListIteratorTest, VerifySingleLayer) {
+ // Unfortunate preamble.
+ FakeLayerTreeHostClient client(FakeLayerTreeHostClient::DIRECT_3D);
+ TestTaskGraphRunner task_graph_runner;
+ std::unique_ptr<FakeLayerTreeHost> host_ptr =
+ FakeLayerTreeHost::Create(&client, &task_graph_runner);
+ FakeLayerTreeHost* host = host_ptr.get();
+
+ // This test constructs a tree consisting of a single layer.
+ scoped_refptr<Layer> layer1 = Layer::Create();
+ std::unordered_map<int, int> layer_id_to_order;
+ layer_id_to_order[layer1->id()] = 1;
+ host->SetRootLayer(std::move(layer1));
+
+ int i = 1;
+ for (auto* layer : *host) {
+ EXPECT_EQ(i++, layer_id_to_order[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<Layer> it(nullptr);
+ LayerListIterator<Layer> end(nullptr);
+
+ EXPECT_EQ(it, end);
+ ++it;
+ EXPECT_EQ(it, end);
+}
+
+TEST(LayerListReverseIteratorTest, VerifyTraversalOrder) {
+ // Unfortunate preamble.
+ FakeLayerTreeHostClient client(FakeLayerTreeHostClient::DIRECT_3D);
+ TestTaskGraphRunner task_graph_runner;
+ std::unique_ptr<FakeLayerTreeHost> host_ptr =
+ FakeLayerTreeHost::Create(&client, &task_graph_runner);
+ FakeLayerTreeHost* host = host_ptr.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_refptr<Layer> layer1 = Layer::Create();
+ scoped_refptr<Layer> layer2 = Layer::Create();
+ scoped_refptr<Layer> layer3 = Layer::Create();
+ scoped_refptr<Layer> layer4 = Layer::Create();
+ scoped_refptr<Layer> layer5 = Layer::Create();
+ scoped_refptr<Layer> layer6 = Layer::Create();
+ scoped_refptr<Layer> layer7 = Layer::Create();
+
+ std::unordered_map<int, int> layer_id_to_order;
+ layer_id_to_order[layer1->id()] = 1;
+ layer_id_to_order[layer2->id()] = 2;
+ layer_id_to_order[layer3->id()] = 3;
+ layer_id_to_order[layer4->id()] = 4;
+ layer_id_to_order[layer5->id()] = 5;
+ layer_id_to_order[layer6->id()] = 6;
+ layer_id_to_order[layer7->id()] = 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->SetRootLayer(std::move(layer1));
+
+ int i = 7;
+
+ for (auto* layer : base::Reversed(*host)) {
+ EXPECT_EQ(i--, layer_id_to_order[layer->id()]);
+ }
+
+ EXPECT_EQ(0, i);
+}
+
+TEST(LayerListReverseIteratorTest, VerifySingleLayer) {
+ // Unfortunate preamble.
+ FakeLayerTreeHostClient client(FakeLayerTreeHostClient::DIRECT_3D);
+ TestTaskGraphRunner task_graph_runner;
+ std::unique_ptr<FakeLayerTreeHost> host_ptr =
+ FakeLayerTreeHost::Create(&client, &task_graph_runner);
+ FakeLayerTreeHost* host = host_ptr.get();
+
+ // This test constructs a tree consisting of a single layer.
+ scoped_refptr<Layer> layer1 = Layer::Create();
+ std::unordered_map<int, int> layer_id_to_order;
+ layer_id_to_order[layer1->id()] = 1;
+ host->SetRootLayer(std::move(layer1));
+
+ int i = 1;
+ for (auto* layer : base::Reversed(*host)) {
+ EXPECT_EQ(i--, layer_id_to_order[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<Layer> it(nullptr);
+ LayerListReverseIterator<Layer> end(nullptr);
+
+ EXPECT_EQ(it, end);
+ ++it;
+ EXPECT_EQ(it, end);
+}
+
+// LayerImpl version unit tests
+
+TEST(LayerListIteratorTest, VerifyTraversalOrderImpl) {
+ // Unfortunate preamble.
FakeImplTaskRunnerProvider task_runner_provider;
TestSharedBitmapManager shared_bitmap_manager;
TestTaskGraphRunner task_graph_runner;
@@ -71,7 +248,7 @@ TEST(LayerListIteratorTest, VerifyTraversalOrder) {
EXPECT_EQ(8, i);
}
-TEST(LayerListIteratorTest, VerifySingleLayer) {
+TEST(LayerListIteratorTest, VerifySingleLayerImpl) {
// Unfortunate preamble.
FakeImplTaskRunnerProvider task_runner_provider;
TestSharedBitmapManager shared_bitmap_manager;
@@ -94,19 +271,19 @@ TEST(LayerListIteratorTest, VerifySingleLayer) {
EXPECT_EQ(2, i);
}
-TEST(LayerListIteratorTest, VerifyNullFirstLayer) {
+TEST(LayerListIteratorTest, VerifyNullFirstLayerImpl) {
// 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);
+ LayerListIterator<LayerImpl> it(nullptr);
+ LayerListIterator<LayerImpl> end(nullptr);
EXPECT_EQ(it, end);
++it;
EXPECT_EQ(it, end);
}
-TEST(LayerListReverseIteratorTest, VerifyTraversalOrder) {
+TEST(LayerListReverseIteratorTest, VerifyTraversalOrderImpl) {
// Unfortunate preamble.
FakeImplTaskRunnerProvider task_runner_provider;
TestSharedBitmapManager shared_bitmap_manager;
@@ -161,7 +338,7 @@ TEST(LayerListReverseIteratorTest, VerifyTraversalOrder) {
EXPECT_EQ(0, i);
}
-TEST(LayerListReverseIteratorTest, VerifySingleLayer) {
+TEST(LayerListReverseIteratorTest, VerifySingleLayerImpl) {
// Unfortunate preamble.
FakeImplTaskRunnerProvider task_runner_provider;
TestSharedBitmapManager shared_bitmap_manager;
@@ -184,12 +361,12 @@ TEST(LayerListReverseIteratorTest, VerifySingleLayer) {
EXPECT_EQ(0, i);
}
-TEST(LayerListReverseIteratorTest, VerifyNullFirstLayer) {
+TEST(LayerListReverseIteratorTest, VerifyNullFirstLayerImpl) {
// 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);
+ LayerListReverseIterator<LayerImpl> it(nullptr);
+ LayerListReverseIterator<LayerImpl> end(nullptr);
EXPECT_EQ(it, end);
++it;
« no previous file with comments | « cc/layers/layer_list_iterator.cc ('k') | cc/trees/layer_tree_host.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698