Chromium Code Reviews| 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/shell/context.h" | 6 #include "mojo/shell/context.h" |
| 7 #include "mojo/shell/dynamic_service_loader.h" | 7 #include "mojo/shell/dynamic_service_loader.h" |
| 8 #include "mojo/shell/dynamic_service_runner.h" | 8 #include "mojo/shell/in_process_dynamic_service_runner.h" |
| 9 #include "net/base/filename_util.h" | 9 #include "net/base/filename_util.h" |
| 10 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
| 11 | 11 |
| 12 namespace mojo { | 12 namespace mojo { |
| 13 namespace shell { | 13 namespace shell { |
| 14 | 14 |
| 15 namespace { | 15 namespace { |
| 16 | 16 |
| 17 struct TestState { | 17 struct TestState { |
| 18 TestState() : runner_was_started(false), runner_was_destroyed(false) {} | 18 TestState() : runner_was_started(false), runner_was_destroyed(false) {} |
| 19 bool runner_was_started; | 19 bool runner_was_started; |
| 20 bool runner_was_destroyed; | 20 bool runner_was_destroyed; |
| 21 }; | 21 }; |
| 22 | 22 |
| 23 class TestDynamicServiceRunner : public DynamicServiceRunner { | 23 class TestDynamicServiceRunner : public InProcessDynamicServiceRunner { |
| 24 public: | 24 public: |
| 25 explicit TestDynamicServiceRunner(TestState* state) : state_(state) {} | 25 explicit TestDynamicServiceRunner(Context* context, TestState* state) |
|
tim (not reviewing)
2014/08/05 23:52:37
nit - don't need explicit
| |
| 26 : InProcessDynamicServiceRunner(context), state_(state) {} | |
| 26 virtual ~TestDynamicServiceRunner() { | 27 virtual ~TestDynamicServiceRunner() { |
| 27 state_->runner_was_destroyed = true; | 28 state_->runner_was_destroyed = true; |
| 28 base::MessageLoop::current()->Quit(); | |
| 29 } | 29 } |
| 30 virtual void Start(const base::FilePath& app_path, | 30 virtual void Start(const base::FilePath& app_path, |
| 31 ScopedMessagePipeHandle service_handle, | 31 ScopedMessagePipeHandle service_handle, |
| 32 const base::Closure& app_completed_callback) OVERRIDE { | 32 const base::Closure& app_completed_callback) OVERRIDE { |
| 33 state_->runner_was_started = true; | 33 state_->runner_was_started = true; |
| 34 InProcessDynamicServiceRunner::Start(app_path, service_handle.Pass(), | |
|
tim (not reviewing)
2014/08/05 23:52:37
What is using a real InProcessDSR buying us?
Aaron Boodman
2014/08/06 00:37:22
It's not needed with the current patch, I had the
| |
| 35 app_completed_callback); | |
| 34 } | 36 } |
| 35 private: | 37 private: |
| 36 TestState* state_; | 38 TestState* state_; |
| 37 }; | 39 }; |
| 38 | 40 |
| 39 class TestDynamicServiceRunnerFactory : public DynamicServiceRunnerFactory { | 41 class TestDynamicServiceRunnerFactory : public DynamicServiceRunnerFactory { |
| 40 public: | 42 public: |
| 41 explicit TestDynamicServiceRunnerFactory(TestState* state) : state_(state) {} | 43 explicit TestDynamicServiceRunnerFactory(TestState* state) : state_(state) {} |
| 42 virtual ~TestDynamicServiceRunnerFactory() {} | 44 virtual ~TestDynamicServiceRunnerFactory() {} |
| 43 virtual scoped_ptr<DynamicServiceRunner> Create(Context* context) OVERRIDE { | 45 virtual scoped_ptr<DynamicServiceRunner> Create(Context* context) OVERRIDE { |
| 44 return scoped_ptr<DynamicServiceRunner>( | 46 return scoped_ptr<DynamicServiceRunner>( |
| 45 new TestDynamicServiceRunner(state_)); | 47 new TestDynamicServiceRunner(context, state_)); |
| 46 } | 48 } |
| 47 private: | 49 private: |
| 48 TestState* state_; | 50 TestState* state_; |
| 49 }; | 51 }; |
| 50 | 52 |
| 51 } // namespace | 53 } // namespace |
| 52 | 54 |
| 53 class DynamicServiceLoaderTest : public testing::Test { | 55 class DynamicServiceLoaderTest : public testing::Test { |
| 54 public: | 56 public: |
| 55 DynamicServiceLoaderTest() {} | 57 DynamicServiceLoaderTest() {} |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 66 scoped_ptr<DynamicServiceLoader> loader_; | 68 scoped_ptr<DynamicServiceLoader> loader_; |
| 67 TestState state_; | 69 TestState state_; |
| 68 }; | 70 }; |
| 69 | 71 |
| 70 TEST_F(DynamicServiceLoaderTest, DoesNotExist) { | 72 TEST_F(DynamicServiceLoaderTest, DoesNotExist) { |
| 71 base::ScopedTempDir temp_dir; | 73 base::ScopedTempDir temp_dir; |
| 72 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); | 74 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); |
| 73 base::FilePath nonexistent_file(FILE_PATH_LITERAL("nonexistent.txt")); | 75 base::FilePath nonexistent_file(FILE_PATH_LITERAL("nonexistent.txt")); |
| 74 GURL url(net::FilePathToFileURL(temp_dir.path().Append(nonexistent_file))); | 76 GURL url(net::FilePathToFileURL(temp_dir.path().Append(nonexistent_file))); |
| 75 MessagePipe pipe; | 77 MessagePipe pipe; |
| 76 loader_->LoadService(context_.service_manager(), url, pipe.handle0.Pass()); | 78 scoped_refptr<ServiceLoader::SimpleLoadServiceCallbacks> callbacks( |
| 79 new ServiceLoader::SimpleLoadServiceCallbacks(pipe.handle0.Pass())); | |
| 80 loader_->LoadService(context_.service_manager(), url, callbacks); | |
| 77 loop_.Run(); | 81 loop_.Run(); |
| 78 EXPECT_FALSE(state_.runner_was_started); | 82 EXPECT_TRUE(state_.runner_was_started); |
| 79 EXPECT_TRUE(state_.runner_was_destroyed); | 83 EXPECT_TRUE(state_.runner_was_destroyed); |
| 80 } | 84 } |
| 81 | 85 |
| 82 } // namespace shell | 86 } // namespace shell |
| 83 } // namespace mojo | 87 } // namespace mojo |
| OLD | NEW |