| 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 1130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1141 ASSERT_EQ(PP_ERROR_BADARGUMENT, result); | 1141 ASSERT_EQ(PP_ERROR_BADARGUMENT, result); |
| 1142 ASSERT_EQ(0U, websocket.GetSeenEvents().size()); | 1142 ASSERT_EQ(0U, websocket.GetSeenEvents().size()); |
| 1143 | 1143 |
| 1144 result = websocket.Connect(pp::Var(), protocols, 1U); | 1144 result = websocket.Connect(pp::Var(), protocols, 1U); |
| 1145 ASSERT_EQ(PP_ERROR_INPROGRESS, result); | 1145 ASSERT_EQ(PP_ERROR_INPROGRESS, result); |
| 1146 ASSERT_EQ(0U, websocket.GetSeenEvents().size()); | 1146 ASSERT_EQ(0U, websocket.GetSeenEvents().size()); |
| 1147 | 1147 |
| 1148 for (int i = 0; kInvalidURLs[i]; ++i) { | 1148 for (int i = 0; kInvalidURLs[i]; ++i) { |
| 1149 TestWebSocketAPI ws(instance_); | 1149 TestWebSocketAPI ws(instance_); |
| 1150 result = ws.Connect(pp::Var(std::string(kInvalidURLs[i])), protocols, 0U); | 1150 result = ws.Connect(pp::Var(std::string(kInvalidURLs[i])), protocols, 0U); |
| 1151 ASSERT_EQ(PP_ERROR_BADARGUMENT, result); | 1151 if (result == PP_OK_COMPLETIONPENDING) { |
| 1152 ASSERT_EQ(0U, ws.GetSeenEvents().size()); | 1152 ws.WaitForClosed(); |
| 1153 const std::vector<WebSocketEvent>& events = ws.GetSeenEvents(); |
| 1154 ASSERT_EQ(WebSocketEvent::EVENT_ERROR, events[0].event_type); |
| 1155 ASSERT_EQ(WebSocketEvent::EVENT_CLOSE, events[1].event_type); |
| 1156 ASSERT_EQ(2U, ws.GetSeenEvents().size()); |
| 1157 } else { |
| 1158 ASSERT_EQ(PP_ERROR_BADARGUMENT, result); |
| 1159 ASSERT_EQ(0U, ws.GetSeenEvents().size()); |
| 1160 } |
| 1153 } | 1161 } |
| 1154 | 1162 |
| 1155 PASS(); | 1163 PASS(); |
| 1156 } | 1164 } |
| 1157 | 1165 |
| 1158 std::string TestWebSocket::TestUtilityProtocols() { | 1166 std::string TestWebSocket::TestUtilityProtocols() { |
| 1159 const pp::Var bad_protocols[] = { | 1167 const pp::Var bad_protocols[] = { |
| 1160 pp::Var(std::string("x-test")), pp::Var(std::string("x-test")) }; | 1168 pp::Var(std::string("x-test")), pp::Var(std::string("x-test")) }; |
| 1161 const pp::Var good_protocols[] = { | 1169 const pp::Var good_protocols[] = { |
| 1162 pp::Var(std::string("x-test")), pp::Var(std::string("x-yatest")) }; | 1170 pp::Var(std::string("x-test")), pp::Var(std::string("x-yatest")) }; |
| (...skipping 25 matching lines...) Expand all Loading... |
| 1188 PASS(); | 1196 PASS(); |
| 1189 } | 1197 } |
| 1190 | 1198 |
| 1191 std::string TestWebSocket::TestUtilityGetURL() { | 1199 std::string TestWebSocket::TestUtilityGetURL() { |
| 1192 const pp::Var protocols[] = { pp::Var() }; | 1200 const pp::Var protocols[] = { pp::Var() }; |
| 1193 | 1201 |
| 1194 for (int i = 0; kInvalidURLs[i]; ++i) { | 1202 for (int i = 0; kInvalidURLs[i]; ++i) { |
| 1195 TestWebSocketAPI websocket(instance_); | 1203 TestWebSocketAPI websocket(instance_); |
| 1196 int32_t result = websocket.Connect( | 1204 int32_t result = websocket.Connect( |
| 1197 pp::Var(std::string(kInvalidURLs[i])), protocols, 0U); | 1205 pp::Var(std::string(kInvalidURLs[i])), protocols, 0U); |
| 1198 ASSERT_EQ(PP_ERROR_BADARGUMENT, result); | 1206 if (result == PP_OK_COMPLETIONPENDING) { |
| 1207 websocket.WaitForClosed(); |
| 1208 const std::vector<WebSocketEvent>& events = websocket.GetSeenEvents(); |
| 1209 ASSERT_EQ(WebSocketEvent::EVENT_ERROR, events[0].event_type); |
| 1210 ASSERT_EQ(WebSocketEvent::EVENT_CLOSE, events[1].event_type); |
| 1211 ASSERT_EQ(2U, events.size()); |
| 1212 } else { |
| 1213 ASSERT_EQ(PP_ERROR_BADARGUMENT, result); |
| 1214 ASSERT_EQ(0U, websocket.GetSeenEvents().size()); |
| 1215 } |
| 1199 pp::Var url = websocket.GetURL(); | 1216 pp::Var url = websocket.GetURL(); |
| 1200 ASSERT_TRUE(AreEqualWithString(url.pp_var(), kInvalidURLs[i])); | 1217 ASSERT_TRUE(AreEqualWithString(url.pp_var(), kInvalidURLs[i])); |
| 1201 ASSERT_EQ(0U, websocket.GetSeenEvents().size()); | |
| 1202 } | 1218 } |
| 1203 | 1219 |
| 1204 PASS(); | 1220 PASS(); |
| 1205 } | 1221 } |
| 1206 | 1222 |
| 1207 std::string TestWebSocket::TestUtilityValidConnect() { | 1223 std::string TestWebSocket::TestUtilityValidConnect() { |
| 1208 const pp::Var protocols[] = { pp::Var() }; | 1224 const pp::Var protocols[] = { pp::Var() }; |
| 1209 TestWebSocketAPI websocket(instance_); | 1225 TestWebSocketAPI websocket(instance_); |
| 1210 int32_t result = websocket.Connect( | 1226 int32_t result = websocket.Connect( |
| 1211 pp::Var(GetFullURL(kEchoServerURL)), protocols, 0U); | 1227 pp::Var(GetFullURL(kEchoServerURL)), protocols, 0U); |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1330 ASSERT_TRUE(AreEqualWithString( | 1346 ASSERT_TRUE(AreEqualWithString( |
| 1331 websocket.GetProtocol().pp_var(), protocol.c_str())); | 1347 websocket.GetProtocol().pp_var(), protocol.c_str())); |
| 1332 const std::vector<WebSocketEvent>& events = websocket.GetSeenEvents(); | 1348 const std::vector<WebSocketEvent>& events = websocket.GetSeenEvents(); |
| 1333 // The server to which this test connect returns the decided protocol as a | 1349 // The server to which this test connect returns the decided protocol as a |
| 1334 // text frame message. So the WebSocketEvent records EVENT_MESSAGE event | 1350 // text frame message. So the WebSocketEvent records EVENT_MESSAGE event |
| 1335 // after EVENT_OPEN event. | 1351 // after EVENT_OPEN event. |
| 1336 ASSERT_EQ(2U, events.size()); | 1352 ASSERT_EQ(2U, events.size()); |
| 1337 ASSERT_EQ(WebSocketEvent::EVENT_OPEN, events[0].event_type); | 1353 ASSERT_EQ(WebSocketEvent::EVENT_OPEN, events[0].event_type); |
| 1338 ASSERT_EQ(WebSocketEvent::EVENT_MESSAGE, events[1].event_type); | 1354 ASSERT_EQ(WebSocketEvent::EVENT_MESSAGE, events[1].event_type); |
| 1339 ASSERT_TRUE(AreEqualWithString(events[1].var.pp_var(), protocol.c_str())); | 1355 ASSERT_TRUE(AreEqualWithString(events[1].var.pp_var(), protocol.c_str())); |
| 1340 ASSERT_TRUE(events[1].was_clean); | |
| 1341 | 1356 |
| 1342 PASS(); | 1357 PASS(); |
| 1343 } | 1358 } |
| 1344 | 1359 |
| 1345 std::string TestWebSocket::TestUtilityTextSendReceive() { | 1360 std::string TestWebSocket::TestUtilityTextSendReceive() { |
| 1346 const pp::Var protocols[] = { pp::Var() }; | 1361 const pp::Var protocols[] = { pp::Var() }; |
| 1347 TestWebSocketAPI websocket(instance_); | 1362 TestWebSocketAPI websocket(instance_); |
| 1348 int32_t result = | 1363 int32_t result = |
| 1349 websocket.Connect(pp::Var(GetFullURL(kEchoServerURL)), protocols, 0U); | 1364 websocket.Connect(pp::Var(GetFullURL(kEchoServerURL)), protocols, 0U); |
| 1350 ASSERT_EQ(PP_OK_COMPLETIONPENDING, result); | 1365 ASSERT_EQ(PP_OK_COMPLETIONPENDING, result); |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1461 size_t last_event = events_on_closed - 1; | 1476 size_t last_event = events_on_closed - 1; |
| 1462 for (uint32_t i = 1; i < last_event; ++i) { | 1477 for (uint32_t i = 1; i < last_event; ++i) { |
| 1463 ASSERT_EQ(WebSocketEvent::EVENT_MESSAGE, events[i].event_type); | 1478 ASSERT_EQ(WebSocketEvent::EVENT_MESSAGE, events[i].event_type); |
| 1464 ASSERT_TRUE(AreEqualWithString(events[i].var.pp_var(), message)); | 1479 ASSERT_TRUE(AreEqualWithString(events[i].var.pp_var(), message)); |
| 1465 } | 1480 } |
| 1466 ASSERT_EQ(WebSocketEvent::EVENT_CLOSE, events[last_event].event_type); | 1481 ASSERT_EQ(WebSocketEvent::EVENT_CLOSE, events[last_event].event_type); |
| 1467 ASSERT_TRUE(events[last_event].was_clean); | 1482 ASSERT_TRUE(events[last_event].was_clean); |
| 1468 | 1483 |
| 1469 PASS(); | 1484 PASS(); |
| 1470 } | 1485 } |
| OLD | NEW |