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 "base/files/scoped_temp_dir.h" | 5 #include "base/files/scoped_temp_dir.h" |
6 #include "base/path_service.h" | 6 #include "base/path_service.h" |
| 7 #include "mojo/package_manager/package_manager_impl.h" |
7 #include "mojo/runner/context.h" | 8 #include "mojo/runner/context.h" |
8 #include "mojo/shell/application_manager.h" | 9 #include "mojo/shell/application_manager.h" |
9 #include "mojo/util/filename_util.h" | 10 #include "mojo/util/filename_util.h" |
10 #include "testing/gtest/include/gtest/gtest.h" | 11 #include "testing/gtest/include/gtest/gtest.h" |
11 | 12 |
12 namespace mojo { | 13 namespace mojo { |
13 namespace runner { | 14 namespace runner { |
14 namespace { | 15 namespace { |
15 | 16 |
16 struct TestState { | 17 struct TestState { |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
53 return scoped_ptr<shell::NativeRunner>(new TestNativeRunner(state_)); | 54 return scoped_ptr<shell::NativeRunner>(new TestNativeRunner(state_)); |
54 } | 55 } |
55 | 56 |
56 private: | 57 private: |
57 TestState* state_; | 58 TestState* state_; |
58 }; | 59 }; |
59 | 60 |
60 class NativeApplicationLoaderTest : public testing::Test { | 61 class NativeApplicationLoaderTest : public testing::Test { |
61 public: | 62 public: |
62 NativeApplicationLoaderTest() { | 63 NativeApplicationLoaderTest() { |
63 base::FilePath shell_dir; | |
64 PathService::Get(base::DIR_MODULE, &shell_dir); | |
65 context_.reset(new Context(shell_dir)); | |
66 loop_.reset(new base::MessageLoop); | 64 loop_.reset(new base::MessageLoop); |
67 } | 65 } |
68 ~NativeApplicationLoaderTest() override { | 66 ~NativeApplicationLoaderTest() override { |
69 loop_.reset(); | 67 loop_.reset(); |
70 context_.reset(); | |
71 } | 68 } |
72 void SetUp() override { | 69 void SetUp() override { |
73 context_->Init(); | 70 base::FilePath shell_dir; |
| 71 PathService::Get(base::DIR_MODULE, &shell_dir); |
| 72 scoped_ptr<package_manager::PackageManagerImpl> package_manager( |
| 73 new package_manager::PackageManagerImpl(shell_dir, nullptr)); |
74 scoped_ptr<shell::NativeRunnerFactory> factory( | 74 scoped_ptr<shell::NativeRunnerFactory> factory( |
75 new TestNativeRunnerFactory(&state_)); | 75 new TestNativeRunnerFactory(&state_)); |
76 context_->application_manager()->set_native_runner_factory(factory.Pass()); | 76 application_manager_.reset(new shell::ApplicationManager( |
77 context_->application_manager()->set_blocking_pool( | 77 package_manager.Pass(), factory.Pass(), nullptr)); |
78 context_->task_runners()->blocking_pool()); | |
79 } | 78 } |
80 void TearDown() override { context_->Shutdown(); } | 79 void TearDown() override { application_manager_.reset(); } |
81 | 80 |
82 protected: | 81 protected: |
83 scoped_ptr<base::MessageLoop> loop_; | 82 scoped_ptr<base::MessageLoop> loop_; |
84 scoped_ptr<Context> context_; | 83 scoped_ptr<shell::ApplicationManager> application_manager_; |
85 TestState state_; | 84 TestState state_; |
86 }; | 85 }; |
87 | 86 |
88 TEST_F(NativeApplicationLoaderTest, DoesNotExist) { | 87 TEST_F(NativeApplicationLoaderTest, DoesNotExist) { |
89 base::ScopedTempDir temp_dir; | 88 base::ScopedTempDir temp_dir; |
90 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); | 89 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); |
91 base::FilePath nonexistent_file(FILE_PATH_LITERAL("nonexistent.txt")); | 90 base::FilePath nonexistent_file(FILE_PATH_LITERAL("nonexistent.txt")); |
92 GURL url(util::FilePathToFileURL(temp_dir.path().Append(nonexistent_file))); | 91 GURL url(util::FilePathToFileURL(temp_dir.path().Append(nonexistent_file))); |
93 InterfaceRequest<ServiceProvider> services; | |
94 ServiceProviderPtr service_provider; | |
95 | 92 |
96 scoped_ptr<shell::ConnectToApplicationParams> params( | 93 scoped_ptr<shell::ConnectToApplicationParams> params( |
97 new shell::ConnectToApplicationParams); | 94 new shell::ConnectToApplicationParams); |
98 params->SetTargetURL(url); | 95 params->SetTargetURL(url); |
99 params->set_services(services.Pass()); | 96 application_manager_->ConnectToApplication(params.Pass()); |
100 params->set_exposed_services(service_provider.Pass()); | |
101 context_->application_manager()->ConnectToApplication(params.Pass()); | |
102 EXPECT_FALSE(state_.runner_was_created); | 97 EXPECT_FALSE(state_.runner_was_created); |
103 EXPECT_FALSE(state_.runner_was_started); | 98 EXPECT_FALSE(state_.runner_was_started); |
104 EXPECT_FALSE(state_.runner_was_destroyed); | 99 EXPECT_FALSE(state_.runner_was_destroyed); |
105 } | 100 } |
106 | 101 |
107 } // namespace | 102 } // namespace |
108 } // namespace runner | 103 } // namespace runner |
109 } // namespace mojo | 104 } // namespace mojo |
OLD | NEW |