wininet: Added more connection limit options tests.
[wine] / dlls / wininet / tests / internet.c
1 /*
2  * Wininet - internet tests
3  *
4  * Copyright 2005 Vijay Kiran Kamuju
5  *
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.
10  *
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.
15  *
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
19  */
20
21 #include <stdarg.h>
22 #include <string.h>
23 #include "windef.h"
24 #include "winbase.h"
25 #include "winuser.h"
26 #include "wininet.h"
27 #include "winerror.h"
28 #include "winreg.h"
29
30 #include "wine/test.h"
31
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);
43
44 /* ############################### */
45
46 static void test_InternetCanonicalizeUrlA(void)
47 {
48     CHAR    buffer[256];
49     LPCSTR  url;
50     DWORD   urllen;
51     DWORD   dwSize;
52     DWORD   res;
53
54     /* Acrobat Updater 5 calls this for Adobe Reader 8.1 */
55     url = "http://swupmf.adobe.com/manifest/50/win/AdobeUpdater.upd";
56     urllen = lstrlenA(url);
57
58     memset(buffer, '#', sizeof(buffer)-1);
59     buffer[sizeof(buffer)-1] = '\0';
60     dwSize = 1; /* Acrobat Updater use this size */
61     SetLastError(0xdeadbeef);
62     res = InternetCanonicalizeUrlA(url, buffer, &dwSize, 0);
63     ok( !res && (GetLastError() == ERROR_INSUFFICIENT_BUFFER) && (dwSize == (urllen+1)),
64         "got %u and %u with size %u for '%s' (%d)\n",
65         res, GetLastError(), dwSize, buffer, lstrlenA(buffer));
66
67
68     /* buffer has no space for the terminating '\0' */
69     memset(buffer, '#', sizeof(buffer)-1);
70     buffer[sizeof(buffer)-1] = '\0';
71     dwSize = urllen;
72     SetLastError(0xdeadbeef);
73     res = InternetCanonicalizeUrlA(url, buffer, &dwSize, 0);
74     /* dwSize is nr. of needed bytes with the terminating '\0' */
75     ok( !res && (GetLastError() == ERROR_INSUFFICIENT_BUFFER) && (dwSize == (urllen+1)),
76         "got %u and %u with size %u for '%s' (%d)\n",
77         res, GetLastError(), dwSize, buffer, lstrlenA(buffer));
78
79     /* buffer has the required size */
80     memset(buffer, '#', sizeof(buffer)-1);
81     buffer[sizeof(buffer)-1] = '\0';
82     dwSize = urllen+1;
83     SetLastError(0xdeadbeef);
84     res = InternetCanonicalizeUrlA(url, buffer, &dwSize, 0);
85     /* dwSize is nr. of copied bytes without the terminating '\0' */
86     ok( res && (dwSize == urllen) && (lstrcmpA(url, buffer) == 0),
87         "got %u and %u with size %u for '%s' (%d)\n",
88         res, GetLastError(), dwSize, buffer, lstrlenA(buffer));
89
90     memset(buffer, '#', sizeof(buffer)-1);
91     buffer[sizeof(buffer)-1] = '\0';
92     dwSize = sizeof(buffer);
93     SetLastError(0xdeadbeef);
94     res = InternetCanonicalizeUrlA("file:///C:/Program%20Files/Atmel/AVR%20Tools/STK500/STK500.xml", buffer, &dwSize, ICU_DECODE | ICU_NO_ENCODE);
95     ok(res, "InternetCanonicalizeUrlA failed %u\n", GetLastError());
96     ok(dwSize == lstrlenA(buffer), "got %d expected %d\n", dwSize, lstrlenA(buffer));
97     ok(!lstrcmpA("file://C:\\Program Files\\Atmel\\AVR Tools\\STK500\\STK500.xml", buffer),
98        "got %s expected 'file://C:\\Program Files\\Atmel\\AVR Tools\\STK500\\STK500.xml'\n", buffer);
99
100     /* buffer is larger as the required size */
101     memset(buffer, '#', sizeof(buffer)-1);
102     buffer[sizeof(buffer)-1] = '\0';
103     dwSize = urllen+2;
104     SetLastError(0xdeadbeef);
105     res = InternetCanonicalizeUrlA(url, buffer, &dwSize, 0);
106     /* dwSize is nr. of copied bytes without the terminating '\0' */
107     ok( res && (dwSize == urllen) && (lstrcmpA(url, buffer) == 0),
108         "got %u and %u with size %u for '%s' (%d)\n",
109         res, GetLastError(), dwSize, buffer, lstrlenA(buffer));
110
111
112     /* check NULL pointers */
113     memset(buffer, '#', urllen + 4);
114     buffer[urllen + 4] = '\0';
115     dwSize = urllen+1;
116     SetLastError(0xdeadbeef);
117     res = InternetCanonicalizeUrlA(NULL, buffer, &dwSize, 0);
118     ok( !res && (GetLastError() == ERROR_INVALID_PARAMETER),
119         "got %u and %u with size %u for '%s' (%d)\n",
120         res, GetLastError(), dwSize, buffer, lstrlenA(buffer));
121
122     memset(buffer, '#', urllen + 4);
123     buffer[urllen + 4] = '\0';
124     dwSize = urllen+1;
125     SetLastError(0xdeadbeef);
126     res = InternetCanonicalizeUrlA(url, NULL, &dwSize, 0);
127     ok( !res && (GetLastError() == ERROR_INVALID_PARAMETER),
128         "got %u and %u with size %u for '%s' (%d)\n",
129         res, GetLastError(), dwSize, buffer, lstrlenA(buffer));
130
131     memset(buffer, '#', urllen + 4);
132     buffer[urllen + 4] = '\0';
133     dwSize = urllen+1;
134     SetLastError(0xdeadbeef);
135     res = InternetCanonicalizeUrlA(url, buffer, NULL, 0);
136     ok( !res && (GetLastError() == ERROR_INVALID_PARAMETER),
137         "got %u and %u with size %u for '%s' (%d)\n",
138         res, GetLastError(), dwSize, buffer, lstrlenA(buffer));
139
140     /* test with trailing space */
141     dwSize = 256;
142     res = InternetCanonicalizeUrlA("http://www.winehq.org/index.php?x= ", buffer, &dwSize, ICU_BROWSER_MODE);
143     ok(res == 1, "InternetCanonicalizeUrlA failed\n");
144     ok(!strcmp(buffer, "http://www.winehq.org/index.php?x="), "Trailing space should have been stripped even in ICU_BROWSER_MODE (%s)\n", buffer);
145
146     res = InternetSetOptionA(NULL, 0xdeadbeef, buffer, sizeof(buffer));
147     ok(!res, "InternetSetOptionA succeeded\n");
148     ok(GetLastError() == ERROR_INTERNET_INVALID_OPTION,
149        "InternetSetOptionA failed %u, expected ERROR_INTERNET_INVALID_OPTION\n", GetLastError());
150 }
151
152 /* ############################### */
153
154 static void test_InternetQueryOptionA(void)
155 {
156   HINTERNET hinet,hurl;
157   DWORD len, val;
158   DWORD err;
159   static const char useragent[] = {"Wininet Test"};
160   char *buffer;
161   int retval;
162   BOOL res;
163
164   hinet = InternetOpenA(useragent,INTERNET_OPEN_TYPE_DIRECT,NULL,NULL, 0);
165   ok((hinet != 0x0),"InternetOpen Failed\n");
166
167   SetLastError(0xdeadbeef);
168   retval=InternetQueryOptionA(NULL,INTERNET_OPTION_USER_AGENT,NULL,&len);
169   err=GetLastError();
170   ok(retval == 0,"Got wrong return value %d\n",retval);
171   ok(err == ERROR_INTERNET_INCORRECT_HANDLE_TYPE, "Got wrong error code%d\n",err);
172
173   SetLastError(0xdeadbeef);
174   len=strlen(useragent)+1;
175   retval=InternetQueryOptionA(hinet,INTERNET_OPTION_USER_AGENT,NULL,&len);
176   err=GetLastError();
177   ok(len == strlen(useragent)+1,"Got wrong user agent length %d instead of %d\n",len,lstrlenA(useragent));
178   ok(retval == 0,"Got wrong return value %d\n",retval);
179   ok(err == ERROR_INSUFFICIENT_BUFFER, "Got wrong error code %d\n",err);
180
181   SetLastError(0xdeadbeef);
182   len=strlen(useragent)+1;
183   buffer=HeapAlloc(GetProcessHeap(),0,len);
184   retval=InternetQueryOptionA(hinet,INTERNET_OPTION_USER_AGENT,buffer,&len);
185   err=GetLastError();
186   ok(retval == 1,"Got wrong return value %d\n",retval);
187   if (retval)
188   {
189       ok(!strcmp(useragent,buffer),"Got wrong user agent string %s instead of %s\n",buffer,useragent);
190       ok(len == strlen(useragent),"Got wrong user agent length %d instead of %d\n",len,lstrlenA(useragent));
191   }
192   ok(err == 0xdeadbeef, "Got wrong error code %d\n",err);
193   HeapFree(GetProcessHeap(),0,buffer);
194
195   SetLastError(0xdeadbeef);
196   len=0;
197   buffer=HeapAlloc(GetProcessHeap(),0,100);
198   retval=InternetQueryOptionA(hinet,INTERNET_OPTION_USER_AGENT,buffer,&len);
199   err=GetLastError();
200   ok(len == strlen(useragent) + 1,"Got wrong user agent length %d instead of %d\n", len, lstrlenA(useragent) + 1);
201   ok(!retval, "Got wrong return value %d\n", retval);
202   ok(err == ERROR_INSUFFICIENT_BUFFER, "Got wrong error code %d\n", err);
203   HeapFree(GetProcessHeap(),0,buffer);
204
205   hurl = InternetConnectA(hinet,"www.winehq.org",INTERNET_DEFAULT_HTTP_PORT,NULL,NULL,INTERNET_SERVICE_HTTP,0,0);
206
207   SetLastError(0xdeadbeef);
208   len=0;
209   retval = InternetQueryOptionA(hurl,INTERNET_OPTION_USER_AGENT,NULL,&len);
210   err=GetLastError();
211   ok(len == 0,"Got wrong user agent length %d instead of 0\n",len);
212   ok(retval == 0,"Got wrong return value %d\n",retval);
213   ok(err == ERROR_INTERNET_INCORRECT_HANDLE_TYPE, "Got wrong error code %d\n",err);
214
215   InternetCloseHandle(hurl);
216   InternetCloseHandle(hinet);
217
218   hinet = InternetOpenA("",INTERNET_OPEN_TYPE_DIRECT,NULL,NULL, 0);
219   ok((hinet != 0x0),"InternetOpen Failed\n");
220
221   SetLastError(0xdeadbeef);
222   len=0;
223   retval=InternetQueryOptionA(hinet,INTERNET_OPTION_USER_AGENT,NULL,&len);
224   err=GetLastError();
225   ok(len == 1,"Got wrong user agent length %d instead of %d\n",len,1);
226   ok(retval == 0,"Got wrong return value %d\n",retval);
227   ok(err == ERROR_INSUFFICIENT_BUFFER, "Got wrong error code%d\n",err);
228
229   InternetCloseHandle(hinet);
230
231   hinet = InternetOpenA(NULL,INTERNET_OPEN_TYPE_DIRECT,NULL,NULL, 0);
232   ok((hinet != 0x0),"InternetOpen Failed\n");
233   SetLastError(0xdeadbeef);
234   len=0;
235   retval=InternetQueryOptionA(hinet,INTERNET_OPTION_USER_AGENT,NULL,&len);
236   err=GetLastError();
237   ok(len == 1,"Got wrong user agent length %d instead of %d\n",len,1);
238   ok(retval == 0,"Got wrong return value %d\n",retval);
239   ok(err == ERROR_INSUFFICIENT_BUFFER, "Got wrong error code%d\n",err);
240
241   len = sizeof(val);
242   val = 0xdeadbeef;
243   res = InternetQueryOptionA(hinet, INTERNET_OPTION_MAX_CONNS_PER_SERVER, &val, &len);
244   ok(!res, "InternetQueryOptionA(INTERNET_OPTION_MAX_CONNS_PER_SERVER) succeeded\n");
245   ok(GetLastError() == ERROR_INTERNET_INVALID_OPERATION, "GetLastError() = %u\n", GetLastError());
246
247   val = 2;
248   res = InternetSetOptionA(hinet, INTERNET_OPTION_MAX_CONNS_PER_SERVER, &val, sizeof(val));
249   ok(!res, "InternetSetOptionA(INTERNET_OPTION_MAX_CONNS_PER_SERVER) succeeded\n");
250   ok(GetLastError() == ERROR_INTERNET_INVALID_OPERATION, "GetLastError() = %u\n", GetLastError());
251
252   InternetCloseHandle(hinet);
253 }
254
255 static void test_max_conns(void)
256 {
257     DWORD len, val;
258     BOOL res;
259
260     len = sizeof(val);
261     val = 0xdeadbeef;
262     res = InternetQueryOptionA(NULL, INTERNET_OPTION_MAX_CONNS_PER_SERVER, &val, &len);
263     ok(res,"Got wrong return value %x\n", res);
264     ok(len == sizeof(val), "got %d\n", len);
265     ok(val == 2, "got %d\n", val);
266
267     len = sizeof(val);
268     val = 0xdeadbeef;
269     res = InternetQueryOptionA(NULL, INTERNET_OPTION_MAX_CONNS_PER_1_0_SERVER, &val, &len);
270     ok(res,"Got wrong return value %x\n", res);
271     ok(len == sizeof(val), "got %d\n", len);
272     ok(val == 4, "got %d\n", val);
273
274     val = 3;
275     res = InternetSetOptionA(NULL, INTERNET_OPTION_MAX_CONNS_PER_SERVER, &val, sizeof(val));
276     ok(res, "InternetSetOptionA(INTERNET_OPTION_MAX_CONNS_PER_SERVER) failed: %x\n", res);
277
278     len = sizeof(val);
279     val = 0xdeadbeef;
280     res = InternetQueryOptionA(NULL, INTERNET_OPTION_MAX_CONNS_PER_SERVER, &val, &len);
281     ok(res,"Got wrong return value %x\n", res);
282     ok(len == sizeof(val), "got %d\n", len);
283     ok(val == 3, "got %d\n", val);
284
285     val = 0;
286     res = InternetSetOptionA(NULL, INTERNET_OPTION_MAX_CONNS_PER_SERVER, &val, sizeof(val));
287     ok(!res, "InternetSetOptionA(INTERNET_OPTION_MAX_CONNS_PER_SERVER, 0) succeeded\n");
288     ok(GetLastError() == ERROR_BAD_ARGUMENTS, "GetLastError() = %u\n", GetLastError());
289
290     val = 2;
291     res = InternetSetOptionA(NULL, INTERNET_OPTION_MAX_CONNS_PER_SERVER, &val, sizeof(val)-1);
292     ok(!res, "InternetSetOptionA(INTERNET_OPTION_MAX_CONNS_PER_SERVER) succeeded\n");
293     ok(GetLastError() == ERROR_INTERNET_BAD_OPTION_LENGTH, "GetLastError() = %u\n", GetLastError());
294
295     val = 2;
296     res = InternetSetOptionA(NULL, INTERNET_OPTION_MAX_CONNS_PER_SERVER, &val, sizeof(val)+1);
297     ok(!res, "InternetSetOptionA(INTERNET_OPTION_MAX_CONNS_PER_SERVER) succeeded\n");
298     ok(GetLastError() == ERROR_INTERNET_BAD_OPTION_LENGTH, "GetLastError() = %u\n", GetLastError());
299 }
300
301 static void test_get_cookie(void)
302 {
303   DWORD len;
304   BOOL ret;
305
306   SetLastError(0xdeadbeef);
307   ret = InternetGetCookie("http://www.example.com", NULL, NULL, &len);
308   ok(!ret && GetLastError() == ERROR_NO_MORE_ITEMS,
309     "InternetGetCookie should have failed with %s and error %d\n",
310     ret ? "TRUE" : "FALSE", GetLastError());
311 }
312
313
314 static void test_complicated_cookie(void)
315 {
316   DWORD len;
317   BOOL ret;
318
319   CHAR buffer[1024];
320
321   ret = InternetSetCookie("http://www.example.com/bar",NULL,"A=B; domain=.example.com");
322   ok(ret == TRUE,"InternetSetCookie failed\n");
323   ret = InternetSetCookie("http://www.example.com/bar",NULL,"C=D; domain=.example.com; path=/");
324   ok(ret == TRUE,"InternetSetCookie failed\n");
325
326   /* Technically illegal! domain should require 2 dots, but native wininet accepts it */
327   ret = InternetSetCookie("http://www.example.com",NULL,"E=F; domain=example.com");
328   ok(ret == TRUE,"InternetSetCookie failed\n");
329   ret = InternetSetCookie("http://www.example.com",NULL,"G=H; domain=.example.com; path=/foo");
330   ok(ret == TRUE,"InternetSetCookie failed\n");
331   ret = InternetSetCookie("http://www.example.com/bar.html",NULL,"I=J; domain=.example.com");
332   ok(ret == TRUE,"InternetSetCookie failed\n");
333   ret = InternetSetCookie("http://www.example.com/bar/",NULL,"K=L; domain=.example.com");
334   ok(ret == TRUE,"InternetSetCookie failed\n");
335   ret = InternetSetCookie("http://www.example.com/bar/",NULL,"M=N; domain=.example.com; path=/foo/");
336   ok(ret == TRUE,"InternetSetCookie failed\n");
337   ret = InternetSetCookie("http://www.example.com/bar/",NULL,"O=P; secure; path=/bar");
338   ok(ret == TRUE,"InternetSetCookie failed\n");
339
340   len = 1024;
341   ret = InternetGetCookie("http://testing.example.com", NULL, buffer, &len);
342   ok(ret == TRUE,"InternetGetCookie failed\n");
343   ok(strstr(buffer,"A=B")!=NULL,"A=B missing\n");
344   ok(strstr(buffer,"C=D")!=NULL,"C=D missing\n");
345   ok(strstr(buffer,"E=F")!=NULL,"E=F missing\n");
346   ok(strstr(buffer,"G=H")==NULL,"G=H present\n");
347   ok(strstr(buffer,"I=J")!=NULL,"I=J missing\n");
348   ok(strstr(buffer,"K=L")==NULL,"K=L present\n");
349   ok(strstr(buffer,"M=N")==NULL,"M=N present\n");
350   ok(strstr(buffer,"O=P")==NULL,"O=P present\n");
351
352   len = 1024;
353   ret = InternetGetCookie("http://testing.example.com/foobar", NULL, buffer, &len);
354   ok(ret == TRUE,"InternetGetCookie failed\n");
355   ok(strstr(buffer,"A=B")!=NULL,"A=B missing\n");
356   ok(strstr(buffer,"C=D")!=NULL,"C=D missing\n");
357   ok(strstr(buffer,"E=F")!=NULL,"E=F missing\n");
358   ok(strstr(buffer,"G=H")==NULL,"G=H present\n");
359   ok(strstr(buffer,"I=J")!=NULL,"I=J missing\n");
360   ok(strstr(buffer,"K=L")==NULL,"K=L present\n");
361   ok(strstr(buffer,"M=N")==NULL,"M=N present\n");
362   ok(strstr(buffer,"O=P")==NULL,"O=P present\n");
363
364   len = 1024;
365   ret = InternetGetCookie("http://testing.example.com/foobar/", NULL, buffer, &len);
366   ok(ret == TRUE,"InternetGetCookie failed\n");
367   ok(strstr(buffer,"A=B")!=NULL,"A=B missing\n");
368   ok(strstr(buffer,"C=D")!=NULL,"C=D missing\n");
369   ok(strstr(buffer,"E=F")!=NULL,"E=F missing\n");
370   ok(strstr(buffer,"G=H")!=NULL,"G=H missing\n");
371   ok(strstr(buffer,"I=J")!=NULL,"I=J missing\n");
372   ok(strstr(buffer,"K=L")==NULL,"K=L present\n");
373   ok(strstr(buffer,"M=N")==NULL,"M=N present\n");
374   ok(strstr(buffer,"O=P")==NULL,"O=P present\n");
375
376   len = 1024;
377   ret = InternetGetCookie("http://testing.example.com/foo/bar", NULL, buffer, &len);
378   ok(ret == TRUE,"InternetGetCookie failed\n");
379   ok(strstr(buffer,"A=B")!=NULL,"A=B missing\n");
380   ok(strstr(buffer,"C=D")!=NULL,"C=D missing\n");
381   ok(strstr(buffer,"E=F")!=NULL,"E=F missing\n");
382   ok(strstr(buffer,"G=H")!=NULL,"G=H missing\n");
383   ok(strstr(buffer,"I=J")!=NULL,"I=J missing\n");
384   ok(strstr(buffer,"K=L")==NULL,"K=L present\n");
385   ok(strstr(buffer,"M=N")!=NULL,"M=N missing\n");
386   ok(strstr(buffer,"O=P")==NULL,"O=P present\n");
387
388   len = 1024;
389   ret = InternetGetCookie("http://testing.example.com/barfoo", NULL, buffer, &len);
390   ok(ret == TRUE,"InternetGetCookie failed\n");
391   ok(strstr(buffer,"A=B")!=NULL,"A=B missing\n");
392   ok(strstr(buffer,"C=D")!=NULL,"C=D missing\n");
393   ok(strstr(buffer,"E=F")!=NULL,"E=F missing\n");
394   ok(strstr(buffer,"G=H")==NULL,"G=H present\n");
395   ok(strstr(buffer,"I=J")!=NULL,"I=J missing\n");
396   ok(strstr(buffer,"K=L")==NULL,"K=L present\n");
397   ok(strstr(buffer,"M=N")==NULL,"M=N present\n");
398   ok(strstr(buffer,"O=P")==NULL,"O=P present\n");
399
400   len = 1024;
401   ret = InternetGetCookie("http://testing.example.com/barfoo/", NULL, buffer, &len);
402   ok(ret == TRUE,"InternetGetCookie failed\n");
403   ok(strstr(buffer,"A=B")!=NULL,"A=B missing\n");
404   ok(strstr(buffer,"C=D")!=NULL,"C=D missing\n");
405   ok(strstr(buffer,"E=F")!=NULL,"E=F missing\n");
406   ok(strstr(buffer,"G=H")==NULL,"G=H present\n");
407   ok(strstr(buffer,"I=J")!=NULL,"I=J missing\n");
408   ok(strstr(buffer,"K=L")==NULL,"K=L present\n");
409   ok(strstr(buffer,"M=N")==NULL,"M=N present\n");
410   ok(strstr(buffer,"O=P")==NULL,"O=P present\n");
411
412   len = 1024;
413   ret = InternetGetCookie("http://testing.example.com/bar/foo", NULL, buffer, &len);
414   ok(ret == TRUE,"InternetGetCookie failed\n");
415   ok(strstr(buffer,"A=B")!=NULL,"A=B missing\n");
416   ok(strstr(buffer,"C=D")!=NULL,"C=D missing\n");
417   ok(strstr(buffer,"E=F")!=NULL,"E=F missing\n");
418   ok(strstr(buffer,"G=H")==NULL,"G=H present\n");
419   ok(strstr(buffer,"I=J")!=NULL,"I=J missing\n");
420   ok(strstr(buffer,"K=L")!=NULL,"K=L missing\n");
421   ok(strstr(buffer,"M=N")==NULL,"M=N present\n");
422   ok(strstr(buffer,"O=P")==NULL,"O=P present\n");
423 }
424
425 static void test_null(void)
426 {
427   HINTERNET hi, hc;
428   static const WCHAR szServer[] = { 's','e','r','v','e','r',0 };
429   static const WCHAR szEmpty[] = { 0 };
430   static const WCHAR szUrl[] = { 'h','t','t','p',':','/','/','a','.','b','.','c',0 };
431   static const WCHAR szUrlEmpty[] = { 'h','t','t','p',':','/','/',0 };
432   static const WCHAR szExpect[] = { 's','e','r','v','e','r',';',' ','s','e','r','v','e','r',0 };
433   WCHAR buffer[0x20];
434   BOOL r;
435   DWORD sz;
436
437   SetLastError(0xdeadbeef);
438   hi = InternetOpenW(NULL, 0, NULL, NULL, 0);
439   if (hi == NULL && GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)
440   {
441     win_skip("Internet*W functions are not implemented\n");
442     return;
443   }
444   ok(hi != NULL, "open failed\n");
445
446   hc = InternetConnectW(hi, NULL, 0, NULL, NULL, 0, 0, 0);
447   ok(GetLastError() == ERROR_INVALID_PARAMETER, "wrong error\n");
448   ok(hc == NULL, "connect failed\n");
449
450   hc = InternetConnectW(hi, NULL, 0, NULL, NULL, INTERNET_SERVICE_HTTP, 0, 0);
451   ok(GetLastError() == ERROR_INVALID_PARAMETER, "wrong error\n");
452   ok(hc == NULL, "connect failed\n");
453
454   hc = InternetConnectW(hi, NULL, 0, NULL, NULL, INTERNET_SERVICE_FTP, 0, 0);
455   ok(GetLastError() == ERROR_INVALID_PARAMETER, "wrong error\n");
456   ok(hc == NULL, "connect failed\n");
457
458   hc = InternetConnectW(NULL, szServer, 0, NULL, NULL, INTERNET_SERVICE_FTP, 0, 0);
459   ok(GetLastError() == ERROR_INVALID_HANDLE, "wrong error\n");
460   ok(hc == NULL, "connect failed\n");
461
462   hc = InternetOpenUrlW(hi, NULL, NULL, 0, 0, 0);
463   ok(GetLastError() == ERROR_INVALID_PARAMETER ||
464      GetLastError() == ERROR_INTERNET_UNRECOGNIZED_SCHEME, "wrong error\n");
465   ok(hc == NULL, "connect failed\n");
466
467   hc = InternetOpenUrlW(hi, szServer, NULL, 0, 0, 0);
468   ok(GetLastError() == ERROR_INTERNET_UNRECOGNIZED_SCHEME, "wrong error\n");
469   ok(hc == NULL, "connect failed\n");
470
471   InternetCloseHandle(hi);
472
473   r = InternetSetCookieW(NULL, NULL, NULL);
474   ok(GetLastError() == ERROR_INVALID_PARAMETER, "wrong error\n");
475   ok(r == FALSE, "return wrong\n");
476
477   r = InternetSetCookieW(szServer, NULL, NULL);
478   ok(GetLastError() == ERROR_INVALID_PARAMETER, "wrong error\n");
479   ok(r == FALSE, "return wrong\n");
480
481   r = InternetSetCookieW(szUrl, szServer, NULL);
482   ok(GetLastError() == ERROR_INVALID_PARAMETER, "wrong error\n");
483   ok(r == FALSE, "return wrong\n");
484
485   r = InternetSetCookieW(szUrl, szServer, szServer);
486   ok(r == TRUE, "return wrong\n");
487
488   r = InternetSetCookieW(szUrl, NULL, szServer);
489   ok(r == TRUE, "return wrong\n");
490
491   r = InternetSetCookieW(szUrl, szServer, szEmpty);
492   ok(r == TRUE, "return wrong\n");
493
494   r = InternetSetCookieW(szUrlEmpty, szServer, szServer);
495   ok(r == FALSE, "return wrong\n");
496
497   r = InternetSetCookieW(szServer, NULL, szServer);
498   todo_wine {
499   ok(GetLastError() == ERROR_INTERNET_UNRECOGNIZED_SCHEME, "wrong error\n");
500   }
501   ok(r == FALSE, "return wrong\n");
502
503   sz = 0;
504   r = InternetGetCookieW(NULL, NULL, NULL, &sz);
505   ok(GetLastError() == ERROR_INVALID_PARAMETER || GetLastError() == ERROR_INTERNET_UNRECOGNIZED_SCHEME,
506      "wrong error %u\n", GetLastError());
507   ok( r == FALSE, "return wrong\n");
508
509   r = InternetGetCookieW(szServer, NULL, NULL, &sz);
510   todo_wine {
511   ok(GetLastError() == ERROR_INTERNET_UNRECOGNIZED_SCHEME, "wrong error\n");
512   }
513   ok( r == FALSE, "return wrong\n");
514
515   sz = 0;
516   r = InternetGetCookieW(szUrlEmpty, szServer, NULL, &sz);
517   ok( r == FALSE, "return wrong\n");
518
519   sz = 0;
520   r = InternetGetCookieW(szUrl, szServer, NULL, &sz);
521   ok( r == TRUE, "return wrong\n");
522
523   /* sz is 14 on XP SP2 and beyond, 30 on XP SP1 and before */
524   ok( sz == 14 || sz == 30, "sz wrong, got %u, expected 14 or 30\n", sz);
525
526   sz = 0x20;
527   memset(buffer, 0, sizeof buffer);
528   r = InternetGetCookieW(szUrl, szServer, buffer, &sz);
529   ok( r == TRUE, "return wrong\n");
530
531   /* sz == lstrlenW(buffer) only in XP SP1 */
532   ok( sz == 1 + lstrlenW(buffer) || sz == lstrlenW(buffer), "sz wrong %d\n", sz);
533
534   /* before XP SP2, buffer is "server; server" */
535   ok( !lstrcmpW(szExpect, buffer) || !lstrcmpW(szServer, buffer), "cookie data wrong\n");
536
537   sz = sizeof(buffer);
538   r = InternetQueryOptionA(NULL, INTERNET_OPTION_CONNECTED_STATE, buffer, &sz);
539   ok(r == TRUE, "ret %d\n", r);
540 }
541
542 static void test_version(void)
543 {
544     INTERNET_VERSION_INFO version;
545     DWORD size;
546     BOOL res;
547
548     size = sizeof(version);
549     res = InternetQueryOptionA(NULL, INTERNET_OPTION_VERSION, &version, &size);
550     ok(res, "Could not get version: %u\n", GetLastError());
551     ok(version.dwMajorVersion == 1, "dwMajorVersion=%d, expected 1\n", version.dwMajorVersion);
552     ok(version.dwMinorVersion == 2, "dwMinorVersion=%d, expected 2\n", version.dwMinorVersion);
553 }
554
555 static void InternetTimeFromSystemTimeA_test(void)
556 {
557     BOOL ret;
558     static const SYSTEMTIME time = { 2005, 1, 5, 7, 12, 6, 35, 0 };
559     char string[INTERNET_RFC1123_BUFSIZE];
560     static const char expect[] = "Fri, 07 Jan 2005 12:06:35 GMT";
561     DWORD error;
562
563     ret = pInternetTimeFromSystemTimeA( &time, INTERNET_RFC1123_FORMAT, string, sizeof(string) );
564     ok( ret, "InternetTimeFromSystemTimeA failed (%u)\n", GetLastError() );
565
566     ok( !memcmp( string, expect, sizeof(expect) ),
567         "InternetTimeFromSystemTimeA failed (%u)\n", GetLastError() );
568
569     /* test NULL time parameter */
570     SetLastError(0xdeadbeef);
571     ret = pInternetTimeFromSystemTimeA( NULL, INTERNET_RFC1123_FORMAT, string, sizeof(string) );
572     error = GetLastError();
573     ok( !ret, "InternetTimeFromSystemTimeA should have returned FALSE\n" );
574     ok( error == ERROR_INVALID_PARAMETER,
575         "InternetTimeFromSystemTimeA failed with ERROR_INVALID_PARAMETER instead of %u\n",
576         error );
577
578     /* test NULL string parameter */
579     SetLastError(0xdeadbeef);
580     ret = pInternetTimeFromSystemTimeA( &time, INTERNET_RFC1123_FORMAT, NULL, sizeof(string) );
581     error = GetLastError();
582     ok( !ret, "InternetTimeFromSystemTimeA should have returned FALSE\n" );
583     ok( error == ERROR_INVALID_PARAMETER,
584         "InternetTimeFromSystemTimeA failed with ERROR_INVALID_PARAMETER instead of %u\n",
585         error );
586
587     /* test invalid format parameter */
588     SetLastError(0xdeadbeef);
589     ret = pInternetTimeFromSystemTimeA( &time, INTERNET_RFC1123_FORMAT + 1, string, sizeof(string) );
590     error = GetLastError();
591     ok( !ret, "InternetTimeFromSystemTimeA should have returned FALSE\n" );
592     ok( error == ERROR_INVALID_PARAMETER,
593         "InternetTimeFromSystemTimeA failed with ERROR_INVALID_PARAMETER instead of %u\n",
594         error );
595
596     /* test too small buffer size */
597     SetLastError(0xdeadbeef);
598     ret = pInternetTimeFromSystemTimeA( &time, INTERNET_RFC1123_FORMAT, string, 0 );
599     error = GetLastError();
600     ok( !ret, "InternetTimeFromSystemTimeA should have returned FALSE\n" );
601     ok( error == ERROR_INSUFFICIENT_BUFFER,
602         "InternetTimeFromSystemTimeA failed with ERROR_INSUFFICIENT_BUFFER instead of %u\n",
603         error );
604 }
605
606 static void InternetTimeFromSystemTimeW_test(void)
607 {
608     BOOL ret;
609     static const SYSTEMTIME time = { 2005, 1, 5, 7, 12, 6, 35, 0 };
610     WCHAR string[INTERNET_RFC1123_BUFSIZE + 1];
611     static const WCHAR expect[] = { 'F','r','i',',',' ','0','7',' ','J','a','n',' ','2','0','0','5',' ',
612                                     '1','2',':','0','6',':','3','5',' ','G','M','T',0 };
613     DWORD error;
614
615     ret = pInternetTimeFromSystemTimeW( &time, INTERNET_RFC1123_FORMAT, string, sizeof(string) );
616     ok( ret, "InternetTimeFromSystemTimeW failed (%u)\n", GetLastError() );
617
618     ok( !memcmp( string, expect, sizeof(expect) ),
619         "InternetTimeFromSystemTimeW failed (%u)\n", GetLastError() );
620
621     /* test NULL time parameter */
622     SetLastError(0xdeadbeef);
623     ret = pInternetTimeFromSystemTimeW( NULL, INTERNET_RFC1123_FORMAT, string, sizeof(string) );
624     error = GetLastError();
625     ok( !ret, "InternetTimeFromSystemTimeW should have returned FALSE\n" );
626     ok( error == ERROR_INVALID_PARAMETER,
627         "InternetTimeFromSystemTimeW failed with ERROR_INVALID_PARAMETER instead of %u\n",
628         error );
629
630     /* test NULL string parameter */
631     SetLastError(0xdeadbeef);
632     ret = pInternetTimeFromSystemTimeW( &time, INTERNET_RFC1123_FORMAT, NULL, sizeof(string) );
633     error = GetLastError();
634     ok( !ret, "InternetTimeFromSystemTimeW should have returned FALSE\n" );
635     ok( error == ERROR_INVALID_PARAMETER,
636         "InternetTimeFromSystemTimeW failed with ERROR_INVALID_PARAMETER instead of %u\n",
637         error );
638
639     /* test invalid format parameter */
640     SetLastError(0xdeadbeef);
641     ret = pInternetTimeFromSystemTimeW( &time, INTERNET_RFC1123_FORMAT + 1, string, sizeof(string) );
642     error = GetLastError();
643     ok( !ret, "InternetTimeFromSystemTimeW should have returned FALSE\n" );
644     ok( error == ERROR_INVALID_PARAMETER,
645         "InternetTimeFromSystemTimeW failed with ERROR_INVALID_PARAMETER instead of %u\n",
646         error );
647
648     /* test too small buffer size */
649     SetLastError(0xdeadbeef);
650     ret = pInternetTimeFromSystemTimeW( &time, INTERNET_RFC1123_FORMAT, string, sizeof(string)/sizeof(string[0]) );
651     error = GetLastError();
652     ok( !ret, "InternetTimeFromSystemTimeW should have returned FALSE\n" );
653     ok( error == ERROR_INSUFFICIENT_BUFFER,
654         "InternetTimeFromSystemTimeW failed with ERROR_INSUFFICIENT_BUFFER instead of %u\n",
655         error );
656 }
657
658 static void InternetTimeToSystemTimeA_test(void)
659 {
660     BOOL ret;
661     SYSTEMTIME time;
662     static const SYSTEMTIME expect = { 2005, 1, 5, 7, 12, 6, 35, 0 };
663     static const char string[] = "Fri, 07 Jan 2005 12:06:35 GMT";
664     static const char string2[] = " fri 7 jan 2005 12 06 35";
665
666     ret = pInternetTimeToSystemTimeA( string, &time, 0 );
667     ok( ret, "InternetTimeToSystemTimeA failed (%u)\n", GetLastError() );
668     ok( !memcmp( &time, &expect, sizeof(expect) ),
669         "InternetTimeToSystemTimeA failed (%u)\n", GetLastError() );
670
671     ret = pInternetTimeToSystemTimeA( string2, &time, 0 );
672     ok( ret, "InternetTimeToSystemTimeA failed (%u)\n", GetLastError() );
673     ok( !memcmp( &time, &expect, sizeof(expect) ),
674         "InternetTimeToSystemTimeA failed (%u)\n", GetLastError() );
675 }
676
677 static void InternetTimeToSystemTimeW_test(void)
678 {
679     BOOL ret;
680     SYSTEMTIME time;
681     static const SYSTEMTIME expect = { 2005, 1, 5, 7, 12, 6, 35, 0 };
682     static const WCHAR string[] = { 'F','r','i',',',' ','0','7',' ','J','a','n',' ','2','0','0','5',' ',
683                                     '1','2',':','0','6',':','3','5',' ','G','M','T',0 };
684     static const WCHAR string2[] = { ' ','f','r','i',' ','7',' ','j','a','n',' ','2','0','0','5',' ',
685                                      '1','2',' ','0','6',' ','3','5',0 };
686     static const WCHAR string3[] = { 'F','r',0 };
687
688     ret = pInternetTimeToSystemTimeW( NULL, NULL, 0 );
689     ok( !ret, "InternetTimeToSystemTimeW succeeded (%u)\n", GetLastError() );
690
691     ret = pInternetTimeToSystemTimeW( NULL, &time, 0 );
692     ok( !ret, "InternetTimeToSystemTimeW succeeded (%u)\n", GetLastError() );
693
694     ret = pInternetTimeToSystemTimeW( string, NULL, 0 );
695     ok( !ret, "InternetTimeToSystemTimeW succeeded (%u)\n", GetLastError() );
696
697     ret = pInternetTimeToSystemTimeW( string, &time, 0 );
698     ok( ret, "InternetTimeToSystemTimeW failed (%u)\n", GetLastError() );
699
700     ret = pInternetTimeToSystemTimeW( string, &time, 0 );
701     ok( ret, "InternetTimeToSystemTimeW failed (%u)\n", GetLastError() );
702     ok( !memcmp( &time, &expect, sizeof(expect) ),
703         "InternetTimeToSystemTimeW failed (%u)\n", GetLastError() );
704
705     ret = pInternetTimeToSystemTimeW( string2, &time, 0 );
706     ok( ret, "InternetTimeToSystemTimeW failed (%u)\n", GetLastError() );
707     ok( !memcmp( &time, &expect, sizeof(expect) ),
708         "InternetTimeToSystemTimeW failed (%u)\n", GetLastError() );
709
710     ret = pInternetTimeToSystemTimeW( string3, &time, 0 );
711     ok( ret, "InternetTimeToSystemTimeW failed (%u)\n", GetLastError() );
712 }
713
714 static void test_IsDomainLegalCookieDomainW(void)
715 {
716     BOOL ret;
717     DWORD error;
718     static const WCHAR empty[]          = {0};
719     static const WCHAR dot[]            = {'.',0};
720     static const WCHAR uk[]             = {'u','k',0};
721     static const WCHAR com[]            = {'c','o','m',0};
722     static const WCHAR dot_com[]        = {'.','c','o','m',0};
723     static const WCHAR gmail_com[]      = {'g','m','a','i','l','.','c','o','m',0};
724     static const WCHAR dot_gmail_com[]  = {'.','g','m','a','i','l','.','c','o','m',0};
725     static const WCHAR mail_gmail_com[] = {'m','a','i','l','.','g','m','a','i','l','.','c','o','m',0};
726     static const WCHAR gmail_co_uk[]    = {'g','m','a','i','l','.','c','o','.','u','k',0};
727     static const WCHAR co_uk[]          = {'c','o','.','u','k',0};
728     static const WCHAR dot_co_uk[]      = {'.','c','o','.','u','k',0};
729
730     SetLastError(0xdeadbeef);
731     ret = pIsDomainLegalCookieDomainW(NULL, NULL);
732     error = GetLastError();
733     if (!ret && error == ERROR_CALL_NOT_IMPLEMENTED)
734     {
735         win_skip("IsDomainLegalCookieDomainW is not implemented\n");
736         return;
737     }
738     ok(!ret ||
739         broken(ret), /* IE6 */
740         "IsDomainLegalCookieDomainW succeeded\n");
741     ok(error == ERROR_INVALID_PARAMETER, "got %u expected ERROR_INVALID_PARAMETER\n", error);
742
743     SetLastError(0xdeadbeef);
744     ret = pIsDomainLegalCookieDomainW(com, NULL);
745     error = GetLastError();
746     ok(!ret, "IsDomainLegalCookieDomainW succeeded\n");
747     ok(error == ERROR_INVALID_PARAMETER, "got %u expected ERROR_INVALID_PARAMETER\n", error);
748
749     SetLastError(0xdeadbeef);
750     ret = pIsDomainLegalCookieDomainW(NULL, gmail_com);
751     error = GetLastError();
752     ok(!ret, "IsDomainLegalCookieDomainW succeeded\n");
753     ok(error == ERROR_INVALID_PARAMETER, "got %u expected ERROR_INVALID_PARAMETER\n", error);
754
755     SetLastError(0xdeadbeef);
756     ret = pIsDomainLegalCookieDomainW(empty, gmail_com);
757     error = GetLastError();
758     ok(!ret, "IsDomainLegalCookieDomainW succeeded\n");
759     ok(error == ERROR_INVALID_NAME ||
760         broken(error == ERROR_INVALID_PARAMETER), /* IE6 */
761         "got %u expected ERROR_INVALID_NAME\n", error);
762
763     SetLastError(0xdeadbeef);
764     ret = pIsDomainLegalCookieDomainW(com, empty);
765     error = GetLastError();
766     ok(!ret, "IsDomainLegalCookieDomainW succeeded\n");
767     ok(error == ERROR_INVALID_NAME ||
768         broken(error == ERROR_INVALID_PARAMETER), /* IE6 */
769         "got %u expected ERROR_INVALID_NAME\n", error);
770
771     SetLastError(0xdeadbeef);
772     ret = pIsDomainLegalCookieDomainW(gmail_com, dot);
773     error = GetLastError();
774     ok(!ret, "IsDomainLegalCookieDomainW succeeded\n");
775     ok(error == ERROR_INVALID_NAME ||
776         broken(error == 0xdeadbeef), /* IE6 */
777         "got %u expected ERROR_INVALID_NAME\n", error);
778
779     SetLastError(0xdeadbeef);
780     ret = pIsDomainLegalCookieDomainW(dot, gmail_com);
781     error = GetLastError();
782     ok(!ret, "IsDomainLegalCookieDomainW succeeded\n");
783     ok(error == ERROR_INVALID_NAME ||
784         broken(error == 0xdeadbeef), /* IE6 */
785         "got %u expected ERROR_INVALID_NAME\n", error);
786
787     SetLastError(0xdeadbeef);
788     ret = pIsDomainLegalCookieDomainW(com, com);
789     error = GetLastError();
790     ok(!ret, "IsDomainLegalCookieDomainW succeeded\n");
791     ok(error == 0xdeadbeef, "got %u expected 0xdeadbeef\n", error);
792
793     SetLastError(0xdeadbeef);
794     ret = pIsDomainLegalCookieDomainW(com, dot_com);
795     error = GetLastError();
796     ok(!ret, "IsDomainLegalCookieDomainW succeeded\n");
797     ok(error == ERROR_INVALID_NAME ||
798         broken(error == 0xdeadbeef), /* IE6 */
799         "got %u expected ERROR_INVALID_NAME\n", error);
800
801     SetLastError(0xdeadbeef);
802     ret = pIsDomainLegalCookieDomainW(dot_com, com);
803     error = GetLastError();
804     ok(!ret, "IsDomainLegalCookieDomainW succeeded\n");
805     ok(error == ERROR_INVALID_NAME ||
806         broken(error == 0xdeadbeef), /* IE6 */
807         "got %u expected ERROR_INVALID_NAME\n", error);
808
809     SetLastError(0xdeadbeef);
810     ret = pIsDomainLegalCookieDomainW(com, gmail_com);
811     error = GetLastError();
812     ok(!ret, "IsDomainLegalCookieDomainW succeeded\n");
813     ok(error == ERROR_SXS_KEY_NOT_FOUND ||
814         error == ERROR_SUCCESS || /* IE8 on W2K3 */
815         error == 0xdeadbeef, /* up to IE7 */
816         "unexpected error: %u\n", error);
817
818     ret = pIsDomainLegalCookieDomainW(gmail_com, gmail_com);
819     ok(ret, "IsDomainLegalCookieDomainW failed\n");
820
821     SetLastError(0xdeadbeef);
822     ret = pIsDomainLegalCookieDomainW(gmail_co_uk, co_uk);
823     error = GetLastError();
824     ok(!ret, "IsDomainLegalCookieDomainW succeeded\n");
825     ok(error == ERROR_SXS_KEY_NOT_FOUND || /* IE8 on XP */
826         error == ERROR_FILE_NOT_FOUND ||   /* IE8 on Vista */
827         error == ERROR_SUCCESS || /* IE8 on W2K3 */
828         error == 0xdeadbeef, /* up to IE7 */
829         "unexpected error: %u\n", error);
830
831     ret = pIsDomainLegalCookieDomainW(uk, co_uk);
832     ok(!ret, "IsDomainLegalCookieDomainW succeeded\n");
833
834     ret = pIsDomainLegalCookieDomainW(gmail_co_uk, dot_co_uk);
835     ok(!ret, "IsDomainLegalCookieDomainW succeeded\n");
836
837     ret = pIsDomainLegalCookieDomainW(gmail_co_uk, gmail_co_uk);
838     ok(ret, "IsDomainLegalCookieDomainW failed\n");
839
840     ret = pIsDomainLegalCookieDomainW(gmail_com, com);
841     ok(!ret, "IsDomainLegalCookieDomainW succeeded\n");
842
843     SetLastError(0xdeadbeef);
844     ret = pIsDomainLegalCookieDomainW(dot_gmail_com, mail_gmail_com);
845     error = GetLastError();
846     ok(!ret, "IsDomainLegalCookieDomainW succeeded\n");
847     ok(error == ERROR_INVALID_NAME ||
848         broken(error == 0xdeadbeef), /* IE6 */
849         "got %u expected ERROR_INVALID_NAME\n", error);
850
851     ret = pIsDomainLegalCookieDomainW(gmail_com, mail_gmail_com);
852     ok(ret, "IsDomainLegalCookieDomainW failed\n");
853
854     ret = pIsDomainLegalCookieDomainW(mail_gmail_com, gmail_com);
855     ok(!ret, "IsDomainLegalCookieDomainW succeeded\n");
856
857     ret = pIsDomainLegalCookieDomainW(mail_gmail_com, com);
858     ok(!ret, "IsDomainLegalCookieDomainW succeeded\n");
859
860     ret = pIsDomainLegalCookieDomainW(dot_gmail_com, mail_gmail_com);
861     ok(!ret, "IsDomainLegalCookieDomainW succeeded\n");
862
863     ret = pIsDomainLegalCookieDomainW(mail_gmail_com, dot_gmail_com);
864     ok(!ret, "IsDomainLegalCookieDomainW succeeded\n");
865 }
866
867 static void test_PrivacyGetSetZonePreferenceW(void)
868 {
869     DWORD ret, zone, type, template, old_template;
870
871     zone = 3;
872     type = 0;
873     ret = pPrivacyGetZonePreferenceW(zone, type, NULL, NULL, NULL);
874     ok(ret == 0, "expected ret == 0, got %u\n", ret);
875
876     old_template = 0;
877     ret = pPrivacyGetZonePreferenceW(zone, type, &old_template, NULL, NULL);
878     ok(ret == 0, "expected ret == 0, got %u\n", ret);
879
880     template = 5;
881     ret = pPrivacySetZonePreferenceW(zone, type, template, NULL);
882     ok(ret == 0, "expected ret == 0, got %u\n", ret);
883
884     template = 0;
885     ret = pPrivacyGetZonePreferenceW(zone, type, &template, NULL, NULL);
886     ok(ret == 0, "expected ret == 0, got %u\n", ret);
887     ok(template == 5, "expected template == 5, got %u\n", template);
888
889     template = 5;
890     ret = pPrivacySetZonePreferenceW(zone, type, old_template, NULL);
891     ok(ret == 0, "expected ret == 0, got %u\n", ret);
892 }
893
894 static void test_InternetSetOption(void)
895 {
896     HINTERNET ses, con, req;
897     ULONG ulArg;
898     DWORD size;
899     BOOL ret;
900
901     ses = InternetOpen(NULL, INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, 0);
902     ok(ses != 0, "InternetOpen failed: 0x%08x\n", GetLastError());
903     con = InternetConnect(ses, "www.winehq.org", 80, NULL, NULL, INTERNET_SERVICE_HTTP, 0, 0);
904     ok(con != 0, "InternetConnect failed: 0x%08x\n", GetLastError());
905     req = HttpOpenRequest(con, "GET", "/", NULL, NULL, NULL, 0, 0);
906     ok(req != 0, "HttpOpenRequest failed: 0x%08x\n", GetLastError());
907
908     /* INTERNET_OPTION_POLICY tests */
909     SetLastError(0xdeadbeef);
910     ret = InternetSetOptionW(ses, INTERNET_OPTION_POLICY, NULL, 0);
911     ok(ret == FALSE, "InternetSetOption should've failed\n");
912     ok(GetLastError() == ERROR_INVALID_PARAMETER, "GetLastError should've "
913             "given ERROR_INVALID_PARAMETER, gave: 0x%08x\n", GetLastError());
914
915     SetLastError(0xdeadbeef);
916     ret = InternetQueryOptionW(ses, INTERNET_OPTION_POLICY, NULL, 0);
917     ok(ret == FALSE, "InternetQueryOption should've failed\n");
918     ok(GetLastError() == ERROR_INVALID_PARAMETER, "GetLastError should've "
919             "given ERROR_INVALID_PARAMETER, gave: 0x%08x\n", GetLastError());
920
921     /* INTERNET_OPTION_ERROR_MASK tests */
922     SetLastError(0xdeadbeef);
923     size = sizeof(ulArg);
924     ret = InternetQueryOptionW(NULL, INTERNET_OPTION_ERROR_MASK, (void*)&ulArg, &size);
925     ok(ret == FALSE, "InternetQueryOption should've failed\n");
926     ok(GetLastError() == ERROR_INTERNET_INCORRECT_HANDLE_TYPE, "GetLastError() = %x\n", GetLastError());
927
928     SetLastError(0xdeadbeef);
929     ulArg = 11;
930     ret = InternetSetOption(NULL, INTERNET_OPTION_ERROR_MASK, (void*)&ulArg, sizeof(ULONG));
931     ok(ret == FALSE, "InternetQueryOption should've failed\n");
932     ok(GetLastError() == ERROR_INTERNET_INCORRECT_HANDLE_TYPE, "GetLastError() = %x\n", GetLastError());
933
934     SetLastError(0xdeadbeef);
935     ulArg = 11;
936     ret = InternetSetOption(req, INTERNET_OPTION_ERROR_MASK, (void*)&ulArg, 20);
937     ok(ret == FALSE, "InternetQueryOption should've failed\n");
938     ok(GetLastError() == ERROR_INTERNET_BAD_OPTION_LENGTH, "GetLastError() = %d\n", GetLastError());
939
940     SetLastError(0xdeadbeef);
941     ulArg = 11;
942     ret = InternetSetOption(req, INTERNET_OPTION_ERROR_MASK, (void*)&ulArg, sizeof(ULONG));
943     ok(ret == TRUE, "InternetQueryOption should've succeeded\n");
944     ok(GetLastError() == 0xdeadbeef, "GetLastError() = %d\n", GetLastError());
945
946     SetLastError(0xdeadbeef);
947     ulArg = 4;
948     ret = InternetSetOption(req, INTERNET_OPTION_ERROR_MASK, (void*)&ulArg, sizeof(ULONG));
949     ok(ret == FALSE, "InternetQueryOption should've failed\n");
950     ok(GetLastError() == ERROR_INVALID_PARAMETER, "GetLastError() = %x\n", GetLastError());
951
952     SetLastError(0xdeadbeef);
953     ulArg = 16;
954     ret = InternetSetOption(req, INTERNET_OPTION_ERROR_MASK, (void*)&ulArg, sizeof(ULONG));
955     ok(ret == FALSE, "InternetQueryOption should've failed\n");
956     ok(GetLastError() == ERROR_INVALID_PARAMETER, "GetLastError() = %x\n", GetLastError());
957
958     ret = InternetCloseHandle(req);
959     ok(ret == TRUE, "InternetCloseHandle failed: 0x%08x\n", GetLastError());
960     ret = InternetCloseHandle(con);
961     ok(ret == TRUE, "InternetCloseHandle failed: 0x%08x\n", GetLastError());
962     ret = InternetCloseHandle(ses);
963     ok(ret == TRUE, "InternetCloseHandle failed: 0x%08x\n", GetLastError());
964 }
965
966 #define verifyProxyEnable(e) r_verifyProxyEnable(__LINE__, e)
967 static void r_verifyProxyEnable(LONG l, DWORD exp)
968 {
969     HKEY hkey;
970     DWORD type, val, size = sizeof(DWORD);
971     LONG ret;
972     static const CHAR szInternetSettings[] = "Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings";
973     static const CHAR szProxyEnable[] = "ProxyEnable";
974
975     ret = RegOpenKeyA(HKEY_CURRENT_USER, szInternetSettings, &hkey);
976     ok_(__FILE__,l) (!ret, "RegOpenKeyA failed: 0x%08x\n", ret);
977
978     ret = RegQueryValueExA(hkey, szProxyEnable, 0, &type, (BYTE*)&val, &size);
979     ok_(__FILE__,l) (!ret, "RegQueryValueExA failed: 0x%08x\n", ret);
980     ok_(__FILE__,l) (type == REG_DWORD, "Expected regtype to be REG_DWORD, was: %d\n", type);
981     ok_(__FILE__,l) (val == exp, "Expected ProxyEnabled to be %d, got: %d\n", exp, val);
982
983     ret = RegCloseKey(hkey);
984     ok_(__FILE__,l) (!ret, "RegCloseKey failed: 0x%08x\n", ret);
985 }
986
987 static void test_Option_PerConnectionOption(void)
988 {
989     BOOL ret;
990     DWORD size = sizeof(INTERNET_PER_CONN_OPTION_LISTW);
991     INTERNET_PER_CONN_OPTION_LISTW list = {size};
992     INTERNET_PER_CONN_OPTIONW *orig_settings;
993     static WCHAR proxy_srvW[] = {'p','r','o','x','y','.','e','x','a','m','p','l','e',0};
994
995     /* get the global IE proxy server info, to restore later */
996     list.dwOptionCount = 2;
997     list.pOptions = HeapAlloc(GetProcessHeap(), 0, 2 * sizeof(INTERNET_PER_CONN_OPTIONW));
998
999     list.pOptions[0].dwOption = INTERNET_PER_CONN_PROXY_SERVER;
1000     list.pOptions[1].dwOption = INTERNET_PER_CONN_FLAGS;
1001
1002     ret = InternetQueryOptionW(NULL, INTERNET_OPTION_PER_CONNECTION_OPTION,
1003             &list, &size);
1004     ok(ret == TRUE, "InternetQueryOption should've succeeded\n");
1005     orig_settings = list.pOptions;
1006
1007     /* set the global IE proxy server */
1008     list.dwOptionCount = 2;
1009     list.pOptions = HeapAlloc(GetProcessHeap(), 0, 2 * sizeof(INTERNET_PER_CONN_OPTIONW));
1010
1011     list.pOptions[0].dwOption = INTERNET_PER_CONN_PROXY_SERVER;
1012     list.pOptions[0].Value.pszValue = proxy_srvW;
1013     list.pOptions[1].dwOption = INTERNET_PER_CONN_FLAGS;
1014     list.pOptions[1].Value.dwValue = PROXY_TYPE_PROXY;
1015
1016     ret = InternetSetOptionW(NULL, INTERNET_OPTION_PER_CONNECTION_OPTION,
1017             &list, size);
1018     ok(ret == TRUE, "InternetSetOption should've succeeded\n");
1019
1020     HeapFree(GetProcessHeap(), 0, list.pOptions);
1021
1022     /* get & verify the global IE proxy server */
1023     list.dwOptionCount = 2;
1024     list.dwOptionError = 0;
1025     list.pOptions = HeapAlloc(GetProcessHeap(), 0, 2 * sizeof(INTERNET_PER_CONN_OPTIONW));
1026
1027     list.pOptions[0].dwOption = INTERNET_PER_CONN_PROXY_SERVER;
1028     list.pOptions[1].dwOption = INTERNET_PER_CONN_FLAGS;
1029
1030     ret = InternetQueryOptionW(NULL, INTERNET_OPTION_PER_CONNECTION_OPTION,
1031             &list, &size);
1032     ok(ret == TRUE, "InternetQueryOption should've succeeded\n");
1033     ok(!lstrcmpW(list.pOptions[0].Value.pszValue, proxy_srvW),
1034             "Retrieved proxy server should've been %s, was: %s\n",
1035             wine_dbgstr_w(proxy_srvW), wine_dbgstr_w(list.pOptions[0].Value.pszValue));
1036     ok(list.pOptions[1].Value.dwValue == PROXY_TYPE_PROXY,
1037             "Retrieved flags should've been PROXY_TYPE_PROXY, was: %d\n",
1038             list.pOptions[1].Value.dwValue);
1039     verifyProxyEnable(1);
1040
1041     HeapFree(GetProcessHeap(), 0, list.pOptions[0].Value.pszValue);
1042     HeapFree(GetProcessHeap(), 0, list.pOptions);
1043
1044     /* disable the proxy server */
1045     list.dwOptionCount = 1;
1046     list.pOptions = HeapAlloc(GetProcessHeap(), 0, sizeof(INTERNET_PER_CONN_OPTIONW));
1047
1048     list.pOptions[0].dwOption = INTERNET_PER_CONN_FLAGS;
1049     list.pOptions[0].Value.dwValue = PROXY_TYPE_DIRECT;
1050
1051     ret = InternetSetOptionW(NULL, INTERNET_OPTION_PER_CONNECTION_OPTION,
1052             &list, size);
1053     ok(ret == TRUE, "InternetSetOption should've succeeded\n");
1054
1055     HeapFree(GetProcessHeap(), 0, list.pOptions);
1056
1057     /* verify that the proxy is disabled */
1058     list.dwOptionCount = 1;
1059     list.dwOptionError = 0;
1060     list.pOptions = HeapAlloc(GetProcessHeap(), 0, sizeof(INTERNET_PER_CONN_OPTIONW));
1061
1062     list.pOptions[0].dwOption = INTERNET_PER_CONN_FLAGS;
1063
1064     ret = InternetQueryOptionW(NULL, INTERNET_OPTION_PER_CONNECTION_OPTION,
1065             &list, &size);
1066     ok(ret == TRUE, "InternetQueryOption should've succeeded\n");
1067     ok(list.pOptions[0].Value.dwValue == PROXY_TYPE_DIRECT,
1068             "Retrieved flags should've been PROXY_TYPE_DIRECT, was: %d\n",
1069             list.pOptions[0].Value.dwValue);
1070     verifyProxyEnable(0);
1071
1072     HeapFree(GetProcessHeap(), 0, list.pOptions);
1073
1074     /* set the proxy flags to 'invalid' value */
1075     list.dwOptionCount = 1;
1076     list.pOptions = HeapAlloc(GetProcessHeap(), 0, sizeof(INTERNET_PER_CONN_OPTIONW));
1077
1078     list.pOptions[0].dwOption = INTERNET_PER_CONN_FLAGS;
1079     list.pOptions[0].Value.dwValue = PROXY_TYPE_PROXY | PROXY_TYPE_DIRECT;
1080
1081     ret = InternetSetOptionW(NULL, INTERNET_OPTION_PER_CONNECTION_OPTION,
1082             &list, size);
1083     ok(ret == TRUE, "InternetSetOption should've succeeded\n");
1084
1085     HeapFree(GetProcessHeap(), 0, list.pOptions);
1086
1087     /* verify that the proxy is enabled */
1088     list.dwOptionCount = 1;
1089     list.dwOptionError = 0;
1090     list.pOptions = HeapAlloc(GetProcessHeap(), 0, sizeof(INTERNET_PER_CONN_OPTIONW));
1091
1092     list.pOptions[0].dwOption = INTERNET_PER_CONN_FLAGS;
1093
1094     ret = InternetQueryOptionW(NULL, INTERNET_OPTION_PER_CONNECTION_OPTION,
1095             &list, &size);
1096     ok(ret == TRUE, "InternetQueryOption should've succeeded\n");
1097     todo_wine ok(list.pOptions[0].Value.dwValue == (PROXY_TYPE_PROXY | PROXY_TYPE_DIRECT),
1098             "Retrieved flags should've been PROXY_TYPE_PROXY | PROXY_TYPE_DIRECT, was: %d\n",
1099             list.pOptions[0].Value.dwValue);
1100     verifyProxyEnable(1);
1101
1102     HeapFree(GetProcessHeap(), 0, list.pOptions);
1103
1104     /* restore original settings */
1105     list.dwOptionCount = 2;
1106     list.pOptions = orig_settings;
1107
1108     ret = InternetSetOptionW(NULL, INTERNET_OPTION_PER_CONNECTION_OPTION,
1109             &list, size);
1110     ok(ret == TRUE, "InternetSetOption should've succeeded\n");
1111
1112     HeapFree(GetProcessHeap(), 0, list.pOptions);
1113 }
1114
1115 static void test_Option_PerConnectionOptionA(void)
1116 {
1117     BOOL ret;
1118     DWORD size = sizeof(INTERNET_PER_CONN_OPTION_LISTA);
1119     INTERNET_PER_CONN_OPTION_LISTA list = {size};
1120     INTERNET_PER_CONN_OPTIONA *orig_settings;
1121     char proxy_srv[] = "proxy.example";
1122
1123     /* get the global IE proxy server info, to restore later */
1124     list.dwOptionCount = 2;
1125     list.pOptions = HeapAlloc(GetProcessHeap(), 0, 2 * sizeof(INTERNET_PER_CONN_OPTIONA));
1126
1127     list.pOptions[0].dwOption = INTERNET_PER_CONN_PROXY_SERVER;
1128     list.pOptions[1].dwOption = INTERNET_PER_CONN_FLAGS;
1129
1130     ret = InternetQueryOptionA(NULL, INTERNET_OPTION_PER_CONNECTION_OPTION,
1131             &list, &size);
1132     ok(ret == TRUE, "InternetQueryOption should've succeeded\n");
1133     orig_settings = list.pOptions;
1134
1135     /* set the global IE proxy server */
1136     list.dwOptionCount = 2;
1137     list.pOptions = HeapAlloc(GetProcessHeap(), 0, 2 * sizeof(INTERNET_PER_CONN_OPTIONA));
1138
1139     list.pOptions[0].dwOption = INTERNET_PER_CONN_PROXY_SERVER;
1140     list.pOptions[0].Value.pszValue = proxy_srv;
1141     list.pOptions[1].dwOption = INTERNET_PER_CONN_FLAGS;
1142     list.pOptions[1].Value.dwValue = PROXY_TYPE_PROXY;
1143
1144     ret = InternetSetOptionA(NULL, INTERNET_OPTION_PER_CONNECTION_OPTION,
1145             &list, size);
1146     ok(ret == TRUE, "InternetSetOption should've succeeded\n");
1147
1148     HeapFree(GetProcessHeap(), 0, list.pOptions);
1149
1150     /* get & verify the global IE proxy server */
1151     list.dwOptionCount = 2;
1152     list.dwOptionError = 0;
1153     list.pOptions = HeapAlloc(GetProcessHeap(), 0, 2 * sizeof(INTERNET_PER_CONN_OPTIONA));
1154
1155     list.pOptions[0].dwOption = INTERNET_PER_CONN_PROXY_SERVER;
1156     list.pOptions[1].dwOption = INTERNET_PER_CONN_FLAGS;
1157
1158     ret = InternetQueryOptionA(NULL, INTERNET_OPTION_PER_CONNECTION_OPTION,
1159             &list, &size);
1160     ok(ret == TRUE, "InternetQueryOption should've succeeded\n");
1161     ok(!lstrcmpA(list.pOptions[0].Value.pszValue, "proxy.example"),
1162             "Retrieved proxy server should've been \"%s\", was: \"%s\"\n",
1163             proxy_srv, list.pOptions[0].Value.pszValue);
1164     ok(list.pOptions[1].Value.dwValue == PROXY_TYPE_PROXY,
1165             "Retrieved flags should've been PROXY_TYPE_PROXY, was: %d\n",
1166             list.pOptions[1].Value.dwValue);
1167
1168     HeapFree(GetProcessHeap(), 0, list.pOptions[0].Value.pszValue);
1169     HeapFree(GetProcessHeap(), 0, list.pOptions);
1170
1171     /* restore original settings */
1172     list.dwOptionCount = 2;
1173     list.pOptions = orig_settings;
1174
1175     ret = InternetSetOptionA(NULL, INTERNET_OPTION_PER_CONNECTION_OPTION,
1176             &list, size);
1177     ok(ret == TRUE, "InternetSetOption should've succeeded\n");
1178
1179     HeapFree(GetProcessHeap(), 0, list.pOptions);
1180 }
1181
1182 #define FLAG_TODO     0x1
1183 #define FLAG_NEEDREQ  0x2
1184 #define FLAG_UNIMPL   0x4
1185
1186 static void test_InternetErrorDlg(void)
1187 {
1188     HINTERNET ses, con, req;
1189     DWORD res, flags;
1190     HWND hwnd;
1191     ULONG i;
1192     static const struct {
1193         DWORD error;
1194         DWORD res;
1195         DWORD test_flags;
1196     } no_ui_res[] = {
1197         { ERROR_INTERNET_INCORRECT_PASSWORD     , ERROR_SUCCESS, FLAG_NEEDREQ },
1198         { ERROR_INTERNET_SEC_CERT_DATE_INVALID  , ERROR_CANCELLED, 0 },
1199         { ERROR_INTERNET_SEC_CERT_CN_INVALID    , ERROR_CANCELLED, 0 },
1200         { ERROR_INTERNET_HTTP_TO_HTTPS_ON_REDIR , ERROR_SUCCESS, 0 },
1201         { ERROR_INTERNET_HTTPS_TO_HTTP_ON_REDIR , ERROR_SUCCESS, FLAG_TODO },
1202         { ERROR_INTERNET_MIXED_SECURITY         , ERROR_CANCELLED, FLAG_TODO },
1203         { ERROR_INTERNET_CHG_POST_IS_NON_SECURE , ERROR_CANCELLED, FLAG_TODO },
1204         { ERROR_INTERNET_POST_IS_NON_SECURE     , ERROR_SUCCESS, 0 },
1205         { ERROR_INTERNET_CLIENT_AUTH_CERT_NEEDED, ERROR_CANCELLED, FLAG_NEEDREQ|FLAG_TODO },
1206         { ERROR_INTERNET_INVALID_CA             , ERROR_CANCELLED, 0 },
1207         { ERROR_INTERNET_HTTPS_HTTP_SUBMIT_REDIR, ERROR_CANCELLED, FLAG_TODO },
1208         { ERROR_INTERNET_INSERT_CDROM           , ERROR_CANCELLED, FLAG_TODO|FLAG_NEEDREQ|FLAG_UNIMPL },
1209         { ERROR_INTERNET_SEC_CERT_ERRORS        , ERROR_CANCELLED, 0 },
1210         { ERROR_INTERNET_SEC_CERT_REV_FAILED    , ERROR_CANCELLED, FLAG_TODO },
1211         { ERROR_HTTP_COOKIE_NEEDS_CONFIRMATION  , ERROR_HTTP_COOKIE_DECLINED, FLAG_TODO },
1212         { ERROR_INTERNET_BAD_AUTO_PROXY_SCRIPT  , ERROR_CANCELLED, FLAG_TODO },
1213         { ERROR_INTERNET_UNABLE_TO_DOWNLOAD_SCRIPT, ERROR_CANCELLED, FLAG_TODO },
1214         { ERROR_HTTP_REDIRECT_NEEDS_CONFIRMATION, ERROR_CANCELLED, FLAG_TODO },
1215         { ERROR_INTERNET_SEC_CERT_REVOKED       , ERROR_CANCELLED, 0 },
1216         { 0, ERROR_NOT_SUPPORTED }
1217     };
1218
1219     flags = 0;
1220
1221     res = InternetErrorDlg(NULL, NULL, 12055, flags, NULL);
1222     ok(res == ERROR_INVALID_HANDLE, "Got %d\n", res);
1223
1224     ses = InternetOpen(NULL, INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, 0);
1225     ok(ses != 0, "InternetOpen failed: 0x%08x\n", GetLastError());
1226     con = InternetConnect(ses, "www.winehq.org", 80, NULL, NULL, INTERNET_SERVICE_HTTP, 0, 0);
1227     ok(con != 0, "InternetConnect failed: 0x%08x\n", GetLastError());
1228     req = HttpOpenRequest(con, "GET", "/", NULL, NULL, NULL, 0, 0);
1229     ok(req != 0, "HttpOpenRequest failed: 0x%08x\n", GetLastError());
1230
1231     /* NULL hwnd and FLAGS_ERROR_UI_FLAGS_NO_UI not set */
1232     for(i = INTERNET_ERROR_BASE; i < INTERNET_ERROR_LAST; i++)
1233     {
1234         res = InternetErrorDlg(NULL, req, i, flags, NULL);
1235         ok(res == ERROR_INVALID_HANDLE, "Got %d (%d)\n", res, i);
1236     }
1237
1238     hwnd = GetDesktopWindow();
1239     ok(hwnd != NULL, "GetDesktopWindow failed (%d)\n", GetLastError());
1240
1241     flags = FLAGS_ERROR_UI_FLAGS_NO_UI;
1242     for(i = INTERNET_ERROR_BASE; i < INTERNET_ERROR_LAST; i++)
1243     {
1244         DWORD expected, test_flags, j;
1245
1246         for(j = 0; no_ui_res[j].error != 0; ++j)
1247             if(no_ui_res[j].error == i)
1248                 break;
1249
1250         test_flags = no_ui_res[j].test_flags;
1251         expected = no_ui_res[j].res;
1252
1253         /* Try an invalid request handle */
1254         res = InternetErrorDlg(hwnd, (HANDLE)0xdeadbeef, i, flags, NULL);
1255         if(res == ERROR_CALL_NOT_IMPLEMENTED)
1256         {
1257             todo_wine ok(test_flags & FLAG_UNIMPL, "%i is unexpectedly unimplemented.\n", i);
1258             continue;
1259         }
1260         else
1261             todo_wine ok(res == ERROR_INVALID_HANDLE, "Got %d (%d)\n", res, i);
1262
1263         /* With a valid req */
1264         if(i == ERROR_INTERNET_NEED_UI)
1265             continue; /* Crashes on windows XP */
1266
1267         if(i == ERROR_INTERNET_SEC_CERT_REVOKED)
1268             continue; /* Interactive (XP, Win7) */
1269
1270         res = InternetErrorDlg(hwnd, req, i, flags, NULL);
1271
1272         /* Handle some special cases */
1273         switch(i)
1274         {
1275         case ERROR_INTERNET_HTTP_TO_HTTPS_ON_REDIR:
1276         case ERROR_INTERNET_HTTPS_TO_HTTP_ON_REDIR:
1277             if(res == ERROR_CANCELLED)
1278             {
1279                 /* Some windows XP, w2k3 x64, W2K8 */
1280                 win_skip("Skipping some tests for %d\n", i);
1281                 continue;
1282             }
1283             break;
1284         case ERROR_INTERNET_FORTEZZA_LOGIN_NEEDED:
1285             if(res != expected)
1286             {
1287                 /* Windows XP, W2K3 */
1288                 ok(res == NTE_PROV_TYPE_NOT_DEF, "Got %d\n", res);
1289                 win_skip("Skipping some tests for %d\n", i);
1290                 continue;
1291             }
1292             break;
1293         default: break;
1294         }
1295
1296         if(test_flags & FLAG_TODO)
1297             todo_wine ok(res == expected, "Got %d, expected %d (%d)\n", res, expected, i);
1298         else
1299             ok(res == expected, "Got %d, expected %d (%d)\n", res, expected, i);
1300
1301         /* Same thing with NULL hwnd */
1302         res = InternetErrorDlg(NULL, req, i, flags, NULL);
1303         if(test_flags & FLAG_TODO)
1304             todo_wine ok(res == expected, "Got %d, expected %d (%d)\n", res, expected, i);
1305         else
1306             ok(res == expected, "Got %d, expected %d (%d)\n", res, expected, i);
1307
1308
1309         /* With a null req */
1310         if(test_flags & FLAG_NEEDREQ)
1311             expected = ERROR_INVALID_PARAMETER;
1312
1313         res = InternetErrorDlg(hwnd, NULL, i, flags, NULL);
1314         if( test_flags & FLAG_TODO || i == ERROR_INTERNET_INCORRECT_PASSWORD)
1315             todo_wine ok(res == expected, "Got %d, expected %d (%d)\n", res, expected, i);
1316         else
1317             ok(res == expected, "Got %d, expected %d (%d)\n", res, expected, i);
1318     }
1319
1320     res = InternetCloseHandle(req);
1321     ok(res == TRUE, "InternetCloseHandle failed: 0x%08x\n", GetLastError());
1322     res = InternetCloseHandle(con);
1323     ok(res == TRUE, "InternetCloseHandle failed: 0x%08x\n", GetLastError());
1324     res = InternetCloseHandle(ses);
1325     ok(res == TRUE, "InternetCloseHandle failed: 0x%08x\n", GetLastError());
1326 }
1327
1328 /* ############################### */
1329
1330 START_TEST(internet)
1331 {
1332     HMODULE hdll;
1333     hdll = GetModuleHandleA("wininet.dll");
1334
1335     if(!GetProcAddress(hdll, "InternetGetCookieExW")) {
1336         win_skip("Too old IE (older than 6.0)\n");
1337         return;
1338     }
1339
1340     pCreateUrlCacheContainerA = (void*)GetProcAddress(hdll, "CreateUrlCacheContainerA");
1341     pCreateUrlCacheContainerW = (void*)GetProcAddress(hdll, "CreateUrlCacheContainerW");
1342     pInternetTimeFromSystemTimeA = (void*)GetProcAddress(hdll, "InternetTimeFromSystemTimeA");
1343     pInternetTimeFromSystemTimeW = (void*)GetProcAddress(hdll, "InternetTimeFromSystemTimeW");
1344     pInternetTimeToSystemTimeA = (void*)GetProcAddress(hdll, "InternetTimeToSystemTimeA");
1345     pInternetTimeToSystemTimeW = (void*)GetProcAddress(hdll, "InternetTimeToSystemTimeW");
1346     pIsDomainLegalCookieDomainW = (void*)GetProcAddress(hdll, (LPCSTR)117);
1347     pPrivacyGetZonePreferenceW = (void*)GetProcAddress(hdll, "PrivacyGetZonePreferenceW");
1348     pPrivacySetZonePreferenceW = (void*)GetProcAddress(hdll, "PrivacySetZonePreferenceW");
1349
1350     test_InternetCanonicalizeUrlA();
1351     test_InternetQueryOptionA();
1352     test_get_cookie();
1353     test_complicated_cookie();
1354     test_version();
1355     test_null();
1356     test_Option_PerConnectionOption();
1357     test_Option_PerConnectionOptionA();
1358     test_InternetErrorDlg();
1359     test_max_conns();
1360
1361     if (!pInternetTimeFromSystemTimeA)
1362         win_skip("skipping the InternetTime tests\n");
1363     else
1364     {
1365         InternetTimeFromSystemTimeA_test();
1366         InternetTimeFromSystemTimeW_test();
1367         InternetTimeToSystemTimeA_test();
1368         InternetTimeToSystemTimeW_test();
1369     }
1370     if (pIsDomainLegalCookieDomainW &&
1371         ((void*)pIsDomainLegalCookieDomainW == (void*)pCreateUrlCacheContainerA ||
1372          (void*)pIsDomainLegalCookieDomainW == (void*)pCreateUrlCacheContainerW))
1373         win_skip("IsDomainLegalCookieDomainW is not available on systems with IE5\n");
1374     else if (!pIsDomainLegalCookieDomainW)
1375         win_skip("IsDomainLegalCookieDomainW (or ordinal 117) is not available\n");
1376     else
1377         test_IsDomainLegalCookieDomainW();
1378
1379     if (pPrivacyGetZonePreferenceW && pPrivacySetZonePreferenceW)
1380         test_PrivacyGetSetZonePreferenceW();
1381     else
1382         win_skip("Privacy[SG]etZonePreferenceW are not available\n");
1383
1384     test_InternetSetOption();
1385 }