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_websocket_dev.h" | 10 #include "ppapi/c/dev/ppb_websocket_dev.h" |
10 #include "ppapi/c/pp_errors.h" | 11 #include "ppapi/c/pp_errors.h" |
11 #include "ppapi/c/pp_var.h" | 12 #include "ppapi/c/pp_var.h" |
12 #include "ppapi/c/pp_completion_callback.h" | 13 #include "ppapi/c/pp_completion_callback.h" |
13 #include "ppapi/c/ppb_core.h" | 14 #include "ppapi/c/ppb_core.h" |
14 #include "ppapi/c/ppb_var.h" | 15 #include "ppapi/c/ppb_var.h" |
| 16 #include "ppapi/cpp/dev/websocket_dev.h" |
15 #include "ppapi/cpp/instance.h" | 17 #include "ppapi/cpp/instance.h" |
16 #include "ppapi/cpp/module.h" | 18 #include "ppapi/cpp/module.h" |
17 #include "ppapi/tests/test_utils.h" | 19 #include "ppapi/tests/test_utils.h" |
18 #include "ppapi/tests/testing_instance.h" | 20 #include "ppapi/tests/testing_instance.h" |
19 | 21 |
20 const char kEchoServerURL[] = | 22 const char kEchoServerURL[] = |
21 "ws://localhost:8880/websocket/tests/hybi/echo"; | 23 "ws://localhost:8880/websocket/tests/hybi/echo"; |
22 | 24 |
23 const char kProtocolTestServerURL[] = | 25 const char kProtocolTestServerURL[] = |
24 "ws://localhost:8880/websocket/tests/hybi/protocol-test?protocol="; | 26 "ws://localhost:8880/websocket/tests/hybi/protocol-test?protocol="; |
(...skipping 29 matching lines...) Expand all Loading... |
54 RUN_TEST(IsWebSocket, filter); | 56 RUN_TEST(IsWebSocket, filter); |
55 RUN_TEST(UninitializedPropertiesAccess, filter); | 57 RUN_TEST(UninitializedPropertiesAccess, filter); |
56 RUN_TEST(InvalidConnect, filter); | 58 RUN_TEST(InvalidConnect, filter); |
57 RUN_TEST(Protocols, filter); | 59 RUN_TEST(Protocols, filter); |
58 RUN_TEST(GetURL, filter); | 60 RUN_TEST(GetURL, filter); |
59 RUN_TEST(ValidConnect, filter); | 61 RUN_TEST(ValidConnect, filter); |
60 RUN_TEST(InvalidClose, filter); | 62 RUN_TEST(InvalidClose, filter); |
61 RUN_TEST(ValidClose, filter); | 63 RUN_TEST(ValidClose, filter); |
62 RUN_TEST(GetProtocol, filter); | 64 RUN_TEST(GetProtocol, filter); |
63 RUN_TEST(TextSendReceive, filter); | 65 RUN_TEST(TextSendReceive, filter); |
| 66 |
| 67 RUN_TEST(CcInterfaces, filter); |
64 } | 68 } |
65 | 69 |
66 PP_Var TestWebSocket::CreateVar(const char* string) { | 70 PP_Var TestWebSocket::CreateVar(const char* string) { |
67 return var_interface_->VarFromUtf8(string, strlen(string)); | 71 return var_interface_->VarFromUtf8(string, strlen(string)); |
68 } | 72 } |
69 | 73 |
70 void TestWebSocket::ReleaseVar(const PP_Var& var) { | 74 void TestWebSocket::ReleaseVar(const PP_Var& var) { |
71 var_interface_->Release(var); | 75 var_interface_->Release(var); |
72 } | 76 } |
73 | 77 |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
131 ASSERT_TRUE(ws); | 135 ASSERT_TRUE(ws); |
132 | 136 |
133 uint64_t bufferedAmount = websocket_interface_->GetBufferedAmount(ws); | 137 uint64_t bufferedAmount = websocket_interface_->GetBufferedAmount(ws); |
134 ASSERT_EQ(0U, bufferedAmount); | 138 ASSERT_EQ(0U, bufferedAmount); |
135 | 139 |
136 uint16_t close_code = websocket_interface_->GetCloseCode(ws); | 140 uint16_t close_code = websocket_interface_->GetCloseCode(ws); |
137 ASSERT_EQ(0U, close_code); | 141 ASSERT_EQ(0U, close_code); |
138 | 142 |
139 PP_Var close_reason = websocket_interface_->GetCloseReason(ws); | 143 PP_Var close_reason = websocket_interface_->GetCloseReason(ws); |
140 ASSERT_TRUE(AreEqual(close_reason, "")); | 144 ASSERT_TRUE(AreEqual(close_reason, "")); |
| 145 ReleaseVar(close_reason); |
141 | 146 |
142 PP_Bool close_was_clean = websocket_interface_->GetCloseWasClean(ws); | 147 PP_Bool close_was_clean = websocket_interface_->GetCloseWasClean(ws); |
143 ASSERT_EQ(PP_FALSE, close_was_clean); | 148 ASSERT_EQ(PP_FALSE, close_was_clean); |
144 | 149 |
145 PP_Var extensions = websocket_interface_->GetExtensions(ws); | 150 PP_Var extensions = websocket_interface_->GetExtensions(ws); |
146 ASSERT_TRUE(AreEqual(extensions, "")); | 151 ASSERT_TRUE(AreEqual(extensions, "")); |
| 152 ReleaseVar(extensions); |
147 | 153 |
148 PP_Var protocol = websocket_interface_->GetProtocol(ws); | 154 PP_Var protocol = websocket_interface_->GetProtocol(ws); |
149 ASSERT_TRUE(AreEqual(protocol, "")); | 155 ASSERT_TRUE(AreEqual(protocol, "")); |
| 156 ReleaseVar(protocol); |
150 | 157 |
151 PP_WebSocketReadyState_Dev ready_state = | 158 PP_WebSocketReadyState_Dev ready_state = |
152 websocket_interface_->GetReadyState(ws); | 159 websocket_interface_->GetReadyState(ws); |
153 ASSERT_EQ(PP_WEBSOCKETREADYSTATE_INVALID_DEV, ready_state); | 160 ASSERT_EQ(PP_WEBSOCKETREADYSTATE_INVALID_DEV, ready_state); |
154 | 161 |
155 PP_Var url = websocket_interface_->GetURL(ws); | 162 PP_Var url = websocket_interface_->GetURL(ws); |
156 ASSERT_TRUE(AreEqual(url, "")); | 163 ASSERT_TRUE(AreEqual(url, "")); |
| 164 ReleaseVar(url); |
157 | 165 |
158 PASS(); | 166 PASS(); |
159 } | 167 } |
160 | 168 |
161 std::string TestWebSocket::TestInvalidConnect() { | 169 std::string TestWebSocket::TestInvalidConnect() { |
162 PP_Var protocols[] = { PP_MakeUndefined() }; | 170 PP_Var protocols[] = { PP_MakeUndefined() }; |
163 | 171 |
164 PP_Resource ws = websocket_interface_->Create(instance_->pp_instance()); | 172 PP_Resource ws = websocket_interface_->Create(instance_->pp_instance()); |
165 ASSERT_TRUE(ws); | 173 ASSERT_TRUE(ws); |
166 | 174 |
(...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
400 PASS(); | 408 PASS(); |
401 } | 409 } |
402 | 410 |
403 // TODO(toyoshim): Add tests for GetBufferedAmount(). | 411 // TODO(toyoshim): Add tests for GetBufferedAmount(). |
404 // For now, the function doesn't work fine because update callback in WebKit is | 412 // For now, the function doesn't work fine because update callback in WebKit is |
405 // not landed yet. | 413 // not landed yet. |
406 | 414 |
407 // TODO(toyoshim): Add tests for didReceiveMessageError(). | 415 // TODO(toyoshim): Add tests for didReceiveMessageError(). |
408 | 416 |
409 // TODO(toyoshim): Add other function tests. | 417 // TODO(toyoshim): Add other function tests. |
| 418 |
| 419 std::string TestWebSocket::TestCcInterfaces() { |
| 420 // C++ bindings is simple straightforward, then just verifies interfaces work |
| 421 // as a interface bridge fine. |
| 422 pp::WebSocket_Dev ws(instance_); |
| 423 |
| 424 // Check uninitialized properties access. |
| 425 ASSERT_EQ(0, ws.GetBufferedAmount()); |
| 426 ASSERT_EQ(0, ws.GetCloseCode()); |
| 427 ASSERT_TRUE(AreEqual(ws.GetCloseReason().pp_var(), "")); |
| 428 ASSERT_TRUE(AreEqual(ws.GetCloseReason().pp_var(), "")); |
| 429 ASSERT_EQ(false, ws.GetCloseWasClean()); |
| 430 //ASSERT_TRUE(AreEqual(ws.GetExtensions().pp_var(), "")); |
| 431 //ASSERT_TRUE(AreEqual(ws.GetProtocol().pp_var(), "")); |
| 432 ASSERT_EQ(PP_WEBSOCKETREADYSTATE_INVALID_DEV, ws.GetReadyState()); |
| 433 //ASSERT_TRUE(AreEqual(ws.GetURL().pp_var(), "")); |
| 434 |
| 435 // Check communication interfaces (connect, send, and receive). |
| 436 TestCompletionCallback connect_callback(instance_->pp_instance()); |
| 437 int32_t result = ws.Connect(pp::Var(std::string(kEchoServerURL)), NULL, 0U, |
| 438 connect_callback); |
| 439 ASSERT_EQ(PP_OK_COMPLETIONPENDING, result); |
| 440 //result = connect_callback.WaitForResult(); |
| 441 //ASSERT_EQ(PP_OK, result); |
| 442 |
| 443 // TODO(toyoshim): Implement. |
| 444 |
| 445 // Check initialized properties access. |
| 446 // TODO(toyoshim): Implement. |
| 447 |
| 448 PASS(); |
| 449 } |
OLD | NEW |