Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(67)

Side by Side Diff: services/shell/tests/connect/connect_unittest.cc

Issue 2179023004: Make Service own ServiceContext. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: . Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
85 } 85 }
86 86
87 void set_ping_callback(const base::Closure& callback) { 87 void set_ping_callback(const base::Closure& callback) {
88 ping_callback_ = callback; 88 ping_callback_ = callback;
89 } 89 }
90 90
91 void CompareConnectionState( 91 void CompareConnectionState(
92 const std::string& connection_local_name, 92 const std::string& connection_local_name,
93 const std::string& connection_remote_name, 93 const std::string& connection_remote_name,
94 const std::string& connection_remote_userid, 94 const std::string& connection_remote_userid,
95 uint32_t connection_remote_id,
96 const std::string& initialize_local_name, 95 const std::string& initialize_local_name,
97 const std::string& initialize_userid, 96 const std::string& initialize_userid) {
98 uint32_t initialize_id) {
99 EXPECT_EQ(connection_local_name, connection_state_->connection_local_name); 97 EXPECT_EQ(connection_local_name, connection_state_->connection_local_name);
100 EXPECT_EQ(connection_remote_name, 98 EXPECT_EQ(connection_remote_name,
101 connection_state_->connection_remote_name); 99 connection_state_->connection_remote_name);
102 EXPECT_EQ(connection_remote_userid, 100 EXPECT_EQ(connection_remote_userid,
103 connection_state_->connection_remote_userid); 101 connection_state_->connection_remote_userid);
104 EXPECT_EQ(connection_remote_id, connection_state_->connection_remote_id);
105 EXPECT_EQ(initialize_local_name, connection_state_->initialize_local_name); 102 EXPECT_EQ(initialize_local_name, connection_state_->initialize_local_name);
106 EXPECT_EQ(initialize_id, connection_state_->initialize_id);
107 EXPECT_EQ(initialize_userid, connection_state_->initialize_userid); 103 EXPECT_EQ(initialize_userid, connection_state_->initialize_userid);
108 } 104 }
109 105
110 private: 106 private:
111 // test::ServiceTest: 107 // test::ServiceTest:
112 void SetUp() override { 108 void SetUp() override {
113 test::ServiceTest::SetUp(); 109 test::ServiceTest::SetUp();
114 // We need to connect to the package first to force the shell to read the 110 // We need to connect to the package first to force the shell to read the
115 // package app's manifest and register aliases for the applications it 111 // package app's manifest and register aliases for the applications it
116 // provides. 112 // provides.
(...skipping 289 matching lines...) Expand 10 before | Expand all | Expand 10 after
406 402
407 // Tests that we can expose an interface to targets on outbound connections. 403 // Tests that we can expose an interface to targets on outbound connections.
408 TEST_F(ConnectTest, LocalInterface) { 404 TEST_F(ConnectTest, LocalInterface) {
409 // Connect to a standalone application. 405 // Connect to a standalone application.
410 { 406 {
411 test::mojom::ConnectTestServicePtr service; 407 test::mojom::ConnectTestServicePtr service;
412 std::unique_ptr<Connection> connection = connector()->Connect(kTestAppName); 408 std::unique_ptr<Connection> connection = connector()->Connect(kTestAppName);
413 connection->GetInterface(&service); 409 connection->GetInterface(&service);
414 connection->AddInterface<test::mojom::ExposedInterface>(this); 410 connection->AddInterface<test::mojom::ExposedInterface>(this);
415 411
416 uint32_t remote_id = mojom::kInvalidInstanceID;
417 { 412 {
418 base::RunLoop run_loop; 413 base::RunLoop run_loop;
419 EXPECT_TRUE(connection->IsPending()); 414 EXPECT_TRUE(connection->IsPending());
420 EXPECT_EQ(mojom::kInvalidInstanceID, connection->GetRemoteInstanceID()); 415 EXPECT_EQ(mojom::kInvalidInstanceID, connection->GetRemoteInstanceID());
421 connection->AddConnectionCompletedClosure( 416 connection->AddConnectionCompletedClosure(
422 base::Bind(&QuitLoop, &run_loop)); 417 base::Bind(&QuitLoop, &run_loop));
423 run_loop.Run(); 418 run_loop.Run();
424 EXPECT_FALSE(connection->IsPending()); 419 EXPECT_FALSE(connection->IsPending());
425 remote_id = connection->GetRemoteInstanceID();
426 EXPECT_NE(mojom::kInvalidInstanceID, remote_id);
427 } 420 }
428 421
429 { 422 {
430 base::RunLoop run_loop; 423 base::RunLoop run_loop;
431 set_ping_callback(base::Bind(&QuitLoop, &run_loop)); 424 set_ping_callback(base::Bind(&QuitLoop, &run_loop));
432 run_loop.Run(); 425 run_loop.Run();
433 CompareConnectionState( 426 CompareConnectionState(
434 kTestAppName, test_name(), test_userid(), test_instance_id(), 427 kTestAppName, test_name(), test_userid(), kTestAppName,
435 kTestAppName, connection->GetRemoteIdentity().user_id(), remote_id); 428 connection->GetRemoteIdentity().user_id());
436 } 429 }
437 } 430 }
438 431
439 // Connect to an application provided by a package. 432 // Connect to an application provided by a package.
440 { 433 {
441 test::mojom::ConnectTestServicePtr service_a; 434 test::mojom::ConnectTestServicePtr service_a;
442 std::unique_ptr<Connection> connection = 435 std::unique_ptr<Connection> connection =
443 connector()->Connect(kTestAppAName); 436 connector()->Connect(kTestAppAName);
444 connection->GetInterface(&service_a); 437 connection->GetInterface(&service_a);
445 connection->AddInterface<test::mojom::ExposedInterface>(this); 438 connection->AddInterface<test::mojom::ExposedInterface>(this);
446 439
447 uint32_t remote_id = mojom::kInvalidInstanceID;
448 { 440 {
449 base::RunLoop run_loop; 441 base::RunLoop run_loop;
450 EXPECT_TRUE(connection->IsPending()); 442 EXPECT_TRUE(connection->IsPending());
451 EXPECT_EQ(mojom::kInvalidInstanceID, connection->GetRemoteInstanceID()); 443 EXPECT_EQ(mojom::kInvalidInstanceID, connection->GetRemoteInstanceID());
452 connection->AddConnectionCompletedClosure( 444 connection->AddConnectionCompletedClosure(
453 base::Bind(&QuitLoop, &run_loop)); 445 base::Bind(&QuitLoop, &run_loop));
454 run_loop.Run(); 446 run_loop.Run();
455 EXPECT_FALSE(connection->IsPending()); 447 EXPECT_FALSE(connection->IsPending());
456 remote_id = connection->GetRemoteInstanceID();
457 EXPECT_NE(mojom::kInvalidInstanceID, remote_id);
458 } 448 }
459 449
460 { 450 {
461 base::RunLoop run_loop; 451 base::RunLoop run_loop;
462 set_ping_callback(base::Bind(&QuitLoop, &run_loop)); 452 set_ping_callback(base::Bind(&QuitLoop, &run_loop));
463 run_loop.Run(); 453 run_loop.Run();
464 CompareConnectionState( 454 CompareConnectionState(
465 kTestAppAName, test_name(), test_userid(), test_instance_id(), 455 kTestAppAName, test_name(), test_userid(), kTestAppAName,
466 kTestAppAName, connection->GetRemoteIdentity().user_id(), remote_id); 456 connection->GetRemoteIdentity().user_id());
467 } 457 }
468 458
469 } 459 }
470 } 460 }
471 461
472 } // namespace shell 462 } // namespace shell
OLDNEW
« no previous file with comments | « services/shell/tests/connect/connect_test_singleton_app.cc ('k') | services/shell/tests/lifecycle/lifecycle_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698