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 289 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
300 | 300 |
301 // static | 301 // static |
302 base::RunLoop* ViewManagerProxy::main_run_loop_ = NULL; | 302 base::RunLoop* ViewManagerProxy::main_run_loop_ = NULL; |
303 | 303 |
304 // static | 304 // static |
305 bool ViewManagerProxy::in_embed_ = false; | 305 bool ViewManagerProxy::in_embed_ = false; |
306 | 306 |
307 class TestViewManagerClientConnection | 307 class TestViewManagerClientConnection |
308 : public InterfaceImpl<ViewManagerClient> { | 308 : public InterfaceImpl<ViewManagerClient> { |
309 public: | 309 public: |
310 TestViewManagerClientConnection(ApplicationConnection* app_connection) : | 310 explicit TestViewManagerClientConnection() : connection_(&tracker_) { |
311 connection_(&tracker_) { | |
312 tracker_.set_delegate(&connection_); | 311 tracker_.set_delegate(&connection_); |
313 } | 312 } |
314 | 313 |
315 // InterfaceImp: | 314 // InterfaceImp: |
316 virtual void OnConnectionEstablished() OVERRIDE { | 315 virtual void OnConnectionEstablished() OVERRIDE { |
317 connection_.set_router(internal_state()->router()); | 316 connection_.set_router(internal_state()->router()); |
318 connection_.set_view_manager(client()); | 317 connection_.set_view_manager(client()); |
319 } | 318 } |
320 | 319 |
321 // ViewMangerClient: | 320 // ViewMangerClient: |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
369 | 368 |
370 private: | 369 private: |
371 TestChangeTracker tracker_; | 370 TestChangeTracker tracker_; |
372 ViewManagerProxy connection_; | 371 ViewManagerProxy connection_; |
373 | 372 |
374 DISALLOW_COPY_AND_ASSIGN(TestViewManagerClientConnection); | 373 DISALLOW_COPY_AND_ASSIGN(TestViewManagerClientConnection); |
375 }; | 374 }; |
376 | 375 |
377 // Used with ViewManagerService::Embed(). Creates a | 376 // Used with ViewManagerService::Embed(). Creates a |
378 // TestViewManagerClientConnection, which creates and owns the ViewManagerProxy. | 377 // TestViewManagerClientConnection, which creates and owns the ViewManagerProxy. |
379 class EmbedServiceLoader : public ServiceLoader, ApplicationDelegate { | 378 class EmbedServiceLoader : public ServiceLoader, |
| 379 ApplicationDelegate, |
| 380 public InterfaceFactory<ViewManagerClient> { |
380 public: | 381 public: |
381 EmbedServiceLoader() {} | 382 EmbedServiceLoader() {} |
382 virtual ~EmbedServiceLoader() {} | 383 virtual ~EmbedServiceLoader() {} |
383 | 384 |
384 // ServiceLoader: | 385 // ServiceLoader implementation: |
385 virtual void LoadService(ServiceManager* manager, | 386 virtual void LoadService(ServiceManager* manager, |
386 const GURL& url, | 387 const GURL& url, |
387 ScopedMessagePipeHandle shell_handle) OVERRIDE { | 388 ScopedMessagePipeHandle shell_handle) OVERRIDE { |
388 scoped_ptr<ApplicationImpl> app(new ApplicationImpl(this, | 389 scoped_ptr<ApplicationImpl> app(new ApplicationImpl(this, |
389 shell_handle.Pass())); | 390 shell_handle.Pass())); |
390 apps_.push_back(app.release()); | 391 apps_.push_back(app.release()); |
391 } | 392 } |
392 virtual void OnServiceError(ServiceManager* manager, | 393 virtual void OnServiceError(ServiceManager* manager, |
393 const GURL& url) OVERRIDE { | 394 const GURL& url) OVERRIDE { |
394 } | 395 } |
395 | 396 |
396 // ApplicationDelegate | 397 // ApplicationDelegate implementation: |
397 virtual bool ConfigureIncomingConnection(ApplicationConnection* connection) | 398 virtual bool ConfigureIncomingConnection(ApplicationConnection* connection) |
398 OVERRIDE { | 399 OVERRIDE { |
399 connection->AddService<TestViewManagerClientConnection>(); | 400 connection->AddService(this); |
400 return true; | 401 return true; |
401 } | 402 } |
402 | 403 |
| 404 // InterfaceFactory<ViewManagerClient> implementation: |
| 405 virtual void Create(ApplicationConnection* connection, |
| 406 InterfaceRequest<ViewManagerClient> request) OVERRIDE { |
| 407 BindToRequest(new TestViewManagerClientConnection, &request); |
| 408 } |
| 409 |
403 private: | 410 private: |
404 ScopedVector<ApplicationImpl> apps_; | 411 ScopedVector<ApplicationImpl> apps_; |
405 | 412 |
406 DISALLOW_COPY_AND_ASSIGN(EmbedServiceLoader); | 413 DISALLOW_COPY_AND_ASSIGN(EmbedServiceLoader); |
407 }; | 414 }; |
408 | 415 |
409 // Creates an id used for transport from the specified parameters. | 416 // Creates an id used for transport from the specified parameters. |
410 Id BuildNodeId(ConnectionSpecificId connection_id, | 417 Id BuildNodeId(ConnectionSpecificId connection_id, |
411 ConnectionSpecificId node_id) { | 418 ConnectionSpecificId node_id) { |
412 return (connection_id << 16) | node_id; | 419 return (connection_id << 16) | node_id; |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
499 ChangeNodeDescription(changes)); | 506 ChangeNodeDescription(changes)); |
500 } | 507 } |
501 } | 508 } |
502 | 509 |
503 void DestroySecondConnection() { | 510 void DestroySecondConnection() { |
504 connection2_->Destroy(); | 511 connection2_->Destroy(); |
505 connection2_ = NULL; | 512 connection2_ = NULL; |
506 } | 513 } |
507 | 514 |
508 base::ShadowingAtExitManager at_exit_; | 515 base::ShadowingAtExitManager at_exit_; |
| 516 shell::ShellTestHelper test_helper_; |
509 base::MessageLoop loop_; | 517 base::MessageLoop loop_; |
510 shell::ShellTestHelper test_helper_; | |
511 | 518 |
512 ViewManagerInitServicePtr view_manager_init_; | 519 ViewManagerInitServicePtr view_manager_init_; |
513 | 520 |
514 ViewManagerProxy* connection_; | 521 ViewManagerProxy* connection_; |
515 ViewManagerProxy* connection2_; | 522 ViewManagerProxy* connection2_; |
516 | 523 |
517 DISALLOW_COPY_AND_ASSIGN(ViewManagerTest); | 524 DISALLOW_COPY_AND_ASSIGN(ViewManagerTest); |
518 }; | 525 }; |
519 | 526 |
520 // Verifies client gets a valid id. | 527 // Verifies client gets a valid id. |
(...skipping 864 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1385 // originating connection. | 1392 // originating connection. |
1386 | 1393 |
1387 // TODO(beng): Add tests for focus: | 1394 // TODO(beng): Add tests for focus: |
1388 // - focus between two nodes known to a connection | 1395 // - focus between two nodes known to a connection |
1389 // - focus between nodes unknown to one of the connections. | 1396 // - focus between nodes unknown to one of the connections. |
1390 // - focus between nodes unknown to either connection. | 1397 // - focus between nodes unknown to either connection. |
1391 | 1398 |
1392 } // namespace service | 1399 } // namespace service |
1393 } // namespace view_manager | 1400 } // namespace view_manager |
1394 } // namespace mojo | 1401 } // namespace mojo |
OLD | NEW |