| 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 #include <string> | 5 #include <string> |
| 6 #include <vector> | 6 #include <vector> |
| 7 | 7 |
| 8 #include "base/at_exit.h" | 8 #include "base/at_exit.h" |
| 9 #include "base/auto_reset.h" | 9 #include "base/auto_reset.h" |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 101 std::vector<Change> changes; | 101 std::vector<Change> changes; |
| 102 tracker_->changes()->swap(changes); | 102 tracker_->changes()->swap(changes); |
| 103 changes_.swap(changes); | 103 changes_.swap(changes); |
| 104 } | 104 } |
| 105 | 105 |
| 106 // The following functions are cover methods for ViewManagerService. They | 106 // The following functions are cover methods for ViewManagerService. They |
| 107 // block until the result is received. | 107 // block until the result is received. |
| 108 bool CreateNode(Id node_id) { | 108 bool CreateNode(Id node_id) { |
| 109 changes_.clear(); | 109 changes_.clear(); |
| 110 ErrorCode result = ERROR_CODE_NONE; | 110 ErrorCode result = ERROR_CODE_NONE; |
| 111 view_manager_->CreateNode( | 111 view_manager_->CreateView( |
| 112 node_id, | 112 node_id, |
| 113 base::Bind(&ViewManagerProxy::GotResultWithErrorCode, | 113 base::Bind(&ViewManagerProxy::GotResultWithErrorCode, |
| 114 base::Unretained(this), &result)); | 114 base::Unretained(this), &result)); |
| 115 RunMainLoop(); | 115 RunMainLoop(); |
| 116 return result == ERROR_CODE_NONE; | 116 return result == ERROR_CODE_NONE; |
| 117 } | 117 } |
| 118 ErrorCode CreateNodeWithErrorCode(Id node_id) { | 118 ErrorCode CreateNodeWithErrorCode(Id node_id) { |
| 119 changes_.clear(); | 119 changes_.clear(); |
| 120 ErrorCode result = ERROR_CODE_NONE; | 120 ErrorCode result = ERROR_CODE_NONE; |
| 121 view_manager_->CreateNode( | 121 view_manager_->CreateView( |
| 122 node_id, | 122 node_id, |
| 123 base::Bind(&ViewManagerProxy::GotResultWithErrorCode, | 123 base::Bind(&ViewManagerProxy::GotResultWithErrorCode, |
| 124 base::Unretained(this), &result)); | 124 base::Unretained(this), &result)); |
| 125 RunMainLoop(); | 125 RunMainLoop(); |
| 126 return result; | 126 return result; |
| 127 } | 127 } |
| 128 bool AddNode(Id parent, Id child) { | 128 bool AddNode(Id parent, Id child) { |
| 129 changes_.clear(); | 129 changes_.clear(); |
| 130 bool result = false; | 130 bool result = false; |
| 131 view_manager_->AddNode(parent, child, | 131 view_manager_->AddView(parent, child, |
| 132 base::Bind(&ViewManagerProxy::GotResult, | 132 base::Bind(&ViewManagerProxy::GotResult, |
| 133 base::Unretained(this), &result)); | 133 base::Unretained(this), &result)); |
| 134 RunMainLoop(); | 134 RunMainLoop(); |
| 135 return result; | 135 return result; |
| 136 } | 136 } |
| 137 bool RemoveNodeFromParent(Id node_id) { | 137 bool RemoveNodeFromParent(Id node_id) { |
| 138 changes_.clear(); | 138 changes_.clear(); |
| 139 bool result = false; | 139 bool result = false; |
| 140 view_manager_->RemoveNodeFromParent(node_id, | 140 view_manager_->RemoveViewFromParent(node_id, |
| 141 base::Bind(&ViewManagerProxy::GotResult, | 141 base::Bind(&ViewManagerProxy::GotResult, |
| 142 base::Unretained(this), &result)); | 142 base::Unretained(this), &result)); |
| 143 RunMainLoop(); | 143 RunMainLoop(); |
| 144 return result; | 144 return result; |
| 145 } | 145 } |
| 146 bool ReorderNode(Id node_id, | 146 bool ReorderNode(Id node_id, |
| 147 Id relative_node_id, | 147 Id relative_node_id, |
| 148 OrderDirection direction) { | 148 OrderDirection direction) { |
| 149 changes_.clear(); | 149 changes_.clear(); |
| 150 bool result = false; | 150 bool result = false; |
| 151 view_manager_->ReorderNode(node_id, relative_node_id, direction, | 151 view_manager_->ReorderView(node_id, relative_node_id, direction, |
| 152 base::Bind(&ViewManagerProxy::GotResult, | 152 base::Bind(&ViewManagerProxy::GotResult, |
| 153 base::Unretained(this), &result)); | 153 base::Unretained(this), &result)); |
| 154 RunMainLoop(); | 154 RunMainLoop(); |
| 155 return result; | 155 return result; |
| 156 } | 156 } |
| 157 void GetNodeTree(Id node_id, std::vector<TestNode>* nodes) { | 157 void GetNodeTree(Id node_id, std::vector<TestNode>* nodes) { |
| 158 changes_.clear(); | 158 changes_.clear(); |
| 159 view_manager_->GetNodeTree(node_id, | 159 view_manager_->GetViewTree(node_id, |
| 160 base::Bind(&ViewManagerProxy::GotNodeTree, | 160 base::Bind(&ViewManagerProxy::GotNodeTree, |
| 161 base::Unretained(this), nodes)); | 161 base::Unretained(this), nodes)); |
| 162 RunMainLoop(); | 162 RunMainLoop(); |
| 163 } | 163 } |
| 164 bool Embed(const Id node_id, const char* url) { | 164 bool Embed(const Id node_id, const char* url) { |
| 165 changes_.clear(); | 165 changes_.clear(); |
| 166 base::AutoReset<bool> auto_reset(&in_embed_, true); | 166 base::AutoReset<bool> auto_reset(&in_embed_, true); |
| 167 bool result = false; | 167 bool result = false; |
| 168 ServiceProviderPtr services; | 168 ServiceProviderPtr services; |
| 169 view_manager_->Embed(url, node_id, services.Pass(), | 169 view_manager_->Embed(url, node_id, services.Pass(), |
| 170 base::Bind(&ViewManagerProxy::GotResult, | 170 base::Bind(&ViewManagerProxy::GotResult, |
| 171 base::Unretained(this), &result)); | 171 base::Unretained(this), &result)); |
| 172 RunMainLoop(); | 172 RunMainLoop(); |
| 173 return result; | 173 return result; |
| 174 } | 174 } |
| 175 bool DeleteNode(Id node_id) { | 175 bool DeleteNode(Id node_id) { |
| 176 changes_.clear(); | 176 changes_.clear(); |
| 177 bool result = false; | 177 bool result = false; |
| 178 view_manager_->DeleteNode(node_id, | 178 view_manager_->DeleteView(node_id, |
| 179 base::Bind(&ViewManagerProxy::GotResult, | 179 base::Bind(&ViewManagerProxy::GotResult, |
| 180 base::Unretained(this), &result)); | 180 base::Unretained(this), &result)); |
| 181 RunMainLoop(); | 181 RunMainLoop(); |
| 182 return result; | 182 return result; |
| 183 } | 183 } |
| 184 bool SetNodeBounds(Id node_id, const gfx::Rect& bounds) { | 184 bool SetNodeBounds(Id node_id, const gfx::Rect& bounds) { |
| 185 changes_.clear(); | 185 changes_.clear(); |
| 186 bool result = false; | 186 bool result = false; |
| 187 view_manager_->SetNodeBounds(node_id, Rect::From(bounds), | 187 view_manager_->SetViewBounds(node_id, Rect::From(bounds), |
| 188 base::Bind(&ViewManagerProxy::GotResult, | 188 base::Bind(&ViewManagerProxy::GotResult, |
| 189 base::Unretained(this), &result)); | 189 base::Unretained(this), &result)); |
| 190 RunMainLoop(); | 190 RunMainLoop(); |
| 191 return result; | 191 return result; |
| 192 } | 192 } |
| 193 | 193 |
| 194 private: | 194 private: |
| 195 friend class TestViewManagerClientConnection; | 195 friend class TestViewManagerClientConnection; |
| 196 | 196 |
| 197 void set_router(mojo::internal::Router* router) { router_ = router; } | 197 void set_router(mojo::internal::Router* router) { router_ = router; } |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 231 main_run_loop_->Quit(); | 231 main_run_loop_->Quit(); |
| 232 } | 232 } |
| 233 | 233 |
| 234 void GotResultWithErrorCode(ErrorCode* error_code_cache, | 234 void GotResultWithErrorCode(ErrorCode* error_code_cache, |
| 235 ErrorCode error_code) { | 235 ErrorCode error_code) { |
| 236 *error_code_cache = error_code; | 236 *error_code_cache = error_code; |
| 237 DCHECK(main_run_loop_); | 237 DCHECK(main_run_loop_); |
| 238 main_run_loop_->Quit(); | 238 main_run_loop_->Quit(); |
| 239 } | 239 } |
| 240 | 240 |
| 241 void GotNodeTree(std::vector<TestNode>* nodes, Array<NodeDataPtr> results) { | 241 void GotNodeTree(std::vector<TestNode>* nodes, Array<ViewDataPtr> results) { |
| 242 NodeDatasToTestNodes(results, nodes); | 242 ViewDatasToTestNodes(results, nodes); |
| 243 DCHECK(main_run_loop_); | 243 DCHECK(main_run_loop_); |
| 244 main_run_loop_->Quit(); | 244 main_run_loop_->Quit(); |
| 245 } | 245 } |
| 246 | 246 |
| 247 // TestChangeTracker::Delegate: | 247 // TestChangeTracker::Delegate: |
| 248 virtual void OnChangeAdded() OVERRIDE { | 248 virtual void OnChangeAdded() OVERRIDE { |
| 249 if (quit_count_ > 0 && --quit_count_ == 0) | 249 if (quit_count_ > 0 && --quit_count_ == 0) |
| 250 QuitCountReached(); | 250 QuitCountReached(); |
| 251 } | 251 } |
| 252 | 252 |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 290 // InterfaceImpl: | 290 // InterfaceImpl: |
| 291 virtual void OnConnectionEstablished() OVERRIDE { | 291 virtual void OnConnectionEstablished() OVERRIDE { |
| 292 connection_.set_router(internal_state()->router()); | 292 connection_.set_router(internal_state()->router()); |
| 293 connection_.set_view_manager(client()); | 293 connection_.set_view_manager(client()); |
| 294 } | 294 } |
| 295 | 295 |
| 296 // ViewManagerClient: | 296 // ViewManagerClient: |
| 297 virtual void OnEmbed( | 297 virtual void OnEmbed( |
| 298 ConnectionSpecificId connection_id, | 298 ConnectionSpecificId connection_id, |
| 299 const String& creator_url, | 299 const String& creator_url, |
| 300 NodeDataPtr root, | 300 ViewDataPtr root, |
| 301 InterfaceRequest<ServiceProvider> services) OVERRIDE { | 301 InterfaceRequest<ServiceProvider> services) OVERRIDE { |
| 302 tracker_.OnEmbed(connection_id, creator_url, root.Pass()); | 302 tracker_.OnEmbed(connection_id, creator_url, root.Pass()); |
| 303 } | 303 } |
| 304 virtual void OnNodeBoundsChanged(Id node_id, | 304 virtual void OnViewBoundsChanged(Id node_id, |
| 305 RectPtr old_bounds, | 305 RectPtr old_bounds, |
| 306 RectPtr new_bounds) OVERRIDE { | 306 RectPtr new_bounds) OVERRIDE { |
| 307 tracker_.OnNodeBoundsChanged(node_id, old_bounds.Pass(), new_bounds.Pass()); | 307 tracker_.OnNodeBoundsChanged(node_id, old_bounds.Pass(), new_bounds.Pass()); |
| 308 } | 308 } |
| 309 virtual void OnNodeHierarchyChanged(Id node, | 309 virtual void OnViewHierarchyChanged(Id node, |
| 310 Id new_parent, | 310 Id new_parent, |
| 311 Id old_parent, | 311 Id old_parent, |
| 312 Array<NodeDataPtr> nodes) OVERRIDE { | 312 Array<ViewDataPtr> nodes) OVERRIDE { |
| 313 tracker_.OnNodeHierarchyChanged(node, new_parent, old_parent, nodes.Pass()); | 313 tracker_.OnNodeHierarchyChanged(node, new_parent, old_parent, nodes.Pass()); |
| 314 } | 314 } |
| 315 virtual void OnNodeReordered(Id node_id, | 315 virtual void OnViewReordered(Id node_id, |
| 316 Id relative_node_id, | 316 Id relative_node_id, |
| 317 OrderDirection direction) OVERRIDE { | 317 OrderDirection direction) OVERRIDE { |
| 318 tracker_.OnNodeReordered(node_id, relative_node_id, direction); | 318 tracker_.OnNodeReordered(node_id, relative_node_id, direction); |
| 319 } | 319 } |
| 320 virtual void OnNodeDeleted(Id node) OVERRIDE { | 320 virtual void OnViewDeleted(Id node) OVERRIDE { |
| 321 tracker_.OnNodeDeleted(node); | 321 tracker_.OnNodeDeleted(node); |
| 322 } | 322 } |
| 323 virtual void OnNodeInputEvent(Id node_id, | 323 virtual void OnViewInputEvent(Id node_id, |
| 324 EventPtr event, | 324 EventPtr event, |
| 325 const Callback<void()>& callback) OVERRIDE { | 325 const Callback<void()>& callback) OVERRIDE { |
| 326 tracker_.OnNodeInputEvent(node_id, event.Pass()); | 326 tracker_.OnNodeInputEvent(node_id, event.Pass()); |
| 327 } | 327 } |
| 328 virtual void OnFocusChanged(Id gained_focus_id, | 328 virtual void OnFocusChanged(Id gained_focus_id, |
| 329 Id lost_focus_id) OVERRIDE {} | 329 Id lost_focus_id) OVERRIDE {} |
| 330 virtual void Embed( | 330 virtual void Embed( |
| 331 const String& url, | 331 const String& url, |
| 332 InterfaceRequest<ServiceProvider> service_provider) OVERRIDE { | 332 InterfaceRequest<ServiceProvider> service_provider) OVERRIDE { |
| 333 tracker_.DelegateEmbed(url); | 333 tracker_.DelegateEmbed(url); |
| 334 } | 334 } |
| 335 virtual void DispatchOnNodeInputEvent(Id node_id, | 335 virtual void DispatchOnViewInputEvent(Id node_id, |
| 336 mojo::EventPtr event) OVERRIDE { | 336 mojo::EventPtr event) OVERRIDE { |
| 337 } | 337 } |
| 338 | 338 |
| 339 private: | 339 private: |
| 340 TestChangeTracker tracker_; | 340 TestChangeTracker tracker_; |
| 341 ViewManagerProxy connection_; | 341 ViewManagerProxy connection_; |
| 342 | 342 |
| 343 DISALLOW_COPY_AND_ASSIGN(TestViewManagerClientConnection); | 343 DISALLOW_COPY_AND_ASSIGN(TestViewManagerClientConnection); |
| 344 }; | 344 }; |
| 345 | 345 |
| (...skipping 825 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1171 } | 1171 } |
| 1172 | 1172 |
| 1173 TEST_F(ViewManagerTest, OnNodeInput) { | 1173 TEST_F(ViewManagerTest, OnNodeInput) { |
| 1174 ASSERT_TRUE(connection_->CreateNode(BuildNodeId(1, 1))); | 1174 ASSERT_TRUE(connection_->CreateNode(BuildNodeId(1, 1))); |
| 1175 ASSERT_NO_FATAL_FAILURE(EstablishSecondConnection(false)); | 1175 ASSERT_NO_FATAL_FAILURE(EstablishSecondConnection(false)); |
| 1176 | 1176 |
| 1177 // Dispatch an event to the node and verify its received. | 1177 // Dispatch an event to the node and verify its received. |
| 1178 { | 1178 { |
| 1179 EventPtr event(Event::New()); | 1179 EventPtr event(Event::New()); |
| 1180 event->action = static_cast<EventType>(1); | 1180 event->action = static_cast<EventType>(1); |
| 1181 connection_->view_manager()->DispatchOnNodeInputEvent( | 1181 connection_->view_manager()->DispatchOnViewInputEvent( |
| 1182 BuildNodeId(1, 1), | 1182 BuildNodeId(1, 1), |
| 1183 event.Pass()); | 1183 event.Pass()); |
| 1184 connection2_->DoRunLoopUntilChangesCount(1); | 1184 connection2_->DoRunLoopUntilChangesCount(1); |
| 1185 const Changes changes(ChangesToDescription1(connection2_->changes())); | 1185 const Changes changes(ChangesToDescription1(connection2_->changes())); |
| 1186 ASSERT_EQ(1u, changes.size()); | 1186 ASSERT_EQ(1u, changes.size()); |
| 1187 EXPECT_EQ("InputEvent node=1,1 event_action=1", changes[0]); | 1187 EXPECT_EQ("InputEvent node=1,1 event_action=1", changes[0]); |
| 1188 } | 1188 } |
| 1189 } | 1189 } |
| 1190 | 1190 |
| 1191 TEST_F(ViewManagerTest, EmbedWithSameNodeId) { | 1191 TEST_F(ViewManagerTest, EmbedWithSameNodeId) { |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1284 // that SetBounsdNodes/AddNode and the like don't result in messages to the | 1284 // that SetBounsdNodes/AddNode and the like don't result in messages to the |
| 1285 // originating connection. | 1285 // originating connection. |
| 1286 | 1286 |
| 1287 // TODO(beng): Add tests for focus: | 1287 // TODO(beng): Add tests for focus: |
| 1288 // - focus between two nodes known to a connection | 1288 // - focus between two nodes known to a connection |
| 1289 // - focus between nodes unknown to one of the connections. | 1289 // - focus between nodes unknown to one of the connections. |
| 1290 // - focus between nodes unknown to either connection. | 1290 // - focus between nodes unknown to either connection. |
| 1291 | 1291 |
| 1292 } // namespace service | 1292 } // namespace service |
| 1293 } // namespace mojo | 1293 } // namespace mojo |
| OLD | NEW |