a83583a8c106d7edc1980e68a65638bc29e88eb6
[reactos.git] / modules / 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 len = 1024;
365 SetLastError(0xdeadbeef);
366 ret = InternetGetCookieA("http://www.example.com", NULL, NULL, &len);
367 ok(!ret && GetLastError() == ERROR_NO_MORE_ITEMS,
368 "InternetGetCookie should have failed with %s and error %d\n",
369 ret ? "TRUE" : "FALSE", GetLastError());
370 ok(!len, "len = %u\n", len);
371 }
372
373
374 static void test_complicated_cookie(void)
375 {
376 DWORD len;
377 BOOL ret;
378
379 CHAR buffer[1024];
380 CHAR user[256];
381 WCHAR wbuf[1024];
382
383 static const WCHAR testing_example_comW[] =
384 {'h','t','t','p',':','/','/','t','e','s','t','i','n','g','.','e','x','a','m','p','l','e','.','c','o','m',0};
385
386 ret = InternetSetCookieA("http://www.example.com/bar",NULL,"A=B; domain=.example.com");
387 ok(ret == TRUE,"InternetSetCookie failed\n");
388 ret = InternetSetCookieA("http://www.example.com/bar",NULL,"C=D; domain=.example.com; path=/");
389 ok(ret == TRUE,"InternetSetCookie failed\n");
390
391 /* Technically illegal! domain should require 2 dots, but native wininet accepts it */
392 ret = InternetSetCookieA("http://www.example.com",NULL,"E=F; domain=example.com");
393 ok(ret == TRUE,"InternetSetCookie failed\n");
394 ret = InternetSetCookieA("http://www.example.com",NULL,"G=H; domain=.example.com; invalid=attr; path=/foo");
395 ok(ret == TRUE,"InternetSetCookie failed\n");
396 ret = InternetSetCookieA("http://www.example.com/bar.html",NULL,"I=J; domain=.example.com");
397 ok(ret == TRUE,"InternetSetCookie failed\n");
398 ret = InternetSetCookieA("http://www.example.com/bar/",NULL,"K=L; domain=.example.com");
399 ok(ret == TRUE,"InternetSetCookie failed\n");
400 ret = InternetSetCookieA("http://www.example.com/bar/",NULL,"M=N; domain=.example.com; path=/foo/");
401 ok(ret == TRUE,"InternetSetCookie failed\n");
402 ret = InternetSetCookieA("http://www.example.com/bar/",NULL,"O=P; secure; path=/bar");
403 ok(ret == TRUE,"InternetSetCookie failed\n");
404
405 len = 1024;
406 ret = InternetGetCookieA("http://testing.example.com", NULL, NULL, &len);
407 ok(ret == TRUE,"InternetGetCookie failed\n");
408 ok(len == 19, "len = %u\n", len);
409
410 len = 1024;
411 memset(buffer, 0xac, sizeof(buffer));
412 ret = InternetGetCookieA("http://testing.example.com", NULL, buffer, &len);
413 ok(ret == TRUE,"InternetGetCookie failed\n");
414 ok(len == 19, "len = %u\n", len);
415 ok(strlen(buffer) == 18, "strlen(buffer) = %u\n", lstrlenA(buffer));
416 ok(strstr(buffer,"A=B")!=NULL,"A=B missing\n");
417 ok(strstr(buffer,"C=D")!=NULL,"C=D missing\n");
418 ok(strstr(buffer,"E=F")!=NULL,"E=F missing\n");
419 ok(strstr(buffer,"G=H")==NULL,"G=H present\n");
420 ok(strstr(buffer,"I=J")!=NULL,"I=J missing\n");
421 ok(strstr(buffer,"K=L")==NULL,"K=L present\n");
422 ok(strstr(buffer,"M=N")==NULL,"M=N present\n");
423 ok(strstr(buffer,"O=P")==NULL,"O=P present\n");
424
425 len = 10;
426 memset(buffer, 0xac, sizeof(buffer));
427 ret = InternetGetCookieA("http://testing.example.com", NULL, buffer, &len);
428 ok(!ret && GetLastError() == ERROR_INSUFFICIENT_BUFFER,
429 "InternetGetCookie returned: %x(%u), expected ERROR_INSUFFICIENT_BUFFER\n", ret, GetLastError());
430 ok(len == 19, "len = %u\n", len);
431
432 len = 1024;
433 ret = InternetGetCookieW(testing_example_comW, NULL, NULL, &len);
434 ok(ret == TRUE,"InternetGetCookieW failed\n");
435 ok(len == 38, "len = %u\n", len);
436
437 len = 1024;
438 memset(wbuf, 0xac, sizeof(wbuf));
439 ret = InternetGetCookieW(testing_example_comW, NULL, wbuf, &len);
440 ok(ret == TRUE,"InternetGetCookieW failed\n");
441 ok(len == 19 || broken(len==18), "len = %u\n", len);
442 ok(lstrlenW(wbuf) == 18, "strlenW(wbuf) = %u\n", lstrlenW(wbuf));
443
444 len = 10;
445 memset(wbuf, 0xac, sizeof(wbuf));
446 ret = InternetGetCookieW(testing_example_comW, NULL, wbuf, &len);
447 ok(!ret && GetLastError() == ERROR_INSUFFICIENT_BUFFER,
448 "InternetGetCookieW returned: %x(%u), expected ERROR_INSUFFICIENT_BUFFER\n", ret, GetLastError());
449 ok(len == 38, "len = %u\n", len);
450
451 len = 1024;
452 ret = InternetGetCookieA("http://testing.example.com/foobar", NULL, buffer, &len);
453 ok(ret == TRUE,"InternetGetCookie failed\n");
454 ok(strstr(buffer,"A=B")!=NULL,"A=B missing\n");
455 ok(strstr(buffer,"C=D")!=NULL,"C=D missing\n");
456 ok(strstr(buffer,"E=F")!=NULL,"E=F missing\n");
457 ok(strstr(buffer,"G=H")==NULL,"G=H present\n");
458 ok(strstr(buffer,"I=J")!=NULL,"I=J missing\n");
459 ok(strstr(buffer,"K=L")==NULL,"K=L present\n");
460 ok(strstr(buffer,"M=N")==NULL,"M=N present\n");
461 ok(strstr(buffer,"O=P")==NULL,"O=P present\n");
462
463 len = 1024;
464 ret = InternetGetCookieA("http://testing.example.com/foobar/", NULL, buffer, &len);
465 ok(ret == TRUE,"InternetGetCookie failed\n");
466 ok(strstr(buffer,"A=B")!=NULL,"A=B missing\n");
467 ok(strstr(buffer,"C=D")!=NULL,"C=D missing\n");
468 ok(strstr(buffer,"E=F")!=NULL,"E=F missing\n");
469 ok(strstr(buffer,"G=H")!=NULL,"G=H missing\n");
470 ok(strstr(buffer,"I=J")!=NULL,"I=J missing\n");
471 ok(strstr(buffer,"K=L")==NULL,"K=L present\n");
472 ok(strstr(buffer,"M=N")==NULL,"M=N present\n");
473 ok(strstr(buffer,"O=P")==NULL,"O=P present\n");
474
475 len = 1024;
476 ret = InternetGetCookieA("http://testing.example.com/foo/bar", NULL, buffer, &len);
477 ok(ret == TRUE,"InternetGetCookie failed\n");
478 ok(strstr(buffer,"A=B")!=NULL,"A=B missing\n");
479 ok(strstr(buffer,"C=D")!=NULL,"C=D missing\n");
480 ok(strstr(buffer,"E=F")!=NULL,"E=F missing\n");
481 ok(strstr(buffer,"G=H")!=NULL,"G=H missing\n");
482 ok(strstr(buffer,"I=J")!=NULL,"I=J missing\n");
483 ok(strstr(buffer,"K=L")==NULL,"K=L present\n");
484 ok(strstr(buffer,"M=N")!=NULL,"M=N missing\n");
485 ok(strstr(buffer,"O=P")==NULL,"O=P present\n");
486
487 len = 1024;
488 ret = InternetGetCookieA("http://testing.example.com/barfoo", NULL, buffer, &len);
489 ok(ret == TRUE,"InternetGetCookie failed\n");
490 ok(strstr(buffer,"A=B")!=NULL,"A=B missing\n");
491 ok(strstr(buffer,"C=D")!=NULL,"C=D missing\n");
492 ok(strstr(buffer,"E=F")!=NULL,"E=F missing\n");
493 ok(strstr(buffer,"G=H")==NULL,"G=H present\n");
494 ok(strstr(buffer,"I=J")!=NULL,"I=J missing\n");
495 ok(strstr(buffer,"K=L")==NULL,"K=L present\n");
496 ok(strstr(buffer,"M=N")==NULL,"M=N present\n");
497 ok(strstr(buffer,"O=P")==NULL,"O=P present\n");
498
499 len = 1024;
500 ret = InternetGetCookieA("http://testing.example.com/barfoo/", NULL, buffer, &len);
501 ok(ret == TRUE,"InternetGetCookie failed\n");
502 ok(strstr(buffer,"A=B")!=NULL,"A=B missing\n");
503 ok(strstr(buffer,"C=D")!=NULL,"C=D missing\n");
504 ok(strstr(buffer,"E=F")!=NULL,"E=F missing\n");
505 ok(strstr(buffer,"G=H")==NULL,"G=H present\n");
506 ok(strstr(buffer,"I=J")!=NULL,"I=J missing\n");
507 ok(strstr(buffer,"K=L")==NULL,"K=L present\n");
508 ok(strstr(buffer,"M=N")==NULL,"M=N present\n");
509 ok(strstr(buffer,"O=P")==NULL,"O=P present\n");
510
511 len = 1024;
512 ret = InternetGetCookieA("http://testing.example.com/bar/foo", NULL, buffer, &len);
513 ok(ret == TRUE,"InternetGetCookie failed\n");
514 ok(len == 24, "len = %u\n", 24);
515 ok(strstr(buffer,"A=B")!=NULL,"A=B missing\n");
516 ok(strstr(buffer,"C=D")!=NULL,"C=D missing\n");
517 ok(strstr(buffer,"E=F")!=NULL,"E=F missing\n");
518 ok(strstr(buffer,"G=H")==NULL,"G=H present\n");
519 ok(strstr(buffer,"I=J")!=NULL,"I=J missing\n");
520 ok(strstr(buffer,"K=L")!=NULL,"K=L missing\n");
521 ok(strstr(buffer,"M=N")==NULL,"M=N present\n");
522 ok(strstr(buffer,"O=P")==NULL,"O=P present\n");
523
524 /* Cookie name argument is not implemented */
525 len = 1024;
526 ret = InternetGetCookieA("http://testing.example.com/bar/foo", "A", buffer, &len);
527 ok(ret == TRUE,"InternetGetCookie failed\n");
528 ok(len == 24, "len = %u\n", 24);
529
530 /* test persistent cookies */
531 ret = InternetSetCookieA("http://testing.example.com", NULL, "A=B; expires=Fri, 01-Jan-2038 00:00:00 GMT");
532 ok(ret, "InternetSetCookie failed with error %d\n", GetLastError());
533
534 len = sizeof(user);
535 ret = GetUserNameA(user, &len);
536 ok(ret, "GetUserName failed with error %d\n", GetLastError());
537 for(; len>0; len--)
538 user[len-1] = tolower(user[len-1]);
539
540 sprintf(buffer, "Cookie:%s@testing.example.com/", user);
541 ret = GetUrlCacheEntryInfoA(buffer, NULL, &len);
542 ok(!ret, "GetUrlCacheEntryInfo succeeded\n");
543 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER, "GetLastError() = %d\n", GetLastError());
544
545 /* remove persistent cookie */
546 ret = InternetSetCookieA("http://testing.example.com", NULL, "A=B");
547 ok(ret, "InternetSetCookie failed with error %d\n", GetLastError());
548
549 ret = GetUrlCacheEntryInfoA(buffer, NULL, &len);
550 ok(!ret, "GetUrlCacheEntryInfo succeeded\n");
551 ok(GetLastError() == ERROR_FILE_NOT_FOUND, "GetLastError() = %d\n", GetLastError());
552
553 /* try setting cookie for different domain */
554 ret = InternetSetCookieA("http://www.aaa.example.com/bar",NULL,"E=F; domain=different.com");
555 ok(!ret, "InternetSetCookie succeeded\n");
556 ok(GetLastError() == ERROR_INVALID_PARAMETER, "GetLastError() = %d\n", GetLastError());
557 ret = InternetSetCookieA("http://www.aaa.example.com.pl/bar",NULL,"E=F; domain=example.com.pl");
558 ok(ret, "InternetSetCookie failed with error: %d\n", GetLastError());
559 ret = InternetSetCookieA("http://www.aaa.example.com.pl/bar",NULL,"E=F; domain=com.pl");
560 todo_wine ok(!ret, "InternetSetCookie succeeded\n");
561 }
562
563 static void test_cookie_attrs(void)
564 {
565 char buf[100];
566 DWORD size, state;
567 BOOL ret;
568
569 if(!GetProcAddress(GetModuleHandleA("wininet.dll"), "DeleteWpadCacheForNetworks")) {
570 win_skip("Skipping cookie attributes tests. Too old IE.\n");
571 return;
572 }
573
574 ret = InternetSetCookieA("http://cookie.attrs.com/bar", NULL, "A=data; httponly");
575 ok(!ret && GetLastError() == ERROR_INVALID_OPERATION, "InternetSetCookie returned: %x (%u)\n", ret, GetLastError());
576
577 SetLastError(0xdeadbeef);
578 state = InternetSetCookieExA("http://cookie.attrs.com/bar", NULL, "A=data; httponly", 0, 0);
579 ok(state == COOKIE_STATE_REJECT && GetLastError() == ERROR_INVALID_OPERATION,
580 "InternetSetCookieEx returned: %x (%u)\n", ret, GetLastError());
581
582 size = sizeof(buf);
583 ret = InternetGetCookieExA("http://cookie.attrs.com/", NULL, buf, &size, INTERNET_COOKIE_HTTPONLY, NULL);
584 ok(!ret && GetLastError() == ERROR_NO_MORE_ITEMS, "InternetGetCookieEx returned: %x (%u)\n", ret, GetLastError());
585
586 state = InternetSetCookieExA("http://cookie.attrs.com/bar",NULL,"A=data; httponly", INTERNET_COOKIE_HTTPONLY, 0);
587 ok(state == COOKIE_STATE_ACCEPT,"InternetSetCookieEx failed: %u\n", GetLastError());
588
589 size = sizeof(buf);
590 ret = InternetGetCookieA("http://cookie.attrs.com/", NULL, buf, &size);
591 ok(!ret && GetLastError() == ERROR_NO_MORE_ITEMS, "InternetGetCookie returned: %x (%u)\n", ret, GetLastError());
592
593 size = sizeof(buf);
594 ret = InternetGetCookieExA("http://cookie.attrs.com/", NULL, buf, &size, 0, NULL);
595 ok(!ret && GetLastError() == ERROR_NO_MORE_ITEMS, "InternetGetCookieEx returned: %x (%u)\n", ret, GetLastError());
596
597 size = sizeof(buf);
598 ret = InternetGetCookieExA("http://cookie.attrs.com/", NULL, buf, &size, INTERNET_COOKIE_HTTPONLY, NULL);
599 ok(ret, "InternetGetCookieEx failed: %u\n", GetLastError());
600 ok(!strcmp(buf, "A=data"), "data = %s\n", buf);
601
602 /* Try to override httponly cookie with non-httponly one */
603 ret = InternetSetCookieA("http://cookie.attrs.com/bar", NULL, "A=test");
604 ok(!ret && GetLastError() == ERROR_INVALID_OPERATION, "InternetSetCookie returned: %x (%u)\n", ret, GetLastError());
605
606 SetLastError(0xdeadbeef);
607 state = InternetSetCookieExA("http://cookie.attrs.com/bar", NULL, "A=data", 0, 0);
608 ok(state == COOKIE_STATE_REJECT && GetLastError() == ERROR_INVALID_OPERATION,
609 "InternetSetCookieEx returned: %x (%u)\n", ret, GetLastError());
610
611 size = sizeof(buf);
612 ret = InternetGetCookieExA("http://cookie.attrs.com/", NULL, buf, &size, INTERNET_COOKIE_HTTPONLY, NULL);
613 ok(ret, "InternetGetCookieEx failed: %u\n", GetLastError());
614 ok(!strcmp(buf, "A=data"), "data = %s\n", buf);
615
616 }
617
618 static void test_cookie_url(void)
619 {
620 char long_url[5000] = "http://long.url.test.com/", *p;
621 WCHAR bufw[512];
622 char buf[512];
623 DWORD len;
624 BOOL res;
625
626 static const WCHAR about_blankW[] = {'a','b','o','u','t',':','b','l','a','n','k',0};
627
628 len = sizeof(buf);
629 res = InternetGetCookieA("about:blank", NULL, buf, &len);
630 ok(!res && GetLastError() == ERROR_INVALID_PARAMETER,
631 "InternetGetCookeA failed: %u, expected ERROR_INVALID_PARAMETER\n", GetLastError());
632
633 len = sizeof(bufw)/sizeof(*bufw);
634 res = InternetGetCookieW(about_blankW, NULL, bufw, &len);
635 ok(!res && GetLastError() == ERROR_INVALID_PARAMETER,
636 "InternetGetCookeW failed: %u, expected ERROR_INVALID_PARAMETER\n", GetLastError());
637
638 len = sizeof(buf);
639 res = pInternetGetCookieExA("about:blank", NULL, buf, &len, 0, NULL);
640 ok(!res && GetLastError() == ERROR_INVALID_PARAMETER,
641 "InternetGetCookeExA failed: %u, expected ERROR_INVALID_PARAMETER\n", GetLastError());
642
643 len = sizeof(bufw)/sizeof(*bufw);
644 res = pInternetGetCookieExW(about_blankW, NULL, bufw, &len, 0, NULL);
645 ok(!res && GetLastError() == ERROR_INVALID_PARAMETER,
646 "InternetGetCookeExW failed: %u, expected ERROR_INVALID_PARAMETER\n", GetLastError());
647
648 p = long_url + strlen(long_url);
649 memset(p, 'x', long_url+sizeof(long_url)-p);
650 p += (long_url+sizeof(long_url)-p) - 3;
651 p[0] = '/';
652 p[2] = 0;
653 res = InternetSetCookieA(long_url, NULL, "A=B");
654 ok(res, "InternetSetCookieA failed: %u\n", GetLastError());
655
656 len = sizeof(buf);
657 res = InternetGetCookieA(long_url, NULL, buf, &len);
658 ok(res, "InternetGetCookieA failed: %u\n", GetLastError());
659 ok(!strcmp(buf, "A=B"), "buf = %s\n", buf);
660
661 len = sizeof(buf);
662 res = InternetGetCookieA("http://long.url.test.com/", NULL, buf, &len);
663 ok(!res && GetLastError() == ERROR_NO_MORE_ITEMS, "InternetGetCookieA failed: %u\n", GetLastError());
664 }
665
666 static void test_null(void)
667 {
668 HINTERNET hi, hc;
669 static const WCHAR szServer[] = { 's','e','r','v','e','r',0 };
670 static const WCHAR szServer2[] = { 's','e','r','v','e','r','=',0 };
671 static const WCHAR szEmpty[] = { 0 };
672 static const WCHAR szUrl[] = { 'h','t','t','p',':','/','/','a','.','b','.','c',0 };
673 static const WCHAR szUrlEmpty[] = { 'h','t','t','p',':','/','/',0 };
674 static const WCHAR szExpect[] = { 's','e','r','v','e','r',';',' ','s','e','r','v','e','r',0 };
675 WCHAR buffer[0x20];
676 BOOL r;
677 DWORD sz;
678
679 SetLastError(0xdeadbeef);
680 hi = InternetOpenW(NULL, 0, NULL, NULL, 0);
681 if (hi == NULL && GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)
682 {
683 win_skip("Internet*W functions are not implemented\n");
684 return;
685 }
686 ok(hi != NULL, "open failed\n");
687
688 hc = InternetConnectW(hi, NULL, 0, NULL, NULL, 0, 0, 0);
689 ok(GetLastError() == ERROR_INVALID_PARAMETER, "wrong error\n");
690 ok(hc == NULL, "connect failed\n");
691
692 hc = InternetConnectW(hi, NULL, 0, NULL, NULL, INTERNET_SERVICE_HTTP, 0, 0);
693 ok(GetLastError() == ERROR_INVALID_PARAMETER, "wrong error\n");
694 ok(hc == NULL, "connect failed\n");
695
696 hc = InternetConnectW(hi, NULL, 0, NULL, NULL, INTERNET_SERVICE_FTP, 0, 0);
697 ok(GetLastError() == ERROR_INVALID_PARAMETER, "wrong error\n");
698 ok(hc == NULL, "connect failed\n");
699
700 hc = InternetConnectW(NULL, szServer, 0, NULL, NULL, INTERNET_SERVICE_FTP, 0, 0);
701 ok(GetLastError() == ERROR_INVALID_HANDLE, "wrong error\n");
702 ok(hc == NULL, "connect failed\n");
703
704 hc = InternetOpenUrlW(hi, NULL, NULL, 0, 0, 0);
705 ok(GetLastError() == ERROR_INVALID_PARAMETER ||
706 GetLastError() == ERROR_INTERNET_UNRECOGNIZED_SCHEME, "wrong error\n");
707 ok(hc == NULL, "connect failed\n");
708
709 hc = InternetOpenUrlW(hi, szServer, NULL, 0, 0, 0);
710 ok(GetLastError() == ERROR_INTERNET_UNRECOGNIZED_SCHEME, "wrong error\n");
711 ok(hc == NULL, "connect failed\n");
712
713 InternetCloseHandle(hi);
714
715 r = InternetSetCookieW(NULL, NULL, NULL);
716 ok(GetLastError() == ERROR_INVALID_PARAMETER, "wrong error\n");
717 ok(r == FALSE, "return wrong\n");
718
719 r = InternetSetCookieW(szServer, NULL, NULL);
720 ok(GetLastError() == ERROR_INVALID_PARAMETER, "wrong error\n");
721 ok(r == FALSE, "return wrong\n");
722
723 r = InternetSetCookieW(szUrl, szServer, NULL);
724 ok(GetLastError() == ERROR_INVALID_PARAMETER, "wrong error\n");
725 ok(r == FALSE, "return wrong\n");
726
727 r = InternetSetCookieW(szUrl, szServer, szServer);
728 ok(r == TRUE, "return wrong\n");
729
730 r = InternetSetCookieW(szUrl, NULL, szServer);
731 ok(r == TRUE, "return wrong\n");
732
733 r = InternetSetCookieW(szUrl, szServer, szEmpty);
734 ok(r == TRUE, "return wrong\n");
735
736 r = InternetSetCookieW(szUrlEmpty, szServer, szServer);
737 ok(r == FALSE, "return wrong\n");
738
739 r = InternetSetCookieW(szServer, NULL, szServer);
740 ok(GetLastError() == ERROR_INTERNET_UNRECOGNIZED_SCHEME, "wrong error\n");
741 ok(r == FALSE, "return wrong\n");
742
743 sz = 0;
744 r = InternetGetCookieW(NULL, NULL, NULL, &sz);
745 ok(GetLastError() == ERROR_INVALID_PARAMETER || GetLastError() == ERROR_INTERNET_UNRECOGNIZED_SCHEME,
746 "wrong error %u\n", GetLastError());
747 ok( r == FALSE, "return wrong\n");
748
749 r = InternetGetCookieW(szServer, NULL, NULL, &sz);
750 todo_wine {
751 ok(GetLastError() == ERROR_INTERNET_UNRECOGNIZED_SCHEME, "wrong error\n");
752 }
753 ok( r == FALSE, "return wrong\n");
754
755 sz = 0;
756 r = InternetGetCookieW(szUrlEmpty, szServer, NULL, &sz);
757 ok( r == FALSE, "return wrong\n");
758
759 sz = 0;
760 r = InternetGetCookieW(szUrl, szServer, NULL, &sz);
761 ok( r == TRUE, "return wrong\n");
762
763 /* sz is 14 on XP SP2 and beyond, 30 on XP SP1 and before, 16 on IE11 */
764 ok( sz == 14 || sz == 16 || sz == 30, "sz wrong, got %u, expected 14, 16 or 30\n", sz);
765
766 sz = 0x20;
767 memset(buffer, 0, sizeof buffer);
768 r = InternetGetCookieW(szUrl, szServer, buffer, &sz);
769 ok( r == TRUE, "return wrong\n");
770
771 /* sz == lstrlenW(buffer) only in XP SP1 */
772 ok( sz == 1 + lstrlenW(buffer) || sz == lstrlenW(buffer), "sz wrong %d\n", sz);
773
774 /* before XP SP2, buffer is "server; server" */
775 ok( !lstrcmpW(szExpect, buffer) || !lstrcmpW(szServer, buffer) || !lstrcmpW(szServer2, buffer),
776 "cookie data wrong %s\n", wine_dbgstr_w(buffer));
777
778 sz = sizeof(buffer);
779 r = InternetQueryOptionA(NULL, INTERNET_OPTION_CONNECTED_STATE, buffer, &sz);
780 ok(r == TRUE, "ret %d\n", r);
781 }
782
783 static void test_version(void)
784 {
785 INTERNET_VERSION_INFO version;
786 DWORD size;
787 BOOL res;
788
789 size = sizeof(version);
790 res = InternetQueryOptionA(NULL, INTERNET_OPTION_VERSION, &version, &size);
791 ok(res, "Could not get version: %u\n", GetLastError());
792 ok(version.dwMajorVersion == 1, "dwMajorVersion=%d, expected 1\n", version.dwMajorVersion);
793 ok(version.dwMinorVersion == 2, "dwMinorVersion=%d, expected 2\n", version.dwMinorVersion);
794 }
795
796 static void InternetTimeFromSystemTimeA_test(void)
797 {
798 BOOL ret;
799 static const SYSTEMTIME time = { 2005, 1, 5, 7, 12, 6, 35, 0 };
800 char string[INTERNET_RFC1123_BUFSIZE];
801 static const char expect[] = "Fri, 07 Jan 2005 12:06:35 GMT";
802 DWORD error;
803
804 ret = pInternetTimeFromSystemTimeA( &time, INTERNET_RFC1123_FORMAT, string, sizeof(string) );
805 ok( ret, "InternetTimeFromSystemTimeA failed (%u)\n", GetLastError() );
806
807 ok( !memcmp( string, expect, sizeof(expect) ),
808 "InternetTimeFromSystemTimeA failed (%u)\n", GetLastError() );
809
810 /* test NULL time parameter */
811 SetLastError(0xdeadbeef);
812 ret = pInternetTimeFromSystemTimeA( NULL, INTERNET_RFC1123_FORMAT, string, sizeof(string) );
813 error = GetLastError();
814 ok( !ret, "InternetTimeFromSystemTimeA should have returned FALSE\n" );
815 ok( error == ERROR_INVALID_PARAMETER,
816 "InternetTimeFromSystemTimeA failed with ERROR_INVALID_PARAMETER instead of %u\n",
817 error );
818
819 /* test NULL string parameter */
820 SetLastError(0xdeadbeef);
821 ret = pInternetTimeFromSystemTimeA( &time, INTERNET_RFC1123_FORMAT, NULL, sizeof(string) );
822 error = GetLastError();
823 ok( !ret, "InternetTimeFromSystemTimeA should have returned FALSE\n" );
824 ok( error == ERROR_INVALID_PARAMETER,
825 "InternetTimeFromSystemTimeA failed with ERROR_INVALID_PARAMETER instead of %u\n",
826 error );
827
828 /* test invalid format parameter */
829 SetLastError(0xdeadbeef);
830 ret = pInternetTimeFromSystemTimeA( &time, INTERNET_RFC1123_FORMAT + 1, string, sizeof(string) );
831 error = GetLastError();
832 ok( !ret, "InternetTimeFromSystemTimeA should have returned FALSE\n" );
833 ok( error == ERROR_INVALID_PARAMETER,
834 "InternetTimeFromSystemTimeA failed with ERROR_INVALID_PARAMETER instead of %u\n",
835 error );
836
837 /* test too small buffer size */
838 SetLastError(0xdeadbeef);
839 ret = pInternetTimeFromSystemTimeA( &time, INTERNET_RFC1123_FORMAT, string, 0 );
840 error = GetLastError();
841 ok( !ret, "InternetTimeFromSystemTimeA should have returned FALSE\n" );
842 ok( error == ERROR_INSUFFICIENT_BUFFER,
843 "InternetTimeFromSystemTimeA failed with ERROR_INSUFFICIENT_BUFFER instead of %u\n",
844 error );
845 }
846
847 static void InternetTimeFromSystemTimeW_test(void)
848 {
849 BOOL ret;
850 static const SYSTEMTIME time = { 2005, 1, 5, 7, 12, 6, 35, 0 };
851 WCHAR string[INTERNET_RFC1123_BUFSIZE + 1];
852 static const WCHAR expect[] = { 'F','r','i',',',' ','0','7',' ','J','a','n',' ','2','0','0','5',' ',
853 '1','2',':','0','6',':','3','5',' ','G','M','T',0 };
854 DWORD error;
855
856 ret = pInternetTimeFromSystemTimeW( &time, INTERNET_RFC1123_FORMAT, string, sizeof(string) );
857 ok( ret, "InternetTimeFromSystemTimeW failed (%u)\n", GetLastError() );
858
859 ok( !memcmp( string, expect, sizeof(expect) ),
860 "InternetTimeFromSystemTimeW failed (%u)\n", GetLastError() );
861
862 /* test NULL time parameter */
863 SetLastError(0xdeadbeef);
864 ret = pInternetTimeFromSystemTimeW( NULL, INTERNET_RFC1123_FORMAT, string, sizeof(string) );
865 error = GetLastError();
866 ok( !ret, "InternetTimeFromSystemTimeW should have returned FALSE\n" );
867 ok( error == ERROR_INVALID_PARAMETER,
868 "InternetTimeFromSystemTimeW failed with ERROR_INVALID_PARAMETER instead of %u\n",
869 error );
870
871 /* test NULL string parameter */
872 SetLastError(0xdeadbeef);
873 ret = pInternetTimeFromSystemTimeW( &time, INTERNET_RFC1123_FORMAT, NULL, sizeof(string) );
874 error = GetLastError();
875 ok( !ret, "InternetTimeFromSystemTimeW should have returned FALSE\n" );
876 ok( error == ERROR_INVALID_PARAMETER,
877 "InternetTimeFromSystemTimeW failed with ERROR_INVALID_PARAMETER instead of %u\n",
878 error );
879
880 /* test invalid format parameter */
881 SetLastError(0xdeadbeef);
882 ret = pInternetTimeFromSystemTimeW( &time, INTERNET_RFC1123_FORMAT + 1, string, sizeof(string) );
883 error = GetLastError();
884 ok( !ret, "InternetTimeFromSystemTimeW should have returned FALSE\n" );
885 ok( error == ERROR_INVALID_PARAMETER,
886 "InternetTimeFromSystemTimeW failed with ERROR_INVALID_PARAMETER instead of %u\n",
887 error );
888
889 /* test too small buffer size */
890 SetLastError(0xdeadbeef);
891 ret = pInternetTimeFromSystemTimeW( &time, INTERNET_RFC1123_FORMAT, string, sizeof(string)/sizeof(string[0]) );
892 error = GetLastError();
893 ok( !ret, "InternetTimeFromSystemTimeW should have returned FALSE\n" );
894 ok( error == ERROR_INSUFFICIENT_BUFFER,
895 "InternetTimeFromSystemTimeW failed with ERROR_INSUFFICIENT_BUFFER instead of %u\n",
896 error );
897 }
898
899 static void InternetTimeToSystemTimeA_test(void)
900 {
901 BOOL ret;
902 SYSTEMTIME time;
903 static const SYSTEMTIME expect = { 2005, 1, 5, 7, 12, 6, 35, 0 };
904 static const char string[] = "Fri, 07 Jan 2005 12:06:35 GMT";
905 static const char string2[] = " fri 7 jan 2005 12 06 35";
906
907 ret = pInternetTimeToSystemTimeA( string, &time, 0 );
908 ok( ret, "InternetTimeToSystemTimeA failed (%u)\n", GetLastError() );
909 ok( !memcmp( &time, &expect, sizeof(expect) ),
910 "InternetTimeToSystemTimeA failed (%u)\n", GetLastError() );
911
912 ret = pInternetTimeToSystemTimeA( string2, &time, 0 );
913 ok( ret, "InternetTimeToSystemTimeA failed (%u)\n", GetLastError() );
914 ok( !memcmp( &time, &expect, sizeof(expect) ),
915 "InternetTimeToSystemTimeA failed (%u)\n", GetLastError() );
916 }
917
918 static void InternetTimeToSystemTimeW_test(void)
919 {
920 BOOL ret;
921 SYSTEMTIME time;
922 static const SYSTEMTIME expect = { 2005, 1, 5, 7, 12, 6, 35, 0 };
923 static const WCHAR string[] = { 'F','r','i',',',' ','0','7',' ','J','a','n',' ','2','0','0','5',' ',
924 '1','2',':','0','6',':','3','5',' ','G','M','T',0 };
925 static const WCHAR string2[] = { ' ','f','r','i',' ','7',' ','j','a','n',' ','2','0','0','5',' ',
926 '1','2',' ','0','6',' ','3','5',0 };
927 static const WCHAR string3[] = { 'F','r',0 };
928
929 ret = pInternetTimeToSystemTimeW( NULL, NULL, 0 );
930 ok( !ret, "InternetTimeToSystemTimeW succeeded (%u)\n", GetLastError() );
931
932 ret = pInternetTimeToSystemTimeW( NULL, &time, 0 );
933 ok( !ret, "InternetTimeToSystemTimeW succeeded (%u)\n", GetLastError() );
934
935 ret = pInternetTimeToSystemTimeW( string, NULL, 0 );
936 ok( !ret, "InternetTimeToSystemTimeW succeeded (%u)\n", GetLastError() );
937
938 ret = pInternetTimeToSystemTimeW( string, &time, 0 );
939 ok( ret, "InternetTimeToSystemTimeW failed (%u)\n", GetLastError() );
940
941 ret = pInternetTimeToSystemTimeW( string, &time, 0 );
942 ok( ret, "InternetTimeToSystemTimeW failed (%u)\n", GetLastError() );
943 ok( !memcmp( &time, &expect, sizeof(expect) ),
944 "InternetTimeToSystemTimeW failed (%u)\n", GetLastError() );
945
946 ret = pInternetTimeToSystemTimeW( string2, &time, 0 );
947 ok( ret, "InternetTimeToSystemTimeW failed (%u)\n", GetLastError() );
948 ok( !memcmp( &time, &expect, sizeof(expect) ),
949 "InternetTimeToSystemTimeW failed (%u)\n", GetLastError() );
950
951 ret = pInternetTimeToSystemTimeW( string3, &time, 0 );
952 ok( ret, "InternetTimeToSystemTimeW failed (%u)\n", GetLastError() );
953 }
954
955 static void test_IsDomainLegalCookieDomainW(void)
956 {
957 BOOL ret;
958 static const WCHAR empty[] = {0};
959 static const WCHAR dot[] = {'.',0};
960 static const WCHAR uk[] = {'u','k',0};
961 static const WCHAR com[] = {'c','o','m',0};
962 static const WCHAR dot_com[] = {'.','c','o','m',0};
963 static const WCHAR gmail_com[] = {'g','m','a','i','l','.','c','o','m',0};
964 static const WCHAR dot_gmail_com[] = {'.','g','m','a','i','l','.','c','o','m',0};
965 static const WCHAR www_gmail_com[] = {'w','w','w','.','g','m','a','i','l','.','c','o','m',0};
966 static const WCHAR www_mail_gmail_com[] = {'w','w','w','.','m','a','i','l','.','g','m','a','i','l','.','c','o','m',0};
967 static const WCHAR mail_gmail_com[] = {'m','a','i','l','.','g','m','a','i','l','.','c','o','m',0};
968 static const WCHAR gmail_co_uk[] = {'g','m','a','i','l','.','c','o','.','u','k',0};
969 static const WCHAR co_uk[] = {'c','o','.','u','k',0};
970 static const WCHAR dot_co_uk[] = {'.','c','o','.','u','k',0};
971
972 SetLastError(0xdeadbeef);
973 ret = pIsDomainLegalCookieDomainW(NULL, NULL);
974 if (!ret && (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED))
975 {
976 win_skip("IsDomainLegalCookieDomainW is not implemented\n");
977 return;
978 }
979 ok(!ret ||
980 broken(ret), /* IE6 */
981 "IsDomainLegalCookieDomainW succeeded\n");
982
983 SetLastError(0xdeadbeef);
984 ret = pIsDomainLegalCookieDomainW(com, NULL);
985 ok(!ret, "IsDomainLegalCookieDomainW succeeded\n");
986
987 SetLastError(0xdeadbeef);
988 ret = pIsDomainLegalCookieDomainW(NULL, gmail_com);
989 ok(!ret, "IsDomainLegalCookieDomainW succeeded\n");
990
991 SetLastError(0xdeadbeef);
992 ret = pIsDomainLegalCookieDomainW(empty, gmail_com);
993 ok(!ret, "IsDomainLegalCookieDomainW succeeded\n");
994
995 SetLastError(0xdeadbeef);
996 ret = pIsDomainLegalCookieDomainW(com, empty);
997 ok(!ret, "IsDomainLegalCookieDomainW succeeded\n");
998
999 SetLastError(0xdeadbeef);
1000 ret = pIsDomainLegalCookieDomainW(gmail_com, dot);
1001 ok(!ret, "IsDomainLegalCookieDomainW succeeded\n");
1002
1003 SetLastError(0xdeadbeef);
1004 ret = pIsDomainLegalCookieDomainW(dot, gmail_com);
1005 ok(!ret, "IsDomainLegalCookieDomainW succeeded\n");
1006
1007 SetLastError(0xdeadbeef);
1008 ret = pIsDomainLegalCookieDomainW(com, com);
1009 ok(!ret, "IsDomainLegalCookieDomainW succeeded\n");
1010
1011 SetLastError(0xdeadbeef);
1012 ret = pIsDomainLegalCookieDomainW(com, dot_com);
1013 ok(!ret, "IsDomainLegalCookieDomainW succeeded\n");
1014
1015 SetLastError(0xdeadbeef);
1016 ret = pIsDomainLegalCookieDomainW(dot_com, com);
1017 ok(!ret, "IsDomainLegalCookieDomainW succeeded\n");
1018
1019 SetLastError(0xdeadbeef);
1020 ret = pIsDomainLegalCookieDomainW(com, gmail_com);
1021 ok(!ret, "IsDomainLegalCookieDomainW succeeded\n");
1022
1023 ret = pIsDomainLegalCookieDomainW(gmail_com, gmail_com);
1024 ok(ret, "IsDomainLegalCookieDomainW failed\n");
1025
1026 ret = pIsDomainLegalCookieDomainW(gmail_com, www_gmail_com);
1027 ok(ret, "IsDomainLegalCookieDomainW failed\n");
1028
1029 ret = pIsDomainLegalCookieDomainW(gmail_com, www_mail_gmail_com);
1030 ok(ret, "IsDomainLegalCookieDomainW failed\n");
1031
1032 SetLastError(0xdeadbeef);
1033 ret = pIsDomainLegalCookieDomainW(gmail_co_uk, co_uk);
1034 ok(!ret, "IsDomainLegalCookieDomainW succeeded\n");
1035
1036 ret = pIsDomainLegalCookieDomainW(uk, co_uk);
1037 ok(!ret, "IsDomainLegalCookieDomainW succeeded\n");
1038
1039 ret = pIsDomainLegalCookieDomainW(gmail_co_uk, dot_co_uk);
1040 ok(!ret, "IsDomainLegalCookieDomainW succeeded\n");
1041
1042 ret = pIsDomainLegalCookieDomainW(co_uk, gmail_co_uk);
1043 todo_wine ok(!ret, "IsDomainLegalCookieDomainW succeeded\n");
1044
1045 ret = pIsDomainLegalCookieDomainW(gmail_co_uk, gmail_co_uk);
1046 ok(ret, "IsDomainLegalCookieDomainW failed\n");
1047
1048 ret = pIsDomainLegalCookieDomainW(gmail_com, com);
1049 ok(!ret, "IsDomainLegalCookieDomainW succeeded\n");
1050
1051 SetLastError(0xdeadbeef);
1052 ret = pIsDomainLegalCookieDomainW(dot_gmail_com, mail_gmail_com);
1053 ok(!ret, "IsDomainLegalCookieDomainW succeeded\n");
1054
1055 ret = pIsDomainLegalCookieDomainW(gmail_com, mail_gmail_com);
1056 ok(ret, "IsDomainLegalCookieDomainW failed\n");
1057
1058 ret = pIsDomainLegalCookieDomainW(mail_gmail_com, gmail_com);
1059 ok(!ret, "IsDomainLegalCookieDomainW succeeded\n");
1060
1061 ret = pIsDomainLegalCookieDomainW(mail_gmail_com, com);
1062 ok(!ret, "IsDomainLegalCookieDomainW succeeded\n");
1063
1064 ret = pIsDomainLegalCookieDomainW(dot_gmail_com, mail_gmail_com);
1065 ok(!ret, "IsDomainLegalCookieDomainW succeeded\n");
1066
1067 ret = pIsDomainLegalCookieDomainW(mail_gmail_com, dot_gmail_com);
1068 ok(!ret, "IsDomainLegalCookieDomainW succeeded\n");
1069 }
1070
1071 static void test_PrivacyGetSetZonePreferenceW(void)
1072 {
1073 DWORD ret, zone, type, template, old_template, pref_size = 0;
1074 WCHAR pref[256];
1075
1076 zone = 3;
1077 type = 0;
1078 ret = pPrivacyGetZonePreferenceW(zone, type, NULL, NULL, NULL);
1079 ok(ret == 0, "expected ret == 0, got %u\n", ret);
1080
1081 old_template = 0;
1082 ret = pPrivacyGetZonePreferenceW(zone, type, &old_template, NULL, NULL);
1083 ok(ret == 0, "expected ret == 0, got %u\n", ret);
1084
1085 trace("template %u\n", old_template);
1086
1087 if(old_template == PRIVACY_TEMPLATE_ADVANCED) {
1088 pref_size = sizeof(pref)/sizeof(WCHAR);
1089 ret = pPrivacyGetZonePreferenceW(zone, type, &old_template, pref, &pref_size);
1090 ok(ret == 0, "expected ret == 0, got %u\n", ret);
1091 }
1092
1093 template = 5;
1094 ret = pPrivacySetZonePreferenceW(zone, type, template, NULL);
1095 ok(ret == 0, "expected ret == 0, got %u\n", ret);
1096
1097 template = 0;
1098 ret = pPrivacyGetZonePreferenceW(zone, type, &template, NULL, NULL);
1099 ok(ret == 0, "expected ret == 0, got %u\n", ret);
1100 ok(template == 5, "expected template == 5, got %u\n", template);
1101
1102 template = 5;
1103 ret = pPrivacySetZonePreferenceW(zone, type, old_template, pref_size ? pref : NULL);
1104 ok(ret == 0, "expected ret == 0, got %u\n", ret);
1105 }
1106
1107 static void test_InternetSetOption(void)
1108 {
1109 HINTERNET ses, con, req;
1110 ULONG ulArg;
1111 DWORD size;
1112 BOOL ret;
1113
1114 ses = InternetOpenA(NULL, INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, 0);
1115 ok(ses != 0, "InternetOpen failed: 0x%08x\n", GetLastError());
1116 con = InternetConnectA(ses, "www.winehq.org", 80, NULL, NULL, INTERNET_SERVICE_HTTP, 0, 0);
1117 ok(con != 0, "InternetConnect failed: 0x%08x\n", GetLastError());
1118 req = HttpOpenRequestA(con, "GET", "/", NULL, NULL, NULL, 0, 0);
1119 ok(req != 0, "HttpOpenRequest failed: 0x%08x\n", GetLastError());
1120
1121 /* INTERNET_OPTION_POLICY tests */
1122 SetLastError(0xdeadbeef);
1123 ret = InternetSetOptionW(ses, INTERNET_OPTION_POLICY, NULL, 0);
1124 ok(ret == FALSE, "InternetSetOption should've failed\n");
1125 ok(GetLastError() == ERROR_INVALID_PARAMETER, "GetLastError should've "
1126 "given ERROR_INVALID_PARAMETER, gave: 0x%08x\n", GetLastError());
1127
1128 SetLastError(0xdeadbeef);
1129 ret = InternetQueryOptionW(ses, INTERNET_OPTION_POLICY, NULL, 0);
1130 ok(ret == FALSE, "InternetQueryOption should've failed\n");
1131 ok(GetLastError() == ERROR_INVALID_PARAMETER, "GetLastError should've "
1132 "given ERROR_INVALID_PARAMETER, gave: 0x%08x\n", GetLastError());
1133
1134 /* INTERNET_OPTION_ERROR_MASK tests */
1135 SetLastError(0xdeadbeef);
1136 size = sizeof(ulArg);
1137 ret = InternetQueryOptionW(NULL, INTERNET_OPTION_ERROR_MASK, (void*)&ulArg, &size);
1138 ok(ret == FALSE, "InternetQueryOption should've failed\n");
1139 ok(GetLastError() == ERROR_INTERNET_INCORRECT_HANDLE_TYPE, "GetLastError() = %x\n", GetLastError());
1140
1141 SetLastError(0xdeadbeef);
1142 ulArg = 11;
1143 ret = InternetSetOptionA(NULL, INTERNET_OPTION_ERROR_MASK, (void*)&ulArg, sizeof(ULONG));
1144 ok(ret == FALSE, "InternetSetOption should've failed\n");
1145 ok(GetLastError() == ERROR_INTERNET_INCORRECT_HANDLE_TYPE, "GetLastError() = %x\n", GetLastError());
1146
1147 SetLastError(0xdeadbeef);
1148 ulArg = 11;
1149 ret = InternetSetOptionA(req, INTERNET_OPTION_ERROR_MASK, (void*)&ulArg, 20);
1150 ok(ret == FALSE, "InternetSetOption should've failed\n");
1151 ok(GetLastError() == ERROR_INTERNET_BAD_OPTION_LENGTH, "GetLastError() = %d\n", GetLastError());
1152
1153 ulArg = 11;
1154 ret = InternetSetOptionA(req, INTERNET_OPTION_ERROR_MASK, (void*)&ulArg, sizeof(ULONG));
1155 ok(ret == TRUE, "InternetSetOption should've succeeded\n");
1156
1157 SetLastError(0xdeadbeef);
1158 ulArg = 4;
1159 ret = InternetSetOptionA(req, INTERNET_OPTION_ERROR_MASK, (void*)&ulArg, sizeof(ULONG));
1160 ok(ret == FALSE, "InternetSetOption should've failed\n");
1161 ok(GetLastError() == ERROR_INVALID_PARAMETER, "GetLastError() = %x\n", GetLastError());
1162
1163 SetLastError(0xdeadbeef);
1164 ulArg = 16;
1165 ret = InternetSetOptionA(req, INTERNET_OPTION_ERROR_MASK, (void*)&ulArg, sizeof(ULONG));
1166 ok(ret == FALSE, "InternetSetOption should've failed\n");
1167 ok(GetLastError() == ERROR_INVALID_PARAMETER, "GetLastError() = %x\n", GetLastError());
1168
1169 ret = InternetCloseHandle(req);
1170 ok(ret == TRUE, "InternetCloseHandle failed: 0x%08x\n", GetLastError());
1171 ret = InternetCloseHandle(con);
1172 ok(ret == TRUE, "InternetCloseHandle failed: 0x%08x\n", GetLastError());
1173 ret = InternetCloseHandle(ses);
1174 ok(ret == TRUE, "InternetCloseHandle failed: 0x%08x\n", GetLastError());
1175 }
1176
1177 static void test_end_browser_session(void)
1178 {
1179 DWORD len;
1180 BOOL ret;
1181
1182 ret = InternetSetCookieA("http://www.example.com/test_end", NULL, "A=B");
1183 ok(ret == TRUE, "InternetSetCookie failed\n");
1184
1185 len = 1024;
1186 ret = InternetGetCookieA("http://www.example.com/test_end", NULL, NULL, &len);
1187 ok(ret == TRUE,"InternetGetCookie failed\n");
1188 ok(len != 0, "len = 0\n");
1189
1190 ret = InternetSetOptionA(NULL, INTERNET_OPTION_END_BROWSER_SESSION, NULL, 0);
1191 ok(ret, "InternetSetOption(INTERNET_OPTION_END_BROWSER_SESSION) failed: %u\n", GetLastError());
1192
1193 len = 1024;
1194 ret = InternetGetCookieA("http://www.example.com/test_end", NULL, NULL, &len);
1195 ok(!ret && GetLastError() == ERROR_NO_MORE_ITEMS, "InternetGetCookie returned %x (%u)\n", ret, GetLastError());
1196 ok(!len, "len = %u\n", len);
1197 }
1198
1199 #define verifyProxyEnable(e) r_verifyProxyEnable(__LINE__, e)
1200 static void r_verifyProxyEnable(LONG l, DWORD exp)
1201 {
1202 HKEY hkey;
1203 DWORD type, val, size = sizeof(DWORD);
1204 LONG ret;
1205 static const CHAR szInternetSettings[] = "Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings";
1206 static const CHAR szProxyEnable[] = "ProxyEnable";
1207
1208 ret = RegOpenKeyA(HKEY_CURRENT_USER, szInternetSettings, &hkey);
1209 ok_(__FILE__,l) (!ret, "RegOpenKeyA failed: 0x%08x\n", ret);
1210
1211 ret = RegQueryValueExA(hkey, szProxyEnable, 0, &type, (BYTE*)&val, &size);
1212 ok_(__FILE__,l) (!ret, "RegQueryValueExA failed: 0x%08x\n", ret);
1213 ok_(__FILE__,l) (type == REG_DWORD, "Expected regtype to be REG_DWORD, was: %d\n", type);
1214 ok_(__FILE__,l) (val == exp, "Expected ProxyEnabled to be %d, got: %d\n", exp, val);
1215
1216 ret = RegCloseKey(hkey);
1217 ok_(__FILE__,l) (!ret, "RegCloseKey failed: 0x%08x\n", ret);
1218 }
1219
1220 static void test_Option_PerConnectionOption(void)
1221 {
1222 BOOL ret;
1223 DWORD size = sizeof(INTERNET_PER_CONN_OPTION_LISTW);
1224 INTERNET_PER_CONN_OPTION_LISTW list = {size};
1225 INTERNET_PER_CONN_OPTIONW *orig_settings;
1226 static WCHAR proxy_srvW[] = {'p','r','o','x','y','.','e','x','a','m','p','l','e',0};
1227
1228 /* get the global IE proxy server info, to restore later */
1229 list.dwOptionCount = 2;
1230 list.pOptions = HeapAlloc(GetProcessHeap(), 0, 2 * sizeof(INTERNET_PER_CONN_OPTIONW));
1231
1232 list.pOptions[0].dwOption = INTERNET_PER_CONN_PROXY_SERVER;
1233 list.pOptions[1].dwOption = INTERNET_PER_CONN_FLAGS;
1234
1235 ret = InternetQueryOptionW(NULL, INTERNET_OPTION_PER_CONNECTION_OPTION,
1236 &list, &size);
1237 ok(ret == TRUE, "InternetQueryOption should've succeeded\n");
1238 orig_settings = list.pOptions;
1239
1240 /* set the global IE proxy server */
1241 list.dwOptionCount = 2;
1242 list.pOptions = HeapAlloc(GetProcessHeap(), 0, 2 * sizeof(INTERNET_PER_CONN_OPTIONW));
1243
1244 list.pOptions[0].dwOption = INTERNET_PER_CONN_PROXY_SERVER;
1245 list.pOptions[0].Value.pszValue = proxy_srvW;
1246 list.pOptions[1].dwOption = INTERNET_PER_CONN_FLAGS;
1247 list.pOptions[1].Value.dwValue = PROXY_TYPE_PROXY;
1248
1249 ret = InternetSetOptionW(NULL, INTERNET_OPTION_PER_CONNECTION_OPTION,
1250 &list, size);
1251 ok(ret == TRUE, "InternetSetOption should've succeeded\n");
1252
1253 HeapFree(GetProcessHeap(), 0, list.pOptions);
1254
1255 /* get & verify the global IE proxy server */
1256 list.dwOptionCount = 2;
1257 list.dwOptionError = 0;
1258 list.pOptions = HeapAlloc(GetProcessHeap(), 0, 2 * sizeof(INTERNET_PER_CONN_OPTIONW));
1259
1260 list.pOptions[0].dwOption = INTERNET_PER_CONN_PROXY_SERVER;
1261 list.pOptions[1].dwOption = INTERNET_PER_CONN_FLAGS;
1262
1263 ret = InternetQueryOptionW(NULL, INTERNET_OPTION_PER_CONNECTION_OPTION,
1264 &list, &size);
1265 ok(ret == TRUE, "InternetQueryOption should've succeeded\n");
1266 ok(!lstrcmpW(list.pOptions[0].Value.pszValue, proxy_srvW),
1267 "Retrieved proxy server should've been %s, was: %s\n",
1268 wine_dbgstr_w(proxy_srvW), wine_dbgstr_w(list.pOptions[0].Value.pszValue));
1269 ok(list.pOptions[1].Value.dwValue == PROXY_TYPE_PROXY,
1270 "Retrieved flags should've been PROXY_TYPE_PROXY, was: %d\n",
1271 list.pOptions[1].Value.dwValue);
1272 verifyProxyEnable(1);
1273
1274 HeapFree(GetProcessHeap(), 0, list.pOptions[0].Value.pszValue);
1275 HeapFree(GetProcessHeap(), 0, list.pOptions);
1276
1277 /* disable the proxy server */
1278 list.dwOptionCount = 1;
1279 list.pOptions = HeapAlloc(GetProcessHeap(), 0, sizeof(INTERNET_PER_CONN_OPTIONW));
1280
1281 list.pOptions[0].dwOption = INTERNET_PER_CONN_FLAGS;
1282 list.pOptions[0].Value.dwValue = PROXY_TYPE_DIRECT;
1283
1284 ret = InternetSetOptionW(NULL, INTERNET_OPTION_PER_CONNECTION_OPTION,
1285 &list, size);
1286 ok(ret == TRUE, "InternetSetOption should've succeeded\n");
1287
1288 HeapFree(GetProcessHeap(), 0, list.pOptions);
1289
1290 /* verify that the proxy is disabled */
1291 list.dwOptionCount = 1;
1292 list.dwOptionError = 0;
1293 list.pOptions = HeapAlloc(GetProcessHeap(), 0, sizeof(INTERNET_PER_CONN_OPTIONW));
1294
1295 list.pOptions[0].dwOption = INTERNET_PER_CONN_FLAGS;
1296
1297 ret = InternetQueryOptionW(NULL, INTERNET_OPTION_PER_CONNECTION_OPTION,
1298 &list, &size);
1299 ok(ret == TRUE, "InternetQueryOption should've succeeded\n");
1300 ok(list.pOptions[0].Value.dwValue == PROXY_TYPE_DIRECT,
1301 "Retrieved flags should've been PROXY_TYPE_DIRECT, was: %d\n",
1302 list.pOptions[0].Value.dwValue);
1303 verifyProxyEnable(0);
1304
1305 HeapFree(GetProcessHeap(), 0, list.pOptions);
1306
1307 /* set the proxy flags to 'invalid' value */
1308 list.dwOptionCount = 1;
1309 list.pOptions = HeapAlloc(GetProcessHeap(), 0, sizeof(INTERNET_PER_CONN_OPTIONW));
1310
1311 list.pOptions[0].dwOption = INTERNET_PER_CONN_FLAGS;
1312 list.pOptions[0].Value.dwValue = PROXY_TYPE_PROXY | PROXY_TYPE_DIRECT;
1313
1314 ret = InternetSetOptionW(NULL, INTERNET_OPTION_PER_CONNECTION_OPTION,
1315 &list, size);
1316 ok(ret == TRUE, "InternetSetOption should've succeeded\n");
1317
1318 HeapFree(GetProcessHeap(), 0, list.pOptions);
1319
1320 /* verify that the proxy is enabled */
1321 list.dwOptionCount = 1;
1322 list.dwOptionError = 0;
1323 list.pOptions = HeapAlloc(GetProcessHeap(), 0, sizeof(INTERNET_PER_CONN_OPTIONW));
1324
1325 list.pOptions[0].dwOption = INTERNET_PER_CONN_FLAGS;
1326
1327 ret = InternetQueryOptionW(NULL, INTERNET_OPTION_PER_CONNECTION_OPTION,
1328 &list, &size);
1329 ok(ret == TRUE, "InternetQueryOption should've succeeded\n");
1330 todo_wine ok(list.pOptions[0].Value.dwValue == (PROXY_TYPE_PROXY | PROXY_TYPE_DIRECT),
1331 "Retrieved flags should've been PROXY_TYPE_PROXY | PROXY_TYPE_DIRECT, was: %d\n",
1332 list.pOptions[0].Value.dwValue);
1333 verifyProxyEnable(1);
1334
1335 HeapFree(GetProcessHeap(), 0, list.pOptions);
1336
1337 /* restore original settings */
1338 list.dwOptionCount = 2;
1339 list.pOptions = orig_settings;
1340
1341 ret = InternetSetOptionW(NULL, INTERNET_OPTION_PER_CONNECTION_OPTION,
1342 &list, size);
1343 ok(ret == TRUE, "InternetSetOption should've succeeded\n");
1344
1345 HeapFree(GetProcessHeap(), 0, list.pOptions);
1346 }
1347
1348 static void test_Option_PerConnectionOptionA(void)
1349 {
1350 BOOL ret;
1351 DWORD size = sizeof(INTERNET_PER_CONN_OPTION_LISTA);
1352 INTERNET_PER_CONN_OPTION_LISTA list = {size};
1353 INTERNET_PER_CONN_OPTIONA *orig_settings;
1354 char proxy_srv[] = "proxy.example";
1355
1356 /* get the global IE proxy server info, to restore later */
1357 list.dwOptionCount = 2;
1358 list.pOptions = HeapAlloc(GetProcessHeap(), 0, 2 * sizeof(INTERNET_PER_CONN_OPTIONA));
1359
1360 list.pOptions[0].dwOption = INTERNET_PER_CONN_PROXY_SERVER;
1361 list.pOptions[1].dwOption = INTERNET_PER_CONN_FLAGS;
1362
1363 ret = InternetQueryOptionA(NULL, INTERNET_OPTION_PER_CONNECTION_OPTION,
1364 &list, &size);
1365 ok(ret == TRUE, "InternetQueryOption should've succeeded\n");
1366 orig_settings = list.pOptions;
1367
1368 /* set the global IE proxy server */
1369 list.dwOptionCount = 2;
1370 list.pOptions = HeapAlloc(GetProcessHeap(), 0, 2 * sizeof(INTERNET_PER_CONN_OPTIONA));
1371
1372 list.pOptions[0].dwOption = INTERNET_PER_CONN_PROXY_SERVER;
1373 list.pOptions[0].Value.pszValue = proxy_srv;
1374 list.pOptions[1].dwOption = INTERNET_PER_CONN_FLAGS;
1375 list.pOptions[1].Value.dwValue = PROXY_TYPE_PROXY;
1376
1377 ret = InternetSetOptionA(NULL, INTERNET_OPTION_PER_CONNECTION_OPTION,
1378 &list, size);
1379 ok(ret == TRUE, "InternetSetOption should've succeeded\n");
1380
1381 HeapFree(GetProcessHeap(), 0, list.pOptions);
1382
1383 /* get & verify the global IE proxy server */
1384 list.dwOptionCount = 2;
1385 list.dwOptionError = 0;
1386 list.pOptions = HeapAlloc(GetProcessHeap(), 0, 2 * sizeof(INTERNET_PER_CONN_OPTIONA));
1387
1388 list.pOptions[0].dwOption = INTERNET_PER_CONN_PROXY_SERVER;
1389 list.pOptions[1].dwOption = INTERNET_PER_CONN_FLAGS;
1390
1391 ret = InternetQueryOptionA(NULL, INTERNET_OPTION_PER_CONNECTION_OPTION,
1392 &list, &size);
1393 ok(ret == TRUE, "InternetQueryOption should've succeeded\n");
1394 ok(!lstrcmpA(list.pOptions[0].Value.pszValue, "proxy.example"),
1395 "Retrieved proxy server should've been \"%s\", was: \"%s\"\n",
1396 proxy_srv, list.pOptions[0].Value.pszValue);
1397 ok(list.pOptions[1].Value.dwValue == PROXY_TYPE_PROXY,
1398 "Retrieved flags should've been PROXY_TYPE_PROXY, was: %d\n",
1399 list.pOptions[1].Value.dwValue);
1400
1401 HeapFree(GetProcessHeap(), 0, list.pOptions[0].Value.pszValue);
1402 HeapFree(GetProcessHeap(), 0, list.pOptions);
1403
1404 /* test with NULL as proxy server */
1405 list.dwOptionCount = 1;
1406 list.pOptions = HeapAlloc(GetProcessHeap(), 0, sizeof(INTERNET_PER_CONN_OPTIONA));
1407 list.pOptions[0].dwOption = INTERNET_PER_CONN_PROXY_SERVER;
1408 list.pOptions[0].Value.pszValue = NULL;
1409
1410 ret = InternetSetOptionA(NULL, INTERNET_OPTION_PER_CONNECTION_OPTION, &list, size);
1411 ok(ret == TRUE, "InternetSetOption should've succeeded\n");
1412
1413 ret = InternetSetOptionA(NULL, INTERNET_OPTION_PER_CONNECTION_OPTION, &list, size);
1414 ok(ret == TRUE, "InternetSetOption should've succeeded\n");
1415
1416 HeapFree(GetProcessHeap(), 0, list.pOptions);
1417
1418 /* get & verify the proxy server */
1419 list.dwOptionCount = 1;
1420 list.dwOptionError = 0;
1421 list.pOptions = HeapAlloc(GetProcessHeap(), 0, sizeof(INTERNET_PER_CONN_OPTIONA));
1422 list.pOptions[0].dwOption = INTERNET_PER_CONN_PROXY_SERVER;
1423
1424 ret = InternetQueryOptionA(NULL, INTERNET_OPTION_PER_CONNECTION_OPTION, &list, &size);
1425 ok(ret == TRUE, "InternetQueryOption should've succeeded\n");
1426 ok(!list.pOptions[0].Value.pszValue,
1427 "Retrieved proxy server should've been NULL, was: \"%s\"\n",
1428 list.pOptions[0].Value.pszValue);
1429
1430 HeapFree(GetProcessHeap(), 0, list.pOptions[0].Value.pszValue);
1431 HeapFree(GetProcessHeap(), 0, list.pOptions);
1432
1433 /* restore original settings */
1434 list.dwOptionCount = 2;
1435 list.pOptions = orig_settings;
1436
1437 ret = InternetSetOptionA(NULL, INTERNET_OPTION_PER_CONNECTION_OPTION,
1438 &list, size);
1439 ok(ret == TRUE, "InternetSetOption should've succeeded\n");
1440
1441 HeapFree(GetProcessHeap(), 0, list.pOptions);
1442 }
1443
1444 #define FLAG_TODO 0x1
1445 #define FLAG_NEEDREQ 0x2
1446 #define FLAG_UNIMPL 0x4
1447
1448 static void test_InternetErrorDlg(void)
1449 {
1450 HINTERNET ses, con, req;
1451 DWORD res, flags;
1452 HWND hwnd;
1453 ULONG i;
1454 static const struct {
1455 DWORD error;
1456 DWORD res;
1457 DWORD test_flags;
1458 } no_ui_res[] = {
1459 { ERROR_INTERNET_INCORRECT_PASSWORD , ERROR_SUCCESS, FLAG_NEEDREQ },
1460 { ERROR_INTERNET_SEC_CERT_DATE_INVALID , ERROR_CANCELLED, 0 },
1461 { ERROR_INTERNET_SEC_CERT_CN_INVALID , ERROR_CANCELLED, 0 },
1462 { ERROR_INTERNET_HTTP_TO_HTTPS_ON_REDIR , ERROR_SUCCESS, 0 },
1463 { ERROR_INTERNET_HTTPS_TO_HTTP_ON_REDIR , ERROR_SUCCESS, FLAG_TODO },
1464 { ERROR_INTERNET_MIXED_SECURITY , ERROR_CANCELLED, FLAG_TODO },
1465 { ERROR_INTERNET_CHG_POST_IS_NON_SECURE , ERROR_CANCELLED, FLAG_TODO },
1466 { ERROR_INTERNET_POST_IS_NON_SECURE , ERROR_SUCCESS, 0 },
1467 { ERROR_INTERNET_CLIENT_AUTH_CERT_NEEDED, ERROR_CANCELLED, FLAG_NEEDREQ|FLAG_TODO },
1468 { ERROR_INTERNET_INVALID_CA , ERROR_CANCELLED, 0 },
1469 { ERROR_INTERNET_HTTPS_HTTP_SUBMIT_REDIR, ERROR_CANCELLED, FLAG_TODO },
1470 { ERROR_INTERNET_INSERT_CDROM , ERROR_CANCELLED, FLAG_TODO|FLAG_NEEDREQ|FLAG_UNIMPL },
1471 { ERROR_INTERNET_SEC_CERT_ERRORS , ERROR_CANCELLED, 0 },
1472 { ERROR_INTERNET_SEC_CERT_REV_FAILED , ERROR_CANCELLED, 0 },
1473 { ERROR_HTTP_COOKIE_NEEDS_CONFIRMATION , ERROR_HTTP_COOKIE_DECLINED, FLAG_TODO },
1474 { ERROR_INTERNET_BAD_AUTO_PROXY_SCRIPT , ERROR_CANCELLED, FLAG_TODO },
1475 { ERROR_INTERNET_UNABLE_TO_DOWNLOAD_SCRIPT, ERROR_CANCELLED, FLAG_TODO },
1476 { ERROR_HTTP_REDIRECT_NEEDS_CONFIRMATION, ERROR_CANCELLED, FLAG_TODO },
1477 { ERROR_INTERNET_SEC_CERT_REVOKED , ERROR_CANCELLED, 0 },
1478 { 0, ERROR_NOT_SUPPORTED }
1479 };
1480
1481 flags = 0;
1482
1483 res = InternetErrorDlg(NULL, NULL, 12055, flags, NULL);
1484 ok(res == ERROR_INVALID_HANDLE, "Got %d\n", res);
1485
1486 ses = InternetOpenA(NULL, INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, 0);
1487 ok(ses != 0, "InternetOpen failed: 0x%08x\n", GetLastError());
1488 con = InternetConnectA(ses, "www.winehq.org", 80, NULL, NULL, INTERNET_SERVICE_HTTP, 0, 0);
1489 ok(con != 0, "InternetConnect failed: 0x%08x\n", GetLastError());
1490 req = HttpOpenRequestA(con, "GET", "/", NULL, NULL, NULL, 0, 0);
1491 ok(req != 0, "HttpOpenRequest failed: 0x%08x\n", GetLastError());
1492
1493 /* NULL hwnd and FLAGS_ERROR_UI_FLAGS_NO_UI not set */
1494 for(i = INTERNET_ERROR_BASE; i < INTERNET_ERROR_LAST; i++)
1495 {
1496 res = InternetErrorDlg(NULL, req, i, flags, NULL);
1497 ok(res == ERROR_INVALID_HANDLE, "Got %d (%d)\n", res, i);
1498 }
1499
1500 hwnd = GetDesktopWindow();
1501 ok(hwnd != NULL, "GetDesktopWindow failed (%d)\n", GetLastError());
1502
1503 flags = FLAGS_ERROR_UI_FLAGS_NO_UI;
1504 for(i = INTERNET_ERROR_BASE; i < INTERNET_ERROR_LAST; i++)
1505 {
1506 DWORD expected, test_flags, j;
1507
1508 for(j = 0; no_ui_res[j].error != 0; ++j)
1509 if(no_ui_res[j].error == i)
1510 break;
1511
1512 test_flags = no_ui_res[j].test_flags;
1513 expected = no_ui_res[j].res;
1514
1515 /* Try an invalid request handle */
1516 res = InternetErrorDlg(hwnd, (HANDLE)0xdeadbeef, i, flags, NULL);
1517 if(res == ERROR_CALL_NOT_IMPLEMENTED)
1518 {
1519 ok(test_flags & FLAG_UNIMPL, "%i is unexpectedly unimplemented.\n", i);
1520 continue;
1521 }
1522 else
1523 ok(res == ERROR_INVALID_HANDLE, "Got %d (%d)\n", res, i);
1524
1525 /* With a valid req */
1526 if(i == ERROR_INTERNET_NEED_UI)
1527 continue; /* Crashes on windows XP */
1528
1529 if(i == ERROR_INTERNET_SEC_CERT_REVOKED)
1530 continue; /* Interactive (XP, Win7) */
1531
1532 res = InternetErrorDlg(hwnd, req, i, flags, NULL);
1533
1534 /* Handle some special cases */
1535 switch(i)
1536 {
1537 case ERROR_INTERNET_HTTP_TO_HTTPS_ON_REDIR:
1538 case ERROR_INTERNET_HTTPS_TO_HTTP_ON_REDIR:
1539 if(res == ERROR_CANCELLED)
1540 {
1541 /* Some windows XP, w2k3 x64, W2K8 */
1542 win_skip("Skipping some tests for %d\n", i);
1543 continue;
1544 }
1545 break;
1546 case ERROR_INTERNET_FORTEZZA_LOGIN_NEEDED:
1547 if(res != expected)
1548 {
1549 /* Windows XP, W2K3 */
1550 ok(res == NTE_PROV_TYPE_NOT_DEF, "Got %d\n", res);
1551 win_skip("Skipping some tests for %d\n", i);
1552 continue;
1553 }
1554 break;
1555 case ERROR_INTERNET_CHG_POST_IS_NON_SECURE:
1556 if(res == ERROR_SUCCESS) /* win10 returns ERROR_SUCCESS */
1557 expected = ERROR_SUCCESS;
1558 break;
1559 default: break;
1560 }
1561
1562 todo_wine_if(test_flags & FLAG_TODO)
1563 ok(res == expected, "Got %d, expected %d (%d)\n", res, expected, i);
1564
1565 /* Same thing with NULL hwnd */
1566 res = InternetErrorDlg(NULL, req, i, flags, NULL);
1567 todo_wine_if(test_flags & FLAG_TODO)
1568 ok(res == expected, "Got %d, expected %d (%d)\n", res, expected, i);
1569
1570
1571 /* With a null req */
1572 if(test_flags & FLAG_NEEDREQ)
1573 expected = ERROR_INVALID_PARAMETER;
1574
1575 res = InternetErrorDlg(hwnd, NULL, i, flags, NULL);
1576 todo_wine_if( test_flags & FLAG_TODO || i == ERROR_INTERNET_INCORRECT_PASSWORD)
1577 ok(res == expected, "Got %d, expected %d (%d)\n", res, expected, i);
1578 }
1579
1580 res = InternetCloseHandle(req);
1581 ok(res == TRUE, "InternetCloseHandle failed: 0x%08x\n", GetLastError());
1582 res = InternetCloseHandle(con);
1583 ok(res == TRUE, "InternetCloseHandle failed: 0x%08x\n", GetLastError());
1584 res = InternetCloseHandle(ses);
1585 ok(res == TRUE, "InternetCloseHandle failed: 0x%08x\n", GetLastError());
1586 }
1587
1588 static void test_InternetGetConnectedStateExA(void)
1589 {
1590 BOOL res;
1591 CHAR buffer[256];
1592 DWORD flags, sz;
1593
1594 if(!pInternetGetConnectedStateExA) {
1595 win_skip("InternetGetConnectedStateExA is not supported\n");
1596 return;
1597 }
1598
1599 flags = 0;
1600 buffer[0] = 0;
1601 res = pInternetGetConnectedStateExA(&flags, buffer, sizeof(buffer), 0);
1602 trace("Internet Connection: Flags 0x%02x - Name '%s'\n", flags, buffer);
1603 todo_wine
1604 ok (flags & INTERNET_RAS_INSTALLED, "Missing RAS flag\n");
1605 if(!res) {
1606 win_skip("InternetGetConnectedStateExA tests require a valid connection\n");
1607 return;
1608 }
1609
1610 res = pInternetGetConnectedStateExA(NULL, NULL, 0, 0);
1611 ok(res == TRUE, "Expected TRUE, got %d\n", res);
1612
1613 flags = 0;
1614 res = pInternetGetConnectedStateExA(&flags, NULL, 0, 0);
1615 ok(res == TRUE, "Expected TRUE, got %d\n", res);
1616 if (flags & INTERNET_CONNECTION_CONFIGURED)
1617 {
1618 ok(flags & INTERNET_CONNECTION_MODEM, "Modem connection flag missing\n");
1619 ok(flags & ~INTERNET_CONNECTION_LAN, "Mixed Modem and LAN flags\n");
1620 }
1621 else
1622 {
1623 ok(flags & INTERNET_CONNECTION_LAN, "LAN connection flag missing\n");
1624 ok(flags & ~INTERNET_CONNECTION_MODEM, "Mixed Modem and LAN flags\n");
1625 }
1626
1627 buffer[0] = 0;
1628 flags = 0;
1629 res = pInternetGetConnectedStateExA(&flags, buffer, 0, 0);
1630 ok(res == TRUE, "Expected TRUE, got %d\n", res);
1631 ok(flags, "Expected at least one flag set\n");
1632 ok(!buffer[0], "Buffer must not change, got %02X\n", buffer[0]);
1633
1634 buffer[0] = 0;
1635 res = pInternetGetConnectedStateExA(NULL, buffer, sizeof(buffer), 0);
1636 ok(res == TRUE, "Expected TRUE, got %d\n", res);
1637 sz = strlen(buffer);
1638 ok(sz > 0, "Expected a connection name\n");
1639
1640 buffer[0] = 0;
1641 flags = 0;
1642 res = pInternetGetConnectedStateExA(&flags, buffer, sizeof(buffer), 0);
1643 ok(res == TRUE, "Expected TRUE, got %d\n", res);
1644 ok(flags, "Expected at least one flag set\n");
1645 sz = strlen(buffer);
1646 ok(sz > 0, "Expected a connection name\n");
1647
1648 flags = 0;
1649 res = pInternetGetConnectedStateExA(&flags, NULL, sizeof(buffer), 0);
1650 ok(res == TRUE, "Expected TRUE, got %d\n", res);
1651 ok(flags, "Expected at least one flag set\n");
1652
1653 /* no space for complete string this time */
1654 buffer[0] = 0;
1655 flags = 0;
1656 res = pInternetGetConnectedStateExA(&flags, buffer, sz, 0);
1657 ok(res == TRUE, "Expected TRUE, got %d\n", res);
1658 ok(flags, "Expected at least one flag set\n");
1659 ok(sz - 1 == strlen(buffer), "Expected %u bytes, got %u\n", sz - 1, lstrlenA(buffer));
1660
1661 buffer[0] = 0;
1662 flags = 0;
1663 res = pInternetGetConnectedStateExA(&flags, buffer, sz / 2, 0);
1664 ok(res == TRUE, "Expected TRUE, got %d\n", res);
1665 ok(flags, "Expected at least one flag set\n");
1666 ok(sz / 2 - 1 == strlen(buffer), "Expected %u bytes, got %u\n", sz / 2 - 1, lstrlenA(buffer));
1667
1668 buffer[0] = 0;
1669 flags = 0;
1670 res = pInternetGetConnectedStateExA(&flags, buffer, 1, 0);
1671 ok(res == TRUE, "Expected TRUE, got %d\n", res);
1672 ok(flags, "Expected at least one flag set\n");
1673 ok(!buffer[0], "Expected 0 bytes, got %u\n", lstrlenA(buffer));
1674
1675 buffer[0] = 0;
1676 flags = 0;
1677 res = pInternetGetConnectedStateExA(&flags, buffer, 2, 0);
1678 ok(res == TRUE, "Expected TRUE, got %d\n", res);
1679 ok(flags, "Expected at least one flag set\n");
1680 ok(strlen(buffer) == 1, "Expected 1 byte, got %u\n", lstrlenA(buffer));
1681
1682 flags = 0;
1683 buffer[0] = 0xDE;
1684 res = pInternetGetConnectedStateExA(&flags, buffer, 1, 0);
1685 ok(res == TRUE, "Expected TRUE, got %d\n", res);
1686 ok(flags, "Expected at least one flag set\n");
1687 ok(!buffer[0], "Expected 0 bytes, got %u\n", lstrlenA(buffer));
1688 }
1689
1690 static void test_InternetGetConnectedStateExW(void)
1691 {
1692 BOOL res;
1693 WCHAR buffer[256];
1694 DWORD flags, sz;
1695
1696 if(!pInternetGetConnectedStateExW) {
1697 win_skip("InternetGetConnectedStateExW is not supported\n");
1698 return;
1699 }
1700
1701 flags = 0;
1702 buffer[0] = 0;
1703 res = pInternetGetConnectedStateExW(&flags, buffer, sizeof(buffer) / sizeof(buffer[0]), 0);
1704 trace("Internet Connection: Flags 0x%02x - Name '%s'\n", flags, wine_dbgstr_w(buffer));
1705 todo_wine
1706 ok (flags & INTERNET_RAS_INSTALLED, "Missing RAS flag\n");
1707 if(!res) {
1708 win_skip("InternetGetConnectedStateExW tests require a valid connection\n");
1709 return;
1710 }
1711
1712 res = pInternetGetConnectedStateExW(NULL, NULL, 0, 0);
1713 ok(res == TRUE, "Expected TRUE, got %d\n", res);
1714
1715 flags = 0;
1716 res = pInternetGetConnectedStateExW(&flags, NULL, 0, 0);
1717 ok(res == TRUE, "Expected TRUE, got %d\n", res);
1718 if (flags & INTERNET_CONNECTION_CONFIGURED)
1719 {
1720 ok(flags & INTERNET_CONNECTION_MODEM, "Modem connection flag missing\n");
1721 ok(flags & ~INTERNET_CONNECTION_LAN, "Mixed Modem and LAN flags\n");
1722 }
1723 else
1724 {
1725 ok(flags & INTERNET_CONNECTION_LAN, "LAN connection flag missing\n");
1726 ok(flags & ~INTERNET_CONNECTION_MODEM, "Mixed Modem and LAN flags\n");
1727 }
1728
1729 buffer[0] = 0;
1730 flags = 0;
1731 res = pInternetGetConnectedStateExW(&flags, buffer, 0, 0);
1732 ok(res == TRUE, "Expected TRUE, got %d\n", res);
1733 ok(flags, "Expected at least one flag set\n");
1734 ok(!buffer[0], "Buffer must not change, got %02X\n", buffer[0]);
1735
1736 buffer[0] = 0;
1737 res = pInternetGetConnectedStateExW(NULL, buffer, sizeof(buffer) / sizeof(buffer[0]), 0);
1738 ok(res == TRUE, "Expected TRUE, got %d\n", res);
1739 sz = lstrlenW(buffer);
1740 ok(sz > 0, "Expected a connection name\n");
1741
1742 buffer[0] = 0;
1743 flags = 0;
1744 res = pInternetGetConnectedStateExW(&flags, buffer, sizeof(buffer) / sizeof(buffer[0]), 0);
1745 ok(res == TRUE, "Expected TRUE, got %d\n", res);
1746 ok(flags, "Expected at least one flag set\n");
1747 sz = lstrlenW(buffer);
1748 ok(sz > 0, "Expected a connection name\n");
1749
1750 flags = 0;
1751 res = pInternetGetConnectedStateExW(&flags, NULL, sizeof(buffer) / sizeof(buffer[0]), 0);
1752 ok(res == TRUE, "Expected TRUE, got %d\n", res);
1753 ok(flags, "Expected at least one flag set\n");
1754
1755 /* no space for complete string this time */
1756 buffer[0] = 0;
1757 flags = 0;
1758 res = pInternetGetConnectedStateExW(&flags, buffer, sz, 0);
1759 ok(res == TRUE, "Expected TRUE, got %d\n", res);
1760 ok(flags, "Expected at least one flag set\n");
1761 if (flags & INTERNET_CONNECTION_MODEM)
1762 ok(!buffer[0], "Expected 0 bytes, got %u\n", lstrlenW(buffer));
1763 else
1764 ok(sz - 1 == lstrlenW(buffer), "Expected %u bytes, got %u\n", sz - 1, lstrlenW(buffer));
1765
1766 buffer[0] = 0;
1767 flags = 0;
1768 res = pInternetGetConnectedStateExW(&flags, buffer, sz / 2, 0);
1769 ok(res == TRUE, "Expected TRUE, got %d\n", res);
1770 ok(flags, "Expected at least one flag set\n");
1771 if (flags & INTERNET_CONNECTION_MODEM)
1772 ok(!buffer[0], "Expected 0 bytes, got %u\n", lstrlenW(buffer));
1773 else
1774 ok(sz / 2 - 1 == lstrlenW(buffer), "Expected %u bytes, got %u\n", sz / 2 - 1, lstrlenW(buffer));
1775
1776 buffer[0] = 0;
1777 flags = 0;
1778 res = pInternetGetConnectedStateExW(&flags, buffer, 1, 0);
1779 ok(res == TRUE, "Expected TRUE, got %d\n", res);
1780 ok(flags, "Expected at least one flag set\n");
1781 ok(!buffer[0], "Expected 0 bytes, got %u\n", lstrlenW(buffer));
1782
1783 buffer[0] = 0;
1784 flags = 0;
1785 res = pInternetGetConnectedStateExW(&flags, buffer, 2, 0);
1786 ok(res == TRUE, "Expected TRUE, got %d\n", res);
1787 ok(flags, "Expected at least one flag set\n");
1788 if (flags & INTERNET_CONNECTION_MODEM)
1789 ok(!buffer[0], "Expected 0 bytes, got %u\n", lstrlenW(buffer));
1790 else
1791 ok(lstrlenW(buffer) == 1, "Expected 1 byte, got %u\n", lstrlenW(buffer));
1792
1793 buffer[0] = 0xDEAD;
1794 flags = 0;
1795 res = pInternetGetConnectedStateExW(&flags, buffer, 1, 0);
1796 ok(res == TRUE, "Expected TRUE, got %d\n", res);
1797 ok(flags, "Expected at least one flag set\n");
1798 ok(!buffer[0], "Expected 0 bytes, got %u\n", lstrlenW(buffer));
1799 }
1800
1801 /* ############################### */
1802
1803 START_TEST(internet)
1804 {
1805 HMODULE hdll;
1806 hdll = GetModuleHandleA("wininet.dll");
1807
1808 pCreateUrlCacheContainerA = (void*)GetProcAddress(hdll, "CreateUrlCacheContainerA");
1809 pCreateUrlCacheContainerW = (void*)GetProcAddress(hdll, "CreateUrlCacheContainerW");
1810 pInternetTimeFromSystemTimeA = (void*)GetProcAddress(hdll, "InternetTimeFromSystemTimeA");
1811 pInternetTimeFromSystemTimeW = (void*)GetProcAddress(hdll, "InternetTimeFromSystemTimeW");
1812 pInternetTimeToSystemTimeA = (void*)GetProcAddress(hdll, "InternetTimeToSystemTimeA");
1813 pInternetTimeToSystemTimeW = (void*)GetProcAddress(hdll, "InternetTimeToSystemTimeW");
1814 pIsDomainLegalCookieDomainW = (void*)GetProcAddress(hdll, (LPCSTR)117);
1815 pPrivacyGetZonePreferenceW = (void*)GetProcAddress(hdll, "PrivacyGetZonePreferenceW");
1816 pPrivacySetZonePreferenceW = (void*)GetProcAddress(hdll, "PrivacySetZonePreferenceW");
1817 pInternetGetCookieExA = (void*)GetProcAddress(hdll, "InternetGetCookieExA");
1818 pInternetGetCookieExW = (void*)GetProcAddress(hdll, "InternetGetCookieExW");
1819 pInternetGetConnectedStateExA = (void*)GetProcAddress(hdll, "InternetGetConnectedStateExA");
1820 pInternetGetConnectedStateExW = (void*)GetProcAddress(hdll, "InternetGetConnectedStateExW");
1821
1822 if(!pInternetGetCookieExW) {
1823 win_skip("Too old IE (older than 6.0)\n");
1824 return;
1825 }
1826
1827 test_InternetCanonicalizeUrlA();
1828 test_InternetQueryOptionA();
1829 test_InternetGetConnectedStateExA();
1830 test_InternetGetConnectedStateExW();
1831 test_get_cookie();
1832 test_complicated_cookie();
1833 test_cookie_url();
1834 test_cookie_attrs();
1835 test_version();
1836 test_null();
1837 test_Option_PerConnectionOption();
1838 test_Option_PerConnectionOptionA();
1839 test_InternetErrorDlg();
1840 test_max_conns();
1841
1842 if (!pInternetTimeFromSystemTimeA)
1843 win_skip("skipping the InternetTime tests\n");
1844 else
1845 {
1846 InternetTimeFromSystemTimeA_test();
1847 InternetTimeFromSystemTimeW_test();
1848 InternetTimeToSystemTimeA_test();
1849 InternetTimeToSystemTimeW_test();
1850 }
1851 if (pIsDomainLegalCookieDomainW &&
1852 ((void*)pIsDomainLegalCookieDomainW == (void*)pCreateUrlCacheContainerA ||
1853 (void*)pIsDomainLegalCookieDomainW == (void*)pCreateUrlCacheContainerW))
1854 win_skip("IsDomainLegalCookieDomainW is not available on systems with IE5\n");
1855 else if (!pIsDomainLegalCookieDomainW)
1856 win_skip("IsDomainLegalCookieDomainW (or ordinal 117) is not available\n");
1857 else
1858 test_IsDomainLegalCookieDomainW();
1859
1860 if (pPrivacyGetZonePreferenceW && pPrivacySetZonePreferenceW)
1861 test_PrivacyGetSetZonePreferenceW();
1862 else
1863 win_skip("Privacy[SG]etZonePreferenceW are not available\n");
1864
1865 test_InternetSetOption();
1866 test_end_browser_session();
1867 }