[WININET_WINETEST] Sync with Wine Staging 3.3. CORE-14434
[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(ses, INTERNET_OPTION_SETTINGS_CHANGED, NULL, 0);
1172 ok(ret == TRUE, "InternetSetOption should've succeeded\n");
1173
1174 ret = InternetSetOptionA(ses, INTERNET_OPTION_REFRESH, NULL, 0);
1175 ok(ret == TRUE, "InternetSetOption should've succeeded\n");
1176
1177 SetLastError(0xdeadbeef);
1178 ret = InternetSetOptionA(req, INTERNET_OPTION_REFRESH, NULL, 0);
1179 todo_wine ok(ret == FALSE, "InternetSetOption should've failed\n");
1180 todo_wine ok(GetLastError() == ERROR_INTERNET_INCORRECT_HANDLE_TYPE, "GetLastError() = %x\n", GetLastError());
1181
1182 ret = InternetCloseHandle(req);
1183 ok(ret == TRUE, "InternetCloseHandle failed: 0x%08x\n", GetLastError());
1184 ret = InternetCloseHandle(con);
1185 ok(ret == TRUE, "InternetCloseHandle failed: 0x%08x\n", GetLastError());
1186 ret = InternetCloseHandle(ses);
1187 ok(ret == TRUE, "InternetCloseHandle failed: 0x%08x\n", GetLastError());
1188 }
1189
1190 static void test_end_browser_session(void)
1191 {
1192 DWORD len;
1193 BOOL ret;
1194
1195 ret = InternetSetCookieA("http://www.example.com/test_end", NULL, "A=B");
1196 ok(ret == TRUE, "InternetSetCookie failed\n");
1197
1198 len = 1024;
1199 ret = InternetGetCookieA("http://www.example.com/test_end", NULL, NULL, &len);
1200 ok(ret == TRUE,"InternetGetCookie failed\n");
1201 ok(len != 0, "len = 0\n");
1202
1203 ret = InternetSetOptionA(NULL, INTERNET_OPTION_END_BROWSER_SESSION, NULL, 0);
1204 ok(ret, "InternetSetOption(INTERNET_OPTION_END_BROWSER_SESSION) failed: %u\n", GetLastError());
1205
1206 len = 1024;
1207 ret = InternetGetCookieA("http://www.example.com/test_end", NULL, NULL, &len);
1208 ok(!ret && GetLastError() == ERROR_NO_MORE_ITEMS, "InternetGetCookie returned %x (%u)\n", ret, GetLastError());
1209 ok(!len, "len = %u\n", len);
1210 }
1211
1212 #define verifyProxyEnable(e) r_verifyProxyEnable(__LINE__, e)
1213 static void r_verifyProxyEnable(LONG l, DWORD exp)
1214 {
1215 HKEY hkey;
1216 DWORD type, val, size = sizeof(DWORD);
1217 LONG ret;
1218 static const CHAR szInternetSettings[] = "Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings";
1219 static const CHAR szProxyEnable[] = "ProxyEnable";
1220
1221 ret = RegOpenKeyA(HKEY_CURRENT_USER, szInternetSettings, &hkey);
1222 ok_(__FILE__,l) (!ret, "RegOpenKeyA failed: 0x%08x\n", ret);
1223
1224 ret = RegQueryValueExA(hkey, szProxyEnable, 0, &type, (BYTE*)&val, &size);
1225 ok_(__FILE__,l) (!ret, "RegQueryValueExA failed: 0x%08x\n", ret);
1226 ok_(__FILE__,l) (type == REG_DWORD, "Expected regtype to be REG_DWORD, was: %d\n", type);
1227 ok_(__FILE__,l) (val == exp, "Expected ProxyEnabled to be %d, got: %d\n", exp, val);
1228
1229 ret = RegCloseKey(hkey);
1230 ok_(__FILE__,l) (!ret, "RegCloseKey failed: 0x%08x\n", ret);
1231 }
1232
1233 static void test_Option_PerConnectionOption(void)
1234 {
1235 BOOL ret;
1236 DWORD size = sizeof(INTERNET_PER_CONN_OPTION_LISTW);
1237 INTERNET_PER_CONN_OPTION_LISTW list = {size};
1238 INTERNET_PER_CONN_OPTIONW *orig_settings;
1239 static WCHAR proxy_srvW[] = {'p','r','o','x','y','.','e','x','a','m','p','l','e',0};
1240
1241 /* get the global IE proxy server info, to restore later */
1242 list.dwOptionCount = 2;
1243 list.pOptions = HeapAlloc(GetProcessHeap(), 0, 2 * sizeof(INTERNET_PER_CONN_OPTIONW));
1244
1245 list.pOptions[0].dwOption = INTERNET_PER_CONN_PROXY_SERVER;
1246 list.pOptions[1].dwOption = INTERNET_PER_CONN_FLAGS;
1247
1248 ret = InternetQueryOptionW(NULL, INTERNET_OPTION_PER_CONNECTION_OPTION,
1249 &list, &size);
1250 ok(ret == TRUE, "InternetQueryOption should've succeeded\n");
1251 orig_settings = list.pOptions;
1252
1253 /* set the global IE proxy server */
1254 list.dwOptionCount = 2;
1255 list.pOptions = HeapAlloc(GetProcessHeap(), 0, 2 * sizeof(INTERNET_PER_CONN_OPTIONW));
1256
1257 list.pOptions[0].dwOption = INTERNET_PER_CONN_PROXY_SERVER;
1258 list.pOptions[0].Value.pszValue = proxy_srvW;
1259 list.pOptions[1].dwOption = INTERNET_PER_CONN_FLAGS;
1260 list.pOptions[1].Value.dwValue = PROXY_TYPE_PROXY;
1261
1262 ret = InternetSetOptionW(NULL, INTERNET_OPTION_PER_CONNECTION_OPTION,
1263 &list, size);
1264 ok(ret == TRUE, "InternetSetOption should've succeeded\n");
1265
1266 HeapFree(GetProcessHeap(), 0, list.pOptions);
1267
1268 /* get & verify the global IE proxy server */
1269 list.dwOptionCount = 2;
1270 list.dwOptionError = 0;
1271 list.pOptions = HeapAlloc(GetProcessHeap(), 0, 2 * sizeof(INTERNET_PER_CONN_OPTIONW));
1272
1273 list.pOptions[0].dwOption = INTERNET_PER_CONN_PROXY_SERVER;
1274 list.pOptions[1].dwOption = INTERNET_PER_CONN_FLAGS;
1275
1276 ret = InternetQueryOptionW(NULL, INTERNET_OPTION_PER_CONNECTION_OPTION,
1277 &list, &size);
1278 ok(ret == TRUE, "InternetQueryOption should've succeeded\n");
1279 ok(!lstrcmpW(list.pOptions[0].Value.pszValue, proxy_srvW),
1280 "Retrieved proxy server should've been %s, was: %s\n",
1281 wine_dbgstr_w(proxy_srvW), wine_dbgstr_w(list.pOptions[0].Value.pszValue));
1282 ok(list.pOptions[1].Value.dwValue == PROXY_TYPE_PROXY,
1283 "Retrieved flags should've been PROXY_TYPE_PROXY, was: %d\n",
1284 list.pOptions[1].Value.dwValue);
1285 verifyProxyEnable(1);
1286
1287 HeapFree(GetProcessHeap(), 0, list.pOptions[0].Value.pszValue);
1288 HeapFree(GetProcessHeap(), 0, list.pOptions);
1289
1290 /* disable the proxy server */
1291 list.dwOptionCount = 1;
1292 list.pOptions = HeapAlloc(GetProcessHeap(), 0, sizeof(INTERNET_PER_CONN_OPTIONW));
1293
1294 list.pOptions[0].dwOption = INTERNET_PER_CONN_FLAGS;
1295 list.pOptions[0].Value.dwValue = PROXY_TYPE_DIRECT;
1296
1297 ret = InternetSetOptionW(NULL, INTERNET_OPTION_PER_CONNECTION_OPTION,
1298 &list, size);
1299 ok(ret == TRUE, "InternetSetOption should've succeeded\n");
1300
1301 HeapFree(GetProcessHeap(), 0, list.pOptions);
1302
1303 /* verify that the proxy is disabled */
1304 list.dwOptionCount = 1;
1305 list.dwOptionError = 0;
1306 list.pOptions = HeapAlloc(GetProcessHeap(), 0, sizeof(INTERNET_PER_CONN_OPTIONW));
1307
1308 list.pOptions[0].dwOption = INTERNET_PER_CONN_FLAGS;
1309
1310 ret = InternetQueryOptionW(NULL, INTERNET_OPTION_PER_CONNECTION_OPTION,
1311 &list, &size);
1312 ok(ret == TRUE, "InternetQueryOption should've succeeded\n");
1313 ok(list.pOptions[0].Value.dwValue == PROXY_TYPE_DIRECT,
1314 "Retrieved flags should've been PROXY_TYPE_DIRECT, was: %d\n",
1315 list.pOptions[0].Value.dwValue);
1316 verifyProxyEnable(0);
1317
1318 HeapFree(GetProcessHeap(), 0, list.pOptions);
1319
1320 /* set the proxy flags to 'invalid' value */
1321 list.dwOptionCount = 1;
1322 list.pOptions = HeapAlloc(GetProcessHeap(), 0, sizeof(INTERNET_PER_CONN_OPTIONW));
1323
1324 list.pOptions[0].dwOption = INTERNET_PER_CONN_FLAGS;
1325 list.pOptions[0].Value.dwValue = PROXY_TYPE_PROXY | PROXY_TYPE_DIRECT;
1326
1327 ret = InternetSetOptionW(NULL, INTERNET_OPTION_PER_CONNECTION_OPTION,
1328 &list, size);
1329 ok(ret == TRUE, "InternetSetOption should've succeeded\n");
1330
1331 HeapFree(GetProcessHeap(), 0, list.pOptions);
1332
1333 /* verify that the proxy is enabled */
1334 list.dwOptionCount = 1;
1335 list.dwOptionError = 0;
1336 list.pOptions = HeapAlloc(GetProcessHeap(), 0, sizeof(INTERNET_PER_CONN_OPTIONW));
1337
1338 list.pOptions[0].dwOption = INTERNET_PER_CONN_FLAGS;
1339
1340 ret = InternetQueryOptionW(NULL, INTERNET_OPTION_PER_CONNECTION_OPTION,
1341 &list, &size);
1342 ok(ret == TRUE, "InternetQueryOption should've succeeded\n");
1343 todo_wine ok(list.pOptions[0].Value.dwValue == (PROXY_TYPE_PROXY | PROXY_TYPE_DIRECT),
1344 "Retrieved flags should've been PROXY_TYPE_PROXY | PROXY_TYPE_DIRECT, was: %d\n",
1345 list.pOptions[0].Value.dwValue);
1346 verifyProxyEnable(1);
1347
1348 HeapFree(GetProcessHeap(), 0, list.pOptions);
1349
1350 /* restore original settings */
1351 list.dwOptionCount = 2;
1352 list.pOptions = orig_settings;
1353
1354 ret = InternetSetOptionW(NULL, INTERNET_OPTION_PER_CONNECTION_OPTION,
1355 &list, size);
1356 ok(ret == TRUE, "InternetSetOption should've succeeded\n");
1357
1358 HeapFree(GetProcessHeap(), 0, list.pOptions);
1359 }
1360
1361 static void test_Option_PerConnectionOptionA(void)
1362 {
1363 BOOL ret;
1364 DWORD size = sizeof(INTERNET_PER_CONN_OPTION_LISTA);
1365 INTERNET_PER_CONN_OPTION_LISTA list = {size};
1366 INTERNET_PER_CONN_OPTIONA *orig_settings;
1367 char proxy_srv[] = "proxy.example";
1368
1369 /* get the global IE proxy server info, to restore later */
1370 list.dwOptionCount = 2;
1371 list.pOptions = HeapAlloc(GetProcessHeap(), 0, 2 * sizeof(INTERNET_PER_CONN_OPTIONA));
1372
1373 list.pOptions[0].dwOption = INTERNET_PER_CONN_PROXY_SERVER;
1374 list.pOptions[1].dwOption = INTERNET_PER_CONN_FLAGS;
1375
1376 ret = InternetQueryOptionA(NULL, INTERNET_OPTION_PER_CONNECTION_OPTION,
1377 &list, &size);
1378 ok(ret == TRUE, "InternetQueryOption should've succeeded\n");
1379 orig_settings = list.pOptions;
1380
1381 /* set the global IE proxy server */
1382 list.dwOptionCount = 2;
1383 list.pOptions = HeapAlloc(GetProcessHeap(), 0, 2 * sizeof(INTERNET_PER_CONN_OPTIONA));
1384
1385 list.pOptions[0].dwOption = INTERNET_PER_CONN_PROXY_SERVER;
1386 list.pOptions[0].Value.pszValue = proxy_srv;
1387 list.pOptions[1].dwOption = INTERNET_PER_CONN_FLAGS;
1388 list.pOptions[1].Value.dwValue = PROXY_TYPE_PROXY;
1389
1390 ret = InternetSetOptionA(NULL, INTERNET_OPTION_PER_CONNECTION_OPTION,
1391 &list, size);
1392 ok(ret == TRUE, "InternetSetOption should've succeeded\n");
1393
1394 HeapFree(GetProcessHeap(), 0, list.pOptions);
1395
1396 /* get & verify the global IE proxy server */
1397 list.dwOptionCount = 2;
1398 list.dwOptionError = 0;
1399 list.pOptions = HeapAlloc(GetProcessHeap(), 0, 2 * sizeof(INTERNET_PER_CONN_OPTIONA));
1400
1401 list.pOptions[0].dwOption = INTERNET_PER_CONN_PROXY_SERVER;
1402 list.pOptions[1].dwOption = INTERNET_PER_CONN_FLAGS;
1403
1404 ret = InternetQueryOptionA(NULL, INTERNET_OPTION_PER_CONNECTION_OPTION,
1405 &list, &size);
1406 ok(ret == TRUE, "InternetQueryOption should've succeeded\n");
1407 ok(!lstrcmpA(list.pOptions[0].Value.pszValue, "proxy.example"),
1408 "Retrieved proxy server should've been \"%s\", was: \"%s\"\n",
1409 proxy_srv, list.pOptions[0].Value.pszValue);
1410 ok(list.pOptions[1].Value.dwValue == PROXY_TYPE_PROXY,
1411 "Retrieved flags should've been PROXY_TYPE_PROXY, was: %d\n",
1412 list.pOptions[1].Value.dwValue);
1413
1414 HeapFree(GetProcessHeap(), 0, list.pOptions[0].Value.pszValue);
1415 HeapFree(GetProcessHeap(), 0, list.pOptions);
1416
1417 /* test with NULL as proxy server */
1418 list.dwOptionCount = 1;
1419 list.pOptions = HeapAlloc(GetProcessHeap(), 0, sizeof(INTERNET_PER_CONN_OPTIONA));
1420 list.pOptions[0].dwOption = INTERNET_PER_CONN_PROXY_SERVER;
1421 list.pOptions[0].Value.pszValue = NULL;
1422
1423 ret = InternetSetOptionA(NULL, INTERNET_OPTION_PER_CONNECTION_OPTION, &list, size);
1424 ok(ret == TRUE, "InternetSetOption should've succeeded\n");
1425
1426 ret = InternetSetOptionA(NULL, INTERNET_OPTION_PER_CONNECTION_OPTION, &list, size);
1427 ok(ret == TRUE, "InternetSetOption should've succeeded\n");
1428
1429 HeapFree(GetProcessHeap(), 0, list.pOptions);
1430
1431 /* get & verify the proxy server */
1432 list.dwOptionCount = 1;
1433 list.dwOptionError = 0;
1434 list.pOptions = HeapAlloc(GetProcessHeap(), 0, sizeof(INTERNET_PER_CONN_OPTIONA));
1435 list.pOptions[0].dwOption = INTERNET_PER_CONN_PROXY_SERVER;
1436
1437 ret = InternetQueryOptionA(NULL, INTERNET_OPTION_PER_CONNECTION_OPTION, &list, &size);
1438 ok(ret == TRUE, "InternetQueryOption should've succeeded\n");
1439 ok(!list.pOptions[0].Value.pszValue,
1440 "Retrieved proxy server should've been NULL, was: \"%s\"\n",
1441 list.pOptions[0].Value.pszValue);
1442
1443 HeapFree(GetProcessHeap(), 0, list.pOptions[0].Value.pszValue);
1444 HeapFree(GetProcessHeap(), 0, list.pOptions);
1445
1446 /* restore original settings */
1447 list.dwOptionCount = 2;
1448 list.pOptions = orig_settings;
1449
1450 ret = InternetSetOptionA(NULL, INTERNET_OPTION_PER_CONNECTION_OPTION,
1451 &list, size);
1452 ok(ret == TRUE, "InternetSetOption should've succeeded\n");
1453
1454 HeapFree(GetProcessHeap(), 0, list.pOptions);
1455 }
1456
1457 #define FLAG_TODO 0x1
1458 #define FLAG_NEEDREQ 0x2
1459 #define FLAG_UNIMPL 0x4
1460
1461 static void test_InternetErrorDlg(void)
1462 {
1463 HINTERNET ses, con, req;
1464 DWORD res, flags;
1465 HWND hwnd;
1466 ULONG i;
1467 static const struct {
1468 DWORD error;
1469 DWORD res;
1470 DWORD test_flags;
1471 } no_ui_res[] = {
1472 { ERROR_INTERNET_INCORRECT_PASSWORD , ERROR_SUCCESS, FLAG_NEEDREQ },
1473 { ERROR_INTERNET_SEC_CERT_DATE_INVALID , ERROR_CANCELLED, 0 },
1474 { ERROR_INTERNET_SEC_CERT_CN_INVALID , ERROR_CANCELLED, 0 },
1475 { ERROR_INTERNET_HTTP_TO_HTTPS_ON_REDIR , ERROR_SUCCESS, 0 },
1476 { ERROR_INTERNET_HTTPS_TO_HTTP_ON_REDIR , ERROR_SUCCESS, FLAG_TODO },
1477 { ERROR_INTERNET_MIXED_SECURITY , ERROR_CANCELLED, FLAG_TODO },
1478 { ERROR_INTERNET_CHG_POST_IS_NON_SECURE , ERROR_CANCELLED, FLAG_TODO },
1479 { ERROR_INTERNET_POST_IS_NON_SECURE , ERROR_SUCCESS, 0 },
1480 { ERROR_INTERNET_CLIENT_AUTH_CERT_NEEDED, ERROR_CANCELLED, FLAG_NEEDREQ|FLAG_TODO },
1481 { ERROR_INTERNET_INVALID_CA , ERROR_CANCELLED, 0 },
1482 { ERROR_INTERNET_HTTPS_HTTP_SUBMIT_REDIR, ERROR_CANCELLED, FLAG_TODO },
1483 { ERROR_INTERNET_INSERT_CDROM , ERROR_CANCELLED, FLAG_TODO|FLAG_NEEDREQ|FLAG_UNIMPL },
1484 { ERROR_INTERNET_SEC_CERT_ERRORS , ERROR_CANCELLED, 0 },
1485 { ERROR_INTERNET_SEC_CERT_REV_FAILED , ERROR_CANCELLED, 0 },
1486 { ERROR_HTTP_COOKIE_NEEDS_CONFIRMATION , ERROR_HTTP_COOKIE_DECLINED, FLAG_TODO },
1487 { ERROR_INTERNET_BAD_AUTO_PROXY_SCRIPT , ERROR_CANCELLED, FLAG_TODO },
1488 { ERROR_INTERNET_UNABLE_TO_DOWNLOAD_SCRIPT, ERROR_CANCELLED, FLAG_TODO },
1489 { ERROR_HTTP_REDIRECT_NEEDS_CONFIRMATION, ERROR_CANCELLED, FLAG_TODO },
1490 { ERROR_INTERNET_SEC_CERT_REVOKED , ERROR_CANCELLED, 0 },
1491 { 0, ERROR_NOT_SUPPORTED }
1492 };
1493
1494 flags = 0;
1495
1496 res = InternetErrorDlg(NULL, NULL, 12055, flags, NULL);
1497 ok(res == ERROR_INVALID_HANDLE, "Got %d\n", res);
1498
1499 ses = InternetOpenA(NULL, INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, 0);
1500 ok(ses != 0, "InternetOpen failed: 0x%08x\n", GetLastError());
1501 con = InternetConnectA(ses, "www.winehq.org", 80, NULL, NULL, INTERNET_SERVICE_HTTP, 0, 0);
1502 ok(con != 0, "InternetConnect failed: 0x%08x\n", GetLastError());
1503 req = HttpOpenRequestA(con, "GET", "/", NULL, NULL, NULL, 0, 0);
1504 ok(req != 0, "HttpOpenRequest failed: 0x%08x\n", GetLastError());
1505
1506 /* NULL hwnd and FLAGS_ERROR_UI_FLAGS_NO_UI not set */
1507 for(i = INTERNET_ERROR_BASE; i < INTERNET_ERROR_LAST; i++)
1508 {
1509 res = InternetErrorDlg(NULL, req, i, flags, NULL);
1510 ok(res == ERROR_INVALID_HANDLE, "Got %d (%d)\n", res, i);
1511 }
1512
1513 hwnd = GetDesktopWindow();
1514 ok(hwnd != NULL, "GetDesktopWindow failed (%d)\n", GetLastError());
1515
1516 flags = FLAGS_ERROR_UI_FLAGS_NO_UI;
1517 for(i = INTERNET_ERROR_BASE; i < INTERNET_ERROR_LAST; i++)
1518 {
1519 DWORD expected, test_flags, j;
1520
1521 for(j = 0; no_ui_res[j].error != 0; ++j)
1522 if(no_ui_res[j].error == i)
1523 break;
1524
1525 test_flags = no_ui_res[j].test_flags;
1526 expected = no_ui_res[j].res;
1527
1528 /* Try an invalid request handle */
1529 res = InternetErrorDlg(hwnd, (HANDLE)0xdeadbeef, i, flags, NULL);
1530 if(res == ERROR_CALL_NOT_IMPLEMENTED)
1531 {
1532 ok(test_flags & FLAG_UNIMPL, "%i is unexpectedly unimplemented.\n", i);
1533 continue;
1534 }
1535 else
1536 ok(res == ERROR_INVALID_HANDLE, "Got %d (%d)\n", res, i);
1537
1538 /* With a valid req */
1539 if(i == ERROR_INTERNET_NEED_UI)
1540 continue; /* Crashes on windows XP */
1541
1542 if(i == ERROR_INTERNET_SEC_CERT_REVOKED)
1543 continue; /* Interactive (XP, Win7) */
1544
1545 res = InternetErrorDlg(hwnd, req, i, flags, NULL);
1546
1547 /* Handle some special cases */
1548 switch(i)
1549 {
1550 case ERROR_INTERNET_HTTP_TO_HTTPS_ON_REDIR:
1551 case ERROR_INTERNET_HTTPS_TO_HTTP_ON_REDIR:
1552 if(res == ERROR_CANCELLED)
1553 {
1554 /* Some windows XP, w2k3 x64, W2K8 */
1555 win_skip("Skipping some tests for %d\n", i);
1556 continue;
1557 }
1558 break;
1559 case ERROR_INTERNET_FORTEZZA_LOGIN_NEEDED:
1560 if(res != expected)
1561 {
1562 /* Windows XP, W2K3 */
1563 ok(res == NTE_PROV_TYPE_NOT_DEF, "Got %d\n", res);
1564 win_skip("Skipping some tests for %d\n", i);
1565 continue;
1566 }
1567 break;
1568 case ERROR_INTERNET_CHG_POST_IS_NON_SECURE:
1569 if(res == ERROR_SUCCESS) /* win10 returns ERROR_SUCCESS */
1570 expected = ERROR_SUCCESS;
1571 break;
1572 default: break;
1573 }
1574
1575 todo_wine_if(test_flags & FLAG_TODO)
1576 ok(res == expected, "Got %d, expected %d (%d)\n", res, expected, i);
1577
1578 /* Same thing with NULL hwnd */
1579 res = InternetErrorDlg(NULL, req, i, flags, NULL);
1580 todo_wine_if(test_flags & FLAG_TODO)
1581 ok(res == expected, "Got %d, expected %d (%d)\n", res, expected, i);
1582
1583
1584 /* With a null req */
1585 if(test_flags & FLAG_NEEDREQ)
1586 expected = ERROR_INVALID_PARAMETER;
1587
1588 res = InternetErrorDlg(hwnd, NULL, i, flags, NULL);
1589 todo_wine_if( test_flags & FLAG_TODO || i == ERROR_INTERNET_INCORRECT_PASSWORD)
1590 ok(res == expected, "Got %d, expected %d (%d)\n", res, expected, i);
1591 }
1592
1593 res = InternetCloseHandle(req);
1594 ok(res == TRUE, "InternetCloseHandle failed: 0x%08x\n", GetLastError());
1595 res = InternetCloseHandle(con);
1596 ok(res == TRUE, "InternetCloseHandle failed: 0x%08x\n", GetLastError());
1597 res = InternetCloseHandle(ses);
1598 ok(res == TRUE, "InternetCloseHandle failed: 0x%08x\n", GetLastError());
1599 }
1600
1601 static void test_InternetGetConnectedStateExA(void)
1602 {
1603 BOOL res;
1604 CHAR buffer[256];
1605 DWORD flags, sz;
1606
1607 if(!pInternetGetConnectedStateExA) {
1608 win_skip("InternetGetConnectedStateExA is not supported\n");
1609 return;
1610 }
1611
1612 flags = 0;
1613 buffer[0] = 0;
1614 res = pInternetGetConnectedStateExA(&flags, buffer, sizeof(buffer), 0);
1615 trace("Internet Connection: Flags 0x%02x - Name '%s'\n", flags, buffer);
1616 todo_wine
1617 ok (flags & INTERNET_RAS_INSTALLED, "Missing RAS flag\n");
1618 if(!res) {
1619 win_skip("InternetGetConnectedStateExA tests require a valid connection\n");
1620 return;
1621 }
1622
1623 res = pInternetGetConnectedStateExA(NULL, NULL, 0, 0);
1624 ok(res == TRUE, "Expected TRUE, got %d\n", res);
1625
1626 flags = 0;
1627 res = pInternetGetConnectedStateExA(&flags, NULL, 0, 0);
1628 ok(res == TRUE, "Expected TRUE, got %d\n", res);
1629 if (flags & INTERNET_CONNECTION_CONFIGURED)
1630 {
1631 ok(flags & INTERNET_CONNECTION_MODEM, "Modem connection flag missing\n");
1632 ok(flags & ~INTERNET_CONNECTION_LAN, "Mixed Modem and LAN flags\n");
1633 }
1634 else
1635 {
1636 ok(flags & INTERNET_CONNECTION_LAN, "LAN connection flag missing\n");
1637 ok(flags & ~INTERNET_CONNECTION_MODEM, "Mixed Modem and LAN flags\n");
1638 }
1639
1640 buffer[0] = 0;
1641 flags = 0;
1642 res = pInternetGetConnectedStateExA(&flags, buffer, 0, 0);
1643 ok(res == TRUE, "Expected TRUE, got %d\n", res);
1644 ok(flags, "Expected at least one flag set\n");
1645 ok(!buffer[0], "Buffer must not change, got %02X\n", buffer[0]);
1646
1647 buffer[0] = 0;
1648 res = pInternetGetConnectedStateExA(NULL, buffer, sizeof(buffer), 0);
1649 ok(res == TRUE, "Expected TRUE, got %d\n", res);
1650 sz = strlen(buffer);
1651 ok(sz > 0, "Expected a connection name\n");
1652
1653 buffer[0] = 0;
1654 flags = 0;
1655 res = pInternetGetConnectedStateExA(&flags, buffer, sizeof(buffer), 0);
1656 ok(res == TRUE, "Expected TRUE, got %d\n", res);
1657 ok(flags, "Expected at least one flag set\n");
1658 sz = strlen(buffer);
1659 ok(sz > 0, "Expected a connection name\n");
1660
1661 flags = 0;
1662 res = pInternetGetConnectedStateExA(&flags, NULL, sizeof(buffer), 0);
1663 ok(res == TRUE, "Expected TRUE, got %d\n", res);
1664 ok(flags, "Expected at least one flag set\n");
1665
1666 /* no space for complete string this time */
1667 buffer[0] = 0;
1668 flags = 0;
1669 res = pInternetGetConnectedStateExA(&flags, buffer, sz, 0);
1670 ok(res == TRUE, "Expected TRUE, got %d\n", res);
1671 ok(flags, "Expected at least one flag set\n");
1672 ok(sz - 1 == strlen(buffer), "Expected %u bytes, got %u\n", sz - 1, lstrlenA(buffer));
1673
1674 buffer[0] = 0;
1675 flags = 0;
1676 res = pInternetGetConnectedStateExA(&flags, buffer, sz / 2, 0);
1677 ok(res == TRUE, "Expected TRUE, got %d\n", res);
1678 ok(flags, "Expected at least one flag set\n");
1679 ok(sz / 2 - 1 == strlen(buffer), "Expected %u bytes, got %u\n", sz / 2 - 1, lstrlenA(buffer));
1680
1681 buffer[0] = 0;
1682 flags = 0;
1683 res = pInternetGetConnectedStateExA(&flags, buffer, 1, 0);
1684 ok(res == TRUE, "Expected TRUE, got %d\n", res);
1685 ok(flags, "Expected at least one flag set\n");
1686 ok(!buffer[0], "Expected 0 bytes, got %u\n", lstrlenA(buffer));
1687
1688 buffer[0] = 0;
1689 flags = 0;
1690 res = pInternetGetConnectedStateExA(&flags, buffer, 2, 0);
1691 ok(res == TRUE, "Expected TRUE, got %d\n", res);
1692 ok(flags, "Expected at least one flag set\n");
1693 ok(strlen(buffer) == 1, "Expected 1 byte, got %u\n", lstrlenA(buffer));
1694
1695 flags = 0;
1696 buffer[0] = 0xDE;
1697 res = pInternetGetConnectedStateExA(&flags, buffer, 1, 0);
1698 ok(res == TRUE, "Expected TRUE, got %d\n", res);
1699 ok(flags, "Expected at least one flag set\n");
1700 ok(!buffer[0], "Expected 0 bytes, got %u\n", lstrlenA(buffer));
1701 }
1702
1703 static void test_InternetGetConnectedStateExW(void)
1704 {
1705 BOOL res;
1706 WCHAR buffer[256];
1707 DWORD flags, sz;
1708
1709 if(!pInternetGetConnectedStateExW) {
1710 win_skip("InternetGetConnectedStateExW is not supported\n");
1711 return;
1712 }
1713
1714 flags = 0;
1715 buffer[0] = 0;
1716 res = pInternetGetConnectedStateExW(&flags, buffer, sizeof(buffer) / sizeof(buffer[0]), 0);
1717 trace("Internet Connection: Flags 0x%02x - Name '%s'\n", flags, wine_dbgstr_w(buffer));
1718 todo_wine
1719 ok (flags & INTERNET_RAS_INSTALLED, "Missing RAS flag\n");
1720 if(!res) {
1721 win_skip("InternetGetConnectedStateExW tests require a valid connection\n");
1722 return;
1723 }
1724
1725 res = pInternetGetConnectedStateExW(NULL, NULL, 0, 0);
1726 ok(res == TRUE, "Expected TRUE, got %d\n", res);
1727
1728 flags = 0;
1729 res = pInternetGetConnectedStateExW(&flags, NULL, 0, 0);
1730 ok(res == TRUE, "Expected TRUE, got %d\n", res);
1731 if (flags & INTERNET_CONNECTION_CONFIGURED)
1732 {
1733 ok(flags & INTERNET_CONNECTION_MODEM, "Modem connection flag missing\n");
1734 ok(flags & ~INTERNET_CONNECTION_LAN, "Mixed Modem and LAN flags\n");
1735 }
1736 else
1737 {
1738 ok(flags & INTERNET_CONNECTION_LAN, "LAN connection flag missing\n");
1739 ok(flags & ~INTERNET_CONNECTION_MODEM, "Mixed Modem and LAN flags\n");
1740 }
1741
1742 buffer[0] = 0;
1743 flags = 0;
1744 res = pInternetGetConnectedStateExW(&flags, buffer, 0, 0);
1745 ok(res == TRUE, "Expected TRUE, got %d\n", res);
1746 ok(flags, "Expected at least one flag set\n");
1747 ok(!buffer[0], "Buffer must not change, got %02X\n", buffer[0]);
1748
1749 buffer[0] = 0;
1750 res = pInternetGetConnectedStateExW(NULL, buffer, sizeof(buffer) / sizeof(buffer[0]), 0);
1751 ok(res == TRUE, "Expected TRUE, got %d\n", res);
1752 sz = lstrlenW(buffer);
1753 ok(sz > 0, "Expected a connection name\n");
1754
1755 buffer[0] = 0;
1756 flags = 0;
1757 res = pInternetGetConnectedStateExW(&flags, buffer, sizeof(buffer) / sizeof(buffer[0]), 0);
1758 ok(res == TRUE, "Expected TRUE, got %d\n", res);
1759 ok(flags, "Expected at least one flag set\n");
1760 sz = lstrlenW(buffer);
1761 ok(sz > 0, "Expected a connection name\n");
1762
1763 flags = 0;
1764 res = pInternetGetConnectedStateExW(&flags, NULL, sizeof(buffer) / sizeof(buffer[0]), 0);
1765 ok(res == TRUE, "Expected TRUE, got %d\n", res);
1766 ok(flags, "Expected at least one flag set\n");
1767
1768 /* no space for complete string this time */
1769 buffer[0] = 0;
1770 flags = 0;
1771 res = pInternetGetConnectedStateExW(&flags, buffer, sz, 0);
1772 ok(res == TRUE, "Expected TRUE, got %d\n", res);
1773 ok(flags, "Expected at least one flag set\n");
1774 if (flags & INTERNET_CONNECTION_MODEM)
1775 ok(!buffer[0], "Expected 0 bytes, got %u\n", lstrlenW(buffer));
1776 else
1777 ok(sz - 1 == lstrlenW(buffer), "Expected %u bytes, got %u\n", sz - 1, lstrlenW(buffer));
1778
1779 buffer[0] = 0;
1780 flags = 0;
1781 res = pInternetGetConnectedStateExW(&flags, buffer, sz / 2, 0);
1782 ok(res == TRUE, "Expected TRUE, got %d\n", res);
1783 ok(flags, "Expected at least one flag set\n");
1784 if (flags & INTERNET_CONNECTION_MODEM)
1785 ok(!buffer[0], "Expected 0 bytes, got %u\n", lstrlenW(buffer));
1786 else
1787 ok(sz / 2 - 1 == lstrlenW(buffer), "Expected %u bytes, got %u\n", sz / 2 - 1, lstrlenW(buffer));
1788
1789 buffer[0] = 0;
1790 flags = 0;
1791 res = pInternetGetConnectedStateExW(&flags, buffer, 1, 0);
1792 ok(res == TRUE, "Expected TRUE, got %d\n", res);
1793 ok(flags, "Expected at least one flag set\n");
1794 ok(!buffer[0], "Expected 0 bytes, got %u\n", lstrlenW(buffer));
1795
1796 buffer[0] = 0;
1797 flags = 0;
1798 res = pInternetGetConnectedStateExW(&flags, buffer, 2, 0);
1799 ok(res == TRUE, "Expected TRUE, got %d\n", res);
1800 ok(flags, "Expected at least one flag set\n");
1801 if (flags & INTERNET_CONNECTION_MODEM)
1802 ok(!buffer[0], "Expected 0 bytes, got %u\n", lstrlenW(buffer));
1803 else
1804 ok(lstrlenW(buffer) == 1, "Expected 1 byte, got %u\n", lstrlenW(buffer));
1805
1806 buffer[0] = 0xDEAD;
1807 flags = 0;
1808 res = pInternetGetConnectedStateExW(&flags, buffer, 1, 0);
1809 ok(res == TRUE, "Expected TRUE, got %d\n", res);
1810 ok(flags, "Expected at least one flag set\n");
1811 ok(!buffer[0], "Expected 0 bytes, got %u\n", lstrlenW(buffer));
1812 }
1813
1814 /* ############################### */
1815
1816 START_TEST(internet)
1817 {
1818 HMODULE hdll;
1819 hdll = GetModuleHandleA("wininet.dll");
1820
1821 pCreateUrlCacheContainerA = (void*)GetProcAddress(hdll, "CreateUrlCacheContainerA");
1822 pCreateUrlCacheContainerW = (void*)GetProcAddress(hdll, "CreateUrlCacheContainerW");
1823 pInternetTimeFromSystemTimeA = (void*)GetProcAddress(hdll, "InternetTimeFromSystemTimeA");
1824 pInternetTimeFromSystemTimeW = (void*)GetProcAddress(hdll, "InternetTimeFromSystemTimeW");
1825 pInternetTimeToSystemTimeA = (void*)GetProcAddress(hdll, "InternetTimeToSystemTimeA");
1826 pInternetTimeToSystemTimeW = (void*)GetProcAddress(hdll, "InternetTimeToSystemTimeW");
1827 pIsDomainLegalCookieDomainW = (void*)GetProcAddress(hdll, (LPCSTR)117);
1828 pPrivacyGetZonePreferenceW = (void*)GetProcAddress(hdll, "PrivacyGetZonePreferenceW");
1829 pPrivacySetZonePreferenceW = (void*)GetProcAddress(hdll, "PrivacySetZonePreferenceW");
1830 pInternetGetCookieExA = (void*)GetProcAddress(hdll, "InternetGetCookieExA");
1831 pInternetGetCookieExW = (void*)GetProcAddress(hdll, "InternetGetCookieExW");
1832 pInternetGetConnectedStateExA = (void*)GetProcAddress(hdll, "InternetGetConnectedStateExA");
1833 pInternetGetConnectedStateExW = (void*)GetProcAddress(hdll, "InternetGetConnectedStateExW");
1834
1835 if(!pInternetGetCookieExW) {
1836 win_skip("Too old IE (older than 6.0)\n");
1837 return;
1838 }
1839
1840 test_InternetCanonicalizeUrlA();
1841 test_InternetQueryOptionA();
1842 test_InternetGetConnectedStateExA();
1843 test_InternetGetConnectedStateExW();
1844 test_get_cookie();
1845 test_complicated_cookie();
1846 test_cookie_url();
1847 test_cookie_attrs();
1848 test_version();
1849 test_null();
1850 test_Option_PerConnectionOption();
1851 test_Option_PerConnectionOptionA();
1852 test_InternetErrorDlg();
1853 test_max_conns();
1854
1855 if (!pInternetTimeFromSystemTimeA)
1856 win_skip("skipping the InternetTime tests\n");
1857 else
1858 {
1859 InternetTimeFromSystemTimeA_test();
1860 InternetTimeFromSystemTimeW_test();
1861 InternetTimeToSystemTimeA_test();
1862 InternetTimeToSystemTimeW_test();
1863 }
1864 if (pIsDomainLegalCookieDomainW &&
1865 ((void*)pIsDomainLegalCookieDomainW == (void*)pCreateUrlCacheContainerA ||
1866 (void*)pIsDomainLegalCookieDomainW == (void*)pCreateUrlCacheContainerW))
1867 win_skip("IsDomainLegalCookieDomainW is not available on systems with IE5\n");
1868 else if (!pIsDomainLegalCookieDomainW)
1869 win_skip("IsDomainLegalCookieDomainW (or ordinal 117) is not available\n");
1870 else
1871 test_IsDomainLegalCookieDomainW();
1872
1873 if (pPrivacyGetZonePreferenceW && pPrivacySetZonePreferenceW)
1874 test_PrivacyGetSetZonePreferenceW();
1875 else
1876 win_skip("Privacy[SG]etZonePreferenceW are not available\n");
1877
1878 test_InternetSetOption();
1879 test_end_browser_session();
1880 }