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/public/cpp/application/service_provider_impl.h" |
| 14 #include "mojo/public/interfaces/application/service_provider.mojom.h" |
13 #include "mojo/service_manager/service_manager.h" | 15 #include "mojo/service_manager/service_manager.h" |
14 #include "mojo/services/public/cpp/view_manager/lib/node_private.h" | 16 #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" | 17 #include "mojo/services/public/cpp/view_manager/lib/view_manager_client_impl.h" |
16 #include "mojo/services/public/cpp/view_manager/node_observer.h" | 18 #include "mojo/services/public/cpp/view_manager/node_observer.h" |
17 #include "mojo/services/public/cpp/view_manager/util.h" | 19 #include "mojo/services/public/cpp/view_manager/util.h" |
18 #include "mojo/services/public/cpp/view_manager/view.h" | 20 #include "mojo/services/public/cpp/view_manager/view.h" |
19 #include "mojo/services/public/cpp/view_manager/view_manager_client_factory.h" | 21 #include "mojo/services/public/cpp/view_manager/view_manager_client_factory.h" |
20 #include "mojo/services/public/cpp/view_manager/view_manager_delegate.h" | 22 #include "mojo/services/public/cpp/view_manager/view_manager_delegate.h" |
21 #include "mojo/services/public/cpp/view_manager/view_observer.h" | 23 #include "mojo/services/public/cpp/view_manager/view_observer.h" |
22 #include "mojo/shell/shell_test_helper.h" | 24 #include "mojo/shell/shell_test_helper.h" |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
65 const GURL& url) OVERRIDE { | 67 const GURL& url) OVERRIDE { |
66 } | 68 } |
67 | 69 |
68 virtual bool ConfigureIncomingConnection(ApplicationConnection* connection) | 70 virtual bool ConfigureIncomingConnection(ApplicationConnection* connection) |
69 OVERRIDE { | 71 OVERRIDE { |
70 connection->AddService(&view_manager_client_factory_); | 72 connection->AddService(&view_manager_client_factory_); |
71 return true; | 73 return true; |
72 } | 74 } |
73 | 75 |
74 // Overridden from ViewManagerDelegate: | 76 // Overridden from ViewManagerDelegate: |
75 virtual void OnEmbed(ViewManager* view_manager, Node* root) OVERRIDE { | 77 virtual void OnEmbed(ViewManager* view_manager, |
| 78 Node* root, |
| 79 ServiceProviderImpl* exported_services, |
| 80 scoped_ptr<ServiceProvider> imported_services) OVERRIDE { |
76 callback_.Run(view_manager, root); | 81 callback_.Run(view_manager, root); |
77 } | 82 } |
78 virtual void OnViewManagerDisconnected(ViewManager* view_manager) OVERRIDE {} | 83 virtual void OnViewManagerDisconnected(ViewManager* view_manager) OVERRIDE {} |
79 | 84 |
80 ScopedVector<ApplicationImpl> apps_; | 85 ScopedVector<ApplicationImpl> apps_; |
81 LoadedCallback callback_; | 86 LoadedCallback callback_; |
82 ViewManagerClientFactory view_manager_client_factory_; | 87 ViewManagerClientFactory view_manager_client_factory_; |
83 | 88 |
84 DISALLOW_COPY_AND_ASSIGN(ConnectServiceLoader); | 89 DISALLOW_COPY_AND_ASSIGN(ConnectServiceLoader); |
85 }; | 90 }; |
(...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
320 } | 325 } |
321 | 326 |
322 // Embeds another version of the test app @ node. | 327 // Embeds another version of the test app @ node. |
323 ViewManager* Embed(ViewManager* view_manager, Node* node) { | 328 ViewManager* Embed(ViewManager* view_manager, Node* node) { |
324 DCHECK_EQ(view_manager, NodePrivate(node).view_manager()); | 329 DCHECK_EQ(view_manager, NodePrivate(node).view_manager()); |
325 node->Embed(kEmbeddedApp1URL); | 330 node->Embed(kEmbeddedApp1URL); |
326 RunRunLoop(); | 331 RunRunLoop(); |
327 return GetLoadedViewManager(); | 332 return GetLoadedViewManager(); |
328 } | 333 } |
329 | 334 |
330 // TODO(beng): remove these methods once all the tests are migrated. | |
331 void DestroyViewManager1() {} | |
332 ViewManager* view_manager_1() { return NULL; } | |
333 ViewManager* view_manager_2() { return NULL; } | |
334 | |
335 ViewManager* GetLoadedViewManager() { | 335 ViewManager* GetLoadedViewManager() { |
336 ViewManager* view_manager = loaded_view_manager_; | 336 ViewManager* view_manager = loaded_view_manager_; |
337 loaded_view_manager_ = NULL; | 337 loaded_view_manager_ = NULL; |
338 return view_manager; | 338 return view_manager; |
339 } | 339 } |
340 | 340 |
341 void UnloadApplication(const GURL& url) { | 341 void UnloadApplication(const GURL& url) { |
342 test_helper_.SetLoaderForURL(scoped_ptr<ServiceLoader>(), url); | 342 test_helper_.SetLoaderForURL(scoped_ptr<ServiceLoader>(), url); |
343 } | 343 } |
344 | 344 |
(...skipping 16 matching lines...) Expand all Loading... |
361 ASSERT_TRUE(EmbedRoot(view_manager_init_.get(), kWindowManagerURL)); | 361 ASSERT_TRUE(EmbedRoot(view_manager_init_.get(), kWindowManagerURL)); |
362 } | 362 } |
363 | 363 |
364 void EmbedRootCallback(bool* result_cache, bool result) { | 364 void EmbedRootCallback(bool* result_cache, bool result) { |
365 *result_cache = result; | 365 *result_cache = result; |
366 } | 366 } |
367 | 367 |
368 bool EmbedRoot(ViewManagerInitService* view_manager_init, | 368 bool EmbedRoot(ViewManagerInitService* view_manager_init, |
369 const std::string& url) { | 369 const std::string& url) { |
370 bool result = false; | 370 bool result = false; |
| 371 ServiceProviderPtr sp; |
| 372 BindToProxy(new ServiceProviderImpl, &sp); |
371 view_manager_init->Embed( | 373 view_manager_init->Embed( |
372 url, | 374 url, sp.Pass(), |
373 base::Bind(&ViewManagerTest::EmbedRootCallback, base::Unretained(this), | 375 base::Bind(&ViewManagerTest::EmbedRootCallback, base::Unretained(this), |
374 &result)); | 376 &result)); |
375 RunRunLoop(); | 377 RunRunLoop(); |
376 window_manager_ = GetLoadedViewManager(); | 378 window_manager_ = GetLoadedViewManager(); |
377 return result; | 379 return result; |
378 } | 380 } |
379 | 381 |
380 void OnViewManagerLoaded(ViewManager* view_manager, Node* root) { | 382 void OnViewManagerLoaded(ViewManager* view_manager, Node* root) { |
381 loaded_view_manager_ = view_manager; | 383 loaded_view_manager_ = view_manager; |
382 connect_loop_->Quit(); | 384 connect_loop_->Quit(); |
(...skipping 285 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
668 | 670 |
669 // TODO(beng): tests for view event dispatcher. | 671 // TODO(beng): tests for view event dispatcher. |
670 // - verify that we see events for all views. | 672 // - verify that we see events for all views. |
671 | 673 |
672 // TODO(beng): tests for focus: | 674 // TODO(beng): tests for focus: |
673 // - focus between two nodes known to a connection | 675 // - focus between two nodes known to a connection |
674 // - focus between nodes unknown to one of the connections. | 676 // - focus between nodes unknown to one of the connections. |
675 // - focus between nodes unknown to either connection. | 677 // - focus between nodes unknown to either connection. |
676 | 678 |
677 } // namespace mojo | 679 } // namespace mojo |
OLD | NEW |