| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 <stddef.h> | 5 #include <stddef.h> |
| 6 #include <stdint.h> | 6 #include <stdint.h> |
| 7 | 7 |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 12 matching lines...) Expand all Loading... |
| 23 // the package's manifest and are thus registered with the PackageManager. | 23 // the package's manifest and are thus registered with the PackageManager. |
| 24 | 24 |
| 25 namespace mojo { | 25 namespace mojo { |
| 26 namespace shell { | 26 namespace shell { |
| 27 namespace { | 27 namespace { |
| 28 const char kTestPackageName[] = "mojo:connect_test_package"; | 28 const char kTestPackageName[] = "mojo:connect_test_package"; |
| 29 const char kTestAppName[] = "mojo:connect_test_app"; | 29 const char kTestAppName[] = "mojo:connect_test_app"; |
| 30 const char kTestAppAName[] = "mojo:connect_test_a"; | 30 const char kTestAppAName[] = "mojo:connect_test_a"; |
| 31 const char kTestAppBName[] = "mojo:connect_test_b"; | 31 const char kTestAppBName[] = "mojo:connect_test_b"; |
| 32 const char kTestClassAppName[] = "mojo:connect_test_class_app"; | 32 const char kTestClassAppName[] = "mojo:connect_test_class_app"; |
| 33 const char kTestSingletonAppName[] = "mojo:connect_test_singleton_app"; |
| 33 const char kTestDriverName[] = "exe:connect_test_driver"; | 34 const char kTestDriverName[] = "exe:connect_test_driver"; |
| 34 | 35 |
| 35 void ReceiveOneString(std::string* out_string, | 36 void ReceiveOneString(std::string* out_string, |
| 36 base::RunLoop* loop, | 37 base::RunLoop* loop, |
| 37 const String& in_string) { | 38 const String& in_string) { |
| 38 *out_string = in_string; | 39 *out_string = in_string; |
| 39 loop->Quit(); | 40 loop->Quit(); |
| 40 } | 41 } |
| 41 | 42 |
| 42 void ReceiveTwoStrings(std::string* out_string_1, std::string* out_string_2, | 43 void ReceiveTwoStrings(std::string* out_string_1, std::string* out_string_2, |
| (...skipping 305 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 348 client_process_test->LaunchAndConnectToProcess( | 349 client_process_test->LaunchAndConnectToProcess( |
| 349 base::Bind(&ReceiveConnectionResult, &result, &result_identity, &loop)); | 350 base::Bind(&ReceiveConnectionResult, &result, &result_identity, &loop)); |
| 350 loop.Run(); | 351 loop.Run(); |
| 351 } | 352 } |
| 352 EXPECT_EQ(shell::mojom::ConnectResult::ACCESS_DENIED, result); | 353 EXPECT_EQ(shell::mojom::ConnectResult::ACCESS_DENIED, result); |
| 353 } | 354 } |
| 354 | 355 |
| 355 // Verifies that a client with the "all_users" capability class can receive | 356 // Verifies that a client with the "all_users" capability class can receive |
| 356 // connections from clients run as other users. | 357 // connections from clients run as other users. |
| 357 TEST_F(ConnectTest, AllUsersSingleton) { | 358 TEST_F(ConnectTest, AllUsersSingleton) { |
| 358 // Connect to an instance with an explicitly different user_id. | 359 // Connect to an instance with an explicitly different user_id. This supplied |
| 360 // user id should be ignored by the shell (which will generate its own |
| 361 // synthetic user id for all-user singleton instances). |
| 359 const std::string singleton_userid = base::GenerateGUID(); | 362 const std::string singleton_userid = base::GenerateGUID(); |
| 360 Connector::ConnectParams params(Identity(kTestAppName, singleton_userid)); | 363 Connector::ConnectParams params( |
| 364 Identity(kTestSingletonAppName, singleton_userid)); |
| 361 scoped_ptr<Connection> connection = connector()->Connect(¶ms); | 365 scoped_ptr<Connection> connection = connector()->Connect(¶ms); |
| 362 { | 366 { |
| 363 base::RunLoop loop; | 367 base::RunLoop loop; |
| 364 connection->AddConnectionCompletedClosure(base::Bind(&QuitLoop, &loop)); | 368 connection->AddConnectionCompletedClosure(base::Bind(&QuitLoop, &loop)); |
| 365 loop.Run(); | 369 loop.Run(); |
| 366 EXPECT_EQ(connection->GetRemoteIdentity().user_id(), singleton_userid); | 370 EXPECT_NE(connection->GetRemoteIdentity().user_id(), singleton_userid); |
| 367 } | 371 } |
| 368 // This connects using the current client's user_id, but should be bound to | 372 // This connects using the current client's user_id. It should be bound to the |
| 369 // the instance run as |singleton_userid|. | 373 // same service started above, with the same shell-generated user id. |
| 370 scoped_ptr<Connection> inherit_connection = | 374 scoped_ptr<Connection> inherit_connection = |
| 371 connector()->Connect(kTestAppName); | 375 connector()->Connect(kTestSingletonAppName); |
| 372 { | 376 { |
| 373 base::RunLoop loop; | 377 base::RunLoop loop; |
| 374 inherit_connection->AddConnectionCompletedClosure( | 378 inherit_connection->AddConnectionCompletedClosure( |
| 375 base::Bind(&QuitLoop, &loop)); | 379 base::Bind(&QuitLoop, &loop)); |
| 376 loop.Run(); | 380 loop.Run(); |
| 377 EXPECT_EQ(connection->GetRemoteIdentity().user_id(), singleton_userid); | 381 EXPECT_EQ(inherit_connection->GetRemoteIdentity().user_id(), |
| 382 connection->GetRemoteIdentity().user_id()); |
| 378 } | 383 } |
| 379 } | 384 } |
| 380 | 385 |
| 381 // Tests that we can expose an interface to targets on outbound connections. | 386 // Tests that we can expose an interface to targets on outbound connections. |
| 382 TEST_F(ConnectTest, LocalInterface) { | 387 TEST_F(ConnectTest, LocalInterface) { |
| 383 // Connect to a standalone application. | 388 // Connect to a standalone application. |
| 384 { | 389 { |
| 385 test::mojom::ConnectTestServicePtr service; | 390 test::mojom::ConnectTestServicePtr service; |
| 386 scoped_ptr<Connection> connection = connector()->Connect(kTestAppName); | 391 scoped_ptr<Connection> connection = connector()->Connect(kTestAppName); |
| 387 connection->GetInterface(&service); | 392 connection->GetInterface(&service); |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 437 CompareConnectionState( | 442 CompareConnectionState( |
| 438 kTestAppAName, test_name(), test_userid(), test_instance_id(), | 443 kTestAppAName, test_name(), test_userid(), test_instance_id(), |
| 439 kTestAppAName, connection->GetRemoteIdentity().user_id(), remote_id); | 444 kTestAppAName, connection->GetRemoteIdentity().user_id(), remote_id); |
| 440 } | 445 } |
| 441 | 446 |
| 442 } | 447 } |
| 443 } | 448 } |
| 444 | 449 |
| 445 } // namespace shell | 450 } // namespace shell |
| 446 } // namespace mojo | 451 } // namespace mojo |
| OLD | NEW |