Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(352)

Side by Side Diff: ppapi/tests/test_websocket.cc

Issue 9192009: WebSocket Pepper API: make the API out of dev (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: remove binary type handling interfaces Created 8 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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_var_array_buffer_dev.h" 11 #include "ppapi/c/dev/ppb_var_array_buffer_dev.h"
12 #include "ppapi/c/dev/ppb_websocket_dev.h"
13 #include "ppapi/c/pp_errors.h" 12 #include "ppapi/c/pp_errors.h"
14 #include "ppapi/c/pp_var.h" 13 #include "ppapi/c/pp_var.h"
15 #include "ppapi/c/pp_completion_callback.h" 14 #include "ppapi/c/pp_completion_callback.h"
16 #include "ppapi/c/ppb_core.h" 15 #include "ppapi/c/ppb_core.h"
17 #include "ppapi/c/ppb_var.h" 16 #include "ppapi/c/ppb_var.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
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_Dev*>( 56 arraybuffer_interface_ = static_cast<const PPB_VarArrayBuffer_Dev*>(
57 pp::Module::Get()->GetBrowserInterface( 57 pp::Module::Get()->GetBrowserInterface(
58 PPB_VAR_ARRAY_BUFFER_DEV_INTERFACE)); 58 PPB_VAR_ARRAY_BUFFER_DEV_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 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
182 ASSERT_EQ(PP_FALSE, close_was_clean); 180 ASSERT_EQ(PP_FALSE, close_was_clean);
183 181
184 PP_Var extensions = websocket_interface_->GetExtensions(ws); 182 PP_Var extensions = websocket_interface_->GetExtensions(ws);
185 ASSERT_TRUE(AreEqualWithString(extensions, "")); 183 ASSERT_TRUE(AreEqualWithString(extensions, ""));
186 ReleaseVar(extensions); 184 ReleaseVar(extensions);
187 185
188 PP_Var protocol = websocket_interface_->GetProtocol(ws); 186 PP_Var protocol = websocket_interface_->GetProtocol(ws);
189 ASSERT_TRUE(AreEqualWithString(protocol, "")); 187 ASSERT_TRUE(AreEqualWithString(protocol, ""));
190 ReleaseVar(protocol); 188 ReleaseVar(protocol);
191 189
192 PP_WebSocketReadyState_Dev ready_state = 190 PP_WebSocketReadyState 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, 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 302 matching lines...) Expand 10 before | Expand all | Expand 10 after
516 break; 510 break;
517 } 511 }
518 512
519 // Close connection. 513 // Close connection.
520 std::string reason_str = "close while busy"; 514 std::string reason_str = "close while busy";
521 PP_Var reason = CreateVarString(reason_str.c_str()); 515 PP_Var reason = CreateVarString(reason_str.c_str());
522 TestCompletionCallback callback(instance_->pp_instance()); 516 TestCompletionCallback callback(instance_->pp_instance());
523 result = websocket_interface_->Close(ws, kCloseCodeNormalClosure, reason, 517 result = websocket_interface_->Close(ws, kCloseCodeNormalClosure, reason,
524 static_cast<pp::CompletionCallback>(callback).pp_completion_callback()); 518 static_cast<pp::CompletionCallback>(callback).pp_completion_callback());
525 ASSERT_EQ(PP_OK_COMPLETIONPENDING, result); 519 ASSERT_EQ(PP_OK_COMPLETIONPENDING, result);
526 ASSERT_EQ(PP_WEBSOCKETREADYSTATE_CLOSING_DEV, 520 ASSERT_EQ(PP_WEBSOCKETREADYSTATE_CLOSING,
527 websocket_interface_->GetReadyState(ws)); 521 websocket_interface_->GetReadyState(ws));
528 522
529 result = callback.WaitForResult(); 523 result = callback.WaitForResult();
530 ASSERT_EQ(PP_OK, result); 524 ASSERT_EQ(PP_OK, result);
531 ASSERT_EQ(PP_WEBSOCKETREADYSTATE_CLOSED_DEV, 525 ASSERT_EQ(PP_WEBSOCKETREADYSTATE_CLOSED,
532 websocket_interface_->GetReadyState(ws)); 526 websocket_interface_->GetReadyState(ws));
533 527
534 uint64_t base_buffered_amount = websocket_interface_->GetBufferedAmount(ws); 528 uint64_t base_buffered_amount = websocket_interface_->GetBufferedAmount(ws);
535 529
536 // After connection closure, all sending requests fail and just increase 530 // After connection closure, all sending requests fail and just increase
537 // the bufferedAmount property. 531 // the bufferedAmount property.
538 PP_Var empty_string = CreateVarString(""); 532 PP_Var empty_string = CreateVarString("");
539 result = websocket_interface_->SendMessage(ws, empty_string); 533 result = websocket_interface_->SendMessage(ws, empty_string);
540 ASSERT_EQ(PP_ERROR_FAILED, result); 534 ASSERT_EQ(PP_ERROR_FAILED, result);
541 buffered_amount = websocket_interface_->GetBufferedAmount(ws); 535 buffered_amount = websocket_interface_->GetBufferedAmount(ws);
(...skipping 10 matching lines...) Expand all
552 ReleaseVar(reason); 546 ReleaseVar(reason);
553 ReleaseVar(empty_string); 547 ReleaseVar(empty_string);
554 core_interface_->ReleaseResource(ws); 548 core_interface_->ReleaseResource(ws);
555 549
556 PASS(); 550 PASS();
557 } 551 }
558 552
559 std::string TestWebSocket::TestCcInterfaces() { 553 std::string TestWebSocket::TestCcInterfaces() {
560 // C++ bindings is simple straightforward, then just verifies interfaces work 554 // C++ bindings is simple straightforward, then just verifies interfaces work
561 // as a interface bridge fine. 555 // as a interface bridge fine.
562 pp::WebSocket_Dev ws(instance_); 556 pp::WebSocket ws(instance_);
563 557
564 // Check uninitialized properties access. 558 // Check uninitialized properties access.
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, 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 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
617 result = close_callback.WaitForResult(); 610 result = close_callback.WaitForResult();
618 ASSERT_EQ(PP_OK, result); 611 ASSERT_EQ(PP_OK, result);
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, 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 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698