Chromium Code Reviews| 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 // Deletes a WindowTreeClient. This cleans up internal state and then deletes | |
| 64 // its. | |
|
sadrul
2016/09/02 17:04:15
incomplete?
sky
2016/09/06 17:15:42
Done.
| |
| 65 void DeleteWindowTreeClient(ui::WindowTreeClient* client); | |
| 66 | |
| 62 // testing::Test: | 67 // testing::Test: |
| 63 void SetUp() override; | 68 void SetUp() override; |
| 64 | 69 |
| 65 // WindowServerServiceTestBase: | 70 // WindowServerServiceTestBase: |
| 66 bool OnConnect(const shell::Identity& remote_identity, | 71 bool OnConnect(const shell::Identity& remote_identity, |
| 67 shell::InterfaceRegistry* registry) override; | 72 shell::InterfaceRegistry* registry) override; |
| 68 | 73 |
| 69 // WindowTreeClientDelegate: | 74 // WindowTreeClientDelegate: |
| 70 void OnEmbed(Window* root) override; | 75 void OnEmbed(Window* root) override; |
| 71 void OnDidDestroyClient(WindowTreeClient* client) override; | 76 void OnLostConnection(WindowTreeClient* client) override; |
| 77 void OnEmbedRootDestroyed(Window* root) override; | |
| 72 void OnPointerEventObserved(const ui::PointerEvent& event, | 78 void OnPointerEventObserved(const ui::PointerEvent& event, |
| 73 Window* target) override; | 79 Window* target) override; |
| 74 | 80 |
| 75 // WindowManagerDelegate: | 81 // WindowManagerDelegate: |
| 76 void SetWindowManagerClient(WindowManagerClient* client) override; | 82 void SetWindowManagerClient(WindowManagerClient* client) override; |
| 77 bool OnWmSetBounds(Window* window, gfx::Rect* bounds) override; | 83 bool OnWmSetBounds(Window* window, gfx::Rect* bounds) override; |
| 78 bool OnWmSetProperty( | 84 bool OnWmSetProperty( |
| 79 Window* window, | 85 Window* window, |
| 80 const std::string& name, | 86 const std::string& name, |
| 81 std::unique_ptr<std::vector<uint8_t>>* new_data) override; | 87 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, | 102 void Create(const shell::Identity& remote_identity, |
| 97 mojo::InterfaceRequest<mojom::WindowTreeClient> request) override; | 103 mojo::InterfaceRequest<mojom::WindowTreeClient> request) override; |
| 98 | 104 |
| 99 // Used to receive the most recent window tree client loaded by an embed | 105 // Used to receive the most recent window tree client loaded by an embed |
| 100 // action. | 106 // action. |
| 101 WindowTreeClient* most_recent_client_; | 107 WindowTreeClient* most_recent_client_; |
| 102 | 108 |
| 103 private: | 109 private: |
| 104 mojom::WindowTreeHostPtr host_; | 110 mojom::WindowTreeHostPtr host_; |
| 105 | 111 |
| 112 std::set<std::unique_ptr<WindowTreeClient>> window_tree_clients_; | |
| 113 | |
| 106 // The window server connection held by the window manager (app running at | 114 // The window server connection held by the window manager (app running at |
| 107 // the root window). | 115 // the root window). |
| 108 WindowTreeClient* window_manager_; | 116 WindowTreeClient* window_manager_; |
| 109 | 117 |
| 110 // A test can override the WM-related behaviour by installing its own | 118 // A test can override the WM-related behaviour by installing its own |
| 111 // WindowManagerDelegate during the test. | 119 // WindowManagerDelegate during the test. |
| 112 WindowManagerDelegate* window_manager_delegate_; | 120 WindowManagerDelegate* window_manager_delegate_; |
| 113 | 121 |
| 114 WindowManagerClient* window_manager_client_; | 122 WindowManagerClient* window_manager_client_; |
| 115 | 123 |
| 116 bool window_tree_client_destroyed_; | 124 bool window_tree_client_lost_connection_ = false; |
| 117 | 125 |
| 118 DISALLOW_COPY_AND_ASSIGN(WindowServerTestBase); | 126 DISALLOW_COPY_AND_ASSIGN(WindowServerTestBase); |
| 119 }; | 127 }; |
| 120 | 128 |
| 121 } // namespace ui | 129 } // namespace ui |
| 122 | 130 |
| 123 #endif // SERVICES_UI_PUBLIC_CPP_TESTS_WINDOW_SERVER_TEST_BASE_H_ | 131 #endif // SERVICES_UI_PUBLIC_CPP_TESTS_WINDOW_SERVER_TEST_BASE_H_ |
| OLD | NEW |