OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "mojo/shell/application_manager.h" | 5 #include "mojo/shell/application_manager.h" |
6 | 6 |
7 #include <utility> | 7 #include <utility> |
8 | 8 |
9 #include "base/at_exit.h" | 9 #include "base/at_exit.h" |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 19 matching lines...) Expand all Loading... |
30 const char kTestAURLString[] = "test:TestA"; | 30 const char kTestAURLString[] = "test:TestA"; |
31 const char kTestBURLString[] = "test:TestB"; | 31 const char kTestBURLString[] = "test:TestB"; |
32 | 32 |
33 struct TestContext { | 33 struct TestContext { |
34 TestContext() : num_impls(0), num_loader_deletes(0) {} | 34 TestContext() : num_impls(0), num_loader_deletes(0) {} |
35 std::string last_test_string; | 35 std::string last_test_string; |
36 int num_impls; | 36 int num_impls; |
37 int num_loader_deletes; | 37 int num_loader_deletes; |
38 }; | 38 }; |
39 | 39 |
40 void QuitClosure(bool* value) { | 40 void QuitClosure(const Identity& expected, |
41 *value = true; | 41 bool* value, |
42 base::MessageLoop::current()->QuitWhenIdle(); | 42 const Identity& actual) { |
| 43 if (expected == actual) { |
| 44 *value = true; |
| 45 base::MessageLoop::current()->QuitWhenIdle(); |
| 46 } |
43 } | 47 } |
44 | 48 |
45 class TestServiceImpl : public TestService { | 49 class TestServiceImpl : public TestService { |
46 public: | 50 public: |
47 TestServiceImpl(TestContext* context, InterfaceRequest<TestService> request) | 51 TestServiceImpl(TestContext* context, InterfaceRequest<TestService> request) |
48 : context_(context), binding_(this, std::move(request)) { | 52 : context_(context), binding_(this, std::move(request)) { |
49 ++context_->num_impls; | 53 ++context_->num_impls; |
50 } | 54 } |
51 | 55 |
52 ~TestServiceImpl() override { | 56 ~TestServiceImpl() override { |
(...skipping 537 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
590 } | 594 } |
591 | 595 |
592 TEST_F(ApplicationManagerTest, TestEndApplicationClosure) { | 596 TEST_F(ApplicationManagerTest, TestEndApplicationClosure) { |
593 ClosingApplicationLoader* loader = new ClosingApplicationLoader(); | 597 ClosingApplicationLoader* loader = new ClosingApplicationLoader(); |
594 application_manager_->SetLoaderForURL( | 598 application_manager_->SetLoaderForURL( |
595 scoped_ptr<ApplicationLoader>(loader), GURL("test:test")); | 599 scoped_ptr<ApplicationLoader>(loader), GURL("test:test")); |
596 | 600 |
597 bool called = false; | 601 bool called = false; |
598 scoped_ptr<ConnectParams> params(new ConnectParams); | 602 scoped_ptr<ConnectParams> params(new ConnectParams); |
599 params->SetTargetURL(GURL("test:test")); | 603 params->SetTargetURL(GURL("test:test")); |
600 params->set_on_application_end( | 604 application_manager_->SetInstanceQuitCallback( |
601 base::Bind(&QuitClosure, base::Unretained(&called))); | 605 base::Bind(&QuitClosure, params->target(), &called)); |
602 application_manager_->Connect(std::move(params)); | 606 application_manager_->Connect(std::move(params)); |
603 loop_.Run(); | 607 loop_.Run(); |
604 EXPECT_TRUE(called); | 608 EXPECT_TRUE(called); |
605 } | 609 } |
606 | 610 |
607 TEST_F(ApplicationManagerTest, SameIdentityShouldNotCauseDuplicateLoad) { | 611 TEST_F(ApplicationManagerTest, SameIdentityShouldNotCauseDuplicateLoad) { |
608 // 1 because ApplicationManagerTest connects once at startup. | 612 // 1 because ApplicationManagerTest connects once at startup. |
609 EXPECT_EQ(1, test_loader_->num_loads()); | 613 EXPECT_EQ(1, test_loader_->num_loads()); |
610 | 614 |
611 TestServicePtr test_service; | 615 TestServicePtr test_service; |
612 ConnectToInterface(GURL("test:foo"), &test_service); | 616 ConnectToInterface(GURL("test:foo"), &test_service); |
613 EXPECT_EQ(2, test_loader_->num_loads()); | 617 EXPECT_EQ(2, test_loader_->num_loads()); |
614 | 618 |
615 // Exactly the same URL as above. | 619 // Exactly the same URL as above. |
616 ConnectToInterface(GURL("test:foo"), &test_service); | 620 ConnectToInterface(GURL("test:foo"), &test_service); |
617 EXPECT_EQ(2, test_loader_->num_loads()); | 621 EXPECT_EQ(2, test_loader_->num_loads()); |
618 | 622 |
619 // A different identity because the domain is different. | 623 // A different identity because the domain is different. |
620 ConnectToInterface(GURL("test:bar"), &test_service); | 624 ConnectToInterface(GURL("test:bar"), &test_service); |
621 EXPECT_EQ(3, test_loader_->num_loads()); | 625 EXPECT_EQ(3, test_loader_->num_loads()); |
622 } | 626 } |
623 | 627 |
624 } // namespace test | 628 } // namespace test |
625 } // namespace shell | 629 } // namespace shell |
626 } // namespace mojo | 630 } // namespace mojo |
OLD | NEW |