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

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

Issue 1684783002: Rename ServiceProvider to InterfaceProvider. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: . Created 4 years, 10 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.h ('k') | mojo/shell/capability_filter_test.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 "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" 18 #include "mojo/shell/fetcher.h"
19 #include "mojo/shell/package_manager.h" 19 #include "mojo/shell/package_manager.h"
20 #include "mojo/shell/public/cpp/interface_factory.h" 20 #include "mojo/shell/public/cpp/interface_factory.h"
21 #include "mojo/shell/public/cpp/shell_client.h" 21 #include "mojo/shell/public/cpp/shell_client.h"
22 #include "mojo/shell/public/cpp/shell_connection.h" 22 #include "mojo/shell/public/cpp/shell_connection.h"
23 #include "mojo/shell/public/interfaces/service_provider.mojom.h" 23 #include "mojo/shell/public/interfaces/interface_provider.mojom.h"
24 #include "mojo/shell/test.mojom.h" 24 #include "mojo/shell/test.mojom.h"
25 #include "mojo/shell/test_package_manager.h" 25 #include "mojo/shell/test_package_manager.h"
26 #include "testing/gtest/include/gtest/gtest.h" 26 #include "testing/gtest/include/gtest/gtest.h"
27 27
28 namespace mojo { 28 namespace mojo {
29 namespace shell { 29 namespace shell {
30 namespace test { 30 namespace test {
31 31
32 const char kTestURLString[] = "test:testService"; 32 const char kTestURLString[] = "test:testService";
33 const char kTestAURLString[] = "test:TestA"; 33 const char kTestAURLString[] = "test:TestA";
(...skipping 361 matching lines...) Expand 10 before | Expand all | Expand 10 after
395 395
396 void SetUp() override { 396 void SetUp() override {
397 application_manager_.reset(new ApplicationManager( 397 application_manager_.reset(new ApplicationManager(
398 make_scoped_ptr(new TestPackageManager))); 398 make_scoped_ptr(new TestPackageManager)));
399 test_loader_ = new TestApplicationLoader; 399 test_loader_ = new TestApplicationLoader;
400 test_loader_->set_context(&context_); 400 test_loader_->set_context(&context_);
401 application_manager_->set_default_loader( 401 application_manager_->set_default_loader(
402 scoped_ptr<ApplicationLoader>(test_loader_)); 402 scoped_ptr<ApplicationLoader>(test_loader_));
403 403
404 TestServicePtr service_proxy; 404 TestServicePtr service_proxy;
405 ConnectToService(application_manager_.get(), GURL(kTestURLString), 405 ConnectToInterface(application_manager_.get(), GURL(kTestURLString),
406 &service_proxy); 406 &service_proxy);
407 test_client_.reset(new TestClient(std::move(service_proxy))); 407 test_client_.reset(new TestClient(std::move(service_proxy)));
408 } 408 }
409 409
410 void TearDown() override { 410 void TearDown() override {
411 test_client_.reset(); 411 test_client_.reset();
412 application_manager_.reset(); 412 application_manager_.reset();
413 } 413 }
414 414
415 void AddLoaderForURL(const GURL& url, const std::string& requestor_url) { 415 void AddLoaderForURL(const GURL& url, const std::string& requestor_url) {
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
472 TEST_F(ApplicationManagerTest, SetLoaders) { 472 TEST_F(ApplicationManagerTest, SetLoaders) {
473 TestApplicationLoader* default_loader = new TestApplicationLoader; 473 TestApplicationLoader* default_loader = new TestApplicationLoader;
474 TestApplicationLoader* url_loader = new TestApplicationLoader; 474 TestApplicationLoader* url_loader = new TestApplicationLoader;
475 application_manager_->set_default_loader( 475 application_manager_->set_default_loader(
476 scoped_ptr<ApplicationLoader>(default_loader)); 476 scoped_ptr<ApplicationLoader>(default_loader));
477 application_manager_->SetLoaderForURL( 477 application_manager_->SetLoaderForURL(
478 scoped_ptr<ApplicationLoader>(url_loader), GURL("test:test1")); 478 scoped_ptr<ApplicationLoader>(url_loader), GURL("test:test1"));
479 479
480 // test::test1 should go to url_loader. 480 // test::test1 should go to url_loader.
481 TestServicePtr test_service; 481 TestServicePtr test_service;
482 ConnectToService(application_manager_.get(), GURL("test:test1"), 482 ConnectToInterface(application_manager_.get(), GURL("test:test1"),
483 &test_service); 483 &test_service);
484 EXPECT_EQ(1, url_loader->num_loads()); 484 EXPECT_EQ(1, url_loader->num_loads());
485 EXPECT_EQ(0, default_loader->num_loads()); 485 EXPECT_EQ(0, default_loader->num_loads());
486 486
487 // http::test1 should go to default loader. 487 // http::test1 should go to default loader.
488 ConnectToService(application_manager_.get(), GURL("http:test1"), 488 ConnectToInterface(application_manager_.get(), GURL("http:test1"),
489 &test_service); 489 &test_service);
490 EXPECT_EQ(1, url_loader->num_loads()); 490 EXPECT_EQ(1, url_loader->num_loads());
491 EXPECT_EQ(1, default_loader->num_loads()); 491 EXPECT_EQ(1, default_loader->num_loads());
492 } 492 }
493 493
494 // Confirm that the url of a service is correctly passed to another service that 494 // Confirm that the url of a service is correctly passed to another service that
495 // it loads. 495 // it loads.
496 TEST_F(ApplicationManagerTest, ACallB) { 496 TEST_F(ApplicationManagerTest, ACallB) {
497 // Any url can load a. 497 // Any url can load a.
498 AddLoaderForURL(GURL(kTestAURLString), std::string()); 498 AddLoaderForURL(GURL(kTestAURLString), std::string());
499 499
500 // Only a can load b. 500 // Only a can load b.
501 AddLoaderForURL(GURL(kTestBURLString), kTestAURLString); 501 AddLoaderForURL(GURL(kTestBURLString), kTestAURLString);
502 502
503 TestAPtr a; 503 TestAPtr a;
504 ConnectToService(application_manager_.get(), GURL(kTestAURLString), &a); 504 ConnectToInterface(application_manager_.get(), GURL(kTestAURLString), &a);
505 a->CallB(); 505 a->CallB();
506 loop_.Run(); 506 loop_.Run();
507 EXPECT_EQ(1, tester_context_.num_b_calls()); 507 EXPECT_EQ(1, tester_context_.num_b_calls());
508 EXPECT_TRUE(tester_context_.a_called_quit()); 508 EXPECT_TRUE(tester_context_.a_called_quit());
509 } 509 }
510 510
511 // A calls B which calls C. 511 // A calls B which calls C.
512 TEST_F(ApplicationManagerTest, BCallC) { 512 TEST_F(ApplicationManagerTest, BCallC) {
513 // Any url can load a. 513 // Any url can load a.
514 AddLoaderForURL(GURL(kTestAURLString), std::string()); 514 AddLoaderForURL(GURL(kTestAURLString), std::string());
515 515
516 // Only a can load b. 516 // Only a can load b.
517 AddLoaderForURL(GURL(kTestBURLString), kTestAURLString); 517 AddLoaderForURL(GURL(kTestBURLString), kTestAURLString);
518 518
519 TestAPtr a; 519 TestAPtr a;
520 ConnectToService(application_manager_.get(), GURL(kTestAURLString), &a); 520 ConnectToInterface(application_manager_.get(), GURL(kTestAURLString), &a);
521 a->CallCFromB(); 521 a->CallCFromB();
522 loop_.Run(); 522 loop_.Run();
523 523
524 EXPECT_EQ(1, tester_context_.num_b_calls()); 524 EXPECT_EQ(1, tester_context_.num_b_calls());
525 EXPECT_EQ(1, tester_context_.num_c_calls()); 525 EXPECT_EQ(1, tester_context_.num_c_calls());
526 EXPECT_TRUE(tester_context_.a_called_quit()); 526 EXPECT_TRUE(tester_context_.a_called_quit());
527 } 527 }
528 528
529 // Confirm that a service impl will be deleted if the app that connected to 529 // Confirm that a service impl will be deleted if the app that connected to
530 // it goes away. 530 // it goes away.
531 TEST_F(ApplicationManagerTest, BDeleted) { 531 TEST_F(ApplicationManagerTest, BDeleted) {
532 AddLoaderForURL(GURL(kTestAURLString), std::string()); 532 AddLoaderForURL(GURL(kTestAURLString), std::string());
533 AddLoaderForURL(GURL(kTestBURLString), std::string()); 533 AddLoaderForURL(GURL(kTestBURLString), std::string());
534 534
535 TestAPtr a; 535 TestAPtr a;
536 ConnectToService(application_manager_.get(), GURL(kTestAURLString), &a); 536 ConnectToInterface(application_manager_.get(), GURL(kTestAURLString), &a);
537 537
538 a->CallB(); 538 a->CallB();
539 loop_.Run(); 539 loop_.Run();
540 540
541 // Kills the a app. 541 // Kills the a app.
542 application_manager_->SetLoaderForURL(scoped_ptr<ApplicationLoader>(), 542 application_manager_->SetLoaderForURL(scoped_ptr<ApplicationLoader>(),
543 GURL(kTestAURLString)); 543 GURL(kTestAURLString));
544 loop_.Run(); 544 loop_.Run();
545 545
546 EXPECT_EQ(1, tester_context_.num_b_deletes()); 546 EXPECT_EQ(1, tester_context_.num_b_deletes());
547 } 547 }
548 548
549 // Confirm that the url of a service is correctly passed to another service that 549 // Confirm that the url of a service is correctly passed to another service that
550 // it loads, and that it can be rejected. 550 // it loads, and that it can be rejected.
551 TEST_F(ApplicationManagerTest, ANoLoadB) { 551 TEST_F(ApplicationManagerTest, ANoLoadB) {
552 // Any url can load a. 552 // Any url can load a.
553 AddLoaderForURL(GURL(kTestAURLString), std::string()); 553 AddLoaderForURL(GURL(kTestAURLString), std::string());
554 554
555 // Only c can load b, so this will fail. 555 // Only c can load b, so this will fail.
556 AddLoaderForURL(GURL(kTestBURLString), "test:TestC"); 556 AddLoaderForURL(GURL(kTestBURLString), "test:TestC");
557 557
558 TestAPtr a; 558 TestAPtr a;
559 ConnectToService(application_manager_.get(), GURL(kTestAURLString), &a); 559 ConnectToInterface(application_manager_.get(), GURL(kTestAURLString), &a);
560 a->CallB(); 560 a->CallB();
561 loop_.Run(); 561 loop_.Run();
562 EXPECT_EQ(0, tester_context_.num_b_calls()); 562 EXPECT_EQ(0, tester_context_.num_b_calls());
563 563
564 EXPECT_FALSE(tester_context_.a_called_quit()); 564 EXPECT_FALSE(tester_context_.a_called_quit());
565 EXPECT_TRUE(tester_context_.tester_called_quit()); 565 EXPECT_TRUE(tester_context_.tester_called_quit());
566 } 566 }
567 567
568 TEST_F(ApplicationManagerTest, NoServiceNoLoad) { 568 TEST_F(ApplicationManagerTest, NoServiceNoLoad) {
569 AddLoaderForURL(GURL(kTestAURLString), std::string()); 569 AddLoaderForURL(GURL(kTestAURLString), std::string());
570 570
571 // There is no TestC service implementation registered with 571 // There is no TestC service implementation registered with
572 // ApplicationManager, so this cannot succeed (but also shouldn't crash). 572 // ApplicationManager, so this cannot succeed (but also shouldn't crash).
573 TestCPtr c; 573 TestCPtr c;
574 ConnectToService(application_manager_.get(), GURL(kTestAURLString), &c); 574 ConnectToInterface(application_manager_.get(), GURL(kTestAURLString), &c);
575 c.set_connection_error_handler( 575 c.set_connection_error_handler(
576 []() { base::MessageLoop::current()->QuitWhenIdle(); }); 576 []() { base::MessageLoop::current()->QuitWhenIdle(); });
577 577
578 loop_.Run(); 578 loop_.Run();
579 EXPECT_TRUE(c.encountered_error()); 579 EXPECT_TRUE(c.encountered_error());
580 } 580 }
581 581
582 TEST_F(ApplicationManagerTest, TestEndApplicationClosure) { 582 TEST_F(ApplicationManagerTest, TestEndApplicationClosure) {
583 ClosingApplicationLoader* loader = new ClosingApplicationLoader(); 583 ClosingApplicationLoader* loader = new ClosingApplicationLoader();
584 application_manager_->SetLoaderForURL( 584 application_manager_->SetLoaderForURL(
585 scoped_ptr<ApplicationLoader>(loader), GURL("test:test")); 585 scoped_ptr<ApplicationLoader>(loader), GURL("test:test"));
586 586
587 bool called = false; 587 bool called = false;
588 scoped_ptr<ConnectToApplicationParams> params(new ConnectToApplicationParams); 588 scoped_ptr<ConnectToApplicationParams> params(new ConnectToApplicationParams);
589 params->SetTargetURL(GURL("test:test")); 589 params->SetTargetURL(GURL("test:test"));
590 params->set_on_application_end( 590 params->set_on_application_end(
591 base::Bind(&QuitClosure, base::Unretained(&called))); 591 base::Bind(&QuitClosure, base::Unretained(&called)));
592 application_manager_->ConnectToApplication(std::move(params)); 592 application_manager_->ConnectToApplication(std::move(params));
593 loop_.Run(); 593 loop_.Run();
594 EXPECT_TRUE(called); 594 EXPECT_TRUE(called);
595 } 595 }
596 596
597 TEST_F(ApplicationManagerTest, SameIdentityShouldNotCauseDuplicateLoad) { 597 TEST_F(ApplicationManagerTest, SameIdentityShouldNotCauseDuplicateLoad) {
598 // 1 because ApplicationManagerTest connects once at startup. 598 // 1 because ApplicationManagerTest connects once at startup.
599 EXPECT_EQ(1, test_loader_->num_loads()); 599 EXPECT_EQ(1, test_loader_->num_loads());
600 600
601 TestServicePtr test_service; 601 TestServicePtr test_service;
602 ConnectToService(application_manager_.get(), 602 ConnectToInterface(application_manager_.get(),
603 GURL("http://www.example.org/abc?def"), &test_service); 603 GURL("http://www.example.org/abc?def"), &test_service);
604 EXPECT_EQ(2, test_loader_->num_loads()); 604 EXPECT_EQ(2, test_loader_->num_loads());
605 605
606 // Exactly the same URL as above. 606 // Exactly the same URL as above.
607 ConnectToService(application_manager_.get(), 607 ConnectToInterface(application_manager_.get(),
608 GURL("http://www.example.org/abc?def"), &test_service); 608 GURL("http://www.example.org/abc?def"), &test_service);
609 EXPECT_EQ(2, test_loader_->num_loads()); 609 EXPECT_EQ(2, test_loader_->num_loads());
610 610
611 // The same identity as the one above because only the query string is 611 // The same identity as the one above because only the query string is
612 // different. 612 // different.
613 ConnectToService(application_manager_.get(), 613 ConnectToInterface(application_manager_.get(),
614 GURL("http://www.example.org/abc"), &test_service); 614 GURL("http://www.example.org/abc"), &test_service);
615 EXPECT_EQ(2, test_loader_->num_loads()); 615 EXPECT_EQ(2, test_loader_->num_loads());
616 616
617 // A different identity because the path is different. 617 // A different identity because the path is different.
618 ConnectToService(application_manager_.get(), 618 ConnectToInterface(application_manager_.get(),
619 GURL("http://www.example.org/another_path"), &test_service); 619 GURL("http://www.example.org/another_path"), &test_service) ;
620 EXPECT_EQ(3, test_loader_->num_loads()); 620 EXPECT_EQ(3, test_loader_->num_loads());
621 621
622 // A different identity because the domain is different. 622 // A different identity because the domain is different.
623 ConnectToService(application_manager_.get(), 623 ConnectToInterface(application_manager_.get(),
624 GURL("http://www.another_domain.org/abc"), &test_service); 624 GURL("http://www.another_domain.org/abc"), &test_service);
625 EXPECT_EQ(4, test_loader_->num_loads()); 625 EXPECT_EQ(4, test_loader_->num_loads());
626 } 626 }
627 627
628 } // namespace test 628 } // namespace test
629 } // namespace shell 629 } // namespace shell
630 } // namespace mojo 630 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/shell/application_manager.h ('k') | mojo/shell/capability_filter_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698