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