shlwapi: Beginning implementation of IUnknown_QueryServiceForWebBrowserApp.
[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 "wininet.h"
26 #include "winerror.h"
27
28 #include "wine/test.h"
29
30 static BOOL (WINAPI *pCreateUrlCacheContainerA)(DWORD, DWORD, DWORD, DWORD,
31                                                 DWORD, DWORD, DWORD, DWORD);
32 static BOOL (WINAPI *pCreateUrlCacheContainerW)(DWORD, DWORD, DWORD, DWORD,
33                                                 DWORD, DWORD, DWORD, DWORD);
34 static BOOL (WINAPI *pInternetTimeFromSystemTimeA)(CONST SYSTEMTIME *,DWORD ,LPSTR ,DWORD);
35 static BOOL (WINAPI *pInternetTimeFromSystemTimeW)(CONST SYSTEMTIME *,DWORD ,LPWSTR ,DWORD);
36 static BOOL (WINAPI *pInternetTimeToSystemTimeA)(LPCSTR ,SYSTEMTIME *,DWORD);
37 static BOOL (WINAPI *pInternetTimeToSystemTimeW)(LPCWSTR ,SYSTEMTIME *,DWORD);
38 static BOOL (WINAPI *pIsDomainLegalCookieDomainW)(LPCWSTR, LPCWSTR);
39 static DWORD (WINAPI *pPrivacyGetZonePreferenceW)(DWORD, DWORD, LPDWORD, LPWSTR, LPDWORD);
40 static DWORD (WINAPI *pPrivacySetZonePreferenceW)(DWORD, DWORD, DWORD, LPCWSTR);
41
42 /* ############################### */
43
44 static void test_InternetCanonicalizeUrlA(void)
45 {
46     CHAR    buffer[256];
47     LPCSTR  url;
48     DWORD   urllen;
49     DWORD   dwSize;
50     DWORD   res;
51
52     /* Acrobat Updater 5 calls this for Adobe Reader 8.1 */
53     url = "http://swupmf.adobe.com/manifest/50/win/AdobeUpdater.upd";
54     urllen = lstrlenA(url);
55
56     memset(buffer, '#', sizeof(buffer)-1);
57     buffer[sizeof(buffer)-1] = '\0';
58     dwSize = 1; /* Acrobat Updater use this size */
59     SetLastError(0xdeadbeef);
60     res = InternetCanonicalizeUrlA(url, buffer, &dwSize, 0);
61     ok( !res && (GetLastError() == ERROR_INSUFFICIENT_BUFFER) && (dwSize == (urllen+1)),
62         "got %u and %u with size %u for '%s' (%d)\n",
63         res, GetLastError(), dwSize, buffer, lstrlenA(buffer));
64
65
66     /* buffer has no space for the terminating '\0' */
67     memset(buffer, '#', sizeof(buffer)-1);
68     buffer[sizeof(buffer)-1] = '\0';
69     dwSize = urllen;
70     SetLastError(0xdeadbeef);
71     res = InternetCanonicalizeUrlA(url, buffer, &dwSize, 0);
72     /* dwSize is nr. of needed bytes with the terminating '\0' */
73     ok( !res && (GetLastError() == ERROR_INSUFFICIENT_BUFFER) && (dwSize == (urllen+1)),
74         "got %u and %u with size %u for '%s' (%d)\n",
75         res, GetLastError(), dwSize, buffer, lstrlenA(buffer));
76
77     /* buffer has the required size */
78     memset(buffer, '#', sizeof(buffer)-1);
79     buffer[sizeof(buffer)-1] = '\0';
80     dwSize = urllen+1;
81     SetLastError(0xdeadbeef);
82     res = InternetCanonicalizeUrlA(url, buffer, &dwSize, 0);
83     /* dwSize is nr. of copied bytes without the terminating '\0' */
84     ok( res && (dwSize == urllen) && (lstrcmpA(url, buffer) == 0),
85         "got %u and %u with size %u for '%s' (%d)\n",
86         res, GetLastError(), dwSize, buffer, lstrlenA(buffer));
87
88     memset(buffer, '#', sizeof(buffer)-1);
89     buffer[sizeof(buffer)-1] = '\0';
90     dwSize = sizeof(buffer);
91     SetLastError(0xdeadbeef);
92     res = InternetCanonicalizeUrlA("file:///C:/Program%20Files/Atmel/AVR%20Tools/STK500/STK500.xml", buffer, &dwSize, ICU_DECODE | ICU_NO_ENCODE);
93     ok(res, "InternetCanonicalizeUrlA failed %u\n", GetLastError());
94     ok(dwSize == lstrlenA(buffer), "got %d expected %d\n", dwSize, lstrlenA(buffer));
95     todo_wine ok(!lstrcmpA("file://C:\\Program Files\\Atmel\\AVR Tools\\STK500\\STK500.xml", buffer),
96        "got %s expected 'file://C:\\Program Files\\Atmel\\AVR Tools\\STK500\\STK500.xml'\n", buffer);
97
98     /* buffer is larger as the required size */
99     memset(buffer, '#', sizeof(buffer)-1);
100     buffer[sizeof(buffer)-1] = '\0';
101     dwSize = urllen+2;
102     SetLastError(0xdeadbeef);
103     res = InternetCanonicalizeUrlA(url, buffer, &dwSize, 0);
104     /* dwSize is nr. of copied bytes without the terminating '\0' */
105     ok( res && (dwSize == urllen) && (lstrcmpA(url, buffer) == 0),
106         "got %u and %u with size %u for '%s' (%d)\n",
107         res, GetLastError(), dwSize, buffer, lstrlenA(buffer));
108
109
110     /* check NULL pointers */
111     memset(buffer, '#', urllen + 4);
112     buffer[urllen + 4] = '\0';
113     dwSize = urllen+1;
114     SetLastError(0xdeadbeef);
115     res = InternetCanonicalizeUrlA(NULL, buffer, &dwSize, 0);
116     ok( !res && (GetLastError() == ERROR_INVALID_PARAMETER),
117         "got %u and %u with size %u for '%s' (%d)\n",
118         res, GetLastError(), dwSize, buffer, lstrlenA(buffer));
119
120     memset(buffer, '#', urllen + 4);
121     buffer[urllen + 4] = '\0';
122     dwSize = urllen+1;
123     SetLastError(0xdeadbeef);
124     res = InternetCanonicalizeUrlA(url, NULL, &dwSize, 0);
125     ok( !res && (GetLastError() == ERROR_INVALID_PARAMETER),
126         "got %u and %u with size %u for '%s' (%d)\n",
127         res, GetLastError(), dwSize, buffer, lstrlenA(buffer));
128
129     memset(buffer, '#', urllen + 4);
130     buffer[urllen + 4] = '\0';
131     dwSize = urllen+1;
132     SetLastError(0xdeadbeef);
133     res = InternetCanonicalizeUrlA(url, buffer, NULL, 0);
134     ok( !res && (GetLastError() == ERROR_INVALID_PARAMETER),
135         "got %u and %u with size %u for '%s' (%d)\n",
136         res, GetLastError(), dwSize, buffer, lstrlenA(buffer));
137
138     /* test with trailing space */
139     dwSize = 256;
140     res = InternetCanonicalizeUrlA("http://www.winehq.org/index.php?x= ", buffer, &dwSize, ICU_BROWSER_MODE);
141     ok(res == 1, "InternetCanonicalizeUrlA failed\n");
142     ok(!strcmp(buffer, "http://www.winehq.org/index.php?x="), "Trailing space should have been stripped even in ICU_BROWSER_MODE (%s)\n", buffer);
143
144     res = InternetSetOptionA(NULL, 0xdeadbeef, buffer, sizeof(buffer));
145     ok(!res, "InternetSetOptionA succeeded\n");
146     ok(GetLastError() == ERROR_INTERNET_INVALID_OPTION,
147        "InternetSetOptionA failed %u, expected ERROR_INTERNET_INVALID_OPTION\n", GetLastError());
148 }
149
150 /* ############################### */
151
152 static void test_InternetQueryOptionA(void)
153 {
154   HINTERNET hinet,hurl;
155   DWORD len;
156   DWORD err;
157   static const char useragent[] = {"Wininet Test"};
158   char *buffer;
159   int retval;
160
161   hinet = InternetOpenA(useragent,INTERNET_OPEN_TYPE_DIRECT,NULL,NULL, 0);
162   ok((hinet != 0x0),"InternetOpen Failed\n");
163
164   SetLastError(0xdeadbeef);
165   retval=InternetQueryOptionA(NULL,INTERNET_OPTION_USER_AGENT,NULL,&len);
166   err=GetLastError();
167   ok(retval == 0,"Got wrong return value %d\n",retval);
168   ok(err == ERROR_INTERNET_INCORRECT_HANDLE_TYPE, "Got wrong error code%d\n",err);
169
170   SetLastError(0xdeadbeef);
171   len=strlen(useragent)+1;
172   retval=InternetQueryOptionA(hinet,INTERNET_OPTION_USER_AGENT,NULL,&len);
173   err=GetLastError();
174   ok(len == strlen(useragent)+1,"Got wrong user agent length %d instead of %d\n",len,lstrlenA(useragent));
175   ok(retval == 0,"Got wrong return value %d\n",retval);
176   ok(err == ERROR_INSUFFICIENT_BUFFER, "Got wrong error code %d\n",err);
177
178   SetLastError(0xdeadbeef);
179   len=strlen(useragent)+1;
180   buffer=HeapAlloc(GetProcessHeap(),0,len);
181   retval=InternetQueryOptionA(hinet,INTERNET_OPTION_USER_AGENT,buffer,&len);
182   err=GetLastError();
183   ok(retval == 1,"Got wrong return value %d\n",retval);
184   if (retval)
185   {
186       ok(!strcmp(useragent,buffer),"Got wrong user agent string %s instead of %s\n",buffer,useragent);
187       ok(len == strlen(useragent),"Got wrong user agent length %d instead of %d\n",len,lstrlenA(useragent));
188   }
189   ok(err == 0xdeadbeef, "Got wrong error code %d\n",err);
190   HeapFree(GetProcessHeap(),0,buffer);
191
192   SetLastError(0xdeadbeef);
193   len=0;
194   buffer=HeapAlloc(GetProcessHeap(),0,100);
195   retval=InternetQueryOptionA(hinet,INTERNET_OPTION_USER_AGENT,buffer,&len);
196   err=GetLastError();
197   ok(len == strlen(useragent) + 1,"Got wrong user agent length %d instead of %d\n", len, lstrlenA(useragent) + 1);
198   ok(!retval, "Got wrong return value %d\n", retval);
199   ok(err == ERROR_INSUFFICIENT_BUFFER, "Got wrong error code %d\n", err);
200   HeapFree(GetProcessHeap(),0,buffer);
201
202   hurl = InternetConnectA(hinet,"www.winehq.org",INTERNET_DEFAULT_HTTP_PORT,NULL,NULL,INTERNET_SERVICE_HTTP,0,0);
203
204   SetLastError(0xdeadbeef);
205   len=0;
206   retval = InternetQueryOptionA(hurl,INTERNET_OPTION_USER_AGENT,NULL,&len);
207   err=GetLastError();
208   ok(len == 0,"Got wrong user agent length %d instead of 0\n",len);
209   ok(retval == 0,"Got wrong return value %d\n",retval);
210   ok(err == ERROR_INTERNET_INCORRECT_HANDLE_TYPE, "Got wrong error code %d\n",err);
211
212   InternetCloseHandle(hurl);
213   InternetCloseHandle(hinet);
214
215   hinet = InternetOpenA("",INTERNET_OPEN_TYPE_DIRECT,NULL,NULL, 0);
216   ok((hinet != 0x0),"InternetOpen Failed\n");
217
218   SetLastError(0xdeadbeef);
219   len=0;
220   retval=InternetQueryOptionA(hinet,INTERNET_OPTION_USER_AGENT,NULL,&len);
221   err=GetLastError();
222   ok(len == 1,"Got wrong user agent length %d instead of %d\n",len,1);
223   ok(retval == 0,"Got wrong return value %d\n",retval);
224   ok(err == ERROR_INSUFFICIENT_BUFFER, "Got wrong error code%d\n",err);
225
226   InternetCloseHandle(hinet);
227
228   hinet = InternetOpenA(NULL,INTERNET_OPEN_TYPE_DIRECT,NULL,NULL, 0);
229   ok((hinet != 0x0),"InternetOpen Failed\n");
230   SetLastError(0xdeadbeef);
231   len=0;
232   retval=InternetQueryOptionA(hinet,INTERNET_OPTION_USER_AGENT,NULL,&len);
233   err=GetLastError();
234   ok(len == 1,"Got wrong user agent length %d instead of %d\n",len,1);
235   ok(retval == 0,"Got wrong return value %d\n",retval);
236   ok(err == ERROR_INSUFFICIENT_BUFFER, "Got wrong error code%d\n",err);
237
238   InternetCloseHandle(hinet);
239 }
240
241 static void test_get_cookie(void)
242 {
243   DWORD len;
244   BOOL ret;
245
246   SetLastError(0xdeadbeef);
247   ret = InternetGetCookie("http://www.example.com", NULL, NULL, &len);
248   ok(!ret && GetLastError() == ERROR_NO_MORE_ITEMS,
249     "InternetGetCookie should have failed with %s and error %d\n",
250     ret ? "TRUE" : "FALSE", GetLastError());
251 }
252
253
254 static void test_complicated_cookie(void)
255 {
256   DWORD len;
257   BOOL ret;
258
259   CHAR buffer[1024];
260
261   ret = InternetSetCookie("http://www.example.com/bar",NULL,"A=B; domain=.example.com");
262   ok(ret == TRUE,"InternetSetCookie failed\n");
263   ret = InternetSetCookie("http://www.example.com/bar",NULL,"C=D; domain=.example.com; path=/");
264   ok(ret == TRUE,"InternetSetCookie failed\n");
265
266   /* Technically illegal! domain should require 2 dots, but native wininet accepts it */
267   ret = InternetSetCookie("http://www.example.com",NULL,"E=F; domain=example.com");
268   ok(ret == TRUE,"InternetSetCookie failed\n");
269   ret = InternetSetCookie("http://www.example.com",NULL,"G=H; domain=.example.com; path=/foo");
270   ok(ret == TRUE,"InternetSetCookie failed\n");
271   ret = InternetSetCookie("http://www.example.com/bar.html",NULL,"I=J; domain=.example.com");
272   ok(ret == TRUE,"InternetSetCookie failed\n");
273   ret = InternetSetCookie("http://www.example.com/bar/",NULL,"K=L; domain=.example.com");
274   ok(ret == TRUE,"InternetSetCookie failed\n");
275   ret = InternetSetCookie("http://www.example.com/bar/",NULL,"M=N; domain=.example.com; path=/foo/");
276   ok(ret == TRUE,"InternetSetCookie failed\n");
277   ret = InternetSetCookie("http://www.example.com/bar/",NULL,"O=P; secure; path=/bar");
278   ok(ret == TRUE,"InternetSetCookie failed\n");
279
280   len = 1024;
281   ret = InternetGetCookie("http://testing.example.com", NULL, buffer, &len);
282   ok(strstr(buffer,"A=B")!=NULL,"A=B missing\n");
283   ok(strstr(buffer,"C=D")!=NULL,"C=D missing\n");
284   ok(strstr(buffer,"E=F")!=NULL,"E=F missing\n");
285   ok(strstr(buffer,"G=H")==NULL,"G=H present\n");
286   ok(strstr(buffer,"I=J")!=NULL,"I=J missing\n");
287   ok(strstr(buffer,"K=L")==NULL,"K=L present\n");
288   ok(strstr(buffer,"M=N")==NULL,"M=N present\n");
289   ok(strstr(buffer,"O=P")==NULL,"O=P present\n");
290
291   len = 1024;
292   ret = InternetGetCookie("http://testing.example.com/foobar", NULL, buffer, &len);
293   ok(strstr(buffer,"A=B")!=NULL,"A=B missing\n");
294   ok(strstr(buffer,"C=D")!=NULL,"C=D missing\n");
295   ok(strstr(buffer,"E=F")!=NULL,"E=F missing\n");
296   ok(strstr(buffer,"G=H")==NULL,"G=H present\n");
297   ok(strstr(buffer,"I=J")!=NULL,"I=J missing\n");
298   ok(strstr(buffer,"K=L")==NULL,"K=L present\n");
299   ok(strstr(buffer,"M=N")==NULL,"M=N present\n");
300   ok(strstr(buffer,"O=P")==NULL,"O=P present\n");
301
302   len = 1024;
303   ret = InternetGetCookie("http://testing.example.com/foobar/", NULL, buffer, &len);
304   ok(strstr(buffer,"A=B")!=NULL,"A=B missing\n");
305   ok(strstr(buffer,"C=D")!=NULL,"C=D missing\n");
306   ok(strstr(buffer,"E=F")!=NULL,"E=F missing\n");
307   ok(strstr(buffer,"G=H")!=NULL,"G=H missing\n");
308   ok(strstr(buffer,"I=J")!=NULL,"I=J missing\n");
309   ok(strstr(buffer,"K=L")==NULL,"K=L present\n");
310   ok(strstr(buffer,"M=N")==NULL,"M=N present\n");
311   ok(strstr(buffer,"O=P")==NULL,"O=P present\n");
312
313   len = 1024;
314   ret = InternetGetCookie("http://testing.example.com/foo/bar", NULL, buffer, &len);
315   ok(strstr(buffer,"A=B")!=NULL,"A=B missing\n");
316   ok(strstr(buffer,"C=D")!=NULL,"C=D missing\n");
317   ok(strstr(buffer,"E=F")!=NULL,"E=F missing\n");
318   ok(strstr(buffer,"G=H")!=NULL,"G=H missing\n");
319   ok(strstr(buffer,"I=J")!=NULL,"I=J missing\n");
320   ok(strstr(buffer,"K=L")==NULL,"K=L present\n");
321   ok(strstr(buffer,"M=N")!=NULL,"M=N missing\n");
322   ok(strstr(buffer,"O=P")==NULL,"O=P present\n");
323
324   len = 1024;
325   ret = InternetGetCookie("http://testing.example.com/barfoo", NULL, buffer, &len);
326   ok(strstr(buffer,"A=B")!=NULL,"A=B missing\n");
327   ok(strstr(buffer,"C=D")!=NULL,"C=D missing\n");
328   ok(strstr(buffer,"E=F")!=NULL,"E=F missing\n");
329   ok(strstr(buffer,"G=H")==NULL,"G=H present\n");
330   ok(strstr(buffer,"I=J")!=NULL,"I=J missing\n");
331   ok(strstr(buffer,"K=L")==NULL,"K=L present\n");
332   ok(strstr(buffer,"M=N")==NULL,"M=N present\n");
333   ok(strstr(buffer,"O=P")==NULL,"O=P present\n");
334
335   len = 1024;
336   ret = InternetGetCookie("http://testing.example.com/barfoo/", NULL, buffer, &len);
337   ok(strstr(buffer,"A=B")!=NULL,"A=B missing\n");
338   ok(strstr(buffer,"C=D")!=NULL,"C=D missing\n");
339   ok(strstr(buffer,"E=F")!=NULL,"E=F missing\n");
340   ok(strstr(buffer,"G=H")==NULL,"G=H present\n");
341   ok(strstr(buffer,"I=J")!=NULL,"I=J missing\n");
342   ok(strstr(buffer,"K=L")==NULL,"K=L present\n");
343   ok(strstr(buffer,"M=N")==NULL,"M=N present\n");
344   ok(strstr(buffer,"O=P")==NULL,"O=P present\n");
345
346   len = 1024;
347   ret = InternetGetCookie("http://testing.example.com/bar/foo", NULL, buffer, &len);
348   ok(strstr(buffer,"A=B")!=NULL,"A=B missing\n");
349   ok(strstr(buffer,"C=D")!=NULL,"C=D missing\n");
350   ok(strstr(buffer,"E=F")!=NULL,"E=F missing\n");
351   ok(strstr(buffer,"G=H")==NULL,"G=H present\n");
352   ok(strstr(buffer,"I=J")!=NULL,"I=J missing\n");
353   ok(strstr(buffer,"K=L")!=NULL,"K=L missing\n");
354   ok(strstr(buffer,"M=N")==NULL,"M=N present\n");
355   ok(strstr(buffer,"O=P")==NULL,"O=P present\n");
356 }
357
358 static void test_null(void)
359 {
360   HINTERNET hi, hc;
361   static const WCHAR szServer[] = { 's','e','r','v','e','r',0 };
362   static const WCHAR szEmpty[] = { 0 };
363   static const WCHAR szUrl[] = { 'h','t','t','p',':','/','/','a','.','b','.','c',0 };
364   static const WCHAR szUrlEmpty[] = { 'h','t','t','p',':','/','/',0 };
365   static const WCHAR szExpect[] = { 's','e','r','v','e','r',';',' ','s','e','r','v','e','r',0 };
366   WCHAR buffer[0x20];
367   BOOL r;
368   DWORD sz;
369
370   SetLastError(0xdeadbeef);
371   hi = InternetOpenW(NULL, 0, NULL, NULL, 0);
372   if (hi == NULL && GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)
373   {
374     win_skip("Internet*W functions are not implemented\n");
375     return;
376   }
377   ok(hi != NULL, "open failed\n");
378
379   hc = InternetConnectW(hi, NULL, 0, NULL, NULL, 0, 0, 0);
380   ok(GetLastError() == ERROR_INVALID_PARAMETER, "wrong error\n");
381   ok(hc == NULL, "connect failed\n");
382
383   hc = InternetConnectW(hi, NULL, 0, NULL, NULL, INTERNET_SERVICE_HTTP, 0, 0);
384   ok(GetLastError() == ERROR_INVALID_PARAMETER, "wrong error\n");
385   ok(hc == NULL, "connect failed\n");
386
387   hc = InternetConnectW(hi, NULL, 0, NULL, NULL, INTERNET_SERVICE_FTP, 0, 0);
388   ok(GetLastError() == ERROR_INVALID_PARAMETER, "wrong error\n");
389   ok(hc == NULL, "connect failed\n");
390
391   hc = InternetConnectW(NULL, szServer, 0, NULL, NULL, INTERNET_SERVICE_FTP, 0, 0);
392   ok(GetLastError() == ERROR_INVALID_HANDLE, "wrong error\n");
393   ok(hc == NULL, "connect failed\n");
394
395   hc = InternetOpenUrlW(hi, NULL, NULL, 0, 0, 0);
396   ok(GetLastError() == ERROR_INVALID_PARAMETER ||
397      GetLastError() == ERROR_INTERNET_UNRECOGNIZED_SCHEME, "wrong error\n");
398   ok(hc == NULL, "connect failed\n");
399
400   hc = InternetOpenUrlW(hi, szServer, NULL, 0, 0, 0);
401   ok(GetLastError() == ERROR_INTERNET_UNRECOGNIZED_SCHEME, "wrong error\n");
402   ok(hc == NULL, "connect failed\n");
403
404   InternetCloseHandle(hi);
405
406   r = InternetSetCookieW(NULL, NULL, NULL);
407   ok(GetLastError() == ERROR_INVALID_PARAMETER, "wrong error\n");
408   ok(r == FALSE, "return wrong\n");
409
410   r = InternetSetCookieW(szServer, NULL, NULL);
411   ok(GetLastError() == ERROR_INVALID_PARAMETER, "wrong error\n");
412   ok(r == FALSE, "return wrong\n");
413
414   r = InternetSetCookieW(szUrl, szServer, NULL);
415   ok(GetLastError() == ERROR_INVALID_PARAMETER, "wrong error\n");
416   ok(r == FALSE, "return wrong\n");
417
418   r = InternetSetCookieW(szUrl, szServer, szServer);
419   ok(r == TRUE, "return wrong\n");
420
421   r = InternetSetCookieW(szUrl, NULL, szServer);
422   ok(r == TRUE, "return wrong\n");
423
424   r = InternetSetCookieW(szUrl, szServer, szEmpty);
425   ok(r == TRUE, "return wrong\n");
426
427   r = InternetSetCookieW(szUrlEmpty, szServer, szServer);
428   ok(r == FALSE, "return wrong\n");
429
430   r = InternetSetCookieW(szServer, NULL, szServer);
431   todo_wine {
432   ok(GetLastError() == ERROR_INTERNET_UNRECOGNIZED_SCHEME, "wrong error\n");
433   }
434   ok(r == FALSE, "return wrong\n");
435
436   sz = 0;
437   r = InternetGetCookieW(NULL, NULL, NULL, &sz);
438   ok(GetLastError() == ERROR_INVALID_PARAMETER || GetLastError() == ERROR_INTERNET_UNRECOGNIZED_SCHEME,
439      "wrong error %u\n", GetLastError());
440   ok( r == FALSE, "return wrong\n");
441
442   r = InternetGetCookieW(szServer, NULL, NULL, &sz);
443   todo_wine {
444   ok(GetLastError() == ERROR_INTERNET_UNRECOGNIZED_SCHEME, "wrong error\n");
445   }
446   ok( r == FALSE, "return wrong\n");
447
448   sz = 0;
449   r = InternetGetCookieW(szUrlEmpty, szServer, NULL, &sz);
450   ok( r == FALSE, "return wrong\n");
451
452   sz = 0;
453   r = InternetGetCookieW(szUrl, szServer, NULL, &sz);
454   ok( r == TRUE, "return wrong\n");
455
456   /* sz is 14 on XP SP2 and beyond, 30 on XP SP1 and before */
457   ok( sz == 14 || sz == 30, "sz wrong, got %u, expected 14 or 30\n", sz);
458
459   sz = 0x20;
460   memset(buffer, 0, sizeof buffer);
461   r = InternetGetCookieW(szUrl, szServer, buffer, &sz);
462   ok( r == TRUE, "return wrong\n");
463
464   /* sz == lstrlenW(buffer) only in XP SP1 */
465   ok( sz == 1 + lstrlenW(buffer) || sz == lstrlenW(buffer), "sz wrong %d\n", sz);
466
467   /* before XP SP2, buffer is "server; server" */
468   ok( !lstrcmpW(szExpect, buffer) || !lstrcmpW(szServer, buffer), "cookie data wrong\n");
469
470   sz = sizeof(buffer);
471   r = InternetQueryOptionA(NULL, INTERNET_OPTION_CONNECTED_STATE, buffer, &sz);
472   ok(r == TRUE, "ret %d\n", r);
473 }
474
475 static void test_version(void)
476 {
477     INTERNET_VERSION_INFO version;
478     DWORD size;
479     BOOL res;
480
481     size = sizeof(version);
482     res = InternetQueryOptionA(NULL, INTERNET_OPTION_VERSION, &version, &size);
483     ok(res, "Could not get version: %u\n", GetLastError());
484     ok(version.dwMajorVersion == 1, "dwMajorVersion=%d, expected 1\n", version.dwMajorVersion);
485     ok(version.dwMinorVersion == 2, "dwMinorVersion=%d, expected 2\n", version.dwMinorVersion);
486 }
487
488 static void InternetTimeFromSystemTimeA_test(void)
489 {
490     BOOL ret;
491     static const SYSTEMTIME time = { 2005, 1, 5, 7, 12, 6, 35, 0 };
492     char string[INTERNET_RFC1123_BUFSIZE];
493     static const char expect[] = "Fri, 07 Jan 2005 12:06:35 GMT";
494     DWORD error;
495
496     ret = pInternetTimeFromSystemTimeA( &time, INTERNET_RFC1123_FORMAT, string, sizeof(string) );
497     ok( ret, "InternetTimeFromSystemTimeA failed (%u)\n", GetLastError() );
498
499     ok( !memcmp( string, expect, sizeof(expect) ),
500         "InternetTimeFromSystemTimeA failed (%u)\n", GetLastError() );
501
502     /* test NULL time parameter */
503     SetLastError(0xdeadbeef);
504     ret = pInternetTimeFromSystemTimeA( NULL, INTERNET_RFC1123_FORMAT, string, sizeof(string) );
505     error = GetLastError();
506     ok( !ret, "InternetTimeFromSystemTimeA should have returned FALSE\n" );
507     ok( error == ERROR_INVALID_PARAMETER,
508         "InternetTimeFromSystemTimeA failed with ERROR_INVALID_PARAMETER instead of %u\n",
509         error );
510
511     /* test NULL string parameter */
512     SetLastError(0xdeadbeef);
513     ret = pInternetTimeFromSystemTimeA( &time, INTERNET_RFC1123_FORMAT, NULL, sizeof(string) );
514     error = GetLastError();
515     ok( !ret, "InternetTimeFromSystemTimeA should have returned FALSE\n" );
516     ok( error == ERROR_INVALID_PARAMETER,
517         "InternetTimeFromSystemTimeA failed with ERROR_INVALID_PARAMETER instead of %u\n",
518         error );
519
520     /* test invalid format parameter */
521     SetLastError(0xdeadbeef);
522     ret = pInternetTimeFromSystemTimeA( &time, INTERNET_RFC1123_FORMAT + 1, string, sizeof(string) );
523     error = GetLastError();
524     ok( !ret, "InternetTimeFromSystemTimeA should have returned FALSE\n" );
525     ok( error == ERROR_INVALID_PARAMETER,
526         "InternetTimeFromSystemTimeA failed with ERROR_INVALID_PARAMETER instead of %u\n",
527         error );
528
529     /* test too small buffer size */
530     SetLastError(0xdeadbeef);
531     ret = pInternetTimeFromSystemTimeA( &time, INTERNET_RFC1123_FORMAT, string, 0 );
532     error = GetLastError();
533     ok( !ret, "InternetTimeFromSystemTimeA should have returned FALSE\n" );
534     ok( error == ERROR_INSUFFICIENT_BUFFER,
535         "InternetTimeFromSystemTimeA failed with ERROR_INSUFFICIENT_BUFFER instead of %u\n",
536         error );
537 }
538
539 static void InternetTimeFromSystemTimeW_test(void)
540 {
541     BOOL ret;
542     static const SYSTEMTIME time = { 2005, 1, 5, 7, 12, 6, 35, 0 };
543     WCHAR string[INTERNET_RFC1123_BUFSIZE + 1];
544     static const WCHAR expect[] = { 'F','r','i',',',' ','0','7',' ','J','a','n',' ','2','0','0','5',' ',
545                                     '1','2',':','0','6',':','3','5',' ','G','M','T',0 };
546     DWORD error;
547
548     ret = pInternetTimeFromSystemTimeW( &time, INTERNET_RFC1123_FORMAT, string, sizeof(string) );
549     ok( ret, "InternetTimeFromSystemTimeW failed (%u)\n", GetLastError() );
550
551     ok( !memcmp( string, expect, sizeof(expect) ),
552         "InternetTimeFromSystemTimeW failed (%u)\n", GetLastError() );
553
554     /* test NULL time parameter */
555     SetLastError(0xdeadbeef);
556     ret = pInternetTimeFromSystemTimeW( NULL, INTERNET_RFC1123_FORMAT, string, sizeof(string) );
557     error = GetLastError();
558     ok( !ret, "InternetTimeFromSystemTimeW should have returned FALSE\n" );
559     ok( error == ERROR_INVALID_PARAMETER,
560         "InternetTimeFromSystemTimeW failed with ERROR_INVALID_PARAMETER instead of %u\n",
561         error );
562
563     /* test NULL string parameter */
564     SetLastError(0xdeadbeef);
565     ret = pInternetTimeFromSystemTimeW( &time, INTERNET_RFC1123_FORMAT, NULL, sizeof(string) );
566     error = GetLastError();
567     ok( !ret, "InternetTimeFromSystemTimeW should have returned FALSE\n" );
568     ok( error == ERROR_INVALID_PARAMETER,
569         "InternetTimeFromSystemTimeW failed with ERROR_INVALID_PARAMETER instead of %u\n",
570         error );
571
572     /* test invalid format parameter */
573     SetLastError(0xdeadbeef);
574     ret = pInternetTimeFromSystemTimeW( &time, INTERNET_RFC1123_FORMAT + 1, string, sizeof(string) );
575     error = GetLastError();
576     ok( !ret, "InternetTimeFromSystemTimeW should have returned FALSE\n" );
577     ok( error == ERROR_INVALID_PARAMETER,
578         "InternetTimeFromSystemTimeW failed with ERROR_INVALID_PARAMETER instead of %u\n",
579         error );
580
581     /* test too small buffer size */
582     SetLastError(0xdeadbeef);
583     ret = pInternetTimeFromSystemTimeW( &time, INTERNET_RFC1123_FORMAT, string, sizeof(string)/sizeof(string[0]) );
584     error = GetLastError();
585     ok( !ret, "InternetTimeFromSystemTimeW should have returned FALSE\n" );
586     ok( error == ERROR_INSUFFICIENT_BUFFER,
587         "InternetTimeFromSystemTimeW failed with ERROR_INSUFFICIENT_BUFFER instead of %u\n",
588         error );
589 }
590
591 static void InternetTimeToSystemTimeA_test(void)
592 {
593     BOOL ret;
594     SYSTEMTIME time;
595     static const SYSTEMTIME expect = { 2005, 1, 5, 7, 12, 6, 35, 0 };
596     static const char string[] = "Fri, 07 Jan 2005 12:06:35 GMT";
597     static const char string2[] = " fri 7 jan 2005 12 06 35";
598
599     ret = pInternetTimeToSystemTimeA( string, &time, 0 );
600     ok( ret, "InternetTimeToSystemTimeA failed (%u)\n", GetLastError() );
601     ok( !memcmp( &time, &expect, sizeof(expect) ),
602         "InternetTimeToSystemTimeA failed (%u)\n", GetLastError() );
603
604     ret = pInternetTimeToSystemTimeA( string2, &time, 0 );
605     ok( ret, "InternetTimeToSystemTimeA failed (%u)\n", GetLastError() );
606     ok( !memcmp( &time, &expect, sizeof(expect) ),
607         "InternetTimeToSystemTimeA failed (%u)\n", GetLastError() );
608 }
609
610 static void InternetTimeToSystemTimeW_test(void)
611 {
612     BOOL ret;
613     SYSTEMTIME time;
614     static const SYSTEMTIME expect = { 2005, 1, 5, 7, 12, 6, 35, 0 };
615     static const WCHAR string[] = { 'F','r','i',',',' ','0','7',' ','J','a','n',' ','2','0','0','5',' ',
616                                     '1','2',':','0','6',':','3','5',' ','G','M','T',0 };
617     static const WCHAR string2[] = { ' ','f','r','i',' ','7',' ','j','a','n',' ','2','0','0','5',' ',
618                                      '1','2',' ','0','6',' ','3','5',0 };
619     static const WCHAR string3[] = { 'F','r',0 };
620
621     ret = pInternetTimeToSystemTimeW( NULL, NULL, 0 );
622     ok( !ret, "InternetTimeToSystemTimeW succeeded (%u)\n", GetLastError() );
623
624     ret = pInternetTimeToSystemTimeW( NULL, &time, 0 );
625     ok( !ret, "InternetTimeToSystemTimeW succeeded (%u)\n", GetLastError() );
626
627     ret = pInternetTimeToSystemTimeW( string, NULL, 0 );
628     ok( !ret, "InternetTimeToSystemTimeW succeeded (%u)\n", GetLastError() );
629
630     ret = pInternetTimeToSystemTimeW( string, &time, 0 );
631     ok( ret, "InternetTimeToSystemTimeW failed (%u)\n", GetLastError() );
632
633     ret = pInternetTimeToSystemTimeW( string, &time, 0 );
634     ok( ret, "InternetTimeToSystemTimeW failed (%u)\n", GetLastError() );
635     ok( !memcmp( &time, &expect, sizeof(expect) ),
636         "InternetTimeToSystemTimeW failed (%u)\n", GetLastError() );
637
638     ret = pInternetTimeToSystemTimeW( string2, &time, 0 );
639     ok( ret, "InternetTimeToSystemTimeW failed (%u)\n", GetLastError() );
640     ok( !memcmp( &time, &expect, sizeof(expect) ),
641         "InternetTimeToSystemTimeW failed (%u)\n", GetLastError() );
642
643     ret = pInternetTimeToSystemTimeW( string3, &time, 0 );
644     ok( ret, "InternetTimeToSystemTimeW failed (%u)\n", GetLastError() );
645 }
646
647 static void test_IsDomainLegalCookieDomainW(void)
648 {
649     BOOL ret;
650     DWORD error;
651     static const WCHAR empty[]          = {0};
652     static const WCHAR dot[]            = {'.',0};
653     static const WCHAR uk[]             = {'u','k',0};
654     static const WCHAR com[]            = {'c','o','m',0};
655     static const WCHAR dot_com[]        = {'.','c','o','m',0};
656     static const WCHAR gmail_com[]      = {'g','m','a','i','l','.','c','o','m',0};
657     static const WCHAR dot_gmail_com[]  = {'.','g','m','a','i','l','.','c','o','m',0};
658     static const WCHAR mail_gmail_com[] = {'m','a','i','l','.','g','m','a','i','l','.','c','o','m',0};
659     static const WCHAR gmail_co_uk[]    = {'g','m','a','i','l','.','c','o','.','u','k',0};
660     static const WCHAR co_uk[]          = {'c','o','.','u','k',0};
661     static const WCHAR dot_co_uk[]      = {'.','c','o','.','u','k',0};
662
663     SetLastError(0xdeadbeef);
664     ret = pIsDomainLegalCookieDomainW(NULL, NULL);
665     error = GetLastError();
666     if (!ret && error == ERROR_CALL_NOT_IMPLEMENTED)
667     {
668         win_skip("IsDomainLegalCookieDomainW is not implemented\n");
669         return;
670     }
671     ok(!ret ||
672         broken(ret), /* IE6 */
673         "IsDomainLegalCookieDomainW succeeded\n");
674     ok(error == ERROR_INVALID_PARAMETER, "got %u expected ERROR_INVALID_PARAMETER\n", error);
675
676     SetLastError(0xdeadbeef);
677     ret = pIsDomainLegalCookieDomainW(com, NULL);
678     error = GetLastError();
679     ok(!ret, "IsDomainLegalCookieDomainW succeeded\n");
680     ok(error == ERROR_INVALID_PARAMETER, "got %u expected ERROR_INVALID_PARAMETER\n", error);
681
682     SetLastError(0xdeadbeef);
683     ret = pIsDomainLegalCookieDomainW(NULL, gmail_com);
684     error = GetLastError();
685     ok(!ret, "IsDomainLegalCookieDomainW succeeded\n");
686     ok(error == ERROR_INVALID_PARAMETER, "got %u expected ERROR_INVALID_PARAMETER\n", error);
687
688     SetLastError(0xdeadbeef);
689     ret = pIsDomainLegalCookieDomainW(empty, gmail_com);
690     error = GetLastError();
691     ok(!ret, "IsDomainLegalCookieDomainW succeeded\n");
692     ok(error == ERROR_INVALID_NAME ||
693         broken(error == ERROR_INVALID_PARAMETER), /* IE6 */
694         "got %u expected ERROR_INVALID_NAME\n", error);
695
696     SetLastError(0xdeadbeef);
697     ret = pIsDomainLegalCookieDomainW(com, empty);
698     error = GetLastError();
699     ok(!ret, "IsDomainLegalCookieDomainW succeeded\n");
700     ok(error == ERROR_INVALID_NAME ||
701         broken(error == ERROR_INVALID_PARAMETER), /* IE6 */
702         "got %u expected ERROR_INVALID_NAME\n", error);
703
704     SetLastError(0xdeadbeef);
705     ret = pIsDomainLegalCookieDomainW(gmail_com, dot);
706     error = GetLastError();
707     ok(!ret, "IsDomainLegalCookieDomainW succeeded\n");
708     ok(error == ERROR_INVALID_NAME ||
709         broken(error == 0xdeadbeef), /* IE6 */
710         "got %u expected ERROR_INVALID_NAME\n", error);
711
712     SetLastError(0xdeadbeef);
713     ret = pIsDomainLegalCookieDomainW(dot, gmail_com);
714     error = GetLastError();
715     ok(!ret, "IsDomainLegalCookieDomainW succeeded\n");
716     ok(error == ERROR_INVALID_NAME ||
717         broken(error == 0xdeadbeef), /* IE6 */
718         "got %u expected ERROR_INVALID_NAME\n", error);
719
720     SetLastError(0xdeadbeef);
721     ret = pIsDomainLegalCookieDomainW(com, com);
722     error = GetLastError();
723     ok(!ret, "IsDomainLegalCookieDomainW succeeded\n");
724     ok(error == 0xdeadbeef, "got %u expected 0xdeadbeef\n", error);
725
726     SetLastError(0xdeadbeef);
727     ret = pIsDomainLegalCookieDomainW(com, dot_com);
728     error = GetLastError();
729     ok(!ret, "IsDomainLegalCookieDomainW succeeded\n");
730     ok(error == ERROR_INVALID_NAME ||
731         broken(error == 0xdeadbeef), /* IE6 */
732         "got %u expected ERROR_INVALID_NAME\n", error);
733
734     SetLastError(0xdeadbeef);
735     ret = pIsDomainLegalCookieDomainW(dot_com, com);
736     error = GetLastError();
737     ok(!ret, "IsDomainLegalCookieDomainW succeeded\n");
738     ok(error == ERROR_INVALID_NAME ||
739         broken(error == 0xdeadbeef), /* IE6 */
740         "got %u expected ERROR_INVALID_NAME\n", error);
741
742     SetLastError(0xdeadbeef);
743     ret = pIsDomainLegalCookieDomainW(com, gmail_com);
744     error = GetLastError();
745     ok(!ret, "IsDomainLegalCookieDomainW succeeded\n");
746     ok(error == ERROR_SXS_KEY_NOT_FOUND ||
747         error == ERROR_SUCCESS || /* IE8 on W2K3 */
748         error == 0xdeadbeef, /* up to IE7 */
749         "unexpected error: %u\n", error);
750
751     ret = pIsDomainLegalCookieDomainW(gmail_com, gmail_com);
752     ok(ret, "IsDomainLegalCookieDomainW failed\n");
753
754     SetLastError(0xdeadbeef);
755     ret = pIsDomainLegalCookieDomainW(gmail_co_uk, co_uk);
756     error = GetLastError();
757     ok(!ret, "IsDomainLegalCookieDomainW succeeded\n");
758     ok(error == ERROR_SXS_KEY_NOT_FOUND || /* IE8 on XP */
759         error == ERROR_FILE_NOT_FOUND ||   /* IE8 on Vista */
760         error == ERROR_SUCCESS || /* IE8 on W2K3 */
761         error == 0xdeadbeef, /* up to IE7 */
762         "unexpected error: %u\n", error);
763
764     ret = pIsDomainLegalCookieDomainW(uk, co_uk);
765     ok(!ret, "IsDomainLegalCookieDomainW succeeded\n");
766
767     ret = pIsDomainLegalCookieDomainW(gmail_co_uk, dot_co_uk);
768     ok(!ret, "IsDomainLegalCookieDomainW succeeded\n");
769
770     ret = pIsDomainLegalCookieDomainW(gmail_co_uk, gmail_co_uk);
771     ok(ret, "IsDomainLegalCookieDomainW failed\n");
772
773     ret = pIsDomainLegalCookieDomainW(gmail_com, com);
774     ok(!ret, "IsDomainLegalCookieDomainW succeeded\n");
775
776     SetLastError(0xdeadbeef);
777     ret = pIsDomainLegalCookieDomainW(dot_gmail_com, mail_gmail_com);
778     error = GetLastError();
779     ok(!ret, "IsDomainLegalCookieDomainW succeeded\n");
780     ok(error == ERROR_INVALID_NAME ||
781         broken(error == 0xdeadbeef), /* IE6 */
782         "got %u expected ERROR_INVALID_NAME\n", error);
783
784     ret = pIsDomainLegalCookieDomainW(gmail_com, mail_gmail_com);
785     ok(ret, "IsDomainLegalCookieDomainW failed\n");
786
787     ret = pIsDomainLegalCookieDomainW(mail_gmail_com, gmail_com);
788     ok(!ret, "IsDomainLegalCookieDomainW succeeded\n");
789
790     ret = pIsDomainLegalCookieDomainW(mail_gmail_com, com);
791     ok(!ret, "IsDomainLegalCookieDomainW succeeded\n");
792
793     ret = pIsDomainLegalCookieDomainW(dot_gmail_com, mail_gmail_com);
794     ok(!ret, "IsDomainLegalCookieDomainW succeeded\n");
795
796     ret = pIsDomainLegalCookieDomainW(mail_gmail_com, dot_gmail_com);
797     ok(!ret, "IsDomainLegalCookieDomainW succeeded\n");
798 }
799
800 static void test_PrivacyGetSetZonePreferenceW(void)
801 {
802     DWORD ret, zone, type, template, old_template;
803
804     zone = 3;
805     type = 0;
806     ret = pPrivacyGetZonePreferenceW(zone, type, NULL, NULL, NULL);
807     ok(ret == 0, "expected ret == 0, got %u\n", ret);
808
809     old_template = 0;
810     ret = pPrivacyGetZonePreferenceW(zone, type, &old_template, NULL, NULL);
811     ok(ret == 0, "expected ret == 0, got %u\n", ret);
812
813     template = 5;
814     ret = pPrivacySetZonePreferenceW(zone, type, template, NULL);
815     ok(ret == 0, "expected ret == 0, got %u\n", ret);
816
817     template = 0;
818     ret = pPrivacyGetZonePreferenceW(zone, type, &template, NULL, NULL);
819     ok(ret == 0, "expected ret == 0, got %u\n", ret);
820     ok(template == 5, "expected template == 5, got %u\n", template);
821
822     template = 5;
823     ret = pPrivacySetZonePreferenceW(zone, type, old_template, NULL);
824     ok(ret == 0, "expected ret == 0, got %u\n", ret);
825 }
826
827 /* ############################### */
828
829 START_TEST(internet)
830 {
831     HMODULE hdll;
832     hdll = GetModuleHandleA("wininet.dll");
833     pCreateUrlCacheContainerA = (void*)GetProcAddress(hdll, "CreateUrlCacheContainerA");
834     pCreateUrlCacheContainerW = (void*)GetProcAddress(hdll, "CreateUrlCacheContainerW");
835     pInternetTimeFromSystemTimeA = (void*)GetProcAddress(hdll, "InternetTimeFromSystemTimeA");
836     pInternetTimeFromSystemTimeW = (void*)GetProcAddress(hdll, "InternetTimeFromSystemTimeW");
837     pInternetTimeToSystemTimeA = (void*)GetProcAddress(hdll, "InternetTimeToSystemTimeA");
838     pInternetTimeToSystemTimeW = (void*)GetProcAddress(hdll, "InternetTimeToSystemTimeW");
839     pIsDomainLegalCookieDomainW = (void*)GetProcAddress(hdll, (LPCSTR)117);
840     pPrivacyGetZonePreferenceW = (void*)GetProcAddress(hdll, "PrivacyGetZonePreferenceW");
841     pPrivacySetZonePreferenceW = (void*)GetProcAddress(hdll, "PrivacySetZonePreferenceW");
842
843     test_InternetCanonicalizeUrlA();
844     test_InternetQueryOptionA();
845     test_get_cookie();
846     test_complicated_cookie();
847     test_version();
848     test_null();
849
850     if (!pInternetTimeFromSystemTimeA)
851         win_skip("skipping the InternetTime tests\n");
852     else
853     {
854         InternetTimeFromSystemTimeA_test();
855         InternetTimeFromSystemTimeW_test();
856         InternetTimeToSystemTimeA_test();
857         InternetTimeToSystemTimeW_test();
858     }
859     if (pIsDomainLegalCookieDomainW &&
860         ((void*)pIsDomainLegalCookieDomainW == (void*)pCreateUrlCacheContainerA ||
861          (void*)pIsDomainLegalCookieDomainW == (void*)pCreateUrlCacheContainerW))
862         win_skip("IsDomainLegalCookieDomainW is not available on systems with IE5\n");
863     else if (!pIsDomainLegalCookieDomainW)
864         win_skip("IsDomainLegalCookieDomainW (or ordinal 117) is not available\n");
865     else
866         test_IsDomainLegalCookieDomainW();
867
868     if (pPrivacyGetZonePreferenceW && pPrivacySetZonePreferenceW)
869         test_PrivacyGetSetZonePreferenceW();
870     else
871         win_skip("Privacy[SG]etZonePreferenceW are not available\n");
872 }