OLD | NEW |
| (Empty) |
1 // Copyright 2014 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 COMPONENTS_MUS_WS_TEST_CHANGE_TRACKER_H_ | |
6 #define COMPONENTS_MUS_WS_TEST_CHANGE_TRACKER_H_ | |
7 | |
8 #include <stdint.h> | |
9 | |
10 #include <string> | |
11 #include <vector> | |
12 | |
13 #include "base/macros.h" | |
14 #include "components/mus/common/types.h" | |
15 #include "components/mus/public/interfaces/window_tree.mojom.h" | |
16 #include "mojo/public/cpp/bindings/array.h" | |
17 #include "ui/gfx/geometry/mojo/geometry.mojom.h" | |
18 | |
19 namespace mus { | |
20 | |
21 namespace ws { | |
22 | |
23 enum ChangeType { | |
24 CHANGE_TYPE_EMBED, | |
25 CHANGE_TYPE_EMBEDDED_APP_DISCONNECTED, | |
26 CHANGE_TYPE_UNEMBED, | |
27 CHANGE_TYPE_LOST_CAPTURE, | |
28 // TODO(sky): nuke NODE. | |
29 CHANGE_TYPE_NODE_ADD_TRANSIENT_WINDOW, | |
30 CHANGE_TYPE_NODE_BOUNDS_CHANGED, | |
31 CHANGE_TYPE_NODE_HIERARCHY_CHANGED, | |
32 CHANGE_TYPE_NODE_REMOVE_TRANSIENT_WINDOW_FROM_PARENT, | |
33 CHANGE_TYPE_NODE_REORDERED, | |
34 CHANGE_TYPE_NODE_VISIBILITY_CHANGED, | |
35 CHANGE_TYPE_NODE_DRAWN_STATE_CHANGED, | |
36 CHANGE_TYPE_NODE_DELETED, | |
37 CHANGE_TYPE_INPUT_EVENT, | |
38 CHANGE_TYPE_EVENT_OBSERVED, | |
39 CHANGE_TYPE_PROPERTY_CHANGED, | |
40 CHANGE_TYPE_FOCUSED, | |
41 CHANGE_TYPE_CURSOR_CHANGED, | |
42 CHANGE_TYPE_ON_CHANGE_COMPLETED, | |
43 CHANGE_TYPE_ON_TOP_LEVEL_CREATED, | |
44 CHANGE_TYPE_OPACITY, | |
45 }; | |
46 | |
47 // TODO(sky): consider nuking and converting directly to WindowData. | |
48 struct TestWindow { | |
49 TestWindow(); | |
50 TestWindow(const TestWindow& other); | |
51 ~TestWindow(); | |
52 | |
53 // Returns a string description of this. | |
54 std::string ToString() const; | |
55 | |
56 // Returns a string description that includes visible and drawn. | |
57 std::string ToString2() const; | |
58 | |
59 Id parent_id; | |
60 Id window_id; | |
61 bool visible; | |
62 std::map<std::string, std::vector<uint8_t>> properties; | |
63 }; | |
64 | |
65 // Tracks a call to WindowTreeClient. See the individual functions for the | |
66 // fields that are used. | |
67 struct Change { | |
68 Change(); | |
69 Change(const Change& other); | |
70 ~Change(); | |
71 | |
72 ChangeType type; | |
73 ClientSpecificId client_id; | |
74 std::vector<TestWindow> windows; | |
75 Id window_id; | |
76 Id window_id2; | |
77 Id window_id3; | |
78 gfx::Rect bounds; | |
79 gfx::Rect bounds2; | |
80 int32_t event_action; | |
81 uint32_t event_observer_id; | |
82 mojo::String embed_url; | |
83 mojom::OrderDirection direction; | |
84 bool bool_value; | |
85 float float_value; | |
86 std::string property_key; | |
87 std::string property_value; | |
88 int32_t cursor_id; | |
89 uint32_t change_id; | |
90 }; | |
91 | |
92 // Converts Changes to string descriptions. | |
93 std::vector<std::string> ChangesToDescription1( | |
94 const std::vector<Change>& changes); | |
95 | |
96 // Convenience for returning the description of the first item in |changes|. | |
97 // Returns an empty string if |changes| has something other than one entry. | |
98 std::string SingleChangeToDescription(const std::vector<Change>& changes); | |
99 std::string SingleChangeToDescription2(const std::vector<Change>& changes); | |
100 | |
101 // Convenience for returning the description of the first item in |windows|. | |
102 // Returns an empty string if |windows| has something other than one entry. | |
103 std::string SingleWindowDescription(const std::vector<TestWindow>& windows); | |
104 | |
105 // Returns a string description of |changes[0].windows|. Returns an empty string | |
106 // if change.size() != 1. | |
107 std::string ChangeWindowDescription(const std::vector<Change>& changes); | |
108 | |
109 // Converts WindowDatas to TestWindows. | |
110 void WindowDatasToTestWindows(const mojo::Array<mojom::WindowDataPtr>& data, | |
111 std::vector<TestWindow>* test_windows); | |
112 | |
113 // TestChangeTracker is used to record WindowTreeClient functions. It notifies | |
114 // a delegate any time a change is added. | |
115 class TestChangeTracker { | |
116 public: | |
117 // Used to notify the delegate when a change is added. A change corresponds to | |
118 // a single WindowTreeClient function. | |
119 class Delegate { | |
120 public: | |
121 virtual void OnChangeAdded() = 0; | |
122 | |
123 protected: | |
124 virtual ~Delegate() {} | |
125 }; | |
126 | |
127 TestChangeTracker(); | |
128 ~TestChangeTracker(); | |
129 | |
130 void set_delegate(Delegate* delegate) { delegate_ = delegate; } | |
131 | |
132 std::vector<Change>* changes() { return &changes_; } | |
133 | |
134 // Each of these functions generate a Change. There is one per | |
135 // WindowTreeClient function. | |
136 void OnEmbed(ClientSpecificId client_id, | |
137 mojom::WindowDataPtr root, | |
138 bool drawn); | |
139 void OnEmbeddedAppDisconnected(Id window_id); | |
140 void OnUnembed(Id window_id); | |
141 void OnLostCapture(Id window_id); | |
142 void OnTransientWindowAdded(Id window_id, Id transient_window_id); | |
143 void OnTransientWindowRemoved(Id window_id, Id transient_window_id); | |
144 void OnWindowBoundsChanged(Id window_id, | |
145 const gfx::Rect& old_bounds, | |
146 const gfx::Rect& new_bounds); | |
147 void OnWindowHierarchyChanged(Id window_id, | |
148 Id old_parent_id, | |
149 Id new_parent_id, | |
150 mojo::Array<mojom::WindowDataPtr> windows); | |
151 void OnWindowReordered(Id window_id, | |
152 Id relative_window_id, | |
153 mojom::OrderDirection direction); | |
154 void OnWindowDeleted(Id window_id); | |
155 void OnWindowVisibilityChanged(Id window_id, bool visible); | |
156 void OnWindowOpacityChanged(Id window_id, float opacity); | |
157 void OnWindowParentDrawnStateChanged(Id window_id, bool drawn); | |
158 void OnWindowInputEvent(Id window_id, | |
159 const ui::Event& event, | |
160 uint32_t event_observer_id); | |
161 void OnEventObserved(const ui::Event& event, uint32_t event_observer_id); | |
162 void OnWindowSharedPropertyChanged(Id window_id, | |
163 mojo::String name, | |
164 mojo::Array<uint8_t> data); | |
165 void OnWindowFocused(Id window_id); | |
166 void OnWindowPredefinedCursorChanged(Id window_id, mojom::Cursor cursor_id); | |
167 void OnChangeCompleted(uint32_t change_id, bool success); | |
168 void OnTopLevelCreated(uint32_t change_id, | |
169 mojom::WindowDataPtr window_data, | |
170 bool drawn); | |
171 | |
172 private: | |
173 void AddChange(const Change& change); | |
174 | |
175 Delegate* delegate_; | |
176 std::vector<Change> changes_; | |
177 | |
178 DISALLOW_COPY_AND_ASSIGN(TestChangeTracker); | |
179 }; | |
180 | |
181 } // namespace ws | |
182 | |
183 } // namespace mus | |
184 | |
185 #endif // COMPONENTS_MUS_WS_TEST_CHANGE_TRACKER_H_ | |
OLD | NEW |