4 * Copyright 2002 Aric Stewart
5 * Copyright 2004 Mike McCormack
6 * Copyright 2005 Hans Leidekker
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
32 #include "wine/test.h"
34 #define TEST_URL "http://www.winehq.org/site/about"
36 static BOOL first_connection_to_test_url = TRUE;
38 /* Adapted from dlls/urlmon/tests/protocol.c */
40 #define SET_EXPECT2(status, num) \
43 #define SET_EXPECT(status) \
44 SET_EXPECT2(status, 1)
46 /* SET_WINE_ALLOW's should be used with an appropriate
47 * todo_wine CHECK_NOTIFIED at a later point in the code */
48 #define SET_WINE_ALLOW2(status, num) \
49 wine_allow[status] = num
51 #define SET_WINE_ALLOW(status) \
52 SET_WINE_ALLOW2(status, 1)
54 #define CHECK_EXPECT(status) \
56 if (!expect[status] && wine_allow[status]) \
58 todo_wine ok(expect[status], "unexpected status %d (%s)\n", status, \
59 status < MAX_INTERNET_STATUS && status_string[status][0] != 0 ? \
60 status_string[status] : "unknown"); \
61 wine_allow[status]--; \
65 ok(expect[status], "unexpected status %d (%s)\n", status, \
66 status < MAX_INTERNET_STATUS && status_string[status][0] != 0 ? \
67 status_string[status] : "unknown"); \
73 /* CLEAR_NOTIFIED used in cases when notification behavior
74 * differs between Windows versions */
75 #define CLEAR_NOTIFIED(status) \
76 expect[status] = wine_allow[status] = notified[status] = 0;
78 #define CHECK_NOTIFIED2(status, num) \
80 ok(notified[status] == (num), "expected status %d (%s) %d times, received %d times\n", \
81 status, status < MAX_INTERNET_STATUS && status_string[status][0] != 0 ? \
82 status_string[status] : "unknown", (num), notified[status]); \
83 CLEAR_NOTIFIED(status); \
86 #define CHECK_NOTIFIED(status) \
87 CHECK_NOTIFIED2(status, 1)
89 #define CHECK_NOT_NOTIFIED(status) \
90 CHECK_NOTIFIED2(status, 0)
92 #define MAX_INTERNET_STATUS (INTERNET_STATUS_COOKIE_HISTORY+1)
93 #define MAX_STATUS_NAME 50
94 static int expect[MAX_INTERNET_STATUS], wine_allow[MAX_INTERNET_STATUS],
95 notified[MAX_INTERNET_STATUS];
96 static CHAR status_string[MAX_INTERNET_STATUS][MAX_STATUS_NAME];
98 static HANDLE hCompleteEvent;
100 static INTERNET_STATUS_CALLBACK (WINAPI *pInternetSetStatusCallbackA)(HINTERNET ,INTERNET_STATUS_CALLBACK);
101 static BOOL (WINAPI *pInternetTimeFromSystemTimeA)(CONST SYSTEMTIME *,DWORD ,LPSTR ,DWORD);
102 static BOOL (WINAPI *pInternetTimeFromSystemTimeW)(CONST SYSTEMTIME *,DWORD ,LPWSTR ,DWORD);
103 static BOOL (WINAPI *pInternetTimeToSystemTimeA)(LPCSTR ,SYSTEMTIME *,DWORD);
104 static BOOL (WINAPI *pInternetTimeToSystemTimeW)(LPCWSTR ,SYSTEMTIME *,DWORD);
107 static VOID WINAPI callback(
110 DWORD dwInternetStatus,
111 LPVOID lpvStatusInformation,
112 DWORD dwStatusInformationLength
115 CHECK_EXPECT(dwInternetStatus);
116 switch (dwInternetStatus)
118 case INTERNET_STATUS_RESOLVING_NAME:
119 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_RESOLVING_NAME \"%s\" %d\n",
120 GetCurrentThreadId(), hInternet, dwContext,
121 (LPCSTR)lpvStatusInformation,dwStatusInformationLength);
122 *(LPSTR)lpvStatusInformation = '\0';
124 case INTERNET_STATUS_NAME_RESOLVED:
125 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_NAME_RESOLVED \"%s\" %d\n",
126 GetCurrentThreadId(), hInternet, dwContext,
127 (LPCSTR)lpvStatusInformation,dwStatusInformationLength);
128 *(LPSTR)lpvStatusInformation = '\0';
130 case INTERNET_STATUS_CONNECTING_TO_SERVER:
131 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_CONNECTING_TO_SERVER \"%s\" %d\n",
132 GetCurrentThreadId(), hInternet, dwContext,
133 (LPCSTR)lpvStatusInformation,dwStatusInformationLength);
134 *(LPSTR)lpvStatusInformation = '\0';
136 case INTERNET_STATUS_CONNECTED_TO_SERVER:
137 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_CONNECTED_TO_SERVER \"%s\" %d\n",
138 GetCurrentThreadId(), hInternet, dwContext,
139 (LPCSTR)lpvStatusInformation,dwStatusInformationLength);
140 *(LPSTR)lpvStatusInformation = '\0';
142 case INTERNET_STATUS_SENDING_REQUEST:
143 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_SENDING_REQUEST %p %d\n",
144 GetCurrentThreadId(), hInternet, dwContext,
145 lpvStatusInformation,dwStatusInformationLength);
147 case INTERNET_STATUS_REQUEST_SENT:
148 ok(dwStatusInformationLength == sizeof(DWORD),
149 "info length should be sizeof(DWORD) instead of %d\n",
150 dwStatusInformationLength);
151 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_REQUEST_SENT 0x%x %d\n",
152 GetCurrentThreadId(), hInternet, dwContext,
153 *(DWORD *)lpvStatusInformation,dwStatusInformationLength);
155 case INTERNET_STATUS_RECEIVING_RESPONSE:
156 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_RECEIVING_RESPONSE %p %d\n",
157 GetCurrentThreadId(), hInternet, dwContext,
158 lpvStatusInformation,dwStatusInformationLength);
160 case INTERNET_STATUS_RESPONSE_RECEIVED:
161 ok(dwStatusInformationLength == sizeof(DWORD),
162 "info length should be sizeof(DWORD) instead of %d\n",
163 dwStatusInformationLength);
164 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_RESPONSE_RECEIVED 0x%x %d\n",
165 GetCurrentThreadId(), hInternet, dwContext,
166 *(DWORD *)lpvStatusInformation,dwStatusInformationLength);
168 case INTERNET_STATUS_CTL_RESPONSE_RECEIVED:
169 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_CTL_RESPONSE_RECEIVED %p %d\n",
170 GetCurrentThreadId(), hInternet,dwContext,
171 lpvStatusInformation,dwStatusInformationLength);
173 case INTERNET_STATUS_PREFETCH:
174 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_PREFETCH %p %d\n",
175 GetCurrentThreadId(), hInternet, dwContext,
176 lpvStatusInformation,dwStatusInformationLength);
178 case INTERNET_STATUS_CLOSING_CONNECTION:
179 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_CLOSING_CONNECTION %p %d\n",
180 GetCurrentThreadId(), hInternet, dwContext,
181 lpvStatusInformation,dwStatusInformationLength);
183 case INTERNET_STATUS_CONNECTION_CLOSED:
184 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_CONNECTION_CLOSED %p %d\n",
185 GetCurrentThreadId(), hInternet, dwContext,
186 lpvStatusInformation,dwStatusInformationLength);
188 case INTERNET_STATUS_HANDLE_CREATED:
189 ok(dwStatusInformationLength == sizeof(HINTERNET),
190 "info length should be sizeof(HINTERNET) instead of %d\n",
191 dwStatusInformationLength);
192 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_HANDLE_CREATED %p %d\n",
193 GetCurrentThreadId(), hInternet, dwContext,
194 *(HINTERNET *)lpvStatusInformation,dwStatusInformationLength);
195 CLEAR_NOTIFIED(INTERNET_STATUS_DETECTING_PROXY);
196 SET_EXPECT(INTERNET_STATUS_DETECTING_PROXY);
198 case INTERNET_STATUS_HANDLE_CLOSING:
199 ok(dwStatusInformationLength == sizeof(HINTERNET),
200 "info length should be sizeof(HINTERNET) instead of %d\n",
201 dwStatusInformationLength);
202 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_HANDLE_CLOSING %p %d\n",
203 GetCurrentThreadId(), hInternet, dwContext,
204 *(HINTERNET *)lpvStatusInformation, dwStatusInformationLength);
206 case INTERNET_STATUS_REQUEST_COMPLETE:
208 INTERNET_ASYNC_RESULT *iar = (INTERNET_ASYNC_RESULT *)lpvStatusInformation;
209 ok(dwStatusInformationLength == sizeof(INTERNET_ASYNC_RESULT),
210 "info length should be sizeof(INTERNET_ASYNC_RESULT) instead of %d\n",
211 dwStatusInformationLength);
212 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_REQUEST_COMPLETE {%ld,%d} %d\n",
213 GetCurrentThreadId(), hInternet, dwContext,
214 iar->dwResult,iar->dwError,dwStatusInformationLength);
215 SetEvent(hCompleteEvent);
218 case INTERNET_STATUS_REDIRECT:
219 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_REDIRECT \"%s\" %d\n",
220 GetCurrentThreadId(), hInternet, dwContext,
221 (LPCSTR)lpvStatusInformation, dwStatusInformationLength);
222 *(LPSTR)lpvStatusInformation = '\0';
223 CLEAR_NOTIFIED(INTERNET_STATUS_DETECTING_PROXY);
224 SET_EXPECT(INTERNET_STATUS_DETECTING_PROXY);
226 case INTERNET_STATUS_INTERMEDIATE_RESPONSE:
227 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_INTERMEDIATE_RESPONSE %p %d\n",
228 GetCurrentThreadId(), hInternet, dwContext,
229 lpvStatusInformation, dwStatusInformationLength);
232 trace("%04x:Callback %p 0x%lx %d %p %d\n",
233 GetCurrentThreadId(), hInternet, dwContext, dwInternetStatus,
234 lpvStatusInformation, dwStatusInformationLength);
238 static void InternetReadFile_test(int flags)
245 const char *types[2] = { "*", NULL };
246 HINTERNET hi, hic = 0, hor = 0;
248 hCompleteEvent = CreateEvent(NULL, FALSE, FALSE, NULL);
250 trace("Starting InternetReadFile test with flags 0x%x\n",flags);
252 trace("InternetOpenA <--\n");
253 hi = InternetOpenA("", INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, flags);
254 ok((hi != 0x0),"InternetOpen failed with error %u\n", GetLastError());
255 trace("InternetOpenA -->\n");
257 if (hi == 0x0) goto abort;
259 pInternetSetStatusCallbackA(hi,&callback);
261 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED);
263 trace("InternetConnectA <--\n");
264 hic=InternetConnectA(hi, "www.winehq.org", INTERNET_INVALID_PORT_NUMBER,
265 NULL, NULL, INTERNET_SERVICE_HTTP, 0x0, 0xdeadbeef);
266 ok((hic != 0x0),"InternetConnect failed with error %u\n", GetLastError());
267 trace("InternetConnectA -->\n");
269 if (hic == 0x0) goto abort;
271 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED);
272 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED);
274 trace("HttpOpenRequestA <--\n");
275 hor = HttpOpenRequestA(hic, "GET", "/about/", NULL, NULL, types,
276 INTERNET_FLAG_KEEP_CONNECTION | INTERNET_FLAG_RESYNCHRONIZE,
278 if (hor == 0x0 && GetLastError() == ERROR_INTERNET_NAME_NOT_RESOLVED) {
280 * If the internet name can't be resolved we are probably behind
281 * a firewall or in some other way not directly connected to the
282 * Internet. Not enough reason to fail the test. Just ignore and
286 ok((hor != 0x0),"HttpOpenRequest failed with error %u\n", GetLastError());
288 trace("HttpOpenRequestA -->\n");
290 if (hor == 0x0) goto abort;
292 length = sizeof(buffer);
293 res = InternetQueryOptionA(hor, INTERNET_OPTION_URL, buffer, &length);
294 ok(res, "InternetQueryOptionA(INTERNET_OPTION_URL) failed: %u\n", GetLastError());
295 ok(!strcmp(buffer, "http://www.winehq.org/about/"), "Wrong URL %s\n", buffer);
297 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED);
298 CHECK_NOT_NOTIFIED(INTERNET_STATUS_RESOLVING_NAME);
299 CHECK_NOT_NOTIFIED(INTERNET_STATUS_NAME_RESOLVED);
300 if (first_connection_to_test_url)
302 SET_EXPECT(INTERNET_STATUS_RESOLVING_NAME);
303 SET_EXPECT(INTERNET_STATUS_NAME_RESOLVED);
307 SET_WINE_ALLOW(INTERNET_STATUS_RESOLVING_NAME);
308 SET_WINE_ALLOW(INTERNET_STATUS_NAME_RESOLVED);
310 SET_WINE_ALLOW(INTERNET_STATUS_CONNECTING_TO_SERVER);
311 SET_EXPECT(INTERNET_STATUS_CONNECTING_TO_SERVER);
312 SET_WINE_ALLOW(INTERNET_STATUS_CONNECTED_TO_SERVER);
313 SET_EXPECT(INTERNET_STATUS_CONNECTED_TO_SERVER);
314 SET_EXPECT2(INTERNET_STATUS_SENDING_REQUEST, 2);
315 SET_EXPECT2(INTERNET_STATUS_REQUEST_SENT, 2);
316 SET_EXPECT2(INTERNET_STATUS_RECEIVING_RESPONSE, 2);
317 SET_EXPECT2(INTERNET_STATUS_RESPONSE_RECEIVED, 2);
318 SET_EXPECT(INTERNET_STATUS_REDIRECT);
319 if (flags & INTERNET_FLAG_ASYNC)
320 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE);
322 SET_WINE_ALLOW(INTERNET_STATUS_REQUEST_COMPLETE);
324 trace("HttpSendRequestA -->\n");
325 SetLastError(0xdeadbeef);
326 rc = HttpSendRequestA(hor, "", -1, NULL, 0);
327 if (flags & INTERNET_FLAG_ASYNC)
328 ok(((rc == 0)&&(GetLastError() == ERROR_IO_PENDING)),
329 "Asynchronous HttpSendRequest NOT returning 0 with error ERROR_IO_PENDING\n");
331 ok((rc != 0) || GetLastError() == ERROR_INTERNET_NAME_NOT_RESOLVED,
332 "Synchronous HttpSendRequest returning 0, error %u\n", GetLastError());
333 trace("HttpSendRequestA <--\n");
335 if (flags & INTERNET_FLAG_ASYNC)
336 WaitForSingleObject(hCompleteEvent, INFINITE);
338 if (first_connection_to_test_url)
340 CHECK_NOTIFIED(INTERNET_STATUS_RESOLVING_NAME);
341 CHECK_NOTIFIED(INTERNET_STATUS_NAME_RESOLVED);
345 CHECK_NOT_NOTIFIED(INTERNET_STATUS_RESOLVING_NAME);
346 CHECK_NOT_NOTIFIED(INTERNET_STATUS_NAME_RESOLVED);
348 CHECK_NOTIFIED2(INTERNET_STATUS_SENDING_REQUEST, 2);
349 CHECK_NOTIFIED2(INTERNET_STATUS_REQUEST_SENT, 2);
350 CHECK_NOTIFIED2(INTERNET_STATUS_RECEIVING_RESPONSE, 2);
351 CHECK_NOTIFIED2(INTERNET_STATUS_RESPONSE_RECEIVED, 2);
352 CHECK_NOTIFIED(INTERNET_STATUS_REDIRECT);
353 if (flags & INTERNET_FLAG_ASYNC)
354 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE);
356 todo_wine CHECK_NOT_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE);
357 /* Sent on WinXP only if first_connection_to_test_url is TRUE, on Win98 always sent */
358 CLEAR_NOTIFIED(INTERNET_STATUS_CONNECTING_TO_SERVER);
359 CLEAR_NOTIFIED(INTERNET_STATUS_CONNECTED_TO_SERVER);
362 rc = InternetQueryOptionA(hor,INTERNET_OPTION_REQUEST_FLAGS,&out,&length);
363 trace("Option 0x17 -> %i %i\n",rc,out);
366 rc = InternetQueryOptionA(hor,INTERNET_OPTION_URL,buffer,&length);
367 trace("Option 0x22 -> %i %s\n",rc,buffer);
370 rc = HttpQueryInfoA(hor,HTTP_QUERY_RAW_HEADERS,buffer,&length,0x0);
372 trace("Option 0x16 -> %i %s\n",rc,buffer);
374 length = sizeof(buffer);
375 res = InternetQueryOptionA(hor, INTERNET_OPTION_URL, buffer, &length);
376 ok(res, "InternetQueryOptionA(INTERNET_OPTION_URL) failed: %u\n", GetLastError());
377 ok(!strcmp(buffer, "http://www.winehq.org/site/about"), "Wrong URL %s\n", buffer);
380 rc = HttpQueryInfoA(hor,HTTP_QUERY_CONTENT_LENGTH,&buffer,&length,0x0);
381 trace("Option 0x5 -> %i %s (%u)\n",rc,buffer,GetLastError());
384 rc = HttpQueryInfoA(hor,HTTP_QUERY_CONTENT_TYPE,buffer,&length,0x0);
386 trace("Option 0x1 -> %i %s\n",rc,buffer);
388 SetLastError(0xdeadbeef);
389 rc = InternetReadFile(NULL, buffer, 100, &length);
390 ok(!rc, "InternetReadFile should have failed\n");
391 ok(GetLastError() == ERROR_INVALID_HANDLE,
392 "InternetReadFile should have set last error to ERROR_INVALID_HANDLE instead of %u\n",
396 trace("Entering Query loop\n");
398 SET_EXPECT(INTERNET_STATUS_CLOSING_CONNECTION);
399 SET_EXPECT(INTERNET_STATUS_CONNECTION_CLOSED);
402 if (flags & INTERNET_FLAG_ASYNC)
403 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE);
404 rc = InternetQueryDataAvailable(hor,&length,0x0,0x0);
405 ok(!(rc == 0 && length != 0),"InternetQueryDataAvailable failed with non-zero length\n");
406 ok(rc != 0 || ((flags & INTERNET_FLAG_ASYNC) && GetLastError() == ERROR_IO_PENDING),
407 "InternetQueryDataAvailable failed, error %d\n", GetLastError());
408 if (flags & INTERNET_FLAG_ASYNC)
412 CHECK_NOT_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE);
414 else if (GetLastError() == ERROR_IO_PENDING)
416 WaitForSingleObject(hCompleteEvent, INFINITE);
417 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE);
424 buffer = HeapAlloc(GetProcessHeap(),0,length+1);
426 rc = InternetReadFile(hor,buffer,length,&length);
430 trace("ReadFile -> %i %i\n",rc,length);
432 HeapFree(GetProcessHeap(),0,buffer);
437 /* WinXP does not send, but Win98 does */
438 CLEAR_NOTIFIED(INTERNET_STATUS_CLOSING_CONNECTION);
439 CLEAR_NOTIFIED(INTERNET_STATUS_CONNECTION_CLOSED);
441 SET_EXPECT2(INTERNET_STATUS_HANDLE_CLOSING, (hor != 0x0) + (hic != 0x0));
443 SET_WINE_ALLOW(INTERNET_STATUS_CLOSING_CONNECTION);
444 SET_WINE_ALLOW(INTERNET_STATUS_CONNECTION_CLOSED);
445 SetLastError(0xdeadbeef);
446 rc = InternetCloseHandle(hor);
447 ok ((rc != 0), "InternetCloseHandle of handle opened by HttpOpenRequestA failed\n");
448 SetLastError(0xdeadbeef);
449 rc = InternetCloseHandle(hor);
450 ok ((rc == 0), "Double close of handle opened by HttpOpenRequestA succeeded\n");
451 ok (GetLastError() == ERROR_INVALID_HANDLE,
452 "Double close of handle should have set ERROR_INVALID_HANDLE instead of %u\n",
455 /* We intentionally do not close the handle opened by InternetConnectA as this
456 * tickles bug #9479: native closes child internet handles when the parent handles
457 * are closed. This is verified below by checking that the number of
458 * INTERNET_STATUS_HANDLE_CLOSING notifications matches the number expected. */
460 SET_WINE_ALLOW(INTERNET_STATUS_HANDLE_CLOSING);
461 rc = InternetCloseHandle(hi);
462 ok ((rc != 0), "InternetCloseHandle of handle opened by InternetOpenA failed\n");
463 if (flags & INTERNET_FLAG_ASYNC)
466 CHECK_NOTIFIED2(INTERNET_STATUS_HANDLE_CLOSING, (hor != 0x0) + (hic != 0x0));
467 if (hor != 0x0) todo_wine
469 CHECK_NOT_NOTIFIED(INTERNET_STATUS_CLOSING_CONNECTION);
470 CHECK_NOT_NOTIFIED(INTERNET_STATUS_CONNECTION_CLOSED);
474 CHECK_NOT_NOTIFIED(INTERNET_STATUS_CLOSING_CONNECTION);
475 CHECK_NOT_NOTIFIED(INTERNET_STATUS_CONNECTION_CLOSED);
477 CloseHandle(hCompleteEvent);
478 first_connection_to_test_url = FALSE;
481 static void InternetReadFileExA_test(int flags)
485 const char *types[2] = { "*", NULL };
486 HINTERNET hi, hic = 0, hor = 0;
487 INTERNET_BUFFERS inetbuffers;
489 hCompleteEvent = CreateEvent(NULL, FALSE, FALSE, NULL);
491 trace("Starting InternetReadFileExA test with flags 0x%x\n",flags);
493 trace("InternetOpenA <--\n");
494 hi = InternetOpenA("", INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, flags);
495 ok((hi != 0x0),"InternetOpen failed with error %u\n", GetLastError());
496 trace("InternetOpenA -->\n");
498 if (hi == 0x0) goto abort;
500 pInternetSetStatusCallbackA(hi,&callback);
502 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED);
504 trace("InternetConnectA <--\n");
505 hic=InternetConnectA(hi, "www.winehq.org", INTERNET_INVALID_PORT_NUMBER,
506 NULL, NULL, INTERNET_SERVICE_HTTP, 0x0, 0xdeadbeef);
507 ok((hic != 0x0),"InternetConnect failed with error %u\n", GetLastError());
508 trace("InternetConnectA -->\n");
510 if (hic == 0x0) goto abort;
512 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED);
513 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED);
515 trace("HttpOpenRequestA <--\n");
516 hor = HttpOpenRequestA(hic, "GET", "/about/", NULL, NULL, types,
517 INTERNET_FLAG_KEEP_CONNECTION | INTERNET_FLAG_RESYNCHRONIZE,
519 if (hor == 0x0 && GetLastError() == ERROR_INTERNET_NAME_NOT_RESOLVED) {
521 * If the internet name can't be resolved we are probably behind
522 * a firewall or in some other way not directly connected to the
523 * Internet. Not enough reason to fail the test. Just ignore and
527 ok((hor != 0x0),"HttpOpenRequest failed with error %u\n", GetLastError());
529 trace("HttpOpenRequestA -->\n");
531 if (hor == 0x0) goto abort;
533 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED);
534 CHECK_NOT_NOTIFIED(INTERNET_STATUS_RESOLVING_NAME);
535 CHECK_NOT_NOTIFIED(INTERNET_STATUS_NAME_RESOLVED);
536 if (first_connection_to_test_url)
538 SET_EXPECT(INTERNET_STATUS_RESOLVING_NAME);
539 SET_EXPECT(INTERNET_STATUS_NAME_RESOLVED);
543 SET_WINE_ALLOW(INTERNET_STATUS_RESOLVING_NAME);
544 SET_WINE_ALLOW(INTERNET_STATUS_NAME_RESOLVED);
546 SET_WINE_ALLOW(INTERNET_STATUS_CONNECTING_TO_SERVER);
547 SET_EXPECT(INTERNET_STATUS_CONNECTING_TO_SERVER);
548 SET_WINE_ALLOW(INTERNET_STATUS_CONNECTED_TO_SERVER);
549 SET_EXPECT(INTERNET_STATUS_CONNECTED_TO_SERVER);
550 SET_EXPECT2(INTERNET_STATUS_SENDING_REQUEST, 2);
551 SET_EXPECT2(INTERNET_STATUS_REQUEST_SENT, 2);
552 SET_EXPECT2(INTERNET_STATUS_RECEIVING_RESPONSE, 2);
553 SET_EXPECT2(INTERNET_STATUS_RESPONSE_RECEIVED, 2);
554 SET_EXPECT(INTERNET_STATUS_REDIRECT);
555 if (flags & INTERNET_FLAG_ASYNC)
556 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE);
558 SET_WINE_ALLOW(INTERNET_STATUS_REQUEST_COMPLETE);
560 trace("HttpSendRequestA -->\n");
561 SetLastError(0xdeadbeef);
562 rc = HttpSendRequestA(hor, "", -1, NULL, 0);
563 if (flags & INTERNET_FLAG_ASYNC)
564 ok(((rc == 0)&&(GetLastError() == ERROR_IO_PENDING)),
565 "Asynchronous HttpSendRequest NOT returning 0 with error ERROR_IO_PENDING\n");
567 ok((rc != 0) || GetLastError() == ERROR_INTERNET_NAME_NOT_RESOLVED,
568 "Synchronous HttpSendRequest returning 0, error %u\n", GetLastError());
569 trace("HttpSendRequestA <--\n");
571 if (!rc && (GetLastError() == ERROR_IO_PENDING))
572 WaitForSingleObject(hCompleteEvent, INFINITE);
574 if (first_connection_to_test_url)
576 CHECK_NOTIFIED(INTERNET_STATUS_RESOLVING_NAME);
577 CHECK_NOTIFIED(INTERNET_STATUS_NAME_RESOLVED);
581 CHECK_NOT_NOTIFIED(INTERNET_STATUS_RESOLVING_NAME);
582 CHECK_NOT_NOTIFIED(INTERNET_STATUS_NAME_RESOLVED);
584 CHECK_NOTIFIED2(INTERNET_STATUS_SENDING_REQUEST, 2);
585 CHECK_NOTIFIED2(INTERNET_STATUS_REQUEST_SENT, 2);
586 CHECK_NOTIFIED2(INTERNET_STATUS_RECEIVING_RESPONSE, 2);
587 CHECK_NOTIFIED2(INTERNET_STATUS_RESPONSE_RECEIVED, 2);
588 CHECK_NOTIFIED(INTERNET_STATUS_REDIRECT);
589 if (flags & INTERNET_FLAG_ASYNC)
590 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE);
592 todo_wine CHECK_NOT_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE);
593 /* Sent on WinXP only if first_connection_to_test_url is TRUE, on Win98 always sent */
594 CLEAR_NOTIFIED(INTERNET_STATUS_CONNECTING_TO_SERVER);
595 CLEAR_NOTIFIED(INTERNET_STATUS_CONNECTED_TO_SERVER);
597 /* tests invalid dwStructSize */
598 inetbuffers.dwStructSize = sizeof(INTERNET_BUFFERS)+1;
599 inetbuffers.lpcszHeader = NULL;
600 inetbuffers.dwHeadersLength = 0;
601 inetbuffers.dwBufferLength = 10;
602 inetbuffers.lpvBuffer = HeapAlloc(GetProcessHeap(), 0, 10);
603 inetbuffers.dwOffsetHigh = 1234;
604 inetbuffers.dwOffsetLow = 5678;
605 rc = InternetReadFileEx(hor, &inetbuffers, 0, 0xdeadcafe);
606 ok(!rc && (GetLastError() == ERROR_INVALID_PARAMETER),
607 "InternetReadFileEx should have failed with ERROR_INVALID_PARAMETER instead of %s, %u\n",
608 rc ? "TRUE" : "FALSE", GetLastError());
609 HeapFree(GetProcessHeap(), 0, inetbuffers.lpvBuffer);
611 /* tests to see whether lpcszHeader is used - it isn't */
612 inetbuffers.dwStructSize = sizeof(INTERNET_BUFFERS);
613 inetbuffers.lpcszHeader = (LPCTSTR)0xdeadbeef;
614 inetbuffers.dwHeadersLength = 255;
615 inetbuffers.dwBufferLength = 0;
616 inetbuffers.lpvBuffer = NULL;
617 inetbuffers.dwOffsetHigh = 1234;
618 inetbuffers.dwOffsetLow = 5678;
619 SET_WINE_ALLOW(INTERNET_STATUS_RECEIVING_RESPONSE);
620 SET_WINE_ALLOW(INTERNET_STATUS_RESPONSE_RECEIVED);
621 rc = InternetReadFileEx(hor, &inetbuffers, 0, 0xdeadcafe);
622 ok(rc, "InternetReadFileEx failed with error %u\n", GetLastError());
625 CHECK_NOT_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE);
626 CHECK_NOT_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED);
629 rc = InternetReadFileEx(NULL, &inetbuffers, 0, 0xdeadcafe);
630 ok(!rc && (GetLastError() == ERROR_INVALID_HANDLE),
631 "InternetReadFileEx should have failed with ERROR_INVALID_HANDLE instead of %s, %u\n",
632 rc ? "TRUE" : "FALSE", GetLastError());
635 trace("Entering Query loop\n");
637 SET_EXPECT(INTERNET_STATUS_CLOSING_CONNECTION);
638 SET_EXPECT(INTERNET_STATUS_CONNECTION_CLOSED);
641 inetbuffers.dwStructSize = sizeof(INTERNET_BUFFERS);
642 inetbuffers.dwBufferLength = 1024;
643 inetbuffers.lpvBuffer = HeapAlloc(GetProcessHeap(), 0, inetbuffers.dwBufferLength+1);
644 inetbuffers.dwOffsetHigh = 1234;
645 inetbuffers.dwOffsetLow = 5678;
647 SET_EXPECT(INTERNET_STATUS_RECEIVING_RESPONSE);
648 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE);
649 SET_EXPECT(INTERNET_STATUS_RESPONSE_RECEIVED);
650 rc = InternetReadFileExA(hor, &inetbuffers, IRF_ASYNC | IRF_USE_CONTEXT, 0xcafebabe);
653 if (GetLastError() == ERROR_IO_PENDING)
655 trace("InternetReadFileEx -> PENDING\n");
656 ok(flags & INTERNET_FLAG_ASYNC,
657 "Should not get ERROR_IO_PENDING without INTERNET_FLAG_ASYNC\n");
658 CHECK_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE);
659 WaitForSingleObject(hCompleteEvent, INFINITE);
660 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE);
661 CHECK_NOT_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED);
665 trace("InternetReadFileEx -> FAILED %u\n", GetLastError());
671 trace("InternetReadFileEx -> SUCCEEDED\n");
672 CHECK_NOT_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE);
673 if (inetbuffers.dwBufferLength)
675 CHECK_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE);
676 CHECK_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED);
680 /* Win98 still sends these when 0 bytes are read, WinXP does not */
681 CLEAR_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE);
682 CLEAR_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED);
686 trace("read %i bytes\n", inetbuffers.dwBufferLength);
687 ((char *)inetbuffers.lpvBuffer)[inetbuffers.dwBufferLength] = '\0';
689 ok(inetbuffers.dwOffsetHigh == 1234 && inetbuffers.dwOffsetLow == 5678,
690 "InternetReadFileEx sets offsets to 0x%x%08x\n",
691 inetbuffers.dwOffsetHigh, inetbuffers.dwOffsetLow);
693 HeapFree(GetProcessHeap(), 0, inetbuffers.lpvBuffer);
695 if (!inetbuffers.dwBufferLength)
698 length += inetbuffers.dwBufferLength;
700 ok(length > 0, "failed to read any of the document\n");
701 trace("Finished. Read %d bytes\n", length);
703 /* WinXP does not send, but Win98 does */
704 CLEAR_NOTIFIED(INTERNET_STATUS_CLOSING_CONNECTION);
705 CLEAR_NOTIFIED(INTERNET_STATUS_CONNECTION_CLOSED);
707 SET_EXPECT2(INTERNET_STATUS_HANDLE_CLOSING, (hor != 0x0) + (hic != 0x0));
709 SET_WINE_ALLOW(INTERNET_STATUS_CLOSING_CONNECTION);
710 SET_WINE_ALLOW(INTERNET_STATUS_CONNECTION_CLOSED);
711 rc = InternetCloseHandle(hor);
712 ok ((rc != 0), "InternetCloseHandle of handle opened by HttpOpenRequestA failed\n");
713 rc = InternetCloseHandle(hor);
714 ok ((rc == 0), "Double close of handle opened by HttpOpenRequestA succeeded\n");
717 rc = InternetCloseHandle(hic);
718 ok ((rc != 0), "InternetCloseHandle of handle opened by InternetConnectA failed\n");
721 SET_WINE_ALLOW(INTERNET_STATUS_HANDLE_CLOSING);
722 rc = InternetCloseHandle(hi);
723 ok ((rc != 0), "InternetCloseHandle of handle opened by InternetOpenA failed\n");
724 if (flags & INTERNET_FLAG_ASYNC)
726 CHECK_NOTIFIED2(INTERNET_STATUS_HANDLE_CLOSING, (hor != 0x0) + (hic != 0x0));
728 if (hor != 0x0) todo_wine
730 CHECK_NOT_NOTIFIED(INTERNET_STATUS_CLOSING_CONNECTION);
731 CHECK_NOT_NOTIFIED(INTERNET_STATUS_CONNECTION_CLOSED);
735 CHECK_NOT_NOTIFIED(INTERNET_STATUS_CLOSING_CONNECTION);
736 CHECK_NOT_NOTIFIED(INTERNET_STATUS_CONNECTION_CLOSED);
738 CloseHandle(hCompleteEvent);
739 first_connection_to_test_url = FALSE;
742 static void InternetOpenUrlA_test(void)
744 HINTERNET myhinternet, myhttp;
746 DWORD size, readbytes, totalbytes=0;
749 myhinternet = InternetOpen("Winetest",0,NULL,NULL,INTERNET_FLAG_NO_CACHE_WRITE);
750 ok((myhinternet != 0), "InternetOpen failed, error %u\n",GetLastError());
752 ret = InternetCanonicalizeUrl(TEST_URL, buffer, &size,ICU_BROWSER_MODE);
753 ok( ret, "InternetCanonicalizeUrl failed, error %u\n",GetLastError());
756 myhttp = InternetOpenUrl(myhinternet, TEST_URL, 0, 0,
757 INTERNET_FLAG_RELOAD|INTERNET_FLAG_NO_CACHE_WRITE|INTERNET_FLAG_TRANSFER_BINARY,0);
758 if (GetLastError() == ERROR_INTERNET_NAME_NOT_RESOLVED)
759 return; /* WinXP returns this when not connected to the net */
760 ok((myhttp != 0),"InternetOpenUrl failed, error %u\n",GetLastError());
761 ret = InternetReadFile(myhttp, buffer,0x400,&readbytes);
762 ok( ret, "InternetReadFile failed, error %u\n",GetLastError());
763 totalbytes += readbytes;
764 while (readbytes && InternetReadFile(myhttp, buffer,0x400,&readbytes))
765 totalbytes += readbytes;
766 trace("read 0x%08x bytes\n",totalbytes);
768 InternetCloseHandle(myhttp);
769 InternetCloseHandle(myhinternet);
772 static void InternetTimeFromSystemTimeA_test(void)
775 static const SYSTEMTIME time = { 2005, 1, 5, 7, 12, 6, 35, 0 };
776 char string[INTERNET_RFC1123_BUFSIZE];
777 static const char expect[] = "Fri, 07 Jan 2005 12:06:35 GMT";
779 ret = pInternetTimeFromSystemTimeA( &time, INTERNET_RFC1123_FORMAT, string, sizeof(string) );
780 ok( ret, "InternetTimeFromSystemTimeA failed (%u)\n", GetLastError() );
782 ok( !memcmp( string, expect, sizeof(expect) ),
783 "InternetTimeFromSystemTimeA failed (%u)\n", GetLastError() );
786 static void InternetTimeFromSystemTimeW_test(void)
789 static const SYSTEMTIME time = { 2005, 1, 5, 7, 12, 6, 35, 0 };
790 WCHAR string[INTERNET_RFC1123_BUFSIZE + 1];
791 static const WCHAR expect[] = { 'F','r','i',',',' ','0','7',' ','J','a','n',' ','2','0','0','5',' ',
792 '1','2',':','0','6',':','3','5',' ','G','M','T',0 };
794 ret = pInternetTimeFromSystemTimeW( &time, INTERNET_RFC1123_FORMAT, string, sizeof(string) );
795 ok( ret, "InternetTimeFromSystemTimeW failed (%u)\n", GetLastError() );
797 ok( !memcmp( string, expect, sizeof(expect) ),
798 "InternetTimeFromSystemTimeW failed (%u)\n", GetLastError() );
801 static void InternetTimeToSystemTimeA_test(void)
805 static const SYSTEMTIME expect = { 2005, 1, 5, 7, 12, 6, 35, 0 };
806 static const char string[] = "Fri, 07 Jan 2005 12:06:35 GMT";
807 static const char string2[] = " fri 7 jan 2005 12 06 35";
809 ret = pInternetTimeToSystemTimeA( string, &time, 0 );
810 ok( ret, "InternetTimeToSystemTimeA failed (%u)\n", GetLastError() );
811 ok( !memcmp( &time, &expect, sizeof(expect) ),
812 "InternetTimeToSystemTimeA failed (%u)\n", GetLastError() );
814 ret = pInternetTimeToSystemTimeA( string2, &time, 0 );
815 ok( ret, "InternetTimeToSystemTimeA failed (%u)\n", GetLastError() );
816 ok( !memcmp( &time, &expect, sizeof(expect) ),
817 "InternetTimeToSystemTimeA failed (%u)\n", GetLastError() );
820 static void InternetTimeToSystemTimeW_test(void)
824 static const SYSTEMTIME expect = { 2005, 1, 5, 7, 12, 6, 35, 0 };
825 static const WCHAR string[] = { 'F','r','i',',',' ','0','7',' ','J','a','n',' ','2','0','0','5',' ',
826 '1','2',':','0','6',':','3','5',' ','G','M','T',0 };
827 static const WCHAR string2[] = { ' ','f','r','i',' ','7',' ','j','a','n',' ','2','0','0','5',' ',
828 '1','2',' ','0','6',' ','3','5',0 };
829 static const WCHAR string3[] = { 'F','r',0 };
831 ret = pInternetTimeToSystemTimeW( NULL, NULL, 0 );
832 ok( !ret, "InternetTimeToSystemTimeW succeeded (%u)\n", GetLastError() );
834 ret = pInternetTimeToSystemTimeW( NULL, &time, 0 );
835 ok( !ret, "InternetTimeToSystemTimeW succeeded (%u)\n", GetLastError() );
837 ret = pInternetTimeToSystemTimeW( string, NULL, 0 );
838 ok( !ret, "InternetTimeToSystemTimeW succeeded (%u)\n", GetLastError() );
840 ret = pInternetTimeToSystemTimeW( string, &time, 0 );
841 ok( ret, "InternetTimeToSystemTimeW failed (%u)\n", GetLastError() );
843 ret = pInternetTimeToSystemTimeW( string, &time, 0 );
844 ok( ret, "InternetTimeToSystemTimeW failed (%u)\n", GetLastError() );
845 ok( !memcmp( &time, &expect, sizeof(expect) ),
846 "InternetTimeToSystemTimeW failed (%u)\n", GetLastError() );
848 ret = pInternetTimeToSystemTimeW( string2, &time, 0 );
849 ok( ret, "InternetTimeToSystemTimeW failed (%u)\n", GetLastError() );
850 ok( !memcmp( &time, &expect, sizeof(expect) ),
851 "InternetTimeToSystemTimeW failed (%u)\n", GetLastError() );
853 ret = pInternetTimeToSystemTimeW( string3, &time, 0 );
854 ok( ret, "InternetTimeToSystemTimeW failed (%u)\n", GetLastError() );
857 static void HttpSendRequestEx_test(void)
863 INTERNET_BUFFERS BufferIn;
864 DWORD dwBytesWritten;
870 static char szPostData[] = "mode=Test";
871 static const char szContentType[] = "Content-Type: application/x-www-form-urlencoded";
873 hSession = InternetOpen("Wine Regression Test",
874 INTERNET_OPEN_TYPE_PRECONFIG,NULL,NULL,0);
875 ok( hSession != NULL ,"Unable to open Internet session\n");
876 hConnect = InternetConnect(hSession, "crossover.codeweavers.com",
877 INTERNET_DEFAULT_HTTP_PORT, NULL, NULL, INTERNET_SERVICE_HTTP, 0,
879 ok( hConnect != NULL, "Unable to connect to http://crossover.codeweavers.com\n");
880 hRequest = HttpOpenRequest(hConnect, "POST", "/posttest.php",
881 NULL, NULL, NULL, INTERNET_FLAG_NO_CACHE_WRITE, 0);
882 if (!hRequest && GetLastError() == ERROR_INTERNET_NAME_NOT_RESOLVED)
884 trace( "Network unreachable, skipping test\n" );
887 ok( hRequest != NULL, "Failed to open request handle err %u\n", GetLastError());
890 BufferIn.dwStructSize = sizeof( INTERNET_BUFFERS);
891 BufferIn.Next = (LPINTERNET_BUFFERS)0xdeadcab;
892 BufferIn.lpcszHeader = szContentType;
893 BufferIn.dwHeadersLength = sizeof(szContentType)-1;
894 BufferIn.dwHeadersTotal = sizeof(szContentType)-1;
895 BufferIn.lpvBuffer = szPostData;
896 BufferIn.dwBufferLength = 3;
897 BufferIn.dwBufferTotal = sizeof(szPostData)-1;
898 BufferIn.dwOffsetLow = 0;
899 BufferIn.dwOffsetHigh = 0;
901 ret = HttpSendRequestEx(hRequest, &BufferIn, NULL, 0 ,0);
902 ok(ret, "HttpSendRequestEx Failed with error %u\n", GetLastError());
904 for (i = 3; szPostData[i]; i++)
905 ok(InternetWriteFile(hRequest, &szPostData[i], 1, &dwBytesWritten),
906 "InternetWriteFile failed\n");
908 ok(HttpEndRequest(hRequest, NULL, 0, 0), "HttpEndRequest Failed\n");
910 ok(InternetReadFile(hRequest, szBuffer, 255, &dwBytesRead),
911 "Unable to read response\n");
912 szBuffer[dwBytesRead] = 0;
914 ok(dwBytesRead == 13,"Read %u bytes instead of 13\n",dwBytesRead);
915 ok(strncmp(szBuffer,"mode => Test\n",dwBytesRead)==0,"Got string %s\n",szBuffer);
917 ok(InternetCloseHandle(hRequest), "Close request handle failed\n");
919 ok(InternetCloseHandle(hConnect), "Close connect handle failed\n");
920 ok(InternetCloseHandle(hSession), "Close session handle failed\n");
923 static void InternetOpenRequest_test(void)
925 HINTERNET session, connect, request;
926 static const char *types[] = { "*", "", NULL };
927 static const WCHAR slash[] = {'/', 0}, any[] = {'*', 0}, empty[] = {0};
928 static const WCHAR *typesW[] = { any, empty, NULL };
931 session = InternetOpenA("Wine Regression Test", INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, 0);
932 ok(session != NULL ,"Unable to open Internet session\n");
934 connect = InternetConnectA(session, NULL, INTERNET_DEFAULT_HTTP_PORT, NULL, NULL,
935 INTERNET_SERVICE_HTTP, 0, 0);
936 ok(connect == NULL, "InternetConnectA should have failed\n");
937 ok(GetLastError() == ERROR_INVALID_PARAMETER, "InternetConnectA with NULL server named should have failed with ERROR_INVALID_PARAMETER instead of %d\n", GetLastError());
939 connect = InternetConnectA(session, "", INTERNET_DEFAULT_HTTP_PORT, NULL, NULL,
940 INTERNET_SERVICE_HTTP, 0, 0);
941 ok(connect == NULL, "InternetConnectA should have failed\n");
942 ok(GetLastError() == ERROR_INVALID_PARAMETER, "InternetConnectA with blank server named should have failed with ERROR_INVALID_PARAMETER instead of %d\n", GetLastError());
944 connect = InternetConnectA(session, "winehq.org", INTERNET_DEFAULT_HTTP_PORT, NULL, NULL,
945 INTERNET_SERVICE_HTTP, 0, 0);
946 ok(connect != NULL, "Unable to connect to http://winehq.org with error %d\n", GetLastError());
948 request = HttpOpenRequestA(connect, NULL, "/", NULL, NULL, types, INTERNET_FLAG_NO_CACHE_WRITE, 0);
949 if (!request && GetLastError() == ERROR_INTERNET_NAME_NOT_RESOLVED)
951 trace( "Network unreachable, skipping test\n" );
954 ok(request != NULL, "Failed to open request handle err %u\n", GetLastError());
956 ret = HttpSendRequest(request, NULL, 0, NULL, 0);
957 ok(ret, "HttpSendRequest failed: %u\n", GetLastError());
958 ok(InternetCloseHandle(request), "Close request handle failed\n");
960 request = HttpOpenRequestW(connect, NULL, slash, NULL, NULL, typesW, INTERNET_FLAG_NO_CACHE_WRITE, 0);
961 ok(request != NULL, "Failed to open request handle err %u\n", GetLastError());
963 ret = HttpSendRequest(request, NULL, 0, NULL, 0);
964 ok(ret, "HttpSendRequest failed: %u\n", GetLastError());
965 ok(InternetCloseHandle(request), "Close request handle failed\n");
968 ok(InternetCloseHandle(connect), "Close connect handle failed\n");
969 ok(InternetCloseHandle(session), "Close session handle failed\n");
972 static void test_http_cache(void)
974 HINTERNET session, connect, request;
975 char file_name[MAX_PATH], url[INTERNET_MAX_URL_LENGTH];
976 DWORD size, file_size;
981 static const char *types[] = { "*", "", NULL };
983 session = InternetOpenA("Wine Regression Test", INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, 0);
984 ok(session != NULL ,"Unable to open Internet session\n");
986 connect = InternetConnectA(session, "www.winehq.org", INTERNET_DEFAULT_HTTP_PORT, NULL, NULL,
987 INTERNET_SERVICE_HTTP, 0, 0);
988 ok(connect != NULL, "Unable to connect to http://winehq.org with error %d\n", GetLastError());
990 request = HttpOpenRequestA(connect, NULL, "/site/about", NULL, NULL, types, INTERNET_FLAG_NEED_FILE, 0);
991 if (!request && GetLastError() == ERROR_INTERNET_NAME_NOT_RESOLVED)
993 trace( "Network unreachable, skipping test\n" );
995 ok(InternetCloseHandle(connect), "Close connect handle failed\n");
996 ok(InternetCloseHandle(session), "Close session handle failed\n");
1000 ok(request != NULL, "Failed to open request handle err %u\n", GetLastError());
1003 ret = InternetQueryOptionA(request, INTERNET_OPTION_URL, url, &size);
1004 ok(ret, "InternetQueryOptionA(INTERNET_OPTION_url) failed: %u\n", GetLastError());
1005 ok(!strcmp(url, "http://www.winehq.org/site/about"), "Wrong URL %s\n", url);
1007 size = sizeof(file_name);
1008 ret = InternetQueryOptionA(request, INTERNET_OPTION_DATAFILE_NAME, file_name, &size);
1009 ok(!ret, "InternetQueryOptionA(INTERNET_OPTION_DATAFILE_NAME) succeeded\n");
1010 ok(GetLastError() == ERROR_INTERNET_ITEM_NOT_FOUND, "GetLastError()=%u\n", GetLastError());
1011 ok(!size, "size = %d\n", size);
1013 ret = HttpSendRequest(request, NULL, 0, NULL, 0);
1014 ok(ret, "HttpSendRequest failed: %u\n", GetLastError());
1016 size = sizeof(file_name);
1017 ret = InternetQueryOptionA(request, INTERNET_OPTION_DATAFILE_NAME, file_name, &size);
1018 ok(ret, "InternetQueryOptionA(INTERNET_OPTION_DATAFILE_NAME) failed: %u\n", GetLastError());
1020 file = CreateFile(file_name, GENERIC_READ, FILE_SHARE_READ|FILE_SHARE_WRITE, NULL, OPEN_EXISTING,
1021 FILE_ATTRIBUTE_NORMAL, NULL);
1022 ok(file != INVALID_HANDLE_VALUE, "Could not create file: %u\n", GetLastError());
1023 file_size = GetFileSize(file, NULL);
1024 ok(file_size == 0, "file size=%d\n", file_size);
1026 ret = InternetReadFile(request, buf, sizeof(buf), &size);
1027 ok(ret, "InternetReadFile failed: %u\n", GetLastError());
1028 ok(size == sizeof(buf), "size=%d\n", size);
1030 file_size = GetFileSize(file, NULL);
1031 ok(file_size == sizeof(buf), "file size=%d\n", file_size);
1034 ok(InternetCloseHandle(request), "Close request handle failed\n");
1036 file = CreateFile(file_name, GENERIC_READ, FILE_SHARE_READ|FILE_SHARE_WRITE, NULL, OPEN_EXISTING,
1037 FILE_ATTRIBUTE_NORMAL, NULL);
1038 ok(file == INVALID_HANDLE_VALUE, "CreateFile succeeded\n");
1039 ok(GetLastError() == ERROR_FILE_NOT_FOUND, "GetLastError()=%u, expected ERROR_FILE_NOT_FOUND\n", GetLastError());
1041 request = HttpOpenRequestA(connect, NULL, "/", NULL, NULL, types, INTERNET_FLAG_NO_CACHE_WRITE, 0);
1042 ok(request != NULL, "Failed to open request handle err %u\n", GetLastError());
1044 ret = InternetQueryOptionA(request, INTERNET_OPTION_DATAFILE_NAME, file_name, &size);
1045 ok(!ret, "InternetQueryOptionA(INTERNET_OPTION_DATAFILE_NAME) succeeded\n");
1046 ok(GetLastError() == ERROR_INTERNET_ITEM_NOT_FOUND, "GetLastError()=%u\n", GetLastError());
1047 ok(!size, "size = %d\n", size);
1049 ret = HttpSendRequest(request, NULL, 0, NULL, 0);
1050 ok(ret, "HttpSendRequest failed: %u\n", GetLastError());
1052 size = sizeof(file_name);
1053 ret = InternetQueryOptionA(request, INTERNET_OPTION_DATAFILE_NAME, file_name, &size);
1054 ok(!ret, "InternetQueryOptionA(INTERNET_OPTION_DATAFILE_NAME) succeeded\n");
1055 ok(GetLastError() == ERROR_INTERNET_ITEM_NOT_FOUND, "GetLastError()=%u\n", GetLastError());
1056 ok(!size, "size = %d\n", size);
1058 file = CreateFile(file_name, GENERIC_READ, FILE_SHARE_READ|FILE_SHARE_WRITE, NULL, OPEN_EXISTING,
1059 FILE_ATTRIBUTE_NORMAL, NULL);
1060 ok(file == INVALID_HANDLE_VALUE, "CreateFile succeeded\n");
1061 ok(GetLastError() == ERROR_FILE_NOT_FOUND, "GetLastError()=%u, expected ERROR_FILE_NOT_FOUND\n", GetLastError());
1063 ok(InternetCloseHandle(request), "Close request handle failed\n");
1065 ok(InternetCloseHandle(connect), "Close connect handle failed\n");
1066 ok(InternetCloseHandle(session), "Close session handle failed\n");
1069 static void HttpHeaders_test(void)
1078 hSession = InternetOpen("Wine Regression Test",
1079 INTERNET_OPEN_TYPE_PRECONFIG,NULL,NULL,0);
1080 ok( hSession != NULL ,"Unable to open Internet session\n");
1081 hConnect = InternetConnect(hSession, "crossover.codeweavers.com",
1082 INTERNET_DEFAULT_HTTP_PORT, NULL, NULL, INTERNET_SERVICE_HTTP, 0,
1084 ok( hConnect != NULL, "Unable to connect to http://crossover.codeweavers.com\n");
1085 hRequest = HttpOpenRequest(hConnect, "POST", "/posttest.php",
1086 NULL, NULL, NULL, INTERNET_FLAG_NO_CACHE_WRITE, 0);
1087 if (!hRequest && GetLastError() == ERROR_INTERNET_NAME_NOT_RESOLVED)
1089 trace( "Network unreachable, skipping test\n" );
1092 ok( hRequest != NULL, "Failed to open request handle\n");
1095 len = sizeof(buffer);
1096 strcpy(buffer,"Warning");
1097 ok(HttpQueryInfo(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS,
1098 buffer,&len,&index)==0,"Warning hearder reported as Existing\n");
1100 ok(HttpAddRequestHeaders(hRequest,"Warning:test1",-1,HTTP_ADDREQ_FLAG_ADD),
1101 "Failed to add new header\n");
1104 len = sizeof(buffer);
1105 strcpy(buffer,"Warning");
1106 ok(HttpQueryInfo(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS,
1107 buffer,&len,&index),"Unable to query header\n");
1108 ok(index == 1, "Index was not incremented\n");
1109 ok(strcmp(buffer,"test1")==0, "incorrect string was returned(%s)\n",buffer);
1110 ok(len == 5, "Invalid length (exp. 5, got %d)\n", len);
1111 ok((len < sizeof(buffer)) && (buffer[len] == 0), "Buffer not NULL-terminated\n"); /* len show only 5 characters but the buffer is NULL-terminated*/
1112 len = sizeof(buffer);
1113 strcpy(buffer,"Warning");
1114 ok(HttpQueryInfo(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS,
1115 buffer,&len,&index)==0,"Second Index Should Not Exist\n");
1118 len = 5; /* could store the string but not the NULL terminator */
1119 strcpy(buffer,"Warning");
1120 ok(HttpQueryInfo(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS,
1121 buffer,&len,&index) == FALSE,"Query succeeded on a too small buffer\n");
1122 ok(strcmp(buffer,"Warning")==0, "incorrect string was returned(%s)\n",buffer); /* string not touched */
1123 ok(len == 6, "Invalid length (exp. 6, got %d)\n", len); /* unlike success, the length includes the NULL-terminator */
1125 /* a call with NULL will fail but will return the length */
1127 len = sizeof(buffer);
1128 SetLastError(0xdeadbeef);
1129 ok(HttpQueryInfo(hRequest,HTTP_QUERY_RAW_HEADERS_CRLF|HTTP_QUERY_FLAG_REQUEST_HEADERS,
1130 NULL,&len,&index) == FALSE,"Query worked\n");
1131 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER, "Unexpected last error: %d\n", GetLastError());
1132 ok(len > 40, "Invalid length (exp. more than 40, got %d)\n", len);
1133 ok(index == 0, "Index was incremented\n");
1135 /* even for a len that is too small */
1138 SetLastError(0xdeadbeef);
1139 ok(HttpQueryInfo(hRequest,HTTP_QUERY_RAW_HEADERS_CRLF|HTTP_QUERY_FLAG_REQUEST_HEADERS,
1140 NULL,&len,&index) == FALSE,"Query worked\n");
1141 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER, "Unexpected last error: %d\n", GetLastError());
1142 ok(len > 40, "Invalid length (exp. more than 40, got %d)\n", len);
1143 ok(index == 0, "Index was incremented\n");
1147 SetLastError(0xdeadbeef);
1148 ok(HttpQueryInfo(hRequest,HTTP_QUERY_RAW_HEADERS_CRLF|HTTP_QUERY_FLAG_REQUEST_HEADERS,
1149 NULL,&len,&index) == FALSE,"Query worked\n");
1150 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER, "Unexpected last error: %d\n", GetLastError());
1151 ok(len > 40, "Invalid length (exp. more than 40, got %d)\n", len);
1152 ok(index == 0, "Index was incremented\n");
1155 /* a working query */
1157 len = sizeof(buffer);
1158 ok(HttpQueryInfo(hRequest,HTTP_QUERY_RAW_HEADERS_CRLF|HTTP_QUERY_FLAG_REQUEST_HEADERS,
1159 buffer,&len,&index),"Unable to query header\n");
1160 /* what's in the middle differs between Wine and Windows so currently we check only the beginning and the end */
1161 ok(strncmp(buffer, "POST /posttest.php HTTP/1", 25)==0, "Invalid beginning of headers string\n");
1162 ok(strcmp(buffer + strlen(buffer) - 4, "\r\n\r\n")==0, "Invalid end of headers string\n");
1163 ok(index == 0, "Index was incremented\n");
1167 ok(HttpAddRequestHeaders(hRequest,"Warning:test2",-1,HTTP_ADDREQ_FLAG_ADD),
1168 "Failed to add duplicate header using HTTP_ADDREQ_FLAG_ADD\n");
1171 len = sizeof(buffer);
1172 strcpy(buffer,"Warning");
1173 ok(HttpQueryInfo(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS,
1174 buffer,&len,&index),"Unable to query header\n");
1175 ok(index == 1, "Index was not incremented\n");
1176 ok(strcmp(buffer,"test1")==0, "incorrect string was returned(%s)\n",buffer);
1177 len = sizeof(buffer);
1178 strcpy(buffer,"Warning");
1179 ok(HttpQueryInfo(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS,
1180 buffer,&len,&index),"Failed to get second header\n");
1181 ok(index == 2, "Index was not incremented\n");
1182 ok(strcmp(buffer,"test2")==0, "incorrect string was returned(%s)\n",buffer);
1183 len = sizeof(buffer);
1184 strcpy(buffer,"Warning");
1185 ok(HttpQueryInfo(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS,
1186 buffer,&len,&index)==0,"Third Header Should Not Exist\n");
1188 ok(HttpAddRequestHeaders(hRequest,"Warning:test3",-1,HTTP_ADDREQ_FLAG_REPLACE), "Failed to replace header using HTTP_ADDREQ_FLAG_REPLACE\n");
1191 len = sizeof(buffer);
1192 strcpy(buffer,"Warning");
1193 ok(HttpQueryInfo(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS,
1194 buffer,&len,&index),"Unable to query header\n");
1195 ok(index == 1, "Index was not incremented\n");
1196 ok(strcmp(buffer,"test2")==0, "incorrect string was returned(%s)\n",buffer);
1197 len = sizeof(buffer);
1198 strcpy(buffer,"Warning");
1199 ok(HttpQueryInfo(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS,
1200 buffer,&len,&index),"Failed to get second header\n");
1201 ok(index == 2, "Index was not incremented\n");
1202 ok(strcmp(buffer,"test3")==0, "incorrect string was returned(%s)\n",buffer);
1203 len = sizeof(buffer);
1204 strcpy(buffer,"Warning");
1205 ok(HttpQueryInfo(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS,
1206 buffer,&len,&index)==0,"Third Header Should Not Exist\n");
1208 ok(HttpAddRequestHeaders(hRequest,"Warning:test4",-1,HTTP_ADDREQ_FLAG_ADD_IF_NEW)==0, "HTTP_ADDREQ_FLAG_ADD_IF_NEW replaced existing header\n");
1211 len = sizeof(buffer);
1212 strcpy(buffer,"Warning");
1213 ok(HttpQueryInfo(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS,
1214 buffer,&len,&index),"Unable to query header\n");
1215 ok(index == 1, "Index was not incremented\n");
1216 ok(strcmp(buffer,"test2")==0, "incorrect string was returned(%s)\n",buffer);
1217 len = sizeof(buffer);
1218 strcpy(buffer,"Warning");
1219 ok(HttpQueryInfo(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS,
1220 buffer,&len,&index),"Failed to get second header\n");
1221 ok(index == 2, "Index was not incremented\n");
1222 ok(strcmp(buffer,"test3")==0, "incorrect string was returned(%s)\n",buffer);
1223 len = sizeof(buffer);
1224 strcpy(buffer,"Warning");
1225 ok(HttpQueryInfo(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS,
1226 buffer,&len,&index)==0,"Third Header Should Not Exist\n");
1228 ok(HttpAddRequestHeaders(hRequest,"Warning:test4",-1, HTTP_ADDREQ_FLAG_COALESCE), "HTTP_ADDREQ_FLAG_COALESCE Did not work\n");
1231 len = sizeof(buffer);
1232 strcpy(buffer,"Warning");
1233 ok(HttpQueryInfo(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS,
1234 buffer,&len,&index),"Unable to query header\n");
1235 ok(index == 1, "Index was not incremented\n");
1236 ok(strcmp(buffer,"test2, test4")==0, "incorrect string was returned(%s)\n", buffer);
1237 len = sizeof(buffer);
1238 strcpy(buffer,"Warning");
1239 ok(HttpQueryInfo(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS, buffer,&len,&index),"Failed to get second header\n");
1240 ok(index == 2, "Index was not incremented\n");
1241 ok(strcmp(buffer,"test3")==0, "incorrect string was returned(%s)\n",buffer);
1242 len = sizeof(buffer);
1243 strcpy(buffer,"Warning");
1244 ok(HttpQueryInfo(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS, buffer,&len,&index)==0,"Third Header Should Not Exist\n");
1246 ok(HttpAddRequestHeaders(hRequest,"Warning:test5",-1, HTTP_ADDREQ_FLAG_COALESCE_WITH_COMMA), "HTTP_ADDREQ_FLAG_COALESCE Did not work\n");
1249 len = sizeof(buffer);
1250 strcpy(buffer,"Warning");
1251 ok(HttpQueryInfo(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS, buffer,&len,&index),"Unable to query header\n");
1252 ok(index == 1, "Index was not incremented\n");
1253 ok(strcmp(buffer,"test2, test4, test5")==0, "incorrect string was returned(%s)\n",buffer);
1254 len = sizeof(buffer);
1255 strcpy(buffer,"Warning");
1256 ok(HttpQueryInfo(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS, buffer,&len,&index),"Failed to get second header\n");
1257 ok(index == 2, "Index was not incremented\n");
1258 ok(strcmp(buffer,"test3")==0, "incorrect string was returned(%s)\n",buffer);
1259 len = sizeof(buffer);
1260 strcpy(buffer,"Warning");
1261 ok(HttpQueryInfo(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS, buffer,&len,&index)==0,"Third Header Should Not Exist\n");
1263 ok(HttpAddRequestHeaders(hRequest,"Warning:test6",-1, HTTP_ADDREQ_FLAG_COALESCE_WITH_SEMICOLON), "HTTP_ADDREQ_FLAG_COALESCE Did not work\n");
1266 len = sizeof(buffer);
1267 strcpy(buffer,"Warning");
1268 ok(HttpQueryInfo(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS, buffer,&len,&index),"Unable to query header\n");
1269 ok(index == 1, "Index was not incremented\n");
1270 ok(strcmp(buffer,"test2, test4, test5; test6")==0, "incorrect string was returned(%s)\n",buffer);
1271 len = sizeof(buffer);
1272 strcpy(buffer,"Warning");
1273 ok(HttpQueryInfo(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS, buffer,&len,&index),"Failed to get second header\n");
1274 ok(index == 2, "Index was not incremented\n");
1275 ok(strcmp(buffer,"test3")==0, "incorrect string was returned(%s)\n",buffer);
1276 len = sizeof(buffer);
1277 strcpy(buffer,"Warning");
1278 ok(HttpQueryInfo(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS, buffer,&len,&index)==0,"Third Header Should Not Exist\n");
1280 ok(HttpAddRequestHeaders(hRequest,"Warning:test7",-1, HTTP_ADDREQ_FLAG_ADD|HTTP_ADDREQ_FLAG_REPLACE), "HTTP_ADDREQ_FLAG_ADD with HTTP_ADDREQ_FLAG_REPALCE Did not work\n");
1283 len = sizeof(buffer);
1284 strcpy(buffer,"Warning");
1285 ok(HttpQueryInfo(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS, buffer,&len,&index),"Unable to query header\n");
1286 ok(index == 1, "Index was not incremented\n");
1287 ok(strcmp(buffer,"test3")==0, "incorrect string was returned(%s)\n",buffer);
1288 len = sizeof(buffer);
1289 strcpy(buffer,"Warning");
1290 ok(HttpQueryInfo(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS, buffer,&len,&index),"Failed to get second header\n");
1291 ok(index == 2, "Index was not incremented\n");
1292 ok(strcmp(buffer,"test7")==0, "incorrect string was returned(%s)\n",buffer);
1293 len = sizeof(buffer);
1294 strcpy(buffer,"Warning");
1295 ok(HttpQueryInfo(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS, buffer,&len,&index)==0,"Third Header Should Not Exist\n");
1298 ok(InternetCloseHandle(hRequest), "Close request handle failed\n");
1300 ok(InternetCloseHandle(hConnect), "Close connect handle failed\n");
1301 ok(InternetCloseHandle(hSession), "Close session handle failed\n");
1304 static const char contmsg[] =
1305 "HTTP/1.1 100 Continue\r\n";
1307 static const char okmsg[] =
1308 "HTTP/1.1 200 OK\r\n"
1309 "Server: winetest\r\n"
1312 static const char notokmsg[] =
1313 "HTTP/1.1 400 Bad Request\r\n"
1314 "Server: winetest\r\n"
1317 static const char noauthmsg[] =
1318 "HTTP/1.1 401 Unauthorized\r\n"
1319 "Server: winetest\r\n"
1322 static const char proxymsg[] =
1323 "HTTP/1.1 407 Proxy Authentication Required\r\n"
1324 "Server: winetest\r\n"
1325 "Proxy-Connection: close\r\n"
1326 "Proxy-Authenticate: Basic realm=\"placebo\"\r\n"
1329 static const char page1[] =
1331 "<HEAD><TITLE>wininet test page</TITLE></HEAD>\r\n"
1332 "<BODY>The quick brown fox jumped over the lazy dog<P></BODY>\r\n"
1335 struct server_info {
1340 static DWORD CALLBACK server_thread(LPVOID param)
1342 struct server_info *si = param;
1345 struct sockaddr_in sa;
1348 int last_request = 0;
1350 WSAStartup(MAKEWORD(1,1), &wsaData);
1352 s = socket(AF_INET, SOCK_STREAM, 0);
1353 if (s == INVALID_SOCKET)
1357 setsockopt(s, SOL_SOCKET, SO_REUSEADDR, (char*)&on, sizeof on);
1359 memset(&sa, 0, sizeof sa);
1360 sa.sin_family = AF_INET;
1361 sa.sin_port = htons(si->port);
1362 sa.sin_addr.S_un.S_addr = inet_addr("127.0.0.1");
1364 r = bind(s, (struct sockaddr*) &sa, sizeof sa);
1370 SetEvent(si->hEvent);
1374 c = accept(s, NULL, NULL);
1376 memset(buffer, 0, sizeof buffer);
1377 for(i=0; i<(sizeof buffer-1); i++)
1379 r = recv(c, &buffer[i], 1, 0);
1383 if (buffer[i-2] == '\n' && buffer[i] == '\n' &&
1384 buffer[i-3] == '\r' && buffer[i-1] == '\r')
1387 if (strstr(buffer, "GET /test1"))
1389 if (!strstr(buffer, "Content-Length: 0"))
1391 send(c, okmsg, sizeof okmsg-1, 0);
1392 send(c, page1, sizeof page1-1, 0);
1395 send(c, notokmsg, sizeof notokmsg-1, 0);
1397 if (strstr(buffer, "/test2"))
1399 if (strstr(buffer, "Proxy-Authorization: Basic bWlrZToxMTAx"))
1401 send(c, okmsg, sizeof okmsg-1, 0);
1402 send(c, page1, sizeof page1-1, 0);
1405 send(c, proxymsg, sizeof proxymsg-1, 0);
1407 if (strstr(buffer, "/test3"))
1409 if (strstr(buffer, "Authorization: Basic dXNlcjpwd2Q="))
1410 send(c, okmsg, sizeof okmsg-1, 0);
1412 send(c, noauthmsg, sizeof noauthmsg-1, 0);
1414 if (strstr(buffer, "/test4"))
1416 if (strstr(buffer, "Connection: Close"))
1417 send(c, okmsg, sizeof okmsg-1, 0);
1419 send(c, notokmsg, sizeof notokmsg-1, 0);
1421 if (strstr(buffer, "POST /test5"))
1423 if (strstr(buffer, "Content-Length: 0"))
1425 send(c, okmsg, sizeof okmsg-1, 0);
1426 send(c, page1, sizeof page1-1, 0);
1429 send(c, notokmsg, sizeof notokmsg-1, 0);
1431 if (strstr(buffer, "GET /test6"))
1433 send(c, contmsg, sizeof contmsg-1, 0);
1434 send(c, contmsg, sizeof contmsg-1, 0);
1435 send(c, okmsg, sizeof okmsg-1, 0);
1436 send(c, page1, sizeof page1-1, 0);
1438 if (strstr(buffer, "POST /test7"))
1440 if (strstr(buffer, "Content-Length: 100"))
1442 send(c, okmsg, sizeof okmsg-1, 0);
1443 send(c, page1, sizeof page1-1, 0);
1446 send(c, notokmsg, sizeof notokmsg-1, 0);
1448 if (strstr(buffer, "/test8"))
1450 if (!strstr(buffer, "Connection: Close") &&
1451 strstr(buffer, "Connection: Keep-Alive"))
1452 send(c, okmsg, sizeof okmsg-1, 0);
1454 send(c, notokmsg, sizeof notokmsg-1, 0);
1456 if (strstr(buffer, "/test9"))
1458 if (!strstr(buffer, "Connection: Close") &&
1459 !strstr(buffer, "Connection: Keep-Alive"))
1460 send(c, okmsg, sizeof okmsg-1, 0);
1462 send(c, notokmsg, sizeof notokmsg-1, 0);
1464 if (strstr(buffer, "GET /quit"))
1466 send(c, okmsg, sizeof okmsg-1, 0);
1467 send(c, page1, sizeof page1-1, 0);
1473 } while (!last_request);
1480 static void test_basic_request(int port, const char *verb, const char *url)
1482 HINTERNET hi, hc, hr;
1486 hi = InternetOpen(NULL, INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, 0);
1487 ok(hi != NULL, "open failed\n");
1489 hc = InternetConnect(hi, "localhost", port, NULL, NULL, INTERNET_SERVICE_HTTP, 0, 0);
1490 ok(hc != NULL, "connect failed\n");
1492 hr = HttpOpenRequest(hc, verb, url, NULL, NULL, NULL, 0, 0);
1493 ok(hr != NULL, "HttpOpenRequest failed\n");
1495 r = HttpSendRequest(hr, NULL, 0, NULL, 0);
1496 ok(r, "HttpSendRequest failed\n");
1499 memset(buffer, 0, sizeof buffer);
1500 r = InternetReadFile(hr, buffer, sizeof buffer, &count);
1501 ok(r, "InternetReadFile failed\n");
1502 ok(count == sizeof page1 - 1, "count was wrong\n");
1503 ok(!memcmp(buffer, page1, sizeof page1), "http data wrong\n");
1505 InternetCloseHandle(hr);
1506 InternetCloseHandle(hc);
1507 InternetCloseHandle(hi);
1510 static void test_proxy_indirect(int port)
1512 HINTERNET hi, hc, hr;
1516 hi = InternetOpen(NULL, 0, NULL, NULL, 0);
1517 ok(hi != NULL, "open failed\n");
1519 hc = InternetConnect(hi, "localhost", port, NULL, NULL, INTERNET_SERVICE_HTTP, 0, 0);
1520 ok(hc != NULL, "connect failed\n");
1522 hr = HttpOpenRequest(hc, NULL, "/test2", NULL, NULL, NULL, 0, 0);
1523 ok(hr != NULL, "HttpOpenRequest failed\n");
1525 r = HttpSendRequest(hr, NULL, 0, NULL, 0);
1526 ok(r, "HttpSendRequest failed\n");
1529 r = HttpQueryInfo(hr, HTTP_QUERY_PROXY_AUTHENTICATE, buffer, &sz, NULL);
1530 ok(r, "HttpQueryInfo failed\n");
1531 ok(!strcmp(buffer, "Basic realm=\"placebo\""), "proxy auth info wrong\n");
1534 r = HttpQueryInfo(hr, HTTP_QUERY_STATUS_CODE, buffer, &sz, NULL);
1535 ok(r, "HttpQueryInfo failed\n");
1536 ok(!strcmp(buffer, "407"), "proxy code wrong\n");
1539 r = HttpQueryInfo(hr, HTTP_QUERY_STATUS_CODE|HTTP_QUERY_FLAG_NUMBER, &val, &sz, NULL);
1540 ok(r, "HttpQueryInfo failed\n");
1541 ok(val == 407, "proxy code wrong\n");
1544 r = HttpQueryInfo(hr, HTTP_QUERY_STATUS_TEXT, buffer, &sz, NULL);
1545 ok(r, "HttpQueryInfo failed\n");
1546 ok(!strcmp(buffer, "Proxy Authentication Required"), "proxy text wrong\n");
1549 r = HttpQueryInfo(hr, HTTP_QUERY_VERSION, buffer, &sz, NULL);
1550 ok(r, "HttpQueryInfo failed\n");
1551 ok(!strcmp(buffer, "HTTP/1.1"), "http version wrong\n");
1554 r = HttpQueryInfo(hr, HTTP_QUERY_SERVER, buffer, &sz, NULL);
1555 ok(r, "HttpQueryInfo failed\n");
1556 ok(!strcmp(buffer, "winetest"), "http server wrong\n");
1559 r = HttpQueryInfo(hr, HTTP_QUERY_CONTENT_ENCODING, buffer, &sz, NULL);
1560 ok(GetLastError() == ERROR_HTTP_HEADER_NOT_FOUND, "HttpQueryInfo should fail\n");
1561 ok(r == FALSE, "HttpQueryInfo failed\n");
1563 InternetCloseHandle(hr);
1564 InternetCloseHandle(hc);
1565 InternetCloseHandle(hi);
1568 static void test_proxy_direct(int port)
1570 HINTERNET hi, hc, hr;
1573 static CHAR username[] = "mike",
1574 password[] = "1101";
1576 sprintf(buffer, "localhost:%d\n", port);
1577 hi = InternetOpen(NULL, INTERNET_OPEN_TYPE_PROXY, buffer, NULL, 0);
1578 ok(hi != NULL, "open failed\n");
1580 /* try connect without authorization */
1581 hc = InternetConnect(hi, "www.winehq.org/", port, NULL, NULL, INTERNET_SERVICE_HTTP, 0, 0);
1582 ok(hc != NULL, "connect failed\n");
1584 hr = HttpOpenRequest(hc, NULL, "/test2", NULL, NULL, NULL, 0, 0);
1585 ok(hr != NULL, "HttpOpenRequest failed\n");
1587 r = HttpSendRequest(hr, NULL, 0, NULL, 0);
1588 ok(r, "HttpSendRequest failed\n");
1591 r = HttpQueryInfo(hr, HTTP_QUERY_STATUS_CODE, buffer, &sz, NULL);
1592 ok(r, "HttpQueryInfo failed\n");
1593 ok(!strcmp(buffer, "407"), "proxy code wrong\n");
1596 /* set the user + password then try again */
1598 r = InternetSetOption(hr, INTERNET_OPTION_PROXY_USERNAME, username, 4);
1599 ok(r, "failed to set user\n");
1601 r = InternetSetOption(hr, INTERNET_OPTION_PROXY_PASSWORD, password, 4);
1602 ok(r, "failed to set password\n");
1605 r = HttpSendRequest(hr, NULL, 0, NULL, 0);
1606 ok(r, "HttpSendRequest failed\n");
1608 r = HttpQueryInfo(hr, HTTP_QUERY_STATUS_CODE, buffer, &sz, NULL);
1609 ok(r, "HttpQueryInfo failed\n");
1611 ok(!strcmp(buffer, "200"), "proxy code wrong\n");
1615 InternetCloseHandle(hr);
1616 InternetCloseHandle(hc);
1617 InternetCloseHandle(hi);
1620 static void test_header_handling_order(int port)
1622 static char authorization[] = "Authorization: Basic dXNlcjpwd2Q=";
1623 static char connection[] = "Connection: Close";
1625 static const char *types[2] = { "*", NULL };
1626 HINTERNET session, connect, request;
1630 session = InternetOpen("winetest", INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, 0);
1631 ok(session != NULL, "InternetOpen failed\n");
1633 connect = InternetConnect(session, "localhost", port, NULL, NULL, INTERNET_SERVICE_HTTP, 0, 0);
1634 ok(connect != NULL, "InternetConnect failed\n");
1636 request = HttpOpenRequest(connect, NULL, "/test3", NULL, NULL, types, INTERNET_FLAG_KEEP_CONNECTION, 0);
1637 ok(request != NULL, "HttpOpenRequest failed\n");
1639 ret = HttpAddRequestHeaders(request, authorization, ~0UL, HTTP_ADDREQ_FLAG_ADD);
1640 ok(ret, "HttpAddRequestHeaders failed\n");
1642 ret = HttpSendRequest(request, NULL, 0, NULL, 0);
1643 ok(ret, "HttpSendRequest failed\n");
1646 size = sizeof(status);
1647 ret = HttpQueryInfo( request, HTTP_QUERY_STATUS_CODE | HTTP_QUERY_FLAG_NUMBER, &status, &size, NULL );
1648 ok(ret, "HttpQueryInfo failed\n");
1649 ok(status == 200, "request failed with status %u\n", status);
1651 InternetCloseHandle(request);
1653 request = HttpOpenRequest(connect, NULL, "/test4", NULL, NULL, types, INTERNET_FLAG_KEEP_CONNECTION, 0);
1654 ok(request != NULL, "HttpOpenRequest failed\n");
1656 ret = HttpSendRequest(request, connection, ~0UL, NULL, 0);
1657 ok(ret, "HttpSendRequest failed\n");
1660 size = sizeof(status);
1661 ret = HttpQueryInfo( request, HTTP_QUERY_STATUS_CODE | HTTP_QUERY_FLAG_NUMBER, &status, &size, NULL );
1662 ok(ret, "HttpQueryInfo failed\n");
1663 ok(status == 200, "request failed with status %u\n", status);
1665 InternetCloseHandle(request);
1667 request = HttpOpenRequest(connect, "POST", "/test7", NULL, NULL, types, INTERNET_FLAG_KEEP_CONNECTION, 0);
1668 ok(request != NULL, "HttpOpenRequest failed\n");
1670 ret = HttpAddRequestHeaders(request, "Content-Length: 100\r\n", ~0UL, HTTP_ADDREQ_FLAG_ADD_IF_NEW);
1671 ok(ret, "HttpAddRequestHeaders failed\n");
1673 ret = HttpSendRequest(request, connection, ~0UL, NULL, 0);
1674 ok(ret, "HttpSendRequest failed\n");
1677 size = sizeof(status);
1678 ret = HttpQueryInfo( request, HTTP_QUERY_STATUS_CODE | HTTP_QUERY_FLAG_NUMBER, &status, &size, NULL );
1679 ok(ret, "HttpQueryInfo failed\n");
1680 ok(status == 200 || status == 400 /* IE6 */, "request failed with status %u\n", status);
1682 InternetCloseHandle(request);
1683 InternetCloseHandle(connect);
1684 InternetCloseHandle(session);
1687 static void test_connection_header(int port)
1689 HINTERNET ses, con, req;
1693 ses = InternetOpen("winetest", INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, 0);
1694 ok(ses != NULL, "InternetOpen failed\n");
1696 con = InternetConnect(ses, "localhost", port, NULL, NULL, INTERNET_SERVICE_HTTP, 0, 0);
1697 ok(con != NULL, "InternetConnect failed\n");
1699 req = HttpOpenRequest(con, NULL, "/test8", NULL, NULL, NULL, INTERNET_FLAG_KEEP_CONNECTION, 0);
1700 ok(req != NULL, "HttpOpenRequest failed\n");
1702 ret = HttpSendRequest(req, NULL, 0, NULL, 0);
1703 ok(ret, "HttpSendRequest failed\n");
1706 size = sizeof(status);
1707 ret = HttpQueryInfo(req, HTTP_QUERY_STATUS_CODE | HTTP_QUERY_FLAG_NUMBER, &status, &size, NULL);
1708 ok(ret, "HttpQueryInfo failed\n");
1709 ok(status == 200, "request failed with status %u\n", status);
1711 InternetCloseHandle(req);
1713 req = HttpOpenRequest(con, NULL, "/test9", NULL, NULL, NULL, 0, 0);
1714 ok(req != NULL, "HttpOpenRequest failed\n");
1716 ret = HttpSendRequest(req, NULL, 0, NULL, 0);
1717 ok(ret, "HttpSendRequest failed\n");
1720 size = sizeof(status);
1721 ret = HttpQueryInfo(req, HTTP_QUERY_STATUS_CODE | HTTP_QUERY_FLAG_NUMBER, &status, &size, NULL);
1722 ok(ret, "HttpQueryInfo failed\n");
1723 ok(status == 200, "request failed with status %u\n", status);
1725 InternetCloseHandle(req);
1726 InternetCloseHandle(con);
1727 InternetCloseHandle(ses);
1730 static void test_http_connection(void)
1732 struct server_info si;
1736 si.hEvent = CreateEvent(NULL, 0, 0, NULL);
1739 hThread = CreateThread(NULL, 0, server_thread, (LPVOID) &si, 0, &id);
1740 ok( hThread != NULL, "create thread failed\n");
1742 r = WaitForSingleObject(si.hEvent, 10000);
1743 ok (r == WAIT_OBJECT_0, "failed to start wininet test server\n");
1744 if (r != WAIT_OBJECT_0)
1747 test_basic_request(si.port, "GET", "/test1");
1748 test_proxy_indirect(si.port);
1749 test_proxy_direct(si.port);
1750 test_header_handling_order(si.port);
1751 test_basic_request(si.port, "POST", "/test5");
1752 test_basic_request(si.port, "GET", "/test6");
1753 test_connection_header(si.port);
1755 /* send the basic request again to shutdown the server thread */
1756 test_basic_request(si.port, "GET", "/quit");
1758 r = WaitForSingleObject(hThread, 3000);
1759 ok( r == WAIT_OBJECT_0, "thread wait failed\n");
1760 CloseHandle(hThread);
1763 static void test_user_agent_header(void)
1765 HINTERNET ses, con, req;
1770 ses = InternetOpen("Gizmo5", INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, 0);
1771 ok(ses != NULL, "InternetOpen failed\n");
1773 con = InternetConnect(ses, "www.winehq.org", 80, NULL, NULL, INTERNET_SERVICE_HTTP, 0, 0);
1774 ok(con != NULL, "InternetConnect failed\n");
1776 req = HttpOpenRequest(con, "GET", "/", "HTTP/1.0", NULL, NULL, 0, 0);
1777 ok(req != NULL, "HttpOpenRequest failed\n");
1779 size = sizeof(buffer);
1780 ret = HttpQueryInfo(req, HTTP_QUERY_USER_AGENT | HTTP_QUERY_FLAG_REQUEST_HEADERS, buffer, &size, NULL);
1781 err = GetLastError();
1782 ok(!ret, "HttpQueryInfo succeeded\n");
1783 ok(err == ERROR_HTTP_HEADER_NOT_FOUND, "expected ERROR_HTTP_HEADER_NOT_FOUND, got %u\n", err);
1785 ret = HttpAddRequestHeaders(req, "User-Agent: Gizmo Project\r\n", ~0UL, HTTP_ADDREQ_FLAG_ADD_IF_NEW);
1786 ok(ret, "HttpAddRequestHeaders succeeded\n");
1788 size = sizeof(buffer);
1789 ret = HttpQueryInfo(req, HTTP_QUERY_USER_AGENT | HTTP_QUERY_FLAG_REQUEST_HEADERS, buffer, &size, NULL);
1790 err = GetLastError();
1791 ok(ret, "HttpQueryInfo failed\n");
1792 ok(err == ERROR_HTTP_HEADER_NOT_FOUND, "expected ERROR_HTTP_HEADER_NOT_FOUND, got %u\n", err);
1794 InternetCloseHandle(req);
1796 req = HttpOpenRequest(con, "GET", "/", "HTTP/1.0", NULL, NULL, 0, 0);
1797 ok(req != NULL, "HttpOpenRequest failed\n");
1799 size = sizeof(buffer);
1800 ret = HttpQueryInfo(req, HTTP_QUERY_ACCEPT | HTTP_QUERY_FLAG_REQUEST_HEADERS, buffer, &size, NULL);
1801 err = GetLastError();
1802 ok(!ret, "HttpQueryInfo succeeded\n");
1803 ok(err == ERROR_HTTP_HEADER_NOT_FOUND, "expected ERROR_HTTP_HEADER_NOT_FOUND, got %u\n", err);
1805 ret = HttpAddRequestHeaders(req, "Accept: audio/*, image/*, text/*\r\nUser-Agent: Gizmo Project\r\n", ~0UL, HTTP_ADDREQ_FLAG_ADD_IF_NEW);
1806 ok(ret, "HttpAddRequestHeaders failed\n");
1809 size = sizeof(buffer);
1810 ret = HttpQueryInfo(req, HTTP_QUERY_ACCEPT | HTTP_QUERY_FLAG_REQUEST_HEADERS, buffer, &size, NULL);
1811 ok(ret, "HttpQueryInfo failed: %u\n", GetLastError());
1812 ok(!strcmp(buffer, "audio/*, image/*, text/*"), "got '%s' expected 'audio/*, image/*, text/*'\n", buffer);
1814 InternetCloseHandle(req);
1815 InternetCloseHandle(con);
1816 InternetCloseHandle(ses);
1819 static void test_bogus_accept_types_array(void)
1821 HINTERNET ses, con, req;
1822 static const char *types[] = { (const char *)6240, "*/*", "%p", "", "*/*", NULL };
1827 ses = InternetOpen("MERONG(0.9/;p)", INTERNET_OPEN_TYPE_DIRECT, "", "", 0);
1828 con = InternetConnect(ses, "www.winehq.org", 80, NULL, NULL, INTERNET_SERVICE_HTTP, 0, 0);
1829 req = HttpOpenRequest(con, "POST", "/post/post_action.php", "HTTP/1.0", "", types, INTERNET_FLAG_FORMS_SUBMIT, 0);
1831 ok(req != NULL, "HttpOpenRequest failed: %u\n", GetLastError());
1834 size = sizeof(buffer);
1835 ret = HttpQueryInfo(req, HTTP_QUERY_ACCEPT | HTTP_QUERY_FLAG_REQUEST_HEADERS, buffer, &size, NULL);
1836 ok(ret, "HttpQueryInfo failed: %u\n", GetLastError());
1837 ok(!strcmp(buffer, ", */*, %p, , */*") || /* IE6 */
1838 !strcmp(buffer, "*/*, %p, */*"),
1839 "got '%s' expected '*/*, %%p, */*' or ', */*, %%p, , */*'\n", buffer);
1841 InternetCloseHandle(req);
1842 InternetCloseHandle(con);
1843 InternetCloseHandle(ses);
1852 static void WINAPI cb(HINTERNET handle, DWORD_PTR context, DWORD status, LPVOID info, DWORD size)
1854 INTERNET_ASYNC_RESULT *result = info;
1855 struct context *ctx = (struct context *)context;
1857 trace("%p 0x%08lx %u %p 0x%08x\n", handle, context, status, info, size);
1859 if (status == INTERNET_STATUS_REQUEST_COMPLETE)
1861 trace("request handle: 0x%08lx\n", result->dwResult);
1862 ctx->req = (HINTERNET)result->dwResult;
1863 SetEvent(ctx->event);
1865 if (status == INTERNET_STATUS_HANDLE_CLOSING)
1867 DWORD type = INTERNET_HANDLE_TYPE_CONNECT_HTTP, size = sizeof(type);
1869 if (InternetQueryOption(handle, INTERNET_OPTION_HANDLE_TYPE, &type, &size))
1870 ok(type != INTERNET_HANDLE_TYPE_CONNECT_HTTP, "unexpected callback\n");
1871 SetEvent(ctx->event);
1875 static void test_open_url_async(void)
1884 ctx.event = CreateEvent(NULL, TRUE, FALSE, "Z:_home_hans_jaman-installer.exe_ev1");
1886 ses = InternetOpen("AdvancedInstaller", 0, NULL, NULL, INTERNET_FLAG_ASYNC);
1887 ok(ses != NULL, "InternetOpen failed\n");
1889 pInternetSetStatusCallbackA(ses, cb);
1890 ResetEvent(ctx.event);
1892 req = InternetOpenUrl(ses, "http://www.winehq.org", NULL, 0, 0, (DWORD_PTR)&ctx);
1893 ok(!req && GetLastError() == ERROR_IO_PENDING, "InternetOpenUrl failed\n");
1895 WaitForSingleObject(ctx.event, INFINITE);
1898 size = sizeof(type);
1899 ret = InternetQueryOption(ctx.req, INTERNET_OPTION_HANDLE_TYPE, &type, &size);
1900 ok(ret, "InternetQueryOption failed: %u\n", GetLastError());
1901 ok(type == INTERNET_HANDLE_TYPE_HTTP_REQUEST,
1902 "expected INTERNET_HANDLE_TYPE_HTTP_REQUEST, got %u\n", type);
1905 ret = HttpQueryInfo(ctx.req, HTTP_QUERY_RAW_HEADERS_CRLF, NULL, &size, NULL);
1906 ok(!ret && GetLastError() == ERROR_INSUFFICIENT_BUFFER, "HttpQueryInfo failed\n");
1907 ok(size > 0, "expected size > 0\n");
1909 ResetEvent(ctx.event);
1910 InternetCloseHandle(ctx.req);
1911 WaitForSingleObject(ctx.event, INFINITE);
1913 InternetCloseHandle(ses);
1914 CloseHandle(ctx.event);
1917 #define STATUS_STRING(status) \
1918 memcpy(status_string[status], #status, sizeof(CHAR) * \
1919 (strlen(#status) < MAX_STATUS_NAME ? \
1921 MAX_STATUS_NAME - 1))
1922 static void init_status_tests(void)
1924 memset(expect, 0, sizeof(expect));
1925 memset(wine_allow, 0, sizeof(wine_allow));
1926 memset(notified, 0, sizeof(notified));
1927 memset(status_string, 0, sizeof(status_string));
1928 STATUS_STRING(INTERNET_STATUS_RESOLVING_NAME);
1929 STATUS_STRING(INTERNET_STATUS_NAME_RESOLVED);
1930 STATUS_STRING(INTERNET_STATUS_CONNECTING_TO_SERVER);
1931 STATUS_STRING(INTERNET_STATUS_CONNECTED_TO_SERVER);
1932 STATUS_STRING(INTERNET_STATUS_SENDING_REQUEST);
1933 STATUS_STRING(INTERNET_STATUS_REQUEST_SENT);
1934 STATUS_STRING(INTERNET_STATUS_RECEIVING_RESPONSE);
1935 STATUS_STRING(INTERNET_STATUS_RESPONSE_RECEIVED);
1936 STATUS_STRING(INTERNET_STATUS_CTL_RESPONSE_RECEIVED);
1937 STATUS_STRING(INTERNET_STATUS_PREFETCH);
1938 STATUS_STRING(INTERNET_STATUS_CLOSING_CONNECTION);
1939 STATUS_STRING(INTERNET_STATUS_CONNECTION_CLOSED);
1940 STATUS_STRING(INTERNET_STATUS_HANDLE_CREATED);
1941 STATUS_STRING(INTERNET_STATUS_HANDLE_CLOSING);
1942 STATUS_STRING(INTERNET_STATUS_DETECTING_PROXY);
1943 STATUS_STRING(INTERNET_STATUS_REQUEST_COMPLETE);
1944 STATUS_STRING(INTERNET_STATUS_REDIRECT);
1945 STATUS_STRING(INTERNET_STATUS_INTERMEDIATE_RESPONSE);
1946 STATUS_STRING(INTERNET_STATUS_USER_INPUT_REQUIRED);
1947 STATUS_STRING(INTERNET_STATUS_STATE_CHANGE);
1948 STATUS_STRING(INTERNET_STATUS_COOKIE_SENT);
1949 STATUS_STRING(INTERNET_STATUS_COOKIE_RECEIVED);
1950 STATUS_STRING(INTERNET_STATUS_PRIVACY_IMPACTED);
1951 STATUS_STRING(INTERNET_STATUS_P3P_HEADER);
1952 STATUS_STRING(INTERNET_STATUS_P3P_POLICYREF);
1953 STATUS_STRING(INTERNET_STATUS_COOKIE_HISTORY);
1955 #undef STATUS_STRING
1960 hdll = GetModuleHandleA("wininet.dll");
1961 pInternetSetStatusCallbackA = (void*)GetProcAddress(hdll, "InternetSetStatusCallbackA");
1962 pInternetTimeFromSystemTimeA = (void*)GetProcAddress(hdll, "InternetTimeFromSystemTimeA");
1963 pInternetTimeFromSystemTimeW = (void*)GetProcAddress(hdll, "InternetTimeFromSystemTimeW");
1964 pInternetTimeToSystemTimeA = (void*)GetProcAddress(hdll, "InternetTimeToSystemTimeA");
1965 pInternetTimeToSystemTimeW = (void*)GetProcAddress(hdll, "InternetTimeToSystemTimeW");
1967 if (!pInternetSetStatusCallbackA)
1968 skip("skipping the InternetReadFile tests\n");
1971 init_status_tests();
1972 InternetReadFile_test(INTERNET_FLAG_ASYNC);
1973 InternetReadFile_test(0);
1974 InternetReadFileExA_test(INTERNET_FLAG_ASYNC);
1975 test_open_url_async();
1977 InternetOpenRequest_test();
1979 InternetOpenUrlA_test();
1980 if (!pInternetTimeFromSystemTimeA)
1981 skip("skipping the InternetTime tests\n");
1984 InternetTimeFromSystemTimeA_test();
1985 InternetTimeFromSystemTimeW_test();
1986 InternetTimeToSystemTimeA_test();
1987 InternetTimeToSystemTimeW_test();
1989 HttpSendRequestEx_test();
1991 test_http_connection();
1992 test_user_agent_header();
1993 test_bogus_accept_types_array();