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

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

Issue 1419373013: exo: Add support for subcompositor interface. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@exosphere-xdg-shell
Patch Set: address review feedback Created 5 years, 1 month 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/sub_surface.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
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "components/exo/sub_surface.h"
6 #include "components/exo/surface.h"
7 #include "components/exo/test/exo_test_base.h"
8 #include "components/exo/test/exo_test_helper.h"
9 #include "testing/gtest/include/gtest/gtest.h"
10
11 namespace exo {
12 namespace {
13
14 using SubSurfaceTest = test::ExoTestBase;
15
16 TEST_F(SubSurfaceTest, SetPosition) {
17 scoped_ptr<Surface> parent(new Surface);
18 scoped_ptr<Surface> surface(new Surface);
19 scoped_ptr<SubSurface> sub_surface(
20 new SubSurface(surface.get(), parent.get()));
21
22 // Initial position is at the origin.
23 EXPECT_EQ(gfx::Point().ToString(), surface->bounds().origin().ToString());
24
25 // Set position to 10, 10.
26 gfx::Point position(10, 10);
27 sub_surface->SetPosition(position);
28
29 // A call to Commit() is required for position to take effect.
30 EXPECT_EQ(gfx::Point().ToString(), surface->bounds().origin().ToString());
31
32 // Check that position is updated when Commit() is called.
33 parent->Commit();
34 EXPECT_EQ(position.ToString(), surface->bounds().origin().ToString());
35 }
36
37 TEST_F(SubSurfaceTest, PlaceAbove) {
38 scoped_ptr<Surface> parent(new Surface);
39 scoped_ptr<Surface> surface1(new Surface);
40 scoped_ptr<Surface> surface2(new Surface);
41 scoped_ptr<Surface> non_sibling_surface(new Surface);
42 scoped_ptr<SubSurface> sub_surface1(
43 new SubSurface(surface1.get(), parent.get()));
44 scoped_ptr<SubSurface> sub_surface2(
45 new SubSurface(surface2.get(), parent.get()));
46
47 ASSERT_EQ(2, parent->child_count());
48 EXPECT_EQ(surface1.get(), parent->child_at(0));
49 EXPECT_EQ(surface2.get(), parent->child_at(1));
50
51 sub_surface2->PlaceAbove(parent.get());
52 sub_surface1->PlaceAbove(non_sibling_surface.get()); // Invalid
53 sub_surface1->PlaceAbove(surface1.get()); // Invalid
54 sub_surface1->PlaceAbove(surface2.get());
55
56 // Nothing should have changed as Commit() is required for new stacking
57 // order to take effect.
58 EXPECT_EQ(surface1.get(), parent->child_at(0));
59 EXPECT_EQ(surface2.get(), parent->child_at(1));
60
61 parent->Commit();
62
63 // surface1 should now be stacked above surface2.
64 EXPECT_EQ(surface2.get(), parent->child_at(0));
65 EXPECT_EQ(surface1.get(), parent->child_at(1));
66 }
67
68 TEST_F(SubSurfaceTest, PlaceBelow) {
69 scoped_ptr<Surface> parent(new Surface);
70 scoped_ptr<Surface> surface1(new Surface);
71 scoped_ptr<Surface> surface2(new Surface);
72 scoped_ptr<Surface> non_sibling_surface(new Surface);
73 scoped_ptr<SubSurface> sub_surface1(
74 new SubSurface(surface1.get(), parent.get()));
75 scoped_ptr<SubSurface> sub_surface2(
76 new SubSurface(surface2.get(), parent.get()));
77
78 ASSERT_EQ(2, parent->child_count());
79 EXPECT_EQ(surface1.get(), parent->child_at(0));
80 EXPECT_EQ(surface2.get(), parent->child_at(1));
81
82 sub_surface2->PlaceBelow(parent.get()); // Invalid
83 sub_surface2->PlaceBelow(non_sibling_surface.get()); // Invalid
84 sub_surface1->PlaceBelow(surface2.get());
85 sub_surface2->PlaceBelow(surface1.get());
86
87 // Nothing should have changed as Commit() is required for new stacking
88 // order to take effect.
89 EXPECT_EQ(surface1.get(), parent->child_at(0));
90 EXPECT_EQ(surface2.get(), parent->child_at(1));
91
92 parent->Commit();
93
94 // surface1 should now be stacked above surface2.
95 EXPECT_EQ(surface2.get(), parent->child_at(0));
96 EXPECT_EQ(surface1.get(), parent->child_at(1));
97 }
98
99 TEST_F(SubSurfaceTest, SetCommitBehavior) {
100 scoped_ptr<Surface> parent(new Surface);
101 scoped_ptr<Surface> child(new Surface);
102 scoped_ptr<Surface> grandchild(new Surface);
103 scoped_ptr<SubSurface> child_sub_surface(
104 new SubSurface(child.get(), parent.get()));
105 scoped_ptr<SubSurface> grandchild_sub_surface(
106 new SubSurface(grandchild.get(), child.get()));
107
108 // Initial position is at the origin.
109 EXPECT_EQ(gfx::Point().ToString(), grandchild->bounds().origin().ToString());
110
111 // Set position to 10, 10.
112 gfx::Point position1(10, 10);
113 grandchild_sub_surface->SetPosition(position1);
114 child->Commit();
115
116 // Initial commit behavior is synchronous and the effect of the child
117 // Commit() call will not take effect until Commit() is called on the
118 // parent.
119 EXPECT_EQ(gfx::Point().ToString(), grandchild->bounds().origin().ToString());
120
121 parent->Commit();
122
123 // Position should have been updated when Commit() has been called on both
124 // child and parent.
125 EXPECT_EQ(position1.ToString(), grandchild->bounds().origin().ToString());
126
127 // Disable synchronous commit behavior.
128 bool synchronized = false;
129 child_sub_surface->SetCommitBehavior(synchronized);
130
131 // Set position to 20, 20.
132 gfx::Point position2(20, 20);
133 grandchild_sub_surface->SetPosition(position2);
134 child->Commit();
135
136 // A Commit() call on child should be sufficient for the position of
137 // grandchild to take effect when synchronous is disabled.
138 EXPECT_EQ(position2.ToString(), grandchild->bounds().origin().ToString());
139 }
140
141 } // namespace
142 } // namespace exo
OLDNEW
« no previous file with comments | « components/exo/sub_surface.cc ('k') | components/exo/surface.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698