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