| 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 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 57 | 57 |
| 58 // Runs a message loop until the single instance has been created. | 58 // Runs a message loop until the single instance has been created. |
| 59 static ViewManagerProxy* WaitForInstance() { | 59 static ViewManagerProxy* WaitForInstance() { |
| 60 if (!instance_) | 60 if (!instance_) |
| 61 RunMainLoop(); | 61 RunMainLoop(); |
| 62 ViewManagerProxy* instance = instance_; | 62 ViewManagerProxy* instance = instance_; |
| 63 instance_ = NULL; | 63 instance_ = NULL; |
| 64 return instance; | 64 return instance; |
| 65 } | 65 } |
| 66 | 66 |
| 67 ViewManagerService* view_manager() { return view_manager_; } |
| 68 |
| 67 // Runs the main loop until |count| changes have been received. | 69 // Runs the main loop until |count| changes have been received. |
| 68 std::vector<Change> DoRunLoopUntilChangesCount(size_t count) { | 70 std::vector<Change> DoRunLoopUntilChangesCount(size_t count) { |
| 69 DCHECK_EQ(0u, quit_count_); | 71 DCHECK_EQ(0u, quit_count_); |
| 70 if (tracker_->changes()->size() >= count) { | 72 if (tracker_->changes()->size() >= count) { |
| 71 CopyChangesFromTracker(); | 73 CopyChangesFromTracker(); |
| 72 return changes_; | 74 return changes_; |
| 73 } | 75 } |
| 74 quit_count_ = count - tracker_->changes()->size(); | 76 quit_count_ = count - tracker_->changes()->size(); |
| 75 // Run the current message loop. When |count| Changes have been received, | 77 // Run the current message loop. When |count| Changes have been received, |
| 76 // we'll quit. | 78 // we'll quit. |
| (...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 284 TestViewManagerClientConnection() : connection_(&tracker_) { | 286 TestViewManagerClientConnection() : connection_(&tracker_) { |
| 285 tracker_.set_delegate(&connection_); | 287 tracker_.set_delegate(&connection_); |
| 286 } | 288 } |
| 287 | 289 |
| 288 // InterfaceImp: | 290 // InterfaceImp: |
| 289 virtual void OnConnectionEstablished() OVERRIDE { | 291 virtual void OnConnectionEstablished() OVERRIDE { |
| 290 connection_.set_router(internal_state()->router()); | 292 connection_.set_router(internal_state()->router()); |
| 291 connection_.set_view_manager(client()); | 293 connection_.set_view_manager(client()); |
| 292 } | 294 } |
| 293 | 295 |
| 294 // IViewMangerClient: | 296 // ViewMangerClient: |
| 295 virtual void OnViewManagerConnectionEstablished( | 297 virtual void OnViewManagerConnectionEstablished( |
| 296 ConnectionSpecificId connection_id, | 298 ConnectionSpecificId connection_id, |
| 297 const String& creator_url, | 299 const String& creator_url, |
| 298 Id next_server_change_id, | 300 Id next_server_change_id, |
| 299 Array<NodeDataPtr> nodes) OVERRIDE { | 301 Array<NodeDataPtr> nodes) OVERRIDE { |
| 300 tracker_.OnViewManagerConnectionEstablished( | 302 tracker_.OnViewManagerConnectionEstablished( |
| 301 connection_id, creator_url, next_server_change_id, nodes.Pass()); | 303 connection_id, creator_url, next_server_change_id, nodes.Pass()); |
| 302 } | 304 } |
| 303 virtual void OnRootsAdded(Array<NodeDataPtr> nodes) OVERRIDE { | 305 virtual void OnRootsAdded(Array<NodeDataPtr> nodes) OVERRIDE { |
| 304 tracker_.OnRootsAdded(nodes.Pass()); | 306 tracker_.OnRootsAdded(nodes.Pass()); |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 336 virtual void OnNodeViewReplaced(Id node, | 338 virtual void OnNodeViewReplaced(Id node, |
| 337 Id new_view_id, | 339 Id new_view_id, |
| 338 Id old_view_id) OVERRIDE { | 340 Id old_view_id) OVERRIDE { |
| 339 tracker_.OnNodeViewReplaced(node, new_view_id, old_view_id); | 341 tracker_.OnNodeViewReplaced(node, new_view_id, old_view_id); |
| 340 } | 342 } |
| 341 virtual void OnViewInputEvent(Id view_id, | 343 virtual void OnViewInputEvent(Id view_id, |
| 342 EventPtr event, | 344 EventPtr event, |
| 343 const Callback<void()>& callback) OVERRIDE { | 345 const Callback<void()>& callback) OVERRIDE { |
| 344 tracker_.OnViewInputEvent(view_id, event.Pass()); | 346 tracker_.OnViewInputEvent(view_id, event.Pass()); |
| 345 } | 347 } |
| 348 virtual void DispatchOnViewInputEvent(Id view_id, |
| 349 mojo::EventPtr event) OVERRIDE { |
| 350 } |
| 346 | 351 |
| 347 private: | 352 private: |
| 348 TestChangeTracker tracker_; | 353 TestChangeTracker tracker_; |
| 349 ViewManagerProxy connection_; | 354 ViewManagerProxy connection_; |
| 350 | 355 |
| 351 DISALLOW_COPY_AND_ASSIGN(TestViewManagerClientConnection); | 356 DISALLOW_COPY_AND_ASSIGN(TestViewManagerClientConnection); |
| 352 }; | 357 }; |
| 353 | 358 |
| 354 // Used with ViewManagerService::Embed(). Creates a | 359 // Used with ViewManagerService::Embed(). Creates a |
| 355 // TestViewManagerClientConnection, which creates and owns the ViewManagerProxy. | 360 // TestViewManagerClientConnection, which creates and owns the ViewManagerProxy. |
| (...skipping 966 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1322 ASSERT_TRUE(connection_->Embed(node_ids)); | 1327 ASSERT_TRUE(connection_->Embed(node_ids)); |
| 1323 connection2_->DoRunLoopUntilChangesCount(1); | 1328 connection2_->DoRunLoopUntilChangesCount(1); |
| 1324 const Changes changes(ChangesToDescription1(connection2_->changes())); | 1329 const Changes changes(ChangesToDescription1(connection2_->changes())); |
| 1325 ASSERT_EQ(1u, changes.size()); | 1330 ASSERT_EQ(1u, changes.size()); |
| 1326 EXPECT_EQ("OnRootsAdded", changes[0]); | 1331 EXPECT_EQ("OnRootsAdded", changes[0]); |
| 1327 EXPECT_EQ("[node=1,2 parent=1,1 view=null]", | 1332 EXPECT_EQ("[node=1,2 parent=1,1 view=null]", |
| 1328 ChangeNodeDescription(connection2_->changes())); | 1333 ChangeNodeDescription(connection2_->changes())); |
| 1329 } | 1334 } |
| 1330 } | 1335 } |
| 1331 | 1336 |
| 1337 TEST_F(ViewManagerTest, OnViewInput) { |
| 1338 // Create node 1 and assign a view from connection 2 to it. |
| 1339 ASSERT_TRUE(connection_->CreateNode(BuildNodeId(1, 1))); |
| 1340 ASSERT_NO_FATAL_FAILURE(EstablishSecondConnection(false)); |
| 1341 ASSERT_TRUE(connection2_->CreateView(BuildViewId(2, 11))); |
| 1342 ASSERT_TRUE(connection2_->SetView(BuildNodeId(1, 1), BuildViewId(2, 11))); |
| 1343 |
| 1344 // Dispatch an event to the view and verify its received. |
| 1345 { |
| 1346 EventPtr event(Event::New()); |
| 1347 event->action = 1; |
| 1348 connection_->view_manager()->DispatchOnViewInputEvent( |
| 1349 BuildViewId(2, 11), |
| 1350 event.Pass()); |
| 1351 connection2_->DoRunLoopUntilChangesCount(1); |
| 1352 const Changes changes(ChangesToDescription1(connection2_->changes())); |
| 1353 ASSERT_EQ(1u, changes.size()); |
| 1354 EXPECT_EQ("InputEvent view=2,11 event_action=1", changes[0]); |
| 1355 } |
| 1356 } |
| 1357 |
| 1332 // TODO(sky): add coverage of test that destroys connections and ensures other | 1358 // TODO(sky): add coverage of test that destroys connections and ensures other |
| 1333 // connections get deletion notification (or advanced server id). | 1359 // connections get deletion notification (or advanced server id). |
| 1334 | 1360 |
| 1335 // TODO(sky): need to better track changes to initial connection. For example, | 1361 // TODO(sky): need to better track changes to initial connection. For example, |
| 1336 // that SetBounsdNodes/AddNode and the like don't result in messages to the | 1362 // that SetBounsdNodes/AddNode and the like don't result in messages to the |
| 1337 // originating connection. | 1363 // originating connection. |
| 1338 | 1364 |
| 1339 } // namespace service | 1365 } // namespace service |
| 1340 } // namespace view_manager | 1366 } // namespace view_manager |
| 1341 } // namespace mojo | 1367 } // namespace mojo |
| OLD | NEW |