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/pp_errors.h" | 11 #include "ppapi/c/pp_errors.h" |
12 #include "ppapi/c/pp_var.h" | 12 #include "ppapi/c/pp_var.h" |
13 #include "ppapi/c/pp_completion_callback.h" | 13 #include "ppapi/c/pp_completion_callback.h" |
14 #include "ppapi/c/ppb_core.h" | 14 #include "ppapi/c/ppb_core.h" |
15 #include "ppapi/c/ppb_var.h" | 15 #include "ppapi/c/ppb_var.h" |
16 #include "ppapi/c/ppb_var_array_buffer.h" | 16 #include "ppapi/c/ppb_var_array_buffer.h" |
17 #include "ppapi/c/ppb_websocket.h" | 17 #include "ppapi/c/ppb_websocket.h" |
18 #include "ppapi/cpp/instance.h" | 18 #include "ppapi/cpp/instance.h" |
19 #include "ppapi/cpp/module.h" | 19 #include "ppapi/cpp/module.h" |
20 #include "ppapi/cpp/var_array_buffer.h" | 20 #include "ppapi/cpp/var_array_buffer.h" |
21 #include "ppapi/cpp/websocket.h" | 21 #include "ppapi/cpp/websocket.h" |
22 #include "ppapi/tests/test_utils.h" | 22 #include "ppapi/tests/test_utils.h" |
23 #include "ppapi/tests/testing_instance.h" | 23 #include "ppapi/tests/testing_instance.h" |
24 #include "ppapi/utility/websocket/websocket_api.h" | 24 #include "ppapi/utility/websocket/websocket_api.h" |
25 | 25 |
26 // These servers are provided by pywebsocket server side handlers in | 26 // These servers are provided by pywebsocket server side handlers in |
27 // LayoutTests/http/tests/websocket/tests/hybi/*_wsh. | 27 // LayoutTests/http/tests/websocket/tests/hybi/*_wsh. |
28 // pywebsocket server itself is launched in ppapi_ui_test.cc. | 28 // pywebsocket server itself is launched in ppapi_ui_test.cc. |
29 const char kEchoServerURL[] = | 29 const char kEchoServerURL[] = |
30 "ws://localhost:8880/websocket/tests/hybi/echo"; | 30 "ws://localhost:8880/websocket/tests/hybi/echo-with-no-extension"; |
31 | 31 |
32 const char kCloseServerURL[] = | 32 const char kCloseServerURL[] = |
33 "ws://localhost:8880/websocket/tests/hybi/close"; | 33 "ws://localhost:8880/websocket/tests/hybi/close"; |
34 | 34 |
35 const char kProtocolTestServerURL[] = | 35 const char kProtocolTestServerURL[] = |
36 "ws://localhost:8880/websocket/tests/hybi/protocol-test?protocol="; | 36 "ws://localhost:8880/websocket/tests/hybi/protocol-test?protocol="; |
37 | 37 |
38 const char* const kInvalidURLs[] = { | 38 const char* const kInvalidURLs[] = { |
39 "http://www.google.com/invalid_scheme", | 39 "http://www.google.com/invalid_scheme", |
40 "ws://www.google.com/invalid#fragment", | 40 "ws://www.google.com/invalid#fragment", |
(...skipping 368 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
409 } | 409 } |
410 | 410 |
411 PASS(); | 411 PASS(); |
412 } | 412 } |
413 | 413 |
414 std::string TestWebSocket::TestValidConnect() { | 414 std::string TestWebSocket::TestValidConnect() { |
415 int32_t result; | 415 int32_t result; |
416 PP_Resource ws = Connect(kEchoServerURL, &result, NULL); | 416 PP_Resource ws = Connect(kEchoServerURL, &result, NULL); |
417 ASSERT_TRUE(ws); | 417 ASSERT_TRUE(ws); |
418 ASSERT_EQ(PP_OK, result); | 418 ASSERT_EQ(PP_OK, result); |
419 PP_Var extensions = websocket_interface_->GetExtensions(ws); | |
420 ASSERT_TRUE(AreEqualWithString(extensions, "")); | |
419 core_interface_->ReleaseResource(ws); | 421 core_interface_->ReleaseResource(ws); |
420 | 422 |
421 PASS(); | 423 PASS(); |
422 } | 424 } |
423 | 425 |
424 std::string TestWebSocket::TestInvalidClose() { | 426 std::string TestWebSocket::TestInvalidClose() { |
425 PP_Var reason = CreateVarString("close for test"); | 427 PP_Var reason = CreateVarString("close for test"); |
426 TestCompletionCallback callback(instance_->pp_instance()); | 428 TestCompletionCallback callback(instance_->pp_instance()); |
427 | 429 |
428 // Close before connect. | 430 // Close before connect. |
(...skipping 312 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
741 PP_WEBSOCKETSTATUSCODE_NORMAL_CLOSURE, pp::Var(reason), close_callback); | 743 PP_WEBSOCKETSTATUSCODE_NORMAL_CLOSURE, pp::Var(reason), close_callback); |
742 ASSERT_EQ(PP_OK_COMPLETIONPENDING, result); | 744 ASSERT_EQ(PP_OK_COMPLETIONPENDING, result); |
743 result = close_callback.WaitForResult(); | 745 result = close_callback.WaitForResult(); |
744 ASSERT_EQ(PP_OK, result); | 746 ASSERT_EQ(PP_OK, result); |
745 | 747 |
746 // Check initialized properties access. | 748 // Check initialized properties access. |
747 ASSERT_EQ(0, ws.GetBufferedAmount()); | 749 ASSERT_EQ(0, ws.GetBufferedAmount()); |
748 ASSERT_EQ(PP_WEBSOCKETSTATUSCODE_NORMAL_CLOSURE, ws.GetCloseCode()); | 750 ASSERT_EQ(PP_WEBSOCKETSTATUSCODE_NORMAL_CLOSURE, ws.GetCloseCode()); |
749 ASSERT_TRUE(AreEqualWithString(ws.GetCloseReason().pp_var(), reason.c_str())); | 751 ASSERT_TRUE(AreEqualWithString(ws.GetCloseReason().pp_var(), reason.c_str())); |
750 ASSERT_EQ(true, ws.GetCloseWasClean()); | 752 ASSERT_EQ(true, ws.GetCloseWasClean()); |
751 ASSERT_TRUE(AreEqualWithString(ws.GetExtensions().pp_var(), "")); | |
Takashi Toyoshima
2012/03/09 19:26:43
CcInterfaces test doesn't use kEchoServer, so I mo
| |
752 ASSERT_TRUE(AreEqualWithString(ws.GetProtocol().pp_var(), "")); | 753 ASSERT_TRUE(AreEqualWithString(ws.GetProtocol().pp_var(), "")); |
753 ASSERT_EQ(PP_WEBSOCKETREADYSTATE_CLOSED, ws.GetReadyState()); | 754 ASSERT_EQ(PP_WEBSOCKETREADYSTATE_CLOSED, ws.GetReadyState()); |
754 ASSERT_TRUE(AreEqualWithString(ws.GetURL().pp_var(), kCloseServerURL)); | 755 ASSERT_TRUE(AreEqualWithString(ws.GetURL().pp_var(), kCloseServerURL)); |
755 | 756 |
756 PASS(); | 757 PASS(); |
757 } | 758 } |
758 | 759 |
759 std::string TestWebSocket::TestUtilityInvalidConnect() { | 760 std::string TestWebSocket::TestUtilityInvalidConnect() { |
760 const pp::Var protocols[] = { pp::Var() }; | 761 const pp::Var protocols[] = { pp::Var() }; |
761 | 762 |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
830 std::string TestWebSocket::TestUtilityValidConnect() { | 831 std::string TestWebSocket::TestUtilityValidConnect() { |
831 const pp::Var protocols[] = { pp::Var() }; | 832 const pp::Var protocols[] = { pp::Var() }; |
832 TestWebSocketAPI websocket(instance_); | 833 TestWebSocketAPI websocket(instance_); |
833 int32_t result = websocket.Connect( | 834 int32_t result = websocket.Connect( |
834 pp::Var(std::string(kEchoServerURL)), protocols, 0U); | 835 pp::Var(std::string(kEchoServerURL)), protocols, 0U); |
835 ASSERT_EQ(PP_OK_COMPLETIONPENDING, result); | 836 ASSERT_EQ(PP_OK_COMPLETIONPENDING, result); |
836 websocket.WaitForConnected(); | 837 websocket.WaitForConnected(); |
837 const std::vector<WebSocketEvent>& events = websocket.GetSeenEvents(); | 838 const std::vector<WebSocketEvent>& events = websocket.GetSeenEvents(); |
838 ASSERT_EQ(1U, events.size()); | 839 ASSERT_EQ(1U, events.size()); |
839 ASSERT_EQ(WebSocketEvent::EVENT_OPEN, events[0].event_type); | 840 ASSERT_EQ(WebSocketEvent::EVENT_OPEN, events[0].event_type); |
841 ASSERT_TRUE(AreEqualWithString(websocket.GetExtensions().pp_var(), "")); | |
840 | 842 |
841 PASS(); | 843 PASS(); |
842 } | 844 } |
843 | 845 |
844 std::string TestWebSocket::TestUtilityInvalidClose() { | 846 std::string TestWebSocket::TestUtilityInvalidClose() { |
845 const pp::Var reason = pp::Var(std::string("close for test")); | 847 const pp::Var reason = pp::Var(std::string("close for test")); |
846 | 848 |
847 // Close before connect. | 849 // Close before connect. |
848 { | 850 { |
849 TestWebSocketAPI websocket(instance_); | 851 TestWebSocketAPI websocket(instance_); |
(...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1085 size_t last_event = events_on_closed - 1; | 1087 size_t last_event = events_on_closed - 1; |
1086 for (uint32_t i = 1; i < last_event; ++i) { | 1088 for (uint32_t i = 1; i < last_event; ++i) { |
1087 ASSERT_EQ(WebSocketEvent::EVENT_MESSAGE, events[i].event_type); | 1089 ASSERT_EQ(WebSocketEvent::EVENT_MESSAGE, events[i].event_type); |
1088 ASSERT_TRUE(AreEqualWithString(events[i].var.pp_var(), message_char)); | 1090 ASSERT_TRUE(AreEqualWithString(events[i].var.pp_var(), message_char)); |
1089 } | 1091 } |
1090 ASSERT_EQ(WebSocketEvent::EVENT_CLOSE, events[last_event].event_type); | 1092 ASSERT_EQ(WebSocketEvent::EVENT_CLOSE, events[last_event].event_type); |
1091 ASSERT_TRUE(events[last_event].was_clean); | 1093 ASSERT_TRUE(events[last_event].was_clean); |
1092 | 1094 |
1093 PASS(); | 1095 PASS(); |
1094 } | 1096 } |
OLD | NEW |