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