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
31 #include "wine/test.h"
33 static BOOL (WINAPI *pCreateUrlCacheContainerA)(DWORD, DWORD, DWORD, DWORD,
34 DWORD, DWORD, DWORD, DWORD);
35 static BOOL (WINAPI *pCreateUrlCacheContainerW)(DWORD, DWORD, DWORD, DWORD,
36 DWORD, DWORD, DWORD, DWORD);
37 static BOOL (WINAPI *pInternetTimeFromSystemTimeA)(CONST SYSTEMTIME *,DWORD ,LPSTR ,DWORD);
38 static BOOL (WINAPI *pInternetTimeFromSystemTimeW)(CONST SYSTEMTIME *,DWORD ,LPWSTR ,DWORD);
39 static BOOL (WINAPI *pInternetTimeToSystemTimeA)(LPCSTR ,SYSTEMTIME *,DWORD);
40 static BOOL (WINAPI *pInternetTimeToSystemTimeW)(LPCWSTR ,SYSTEMTIME *,DWORD);
41 static BOOL (WINAPI *pIsDomainLegalCookieDomainW)(LPCWSTR, LPCWSTR);
42 static DWORD (WINAPI *pPrivacyGetZonePreferenceW)(DWORD, DWORD, LPDWORD, LPWSTR, LPDWORD);
43 static DWORD (WINAPI *pPrivacySetZonePreferenceW)(DWORD, DWORD, DWORD, LPCWSTR);
44 static BOOL (WINAPI *pInternetGetCookieExA)(LPCSTR,LPCSTR,LPSTR,LPDWORD,DWORD,LPVOID);
45 static BOOL (WINAPI *pInternetGetCookieExW)(LPCWSTR,LPCWSTR,LPWSTR,LPDWORD,DWORD,LPVOID);
47 /* ############################### */
49 static void test_InternetCanonicalizeUrlA(void)
57 /* Acrobat Updater 5 calls this for Adobe Reader 8.1 */
58 url = "http://swupmf.adobe.com/manifest/50/win/AdobeUpdater.upd";
59 urllen = lstrlenA(url);
61 memset(buffer, '#', sizeof(buffer)-1);
62 buffer[sizeof(buffer)-1] = '\0';
63 dwSize = 1; /* Acrobat Updater use this size */
64 SetLastError(0xdeadbeef);
65 res = InternetCanonicalizeUrlA(url, buffer, &dwSize, 0);
66 ok( !res && (GetLastError() == ERROR_INSUFFICIENT_BUFFER) && (dwSize == (urllen+1)),
67 "got %u and %u with size %u for '%s' (%d)\n",
68 res, GetLastError(), dwSize, buffer, lstrlenA(buffer));
71 /* buffer has no space for the terminating '\0' */
72 memset(buffer, '#', sizeof(buffer)-1);
73 buffer[sizeof(buffer)-1] = '\0';
75 SetLastError(0xdeadbeef);
76 res = InternetCanonicalizeUrlA(url, buffer, &dwSize, 0);
77 /* dwSize is nr. of needed bytes with the terminating '\0' */
78 ok( !res && (GetLastError() == ERROR_INSUFFICIENT_BUFFER) && (dwSize == (urllen+1)),
79 "got %u and %u with size %u for '%s' (%d)\n",
80 res, GetLastError(), dwSize, buffer, lstrlenA(buffer));
82 /* buffer has the required size */
83 memset(buffer, '#', sizeof(buffer)-1);
84 buffer[sizeof(buffer)-1] = '\0';
86 SetLastError(0xdeadbeef);
87 res = InternetCanonicalizeUrlA(url, buffer, &dwSize, 0);
88 /* dwSize is nr. of copied bytes without the terminating '\0' */
89 ok( res && (dwSize == urllen) && (lstrcmpA(url, buffer) == 0),
90 "got %u and %u with size %u for '%s' (%d)\n",
91 res, GetLastError(), dwSize, buffer, lstrlenA(buffer));
93 memset(buffer, '#', sizeof(buffer)-1);
94 buffer[sizeof(buffer)-1] = '\0';
95 dwSize = sizeof(buffer);
96 SetLastError(0xdeadbeef);
97 res = InternetCanonicalizeUrlA("file:///C:/Program%20Files/Atmel/AVR%20Tools/STK500/STK500.xml", buffer, &dwSize, ICU_DECODE | ICU_NO_ENCODE);
98 ok(res, "InternetCanonicalizeUrlA failed %u\n", GetLastError());
99 ok(dwSize == lstrlenA(buffer), "got %d expected %d\n", dwSize, lstrlenA(buffer));
100 ok(!lstrcmpA("file://C:\\Program Files\\Atmel\\AVR Tools\\STK500\\STK500.xml", buffer),
101 "got %s expected 'file://C:\\Program Files\\Atmel\\AVR Tools\\STK500\\STK500.xml'\n", buffer);
103 /* buffer is larger as the required size */
104 memset(buffer, '#', sizeof(buffer)-1);
105 buffer[sizeof(buffer)-1] = '\0';
107 SetLastError(0xdeadbeef);
108 res = InternetCanonicalizeUrlA(url, buffer, &dwSize, 0);
109 /* dwSize is nr. of copied bytes without the terminating '\0' */
110 ok( res && (dwSize == urllen) && (lstrcmpA(url, buffer) == 0),
111 "got %u and %u with size %u for '%s' (%d)\n",
112 res, GetLastError(), dwSize, buffer, lstrlenA(buffer));
115 /* check NULL pointers */
116 memset(buffer, '#', urllen + 4);
117 buffer[urllen + 4] = '\0';
119 SetLastError(0xdeadbeef);
120 res = InternetCanonicalizeUrlA(NULL, buffer, &dwSize, 0);
121 ok( !res && (GetLastError() == ERROR_INVALID_PARAMETER),
122 "got %u and %u with size %u for '%s' (%d)\n",
123 res, GetLastError(), dwSize, buffer, lstrlenA(buffer));
125 memset(buffer, '#', urllen + 4);
126 buffer[urllen + 4] = '\0';
128 SetLastError(0xdeadbeef);
129 res = InternetCanonicalizeUrlA(url, NULL, &dwSize, 0);
130 ok( !res && (GetLastError() == ERROR_INVALID_PARAMETER),
131 "got %u and %u with size %u for '%s' (%d)\n",
132 res, GetLastError(), dwSize, buffer, lstrlenA(buffer));
134 memset(buffer, '#', urllen + 4);
135 buffer[urllen + 4] = '\0';
137 SetLastError(0xdeadbeef);
138 res = InternetCanonicalizeUrlA(url, buffer, NULL, 0);
139 ok( !res && (GetLastError() == ERROR_INVALID_PARAMETER),
140 "got %u and %u with size %u for '%s' (%d)\n",
141 res, GetLastError(), dwSize, buffer, lstrlenA(buffer));
143 /* test with trailing space */
145 res = InternetCanonicalizeUrlA("http://www.winehq.org/index.php?x= ", buffer, &dwSize, ICU_BROWSER_MODE);
146 ok(res == 1, "InternetCanonicalizeUrlA failed\n");
147 ok(!strcmp(buffer, "http://www.winehq.org/index.php?x="), "Trailing space should have been stripped even in ICU_BROWSER_MODE (%s)\n", buffer);
149 res = InternetSetOptionA(NULL, 0xdeadbeef, buffer, sizeof(buffer));
150 ok(!res, "InternetSetOptionA succeeded\n");
151 ok(GetLastError() == ERROR_INTERNET_INVALID_OPTION,
152 "InternetSetOptionA failed %u, expected ERROR_INTERNET_INVALID_OPTION\n", GetLastError());
155 /* ############################### */
157 static void test_InternetQueryOptionA(void)
159 HINTERNET hinet,hurl;
162 static const char useragent[] = {"Wininet Test"};
167 hinet = InternetOpenA(useragent,INTERNET_OPEN_TYPE_DIRECT,NULL,NULL, 0);
168 ok((hinet != 0x0),"InternetOpen Failed\n");
170 SetLastError(0xdeadbeef);
171 retval=InternetQueryOptionA(NULL,INTERNET_OPTION_USER_AGENT,NULL,&len);
173 ok(retval == 0,"Got wrong return value %d\n",retval);
174 ok(err == ERROR_INTERNET_INCORRECT_HANDLE_TYPE, "Got wrong error code%d\n",err);
176 SetLastError(0xdeadbeef);
177 len=strlen(useragent)+1;
178 retval=InternetQueryOptionA(hinet,INTERNET_OPTION_USER_AGENT,NULL,&len);
180 ok(len == strlen(useragent)+1,"Got wrong user agent length %d instead of %d\n",len,lstrlenA(useragent));
181 ok(retval == 0,"Got wrong return value %d\n",retval);
182 ok(err == ERROR_INSUFFICIENT_BUFFER, "Got wrong error code %d\n",err);
184 SetLastError(0xdeadbeef);
185 len=strlen(useragent)+1;
186 buffer=HeapAlloc(GetProcessHeap(),0,len);
187 retval=InternetQueryOptionA(hinet,INTERNET_OPTION_USER_AGENT,buffer,&len);
189 ok(retval == 1,"Got wrong return value %d\n",retval);
192 ok(!strcmp(useragent,buffer),"Got wrong user agent string %s instead of %s\n",buffer,useragent);
193 ok(len == strlen(useragent),"Got wrong user agent length %d instead of %d\n",len,lstrlenA(useragent));
195 ok(err == 0xdeadbeef, "Got wrong error code %d\n",err);
196 HeapFree(GetProcessHeap(),0,buffer);
198 SetLastError(0xdeadbeef);
200 buffer=HeapAlloc(GetProcessHeap(),0,100);
201 retval=InternetQueryOptionA(hinet,INTERNET_OPTION_USER_AGENT,buffer,&len);
203 ok(len == strlen(useragent) + 1,"Got wrong user agent length %d instead of %d\n", len, lstrlenA(useragent) + 1);
204 ok(!retval, "Got wrong return value %d\n", retval);
205 ok(err == ERROR_INSUFFICIENT_BUFFER, "Got wrong error code %d\n", err);
206 HeapFree(GetProcessHeap(),0,buffer);
208 hurl = InternetConnectA(hinet,"www.winehq.org",INTERNET_DEFAULT_HTTP_PORT,NULL,NULL,INTERNET_SERVICE_HTTP,0,0);
210 SetLastError(0xdeadbeef);
212 retval = InternetQueryOptionA(hurl,INTERNET_OPTION_USER_AGENT,NULL,&len);
214 ok(len == 0,"Got wrong user agent length %d instead of 0\n",len);
215 ok(retval == 0,"Got wrong return value %d\n",retval);
216 ok(err == ERROR_INTERNET_INCORRECT_HANDLE_TYPE, "Got wrong error code %d\n",err);
218 SetLastError(0xdeadbeef);
220 retval = InternetQueryOptionA(hurl,INTERNET_OPTION_REQUEST_FLAGS,NULL,&len);
221 err = GetLastError();
222 ok(retval == 0,"Got wrong return value %d\n",retval);
223 ok(err == ERROR_INTERNET_INCORRECT_HANDLE_TYPE, "Got wrong error code %d\n",err);
224 ok(len == sizeof(DWORD), "len = %d\n", len);
226 SetLastError(0xdeadbeef);
228 retval = InternetQueryOptionA(NULL,INTERNET_OPTION_REQUEST_FLAGS,NULL,&len);
229 err = GetLastError();
230 ok(retval == 0,"Got wrong return value %d\n",retval);
231 ok(err == ERROR_INTERNET_INCORRECT_HANDLE_TYPE, "Got wrong error code %d\n",err);
232 ok(!len, "len = %d\n", len);
234 InternetCloseHandle(hurl);
235 InternetCloseHandle(hinet);
237 hinet = InternetOpenA("",INTERNET_OPEN_TYPE_DIRECT,NULL,NULL, 0);
238 ok((hinet != 0x0),"InternetOpen Failed\n");
240 SetLastError(0xdeadbeef);
242 retval=InternetQueryOptionA(hinet,INTERNET_OPTION_USER_AGENT,NULL,&len);
244 ok(len == 1,"Got wrong user agent length %d instead of %d\n",len,1);
245 ok(retval == 0,"Got wrong return value %d\n",retval);
246 ok(err == ERROR_INSUFFICIENT_BUFFER, "Got wrong error code%d\n",err);
248 InternetCloseHandle(hinet);
251 res = InternetSetOptionA(NULL, INTERNET_OPTION_CONNECT_TIMEOUT, &val, sizeof(val));
252 ok(res, "InternetSetOptionA(INTERNET_OPTION_CONNECT_TIMEOUT) failed (%u)\n", GetLastError());
255 res = InternetQueryOptionA(NULL, INTERNET_OPTION_CONNECT_TIMEOUT, &val, &len);
256 ok(res, "InternetQueryOptionA failed %d)\n", GetLastError());
257 ok(val == 12345, "val = %d\n", val);
258 ok(len == sizeof(val), "len = %d\n", len);
260 hinet = InternetOpenA(NULL,INTERNET_OPEN_TYPE_DIRECT,NULL,NULL, 0);
261 ok((hinet != 0x0),"InternetOpen Failed\n");
262 SetLastError(0xdeadbeef);
264 retval=InternetQueryOptionA(hinet,INTERNET_OPTION_USER_AGENT,NULL,&len);
266 ok(len == 1,"Got wrong user agent length %d instead of %d\n",len,1);
267 ok(retval == 0,"Got wrong return value %d\n",retval);
268 ok(err == ERROR_INSUFFICIENT_BUFFER, "Got wrong error code%d\n",err);
272 res = InternetQueryOptionA(hinet, INTERNET_OPTION_MAX_CONNS_PER_SERVER, &val, &len);
273 ok(!res, "InternetQueryOptionA(INTERNET_OPTION_MAX_CONNS_PER_SERVER) succeeded\n");
274 ok(GetLastError() == ERROR_INTERNET_INVALID_OPERATION, "GetLastError() = %u\n", GetLastError());
277 res = InternetSetOptionA(hinet, INTERNET_OPTION_MAX_CONNS_PER_SERVER, &val, sizeof(val));
278 ok(!res, "InternetSetOptionA(INTERNET_OPTION_MAX_CONNS_PER_SERVER) succeeded\n");
279 ok(GetLastError() == ERROR_INTERNET_INVALID_OPERATION, "GetLastError() = %u\n", GetLastError());
282 res = InternetQueryOptionA(hinet, INTERNET_OPTION_CONNECT_TIMEOUT, &val, &len);
283 ok(res, "InternetQueryOptionA failed %d)\n", GetLastError());
284 ok(val == 12345, "val = %d\n", val);
285 ok(len == sizeof(val), "len = %d\n", len);
288 res = InternetSetOptionA(hinet, INTERNET_OPTION_CONNECT_TIMEOUT, &val, sizeof(val));
289 ok(res, "InternetSetOptionA(INTERNET_OPTION_CONNECT_TIMEOUT) failed (%u)\n", GetLastError());
292 res = InternetQueryOptionA(hinet, INTERNET_OPTION_CONNECT_TIMEOUT, &val, &len);
293 ok(res, "InternetQueryOptionA failed %d)\n", GetLastError());
294 ok(val == 1, "val = %d\n", val);
295 ok(len == sizeof(val), "len = %d\n", len);
298 res = InternetQueryOptionA(NULL, INTERNET_OPTION_CONNECT_TIMEOUT, &val, &len);
299 ok(res, "InternetQueryOptionA failed %d)\n", GetLastError());
300 ok(val == 12345, "val = %d\n", val);
301 ok(len == sizeof(val), "len = %d\n", len);
303 InternetCloseHandle(hinet);
306 static void test_max_conns(void)
313 res = InternetQueryOptionA(NULL, INTERNET_OPTION_MAX_CONNS_PER_SERVER, &val, &len);
314 ok(res,"Got wrong return value %x\n", res);
315 ok(len == sizeof(val), "got %d\n", len);
316 ok(val == 2, "got %d\n", val);
320 res = InternetQueryOptionA(NULL, INTERNET_OPTION_MAX_CONNS_PER_1_0_SERVER, &val, &len);
321 ok(res,"Got wrong return value %x\n", res);
322 ok(len == sizeof(val), "got %d\n", len);
323 ok(val == 4, "got %d\n", val);
326 res = InternetSetOptionA(NULL, INTERNET_OPTION_MAX_CONNS_PER_SERVER, &val, sizeof(val));
327 ok(res, "InternetSetOptionA(INTERNET_OPTION_MAX_CONNS_PER_SERVER) failed: %x\n", res);
331 res = InternetQueryOptionA(NULL, INTERNET_OPTION_MAX_CONNS_PER_SERVER, &val, &len);
332 ok(res,"Got wrong return value %x\n", res);
333 ok(len == sizeof(val), "got %d\n", len);
334 ok(val == 3, "got %d\n", val);
337 res = InternetSetOptionA(NULL, INTERNET_OPTION_MAX_CONNS_PER_SERVER, &val, sizeof(val));
338 ok(!res || broken(res), /* <= w2k3 */
339 "InternetSetOptionA(INTERNET_OPTION_MAX_CONNS_PER_SERVER, 0) succeeded\n");
340 if (!res) ok(GetLastError() == ERROR_BAD_ARGUMENTS, "GetLastError() = %u\n", GetLastError());
343 res = InternetSetOptionA(NULL, INTERNET_OPTION_MAX_CONNS_PER_SERVER, &val, sizeof(val)-1);
344 ok(!res, "InternetSetOptionA(INTERNET_OPTION_MAX_CONNS_PER_SERVER) succeeded\n");
345 ok(GetLastError() == ERROR_INTERNET_BAD_OPTION_LENGTH, "GetLastError() = %u\n", GetLastError());
348 res = InternetSetOptionA(NULL, INTERNET_OPTION_MAX_CONNS_PER_SERVER, &val, sizeof(val)+1);
349 ok(!res, "InternetSetOptionA(INTERNET_OPTION_MAX_CONNS_PER_SERVER) succeeded\n");
350 ok(GetLastError() == ERROR_INTERNET_BAD_OPTION_LENGTH, "GetLastError() = %u\n", GetLastError());
353 static void test_get_cookie(void)
358 SetLastError(0xdeadbeef);
359 ret = InternetGetCookie("http://www.example.com", NULL, NULL, &len);
360 ok(!ret && GetLastError() == ERROR_NO_MORE_ITEMS,
361 "InternetGetCookie should have failed with %s and error %d\n",
362 ret ? "TRUE" : "FALSE", GetLastError());
366 static void test_complicated_cookie(void)
375 static const WCHAR testing_example_comW[] =
376 {'h','t','t','p',':','/','/','t','e','s','t','i','n','g','.','e','x','a','m','p','l','e','.','c','o','m',0};
378 ret = InternetSetCookie("http://www.example.com/bar",NULL,"A=B; domain=.example.com");
379 ok(ret == TRUE,"InternetSetCookie failed\n");
380 ret = InternetSetCookie("http://www.example.com/bar",NULL,"C=D; domain=.example.com; path=/");
381 ok(ret == TRUE,"InternetSetCookie failed\n");
383 /* Technically illegal! domain should require 2 dots, but native wininet accepts it */
384 ret = InternetSetCookie("http://www.example.com",NULL,"E=F; domain=example.com");
385 ok(ret == TRUE,"InternetSetCookie failed\n");
386 ret = InternetSetCookie("http://www.example.com",NULL,"G=H; domain=.example.com; path=/foo");
387 ok(ret == TRUE,"InternetSetCookie failed\n");
388 ret = InternetSetCookie("http://www.example.com/bar.html",NULL,"I=J; domain=.example.com");
389 ok(ret == TRUE,"InternetSetCookie failed\n");
390 ret = InternetSetCookie("http://www.example.com/bar/",NULL,"K=L; domain=.example.com");
391 ok(ret == TRUE,"InternetSetCookie failed\n");
392 ret = InternetSetCookie("http://www.example.com/bar/",NULL,"M=N; domain=.example.com; path=/foo/");
393 ok(ret == TRUE,"InternetSetCookie failed\n");
394 ret = InternetSetCookie("http://www.example.com/bar/",NULL,"O=P; secure; path=/bar");
395 ok(ret == TRUE,"InternetSetCookie failed\n");
398 ret = InternetGetCookie("http://testing.example.com", NULL, NULL, &len);
399 ok(ret == TRUE,"InternetGetCookie failed\n");
400 ok(len == 19, "len = %u\n", len);
403 memset(buffer, 0xac, sizeof(buffer));
404 ret = InternetGetCookie("http://testing.example.com", NULL, buffer, &len);
405 ok(ret == TRUE,"InternetGetCookie failed\n");
406 ok(len == 19, "len = %u\n", len);
407 ok(strlen(buffer) == 18, "strlen(buffer) = %u\n", lstrlenA(buffer));
408 ok(strstr(buffer,"A=B")!=NULL,"A=B missing\n");
409 ok(strstr(buffer,"C=D")!=NULL,"C=D missing\n");
410 ok(strstr(buffer,"E=F")!=NULL,"E=F missing\n");
411 ok(strstr(buffer,"G=H")==NULL,"G=H present\n");
412 ok(strstr(buffer,"I=J")!=NULL,"I=J missing\n");
413 ok(strstr(buffer,"K=L")==NULL,"K=L present\n");
414 ok(strstr(buffer,"M=N")==NULL,"M=N present\n");
415 ok(strstr(buffer,"O=P")==NULL,"O=P present\n");
418 ret = InternetGetCookieW(testing_example_comW, NULL, NULL, &len);
419 ok(ret == TRUE,"InternetGetCookieW failed\n");
420 ok(len == 38, "len = %u\n", len);
423 memset(wbuf, 0xac, sizeof(wbuf));
424 ret = InternetGetCookieW(testing_example_comW, NULL, wbuf, &len);
425 ok(ret == TRUE,"InternetGetCookieW failed\n");
426 ok(len == 19, "len = %u\n", len);
427 ok(lstrlenW(wbuf) == 18, "strlenW(wbuf) = %u\n", lstrlenW(wbuf));
430 ret = InternetGetCookie("http://testing.example.com/foobar", NULL, buffer, &len);
431 ok(ret == TRUE,"InternetGetCookie failed\n");
432 ok(strstr(buffer,"A=B")!=NULL,"A=B missing\n");
433 ok(strstr(buffer,"C=D")!=NULL,"C=D missing\n");
434 ok(strstr(buffer,"E=F")!=NULL,"E=F missing\n");
435 ok(strstr(buffer,"G=H")==NULL,"G=H present\n");
436 ok(strstr(buffer,"I=J")!=NULL,"I=J missing\n");
437 ok(strstr(buffer,"K=L")==NULL,"K=L present\n");
438 ok(strstr(buffer,"M=N")==NULL,"M=N present\n");
439 ok(strstr(buffer,"O=P")==NULL,"O=P present\n");
442 ret = InternetGetCookie("http://testing.example.com/foobar/", NULL, buffer, &len);
443 ok(ret == TRUE,"InternetGetCookie failed\n");
444 ok(strstr(buffer,"A=B")!=NULL,"A=B missing\n");
445 ok(strstr(buffer,"C=D")!=NULL,"C=D missing\n");
446 ok(strstr(buffer,"E=F")!=NULL,"E=F missing\n");
447 ok(strstr(buffer,"G=H")!=NULL,"G=H missing\n");
448 ok(strstr(buffer,"I=J")!=NULL,"I=J missing\n");
449 ok(strstr(buffer,"K=L")==NULL,"K=L present\n");
450 ok(strstr(buffer,"M=N")==NULL,"M=N present\n");
451 ok(strstr(buffer,"O=P")==NULL,"O=P present\n");
454 ret = InternetGetCookie("http://testing.example.com/foo/bar", NULL, buffer, &len);
455 ok(ret == TRUE,"InternetGetCookie failed\n");
456 ok(strstr(buffer,"A=B")!=NULL,"A=B missing\n");
457 ok(strstr(buffer,"C=D")!=NULL,"C=D missing\n");
458 ok(strstr(buffer,"E=F")!=NULL,"E=F missing\n");
459 ok(strstr(buffer,"G=H")!=NULL,"G=H missing\n");
460 ok(strstr(buffer,"I=J")!=NULL,"I=J missing\n");
461 ok(strstr(buffer,"K=L")==NULL,"K=L present\n");
462 ok(strstr(buffer,"M=N")!=NULL,"M=N missing\n");
463 ok(strstr(buffer,"O=P")==NULL,"O=P present\n");
466 ret = InternetGetCookie("http://testing.example.com/barfoo", NULL, buffer, &len);
467 ok(ret == TRUE,"InternetGetCookie failed\n");
468 ok(strstr(buffer,"A=B")!=NULL,"A=B missing\n");
469 ok(strstr(buffer,"C=D")!=NULL,"C=D missing\n");
470 ok(strstr(buffer,"E=F")!=NULL,"E=F missing\n");
471 ok(strstr(buffer,"G=H")==NULL,"G=H present\n");
472 ok(strstr(buffer,"I=J")!=NULL,"I=J missing\n");
473 ok(strstr(buffer,"K=L")==NULL,"K=L present\n");
474 ok(strstr(buffer,"M=N")==NULL,"M=N present\n");
475 ok(strstr(buffer,"O=P")==NULL,"O=P present\n");
478 ret = InternetGetCookie("http://testing.example.com/barfoo/", NULL, buffer, &len);
479 ok(ret == TRUE,"InternetGetCookie failed\n");
480 ok(strstr(buffer,"A=B")!=NULL,"A=B missing\n");
481 ok(strstr(buffer,"C=D")!=NULL,"C=D missing\n");
482 ok(strstr(buffer,"E=F")!=NULL,"E=F missing\n");
483 ok(strstr(buffer,"G=H")==NULL,"G=H present\n");
484 ok(strstr(buffer,"I=J")!=NULL,"I=J missing\n");
485 ok(strstr(buffer,"K=L")==NULL,"K=L present\n");
486 ok(strstr(buffer,"M=N")==NULL,"M=N present\n");
487 ok(strstr(buffer,"O=P")==NULL,"O=P present\n");
490 ret = InternetGetCookie("http://testing.example.com/bar/foo", NULL, buffer, &len);
491 ok(ret == TRUE,"InternetGetCookie failed\n");
492 ok(len == 24, "len = %u\n", 24);
493 ok(strstr(buffer,"A=B")!=NULL,"A=B missing\n");
494 ok(strstr(buffer,"C=D")!=NULL,"C=D missing\n");
495 ok(strstr(buffer,"E=F")!=NULL,"E=F missing\n");
496 ok(strstr(buffer,"G=H")==NULL,"G=H present\n");
497 ok(strstr(buffer,"I=J")!=NULL,"I=J missing\n");
498 ok(strstr(buffer,"K=L")!=NULL,"K=L missing\n");
499 ok(strstr(buffer,"M=N")==NULL,"M=N present\n");
500 ok(strstr(buffer,"O=P")==NULL,"O=P present\n");
502 /* Cookie name argument is not implemented */
504 ret = InternetGetCookie("http://testing.example.com/bar/foo", "A", buffer, &len);
505 ok(ret == TRUE,"InternetGetCookie failed\n");
506 ok(len == 24, "len = %u\n", 24);
508 /* test persistent cookies */
509 ret = InternetSetCookie("http://testing.example.com", NULL, "A=B; expires=Fri, 01-Jan-2038 00:00:00 GMT");
510 ok(ret, "InternetSetCookie failed with error %d\n", GetLastError());
513 ret = GetUserName(user, &len);
514 ok(ret, "GetUserName failed with error %d\n", GetLastError());
516 user[len-1] = tolower(user[len-1]);
518 sprintf(buffer, "Cookie:%s@testing.example.com/", user);
519 ret = GetUrlCacheEntryInfo(buffer, NULL, &len);
520 ok(!ret, "GetUrlCacheEntryInfo succeeded\n");
521 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER, "GetLastError() = %d\n", GetLastError());
523 /* remove persistent cookie */
524 ret = InternetSetCookie("http://testing.example.com", NULL, "A=B");
525 ok(ret, "InternetSetCookie failed with error %d\n", GetLastError());
527 ret = GetUrlCacheEntryInfo(buffer, NULL, &len);
528 ok(!ret, "GetUrlCacheEntryInfo succeeded\n");
529 ok(GetLastError() == ERROR_FILE_NOT_FOUND, "GetLastError() = %d\n", GetLastError());
531 /* try setting cookie for different domain */
532 ret = InternetSetCookie("http://www.aaa.example.com/bar",NULL,"E=F; domain=different.com");
533 ok(!ret, "InternetSetCookie succeeded\n");
534 ok(GetLastError() == ERROR_INVALID_PARAMETER, "GetLastError() = %d\n", GetLastError());
535 ret = InternetSetCookie("http://www.aaa.example.com.pl/bar",NULL,"E=F; domain=example.com.pl");
536 ok(ret, "InternetSetCookie failed with error: %d\n", GetLastError());
537 ret = InternetSetCookie("http://www.aaa.example.com.pl/bar",NULL,"E=F; domain=com.pl");
538 todo_wine ok(!ret, "InternetSetCookie succeeded\n");
541 static void test_cookie_url(void)
548 static const WCHAR about_blankW[] = {'a','b','o','u','t',':','b','l','a','n','k',0};
551 res = InternetGetCookieA("about:blank", NULL, buf, &len);
552 ok(!res && GetLastError() == ERROR_INVALID_PARAMETER,
553 "InternetGetCookeA failed: %u, expected ERROR_INVALID_PARAMETER\n", GetLastError());
555 len = sizeof(bufw)/sizeof(*bufw);
556 res = InternetGetCookieW(about_blankW, NULL, bufw, &len);
557 ok(!res && GetLastError() == ERROR_INVALID_PARAMETER,
558 "InternetGetCookeW failed: %u, expected ERROR_INVALID_PARAMETER\n", GetLastError());
561 res = pInternetGetCookieExA("about:blank", NULL, buf, &len, 0, NULL);
562 ok(!res && GetLastError() == ERROR_INVALID_PARAMETER,
563 "InternetGetCookeExA failed: %u, expected ERROR_INVALID_PARAMETER\n", GetLastError());
565 len = sizeof(bufw)/sizeof(*bufw);
566 res = pInternetGetCookieExW(about_blankW, NULL, bufw, &len, 0, NULL);
567 ok(!res && GetLastError() == ERROR_INVALID_PARAMETER,
568 "InternetGetCookeExW failed: %u, expected ERROR_INVALID_PARAMETER\n", GetLastError());
571 static void test_null(void)
574 static const WCHAR szServer[] = { 's','e','r','v','e','r',0 };
575 static const WCHAR szEmpty[] = { 0 };
576 static const WCHAR szUrl[] = { 'h','t','t','p',':','/','/','a','.','b','.','c',0 };
577 static const WCHAR szUrlEmpty[] = { 'h','t','t','p',':','/','/',0 };
578 static const WCHAR szExpect[] = { 's','e','r','v','e','r',';',' ','s','e','r','v','e','r',0 };
583 SetLastError(0xdeadbeef);
584 hi = InternetOpenW(NULL, 0, NULL, NULL, 0);
585 if (hi == NULL && GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)
587 win_skip("Internet*W functions are not implemented\n");
590 ok(hi != NULL, "open failed\n");
592 hc = InternetConnectW(hi, NULL, 0, NULL, NULL, 0, 0, 0);
593 ok(GetLastError() == ERROR_INVALID_PARAMETER, "wrong error\n");
594 ok(hc == NULL, "connect failed\n");
596 hc = InternetConnectW(hi, NULL, 0, NULL, NULL, INTERNET_SERVICE_HTTP, 0, 0);
597 ok(GetLastError() == ERROR_INVALID_PARAMETER, "wrong error\n");
598 ok(hc == NULL, "connect failed\n");
600 hc = InternetConnectW(hi, NULL, 0, NULL, NULL, INTERNET_SERVICE_FTP, 0, 0);
601 ok(GetLastError() == ERROR_INVALID_PARAMETER, "wrong error\n");
602 ok(hc == NULL, "connect failed\n");
604 hc = InternetConnectW(NULL, szServer, 0, NULL, NULL, INTERNET_SERVICE_FTP, 0, 0);
605 ok(GetLastError() == ERROR_INVALID_HANDLE, "wrong error\n");
606 ok(hc == NULL, "connect failed\n");
608 hc = InternetOpenUrlW(hi, NULL, NULL, 0, 0, 0);
609 ok(GetLastError() == ERROR_INVALID_PARAMETER ||
610 GetLastError() == ERROR_INTERNET_UNRECOGNIZED_SCHEME, "wrong error\n");
611 ok(hc == NULL, "connect failed\n");
613 hc = InternetOpenUrlW(hi, szServer, NULL, 0, 0, 0);
614 ok(GetLastError() == ERROR_INTERNET_UNRECOGNIZED_SCHEME, "wrong error\n");
615 ok(hc == NULL, "connect failed\n");
617 InternetCloseHandle(hi);
619 r = InternetSetCookieW(NULL, NULL, NULL);
620 ok(GetLastError() == ERROR_INVALID_PARAMETER, "wrong error\n");
621 ok(r == FALSE, "return wrong\n");
623 r = InternetSetCookieW(szServer, NULL, NULL);
624 ok(GetLastError() == ERROR_INVALID_PARAMETER, "wrong error\n");
625 ok(r == FALSE, "return wrong\n");
627 r = InternetSetCookieW(szUrl, szServer, NULL);
628 ok(GetLastError() == ERROR_INVALID_PARAMETER, "wrong error\n");
629 ok(r == FALSE, "return wrong\n");
631 r = InternetSetCookieW(szUrl, szServer, szServer);
632 ok(r == TRUE, "return wrong\n");
634 r = InternetSetCookieW(szUrl, NULL, szServer);
635 ok(r == TRUE, "return wrong\n");
637 r = InternetSetCookieW(szUrl, szServer, szEmpty);
638 ok(r == TRUE, "return wrong\n");
640 r = InternetSetCookieW(szUrlEmpty, szServer, szServer);
641 ok(r == FALSE, "return wrong\n");
643 r = InternetSetCookieW(szServer, NULL, szServer);
645 ok(GetLastError() == ERROR_INTERNET_UNRECOGNIZED_SCHEME, "wrong error\n");
647 ok(r == FALSE, "return wrong\n");
650 r = InternetGetCookieW(NULL, NULL, NULL, &sz);
651 ok(GetLastError() == ERROR_INVALID_PARAMETER || GetLastError() == ERROR_INTERNET_UNRECOGNIZED_SCHEME,
652 "wrong error %u\n", GetLastError());
653 ok( r == FALSE, "return wrong\n");
655 r = InternetGetCookieW(szServer, NULL, NULL, &sz);
657 ok(GetLastError() == ERROR_INTERNET_UNRECOGNIZED_SCHEME, "wrong error\n");
659 ok( r == FALSE, "return wrong\n");
662 r = InternetGetCookieW(szUrlEmpty, szServer, NULL, &sz);
663 ok( r == FALSE, "return wrong\n");
666 r = InternetGetCookieW(szUrl, szServer, NULL, &sz);
667 ok( r == TRUE, "return wrong\n");
669 /* sz is 14 on XP SP2 and beyond, 30 on XP SP1 and before */
670 ok( sz == 14 || sz == 30, "sz wrong, got %u, expected 14 or 30\n", sz);
673 memset(buffer, 0, sizeof buffer);
674 r = InternetGetCookieW(szUrl, szServer, buffer, &sz);
675 ok( r == TRUE, "return wrong\n");
677 /* sz == lstrlenW(buffer) only in XP SP1 */
678 ok( sz == 1 + lstrlenW(buffer) || sz == lstrlenW(buffer), "sz wrong %d\n", sz);
680 /* before XP SP2, buffer is "server; server" */
681 ok( !lstrcmpW(szExpect, buffer) || !lstrcmpW(szServer, buffer), "cookie data wrong\n");
684 r = InternetQueryOptionA(NULL, INTERNET_OPTION_CONNECTED_STATE, buffer, &sz);
685 ok(r == TRUE, "ret %d\n", r);
688 static void test_version(void)
690 INTERNET_VERSION_INFO version;
694 size = sizeof(version);
695 res = InternetQueryOptionA(NULL, INTERNET_OPTION_VERSION, &version, &size);
696 ok(res, "Could not get version: %u\n", GetLastError());
697 ok(version.dwMajorVersion == 1, "dwMajorVersion=%d, expected 1\n", version.dwMajorVersion);
698 ok(version.dwMinorVersion == 2, "dwMinorVersion=%d, expected 2\n", version.dwMinorVersion);
701 static void InternetTimeFromSystemTimeA_test(void)
704 static const SYSTEMTIME time = { 2005, 1, 5, 7, 12, 6, 35, 0 };
705 char string[INTERNET_RFC1123_BUFSIZE];
706 static const char expect[] = "Fri, 07 Jan 2005 12:06:35 GMT";
709 ret = pInternetTimeFromSystemTimeA( &time, INTERNET_RFC1123_FORMAT, string, sizeof(string) );
710 ok( ret, "InternetTimeFromSystemTimeA failed (%u)\n", GetLastError() );
712 ok( !memcmp( string, expect, sizeof(expect) ),
713 "InternetTimeFromSystemTimeA failed (%u)\n", GetLastError() );
715 /* test NULL time parameter */
716 SetLastError(0xdeadbeef);
717 ret = pInternetTimeFromSystemTimeA( NULL, INTERNET_RFC1123_FORMAT, string, sizeof(string) );
718 error = GetLastError();
719 ok( !ret, "InternetTimeFromSystemTimeA should have returned FALSE\n" );
720 ok( error == ERROR_INVALID_PARAMETER,
721 "InternetTimeFromSystemTimeA failed with ERROR_INVALID_PARAMETER instead of %u\n",
724 /* test NULL string parameter */
725 SetLastError(0xdeadbeef);
726 ret = pInternetTimeFromSystemTimeA( &time, INTERNET_RFC1123_FORMAT, NULL, sizeof(string) );
727 error = GetLastError();
728 ok( !ret, "InternetTimeFromSystemTimeA should have returned FALSE\n" );
729 ok( error == ERROR_INVALID_PARAMETER,
730 "InternetTimeFromSystemTimeA failed with ERROR_INVALID_PARAMETER instead of %u\n",
733 /* test invalid format parameter */
734 SetLastError(0xdeadbeef);
735 ret = pInternetTimeFromSystemTimeA( &time, INTERNET_RFC1123_FORMAT + 1, string, sizeof(string) );
736 error = GetLastError();
737 ok( !ret, "InternetTimeFromSystemTimeA should have returned FALSE\n" );
738 ok( error == ERROR_INVALID_PARAMETER,
739 "InternetTimeFromSystemTimeA failed with ERROR_INVALID_PARAMETER instead of %u\n",
742 /* test too small buffer size */
743 SetLastError(0xdeadbeef);
744 ret = pInternetTimeFromSystemTimeA( &time, INTERNET_RFC1123_FORMAT, string, 0 );
745 error = GetLastError();
746 ok( !ret, "InternetTimeFromSystemTimeA should have returned FALSE\n" );
747 ok( error == ERROR_INSUFFICIENT_BUFFER,
748 "InternetTimeFromSystemTimeA failed with ERROR_INSUFFICIENT_BUFFER instead of %u\n",
752 static void InternetTimeFromSystemTimeW_test(void)
755 static const SYSTEMTIME time = { 2005, 1, 5, 7, 12, 6, 35, 0 };
756 WCHAR string[INTERNET_RFC1123_BUFSIZE + 1];
757 static const WCHAR expect[] = { 'F','r','i',',',' ','0','7',' ','J','a','n',' ','2','0','0','5',' ',
758 '1','2',':','0','6',':','3','5',' ','G','M','T',0 };
761 ret = pInternetTimeFromSystemTimeW( &time, INTERNET_RFC1123_FORMAT, string, sizeof(string) );
762 ok( ret, "InternetTimeFromSystemTimeW failed (%u)\n", GetLastError() );
764 ok( !memcmp( string, expect, sizeof(expect) ),
765 "InternetTimeFromSystemTimeW failed (%u)\n", GetLastError() );
767 /* test NULL time parameter */
768 SetLastError(0xdeadbeef);
769 ret = pInternetTimeFromSystemTimeW( NULL, INTERNET_RFC1123_FORMAT, string, sizeof(string) );
770 error = GetLastError();
771 ok( !ret, "InternetTimeFromSystemTimeW should have returned FALSE\n" );
772 ok( error == ERROR_INVALID_PARAMETER,
773 "InternetTimeFromSystemTimeW failed with ERROR_INVALID_PARAMETER instead of %u\n",
776 /* test NULL string parameter */
777 SetLastError(0xdeadbeef);
778 ret = pInternetTimeFromSystemTimeW( &time, INTERNET_RFC1123_FORMAT, NULL, sizeof(string) );
779 error = GetLastError();
780 ok( !ret, "InternetTimeFromSystemTimeW should have returned FALSE\n" );
781 ok( error == ERROR_INVALID_PARAMETER,
782 "InternetTimeFromSystemTimeW failed with ERROR_INVALID_PARAMETER instead of %u\n",
785 /* test invalid format parameter */
786 SetLastError(0xdeadbeef);
787 ret = pInternetTimeFromSystemTimeW( &time, INTERNET_RFC1123_FORMAT + 1, string, sizeof(string) );
788 error = GetLastError();
789 ok( !ret, "InternetTimeFromSystemTimeW should have returned FALSE\n" );
790 ok( error == ERROR_INVALID_PARAMETER,
791 "InternetTimeFromSystemTimeW failed with ERROR_INVALID_PARAMETER instead of %u\n",
794 /* test too small buffer size */
795 SetLastError(0xdeadbeef);
796 ret = pInternetTimeFromSystemTimeW( &time, INTERNET_RFC1123_FORMAT, string, sizeof(string)/sizeof(string[0]) );
797 error = GetLastError();
798 ok( !ret, "InternetTimeFromSystemTimeW should have returned FALSE\n" );
799 ok( error == ERROR_INSUFFICIENT_BUFFER,
800 "InternetTimeFromSystemTimeW failed with ERROR_INSUFFICIENT_BUFFER instead of %u\n",
804 static void InternetTimeToSystemTimeA_test(void)
808 static const SYSTEMTIME expect = { 2005, 1, 5, 7, 12, 6, 35, 0 };
809 static const char string[] = "Fri, 07 Jan 2005 12:06:35 GMT";
810 static const char string2[] = " fri 7 jan 2005 12 06 35";
812 ret = pInternetTimeToSystemTimeA( string, &time, 0 );
813 ok( ret, "InternetTimeToSystemTimeA failed (%u)\n", GetLastError() );
814 ok( !memcmp( &time, &expect, sizeof(expect) ),
815 "InternetTimeToSystemTimeA failed (%u)\n", GetLastError() );
817 ret = pInternetTimeToSystemTimeA( string2, &time, 0 );
818 ok( ret, "InternetTimeToSystemTimeA failed (%u)\n", GetLastError() );
819 ok( !memcmp( &time, &expect, sizeof(expect) ),
820 "InternetTimeToSystemTimeA failed (%u)\n", GetLastError() );
823 static void InternetTimeToSystemTimeW_test(void)
827 static const SYSTEMTIME expect = { 2005, 1, 5, 7, 12, 6, 35, 0 };
828 static const WCHAR string[] = { 'F','r','i',',',' ','0','7',' ','J','a','n',' ','2','0','0','5',' ',
829 '1','2',':','0','6',':','3','5',' ','G','M','T',0 };
830 static const WCHAR string2[] = { ' ','f','r','i',' ','7',' ','j','a','n',' ','2','0','0','5',' ',
831 '1','2',' ','0','6',' ','3','5',0 };
832 static const WCHAR string3[] = { 'F','r',0 };
834 ret = pInternetTimeToSystemTimeW( NULL, NULL, 0 );
835 ok( !ret, "InternetTimeToSystemTimeW succeeded (%u)\n", GetLastError() );
837 ret = pInternetTimeToSystemTimeW( NULL, &time, 0 );
838 ok( !ret, "InternetTimeToSystemTimeW succeeded (%u)\n", GetLastError() );
840 ret = pInternetTimeToSystemTimeW( string, NULL, 0 );
841 ok( !ret, "InternetTimeToSystemTimeW succeeded (%u)\n", GetLastError() );
843 ret = pInternetTimeToSystemTimeW( string, &time, 0 );
844 ok( ret, "InternetTimeToSystemTimeW failed (%u)\n", GetLastError() );
846 ret = pInternetTimeToSystemTimeW( string, &time, 0 );
847 ok( ret, "InternetTimeToSystemTimeW failed (%u)\n", GetLastError() );
848 ok( !memcmp( &time, &expect, sizeof(expect) ),
849 "InternetTimeToSystemTimeW failed (%u)\n", GetLastError() );
851 ret = pInternetTimeToSystemTimeW( string2, &time, 0 );
852 ok( ret, "InternetTimeToSystemTimeW failed (%u)\n", GetLastError() );
853 ok( !memcmp( &time, &expect, sizeof(expect) ),
854 "InternetTimeToSystemTimeW failed (%u)\n", GetLastError() );
856 ret = pInternetTimeToSystemTimeW( string3, &time, 0 );
857 ok( ret, "InternetTimeToSystemTimeW failed (%u)\n", GetLastError() );
860 static void test_IsDomainLegalCookieDomainW(void)
864 static const WCHAR empty[] = {0};
865 static const WCHAR dot[] = {'.',0};
866 static const WCHAR uk[] = {'u','k',0};
867 static const WCHAR com[] = {'c','o','m',0};
868 static const WCHAR dot_com[] = {'.','c','o','m',0};
869 static const WCHAR gmail_com[] = {'g','m','a','i','l','.','c','o','m',0};
870 static const WCHAR dot_gmail_com[] = {'.','g','m','a','i','l','.','c','o','m',0};
871 static const WCHAR www_gmail_com[] = {'w','w','w','.','g','m','a','i','l','.','c','o','m',0};
872 static const WCHAR www_mail_gmail_com[] = {'w','w','w','.','m','a','i','l','.','g','m','a','i','l','.','c','o','m',0};
873 static const WCHAR mail_gmail_com[] = {'m','a','i','l','.','g','m','a','i','l','.','c','o','m',0};
874 static const WCHAR gmail_co_uk[] = {'g','m','a','i','l','.','c','o','.','u','k',0};
875 static const WCHAR co_uk[] = {'c','o','.','u','k',0};
876 static const WCHAR dot_co_uk[] = {'.','c','o','.','u','k',0};
878 SetLastError(0xdeadbeef);
879 ret = pIsDomainLegalCookieDomainW(NULL, NULL);
880 error = GetLastError();
881 if (!ret && error == ERROR_CALL_NOT_IMPLEMENTED)
883 win_skip("IsDomainLegalCookieDomainW is not implemented\n");
887 broken(ret), /* IE6 */
888 "IsDomainLegalCookieDomainW succeeded\n");
889 ok(error == ERROR_INVALID_PARAMETER, "got %u expected ERROR_INVALID_PARAMETER\n", error);
891 SetLastError(0xdeadbeef);
892 ret = pIsDomainLegalCookieDomainW(com, NULL);
893 error = GetLastError();
894 ok(!ret, "IsDomainLegalCookieDomainW succeeded\n");
895 ok(error == ERROR_INVALID_PARAMETER, "got %u expected ERROR_INVALID_PARAMETER\n", error);
897 SetLastError(0xdeadbeef);
898 ret = pIsDomainLegalCookieDomainW(NULL, gmail_com);
899 error = GetLastError();
900 ok(!ret, "IsDomainLegalCookieDomainW succeeded\n");
901 ok(error == ERROR_INVALID_PARAMETER, "got %u expected ERROR_INVALID_PARAMETER\n", error);
903 SetLastError(0xdeadbeef);
904 ret = pIsDomainLegalCookieDomainW(empty, gmail_com);
905 error = GetLastError();
906 ok(!ret, "IsDomainLegalCookieDomainW succeeded\n");
907 ok(error == ERROR_INVALID_NAME ||
908 broken(error == ERROR_INVALID_PARAMETER), /* IE6 */
909 "got %u expected ERROR_INVALID_NAME\n", error);
911 SetLastError(0xdeadbeef);
912 ret = pIsDomainLegalCookieDomainW(com, empty);
913 error = GetLastError();
914 ok(!ret, "IsDomainLegalCookieDomainW succeeded\n");
915 ok(error == ERROR_INVALID_NAME ||
916 broken(error == ERROR_INVALID_PARAMETER), /* IE6 */
917 "got %u expected ERROR_INVALID_NAME\n", error);
919 SetLastError(0xdeadbeef);
920 ret = pIsDomainLegalCookieDomainW(gmail_com, dot);
921 error = GetLastError();
922 ok(!ret, "IsDomainLegalCookieDomainW succeeded\n");
923 ok(error == ERROR_INVALID_NAME ||
924 broken(error == 0xdeadbeef), /* IE6 */
925 "got %u expected ERROR_INVALID_NAME\n", error);
927 SetLastError(0xdeadbeef);
928 ret = pIsDomainLegalCookieDomainW(dot, gmail_com);
929 error = GetLastError();
930 ok(!ret, "IsDomainLegalCookieDomainW succeeded\n");
931 ok(error == ERROR_INVALID_NAME ||
932 broken(error == 0xdeadbeef), /* IE6 */
933 "got %u expected ERROR_INVALID_NAME\n", error);
935 SetLastError(0xdeadbeef);
936 ret = pIsDomainLegalCookieDomainW(com, com);
937 error = GetLastError();
938 ok(!ret, "IsDomainLegalCookieDomainW succeeded\n");
939 ok(error == 0xdeadbeef, "got %u expected 0xdeadbeef\n", error);
941 SetLastError(0xdeadbeef);
942 ret = pIsDomainLegalCookieDomainW(com, dot_com);
943 error = GetLastError();
944 ok(!ret, "IsDomainLegalCookieDomainW succeeded\n");
945 ok(error == ERROR_INVALID_NAME ||
946 broken(error == 0xdeadbeef), /* IE6 */
947 "got %u expected ERROR_INVALID_NAME\n", error);
949 SetLastError(0xdeadbeef);
950 ret = pIsDomainLegalCookieDomainW(dot_com, com);
951 error = GetLastError();
952 ok(!ret, "IsDomainLegalCookieDomainW succeeded\n");
953 ok(error == ERROR_INVALID_NAME ||
954 broken(error == 0xdeadbeef), /* IE6 */
955 "got %u expected ERROR_INVALID_NAME\n", error);
957 SetLastError(0xdeadbeef);
958 ret = pIsDomainLegalCookieDomainW(com, gmail_com);
959 error = GetLastError();
960 ok(!ret, "IsDomainLegalCookieDomainW succeeded\n");
961 ok(error == ERROR_SXS_KEY_NOT_FOUND ||
962 error == ERROR_SUCCESS || /* IE8 on W2K3 */
963 error == 0xdeadbeef, /* up to IE7 */
964 "unexpected error: %u\n", error);
966 ret = pIsDomainLegalCookieDomainW(gmail_com, gmail_com);
967 ok(ret, "IsDomainLegalCookieDomainW failed\n");
969 ret = pIsDomainLegalCookieDomainW(gmail_com, www_gmail_com);
970 ok(ret, "IsDomainLegalCookieDomainW failed\n");
972 ret = pIsDomainLegalCookieDomainW(gmail_com, www_mail_gmail_com);
973 ok(ret, "IsDomainLegalCookieDomainW failed\n");
975 SetLastError(0xdeadbeef);
976 ret = pIsDomainLegalCookieDomainW(gmail_co_uk, co_uk);
977 error = GetLastError();
978 ok(!ret, "IsDomainLegalCookieDomainW succeeded\n");
979 ok(error == ERROR_SXS_KEY_NOT_FOUND || /* IE8 on XP */
980 error == ERROR_FILE_NOT_FOUND || /* IE8 on Vista */
981 error == ERROR_SUCCESS || /* IE8 on W2K3 */
982 error == 0xdeadbeef, /* up to IE7 */
983 "unexpected error: %u\n", error);
985 ret = pIsDomainLegalCookieDomainW(uk, co_uk);
986 ok(!ret, "IsDomainLegalCookieDomainW succeeded\n");
988 ret = pIsDomainLegalCookieDomainW(gmail_co_uk, dot_co_uk);
989 ok(!ret, "IsDomainLegalCookieDomainW succeeded\n");
991 ret = pIsDomainLegalCookieDomainW(co_uk, gmail_co_uk);
992 todo_wine ok(!ret, "IsDomainLegalCookieDomainW succeeded\n");
994 ret = pIsDomainLegalCookieDomainW(gmail_co_uk, gmail_co_uk);
995 ok(ret, "IsDomainLegalCookieDomainW failed\n");
997 ret = pIsDomainLegalCookieDomainW(gmail_com, com);
998 ok(!ret, "IsDomainLegalCookieDomainW succeeded\n");
1000 SetLastError(0xdeadbeef);
1001 ret = pIsDomainLegalCookieDomainW(dot_gmail_com, mail_gmail_com);
1002 error = GetLastError();
1003 ok(!ret, "IsDomainLegalCookieDomainW succeeded\n");
1004 ok(error == ERROR_INVALID_NAME ||
1005 broken(error == 0xdeadbeef), /* IE6 */
1006 "got %u expected ERROR_INVALID_NAME\n", error);
1008 ret = pIsDomainLegalCookieDomainW(gmail_com, mail_gmail_com);
1009 ok(ret, "IsDomainLegalCookieDomainW failed\n");
1011 ret = pIsDomainLegalCookieDomainW(mail_gmail_com, gmail_com);
1012 ok(!ret, "IsDomainLegalCookieDomainW succeeded\n");
1014 ret = pIsDomainLegalCookieDomainW(mail_gmail_com, com);
1015 ok(!ret, "IsDomainLegalCookieDomainW succeeded\n");
1017 ret = pIsDomainLegalCookieDomainW(dot_gmail_com, mail_gmail_com);
1018 ok(!ret, "IsDomainLegalCookieDomainW succeeded\n");
1020 ret = pIsDomainLegalCookieDomainW(mail_gmail_com, dot_gmail_com);
1021 ok(!ret, "IsDomainLegalCookieDomainW succeeded\n");
1024 static void test_PrivacyGetSetZonePreferenceW(void)
1026 DWORD ret, zone, type, template, old_template;
1030 ret = pPrivacyGetZonePreferenceW(zone, type, NULL, NULL, NULL);
1031 ok(ret == 0, "expected ret == 0, got %u\n", ret);
1034 ret = pPrivacyGetZonePreferenceW(zone, type, &old_template, NULL, NULL);
1035 ok(ret == 0, "expected ret == 0, got %u\n", ret);
1038 ret = pPrivacySetZonePreferenceW(zone, type, template, NULL);
1039 ok(ret == 0, "expected ret == 0, got %u\n", ret);
1042 ret = pPrivacyGetZonePreferenceW(zone, type, &template, NULL, NULL);
1043 ok(ret == 0, "expected ret == 0, got %u\n", ret);
1044 ok(template == 5, "expected template == 5, got %u\n", template);
1047 ret = pPrivacySetZonePreferenceW(zone, type, old_template, NULL);
1048 ok(ret == 0, "expected ret == 0, got %u\n", ret);
1051 static void test_InternetSetOption(void)
1053 HINTERNET ses, con, req;
1058 ses = InternetOpen(NULL, INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, 0);
1059 ok(ses != 0, "InternetOpen failed: 0x%08x\n", GetLastError());
1060 con = InternetConnect(ses, "www.winehq.org", 80, NULL, NULL, INTERNET_SERVICE_HTTP, 0, 0);
1061 ok(con != 0, "InternetConnect failed: 0x%08x\n", GetLastError());
1062 req = HttpOpenRequest(con, "GET", "/", NULL, NULL, NULL, 0, 0);
1063 ok(req != 0, "HttpOpenRequest failed: 0x%08x\n", GetLastError());
1065 /* INTERNET_OPTION_POLICY tests */
1066 SetLastError(0xdeadbeef);
1067 ret = InternetSetOptionW(ses, INTERNET_OPTION_POLICY, NULL, 0);
1068 ok(ret == FALSE, "InternetSetOption should've failed\n");
1069 ok(GetLastError() == ERROR_INVALID_PARAMETER, "GetLastError should've "
1070 "given ERROR_INVALID_PARAMETER, gave: 0x%08x\n", GetLastError());
1072 SetLastError(0xdeadbeef);
1073 ret = InternetQueryOptionW(ses, INTERNET_OPTION_POLICY, NULL, 0);
1074 ok(ret == FALSE, "InternetQueryOption should've failed\n");
1075 ok(GetLastError() == ERROR_INVALID_PARAMETER, "GetLastError should've "
1076 "given ERROR_INVALID_PARAMETER, gave: 0x%08x\n", GetLastError());
1078 /* INTERNET_OPTION_ERROR_MASK tests */
1079 SetLastError(0xdeadbeef);
1080 size = sizeof(ulArg);
1081 ret = InternetQueryOptionW(NULL, INTERNET_OPTION_ERROR_MASK, (void*)&ulArg, &size);
1082 ok(ret == FALSE, "InternetQueryOption should've failed\n");
1083 ok(GetLastError() == ERROR_INTERNET_INCORRECT_HANDLE_TYPE, "GetLastError() = %x\n", GetLastError());
1085 SetLastError(0xdeadbeef);
1087 ret = InternetSetOption(NULL, INTERNET_OPTION_ERROR_MASK, (void*)&ulArg, sizeof(ULONG));
1088 ok(ret == FALSE, "InternetQueryOption should've failed\n");
1089 ok(GetLastError() == ERROR_INTERNET_INCORRECT_HANDLE_TYPE, "GetLastError() = %x\n", GetLastError());
1091 SetLastError(0xdeadbeef);
1093 ret = InternetSetOption(req, INTERNET_OPTION_ERROR_MASK, (void*)&ulArg, 20);
1094 ok(ret == FALSE, "InternetQueryOption should've failed\n");
1095 ok(GetLastError() == ERROR_INTERNET_BAD_OPTION_LENGTH, "GetLastError() = %d\n", GetLastError());
1097 SetLastError(0xdeadbeef);
1099 ret = InternetSetOption(req, INTERNET_OPTION_ERROR_MASK, (void*)&ulArg, sizeof(ULONG));
1100 ok(ret == TRUE, "InternetQueryOption should've succeeded\n");
1101 ok(GetLastError() == 0xdeadbeef, "GetLastError() = %d\n", GetLastError());
1103 SetLastError(0xdeadbeef);
1105 ret = InternetSetOption(req, INTERNET_OPTION_ERROR_MASK, (void*)&ulArg, sizeof(ULONG));
1106 ok(ret == FALSE, "InternetQueryOption should've failed\n");
1107 ok(GetLastError() == ERROR_INVALID_PARAMETER, "GetLastError() = %x\n", GetLastError());
1109 SetLastError(0xdeadbeef);
1111 ret = InternetSetOption(req, INTERNET_OPTION_ERROR_MASK, (void*)&ulArg, sizeof(ULONG));
1112 ok(ret == FALSE, "InternetQueryOption should've failed\n");
1113 ok(GetLastError() == ERROR_INVALID_PARAMETER, "GetLastError() = %x\n", GetLastError());
1115 ret = InternetCloseHandle(req);
1116 ok(ret == TRUE, "InternetCloseHandle failed: 0x%08x\n", GetLastError());
1117 ret = InternetCloseHandle(con);
1118 ok(ret == TRUE, "InternetCloseHandle failed: 0x%08x\n", GetLastError());
1119 ret = InternetCloseHandle(ses);
1120 ok(ret == TRUE, "InternetCloseHandle failed: 0x%08x\n", GetLastError());
1123 #define verifyProxyEnable(e) r_verifyProxyEnable(__LINE__, e)
1124 static void r_verifyProxyEnable(LONG l, DWORD exp)
1127 DWORD type, val, size = sizeof(DWORD);
1129 static const CHAR szInternetSettings[] = "Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings";
1130 static const CHAR szProxyEnable[] = "ProxyEnable";
1132 ret = RegOpenKeyA(HKEY_CURRENT_USER, szInternetSettings, &hkey);
1133 ok_(__FILE__,l) (!ret, "RegOpenKeyA failed: 0x%08x\n", ret);
1135 ret = RegQueryValueExA(hkey, szProxyEnable, 0, &type, (BYTE*)&val, &size);
1136 ok_(__FILE__,l) (!ret, "RegQueryValueExA failed: 0x%08x\n", ret);
1137 ok_(__FILE__,l) (type == REG_DWORD, "Expected regtype to be REG_DWORD, was: %d\n", type);
1138 ok_(__FILE__,l) (val == exp, "Expected ProxyEnabled to be %d, got: %d\n", exp, val);
1140 ret = RegCloseKey(hkey);
1141 ok_(__FILE__,l) (!ret, "RegCloseKey failed: 0x%08x\n", ret);
1144 static void test_Option_PerConnectionOption(void)
1147 DWORD size = sizeof(INTERNET_PER_CONN_OPTION_LISTW);
1148 INTERNET_PER_CONN_OPTION_LISTW list = {size};
1149 INTERNET_PER_CONN_OPTIONW *orig_settings;
1150 static WCHAR proxy_srvW[] = {'p','r','o','x','y','.','e','x','a','m','p','l','e',0};
1152 /* get the global IE proxy server info, to restore later */
1153 list.dwOptionCount = 2;
1154 list.pOptions = HeapAlloc(GetProcessHeap(), 0, 2 * sizeof(INTERNET_PER_CONN_OPTIONW));
1156 list.pOptions[0].dwOption = INTERNET_PER_CONN_PROXY_SERVER;
1157 list.pOptions[1].dwOption = INTERNET_PER_CONN_FLAGS;
1159 ret = InternetQueryOptionW(NULL, INTERNET_OPTION_PER_CONNECTION_OPTION,
1161 ok(ret == TRUE, "InternetQueryOption should've succeeded\n");
1162 orig_settings = list.pOptions;
1164 /* set the global IE proxy server */
1165 list.dwOptionCount = 2;
1166 list.pOptions = HeapAlloc(GetProcessHeap(), 0, 2 * sizeof(INTERNET_PER_CONN_OPTIONW));
1168 list.pOptions[0].dwOption = INTERNET_PER_CONN_PROXY_SERVER;
1169 list.pOptions[0].Value.pszValue = proxy_srvW;
1170 list.pOptions[1].dwOption = INTERNET_PER_CONN_FLAGS;
1171 list.pOptions[1].Value.dwValue = PROXY_TYPE_PROXY;
1173 ret = InternetSetOptionW(NULL, INTERNET_OPTION_PER_CONNECTION_OPTION,
1175 ok(ret == TRUE, "InternetSetOption should've succeeded\n");
1177 HeapFree(GetProcessHeap(), 0, list.pOptions);
1179 /* get & verify the global IE proxy server */
1180 list.dwOptionCount = 2;
1181 list.dwOptionError = 0;
1182 list.pOptions = HeapAlloc(GetProcessHeap(), 0, 2 * sizeof(INTERNET_PER_CONN_OPTIONW));
1184 list.pOptions[0].dwOption = INTERNET_PER_CONN_PROXY_SERVER;
1185 list.pOptions[1].dwOption = INTERNET_PER_CONN_FLAGS;
1187 ret = InternetQueryOptionW(NULL, INTERNET_OPTION_PER_CONNECTION_OPTION,
1189 ok(ret == TRUE, "InternetQueryOption should've succeeded\n");
1190 ok(!lstrcmpW(list.pOptions[0].Value.pszValue, proxy_srvW),
1191 "Retrieved proxy server should've been %s, was: %s\n",
1192 wine_dbgstr_w(proxy_srvW), wine_dbgstr_w(list.pOptions[0].Value.pszValue));
1193 ok(list.pOptions[1].Value.dwValue == PROXY_TYPE_PROXY,
1194 "Retrieved flags should've been PROXY_TYPE_PROXY, was: %d\n",
1195 list.pOptions[1].Value.dwValue);
1196 verifyProxyEnable(1);
1198 HeapFree(GetProcessHeap(), 0, list.pOptions[0].Value.pszValue);
1199 HeapFree(GetProcessHeap(), 0, list.pOptions);
1201 /* disable the proxy server */
1202 list.dwOptionCount = 1;
1203 list.pOptions = HeapAlloc(GetProcessHeap(), 0, sizeof(INTERNET_PER_CONN_OPTIONW));
1205 list.pOptions[0].dwOption = INTERNET_PER_CONN_FLAGS;
1206 list.pOptions[0].Value.dwValue = PROXY_TYPE_DIRECT;
1208 ret = InternetSetOptionW(NULL, INTERNET_OPTION_PER_CONNECTION_OPTION,
1210 ok(ret == TRUE, "InternetSetOption should've succeeded\n");
1212 HeapFree(GetProcessHeap(), 0, list.pOptions);
1214 /* verify that the proxy is disabled */
1215 list.dwOptionCount = 1;
1216 list.dwOptionError = 0;
1217 list.pOptions = HeapAlloc(GetProcessHeap(), 0, sizeof(INTERNET_PER_CONN_OPTIONW));
1219 list.pOptions[0].dwOption = INTERNET_PER_CONN_FLAGS;
1221 ret = InternetQueryOptionW(NULL, INTERNET_OPTION_PER_CONNECTION_OPTION,
1223 ok(ret == TRUE, "InternetQueryOption should've succeeded\n");
1224 ok(list.pOptions[0].Value.dwValue == PROXY_TYPE_DIRECT,
1225 "Retrieved flags should've been PROXY_TYPE_DIRECT, was: %d\n",
1226 list.pOptions[0].Value.dwValue);
1227 verifyProxyEnable(0);
1229 HeapFree(GetProcessHeap(), 0, list.pOptions);
1231 /* set the proxy flags to 'invalid' value */
1232 list.dwOptionCount = 1;
1233 list.pOptions = HeapAlloc(GetProcessHeap(), 0, sizeof(INTERNET_PER_CONN_OPTIONW));
1235 list.pOptions[0].dwOption = INTERNET_PER_CONN_FLAGS;
1236 list.pOptions[0].Value.dwValue = PROXY_TYPE_PROXY | PROXY_TYPE_DIRECT;
1238 ret = InternetSetOptionW(NULL, INTERNET_OPTION_PER_CONNECTION_OPTION,
1240 ok(ret == TRUE, "InternetSetOption should've succeeded\n");
1242 HeapFree(GetProcessHeap(), 0, list.pOptions);
1244 /* verify that the proxy is enabled */
1245 list.dwOptionCount = 1;
1246 list.dwOptionError = 0;
1247 list.pOptions = HeapAlloc(GetProcessHeap(), 0, sizeof(INTERNET_PER_CONN_OPTIONW));
1249 list.pOptions[0].dwOption = INTERNET_PER_CONN_FLAGS;
1251 ret = InternetQueryOptionW(NULL, INTERNET_OPTION_PER_CONNECTION_OPTION,
1253 ok(ret == TRUE, "InternetQueryOption should've succeeded\n");
1254 todo_wine ok(list.pOptions[0].Value.dwValue == (PROXY_TYPE_PROXY | PROXY_TYPE_DIRECT),
1255 "Retrieved flags should've been PROXY_TYPE_PROXY | PROXY_TYPE_DIRECT, was: %d\n",
1256 list.pOptions[0].Value.dwValue);
1257 verifyProxyEnable(1);
1259 HeapFree(GetProcessHeap(), 0, list.pOptions);
1261 /* restore original settings */
1262 list.dwOptionCount = 2;
1263 list.pOptions = orig_settings;
1265 ret = InternetSetOptionW(NULL, INTERNET_OPTION_PER_CONNECTION_OPTION,
1267 ok(ret == TRUE, "InternetSetOption should've succeeded\n");
1269 HeapFree(GetProcessHeap(), 0, list.pOptions);
1272 static void test_Option_PerConnectionOptionA(void)
1275 DWORD size = sizeof(INTERNET_PER_CONN_OPTION_LISTA);
1276 INTERNET_PER_CONN_OPTION_LISTA list = {size};
1277 INTERNET_PER_CONN_OPTIONA *orig_settings;
1278 char proxy_srv[] = "proxy.example";
1280 /* get the global IE proxy server info, to restore later */
1281 list.dwOptionCount = 2;
1282 list.pOptions = HeapAlloc(GetProcessHeap(), 0, 2 * sizeof(INTERNET_PER_CONN_OPTIONA));
1284 list.pOptions[0].dwOption = INTERNET_PER_CONN_PROXY_SERVER;
1285 list.pOptions[1].dwOption = INTERNET_PER_CONN_FLAGS;
1287 ret = InternetQueryOptionA(NULL, INTERNET_OPTION_PER_CONNECTION_OPTION,
1289 ok(ret == TRUE, "InternetQueryOption should've succeeded\n");
1290 orig_settings = list.pOptions;
1292 /* set the global IE proxy server */
1293 list.dwOptionCount = 2;
1294 list.pOptions = HeapAlloc(GetProcessHeap(), 0, 2 * sizeof(INTERNET_PER_CONN_OPTIONA));
1296 list.pOptions[0].dwOption = INTERNET_PER_CONN_PROXY_SERVER;
1297 list.pOptions[0].Value.pszValue = proxy_srv;
1298 list.pOptions[1].dwOption = INTERNET_PER_CONN_FLAGS;
1299 list.pOptions[1].Value.dwValue = PROXY_TYPE_PROXY;
1301 ret = InternetSetOptionA(NULL, INTERNET_OPTION_PER_CONNECTION_OPTION,
1303 ok(ret == TRUE, "InternetSetOption should've succeeded\n");
1305 HeapFree(GetProcessHeap(), 0, list.pOptions);
1307 /* get & verify the global IE proxy server */
1308 list.dwOptionCount = 2;
1309 list.dwOptionError = 0;
1310 list.pOptions = HeapAlloc(GetProcessHeap(), 0, 2 * sizeof(INTERNET_PER_CONN_OPTIONA));
1312 list.pOptions[0].dwOption = INTERNET_PER_CONN_PROXY_SERVER;
1313 list.pOptions[1].dwOption = INTERNET_PER_CONN_FLAGS;
1315 ret = InternetQueryOptionA(NULL, INTERNET_OPTION_PER_CONNECTION_OPTION,
1317 ok(ret == TRUE, "InternetQueryOption should've succeeded\n");
1318 ok(!lstrcmpA(list.pOptions[0].Value.pszValue, "proxy.example"),
1319 "Retrieved proxy server should've been \"%s\", was: \"%s\"\n",
1320 proxy_srv, list.pOptions[0].Value.pszValue);
1321 ok(list.pOptions[1].Value.dwValue == PROXY_TYPE_PROXY,
1322 "Retrieved flags should've been PROXY_TYPE_PROXY, was: %d\n",
1323 list.pOptions[1].Value.dwValue);
1325 HeapFree(GetProcessHeap(), 0, list.pOptions[0].Value.pszValue);
1326 HeapFree(GetProcessHeap(), 0, list.pOptions);
1328 /* restore original settings */
1329 list.dwOptionCount = 2;
1330 list.pOptions = orig_settings;
1332 ret = InternetSetOptionA(NULL, INTERNET_OPTION_PER_CONNECTION_OPTION,
1334 ok(ret == TRUE, "InternetSetOption should've succeeded\n");
1336 HeapFree(GetProcessHeap(), 0, list.pOptions);
1339 #define FLAG_TODO 0x1
1340 #define FLAG_NEEDREQ 0x2
1341 #define FLAG_UNIMPL 0x4
1343 static void test_InternetErrorDlg(void)
1345 HINTERNET ses, con, req;
1349 static const struct {
1354 { ERROR_INTERNET_INCORRECT_PASSWORD , ERROR_SUCCESS, FLAG_NEEDREQ },
1355 { ERROR_INTERNET_SEC_CERT_DATE_INVALID , ERROR_CANCELLED, 0 },
1356 { ERROR_INTERNET_SEC_CERT_CN_INVALID , ERROR_CANCELLED, 0 },
1357 { ERROR_INTERNET_HTTP_TO_HTTPS_ON_REDIR , ERROR_SUCCESS, 0 },
1358 { ERROR_INTERNET_HTTPS_TO_HTTP_ON_REDIR , ERROR_SUCCESS, FLAG_TODO },
1359 { ERROR_INTERNET_MIXED_SECURITY , ERROR_CANCELLED, FLAG_TODO },
1360 { ERROR_INTERNET_CHG_POST_IS_NON_SECURE , ERROR_CANCELLED, FLAG_TODO },
1361 { ERROR_INTERNET_POST_IS_NON_SECURE , ERROR_SUCCESS, 0 },
1362 { ERROR_INTERNET_CLIENT_AUTH_CERT_NEEDED, ERROR_CANCELLED, FLAG_NEEDREQ|FLAG_TODO },
1363 { ERROR_INTERNET_INVALID_CA , ERROR_CANCELLED, 0 },
1364 { ERROR_INTERNET_HTTPS_HTTP_SUBMIT_REDIR, ERROR_CANCELLED, FLAG_TODO },
1365 { ERROR_INTERNET_INSERT_CDROM , ERROR_CANCELLED, FLAG_TODO|FLAG_NEEDREQ|FLAG_UNIMPL },
1366 { ERROR_INTERNET_SEC_CERT_ERRORS , ERROR_CANCELLED, 0 },
1367 { ERROR_INTERNET_SEC_CERT_REV_FAILED , ERROR_CANCELLED, 0 },
1368 { ERROR_HTTP_COOKIE_NEEDS_CONFIRMATION , ERROR_HTTP_COOKIE_DECLINED, FLAG_TODO },
1369 { ERROR_INTERNET_BAD_AUTO_PROXY_SCRIPT , ERROR_CANCELLED, FLAG_TODO },
1370 { ERROR_INTERNET_UNABLE_TO_DOWNLOAD_SCRIPT, ERROR_CANCELLED, FLAG_TODO },
1371 { ERROR_HTTP_REDIRECT_NEEDS_CONFIRMATION, ERROR_CANCELLED, FLAG_TODO },
1372 { ERROR_INTERNET_SEC_CERT_REVOKED , ERROR_CANCELLED, 0 },
1373 { 0, ERROR_NOT_SUPPORTED }
1378 res = InternetErrorDlg(NULL, NULL, 12055, flags, NULL);
1379 ok(res == ERROR_INVALID_HANDLE, "Got %d\n", res);
1381 ses = InternetOpen(NULL, INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, 0);
1382 ok(ses != 0, "InternetOpen failed: 0x%08x\n", GetLastError());
1383 con = InternetConnect(ses, "www.winehq.org", 80, NULL, NULL, INTERNET_SERVICE_HTTP, 0, 0);
1384 ok(con != 0, "InternetConnect failed: 0x%08x\n", GetLastError());
1385 req = HttpOpenRequest(con, "GET", "/", NULL, NULL, NULL, 0, 0);
1386 ok(req != 0, "HttpOpenRequest failed: 0x%08x\n", GetLastError());
1388 /* NULL hwnd and FLAGS_ERROR_UI_FLAGS_NO_UI not set */
1389 for(i = INTERNET_ERROR_BASE; i < INTERNET_ERROR_LAST; i++)
1391 res = InternetErrorDlg(NULL, req, i, flags, NULL);
1392 ok(res == ERROR_INVALID_HANDLE, "Got %d (%d)\n", res, i);
1395 hwnd = GetDesktopWindow();
1396 ok(hwnd != NULL, "GetDesktopWindow failed (%d)\n", GetLastError());
1398 flags = FLAGS_ERROR_UI_FLAGS_NO_UI;
1399 for(i = INTERNET_ERROR_BASE; i < INTERNET_ERROR_LAST; i++)
1401 DWORD expected, test_flags, j;
1403 for(j = 0; no_ui_res[j].error != 0; ++j)
1404 if(no_ui_res[j].error == i)
1407 test_flags = no_ui_res[j].test_flags;
1408 expected = no_ui_res[j].res;
1410 /* Try an invalid request handle */
1411 res = InternetErrorDlg(hwnd, (HANDLE)0xdeadbeef, i, flags, NULL);
1412 if(res == ERROR_CALL_NOT_IMPLEMENTED)
1414 ok(test_flags & FLAG_UNIMPL, "%i is unexpectedly unimplemented.\n", i);
1418 ok(res == ERROR_INVALID_HANDLE, "Got %d (%d)\n", res, i);
1420 /* With a valid req */
1421 if(i == ERROR_INTERNET_NEED_UI)
1422 continue; /* Crashes on windows XP */
1424 if(i == ERROR_INTERNET_SEC_CERT_REVOKED)
1425 continue; /* Interactive (XP, Win7) */
1427 res = InternetErrorDlg(hwnd, req, i, flags, NULL);
1429 /* Handle some special cases */
1432 case ERROR_INTERNET_HTTP_TO_HTTPS_ON_REDIR:
1433 case ERROR_INTERNET_HTTPS_TO_HTTP_ON_REDIR:
1434 if(res == ERROR_CANCELLED)
1436 /* Some windows XP, w2k3 x64, W2K8 */
1437 win_skip("Skipping some tests for %d\n", i);
1441 case ERROR_INTERNET_FORTEZZA_LOGIN_NEEDED:
1444 /* Windows XP, W2K3 */
1445 ok(res == NTE_PROV_TYPE_NOT_DEF, "Got %d\n", res);
1446 win_skip("Skipping some tests for %d\n", i);
1453 if(test_flags & FLAG_TODO)
1454 todo_wine ok(res == expected, "Got %d, expected %d (%d)\n", res, expected, i);
1456 ok(res == expected, "Got %d, expected %d (%d)\n", res, expected, i);
1458 /* Same thing with NULL hwnd */
1459 res = InternetErrorDlg(NULL, req, i, flags, NULL);
1460 if(test_flags & FLAG_TODO)
1461 todo_wine ok(res == expected, "Got %d, expected %d (%d)\n", res, expected, i);
1463 ok(res == expected, "Got %d, expected %d (%d)\n", res, expected, i);
1466 /* With a null req */
1467 if(test_flags & FLAG_NEEDREQ)
1468 expected = ERROR_INVALID_PARAMETER;
1470 res = InternetErrorDlg(hwnd, NULL, i, flags, NULL);
1471 if( test_flags & FLAG_TODO || i == ERROR_INTERNET_INCORRECT_PASSWORD)
1472 todo_wine ok(res == expected, "Got %d, expected %d (%d)\n", res, expected, i);
1474 ok(res == expected, "Got %d, expected %d (%d)\n", res, expected, i);
1477 res = InternetCloseHandle(req);
1478 ok(res == TRUE, "InternetCloseHandle failed: 0x%08x\n", GetLastError());
1479 res = InternetCloseHandle(con);
1480 ok(res == TRUE, "InternetCloseHandle failed: 0x%08x\n", GetLastError());
1481 res = InternetCloseHandle(ses);
1482 ok(res == TRUE, "InternetCloseHandle failed: 0x%08x\n", GetLastError());
1485 /* ############################### */
1487 START_TEST(internet)
1490 hdll = GetModuleHandleA("wininet.dll");
1492 pCreateUrlCacheContainerA = (void*)GetProcAddress(hdll, "CreateUrlCacheContainerA");
1493 pCreateUrlCacheContainerW = (void*)GetProcAddress(hdll, "CreateUrlCacheContainerW");
1494 pInternetTimeFromSystemTimeA = (void*)GetProcAddress(hdll, "InternetTimeFromSystemTimeA");
1495 pInternetTimeFromSystemTimeW = (void*)GetProcAddress(hdll, "InternetTimeFromSystemTimeW");
1496 pInternetTimeToSystemTimeA = (void*)GetProcAddress(hdll, "InternetTimeToSystemTimeA");
1497 pInternetTimeToSystemTimeW = (void*)GetProcAddress(hdll, "InternetTimeToSystemTimeW");
1498 pIsDomainLegalCookieDomainW = (void*)GetProcAddress(hdll, (LPCSTR)117);
1499 pPrivacyGetZonePreferenceW = (void*)GetProcAddress(hdll, "PrivacyGetZonePreferenceW");
1500 pPrivacySetZonePreferenceW = (void*)GetProcAddress(hdll, "PrivacySetZonePreferenceW");
1501 pInternetGetCookieExA = (void*)GetProcAddress(hdll, "InternetGetCookieExA");
1502 pInternetGetCookieExW = (void*)GetProcAddress(hdll, "InternetGetCookieExW");
1504 if(!pInternetGetCookieExW) {
1505 win_skip("Too old IE (older than 6.0)\n");
1509 test_InternetCanonicalizeUrlA();
1510 test_InternetQueryOptionA();
1512 test_complicated_cookie();
1516 test_Option_PerConnectionOption();
1517 test_Option_PerConnectionOptionA();
1518 test_InternetErrorDlg();
1521 if (!pInternetTimeFromSystemTimeA)
1522 win_skip("skipping the InternetTime tests\n");
1525 InternetTimeFromSystemTimeA_test();
1526 InternetTimeFromSystemTimeW_test();
1527 InternetTimeToSystemTimeA_test();
1528 InternetTimeToSystemTimeW_test();
1530 if (pIsDomainLegalCookieDomainW &&
1531 ((void*)pIsDomainLegalCookieDomainW == (void*)pCreateUrlCacheContainerA ||
1532 (void*)pIsDomainLegalCookieDomainW == (void*)pCreateUrlCacheContainerW))
1533 win_skip("IsDomainLegalCookieDomainW is not available on systems with IE5\n");
1534 else if (!pIsDomainLegalCookieDomainW)
1535 win_skip("IsDomainLegalCookieDomainW (or ordinal 117) is not available\n");
1537 test_IsDomainLegalCookieDomainW();
1539 if (pPrivacyGetZonePreferenceW && pPrivacySetZonePreferenceW)
1540 test_PrivacyGetSetZonePreferenceW();
1542 win_skip("Privacy[SG]etZonePreferenceW are not available\n");
1544 test_InternetSetOption();