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 "mojo/services/public/cpp/view_manager/view_manager.h" | 5 #include "mojo/services/public/cpp/view_manager/view_manager.h" |
6 | 6 |
7 #include "base/auto_reset.h" | 7 #include "base/auto_reset.h" |
8 #include "base/bind.h" | 8 #include "base/bind.h" |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "mojo/public/cpp/application/application_connection.h" | 10 #include "mojo/public/cpp/application/application_connection.h" |
11 #include "mojo/public/cpp/application/application_delegate.h" | 11 #include "mojo/public/cpp/application/application_delegate.h" |
12 #include "mojo/public/cpp/application/application_impl.h" | 12 #include "mojo/public/cpp/application/application_impl.h" |
13 #include "mojo/service_manager/service_manager.h" | 13 #include "mojo/service_manager/service_manager.h" |
14 #include "mojo/services/public/cpp/view_manager/lib/node_private.h" | 14 #include "mojo/services/public/cpp/view_manager/lib/node_private.h" |
15 #include "mojo/services/public/cpp/view_manager/lib/view_manager_client_impl.h" | 15 #include "mojo/services/public/cpp/view_manager/lib/view_manager_client_impl.h" |
16 #include "mojo/services/public/cpp/view_manager/node_observer.h" | 16 #include "mojo/services/public/cpp/view_manager/node_observer.h" |
17 #include "mojo/services/public/cpp/view_manager/util.h" | 17 #include "mojo/services/public/cpp/view_manager/util.h" |
18 #include "mojo/services/public/cpp/view_manager/view.h" | 18 #include "mojo/services/public/cpp/view_manager/view.h" |
| 19 #include "mojo/services/public/cpp/view_manager/view_manager_client_factory.h" |
19 #include "mojo/services/public/cpp/view_manager/view_manager_delegate.h" | 20 #include "mojo/services/public/cpp/view_manager/view_manager_delegate.h" |
20 #include "mojo/services/public/cpp/view_manager/view_observer.h" | 21 #include "mojo/services/public/cpp/view_manager/view_observer.h" |
21 #include "mojo/shell/shell_test_helper.h" | 22 #include "mojo/shell/shell_test_helper.h" |
22 #include "testing/gtest/include/gtest/gtest.h" | 23 #include "testing/gtest/include/gtest/gtest.h" |
23 | 24 |
24 namespace mojo { | 25 namespace mojo { |
25 namespace view_manager { | 26 namespace view_manager { |
26 namespace { | 27 namespace { |
27 | 28 |
28 const char kWindowManagerURL[] = "mojo:window_manager"; | 29 const char kWindowManagerURL[] = "mojo:window_manager"; |
(...skipping 18 matching lines...) Expand all Loading... |
47 client->ClearChangesAckedCallback(); | 48 client->ClearChangesAckedCallback(); |
48 } | 49 } |
49 | 50 |
50 class ConnectServiceLoader : public ServiceLoader, | 51 class ConnectServiceLoader : public ServiceLoader, |
51 public ApplicationDelegate, | 52 public ApplicationDelegate, |
52 public ViewManagerDelegate { | 53 public ViewManagerDelegate { |
53 public: | 54 public: |
54 typedef base::Callback<void(ViewManager*, Node*)> LoadedCallback; | 55 typedef base::Callback<void(ViewManager*, Node*)> LoadedCallback; |
55 | 56 |
56 explicit ConnectServiceLoader(const LoadedCallback& callback) | 57 explicit ConnectServiceLoader(const LoadedCallback& callback) |
57 : callback_(callback) { | 58 : callback_(callback), view_manager_client_factory_(this) {} |
58 } | |
59 virtual ~ConnectServiceLoader() {} | 59 virtual ~ConnectServiceLoader() {} |
60 | 60 |
61 private: | 61 private: |
62 // Overridden from ServiceLoader: | 62 // Overridden from ServiceLoader: |
63 virtual void LoadService(ServiceManager* manager, | 63 virtual void LoadService(ServiceManager* manager, |
64 const GURL& url, | 64 const GURL& url, |
65 ScopedMessagePipeHandle shell_handle) OVERRIDE { | 65 ScopedMessagePipeHandle shell_handle) OVERRIDE { |
66 scoped_ptr<ApplicationImpl> app(new ApplicationImpl(this, | 66 scoped_ptr<ApplicationImpl> app(new ApplicationImpl(this, |
67 shell_handle.Pass())); | 67 shell_handle.Pass())); |
68 apps_.push_back(app.release()); | 68 apps_.push_back(app.release()); |
69 } | 69 } |
70 | 70 |
71 virtual void OnServiceError(ServiceManager* manager, | 71 virtual void OnServiceError(ServiceManager* manager, |
72 const GURL& url) OVERRIDE { | 72 const GURL& url) OVERRIDE { |
73 } | 73 } |
74 | 74 |
75 virtual bool ConfigureIncomingConnection(ApplicationConnection* connection) | 75 virtual bool ConfigureIncomingConnection(ApplicationConnection* connection) |
76 OVERRIDE { | 76 OVERRIDE { |
77 ViewManager::ConfigureIncomingConnection(connection, this); | 77 connection->AddService(&view_manager_client_factory_); |
78 return true; | 78 return true; |
79 } | 79 } |
80 | 80 |
81 // Overridden from ViewManagerDelegate: | 81 // Overridden from ViewManagerDelegate: |
82 virtual void OnRootAdded(ViewManager* view_manager, | 82 virtual void OnRootAdded(ViewManager* view_manager, |
83 Node* root) OVERRIDE { | 83 Node* root) OVERRIDE { |
84 callback_.Run(view_manager, root); | 84 callback_.Run(view_manager, root); |
85 } | 85 } |
86 virtual void OnViewManagerDisconnected(ViewManager* view_manager) OVERRIDE {} | 86 virtual void OnViewManagerDisconnected(ViewManager* view_manager) OVERRIDE {} |
87 | 87 |
88 ScopedVector<ApplicationImpl> apps_; | 88 ScopedVector<ApplicationImpl> apps_; |
89 LoadedCallback callback_; | 89 LoadedCallback callback_; |
| 90 ViewManagerClientFactory view_manager_client_factory_; |
90 | 91 |
91 DISALLOW_COPY_AND_ASSIGN(ConnectServiceLoader); | 92 DISALLOW_COPY_AND_ASSIGN(ConnectServiceLoader); |
92 }; | 93 }; |
93 | 94 |
94 class ActiveViewChangedObserver : public NodeObserver { | 95 class ActiveViewChangedObserver : public NodeObserver { |
95 public: | 96 public: |
96 explicit ActiveViewChangedObserver(Node* node) | 97 explicit ActiveViewChangedObserver(Node* node) |
97 : node_(node) {} | 98 : node_(node) {} |
98 virtual ~ActiveViewChangedObserver() {} | 99 virtual ~ActiveViewChangedObserver() {} |
99 | 100 |
(...skipping 290 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
390 connect_loop_->Quit(); | 391 connect_loop_->Quit(); |
391 } | 392 } |
392 | 393 |
393 void RunRunLoop() { | 394 void RunRunLoop() { |
394 base::RunLoop run_loop; | 395 base::RunLoop run_loop; |
395 connect_loop_ = &run_loop; | 396 connect_loop_ = &run_loop; |
396 connect_loop_->Run(); | 397 connect_loop_->Run(); |
397 connect_loop_ = NULL; | 398 connect_loop_ = NULL; |
398 } | 399 } |
399 | 400 |
400 base::MessageLoop loop_; | |
401 base::RunLoop* connect_loop_; | 401 base::RunLoop* connect_loop_; |
402 shell::ShellTestHelper test_helper_; | 402 shell::ShellTestHelper test_helper_; |
| 403 base::MessageLoop loop_; |
403 ViewManagerInitServicePtr view_manager_init_; | 404 ViewManagerInitServicePtr view_manager_init_; |
404 // Used to receive the most recent view manager loaded by an embed action. | 405 // Used to receive the most recent view manager loaded by an embed action. |
405 ViewManager* loaded_view_manager_; | 406 ViewManager* loaded_view_manager_; |
406 // The View Manager connection held by the window manager (app running at the | 407 // The View Manager connection held by the window manager (app running at the |
407 // root node). | 408 // root node). |
408 ViewManager* window_manager_; | 409 ViewManager* window_manager_; |
409 int commit_count_; | 410 int commit_count_; |
410 | 411 |
411 DISALLOW_COPY_AND_ASSIGN(ViewManagerTest); | 412 DISALLOW_COPY_AND_ASSIGN(ViewManagerTest); |
412 }; | 413 }; |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
501 nested->Destroy(); | 502 nested->Destroy(); |
502 | 503 |
503 std::set<Id> nodes; | 504 std::set<Id> nodes; |
504 nodes.insert(id); | 505 nodes.insert(id); |
505 WaitForDestruction(embedded, &nodes, NULL); | 506 WaitForDestruction(embedded, &nodes, NULL); |
506 | 507 |
507 EXPECT_TRUE(embedded->GetRoots().front()->children().empty()); | 508 EXPECT_TRUE(embedded->GetRoots().front()->children().empty()); |
508 EXPECT_EQ(NULL, embedded->GetNodeById(id)); | 509 EXPECT_EQ(NULL, embedded->GetNodeById(id)); |
509 } | 510 } |
510 | 511 |
511 TEST_F(ViewManagerTest, ViewManagerDestroyed_CleanupNode) { | 512 // http://crbug.com/396300 |
| 513 TEST_F(ViewManagerTest, DISABLED_ViewManagerDestroyed_CleanupNode) { |
512 Node* node = Node::Create(window_manager()); | 514 Node* node = Node::Create(window_manager()); |
513 window_manager()->GetRoots().front()->AddChild(node); | 515 window_manager()->GetRoots().front()->AddChild(node); |
514 ViewManager* embedded = Embed(window_manager(), node); | 516 ViewManager* embedded = Embed(window_manager(), node); |
515 | 517 |
516 Id node_id = node->id(); | 518 Id node_id = node->id(); |
517 | 519 |
518 UnloadApplication(GURL(kWindowManagerURL)); | 520 UnloadApplication(GURL(kWindowManagerURL)); |
519 | 521 |
520 std::set<Id> nodes; | 522 std::set<Id> nodes; |
521 nodes.insert(node_id); | 523 nodes.insert(node_id); |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
556 | 558 |
557 std::set<Id> views; | 559 std::set<Id> views; |
558 views.insert(view_id); | 560 views.insert(view_id); |
559 WaitForDestruction(embedded, NULL, &views); | 561 WaitForDestruction(embedded, NULL, &views); |
560 EXPECT_EQ(NULL, node_in_embedded->active_view()); | 562 EXPECT_EQ(NULL, node_in_embedded->active_view()); |
561 EXPECT_EQ(NULL, embedded->GetViewById(view_id)); | 563 EXPECT_EQ(NULL, embedded->GetViewById(view_id)); |
562 } | 564 } |
563 | 565 |
564 // Destroying the connection that created a node and view should result in that | 566 // Destroying the connection that created a node and view should result in that |
565 // node and view disappearing from all connections that see them. | 567 // node and view disappearing from all connections that see them. |
566 TEST_F(ViewManagerTest, ViewManagerDestroyed_CleanupNodeAndView) { | 568 // http://crbug.com/396300 |
| 569 TEST_F(ViewManagerTest, DISABLED_ViewManagerDestroyed_CleanupNodeAndView) { |
567 Node* node = Node::Create(window_manager()); | 570 Node* node = Node::Create(window_manager()); |
568 window_manager()->GetRoots().front()->AddChild(node); | 571 window_manager()->GetRoots().front()->AddChild(node); |
569 View* view = View::Create(window_manager()); | 572 View* view = View::Create(window_manager()); |
570 node->SetActiveView(view); | 573 node->SetActiveView(view); |
571 ViewManager* embedded = Embed(window_manager(), node); | 574 ViewManager* embedded = Embed(window_manager(), node); |
572 | 575 |
573 Id node_id = node->id(); | 576 Id node_id = node->id(); |
574 Id view_id = view->id(); | 577 Id view_id = view->id(); |
575 | 578 |
576 UnloadApplication(GURL(kWindowManagerURL)); | 579 UnloadApplication(GURL(kWindowManagerURL)); |
577 | 580 |
578 std::set<Id> observed_nodes; | 581 std::set<Id> observed_nodes; |
579 observed_nodes.insert(node_id); | 582 observed_nodes.insert(node_id); |
580 std::set<Id> observed_views; | 583 std::set<Id> observed_views; |
581 observed_views.insert(view_id); | 584 observed_views.insert(view_id); |
582 WaitForDestruction(embedded, &observed_nodes, &observed_views); | 585 WaitForDestruction(embedded, &observed_nodes, &observed_views); |
583 | 586 |
584 EXPECT_TRUE(embedded->GetRoots().empty()); | 587 EXPECT_TRUE(embedded->GetRoots().empty()); |
585 EXPECT_EQ(NULL, embedded->GetNodeById(node_id)); | 588 EXPECT_EQ(NULL, embedded->GetNodeById(node_id)); |
586 EXPECT_EQ(NULL, embedded->GetViewById(view_id)); | 589 EXPECT_EQ(NULL, embedded->GetViewById(view_id)); |
587 } | 590 } |
588 | 591 |
589 // This test validates the following scenario: | 592 // This test validates the following scenario: |
590 // - a node originating from one connection | 593 // - a node originating from one connection |
591 // - a view originating from a second connection | 594 // - a view originating from a second connection |
592 // + the connection originating the node is destroyed | 595 // + the connection originating the node is destroyed |
593 // -> the view should still exist (since the second connection is live) but | 596 // -> the view should still exist (since the second connection is live) but |
594 // should be disconnected from any nodes. | 597 // should be disconnected from any nodes. |
595 TEST_F(ViewManagerTest, | 598 // http://crbug.com/396300 |
596 ViewManagerDestroyed_CleanupNodeAndViewFromDifferentConnections) { | 599 TEST_F( |
| 600 ViewManagerTest, |
| 601 DISABLED_ViewManagerDestroyed_CleanupNodeAndViewFromDifferentConnections) { |
597 Node* node = Node::Create(window_manager()); | 602 Node* node = Node::Create(window_manager()); |
598 window_manager()->GetRoots().front()->AddChild(node); | 603 window_manager()->GetRoots().front()->AddChild(node); |
599 ViewManager* embedded = Embed(window_manager(), node); | 604 ViewManager* embedded = Embed(window_manager(), node); |
600 View* view_in_embedded = View::Create(embedded); | 605 View* view_in_embedded = View::Create(embedded); |
601 Node* node_in_embedded = embedded->GetNodeById(node->id()); | 606 Node* node_in_embedded = embedded->GetNodeById(node->id()); |
602 node_in_embedded->SetActiveView(view_in_embedded); | 607 node_in_embedded->SetActiveView(view_in_embedded); |
603 | 608 |
604 WaitForActiveViewToChange(node); | 609 WaitForActiveViewToChange(node); |
605 | 610 |
606 Id node_id = node->id(); | 611 Id node_id = node->id(); |
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
768 // TODO(beng): tests for view event dispatcher. | 773 // TODO(beng): tests for view event dispatcher. |
769 // - verify that we see events for all views. | 774 // - verify that we see events for all views. |
770 | 775 |
771 // TODO(beng): tests for focus: | 776 // TODO(beng): tests for focus: |
772 // - focus between two nodes known to a connection | 777 // - focus between two nodes known to a connection |
773 // - focus between nodes unknown to one of the connections. | 778 // - focus between nodes unknown to one of the connections. |
774 // - focus between nodes unknown to either connection. | 779 // - focus between nodes unknown to either connection. |
775 | 780 |
776 } // namespace view_manager | 781 } // namespace view_manager |
777 } // namespace mojo | 782 } // namespace mojo |
OLD | NEW |