| 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 "mojo/runner/context.h" | 6 #include "mojo/runner/context.h" |
| 7 #include "mojo/shell/application_manager.h" | 7 #include "mojo/shell/application_manager.h" |
| 8 #include "mojo/util/filename_util.h" | 8 #include "mojo/util/filename_util.h" |
| 9 #include "testing/gtest/include/gtest/gtest.h" | 9 #include "testing/gtest/include/gtest/gtest.h" |
| 10 | 10 |
| 11 namespace mojo { | 11 namespace mojo { |
| 12 namespace shell { | 12 namespace runner { |
| 13 namespace { | 13 namespace { |
| 14 | 14 |
| 15 struct TestState { | 15 struct TestState { |
| 16 TestState() | 16 TestState() |
| 17 : runner_was_created(false), | 17 : runner_was_created(false), |
| 18 runner_was_started(false), | 18 runner_was_started(false), |
| 19 runner_was_destroyed(false) {} | 19 runner_was_destroyed(false) {} |
| 20 | 20 |
| 21 bool runner_was_created; | 21 bool runner_was_created; |
| 22 bool runner_was_started; | 22 bool runner_was_started; |
| 23 bool runner_was_destroyed; | 23 bool runner_was_destroyed; |
| 24 }; | 24 }; |
| 25 | 25 |
| 26 class TestNativeRunner : public NativeRunner { | 26 class TestNativeRunner : public shell::NativeRunner { |
| 27 public: | 27 public: |
| 28 explicit TestNativeRunner(TestState* state) : state_(state) { | 28 explicit TestNativeRunner(TestState* state) : state_(state) { |
| 29 state_->runner_was_created = true; | 29 state_->runner_was_created = true; |
| 30 } | 30 } |
| 31 ~TestNativeRunner() override { | 31 ~TestNativeRunner() override { |
| 32 state_->runner_was_destroyed = true; | 32 state_->runner_was_destroyed = true; |
| 33 base::MessageLoop::current()->Quit(); | 33 base::MessageLoop::current()->Quit(); |
| 34 } | 34 } |
| 35 void Start(const base::FilePath& app_path, | 35 void Start(const base::FilePath& app_path, |
| 36 NativeApplicationCleanup cleanup, | 36 shell::NativeApplicationCleanup cleanup, |
| 37 InterfaceRequest<Application> application_request, | 37 InterfaceRequest<Application> application_request, |
| 38 const base::Closure& app_completed_callback) override { | 38 const base::Closure& app_completed_callback) override { |
| 39 state_->runner_was_started = true; | 39 state_->runner_was_started = true; |
| 40 } | 40 } |
| 41 | 41 |
| 42 private: | 42 private: |
| 43 TestState* state_; | 43 TestState* state_; |
| 44 }; | 44 }; |
| 45 | 45 |
| 46 class TestNativeRunnerFactory : public NativeRunnerFactory { | 46 class TestNativeRunnerFactory : public shell::NativeRunnerFactory { |
| 47 public: | 47 public: |
| 48 explicit TestNativeRunnerFactory(TestState* state) : state_(state) {} | 48 explicit TestNativeRunnerFactory(TestState* state) : state_(state) {} |
| 49 ~TestNativeRunnerFactory() override {} | 49 ~TestNativeRunnerFactory() override {} |
| 50 scoped_ptr<NativeRunner> Create(const Options& options) override { | 50 scoped_ptr<shell::NativeRunner> Create(const Options& options) override { |
| 51 return scoped_ptr<NativeRunner>(new TestNativeRunner(state_)); | 51 return scoped_ptr<shell::NativeRunner>(new TestNativeRunner(state_)); |
| 52 } | 52 } |
| 53 | 53 |
| 54 private: | 54 private: |
| 55 TestState* state_; | 55 TestState* state_; |
| 56 }; | 56 }; |
| 57 | 57 |
| 58 class NativeApplicationLoaderTest : public testing::Test, | 58 class NativeApplicationLoaderTest : public testing::Test, |
| 59 public ApplicationManager::Delegate { | 59 public shell::ApplicationManager::Delegate { |
| 60 public: | 60 public: |
| 61 NativeApplicationLoaderTest() : application_manager_(this) {} | 61 NativeApplicationLoaderTest() : application_manager_(this) {} |
| 62 ~NativeApplicationLoaderTest() override {} | 62 ~NativeApplicationLoaderTest() override {} |
| 63 void SetUp() override { | 63 void SetUp() override { |
| 64 context_.Init(); | 64 context_.Init(); |
| 65 scoped_ptr<NativeRunnerFactory> factory( | 65 scoped_ptr<shell::NativeRunnerFactory> factory( |
| 66 new TestNativeRunnerFactory(&state_)); | 66 new TestNativeRunnerFactory(&state_)); |
| 67 application_manager_.set_native_runner_factory(factory.Pass()); | 67 application_manager_.set_native_runner_factory(factory.Pass()); |
| 68 application_manager_.set_blocking_pool( | 68 application_manager_.set_blocking_pool( |
| 69 context_.task_runners()->blocking_pool()); | 69 context_.task_runners()->blocking_pool()); |
| 70 } | 70 } |
| 71 void TearDown() override { context_.Shutdown(); } | 71 void TearDown() override { context_.Shutdown(); } |
| 72 | 72 |
| 73 protected: | 73 protected: |
| 74 shell::Context context_; | 74 Context context_; |
| 75 base::MessageLoop loop_; | 75 base::MessageLoop loop_; |
| 76 ApplicationManager application_manager_; | 76 shell::ApplicationManager application_manager_; |
| 77 TestState state_; | 77 TestState state_; |
| 78 | 78 |
| 79 private: | 79 private: |
| 80 // ApplicationManager::Delegate | 80 // shell::ApplicationManager::Delegate |
| 81 GURL ResolveMappings(const GURL& url) override { return url; } | 81 GURL ResolveMappings(const GURL& url) override { return url; } |
| 82 GURL ResolveMojoURL(const GURL& url) override { return url; } | 82 GURL ResolveMojoURL(const GURL& url) override { return url; } |
| 83 }; | 83 }; |
| 84 | 84 |
| 85 TEST_F(NativeApplicationLoaderTest, DoesNotExist) { | 85 TEST_F(NativeApplicationLoaderTest, DoesNotExist) { |
| 86 base::ScopedTempDir temp_dir; | 86 base::ScopedTempDir temp_dir; |
| 87 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); | 87 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); |
| 88 base::FilePath nonexistent_file(FILE_PATH_LITERAL("nonexistent.txt")); | 88 base::FilePath nonexistent_file(FILE_PATH_LITERAL("nonexistent.txt")); |
| 89 GURL url(util::FilePathToFileURL(temp_dir.path().Append(nonexistent_file))); | 89 GURL url(util::FilePathToFileURL(temp_dir.path().Append(nonexistent_file))); |
| 90 InterfaceRequest<ServiceProvider> services; | 90 InterfaceRequest<ServiceProvider> services; |
| 91 ServiceProviderPtr service_provider; | 91 ServiceProviderPtr service_provider; |
| 92 application_manager_.ConnectToApplication( | 92 application_manager_.ConnectToApplication( |
| 93 url, GURL(), services.Pass(), service_provider.Pass(), base::Closure()); | 93 url, GURL(), services.Pass(), service_provider.Pass(), base::Closure()); |
| 94 EXPECT_FALSE(state_.runner_was_created); | 94 EXPECT_FALSE(state_.runner_was_created); |
| 95 EXPECT_FALSE(state_.runner_was_started); | 95 EXPECT_FALSE(state_.runner_was_started); |
| 96 EXPECT_FALSE(state_.runner_was_destroyed); | 96 EXPECT_FALSE(state_.runner_was_destroyed); |
| 97 } | 97 } |
| 98 | 98 |
| 99 } // namespace | 99 } // namespace |
| 100 } // namespace shell | 100 } // namespace runner |
| 101 } // namespace mojo | 101 } // namespace mojo |
| OLD | NEW |