OLD | NEW |
(Empty) | |
| 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. |
| 4 |
| 5 #ifndef SERVICES_VIEW_MANAGER_TEST_CHANGE_TRACKER_H_ |
| 6 #define SERVICES_VIEW_MANAGER_TEST_CHANGE_TRACKER_H_ |
| 7 |
| 8 #include <string> |
| 9 #include <vector> |
| 10 |
| 11 #include "base/basictypes.h" |
| 12 #include "mojo/public/cpp/bindings/array.h" |
| 13 #include "third_party/mojo_services/src/geometry/public/interfaces/geometry.mojo
m.h" |
| 14 #include "third_party/mojo_services/src/view_manager/public/cpp/types.h" |
| 15 #include "third_party/mojo_services/src/view_manager/public/interfaces/view_mana
ger.mojom.h" |
| 16 |
| 17 namespace view_manager { |
| 18 |
| 19 enum ChangeType { |
| 20 CHANGE_TYPE_EMBED, |
| 21 CHANGE_TYPE_EMBEDDED_APP_DISCONNECTED, |
| 22 // TODO(sky): NODE->VIEW. |
| 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 }; |
| 34 |
| 35 // TODO(sky): consider nuking and converting directly to ViewData. |
| 36 struct TestView { |
| 37 TestView(); |
| 38 ~TestView(); |
| 39 |
| 40 // Returns a string description of this. |
| 41 std::string ToString() const; |
| 42 |
| 43 // Returns a string description that includes visible and drawn. |
| 44 std::string ToString2() const; |
| 45 |
| 46 mojo::Id parent_id; |
| 47 mojo::Id view_id; |
| 48 bool visible; |
| 49 bool drawn; |
| 50 std::map<std::string, std::vector<uint8_t>> properties; |
| 51 }; |
| 52 |
| 53 // Tracks a call to ViewManagerClient. See the individual functions for the |
| 54 // fields that are used. |
| 55 struct Change { |
| 56 Change(); |
| 57 ~Change(); |
| 58 |
| 59 ChangeType type; |
| 60 mojo::ConnectionSpecificId connection_id; |
| 61 std::vector<TestView> views; |
| 62 mojo::Id view_id; |
| 63 mojo::Id view_id2; |
| 64 mojo::Id view_id3; |
| 65 mojo::Rect bounds; |
| 66 mojo::Rect bounds2; |
| 67 int32_t event_action; |
| 68 mojo::String creator_url; |
| 69 mojo::String embed_url; |
| 70 mojo::OrderDirection direction; |
| 71 bool bool_value; |
| 72 std::string property_key; |
| 73 std::string property_value; |
| 74 }; |
| 75 |
| 76 // Converts Changes to string descriptions. |
| 77 std::vector<std::string> ChangesToDescription1( |
| 78 const std::vector<Change>& changes); |
| 79 |
| 80 // Convenience for returning the description of the first item in |changes|. |
| 81 // Returns an empty string if |changes| has something other than one entry. |
| 82 std::string SingleChangeToDescription(const std::vector<Change>& changes); |
| 83 |
| 84 // Convenience for returning the description of the first item in |views|. |
| 85 // Returns an empty string if |views| has something other than one entry. |
| 86 std::string SingleViewDescription(const std::vector<TestView>& views); |
| 87 |
| 88 // Returns a string description of |changes[0].views|. Returns an empty string |
| 89 // if change.size() != 1. |
| 90 std::string ChangeViewDescription(const std::vector<Change>& changes); |
| 91 |
| 92 // Converts ViewDatas to TestViews. |
| 93 void ViewDatasToTestViews(const mojo::Array<mojo::ViewDataPtr>& data, |
| 94 std::vector<TestView>* test_views); |
| 95 |
| 96 // TestChangeTracker is used to record ViewManagerClient functions. It notifies |
| 97 // a delegate any time a change is added. |
| 98 class TestChangeTracker { |
| 99 public: |
| 100 // Used to notify the delegate when a change is added. A change corresponds to |
| 101 // a single ViewManagerClient function. |
| 102 class Delegate { |
| 103 public: |
| 104 virtual void OnChangeAdded() = 0; |
| 105 |
| 106 protected: |
| 107 virtual ~Delegate() {} |
| 108 }; |
| 109 |
| 110 TestChangeTracker(); |
| 111 ~TestChangeTracker(); |
| 112 |
| 113 void set_delegate(Delegate* delegate) { |
| 114 delegate_ = delegate; |
| 115 } |
| 116 |
| 117 std::vector<Change>* changes() { return &changes_; } |
| 118 |
| 119 // Each of these functions generate a Change. There is one per |
| 120 // ViewManagerClient function. |
| 121 void OnEmbed(mojo::ConnectionSpecificId connection_id, |
| 122 const mojo::String& creator_url, |
| 123 mojo::ViewDataPtr root); |
| 124 void OnEmbeddedAppDisconnected(mojo::Id view_id); |
| 125 void OnViewBoundsChanged(mojo::Id view_id, |
| 126 mojo::RectPtr old_bounds, |
| 127 mojo::RectPtr new_bounds); |
| 128 void OnViewViewportMetricsChanged(mojo::ViewportMetricsPtr old_bounds, |
| 129 mojo::ViewportMetricsPtr new_bounds); |
| 130 void OnViewHierarchyChanged(mojo::Id view_id, |
| 131 mojo::Id new_parent_id, |
| 132 mojo::Id old_parent_id, |
| 133 mojo::Array<mojo::ViewDataPtr> views); |
| 134 void OnViewReordered(mojo::Id view_id, |
| 135 mojo::Id relative_view_id, |
| 136 mojo::OrderDirection direction); |
| 137 void OnViewDeleted(mojo::Id view_id); |
| 138 void OnViewVisibilityChanged(mojo::Id view_id, bool visible); |
| 139 void OnViewDrawnStateChanged(mojo::Id view_id, bool drawn); |
| 140 void OnViewInputEvent(mojo::Id view_id, mojo::EventPtr event); |
| 141 void OnViewSharedPropertyChanged(mojo::Id view_id, |
| 142 mojo::String name, |
| 143 mojo::Array<uint8_t> data); |
| 144 void DelegateEmbed(const mojo::String& url); |
| 145 |
| 146 private: |
| 147 void AddChange(const Change& change); |
| 148 |
| 149 Delegate* delegate_; |
| 150 std::vector<Change> changes_; |
| 151 |
| 152 DISALLOW_COPY_AND_ASSIGN(TestChangeTracker); |
| 153 }; |
| 154 |
| 155 } // namespace view_manager |
| 156 |
| 157 #endif // SERVICES_VIEW_MANAGER_TEST_CHANGE_TRACKER_H_ |
OLD | NEW |