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 /* Win9x and WinMe don't have lstrcmpW */
45 static int strcmp_ww(const WCHAR *str1, const WCHAR *str2)
47 DWORD len1 = lstrlenW(str1);
48 DWORD len2 = lstrlenW(str2);
50 if (len1 != len2) return 1;
51 return memcmp(str1, str2, len1 * sizeof(WCHAR));
54 /* ############################### */
56 static void test_InternetCanonicalizeUrlA(void)
64 /* Acrobat Updater 5 calls this for Adobe Reader 8.1 */
65 url = "http://swupmf.adobe.com/manifest/50/win/AdobeUpdater.upd";
66 urllen = lstrlenA(url);
68 memset(buffer, '#', sizeof(buffer)-1);
69 buffer[sizeof(buffer)-1] = '\0';
70 dwSize = 1; /* Acrobat Updater use this size */
71 SetLastError(0xdeadbeef);
72 res = InternetCanonicalizeUrlA(url, buffer, &dwSize, 0);
73 ok( !res && (GetLastError() == ERROR_INSUFFICIENT_BUFFER) && (dwSize == (urllen+1)),
74 "got %u and %u with size %u for '%s' (%d)\n",
75 res, GetLastError(), dwSize, buffer, lstrlenA(buffer));
78 /* buffer has no space for the terminating '\0' */
79 memset(buffer, '#', sizeof(buffer)-1);
80 buffer[sizeof(buffer)-1] = '\0';
82 SetLastError(0xdeadbeef);
83 res = InternetCanonicalizeUrlA(url, buffer, &dwSize, 0);
84 /* dwSize is nr. of needed bytes with the terminating '\0' */
85 ok( !res && (GetLastError() == ERROR_INSUFFICIENT_BUFFER) && (dwSize == (urllen+1)),
86 "got %u and %u with size %u for '%s' (%d)\n",
87 res, GetLastError(), dwSize, buffer, lstrlenA(buffer));
89 /* buffer has the required size */
90 memset(buffer, '#', sizeof(buffer)-1);
91 buffer[sizeof(buffer)-1] = '\0';
93 SetLastError(0xdeadbeef);
94 res = InternetCanonicalizeUrlA(url, buffer, &dwSize, 0);
95 /* dwSize is nr. of copied bytes without the terminating '\0' */
96 ok( res && (dwSize == urllen) && (lstrcmpA(url, buffer) == 0),
97 "got %u and %u with size %u for '%s' (%d)\n",
98 res, GetLastError(), dwSize, buffer, lstrlenA(buffer));
100 memset(buffer, '#', sizeof(buffer)-1);
101 buffer[sizeof(buffer)-1] = '\0';
102 dwSize = sizeof(buffer);
103 SetLastError(0xdeadbeef);
104 res = InternetCanonicalizeUrlA("file:///C:/Program%20Files/Atmel/AVR%20Tools/STK500/STK500.xml", buffer, &dwSize, ICU_DECODE | ICU_NO_ENCODE);
105 ok(res, "InternetCanonicalizeUrlA failed %u\n", GetLastError());
106 ok(dwSize == lstrlenA(buffer), "got %d expected %d\n", dwSize, lstrlenA(buffer));
107 ok(!lstrcmpA("file://C:\\Program Files\\Atmel\\AVR Tools\\STK500\\STK500.xml", buffer),
108 "got %s expected 'file://C:\\Program Files\\Atmel\\AVR Tools\\STK500\\STK500.xml'\n", buffer);
110 /* buffer is larger as the required size */
111 memset(buffer, '#', sizeof(buffer)-1);
112 buffer[sizeof(buffer)-1] = '\0';
114 SetLastError(0xdeadbeef);
115 res = InternetCanonicalizeUrlA(url, buffer, &dwSize, 0);
116 /* dwSize is nr. of copied bytes without the terminating '\0' */
117 ok( res && (dwSize == urllen) && (lstrcmpA(url, buffer) == 0),
118 "got %u and %u with size %u for '%s' (%d)\n",
119 res, GetLastError(), dwSize, buffer, lstrlenA(buffer));
122 /* check NULL pointers */
123 memset(buffer, '#', urllen + 4);
124 buffer[urllen + 4] = '\0';
126 SetLastError(0xdeadbeef);
127 res = InternetCanonicalizeUrlA(NULL, buffer, &dwSize, 0);
128 ok( !res && (GetLastError() == ERROR_INVALID_PARAMETER),
129 "got %u and %u with size %u for '%s' (%d)\n",
130 res, GetLastError(), dwSize, buffer, lstrlenA(buffer));
132 memset(buffer, '#', urllen + 4);
133 buffer[urllen + 4] = '\0';
135 SetLastError(0xdeadbeef);
136 res = InternetCanonicalizeUrlA(url, NULL, &dwSize, 0);
137 ok( !res && (GetLastError() == ERROR_INVALID_PARAMETER),
138 "got %u and %u with size %u for '%s' (%d)\n",
139 res, GetLastError(), dwSize, buffer, lstrlenA(buffer));
141 memset(buffer, '#', urllen + 4);
142 buffer[urllen + 4] = '\0';
144 SetLastError(0xdeadbeef);
145 res = InternetCanonicalizeUrlA(url, buffer, NULL, 0);
146 ok( !res && (GetLastError() == ERROR_INVALID_PARAMETER),
147 "got %u and %u with size %u for '%s' (%d)\n",
148 res, GetLastError(), dwSize, buffer, lstrlenA(buffer));
150 /* test with trailing space */
152 res = InternetCanonicalizeUrlA("http://www.winehq.org/index.php?x= ", buffer, &dwSize, ICU_BROWSER_MODE);
153 ok(res == 1, "InternetCanonicalizeUrlA failed\n");
154 ok(!strcmp(buffer, "http://www.winehq.org/index.php?x="), "Trailing space should have been stripped even in ICU_BROWSER_MODE (%s)\n", buffer);
156 res = InternetSetOptionA(NULL, 0xdeadbeef, buffer, sizeof(buffer));
157 ok(!res, "InternetSetOptionA succeeded\n");
158 ok(GetLastError() == ERROR_INTERNET_INVALID_OPTION,
159 "InternetSetOptionA failed %u, expected ERROR_INTERNET_INVALID_OPTION\n", GetLastError());
162 /* ############################### */
164 static void test_InternetQueryOptionA(void)
166 HINTERNET hinet,hurl;
169 static const char useragent[] = {"Wininet Test"};
173 hinet = InternetOpenA(useragent,INTERNET_OPEN_TYPE_DIRECT,NULL,NULL, 0);
174 ok((hinet != 0x0),"InternetOpen Failed\n");
176 SetLastError(0xdeadbeef);
177 retval=InternetQueryOptionA(NULL,INTERNET_OPTION_USER_AGENT,NULL,&len);
179 ok(retval == 0,"Got wrong return value %d\n",retval);
180 ok(err == ERROR_INTERNET_INCORRECT_HANDLE_TYPE, "Got wrong error code%d\n",err);
182 SetLastError(0xdeadbeef);
183 len=strlen(useragent)+1;
184 retval=InternetQueryOptionA(hinet,INTERNET_OPTION_USER_AGENT,NULL,&len);
186 ok(len == strlen(useragent)+1,"Got wrong user agent length %d instead of %d\n",len,lstrlenA(useragent));
187 ok(retval == 0,"Got wrong return value %d\n",retval);
188 ok(err == ERROR_INSUFFICIENT_BUFFER, "Got wrong error code %d\n",err);
190 SetLastError(0xdeadbeef);
191 len=strlen(useragent)+1;
192 buffer=HeapAlloc(GetProcessHeap(),0,len);
193 retval=InternetQueryOptionA(hinet,INTERNET_OPTION_USER_AGENT,buffer,&len);
195 ok(retval == 1,"Got wrong return value %d\n",retval);
198 ok(!strcmp(useragent,buffer),"Got wrong user agent string %s instead of %s\n",buffer,useragent);
199 ok(len == strlen(useragent),"Got wrong user agent length %d instead of %d\n",len,lstrlenA(useragent));
201 ok(err == 0xdeadbeef, "Got wrong error code %d\n",err);
202 HeapFree(GetProcessHeap(),0,buffer);
204 SetLastError(0xdeadbeef);
206 buffer=HeapAlloc(GetProcessHeap(),0,100);
207 retval=InternetQueryOptionA(hinet,INTERNET_OPTION_USER_AGENT,buffer,&len);
209 ok(len == strlen(useragent) + 1,"Got wrong user agent length %d instead of %d\n", len, lstrlenA(useragent) + 1);
210 ok(!retval, "Got wrong return value %d\n", retval);
211 ok(err == ERROR_INSUFFICIENT_BUFFER, "Got wrong error code %d\n", err);
212 HeapFree(GetProcessHeap(),0,buffer);
214 hurl = InternetConnectA(hinet,"www.winehq.org",INTERNET_DEFAULT_HTTP_PORT,NULL,NULL,INTERNET_SERVICE_HTTP,0,0);
216 SetLastError(0xdeadbeef);
218 retval = InternetQueryOptionA(hurl,INTERNET_OPTION_USER_AGENT,NULL,&len);
220 ok(len == 0,"Got wrong user agent length %d instead of 0\n",len);
221 ok(retval == 0,"Got wrong return value %d\n",retval);
222 ok(err == ERROR_INTERNET_INCORRECT_HANDLE_TYPE, "Got wrong error code %d\n",err);
224 InternetCloseHandle(hurl);
225 InternetCloseHandle(hinet);
227 hinet = InternetOpenA("",INTERNET_OPEN_TYPE_DIRECT,NULL,NULL, 0);
228 ok((hinet != 0x0),"InternetOpen Failed\n");
230 SetLastError(0xdeadbeef);
232 retval=InternetQueryOptionA(hinet,INTERNET_OPTION_USER_AGENT,NULL,&len);
234 ok(len == 1,"Got wrong user agent length %d instead of %d\n",len,1);
235 ok(retval == 0,"Got wrong return value %d\n",retval);
236 ok(err == ERROR_INSUFFICIENT_BUFFER, "Got wrong error code%d\n",err);
238 InternetCloseHandle(hinet);
240 hinet = InternetOpenA(NULL,INTERNET_OPEN_TYPE_DIRECT,NULL,NULL, 0);
241 ok((hinet != 0x0),"InternetOpen Failed\n");
242 SetLastError(0xdeadbeef);
244 retval=InternetQueryOptionA(hinet,INTERNET_OPTION_USER_AGENT,NULL,&len);
246 ok(len == 1,"Got wrong user agent length %d instead of %d\n",len,1);
247 ok(retval == 0,"Got wrong return value %d\n",retval);
248 ok(err == ERROR_INSUFFICIENT_BUFFER, "Got wrong error code%d\n",err);
250 InternetCloseHandle(hinet);
253 static void test_get_cookie(void)
258 SetLastError(0xdeadbeef);
259 ret = InternetGetCookie("http://www.example.com", NULL, NULL, &len);
260 ok(!ret && GetLastError() == ERROR_NO_MORE_ITEMS,
261 "InternetGetCookie should have failed with %s and error %d\n",
262 ret ? "TRUE" : "FALSE", GetLastError());
266 static void test_complicated_cookie(void)
273 ret = InternetSetCookie("http://www.example.com/bar",NULL,"A=B; domain=.example.com");
274 ok(ret == TRUE,"InternetSetCookie failed\n");
275 ret = InternetSetCookie("http://www.example.com/bar",NULL,"C=D; domain=.example.com; path=/");
276 ok(ret == TRUE,"InternetSetCookie failed\n");
278 /* Technically illegal! domain should require 2 dots, but native wininet accepts it */
279 ret = InternetSetCookie("http://www.example.com",NULL,"E=F; domain=example.com");
280 ok(ret == TRUE,"InternetSetCookie failed\n");
281 ret = InternetSetCookie("http://www.example.com",NULL,"G=H; domain=.example.com; path=/foo");
282 ok(ret == TRUE,"InternetSetCookie failed\n");
283 ret = InternetSetCookie("http://www.example.com/bar.html",NULL,"I=J; domain=.example.com");
284 ok(ret == TRUE,"InternetSetCookie failed\n");
285 ret = InternetSetCookie("http://www.example.com/bar/",NULL,"K=L; domain=.example.com");
286 ok(ret == TRUE,"InternetSetCookie failed\n");
287 ret = InternetSetCookie("http://www.example.com/bar/",NULL,"M=N; domain=.example.com; path=/foo/");
288 ok(ret == TRUE,"InternetSetCookie failed\n");
289 ret = InternetSetCookie("http://www.example.com/bar/",NULL,"O=P; secure; path=/bar");
290 ok(ret == TRUE,"InternetSetCookie failed\n");
293 ret = InternetGetCookie("http://testing.example.com", NULL, buffer, &len);
294 ok(strstr(buffer,"A=B")!=NULL,"A=B missing\n");
295 ok(strstr(buffer,"C=D")!=NULL,"C=D missing\n");
296 ok(strstr(buffer,"E=F")!=NULL,"E=F missing\n");
297 ok(strstr(buffer,"G=H")==NULL,"G=H present\n");
298 ok(strstr(buffer,"I=J")!=NULL,"I=J missing\n");
299 ok(strstr(buffer,"K=L")==NULL,"K=L present\n");
300 ok(strstr(buffer,"M=N")==NULL,"M=N present\n");
301 ok(strstr(buffer,"O=P")==NULL,"O=P present\n");
304 ret = InternetGetCookie("http://testing.example.com/foobar", NULL, buffer, &len);
305 ok(strstr(buffer,"A=B")!=NULL,"A=B missing\n");
306 ok(strstr(buffer,"C=D")!=NULL,"C=D missing\n");
307 ok(strstr(buffer,"E=F")!=NULL,"E=F missing\n");
308 ok(strstr(buffer,"G=H")==NULL,"G=H present\n");
309 ok(strstr(buffer,"I=J")!=NULL,"I=J missing\n");
310 ok(strstr(buffer,"K=L")==NULL,"K=L present\n");
311 ok(strstr(buffer,"M=N")==NULL,"M=N present\n");
312 ok(strstr(buffer,"O=P")==NULL,"O=P present\n");
315 ret = InternetGetCookie("http://testing.example.com/foobar/", NULL, buffer, &len);
316 ok(strstr(buffer,"A=B")!=NULL,"A=B missing\n");
317 ok(strstr(buffer,"C=D")!=NULL,"C=D missing\n");
318 ok(strstr(buffer,"E=F")!=NULL,"E=F missing\n");
319 ok(strstr(buffer,"G=H")!=NULL,"G=H missing\n");
320 ok(strstr(buffer,"I=J")!=NULL,"I=J missing\n");
321 ok(strstr(buffer,"K=L")==NULL,"K=L present\n");
322 ok(strstr(buffer,"M=N")==NULL,"M=N present\n");
323 ok(strstr(buffer,"O=P")==NULL,"O=P present\n");
326 ret = InternetGetCookie("http://testing.example.com/foo/bar", NULL, buffer, &len);
327 ok(strstr(buffer,"A=B")!=NULL,"A=B missing\n");
328 ok(strstr(buffer,"C=D")!=NULL,"C=D missing\n");
329 ok(strstr(buffer,"E=F")!=NULL,"E=F missing\n");
330 ok(strstr(buffer,"G=H")!=NULL,"G=H missing\n");
331 ok(strstr(buffer,"I=J")!=NULL,"I=J missing\n");
332 ok(strstr(buffer,"K=L")==NULL,"K=L present\n");
333 ok(strstr(buffer,"M=N")!=NULL,"M=N missing\n");
334 ok(strstr(buffer,"O=P")==NULL,"O=P present\n");
337 ret = InternetGetCookie("http://testing.example.com/barfoo", NULL, buffer, &len);
338 ok(strstr(buffer,"A=B")!=NULL,"A=B missing\n");
339 ok(strstr(buffer,"C=D")!=NULL,"C=D missing\n");
340 ok(strstr(buffer,"E=F")!=NULL,"E=F missing\n");
341 ok(strstr(buffer,"G=H")==NULL,"G=H present\n");
342 ok(strstr(buffer,"I=J")!=NULL,"I=J missing\n");
343 ok(strstr(buffer,"K=L")==NULL,"K=L present\n");
344 ok(strstr(buffer,"M=N")==NULL,"M=N present\n");
345 ok(strstr(buffer,"O=P")==NULL,"O=P present\n");
348 ret = InternetGetCookie("http://testing.example.com/barfoo/", NULL, buffer, &len);
349 ok(strstr(buffer,"A=B")!=NULL,"A=B missing\n");
350 ok(strstr(buffer,"C=D")!=NULL,"C=D missing\n");
351 ok(strstr(buffer,"E=F")!=NULL,"E=F missing\n");
352 ok(strstr(buffer,"G=H")==NULL,"G=H present\n");
353 ok(strstr(buffer,"I=J")!=NULL,"I=J missing\n");
354 ok(strstr(buffer,"K=L")==NULL,"K=L present\n");
355 ok(strstr(buffer,"M=N")==NULL,"M=N present\n");
356 ok(strstr(buffer,"O=P")==NULL,"O=P present\n");
359 ret = InternetGetCookie("http://testing.example.com/bar/foo", NULL, buffer, &len);
360 ok(strstr(buffer,"A=B")!=NULL,"A=B missing\n");
361 ok(strstr(buffer,"C=D")!=NULL,"C=D missing\n");
362 ok(strstr(buffer,"E=F")!=NULL,"E=F missing\n");
363 ok(strstr(buffer,"G=H")==NULL,"G=H present\n");
364 ok(strstr(buffer,"I=J")!=NULL,"I=J missing\n");
365 ok(strstr(buffer,"K=L")!=NULL,"K=L missing\n");
366 ok(strstr(buffer,"M=N")==NULL,"M=N present\n");
367 ok(strstr(buffer,"O=P")==NULL,"O=P present\n");
370 static void test_null(void)
373 static const WCHAR szServer[] = { 's','e','r','v','e','r',0 };
374 static const WCHAR szEmpty[] = { 0 };
375 static const WCHAR szUrl[] = { 'h','t','t','p',':','/','/','a','.','b','.','c',0 };
376 static const WCHAR szUrlEmpty[] = { 'h','t','t','p',':','/','/',0 };
377 static const WCHAR szExpect[] = { 's','e','r','v','e','r',';',' ','s','e','r','v','e','r',0 };
382 SetLastError(0xdeadbeef);
383 hi = InternetOpenW(NULL, 0, NULL, NULL, 0);
384 if (hi == NULL && GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)
386 win_skip("Internet*W functions are not implemented\n");
389 ok(hi != NULL, "open failed\n");
391 hc = InternetConnectW(hi, NULL, 0, NULL, NULL, 0, 0, 0);
392 ok(GetLastError() == ERROR_INVALID_PARAMETER, "wrong error\n");
393 ok(hc == NULL, "connect failed\n");
395 hc = InternetConnectW(hi, NULL, 0, NULL, NULL, INTERNET_SERVICE_HTTP, 0, 0);
396 ok(GetLastError() == ERROR_INVALID_PARAMETER, "wrong error\n");
397 ok(hc == NULL, "connect failed\n");
399 hc = InternetConnectW(hi, NULL, 0, NULL, NULL, INTERNET_SERVICE_FTP, 0, 0);
400 ok(GetLastError() == ERROR_INVALID_PARAMETER, "wrong error\n");
401 ok(hc == NULL, "connect failed\n");
403 hc = InternetConnectW(NULL, szServer, 0, NULL, NULL, INTERNET_SERVICE_FTP, 0, 0);
404 ok(GetLastError() == ERROR_INVALID_HANDLE, "wrong error\n");
405 ok(hc == NULL, "connect failed\n");
407 hc = InternetOpenUrlW(hi, NULL, NULL, 0, 0, 0);
408 ok(GetLastError() == ERROR_INVALID_PARAMETER ||
409 GetLastError() == ERROR_INTERNET_UNRECOGNIZED_SCHEME, "wrong error\n");
410 ok(hc == NULL, "connect failed\n");
412 hc = InternetOpenUrlW(hi, szServer, NULL, 0, 0, 0);
413 ok(GetLastError() == ERROR_INTERNET_UNRECOGNIZED_SCHEME, "wrong error\n");
414 ok(hc == NULL, "connect failed\n");
416 InternetCloseHandle(hi);
418 r = InternetSetCookieW(NULL, NULL, NULL);
419 ok(GetLastError() == ERROR_INVALID_PARAMETER, "wrong error\n");
420 ok(r == FALSE, "return wrong\n");
422 r = InternetSetCookieW(szServer, NULL, NULL);
423 ok(GetLastError() == ERROR_INVALID_PARAMETER, "wrong error\n");
424 ok(r == FALSE, "return wrong\n");
426 r = InternetSetCookieW(szUrl, szServer, NULL);
427 ok(GetLastError() == ERROR_INVALID_PARAMETER, "wrong error\n");
428 ok(r == FALSE, "return wrong\n");
430 r = InternetSetCookieW(szUrl, szServer, szServer);
431 ok(r == TRUE, "return wrong\n");
433 r = InternetSetCookieW(szUrl, NULL, szServer);
434 ok(r == TRUE, "return wrong\n");
436 r = InternetSetCookieW(szUrl, szServer, szEmpty);
437 ok(r == TRUE, "return wrong\n");
439 r = InternetSetCookieW(szUrlEmpty, szServer, szServer);
440 ok(r == FALSE, "return wrong\n");
442 r = InternetSetCookieW(szServer, NULL, szServer);
444 ok(GetLastError() == ERROR_INTERNET_UNRECOGNIZED_SCHEME, "wrong error\n");
446 ok(r == FALSE, "return wrong\n");
449 r = InternetGetCookieW(NULL, NULL, NULL, &sz);
450 ok(GetLastError() == ERROR_INVALID_PARAMETER || GetLastError() == ERROR_INTERNET_UNRECOGNIZED_SCHEME,
451 "wrong error %u\n", GetLastError());
452 ok( r == FALSE, "return wrong\n");
454 r = InternetGetCookieW(szServer, NULL, NULL, &sz);
456 ok(GetLastError() == ERROR_INTERNET_UNRECOGNIZED_SCHEME, "wrong error\n");
458 ok( r == FALSE, "return wrong\n");
461 r = InternetGetCookieW(szUrlEmpty, szServer, NULL, &sz);
462 ok( r == FALSE, "return wrong\n");
465 r = InternetGetCookieW(szUrl, szServer, NULL, &sz);
466 ok( r == TRUE, "return wrong\n");
468 /* sz is 14 on XP SP2 and beyond, 30 on XP SP1 and before */
469 ok( sz == 14 || sz == 30, "sz wrong, got %u, expected 14 or 30\n", sz);
472 memset(buffer, 0, sizeof buffer);
473 r = InternetGetCookieW(szUrl, szServer, buffer, &sz);
474 ok( r == TRUE, "return wrong\n");
476 /* sz == lstrlenW(buffer) only in XP SP1 */
477 ok( sz == 1 + lstrlenW(buffer) || sz == lstrlenW(buffer), "sz wrong %d\n", sz);
479 /* before XP SP2, buffer is "server; server" */
480 ok( !strcmp_ww(szExpect, buffer) || !strcmp_ww(szServer, buffer), "cookie data wrong\n");
483 r = InternetQueryOptionA(NULL, INTERNET_OPTION_CONNECTED_STATE, buffer, &sz);
484 ok(r == TRUE, "ret %d\n", r);
487 static void test_version(void)
489 INTERNET_VERSION_INFO version;
493 size = sizeof(version);
494 res = InternetQueryOptionA(NULL, INTERNET_OPTION_VERSION, &version, &size);
495 ok(res, "Could not get version: %u\n", GetLastError());
496 ok(version.dwMajorVersion == 1, "dwMajorVersion=%d, expected 1\n", version.dwMajorVersion);
497 ok(version.dwMinorVersion == 2, "dwMinorVersion=%d, expected 2\n", version.dwMinorVersion);
500 static void InternetTimeFromSystemTimeA_test(void)
503 static const SYSTEMTIME time = { 2005, 1, 5, 7, 12, 6, 35, 0 };
504 char string[INTERNET_RFC1123_BUFSIZE];
505 static const char expect[] = "Fri, 07 Jan 2005 12:06:35 GMT";
508 ret = pInternetTimeFromSystemTimeA( &time, INTERNET_RFC1123_FORMAT, string, sizeof(string) );
509 ok( ret, "InternetTimeFromSystemTimeA failed (%u)\n", GetLastError() );
511 ok( !memcmp( string, expect, sizeof(expect) ),
512 "InternetTimeFromSystemTimeA failed (%u)\n", GetLastError() );
514 /* test NULL time parameter */
515 SetLastError(0xdeadbeef);
516 ret = pInternetTimeFromSystemTimeA( NULL, INTERNET_RFC1123_FORMAT, string, sizeof(string) );
517 error = GetLastError();
518 ok( !ret, "InternetTimeFromSystemTimeA should have returned FALSE\n" );
519 ok( error == ERROR_INVALID_PARAMETER,
520 "InternetTimeFromSystemTimeA failed with ERROR_INVALID_PARAMETER instead of %u\n",
523 /* test NULL string parameter */
524 SetLastError(0xdeadbeef);
525 ret = pInternetTimeFromSystemTimeA( &time, INTERNET_RFC1123_FORMAT, NULL, sizeof(string) );
526 error = GetLastError();
527 ok( !ret, "InternetTimeFromSystemTimeA should have returned FALSE\n" );
528 ok( error == ERROR_INVALID_PARAMETER,
529 "InternetTimeFromSystemTimeA failed with ERROR_INVALID_PARAMETER instead of %u\n",
532 /* test invalid format parameter */
533 SetLastError(0xdeadbeef);
534 ret = pInternetTimeFromSystemTimeA( &time, INTERNET_RFC1123_FORMAT + 1, string, sizeof(string) );
535 error = GetLastError();
536 ok( !ret, "InternetTimeFromSystemTimeA should have returned FALSE\n" );
537 ok( error == ERROR_INVALID_PARAMETER,
538 "InternetTimeFromSystemTimeA failed with ERROR_INVALID_PARAMETER instead of %u\n",
541 /* test too small buffer size */
542 SetLastError(0xdeadbeef);
543 ret = pInternetTimeFromSystemTimeA( &time, INTERNET_RFC1123_FORMAT, string, 0 );
544 error = GetLastError();
545 ok( !ret, "InternetTimeFromSystemTimeA should have returned FALSE\n" );
546 ok( error == ERROR_INSUFFICIENT_BUFFER,
547 "InternetTimeFromSystemTimeA failed with ERROR_INSUFFICIENT_BUFFER instead of %u\n",
551 static void InternetTimeFromSystemTimeW_test(void)
554 static const SYSTEMTIME time = { 2005, 1, 5, 7, 12, 6, 35, 0 };
555 WCHAR string[INTERNET_RFC1123_BUFSIZE + 1];
556 static const WCHAR expect[] = { 'F','r','i',',',' ','0','7',' ','J','a','n',' ','2','0','0','5',' ',
557 '1','2',':','0','6',':','3','5',' ','G','M','T',0 };
560 ret = pInternetTimeFromSystemTimeW( &time, INTERNET_RFC1123_FORMAT, string, sizeof(string) );
561 ok( ret, "InternetTimeFromSystemTimeW failed (%u)\n", GetLastError() );
563 ok( !memcmp( string, expect, sizeof(expect) ),
564 "InternetTimeFromSystemTimeW failed (%u)\n", GetLastError() );
566 /* test NULL time parameter */
567 SetLastError(0xdeadbeef);
568 ret = pInternetTimeFromSystemTimeW( NULL, INTERNET_RFC1123_FORMAT, string, sizeof(string) );
569 error = GetLastError();
570 ok( !ret, "InternetTimeFromSystemTimeW should have returned FALSE\n" );
571 ok( error == ERROR_INVALID_PARAMETER,
572 "InternetTimeFromSystemTimeW failed with ERROR_INVALID_PARAMETER instead of %u\n",
575 /* test NULL string parameter */
576 SetLastError(0xdeadbeef);
577 ret = pInternetTimeFromSystemTimeW( &time, INTERNET_RFC1123_FORMAT, NULL, sizeof(string) );
578 error = GetLastError();
579 ok( !ret, "InternetTimeFromSystemTimeW should have returned FALSE\n" );
580 ok( error == ERROR_INVALID_PARAMETER,
581 "InternetTimeFromSystemTimeW failed with ERROR_INVALID_PARAMETER instead of %u\n",
584 /* test invalid format parameter */
585 SetLastError(0xdeadbeef);
586 ret = pInternetTimeFromSystemTimeW( &time, INTERNET_RFC1123_FORMAT + 1, string, sizeof(string) );
587 error = GetLastError();
588 ok( !ret, "InternetTimeFromSystemTimeW should have returned FALSE\n" );
589 ok( error == ERROR_INVALID_PARAMETER,
590 "InternetTimeFromSystemTimeW failed with ERROR_INVALID_PARAMETER instead of %u\n",
593 /* test too small buffer size */
594 SetLastError(0xdeadbeef);
595 ret = pInternetTimeFromSystemTimeW( &time, INTERNET_RFC1123_FORMAT, string, sizeof(string)/sizeof(string[0]) );
596 error = GetLastError();
597 ok( !ret, "InternetTimeFromSystemTimeW should have returned FALSE\n" );
598 ok( error == ERROR_INSUFFICIENT_BUFFER,
599 "InternetTimeFromSystemTimeW failed with ERROR_INSUFFICIENT_BUFFER instead of %u\n",
603 static void InternetTimeToSystemTimeA_test(void)
607 static const SYSTEMTIME expect = { 2005, 1, 5, 7, 12, 6, 35, 0 };
608 static const char string[] = "Fri, 07 Jan 2005 12:06:35 GMT";
609 static const char string2[] = " fri 7 jan 2005 12 06 35";
611 ret = pInternetTimeToSystemTimeA( string, &time, 0 );
612 ok( ret, "InternetTimeToSystemTimeA failed (%u)\n", GetLastError() );
613 ok( !memcmp( &time, &expect, sizeof(expect) ),
614 "InternetTimeToSystemTimeA failed (%u)\n", GetLastError() );
616 ret = pInternetTimeToSystemTimeA( string2, &time, 0 );
617 ok( ret, "InternetTimeToSystemTimeA failed (%u)\n", GetLastError() );
618 ok( !memcmp( &time, &expect, sizeof(expect) ),
619 "InternetTimeToSystemTimeA failed (%u)\n", GetLastError() );
622 static void InternetTimeToSystemTimeW_test(void)
626 static const SYSTEMTIME expect = { 2005, 1, 5, 7, 12, 6, 35, 0 };
627 static const WCHAR string[] = { 'F','r','i',',',' ','0','7',' ','J','a','n',' ','2','0','0','5',' ',
628 '1','2',':','0','6',':','3','5',' ','G','M','T',0 };
629 static const WCHAR string2[] = { ' ','f','r','i',' ','7',' ','j','a','n',' ','2','0','0','5',' ',
630 '1','2',' ','0','6',' ','3','5',0 };
631 static const WCHAR string3[] = { 'F','r',0 };
633 ret = pInternetTimeToSystemTimeW( NULL, NULL, 0 );
634 ok( !ret, "InternetTimeToSystemTimeW succeeded (%u)\n", GetLastError() );
636 ret = pInternetTimeToSystemTimeW( NULL, &time, 0 );
637 ok( !ret, "InternetTimeToSystemTimeW succeeded (%u)\n", GetLastError() );
639 ret = pInternetTimeToSystemTimeW( string, NULL, 0 );
640 ok( !ret, "InternetTimeToSystemTimeW succeeded (%u)\n", GetLastError() );
642 ret = pInternetTimeToSystemTimeW( string, &time, 0 );
643 ok( ret, "InternetTimeToSystemTimeW failed (%u)\n", GetLastError() );
645 ret = pInternetTimeToSystemTimeW( string, &time, 0 );
646 ok( ret, "InternetTimeToSystemTimeW failed (%u)\n", GetLastError() );
647 ok( !memcmp( &time, &expect, sizeof(expect) ),
648 "InternetTimeToSystemTimeW failed (%u)\n", GetLastError() );
650 ret = pInternetTimeToSystemTimeW( string2, &time, 0 );
651 ok( ret, "InternetTimeToSystemTimeW failed (%u)\n", GetLastError() );
652 ok( !memcmp( &time, &expect, sizeof(expect) ),
653 "InternetTimeToSystemTimeW failed (%u)\n", GetLastError() );
655 ret = pInternetTimeToSystemTimeW( string3, &time, 0 );
656 ok( ret, "InternetTimeToSystemTimeW failed (%u)\n", GetLastError() );
659 static void test_IsDomainLegalCookieDomainW(void)
663 static const WCHAR empty[] = {0};
664 static const WCHAR dot[] = {'.',0};
665 static const WCHAR uk[] = {'u','k',0};
666 static const WCHAR com[] = {'c','o','m',0};
667 static const WCHAR dot_com[] = {'.','c','o','m',0};
668 static const WCHAR gmail_com[] = {'g','m','a','i','l','.','c','o','m',0};
669 static const WCHAR dot_gmail_com[] = {'.','g','m','a','i','l','.','c','o','m',0};
670 static const WCHAR mail_gmail_com[] = {'m','a','i','l','.','g','m','a','i','l','.','c','o','m',0};
671 static const WCHAR gmail_co_uk[] = {'g','m','a','i','l','.','c','o','.','u','k',0};
672 static const WCHAR co_uk[] = {'c','o','.','u','k',0};
673 static const WCHAR dot_co_uk[] = {'.','c','o','.','u','k',0};
675 SetLastError(0xdeadbeef);
676 ret = pIsDomainLegalCookieDomainW(NULL, NULL);
677 error = GetLastError();
678 if (!ret && error == ERROR_CALL_NOT_IMPLEMENTED)
680 win_skip("IsDomainLegalCookieDomainW is not implemented\n");
684 broken(ret), /* IE6 */
685 "IsDomainLegalCookieDomainW succeeded\n");
686 ok(error == ERROR_INVALID_PARAMETER, "got %u expected ERROR_INVALID_PARAMETER\n", error);
688 SetLastError(0xdeadbeef);
689 ret = pIsDomainLegalCookieDomainW(com, NULL);
690 error = GetLastError();
691 ok(!ret, "IsDomainLegalCookieDomainW succeeded\n");
692 ok(error == ERROR_INVALID_PARAMETER, "got %u expected ERROR_INVALID_PARAMETER\n", error);
694 SetLastError(0xdeadbeef);
695 ret = pIsDomainLegalCookieDomainW(NULL, gmail_com);
696 error = GetLastError();
697 ok(!ret, "IsDomainLegalCookieDomainW succeeded\n");
698 ok(error == ERROR_INVALID_PARAMETER, "got %u expected ERROR_INVALID_PARAMETER\n", error);
700 SetLastError(0xdeadbeef);
701 ret = pIsDomainLegalCookieDomainW(empty, gmail_com);
702 error = GetLastError();
703 ok(!ret, "IsDomainLegalCookieDomainW succeeded\n");
704 ok(error == ERROR_INVALID_NAME ||
705 broken(error == ERROR_INVALID_PARAMETER), /* IE6 */
706 "got %u expected ERROR_INVALID_NAME\n", error);
708 SetLastError(0xdeadbeef);
709 ret = pIsDomainLegalCookieDomainW(com, empty);
710 error = GetLastError();
711 ok(!ret, "IsDomainLegalCookieDomainW succeeded\n");
712 ok(error == ERROR_INVALID_NAME ||
713 broken(error == ERROR_INVALID_PARAMETER), /* IE6 */
714 "got %u expected ERROR_INVALID_NAME\n", error);
716 SetLastError(0xdeadbeef);
717 ret = pIsDomainLegalCookieDomainW(gmail_com, dot);
718 error = GetLastError();
719 ok(!ret, "IsDomainLegalCookieDomainW succeeded\n");
720 ok(error == ERROR_INVALID_NAME ||
721 broken(error == 0xdeadbeef), /* IE6 */
722 "got %u expected ERROR_INVALID_NAME\n", error);
724 SetLastError(0xdeadbeef);
725 ret = pIsDomainLegalCookieDomainW(dot, gmail_com);
726 error = GetLastError();
727 ok(!ret, "IsDomainLegalCookieDomainW succeeded\n");
728 ok(error == ERROR_INVALID_NAME ||
729 broken(error == 0xdeadbeef), /* IE6 */
730 "got %u expected ERROR_INVALID_NAME\n", error);
732 SetLastError(0xdeadbeef);
733 ret = pIsDomainLegalCookieDomainW(com, com);
734 error = GetLastError();
735 ok(!ret, "IsDomainLegalCookieDomainW succeeded\n");
736 ok(error == 0xdeadbeef, "got %u expected 0xdeadbeef\n", error);
738 SetLastError(0xdeadbeef);
739 ret = pIsDomainLegalCookieDomainW(com, dot_com);
740 error = GetLastError();
741 ok(!ret, "IsDomainLegalCookieDomainW succeeded\n");
742 ok(error == ERROR_INVALID_NAME ||
743 broken(error == 0xdeadbeef), /* IE6 */
744 "got %u expected ERROR_INVALID_NAME\n", error);
746 SetLastError(0xdeadbeef);
747 ret = pIsDomainLegalCookieDomainW(dot_com, com);
748 error = GetLastError();
749 ok(!ret, "IsDomainLegalCookieDomainW succeeded\n");
750 ok(error == ERROR_INVALID_NAME ||
751 broken(error == 0xdeadbeef), /* IE6 */
752 "got %u expected ERROR_INVALID_NAME\n", error);
754 SetLastError(0xdeadbeef);
755 ret = pIsDomainLegalCookieDomainW(com, gmail_com);
756 error = GetLastError();
757 ok(!ret, "IsDomainLegalCookieDomainW succeeded\n");
758 ok(error == ERROR_SXS_KEY_NOT_FOUND ||
759 error == ERROR_SUCCESS || /* IE8 on W2K3 */
760 error == 0xdeadbeef, /* up to IE7 */
761 "unexpected error: %u\n", error);
763 ret = pIsDomainLegalCookieDomainW(gmail_com, gmail_com);
764 ok(ret, "IsDomainLegalCookieDomainW failed\n");
766 SetLastError(0xdeadbeef);
767 ret = pIsDomainLegalCookieDomainW(gmail_co_uk, co_uk);
768 error = GetLastError();
769 ok(!ret, "IsDomainLegalCookieDomainW succeeded\n");
770 ok(error == ERROR_SXS_KEY_NOT_FOUND || /* IE8 on XP */
771 error == ERROR_FILE_NOT_FOUND || /* IE8 on Vista */
772 error == ERROR_SUCCESS || /* IE8 on W2K3 */
773 error == 0xdeadbeef, /* up to IE7 */
774 "unexpected error: %u\n", error);
776 ret = pIsDomainLegalCookieDomainW(uk, co_uk);
777 ok(!ret, "IsDomainLegalCookieDomainW succeeded\n");
779 ret = pIsDomainLegalCookieDomainW(gmail_co_uk, dot_co_uk);
780 ok(!ret, "IsDomainLegalCookieDomainW succeeded\n");
782 ret = pIsDomainLegalCookieDomainW(gmail_co_uk, gmail_co_uk);
783 ok(ret, "IsDomainLegalCookieDomainW failed\n");
785 ret = pIsDomainLegalCookieDomainW(gmail_com, com);
786 ok(!ret, "IsDomainLegalCookieDomainW succeeded\n");
788 SetLastError(0xdeadbeef);
789 ret = pIsDomainLegalCookieDomainW(dot_gmail_com, mail_gmail_com);
790 error = GetLastError();
791 ok(!ret, "IsDomainLegalCookieDomainW succeeded\n");
792 ok(error == ERROR_INVALID_NAME ||
793 broken(error == 0xdeadbeef), /* IE6 */
794 "got %u expected ERROR_INVALID_NAME\n", error);
796 ret = pIsDomainLegalCookieDomainW(gmail_com, mail_gmail_com);
797 ok(ret, "IsDomainLegalCookieDomainW failed\n");
799 ret = pIsDomainLegalCookieDomainW(mail_gmail_com, gmail_com);
800 ok(!ret, "IsDomainLegalCookieDomainW succeeded\n");
802 ret = pIsDomainLegalCookieDomainW(mail_gmail_com, com);
803 ok(!ret, "IsDomainLegalCookieDomainW succeeded\n");
805 ret = pIsDomainLegalCookieDomainW(dot_gmail_com, mail_gmail_com);
806 ok(!ret, "IsDomainLegalCookieDomainW succeeded\n");
808 ret = pIsDomainLegalCookieDomainW(mail_gmail_com, dot_gmail_com);
809 ok(!ret, "IsDomainLegalCookieDomainW succeeded\n");
812 static void test_PrivacyGetSetZonePreferenceW(void)
814 DWORD ret, zone, type, template, old_template;
818 ret = pPrivacyGetZonePreferenceW(zone, type, NULL, NULL, NULL);
819 ok(ret == 0, "expected ret == 0, got %u\n", ret);
822 ret = pPrivacyGetZonePreferenceW(zone, type, &old_template, NULL, NULL);
823 ok(ret == 0, "expected ret == 0, got %u\n", ret);
826 ret = pPrivacySetZonePreferenceW(zone, type, template, NULL);
827 ok(ret == 0, "expected ret == 0, got %u\n", ret);
830 ret = pPrivacyGetZonePreferenceW(zone, type, &template, NULL, NULL);
831 ok(ret == 0, "expected ret == 0, got %u\n", ret);
832 ok(template == 5, "expected template == 5, got %u\n", template);
835 ret = pPrivacySetZonePreferenceW(zone, type, old_template, NULL);
836 ok(ret == 0, "expected ret == 0, got %u\n", ret);
839 static void test_InternetSetOption(void)
841 HINTERNET ses, con, req;
846 ses = InternetOpen(NULL, INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, 0);
847 ok(ses != 0, "InternetOpen failed: 0x%08x\n", GetLastError());
848 con = InternetConnect(ses, "www.winehq.org", 80, NULL, NULL, INTERNET_SERVICE_HTTP, 0, 0);
849 ok(con != 0, "InternetConnect failed: 0x%08x\n", GetLastError());
850 req = HttpOpenRequest(con, "GET", "/", NULL, NULL, NULL, 0, 0);
851 ok(req != 0, "HttpOpenRequest failed: 0x%08x\n", GetLastError());
853 /* INTERNET_OPTION_POLICY tests */
854 SetLastError(0xdeadbeef);
855 ret = InternetSetOptionW(ses, INTERNET_OPTION_POLICY, NULL, 0);
856 ok(ret == FALSE, "InternetSetOption should've failed\n");
857 ok(GetLastError() == ERROR_INVALID_PARAMETER, "GetLastError should've "
858 "given ERROR_INVALID_PARAMETER, gave: 0x%08x\n", GetLastError());
860 SetLastError(0xdeadbeef);
861 ret = InternetQueryOptionW(ses, INTERNET_OPTION_POLICY, NULL, 0);
862 ok(ret == FALSE, "InternetQueryOption should've failed\n");
863 ok(GetLastError() == ERROR_INVALID_PARAMETER, "GetLastError should've "
864 "given ERROR_INVALID_PARAMETER, gave: 0x%08x\n", GetLastError());
866 /* INTERNET_OPTION_ERROR_MASK tests */
867 SetLastError(0xdeadbeef);
868 size = sizeof(ulArg);
869 ret = InternetQueryOptionW(NULL, INTERNET_OPTION_ERROR_MASK, (void*)&ulArg, &size);
870 ok(ret == FALSE, "InternetQueryOption should've failed\n");
871 ok(GetLastError() == ERROR_INTERNET_INCORRECT_HANDLE_TYPE, "GetLastError() = %x\n", GetLastError());
873 SetLastError(0xdeadbeef);
875 ret = InternetSetOption(NULL, INTERNET_OPTION_ERROR_MASK, (void*)&ulArg, sizeof(ULONG));
876 ok(ret == FALSE, "InternetQueryOption should've failed\n");
877 ok(GetLastError() == ERROR_INTERNET_INCORRECT_HANDLE_TYPE, "GetLastError() = %x\n", GetLastError());
879 SetLastError(0xdeadbeef);
881 ret = InternetSetOption(req, INTERNET_OPTION_ERROR_MASK, (void*)&ulArg, 20);
882 ok(ret == FALSE, "InternetQueryOption should've failed\n");
883 ok(GetLastError() == ERROR_INTERNET_BAD_OPTION_LENGTH, "GetLastError() = %d\n", GetLastError());
885 SetLastError(0xdeadbeef);
887 ret = InternetSetOption(req, INTERNET_OPTION_ERROR_MASK, (void*)&ulArg, sizeof(ULONG));
888 ok(ret == TRUE, "InternetQueryOption should've succeeded\n");
889 ok(GetLastError() == 0xdeadbeef, "GetLastError() = %d\n", GetLastError());
891 SetLastError(0xdeadbeef);
893 ret = InternetSetOption(req, INTERNET_OPTION_ERROR_MASK, (void*)&ulArg, sizeof(ULONG));
894 ok(ret == FALSE, "InternetQueryOption should've failed\n");
895 ok(GetLastError() == ERROR_INVALID_PARAMETER, "GetLastError() = %x\n", GetLastError());
897 SetLastError(0xdeadbeef);
899 ret = InternetSetOption(req, INTERNET_OPTION_ERROR_MASK, (void*)&ulArg, sizeof(ULONG));
900 ok(ret == FALSE, "InternetQueryOption should've failed\n");
901 ok(GetLastError() == ERROR_INVALID_PARAMETER, "GetLastError() = %x\n", GetLastError());
903 ret = InternetCloseHandle(req);
904 ok(ret == TRUE, "InternetCloseHandle failed: 0x%08x\n", GetLastError());
905 ret = InternetCloseHandle(con);
906 ok(ret == TRUE, "InternetCloseHandle failed: 0x%08x\n", GetLastError());
907 ret = InternetCloseHandle(ses);
908 ok(ret == TRUE, "InternetCloseHandle failed: 0x%08x\n", GetLastError());
911 #define verifyProxyEnable(e) r_verifyProxyEnable(__LINE__, e)
912 static void r_verifyProxyEnable(LONG l, DWORD exp)
915 DWORD type, val, size = sizeof(DWORD);
917 static const CHAR szInternetSettings[] = "Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings";
918 static const CHAR szProxyEnable[] = "ProxyEnable";
920 ret = RegOpenKeyA(HKEY_CURRENT_USER, szInternetSettings, &hkey);
921 ok_(__FILE__,l) (!ret, "RegOpenKeyA failed: 0x%08x\n", ret);
923 ret = RegQueryValueExA(hkey, szProxyEnable, 0, &type, (BYTE*)&val, &size);
924 ok_(__FILE__,l) (!ret, "RegQueryValueExA failed: 0x%08x\n", ret);
925 ok_(__FILE__,l) (type == REG_DWORD, "Expected regtype to be REG_DWORD, was: %d\n", type);
926 ok_(__FILE__,l) (val == exp, "Expected ProxyEnabled to be %d, got: %d\n", exp, val);
928 ret = RegCloseKey(hkey);
929 ok_(__FILE__,l) (!ret, "RegCloseKey failed: 0x%08x\n", ret);
932 static void test_Option_PerConnectionOption(void)
935 DWORD size = sizeof(INTERNET_PER_CONN_OPTION_LISTW);
936 INTERNET_PER_CONN_OPTION_LISTW list = {size};
937 INTERNET_PER_CONN_OPTIONW *orig_settings;
938 static WCHAR proxy_srvW[] = {'p','r','o','x','y','.','e','x','a','m','p','l','e',0};
940 /* get the global IE proxy server info, to restore later */
941 list.dwOptionCount = 2;
942 list.pOptions = HeapAlloc(GetProcessHeap(), 0, 2 * sizeof(INTERNET_PER_CONN_OPTIONW));
944 list.pOptions[0].dwOption = INTERNET_PER_CONN_PROXY_SERVER;
945 list.pOptions[1].dwOption = INTERNET_PER_CONN_FLAGS;
947 ret = InternetQueryOptionW(NULL, INTERNET_OPTION_PER_CONNECTION_OPTION,
949 ok(ret == TRUE, "InternetQueryOption should've succeeded\n");
950 orig_settings = list.pOptions;
952 /* set the global IE proxy server */
953 list.dwOptionCount = 2;
954 list.pOptions = HeapAlloc(GetProcessHeap(), 0, 2 * sizeof(INTERNET_PER_CONN_OPTIONW));
956 list.pOptions[0].dwOption = INTERNET_PER_CONN_PROXY_SERVER;
957 list.pOptions[0].Value.pszValue = proxy_srvW;
958 list.pOptions[1].dwOption = INTERNET_PER_CONN_FLAGS;
959 list.pOptions[1].Value.dwValue = PROXY_TYPE_PROXY;
961 ret = InternetSetOptionW(NULL, INTERNET_OPTION_PER_CONNECTION_OPTION,
963 ok(ret == TRUE, "InternetSetOption should've succeeded\n");
965 HeapFree(GetProcessHeap(), 0, list.pOptions);
967 /* get & verify the global IE proxy server */
968 list.dwOptionCount = 2;
969 list.dwOptionError = 0;
970 list.pOptions = HeapAlloc(GetProcessHeap(), 0, 2 * sizeof(INTERNET_PER_CONN_OPTIONW));
972 list.pOptions[0].dwOption = INTERNET_PER_CONN_PROXY_SERVER;
973 list.pOptions[1].dwOption = INTERNET_PER_CONN_FLAGS;
975 ret = InternetQueryOptionW(NULL, INTERNET_OPTION_PER_CONNECTION_OPTION,
977 ok(ret == TRUE, "InternetQueryOption should've succeeded\n");
978 ok(!strcmp_ww(list.pOptions[0].Value.pszValue, proxy_srvW),
979 "Retrieved proxy server should've been %s, was: %s\n",
980 wine_dbgstr_w(proxy_srvW), wine_dbgstr_w(list.pOptions[0].Value.pszValue));
981 ok(list.pOptions[1].Value.dwValue == PROXY_TYPE_PROXY,
982 "Retrieved flags should've been PROXY_TYPE_PROXY, was: %d\n",
983 list.pOptions[1].Value.dwValue);
984 verifyProxyEnable(1);
986 HeapFree(GetProcessHeap(), 0, list.pOptions[0].Value.pszValue);
987 HeapFree(GetProcessHeap(), 0, list.pOptions);
989 /* disable the proxy server */
990 list.dwOptionCount = 1;
991 list.pOptions = HeapAlloc(GetProcessHeap(), 0, sizeof(INTERNET_PER_CONN_OPTIONW));
993 list.pOptions[0].dwOption = INTERNET_PER_CONN_FLAGS;
994 list.pOptions[0].Value.dwValue = PROXY_TYPE_DIRECT;
996 ret = InternetSetOptionW(NULL, INTERNET_OPTION_PER_CONNECTION_OPTION,
998 ok(ret == TRUE, "InternetSetOption should've succeeded\n");
1000 HeapFree(GetProcessHeap(), 0, list.pOptions);
1002 /* verify that the proxy is disabled */
1003 list.dwOptionCount = 1;
1004 list.dwOptionError = 0;
1005 list.pOptions = HeapAlloc(GetProcessHeap(), 0, sizeof(INTERNET_PER_CONN_OPTIONW));
1007 list.pOptions[0].dwOption = INTERNET_PER_CONN_FLAGS;
1009 ret = InternetQueryOptionW(NULL, INTERNET_OPTION_PER_CONNECTION_OPTION,
1011 ok(ret == TRUE, "InternetQueryOption should've succeeded\n");
1012 ok(list.pOptions[0].Value.dwValue == PROXY_TYPE_DIRECT,
1013 "Retrieved flags should've been PROXY_TYPE_DIRECT, was: %d\n",
1014 list.pOptions[0].Value.dwValue);
1015 verifyProxyEnable(0);
1017 HeapFree(GetProcessHeap(), 0, list.pOptions);
1019 /* set the proxy flags to 'invalid' value */
1020 list.dwOptionCount = 1;
1021 list.pOptions = HeapAlloc(GetProcessHeap(), 0, sizeof(INTERNET_PER_CONN_OPTIONW));
1023 list.pOptions[0].dwOption = INTERNET_PER_CONN_FLAGS;
1024 list.pOptions[0].Value.dwValue = PROXY_TYPE_PROXY | PROXY_TYPE_DIRECT;
1026 ret = InternetSetOptionW(NULL, INTERNET_OPTION_PER_CONNECTION_OPTION,
1028 ok(ret == TRUE, "InternetSetOption should've succeeded\n");
1030 HeapFree(GetProcessHeap(), 0, list.pOptions);
1032 /* verify that the proxy is enabled */
1033 list.dwOptionCount = 1;
1034 list.dwOptionError = 0;
1035 list.pOptions = HeapAlloc(GetProcessHeap(), 0, sizeof(INTERNET_PER_CONN_OPTIONW));
1037 list.pOptions[0].dwOption = INTERNET_PER_CONN_FLAGS;
1039 ret = InternetQueryOptionW(NULL, INTERNET_OPTION_PER_CONNECTION_OPTION,
1041 ok(ret == TRUE, "InternetQueryOption should've succeeded\n");
1042 todo_wine ok(list.pOptions[0].Value.dwValue == (PROXY_TYPE_PROXY | PROXY_TYPE_DIRECT),
1043 "Retrieved flags should've been PROXY_TYPE_PROXY | PROXY_TYPE_DIRECT, was: %d\n",
1044 list.pOptions[0].Value.dwValue);
1045 verifyProxyEnable(1);
1047 HeapFree(GetProcessHeap(), 0, list.pOptions);
1049 /* restore original settings */
1050 list.dwOptionCount = 2;
1051 list.pOptions = orig_settings;
1053 ret = InternetSetOptionW(NULL, INTERNET_OPTION_PER_CONNECTION_OPTION,
1055 ok(ret == TRUE, "InternetSetOption should've succeeded\n");
1057 HeapFree(GetProcessHeap(), 0, list.pOptions);
1060 static void test_Option_PerConnectionOptionA(void)
1063 DWORD size = sizeof(INTERNET_PER_CONN_OPTION_LISTA);
1064 INTERNET_PER_CONN_OPTION_LISTA list = {size};
1065 INTERNET_PER_CONN_OPTIONA *orig_settings;
1066 char proxy_srv[] = "proxy.example";
1068 /* get the global IE proxy server info, to restore later */
1069 list.dwOptionCount = 2;
1070 list.pOptions = HeapAlloc(GetProcessHeap(), 0, 2 * sizeof(INTERNET_PER_CONN_OPTIONA));
1072 list.pOptions[0].dwOption = INTERNET_PER_CONN_PROXY_SERVER;
1073 list.pOptions[1].dwOption = INTERNET_PER_CONN_FLAGS;
1075 ret = InternetQueryOptionA(NULL, INTERNET_OPTION_PER_CONNECTION_OPTION,
1077 ok(ret == TRUE, "InternetQueryOption should've succeeded\n");
1078 orig_settings = list.pOptions;
1080 /* set the global IE proxy server */
1081 list.dwOptionCount = 2;
1082 list.pOptions = HeapAlloc(GetProcessHeap(), 0, 2 * sizeof(INTERNET_PER_CONN_OPTIONA));
1084 list.pOptions[0].dwOption = INTERNET_PER_CONN_PROXY_SERVER;
1085 list.pOptions[0].Value.pszValue = proxy_srv;
1086 list.pOptions[1].dwOption = INTERNET_PER_CONN_FLAGS;
1087 list.pOptions[1].Value.dwValue = PROXY_TYPE_PROXY;
1089 ret = InternetSetOptionA(NULL, INTERNET_OPTION_PER_CONNECTION_OPTION,
1091 ok(ret == TRUE, "InternetSetOption should've succeeded\n");
1093 HeapFree(GetProcessHeap(), 0, list.pOptions);
1095 /* get & verify the global IE proxy server */
1096 list.dwOptionCount = 2;
1097 list.dwOptionError = 0;
1098 list.pOptions = HeapAlloc(GetProcessHeap(), 0, 2 * sizeof(INTERNET_PER_CONN_OPTIONA));
1100 list.pOptions[0].dwOption = INTERNET_PER_CONN_PROXY_SERVER;
1101 list.pOptions[1].dwOption = INTERNET_PER_CONN_FLAGS;
1103 ret = InternetQueryOptionA(NULL, INTERNET_OPTION_PER_CONNECTION_OPTION,
1105 ok(ret == TRUE, "InternetQueryOption should've succeeded\n");
1106 ok(!lstrcmpA(list.pOptions[0].Value.pszValue, "proxy.example"),
1107 "Retrieved proxy server should've been \"%s\", was: \"%s\"\n",
1108 proxy_srv, list.pOptions[0].Value.pszValue);
1109 ok(list.pOptions[1].Value.dwValue == PROXY_TYPE_PROXY,
1110 "Retrieved flags should've been PROXY_TYPE_PROXY, was: %d\n",
1111 list.pOptions[1].Value.dwValue);
1113 HeapFree(GetProcessHeap(), 0, list.pOptions[0].Value.pszValue);
1114 HeapFree(GetProcessHeap(), 0, list.pOptions);
1116 /* restore original settings */
1117 list.dwOptionCount = 2;
1118 list.pOptions = orig_settings;
1120 ret = InternetSetOptionA(NULL, INTERNET_OPTION_PER_CONNECTION_OPTION,
1122 ok(ret == TRUE, "InternetSetOption should've succeeded\n");
1124 HeapFree(GetProcessHeap(), 0, list.pOptions);
1127 #define FLAG_TODO 0x1
1128 #define FLAG_NEEDREQ 0x2
1129 #define FLAG_UNIMPL 0x4
1131 void test_InternetErrorDlg(void)
1133 HINTERNET ses, con, req;
1137 static const struct {
1142 { ERROR_INTERNET_INCORRECT_PASSWORD , ERROR_SUCCESS, FLAG_NEEDREQ },
1143 { ERROR_INTERNET_SEC_CERT_DATE_INVALID , ERROR_CANCELLED, 0 },
1144 { ERROR_INTERNET_SEC_CERT_CN_INVALID , ERROR_CANCELLED, 0 },
1145 { ERROR_INTERNET_HTTP_TO_HTTPS_ON_REDIR , ERROR_SUCCESS, 0 },
1146 { ERROR_INTERNET_HTTPS_TO_HTTP_ON_REDIR , ERROR_SUCCESS, FLAG_TODO },
1147 { ERROR_INTERNET_MIXED_SECURITY , ERROR_CANCELLED, FLAG_TODO },
1148 { ERROR_INTERNET_CHG_POST_IS_NON_SECURE , ERROR_CANCELLED, FLAG_TODO },
1149 { ERROR_INTERNET_POST_IS_NON_SECURE , ERROR_SUCCESS, 0 },
1150 { ERROR_INTERNET_CLIENT_AUTH_CERT_NEEDED, ERROR_CANCELLED, FLAG_NEEDREQ|FLAG_TODO },
1151 { ERROR_INTERNET_INVALID_CA , ERROR_CANCELLED, 0 },
1152 { ERROR_INTERNET_HTTPS_HTTP_SUBMIT_REDIR, ERROR_CANCELLED, FLAG_TODO },
1153 { ERROR_INTERNET_INSERT_CDROM , ERROR_CANCELLED, FLAG_TODO|FLAG_NEEDREQ|FLAG_UNIMPL },
1154 { ERROR_INTERNET_SEC_CERT_ERRORS , ERROR_CANCELLED, 0 },
1155 { ERROR_INTERNET_SEC_CERT_REV_FAILED , ERROR_CANCELLED, FLAG_TODO },
1156 { ERROR_HTTP_COOKIE_NEEDS_CONFIRMATION , ERROR_HTTP_COOKIE_DECLINED, FLAG_TODO },
1157 { ERROR_INTERNET_BAD_AUTO_PROXY_SCRIPT , ERROR_CANCELLED, FLAG_TODO },
1158 { ERROR_INTERNET_UNABLE_TO_DOWNLOAD_SCRIPT, ERROR_CANCELLED, FLAG_TODO },
1159 { ERROR_HTTP_REDIRECT_NEEDS_CONFIRMATION, ERROR_CANCELLED, FLAG_TODO },
1160 { ERROR_INTERNET_SEC_CERT_REVOKED , ERROR_CANCELLED, 0 },
1161 { 0, ERROR_NOT_SUPPORTED }
1166 res = InternetErrorDlg(NULL, NULL, 12055, flags, NULL);
1167 ok(res == ERROR_INVALID_HANDLE, "Got %d\n", res);
1169 ses = InternetOpen(NULL, INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, 0);
1170 ok(ses != 0, "InternetOpen failed: 0x%08x\n", GetLastError());
1171 con = InternetConnect(ses, "www.winehq.org", 80, NULL, NULL, INTERNET_SERVICE_HTTP, 0, 0);
1172 ok(con != 0, "InternetConnect failed: 0x%08x\n", GetLastError());
1173 req = HttpOpenRequest(con, "GET", "/", NULL, NULL, NULL, 0, 0);
1174 ok(req != 0, "HttpOpenRequest failed: 0x%08x\n", GetLastError());
1176 /* NULL hwnd and FLAGS_ERROR_UI_FLAGS_NO_UI not set */
1177 for(i = INTERNET_ERROR_BASE; i < INTERNET_ERROR_LAST; i++)
1179 res = InternetErrorDlg(NULL, req, i, flags, NULL);
1180 ok(res == ERROR_INVALID_HANDLE, "Got %d (%d)\n", res, i);
1183 hwnd = GetDesktopWindow();
1184 ok(hwnd != NULL, "GetDesktopWindow failed (%d)\n", GetLastError());
1186 flags = FLAGS_ERROR_UI_FLAGS_NO_UI;
1187 for(i = INTERNET_ERROR_BASE; i < INTERNET_ERROR_LAST; i++)
1189 DWORD expected, test_flags, j;
1191 for(j = 0; no_ui_res[j].error != 0; ++j)
1192 if(no_ui_res[j].error == i)
1195 test_flags = no_ui_res[j].test_flags;
1196 expected = no_ui_res[j].res;
1198 /* Try an invalid request handle */
1199 res = InternetErrorDlg(hwnd, (HANDLE)0xdeadbeef, i, flags, NULL);
1200 if(res == ERROR_CALL_NOT_IMPLEMENTED)
1202 todo_wine ok(test_flags & FLAG_UNIMPL, "%i is unexpectedly unimplemented.\n", i);
1206 todo_wine ok(res == ERROR_INVALID_HANDLE, "Got %d (%d)\n", res, i);
1208 /* With a valid req */
1209 if(i == ERROR_INTERNET_NEED_UI)
1210 continue; /* Crashes on windows XP */
1212 if(i == ERROR_INTERNET_SEC_CERT_REVOKED)
1213 continue; /* Interactive (XP, Win7) */
1215 res = InternetErrorDlg(hwnd, req, i, flags, NULL);
1217 /* Handle some special cases */
1220 case ERROR_INTERNET_HTTP_TO_HTTPS_ON_REDIR:
1221 case ERROR_INTERNET_HTTPS_TO_HTTP_ON_REDIR:
1222 if(res == ERROR_CANCELLED)
1224 /* Some windows XP, w2k3 x64, W2K8 */
1225 win_skip("Skipping some tests for %d\n", i);
1229 case ERROR_INTERNET_FORTEZZA_LOGIN_NEEDED:
1232 /* Windows XP, W2K3 */
1233 ok(res == NTE_PROV_TYPE_NOT_DEF, "Got %d\n", res);
1234 win_skip("Skipping some tests for %d\n", i);
1241 if(test_flags & FLAG_TODO)
1242 todo_wine ok(res == expected, "Got %d, expected %d (%d)\n", res, expected, i);
1244 ok(res == expected, "Got %d, expected %d (%d)\n", res, expected, i);
1246 /* Same thing with NULL hwnd */
1247 res = InternetErrorDlg(NULL, req, i, flags, NULL);
1248 if(test_flags & FLAG_TODO)
1249 todo_wine ok(res == expected, "Got %d, expected %d (%d)\n", res, expected, i);
1251 ok(res == expected, "Got %d, expected %d (%d)\n", res, expected, i);
1254 /* With a null req */
1255 if(test_flags & FLAG_NEEDREQ)
1256 expected = ERROR_INVALID_PARAMETER;
1258 res = InternetErrorDlg(hwnd, NULL, i, flags, NULL);
1259 if( test_flags & FLAG_TODO || i == ERROR_INTERNET_INCORRECT_PASSWORD)
1260 todo_wine ok(res == expected, "Got %d, expected %d (%d)\n", res, expected, i);
1262 ok(res == expected, "Got %d, expected %d (%d)\n", res, expected, i);
1265 res = InternetCloseHandle(req);
1266 ok(res == TRUE, "InternetCloseHandle failed: 0x%08x\n", GetLastError());
1267 res = InternetCloseHandle(con);
1268 ok(res == TRUE, "InternetCloseHandle failed: 0x%08x\n", GetLastError());
1269 res = InternetCloseHandle(ses);
1270 ok(res == TRUE, "InternetCloseHandle failed: 0x%08x\n", GetLastError());
1273 /* ############################### */
1275 START_TEST(internet)
1278 hdll = GetModuleHandleA("wininet.dll");
1280 if(!GetProcAddress(hdll, "InternetGetCookieExW")) {
1281 win_skip("Too old IE (older than 6.0)\n");
1285 pCreateUrlCacheContainerA = (void*)GetProcAddress(hdll, "CreateUrlCacheContainerA");
1286 pCreateUrlCacheContainerW = (void*)GetProcAddress(hdll, "CreateUrlCacheContainerW");
1287 pInternetTimeFromSystemTimeA = (void*)GetProcAddress(hdll, "InternetTimeFromSystemTimeA");
1288 pInternetTimeFromSystemTimeW = (void*)GetProcAddress(hdll, "InternetTimeFromSystemTimeW");
1289 pInternetTimeToSystemTimeA = (void*)GetProcAddress(hdll, "InternetTimeToSystemTimeA");
1290 pInternetTimeToSystemTimeW = (void*)GetProcAddress(hdll, "InternetTimeToSystemTimeW");
1291 pIsDomainLegalCookieDomainW = (void*)GetProcAddress(hdll, (LPCSTR)117);
1292 pPrivacyGetZonePreferenceW = (void*)GetProcAddress(hdll, "PrivacyGetZonePreferenceW");
1293 pPrivacySetZonePreferenceW = (void*)GetProcAddress(hdll, "PrivacySetZonePreferenceW");
1295 test_InternetCanonicalizeUrlA();
1296 test_InternetQueryOptionA();
1298 test_complicated_cookie();
1301 test_Option_PerConnectionOption();
1302 test_Option_PerConnectionOptionA();
1303 test_InternetErrorDlg();
1305 if (!pInternetTimeFromSystemTimeA)
1306 win_skip("skipping the InternetTime tests\n");
1309 InternetTimeFromSystemTimeA_test();
1310 InternetTimeFromSystemTimeW_test();
1311 InternetTimeToSystemTimeA_test();
1312 InternetTimeToSystemTimeW_test();
1314 if (pIsDomainLegalCookieDomainW &&
1315 ((void*)pIsDomainLegalCookieDomainW == (void*)pCreateUrlCacheContainerA ||
1316 (void*)pIsDomainLegalCookieDomainW == (void*)pCreateUrlCacheContainerW))
1317 win_skip("IsDomainLegalCookieDomainW is not available on systems with IE5\n");
1318 else if (!pIsDomainLegalCookieDomainW)
1319 win_skip("IsDomainLegalCookieDomainW (or ordinal 117) is not available\n");
1321 test_IsDomainLegalCookieDomainW();
1323 if (pPrivacyGetZonePreferenceW && pPrivacySetZonePreferenceW)
1324 test_PrivacyGetSetZonePreferenceW();
1326 win_skip("Privacy[SG]etZonePreferenceW are not available\n");
1328 test_InternetSetOption();