OLD | NEW |
| (Empty) |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #ifndef COMPONENTS_MUS_PUBLIC_CPP_TESTS_WINDOW_SERVER_TEST_BASE_H_ | |
6 #define COMPONENTS_MUS_PUBLIC_CPP_TESTS_WINDOW_SERVER_TEST_BASE_H_ | |
7 | |
8 #include <memory> | |
9 | |
10 #include "base/macros.h" | |
11 #include "components/mus/public/cpp/tests/window_server_shelltest_base.h" | |
12 #include "components/mus/public/cpp/window_manager_delegate.h" | |
13 #include "components/mus/public/cpp/window_tree_client_delegate.h" | |
14 #include "components/mus/public/interfaces/window_tree.mojom.h" | |
15 #include "components/mus/public/interfaces/window_tree_host.mojom.h" | |
16 #include "services/shell/public/cpp/interface_factory.h" | |
17 | |
18 namespace mus { | |
19 | |
20 // WindowServerTestBase is a base class for use with shell tests that use | |
21 // WindowServer. SetUp() connects to the WindowServer and blocks until OnEmbed() | |
22 // has been invoked. window_manager() can be used to access the WindowServer | |
23 // established as part of SetUp(). | |
24 class WindowServerTestBase | |
25 : public WindowServerShellTestBase, | |
26 public WindowTreeClientDelegate, | |
27 public WindowManagerDelegate, | |
28 public shell::InterfaceFactory<mojom::WindowTreeClient> { | |
29 public: | |
30 WindowServerTestBase(); | |
31 ~WindowServerTestBase() override; | |
32 | |
33 // True if WindowTreeClientDelegate::OnDidDestroyClient() was called. | |
34 bool window_tree_client_destroyed() const { | |
35 return window_tree_client_destroyed_; | |
36 } | |
37 | |
38 // Runs the MessageLoop until QuitRunLoop() is called, or a timeout occurs. | |
39 // Returns true on success. Generally prefer running a RunLoop and | |
40 // explicitly quiting that, but use this for times when that is not possible. | |
41 static bool DoRunLoopWithTimeout() WARN_UNUSED_RESULT; | |
42 | |
43 // Quits a run loop started by DoRunLoopWithTimeout(). Returns true on | |
44 // success, false if a RunLoop isn't running. | |
45 static bool QuitRunLoop() WARN_UNUSED_RESULT; | |
46 | |
47 WindowTreeClient* window_manager() { return window_manager_; } | |
48 WindowManagerClient* window_manager_client() { | |
49 return window_manager_client_; | |
50 } | |
51 | |
52 protected: | |
53 mojom::WindowTreeHost* host() { return host_.get(); } | |
54 WindowTreeClient* most_recent_client() { | |
55 return most_recent_client_; | |
56 } | |
57 | |
58 void set_window_manager_delegate(WindowManagerDelegate* delegate) { | |
59 window_manager_delegate_ = delegate; | |
60 } | |
61 | |
62 // testing::Test: | |
63 void SetUp() override; | |
64 | |
65 // WindowServerShellTestBase: | |
66 bool AcceptConnection(shell::Connection* connection) override; | |
67 | |
68 // WindowTreeClientDelegate: | |
69 void OnEmbed(Window* root) override; | |
70 void OnDidDestroyClient(WindowTreeClient* client) override; | |
71 void OnEventObserved(const ui::Event& event, Window* target) override; | |
72 | |
73 // WindowManagerDelegate: | |
74 void SetWindowManagerClient(WindowManagerClient* client) override; | |
75 bool OnWmSetBounds(Window* window, gfx::Rect* bounds) override; | |
76 bool OnWmSetProperty( | |
77 Window* window, | |
78 const std::string& name, | |
79 std::unique_ptr<std::vector<uint8_t>>* new_data) override; | |
80 Window* OnWmCreateTopLevelWindow( | |
81 std::map<std::string, std::vector<uint8_t>>* properties) override; | |
82 void OnWmClientJankinessChanged(const std::set<Window*>& client_windows, | |
83 bool not_responding) override; | |
84 void OnWmNewDisplay(Window* window, const display::Display& display) override; | |
85 void OnAccelerator(uint32_t id, const ui::Event& event) override; | |
86 | |
87 // InterfaceFactory<WindowTreeClient>: | |
88 void Create(shell::Connection* connection, | |
89 mojo::InterfaceRequest<mojom::WindowTreeClient> request) override; | |
90 | |
91 // Used to receive the most recent window tree client loaded by an embed | |
92 // action. | |
93 WindowTreeClient* most_recent_client_; | |
94 | |
95 private: | |
96 mojom::WindowTreeHostPtr host_; | |
97 | |
98 // The window server connection held by the window manager (app running at | |
99 // the root window). | |
100 WindowTreeClient* window_manager_; | |
101 | |
102 // A test can override the WM-related behaviour by installing its own | |
103 // WindowManagerDelegate during the test. | |
104 WindowManagerDelegate* window_manager_delegate_; | |
105 | |
106 WindowManagerClient* window_manager_client_; | |
107 | |
108 bool window_tree_client_destroyed_; | |
109 | |
110 DISALLOW_COPY_AND_ASSIGN(WindowServerTestBase); | |
111 }; | |
112 | |
113 } // namespace mus | |
114 | |
115 #endif // COMPONENTS_MUS_PUBLIC_CPP_TESTS_WINDOW_SERVER_TEST_BASE_H_ | |
OLD | NEW |