Release 1.5.29.
[wine] / dlls / winhttp / tests / notification.c
1 /*
2  * test status notifications
3  *
4  * Copyright 2008 Hans Leidekker for CodeWeavers
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19  */
20
21 #include <stdarg.h>
22 #include <stdlib.h>
23 #include <windef.h>
24 #include <winbase.h>
25 #include <winhttp.h>
26
27 #include "wine/test.h"
28
29 static const WCHAR user_agent[] = {'w','i','n','e','t','e','s','t',0};
30
31 enum api
32 {
33     winhttp_connect = 1,
34     winhttp_open_request,
35     winhttp_send_request,
36     winhttp_receive_response,
37     winhttp_query_data,
38     winhttp_read_data,
39     winhttp_write_data,
40     winhttp_close_handle
41 };
42
43 struct notification
44 {
45     enum api function;      /* api responsible for notification */
46     unsigned int status;    /* status received */
47     int todo;
48     int ignore;
49     int skipped_for_proxy;
50 };
51
52 struct info
53 {
54     enum api function;
55     const struct notification *test;
56     unsigned int count;
57     unsigned int index;
58     HANDLE wait;
59     unsigned int line;
60 };
61
62 static BOOL proxy_active(void)
63 {
64     WINHTTP_PROXY_INFO proxy_info;
65     BOOL active = FALSE;
66
67     if (WinHttpGetDefaultProxyConfiguration(&proxy_info))
68     {
69         active = (proxy_info.lpszProxy != NULL);
70         if (active)
71             GlobalFree(proxy_info.lpszProxy);
72         if (proxy_info.lpszProxyBypass != NULL)
73             GlobalFree(proxy_info.lpszProxyBypass);
74     }
75     else
76        active = FALSE;
77
78     return active;
79 }
80
81 static void CALLBACK check_notification( HINTERNET handle, DWORD_PTR context, DWORD status, LPVOID buffer, DWORD buflen )
82 {
83     BOOL status_ok, function_ok;
84     struct info *info = (struct info *)context;
85     unsigned int i = info->index;
86
87     if (status == WINHTTP_CALLBACK_STATUS_HANDLE_CREATED)
88     {
89         DWORD size = sizeof(struct info *);
90         WinHttpQueryOption( handle, WINHTTP_OPTION_CONTEXT_VALUE, &info, &size );
91     }
92     ok(i < info->count, "unexpected notification 0x%08x\n", status);
93     if (i >= info->count) return;
94
95     status_ok   = (info->test[i].status == status);
96     function_ok = (info->test[i].function == info->function);
97     if (!info->test[i].ignore && !info->test[i].todo)
98     {
99         ok(status_ok, "%u: expected status 0x%08x got 0x%08x\n", info->line, info->test[i].status, status);
100         ok(function_ok, "%u: expected function %u got %u\n", info->line, info->test[i].function, info->function);
101     }
102     else if (!info->test[i].ignore)
103     {
104         todo_wine ok(status_ok, "%u: expected status 0x%08x got 0x%08x\n", info->line, info->test[i].status, status);
105         if (status_ok)
106         {
107             todo_wine ok(function_ok, "%u: expected function %u got %u\n", info->line, info->test[i].function, info->function);
108         }
109     }
110     if (status_ok) info->index++;
111     if (proxy_active())
112     {
113         while (info->test[info->index].skipped_for_proxy)
114             info->index++;
115     }
116
117     if (status & (WINHTTP_CALLBACK_FLAG_ALL_COMPLETIONS | WINHTTP_CALLBACK_STATUS_HANDLE_CLOSING))
118     {
119         SetEvent( info->wait );
120     }
121 }
122
123 static const struct notification cache_test[] =
124 {
125     { winhttp_connect,          WINHTTP_CALLBACK_STATUS_HANDLE_CREATED, 0 },
126     { winhttp_open_request,     WINHTTP_CALLBACK_STATUS_HANDLE_CREATED, 0 },
127     { winhttp_send_request,     WINHTTP_CALLBACK_STATUS_RESOLVING_NAME, 0 },
128     { winhttp_send_request,     WINHTTP_CALLBACK_STATUS_NAME_RESOLVED, 0 },
129     { winhttp_send_request,     WINHTTP_CALLBACK_STATUS_CONNECTING_TO_SERVER, 0 },
130     { winhttp_send_request,     WINHTTP_CALLBACK_STATUS_CONNECTED_TO_SERVER, 0 },
131     { winhttp_send_request,     WINHTTP_CALLBACK_STATUS_SENDING_REQUEST, 0 },
132     { winhttp_send_request,     WINHTTP_CALLBACK_STATUS_REQUEST_SENT, 0 },
133     { winhttp_receive_response, WINHTTP_CALLBACK_STATUS_RECEIVING_RESPONSE, 0 },
134     { winhttp_receive_response, WINHTTP_CALLBACK_STATUS_RESPONSE_RECEIVED, 0 },
135     { winhttp_close_handle,     WINHTTP_CALLBACK_STATUS_CLOSING_CONNECTION, 0, 1 },
136     { winhttp_close_handle,     WINHTTP_CALLBACK_STATUS_CONNECTION_CLOSED, 0, 1 },
137     { winhttp_close_handle,     WINHTTP_CALLBACK_STATUS_HANDLE_CLOSING, 0, 1 },
138     { winhttp_open_request,     WINHTTP_CALLBACK_STATUS_HANDLE_CREATED, 0 },
139     { winhttp_send_request,     WINHTTP_CALLBACK_STATUS_CONNECTING_TO_SERVER, 0 },
140     { winhttp_send_request,     WINHTTP_CALLBACK_STATUS_CONNECTED_TO_SERVER, 0 },
141     { winhttp_send_request,     WINHTTP_CALLBACK_STATUS_SENDING_REQUEST, 0 },
142     { winhttp_send_request,     WINHTTP_CALLBACK_STATUS_REQUEST_SENT, 0 },
143     { winhttp_receive_response, WINHTTP_CALLBACK_STATUS_RECEIVING_RESPONSE, 0 },
144     { winhttp_receive_response, WINHTTP_CALLBACK_STATUS_RESPONSE_RECEIVED, 0 },
145     { winhttp_close_handle,     WINHTTP_CALLBACK_STATUS_CLOSING_CONNECTION, 0, 1 },
146     { winhttp_close_handle,     WINHTTP_CALLBACK_STATUS_CONNECTION_CLOSED, 0, 1 },
147     { winhttp_close_handle,     WINHTTP_CALLBACK_STATUS_HANDLE_CLOSING, 0, 1 },
148     { winhttp_close_handle,     WINHTTP_CALLBACK_STATUS_HANDLE_CLOSING, 1, 1 },
149     { winhttp_close_handle,     WINHTTP_CALLBACK_STATUS_HANDLE_CLOSING, 1, 1 }
150 };
151
152 static void setup_test( struct info *info, enum api function, unsigned int line )
153 {
154     info->function = function;
155     info->line = line;
156 }
157
158 static void test_connection_cache( void )
159 {
160     static const WCHAR codeweavers[] = {'w','w','w','.','c','o','d','e','w','e','a','v','e','r','s','.','c','o','m',0};
161
162     HANDLE ses, con, req;
163     DWORD size, status;
164     BOOL ret;
165     struct info info, *context = &info;
166
167     info.test  = cache_test;
168     info.count = sizeof(cache_test) / sizeof(cache_test[0]);
169     info.index = 0;
170     info.wait = NULL;
171
172     ses = WinHttpOpen( user_agent, 0, NULL, NULL, 0 );
173     ok(ses != NULL, "failed to open session %u\n", GetLastError());
174
175     WinHttpSetStatusCallback( ses, check_notification, WINHTTP_CALLBACK_FLAG_ALL_NOTIFICATIONS, 0 );
176
177     ret = WinHttpSetOption( ses, WINHTTP_OPTION_CONTEXT_VALUE, &context, sizeof(struct info *) );
178     ok(ret, "failed to set context value %u\n", GetLastError());
179
180     setup_test( &info, winhttp_connect, __LINE__ );
181     con = WinHttpConnect( ses, codeweavers, 0, 0 );
182     ok(con != NULL, "failed to open a connection %u\n", GetLastError());
183
184     setup_test( &info, winhttp_open_request, __LINE__ );
185     req = WinHttpOpenRequest( con, NULL, NULL, NULL, NULL, NULL, 0 );
186     ok(req != NULL, "failed to open a request %u\n", GetLastError());
187
188     setup_test( &info, winhttp_send_request, __LINE__ );
189     ret = WinHttpSendRequest( req, NULL, 0, NULL, 0, 0, 0 );
190     ok(ret, "failed to send request %u\n", GetLastError());
191
192     setup_test( &info, winhttp_receive_response, __LINE__ );
193     ret = WinHttpReceiveResponse( req, NULL );
194     ok(ret, "failed to receive response %u\n", GetLastError());
195
196     size = sizeof(status);
197     ret = WinHttpQueryHeaders( req, WINHTTP_QUERY_STATUS_CODE | WINHTTP_QUERY_FLAG_NUMBER, NULL, &status, &size, NULL );
198     ok(ret, "failed unexpectedly %u\n", GetLastError());
199     ok(status == 200, "request failed unexpectedly %u\n", status);
200
201     setup_test( &info, winhttp_close_handle, __LINE__ );
202     WinHttpCloseHandle( req );
203
204     setup_test( &info, winhttp_open_request, __LINE__ );
205     req = WinHttpOpenRequest( con, NULL, NULL, NULL, NULL, NULL, 0 );
206     ok(req != NULL, "failed to open a request %u\n", GetLastError());
207
208     ret = WinHttpSetOption( req, WINHTTP_OPTION_CONTEXT_VALUE, &context, sizeof(struct info *) );
209     ok(ret, "failed to set context value %u\n", GetLastError());
210
211     setup_test( &info, winhttp_send_request, __LINE__ );
212     ret = WinHttpSendRequest( req, NULL, 0, NULL, 0, 0, 0 );
213     ok(ret, "failed to send request %u\n", GetLastError());
214
215     setup_test( &info, winhttp_receive_response, __LINE__ );
216     ret = WinHttpReceiveResponse( req, NULL );
217     ok(ret, "failed to receive response %u\n", GetLastError());
218
219     size = sizeof(status);
220     ret = WinHttpQueryHeaders( req, WINHTTP_QUERY_STATUS_CODE | WINHTTP_QUERY_FLAG_NUMBER, NULL, &status, &size, NULL );
221     ok(ret, "failed unexpectedly %u\n", GetLastError());
222     ok(status == 200, "request failed unexpectedly %u\n", status);
223
224     setup_test( &info, winhttp_close_handle, __LINE__ );
225     WinHttpCloseHandle( req );
226
227     setup_test( &info, winhttp_close_handle, __LINE__ );
228     WinHttpCloseHandle( req );
229     WinHttpCloseHandle( con );
230     WinHttpCloseHandle( ses );
231
232     Sleep(2000); /* make sure connection is evicted from cache */
233
234     info.index = 0;
235
236     ses = WinHttpOpen( user_agent, 0, NULL, NULL, 0 );
237     ok(ses != NULL, "failed to open session %u\n", GetLastError());
238
239     WinHttpSetStatusCallback( ses, check_notification, WINHTTP_CALLBACK_FLAG_ALL_NOTIFICATIONS, 0 );
240
241     ret = WinHttpSetOption( ses, WINHTTP_OPTION_CONTEXT_VALUE, &context, sizeof(struct info *) );
242     ok(ret, "failed to set context value %u\n", GetLastError());
243
244     setup_test( &info, winhttp_connect, __LINE__ );
245     con = WinHttpConnect( ses, codeweavers, 0, 0 );
246     ok(con != NULL, "failed to open a connection %u\n", GetLastError());
247
248     setup_test( &info, winhttp_open_request, __LINE__ );
249     req = WinHttpOpenRequest( con, NULL, NULL, NULL, NULL, NULL, 0 );
250     ok(req != NULL, "failed to open a request %u\n", GetLastError());
251
252     ret = WinHttpSetOption( req, WINHTTP_OPTION_CONTEXT_VALUE, &context, sizeof(struct info *) );
253     ok(ret, "failed to set context value %u\n", GetLastError());
254
255     setup_test( &info, winhttp_send_request, __LINE__ );
256     ret = WinHttpSendRequest( req, NULL, 0, NULL, 0, 0, 0 );
257     ok(ret, "failed to send request %u\n", GetLastError());
258
259     setup_test( &info, winhttp_receive_response, __LINE__ );
260     ret = WinHttpReceiveResponse( req, NULL );
261     ok(ret, "failed to receive response %u\n", GetLastError());
262
263     size = sizeof(status);
264     ret = WinHttpQueryHeaders( req, WINHTTP_QUERY_STATUS_CODE | WINHTTP_QUERY_FLAG_NUMBER, NULL, &status, &size, NULL );
265     ok(ret, "failed unexpectedly %u\n", GetLastError());
266     ok(status == 200, "request failed unexpectedly %u\n", status);
267
268     setup_test( &info, winhttp_close_handle, __LINE__ );
269     WinHttpCloseHandle( req );
270
271     setup_test( &info, winhttp_open_request, __LINE__ );
272     req = WinHttpOpenRequest( con, NULL, NULL, NULL, NULL, NULL, 0 );
273     ok(req != NULL, "failed to open a request %u\n", GetLastError());
274
275     ret = WinHttpSetOption( req, WINHTTP_OPTION_CONTEXT_VALUE, &context, sizeof(struct info *) );
276     ok(ret, "failed to set context value %u\n", GetLastError());
277
278     setup_test( &info, winhttp_send_request, __LINE__ );
279     ret = WinHttpSendRequest( req, NULL, 0, NULL, 0, 0, 0 );
280     ok(ret, "failed to send request %u\n", GetLastError());
281
282     setup_test( &info, winhttp_receive_response, __LINE__ );
283     ret = WinHttpReceiveResponse( req, NULL );
284     ok(ret, "failed to receive response %u\n", GetLastError());
285
286     size = sizeof(status);
287     ret = WinHttpQueryHeaders( req, WINHTTP_QUERY_STATUS_CODE | WINHTTP_QUERY_FLAG_NUMBER, NULL, &status, &size, NULL );
288     ok(ret, "failed unexpectedly %u\n", GetLastError());
289     ok(status == 200, "request failed unexpectedly %u\n", status);
290
291     setup_test( &info, winhttp_close_handle, __LINE__ );
292     WinHttpCloseHandle( req );
293     WinHttpCloseHandle( con );
294     WinHttpCloseHandle( ses );
295
296     Sleep(2000); /* make sure connection is evicted from cache */
297 }
298
299 static const struct notification redirect_test[] =
300 {
301     { winhttp_connect,          WINHTTP_CALLBACK_STATUS_HANDLE_CREATED, 0 },
302     { winhttp_open_request,     WINHTTP_CALLBACK_STATUS_HANDLE_CREATED, 0 },
303     { winhttp_send_request,     WINHTTP_CALLBACK_STATUS_RESOLVING_NAME, 0 },
304     { winhttp_send_request,     WINHTTP_CALLBACK_STATUS_NAME_RESOLVED, 0 },
305     { winhttp_send_request,     WINHTTP_CALLBACK_STATUS_CONNECTING_TO_SERVER, 0 },
306     { winhttp_send_request,     WINHTTP_CALLBACK_STATUS_CONNECTED_TO_SERVER, 0 },
307     { winhttp_send_request,     WINHTTP_CALLBACK_STATUS_SENDING_REQUEST, 0 },
308     { winhttp_send_request,     WINHTTP_CALLBACK_STATUS_REQUEST_SENT, 0 },
309     { winhttp_receive_response, WINHTTP_CALLBACK_STATUS_RECEIVING_RESPONSE, 0 },
310     { winhttp_receive_response, WINHTTP_CALLBACK_STATUS_RESPONSE_RECEIVED, 0 },
311     { winhttp_receive_response, WINHTTP_CALLBACK_STATUS_REDIRECT, 0 },
312     { winhttp_receive_response, WINHTTP_CALLBACK_STATUS_RESOLVING_NAME, 0, 0, 1 },
313     { winhttp_receive_response, WINHTTP_CALLBACK_STATUS_NAME_RESOLVED, 0, 0, 1 },
314     { winhttp_receive_response, WINHTTP_CALLBACK_STATUS_CONNECTING_TO_SERVER, 0, 0, 1 },
315     { winhttp_receive_response, WINHTTP_CALLBACK_STATUS_CONNECTED_TO_SERVER, 0, 0, 1 },
316     { winhttp_receive_response, WINHTTP_CALLBACK_STATUS_SENDING_REQUEST, 0 },
317     { winhttp_receive_response, WINHTTP_CALLBACK_STATUS_REQUEST_SENT, 0 },
318     { winhttp_receive_response, WINHTTP_CALLBACK_STATUS_RECEIVING_RESPONSE, 0 },
319     { winhttp_receive_response, WINHTTP_CALLBACK_STATUS_RESPONSE_RECEIVED, 0 },
320     { winhttp_close_handle,     WINHTTP_CALLBACK_STATUS_CLOSING_CONNECTION, 0, 1 },
321     { winhttp_close_handle,     WINHTTP_CALLBACK_STATUS_CONNECTION_CLOSED, 0, 1 },
322     { winhttp_close_handle,     WINHTTP_CALLBACK_STATUS_HANDLE_CLOSING, 0, 1 },
323     { winhttp_close_handle,     WINHTTP_CALLBACK_STATUS_HANDLE_CLOSING, 1, 1 },
324     { winhttp_close_handle,     WINHTTP_CALLBACK_STATUS_HANDLE_CLOSING, 1, 1 }
325 };
326
327 static void test_redirect( void )
328 {
329     static const WCHAR codeweavers[] = {'c','o','d','e','w','e','a','v','e','r','s','.','c','o','m',0};
330
331     HANDLE ses, con, req;
332     DWORD size, status;
333     BOOL ret;
334     struct info info, *context = &info;
335
336     info.test  = redirect_test;
337     info.count = sizeof(redirect_test) / sizeof(redirect_test[0]);
338     info.index = 0;
339     info.wait = NULL;
340
341     ses = WinHttpOpen( user_agent, 0, NULL, NULL, 0 );
342     ok(ses != NULL, "failed to open session %u\n", GetLastError());
343
344     WinHttpSetStatusCallback( ses, check_notification, WINHTTP_CALLBACK_FLAG_ALL_NOTIFICATIONS, 0 );
345
346     ret = WinHttpSetOption( ses, WINHTTP_OPTION_CONTEXT_VALUE, &context, sizeof(struct info *) );
347     ok(ret, "failed to set context value %u\n", GetLastError());
348
349     setup_test( &info, winhttp_connect, __LINE__ );
350     con = WinHttpConnect( ses, codeweavers, 0, 0 );
351     ok(con != NULL, "failed to open a connection %u\n", GetLastError());
352
353     setup_test( &info, winhttp_open_request, __LINE__ );
354     req = WinHttpOpenRequest( con, NULL, NULL, NULL, NULL, NULL, 0 );
355     ok(req != NULL, "failed to open a request %u\n", GetLastError());
356
357     setup_test( &info, winhttp_send_request, __LINE__ );
358     ret = WinHttpSendRequest( req, NULL, 0, NULL, 0, 0, 0 );
359     ok(ret, "failed to send request %u\n", GetLastError());
360
361     setup_test( &info, winhttp_receive_response, __LINE__ );
362     ret = WinHttpReceiveResponse( req, NULL );
363     ok(ret, "failed to receive response %u\n", GetLastError());
364
365     size = sizeof(status);
366     ret = WinHttpQueryHeaders( req, WINHTTP_QUERY_STATUS_CODE | WINHTTP_QUERY_FLAG_NUMBER, NULL, &status, &size, NULL );
367     ok(ret, "failed unexpectedly %u\n", GetLastError());
368     ok(status == 200, "request failed unexpectedly %u\n", status);
369
370     setup_test( &info, winhttp_close_handle, __LINE__ );
371     WinHttpCloseHandle( req );
372     WinHttpCloseHandle( con );
373     WinHttpCloseHandle( ses );
374 }
375
376 static const struct notification async_test[] =
377 {
378     { winhttp_connect,          WINHTTP_CALLBACK_STATUS_HANDLE_CREATED, 0 },
379     { winhttp_open_request,     WINHTTP_CALLBACK_STATUS_HANDLE_CREATED, 0 },
380     { winhttp_send_request,     WINHTTP_CALLBACK_STATUS_RESOLVING_NAME, 0 },
381     { winhttp_send_request,     WINHTTP_CALLBACK_STATUS_NAME_RESOLVED, 0 },
382     { winhttp_send_request,     WINHTTP_CALLBACK_STATUS_CONNECTING_TO_SERVER, 0 },
383     { winhttp_send_request,     WINHTTP_CALLBACK_STATUS_CONNECTED_TO_SERVER, 0 },
384     { winhttp_send_request,     WINHTTP_CALLBACK_STATUS_SENDING_REQUEST, 0 },
385     { winhttp_send_request,     WINHTTP_CALLBACK_STATUS_REQUEST_SENT, 0 },
386     { winhttp_send_request,     WINHTTP_CALLBACK_STATUS_SENDREQUEST_COMPLETE, 0 },
387     { winhttp_receive_response, WINHTTP_CALLBACK_STATUS_RECEIVING_RESPONSE, 0 },
388     { winhttp_receive_response, WINHTTP_CALLBACK_STATUS_RESPONSE_RECEIVED, 0 },
389     { winhttp_receive_response, WINHTTP_CALLBACK_STATUS_REDIRECT, 0 },
390     { winhttp_receive_response, WINHTTP_CALLBACK_STATUS_RESOLVING_NAME, 0, 0, 1 },
391     { winhttp_receive_response, WINHTTP_CALLBACK_STATUS_NAME_RESOLVED, 0, 0, 1 },
392     { winhttp_receive_response, WINHTTP_CALLBACK_STATUS_CONNECTING_TO_SERVER, 0, 0, 1 },
393     { winhttp_receive_response, WINHTTP_CALLBACK_STATUS_CONNECTED_TO_SERVER, 0, 0, 1 },
394     { winhttp_receive_response, WINHTTP_CALLBACK_STATUS_SENDING_REQUEST, 0 },
395     { winhttp_receive_response, WINHTTP_CALLBACK_STATUS_REQUEST_SENT, 0 },
396     { winhttp_receive_response, WINHTTP_CALLBACK_STATUS_RECEIVING_RESPONSE, 0 },
397     { winhttp_receive_response, WINHTTP_CALLBACK_STATUS_RESPONSE_RECEIVED, 0 },
398     { winhttp_receive_response, WINHTTP_CALLBACK_STATUS_HEADERS_AVAILABLE, 0 },
399     { winhttp_query_data,       WINHTTP_CALLBACK_STATUS_DATA_AVAILABLE, 0 },
400     { winhttp_read_data,        WINHTTP_CALLBACK_STATUS_RECEIVING_RESPONSE, 0, 1 },
401     { winhttp_read_data,        WINHTTP_CALLBACK_STATUS_RESPONSE_RECEIVED, 0, 1 },
402     { winhttp_read_data,        WINHTTP_CALLBACK_STATUS_READ_COMPLETE, 0, 1 },
403     { winhttp_close_handle,     WINHTTP_CALLBACK_STATUS_CLOSING_CONNECTION, 0, 1 },
404     { winhttp_close_handle,     WINHTTP_CALLBACK_STATUS_CONNECTION_CLOSED, 0, 1 },
405     { winhttp_close_handle,     WINHTTP_CALLBACK_STATUS_HANDLE_CLOSING, 0, 1 },
406     { winhttp_close_handle,     WINHTTP_CALLBACK_STATUS_HANDLE_CLOSING, 1, 1 },
407     { winhttp_close_handle,     WINHTTP_CALLBACK_STATUS_HANDLE_CLOSING, 1, 1 }
408 };
409
410 static void test_async( void )
411 {
412     static const WCHAR codeweavers[] = {'c','o','d','e','w','e','a','v','e','r','s','.','c','o','m',0};
413
414     HANDLE ses, con, req;
415     DWORD size, status;
416     BOOL ret;
417     struct info info, *context = &info;
418     char buffer[1024];
419
420     info.test  = async_test;
421     info.count = sizeof(async_test) / sizeof(async_test[0]);
422     info.index = 0;
423     info.wait = CreateEvent( NULL, FALSE, FALSE, NULL );
424
425     ses = WinHttpOpen( user_agent, 0, NULL, NULL, WINHTTP_FLAG_ASYNC );
426     ok(ses != NULL, "failed to open session %u\n", GetLastError());
427
428     WinHttpSetStatusCallback( ses, check_notification, WINHTTP_CALLBACK_FLAG_ALL_NOTIFICATIONS, 0 );
429
430     ret = WinHttpSetOption( ses, WINHTTP_OPTION_CONTEXT_VALUE, &context, sizeof(struct info *) );
431     ok(ret, "failed to set context value %u\n", GetLastError());
432
433     setup_test( &info, winhttp_connect, __LINE__ );
434     con = WinHttpConnect( ses, codeweavers, 0, 0 );
435     ok(con != NULL, "failed to open a connection %u\n", GetLastError());
436
437     setup_test( &info, winhttp_open_request, __LINE__ );
438     req = WinHttpOpenRequest( con, NULL, NULL, NULL, NULL, NULL, 0 );
439     ok(req != NULL, "failed to open a request %u\n", GetLastError());
440
441     setup_test( &info, winhttp_send_request, __LINE__ );
442     ret = WinHttpSendRequest( req, NULL, 0, NULL, 0, 0, 0 );
443     ok(ret, "failed to send request %u\n", GetLastError());
444
445     WaitForSingleObject( info.wait, INFINITE );
446
447     setup_test( &info, winhttp_receive_response, __LINE__ );
448     ret = WinHttpReceiveResponse( req, NULL );
449     ok(ret, "failed to receive response %u\n", GetLastError());
450
451     WaitForSingleObject( info.wait, INFINITE );
452
453     size = sizeof(status);
454     ret = WinHttpQueryHeaders( req, WINHTTP_QUERY_STATUS_CODE | WINHTTP_QUERY_FLAG_NUMBER, NULL, &status, &size, NULL );
455     ok(ret, "failed unexpectedly %u\n", GetLastError());
456     ok(status == 200, "request failed unexpectedly %u\n", status);
457
458     setup_test( &info, winhttp_query_data, __LINE__ );
459     ret = WinHttpQueryDataAvailable( req, NULL );
460     ok(ret, "failed to query data available %u\n", GetLastError());
461
462     WaitForSingleObject( info.wait, INFINITE );
463
464     setup_test( &info, winhttp_read_data, __LINE__ );
465     ret = WinHttpReadData( req, buffer, sizeof(buffer), NULL );
466     ok(ret, "failed to query data available %u\n", GetLastError());
467
468     WaitForSingleObject( info.wait, INFINITE );
469
470     setup_test( &info, winhttp_close_handle, __LINE__ );
471     WinHttpCloseHandle( req );
472     WinHttpCloseHandle( con );
473     WinHttpCloseHandle( ses );
474
475     WaitForSingleObject( info.wait, INFINITE );
476     CloseHandle( info.wait );
477 }
478
479 START_TEST (notification)
480 {
481     test_connection_cache();
482     test_redirect();
483     Sleep(2000); /* make sure previous connection is evicted from cache */
484     test_async();
485 }