| 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" |
| 11 #include "base/macros.h" | 11 #include "base/macros.h" |
| 12 #include "base/memory/scoped_vector.h" | 12 #include "base/memory/scoped_vector.h" |
| 13 #include "base/message_loop/message_loop.h" | 13 #include "base/message_loop/message_loop.h" |
| 14 #include "base/run_loop.h" | 14 #include "base/run_loop.h" |
| 15 #include "mojo/public/cpp/bindings/strong_binding.h" | 15 #include "mojo/public/cpp/bindings/strong_binding.h" |
| 16 #include "mojo/shell/application_loader.h" | 16 #include "mojo/shell/application_loader.h" |
| 17 #include "mojo/shell/connect_util.h" | 17 #include "mojo/shell/connect_util.h" |
| 18 #include "mojo/shell/fetcher.h" | |
| 19 #include "mojo/shell/package_manager.h" | |
| 20 #include "mojo/shell/public/cpp/interface_factory.h" | 18 #include "mojo/shell/public/cpp/interface_factory.h" |
| 21 #include "mojo/shell/public/cpp/shell_client.h" | 19 #include "mojo/shell/public/cpp/shell_client.h" |
| 22 #include "mojo/shell/public/cpp/shell_connection.h" | 20 #include "mojo/shell/public/cpp/shell_connection.h" |
| 23 #include "mojo/shell/public/interfaces/interface_provider.mojom.h" | 21 #include "mojo/shell/public/interfaces/interface_provider.mojom.h" |
| 24 #include "mojo/shell/test.mojom.h" | 22 #include "mojo/shell/test.mojom.h" |
| 25 #include "mojo/shell/test_package_manager.h" | |
| 26 #include "testing/gtest/include/gtest/gtest.h" | 23 #include "testing/gtest/include/gtest/gtest.h" |
| 27 | 24 |
| 28 namespace mojo { | 25 namespace mojo { |
| 29 namespace shell { | 26 namespace shell { |
| 30 namespace test { | 27 namespace test { |
| 31 | 28 |
| 32 const char kTestURLString[] = "test:testService"; | 29 const char kTestURLString[] = "test:testService"; |
| 33 const char kTestAURLString[] = "test:TestA"; | 30 const char kTestAURLString[] = "test:TestA"; |
| 34 const char kTestBURLString[] = "test:TestB"; | 31 const char kTestBURLString[] = "test:TestB"; |
| 35 | 32 |
| (...skipping 351 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 387 ScopedVector<TestAImpl> a_bindings_; | 384 ScopedVector<TestAImpl> a_bindings_; |
| 388 }; | 385 }; |
| 389 | 386 |
| 390 class ApplicationManagerTest : public testing::Test { | 387 class ApplicationManagerTest : public testing::Test { |
| 391 public: | 388 public: |
| 392 ApplicationManagerTest() : tester_context_(&loop_) {} | 389 ApplicationManagerTest() : tester_context_(&loop_) {} |
| 393 | 390 |
| 394 ~ApplicationManagerTest() override {} | 391 ~ApplicationManagerTest() override {} |
| 395 | 392 |
| 396 void SetUp() override { | 393 void SetUp() override { |
| 397 application_manager_.reset(new ApplicationManager( | 394 application_manager_.reset(new ApplicationManager(true)); |
| 398 make_scoped_ptr(new TestPackageManager), true)); | |
| 399 test_loader_ = new TestApplicationLoader; | 395 test_loader_ = new TestApplicationLoader; |
| 400 test_loader_->set_context(&context_); | 396 test_loader_->set_context(&context_); |
| 401 application_manager_->set_default_loader( | 397 application_manager_->set_default_loader( |
| 402 scoped_ptr<ApplicationLoader>(test_loader_)); | 398 scoped_ptr<ApplicationLoader>(test_loader_)); |
| 403 | 399 |
| 404 TestServicePtr service_proxy; | 400 TestServicePtr service_proxy; |
| 405 ConnectToInterface(application_manager_.get(), GURL(kTestURLString), | 401 ConnectToInterface(application_manager_.get(), GURL(kTestURLString), |
| 406 &service_proxy); | 402 &service_proxy); |
| 407 test_client_.reset(new TestClient(std::move(service_proxy))); | 403 test_client_.reset(new TestClient(std::move(service_proxy))); |
| 408 } | 404 } |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 445 loop_.Run(); | 441 loop_.Run(); |
| 446 EXPECT_EQ(1, context_.num_impls); | 442 EXPECT_EQ(1, context_.num_impls); |
| 447 test_client_.reset(); | 443 test_client_.reset(); |
| 448 loop_.Run(); | 444 loop_.Run(); |
| 449 EXPECT_EQ(0, context_.num_impls); | 445 EXPECT_EQ(0, context_.num_impls); |
| 450 EXPECT_TRUE(HasRunningInstanceForURL(GURL(kTestURLString))); | 446 EXPECT_TRUE(HasRunningInstanceForURL(GURL(kTestURLString))); |
| 451 } | 447 } |
| 452 | 448 |
| 453 TEST_F(ApplicationManagerTest, Deletes) { | 449 TEST_F(ApplicationManagerTest, Deletes) { |
| 454 { | 450 { |
| 455 ApplicationManager am(make_scoped_ptr(new TestPackageManager), true); | 451 ApplicationManager am(true); |
| 456 TestApplicationLoader* default_loader = new TestApplicationLoader; | 452 TestApplicationLoader* default_loader = new TestApplicationLoader; |
| 457 default_loader->set_context(&context_); | 453 default_loader->set_context(&context_); |
| 458 TestApplicationLoader* url_loader1 = new TestApplicationLoader; | 454 TestApplicationLoader* url_loader1 = new TestApplicationLoader; |
| 459 TestApplicationLoader* url_loader2 = new TestApplicationLoader; | 455 TestApplicationLoader* url_loader2 = new TestApplicationLoader; |
| 460 url_loader1->set_context(&context_); | 456 url_loader1->set_context(&context_); |
| 461 url_loader2->set_context(&context_); | 457 url_loader2->set_context(&context_); |
| 462 am.set_default_loader(scoped_ptr<ApplicationLoader>(default_loader)); | 458 am.set_default_loader(scoped_ptr<ApplicationLoader>(default_loader)); |
| 463 am.SetLoaderForURL(scoped_ptr<ApplicationLoader>(url_loader1), | 459 am.SetLoaderForURL(scoped_ptr<ApplicationLoader>(url_loader1), |
| 464 GURL("test:test1")); | 460 GURL("test:test1")); |
| 465 am.SetLoaderForURL(scoped_ptr<ApplicationLoader>(url_loader2), | 461 am.SetLoaderForURL(scoped_ptr<ApplicationLoader>(url_loader2), |
| (...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 593 loop_.Run(); | 589 loop_.Run(); |
| 594 EXPECT_TRUE(called); | 590 EXPECT_TRUE(called); |
| 595 } | 591 } |
| 596 | 592 |
| 597 TEST_F(ApplicationManagerTest, SameIdentityShouldNotCauseDuplicateLoad) { | 593 TEST_F(ApplicationManagerTest, SameIdentityShouldNotCauseDuplicateLoad) { |
| 598 // 1 because ApplicationManagerTest connects once at startup. | 594 // 1 because ApplicationManagerTest connects once at startup. |
| 599 EXPECT_EQ(1, test_loader_->num_loads()); | 595 EXPECT_EQ(1, test_loader_->num_loads()); |
| 600 | 596 |
| 601 TestServicePtr test_service; | 597 TestServicePtr test_service; |
| 602 ConnectToInterface(application_manager_.get(), | 598 ConnectToInterface(application_manager_.get(), |
| 603 GURL("http://www.example.org/abc?def"), &test_service); | 599 GURL("mojo:foo"), &test_service); |
| 604 EXPECT_EQ(2, test_loader_->num_loads()); | 600 EXPECT_EQ(2, test_loader_->num_loads()); |
| 605 | 601 |
| 606 // Exactly the same URL as above. | 602 // Exactly the same URL as above. |
| 607 ConnectToInterface(application_manager_.get(), | 603 ConnectToInterface(application_manager_.get(), |
| 608 GURL("http://www.example.org/abc?def"), &test_service); | 604 GURL("mojo:foo"), &test_service); |
| 609 EXPECT_EQ(2, test_loader_->num_loads()); | 605 EXPECT_EQ(2, test_loader_->num_loads()); |
| 610 | 606 |
| 611 // The same identity as the one above because only the query string is | |
| 612 // different. | |
| 613 ConnectToInterface(application_manager_.get(), | |
| 614 GURL("http://www.example.org/abc"), &test_service); | |
| 615 EXPECT_EQ(2, test_loader_->num_loads()); | |
| 616 | |
| 617 // A different identity because the path is different. | |
| 618 ConnectToInterface(application_manager_.get(), | |
| 619 GURL("http://www.example.org/another_path"), &test_service)
; | |
| 620 EXPECT_EQ(3, test_loader_->num_loads()); | |
| 621 | |
| 622 // A different identity because the domain is different. | 607 // A different identity because the domain is different. |
| 623 ConnectToInterface(application_manager_.get(), | 608 ConnectToInterface(application_manager_.get(), |
| 624 GURL("http://www.another_domain.org/abc"), &test_service); | 609 GURL("mojo:bar"), &test_service); |
| 625 EXPECT_EQ(4, test_loader_->num_loads()); | 610 EXPECT_EQ(3, test_loader_->num_loads()); |
| 626 } | 611 } |
| 627 | 612 |
| 628 } // namespace test | 613 } // namespace test |
| 629 } // namespace shell | 614 } // namespace shell |
| 630 } // namespace mojo | 615 } // namespace mojo |
| OLD | NEW |