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

Side by Side Diff: mojo/shell/application_manager_unittest.cc

Issue 1352663002: Extract some stuff into PackageManager (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: . Created 5 years, 3 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
« no previous file with comments | « mojo/shell/application_manager.cc ('k') | mojo/shell/capability_filter_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "base/at_exit.h" 5 #include "base/at_exit.h"
6 #include "base/bind.h" 6 #include "base/bind.h"
7 #include "base/macros.h" 7 #include "base/macros.h"
8 #include "base/memory/scoped_vector.h" 8 #include "base/memory/scoped_vector.h"
9 #include "base/message_loop/message_loop.h" 9 #include "base/message_loop/message_loop.h"
10 #include "base/run_loop.h" 10 #include "base/run_loop.h"
11 #include "mojo/application/public/cpp/application_connection.h" 11 #include "mojo/application/public/cpp/application_connection.h"
12 #include "mojo/application/public/cpp/application_delegate.h" 12 #include "mojo/application/public/cpp/application_delegate.h"
13 #include "mojo/application/public/cpp/application_impl.h" 13 #include "mojo/application/public/cpp/application_impl.h"
14 #include "mojo/application/public/cpp/interface_factory.h" 14 #include "mojo/application/public/cpp/interface_factory.h"
15 #include "mojo/application/public/interfaces/content_handler.mojom.h" 15 #include "mojo/application/public/interfaces/content_handler.mojom.h"
16 #include "mojo/application/public/interfaces/service_provider.mojom.h" 16 #include "mojo/application/public/interfaces/service_provider.mojom.h"
17 #include "mojo/public/cpp/bindings/strong_binding.h" 17 #include "mojo/public/cpp/bindings/strong_binding.h"
18 #include "mojo/shell/application_fetcher.h"
19 #include "mojo/shell/application_loader.h" 18 #include "mojo/shell/application_loader.h"
20 #include "mojo/shell/application_manager.h" 19 #include "mojo/shell/application_manager.h"
21 #include "mojo/shell/fetcher.h" 20 #include "mojo/shell/fetcher.h"
22 #include "mojo/shell/test.mojom.h" 21 #include "mojo/shell/test.mojom.h"
22 #include "mojo/shell/test_package_manager.h"
23 #include "testing/gtest/include/gtest/gtest.h" 23 #include "testing/gtest/include/gtest/gtest.h"
24 24
25 namespace mojo { 25 namespace mojo {
26 namespace shell { 26 namespace shell {
27 namespace { 27 namespace {
28 28
29 const char kTestURLString[] = "test:testService"; 29 const char kTestURLString[] = "test:testService";
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
(...skipping 416 matching lines...) Expand 10 before | Expand all | Expand 10 after
449 InterfaceRequest<TestC> request) override { 449 InterfaceRequest<TestC> request) override {
450 new TestCImpl(connection, context_, request.Pass()); 450 new TestCImpl(connection, context_, request.Pass());
451 } 451 }
452 452
453 TesterContext* context_; 453 TesterContext* context_;
454 scoped_ptr<ApplicationImpl> app_; 454 scoped_ptr<ApplicationImpl> app_;
455 std::string requestor_url_; 455 std::string requestor_url_;
456 ScopedVector<TestAImpl> a_bindings_; 456 ScopedVector<TestAImpl> a_bindings_;
457 }; 457 };
458 458
459 class TestApplicationFetcher : public ApplicationFetcher { 459 class AMTestPackageManager : public TestPackageManager {
460 public: 460 public:
461 TestApplicationFetcher() 461 AMTestPackageManager()
462 : create_test_fetcher_(false), 462 : create_test_fetcher_(false),
463 fetcher_url_("xxx"), 463 fetcher_url_("xxx"),
464 mime_type_(kTestMimeType) {} 464 mime_type_(kTestMimeType) {}
465 ~TestApplicationFetcher() override {} 465 ~AMTestPackageManager() override {}
466 466
467 void set_create_test_fetcher(bool create_test_fetcher) { 467 void set_create_test_fetcher(bool create_test_fetcher) {
468 create_test_fetcher_ = create_test_fetcher; 468 create_test_fetcher_ = create_test_fetcher;
469 } 469 }
470 470
471 void set_fetcher_url(const GURL& url) { fetcher_url_ = url; } 471 void set_fetcher_url(const GURL& url) { fetcher_url_ = url; }
472 472
473 void set_mime_type(const std::string& mime_type) { mime_type_ = mime_type; } 473 void set_mime_type(const std::string& mime_type) { mime_type_ = mime_type; }
474 474
475 // ApplicationManager::Delegate 475 // TestPackageManager:
476 void SetApplicationManager(ApplicationManager* manager) override {}
477 GURL ResolveURL(const GURL& url) override { 476 GURL ResolveURL(const GURL& url) override {
478 GURL resolved_url = url; 477 GURL resolved_url = url;
479 // The shell automatically map mojo URLs. 478 // The shell automatically map mojo URLs.
480 if (resolved_url.scheme() == "mojo") { 479 if (resolved_url.scheme() == "mojo") {
481 url::Replacements<char> replacements; 480 url::Replacements<char> replacements;
482 replacements.SetScheme("file", url::Component(0, 4)); 481 replacements.SetScheme("file", url::Component(0, 4));
483 resolved_url = resolved_url.ReplaceComponents(replacements); 482 resolved_url = resolved_url.ReplaceComponents(replacements);
484 } 483 }
485 return resolved_url; 484 return resolved_url;
486 } 485 }
487 void FetchRequest(URLRequestPtr request, 486 void FetchRequest(URLRequestPtr request,
488 const Fetcher::FetchCallback& loader_callback) override { 487 const Fetcher::FetchCallback& loader_callback) override {
489 if (create_test_fetcher_) 488 if (create_test_fetcher_)
490 new TestMimeTypeFetcher(loader_callback, fetcher_url_, mime_type_); 489 new TestMimeTypeFetcher(loader_callback, fetcher_url_, mime_type_);
491 } 490 }
492 491
493 private: 492 private:
494 bool create_test_fetcher_; 493 bool create_test_fetcher_;
495 GURL fetcher_url_; 494 GURL fetcher_url_;
496 std::string mime_type_; 495 std::string mime_type_;
497 496
498 DISALLOW_COPY_AND_ASSIGN(TestApplicationFetcher); 497 DISALLOW_COPY_AND_ASSIGN(AMTestPackageManager);
499 }; 498 };
500 499
501 class ApplicationManagerTest : public testing::Test { 500 class ApplicationManagerTest : public testing::Test {
502 public: 501 public:
503 ApplicationManagerTest() : tester_context_(&loop_) {} 502 ApplicationManagerTest() : tester_context_(&loop_) {}
504 503
505 ~ApplicationManagerTest() override {} 504 ~ApplicationManagerTest() override {}
506 505
507 void SetUp() override { 506 void SetUp() override {
508 application_manager_.reset(new ApplicationManager( 507 application_manager_.reset(new ApplicationManager(
509 make_scoped_ptr(new TestApplicationFetcher))); 508 make_scoped_ptr(new AMTestPackageManager)));
510 test_loader_ = new TestApplicationLoader; 509 test_loader_ = new TestApplicationLoader;
511 test_loader_->set_context(&context_); 510 test_loader_->set_context(&context_);
512 application_manager_->set_default_loader( 511 application_manager_->set_default_loader(
513 scoped_ptr<ApplicationLoader>(test_loader_)); 512 scoped_ptr<ApplicationLoader>(test_loader_));
514 513
515 TestServicePtr service_proxy; 514 TestServicePtr service_proxy;
516 application_manager_->ConnectToService(GURL(kTestURLString), 515 application_manager_->ConnectToService(GURL(kTestURLString),
517 &service_proxy); 516 &service_proxy);
518 test_client_.reset(new TestClient(service_proxy.Pass())); 517 test_client_.reset(new TestClient(service_proxy.Pass()));
519 } 518 }
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
556 loop_.Run(); 555 loop_.Run();
557 EXPECT_EQ(1, context_.num_impls); 556 EXPECT_EQ(1, context_.num_impls);
558 test_client_.reset(); 557 test_client_.reset();
559 loop_.Run(); 558 loop_.Run();
560 EXPECT_EQ(0, context_.num_impls); 559 EXPECT_EQ(0, context_.num_impls);
561 EXPECT_TRUE(HasRunningInstanceForURL(GURL(kTestURLString))); 560 EXPECT_TRUE(HasRunningInstanceForURL(GURL(kTestURLString)));
562 } 561 }
563 562
564 TEST_F(ApplicationManagerTest, Deletes) { 563 TEST_F(ApplicationManagerTest, Deletes) {
565 { 564 {
566 ApplicationManager am(make_scoped_ptr(new TestApplicationFetcher)); 565 ApplicationManager am(make_scoped_ptr(new AMTestPackageManager));
567 TestApplicationLoader* default_loader = new TestApplicationLoader; 566 TestApplicationLoader* default_loader = new TestApplicationLoader;
568 default_loader->set_context(&context_); 567 default_loader->set_context(&context_);
569 TestApplicationLoader* url_loader1 = new TestApplicationLoader; 568 TestApplicationLoader* url_loader1 = new TestApplicationLoader;
570 TestApplicationLoader* url_loader2 = new TestApplicationLoader; 569 TestApplicationLoader* url_loader2 = new TestApplicationLoader;
571 url_loader1->set_context(&context_); 570 url_loader1->set_context(&context_);
572 url_loader2->set_context(&context_); 571 url_loader2->set_context(&context_);
573 am.set_default_loader(scoped_ptr<ApplicationLoader>(default_loader)); 572 am.set_default_loader(scoped_ptr<ApplicationLoader>(default_loader));
574 am.SetLoaderForURL(scoped_ptr<ApplicationLoader>(url_loader1), 573 am.SetLoaderForURL(scoped_ptr<ApplicationLoader>(url_loader1),
575 GURL("test:test1")); 574 GURL("test:test1"));
576 am.SetLoaderForURL(scoped_ptr<ApplicationLoader>(url_loader2), 575 am.SetLoaderForURL(scoped_ptr<ApplicationLoader>(url_loader2),
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
702 application_manager_->ConnectToApplication(params.Pass()); 701 application_manager_->ConnectToApplication(params.Pass());
703 loop_.Run(); 702 loop_.Run();
704 EXPECT_TRUE(called); 703 EXPECT_TRUE(called);
705 } 704 }
706 705
707 TEST(ApplicationManagerTest2, ContentHandlerConnectionGetsRequestorURL) { 706 TEST(ApplicationManagerTest2, ContentHandlerConnectionGetsRequestorURL) {
708 const GURL content_handler_url("http://test.content.handler"); 707 const GURL content_handler_url("http://test.content.handler");
709 const GURL requestor_url("http://requestor.url"); 708 const GURL requestor_url("http://requestor.url");
710 TestContext test_context; 709 TestContext test_context;
711 base::MessageLoop loop; 710 base::MessageLoop loop;
712 scoped_ptr<TestApplicationFetcher> test_application_fetcher( 711 scoped_ptr<AMTestPackageManager> test_package_manager(
713 new TestApplicationFetcher); 712 new AMTestPackageManager);
714 test_application_fetcher->set_create_test_fetcher(true); 713 test_package_manager->set_create_test_fetcher(true);
715 ApplicationManager application_manager(test_application_fetcher.Pass()); 714 test_package_manager->RegisterContentHandler(kTestMimeType,
715 content_handler_url);
716 ApplicationManager application_manager(test_package_manager.Pass());
716 application_manager.set_default_loader(nullptr); 717 application_manager.set_default_loader(nullptr);
717 application_manager.RegisterContentHandler(kTestMimeType,
718 content_handler_url);
719 718
720 TestApplicationLoader* loader = new TestApplicationLoader; 719 TestApplicationLoader* loader = new TestApplicationLoader;
721 loader->set_context(&test_context); 720 loader->set_context(&test_context);
722 application_manager.SetLoaderForURL(scoped_ptr<ApplicationLoader>(loader), 721 application_manager.SetLoaderForURL(scoped_ptr<ApplicationLoader>(loader),
723 content_handler_url); 722 content_handler_url);
724 723
725 bool called = false; 724 bool called = false;
726 scoped_ptr<ConnectToApplicationParams> params(new ConnectToApplicationParams); 725 scoped_ptr<ConnectToApplicationParams> params(new ConnectToApplicationParams);
727 params->set_originator_identity(Identity(requestor_url)); 726 params->set_originator_identity(Identity(requestor_url));
728 params->set_originator_filter(GetPermissiveCapabilityFilter()); 727 params->set_originator_filter(GetPermissiveCapabilityFilter());
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
768 GURL("http://www.another_domain.org/abc"), &test_service); 767 GURL("http://www.another_domain.org/abc"), &test_service);
769 EXPECT_EQ(4, test_loader_->num_loads()); 768 EXPECT_EQ(4, test_loader_->num_loads());
770 } 769 }
771 770
772 TEST(ApplicationManagerTest2, 771 TEST(ApplicationManagerTest2,
773 MultipleConnectionsToContentHandlerGetSameContentHandlerId) { 772 MultipleConnectionsToContentHandlerGetSameContentHandlerId) {
774 base::MessageLoop loop; 773 base::MessageLoop loop;
775 const GURL content_handler_url("http://test.content.handler"); 774 const GURL content_handler_url("http://test.content.handler");
776 const GURL requestor_url("http://requestor.url"); 775 const GURL requestor_url("http://requestor.url");
777 TestContext test_context; 776 TestContext test_context;
778 scoped_ptr<TestApplicationFetcher> test_application_fetcher( 777 scoped_ptr<AMTestPackageManager> test_package_manager(
779 new TestApplicationFetcher); 778 new AMTestPackageManager);
780 test_application_fetcher->set_fetcher_url(GURL("test:test")); 779 test_package_manager->set_fetcher_url(GURL("test:test"));
781 test_application_fetcher->set_create_test_fetcher(true); 780 test_package_manager->set_create_test_fetcher(true);
782 ApplicationManager application_manager(test_application_fetcher.Pass()); 781 test_package_manager->RegisterContentHandler(kTestMimeType,
782 content_handler_url);
783 ApplicationManager application_manager(test_package_manager.Pass());
783 application_manager.set_default_loader(nullptr); 784 application_manager.set_default_loader(nullptr);
784 application_manager.RegisterContentHandler(kTestMimeType,
785 content_handler_url);
786 785
787 TestApplicationLoader* content_handler_loader = new TestApplicationLoader; 786 TestApplicationLoader* content_handler_loader = new TestApplicationLoader;
788 content_handler_loader->set_create_content_handler(true); 787 content_handler_loader->set_create_content_handler(true);
789 content_handler_loader->set_context(&test_context); 788 content_handler_loader->set_context(&test_context);
790 application_manager.SetLoaderForURL( 789 application_manager.SetLoaderForURL(
791 scoped_ptr<ApplicationLoader>(content_handler_loader), 790 scoped_ptr<ApplicationLoader>(content_handler_loader),
792 content_handler_url); 791 content_handler_url);
793 792
794 uint32_t content_handler_id; 793 uint32_t content_handler_id;
795 { 794 {
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
827 EXPECT_NE(Shell::kInvalidContentHandlerID, content_handler_id2); 826 EXPECT_NE(Shell::kInvalidContentHandlerID, content_handler_id2);
828 } 827 }
829 EXPECT_EQ(content_handler_id, content_handler_id2); 828 EXPECT_EQ(content_handler_id, content_handler_id2);
830 } 829 }
831 830
832 TEST(ApplicationManagerTest2, DifferedContentHandlersGetDifferentIDs) { 831 TEST(ApplicationManagerTest2, DifferedContentHandlersGetDifferentIDs) {
833 base::MessageLoop loop; 832 base::MessageLoop loop;
834 const GURL content_handler_url("http://test.content.handler"); 833 const GURL content_handler_url("http://test.content.handler");
835 const GURL requestor_url("http://requestor.url"); 834 const GURL requestor_url("http://requestor.url");
836 TestContext test_context; 835 TestContext test_context;
837 TestApplicationFetcher* test_application_fetcher = new TestApplicationFetcher; 836 AMTestPackageManager* test_package_manager = new AMTestPackageManager;
838 test_application_fetcher->set_fetcher_url(GURL("test:test")); 837 test_package_manager->set_fetcher_url(GURL("test:test"));
839 test_application_fetcher->set_create_test_fetcher(true); 838 test_package_manager->set_create_test_fetcher(true);
840 ApplicationManager application_manager( 839 test_package_manager->RegisterContentHandler(kTestMimeType,
841 make_scoped_ptr(test_application_fetcher)); 840 content_handler_url);
841 ApplicationManager application_manager(make_scoped_ptr(test_package_manager));
842 application_manager.set_default_loader(nullptr); 842 application_manager.set_default_loader(nullptr);
843 application_manager.RegisterContentHandler(kTestMimeType,
844 content_handler_url);
845 843
846 TestApplicationLoader* content_handler_loader = new TestApplicationLoader; 844 TestApplicationLoader* content_handler_loader = new TestApplicationLoader;
847 content_handler_loader->set_create_content_handler(true); 845 content_handler_loader->set_create_content_handler(true);
848 content_handler_loader->set_context(&test_context); 846 content_handler_loader->set_context(&test_context);
849 application_manager.SetLoaderForURL( 847 application_manager.SetLoaderForURL(
850 scoped_ptr<ApplicationLoader>(content_handler_loader), 848 scoped_ptr<ApplicationLoader>(content_handler_loader),
851 content_handler_url); 849 content_handler_url);
852 850
853 uint32_t content_handler_id; 851 uint32_t content_handler_id;
854 { 852 {
855 base::RunLoop run_loop; 853 base::RunLoop run_loop;
856 scoped_ptr<ConnectToApplicationParams> params( 854 scoped_ptr<ConnectToApplicationParams> params(
857 new ConnectToApplicationParams); 855 new ConnectToApplicationParams);
858 params->set_originator_identity(Identity(requestor_url)); 856 params->set_originator_identity(Identity(requestor_url));
859 params->set_originator_filter(GetPermissiveCapabilityFilter()); 857 params->set_originator_filter(GetPermissiveCapabilityFilter());
860 params->SetURLInfo(GURL("test:test")); 858 params->SetURLInfo(GURL("test:test"));
861 params->set_filter(GetPermissiveCapabilityFilter()); 859 params->set_filter(GetPermissiveCapabilityFilter());
862 params->set_connect_callback([&content_handler_id, &run_loop](uint32_t t) { 860 params->set_connect_callback([&content_handler_id, &run_loop](uint32_t t) {
863 content_handler_id = t; 861 content_handler_id = t;
864 run_loop.Quit(); 862 run_loop.Quit();
865 }); 863 });
866 application_manager.ConnectToApplication(params.Pass()); 864 application_manager.ConnectToApplication(params.Pass());
867 run_loop.Run(); 865 run_loop.Run();
868 EXPECT_NE(Shell::kInvalidContentHandlerID, content_handler_id); 866 EXPECT_NE(Shell::kInvalidContentHandlerID, content_handler_id);
869 } 867 }
870 868
871 const std::string mime_type2("test/mime-type2"); 869 const std::string mime_type2("test/mime-type2");
872 const GURL content_handler_url2("http://test.content2.handler"); 870 const GURL content_handler_url2("http://test.content2.handler");
873 test_application_fetcher->set_fetcher_url(GURL("test2:test2")); 871 test_package_manager->set_fetcher_url(GURL("test2:test2"));
874 test_application_fetcher->set_mime_type(mime_type2); 872 test_package_manager->set_mime_type(mime_type2);
875 application_manager.RegisterContentHandler(mime_type2, content_handler_url2); 873 test_package_manager->RegisterContentHandler(mime_type2,
874 content_handler_url2);
876 875
877 TestApplicationLoader* content_handler_loader2 = new TestApplicationLoader; 876 TestApplicationLoader* content_handler_loader2 = new TestApplicationLoader;
878 content_handler_loader->set_create_content_handler(true); 877 content_handler_loader->set_create_content_handler(true);
879 content_handler_loader->set_context(&test_context); 878 content_handler_loader->set_context(&test_context);
880 application_manager.SetLoaderForURL( 879 application_manager.SetLoaderForURL(
881 scoped_ptr<ApplicationLoader>(content_handler_loader2), 880 scoped_ptr<ApplicationLoader>(content_handler_loader2),
882 content_handler_url2); 881 content_handler_url2);
883 882
884 uint32_t content_handler_id2; 883 uint32_t content_handler_id2;
885 { 884 {
(...skipping 27 matching lines...) Expand all
913 params->set_filter(GetPermissiveCapabilityFilter()); 912 params->set_filter(GetPermissiveCapabilityFilter());
914 params->set_connect_callback( 913 params->set_connect_callback(
915 [&content_handler_id](uint32_t t) { content_handler_id = t; }); 914 [&content_handler_id](uint32_t t) { content_handler_id = t; });
916 application_manager_->ConnectToApplication(params.Pass()); 915 application_manager_->ConnectToApplication(params.Pass());
917 EXPECT_EQ(0u, content_handler_id); 916 EXPECT_EQ(0u, content_handler_id);
918 } 917 }
919 918
920 } // namespace 919 } // namespace
921 } // namespace shell 920 } // namespace shell
922 } // namespace mojo 921 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/shell/application_manager.cc ('k') | mojo/shell/capability_filter_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698