Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(6)

Side by Side Diff: mojo/services/view_manager/test_change_tracker.h

Issue 774473003: Move view_manager service implementation to //services (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 6 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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 MOJO_SERVICES_VIEW_MANAGER_TEST_CHANGE_TRACKER_H_
6 #define MOJO_SERVICES_VIEW_MANAGER_TEST_CHANGE_TRACKER_H_
7
8 #include <string>
9 #include <vector>
10
11 #include "base/basictypes.h"
12 #include "mojo/public/cpp/bindings/array.h"
13 #include "mojo/services/public/cpp/view_manager/types.h"
14 #include "mojo/services/public/interfaces/geometry/geometry.mojom.h"
15 #include "mojo/services/public/interfaces/view_manager/view_manager.mojom.h"
16
17 namespace mojo {
18 namespace service {
19
20 enum ChangeType {
21 CHANGE_TYPE_EMBED,
22 CHANGE_TYPE_EMBEDDED_APP_DISCONNECTED,
23 // TODO(sky): NODE->VIEW.
24 CHANGE_TYPE_NODE_BOUNDS_CHANGED,
25 CHANGE_TYPE_NODE_HIERARCHY_CHANGED,
26 CHANGE_TYPE_NODE_REORDERED,
27 CHANGE_TYPE_NODE_VISIBILITY_CHANGED,
28 CHANGE_TYPE_NODE_DRAWN_STATE_CHANGED,
29 CHANGE_TYPE_NODE_DELETED,
30 CHANGE_TYPE_INPUT_EVENT,
31 CHANGE_TYPE_PROPERTY_CHANGED,
32 CHANGE_TYPE_DELEGATE_EMBED,
33 };
34
35 // TODO(sky): consider nuking and converting directly to ViewData.
36 struct TestView {
37 TestView();
38 ~TestView();
39
40 // Returns a string description of this.
41 std::string ToString() const;
42
43 // Returns a string description that includes visible and drawn.
44 std::string ToString2() const;
45
46 Id parent_id;
47 Id view_id;
48 bool visible;
49 bool drawn;
50 std::map<std::string, std::vector<uint8_t>> properties;
51 };
52
53 // Tracks a call to ViewManagerClient. See the individual functions for the
54 // fields that are used.
55 struct Change {
56 Change();
57 ~Change();
58
59 ChangeType type;
60 ConnectionSpecificId connection_id;
61 std::vector<TestView> views;
62 Id view_id;
63 Id view_id2;
64 Id view_id3;
65 Rect bounds;
66 Rect bounds2;
67 int32_t event_action;
68 String creator_url;
69 String embed_url;
70 OrderDirection direction;
71 bool bool_value;
72 std::string property_key;
73 std::string property_value;
74 };
75
76 // Converts Changes to string descriptions.
77 std::vector<std::string> ChangesToDescription1(
78 const std::vector<Change>& changes);
79
80 // Convenience for returning the description of the first item in |changes|.
81 // Returns an empty string if |changes| has something other than one entry.
82 std::string SingleChangeToDescription(const std::vector<Change>& changes);
83
84 // Convenience for returning the description of the first item in |views|.
85 // Returns an empty string if |views| has something other than one entry.
86 std::string SingleViewDescription(const std::vector<TestView>& views);
87
88 // Returns a string description of |changes[0].views|. Returns an empty string
89 // if change.size() != 1.
90 std::string ChangeViewDescription(const std::vector<Change>& changes);
91
92 // Converts ViewDatas to TestViews.
93 void ViewDatasToTestViews(const Array<ViewDataPtr>& data,
94 std::vector<TestView>* test_views);
95
96 // TestChangeTracker is used to record ViewManagerClient functions. It notifies
97 // a delegate any time a change is added.
98 class TestChangeTracker {
99 public:
100 // Used to notify the delegate when a change is added. A change corresponds to
101 // a single ViewManagerClient function.
102 class Delegate {
103 public:
104 virtual void OnChangeAdded() = 0;
105
106 protected:
107 virtual ~Delegate() {}
108 };
109
110 TestChangeTracker();
111 ~TestChangeTracker();
112
113 void set_delegate(Delegate* delegate) {
114 delegate_ = delegate;
115 }
116
117 std::vector<Change>* changes() { return &changes_; }
118
119 // Each of these functions generate a Change. There is one per
120 // ViewManagerClient function.
121 void OnEmbed(ConnectionSpecificId connection_id,
122 const String& creator_url,
123 ViewDataPtr root);
124 void OnEmbeddedAppDisconnected(Id view_id);
125 void OnViewBoundsChanged(Id view_id, RectPtr old_bounds, RectPtr new_bounds);
126 void OnViewHierarchyChanged(Id view_id,
127 Id new_parent_id,
128 Id old_parent_id,
129 Array<ViewDataPtr> views);
130 void OnViewReordered(Id view_id,
131 Id relative_view_id,
132 OrderDirection direction);
133 void OnViewDeleted(Id view_id);
134 void OnViewVisibilityChanged(Id view_id, bool visible);
135 void OnViewDrawnStateChanged(Id view_id, bool drawn);
136 void OnViewInputEvent(Id view_id, EventPtr event);
137 void OnViewSharedPropertyChanged(Id view_id,
138 String name,
139 Array<uint8_t> data);
140 void DelegateEmbed(const String& url);
141
142 private:
143 void AddChange(const Change& change);
144
145 Delegate* delegate_;
146 std::vector<Change> changes_;
147
148 DISALLOW_COPY_AND_ASSIGN(TestChangeTracker);
149 };
150
151 } // namespace service
152 } // namespace mojo
153
154 #endif // MOJO_SERVICES_VIEW_MANAGER_TEST_CHANGE_TRACKER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698