| 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 <string.h> | 7 #include <string.h> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "ppapi/c/dev/ppb_testing_dev.h" | 10 #include "ppapi/c/dev/ppb_testing_dev.h" |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 126 PP_Resource ws = websocket_interface_->Create(instance_->pp_instance()); | 126 PP_Resource ws = websocket_interface_->Create(instance_->pp_instance()); |
| 127 if (!ws) | 127 if (!ws) |
| 128 return 0; | 128 return 0; |
| 129 PP_Var url_var = CreateVarString(url); | 129 PP_Var url_var = CreateVarString(url); |
| 130 TestCompletionCallback callback(instance_->pp_instance(), force_async_); | 130 TestCompletionCallback callback(instance_->pp_instance(), force_async_); |
| 131 uint32_t protocol_count = 0U; | 131 uint32_t protocol_count = 0U; |
| 132 if (protocol) { | 132 if (protocol) { |
| 133 protocols[0] = CreateVarString(protocol); | 133 protocols[0] = CreateVarString(protocol); |
| 134 protocol_count = 1U; | 134 protocol_count = 1U; |
| 135 } | 135 } |
| 136 websocket_interface_->SetBinaryType( | |
| 137 ws, PP_WEBSOCKETBINARYTYPE_ARRAYBUFFER_DEV); | |
| 138 *result = websocket_interface_->Connect( | 136 *result = websocket_interface_->Connect( |
| 139 ws, url_var, protocols, protocol_count, | 137 ws, url_var, protocols, protocol_count, |
| 140 static_cast<pp::CompletionCallback>(callback).pp_completion_callback()); | 138 static_cast<pp::CompletionCallback>(callback).pp_completion_callback()); |
| 141 ReleaseVar(url_var); | 139 ReleaseVar(url_var); |
| 142 if (protocol) | 140 if (protocol) |
| 143 ReleaseVar(protocols[0]); | 141 ReleaseVar(protocols[0]); |
| 144 if (*result == PP_OK_COMPLETIONPENDING) | 142 if (*result == PP_OK_COMPLETIONPENDING) |
| 145 *result = callback.WaitForResult(); | 143 *result = callback.WaitForResult(); |
| 146 return ws; | 144 return ws; |
| 147 } | 145 } |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 190 ReleaseVar(protocol); | 188 ReleaseVar(protocol); |
| 191 | 189 |
| 192 PP_WebSocketReadyState_Dev ready_state = | 190 PP_WebSocketReadyState_Dev ready_state = |
| 193 websocket_interface_->GetReadyState(ws); | 191 websocket_interface_->GetReadyState(ws); |
| 194 ASSERT_EQ(PP_WEBSOCKETREADYSTATE_INVALID_DEV, ready_state); | 192 ASSERT_EQ(PP_WEBSOCKETREADYSTATE_INVALID_DEV, ready_state); |
| 195 | 193 |
| 196 PP_Var url = websocket_interface_->GetURL(ws); | 194 PP_Var url = websocket_interface_->GetURL(ws); |
| 197 ASSERT_TRUE(AreEqualWithString(url, "")); | 195 ASSERT_TRUE(AreEqualWithString(url, "")); |
| 198 ReleaseVar(url); | 196 ReleaseVar(url); |
| 199 | 197 |
| 200 PP_WebSocketBinaryType_Dev binary_type = | |
| 201 websocket_interface_->GetBinaryType(ws); | |
| 202 ASSERT_EQ(PP_WEBSOCKETBINARYTYPE_BLOB_DEV, binary_type); | |
| 203 | |
| 204 core_interface_->ReleaseResource(ws); | 198 core_interface_->ReleaseResource(ws); |
| 205 | 199 |
| 206 PASS(); | 200 PASS(); |
| 207 } | 201 } |
| 208 | 202 |
| 209 std::string TestWebSocket::TestInvalidConnect() { | 203 std::string TestWebSocket::TestInvalidConnect() { |
| 210 PP_Var protocols[] = { PP_MakeUndefined() }; | 204 PP_Var protocols[] = { PP_MakeUndefined() }; |
| 211 | 205 |
| 212 PP_Resource ws = websocket_interface_->Create(instance_->pp_instance()); | 206 PP_Resource ws = websocket_interface_->Create(instance_->pp_instance()); |
| 213 ASSERT_TRUE(ws); | 207 ASSERT_TRUE(ws); |
| (...skipping 351 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 565 ASSERT_EQ(0, ws.GetBufferedAmount()); | 559 ASSERT_EQ(0, ws.GetBufferedAmount()); |
| 566 ASSERT_EQ(0, ws.GetCloseCode()); | 560 ASSERT_EQ(0, ws.GetCloseCode()); |
| 567 ASSERT_TRUE(AreEqualWithString(ws.GetCloseReason().pp_var(), "")); | 561 ASSERT_TRUE(AreEqualWithString(ws.GetCloseReason().pp_var(), "")); |
| 568 ASSERT_EQ(false, ws.GetCloseWasClean()); | 562 ASSERT_EQ(false, ws.GetCloseWasClean()); |
| 569 ASSERT_TRUE(AreEqualWithString(ws.GetExtensions().pp_var(), "")); | 563 ASSERT_TRUE(AreEqualWithString(ws.GetExtensions().pp_var(), "")); |
| 570 ASSERT_TRUE(AreEqualWithString(ws.GetProtocol().pp_var(), "")); | 564 ASSERT_TRUE(AreEqualWithString(ws.GetProtocol().pp_var(), "")); |
| 571 ASSERT_EQ(PP_WEBSOCKETREADYSTATE_INVALID_DEV, ws.GetReadyState()); | 565 ASSERT_EQ(PP_WEBSOCKETREADYSTATE_INVALID_DEV, ws.GetReadyState()); |
| 572 ASSERT_TRUE(AreEqualWithString(ws.GetURL().pp_var(), "")); | 566 ASSERT_TRUE(AreEqualWithString(ws.GetURL().pp_var(), "")); |
| 573 | 567 |
| 574 // Check communication interfaces (connect, send, receive, and close). | 568 // Check communication interfaces (connect, send, receive, and close). |
| 575 ASSERT_TRUE(ws.SetBinaryType(PP_WEBSOCKETBINARYTYPE_ARRAYBUFFER_DEV)); | |
| 576 TestCompletionCallback connect_callback(instance_->pp_instance()); | 569 TestCompletionCallback connect_callback(instance_->pp_instance()); |
| 577 int32_t result = ws.Connect(pp::Var(std::string(kCloseServerURL)), NULL, 0U, | 570 int32_t result = ws.Connect(pp::Var(std::string(kCloseServerURL)), NULL, 0U, |
| 578 connect_callback); | 571 connect_callback); |
| 579 ASSERT_EQ(PP_OK_COMPLETIONPENDING, result); | 572 ASSERT_EQ(PP_OK_COMPLETIONPENDING, result); |
| 580 result = connect_callback.WaitForResult(); | 573 result = connect_callback.WaitForResult(); |
| 581 ASSERT_EQ(PP_OK, result); | 574 ASSERT_EQ(PP_OK, result); |
| 582 | 575 |
| 583 std::string text_message("hello C++"); | 576 std::string text_message("hello C++"); |
| 584 result = ws.SendMessage(pp::Var(text_message)); | 577 result = ws.SendMessage(pp::Var(text_message)); |
| 585 ASSERT_EQ(PP_OK, result); | 578 ASSERT_EQ(PP_OK, result); |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 619 | 612 |
| 620 // Check initialized properties access. | 613 // Check initialized properties access. |
| 621 ASSERT_EQ(0, ws.GetBufferedAmount()); | 614 ASSERT_EQ(0, ws.GetBufferedAmount()); |
| 622 ASSERT_EQ(kCloseCodeNormalClosure, ws.GetCloseCode()); | 615 ASSERT_EQ(kCloseCodeNormalClosure, ws.GetCloseCode()); |
| 623 ASSERT_TRUE(AreEqualWithString(ws.GetCloseReason().pp_var(), reason.c_str())); | 616 ASSERT_TRUE(AreEqualWithString(ws.GetCloseReason().pp_var(), reason.c_str())); |
| 624 ASSERT_EQ(true, ws.GetCloseWasClean()); | 617 ASSERT_EQ(true, ws.GetCloseWasClean()); |
| 625 ASSERT_TRUE(AreEqualWithString(ws.GetExtensions().pp_var(), "")); | 618 ASSERT_TRUE(AreEqualWithString(ws.GetExtensions().pp_var(), "")); |
| 626 ASSERT_TRUE(AreEqualWithString(ws.GetProtocol().pp_var(), "")); | 619 ASSERT_TRUE(AreEqualWithString(ws.GetProtocol().pp_var(), "")); |
| 627 ASSERT_EQ(PP_WEBSOCKETREADYSTATE_CLOSED_DEV, ws.GetReadyState()); | 620 ASSERT_EQ(PP_WEBSOCKETREADYSTATE_CLOSED_DEV, ws.GetReadyState()); |
| 628 ASSERT_TRUE(AreEqualWithString(ws.GetURL().pp_var(), kCloseServerURL)); | 621 ASSERT_TRUE(AreEqualWithString(ws.GetURL().pp_var(), kCloseServerURL)); |
| 629 ASSERT_EQ(PP_WEBSOCKETBINARYTYPE_ARRAYBUFFER_DEV, ws.GetBinaryType()); | |
| 630 | 622 |
| 631 PASS(); | 623 PASS(); |
| 632 } | 624 } |
| OLD | NEW |