Roll src/third_party/skia d32087a:1052f51
[chromium-blink-merge.git] / mojo / runner / native_runner_unittest.cc
blobe4a636d7b246bed0f616945dfca3de61ab61e429
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 "base/path_service.h"
7 #include "mojo/runner/context.h"
8 #include "mojo/shell/application_manager.h"
9 #include "mojo/util/filename_util.h"
10 #include "testing/gtest/include/gtest/gtest.h"
12 namespace mojo {
13 namespace runner {
14 namespace {
16 struct TestState {
17 TestState()
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 {
28 public:
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,
38 bool start_sandboxed,
39 InterfaceRequest<Application> application_request,
40 const base::Closure& app_completed_callback) override {
41 state_->runner_was_started = true;
44 private:
45 TestState* state_;
48 class TestNativeRunnerFactory : public shell::NativeRunnerFactory {
49 public:
50 explicit TestNativeRunnerFactory(TestState* state) : state_(state) {}
51 ~TestNativeRunnerFactory() override {}
52 scoped_ptr<shell::NativeRunner> Create() override {
53 return scoped_ptr<shell::NativeRunner>(new TestNativeRunner(state_));
56 private:
57 TestState* state_;
60 class NativeApplicationLoaderTest : public testing::Test {
61 public:
62 NativeApplicationLoaderTest() {
63 base::FilePath shell_dir;
64 PathService::Get(base::DIR_MODULE, &shell_dir);
65 context_.reset(new Context(shell_dir));
66 loop_.reset(new base::MessageLoop);
68 ~NativeApplicationLoaderTest() override {
69 loop_.reset();
70 context_.reset();
72 void SetUp() override {
73 context_->Init();
74 scoped_ptr<shell::NativeRunnerFactory> factory(
75 new TestNativeRunnerFactory(&state_));
76 context_->application_manager()->set_native_runner_factory(factory.Pass());
77 context_->application_manager()->set_blocking_pool(
78 context_->task_runners()->blocking_pool());
80 void TearDown() override { context_->Shutdown(); }
82 protected:
83 scoped_ptr<base::MessageLoop> loop_;
84 scoped_ptr<Context> context_;
85 TestState state_;
88 TEST_F(NativeApplicationLoaderTest, DoesNotExist) {
89 base::ScopedTempDir temp_dir;
90 ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
91 base::FilePath nonexistent_file(FILE_PATH_LITERAL("nonexistent.txt"));
92 GURL url(util::FilePathToFileURL(temp_dir.path().Append(nonexistent_file)));
93 InterfaceRequest<ServiceProvider> services;
94 ServiceProviderPtr service_provider;
95 mojo::URLRequestPtr request(mojo::URLRequest::New());
96 request->url = mojo::String::From(url.spec());
98 scoped_ptr<shell::ConnectToApplicationParams> params(
99 new shell::ConnectToApplicationParams);
100 params->SetURLInfo(request.Pass());
101 params->set_services(services.Pass());
102 params->set_exposed_services(service_provider.Pass());
103 params->set_filter(shell::GetPermissiveCapabilityFilter());
104 context_->application_manager()->ConnectToApplication(params.Pass());
105 EXPECT_FALSE(state_.runner_was_created);
106 EXPECT_FALSE(state_.runner_was_started);
107 EXPECT_FALSE(state_.runner_was_destroyed);
110 } // namespace
111 } // namespace runner
112 } // namespace mojo