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

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

Issue 788243007: Moves BackgroundShellApplicationLoader to shell/android (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: another printf Created 6 years 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 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/message_loop/message_loop.h" 8 #include "base/message_loop/message_loop.h"
9 #include "mojo/application_manager/application_loader.h" 9 #include "mojo/application_manager/application_loader.h"
10 #include "mojo/application_manager/application_manager.h" 10 #include "mojo/application_manager/application_manager.h"
11 #include "mojo/application_manager/background_shell_application_loader.h"
12 #include "mojo/application_manager/test.mojom.h" 11 #include "mojo/application_manager/test.mojom.h"
13 #include "mojo/public/cpp/application/application_connection.h" 12 #include "mojo/public/cpp/application/application_connection.h"
14 #include "mojo/public/cpp/application/application_delegate.h" 13 #include "mojo/public/cpp/application/application_delegate.h"
15 #include "mojo/public/cpp/application/application_impl.h" 14 #include "mojo/public/cpp/application/application_impl.h"
16 #include "mojo/public/cpp/application/interface_factory.h" 15 #include "mojo/public/cpp/application/interface_factory.h"
17 #include "mojo/public/interfaces/application/service_provider.mojom.h" 16 #include "mojo/public/interfaces/application/service_provider.mojom.h"
18 #include "testing/gtest/include/gtest/gtest.h" 17 #include "testing/gtest/include/gtest/gtest.h"
19 18
20 namespace mojo { 19 namespace mojo {
21 namespace { 20 namespace {
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
77 service_.set_client(this); 76 service_.set_client(this);
78 } 77 }
79 78
80 ~TestClientImpl() override { service_.reset(); } 79 ~TestClientImpl() override { service_.reset(); }
81 80
82 void AckTest() override { 81 void AckTest() override {
83 if (quit_after_ack_) 82 if (quit_after_ack_)
84 base::MessageLoop::current()->Quit(); 83 base::MessageLoop::current()->Quit();
85 } 84 }
86 85
87 void Test(std::string test_string) { 86 void Test(const std::string& test_string) {
88 quit_after_ack_ = true; 87 quit_after_ack_ = true;
89 service_->Test(test_string); 88 service_->Test(test_string);
90 } 89 }
91 90
92 private: 91 private:
93 TestServicePtr service_; 92 TestServicePtr service_;
94 bool quit_after_ack_; 93 bool quit_after_ack_;
95 DISALLOW_COPY_AND_ASSIGN(TestClientImpl); 94 DISALLOW_COPY_AND_ASSIGN(TestClientImpl);
96 }; 95 };
97 96
(...skipping 345 matching lines...) Expand 10 before | Expand all | Expand 10 after
443 application_manager_->ConnectToService(GURL(kTestURLString), 442 application_manager_->ConnectToService(GURL(kTestURLString),
444 &service_proxy); 443 &service_proxy);
445 test_client_.reset(new TestClientImpl(service_proxy.Pass())); 444 test_client_.reset(new TestClientImpl(service_proxy.Pass()));
446 } 445 }
447 446
448 void TearDown() override { 447 void TearDown() override {
449 test_client_.reset(NULL); 448 test_client_.reset(NULL);
450 application_manager_.reset(NULL); 449 application_manager_.reset(NULL);
451 } 450 }
452 451
453 scoped_ptr<BackgroundShellApplicationLoader> MakeLoader(
454 const std::string& requestor_url) {
455 scoped_ptr<ApplicationLoader> real_loader(
456 new Tester(&tester_context_, requestor_url));
457 scoped_ptr<BackgroundShellApplicationLoader> loader(
458 new BackgroundShellApplicationLoader(real_loader.Pass(),
459 std::string(),
460 base::MessageLoop::TYPE_DEFAULT));
461 return loader.Pass();
462 }
463
464 void AddLoaderForURL(const GURL& url, const std::string& requestor_url) { 452 void AddLoaderForURL(const GURL& url, const std::string& requestor_url) {
465 application_manager_->SetLoaderForURL(MakeLoader(requestor_url), url); 453 application_manager_->SetLoaderForURL(
454 make_scoped_ptr(new Tester(&tester_context_, requestor_url)), url);
466 } 455 }
467 456
468 bool HasFactoryForTestURL() { 457 bool HasFactoryForTestURL() {
469 ApplicationManager::TestAPI manager_test_api(application_manager_.get()); 458 ApplicationManager::TestAPI manager_test_api(application_manager_.get());
470 return manager_test_api.HasFactoryForURL(GURL(kTestURLString)); 459 return manager_test_api.HasFactoryForURL(GURL(kTestURLString));
471 } 460 }
472 461
473 protected: 462 protected:
474 base::ShadowingAtExitManager at_exit_; 463 base::ShadowingAtExitManager at_exit_;
475 TestDelegate test_delegate_; 464 TestDelegate test_delegate_;
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after
623 TestAPtr a; 612 TestAPtr a;
624 application_manager_->ConnectToService(GURL(kTestAURLString), &a); 613 application_manager_->ConnectToService(GURL(kTestAURLString), &a);
625 a->CallCFromB(); 614 a->CallCFromB();
626 loop_.Run(); 615 loop_.Run();
627 616
628 EXPECT_EQ(1, tester_context_.num_b_calls()); 617 EXPECT_EQ(1, tester_context_.num_b_calls());
629 EXPECT_EQ(1, tester_context_.num_c_calls()); 618 EXPECT_EQ(1, tester_context_.num_c_calls());
630 EXPECT_TRUE(tester_context_.a_called_quit()); 619 EXPECT_TRUE(tester_context_.a_called_quit());
631 } 620 }
632 621
633 // Confirm that a service impl will be deleted if the app that connected to
634 // it goes away.
635 TEST_F(ApplicationManagerTest, BDeleted) {
sky 2014/12/16 19:22:19 Contrary to the description this test was exercisi
qsr 2014/12/17 10:34:34 Can you still make this work by having Tester use
636 AddLoaderForURL(GURL(kTestAURLString), std::string());
637 AddLoaderForURL(GURL(kTestBURLString), std::string());
638
639 TestAPtr a;
640 application_manager_->ConnectToService(GURL(kTestAURLString), &a);
641
642 a->CallB();
643 loop_.Run();
644
645 // Kills the a app.
646 application_manager_->SetLoaderForURL(scoped_ptr<ApplicationLoader>(),
647 GURL(kTestAURLString));
648 loop_.Run();
649
650 EXPECT_EQ(1, tester_context_.num_b_deletes());
651 }
652
653 // Confirm that the url of a service is correctly passed to another service that 622 // Confirm that the url of a service is correctly passed to another service that
654 // it loads, and that it can be rejected. 623 // it loads, and that it can be rejected.
655 TEST_F(ApplicationManagerTest, ANoLoadB) { 624 TEST_F(ApplicationManagerTest, ANoLoadB) {
656 // Any url can load a. 625 // Any url can load a.
657 AddLoaderForURL(GURL(kTestAURLString), std::string()); 626 AddLoaderForURL(GURL(kTestAURLString), std::string());
658 627
659 // Only c can load b, so this will fail. 628 // Only c can load b, so this will fail.
660 AddLoaderForURL(GURL(kTestBURLString), "test:TestC"); 629 AddLoaderForURL(GURL(kTestBURLString), "test:TestC");
661 630
662 TestAPtr a; 631 TestAPtr a;
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
711 TestServicePtr test_service2; 680 TestServicePtr test_service2;
712 application_manager_->ConnectToService(GURL("foo:foo2"), &test_service2); 681 application_manager_->ConnectToService(GURL("foo:foo2"), &test_service2);
713 EXPECT_EQ(2, test_loader_->num_loads()); 682 EXPECT_EQ(2, test_loader_->num_loads());
714 683
715 TestServicePtr test_service3; 684 TestServicePtr test_service3;
716 application_manager_->ConnectToService(GURL("bar:bar"), &test_service2); 685 application_manager_->ConnectToService(GURL("bar:bar"), &test_service2);
717 EXPECT_EQ(3, test_loader_->num_loads()); 686 EXPECT_EQ(3, test_loader_->num_loads());
718 } 687 }
719 688
720 } // namespace mojo 689 } // namespace mojo
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698