mandoline: Enable the sandbox on clipboard and tracing.
[chromium-blink-merge.git] / mojo / runner / native_runner_unittest.cc
blob219600b215fd37ae3c84b358252b63e89b71c4e3
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/shell/application_manager.h"
8 #include "mojo/util/filename_util.h"
9 #include "testing/gtest/include/gtest/gtest.h"
11 namespace mojo {
12 namespace runner {
13 namespace {
15 struct TestState {
16 TestState()
17 : runner_was_created(false),
18 runner_was_started(false),
19 runner_was_destroyed(false) {}
21 bool runner_was_created;
22 bool runner_was_started;
23 bool runner_was_destroyed;
26 class TestNativeRunner : public shell::NativeRunner {
27 public:
28 explicit TestNativeRunner(TestState* state) : state_(state) {
29 state_->runner_was_created = true;
31 ~TestNativeRunner() override {
32 state_->runner_was_destroyed = true;
33 base::MessageLoop::current()->Quit();
35 void Start(const base::FilePath& app_path,
36 bool start_sandboxed,
37 shell::NativeApplicationCleanup cleanup,
38 InterfaceRequest<Application> application_request,
39 const base::Closure& app_completed_callback) override {
40 state_->runner_was_started = true;
43 private:
44 TestState* state_;
47 class TestNativeRunnerFactory : public shell::NativeRunnerFactory {
48 public:
49 explicit TestNativeRunnerFactory(TestState* state) : state_(state) {}
50 ~TestNativeRunnerFactory() override {}
51 scoped_ptr<shell::NativeRunner> Create(const Options& options) override {
52 return scoped_ptr<shell::NativeRunner>(new TestNativeRunner(state_));
55 private:
56 TestState* state_;
59 class NativeApplicationLoaderTest : public testing::Test,
60 public shell::ApplicationManager::Delegate {
61 public:
62 NativeApplicationLoaderTest() : application_manager_(this) {}
63 ~NativeApplicationLoaderTest() override {}
64 void SetUp() override {
65 context_.Init();
66 scoped_ptr<shell::NativeRunnerFactory> factory(
67 new TestNativeRunnerFactory(&state_));
68 application_manager_.set_native_runner_factory(factory.Pass());
69 application_manager_.set_blocking_pool(
70 context_.task_runners()->blocking_pool());
72 void TearDown() override { context_.Shutdown(); }
74 protected:
75 Context context_;
76 base::MessageLoop loop_;
77 shell::ApplicationManager application_manager_;
78 TestState state_;
80 private:
81 // shell::ApplicationManager::Delegate
82 GURL ResolveMappings(const GURL& url) override { return url; }
83 GURL ResolveMojoURL(const GURL& url) override { return url; }
84 bool CreateFetcher(
85 const GURL& url,
86 const shell::Fetcher::FetchCallback& loader_callback) override {
87 return false;
91 TEST_F(NativeApplicationLoaderTest, DoesNotExist) {
92 base::ScopedTempDir temp_dir;
93 ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
94 base::FilePath nonexistent_file(FILE_PATH_LITERAL("nonexistent.txt"));
95 GURL url(util::FilePathToFileURL(temp_dir.path().Append(nonexistent_file)));
96 InterfaceRequest<ServiceProvider> services;
97 ServiceProviderPtr service_provider;
98 mojo::URLRequestPtr request(mojo::URLRequest::New());
99 request->url = mojo::String::From(url.spec());
100 application_manager_.ConnectToApplication(
101 nullptr, request.Pass(), std::string(), GURL(), services.Pass(),
102 service_provider.Pass(), nullptr, base::Closure());
103 EXPECT_FALSE(state_.runner_was_created);
104 EXPECT_FALSE(state_.runner_was_started);
105 EXPECT_FALSE(state_.runner_was_destroyed);
108 } // namespace
109 } // namespace runner
110 } // namespace mojo