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

Side by Side Diff: services/ui/ws/test_utils.h

Issue 2326203002: services/ui: Add WindowServerTestHelper. (Closed)
Patch Set: self nit Created 4 years, 3 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 | « services/ui/ws/display_unittest.cc ('k') | services/ui/ws/test_utils.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 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 #ifndef SERVICES_UI_WS_TEST_UTILS_H_ 5 #ifndef SERVICES_UI_WS_TEST_UTILS_H_
6 #define SERVICES_UI_WS_TEST_UTILS_H_ 6 #define SERVICES_UI_WS_TEST_UTILS_H_
7 7
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <memory> 10 #include <memory>
(...skipping 487 matching lines...) Expand 10 before | Expand all | Expand 10 after
498 bool got_on_no_more_displays_ = false; 498 bool got_on_no_more_displays_ = false;
499 // All TestWindowTreeBinding objects created via CreateWindowTreeBinding. 499 // All TestWindowTreeBinding objects created via CreateWindowTreeBinding.
500 // These are owned by the corresponding WindowTree. 500 // These are owned by the corresponding WindowTree.
501 std::vector<TestWindowTreeBinding*> bindings_; 501 std::vector<TestWindowTreeBinding*> bindings_;
502 502
503 DISALLOW_COPY_AND_ASSIGN(TestWindowServerDelegate); 503 DISALLOW_COPY_AND_ASSIGN(TestWindowServerDelegate);
504 }; 504 };
505 505
506 // ----------------------------------------------------------------------------- 506 // -----------------------------------------------------------------------------
507 507
508 // Helper class which creates and sets up the necessary objects for tests that
509 // use the WindowServer.
510 class WindowServerTestHelper {
511 public:
512 WindowServerTestHelper();
513 ~WindowServerTestHelper();
514
515 WindowServer* window_server() { return window_server_.get(); }
516 int32_t cursor_id() const { return cursor_id_; }
517
518 TestWindowServerDelegate* window_server_delegate() {
519 return &window_server_delegate_;
520 }
521 base::MessageLoop* message_loop() { return &message_loop_; }
522
523 private:
524 int32_t cursor_id_;
525 TestPlatformDisplayFactory platform_display_factory_;
526 TestWindowServerDelegate window_server_delegate_;
527 std::unique_ptr<WindowServer> window_server_;
528 base::MessageLoop message_loop_;
529
530 DISALLOW_COPY_AND_ASSIGN(WindowServerTestHelper);
531 };
532
533 // -----------------------------------------------------------------------------
534
508 // Helper class which owns all of the necessary objects to test event targeting 535 // Helper class which owns all of the necessary objects to test event targeting
509 // of ServerWindow objects. 536 // of ServerWindow objects.
510 class WindowEventTargetingHelper { 537 class WindowEventTargetingHelper {
511 public: 538 public:
512 WindowEventTargetingHelper(); 539 WindowEventTargetingHelper();
513 ~WindowEventTargetingHelper(); 540 ~WindowEventTargetingHelper();
514 541
515 // Creates |window| as an embeded window of the primary tree. This window is a 542 // Creates |window| as an embeded window of the primary tree. This window is a
516 // root window of its own tree, with bounds |window_bounds|. The bounds of the 543 // root window of its own tree, with bounds |window_bounds|. The bounds of the
517 // root window of |display_| are defined by |root_window_bounds|. 544 // root window of |display_| are defined by |root_window_bounds|.
518 ServerWindow* CreatePrimaryTree(const gfx::Rect& root_window_bounds, 545 ServerWindow* CreatePrimaryTree(const gfx::Rect& root_window_bounds,
519 const gfx::Rect& window_bounds); 546 const gfx::Rect& window_bounds);
520 // Creates a secondary tree, embedded as a child of |embed_window|. The 547 // Creates a secondary tree, embedded as a child of |embed_window|. The
521 // resulting |window| is setup for event targeting, with bounds 548 // resulting |window| is setup for event targeting, with bounds
522 // |window_bounds|. 549 // |window_bounds|.
523 void CreateSecondaryTree(ServerWindow* embed_window, 550 void CreateSecondaryTree(ServerWindow* embed_window,
524 const gfx::Rect& window_bounds, 551 const gfx::Rect& window_bounds,
525 TestWindowTreeClient** out_client, 552 TestWindowTreeClient** out_client,
526 WindowTree** window_tree, 553 WindowTree** window_tree,
527 ServerWindow** window); 554 ServerWindow** window);
528 // Sets the task runner for |message_loop_| 555 // Sets the task runner for |message_loop_|
529 void SetTaskRunner(scoped_refptr<base::SingleThreadTaskRunner> task_runner); 556 void SetTaskRunner(scoped_refptr<base::SingleThreadTaskRunner> task_runner);
530 557
531 int32_t cursor_id() { return cursor_id_; } 558 int32_t cursor_id() const { return ws_test_helper_.cursor_id(); }
532 Display* display() { return display_; } 559 Display* display() { return display_; }
533 TestWindowTreeBinding* last_binding() { 560 TestWindowTreeBinding* last_binding() {
534 return window_server_delegate_.last_binding(); 561 return ws_test_helper_.window_server_delegate()->last_binding();
535 } 562 }
536 TestWindowTreeClient* last_window_tree_client() { 563 TestWindowTreeClient* last_window_tree_client() {
537 return window_server_delegate_.last_client(); 564 return ws_test_helper_.window_server_delegate()->last_client();
538 } 565 }
539 TestWindowTreeClient* wm_client() { return wm_client_; } 566 TestWindowTreeClient* wm_client() { return wm_client_; }
540 WindowServer* window_server() { return window_server_.get(); } 567 WindowServer* window_server() { return ws_test_helper_.window_server(); }
541 568
542 private: 569 private:
570 WindowServerTestHelper ws_test_helper_;
543 // TestWindowTreeClient that is used for the WM client. Owned by 571 // TestWindowTreeClient that is used for the WM client. Owned by
544 // |window_server_delegate_| 572 // |window_server_delegate_|
545 TestWindowTreeClient* wm_client_; 573 TestWindowTreeClient* wm_client_;
546 int32_t cursor_id_;
547 TestPlatformDisplayFactory platform_display_factory_;
548 TestWindowServerDelegate window_server_delegate_;
549 // Owned by WindowServer 574 // Owned by WindowServer
550 TestDisplayBinding* display_binding_; 575 TestDisplayBinding* display_binding_;
551 // Owned by WindowServer's DisplayManager. 576 // Owned by WindowServer's DisplayManager.
552 Display* display_; 577 Display* display_;
553 scoped_refptr<SurfacesState> surfaces_state_; 578 scoped_refptr<SurfacesState> surfaces_state_;
554 std::unique_ptr<WindowServer> window_server_;
555 // Needed to Bind to |wm_client_|
556 base::MessageLoop message_loop_;
557 579
558 DISALLOW_COPY_AND_ASSIGN(WindowEventTargetingHelper); 580 DISALLOW_COPY_AND_ASSIGN(WindowEventTargetingHelper);
559 }; 581 };
560 582
561 // ----------------------------------------------------------------------------- 583 // -----------------------------------------------------------------------------
562 584
563 // Returns the first and only root of |tree|. If |tree| has zero or more than 585 // Returns the first and only root of |tree|. If |tree| has zero or more than
564 // one root returns null. 586 // one root returns null.
565 ServerWindow* FirstRoot(WindowTree* tree); 587 ServerWindow* FirstRoot(WindowTree* tree);
566 588
(...skipping 10 matching lines...) Expand all
577 ServerWindow* NewWindowInTree(WindowTree* tree, ClientWindowId* client_id); 599 ServerWindow* NewWindowInTree(WindowTree* tree, ClientWindowId* client_id);
578 ServerWindow* NewWindowInTreeWithParent(WindowTree* tree, 600 ServerWindow* NewWindowInTreeWithParent(WindowTree* tree,
579 ServerWindow* parent, 601 ServerWindow* parent,
580 ClientWindowId* client_id); 602 ClientWindowId* client_id);
581 603
582 } // namespace test 604 } // namespace test
583 } // namespace ws 605 } // namespace ws
584 } // namespace ui 606 } // namespace ui
585 607
586 #endif // SERVICES_UI_WS_TEST_UTILS_H_ 608 #endif // SERVICES_UI_WS_TEST_UTILS_H_
OLDNEW
« no previous file with comments | « services/ui/ws/display_unittest.cc ('k') | services/ui/ws/test_utils.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698