| 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 SERVICES_UI_PUBLIC_CPP_TESTS_WINDOW_SERVER_TEST_BASE_H_ | 5 #ifndef SERVICES_UI_PUBLIC_CPP_TESTS_WINDOW_SERVER_TEST_BASE_H_ |
| 6 #define SERVICES_UI_PUBLIC_CPP_TESTS_WINDOW_SERVER_TEST_BASE_H_ | 6 #define SERVICES_UI_PUBLIC_CPP_TESTS_WINDOW_SERVER_TEST_BASE_H_ |
| 7 | 7 |
| 8 #include <memory> | 8 #include <memory> |
| 9 #include <set> |
| 9 | 10 |
| 10 #include "base/macros.h" | 11 #include "base/macros.h" |
| 11 #include "services/shell/public/cpp/interface_factory.h" | 12 #include "services/shell/public/cpp/interface_factory.h" |
| 12 #include "services/ui/public/cpp/tests/window_server_shelltest_base.h" | 13 #include "services/ui/public/cpp/tests/window_server_shelltest_base.h" |
| 13 #include "services/ui/public/cpp/window_manager_delegate.h" | 14 #include "services/ui/public/cpp/window_manager_delegate.h" |
| 14 #include "services/ui/public/cpp/window_tree_client_delegate.h" | 15 #include "services/ui/public/cpp/window_tree_client_delegate.h" |
| 15 #include "services/ui/public/interfaces/window_tree.mojom.h" | 16 #include "services/ui/public/interfaces/window_tree.mojom.h" |
| 16 #include "services/ui/public/interfaces/window_tree_host.mojom.h" | 17 #include "services/ui/public/interfaces/window_tree_host.mojom.h" |
| 17 | 18 |
| 18 namespace ui { | 19 namespace ui { |
| 19 | 20 |
| 20 // WindowServerTestBase is a base class for use with shell tests that use | 21 // WindowServerTestBase is a base class for use with shell tests that use |
| 21 // WindowServer. SetUp() connects to the WindowServer and blocks until OnEmbed() | 22 // WindowServer. SetUp() connects to the WindowServer and blocks until OnEmbed() |
| 22 // has been invoked. window_manager() can be used to access the WindowServer | 23 // has been invoked. window_manager() can be used to access the WindowServer |
| 23 // established as part of SetUp(). | 24 // established as part of SetUp(). |
| 24 class WindowServerTestBase | 25 class WindowServerTestBase |
| 25 : public WindowServerServiceTestBase, | 26 : public WindowServerServiceTestBase, |
| 26 public WindowTreeClientDelegate, | 27 public WindowTreeClientDelegate, |
| 27 public WindowManagerDelegate, | 28 public WindowManagerDelegate, |
| 28 public shell::InterfaceFactory<mojom::WindowTreeClient> { | 29 public shell::InterfaceFactory<mojom::WindowTreeClient> { |
| 29 public: | 30 public: |
| 30 WindowServerTestBase(); | 31 WindowServerTestBase(); |
| 31 ~WindowServerTestBase() override; | 32 ~WindowServerTestBase() override; |
| 32 | 33 |
| 33 // True if WindowTreeClientDelegate::OnDidDestroyClient() was called. | 34 // True if WindowTreeClientDelegate::OnLostConnection() was called. |
| 34 bool window_tree_client_destroyed() const { | 35 bool window_tree_client_lost_connection() const { |
| 35 return window_tree_client_destroyed_; | 36 return window_tree_client_lost_connection_; |
| 36 } | 37 } |
| 37 | 38 |
| 38 // Runs the MessageLoop until QuitRunLoop() is called, or a timeout occurs. | 39 // Runs the MessageLoop until QuitRunLoop() is called, or a timeout occurs. |
| 39 // Returns true on success. Generally prefer running a RunLoop and | 40 // 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 // explicitly quiting that, but use this for times when that is not possible. |
| 41 static bool DoRunLoopWithTimeout() WARN_UNUSED_RESULT; | 42 static bool DoRunLoopWithTimeout() WARN_UNUSED_RESULT; |
| 42 | 43 |
| 43 // Quits a run loop started by DoRunLoopWithTimeout(). Returns true on | 44 // Quits a run loop started by DoRunLoopWithTimeout(). Returns true on |
| 44 // success, false if a RunLoop isn't running. | 45 // success, false if a RunLoop isn't running. |
| 45 static bool QuitRunLoop() WARN_UNUSED_RESULT; | 46 static bool QuitRunLoop() WARN_UNUSED_RESULT; |
| 46 | 47 |
| 47 WindowTreeClient* window_manager() { return window_manager_; } | 48 WindowTreeClient* window_manager() { return window_manager_; } |
| 48 WindowManagerClient* window_manager_client() { | 49 WindowManagerClient* window_manager_client() { |
| 49 return window_manager_client_; | 50 return window_manager_client_; |
| 50 } | 51 } |
| 51 | 52 |
| 52 protected: | 53 protected: |
| 53 mojom::WindowTreeHost* host() { return host_.get(); } | 54 mojom::WindowTreeHost* host() { return host_.get(); } |
| 54 WindowTreeClient* most_recent_client() { | 55 WindowTreeClient* most_recent_client() { |
| 55 return most_recent_client_; | 56 return most_recent_client_; |
| 56 } | 57 } |
| 57 | 58 |
| 58 void set_window_manager_delegate(WindowManagerDelegate* delegate) { | 59 void set_window_manager_delegate(WindowManagerDelegate* delegate) { |
| 59 window_manager_delegate_ = delegate; | 60 window_manager_delegate_ = delegate; |
| 60 } | 61 } |
| 61 | 62 |
| 63 // Cleans up internal state then deletes |client|. |
| 64 void DeleteWindowTreeClient(ui::WindowTreeClient* client); |
| 65 |
| 62 // testing::Test: | 66 // testing::Test: |
| 63 void SetUp() override; | 67 void SetUp() override; |
| 64 | 68 |
| 65 // WindowServerServiceTestBase: | 69 // WindowServerServiceTestBase: |
| 66 bool OnConnect(const shell::Identity& remote_identity, | 70 bool OnConnect(const shell::Identity& remote_identity, |
| 67 shell::InterfaceRegistry* registry) override; | 71 shell::InterfaceRegistry* registry) override; |
| 68 | 72 |
| 69 // WindowTreeClientDelegate: | 73 // WindowTreeClientDelegate: |
| 70 void OnEmbed(Window* root) override; | 74 void OnEmbed(Window* root) override; |
| 71 void OnDidDestroyClient(WindowTreeClient* client) override; | 75 void OnLostConnection(WindowTreeClient* client) override; |
| 76 void OnEmbedRootDestroyed(Window* root) override; |
| 72 void OnPointerEventObserved(const ui::PointerEvent& event, | 77 void OnPointerEventObserved(const ui::PointerEvent& event, |
| 73 Window* target) override; | 78 Window* target) override; |
| 74 | 79 |
| 75 // WindowManagerDelegate: | 80 // WindowManagerDelegate: |
| 76 void SetWindowManagerClient(WindowManagerClient* client) override; | 81 void SetWindowManagerClient(WindowManagerClient* client) override; |
| 77 bool OnWmSetBounds(Window* window, gfx::Rect* bounds) override; | 82 bool OnWmSetBounds(Window* window, gfx::Rect* bounds) override; |
| 78 bool OnWmSetProperty( | 83 bool OnWmSetProperty( |
| 79 Window* window, | 84 Window* window, |
| 80 const std::string& name, | 85 const std::string& name, |
| 81 std::unique_ptr<std::vector<uint8_t>>* new_data) override; | 86 std::unique_ptr<std::vector<uint8_t>>* new_data) override; |
| (...skipping 14 matching lines...) Expand all Loading... |
| 96 void Create(const shell::Identity& remote_identity, | 101 void Create(const shell::Identity& remote_identity, |
| 97 mojo::InterfaceRequest<mojom::WindowTreeClient> request) override; | 102 mojo::InterfaceRequest<mojom::WindowTreeClient> request) override; |
| 98 | 103 |
| 99 // Used to receive the most recent window tree client loaded by an embed | 104 // Used to receive the most recent window tree client loaded by an embed |
| 100 // action. | 105 // action. |
| 101 WindowTreeClient* most_recent_client_; | 106 WindowTreeClient* most_recent_client_; |
| 102 | 107 |
| 103 private: | 108 private: |
| 104 mojom::WindowTreeHostPtr host_; | 109 mojom::WindowTreeHostPtr host_; |
| 105 | 110 |
| 111 std::set<std::unique_ptr<WindowTreeClient>> window_tree_clients_; |
| 112 |
| 106 // The window server connection held by the window manager (app running at | 113 // The window server connection held by the window manager (app running at |
| 107 // the root window). | 114 // the root window). |
| 108 WindowTreeClient* window_manager_; | 115 WindowTreeClient* window_manager_; |
| 109 | 116 |
| 110 // A test can override the WM-related behaviour by installing its own | 117 // A test can override the WM-related behaviour by installing its own |
| 111 // WindowManagerDelegate during the test. | 118 // WindowManagerDelegate during the test. |
| 112 WindowManagerDelegate* window_manager_delegate_; | 119 WindowManagerDelegate* window_manager_delegate_; |
| 113 | 120 |
| 114 WindowManagerClient* window_manager_client_; | 121 WindowManagerClient* window_manager_client_; |
| 115 | 122 |
| 116 bool window_tree_client_destroyed_; | 123 bool window_tree_client_lost_connection_ = false; |
| 117 | 124 |
| 118 DISALLOW_COPY_AND_ASSIGN(WindowServerTestBase); | 125 DISALLOW_COPY_AND_ASSIGN(WindowServerTestBase); |
| 119 }; | 126 }; |
| 120 | 127 |
| 121 } // namespace ui | 128 } // namespace ui |
| 122 | 129 |
| 123 #endif // SERVICES_UI_PUBLIC_CPP_TESTS_WINDOW_SERVER_TEST_BASE_H_ | 130 #endif // SERVICES_UI_PUBLIC_CPP_TESTS_WINDOW_SERVER_TEST_BASE_H_ |
| OLD | NEW |