| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef MOJO_SERVICES_VIEW_MANAGER_TEST_CHANGE_TRACKER_H_ | 5 #ifndef MOJO_SERVICES_VIEW_MANAGER_TEST_CHANGE_TRACKER_H_ |
| 6 #define MOJO_SERVICES_VIEW_MANAGER_TEST_CHANGE_TRACKER_H_ | 6 #define MOJO_SERVICES_VIEW_MANAGER_TEST_CHANGE_TRACKER_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| 11 #include "mojo/public/cpp/bindings/array.h" | 11 #include "mojo/public/cpp/bindings/array.h" |
| 12 #include "mojo/services/public/cpp/view_manager/types.h" | 12 #include "mojo/services/public/cpp/view_manager/types.h" |
| 13 #include "mojo/services/public/interfaces/view_manager/view_manager.mojom.h" | 13 #include "mojo/services/public/interfaces/view_manager/view_manager.mojom.h" |
| 14 #include "ui/gfx/rect.h" | 14 #include "ui/gfx/rect.h" |
| 15 | 15 |
| 16 namespace mojo { | 16 namespace mojo { |
| 17 namespace service { | 17 namespace service { |
| 18 | 18 |
| 19 enum ChangeType { | 19 enum ChangeType { |
| 20 CHANGE_TYPE_EMBED, | 20 CHANGE_TYPE_EMBED, |
| 21 CHANGE_TYPE_NODE_BOUNDS_CHANGED, | 21 CHANGE_TYPE_NODE_BOUNDS_CHANGED, |
| 22 CHANGE_TYPE_NODE_HIERARCHY_CHANGED, | 22 CHANGE_TYPE_NODE_HIERARCHY_CHANGED, |
| 23 CHANGE_TYPE_NODE_REORDERED, | 23 CHANGE_TYPE_NODE_REORDERED, |
| 24 CHANGE_TYPE_NODE_DELETED, | 24 CHANGE_TYPE_NODE_DELETED, |
| 25 CHANGE_TYPE_INPUT_EVENT, | 25 CHANGE_TYPE_INPUT_EVENT, |
| 26 CHANGE_TYPE_DELEGATE_EMBED, | 26 CHANGE_TYPE_DELEGATE_EMBED, |
| 27 }; | 27 }; |
| 28 | 28 |
| 29 // TODO(sky): consider nuking and converting directly to NodeData. | 29 // TODO(sky): consider nuking and converting directly to ViewData. |
| 30 struct TestNode { | 30 struct TestNode { |
| 31 // Returns a string description of this. | 31 // Returns a string description of this. |
| 32 std::string ToString() const; | 32 std::string ToString() const; |
| 33 | 33 |
| 34 Id parent_id; | 34 Id parent_id; |
| 35 Id node_id; | 35 Id node_id; |
| 36 }; | 36 }; |
| 37 | 37 |
| 38 // Tracks a call to ViewManagerClient. See the individual functions for the | 38 // Tracks a call to ViewManagerClient. See the individual functions for the |
| 39 // fields that are used. | 39 // fields that are used. |
| (...skipping 16 matching lines...) Expand all Loading... |
| 56 }; | 56 }; |
| 57 | 57 |
| 58 // Converts Changes to string descriptions. | 58 // Converts Changes to string descriptions. |
| 59 std::vector<std::string> ChangesToDescription1( | 59 std::vector<std::string> ChangesToDescription1( |
| 60 const std::vector<Change>& changes); | 60 const std::vector<Change>& changes); |
| 61 | 61 |
| 62 // Returns a string description of |changes[0].nodes|. Returns an empty string | 62 // Returns a string description of |changes[0].nodes|. Returns an empty string |
| 63 // if change.size() != 1. | 63 // if change.size() != 1. |
| 64 std::string ChangeNodeDescription(const std::vector<Change>& changes); | 64 std::string ChangeNodeDescription(const std::vector<Change>& changes); |
| 65 | 65 |
| 66 // Converts NodeDatas to TestNodes. | 66 // Converts ViewDatas to TestNodes. |
| 67 void NodeDatasToTestNodes(const Array<NodeDataPtr>& data, | 67 void ViewDatasToTestNodes(const Array<ViewDataPtr>& data, |
| 68 std::vector<TestNode>* test_nodes); | 68 std::vector<TestNode>* test_nodes); |
| 69 | 69 |
| 70 // TestChangeTracker is used to record ViewManagerClient functions. It notifies | 70 // TestChangeTracker is used to record ViewManagerClient functions. It notifies |
| 71 // a delegate any time a change is added. | 71 // a delegate any time a change is added. |
| 72 class TestChangeTracker { | 72 class TestChangeTracker { |
| 73 public: | 73 public: |
| 74 // Used to notify the delegate when a change is added. A change corresponds to | 74 // Used to notify the delegate when a change is added. A change corresponds to |
| 75 // a single ViewManagerClient function. | 75 // a single ViewManagerClient function. |
| 76 class Delegate { | 76 class Delegate { |
| 77 public: | 77 public: |
| 78 virtual void OnChangeAdded() = 0; | 78 virtual void OnChangeAdded() = 0; |
| 79 | 79 |
| 80 protected: | 80 protected: |
| 81 virtual ~Delegate() {} | 81 virtual ~Delegate() {} |
| 82 }; | 82 }; |
| 83 | 83 |
| 84 TestChangeTracker(); | 84 TestChangeTracker(); |
| 85 ~TestChangeTracker(); | 85 ~TestChangeTracker(); |
| 86 | 86 |
| 87 void set_delegate(Delegate* delegate) { | 87 void set_delegate(Delegate* delegate) { |
| 88 delegate_ = delegate; | 88 delegate_ = delegate; |
| 89 } | 89 } |
| 90 | 90 |
| 91 std::vector<Change>* changes() { return &changes_; } | 91 std::vector<Change>* changes() { return &changes_; } |
| 92 | 92 |
| 93 // Each of these functions generate a Change. There is one per | 93 // Each of these functions generate a Change. There is one per |
| 94 // ViewManagerClient function. | 94 // ViewManagerClient function. |
| 95 void OnEmbed(ConnectionSpecificId connection_id, | 95 void OnEmbed(ConnectionSpecificId connection_id, |
| 96 const String& creator_url, | 96 const String& creator_url, |
| 97 NodeDataPtr root); | 97 ViewDataPtr root); |
| 98 void OnNodeBoundsChanged(Id node_id, RectPtr old_bounds, RectPtr new_bounds); | 98 void OnNodeBoundsChanged(Id node_id, RectPtr old_bounds, RectPtr new_bounds); |
| 99 void OnNodeHierarchyChanged(Id node_id, | 99 void OnNodeHierarchyChanged(Id node_id, |
| 100 Id new_parent_id, | 100 Id new_parent_id, |
| 101 Id old_parent_id, | 101 Id old_parent_id, |
| 102 Array<NodeDataPtr> nodes); | 102 Array<ViewDataPtr> nodes); |
| 103 void OnNodeReordered(Id node_id, | 103 void OnNodeReordered(Id node_id, |
| 104 Id relative_node_id, | 104 Id relative_node_id, |
| 105 OrderDirection direction); | 105 OrderDirection direction); |
| 106 void OnNodeDeleted(Id node_id); | 106 void OnNodeDeleted(Id node_id); |
| 107 void OnNodeInputEvent(Id node_id, EventPtr event); | 107 void OnNodeInputEvent(Id node_id, EventPtr event); |
| 108 void DelegateEmbed(const String& url); | 108 void DelegateEmbed(const String& url); |
| 109 | 109 |
| 110 private: | 110 private: |
| 111 void AddChange(const Change& change); | 111 void AddChange(const Change& change); |
| 112 | 112 |
| 113 Delegate* delegate_; | 113 Delegate* delegate_; |
| 114 std::vector<Change> changes_; | 114 std::vector<Change> changes_; |
| 115 | 115 |
| 116 DISALLOW_COPY_AND_ASSIGN(TestChangeTracker); | 116 DISALLOW_COPY_AND_ASSIGN(TestChangeTracker); |
| 117 }; | 117 }; |
| 118 | 118 |
| 119 } // namespace service | 119 } // namespace service |
| 120 } // namespace mojo | 120 } // namespace mojo |
| 121 | 121 |
| 122 #endif // MOJO_SERVICES_VIEW_MANAGER_TEST_CHANGE_TRACKER_H_ | 122 #endif // MOJO_SERVICES_VIEW_MANAGER_TEST_CHANGE_TRACKER_H_ |
| OLD | NEW |