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

Side by Side Diff: services/dart/pingpong_apptest.cc

Issue 971083002: Create an apptesting framework for dart. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Update upload_binaries.py to add the apptest.dartzip artifact. Created 5 years, 9 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
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 "mojo/public/cpp/bindings/strong_binding.h"
11 #include "services/dart/test/pingpong_service.mojom.h"
12
13 namespace dart {
14 namespace {
15
16 class PingPongClientImpl : public PingPongClient {
17 public:
18 PingPongClientImpl(mojo::InterfaceRequest<PingPongClient> request)
19 : last_pong_value_(0), binding_(this, request.Pass()) {}
20 ~PingPongClientImpl() override {}
21
22 int16_t WaitForPongValue() {
23 if (!binding_.WaitForIncomingMethodCall())
24 return 0;
25 return last_pong_value_;
26 }
27
28 private:
29 // PingPongClient overrides.
30 void Pong(uint16_t pong_value) override {
31 last_pong_value_ = pong_value;
32 }
33
34 int16_t last_pong_value_;
35 mojo::StrongBinding<PingPongClient> binding_;
36 MOJO_DISALLOW_COPY_AND_ASSIGN(PingPongClientImpl);
37 };
38
39 class DartPingPongTest : public mojo::test::ApplicationTestBase {
40 public:
41 DartPingPongTest() : mojo::test::ApplicationTestBase() {}
42 ~DartPingPongTest() override {}
43
44 protected:
45 // ApplicationTestBase:
46 void SetUp() override {
47 ApplicationTestBase::SetUp();
48 application_impl()->ConnectToService("mojo:dart_pingpong",
49 &pingpong_service_);
50 }
51
52 PingPongServicePtr pingpong_service_;
53
54 private:
55 MOJO_DISALLOW_COPY_AND_ASSIGN(DartPingPongTest);
56 };
57
58 struct PingTargetCallback {
59 explicit PingTargetCallback(bool *b) : value(b) {}
60 void Run(bool callback_value) const {
61 *value = callback_value;
62 }
63 bool *value;
64 };
65
66 // Verify that "pingpong.dart" implements the PingPongService interface
67 // and sends responses to our client.
68 TEST_F(DartPingPongTest, PingServiceToPongClient) {
69 PingPongClientPtr client;
70 auto pingpong_client = new PingPongClientImpl(GetProxy(&client));
71 pingpong_service_->SetClient(client.Pass());
72
73 pingpong_service_->Ping(1);
74 EXPECT_EQ(2, pingpong_client->WaitForPongValue());
75 pingpong_service_->Ping(100);
76 EXPECT_EQ(101, pingpong_client->WaitForPongValue());
77 pingpong_service_->Quit();
78 }
79
80 // Verify that "pingpong.dart" can connect to "pingpong_target.dart", act as
81 // its client, and return a Future that only resolves after the target.ping()
82 // => client.pong() methods have executed 9 times.
83 TEST_F(DartPingPongTest, PingTargetURL) {
84 bool returned_value = false;
85 PingTargetCallback callback(&returned_value);
86 pingpong_service_->PingTargetURL("mojo:dart_pingpong_target", 9, callback);
87 EXPECT_TRUE(pingpong_service_.WaitForIncomingMethodCall());
88 EXPECT_TRUE(returned_value);
89 pingpong_service_->Quit();
90 }
91
92 // Same as the previous test except that instead of providing the
93 // pingpong_target.dart URL, we provide a connection to its PingPongService.
94 TEST_F(DartPingPongTest, PingTargetService) {
95 PingPongServicePtr target;
96 application_impl()->ConnectToService("mojo:dart_pingpong_target", &target);
97 bool returned_value = false;
98 PingTargetCallback callback(&returned_value);
99 pingpong_service_->PingTargetService(target.Pass(), 9, callback);
100 EXPECT_TRUE(pingpong_service_.WaitForIncomingMethodCall());
101 EXPECT_TRUE(returned_value);
102 pingpong_service_->Quit();
103 }
104
105 // Verify that Dart can implement an interface "request" parameter.
106 TEST_F(DartPingPongTest, GetTargetService) {
107 PingPongServicePtr target;
108 PingPongClientPtr client;
109 auto pingpong_client = new PingPongClientImpl(GetProxy(&client));
110
111 pingpong_service_->GetPingPongService(GetProxy(&target));
112 target->SetClient(client.Pass());
113
114 target->Ping(1);
115 EXPECT_EQ(2, pingpong_client->WaitForPongValue());
116 target->Ping(100);
117 EXPECT_EQ(101, pingpong_client->WaitForPongValue());
118 target->Quit();
119 pingpong_service_->Quit();
120 }
121
122 } // namespace
123 } // namespace dart
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698