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
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)
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';
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';
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';
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';
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';
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';
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 */
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
;
168 static const char useragent
[] = {"Wininet Test"};
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
);
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
);
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
);
194 ok(retval
== 1,"Got wrong return value %d\n",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);
205 buffer
=HeapAlloc(GetProcessHeap(),0,100);
206 retval
=InternetQueryOptionA(hinet
,INTERNET_OPTION_USER_AGENT
,buffer
,&len
);
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);
217 retval
= InternetQueryOptionA(hurl
,INTERNET_OPTION_USER_AGENT
,NULL
,&len
);
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);
231 retval
=InternetQueryOptionA(hinet
,INTERNET_OPTION_USER_AGENT
,NULL
,&len
);
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);
243 retval
=InternetQueryOptionA(hinet
,INTERNET_OPTION_USER_AGENT
,NULL
,&len
);
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)
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)
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");
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");
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");
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");
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");
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");
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");
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)
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 };
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");
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
);
443 ok(GetLastError() == ERROR_INTERNET_UNRECOGNIZED_SCHEME
, "wrong error\n");
445 ok(r
== FALSE
, "return wrong\n");
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
);
455 ok(GetLastError() == ERROR_INTERNET_UNRECOGNIZED_SCHEME
, "wrong error\n");
457 ok( r
== FALSE
, "return wrong\n");
460 r
= InternetGetCookieW(szUrlEmpty
, szServer
, NULL
, &sz
);
461 ok( r
== FALSE
, "return wrong\n");
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
);
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");
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
;
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)
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";
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",
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",
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",
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",
550 static void InternetTimeFromSystemTimeW_test(void)
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 };
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",
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",
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",
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",
602 static void InternetTimeToSystemTimeA_test(void)
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)
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)
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");
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
;
817 ret
= pPrivacyGetZonePreferenceW(zone
, type
, NULL
, NULL
, NULL
);
818 ok(ret
== 0, "expected ret == 0, got %u\n", ret
);
821 ret
= pPrivacyGetZonePreferenceW(zone
, type
, &old_template
, NULL
, NULL
);
822 ok(ret
== 0, "expected ret == 0, got %u\n", ret
);
825 ret
= pPrivacySetZonePreferenceW(zone
, type
, template, NULL
);
826 ok(ret
== 0, "expected ret == 0, got %u\n", ret
);
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);
834 ret
= pPrivacySetZonePreferenceW(zone
, type
, old_template
, NULL
);
835 ok(ret
== 0, "expected ret == 0, got %u\n", ret
);
838 static void test_InternetSetOption(void)
840 HINTERNET ses
, con
, req
;
845 ses
= InternetOpen(NULL
, INTERNET_OPEN_TYPE_DIRECT
, NULL
, NULL
, 0);
846 ok(ses
!= 0, "InternetOpen failed: 0x%08x\n", GetLastError());
847 con
= InternetConnect(ses
, "www.winehq.org", 80, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0);
848 ok(con
!= 0, "InternetConnect failed: 0x%08x\n", GetLastError());
849 req
= HttpOpenRequest(con
, "GET", "/", NULL
, NULL
, NULL
, 0, 0);
850 ok(req
!= 0, "HttpOpenRequest failed: 0x%08x\n", GetLastError());
852 /* INTERNET_OPTION_POLICY tests */
853 SetLastError(0xdeadbeef);
854 ret
= InternetSetOptionW(ses
, INTERNET_OPTION_POLICY
, NULL
, 0);
855 ok(ret
== FALSE
, "InternetSetOption should've failed\n");
856 ok(GetLastError() == ERROR_INVALID_PARAMETER
, "GetLastError should've "
857 "given ERROR_INVALID_PARAMETER, gave: 0x%08x\n", GetLastError());
859 SetLastError(0xdeadbeef);
860 ret
= InternetQueryOptionW(ses
, INTERNET_OPTION_POLICY
, NULL
, 0);
861 ok(ret
== FALSE
, "InternetQueryOption should've failed\n");
862 ok(GetLastError() == ERROR_INVALID_PARAMETER
, "GetLastError should've "
863 "given ERROR_INVALID_PARAMETER, gave: 0x%08x\n", GetLastError());
865 /* INTERNET_OPTION_ERROR_MASK tests */
866 SetLastError(0xdeadbeef);
867 size
= sizeof(ulArg
);
868 ret
= InternetQueryOptionW(NULL
, INTERNET_OPTION_ERROR_MASK
, (void*)&ulArg
, &size
);
869 ok(ret
== FALSE
, "InternetQueryOption should've failed\n");
870 ok(GetLastError() == ERROR_INTERNET_INCORRECT_HANDLE_TYPE
, "GetLastError() = %x\n", GetLastError());
872 SetLastError(0xdeadbeef);
874 ret
= InternetSetOption(NULL
, INTERNET_OPTION_ERROR_MASK
, (void*)&ulArg
, sizeof(ULONG
));
875 ok(ret
== FALSE
, "InternetQueryOption should've failed\n");
876 ok(GetLastError() == ERROR_INTERNET_INCORRECT_HANDLE_TYPE
, "GetLastError() = %x\n", GetLastError());
878 SetLastError(0xdeadbeef);
880 ret
= InternetSetOption(req
, INTERNET_OPTION_ERROR_MASK
, (void*)&ulArg
, 20);
881 ok(ret
== FALSE
, "InternetQueryOption should've failed\n");
882 ok(GetLastError() == ERROR_INTERNET_BAD_OPTION_LENGTH
, "GetLastError() = %d\n", GetLastError());
884 SetLastError(0xdeadbeef);
886 ret
= InternetSetOption(req
, INTERNET_OPTION_ERROR_MASK
, (void*)&ulArg
, sizeof(ULONG
));
887 ok(ret
== TRUE
, "InternetQueryOption should've succeeded\n");
888 ok(GetLastError() == 0xdeadbeef, "GetLastError() = %d\n", GetLastError());
890 SetLastError(0xdeadbeef);
892 ret
= InternetSetOption(req
, INTERNET_OPTION_ERROR_MASK
, (void*)&ulArg
, sizeof(ULONG
));
893 ok(ret
== FALSE
, "InternetQueryOption should've failed\n");
894 ok(GetLastError() == ERROR_INVALID_PARAMETER
, "GetLastError() = %x\n", GetLastError());
896 SetLastError(0xdeadbeef);
898 ret
= InternetSetOption(req
, INTERNET_OPTION_ERROR_MASK
, (void*)&ulArg
, sizeof(ULONG
));
899 ok(ret
== FALSE
, "InternetQueryOption should've failed\n");
900 ok(GetLastError() == ERROR_INVALID_PARAMETER
, "GetLastError() = %x\n", GetLastError());
902 ret
= InternetCloseHandle(req
);
903 ok(ret
== TRUE
, "InternetCloseHandle failed: 0x%08x\n", GetLastError());
904 ret
= InternetCloseHandle(con
);
905 ok(ret
== TRUE
, "InternetCloseHandle failed: 0x%08x\n", GetLastError());
906 ret
= InternetCloseHandle(ses
);
907 ok(ret
== TRUE
, "InternetCloseHandle failed: 0x%08x\n", GetLastError());
910 #define verifyProxyEnable(e) r_verifyProxyEnable(__LINE__, e)
911 static void r_verifyProxyEnable(LONG l
, DWORD exp
)
914 DWORD type
, val
, size
= sizeof(DWORD
);
916 static const CHAR szInternetSettings
[] = "Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings";
917 static const CHAR szProxyEnable
[] = "ProxyEnable";
919 ret
= RegOpenKeyA(HKEY_CURRENT_USER
, szInternetSettings
, &hkey
);
920 ok_(__FILE__
,l
) (!ret
, "RegOpenKeyA failed: 0x%08x\n", ret
);
922 ret
= RegQueryValueExA(hkey
, szProxyEnable
, 0, &type
, (BYTE
*)&val
, &size
);
923 ok_(__FILE__
,l
) (!ret
, "RegQueryValueExA failed: 0x%08x\n", ret
);
924 ok_(__FILE__
,l
) (type
== REG_DWORD
, "Expected regtype to be REG_DWORD, was: %d\n", type
);
925 ok_(__FILE__
,l
) (val
== exp
, "Expected ProxyEnabled to be %d, got: %d\n", exp
, val
);
927 ret
= RegCloseKey(hkey
);
928 ok_(__FILE__
,l
) (!ret
, "RegCloseKey failed: 0x%08x\n", ret
);
931 static void test_Option_PerConnectionOption(void)
934 DWORD size
= sizeof(INTERNET_PER_CONN_OPTION_LISTW
);
935 INTERNET_PER_CONN_OPTION_LISTW list
= {size
};
936 INTERNET_PER_CONN_OPTIONW
*orig_settings
;
937 static WCHAR proxy_srvW
[] = {'p','r','o','x','y','.','e','x','a','m','p','l','e',0};
939 /* get the global IE proxy server info, to restore later */
940 list
.dwOptionCount
= 2;
941 list
.pOptions
= HeapAlloc(GetProcessHeap(), 0, 2 * sizeof(INTERNET_PER_CONN_OPTIONW
));
943 list
.pOptions
[0].dwOption
= INTERNET_PER_CONN_PROXY_SERVER
;
944 list
.pOptions
[1].dwOption
= INTERNET_PER_CONN_FLAGS
;
946 ret
= InternetQueryOptionW(NULL
, INTERNET_OPTION_PER_CONNECTION_OPTION
,
948 ok(ret
== TRUE
, "InternetQueryOption should've succeeded\n");
949 orig_settings
= list
.pOptions
;
951 /* set the global IE proxy server */
952 list
.dwOptionCount
= 2;
953 list
.pOptions
= HeapAlloc(GetProcessHeap(), 0, 2 * sizeof(INTERNET_PER_CONN_OPTIONW
));
955 list
.pOptions
[0].dwOption
= INTERNET_PER_CONN_PROXY_SERVER
;
956 list
.pOptions
[0].Value
.pszValue
= proxy_srvW
;
957 list
.pOptions
[1].dwOption
= INTERNET_PER_CONN_FLAGS
;
958 list
.pOptions
[1].Value
.dwValue
= PROXY_TYPE_PROXY
;
960 ret
= InternetSetOptionW(NULL
, INTERNET_OPTION_PER_CONNECTION_OPTION
,
962 ok(ret
== TRUE
, "InternetSetOption should've succeeded\n");
964 HeapFree(GetProcessHeap(), 0, list
.pOptions
);
966 /* get & verify the global IE proxy server */
967 list
.dwOptionCount
= 2;
968 list
.dwOptionError
= 0;
969 list
.pOptions
= HeapAlloc(GetProcessHeap(), 0, 2 * sizeof(INTERNET_PER_CONN_OPTIONW
));
971 list
.pOptions
[0].dwOption
= INTERNET_PER_CONN_PROXY_SERVER
;
972 list
.pOptions
[1].dwOption
= INTERNET_PER_CONN_FLAGS
;
974 ret
= InternetQueryOptionW(NULL
, INTERNET_OPTION_PER_CONNECTION_OPTION
,
976 ok(ret
== TRUE
, "InternetQueryOption should've succeeded\n");
977 ok(!strcmp_ww(list
.pOptions
[0].Value
.pszValue
, proxy_srvW
),
978 "Retrieved proxy server should've been %s, was: %s\n",
979 wine_dbgstr_w(proxy_srvW
), wine_dbgstr_w(list
.pOptions
[0].Value
.pszValue
));
980 ok(list
.pOptions
[1].Value
.dwValue
== PROXY_TYPE_PROXY
,
981 "Retrieved flags should've been PROXY_TYPE_PROXY, was: %d\n",
982 list
.pOptions
[1].Value
.dwValue
);
983 verifyProxyEnable(1);
985 HeapFree(GetProcessHeap(), 0, list
.pOptions
[0].Value
.pszValue
);
986 HeapFree(GetProcessHeap(), 0, list
.pOptions
);
988 /* disable the proxy server */
989 list
.dwOptionCount
= 1;
990 list
.pOptions
= HeapAlloc(GetProcessHeap(), 0, sizeof(INTERNET_PER_CONN_OPTIONW
));
992 list
.pOptions
[0].dwOption
= INTERNET_PER_CONN_FLAGS
;
993 list
.pOptions
[0].Value
.dwValue
= PROXY_TYPE_DIRECT
;
995 ret
= InternetSetOptionW(NULL
, INTERNET_OPTION_PER_CONNECTION_OPTION
,
997 ok(ret
== TRUE
, "InternetSetOption should've succeeded\n");
999 HeapFree(GetProcessHeap(), 0, list
.pOptions
);
1001 /* verify that the proxy is disabled */
1002 list
.dwOptionCount
= 1;
1003 list
.dwOptionError
= 0;
1004 list
.pOptions
= HeapAlloc(GetProcessHeap(), 0, sizeof(INTERNET_PER_CONN_OPTIONW
));
1006 list
.pOptions
[0].dwOption
= INTERNET_PER_CONN_FLAGS
;
1008 ret
= InternetQueryOptionW(NULL
, INTERNET_OPTION_PER_CONNECTION_OPTION
,
1010 ok(ret
== TRUE
, "InternetQueryOption should've succeeded\n");
1011 ok(list
.pOptions
[0].Value
.dwValue
== PROXY_TYPE_DIRECT
,
1012 "Retrieved flags should've been PROXY_TYPE_DIRECT, was: %d\n",
1013 list
.pOptions
[0].Value
.dwValue
);
1014 verifyProxyEnable(0);
1016 HeapFree(GetProcessHeap(), 0, list
.pOptions
);
1018 /* set the proxy flags to 'invalid' value */
1019 list
.dwOptionCount
= 1;
1020 list
.pOptions
= HeapAlloc(GetProcessHeap(), 0, sizeof(INTERNET_PER_CONN_OPTIONW
));
1022 list
.pOptions
[0].dwOption
= INTERNET_PER_CONN_FLAGS
;
1023 list
.pOptions
[0].Value
.dwValue
= PROXY_TYPE_PROXY
| PROXY_TYPE_DIRECT
;
1025 ret
= InternetSetOptionW(NULL
, INTERNET_OPTION_PER_CONNECTION_OPTION
,
1027 ok(ret
== TRUE
, "InternetSetOption should've succeeded\n");
1029 HeapFree(GetProcessHeap(), 0, list
.pOptions
);
1031 /* verify that the proxy is enabled */
1032 list
.dwOptionCount
= 1;
1033 list
.dwOptionError
= 0;
1034 list
.pOptions
= HeapAlloc(GetProcessHeap(), 0, sizeof(INTERNET_PER_CONN_OPTIONW
));
1036 list
.pOptions
[0].dwOption
= INTERNET_PER_CONN_FLAGS
;
1038 ret
= InternetQueryOptionW(NULL
, INTERNET_OPTION_PER_CONNECTION_OPTION
,
1040 ok(ret
== TRUE
, "InternetQueryOption should've succeeded\n");
1041 todo_wine
ok(list
.pOptions
[0].Value
.dwValue
== (PROXY_TYPE_PROXY
| PROXY_TYPE_DIRECT
),
1042 "Retrieved flags should've been PROXY_TYPE_PROXY | PROXY_TYPE_DIRECT, was: %d\n",
1043 list
.pOptions
[0].Value
.dwValue
);
1044 verifyProxyEnable(1);
1046 HeapFree(GetProcessHeap(), 0, list
.pOptions
);
1048 /* restore original settings */
1049 list
.dwOptionCount
= 2;
1050 list
.pOptions
= orig_settings
;
1052 ret
= InternetSetOptionW(NULL
, INTERNET_OPTION_PER_CONNECTION_OPTION
,
1054 ok(ret
== TRUE
, "InternetSetOption should've succeeded\n");
1056 HeapFree(GetProcessHeap(), 0, list
.pOptions
);
1059 static void test_Option_PerConnectionOptionA(void)
1062 DWORD size
= sizeof(INTERNET_PER_CONN_OPTION_LISTA
);
1063 INTERNET_PER_CONN_OPTION_LISTA list
= {size
};
1064 INTERNET_PER_CONN_OPTIONA
*orig_settings
;
1065 char proxy_srv
[] = "proxy.example";
1067 /* get the global IE proxy server info, to restore later */
1068 list
.dwOptionCount
= 2;
1069 list
.pOptions
= HeapAlloc(GetProcessHeap(), 0, 2 * sizeof(INTERNET_PER_CONN_OPTIONA
));
1071 list
.pOptions
[0].dwOption
= INTERNET_PER_CONN_PROXY_SERVER
;
1072 list
.pOptions
[1].dwOption
= INTERNET_PER_CONN_FLAGS
;
1074 ret
= InternetQueryOptionA(NULL
, INTERNET_OPTION_PER_CONNECTION_OPTION
,
1076 ok(ret
== TRUE
, "InternetQueryOption should've succeeded\n");
1077 orig_settings
= list
.pOptions
;
1079 /* set the global IE proxy server */
1080 list
.dwOptionCount
= 2;
1081 list
.pOptions
= HeapAlloc(GetProcessHeap(), 0, 2 * sizeof(INTERNET_PER_CONN_OPTIONA
));
1083 list
.pOptions
[0].dwOption
= INTERNET_PER_CONN_PROXY_SERVER
;
1084 list
.pOptions
[0].Value
.pszValue
= proxy_srv
;
1085 list
.pOptions
[1].dwOption
= INTERNET_PER_CONN_FLAGS
;
1086 list
.pOptions
[1].Value
.dwValue
= PROXY_TYPE_PROXY
;
1088 ret
= InternetSetOptionA(NULL
, INTERNET_OPTION_PER_CONNECTION_OPTION
,
1090 ok(ret
== TRUE
, "InternetSetOption should've succeeded\n");
1092 HeapFree(GetProcessHeap(), 0, list
.pOptions
);
1094 /* get & verify the global IE proxy server */
1095 list
.dwOptionCount
= 2;
1096 list
.dwOptionError
= 0;
1097 list
.pOptions
= HeapAlloc(GetProcessHeap(), 0, 2 * sizeof(INTERNET_PER_CONN_OPTIONA
));
1099 list
.pOptions
[0].dwOption
= INTERNET_PER_CONN_PROXY_SERVER
;
1100 list
.pOptions
[1].dwOption
= INTERNET_PER_CONN_FLAGS
;
1102 ret
= InternetQueryOptionA(NULL
, INTERNET_OPTION_PER_CONNECTION_OPTION
,
1104 ok(ret
== TRUE
, "InternetQueryOption should've succeeded\n");
1105 ok(!lstrcmpA(list
.pOptions
[0].Value
.pszValue
, "proxy.example"),
1106 "Retrieved proxy server should've been \"%s\", was: \"%s\"\n",
1107 proxy_srv
, list
.pOptions
[0].Value
.pszValue
);
1108 ok(list
.pOptions
[1].Value
.dwValue
== PROXY_TYPE_PROXY
,
1109 "Retrieved flags should've been PROXY_TYPE_PROXY, was: %d\n",
1110 list
.pOptions
[1].Value
.dwValue
);
1112 HeapFree(GetProcessHeap(), 0, list
.pOptions
[0].Value
.pszValue
);
1113 HeapFree(GetProcessHeap(), 0, list
.pOptions
);
1115 /* restore original settings */
1116 list
.dwOptionCount
= 2;
1117 list
.pOptions
= orig_settings
;
1119 ret
= InternetSetOptionA(NULL
, INTERNET_OPTION_PER_CONNECTION_OPTION
,
1121 ok(ret
== TRUE
, "InternetSetOption should've succeeded\n");
1123 HeapFree(GetProcessHeap(), 0, list
.pOptions
);
1126 /* ############################### */
1128 START_TEST(internet
)
1131 hdll
= GetModuleHandleA("wininet.dll");
1132 pCreateUrlCacheContainerA
= (void*)GetProcAddress(hdll
, "CreateUrlCacheContainerA");
1133 pCreateUrlCacheContainerW
= (void*)GetProcAddress(hdll
, "CreateUrlCacheContainerW");
1134 pInternetTimeFromSystemTimeA
= (void*)GetProcAddress(hdll
, "InternetTimeFromSystemTimeA");
1135 pInternetTimeFromSystemTimeW
= (void*)GetProcAddress(hdll
, "InternetTimeFromSystemTimeW");
1136 pInternetTimeToSystemTimeA
= (void*)GetProcAddress(hdll
, "InternetTimeToSystemTimeA");
1137 pInternetTimeToSystemTimeW
= (void*)GetProcAddress(hdll
, "InternetTimeToSystemTimeW");
1138 pIsDomainLegalCookieDomainW
= (void*)GetProcAddress(hdll
, (LPCSTR
)117);
1139 pPrivacyGetZonePreferenceW
= (void*)GetProcAddress(hdll
, "PrivacyGetZonePreferenceW");
1140 pPrivacySetZonePreferenceW
= (void*)GetProcAddress(hdll
, "PrivacySetZonePreferenceW");
1142 test_InternetCanonicalizeUrlA();
1143 test_InternetQueryOptionA();
1145 test_complicated_cookie();
1148 test_Option_PerConnectionOption();
1149 test_Option_PerConnectionOptionA();
1151 if (!pInternetTimeFromSystemTimeA
)
1152 win_skip("skipping the InternetTime tests\n");
1155 InternetTimeFromSystemTimeA_test();
1156 InternetTimeFromSystemTimeW_test();
1157 InternetTimeToSystemTimeA_test();
1158 InternetTimeToSystemTimeW_test();
1160 if (pIsDomainLegalCookieDomainW
&&
1161 ((void*)pIsDomainLegalCookieDomainW
== (void*)pCreateUrlCacheContainerA
||
1162 (void*)pIsDomainLegalCookieDomainW
== (void*)pCreateUrlCacheContainerW
))
1163 win_skip("IsDomainLegalCookieDomainW is not available on systems with IE5\n");
1164 else if (!pIsDomainLegalCookieDomainW
)
1165 win_skip("IsDomainLegalCookieDomainW (or ordinal 117) is not available\n");
1167 test_IsDomainLegalCookieDomainW();
1169 if (pPrivacyGetZonePreferenceW
&& pPrivacySetZonePreferenceW
)
1170 test_PrivacyGetSetZonePreferenceW();
1172 win_skip("Privacy[SG]etZonePreferenceW are not available\n");
1174 test_InternetSetOption();