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

Side by Side Diff: ui/aura/mus/window_tree_client_unittest.cc

Issue 2780043002: Aura-Mus: Allocate a LocalSurfaceId on size change (Closed)
Patch Set: Cleanup Created 3 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 unified diff | Download patch
« no previous file with comments | « ui/aura/mus/window_tree_client.cc ('k') | ui/aura/test/mus/test_window_tree.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 "ui/aura/mus/window_tree_client.h" 5 #include "ui/aura/mus/window_tree_client.h"
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8 8
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after
148 const gfx::Rect original_bounds(window.bounds()); 148 const gfx::Rect original_bounds(window.bounds());
149 const gfx::Rect new_bounds(gfx::Rect(0, 0, 100, 100)); 149 const gfx::Rect new_bounds(gfx::Rect(0, 0, 100, 100));
150 ASSERT_NE(new_bounds, window.bounds()); 150 ASSERT_NE(new_bounds, window.bounds());
151 window.SetBounds(new_bounds); 151 window.SetBounds(new_bounds);
152 EXPECT_EQ(new_bounds, window.bounds()); 152 EXPECT_EQ(new_bounds, window.bounds());
153 ASSERT_TRUE(window_tree()->AckSingleChangeOfType(WindowTreeChangeType::BOUNDS, 153 ASSERT_TRUE(window_tree()->AckSingleChangeOfType(WindowTreeChangeType::BOUNDS,
154 false)); 154 false));
155 EXPECT_EQ(original_bounds, window.bounds()); 155 EXPECT_EQ(original_bounds, window.bounds());
156 } 156 }
157 157
158 // Verifies bounds and the cc::LocalSurfaceId associated with the bounds are
159 // reverted if the server replied that the change failed.
160 TEST_F(WindowTreeClientWmTest, SetBoundsFailedLocalSurfaceId) {
161 Window window(nullptr);
162 // TOP_LEVEL_IN_WM and EMBED_IN_OWNER windows allocate cc::LocalSurfaceIds
163 // when their sizes change.
164 window.SetProperty(aura::client::kEmbedType,
165 aura::client::WindowEmbedType::EMBED_IN_OWNER);
166 window.Init(ui::LAYER_NOT_DRAWN);
167
168 const gfx::Rect original_bounds(window.bounds());
169 const gfx::Rect new_bounds(gfx::Rect(0, 0, 100, 100));
170 ASSERT_NE(new_bounds, window.bounds());
171 window.SetBounds(new_bounds);
172 EXPECT_EQ(new_bounds, window.bounds());
173 WindowMus* window_mus = WindowMus::Get(&window);
174 ASSERT_NE(nullptr, window_mus);
175 EXPECT_TRUE(window_mus->GetLocalSurfaceId().is_valid());
176
177 // Reverting the change should also revert the cc::LocalSurfaceId.
178 ASSERT_TRUE(window_tree()->AckSingleChangeOfType(WindowTreeChangeType::BOUNDS,
179 false));
180 EXPECT_EQ(original_bounds, window.bounds());
181 EXPECT_FALSE(window_mus->GetLocalSurfaceId().is_valid());
182 }
183
184 // Verifies that the cc::LocalSurfaceId generated by an embedder changes when
185 // the size changes, but not when the position changes.
186 TEST_F(WindowTreeClientWmTest, SetBoundsLocalSurfaceIdChanges) {
187 ASSERT_EQ(base::nullopt, window_tree()->last_local_surface_id());
188 Window window(nullptr);
189 // TOP_LEVEL_IN_WM and EMBED_IN_OWNER windows allocate cc::LocalSurfaceIds
190 // when their sizes change.
191 window.SetProperty(aura::client::kEmbedType,
192 aura::client::WindowEmbedType::EMBED_IN_OWNER);
193 window.Init(ui::LAYER_NOT_DRAWN);
194
195 // Resize the window and verify that we've allocated a cc::LocalSurfaceId.
196 const gfx::Rect new_bounds(0, 0, 100, 100);
197 ASSERT_NE(new_bounds, window.bounds());
198 window.SetBounds(new_bounds);
199 EXPECT_EQ(new_bounds, window.bounds());
200 base::Optional<cc::LocalSurfaceId> last_local_surface_id =
201 window_tree()->last_local_surface_id();
202 ASSERT_NE(base::nullopt, last_local_surface_id);
203
204 // Resize the window again and verify that the cc::LocalSurfaceId has changed.
205 const gfx::Rect new_bounds2(0, 0, 100, 102);
206 ASSERT_NE(new_bounds2, window.bounds());
207 window.SetBounds(new_bounds2);
208 EXPECT_EQ(new_bounds2, window.bounds());
209 base::Optional<cc::LocalSurfaceId> last_local_surface_id2 =
210 window_tree()->last_local_surface_id();
211 ASSERT_NE(base::nullopt, last_local_surface_id2);
212 EXPECT_NE(last_local_surface_id2, last_local_surface_id);
213
214 // Moving the window but not changing the size should not allocate a new
215 // cc::LocalSurfaceId.
216 const gfx::Rect new_bounds3(1337, 7331, 100, 102);
217 ASSERT_NE(new_bounds3, window.bounds());
218 window.SetBounds(new_bounds3);
219 EXPECT_EQ(new_bounds3, window.bounds());
220 base::Optional<cc::LocalSurfaceId> last_local_surface_id3 =
221 window_tree()->last_local_surface_id();
222 ASSERT_NE(base::nullopt, last_local_surface_id3);
223 EXPECT_EQ(last_local_surface_id2, last_local_surface_id3);
224 }
225
158 // Verifies a new window from the server doesn't result in attempting to add 226 // Verifies a new window from the server doesn't result in attempting to add
159 // the window back to the server. 227 // the window back to the server.
160 TEST_F(WindowTreeClientWmTest, AddFromServerDoesntAddAgain) { 228 TEST_F(WindowTreeClientWmTest, AddFromServerDoesntAddAgain) {
161 const Id child_window_id = server_id(root_window()) + 11; 229 const Id child_window_id = server_id(root_window()) + 11;
162 ui::mojom::WindowDataPtr data = ui::mojom::WindowData::New(); 230 ui::mojom::WindowDataPtr data = ui::mojom::WindowData::New();
163 data->parent_id = server_id(root_window()); 231 data->parent_id = server_id(root_window());
164 data->window_id = child_window_id; 232 data->window_id = child_window_id;
165 data->bounds = gfx::Rect(1, 2, 3, 4); 233 data->bounds = gfx::Rect(1, 2, 3, 4);
166 data->visible = false; 234 data->visible = false;
167 std::vector<ui::mojom::WindowDataPtr> data_array(1); 235 std::vector<ui::mojom::WindowDataPtr> data_array(1);
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
259 window_tree()->AckAllChanges(); 327 window_tree()->AckAllChanges();
260 EXPECT_FALSE(window1.HasFocus()); 328 EXPECT_FALSE(window1.HasFocus());
261 // Simulate moving |window1| to be a child of |window2| from the server. 329 // Simulate moving |window1| to be a child of |window2| from the server.
262 window_tree_client()->OnWindowFocused(server_id(&window1)); 330 window_tree_client()->OnWindowFocused(server_id(&window1));
263 ASSERT_FALSE(window_tree()->has_change()); 331 ASSERT_FALSE(window_tree()->has_change());
264 EXPECT_TRUE(window1.HasFocus()); 332 EXPECT_TRUE(window1.HasFocus());
265 } 333 }
266 334
267 // Simulates a bounds change, and while the bounds change is in flight the 335 // Simulates a bounds change, and while the bounds change is in flight the
268 // server replies with a new bounds and the original bounds change fails. 336 // server replies with a new bounds and the original bounds change fails.
337 // The server bounds change takes hold along with the associated
338 // cc::LocalSurfaceId.
269 TEST_F(WindowTreeClientWmTest, SetBoundsFailedWithPendingChange) { 339 TEST_F(WindowTreeClientWmTest, SetBoundsFailedWithPendingChange) {
270 const gfx::Rect original_bounds(root_window()->bounds()); 340 const gfx::Rect original_bounds(root_window()->bounds());
271 const gfx::Rect new_bounds(gfx::Rect(0, 0, 100, 100)); 341 const gfx::Rect new_bounds(gfx::Rect(0, 0, 100, 100));
272 ASSERT_NE(new_bounds, root_window()->bounds()); 342 ASSERT_NE(new_bounds, root_window()->bounds());
273 root_window()->SetBounds(new_bounds); 343 root_window()->SetBounds(new_bounds);
274 EXPECT_EQ(new_bounds, root_window()->bounds()); 344 EXPECT_EQ(new_bounds, root_window()->bounds());
275 345
276 // Simulate the server responding with a bounds change. 346 // Simulate the server responding with a bounds change.
277 const gfx::Rect server_changed_bounds(gfx::Rect(0, 0, 101, 102)); 347 const gfx::Rect server_changed_bounds(gfx::Rect(0, 0, 101, 102));
348 const cc::LocalSurfaceId server_changed_local_surface_id(
349 1, base::UnguessableToken::Create());
278 window_tree_client()->OnWindowBoundsChanged( 350 window_tree_client()->OnWindowBoundsChanged(
279 server_id(root_window()), original_bounds, server_changed_bounds, 351 server_id(root_window()), original_bounds, server_changed_bounds,
280 base::nullopt); 352 server_changed_local_surface_id);
353
354 WindowMus* root_window_mus = WindowMus::Get(root_window());
355 ASSERT_NE(nullptr, root_window_mus);
281 356
282 // This shouldn't trigger the bounds changing yet. 357 // This shouldn't trigger the bounds changing yet.
283 EXPECT_EQ(new_bounds, root_window()->bounds()); 358 EXPECT_EQ(new_bounds, root_window()->bounds());
359 EXPECT_FALSE(root_window_mus->GetLocalSurfaceId().is_valid());
284 360
285 // Tell the client the change failed, which should trigger failing to the 361 // Tell the client the change failed, which should trigger failing to the
286 // most recent bounds from server. 362 // most recent bounds from server.
287 ASSERT_TRUE(window_tree()->AckSingleChangeOfType(WindowTreeChangeType::BOUNDS, 363 ASSERT_TRUE(window_tree()->AckSingleChangeOfType(WindowTreeChangeType::BOUNDS,
288 false)); 364 false));
289 EXPECT_EQ(server_changed_bounds, root_window()->bounds()); 365 EXPECT_EQ(server_changed_bounds, root_window()->bounds());
366 EXPECT_EQ(server_changed_local_surface_id,
367 root_window_mus->GetLocalSurfaceId());
290 368
291 // Simulate server changing back to original bounds. Should take immediately. 369 // Simulate server changing back to original bounds. Should take immediately.
292 window_tree_client()->OnWindowBoundsChanged(server_id(root_window()), 370 window_tree_client()->OnWindowBoundsChanged(server_id(root_window()),
293 server_changed_bounds, 371 server_changed_bounds,
294 original_bounds, base::nullopt); 372 original_bounds, base::nullopt);
295 EXPECT_EQ(original_bounds, root_window()->bounds()); 373 EXPECT_EQ(original_bounds, root_window()->bounds());
374 EXPECT_FALSE(root_window_mus->GetLocalSurfaceId().is_valid());
296 } 375 }
297 376
298 TEST_F(WindowTreeClientWmTest, TwoInFlightBoundsChangesBothCanceled) { 377 TEST_F(WindowTreeClientWmTest, TwoInFlightBoundsChangesBothCanceled) {
299 const gfx::Rect original_bounds(root_window()->bounds()); 378 const gfx::Rect original_bounds(root_window()->bounds());
300 const gfx::Rect bounds1(gfx::Rect(0, 0, 100, 100)); 379 const gfx::Rect bounds1(gfx::Rect(0, 0, 100, 100));
301 const gfx::Rect bounds2(gfx::Rect(0, 0, 100, 102)); 380 const gfx::Rect bounds2(gfx::Rect(0, 0, 100, 102));
302 root_window()->SetBounds(bounds1); 381 root_window()->SetBounds(bounds1);
303 EXPECT_EQ(bounds1, root_window()->bounds()); 382 EXPECT_EQ(bounds1, root_window()->bounds());
304 383
305 root_window()->SetBounds(bounds2); 384 root_window()->SetBounds(bounds2);
(...skipping 1721 matching lines...) Expand 10 before | Expand all | Expand 10 after
2027 window_tree()->GetEventResult(event_id)); 2106 window_tree()->GetEventResult(event_id));
2028 EXPECT_TRUE(window_delegate1.got_move()); 2107 EXPECT_TRUE(window_delegate1.got_move());
2029 EXPECT_FALSE(window_delegate2.got_move()); 2108 EXPECT_FALSE(window_delegate2.got_move());
2030 gfx::Point transformed_event_location_in_dip(event_location_in_dip.x() + 20, 2109 gfx::Point transformed_event_location_in_dip(event_location_in_dip.x() + 20,
2031 event_location_in_dip.y() + 30); 2110 event_location_in_dip.y() + 30);
2032 EXPECT_EQ(transformed_event_location_in_dip, 2111 EXPECT_EQ(transformed_event_location_in_dip,
2033 window_delegate1.last_event_location()); 2112 window_delegate1.last_event_location());
2034 } 2113 }
2035 2114
2036 } // namespace aura 2115 } // namespace aura
OLDNEW
« no previous file with comments | « ui/aura/mus/window_tree_client.cc ('k') | ui/aura/test/mus/test_window_tree.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698