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
30 #include "wine/test.h"
32 static BOOL (WINAPI *pCreateUrlCacheContainerA)(DWORD, DWORD, DWORD, DWORD,
33 DWORD, DWORD, DWORD, DWORD);
34 static BOOL (WINAPI *pCreateUrlCacheContainerW)(DWORD, DWORD, DWORD, DWORD,
35 DWORD, DWORD, DWORD, DWORD);
36 static BOOL (WINAPI *pInternetTimeFromSystemTimeA)(CONST SYSTEMTIME *,DWORD ,LPSTR ,DWORD);
37 static BOOL (WINAPI *pInternetTimeFromSystemTimeW)(CONST SYSTEMTIME *,DWORD ,LPWSTR ,DWORD);
38 static BOOL (WINAPI *pInternetTimeToSystemTimeA)(LPCSTR ,SYSTEMTIME *,DWORD);
39 static BOOL (WINAPI *pInternetTimeToSystemTimeW)(LPCWSTR ,SYSTEMTIME *,DWORD);
40 static BOOL (WINAPI *pIsDomainLegalCookieDomainW)(LPCWSTR, LPCWSTR);
41 static DWORD (WINAPI *pPrivacyGetZonePreferenceW)(DWORD, DWORD, LPDWORD, LPWSTR, LPDWORD);
42 static DWORD (WINAPI *pPrivacySetZonePreferenceW)(DWORD, DWORD, DWORD, LPCWSTR);
44 /* ############################### */
46 static void test_InternetCanonicalizeUrlA(void)
54 /* Acrobat Updater 5 calls this for Adobe Reader 8.1 */
55 url = "http://swupmf.adobe.com/manifest/50/win/AdobeUpdater.upd";
56 urllen = lstrlenA(url);
58 memset(buffer, '#', sizeof(buffer)-1);
59 buffer[sizeof(buffer)-1] = '\0';
60 dwSize = 1; /* Acrobat Updater use this size */
61 SetLastError(0xdeadbeef);
62 res = InternetCanonicalizeUrlA(url, buffer, &dwSize, 0);
63 ok( !res && (GetLastError() == ERROR_INSUFFICIENT_BUFFER) && (dwSize == (urllen+1)),
64 "got %u and %u with size %u for '%s' (%d)\n",
65 res, GetLastError(), dwSize, buffer, lstrlenA(buffer));
68 /* buffer has no space for the terminating '\0' */
69 memset(buffer, '#', sizeof(buffer)-1);
70 buffer[sizeof(buffer)-1] = '\0';
72 SetLastError(0xdeadbeef);
73 res = InternetCanonicalizeUrlA(url, buffer, &dwSize, 0);
74 /* dwSize is nr. of needed bytes with the terminating '\0' */
75 ok( !res && (GetLastError() == ERROR_INSUFFICIENT_BUFFER) && (dwSize == (urllen+1)),
76 "got %u and %u with size %u for '%s' (%d)\n",
77 res, GetLastError(), dwSize, buffer, lstrlenA(buffer));
79 /* buffer has the required size */
80 memset(buffer, '#', sizeof(buffer)-1);
81 buffer[sizeof(buffer)-1] = '\0';
83 SetLastError(0xdeadbeef);
84 res = InternetCanonicalizeUrlA(url, buffer, &dwSize, 0);
85 /* dwSize is nr. of copied bytes without the terminating '\0' */
86 ok( res && (dwSize == urllen) && (lstrcmpA(url, buffer) == 0),
87 "got %u and %u with size %u for '%s' (%d)\n",
88 res, GetLastError(), dwSize, buffer, lstrlenA(buffer));
90 memset(buffer, '#', sizeof(buffer)-1);
91 buffer[sizeof(buffer)-1] = '\0';
92 dwSize = sizeof(buffer);
93 SetLastError(0xdeadbeef);
94 res = InternetCanonicalizeUrlA("file:///C:/Program%20Files/Atmel/AVR%20Tools/STK500/STK500.xml", buffer, &dwSize, ICU_DECODE | ICU_NO_ENCODE);
95 ok(res, "InternetCanonicalizeUrlA failed %u\n", GetLastError());
96 ok(dwSize == lstrlenA(buffer), "got %d expected %d\n", dwSize, lstrlenA(buffer));
97 ok(!lstrcmpA("file://C:\\Program Files\\Atmel\\AVR Tools\\STK500\\STK500.xml", buffer),
98 "got %s expected 'file://C:\\Program Files\\Atmel\\AVR Tools\\STK500\\STK500.xml'\n", buffer);
100 /* buffer is larger as the required size */
101 memset(buffer, '#', sizeof(buffer)-1);
102 buffer[sizeof(buffer)-1] = '\0';
104 SetLastError(0xdeadbeef);
105 res = InternetCanonicalizeUrlA(url, buffer, &dwSize, 0);
106 /* dwSize is nr. of copied bytes without the terminating '\0' */
107 ok( res && (dwSize == urllen) && (lstrcmpA(url, buffer) == 0),
108 "got %u and %u with size %u for '%s' (%d)\n",
109 res, GetLastError(), dwSize, buffer, lstrlenA(buffer));
112 /* check NULL pointers */
113 memset(buffer, '#', urllen + 4);
114 buffer[urllen + 4] = '\0';
116 SetLastError(0xdeadbeef);
117 res = InternetCanonicalizeUrlA(NULL, buffer, &dwSize, 0);
118 ok( !res && (GetLastError() == ERROR_INVALID_PARAMETER),
119 "got %u and %u with size %u for '%s' (%d)\n",
120 res, GetLastError(), dwSize, buffer, lstrlenA(buffer));
122 memset(buffer, '#', urllen + 4);
123 buffer[urllen + 4] = '\0';
125 SetLastError(0xdeadbeef);
126 res = InternetCanonicalizeUrlA(url, NULL, &dwSize, 0);
127 ok( !res && (GetLastError() == ERROR_INVALID_PARAMETER),
128 "got %u and %u with size %u for '%s' (%d)\n",
129 res, GetLastError(), dwSize, buffer, lstrlenA(buffer));
131 memset(buffer, '#', urllen + 4);
132 buffer[urllen + 4] = '\0';
134 SetLastError(0xdeadbeef);
135 res = InternetCanonicalizeUrlA(url, buffer, NULL, 0);
136 ok( !res && (GetLastError() == ERROR_INVALID_PARAMETER),
137 "got %u and %u with size %u for '%s' (%d)\n",
138 res, GetLastError(), dwSize, buffer, lstrlenA(buffer));
140 /* test with trailing space */
142 res = InternetCanonicalizeUrlA("http://www.winehq.org/index.php?x= ", buffer, &dwSize, ICU_BROWSER_MODE);
143 ok(res == 1, "InternetCanonicalizeUrlA failed\n");
144 ok(!strcmp(buffer, "http://www.winehq.org/index.php?x="), "Trailing space should have been stripped even in ICU_BROWSER_MODE (%s)\n", buffer);
146 res = InternetSetOptionA(NULL, 0xdeadbeef, buffer, sizeof(buffer));
147 ok(!res, "InternetSetOptionA succeeded\n");
148 ok(GetLastError() == ERROR_INTERNET_INVALID_OPTION,
149 "InternetSetOptionA failed %u, expected ERROR_INTERNET_INVALID_OPTION\n", GetLastError());
152 /* ############################### */
154 static void test_InternetQueryOptionA(void)
156 HINTERNET hinet,hurl;
159 static const char useragent[] = {"Wininet Test"};
164 hinet = InternetOpenA(useragent,INTERNET_OPEN_TYPE_DIRECT,NULL,NULL, 0);
165 ok((hinet != 0x0),"InternetOpen Failed\n");
167 SetLastError(0xdeadbeef);
168 retval=InternetQueryOptionA(NULL,INTERNET_OPTION_USER_AGENT,NULL,&len);
170 ok(retval == 0,"Got wrong return value %d\n",retval);
171 ok(err == ERROR_INTERNET_INCORRECT_HANDLE_TYPE, "Got wrong error code%d\n",err);
173 SetLastError(0xdeadbeef);
174 len=strlen(useragent)+1;
175 retval=InternetQueryOptionA(hinet,INTERNET_OPTION_USER_AGENT,NULL,&len);
177 ok(len == strlen(useragent)+1,"Got wrong user agent length %d instead of %d\n",len,lstrlenA(useragent));
178 ok(retval == 0,"Got wrong return value %d\n",retval);
179 ok(err == ERROR_INSUFFICIENT_BUFFER, "Got wrong error code %d\n",err);
181 SetLastError(0xdeadbeef);
182 len=strlen(useragent)+1;
183 buffer=HeapAlloc(GetProcessHeap(),0,len);
184 retval=InternetQueryOptionA(hinet,INTERNET_OPTION_USER_AGENT,buffer,&len);
186 ok(retval == 1,"Got wrong return value %d\n",retval);
189 ok(!strcmp(useragent,buffer),"Got wrong user agent string %s instead of %s\n",buffer,useragent);
190 ok(len == strlen(useragent),"Got wrong user agent length %d instead of %d\n",len,lstrlenA(useragent));
192 ok(err == 0xdeadbeef, "Got wrong error code %d\n",err);
193 HeapFree(GetProcessHeap(),0,buffer);
195 SetLastError(0xdeadbeef);
197 buffer=HeapAlloc(GetProcessHeap(),0,100);
198 retval=InternetQueryOptionA(hinet,INTERNET_OPTION_USER_AGENT,buffer,&len);
200 ok(len == strlen(useragent) + 1,"Got wrong user agent length %d instead of %d\n", len, lstrlenA(useragent) + 1);
201 ok(!retval, "Got wrong return value %d\n", retval);
202 ok(err == ERROR_INSUFFICIENT_BUFFER, "Got wrong error code %d\n", err);
203 HeapFree(GetProcessHeap(),0,buffer);
205 hurl = InternetConnectA(hinet,"www.winehq.org",INTERNET_DEFAULT_HTTP_PORT,NULL,NULL,INTERNET_SERVICE_HTTP,0,0);
207 SetLastError(0xdeadbeef);
209 retval = InternetQueryOptionA(hurl,INTERNET_OPTION_USER_AGENT,NULL,&len);
211 ok(len == 0,"Got wrong user agent length %d instead of 0\n",len);
212 ok(retval == 0,"Got wrong return value %d\n",retval);
213 ok(err == ERROR_INTERNET_INCORRECT_HANDLE_TYPE, "Got wrong error code %d\n",err);
215 InternetCloseHandle(hurl);
216 InternetCloseHandle(hinet);
218 hinet = InternetOpenA("",INTERNET_OPEN_TYPE_DIRECT,NULL,NULL, 0);
219 ok((hinet != 0x0),"InternetOpen Failed\n");
221 SetLastError(0xdeadbeef);
223 retval=InternetQueryOptionA(hinet,INTERNET_OPTION_USER_AGENT,NULL,&len);
225 ok(len == 1,"Got wrong user agent length %d instead of %d\n",len,1);
226 ok(retval == 0,"Got wrong return value %d\n",retval);
227 ok(err == ERROR_INSUFFICIENT_BUFFER, "Got wrong error code%d\n",err);
229 InternetCloseHandle(hinet);
231 hinet = InternetOpenA(NULL,INTERNET_OPEN_TYPE_DIRECT,NULL,NULL, 0);
232 ok((hinet != 0x0),"InternetOpen Failed\n");
233 SetLastError(0xdeadbeef);
235 retval=InternetQueryOptionA(hinet,INTERNET_OPTION_USER_AGENT,NULL,&len);
237 ok(len == 1,"Got wrong user agent length %d instead of %d\n",len,1);
238 ok(retval == 0,"Got wrong return value %d\n",retval);
239 ok(err == ERROR_INSUFFICIENT_BUFFER, "Got wrong error code%d\n",err);
243 res = InternetQueryOptionA(hinet, INTERNET_OPTION_MAX_CONNS_PER_SERVER, &val, &len);
244 ok(!res, "InternetQueryOptionA(INTERNET_OPTION_MAX_CONNS_PER_SERVER) succeeded\n");
245 ok(GetLastError() == ERROR_INTERNET_INVALID_OPERATION, "GetLastError() = %u\n", GetLastError());
248 res = InternetSetOptionA(hinet, INTERNET_OPTION_MAX_CONNS_PER_SERVER, &val, sizeof(val));
249 ok(!res, "InternetSetOptionA(INTERNET_OPTION_MAX_CONNS_PER_SERVER) succeeded\n");
250 ok(GetLastError() == ERROR_INTERNET_INVALID_OPERATION, "GetLastError() = %u\n", GetLastError());
252 InternetCloseHandle(hinet);
255 static void test_max_conns(void)
262 res = InternetQueryOptionA(NULL, INTERNET_OPTION_MAX_CONNS_PER_SERVER, &val, &len);
263 ok(res,"Got wrong return value %x\n", res);
264 ok(len == sizeof(val), "got %d\n", len);
265 ok(val == 2, "got %d\n", val);
269 res = InternetQueryOptionA(NULL, INTERNET_OPTION_MAX_CONNS_PER_1_0_SERVER, &val, &len);
270 ok(res,"Got wrong return value %x\n", res);
271 ok(len == sizeof(val), "got %d\n", len);
272 ok(val == 4, "got %d\n", val);
275 res = InternetSetOptionA(NULL, INTERNET_OPTION_MAX_CONNS_PER_SERVER, &val, sizeof(val));
276 ok(res, "InternetSetOptionA(INTERNET_OPTION_MAX_CONNS_PER_SERVER) failed: %x\n", res);
280 res = InternetQueryOptionA(NULL, INTERNET_OPTION_MAX_CONNS_PER_SERVER, &val, &len);
281 ok(res,"Got wrong return value %x\n", res);
282 ok(len == sizeof(val), "got %d\n", len);
283 ok(val == 3, "got %d\n", val);
286 res = InternetSetOptionA(NULL, INTERNET_OPTION_MAX_CONNS_PER_SERVER, &val, sizeof(val));
287 ok(!res, "InternetSetOptionA(INTERNET_OPTION_MAX_CONNS_PER_SERVER, 0) succeeded\n");
288 ok(GetLastError() == ERROR_BAD_ARGUMENTS, "GetLastError() = %u\n", GetLastError());
291 res = InternetSetOptionA(NULL, INTERNET_OPTION_MAX_CONNS_PER_SERVER, &val, sizeof(val)-1);
292 ok(!res, "InternetSetOptionA(INTERNET_OPTION_MAX_CONNS_PER_SERVER) succeeded\n");
293 ok(GetLastError() == ERROR_INTERNET_BAD_OPTION_LENGTH, "GetLastError() = %u\n", GetLastError());
296 res = InternetSetOptionA(NULL, INTERNET_OPTION_MAX_CONNS_PER_SERVER, &val, sizeof(val)+1);
297 ok(!res, "InternetSetOptionA(INTERNET_OPTION_MAX_CONNS_PER_SERVER) succeeded\n");
298 ok(GetLastError() == ERROR_INTERNET_BAD_OPTION_LENGTH, "GetLastError() = %u\n", GetLastError());
301 static void test_get_cookie(void)
306 SetLastError(0xdeadbeef);
307 ret = InternetGetCookie("http://www.example.com", NULL, NULL, &len);
308 ok(!ret && GetLastError() == ERROR_NO_MORE_ITEMS,
309 "InternetGetCookie should have failed with %s and error %d\n",
310 ret ? "TRUE" : "FALSE", GetLastError());
314 static void test_complicated_cookie(void)
321 ret = InternetSetCookie("http://www.example.com/bar",NULL,"A=B; domain=.example.com");
322 ok(ret == TRUE,"InternetSetCookie failed\n");
323 ret = InternetSetCookie("http://www.example.com/bar",NULL,"C=D; domain=.example.com; path=/");
324 ok(ret == TRUE,"InternetSetCookie failed\n");
326 /* Technically illegal! domain should require 2 dots, but native wininet accepts it */
327 ret = InternetSetCookie("http://www.example.com",NULL,"E=F; domain=example.com");
328 ok(ret == TRUE,"InternetSetCookie failed\n");
329 ret = InternetSetCookie("http://www.example.com",NULL,"G=H; domain=.example.com; path=/foo");
330 ok(ret == TRUE,"InternetSetCookie failed\n");
331 ret = InternetSetCookie("http://www.example.com/bar.html",NULL,"I=J; domain=.example.com");
332 ok(ret == TRUE,"InternetSetCookie failed\n");
333 ret = InternetSetCookie("http://www.example.com/bar/",NULL,"K=L; domain=.example.com");
334 ok(ret == TRUE,"InternetSetCookie failed\n");
335 ret = InternetSetCookie("http://www.example.com/bar/",NULL,"M=N; domain=.example.com; path=/foo/");
336 ok(ret == TRUE,"InternetSetCookie failed\n");
337 ret = InternetSetCookie("http://www.example.com/bar/",NULL,"O=P; secure; path=/bar");
338 ok(ret == TRUE,"InternetSetCookie failed\n");
341 ret = InternetGetCookie("http://testing.example.com", NULL, buffer, &len);
342 ok(ret == TRUE,"InternetGetCookie failed\n");
343 ok(strstr(buffer,"A=B")!=NULL,"A=B missing\n");
344 ok(strstr(buffer,"C=D")!=NULL,"C=D missing\n");
345 ok(strstr(buffer,"E=F")!=NULL,"E=F missing\n");
346 ok(strstr(buffer,"G=H")==NULL,"G=H present\n");
347 ok(strstr(buffer,"I=J")!=NULL,"I=J missing\n");
348 ok(strstr(buffer,"K=L")==NULL,"K=L present\n");
349 ok(strstr(buffer,"M=N")==NULL,"M=N present\n");
350 ok(strstr(buffer,"O=P")==NULL,"O=P present\n");
353 ret = InternetGetCookie("http://testing.example.com/foobar", NULL, buffer, &len);
354 ok(ret == TRUE,"InternetGetCookie failed\n");
355 ok(strstr(buffer,"A=B")!=NULL,"A=B missing\n");
356 ok(strstr(buffer,"C=D")!=NULL,"C=D missing\n");
357 ok(strstr(buffer,"E=F")!=NULL,"E=F missing\n");
358 ok(strstr(buffer,"G=H")==NULL,"G=H present\n");
359 ok(strstr(buffer,"I=J")!=NULL,"I=J missing\n");
360 ok(strstr(buffer,"K=L")==NULL,"K=L present\n");
361 ok(strstr(buffer,"M=N")==NULL,"M=N present\n");
362 ok(strstr(buffer,"O=P")==NULL,"O=P present\n");
365 ret = InternetGetCookie("http://testing.example.com/foobar/", NULL, buffer, &len);
366 ok(ret == TRUE,"InternetGetCookie failed\n");
367 ok(strstr(buffer,"A=B")!=NULL,"A=B missing\n");
368 ok(strstr(buffer,"C=D")!=NULL,"C=D missing\n");
369 ok(strstr(buffer,"E=F")!=NULL,"E=F missing\n");
370 ok(strstr(buffer,"G=H")!=NULL,"G=H missing\n");
371 ok(strstr(buffer,"I=J")!=NULL,"I=J missing\n");
372 ok(strstr(buffer,"K=L")==NULL,"K=L present\n");
373 ok(strstr(buffer,"M=N")==NULL,"M=N present\n");
374 ok(strstr(buffer,"O=P")==NULL,"O=P present\n");
377 ret = InternetGetCookie("http://testing.example.com/foo/bar", NULL, buffer, &len);
378 ok(ret == TRUE,"InternetGetCookie failed\n");
379 ok(strstr(buffer,"A=B")!=NULL,"A=B missing\n");
380 ok(strstr(buffer,"C=D")!=NULL,"C=D missing\n");
381 ok(strstr(buffer,"E=F")!=NULL,"E=F missing\n");
382 ok(strstr(buffer,"G=H")!=NULL,"G=H missing\n");
383 ok(strstr(buffer,"I=J")!=NULL,"I=J missing\n");
384 ok(strstr(buffer,"K=L")==NULL,"K=L present\n");
385 ok(strstr(buffer,"M=N")!=NULL,"M=N missing\n");
386 ok(strstr(buffer,"O=P")==NULL,"O=P present\n");
389 ret = InternetGetCookie("http://testing.example.com/barfoo", NULL, buffer, &len);
390 ok(ret == TRUE,"InternetGetCookie failed\n");
391 ok(strstr(buffer,"A=B")!=NULL,"A=B missing\n");
392 ok(strstr(buffer,"C=D")!=NULL,"C=D missing\n");
393 ok(strstr(buffer,"E=F")!=NULL,"E=F missing\n");
394 ok(strstr(buffer,"G=H")==NULL,"G=H present\n");
395 ok(strstr(buffer,"I=J")!=NULL,"I=J missing\n");
396 ok(strstr(buffer,"K=L")==NULL,"K=L present\n");
397 ok(strstr(buffer,"M=N")==NULL,"M=N present\n");
398 ok(strstr(buffer,"O=P")==NULL,"O=P present\n");
401 ret = InternetGetCookie("http://testing.example.com/barfoo/", NULL, buffer, &len);
402 ok(ret == TRUE,"InternetGetCookie failed\n");
403 ok(strstr(buffer,"A=B")!=NULL,"A=B missing\n");
404 ok(strstr(buffer,"C=D")!=NULL,"C=D missing\n");
405 ok(strstr(buffer,"E=F")!=NULL,"E=F missing\n");
406 ok(strstr(buffer,"G=H")==NULL,"G=H present\n");
407 ok(strstr(buffer,"I=J")!=NULL,"I=J missing\n");
408 ok(strstr(buffer,"K=L")==NULL,"K=L present\n");
409 ok(strstr(buffer,"M=N")==NULL,"M=N present\n");
410 ok(strstr(buffer,"O=P")==NULL,"O=P present\n");
413 ret = InternetGetCookie("http://testing.example.com/bar/foo", NULL, buffer, &len);
414 ok(ret == TRUE,"InternetGetCookie failed\n");
415 ok(strstr(buffer,"A=B")!=NULL,"A=B missing\n");
416 ok(strstr(buffer,"C=D")!=NULL,"C=D missing\n");
417 ok(strstr(buffer,"E=F")!=NULL,"E=F missing\n");
418 ok(strstr(buffer,"G=H")==NULL,"G=H present\n");
419 ok(strstr(buffer,"I=J")!=NULL,"I=J missing\n");
420 ok(strstr(buffer,"K=L")!=NULL,"K=L missing\n");
421 ok(strstr(buffer,"M=N")==NULL,"M=N present\n");
422 ok(strstr(buffer,"O=P")==NULL,"O=P present\n");
425 static void test_null(void)
428 static const WCHAR szServer[] = { 's','e','r','v','e','r',0 };
429 static const WCHAR szEmpty[] = { 0 };
430 static const WCHAR szUrl[] = { 'h','t','t','p',':','/','/','a','.','b','.','c',0 };
431 static const WCHAR szUrlEmpty[] = { 'h','t','t','p',':','/','/',0 };
432 static const WCHAR szExpect[] = { 's','e','r','v','e','r',';',' ','s','e','r','v','e','r',0 };
437 SetLastError(0xdeadbeef);
438 hi = InternetOpenW(NULL, 0, NULL, NULL, 0);
439 if (hi == NULL && GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)
441 win_skip("Internet*W functions are not implemented\n");
444 ok(hi != NULL, "open failed\n");
446 hc = InternetConnectW(hi, NULL, 0, NULL, NULL, 0, 0, 0);
447 ok(GetLastError() == ERROR_INVALID_PARAMETER, "wrong error\n");
448 ok(hc == NULL, "connect failed\n");
450 hc = InternetConnectW(hi, NULL, 0, NULL, NULL, INTERNET_SERVICE_HTTP, 0, 0);
451 ok(GetLastError() == ERROR_INVALID_PARAMETER, "wrong error\n");
452 ok(hc == NULL, "connect failed\n");
454 hc = InternetConnectW(hi, NULL, 0, NULL, NULL, INTERNET_SERVICE_FTP, 0, 0);
455 ok(GetLastError() == ERROR_INVALID_PARAMETER, "wrong error\n");
456 ok(hc == NULL, "connect failed\n");
458 hc = InternetConnectW(NULL, szServer, 0, NULL, NULL, INTERNET_SERVICE_FTP, 0, 0);
459 ok(GetLastError() == ERROR_INVALID_HANDLE, "wrong error\n");
460 ok(hc == NULL, "connect failed\n");
462 hc = InternetOpenUrlW(hi, NULL, NULL, 0, 0, 0);
463 ok(GetLastError() == ERROR_INVALID_PARAMETER ||
464 GetLastError() == ERROR_INTERNET_UNRECOGNIZED_SCHEME, "wrong error\n");
465 ok(hc == NULL, "connect failed\n");
467 hc = InternetOpenUrlW(hi, szServer, NULL, 0, 0, 0);
468 ok(GetLastError() == ERROR_INTERNET_UNRECOGNIZED_SCHEME, "wrong error\n");
469 ok(hc == NULL, "connect failed\n");
471 InternetCloseHandle(hi);
473 r = InternetSetCookieW(NULL, NULL, NULL);
474 ok(GetLastError() == ERROR_INVALID_PARAMETER, "wrong error\n");
475 ok(r == FALSE, "return wrong\n");
477 r = InternetSetCookieW(szServer, NULL, NULL);
478 ok(GetLastError() == ERROR_INVALID_PARAMETER, "wrong error\n");
479 ok(r == FALSE, "return wrong\n");
481 r = InternetSetCookieW(szUrl, szServer, NULL);
482 ok(GetLastError() == ERROR_INVALID_PARAMETER, "wrong error\n");
483 ok(r == FALSE, "return wrong\n");
485 r = InternetSetCookieW(szUrl, szServer, szServer);
486 ok(r == TRUE, "return wrong\n");
488 r = InternetSetCookieW(szUrl, NULL, szServer);
489 ok(r == TRUE, "return wrong\n");
491 r = InternetSetCookieW(szUrl, szServer, szEmpty);
492 ok(r == TRUE, "return wrong\n");
494 r = InternetSetCookieW(szUrlEmpty, szServer, szServer);
495 ok(r == FALSE, "return wrong\n");
497 r = InternetSetCookieW(szServer, NULL, szServer);
499 ok(GetLastError() == ERROR_INTERNET_UNRECOGNIZED_SCHEME, "wrong error\n");
501 ok(r == FALSE, "return wrong\n");
504 r = InternetGetCookieW(NULL, NULL, NULL, &sz);
505 ok(GetLastError() == ERROR_INVALID_PARAMETER || GetLastError() == ERROR_INTERNET_UNRECOGNIZED_SCHEME,
506 "wrong error %u\n", GetLastError());
507 ok( r == FALSE, "return wrong\n");
509 r = InternetGetCookieW(szServer, NULL, NULL, &sz);
511 ok(GetLastError() == ERROR_INTERNET_UNRECOGNIZED_SCHEME, "wrong error\n");
513 ok( r == FALSE, "return wrong\n");
516 r = InternetGetCookieW(szUrlEmpty, szServer, NULL, &sz);
517 ok( r == FALSE, "return wrong\n");
520 r = InternetGetCookieW(szUrl, szServer, NULL, &sz);
521 ok( r == TRUE, "return wrong\n");
523 /* sz is 14 on XP SP2 and beyond, 30 on XP SP1 and before */
524 ok( sz == 14 || sz == 30, "sz wrong, got %u, expected 14 or 30\n", sz);
527 memset(buffer, 0, sizeof buffer);
528 r = InternetGetCookieW(szUrl, szServer, buffer, &sz);
529 ok( r == TRUE, "return wrong\n");
531 /* sz == lstrlenW(buffer) only in XP SP1 */
532 ok( sz == 1 + lstrlenW(buffer) || sz == lstrlenW(buffer), "sz wrong %d\n", sz);
534 /* before XP SP2, buffer is "server; server" */
535 ok( !lstrcmpW(szExpect, buffer) || !lstrcmpW(szServer, buffer), "cookie data wrong\n");
538 r = InternetQueryOptionA(NULL, INTERNET_OPTION_CONNECTED_STATE, buffer, &sz);
539 ok(r == TRUE, "ret %d\n", r);
542 static void test_version(void)
544 INTERNET_VERSION_INFO version;
548 size = sizeof(version);
549 res = InternetQueryOptionA(NULL, INTERNET_OPTION_VERSION, &version, &size);
550 ok(res, "Could not get version: %u\n", GetLastError());
551 ok(version.dwMajorVersion == 1, "dwMajorVersion=%d, expected 1\n", version.dwMajorVersion);
552 ok(version.dwMinorVersion == 2, "dwMinorVersion=%d, expected 2\n", version.dwMinorVersion);
555 static void InternetTimeFromSystemTimeA_test(void)
558 static const SYSTEMTIME time = { 2005, 1, 5, 7, 12, 6, 35, 0 };
559 char string[INTERNET_RFC1123_BUFSIZE];
560 static const char expect[] = "Fri, 07 Jan 2005 12:06:35 GMT";
563 ret = pInternetTimeFromSystemTimeA( &time, INTERNET_RFC1123_FORMAT, string, sizeof(string) );
564 ok( ret, "InternetTimeFromSystemTimeA failed (%u)\n", GetLastError() );
566 ok( !memcmp( string, expect, sizeof(expect) ),
567 "InternetTimeFromSystemTimeA failed (%u)\n", GetLastError() );
569 /* test NULL time parameter */
570 SetLastError(0xdeadbeef);
571 ret = pInternetTimeFromSystemTimeA( NULL, INTERNET_RFC1123_FORMAT, string, sizeof(string) );
572 error = GetLastError();
573 ok( !ret, "InternetTimeFromSystemTimeA should have returned FALSE\n" );
574 ok( error == ERROR_INVALID_PARAMETER,
575 "InternetTimeFromSystemTimeA failed with ERROR_INVALID_PARAMETER instead of %u\n",
578 /* test NULL string parameter */
579 SetLastError(0xdeadbeef);
580 ret = pInternetTimeFromSystemTimeA( &time, INTERNET_RFC1123_FORMAT, NULL, sizeof(string) );
581 error = GetLastError();
582 ok( !ret, "InternetTimeFromSystemTimeA should have returned FALSE\n" );
583 ok( error == ERROR_INVALID_PARAMETER,
584 "InternetTimeFromSystemTimeA failed with ERROR_INVALID_PARAMETER instead of %u\n",
587 /* test invalid format parameter */
588 SetLastError(0xdeadbeef);
589 ret = pInternetTimeFromSystemTimeA( &time, INTERNET_RFC1123_FORMAT + 1, string, sizeof(string) );
590 error = GetLastError();
591 ok( !ret, "InternetTimeFromSystemTimeA should have returned FALSE\n" );
592 ok( error == ERROR_INVALID_PARAMETER,
593 "InternetTimeFromSystemTimeA failed with ERROR_INVALID_PARAMETER instead of %u\n",
596 /* test too small buffer size */
597 SetLastError(0xdeadbeef);
598 ret = pInternetTimeFromSystemTimeA( &time, INTERNET_RFC1123_FORMAT, string, 0 );
599 error = GetLastError();
600 ok( !ret, "InternetTimeFromSystemTimeA should have returned FALSE\n" );
601 ok( error == ERROR_INSUFFICIENT_BUFFER,
602 "InternetTimeFromSystemTimeA failed with ERROR_INSUFFICIENT_BUFFER instead of %u\n",
606 static void InternetTimeFromSystemTimeW_test(void)
609 static const SYSTEMTIME time = { 2005, 1, 5, 7, 12, 6, 35, 0 };
610 WCHAR string[INTERNET_RFC1123_BUFSIZE + 1];
611 static const WCHAR expect[] = { 'F','r','i',',',' ','0','7',' ','J','a','n',' ','2','0','0','5',' ',
612 '1','2',':','0','6',':','3','5',' ','G','M','T',0 };
615 ret = pInternetTimeFromSystemTimeW( &time, INTERNET_RFC1123_FORMAT, string, sizeof(string) );
616 ok( ret, "InternetTimeFromSystemTimeW failed (%u)\n", GetLastError() );
618 ok( !memcmp( string, expect, sizeof(expect) ),
619 "InternetTimeFromSystemTimeW failed (%u)\n", GetLastError() );
621 /* test NULL time parameter */
622 SetLastError(0xdeadbeef);
623 ret = pInternetTimeFromSystemTimeW( NULL, INTERNET_RFC1123_FORMAT, string, sizeof(string) );
624 error = GetLastError();
625 ok( !ret, "InternetTimeFromSystemTimeW should have returned FALSE\n" );
626 ok( error == ERROR_INVALID_PARAMETER,
627 "InternetTimeFromSystemTimeW failed with ERROR_INVALID_PARAMETER instead of %u\n",
630 /* test NULL string parameter */
631 SetLastError(0xdeadbeef);
632 ret = pInternetTimeFromSystemTimeW( &time, INTERNET_RFC1123_FORMAT, NULL, sizeof(string) );
633 error = GetLastError();
634 ok( !ret, "InternetTimeFromSystemTimeW should have returned FALSE\n" );
635 ok( error == ERROR_INVALID_PARAMETER,
636 "InternetTimeFromSystemTimeW failed with ERROR_INVALID_PARAMETER instead of %u\n",
639 /* test invalid format parameter */
640 SetLastError(0xdeadbeef);
641 ret = pInternetTimeFromSystemTimeW( &time, INTERNET_RFC1123_FORMAT + 1, string, sizeof(string) );
642 error = GetLastError();
643 ok( !ret, "InternetTimeFromSystemTimeW should have returned FALSE\n" );
644 ok( error == ERROR_INVALID_PARAMETER,
645 "InternetTimeFromSystemTimeW failed with ERROR_INVALID_PARAMETER instead of %u\n",
648 /* test too small buffer size */
649 SetLastError(0xdeadbeef);
650 ret = pInternetTimeFromSystemTimeW( &time, INTERNET_RFC1123_FORMAT, string, sizeof(string)/sizeof(string[0]) );
651 error = GetLastError();
652 ok( !ret, "InternetTimeFromSystemTimeW should have returned FALSE\n" );
653 ok( error == ERROR_INSUFFICIENT_BUFFER,
654 "InternetTimeFromSystemTimeW failed with ERROR_INSUFFICIENT_BUFFER instead of %u\n",
658 static void InternetTimeToSystemTimeA_test(void)
662 static const SYSTEMTIME expect = { 2005, 1, 5, 7, 12, 6, 35, 0 };
663 static const char string[] = "Fri, 07 Jan 2005 12:06:35 GMT";
664 static const char string2[] = " fri 7 jan 2005 12 06 35";
666 ret = pInternetTimeToSystemTimeA( string, &time, 0 );
667 ok( ret, "InternetTimeToSystemTimeA failed (%u)\n", GetLastError() );
668 ok( !memcmp( &time, &expect, sizeof(expect) ),
669 "InternetTimeToSystemTimeA failed (%u)\n", GetLastError() );
671 ret = pInternetTimeToSystemTimeA( string2, &time, 0 );
672 ok( ret, "InternetTimeToSystemTimeA failed (%u)\n", GetLastError() );
673 ok( !memcmp( &time, &expect, sizeof(expect) ),
674 "InternetTimeToSystemTimeA failed (%u)\n", GetLastError() );
677 static void InternetTimeToSystemTimeW_test(void)
681 static const SYSTEMTIME expect = { 2005, 1, 5, 7, 12, 6, 35, 0 };
682 static const WCHAR string[] = { 'F','r','i',',',' ','0','7',' ','J','a','n',' ','2','0','0','5',' ',
683 '1','2',':','0','6',':','3','5',' ','G','M','T',0 };
684 static const WCHAR string2[] = { ' ','f','r','i',' ','7',' ','j','a','n',' ','2','0','0','5',' ',
685 '1','2',' ','0','6',' ','3','5',0 };
686 static const WCHAR string3[] = { 'F','r',0 };
688 ret = pInternetTimeToSystemTimeW( NULL, NULL, 0 );
689 ok( !ret, "InternetTimeToSystemTimeW succeeded (%u)\n", GetLastError() );
691 ret = pInternetTimeToSystemTimeW( NULL, &time, 0 );
692 ok( !ret, "InternetTimeToSystemTimeW succeeded (%u)\n", GetLastError() );
694 ret = pInternetTimeToSystemTimeW( string, NULL, 0 );
695 ok( !ret, "InternetTimeToSystemTimeW succeeded (%u)\n", GetLastError() );
697 ret = pInternetTimeToSystemTimeW( string, &time, 0 );
698 ok( ret, "InternetTimeToSystemTimeW failed (%u)\n", GetLastError() );
700 ret = pInternetTimeToSystemTimeW( string, &time, 0 );
701 ok( ret, "InternetTimeToSystemTimeW failed (%u)\n", GetLastError() );
702 ok( !memcmp( &time, &expect, sizeof(expect) ),
703 "InternetTimeToSystemTimeW failed (%u)\n", GetLastError() );
705 ret = pInternetTimeToSystemTimeW( string2, &time, 0 );
706 ok( ret, "InternetTimeToSystemTimeW failed (%u)\n", GetLastError() );
707 ok( !memcmp( &time, &expect, sizeof(expect) ),
708 "InternetTimeToSystemTimeW failed (%u)\n", GetLastError() );
710 ret = pInternetTimeToSystemTimeW( string3, &time, 0 );
711 ok( ret, "InternetTimeToSystemTimeW failed (%u)\n", GetLastError() );
714 static void test_IsDomainLegalCookieDomainW(void)
718 static const WCHAR empty[] = {0};
719 static const WCHAR dot[] = {'.',0};
720 static const WCHAR uk[] = {'u','k',0};
721 static const WCHAR com[] = {'c','o','m',0};
722 static const WCHAR dot_com[] = {'.','c','o','m',0};
723 static const WCHAR gmail_com[] = {'g','m','a','i','l','.','c','o','m',0};
724 static const WCHAR dot_gmail_com[] = {'.','g','m','a','i','l','.','c','o','m',0};
725 static const WCHAR mail_gmail_com[] = {'m','a','i','l','.','g','m','a','i','l','.','c','o','m',0};
726 static const WCHAR gmail_co_uk[] = {'g','m','a','i','l','.','c','o','.','u','k',0};
727 static const WCHAR co_uk[] = {'c','o','.','u','k',0};
728 static const WCHAR dot_co_uk[] = {'.','c','o','.','u','k',0};
730 SetLastError(0xdeadbeef);
731 ret = pIsDomainLegalCookieDomainW(NULL, NULL);
732 error = GetLastError();
733 if (!ret && error == ERROR_CALL_NOT_IMPLEMENTED)
735 win_skip("IsDomainLegalCookieDomainW is not implemented\n");
739 broken(ret), /* IE6 */
740 "IsDomainLegalCookieDomainW succeeded\n");
741 ok(error == ERROR_INVALID_PARAMETER, "got %u expected ERROR_INVALID_PARAMETER\n", error);
743 SetLastError(0xdeadbeef);
744 ret = pIsDomainLegalCookieDomainW(com, NULL);
745 error = GetLastError();
746 ok(!ret, "IsDomainLegalCookieDomainW succeeded\n");
747 ok(error == ERROR_INVALID_PARAMETER, "got %u expected ERROR_INVALID_PARAMETER\n", error);
749 SetLastError(0xdeadbeef);
750 ret = pIsDomainLegalCookieDomainW(NULL, gmail_com);
751 error = GetLastError();
752 ok(!ret, "IsDomainLegalCookieDomainW succeeded\n");
753 ok(error == ERROR_INVALID_PARAMETER, "got %u expected ERROR_INVALID_PARAMETER\n", error);
755 SetLastError(0xdeadbeef);
756 ret = pIsDomainLegalCookieDomainW(empty, gmail_com);
757 error = GetLastError();
758 ok(!ret, "IsDomainLegalCookieDomainW succeeded\n");
759 ok(error == ERROR_INVALID_NAME ||
760 broken(error == ERROR_INVALID_PARAMETER), /* IE6 */
761 "got %u expected ERROR_INVALID_NAME\n", error);
763 SetLastError(0xdeadbeef);
764 ret = pIsDomainLegalCookieDomainW(com, empty);
765 error = GetLastError();
766 ok(!ret, "IsDomainLegalCookieDomainW succeeded\n");
767 ok(error == ERROR_INVALID_NAME ||
768 broken(error == ERROR_INVALID_PARAMETER), /* IE6 */
769 "got %u expected ERROR_INVALID_NAME\n", error);
771 SetLastError(0xdeadbeef);
772 ret = pIsDomainLegalCookieDomainW(gmail_com, dot);
773 error = GetLastError();
774 ok(!ret, "IsDomainLegalCookieDomainW succeeded\n");
775 ok(error == ERROR_INVALID_NAME ||
776 broken(error == 0xdeadbeef), /* IE6 */
777 "got %u expected ERROR_INVALID_NAME\n", error);
779 SetLastError(0xdeadbeef);
780 ret = pIsDomainLegalCookieDomainW(dot, gmail_com);
781 error = GetLastError();
782 ok(!ret, "IsDomainLegalCookieDomainW succeeded\n");
783 ok(error == ERROR_INVALID_NAME ||
784 broken(error == 0xdeadbeef), /* IE6 */
785 "got %u expected ERROR_INVALID_NAME\n", error);
787 SetLastError(0xdeadbeef);
788 ret = pIsDomainLegalCookieDomainW(com, com);
789 error = GetLastError();
790 ok(!ret, "IsDomainLegalCookieDomainW succeeded\n");
791 ok(error == 0xdeadbeef, "got %u expected 0xdeadbeef\n", error);
793 SetLastError(0xdeadbeef);
794 ret = pIsDomainLegalCookieDomainW(com, dot_com);
795 error = GetLastError();
796 ok(!ret, "IsDomainLegalCookieDomainW succeeded\n");
797 ok(error == ERROR_INVALID_NAME ||
798 broken(error == 0xdeadbeef), /* IE6 */
799 "got %u expected ERROR_INVALID_NAME\n", error);
801 SetLastError(0xdeadbeef);
802 ret = pIsDomainLegalCookieDomainW(dot_com, com);
803 error = GetLastError();
804 ok(!ret, "IsDomainLegalCookieDomainW succeeded\n");
805 ok(error == ERROR_INVALID_NAME ||
806 broken(error == 0xdeadbeef), /* IE6 */
807 "got %u expected ERROR_INVALID_NAME\n", error);
809 SetLastError(0xdeadbeef);
810 ret = pIsDomainLegalCookieDomainW(com, gmail_com);
811 error = GetLastError();
812 ok(!ret, "IsDomainLegalCookieDomainW succeeded\n");
813 ok(error == ERROR_SXS_KEY_NOT_FOUND ||
814 error == ERROR_SUCCESS || /* IE8 on W2K3 */
815 error == 0xdeadbeef, /* up to IE7 */
816 "unexpected error: %u\n", error);
818 ret = pIsDomainLegalCookieDomainW(gmail_com, gmail_com);
819 ok(ret, "IsDomainLegalCookieDomainW failed\n");
821 SetLastError(0xdeadbeef);
822 ret = pIsDomainLegalCookieDomainW(gmail_co_uk, co_uk);
823 error = GetLastError();
824 ok(!ret, "IsDomainLegalCookieDomainW succeeded\n");
825 ok(error == ERROR_SXS_KEY_NOT_FOUND || /* IE8 on XP */
826 error == ERROR_FILE_NOT_FOUND || /* IE8 on Vista */
827 error == ERROR_SUCCESS || /* IE8 on W2K3 */
828 error == 0xdeadbeef, /* up to IE7 */
829 "unexpected error: %u\n", error);
831 ret = pIsDomainLegalCookieDomainW(uk, co_uk);
832 ok(!ret, "IsDomainLegalCookieDomainW succeeded\n");
834 ret = pIsDomainLegalCookieDomainW(gmail_co_uk, dot_co_uk);
835 ok(!ret, "IsDomainLegalCookieDomainW succeeded\n");
837 ret = pIsDomainLegalCookieDomainW(gmail_co_uk, gmail_co_uk);
838 ok(ret, "IsDomainLegalCookieDomainW failed\n");
840 ret = pIsDomainLegalCookieDomainW(gmail_com, com);
841 ok(!ret, "IsDomainLegalCookieDomainW succeeded\n");
843 SetLastError(0xdeadbeef);
844 ret = pIsDomainLegalCookieDomainW(dot_gmail_com, mail_gmail_com);
845 error = GetLastError();
846 ok(!ret, "IsDomainLegalCookieDomainW succeeded\n");
847 ok(error == ERROR_INVALID_NAME ||
848 broken(error == 0xdeadbeef), /* IE6 */
849 "got %u expected ERROR_INVALID_NAME\n", error);
851 ret = pIsDomainLegalCookieDomainW(gmail_com, mail_gmail_com);
852 ok(ret, "IsDomainLegalCookieDomainW failed\n");
854 ret = pIsDomainLegalCookieDomainW(mail_gmail_com, gmail_com);
855 ok(!ret, "IsDomainLegalCookieDomainW succeeded\n");
857 ret = pIsDomainLegalCookieDomainW(mail_gmail_com, com);
858 ok(!ret, "IsDomainLegalCookieDomainW succeeded\n");
860 ret = pIsDomainLegalCookieDomainW(dot_gmail_com, mail_gmail_com);
861 ok(!ret, "IsDomainLegalCookieDomainW succeeded\n");
863 ret = pIsDomainLegalCookieDomainW(mail_gmail_com, dot_gmail_com);
864 ok(!ret, "IsDomainLegalCookieDomainW succeeded\n");
867 static void test_PrivacyGetSetZonePreferenceW(void)
869 DWORD ret, zone, type, template, old_template;
873 ret = pPrivacyGetZonePreferenceW(zone, type, NULL, NULL, NULL);
874 ok(ret == 0, "expected ret == 0, got %u\n", ret);
877 ret = pPrivacyGetZonePreferenceW(zone, type, &old_template, NULL, NULL);
878 ok(ret == 0, "expected ret == 0, got %u\n", ret);
881 ret = pPrivacySetZonePreferenceW(zone, type, template, NULL);
882 ok(ret == 0, "expected ret == 0, got %u\n", ret);
885 ret = pPrivacyGetZonePreferenceW(zone, type, &template, NULL, NULL);
886 ok(ret == 0, "expected ret == 0, got %u\n", ret);
887 ok(template == 5, "expected template == 5, got %u\n", template);
890 ret = pPrivacySetZonePreferenceW(zone, type, old_template, NULL);
891 ok(ret == 0, "expected ret == 0, got %u\n", ret);
894 static void test_InternetSetOption(void)
896 HINTERNET ses, con, req;
901 ses = InternetOpen(NULL, INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, 0);
902 ok(ses != 0, "InternetOpen failed: 0x%08x\n", GetLastError());
903 con = InternetConnect(ses, "www.winehq.org", 80, NULL, NULL, INTERNET_SERVICE_HTTP, 0, 0);
904 ok(con != 0, "InternetConnect failed: 0x%08x\n", GetLastError());
905 req = HttpOpenRequest(con, "GET", "/", NULL, NULL, NULL, 0, 0);
906 ok(req != 0, "HttpOpenRequest failed: 0x%08x\n", GetLastError());
908 /* INTERNET_OPTION_POLICY tests */
909 SetLastError(0xdeadbeef);
910 ret = InternetSetOptionW(ses, INTERNET_OPTION_POLICY, NULL, 0);
911 ok(ret == FALSE, "InternetSetOption should've failed\n");
912 ok(GetLastError() == ERROR_INVALID_PARAMETER, "GetLastError should've "
913 "given ERROR_INVALID_PARAMETER, gave: 0x%08x\n", GetLastError());
915 SetLastError(0xdeadbeef);
916 ret = InternetQueryOptionW(ses, INTERNET_OPTION_POLICY, NULL, 0);
917 ok(ret == FALSE, "InternetQueryOption should've failed\n");
918 ok(GetLastError() == ERROR_INVALID_PARAMETER, "GetLastError should've "
919 "given ERROR_INVALID_PARAMETER, gave: 0x%08x\n", GetLastError());
921 /* INTERNET_OPTION_ERROR_MASK tests */
922 SetLastError(0xdeadbeef);
923 size = sizeof(ulArg);
924 ret = InternetQueryOptionW(NULL, INTERNET_OPTION_ERROR_MASK, (void*)&ulArg, &size);
925 ok(ret == FALSE, "InternetQueryOption should've failed\n");
926 ok(GetLastError() == ERROR_INTERNET_INCORRECT_HANDLE_TYPE, "GetLastError() = %x\n", GetLastError());
928 SetLastError(0xdeadbeef);
930 ret = InternetSetOption(NULL, INTERNET_OPTION_ERROR_MASK, (void*)&ulArg, sizeof(ULONG));
931 ok(ret == FALSE, "InternetQueryOption should've failed\n");
932 ok(GetLastError() == ERROR_INTERNET_INCORRECT_HANDLE_TYPE, "GetLastError() = %x\n", GetLastError());
934 SetLastError(0xdeadbeef);
936 ret = InternetSetOption(req, INTERNET_OPTION_ERROR_MASK, (void*)&ulArg, 20);
937 ok(ret == FALSE, "InternetQueryOption should've failed\n");
938 ok(GetLastError() == ERROR_INTERNET_BAD_OPTION_LENGTH, "GetLastError() = %d\n", GetLastError());
940 SetLastError(0xdeadbeef);
942 ret = InternetSetOption(req, INTERNET_OPTION_ERROR_MASK, (void*)&ulArg, sizeof(ULONG));
943 ok(ret == TRUE, "InternetQueryOption should've succeeded\n");
944 ok(GetLastError() == 0xdeadbeef, "GetLastError() = %d\n", GetLastError());
946 SetLastError(0xdeadbeef);
948 ret = InternetSetOption(req, INTERNET_OPTION_ERROR_MASK, (void*)&ulArg, sizeof(ULONG));
949 ok(ret == FALSE, "InternetQueryOption should've failed\n");
950 ok(GetLastError() == ERROR_INVALID_PARAMETER, "GetLastError() = %x\n", GetLastError());
952 SetLastError(0xdeadbeef);
954 ret = InternetSetOption(req, INTERNET_OPTION_ERROR_MASK, (void*)&ulArg, sizeof(ULONG));
955 ok(ret == FALSE, "InternetQueryOption should've failed\n");
956 ok(GetLastError() == ERROR_INVALID_PARAMETER, "GetLastError() = %x\n", GetLastError());
958 ret = InternetCloseHandle(req);
959 ok(ret == TRUE, "InternetCloseHandle failed: 0x%08x\n", GetLastError());
960 ret = InternetCloseHandle(con);
961 ok(ret == TRUE, "InternetCloseHandle failed: 0x%08x\n", GetLastError());
962 ret = InternetCloseHandle(ses);
963 ok(ret == TRUE, "InternetCloseHandle failed: 0x%08x\n", GetLastError());
966 #define verifyProxyEnable(e) r_verifyProxyEnable(__LINE__, e)
967 static void r_verifyProxyEnable(LONG l, DWORD exp)
970 DWORD type, val, size = sizeof(DWORD);
972 static const CHAR szInternetSettings[] = "Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings";
973 static const CHAR szProxyEnable[] = "ProxyEnable";
975 ret = RegOpenKeyA(HKEY_CURRENT_USER, szInternetSettings, &hkey);
976 ok_(__FILE__,l) (!ret, "RegOpenKeyA failed: 0x%08x\n", ret);
978 ret = RegQueryValueExA(hkey, szProxyEnable, 0, &type, (BYTE*)&val, &size);
979 ok_(__FILE__,l) (!ret, "RegQueryValueExA failed: 0x%08x\n", ret);
980 ok_(__FILE__,l) (type == REG_DWORD, "Expected regtype to be REG_DWORD, was: %d\n", type);
981 ok_(__FILE__,l) (val == exp, "Expected ProxyEnabled to be %d, got: %d\n", exp, val);
983 ret = RegCloseKey(hkey);
984 ok_(__FILE__,l) (!ret, "RegCloseKey failed: 0x%08x\n", ret);
987 static void test_Option_PerConnectionOption(void)
990 DWORD size = sizeof(INTERNET_PER_CONN_OPTION_LISTW);
991 INTERNET_PER_CONN_OPTION_LISTW list = {size};
992 INTERNET_PER_CONN_OPTIONW *orig_settings;
993 static WCHAR proxy_srvW[] = {'p','r','o','x','y','.','e','x','a','m','p','l','e',0};
995 /* get the global IE proxy server info, to restore later */
996 list.dwOptionCount = 2;
997 list.pOptions = HeapAlloc(GetProcessHeap(), 0, 2 * sizeof(INTERNET_PER_CONN_OPTIONW));
999 list.pOptions[0].dwOption = INTERNET_PER_CONN_PROXY_SERVER;
1000 list.pOptions[1].dwOption = INTERNET_PER_CONN_FLAGS;
1002 ret = InternetQueryOptionW(NULL, INTERNET_OPTION_PER_CONNECTION_OPTION,
1004 ok(ret == TRUE, "InternetQueryOption should've succeeded\n");
1005 orig_settings = list.pOptions;
1007 /* set the global IE proxy server */
1008 list.dwOptionCount = 2;
1009 list.pOptions = HeapAlloc(GetProcessHeap(), 0, 2 * sizeof(INTERNET_PER_CONN_OPTIONW));
1011 list.pOptions[0].dwOption = INTERNET_PER_CONN_PROXY_SERVER;
1012 list.pOptions[0].Value.pszValue = proxy_srvW;
1013 list.pOptions[1].dwOption = INTERNET_PER_CONN_FLAGS;
1014 list.pOptions[1].Value.dwValue = PROXY_TYPE_PROXY;
1016 ret = InternetSetOptionW(NULL, INTERNET_OPTION_PER_CONNECTION_OPTION,
1018 ok(ret == TRUE, "InternetSetOption should've succeeded\n");
1020 HeapFree(GetProcessHeap(), 0, list.pOptions);
1022 /* get & verify the global IE proxy server */
1023 list.dwOptionCount = 2;
1024 list.dwOptionError = 0;
1025 list.pOptions = HeapAlloc(GetProcessHeap(), 0, 2 * sizeof(INTERNET_PER_CONN_OPTIONW));
1027 list.pOptions[0].dwOption = INTERNET_PER_CONN_PROXY_SERVER;
1028 list.pOptions[1].dwOption = INTERNET_PER_CONN_FLAGS;
1030 ret = InternetQueryOptionW(NULL, INTERNET_OPTION_PER_CONNECTION_OPTION,
1032 ok(ret == TRUE, "InternetQueryOption should've succeeded\n");
1033 ok(!lstrcmpW(list.pOptions[0].Value.pszValue, proxy_srvW),
1034 "Retrieved proxy server should've been %s, was: %s\n",
1035 wine_dbgstr_w(proxy_srvW), wine_dbgstr_w(list.pOptions[0].Value.pszValue));
1036 ok(list.pOptions[1].Value.dwValue == PROXY_TYPE_PROXY,
1037 "Retrieved flags should've been PROXY_TYPE_PROXY, was: %d\n",
1038 list.pOptions[1].Value.dwValue);
1039 verifyProxyEnable(1);
1041 HeapFree(GetProcessHeap(), 0, list.pOptions[0].Value.pszValue);
1042 HeapFree(GetProcessHeap(), 0, list.pOptions);
1044 /* disable the proxy server */
1045 list.dwOptionCount = 1;
1046 list.pOptions = HeapAlloc(GetProcessHeap(), 0, sizeof(INTERNET_PER_CONN_OPTIONW));
1048 list.pOptions[0].dwOption = INTERNET_PER_CONN_FLAGS;
1049 list.pOptions[0].Value.dwValue = PROXY_TYPE_DIRECT;
1051 ret = InternetSetOptionW(NULL, INTERNET_OPTION_PER_CONNECTION_OPTION,
1053 ok(ret == TRUE, "InternetSetOption should've succeeded\n");
1055 HeapFree(GetProcessHeap(), 0, list.pOptions);
1057 /* verify that the proxy is disabled */
1058 list.dwOptionCount = 1;
1059 list.dwOptionError = 0;
1060 list.pOptions = HeapAlloc(GetProcessHeap(), 0, sizeof(INTERNET_PER_CONN_OPTIONW));
1062 list.pOptions[0].dwOption = INTERNET_PER_CONN_FLAGS;
1064 ret = InternetQueryOptionW(NULL, INTERNET_OPTION_PER_CONNECTION_OPTION,
1066 ok(ret == TRUE, "InternetQueryOption should've succeeded\n");
1067 ok(list.pOptions[0].Value.dwValue == PROXY_TYPE_DIRECT,
1068 "Retrieved flags should've been PROXY_TYPE_DIRECT, was: %d\n",
1069 list.pOptions[0].Value.dwValue);
1070 verifyProxyEnable(0);
1072 HeapFree(GetProcessHeap(), 0, list.pOptions);
1074 /* set the proxy flags to 'invalid' value */
1075 list.dwOptionCount = 1;
1076 list.pOptions = HeapAlloc(GetProcessHeap(), 0, sizeof(INTERNET_PER_CONN_OPTIONW));
1078 list.pOptions[0].dwOption = INTERNET_PER_CONN_FLAGS;
1079 list.pOptions[0].Value.dwValue = PROXY_TYPE_PROXY | PROXY_TYPE_DIRECT;
1081 ret = InternetSetOptionW(NULL, INTERNET_OPTION_PER_CONNECTION_OPTION,
1083 ok(ret == TRUE, "InternetSetOption should've succeeded\n");
1085 HeapFree(GetProcessHeap(), 0, list.pOptions);
1087 /* verify that the proxy is enabled */
1088 list.dwOptionCount = 1;
1089 list.dwOptionError = 0;
1090 list.pOptions = HeapAlloc(GetProcessHeap(), 0, sizeof(INTERNET_PER_CONN_OPTIONW));
1092 list.pOptions[0].dwOption = INTERNET_PER_CONN_FLAGS;
1094 ret = InternetQueryOptionW(NULL, INTERNET_OPTION_PER_CONNECTION_OPTION,
1096 ok(ret == TRUE, "InternetQueryOption should've succeeded\n");
1097 todo_wine ok(list.pOptions[0].Value.dwValue == (PROXY_TYPE_PROXY | PROXY_TYPE_DIRECT),
1098 "Retrieved flags should've been PROXY_TYPE_PROXY | PROXY_TYPE_DIRECT, was: %d\n",
1099 list.pOptions[0].Value.dwValue);
1100 verifyProxyEnable(1);
1102 HeapFree(GetProcessHeap(), 0, list.pOptions);
1104 /* restore original settings */
1105 list.dwOptionCount = 2;
1106 list.pOptions = orig_settings;
1108 ret = InternetSetOptionW(NULL, INTERNET_OPTION_PER_CONNECTION_OPTION,
1110 ok(ret == TRUE, "InternetSetOption should've succeeded\n");
1112 HeapFree(GetProcessHeap(), 0, list.pOptions);
1115 static void test_Option_PerConnectionOptionA(void)
1118 DWORD size = sizeof(INTERNET_PER_CONN_OPTION_LISTA);
1119 INTERNET_PER_CONN_OPTION_LISTA list = {size};
1120 INTERNET_PER_CONN_OPTIONA *orig_settings;
1121 char proxy_srv[] = "proxy.example";
1123 /* get the global IE proxy server info, to restore later */
1124 list.dwOptionCount = 2;
1125 list.pOptions = HeapAlloc(GetProcessHeap(), 0, 2 * sizeof(INTERNET_PER_CONN_OPTIONA));
1127 list.pOptions[0].dwOption = INTERNET_PER_CONN_PROXY_SERVER;
1128 list.pOptions[1].dwOption = INTERNET_PER_CONN_FLAGS;
1130 ret = InternetQueryOptionA(NULL, INTERNET_OPTION_PER_CONNECTION_OPTION,
1132 ok(ret == TRUE, "InternetQueryOption should've succeeded\n");
1133 orig_settings = list.pOptions;
1135 /* set the global IE proxy server */
1136 list.dwOptionCount = 2;
1137 list.pOptions = HeapAlloc(GetProcessHeap(), 0, 2 * sizeof(INTERNET_PER_CONN_OPTIONA));
1139 list.pOptions[0].dwOption = INTERNET_PER_CONN_PROXY_SERVER;
1140 list.pOptions[0].Value.pszValue = proxy_srv;
1141 list.pOptions[1].dwOption = INTERNET_PER_CONN_FLAGS;
1142 list.pOptions[1].Value.dwValue = PROXY_TYPE_PROXY;
1144 ret = InternetSetOptionA(NULL, INTERNET_OPTION_PER_CONNECTION_OPTION,
1146 ok(ret == TRUE, "InternetSetOption should've succeeded\n");
1148 HeapFree(GetProcessHeap(), 0, list.pOptions);
1150 /* get & verify the global IE proxy server */
1151 list.dwOptionCount = 2;
1152 list.dwOptionError = 0;
1153 list.pOptions = HeapAlloc(GetProcessHeap(), 0, 2 * sizeof(INTERNET_PER_CONN_OPTIONA));
1155 list.pOptions[0].dwOption = INTERNET_PER_CONN_PROXY_SERVER;
1156 list.pOptions[1].dwOption = INTERNET_PER_CONN_FLAGS;
1158 ret = InternetQueryOptionA(NULL, INTERNET_OPTION_PER_CONNECTION_OPTION,
1160 ok(ret == TRUE, "InternetQueryOption should've succeeded\n");
1161 ok(!lstrcmpA(list.pOptions[0].Value.pszValue, "proxy.example"),
1162 "Retrieved proxy server should've been \"%s\", was: \"%s\"\n",
1163 proxy_srv, list.pOptions[0].Value.pszValue);
1164 ok(list.pOptions[1].Value.dwValue == PROXY_TYPE_PROXY,
1165 "Retrieved flags should've been PROXY_TYPE_PROXY, was: %d\n",
1166 list.pOptions[1].Value.dwValue);
1168 HeapFree(GetProcessHeap(), 0, list.pOptions[0].Value.pszValue);
1169 HeapFree(GetProcessHeap(), 0, list.pOptions);
1171 /* restore original settings */
1172 list.dwOptionCount = 2;
1173 list.pOptions = orig_settings;
1175 ret = InternetSetOptionA(NULL, INTERNET_OPTION_PER_CONNECTION_OPTION,
1177 ok(ret == TRUE, "InternetSetOption should've succeeded\n");
1179 HeapFree(GetProcessHeap(), 0, list.pOptions);
1182 #define FLAG_TODO 0x1
1183 #define FLAG_NEEDREQ 0x2
1184 #define FLAG_UNIMPL 0x4
1186 static void test_InternetErrorDlg(void)
1188 HINTERNET ses, con, req;
1192 static const struct {
1197 { ERROR_INTERNET_INCORRECT_PASSWORD , ERROR_SUCCESS, FLAG_NEEDREQ },
1198 { ERROR_INTERNET_SEC_CERT_DATE_INVALID , ERROR_CANCELLED, 0 },
1199 { ERROR_INTERNET_SEC_CERT_CN_INVALID , ERROR_CANCELLED, 0 },
1200 { ERROR_INTERNET_HTTP_TO_HTTPS_ON_REDIR , ERROR_SUCCESS, 0 },
1201 { ERROR_INTERNET_HTTPS_TO_HTTP_ON_REDIR , ERROR_SUCCESS, FLAG_TODO },
1202 { ERROR_INTERNET_MIXED_SECURITY , ERROR_CANCELLED, FLAG_TODO },
1203 { ERROR_INTERNET_CHG_POST_IS_NON_SECURE , ERROR_CANCELLED, FLAG_TODO },
1204 { ERROR_INTERNET_POST_IS_NON_SECURE , ERROR_SUCCESS, 0 },
1205 { ERROR_INTERNET_CLIENT_AUTH_CERT_NEEDED, ERROR_CANCELLED, FLAG_NEEDREQ|FLAG_TODO },
1206 { ERROR_INTERNET_INVALID_CA , ERROR_CANCELLED, 0 },
1207 { ERROR_INTERNET_HTTPS_HTTP_SUBMIT_REDIR, ERROR_CANCELLED, FLAG_TODO },
1208 { ERROR_INTERNET_INSERT_CDROM , ERROR_CANCELLED, FLAG_TODO|FLAG_NEEDREQ|FLAG_UNIMPL },
1209 { ERROR_INTERNET_SEC_CERT_ERRORS , ERROR_CANCELLED, 0 },
1210 { ERROR_INTERNET_SEC_CERT_REV_FAILED , ERROR_CANCELLED, FLAG_TODO },
1211 { ERROR_HTTP_COOKIE_NEEDS_CONFIRMATION , ERROR_HTTP_COOKIE_DECLINED, FLAG_TODO },
1212 { ERROR_INTERNET_BAD_AUTO_PROXY_SCRIPT , ERROR_CANCELLED, FLAG_TODO },
1213 { ERROR_INTERNET_UNABLE_TO_DOWNLOAD_SCRIPT, ERROR_CANCELLED, FLAG_TODO },
1214 { ERROR_HTTP_REDIRECT_NEEDS_CONFIRMATION, ERROR_CANCELLED, FLAG_TODO },
1215 { ERROR_INTERNET_SEC_CERT_REVOKED , ERROR_CANCELLED, 0 },
1216 { 0, ERROR_NOT_SUPPORTED }
1221 res = InternetErrorDlg(NULL, NULL, 12055, flags, NULL);
1222 ok(res == ERROR_INVALID_HANDLE, "Got %d\n", res);
1224 ses = InternetOpen(NULL, INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, 0);
1225 ok(ses != 0, "InternetOpen failed: 0x%08x\n", GetLastError());
1226 con = InternetConnect(ses, "www.winehq.org", 80, NULL, NULL, INTERNET_SERVICE_HTTP, 0, 0);
1227 ok(con != 0, "InternetConnect failed: 0x%08x\n", GetLastError());
1228 req = HttpOpenRequest(con, "GET", "/", NULL, NULL, NULL, 0, 0);
1229 ok(req != 0, "HttpOpenRequest failed: 0x%08x\n", GetLastError());
1231 /* NULL hwnd and FLAGS_ERROR_UI_FLAGS_NO_UI not set */
1232 for(i = INTERNET_ERROR_BASE; i < INTERNET_ERROR_LAST; i++)
1234 res = InternetErrorDlg(NULL, req, i, flags, NULL);
1235 ok(res == ERROR_INVALID_HANDLE, "Got %d (%d)\n", res, i);
1238 hwnd = GetDesktopWindow();
1239 ok(hwnd != NULL, "GetDesktopWindow failed (%d)\n", GetLastError());
1241 flags = FLAGS_ERROR_UI_FLAGS_NO_UI;
1242 for(i = INTERNET_ERROR_BASE; i < INTERNET_ERROR_LAST; i++)
1244 DWORD expected, test_flags, j;
1246 for(j = 0; no_ui_res[j].error != 0; ++j)
1247 if(no_ui_res[j].error == i)
1250 test_flags = no_ui_res[j].test_flags;
1251 expected = no_ui_res[j].res;
1253 /* Try an invalid request handle */
1254 res = InternetErrorDlg(hwnd, (HANDLE)0xdeadbeef, i, flags, NULL);
1255 if(res == ERROR_CALL_NOT_IMPLEMENTED)
1257 todo_wine ok(test_flags & FLAG_UNIMPL, "%i is unexpectedly unimplemented.\n", i);
1261 todo_wine ok(res == ERROR_INVALID_HANDLE, "Got %d (%d)\n", res, i);
1263 /* With a valid req */
1264 if(i == ERROR_INTERNET_NEED_UI)
1265 continue; /* Crashes on windows XP */
1267 if(i == ERROR_INTERNET_SEC_CERT_REVOKED)
1268 continue; /* Interactive (XP, Win7) */
1270 res = InternetErrorDlg(hwnd, req, i, flags, NULL);
1272 /* Handle some special cases */
1275 case ERROR_INTERNET_HTTP_TO_HTTPS_ON_REDIR:
1276 case ERROR_INTERNET_HTTPS_TO_HTTP_ON_REDIR:
1277 if(res == ERROR_CANCELLED)
1279 /* Some windows XP, w2k3 x64, W2K8 */
1280 win_skip("Skipping some tests for %d\n", i);
1284 case ERROR_INTERNET_FORTEZZA_LOGIN_NEEDED:
1287 /* Windows XP, W2K3 */
1288 ok(res == NTE_PROV_TYPE_NOT_DEF, "Got %d\n", res);
1289 win_skip("Skipping some tests for %d\n", i);
1296 if(test_flags & FLAG_TODO)
1297 todo_wine ok(res == expected, "Got %d, expected %d (%d)\n", res, expected, i);
1299 ok(res == expected, "Got %d, expected %d (%d)\n", res, expected, i);
1301 /* Same thing with NULL hwnd */
1302 res = InternetErrorDlg(NULL, req, i, flags, NULL);
1303 if(test_flags & FLAG_TODO)
1304 todo_wine ok(res == expected, "Got %d, expected %d (%d)\n", res, expected, i);
1306 ok(res == expected, "Got %d, expected %d (%d)\n", res, expected, i);
1309 /* With a null req */
1310 if(test_flags & FLAG_NEEDREQ)
1311 expected = ERROR_INVALID_PARAMETER;
1313 res = InternetErrorDlg(hwnd, NULL, i, flags, NULL);
1314 if( test_flags & FLAG_TODO || i == ERROR_INTERNET_INCORRECT_PASSWORD)
1315 todo_wine ok(res == expected, "Got %d, expected %d (%d)\n", res, expected, i);
1317 ok(res == expected, "Got %d, expected %d (%d)\n", res, expected, i);
1320 res = InternetCloseHandle(req);
1321 ok(res == TRUE, "InternetCloseHandle failed: 0x%08x\n", GetLastError());
1322 res = InternetCloseHandle(con);
1323 ok(res == TRUE, "InternetCloseHandle failed: 0x%08x\n", GetLastError());
1324 res = InternetCloseHandle(ses);
1325 ok(res == TRUE, "InternetCloseHandle failed: 0x%08x\n", GetLastError());
1328 /* ############################### */
1330 START_TEST(internet)
1333 hdll = GetModuleHandleA("wininet.dll");
1335 if(!GetProcAddress(hdll, "InternetGetCookieExW")) {
1336 win_skip("Too old IE (older than 6.0)\n");
1340 pCreateUrlCacheContainerA = (void*)GetProcAddress(hdll, "CreateUrlCacheContainerA");
1341 pCreateUrlCacheContainerW = (void*)GetProcAddress(hdll, "CreateUrlCacheContainerW");
1342 pInternetTimeFromSystemTimeA = (void*)GetProcAddress(hdll, "InternetTimeFromSystemTimeA");
1343 pInternetTimeFromSystemTimeW = (void*)GetProcAddress(hdll, "InternetTimeFromSystemTimeW");
1344 pInternetTimeToSystemTimeA = (void*)GetProcAddress(hdll, "InternetTimeToSystemTimeA");
1345 pInternetTimeToSystemTimeW = (void*)GetProcAddress(hdll, "InternetTimeToSystemTimeW");
1346 pIsDomainLegalCookieDomainW = (void*)GetProcAddress(hdll, (LPCSTR)117);
1347 pPrivacyGetZonePreferenceW = (void*)GetProcAddress(hdll, "PrivacyGetZonePreferenceW");
1348 pPrivacySetZonePreferenceW = (void*)GetProcAddress(hdll, "PrivacySetZonePreferenceW");
1350 test_InternetCanonicalizeUrlA();
1351 test_InternetQueryOptionA();
1353 test_complicated_cookie();
1356 test_Option_PerConnectionOption();
1357 test_Option_PerConnectionOptionA();
1358 test_InternetErrorDlg();
1361 if (!pInternetTimeFromSystemTimeA)
1362 win_skip("skipping the InternetTime tests\n");
1365 InternetTimeFromSystemTimeA_test();
1366 InternetTimeFromSystemTimeW_test();
1367 InternetTimeToSystemTimeA_test();
1368 InternetTimeToSystemTimeW_test();
1370 if (pIsDomainLegalCookieDomainW &&
1371 ((void*)pIsDomainLegalCookieDomainW == (void*)pCreateUrlCacheContainerA ||
1372 (void*)pIsDomainLegalCookieDomainW == (void*)pCreateUrlCacheContainerW))
1373 win_skip("IsDomainLegalCookieDomainW is not available on systems with IE5\n");
1374 else if (!pIsDomainLegalCookieDomainW)
1375 win_skip("IsDomainLegalCookieDomainW (or ordinal 117) is not available\n");
1377 test_IsDomainLegalCookieDomainW();
1379 if (pPrivacyGetZonePreferenceW && pPrivacySetZonePreferenceW)
1380 test_PrivacyGetSetZonePreferenceW();
1382 win_skip("Privacy[SG]etZonePreferenceW are not available\n");
1384 test_InternetSetOption();