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

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

Issue 1082513002: Revert of Simplify mojo_shell since it's now only used for Mandoline. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Sync and rebase. Created 5 years, 8 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/application_manager.cc ('k') | mojo/shell/command_line_util.h » ('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 "mojo/public/cpp/application/application_connection.h" 10 #include "mojo/public/cpp/application/application_connection.h"
(...skipping 401 matching lines...) Expand 10 before | Expand all | Expand 10 after
412 replacements.SetScheme("file", url::Component(0, 4)); 412 replacements.SetScheme("file", url::Component(0, 4));
413 mapped_url = mapped_url.ReplaceComponents(replacements); 413 mapped_url = mapped_url.ReplaceComponents(replacements);
414 } 414 }
415 return mapped_url; 415 return mapped_url;
416 } 416 }
417 417
418 private: 418 private:
419 std::map<GURL, GURL> mappings_; 419 std::map<GURL, GURL> mappings_;
420 }; 420 };
421 421
422 class TestExternal : public ApplicationDelegate {
423 public:
424 TestExternal() : configure_incoming_connection_called_(false) {}
425
426 void Initialize(ApplicationImpl* app) override {
427 initialize_args_ = app->args();
428 base::MessageLoop::current()->Quit();
429 }
430
431 bool ConfigureIncomingConnection(ApplicationConnection* connection) override {
432 configure_incoming_connection_called_ = true;
433 base::MessageLoop::current()->Quit();
434 return true;
435 }
436
437 const std::vector<std::string>& initialize_args() const {
438 return initialize_args_;
439 }
440
441 bool configure_incoming_connection_called() const {
442 return configure_incoming_connection_called_;
443 }
444
445 private:
446 std::vector<std::string> initialize_args_;
447 bool configure_incoming_connection_called_;
448 };
449
422 class ApplicationManagerTest : public testing::Test { 450 class ApplicationManagerTest : public testing::Test {
423 public: 451 public:
424 ApplicationManagerTest() : tester_context_(&loop_) {} 452 ApplicationManagerTest() : tester_context_(&loop_) {}
425 453
426 ~ApplicationManagerTest() override {} 454 ~ApplicationManagerTest() override {}
427 455
428 void SetUp() override { 456 void SetUp() override {
429 application_manager_.reset(new ApplicationManager(&test_delegate_)); 457 application_manager_.reset(new ApplicationManager(&test_delegate_));
430 test_loader_ = new TestApplicationLoader; 458 test_loader_ = new TestApplicationLoader;
431 test_loader_->set_context(&context_); 459 test_loader_->set_context(&context_);
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
480 am.SetLoaderForURL(scoped_ptr<ApplicationLoader>(loader), test_url); 508 am.SetLoaderForURL(scoped_ptr<ApplicationLoader>(loader), test_url);
481 TestServicePtr test_service; 509 TestServicePtr test_service;
482 am.ConnectToService(test_url, &test_service); 510 am.ConnectToService(test_url, &test_service);
483 TestClient test_client(test_service.Pass()); 511 TestClient test_client(test_service.Pass());
484 test_client.Test("test"); 512 test_client.Test("test");
485 loop_.Run(); 513 loop_.Run();
486 std::vector<std::string> app_args = loader->GetArgs(); 514 std::vector<std::string> app_args = loader->GetArgs();
487 EXPECT_EQ(0U, app_args.size()); 515 EXPECT_EQ(0U, app_args.size());
488 } 516 }
489 517
518 // Confirm that arguments are sent to an application.
519 TEST_F(ApplicationManagerTest, Args) {
520 ApplicationManager am(&test_delegate_);
521 GURL test_url("test:test");
522 std::vector<std::string> args;
523 args.push_back("test_arg1");
524 args.push_back("test_arg2");
525 am.SetArgsForURL(args, test_url);
526 TestApplicationLoader* loader = new TestApplicationLoader;
527 loader->set_context(&context_);
528 am.SetLoaderForURL(scoped_ptr<ApplicationLoader>(loader), test_url);
529 TestServicePtr test_service;
530 am.ConnectToService(test_url, &test_service);
531 TestClient test_client(test_service.Pass());
532 test_client.Test("test");
533 loop_.Run();
534 std::vector<std::string> app_args = loader->GetArgs();
535 ASSERT_EQ(args.size(), app_args.size());
536 EXPECT_EQ(args[0], app_args[0]);
537 EXPECT_EQ(args[1], app_args[1]);
538 }
539
540 // Confirm that arguments are aggregated through mappings.
541 TEST_F(ApplicationManagerTest, ArgsAndMapping) {
542 ApplicationManager am(&test_delegate_);
543 GURL test_url("test:test");
544 GURL test_url2("test:test2");
545 test_delegate_.AddMapping(test_url, test_url2);
546 std::vector<std::string> args;
547 args.push_back("test_arg1");
548 args.push_back("test_arg2");
549 am.SetArgsForURL(args, test_url);
550 std::vector<std::string> args2;
551 args2.push_back("test_arg3");
552 args2.push_back("test_arg4");
553 am.SetArgsForURL(args2, test_url2);
554 TestApplicationLoader* loader = new TestApplicationLoader;
555 loader->set_context(&context_);
556 am.SetLoaderForURL(scoped_ptr<ApplicationLoader>(loader), test_url2);
557 {
558 // Connext to the mapped url
559 TestServicePtr test_service;
560 am.ConnectToService(test_url, &test_service);
561 TestClient test_client(test_service.Pass());
562 test_client.Test("test");
563 loop_.Run();
564 std::vector<std::string> app_args = loader->GetArgs();
565 ASSERT_EQ(args.size() + args2.size(), app_args.size());
566 EXPECT_EQ(args[0], app_args[0]);
567 EXPECT_EQ(args[1], app_args[1]);
568 EXPECT_EQ(args2[0], app_args[2]);
569 EXPECT_EQ(args2[1], app_args[3]);
570 }
571 {
572 // Connext to the target url
573 TestServicePtr test_service;
574 am.ConnectToService(test_url2, &test_service);
575 TestClient test_client(test_service.Pass());
576 test_client.Test("test");
577 loop_.Run();
578 std::vector<std::string> app_args = loader->GetArgs();
579 ASSERT_EQ(args.size() + args2.size(), app_args.size());
580 EXPECT_EQ(args[0], app_args[0]);
581 EXPECT_EQ(args[1], app_args[1]);
582 EXPECT_EQ(args2[0], app_args[2]);
583 EXPECT_EQ(args2[1], app_args[3]);
584 }
585 }
586
490 TEST_F(ApplicationManagerTest, ClientError) { 587 TEST_F(ApplicationManagerTest, ClientError) {
491 test_client_->Test("test"); 588 test_client_->Test("test");
492 EXPECT_TRUE(HasFactoryForTestURL()); 589 EXPECT_TRUE(HasFactoryForTestURL());
493 loop_.Run(); 590 loop_.Run();
494 EXPECT_EQ(1, context_.num_impls); 591 EXPECT_EQ(1, context_.num_impls);
495 test_client_.reset(); 592 test_client_.reset();
496 loop_.Run(); 593 loop_.Run();
497 EXPECT_EQ(0, context_.num_impls); 594 EXPECT_EQ(0, context_.num_impls);
498 EXPECT_TRUE(HasFactoryForTestURL()); 595 EXPECT_TRUE(HasFactoryForTestURL());
499 } 596 }
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after
669 application_manager_->SetLoaderForURL(make_scoped_ptr(custom_loader), 766 application_manager_->SetLoaderForURL(make_scoped_ptr(custom_loader),
670 GURL("mojo:foo")); 767 GURL("mojo:foo"));
671 test_delegate_.AddMapping(GURL("mojo:foo2"), GURL("mojo:foo")); 768 test_delegate_.AddMapping(GURL("mojo:foo2"), GURL("mojo:foo"));
672 769
673 TestServicePtr test_service; 770 TestServicePtr test_service;
674 application_manager_->ConnectToService(GURL("mojo:foo2"), &test_service); 771 application_manager_->ConnectToService(GURL("mojo:foo2"), &test_service);
675 EXPECT_EQ(1, custom_loader->num_loads()); 772 EXPECT_EQ(1, custom_loader->num_loads());
676 custom_loader->set_context(nullptr); 773 custom_loader->set_context(nullptr);
677 } 774 }
678 775
776 TEST_F(ApplicationManagerTest, ExternalApp) {
777 ApplicationPtr application;
778 TestExternal external;
779 std::vector<std::string> args;
780 args.push_back("test");
781 ApplicationImpl app(&external, GetProxy(&application));
782 application_manager_->RegisterExternalApplication(GURL("mojo:test"), args,
783 application.Pass());
784 loop_.Run();
785 EXPECT_EQ(args, external.initialize_args());
786 application_manager_->ConnectToServiceByName(GURL("mojo:test"),
787 std::string());
788 loop_.Run();
789 EXPECT_TRUE(external.configure_incoming_connection_called());
790 };
791
679 TEST_F(ApplicationManagerTest, TestQueryWithLoaders) { 792 TEST_F(ApplicationManagerTest, TestQueryWithLoaders) {
680 TestApplicationLoader* url_loader = new TestApplicationLoader; 793 TestApplicationLoader* url_loader = new TestApplicationLoader;
681 TestApplicationLoader* scheme_loader = new TestApplicationLoader; 794 TestApplicationLoader* scheme_loader = new TestApplicationLoader;
682 application_manager_->SetLoaderForURL( 795 application_manager_->SetLoaderForURL(
683 scoped_ptr<ApplicationLoader>(url_loader), GURL("test:test1")); 796 scoped_ptr<ApplicationLoader>(url_loader), GURL("test:test1"));
684 application_manager_->SetLoaderForScheme( 797 application_manager_->SetLoaderForScheme(
685 scoped_ptr<ApplicationLoader>(scheme_loader), "test"); 798 scoped_ptr<ApplicationLoader>(scheme_loader), "test");
686 799
687 // test::test1 should go to url_loader. 800 // test::test1 should go to url_loader.
688 TestServicePtr test_service; 801 TestServicePtr test_service;
(...skipping 18 matching lines...) Expand all
707 application_manager_->ConnectToApplication( 820 application_manager_->ConnectToApplication(
708 GURL("test:test"), GURL(), nullptr, nullptr, 821 GURL("test:test"), GURL(), nullptr, nullptr,
709 base::Bind(&QuitClosure, base::Unretained(&called))); 822 base::Bind(&QuitClosure, base::Unretained(&called)));
710 loop_.Run(); 823 loop_.Run();
711 EXPECT_TRUE(called); 824 EXPECT_TRUE(called);
712 } 825 }
713 826
714 } // namespace 827 } // namespace
715 } // namespace shell 828 } // namespace shell
716 } // namespace mojo 829 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/shell/application_manager/application_manager.cc ('k') | mojo/shell/command_line_util.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698