| 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 <memory> | 8 #include <memory> |
| 9 #include <utility> | 9 #include <utility> |
| 10 | 10 |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 72 } // namespace | 72 } // namespace |
| 73 | 73 |
| 74 class ConnectTest : public test::ServiceTest, | 74 class ConnectTest : public test::ServiceTest, |
| 75 public InterfaceFactory<test::mojom::ExposedInterface>, | 75 public InterfaceFactory<test::mojom::ExposedInterface>, |
| 76 public test::mojom::ExposedInterface { | 76 public test::mojom::ExposedInterface { |
| 77 public: | 77 public: |
| 78 ConnectTest() : ServiceTest("connect_unittests") {} | 78 ConnectTest() : ServiceTest("connect_unittests") {} |
| 79 ~ConnectTest() override {} | 79 ~ConnectTest() override {} |
| 80 | 80 |
| 81 protected: | 81 protected: |
| 82 std::unique_ptr<Connection> ConnectTo(Connector::ConnectParams* params) { | 82 std::unique_ptr<Connection> ConnectTo(const Identity& target) { |
| 83 std::unique_ptr<Connection> connection = connector()->Connect(params); | 83 std::unique_ptr<Connection> connection = connector()->Connect(target); |
| 84 base::RunLoop loop; | 84 base::RunLoop loop; |
| 85 connection->AddConnectionCompletedClosure(base::Bind(&QuitLoop, &loop)); | 85 connection->AddConnectionCompletedClosure(base::Bind(&QuitLoop, &loop)); |
| 86 loop.Run(); | 86 loop.Run(); |
| 87 return connection; | 87 return connection; |
| 88 } | 88 } |
| 89 | 89 |
| 90 void CompareConnectionState( | 90 void CompareConnectionState( |
| 91 const std::string& connection_local_name, | 91 const std::string& connection_local_name, |
| 92 const std::string& connection_remote_name, | 92 const std::string& connection_remote_name, |
| 93 const std::string& connection_remote_userid, | 93 const std::string& connection_remote_userid, |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 168 base::RunLoop run_loop; | 168 base::RunLoop run_loop; |
| 169 std::string title; | 169 std::string title; |
| 170 service->GetTitle(base::Bind(&ReceiveOneString, &title, &run_loop)); | 170 service->GetTitle(base::Bind(&ReceiveOneString, &title, &run_loop)); |
| 171 run_loop.Run(); | 171 run_loop.Run(); |
| 172 EXPECT_EQ("APP", title); | 172 EXPECT_EQ("APP", title); |
| 173 EXPECT_FALSE(connection->IsPending()); | 173 EXPECT_FALSE(connection->IsPending()); |
| 174 EXPECT_EQ(connection->GetRemoteIdentity().name(), kTestAppName); | 174 EXPECT_EQ(connection->GetRemoteIdentity().name(), kTestAppName); |
| 175 } | 175 } |
| 176 | 176 |
| 177 TEST_F(ConnectTest, Instances) { | 177 TEST_F(ConnectTest, Instances) { |
| 178 Connector::ConnectParams params_a( | 178 Identity identity_a(kTestAppName, mojom::kInheritUserID, "A"); |
| 179 Identity(kTestAppName, mojom::kInheritUserID, "A")); | 179 std::unique_ptr<Connection> connection_a1 = ConnectTo(identity_a); |
| 180 std::unique_ptr<Connection> connection_a1 = ConnectTo(¶ms_a); | 180 std::unique_ptr<Connection> connection_a2 = ConnectTo(identity_a); |
| 181 std::unique_ptr<Connection> connection_a2 = ConnectTo(¶ms_a); | |
| 182 std::string instance_a1, instance_a2; | 181 std::string instance_a1, instance_a2; |
| 183 test::mojom::ConnectTestServicePtr service_a1; | 182 test::mojom::ConnectTestServicePtr service_a1; |
| 184 { | 183 { |
| 185 connection_a1->GetInterface(&service_a1); | 184 connection_a1->GetInterface(&service_a1); |
| 186 base::RunLoop loop; | 185 base::RunLoop loop; |
| 187 service_a1->GetInstance(base::Bind(&ReceiveOneString, &instance_a1, &loop)); | 186 service_a1->GetInstance(base::Bind(&ReceiveOneString, &instance_a1, &loop)); |
| 188 loop.Run(); | 187 loop.Run(); |
| 189 } | 188 } |
| 190 test::mojom::ConnectTestServicePtr service_a2; | 189 test::mojom::ConnectTestServicePtr service_a2; |
| 191 { | 190 { |
| 192 connection_a2->GetInterface(&service_a2); | 191 connection_a2->GetInterface(&service_a2); |
| 193 base::RunLoop loop; | 192 base::RunLoop loop; |
| 194 service_a2->GetInstance(base::Bind(&ReceiveOneString, &instance_a2, &loop)); | 193 service_a2->GetInstance(base::Bind(&ReceiveOneString, &instance_a2, &loop)); |
| 195 loop.Run(); | 194 loop.Run(); |
| 196 } | 195 } |
| 197 EXPECT_EQ(instance_a1, instance_a2); | 196 EXPECT_EQ(instance_a1, instance_a2); |
| 198 | 197 |
| 199 Connector::ConnectParams params_b( | 198 Identity identity_b(kTestAppName, mojom::kInheritUserID, "B"); |
| 200 Identity(kTestAppName, mojom::kInheritUserID, "B")); | 199 std::unique_ptr<Connection> connection_b = ConnectTo(identity_b); |
| 201 std::unique_ptr<Connection> connection_b = ConnectTo(¶ms_b); | |
| 202 std::string instance_b; | 200 std::string instance_b; |
| 203 test::mojom::ConnectTestServicePtr service_b; | 201 test::mojom::ConnectTestServicePtr service_b; |
| 204 { | 202 { |
| 205 connection_b->GetInterface(&service_b); | 203 connection_b->GetInterface(&service_b); |
| 206 base::RunLoop loop; | 204 base::RunLoop loop; |
| 207 service_b->GetInstance(base::Bind(&ReceiveOneString, &instance_b, &loop)); | 205 service_b->GetInstance(base::Bind(&ReceiveOneString, &instance_b, &loop)); |
| 208 loop.Run(); | 206 loop.Run(); |
| 209 } | 207 } |
| 210 | 208 |
| 211 EXPECT_NE(instance_a1, instance_b); | 209 EXPECT_NE(instance_a1, instance_b); |
| (...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 361 } | 359 } |
| 362 | 360 |
| 363 // Verifies that a client with the "all_users" capability class can receive | 361 // Verifies that a client with the "all_users" capability class can receive |
| 364 // connections from clients run as other users. | 362 // connections from clients run as other users. |
| 365 TEST_F(ConnectTest, AllUsersSingleton) { | 363 TEST_F(ConnectTest, AllUsersSingleton) { |
| 366 // Connect to an instance with an explicitly different user_id. This supplied | 364 // Connect to an instance with an explicitly different user_id. This supplied |
| 367 // user id should be ignored by the service manager (which will generate its | 365 // user id should be ignored by the service manager (which will generate its |
| 368 // own | 366 // own |
| 369 // synthetic user id for all-user singleton instances). | 367 // synthetic user id for all-user singleton instances). |
| 370 const std::string singleton_userid = base::GenerateGUID(); | 368 const std::string singleton_userid = base::GenerateGUID(); |
| 371 Connector::ConnectParams params( | 369 Identity singleton_id(kTestSingletonAppName, singleton_userid); |
| 372 Identity(kTestSingletonAppName, singleton_userid)); | 370 std::unique_ptr<Connection> connection = connector()->Connect(singleton_id); |
| 373 std::unique_ptr<Connection> connection = connector()->Connect(¶ms); | |
| 374 { | 371 { |
| 375 base::RunLoop loop; | 372 base::RunLoop loop; |
| 376 connection->AddConnectionCompletedClosure(base::Bind(&QuitLoop, &loop)); | 373 connection->AddConnectionCompletedClosure(base::Bind(&QuitLoop, &loop)); |
| 377 loop.Run(); | 374 loop.Run(); |
| 378 EXPECT_NE(connection->GetRemoteIdentity().user_id(), singleton_userid); | 375 EXPECT_NE(connection->GetRemoteIdentity().user_id(), singleton_userid); |
| 379 } | 376 } |
| 380 // This connects using the current client's user_id. It should be bound to the | 377 // This connects using the current client's user_id. It should be bound to the |
| 381 // same service started above, with the same service manager-generated user | 378 // same service started above, with the same service manager-generated user |
| 382 // id. | 379 // id. |
| 383 std::unique_ptr<Connection> inherit_connection = | 380 std::unique_ptr<Connection> inherit_connection = |
| 384 connector()->Connect(kTestSingletonAppName); | 381 connector()->Connect(kTestSingletonAppName); |
| 385 { | 382 { |
| 386 base::RunLoop loop; | 383 base::RunLoop loop; |
| 387 inherit_connection->AddConnectionCompletedClosure( | 384 inherit_connection->AddConnectionCompletedClosure( |
| 388 base::Bind(&QuitLoop, &loop)); | 385 base::Bind(&QuitLoop, &loop)); |
| 389 loop.Run(); | 386 loop.Run(); |
| 390 EXPECT_EQ(inherit_connection->GetRemoteIdentity().user_id(), | 387 EXPECT_EQ(inherit_connection->GetRemoteIdentity().user_id(), |
| 391 connection->GetRemoteIdentity().user_id()); | 388 connection->GetRemoteIdentity().user_id()); |
| 392 } | 389 } |
| 393 } | 390 } |
| 394 | 391 |
| 395 } // namespace service_manager | 392 } // namespace service_manager |
| OLD | NEW |