Release 1.6-rc2.
[wine/testsucceed.git] / dlls / wininet / tests / internet.c
blobbf5723c21672de805b1dbd4c2ddec5a0868adc4c
1 /*
2 * Wininet - internet tests
4 * Copyright 2005 Vijay Kiran Kamuju
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.
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.
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
21 #include <stdarg.h>
22 #include <stdio.h>
23 #include <string.h>
24 #include "windef.h"
25 #include "winbase.h"
26 #include "winuser.h"
27 #include "wininet.h"
28 #include "winerror.h"
29 #include "winreg.h"
31 #include "wine/test.h"
33 static BOOL (WINAPI *pCreateUrlCacheContainerA)(DWORD, DWORD, DWORD, DWORD,
34 DWORD, DWORD, DWORD, DWORD);
35 static BOOL (WINAPI *pCreateUrlCacheContainerW)(DWORD, DWORD, DWORD, DWORD,
36 DWORD, DWORD, DWORD, DWORD);
37 static BOOL (WINAPI *pInternetTimeFromSystemTimeA)(CONST SYSTEMTIME *,DWORD ,LPSTR ,DWORD);
38 static BOOL (WINAPI *pInternetTimeFromSystemTimeW)(CONST SYSTEMTIME *,DWORD ,LPWSTR ,DWORD);
39 static BOOL (WINAPI *pInternetTimeToSystemTimeA)(LPCSTR ,SYSTEMTIME *,DWORD);
40 static BOOL (WINAPI *pInternetTimeToSystemTimeW)(LPCWSTR ,SYSTEMTIME *,DWORD);
41 static BOOL (WINAPI *pIsDomainLegalCookieDomainW)(LPCWSTR, LPCWSTR);
42 static DWORD (WINAPI *pPrivacyGetZonePreferenceW)(DWORD, DWORD, LPDWORD, LPWSTR, LPDWORD);
43 static DWORD (WINAPI *pPrivacySetZonePreferenceW)(DWORD, DWORD, DWORD, LPCWSTR);
44 static BOOL (WINAPI *pInternetGetCookieExA)(LPCSTR,LPCSTR,LPSTR,LPDWORD,DWORD,LPVOID);
45 static BOOL (WINAPI *pInternetGetCookieExW)(LPCWSTR,LPCWSTR,LPWSTR,LPDWORD,DWORD,LPVOID);
47 /* ############################### */
49 static void test_InternetCanonicalizeUrlA(void)
51 CHAR buffer[256];
52 LPCSTR url;
53 DWORD urllen;
54 DWORD dwSize;
55 DWORD res;
57 /* Acrobat Updater 5 calls this for Adobe Reader 8.1 */
58 url = "http://swupmf.adobe.com/manifest/50/win/AdobeUpdater.upd";
59 urllen = lstrlenA(url);
61 memset(buffer, '#', sizeof(buffer)-1);
62 buffer[sizeof(buffer)-1] = '\0';
63 dwSize = 1; /* Acrobat Updater use this size */
64 SetLastError(0xdeadbeef);
65 res = InternetCanonicalizeUrlA(url, buffer, &dwSize, 0);
66 ok( !res && (GetLastError() == ERROR_INSUFFICIENT_BUFFER) && (dwSize == (urllen+1)),
67 "got %u and %u with size %u for '%s' (%d)\n",
68 res, GetLastError(), dwSize, buffer, lstrlenA(buffer));
71 /* buffer has no space for the terminating '\0' */
72 memset(buffer, '#', sizeof(buffer)-1);
73 buffer[sizeof(buffer)-1] = '\0';
74 dwSize = urllen;
75 SetLastError(0xdeadbeef);
76 res = InternetCanonicalizeUrlA(url, buffer, &dwSize, 0);
77 /* dwSize is nr. of needed bytes with the terminating '\0' */
78 ok( !res && (GetLastError() == ERROR_INSUFFICIENT_BUFFER) && (dwSize == (urllen+1)),
79 "got %u and %u with size %u for '%s' (%d)\n",
80 res, GetLastError(), dwSize, buffer, lstrlenA(buffer));
82 /* buffer has the required size */
83 memset(buffer, '#', sizeof(buffer)-1);
84 buffer[sizeof(buffer)-1] = '\0';
85 dwSize = urllen+1;
86 SetLastError(0xdeadbeef);
87 res = InternetCanonicalizeUrlA(url, buffer, &dwSize, 0);
88 /* dwSize is nr. of copied bytes without the terminating '\0' */
89 ok( res && (dwSize == urllen) && (lstrcmpA(url, buffer) == 0),
90 "got %u and %u with size %u for '%s' (%d)\n",
91 res, GetLastError(), dwSize, buffer, lstrlenA(buffer));
93 memset(buffer, '#', sizeof(buffer)-1);
94 buffer[sizeof(buffer)-1] = '\0';
95 dwSize = sizeof(buffer);
96 SetLastError(0xdeadbeef);
97 res = InternetCanonicalizeUrlA("file:///C:/Program%20Files/Atmel/AVR%20Tools/STK500/STK500.xml", buffer, &dwSize, ICU_DECODE | ICU_NO_ENCODE);
98 ok(res, "InternetCanonicalizeUrlA failed %u\n", GetLastError());
99 ok(dwSize == lstrlenA(buffer), "got %d expected %d\n", dwSize, lstrlenA(buffer));
100 ok(!lstrcmpA("file://C:\\Program Files\\Atmel\\AVR Tools\\STK500\\STK500.xml", buffer),
101 "got %s expected 'file://C:\\Program Files\\Atmel\\AVR Tools\\STK500\\STK500.xml'\n", buffer);
103 /* buffer is larger as the required size */
104 memset(buffer, '#', sizeof(buffer)-1);
105 buffer[sizeof(buffer)-1] = '\0';
106 dwSize = urllen+2;
107 SetLastError(0xdeadbeef);
108 res = InternetCanonicalizeUrlA(url, buffer, &dwSize, 0);
109 /* dwSize is nr. of copied bytes without the terminating '\0' */
110 ok( res && (dwSize == urllen) && (lstrcmpA(url, buffer) == 0),
111 "got %u and %u with size %u for '%s' (%d)\n",
112 res, GetLastError(), dwSize, buffer, lstrlenA(buffer));
115 /* check NULL pointers */
116 memset(buffer, '#', urllen + 4);
117 buffer[urllen + 4] = '\0';
118 dwSize = urllen+1;
119 SetLastError(0xdeadbeef);
120 res = InternetCanonicalizeUrlA(NULL, buffer, &dwSize, 0);
121 ok( !res && (GetLastError() == ERROR_INVALID_PARAMETER),
122 "got %u and %u with size %u for '%s' (%d)\n",
123 res, GetLastError(), dwSize, buffer, lstrlenA(buffer));
125 memset(buffer, '#', urllen + 4);
126 buffer[urllen + 4] = '\0';
127 dwSize = urllen+1;
128 SetLastError(0xdeadbeef);
129 res = InternetCanonicalizeUrlA(url, NULL, &dwSize, 0);
130 ok( !res && (GetLastError() == ERROR_INVALID_PARAMETER),
131 "got %u and %u with size %u for '%s' (%d)\n",
132 res, GetLastError(), dwSize, buffer, lstrlenA(buffer));
134 memset(buffer, '#', urllen + 4);
135 buffer[urllen + 4] = '\0';
136 dwSize = urllen+1;
137 SetLastError(0xdeadbeef);
138 res = InternetCanonicalizeUrlA(url, buffer, NULL, 0);
139 ok( !res && (GetLastError() == ERROR_INVALID_PARAMETER),
140 "got %u and %u with size %u for '%s' (%d)\n",
141 res, GetLastError(), dwSize, buffer, lstrlenA(buffer));
143 /* test with trailing space */
144 dwSize = 256;
145 res = InternetCanonicalizeUrlA("http://www.winehq.org/index.php?x= ", buffer, &dwSize, ICU_BROWSER_MODE);
146 ok(res == 1, "InternetCanonicalizeUrlA failed\n");
147 ok(!strcmp(buffer, "http://www.winehq.org/index.php?x="), "Trailing space should have been stripped even in ICU_BROWSER_MODE (%s)\n", buffer);
149 res = InternetSetOptionA(NULL, 0xdeadbeef, buffer, sizeof(buffer));
150 ok(!res, "InternetSetOptionA succeeded\n");
151 ok(GetLastError() == ERROR_INTERNET_INVALID_OPTION,
152 "InternetSetOptionA failed %u, expected ERROR_INTERNET_INVALID_OPTION\n", GetLastError());
155 /* ############################### */
157 static void test_InternetQueryOptionA(void)
159 HINTERNET hinet,hurl;
160 DWORD len, val;
161 DWORD err;
162 static const char useragent[] = {"Wininet Test"};
163 char *buffer;
164 int retval;
165 BOOL res;
167 SetLastError(0xdeadbeef);
168 len = 0xdeadbeef;
169 retval = InternetQueryOptionA(NULL, INTERNET_OPTION_PROXY, NULL, &len);
170 ok(!retval && GetLastError() == ERROR_INSUFFICIENT_BUFFER, "Got wrong error %x(%u)\n", retval, GetLastError());
171 ok(len >= sizeof(INTERNET_PROXY_INFO) && len != 0xdeadbeef,"len = %u\n", len);
173 hinet = InternetOpenA(useragent,INTERNET_OPEN_TYPE_DIRECT,NULL,NULL, 0);
174 ok((hinet != 0x0),"InternetOpen Failed\n");
176 SetLastError(0xdeadbeef);
177 retval=InternetQueryOptionA(NULL,INTERNET_OPTION_USER_AGENT,NULL,&len);
178 err=GetLastError();
179 ok(retval == 0,"Got wrong return value %d\n",retval);
180 ok(err == ERROR_INTERNET_INCORRECT_HANDLE_TYPE, "Got wrong error code%d\n",err);
182 SetLastError(0xdeadbeef);
183 len=strlen(useragent)+1;
184 retval=InternetQueryOptionA(hinet,INTERNET_OPTION_USER_AGENT,NULL,&len);
185 err=GetLastError();
186 ok(len == strlen(useragent)+1,"Got wrong user agent length %d instead of %d\n",len,lstrlenA(useragent));
187 ok(retval == 0,"Got wrong return value %d\n",retval);
188 ok(err == ERROR_INSUFFICIENT_BUFFER, "Got wrong error code %d\n",err);
190 SetLastError(0xdeadbeef);
191 len=strlen(useragent)+1;
192 buffer=HeapAlloc(GetProcessHeap(),0,len);
193 retval=InternetQueryOptionA(hinet,INTERNET_OPTION_USER_AGENT,buffer,&len);
194 err=GetLastError();
195 ok(retval == 1,"Got wrong return value %d\n",retval);
196 if (retval)
198 ok(!strcmp(useragent,buffer),"Got wrong user agent string %s instead of %s\n",buffer,useragent);
199 ok(len == strlen(useragent),"Got wrong user agent length %d instead of %d\n",len,lstrlenA(useragent));
201 ok(err == 0xdeadbeef, "Got wrong error code %d\n",err);
202 HeapFree(GetProcessHeap(),0,buffer);
204 SetLastError(0xdeadbeef);
205 len=0;
206 buffer=HeapAlloc(GetProcessHeap(),0,100);
207 retval=InternetQueryOptionA(hinet,INTERNET_OPTION_USER_AGENT,buffer,&len);
208 err=GetLastError();
209 ok(len == strlen(useragent) + 1,"Got wrong user agent length %d instead of %d\n", len, lstrlenA(useragent) + 1);
210 ok(!retval, "Got wrong return value %d\n", retval);
211 ok(err == ERROR_INSUFFICIENT_BUFFER, "Got wrong error code %d\n", err);
212 HeapFree(GetProcessHeap(),0,buffer);
214 hurl = InternetConnectA(hinet,"www.winehq.org",INTERNET_DEFAULT_HTTP_PORT,NULL,NULL,INTERNET_SERVICE_HTTP,0,0);
216 SetLastError(0xdeadbeef);
217 len=0;
218 retval = InternetQueryOptionA(hurl,INTERNET_OPTION_USER_AGENT,NULL,&len);
219 err=GetLastError();
220 ok(len == 0,"Got wrong user agent length %d instead of 0\n",len);
221 ok(retval == 0,"Got wrong return value %d\n",retval);
222 ok(err == ERROR_INTERNET_INCORRECT_HANDLE_TYPE, "Got wrong error code %d\n",err);
224 SetLastError(0xdeadbeef);
225 len = sizeof(DWORD);
226 retval = InternetQueryOptionA(hurl,INTERNET_OPTION_REQUEST_FLAGS,NULL,&len);
227 err = GetLastError();
228 ok(retval == 0,"Got wrong return value %d\n",retval);
229 ok(err == ERROR_INTERNET_INCORRECT_HANDLE_TYPE, "Got wrong error code %d\n",err);
230 ok(len == sizeof(DWORD), "len = %d\n", len);
232 SetLastError(0xdeadbeef);
233 len = sizeof(DWORD);
234 retval = InternetQueryOptionA(NULL,INTERNET_OPTION_REQUEST_FLAGS,NULL,&len);
235 err = GetLastError();
236 ok(retval == 0,"Got wrong return value %d\n",retval);
237 ok(err == ERROR_INTERNET_INCORRECT_HANDLE_TYPE, "Got wrong error code %d\n",err);
238 ok(!len, "len = %d\n", len);
240 InternetCloseHandle(hurl);
241 InternetCloseHandle(hinet);
243 hinet = InternetOpenA("",INTERNET_OPEN_TYPE_DIRECT,NULL,NULL, 0);
244 ok((hinet != 0x0),"InternetOpen Failed\n");
246 SetLastError(0xdeadbeef);
247 len=0;
248 retval=InternetQueryOptionA(hinet,INTERNET_OPTION_USER_AGENT,NULL,&len);
249 err=GetLastError();
250 ok(len == 1,"Got wrong user agent length %d instead of %d\n",len,1);
251 ok(retval == 0,"Got wrong return value %d\n",retval);
252 ok(err == ERROR_INSUFFICIENT_BUFFER, "Got wrong error code%d\n",err);
254 InternetCloseHandle(hinet);
256 val = 12345;
257 res = InternetSetOptionA(NULL, INTERNET_OPTION_CONNECT_TIMEOUT, &val, sizeof(val));
258 ok(res, "InternetSetOptionA(INTERNET_OPTION_CONNECT_TIMEOUT) failed (%u)\n", GetLastError());
260 len = sizeof(val);
261 res = InternetQueryOptionA(NULL, INTERNET_OPTION_CONNECT_TIMEOUT, &val, &len);
262 ok(res, "InternetQueryOptionA failed %d)\n", GetLastError());
263 ok(val == 12345, "val = %d\n", val);
264 ok(len == sizeof(val), "len = %d\n", len);
266 hinet = InternetOpenA(NULL,INTERNET_OPEN_TYPE_DIRECT,NULL,NULL, 0);
267 ok((hinet != 0x0),"InternetOpen Failed\n");
268 SetLastError(0xdeadbeef);
269 len=0;
270 retval=InternetQueryOptionA(hinet,INTERNET_OPTION_USER_AGENT,NULL,&len);
271 err=GetLastError();
272 ok(len == 1,"Got wrong user agent length %d instead of %d\n",len,1);
273 ok(retval == 0,"Got wrong return value %d\n",retval);
274 ok(err == ERROR_INSUFFICIENT_BUFFER, "Got wrong error code%d\n",err);
276 len = sizeof(val);
277 val = 0xdeadbeef;
278 res = InternetQueryOptionA(hinet, INTERNET_OPTION_MAX_CONNS_PER_SERVER, &val, &len);
279 ok(!res, "InternetQueryOptionA(INTERNET_OPTION_MAX_CONNS_PER_SERVER) succeeded\n");
280 ok(GetLastError() == ERROR_INTERNET_INVALID_OPERATION, "GetLastError() = %u\n", GetLastError());
282 val = 2;
283 res = InternetSetOptionA(hinet, INTERNET_OPTION_MAX_CONNS_PER_SERVER, &val, sizeof(val));
284 ok(!res, "InternetSetOptionA(INTERNET_OPTION_MAX_CONNS_PER_SERVER) succeeded\n");
285 ok(GetLastError() == ERROR_INTERNET_INVALID_OPERATION, "GetLastError() = %u\n", GetLastError());
287 len = sizeof(val);
288 res = InternetQueryOptionA(hinet, INTERNET_OPTION_CONNECT_TIMEOUT, &val, &len);
289 ok(res, "InternetQueryOptionA failed %d)\n", GetLastError());
290 ok(val == 12345, "val = %d\n", val);
291 ok(len == sizeof(val), "len = %d\n", len);
293 val = 1;
294 res = InternetSetOptionA(hinet, INTERNET_OPTION_CONNECT_TIMEOUT, &val, sizeof(val));
295 ok(res, "InternetSetOptionA(INTERNET_OPTION_CONNECT_TIMEOUT) failed (%u)\n", GetLastError());
297 len = sizeof(val);
298 res = InternetQueryOptionA(hinet, INTERNET_OPTION_CONNECT_TIMEOUT, &val, &len);
299 ok(res, "InternetQueryOptionA failed %d)\n", GetLastError());
300 ok(val == 1, "val = %d\n", val);
301 ok(len == sizeof(val), "len = %d\n", len);
303 len = sizeof(val);
304 res = InternetQueryOptionA(NULL, INTERNET_OPTION_CONNECT_TIMEOUT, &val, &len);
305 ok(res, "InternetQueryOptionA failed %d)\n", GetLastError());
306 ok(val == 12345, "val = %d\n", val);
307 ok(len == sizeof(val), "len = %d\n", len);
309 InternetCloseHandle(hinet);
312 static void test_max_conns(void)
314 DWORD len, val;
315 BOOL res;
317 len = sizeof(val);
318 val = 0xdeadbeef;
319 res = InternetQueryOptionA(NULL, INTERNET_OPTION_MAX_CONNS_PER_SERVER, &val, &len);
320 ok(res,"Got wrong return value %x\n", res);
321 ok(len == sizeof(val), "got %d\n", len);
322 trace("INTERNET_OPTION_MAX_CONNS_PER_SERVER: %d\n", val);
324 len = sizeof(val);
325 val = 0xdeadbeef;
326 res = InternetQueryOptionA(NULL, INTERNET_OPTION_MAX_CONNS_PER_1_0_SERVER, &val, &len);
327 ok(res,"Got wrong return value %x\n", res);
328 ok(len == sizeof(val), "got %d\n", len);
329 trace("INTERNET_OPTION_MAX_CONNS_PER_1_0_SERVER: %d\n", val);
331 val = 3;
332 res = InternetSetOptionA(NULL, INTERNET_OPTION_MAX_CONNS_PER_SERVER, &val, sizeof(val));
333 ok(res, "InternetSetOptionA(INTERNET_OPTION_MAX_CONNS_PER_SERVER) failed: %x\n", res);
335 len = sizeof(val);
336 val = 0xdeadbeef;
337 res = InternetQueryOptionA(NULL, INTERNET_OPTION_MAX_CONNS_PER_SERVER, &val, &len);
338 ok(res,"Got wrong return value %x\n", res);
339 ok(len == sizeof(val), "got %d\n", len);
340 ok(val == 3, "got %d\n", val);
342 val = 0;
343 res = InternetSetOptionA(NULL, INTERNET_OPTION_MAX_CONNS_PER_SERVER, &val, sizeof(val));
344 ok(!res || broken(res), /* <= w2k3 */
345 "InternetSetOptionA(INTERNET_OPTION_MAX_CONNS_PER_SERVER, 0) succeeded\n");
346 if (!res) ok(GetLastError() == ERROR_BAD_ARGUMENTS, "GetLastError() = %u\n", GetLastError());
348 val = 2;
349 res = InternetSetOptionA(NULL, INTERNET_OPTION_MAX_CONNS_PER_SERVER, &val, sizeof(val)-1);
350 ok(!res, "InternetSetOptionA(INTERNET_OPTION_MAX_CONNS_PER_SERVER) succeeded\n");
351 ok(GetLastError() == ERROR_INTERNET_BAD_OPTION_LENGTH, "GetLastError() = %u\n", GetLastError());
353 val = 2;
354 res = InternetSetOptionA(NULL, INTERNET_OPTION_MAX_CONNS_PER_SERVER, &val, sizeof(val)+1);
355 ok(!res, "InternetSetOptionA(INTERNET_OPTION_MAX_CONNS_PER_SERVER) succeeded\n");
356 ok(GetLastError() == ERROR_INTERNET_BAD_OPTION_LENGTH, "GetLastError() = %u\n", GetLastError());
359 static void test_get_cookie(void)
361 DWORD len;
362 BOOL ret;
364 SetLastError(0xdeadbeef);
365 ret = InternetGetCookie("http://www.example.com", NULL, NULL, &len);
366 ok(!ret && GetLastError() == ERROR_NO_MORE_ITEMS,
367 "InternetGetCookie should have failed with %s and error %d\n",
368 ret ? "TRUE" : "FALSE", GetLastError());
372 static void test_complicated_cookie(void)
374 DWORD len;
375 BOOL ret;
377 CHAR buffer[1024];
378 CHAR user[256];
379 WCHAR wbuf[1024];
381 static const WCHAR testing_example_comW[] =
382 {'h','t','t','p',':','/','/','t','e','s','t','i','n','g','.','e','x','a','m','p','l','e','.','c','o','m',0};
384 ret = InternetSetCookie("http://www.example.com/bar",NULL,"A=B; domain=.example.com");
385 ok(ret == TRUE,"InternetSetCookie failed\n");
386 ret = InternetSetCookie("http://www.example.com/bar",NULL,"C=D; domain=.example.com; path=/");
387 ok(ret == TRUE,"InternetSetCookie failed\n");
389 /* Technically illegal! domain should require 2 dots, but native wininet accepts it */
390 ret = InternetSetCookie("http://www.example.com",NULL,"E=F; domain=example.com");
391 ok(ret == TRUE,"InternetSetCookie failed\n");
392 ret = InternetSetCookie("http://www.example.com",NULL,"G=H; domain=.example.com; path=/foo");
393 ok(ret == TRUE,"InternetSetCookie failed\n");
394 ret = InternetSetCookie("http://www.example.com/bar.html",NULL,"I=J; domain=.example.com");
395 ok(ret == TRUE,"InternetSetCookie failed\n");
396 ret = InternetSetCookie("http://www.example.com/bar/",NULL,"K=L; domain=.example.com");
397 ok(ret == TRUE,"InternetSetCookie failed\n");
398 ret = InternetSetCookie("http://www.example.com/bar/",NULL,"M=N; domain=.example.com; path=/foo/");
399 ok(ret == TRUE,"InternetSetCookie failed\n");
400 ret = InternetSetCookie("http://www.example.com/bar/",NULL,"O=P; secure; path=/bar");
401 ok(ret == TRUE,"InternetSetCookie failed\n");
403 len = 1024;
404 ret = InternetGetCookie("http://testing.example.com", NULL, NULL, &len);
405 ok(ret == TRUE,"InternetGetCookie failed\n");
406 ok(len == 19, "len = %u\n", len);
408 len = 1024;
409 memset(buffer, 0xac, sizeof(buffer));
410 ret = InternetGetCookie("http://testing.example.com", NULL, buffer, &len);
411 ok(ret == TRUE,"InternetGetCookie failed\n");
412 ok(len == 19, "len = %u\n", len);
413 ok(strlen(buffer) == 18, "strlen(buffer) = %u\n", lstrlenA(buffer));
414 ok(strstr(buffer,"A=B")!=NULL,"A=B missing\n");
415 ok(strstr(buffer,"C=D")!=NULL,"C=D missing\n");
416 ok(strstr(buffer,"E=F")!=NULL,"E=F missing\n");
417 ok(strstr(buffer,"G=H")==NULL,"G=H present\n");
418 ok(strstr(buffer,"I=J")!=NULL,"I=J missing\n");
419 ok(strstr(buffer,"K=L")==NULL,"K=L present\n");
420 ok(strstr(buffer,"M=N")==NULL,"M=N present\n");
421 ok(strstr(buffer,"O=P")==NULL,"O=P present\n");
423 len = 10;
424 memset(buffer, 0xac, sizeof(buffer));
425 ret = InternetGetCookie("http://testing.example.com", NULL, buffer, &len);
426 ok(!ret && GetLastError() == ERROR_INSUFFICIENT_BUFFER,
427 "InternetGetCookie returned: %x(%u), expected ERROR_INSUFFICIENT_BUFFER\n", ret, GetLastError());
428 ok(len == 19, "len = %u\n", len);
430 len = 1024;
431 ret = InternetGetCookieW(testing_example_comW, NULL, NULL, &len);
432 ok(ret == TRUE,"InternetGetCookieW failed\n");
433 ok(len == 38, "len = %u\n", len);
435 len = 1024;
436 memset(wbuf, 0xac, sizeof(wbuf));
437 ret = InternetGetCookieW(testing_example_comW, NULL, wbuf, &len);
438 ok(ret == TRUE,"InternetGetCookieW failed\n");
439 ok(len == 19 || broken(len==18), "len = %u\n", len);
440 ok(lstrlenW(wbuf) == 18, "strlenW(wbuf) = %u\n", lstrlenW(wbuf));
442 len = 10;
443 memset(wbuf, 0xac, sizeof(wbuf));
444 ret = InternetGetCookieW(testing_example_comW, NULL, wbuf, &len);
445 ok(!ret && GetLastError() == ERROR_INSUFFICIENT_BUFFER,
446 "InternetGetCookieW returned: %x(%u), expected ERROR_INSUFFICIENT_BUFFER\n", ret, GetLastError());
447 ok(len == 38, "len = %u\n", len);
449 len = 1024;
450 ret = InternetGetCookie("http://testing.example.com/foobar", NULL, buffer, &len);
451 ok(ret == TRUE,"InternetGetCookie failed\n");
452 ok(strstr(buffer,"A=B")!=NULL,"A=B missing\n");
453 ok(strstr(buffer,"C=D")!=NULL,"C=D missing\n");
454 ok(strstr(buffer,"E=F")!=NULL,"E=F missing\n");
455 ok(strstr(buffer,"G=H")==NULL,"G=H present\n");
456 ok(strstr(buffer,"I=J")!=NULL,"I=J missing\n");
457 ok(strstr(buffer,"K=L")==NULL,"K=L present\n");
458 ok(strstr(buffer,"M=N")==NULL,"M=N present\n");
459 ok(strstr(buffer,"O=P")==NULL,"O=P present\n");
461 len = 1024;
462 ret = InternetGetCookie("http://testing.example.com/foobar/", NULL, buffer, &len);
463 ok(ret == TRUE,"InternetGetCookie failed\n");
464 ok(strstr(buffer,"A=B")!=NULL,"A=B missing\n");
465 ok(strstr(buffer,"C=D")!=NULL,"C=D missing\n");
466 ok(strstr(buffer,"E=F")!=NULL,"E=F missing\n");
467 ok(strstr(buffer,"G=H")!=NULL,"G=H missing\n");
468 ok(strstr(buffer,"I=J")!=NULL,"I=J missing\n");
469 ok(strstr(buffer,"K=L")==NULL,"K=L present\n");
470 ok(strstr(buffer,"M=N")==NULL,"M=N present\n");
471 ok(strstr(buffer,"O=P")==NULL,"O=P present\n");
473 len = 1024;
474 ret = InternetGetCookie("http://testing.example.com/foo/bar", NULL, buffer, &len);
475 ok(ret == TRUE,"InternetGetCookie failed\n");
476 ok(strstr(buffer,"A=B")!=NULL,"A=B missing\n");
477 ok(strstr(buffer,"C=D")!=NULL,"C=D missing\n");
478 ok(strstr(buffer,"E=F")!=NULL,"E=F missing\n");
479 ok(strstr(buffer,"G=H")!=NULL,"G=H missing\n");
480 ok(strstr(buffer,"I=J")!=NULL,"I=J missing\n");
481 ok(strstr(buffer,"K=L")==NULL,"K=L present\n");
482 ok(strstr(buffer,"M=N")!=NULL,"M=N missing\n");
483 ok(strstr(buffer,"O=P")==NULL,"O=P present\n");
485 len = 1024;
486 ret = InternetGetCookie("http://testing.example.com/barfoo", NULL, buffer, &len);
487 ok(ret == TRUE,"InternetGetCookie failed\n");
488 ok(strstr(buffer,"A=B")!=NULL,"A=B missing\n");
489 ok(strstr(buffer,"C=D")!=NULL,"C=D missing\n");
490 ok(strstr(buffer,"E=F")!=NULL,"E=F missing\n");
491 ok(strstr(buffer,"G=H")==NULL,"G=H present\n");
492 ok(strstr(buffer,"I=J")!=NULL,"I=J missing\n");
493 ok(strstr(buffer,"K=L")==NULL,"K=L present\n");
494 ok(strstr(buffer,"M=N")==NULL,"M=N present\n");
495 ok(strstr(buffer,"O=P")==NULL,"O=P present\n");
497 len = 1024;
498 ret = InternetGetCookie("http://testing.example.com/barfoo/", NULL, buffer, &len);
499 ok(ret == TRUE,"InternetGetCookie failed\n");
500 ok(strstr(buffer,"A=B")!=NULL,"A=B missing\n");
501 ok(strstr(buffer,"C=D")!=NULL,"C=D missing\n");
502 ok(strstr(buffer,"E=F")!=NULL,"E=F missing\n");
503 ok(strstr(buffer,"G=H")==NULL,"G=H present\n");
504 ok(strstr(buffer,"I=J")!=NULL,"I=J missing\n");
505 ok(strstr(buffer,"K=L")==NULL,"K=L present\n");
506 ok(strstr(buffer,"M=N")==NULL,"M=N present\n");
507 ok(strstr(buffer,"O=P")==NULL,"O=P present\n");
509 len = 1024;
510 ret = InternetGetCookie("http://testing.example.com/bar/foo", NULL, buffer, &len);
511 ok(ret == TRUE,"InternetGetCookie failed\n");
512 ok(len == 24, "len = %u\n", 24);
513 ok(strstr(buffer,"A=B")!=NULL,"A=B missing\n");
514 ok(strstr(buffer,"C=D")!=NULL,"C=D missing\n");
515 ok(strstr(buffer,"E=F")!=NULL,"E=F missing\n");
516 ok(strstr(buffer,"G=H")==NULL,"G=H present\n");
517 ok(strstr(buffer,"I=J")!=NULL,"I=J missing\n");
518 ok(strstr(buffer,"K=L")!=NULL,"K=L missing\n");
519 ok(strstr(buffer,"M=N")==NULL,"M=N present\n");
520 ok(strstr(buffer,"O=P")==NULL,"O=P present\n");
522 /* Cookie name argument is not implemented */
523 len = 1024;
524 ret = InternetGetCookie("http://testing.example.com/bar/foo", "A", buffer, &len);
525 ok(ret == TRUE,"InternetGetCookie failed\n");
526 ok(len == 24, "len = %u\n", 24);
528 /* test persistent cookies */
529 ret = InternetSetCookie("http://testing.example.com", NULL, "A=B; expires=Fri, 01-Jan-2038 00:00:00 GMT");
530 ok(ret, "InternetSetCookie failed with error %d\n", GetLastError());
532 len = sizeof(user);
533 ret = GetUserName(user, &len);
534 ok(ret, "GetUserName failed with error %d\n", GetLastError());
535 for(; len>0; len--)
536 user[len-1] = tolower(user[len-1]);
538 sprintf(buffer, "Cookie:%s@testing.example.com/", user);
539 ret = GetUrlCacheEntryInfo(buffer, NULL, &len);
540 ok(!ret, "GetUrlCacheEntryInfo succeeded\n");
541 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER, "GetLastError() = %d\n", GetLastError());
543 /* remove persistent cookie */
544 ret = InternetSetCookie("http://testing.example.com", NULL, "A=B");
545 ok(ret, "InternetSetCookie failed with error %d\n", GetLastError());
547 ret = GetUrlCacheEntryInfo(buffer, NULL, &len);
548 ok(!ret, "GetUrlCacheEntryInfo succeeded\n");
549 ok(GetLastError() == ERROR_FILE_NOT_FOUND, "GetLastError() = %d\n", GetLastError());
551 /* try setting cookie for different domain */
552 ret = InternetSetCookie("http://www.aaa.example.com/bar",NULL,"E=F; domain=different.com");
553 ok(!ret, "InternetSetCookie succeeded\n");
554 ok(GetLastError() == ERROR_INVALID_PARAMETER, "GetLastError() = %d\n", GetLastError());
555 ret = InternetSetCookie("http://www.aaa.example.com.pl/bar",NULL,"E=F; domain=example.com.pl");
556 ok(ret, "InternetSetCookie failed with error: %d\n", GetLastError());
557 ret = InternetSetCookie("http://www.aaa.example.com.pl/bar",NULL,"E=F; domain=com.pl");
558 todo_wine ok(!ret, "InternetSetCookie succeeded\n");
561 static void test_cookie_url(void)
563 WCHAR bufw[512];
564 char buf[512];
565 DWORD len;
566 BOOL res;
568 static const WCHAR about_blankW[] = {'a','b','o','u','t',':','b','l','a','n','k',0};
570 len = sizeof(buf);
571 res = InternetGetCookieA("about:blank", NULL, buf, &len);
572 ok(!res && GetLastError() == ERROR_INVALID_PARAMETER,
573 "InternetGetCookeA failed: %u, expected ERROR_INVALID_PARAMETER\n", GetLastError());
575 len = sizeof(bufw)/sizeof(*bufw);
576 res = InternetGetCookieW(about_blankW, NULL, bufw, &len);
577 ok(!res && GetLastError() == ERROR_INVALID_PARAMETER,
578 "InternetGetCookeW failed: %u, expected ERROR_INVALID_PARAMETER\n", GetLastError());
580 len = sizeof(buf);
581 res = pInternetGetCookieExA("about:blank", NULL, buf, &len, 0, NULL);
582 ok(!res && GetLastError() == ERROR_INVALID_PARAMETER,
583 "InternetGetCookeExA failed: %u, expected ERROR_INVALID_PARAMETER\n", GetLastError());
585 len = sizeof(bufw)/sizeof(*bufw);
586 res = pInternetGetCookieExW(about_blankW, NULL, bufw, &len, 0, NULL);
587 ok(!res && GetLastError() == ERROR_INVALID_PARAMETER,
588 "InternetGetCookeExW failed: %u, expected ERROR_INVALID_PARAMETER\n", GetLastError());
591 static void test_null(void)
593 HINTERNET hi, hc;
594 static const WCHAR szServer[] = { 's','e','r','v','e','r',0 };
595 static const WCHAR szEmpty[] = { 0 };
596 static const WCHAR szUrl[] = { 'h','t','t','p',':','/','/','a','.','b','.','c',0 };
597 static const WCHAR szUrlEmpty[] = { 'h','t','t','p',':','/','/',0 };
598 static const WCHAR szExpect[] = { 's','e','r','v','e','r',';',' ','s','e','r','v','e','r',0 };
599 WCHAR buffer[0x20];
600 BOOL r;
601 DWORD sz;
603 SetLastError(0xdeadbeef);
604 hi = InternetOpenW(NULL, 0, NULL, NULL, 0);
605 if (hi == NULL && GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)
607 win_skip("Internet*W functions are not implemented\n");
608 return;
610 ok(hi != NULL, "open failed\n");
612 hc = InternetConnectW(hi, NULL, 0, NULL, NULL, 0, 0, 0);
613 ok(GetLastError() == ERROR_INVALID_PARAMETER, "wrong error\n");
614 ok(hc == NULL, "connect failed\n");
616 hc = InternetConnectW(hi, NULL, 0, NULL, NULL, INTERNET_SERVICE_HTTP, 0, 0);
617 ok(GetLastError() == ERROR_INVALID_PARAMETER, "wrong error\n");
618 ok(hc == NULL, "connect failed\n");
620 hc = InternetConnectW(hi, NULL, 0, NULL, NULL, INTERNET_SERVICE_FTP, 0, 0);
621 ok(GetLastError() == ERROR_INVALID_PARAMETER, "wrong error\n");
622 ok(hc == NULL, "connect failed\n");
624 hc = InternetConnectW(NULL, szServer, 0, NULL, NULL, INTERNET_SERVICE_FTP, 0, 0);
625 ok(GetLastError() == ERROR_INVALID_HANDLE, "wrong error\n");
626 ok(hc == NULL, "connect failed\n");
628 hc = InternetOpenUrlW(hi, NULL, NULL, 0, 0, 0);
629 ok(GetLastError() == ERROR_INVALID_PARAMETER ||
630 GetLastError() == ERROR_INTERNET_UNRECOGNIZED_SCHEME, "wrong error\n");
631 ok(hc == NULL, "connect failed\n");
633 hc = InternetOpenUrlW(hi, szServer, NULL, 0, 0, 0);
634 ok(GetLastError() == ERROR_INTERNET_UNRECOGNIZED_SCHEME, "wrong error\n");
635 ok(hc == NULL, "connect failed\n");
637 InternetCloseHandle(hi);
639 r = InternetSetCookieW(NULL, NULL, NULL);
640 ok(GetLastError() == ERROR_INVALID_PARAMETER, "wrong error\n");
641 ok(r == FALSE, "return wrong\n");
643 r = InternetSetCookieW(szServer, NULL, NULL);
644 ok(GetLastError() == ERROR_INVALID_PARAMETER, "wrong error\n");
645 ok(r == FALSE, "return wrong\n");
647 r = InternetSetCookieW(szUrl, szServer, NULL);
648 ok(GetLastError() == ERROR_INVALID_PARAMETER, "wrong error\n");
649 ok(r == FALSE, "return wrong\n");
651 r = InternetSetCookieW(szUrl, szServer, szServer);
652 ok(r == TRUE, "return wrong\n");
654 r = InternetSetCookieW(szUrl, NULL, szServer);
655 ok(r == TRUE, "return wrong\n");
657 r = InternetSetCookieW(szUrl, szServer, szEmpty);
658 ok(r == TRUE, "return wrong\n");
660 r = InternetSetCookieW(szUrlEmpty, szServer, szServer);
661 ok(r == FALSE, "return wrong\n");
663 r = InternetSetCookieW(szServer, NULL, szServer);
664 ok(GetLastError() == ERROR_INTERNET_UNRECOGNIZED_SCHEME, "wrong error\n");
665 ok(r == FALSE, "return wrong\n");
667 sz = 0;
668 r = InternetGetCookieW(NULL, NULL, NULL, &sz);
669 ok(GetLastError() == ERROR_INVALID_PARAMETER || GetLastError() == ERROR_INTERNET_UNRECOGNIZED_SCHEME,
670 "wrong error %u\n", GetLastError());
671 ok( r == FALSE, "return wrong\n");
673 r = InternetGetCookieW(szServer, NULL, NULL, &sz);
674 todo_wine {
675 ok(GetLastError() == ERROR_INTERNET_UNRECOGNIZED_SCHEME, "wrong error\n");
677 ok( r == FALSE, "return wrong\n");
679 sz = 0;
680 r = InternetGetCookieW(szUrlEmpty, szServer, NULL, &sz);
681 ok( r == FALSE, "return wrong\n");
683 sz = 0;
684 r = InternetGetCookieW(szUrl, szServer, NULL, &sz);
685 ok( r == TRUE, "return wrong\n");
687 /* sz is 14 on XP SP2 and beyond, 30 on XP SP1 and before */
688 ok( sz == 14 || sz == 30, "sz wrong, got %u, expected 14 or 30\n", sz);
690 sz = 0x20;
691 memset(buffer, 0, sizeof buffer);
692 r = InternetGetCookieW(szUrl, szServer, buffer, &sz);
693 ok( r == TRUE, "return wrong\n");
695 /* sz == lstrlenW(buffer) only in XP SP1 */
696 ok( sz == 1 + lstrlenW(buffer) || sz == lstrlenW(buffer), "sz wrong %d\n", sz);
698 /* before XP SP2, buffer is "server; server" */
699 ok( !lstrcmpW(szExpect, buffer) || !lstrcmpW(szServer, buffer), "cookie data wrong\n");
701 sz = sizeof(buffer);
702 r = InternetQueryOptionA(NULL, INTERNET_OPTION_CONNECTED_STATE, buffer, &sz);
703 ok(r == TRUE, "ret %d\n", r);
706 static void test_version(void)
708 INTERNET_VERSION_INFO version;
709 DWORD size;
710 BOOL res;
712 size = sizeof(version);
713 res = InternetQueryOptionA(NULL, INTERNET_OPTION_VERSION, &version, &size);
714 ok(res, "Could not get version: %u\n", GetLastError());
715 ok(version.dwMajorVersion == 1, "dwMajorVersion=%d, expected 1\n", version.dwMajorVersion);
716 ok(version.dwMinorVersion == 2, "dwMinorVersion=%d, expected 2\n", version.dwMinorVersion);
719 static void InternetTimeFromSystemTimeA_test(void)
721 BOOL ret;
722 static const SYSTEMTIME time = { 2005, 1, 5, 7, 12, 6, 35, 0 };
723 char string[INTERNET_RFC1123_BUFSIZE];
724 static const char expect[] = "Fri, 07 Jan 2005 12:06:35 GMT";
725 DWORD error;
727 ret = pInternetTimeFromSystemTimeA( &time, INTERNET_RFC1123_FORMAT, string, sizeof(string) );
728 ok( ret, "InternetTimeFromSystemTimeA failed (%u)\n", GetLastError() );
730 ok( !memcmp( string, expect, sizeof(expect) ),
731 "InternetTimeFromSystemTimeA failed (%u)\n", GetLastError() );
733 /* test NULL time parameter */
734 SetLastError(0xdeadbeef);
735 ret = pInternetTimeFromSystemTimeA( NULL, INTERNET_RFC1123_FORMAT, string, sizeof(string) );
736 error = GetLastError();
737 ok( !ret, "InternetTimeFromSystemTimeA should have returned FALSE\n" );
738 ok( error == ERROR_INVALID_PARAMETER,
739 "InternetTimeFromSystemTimeA failed with ERROR_INVALID_PARAMETER instead of %u\n",
740 error );
742 /* test NULL string parameter */
743 SetLastError(0xdeadbeef);
744 ret = pInternetTimeFromSystemTimeA( &time, INTERNET_RFC1123_FORMAT, NULL, sizeof(string) );
745 error = GetLastError();
746 ok( !ret, "InternetTimeFromSystemTimeA should have returned FALSE\n" );
747 ok( error == ERROR_INVALID_PARAMETER,
748 "InternetTimeFromSystemTimeA failed with ERROR_INVALID_PARAMETER instead of %u\n",
749 error );
751 /* test invalid format parameter */
752 SetLastError(0xdeadbeef);
753 ret = pInternetTimeFromSystemTimeA( &time, INTERNET_RFC1123_FORMAT + 1, string, sizeof(string) );
754 error = GetLastError();
755 ok( !ret, "InternetTimeFromSystemTimeA should have returned FALSE\n" );
756 ok( error == ERROR_INVALID_PARAMETER,
757 "InternetTimeFromSystemTimeA failed with ERROR_INVALID_PARAMETER instead of %u\n",
758 error );
760 /* test too small buffer size */
761 SetLastError(0xdeadbeef);
762 ret = pInternetTimeFromSystemTimeA( &time, INTERNET_RFC1123_FORMAT, string, 0 );
763 error = GetLastError();
764 ok( !ret, "InternetTimeFromSystemTimeA should have returned FALSE\n" );
765 ok( error == ERROR_INSUFFICIENT_BUFFER,
766 "InternetTimeFromSystemTimeA failed with ERROR_INSUFFICIENT_BUFFER instead of %u\n",
767 error );
770 static void InternetTimeFromSystemTimeW_test(void)
772 BOOL ret;
773 static const SYSTEMTIME time = { 2005, 1, 5, 7, 12, 6, 35, 0 };
774 WCHAR string[INTERNET_RFC1123_BUFSIZE + 1];
775 static const WCHAR expect[] = { 'F','r','i',',',' ','0','7',' ','J','a','n',' ','2','0','0','5',' ',
776 '1','2',':','0','6',':','3','5',' ','G','M','T',0 };
777 DWORD error;
779 ret = pInternetTimeFromSystemTimeW( &time, INTERNET_RFC1123_FORMAT, string, sizeof(string) );
780 ok( ret, "InternetTimeFromSystemTimeW failed (%u)\n", GetLastError() );
782 ok( !memcmp( string, expect, sizeof(expect) ),
783 "InternetTimeFromSystemTimeW failed (%u)\n", GetLastError() );
785 /* test NULL time parameter */
786 SetLastError(0xdeadbeef);
787 ret = pInternetTimeFromSystemTimeW( NULL, INTERNET_RFC1123_FORMAT, string, sizeof(string) );
788 error = GetLastError();
789 ok( !ret, "InternetTimeFromSystemTimeW should have returned FALSE\n" );
790 ok( error == ERROR_INVALID_PARAMETER,
791 "InternetTimeFromSystemTimeW failed with ERROR_INVALID_PARAMETER instead of %u\n",
792 error );
794 /* test NULL string parameter */
795 SetLastError(0xdeadbeef);
796 ret = pInternetTimeFromSystemTimeW( &time, INTERNET_RFC1123_FORMAT, NULL, sizeof(string) );
797 error = GetLastError();
798 ok( !ret, "InternetTimeFromSystemTimeW should have returned FALSE\n" );
799 ok( error == ERROR_INVALID_PARAMETER,
800 "InternetTimeFromSystemTimeW failed with ERROR_INVALID_PARAMETER instead of %u\n",
801 error );
803 /* test invalid format parameter */
804 SetLastError(0xdeadbeef);
805 ret = pInternetTimeFromSystemTimeW( &time, INTERNET_RFC1123_FORMAT + 1, string, sizeof(string) );
806 error = GetLastError();
807 ok( !ret, "InternetTimeFromSystemTimeW should have returned FALSE\n" );
808 ok( error == ERROR_INVALID_PARAMETER,
809 "InternetTimeFromSystemTimeW failed with ERROR_INVALID_PARAMETER instead of %u\n",
810 error );
812 /* test too small buffer size */
813 SetLastError(0xdeadbeef);
814 ret = pInternetTimeFromSystemTimeW( &time, INTERNET_RFC1123_FORMAT, string, sizeof(string)/sizeof(string[0]) );
815 error = GetLastError();
816 ok( !ret, "InternetTimeFromSystemTimeW should have returned FALSE\n" );
817 ok( error == ERROR_INSUFFICIENT_BUFFER,
818 "InternetTimeFromSystemTimeW failed with ERROR_INSUFFICIENT_BUFFER instead of %u\n",
819 error );
822 static void InternetTimeToSystemTimeA_test(void)
824 BOOL ret;
825 SYSTEMTIME time;
826 static const SYSTEMTIME expect = { 2005, 1, 5, 7, 12, 6, 35, 0 };
827 static const char string[] = "Fri, 07 Jan 2005 12:06:35 GMT";
828 static const char string2[] = " fri 7 jan 2005 12 06 35";
830 ret = pInternetTimeToSystemTimeA( string, &time, 0 );
831 ok( ret, "InternetTimeToSystemTimeA failed (%u)\n", GetLastError() );
832 ok( !memcmp( &time, &expect, sizeof(expect) ),
833 "InternetTimeToSystemTimeA failed (%u)\n", GetLastError() );
835 ret = pInternetTimeToSystemTimeA( string2, &time, 0 );
836 ok( ret, "InternetTimeToSystemTimeA failed (%u)\n", GetLastError() );
837 ok( !memcmp( &time, &expect, sizeof(expect) ),
838 "InternetTimeToSystemTimeA failed (%u)\n", GetLastError() );
841 static void InternetTimeToSystemTimeW_test(void)
843 BOOL ret;
844 SYSTEMTIME time;
845 static const SYSTEMTIME expect = { 2005, 1, 5, 7, 12, 6, 35, 0 };
846 static const WCHAR string[] = { 'F','r','i',',',' ','0','7',' ','J','a','n',' ','2','0','0','5',' ',
847 '1','2',':','0','6',':','3','5',' ','G','M','T',0 };
848 static const WCHAR string2[] = { ' ','f','r','i',' ','7',' ','j','a','n',' ','2','0','0','5',' ',
849 '1','2',' ','0','6',' ','3','5',0 };
850 static const WCHAR string3[] = { 'F','r',0 };
852 ret = pInternetTimeToSystemTimeW( NULL, NULL, 0 );
853 ok( !ret, "InternetTimeToSystemTimeW succeeded (%u)\n", GetLastError() );
855 ret = pInternetTimeToSystemTimeW( NULL, &time, 0 );
856 ok( !ret, "InternetTimeToSystemTimeW succeeded (%u)\n", GetLastError() );
858 ret = pInternetTimeToSystemTimeW( string, NULL, 0 );
859 ok( !ret, "InternetTimeToSystemTimeW succeeded (%u)\n", GetLastError() );
861 ret = pInternetTimeToSystemTimeW( string, &time, 0 );
862 ok( ret, "InternetTimeToSystemTimeW failed (%u)\n", GetLastError() );
864 ret = pInternetTimeToSystemTimeW( string, &time, 0 );
865 ok( ret, "InternetTimeToSystemTimeW failed (%u)\n", GetLastError() );
866 ok( !memcmp( &time, &expect, sizeof(expect) ),
867 "InternetTimeToSystemTimeW failed (%u)\n", GetLastError() );
869 ret = pInternetTimeToSystemTimeW( string2, &time, 0 );
870 ok( ret, "InternetTimeToSystemTimeW failed (%u)\n", GetLastError() );
871 ok( !memcmp( &time, &expect, sizeof(expect) ),
872 "InternetTimeToSystemTimeW failed (%u)\n", GetLastError() );
874 ret = pInternetTimeToSystemTimeW( string3, &time, 0 );
875 ok( ret, "InternetTimeToSystemTimeW failed (%u)\n", GetLastError() );
878 static void test_IsDomainLegalCookieDomainW(void)
880 BOOL ret;
881 static const WCHAR empty[] = {0};
882 static const WCHAR dot[] = {'.',0};
883 static const WCHAR uk[] = {'u','k',0};
884 static const WCHAR com[] = {'c','o','m',0};
885 static const WCHAR dot_com[] = {'.','c','o','m',0};
886 static const WCHAR gmail_com[] = {'g','m','a','i','l','.','c','o','m',0};
887 static const WCHAR dot_gmail_com[] = {'.','g','m','a','i','l','.','c','o','m',0};
888 static const WCHAR www_gmail_com[] = {'w','w','w','.','g','m','a','i','l','.','c','o','m',0};
889 static const WCHAR www_mail_gmail_com[] = {'w','w','w','.','m','a','i','l','.','g','m','a','i','l','.','c','o','m',0};
890 static const WCHAR mail_gmail_com[] = {'m','a','i','l','.','g','m','a','i','l','.','c','o','m',0};
891 static const WCHAR gmail_co_uk[] = {'g','m','a','i','l','.','c','o','.','u','k',0};
892 static const WCHAR co_uk[] = {'c','o','.','u','k',0};
893 static const WCHAR dot_co_uk[] = {'.','c','o','.','u','k',0};
895 SetLastError(0xdeadbeef);
896 ret = pIsDomainLegalCookieDomainW(NULL, NULL);
897 if (!ret && (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED))
899 win_skip("IsDomainLegalCookieDomainW is not implemented\n");
900 return;
902 ok(!ret ||
903 broken(ret), /* IE6 */
904 "IsDomainLegalCookieDomainW succeeded\n");
906 SetLastError(0xdeadbeef);
907 ret = pIsDomainLegalCookieDomainW(com, NULL);
908 ok(!ret, "IsDomainLegalCookieDomainW succeeded\n");
910 SetLastError(0xdeadbeef);
911 ret = pIsDomainLegalCookieDomainW(NULL, gmail_com);
912 ok(!ret, "IsDomainLegalCookieDomainW succeeded\n");
914 SetLastError(0xdeadbeef);
915 ret = pIsDomainLegalCookieDomainW(empty, gmail_com);
916 ok(!ret, "IsDomainLegalCookieDomainW succeeded\n");
918 SetLastError(0xdeadbeef);
919 ret = pIsDomainLegalCookieDomainW(com, empty);
920 ok(!ret, "IsDomainLegalCookieDomainW succeeded\n");
922 SetLastError(0xdeadbeef);
923 ret = pIsDomainLegalCookieDomainW(gmail_com, dot);
924 ok(!ret, "IsDomainLegalCookieDomainW succeeded\n");
926 SetLastError(0xdeadbeef);
927 ret = pIsDomainLegalCookieDomainW(dot, gmail_com);
928 ok(!ret, "IsDomainLegalCookieDomainW succeeded\n");
930 SetLastError(0xdeadbeef);
931 ret = pIsDomainLegalCookieDomainW(com, com);
932 ok(!ret, "IsDomainLegalCookieDomainW succeeded\n");
934 SetLastError(0xdeadbeef);
935 ret = pIsDomainLegalCookieDomainW(com, dot_com);
936 ok(!ret, "IsDomainLegalCookieDomainW succeeded\n");
938 SetLastError(0xdeadbeef);
939 ret = pIsDomainLegalCookieDomainW(dot_com, com);
940 ok(!ret, "IsDomainLegalCookieDomainW succeeded\n");
942 SetLastError(0xdeadbeef);
943 ret = pIsDomainLegalCookieDomainW(com, gmail_com);
944 ok(!ret, "IsDomainLegalCookieDomainW succeeded\n");
946 ret = pIsDomainLegalCookieDomainW(gmail_com, gmail_com);
947 ok(ret, "IsDomainLegalCookieDomainW failed\n");
949 ret = pIsDomainLegalCookieDomainW(gmail_com, www_gmail_com);
950 ok(ret, "IsDomainLegalCookieDomainW failed\n");
952 ret = pIsDomainLegalCookieDomainW(gmail_com, www_mail_gmail_com);
953 ok(ret, "IsDomainLegalCookieDomainW failed\n");
955 SetLastError(0xdeadbeef);
956 ret = pIsDomainLegalCookieDomainW(gmail_co_uk, co_uk);
957 ok(!ret, "IsDomainLegalCookieDomainW succeeded\n");
959 ret = pIsDomainLegalCookieDomainW(uk, co_uk);
960 ok(!ret, "IsDomainLegalCookieDomainW succeeded\n");
962 ret = pIsDomainLegalCookieDomainW(gmail_co_uk, dot_co_uk);
963 ok(!ret, "IsDomainLegalCookieDomainW succeeded\n");
965 ret = pIsDomainLegalCookieDomainW(co_uk, gmail_co_uk);
966 todo_wine ok(!ret, "IsDomainLegalCookieDomainW succeeded\n");
968 ret = pIsDomainLegalCookieDomainW(gmail_co_uk, gmail_co_uk);
969 ok(ret, "IsDomainLegalCookieDomainW failed\n");
971 ret = pIsDomainLegalCookieDomainW(gmail_com, com);
972 ok(!ret, "IsDomainLegalCookieDomainW succeeded\n");
974 SetLastError(0xdeadbeef);
975 ret = pIsDomainLegalCookieDomainW(dot_gmail_com, mail_gmail_com);
976 ok(!ret, "IsDomainLegalCookieDomainW succeeded\n");
978 ret = pIsDomainLegalCookieDomainW(gmail_com, mail_gmail_com);
979 ok(ret, "IsDomainLegalCookieDomainW failed\n");
981 ret = pIsDomainLegalCookieDomainW(mail_gmail_com, gmail_com);
982 ok(!ret, "IsDomainLegalCookieDomainW succeeded\n");
984 ret = pIsDomainLegalCookieDomainW(mail_gmail_com, com);
985 ok(!ret, "IsDomainLegalCookieDomainW succeeded\n");
987 ret = pIsDomainLegalCookieDomainW(dot_gmail_com, mail_gmail_com);
988 ok(!ret, "IsDomainLegalCookieDomainW succeeded\n");
990 ret = pIsDomainLegalCookieDomainW(mail_gmail_com, dot_gmail_com);
991 ok(!ret, "IsDomainLegalCookieDomainW succeeded\n");
994 static void test_PrivacyGetSetZonePreferenceW(void)
996 DWORD ret, zone, type, template, old_template;
998 zone = 3;
999 type = 0;
1000 ret = pPrivacyGetZonePreferenceW(zone, type, NULL, NULL, NULL);
1001 ok(ret == 0, "expected ret == 0, got %u\n", ret);
1003 old_template = 0;
1004 ret = pPrivacyGetZonePreferenceW(zone, type, &old_template, NULL, NULL);
1005 ok(ret == 0, "expected ret == 0, got %u\n", ret);
1007 template = 5;
1008 ret = pPrivacySetZonePreferenceW(zone, type, template, NULL);
1009 ok(ret == 0, "expected ret == 0, got %u\n", ret);
1011 template = 0;
1012 ret = pPrivacyGetZonePreferenceW(zone, type, &template, NULL, NULL);
1013 ok(ret == 0, "expected ret == 0, got %u\n", ret);
1014 ok(template == 5, "expected template == 5, got %u\n", template);
1016 template = 5;
1017 ret = pPrivacySetZonePreferenceW(zone, type, old_template, NULL);
1018 ok(ret == 0, "expected ret == 0, got %u\n", ret);
1021 static void test_InternetSetOption(void)
1023 HINTERNET ses, con, req;
1024 ULONG ulArg;
1025 DWORD size;
1026 BOOL ret;
1028 ses = InternetOpen(NULL, INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, 0);
1029 ok(ses != 0, "InternetOpen failed: 0x%08x\n", GetLastError());
1030 con = InternetConnect(ses, "www.winehq.org", 80, NULL, NULL, INTERNET_SERVICE_HTTP, 0, 0);
1031 ok(con != 0, "InternetConnect failed: 0x%08x\n", GetLastError());
1032 req = HttpOpenRequest(con, "GET", "/", NULL, NULL, NULL, 0, 0);
1033 ok(req != 0, "HttpOpenRequest failed: 0x%08x\n", GetLastError());
1035 /* INTERNET_OPTION_POLICY tests */
1036 SetLastError(0xdeadbeef);
1037 ret = InternetSetOptionW(ses, INTERNET_OPTION_POLICY, NULL, 0);
1038 ok(ret == FALSE, "InternetSetOption should've failed\n");
1039 ok(GetLastError() == ERROR_INVALID_PARAMETER, "GetLastError should've "
1040 "given ERROR_INVALID_PARAMETER, gave: 0x%08x\n", GetLastError());
1042 SetLastError(0xdeadbeef);
1043 ret = InternetQueryOptionW(ses, INTERNET_OPTION_POLICY, NULL, 0);
1044 ok(ret == FALSE, "InternetQueryOption should've failed\n");
1045 ok(GetLastError() == ERROR_INVALID_PARAMETER, "GetLastError should've "
1046 "given ERROR_INVALID_PARAMETER, gave: 0x%08x\n", GetLastError());
1048 /* INTERNET_OPTION_ERROR_MASK tests */
1049 SetLastError(0xdeadbeef);
1050 size = sizeof(ulArg);
1051 ret = InternetQueryOptionW(NULL, INTERNET_OPTION_ERROR_MASK, (void*)&ulArg, &size);
1052 ok(ret == FALSE, "InternetQueryOption should've failed\n");
1053 ok(GetLastError() == ERROR_INTERNET_INCORRECT_HANDLE_TYPE, "GetLastError() = %x\n", GetLastError());
1055 SetLastError(0xdeadbeef);
1056 ulArg = 11;
1057 ret = InternetSetOption(NULL, INTERNET_OPTION_ERROR_MASK, (void*)&ulArg, sizeof(ULONG));
1058 ok(ret == FALSE, "InternetQueryOption should've failed\n");
1059 ok(GetLastError() == ERROR_INTERNET_INCORRECT_HANDLE_TYPE, "GetLastError() = %x\n", GetLastError());
1061 SetLastError(0xdeadbeef);
1062 ulArg = 11;
1063 ret = InternetSetOption(req, INTERNET_OPTION_ERROR_MASK, (void*)&ulArg, 20);
1064 ok(ret == FALSE, "InternetQueryOption should've failed\n");
1065 ok(GetLastError() == ERROR_INTERNET_BAD_OPTION_LENGTH, "GetLastError() = %d\n", GetLastError());
1067 SetLastError(0xdeadbeef);
1068 ulArg = 11;
1069 ret = InternetSetOption(req, INTERNET_OPTION_ERROR_MASK, (void*)&ulArg, sizeof(ULONG));
1070 ok(ret == TRUE, "InternetQueryOption should've succeeded\n");
1071 ok(GetLastError() == 0xdeadbeef, "GetLastError() = %d\n", GetLastError());
1073 SetLastError(0xdeadbeef);
1074 ulArg = 4;
1075 ret = InternetSetOption(req, INTERNET_OPTION_ERROR_MASK, (void*)&ulArg, sizeof(ULONG));
1076 ok(ret == FALSE, "InternetQueryOption should've failed\n");
1077 ok(GetLastError() == ERROR_INVALID_PARAMETER, "GetLastError() = %x\n", GetLastError());
1079 SetLastError(0xdeadbeef);
1080 ulArg = 16;
1081 ret = InternetSetOption(req, INTERNET_OPTION_ERROR_MASK, (void*)&ulArg, sizeof(ULONG));
1082 ok(ret == FALSE, "InternetQueryOption should've failed\n");
1083 ok(GetLastError() == ERROR_INVALID_PARAMETER, "GetLastError() = %x\n", GetLastError());
1085 ret = InternetCloseHandle(req);
1086 ok(ret == TRUE, "InternetCloseHandle failed: 0x%08x\n", GetLastError());
1087 ret = InternetCloseHandle(con);
1088 ok(ret == TRUE, "InternetCloseHandle failed: 0x%08x\n", GetLastError());
1089 ret = InternetCloseHandle(ses);
1090 ok(ret == TRUE, "InternetCloseHandle failed: 0x%08x\n", GetLastError());
1093 #define verifyProxyEnable(e) r_verifyProxyEnable(__LINE__, e)
1094 static void r_verifyProxyEnable(LONG l, DWORD exp)
1096 HKEY hkey;
1097 DWORD type, val, size = sizeof(DWORD);
1098 LONG ret;
1099 static const CHAR szInternetSettings[] = "Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings";
1100 static const CHAR szProxyEnable[] = "ProxyEnable";
1102 ret = RegOpenKeyA(HKEY_CURRENT_USER, szInternetSettings, &hkey);
1103 ok_(__FILE__,l) (!ret, "RegOpenKeyA failed: 0x%08x\n", ret);
1105 ret = RegQueryValueExA(hkey, szProxyEnable, 0, &type, (BYTE*)&val, &size);
1106 ok_(__FILE__,l) (!ret, "RegQueryValueExA failed: 0x%08x\n", ret);
1107 ok_(__FILE__,l) (type == REG_DWORD, "Expected regtype to be REG_DWORD, was: %d\n", type);
1108 ok_(__FILE__,l) (val == exp, "Expected ProxyEnabled to be %d, got: %d\n", exp, val);
1110 ret = RegCloseKey(hkey);
1111 ok_(__FILE__,l) (!ret, "RegCloseKey failed: 0x%08x\n", ret);
1114 static void test_Option_PerConnectionOption(void)
1116 BOOL ret;
1117 DWORD size = sizeof(INTERNET_PER_CONN_OPTION_LISTW);
1118 INTERNET_PER_CONN_OPTION_LISTW list = {size};
1119 INTERNET_PER_CONN_OPTIONW *orig_settings;
1120 static WCHAR proxy_srvW[] = {'p','r','o','x','y','.','e','x','a','m','p','l','e',0};
1122 /* get the global IE proxy server info, to restore later */
1123 list.dwOptionCount = 2;
1124 list.pOptions = HeapAlloc(GetProcessHeap(), 0, 2 * sizeof(INTERNET_PER_CONN_OPTIONW));
1126 list.pOptions[0].dwOption = INTERNET_PER_CONN_PROXY_SERVER;
1127 list.pOptions[1].dwOption = INTERNET_PER_CONN_FLAGS;
1129 ret = InternetQueryOptionW(NULL, INTERNET_OPTION_PER_CONNECTION_OPTION,
1130 &list, &size);
1131 ok(ret == TRUE, "InternetQueryOption should've succeeded\n");
1132 orig_settings = list.pOptions;
1134 /* set the global IE proxy server */
1135 list.dwOptionCount = 2;
1136 list.pOptions = HeapAlloc(GetProcessHeap(), 0, 2 * sizeof(INTERNET_PER_CONN_OPTIONW));
1138 list.pOptions[0].dwOption = INTERNET_PER_CONN_PROXY_SERVER;
1139 list.pOptions[0].Value.pszValue = proxy_srvW;
1140 list.pOptions[1].dwOption = INTERNET_PER_CONN_FLAGS;
1141 list.pOptions[1].Value.dwValue = PROXY_TYPE_PROXY;
1143 ret = InternetSetOptionW(NULL, INTERNET_OPTION_PER_CONNECTION_OPTION,
1144 &list, size);
1145 ok(ret == TRUE, "InternetSetOption should've succeeded\n");
1147 HeapFree(GetProcessHeap(), 0, list.pOptions);
1149 /* get & verify the global IE proxy server */
1150 list.dwOptionCount = 2;
1151 list.dwOptionError = 0;
1152 list.pOptions = HeapAlloc(GetProcessHeap(), 0, 2 * sizeof(INTERNET_PER_CONN_OPTIONW));
1154 list.pOptions[0].dwOption = INTERNET_PER_CONN_PROXY_SERVER;
1155 list.pOptions[1].dwOption = INTERNET_PER_CONN_FLAGS;
1157 ret = InternetQueryOptionW(NULL, INTERNET_OPTION_PER_CONNECTION_OPTION,
1158 &list, &size);
1159 ok(ret == TRUE, "InternetQueryOption should've succeeded\n");
1160 ok(!lstrcmpW(list.pOptions[0].Value.pszValue, proxy_srvW),
1161 "Retrieved proxy server should've been %s, was: %s\n",
1162 wine_dbgstr_w(proxy_srvW), wine_dbgstr_w(list.pOptions[0].Value.pszValue));
1163 ok(list.pOptions[1].Value.dwValue == PROXY_TYPE_PROXY,
1164 "Retrieved flags should've been PROXY_TYPE_PROXY, was: %d\n",
1165 list.pOptions[1].Value.dwValue);
1166 verifyProxyEnable(1);
1168 HeapFree(GetProcessHeap(), 0, list.pOptions[0].Value.pszValue);
1169 HeapFree(GetProcessHeap(), 0, list.pOptions);
1171 /* disable the proxy server */
1172 list.dwOptionCount = 1;
1173 list.pOptions = HeapAlloc(GetProcessHeap(), 0, sizeof(INTERNET_PER_CONN_OPTIONW));
1175 list.pOptions[0].dwOption = INTERNET_PER_CONN_FLAGS;
1176 list.pOptions[0].Value.dwValue = PROXY_TYPE_DIRECT;
1178 ret = InternetSetOptionW(NULL, INTERNET_OPTION_PER_CONNECTION_OPTION,
1179 &list, size);
1180 ok(ret == TRUE, "InternetSetOption should've succeeded\n");
1182 HeapFree(GetProcessHeap(), 0, list.pOptions);
1184 /* verify that the proxy is disabled */
1185 list.dwOptionCount = 1;
1186 list.dwOptionError = 0;
1187 list.pOptions = HeapAlloc(GetProcessHeap(), 0, sizeof(INTERNET_PER_CONN_OPTIONW));
1189 list.pOptions[0].dwOption = INTERNET_PER_CONN_FLAGS;
1191 ret = InternetQueryOptionW(NULL, INTERNET_OPTION_PER_CONNECTION_OPTION,
1192 &list, &size);
1193 ok(ret == TRUE, "InternetQueryOption should've succeeded\n");
1194 ok(list.pOptions[0].Value.dwValue == PROXY_TYPE_DIRECT,
1195 "Retrieved flags should've been PROXY_TYPE_DIRECT, was: %d\n",
1196 list.pOptions[0].Value.dwValue);
1197 verifyProxyEnable(0);
1199 HeapFree(GetProcessHeap(), 0, list.pOptions);
1201 /* set the proxy flags to 'invalid' value */
1202 list.dwOptionCount = 1;
1203 list.pOptions = HeapAlloc(GetProcessHeap(), 0, sizeof(INTERNET_PER_CONN_OPTIONW));
1205 list.pOptions[0].dwOption = INTERNET_PER_CONN_FLAGS;
1206 list.pOptions[0].Value.dwValue = PROXY_TYPE_PROXY | PROXY_TYPE_DIRECT;
1208 ret = InternetSetOptionW(NULL, INTERNET_OPTION_PER_CONNECTION_OPTION,
1209 &list, size);
1210 ok(ret == TRUE, "InternetSetOption should've succeeded\n");
1212 HeapFree(GetProcessHeap(), 0, list.pOptions);
1214 /* verify that the proxy is enabled */
1215 list.dwOptionCount = 1;
1216 list.dwOptionError = 0;
1217 list.pOptions = HeapAlloc(GetProcessHeap(), 0, sizeof(INTERNET_PER_CONN_OPTIONW));
1219 list.pOptions[0].dwOption = INTERNET_PER_CONN_FLAGS;
1221 ret = InternetQueryOptionW(NULL, INTERNET_OPTION_PER_CONNECTION_OPTION,
1222 &list, &size);
1223 ok(ret == TRUE, "InternetQueryOption should've succeeded\n");
1224 todo_wine ok(list.pOptions[0].Value.dwValue == (PROXY_TYPE_PROXY | PROXY_TYPE_DIRECT),
1225 "Retrieved flags should've been PROXY_TYPE_PROXY | PROXY_TYPE_DIRECT, was: %d\n",
1226 list.pOptions[0].Value.dwValue);
1227 verifyProxyEnable(1);
1229 HeapFree(GetProcessHeap(), 0, list.pOptions);
1231 /* restore original settings */
1232 list.dwOptionCount = 2;
1233 list.pOptions = orig_settings;
1235 ret = InternetSetOptionW(NULL, INTERNET_OPTION_PER_CONNECTION_OPTION,
1236 &list, size);
1237 ok(ret == TRUE, "InternetSetOption should've succeeded\n");
1239 HeapFree(GetProcessHeap(), 0, list.pOptions);
1242 static void test_Option_PerConnectionOptionA(void)
1244 BOOL ret;
1245 DWORD size = sizeof(INTERNET_PER_CONN_OPTION_LISTA);
1246 INTERNET_PER_CONN_OPTION_LISTA list = {size};
1247 INTERNET_PER_CONN_OPTIONA *orig_settings;
1248 char proxy_srv[] = "proxy.example";
1250 /* get the global IE proxy server info, to restore later */
1251 list.dwOptionCount = 2;
1252 list.pOptions = HeapAlloc(GetProcessHeap(), 0, 2 * sizeof(INTERNET_PER_CONN_OPTIONA));
1254 list.pOptions[0].dwOption = INTERNET_PER_CONN_PROXY_SERVER;
1255 list.pOptions[1].dwOption = INTERNET_PER_CONN_FLAGS;
1257 ret = InternetQueryOptionA(NULL, INTERNET_OPTION_PER_CONNECTION_OPTION,
1258 &list, &size);
1259 ok(ret == TRUE, "InternetQueryOption should've succeeded\n");
1260 orig_settings = list.pOptions;
1262 /* set the global IE proxy server */
1263 list.dwOptionCount = 2;
1264 list.pOptions = HeapAlloc(GetProcessHeap(), 0, 2 * sizeof(INTERNET_PER_CONN_OPTIONA));
1266 list.pOptions[0].dwOption = INTERNET_PER_CONN_PROXY_SERVER;
1267 list.pOptions[0].Value.pszValue = proxy_srv;
1268 list.pOptions[1].dwOption = INTERNET_PER_CONN_FLAGS;
1269 list.pOptions[1].Value.dwValue = PROXY_TYPE_PROXY;
1271 ret = InternetSetOptionA(NULL, INTERNET_OPTION_PER_CONNECTION_OPTION,
1272 &list, size);
1273 ok(ret == TRUE, "InternetSetOption should've succeeded\n");
1275 HeapFree(GetProcessHeap(), 0, list.pOptions);
1277 /* get & verify the global IE proxy server */
1278 list.dwOptionCount = 2;
1279 list.dwOptionError = 0;
1280 list.pOptions = HeapAlloc(GetProcessHeap(), 0, 2 * sizeof(INTERNET_PER_CONN_OPTIONA));
1282 list.pOptions[0].dwOption = INTERNET_PER_CONN_PROXY_SERVER;
1283 list.pOptions[1].dwOption = INTERNET_PER_CONN_FLAGS;
1285 ret = InternetQueryOptionA(NULL, INTERNET_OPTION_PER_CONNECTION_OPTION,
1286 &list, &size);
1287 ok(ret == TRUE, "InternetQueryOption should've succeeded\n");
1288 ok(!lstrcmpA(list.pOptions[0].Value.pszValue, "proxy.example"),
1289 "Retrieved proxy server should've been \"%s\", was: \"%s\"\n",
1290 proxy_srv, list.pOptions[0].Value.pszValue);
1291 ok(list.pOptions[1].Value.dwValue == PROXY_TYPE_PROXY,
1292 "Retrieved flags should've been PROXY_TYPE_PROXY, was: %d\n",
1293 list.pOptions[1].Value.dwValue);
1295 HeapFree(GetProcessHeap(), 0, list.pOptions[0].Value.pszValue);
1296 HeapFree(GetProcessHeap(), 0, list.pOptions);
1298 /* restore original settings */
1299 list.dwOptionCount = 2;
1300 list.pOptions = orig_settings;
1302 ret = InternetSetOptionA(NULL, INTERNET_OPTION_PER_CONNECTION_OPTION,
1303 &list, size);
1304 ok(ret == TRUE, "InternetSetOption should've succeeded\n");
1306 HeapFree(GetProcessHeap(), 0, list.pOptions);
1309 #define FLAG_TODO 0x1
1310 #define FLAG_NEEDREQ 0x2
1311 #define FLAG_UNIMPL 0x4
1313 static void test_InternetErrorDlg(void)
1315 HINTERNET ses, con, req;
1316 DWORD res, flags;
1317 HWND hwnd;
1318 ULONG i;
1319 static const struct {
1320 DWORD error;
1321 DWORD res;
1322 DWORD test_flags;
1323 } no_ui_res[] = {
1324 { ERROR_INTERNET_INCORRECT_PASSWORD , ERROR_SUCCESS, FLAG_NEEDREQ },
1325 { ERROR_INTERNET_SEC_CERT_DATE_INVALID , ERROR_CANCELLED, 0 },
1326 { ERROR_INTERNET_SEC_CERT_CN_INVALID , ERROR_CANCELLED, 0 },
1327 { ERROR_INTERNET_HTTP_TO_HTTPS_ON_REDIR , ERROR_SUCCESS, 0 },
1328 { ERROR_INTERNET_HTTPS_TO_HTTP_ON_REDIR , ERROR_SUCCESS, FLAG_TODO },
1329 { ERROR_INTERNET_MIXED_SECURITY , ERROR_CANCELLED, FLAG_TODO },
1330 { ERROR_INTERNET_CHG_POST_IS_NON_SECURE , ERROR_CANCELLED, FLAG_TODO },
1331 { ERROR_INTERNET_POST_IS_NON_SECURE , ERROR_SUCCESS, 0 },
1332 { ERROR_INTERNET_CLIENT_AUTH_CERT_NEEDED, ERROR_CANCELLED, FLAG_NEEDREQ|FLAG_TODO },
1333 { ERROR_INTERNET_INVALID_CA , ERROR_CANCELLED, 0 },
1334 { ERROR_INTERNET_HTTPS_HTTP_SUBMIT_REDIR, ERROR_CANCELLED, FLAG_TODO },
1335 { ERROR_INTERNET_INSERT_CDROM , ERROR_CANCELLED, FLAG_TODO|FLAG_NEEDREQ|FLAG_UNIMPL },
1336 { ERROR_INTERNET_SEC_CERT_ERRORS , ERROR_CANCELLED, 0 },
1337 { ERROR_INTERNET_SEC_CERT_REV_FAILED , ERROR_CANCELLED, 0 },
1338 { ERROR_HTTP_COOKIE_NEEDS_CONFIRMATION , ERROR_HTTP_COOKIE_DECLINED, FLAG_TODO },
1339 { ERROR_INTERNET_BAD_AUTO_PROXY_SCRIPT , ERROR_CANCELLED, FLAG_TODO },
1340 { ERROR_INTERNET_UNABLE_TO_DOWNLOAD_SCRIPT, ERROR_CANCELLED, FLAG_TODO },
1341 { ERROR_HTTP_REDIRECT_NEEDS_CONFIRMATION, ERROR_CANCELLED, FLAG_TODO },
1342 { ERROR_INTERNET_SEC_CERT_REVOKED , ERROR_CANCELLED, 0 },
1343 { 0, ERROR_NOT_SUPPORTED }
1346 flags = 0;
1348 res = InternetErrorDlg(NULL, NULL, 12055, flags, NULL);
1349 ok(res == ERROR_INVALID_HANDLE, "Got %d\n", res);
1351 ses = InternetOpen(NULL, INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, 0);
1352 ok(ses != 0, "InternetOpen failed: 0x%08x\n", GetLastError());
1353 con = InternetConnect(ses, "www.winehq.org", 80, NULL, NULL, INTERNET_SERVICE_HTTP, 0, 0);
1354 ok(con != 0, "InternetConnect failed: 0x%08x\n", GetLastError());
1355 req = HttpOpenRequest(con, "GET", "/", NULL, NULL, NULL, 0, 0);
1356 ok(req != 0, "HttpOpenRequest failed: 0x%08x\n", GetLastError());
1358 /* NULL hwnd and FLAGS_ERROR_UI_FLAGS_NO_UI not set */
1359 for(i = INTERNET_ERROR_BASE; i < INTERNET_ERROR_LAST; i++)
1361 res = InternetErrorDlg(NULL, req, i, flags, NULL);
1362 ok(res == ERROR_INVALID_HANDLE, "Got %d (%d)\n", res, i);
1365 hwnd = GetDesktopWindow();
1366 ok(hwnd != NULL, "GetDesktopWindow failed (%d)\n", GetLastError());
1368 flags = FLAGS_ERROR_UI_FLAGS_NO_UI;
1369 for(i = INTERNET_ERROR_BASE; i < INTERNET_ERROR_LAST; i++)
1371 DWORD expected, test_flags, j;
1373 for(j = 0; no_ui_res[j].error != 0; ++j)
1374 if(no_ui_res[j].error == i)
1375 break;
1377 test_flags = no_ui_res[j].test_flags;
1378 expected = no_ui_res[j].res;
1380 /* Try an invalid request handle */
1381 res = InternetErrorDlg(hwnd, (HANDLE)0xdeadbeef, i, flags, NULL);
1382 if(res == ERROR_CALL_NOT_IMPLEMENTED)
1384 ok(test_flags & FLAG_UNIMPL, "%i is unexpectedly unimplemented.\n", i);
1385 continue;
1387 else
1388 ok(res == ERROR_INVALID_HANDLE, "Got %d (%d)\n", res, i);
1390 /* With a valid req */
1391 if(i == ERROR_INTERNET_NEED_UI)
1392 continue; /* Crashes on windows XP */
1394 if(i == ERROR_INTERNET_SEC_CERT_REVOKED)
1395 continue; /* Interactive (XP, Win7) */
1397 res = InternetErrorDlg(hwnd, req, i, flags, NULL);
1399 /* Handle some special cases */
1400 switch(i)
1402 case ERROR_INTERNET_HTTP_TO_HTTPS_ON_REDIR:
1403 case ERROR_INTERNET_HTTPS_TO_HTTP_ON_REDIR:
1404 if(res == ERROR_CANCELLED)
1406 /* Some windows XP, w2k3 x64, W2K8 */
1407 win_skip("Skipping some tests for %d\n", i);
1408 continue;
1410 break;
1411 case ERROR_INTERNET_FORTEZZA_LOGIN_NEEDED:
1412 if(res != expected)
1414 /* Windows XP, W2K3 */
1415 ok(res == NTE_PROV_TYPE_NOT_DEF, "Got %d\n", res);
1416 win_skip("Skipping some tests for %d\n", i);
1417 continue;
1419 break;
1420 default: break;
1423 if(test_flags & FLAG_TODO)
1424 todo_wine ok(res == expected, "Got %d, expected %d (%d)\n", res, expected, i);
1425 else
1426 ok(res == expected, "Got %d, expected %d (%d)\n", res, expected, i);
1428 /* Same thing with NULL hwnd */
1429 res = InternetErrorDlg(NULL, req, i, flags, NULL);
1430 if(test_flags & FLAG_TODO)
1431 todo_wine ok(res == expected, "Got %d, expected %d (%d)\n", res, expected, i);
1432 else
1433 ok(res == expected, "Got %d, expected %d (%d)\n", res, expected, i);
1436 /* With a null req */
1437 if(test_flags & FLAG_NEEDREQ)
1438 expected = ERROR_INVALID_PARAMETER;
1440 res = InternetErrorDlg(hwnd, NULL, i, flags, NULL);
1441 if( test_flags & FLAG_TODO || i == ERROR_INTERNET_INCORRECT_PASSWORD)
1442 todo_wine ok(res == expected, "Got %d, expected %d (%d)\n", res, expected, i);
1443 else
1444 ok(res == expected, "Got %d, expected %d (%d)\n", res, expected, i);
1447 res = InternetCloseHandle(req);
1448 ok(res == TRUE, "InternetCloseHandle failed: 0x%08x\n", GetLastError());
1449 res = InternetCloseHandle(con);
1450 ok(res == TRUE, "InternetCloseHandle failed: 0x%08x\n", GetLastError());
1451 res = InternetCloseHandle(ses);
1452 ok(res == TRUE, "InternetCloseHandle failed: 0x%08x\n", GetLastError());
1455 /* ############################### */
1457 START_TEST(internet)
1459 HMODULE hdll;
1460 hdll = GetModuleHandleA("wininet.dll");
1462 pCreateUrlCacheContainerA = (void*)GetProcAddress(hdll, "CreateUrlCacheContainerA");
1463 pCreateUrlCacheContainerW = (void*)GetProcAddress(hdll, "CreateUrlCacheContainerW");
1464 pInternetTimeFromSystemTimeA = (void*)GetProcAddress(hdll, "InternetTimeFromSystemTimeA");
1465 pInternetTimeFromSystemTimeW = (void*)GetProcAddress(hdll, "InternetTimeFromSystemTimeW");
1466 pInternetTimeToSystemTimeA = (void*)GetProcAddress(hdll, "InternetTimeToSystemTimeA");
1467 pInternetTimeToSystemTimeW = (void*)GetProcAddress(hdll, "InternetTimeToSystemTimeW");
1468 pIsDomainLegalCookieDomainW = (void*)GetProcAddress(hdll, (LPCSTR)117);
1469 pPrivacyGetZonePreferenceW = (void*)GetProcAddress(hdll, "PrivacyGetZonePreferenceW");
1470 pPrivacySetZonePreferenceW = (void*)GetProcAddress(hdll, "PrivacySetZonePreferenceW");
1471 pInternetGetCookieExA = (void*)GetProcAddress(hdll, "InternetGetCookieExA");
1472 pInternetGetCookieExW = (void*)GetProcAddress(hdll, "InternetGetCookieExW");
1474 if(!pInternetGetCookieExW) {
1475 win_skip("Too old IE (older than 6.0)\n");
1476 return;
1479 test_InternetCanonicalizeUrlA();
1480 test_InternetQueryOptionA();
1481 test_get_cookie();
1482 test_complicated_cookie();
1483 test_cookie_url();
1484 test_version();
1485 test_null();
1486 test_Option_PerConnectionOption();
1487 test_Option_PerConnectionOptionA();
1488 test_InternetErrorDlg();
1489 test_max_conns();
1491 if (!pInternetTimeFromSystemTimeA)
1492 win_skip("skipping the InternetTime tests\n");
1493 else
1495 InternetTimeFromSystemTimeA_test();
1496 InternetTimeFromSystemTimeW_test();
1497 InternetTimeToSystemTimeA_test();
1498 InternetTimeToSystemTimeW_test();
1500 if (pIsDomainLegalCookieDomainW &&
1501 ((void*)pIsDomainLegalCookieDomainW == (void*)pCreateUrlCacheContainerA ||
1502 (void*)pIsDomainLegalCookieDomainW == (void*)pCreateUrlCacheContainerW))
1503 win_skip("IsDomainLegalCookieDomainW is not available on systems with IE5\n");
1504 else if (!pIsDomainLegalCookieDomainW)
1505 win_skip("IsDomainLegalCookieDomainW (or ordinal 117) is not available\n");
1506 else
1507 test_IsDomainLegalCookieDomainW();
1509 if (pPrivacyGetZonePreferenceW && pPrivacySetZonePreferenceW)
1510 test_PrivacyGetSetZonePreferenceW();
1511 else
1512 win_skip("Privacy[SG]etZonePreferenceW are not available\n");
1514 test_InternetSetOption();