OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 | 9 |
9 #include "ppapi/c/dev/ppb_testing_dev.h" | 10 #include "ppapi/c/dev/ppb_testing_dev.h" |
10 #include "ppapi/c/dev/ppb_websocket_dev.h" | 11 #include "ppapi/c/dev/ppb_websocket_dev.h" |
11 #include "ppapi/c/pp_errors.h" | 12 #include "ppapi/c/pp_errors.h" |
12 #include "ppapi/c/pp_var.h" | 13 #include "ppapi/c/pp_var.h" |
13 #include "ppapi/c/pp_completion_callback.h" | 14 #include "ppapi/c/pp_completion_callback.h" |
14 #include "ppapi/c/ppb_core.h" | 15 #include "ppapi/c/ppb_core.h" |
15 #include "ppapi/c/ppb_var.h" | 16 #include "ppapi/c/ppb_var.h" |
| 17 #include "ppapi/cpp/dev/websocket_dev.h" |
16 #include "ppapi/cpp/instance.h" | 18 #include "ppapi/cpp/instance.h" |
17 #include "ppapi/cpp/module.h" | 19 #include "ppapi/cpp/module.h" |
18 #include "ppapi/tests/test_utils.h" | 20 #include "ppapi/tests/test_utils.h" |
19 #include "ppapi/tests/testing_instance.h" | 21 #include "ppapi/tests/testing_instance.h" |
20 | 22 |
21 const char kEchoServerURL[] = | 23 const char kEchoServerURL[] = |
22 "ws://localhost:8880/websocket/tests/hybi/echo"; | 24 "ws://localhost:8880/websocket/tests/hybi/echo"; |
23 | 25 |
| 26 const char kCloseServerURL[] = |
| 27 "ws://localhost:8880/websocket/tests/hybi/close"; |
| 28 |
24 const char kProtocolTestServerURL[] = | 29 const char kProtocolTestServerURL[] = |
25 "ws://localhost:8880/websocket/tests/hybi/protocol-test?protocol="; | 30 "ws://localhost:8880/websocket/tests/hybi/protocol-test?protocol="; |
26 | 31 |
27 const char* const kInvalidURLs[] = { | 32 const char* const kInvalidURLs[] = { |
28 "http://www.google.com/invalid_scheme", | 33 "http://www.google.com/invalid_scheme", |
29 "ws://www.google.com/invalid#fragment", | 34 "ws://www.google.com/invalid#fragment", |
30 "ws://www.google.com:65535/invalid_port", | 35 "ws://www.google.com:65535/invalid_port", |
31 NULL | 36 NULL |
32 }; | 37 }; |
33 | 38 |
(...skipping 21 matching lines...) Expand all Loading... |
55 RUN_TEST_WITH_REFERENCE_CHECK(IsWebSocket, filter); | 60 RUN_TEST_WITH_REFERENCE_CHECK(IsWebSocket, filter); |
56 RUN_TEST_WITH_REFERENCE_CHECK(UninitializedPropertiesAccess, filter); | 61 RUN_TEST_WITH_REFERENCE_CHECK(UninitializedPropertiesAccess, filter); |
57 RUN_TEST_WITH_REFERENCE_CHECK(InvalidConnect, filter); | 62 RUN_TEST_WITH_REFERENCE_CHECK(InvalidConnect, filter); |
58 RUN_TEST_WITH_REFERENCE_CHECK(Protocols, filter); | 63 RUN_TEST_WITH_REFERENCE_CHECK(Protocols, filter); |
59 RUN_TEST_WITH_REFERENCE_CHECK(GetURL, filter); | 64 RUN_TEST_WITH_REFERENCE_CHECK(GetURL, filter); |
60 RUN_TEST_WITH_REFERENCE_CHECK(ValidConnect, filter); | 65 RUN_TEST_WITH_REFERENCE_CHECK(ValidConnect, filter); |
61 RUN_TEST_WITH_REFERENCE_CHECK(InvalidClose, filter); | 66 RUN_TEST_WITH_REFERENCE_CHECK(InvalidClose, filter); |
62 RUN_TEST_WITH_REFERENCE_CHECK(ValidClose, filter); | 67 RUN_TEST_WITH_REFERENCE_CHECK(ValidClose, filter); |
63 RUN_TEST_WITH_REFERENCE_CHECK(GetProtocol, filter); | 68 RUN_TEST_WITH_REFERENCE_CHECK(GetProtocol, filter); |
64 RUN_TEST_WITH_REFERENCE_CHECK(TextSendReceive, filter); | 69 RUN_TEST_WITH_REFERENCE_CHECK(TextSendReceive, filter); |
| 70 |
| 71 RUN_TEST_WITH_REFERENCE_CHECK(CcInterfaces, filter); |
65 } | 72 } |
66 | 73 |
67 PP_Var TestWebSocket::CreateVar(const char* string) { | 74 PP_Var TestWebSocket::CreateVar(const char* string) { |
68 return var_interface_->VarFromUtf8(string, strlen(string)); | 75 return var_interface_->VarFromUtf8(string, strlen(string)); |
69 } | 76 } |
70 | 77 |
71 void TestWebSocket::ReleaseVar(const PP_Var& var) { | 78 void TestWebSocket::ReleaseVar(const PP_Var& var) { |
72 var_interface_->Release(var); | 79 var_interface_->Release(var); |
73 } | 80 } |
74 | 81 |
(...skipping 332 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
407 PASS(); | 414 PASS(); |
408 } | 415 } |
409 | 416 |
410 // TODO(toyoshim): Add tests for GetBufferedAmount(). | 417 // TODO(toyoshim): Add tests for GetBufferedAmount(). |
411 // For now, the function doesn't work fine because update callback in WebKit is | 418 // For now, the function doesn't work fine because update callback in WebKit is |
412 // not landed yet. | 419 // not landed yet. |
413 | 420 |
414 // TODO(toyoshim): Add tests for didReceiveMessageError(). | 421 // TODO(toyoshim): Add tests for didReceiveMessageError(). |
415 | 422 |
416 // TODO(toyoshim): Add other function tests. | 423 // TODO(toyoshim): Add other function tests. |
| 424 |
| 425 std::string TestWebSocket::TestCcInterfaces() { |
| 426 // C++ bindings is simple straightforward, then just verifies interfaces work |
| 427 // as a interface bridge fine. |
| 428 pp::WebSocket_Dev ws(instance_); |
| 429 |
| 430 // Check uninitialized properties access. |
| 431 ASSERT_EQ(0, ws.GetBufferedAmount()); |
| 432 ASSERT_EQ(0, ws.GetCloseCode()); |
| 433 ASSERT_TRUE(AreEqual(ws.GetCloseReason().pp_var(), "")); |
| 434 ASSERT_EQ(false, ws.GetCloseWasClean()); |
| 435 ASSERT_TRUE(AreEqual(ws.GetExtensions().pp_var(), "")); |
| 436 ASSERT_TRUE(AreEqual(ws.GetProtocol().pp_var(), "")); |
| 437 ASSERT_EQ(PP_WEBSOCKETREADYSTATE_INVALID_DEV, ws.GetReadyState()); |
| 438 ASSERT_TRUE(AreEqual(ws.GetURL().pp_var(), "")); |
| 439 |
| 440 // Check communication interfaces (connect, send, receive, and close). |
| 441 TestCompletionCallback connect_callback(instance_->pp_instance()); |
| 442 int32_t result = ws.Connect(pp::Var(std::string(kCloseServerURL)), NULL, 0U, |
| 443 connect_callback); |
| 444 ASSERT_EQ(PP_OK_COMPLETIONPENDING, result); |
| 445 result = connect_callback.WaitForResult(); |
| 446 ASSERT_EQ(PP_OK, result); |
| 447 |
| 448 std::string message("hello C++"); |
| 449 result = ws.SendMessage(pp::Var(message)); |
| 450 ASSERT_EQ(PP_OK, result); |
| 451 |
| 452 pp::Var receive_var; |
| 453 TestCompletionCallback receive_callback(instance_->pp_instance()); |
| 454 result = ws.ReceiveMessage(&receive_var, receive_callback); |
| 455 if (result == PP_OK_COMPLETIONPENDING) |
| 456 result = receive_callback.WaitForResult(); |
| 457 ASSERT_EQ(PP_OK, result); |
| 458 ASSERT_TRUE(AreEqual(receive_var.pp_var(), message.c_str())); |
| 459 |
| 460 TestCompletionCallback close_callback(instance_->pp_instance()); |
| 461 std::string reason("bye"); |
| 462 result = ws.Close(kCloseCodeNormalClosure, pp::Var(reason), close_callback); |
| 463 ASSERT_EQ(PP_OK_COMPLETIONPENDING, result); |
| 464 result = close_callback.WaitForResult(); |
| 465 ASSERT_EQ(PP_OK, result); |
| 466 |
| 467 // Check initialized properties access. |
| 468 ASSERT_EQ(0, ws.GetBufferedAmount()); |
| 469 ASSERT_EQ(kCloseCodeNormalClosure, ws.GetCloseCode()); |
| 470 ASSERT_TRUE(AreEqual(ws.GetCloseReason().pp_var(), reason.c_str())); |
| 471 ASSERT_EQ(true, ws.GetCloseWasClean()); |
| 472 ASSERT_TRUE(AreEqual(ws.GetExtensions().pp_var(), "")); |
| 473 ASSERT_TRUE(AreEqual(ws.GetProtocol().pp_var(), "")); |
| 474 ASSERT_EQ(PP_WEBSOCKETREADYSTATE_CLOSED_DEV, ws.GetReadyState()); |
| 475 ASSERT_TRUE(AreEqual(ws.GetURL().pp_var(), kCloseServerURL)); |
| 476 |
| 477 PASS(); |
| 478 } |
OLD | NEW |