Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(55)

Side by Side Diff: mojo/shell/dynamic_service_loader_unittest.cc

Issue 414173004: mojo: fix little bug in DynamicServiceLoader/Runner (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: oopsies Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « mojo/shell/dynamic_service_loader.cc ('k') | mojo/shell/in_process_dynamic_service_runner.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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.
4
5 #include "base/files/scoped_temp_dir.h"
6 #include "mojo/shell/context.h"
7 #include "mojo/shell/dynamic_service_loader.h"
8 #include "mojo/shell/dynamic_service_runner.h"
9 #include "net/base/filename_util.h"
10 #include "testing/gtest/include/gtest/gtest.h"
11
12 namespace mojo {
13 namespace shell {
14
15 namespace {
16
17 struct TestState {
18 TestState() : runner_was_started(false), runner_was_destroyed(false) {}
19 bool runner_was_started;
20 bool runner_was_destroyed;
21 };
22
23 class TestDynamicServiceRunner : public DynamicServiceRunner {
24 public:
25 explicit TestDynamicServiceRunner(TestState* state) : state_(state) {}
26 virtual ~TestDynamicServiceRunner() {
27 state_->runner_was_destroyed = true;
28 base::MessageLoop::current()->Quit();
29 }
30 virtual void Start(const base::FilePath& app_path,
31 ScopedMessagePipeHandle service_handle,
32 const base::Closure& app_completed_callback) OVERRIDE {
33 state_->runner_was_started = true;
34 }
35 private:
36 TestState* state_;
37 };
38
39 class TestDynamicServiceRunnerFactory : public DynamicServiceRunnerFactory {
40 public:
41 explicit TestDynamicServiceRunnerFactory(TestState* state) : state_(state) {}
42 virtual ~TestDynamicServiceRunnerFactory() {}
43 virtual scoped_ptr<DynamicServiceRunner> Create(Context* context) OVERRIDE {
44 return scoped_ptr<DynamicServiceRunner>(
45 new TestDynamicServiceRunner(state_));
46 }
47 private:
48 TestState* state_;
49 };
50
51 } // namespace
52
53 class DynamicServiceLoaderTest : public testing::Test {
54 public:
55 DynamicServiceLoaderTest() {}
56 virtual ~DynamicServiceLoaderTest() {}
57 virtual void SetUp() OVERRIDE {
58 scoped_ptr<DynamicServiceRunnerFactory> factory(
59 new TestDynamicServiceRunnerFactory(&state_));
60 loader_.reset(new DynamicServiceLoader(&context_, factory.Pass()));
61 }
62 protected:
63 base::MessageLoop loop_;
64 Context context_;
65 scoped_ptr<DynamicServiceLoader> loader_;
66 TestState state_;
67 };
68
69 TEST_F(DynamicServiceLoaderTest, DoesNotExist) {
70 base::ScopedTempDir temp_dir;
71 ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
72 base::FilePath nonexistent_file(FILE_PATH_LITERAL("nonexistent.txt"));
73 GURL url(net::FilePathToFileURL(temp_dir.path().Append(nonexistent_file)));
74 MessagePipe pipe;
75 loader_->LoadService(context_.service_manager(), url, pipe.handle0.Pass());
76 loop_.Run();
77 EXPECT_FALSE(state_.runner_was_started);
78 EXPECT_TRUE(state_.runner_was_destroyed);
79 }
80
81 } // namespace shell
82 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/shell/dynamic_service_loader.cc ('k') | mojo/shell/in_process_dynamic_service_runner.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698