1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
|
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "components/exo/sub_surface.h"
#include "base/memory/ptr_util.h"
#include "components/exo/surface.h"
#include "components/exo/test/exo_test_base.h"
#include "components/exo/test/exo_test_helper.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace exo {
namespace {
using SubSurfaceTest = test::ExoTestBase;
TEST_F(SubSurfaceTest, SetPosition) {
std::unique_ptr<Surface> parent(new Surface);
std::unique_ptr<Surface> surface(new Surface);
std::unique_ptr<SubSurface> sub_surface(
new SubSurface(surface.get(), parent.get()));
// Initial position is at the origin.
EXPECT_EQ(gfx::Point().ToString(),
surface->window()->bounds().origin().ToString());
// Set position to 10, 10.
gfx::Point position(10, 10);
sub_surface->SetPosition(position);
// A call to Commit() is required for position to take effect.
EXPECT_EQ(gfx::Point().ToString(),
surface->window()->bounds().origin().ToString());
// Check that position is updated when Commit() is called.
parent->Commit();
EXPECT_EQ(position.ToString(),
surface->window()->bounds().origin().ToString());
// Create and commit a new sub-surface using the same surface.
sub_surface.reset();
sub_surface = base::MakeUnique<SubSurface>(surface.get(), parent.get());
parent->Commit();
// Initial position should be reset to origin.
EXPECT_EQ(gfx::Point().ToString(),
surface->window()->bounds().origin().ToString());
}
TEST_F(SubSurfaceTest, PlaceAbove) {
std::unique_ptr<Surface> parent(new Surface);
std::unique_ptr<Surface> surface1(new Surface);
std::unique_ptr<Surface> surface2(new Surface);
std::unique_ptr<Surface> non_sibling_surface(new Surface);
std::unique_ptr<SubSurface> sub_surface1(
new SubSurface(surface1.get(), parent.get()));
std::unique_ptr<SubSurface> sub_surface2(
new SubSurface(surface2.get(), parent.get()));
ASSERT_EQ(2u, parent->window()->children().size());
EXPECT_EQ(surface1->window(), parent->window()->children()[0]);
EXPECT_EQ(surface2->window(), parent->window()->children()[1]);
sub_surface2->PlaceAbove(parent.get());
sub_surface1->PlaceAbove(non_sibling_surface.get()); // Invalid
sub_surface1->PlaceAbove(surface1.get()); // Invalid
sub_surface1->PlaceAbove(surface2.get());
// Nothing should have changed as Commit() is required for new stacking
// order to take effect.
EXPECT_EQ(surface1->window(), parent->window()->children()[0]);
EXPECT_EQ(surface2->window(), parent->window()->children()[1]);
parent->Commit();
// surface1 should now be stacked above surface2.
EXPECT_EQ(surface2->window(), parent->window()->children()[0]);
EXPECT_EQ(surface1->window(), parent->window()->children()[1]);
}
TEST_F(SubSurfaceTest, PlaceBelow) {
std::unique_ptr<Surface> parent(new Surface);
std::unique_ptr<Surface> surface1(new Surface);
std::unique_ptr<Surface> surface2(new Surface);
std::unique_ptr<Surface> non_sibling_surface(new Surface);
std::unique_ptr<SubSurface> sub_surface1(
new SubSurface(surface1.get(), parent.get()));
std::unique_ptr<SubSurface> sub_surface2(
new SubSurface(surface2.get(), parent.get()));
ASSERT_EQ(2u, parent->window()->children().size());
EXPECT_EQ(surface1->window(), parent->window()->children()[0]);
EXPECT_EQ(surface2->window(), parent->window()->children()[1]);
sub_surface2->PlaceBelow(parent.get()); // Invalid
sub_surface2->PlaceBelow(non_sibling_surface.get()); // Invalid
sub_surface1->PlaceBelow(surface2.get());
sub_surface2->PlaceBelow(surface1.get());
// Nothing should have changed as Commit() is required for new stacking
// order to take effect.
EXPECT_EQ(surface1->window(), parent->window()->children()[0]);
EXPECT_EQ(surface2->window(), parent->window()->children()[1]);
parent->Commit();
// surface1 should now be stacked above surface2.
EXPECT_EQ(surface2->window(), parent->window()->children()[0]);
EXPECT_EQ(surface1->window(), parent->window()->children()[1]);
}
TEST_F(SubSurfaceTest, SetCommitBehavior) {
std::unique_ptr<Surface> parent(new Surface);
std::unique_ptr<Surface> child(new Surface);
std::unique_ptr<Surface> grandchild(new Surface);
std::unique_ptr<SubSurface> child_sub_surface(
new SubSurface(child.get(), parent.get()));
std::unique_ptr<SubSurface> grandchild_sub_surface(
new SubSurface(grandchild.get(), child.get()));
// Initial position is at the origin.
EXPECT_EQ(gfx::Point().ToString(),
grandchild->window()->bounds().origin().ToString());
// Set position to 10, 10.
gfx::Point position1(10, 10);
grandchild_sub_surface->SetPosition(position1);
child->Commit();
// Initial commit behavior is synchronous and the effect of the child
// Commit() call will not take effect until Commit() is called on the
// parent.
EXPECT_EQ(gfx::Point().ToString(),
grandchild->window()->bounds().origin().ToString());
parent->Commit();
// Position should have been updated when Commit() has been called on both
// child and parent.
EXPECT_EQ(position1.ToString(),
grandchild->window()->bounds().origin().ToString());
// Disable synchronous commit behavior.
bool synchronized = false;
child_sub_surface->SetCommitBehavior(synchronized);
// Set position to 20, 20.
gfx::Point position2(20, 20);
grandchild_sub_surface->SetPosition(position2);
child->Commit();
// A Commit() call on child should be sufficient for the position of
// grandchild to take effect when synchronous is disabled.
EXPECT_EQ(position2.ToString(),
grandchild->window()->bounds().origin().ToString());
}
} // namespace
} // namespace exo
|