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 <utility> | 5 #include <utility> |
6 | 6 |
7 #include "base/at_exit.h" | 7 #include "base/at_exit.h" |
8 #include "base/bind.h" | 8 #include "base/bind.h" |
9 #include "base/macros.h" | 9 #include "base/macros.h" |
10 #include "base/memory/scoped_vector.h" | 10 #include "base/memory/scoped_vector.h" |
11 #include "base/message_loop/message_loop.h" | 11 #include "base/message_loop/message_loop.h" |
12 #include "base/run_loop.h" | 12 #include "base/run_loop.h" |
13 #include "mojo/public/cpp/bindings/strong_binding.h" | 13 #include "mojo/public/cpp/bindings/strong_binding.h" |
14 #include "mojo/services/catalog/owner.h" | 14 #include "mojo/services/catalog/factory.h" |
15 #include "mojo/services/catalog/store.h" | 15 #include "mojo/services/catalog/store.h" |
16 #include "mojo/shell/connect_util.h" | 16 #include "mojo/shell/connect_util.h" |
17 #include "mojo/shell/loader.h" | 17 #include "mojo/shell/loader.h" |
18 #include "mojo/shell/public/cpp/connector.h" | 18 #include "mojo/shell/public/cpp/connector.h" |
19 #include "mojo/shell/public/cpp/interface_factory.h" | 19 #include "mojo/shell/public/cpp/interface_factory.h" |
20 #include "mojo/shell/public/cpp/shell_client.h" | 20 #include "mojo/shell/public/cpp/shell_client.h" |
21 #include "mojo/shell/public/cpp/shell_connection.h" | 21 #include "mojo/shell/public/cpp/shell_connection.h" |
22 #include "mojo/shell/public/interfaces/interface_provider.mojom.h" | 22 #include "mojo/shell/public/interfaces/interface_provider.mojom.h" |
23 #include "mojo/shell/shell.h" | 23 #include "mojo/shell/shell.h" |
24 #include "mojo/shell/tests/test.mojom.h" | 24 #include "mojo/shell/tests/test.mojom.h" |
(...skipping 370 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
395 loop->Quit(); | 395 loop->Quit(); |
396 } | 396 } |
397 | 397 |
398 class LoaderTest : public testing::Test { | 398 class LoaderTest : public testing::Test { |
399 public: | 399 public: |
400 LoaderTest() : tester_context_(&loop_) {} | 400 LoaderTest() : tester_context_(&loop_) {} |
401 ~LoaderTest() override {} | 401 ~LoaderTest() override {} |
402 | 402 |
403 void SetUp() override { | 403 void SetUp() override { |
404 blocking_pool_ = new base::SequencedWorkerPool(3, "blocking_pool"); | 404 blocking_pool_ = new base::SequencedWorkerPool(3, "blocking_pool"); |
405 catalog_.reset(new catalog::Owner(blocking_pool_.get(), nullptr)); | 405 catalog_.reset(new catalog::Factory(blocking_pool_.get(), nullptr)); |
406 shell_.reset(new Shell(nullptr, catalog_->TakeShellClient())); | 406 shell_.reset(new Shell(nullptr, catalog_->TakeShellClient())); |
407 test_loader_ = new TestLoader(&context_); | 407 test_loader_ = new TestLoader(&context_); |
408 shell_->set_default_loader(scoped_ptr<Loader>(test_loader_)); | 408 shell_->set_default_loader(scoped_ptr<Loader>(test_loader_)); |
409 | 409 |
410 TestServicePtr service_proxy; | 410 TestServicePtr service_proxy; |
411 ConnectToInterface(kTestURLString, &service_proxy); | 411 ConnectToInterface(kTestURLString, &service_proxy); |
412 test_client_.reset(new TestClient(std::move(service_proxy))); | 412 test_client_.reset(new TestClient(std::move(service_proxy))); |
413 } | 413 } |
414 | 414 |
415 void TearDown() override { | 415 void TearDown() override { |
(...skipping 30 matching lines...) Expand all Loading... |
446 | 446 |
447 mojo::GetInterface(remote_interfaces.get(), ptr); | 447 mojo::GetInterface(remote_interfaces.get(), ptr); |
448 } | 448 } |
449 | 449 |
450 base::ShadowingAtExitManager at_exit_; | 450 base::ShadowingAtExitManager at_exit_; |
451 TestLoader* test_loader_; | 451 TestLoader* test_loader_; |
452 TesterContext tester_context_; | 452 TesterContext tester_context_; |
453 TestContext context_; | 453 TestContext context_; |
454 base::MessageLoop loop_; | 454 base::MessageLoop loop_; |
455 scoped_ptr<TestClient> test_client_; | 455 scoped_ptr<TestClient> test_client_; |
456 scoped_ptr<catalog::Owner> catalog_; | 456 scoped_ptr<catalog::Factory> catalog_; |
457 scoped_refptr<base::SequencedWorkerPool> blocking_pool_; | 457 scoped_refptr<base::SequencedWorkerPool> blocking_pool_; |
458 scoped_ptr<Shell> shell_; | 458 scoped_ptr<Shell> shell_; |
459 DISALLOW_COPY_AND_ASSIGN(LoaderTest); | 459 DISALLOW_COPY_AND_ASSIGN(LoaderTest); |
460 }; | 460 }; |
461 | 461 |
462 TEST_F(LoaderTest, Basic) { | 462 TEST_F(LoaderTest, Basic) { |
463 test_client_->Test("test"); | 463 test_client_->Test("test"); |
464 loop_.Run(); | 464 loop_.Run(); |
465 EXPECT_EQ(std::string("test"), context_.last_test_string); | 465 EXPECT_EQ(std::string("test"), context_.last_test_string); |
466 } | 466 } |
467 | 467 |
468 TEST_F(LoaderTest, ClientError) { | 468 TEST_F(LoaderTest, ClientError) { |
469 test_client_->Test("test"); | 469 test_client_->Test("test"); |
470 EXPECT_TRUE(HasRunningInstanceForName(kTestURLString)); | 470 EXPECT_TRUE(HasRunningInstanceForName(kTestURLString)); |
471 loop_.Run(); | 471 loop_.Run(); |
472 EXPECT_EQ(1, context_.num_impls); | 472 EXPECT_EQ(1, context_.num_impls); |
473 test_client_.reset(); | 473 test_client_.reset(); |
474 loop_.Run(); | 474 loop_.Run(); |
475 EXPECT_EQ(0, context_.num_impls); | 475 EXPECT_EQ(0, context_.num_impls); |
476 EXPECT_TRUE(HasRunningInstanceForName(kTestURLString)); | 476 EXPECT_TRUE(HasRunningInstanceForName(kTestURLString)); |
477 } | 477 } |
478 | 478 |
479 TEST_F(LoaderTest, Deletes) { | 479 TEST_F(LoaderTest, Deletes) { |
480 { | 480 { |
481 catalog::Owner catalog(blocking_pool_.get(), nullptr); | 481 catalog::Factory catalog(blocking_pool_.get(), nullptr); |
482 Shell shell(nullptr, catalog.TakeShellClient()); | 482 Shell shell(nullptr, catalog.TakeShellClient()); |
483 TestLoader* default_loader = new TestLoader(&context_); | 483 TestLoader* default_loader = new TestLoader(&context_); |
484 TestLoader* name_loader1 = new TestLoader(&context_); | 484 TestLoader* name_loader1 = new TestLoader(&context_); |
485 TestLoader* name_loader2 = new TestLoader(&context_); | 485 TestLoader* name_loader2 = new TestLoader(&context_); |
486 shell.set_default_loader(scoped_ptr<Loader>(default_loader)); | 486 shell.set_default_loader(scoped_ptr<Loader>(default_loader)); |
487 shell.SetLoaderForName(scoped_ptr<Loader>(name_loader1), "test:test1"); | 487 shell.SetLoaderForName(scoped_ptr<Loader>(name_loader1), "test:test1"); |
488 shell.SetLoaderForName(scoped_ptr<Loader>(name_loader2), "test:test1"); | 488 shell.SetLoaderForName(scoped_ptr<Loader>(name_loader2), "test:test1"); |
489 } | 489 } |
490 EXPECT_EQ(3, context_.num_loader_deletes); | 490 EXPECT_EQ(3, context_.num_loader_deletes); |
491 } | 491 } |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
551 EXPECT_EQ(2, test_loader_->num_loads()); | 551 EXPECT_EQ(2, test_loader_->num_loads()); |
552 | 552 |
553 // A different identity because the domain is different. | 553 // A different identity because the domain is different. |
554 ConnectToInterface("test:bar", &test_service); | 554 ConnectToInterface("test:bar", &test_service); |
555 EXPECT_EQ(3, test_loader_->num_loads()); | 555 EXPECT_EQ(3, test_loader_->num_loads()); |
556 } | 556 } |
557 | 557 |
558 } // namespace test | 558 } // namespace test |
559 } // namespace shell | 559 } // namespace shell |
560 } // namespace mojo | 560 } // namespace mojo |
OLD | NEW |