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.
5 #include "base/files/scoped_temp_dir.h"
6 #include "mojo/runner/context.h"
7 #include "mojo/runner/url_resolver.h"
8 #include "mojo/shell/application_manager.h"
9 #include "mojo/util/filename_util.h"
10 #include "testing/gtest/include/gtest/gtest.h"
18 : runner_was_created(false),
19 runner_was_started(false),
20 runner_was_destroyed(false) {}
22 bool runner_was_created
;
23 bool runner_was_started
;
24 bool runner_was_destroyed
;
27 class TestNativeRunner
: public shell::NativeRunner
{
29 explicit TestNativeRunner(TestState
* state
) : state_(state
) {
30 state_
->runner_was_created
= true;
32 ~TestNativeRunner() override
{
33 state_
->runner_was_destroyed
= true;
34 if (base::MessageLoop::current()->is_running())
35 base::MessageLoop::current()->Quit();
37 void Start(const base::FilePath
& app_path
,
39 shell::NativeApplicationCleanup cleanup
,
40 InterfaceRequest
<Application
> application_request
,
41 const base::Closure
& app_completed_callback
) override
{
42 state_
->runner_was_started
= true;
49 class TestNativeRunnerFactory
: public shell::NativeRunnerFactory
{
51 explicit TestNativeRunnerFactory(TestState
* state
) : state_(state
) {}
52 ~TestNativeRunnerFactory() override
{}
53 scoped_ptr
<shell::NativeRunner
> Create(const Options
& options
) override
{
54 return scoped_ptr
<shell::NativeRunner
>(new TestNativeRunner(state_
));
61 class NativeApplicationLoaderTest
: public testing::Test
,
62 public shell::ApplicationManager::Delegate
{
64 NativeApplicationLoaderTest() : application_manager_(this) {}
65 ~NativeApplicationLoaderTest() override
{}
66 void SetUp() override
{
68 scoped_ptr
<shell::NativeRunnerFactory
> factory(
69 new TestNativeRunnerFactory(&state_
));
70 application_manager_
.set_native_runner_factory(factory
.Pass());
71 application_manager_
.set_blocking_pool(
72 context_
.task_runners()->blocking_pool());
74 void TearDown() override
{ context_
.Shutdown(); }
78 base::MessageLoop loop_
;
79 shell::ApplicationManager application_manager_
;
83 // shell::ApplicationManager::Delegate
84 GURL
ResolveMappings(const GURL
& url
) override
{
85 return context_
.url_resolver()->ApplyMappings(url
);
87 GURL
ResolveMojoURL(const GURL
& url
) override
{
88 return context_
.url_resolver()->ResolveMojoURL(url
);
92 const shell::Fetcher::FetchCallback
& loader_callback
) override
{
97 TEST_F(NativeApplicationLoaderTest
, DoesNotExist
) {
98 base::ScopedTempDir temp_dir
;
99 ASSERT_TRUE(temp_dir
.CreateUniqueTempDir());
100 base::FilePath
nonexistent_file(FILE_PATH_LITERAL("nonexistent.txt"));
101 GURL
url(util::FilePathToFileURL(temp_dir
.path().Append(nonexistent_file
)));
102 InterfaceRequest
<ServiceProvider
> services
;
103 ServiceProviderPtr service_provider
;
104 mojo::URLRequestPtr
request(mojo::URLRequest::New());
105 request
->url
= mojo::String::From(url
.spec());
106 application_manager_
.ConnectToApplication(
107 nullptr, request
.Pass(), std::string(), GURL(), services
.Pass(),
108 service_provider
.Pass(), shell::GetPermissiveCapabilityFilter(),
110 EXPECT_FALSE(state_
.runner_was_created
);
111 EXPECT_FALSE(state_
.runner_was_started
);
112 EXPECT_FALSE(state_
.runner_was_destroyed
);
116 } // namespace runner