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

Side by Side Diff: services/ui/ws/window_tree_client_unittest.cc

Issue 2511883006: Mojo C++ bindings: switch services/ui/public/interfaces mojom target to use STL types. (Closed)
Patch Set: . Created 4 years 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 | « services/ui/ws/window_tree.cc ('k') | services/ui/ws/window_tree_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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 <stddef.h> 5 #include <stddef.h>
6 #include <stdint.h> 6 #include <stdint.h>
7 7
8 #include "base/bind.h" 8 #include "base/bind.h"
9 #include "base/macros.h" 9 #include "base/macros.h"
10 #include "base/message_loop/message_loop.h" 10 #include "base/message_loop/message_loop.h"
11 #include "base/run_loop.h" 11 #include "base/run_loop.h"
12 #include "base/strings/stringprintf.h" 12 #include "base/strings/stringprintf.h"
13 #include "mojo/public/cpp/bindings/associated_binding.h" 13 #include "mojo/public/cpp/bindings/associated_binding.h"
14 #include "mojo/public/cpp/bindings/binding.h" 14 #include "mojo/public/cpp/bindings/binding.h"
15 #include "services/service_manager/public/cpp/interface_factory.h" 15 #include "services/service_manager/public/cpp/interface_factory.h"
16 #include "services/service_manager/public/cpp/interface_registry.h" 16 #include "services/service_manager/public/cpp/interface_registry.h"
17 #include "services/service_manager/public/cpp/service_test.h" 17 #include "services/service_manager/public/cpp/service_test.h"
18 #include "services/ui/public/cpp/tests/window_server_shelltest_base.h" 18 #include "services/ui/public/cpp/tests/window_server_shelltest_base.h"
19 #include "services/ui/public/interfaces/constants.mojom.h" 19 #include "services/ui/public/interfaces/constants.mojom.h"
20 #include "services/ui/public/interfaces/window_tree.mojom.h" 20 #include "services/ui/public/interfaces/window_tree.mojom.h"
21 #include "services/ui/public/interfaces/window_tree_host.mojom.h" 21 #include "services/ui/public/interfaces/window_tree_host.mojom.h"
22 #include "services/ui/ws/ids.h" 22 #include "services/ui/ws/ids.h"
23 #include "services/ui/ws/test_change_tracker.h" 23 #include "services/ui/ws/test_change_tracker.h"
24 24
25 using mojo::Array;
26 using service_manager::Connection; 25 using service_manager::Connection;
27 using mojo::InterfaceRequest; 26 using mojo::InterfaceRequest;
28 using service_manager::Service; 27 using service_manager::Service;
29 using mojo::String;
30 using ui::mojom::WindowDataPtr; 28 using ui::mojom::WindowDataPtr;
31 using ui::mojom::WindowTree; 29 using ui::mojom::WindowTree;
32 using ui::mojom::WindowTreeClient; 30 using ui::mojom::WindowTreeClient;
33 31
34 namespace ui { 32 namespace ui {
35 namespace ws { 33 namespace ws {
36 namespace test { 34 namespace test {
37 35
38 namespace { 36 namespace {
39 37
40 // Creates an id used for transport from the specified parameters. 38 // Creates an id used for transport from the specified parameters.
41 Id BuildWindowId(ClientSpecificId client_id, 39 Id BuildWindowId(ClientSpecificId client_id,
42 ClientSpecificId window_id) { 40 ClientSpecificId window_id) {
43 return (client_id << 16) | window_id; 41 return (client_id << 16) | window_id;
44 } 42 }
45 43
46 // Callback function from WindowTree functions. 44 // Callback function from WindowTree functions.
47 // ---------------------------------- 45 // ----------------------------------
48 46
49 void WindowTreeResultCallback(base::RunLoop* run_loop, 47 void WindowTreeResultCallback(base::RunLoop* run_loop,
50 std::vector<TestWindow>* windows, 48 std::vector<TestWindow>* windows,
51 Array<WindowDataPtr> results) { 49 std::vector<WindowDataPtr> results) {
52 WindowDatasToTestWindows(results, windows); 50 WindowDatasToTestWindows(results, windows);
53 run_loop->Quit(); 51 run_loop->Quit();
54 } 52 }
55 53
56 void EmbedCallbackImpl(base::RunLoop* run_loop, 54 void EmbedCallbackImpl(base::RunLoop* run_loop,
57 bool* result_cache, 55 bool* result_cache,
58 bool result) { 56 bool result) {
59 *result_cache = result; 57 *result_cache = result;
60 run_loop->Quit(); 58 run_loop->Quit();
61 } 59 }
62 60
63 // ----------------------------------------------------------------------------- 61 // -----------------------------------------------------------------------------
64 62
65 bool EmbedUrl(service_manager::Connector* connector, 63 bool EmbedUrl(service_manager::Connector* connector,
66 WindowTree* tree, 64 WindowTree* tree,
67 const String& url, 65 const std::string& url,
68 Id root_id) { 66 Id root_id) {
69 bool result = false; 67 bool result = false;
70 base::RunLoop run_loop; 68 base::RunLoop run_loop;
71 { 69 {
72 mojom::WindowTreeClientPtr client; 70 mojom::WindowTreeClientPtr client;
73 connector->ConnectToInterface(url.get(), &client); 71 connector->ConnectToInterface(url, &client);
74 const uint32_t embed_flags = 0; 72 const uint32_t embed_flags = 0;
75 tree->Embed(root_id, std::move(client), embed_flags, 73 tree->Embed(root_id, std::move(client), embed_flags,
76 base::Bind(&EmbedCallbackImpl, &run_loop, &result)); 74 base::Bind(&EmbedCallbackImpl, &run_loop, &result));
77 } 75 }
78 run_loop.Run(); 76 run_loop.Run();
79 return result; 77 return result;
80 } 78 }
81 79
82 bool Embed(WindowTree* tree, Id root_id, mojom::WindowTreeClientPtr client) { 80 bool Embed(WindowTree* tree, Id root_id, mojom::WindowTreeClientPtr client) {
83 bool result = false; 81 bool result = false;
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
213 0; 211 0;
214 } 212 }
215 213
216 Id NewWindow(ClientSpecificId window_id) { 214 Id NewWindow(ClientSpecificId window_id) {
217 return NewWindowWithCompleteId(BuildWindowId(client_id_, window_id)); 215 return NewWindowWithCompleteId(BuildWindowId(client_id_, window_id));
218 } 216 }
219 217
220 // Generally you want NewWindow(), but use this if you need to test given 218 // Generally you want NewWindow(), but use this if you need to test given
221 // a complete window id (NewWindow() ors with the client id). 219 // a complete window id (NewWindow() ors with the client id).
222 Id NewWindowWithCompleteId(Id id) { 220 Id NewWindowWithCompleteId(Id id) {
223 mojo::Map<mojo::String, mojo::Array<uint8_t>> properties; 221 std::unordered_map<std::string, std::vector<uint8_t>> properties;
224 const uint32_t change_id = GetAndAdvanceChangeId(); 222 const uint32_t change_id = GetAndAdvanceChangeId();
225 tree()->NewWindow(change_id, id, std::move(properties)); 223 tree()->NewWindow(change_id, id, std::move(properties));
226 return WaitForChangeCompleted(change_id) ? id : 0; 224 return WaitForChangeCompleted(change_id) ? id : 0;
227 } 225 }
228 226
229 bool SetWindowProperty(Id window_id, 227 bool SetWindowProperty(Id window_id,
230 const std::string& name, 228 const std::string& name,
231 const std::vector<uint8_t>* data) { 229 const std::vector<uint8_t>* data) {
232 Array<uint8_t> mojo_data(nullptr); 230 base::Optional<std::vector<uint8_t>> mojo_data;
233 if (data) 231 if (data)
234 mojo_data = Array<uint8_t>::From(*data); 232 mojo_data.emplace(*data);
235 const uint32_t change_id = GetAndAdvanceChangeId(); 233 const uint32_t change_id = GetAndAdvanceChangeId();
236 tree()->SetWindowProperty(change_id, window_id, name, std::move(mojo_data)); 234 tree()->SetWindowProperty(change_id, window_id, name, mojo_data);
237 return WaitForChangeCompleted(change_id); 235 return WaitForChangeCompleted(change_id);
238 } 236 }
239 237
240 bool SetPredefinedCursor(Id window_id, mojom::Cursor cursor) { 238 bool SetPredefinedCursor(Id window_id, mojom::Cursor cursor) {
241 const uint32_t change_id = GetAndAdvanceChangeId(); 239 const uint32_t change_id = GetAndAdvanceChangeId();
242 tree()->SetPredefinedCursor(change_id, window_id, cursor); 240 tree()->SetPredefinedCursor(change_id, window_id, cursor);
243 return WaitForChangeCompleted(change_id); 241 return WaitForChangeCompleted(change_id);
244 } 242 }
245 243
246 bool SetWindowVisibility(Id window_id, bool visible) { 244 bool SetWindowVisibility(Id window_id, bool visible) {
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
309 // The bounds of the root may change during startup on Android at random 307 // The bounds of the root may change during startup on Android at random
310 // times. As this doesn't matter, and shouldn't impact test exepctations, 308 // times. As this doesn't matter, and shouldn't impact test exepctations,
311 // it is ignored. 309 // it is ignored.
312 if (window_id == root_window_id_ && !track_root_bounds_changes_) 310 if (window_id == root_window_id_ && !track_root_bounds_changes_)
313 return; 311 return;
314 tracker()->OnWindowBoundsChanged(window_id, old_bounds, new_bounds); 312 tracker()->OnWindowBoundsChanged(window_id, old_bounds, new_bounds);
315 } 313 }
316 void OnClientAreaChanged( 314 void OnClientAreaChanged(
317 uint32_t window_id, 315 uint32_t window_id,
318 const gfx::Insets& new_client_area, 316 const gfx::Insets& new_client_area,
319 mojo::Array<gfx::Rect> new_additional_client_areas) override {} 317 const std::vector<gfx::Rect>& new_additional_client_areas) override {}
320 void OnTransientWindowAdded(uint32_t window_id, 318 void OnTransientWindowAdded(uint32_t window_id,
321 uint32_t transient_window_id) override { 319 uint32_t transient_window_id) override {
322 tracker()->OnTransientWindowAdded(window_id, transient_window_id); 320 tracker()->OnTransientWindowAdded(window_id, transient_window_id);
323 } 321 }
324 void OnTransientWindowRemoved(uint32_t window_id, 322 void OnTransientWindowRemoved(uint32_t window_id,
325 uint32_t transient_window_id) override { 323 uint32_t transient_window_id) override {
326 tracker()->OnTransientWindowRemoved(window_id, transient_window_id); 324 tracker()->OnTransientWindowRemoved(window_id, transient_window_id);
327 } 325 }
328 void OnWindowHierarchyChanged(Id window, 326 void OnWindowHierarchyChanged(Id window,
329 Id old_parent, 327 Id old_parent,
330 Id new_parent, 328 Id new_parent,
331 Array<WindowDataPtr> windows) override { 329 std::vector<WindowDataPtr> windows) override {
332 tracker()->OnWindowHierarchyChanged(window, old_parent, new_parent, 330 tracker()->OnWindowHierarchyChanged(window, old_parent, new_parent,
333 std::move(windows)); 331 std::move(windows));
334 } 332 }
335 void OnWindowReordered(Id window_id, 333 void OnWindowReordered(Id window_id,
336 Id relative_window_id, 334 Id relative_window_id,
337 mojom::OrderDirection direction) override { 335 mojom::OrderDirection direction) override {
338 tracker()->OnWindowReordered(window_id, relative_window_id, direction); 336 tracker()->OnWindowReordered(window_id, relative_window_id, direction);
339 } 337 }
340 void OnWindowDeleted(Id window) override { 338 void OnWindowDeleted(Id window) override {
341 tracker()->OnWindowDeleted(window); 339 tracker()->OnWindowDeleted(window);
(...skipping 15 matching lines...) Expand all
357 bool matches_pointer_watcher) override { 355 bool matches_pointer_watcher) override {
358 // Ack input events to clear the state on the server. These can be received 356 // Ack input events to clear the state on the server. These can be received
359 // during test startup. X11Window::DispatchEvent sends a synthetic move 357 // during test startup. X11Window::DispatchEvent sends a synthetic move
360 // event to notify of entry. 358 // event to notify of entry.
361 tree()->OnWindowInputEventAck(event_id, mojom::EventResult::HANDLED); 359 tree()->OnWindowInputEventAck(event_id, mojom::EventResult::HANDLED);
362 // Don't log input events as none of the tests care about them and they 360 // Don't log input events as none of the tests care about them and they
363 // may come in at random points. 361 // may come in at random points.
364 } 362 }
365 void OnPointerEventObserved(std::unique_ptr<ui::Event>, 363 void OnPointerEventObserved(std::unique_ptr<ui::Event>,
366 uint32_t window_id) override {} 364 uint32_t window_id) override {}
367 void OnWindowSharedPropertyChanged(uint32_t window, 365 void OnWindowSharedPropertyChanged(
368 const String& name, 366 uint32_t window,
369 Array<uint8_t> new_data) override { 367 const std::string& name,
370 tracker_.OnWindowSharedPropertyChanged(window, name, std::move(new_data)); 368 const base::Optional<std::vector<uint8_t>>& new_data) override {
369 tracker_.OnWindowSharedPropertyChanged(window, name, new_data);
371 } 370 }
372 // TODO(sky): add testing coverage. 371 // TODO(sky): add testing coverage.
373 void OnWindowFocused(uint32_t focused_window_id) override {} 372 void OnWindowFocused(uint32_t focused_window_id) override {}
374 void OnWindowPredefinedCursorChanged(uint32_t window_id, 373 void OnWindowPredefinedCursorChanged(uint32_t window_id,
375 mojom::Cursor cursor_id) override { 374 mojom::Cursor cursor_id) override {
376 tracker_.OnWindowPredefinedCursorChanged(window_id, cursor_id); 375 tracker_.OnWindowPredefinedCursorChanged(window_id, cursor_id);
377 } 376 }
378 377
379 void OnDragDropStart( 378 void OnDragDropStart(
380 mojo::Map<mojo::String, mojo::Array<uint8_t>> drag_data) override { 379 const std::unordered_map<std::string, std::vector<uint8_t>>& drag_data)
380 override {
381 NOTIMPLEMENTED(); 381 NOTIMPLEMENTED();
382 } 382 }
383 383
384 void OnWindowSurfaceChanged(Id window_id, 384 void OnWindowSurfaceChanged(Id window_id,
385 const cc::SurfaceId& surface_id, 385 const cc::SurfaceId& surface_id,
386 const gfx::Size& frame_size, 386 const gfx::Size& frame_size,
387 float device_scale_factor) override { 387 float device_scale_factor) override {
388 tracker_.OnWindowSurfaceChanged(window_id, surface_id, frame_size, 388 tracker_.OnWindowSurfaceChanged(window_id, surface_id, frame_size,
389 device_scale_factor); 389 device_scale_factor);
390 } 390 }
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
445 } 445 }
446 void WmDisplayRemoved(int64_t display_id) override { NOTIMPLEMENTED(); } 446 void WmDisplayRemoved(int64_t display_id) override { NOTIMPLEMENTED(); }
447 void WmDisplayModified(const display::Display& display) override { 447 void WmDisplayModified(const display::Display& display) override {
448 NOTIMPLEMENTED(); 448 NOTIMPLEMENTED();
449 } 449 }
450 void WmSetBounds(uint32_t change_id, 450 void WmSetBounds(uint32_t change_id,
451 uint32_t window_id, 451 uint32_t window_id,
452 const gfx::Rect& bounds) override { 452 const gfx::Rect& bounds) override {
453 window_manager_client_->WmResponse(change_id, false); 453 window_manager_client_->WmResponse(change_id, false);
454 } 454 }
455 void WmSetProperty(uint32_t change_id, 455 void WmSetProperty(
456 uint32_t window_id, 456 uint32_t change_id,
457 const mojo::String& name, 457 uint32_t window_id,
458 mojo::Array<uint8_t> value) override { 458 const std::string& name,
459 const base::Optional<std::vector<uint8_t>>& value) override {
459 window_manager_client_->WmResponse(change_id, false); 460 window_manager_client_->WmResponse(change_id, false);
460 } 461 }
461 void WmCreateTopLevelWindow( 462 void WmCreateTopLevelWindow(
462 uint32_t change_id, 463 uint32_t change_id,
463 ClientSpecificId requesting_client_id, 464 ClientSpecificId requesting_client_id,
464 mojo::Map<mojo::String, mojo::Array<uint8_t>> properties) override { 465 const std::unordered_map<std::string, std::vector<uint8_t>>& properties)
466 override {
465 NOTIMPLEMENTED(); 467 NOTIMPLEMENTED();
466 } 468 }
467 void WmClientJankinessChanged(ClientSpecificId client_id, 469 void WmClientJankinessChanged(ClientSpecificId client_id,
468 bool janky) override { 470 bool janky) override {
469 NOTIMPLEMENTED(); 471 NOTIMPLEMENTED();
470 } 472 }
471 void WmPerformMoveLoop(uint32_t change_id, 473 void WmPerformMoveLoop(uint32_t change_id,
472 uint32_t window_id, 474 uint32_t window_id,
473 mojom::MoveLoopSource source, 475 mojom::MoveLoopSource source,
474 const gfx::Point& cursor_location) override { 476 const gfx::Point& cursor_location) override {
(...skipping 1737 matching lines...) Expand 10 before | Expand all | Expand 10 after
2212 2214
2213 // TODO(sky): make sure coverage of what was 2215 // TODO(sky): make sure coverage of what was
2214 // WindowManagerTest.SecondEmbedRoot_InitService and 2216 // WindowManagerTest.SecondEmbedRoot_InitService and
2215 // WindowManagerTest.MultipleEmbedRootsBeforeWTHReady gets added to window 2217 // WindowManagerTest.MultipleEmbedRootsBeforeWTHReady gets added to window
2216 // manager 2218 // manager
2217 // tests. 2219 // tests.
2218 2220
2219 } // namespace test 2221 } // namespace test
2220 } // namespace ws 2222 } // namespace ws
2221 } // namespace ui 2223 } // namespace ui
OLDNEW
« no previous file with comments | « services/ui/ws/window_tree.cc ('k') | services/ui/ws/window_tree_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698