Chromium Code Reviews| 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 <stdio.h> | 7 #include <stdio.h> |
| 8 #include <string.h> | 8 #include <string.h> |
| 9 | 9 |
| 10 #include <algorithm> | 10 #include <algorithm> |
| 11 #include <memory> | 11 #include <memory> |
| 12 #include <string> | 12 #include <string> |
| 13 #include <vector> | 13 #include <vector> |
| 14 | 14 |
| 15 #include "ppapi/c/dev/ppb_testing_dev.h" | 15 #include "ppapi/c/dev/ppb_testing_dev.h" |
| 16 #include "ppapi/c/pp_bool.h" | 16 #include "ppapi/c/pp_bool.h" |
| 17 #include "ppapi/c/pp_completion_callback.h" | 17 #include "ppapi/c/pp_completion_callback.h" |
| 18 #include "ppapi/c/pp_errors.h" | 18 #include "ppapi/c/pp_errors.h" |
| 19 #include "ppapi/c/pp_instance.h" | 19 #include "ppapi/c/pp_instance.h" |
| 20 #include "ppapi/c/pp_resource.h" | 20 #include "ppapi/c/pp_resource.h" |
| 21 #include "ppapi/c/pp_var.h" | 21 #include "ppapi/c/pp_var.h" |
| 22 #include "ppapi/c/ppb_core.h" | 22 #include "ppapi/c/ppb_core.h" |
| 23 #include "ppapi/c/ppb_var.h" | 23 #include "ppapi/c/ppb_var.h" |
| 24 #include "ppapi/c/ppb_var_array_buffer.h" | 24 #include "ppapi/c/ppb_var_array_buffer.h" |
| 25 #include "ppapi/c/ppb_websocket.h" | 25 #include "ppapi/c/ppb_websocket.h" |
| 26 #include "ppapi/cpp/instance.h" | 26 #include "ppapi/cpp/instance.h" |
| 27 #include "ppapi/cpp/module.h" | 27 #include "ppapi/cpp/module.h" |
| 28 #include "ppapi/cpp/var_array_buffer.h" | 28 #include "ppapi/cpp/var_array_buffer.h" |
| 29 #include "ppapi/cpp/websocket.h" | 29 #include "ppapi/cpp/websocket.h" |
| 30 #include "ppapi/tests/test_utils.h" | |
| 31 #include "ppapi/tests/testing_instance.h" | 30 #include "ppapi/tests/testing_instance.h" |
| 32 #include "ppapi/utility/websocket/websocket_api.h" | 31 #include "ppapi/utility/websocket/websocket_api.h" |
| 33 | 32 |
| 34 // These servers are provided by pywebsocket server side handlers in | 33 // These servers are provided by pywebsocket server side handlers in |
| 35 // LayoutTests/http/tests/websocket/tests/hybi/*_wsh. | 34 // LayoutTests/http/tests/websocket/tests/hybi/*_wsh. |
| 36 // pywebsocket server itself is launched in ppapi_ui_test.cc. | 35 // pywebsocket server itself is launched in ppapi_ui_test.cc. |
| 37 const char kEchoServerURL[] = "websocket/tests/hybi/echo-with-no-extension"; | 36 const char kEchoServerURL[] = "websocket/tests/hybi/echo-with-no-extension"; |
| 38 | 37 |
| 39 const char kCloseServerURL[] = "websocket/tests/hybi/close"; | 38 const char kCloseServerURL[] = "websocket/tests/hybi/close"; |
| 40 | 39 |
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 165 bool wait_for_connected_; | 164 bool wait_for_connected_; |
| 166 bool wait_for_received_; | 165 bool wait_for_received_; |
| 167 bool wait_for_closed_; | 166 bool wait_for_closed_; |
| 168 PP_Instance instance_; | 167 PP_Instance instance_; |
| 169 }; | 168 }; |
| 170 | 169 |
| 171 } // namespace | 170 } // namespace |
| 172 | 171 |
| 173 REGISTER_TEST_CASE(WebSocket); | 172 REGISTER_TEST_CASE(WebSocket); |
| 174 | 173 |
| 174 void TestWebSocket::OnCallback(void* user_data, int32_t result) { | |
| 175 if (resource_) | |
| 176 core_interface_->ReleaseResource(resource_); | |
| 177 } | |
| 178 | |
| 175 bool TestWebSocket::Init() { | 179 bool TestWebSocket::Init() { |
| 180 resource_ = 0; | |
| 176 websocket_interface_ = static_cast<const PPB_WebSocket*>( | 181 websocket_interface_ = static_cast<const PPB_WebSocket*>( |
| 177 pp::Module::Get()->GetBrowserInterface(PPB_WEBSOCKET_INTERFACE)); | 182 pp::Module::Get()->GetBrowserInterface(PPB_WEBSOCKET_INTERFACE)); |
| 178 var_interface_ = static_cast<const PPB_Var*>( | 183 var_interface_ = static_cast<const PPB_Var*>( |
| 179 pp::Module::Get()->GetBrowserInterface(PPB_VAR_INTERFACE)); | 184 pp::Module::Get()->GetBrowserInterface(PPB_VAR_INTERFACE)); |
| 180 arraybuffer_interface_ = static_cast<const PPB_VarArrayBuffer*>( | 185 arraybuffer_interface_ = static_cast<const PPB_VarArrayBuffer*>( |
| 181 pp::Module::Get()->GetBrowserInterface( | 186 pp::Module::Get()->GetBrowserInterface( |
| 182 PPB_VAR_ARRAY_BUFFER_INTERFACE)); | 187 PPB_VAR_ARRAY_BUFFER_INTERFACE)); |
| 183 core_interface_ = static_cast<const PPB_Core*>( | 188 core_interface_ = static_cast<const PPB_Core*>( |
| 184 pp::Module::Get()->GetBrowserInterface(PPB_CORE_INTERFACE)); | 189 pp::Module::Get()->GetBrowserInterface(PPB_CORE_INTERFACE)); |
| 185 if (!websocket_interface_ || !var_interface_ || !arraybuffer_interface_ || | 190 if (!websocket_interface_ || !var_interface_ || !arraybuffer_interface_ || |
| (...skipping 381 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 567 ws = Connect(GetFullURL(kEchoServerURL), &result, ""); | 572 ws = Connect(GetFullURL(kEchoServerURL), &result, ""); |
| 568 ASSERT_TRUE(ws); | 573 ASSERT_TRUE(ws); |
| 569 ASSERT_EQ(PP_OK, result); | 574 ASSERT_EQ(PP_OK, result); |
| 570 callback.WaitForResult(websocket_interface_->Close( | 575 callback.WaitForResult(websocket_interface_->Close( |
| 571 ws, PP_WEBSOCKETSTATUSCODE_NORMAL_CLOSURE, PP_MakeUndefined(), | 576 ws, PP_WEBSOCKETSTATUSCODE_NORMAL_CLOSURE, PP_MakeUndefined(), |
| 572 callback.GetCallback().pp_completion_callback())); | 577 callback.GetCallback().pp_completion_callback())); |
| 573 CHECK_CALLBACK_BEHAVIOR(callback); | 578 CHECK_CALLBACK_BEHAVIOR(callback); |
| 574 ASSERT_EQ(PP_OK, callback.result()); | 579 ASSERT_EQ(PP_OK, callback.result()); |
| 575 core_interface_->ReleaseResource(ws); | 580 core_interface_->ReleaseResource(ws); |
| 576 | 581 |
| 582 // Release the resource before completion callback invoked. | |
|
dmichael (off chromium)
2012/06/25 15:50:51
nit: before +the+ completion callback +is+ invoked
Takashi Toyoshima
2012/06/26 09:19:10
Done.
| |
| 583 ws = Connect(GetFullURL(kEchoServerURL), &result, ""); | |
| 584 ASSERT_TRUE(ws); | |
| 585 ASSERT_EQ(PP_OK, result); | |
| 586 result = websocket_interface_->Close( | |
| 587 ws, PP_WEBSOCKETSTATUSCODE_NORMAL_CLOSURE, PP_MakeUndefined(), | |
| 588 callback.GetCallback().pp_completion_callback()); | |
| 589 core_interface_->ReleaseResource(ws); | |
| 590 callback.WaitForResult(result); | |
| 591 CHECK_CALLBACK_BEHAVIOR(callback); | |
| 592 ASSERT_EQ(PP_ERROR_ABORTED, callback.result()); | |
| 593 | |
| 594 // Release the resource in the completion callback. | |
| 595 ws = Connect(GetFullURL(kEchoServerURL), &result, ""); | |
| 596 ASSERT_TRUE(ws); | |
| 597 ASSERT_EQ(PP_OK, result); | |
| 598 result = websocket_interface_->Close( | |
| 599 ws, PP_WEBSOCKETSTATUSCODE_NORMAL_CLOSURE, PP_MakeUndefined(), | |
| 600 callback.GetCallback().pp_completion_callback()); | |
| 601 resource_ = ws; | |
| 602 callback.SetDelegate(this); | |
| 603 callback.WaitForResult(result); | |
| 604 CHECK_CALLBACK_BEHAVIOR(callback); | |
| 605 ASSERT_EQ(PP_OK, callback.result()); | |
| 606 | |
| 577 // Close in connecting. | 607 // Close in connecting. |
| 578 // The ongoing connect failed with PP_ERROR_ABORTED, then the close is done | 608 // The ongoing connect failed with PP_ERROR_ABORTED, then the close is done |
| 579 // successfully. | 609 // successfully. |
| 580 ws = websocket_interface_->Create(instance_->pp_instance()); | 610 ws = websocket_interface_->Create(instance_->pp_instance()); |
| 581 result = websocket_interface_->Connect( | 611 result = websocket_interface_->Connect( |
| 582 ws, url, protocols, 0U, callback.GetCallback().pp_completion_callback()); | 612 ws, url, protocols, 0U, callback.GetCallback().pp_completion_callback()); |
| 583 ASSERT_EQ(PP_OK_COMPLETIONPENDING, result); | 613 ASSERT_EQ(PP_OK_COMPLETIONPENDING, result); |
| 584 result = websocket_interface_->Close( | 614 result = websocket_interface_->Close( |
| 585 ws, PP_WEBSOCKETSTATUSCODE_NORMAL_CLOSURE, reason, | 615 ws, PP_WEBSOCKETSTATUSCODE_NORMAL_CLOSURE, reason, |
| 586 another_callback.GetCallback().pp_completion_callback()); | 616 another_callback.GetCallback().pp_completion_callback()); |
| (...skipping 820 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1407 size_t last_event = events_on_closed - 1; | 1437 size_t last_event = events_on_closed - 1; |
| 1408 for (uint32_t i = 1; i < last_event; ++i) { | 1438 for (uint32_t i = 1; i < last_event; ++i) { |
| 1409 ASSERT_EQ(WebSocketEvent::EVENT_MESSAGE, events[i].event_type); | 1439 ASSERT_EQ(WebSocketEvent::EVENT_MESSAGE, events[i].event_type); |
| 1410 ASSERT_TRUE(AreEqualWithString(events[i].var.pp_var(), message)); | 1440 ASSERT_TRUE(AreEqualWithString(events[i].var.pp_var(), message)); |
| 1411 } | 1441 } |
| 1412 ASSERT_EQ(WebSocketEvent::EVENT_CLOSE, events[last_event].event_type); | 1442 ASSERT_EQ(WebSocketEvent::EVENT_CLOSE, events[last_event].event_type); |
| 1413 ASSERT_TRUE(events[last_event].was_clean); | 1443 ASSERT_TRUE(events[last_event].was_clean); |
| 1414 | 1444 |
| 1415 PASS(); | 1445 PASS(); |
| 1416 } | 1446 } |
| OLD | NEW |