| 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 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 51 num_bytes = 0; | 51 num_bytes = 0; |
| 52 if (!mojo::test::BlockingRead(h2, &r, sizeof(r), &num_bytes) || | 52 if (!mojo::test::BlockingRead(h2, &r, sizeof(r), &num_bytes) || |
| 53 num_bytes != sizeof(r)) | 53 num_bytes != sizeof(r)) |
| 54 return false; | 54 return false; |
| 55 if (r != w2) | 55 if (r != w2) |
| 56 return false; | 56 return false; |
| 57 | 57 |
| 58 return true; | 58 return true; |
| 59 } | 59 } |
| 60 | 60 |
| 61 bool IsValidSlaveProcessIdentifier(ProcessIdentifier process_identifier) { |
| 62 return process_identifier != kInvalidProcessIdentifier && |
| 63 process_identifier != kMasterProcessIdentifier; |
| 64 } |
| 65 |
| 61 class TestSlaveInfo : public embedder::SlaveInfo { | 66 class TestSlaveInfo : public embedder::SlaveInfo { |
| 62 public: | 67 public: |
| 63 explicit TestSlaveInfo(const std::string& name) : name_(name) {} | 68 explicit TestSlaveInfo(const std::string& name) : name_(name) {} |
| 64 ~TestSlaveInfo() override { CHECK(thread_checker_.CalledOnValidThread()); } | 69 ~TestSlaveInfo() override { CHECK(thread_checker_.CalledOnValidThread()); } |
| 65 | 70 |
| 66 const std::string& name() const { return name_; } | 71 const std::string& name() const { return name_; } |
| 67 | 72 |
| 68 private: | 73 private: |
| 69 base::ThreadChecker thread_checker_; | 74 base::ThreadChecker thread_checker_; |
| 70 std::string name_; | 75 std::string name_; |
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 193 ConnectSlave(&master, &slave1_process_delegate, &slave1, "slave1"); | 198 ConnectSlave(&master, &slave1_process_delegate, &slave1, "slave1"); |
| 194 | 199 |
| 195 MockSlaveProcessDelegate slave2_process_delegate; | 200 MockSlaveProcessDelegate slave2_process_delegate; |
| 196 SlaveConnectionManager slave2; | 201 SlaveConnectionManager slave2; |
| 197 ConnectSlave(&master, &slave2_process_delegate, &slave2, "slave2"); | 202 ConnectSlave(&master, &slave2_process_delegate, &slave2, "slave2"); |
| 198 | 203 |
| 199 ConnectionIdentifier connection_id = ConnectionIdentifier::Generate(); | 204 ConnectionIdentifier connection_id = ConnectionIdentifier::Generate(); |
| 200 EXPECT_TRUE(slave1.AllowConnect(connection_id)); | 205 EXPECT_TRUE(slave1.AllowConnect(connection_id)); |
| 201 EXPECT_TRUE(slave2.AllowConnect(connection_id)); | 206 EXPECT_TRUE(slave2.AllowConnect(connection_id)); |
| 202 | 207 |
| 203 ProcessIdentifier peer1; | 208 ProcessIdentifier peer1 = kInvalidProcessIdentifier; |
| 204 embedder::ScopedPlatformHandle h1; | 209 embedder::ScopedPlatformHandle h1; |
| 205 EXPECT_TRUE(slave1.Connect(connection_id, &peer1, &h1)); | 210 EXPECT_TRUE(slave1.Connect(connection_id, &peer1, &h1)); |
| 211 EXPECT_TRUE(IsValidSlaveProcessIdentifier(peer1)); |
| 206 EXPECT_TRUE(h1.is_valid()); | 212 EXPECT_TRUE(h1.is_valid()); |
| 207 ProcessIdentifier peer2; | 213 ProcessIdentifier peer2 = kInvalidProcessIdentifier; |
| 208 embedder::ScopedPlatformHandle h2; | 214 embedder::ScopedPlatformHandle h2; |
| 209 EXPECT_TRUE(slave2.Connect(connection_id, &peer2, &h2)); | 215 EXPECT_TRUE(slave2.Connect(connection_id, &peer2, &h2)); |
| 216 EXPECT_TRUE(IsValidSlaveProcessIdentifier(peer2)); |
| 210 EXPECT_TRUE(h2.is_valid()); | 217 EXPECT_TRUE(h2.is_valid()); |
| 211 | 218 |
| 212 // 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, |
| 213 // there'll be more we can check. | 220 // there'll be more we can check. |
| 214 EXPECT_NE(peer1, peer2); | 221 EXPECT_NE(peer1, peer2); |
| 215 EXPECT_TRUE(ArePlatformHandlesConnected(h1.get(), h2.get())); | 222 EXPECT_TRUE(ArePlatformHandlesConnected(h1.get(), h2.get())); |
| 216 | 223 |
| 217 // The process manager shouldn't have gotten any notifications yet. (Spin the | 224 // The process manager shouldn't have gotten any notifications yet. (Spin the |
| 218 // message loop to make sure none were enqueued.) | 225 // message loop to make sure none were enqueued.) |
| 219 base::RunLoop().RunUntilIdle(); | 226 base::RunLoop().RunUntilIdle(); |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 278 | 285 |
| 279 MockSlaveProcessDelegate slave2_process_delegate; | 286 MockSlaveProcessDelegate slave2_process_delegate; |
| 280 SlaveConnectionManager slave2; | 287 SlaveConnectionManager slave2; |
| 281 ConnectSlave(&master, &slave2_process_delegate, &slave2, "slave2"); | 288 ConnectSlave(&master, &slave2_process_delegate, &slave2, "slave2"); |
| 282 | 289 |
| 283 ConnectionIdentifier connection_id = ConnectionIdentifier::Generate(); | 290 ConnectionIdentifier connection_id = ConnectionIdentifier::Generate(); |
| 284 EXPECT_TRUE(slave1.AllowConnect(connection_id)); | 291 EXPECT_TRUE(slave1.AllowConnect(connection_id)); |
| 285 EXPECT_TRUE(slave2.AllowConnect(connection_id)); | 292 EXPECT_TRUE(slave2.AllowConnect(connection_id)); |
| 286 | 293 |
| 287 EXPECT_TRUE(slave1.CancelConnect(connection_id)); | 294 EXPECT_TRUE(slave1.CancelConnect(connection_id)); |
| 288 ProcessIdentifier peer2; | 295 ProcessIdentifier peer2 = kInvalidProcessIdentifier; |
| 289 embedder::ScopedPlatformHandle h2; | 296 embedder::ScopedPlatformHandle h2; |
| 290 EXPECT_FALSE(slave2.Connect(connection_id, &peer2, &h2)); | 297 EXPECT_FALSE(slave2.Connect(connection_id, &peer2, &h2)); |
| 298 EXPECT_EQ(kInvalidProcessIdentifier, peer2); |
| 291 EXPECT_FALSE(h2.is_valid()); | 299 EXPECT_FALSE(h2.is_valid()); |
| 292 | 300 |
| 293 slave1.Shutdown(); | 301 slave1.Shutdown(); |
| 294 slave2.Shutdown(); | 302 slave2.Shutdown(); |
| 295 master.Shutdown(); | 303 master.Shutdown(); |
| 296 } | 304 } |
| 297 | 305 |
| 298 // Tests that pending connections are removed on error. | 306 // Tests that pending connections are removed on error. |
| 299 TEST_F(ConnectionManagerTest, ErrorRemovePending) { | 307 TEST_F(ConnectionManagerTest, ErrorRemovePending) { |
| 300 MasterConnectionManager master; | 308 MasterConnectionManager master; |
| (...skipping 12 matching lines...) Expand all Loading... |
| 313 EXPECT_TRUE(slave2.AllowConnect(connection_id)); | 321 EXPECT_TRUE(slave2.AllowConnect(connection_id)); |
| 314 | 322 |
| 315 slave1.Shutdown(); | 323 slave1.Shutdown(); |
| 316 | 324 |
| 317 // |OnSlaveDisconnect()| should be called. After it's called, this means that | 325 // |OnSlaveDisconnect()| should be called. After it's called, this means that |
| 318 // the disconnect has been detected and handled, including the removal of the | 326 // the disconnect has been detected and handled, including the removal of the |
| 319 // pending connection. | 327 // pending connection. |
| 320 master_process_delegate().RunUntilNotified(); | 328 master_process_delegate().RunUntilNotified(); |
| 321 EXPECT_EQ(1u, master_process_delegate().on_slave_disconnect_calls()); | 329 EXPECT_EQ(1u, master_process_delegate().on_slave_disconnect_calls()); |
| 322 | 330 |
| 323 ProcessIdentifier peer2; | 331 ProcessIdentifier peer2 = kInvalidProcessIdentifier; |
| 324 embedder::ScopedPlatformHandle h2; | 332 embedder::ScopedPlatformHandle h2; |
| 325 EXPECT_FALSE(slave2.Connect(connection_id, &peer2, &h2)); | 333 EXPECT_FALSE(slave2.Connect(connection_id, &peer2, &h2)); |
| 334 EXPECT_EQ(kInvalidProcessIdentifier, peer2); |
| 326 EXPECT_FALSE(h2.is_valid()); | 335 EXPECT_FALSE(h2.is_valid()); |
| 327 | 336 |
| 328 slave2.Shutdown(); | 337 slave2.Shutdown(); |
| 329 master.Shutdown(); | 338 master.Shutdown(); |
| 330 } | 339 } |
| 331 | 340 |
| 332 TEST_F(ConnectionManagerTest, ConnectSlaveToSelf) { | 341 TEST_F(ConnectionManagerTest, ConnectSlaveToSelf) { |
| 333 MasterConnectionManager master; | 342 MasterConnectionManager master; |
| 334 master.Init(&master_process_delegate()); | 343 master.Init(&master_process_delegate()); |
| 335 | 344 |
| 336 MockSlaveProcessDelegate slave_process_delegate; | 345 MockSlaveProcessDelegate slave_process_delegate; |
| 337 SlaveConnectionManager slave; | 346 SlaveConnectionManager slave; |
| 338 ConnectSlave(&master, &slave_process_delegate, &slave, "slave"); | 347 ConnectSlave(&master, &slave_process_delegate, &slave, "slave"); |
| 339 | 348 |
| 340 ConnectionIdentifier connection_id = ConnectionIdentifier::Generate(); | 349 ConnectionIdentifier connection_id = ConnectionIdentifier::Generate(); |
| 341 EXPECT_TRUE(slave.AllowConnect(connection_id)); | 350 EXPECT_TRUE(slave.AllowConnect(connection_id)); |
| 342 EXPECT_TRUE(slave.AllowConnect(connection_id)); | 351 EXPECT_TRUE(slave.AllowConnect(connection_id)); |
| 343 | 352 |
| 344 // Currently, the connect-to-self case is signalled by the master not sending | 353 // Currently, the connect-to-self case is signalled by the master not sending |
| 345 // back a handle. | 354 // back a handle. |
| 346 ProcessIdentifier peer1; | 355 ProcessIdentifier peer1 = kInvalidProcessIdentifier; |
| 347 embedder::ScopedPlatformHandle h1; | 356 embedder::ScopedPlatformHandle h1; |
| 348 EXPECT_TRUE(slave.Connect(connection_id, &peer1, &h1)); | 357 EXPECT_TRUE(slave.Connect(connection_id, &peer1, &h1)); |
| 358 EXPECT_TRUE(IsValidSlaveProcessIdentifier(peer1)); |
| 349 EXPECT_FALSE(h1.is_valid()); | 359 EXPECT_FALSE(h1.is_valid()); |
| 350 ProcessIdentifier peer2; | 360 ProcessIdentifier peer2 = kInvalidProcessIdentifier; |
| 351 embedder::ScopedPlatformHandle h2; | 361 embedder::ScopedPlatformHandle h2; |
| 352 EXPECT_TRUE(slave.Connect(connection_id, &peer2, &h2)); | 362 EXPECT_TRUE(slave.Connect(connection_id, &peer2, &h2)); |
| 363 EXPECT_TRUE(IsValidSlaveProcessIdentifier(peer2)); |
| 353 EXPECT_FALSE(h2.is_valid()); | 364 EXPECT_FALSE(h2.is_valid()); |
| 354 | 365 |
| 355 EXPECT_EQ(peer1, peer2); | 366 EXPECT_EQ(peer1, peer2); |
| 356 | 367 |
| 357 slave.Shutdown(); | 368 slave.Shutdown(); |
| 358 master.Shutdown(); | 369 master.Shutdown(); |
| 359 } | 370 } |
| 360 | 371 |
| 361 TEST_F(ConnectionManagerTest, ConnectSlavesTwice) { | 372 TEST_F(ConnectionManagerTest, ConnectSlavesTwice) { |
| 362 MasterConnectionManager master; | 373 MasterConnectionManager master; |
| 363 master.Init(&master_process_delegate()); | 374 master.Init(&master_process_delegate()); |
| 364 | 375 |
| 365 MockSlaveProcessDelegate slave1_process_delegate; | 376 MockSlaveProcessDelegate slave1_process_delegate; |
| 366 SlaveConnectionManager slave1; | 377 SlaveConnectionManager slave1; |
| 367 ConnectSlave(&master, &slave1_process_delegate, &slave1, "slave1"); | 378 ConnectSlave(&master, &slave1_process_delegate, &slave1, "slave1"); |
| 368 | 379 |
| 369 MockSlaveProcessDelegate slave2_process_delegate; | 380 MockSlaveProcessDelegate slave2_process_delegate; |
| 370 SlaveConnectionManager slave2; | 381 SlaveConnectionManager slave2; |
| 371 ConnectSlave(&master, &slave2_process_delegate, &slave2, "slave2"); | 382 ConnectSlave(&master, &slave2_process_delegate, &slave2, "slave2"); |
| 372 | 383 |
| 373 ConnectionIdentifier connection_id = ConnectionIdentifier::Generate(); | 384 ConnectionIdentifier connection_id = ConnectionIdentifier::Generate(); |
| 374 EXPECT_TRUE(slave1.AllowConnect(connection_id)); | 385 EXPECT_TRUE(slave1.AllowConnect(connection_id)); |
| 375 EXPECT_TRUE(slave2.AllowConnect(connection_id)); | 386 EXPECT_TRUE(slave2.AllowConnect(connection_id)); |
| 376 | 387 |
| 377 ProcessIdentifier peer1; | 388 ProcessIdentifier peer1 = kInvalidProcessIdentifier; |
| 378 embedder::ScopedPlatformHandle h1; | 389 embedder::ScopedPlatformHandle h1; |
| 379 EXPECT_TRUE(slave1.Connect(connection_id, &peer1, &h1)); | 390 EXPECT_TRUE(slave1.Connect(connection_id, &peer1, &h1)); |
| 380 ProcessIdentifier peer2; | 391 ProcessIdentifier peer2 = kInvalidProcessIdentifier; |
| 381 embedder::ScopedPlatformHandle h2; | 392 embedder::ScopedPlatformHandle h2; |
| 382 EXPECT_TRUE(slave2.Connect(connection_id, &peer2, &h2)); | 393 EXPECT_TRUE(slave2.Connect(connection_id, &peer2, &h2)); |
| 383 | 394 |
| 384 EXPECT_NE(peer1, peer2); | 395 EXPECT_NE(peer1, peer2); |
| 385 EXPECT_TRUE(ArePlatformHandlesConnected(h1.get(), h2.get())); | 396 EXPECT_TRUE(ArePlatformHandlesConnected(h1.get(), h2.get())); |
| 386 | 397 |
| 387 // Currently, the master doesn't detect the case of connecting a pair of | 398 // Currently, the master doesn't detect the case of connecting a pair of |
| 388 // slaves that are already connected. (Doing so would require more careful | 399 // slaves that are already connected. (Doing so would require more careful |
| 389 // tracking and is prone to races -- especially if we want slaves to be able | 400 // tracking and is prone to races -- especially if we want slaves to be able |
| 390 // to tear down no-longer-needed connections.) But the slaves should be able | 401 // to tear down no-longer-needed connections.) But the slaves should be able |
| 391 // to do the tracking themselves (using the peer process identifiers). | 402 // to do the tracking themselves (using the peer process identifiers). |
| 392 connection_id = ConnectionIdentifier::Generate(); | 403 connection_id = ConnectionIdentifier::Generate(); |
| 393 EXPECT_TRUE(slave1.AllowConnect(connection_id)); | 404 EXPECT_TRUE(slave1.AllowConnect(connection_id)); |
| 394 EXPECT_TRUE(slave2.AllowConnect(connection_id)); | 405 EXPECT_TRUE(slave2.AllowConnect(connection_id)); |
| 395 | 406 |
| 396 h1.reset(); | 407 h1.reset(); |
| 397 h2.reset(); | 408 h2.reset(); |
| 398 ProcessIdentifier second_peer2; | 409 ProcessIdentifier second_peer2 = kInvalidProcessIdentifier; |
| 399 EXPECT_TRUE(slave2.Connect(connection_id, &second_peer2, &h2)); | 410 EXPECT_TRUE(slave2.Connect(connection_id, &second_peer2, &h2)); |
| 400 ProcessIdentifier second_peer1; | 411 ProcessIdentifier second_peer1 = kInvalidProcessIdentifier; |
| 401 EXPECT_TRUE(slave1.Connect(connection_id, &second_peer1, &h1)); | 412 EXPECT_TRUE(slave1.Connect(connection_id, &second_peer1, &h1)); |
| 402 | 413 |
| 403 EXPECT_EQ(peer1, second_peer1); | 414 EXPECT_EQ(peer1, second_peer1); |
| 404 EXPECT_EQ(peer2, second_peer2); | 415 EXPECT_EQ(peer2, second_peer2); |
| 405 EXPECT_TRUE(ArePlatformHandlesConnected(h1.get(), h2.get())); | 416 EXPECT_TRUE(ArePlatformHandlesConnected(h1.get(), h2.get())); |
| 406 | 417 |
| 407 slave2.Shutdown(); | 418 slave2.Shutdown(); |
| 408 slave1.Shutdown(); | 419 slave1.Shutdown(); |
| 409 master.Shutdown(); | 420 master.Shutdown(); |
| 410 } | 421 } |
| 411 | 422 |
| 412 TEST_F(ConnectionManagerTest, ConnectMasterToSlave) { | 423 TEST_F(ConnectionManagerTest, ConnectMasterToSlave) { |
| 413 MasterConnectionManager master; | 424 MasterConnectionManager master; |
| 414 master.Init(&master_process_delegate()); | 425 master.Init(&master_process_delegate()); |
| 415 | 426 |
| 416 MockSlaveProcessDelegate slave_process_delegate; | 427 MockSlaveProcessDelegate slave_process_delegate; |
| 417 SlaveConnectionManager slave; | 428 SlaveConnectionManager slave; |
| 418 ConnectSlave(&master, &slave_process_delegate, &slave, "slave"); | 429 ConnectSlave(&master, &slave_process_delegate, &slave, "slave"); |
| 419 | 430 |
| 420 ConnectionIdentifier connection_id = ConnectionIdentifier::Generate(); | 431 ConnectionIdentifier connection_id = ConnectionIdentifier::Generate(); |
| 421 EXPECT_TRUE(master.AllowConnect(connection_id)); | 432 EXPECT_TRUE(master.AllowConnect(connection_id)); |
| 422 EXPECT_TRUE(slave.AllowConnect(connection_id)); | 433 EXPECT_TRUE(slave.AllowConnect(connection_id)); |
| 423 | 434 |
| 424 ProcessIdentifier master_peer; | 435 ProcessIdentifier master_peer = kInvalidProcessIdentifier; |
| 425 embedder::ScopedPlatformHandle master_h; | 436 embedder::ScopedPlatformHandle master_h; |
| 426 EXPECT_TRUE(master.Connect(connection_id, &master_peer, &master_h)); | 437 EXPECT_TRUE(master.Connect(connection_id, &master_peer, &master_h)); |
| 438 EXPECT_TRUE(IsValidSlaveProcessIdentifier(master_peer)); |
| 427 EXPECT_TRUE(master_h.is_valid()); | 439 EXPECT_TRUE(master_h.is_valid()); |
| 428 ProcessIdentifier slave_peer; | 440 ProcessIdentifier slave_peer = kInvalidProcessIdentifier; |
| 429 embedder::ScopedPlatformHandle slave_h; | 441 embedder::ScopedPlatformHandle slave_h; |
| 430 EXPECT_TRUE(slave.Connect(connection_id, &slave_peer, &slave_h)); | 442 EXPECT_TRUE(slave.Connect(connection_id, &slave_peer, &slave_h)); |
| 443 EXPECT_EQ(kMasterProcessIdentifier, slave_peer); |
| 431 EXPECT_TRUE(slave_h.is_valid()); | 444 EXPECT_TRUE(slave_h.is_valid()); |
| 432 | 445 |
| 433 EXPECT_NE(master_peer, slave_peer); | 446 EXPECT_NE(master_peer, slave_peer); |
| 434 EXPECT_TRUE(ArePlatformHandlesConnected(master_h.get(), slave_h.get())); | 447 EXPECT_TRUE(ArePlatformHandlesConnected(master_h.get(), slave_h.get())); |
| 435 | 448 |
| 436 slave.Shutdown(); | 449 slave.Shutdown(); |
| 437 master.Shutdown(); | 450 master.Shutdown(); |
| 438 } | 451 } |
| 439 | 452 |
| 440 TEST_F(ConnectionManagerTest, ConnectMasterToSelf) { | 453 TEST_F(ConnectionManagerTest, ConnectMasterToSelf) { |
| 441 MasterConnectionManager master; | 454 MasterConnectionManager master; |
| 442 master.Init(&master_process_delegate()); | 455 master.Init(&master_process_delegate()); |
| 443 | 456 |
| 444 ConnectionIdentifier connection_id = ConnectionIdentifier::Generate(); | 457 ConnectionIdentifier connection_id = ConnectionIdentifier::Generate(); |
| 445 EXPECT_TRUE(master.AllowConnect(connection_id)); | 458 EXPECT_TRUE(master.AllowConnect(connection_id)); |
| 446 EXPECT_TRUE(master.AllowConnect(connection_id)); | 459 EXPECT_TRUE(master.AllowConnect(connection_id)); |
| 447 | 460 |
| 448 // Currently, the connect-to-self case is signalled by the master not sending | 461 // Currently, the connect-to-self case is signalled by the master not sending |
| 449 // back a handle. | 462 // back a handle. |
| 450 ProcessIdentifier peer1; | 463 ProcessIdentifier peer1 = kInvalidProcessIdentifier; |
| 451 embedder::ScopedPlatformHandle h1; | 464 embedder::ScopedPlatformHandle h1; |
| 452 EXPECT_TRUE(master.Connect(connection_id, &peer1, &h1)); | 465 EXPECT_TRUE(master.Connect(connection_id, &peer1, &h1)); |
| 466 EXPECT_EQ(kMasterProcessIdentifier, peer1); |
| 453 EXPECT_FALSE(h1.is_valid()); | 467 EXPECT_FALSE(h1.is_valid()); |
| 454 ProcessIdentifier peer2; | 468 ProcessIdentifier peer2 = kInvalidProcessIdentifier; |
| 455 embedder::ScopedPlatformHandle h2; | 469 embedder::ScopedPlatformHandle h2; |
| 456 EXPECT_TRUE(master.Connect(connection_id, &peer2, &h2)); | 470 EXPECT_TRUE(master.Connect(connection_id, &peer2, &h2)); |
| 471 EXPECT_EQ(kMasterProcessIdentifier, peer2); |
| 457 EXPECT_FALSE(h2.is_valid()); | 472 EXPECT_FALSE(h2.is_valid()); |
| 458 | 473 |
| 459 EXPECT_EQ(peer1, peer2); | 474 EXPECT_EQ(peer1, peer2); |
| 460 | 475 |
| 461 master.Shutdown(); | 476 master.Shutdown(); |
| 462 } | 477 } |
| 463 | 478 |
| 464 TEST_F(ConnectionManagerTest, MasterCancelConnect) { | 479 TEST_F(ConnectionManagerTest, MasterCancelConnect) { |
| 465 MasterConnectionManager master; | 480 MasterConnectionManager master; |
| 466 master.Init(&master_process_delegate()); | 481 master.Init(&master_process_delegate()); |
| 467 | 482 |
| 468 MockSlaveProcessDelegate slave_process_delegate; | 483 MockSlaveProcessDelegate slave_process_delegate; |
| 469 SlaveConnectionManager slave; | 484 SlaveConnectionManager slave; |
| 470 ConnectSlave(&master, &slave_process_delegate, &slave, "slave"); | 485 ConnectSlave(&master, &slave_process_delegate, &slave, "slave"); |
| 471 | 486 |
| 472 ConnectionIdentifier connection_id = ConnectionIdentifier::Generate(); | 487 ConnectionIdentifier connection_id = ConnectionIdentifier::Generate(); |
| 473 EXPECT_TRUE(master.AllowConnect(connection_id)); | 488 EXPECT_TRUE(master.AllowConnect(connection_id)); |
| 474 EXPECT_TRUE(slave.AllowConnect(connection_id)); | 489 EXPECT_TRUE(slave.AllowConnect(connection_id)); |
| 475 | 490 |
| 476 EXPECT_TRUE(master.CancelConnect(connection_id)); | 491 EXPECT_TRUE(master.CancelConnect(connection_id)); |
| 477 ProcessIdentifier peer; | 492 ProcessIdentifier peer = kInvalidProcessIdentifier; |
| 478 embedder::ScopedPlatformHandle h; | 493 embedder::ScopedPlatformHandle h; |
| 479 EXPECT_FALSE(slave.Connect(connection_id, &peer, &h)); | 494 EXPECT_FALSE(slave.Connect(connection_id, &peer, &h)); |
| 495 EXPECT_EQ(kInvalidProcessIdentifier, peer); |
| 480 EXPECT_FALSE(h.is_valid()); | 496 EXPECT_FALSE(h.is_valid()); |
| 481 | 497 |
| 482 slave.Shutdown(); | 498 slave.Shutdown(); |
| 483 master.Shutdown(); | 499 master.Shutdown(); |
| 484 } | 500 } |
| 485 | 501 |
| 486 TEST_F(ConnectionManagerTest, AddSlaveThenImmediateShutdown) { | 502 TEST_F(ConnectionManagerTest, AddSlaveThenImmediateShutdown) { |
| 487 MasterConnectionManager master; | 503 MasterConnectionManager master; |
| 488 master.Init(&master_process_delegate()); | 504 master.Init(&master_process_delegate()); |
| 489 | 505 |
| 490 MockSlaveProcessDelegate slave_process_delegate; | 506 MockSlaveProcessDelegate slave_process_delegate; |
| 491 SlaveConnectionManager slave; | 507 SlaveConnectionManager slave; |
| 492 embedder::PlatformChannelPair platform_channel_pair; | 508 embedder::PlatformChannelPair platform_channel_pair; |
| 493 master.AddSlave(make_scoped_ptr(new TestSlaveInfo("slave")), | 509 master.AddSlave(make_scoped_ptr(new TestSlaveInfo("slave")), |
| 494 platform_channel_pair.PassServerHandle()); | 510 platform_channel_pair.PassServerHandle()); |
| 495 master.Shutdown(); | 511 master.Shutdown(); |
| 496 // Since we never initialized |slave|, we don't have to shut it down. | 512 // Since we never initialized |slave|, we don't have to shut it down. |
| 497 } | 513 } |
| 498 | 514 |
| 499 } // namespace | 515 } // namespace |
| 500 } // namespace system | 516 } // namespace system |
| 501 } // namespace mojo | 517 } // namespace mojo |
| OLD | NEW |