push 87b6981010d7405c33b14cddcceec21b47729eba
[wine/hacks.git] / dlls / wininet / tests / internet.c
blobfa28b0cbbb42696dcb3c1c373a60ec6e3cc58855
1 /*
2 * Wininet - internet tests
4 * Copyright 2005 Vijay Kiran Kamuju
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
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 #include "winreg.h"
29 #include "wine/test.h"
31 static BOOL (WINAPI *pCreateUrlCacheContainerA)(DWORD, DWORD, DWORD, DWORD,
32 DWORD, DWORD, DWORD, DWORD);
33 static BOOL (WINAPI *pCreateUrlCacheContainerW)(DWORD, DWORD, DWORD, DWORD,
34 DWORD, DWORD, DWORD, DWORD);
35 static BOOL (WINAPI *pInternetTimeFromSystemTimeA)(CONST SYSTEMTIME *,DWORD ,LPSTR ,DWORD);
36 static BOOL (WINAPI *pInternetTimeFromSystemTimeW)(CONST SYSTEMTIME *,DWORD ,LPWSTR ,DWORD);
37 static BOOL (WINAPI *pInternetTimeToSystemTimeA)(LPCSTR ,SYSTEMTIME *,DWORD);
38 static BOOL (WINAPI *pInternetTimeToSystemTimeW)(LPCWSTR ,SYSTEMTIME *,DWORD);
39 static BOOL (WINAPI *pIsDomainLegalCookieDomainW)(LPCWSTR, LPCWSTR);
40 static DWORD (WINAPI *pPrivacyGetZonePreferenceW)(DWORD, DWORD, LPDWORD, LPWSTR, LPDWORD);
41 static DWORD (WINAPI *pPrivacySetZonePreferenceW)(DWORD, DWORD, DWORD, LPCWSTR);
43 /* Win9x and WinMe don't have lstrcmpW */
44 static int strcmp_ww(const WCHAR *str1, const WCHAR *str2)
46 DWORD len1 = lstrlenW(str1);
47 DWORD len2 = lstrlenW(str2);
49 if (len1 != len2) return 1;
50 return memcmp(str1, str2, len1 * sizeof(WCHAR));
53 /* ############################### */
55 static void test_InternetCanonicalizeUrlA(void)
57 CHAR buffer[256];
58 LPCSTR url;
59 DWORD urllen;
60 DWORD dwSize;
61 DWORD res;
63 /* Acrobat Updater 5 calls this for Adobe Reader 8.1 */
64 url = "http://swupmf.adobe.com/manifest/50/win/AdobeUpdater.upd";
65 urllen = lstrlenA(url);
67 memset(buffer, '#', sizeof(buffer)-1);
68 buffer[sizeof(buffer)-1] = '\0';
69 dwSize = 1; /* Acrobat Updater use this size */
70 SetLastError(0xdeadbeef);
71 res = InternetCanonicalizeUrlA(url, buffer, &dwSize, 0);
72 ok( !res && (GetLastError() == ERROR_INSUFFICIENT_BUFFER) && (dwSize == (urllen+1)),
73 "got %u and %u with size %u for '%s' (%d)\n",
74 res, GetLastError(), dwSize, buffer, lstrlenA(buffer));
77 /* buffer has no space for the terminating '\0' */
78 memset(buffer, '#', sizeof(buffer)-1);
79 buffer[sizeof(buffer)-1] = '\0';
80 dwSize = urllen;
81 SetLastError(0xdeadbeef);
82 res = InternetCanonicalizeUrlA(url, buffer, &dwSize, 0);
83 /* dwSize is nr. of needed bytes with the terminating '\0' */
84 ok( !res && (GetLastError() == ERROR_INSUFFICIENT_BUFFER) && (dwSize == (urllen+1)),
85 "got %u and %u with size %u for '%s' (%d)\n",
86 res, GetLastError(), dwSize, buffer, lstrlenA(buffer));
88 /* buffer has the required size */
89 memset(buffer, '#', sizeof(buffer)-1);
90 buffer[sizeof(buffer)-1] = '\0';
91 dwSize = urllen+1;
92 SetLastError(0xdeadbeef);
93 res = InternetCanonicalizeUrlA(url, buffer, &dwSize, 0);
94 /* dwSize is nr. of copied bytes without the terminating '\0' */
95 ok( res && (dwSize == urllen) && (lstrcmpA(url, buffer) == 0),
96 "got %u and %u with size %u for '%s' (%d)\n",
97 res, GetLastError(), dwSize, buffer, lstrlenA(buffer));
99 memset(buffer, '#', sizeof(buffer)-1);
100 buffer[sizeof(buffer)-1] = '\0';
101 dwSize = sizeof(buffer);
102 SetLastError(0xdeadbeef);
103 res = InternetCanonicalizeUrlA("file:///C:/Program%20Files/Atmel/AVR%20Tools/STK500/STK500.xml", buffer, &dwSize, ICU_DECODE | ICU_NO_ENCODE);
104 ok(res, "InternetCanonicalizeUrlA failed %u\n", GetLastError());
105 ok(dwSize == lstrlenA(buffer), "got %d expected %d\n", dwSize, lstrlenA(buffer));
106 todo_wine ok(!lstrcmpA("file://C:\\Program Files\\Atmel\\AVR Tools\\STK500\\STK500.xml", buffer),
107 "got %s expected 'file://C:\\Program Files\\Atmel\\AVR Tools\\STK500\\STK500.xml'\n", buffer);
109 /* buffer is larger as the required size */
110 memset(buffer, '#', sizeof(buffer)-1);
111 buffer[sizeof(buffer)-1] = '\0';
112 dwSize = urllen+2;
113 SetLastError(0xdeadbeef);
114 res = InternetCanonicalizeUrlA(url, buffer, &dwSize, 0);
115 /* dwSize is nr. of copied bytes without the terminating '\0' */
116 ok( res && (dwSize == urllen) && (lstrcmpA(url, buffer) == 0),
117 "got %u and %u with size %u for '%s' (%d)\n",
118 res, GetLastError(), dwSize, buffer, lstrlenA(buffer));
121 /* check NULL pointers */
122 memset(buffer, '#', urllen + 4);
123 buffer[urllen + 4] = '\0';
124 dwSize = urllen+1;
125 SetLastError(0xdeadbeef);
126 res = InternetCanonicalizeUrlA(NULL, buffer, &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));
131 memset(buffer, '#', urllen + 4);
132 buffer[urllen + 4] = '\0';
133 dwSize = urllen+1;
134 SetLastError(0xdeadbeef);
135 res = InternetCanonicalizeUrlA(url, NULL, &dwSize, 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));
140 memset(buffer, '#', urllen + 4);
141 buffer[urllen + 4] = '\0';
142 dwSize = urllen+1;
143 SetLastError(0xdeadbeef);
144 res = InternetCanonicalizeUrlA(url, buffer, NULL, 0);
145 ok( !res && (GetLastError() == ERROR_INVALID_PARAMETER),
146 "got %u and %u with size %u for '%s' (%d)\n",
147 res, GetLastError(), dwSize, buffer, lstrlenA(buffer));
149 /* test with trailing space */
150 dwSize = 256;
151 res = InternetCanonicalizeUrlA("http://www.winehq.org/index.php?x= ", buffer, &dwSize, ICU_BROWSER_MODE);
152 ok(res == 1, "InternetCanonicalizeUrlA failed\n");
153 ok(!strcmp(buffer, "http://www.winehq.org/index.php?x="), "Trailing space should have been stripped even in ICU_BROWSER_MODE (%s)\n", buffer);
155 res = InternetSetOptionA(NULL, 0xdeadbeef, buffer, sizeof(buffer));
156 ok(!res, "InternetSetOptionA succeeded\n");
157 ok(GetLastError() == ERROR_INTERNET_INVALID_OPTION,
158 "InternetSetOptionA failed %u, expected ERROR_INTERNET_INVALID_OPTION\n", GetLastError());
161 /* ############################### */
163 static void test_InternetQueryOptionA(void)
165 HINTERNET hinet,hurl;
166 DWORD len;
167 DWORD err;
168 static const char useragent[] = {"Wininet Test"};
169 char *buffer;
170 int retval;
172 hinet = InternetOpenA(useragent,INTERNET_OPEN_TYPE_DIRECT,NULL,NULL, 0);
173 ok((hinet != 0x0),"InternetOpen Failed\n");
175 SetLastError(0xdeadbeef);
176 retval=InternetQueryOptionA(NULL,INTERNET_OPTION_USER_AGENT,NULL,&len);
177 err=GetLastError();
178 ok(retval == 0,"Got wrong return value %d\n",retval);
179 ok(err == ERROR_INTERNET_INCORRECT_HANDLE_TYPE, "Got wrong error code%d\n",err);
181 SetLastError(0xdeadbeef);
182 len=strlen(useragent)+1;
183 retval=InternetQueryOptionA(hinet,INTERNET_OPTION_USER_AGENT,NULL,&len);
184 err=GetLastError();
185 ok(len == strlen(useragent)+1,"Got wrong user agent length %d instead of %d\n",len,lstrlenA(useragent));
186 ok(retval == 0,"Got wrong return value %d\n",retval);
187 ok(err == ERROR_INSUFFICIENT_BUFFER, "Got wrong error code %d\n",err);
189 SetLastError(0xdeadbeef);
190 len=strlen(useragent)+1;
191 buffer=HeapAlloc(GetProcessHeap(),0,len);
192 retval=InternetQueryOptionA(hinet,INTERNET_OPTION_USER_AGENT,buffer,&len);
193 err=GetLastError();
194 ok(retval == 1,"Got wrong return value %d\n",retval);
195 if (retval)
197 ok(!strcmp(useragent,buffer),"Got wrong user agent string %s instead of %s\n",buffer,useragent);
198 ok(len == strlen(useragent),"Got wrong user agent length %d instead of %d\n",len,lstrlenA(useragent));
200 ok(err == 0xdeadbeef, "Got wrong error code %d\n",err);
201 HeapFree(GetProcessHeap(),0,buffer);
203 SetLastError(0xdeadbeef);
204 len=0;
205 buffer=HeapAlloc(GetProcessHeap(),0,100);
206 retval=InternetQueryOptionA(hinet,INTERNET_OPTION_USER_AGENT,buffer,&len);
207 err=GetLastError();
208 ok(len == strlen(useragent) + 1,"Got wrong user agent length %d instead of %d\n", len, lstrlenA(useragent) + 1);
209 ok(!retval, "Got wrong return value %d\n", retval);
210 ok(err == ERROR_INSUFFICIENT_BUFFER, "Got wrong error code %d\n", err);
211 HeapFree(GetProcessHeap(),0,buffer);
213 hurl = InternetConnectA(hinet,"www.winehq.org",INTERNET_DEFAULT_HTTP_PORT,NULL,NULL,INTERNET_SERVICE_HTTP,0,0);
215 SetLastError(0xdeadbeef);
216 len=0;
217 retval = InternetQueryOptionA(hurl,INTERNET_OPTION_USER_AGENT,NULL,&len);
218 err=GetLastError();
219 ok(len == 0,"Got wrong user agent length %d instead of 0\n",len);
220 ok(retval == 0,"Got wrong return value %d\n",retval);
221 ok(err == ERROR_INTERNET_INCORRECT_HANDLE_TYPE, "Got wrong error code %d\n",err);
223 InternetCloseHandle(hurl);
224 InternetCloseHandle(hinet);
226 hinet = InternetOpenA("",INTERNET_OPEN_TYPE_DIRECT,NULL,NULL, 0);
227 ok((hinet != 0x0),"InternetOpen Failed\n");
229 SetLastError(0xdeadbeef);
230 len=0;
231 retval=InternetQueryOptionA(hinet,INTERNET_OPTION_USER_AGENT,NULL,&len);
232 err=GetLastError();
233 ok(len == 1,"Got wrong user agent length %d instead of %d\n",len,1);
234 ok(retval == 0,"Got wrong return value %d\n",retval);
235 ok(err == ERROR_INSUFFICIENT_BUFFER, "Got wrong error code%d\n",err);
237 InternetCloseHandle(hinet);
239 hinet = InternetOpenA(NULL,INTERNET_OPEN_TYPE_DIRECT,NULL,NULL, 0);
240 ok((hinet != 0x0),"InternetOpen Failed\n");
241 SetLastError(0xdeadbeef);
242 len=0;
243 retval=InternetQueryOptionA(hinet,INTERNET_OPTION_USER_AGENT,NULL,&len);
244 err=GetLastError();
245 ok(len == 1,"Got wrong user agent length %d instead of %d\n",len,1);
246 ok(retval == 0,"Got wrong return value %d\n",retval);
247 ok(err == ERROR_INSUFFICIENT_BUFFER, "Got wrong error code%d\n",err);
249 InternetCloseHandle(hinet);
252 static void test_get_cookie(void)
254 DWORD len;
255 BOOL ret;
257 SetLastError(0xdeadbeef);
258 ret = InternetGetCookie("http://www.example.com", NULL, NULL, &len);
259 ok(!ret && GetLastError() == ERROR_NO_MORE_ITEMS,
260 "InternetGetCookie should have failed with %s and error %d\n",
261 ret ? "TRUE" : "FALSE", GetLastError());
265 static void test_complicated_cookie(void)
267 DWORD len;
268 BOOL ret;
270 CHAR buffer[1024];
272 ret = InternetSetCookie("http://www.example.com/bar",NULL,"A=B; domain=.example.com");
273 ok(ret == TRUE,"InternetSetCookie failed\n");
274 ret = InternetSetCookie("http://www.example.com/bar",NULL,"C=D; domain=.example.com; path=/");
275 ok(ret == TRUE,"InternetSetCookie failed\n");
277 /* Technically illegal! domain should require 2 dots, but native wininet accepts it */
278 ret = InternetSetCookie("http://www.example.com",NULL,"E=F; domain=example.com");
279 ok(ret == TRUE,"InternetSetCookie failed\n");
280 ret = InternetSetCookie("http://www.example.com",NULL,"G=H; domain=.example.com; path=/foo");
281 ok(ret == TRUE,"InternetSetCookie failed\n");
282 ret = InternetSetCookie("http://www.example.com/bar.html",NULL,"I=J; domain=.example.com");
283 ok(ret == TRUE,"InternetSetCookie failed\n");
284 ret = InternetSetCookie("http://www.example.com/bar/",NULL,"K=L; domain=.example.com");
285 ok(ret == TRUE,"InternetSetCookie failed\n");
286 ret = InternetSetCookie("http://www.example.com/bar/",NULL,"M=N; domain=.example.com; path=/foo/");
287 ok(ret == TRUE,"InternetSetCookie failed\n");
288 ret = InternetSetCookie("http://www.example.com/bar/",NULL,"O=P; secure; path=/bar");
289 ok(ret == TRUE,"InternetSetCookie failed\n");
291 len = 1024;
292 ret = InternetGetCookie("http://testing.example.com", 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");
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 present\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");
313 len = 1024;
314 ret = InternetGetCookie("http://testing.example.com/foobar/", 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 present\n");
322 ok(strstr(buffer,"O=P")==NULL,"O=P present\n");
324 len = 1024;
325 ret = InternetGetCookie("http://testing.example.com/foo/bar", 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 missing\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 missing\n");
333 ok(strstr(buffer,"O=P")==NULL,"O=P present\n");
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");
346 len = 1024;
347 ret = InternetGetCookie("http://testing.example.com/barfoo/", 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 present\n");
354 ok(strstr(buffer,"M=N")==NULL,"M=N present\n");
355 ok(strstr(buffer,"O=P")==NULL,"O=P present\n");
357 len = 1024;
358 ret = InternetGetCookie("http://testing.example.com/bar/foo", NULL, buffer, &len);
359 ok(strstr(buffer,"A=B")!=NULL,"A=B missing\n");
360 ok(strstr(buffer,"C=D")!=NULL,"C=D missing\n");
361 ok(strstr(buffer,"E=F")!=NULL,"E=F missing\n");
362 ok(strstr(buffer,"G=H")==NULL,"G=H present\n");
363 ok(strstr(buffer,"I=J")!=NULL,"I=J missing\n");
364 ok(strstr(buffer,"K=L")!=NULL,"K=L missing\n");
365 ok(strstr(buffer,"M=N")==NULL,"M=N present\n");
366 ok(strstr(buffer,"O=P")==NULL,"O=P present\n");
369 static void test_null(void)
371 HINTERNET hi, hc;
372 static const WCHAR szServer[] = { 's','e','r','v','e','r',0 };
373 static const WCHAR szEmpty[] = { 0 };
374 static const WCHAR szUrl[] = { 'h','t','t','p',':','/','/','a','.','b','.','c',0 };
375 static const WCHAR szUrlEmpty[] = { 'h','t','t','p',':','/','/',0 };
376 static const WCHAR szExpect[] = { 's','e','r','v','e','r',';',' ','s','e','r','v','e','r',0 };
377 WCHAR buffer[0x20];
378 BOOL r;
379 DWORD sz;
381 SetLastError(0xdeadbeef);
382 hi = InternetOpenW(NULL, 0, NULL, NULL, 0);
383 if (hi == NULL && GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)
385 win_skip("Internet*W functions are not implemented\n");
386 return;
388 ok(hi != NULL, "open failed\n");
390 hc = InternetConnectW(hi, NULL, 0, NULL, NULL, 0, 0, 0);
391 ok(GetLastError() == ERROR_INVALID_PARAMETER, "wrong error\n");
392 ok(hc == NULL, "connect failed\n");
394 hc = InternetConnectW(hi, NULL, 0, NULL, NULL, INTERNET_SERVICE_HTTP, 0, 0);
395 ok(GetLastError() == ERROR_INVALID_PARAMETER, "wrong error\n");
396 ok(hc == NULL, "connect failed\n");
398 hc = InternetConnectW(hi, NULL, 0, NULL, NULL, INTERNET_SERVICE_FTP, 0, 0);
399 ok(GetLastError() == ERROR_INVALID_PARAMETER, "wrong error\n");
400 ok(hc == NULL, "connect failed\n");
402 hc = InternetConnectW(NULL, szServer, 0, NULL, NULL, INTERNET_SERVICE_FTP, 0, 0);
403 ok(GetLastError() == ERROR_INVALID_HANDLE, "wrong error\n");
404 ok(hc == NULL, "connect failed\n");
406 hc = InternetOpenUrlW(hi, NULL, NULL, 0, 0, 0);
407 ok(GetLastError() == ERROR_INVALID_PARAMETER ||
408 GetLastError() == ERROR_INTERNET_UNRECOGNIZED_SCHEME, "wrong error\n");
409 ok(hc == NULL, "connect failed\n");
411 hc = InternetOpenUrlW(hi, szServer, NULL, 0, 0, 0);
412 ok(GetLastError() == ERROR_INTERNET_UNRECOGNIZED_SCHEME, "wrong error\n");
413 ok(hc == NULL, "connect failed\n");
415 InternetCloseHandle(hi);
417 r = InternetSetCookieW(NULL, NULL, NULL);
418 ok(GetLastError() == ERROR_INVALID_PARAMETER, "wrong error\n");
419 ok(r == FALSE, "return wrong\n");
421 r = InternetSetCookieW(szServer, NULL, NULL);
422 ok(GetLastError() == ERROR_INVALID_PARAMETER, "wrong error\n");
423 ok(r == FALSE, "return wrong\n");
425 r = InternetSetCookieW(szUrl, szServer, NULL);
426 ok(GetLastError() == ERROR_INVALID_PARAMETER, "wrong error\n");
427 ok(r == FALSE, "return wrong\n");
429 r = InternetSetCookieW(szUrl, szServer, szServer);
430 ok(r == TRUE, "return wrong\n");
432 r = InternetSetCookieW(szUrl, NULL, szServer);
433 ok(r == TRUE, "return wrong\n");
435 r = InternetSetCookieW(szUrl, szServer, szEmpty);
436 ok(r == TRUE, "return wrong\n");
438 r = InternetSetCookieW(szUrlEmpty, szServer, szServer);
439 ok(r == FALSE, "return wrong\n");
441 r = InternetSetCookieW(szServer, NULL, szServer);
442 todo_wine {
443 ok(GetLastError() == ERROR_INTERNET_UNRECOGNIZED_SCHEME, "wrong error\n");
445 ok(r == FALSE, "return wrong\n");
447 sz = 0;
448 r = InternetGetCookieW(NULL, NULL, NULL, &sz);
449 ok(GetLastError() == ERROR_INVALID_PARAMETER || GetLastError() == ERROR_INTERNET_UNRECOGNIZED_SCHEME,
450 "wrong error %u\n", GetLastError());
451 ok( r == FALSE, "return wrong\n");
453 r = InternetGetCookieW(szServer, NULL, NULL, &sz);
454 todo_wine {
455 ok(GetLastError() == ERROR_INTERNET_UNRECOGNIZED_SCHEME, "wrong error\n");
457 ok( r == FALSE, "return wrong\n");
459 sz = 0;
460 r = InternetGetCookieW(szUrlEmpty, szServer, NULL, &sz);
461 ok( r == FALSE, "return wrong\n");
463 sz = 0;
464 r = InternetGetCookieW(szUrl, szServer, NULL, &sz);
465 ok( r == TRUE, "return wrong\n");
467 /* sz is 14 on XP SP2 and beyond, 30 on XP SP1 and before */
468 ok( sz == 14 || sz == 30, "sz wrong, got %u, expected 14 or 30\n", sz);
470 sz = 0x20;
471 memset(buffer, 0, sizeof buffer);
472 r = InternetGetCookieW(szUrl, szServer, buffer, &sz);
473 ok( r == TRUE, "return wrong\n");
475 /* sz == lstrlenW(buffer) only in XP SP1 */
476 ok( sz == 1 + lstrlenW(buffer) || sz == lstrlenW(buffer), "sz wrong %d\n", sz);
478 /* before XP SP2, buffer is "server; server" */
479 ok( !strcmp_ww(szExpect, buffer) || !strcmp_ww(szServer, buffer), "cookie data wrong\n");
481 sz = sizeof(buffer);
482 r = InternetQueryOptionA(NULL, INTERNET_OPTION_CONNECTED_STATE, buffer, &sz);
483 ok(r == TRUE, "ret %d\n", r);
486 static void test_version(void)
488 INTERNET_VERSION_INFO version;
489 DWORD size;
490 BOOL res;
492 size = sizeof(version);
493 res = InternetQueryOptionA(NULL, INTERNET_OPTION_VERSION, &version, &size);
494 ok(res, "Could not get version: %u\n", GetLastError());
495 ok(version.dwMajorVersion == 1, "dwMajorVersion=%d, expected 1\n", version.dwMajorVersion);
496 ok(version.dwMinorVersion == 2, "dwMinorVersion=%d, expected 2\n", version.dwMinorVersion);
499 static void InternetTimeFromSystemTimeA_test(void)
501 BOOL ret;
502 static const SYSTEMTIME time = { 2005, 1, 5, 7, 12, 6, 35, 0 };
503 char string[INTERNET_RFC1123_BUFSIZE];
504 static const char expect[] = "Fri, 07 Jan 2005 12:06:35 GMT";
505 DWORD error;
507 ret = pInternetTimeFromSystemTimeA( &time, INTERNET_RFC1123_FORMAT, string, sizeof(string) );
508 ok( ret, "InternetTimeFromSystemTimeA failed (%u)\n", GetLastError() );
510 ok( !memcmp( string, expect, sizeof(expect) ),
511 "InternetTimeFromSystemTimeA failed (%u)\n", GetLastError() );
513 /* test NULL time parameter */
514 SetLastError(0xdeadbeef);
515 ret = pInternetTimeFromSystemTimeA( NULL, INTERNET_RFC1123_FORMAT, string, sizeof(string) );
516 error = GetLastError();
517 ok( !ret, "InternetTimeFromSystemTimeA should have returned FALSE\n" );
518 ok( error == ERROR_INVALID_PARAMETER,
519 "InternetTimeFromSystemTimeA failed with ERROR_INVALID_PARAMETER instead of %u\n",
520 error );
522 /* test NULL string parameter */
523 SetLastError(0xdeadbeef);
524 ret = pInternetTimeFromSystemTimeA( &time, INTERNET_RFC1123_FORMAT, NULL, sizeof(string) );
525 error = GetLastError();
526 ok( !ret, "InternetTimeFromSystemTimeA should have returned FALSE\n" );
527 ok( error == ERROR_INVALID_PARAMETER,
528 "InternetTimeFromSystemTimeA failed with ERROR_INVALID_PARAMETER instead of %u\n",
529 error );
531 /* test invalid format parameter */
532 SetLastError(0xdeadbeef);
533 ret = pInternetTimeFromSystemTimeA( &time, INTERNET_RFC1123_FORMAT + 1, string, sizeof(string) );
534 error = GetLastError();
535 ok( !ret, "InternetTimeFromSystemTimeA should have returned FALSE\n" );
536 ok( error == ERROR_INVALID_PARAMETER,
537 "InternetTimeFromSystemTimeA failed with ERROR_INVALID_PARAMETER instead of %u\n",
538 error );
540 /* test too small buffer size */
541 SetLastError(0xdeadbeef);
542 ret = pInternetTimeFromSystemTimeA( &time, INTERNET_RFC1123_FORMAT, string, 0 );
543 error = GetLastError();
544 ok( !ret, "InternetTimeFromSystemTimeA should have returned FALSE\n" );
545 ok( error == ERROR_INSUFFICIENT_BUFFER,
546 "InternetTimeFromSystemTimeA failed with ERROR_INSUFFICIENT_BUFFER instead of %u\n",
547 error );
550 static void InternetTimeFromSystemTimeW_test(void)
552 BOOL ret;
553 static const SYSTEMTIME time = { 2005, 1, 5, 7, 12, 6, 35, 0 };
554 WCHAR string[INTERNET_RFC1123_BUFSIZE + 1];
555 static const WCHAR expect[] = { 'F','r','i',',',' ','0','7',' ','J','a','n',' ','2','0','0','5',' ',
556 '1','2',':','0','6',':','3','5',' ','G','M','T',0 };
557 DWORD error;
559 ret = pInternetTimeFromSystemTimeW( &time, INTERNET_RFC1123_FORMAT, string, sizeof(string) );
560 ok( ret, "InternetTimeFromSystemTimeW failed (%u)\n", GetLastError() );
562 ok( !memcmp( string, expect, sizeof(expect) ),
563 "InternetTimeFromSystemTimeW failed (%u)\n", GetLastError() );
565 /* test NULL time parameter */
566 SetLastError(0xdeadbeef);
567 ret = pInternetTimeFromSystemTimeW( NULL, INTERNET_RFC1123_FORMAT, string, sizeof(string) );
568 error = GetLastError();
569 ok( !ret, "InternetTimeFromSystemTimeW should have returned FALSE\n" );
570 ok( error == ERROR_INVALID_PARAMETER,
571 "InternetTimeFromSystemTimeW failed with ERROR_INVALID_PARAMETER instead of %u\n",
572 error );
574 /* test NULL string parameter */
575 SetLastError(0xdeadbeef);
576 ret = pInternetTimeFromSystemTimeW( &time, INTERNET_RFC1123_FORMAT, NULL, sizeof(string) );
577 error = GetLastError();
578 ok( !ret, "InternetTimeFromSystemTimeW should have returned FALSE\n" );
579 ok( error == ERROR_INVALID_PARAMETER,
580 "InternetTimeFromSystemTimeW failed with ERROR_INVALID_PARAMETER instead of %u\n",
581 error );
583 /* test invalid format parameter */
584 SetLastError(0xdeadbeef);
585 ret = pInternetTimeFromSystemTimeW( &time, INTERNET_RFC1123_FORMAT + 1, string, sizeof(string) );
586 error = GetLastError();
587 ok( !ret, "InternetTimeFromSystemTimeW should have returned FALSE\n" );
588 ok( error == ERROR_INVALID_PARAMETER,
589 "InternetTimeFromSystemTimeW failed with ERROR_INVALID_PARAMETER instead of %u\n",
590 error );
592 /* test too small buffer size */
593 SetLastError(0xdeadbeef);
594 ret = pInternetTimeFromSystemTimeW( &time, INTERNET_RFC1123_FORMAT, string, sizeof(string)/sizeof(string[0]) );
595 error = GetLastError();
596 ok( !ret, "InternetTimeFromSystemTimeW should have returned FALSE\n" );
597 ok( error == ERROR_INSUFFICIENT_BUFFER,
598 "InternetTimeFromSystemTimeW failed with ERROR_INSUFFICIENT_BUFFER instead of %u\n",
599 error );
602 static void InternetTimeToSystemTimeA_test(void)
604 BOOL ret;
605 SYSTEMTIME time;
606 static const SYSTEMTIME expect = { 2005, 1, 5, 7, 12, 6, 35, 0 };
607 static const char string[] = "Fri, 07 Jan 2005 12:06:35 GMT";
608 static const char string2[] = " fri 7 jan 2005 12 06 35";
610 ret = pInternetTimeToSystemTimeA( string, &time, 0 );
611 ok( ret, "InternetTimeToSystemTimeA failed (%u)\n", GetLastError() );
612 ok( !memcmp( &time, &expect, sizeof(expect) ),
613 "InternetTimeToSystemTimeA failed (%u)\n", GetLastError() );
615 ret = pInternetTimeToSystemTimeA( string2, &time, 0 );
616 ok( ret, "InternetTimeToSystemTimeA failed (%u)\n", GetLastError() );
617 ok( !memcmp( &time, &expect, sizeof(expect) ),
618 "InternetTimeToSystemTimeA failed (%u)\n", GetLastError() );
621 static void InternetTimeToSystemTimeW_test(void)
623 BOOL ret;
624 SYSTEMTIME time;
625 static const SYSTEMTIME expect = { 2005, 1, 5, 7, 12, 6, 35, 0 };
626 static const WCHAR string[] = { 'F','r','i',',',' ','0','7',' ','J','a','n',' ','2','0','0','5',' ',
627 '1','2',':','0','6',':','3','5',' ','G','M','T',0 };
628 static const WCHAR string2[] = { ' ','f','r','i',' ','7',' ','j','a','n',' ','2','0','0','5',' ',
629 '1','2',' ','0','6',' ','3','5',0 };
630 static const WCHAR string3[] = { 'F','r',0 };
632 ret = pInternetTimeToSystemTimeW( NULL, NULL, 0 );
633 ok( !ret, "InternetTimeToSystemTimeW succeeded (%u)\n", GetLastError() );
635 ret = pInternetTimeToSystemTimeW( NULL, &time, 0 );
636 ok( !ret, "InternetTimeToSystemTimeW succeeded (%u)\n", GetLastError() );
638 ret = pInternetTimeToSystemTimeW( string, NULL, 0 );
639 ok( !ret, "InternetTimeToSystemTimeW succeeded (%u)\n", GetLastError() );
641 ret = pInternetTimeToSystemTimeW( string, &time, 0 );
642 ok( ret, "InternetTimeToSystemTimeW failed (%u)\n", GetLastError() );
644 ret = pInternetTimeToSystemTimeW( string, &time, 0 );
645 ok( ret, "InternetTimeToSystemTimeW failed (%u)\n", GetLastError() );
646 ok( !memcmp( &time, &expect, sizeof(expect) ),
647 "InternetTimeToSystemTimeW failed (%u)\n", GetLastError() );
649 ret = pInternetTimeToSystemTimeW( string2, &time, 0 );
650 ok( ret, "InternetTimeToSystemTimeW failed (%u)\n", GetLastError() );
651 ok( !memcmp( &time, &expect, sizeof(expect) ),
652 "InternetTimeToSystemTimeW failed (%u)\n", GetLastError() );
654 ret = pInternetTimeToSystemTimeW( string3, &time, 0 );
655 ok( ret, "InternetTimeToSystemTimeW failed (%u)\n", GetLastError() );
658 static void test_IsDomainLegalCookieDomainW(void)
660 BOOL ret;
661 DWORD error;
662 static const WCHAR empty[] = {0};
663 static const WCHAR dot[] = {'.',0};
664 static const WCHAR uk[] = {'u','k',0};
665 static const WCHAR com[] = {'c','o','m',0};
666 static const WCHAR dot_com[] = {'.','c','o','m',0};
667 static const WCHAR gmail_com[] = {'g','m','a','i','l','.','c','o','m',0};
668 static const WCHAR dot_gmail_com[] = {'.','g','m','a','i','l','.','c','o','m',0};
669 static const WCHAR mail_gmail_com[] = {'m','a','i','l','.','g','m','a','i','l','.','c','o','m',0};
670 static const WCHAR gmail_co_uk[] = {'g','m','a','i','l','.','c','o','.','u','k',0};
671 static const WCHAR co_uk[] = {'c','o','.','u','k',0};
672 static const WCHAR dot_co_uk[] = {'.','c','o','.','u','k',0};
674 SetLastError(0xdeadbeef);
675 ret = pIsDomainLegalCookieDomainW(NULL, NULL);
676 error = GetLastError();
677 if (!ret && error == ERROR_CALL_NOT_IMPLEMENTED)
679 win_skip("IsDomainLegalCookieDomainW is not implemented\n");
680 return;
682 ok(!ret ||
683 broken(ret), /* IE6 */
684 "IsDomainLegalCookieDomainW succeeded\n");
685 ok(error == ERROR_INVALID_PARAMETER, "got %u expected ERROR_INVALID_PARAMETER\n", error);
687 SetLastError(0xdeadbeef);
688 ret = pIsDomainLegalCookieDomainW(com, NULL);
689 error = GetLastError();
690 ok(!ret, "IsDomainLegalCookieDomainW succeeded\n");
691 ok(error == ERROR_INVALID_PARAMETER, "got %u expected ERROR_INVALID_PARAMETER\n", error);
693 SetLastError(0xdeadbeef);
694 ret = pIsDomainLegalCookieDomainW(NULL, gmail_com);
695 error = GetLastError();
696 ok(!ret, "IsDomainLegalCookieDomainW succeeded\n");
697 ok(error == ERROR_INVALID_PARAMETER, "got %u expected ERROR_INVALID_PARAMETER\n", error);
699 SetLastError(0xdeadbeef);
700 ret = pIsDomainLegalCookieDomainW(empty, gmail_com);
701 error = GetLastError();
702 ok(!ret, "IsDomainLegalCookieDomainW succeeded\n");
703 ok(error == ERROR_INVALID_NAME ||
704 broken(error == ERROR_INVALID_PARAMETER), /* IE6 */
705 "got %u expected ERROR_INVALID_NAME\n", error);
707 SetLastError(0xdeadbeef);
708 ret = pIsDomainLegalCookieDomainW(com, empty);
709 error = GetLastError();
710 ok(!ret, "IsDomainLegalCookieDomainW succeeded\n");
711 ok(error == ERROR_INVALID_NAME ||
712 broken(error == ERROR_INVALID_PARAMETER), /* IE6 */
713 "got %u expected ERROR_INVALID_NAME\n", error);
715 SetLastError(0xdeadbeef);
716 ret = pIsDomainLegalCookieDomainW(gmail_com, dot);
717 error = GetLastError();
718 ok(!ret, "IsDomainLegalCookieDomainW succeeded\n");
719 ok(error == ERROR_INVALID_NAME ||
720 broken(error == 0xdeadbeef), /* IE6 */
721 "got %u expected ERROR_INVALID_NAME\n", error);
723 SetLastError(0xdeadbeef);
724 ret = pIsDomainLegalCookieDomainW(dot, gmail_com);
725 error = GetLastError();
726 ok(!ret, "IsDomainLegalCookieDomainW succeeded\n");
727 ok(error == ERROR_INVALID_NAME ||
728 broken(error == 0xdeadbeef), /* IE6 */
729 "got %u expected ERROR_INVALID_NAME\n", error);
731 SetLastError(0xdeadbeef);
732 ret = pIsDomainLegalCookieDomainW(com, com);
733 error = GetLastError();
734 ok(!ret, "IsDomainLegalCookieDomainW succeeded\n");
735 ok(error == 0xdeadbeef, "got %u expected 0xdeadbeef\n", error);
737 SetLastError(0xdeadbeef);
738 ret = pIsDomainLegalCookieDomainW(com, dot_com);
739 error = GetLastError();
740 ok(!ret, "IsDomainLegalCookieDomainW succeeded\n");
741 ok(error == ERROR_INVALID_NAME ||
742 broken(error == 0xdeadbeef), /* IE6 */
743 "got %u expected ERROR_INVALID_NAME\n", error);
745 SetLastError(0xdeadbeef);
746 ret = pIsDomainLegalCookieDomainW(dot_com, com);
747 error = GetLastError();
748 ok(!ret, "IsDomainLegalCookieDomainW succeeded\n");
749 ok(error == ERROR_INVALID_NAME ||
750 broken(error == 0xdeadbeef), /* IE6 */
751 "got %u expected ERROR_INVALID_NAME\n", error);
753 SetLastError(0xdeadbeef);
754 ret = pIsDomainLegalCookieDomainW(com, gmail_com);
755 error = GetLastError();
756 ok(!ret, "IsDomainLegalCookieDomainW succeeded\n");
757 ok(error == ERROR_SXS_KEY_NOT_FOUND ||
758 error == ERROR_SUCCESS || /* IE8 on W2K3 */
759 error == 0xdeadbeef, /* up to IE7 */
760 "unexpected error: %u\n", error);
762 ret = pIsDomainLegalCookieDomainW(gmail_com, gmail_com);
763 ok(ret, "IsDomainLegalCookieDomainW failed\n");
765 SetLastError(0xdeadbeef);
766 ret = pIsDomainLegalCookieDomainW(gmail_co_uk, co_uk);
767 error = GetLastError();
768 ok(!ret, "IsDomainLegalCookieDomainW succeeded\n");
769 ok(error == ERROR_SXS_KEY_NOT_FOUND || /* IE8 on XP */
770 error == ERROR_FILE_NOT_FOUND || /* IE8 on Vista */
771 error == ERROR_SUCCESS || /* IE8 on W2K3 */
772 error == 0xdeadbeef, /* up to IE7 */
773 "unexpected error: %u\n", error);
775 ret = pIsDomainLegalCookieDomainW(uk, co_uk);
776 ok(!ret, "IsDomainLegalCookieDomainW succeeded\n");
778 ret = pIsDomainLegalCookieDomainW(gmail_co_uk, dot_co_uk);
779 ok(!ret, "IsDomainLegalCookieDomainW succeeded\n");
781 ret = pIsDomainLegalCookieDomainW(gmail_co_uk, gmail_co_uk);
782 ok(ret, "IsDomainLegalCookieDomainW failed\n");
784 ret = pIsDomainLegalCookieDomainW(gmail_com, com);
785 ok(!ret, "IsDomainLegalCookieDomainW succeeded\n");
787 SetLastError(0xdeadbeef);
788 ret = pIsDomainLegalCookieDomainW(dot_gmail_com, mail_gmail_com);
789 error = GetLastError();
790 ok(!ret, "IsDomainLegalCookieDomainW succeeded\n");
791 ok(error == ERROR_INVALID_NAME ||
792 broken(error == 0xdeadbeef), /* IE6 */
793 "got %u expected ERROR_INVALID_NAME\n", error);
795 ret = pIsDomainLegalCookieDomainW(gmail_com, mail_gmail_com);
796 ok(ret, "IsDomainLegalCookieDomainW failed\n");
798 ret = pIsDomainLegalCookieDomainW(mail_gmail_com, gmail_com);
799 ok(!ret, "IsDomainLegalCookieDomainW succeeded\n");
801 ret = pIsDomainLegalCookieDomainW(mail_gmail_com, com);
802 ok(!ret, "IsDomainLegalCookieDomainW succeeded\n");
804 ret = pIsDomainLegalCookieDomainW(dot_gmail_com, mail_gmail_com);
805 ok(!ret, "IsDomainLegalCookieDomainW succeeded\n");
807 ret = pIsDomainLegalCookieDomainW(mail_gmail_com, dot_gmail_com);
808 ok(!ret, "IsDomainLegalCookieDomainW succeeded\n");
811 static void test_PrivacyGetSetZonePreferenceW(void)
813 DWORD ret, zone, type, template, old_template;
815 zone = 3;
816 type = 0;
817 ret = pPrivacyGetZonePreferenceW(zone, type, NULL, NULL, NULL);
818 ok(ret == 0, "expected ret == 0, got %u\n", ret);
820 old_template = 0;
821 ret = pPrivacyGetZonePreferenceW(zone, type, &old_template, NULL, NULL);
822 ok(ret == 0, "expected ret == 0, got %u\n", ret);
824 template = 5;
825 ret = pPrivacySetZonePreferenceW(zone, type, template, NULL);
826 ok(ret == 0, "expected ret == 0, got %u\n", ret);
828 template = 0;
829 ret = pPrivacyGetZonePreferenceW(zone, type, &template, NULL, NULL);
830 ok(ret == 0, "expected ret == 0, got %u\n", ret);
831 ok(template == 5, "expected template == 5, got %u\n", template);
833 template = 5;
834 ret = pPrivacySetZonePreferenceW(zone, type, old_template, NULL);
835 ok(ret == 0, "expected ret == 0, got %u\n", ret);
838 static void test_Option_Policy(void)
840 HINTERNET hinet;
841 BOOL ret;
843 hinet = InternetOpen(NULL, INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, 0);
844 ok(hinet != 0, "InternetOpen failed: 0x%08x\n", GetLastError());
846 SetLastError(0xdeadbeef);
847 ret = InternetSetOptionW(hinet, INTERNET_OPTION_POLICY, NULL, 0);
848 ok(ret == FALSE, "InternetSetOption should've failed\n");
849 ok(GetLastError() == ERROR_INVALID_PARAMETER, "GetLastError should've "
850 "given ERROR_INVALID_PARAMETER, gave: 0x%08x\n", GetLastError());
852 SetLastError(0xdeadbeef);
853 ret = InternetQueryOptionW(hinet, INTERNET_OPTION_POLICY, NULL, 0);
854 ok(ret == FALSE, "InternetQueryOption should've failed\n");
855 ok(GetLastError() == ERROR_INVALID_PARAMETER, "GetLastError should've "
856 "given ERROR_INVALID_PARAMETER, gave: 0x%08x\n", GetLastError());
858 ret = InternetCloseHandle(hinet);
859 ok(ret == TRUE, "InternetCloseHandle failed: 0x%08x\n", GetLastError());
862 #define verifyProxyEnable(e) r_verifyProxyEnable(__LINE__, e)
863 static void r_verifyProxyEnable(LONG l, DWORD exp)
865 HKEY hkey;
866 DWORD type, val, size = sizeof(DWORD);
867 LONG ret;
868 static const CHAR szInternetSettings[] = "Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings";
869 static const CHAR szProxyEnable[] = "ProxyEnable";
871 ret = RegOpenKeyA(HKEY_CURRENT_USER, szInternetSettings, &hkey);
872 ok_(__FILE__,l) (!ret, "RegOpenKeyA failed: 0x%08x\n", ret);
874 ret = RegQueryValueExA(hkey, szProxyEnable, 0, &type, (BYTE*)&val, &size);
875 ok_(__FILE__,l) (!ret, "RegQueryValueExA failed: 0x%08x\n", ret);
876 ok_(__FILE__,l) (type == REG_DWORD, "Expected regtype to be REG_DWORD, was: %d\n", type);
877 ok_(__FILE__,l) (val == exp, "Expected ProxyEnabled to be %d, got: %d\n", exp, val);
879 ret = RegCloseKey(hkey);
880 ok_(__FILE__,l) (!ret, "RegCloseKey failed: 0x%08x\n", ret);
883 static void test_Option_PerConnectionOption(void)
885 BOOL ret;
886 DWORD size = sizeof(INTERNET_PER_CONN_OPTION_LISTW);
887 INTERNET_PER_CONN_OPTION_LISTW list = {size};
888 INTERNET_PER_CONN_OPTIONW *orig_settings;
889 static WCHAR proxy_srvW[] = {'p','r','o','x','y','.','e','x','a','m','p','l','e',0};
891 /* get the global IE proxy server info, to restore later */
892 list.dwOptionCount = 2;
893 list.pOptions = HeapAlloc(GetProcessHeap(), 0, 2 * sizeof(INTERNET_PER_CONN_OPTIONW));
895 list.pOptions[0].dwOption = INTERNET_PER_CONN_PROXY_SERVER;
896 list.pOptions[1].dwOption = INTERNET_PER_CONN_FLAGS;
898 ret = InternetQueryOptionW(NULL, INTERNET_OPTION_PER_CONNECTION_OPTION,
899 &list, &size);
900 ok(ret == TRUE, "InternetQueryOption should've succeeded\n");
901 orig_settings = list.pOptions;
903 /* set the global IE proxy server */
904 list.dwOptionCount = 2;
905 list.pOptions = HeapAlloc(GetProcessHeap(), 0, 2 * sizeof(INTERNET_PER_CONN_OPTIONW));
907 list.pOptions[0].dwOption = INTERNET_PER_CONN_PROXY_SERVER;
908 list.pOptions[0].Value.pszValue = proxy_srvW;
909 list.pOptions[1].dwOption = INTERNET_PER_CONN_FLAGS;
910 list.pOptions[1].Value.dwValue = PROXY_TYPE_PROXY;
912 ret = InternetSetOptionW(NULL, INTERNET_OPTION_PER_CONNECTION_OPTION,
913 &list, size);
914 ok(ret == TRUE, "InternetSetOption should've succeeded\n");
916 HeapFree(GetProcessHeap(), 0, list.pOptions);
918 /* get & verify the global IE proxy server */
919 list.dwOptionCount = 2;
920 list.dwOptionError = 0;
921 list.pOptions = HeapAlloc(GetProcessHeap(), 0, 2 * sizeof(INTERNET_PER_CONN_OPTIONW));
923 list.pOptions[0].dwOption = INTERNET_PER_CONN_PROXY_SERVER;
924 list.pOptions[1].dwOption = INTERNET_PER_CONN_FLAGS;
926 ret = InternetQueryOptionW(NULL, INTERNET_OPTION_PER_CONNECTION_OPTION,
927 &list, &size);
928 ok(ret == TRUE, "InternetQueryOption should've succeeded\n");
929 ok(!strcmp_ww(list.pOptions[0].Value.pszValue, proxy_srvW),
930 "Retrieved proxy server should've been %s, was: %s\n",
931 wine_dbgstr_w(proxy_srvW), wine_dbgstr_w(list.pOptions[0].Value.pszValue));
932 ok(list.pOptions[1].Value.dwValue == PROXY_TYPE_PROXY,
933 "Retrieved flags should've been PROXY_TYPE_PROXY, was: %d\n",
934 list.pOptions[1].Value.dwValue);
935 verifyProxyEnable(1);
937 HeapFree(GetProcessHeap(), 0, list.pOptions[0].Value.pszValue);
938 HeapFree(GetProcessHeap(), 0, list.pOptions);
940 /* disable the proxy server */
941 list.dwOptionCount = 1;
942 list.pOptions = HeapAlloc(GetProcessHeap(), 0, sizeof(INTERNET_PER_CONN_OPTIONW));
944 list.pOptions[0].dwOption = INTERNET_PER_CONN_FLAGS;
945 list.pOptions[0].Value.dwValue = PROXY_TYPE_DIRECT;
947 ret = InternetSetOptionW(NULL, INTERNET_OPTION_PER_CONNECTION_OPTION,
948 &list, size);
949 ok(ret == TRUE, "InternetSetOption should've succeeded\n");
951 HeapFree(GetProcessHeap(), 0, list.pOptions);
953 /* verify that the proxy is disabled */
954 list.dwOptionCount = 1;
955 list.dwOptionError = 0;
956 list.pOptions = HeapAlloc(GetProcessHeap(), 0, sizeof(INTERNET_PER_CONN_OPTIONW));
958 list.pOptions[0].dwOption = INTERNET_PER_CONN_FLAGS;
960 ret = InternetQueryOptionW(NULL, INTERNET_OPTION_PER_CONNECTION_OPTION,
961 &list, &size);
962 ok(ret == TRUE, "InternetQueryOption should've succeeded\n");
963 ok(list.pOptions[0].Value.dwValue == PROXY_TYPE_DIRECT,
964 "Retrieved flags should've been PROXY_TYPE_DIRECT, was: %d\n",
965 list.pOptions[0].Value.dwValue);
966 verifyProxyEnable(0);
968 HeapFree(GetProcessHeap(), 0, list.pOptions);
970 /* set the proxy flags to 'invalid' value */
971 list.dwOptionCount = 1;
972 list.pOptions = HeapAlloc(GetProcessHeap(), 0, sizeof(INTERNET_PER_CONN_OPTIONW));
974 list.pOptions[0].dwOption = INTERNET_PER_CONN_FLAGS;
975 list.pOptions[0].Value.dwValue = PROXY_TYPE_PROXY | PROXY_TYPE_DIRECT;
977 ret = InternetSetOptionW(NULL, INTERNET_OPTION_PER_CONNECTION_OPTION,
978 &list, size);
979 ok(ret == TRUE, "InternetSetOption should've succeeded\n");
981 HeapFree(GetProcessHeap(), 0, list.pOptions);
983 /* verify that the proxy is enabled */
984 list.dwOptionCount = 1;
985 list.dwOptionError = 0;
986 list.pOptions = HeapAlloc(GetProcessHeap(), 0, sizeof(INTERNET_PER_CONN_OPTIONW));
988 list.pOptions[0].dwOption = INTERNET_PER_CONN_FLAGS;
990 ret = InternetQueryOptionW(NULL, INTERNET_OPTION_PER_CONNECTION_OPTION,
991 &list, &size);
992 ok(ret == TRUE, "InternetQueryOption should've succeeded\n");
993 todo_wine ok(list.pOptions[0].Value.dwValue == (PROXY_TYPE_PROXY | PROXY_TYPE_DIRECT),
994 "Retrieved flags should've been PROXY_TYPE_PROXY | PROXY_TYPE_DIRECT, was: %d\n",
995 list.pOptions[0].Value.dwValue);
996 verifyProxyEnable(1);
998 HeapFree(GetProcessHeap(), 0, list.pOptions);
1000 /* restore original settings */
1001 list.dwOptionCount = 2;
1002 list.pOptions = orig_settings;
1004 ret = InternetSetOptionW(NULL, INTERNET_OPTION_PER_CONNECTION_OPTION,
1005 &list, size);
1006 ok(ret == TRUE, "InternetSetOption should've succeeded\n");
1008 HeapFree(GetProcessHeap(), 0, list.pOptions);
1011 static void test_Option_PerConnectionOptionA(void)
1013 BOOL ret;
1014 DWORD size = sizeof(INTERNET_PER_CONN_OPTION_LISTA);
1015 INTERNET_PER_CONN_OPTION_LISTA list = {size};
1016 INTERNET_PER_CONN_OPTIONA *orig_settings;
1017 char proxy_srv[] = "proxy.example";
1019 /* get the global IE proxy server info, to restore later */
1020 list.dwOptionCount = 2;
1021 list.pOptions = HeapAlloc(GetProcessHeap(), 0, 2 * sizeof(INTERNET_PER_CONN_OPTIONA));
1023 list.pOptions[0].dwOption = INTERNET_PER_CONN_PROXY_SERVER;
1024 list.pOptions[1].dwOption = INTERNET_PER_CONN_FLAGS;
1026 ret = InternetQueryOptionA(NULL, INTERNET_OPTION_PER_CONNECTION_OPTION,
1027 &list, &size);
1028 ok(ret == TRUE, "InternetQueryOption should've succeeded\n");
1029 orig_settings = list.pOptions;
1031 /* set the global IE proxy server */
1032 list.dwOptionCount = 2;
1033 list.pOptions = HeapAlloc(GetProcessHeap(), 0, 2 * sizeof(INTERNET_PER_CONN_OPTIONA));
1035 list.pOptions[0].dwOption = INTERNET_PER_CONN_PROXY_SERVER;
1036 list.pOptions[0].Value.pszValue = proxy_srv;
1037 list.pOptions[1].dwOption = INTERNET_PER_CONN_FLAGS;
1038 list.pOptions[1].Value.dwValue = PROXY_TYPE_PROXY;
1040 ret = InternetSetOptionA(NULL, INTERNET_OPTION_PER_CONNECTION_OPTION,
1041 &list, size);
1042 ok(ret == TRUE, "InternetSetOption should've succeeded\n");
1044 HeapFree(GetProcessHeap(), 0, list.pOptions);
1046 /* get & verify the global IE proxy server */
1047 list.dwOptionCount = 2;
1048 list.dwOptionError = 0;
1049 list.pOptions = HeapAlloc(GetProcessHeap(), 0, 2 * sizeof(INTERNET_PER_CONN_OPTIONA));
1051 list.pOptions[0].dwOption = INTERNET_PER_CONN_PROXY_SERVER;
1052 list.pOptions[1].dwOption = INTERNET_PER_CONN_FLAGS;
1054 ret = InternetQueryOptionA(NULL, INTERNET_OPTION_PER_CONNECTION_OPTION,
1055 &list, &size);
1056 ok(ret == TRUE, "InternetQueryOption should've succeeded\n");
1057 ok(!lstrcmpA(list.pOptions[0].Value.pszValue, "proxy.example"),
1058 "Retrieved proxy server should've been \"%s\", was: \"%s\"\n",
1059 proxy_srv, list.pOptions[0].Value.pszValue);
1060 ok(list.pOptions[1].Value.dwValue == PROXY_TYPE_PROXY,
1061 "Retrieved flags should've been PROXY_TYPE_PROXY, was: %d\n",
1062 list.pOptions[1].Value.dwValue);
1064 HeapFree(GetProcessHeap(), 0, list.pOptions[0].Value.pszValue);
1065 HeapFree(GetProcessHeap(), 0, list.pOptions);
1067 /* restore original settings */
1068 list.dwOptionCount = 2;
1069 list.pOptions = orig_settings;
1071 ret = InternetSetOptionA(NULL, INTERNET_OPTION_PER_CONNECTION_OPTION,
1072 &list, size);
1073 ok(ret == TRUE, "InternetSetOption should've succeeded\n");
1075 HeapFree(GetProcessHeap(), 0, list.pOptions);
1078 /* ############################### */
1080 START_TEST(internet)
1082 HMODULE hdll;
1083 hdll = GetModuleHandleA("wininet.dll");
1084 pCreateUrlCacheContainerA = (void*)GetProcAddress(hdll, "CreateUrlCacheContainerA");
1085 pCreateUrlCacheContainerW = (void*)GetProcAddress(hdll, "CreateUrlCacheContainerW");
1086 pInternetTimeFromSystemTimeA = (void*)GetProcAddress(hdll, "InternetTimeFromSystemTimeA");
1087 pInternetTimeFromSystemTimeW = (void*)GetProcAddress(hdll, "InternetTimeFromSystemTimeW");
1088 pInternetTimeToSystemTimeA = (void*)GetProcAddress(hdll, "InternetTimeToSystemTimeA");
1089 pInternetTimeToSystemTimeW = (void*)GetProcAddress(hdll, "InternetTimeToSystemTimeW");
1090 pIsDomainLegalCookieDomainW = (void*)GetProcAddress(hdll, (LPCSTR)117);
1091 pPrivacyGetZonePreferenceW = (void*)GetProcAddress(hdll, "PrivacyGetZonePreferenceW");
1092 pPrivacySetZonePreferenceW = (void*)GetProcAddress(hdll, "PrivacySetZonePreferenceW");
1094 test_InternetCanonicalizeUrlA();
1095 test_InternetQueryOptionA();
1096 test_get_cookie();
1097 test_complicated_cookie();
1098 test_version();
1099 test_null();
1100 test_Option_Policy();
1101 test_Option_PerConnectionOption();
1102 test_Option_PerConnectionOptionA();
1104 if (!pInternetTimeFromSystemTimeA)
1105 win_skip("skipping the InternetTime tests\n");
1106 else
1108 InternetTimeFromSystemTimeA_test();
1109 InternetTimeFromSystemTimeW_test();
1110 InternetTimeToSystemTimeA_test();
1111 InternetTimeToSystemTimeW_test();
1113 if (pIsDomainLegalCookieDomainW &&
1114 ((void*)pIsDomainLegalCookieDomainW == (void*)pCreateUrlCacheContainerA ||
1115 (void*)pIsDomainLegalCookieDomainW == (void*)pCreateUrlCacheContainerW))
1116 win_skip("IsDomainLegalCookieDomainW is not available on systems with IE5\n");
1117 else if (!pIsDomainLegalCookieDomainW)
1118 win_skip("IsDomainLegalCookieDomainW (or ordinal 117) is not available\n");
1119 else
1120 test_IsDomainLegalCookieDomainW();
1122 if (pPrivacyGetZonePreferenceW && pPrivacySetZonePreferenceW)
1123 test_PrivacyGetSetZonePreferenceW();
1124 else
1125 win_skip("Privacy[SG]etZonePreferenceW are not available\n");