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 249 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1461 size_t last_event = events_on_closed - 1; | 1477 size_t last_event = events_on_closed - 1; |
1462 for (uint32_t i = 1; i < last_event; ++i) { | 1478 for (uint32_t i = 1; i < last_event; ++i) { |
1463 ASSERT_EQ(WebSocketEvent::EVENT_MESSAGE, events[i].event_type); | 1479 ASSERT_EQ(WebSocketEvent::EVENT_MESSAGE, events[i].event_type); |
1464 ASSERT_TRUE(AreEqualWithString(events[i].var.pp_var(), message)); | 1480 ASSERT_TRUE(AreEqualWithString(events[i].var.pp_var(), message)); |
1465 } | 1481 } |
1466 ASSERT_EQ(WebSocketEvent::EVENT_CLOSE, events[last_event].event_type); | 1482 ASSERT_EQ(WebSocketEvent::EVENT_CLOSE, events[last_event].event_type); |
1467 ASSERT_TRUE(events[last_event].was_clean); | 1483 ASSERT_TRUE(events[last_event].was_clean); |
1468 | 1484 |
1469 PASS(); | 1485 PASS(); |
1470 } | 1486 } |
OLD | NEW |