| 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 484 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 495 PP_Var send_message_var = CreateVarString(send_message); | 495 PP_Var send_message_var = CreateVarString(send_message); |
| 496 result = websocket_interface_->SendMessage(ws, send_message_var); | 496 result = websocket_interface_->SendMessage(ws, send_message_var); |
| 497 ReleaseVar(send_message_var); | 497 ReleaseVar(send_message_var); |
| 498 ASSERT_EQ(PP_OK, result); | 498 ASSERT_EQ(PP_OK, result); |
| 499 result = callback.WaitForResult(); | 499 result = callback.WaitForResult(); |
| 500 ASSERT_EQ(PP_OK, result); | 500 ASSERT_EQ(PP_OK, result); |
| 501 ASSERT_TRUE(AreEqualWithString(receive_message_var, send_message)); | 501 ASSERT_TRUE(AreEqualWithString(receive_message_var, send_message)); |
| 502 ReleaseVar(receive_message_var); | 502 ReleaseVar(receive_message_var); |
| 503 core_interface_->ReleaseResource(ws); | 503 core_interface_->ReleaseResource(ws); |
| 504 | 504 |
| 505 // Close twice. |
| 506 ws = Connect(GetFullURL(kEchoServerURL), &result, ""); |
| 507 ASSERT_TRUE(ws); |
| 508 ASSERT_EQ(PP_OK, result); |
| 509 result = websocket_interface_->Close(ws, |
| 510 PP_WEBSOCKETSTATUSCODE_NORMAL_CLOSURE, reason, |
| 511 callback.GetCallback().pp_completion_callback()); |
| 512 ASSERT_EQ(PP_OK_COMPLETIONPENDING, result); |
| 513 // Call another Close() before previous one is in progress. |
| 514 result = websocket_interface_->Close(ws, |
| 515 PP_WEBSOCKETSTATUSCODE_NORMAL_CLOSURE, reason, |
| 516 another_callback.GetCallback().pp_completion_callback()); |
| 517 ASSERT_EQ(PP_ERROR_INPROGRESS, result); |
| 518 result = callback.WaitForResult(); |
| 519 ASSERT_EQ(PP_OK, result); |
| 520 // Call another Close() after previous one is completed. |
| 521 // This Close() must do nothing and reports no error. |
| 522 result = websocket_interface_->Close(ws, |
| 523 PP_WEBSOCKETSTATUSCODE_NORMAL_CLOSURE, reason, |
| 524 callback.GetCallback().pp_completion_callback()); |
| 525 if (result == PP_OK_COMPLETIONPENDING) |
| 526 result = callback.WaitForResult(); |
| 527 ASSERT_EQ(PP_OK, result); |
| 528 core_interface_->ReleaseResource(ws); |
| 529 |
| 505 ReleaseVar(reason); | 530 ReleaseVar(reason); |
| 506 | 531 |
| 507 PASS(); | 532 PASS(); |
| 508 } | 533 } |
| 509 | 534 |
| 510 std::string TestWebSocket::TestValidClose() { | 535 std::string TestWebSocket::TestValidClose() { |
| 511 PP_Var reason = CreateVarString("close for test"); | 536 PP_Var reason = CreateVarString("close for test"); |
| 512 PP_Var url = CreateVarString(GetFullURL(kEchoServerURL).c_str()); | 537 PP_Var url = CreateVarString(GetFullURL(kEchoServerURL).c_str()); |
| 513 PP_Var protocols[] = { PP_MakeUndefined() }; | 538 PP_Var protocols[] = { PP_MakeUndefined() }; |
| 514 TestCompletionCallback callback(instance_->pp_instance()); | 539 TestCompletionCallback callback(instance_->pp_instance()); |
| (...skipping 852 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1367 size_t last_event = events_on_closed - 1; | 1392 size_t last_event = events_on_closed - 1; |
| 1368 for (uint32_t i = 1; i < last_event; ++i) { | 1393 for (uint32_t i = 1; i < last_event; ++i) { |
| 1369 ASSERT_EQ(WebSocketEvent::EVENT_MESSAGE, events[i].event_type); | 1394 ASSERT_EQ(WebSocketEvent::EVENT_MESSAGE, events[i].event_type); |
| 1370 ASSERT_TRUE(AreEqualWithString(events[i].var.pp_var(), message)); | 1395 ASSERT_TRUE(AreEqualWithString(events[i].var.pp_var(), message)); |
| 1371 } | 1396 } |
| 1372 ASSERT_EQ(WebSocketEvent::EVENT_CLOSE, events[last_event].event_type); | 1397 ASSERT_EQ(WebSocketEvent::EVENT_CLOSE, events[last_event].event_type); |
| 1373 ASSERT_TRUE(events[last_event].was_clean); | 1398 ASSERT_TRUE(events[last_event].was_clean); |
| 1374 | 1399 |
| 1375 PASS(); | 1400 PASS(); |
| 1376 } | 1401 } |
| OLD | NEW |