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/runner/url_resolver.h" |
7 #include "mojo/shell/application_manager.h" | 8 #include "mojo/shell/application_manager.h" |
8 #include "mojo/util/filename_util.h" | 9 #include "mojo/util/filename_util.h" |
9 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
10 | 11 |
11 namespace mojo { | 12 namespace mojo { |
12 namespace runner { | 13 namespace runner { |
13 namespace { | 14 namespace { |
14 | 15 |
15 struct TestState { | 16 struct TestState { |
16 TestState() | 17 TestState() |
17 : runner_was_created(false), | 18 : runner_was_created(false), |
18 runner_was_started(false), | 19 runner_was_started(false), |
19 runner_was_destroyed(false) {} | 20 runner_was_destroyed(false) {} |
20 | 21 |
21 bool runner_was_created; | 22 bool runner_was_created; |
22 bool runner_was_started; | 23 bool runner_was_started; |
23 bool runner_was_destroyed; | 24 bool runner_was_destroyed; |
24 }; | 25 }; |
25 | 26 |
26 class TestNativeRunner : public shell::NativeRunner { | 27 class TestNativeRunner : public shell::NativeRunner { |
27 public: | 28 public: |
28 explicit TestNativeRunner(TestState* state) : state_(state) { | 29 explicit TestNativeRunner(TestState* state) : state_(state) { |
29 state_->runner_was_created = true; | 30 state_->runner_was_created = true; |
30 } | 31 } |
31 ~TestNativeRunner() override { | 32 ~TestNativeRunner() override { |
32 state_->runner_was_destroyed = true; | 33 state_->runner_was_destroyed = true; |
33 base::MessageLoop::current()->Quit(); | 34 if (base::MessageLoop::current()->is_running()) |
| 35 base::MessageLoop::current()->Quit(); |
34 } | 36 } |
35 void Start(const base::FilePath& app_path, | 37 void Start(const base::FilePath& app_path, |
36 bool start_sandboxed, | 38 bool start_sandboxed, |
37 shell::NativeApplicationCleanup cleanup, | 39 shell::NativeApplicationCleanup cleanup, |
38 InterfaceRequest<Application> application_request, | 40 InterfaceRequest<Application> application_request, |
39 const base::Closure& app_completed_callback) override { | 41 const base::Closure& app_completed_callback) override { |
40 state_->runner_was_started = true; | 42 state_->runner_was_started = true; |
41 } | 43 } |
42 | 44 |
43 private: | 45 private: |
(...skipping 28 matching lines...) Expand all Loading... |
72 void TearDown() override { context_.Shutdown(); } | 74 void TearDown() override { context_.Shutdown(); } |
73 | 75 |
74 protected: | 76 protected: |
75 Context context_; | 77 Context context_; |
76 base::MessageLoop loop_; | 78 base::MessageLoop loop_; |
77 shell::ApplicationManager application_manager_; | 79 shell::ApplicationManager application_manager_; |
78 TestState state_; | 80 TestState state_; |
79 | 81 |
80 private: | 82 private: |
81 // shell::ApplicationManager::Delegate | 83 // shell::ApplicationManager::Delegate |
82 GURL ResolveMappings(const GURL& url) override { return url; } | 84 GURL ResolveMappings(const GURL& url) override { |
83 GURL ResolveMojoURL(const GURL& url) override { return url; } | 85 return context_.url_resolver()->ApplyMappings(url); |
| 86 } |
| 87 GURL ResolveMojoURL(const GURL& url) override { |
| 88 return context_.url_resolver()->ResolveMojoURL(url); |
| 89 } |
84 bool CreateFetcher( | 90 bool CreateFetcher( |
85 const GURL& url, | 91 const GURL& url, |
86 const shell::Fetcher::FetchCallback& loader_callback) override { | 92 const shell::Fetcher::FetchCallback& loader_callback) override { |
87 return false; | 93 return false; |
88 } | 94 } |
89 }; | 95 }; |
90 | 96 |
91 TEST_F(NativeApplicationLoaderTest, DoesNotExist) { | 97 TEST_F(NativeApplicationLoaderTest, DoesNotExist) { |
92 base::ScopedTempDir temp_dir; | 98 base::ScopedTempDir temp_dir; |
93 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); | 99 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); |
94 base::FilePath nonexistent_file(FILE_PATH_LITERAL("nonexistent.txt")); | 100 base::FilePath nonexistent_file(FILE_PATH_LITERAL("nonexistent.txt")); |
95 GURL url(util::FilePathToFileURL(temp_dir.path().Append(nonexistent_file))); | 101 GURL url(util::FilePathToFileURL(temp_dir.path().Append(nonexistent_file))); |
96 InterfaceRequest<ServiceProvider> services; | 102 InterfaceRequest<ServiceProvider> services; |
97 ServiceProviderPtr service_provider; | 103 ServiceProviderPtr service_provider; |
98 mojo::URLRequestPtr request(mojo::URLRequest::New()); | 104 mojo::URLRequestPtr request(mojo::URLRequest::New()); |
99 request->url = mojo::String::From(url.spec()); | 105 request->url = mojo::String::From(url.spec()); |
100 application_manager_.ConnectToApplication( | 106 application_manager_.ConnectToApplication( |
101 nullptr, request.Pass(), std::string(), GURL(), services.Pass(), | 107 nullptr, request.Pass(), std::string(), GURL(), services.Pass(), |
102 service_provider.Pass(), shell::GetPermissiveCapabilityFilter(), | 108 service_provider.Pass(), shell::GetPermissiveCapabilityFilter(), |
103 base::Closure()); | 109 base::Closure()); |
104 EXPECT_FALSE(state_.runner_was_created); | 110 EXPECT_FALSE(state_.runner_was_created); |
105 EXPECT_FALSE(state_.runner_was_started); | 111 EXPECT_FALSE(state_.runner_was_started); |
106 EXPECT_FALSE(state_.runner_was_destroyed); | 112 EXPECT_FALSE(state_.runner_was_destroyed); |
107 } | 113 } |
108 | 114 |
109 } // namespace | 115 } // namespace |
110 } // namespace runner | 116 } // namespace runner |
111 } // namespace mojo | 117 } // namespace mojo |
OLD | NEW |