d0ca8eedcb355381f01cb3b4382eeab2ae539f0d
[reactos.git] / rostests / winetests / wininet / internet.c
1 /*
2 * Wininet - internet tests
3 *
4 * Copyright 2005 Vijay Kiran Kamuju
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19 */
20
21 #include <stdarg.h>
22 #include <stdio.h>
23 //#include <string.h>
24
25 #include <windef.h>
26 #include <winbase.h>
27 #include <winuser.h>
28 #include <wininet.h>
29 //#include "winerror.h"
30 #include <winreg.h>
31
32 #include <wine/test.h>
33
34 static BOOL (WINAPI *pCreateUrlCacheContainerA)(DWORD, DWORD, DWORD, DWORD,
35 DWORD, DWORD, DWORD, DWORD);
36 static BOOL (WINAPI *pCreateUrlCacheContainerW)(DWORD, DWORD, DWORD, DWORD,
37 DWORD, DWORD, DWORD, DWORD);
38 static BOOL (WINAPI *pInternetTimeFromSystemTimeA)(const SYSTEMTIME *, DWORD, LPSTR, DWORD);
39 static BOOL (WINAPI *pInternetTimeFromSystemTimeW)(const SYSTEMTIME *, DWORD, LPWSTR, DWORD);
40 static BOOL (WINAPI *pInternetTimeToSystemTimeA)(LPCSTR ,SYSTEMTIME *,DWORD);
41 static BOOL (WINAPI *pInternetTimeToSystemTimeW)(LPCWSTR ,SYSTEMTIME *,DWORD);
42 static BOOL (WINAPI *pIsDomainLegalCookieDomainW)(LPCWSTR, LPCWSTR);
43 static DWORD (WINAPI *pPrivacyGetZonePreferenceW)(DWORD, DWORD, LPDWORD, LPWSTR, LPDWORD);
44 static DWORD (WINAPI *pPrivacySetZonePreferenceW)(DWORD, DWORD, DWORD, LPCWSTR);
45 static BOOL (WINAPI *pInternetGetCookieExA)(LPCSTR,LPCSTR,LPSTR,LPDWORD,DWORD,LPVOID);
46 static BOOL (WINAPI *pInternetGetCookieExW)(LPCWSTR,LPCWSTR,LPWSTR,LPDWORD,DWORD,LPVOID);
47 static BOOL (WINAPI *pInternetGetConnectedStateExA)(LPDWORD,LPSTR,DWORD,DWORD);
48 static BOOL (WINAPI *pInternetGetConnectedStateExW)(LPDWORD,LPWSTR,DWORD,DWORD);
49
50 /* ############################### */
51
52 static void test_InternetCanonicalizeUrlA(void)
53 {
54 CHAR buffer[256];
55 LPCSTR url;
56 DWORD urllen;
57 DWORD dwSize;
58 DWORD res;
59
60 /* Acrobat Updater 5 calls this for Adobe Reader 8.1 */
61 url = "http://swupmf.adobe.com/manifest/50/win/AdobeUpdater.upd";
62 urllen = lstrlenA(url);
63
64 memset(buffer, '#', sizeof(buffer)-1);
65 buffer[sizeof(buffer)-1] = '\0';
66 dwSize = 1; /* Acrobat Updater use this size */
67 SetLastError(0xdeadbeef);
68 res = InternetCanonicalizeUrlA(url, buffer, &dwSize, 0);
69 ok( !res && (GetLastError() == ERROR_INSUFFICIENT_BUFFER) && (dwSize == (urllen+1)),
70 "got %u and %u with size %u for '%s' (%d)\n",
71 res, GetLastError(), dwSize, buffer, lstrlenA(buffer));
72
73
74 /* buffer has no space for the terminating '\0' */
75 memset(buffer, '#', sizeof(buffer)-1);
76 buffer[sizeof(buffer)-1] = '\0';
77 dwSize = urllen;
78 SetLastError(0xdeadbeef);
79 res = InternetCanonicalizeUrlA(url, buffer, &dwSize, 0);
80 /* dwSize is nr. of needed bytes with the terminating '\0' */
81 ok( !res && (GetLastError() == ERROR_INSUFFICIENT_BUFFER) && (dwSize == (urllen+1)),
82 "got %u and %u with size %u for '%s' (%d)\n",
83 res, GetLastError(), dwSize, buffer, lstrlenA(buffer));
84
85 /* buffer has the required size */
86 memset(buffer, '#', sizeof(buffer)-1);
87 buffer[sizeof(buffer)-1] = '\0';
88 dwSize = urllen+1;
89 SetLastError(0xdeadbeef);
90 res = InternetCanonicalizeUrlA(url, buffer, &dwSize, 0);
91 /* dwSize is nr. of copied bytes without the terminating '\0' */
92 ok( res && (dwSize == urllen) && (lstrcmpA(url, buffer) == 0),
93 "got %u and %u with size %u for '%s' (%d)\n",
94 res, GetLastError(), dwSize, buffer, lstrlenA(buffer));
95
96 memset(buffer, '#', sizeof(buffer)-1);
97 buffer[sizeof(buffer)-1] = '\0';
98 dwSize = sizeof(buffer);
99 SetLastError(0xdeadbeef);
100 res = InternetCanonicalizeUrlA("file:///C:/Program%20Files/Atmel/AVR%20Tools/STK500/STK500.xml", buffer, &dwSize, ICU_DECODE | ICU_NO_ENCODE);
101 ok(res, "InternetCanonicalizeUrlA failed %u\n", GetLastError());
102 ok(dwSize == lstrlenA(buffer), "got %d expected %d\n", dwSize, lstrlenA(buffer));
103 ok(!lstrcmpA("file://C:\\Program Files\\Atmel\\AVR Tools\\STK500\\STK500.xml", buffer),
104 "got %s expected 'file://C:\\Program Files\\Atmel\\AVR Tools\\STK500\\STK500.xml'\n", buffer);
105
106 /* buffer is larger as the required size */
107 memset(buffer, '#', sizeof(buffer)-1);
108 buffer[sizeof(buffer)-1] = '\0';
109 dwSize = urllen+2;
110 SetLastError(0xdeadbeef);
111 res = InternetCanonicalizeUrlA(url, buffer, &dwSize, 0);
112 /* dwSize is nr. of copied bytes without the terminating '\0' */
113 ok( res && (dwSize == urllen) && (lstrcmpA(url, buffer) == 0),
114 "got %u and %u with size %u for '%s' (%d)\n",
115 res, GetLastError(), dwSize, buffer, lstrlenA(buffer));
116
117
118 /* check NULL pointers */
119 memset(buffer, '#', urllen + 4);
120 buffer[urllen + 4] = '\0';
121 dwSize = urllen+1;
122 SetLastError(0xdeadbeef);
123 res = InternetCanonicalizeUrlA(NULL, buffer, &dwSize, 0);
124 ok( !res && (GetLastError() == ERROR_INVALID_PARAMETER),
125 "got %u and %u with size %u for '%s' (%d)\n",
126 res, GetLastError(), dwSize, buffer, lstrlenA(buffer));
127
128 memset(buffer, '#', urllen + 4);
129 buffer[urllen + 4] = '\0';
130 dwSize = urllen+1;
131 SetLastError(0xdeadbeef);
132 res = InternetCanonicalizeUrlA(url, NULL, &dwSize, 0);
133 ok( !res && (GetLastError() == ERROR_INVALID_PARAMETER),
134 "got %u and %u with size %u for '%s' (%d)\n",
135 res, GetLastError(), dwSize, buffer, lstrlenA(buffer));
136
137 memset(buffer, '#', urllen + 4);
138 buffer[urllen + 4] = '\0';
139 dwSize = urllen+1;
140 SetLastError(0xdeadbeef);
141 res = InternetCanonicalizeUrlA(url, buffer, NULL, 0);
142 ok( !res && (GetLastError() == ERROR_INVALID_PARAMETER),
143 "got %u and %u with size %u for '%s' (%d)\n",
144 res, GetLastError(), dwSize, buffer, lstrlenA(buffer));
145
146 /* test with trailing space */
147 dwSize = 256;
148 res = InternetCanonicalizeUrlA("http://www.winehq.org/index.php?x= ", buffer, &dwSize, ICU_BROWSER_MODE);
149 ok(res == 1, "InternetCanonicalizeUrlA failed\n");
150 ok(!strcmp(buffer, "http://www.winehq.org/index.php?x="), "Trailing space should have been stripped even in ICU_BROWSER_MODE (%s)\n", buffer);
151
152 res = InternetSetOptionA(NULL, 0xdeadbeef, buffer, sizeof(buffer));
153 ok(!res, "InternetSetOptionA succeeded\n");
154 ok(GetLastError() == ERROR_INTERNET_INVALID_OPTION,
155 "InternetSetOptionA failed %u, expected ERROR_INTERNET_INVALID_OPTION\n", GetLastError());
156 }
157
158 /* ############################### */
159
160 static void test_InternetQueryOptionA(void)
161 {
162 HINTERNET hinet,hurl;
163 DWORD len, val;
164 DWORD err;
165 static const char useragent[] = {"Wininet Test"};
166 char *buffer;
167 int retval;
168 BOOL res;
169
170 SetLastError(0xdeadbeef);
171 len = 0xdeadbeef;
172 retval = InternetQueryOptionA(NULL, INTERNET_OPTION_PROXY, NULL, &len);
173 ok(!retval && GetLastError() == ERROR_INSUFFICIENT_BUFFER, "Got wrong error %x(%u)\n", retval, GetLastError());
174 ok(len >= sizeof(INTERNET_PROXY_INFOA) && len != 0xdeadbeef,"len = %u\n", len);
175
176 hinet = InternetOpenA(useragent,INTERNET_OPEN_TYPE_DIRECT,NULL,NULL, 0);
177 ok((hinet != 0x0),"InternetOpen Failed\n");
178
179 SetLastError(0xdeadbeef);
180 retval=InternetQueryOptionA(NULL,INTERNET_OPTION_USER_AGENT,NULL,&len);
181 err=GetLastError();
182 ok(retval == 0,"Got wrong return value %d\n",retval);
183 ok(err == ERROR_INTERNET_INCORRECT_HANDLE_TYPE, "Got wrong error code%d\n",err);
184
185 SetLastError(0xdeadbeef);
186 len=strlen(useragent)+1;
187 retval=InternetQueryOptionA(hinet,INTERNET_OPTION_USER_AGENT,NULL,&len);
188 err=GetLastError();
189 ok(len == strlen(useragent)+1,"Got wrong user agent length %d instead of %d\n",len,lstrlenA(useragent));
190 ok(retval == 0,"Got wrong return value %d\n",retval);
191 ok(err == ERROR_INSUFFICIENT_BUFFER, "Got wrong error code %d\n",err);
192
193 len=strlen(useragent)+1;
194 buffer=HeapAlloc(GetProcessHeap(),0,len);
195 retval=InternetQueryOptionA(hinet,INTERNET_OPTION_USER_AGENT,buffer,&len);
196 ok(retval == 1,"Got wrong return value %d\n",retval);
197 if (retval)
198 {
199 ok(!strcmp(useragent,buffer),"Got wrong user agent string %s instead of %s\n",buffer,useragent);
200 ok(len == strlen(useragent),"Got wrong user agent length %d instead of %d\n",len,lstrlenA(useragent));
201 }
202 HeapFree(GetProcessHeap(),0,buffer);
203
204 SetLastError(0xdeadbeef);
205 len=0;
206 buffer=HeapAlloc(GetProcessHeap(),0,100);
207 retval=InternetQueryOptionA(hinet,INTERNET_OPTION_USER_AGENT,buffer,&len);
208 err=GetLastError();
209 ok(len == strlen(useragent) + 1,"Got wrong user agent length %d instead of %d\n", len, lstrlenA(useragent) + 1);
210 ok(!retval, "Got wrong return value %d\n", retval);
211 ok(err == ERROR_INSUFFICIENT_BUFFER, "Got wrong error code %d\n", err);
212 HeapFree(GetProcessHeap(),0,buffer);
213
214 hurl = InternetConnectA(hinet,"www.winehq.org",INTERNET_DEFAULT_HTTP_PORT,NULL,NULL,INTERNET_SERVICE_HTTP,0,0);
215
216 SetLastError(0xdeadbeef);
217 len=0;
218 retval = InternetQueryOptionA(hurl,INTERNET_OPTION_USER_AGENT,NULL,&len);
219 err=GetLastError();
220 ok(len == 0,"Got wrong user agent length %d instead of 0\n",len);
221 ok(retval == 0,"Got wrong return value %d\n",retval);
222 ok(err == ERROR_INTERNET_INCORRECT_HANDLE_TYPE, "Got wrong error code %d\n",err);
223
224 SetLastError(0xdeadbeef);
225 len = sizeof(DWORD);
226 retval = InternetQueryOptionA(hurl,INTERNET_OPTION_REQUEST_FLAGS,NULL,&len);
227 err = GetLastError();
228 ok(retval == 0,"Got wrong return value %d\n",retval);
229 ok(err == ERROR_INTERNET_INCORRECT_HANDLE_TYPE, "Got wrong error code %d\n",err);
230 ok(len == sizeof(DWORD), "len = %d\n", len);
231
232 SetLastError(0xdeadbeef);
233 len = sizeof(DWORD);
234 retval = InternetQueryOptionA(NULL,INTERNET_OPTION_REQUEST_FLAGS,NULL,&len);
235 err = GetLastError();
236 ok(retval == 0,"Got wrong return value %d\n",retval);
237 ok(err == ERROR_INTERNET_INCORRECT_HANDLE_TYPE, "Got wrong error code %d\n",err);
238 ok(!len, "len = %d\n", len);
239
240 InternetCloseHandle(hurl);
241 InternetCloseHandle(hinet);
242
243 hinet = InternetOpenA("",INTERNET_OPEN_TYPE_DIRECT,NULL,NULL, 0);
244 ok((hinet != 0x0),"InternetOpen Failed\n");
245
246 SetLastError(0xdeadbeef);
247 len=0;
248 retval=InternetQueryOptionA(hinet,INTERNET_OPTION_USER_AGENT,NULL,&len);
249 err=GetLastError();
250 ok(len == 1,"Got wrong user agent length %d instead of %d\n",len,1);
251 ok(retval == 0,"Got wrong return value %d\n",retval);
252 ok(err == ERROR_INSUFFICIENT_BUFFER, "Got wrong error code%d\n",err);
253
254 InternetCloseHandle(hinet);
255
256 val = 12345;
257 res = InternetSetOptionA(NULL, INTERNET_OPTION_CONNECT_TIMEOUT, &val, sizeof(val));
258 ok(res, "InternetSetOptionA(INTERNET_OPTION_CONNECT_TIMEOUT) failed (%u)\n", GetLastError());
259
260 len = sizeof(val);
261 res = InternetQueryOptionA(NULL, INTERNET_OPTION_CONNECT_TIMEOUT, &val, &len);
262 ok(res, "InternetQueryOptionA failed %d)\n", GetLastError());
263 ok(val == 12345, "val = %d\n", val);
264 ok(len == sizeof(val), "len = %d\n", len);
265
266 hinet = InternetOpenA(NULL,INTERNET_OPEN_TYPE_DIRECT,NULL,NULL, 0);
267 ok((hinet != 0x0),"InternetOpen Failed\n");
268 SetLastError(0xdeadbeef);
269 len=0;
270 retval=InternetQueryOptionA(hinet,INTERNET_OPTION_USER_AGENT,NULL,&len);
271 err=GetLastError();
272 ok(len == 1,"Got wrong user agent length %d instead of %d\n",len,1);
273 ok(retval == 0,"Got wrong return value %d\n",retval);
274 ok(err == ERROR_INSUFFICIENT_BUFFER, "Got wrong error code%d\n",err);
275
276 len = sizeof(val);
277 val = 0xdeadbeef;
278 res = InternetQueryOptionA(hinet, INTERNET_OPTION_MAX_CONNS_PER_SERVER, &val, &len);
279 ok(!res, "InternetQueryOptionA(INTERNET_OPTION_MAX_CONNS_PER_SERVER) succeeded\n");
280 ok(GetLastError() == ERROR_INTERNET_INVALID_OPERATION, "GetLastError() = %u\n", GetLastError());
281
282 val = 2;
283 res = InternetSetOptionA(hinet, INTERNET_OPTION_MAX_CONNS_PER_SERVER, &val, sizeof(val));
284 ok(!res, "InternetSetOptionA(INTERNET_OPTION_MAX_CONNS_PER_SERVER) succeeded\n");
285 ok(GetLastError() == ERROR_INTERNET_INVALID_OPERATION, "GetLastError() = %u\n", GetLastError());
286
287 len = sizeof(val);
288 res = InternetQueryOptionA(hinet, INTERNET_OPTION_CONNECT_TIMEOUT, &val, &len);
289 ok(res, "InternetQueryOptionA failed %d)\n", GetLastError());
290 ok(val == 12345, "val = %d\n", val);
291 ok(len == sizeof(val), "len = %d\n", len);
292
293 val = 1;
294 res = InternetSetOptionA(hinet, INTERNET_OPTION_CONNECT_TIMEOUT, &val, sizeof(val));
295 ok(res, "InternetSetOptionA(INTERNET_OPTION_CONNECT_TIMEOUT) failed (%u)\n", GetLastError());
296
297 len = sizeof(val);
298 res = InternetQueryOptionA(hinet, INTERNET_OPTION_CONNECT_TIMEOUT, &val, &len);
299 ok(res, "InternetQueryOptionA failed %d)\n", GetLastError());
300 ok(val == 1, "val = %d\n", val);
301 ok(len == sizeof(val), "len = %d\n", len);
302
303 len = sizeof(val);
304 res = InternetQueryOptionA(NULL, INTERNET_OPTION_CONNECT_TIMEOUT, &val, &len);
305 ok(res, "InternetQueryOptionA failed %d)\n", GetLastError());
306 ok(val == 12345, "val = %d\n", val);
307 ok(len == sizeof(val), "len = %d\n", len);
308
309 InternetCloseHandle(hinet);
310 }
311
312 static void test_max_conns(void)
313 {
314 DWORD len, val;
315 BOOL res;
316
317 len = sizeof(val);
318 val = 0xdeadbeef;
319 res = InternetQueryOptionA(NULL, INTERNET_OPTION_MAX_CONNS_PER_SERVER, &val, &len);
320 ok(res,"Got wrong return value %x\n", res);
321 ok(len == sizeof(val), "got %d\n", len);
322 trace("INTERNET_OPTION_MAX_CONNS_PER_SERVER: %d\n", val);
323
324 len = sizeof(val);
325 val = 0xdeadbeef;
326 res = InternetQueryOptionA(NULL, INTERNET_OPTION_MAX_CONNS_PER_1_0_SERVER, &val, &len);
327 ok(res,"Got wrong return value %x\n", res);
328 ok(len == sizeof(val), "got %d\n", len);
329 trace("INTERNET_OPTION_MAX_CONNS_PER_1_0_SERVER: %d\n", val);
330
331 val = 3;
332 res = InternetSetOptionA(NULL, INTERNET_OPTION_MAX_CONNS_PER_SERVER, &val, sizeof(val));
333 ok(res, "InternetSetOptionA(INTERNET_OPTION_MAX_CONNS_PER_SERVER) failed: %x\n", res);
334
335 len = sizeof(val);
336 val = 0xdeadbeef;
337 res = InternetQueryOptionA(NULL, INTERNET_OPTION_MAX_CONNS_PER_SERVER, &val, &len);
338 ok(res,"Got wrong return value %x\n", res);
339 ok(len == sizeof(val), "got %d\n", len);
340 ok(val == 3, "got %d\n", val);
341
342 val = 0;
343 res = InternetSetOptionA(NULL, INTERNET_OPTION_MAX_CONNS_PER_SERVER, &val, sizeof(val));
344 ok(!res || broken(res), /* <= w2k3 */
345 "InternetSetOptionA(INTERNET_OPTION_MAX_CONNS_PER_SERVER, 0) succeeded\n");
346 if (!res) ok(GetLastError() == ERROR_BAD_ARGUMENTS, "GetLastError() = %u\n", GetLastError());
347
348 val = 2;
349 res = InternetSetOptionA(NULL, INTERNET_OPTION_MAX_CONNS_PER_SERVER, &val, sizeof(val)-1);
350 ok(!res, "InternetSetOptionA(INTERNET_OPTION_MAX_CONNS_PER_SERVER) succeeded\n");
351 ok(GetLastError() == ERROR_INTERNET_BAD_OPTION_LENGTH, "GetLastError() = %u\n", GetLastError());
352
353 val = 2;
354 res = InternetSetOptionA(NULL, INTERNET_OPTION_MAX_CONNS_PER_SERVER, &val, sizeof(val)+1);
355 ok(!res, "InternetSetOptionA(INTERNET_OPTION_MAX_CONNS_PER_SERVER) succeeded\n");
356 ok(GetLastError() == ERROR_INTERNET_BAD_OPTION_LENGTH, "GetLastError() = %u\n", GetLastError());
357 }
358
359 static void test_get_cookie(void)
360 {
361 DWORD len;
362 BOOL ret;
363
364 SetLastError(0xdeadbeef);
365 ret = InternetGetCookieA("http://www.example.com", NULL, NULL, &len);
366 ok(!ret && GetLastError() == ERROR_NO_MORE_ITEMS,
367 "InternetGetCookie should have failed with %s and error %d\n",
368 ret ? "TRUE" : "FALSE", GetLastError());
369 }
370
371
372 static void test_complicated_cookie(void)
373 {
374 DWORD len;
375 BOOL ret;
376
377 CHAR buffer[1024];
378 CHAR user[256];
379 WCHAR wbuf[1024];
380
381 static const WCHAR testing_example_comW[] =
382 {'h','t','t','p',':','/','/','t','e','s','t','i','n','g','.','e','x','a','m','p','l','e','.','c','o','m',0};
383
384 ret = InternetSetCookieA("http://www.example.com/bar",NULL,"A=B; domain=.example.com");
385 ok(ret == TRUE,"InternetSetCookie failed\n");
386 ret = InternetSetCookieA("http://www.example.com/bar",NULL,"C=D; domain=.example.com; path=/");
387 ok(ret == TRUE,"InternetSetCookie failed\n");
388
389 /* Technically illegal! domain should require 2 dots, but native wininet accepts it */
390 ret = InternetSetCookieA("http://www.example.com",NULL,"E=F; domain=example.com");
391 ok(ret == TRUE,"InternetSetCookie failed\n");
392 ret = InternetSetCookieA("http://www.example.com",NULL,"G=H; domain=.example.com; path=/foo");
393 ok(ret == TRUE,"InternetSetCookie failed\n");
394 ret = InternetSetCookieA("http://www.example.com/bar.html",NULL,"I=J; domain=.example.com");
395 ok(ret == TRUE,"InternetSetCookie failed\n");
396 ret = InternetSetCookieA("http://www.example.com/bar/",NULL,"K=L; domain=.example.com");
397 ok(ret == TRUE,"InternetSetCookie failed\n");
398 ret = InternetSetCookieA("http://www.example.com/bar/",NULL,"M=N; domain=.example.com; path=/foo/");
399 ok(ret == TRUE,"InternetSetCookie failed\n");
400 ret = InternetSetCookieA("http://www.example.com/bar/",NULL,"O=P; secure; path=/bar");
401 ok(ret == TRUE,"InternetSetCookie failed\n");
402
403 len = 1024;
404 ret = InternetGetCookieA("http://testing.example.com", NULL, NULL, &len);
405 ok(ret == TRUE,"InternetGetCookie failed\n");
406 ok(len == 19, "len = %u\n", len);
407
408 len = 1024;
409 memset(buffer, 0xac, sizeof(buffer));
410 ret = InternetGetCookieA("http://testing.example.com", NULL, buffer, &len);
411 ok(ret == TRUE,"InternetGetCookie failed\n");
412 ok(len == 19, "len = %u\n", len);
413 ok(strlen(buffer) == 18, "strlen(buffer) = %u\n", lstrlenA(buffer));
414 ok(strstr(buffer,"A=B")!=NULL,"A=B missing\n");
415 ok(strstr(buffer,"C=D")!=NULL,"C=D missing\n");
416 ok(strstr(buffer,"E=F")!=NULL,"E=F missing\n");
417 ok(strstr(buffer,"G=H")==NULL,"G=H present\n");
418 ok(strstr(buffer,"I=J")!=NULL,"I=J missing\n");
419 ok(strstr(buffer,"K=L")==NULL,"K=L present\n");
420 ok(strstr(buffer,"M=N")==NULL,"M=N present\n");
421 ok(strstr(buffer,"O=P")==NULL,"O=P present\n");
422
423 len = 10;
424 memset(buffer, 0xac, sizeof(buffer));
425 ret = InternetGetCookieA("http://testing.example.com", NULL, buffer, &len);
426 ok(!ret && GetLastError() == ERROR_INSUFFICIENT_BUFFER,
427 "InternetGetCookie returned: %x(%u), expected ERROR_INSUFFICIENT_BUFFER\n", ret, GetLastError());
428 ok(len == 19, "len = %u\n", len);
429
430 len = 1024;
431 ret = InternetGetCookieW(testing_example_comW, NULL, NULL, &len);
432 ok(ret == TRUE,"InternetGetCookieW failed\n");
433 ok(len == 38, "len = %u\n", len);
434
435 len = 1024;
436 memset(wbuf, 0xac, sizeof(wbuf));
437 ret = InternetGetCookieW(testing_example_comW, NULL, wbuf, &len);
438 ok(ret == TRUE,"InternetGetCookieW failed\n");
439 ok(len == 19 || broken(len==18), "len = %u\n", len);
440 ok(lstrlenW(wbuf) == 18, "strlenW(wbuf) = %u\n", lstrlenW(wbuf));
441
442 len = 10;
443 memset(wbuf, 0xac, sizeof(wbuf));
444 ret = InternetGetCookieW(testing_example_comW, NULL, wbuf, &len);
445 ok(!ret && GetLastError() == ERROR_INSUFFICIENT_BUFFER,
446 "InternetGetCookieW returned: %x(%u), expected ERROR_INSUFFICIENT_BUFFER\n", ret, GetLastError());
447 ok(len == 38, "len = %u\n", len);
448
449 len = 1024;
450 ret = InternetGetCookieA("http://testing.example.com/foobar", NULL, buffer, &len);
451 ok(ret == TRUE,"InternetGetCookie failed\n");
452 ok(strstr(buffer,"A=B")!=NULL,"A=B missing\n");
453 ok(strstr(buffer,"C=D")!=NULL,"C=D missing\n");
454 ok(strstr(buffer,"E=F")!=NULL,"E=F missing\n");
455 ok(strstr(buffer,"G=H")==NULL,"G=H present\n");
456 ok(strstr(buffer,"I=J")!=NULL,"I=J missing\n");
457 ok(strstr(buffer,"K=L")==NULL,"K=L present\n");
458 ok(strstr(buffer,"M=N")==NULL,"M=N present\n");
459 ok(strstr(buffer,"O=P")==NULL,"O=P present\n");
460
461 len = 1024;
462 ret = InternetGetCookieA("http://testing.example.com/foobar/", NULL, buffer, &len);
463 ok(ret == TRUE,"InternetGetCookie failed\n");
464 ok(strstr(buffer,"A=B")!=NULL,"A=B missing\n");
465 ok(strstr(buffer,"C=D")!=NULL,"C=D missing\n");
466 ok(strstr(buffer,"E=F")!=NULL,"E=F missing\n");
467 ok(strstr(buffer,"G=H")!=NULL,"G=H missing\n");
468 ok(strstr(buffer,"I=J")!=NULL,"I=J missing\n");
469 ok(strstr(buffer,"K=L")==NULL,"K=L present\n");
470 ok(strstr(buffer,"M=N")==NULL,"M=N present\n");
471 ok(strstr(buffer,"O=P")==NULL,"O=P present\n");
472
473 len = 1024;
474 ret = InternetGetCookieA("http://testing.example.com/foo/bar", NULL, buffer, &len);
475 ok(ret == TRUE,"InternetGetCookie failed\n");
476 ok(strstr(buffer,"A=B")!=NULL,"A=B missing\n");
477 ok(strstr(buffer,"C=D")!=NULL,"C=D missing\n");
478 ok(strstr(buffer,"E=F")!=NULL,"E=F missing\n");
479 ok(strstr(buffer,"G=H")!=NULL,"G=H missing\n");
480 ok(strstr(buffer,"I=J")!=NULL,"I=J missing\n");
481 ok(strstr(buffer,"K=L")==NULL,"K=L present\n");
482 ok(strstr(buffer,"M=N")!=NULL,"M=N missing\n");
483 ok(strstr(buffer,"O=P")==NULL,"O=P present\n");
484
485 len = 1024;
486 ret = InternetGetCookieA("http://testing.example.com/barfoo", NULL, buffer, &len);
487 ok(ret == TRUE,"InternetGetCookie failed\n");
488 ok(strstr(buffer,"A=B")!=NULL,"A=B missing\n");
489 ok(strstr(buffer,"C=D")!=NULL,"C=D missing\n");
490 ok(strstr(buffer,"E=F")!=NULL,"E=F missing\n");
491 ok(strstr(buffer,"G=H")==NULL,"G=H present\n");
492 ok(strstr(buffer,"I=J")!=NULL,"I=J missing\n");
493 ok(strstr(buffer,"K=L")==NULL,"K=L present\n");
494 ok(strstr(buffer,"M=N")==NULL,"M=N present\n");
495 ok(strstr(buffer,"O=P")==NULL,"O=P present\n");
496
497 len = 1024;
498 ret = InternetGetCookieA("http://testing.example.com/barfoo/", NULL, buffer, &len);
499 ok(ret == TRUE,"InternetGetCookie failed\n");
500 ok(strstr(buffer,"A=B")!=NULL,"A=B missing\n");
501 ok(strstr(buffer,"C=D")!=NULL,"C=D missing\n");
502 ok(strstr(buffer,"E=F")!=NULL,"E=F missing\n");
503 ok(strstr(buffer,"G=H")==NULL,"G=H present\n");
504 ok(strstr(buffer,"I=J")!=NULL,"I=J missing\n");
505 ok(strstr(buffer,"K=L")==NULL,"K=L present\n");
506 ok(strstr(buffer,"M=N")==NULL,"M=N present\n");
507 ok(strstr(buffer,"O=P")==NULL,"O=P present\n");
508
509 len = 1024;
510 ret = InternetGetCookieA("http://testing.example.com/bar/foo", NULL, buffer, &len);
511 ok(ret == TRUE,"InternetGetCookie failed\n");
512 ok(len == 24, "len = %u\n", 24);
513 ok(strstr(buffer,"A=B")!=NULL,"A=B missing\n");
514 ok(strstr(buffer,"C=D")!=NULL,"C=D missing\n");
515 ok(strstr(buffer,"E=F")!=NULL,"E=F missing\n");
516 ok(strstr(buffer,"G=H")==NULL,"G=H present\n");
517 ok(strstr(buffer,"I=J")!=NULL,"I=J missing\n");
518 ok(strstr(buffer,"K=L")!=NULL,"K=L missing\n");
519 ok(strstr(buffer,"M=N")==NULL,"M=N present\n");
520 ok(strstr(buffer,"O=P")==NULL,"O=P present\n");
521
522 /* Cookie name argument is not implemented */
523 len = 1024;
524 ret = InternetGetCookieA("http://testing.example.com/bar/foo", "A", buffer, &len);
525 ok(ret == TRUE,"InternetGetCookie failed\n");
526 ok(len == 24, "len = %u\n", 24);
527
528 /* test persistent cookies */
529 ret = InternetSetCookieA("http://testing.example.com", NULL, "A=B; expires=Fri, 01-Jan-2038 00:00:00 GMT");
530 ok(ret, "InternetSetCookie failed with error %d\n", GetLastError());
531
532 len = sizeof(user);
533 ret = GetUserNameA(user, &len);
534 ok(ret, "GetUserName failed with error %d\n", GetLastError());
535 for(; len>0; len--)
536 user[len-1] = tolower(user[len-1]);
537
538 sprintf(buffer, "Cookie:%s@testing.example.com/", user);
539 ret = GetUrlCacheEntryInfoA(buffer, NULL, &len);
540 ok(!ret, "GetUrlCacheEntryInfo succeeded\n");
541 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER, "GetLastError() = %d\n", GetLastError());
542
543 /* remove persistent cookie */
544 ret = InternetSetCookieA("http://testing.example.com", NULL, "A=B");
545 ok(ret, "InternetSetCookie failed with error %d\n", GetLastError());
546
547 ret = GetUrlCacheEntryInfoA(buffer, NULL, &len);
548 ok(!ret, "GetUrlCacheEntryInfo succeeded\n");
549 ok(GetLastError() == ERROR_FILE_NOT_FOUND, "GetLastError() = %d\n", GetLastError());
550
551 /* try setting cookie for different domain */
552 ret = InternetSetCookieA("http://www.aaa.example.com/bar",NULL,"E=F; domain=different.com");
553 ok(!ret, "InternetSetCookie succeeded\n");
554 ok(GetLastError() == ERROR_INVALID_PARAMETER, "GetLastError() = %d\n", GetLastError());
555 ret = InternetSetCookieA("http://www.aaa.example.com.pl/bar",NULL,"E=F; domain=example.com.pl");
556 ok(ret, "InternetSetCookie failed with error: %d\n", GetLastError());
557 ret = InternetSetCookieA("http://www.aaa.example.com.pl/bar",NULL,"E=F; domain=com.pl");
558 todo_wine ok(!ret, "InternetSetCookie succeeded\n");
559 }
560
561 static void test_cookie_attrs(void)
562 {
563 char buf[100];
564 DWORD size, state;
565 BOOL ret;
566
567 if(!GetProcAddress(GetModuleHandleA("wininet.dll"), "InternetGetSecurityInfoByURLA")) {
568 win_skip("Skipping cookie attributes tests. Too old IE.\n");
569 return;
570 }
571
572 ret = InternetSetCookieA("http://cookie.attrs.com/bar", NULL, "A=data; httponly");
573 ok(!ret && GetLastError() == ERROR_INVALID_OPERATION, "InternetSetCookie returned: %x (%u)\n", ret, GetLastError());
574
575 SetLastError(0xdeadbeef);
576 state = InternetSetCookieExA("http://cookie.attrs.com/bar", NULL, "A=data; httponly", 0, 0);
577 ok(state == COOKIE_STATE_REJECT && GetLastError() == ERROR_INVALID_OPERATION,
578 "InternetSetCookieEx returned: %x (%u)\n", ret, GetLastError());
579
580 size = sizeof(buf);
581 ret = InternetGetCookieExA("http://cookie.attrs.com/", NULL, buf, &size, INTERNET_COOKIE_HTTPONLY, NULL);
582 ok(!ret && GetLastError() == ERROR_NO_MORE_ITEMS, "InternetGetCookieEx returned: %x (%u)\n", ret, GetLastError());
583
584 state = InternetSetCookieExA("http://cookie.attrs.com/bar",NULL,"A=data; httponly", INTERNET_COOKIE_HTTPONLY, 0);
585 ok(state == COOKIE_STATE_ACCEPT,"InternetSetCookieEx failed: %u\n", GetLastError());
586
587 size = sizeof(buf);
588 ret = InternetGetCookieA("http://cookie.attrs.com/", NULL, buf, &size);
589 ok(!ret && GetLastError() == ERROR_NO_MORE_ITEMS, "InternetGetCookie returned: %x (%u)\n", ret, GetLastError());
590
591 size = sizeof(buf);
592 ret = InternetGetCookieExA("http://cookie.attrs.com/", NULL, buf, &size, 0, NULL);
593 ok(!ret && GetLastError() == ERROR_NO_MORE_ITEMS, "InternetGetCookieEx returned: %x (%u)\n", ret, GetLastError());
594
595 size = sizeof(buf);
596 ret = InternetGetCookieExA("http://cookie.attrs.com/", NULL, buf, &size, INTERNET_COOKIE_HTTPONLY, NULL);
597 ok(ret, "InternetGetCookieEx failed: %u\n", GetLastError());
598 ok(!strcmp(buf, "A=data"), "data = %s\n", buf);
599
600 /* Try to override httponly cookie with non-httponly one */
601 ret = InternetSetCookieA("http://cookie.attrs.com/bar", NULL, "A=test");
602 ok(!ret && GetLastError() == ERROR_INVALID_OPERATION, "InternetSetCookie returned: %x (%u)\n", ret, GetLastError());
603
604 SetLastError(0xdeadbeef);
605 state = InternetSetCookieExA("http://cookie.attrs.com/bar", NULL, "A=data", 0, 0);
606 ok(state == COOKIE_STATE_REJECT && GetLastError() == ERROR_INVALID_OPERATION,
607 "InternetSetCookieEx returned: %x (%u)\n", ret, GetLastError());
608
609 size = sizeof(buf);
610 ret = InternetGetCookieExA("http://cookie.attrs.com/", NULL, buf, &size, INTERNET_COOKIE_HTTPONLY, NULL);
611 ok(ret, "InternetGetCookieEx failed: %u\n", GetLastError());
612 ok(!strcmp(buf, "A=data"), "data = %s\n", buf);
613
614 }
615
616 static void test_cookie_url(void)
617 {
618 char long_url[5000] = "http://long.url.test.com/", *p;
619 WCHAR bufw[512];
620 char buf[512];
621 DWORD len;
622 BOOL res;
623
624 static const WCHAR about_blankW[] = {'a','b','o','u','t',':','b','l','a','n','k',0};
625
626 len = sizeof(buf);
627 res = InternetGetCookieA("about:blank", NULL, buf, &len);
628 ok(!res && GetLastError() == ERROR_INVALID_PARAMETER,
629 "InternetGetCookeA failed: %u, expected ERROR_INVALID_PARAMETER\n", GetLastError());
630
631 len = sizeof(bufw)/sizeof(*bufw);
632 res = InternetGetCookieW(about_blankW, NULL, bufw, &len);
633 ok(!res && GetLastError() == ERROR_INVALID_PARAMETER,
634 "InternetGetCookeW failed: %u, expected ERROR_INVALID_PARAMETER\n", GetLastError());
635
636 len = sizeof(buf);
637 res = pInternetGetCookieExA("about:blank", NULL, buf, &len, 0, NULL);
638 ok(!res && GetLastError() == ERROR_INVALID_PARAMETER,
639 "InternetGetCookeExA failed: %u, expected ERROR_INVALID_PARAMETER\n", GetLastError());
640
641 len = sizeof(bufw)/sizeof(*bufw);
642 res = pInternetGetCookieExW(about_blankW, NULL, bufw, &len, 0, NULL);
643 ok(!res && GetLastError() == ERROR_INVALID_PARAMETER,
644 "InternetGetCookeExW failed: %u, expected ERROR_INVALID_PARAMETER\n", GetLastError());
645
646 p = long_url + strlen(long_url);
647 memset(p, 'x', long_url+sizeof(long_url)-p);
648 p += (long_url+sizeof(long_url)-p) - 3;
649 p[0] = '/';
650 p[2] = 0;
651 res = InternetSetCookieA(long_url, NULL, "A=B");
652 ok(res, "InternetSetCookieA failed: %u\n", GetLastError());
653
654 len = sizeof(buf);
655 res = InternetGetCookieA(long_url, NULL, buf, &len);
656 ok(res, "InternetGetCookieA failed: %u\n", GetLastError());
657 ok(!strcmp(buf, "A=B"), "buf = %s\n", buf);
658
659 len = sizeof(buf);
660 res = InternetGetCookieA("http://long.url.test.com/", NULL, buf, &len);
661 ok(!res && GetLastError() == ERROR_NO_MORE_ITEMS, "InternetGetCookieA failed: %u\n", GetLastError());
662 }
663
664 static void test_null(void)
665 {
666 HINTERNET hi, hc;
667 static const WCHAR szServer[] = { 's','e','r','v','e','r',0 };
668 static const WCHAR szServer2[] = { 's','e','r','v','e','r','=',0 };
669 static const WCHAR szEmpty[] = { 0 };
670 static const WCHAR szUrl[] = { 'h','t','t','p',':','/','/','a','.','b','.','c',0 };
671 static const WCHAR szUrlEmpty[] = { 'h','t','t','p',':','/','/',0 };
672 static const WCHAR szExpect[] = { 's','e','r','v','e','r',';',' ','s','e','r','v','e','r',0 };
673 WCHAR buffer[0x20];
674 BOOL r;
675 DWORD sz;
676
677 SetLastError(0xdeadbeef);
678 hi = InternetOpenW(NULL, 0, NULL, NULL, 0);
679 if (hi == NULL && GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)
680 {
681 win_skip("Internet*W functions are not implemented\n");
682 return;
683 }
684 ok(hi != NULL, "open failed\n");
685
686 hc = InternetConnectW(hi, NULL, 0, NULL, NULL, 0, 0, 0);
687 ok(GetLastError() == ERROR_INVALID_PARAMETER, "wrong error\n");
688 ok(hc == NULL, "connect failed\n");
689
690 hc = InternetConnectW(hi, NULL, 0, NULL, NULL, INTERNET_SERVICE_HTTP, 0, 0);
691 ok(GetLastError() == ERROR_INVALID_PARAMETER, "wrong error\n");
692 ok(hc == NULL, "connect failed\n");
693
694 hc = InternetConnectW(hi, NULL, 0, NULL, NULL, INTERNET_SERVICE_FTP, 0, 0);
695 ok(GetLastError() == ERROR_INVALID_PARAMETER, "wrong error\n");
696 ok(hc == NULL, "connect failed\n");
697
698 hc = InternetConnectW(NULL, szServer, 0, NULL, NULL, INTERNET_SERVICE_FTP, 0, 0);
699 ok(GetLastError() == ERROR_INVALID_HANDLE, "wrong error\n");
700 ok(hc == NULL, "connect failed\n");
701
702 hc = InternetOpenUrlW(hi, NULL, NULL, 0, 0, 0);
703 ok(GetLastError() == ERROR_INVALID_PARAMETER ||
704 GetLastError() == ERROR_INTERNET_UNRECOGNIZED_SCHEME, "wrong error\n");
705 ok(hc == NULL, "connect failed\n");
706
707 hc = InternetOpenUrlW(hi, szServer, NULL, 0, 0, 0);
708 ok(GetLastError() == ERROR_INTERNET_UNRECOGNIZED_SCHEME, "wrong error\n");
709 ok(hc == NULL, "connect failed\n");
710
711 InternetCloseHandle(hi);
712
713 r = InternetSetCookieW(NULL, NULL, NULL);
714 ok(GetLastError() == ERROR_INVALID_PARAMETER, "wrong error\n");
715 ok(r == FALSE, "return wrong\n");
716
717 r = InternetSetCookieW(szServer, NULL, NULL);
718 ok(GetLastError() == ERROR_INVALID_PARAMETER, "wrong error\n");
719 ok(r == FALSE, "return wrong\n");
720
721 r = InternetSetCookieW(szUrl, szServer, NULL);
722 ok(GetLastError() == ERROR_INVALID_PARAMETER, "wrong error\n");
723 ok(r == FALSE, "return wrong\n");
724
725 r = InternetSetCookieW(szUrl, szServer, szServer);
726 ok(r == TRUE, "return wrong\n");
727
728 r = InternetSetCookieW(szUrl, NULL, szServer);
729 ok(r == TRUE, "return wrong\n");
730
731 r = InternetSetCookieW(szUrl, szServer, szEmpty);
732 ok(r == TRUE, "return wrong\n");
733
734 r = InternetSetCookieW(szUrlEmpty, szServer, szServer);
735 ok(r == FALSE, "return wrong\n");
736
737 r = InternetSetCookieW(szServer, NULL, szServer);
738 ok(GetLastError() == ERROR_INTERNET_UNRECOGNIZED_SCHEME, "wrong error\n");
739 ok(r == FALSE, "return wrong\n");
740
741 sz = 0;
742 r = InternetGetCookieW(NULL, NULL, NULL, &sz);
743 ok(GetLastError() == ERROR_INVALID_PARAMETER || GetLastError() == ERROR_INTERNET_UNRECOGNIZED_SCHEME,
744 "wrong error %u\n", GetLastError());
745 ok( r == FALSE, "return wrong\n");
746
747 r = InternetGetCookieW(szServer, NULL, NULL, &sz);
748 todo_wine {
749 ok(GetLastError() == ERROR_INTERNET_UNRECOGNIZED_SCHEME, "wrong error\n");
750 }
751 ok( r == FALSE, "return wrong\n");
752
753 sz = 0;
754 r = InternetGetCookieW(szUrlEmpty, szServer, NULL, &sz);
755 ok( r == FALSE, "return wrong\n");
756
757 sz = 0;
758 r = InternetGetCookieW(szUrl, szServer, NULL, &sz);
759 ok( r == TRUE, "return wrong\n");
760
761 /* sz is 14 on XP SP2 and beyond, 30 on XP SP1 and before, 16 on IE11 */
762 ok( sz == 14 || sz == 16 || sz == 30, "sz wrong, got %u, expected 14, 16 or 30\n", sz);
763
764 sz = 0x20;
765 memset(buffer, 0, sizeof buffer);
766 r = InternetGetCookieW(szUrl, szServer, buffer, &sz);
767 ok( r == TRUE, "return wrong\n");
768
769 /* sz == lstrlenW(buffer) only in XP SP1 */
770 ok( sz == 1 + lstrlenW(buffer) || sz == lstrlenW(buffer), "sz wrong %d\n", sz);
771
772 /* before XP SP2, buffer is "server; server" */
773 ok( !lstrcmpW(szExpect, buffer) || !lstrcmpW(szServer, buffer) || !lstrcmpW(szServer2, buffer),
774 "cookie data wrong %s\n", wine_dbgstr_w(buffer));
775
776 sz = sizeof(buffer);
777 r = InternetQueryOptionA(NULL, INTERNET_OPTION_CONNECTED_STATE, buffer, &sz);
778 ok(r == TRUE, "ret %d\n", r);
779 }
780
781 static void test_version(void)
782 {
783 INTERNET_VERSION_INFO version;
784 DWORD size;
785 BOOL res;
786
787 size = sizeof(version);
788 res = InternetQueryOptionA(NULL, INTERNET_OPTION_VERSION, &version, &size);
789 ok(res, "Could not get version: %u\n", GetLastError());
790 ok(version.dwMajorVersion == 1, "dwMajorVersion=%d, expected 1\n", version.dwMajorVersion);
791 ok(version.dwMinorVersion == 2, "dwMinorVersion=%d, expected 2\n", version.dwMinorVersion);
792 }
793
794 static void InternetTimeFromSystemTimeA_test(void)
795 {
796 BOOL ret;
797 static const SYSTEMTIME time = { 2005, 1, 5, 7, 12, 6, 35, 0 };
798 char string[INTERNET_RFC1123_BUFSIZE];
799 static const char expect[] = "Fri, 07 Jan 2005 12:06:35 GMT";
800 DWORD error;
801
802 ret = pInternetTimeFromSystemTimeA( &time, INTERNET_RFC1123_FORMAT, string, sizeof(string) );
803 ok( ret, "InternetTimeFromSystemTimeA failed (%u)\n", GetLastError() );
804
805 ok( !memcmp( string, expect, sizeof(expect) ),
806 "InternetTimeFromSystemTimeA failed (%u)\n", GetLastError() );
807
808 /* test NULL time parameter */
809 SetLastError(0xdeadbeef);
810 ret = pInternetTimeFromSystemTimeA( NULL, INTERNET_RFC1123_FORMAT, string, sizeof(string) );
811 error = GetLastError();
812 ok( !ret, "InternetTimeFromSystemTimeA should have returned FALSE\n" );
813 ok( error == ERROR_INVALID_PARAMETER,
814 "InternetTimeFromSystemTimeA failed with ERROR_INVALID_PARAMETER instead of %u\n",
815 error );
816
817 /* test NULL string parameter */
818 SetLastError(0xdeadbeef);
819 ret = pInternetTimeFromSystemTimeA( &time, INTERNET_RFC1123_FORMAT, NULL, sizeof(string) );
820 error = GetLastError();
821 ok( !ret, "InternetTimeFromSystemTimeA should have returned FALSE\n" );
822 ok( error == ERROR_INVALID_PARAMETER,
823 "InternetTimeFromSystemTimeA failed with ERROR_INVALID_PARAMETER instead of %u\n",
824 error );
825
826 /* test invalid format parameter */
827 SetLastError(0xdeadbeef);
828 ret = pInternetTimeFromSystemTimeA( &time, INTERNET_RFC1123_FORMAT + 1, string, sizeof(string) );
829 error = GetLastError();
830 ok( !ret, "InternetTimeFromSystemTimeA should have returned FALSE\n" );
831 ok( error == ERROR_INVALID_PARAMETER,
832 "InternetTimeFromSystemTimeA failed with ERROR_INVALID_PARAMETER instead of %u\n",
833 error );
834
835 /* test too small buffer size */
836 SetLastError(0xdeadbeef);
837 ret = pInternetTimeFromSystemTimeA( &time, INTERNET_RFC1123_FORMAT, string, 0 );
838 error = GetLastError();
839 ok( !ret, "InternetTimeFromSystemTimeA should have returned FALSE\n" );
840 ok( error == ERROR_INSUFFICIENT_BUFFER,
841 "InternetTimeFromSystemTimeA failed with ERROR_INSUFFICIENT_BUFFER instead of %u\n",
842 error );
843 }
844
845 static void InternetTimeFromSystemTimeW_test(void)
846 {
847 BOOL ret;
848 static const SYSTEMTIME time = { 2005, 1, 5, 7, 12, 6, 35, 0 };
849 WCHAR string[INTERNET_RFC1123_BUFSIZE + 1];
850 static const WCHAR expect[] = { 'F','r','i',',',' ','0','7',' ','J','a','n',' ','2','0','0','5',' ',
851 '1','2',':','0','6',':','3','5',' ','G','M','T',0 };
852 DWORD error;
853
854 ret = pInternetTimeFromSystemTimeW( &time, INTERNET_RFC1123_FORMAT, string, sizeof(string) );
855 ok( ret, "InternetTimeFromSystemTimeW failed (%u)\n", GetLastError() );
856
857 ok( !memcmp( string, expect, sizeof(expect) ),
858 "InternetTimeFromSystemTimeW failed (%u)\n", GetLastError() );
859
860 /* test NULL time parameter */
861 SetLastError(0xdeadbeef);
862 ret = pInternetTimeFromSystemTimeW( NULL, INTERNET_RFC1123_FORMAT, string, sizeof(string) );
863 error = GetLastError();
864 ok( !ret, "InternetTimeFromSystemTimeW should have returned FALSE\n" );
865 ok( error == ERROR_INVALID_PARAMETER,
866 "InternetTimeFromSystemTimeW failed with ERROR_INVALID_PARAMETER instead of %u\n",
867 error );
868
869 /* test NULL string parameter */
870 SetLastError(0xdeadbeef);
871 ret = pInternetTimeFromSystemTimeW( &time, INTERNET_RFC1123_FORMAT, NULL, sizeof(string) );
872 error = GetLastError();
873 ok( !ret, "InternetTimeFromSystemTimeW should have returned FALSE\n" );
874 ok( error == ERROR_INVALID_PARAMETER,
875 "InternetTimeFromSystemTimeW failed with ERROR_INVALID_PARAMETER instead of %u\n",
876 error );
877
878 /* test invalid format parameter */
879 SetLastError(0xdeadbeef);
880 ret = pInternetTimeFromSystemTimeW( &time, INTERNET_RFC1123_FORMAT + 1, string, sizeof(string) );
881 error = GetLastError();
882 ok( !ret, "InternetTimeFromSystemTimeW should have returned FALSE\n" );
883 ok( error == ERROR_INVALID_PARAMETER,
884 "InternetTimeFromSystemTimeW failed with ERROR_INVALID_PARAMETER instead of %u\n",
885 error );
886
887 /* test too small buffer size */
888 SetLastError(0xdeadbeef);
889 ret = pInternetTimeFromSystemTimeW( &time, INTERNET_RFC1123_FORMAT, string, sizeof(string)/sizeof(string[0]) );
890 error = GetLastError();
891 ok( !ret, "InternetTimeFromSystemTimeW should have returned FALSE\n" );
892 ok( error == ERROR_INSUFFICIENT_BUFFER,
893 "InternetTimeFromSystemTimeW failed with ERROR_INSUFFICIENT_BUFFER instead of %u\n",
894 error );
895 }
896
897 static void InternetTimeToSystemTimeA_test(void)
898 {
899 BOOL ret;
900 SYSTEMTIME time;
901 static const SYSTEMTIME expect = { 2005, 1, 5, 7, 12, 6, 35, 0 };
902 static const char string[] = "Fri, 07 Jan 2005 12:06:35 GMT";
903 static const char string2[] = " fri 7 jan 2005 12 06 35";
904
905 ret = pInternetTimeToSystemTimeA( string, &time, 0 );
906 ok( ret, "InternetTimeToSystemTimeA failed (%u)\n", GetLastError() );
907 ok( !memcmp( &time, &expect, sizeof(expect) ),
908 "InternetTimeToSystemTimeA failed (%u)\n", GetLastError() );
909
910 ret = pInternetTimeToSystemTimeA( string2, &time, 0 );
911 ok( ret, "InternetTimeToSystemTimeA failed (%u)\n", GetLastError() );
912 ok( !memcmp( &time, &expect, sizeof(expect) ),
913 "InternetTimeToSystemTimeA failed (%u)\n", GetLastError() );
914 }
915
916 static void InternetTimeToSystemTimeW_test(void)
917 {
918 BOOL ret;
919 SYSTEMTIME time;
920 static const SYSTEMTIME expect = { 2005, 1, 5, 7, 12, 6, 35, 0 };
921 static const WCHAR string[] = { 'F','r','i',',',' ','0','7',' ','J','a','n',' ','2','0','0','5',' ',
922 '1','2',':','0','6',':','3','5',' ','G','M','T',0 };
923 static const WCHAR string2[] = { ' ','f','r','i',' ','7',' ','j','a','n',' ','2','0','0','5',' ',
924 '1','2',' ','0','6',' ','3','5',0 };
925 static const WCHAR string3[] = { 'F','r',0 };
926
927 ret = pInternetTimeToSystemTimeW( NULL, NULL, 0 );
928 ok( !ret, "InternetTimeToSystemTimeW succeeded (%u)\n", GetLastError() );
929
930 ret = pInternetTimeToSystemTimeW( NULL, &time, 0 );
931 ok( !ret, "InternetTimeToSystemTimeW succeeded (%u)\n", GetLastError() );
932
933 ret = pInternetTimeToSystemTimeW( string, NULL, 0 );
934 ok( !ret, "InternetTimeToSystemTimeW succeeded (%u)\n", GetLastError() );
935
936 ret = pInternetTimeToSystemTimeW( string, &time, 0 );
937 ok( ret, "InternetTimeToSystemTimeW failed (%u)\n", GetLastError() );
938
939 ret = pInternetTimeToSystemTimeW( string, &time, 0 );
940 ok( ret, "InternetTimeToSystemTimeW failed (%u)\n", GetLastError() );
941 ok( !memcmp( &time, &expect, sizeof(expect) ),
942 "InternetTimeToSystemTimeW failed (%u)\n", GetLastError() );
943
944 ret = pInternetTimeToSystemTimeW( string2, &time, 0 );
945 ok( ret, "InternetTimeToSystemTimeW failed (%u)\n", GetLastError() );
946 ok( !memcmp( &time, &expect, sizeof(expect) ),
947 "InternetTimeToSystemTimeW failed (%u)\n", GetLastError() );
948
949 ret = pInternetTimeToSystemTimeW( string3, &time, 0 );
950 ok( ret, "InternetTimeToSystemTimeW failed (%u)\n", GetLastError() );
951 }
952
953 static void test_IsDomainLegalCookieDomainW(void)
954 {
955 BOOL ret;
956 static const WCHAR empty[] = {0};
957 static const WCHAR dot[] = {'.',0};
958 static const WCHAR uk[] = {'u','k',0};
959 static const WCHAR com[] = {'c','o','m',0};
960 static const WCHAR dot_com[] = {'.','c','o','m',0};
961 static const WCHAR gmail_com[] = {'g','m','a','i','l','.','c','o','m',0};
962 static const WCHAR dot_gmail_com[] = {'.','g','m','a','i','l','.','c','o','m',0};
963 static const WCHAR www_gmail_com[] = {'w','w','w','.','g','m','a','i','l','.','c','o','m',0};
964 static const WCHAR www_mail_gmail_com[] = {'w','w','w','.','m','a','i','l','.','g','m','a','i','l','.','c','o','m',0};
965 static const WCHAR mail_gmail_com[] = {'m','a','i','l','.','g','m','a','i','l','.','c','o','m',0};
966 static const WCHAR gmail_co_uk[] = {'g','m','a','i','l','.','c','o','.','u','k',0};
967 static const WCHAR co_uk[] = {'c','o','.','u','k',0};
968 static const WCHAR dot_co_uk[] = {'.','c','o','.','u','k',0};
969
970 SetLastError(0xdeadbeef);
971 ret = pIsDomainLegalCookieDomainW(NULL, NULL);
972 if (!ret && (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED))
973 {
974 win_skip("IsDomainLegalCookieDomainW is not implemented\n");
975 return;
976 }
977 ok(!ret ||
978 broken(ret), /* IE6 */
979 "IsDomainLegalCookieDomainW succeeded\n");
980
981 SetLastError(0xdeadbeef);
982 ret = pIsDomainLegalCookieDomainW(com, NULL);
983 ok(!ret, "IsDomainLegalCookieDomainW succeeded\n");
984
985 SetLastError(0xdeadbeef);
986 ret = pIsDomainLegalCookieDomainW(NULL, gmail_com);
987 ok(!ret, "IsDomainLegalCookieDomainW succeeded\n");
988
989 SetLastError(0xdeadbeef);
990 ret = pIsDomainLegalCookieDomainW(empty, gmail_com);
991 ok(!ret, "IsDomainLegalCookieDomainW succeeded\n");
992
993 SetLastError(0xdeadbeef);
994 ret = pIsDomainLegalCookieDomainW(com, empty);
995 ok(!ret, "IsDomainLegalCookieDomainW succeeded\n");
996
997 SetLastError(0xdeadbeef);
998 ret = pIsDomainLegalCookieDomainW(gmail_com, dot);
999 ok(!ret, "IsDomainLegalCookieDomainW succeeded\n");
1000
1001 SetLastError(0xdeadbeef);
1002 ret = pIsDomainLegalCookieDomainW(dot, gmail_com);
1003 ok(!ret, "IsDomainLegalCookieDomainW succeeded\n");
1004
1005 SetLastError(0xdeadbeef);
1006 ret = pIsDomainLegalCookieDomainW(com, com);
1007 ok(!ret, "IsDomainLegalCookieDomainW succeeded\n");
1008
1009 SetLastError(0xdeadbeef);
1010 ret = pIsDomainLegalCookieDomainW(com, dot_com);
1011 ok(!ret, "IsDomainLegalCookieDomainW succeeded\n");
1012
1013 SetLastError(0xdeadbeef);
1014 ret = pIsDomainLegalCookieDomainW(dot_com, com);
1015 ok(!ret, "IsDomainLegalCookieDomainW succeeded\n");
1016
1017 SetLastError(0xdeadbeef);
1018 ret = pIsDomainLegalCookieDomainW(com, gmail_com);
1019 ok(!ret, "IsDomainLegalCookieDomainW succeeded\n");
1020
1021 ret = pIsDomainLegalCookieDomainW(gmail_com, gmail_com);
1022 ok(ret, "IsDomainLegalCookieDomainW failed\n");
1023
1024 ret = pIsDomainLegalCookieDomainW(gmail_com, www_gmail_com);
1025 ok(ret, "IsDomainLegalCookieDomainW failed\n");
1026
1027 ret = pIsDomainLegalCookieDomainW(gmail_com, www_mail_gmail_com);
1028 ok(ret, "IsDomainLegalCookieDomainW failed\n");
1029
1030 SetLastError(0xdeadbeef);
1031 ret = pIsDomainLegalCookieDomainW(gmail_co_uk, co_uk);
1032 ok(!ret, "IsDomainLegalCookieDomainW succeeded\n");
1033
1034 ret = pIsDomainLegalCookieDomainW(uk, co_uk);
1035 ok(!ret, "IsDomainLegalCookieDomainW succeeded\n");
1036
1037 ret = pIsDomainLegalCookieDomainW(gmail_co_uk, dot_co_uk);
1038 ok(!ret, "IsDomainLegalCookieDomainW succeeded\n");
1039
1040 ret = pIsDomainLegalCookieDomainW(co_uk, gmail_co_uk);
1041 todo_wine ok(!ret, "IsDomainLegalCookieDomainW succeeded\n");
1042
1043 ret = pIsDomainLegalCookieDomainW(gmail_co_uk, gmail_co_uk);
1044 ok(ret, "IsDomainLegalCookieDomainW failed\n");
1045
1046 ret = pIsDomainLegalCookieDomainW(gmail_com, com);
1047 ok(!ret, "IsDomainLegalCookieDomainW succeeded\n");
1048
1049 SetLastError(0xdeadbeef);
1050 ret = pIsDomainLegalCookieDomainW(dot_gmail_com, mail_gmail_com);
1051 ok(!ret, "IsDomainLegalCookieDomainW succeeded\n");
1052
1053 ret = pIsDomainLegalCookieDomainW(gmail_com, mail_gmail_com);
1054 ok(ret, "IsDomainLegalCookieDomainW failed\n");
1055
1056 ret = pIsDomainLegalCookieDomainW(mail_gmail_com, gmail_com);
1057 ok(!ret, "IsDomainLegalCookieDomainW succeeded\n");
1058
1059 ret = pIsDomainLegalCookieDomainW(mail_gmail_com, com);
1060 ok(!ret, "IsDomainLegalCookieDomainW succeeded\n");
1061
1062 ret = pIsDomainLegalCookieDomainW(dot_gmail_com, mail_gmail_com);
1063 ok(!ret, "IsDomainLegalCookieDomainW succeeded\n");
1064
1065 ret = pIsDomainLegalCookieDomainW(mail_gmail_com, dot_gmail_com);
1066 ok(!ret, "IsDomainLegalCookieDomainW succeeded\n");
1067 }
1068
1069 static void test_PrivacyGetSetZonePreferenceW(void)
1070 {
1071 DWORD ret, zone, type, template, old_template;
1072
1073 zone = 3;
1074 type = 0;
1075 ret = pPrivacyGetZonePreferenceW(zone, type, NULL, NULL, NULL);
1076 ok(ret == 0, "expected ret == 0, got %u\n", ret);
1077
1078 old_template = 0;
1079 ret = pPrivacyGetZonePreferenceW(zone, type, &old_template, NULL, NULL);
1080 ok(ret == 0, "expected ret == 0, got %u\n", ret);
1081
1082 template = 5;
1083 ret = pPrivacySetZonePreferenceW(zone, type, template, NULL);
1084 ok(ret == 0, "expected ret == 0, got %u\n", ret);
1085
1086 template = 0;
1087 ret = pPrivacyGetZonePreferenceW(zone, type, &template, NULL, NULL);
1088 ok(ret == 0, "expected ret == 0, got %u\n", ret);
1089 ok(template == 5, "expected template == 5, got %u\n", template);
1090
1091 template = 5;
1092 ret = pPrivacySetZonePreferenceW(zone, type, old_template, NULL);
1093 ok(ret == 0, "expected ret == 0, got %u\n", ret);
1094 }
1095
1096 static void test_InternetSetOption(void)
1097 {
1098 HINTERNET ses, con, req;
1099 ULONG ulArg;
1100 DWORD size;
1101 BOOL ret;
1102
1103 ses = InternetOpenA(NULL, INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, 0);
1104 ok(ses != 0, "InternetOpen failed: 0x%08x\n", GetLastError());
1105 con = InternetConnectA(ses, "www.winehq.org", 80, NULL, NULL, INTERNET_SERVICE_HTTP, 0, 0);
1106 ok(con != 0, "InternetConnect failed: 0x%08x\n", GetLastError());
1107 req = HttpOpenRequestA(con, "GET", "/", NULL, NULL, NULL, 0, 0);
1108 ok(req != 0, "HttpOpenRequest failed: 0x%08x\n", GetLastError());
1109
1110 /* INTERNET_OPTION_POLICY tests */
1111 SetLastError(0xdeadbeef);
1112 ret = InternetSetOptionW(ses, INTERNET_OPTION_POLICY, NULL, 0);
1113 ok(ret == FALSE, "InternetSetOption should've failed\n");
1114 ok(GetLastError() == ERROR_INVALID_PARAMETER, "GetLastError should've "
1115 "given ERROR_INVALID_PARAMETER, gave: 0x%08x\n", GetLastError());
1116
1117 SetLastError(0xdeadbeef);
1118 ret = InternetQueryOptionW(ses, INTERNET_OPTION_POLICY, NULL, 0);
1119 ok(ret == FALSE, "InternetQueryOption should've failed\n");
1120 ok(GetLastError() == ERROR_INVALID_PARAMETER, "GetLastError should've "
1121 "given ERROR_INVALID_PARAMETER, gave: 0x%08x\n", GetLastError());
1122
1123 /* INTERNET_OPTION_ERROR_MASK tests */
1124 SetLastError(0xdeadbeef);
1125 size = sizeof(ulArg);
1126 ret = InternetQueryOptionW(NULL, INTERNET_OPTION_ERROR_MASK, (void*)&ulArg, &size);
1127 ok(ret == FALSE, "InternetQueryOption should've failed\n");
1128 ok(GetLastError() == ERROR_INTERNET_INCORRECT_HANDLE_TYPE, "GetLastError() = %x\n", GetLastError());
1129
1130 SetLastError(0xdeadbeef);
1131 ulArg = 11;
1132 ret = InternetSetOptionA(NULL, INTERNET_OPTION_ERROR_MASK, (void*)&ulArg, sizeof(ULONG));
1133 ok(ret == FALSE, "InternetSetOption should've failed\n");
1134 ok(GetLastError() == ERROR_INTERNET_INCORRECT_HANDLE_TYPE, "GetLastError() = %x\n", GetLastError());
1135
1136 SetLastError(0xdeadbeef);
1137 ulArg = 11;
1138 ret = InternetSetOptionA(req, INTERNET_OPTION_ERROR_MASK, (void*)&ulArg, 20);
1139 ok(ret == FALSE, "InternetSetOption should've failed\n");
1140 ok(GetLastError() == ERROR_INTERNET_BAD_OPTION_LENGTH, "GetLastError() = %d\n", GetLastError());
1141
1142 ulArg = 11;
1143 ret = InternetSetOptionA(req, INTERNET_OPTION_ERROR_MASK, (void*)&ulArg, sizeof(ULONG));
1144 ok(ret == TRUE, "InternetSetOption should've succeeded\n");
1145
1146 SetLastError(0xdeadbeef);
1147 ulArg = 4;
1148 ret = InternetSetOptionA(req, INTERNET_OPTION_ERROR_MASK, (void*)&ulArg, sizeof(ULONG));
1149 ok(ret == FALSE, "InternetSetOption should've failed\n");
1150 ok(GetLastError() == ERROR_INVALID_PARAMETER, "GetLastError() = %x\n", GetLastError());
1151
1152 SetLastError(0xdeadbeef);
1153 ulArg = 16;
1154 ret = InternetSetOptionA(req, INTERNET_OPTION_ERROR_MASK, (void*)&ulArg, sizeof(ULONG));
1155 ok(ret == FALSE, "InternetSetOption should've failed\n");
1156 ok(GetLastError() == ERROR_INVALID_PARAMETER, "GetLastError() = %x\n", GetLastError());
1157
1158 ret = InternetSetOptionA(req, INTERNET_OPTION_SETTINGS_CHANGED, NULL, 0);
1159 ok(ret == TRUE, "InternetSetOption should've succeeded\n");
1160
1161 ret = InternetSetOptionA(ses, INTERNET_OPTION_SETTINGS_CHANGED, NULL, 0);
1162 ok(ret == TRUE, "InternetSetOption should've succeeded\n");
1163
1164 ret = InternetSetOptionA(ses, INTERNET_OPTION_REFRESH, NULL, 0);
1165 ok(ret == TRUE, "InternetSetOption should've succeeded\n");
1166
1167 SetLastError(0xdeadbeef);
1168 ret = InternetSetOptionA(req, INTERNET_OPTION_REFRESH, NULL, 0);
1169 todo_wine ok(ret == FALSE, "InternetSetOption should've failed\n");
1170 todo_wine ok(GetLastError() == ERROR_INTERNET_INCORRECT_HANDLE_TYPE, "GetLastError() = %x\n", GetLastError());
1171
1172 ret = InternetCloseHandle(req);
1173 ok(ret == TRUE, "InternetCloseHandle failed: 0x%08x\n", GetLastError());
1174 ret = InternetCloseHandle(con);
1175 ok(ret == TRUE, "InternetCloseHandle failed: 0x%08x\n", GetLastError());
1176 ret = InternetCloseHandle(ses);
1177 ok(ret == TRUE, "InternetCloseHandle failed: 0x%08x\n", GetLastError());
1178 }
1179
1180 #define verifyProxyEnable(e) r_verifyProxyEnable(__LINE__, e)
1181 static void r_verifyProxyEnable(LONG l, DWORD exp)
1182 {
1183 HKEY hkey;
1184 DWORD type, val, size = sizeof(DWORD);
1185 LONG ret;
1186 static const CHAR szInternetSettings[] = "Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings";
1187 static const CHAR szProxyEnable[] = "ProxyEnable";
1188
1189 ret = RegOpenKeyA(HKEY_CURRENT_USER, szInternetSettings, &hkey);
1190 ok_(__FILE__,l) (!ret, "RegOpenKeyA failed: 0x%08x\n", ret);
1191
1192 ret = RegQueryValueExA(hkey, szProxyEnable, 0, &type, (BYTE*)&val, &size);
1193 ok_(__FILE__,l) (!ret, "RegQueryValueExA failed: 0x%08x\n", ret);
1194 ok_(__FILE__,l) (type == REG_DWORD, "Expected regtype to be REG_DWORD, was: %d\n", type);
1195 ok_(__FILE__,l) (val == exp, "Expected ProxyEnabled to be %d, got: %d\n", exp, val);
1196
1197 ret = RegCloseKey(hkey);
1198 ok_(__FILE__,l) (!ret, "RegCloseKey failed: 0x%08x\n", ret);
1199 }
1200
1201 static void test_Option_PerConnectionOption(void)
1202 {
1203 BOOL ret;
1204 DWORD size = sizeof(INTERNET_PER_CONN_OPTION_LISTW);
1205 INTERNET_PER_CONN_OPTION_LISTW list = {size};
1206 INTERNET_PER_CONN_OPTIONW *orig_settings;
1207 static WCHAR proxy_srvW[] = {'p','r','o','x','y','.','e','x','a','m','p','l','e',0};
1208
1209 /* get the global IE proxy server info, to restore later */
1210 list.dwOptionCount = 2;
1211 list.pOptions = HeapAlloc(GetProcessHeap(), 0, 2 * sizeof(INTERNET_PER_CONN_OPTIONW));
1212
1213 list.pOptions[0].dwOption = INTERNET_PER_CONN_PROXY_SERVER;
1214 list.pOptions[1].dwOption = INTERNET_PER_CONN_FLAGS;
1215
1216 ret = InternetQueryOptionW(NULL, INTERNET_OPTION_PER_CONNECTION_OPTION,
1217 &list, &size);
1218 ok(ret == TRUE, "InternetQueryOption should've succeeded\n");
1219 orig_settings = list.pOptions;
1220
1221 /* set the global IE proxy server */
1222 list.dwOptionCount = 2;
1223 list.pOptions = HeapAlloc(GetProcessHeap(), 0, 2 * sizeof(INTERNET_PER_CONN_OPTIONW));
1224
1225 list.pOptions[0].dwOption = INTERNET_PER_CONN_PROXY_SERVER;
1226 list.pOptions[0].Value.pszValue = proxy_srvW;
1227 list.pOptions[1].dwOption = INTERNET_PER_CONN_FLAGS;
1228 list.pOptions[1].Value.dwValue = PROXY_TYPE_PROXY;
1229
1230 ret = InternetSetOptionW(NULL, INTERNET_OPTION_PER_CONNECTION_OPTION,
1231 &list, size);
1232 ok(ret == TRUE, "InternetSetOption should've succeeded\n");
1233
1234 HeapFree(GetProcessHeap(), 0, list.pOptions);
1235
1236 /* get & verify the global IE proxy server */
1237 list.dwOptionCount = 2;
1238 list.dwOptionError = 0;
1239 list.pOptions = HeapAlloc(GetProcessHeap(), 0, 2 * sizeof(INTERNET_PER_CONN_OPTIONW));
1240
1241 list.pOptions[0].dwOption = INTERNET_PER_CONN_PROXY_SERVER;
1242 list.pOptions[1].dwOption = INTERNET_PER_CONN_FLAGS;
1243
1244 ret = InternetQueryOptionW(NULL, INTERNET_OPTION_PER_CONNECTION_OPTION,
1245 &list, &size);
1246 ok(ret == TRUE, "InternetQueryOption should've succeeded\n");
1247 ok(!lstrcmpW(list.pOptions[0].Value.pszValue, proxy_srvW),
1248 "Retrieved proxy server should've been %s, was: %s\n",
1249 wine_dbgstr_w(proxy_srvW), wine_dbgstr_w(list.pOptions[0].Value.pszValue));
1250 ok(list.pOptions[1].Value.dwValue == PROXY_TYPE_PROXY,
1251 "Retrieved flags should've been PROXY_TYPE_PROXY, was: %d\n",
1252 list.pOptions[1].Value.dwValue);
1253 verifyProxyEnable(1);
1254
1255 HeapFree(GetProcessHeap(), 0, list.pOptions[0].Value.pszValue);
1256 HeapFree(GetProcessHeap(), 0, list.pOptions);
1257
1258 /* disable the proxy server */
1259 list.dwOptionCount = 1;
1260 list.pOptions = HeapAlloc(GetProcessHeap(), 0, sizeof(INTERNET_PER_CONN_OPTIONW));
1261
1262 list.pOptions[0].dwOption = INTERNET_PER_CONN_FLAGS;
1263 list.pOptions[0].Value.dwValue = PROXY_TYPE_DIRECT;
1264
1265 ret = InternetSetOptionW(NULL, INTERNET_OPTION_PER_CONNECTION_OPTION,
1266 &list, size);
1267 ok(ret == TRUE, "InternetSetOption should've succeeded\n");
1268
1269 HeapFree(GetProcessHeap(), 0, list.pOptions);
1270
1271 /* verify that the proxy is disabled */
1272 list.dwOptionCount = 1;
1273 list.dwOptionError = 0;
1274 list.pOptions = HeapAlloc(GetProcessHeap(), 0, sizeof(INTERNET_PER_CONN_OPTIONW));
1275
1276 list.pOptions[0].dwOption = INTERNET_PER_CONN_FLAGS;
1277
1278 ret = InternetQueryOptionW(NULL, INTERNET_OPTION_PER_CONNECTION_OPTION,
1279 &list, &size);
1280 ok(ret == TRUE, "InternetQueryOption should've succeeded\n");
1281 ok(list.pOptions[0].Value.dwValue == PROXY_TYPE_DIRECT,
1282 "Retrieved flags should've been PROXY_TYPE_DIRECT, was: %d\n",
1283 list.pOptions[0].Value.dwValue);
1284 verifyProxyEnable(0);
1285
1286 HeapFree(GetProcessHeap(), 0, list.pOptions);
1287
1288 /* set the proxy flags to 'invalid' value */
1289 list.dwOptionCount = 1;
1290 list.pOptions = HeapAlloc(GetProcessHeap(), 0, sizeof(INTERNET_PER_CONN_OPTIONW));
1291
1292 list.pOptions[0].dwOption = INTERNET_PER_CONN_FLAGS;
1293 list.pOptions[0].Value.dwValue = PROXY_TYPE_PROXY | PROXY_TYPE_DIRECT;
1294
1295 ret = InternetSetOptionW(NULL, INTERNET_OPTION_PER_CONNECTION_OPTION,
1296 &list, size);
1297 ok(ret == TRUE, "InternetSetOption should've succeeded\n");
1298
1299 HeapFree(GetProcessHeap(), 0, list.pOptions);
1300
1301 /* verify that the proxy is enabled */
1302 list.dwOptionCount = 1;
1303 list.dwOptionError = 0;
1304 list.pOptions = HeapAlloc(GetProcessHeap(), 0, sizeof(INTERNET_PER_CONN_OPTIONW));
1305
1306 list.pOptions[0].dwOption = INTERNET_PER_CONN_FLAGS;
1307
1308 ret = InternetQueryOptionW(NULL, INTERNET_OPTION_PER_CONNECTION_OPTION,
1309 &list, &size);
1310 ok(ret == TRUE, "InternetQueryOption should've succeeded\n");
1311 todo_wine ok(list.pOptions[0].Value.dwValue == (PROXY_TYPE_PROXY | PROXY_TYPE_DIRECT),
1312 "Retrieved flags should've been PROXY_TYPE_PROXY | PROXY_TYPE_DIRECT, was: %d\n",
1313 list.pOptions[0].Value.dwValue);
1314 verifyProxyEnable(1);
1315
1316 HeapFree(GetProcessHeap(), 0, list.pOptions);
1317
1318 /* restore original settings */
1319 list.dwOptionCount = 2;
1320 list.pOptions = orig_settings;
1321
1322 ret = InternetSetOptionW(NULL, INTERNET_OPTION_PER_CONNECTION_OPTION,
1323 &list, size);
1324 ok(ret == TRUE, "InternetSetOption should've succeeded\n");
1325
1326 HeapFree(GetProcessHeap(), 0, list.pOptions);
1327 }
1328
1329 static void test_Option_PerConnectionOptionA(void)
1330 {
1331 BOOL ret;
1332 DWORD size = sizeof(INTERNET_PER_CONN_OPTION_LISTA);
1333 INTERNET_PER_CONN_OPTION_LISTA list = {size};
1334 INTERNET_PER_CONN_OPTIONA *orig_settings;
1335 char proxy_srv[] = "proxy.example";
1336
1337 /* get the global IE proxy server info, to restore later */
1338 list.dwOptionCount = 2;
1339 list.pOptions = HeapAlloc(GetProcessHeap(), 0, 2 * sizeof(INTERNET_PER_CONN_OPTIONA));
1340
1341 list.pOptions[0].dwOption = INTERNET_PER_CONN_PROXY_SERVER;
1342 list.pOptions[1].dwOption = INTERNET_PER_CONN_FLAGS;
1343
1344 ret = InternetQueryOptionA(NULL, INTERNET_OPTION_PER_CONNECTION_OPTION,
1345 &list, &size);
1346 ok(ret == TRUE, "InternetQueryOption should've succeeded\n");
1347 orig_settings = list.pOptions;
1348
1349 /* set the global IE proxy server */
1350 list.dwOptionCount = 2;
1351 list.pOptions = HeapAlloc(GetProcessHeap(), 0, 2 * sizeof(INTERNET_PER_CONN_OPTIONA));
1352
1353 list.pOptions[0].dwOption = INTERNET_PER_CONN_PROXY_SERVER;
1354 list.pOptions[0].Value.pszValue = proxy_srv;
1355 list.pOptions[1].dwOption = INTERNET_PER_CONN_FLAGS;
1356 list.pOptions[1].Value.dwValue = PROXY_TYPE_PROXY;
1357
1358 ret = InternetSetOptionA(NULL, INTERNET_OPTION_PER_CONNECTION_OPTION,
1359 &list, size);
1360 ok(ret == TRUE, "InternetSetOption should've succeeded\n");
1361
1362 HeapFree(GetProcessHeap(), 0, list.pOptions);
1363
1364 /* get & verify the global IE proxy server */
1365 list.dwOptionCount = 2;
1366 list.dwOptionError = 0;
1367 list.pOptions = HeapAlloc(GetProcessHeap(), 0, 2 * sizeof(INTERNET_PER_CONN_OPTIONA));
1368
1369 list.pOptions[0].dwOption = INTERNET_PER_CONN_PROXY_SERVER;
1370 list.pOptions[1].dwOption = INTERNET_PER_CONN_FLAGS;
1371
1372 ret = InternetQueryOptionA(NULL, INTERNET_OPTION_PER_CONNECTION_OPTION,
1373 &list, &size);
1374 ok(ret == TRUE, "InternetQueryOption should've succeeded\n");
1375 ok(!lstrcmpA(list.pOptions[0].Value.pszValue, "proxy.example"),
1376 "Retrieved proxy server should've been \"%s\", was: \"%s\"\n",
1377 proxy_srv, list.pOptions[0].Value.pszValue);
1378 ok(list.pOptions[1].Value.dwValue == PROXY_TYPE_PROXY,
1379 "Retrieved flags should've been PROXY_TYPE_PROXY, was: %d\n",
1380 list.pOptions[1].Value.dwValue);
1381
1382 HeapFree(GetProcessHeap(), 0, list.pOptions[0].Value.pszValue);
1383 HeapFree(GetProcessHeap(), 0, list.pOptions);
1384
1385 /* test with NULL as proxy server */
1386 list.dwOptionCount = 1;
1387 list.pOptions = HeapAlloc(GetProcessHeap(), 0, sizeof(INTERNET_PER_CONN_OPTIONA));
1388 list.pOptions[0].dwOption = INTERNET_PER_CONN_PROXY_SERVER;
1389 list.pOptions[0].Value.pszValue = NULL;
1390
1391 ret = InternetSetOptionA(NULL, INTERNET_OPTION_PER_CONNECTION_OPTION, &list, size);
1392 ok(ret == TRUE, "InternetSetOption should've succeeded\n");
1393
1394 ret = InternetSetOptionA(NULL, INTERNET_OPTION_PER_CONNECTION_OPTION, &list, size);
1395 ok(ret == TRUE, "InternetSetOption should've succeeded\n");
1396
1397 HeapFree(GetProcessHeap(), 0, list.pOptions);
1398
1399 /* get & verify the proxy server */
1400 list.dwOptionCount = 1;
1401 list.dwOptionError = 0;
1402 list.pOptions = HeapAlloc(GetProcessHeap(), 0, sizeof(INTERNET_PER_CONN_OPTIONA));
1403 list.pOptions[0].dwOption = INTERNET_PER_CONN_PROXY_SERVER;
1404
1405 ret = InternetQueryOptionA(NULL, INTERNET_OPTION_PER_CONNECTION_OPTION, &list, &size);
1406 ok(ret == TRUE, "InternetQueryOption should've succeeded\n");
1407 ok(!list.pOptions[0].Value.pszValue,
1408 "Retrieved proxy server should've been NULL, was: \"%s\"\n",
1409 list.pOptions[0].Value.pszValue);
1410
1411 HeapFree(GetProcessHeap(), 0, list.pOptions[0].Value.pszValue);
1412 HeapFree(GetProcessHeap(), 0, list.pOptions);
1413
1414 /* restore original settings */
1415 list.dwOptionCount = 2;
1416 list.pOptions = orig_settings;
1417
1418 ret = InternetSetOptionA(NULL, INTERNET_OPTION_PER_CONNECTION_OPTION,
1419 &list, size);
1420 ok(ret == TRUE, "InternetSetOption should've succeeded\n");
1421
1422 HeapFree(GetProcessHeap(), 0, list.pOptions);
1423 }
1424
1425 #define FLAG_TODO 0x1
1426 #define FLAG_NEEDREQ 0x2
1427 #define FLAG_UNIMPL 0x4
1428
1429 static void test_InternetErrorDlg(void)
1430 {
1431 HINTERNET ses, con, req;
1432 DWORD res, flags;
1433 HWND hwnd;
1434 ULONG i;
1435 static const struct {
1436 DWORD error;
1437 DWORD res;
1438 DWORD test_flags;
1439 } no_ui_res[] = {
1440 { ERROR_INTERNET_INCORRECT_PASSWORD , ERROR_SUCCESS, FLAG_NEEDREQ },
1441 { ERROR_INTERNET_SEC_CERT_DATE_INVALID , ERROR_CANCELLED, 0 },
1442 { ERROR_INTERNET_SEC_CERT_CN_INVALID , ERROR_CANCELLED, 0 },
1443 { ERROR_INTERNET_HTTP_TO_HTTPS_ON_REDIR , ERROR_SUCCESS, 0 },
1444 { ERROR_INTERNET_HTTPS_TO_HTTP_ON_REDIR , ERROR_SUCCESS, FLAG_TODO },
1445 { ERROR_INTERNET_MIXED_SECURITY , ERROR_CANCELLED, FLAG_TODO },
1446 { ERROR_INTERNET_CHG_POST_IS_NON_SECURE , ERROR_CANCELLED, FLAG_TODO },
1447 { ERROR_INTERNET_POST_IS_NON_SECURE , ERROR_SUCCESS, 0 },
1448 { ERROR_INTERNET_CLIENT_AUTH_CERT_NEEDED, ERROR_CANCELLED, FLAG_NEEDREQ|FLAG_TODO },
1449 { ERROR_INTERNET_INVALID_CA , ERROR_CANCELLED, 0 },
1450 { ERROR_INTERNET_HTTPS_HTTP_SUBMIT_REDIR, ERROR_CANCELLED, FLAG_TODO },
1451 { ERROR_INTERNET_INSERT_CDROM , ERROR_CANCELLED, FLAG_TODO|FLAG_NEEDREQ|FLAG_UNIMPL },
1452 { ERROR_INTERNET_SEC_CERT_ERRORS , ERROR_CANCELLED, 0 },
1453 { ERROR_INTERNET_SEC_CERT_REV_FAILED , ERROR_CANCELLED, 0 },
1454 { ERROR_HTTP_COOKIE_NEEDS_CONFIRMATION , ERROR_HTTP_COOKIE_DECLINED, FLAG_TODO },
1455 { ERROR_INTERNET_BAD_AUTO_PROXY_SCRIPT , ERROR_CANCELLED, FLAG_TODO },
1456 { ERROR_INTERNET_UNABLE_TO_DOWNLOAD_SCRIPT, ERROR_CANCELLED, FLAG_TODO },
1457 { ERROR_HTTP_REDIRECT_NEEDS_CONFIRMATION, ERROR_CANCELLED, FLAG_TODO },
1458 { ERROR_INTERNET_SEC_CERT_REVOKED , ERROR_CANCELLED, 0 },
1459 { 0, ERROR_NOT_SUPPORTED }
1460 };
1461
1462 flags = 0;
1463
1464 res = InternetErrorDlg(NULL, NULL, 12055, flags, NULL);
1465 ok(res == ERROR_INVALID_HANDLE, "Got %d\n", res);
1466
1467 ses = InternetOpenA(NULL, INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, 0);
1468 ok(ses != 0, "InternetOpen failed: 0x%08x\n", GetLastError());
1469 con = InternetConnectA(ses, "www.winehq.org", 80, NULL, NULL, INTERNET_SERVICE_HTTP, 0, 0);
1470 ok(con != 0, "InternetConnect failed: 0x%08x\n", GetLastError());
1471 req = HttpOpenRequestA(con, "GET", "/", NULL, NULL, NULL, 0, 0);
1472 ok(req != 0, "HttpOpenRequest failed: 0x%08x\n", GetLastError());
1473
1474 /* NULL hwnd and FLAGS_ERROR_UI_FLAGS_NO_UI not set */
1475 for(i = INTERNET_ERROR_BASE; i < INTERNET_ERROR_LAST; i++)
1476 {
1477 res = InternetErrorDlg(NULL, req, i, flags, NULL);
1478 ok(res == ERROR_INVALID_HANDLE, "Got %d (%d)\n", res, i);
1479 }
1480
1481 hwnd = GetDesktopWindow();
1482 ok(hwnd != NULL, "GetDesktopWindow failed (%d)\n", GetLastError());
1483
1484 flags = FLAGS_ERROR_UI_FLAGS_NO_UI;
1485 for(i = INTERNET_ERROR_BASE; i < INTERNET_ERROR_LAST; i++)
1486 {
1487 DWORD expected, test_flags, j;
1488
1489 for(j = 0; no_ui_res[j].error != 0; ++j)
1490 if(no_ui_res[j].error == i)
1491 break;
1492
1493 test_flags = no_ui_res[j].test_flags;
1494 expected = no_ui_res[j].res;
1495
1496 /* Try an invalid request handle */
1497 res = InternetErrorDlg(hwnd, (HANDLE)0xdeadbeef, i, flags, NULL);
1498 if(res == ERROR_CALL_NOT_IMPLEMENTED)
1499 {
1500 ok(test_flags & FLAG_UNIMPL, "%i is unexpectedly unimplemented.\n", i);
1501 continue;
1502 }
1503 else
1504 ok(res == ERROR_INVALID_HANDLE, "Got %d (%d)\n", res, i);
1505
1506 /* With a valid req */
1507 if(i == ERROR_INTERNET_NEED_UI)
1508 continue; /* Crashes on windows XP */
1509
1510 if(i == ERROR_INTERNET_SEC_CERT_REVOKED)
1511 continue; /* Interactive (XP, Win7) */
1512
1513 res = InternetErrorDlg(hwnd, req, i, flags, NULL);
1514
1515 /* Handle some special cases */
1516 switch(i)
1517 {
1518 case ERROR_INTERNET_HTTP_TO_HTTPS_ON_REDIR:
1519 case ERROR_INTERNET_HTTPS_TO_HTTP_ON_REDIR:
1520 if(res == ERROR_CANCELLED)
1521 {
1522 /* Some windows XP, w2k3 x64, W2K8 */
1523 win_skip("Skipping some tests for %d\n", i);
1524 continue;
1525 }
1526 break;
1527 case ERROR_INTERNET_FORTEZZA_LOGIN_NEEDED:
1528 if(res != expected)
1529 {
1530 /* Windows XP, W2K3 */
1531 ok(res == NTE_PROV_TYPE_NOT_DEF, "Got %d\n", res);
1532 win_skip("Skipping some tests for %d\n", i);
1533 continue;
1534 }
1535 break;
1536 case ERROR_INTERNET_CHG_POST_IS_NON_SECURE:
1537 if(res == ERROR_SUCCESS) /* win10 returns ERROR_SUCCESS */
1538 expected = ERROR_SUCCESS;
1539 break;
1540 default: break;
1541 }
1542
1543 todo_wine_if(test_flags & FLAG_TODO)
1544 ok(res == expected, "Got %d, expected %d (%d)\n", res, expected, i);
1545
1546 /* Same thing with NULL hwnd */
1547 res = InternetErrorDlg(NULL, req, i, flags, NULL);
1548 todo_wine_if(test_flags & FLAG_TODO)
1549 ok(res == expected, "Got %d, expected %d (%d)\n", res, expected, i);
1550
1551
1552 /* With a null req */
1553 if(test_flags & FLAG_NEEDREQ)
1554 expected = ERROR_INVALID_PARAMETER;
1555
1556 res = InternetErrorDlg(hwnd, NULL, i, flags, NULL);
1557 todo_wine_if( test_flags & FLAG_TODO || i == ERROR_INTERNET_INCORRECT_PASSWORD)
1558 ok(res == expected, "Got %d, expected %d (%d)\n", res, expected, i);
1559 }
1560
1561 res = InternetCloseHandle(req);
1562 ok(res == TRUE, "InternetCloseHandle failed: 0x%08x\n", GetLastError());
1563 res = InternetCloseHandle(con);
1564 ok(res == TRUE, "InternetCloseHandle failed: 0x%08x\n", GetLastError());
1565 res = InternetCloseHandle(ses);
1566 ok(res == TRUE, "InternetCloseHandle failed: 0x%08x\n", GetLastError());
1567 }
1568
1569 static void test_InternetGetConnectedStateExA(void)
1570 {
1571 BOOL res;
1572 CHAR buffer[256];
1573 DWORD flags, sz;
1574
1575 if(!pInternetGetConnectedStateExA) {
1576 win_skip("InternetGetConnectedStateExA is not supported\n");
1577 return;
1578 }
1579
1580 res = pInternetGetConnectedStateExA(&flags, buffer, sizeof(buffer), 0);
1581 if(!res) {
1582 win_skip("InternetGetConnectedStateExA tests require a valid connection\n");
1583 return;
1584 }
1585 trace("Internet Connection: Flags 0x%02x - Name '%s'\n", flags, buffer);
1586
1587 res = pInternetGetConnectedStateExA(NULL, NULL, 0, 0);
1588 ok(res == TRUE, "Expected TRUE, got %d\n", res);
1589
1590 flags = 0;
1591 res = pInternetGetConnectedStateExA(&flags, NULL, 0, 0);
1592 ok(res == TRUE, "Expected TRUE, got %d\n", res);
1593 ok(flags, "Expected at least one flag set\n");
1594
1595 buffer[0] = 0;
1596 flags = 0;
1597 res = pInternetGetConnectedStateExA(&flags, buffer, 0, 0);
1598 ok(res == TRUE, "Expected TRUE, got %d\n", res);
1599 ok(flags, "Expected at least one flag set\n");
1600 ok(!buffer[0], "Buffer must not change, got %02X\n", buffer[0]);
1601
1602 buffer[0] = 0;
1603 res = pInternetGetConnectedStateExA(NULL, buffer, sizeof(buffer), 0);
1604 ok(res == TRUE, "Expected TRUE, got %d\n", res);
1605 sz = strlen(buffer);
1606 ok(sz > 0, "Expected a connection name\n");
1607
1608 buffer[0] = 0;
1609 flags = 0;
1610 res = pInternetGetConnectedStateExA(&flags, buffer, sizeof(buffer), 0);
1611 ok(res == TRUE, "Expected TRUE, got %d\n", res);
1612 ok(flags, "Expected at least one flag set\n");
1613 sz = strlen(buffer);
1614 ok(sz > 0, "Expected a connection name\n");
1615
1616 flags = 0;
1617 res = pInternetGetConnectedStateExA(&flags, NULL, sizeof(buffer), 0);
1618 ok(res == TRUE, "Expected TRUE, got %d\n", res);
1619 ok(flags, "Expected at least one flag set\n");
1620
1621 /* no space for complete string this time */
1622 buffer[0] = 0;
1623 flags = 0;
1624 res = pInternetGetConnectedStateExA(&flags, buffer, sz, 0);
1625 ok(res == TRUE, "Expected TRUE, got %d\n", res);
1626 ok(flags, "Expected at least one flag set\n");
1627 ok(sz - 1 == strlen(buffer), "Expected %u bytes, got %u\n", sz - 1, lstrlenA(buffer));
1628
1629 buffer[0] = 0;
1630 flags = 0;
1631 res = pInternetGetConnectedStateExA(&flags, buffer, sz / 2, 0);
1632 ok(res == TRUE, "Expected TRUE, got %d\n", res);
1633 ok(flags, "Expected at least one flag set\n");
1634 ok(sz / 2 - 1 == strlen(buffer), "Expected %u bytes, got %u\n", sz / 2 - 1, lstrlenA(buffer));
1635
1636 buffer[0] = 0;
1637 flags = 0;
1638 res = pInternetGetConnectedStateExA(&flags, buffer, 1, 0);
1639 ok(res == TRUE, "Expected TRUE, got %d\n", res);
1640 ok(flags, "Expected at least one flag set\n");
1641 ok(!buffer[0], "Expected 0 bytes, got %u\n", lstrlenA(buffer));
1642
1643 buffer[0] = 0;
1644 flags = 0;
1645 res = pInternetGetConnectedStateExA(&flags, buffer, 2, 0);
1646 ok(res == TRUE, "Expected TRUE, got %d\n", res);
1647 ok(flags, "Expected at least one flag set\n");
1648 ok(strlen(buffer) == 1, "Expected 1 byte, got %u\n", lstrlenA(buffer));
1649
1650 flags = 0;
1651 buffer[0] = 0xDE;
1652 res = pInternetGetConnectedStateExA(&flags, buffer, 1, 0);
1653 ok(res == TRUE, "Expected TRUE, got %d\n", res);
1654 ok(flags, "Expected at least one flag set\n");
1655 ok(!buffer[0], "Expected 0 bytes, got %u\n", lstrlenA(buffer));
1656 }
1657
1658 static void test_InternetGetConnectedStateExW(void)
1659 {
1660 BOOL res;
1661 WCHAR buffer[256];
1662 DWORD flags, sz;
1663
1664 if(!pInternetGetConnectedStateExW) {
1665 win_skip("InternetGetConnectedStateExW is not supported\n");
1666 return;
1667 }
1668
1669 res = pInternetGetConnectedStateExW(&flags, buffer, sizeof(buffer) / sizeof(buffer[0]), 0);
1670 if(!res) {
1671 win_skip("InternetGetConnectedStateExW tests require a valid connection\n");
1672 return;
1673 }
1674 trace("Internet Connection: Flags 0x%02x - Name '%s'\n", flags, wine_dbgstr_w(buffer));
1675
1676 res = pInternetGetConnectedStateExW(NULL, NULL, 0, 0);
1677 ok(res == TRUE, "Expected TRUE, got %d\n", res);
1678
1679 flags = 0;
1680 res = pInternetGetConnectedStateExW(&flags, NULL, 0, 0);
1681 ok(res == TRUE, "Expected TRUE, got %d\n", res);
1682 ok(flags, "Expected at least one flag set\n");
1683
1684 buffer[0] = 0;
1685 flags = 0;
1686 res = pInternetGetConnectedStateExW(&flags, buffer, 0, 0);
1687 ok(res == TRUE, "Expected TRUE, got %d\n", res);
1688 ok(flags, "Expected at least one flag set\n");
1689 ok(!buffer[0], "Buffer must not change, got %02X\n", buffer[0]);
1690
1691 buffer[0] = 0;
1692 res = pInternetGetConnectedStateExW(NULL, buffer, sizeof(buffer) / sizeof(buffer[0]), 0);
1693 ok(res == TRUE, "Expected TRUE, got %d\n", res);
1694 sz = lstrlenW(buffer);
1695 ok(sz > 0, "Expected a connection name\n");
1696
1697 buffer[0] = 0;
1698 flags = 0;
1699 res = pInternetGetConnectedStateExW(&flags, buffer, sizeof(buffer) / sizeof(buffer[0]), 0);
1700 ok(res == TRUE, "Expected TRUE, got %d\n", res);
1701 ok(flags, "Expected at least one flag set\n");
1702 sz = lstrlenW(buffer);
1703 ok(sz > 0, "Expected a connection name\n");
1704
1705 flags = 0;
1706 res = pInternetGetConnectedStateExW(&flags, NULL, sizeof(buffer) / sizeof(buffer[0]), 0);
1707 ok(res == TRUE, "Expected TRUE, got %d\n", res);
1708 ok(flags, "Expected at least one flag set\n");
1709
1710 /* no space for complete string this time */
1711 buffer[0] = 0;
1712 flags = 0;
1713 res = pInternetGetConnectedStateExW(&flags, buffer, sz, 0);
1714 ok(res == TRUE, "Expected TRUE, got %d\n", res);
1715 ok(flags, "Expected at least one flag set\n");
1716 ok(sz - 1 == lstrlenW(buffer), "Expected %u bytes, got %u\n", sz - 1, lstrlenW(buffer));
1717
1718 buffer[0] = 0;
1719 flags = 0;
1720 res = pInternetGetConnectedStateExW(&flags, buffer, sz / 2, 0);
1721 ok(res == TRUE, "Expected TRUE, got %d\n", res);
1722 ok(flags, "Expected at least one flag set\n");
1723 ok(sz / 2 - 1 == lstrlenW(buffer), "Expected %u bytes, got %u\n", sz / 2 - 1, lstrlenW(buffer));
1724
1725 buffer[0] = 0;
1726 flags = 0;
1727 res = pInternetGetConnectedStateExW(&flags, buffer, 1, 0);
1728 ok(res == TRUE, "Expected TRUE, got %d\n", res);
1729 ok(flags, "Expected at least one flag set\n");
1730 ok(!buffer[0], "Expected 0 bytes, got %u\n", lstrlenW(buffer));
1731
1732 buffer[0] = 0;
1733 flags = 0;
1734 res = pInternetGetConnectedStateExW(&flags, buffer, 2, 0);
1735 ok(res == TRUE, "Expected TRUE, got %d\n", res);
1736 ok(flags, "Expected at least one flag set\n");
1737 ok(lstrlenW(buffer) == 1, "Expected 1 byte, got %u\n", lstrlenW(buffer));
1738
1739 buffer[0] = 0xDEAD;
1740 flags = 0;
1741 res = pInternetGetConnectedStateExW(&flags, buffer, 1, 0);
1742 ok(res == TRUE, "Expected TRUE, got %d\n", res);
1743 ok(flags, "Expected at least one flag set\n");
1744 ok(!buffer[0], "Expected 0 bytes, got %u\n", lstrlenW(buffer));
1745 }
1746
1747 /* ############################### */
1748
1749 START_TEST(internet)
1750 {
1751 HMODULE hdll;
1752 hdll = GetModuleHandleA("wininet.dll");
1753
1754 pCreateUrlCacheContainerA = (void*)GetProcAddress(hdll, "CreateUrlCacheContainerA");
1755 pCreateUrlCacheContainerW = (void*)GetProcAddress(hdll, "CreateUrlCacheContainerW");
1756 pInternetTimeFromSystemTimeA = (void*)GetProcAddress(hdll, "InternetTimeFromSystemTimeA");
1757 pInternetTimeFromSystemTimeW = (void*)GetProcAddress(hdll, "InternetTimeFromSystemTimeW");
1758 pInternetTimeToSystemTimeA = (void*)GetProcAddress(hdll, "InternetTimeToSystemTimeA");
1759 pInternetTimeToSystemTimeW = (void*)GetProcAddress(hdll, "InternetTimeToSystemTimeW");
1760 pIsDomainLegalCookieDomainW = (void*)GetProcAddress(hdll, (LPCSTR)117);
1761 pPrivacyGetZonePreferenceW = (void*)GetProcAddress(hdll, "PrivacyGetZonePreferenceW");
1762 pPrivacySetZonePreferenceW = (void*)GetProcAddress(hdll, "PrivacySetZonePreferenceW");
1763 pInternetGetCookieExA = (void*)GetProcAddress(hdll, "InternetGetCookieExA");
1764 pInternetGetCookieExW = (void*)GetProcAddress(hdll, "InternetGetCookieExW");
1765 pInternetGetConnectedStateExA = (void*)GetProcAddress(hdll, "InternetGetConnectedStateExA");
1766 pInternetGetConnectedStateExW = (void*)GetProcAddress(hdll, "InternetGetConnectedStateExW");
1767
1768 if(!pInternetGetCookieExW) {
1769 win_skip("Too old IE (older than 6.0)\n");
1770 return;
1771 }
1772
1773 test_InternetCanonicalizeUrlA();
1774 test_InternetQueryOptionA();
1775 test_InternetGetConnectedStateExA();
1776 test_InternetGetConnectedStateExW();
1777 test_get_cookie();
1778 test_complicated_cookie();
1779 test_cookie_url();
1780 test_cookie_attrs();
1781 test_version();
1782 test_null();
1783 test_Option_PerConnectionOption();
1784 test_Option_PerConnectionOptionA();
1785 test_InternetErrorDlg();
1786 test_max_conns();
1787
1788 if (!pInternetTimeFromSystemTimeA)
1789 win_skip("skipping the InternetTime tests\n");
1790 else
1791 {
1792 InternetTimeFromSystemTimeA_test();
1793 InternetTimeFromSystemTimeW_test();
1794 InternetTimeToSystemTimeA_test();
1795 InternetTimeToSystemTimeW_test();
1796 }
1797 if (pIsDomainLegalCookieDomainW &&
1798 ((void*)pIsDomainLegalCookieDomainW == (void*)pCreateUrlCacheContainerA ||
1799 (void*)pIsDomainLegalCookieDomainW == (void*)pCreateUrlCacheContainerW))
1800 win_skip("IsDomainLegalCookieDomainW is not available on systems with IE5\n");
1801 else if (!pIsDomainLegalCookieDomainW)
1802 win_skip("IsDomainLegalCookieDomainW (or ordinal 117) is not available\n");
1803 else
1804 test_IsDomainLegalCookieDomainW();
1805
1806 if (pPrivacyGetZonePreferenceW && pPrivacySetZonePreferenceW)
1807 test_PrivacyGetSetZonePreferenceW();
1808 else
1809 win_skip("Privacy[SG]etZonePreferenceW are not available\n");
1810
1811 test_InternetSetOption();
1812 }