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

Side by Side Diff: components/exo/shell_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/display.cc ('k') | components/exo/sub_surface_unittest.cc » ('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 "base/message_loop/message_loop.h" 5 #include "base/message_loop/message_loop.h"
6 #include "base/strings/utf_string_conversions.h" 6 #include "base/strings/utf_string_conversions.h"
7 #include "components/exo/buffer.h" 7 #include "components/exo/buffer.h"
8 #include "components/exo/shell_surface.h" 8 #include "components/exo/shell_surface.h"
9 #include "components/exo/surface.h" 9 #include "components/exo/surface.h"
10 #include "components/exo/test/exo_test_base.h" 10 #include "components/exo/test/exo_test_base.h"
11 #include "components/exo/test/exo_test_helper.h" 11 #include "components/exo/test/exo_test_helper.h"
12 #include "testing/gtest/include/gtest/gtest.h" 12 #include "testing/gtest/include/gtest/gtest.h"
13 #include "ui/aura/window.h" 13 #include "ui/aura/window.h"
14 #include "ui/base/hit_test.h" 14 #include "ui/base/hit_test.h"
15 #include "ui/views/widget/widget.h" 15 #include "ui/views/widget/widget.h"
16 #include "ui/wm/core/window_util.h" 16 #include "ui/wm/core/window_util.h"
17 17
18 namespace exo { 18 namespace exo {
19 namespace { 19 namespace {
20 20
21 using ShellSurfaceTest = test::ExoTestBase; 21 class ShellSurfaceTest : public test::ExoTestBase,
22 public ::testing::WithParamInterface<bool> {
23 void SetUp() override {
24 Surface::SetUseSurfaceLayer(GetParam());
25 test::ExoTestBase::SetUp();
26 }
27 };
22 28
23 uint32_t ConfigureFullscreen(uint32_t serial, 29 uint32_t ConfigureFullscreen(uint32_t serial,
24 const gfx::Size& size, 30 const gfx::Size& size,
25 ash::wm::WindowStateType state_type, 31 ash::wm::WindowStateType state_type,
26 bool resizing, 32 bool resizing,
27 bool activated) { 33 bool activated) {
28 EXPECT_EQ(ash::wm::WINDOW_STATE_TYPE_FULLSCREEN, state_type); 34 EXPECT_EQ(ash::wm::WINDOW_STATE_TYPE_FULLSCREEN, state_type);
29 return serial; 35 return serial;
30 } 36 }
31 37
32 TEST_F(ShellSurfaceTest, AcknowledgeConfigure) { 38 TEST_P(ShellSurfaceTest, AcknowledgeConfigure) {
33 gfx::Size buffer_size(32, 32); 39 gfx::Size buffer_size(32, 32);
34 std::unique_ptr<Buffer> buffer( 40 std::unique_ptr<Buffer> buffer(
35 new Buffer(exo_test_helper()->CreateGpuMemoryBuffer(buffer_size))); 41 new Buffer(exo_test_helper()->CreateGpuMemoryBuffer(buffer_size)));
36 std::unique_ptr<Surface> surface(new Surface); 42 std::unique_ptr<Surface> surface(new Surface);
37 std::unique_ptr<ShellSurface> shell_surface(new ShellSurface(surface.get())); 43 std::unique_ptr<ShellSurface> shell_surface(new ShellSurface(surface.get()));
38 44
39 surface->Attach(buffer.get()); 45 surface->Attach(buffer.get());
40 surface->Commit(); 46 surface->Commit();
41 47
42 gfx::Point origin(100, 100); 48 gfx::Point origin(100, 100);
(...skipping 14 matching lines...) Expand all
57 std::unique_ptr<Buffer> fullscreen_buffer( 63 std::unique_ptr<Buffer> fullscreen_buffer(
58 new Buffer(exo_test_helper()->CreateGpuMemoryBuffer( 64 new Buffer(exo_test_helper()->CreateGpuMemoryBuffer(
59 CurrentContext()->bounds().size()))); 65 CurrentContext()->bounds().size())));
60 surface->Attach(fullscreen_buffer.get()); 66 surface->Attach(fullscreen_buffer.get());
61 surface->Commit(); 67 surface->Commit();
62 68
63 EXPECT_EQ(gfx::Point().ToString(), 69 EXPECT_EQ(gfx::Point().ToString(),
64 surface->GetBoundsInRootWindow().origin().ToString()); 70 surface->GetBoundsInRootWindow().origin().ToString());
65 } 71 }
66 72
67 TEST_F(ShellSurfaceTest, SetParent) { 73 TEST_P(ShellSurfaceTest, SetParent) {
68 gfx::Size buffer_size(256, 256); 74 gfx::Size buffer_size(256, 256);
69 std::unique_ptr<Buffer> parent_buffer( 75 std::unique_ptr<Buffer> parent_buffer(
70 new Buffer(exo_test_helper()->CreateGpuMemoryBuffer(buffer_size))); 76 new Buffer(exo_test_helper()->CreateGpuMemoryBuffer(buffer_size)));
71 std::unique_ptr<Surface> parent_surface(new Surface); 77 std::unique_ptr<Surface> parent_surface(new Surface);
72 std::unique_ptr<ShellSurface> parent_shell_surface( 78 std::unique_ptr<ShellSurface> parent_shell_surface(
73 new ShellSurface(parent_surface.get())); 79 new ShellSurface(parent_surface.get()));
74 80
75 parent_surface->Attach(parent_buffer.get()); 81 parent_surface->Attach(parent_buffer.get());
76 parent_surface->Commit(); 82 parent_surface->Commit();
77 83
78 std::unique_ptr<Buffer> buffer( 84 std::unique_ptr<Buffer> buffer(
79 new Buffer(exo_test_helper()->CreateGpuMemoryBuffer(buffer_size))); 85 new Buffer(exo_test_helper()->CreateGpuMemoryBuffer(buffer_size)));
80 std::unique_ptr<Surface> surface(new Surface); 86 std::unique_ptr<Surface> surface(new Surface);
81 std::unique_ptr<ShellSurface> shell_surface(new ShellSurface(surface.get())); 87 std::unique_ptr<ShellSurface> shell_surface(new ShellSurface(surface.get()));
82 shell_surface->SetParent(parent_shell_surface.get()); 88 shell_surface->SetParent(parent_shell_surface.get());
83 89
84 surface->Attach(buffer.get()); 90 surface->Attach(buffer.get());
85 surface->Commit(); 91 surface->Commit();
86 EXPECT_EQ( 92 EXPECT_EQ(
87 parent_shell_surface->GetWidget()->GetNativeWindow(), 93 parent_shell_surface->GetWidget()->GetNativeWindow(),
88 wm::GetTransientParent(shell_surface->GetWidget()->GetNativeWindow())); 94 wm::GetTransientParent(shell_surface->GetWidget()->GetNativeWindow()));
89 } 95 }
90 96
91 TEST_F(ShellSurfaceTest, Maximize) { 97 TEST_P(ShellSurfaceTest, Maximize) {
92 gfx::Size buffer_size(256, 256); 98 gfx::Size buffer_size(256, 256);
93 std::unique_ptr<Buffer> buffer( 99 std::unique_ptr<Buffer> buffer(
94 new Buffer(exo_test_helper()->CreateGpuMemoryBuffer(buffer_size))); 100 new Buffer(exo_test_helper()->CreateGpuMemoryBuffer(buffer_size)));
95 std::unique_ptr<Surface> surface(new Surface); 101 std::unique_ptr<Surface> surface(new Surface);
96 std::unique_ptr<ShellSurface> shell_surface(new ShellSurface(surface.get())); 102 std::unique_ptr<ShellSurface> shell_surface(new ShellSurface(surface.get()));
97 103
98 surface->Attach(buffer.get()); 104 surface->Attach(buffer.get());
99 shell_surface->Maximize(); 105 shell_surface->Maximize();
100 surface->Commit(); 106 surface->Commit();
101 EXPECT_EQ(CurrentContext()->bounds().width(), 107 EXPECT_EQ(CurrentContext()->bounds().width(),
102 shell_surface->GetWidget()->GetWindowBoundsInScreen().width()); 108 shell_surface->GetWidget()->GetWindowBoundsInScreen().width());
103 } 109 }
104 110
105 TEST_F(ShellSurfaceTest, Restore) { 111 TEST_P(ShellSurfaceTest, Restore) {
106 gfx::Size buffer_size(256, 256); 112 gfx::Size buffer_size(256, 256);
107 std::unique_ptr<Buffer> buffer( 113 std::unique_ptr<Buffer> buffer(
108 new Buffer(exo_test_helper()->CreateGpuMemoryBuffer(buffer_size))); 114 new Buffer(exo_test_helper()->CreateGpuMemoryBuffer(buffer_size)));
109 std::unique_ptr<Surface> surface(new Surface); 115 std::unique_ptr<Surface> surface(new Surface);
110 std::unique_ptr<ShellSurface> shell_surface(new ShellSurface(surface.get())); 116 std::unique_ptr<ShellSurface> shell_surface(new ShellSurface(surface.get()));
111 117
112 surface->Attach(buffer.get()); 118 surface->Attach(buffer.get());
113 surface->Commit(); 119 surface->Commit();
114 // Note: Remove contents to avoid issues with maximize animations in tests. 120 // Note: Remove contents to avoid issues with maximize animations in tests.
115 surface->Attach(nullptr); 121 if (!GetParam()) {
116 surface->Commit(); 122 surface->Attach(nullptr);
123 surface->Commit();
124 }
117 shell_surface->Maximize(); 125 shell_surface->Maximize();
118 shell_surface->Restore(); 126 shell_surface->Restore();
119 EXPECT_EQ( 127 EXPECT_EQ(
120 buffer_size.ToString(), 128 buffer_size.ToString(),
121 shell_surface->GetWidget()->GetWindowBoundsInScreen().size().ToString()); 129 shell_surface->GetWidget()->GetWindowBoundsInScreen().size().ToString());
122 } 130 }
123 131
124 TEST_F(ShellSurfaceTest, SetFullscreen) { 132 TEST_P(ShellSurfaceTest, SetFullscreen) {
125 gfx::Size buffer_size(256, 256); 133 gfx::Size buffer_size(256, 256);
126 std::unique_ptr<Buffer> buffer( 134 std::unique_ptr<Buffer> buffer(
127 new Buffer(exo_test_helper()->CreateGpuMemoryBuffer(buffer_size))); 135 new Buffer(exo_test_helper()->CreateGpuMemoryBuffer(buffer_size)));
128 std::unique_ptr<Surface> surface(new Surface); 136 std::unique_ptr<Surface> surface(new Surface);
129 std::unique_ptr<ShellSurface> shell_surface(new ShellSurface(surface.get())); 137 std::unique_ptr<ShellSurface> shell_surface(new ShellSurface(surface.get()));
130 138
131 shell_surface->SetFullscreen(true); 139 shell_surface->SetFullscreen(true);
132 surface->Attach(buffer.get()); 140 surface->Attach(buffer.get());
133 surface->Commit(); 141 surface->Commit();
134 EXPECT_EQ(CurrentContext()->bounds().ToString(), 142 EXPECT_EQ(CurrentContext()->bounds().ToString(),
135 shell_surface->GetWidget()->GetWindowBoundsInScreen().ToString()); 143 shell_surface->GetWidget()->GetWindowBoundsInScreen().ToString());
136 } 144 }
137 145
138 TEST_F(ShellSurfaceTest, SetTitle) { 146 TEST_P(ShellSurfaceTest, SetTitle) {
139 std::unique_ptr<Surface> surface(new Surface); 147 std::unique_ptr<Surface> surface(new Surface);
140 std::unique_ptr<ShellSurface> shell_surface(new ShellSurface(surface.get())); 148 std::unique_ptr<ShellSurface> shell_surface(new ShellSurface(surface.get()));
141 149
142 shell_surface->SetTitle(base::string16(base::ASCIIToUTF16("test"))); 150 shell_surface->SetTitle(base::string16(base::ASCIIToUTF16("test")));
143 surface->Commit(); 151 surface->Commit();
144 } 152 }
145 153
146 TEST_F(ShellSurfaceTest, SetApplicationId) { 154 TEST_P(ShellSurfaceTest, SetApplicationId) {
147 std::unique_ptr<Surface> surface(new Surface); 155 std::unique_ptr<Surface> surface(new Surface);
148 std::unique_ptr<ShellSurface> shell_surface(new ShellSurface(surface.get())); 156 std::unique_ptr<ShellSurface> shell_surface(new ShellSurface(surface.get()));
149 157
150 surface->Commit(); 158 surface->Commit();
151 EXPECT_EQ("", ShellSurface::GetApplicationId( 159 EXPECT_EQ("", ShellSurface::GetApplicationId(
152 shell_surface->GetWidget()->GetNativeWindow())); 160 shell_surface->GetWidget()->GetNativeWindow()));
153 shell_surface->SetApplicationId("test"); 161 shell_surface->SetApplicationId("test");
154 EXPECT_EQ("test", ShellSurface::GetApplicationId( 162 EXPECT_EQ("test", ShellSurface::GetApplicationId(
155 shell_surface->GetWidget()->GetNativeWindow())); 163 shell_surface->GetWidget()->GetNativeWindow()));
156 } 164 }
157 165
158 TEST_F(ShellSurfaceTest, Move) { 166 TEST_P(ShellSurfaceTest, Move) {
159 std::unique_ptr<Surface> surface(new Surface); 167 std::unique_ptr<Surface> surface(new Surface);
160 std::unique_ptr<ShellSurface> shell_surface(new ShellSurface(surface.get())); 168 std::unique_ptr<ShellSurface> shell_surface(new ShellSurface(surface.get()));
161 169
162 // Map shell surface. 170 // Map shell surface.
163 surface->Commit(); 171 surface->Commit();
164 172
165 // The interactive move should end when surface is destroyed. 173 // The interactive move should end when surface is destroyed.
166 shell_surface->Move(); 174 shell_surface->Move();
167 175
168 // Test that destroying the shell surface before move ends is OK. 176 // Test that destroying the shell surface before move ends is OK.
169 shell_surface.reset(); 177 shell_surface.reset();
170 } 178 }
171 179
172 TEST_F(ShellSurfaceTest, Resize) { 180 TEST_P(ShellSurfaceTest, Resize) {
173 std::unique_ptr<Surface> surface(new Surface); 181 std::unique_ptr<Surface> surface(new Surface);
174 std::unique_ptr<ShellSurface> shell_surface(new ShellSurface(surface.get())); 182 std::unique_ptr<ShellSurface> shell_surface(new ShellSurface(surface.get()));
175 183
176 // Map shell surface. 184 // Map shell surface.
177 surface->Commit(); 185 surface->Commit();
178 186
179 // The interactive resize should end when surface is destroyed. 187 // The interactive resize should end when surface is destroyed.
180 shell_surface->Resize(HTBOTTOMRIGHT); 188 shell_surface->Resize(HTBOTTOMRIGHT);
181 189
182 // Test that destroying the surface before resize ends is OK. 190 // Test that destroying the surface before resize ends is OK.
183 surface.reset(); 191 surface.reset();
184 } 192 }
185 193
186 TEST_F(ShellSurfaceTest, SetGeometry) { 194 TEST_P(ShellSurfaceTest, SetGeometry) {
187 gfx::Size buffer_size(64, 64); 195 gfx::Size buffer_size(64, 64);
188 std::unique_ptr<Buffer> buffer( 196 std::unique_ptr<Buffer> buffer(
189 new Buffer(exo_test_helper()->CreateGpuMemoryBuffer(buffer_size))); 197 new Buffer(exo_test_helper()->CreateGpuMemoryBuffer(buffer_size)));
190 std::unique_ptr<Surface> surface(new Surface); 198 std::unique_ptr<Surface> surface(new Surface);
191 std::unique_ptr<ShellSurface> shell_surface(new ShellSurface(surface.get())); 199 std::unique_ptr<ShellSurface> shell_surface(new ShellSurface(surface.get()));
192 200
193 gfx::Rect geometry(16, 16, 32, 32); 201 gfx::Rect geometry(16, 16, 32, 32);
194 shell_surface->SetGeometry(geometry); 202 shell_surface->SetGeometry(geometry);
195 surface->Attach(buffer.get()); 203 surface->Attach(buffer.get());
196 surface->Commit(); 204 surface->Commit();
(...skipping 20 matching lines...) Expand all
217 gfx::Transform transform; 225 gfx::Transform transform;
218 transform.Scale(1.0 / scale, 1.0 / scale); 226 transform.Scale(1.0 / scale, 1.0 / scale);
219 EXPECT_EQ(transform.ToString(), 227 EXPECT_EQ(transform.ToString(),
220 surface->layer()->GetTargetTransform().ToString()); 228 surface->layer()->GetTargetTransform().ToString());
221 } 229 }
222 230
223 void Close(int* close_call_count) { 231 void Close(int* close_call_count) {
224 (*close_call_count)++; 232 (*close_call_count)++;
225 } 233 }
226 234
227 TEST_F(ShellSurfaceTest, CloseCallback) { 235 TEST_P(ShellSurfaceTest, CloseCallback) {
228 std::unique_ptr<Surface> surface(new Surface); 236 std::unique_ptr<Surface> surface(new Surface);
229 std::unique_ptr<ShellSurface> shell_surface(new ShellSurface(surface.get())); 237 std::unique_ptr<ShellSurface> shell_surface(new ShellSurface(surface.get()));
230 238
231 int close_call_count = 0; 239 int close_call_count = 0;
232 shell_surface->set_close_callback( 240 shell_surface->set_close_callback(
233 base::Bind(&Close, base::Unretained(&close_call_count))); 241 base::Bind(&Close, base::Unretained(&close_call_count)));
234 242
235 surface->Commit(); 243 surface->Commit();
236 244
237 EXPECT_EQ(0, close_call_count); 245 EXPECT_EQ(0, close_call_count);
238 shell_surface->GetWidget()->Close(); 246 shell_surface->GetWidget()->Close();
239 EXPECT_EQ(1, close_call_count); 247 EXPECT_EQ(1, close_call_count);
240 } 248 }
241 249
242 void DestroyShellSurface(std::unique_ptr<ShellSurface>* shell_surface) { 250 void DestroyShellSurface(std::unique_ptr<ShellSurface>* shell_surface) {
243 shell_surface->reset(); 251 shell_surface->reset();
244 } 252 }
245 253
246 TEST_F(ShellSurfaceTest, SurfaceDestroyedCallback) { 254 TEST_P(ShellSurfaceTest, SurfaceDestroyedCallback) {
247 std::unique_ptr<Surface> surface(new Surface); 255 std::unique_ptr<Surface> surface(new Surface);
248 std::unique_ptr<ShellSurface> shell_surface(new ShellSurface(surface.get())); 256 std::unique_ptr<ShellSurface> shell_surface(new ShellSurface(surface.get()));
249 257
250 shell_surface->set_surface_destroyed_callback( 258 shell_surface->set_surface_destroyed_callback(
251 base::Bind(&DestroyShellSurface, base::Unretained(&shell_surface))); 259 base::Bind(&DestroyShellSurface, base::Unretained(&shell_surface)));
252 260
253 surface->Commit(); 261 surface->Commit();
254 262
255 EXPECT_TRUE(shell_surface.get()); 263 EXPECT_TRUE(shell_surface.get());
256 surface.reset(); 264 surface.reset();
257 EXPECT_FALSE(shell_surface.get()); 265 EXPECT_FALSE(shell_surface.get());
258 } 266 }
259 267
260 uint32_t Configure(gfx::Size* suggested_size, 268 uint32_t Configure(gfx::Size* suggested_size,
261 ash::wm::WindowStateType* has_state_type, 269 ash::wm::WindowStateType* has_state_type,
262 bool* is_resizing, 270 bool* is_resizing,
263 bool* is_active, 271 bool* is_active,
264 const gfx::Size& size, 272 const gfx::Size& size,
265 ash::wm::WindowStateType state_type, 273 ash::wm::WindowStateType state_type,
266 bool resizing, 274 bool resizing,
267 bool activated) { 275 bool activated) {
268 *suggested_size = size; 276 *suggested_size = size;
269 *has_state_type = state_type; 277 *has_state_type = state_type;
270 *is_resizing = resizing; 278 *is_resizing = resizing;
271 *is_active = activated; 279 *is_active = activated;
272 return 0; 280 return 0;
273 } 281 }
274 282
275 TEST_F(ShellSurfaceTest, ConfigureCallback) { 283 TEST_P(ShellSurfaceTest, ConfigureCallback) {
276 std::unique_ptr<Surface> surface(new Surface); 284 std::unique_ptr<Surface> surface(new Surface);
277 std::unique_ptr<ShellSurface> shell_surface(new ShellSurface(surface.get())); 285 std::unique_ptr<ShellSurface> shell_surface(new ShellSurface(surface.get()));
278 286
279 gfx::Size suggested_size; 287 gfx::Size suggested_size;
280 ash::wm::WindowStateType has_state_type = ash::wm::WINDOW_STATE_TYPE_NORMAL; 288 ash::wm::WindowStateType has_state_type = ash::wm::WINDOW_STATE_TYPE_NORMAL;
281 bool is_resizing = false; 289 bool is_resizing = false;
282 bool is_active = false; 290 bool is_active = false;
283 shell_surface->set_configure_callback( 291 shell_surface->set_configure_callback(
284 base::Bind(&Configure, base::Unretained(&suggested_size), 292 base::Bind(&Configure, base::Unretained(&suggested_size),
285 base::Unretained(&has_state_type), 293 base::Unretained(&has_state_type),
(...skipping 24 matching lines...) Expand all
310 shell_surface->GetWidget()->Deactivate(); 318 shell_surface->GetWidget()->Deactivate();
311 shell_surface->AcknowledgeConfigure(0); 319 shell_surface->AcknowledgeConfigure(0);
312 EXPECT_FALSE(is_active); 320 EXPECT_FALSE(is_active);
313 321
314 EXPECT_FALSE(is_resizing); 322 EXPECT_FALSE(is_resizing);
315 shell_surface->Resize(HTBOTTOMRIGHT); 323 shell_surface->Resize(HTBOTTOMRIGHT);
316 shell_surface->AcknowledgeConfigure(0); 324 shell_surface->AcknowledgeConfigure(0);
317 EXPECT_TRUE(is_resizing); 325 EXPECT_TRUE(is_resizing);
318 } 326 }
319 327
328 INSTANTIATE_TEST_CASE_P(, ShellSurfaceTest, ::testing::Bool());
329
320 } // namespace 330 } // namespace
321 } // namespace exo 331 } // namespace exo
OLDNEW
« no previous file with comments | « components/exo/display.cc ('k') | components/exo/sub_surface_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698