OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 // This is really a unit test for |MasterConnectionManager| and | 5 // This is really a unit test for |MasterConnectionManager| and |
6 // |SlaveConnectionManager| (since they need to be tested together). | 6 // |SlaveConnectionManager| (since they need to be tested together). |
7 | 7 |
8 #include "mojo/edk/system/connection_manager.h" | 8 #include "mojo/edk/system/connection_manager.h" |
9 | 9 |
10 #include <stdint.h> | 10 #include <stdint.h> |
(...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
219 // TODO(vtl): If/when I add the ability to get one's own process identifier, | 219 // TODO(vtl): If/when I add the ability to get one's own process identifier, |
220 // there'll be more we can check. | 220 // there'll be more we can check. |
221 EXPECT_NE(slave1_id, slave2_id); | 221 EXPECT_NE(slave1_id, slave2_id); |
222 | 222 |
223 ConnectionIdentifier connection_id = master.GenerateConnectionIdentifier(); | 223 ConnectionIdentifier connection_id = master.GenerateConnectionIdentifier(); |
224 EXPECT_TRUE(slave1.AllowConnect(connection_id)); | 224 EXPECT_TRUE(slave1.AllowConnect(connection_id)); |
225 EXPECT_TRUE(slave2.AllowConnect(connection_id)); | 225 EXPECT_TRUE(slave2.AllowConnect(connection_id)); |
226 | 226 |
227 ProcessIdentifier peer1 = kInvalidProcessIdentifier; | 227 ProcessIdentifier peer1 = kInvalidProcessIdentifier; |
228 embedder::ScopedPlatformHandle h1; | 228 embedder::ScopedPlatformHandle h1; |
229 EXPECT_TRUE(slave1.Connect(connection_id, &peer1, &h1)); | 229 EXPECT_EQ(ConnectionManager::Result::SUCCESS_CONNECT_NEW_CONNECTION, |
| 230 slave1.Connect(connection_id, &peer1, &h1)); |
230 EXPECT_EQ(slave2_id, peer1); | 231 EXPECT_EQ(slave2_id, peer1); |
231 EXPECT_TRUE(h1.is_valid()); | 232 EXPECT_TRUE(h1.is_valid()); |
232 ProcessIdentifier peer2 = kInvalidProcessIdentifier; | 233 ProcessIdentifier peer2 = kInvalidProcessIdentifier; |
233 embedder::ScopedPlatformHandle h2; | 234 embedder::ScopedPlatformHandle h2; |
234 EXPECT_TRUE(slave2.Connect(connection_id, &peer2, &h2)); | 235 EXPECT_EQ(ConnectionManager::Result::SUCCESS_CONNECT_NEW_CONNECTION, |
| 236 slave2.Connect(connection_id, &peer2, &h2)); |
235 EXPECT_EQ(slave1_id, peer2); | 237 EXPECT_EQ(slave1_id, peer2); |
236 EXPECT_TRUE(h2.is_valid()); | 238 EXPECT_TRUE(h2.is_valid()); |
237 | 239 |
238 EXPECT_TRUE(ArePlatformHandlesConnected(h1.get(), h2.get())); | 240 EXPECT_TRUE(ArePlatformHandlesConnected(h1.get(), h2.get())); |
239 | 241 |
240 // The process manager shouldn't have gotten any notifications yet. (Spin the | 242 // The process manager shouldn't have gotten any notifications yet. (Spin the |
241 // message loop to make sure none were enqueued.) | 243 // message loop to make sure none were enqueued.) |
242 base::RunLoop().RunUntilIdle(); | 244 base::RunLoop().RunUntilIdle(); |
243 EXPECT_EQ(0u, master_process_delegate().on_slave_disconnect_calls()); | 245 EXPECT_EQ(0u, master_process_delegate().on_slave_disconnect_calls()); |
244 | 246 |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
312 EXPECT_TRUE(IsValidSlaveProcessIdentifier(slave2_id)); | 314 EXPECT_TRUE(IsValidSlaveProcessIdentifier(slave2_id)); |
313 EXPECT_NE(slave1_id, slave2_id); | 315 EXPECT_NE(slave1_id, slave2_id); |
314 | 316 |
315 ConnectionIdentifier connection_id = master.GenerateConnectionIdentifier(); | 317 ConnectionIdentifier connection_id = master.GenerateConnectionIdentifier(); |
316 EXPECT_TRUE(slave1.AllowConnect(connection_id)); | 318 EXPECT_TRUE(slave1.AllowConnect(connection_id)); |
317 EXPECT_TRUE(slave2.AllowConnect(connection_id)); | 319 EXPECT_TRUE(slave2.AllowConnect(connection_id)); |
318 | 320 |
319 EXPECT_TRUE(slave1.CancelConnect(connection_id)); | 321 EXPECT_TRUE(slave1.CancelConnect(connection_id)); |
320 ProcessIdentifier peer2 = kInvalidProcessIdentifier; | 322 ProcessIdentifier peer2 = kInvalidProcessIdentifier; |
321 embedder::ScopedPlatformHandle h2; | 323 embedder::ScopedPlatformHandle h2; |
322 EXPECT_FALSE(slave2.Connect(connection_id, &peer2, &h2)); | 324 EXPECT_EQ(ConnectionManager::Result::FAILURE, |
| 325 slave2.Connect(connection_id, &peer2, &h2)); |
323 EXPECT_EQ(kInvalidProcessIdentifier, peer2); | 326 EXPECT_EQ(kInvalidProcessIdentifier, peer2); |
324 EXPECT_FALSE(h2.is_valid()); | 327 EXPECT_FALSE(h2.is_valid()); |
325 | 328 |
326 slave1.Shutdown(); | 329 slave1.Shutdown(); |
327 slave2.Shutdown(); | 330 slave2.Shutdown(); |
328 master.Shutdown(); | 331 master.Shutdown(); |
329 } | 332 } |
330 | 333 |
331 // Tests that pending connections are removed on error. | 334 // Tests that pending connections are removed on error. |
332 TEST_F(ConnectionManagerTest, ErrorRemovePending) { | 335 TEST_F(ConnectionManagerTest, ErrorRemovePending) { |
(...skipping 21 matching lines...) Expand all Loading... |
354 slave1.Shutdown(); | 357 slave1.Shutdown(); |
355 | 358 |
356 // |OnSlaveDisconnect()| should be called. After it's called, this means that | 359 // |OnSlaveDisconnect()| should be called. After it's called, this means that |
357 // the disconnect has been detected and handled, including the removal of the | 360 // the disconnect has been detected and handled, including the removal of the |
358 // pending connection. | 361 // pending connection. |
359 master_process_delegate().RunUntilNotified(); | 362 master_process_delegate().RunUntilNotified(); |
360 EXPECT_EQ(1u, master_process_delegate().on_slave_disconnect_calls()); | 363 EXPECT_EQ(1u, master_process_delegate().on_slave_disconnect_calls()); |
361 | 364 |
362 ProcessIdentifier peer2 = kInvalidProcessIdentifier; | 365 ProcessIdentifier peer2 = kInvalidProcessIdentifier; |
363 embedder::ScopedPlatformHandle h2; | 366 embedder::ScopedPlatformHandle h2; |
364 EXPECT_FALSE(slave2.Connect(connection_id, &peer2, &h2)); | 367 EXPECT_EQ(ConnectionManager::Result::FAILURE, |
| 368 slave2.Connect(connection_id, &peer2, &h2)); |
365 EXPECT_EQ(kInvalidProcessIdentifier, peer2); | 369 EXPECT_EQ(kInvalidProcessIdentifier, peer2); |
366 EXPECT_FALSE(h2.is_valid()); | 370 EXPECT_FALSE(h2.is_valid()); |
367 | 371 |
368 slave2.Shutdown(); | 372 slave2.Shutdown(); |
369 master.Shutdown(); | 373 master.Shutdown(); |
370 } | 374 } |
371 | 375 |
372 TEST_F(ConnectionManagerTest, ConnectSlaveToSelf) { | 376 TEST_F(ConnectionManagerTest, ConnectSlaveToSelf) { |
373 MasterConnectionManager master(platform_support()); | 377 MasterConnectionManager master(platform_support()); |
374 master.Init(base::MessageLoop::current()->task_runner(), | 378 master.Init(base::MessageLoop::current()->task_runner(), |
375 &master_process_delegate()); | 379 &master_process_delegate()); |
376 | 380 |
377 MockSlaveProcessDelegate slave_process_delegate; | 381 MockSlaveProcessDelegate slave_process_delegate; |
378 SlaveConnectionManager slave(platform_support()); | 382 SlaveConnectionManager slave(platform_support()); |
379 ProcessIdentifier slave_id = | 383 ProcessIdentifier slave_id = |
380 ConnectSlave(&master, &slave_process_delegate, &slave, "slave"); | 384 ConnectSlave(&master, &slave_process_delegate, &slave, "slave"); |
381 EXPECT_TRUE(IsValidSlaveProcessIdentifier(slave_id)); | 385 EXPECT_TRUE(IsValidSlaveProcessIdentifier(slave_id)); |
382 | 386 |
383 ConnectionIdentifier connection_id = master.GenerateConnectionIdentifier(); | 387 ConnectionIdentifier connection_id = master.GenerateConnectionIdentifier(); |
384 EXPECT_TRUE(slave.AllowConnect(connection_id)); | 388 EXPECT_TRUE(slave.AllowConnect(connection_id)); |
385 EXPECT_TRUE(slave.AllowConnect(connection_id)); | 389 EXPECT_TRUE(slave.AllowConnect(connection_id)); |
386 | 390 |
387 // Currently, the connect-to-self case is signalled by the master not sending | |
388 // back a handle. | |
389 ProcessIdentifier peer1 = kInvalidProcessIdentifier; | 391 ProcessIdentifier peer1 = kInvalidProcessIdentifier; |
390 embedder::ScopedPlatformHandle h1; | 392 embedder::ScopedPlatformHandle h1; |
391 EXPECT_TRUE(slave.Connect(connection_id, &peer1, &h1)); | 393 EXPECT_EQ(ConnectionManager::Result::SUCCESS_CONNECT_SAME_PROCESS, |
| 394 slave.Connect(connection_id, &peer1, &h1)); |
392 EXPECT_EQ(slave_id, peer1); | 395 EXPECT_EQ(slave_id, peer1); |
393 EXPECT_FALSE(h1.is_valid()); | 396 EXPECT_FALSE(h1.is_valid()); |
394 ProcessIdentifier peer2 = kInvalidProcessIdentifier; | 397 ProcessIdentifier peer2 = kInvalidProcessIdentifier; |
395 embedder::ScopedPlatformHandle h2; | 398 embedder::ScopedPlatformHandle h2; |
396 EXPECT_TRUE(slave.Connect(connection_id, &peer2, &h2)); | 399 EXPECT_EQ(ConnectionManager::Result::SUCCESS_CONNECT_SAME_PROCESS, |
| 400 slave.Connect(connection_id, &peer2, &h2)); |
397 EXPECT_EQ(slave_id, peer2); | 401 EXPECT_EQ(slave_id, peer2); |
398 EXPECT_FALSE(h2.is_valid()); | 402 EXPECT_FALSE(h2.is_valid()); |
399 | 403 |
400 slave.Shutdown(); | 404 slave.Shutdown(); |
401 master.Shutdown(); | 405 master.Shutdown(); |
402 } | 406 } |
403 | 407 |
404 TEST_F(ConnectionManagerTest, ConnectSlavesTwice) { | 408 TEST_F(ConnectionManagerTest, ConnectSlavesTwice) { |
405 MasterConnectionManager master(platform_support()); | 409 MasterConnectionManager master(platform_support()); |
406 master.Init(base::MessageLoop::current()->task_runner(), | 410 master.Init(base::MessageLoop::current()->task_runner(), |
(...skipping 11 matching lines...) Expand all Loading... |
418 ConnectSlave(&master, &slave2_process_delegate, &slave2, "slave2"); | 422 ConnectSlave(&master, &slave2_process_delegate, &slave2, "slave2"); |
419 EXPECT_TRUE(IsValidSlaveProcessIdentifier(slave2_id)); | 423 EXPECT_TRUE(IsValidSlaveProcessIdentifier(slave2_id)); |
420 EXPECT_NE(slave1_id, slave2_id); | 424 EXPECT_NE(slave1_id, slave2_id); |
421 | 425 |
422 ConnectionIdentifier connection_id = master.GenerateConnectionIdentifier(); | 426 ConnectionIdentifier connection_id = master.GenerateConnectionIdentifier(); |
423 EXPECT_TRUE(slave1.AllowConnect(connection_id)); | 427 EXPECT_TRUE(slave1.AllowConnect(connection_id)); |
424 EXPECT_TRUE(slave2.AllowConnect(connection_id)); | 428 EXPECT_TRUE(slave2.AllowConnect(connection_id)); |
425 | 429 |
426 ProcessIdentifier peer1 = kInvalidProcessIdentifier; | 430 ProcessIdentifier peer1 = kInvalidProcessIdentifier; |
427 embedder::ScopedPlatformHandle h1; | 431 embedder::ScopedPlatformHandle h1; |
428 EXPECT_TRUE(slave1.Connect(connection_id, &peer1, &h1)); | 432 EXPECT_EQ(ConnectionManager::Result::SUCCESS_CONNECT_NEW_CONNECTION, |
| 433 slave1.Connect(connection_id, &peer1, &h1)); |
429 EXPECT_EQ(slave2_id, peer1); | 434 EXPECT_EQ(slave2_id, peer1); |
430 ProcessIdentifier peer2 = kInvalidProcessIdentifier; | 435 ProcessIdentifier peer2 = kInvalidProcessIdentifier; |
431 embedder::ScopedPlatformHandle h2; | 436 embedder::ScopedPlatformHandle h2; |
432 EXPECT_TRUE(slave2.Connect(connection_id, &peer2, &h2)); | 437 EXPECT_EQ(ConnectionManager::Result::SUCCESS_CONNECT_NEW_CONNECTION, |
| 438 slave2.Connect(connection_id, &peer2, &h2)); |
433 EXPECT_EQ(slave1_id, peer2); | 439 EXPECT_EQ(slave1_id, peer2); |
434 | 440 |
435 EXPECT_TRUE(ArePlatformHandlesConnected(h1.get(), h2.get())); | 441 EXPECT_TRUE(ArePlatformHandlesConnected(h1.get(), h2.get())); |
436 | 442 |
437 // Currently, the master doesn't detect the case of connecting a pair of | 443 // TODO(vtl): Currently, the master doesn't detect the case of connecting a |
438 // slaves that are already connected. (Doing so would require more careful | 444 // pair of slaves that are already connected. (Doing so would require more |
439 // tracking and is prone to races -- especially if we want slaves to be able | 445 // careful tracking and is prone to races -- especially if we want slaves to |
440 // to tear down no-longer-needed connections.) But the slaves should be able | 446 // be able to tear down no-longer-needed connections.) But the slaves should |
441 // to do the tracking themselves (using the peer process identifiers). | 447 // be able to do the tracking themselves (using the peer process identifiers). |
442 connection_id = master.GenerateConnectionIdentifier(); | 448 connection_id = master.GenerateConnectionIdentifier(); |
443 EXPECT_TRUE(slave1.AllowConnect(connection_id)); | 449 EXPECT_TRUE(slave1.AllowConnect(connection_id)); |
444 EXPECT_TRUE(slave2.AllowConnect(connection_id)); | 450 EXPECT_TRUE(slave2.AllowConnect(connection_id)); |
445 | 451 |
446 h1.reset(); | 452 h1.reset(); |
447 h2.reset(); | 453 h2.reset(); |
| 454 // TODO(vtl): FIXME -- this will break when I implemented |
| 455 // SUCCESS_CONNECT_REUSE_CONNECTION. |
448 ProcessIdentifier second_peer2 = kInvalidProcessIdentifier; | 456 ProcessIdentifier second_peer2 = kInvalidProcessIdentifier; |
449 EXPECT_TRUE(slave2.Connect(connection_id, &second_peer2, &h2)); | 457 EXPECT_EQ(ConnectionManager::Result::SUCCESS_CONNECT_NEW_CONNECTION, |
| 458 slave2.Connect(connection_id, &second_peer2, &h2)); |
450 ProcessIdentifier second_peer1 = kInvalidProcessIdentifier; | 459 ProcessIdentifier second_peer1 = kInvalidProcessIdentifier; |
451 EXPECT_TRUE(slave1.Connect(connection_id, &second_peer1, &h1)); | 460 EXPECT_EQ(ConnectionManager::Result::SUCCESS_CONNECT_NEW_CONNECTION, |
| 461 slave1.Connect(connection_id, &second_peer1, &h1)); |
452 | 462 |
453 EXPECT_EQ(peer1, second_peer1); | 463 EXPECT_EQ(peer1, second_peer1); |
454 EXPECT_EQ(peer2, second_peer2); | 464 EXPECT_EQ(peer2, second_peer2); |
455 EXPECT_TRUE(ArePlatformHandlesConnected(h1.get(), h2.get())); | 465 EXPECT_TRUE(ArePlatformHandlesConnected(h1.get(), h2.get())); |
456 | 466 |
457 slave2.Shutdown(); | 467 slave2.Shutdown(); |
458 slave1.Shutdown(); | 468 slave1.Shutdown(); |
459 master.Shutdown(); | 469 master.Shutdown(); |
460 } | 470 } |
461 | 471 |
462 TEST_F(ConnectionManagerTest, ConnectMasterToSlave) { | 472 TEST_F(ConnectionManagerTest, ConnectMasterToSlave) { |
463 MasterConnectionManager master(platform_support()); | 473 MasterConnectionManager master(platform_support()); |
464 master.Init(base::MessageLoop::current()->task_runner(), | 474 master.Init(base::MessageLoop::current()->task_runner(), |
465 &master_process_delegate()); | 475 &master_process_delegate()); |
466 | 476 |
467 MockSlaveProcessDelegate slave_process_delegate; | 477 MockSlaveProcessDelegate slave_process_delegate; |
468 SlaveConnectionManager slave(platform_support()); | 478 SlaveConnectionManager slave(platform_support()); |
469 ProcessIdentifier slave_id = | 479 ProcessIdentifier slave_id = |
470 ConnectSlave(&master, &slave_process_delegate, &slave, "slave"); | 480 ConnectSlave(&master, &slave_process_delegate, &slave, "slave"); |
471 EXPECT_TRUE(IsValidSlaveProcessIdentifier(slave_id)); | 481 EXPECT_TRUE(IsValidSlaveProcessIdentifier(slave_id)); |
472 | 482 |
473 ConnectionIdentifier connection_id = master.GenerateConnectionIdentifier(); | 483 ConnectionIdentifier connection_id = master.GenerateConnectionIdentifier(); |
474 EXPECT_TRUE(master.AllowConnect(connection_id)); | 484 EXPECT_TRUE(master.AllowConnect(connection_id)); |
475 EXPECT_TRUE(slave.AllowConnect(connection_id)); | 485 EXPECT_TRUE(slave.AllowConnect(connection_id)); |
476 | 486 |
477 ProcessIdentifier master_peer = kInvalidProcessIdentifier; | 487 ProcessIdentifier master_peer = kInvalidProcessIdentifier; |
478 embedder::ScopedPlatformHandle master_h; | 488 embedder::ScopedPlatformHandle master_h; |
479 EXPECT_TRUE(master.Connect(connection_id, &master_peer, &master_h)); | 489 EXPECT_EQ(ConnectionManager::Result::SUCCESS_CONNECT_NEW_CONNECTION, |
| 490 master.Connect(connection_id, &master_peer, &master_h)); |
480 EXPECT_EQ(slave_id, master_peer); | 491 EXPECT_EQ(slave_id, master_peer); |
481 EXPECT_TRUE(master_h.is_valid()); | 492 EXPECT_TRUE(master_h.is_valid()); |
482 ProcessIdentifier slave_peer = kInvalidProcessIdentifier; | 493 ProcessIdentifier slave_peer = kInvalidProcessIdentifier; |
483 embedder::ScopedPlatformHandle slave_h; | 494 embedder::ScopedPlatformHandle slave_h; |
484 EXPECT_TRUE(slave.Connect(connection_id, &slave_peer, &slave_h)); | 495 EXPECT_EQ(ConnectionManager::Result::SUCCESS_CONNECT_NEW_CONNECTION, |
| 496 slave.Connect(connection_id, &slave_peer, &slave_h)); |
485 EXPECT_EQ(kMasterProcessIdentifier, slave_peer); | 497 EXPECT_EQ(kMasterProcessIdentifier, slave_peer); |
486 EXPECT_TRUE(slave_h.is_valid()); | 498 EXPECT_TRUE(slave_h.is_valid()); |
487 | 499 |
488 EXPECT_TRUE(ArePlatformHandlesConnected(master_h.get(), slave_h.get())); | 500 EXPECT_TRUE(ArePlatformHandlesConnected(master_h.get(), slave_h.get())); |
489 | 501 |
490 slave.Shutdown(); | 502 slave.Shutdown(); |
491 master.Shutdown(); | 503 master.Shutdown(); |
492 } | 504 } |
493 | 505 |
494 TEST_F(ConnectionManagerTest, ConnectMasterToSelf) { | 506 TEST_F(ConnectionManagerTest, ConnectMasterToSelf) { |
495 MasterConnectionManager master(platform_support()); | 507 MasterConnectionManager master(platform_support()); |
496 master.Init(base::MessageLoop::current()->task_runner(), | 508 master.Init(base::MessageLoop::current()->task_runner(), |
497 &master_process_delegate()); | 509 &master_process_delegate()); |
498 | 510 |
499 ConnectionIdentifier connection_id = master.GenerateConnectionIdentifier(); | 511 ConnectionIdentifier connection_id = master.GenerateConnectionIdentifier(); |
500 EXPECT_TRUE(master.AllowConnect(connection_id)); | 512 EXPECT_TRUE(master.AllowConnect(connection_id)); |
501 EXPECT_TRUE(master.AllowConnect(connection_id)); | 513 EXPECT_TRUE(master.AllowConnect(connection_id)); |
502 | 514 |
503 // Currently, the connect-to-self case is signalled by the master not sending | |
504 // back a handle. | |
505 ProcessIdentifier peer1 = kInvalidProcessIdentifier; | 515 ProcessIdentifier peer1 = kInvalidProcessIdentifier; |
506 embedder::ScopedPlatformHandle h1; | 516 embedder::ScopedPlatformHandle h1; |
507 EXPECT_TRUE(master.Connect(connection_id, &peer1, &h1)); | 517 EXPECT_EQ(ConnectionManager::Result::SUCCESS_CONNECT_SAME_PROCESS, |
| 518 master.Connect(connection_id, &peer1, &h1)); |
508 EXPECT_EQ(kMasterProcessIdentifier, peer1); | 519 EXPECT_EQ(kMasterProcessIdentifier, peer1); |
509 EXPECT_FALSE(h1.is_valid()); | 520 EXPECT_FALSE(h1.is_valid()); |
510 ProcessIdentifier peer2 = kInvalidProcessIdentifier; | 521 ProcessIdentifier peer2 = kInvalidProcessIdentifier; |
511 embedder::ScopedPlatformHandle h2; | 522 embedder::ScopedPlatformHandle h2; |
512 EXPECT_TRUE(master.Connect(connection_id, &peer2, &h2)); | 523 EXPECT_EQ(ConnectionManager::Result::SUCCESS_CONNECT_SAME_PROCESS, |
| 524 master.Connect(connection_id, &peer2, &h2)); |
513 EXPECT_EQ(kMasterProcessIdentifier, peer2); | 525 EXPECT_EQ(kMasterProcessIdentifier, peer2); |
514 EXPECT_FALSE(h2.is_valid()); | 526 EXPECT_FALSE(h2.is_valid()); |
515 | 527 |
516 EXPECT_EQ(peer1, peer2); | 528 EXPECT_EQ(peer1, peer2); |
517 | 529 |
518 master.Shutdown(); | 530 master.Shutdown(); |
519 } | 531 } |
520 | 532 |
521 TEST_F(ConnectionManagerTest, MasterCancelConnect) { | 533 TEST_F(ConnectionManagerTest, MasterCancelConnect) { |
522 MasterConnectionManager master(platform_support()); | 534 MasterConnectionManager master(platform_support()); |
523 master.Init(base::MessageLoop::current()->task_runner(), | 535 master.Init(base::MessageLoop::current()->task_runner(), |
524 &master_process_delegate()); | 536 &master_process_delegate()); |
525 | 537 |
526 MockSlaveProcessDelegate slave_process_delegate; | 538 MockSlaveProcessDelegate slave_process_delegate; |
527 SlaveConnectionManager slave(platform_support()); | 539 SlaveConnectionManager slave(platform_support()); |
528 ProcessIdentifier slave_id = | 540 ProcessIdentifier slave_id = |
529 ConnectSlave(&master, &slave_process_delegate, &slave, "slave"); | 541 ConnectSlave(&master, &slave_process_delegate, &slave, "slave"); |
530 EXPECT_TRUE(IsValidSlaveProcessIdentifier(slave_id)); | 542 EXPECT_TRUE(IsValidSlaveProcessIdentifier(slave_id)); |
531 | 543 |
532 ConnectionIdentifier connection_id = master.GenerateConnectionIdentifier(); | 544 ConnectionIdentifier connection_id = master.GenerateConnectionIdentifier(); |
533 EXPECT_TRUE(master.AllowConnect(connection_id)); | 545 EXPECT_TRUE(master.AllowConnect(connection_id)); |
534 EXPECT_TRUE(slave.AllowConnect(connection_id)); | 546 EXPECT_TRUE(slave.AllowConnect(connection_id)); |
535 | 547 |
536 EXPECT_TRUE(master.CancelConnect(connection_id)); | 548 EXPECT_TRUE(master.CancelConnect(connection_id)); |
537 ProcessIdentifier peer = kInvalidProcessIdentifier; | 549 ProcessIdentifier peer = kInvalidProcessIdentifier; |
538 embedder::ScopedPlatformHandle h; | 550 embedder::ScopedPlatformHandle h; |
539 EXPECT_FALSE(slave.Connect(connection_id, &peer, &h)); | 551 EXPECT_EQ(ConnectionManager::Result::FAILURE, |
| 552 slave.Connect(connection_id, &peer, &h)); |
540 EXPECT_EQ(kInvalidProcessIdentifier, peer); | 553 EXPECT_EQ(kInvalidProcessIdentifier, peer); |
541 EXPECT_FALSE(h.is_valid()); | 554 EXPECT_FALSE(h.is_valid()); |
542 | 555 |
543 slave.Shutdown(); | 556 slave.Shutdown(); |
544 master.Shutdown(); | 557 master.Shutdown(); |
545 } | 558 } |
546 | 559 |
547 TEST_F(ConnectionManagerTest, AddSlaveThenImmediateShutdown) { | 560 TEST_F(ConnectionManagerTest, AddSlaveThenImmediateShutdown) { |
548 MasterConnectionManager master(platform_support()); | 561 MasterConnectionManager master(platform_support()); |
549 master.Init(base::MessageLoop::current()->task_runner(), | 562 master.Init(base::MessageLoop::current()->task_runner(), |
(...skipping 16 matching lines...) Expand all Loading... |
566 | 579 |
567 embedder::PlatformChannelPair platform_channel_pair; | 580 embedder::PlatformChannelPair platform_channel_pair; |
568 ConnectionIdentifier connection_id = master.GenerateConnectionIdentifier(); | 581 ConnectionIdentifier connection_id = master.GenerateConnectionIdentifier(); |
569 ProcessIdentifier slave_id = master.AddSlaveAndBootstrap( | 582 ProcessIdentifier slave_id = master.AddSlaveAndBootstrap( |
570 new TestSlaveInfo("slave"), platform_channel_pair.PassServerHandle(), | 583 new TestSlaveInfo("slave"), platform_channel_pair.PassServerHandle(), |
571 connection_id); | 584 connection_id); |
572 EXPECT_TRUE(IsValidSlaveProcessIdentifier(slave_id)); | 585 EXPECT_TRUE(IsValidSlaveProcessIdentifier(slave_id)); |
573 | 586 |
574 embedder::ScopedPlatformHandle h1; | 587 embedder::ScopedPlatformHandle h1; |
575 ProcessIdentifier master_peer = kInvalidProcessIdentifier; | 588 ProcessIdentifier master_peer = kInvalidProcessIdentifier; |
576 EXPECT_TRUE(master.Connect(connection_id, &master_peer, &h1)); | 589 EXPECT_EQ(ConnectionManager::Result::SUCCESS_CONNECT_NEW_CONNECTION, |
| 590 master.Connect(connection_id, &master_peer, &h1)); |
577 EXPECT_EQ(slave_id, master_peer); | 591 EXPECT_EQ(slave_id, master_peer); |
578 EXPECT_TRUE(h1.is_valid()); | 592 EXPECT_TRUE(h1.is_valid()); |
579 | 593 |
580 // We can delay creating/initializing |slave| for quite a while. | 594 // We can delay creating/initializing |slave| for quite a while. |
581 MockSlaveProcessDelegate slave_process_delegate; | 595 MockSlaveProcessDelegate slave_process_delegate; |
582 SlaveConnectionManager slave(platform_support()); | 596 SlaveConnectionManager slave(platform_support()); |
583 slave.Init(base::MessageLoop::current()->task_runner(), | 597 slave.Init(base::MessageLoop::current()->task_runner(), |
584 &slave_process_delegate, platform_channel_pair.PassClientHandle()); | 598 &slave_process_delegate, platform_channel_pair.PassClientHandle()); |
585 | 599 |
586 ProcessIdentifier slave_peer = kInvalidProcessIdentifier; | 600 ProcessIdentifier slave_peer = kInvalidProcessIdentifier; |
587 embedder::ScopedPlatformHandle h2; | 601 embedder::ScopedPlatformHandle h2; |
588 EXPECT_TRUE(slave.Connect(connection_id, &slave_peer, &h2)); | 602 EXPECT_EQ(ConnectionManager::Result::SUCCESS_CONNECT_NEW_CONNECTION, |
| 603 slave.Connect(connection_id, &slave_peer, &h2)); |
589 EXPECT_EQ(kMasterProcessIdentifier, slave_peer); | 604 EXPECT_EQ(kMasterProcessIdentifier, slave_peer); |
590 | 605 |
591 EXPECT_TRUE(ArePlatformHandlesConnected(h1.get(), h2.get())); | 606 EXPECT_TRUE(ArePlatformHandlesConnected(h1.get(), h2.get())); |
592 | 607 |
593 slave.Shutdown(); | 608 slave.Shutdown(); |
594 master.Shutdown(); | 609 master.Shutdown(); |
595 } | 610 } |
596 | 611 |
597 // TODO(vtl): More shutdown cases for |AddSlaveAndBootstrap()|? | 612 // TODO(vtl): More shutdown cases for |AddSlaveAndBootstrap()|? |
598 | 613 |
599 } // namespace | 614 } // namespace |
600 } // namespace system | 615 } // namespace system |
601 } // namespace mojo | 616 } // namespace mojo |
OLD | NEW |