| 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_TEST_WINDOW_TREE_H_ | 5 #ifndef UI_AURA_TEST_MUS_TEST_WINDOW_TREE_H_ |
| 6 #define SERVICES_UI_PUBLIC_CPP_TESTS_TEST_WINDOW_TREE_H_ | 6 #define UI_AURA_TEST_MUS_TEST_WINDOW_TREE_H_ |
| 7 | 7 |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <set> | 10 #include <set> |
| 11 | 11 |
| 12 #include "base/macros.h" | 12 #include "base/macros.h" |
| 13 #include "services/ui/public/interfaces/window_tree.mojom.h" | 13 #include "services/ui/public/interfaces/window_tree.mojom.h" |
| 14 | 14 |
| 15 namespace ui { | 15 namespace aura { |
| 16 | 16 |
| 17 // Testing WindowTree implementation. | 17 enum class WindowTreeChangeType { |
| 18 class TestWindowTree : public mojom::WindowTree { | 18 BOUNDS, |
| 19 // Used for both set and release capture. |
| 20 CAPTURE, |
| 21 FOCUS, |
| 22 NEW_TOP_LEVEL, |
| 23 NEW_WINDOW, |
| 24 PROPERTY, |
| 25 VISIBLE, |
| 26 |
| 27 // This covers all cases that aren't used in tests. |
| 28 OTHER, |
| 29 }; |
| 30 |
| 31 // WindowTree implementation for tests. TestWindowTree maintains a list of all |
| 32 // calls that take a change_id and are expected to be acked back to the client. |
| 33 // Various functions are provided to respond to the changes. |
| 34 class TestWindowTree : public ui::mojom::WindowTree { |
| 19 public: | 35 public: |
| 20 TestWindowTree(); | 36 TestWindowTree(); |
| 21 ~TestWindowTree() override; | 37 ~TestWindowTree() override; |
| 22 | 38 |
| 23 // Returns the most recent change_id supplied to one of the WindowTree | 39 void set_client(ui::mojom::WindowTreeClient* client) { client_ = client; } |
| 24 // functions. Returns false if one of the WindowTree functions has not been | |
| 25 // invoked since the last GetAndClearChangeId(). | |
| 26 bool GetAndClearChangeId(uint32_t* change_id); | |
| 27 | 40 |
| 28 uint32_t window_id() const { return window_id_; } | 41 uint32_t window_id() const { return window_id_; } |
| 29 | 42 |
| 30 bool WasEventAcked(uint32_t event_id) const; | 43 bool WasEventAcked(uint32_t event_id) const; |
| 31 | 44 |
| 45 mojo::Array<uint8_t> GetLastPropertyValue(); |
| 46 |
| 47 mojo::Map<mojo::String, mojo::Array<uint8_t>> GetLastNewWindowProperties(); |
| 48 |
| 49 // True if at least one function has been called that takes a change id. |
| 50 bool has_change() const { return !changes_.empty(); } |
| 51 |
| 52 // Acks all changes with a value of true. |
| 53 void AckAllChanges(); |
| 54 |
| 55 // Returns false if there are no, or more than one, changes of the specified |
| 56 // type. If there is only one of the matching type it is acked with a result |
| 57 // of |result| and true is returned. |
| 58 bool AckSingleChangeOfType(WindowTreeChangeType type, bool result); |
| 59 |
| 60 // Same as AckSingleChangeOfType(), but doesn't fail if there is more than |
| 61 // one change of the specified type. |
| 62 bool AckFirstChangeOfType(WindowTreeChangeType type, bool result); |
| 63 |
| 64 void AckAllChangesOfType(WindowTreeChangeType type, bool result); |
| 65 |
| 66 bool GetAndRemoveFirstChangeOfType(WindowTreeChangeType type, |
| 67 uint32_t* change_id); |
| 68 |
| 32 private: | 69 private: |
| 33 // mojom::WindowTree: | 70 struct Change { |
| 71 WindowTreeChangeType type; |
| 72 uint32_t id; |
| 73 }; |
| 74 |
| 75 void OnChangeReceived( |
| 76 uint32_t change_id, |
| 77 WindowTreeChangeType type = WindowTreeChangeType::OTHER); |
| 78 |
| 79 // ui::mojom::WindowTree: |
| 34 void NewWindow( | 80 void NewWindow( |
| 35 uint32_t change_id, | 81 uint32_t change_id, |
| 36 uint32_t window_id, | 82 uint32_t window_id, |
| 37 mojo::Map<mojo::String, mojo::Array<uint8_t>> properties) override; | 83 mojo::Map<mojo::String, mojo::Array<uint8_t>> properties) override; |
| 38 void NewTopLevelWindow( | 84 void NewTopLevelWindow( |
| 39 uint32_t change_id, | 85 uint32_t change_id, |
| 40 uint32_t window_id, | 86 uint32_t window_id, |
| 41 mojo::Map<mojo::String, mojo::Array<uint8_t>> properties) override; | 87 mojo::Map<mojo::String, mojo::Array<uint8_t>> properties) override; |
| 42 void DeleteWindow(uint32_t change_id, uint32_t window_id) override; | 88 void DeleteWindow(uint32_t change_id, uint32_t window_id) override; |
| 43 void SetWindowBounds(uint32_t change_id, | 89 void SetWindowBounds(uint32_t change_id, |
| (...skipping 10 matching lines...) Expand all Loading... |
| 54 bool visible) override; | 100 bool visible) override; |
| 55 void SetWindowProperty(uint32_t change_id, | 101 void SetWindowProperty(uint32_t change_id, |
| 56 uint32_t window_id, | 102 uint32_t window_id, |
| 57 const mojo::String& name, | 103 const mojo::String& name, |
| 58 mojo::Array<uint8_t> value) override; | 104 mojo::Array<uint8_t> value) override; |
| 59 void SetWindowOpacity(uint32_t change_id, | 105 void SetWindowOpacity(uint32_t change_id, |
| 60 uint32_t window_id, | 106 uint32_t window_id, |
| 61 float opacity) override; | 107 float opacity) override; |
| 62 void AttachCompositorFrameSink( | 108 void AttachCompositorFrameSink( |
| 63 uint32_t window_id, | 109 uint32_t window_id, |
| 64 mojom::CompositorFrameSinkType type, | 110 ui::mojom::CompositorFrameSinkType type, |
| 65 mojo::InterfaceRequest<cc::mojom::MojoCompositorFrameSink> surface, | 111 mojo::InterfaceRequest<cc::mojom::MojoCompositorFrameSink> surface, |
| 66 cc::mojom::MojoCompositorFrameSinkClientPtr client) override; | 112 cc::mojom::MojoCompositorFrameSinkClientPtr client) override; |
| 113 void OnWindowSurfaceDetached(uint32_t window_id, |
| 114 const cc::SurfaceSequence& sequence) override; |
| 67 void AddWindow(uint32_t change_id, uint32_t parent, uint32_t child) override; | 115 void AddWindow(uint32_t change_id, uint32_t parent, uint32_t child) override; |
| 68 void RemoveWindowFromParent(uint32_t change_id, uint32_t window_id) override; | 116 void RemoveWindowFromParent(uint32_t change_id, uint32_t window_id) override; |
| 69 void AddTransientWindow(uint32_t change_id, | 117 void AddTransientWindow(uint32_t change_id, |
| 70 uint32_t window_id, | 118 uint32_t window_id, |
| 71 uint32_t transient_window_id) override; | 119 uint32_t transient_window_id) override; |
| 72 void RemoveTransientWindowFromParent(uint32_t change_id, | 120 void RemoveTransientWindowFromParent(uint32_t change_id, |
| 73 uint32_t window_id) override; | 121 uint32_t window_id) override; |
| 74 void SetModal(uint32_t change_id, uint32_t window_id) override; | 122 void SetModal(uint32_t change_id, uint32_t window_id) override; |
| 75 void ReorderWindow(uint32_t change_id, | 123 void ReorderWindow(uint32_t change_id, |
| 76 uint32_t window_id, | 124 uint32_t window_id, |
| 77 uint32_t relative_window_id, | 125 uint32_t relative_window_id, |
| 78 mojom::OrderDirection direction) override; | 126 ui::mojom::OrderDirection direction) override; |
| 79 void GetWindowTree(uint32_t window_id, | 127 void GetWindowTree(uint32_t window_id, |
| 80 const GetWindowTreeCallback& callback) override; | 128 const GetWindowTreeCallback& callback) override; |
| 81 void SetCapture(uint32_t change_id, uint32_t window_id) override; | 129 void SetCapture(uint32_t change_id, uint32_t window_id) override; |
| 82 void ReleaseCapture(uint32_t change_id, uint32_t window_id) override; | 130 void ReleaseCapture(uint32_t change_id, uint32_t window_id) override; |
| 83 void StartPointerWatcher(bool want_moves) override; | 131 void StartPointerWatcher(bool want_moves) override; |
| 84 void StopPointerWatcher() override; | 132 void StopPointerWatcher() override; |
| 85 void Embed(uint32_t window_id, | 133 void Embed(uint32_t window_id, |
| 86 mojom::WindowTreeClientPtr client, | 134 ui::mojom::WindowTreeClientPtr client, |
| 87 uint32_t flags, | 135 uint32_t flags, |
| 88 const EmbedCallback& callback) override; | 136 const EmbedCallback& callback) override; |
| 89 void SetFocus(uint32_t change_id, uint32_t window_id) override; | 137 void SetFocus(uint32_t change_id, uint32_t window_id) override; |
| 90 void SetCanFocus(uint32_t window_id, bool can_focus) override; | 138 void SetCanFocus(uint32_t window_id, bool can_focus) override; |
| 91 void SetCanAcceptEvents(uint32_t window_id, bool can_accept_events) override; | 139 void SetCanAcceptEvents(uint32_t window_id, bool can_accept_events) override; |
| 92 void SetPredefinedCursor(uint32_t change_id, | 140 void SetPredefinedCursor(uint32_t change_id, |
| 93 uint32_t window_id, | 141 uint32_t window_id, |
| 94 ui::mojom::Cursor cursor_id) override; | 142 ui::mojom::Cursor cursor_id) override; |
| 95 void SetWindowTextInputState(uint32_t window_id, | 143 void SetWindowTextInputState(uint32_t window_id, |
| 96 mojo::TextInputStatePtr state) override; | 144 mojo::TextInputStatePtr state) override; |
| 97 void SetImeVisibility(uint32_t window_id, | 145 void SetImeVisibility(uint32_t window_id, |
| 98 bool visible, | 146 bool visible, |
| 99 mojo::TextInputStatePtr state) override; | 147 mojo::TextInputStatePtr state) override; |
| 100 void OnWindowInputEventAck(uint32_t event_id, | 148 void OnWindowInputEventAck(uint32_t event_id, |
| 101 ui::mojom::EventResult result) override; | 149 ui::mojom::EventResult result) override; |
| 102 void GetWindowManagerClient( | 150 void GetWindowManagerClient( |
| 103 mojo::AssociatedInterfaceRequest<mojom::WindowManagerClient> internal) | 151 mojo::AssociatedInterfaceRequest<ui::mojom::WindowManagerClient> internal) |
| 104 override; | 152 override; |
| 105 void GetCursorLocationMemory(const GetCursorLocationMemoryCallback& callback) | 153 void GetCursorLocationMemory( |
| 106 override; | 154 const GetCursorLocationMemoryCallback& callback) override; |
| 107 void PerformDragDrop(uint32_t change_id, | 155 void PerformDragDrop(uint32_t change_id, |
| 108 uint32_t source_window_id, | 156 uint32_t source_window_id, |
| 109 mojo::Map<mojo::String, mojo::Array<uint8_t>> drag_data, | 157 mojo::Map<mojo::String, mojo::Array<uint8_t>> drag_data, |
| 110 uint32_t drag_operation) override; | 158 uint32_t drag_operation) override; |
| 111 void CancelDragDrop(uint32_t window_id) override; | 159 void CancelDragDrop(uint32_t window_id) override; |
| 112 void PerformWindowMove(uint32_t change_id, | 160 void PerformWindowMove(uint32_t change_id, |
| 113 uint32_t window_id, | 161 uint32_t window_id, |
| 114 mojom::MoveLoopSource source, | 162 ui::mojom::MoveLoopSource source, |
| 115 const gfx::Point& cursor_location) override; | 163 const gfx::Point& cursor_location) override; |
| 116 void CancelWindowMove(uint32_t window_id) override; | 164 void CancelWindowMove(uint32_t window_id) override; |
| 117 void OnWindowSurfaceDetached(uint32_t window_id, | |
| 118 const cc::SurfaceSequence& sequence) override; | |
| 119 | 165 |
| 120 bool got_change_; | |
| 121 uint32_t change_id_; | |
| 122 std::set<uint32_t> acked_events_; | 166 std::set<uint32_t> acked_events_; |
| 123 uint32_t window_id_; | 167 uint32_t window_id_ = 0u; |
| 168 |
| 169 mojo::Array<uint8_t> last_property_value_; |
| 170 |
| 171 std::vector<Change> changes_; |
| 172 |
| 173 ui::mojom::WindowTreeClient* client_; |
| 174 |
| 175 mojo::Map<mojo::String, mojo::Array<uint8_t>> last_new_window_properties_; |
| 124 | 176 |
| 125 DISALLOW_COPY_AND_ASSIGN(TestWindowTree); | 177 DISALLOW_COPY_AND_ASSIGN(TestWindowTree); |
| 126 }; | 178 }; |
| 127 | 179 |
| 128 } // namespace ui | 180 } // namespace aura |
| 129 | 181 |
| 130 #endif // SERVICES_UI_PUBLIC_CPP_TESTS_TEST_WINDOW_TREE_H_ | 182 #endif // UI_AURA_TEST_MUS_TEST_WINDOW_TREE_H_ |
| OLD | NEW |