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

Unified 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, 5 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 side-by-side diff with in-line comments
Download patch
« 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 »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: mojo/shell/dynamic_service_loader_unittest.cc
diff --git a/mojo/shell/dynamic_service_loader_unittest.cc b/mojo/shell/dynamic_service_loader_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..7cfb74b171976001fb8f3485d0edd8a8a4d960bb
--- /dev/null
+++ b/mojo/shell/dynamic_service_loader_unittest.cc
@@ -0,0 +1,82 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "base/files/scoped_temp_dir.h"
+#include "mojo/shell/context.h"
+#include "mojo/shell/dynamic_service_loader.h"
+#include "mojo/shell/dynamic_service_runner.h"
+#include "net/base/filename_util.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+namespace mojo {
+namespace shell {
+
+namespace {
+
+struct TestState {
+ TestState() : runner_was_started(false), runner_was_destroyed(false) {}
+ bool runner_was_started;
+ bool runner_was_destroyed;
+};
+
+class TestDynamicServiceRunner : public DynamicServiceRunner {
+ public:
+ explicit TestDynamicServiceRunner(TestState* state) : state_(state) {}
+ virtual ~TestDynamicServiceRunner() {
+ state_->runner_was_destroyed = true;
+ base::MessageLoop::current()->Quit();
+ }
+ virtual void Start(const base::FilePath& app_path,
+ ScopedMessagePipeHandle service_handle,
+ const base::Closure& app_completed_callback) OVERRIDE {
+ state_->runner_was_started = true;
+ }
+ private:
+ TestState* state_;
+};
+
+class TestDynamicServiceRunnerFactory : public DynamicServiceRunnerFactory {
+ public:
+ explicit TestDynamicServiceRunnerFactory(TestState* state) : state_(state) {}
+ virtual ~TestDynamicServiceRunnerFactory() {}
+ virtual scoped_ptr<DynamicServiceRunner> Create(Context* context) OVERRIDE {
+ return scoped_ptr<DynamicServiceRunner>(
+ new TestDynamicServiceRunner(state_));
+ }
+ private:
+ TestState* state_;
+};
+
+} // namespace
+
+class DynamicServiceLoaderTest : public testing::Test {
+ public:
+ DynamicServiceLoaderTest() {}
+ virtual ~DynamicServiceLoaderTest() {}
+ virtual void SetUp() OVERRIDE {
+ scoped_ptr<DynamicServiceRunnerFactory> factory(
+ new TestDynamicServiceRunnerFactory(&state_));
+ loader_.reset(new DynamicServiceLoader(&context_, factory.Pass()));
+ }
+ protected:
+ base::MessageLoop loop_;
+ Context context_;
+ scoped_ptr<DynamicServiceLoader> loader_;
+ TestState state_;
+};
+
+TEST_F(DynamicServiceLoaderTest, DoesNotExist) {
+ base::ScopedTempDir temp_dir;
+ ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
+ base::FilePath nonexistent_file(FILE_PATH_LITERAL("nonexistent.txt"));
+ GURL url(net::FilePathToFileURL(temp_dir.path().Append(nonexistent_file)));
+ MessagePipe pipe;
+ loader_->LoadService(context_.service_manager(), url, pipe.handle0.Pass());
+ loop_.Run();
+ EXPECT_FALSE(state_.runner_was_started);
+ EXPECT_TRUE(state_.runner_was_destroyed);
+}
+
+} // namespace shell
+} // namespace mojo
« 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