This change is intended to M-43. Currently screen rotation animations expose a bug...
[chromium-blink-merge.git] / components / view_manager / test_change_tracker.h
blob2312828aef2012b6ea64383fa15efcfe794f73ff
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 // TODO(sky): nuke NODE.
23 CHANGE_TYPE_NODE_BOUNDS_CHANGED,
24 CHANGE_TYPE_NODE_VIEWPORT_METRICS_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 CHANGE_TYPE_FOCUSED,
36 // TODO(sky): consider nuking and converting directly to ViewData.
37 struct TestView {
38 TestView();
39 ~TestView();
41 // Returns a string description of this.
42 std::string ToString() const;
44 // Returns a string description that includes visible and drawn.
45 std::string ToString2() const;
47 mojo::Id parent_id;
48 mojo::Id view_id;
49 bool visible;
50 bool drawn;
51 std::map<std::string, std::vector<uint8_t>> properties;
54 // Tracks a call to ViewManagerClient. See the individual functions for the
55 // fields that are used.
56 struct Change {
57 Change();
58 ~Change();
60 ChangeType type;
61 mojo::ConnectionSpecificId connection_id;
62 std::vector<TestView> views;
63 mojo::Id view_id;
64 mojo::Id view_id2;
65 mojo::Id view_id3;
66 mojo::Rect bounds;
67 mojo::Rect bounds2;
68 int32_t event_action;
69 mojo::String creator_url;
70 mojo::String embed_url;
71 mojo::OrderDirection direction;
72 bool bool_value;
73 std::string property_key;
74 std::string property_value;
77 // Converts Changes to string descriptions.
78 std::vector<std::string> ChangesToDescription1(
79 const std::vector<Change>& changes);
81 // Convenience for returning the description of the first item in |changes|.
82 // Returns an empty string if |changes| has something other than one entry.
83 std::string SingleChangeToDescription(const std::vector<Change>& changes);
85 // Convenience for returning the description of the first item in |views|.
86 // Returns an empty string if |views| has something other than one entry.
87 std::string SingleViewDescription(const std::vector<TestView>& views);
89 // Returns a string description of |changes[0].views|. Returns an empty string
90 // if change.size() != 1.
91 std::string ChangeViewDescription(const std::vector<Change>& changes);
93 // Converts ViewDatas to TestViews.
94 void ViewDatasToTestViews(const mojo::Array<mojo::ViewDataPtr>& data,
95 std::vector<TestView>* test_views);
97 // TestChangeTracker is used to record ViewManagerClient functions. It notifies
98 // a delegate any time a change is added.
99 class TestChangeTracker {
100 public:
101 // Used to notify the delegate when a change is added. A change corresponds to
102 // a single ViewManagerClient function.
103 class Delegate {
104 public:
105 virtual void OnChangeAdded() = 0;
107 protected:
108 virtual ~Delegate() {}
111 TestChangeTracker();
112 ~TestChangeTracker();
114 void set_delegate(Delegate* delegate) {
115 delegate_ = delegate;
118 std::vector<Change>* changes() { return &changes_; }
120 // Each of these functions generate a Change. There is one per
121 // ViewManagerClient function.
122 void OnEmbed(mojo::ConnectionSpecificId connection_id,
123 const mojo::String& creator_url,
124 mojo::ViewDataPtr root);
125 void OnEmbeddedAppDisconnected(mojo::Id view_id);
126 void OnViewBoundsChanged(mojo::Id view_id,
127 mojo::RectPtr old_bounds,
128 mojo::RectPtr new_bounds);
129 void OnViewViewportMetricsChanged(mojo::ViewportMetricsPtr old_bounds,
130 mojo::ViewportMetricsPtr new_bounds);
131 void OnViewHierarchyChanged(mojo::Id view_id,
132 mojo::Id new_parent_id,
133 mojo::Id old_parent_id,
134 mojo::Array<mojo::ViewDataPtr> views);
135 void OnViewReordered(mojo::Id view_id,
136 mojo::Id relative_view_id,
137 mojo::OrderDirection direction);
138 void OnViewDeleted(mojo::Id view_id);
139 void OnViewVisibilityChanged(mojo::Id view_id, bool visible);
140 void OnViewDrawnStateChanged(mojo::Id view_id, bool drawn);
141 void OnViewInputEvent(mojo::Id view_id, mojo::EventPtr event);
142 void OnViewSharedPropertyChanged(mojo::Id view_id,
143 mojo::String name,
144 mojo::Array<uint8_t> data);
145 void OnViewFocused(mojo::Id view_id);
146 void DelegateEmbed(const mojo::String& url);
148 private:
149 void AddChange(const Change& change);
151 Delegate* delegate_;
152 std::vector<Change> changes_;
154 DISALLOW_COPY_AND_ASSIGN(TestChangeTracker);
157 } // namespace view_manager
159 #endif // COMPONENTS_VIEW_MANAGER_TEST_CHANGE_TRACKER_H_