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