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 || broken(res), /* <= w2k3 */
288 "InternetSetOptionA(INTERNET_OPTION_MAX_CONNS_PER_SERVER, 0) succeeded\n");
289 if (!res) ok(GetLastError() == ERROR_BAD_ARGUMENTS, "GetLastError() = %u\n", GetLastError());
292 res = InternetSetOptionA(NULL, INTERNET_OPTION_MAX_CONNS_PER_SERVER, &val, sizeof(val)-1);
293 ok(!res, "InternetSetOptionA(INTERNET_OPTION_MAX_CONNS_PER_SERVER) succeeded\n");
294 ok(GetLastError() == ERROR_INTERNET_BAD_OPTION_LENGTH, "GetLastError() = %u\n", GetLastError());
297 res = InternetSetOptionA(NULL, INTERNET_OPTION_MAX_CONNS_PER_SERVER, &val, sizeof(val)+1);
298 ok(!res, "InternetSetOptionA(INTERNET_OPTION_MAX_CONNS_PER_SERVER) succeeded\n");
299 ok(GetLastError() == ERROR_INTERNET_BAD_OPTION_LENGTH, "GetLastError() = %u\n", GetLastError());
302 static void test_get_cookie(void)
307 SetLastError(0xdeadbeef);
308 ret = InternetGetCookie("http://www.example.com", NULL, NULL, &len);
309 ok(!ret && GetLastError() == ERROR_NO_MORE_ITEMS,
310 "InternetGetCookie should have failed with %s and error %d\n",
311 ret ? "TRUE" : "FALSE", GetLastError());
315 static void test_complicated_cookie(void)
322 ret = InternetSetCookie("http://www.example.com/bar",NULL,"A=B; domain=.example.com");
323 ok(ret == TRUE,"InternetSetCookie failed\n");
324 ret = InternetSetCookie("http://www.example.com/bar",NULL,"C=D; domain=.example.com; path=/");
325 ok(ret == TRUE,"InternetSetCookie failed\n");
327 /* Technically illegal! domain should require 2 dots, but native wininet accepts it */
328 ret = InternetSetCookie("http://www.example.com",NULL,"E=F; domain=example.com");
329 ok(ret == TRUE,"InternetSetCookie failed\n");
330 ret = InternetSetCookie("http://www.example.com",NULL,"G=H; domain=.example.com; path=/foo");
331 ok(ret == TRUE,"InternetSetCookie failed\n");
332 ret = InternetSetCookie("http://www.example.com/bar.html",NULL,"I=J; domain=.example.com");
333 ok(ret == TRUE,"InternetSetCookie failed\n");
334 ret = InternetSetCookie("http://www.example.com/bar/",NULL,"K=L; domain=.example.com");
335 ok(ret == TRUE,"InternetSetCookie failed\n");
336 ret = InternetSetCookie("http://www.example.com/bar/",NULL,"M=N; domain=.example.com; path=/foo/");
337 ok(ret == TRUE,"InternetSetCookie failed\n");
338 ret = InternetSetCookie("http://www.example.com/bar/",NULL,"O=P; secure; path=/bar");
339 ok(ret == TRUE,"InternetSetCookie failed\n");
342 ret = InternetGetCookie("http://testing.example.com", NULL, buffer, &len);
343 ok(ret == TRUE,"InternetGetCookie failed\n");
344 ok(strstr(buffer,"A=B")!=NULL,"A=B missing\n");
345 ok(strstr(buffer,"C=D")!=NULL,"C=D missing\n");
346 ok(strstr(buffer,"E=F")!=NULL,"E=F missing\n");
347 ok(strstr(buffer,"G=H")==NULL,"G=H present\n");
348 ok(strstr(buffer,"I=J")!=NULL,"I=J missing\n");
349 ok(strstr(buffer,"K=L")==NULL,"K=L present\n");
350 ok(strstr(buffer,"M=N")==NULL,"M=N present\n");
351 ok(strstr(buffer,"O=P")==NULL,"O=P present\n");
354 ret = InternetGetCookie("http://testing.example.com/foobar", NULL, buffer, &len);
355 ok(ret == TRUE,"InternetGetCookie failed\n");
356 ok(strstr(buffer,"A=B")!=NULL,"A=B missing\n");
357 ok(strstr(buffer,"C=D")!=NULL,"C=D missing\n");
358 ok(strstr(buffer,"E=F")!=NULL,"E=F missing\n");
359 ok(strstr(buffer,"G=H")==NULL,"G=H present\n");
360 ok(strstr(buffer,"I=J")!=NULL,"I=J missing\n");
361 ok(strstr(buffer,"K=L")==NULL,"K=L present\n");
362 ok(strstr(buffer,"M=N")==NULL,"M=N present\n");
363 ok(strstr(buffer,"O=P")==NULL,"O=P present\n");
366 ret = InternetGetCookie("http://testing.example.com/foobar/", NULL, buffer, &len);
367 ok(ret == TRUE,"InternetGetCookie failed\n");
368 ok(strstr(buffer,"A=B")!=NULL,"A=B missing\n");
369 ok(strstr(buffer,"C=D")!=NULL,"C=D missing\n");
370 ok(strstr(buffer,"E=F")!=NULL,"E=F missing\n");
371 ok(strstr(buffer,"G=H")!=NULL,"G=H missing\n");
372 ok(strstr(buffer,"I=J")!=NULL,"I=J missing\n");
373 ok(strstr(buffer,"K=L")==NULL,"K=L present\n");
374 ok(strstr(buffer,"M=N")==NULL,"M=N present\n");
375 ok(strstr(buffer,"O=P")==NULL,"O=P present\n");
378 ret = InternetGetCookie("http://testing.example.com/foo/bar", NULL, buffer, &len);
379 ok(ret == TRUE,"InternetGetCookie failed\n");
380 ok(strstr(buffer,"A=B")!=NULL,"A=B missing\n");
381 ok(strstr(buffer,"C=D")!=NULL,"C=D missing\n");
382 ok(strstr(buffer,"E=F")!=NULL,"E=F missing\n");
383 ok(strstr(buffer,"G=H")!=NULL,"G=H missing\n");
384 ok(strstr(buffer,"I=J")!=NULL,"I=J missing\n");
385 ok(strstr(buffer,"K=L")==NULL,"K=L present\n");
386 ok(strstr(buffer,"M=N")!=NULL,"M=N missing\n");
387 ok(strstr(buffer,"O=P")==NULL,"O=P present\n");
390 ret = InternetGetCookie("http://testing.example.com/barfoo", NULL, buffer, &len);
391 ok(ret == TRUE,"InternetGetCookie failed\n");
392 ok(strstr(buffer,"A=B")!=NULL,"A=B missing\n");
393 ok(strstr(buffer,"C=D")!=NULL,"C=D missing\n");
394 ok(strstr(buffer,"E=F")!=NULL,"E=F missing\n");
395 ok(strstr(buffer,"G=H")==NULL,"G=H present\n");
396 ok(strstr(buffer,"I=J")!=NULL,"I=J missing\n");
397 ok(strstr(buffer,"K=L")==NULL,"K=L present\n");
398 ok(strstr(buffer,"M=N")==NULL,"M=N present\n");
399 ok(strstr(buffer,"O=P")==NULL,"O=P present\n");
402 ret = InternetGetCookie("http://testing.example.com/barfoo/", NULL, buffer, &len);
403 ok(ret == TRUE,"InternetGetCookie failed\n");
404 ok(strstr(buffer,"A=B")!=NULL,"A=B missing\n");
405 ok(strstr(buffer,"C=D")!=NULL,"C=D missing\n");
406 ok(strstr(buffer,"E=F")!=NULL,"E=F missing\n");
407 ok(strstr(buffer,"G=H")==NULL,"G=H present\n");
408 ok(strstr(buffer,"I=J")!=NULL,"I=J missing\n");
409 ok(strstr(buffer,"K=L")==NULL,"K=L present\n");
410 ok(strstr(buffer,"M=N")==NULL,"M=N present\n");
411 ok(strstr(buffer,"O=P")==NULL,"O=P present\n");
414 ret = InternetGetCookie("http://testing.example.com/bar/foo", NULL, buffer, &len);
415 ok(ret == TRUE,"InternetGetCookie failed\n");
416 ok(strstr(buffer,"A=B")!=NULL,"A=B missing\n");
417 ok(strstr(buffer,"C=D")!=NULL,"C=D missing\n");
418 ok(strstr(buffer,"E=F")!=NULL,"E=F missing\n");
419 ok(strstr(buffer,"G=H")==NULL,"G=H present\n");
420 ok(strstr(buffer,"I=J")!=NULL,"I=J missing\n");
421 ok(strstr(buffer,"K=L")!=NULL,"K=L missing\n");
422 ok(strstr(buffer,"M=N")==NULL,"M=N present\n");
423 ok(strstr(buffer,"O=P")==NULL,"O=P present\n");
426 static void test_null(void)
429 static const WCHAR szServer[] = { 's','e','r','v','e','r',0 };
430 static const WCHAR szEmpty[] = { 0 };
431 static const WCHAR szUrl[] = { 'h','t','t','p',':','/','/','a','.','b','.','c',0 };
432 static const WCHAR szUrlEmpty[] = { 'h','t','t','p',':','/','/',0 };
433 static const WCHAR szExpect[] = { 's','e','r','v','e','r',';',' ','s','e','r','v','e','r',0 };
438 SetLastError(0xdeadbeef);
439 hi = InternetOpenW(NULL, 0, NULL, NULL, 0);
440 if (hi == NULL && GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)
442 win_skip("Internet*W functions are not implemented\n");
445 ok(hi != NULL, "open failed\n");
447 hc = InternetConnectW(hi, NULL, 0, NULL, NULL, 0, 0, 0);
448 ok(GetLastError() == ERROR_INVALID_PARAMETER, "wrong error\n");
449 ok(hc == NULL, "connect failed\n");
451 hc = InternetConnectW(hi, NULL, 0, NULL, NULL, INTERNET_SERVICE_HTTP, 0, 0);
452 ok(GetLastError() == ERROR_INVALID_PARAMETER, "wrong error\n");
453 ok(hc == NULL, "connect failed\n");
455 hc = InternetConnectW(hi, NULL, 0, NULL, NULL, INTERNET_SERVICE_FTP, 0, 0);
456 ok(GetLastError() == ERROR_INVALID_PARAMETER, "wrong error\n");
457 ok(hc == NULL, "connect failed\n");
459 hc = InternetConnectW(NULL, szServer, 0, NULL, NULL, INTERNET_SERVICE_FTP, 0, 0);
460 ok(GetLastError() == ERROR_INVALID_HANDLE, "wrong error\n");
461 ok(hc == NULL, "connect failed\n");
463 hc = InternetOpenUrlW(hi, NULL, NULL, 0, 0, 0);
464 ok(GetLastError() == ERROR_INVALID_PARAMETER ||
465 GetLastError() == ERROR_INTERNET_UNRECOGNIZED_SCHEME, "wrong error\n");
466 ok(hc == NULL, "connect failed\n");
468 hc = InternetOpenUrlW(hi, szServer, NULL, 0, 0, 0);
469 ok(GetLastError() == ERROR_INTERNET_UNRECOGNIZED_SCHEME, "wrong error\n");
470 ok(hc == NULL, "connect failed\n");
472 InternetCloseHandle(hi);
474 r = InternetSetCookieW(NULL, NULL, NULL);
475 ok(GetLastError() == ERROR_INVALID_PARAMETER, "wrong error\n");
476 ok(r == FALSE, "return wrong\n");
478 r = InternetSetCookieW(szServer, NULL, NULL);
479 ok(GetLastError() == ERROR_INVALID_PARAMETER, "wrong error\n");
480 ok(r == FALSE, "return wrong\n");
482 r = InternetSetCookieW(szUrl, szServer, NULL);
483 ok(GetLastError() == ERROR_INVALID_PARAMETER, "wrong error\n");
484 ok(r == FALSE, "return wrong\n");
486 r = InternetSetCookieW(szUrl, szServer, szServer);
487 ok(r == TRUE, "return wrong\n");
489 r = InternetSetCookieW(szUrl, NULL, szServer);
490 ok(r == TRUE, "return wrong\n");
492 r = InternetSetCookieW(szUrl, szServer, szEmpty);
493 ok(r == TRUE, "return wrong\n");
495 r = InternetSetCookieW(szUrlEmpty, szServer, szServer);
496 ok(r == FALSE, "return wrong\n");
498 r = InternetSetCookieW(szServer, NULL, szServer);
500 ok(GetLastError() == ERROR_INTERNET_UNRECOGNIZED_SCHEME, "wrong error\n");
502 ok(r == FALSE, "return wrong\n");
505 r = InternetGetCookieW(NULL, NULL, NULL, &sz);
506 ok(GetLastError() == ERROR_INVALID_PARAMETER || GetLastError() == ERROR_INTERNET_UNRECOGNIZED_SCHEME,
507 "wrong error %u\n", GetLastError());
508 ok( r == FALSE, "return wrong\n");
510 r = InternetGetCookieW(szServer, NULL, NULL, &sz);
512 ok(GetLastError() == ERROR_INTERNET_UNRECOGNIZED_SCHEME, "wrong error\n");
514 ok( r == FALSE, "return wrong\n");
517 r = InternetGetCookieW(szUrlEmpty, szServer, NULL, &sz);
518 ok( r == FALSE, "return wrong\n");
521 r = InternetGetCookieW(szUrl, szServer, NULL, &sz);
522 ok( r == TRUE, "return wrong\n");
524 /* sz is 14 on XP SP2 and beyond, 30 on XP SP1 and before */
525 ok( sz == 14 || sz == 30, "sz wrong, got %u, expected 14 or 30\n", sz);
528 memset(buffer, 0, sizeof buffer);
529 r = InternetGetCookieW(szUrl, szServer, buffer, &sz);
530 ok( r == TRUE, "return wrong\n");
532 /* sz == lstrlenW(buffer) only in XP SP1 */
533 ok( sz == 1 + lstrlenW(buffer) || sz == lstrlenW(buffer), "sz wrong %d\n", sz);
535 /* before XP SP2, buffer is "server; server" */
536 ok( !lstrcmpW(szExpect, buffer) || !lstrcmpW(szServer, buffer), "cookie data wrong\n");
539 r = InternetQueryOptionA(NULL, INTERNET_OPTION_CONNECTED_STATE, buffer, &sz);
540 ok(r == TRUE, "ret %d\n", r);
543 static void test_version(void)
545 INTERNET_VERSION_INFO version;
549 size = sizeof(version);
550 res = InternetQueryOptionA(NULL, INTERNET_OPTION_VERSION, &version, &size);
551 ok(res, "Could not get version: %u\n", GetLastError());
552 ok(version.dwMajorVersion == 1, "dwMajorVersion=%d, expected 1\n", version.dwMajorVersion);
553 ok(version.dwMinorVersion == 2, "dwMinorVersion=%d, expected 2\n", version.dwMinorVersion);
556 static void InternetTimeFromSystemTimeA_test(void)
559 static const SYSTEMTIME time = { 2005, 1, 5, 7, 12, 6, 35, 0 };
560 char string[INTERNET_RFC1123_BUFSIZE];
561 static const char expect[] = "Fri, 07 Jan 2005 12:06:35 GMT";
564 ret = pInternetTimeFromSystemTimeA( &time, INTERNET_RFC1123_FORMAT, string, sizeof(string) );
565 ok( ret, "InternetTimeFromSystemTimeA failed (%u)\n", GetLastError() );
567 ok( !memcmp( string, expect, sizeof(expect) ),
568 "InternetTimeFromSystemTimeA failed (%u)\n", GetLastError() );
570 /* test NULL time parameter */
571 SetLastError(0xdeadbeef);
572 ret = pInternetTimeFromSystemTimeA( NULL, INTERNET_RFC1123_FORMAT, string, sizeof(string) );
573 error = GetLastError();
574 ok( !ret, "InternetTimeFromSystemTimeA should have returned FALSE\n" );
575 ok( error == ERROR_INVALID_PARAMETER,
576 "InternetTimeFromSystemTimeA failed with ERROR_INVALID_PARAMETER instead of %u\n",
579 /* test NULL string parameter */
580 SetLastError(0xdeadbeef);
581 ret = pInternetTimeFromSystemTimeA( &time, INTERNET_RFC1123_FORMAT, NULL, sizeof(string) );
582 error = GetLastError();
583 ok( !ret, "InternetTimeFromSystemTimeA should have returned FALSE\n" );
584 ok( error == ERROR_INVALID_PARAMETER,
585 "InternetTimeFromSystemTimeA failed with ERROR_INVALID_PARAMETER instead of %u\n",
588 /* test invalid format parameter */
589 SetLastError(0xdeadbeef);
590 ret = pInternetTimeFromSystemTimeA( &time, INTERNET_RFC1123_FORMAT + 1, string, sizeof(string) );
591 error = GetLastError();
592 ok( !ret, "InternetTimeFromSystemTimeA should have returned FALSE\n" );
593 ok( error == ERROR_INVALID_PARAMETER,
594 "InternetTimeFromSystemTimeA failed with ERROR_INVALID_PARAMETER instead of %u\n",
597 /* test too small buffer size */
598 SetLastError(0xdeadbeef);
599 ret = pInternetTimeFromSystemTimeA( &time, INTERNET_RFC1123_FORMAT, string, 0 );
600 error = GetLastError();
601 ok( !ret, "InternetTimeFromSystemTimeA should have returned FALSE\n" );
602 ok( error == ERROR_INSUFFICIENT_BUFFER,
603 "InternetTimeFromSystemTimeA failed with ERROR_INSUFFICIENT_BUFFER instead of %u\n",
607 static void InternetTimeFromSystemTimeW_test(void)
610 static const SYSTEMTIME time = { 2005, 1, 5, 7, 12, 6, 35, 0 };
611 WCHAR string[INTERNET_RFC1123_BUFSIZE + 1];
612 static const WCHAR expect[] = { 'F','r','i',',',' ','0','7',' ','J','a','n',' ','2','0','0','5',' ',
613 '1','2',':','0','6',':','3','5',' ','G','M','T',0 };
616 ret = pInternetTimeFromSystemTimeW( &time, INTERNET_RFC1123_FORMAT, string, sizeof(string) );
617 ok( ret, "InternetTimeFromSystemTimeW failed (%u)\n", GetLastError() );
619 ok( !memcmp( string, expect, sizeof(expect) ),
620 "InternetTimeFromSystemTimeW failed (%u)\n", GetLastError() );
622 /* test NULL time parameter */
623 SetLastError(0xdeadbeef);
624 ret = pInternetTimeFromSystemTimeW( NULL, INTERNET_RFC1123_FORMAT, string, sizeof(string) );
625 error = GetLastError();
626 ok( !ret, "InternetTimeFromSystemTimeW should have returned FALSE\n" );
627 ok( error == ERROR_INVALID_PARAMETER,
628 "InternetTimeFromSystemTimeW failed with ERROR_INVALID_PARAMETER instead of %u\n",
631 /* test NULL string parameter */
632 SetLastError(0xdeadbeef);
633 ret = pInternetTimeFromSystemTimeW( &time, INTERNET_RFC1123_FORMAT, NULL, sizeof(string) );
634 error = GetLastError();
635 ok( !ret, "InternetTimeFromSystemTimeW should have returned FALSE\n" );
636 ok( error == ERROR_INVALID_PARAMETER,
637 "InternetTimeFromSystemTimeW failed with ERROR_INVALID_PARAMETER instead of %u\n",
640 /* test invalid format parameter */
641 SetLastError(0xdeadbeef);
642 ret = pInternetTimeFromSystemTimeW( &time, INTERNET_RFC1123_FORMAT + 1, string, sizeof(string) );
643 error = GetLastError();
644 ok( !ret, "InternetTimeFromSystemTimeW should have returned FALSE\n" );
645 ok( error == ERROR_INVALID_PARAMETER,
646 "InternetTimeFromSystemTimeW failed with ERROR_INVALID_PARAMETER instead of %u\n",
649 /* test too small buffer size */
650 SetLastError(0xdeadbeef);
651 ret = pInternetTimeFromSystemTimeW( &time, INTERNET_RFC1123_FORMAT, string, sizeof(string)/sizeof(string[0]) );
652 error = GetLastError();
653 ok( !ret, "InternetTimeFromSystemTimeW should have returned FALSE\n" );
654 ok( error == ERROR_INSUFFICIENT_BUFFER,
655 "InternetTimeFromSystemTimeW failed with ERROR_INSUFFICIENT_BUFFER instead of %u\n",
659 static void InternetTimeToSystemTimeA_test(void)
663 static const SYSTEMTIME expect = { 2005, 1, 5, 7, 12, 6, 35, 0 };
664 static const char string[] = "Fri, 07 Jan 2005 12:06:35 GMT";
665 static const char string2[] = " fri 7 jan 2005 12 06 35";
667 ret = pInternetTimeToSystemTimeA( string, &time, 0 );
668 ok( ret, "InternetTimeToSystemTimeA failed (%u)\n", GetLastError() );
669 ok( !memcmp( &time, &expect, sizeof(expect) ),
670 "InternetTimeToSystemTimeA failed (%u)\n", GetLastError() );
672 ret = pInternetTimeToSystemTimeA( string2, &time, 0 );
673 ok( ret, "InternetTimeToSystemTimeA failed (%u)\n", GetLastError() );
674 ok( !memcmp( &time, &expect, sizeof(expect) ),
675 "InternetTimeToSystemTimeA failed (%u)\n", GetLastError() );
678 static void InternetTimeToSystemTimeW_test(void)
682 static const SYSTEMTIME expect = { 2005, 1, 5, 7, 12, 6, 35, 0 };
683 static const WCHAR string[] = { 'F','r','i',',',' ','0','7',' ','J','a','n',' ','2','0','0','5',' ',
684 '1','2',':','0','6',':','3','5',' ','G','M','T',0 };
685 static const WCHAR string2[] = { ' ','f','r','i',' ','7',' ','j','a','n',' ','2','0','0','5',' ',
686 '1','2',' ','0','6',' ','3','5',0 };
687 static const WCHAR string3[] = { 'F','r',0 };
689 ret = pInternetTimeToSystemTimeW( NULL, NULL, 0 );
690 ok( !ret, "InternetTimeToSystemTimeW succeeded (%u)\n", GetLastError() );
692 ret = pInternetTimeToSystemTimeW( NULL, &time, 0 );
693 ok( !ret, "InternetTimeToSystemTimeW succeeded (%u)\n", GetLastError() );
695 ret = pInternetTimeToSystemTimeW( string, NULL, 0 );
696 ok( !ret, "InternetTimeToSystemTimeW succeeded (%u)\n", GetLastError() );
698 ret = pInternetTimeToSystemTimeW( string, &time, 0 );
699 ok( ret, "InternetTimeToSystemTimeW failed (%u)\n", GetLastError() );
701 ret = pInternetTimeToSystemTimeW( string, &time, 0 );
702 ok( ret, "InternetTimeToSystemTimeW failed (%u)\n", GetLastError() );
703 ok( !memcmp( &time, &expect, sizeof(expect) ),
704 "InternetTimeToSystemTimeW failed (%u)\n", GetLastError() );
706 ret = pInternetTimeToSystemTimeW( string2, &time, 0 );
707 ok( ret, "InternetTimeToSystemTimeW failed (%u)\n", GetLastError() );
708 ok( !memcmp( &time, &expect, sizeof(expect) ),
709 "InternetTimeToSystemTimeW failed (%u)\n", GetLastError() );
711 ret = pInternetTimeToSystemTimeW( string3, &time, 0 );
712 ok( ret, "InternetTimeToSystemTimeW failed (%u)\n", GetLastError() );
715 static void test_IsDomainLegalCookieDomainW(void)
719 static const WCHAR empty[] = {0};
720 static const WCHAR dot[] = {'.',0};
721 static const WCHAR uk[] = {'u','k',0};
722 static const WCHAR com[] = {'c','o','m',0};
723 static const WCHAR dot_com[] = {'.','c','o','m',0};
724 static const WCHAR gmail_com[] = {'g','m','a','i','l','.','c','o','m',0};
725 static const WCHAR dot_gmail_com[] = {'.','g','m','a','i','l','.','c','o','m',0};
726 static const WCHAR mail_gmail_com[] = {'m','a','i','l','.','g','m','a','i','l','.','c','o','m',0};
727 static const WCHAR gmail_co_uk[] = {'g','m','a','i','l','.','c','o','.','u','k',0};
728 static const WCHAR co_uk[] = {'c','o','.','u','k',0};
729 static const WCHAR dot_co_uk[] = {'.','c','o','.','u','k',0};
731 SetLastError(0xdeadbeef);
732 ret = pIsDomainLegalCookieDomainW(NULL, NULL);
733 error = GetLastError();
734 if (!ret && error == ERROR_CALL_NOT_IMPLEMENTED)
736 win_skip("IsDomainLegalCookieDomainW is not implemented\n");
740 broken(ret), /* IE6 */
741 "IsDomainLegalCookieDomainW succeeded\n");
742 ok(error == ERROR_INVALID_PARAMETER, "got %u expected ERROR_INVALID_PARAMETER\n", error);
744 SetLastError(0xdeadbeef);
745 ret = pIsDomainLegalCookieDomainW(com, NULL);
746 error = GetLastError();
747 ok(!ret, "IsDomainLegalCookieDomainW succeeded\n");
748 ok(error == ERROR_INVALID_PARAMETER, "got %u expected ERROR_INVALID_PARAMETER\n", error);
750 SetLastError(0xdeadbeef);
751 ret = pIsDomainLegalCookieDomainW(NULL, gmail_com);
752 error = GetLastError();
753 ok(!ret, "IsDomainLegalCookieDomainW succeeded\n");
754 ok(error == ERROR_INVALID_PARAMETER, "got %u expected ERROR_INVALID_PARAMETER\n", error);
756 SetLastError(0xdeadbeef);
757 ret = pIsDomainLegalCookieDomainW(empty, gmail_com);
758 error = GetLastError();
759 ok(!ret, "IsDomainLegalCookieDomainW succeeded\n");
760 ok(error == ERROR_INVALID_NAME ||
761 broken(error == ERROR_INVALID_PARAMETER), /* IE6 */
762 "got %u expected ERROR_INVALID_NAME\n", error);
764 SetLastError(0xdeadbeef);
765 ret = pIsDomainLegalCookieDomainW(com, empty);
766 error = GetLastError();
767 ok(!ret, "IsDomainLegalCookieDomainW succeeded\n");
768 ok(error == ERROR_INVALID_NAME ||
769 broken(error == ERROR_INVALID_PARAMETER), /* IE6 */
770 "got %u expected ERROR_INVALID_NAME\n", error);
772 SetLastError(0xdeadbeef);
773 ret = pIsDomainLegalCookieDomainW(gmail_com, dot);
774 error = GetLastError();
775 ok(!ret, "IsDomainLegalCookieDomainW succeeded\n");
776 ok(error == ERROR_INVALID_NAME ||
777 broken(error == 0xdeadbeef), /* IE6 */
778 "got %u expected ERROR_INVALID_NAME\n", error);
780 SetLastError(0xdeadbeef);
781 ret = pIsDomainLegalCookieDomainW(dot, gmail_com);
782 error = GetLastError();
783 ok(!ret, "IsDomainLegalCookieDomainW succeeded\n");
784 ok(error == ERROR_INVALID_NAME ||
785 broken(error == 0xdeadbeef), /* IE6 */
786 "got %u expected ERROR_INVALID_NAME\n", error);
788 SetLastError(0xdeadbeef);
789 ret = pIsDomainLegalCookieDomainW(com, com);
790 error = GetLastError();
791 ok(!ret, "IsDomainLegalCookieDomainW succeeded\n");
792 ok(error == 0xdeadbeef, "got %u expected 0xdeadbeef\n", error);
794 SetLastError(0xdeadbeef);
795 ret = pIsDomainLegalCookieDomainW(com, dot_com);
796 error = GetLastError();
797 ok(!ret, "IsDomainLegalCookieDomainW succeeded\n");
798 ok(error == ERROR_INVALID_NAME ||
799 broken(error == 0xdeadbeef), /* IE6 */
800 "got %u expected ERROR_INVALID_NAME\n", error);
802 SetLastError(0xdeadbeef);
803 ret = pIsDomainLegalCookieDomainW(dot_com, com);
804 error = GetLastError();
805 ok(!ret, "IsDomainLegalCookieDomainW succeeded\n");
806 ok(error == ERROR_INVALID_NAME ||
807 broken(error == 0xdeadbeef), /* IE6 */
808 "got %u expected ERROR_INVALID_NAME\n", error);
810 SetLastError(0xdeadbeef);
811 ret = pIsDomainLegalCookieDomainW(com, gmail_com);
812 error = GetLastError();
813 ok(!ret, "IsDomainLegalCookieDomainW succeeded\n");
814 ok(error == ERROR_SXS_KEY_NOT_FOUND ||
815 error == ERROR_SUCCESS || /* IE8 on W2K3 */
816 error == 0xdeadbeef, /* up to IE7 */
817 "unexpected error: %u\n", error);
819 ret = pIsDomainLegalCookieDomainW(gmail_com, gmail_com);
820 ok(ret, "IsDomainLegalCookieDomainW failed\n");
822 SetLastError(0xdeadbeef);
823 ret = pIsDomainLegalCookieDomainW(gmail_co_uk, co_uk);
824 error = GetLastError();
825 ok(!ret, "IsDomainLegalCookieDomainW succeeded\n");
826 ok(error == ERROR_SXS_KEY_NOT_FOUND || /* IE8 on XP */
827 error == ERROR_FILE_NOT_FOUND || /* IE8 on Vista */
828 error == ERROR_SUCCESS || /* IE8 on W2K3 */
829 error == 0xdeadbeef, /* up to IE7 */
830 "unexpected error: %u\n", error);
832 ret = pIsDomainLegalCookieDomainW(uk, co_uk);
833 ok(!ret, "IsDomainLegalCookieDomainW succeeded\n");
835 ret = pIsDomainLegalCookieDomainW(gmail_co_uk, dot_co_uk);
836 ok(!ret, "IsDomainLegalCookieDomainW succeeded\n");
838 ret = pIsDomainLegalCookieDomainW(gmail_co_uk, gmail_co_uk);
839 ok(ret, "IsDomainLegalCookieDomainW failed\n");
841 ret = pIsDomainLegalCookieDomainW(gmail_com, com);
842 ok(!ret, "IsDomainLegalCookieDomainW succeeded\n");
844 SetLastError(0xdeadbeef);
845 ret = pIsDomainLegalCookieDomainW(dot_gmail_com, mail_gmail_com);
846 error = GetLastError();
847 ok(!ret, "IsDomainLegalCookieDomainW succeeded\n");
848 ok(error == ERROR_INVALID_NAME ||
849 broken(error == 0xdeadbeef), /* IE6 */
850 "got %u expected ERROR_INVALID_NAME\n", error);
852 ret = pIsDomainLegalCookieDomainW(gmail_com, mail_gmail_com);
853 ok(ret, "IsDomainLegalCookieDomainW failed\n");
855 ret = pIsDomainLegalCookieDomainW(mail_gmail_com, gmail_com);
856 ok(!ret, "IsDomainLegalCookieDomainW succeeded\n");
858 ret = pIsDomainLegalCookieDomainW(mail_gmail_com, com);
859 ok(!ret, "IsDomainLegalCookieDomainW succeeded\n");
861 ret = pIsDomainLegalCookieDomainW(dot_gmail_com, mail_gmail_com);
862 ok(!ret, "IsDomainLegalCookieDomainW succeeded\n");
864 ret = pIsDomainLegalCookieDomainW(mail_gmail_com, dot_gmail_com);
865 ok(!ret, "IsDomainLegalCookieDomainW succeeded\n");
868 static void test_PrivacyGetSetZonePreferenceW(void)
870 DWORD ret, zone, type, template, old_template;
874 ret = pPrivacyGetZonePreferenceW(zone, type, NULL, NULL, NULL);
875 ok(ret == 0, "expected ret == 0, got %u\n", ret);
878 ret = pPrivacyGetZonePreferenceW(zone, type, &old_template, NULL, NULL);
879 ok(ret == 0, "expected ret == 0, got %u\n", ret);
882 ret = pPrivacySetZonePreferenceW(zone, type, template, NULL);
883 ok(ret == 0, "expected ret == 0, got %u\n", ret);
886 ret = pPrivacyGetZonePreferenceW(zone, type, &template, NULL, NULL);
887 ok(ret == 0, "expected ret == 0, got %u\n", ret);
888 ok(template == 5, "expected template == 5, got %u\n", template);
891 ret = pPrivacySetZonePreferenceW(zone, type, old_template, NULL);
892 ok(ret == 0, "expected ret == 0, got %u\n", ret);
895 static void test_InternetSetOption(void)
897 HINTERNET ses, con, req;
902 ses = InternetOpen(NULL, INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, 0);
903 ok(ses != 0, "InternetOpen failed: 0x%08x\n", GetLastError());
904 con = InternetConnect(ses, "www.winehq.org", 80, NULL, NULL, INTERNET_SERVICE_HTTP, 0, 0);
905 ok(con != 0, "InternetConnect failed: 0x%08x\n", GetLastError());
906 req = HttpOpenRequest(con, "GET", "/", NULL, NULL, NULL, 0, 0);
907 ok(req != 0, "HttpOpenRequest failed: 0x%08x\n", GetLastError());
909 /* INTERNET_OPTION_POLICY tests */
910 SetLastError(0xdeadbeef);
911 ret = InternetSetOptionW(ses, INTERNET_OPTION_POLICY, NULL, 0);
912 ok(ret == FALSE, "InternetSetOption should've failed\n");
913 ok(GetLastError() == ERROR_INVALID_PARAMETER, "GetLastError should've "
914 "given ERROR_INVALID_PARAMETER, gave: 0x%08x\n", GetLastError());
916 SetLastError(0xdeadbeef);
917 ret = InternetQueryOptionW(ses, INTERNET_OPTION_POLICY, NULL, 0);
918 ok(ret == FALSE, "InternetQueryOption should've failed\n");
919 ok(GetLastError() == ERROR_INVALID_PARAMETER, "GetLastError should've "
920 "given ERROR_INVALID_PARAMETER, gave: 0x%08x\n", GetLastError());
922 /* INTERNET_OPTION_ERROR_MASK tests */
923 SetLastError(0xdeadbeef);
924 size = sizeof(ulArg);
925 ret = InternetQueryOptionW(NULL, INTERNET_OPTION_ERROR_MASK, (void*)&ulArg, &size);
926 ok(ret == FALSE, "InternetQueryOption should've failed\n");
927 ok(GetLastError() == ERROR_INTERNET_INCORRECT_HANDLE_TYPE, "GetLastError() = %x\n", GetLastError());
929 SetLastError(0xdeadbeef);
931 ret = InternetSetOption(NULL, INTERNET_OPTION_ERROR_MASK, (void*)&ulArg, sizeof(ULONG));
932 ok(ret == FALSE, "InternetQueryOption should've failed\n");
933 ok(GetLastError() == ERROR_INTERNET_INCORRECT_HANDLE_TYPE, "GetLastError() = %x\n", GetLastError());
935 SetLastError(0xdeadbeef);
937 ret = InternetSetOption(req, INTERNET_OPTION_ERROR_MASK, (void*)&ulArg, 20);
938 ok(ret == FALSE, "InternetQueryOption should've failed\n");
939 ok(GetLastError() == ERROR_INTERNET_BAD_OPTION_LENGTH, "GetLastError() = %d\n", GetLastError());
941 SetLastError(0xdeadbeef);
943 ret = InternetSetOption(req, INTERNET_OPTION_ERROR_MASK, (void*)&ulArg, sizeof(ULONG));
944 ok(ret == TRUE, "InternetQueryOption should've succeeded\n");
945 ok(GetLastError() == 0xdeadbeef, "GetLastError() = %d\n", GetLastError());
947 SetLastError(0xdeadbeef);
949 ret = InternetSetOption(req, INTERNET_OPTION_ERROR_MASK, (void*)&ulArg, sizeof(ULONG));
950 ok(ret == FALSE, "InternetQueryOption should've failed\n");
951 ok(GetLastError() == ERROR_INVALID_PARAMETER, "GetLastError() = %x\n", GetLastError());
953 SetLastError(0xdeadbeef);
955 ret = InternetSetOption(req, INTERNET_OPTION_ERROR_MASK, (void*)&ulArg, sizeof(ULONG));
956 ok(ret == FALSE, "InternetQueryOption should've failed\n");
957 ok(GetLastError() == ERROR_INVALID_PARAMETER, "GetLastError() = %x\n", GetLastError());
959 ret = InternetCloseHandle(req);
960 ok(ret == TRUE, "InternetCloseHandle failed: 0x%08x\n", GetLastError());
961 ret = InternetCloseHandle(con);
962 ok(ret == TRUE, "InternetCloseHandle failed: 0x%08x\n", GetLastError());
963 ret = InternetCloseHandle(ses);
964 ok(ret == TRUE, "InternetCloseHandle failed: 0x%08x\n", GetLastError());
967 #define verifyProxyEnable(e) r_verifyProxyEnable(__LINE__, e)
968 static void r_verifyProxyEnable(LONG l, DWORD exp)
971 DWORD type, val, size = sizeof(DWORD);
973 static const CHAR szInternetSettings[] = "Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings";
974 static const CHAR szProxyEnable[] = "ProxyEnable";
976 ret = RegOpenKeyA(HKEY_CURRENT_USER, szInternetSettings, &hkey);
977 ok_(__FILE__,l) (!ret, "RegOpenKeyA failed: 0x%08x\n", ret);
979 ret = RegQueryValueExA(hkey, szProxyEnable, 0, &type, (BYTE*)&val, &size);
980 ok_(__FILE__,l) (!ret, "RegQueryValueExA failed: 0x%08x\n", ret);
981 ok_(__FILE__,l) (type == REG_DWORD, "Expected regtype to be REG_DWORD, was: %d\n", type);
982 ok_(__FILE__,l) (val == exp, "Expected ProxyEnabled to be %d, got: %d\n", exp, val);
984 ret = RegCloseKey(hkey);
985 ok_(__FILE__,l) (!ret, "RegCloseKey failed: 0x%08x\n", ret);
988 static void test_Option_PerConnectionOption(void)
991 DWORD size = sizeof(INTERNET_PER_CONN_OPTION_LISTW);
992 INTERNET_PER_CONN_OPTION_LISTW list = {size};
993 INTERNET_PER_CONN_OPTIONW *orig_settings;
994 static WCHAR proxy_srvW[] = {'p','r','o','x','y','.','e','x','a','m','p','l','e',0};
996 /* get the global IE proxy server info, to restore later */
997 list.dwOptionCount = 2;
998 list.pOptions = HeapAlloc(GetProcessHeap(), 0, 2 * sizeof(INTERNET_PER_CONN_OPTIONW));
1000 list.pOptions[0].dwOption = INTERNET_PER_CONN_PROXY_SERVER;
1001 list.pOptions[1].dwOption = INTERNET_PER_CONN_FLAGS;
1003 ret = InternetQueryOptionW(NULL, INTERNET_OPTION_PER_CONNECTION_OPTION,
1005 ok(ret == TRUE, "InternetQueryOption should've succeeded\n");
1006 orig_settings = list.pOptions;
1008 /* set the global IE proxy server */
1009 list.dwOptionCount = 2;
1010 list.pOptions = HeapAlloc(GetProcessHeap(), 0, 2 * sizeof(INTERNET_PER_CONN_OPTIONW));
1012 list.pOptions[0].dwOption = INTERNET_PER_CONN_PROXY_SERVER;
1013 list.pOptions[0].Value.pszValue = proxy_srvW;
1014 list.pOptions[1].dwOption = INTERNET_PER_CONN_FLAGS;
1015 list.pOptions[1].Value.dwValue = PROXY_TYPE_PROXY;
1017 ret = InternetSetOptionW(NULL, INTERNET_OPTION_PER_CONNECTION_OPTION,
1019 ok(ret == TRUE, "InternetSetOption should've succeeded\n");
1021 HeapFree(GetProcessHeap(), 0, list.pOptions);
1023 /* get & verify the global IE proxy server */
1024 list.dwOptionCount = 2;
1025 list.dwOptionError = 0;
1026 list.pOptions = HeapAlloc(GetProcessHeap(), 0, 2 * sizeof(INTERNET_PER_CONN_OPTIONW));
1028 list.pOptions[0].dwOption = INTERNET_PER_CONN_PROXY_SERVER;
1029 list.pOptions[1].dwOption = INTERNET_PER_CONN_FLAGS;
1031 ret = InternetQueryOptionW(NULL, INTERNET_OPTION_PER_CONNECTION_OPTION,
1033 ok(ret == TRUE, "InternetQueryOption should've succeeded\n");
1034 ok(!lstrcmpW(list.pOptions[0].Value.pszValue, proxy_srvW),
1035 "Retrieved proxy server should've been %s, was: %s\n",
1036 wine_dbgstr_w(proxy_srvW), wine_dbgstr_w(list.pOptions[0].Value.pszValue));
1037 ok(list.pOptions[1].Value.dwValue == PROXY_TYPE_PROXY,
1038 "Retrieved flags should've been PROXY_TYPE_PROXY, was: %d\n",
1039 list.pOptions[1].Value.dwValue);
1040 verifyProxyEnable(1);
1042 HeapFree(GetProcessHeap(), 0, list.pOptions[0].Value.pszValue);
1043 HeapFree(GetProcessHeap(), 0, list.pOptions);
1045 /* disable the proxy server */
1046 list.dwOptionCount = 1;
1047 list.pOptions = HeapAlloc(GetProcessHeap(), 0, sizeof(INTERNET_PER_CONN_OPTIONW));
1049 list.pOptions[0].dwOption = INTERNET_PER_CONN_FLAGS;
1050 list.pOptions[0].Value.dwValue = PROXY_TYPE_DIRECT;
1052 ret = InternetSetOptionW(NULL, INTERNET_OPTION_PER_CONNECTION_OPTION,
1054 ok(ret == TRUE, "InternetSetOption should've succeeded\n");
1056 HeapFree(GetProcessHeap(), 0, list.pOptions);
1058 /* verify that the proxy is disabled */
1059 list.dwOptionCount = 1;
1060 list.dwOptionError = 0;
1061 list.pOptions = HeapAlloc(GetProcessHeap(), 0, sizeof(INTERNET_PER_CONN_OPTIONW));
1063 list.pOptions[0].dwOption = INTERNET_PER_CONN_FLAGS;
1065 ret = InternetQueryOptionW(NULL, INTERNET_OPTION_PER_CONNECTION_OPTION,
1067 ok(ret == TRUE, "InternetQueryOption should've succeeded\n");
1068 ok(list.pOptions[0].Value.dwValue == PROXY_TYPE_DIRECT,
1069 "Retrieved flags should've been PROXY_TYPE_DIRECT, was: %d\n",
1070 list.pOptions[0].Value.dwValue);
1071 verifyProxyEnable(0);
1073 HeapFree(GetProcessHeap(), 0, list.pOptions);
1075 /* set the proxy flags to 'invalid' value */
1076 list.dwOptionCount = 1;
1077 list.pOptions = HeapAlloc(GetProcessHeap(), 0, sizeof(INTERNET_PER_CONN_OPTIONW));
1079 list.pOptions[0].dwOption = INTERNET_PER_CONN_FLAGS;
1080 list.pOptions[0].Value.dwValue = PROXY_TYPE_PROXY | PROXY_TYPE_DIRECT;
1082 ret = InternetSetOptionW(NULL, INTERNET_OPTION_PER_CONNECTION_OPTION,
1084 ok(ret == TRUE, "InternetSetOption should've succeeded\n");
1086 HeapFree(GetProcessHeap(), 0, list.pOptions);
1088 /* verify that the proxy is enabled */
1089 list.dwOptionCount = 1;
1090 list.dwOptionError = 0;
1091 list.pOptions = HeapAlloc(GetProcessHeap(), 0, sizeof(INTERNET_PER_CONN_OPTIONW));
1093 list.pOptions[0].dwOption = INTERNET_PER_CONN_FLAGS;
1095 ret = InternetQueryOptionW(NULL, INTERNET_OPTION_PER_CONNECTION_OPTION,
1097 ok(ret == TRUE, "InternetQueryOption should've succeeded\n");
1098 todo_wine ok(list.pOptions[0].Value.dwValue == (PROXY_TYPE_PROXY | PROXY_TYPE_DIRECT),
1099 "Retrieved flags should've been PROXY_TYPE_PROXY | PROXY_TYPE_DIRECT, was: %d\n",
1100 list.pOptions[0].Value.dwValue);
1101 verifyProxyEnable(1);
1103 HeapFree(GetProcessHeap(), 0, list.pOptions);
1105 /* restore original settings */
1106 list.dwOptionCount = 2;
1107 list.pOptions = orig_settings;
1109 ret = InternetSetOptionW(NULL, INTERNET_OPTION_PER_CONNECTION_OPTION,
1111 ok(ret == TRUE, "InternetSetOption should've succeeded\n");
1113 HeapFree(GetProcessHeap(), 0, list.pOptions);
1116 static void test_Option_PerConnectionOptionA(void)
1119 DWORD size = sizeof(INTERNET_PER_CONN_OPTION_LISTA);
1120 INTERNET_PER_CONN_OPTION_LISTA list = {size};
1121 INTERNET_PER_CONN_OPTIONA *orig_settings;
1122 char proxy_srv[] = "proxy.example";
1124 /* get the global IE proxy server info, to restore later */
1125 list.dwOptionCount = 2;
1126 list.pOptions = HeapAlloc(GetProcessHeap(), 0, 2 * sizeof(INTERNET_PER_CONN_OPTIONA));
1128 list.pOptions[0].dwOption = INTERNET_PER_CONN_PROXY_SERVER;
1129 list.pOptions[1].dwOption = INTERNET_PER_CONN_FLAGS;
1131 ret = InternetQueryOptionA(NULL, INTERNET_OPTION_PER_CONNECTION_OPTION,
1133 ok(ret == TRUE, "InternetQueryOption should've succeeded\n");
1134 orig_settings = list.pOptions;
1136 /* set the global IE proxy server */
1137 list.dwOptionCount = 2;
1138 list.pOptions = HeapAlloc(GetProcessHeap(), 0, 2 * sizeof(INTERNET_PER_CONN_OPTIONA));
1140 list.pOptions[0].dwOption = INTERNET_PER_CONN_PROXY_SERVER;
1141 list.pOptions[0].Value.pszValue = proxy_srv;
1142 list.pOptions[1].dwOption = INTERNET_PER_CONN_FLAGS;
1143 list.pOptions[1].Value.dwValue = PROXY_TYPE_PROXY;
1145 ret = InternetSetOptionA(NULL, INTERNET_OPTION_PER_CONNECTION_OPTION,
1147 ok(ret == TRUE, "InternetSetOption should've succeeded\n");
1149 HeapFree(GetProcessHeap(), 0, list.pOptions);
1151 /* get & verify the global IE proxy server */
1152 list.dwOptionCount = 2;
1153 list.dwOptionError = 0;
1154 list.pOptions = HeapAlloc(GetProcessHeap(), 0, 2 * sizeof(INTERNET_PER_CONN_OPTIONA));
1156 list.pOptions[0].dwOption = INTERNET_PER_CONN_PROXY_SERVER;
1157 list.pOptions[1].dwOption = INTERNET_PER_CONN_FLAGS;
1159 ret = InternetQueryOptionA(NULL, INTERNET_OPTION_PER_CONNECTION_OPTION,
1161 ok(ret == TRUE, "InternetQueryOption should've succeeded\n");
1162 ok(!lstrcmpA(list.pOptions[0].Value.pszValue, "proxy.example"),
1163 "Retrieved proxy server should've been \"%s\", was: \"%s\"\n",
1164 proxy_srv, list.pOptions[0].Value.pszValue);
1165 ok(list.pOptions[1].Value.dwValue == PROXY_TYPE_PROXY,
1166 "Retrieved flags should've been PROXY_TYPE_PROXY, was: %d\n",
1167 list.pOptions[1].Value.dwValue);
1169 HeapFree(GetProcessHeap(), 0, list.pOptions[0].Value.pszValue);
1170 HeapFree(GetProcessHeap(), 0, list.pOptions);
1172 /* restore original settings */
1173 list.dwOptionCount = 2;
1174 list.pOptions = orig_settings;
1176 ret = InternetSetOptionA(NULL, INTERNET_OPTION_PER_CONNECTION_OPTION,
1178 ok(ret == TRUE, "InternetSetOption should've succeeded\n");
1180 HeapFree(GetProcessHeap(), 0, list.pOptions);
1183 #define FLAG_TODO 0x1
1184 #define FLAG_NEEDREQ 0x2
1185 #define FLAG_UNIMPL 0x4
1187 static void test_InternetErrorDlg(void)
1189 HINTERNET ses, con, req;
1193 static const struct {
1198 { ERROR_INTERNET_INCORRECT_PASSWORD , ERROR_SUCCESS, FLAG_NEEDREQ },
1199 { ERROR_INTERNET_SEC_CERT_DATE_INVALID , ERROR_CANCELLED, 0 },
1200 { ERROR_INTERNET_SEC_CERT_CN_INVALID , ERROR_CANCELLED, 0 },
1201 { ERROR_INTERNET_HTTP_TO_HTTPS_ON_REDIR , ERROR_SUCCESS, 0 },
1202 { ERROR_INTERNET_HTTPS_TO_HTTP_ON_REDIR , ERROR_SUCCESS, FLAG_TODO },
1203 { ERROR_INTERNET_MIXED_SECURITY , ERROR_CANCELLED, FLAG_TODO },
1204 { ERROR_INTERNET_CHG_POST_IS_NON_SECURE , ERROR_CANCELLED, FLAG_TODO },
1205 { ERROR_INTERNET_POST_IS_NON_SECURE , ERROR_SUCCESS, 0 },
1206 { ERROR_INTERNET_CLIENT_AUTH_CERT_NEEDED, ERROR_CANCELLED, FLAG_NEEDREQ|FLAG_TODO },
1207 { ERROR_INTERNET_INVALID_CA , ERROR_CANCELLED, 0 },
1208 { ERROR_INTERNET_HTTPS_HTTP_SUBMIT_REDIR, ERROR_CANCELLED, FLAG_TODO },
1209 { ERROR_INTERNET_INSERT_CDROM , ERROR_CANCELLED, FLAG_TODO|FLAG_NEEDREQ|FLAG_UNIMPL },
1210 { ERROR_INTERNET_SEC_CERT_ERRORS , ERROR_CANCELLED, 0 },
1211 { ERROR_INTERNET_SEC_CERT_REV_FAILED , ERROR_CANCELLED, FLAG_TODO },
1212 { ERROR_HTTP_COOKIE_NEEDS_CONFIRMATION , ERROR_HTTP_COOKIE_DECLINED, FLAG_TODO },
1213 { ERROR_INTERNET_BAD_AUTO_PROXY_SCRIPT , ERROR_CANCELLED, FLAG_TODO },
1214 { ERROR_INTERNET_UNABLE_TO_DOWNLOAD_SCRIPT, ERROR_CANCELLED, FLAG_TODO },
1215 { ERROR_HTTP_REDIRECT_NEEDS_CONFIRMATION, ERROR_CANCELLED, FLAG_TODO },
1216 { ERROR_INTERNET_SEC_CERT_REVOKED , ERROR_CANCELLED, 0 },
1217 { 0, ERROR_NOT_SUPPORTED }
1222 res = InternetErrorDlg(NULL, NULL, 12055, flags, NULL);
1223 ok(res == ERROR_INVALID_HANDLE, "Got %d\n", res);
1225 ses = InternetOpen(NULL, INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, 0);
1226 ok(ses != 0, "InternetOpen failed: 0x%08x\n", GetLastError());
1227 con = InternetConnect(ses, "www.winehq.org", 80, NULL, NULL, INTERNET_SERVICE_HTTP, 0, 0);
1228 ok(con != 0, "InternetConnect failed: 0x%08x\n", GetLastError());
1229 req = HttpOpenRequest(con, "GET", "/", NULL, NULL, NULL, 0, 0);
1230 ok(req != 0, "HttpOpenRequest failed: 0x%08x\n", GetLastError());
1232 /* NULL hwnd and FLAGS_ERROR_UI_FLAGS_NO_UI not set */
1233 for(i = INTERNET_ERROR_BASE; i < INTERNET_ERROR_LAST; i++)
1235 res = InternetErrorDlg(NULL, req, i, flags, NULL);
1236 ok(res == ERROR_INVALID_HANDLE, "Got %d (%d)\n", res, i);
1239 hwnd = GetDesktopWindow();
1240 ok(hwnd != NULL, "GetDesktopWindow failed (%d)\n", GetLastError());
1242 flags = FLAGS_ERROR_UI_FLAGS_NO_UI;
1243 for(i = INTERNET_ERROR_BASE; i < INTERNET_ERROR_LAST; i++)
1245 DWORD expected, test_flags, j;
1247 for(j = 0; no_ui_res[j].error != 0; ++j)
1248 if(no_ui_res[j].error == i)
1251 test_flags = no_ui_res[j].test_flags;
1252 expected = no_ui_res[j].res;
1254 /* Try an invalid request handle */
1255 res = InternetErrorDlg(hwnd, (HANDLE)0xdeadbeef, i, flags, NULL);
1256 if(res == ERROR_CALL_NOT_IMPLEMENTED)
1258 todo_wine ok(test_flags & FLAG_UNIMPL, "%i is unexpectedly unimplemented.\n", i);
1262 todo_wine ok(res == ERROR_INVALID_HANDLE, "Got %d (%d)\n", res, i);
1264 /* With a valid req */
1265 if(i == ERROR_INTERNET_NEED_UI)
1266 continue; /* Crashes on windows XP */
1268 if(i == ERROR_INTERNET_SEC_CERT_REVOKED)
1269 continue; /* Interactive (XP, Win7) */
1271 res = InternetErrorDlg(hwnd, req, i, flags, NULL);
1273 /* Handle some special cases */
1276 case ERROR_INTERNET_HTTP_TO_HTTPS_ON_REDIR:
1277 case ERROR_INTERNET_HTTPS_TO_HTTP_ON_REDIR:
1278 if(res == ERROR_CANCELLED)
1280 /* Some windows XP, w2k3 x64, W2K8 */
1281 win_skip("Skipping some tests for %d\n", i);
1285 case ERROR_INTERNET_FORTEZZA_LOGIN_NEEDED:
1288 /* Windows XP, W2K3 */
1289 ok(res == NTE_PROV_TYPE_NOT_DEF, "Got %d\n", res);
1290 win_skip("Skipping some tests for %d\n", i);
1297 if(test_flags & FLAG_TODO)
1298 todo_wine ok(res == expected, "Got %d, expected %d (%d)\n", res, expected, i);
1300 ok(res == expected, "Got %d, expected %d (%d)\n", res, expected, i);
1302 /* Same thing with NULL hwnd */
1303 res = InternetErrorDlg(NULL, req, i, flags, NULL);
1304 if(test_flags & FLAG_TODO)
1305 todo_wine ok(res == expected, "Got %d, expected %d (%d)\n", res, expected, i);
1307 ok(res == expected, "Got %d, expected %d (%d)\n", res, expected, i);
1310 /* With a null req */
1311 if(test_flags & FLAG_NEEDREQ)
1312 expected = ERROR_INVALID_PARAMETER;
1314 res = InternetErrorDlg(hwnd, NULL, i, flags, NULL);
1315 if( test_flags & FLAG_TODO || i == ERROR_INTERNET_INCORRECT_PASSWORD)
1316 todo_wine ok(res == expected, "Got %d, expected %d (%d)\n", res, expected, i);
1318 ok(res == expected, "Got %d, expected %d (%d)\n", res, expected, i);
1321 res = InternetCloseHandle(req);
1322 ok(res == TRUE, "InternetCloseHandle failed: 0x%08x\n", GetLastError());
1323 res = InternetCloseHandle(con);
1324 ok(res == TRUE, "InternetCloseHandle failed: 0x%08x\n", GetLastError());
1325 res = InternetCloseHandle(ses);
1326 ok(res == TRUE, "InternetCloseHandle failed: 0x%08x\n", GetLastError());
1329 /* ############################### */
1331 START_TEST(internet)
1334 hdll = GetModuleHandleA("wininet.dll");
1336 if(!GetProcAddress(hdll, "InternetGetCookieExW")) {
1337 win_skip("Too old IE (older than 6.0)\n");
1341 pCreateUrlCacheContainerA = (void*)GetProcAddress(hdll, "CreateUrlCacheContainerA");
1342 pCreateUrlCacheContainerW = (void*)GetProcAddress(hdll, "CreateUrlCacheContainerW");
1343 pInternetTimeFromSystemTimeA = (void*)GetProcAddress(hdll, "InternetTimeFromSystemTimeA");
1344 pInternetTimeFromSystemTimeW = (void*)GetProcAddress(hdll, "InternetTimeFromSystemTimeW");
1345 pInternetTimeToSystemTimeA = (void*)GetProcAddress(hdll, "InternetTimeToSystemTimeA");
1346 pInternetTimeToSystemTimeW = (void*)GetProcAddress(hdll, "InternetTimeToSystemTimeW");
1347 pIsDomainLegalCookieDomainW = (void*)GetProcAddress(hdll, (LPCSTR)117);
1348 pPrivacyGetZonePreferenceW = (void*)GetProcAddress(hdll, "PrivacyGetZonePreferenceW");
1349 pPrivacySetZonePreferenceW = (void*)GetProcAddress(hdll, "PrivacySetZonePreferenceW");
1351 test_InternetCanonicalizeUrlA();
1352 test_InternetQueryOptionA();
1354 test_complicated_cookie();
1357 test_Option_PerConnectionOption();
1358 test_Option_PerConnectionOptionA();
1359 test_InternetErrorDlg();
1362 if (!pInternetTimeFromSystemTimeA)
1363 win_skip("skipping the InternetTime tests\n");
1366 InternetTimeFromSystemTimeA_test();
1367 InternetTimeFromSystemTimeW_test();
1368 InternetTimeToSystemTimeA_test();
1369 InternetTimeToSystemTimeW_test();
1371 if (pIsDomainLegalCookieDomainW &&
1372 ((void*)pIsDomainLegalCookieDomainW == (void*)pCreateUrlCacheContainerA ||
1373 (void*)pIsDomainLegalCookieDomainW == (void*)pCreateUrlCacheContainerW))
1374 win_skip("IsDomainLegalCookieDomainW is not available on systems with IE5\n");
1375 else if (!pIsDomainLegalCookieDomainW)
1376 win_skip("IsDomainLegalCookieDomainW (or ordinal 117) is not available\n");
1378 test_IsDomainLegalCookieDomainW();
1380 if (pPrivacyGetZonePreferenceW && pPrivacySetZonePreferenceW)
1381 test_PrivacyGetSetZonePreferenceW();
1383 win_skip("Privacy[SG]etZonePreferenceW are not available\n");
1385 test_InternetSetOption();