53cbb3ce88b4994eb40faf7ea6b78b5ae3d2b43f
[reactos.git] / rostests / winetests / urlmon / misc.c
1 /*
2 * Copyright 2005-2006 Jacek Caban for CodeWeavers
3 *
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
8 *
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
17 */
18
19 #define WIN32_NO_STATUS
20 #define _INC_WINDOWS
21 #define COM_NO_WINDOWS_H
22
23 #define COBJMACROS
24 #define CONST_VTABLE
25 #define NONAMELESSUNION
26
27 #include <wine/test.h>
28 //#include <stdarg.h>
29 //#include <stddef.h>
30 #include <stdio.h>
31
32 //#include "windef.h"
33 //#include "winbase.h"
34 #include <winreg.h>
35 #include <winnls.h>
36 #include <ole2.h>
37 //#include "urlmon.h"
38
39 #include <initguid.h>
40
41 DEFINE_GUID(CLSID_AboutProtocol, 0x3050F406, 0x98B5, 0x11CF, 0xBB,0x82, 0x00,0xAA,0x00,0xBD,0xCE,0x0B);
42
43 #define DEFINE_EXPECT(func) \
44 static BOOL expect_ ## func = FALSE, called_ ## func = FALSE
45
46 #define SET_EXPECT(func) \
47 expect_ ## func = TRUE
48
49 #define CHECK_EXPECT(func) \
50 do { \
51 ok(expect_ ##func, "unexpected call " #func "\n"); \
52 expect_ ## func = FALSE; \
53 called_ ## func = TRUE; \
54 }while(0)
55
56 #define CHECK_EXPECT2(func) \
57 do { \
58 ok(expect_ ##func, "unexpected call " #func "\n"); \
59 called_ ## func = TRUE; \
60 }while(0)
61
62 #define CHECK_CALLED(func) \
63 do { \
64 ok(called_ ## func, "expected " #func "\n"); \
65 expect_ ## func = called_ ## func = FALSE; \
66 }while(0)
67
68 DEFINE_EXPECT(ParseUrl);
69 DEFINE_EXPECT(QI_IInternetProtocolInfo);
70 DEFINE_EXPECT(CreateInstance);
71 DEFINE_EXPECT(unk_Release);
72
73 static HRESULT (WINAPI *pCoInternetCompareUrl)(LPCWSTR, LPCWSTR, DWORD);
74 static HRESULT (WINAPI *pCoInternetGetSecurityUrl)(LPCWSTR, LPWSTR*, PSUACTION, DWORD);
75 static HRESULT (WINAPI *pCoInternetGetSession)(DWORD, IInternetSession **, DWORD);
76 static HRESULT (WINAPI *pCoInternetParseUrl)(LPCWSTR, PARSEACTION, DWORD, LPWSTR, DWORD, DWORD *, DWORD);
77 static HRESULT (WINAPI *pCoInternetQueryInfo)(LPCWSTR, QUERYOPTION, DWORD, LPVOID, DWORD, DWORD *, DWORD);
78 static HRESULT (WINAPI *pCopyStgMedium)(const STGMEDIUM *, STGMEDIUM *);
79 static HRESULT (WINAPI *pCopyBindInfo)(const BINDINFO *, BINDINFO *);
80 static HRESULT (WINAPI *pFindMimeFromData)(LPBC, LPCWSTR, LPVOID, DWORD, LPCWSTR,
81 DWORD, LPWSTR*, DWORD);
82 static HRESULT (WINAPI *pObtainUserAgentString)(DWORD, LPSTR, DWORD*);
83 static HRESULT (WINAPI *pReleaseBindInfo)(BINDINFO*);
84 static HRESULT (WINAPI *pUrlMkGetSessionOption)(DWORD, LPVOID, DWORD, DWORD *, DWORD);
85 static HRESULT (WINAPI *pCompareSecurityIds)(BYTE*,DWORD,BYTE*,DWORD,DWORD);
86 static HRESULT (WINAPI *pCoInternetIsFeatureEnabled)(INTERNETFEATURELIST,DWORD);
87 static HRESULT (WINAPI *pCoInternetSetFeatureEnabled)(INTERNETFEATURELIST,DWORD,BOOL);
88 static HRESULT (WINAPI *pIEInstallScope)(DWORD*);
89
90 static int strcmp_wa(const WCHAR *strw, const char *stra)
91 {
92 WCHAR buf[512];
93 MultiByteToWideChar(CP_ACP, 0, stra, -1, buf, sizeof(buf)/sizeof(WCHAR));
94 return lstrcmpW(strw, buf);
95 }
96
97 static void heap_free(void *mem)
98 {
99 HeapFree(GetProcessHeap(), 0, mem);
100 }
101
102 static WCHAR *a2w(const char *str)
103 {
104 WCHAR *ret;
105 int len;
106
107 if(!str)
108 return NULL;
109
110 len = MultiByteToWideChar(CP_ACP, 0, str, -1, NULL, 0);
111 ret = HeapAlloc(GetProcessHeap(), 0, len*sizeof(WCHAR));
112 MultiByteToWideChar(CP_ACP, 0, str, -1, ret, len);
113
114 return ret;
115 }
116
117 static void test_CreateFormatEnum(void)
118 {
119 IEnumFORMATETC *fenum = NULL, *fenum2 = NULL;
120 FORMATETC fetc[5];
121 ULONG ul;
122 HRESULT hres;
123
124 static DVTARGETDEVICE dev = {sizeof(dev),0,0,0,0,{0}};
125 static FORMATETC formatetc[] = {
126 {0,&dev,0,0,0},
127 {0,&dev,0,1,0},
128 {0,NULL,0,2,0},
129 {0,NULL,0,3,0},
130 {0,NULL,0,4,0}
131 };
132
133 hres = CreateFormatEnumerator(0, formatetc, &fenum);
134 ok(hres == E_FAIL, "CreateFormatEnumerator failed: %08x, expected E_FAIL\n", hres);
135 hres = CreateFormatEnumerator(0, formatetc, NULL);
136 ok(hres == E_INVALIDARG, "CreateFormatEnumerator failed: %08x, expected E_INVALIDARG\n", hres);
137 hres = CreateFormatEnumerator(5, formatetc, NULL);
138 ok(hres == E_INVALIDARG, "CreateFormatEnumerator failed: %08x, expected E_INVALIDARG\n", hres);
139
140
141 hres = CreateFormatEnumerator(5, formatetc, &fenum);
142 ok(hres == S_OK, "CreateFormatEnumerator failed: %08x\n", hres);
143 if(FAILED(hres))
144 return;
145
146 hres = IEnumFORMATETC_Next(fenum, 2, NULL, &ul);
147 ok(hres == E_INVALIDARG, "Next failed: %08x, expected E_INVALIDARG\n", hres);
148 ul = 100;
149 hres = IEnumFORMATETC_Next(fenum, 0, fetc, &ul);
150 ok(hres == S_OK, "Next failed: %08x\n", hres);
151 ok(ul == 0, "ul=%d, expected 0\n", ul);
152
153 hres = IEnumFORMATETC_Next(fenum, 2, fetc, &ul);
154 ok(hres == S_OK, "Next failed: %08x\n", hres);
155 ok(fetc[0].lindex == 0, "fetc[0].lindex=%d, expected 0\n", fetc[0].lindex);
156 ok(fetc[1].lindex == 1, "fetc[1].lindex=%d, expected 1\n", fetc[1].lindex);
157 ok(fetc[0].ptd == &dev, "fetc[0].ptd=%p, expected %p\n", fetc[0].ptd, &dev);
158 ok(ul == 2, "ul=%d, expected 2\n", ul);
159
160 hres = IEnumFORMATETC_Skip(fenum, 1);
161 ok(hres == S_OK, "Skip failed: %08x\n", hres);
162
163 hres = IEnumFORMATETC_Next(fenum, 4, fetc, &ul);
164 ok(hres == S_FALSE, "Next failed: %08x, expected S_FALSE\n", hres);
165 ok(fetc[0].lindex == 3, "fetc[0].lindex=%d, expected 3\n", fetc[0].lindex);
166 ok(fetc[1].lindex == 4, "fetc[1].lindex=%d, expected 4\n", fetc[1].lindex);
167 ok(fetc[0].ptd == NULL, "fetc[0].ptd=%p, expected NULL\n", fetc[0].ptd);
168 ok(ul == 2, "ul=%d, expected 2\n", ul);
169
170 hres = IEnumFORMATETC_Next(fenum, 4, fetc, &ul);
171 ok(hres == S_FALSE, "Next failed: %08x, expected S_FALSE\n", hres);
172 ok(ul == 0, "ul=%d, expected 0\n", ul);
173 ul = 100;
174 hres = IEnumFORMATETC_Next(fenum, 0, fetc, &ul);
175 ok(hres == S_OK, "Next failed: %08x\n", hres);
176 ok(ul == 0, "ul=%d, expected 0\n", ul);
177
178 hres = IEnumFORMATETC_Skip(fenum, 3);
179 ok(hres == S_FALSE, "Skip failed: %08x, expected S_FALSE\n", hres);
180
181 hres = IEnumFORMATETC_Reset(fenum);
182 ok(hres == S_OK, "Reset failed: %08x\n", hres);
183
184 hres = IEnumFORMATETC_Next(fenum, 5, fetc, NULL);
185 ok(hres == S_OK, "Next failed: %08x\n", hres);
186 ok(fetc[0].lindex == 0, "fetc[0].lindex=%d, expected 0\n", fetc[0].lindex);
187
188 hres = IEnumFORMATETC_Reset(fenum);
189 ok(hres == S_OK, "Reset failed: %08x\n", hres);
190
191 hres = IEnumFORMATETC_Skip(fenum, 2);
192 ok(hres == S_OK, "Skip failed: %08x\n", hres);
193
194 hres = IEnumFORMATETC_Clone(fenum, NULL);
195 ok(hres == E_INVALIDARG, "Clone failed: %08x, expected E_INVALIDARG\n", hres);
196
197 hres = IEnumFORMATETC_Clone(fenum, &fenum2);
198 ok(hres == S_OK, "Clone failed: %08x\n", hres);
199
200 if(SUCCEEDED(hres)) {
201 ok(fenum != fenum2, "fenum == fenum2\n");
202
203 hres = IEnumFORMATETC_Next(fenum2, 2, fetc, &ul);
204 ok(hres == S_OK, "Next failed: %08x\n", hres);
205 ok(fetc[0].lindex == 2, "fetc[0].lindex=%d, expected 2\n", fetc[0].lindex);
206
207 IEnumFORMATETC_Release(fenum2);
208 }
209
210 hres = IEnumFORMATETC_Next(fenum, 2, fetc, &ul);
211 ok(hres == S_OK, "Next failed: %08x\n", hres);
212 ok(fetc[0].lindex == 2, "fetc[0].lindex=%d, expected 2\n", fetc[0].lindex);
213
214 hres = IEnumFORMATETC_Skip(fenum, 1);
215 ok(hres == S_OK, "Skip failed: %08x\n", hres);
216
217 IEnumFORMATETC_Release(fenum);
218 }
219
220 static void test_RegisterFormatEnumerator(void)
221 {
222 IBindCtx *bctx = NULL;
223 IEnumFORMATETC *format = NULL, *format2 = NULL;
224 IUnknown *unk = NULL;
225 HRESULT hres;
226
227 static FORMATETC formatetc = {0,NULL,0,0,0};
228 static WCHAR wszEnumFORMATETC[] =
229 {'_','E','n','u','m','F','O','R','M','A','T','E','T','C','_',0};
230
231 CreateBindCtx(0, &bctx);
232
233 hres = CreateFormatEnumerator(1, &formatetc, &format);
234 ok(hres == S_OK, "CreateFormatEnumerator failed: %08x\n", hres);
235 if(FAILED(hres))
236 return;
237
238 hres = RegisterFormatEnumerator(NULL, format, 0);
239 ok(hres == E_INVALIDARG,
240 "RegisterFormatEnumerator failed: %08x, expected E_INVALIDARG\n", hres);
241 hres = RegisterFormatEnumerator(bctx, NULL, 0);
242 ok(hres == E_INVALIDARG,
243 "RegisterFormatEnumerator failed: %08x, expected E_INVALIDARG\n", hres);
244
245 hres = RegisterFormatEnumerator(bctx, format, 0);
246 ok(hres == S_OK, "RegisterFormatEnumerator failed: %08x\n", hres);
247
248 hres = IBindCtx_GetObjectParam(bctx, wszEnumFORMATETC, &unk);
249 ok(hres == S_OK, "GetObjectParam failed: %08x\n", hres);
250 ok(unk == (IUnknown*)format, "unk != format\n");
251
252 hres = RevokeFormatEnumerator(NULL, format);
253 ok(hres == E_INVALIDARG,
254 "RevokeFormatEnumerator failed: %08x, expected E_INVALIDARG\n", hres);
255
256 hres = RevokeFormatEnumerator(bctx, format);
257 ok(hres == S_OK, "RevokeFormatEnumerator failed: %08x\n", hres);
258
259 hres = RevokeFormatEnumerator(bctx, format);
260 ok(hres == E_FAIL, "RevokeFormatEnumerator failed: %08x, expected E_FAIL\n", hres);
261
262 hres = IBindCtx_GetObjectParam(bctx, wszEnumFORMATETC, &unk);
263 ok(hres == E_FAIL, "GetObjectParam failed: %08x, expected E_FAIL\n", hres);
264
265 hres = RegisterFormatEnumerator(bctx, format, 0);
266 ok(hres == S_OK, "RegisterFormatEnumerator failed: %08x\n", hres);
267
268 hres = CreateFormatEnumerator(1, &formatetc, &format2);
269 ok(hres == S_OK, "CreateFormatEnumerator failed: %08x\n", hres);
270
271 if(SUCCEEDED(hres)) {
272 hres = RevokeFormatEnumerator(bctx, format);
273 ok(hres == S_OK, "RevokeFormatEnumerator failed: %08x\n", hres);
274
275 IEnumFORMATETC_Release(format2);
276 }
277
278 hres = IBindCtx_GetObjectParam(bctx, wszEnumFORMATETC, &unk);
279 ok(hres == E_FAIL, "GetObjectParam failed: %08x, expected E_FAIL\n", hres);
280
281 IEnumFORMATETC_Release(format);
282
283 hres = RegisterFormatEnumerator(bctx, format, 0);
284 ok(hres == S_OK, "RegisterFormatEnumerator failed: %08x\n", hres);
285 hres = RevokeFormatEnumerator(bctx, NULL);
286 ok(hres == S_OK, "RevokeFormatEnumerator failed: %08x\n", hres);
287 hres = IBindCtx_GetObjectParam(bctx, wszEnumFORMATETC, &unk);
288 ok(hres == E_FAIL, "GetObjectParam failed: %08x, expected E_FAIL\n", hres);
289
290 IEnumFORMATETC_Release(format);
291 IBindCtx_Release(bctx);
292 }
293 static const WCHAR url1[] = {'r','e','s',':','/','/','m','s','h','t','m','l','.','d','l','l',
294 '/','b','l','a','n','k','.','h','t','m',0};
295 static const WCHAR url2[] = {'i','n','d','e','x','.','h','t','m',0};
296 static const WCHAR url3[] = {'f','i','l','e',':','/','/','c',':','\\','I','n','d','e','x','.','h','t','m',0};
297 static const WCHAR url4[] = {'f','i','l','e',':','s','o','m','e','%','2','0','f','i','l','e',
298 '%','2','e','j','p','g',0};
299 static const WCHAR url5[] = {'h','t','t','p',':','/','/','w','w','w','.','w','i','n','e','h','q',
300 '.','o','r','g',0};
301 static const WCHAR url6[] = {'a','b','o','u','t',':','b','l','a','n','k',0};
302 static const WCHAR url7[] = {'f','t','p',':','/','/','w','i','n','e','h','q','.','o','r','g','/',
303 'f','i','l','e','.','t','e','s','t',0};
304 static const WCHAR url8[] = {'t','e','s','t',':','1','2','3','a','b','c',0};
305 static const WCHAR url9[] =
306 {'h','t','t','p',':','/','/','w','w','w','.','w','i','n','e','h','q','.','o','r','g',
307 '/','s','i','t','e','/','a','b','o','u','t',0};
308 static const WCHAR url10[] = {'h','t','t','p',':','/','/','g','o','o','g','l','e','.','*','.',
309 'c','o','m',0};
310 static const WCHAR url4e[] = {'f','i','l','e',':','s','o','m','e',' ','f','i','l','e',
311 '.','j','p','g',0};
312
313 static const WCHAR path3[] = {'c',':','\\','I','n','d','e','x','.','h','t','m',0};
314 static const WCHAR path4[] = {'s','o','m','e',' ','f','i','l','e','.','j','p','g',0};
315
316 static const WCHAR wszRes[] = {'r','e','s',0};
317 static const WCHAR wszFile[] = {'f','i','l','e',0};
318 static const WCHAR wszHttp[] = {'h','t','t','p',0};
319 static const WCHAR wszAbout[] = {'a','b','o','u','t',0};
320 static const WCHAR wszEmpty[] = {0};
321 static const WCHAR wszGoogle[] = {'g','o','o','g','l','e','.','*','.','c','o','m',0};
322
323 static const WCHAR wszWineHQ[] = {'w','w','w','.','w','i','n','e','h','q','.','o','r','g',0};
324 static const WCHAR wszHttpWineHQ[] = {'h','t','t','p',':','/','/','w','w','w','.',
325 'w','i','n','e','h','q','.','o','r','g',0};
326 static const WCHAR wszHttpGoogle[] = {'h','t','t','p',':','/','/','g','o','o','g','l','e',
327 '.','*','.','c','o','m',0};
328
329 struct parse_test {
330 LPCWSTR url;
331 HRESULT secur_hres;
332 LPCWSTR encoded_url;
333 HRESULT path_hres;
334 LPCWSTR path;
335 LPCWSTR schema;
336 LPCWSTR domain;
337 HRESULT domain_hres;
338 LPCWSTR rootdocument;
339 HRESULT rootdocument_hres;
340 };
341
342 static const struct parse_test parse_tests[] = {
343 {url1, S_OK, url1, E_INVALIDARG, NULL, wszRes, NULL, E_FAIL, NULL, E_FAIL},
344 {url2, E_FAIL, url2, E_INVALIDARG, NULL, wszEmpty, NULL, E_FAIL, NULL, E_FAIL},
345 {url3, E_FAIL, url3, S_OK, path3, wszFile, wszEmpty, S_OK, NULL, E_FAIL},
346 {url4, E_FAIL, url4e, S_OK, path4, wszFile, wszEmpty, S_OK, NULL, E_FAIL},
347 {url5, E_FAIL, url5, E_INVALIDARG, NULL, wszHttp, wszWineHQ, S_OK, wszHttpWineHQ, S_OK},
348 {url6, S_OK, url6, E_INVALIDARG, NULL, wszAbout, NULL, E_FAIL, NULL, E_FAIL},
349 {url10, E_FAIL, url10, E_INVALIDARG,NULL, wszHttp, wszGoogle, S_OK, wszHttpGoogle, S_OK}
350 };
351
352 static void test_CoInternetParseUrl(void)
353 {
354 HRESULT hres;
355 DWORD size;
356 int i;
357
358 static WCHAR buf[4096];
359
360 memset(buf, 0xf0, sizeof(buf));
361 hres = pCoInternetParseUrl(parse_tests[0].url, PARSE_SCHEMA, 0, buf,
362 3, &size, 0);
363 ok(hres == E_POINTER, "schema failed: %08x, expected E_POINTER\n", hres);
364
365 for(i=0; i < sizeof(parse_tests)/sizeof(parse_tests[0]); i++) {
366 memset(buf, 0xf0, sizeof(buf));
367 hres = pCoInternetParseUrl(parse_tests[i].url, PARSE_SECURITY_URL, 0, buf,
368 sizeof(buf)/sizeof(WCHAR), &size, 0);
369 ok(hres == parse_tests[i].secur_hres, "[%d] security url failed: %08x, expected %08x\n",
370 i, hres, parse_tests[i].secur_hres);
371
372 memset(buf, 0xf0, sizeof(buf));
373 hres = pCoInternetParseUrl(parse_tests[i].url, PARSE_ENCODE, 0, buf,
374 sizeof(buf)/sizeof(WCHAR), &size, 0);
375 ok(hres == S_OK, "[%d] encoding failed: %08x\n", i, hres);
376 ok(size == lstrlenW(parse_tests[i].encoded_url), "[%d] wrong size\n", i);
377 ok(!lstrcmpW(parse_tests[i].encoded_url, buf), "[%d] wrong encoded url\n", i);
378
379 memset(buf, 0xf0, sizeof(buf));
380 hres = pCoInternetParseUrl(parse_tests[i].url, PARSE_PATH_FROM_URL, 0, buf,
381 sizeof(buf)/sizeof(WCHAR), &size, 0);
382 ok(hres == parse_tests[i].path_hres, "[%d] path failed: %08x, expected %08x\n",
383 i, hres, parse_tests[i].path_hres);
384 if(parse_tests[i].path) {
385 ok(size == lstrlenW(parse_tests[i].path), "[%d] wrong size\n", i);
386 ok(!lstrcmpW(parse_tests[i].path, buf), "[%d] wrong path\n", i);
387 }
388
389 memset(buf, 0xf0, sizeof(buf));
390 hres = pCoInternetParseUrl(parse_tests[i].url, PARSE_SCHEMA, 0, buf,
391 sizeof(buf)/sizeof(WCHAR), &size, 0);
392 ok(hres == S_OK, "[%d] schema failed: %08x\n", i, hres);
393 ok(size == lstrlenW(parse_tests[i].schema), "[%d] wrong size\n", i);
394 ok(!lstrcmpW(parse_tests[i].schema, buf), "[%d] wrong schema\n", i);
395
396 if(memcmp(parse_tests[i].url, wszRes, 3*sizeof(WCHAR))
397 && memcmp(parse_tests[i].url, wszAbout, 5*sizeof(WCHAR))) {
398 memset(buf, 0xf0, sizeof(buf));
399 hres = pCoInternetParseUrl(parse_tests[i].url, PARSE_DOMAIN, 0, buf,
400 sizeof(buf)/sizeof(WCHAR), &size, 0);
401 ok(hres == parse_tests[i].domain_hres, "[%d] domain failed: %08x\n", i, hres);
402 if(parse_tests[i].domain)
403 ok(!lstrcmpW(parse_tests[i].domain, buf), "[%d] wrong domain, received %s\n", i, wine_dbgstr_w(buf));
404 }
405
406 memset(buf, 0xf0, sizeof(buf));
407 hres = pCoInternetParseUrl(parse_tests[i].url, PARSE_ROOTDOCUMENT, 0, buf,
408 sizeof(buf)/sizeof(WCHAR), &size, 0);
409 ok(hres == parse_tests[i].rootdocument_hres, "[%d] rootdocument failed: %08x\n", i, hres);
410 if(parse_tests[i].rootdocument)
411 ok(!lstrcmpW(parse_tests[i].rootdocument, buf), "[%d] wrong rootdocument, received %s\n", i, wine_dbgstr_w(buf));
412 }
413 }
414
415 static void test_CoInternetCompareUrl(void)
416 {
417 HRESULT hres;
418
419 hres = pCoInternetCompareUrl(url1, url1, 0);
420 ok(hres == S_OK, "CoInternetCompareUrl failed: %08x\n", hres);
421
422 hres = pCoInternetCompareUrl(url1, url3, 0);
423 ok(hres == S_FALSE, "CoInternetCompareUrl failed: %08x\n", hres);
424
425 hres = pCoInternetCompareUrl(url3, url1, 0);
426 ok(hres == S_FALSE, "CoInternetCompareUrl failed: %08x\n", hres);
427 }
428
429 static const struct {
430 LPCWSTR url;
431 DWORD uses_net;
432 } query_info_tests[] = {
433 {url1, 0},
434 {url2, 0},
435 {url3, 0},
436 {url4, 0},
437 {url5, 0},
438 {url6, 0},
439 {url7, 0},
440 {url8, 0}
441 };
442
443 static void test_CoInternetQueryInfo(void)
444 {
445 BYTE buf[100];
446 DWORD cb, i;
447 HRESULT hres;
448
449 for(i=0; i < sizeof(query_info_tests)/sizeof(query_info_tests[0]); i++) {
450 cb = 0xdeadbeef;
451 memset(buf, '?', sizeof(buf));
452 hres = pCoInternetQueryInfo(query_info_tests[0].url, QUERY_USES_NETWORK, 0, buf, sizeof(buf), &cb, 0);
453 ok(hres == S_OK, "[%d] CoInternetQueryInfo failed: %08x\n", i, hres);
454 ok(cb == sizeof(DWORD), "[%d] cb = %d\n", i, cb);
455 ok(*(DWORD*)buf == query_info_tests[i].uses_net, "[%d] ret %x, expected %x\n",
456 i, *(DWORD*)buf, query_info_tests[i].uses_net);
457
458 hres = pCoInternetQueryInfo(query_info_tests[0].url, QUERY_USES_NETWORK, 0, buf, 3, &cb, 0);
459 ok(hres == E_FAIL, "[%d] CoInternetQueryInfo failed: %08x, expected E_FAIL\n", i, hres);
460 hres = pCoInternetQueryInfo(query_info_tests[0].url, QUERY_USES_NETWORK, 0, NULL, sizeof(buf), &cb, 0);
461 ok(hres == E_FAIL, "[%d] CoInternetQueryInfo failed: %08x, expected E_FAIL\n", i, hres);
462
463 memset(buf, '?', sizeof(buf));
464 hres = pCoInternetQueryInfo(query_info_tests[0].url, QUERY_USES_NETWORK, 0, buf, sizeof(buf), NULL, 0);
465 ok(hres == S_OK, "[%d] CoInternetQueryInfo failed: %08x\n", i, hres);
466 ok(*(DWORD*)buf == query_info_tests[i].uses_net, "[%d] ret %x, expected %x\n",
467 i, *(DWORD*)buf, query_info_tests[i].uses_net);
468 }
469 }
470
471 static const struct {
472 const char *url;
473 const char *mime;
474 HRESULT hres;
475 BOOL broken_failure;
476 const char *broken_mime;
477 } mime_tests[] = {
478 {"res://mshtml.dll/blank.htm", "text/html", S_OK},
479 {"index.htm", "text/html", S_OK},
480 {"file://c:\\Index.htm", "text/html", S_OK},
481 {"file://c:\\Index.htm?q=test", "text/html", S_OK, TRUE},
482 {"file://c:\\Index.htm#hash_part", "text/html", S_OK, TRUE},
483 {"file://c:\\Index.htm#hash_part.txt", "text/html", S_OK, FALSE, "text/plain"},
484 {"file://some%20file%2ejpg", NULL, E_FAIL},
485 {"http://www.winehq.org", NULL, __HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND)},
486 {"about:blank", NULL, E_FAIL},
487 {"ftp://winehq.org/file.test", NULL, __HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND)}
488 };
489
490 static BYTE data1[] = "test data\n";
491 static BYTE data2[] = {31,'t','e','s',0xfa,'t',' ','d','a','t','a','\n',0};
492 static BYTE data3[] = {0,0,0};
493 static BYTE data4[] = {'t','e','s',0xfa,'t',' ','d','a','t','a','\n',0,0};
494 static BYTE data5[] = {0xa,0xa,0xa,'x',32,'x',0};
495 static BYTE data6[] = {0xfa,0xfa,0xfa,0xfa,'\n','\r','\t','x','x','x',1};
496 static BYTE data7[] = "<html>blahblah";
497 static BYTE data8[] = {'t','e','s',0xfa,'t',' ','<','h','t','m','l','>','d','a','t','a','\n',0,0};
498 static BYTE data9[] = {'t','e',0,'s',0xfa,'t',' ','<','h','t','m','l','>','d','a','t','a','\n',0,0};
499 static BYTE data10[] = "<HtmL>blahblah";
500 static BYTE data11[] = "blah<HTML>blahblah";
501 static BYTE data12[] = "blah<HTMLblahblah";
502 static BYTE data13[] = "blahHTML>blahblah";
503 static BYTE data14[] = "blah<HTMblahblah";
504 static BYTE data15[] = {0xff,0xd8};
505 static BYTE data16[] = {0xff,0xd8,'h'};
506 static BYTE data17[] = {0,0xff,0xd8};
507 static BYTE data18[] = {0xff,0xd8,'<','h','t','m','l','>'};
508 static BYTE data19[] = {'G','I','F','8','7','a'};
509 static BYTE data20[] = {'G','I','F','8','9','a'};
510 static BYTE data21[] = {'G','I','F','8','7'};
511 static BYTE data22[] = {'G','i','F','8','7','a'};
512 static BYTE data23[] = {'G','i','F','8','8','a'};
513 static BYTE data24[] = {'g','i','f','8','7','a'};
514 static BYTE data25[] = {'G','i','F','8','7','A'};
515 static BYTE data26[] = {'G','i','F','8','7','a','<','h','t','m','l','>'};
516 static BYTE data27[] = {0x30,'G','i','F','8','7','A'};
517 static BYTE data28[] = {0x42,0x4d,0x6e,0x42,0x1c,0x00,0x00,0x00,0x00,0x00,0x36,0x00,0x00,0x00};
518 static BYTE data29[] = {0x42,0x4d,'x','x','x','x',0x00,0x00,0x00,0x00,'x','x','x','x'};
519 static BYTE data30[] = {0x42,0x4d,'x','x','x','x',0x00,0x01,0x00,0x00,'x','x','x','x'};
520 static BYTE data31[] = {0x42,0x4d,'x','x','x','x',0x00,0x00,0x00,0x00,'<','h','t','m','l','>'};
521 static BYTE data32[] = {0x42,0x4d,'x','x','x','x',0x00,0x00,0x00,0x00,'x','x','x'};
522 static BYTE data33[] = {0x00,0x42,0x4d,'x','x','x','x',0x00,0x00,0x00,0x00,'x','x','x'};
523 static BYTE data34[] = {0x89,'P','N','G',0x0d,0x0a,0x1a,0x0a,'x'};
524 static BYTE data35[] = {0x89,'P','N','G',0x0d,0x0a,0x1a,0x0a,'x','x','x','x',0};
525 static BYTE data36[] = {0x89,'P','N','G',0x0d,0x0a,0x1a,'x','x'};
526 static BYTE data37[] = {0x89,'P','N','G',0x0d,0x0a,0x1a,0x0a,'<','h','t','m','l','>'};
527 static BYTE data38[] = {0x00,0x89,'P','N','G',0x0d,0x0a,0x1a,0x0a,'x'};
528 static BYTE data39[] = {0x4d,0x4d,0x00,0x2a,0xff};
529 static BYTE data40[] = {0x4d,0x4d,0x00,0x2a,'<','h','t','m','l','>',0};
530 static BYTE data41[] = {0x4d,0x4d,0xff};
531 static BYTE data42[] = {0x4d,0x4d};
532 static BYTE data43[] = {0x00,0x4d,0x4d,0x00};
533 static BYTE data44[] = {'R','I','F','F',0xff,0xff,0xff,0xff,'A','V','I',0x20,0xff};
534 static BYTE data45[] = {'R','I','F','f',0xff,0xff,0xff,0xff,'A','V','I',0x20,0xff};
535 static BYTE data46[] = {'R','I','F','F',0xff,0xff,0xff,0xff,'A','V','I',0x20};
536 static BYTE data47[] = {'R','I','F','F',0xff,0xff,0xff,0xff,'A','V','I',0x21,0xff};
537 static BYTE data48[] = {'R','I','F','F',0xff,0xff,0xff,0xff,'A','V','I',0x20,'<','h','t','m','l','>'};
538 static BYTE data49[] = {'R','I','F','F',0x0f,0x0f,0xf0,0xf0,'A','V','I',0x20,0xf0,0x00};
539 static BYTE data50[] = {0x00,0x00,0x01,0xb3,0xff};
540 static BYTE data51[] = {0x00,0x00,0x01,0xba,0xff};
541 static BYTE data52[] = {0x00,0x00,0x01,0xb8,0xff};
542 static BYTE data53[] = {0x00,0x00,0x01,0xba};
543 static BYTE data54[] = {0x00,0x00,0x01,0xba,'<','h','t','m','l','>'};
544 static BYTE data55[] = {0x1f,0x8b,'x'};
545 static BYTE data56[] = {0x1f};
546 static BYTE data57[] = {0x1f,0x8b,'<','h','t','m','l','>','t','e','s','t',0};
547 static BYTE data58[] = {0x1f,0x8b};
548 static BYTE data59[] = {0x50,0x4b,'x'};
549 static BYTE data60[] = {0x50,0x4b};
550 static BYTE data61[] = {0x50,0x4b,'<','h','t','m','l','>',0};
551 static BYTE data62[] = {0xca,0xfe,0xba,0xbe,'x'};
552 static BYTE data63[] = {0xca,0xfe,0xba,0xbe};
553 static BYTE data64[] = {0xca,0xfe,0xba,0xbe,'<','h','t','m','l','>',0};
554 static BYTE data65[] = {0x25,0x50,0x44,0x46,'x'};
555 static BYTE data66[] = {0x25,0x50,0x44,0x46};
556 static BYTE data67[] = {0x25,0x50,0x44,0x46,'x','<','h','t','m','l','>'};
557 static BYTE data68[] = {'M','Z','x'};
558 static BYTE data69[] = {'M','Z'};
559 static BYTE data70[] = {'M','Z','<','h','t','m','l','>',0xff};
560 static BYTE data71[] = {'{','\\','r','t','f',0};
561 static BYTE data72[] = {'{','\\','r','t','f'};
562 static BYTE data73[] = {' ','{','\\','r','t','f',' '};
563 static BYTE data74[] = {'{','\\','r','t','f','<','h','t','m','l','>',' '};
564 static BYTE data75[] = {'R','I','F','F',0xff,0xff,0xff,0xff,'W','A','V','E',0xff};
565 static BYTE data76[] = {'R','I','F','F',0xff,0xff,0xff,0xff,'W','A','V','E'};
566 static BYTE data77[] = {'R','I','F','F',0xff,0xff,0xff,0xff,'W','A','V',0xff,0xff};
567 static BYTE data78[] = {'R','I','F','F',0xff,0xff,0xff,0xff,'<','h','t','m','l','>',0xff};
568 static BYTE data79[] = {'%','!',0xff};
569 static BYTE data80[] = {'%','!'};
570 static BYTE data81[] = {'%','!','P','S','<','h','t','m','l','>'};
571 static BYTE data82[] = {'.','s','n','d',0};
572 static BYTE data83[] = {'.','s','n','d'};
573 static BYTE data84[] = {'.','s','n','d',0,'<','h','t','m','l','>',1,1};
574 static BYTE data85[] = {'.','S','N','D',0};
575 static BYTE data86[] = {0x49,0x49,0x2a,0xff};
576 static BYTE data87[] = {' ','<','h','e','a','d'};
577 static BYTE data88[] = {' ','<','h','e','a','d','>'};
578 static BYTE data89[] = {'\t','\r','<','h','e','a','d','>'};
579 static BYTE data90[] = {'<','H','e','A','d',' '};
580 static BYTE data91[] = {'<','?','x','m','l',' ',0};
581 static BYTE data92[] = {'a','b','c','<','?','x','m','l',' ',' '};
582 static BYTE data93[] = {'<','?','x','m','l',' ',' ','<','h','t','m','l','>'};
583 static BYTE data94[] = {'<','h','t','m','l','>','<','?','x','m','l',' ',' '};
584 static BYTE data95[] = {'{','\\','r','t','f','<','?','x','m','l',' ',' '};
585 static BYTE data96[] = {'<','?','x','m','l',' '};
586 static BYTE data97[] = "<body";
587 static BYTE data98[] = "blah<BoDyblahblah";
588
589 static const struct {
590 BYTE *data;
591 DWORD size;
592 const char *mime;
593 const char *mime_pjpeg;
594 const char *broken_mime;
595 const char *url;
596 const char *proposed_mime;
597 } mime_tests2[] = {
598 {data1, sizeof(data1), "text/plain"},
599 {data2, sizeof(data2), "application/octet-stream", "image/pjpeg"},
600 {data3, sizeof(data3), "application/octet-stream", "image/pjpeg"},
601 {data4, sizeof(data4), "application/octet-stream", "image/pjpeg"},
602 {data5, sizeof(data5), "text/plain"},
603 {data6, sizeof(data6), "text/plain"},
604 {data7, sizeof(data7), "text/html", "text/plain"},
605 {data8, sizeof(data8), "text/html", "text/plain"},
606 {data9, sizeof(data9), "text/html", "image/pjpeg"},
607 {data10, sizeof(data10), "text/html", "text/plain"},
608 {data11, sizeof(data11), "text/html", "text/plain"},
609 {data12, sizeof(data12), "text/html", "text/plain"},
610 {data13, sizeof(data13), "text/plain"},
611 {data14, sizeof(data14), "text/plain"},
612 {data15, sizeof(data15), "text/plain"},
613 {data16, sizeof(data16), "image/pjpeg"},
614 {data17, sizeof(data17), "application/octet-stream", "image/pjpeg"},
615 {data18, sizeof(data18), "text/html", "image/pjpeg"},
616 {data19, sizeof(data19), "image/gif"},
617 {data20, sizeof(data20), "image/gif"},
618 {data21, sizeof(data21), "text/plain"},
619 {data22, sizeof(data22), "image/gif"},
620 {data23, sizeof(data23), "text/plain"},
621 {data24, sizeof(data24), "image/gif"},
622 {data25, sizeof(data25), "image/gif"},
623 {data26, sizeof(data26), "text/html", "image/gif"},
624 {data27, sizeof(data27), "text/plain"},
625 {data28, sizeof(data28), "image/bmp"},
626 {data29, sizeof(data29), "image/bmp"},
627 {data30, sizeof(data30), "application/octet-stream", "image/pjpeg"},
628 {data31, sizeof(data31), "text/html", "image/bmp"},
629 {data32, sizeof(data32), "application/octet-stream", "image/pjpeg"},
630 {data33, sizeof(data33), "application/octet-stream", "image/pjpeg"},
631 {data34, sizeof(data34), "image/x-png"},
632 {data35, sizeof(data35), "image/x-png"},
633 {data36, sizeof(data36), "application/octet-stream", "image/pjpeg"},
634 {data37, sizeof(data37), "text/html", "image/x-png"},
635 {data38, sizeof(data38), "application/octet-stream", "image/pjpeg"},
636 {data39, sizeof(data39), "image/tiff"},
637 {data40, sizeof(data40), "text/html", "image/tiff"},
638 {data41, sizeof(data41), "text/plain", NULL, "image/tiff"},
639 {data42, sizeof(data42), "text/plain"},
640 {data43, sizeof(data43), "application/octet-stream", "image/pjpeg"},
641 {data44, sizeof(data44), "video/avi"},
642 {data45, sizeof(data45), "text/plain"},
643 {data46, sizeof(data46), "text/plain"},
644 {data47, sizeof(data47), "text/plain"},
645 {data48, sizeof(data48), "text/html", "video/avi"},
646 {data49, sizeof(data49), "video/avi"},
647 {data50, sizeof(data50), "video/mpeg"},
648 {data51, sizeof(data51), "video/mpeg"},
649 {data52, sizeof(data52), "application/octet-stream", "image/pjpeg"},
650 {data53, sizeof(data53), "application/octet-stream", "image/pjpeg"},
651 {data54, sizeof(data54), "text/html", "video/mpeg"},
652 {data55, sizeof(data55), "application/x-gzip-compressed"},
653 {data56, sizeof(data56), "text/plain"},
654 {data57, sizeof(data57), "text/html", "application/x-gzip-compressed"},
655 {data58, sizeof(data58), "application/octet-stream", "image/pjpeg"},
656 {data59, sizeof(data59), "application/x-zip-compressed"},
657 {data60, sizeof(data60), "text/plain"},
658 {data61, sizeof(data61), "text/html", "application/x-zip-compressed"},
659 {data62, sizeof(data62), "application/java"},
660 {data63, sizeof(data63), "text/plain"},
661 {data64, sizeof(data64), "text/html", "application/java"},
662 {data65, sizeof(data65), "application/pdf"},
663 {data66, sizeof(data66), "text/plain"},
664 {data67, sizeof(data67), "text/html", "application/pdf"},
665 {data68, sizeof(data68), "application/x-msdownload"},
666 {data69, sizeof(data69), "text/plain"},
667 {data70, sizeof(data70), "text/html", "application/x-msdownload"},
668 {data71, sizeof(data71), "text/richtext"},
669 {data72, sizeof(data72), "text/plain"},
670 {data73, sizeof(data73), "text/plain"},
671 {data74, sizeof(data74), "text/html", "text/richtext"},
672 {data75, sizeof(data75), "audio/wav"},
673 {data76, sizeof(data76), "text/plain"},
674 {data77, sizeof(data77), "text/plain"},
675 {data78, sizeof(data78), "text/html", "text/plain"},
676 {data79, sizeof(data79), "application/postscript"},
677 {data80, sizeof(data80), "text/plain"},
678 {data81, sizeof(data81), "text/html", "application/postscript"},
679 {data82, sizeof(data82), "audio/basic"},
680 {data83, sizeof(data83), "text/plain"},
681 {data84, sizeof(data84), "text/html", "audio/basic"},
682 {data85, sizeof(data85), "text/plain"},
683 {data86, sizeof(data86), "image/tiff", NULL, "text/plain"},
684 {data87, sizeof(data87), "text/plain"},
685 {data88, sizeof(data88), "text/html", "text/plain"},
686 {data89, sizeof(data89), "text/html", "text/plain"},
687 {data90, sizeof(data90), "text/html", "text/plain"},
688 {data91, sizeof(data91), "text/xml", "text/plain"},
689 {data92, sizeof(data92), "text/xml", "text/plain"},
690 {data93, sizeof(data93), "text/xml", "text/plain"},
691 {data94, sizeof(data94), "text/html", "text/plain"},
692 {data95, sizeof(data95), "text/xml", "text/richtext"},
693 {data96, sizeof(data96), "text/plain"},
694 {data97, sizeof(data97), "text/html", "text/plain"},
695 {data98, sizeof(data98), "text/html", "text/plain"},
696 {data1, sizeof(data1), "text/plain", NULL, NULL, "res://mshtml.dll/blank.htm"},
697 {NULL, 0, "text/html", NULL, NULL, "res://mshtml.dll/blank.htm"},
698 {data1, sizeof(data1), "text/plain", NULL, NULL, "res://mshtml.dll/blank.htm", "application/octet-stream"},
699 {data1, sizeof(data1), "text/plain", NULL, NULL, "file:some%20file%2ejpg", "application/octet-stream"},
700 {NULL, sizeof(data1), "text/html", NULL, NULL, "res://mshtml.dll/blank.htm"},
701 {data1, sizeof(data1), "text/css", NULL, NULL, "http://www.winehq.org/test.css"},
702 {data2, sizeof(data2), "text/css", NULL, NULL, "http://www.winehq.org/test.css"},
703 {data10, sizeof(data10), "text/html", NULL, NULL, "http://www.winehq.org/test.css"},
704 {data1, sizeof(data1), "text/css", NULL, NULL, "http://www.winehq.org/test.css", "text/plain"},
705 {data1, sizeof(data1), "text/css", NULL, NULL, "http://www.winehq.org/test.css", "application/octet-stream"},
706 {data1, sizeof(data1), "text/test", NULL, NULL, "http://www.winehq.org/test.css", "text/test"}
707 };
708
709 static void test_FindMimeFromData(void)
710 {
711 WCHAR *mime, *proposed_mime, *url;
712 HRESULT hres;
713 BYTE b;
714 int i;
715
716 static const WCHAR app_octet_streamW[] =
717 {'a','p','p','l','i','c','a','t','i','o','n','/','o','c','t','e','t','-','s','t','r','e','a','m',0};
718 static const WCHAR image_pjpegW[] = {'i','m','a','g','e','/','p','j','p','e','g',0};
719 static const WCHAR text_htmlW[] = {'t','e','x','t','/','h','t','m','l',0};
720 static const WCHAR text_plainW[] = {'t','e','x','t','/','p','l','a','i','n',0};
721
722 for(i=0; i<sizeof(mime_tests)/sizeof(mime_tests[0]); i++) {
723 mime = (LPWSTR)0xf0f0f0f0;
724 url = a2w(mime_tests[i].url);
725 hres = pFindMimeFromData(NULL, url, NULL, 0, NULL, 0, &mime, 0);
726 if(mime_tests[i].mime) {
727 ok(hres == S_OK || broken(mime_tests[i].broken_failure), "[%d] FindMimeFromData failed: %08x\n", i, hres);
728 if(hres == S_OK) {
729 ok(!strcmp_wa(mime, mime_tests[i].mime)
730 || broken(mime_tests[i].broken_mime && !strcmp_wa(mime, mime_tests[i].broken_mime)),
731 "[%d] wrong mime: %s\n", i, wine_dbgstr_w(mime));
732 CoTaskMemFree(mime);
733 }
734 }else {
735 ok(hres == E_FAIL || hres == mime_tests[i].hres,
736 "[%d] FindMimeFromData failed: %08x, expected %08x\n",
737 i, hres, mime_tests[i].hres);
738 ok(mime == (LPWSTR)0xf0f0f0f0, "[%d] mime != 0xf0f0f0f0\n", i);
739 }
740
741 mime = (LPWSTR)0xf0f0f0f0;
742 hres = pFindMimeFromData(NULL, url, NULL, 0, text_plainW, 0, &mime, 0);
743 ok(hres == S_OK, "[%d] FindMimeFromData failed: %08x\n", i, hres);
744 ok(!strcmp_wa(mime, "text/plain"), "[%d] wrong mime: %s\n", i, wine_dbgstr_w(mime));
745 CoTaskMemFree(mime);
746
747 mime = (LPWSTR)0xf0f0f0f0;
748 hres = pFindMimeFromData(NULL, url, NULL, 0, app_octet_streamW, 0, &mime, 0);
749 ok(hres == S_OK, "[%d] FindMimeFromData failed: %08x\n", i, hres);
750 ok(!strcmp_wa(mime, "application/octet-stream"), "[%d] wrong mime: %s\n", i, wine_dbgstr_w(mime));
751 CoTaskMemFree(mime);
752 heap_free(url);
753 }
754
755 for(i=0; i < sizeof(mime_tests2)/sizeof(mime_tests2[0]); i++) {
756 url = a2w(mime_tests2[i].url);
757 proposed_mime = a2w(mime_tests2[i].proposed_mime);
758 hres = pFindMimeFromData(NULL, url, mime_tests2[i].data, mime_tests2[i].size,
759 proposed_mime, 0, &mime, 0);
760 ok(hres == S_OK, "[%d] FindMimeFromData failed: %08x\n", i, hres);
761 b = !strcmp_wa(mime, mime_tests2[i].mime);
762 ok(b || broken(mime_tests2[i].broken_mime && !strcmp_wa(mime, mime_tests2[i].broken_mime)),
763 "[%d] wrong mime: %s\n", i, wine_dbgstr_w(mime));
764 heap_free(proposed_mime);
765 heap_free(url);
766 CoTaskMemFree(mime);
767 if(!b || url || proposed_mime)
768 continue;
769
770 hres = pFindMimeFromData(NULL, NULL, mime_tests2[i].data, mime_tests2[i].size,
771 app_octet_streamW, 0, &mime, 0);
772 ok(hres == S_OK, "[%d] FindMimeFromData failed: %08x\n", i, hres);
773 ok(!strcmp_wa(mime, mime_tests2[i].mime) || broken(mime_tests2[i].broken_mime
774 && !strcmp_wa(mime, mime_tests2[i].broken_mime)),
775 "[%d] wrong mime: %s\n", i, wine_dbgstr_w(mime));
776 CoTaskMemFree(mime);
777
778 hres = pFindMimeFromData(NULL, NULL, mime_tests2[i].data, mime_tests2[i].size,
779 text_plainW, 0, &mime, 0);
780 ok(hres == S_OK, "[%d] FindMimeFromData failed: %08x\n", i, hres);
781 ok(!strcmp_wa(mime, mime_tests2[i].mime) || broken(mime_tests2[i].broken_mime
782 && !strcmp_wa(mime, mime_tests2[i].broken_mime)),
783 "[%d] wrong mime: %s\n", i, wine_dbgstr_w(mime));
784 CoTaskMemFree(mime);
785
786 hres = pFindMimeFromData(NULL, NULL, mime_tests2[i].data, mime_tests2[i].size,
787 text_htmlW, 0, &mime, 0);
788 ok(hres == S_OK, "[%d] FindMimeFromData failed: %08x\n", i, hres);
789 if(!strcmp("application/octet-stream", mime_tests2[i].mime)
790 || !strcmp("text/plain", mime_tests2[i].mime) || i==92)
791 ok(!strcmp_wa(mime, "text/html"), "[%d] wrong mime: %s\n", i, wine_dbgstr_w(mime));
792 else
793 ok(!strcmp_wa(mime, mime_tests2[i].mime), "[%d] wrong mime: %s\n", i, wine_dbgstr_w(mime));
794 CoTaskMemFree(mime);
795
796 hres = pFindMimeFromData(NULL, NULL, mime_tests2[i].data, mime_tests2[i].size,
797 image_pjpegW, 0, &mime, 0);
798 ok(hres == S_OK, "[%d] FindMimeFromData failed: %08x\n", i, hres);
799 ok(!strcmp_wa(mime, mime_tests2[i].mime_pjpeg ? mime_tests2[i].mime_pjpeg : mime_tests2[i].mime)
800 || broken(!strcmp_wa(mime, mime_tests2[i].mime)),
801 "[%d] wrong mime, got %s\n", i, wine_dbgstr_w(mime));
802 CoTaskMemFree(mime);
803 }
804
805 hres = pFindMimeFromData(NULL, NULL, NULL, 0, NULL, 0, &mime, 0);
806 ok(hres == E_INVALIDARG, "FindMimeFromData failed: %08x, expected E_INVALIDARG\n", hres);
807
808 hres = pFindMimeFromData(NULL, NULL, NULL, 0, text_plainW, 0, &mime, 0);
809 ok(hres == E_INVALIDARG, "FindMimeFromData failed: %08x, expected E_INVALIDARG\n", hres);
810
811 hres = pFindMimeFromData(NULL, NULL, data1, 0, NULL, 0, &mime, 0);
812 ok(hres == E_FAIL, "FindMimeFromData failed: %08x, expected E_FAIL\n", hres);
813
814 hres = pFindMimeFromData(NULL, url1, data1, 0, NULL, 0, &mime, 0);
815 ok(hres == E_FAIL, "FindMimeFromData failed: %08x, expected E_FAIL\n", hres);
816
817 hres = pFindMimeFromData(NULL, NULL, data1, 0, text_plainW, 0, &mime, 0);
818 ok(hres == S_OK, "FindMimeFromData failed: %08x\n", hres);
819 ok(!strcmp_wa(mime, "text/plain"), "wrong mime: %s\n", wine_dbgstr_w(mime));
820 CoTaskMemFree(mime);
821
822 hres = pFindMimeFromData(NULL, NULL, data1, 0, text_plainW, 0, NULL, 0);
823 ok(hres == E_INVALIDARG, "FindMimeFromData failed: %08x, expected E_INVALIDARG\n", hres);
824 }
825
826 static void register_protocols(void)
827 {
828 IInternetSession *session;
829 IClassFactory *factory;
830 HRESULT hres;
831
832 static const WCHAR wszAbout[] = {'a','b','o','u','t',0};
833
834 hres = pCoInternetGetSession(0, &session, 0);
835 ok(hres == S_OK, "CoInternetGetSession failed: %08x\n", hres);
836 if(FAILED(hres))
837 return;
838
839 hres = CoGetClassObject(&CLSID_AboutProtocol, CLSCTX_INPROC_SERVER, NULL,
840 &IID_IClassFactory, (void**)&factory);
841 ok(hres == S_OK, "Could not get AboutProtocol factory: %08x\n", hres);
842 if(FAILED(hres))
843 return;
844
845 IInternetSession_RegisterNameSpace(session, factory, &CLSID_AboutProtocol,
846 wszAbout, 0, NULL, 0);
847 IClassFactory_Release(factory);
848
849 IInternetSession_Release(session);
850 }
851
852 static HRESULT WINAPI InternetProtocolInfo_QueryInterface(IInternetProtocolInfo *iface,
853 REFIID riid, void **ppv)
854 {
855 ok(0, "unexpected call\n");
856 return E_NOINTERFACE;
857 }
858
859 static ULONG WINAPI InternetProtocolInfo_AddRef(IInternetProtocolInfo *iface)
860 {
861 return 2;
862 }
863
864 static ULONG WINAPI InternetProtocolInfo_Release(IInternetProtocolInfo *iface)
865 {
866 return 1;
867 }
868
869 static HRESULT WINAPI InternetProtocolInfo_ParseUrl(IInternetProtocolInfo *iface, LPCWSTR pwzUrl,
870 PARSEACTION ParseAction, DWORD dwParseFlags, LPWSTR pwzResult, DWORD cchResult,
871 DWORD *pcchResult, DWORD dwReserved)
872 {
873 CHECK_EXPECT2(ParseUrl);
874
875 if(ParseAction == PARSE_SECURITY_URL) {
876 if(pcchResult)
877 *pcchResult = sizeof(url1)/sizeof(WCHAR);
878
879 if(cchResult<sizeof(url1)/sizeof(WCHAR))
880 return S_FALSE;
881
882 memcpy(pwzResult, url1, sizeof(url1));
883 return S_OK;
884 }
885
886 return E_NOTIMPL;
887 }
888
889 static HRESULT WINAPI InternetProtocolInfo_CombineUrl(IInternetProtocolInfo *iface,
890 LPCWSTR pwzBaseUrl, LPCWSTR pwzRelativeUrl, DWORD dwCombineFlags,
891 LPWSTR pwzResult, DWORD cchResult, DWORD *pcchResult, DWORD dwReserved)
892 {
893 ok(0, "unexpected call\n");
894 return E_NOTIMPL;
895 }
896
897 static HRESULT WINAPI InternetProtocolInfo_CompareUrl(IInternetProtocolInfo *iface,
898 LPCWSTR pwzUrl1, LPCWSTR pwzUrl2, DWORD dwCompareFlags)
899 {
900 ok(0, "unexpected call\n");
901 return E_NOTIMPL;
902 }
903
904 static HRESULT WINAPI InternetProtocolInfo_QueryInfo(IInternetProtocolInfo *iface,
905 LPCWSTR pwzUrl, QUERYOPTION OueryOption, DWORD dwQueryFlags, LPVOID pBuffer,
906 DWORD cbBuffer, DWORD *pcbBuf, DWORD dwReserved)
907 {
908 ok(0, "unexpected call\n");
909 return E_NOTIMPL;
910 }
911
912 static const IInternetProtocolInfoVtbl InternetProtocolInfoVtbl = {
913 InternetProtocolInfo_QueryInterface,
914 InternetProtocolInfo_AddRef,
915 InternetProtocolInfo_Release,
916 InternetProtocolInfo_ParseUrl,
917 InternetProtocolInfo_CombineUrl,
918 InternetProtocolInfo_CompareUrl,
919 InternetProtocolInfo_QueryInfo
920 };
921
922 static IInternetProtocolInfo protocol_info = { &InternetProtocolInfoVtbl };
923
924 static HRESULT qiret;
925 static IClassFactory *expect_cf;
926
927 static HRESULT WINAPI ClassFactory_QueryInterface(IClassFactory *iface, REFIID riid, void **ppv)
928 {
929 if(IsEqualGUID(&IID_IInternetProtocolInfo, riid)) {
930 CHECK_EXPECT2(QI_IInternetProtocolInfo);
931 ok(iface == expect_cf, "unexpected iface\n");
932 *ppv = &protocol_info;
933 return qiret;
934 }
935
936 ok(0, "unexpected call\n");
937 return E_NOINTERFACE;
938 }
939
940 static ULONG WINAPI ClassFactory_AddRef(IClassFactory *iface)
941 {
942 return 2;
943 }
944
945 static ULONG WINAPI ClassFactory_Release(IClassFactory *iface)
946 {
947 return 1;
948 }
949
950 static HRESULT WINAPI ClassFactory_CreateInstance(IClassFactory *iface, IUnknown *pOuter,
951 REFIID riid, void **ppv)
952 {
953 ok(0, "unexpected call\n");
954 return E_NOTIMPL;
955 }
956
957 static HRESULT WINAPI ProtocolCF_CreateInstance(IClassFactory *iface, IUnknown *pOuter,
958 REFIID riid, void **ppv)
959 {
960 CHECK_EXPECT(CreateInstance);
961
962 ok(iface == expect_cf, "unexpected iface\n");
963 ok(pOuter == NULL, "pOuter = %p\n", pOuter);
964 ok(IsEqualGUID(&IID_IInternetProtocolInfo, riid), "unexpected riid\n");
965 ok(ppv != NULL, "ppv == NULL\n");
966
967 *ppv = &protocol_info;
968 return S_OK;
969 }
970
971 static HRESULT WINAPI ClassFactory_LockServer(IClassFactory *iface, BOOL dolock)
972 {
973 ok(0, "unexpected call\n");
974 return S_OK;
975 }
976
977 static const IClassFactoryVtbl ClassFactoryVtbl = {
978 ClassFactory_QueryInterface,
979 ClassFactory_AddRef,
980 ClassFactory_Release,
981 ClassFactory_CreateInstance,
982 ClassFactory_LockServer
983 };
984
985 static const IClassFactoryVtbl ProtocolCFVtbl = {
986 ClassFactory_QueryInterface,
987 ClassFactory_AddRef,
988 ClassFactory_Release,
989 ProtocolCF_CreateInstance,
990 ClassFactory_LockServer
991 };
992
993 static IClassFactory test_protocol_cf = { &ProtocolCFVtbl };
994 static IClassFactory test_protocol_cf2 = { &ProtocolCFVtbl };
995 static IClassFactory test_cf = { &ClassFactoryVtbl };
996
997 static void test_NameSpace(void)
998 {
999 IInternetSession *session;
1000 WCHAR buf[200];
1001 LPWSTR sec_url;
1002 DWORD size;
1003 HRESULT hres;
1004
1005 static const WCHAR wszTest[] = {'t','e','s','t',0};
1006
1007 hres = pCoInternetGetSession(0, &session, 0);
1008 ok(hres == S_OK, "CoInternetGetSession failed: %08x\n", hres);
1009 if(FAILED(hres))
1010 return;
1011
1012 hres = IInternetSession_RegisterNameSpace(session, NULL, &IID_NULL,
1013 wszTest, 0, NULL, 0);
1014 ok(hres == E_INVALIDARG, "RegisterNameSpace failed: %08x\n", hres);
1015
1016 hres = IInternetSession_RegisterNameSpace(session, &test_protocol_cf, &IID_NULL,
1017 NULL, 0, NULL, 0);
1018 ok(hres == E_INVALIDARG, "RegisterNameSpace failed: %08x\n", hres);
1019
1020 hres = IInternetSession_RegisterNameSpace(session, &test_protocol_cf, &IID_NULL,
1021 wszTest, 0, NULL, 0);
1022 ok(hres == S_OK, "RegisterNameSpace failed: %08x\n", hres);
1023
1024 qiret = E_NOINTERFACE;
1025 expect_cf = &test_protocol_cf;
1026 SET_EXPECT(QI_IInternetProtocolInfo);
1027 SET_EXPECT(CreateInstance);
1028 SET_EXPECT(ParseUrl);
1029
1030 hres = pCoInternetParseUrl(url8, PARSE_ENCODE, 0, buf, sizeof(buf)/sizeof(WCHAR),
1031 &size, 0);
1032 ok(hres == S_OK, "CoInternetParseUrl failed: %08x\n", hres);
1033
1034 CHECK_CALLED(QI_IInternetProtocolInfo);
1035 CHECK_CALLED(CreateInstance);
1036 CHECK_CALLED(ParseUrl);
1037
1038 qiret = S_OK;
1039 SET_EXPECT(QI_IInternetProtocolInfo);
1040 SET_EXPECT(ParseUrl);
1041
1042 hres = pCoInternetParseUrl(url8, PARSE_ENCODE, 0, buf, sizeof(buf)/sizeof(WCHAR),
1043 &size, 0);
1044 ok(hres == S_OK, "CoInternetParseUrl failed: %08x\n", hres);
1045
1046 CHECK_CALLED(QI_IInternetProtocolInfo);
1047 CHECK_CALLED(ParseUrl);
1048
1049 SET_EXPECT(QI_IInternetProtocolInfo);
1050 SET_EXPECT(ParseUrl);
1051
1052 hres = pCoInternetParseUrl(url8, PARSE_SECURITY_URL, 0, buf,
1053 sizeof(buf)/sizeof(WCHAR), &size, 0);
1054 ok(hres == S_OK, "CoInternetParseUrl failed: %08x\n", hres);
1055 ok(size == sizeof(url1)/sizeof(WCHAR), "Size = %d\n", size);
1056 if(size == sizeof(url1)/sizeof(WCHAR))
1057 ok(!memcmp(buf, url1, sizeof(url1)), "Encoded url = %s\n", wine_dbgstr_w(buf));
1058
1059 CHECK_CALLED(QI_IInternetProtocolInfo);
1060 CHECK_CALLED(ParseUrl);
1061
1062 SET_EXPECT(QI_IInternetProtocolInfo);
1063 SET_EXPECT(ParseUrl);
1064
1065 if (pCoInternetGetSecurityUrl) {
1066 hres = pCoInternetGetSecurityUrl(url8, &sec_url, PSU_SECURITY_URL_ONLY, 0);
1067 ok(hres == S_OK, "CoInternetGetSecurityUrl failed: %08x\n", hres);
1068 if(hres == S_OK) {
1069 ok(lstrlenW(sec_url)>sizeof(wszFile)/sizeof(WCHAR) &&
1070 !memcmp(sec_url, wszFile, sizeof(wszFile)-sizeof(WCHAR)),
1071 "Encoded url = %s\n", wine_dbgstr_w(sec_url));
1072 CoTaskMemFree(sec_url);
1073 }
1074
1075 CHECK_CALLED(QI_IInternetProtocolInfo);
1076 CHECK_CALLED(ParseUrl);
1077 }
1078
1079 hres = IInternetSession_UnregisterNameSpace(session, &test_protocol_cf, wszTest);
1080 ok(hres == S_OK, "UnregisterNameSpace failed: %08x\n", hres);
1081
1082 hres = pCoInternetParseUrl(url8, PARSE_ENCODE, 0, buf, sizeof(buf)/sizeof(WCHAR),
1083 &size, 0);
1084 ok(hres == S_OK, "CoInternetParseUrl failed: %08x\n", hres);
1085
1086 hres = IInternetSession_RegisterNameSpace(session, &test_protocol_cf2, &IID_NULL,
1087 wszTest, 0, NULL, 0);
1088 ok(hres == S_OK, "RegisterNameSpace failed: %08x\n", hres);
1089
1090 hres = IInternetSession_RegisterNameSpace(session, &test_protocol_cf, &IID_NULL,
1091 wszTest, 0, NULL, 0);
1092 ok(hres == S_OK, "RegisterNameSpace failed: %08x\n", hres);
1093
1094 hres = IInternetSession_RegisterNameSpace(session, &test_protocol_cf, &IID_NULL,
1095 wszTest, 0, NULL, 0);
1096 ok(hres == S_OK, "RegisterNameSpace failed: %08x\n", hres);
1097
1098 SET_EXPECT(QI_IInternetProtocolInfo);
1099 SET_EXPECT(ParseUrl);
1100
1101 hres = pCoInternetParseUrl(url8, PARSE_ENCODE, 0, buf, sizeof(buf)/sizeof(WCHAR),
1102 &size, 0);
1103 ok(hres == S_OK, "CoInternetParseUrl failed: %08x\n", hres);
1104
1105 CHECK_CALLED(QI_IInternetProtocolInfo);
1106 CHECK_CALLED(ParseUrl);
1107
1108 hres = IInternetSession_UnregisterNameSpace(session, &test_protocol_cf, wszTest);
1109 ok(hres == S_OK, "UnregisterNameSpace failed: %08x\n", hres);
1110
1111 SET_EXPECT(QI_IInternetProtocolInfo);
1112 SET_EXPECT(ParseUrl);
1113
1114 hres = pCoInternetParseUrl(url8, PARSE_ENCODE, 0, buf, sizeof(buf)/sizeof(WCHAR),
1115 &size, 0);
1116 ok(hres == S_OK, "CoInternetParseUrl failed: %08x\n", hres);
1117
1118 CHECK_CALLED(QI_IInternetProtocolInfo);
1119 CHECK_CALLED(ParseUrl);
1120
1121 hres = IInternetSession_UnregisterNameSpace(session, &test_protocol_cf, wszTest);
1122 ok(hres == S_OK, "UnregisterNameSpace failed: %08x\n", hres);
1123
1124 expect_cf = &test_protocol_cf2;
1125 SET_EXPECT(QI_IInternetProtocolInfo);
1126 SET_EXPECT(ParseUrl);
1127
1128 hres = pCoInternetParseUrl(url8, PARSE_ENCODE, 0, buf, sizeof(buf)/sizeof(WCHAR),
1129 &size, 0);
1130 ok(hres == S_OK, "CoInternetParseUrl failed: %08x\n", hres);
1131
1132 CHECK_CALLED(QI_IInternetProtocolInfo);
1133 CHECK_CALLED(ParseUrl);
1134
1135 hres = IInternetSession_UnregisterNameSpace(session, &test_protocol_cf, wszTest);
1136 ok(hres == S_OK, "UnregisterNameSpace failed: %08x\n", hres);
1137 hres = IInternetSession_UnregisterNameSpace(session, &test_protocol_cf, wszTest);
1138 ok(hres == S_OK, "UnregisterNameSpace failed: %08x\n", hres);
1139 hres = IInternetSession_UnregisterNameSpace(session, &test_protocol_cf, NULL);
1140 ok(hres == E_INVALIDARG, "UnregisterNameSpace failed: %08x\n", hres);
1141 hres = IInternetSession_UnregisterNameSpace(session, NULL, wszTest);
1142 ok(hres == E_INVALIDARG, "UnregisterNameSpace failed: %08x\n", hres);
1143
1144 hres = IInternetSession_UnregisterNameSpace(session, &test_protocol_cf2, wszTest);
1145 ok(hres == S_OK, "UnregisterNameSpace failed: %08x\n", hres);
1146
1147 hres = pCoInternetParseUrl(url8, PARSE_ENCODE, 0, buf, sizeof(buf)/sizeof(WCHAR),
1148 &size, 0);
1149 ok(hres == S_OK, "CoInternetParseUrl failed: %08x\n", hres);
1150
1151 IInternetSession_Release(session);
1152 }
1153
1154 static void test_MimeFilter(void)
1155 {
1156 IInternetSession *session;
1157 HRESULT hres;
1158
1159 static const WCHAR mimeW[] = {'t','e','s','t','/','m','i','m','e',0};
1160
1161 hres = pCoInternetGetSession(0, &session, 0);
1162 ok(hres == S_OK, "CoInternetGetSession failed: %08x\n", hres);
1163 if(FAILED(hres))
1164 return;
1165
1166 hres = IInternetSession_RegisterMimeFilter(session, &test_cf, &IID_NULL, mimeW);
1167 ok(hres == S_OK, "RegisterMimeFilter failed: %08x\n", hres);
1168
1169 hres = IInternetSession_UnregisterMimeFilter(session, &test_cf, mimeW);
1170 ok(hres == S_OK, "UnregisterMimeFilter failed: %08x\n", hres);
1171
1172 hres = IInternetSession_UnregisterMimeFilter(session, &test_cf, mimeW);
1173 ok(hres == S_OK, "UnregisterMimeFilter failed: %08x\n", hres);
1174
1175 hres = IInternetSession_UnregisterMimeFilter(session, (void*)0xdeadbeef, mimeW);
1176 ok(hres == S_OK, "UnregisterMimeFilter failed: %08x\n", hres);
1177
1178 IInternetSession_Release(session);
1179 }
1180
1181 static ULONG WINAPI unk_Release(IUnknown *iface)
1182 {
1183 CHECK_EXPECT(unk_Release);
1184 return 0;
1185 }
1186
1187 static const IUnknownVtbl unk_vtbl = {
1188 (void*)0xdeadbeef,
1189 (void*)0xdeadbeef,
1190 unk_Release
1191 };
1192
1193 static void test_ReleaseBindInfo(void)
1194 {
1195 BINDINFO bi;
1196 IUnknown unk = { &unk_vtbl };
1197
1198 pReleaseBindInfo(NULL); /* shouldn't crash */
1199
1200 memset(&bi, 0, sizeof(bi));
1201 bi.cbSize = sizeof(BINDINFO);
1202 bi.pUnk = &unk;
1203 SET_EXPECT(unk_Release);
1204 pReleaseBindInfo(&bi);
1205 ok(bi.cbSize == sizeof(BINDINFO), "bi.cbSize=%d\n", bi.cbSize);
1206 ok(bi.pUnk == NULL, "bi.pUnk=%p, expected NULL\n", bi.pUnk);
1207 CHECK_CALLED(unk_Release);
1208
1209 memset(&bi, 0, sizeof(bi));
1210 bi.cbSize = offsetof(BINDINFO, pUnk);
1211 bi.pUnk = &unk;
1212 pReleaseBindInfo(&bi);
1213 ok(bi.cbSize == offsetof(BINDINFO, pUnk), "bi.cbSize=%d\n", bi.cbSize);
1214 ok(bi.pUnk == &unk, "bi.pUnk=%p, expected %p\n", bi.pUnk, &unk);
1215
1216 memset(&bi, 0, sizeof(bi));
1217 bi.pUnk = &unk;
1218 pReleaseBindInfo(&bi);
1219 ok(!bi.cbSize, "bi.cbSize=%d, expected 0\n", bi.cbSize);
1220 ok(bi.pUnk == &unk, "bi.pUnk=%p, expected %p\n", bi.pUnk, &unk);
1221 }
1222
1223 static void test_CopyStgMedium(void)
1224 {
1225 STGMEDIUM src, dst;
1226 HGLOBAL empty, hg;
1227 char *ptr1, *ptr2;
1228 HRESULT hres;
1229 int size;
1230
1231 static WCHAR fileW[] = {'f','i','l','e',0};
1232
1233 memset(&src, 0xf0, sizeof(src));
1234 memset(&dst, 0xe0, sizeof(dst));
1235 memset(&empty, 0xf0, sizeof(empty));
1236 src.tymed = TYMED_NULL;
1237 src.pUnkForRelease = NULL;
1238 hres = pCopyStgMedium(&src, &dst);
1239 ok(hres == S_OK, "CopyStgMedium failed: %08x\n", hres);
1240 ok(dst.tymed == TYMED_NULL, "tymed=%d\n", dst.tymed);
1241 ok(dst.u.hGlobal == empty, "u=%p\n", dst.u.hGlobal);
1242 ok(!dst.pUnkForRelease, "pUnkForRelease=%p, expected NULL\n", dst.pUnkForRelease);
1243
1244 memset(&dst, 0xe0, sizeof(dst));
1245 src.tymed = TYMED_ISTREAM;
1246 src.u.pstm = NULL;
1247 src.pUnkForRelease = NULL;
1248 hres = pCopyStgMedium(&src, &dst);
1249 ok(hres == S_OK, "CopyStgMedium failed: %08x\n", hres);
1250 ok(dst.tymed == TYMED_ISTREAM, "tymed=%d\n", dst.tymed);
1251 ok(!dst.u.pstm, "pstm=%p\n", dst.u.pstm);
1252 ok(!dst.pUnkForRelease, "pUnkForRelease=%p, expected NULL\n", dst.pUnkForRelease);
1253
1254 memset(&dst, 0xe0, sizeof(dst));
1255 src.tymed = TYMED_FILE;
1256 src.u.lpszFileName = fileW;
1257 src.pUnkForRelease = NULL;
1258 hres = pCopyStgMedium(&src, &dst);
1259 ok(hres == S_OK, "CopyStgMedium failed: %08x\n", hres);
1260 ok(dst.tymed == TYMED_FILE, "tymed=%d\n", dst.tymed);
1261 ok(dst.u.lpszFileName && dst.u.lpszFileName != fileW, "lpszFileName=%p\n", dst.u.lpszFileName);
1262 ok(!lstrcmpW(dst.u.lpszFileName, fileW), "wrong file name\n");
1263 ok(!dst.pUnkForRelease, "pUnkForRelease=%p, expected NULL\n", dst.pUnkForRelease);
1264 ReleaseStgMedium(&dst);
1265
1266 /* TYMED_HGLOBAL */
1267 hg = GlobalAlloc(GMEM_MOVEABLE, 10);
1268 ptr1 = GlobalLock(hg);
1269 memset(ptr1, 0xfa, 10);
1270 memset(&dst, 0xe0, sizeof(dst));
1271 src.tymed = TYMED_HGLOBAL;
1272 src.u.hGlobal = hg;
1273 hres = pCopyStgMedium(&src, &dst);
1274 ok(hres == S_OK, "CopyStgMedium failed: %08x\n", hres);
1275 ok(dst.tymed == TYMED_HGLOBAL, "tymed=%d\n", dst.tymed);
1276 ok(dst.u.hGlobal != hg, "got %p, %p\n", dst.u.hGlobal, hg);
1277 size = GlobalSize(dst.u.hGlobal);
1278 ok(size == 10, "got size %d\n", size);
1279 /* compare contents */
1280 ptr2 = GlobalLock(dst.u.hGlobal);
1281 ok(!memcmp(ptr1, ptr2, 10), "got wrong data\n");
1282 GlobalUnlock(ptr2);
1283 GlobalUnlock(ptr1);
1284 ok(GlobalFlags(dst.u.hGlobal) == 0, "got 0x%08x\n", GlobalFlags(dst.u.hGlobal));
1285 GlobalFree(hg);
1286 ReleaseStgMedium(&dst);
1287
1288 memset(&dst, 0xe0, sizeof(dst));
1289 src.tymed = TYMED_HGLOBAL;
1290 src.u.hGlobal = NULL;
1291 hres = pCopyStgMedium(&src, &dst);
1292 ok(hres == S_OK, "CopyStgMedium failed: %08x\n", hres);
1293 ok(dst.u.hGlobal == NULL, "got %p\n", dst.u.hGlobal);
1294
1295 hres = pCopyStgMedium(&src, NULL);
1296 ok(hres == E_POINTER, "CopyStgMedium failed: %08x, expected E_POINTER\n", hres);
1297 hres = pCopyStgMedium(NULL, &dst);
1298 ok(hres == E_POINTER, "CopyStgMedium failed: %08x, expected E_POINTER\n", hres);
1299 }
1300
1301 static void test_CopyBindInfo(void)
1302 {
1303 BINDINFO src[2], dest[2];
1304 SECURITY_DESCRIPTOR sec_desc;
1305 HRESULT hres;
1306 int i;
1307
1308 hres = pCopyBindInfo(NULL, NULL);
1309 ok(hres == E_POINTER, "CopyBindInfo returned %08x, expected E_POINTER\n", hres);
1310
1311 memset(src, 0, sizeof(BINDINFO[2]));
1312 memset(dest, 0xde, sizeof(BINDINFO[2]));
1313 hres = pCopyBindInfo(src, dest);
1314 ok(hres == E_INVALIDARG, "CopyBindInfo returned: %08x, expected E_INVALIDARG\n", hres);
1315
1316 memset(src, 0, sizeof(BINDINFO[2]));
1317 memset(dest, 0xde, sizeof(BINDINFO[2]));
1318 src[0].cbSize = sizeof(BINDINFO);
1319 dest[0].cbSize = 0;
1320 hres = pCopyBindInfo(src, dest);
1321 ok(hres == E_INVALIDARG, "CopyBindInfo returned: %08x, expected E_INVALIDARG\n", hres);
1322
1323 memset(src, 0, sizeof(BINDINFO[2]));
1324 memset(dest, 0xde, sizeof(BINDINFO[2]));
1325 src[0].cbSize = 1;
1326 dest[0].cbSize = sizeof(BINDINFO)+sizeof(DWORD);
1327 hres = pCopyBindInfo(src, dest);
1328 ok(hres == S_OK, "CopyBindInfo failed: %08x\n", hres);
1329 ok(dest[0].cbSize == sizeof(BINDINFO)+sizeof(DWORD), "incorrect cbSize: %d\n", dest[0].cbSize);
1330 for(i=1; i<dest[0].cbSize/sizeof(int); i++)
1331 ok(((int*)dest)[i] == 0, "unset values should be set to 0, got %d on %d\n", ((int*)dest)[i], i);
1332
1333 memset(src, 0, sizeof(BINDINFO[2]));
1334 memset(dest, 0xde, sizeof(BINDINFO[2]));
1335 src[0].cbSize = sizeof(BINDINFO)+2*sizeof(DWORD);
1336 dest[0].cbSize = sizeof(BINDINFO)+sizeof(DWORD);
1337 hres = pCopyBindInfo(src, dest);
1338 ok(hres == S_OK, "CopyBindInfo failed: %08x\n", hres);
1339 ok(dest[1].cbSize == src[1].cbSize, "additional data should be copied\n");
1340 ok(dest[1].szExtraInfo != src[1].szExtraInfo,
1341 "data not fitting in destination buffer should not be copied\n");
1342
1343 memset(src, 0xf0, sizeof(BINDINFO[2]));
1344 memset(dest, 0xde, sizeof(BINDINFO[2]));
1345 src[0].cbSize = sizeof(BINDINFO);
1346 src[0].szExtraInfo = CoTaskMemAlloc(sizeof(WCHAR));
1347 src[0].szExtraInfo[0] = 0;
1348 src[0].szCustomVerb = NULL;
1349 src[0].pUnk = NULL;
1350 src[0].stgmedData.tymed = TYMED_NULL;
1351 src[0].stgmedData.pUnkForRelease = NULL;
1352 dest[0].cbSize = sizeof(BINDINFO);
1353 hres = pCopyBindInfo(src, dest);
1354 ok(hres == S_OK, "CopyBindInfo failed: %08x\n", hres);
1355
1356 ok(dest[0].cbSize == sizeof(BINDINFO), "incorrect cbSize: %d\n", dest[0].cbSize);
1357 ok(dest[0].szExtraInfo && !dest[0].szExtraInfo[0] && dest[0].szExtraInfo!=src[0].szExtraInfo,
1358 "incorrect szExtraInfo: (%p!=%p) %d\n", dest[0].szExtraInfo,
1359 src[0].szExtraInfo, dest[0].szExtraInfo[0]);
1360 ok(!memcmp(&dest[0].stgmedData, &src[0].stgmedData, sizeof(STGMEDIUM)),
1361 "incorrect stgmedData value\n");
1362 ok(src[0].grfBindInfoF == dest[0].grfBindInfoF, "grfBindInfoF = %x, expected %x\n",
1363 dest[0].grfBindInfoF, src[0].grfBindInfoF);
1364 ok(src[0].dwBindVerb == dest[0].dwBindVerb, "dwBindVerb = %x, expected %x\n",
1365 dest[0].dwBindVerb, src[0].dwBindVerb);
1366 ok(!dest[0].szCustomVerb, "szCustmoVerb != NULL\n");
1367 ok(src[0].cbstgmedData == dest[0].cbstgmedData, "cbstgmedData = %x, expected %x\n",
1368 dest[0].cbstgmedData, src[0].cbstgmedData);
1369 ok(src[0].dwOptions == dest[0].dwOptions, "dwOptions = %x, expected %x\n",
1370 dest[0].dwOptions, src[0].dwOptions);
1371 ok(src[0].dwOptionsFlags == dest[0].dwOptionsFlags, "dwOptionsFlags = %x, expected %x\n",
1372 dest[0].dwOptionsFlags, src[0].dwOptionsFlags);
1373 ok(src[0].dwCodePage == dest[0].dwCodePage, "dwCodePage = %x, expected %x\n",
1374 dest[0].dwCodePage, src[0].dwCodePage);
1375 ok(!dest[0].securityAttributes.nLength,
1376 "unexpected securityAttributes.nLength value: %d\n",
1377 dest[0].securityAttributes.nLength);
1378 ok(!dest[0].securityAttributes.lpSecurityDescriptor,
1379 "unexpected securityAttributes.lpSecurityDescriptor value: %p\n",
1380 dest[0].securityAttributes.lpSecurityDescriptor);
1381 ok(!dest[0].securityAttributes.bInheritHandle,
1382 "unexpected securityAttributes.bInheritHandle value: %d\n",
1383 dest[0].securityAttributes.bInheritHandle);
1384 ok(!memcmp(&dest[0].iid, &src[0].iid, sizeof(IID)),
1385 "incorrect iid value\n");
1386 ok(!dest[0].pUnk, "pUnk != NULL\n");
1387 ok(src[0].dwReserved == dest[0].dwReserved, "dwReserved = %x, expected %x\n",
1388 dest[0].dwReserved, src[0].dwReserved);
1389
1390 CoTaskMemFree(src[0].szExtraInfo);
1391 CoTaskMemFree(dest[0].szExtraInfo);
1392
1393 src[0].szExtraInfo = NULL;
1394 src[0].securityAttributes.nLength = sizeof(SECURITY_ATTRIBUTES);
1395 ok(InitializeSecurityDescriptor(&sec_desc, SECURITY_DESCRIPTOR_REVISION),
1396 "InitializeSecurityDescriptor failed\n");
1397 src[0].securityAttributes.lpSecurityDescriptor = (void*)&sec_desc;
1398 src[0].securityAttributes.bInheritHandle = TRUE;
1399 hres = pCopyBindInfo(src, dest);
1400 ok(hres == S_OK, "CopyBindInfo failed: %08x\n", hres);
1401 ok(!dest[0].securityAttributes.nLength,
1402 "unexpected securityAttributes.nLength value: %d\n",
1403 dest[0].securityAttributes.nLength);
1404 ok(!dest[0].securityAttributes.lpSecurityDescriptor,
1405 "unexpected securityAttributes.lpSecurityDescriptor value: %p\n",
1406 dest[0].securityAttributes.lpSecurityDescriptor);
1407 ok(!dest[0].securityAttributes.bInheritHandle,
1408 "unexpected securityAttributes.bInheritHandle value: %d\n",
1409 dest[0].securityAttributes.bInheritHandle);
1410 }
1411
1412 static void test_UrlMkGetSessionOption(void)
1413 {
1414 DWORD encoding, size;
1415 HRESULT hres;
1416
1417 size = encoding = 0xdeadbeef;
1418 hres = pUrlMkGetSessionOption(URLMON_OPTION_URL_ENCODING, &encoding,
1419 sizeof(encoding), &size, 0);
1420 ok(hres == S_OK, "UrlMkGetSessionOption failed: %08x\n", hres);
1421 ok(encoding != 0xdeadbeef, "encoding not changed\n");
1422 ok(size == sizeof(encoding), "size=%d\n", size);
1423
1424 size = encoding = 0xdeadbeef;
1425 hres = pUrlMkGetSessionOption(URLMON_OPTION_URL_ENCODING, &encoding,
1426 sizeof(encoding)+1, &size, 0);
1427 ok(hres == S_OK, "UrlMkGetSessionOption failed: %08x\n", hres);
1428 ok(encoding != 0xdeadbeef, "encoding not changed\n");
1429 ok(size == sizeof(encoding), "size=%d\n", size);
1430
1431 size = encoding = 0xdeadbeef;
1432 hres = pUrlMkGetSessionOption(URLMON_OPTION_URL_ENCODING, &encoding,
1433 sizeof(encoding)-1, &size, 0);
1434 ok(hres == E_INVALIDARG, "UrlMkGetSessionOption failed: %08x\n", hres);
1435 ok(encoding == 0xdeadbeef, "encoding = %08x, exepcted 0xdeadbeef\n", encoding);
1436 ok(size == 0xdeadbeef, "size=%d\n", size);
1437
1438 size = encoding = 0xdeadbeef;
1439 hres = pUrlMkGetSessionOption(URLMON_OPTION_URL_ENCODING, NULL,
1440 sizeof(encoding)-1, &size, 0);
1441 ok(hres == E_INVALIDARG, "UrlMkGetSessionOption failed: %08x\n", hres);
1442 ok(encoding == 0xdeadbeef, "encoding = %08x, exepcted 0xdeadbeef\n", encoding);
1443 ok(size == 0xdeadbeef, "size=%d\n", size);
1444
1445 encoding = 0xdeadbeef;
1446 hres = pUrlMkGetSessionOption(URLMON_OPTION_URL_ENCODING, &encoding,
1447 sizeof(encoding)-1, NULL, 0);
1448 ok(hres == E_INVALIDARG, "UrlMkGetSessionOption failed: %08x\n", hres);
1449 ok(encoding == 0xdeadbeef, "encoding = %08x, exepcted 0xdeadbeef\n", encoding);
1450 }
1451
1452 static void test_user_agent(void)
1453 {
1454 static const CHAR expected[] = "Mozilla/4.0 (compatible; MSIE ";
1455 static char test_str[] = "test";
1456 static char test2_str[] = "test\0test";
1457 static CHAR str[3];
1458 LPSTR str2 = NULL;
1459 HRESULT hres;
1460 DWORD size, saved;
1461
1462 hres = pObtainUserAgentString(0, NULL, NULL);
1463 ok(hres == E_INVALIDARG, "ObtainUserAgentString failed: %08x\n", hres);
1464
1465 size = 100;
1466 hres = pObtainUserAgentString(0, NULL, &size);
1467 ok(hres == E_INVALIDARG, "ObtainUserAgentString failed: %08x\n", hres);
1468 ok(size == 100, "size=%d, expected %d\n", size, 100);
1469
1470 size = 0;
1471 hres = pObtainUserAgentString(0, str, &size);
1472 ok(hres == E_OUTOFMEMORY, "ObtainUserAgentString failed: %08x\n", hres);
1473 ok(size > 0, "size=%d, expected non-zero\n", size);
1474
1475 size = 2;
1476 str[0] = 'a';
1477 hres = pObtainUserAgentString(0, str, &size);
1478 ok(hres == E_OUTOFMEMORY, "ObtainUserAgentString failed: %08x\n", hres);
1479 ok(size > 0, "size=%d, expected non-zero\n", size);
1480 ok(str[0] == 'a', "str[0]=%c, expected 'a'\n", str[0]);
1481
1482 size = 0;
1483 hres = pObtainUserAgentString(1, str, &size);
1484 ok(hres == E_OUTOFMEMORY, "ObtainUserAgentString failed: %08x\n", hres);
1485 ok(size > 0, "size=%d, expected non-zero\n", size);
1486
1487 str2 = HeapAlloc(GetProcessHeap(), 0, (size+20)*sizeof(CHAR));
1488 saved = size;
1489 hres = pObtainUserAgentString(0, str2, &size);
1490 ok(hres == S_OK, "ObtainUserAgentString failed: %08x\n", hres);
1491 ok(size == saved, "size=%d, expected %d\n", size, saved);
1492 ok(strlen(expected) <= strlen(str2) &&
1493 !memcmp(expected, str2, strlen(expected)*sizeof(CHAR)),
1494 "user agent was \"%s\", expected to start with \"%s\"\n",
1495 str2, expected);
1496
1497 size = saved+10;
1498 hres = pObtainUserAgentString(0, str2, &size);
1499 ok(hres == S_OK, "ObtainUserAgentString failed: %08x\n", hres);
1500 ok(size == saved, "size=%d, expected %d\n", size, saved);
1501
1502 size = 0;
1503 hres = pUrlMkGetSessionOption(URLMON_OPTION_USERAGENT, NULL, 0, &size, 0);
1504 ok(hres == E_OUTOFMEMORY, "UrlMkGetSessionOption failed: %08x\n", hres);
1505 ok(size, "size == 0\n");
1506
1507 size = 0xdeadbeef;
1508 hres = pUrlMkGetSessionOption(URLMON_OPTION_USERAGENT, NULL, 1000, &size, 0);
1509 ok(hres == E_INVALIDARG, "UrlMkGetSessionOption failed: %08x\n", hres);
1510 ok(size, "size == 0\n");
1511
1512 saved = size;
1513 size = 0;
1514 hres = pUrlMkGetSessionOption(URLMON_OPTION_USERAGENT, str2, saved+10, &size, 0);
1515 ok(hres == E_OUTOFMEMORY, "UrlMkGetSessionOption failed: %08x\n", hres);
1516 ok(size == saved, "size = %d, expected %d\n", size, saved);
1517 ok(sizeof(expected) <= strlen(str2) && !memcmp(expected, str2, sizeof(expected)-1),
1518 "user agent was \"%s\", expected to start with \"%s\"\n",
1519 str2, expected);
1520
1521 size = 0;
1522 str2[0] = 0;
1523 hres = pUrlMkGetSessionOption(URLMON_OPTION_USERAGENT, str2, saved, &size, 0);
1524 ok(hres == E_OUTOFMEMORY, "UrlMkGetSessionOption failed: %08x\n", hres);
1525 ok(size == saved, "size = %d, expected %d\n", size, saved);
1526 ok(sizeof(expected) <= strlen(str2) && !memcmp(expected, str2, sizeof(expected)-1),
1527 "user agent was \"%s\", expected to start with \"%s\"\n",
1528 str2, expected);
1529
1530 size = saved;
1531 str2[0] = 0;
1532 hres = pUrlMkGetSessionOption(URLMON_OPTION_USERAGENT, str2, saved-1, &size, 0);
1533 ok(hres == E_OUTOFMEMORY, "UrlMkGetSessionOption failed: %08x\n", hres);
1534 ok(size == saved, "size = %d, expected %d\n", size, saved);
1535 ok(!str2[0], "buf changed\n");
1536
1537 size = saved;
1538 str2[0] = 0;
1539 hres = pUrlMkGetSessionOption(URLMON_OPTION_USERAGENT, str2, saved, NULL, 0);
1540 ok(hres == E_INVALIDARG, "UrlMkGetSessionOption failed: %08x\n", hres);
1541 ok(!str2[0], "buf changed\n");
1542
1543 hres = UrlMkSetSessionOption(URLMON_OPTION_USERAGENT, test_str, sizeof(test_str), 0);
1544 ok(hres == S_OK, "UrlMkSetSessionOption failed: %08x\n", hres);
1545
1546 size = 0;
1547 str2[0] = 0;
1548 hres = pUrlMkGetSessionOption(URLMON_OPTION_USERAGENT, str2, saved, &size, 0);
1549 ok(hres == E_OUTOFMEMORY, "UrlMkGetSessionOption failed: %08x\n", hres);
1550 ok(size == sizeof(test_str) && !memcmp(str2, test_str, sizeof(test_str)), "wrong user agent\n");
1551
1552 hres = UrlMkSetSessionOption(URLMON_OPTION_USERAGENT, test2_str, sizeof(test2_str), 0);
1553 ok(hres == S_OK, "UrlMkSetSessionOption failed: %08x\n", hres);
1554
1555 size = 0;
1556 str2[0] = 0;
1557 hres = pUrlMkGetSessionOption(URLMON_OPTION_USERAGENT, str2, saved, &size, 0);
1558 ok(hres == E_OUTOFMEMORY, "UrlMkGetSessionOption failed: %08x\n", hres);
1559 ok(size == sizeof(test_str) && !memcmp(str2, test_str, sizeof(test_str)), "wrong user agent\n");
1560
1561 hres = UrlMkSetSessionOption(URLMON_OPTION_USERAGENT, test_str, 2, 0);
1562 ok(hres == S_OK, "UrlMkSetSessionOption failed: %08x\n", hres);
1563
1564 size = 0;
1565 str2[0] = 0;
1566 hres = pUrlMkGetSessionOption(URLMON_OPTION_USERAGENT, str2, saved, &size, 0);
1567 ok(hres == E_OUTOFMEMORY, "UrlMkGetSessionOption failed: %08x\n", hres);
1568 ok(size == 3 && !strcmp(str2, "te"), "wrong user agent\n");
1569
1570 hres = UrlMkSetSessionOption(URLMON_OPTION_USERAGENT, test_str, 0, 0);
1571 ok(hres == E_INVALIDARG, "UrlMkSetSessionOption failed: %08x\n", hres);
1572
1573 hres = UrlMkSetSessionOption(URLMON_OPTION_USERAGENT, NULL, sizeof(test_str), 0);
1574 ok(hres == E_INVALIDARG, "UrlMkSetSessionOption failed: %08x\n", hres);
1575
1576 hres = UrlMkSetSessionOption(URLMON_OPTION_USERAGENT, NULL, 0, 0);
1577 ok(hres == E_INVALIDARG, "UrlMkSetSessionOption failed: %08x\n", hres);
1578
1579 HeapFree(GetProcessHeap(), 0, str2);
1580 }
1581
1582 static void test_MkParseDisplayNameEx(void)
1583 {
1584 IMoniker *mon = NULL;
1585 LPWSTR name;
1586 DWORD issys;
1587 ULONG eaten = 0;
1588 IBindCtx *bctx;
1589 HRESULT hres;
1590
1591 static const WCHAR clsid_nameW[] = {'c','l','s','i','d',':',
1592 '2','0','D','0','4','F','E','0','-','3','A','E','A','-','1','0','6','9','-','A','2','D','8',
1593 '-','0','8','0','0','2','B','3','0','3','0','9','D',':',0};
1594
1595 const struct
1596 {
1597 LPBC *ppbc;
1598 LPCWSTR szDisplayName;
1599 ULONG *pchEaten;
1600 LPMONIKER *ppmk;
1601 } invalid_parameters[] =
1602 {
1603 {NULL, NULL, NULL, NULL},
1604 {NULL, NULL, NULL, &mon},
1605 {NULL, NULL, &eaten, NULL},
1606 {NULL, NULL, &eaten, &mon},
1607 {NULL, wszEmpty, NULL, NULL},
1608 {NULL, wszEmpty, NULL, &mon},
1609 {NULL, wszEmpty, &eaten, NULL},
1610 {NULL, wszEmpty, &eaten, &mon},
1611 {&bctx, NULL, NULL, NULL},
1612 {&bctx, NULL, NULL, &mon},
1613 {&bctx, NULL, &eaten, NULL},
1614 {&bctx, NULL, &eaten, &mon},
1615 {&bctx, wszEmpty, NULL, NULL},
1616 {&bctx, wszEmpty, NULL, &mon},
1617 {&bctx, wszEmpty, &eaten, NULL},
1618 {&bctx, wszEmpty, &eaten, &mon},
1619 };
1620
1621 int i;
1622
1623 CreateBindCtx(0, &bctx);
1624
1625 for (i = 0; i < sizeof(invalid_parameters)/sizeof(invalid_parameters[0]); i++)
1626 {
1627 eaten = 0xdeadbeef;
1628 mon = (IMoniker *)0xdeadbeef;
1629 hres = MkParseDisplayNameEx(invalid_parameters[i].ppbc ? *invalid_parameters[i].ppbc : NULL,
1630 invalid_parameters[i].szDisplayName,
1631 invalid_parameters[i].pchEaten,
1632 invalid_parameters[i].ppmk);
1633 ok(hres == E_INVALIDARG,
1634 "[%d] Expected MkParseDisplayNameEx to return E_INVALIDARG, got %08x\n", i, hres);
1635 ok(eaten == 0xdeadbeef, "[%d] Expected eaten to be 0xdeadbeef, got %u\n", i, eaten);
1636 ok(mon == (IMoniker *)0xdeadbeef, "[%d] Expected mon to be 0xdeadbeef, got %p\n", i, mon);
1637 }
1638
1639 hres = MkParseDisplayNameEx(bctx, url9, &eaten, &mon);
1640 ok(hres == S_OK, "MkParseDisplayNameEx failed: %08x\n", hres);
1641 ok(eaten == sizeof(url9)/sizeof(WCHAR)-1, "eaten=%d\n", eaten);
1642 ok(mon != NULL, "mon == NULL\n");
1643
1644 hres = IMoniker_GetDisplayName(mon, NULL, 0, &name);
1645 ok(hres == S_OK, "GetDisplayName failed: %08x\n", hres);
1646 ok(!lstrcmpW(name, url9), "wrong display name %s\n", wine_dbgstr_w(name));
1647 CoTaskMemFree(name);
1648
1649 hres = IMoniker_IsSystemMoniker(mon, &issys);
1650 ok(hres == S_OK, "IsSystemMoniker failed: %08x\n", hres);
1651 ok(issys == MKSYS_URLMONIKER, "issys=%x\n", issys);
1652
1653 IMoniker_Release(mon);
1654
1655 hres = MkParseDisplayNameEx(bctx, clsid_nameW, &eaten, &mon);
1656 ok(hres == S_OK, "MkParseDisplayNameEx failed: %08x\n", hres);
1657 ok(eaten == sizeof(clsid_nameW)/sizeof(WCHAR)-1, "eaten=%d\n", eaten);
1658 ok(mon != NULL, "mon == NULL\n");
1659
1660 hres = IMoniker_IsSystemMoniker(mon, &issys);
1661 ok(hres == S_OK, "IsSystemMoniker failed: %08x\n", hres);
1662 ok(issys == MKSYS_CLASSMONIKER, "issys=%x\n", issys);
1663
1664 IMoniker_Release(mon);
1665
1666 hres = MkParseDisplayNameEx(bctx, url8, &eaten, &mon);
1667 ok(FAILED(hres), "MkParseDisplayNameEx succeeded: %08x\n", hres);
1668
1669 IBindCtx_Release(bctx);
1670 }
1671
1672 static void test_IsValidURL(void)
1673 {
1674 HRESULT hr;
1675 IBindCtx *bctx = NULL;
1676
1677 hr = IsValidURL(NULL, 0, 0);
1678 ok(hr == E_INVALIDARG, "Expected E_INVALIDARG, got %08x\n", hr);
1679
1680 hr = IsValidURL(NULL, wszHttpWineHQ, 0);
1681 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
1682
1683 CreateBindCtx(0, &bctx);
1684
1685 hr = IsValidURL(bctx, wszHttpWineHQ, 0);
1686 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
1687
1688 IBindCtx_Release(bctx);
1689 }
1690
1691 static const struct {
1692 INTERNETFEATURELIST feature;
1693 DWORD get_flags;
1694 HRESULT expected;
1695 BOOL todo;
1696 } default_feature_tests[] = {
1697 {FEATURE_OBJECT_CACHING,GET_FEATURE_FROM_PROCESS,S_OK},
1698 {FEATURE_ZONE_ELEVATION,GET_FEATURE_FROM_PROCESS,S_FALSE},
1699 {FEATURE_MIME_HANDLING,GET_FEATURE_FROM_PROCESS,S_FALSE},
1700 {FEATURE_MIME_SNIFFING,GET_FEATURE_FROM_PROCESS,S_FALSE},
1701 {FEATURE_WINDOW_RESTRICTIONS,GET_FEATURE_FROM_PROCESS,S_FALSE},
1702 {FEATURE_WEBOC_POPUPMANAGEMENT,GET_FEATURE_FROM_PROCESS,S_FALSE},
1703 {FEATURE_BEHAVIORS,GET_FEATURE_FROM_PROCESS,S_OK},
1704 {FEATURE_DISABLE_MK_PROTOCOL,GET_FEATURE_FROM_PROCESS,S_OK},
1705 {FEATURE_LOCALMACHINE_LOCKDOWN,GET_FEATURE_FROM_PROCESS,S_FALSE},
1706 {FEATURE_SECURITYBAND,GET_FEATURE_FROM_PROCESS,S_FALSE},
1707 {FEATURE_RESTRICT_ACTIVEXINSTALL,GET_FEATURE_FROM_PROCESS,S_FALSE},
1708 {FEATURE_VALIDATE_NAVIGATE_URL,GET_FEATURE_FROM_PROCESS,S_FALSE},
1709 {FEATURE_RESTRICT_FILEDOWNLOAD,GET_FEATURE_FROM_PROCESS,S_FALSE},
1710 {FEATURE_ADDON_MANAGEMENT,GET_FEATURE_FROM_PROCESS,S_FALSE},
1711 {FEATURE_PROTOCOL_LOCKDOWN,GET_FEATURE_FROM_PROCESS,S_FALSE},
1712 {FEATURE_HTTP_USERNAME_PASSWORD_DISABLE,GET_FEATURE_FROM_PROCESS,S_FALSE},
1713 {FEATURE_SAFE_BINDTOOBJECT,GET_FEATURE_FROM_PROCESS,S_FALSE},
1714 {FEATURE_UNC_SAVEDFILECHECK,GET_FEATURE_FROM_PROCESS,S_FALSE},
1715 {FEATURE_GET_URL_DOM_FILEPATH_UNENCODED,GET_FEATURE_FROM_PROCESS,S_OK},
1716 {FEATURE_TABBED_BROWSING,GET_FEATURE_FROM_PROCESS,S_FALSE},
1717 {FEATURE_SSLUX,GET_FEATURE_FROM_PROCESS,S_FALSE},
1718 {FEATURE_DISABLE_NAVIGATION_SOUNDS,GET_FEATURE_FROM_PROCESS,S_FALSE},
1719 {FEATURE_DISABLE_LEGACY_COMPRESSION,GET_FEATURE_FROM_PROCESS,S_OK},
1720 {FEATURE_FORCE_ADDR_AND_STATUS,GET_FEATURE_FROM_PROCESS,S_FALSE},
1721 {FEATURE_XMLHTTP,GET_FEATURE_FROM_PROCESS,S_OK},
1722 {FEATURE_DISABLE_TELNET_PROTOCOL,GET_FEATURE_FROM_PROCESS,S_FALSE},
1723 {FEATURE_FEEDS,GET_FEATURE_FROM_PROCESS,S_FALSE},
1724 {FEATURE_BLOCK_INPUT_PROMPTS,GET_FEATURE_FROM_PROCESS,S_FALSE}
1725 };
1726
1727 static void test_internet_feature_defaults(void) {
1728 HRESULT hres;
1729 DWORD i;
1730
1731 for(i = 0; i < sizeof(default_feature_tests)/sizeof(default_feature_tests[0]); ++i) {
1732 hres = pCoInternetIsFeatureEnabled(default_feature_tests[i].feature, default_feature_tests[i].get_flags);
1733 todo_wine_if (default_feature_tests[i].todo)
1734 ok(hres == default_feature_tests[i].expected, "CoInternetIsFeatureEnabled returned %08x, expected %08x on test %d\n",
1735 hres, default_feature_tests[i].expected, i);
1736 }
1737 }
1738
1739 /* With older versions of IE (IE 7 and earlier), urlmon caches
1740 * the FeatureControl values from the registry when it's loaded
1741 * into memory. Newer versions of IE conditionally cache the
1742 * the FeatureControl registry values (i.e. When a call to
1743 * CoInternetIsFeatureEnabled and a corresponding CoInternetSetFeatureEnabled
1744 * call hasn't already been made for the specified Feature). Because of
1745 * this we skip these tests on IE 7 and earlier.
1746 */
1747 static const char* szFeatureControlKey = "Software\\Microsoft\\Internet Explorer\\Main\\FeatureControl";
1748
1749 static void test_internet_features_registry(void) {
1750 HRESULT hres;
1751 DWORD res;
1752 char module[MAX_PATH];
1753 char *name;
1754 HKEY feature_control;
1755 HKEY feature;
1756 DWORD value;
1757 BOOL skip_zone;
1758 BOOL delete_feature_key = TRUE;
1759
1760 static const char* szFeatureBehaviorsKey = "FEATURE_BEHAVIORS";
1761 static const char* szFeatureZoneElevationKey = "FEATURE_ZONE_ELEVATION";
1762
1763 if(!pIEInstallScope) {
1764 win_skip("Skipping internet feature registry tests, IE is too old...\n");
1765 return;
1766 }
1767
1768 res = GetModuleFileNameA(NULL, module, sizeof(module));
1769 ok(res, "GetModuleFileName failed: %d\n", GetLastError());
1770
1771 name = strrchr(module, '\\')+1;
1772
1773 /* Some Windows machines don't have a FeatureControl key in HKCU. */
1774 res = RegOpenKeyA(HKEY_CURRENT_USER, szFeatureControlKey, &feature_control);
1775 ok(res == ERROR_SUCCESS, "RegCreateKey failed: %d\n", res);
1776
1777 res = RegOpenKeyA(feature_control, szFeatureBehaviorsKey, &feature);
1778 if(res == ERROR_SUCCESS) {
1779 /* FEATURE_BEHAVIORS already existed, so don't delete it when we're done. */
1780 delete_feature_key = FALSE;
1781 }else {
1782 res = RegCreateKeyA(feature_control, szFeatureBehaviorsKey, &feature);
1783 ok(res == ERROR_SUCCESS, "RegCreateKey failed: %d\n", res);
1784 }
1785
1786 value = 0;
1787 res = RegSetValueExA(feature, name, 0, REG_DWORD, (BYTE*)&value, sizeof(DWORD));
1788 ok(res == ERROR_SUCCESS, "RegSetValueEx failed: %d\n", res);
1789
1790 hres = pCoInternetIsFeatureEnabled(FEATURE_BEHAVIORS, GET_FEATURE_FROM_PROCESS);
1791 ok(hres == S_FALSE, "CoInternetIsFeatureEnabled returned %08x, expected S_FALSE\n", hres);
1792
1793 if(delete_feature_key) {
1794 RegCloseKey(feature);
1795 RegDeleteKeyA(feature_control, szFeatureBehaviorsKey);
1796 } else {
1797 RegDeleteValueA(feature, name);
1798 RegCloseKey(feature);
1799 }
1800
1801 /* IE's feature control cached the value it got from the registry earlier. */
1802 hres = pCoInternetIsFeatureEnabled(FEATURE_BEHAVIORS, GET_FEATURE_FROM_PROCESS);
1803 ok(hres == S_FALSE, "CoInternetIsFeatureEnabled returned %08x, expected S_FALSE\n", hres);
1804
1805 /* Restore this feature back to its default value. */
1806 hres = pCoInternetSetFeatureEnabled(FEATURE_BEHAVIORS, SET_FEATURE_ON_PROCESS, TRUE);
1807 ok(hres == S_OK, "CoInternetSetFeatureEnabled failed: %08x\n", hres);
1808
1809 RegCloseKey(feature_control);
1810
1811 res = RegOpenKeyA(HKEY_LOCAL_MACHINE, szFeatureControlKey, &feature_control);
1812 ok(res == ERROR_SUCCESS, "RegOpenKey failed: %d\n", res);
1813
1814 res = RegOpenKeyA(feature_control, szFeatureZoneElevationKey, &feature);
1815 ok(res == ERROR_SUCCESS, "RegOpenKey failed: %d\n", res);
1816
1817 value = 1;
1818 res = RegSetValueExA(feature, "*", 0, REG_DWORD, (BYTE*)&value, sizeof(DWORD));
1819 if (res == ERROR_ACCESS_DENIED)
1820 {
1821 skip("Not allowed to modify zone elevation\n");
1822 skip_zone = TRUE;
1823 }
1824 else
1825 {
1826 skip_zone = FALSE;
1827 ok(res == ERROR_SUCCESS, "RegSetValueEx failed: %d\n", res);
1828
1829 hres = pCoInternetIsFeatureEnabled(FEATURE_ZONE_ELEVATION, GET_FEATURE_FROM_PROCESS);
1830 ok(hres == S_OK, "CoInternetIsFeatureEnabled returned %08x, expected S_OK\n", hres);
1831 }
1832 RegDeleteValueA(feature, "*");
1833 RegCloseKey(feature);
1834 RegCloseKey(feature_control);
1835
1836 /* Value is still cached from last time. */
1837 if (!skip_zone)
1838 {
1839 hres = pCoInternetIsFeatureEnabled(FEATURE_ZONE_ELEVATION, GET_FEATURE_FROM_PROCESS);
1840 ok(hres == S_OK, "CoInternetIsFeatureEnabled returned %08x, expected S_OK\n", hres);
1841
1842 hres = pCoInternetSetFeatureEnabled(FEATURE_ZONE_ELEVATION, SET_FEATURE_ON_PROCESS, FALSE);
1843 ok(hres == S_OK, "CoInternetSetFeatureEnabled failed: %08x\n", hres);
1844 }
1845
1846 test_internet_feature_defaults();
1847 }
1848
1849 static void test_CoInternetIsFeatureEnabled(void) {
1850 HRESULT hres;
1851
1852 hres = pCoInternetIsFeatureEnabled(FEATURE_ENTRY_COUNT, GET_FEATURE_FROM_PROCESS);
1853 ok(hres == E_FAIL, "CoInternetIsFeatureEnabled returned %08x, expected E_FAIL\n", hres);
1854 }
1855
1856 static const struct {
1857 INTERNETFEATURELIST feature;
1858 DWORD set_flags;
1859 BOOL enable;
1860 HRESULT set_expected;
1861 BOOL set_todo;
1862 DWORD get_flags;
1863 HRESULT get_expected;
1864 BOOL get_todo;
1865 } internet_feature_tests[] = {
1866 {FEATURE_OBJECT_CACHING,SET_FEATURE_ON_PROCESS,FALSE,S_OK,FALSE,GET_FEATURE_FROM_PROCESS,S_FALSE},
1867 {FEATURE_WEBOC_POPUPMANAGEMENT,SET_FEATURE_ON_PROCESS,TRUE,S_OK,FALSE,GET_FEATURE_FROM_PROCESS,S_OK},
1868 {FEATURE_LOCALMACHINE_LOCKDOWN,SET_FEATURE_ON_PROCESS,TRUE,S_OK,FALSE,GET_FEATURE_FROM_PROCESS,S_OK}
1869 };
1870
1871 static void test_CoInternetSetFeatureEnabled(void) {
1872 HRESULT hres;
1873 DWORD i;
1874
1875 hres = pCoInternetSetFeatureEnabled(FEATURE_ENTRY_COUNT,SET_FEATURE_ON_PROCESS,TRUE);
1876 ok(hres == E_FAIL, "CoInternetSetFeatureEnabled returned %08x, expected E_FAIL\n", hres);
1877
1878 for(i = 0; i < sizeof(internet_feature_tests)/sizeof(internet_feature_tests[0]); ++i) {
1879 hres = pCoInternetSetFeatureEnabled(internet_feature_tests[i].feature, internet_feature_tests[i].set_flags,
1880 internet_feature_tests[i].enable);
1881 todo_wine_if (internet_feature_tests[i].set_todo)
1882 ok(hres == internet_feature_tests[i].set_expected, "CoInternetSetFeatureEnabled returned %08x, expected %08x on test %d\n",
1883 hres, internet_feature_tests[i].set_expected, i);
1884
1885 hres = pCoInternetIsFeatureEnabled(internet_feature_tests[i].feature, internet_feature_tests[i].set_flags);
1886 todo_wine_if (internet_feature_tests[i].get_todo)
1887 ok(hres == internet_feature_tests[i].get_expected, "CoInternetIsFeatureEnabled returned %08x, expected %08x on test %d\n",
1888 hres, internet_feature_tests[i].get_expected, i);
1889
1890 }
1891 }
1892
1893 static void test_internet_features(void) {
1894 HKEY key;
1895 DWORD res;
1896
1897 if(!pCoInternetIsFeatureEnabled || !pCoInternetSetFeatureEnabled) {
1898 win_skip("Skipping internet feature tests, IE is too old\n");
1899 return;
1900 }
1901
1902 /* IE10 takes FeatureControl key into account only if it's available upon process start. */
1903 res = RegOpenKeyA(HKEY_CURRENT_USER, szFeatureControlKey, &key);
1904 if(res != ERROR_SUCCESS) {
1905 PROCESS_INFORMATION pi;
1906 STARTUPINFOA si = { 0 };
1907 char cmdline[MAX_PATH];
1908 char **argv;
1909 BOOL ret;
1910
1911 res = RegCreateKeyA(HKEY_CURRENT_USER, szFeatureControlKey, &key);
1912 ok(res == ERROR_SUCCESS, "RegCreateKey failed: %d\n", res);
1913
1914 trace("Running features tests in a separated process.\n");
1915
1916 winetest_get_mainargs( &argv );
1917 sprintf(cmdline, "\"%s\" %s internet_features", argv[0], argv[1]);
1918 ret = CreateProcessA(argv[0], cmdline, NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi);
1919 ok(ret, "Could not create process: %u\n", GetLastError());
1920 winetest_wait_child_process( pi.hProcess );
1921 CloseHandle(pi.hThread);
1922 CloseHandle(pi.hProcess);
1923
1924 RegDeleteKeyA(HKEY_CURRENT_USER, szFeatureControlKey);
1925 return;
1926 }
1927
1928 test_internet_features_registry();
1929 test_CoInternetIsFeatureEnabled();
1930 test_CoInternetSetFeatureEnabled();
1931 }
1932
1933 START_TEST(misc)
1934 {
1935 HMODULE hurlmon;
1936 int argc;
1937 char **argv;
1938
1939 argc = winetest_get_mainargs(&argv);
1940
1941 hurlmon = GetModuleHandleA("urlmon.dll");
1942 pCoInternetCompareUrl = (void *) GetProcAddress(hurlmon, "CoInternetCompareUrl");
1943 pCoInternetGetSecurityUrl = (void*) GetProcAddress(hurlmon, "CoInternetGetSecurityUrl");
1944 pCoInternetGetSession = (void*) GetProcAddress(hurlmon, "CoInternetGetSession");
1945 pCoInternetParseUrl = (void*) GetProcAddress(hurlmon, "CoInternetParseUrl");
1946 pCoInternetQueryInfo = (void*) GetProcAddress(hurlmon, "CoInternetQueryInfo");
1947 pCopyStgMedium = (void*) GetProcAddress(hurlmon, "CopyStgMedium");
1948 pCopyBindInfo = (void*) GetProcAddress(hurlmon, "CopyBindInfo");
1949 pFindMimeFromData = (void*) GetProcAddress(hurlmon, "FindMimeFromData");
1950 pObtainUserAgentString = (void*) GetProcAddress(hurlmon, "ObtainUserAgentString");
1951 pReleaseBindInfo = (void*) GetProcAddress(hurlmon, "ReleaseBindInfo");
1952 pUrlMkGetSessionOption = (void*) GetProcAddress(hurlmon, "UrlMkGetSessionOption");
1953 pCompareSecurityIds = (void*) GetProcAddress(hurlmon, "CompareSecurityIds");
1954 pCoInternetIsFeatureEnabled = (void*) GetProcAddress(hurlmon, "CoInternetIsFeatureEnabled");
1955 pCoInternetSetFeatureEnabled = (void*) GetProcAddress(hurlmon, "CoInternetSetFeatureEnabled");
1956 pIEInstallScope = (void*) GetProcAddress(hurlmon, "IEInstallScope");
1957
1958 if (!pCoInternetCompareUrl || !pCoInternetGetSecurityUrl ||
1959 !pCoInternetGetSession || !pCoInternetParseUrl || !pCompareSecurityIds) {
1960 win_skip("Various needed functions not present, too old IE\n");
1961 return;
1962 }
1963
1964 OleInitialize(NULL);
1965
1966 if(argc <= 2 || strcmp(argv[2], "internet_features")) {
1967 register_protocols();
1968
1969 test_CreateFormatEnum();
1970 test_RegisterFormatEnumerator();
1971 test_CoInternetParseUrl();
1972 test_CoInternetCompareUrl();
1973 test_CoInternetQueryInfo();
1974 test_FindMimeFromData();
1975 test_NameSpace();
1976 test_MimeFilter();
1977 test_ReleaseBindInfo();
1978 test_CopyStgMedium();
1979 test_CopyBindInfo();
1980 test_UrlMkGetSessionOption();
1981 test_user_agent();
1982 test_MkParseDisplayNameEx();
1983 test_IsValidURL();
1984 }
1985
1986 test_internet_features();
1987
1988 OleUninitialize();
1989 }