Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(583)

Side by Side Diff: ppapi/tests/test_websocket.cc

Issue 10661026: WebSocket Pepper API: allow to release in completion callbacks (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: remvoe redundant checker Created 8 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « ppapi/tests/test_utils.cc ('k') | webkit/plugins/ppapi/ppb_websocket_impl.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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) {
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 838 matching lines...) Expand 10 before | Expand all | Expand 10 after
931 TestCompletionCallback receive_callback( 950 TestCompletionCallback receive_callback(
932 instance_->pp_instance(), callback_type()); 951 instance_->pp_instance(), callback_type());
933 result = websocket_interface_->ReceiveMessage( 952 result = websocket_interface_->ReceiveMessage(
934 ws, &receive_var, 953 ws, &receive_var,
935 receive_callback.GetCallback().pp_completion_callback()); 954 receive_callback.GetCallback().pp_completion_callback());
936 ASSERT_EQ(PP_OK_COMPLETIONPENDING, result); 955 ASSERT_EQ(PP_OK_COMPLETIONPENDING, result);
937 core_interface_->ReleaseResource(ws); 956 core_interface_->ReleaseResource(ws);
938 receive_callback.WaitForResult(result); 957 receive_callback.WaitForResult(result);
939 ASSERT_EQ(PP_ERROR_ABORTED, receive_callback.result()); 958 ASSERT_EQ(PP_ERROR_ABORTED, receive_callback.result());
940 959
960 // Release the resource in the close completion callback.
961 ws = Connect(url, &result, "");
962 ASSERT_TRUE(ws);
963 ASSERT_EQ(PP_OK, result);
964 result = websocket_interface_->Close(
965 ws, PP_WEBSOCKETSTATUSCODE_NORMAL_CLOSURE, PP_MakeUndefined(),
966 close_callback.GetCallback().pp_completion_callback());
967 ReleaseResourceDelegate close_delegate(core_interface_, ws);
968 close_callback.SetDelegate(&close_delegate);
969 close_callback.WaitForResult(result);
970 CHECK_CALLBACK_BEHAVIOR(close_callback);
971 ASSERT_EQ(PP_OK, close_callback.result());
972
973 // Release the resource in the aborting receive completion callback which is
974 // introduced by calling Close().
975 ws = Connect(url, &result, "");
976 ASSERT_TRUE(ws);
977 ASSERT_EQ(PP_OK, result);
978 result = websocket_interface_->ReceiveMessage(
979 ws, &receive_var,
980 receive_callback.GetCallback().pp_completion_callback());
981 ASSERT_EQ(PP_OK_COMPLETIONPENDING, result);
982 ReleaseResourceDelegate receive_delegate(core_interface_, ws);
983 receive_callback.SetDelegate(&receive_delegate);
984 result = websocket_interface_->Close(
985 ws, PP_WEBSOCKETSTATUSCODE_NORMAL_CLOSURE, PP_MakeUndefined(),
986 close_callback.GetCallback().pp_completion_callback());
987 ASSERT_EQ(PP_OK_COMPLETIONPENDING, result);
988 receive_callback.WaitForResult(result);
989 CHECK_CALLBACK_BEHAVIOR(receive_callback);
990 ASSERT_EQ(PP_ERROR_ABORTED, receive_callback.result());
991 close_callback.WaitForResult(result);
992 CHECK_CALLBACK_BEHAVIOR(close_callback);
993 ASSERT_EQ(PP_ERROR_ABORTED, close_callback.result());
994
941 // Test the behavior where receive process might be in-flight. 995 // Test the behavior where receive process might be in-flight.
942 const char* text = "yukarin"; 996 const char* text = "yukarin";
943 PP_Var text_var = CreateVarString(text); 997 PP_Var text_var = CreateVarString(text);
944 998
945 // Each trial sends 17 messages and receives just |trial| number of 999 // Each trial sends 17 messages and receives just |trial| number of
946 // message(s) before releasing the WebSocket. The WebSocket is released while 1000 // message(s) before releasing the WebSocket. The WebSocket is released while
947 // the next message is going to be received. 1001 // the next message is going to be received.
948 for (int trial = 1; trial <= 16; trial++) { 1002 for (int trial = 1; trial <= 16; trial++) {
949 ws = Connect(url, &result, ""); 1003 ws = Connect(url, &result, "");
950 ASSERT_TRUE(ws); 1004 ASSERT_TRUE(ws);
(...skipping 456 matching lines...) Expand 10 before | Expand all | Expand 10 after
1407 size_t last_event = events_on_closed - 1; 1461 size_t last_event = events_on_closed - 1;
1408 for (uint32_t i = 1; i < last_event; ++i) { 1462 for (uint32_t i = 1; i < last_event; ++i) {
1409 ASSERT_EQ(WebSocketEvent::EVENT_MESSAGE, events[i].event_type); 1463 ASSERT_EQ(WebSocketEvent::EVENT_MESSAGE, events[i].event_type);
1410 ASSERT_TRUE(AreEqualWithString(events[i].var.pp_var(), message)); 1464 ASSERT_TRUE(AreEqualWithString(events[i].var.pp_var(), message));
1411 } 1465 }
1412 ASSERT_EQ(WebSocketEvent::EVENT_CLOSE, events[last_event].event_type); 1466 ASSERT_EQ(WebSocketEvent::EVENT_CLOSE, events[last_event].event_type);
1413 ASSERT_TRUE(events[last_event].was_clean); 1467 ASSERT_TRUE(events[last_event].was_clean);
1414 1468
1415 PASS(); 1469 PASS();
1416 } 1470 }
OLDNEW
« no previous file with comments | « ppapi/tests/test_utils.cc ('k') | webkit/plugins/ppapi/ppb_websocket_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698