| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "base/files/scoped_temp_dir.h" | |
| 6 #include "mojo/shell/context.h" | |
| 7 #include "mojo/shell/dynamic_service_loader.h" | |
| 8 #include "mojo/shell/dynamic_service_runner.h" | |
| 9 #include "net/base/filename_util.h" | |
| 10 #include "testing/gtest/include/gtest/gtest.h" | |
| 11 | |
| 12 namespace mojo { | |
| 13 namespace shell { | |
| 14 | |
| 15 namespace { | |
| 16 | |
| 17 struct TestState { | |
| 18 bool runner_was_started; | |
| 19 bool runner_was_destroyed; | |
| 20 }; | |
| 21 | |
| 22 class TestDynamicServiceRunner : public DynamicServiceRunner { | |
| 23 public: | |
| 24 explicit TestDynamicServiceRunner(TestState* state) : state_(state) {} | |
| 25 virtual ~TestDynamicServiceRunner() { | |
| 26 state_->runner_was_destroyed = true; | |
| 27 base::MessageLoop::current()->Quit(); | |
| 28 } | |
| 29 virtual void Start(const base::FilePath& app_path, | |
| 30 ScopedMessagePipeHandle service_handle, | |
| 31 const base::Closure& app_completed_callback) OVERRIDE { | |
| 32 state_->runner_was_started = true; | |
| 33 } | |
| 34 private: | |
| 35 TestState* state_; | |
| 36 }; | |
| 37 | |
| 38 class TestDynamicServiceRunnerFactory : public DynamicServiceRunnerFactory { | |
| 39 public: | |
| 40 explicit TestDynamicServiceRunnerFactory(TestState* state) : state_(state) {} | |
| 41 virtual ~TestDynamicServiceRunnerFactory() {} | |
| 42 virtual scoped_ptr<DynamicServiceRunner> Create(Context* context) OVERRIDE { | |
| 43 return scoped_ptr<DynamicServiceRunner>( | |
| 44 new TestDynamicServiceRunner(state_)); | |
| 45 } | |
| 46 private: | |
| 47 TestState* state_; | |
| 48 }; | |
| 49 | |
| 50 } // namespace | |
| 51 | |
| 52 class DynamicServiceLoaderTest : public testing::Test { | |
| 53 public: | |
| 54 DynamicServiceLoaderTest() {} | |
| 55 virtual ~DynamicServiceLoaderTest() {} | |
| 56 virtual void SetUp() OVERRIDE { | |
| 57 scoped_ptr<DynamicServiceRunnerFactory> factory( | |
| 58 new TestDynamicServiceRunnerFactory(&state_)); | |
| 59 loader_.reset(new DynamicServiceLoader(&context_, factory.Pass())); | |
| 60 } | |
| 61 protected: | |
| 62 base::MessageLoop loop_; | |
| 63 Context context_; | |
| 64 scoped_ptr<DynamicServiceLoader> loader_; | |
| 65 TestState state_; | |
| 66 }; | |
| 67 | |
| 68 TEST_F(DynamicServiceLoaderTest, DoesNotExist) { | |
| 69 base::ScopedTempDir temp_dir; | |
| 70 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); | |
| 71 base::FilePath nonexistent_file(FILE_PATH_LITERAL("nonexistent.txt")); | |
| 72 GURL url(net::FilePathToFileURL(temp_dir.path().Append(nonexistent_file))); | |
| 73 MessagePipe pipe; | |
| 74 loader_->LoadService(context_.service_manager(), url, pipe.handle0.Pass()); | |
| 75 loop_.Run(); | |
| 76 EXPECT_FALSE(state_.runner_was_started); | |
| 77 EXPECT_TRUE(state_.runner_was_destroyed); | |
| 78 } | |
| 79 | |
| 80 } // namespace shell | |
| 81 } // namespace mojo | |
| OLD | NEW |