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_MUS_TEST_CHANGE_TRACKER_H_
6 #define COMPONENTS_MUS_TEST_CHANGE_TRACKER_H_
11 #include "base/basictypes.h"
12 #include "components/mus/public/cpp/types.h"
13 #include "components/mus/public/interfaces/view_tree.mojom.h"
14 #include "third_party/mojo/src/mojo/public/cpp/bindings/array.h"
15 #include "ui/mojo/geometry/geometry.mojom.h"
21 CHANGE_TYPE_EMBEDDED_APP_DISCONNECTED
,
23 // TODO(sky): nuke NODE.
24 CHANGE_TYPE_NODE_BOUNDS_CHANGED
,
25 CHANGE_TYPE_NODE_VIEWPORT_METRICS_CHANGED
,
26 CHANGE_TYPE_NODE_HIERARCHY_CHANGED
,
27 CHANGE_TYPE_NODE_REORDERED
,
28 CHANGE_TYPE_NODE_VISIBILITY_CHANGED
,
29 CHANGE_TYPE_NODE_DRAWN_STATE_CHANGED
,
30 CHANGE_TYPE_NODE_DELETED
,
31 CHANGE_TYPE_INPUT_EVENT
,
32 CHANGE_TYPE_PROPERTY_CHANGED
,
33 CHANGE_TYPE_DELEGATE_EMBED
,
37 // TODO(sky): consider nuking and converting directly to ViewData.
42 // Returns a string description of this.
43 std::string
ToString() const;
45 // Returns a string description that includes visible and drawn.
46 std::string
ToString2() const;
52 std::map
<std::string
, std::vector
<uint8_t>> properties
;
55 // Tracks a call to ViewTreeClient. See the individual functions for the fields
62 ConnectionSpecificId connection_id
;
63 std::vector
<TestView
> views
;
70 mojo::String embed_url
;
71 mojo::OrderDirection direction
;
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 ViewTreeClient functions. It notifies
98 // a delegate any time a change is added.
99 class TestChangeTracker
{
101 // Used to notify the delegate when a change is added. A change corresponds to
102 // a single ViewTreeClient function.
105 virtual void OnChangeAdded() = 0;
108 virtual ~Delegate() {}
112 ~TestChangeTracker();
114 void set_delegate(Delegate
* delegate
) { delegate_
= delegate
; }
116 std::vector
<Change
>* changes() { return &changes_
; }
118 // Each of these functions generate a Change. There is one per
119 // ViewTreeClient function.
120 void OnEmbed(ConnectionSpecificId connection_id
, mojo::ViewDataPtr root
);
121 void OnEmbeddedAppDisconnected(Id view_id
);
123 void OnViewBoundsChanged(Id view_id
,
124 mojo::RectPtr old_bounds
,
125 mojo::RectPtr new_bounds
);
126 void OnViewViewportMetricsChanged(mojo::ViewportMetricsPtr old_bounds
,
127 mojo::ViewportMetricsPtr new_bounds
);
128 void OnViewHierarchyChanged(Id view_id
,
131 mojo::Array
<mojo::ViewDataPtr
> views
);
132 void OnViewReordered(Id view_id
,
134 mojo::OrderDirection direction
);
135 void OnViewDeleted(Id view_id
);
136 void OnViewVisibilityChanged(Id view_id
, bool visible
);
137 void OnViewDrawnStateChanged(Id view_id
, bool drawn
);
138 void OnViewInputEvent(Id view_id
, mojo::EventPtr event
);
139 void OnViewSharedPropertyChanged(Id view_id
,
141 mojo::Array
<uint8_t> data
);
142 void OnViewFocused(Id view_id
);
143 void DelegateEmbed(const mojo::String
& url
);
146 void AddChange(const Change
& change
);
149 std::vector
<Change
> changes_
;
151 DISALLOW_COPY_AND_ASSIGN(TestChangeTracker
);
156 #endif // COMPONENTS_MUS_TEST_CHANGE_TRACKER_H_