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 // TODO(sky): NODE->VIEW.
22 CHANGE_TYPE_NODE_BOUNDS_CHANGED,
23 CHANGE_TYPE_NODE_HIERARCHY_CHANGED,
24 CHANGE_TYPE_NODE_REORDERED,
25 CHANGE_TYPE_NODE_VISIBILITY_CHANGED,
26 CHANGE_TYPE_NODE_DRAWN_STATE_CHANGED,
27 CHANGE_TYPE_NODE_DELETED,
28 CHANGE_TYPE_INPUT_EVENT,
29 CHANGE_TYPE_DELEGATE_EMBED,
32 // TODO(sky): consider nuking and converting directly to ViewData.
34 // Returns a string description of this.
35 std::string ToString() const;
37 // Returns a string description that includes visible and drawn.
38 std::string ToString2() const;
46 // Tracks a call to ViewManagerClient. See the individual functions for the
47 // fields that are used.
53 ConnectionSpecificId connection_id;
54 std::vector<TestView> views;
63 OrderDirection direction;
67 // Converts Changes to string descriptions.
68 std::vector<std::string> ChangesToDescription1(
69 const std::vector<Change>& changes);
71 // Returns a string description of |changes[0].views|. Returns an empty string
72 // if change.size() != 1.
73 std::string ChangeViewDescription(const std::vector<Change>& changes);
75 // Converts ViewDatas to TestViews.
76 void ViewDatasToTestViews(const Array<ViewDataPtr>& data,
77 std::vector<TestView>* test_views);
79 // TestChangeTracker is used to record ViewManagerClient functions. It notifies
80 // a delegate any time a change is added.
81 class TestChangeTracker {
83 // Used to notify the delegate when a change is added. A change corresponds to
84 // a single ViewManagerClient function.
87 virtual void OnChangeAdded() = 0;
90 virtual ~Delegate() {}
96 void set_delegate(Delegate* delegate) {
100 std::vector<Change>* changes() { return &changes_; }
102 // Each of these functions generate a Change. There is one per
103 // ViewManagerClient function.
104 void OnEmbed(ConnectionSpecificId connection_id,
105 const String& creator_url,
107 void OnViewBoundsChanged(Id view_id, RectPtr old_bounds, RectPtr new_bounds);
108 void OnViewHierarchyChanged(Id view_id,
111 Array<ViewDataPtr> views);
112 void OnViewReordered(Id view_id,
114 OrderDirection direction);
115 void OnViewDeleted(Id view_id);
116 void OnViewVisibilityChanged(Id view_id, bool visible);
117 void OnViewDrawnStateChanged(Id view_id, bool drawn);
118 void OnViewInputEvent(Id view_id, EventPtr event);
119 void DelegateEmbed(const String& url);
122 void AddChange(const Change& change);
125 std::vector<Change> changes_;
127 DISALLOW_COPY_AND_ASSIGN(TestChangeTracker);
130 } // namespace service
133 #endif // MOJO_SERVICES_VIEW_MANAGER_TEST_CHANGE_TRACKER_H_