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> |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 73 was_clean(was_clean), | 73 was_clean(was_clean), |
| 74 close_code(close_code), | 74 close_code(close_code), |
| 75 var(var) { | 75 var(var) { |
| 76 } | 76 } |
| 77 EventType event_type; | 77 EventType event_type; |
| 78 bool was_clean; | 78 bool was_clean; |
| 79 uint16_t close_code; | 79 uint16_t close_code; |
| 80 pp::Var var; | 80 pp::Var var; |
| 81 }; | 81 }; |
| 82 | 82 |
| 83 class ReleaseResourceDelegate : public TestCompletionCallback::Delegate { | |
| 84 public: | |
| 85 explicit ReleaseResourceDelegate(const PPB_Core* core_interface, | |
| 86 PP_Resource resource) | |
| 87 : core_interface_(core_interface), | |
| 88 resource_(resource) { | |
| 89 } | |
| 90 | |
| 91 // TestCompletionCallback::Delegate implementation. | |
| 92 virtual void OnCallback(void* user_data, int32_t result) { | |
|
dmichael (off chromium)
2012/06/26 16:01:40
nit: OVERRIDE
Takashi Toyoshima
2012/06/27 08:09:05
This code is for NaCl targeted compilers, so I thi
| |
| 93 if (resource_) | |
| 94 core_interface_->ReleaseResource(resource_); | |
| 95 } | |
| 96 | |
| 97 private: | |
| 98 const PPB_Core* core_interface_; | |
| 99 PP_Resource resource_; | |
| 100 }; | |
| 101 | |
| 83 class TestWebSocketAPI : public pp::WebSocketAPI { | 102 class TestWebSocketAPI : public pp::WebSocketAPI { |
| 84 public: | 103 public: |
| 85 explicit TestWebSocketAPI(pp::Instance* instance) | 104 explicit TestWebSocketAPI(pp::Instance* instance) |
| 86 : pp::WebSocketAPI(instance), | 105 : pp::WebSocketAPI(instance), |
| 87 connected_(false), | 106 connected_(false), |
| 88 received_(false), | 107 received_(false), |
| 89 closed_(false), | 108 closed_(false), |
| 90 wait_for_connected_(false), | 109 wait_for_connected_(false), |
| 91 wait_for_received_(false), | 110 wait_for_received_(false), |
| 92 wait_for_closed_(false), | 111 wait_for_closed_(false), |
| (...skipping 474 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 567 ws = Connect(GetFullURL(kEchoServerURL), &result, ""); | 586 ws = Connect(GetFullURL(kEchoServerURL), &result, ""); |
| 568 ASSERT_TRUE(ws); | 587 ASSERT_TRUE(ws); |
| 569 ASSERT_EQ(PP_OK, result); | 588 ASSERT_EQ(PP_OK, result); |
| 570 callback.WaitForResult(websocket_interface_->Close( | 589 callback.WaitForResult(websocket_interface_->Close( |
| 571 ws, PP_WEBSOCKETSTATUSCODE_NORMAL_CLOSURE, PP_MakeUndefined(), | 590 ws, PP_WEBSOCKETSTATUSCODE_NORMAL_CLOSURE, PP_MakeUndefined(), |
| 572 callback.GetCallback().pp_completion_callback())); | 591 callback.GetCallback().pp_completion_callback())); |
| 573 CHECK_CALLBACK_BEHAVIOR(callback); | 592 CHECK_CALLBACK_BEHAVIOR(callback); |
| 574 ASSERT_EQ(PP_OK, callback.result()); | 593 ASSERT_EQ(PP_OK, callback.result()); |
| 575 core_interface_->ReleaseResource(ws); | 594 core_interface_->ReleaseResource(ws); |
| 576 | 595 |
| 596 // Release the resource before the completion callback is invoked. | |
|
Takashi Toyoshima
2012/06/27 08:09:05
I notice that we already have this first case in T
| |
| 597 ws = Connect(GetFullURL(kEchoServerURL), &result, ""); | |
| 598 ASSERT_TRUE(ws); | |
| 599 ASSERT_EQ(PP_OK, result); | |
| 600 result = websocket_interface_->Close( | |
| 601 ws, PP_WEBSOCKETSTATUSCODE_NORMAL_CLOSURE, PP_MakeUndefined(), | |
| 602 callback.GetCallback().pp_completion_callback()); | |
| 603 core_interface_->ReleaseResource(ws); | |
| 604 callback.WaitForResult(result); | |
| 605 CHECK_CALLBACK_BEHAVIOR(callback); | |
| 606 ASSERT_EQ(PP_ERROR_ABORTED, callback.result()); | |
| 607 | |
| 608 // Release the resource in the completion callback. | |
| 609 ws = Connect(GetFullURL(kEchoServerURL), &result, ""); | |
| 610 ASSERT_TRUE(ws); | |
| 611 ASSERT_EQ(PP_OK, result); | |
| 612 result = websocket_interface_->Close( | |
| 613 ws, PP_WEBSOCKETSTATUSCODE_NORMAL_CLOSURE, PP_MakeUndefined(), | |
| 614 callback.GetCallback().pp_completion_callback()); | |
| 615 ReleaseResourceDelegate delegate(core_interface_, ws); | |
| 616 callback.SetDelegate(&delegate); | |
| 617 callback.WaitForResult(result); | |
| 618 CHECK_CALLBACK_BEHAVIOR(callback); | |
| 619 ASSERT_EQ(PP_OK, callback.result()); | |
| 620 | |
| 577 // Close in connecting. | 621 // Close in connecting. |
| 578 // The ongoing connect failed with PP_ERROR_ABORTED, then the close is done | 622 // The ongoing connect failed with PP_ERROR_ABORTED, then the close is done |
| 579 // successfully. | 623 // successfully. |
| 580 ws = websocket_interface_->Create(instance_->pp_instance()); | 624 ws = websocket_interface_->Create(instance_->pp_instance()); |
| 581 result = websocket_interface_->Connect( | 625 result = websocket_interface_->Connect( |
| 582 ws, url, protocols, 0U, callback.GetCallback().pp_completion_callback()); | 626 ws, url, protocols, 0U, callback.GetCallback().pp_completion_callback()); |
| 583 ASSERT_EQ(PP_OK_COMPLETIONPENDING, result); | 627 ASSERT_EQ(PP_OK_COMPLETIONPENDING, result); |
| 584 result = websocket_interface_->Close( | 628 result = websocket_interface_->Close( |
| 585 ws, PP_WEBSOCKETSTATUSCODE_NORMAL_CLOSURE, reason, | 629 ws, PP_WEBSOCKETSTATUSCODE_NORMAL_CLOSURE, reason, |
| 586 another_callback.GetCallback().pp_completion_callback()); | 630 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; | 1451 size_t last_event = events_on_closed - 1; |
| 1408 for (uint32_t i = 1; i < last_event; ++i) { | 1452 for (uint32_t i = 1; i < last_event; ++i) { |
| 1409 ASSERT_EQ(WebSocketEvent::EVENT_MESSAGE, events[i].event_type); | 1453 ASSERT_EQ(WebSocketEvent::EVENT_MESSAGE, events[i].event_type); |
| 1410 ASSERT_TRUE(AreEqualWithString(events[i].var.pp_var(), message)); | 1454 ASSERT_TRUE(AreEqualWithString(events[i].var.pp_var(), message)); |
| 1411 } | 1455 } |
| 1412 ASSERT_EQ(WebSocketEvent::EVENT_CLOSE, events[last_event].event_type); | 1456 ASSERT_EQ(WebSocketEvent::EVENT_CLOSE, events[last_event].event_type); |
| 1413 ASSERT_TRUE(events[last_event].was_clean); | 1457 ASSERT_TRUE(events[last_event].was_clean); |
| 1414 | 1458 |
| 1415 PASS(); | 1459 PASS(); |
| 1416 } | 1460 } |
| OLD | NEW |