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 "shell/context.h" | |
7 #include "shell/dynamic_application_loader.h" | |
8 #include "shell/dynamic_service_runner.h" | |
9 #include "shell/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 TestState() | |
19 : runner_was_created(false), | |
20 runner_was_started(false), | |
21 runner_was_destroyed(false) {} | |
22 | |
23 bool runner_was_created; | |
24 bool runner_was_started; | |
25 bool runner_was_destroyed; | |
26 }; | |
27 | |
28 class TestDynamicServiceRunner : public DynamicServiceRunner { | |
29 public: | |
30 explicit TestDynamicServiceRunner(TestState* state) : state_(state) { | |
31 state_->runner_was_created = true; | |
32 } | |
33 ~TestDynamicServiceRunner() override { | |
34 state_->runner_was_destroyed = true; | |
35 base::MessageLoop::current()->Quit(); | |
36 } | |
37 void Start(const base::FilePath& app_path, | |
38 DynamicServiceRunner::CleanupBehavior cleanup_behavior, | |
39 InterfaceRequest<Application> application_request, | |
40 const base::Closure& app_completed_callback) override { | |
41 state_->runner_was_started = true; | |
42 } | |
43 | |
44 private: | |
45 TestState* state_; | |
46 }; | |
47 | |
48 class TestDynamicServiceRunnerFactory : public DynamicServiceRunnerFactory { | |
49 public: | |
50 explicit TestDynamicServiceRunnerFactory(TestState* state) : state_(state) {} | |
51 ~TestDynamicServiceRunnerFactory() override {} | |
52 scoped_ptr<DynamicServiceRunner> Create(Context* context) override { | |
53 return scoped_ptr<DynamicServiceRunner>( | |
54 new TestDynamicServiceRunner(state_)); | |
55 } | |
56 | |
57 private: | |
58 TestState* state_; | |
59 }; | |
60 | |
61 } // namespace | |
62 | |
63 class DynamicApplicationLoaderTest : public testing::Test { | |
64 public: | |
65 DynamicApplicationLoaderTest() {} | |
66 ~DynamicApplicationLoaderTest() override {} | |
67 void SetUp() override { | |
68 context_.Init(); | |
69 scoped_ptr<DynamicServiceRunnerFactory> factory( | |
70 new TestDynamicServiceRunnerFactory(&state_)); | |
71 loader_.reset(new DynamicApplicationLoader(&context_, factory.Pass())); | |
72 } | |
73 | |
74 protected: | |
75 Context context_; | |
76 base::MessageLoop loop_; | |
77 scoped_ptr<DynamicApplicationLoader> loader_; | |
78 TestState state_; | |
79 }; | |
80 | |
81 TEST_F(DynamicApplicationLoaderTest, DoesNotExist) { | |
82 base::ScopedTempDir temp_dir; | |
83 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); | |
84 base::FilePath nonexistent_file(FILE_PATH_LITERAL("nonexistent.txt")); | |
85 GURL url(FilePathToFileURL(temp_dir.path().Append(nonexistent_file))); | |
86 ApplicationPtr application; | |
87 loader_->Load(context_.application_manager(), url, GetProxy(&application), | |
88 ApplicationLoader::SimpleLoadCallback()); | |
89 EXPECT_FALSE(state_.runner_was_created); | |
90 EXPECT_FALSE(state_.runner_was_started); | |
91 EXPECT_FALSE(state_.runner_was_destroyed); | |
92 } | |
93 | |
94 } // namespace shell | |
95 } // namespace mojo | |
OLD | NEW |