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

Unified Diff: services/dart/echo_apptest.cc

Issue 816113004: Dart: Adds a content handler and a test. (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: comment Created 5 years, 11 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
Index: services/dart/echo_apptest.cc
diff --git a/services/dart/echo_apptest.cc b/services/dart/echo_apptest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..4e51a1781ec735e0237b3948b18f2d0e5da47b16
--- /dev/null
+++ b/services/dart/echo_apptest.cc
@@ -0,0 +1,88 @@
+// 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/file_path.h"
+#include "base/logging.h"
+#include "base/path_service.h"
+#include "mojo/public/cpp/application/application_impl.h"
+#include "mojo/public/cpp/application/application_test_base.h"
+#include "services/dart/test/echo_service.mojom.h"
+
+using mojo::String;
+
+namespace dart {
+namespace {
+
+class DartEchoTest : public mojo::test::ApplicationTestBase {
+ public:
+ DartEchoTest() : ApplicationTestBase() {}
+ ~DartEchoTest() override {}
+
+ protected:
+ const std::string DartAppURL(const std::string& filename) {
+ base::FilePath path;
+ PathService::Get(base::DIR_SOURCE_ROOT, &path);
+ path = path.AppendASCII("services")
+ .AppendASCII("dart")
+ .AppendASCII("test")
+ .AppendASCII(filename);
+ return "file://" + path.AsUTF8Unsafe();
+ }
+
+ // ApplicationTestBase:
+ void SetUp() override {
+ ApplicationTestBase::SetUp();
+ const std::string& url = DartAppURL("echo.dart");
+ application_impl()->ConnectToService(url, &echo_service_);
+ }
+
+ mojo::EchoServicePtr echo_service_;
+
+ private:
+ MOJO_DISALLOW_COPY_AND_ASSIGN(DartEchoTest);
+};
+
+struct EchoStringCallback {
+ explicit EchoStringCallback(String *s) : echo_value(s) {}
+ void Run(const String& value) const {
+ *echo_value = value;
+ }
+ String *echo_value;
+};
+
+TEST_F(DartEchoTest, EchoString) {
+ String foo;
+ EchoStringCallback callback(&foo);
+ echo_service_->EchoString("foo", callback);
+ EXPECT_TRUE(echo_service_.WaitForIncomingMethodCall());
+ EXPECT_EQ("foo", foo);
+ echo_service_->EchoString("quit", callback);
+ EXPECT_TRUE(echo_service_.WaitForIncomingMethodCall());
+ EXPECT_EQ("quit", foo);
+}
+
+TEST_F(DartEchoTest, EchoEmptyString) {
+ String empty;
+ EchoStringCallback callback(&empty);
+ echo_service_->EchoString("", callback);
+ EXPECT_TRUE(echo_service_.WaitForIncomingMethodCall());
+ EXPECT_EQ("", empty);
+ echo_service_->EchoString("quit", callback);
+ EXPECT_TRUE(echo_service_.WaitForIncomingMethodCall());
+ EXPECT_EQ("quit", empty);
+}
+
+TEST_F(DartEchoTest, EchoNullString) {
+ String null;
+ EchoStringCallback callback(&null);
+ echo_service_->EchoString(nullptr, callback);
+ EXPECT_TRUE(echo_service_.WaitForIncomingMethodCall());
+ EXPECT_TRUE(null.is_null());
+ echo_service_->EchoString("quit", callback);
+ EXPECT_TRUE(echo_service_.WaitForIncomingMethodCall());
+ EXPECT_EQ("quit", null);
+}
+
+} // namespace
+} // namespace dart

Powered by Google App Engine
This is Rietveld 408576698