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

Side by Side Diff: components/exo/sub_surface_unittest.cc

Issue 2008153002: Add initial implementation of cc::Surfaces backend for exo. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 6 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 | « components/exo/shell_surface_unittest.cc ('k') | components/exo/surface.h » ('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 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 "components/exo/sub_surface.h" 5 #include "components/exo/sub_surface.h"
6 6
7 #include "base/memory/ptr_util.h" 7 #include "base/memory/ptr_util.h"
8 #include "components/exo/surface.h" 8 #include "components/exo/surface.h"
9 #include "components/exo/test/exo_test_base.h" 9 #include "components/exo/test/exo_test_base.h"
10 #include "components/exo/test/exo_test_helper.h" 10 #include "components/exo/test/exo_test_helper.h"
11 #include "testing/gtest/include/gtest/gtest.h" 11 #include "testing/gtest/include/gtest/gtest.h"
12 12
13 namespace exo { 13 namespace exo {
14 namespace { 14 namespace {
15 15
16 using SubSurfaceTest = test::ExoTestBase; 16 class SubSurfaceTest : public test::ExoTestBase,
17 public ::testing::WithParamInterface<bool> {
18 void SetUp() override {
19 Surface::SetUseSurfaceLayer(GetParam());
20 test::ExoTestBase::SetUp();
21 }
22 };
17 23
18 TEST_F(SubSurfaceTest, SetPosition) { 24 TEST_P(SubSurfaceTest, SetPosition) {
19 std::unique_ptr<Surface> parent(new Surface); 25 std::unique_ptr<Surface> parent(new Surface);
20 std::unique_ptr<Surface> surface(new Surface); 26 std::unique_ptr<Surface> surface(new Surface);
21 std::unique_ptr<SubSurface> sub_surface( 27 std::unique_ptr<SubSurface> sub_surface(
22 new SubSurface(surface.get(), parent.get())); 28 new SubSurface(surface.get(), parent.get()));
23 29
24 // Initial position is at the origin. 30 // Initial position is at the origin.
25 EXPECT_EQ(gfx::Point().ToString(), surface->bounds().origin().ToString()); 31 EXPECT_EQ(gfx::Point().ToString(), surface->bounds().origin().ToString());
26 32
27 // Set position to 10, 10. 33 // Set position to 10, 10.
28 gfx::Point position(10, 10); 34 gfx::Point position(10, 10);
29 sub_surface->SetPosition(position); 35 sub_surface->SetPosition(position);
30 36
31 // A call to Commit() is required for position to take effect. 37 // A call to Commit() is required for position to take effect.
32 EXPECT_EQ(gfx::Point().ToString(), surface->bounds().origin().ToString()); 38 EXPECT_EQ(gfx::Point().ToString(), surface->bounds().origin().ToString());
33 39
34 // Check that position is updated when Commit() is called. 40 // Check that position is updated when Commit() is called.
35 parent->Commit(); 41 parent->Commit();
36 EXPECT_EQ(position.ToString(), surface->bounds().origin().ToString()); 42 EXPECT_EQ(position.ToString(), surface->bounds().origin().ToString());
37 43
38 // Create and commit a new sub-surface using the same surface. 44 // Create and commit a new sub-surface using the same surface.
39 sub_surface.reset(); 45 sub_surface.reset();
40 sub_surface = base::WrapUnique(new SubSurface(surface.get(), parent.get())); 46 sub_surface = base::WrapUnique(new SubSurface(surface.get(), parent.get()));
41 parent->Commit(); 47 parent->Commit();
42 48
43 // Initial position should be reset to origin. 49 // Initial position should be reset to origin.
44 EXPECT_EQ(gfx::Point().ToString(), surface->bounds().origin().ToString()); 50 EXPECT_EQ(gfx::Point().ToString(), surface->bounds().origin().ToString());
45 } 51 }
46 52
47 TEST_F(SubSurfaceTest, PlaceAbove) { 53 TEST_P(SubSurfaceTest, PlaceAbove) {
48 std::unique_ptr<Surface> parent(new Surface); 54 std::unique_ptr<Surface> parent(new Surface);
49 std::unique_ptr<Surface> surface1(new Surface); 55 std::unique_ptr<Surface> surface1(new Surface);
50 std::unique_ptr<Surface> surface2(new Surface); 56 std::unique_ptr<Surface> surface2(new Surface);
51 std::unique_ptr<Surface> non_sibling_surface(new Surface); 57 std::unique_ptr<Surface> non_sibling_surface(new Surface);
52 std::unique_ptr<SubSurface> sub_surface1( 58 std::unique_ptr<SubSurface> sub_surface1(
53 new SubSurface(surface1.get(), parent.get())); 59 new SubSurface(surface1.get(), parent.get()));
54 std::unique_ptr<SubSurface> sub_surface2( 60 std::unique_ptr<SubSurface> sub_surface2(
55 new SubSurface(surface2.get(), parent.get())); 61 new SubSurface(surface2.get(), parent.get()));
56 62
57 ASSERT_EQ(2u, parent->children().size()); 63 ASSERT_EQ(2u, parent->children().size());
(...skipping 10 matching lines...) Expand all
68 EXPECT_EQ(surface1.get(), parent->children()[0]); 74 EXPECT_EQ(surface1.get(), parent->children()[0]);
69 EXPECT_EQ(surface2.get(), parent->children()[1]); 75 EXPECT_EQ(surface2.get(), parent->children()[1]);
70 76
71 parent->Commit(); 77 parent->Commit();
72 78
73 // surface1 should now be stacked above surface2. 79 // surface1 should now be stacked above surface2.
74 EXPECT_EQ(surface2.get(), parent->children()[0]); 80 EXPECT_EQ(surface2.get(), parent->children()[0]);
75 EXPECT_EQ(surface1.get(), parent->children()[1]); 81 EXPECT_EQ(surface1.get(), parent->children()[1]);
76 } 82 }
77 83
78 TEST_F(SubSurfaceTest, PlaceBelow) { 84 TEST_P(SubSurfaceTest, PlaceBelow) {
79 std::unique_ptr<Surface> parent(new Surface); 85 std::unique_ptr<Surface> parent(new Surface);
80 std::unique_ptr<Surface> surface1(new Surface); 86 std::unique_ptr<Surface> surface1(new Surface);
81 std::unique_ptr<Surface> surface2(new Surface); 87 std::unique_ptr<Surface> surface2(new Surface);
82 std::unique_ptr<Surface> non_sibling_surface(new Surface); 88 std::unique_ptr<Surface> non_sibling_surface(new Surface);
83 std::unique_ptr<SubSurface> sub_surface1( 89 std::unique_ptr<SubSurface> sub_surface1(
84 new SubSurface(surface1.get(), parent.get())); 90 new SubSurface(surface1.get(), parent.get()));
85 std::unique_ptr<SubSurface> sub_surface2( 91 std::unique_ptr<SubSurface> sub_surface2(
86 new SubSurface(surface2.get(), parent.get())); 92 new SubSurface(surface2.get(), parent.get()));
87 93
88 ASSERT_EQ(2u, parent->children().size()); 94 ASSERT_EQ(2u, parent->children().size());
(...skipping 10 matching lines...) Expand all
99 EXPECT_EQ(surface1.get(), parent->children()[0]); 105 EXPECT_EQ(surface1.get(), parent->children()[0]);
100 EXPECT_EQ(surface2.get(), parent->children()[1]); 106 EXPECT_EQ(surface2.get(), parent->children()[1]);
101 107
102 parent->Commit(); 108 parent->Commit();
103 109
104 // surface1 should now be stacked above surface2. 110 // surface1 should now be stacked above surface2.
105 EXPECT_EQ(surface2.get(), parent->children()[0]); 111 EXPECT_EQ(surface2.get(), parent->children()[0]);
106 EXPECT_EQ(surface1.get(), parent->children()[1]); 112 EXPECT_EQ(surface1.get(), parent->children()[1]);
107 } 113 }
108 114
109 TEST_F(SubSurfaceTest, SetCommitBehavior) { 115 TEST_P(SubSurfaceTest, SetCommitBehavior) {
110 std::unique_ptr<Surface> parent(new Surface); 116 std::unique_ptr<Surface> parent(new Surface);
111 std::unique_ptr<Surface> child(new Surface); 117 std::unique_ptr<Surface> child(new Surface);
112 std::unique_ptr<Surface> grandchild(new Surface); 118 std::unique_ptr<Surface> grandchild(new Surface);
113 std::unique_ptr<SubSurface> child_sub_surface( 119 std::unique_ptr<SubSurface> child_sub_surface(
114 new SubSurface(child.get(), parent.get())); 120 new SubSurface(child.get(), parent.get()));
115 std::unique_ptr<SubSurface> grandchild_sub_surface( 121 std::unique_ptr<SubSurface> grandchild_sub_surface(
116 new SubSurface(grandchild.get(), child.get())); 122 new SubSurface(grandchild.get(), child.get()));
117 123
118 // Initial position is at the origin. 124 // Initial position is at the origin.
119 EXPECT_EQ(gfx::Point().ToString(), grandchild->bounds().origin().ToString()); 125 EXPECT_EQ(gfx::Point().ToString(), grandchild->bounds().origin().ToString());
(...skipping 21 matching lines...) Expand all
141 // Set position to 20, 20. 147 // Set position to 20, 20.
142 gfx::Point position2(20, 20); 148 gfx::Point position2(20, 20);
143 grandchild_sub_surface->SetPosition(position2); 149 grandchild_sub_surface->SetPosition(position2);
144 child->Commit(); 150 child->Commit();
145 151
146 // A Commit() call on child should be sufficient for the position of 152 // A Commit() call on child should be sufficient for the position of
147 // grandchild to take effect when synchronous is disabled. 153 // grandchild to take effect when synchronous is disabled.
148 EXPECT_EQ(position2.ToString(), grandchild->bounds().origin().ToString()); 154 EXPECT_EQ(position2.ToString(), grandchild->bounds().origin().ToString());
149 } 155 }
150 156
157 INSTANTIATE_TEST_CASE_P(, SubSurfaceTest, ::testing::Bool());
158
151 } // namespace 159 } // namespace
152 } // namespace exo 160 } // namespace exo
OLDNEW
« no previous file with comments | « components/exo/shell_surface_unittest.cc ('k') | components/exo/surface.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698