cc: Make picture pile base thread safe.
[chromium-blink-merge.git] / mojo / shell / dynamic_application_loader_unittest.cc
blob693cab1cbaf9dbe6d5ba5c97d5ae5c7d446b36b2
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/shell/context.h"
7 #include "mojo/shell/dynamic_application_loader.h"
8 #include "mojo/shell/dynamic_service_runner.h"
9 #include "mojo/shell/filename_util.h"
10 #include "testing/gtest/include/gtest/gtest.h"
12 namespace mojo {
13 namespace shell {
15 namespace {
17 struct TestState {
18 TestState()
19 : runner_was_created(false),
20 runner_was_started(false),
21 runner_was_destroyed(false) {}
23 bool runner_was_created;
24 bool runner_was_started;
25 bool runner_was_destroyed;
28 class TestDynamicServiceRunner : public DynamicServiceRunner {
29 public:
30 explicit TestDynamicServiceRunner(TestState* state) : state_(state) {
31 state_->runner_was_created = true;
33 ~TestDynamicServiceRunner() override {
34 state_->runner_was_destroyed = true;
35 base::MessageLoop::current()->Quit();
37 void Start(const base::FilePath& app_path,
38 ScopedMessagePipeHandle service_handle,
39 const base::Closure& app_completed_callback) override {
40 state_->runner_was_started = true;
43 private:
44 TestState* state_;
47 class TestDynamicServiceRunnerFactory : public DynamicServiceRunnerFactory {
48 public:
49 explicit TestDynamicServiceRunnerFactory(TestState* state) : state_(state) {}
50 ~TestDynamicServiceRunnerFactory() override {}
51 scoped_ptr<DynamicServiceRunner> Create(Context* context) override {
52 return scoped_ptr<DynamicServiceRunner>(
53 new TestDynamicServiceRunner(state_));
56 private:
57 TestState* state_;
60 } // namespace
62 class DynamicApplicationLoaderTest : public testing::Test {
63 public:
64 DynamicApplicationLoaderTest() {}
65 virtual ~DynamicApplicationLoaderTest() {}
66 virtual void SetUp() override {
67 context_.Init();
68 scoped_ptr<DynamicServiceRunnerFactory> factory(
69 new TestDynamicServiceRunnerFactory(&state_));
70 loader_.reset(new DynamicApplicationLoader(&context_, factory.Pass()));
73 protected:
74 Context context_;
75 base::MessageLoop loop_;
76 scoped_ptr<DynamicApplicationLoader> loader_;
77 TestState state_;
80 TEST_F(DynamicApplicationLoaderTest, DoesNotExist) {
81 base::ScopedTempDir temp_dir;
82 ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
83 base::FilePath nonexistent_file(FILE_PATH_LITERAL("nonexistent.txt"));
84 GURL url(FilePathToFileURL(temp_dir.path().Append(nonexistent_file)));
85 MessagePipe pipe;
86 scoped_refptr<ApplicationLoader::SimpleLoadCallbacks> callbacks(
87 new ApplicationLoader::SimpleLoadCallbacks(pipe.handle0.Pass()));
88 loader_->Load(context_.application_manager(), url, callbacks);
89 EXPECT_FALSE(state_.runner_was_created);
90 EXPECT_FALSE(state_.runner_was_started);
91 EXPECT_FALSE(state_.runner_was_destroyed);
94 } // namespace shell
95 } // namespace mojo