OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "mojo/public/cpp/application/connect.h" | 5 #include "mojo/public/cpp/application/connect.h" |
6 #include "services/js/test/js_application_test_base.h" | 6 #include "services/js/test/js_application_test_base.h" |
7 #include "services/js/test/pingpong_service.mojom.h" | 7 #include "services/js/test/pingpong_service.mojom.h" |
8 | 8 |
9 namespace js { | 9 namespace js { |
10 namespace { | 10 namespace { |
(...skipping 28 matching lines...) Expand all Loading... |
39 class JSPingPongTest : public test::JSApplicationTestBase { | 39 class JSPingPongTest : public test::JSApplicationTestBase { |
40 public: | 40 public: |
41 JSPingPongTest() : JSApplicationTestBase() {} | 41 JSPingPongTest() : JSApplicationTestBase() {} |
42 ~JSPingPongTest() override {} | 42 ~JSPingPongTest() override {} |
43 | 43 |
44 protected: | 44 protected: |
45 // ApplicationTestBase: | 45 // ApplicationTestBase: |
46 void SetUp() override { | 46 void SetUp() override { |
47 ApplicationTestBase::SetUp(); | 47 ApplicationTestBase::SetUp(); |
48 const std::string& url = JSAppURL("pingpong.js"); | 48 const std::string& url = JSAppURL("pingpong.js"); |
49 mojo::ConnectToService(application_impl()->shell(), url, | 49 mojo::ConnectToService(shell(), url, GetProxy(&pingpong_service_)); |
50 GetProxy(&pingpong_service_)); | |
51 PingPongClientPtr client_ptr; | 50 PingPongClientPtr client_ptr; |
52 pingpong_client_.Bind(GetProxy(&client_ptr)); | 51 pingpong_client_.Bind(GetProxy(&client_ptr)); |
53 pingpong_service_->SetClient(client_ptr.Pass()); | 52 pingpong_service_->SetClient(client_ptr.Pass()); |
54 } | 53 } |
55 | 54 |
56 PingPongServicePtr pingpong_service_; | 55 PingPongServicePtr pingpong_service_; |
57 PingPongClientImpl pingpong_client_; | 56 PingPongClientImpl pingpong_client_; |
58 | 57 |
59 private: | 58 private: |
60 MOJO_DISALLOW_COPY_AND_ASSIGN(JSPingPongTest); | 59 MOJO_DISALLOW_COPY_AND_ASSIGN(JSPingPongTest); |
(...skipping 26 matching lines...) Expand all Loading... |
87 pingpong_service_->PingTargetURL(JSAppURL("pingpong_target.js"), 9, callback); | 86 pingpong_service_->PingTargetURL(JSAppURL("pingpong_target.js"), 9, callback); |
88 EXPECT_TRUE(pingpong_service_.WaitForIncomingResponse()); | 87 EXPECT_TRUE(pingpong_service_.WaitForIncomingResponse()); |
89 EXPECT_TRUE(returned_value); | 88 EXPECT_TRUE(returned_value); |
90 pingpong_service_->Quit(); | 89 pingpong_service_->Quit(); |
91 } | 90 } |
92 | 91 |
93 // Same as the previous test except that instead of providing the | 92 // Same as the previous test except that instead of providing the |
94 // pingpong-target.js URL, we provide a connection to its PingPongService. | 93 // pingpong-target.js URL, we provide a connection to its PingPongService. |
95 TEST_F(JSPingPongTest, PingTargetService) { | 94 TEST_F(JSPingPongTest, PingTargetService) { |
96 PingPongServicePtr target; | 95 PingPongServicePtr target; |
97 mojo::ConnectToService(application_impl()->shell(), | 96 mojo::ConnectToService(shell(), JSAppURL("pingpong_target.js"), |
98 JSAppURL("pingpong_target.js"), GetProxy(&target)); | 97 GetProxy(&target)); |
99 bool returned_value = false; | 98 bool returned_value = false; |
100 PingTargetCallback callback(&returned_value); | 99 PingTargetCallback callback(&returned_value); |
101 pingpong_service_->PingTargetService(target.Pass(), 9, callback); | 100 pingpong_service_->PingTargetService(target.Pass(), 9, callback); |
102 EXPECT_TRUE(pingpong_service_.WaitForIncomingResponse()); | 101 EXPECT_TRUE(pingpong_service_.WaitForIncomingResponse()); |
103 EXPECT_TRUE(returned_value); | 102 EXPECT_TRUE(returned_value); |
104 pingpong_service_->Quit(); | 103 pingpong_service_->Quit(); |
105 } | 104 } |
106 | 105 |
107 // Verify that JS can implement an interface& "request" parameter. | 106 // Verify that JS can implement an interface& "request" parameter. |
108 TEST_F(JSPingPongTest, GetTargetService) { | 107 TEST_F(JSPingPongTest, GetTargetService) { |
109 PingPongServicePtr target; | 108 PingPongServicePtr target; |
110 PingPongClientImpl client; | 109 PingPongClientImpl client; |
111 pingpong_service_->GetPingPongService(GetProxy(&target)); | 110 pingpong_service_->GetPingPongService(GetProxy(&target)); |
112 PingPongClientPtr client_ptr; | 111 PingPongClientPtr client_ptr; |
113 client.Bind(GetProxy(&client_ptr)); | 112 client.Bind(GetProxy(&client_ptr)); |
114 target->SetClient(client_ptr.Pass()); | 113 target->SetClient(client_ptr.Pass()); |
115 target->Ping(1); | 114 target->Ping(1); |
116 EXPECT_EQ(2, client.WaitForPongValue()); | 115 EXPECT_EQ(2, client.WaitForPongValue()); |
117 target->Ping(100); | 116 target->Ping(100); |
118 EXPECT_EQ(101, client.WaitForPongValue()); | 117 EXPECT_EQ(101, client.WaitForPongValue()); |
119 target->Quit(); | 118 target->Quit(); |
120 pingpong_service_->Quit(); | 119 pingpong_service_->Quit(); |
121 } | 120 } |
122 | 121 |
123 | 122 |
124 } // namespace | 123 } // namespace |
125 } // namespace js | 124 } // namespace js |
OLD | NEW |