winhttp/tests: Test shutting down websocket when receive is pending.
Signed-off-by: Paul Gofman <pgofman@codeweavers.com> Signed-off-by: Hans Leidekker <hans@codeweavers.com> Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
parent
be921fb386
commit
63ce184f9a
|
@ -707,6 +707,30 @@ static const struct notification websocket_test2[] =
|
||||||
{ winhttp_close_handle, WINHTTP_CALLBACK_STATUS_HANDLE_CLOSING },
|
{ winhttp_close_handle, WINHTTP_CALLBACK_STATUS_HANDLE_CLOSING },
|
||||||
{ winhttp_close_handle, WINHTTP_CALLBACK_STATUS_CLOSING_CONNECTION, NF_WINE_ALLOW },
|
{ winhttp_close_handle, WINHTTP_CALLBACK_STATUS_CLOSING_CONNECTION, NF_WINE_ALLOW },
|
||||||
{ winhttp_close_handle, WINHTTP_CALLBACK_STATUS_CONNECTION_CLOSED, NF_WINE_ALLOW },
|
{ winhttp_close_handle, WINHTTP_CALLBACK_STATUS_CONNECTION_CLOSED, NF_WINE_ALLOW },
|
||||||
|
{ winhttp_close_handle, WINHTTP_CALLBACK_STATUS_HANDLE_CLOSING, NF_SIGNAL }
|
||||||
|
};
|
||||||
|
|
||||||
|
static const struct notification websocket_test3[] =
|
||||||
|
{
|
||||||
|
{ winhttp_open_request, WINHTTP_CALLBACK_STATUS_HANDLE_CREATED },
|
||||||
|
{ winhttp_send_request, WINHTTP_CALLBACK_STATUS_RESOLVING_NAME, NF_ALLOW },
|
||||||
|
{ winhttp_send_request, WINHTTP_CALLBACK_STATUS_NAME_RESOLVED, NF_ALLOW },
|
||||||
|
{ winhttp_send_request, WINHTTP_CALLBACK_STATUS_CONNECTING_TO_SERVER },
|
||||||
|
{ winhttp_send_request, WINHTTP_CALLBACK_STATUS_CONNECTED_TO_SERVER },
|
||||||
|
{ winhttp_send_request, WINHTTP_CALLBACK_STATUS_SENDING_REQUEST },
|
||||||
|
{ winhttp_send_request, WINHTTP_CALLBACK_STATUS_REQUEST_SENT },
|
||||||
|
{ winhttp_send_request, WINHTTP_CALLBACK_STATUS_SENDREQUEST_COMPLETE, NF_SIGNAL },
|
||||||
|
{ winhttp_receive_response, WINHTTP_CALLBACK_STATUS_RECEIVING_RESPONSE },
|
||||||
|
{ winhttp_receive_response, WINHTTP_CALLBACK_STATUS_RESPONSE_RECEIVED },
|
||||||
|
{ winhttp_receive_response, WINHTTP_CALLBACK_STATUS_HEADERS_AVAILABLE, NF_SIGNAL },
|
||||||
|
{ winhttp_websocket_complete_upgrade, WINHTTP_CALLBACK_STATUS_HANDLE_CREATED, NF_SIGNAL },
|
||||||
|
{ winhttp_websocket_receive, WINHTTP_CALLBACK_STATUS_READ_COMPLETE, NF_SIGNAL },
|
||||||
|
|
||||||
|
{ winhttp_websocket_shutdown, WINHTTP_CALLBACK_STATUS_SHUTDOWN_COMPLETE, NF_MAIN_THREAD },
|
||||||
|
{ winhttp_websocket_shutdown, WINHTTP_CALLBACK_STATUS_READ_COMPLETE, NF_SAVE_BUFFER | NF_SIGNAL },
|
||||||
|
{ winhttp_close_handle, WINHTTP_CALLBACK_STATUS_HANDLE_CLOSING },
|
||||||
|
{ winhttp_close_handle, WINHTTP_CALLBACK_STATUS_CLOSING_CONNECTION, NF_WINE_ALLOW },
|
||||||
|
{ winhttp_close_handle, WINHTTP_CALLBACK_STATUS_CONNECTION_CLOSED, NF_WINE_ALLOW },
|
||||||
{ winhttp_close_handle, WINHTTP_CALLBACK_STATUS_HANDLE_CLOSING },
|
{ winhttp_close_handle, WINHTTP_CALLBACK_STATUS_HANDLE_CLOSING },
|
||||||
{ winhttp_close_handle, WINHTTP_CALLBACK_STATUS_HANDLE_CLOSING },
|
{ winhttp_close_handle, WINHTTP_CALLBACK_STATUS_HANDLE_CLOSING },
|
||||||
{ winhttp_close_handle, WINHTTP_CALLBACK_STATUS_HANDLE_CLOSING, NF_SIGNAL }
|
{ winhttp_close_handle, WINHTTP_CALLBACK_STATUS_HANDLE_CLOSING, NF_SIGNAL }
|
||||||
|
@ -996,7 +1020,7 @@ static void test_websocket(BOOL secure)
|
||||||
ok( err == ERROR_SUCCESS, "got %u\n", err );
|
ok( err == ERROR_SUCCESS, "got %u\n", err );
|
||||||
|
|
||||||
setup_test( &info, winhttp_websocket_close, __LINE__ );
|
setup_test( &info, winhttp_websocket_close, __LINE__ );
|
||||||
ret = pWinHttpWebSocketClose( socket, 1000, (void *)"success", sizeof("success") );
|
err = pWinHttpWebSocketClose( socket, 1000, (void *)"success", sizeof("success") );
|
||||||
ok( err == ERROR_SUCCESS, "got %u\n", err );
|
ok( err == ERROR_SUCCESS, "got %u\n", err );
|
||||||
ok( info.buflen == sizeof(*result), "got unexpected buflen %u.\n", info.buflen );
|
ok( info.buflen == sizeof(*result), "got unexpected buflen %u.\n", info.buflen );
|
||||||
result = (WINHTTP_WEB_SOCKET_ASYNC_RESULT *)info.buffer;
|
result = (WINHTTP_WEB_SOCKET_ASYNC_RESULT *)info.buffer;
|
||||||
|
@ -1022,6 +1046,90 @@ static void test_websocket(BOOL secure)
|
||||||
ok( close_status == 1000, "got %u\n", close_status );
|
ok( close_status == 1000, "got %u\n", close_status );
|
||||||
ok( size <= sizeof(buffer), "got %u\n", size );
|
ok( size <= sizeof(buffer), "got %u\n", size );
|
||||||
|
|
||||||
|
setup_test( &info, winhttp_close_handle, __LINE__ );
|
||||||
|
WinHttpCloseHandle( socket );
|
||||||
|
WinHttpCloseHandle( request );
|
||||||
|
|
||||||
|
WaitForSingleObject( info.wait, INFINITE );
|
||||||
|
end_test( &info, __LINE__ );
|
||||||
|
|
||||||
|
/* Test socket shutdown while receive is pending. */
|
||||||
|
info.test = websocket_test3;
|
||||||
|
info.count = ARRAY_SIZE( websocket_test3 );
|
||||||
|
info.index = 0;
|
||||||
|
|
||||||
|
setup_test( &info, winhttp_open_request, __LINE__ );
|
||||||
|
request = WinHttpOpenRequest( connection, NULL, L"/", NULL, NULL, NULL, secure ? WINHTTP_FLAG_SECURE : 0);
|
||||||
|
ok( request != NULL, "got %u\n", err );
|
||||||
|
|
||||||
|
if (secure)
|
||||||
|
{
|
||||||
|
flags = SECURITY_FLAG_IGNORE_UNKNOWN_CA | SECURITY_FLAG_IGNORE_CERT_DATE_INVALID |
|
||||||
|
SECURITY_FLAG_IGNORE_CERT_CN_INVALID;
|
||||||
|
ret = WinHttpSetOption(request, WINHTTP_OPTION_SECURITY_FLAGS, &flags, sizeof(flags));
|
||||||
|
ok(ret, "failed to set security flags %u\n", GetLastError());
|
||||||
|
}
|
||||||
|
|
||||||
|
ret = WinHttpSetOption( request, WINHTTP_OPTION_UPGRADE_TO_WEB_SOCKET, NULL, 0 );
|
||||||
|
ok( ret, "got %u\n", GetLastError() );
|
||||||
|
|
||||||
|
setup_test( &info, winhttp_send_request, __LINE__ );
|
||||||
|
ret = WinHttpSendRequest( request, NULL, 0, NULL, 0, 0, 0 );
|
||||||
|
ok( ret, "got %u\n", GetLastError() );
|
||||||
|
WaitForSingleObject( info.wait, INFINITE );
|
||||||
|
|
||||||
|
setup_test( &info, winhttp_receive_response, __LINE__ );
|
||||||
|
ret = WinHttpReceiveResponse( request, NULL );
|
||||||
|
ok( ret, "got %u\n", err );
|
||||||
|
WaitForSingleObject( info.wait, INFINITE );
|
||||||
|
|
||||||
|
size = sizeof(status);
|
||||||
|
ret = WinHttpQueryHeaders( request, WINHTTP_QUERY_STATUS_CODE|WINHTTP_QUERY_FLAG_NUMBER, NULL, &status, &size, NULL );
|
||||||
|
ok( ret, "failed unexpectedly %u\n", err );
|
||||||
|
ok( status == 101, "got %u\n", status );
|
||||||
|
|
||||||
|
setup_test( &info, winhttp_websocket_complete_upgrade, __LINE__ );
|
||||||
|
socket = pWinHttpWebSocketCompleteUpgrade( request, (DWORD_PTR)context );
|
||||||
|
ok( socket != NULL, "got %u\n", err );
|
||||||
|
WaitForSingleObject( info.wait, INFINITE );
|
||||||
|
|
||||||
|
setup_test( &info, winhttp_websocket_receive, __LINE__ );
|
||||||
|
buffer[0] = 0;
|
||||||
|
err = pWinHttpWebSocketReceive( socket, buffer, sizeof(buffer), &size, &type );
|
||||||
|
ok( err == ERROR_SUCCESS, "got %u\n", err );
|
||||||
|
WaitForSingleObject( info.wait, INFINITE );
|
||||||
|
ok( buffer[0] == 'R', "unexpected data\n" );
|
||||||
|
|
||||||
|
err = pWinHttpWebSocketReceive( socket, buffer, sizeof(buffer), &size, &type );
|
||||||
|
ok( err == ERROR_SUCCESS, "got %u\n", err );
|
||||||
|
|
||||||
|
setup_test( &info, winhttp_websocket_shutdown, __LINE__ );
|
||||||
|
ws_status = (WINHTTP_WEB_SOCKET_STATUS *)info.buffer;
|
||||||
|
ws_status->eBufferType = ~0u;
|
||||||
|
err = pWinHttpWebSocketShutdown( socket, 1000, (void *)"success", sizeof("success") );
|
||||||
|
ok( err == ERROR_SUCCESS, "got %u\n", err );
|
||||||
|
|
||||||
|
close_status = 0xdead;
|
||||||
|
size = sizeof(buffer) + 1;
|
||||||
|
err = pWinHttpWebSocketQueryCloseStatus( socket, &close_status, buffer, sizeof(buffer), &size );
|
||||||
|
ok( err == ERROR_INVALID_OPERATION, "got %u\n", err );
|
||||||
|
ok( close_status == 0xdead, "got %u\n", close_status );
|
||||||
|
ok( size == sizeof(buffer) + 1, "got %u\n", size );
|
||||||
|
|
||||||
|
WaitForSingleObject( info.wait, INFINITE );
|
||||||
|
|
||||||
|
ok( info.buflen == sizeof(*ws_status), "got unexpected buflen %u.\n", info.buflen );
|
||||||
|
ok( ws_status->eBufferType == WINHTTP_WEB_SOCKET_CLOSE_BUFFER_TYPE, "Got unexpected eBufferType %u.\n",
|
||||||
|
ws_status->eBufferType );
|
||||||
|
ok( !ws_status->dwBytesTransferred, "got unexpected dwBytesTransferred %u.\n", ws_status->dwBytesTransferred );
|
||||||
|
|
||||||
|
close_status = 0xdead;
|
||||||
|
size = sizeof(buffer) + 1;
|
||||||
|
err = pWinHttpWebSocketQueryCloseStatus( socket, &close_status, buffer, sizeof(buffer), &size );
|
||||||
|
todo_wine ok( err == ERROR_SUCCESS, "got %u\n", err );
|
||||||
|
todo_wine ok( close_status == 1000, "got %u\n", close_status );
|
||||||
|
todo_wine ok( size <= sizeof(buffer), "got %u\n", size );
|
||||||
|
|
||||||
setup_test( &info, winhttp_close_handle, __LINE__ );
|
setup_test( &info, winhttp_close_handle, __LINE__ );
|
||||||
|
|
||||||
WinHttpCloseHandle( socket );
|
WinHttpCloseHandle( socket );
|
||||||
|
|
Loading…
Reference in New Issue