Use unique image for lofi testing
[chromium-blink-merge.git] / components / view_manager / test_change_tracker.h
blob49ad6b681777a47098b4e88296df16b5528fddce
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.
5 #ifndef COMPONENTS_VIEW_MANAGER_TEST_CHANGE_TRACKER_H_
6 #define COMPONENTS_VIEW_MANAGER_TEST_CHANGE_TRACKER_H_
8 #include <string>
9 #include <vector>
11 #include "base/basictypes.h"
12 #include "components/view_manager/public/cpp/types.h"
13 #include "components/view_manager/public/interfaces/view_manager.mojom.h"
14 #include "third_party/mojo/src/mojo/public/cpp/bindings/array.h"
15 #include "ui/mojo/geometry/geometry.mojom.h"
17 namespace view_manager {
19 enum ChangeType {
20 CHANGE_TYPE_EMBED,
21 CHANGE_TYPE_EMBEDDED_APP_DISCONNECTED,
22 CHANGE_TYPE_EMBED_FOR_DESCENDANT,
23 CHANGE_TYPE_UNEMBED,
24 // TODO(sky): nuke NODE.
25 CHANGE_TYPE_NODE_BOUNDS_CHANGED,
26 CHANGE_TYPE_NODE_VIEWPORT_METRICS_CHANGED,
27 CHANGE_TYPE_NODE_HIERARCHY_CHANGED,
28 CHANGE_TYPE_NODE_REORDERED,
29 CHANGE_TYPE_NODE_VISIBILITY_CHANGED,
30 CHANGE_TYPE_NODE_DRAWN_STATE_CHANGED,
31 CHANGE_TYPE_NODE_DELETED,
32 CHANGE_TYPE_INPUT_EVENT,
33 CHANGE_TYPE_PROPERTY_CHANGED,
34 CHANGE_TYPE_DELEGATE_EMBED,
35 CHANGE_TYPE_FOCUSED,
38 // TODO(sky): consider nuking and converting directly to ViewData.
39 struct TestView {
40 TestView();
41 ~TestView();
43 // Returns a string description of this.
44 std::string ToString() const;
46 // Returns a string description that includes visible and drawn.
47 std::string ToString2() const;
49 mojo::Id parent_id;
50 mojo::Id view_id;
51 bool visible;
52 bool drawn;
53 std::map<std::string, std::vector<uint8_t>> properties;
56 // Tracks a call to ViewManagerClient. See the individual functions for the
57 // fields that are used.
58 struct Change {
59 Change();
60 ~Change();
62 ChangeType type;
63 mojo::ConnectionSpecificId connection_id;
64 std::vector<TestView> views;
65 mojo::Id view_id;
66 mojo::Id view_id2;
67 mojo::Id view_id3;
68 mojo::Rect bounds;
69 mojo::Rect bounds2;
70 int32_t event_action;
71 mojo::String embed_url;
72 mojo::OrderDirection direction;
73 bool bool_value;
74 std::string property_key;
75 std::string property_value;
78 // Converts Changes to string descriptions.
79 std::vector<std::string> ChangesToDescription1(
80 const std::vector<Change>& changes);
82 // Convenience for returning the description of the first item in |changes|.
83 // Returns an empty string if |changes| has something other than one entry.
84 std::string SingleChangeToDescription(const std::vector<Change>& changes);
86 // Convenience for returning the description of the first item in |views|.
87 // Returns an empty string if |views| has something other than one entry.
88 std::string SingleViewDescription(const std::vector<TestView>& views);
90 // Returns a string description of |changes[0].views|. Returns an empty string
91 // if change.size() != 1.
92 std::string ChangeViewDescription(const std::vector<Change>& changes);
94 // Converts ViewDatas to TestViews.
95 void ViewDatasToTestViews(const mojo::Array<mojo::ViewDataPtr>& data,
96 std::vector<TestView>* test_views);
98 // TestChangeTracker is used to record ViewManagerClient functions. It notifies
99 // a delegate any time a change is added.
100 class TestChangeTracker {
101 public:
102 // Used to notify the delegate when a change is added. A change corresponds to
103 // a single ViewManagerClient function.
104 class Delegate {
105 public:
106 virtual void OnChangeAdded() = 0;
108 protected:
109 virtual ~Delegate() {}
112 TestChangeTracker();
113 ~TestChangeTracker();
115 void set_delegate(Delegate* delegate) {
116 delegate_ = delegate;
119 std::vector<Change>* changes() { return &changes_; }
121 // Each of these functions generate a Change. There is one per
122 // ViewManagerClient function.
123 void OnEmbed(mojo::ConnectionSpecificId connection_id,
124 mojo::ViewDataPtr root);
125 void OnEmbedForDescendant(mojo::Id view_id);
126 void OnEmbeddedAppDisconnected(mojo::Id view_id);
127 void OnUnembed();
128 void OnViewBoundsChanged(mojo::Id view_id,
129 mojo::RectPtr old_bounds,
130 mojo::RectPtr new_bounds);
131 void OnViewViewportMetricsChanged(mojo::ViewportMetricsPtr old_bounds,
132 mojo::ViewportMetricsPtr new_bounds);
133 void OnViewHierarchyChanged(mojo::Id view_id,
134 mojo::Id new_parent_id,
135 mojo::Id old_parent_id,
136 mojo::Array<mojo::ViewDataPtr> views);
137 void OnViewReordered(mojo::Id view_id,
138 mojo::Id relative_view_id,
139 mojo::OrderDirection direction);
140 void OnViewDeleted(mojo::Id view_id);
141 void OnViewVisibilityChanged(mojo::Id view_id, bool visible);
142 void OnViewDrawnStateChanged(mojo::Id view_id, bool drawn);
143 void OnViewInputEvent(mojo::Id view_id, mojo::EventPtr event);
144 void OnViewSharedPropertyChanged(mojo::Id view_id,
145 mojo::String name,
146 mojo::Array<uint8_t> data);
147 void OnViewFocused(mojo::Id view_id);
148 void DelegateEmbed(const mojo::String& url);
150 private:
151 void AddChange(const Change& change);
153 Delegate* delegate_;
154 std::vector<Change> changes_;
156 DISALLOW_COPY_AND_ASSIGN(TestChangeTracker);
159 } // namespace view_manager
161 #endif // COMPONENTS_VIEW_MANAGER_TEST_CHANGE_TRACKER_H_