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 MOJO_SERVICES_VIEW_MANAGER_TEST_CHANGE_TRACKER_H_
6 #define MOJO_SERVICES_VIEW_MANAGER_TEST_CHANGE_TRACKER_H_
11 #include "mojo/public/cpp/bindings/array.h"
12 #include "mojo/services/public/cpp/view_manager/types.h"
13 #include "mojo/services/public/interfaces/view_manager/view_manager.mojom.h"
14 #include "ui/gfx/rect.h"
21 CHANGE_TYPE_NODE_BOUNDS_CHANGED
,
22 CHANGE_TYPE_NODE_HIERARCHY_CHANGED
,
23 CHANGE_TYPE_NODE_REORDERED
,
24 CHANGE_TYPE_NODE_DELETED
,
25 CHANGE_TYPE_INPUT_EVENT
,
26 CHANGE_TYPE_DELEGATE_EMBED
,
29 // TODO(sky): consider nuking and converting directly to ViewData.
31 // Returns a string description of this.
32 std::string
ToString() const;
38 // Tracks a call to ViewManagerClient. See the individual functions for the
39 // fields that are used.
45 ConnectionSpecificId connection_id
;
46 std::vector
<TestView
> views
;
55 OrderDirection direction
;
58 // Converts Changes to string descriptions.
59 std::vector
<std::string
> ChangesToDescription1(
60 const std::vector
<Change
>& changes
);
62 // Returns a string description of |changes[0].views|. Returns an empty string
63 // if change.size() != 1.
64 std::string
ChangeViewDescription(const std::vector
<Change
>& changes
);
66 // Converts ViewDatas to TestViews.
67 void ViewDatasToTestViews(const Array
<ViewDataPtr
>& data
,
68 std::vector
<TestView
>* test_views
);
70 // TestChangeTracker is used to record ViewManagerClient functions. It notifies
71 // a delegate any time a change is added.
72 class TestChangeTracker
{
74 // Used to notify the delegate when a change is added. A change corresponds to
75 // a single ViewManagerClient function.
78 virtual void OnChangeAdded() = 0;
81 virtual ~Delegate() {}
87 void set_delegate(Delegate
* delegate
) {
91 std::vector
<Change
>* changes() { return &changes_
; }
93 // Each of these functions generate a Change. There is one per
94 // ViewManagerClient function.
95 void OnEmbed(ConnectionSpecificId connection_id
,
96 const String
& creator_url
,
98 void OnViewBoundsChanged(Id view_id
, RectPtr old_bounds
, RectPtr new_bounds
);
99 void OnViewHierarchyChanged(Id view_id
,
102 Array
<ViewDataPtr
> views
);
103 void OnViewReordered(Id view_id
,
105 OrderDirection direction
);
106 void OnViewDeleted(Id view_id
);
107 void OnViewInputEvent(Id view_id
, EventPtr event
);
108 void DelegateEmbed(const String
& url
);
111 void AddChange(const Change
& change
);
114 std::vector
<Change
> changes_
;
116 DISALLOW_COPY_AND_ASSIGN(TestChangeTracker
);
119 } // namespace service
122 #endif // MOJO_SERVICES_VIEW_MANAGER_TEST_CHANGE_TRACKER_H_