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" |
11 #include "ppapi/c/dev/ppb_websocket_dev.h" | |
12 #include "ppapi/c/pp_errors.h" | 11 #include "ppapi/c/pp_errors.h" |
13 #include "ppapi/c/pp_var.h" | 12 #include "ppapi/c/pp_var.h" |
14 #include "ppapi/c/pp_completion_callback.h" | 13 #include "ppapi/c/pp_completion_callback.h" |
15 #include "ppapi/c/ppb_core.h" | 14 #include "ppapi/c/ppb_core.h" |
16 #include "ppapi/c/ppb_var.h" | 15 #include "ppapi/c/ppb_var.h" |
17 #include "ppapi/c/ppb_var_array_buffer.h" | 16 #include "ppapi/c/ppb_var_array_buffer.h" |
18 #include "ppapi/cpp/dev/websocket_dev.h" | 17 #include "ppapi/c/ppb_websocket.h" |
19 #include "ppapi/cpp/instance.h" | 18 #include "ppapi/cpp/instance.h" |
20 #include "ppapi/cpp/module.h" | 19 #include "ppapi/cpp/module.h" |
| 20 #include "ppapi/cpp/websocket.h" |
21 #include "ppapi/tests/test_utils.h" | 21 #include "ppapi/tests/test_utils.h" |
22 #include "ppapi/tests/testing_instance.h" | 22 #include "ppapi/tests/testing_instance.h" |
23 | 23 |
24 const char kEchoServerURL[] = | 24 const char kEchoServerURL[] = |
25 "ws://localhost:8880/websocket/tests/hybi/echo"; | 25 "ws://localhost:8880/websocket/tests/hybi/echo"; |
26 | 26 |
27 const char kCloseServerURL[] = | 27 const char kCloseServerURL[] = |
28 "ws://localhost:8880/websocket/tests/hybi/close"; | 28 "ws://localhost:8880/websocket/tests/hybi/close"; |
29 | 29 |
30 const char kProtocolTestServerURL[] = | 30 const char kProtocolTestServerURL[] = |
(...skipping 11 matching lines...) Expand all Loading... |
42 // See section 7.4.1. of RFC 6455. | 42 // See section 7.4.1. of RFC 6455. |
43 const uint16_t kCloseCodeNormalClosure = 1000U; | 43 const uint16_t kCloseCodeNormalClosure = 1000U; |
44 | 44 |
45 // Internal packet sizes. | 45 // Internal packet sizes. |
46 const uint64_t kCloseFrameSize = 6; | 46 const uint64_t kCloseFrameSize = 6; |
47 const uint64_t kMessageFrameOverhead = 6; | 47 const uint64_t kMessageFrameOverhead = 6; |
48 | 48 |
49 REGISTER_TEST_CASE(WebSocket); | 49 REGISTER_TEST_CASE(WebSocket); |
50 | 50 |
51 bool TestWebSocket::Init() { | 51 bool TestWebSocket::Init() { |
52 websocket_interface_ = static_cast<const PPB_WebSocket_Dev*>( | 52 websocket_interface_ = static_cast<const PPB_WebSocket*>( |
53 pp::Module::Get()->GetBrowserInterface(PPB_WEBSOCKET_DEV_INTERFACE)); | 53 pp::Module::Get()->GetBrowserInterface(PPB_WEBSOCKET_INTERFACE)); |
54 var_interface_ = static_cast<const PPB_Var*>( | 54 var_interface_ = static_cast<const PPB_Var*>( |
55 pp::Module::Get()->GetBrowserInterface(PPB_VAR_INTERFACE)); | 55 pp::Module::Get()->GetBrowserInterface(PPB_VAR_INTERFACE)); |
56 arraybuffer_interface_ = static_cast<const PPB_VarArrayBuffer*>( | 56 arraybuffer_interface_ = static_cast<const PPB_VarArrayBuffer*>( |
57 pp::Module::Get()->GetBrowserInterface( | 57 pp::Module::Get()->GetBrowserInterface( |
58 PPB_VAR_ARRAY_BUFFER_INTERFACE)); | 58 PPB_VAR_ARRAY_BUFFER_INTERFACE)); |
59 core_interface_ = static_cast<const PPB_Core*>( | 59 core_interface_ = static_cast<const PPB_Core*>( |
60 pp::Module::Get()->GetBrowserInterface(PPB_CORE_INTERFACE)); | 60 pp::Module::Get()->GetBrowserInterface(PPB_CORE_INTERFACE)); |
61 if (!websocket_interface_ || !var_interface_ || !arraybuffer_interface_ || | 61 if (!websocket_interface_ || !var_interface_ || !arraybuffer_interface_ || |
62 !core_interface_) | 62 !core_interface_) |
63 return false; | 63 return false; |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
182 ASSERT_EQ(PP_FALSE, close_was_clean); | 182 ASSERT_EQ(PP_FALSE, close_was_clean); |
183 | 183 |
184 PP_Var extensions = websocket_interface_->GetExtensions(ws); | 184 PP_Var extensions = websocket_interface_->GetExtensions(ws); |
185 ASSERT_TRUE(AreEqualWithString(extensions, "")); | 185 ASSERT_TRUE(AreEqualWithString(extensions, "")); |
186 ReleaseVar(extensions); | 186 ReleaseVar(extensions); |
187 | 187 |
188 PP_Var protocol = websocket_interface_->GetProtocol(ws); | 188 PP_Var protocol = websocket_interface_->GetProtocol(ws); |
189 ASSERT_TRUE(AreEqualWithString(protocol, "")); | 189 ASSERT_TRUE(AreEqualWithString(protocol, "")); |
190 ReleaseVar(protocol); | 190 ReleaseVar(protocol); |
191 | 191 |
192 PP_WebSocketReadyState_Dev ready_state = | 192 PP_WebSocketReadyState ready_state = |
193 websocket_interface_->GetReadyState(ws); | 193 websocket_interface_->GetReadyState(ws); |
194 ASSERT_EQ(PP_WEBSOCKETREADYSTATE_INVALID_DEV, ready_state); | 194 ASSERT_EQ(PP_WEBSOCKETREADYSTATE_INVALID, ready_state); |
195 | 195 |
196 PP_Var url = websocket_interface_->GetURL(ws); | 196 PP_Var url = websocket_interface_->GetURL(ws); |
197 ASSERT_TRUE(AreEqualWithString(url, "")); | 197 ASSERT_TRUE(AreEqualWithString(url, "")); |
198 ReleaseVar(url); | 198 ReleaseVar(url); |
199 | 199 |
200 core_interface_->ReleaseResource(ws); | 200 core_interface_->ReleaseResource(ws); |
201 | 201 |
202 PASS(); | 202 PASS(); |
203 } | 203 } |
204 | 204 |
(...skipping 307 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
512 break; | 512 break; |
513 } | 513 } |
514 | 514 |
515 // Close connection. | 515 // Close connection. |
516 std::string reason_str = "close while busy"; | 516 std::string reason_str = "close while busy"; |
517 PP_Var reason = CreateVarString(reason_str.c_str()); | 517 PP_Var reason = CreateVarString(reason_str.c_str()); |
518 TestCompletionCallback callback(instance_->pp_instance()); | 518 TestCompletionCallback callback(instance_->pp_instance()); |
519 result = websocket_interface_->Close(ws, kCloseCodeNormalClosure, reason, | 519 result = websocket_interface_->Close(ws, kCloseCodeNormalClosure, reason, |
520 static_cast<pp::CompletionCallback>(callback).pp_completion_callback()); | 520 static_cast<pp::CompletionCallback>(callback).pp_completion_callback()); |
521 ASSERT_EQ(PP_OK_COMPLETIONPENDING, result); | 521 ASSERT_EQ(PP_OK_COMPLETIONPENDING, result); |
522 ASSERT_EQ(PP_WEBSOCKETREADYSTATE_CLOSING_DEV, | 522 ASSERT_EQ(PP_WEBSOCKETREADYSTATE_CLOSING, |
523 websocket_interface_->GetReadyState(ws)); | 523 websocket_interface_->GetReadyState(ws)); |
524 | 524 |
525 result = callback.WaitForResult(); | 525 result = callback.WaitForResult(); |
526 ASSERT_EQ(PP_OK, result); | 526 ASSERT_EQ(PP_OK, result); |
527 ASSERT_EQ(PP_WEBSOCKETREADYSTATE_CLOSED_DEV, | 527 ASSERT_EQ(PP_WEBSOCKETREADYSTATE_CLOSED, |
528 websocket_interface_->GetReadyState(ws)); | 528 websocket_interface_->GetReadyState(ws)); |
529 | 529 |
530 uint64_t base_buffered_amount = websocket_interface_->GetBufferedAmount(ws); | 530 uint64_t base_buffered_amount = websocket_interface_->GetBufferedAmount(ws); |
531 | 531 |
532 // After connection closure, all sending requests fail and just increase | 532 // After connection closure, all sending requests fail and just increase |
533 // the bufferedAmount property. | 533 // the bufferedAmount property. |
534 PP_Var empty_string = CreateVarString(""); | 534 PP_Var empty_string = CreateVarString(""); |
535 result = websocket_interface_->SendMessage(ws, empty_string); | 535 result = websocket_interface_->SendMessage(ws, empty_string); |
536 ASSERT_EQ(PP_ERROR_FAILED, result); | 536 ASSERT_EQ(PP_ERROR_FAILED, result); |
537 buffered_amount = websocket_interface_->GetBufferedAmount(ws); | 537 buffered_amount = websocket_interface_->GetBufferedAmount(ws); |
(...skipping 10 matching lines...) Expand all Loading... |
548 ReleaseVar(reason); | 548 ReleaseVar(reason); |
549 ReleaseVar(empty_string); | 549 ReleaseVar(empty_string); |
550 core_interface_->ReleaseResource(ws); | 550 core_interface_->ReleaseResource(ws); |
551 | 551 |
552 PASS(); | 552 PASS(); |
553 } | 553 } |
554 | 554 |
555 std::string TestWebSocket::TestCcInterfaces() { | 555 std::string TestWebSocket::TestCcInterfaces() { |
556 // C++ bindings is simple straightforward, then just verifies interfaces work | 556 // C++ bindings is simple straightforward, then just verifies interfaces work |
557 // as a interface bridge fine. | 557 // as a interface bridge fine. |
558 pp::WebSocket_Dev ws(instance_); | 558 pp::WebSocket ws(instance_); |
559 | 559 |
560 // Check uninitialized properties access. | 560 // Check uninitialized properties access. |
561 ASSERT_EQ(0, ws.GetBufferedAmount()); | 561 ASSERT_EQ(0, ws.GetBufferedAmount()); |
562 ASSERT_EQ(0, ws.GetCloseCode()); | 562 ASSERT_EQ(0, ws.GetCloseCode()); |
563 ASSERT_TRUE(AreEqualWithString(ws.GetCloseReason().pp_var(), "")); | 563 ASSERT_TRUE(AreEqualWithString(ws.GetCloseReason().pp_var(), "")); |
564 ASSERT_EQ(false, ws.GetCloseWasClean()); | 564 ASSERT_EQ(false, ws.GetCloseWasClean()); |
565 ASSERT_TRUE(AreEqualWithString(ws.GetExtensions().pp_var(), "")); | 565 ASSERT_TRUE(AreEqualWithString(ws.GetExtensions().pp_var(), "")); |
566 ASSERT_TRUE(AreEqualWithString(ws.GetProtocol().pp_var(), "")); | 566 ASSERT_TRUE(AreEqualWithString(ws.GetProtocol().pp_var(), "")); |
567 ASSERT_EQ(PP_WEBSOCKETREADYSTATE_INVALID_DEV, ws.GetReadyState()); | 567 ASSERT_EQ(PP_WEBSOCKETREADYSTATE_INVALID, ws.GetReadyState()); |
568 ASSERT_TRUE(AreEqualWithString(ws.GetURL().pp_var(), "")); | 568 ASSERT_TRUE(AreEqualWithString(ws.GetURL().pp_var(), "")); |
569 | 569 |
570 // Check communication interfaces (connect, send, receive, and close). | 570 // Check communication interfaces (connect, send, receive, and close). |
571 TestCompletionCallback connect_callback(instance_->pp_instance()); | 571 TestCompletionCallback connect_callback(instance_->pp_instance()); |
572 int32_t result = ws.Connect(pp::Var(std::string(kCloseServerURL)), NULL, 0U, | 572 int32_t result = ws.Connect(pp::Var(std::string(kCloseServerURL)), NULL, 0U, |
573 connect_callback); | 573 connect_callback); |
574 ASSERT_EQ(PP_OK_COMPLETIONPENDING, result); | 574 ASSERT_EQ(PP_OK_COMPLETIONPENDING, result); |
575 result = connect_callback.WaitForResult(); | 575 result = connect_callback.WaitForResult(); |
576 ASSERT_EQ(PP_OK, result); | 576 ASSERT_EQ(PP_OK, result); |
577 | 577 |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
612 result = close_callback.WaitForResult(); | 612 result = close_callback.WaitForResult(); |
613 ASSERT_EQ(PP_OK, result); | 613 ASSERT_EQ(PP_OK, result); |
614 | 614 |
615 // Check initialized properties access. | 615 // Check initialized properties access. |
616 ASSERT_EQ(0, ws.GetBufferedAmount()); | 616 ASSERT_EQ(0, ws.GetBufferedAmount()); |
617 ASSERT_EQ(kCloseCodeNormalClosure, ws.GetCloseCode()); | 617 ASSERT_EQ(kCloseCodeNormalClosure, ws.GetCloseCode()); |
618 ASSERT_TRUE(AreEqualWithString(ws.GetCloseReason().pp_var(), reason.c_str())); | 618 ASSERT_TRUE(AreEqualWithString(ws.GetCloseReason().pp_var(), reason.c_str())); |
619 ASSERT_EQ(true, ws.GetCloseWasClean()); | 619 ASSERT_EQ(true, ws.GetCloseWasClean()); |
620 ASSERT_TRUE(AreEqualWithString(ws.GetExtensions().pp_var(), "")); | 620 ASSERT_TRUE(AreEqualWithString(ws.GetExtensions().pp_var(), "")); |
621 ASSERT_TRUE(AreEqualWithString(ws.GetProtocol().pp_var(), "")); | 621 ASSERT_TRUE(AreEqualWithString(ws.GetProtocol().pp_var(), "")); |
622 ASSERT_EQ(PP_WEBSOCKETREADYSTATE_CLOSED_DEV, ws.GetReadyState()); | 622 ASSERT_EQ(PP_WEBSOCKETREADYSTATE_CLOSED, ws.GetReadyState()); |
623 ASSERT_TRUE(AreEqualWithString(ws.GetURL().pp_var(), kCloseServerURL)); | 623 ASSERT_TRUE(AreEqualWithString(ws.GetURL().pp_var(), kCloseServerURL)); |
624 | 624 |
625 PASS(); | 625 PASS(); |
626 } | 626 } |
OLD | NEW |