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

Side by Side 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: Address comments 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 unified diff | Download patch
« no previous file with comments | « services/dart/dart_app.cc ('k') | services/dart/lib/application.dart » ('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/file_path.h"
6 #include "base/logging.h"
7 #include "base/path_service.h"
8 #include "mojo/public/cpp/application/application_impl.h"
9 #include "mojo/public/cpp/application/application_test_base.h"
10 #include "services/dart/test/echo_service.mojom.h"
11
12 using mojo::String;
13
14 namespace dart {
15 namespace {
16
17 class DartEchoTest : public mojo::test::ApplicationTestBase {
18 public:
19 DartEchoTest() : ApplicationTestBase() {}
20 ~DartEchoTest() override {}
21
22 protected:
23 const std::string DartAppURL(const std::string& filename) {
24 base::FilePath path;
25 PathService::Get(base::DIR_SOURCE_ROOT, &path);
26 path = path.AppendASCII("services")
27 .AppendASCII("dart")
28 .AppendASCII("test")
29 .AppendASCII(filename);
30 return "file://" + path.AsUTF8Unsafe();
31 }
32
33 // ApplicationTestBase:
34 void SetUp() override {
35 ApplicationTestBase::SetUp();
36 const std::string& url = DartAppURL("echo.dart");
37 application_impl()->ConnectToService(url, &echo_service_);
38 }
39
40 mojo::EchoServicePtr echo_service_;
41
42 private:
43 MOJO_DISALLOW_COPY_AND_ASSIGN(DartEchoTest);
44 };
45
46 struct EchoStringCallback {
47 explicit EchoStringCallback(String *s) : echo_value(s) {}
48 void Run(const String& value) const {
49 *echo_value = value;
50 }
51 String *echo_value;
52 };
53
54 TEST_F(DartEchoTest, EchoString) {
55 String foo;
56 EchoStringCallback callback(&foo);
57 echo_service_->EchoString("foo", callback);
58 EXPECT_TRUE(echo_service_.WaitForIncomingMethodCall());
59 EXPECT_EQ("foo", foo);
60 echo_service_->EchoString("quit", callback);
61 EXPECT_TRUE(echo_service_.WaitForIncomingMethodCall());
62 EXPECT_EQ("quit", foo);
63 }
64
65 TEST_F(DartEchoTest, EchoEmptyString) {
66 String empty;
67 EchoStringCallback callback(&empty);
68 echo_service_->EchoString("", callback);
69 EXPECT_TRUE(echo_service_.WaitForIncomingMethodCall());
70 EXPECT_EQ("", empty);
71 echo_service_->EchoString("quit", callback);
72 EXPECT_TRUE(echo_service_.WaitForIncomingMethodCall());
73 EXPECT_EQ("quit", empty);
74 }
75
76 TEST_F(DartEchoTest, EchoNullString) {
77 String null;
78 EchoStringCallback callback(&null);
79 echo_service_->EchoString(nullptr, callback);
80 EXPECT_TRUE(echo_service_.WaitForIncomingMethodCall());
81 EXPECT_TRUE(null.is_null());
82 echo_service_->EchoString("quit", callback);
83 EXPECT_TRUE(echo_service_.WaitForIncomingMethodCall());
84 EXPECT_EQ("quit", null);
85 }
86
87 } // namespace
88 } // namespace dart
OLDNEW
« no previous file with comments | « services/dart/dart_app.cc ('k') | services/dart/lib/application.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698