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