Battery Status API: add UMA logging for Linux.
[chromium-blink-merge.git] / mojo / services / view_manager / test_change_tracker.h
blobd92024495149c4a8798ee8dffa5144b9d494fea2
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_
8 #include <string>
9 #include <vector>
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"
16 namespace mojo {
17 namespace service {
19 enum ChangeType {
20 CHANGE_TYPE_EMBED,
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.
30 struct TestView {
31 // Returns a string description of this.
32 std::string ToString() const;
34 Id parent_id;
35 Id view_id;
38 // Tracks a call to ViewManagerClient. See the individual functions for the
39 // fields that are used.
40 struct Change {
41 Change();
42 ~Change();
44 ChangeType type;
45 ConnectionSpecificId connection_id;
46 std::vector<TestView> views;
47 Id view_id;
48 Id view_id2;
49 Id view_id3;
50 gfx::Rect bounds;
51 gfx::Rect bounds2;
52 int32 event_action;
53 String creator_url;
54 String embed_url;
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 {
73 public:
74 // Used to notify the delegate when a change is added. A change corresponds to
75 // a single ViewManagerClient function.
76 class Delegate {
77 public:
78 virtual void OnChangeAdded() = 0;
80 protected:
81 virtual ~Delegate() {}
84 TestChangeTracker();
85 ~TestChangeTracker();
87 void set_delegate(Delegate* delegate) {
88 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,
97 ViewDataPtr root);
98 void OnViewBoundsChanged(Id view_id, RectPtr old_bounds, RectPtr new_bounds);
99 void OnViewHierarchyChanged(Id view_id,
100 Id new_parent_id,
101 Id old_parent_id,
102 Array<ViewDataPtr> views);
103 void OnViewReordered(Id view_id,
104 Id relative_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);
110 private:
111 void AddChange(const Change& change);
113 Delegate* delegate_;
114 std::vector<Change> changes_;
116 DISALLOW_COPY_AND_ASSIGN(TestChangeTracker);
119 } // namespace service
120 } // namespace mojo
122 #endif // MOJO_SERVICES_VIEW_MANAGER_TEST_CHANGE_TRACKER_H_