OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "ppapi/tests/test_websocket.h" | 5 #include "ppapi/tests/test_websocket.h" |
6 | 6 |
7 #include <stdio.h> | 7 #include <stdio.h> |
8 #include <string.h> | 8 #include <string.h> |
9 | 9 |
10 #include <algorithm> | 10 #include <algorithm> |
(...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
217 RUN_TEST_WITH_REFERENCE_CHECK(BinarySendReceive, filter); | 217 RUN_TEST_WITH_REFERENCE_CHECK(BinarySendReceive, filter); |
218 RUN_TEST_WITH_REFERENCE_CHECK(StressedSendReceive, filter); | 218 RUN_TEST_WITH_REFERENCE_CHECK(StressedSendReceive, filter); |
219 RUN_TEST_WITH_REFERENCE_CHECK(BufferedAmount, filter); | 219 RUN_TEST_WITH_REFERENCE_CHECK(BufferedAmount, filter); |
220 // PP_Resource for WebSocket may be released later because of an internal | 220 // PP_Resource for WebSocket may be released later because of an internal |
221 // reference for asynchronous IPC handling. So, suppress reference check on | 221 // reference for asynchronous IPC handling. So, suppress reference check on |
222 // the following AbortCallsWithCallback test. | 222 // the following AbortCallsWithCallback test. |
223 RUN_TEST(AbortCallsWithCallback, filter); | 223 RUN_TEST(AbortCallsWithCallback, filter); |
224 RUN_TEST_WITH_REFERENCE_CHECK(AbortSendMessageCall, filter); | 224 RUN_TEST_WITH_REFERENCE_CHECK(AbortSendMessageCall, filter); |
225 RUN_TEST_WITH_REFERENCE_CHECK(AbortCloseCall, filter); | 225 RUN_TEST_WITH_REFERENCE_CHECK(AbortCloseCall, filter); |
226 RUN_TEST_WITH_REFERENCE_CHECK(AbortReceiveMessageCall, filter); | 226 RUN_TEST_WITH_REFERENCE_CHECK(AbortReceiveMessageCall, filter); |
227 RUN_TEST_WITH_REFERENCE_CHECK(ClosedFromServerWhileSending, filter); | |
227 | 228 |
228 RUN_TEST_WITH_REFERENCE_CHECK(CcInterfaces, filter); | 229 RUN_TEST_WITH_REFERENCE_CHECK(CcInterfaces, filter); |
229 | 230 |
230 RUN_TEST_WITH_REFERENCE_CHECK(UtilityInvalidConnect, filter); | 231 RUN_TEST_WITH_REFERENCE_CHECK(UtilityInvalidConnect, filter); |
231 RUN_TEST_WITH_REFERENCE_CHECK(UtilityProtocols, filter); | 232 RUN_TEST_WITH_REFERENCE_CHECK(UtilityProtocols, filter); |
232 RUN_TEST_WITH_REFERENCE_CHECK(UtilityGetURL, filter); | 233 RUN_TEST_WITH_REFERENCE_CHECK(UtilityGetURL, filter); |
233 RUN_TEST_WITH_REFERENCE_CHECK(UtilityValidConnect, filter); | 234 RUN_TEST_WITH_REFERENCE_CHECK(UtilityValidConnect, filter); |
234 RUN_TEST_WITH_REFERENCE_CHECK(UtilityInvalidClose, filter); | 235 RUN_TEST_WITH_REFERENCE_CHECK(UtilityInvalidClose, filter); |
235 RUN_TEST_WITH_REFERENCE_CHECK(UtilityValidClose, filter); | 236 RUN_TEST_WITH_REFERENCE_CHECK(UtilityValidClose, filter); |
236 RUN_TEST_WITH_REFERENCE_CHECK(UtilityGetProtocol, filter); | 237 RUN_TEST_WITH_REFERENCE_CHECK(UtilityGetProtocol, filter); |
(...skipping 914 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1151 ASSERT_EQ(PP_ERROR_ABORTED, callback.result()); | 1152 ASSERT_EQ(PP_ERROR_ABORTED, callback.result()); |
1152 } | 1153 } |
1153 } | 1154 } |
1154 | 1155 |
1155 ReleaseVar(large_var); | 1156 ReleaseVar(large_var); |
1156 ReleaseVar(text_var); | 1157 ReleaseVar(text_var); |
1157 | 1158 |
1158 PASS(); | 1159 PASS(); |
1159 } | 1160 } |
1160 | 1161 |
1162 std::string TestWebSocket::TestClosedFromServerWhileSending() { | |
1163 // Connect to test echo server. | |
1164 const pp::Var protocols[] = { pp::Var() }; | |
1165 TestWebSocketAPI websocket(instance_); | |
1166 int32_t result = | |
1167 websocket.Connect(pp::Var(GetFullURL(kEchoServerURL)), protocols, 0U); | |
1168 ASSERT_EQ(PP_OK_COMPLETIONPENDING, result); | |
1169 websocket.WaitForConnected(); | |
1170 | |
1171 result = websocket.Send(pp::Var("hello")); | |
1172 ASSERT_EQ(PP_OK, result); | |
1173 result = websocket.Send(pp::Var("Goodbye")); | |
1174 // We send many messages so that PepperWebSocketHost::SendText is called | |
1175 // after PepperWebSocketHost::didClose is called. | |
1176 // Note: We must not wait for CLOSED event here because | |
1177 // WebSocketResource::SendMessage doesn't call PepperWebSocketHost::SendText | |
1178 // when its internal state is CLOSING or CLOSED. We want to test if the | |
1179 // pepper WebSocket works well when WebSocketResource is OPEN and | |
1180 // PepperWebSocketHost is CLOSED. | |
1181 for (size_t i = 0; i < 10000; ++i) { | |
Adam Rice
2014/08/27 05:58:57
Nit: this test could be flaky. However, I can't se
yhirano
2014/08/27 07:06:32
me neither.
| |
1182 result = websocket.Send(pp::Var("")); | |
1183 ASSERT_EQ(PP_OK, result); | |
1184 } | |
1185 | |
1186 PASS(); | |
1187 } | |
1188 | |
1161 std::string TestWebSocket::TestCcInterfaces() { | 1189 std::string TestWebSocket::TestCcInterfaces() { |
1162 // C++ bindings is simple straightforward, then just verifies interfaces work | 1190 // C++ bindings is simple straightforward, then just verifies interfaces work |
1163 // as a interface bridge fine. | 1191 // as a interface bridge fine. |
1164 pp::WebSocket ws(instance_); | 1192 pp::WebSocket ws(instance_); |
1165 | 1193 |
1166 // Check uninitialized properties access. | 1194 // Check uninitialized properties access. |
1167 ASSERT_EQ(0, ws.GetBufferedAmount()); | 1195 ASSERT_EQ(0, ws.GetBufferedAmount()); |
1168 ASSERT_EQ(0, ws.GetCloseCode()); | 1196 ASSERT_EQ(0, ws.GetCloseCode()); |
1169 ASSERT_TRUE(AreEqualWithString(ws.GetCloseReason().pp_var(), std::string())); | 1197 ASSERT_TRUE(AreEqualWithString(ws.GetCloseReason().pp_var(), std::string())); |
1170 ASSERT_FALSE(ws.GetCloseWasClean()); | 1198 ASSERT_FALSE(ws.GetCloseWasClean()); |
(...skipping 408 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1579 size_t last_event = events_on_closed - 1; | 1607 size_t last_event = events_on_closed - 1; |
1580 for (uint32_t i = 1; i < last_event; ++i) { | 1608 for (uint32_t i = 1; i < last_event; ++i) { |
1581 ASSERT_EQ(WebSocketEvent::EVENT_MESSAGE, events[i].event_type); | 1609 ASSERT_EQ(WebSocketEvent::EVENT_MESSAGE, events[i].event_type); |
1582 ASSERT_TRUE(AreEqualWithString(events[i].var.pp_var(), message)); | 1610 ASSERT_TRUE(AreEqualWithString(events[i].var.pp_var(), message)); |
1583 } | 1611 } |
1584 ASSERT_EQ(WebSocketEvent::EVENT_CLOSE, events[last_event].event_type); | 1612 ASSERT_EQ(WebSocketEvent::EVENT_CLOSE, events[last_event].event_type); |
1585 ASSERT_TRUE(events[last_event].was_clean); | 1613 ASSERT_TRUE(events[last_event].was_clean); |
1586 | 1614 |
1587 PASS(); | 1615 PASS(); |
1588 } | 1616 } |
OLD | NEW |