Chromium Code Reviews| 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 531 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 542 instance_->pp_instance(), callback_type()); | 542 instance_->pp_instance(), callback_type()); |
| 543 | 543 |
| 544 // Close. | 544 // Close. |
| 545 int32_t result; | 545 int32_t result; |
| 546 PP_Resource ws = Connect(GetFullURL(kEchoServerURL), &result, ""); | 546 PP_Resource ws = Connect(GetFullURL(kEchoServerURL), &result, ""); |
| 547 ASSERT_TRUE(ws); | 547 ASSERT_TRUE(ws); |
| 548 ASSERT_EQ(PP_OK, result); | 548 ASSERT_EQ(PP_OK, result); |
| 549 callback.WaitForResult(websocket_interface_->Close( | 549 callback.WaitForResult(websocket_interface_->Close( |
| 550 ws, PP_WEBSOCKETSTATUSCODE_NORMAL_CLOSURE, reason, | 550 ws, PP_WEBSOCKETSTATUSCODE_NORMAL_CLOSURE, reason, |
| 551 callback.GetCallback().pp_completion_callback())); | 551 callback.GetCallback().pp_completion_callback())); |
| 552 CHECK_CALLBACK_BEHAVIOR(callback); | |
|
Takashi Toyoshima
2012/05/14 12:05:04
I'm afraid that these checks will not work in the
dmichael (off chromium)
2012/05/14 16:10:49
Can you elaborate on your concerns?
The check sim
Takashi Toyoshima
2012/05/15 10:55:28
Sorry, I misunderstood on CHECK_CALLBACK_BEHAVIOR
| |
| 553 ASSERT_EQ(PP_OK, callback.result()); | 552 ASSERT_EQ(PP_OK, callback.result()); |
| 554 core_interface_->ReleaseResource(ws); | 553 core_interface_->ReleaseResource(ws); |
| 555 | 554 |
| 555 // Close without code and reason. | |
| 556 ws = Connect(GetFullURL(kEchoServerURL), &result, ""); | |
| 557 ASSERT_TRUE(ws); | |
| 558 ASSERT_EQ(PP_OK, result); | |
| 559 callback.WaitForResult(websocket_interface_->Close( | |
| 560 ws, PP_WEBSOCKETSTATUSCODE_NOT_SPECIFIED, reason, | |
| 561 callback.GetCallback().pp_completion_callback())); | |
| 562 ASSERT_EQ(PP_OK, callback.result()); | |
| 563 core_interface_->ReleaseResource(ws); | |
| 564 | |
| 556 // Close with PP_VARTYPE_UNDEFINED. | 565 // Close with PP_VARTYPE_UNDEFINED. |
| 557 ws = Connect(GetFullURL(kEchoServerURL), &result, ""); | 566 ws = Connect(GetFullURL(kEchoServerURL), &result, ""); |
| 558 ASSERT_TRUE(ws); | 567 ASSERT_TRUE(ws); |
| 559 ASSERT_EQ(PP_OK, result); | 568 ASSERT_EQ(PP_OK, result); |
| 560 callback.WaitForResult(websocket_interface_->Close( | 569 callback.WaitForResult(websocket_interface_->Close( |
| 561 ws, PP_WEBSOCKETSTATUSCODE_NORMAL_CLOSURE, PP_MakeUndefined(), | 570 ws, PP_WEBSOCKETSTATUSCODE_NORMAL_CLOSURE, PP_MakeUndefined(), |
| 562 callback.GetCallback().pp_completion_callback())); | 571 callback.GetCallback().pp_completion_callback())); |
| 563 CHECK_CALLBACK_BEHAVIOR(callback); | |
| 564 ASSERT_EQ(PP_OK, callback.result()); | 572 ASSERT_EQ(PP_OK, callback.result()); |
| 565 core_interface_->ReleaseResource(ws); | 573 core_interface_->ReleaseResource(ws); |
| 566 | 574 |
| 567 // Close in connecting. | 575 // Close in connecting. |
| 568 // The ongoing connect failed with PP_ERROR_ABORTED, then the close is done | 576 // The ongoing connect failed with PP_ERROR_ABORTED, then the close is done |
| 569 // successfully. | 577 // successfully. |
| 570 ws = websocket_interface_->Create(instance_->pp_instance()); | 578 ws = websocket_interface_->Create(instance_->pp_instance()); |
| 571 result = websocket_interface_->Connect( | 579 result = websocket_interface_->Connect( |
| 572 ws, url, protocols, 0U, callback.GetCallback().pp_completion_callback()); | 580 ws, url, protocols, 0U, callback.GetCallback().pp_completion_callback()); |
| 573 ASSERT_EQ(PP_OK_COMPLETIONPENDING, result); | 581 ASSERT_EQ(PP_OK_COMPLETIONPENDING, result); |
| (...skipping 435 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1009 ASSERT_TRUE(AreEqualWithString(ws.GetExtensions().pp_var(), "")); | 1017 ASSERT_TRUE(AreEqualWithString(ws.GetExtensions().pp_var(), "")); |
| 1010 ASSERT_TRUE(AreEqualWithString(ws.GetProtocol().pp_var(), "")); | 1018 ASSERT_TRUE(AreEqualWithString(ws.GetProtocol().pp_var(), "")); |
| 1011 ASSERT_EQ(PP_WEBSOCKETREADYSTATE_INVALID, ws.GetReadyState()); | 1019 ASSERT_EQ(PP_WEBSOCKETREADYSTATE_INVALID, ws.GetReadyState()); |
| 1012 ASSERT_TRUE(AreEqualWithString(ws.GetURL().pp_var(), "")); | 1020 ASSERT_TRUE(AreEqualWithString(ws.GetURL().pp_var(), "")); |
| 1013 | 1021 |
| 1014 // Check communication interfaces (connect, send, receive, and close). | 1022 // Check communication interfaces (connect, send, receive, and close). |
| 1015 TestCompletionCallback connect_callback( | 1023 TestCompletionCallback connect_callback( |
| 1016 instance_->pp_instance(), callback_type()); | 1024 instance_->pp_instance(), callback_type()); |
| 1017 connect_callback.WaitForResult(ws.Connect( | 1025 connect_callback.WaitForResult(ws.Connect( |
| 1018 pp::Var(GetFullURL(kCloseServerURL)), NULL, 0U, connect_callback)); | 1026 pp::Var(GetFullURL(kCloseServerURL)), NULL, 0U, connect_callback)); |
| 1019 CHECK_CALLBACK_BEHAVIOR(connect_callback); | |
| 1020 ASSERT_EQ(PP_OK, connect_callback.result()); | 1027 ASSERT_EQ(PP_OK, connect_callback.result()); |
| 1021 | 1028 |
| 1022 std::string text_message("hello C++"); | 1029 std::string text_message("hello C++"); |
| 1023 int32_t result = ws.SendMessage(pp::Var(text_message)); | 1030 int32_t result = ws.SendMessage(pp::Var(text_message)); |
| 1024 ASSERT_EQ(PP_OK, result); | 1031 ASSERT_EQ(PP_OK, result); |
| 1025 | 1032 |
| 1026 std::vector<uint8_t> binary(256); | 1033 std::vector<uint8_t> binary(256); |
| 1027 for (uint32_t i = 0; i < binary.size(); ++i) | 1034 for (uint32_t i = 0; i < binary.size(); ++i) |
| 1028 binary[i] = i; | 1035 binary[i] = i; |
| 1029 result = ws.SendMessage( | 1036 result = ws.SendMessage( |
| (...skipping 367 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1397 size_t last_event = events_on_closed - 1; | 1404 size_t last_event = events_on_closed - 1; |
| 1398 for (uint32_t i = 1; i < last_event; ++i) { | 1405 for (uint32_t i = 1; i < last_event; ++i) { |
| 1399 ASSERT_EQ(WebSocketEvent::EVENT_MESSAGE, events[i].event_type); | 1406 ASSERT_EQ(WebSocketEvent::EVENT_MESSAGE, events[i].event_type); |
| 1400 ASSERT_TRUE(AreEqualWithString(events[i].var.pp_var(), message)); | 1407 ASSERT_TRUE(AreEqualWithString(events[i].var.pp_var(), message)); |
| 1401 } | 1408 } |
| 1402 ASSERT_EQ(WebSocketEvent::EVENT_CLOSE, events[last_event].event_type); | 1409 ASSERT_EQ(WebSocketEvent::EVENT_CLOSE, events[last_event].event_type); |
| 1403 ASSERT_TRUE(events[last_event].was_clean); | 1410 ASSERT_TRUE(events[last_event].was_clean); |
| 1404 | 1411 |
| 1405 PASS(); | 1412 PASS(); |
| 1406 } | 1413 } |
| OLD | NEW |