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 432 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
443 PP_Var extensions = websocket_interface_->GetExtensions(ws); | 443 PP_Var extensions = websocket_interface_->GetExtensions(ws); |
444 ASSERT_TRUE(AreEqualWithString(extensions, "")); | 444 ASSERT_TRUE(AreEqualWithString(extensions, "")); |
445 core_interface_->ReleaseResource(ws); | 445 core_interface_->ReleaseResource(ws); |
446 | 446 |
447 PASS(); | 447 PASS(); |
448 } | 448 } |
449 | 449 |
450 std::string TestWebSocket::TestInvalidClose() { | 450 std::string TestWebSocket::TestInvalidClose() { |
451 PP_Var reason = CreateVarString("close for test"); | 451 PP_Var reason = CreateVarString("close for test"); |
452 TestCompletionCallback callback(instance_->pp_instance()); | 452 TestCompletionCallback callback(instance_->pp_instance()); |
453 TestCompletionCallback another_callback(instance_->pp_instance()); | |
453 | 454 |
454 // Close before connect. | 455 // Close before connect. |
455 PP_Resource ws = websocket_interface_->Create(instance_->pp_instance()); | 456 PP_Resource ws = websocket_interface_->Create(instance_->pp_instance()); |
456 int32_t result = websocket_interface_->Close( | 457 int32_t result = websocket_interface_->Close(ws, |
457 ws, PP_WEBSOCKETSTATUSCODE_NORMAL_CLOSURE, reason, | 458 PP_WEBSOCKETSTATUSCODE_NORMAL_CLOSURE, reason, |
458 callback.GetCallback().pp_completion_callback()); | 459 callback.GetCallback().pp_completion_callback()); |
459 ASSERT_EQ(PP_ERROR_FAILED, result); | 460 ASSERT_EQ(PP_ERROR_FAILED, result); |
460 core_interface_->ReleaseResource(ws); | 461 core_interface_->ReleaseResource(ws); |
461 | 462 |
462 // Close with bad arguments. | 463 // Close with bad arguments. |
463 ws = Connect(GetFullURL(kEchoServerURL), &result, ""); | 464 ws = Connect(GetFullURL(kEchoServerURL), &result, ""); |
464 ASSERT_TRUE(ws); | 465 ASSERT_TRUE(ws); |
465 ASSERT_EQ(PP_OK, result); | 466 ASSERT_EQ(PP_OK, result); |
466 result = websocket_interface_->Close(ws, 1U, reason, | 467 result = websocket_interface_->Close(ws, 1U, reason, |
467 callback.GetCallback().pp_completion_callback()); | 468 callback.GetCallback().pp_completion_callback()); |
468 ASSERT_EQ(PP_ERROR_NOACCESS, result); | 469 ASSERT_EQ(PP_ERROR_NOACCESS, result); |
469 core_interface_->ReleaseResource(ws); | 470 core_interface_->ReleaseResource(ws); |
470 | 471 |
472 // Close with PP_VARTYPE_NULL. | |
473 ws = Connect(GetFullURL(kEchoServerURL), &result, ""); | |
474 ASSERT_TRUE(ws); | |
475 ASSERT_EQ(PP_OK, result); | |
476 result = websocket_interface_->Close(ws, | |
477 PP_WEBSOCKETSTATUSCODE_NORMAL_CLOSURE, PP_MakeNull(), | |
478 callback.GetCallback().pp_completion_callback()); | |
479 ASSERT_EQ(PP_ERROR_BADARGUMENT, result); | |
480 core_interface_->ReleaseResource(ws); | |
481 | |
482 // Close with PP_VARTYPE_NULL and ongoing receive message. | |
483 ws = Connect(GetFullURL(kEchoServerURL), &result, ""); | |
484 ASSERT_TRUE(ws); | |
485 ASSERT_EQ(PP_OK, result); | |
486 PP_Var receive_message_var; | |
487 result = websocket_interface_->ReceiveMessage(ws, &receive_message_var, | |
488 callback.GetCallback().pp_completion_callback()); | |
489 ASSERT_EQ(PP_OK_COMPLETIONPENDING, result); | |
490 result = websocket_interface_->Close(ws, | |
491 PP_WEBSOCKETSTATUSCODE_NORMAL_CLOSURE, PP_MakeNull(), | |
492 another_callback.GetCallback().pp_completion_callback()); | |
493 ASSERT_EQ(PP_ERROR_BADARGUMENT, result); | |
494 const char* send_message = "hi"; | |
495 PP_Var send_message_var = CreateVarString(send_message); | |
496 result = websocket_interface_->SendMessage(ws, send_message_var); | |
497 ReleaseVar(send_message_var); | |
498 ASSERT_EQ(PP_OK, result); | |
499 result = callback.WaitForResult(); | |
500 ASSERT_EQ(PP_OK, result); | |
501 ASSERT_TRUE(AreEqualWithString(receive_message_var, send_message)); | |
502 ReleaseVar(receive_message_var); | |
503 core_interface_->ReleaseResource(ws); | |
504 | |
471 ReleaseVar(reason); | 505 ReleaseVar(reason); |
472 | 506 |
473 PASS(); | 507 PASS(); |
474 } | 508 } |
475 | 509 |
476 std::string TestWebSocket::TestValidClose() { | 510 std::string TestWebSocket::TestValidClose() { |
477 PP_Var reason = CreateVarString("close for test"); | 511 PP_Var reason = CreateVarString("close for test"); |
478 PP_Var url = CreateVarString(GetFullURL(kEchoServerURL).c_str()); | 512 PP_Var url = CreateVarString(GetFullURL(kEchoServerURL).c_str()); |
479 PP_Var protocols[] = { PP_MakeUndefined() }; | 513 PP_Var protocols[] = { PP_MakeUndefined() }; |
480 TestCompletionCallback callback(instance_->pp_instance()); | 514 TestCompletionCallback callback(instance_->pp_instance()); |
481 TestCompletionCallback another_callback(instance_->pp_instance()); | 515 TestCompletionCallback another_callback(instance_->pp_instance()); |
482 | 516 |
483 // Close. | 517 // Close. |
484 int32_t result; | 518 int32_t result; |
485 PP_Resource ws = Connect(GetFullURL(kEchoServerURL), &result, ""); | 519 PP_Resource ws = Connect(GetFullURL(kEchoServerURL), &result, ""); |
486 ASSERT_TRUE(ws); | 520 ASSERT_TRUE(ws); |
487 ASSERT_EQ(PP_OK, result); | 521 ASSERT_EQ(PP_OK, result); |
488 result = websocket_interface_->Close(ws, | 522 result = websocket_interface_->Close(ws, |
489 PP_WEBSOCKETSTATUSCODE_NORMAL_CLOSURE, reason, | 523 PP_WEBSOCKETSTATUSCODE_NORMAL_CLOSURE, reason, |
490 callback.GetCallback().pp_completion_callback()); | 524 callback.GetCallback().pp_completion_callback()); |
491 ASSERT_EQ(PP_OK_COMPLETIONPENDING, result); | 525 ASSERT_EQ(PP_OK_COMPLETIONPENDING, result); |
492 result = callback.WaitForResult(); | 526 result = callback.WaitForResult(); |
493 ASSERT_EQ(PP_OK, result); | 527 ASSERT_EQ(PP_OK, result); |
494 core_interface_->ReleaseResource(ws); | 528 core_interface_->ReleaseResource(ws); |
495 | 529 |
530 // Close with PP_VARTYPE_UNDEFINED. | |
531 ws = Connect(GetFullURL(kEchoServerURL), &result, ""); | |
532 ASSERT_TRUE(ws); | |
533 ASSERT_EQ(PP_OK, result); | |
534 result = websocket_interface_->Close(ws, | |
535 PP_WEBSOCKETSTATUSCODE_NORMAL_CLOSURE, PP_MakeUndefined(), | |
dmichael (off chromium)
2012/04/23 15:14:46
For what it's worth, I don't think supporting Unde
Takashi Toyoshima
2012/04/24 06:44:57
Actually, code and reason arguments are optional n
| |
536 callback.GetCallback().pp_completion_callback()); | |
537 ASSERT_EQ(PP_OK_COMPLETIONPENDING, result); | |
538 result = callback.WaitForResult(); | |
539 ASSERT_EQ(PP_OK, result); | |
540 core_interface_->ReleaseResource(ws); | |
541 | |
496 // Close in connecting. | 542 // Close in connecting. |
497 // The ongoing connect failed with PP_ERROR_ABORTED, then the close is done | 543 // The ongoing connect failed with PP_ERROR_ABORTED, then the close is done |
498 // successfully. | 544 // successfully. |
499 ws = websocket_interface_->Create(instance_->pp_instance()); | 545 ws = websocket_interface_->Create(instance_->pp_instance()); |
500 result = websocket_interface_->Connect(ws, url, protocols, 0U, | 546 result = websocket_interface_->Connect(ws, url, protocols, 0U, |
501 callback.GetCallback().pp_completion_callback()); | 547 callback.GetCallback().pp_completion_callback()); |
502 ASSERT_EQ(PP_OK_COMPLETIONPENDING, result); | 548 ASSERT_EQ(PP_OK_COMPLETIONPENDING, result); |
503 result = websocket_interface_->Close(ws, | 549 result = websocket_interface_->Close(ws, |
504 PP_WEBSOCKETSTATUSCODE_NORMAL_CLOSURE, reason, | 550 PP_WEBSOCKETSTATUSCODE_NORMAL_CLOSURE, reason, |
505 another_callback.GetCallback().pp_completion_callback()); | 551 another_callback.GetCallback().pp_completion_callback()); |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
539 result = websocket_interface_->Close(ws, | 585 result = websocket_interface_->Close(ws, |
540 PP_WEBSOCKETSTATUSCODE_NORMAL_CLOSURE, reason, | 586 PP_WEBSOCKETSTATUSCODE_NORMAL_CLOSURE, reason, |
541 another_callback.GetCallback().pp_completion_callback()); | 587 another_callback.GetCallback().pp_completion_callback()); |
542 ASSERT_EQ(PP_OK_COMPLETIONPENDING, result); | 588 ASSERT_EQ(PP_OK_COMPLETIONPENDING, result); |
543 result = callback.WaitForResult(); | 589 result = callback.WaitForResult(); |
544 ASSERT_EQ(PP_ERROR_ABORTED, result); | 590 ASSERT_EQ(PP_ERROR_ABORTED, result); |
545 result = another_callback.WaitForResult(); | 591 result = another_callback.WaitForResult(); |
546 ASSERT_EQ(PP_OK, result); | 592 ASSERT_EQ(PP_OK, result); |
547 core_interface_->ReleaseResource(ws); | 593 core_interface_->ReleaseResource(ws); |
548 | 594 |
595 // Close with PP_VARTYPE_UNDEFINED and ongoing receive message. | |
596 ws = Connect(GetFullURL(kEchoServerURL), &result, ""); | |
597 ASSERT_TRUE(ws); | |
598 ASSERT_EQ(PP_OK, result); | |
599 result = websocket_interface_->ReceiveMessage(ws, &receive_message_var, | |
600 callback.GetCallback().pp_completion_callback()); | |
601 ASSERT_EQ(PP_OK_COMPLETIONPENDING, result); | |
602 result = websocket_interface_->Close(ws, | |
603 PP_WEBSOCKETSTATUSCODE_NORMAL_CLOSURE, PP_MakeUndefined(), | |
604 another_callback.GetCallback().pp_completion_callback()); | |
605 ASSERT_EQ(PP_OK_COMPLETIONPENDING, result); | |
606 result = callback.WaitForResult(); | |
607 ASSERT_EQ(PP_ERROR_ABORTED, result); | |
608 result = another_callback.WaitForResult(); | |
609 ASSERT_EQ(PP_OK, result); | |
610 core_interface_->ReleaseResource(ws); | |
611 | |
549 ReleaseVar(reason); | 612 ReleaseVar(reason); |
550 ReleaseVar(url); | 613 ReleaseVar(url); |
551 | 614 |
552 PASS(); | 615 PASS(); |
553 } | 616 } |
554 | 617 |
555 std::string TestWebSocket::TestGetProtocol() { | 618 std::string TestWebSocket::TestGetProtocol() { |
556 const char* expected_protocols[] = { | 619 const char* expected_protocols[] = { |
557 "x-chat", | 620 "x-chat", |
558 "hoehoe", | 621 "hoehoe", |
(...skipping 745 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1304 size_t last_event = events_on_closed - 1; | 1367 size_t last_event = events_on_closed - 1; |
1305 for (uint32_t i = 1; i < last_event; ++i) { | 1368 for (uint32_t i = 1; i < last_event; ++i) { |
1306 ASSERT_EQ(WebSocketEvent::EVENT_MESSAGE, events[i].event_type); | 1369 ASSERT_EQ(WebSocketEvent::EVENT_MESSAGE, events[i].event_type); |
1307 ASSERT_TRUE(AreEqualWithString(events[i].var.pp_var(), message)); | 1370 ASSERT_TRUE(AreEqualWithString(events[i].var.pp_var(), message)); |
1308 } | 1371 } |
1309 ASSERT_EQ(WebSocketEvent::EVENT_CLOSE, events[last_event].event_type); | 1372 ASSERT_EQ(WebSocketEvent::EVENT_CLOSE, events[last_event].event_type); |
1310 ASSERT_TRUE(events[last_event].was_clean); | 1373 ASSERT_TRUE(events[last_event].was_clean); |
1311 | 1374 |
1312 PASS(); | 1375 PASS(); |
1313 } | 1376 } |
1314 | |
OLD | NEW |