user32/tests: Fix the listbox delete test on NT4.
[wine] / dlls / urlmon / tests / 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 COBJMACROS
20 #define CONST_VTABLE
21 #define NONAMELESSUNION
22
23 #include <wine/test.h>
24 #include <stdarg.h>
25 #include <stddef.h>
26
27 #include "windef.h"
28 #include "winbase.h"
29 #include "ole2.h"
30 #include "urlmon.h"
31
32 #include "initguid.h"
33
34 DEFINE_GUID(CLSID_AboutProtocol, 0x3050F406, 0x98B5, 0x11CF, 0xBB,0x82, 0x00,0xAA,0x00,0xBD,0xCE,0x0B);
35
36 #define DEFINE_EXPECT(func) \
37     static BOOL expect_ ## func = FALSE, called_ ## func = FALSE
38
39 #define SET_EXPECT(func) \
40     expect_ ## func = TRUE
41
42 #define CHECK_EXPECT(func) \
43     do { \
44         ok(expect_ ##func, "unexpected call " #func "\n"); \
45         expect_ ## func = FALSE; \
46         called_ ## func = TRUE; \
47     }while(0)
48
49 #define CHECK_EXPECT2(func) \
50     do { \
51         ok(expect_ ##func, "unexpected call " #func "\n"); \
52         called_ ## func = TRUE; \
53     }while(0)
54
55 #define CHECK_CALLED(func) \
56     do { \
57         ok(called_ ## func, "expected " #func "\n"); \
58         expect_ ## func = called_ ## func = FALSE; \
59     }while(0)
60
61 DEFINE_EXPECT(ParseUrl);
62 DEFINE_EXPECT(QI_IInternetProtocolInfo);
63 DEFINE_EXPECT(CreateInstance);
64 DEFINE_EXPECT(unk_Release);
65
66 static const char *debugstr_w(LPCWSTR str)
67 {
68     static char buf[1024];
69     WideCharToMultiByte(CP_ACP, 0, str, -1, buf, sizeof(buf), NULL, NULL);
70     return buf;
71 }
72
73 static void test_CreateFormatEnum(void)
74 {
75     IEnumFORMATETC *fenum = NULL, *fenum2 = NULL;
76     FORMATETC fetc[5];
77     ULONG ul;
78     HRESULT hres;
79
80     static DVTARGETDEVICE dev = {sizeof(dev),0,0,0,0,{0}};
81     static FORMATETC formatetc[] = {
82         {0,&dev,0,0,0},
83         {0,&dev,0,1,0},
84         {0,NULL,0,2,0},
85         {0,NULL,0,3,0},
86         {0,NULL,0,4,0}
87     };
88
89     hres = CreateFormatEnumerator(0, formatetc, &fenum);
90     ok(hres == E_FAIL, "CreateFormatEnumerator failed: %08x, expected E_FAIL\n", hres);
91     hres = CreateFormatEnumerator(0, formatetc, NULL);
92     ok(hres == E_INVALIDARG, "CreateFormatEnumerator failed: %08x, expected E_INVALIDARG\n", hres);
93     hres = CreateFormatEnumerator(5, formatetc, NULL);
94     ok(hres == E_INVALIDARG, "CreateFormatEnumerator failed: %08x, expected E_INVALIDARG\n", hres);
95
96
97     hres = CreateFormatEnumerator(5, formatetc, &fenum);
98     ok(hres == S_OK, "CreateFormatEnumerator failed: %08x\n", hres);
99     if(FAILED(hres))
100         return;
101
102     hres = IEnumFORMATETC_Next(fenum, 2, NULL, &ul);
103     ok(hres == E_INVALIDARG, "Next failed: %08x, expected E_INVALIDARG\n", hres);
104     ul = 100;
105     hres = IEnumFORMATETC_Next(fenum, 0, fetc, &ul);
106     ok(hres == S_OK, "Next failed: %08x\n", hres);
107     ok(ul == 0, "ul=%d, expected 0\n", ul);
108
109     hres = IEnumFORMATETC_Next(fenum, 2, fetc, &ul);
110     ok(hres == S_OK, "Next failed: %08x\n", hres);
111     ok(fetc[0].lindex == 0, "fetc[0].lindex=%d, expected 0\n", fetc[0].lindex);
112     ok(fetc[1].lindex == 1, "fetc[1].lindex=%d, expected 1\n", fetc[1].lindex);
113     ok(fetc[0].ptd == &dev, "fetc[0].ptd=%p, expected %p\n", fetc[0].ptd, &dev);
114     ok(ul == 2, "ul=%d, expected 2\n", ul);
115
116     hres = IEnumFORMATETC_Skip(fenum, 1);
117     ok(hres == S_OK, "Skip failed: %08x\n", hres);
118
119     hres = IEnumFORMATETC_Next(fenum, 4, fetc, &ul);
120     ok(hres == S_FALSE, "Next failed: %08x, expected S_FALSE\n", hres);
121     ok(fetc[0].lindex == 3, "fetc[0].lindex=%d, expected 3\n", fetc[0].lindex);
122     ok(fetc[1].lindex == 4, "fetc[1].lindex=%d, expected 4\n", fetc[1].lindex);
123     ok(fetc[0].ptd == NULL, "fetc[0].ptd=%p, expected NULL\n", fetc[0].ptd);
124     ok(ul == 2, "ul=%d, expected 2\n", ul);
125
126     hres = IEnumFORMATETC_Next(fenum, 4, fetc, &ul);
127     ok(hres == S_FALSE, "Next failed: %08x, expected S_FALSE\n", hres);
128     ok(ul == 0, "ul=%d, expected 0\n", ul);
129     ul = 100;
130     hres = IEnumFORMATETC_Next(fenum, 0, fetc, &ul);
131     ok(hres == S_OK, "Next failed: %08x\n", hres);
132     ok(ul == 0, "ul=%d, expected 0\n", ul);
133
134     hres = IEnumFORMATETC_Skip(fenum, 3);
135     ok(hres == S_FALSE, "Skip failed: %08x, expected S_FALSE\n", hres);
136
137     hres = IEnumFORMATETC_Reset(fenum);
138     ok(hres == S_OK, "Reset failed: %08x\n", hres);
139
140     hres = IEnumFORMATETC_Next(fenum, 5, fetc, NULL);
141     ok(hres == S_OK, "Next failed: %08x\n", hres);
142     ok(fetc[0].lindex == 0, "fetc[0].lindex=%d, expected 0\n", fetc[0].lindex);
143
144     hres = IEnumFORMATETC_Reset(fenum);
145     ok(hres == S_OK, "Reset failed: %08x\n", hres);
146
147     hres = IEnumFORMATETC_Skip(fenum, 2);
148     ok(hres == S_OK, "Skip failed: %08x\n", hres);
149
150     hres = IEnumFORMATETC_Clone(fenum, NULL);
151     ok(hres == E_INVALIDARG, "Clone failed: %08x, expected E_INVALIDARG\n", hres);
152
153     hres = IEnumFORMATETC_Clone(fenum, &fenum2);
154     ok(hres == S_OK, "Clone failed: %08x\n", hres);
155
156     if(SUCCEEDED(hres)) {
157         ok(fenum != fenum2, "fenum == fenum2\n");
158
159         hres = IEnumFORMATETC_Next(fenum2, 2, fetc, &ul);
160         ok(hres == S_OK, "Next failed: %08x\n", hres);
161         ok(fetc[0].lindex == 2, "fetc[0].lindex=%d, expected 2\n", fetc[0].lindex);
162
163         IEnumFORMATETC_Release(fenum2);
164     }
165
166     hres = IEnumFORMATETC_Next(fenum, 2, fetc, &ul);
167     ok(hres == S_OK, "Next failed: %08x\n", hres);
168     ok(fetc[0].lindex == 2, "fetc[0].lindex=%d, expected 2\n", fetc[0].lindex);
169
170     hres = IEnumFORMATETC_Skip(fenum, 1);
171     ok(hres == S_OK, "Skip failed: %08x\n", hres);
172     
173     IEnumFORMATETC_Release(fenum);
174 }
175
176 static void test_RegisterFormatEnumerator(void)
177 {
178     IBindCtx *bctx = NULL;
179     IEnumFORMATETC *format = NULL, *format2 = NULL;
180     IUnknown *unk = NULL;
181     HRESULT hres;
182
183     static FORMATETC formatetc = {0,NULL,0,0,0};
184     static WCHAR wszEnumFORMATETC[] =
185         {'_','E','n','u','m','F','O','R','M','A','T','E','T','C','_',0};
186
187     CreateBindCtx(0, &bctx);
188
189     hres = CreateFormatEnumerator(1, &formatetc, &format);
190     ok(hres == S_OK, "CreateFormatEnumerator failed: %08x\n", hres);
191     if(FAILED(hres))
192         return;
193
194     hres = RegisterFormatEnumerator(NULL, format, 0);
195     ok(hres == E_INVALIDARG,
196             "RegisterFormatEnumerator failed: %08x, expected E_INVALIDARG\n", hres);
197     hres = RegisterFormatEnumerator(bctx, NULL, 0);
198     ok(hres == E_INVALIDARG,
199             "RegisterFormatEnumerator failed: %08x, expected E_INVALIDARG\n", hres);
200
201     hres = RegisterFormatEnumerator(bctx, format, 0);
202     ok(hres == S_OK, "RegisterFormatEnumerator failed: %08x\n", hres);
203
204     hres = IBindCtx_GetObjectParam(bctx, wszEnumFORMATETC, &unk);
205     ok(hres == S_OK, "GetObjectParam failed: %08x\n", hres);
206     ok(unk == (IUnknown*)format, "unk != format\n");
207
208     hres = RevokeFormatEnumerator(NULL, format);
209     ok(hres == E_INVALIDARG,
210             "RevokeFormatEnumerator failed: %08x, expected E_INVALIDARG\n", hres);
211
212     hres = RevokeFormatEnumerator(bctx, format);
213     ok(hres == S_OK, "RevokeFormatEnumerator failed: %08x\n", hres);
214
215     hres = RevokeFormatEnumerator(bctx, format);
216     ok(hres == E_FAIL, "RevokeFormatEnumerator failed: %08x, expected E_FAIL\n", hres);
217
218     hres = IBindCtx_GetObjectParam(bctx, wszEnumFORMATETC, &unk);
219     ok(hres == E_FAIL, "GetObjectParam failed: %08x, expected E_FAIL\n", hres);
220
221     hres = RegisterFormatEnumerator(bctx, format, 0);
222     ok(hres == S_OK, "RegisterFormatEnumerator failed: %08x\n", hres);
223
224     hres = CreateFormatEnumerator(1, &formatetc, &format2);
225     ok(hres == S_OK, "CreateFormatEnumerator failed: %08x\n", hres);
226
227     if(SUCCEEDED(hres)) {
228         hres = RevokeFormatEnumerator(bctx, format);
229         ok(hres == S_OK, "RevokeFormatEnumerator failed: %08x\n", hres);
230
231         IEnumFORMATETC_Release(format2);
232     }
233
234     hres = IBindCtx_GetObjectParam(bctx, wszEnumFORMATETC, &unk);
235     ok(hres == E_FAIL, "GetObjectParam failed: %08x, expected E_FAIL\n", hres);
236
237     IEnumFORMATETC_Release(format);
238
239     hres = RegisterFormatEnumerator(bctx, format, 0);
240     ok(hres == S_OK, "RegisterFormatEnumerator failed: %08x\n", hres);
241     hres = RevokeFormatEnumerator(bctx, NULL);
242     ok(hres == S_OK, "RevokeFormatEnumerator failed: %08x\n", hres);
243     hres = IBindCtx_GetObjectParam(bctx, wszEnumFORMATETC, &unk);
244     ok(hres == E_FAIL, "GetObjectParam failed: %08x, expected E_FAIL\n", hres);
245
246     IEnumFORMATETC_Release(format);
247     IBindCtx_Release(bctx);
248 }
249
250 static const WCHAR url1[] = {'r','e','s',':','/','/','m','s','h','t','m','l','.','d','l','l',
251         '/','b','l','a','n','k','.','h','t','m',0};
252 static const WCHAR url2[] = {'i','n','d','e','x','.','h','t','m',0};
253 static const WCHAR url3[] = {'f','i','l','e',':','/','/','c',':','\\','I','n','d','e','x','.','h','t','m',0};
254 static const WCHAR url4[] = {'f','i','l','e',':','s','o','m','e','%','2','0','f','i','l','e',
255         '%','2','e','j','p','g',0};
256 static const WCHAR url5[] = {'h','t','t','p',':','/','/','w','w','w','.','w','i','n','e','h','q',
257         '.','o','r','g',0};
258 static const WCHAR url6[] = {'a','b','o','u','t',':','b','l','a','n','k',0};
259 static const WCHAR url7[] = {'f','t','p',':','/','/','w','i','n','e','h','q','.','o','r','g','/',
260         'f','i','l','e','.','t','e','s','t',0};
261 static const WCHAR url8[] = {'t','e','s','t',':','1','2','3','a','b','c',0};
262 static const WCHAR url9[] =
263     {'h','t','t','p',':','/','/','w','w','w','.','w','i','n','e','h','q','.','o','r','g',
264      '/','s','i','t','e','/','a','b','o','u','t',0};
265 static const WCHAR url10[] = {'f','i','l','e',':','/','/','s','o','m','e','%','2','0','f','i','l','e',
266         '.','j','p','g',0};
267
268 static const WCHAR url4e[] = {'f','i','l','e',':','s','o','m','e',' ','f','i','l','e',
269         '.','j','p','g',0};
270
271 static const WCHAR path3[] = {'c',':','\\','I','n','d','e','x','.','h','t','m',0};
272 static const WCHAR path4[] = {'s','o','m','e',' ','f','i','l','e','.','j','p','g',0};
273
274 static const WCHAR wszRes[] = {'r','e','s',0};
275 static const WCHAR wszFile[] = {'f','i','l','e',0};
276 static const WCHAR wszHttp[] = {'h','t','t','p',0};
277 static const WCHAR wszAbout[] = {'a','b','o','u','t',0};
278 static const WCHAR wszEmpty[] = {0};
279
280 struct parse_test {
281     LPCWSTR url;
282     HRESULT secur_hres;
283     LPCWSTR encoded_url;
284     HRESULT path_hres;
285     LPCWSTR path;
286     LPCWSTR schema;
287 };
288
289 static const struct parse_test parse_tests[] = {
290     {url1, S_OK,   url1,  E_INVALIDARG, NULL, wszRes},
291     {url2, E_FAIL, url2,  E_INVALIDARG, NULL, wszEmpty},
292     {url3, E_FAIL, url3,  S_OK, path3,        wszFile},
293     {url4, E_FAIL, url4e, S_OK, path4,        wszFile},
294     {url5, E_FAIL, url5,  E_INVALIDARG, NULL, wszHttp},
295     {url6, S_OK,   url6,  E_INVALIDARG, NULL, wszAbout}
296 };
297
298 static void test_CoInternetParseUrl(void)
299 {
300     HRESULT hres;
301     DWORD size;
302     int i;
303
304     static WCHAR buf[4096];
305
306     memset(buf, 0xf0, sizeof(buf));
307     hres = CoInternetParseUrl(parse_tests[0].url, PARSE_SCHEMA, 0, buf,
308             3, &size, 0);
309     ok(hres == E_POINTER, "schema failed: %08x, expected E_POINTER\n", hres);
310
311     for(i=0; i < sizeof(parse_tests)/sizeof(parse_tests[0]); i++) {
312         memset(buf, 0xf0, sizeof(buf));
313         hres = CoInternetParseUrl(parse_tests[i].url, PARSE_SECURITY_URL, 0, buf,
314                 sizeof(buf)/sizeof(WCHAR), &size, 0);
315         ok(hres == parse_tests[i].secur_hres, "[%d] security url failed: %08x, expected %08x\n",
316                 i, hres, parse_tests[i].secur_hres);
317
318         memset(buf, 0xf0, sizeof(buf));
319         hres = CoInternetParseUrl(parse_tests[i].url, PARSE_ENCODE, 0, buf,
320                 sizeof(buf)/sizeof(WCHAR), &size, 0);
321         ok(hres == S_OK, "[%d] encoding failed: %08x\n", i, hres);
322         ok(size == lstrlenW(parse_tests[i].encoded_url), "[%d] wrong size\n", i);
323         ok(!lstrcmpW(parse_tests[i].encoded_url, buf), "[%d] wrong encoded url\n", i);
324
325         memset(buf, 0xf0, sizeof(buf));
326         hres = CoInternetParseUrl(parse_tests[i].url, PARSE_PATH_FROM_URL, 0, buf,
327                 sizeof(buf)/sizeof(WCHAR), &size, 0);
328         ok(hres == parse_tests[i].path_hres, "[%d] path failed: %08x, expected %08x\n",
329                 i, hres, parse_tests[i].path_hres);
330         if(parse_tests[i].path) {
331             ok(size == lstrlenW(parse_tests[i].path), "[%d] wrong size\n", i);
332             ok(!lstrcmpW(parse_tests[i].path, buf), "[%d] wrong path\n", i);
333         }
334
335         memset(buf, 0xf0, sizeof(buf));
336         hres = CoInternetParseUrl(parse_tests[i].url, PARSE_SCHEMA, 0, buf,
337                 sizeof(buf)/sizeof(WCHAR), &size, 0);
338         ok(hres == S_OK, "[%d] schema failed: %08x\n", i, hres);
339         ok(size == lstrlenW(parse_tests[i].schema), "[%d] wrong size\n", i);
340         ok(!lstrcmpW(parse_tests[i].schema, buf), "[%d] wrong schema\n", i);
341     }
342 }
343
344 static void test_CoInternetCompareUrl(void)
345 {
346     HRESULT hres;
347
348     hres = CoInternetCompareUrl(url1, url1, 0);
349     ok(hres == S_OK, "CoInternetParseUrl failed: %08x\n", hres);
350
351     hres = CoInternetCompareUrl(url1, url3, 0);
352     ok(hres == S_FALSE, "CoInternetParseUrl failed: %08x\n", hres);
353
354     hres = CoInternetCompareUrl(url3, url1, 0);
355     ok(hres == S_FALSE, "CoInternetParseUrl failed: %08x\n", hres);
356 }
357
358 static const struct {
359     LPCWSTR url;
360     DWORD uses_net;
361 } query_info_tests[] = {
362     {url1, 0},
363     {url2, 0},
364     {url3, 0},
365     {url4, 0},
366     {url5, 0},
367     {url6, 0},
368     {url7, 0},
369     {url8, 0}
370 };
371
372 static void test_CoInternetQueryInfo(void)
373 {
374     BYTE buf[100];
375     DWORD cb, i;
376     HRESULT hres;
377
378     for(i=0; i < sizeof(query_info_tests)/sizeof(query_info_tests[0]); i++) {
379         cb = 0xdeadbeef;
380         memset(buf, '?', sizeof(buf));
381         hres = CoInternetQueryInfo(query_info_tests[0].url, QUERY_USES_NETWORK, 0, buf, sizeof(buf), &cb, 0);
382         ok(hres == S_OK, "[%d] CoInternetQueryInfo failed: %08x\n", i, hres);
383         ok(cb == sizeof(DWORD), "[%d] cb = %d\n", i, cb);
384         ok(*(DWORD*)buf == query_info_tests[i].uses_net, "[%d] ret %x, expected %x\n",
385            i, *(DWORD*)buf, query_info_tests[i].uses_net);
386
387         hres = CoInternetQueryInfo(query_info_tests[0].url, QUERY_USES_NETWORK, 0, buf, 3, &cb, 0);
388         ok(hres == E_FAIL, "[%d] CoInternetQueryInfo failed: %08x, expected E_FAIL\n", i, hres);
389         hres = CoInternetQueryInfo(query_info_tests[0].url, QUERY_USES_NETWORK, 0, NULL, sizeof(buf), &cb, 0);
390         ok(hres == E_FAIL, "[%d] CoInternetQueryInfo failed: %08x, expected E_FAIL\n", i, hres);
391
392         memset(buf, '?', sizeof(buf));
393         hres = CoInternetQueryInfo(query_info_tests[0].url, QUERY_USES_NETWORK, 0, buf, sizeof(buf), NULL, 0);
394         ok(hres == S_OK, "[%d] CoInternetQueryInfo failed: %08x\n", i, hres);
395         ok(*(DWORD*)buf == query_info_tests[i].uses_net, "[%d] ret %x, expected %x\n",
396            i, *(DWORD*)buf, query_info_tests[i].uses_net);
397     }
398 }
399
400 static const WCHAR mimeTextHtml[] = {'t','e','x','t','/','h','t','m','l',0};
401 static const WCHAR mimeTextPlain[] = {'t','e','x','t','/','p','l','a','i','n',0};
402 static const WCHAR mimeTextRichtext[] = {'t','e','x','t','/','r','i','c','h','t','e','x','t',0};
403 static const WCHAR mimeAppOctetStream[] = {'a','p','p','l','i','c','a','t','i','o','n','/',
404     'o','c','t','e','t','-','s','t','r','e','a','m',0};
405 static const WCHAR mimeImagePjpeg[] = {'i','m','a','g','e','/','p','j','p','e','g',0};
406 static const WCHAR mimeImageGif[] = {'i','m','a','g','e','/','g','i','f',0};
407 static const WCHAR mimeImageBmp[] = {'i','m','a','g','e','/','b','m','p',0};
408 static const WCHAR mimeImageXPng[] = {'i','m','a','g','e','/','x','-','p','n','g',0};
409 static const WCHAR mimeImageTiff[] = {'i','m','a','g','e','/','t','i','f','f',0};
410 static const WCHAR mimeVideoAvi[] = {'v','i','d','e','o','/','a','v','i',0};
411 static const WCHAR mimeVideoMpeg[] = {'v','i','d','e','o','/','m','p','e','g',0};
412 static const WCHAR mimeAppPostscript[] =
413     {'a','p','p','l','i','c','a','t','i','o','n','/','p','o','s','t','s','c','r','i','p','t',0};
414 static const WCHAR mimeAppXCompressed[] = {'a','p','p','l','i','c','a','t','i','o','n','/',
415                                     'x','-','c','o','m','p','r','e','s','s','e','d',0};
416 static const WCHAR mimeAppXZip[] = {'a','p','p','l','i','c','a','t','i','o','n','/',
417                                     'x','-','z','i','p','-','c','o','m','p','r','e','s','s','e','d',0};
418 static const WCHAR mimeAppXGzip[] = {'a','p','p','l','i','c','a','t','i','o','n','/',
419                                     'x','-','g','z','i','p','-','c','o','m','p','r','e','s','s','e','d',0};
420 static const WCHAR mimeAppJava[] = {'a','p','p','l','i','c','a','t','i','o','n','/','j','a','v','a',0};
421 static const WCHAR mimeAppPdf[] = {'a','p','p','l','i','c','a','t','i','o','n','/','p','d','f',0};
422 static const WCHAR mimeAppXMSDownload[] =
423     {'a','p','p','l','i','c','a','t','i','o','n','/','x','-','m','s','d','o','w','n','l','o','a','d',0};
424 static const WCHAR mimeAudioWav[] = {'a','u','d','i','o','/','w','a','v',0};
425 static const WCHAR mimeAudioBasic[] = {'a','u','d','i','o','/','b','a','s','i','c',0};
426
427 static const struct {
428     LPCWSTR url;
429     LPCWSTR mime;
430     HRESULT hres;
431 } mime_tests[] = {
432     {url1, mimeTextHtml, S_OK},
433     {url2, mimeTextHtml, S_OK},
434     {url3, mimeTextHtml, S_OK},
435     {url4, NULL, E_FAIL},
436     {url5, NULL, __HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND)},
437     {url6, NULL, E_FAIL},
438     {url7, NULL, __HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND)}
439 };
440
441 static BYTE data1[] = "test data\n";
442 static BYTE data2[] = {31,'t','e','s',0xfa,'t',' ','d','a','t','a','\n',0};
443 static BYTE data3[] = {0,0,0};
444 static BYTE data4[] = {'t','e','s',0xfa,'t',' ','d','a','t','a','\n',0,0};
445 static BYTE data5[] = {0xa,0xa,0xa,'x',32,'x',0};
446 static BYTE data6[] = {0xfa,0xfa,0xfa,0xfa,'\n','\r','\t','x','x','x',1};
447 static BYTE data7[] = "<html>blahblah";
448 static BYTE data8[] = {'t','e','s',0xfa,'t',' ','<','h','t','m','l','>','d','a','t','a','\n',0,0};
449 static BYTE data9[] = {'t','e',0,'s',0xfa,'t',' ','<','h','t','m','l','>','d','a','t','a','\n',0,0};
450 static BYTE data10[] = "<HtmL>blahblah";
451 static BYTE data11[] = "blah<HTML>blahblah";
452 static BYTE data12[] = "blah<HTMLblahblah";
453 static BYTE data13[] = "blahHTML>blahblah";
454 static BYTE data14[] = "blah<HTMblahblah";
455 static BYTE data15[] = {0xff,0xd8};
456 static BYTE data16[] = {0xff,0xd8,'h'};
457 static BYTE data17[] = {0,0xff,0xd8};
458 static BYTE data18[] = {0xff,0xd8,'<','h','t','m','l','>'};
459 static BYTE data19[] = {'G','I','F','8','7','a'};
460 static BYTE data20[] = {'G','I','F','8','9','a'};
461 static BYTE data21[] = {'G','I','F','8','7'};
462 static BYTE data22[] = {'G','i','F','8','7','a'};
463 static BYTE data23[] = {'G','i','F','8','8','a'};
464 static BYTE data24[] = {'g','i','f','8','7','a'};
465 static BYTE data25[] = {'G','i','F','8','7','A'};
466 static BYTE data26[] = {'G','i','F','8','7','a','<','h','t','m','l','>'};
467 static BYTE data27[] = {0x30,'G','i','F','8','7','A'};
468 static BYTE data28[] = {0x42,0x4d,0x6e,0x42,0x1c,0x00,0x00,0x00,0x00,0x00,0x36,0x00,0x00,0x00};
469 static BYTE data29[] = {0x42,0x4d,'x','x','x','x',0x00,0x00,0x00,0x00,'x','x','x','x'};
470 static BYTE data30[] = {0x42,0x4d,'x','x','x','x',0x00,0x01,0x00,0x00,'x','x','x','x'};
471 static BYTE data31[] = {0x42,0x4d,'x','x','x','x',0x00,0x00,0x00,0x00,'<','h','t','m','l','>'};
472 static BYTE data32[] = {0x42,0x4d,'x','x','x','x',0x00,0x00,0x00,0x00,'x','x','x'};
473 static BYTE data33[] = {0x00,0x42,0x4d,'x','x','x','x',0x00,0x00,0x00,0x00,'x','x','x'};
474 static BYTE data34[] = {0x89,'P','N','G',0x0d,0x0a,0x1a,0x0a,'x'};
475 static BYTE data35[] = {0x89,'P','N','G',0x0d,0x0a,0x1a,0x0a,'x','x','x','x',0};
476 static BYTE data36[] = {0x89,'P','N','G',0x0d,0x0a,0x1a,'x','x'};
477 static BYTE data37[] = {0x89,'P','N','G',0x0d,0x0a,0x1a,0x0a,'<','h','t','m','l','>'};
478 static BYTE data38[] = {0x00,0x89,'P','N','G',0x0d,0x0a,0x1a,0x0a,'x'};
479 static BYTE data39[] = {0x4d,0x4d,0x00,0x2a};
480 static BYTE data40[] = {0x4d,0x4d,0x00,0x2a,'<','h','t','m','l','>',0};
481 static BYTE data41[] = {0x4d,0x4d,0xff};
482 static BYTE data42[] = {0x4d,0x4d};
483 static BYTE data43[] = {0x00,0x4d,0x4d,0x00};
484 static BYTE data44[] = {'R','I','F','F',0xff,0xff,0xff,0xff,'A','V','I',0x20,0xff};
485 static BYTE data45[] = {'R','I','F','f',0xff,0xff,0xff,0xff,'A','V','I',0x20,0xff};
486 static BYTE data46[] = {'R','I','F','F',0xff,0xff,0xff,0xff,'A','V','I',0x20};
487 static BYTE data47[] = {'R','I','F','F',0xff,0xff,0xff,0xff,'A','V','I',0x21,0xff};
488 static BYTE data48[] = {'R','I','F','F',0xff,0xff,0xff,0xff,'A','V','I',0x20,'<','h','t','m','l','>'};
489 static BYTE data49[] = {'R','I','F','F',0x0f,0x0f,0xf0,0xf0,'A','V','I',0x20,0xf0,0x00};
490 static BYTE data50[] = {0x00,0x00,0x01,0xb3,0xff};
491 static BYTE data51[] = {0x00,0x00,0x01,0xba,0xff};
492 static BYTE data52[] = {0x00,0x00,0x01,0xb8,0xff};
493 static BYTE data53[] = {0x00,0x00,0x01,0xba};
494 static BYTE data54[] = {0x00,0x00,0x01,0xba,'<','h','t','m','l','>'};
495 static BYTE data55[] = {0x1f,0x8b,'x'};
496 static BYTE data56[] = {0x1f};
497 static BYTE data57[] = {0x1f,0x8b,'<','h','t','m','l','>','t','e','s','t',0};
498 static BYTE data58[] = {0x1f,0x8b};
499 static BYTE data59[] = {0x50,0x4b,'x'};
500 static BYTE data60[] = {0x50,0x4b};
501 static BYTE data61[] = {0x50,0x4b,'<','h','t','m','l','>',0};
502 static BYTE data62[] = {0xca,0xfe,0xba,0xbe,'x'};
503 static BYTE data63[] = {0xca,0xfe,0xba,0xbe};
504 static BYTE data64[] = {0xca,0xfe,0xba,0xbe,'<','h','t','m','l','>',0};
505 static BYTE data65[] = {0x25,0x50,0x44,0x46,'x'};
506 static BYTE data66[] = {0x25,0x50,0x44,0x46};
507 static BYTE data67[] = {0x25,0x50,0x44,0x46,'x','<','h','t','m','l','>'};
508 static BYTE data68[] = {'M','Z','x'};
509 static BYTE data69[] = {'M','Z'};
510 static BYTE data70[] = {'M','Z','<','h','t','m','l','>',0xff};
511 static BYTE data71[] = {'{','\\','r','t','f',0};
512 static BYTE data72[] = {'{','\\','r','t','f'};
513 static BYTE data73[] = {' ','{','\\','r','t','f',' '};
514 static BYTE data74[] = {'{','\\','r','t','f','<','h','t','m','l','>',' '};
515 static BYTE data75[] = {'R','I','F','F',0xff,0xff,0xff,0xff,'W','A','V','E',0xff};
516 static BYTE data76[] = {'R','I','F','F',0xff,0xff,0xff,0xff,'W','A','V','E'};
517 static BYTE data77[] = {'R','I','F','F',0xff,0xff,0xff,0xff,'W','A','V',0xff,0xff};
518 static BYTE data78[] = {'R','I','F','F',0xff,0xff,0xff,0xff,'<','h','t','m','l','>',0xff};
519 static BYTE data79[] = {'%','!',0xff};
520 static BYTE data80[] = {'%','!'};
521 static BYTE data81[] = {'%','!','P','S','<','h','t','m','l','>'};
522 static BYTE data82[] = {'.','s','n','d',0};
523 static BYTE data83[] = {'.','s','n','d'};
524 static BYTE data84[] = {'.','s','n','d',0,'<','h','t','m','l','>',1,1};
525 static BYTE data85[] = {'.','S','N','D',0};
526
527 static const struct {
528     BYTE *data;
529     DWORD size;
530     LPCWSTR mime, mime_alt;
531 } mime_tests2[] = {
532     {data1, sizeof(data1), mimeTextPlain},
533     {data2, sizeof(data2), mimeAppOctetStream},
534     {data3, sizeof(data3), mimeAppOctetStream},
535     {data4, sizeof(data4), mimeAppOctetStream},
536     {data5, sizeof(data5), mimeTextPlain},
537     {data6, sizeof(data6), mimeTextPlain},
538     {data7, sizeof(data7), mimeTextHtml, mimeTextPlain /* IE8 */},
539     {data8, sizeof(data8), mimeTextHtml, mimeTextPlain /* IE8 */},
540     {data9, sizeof(data9), mimeTextHtml, mimeImagePjpeg /* IE8 */},
541     {data10, sizeof(data10), mimeTextHtml, mimeTextPlain /* IE8 */},
542     {data11, sizeof(data11), mimeTextHtml, mimeTextPlain /* IE8 */},
543     {data12, sizeof(data12), mimeTextHtml, mimeTextPlain /* IE8 */},
544     {data13, sizeof(data13), mimeTextPlain},
545     {data14, sizeof(data14), mimeTextPlain},
546     {data15, sizeof(data15), mimeTextPlain},
547     {data16, sizeof(data16), mimeImagePjpeg},
548     {data17, sizeof(data17), mimeAppOctetStream},
549     {data18, sizeof(data18), mimeTextHtml},
550     {data19, sizeof(data19), mimeImageGif},
551     {data20, sizeof(data20), mimeImageGif},
552     {data21, sizeof(data21), mimeTextPlain},
553     {data22, sizeof(data22), mimeImageGif},
554     {data23, sizeof(data23), mimeTextPlain},
555     {data24, sizeof(data24), mimeImageGif},
556     {data25, sizeof(data25), mimeImageGif},
557     {data26, sizeof(data26), mimeTextHtml, mimeImageGif /* IE8 */},
558     {data27, sizeof(data27), mimeTextPlain},
559     {data28, sizeof(data28), mimeImageBmp},
560     {data29, sizeof(data29), mimeImageBmp},
561     {data30, sizeof(data30), mimeAppOctetStream},
562     {data31, sizeof(data31), mimeTextHtml, mimeImageBmp /* IE8 */},
563     {data32, sizeof(data32), mimeAppOctetStream},
564     {data33, sizeof(data33), mimeAppOctetStream},
565     {data34, sizeof(data34), mimeImageXPng},
566     {data35, sizeof(data35), mimeImageXPng},
567     {data36, sizeof(data36), mimeAppOctetStream},
568     {data37, sizeof(data37), mimeTextHtml, mimeImageXPng /* IE8 */},
569     {data38, sizeof(data38), mimeAppOctetStream},
570     {data39, sizeof(data39), mimeImageTiff},
571     {data40, sizeof(data40), mimeTextHtml, mimeImageTiff /* IE8 */},
572     {data41, sizeof(data41), mimeImageTiff},
573     {data42, sizeof(data42), mimeTextPlain},
574     {data43, sizeof(data43), mimeAppOctetStream},
575     {data44, sizeof(data44), mimeVideoAvi},
576     {data45, sizeof(data45), mimeTextPlain},
577     {data46, sizeof(data46), mimeTextPlain},
578     {data47, sizeof(data47), mimeTextPlain},
579     {data48, sizeof(data48), mimeTextHtml, mimeVideoAvi /* IE8 */},
580     {data49, sizeof(data49), mimeVideoAvi},
581     {data50, sizeof(data50), mimeVideoMpeg},
582     {data51, sizeof(data51), mimeVideoMpeg},
583     {data52, sizeof(data52), mimeAppOctetStream},
584     {data53, sizeof(data53), mimeAppOctetStream},
585     {data54, sizeof(data54), mimeTextHtml, mimeVideoMpeg /* IE8 */},
586     {data55, sizeof(data55), mimeAppXGzip},
587     {data56, sizeof(data56), mimeTextPlain},
588     {data57, sizeof(data57), mimeTextHtml, mimeAppXGzip /* IE8 */},
589     {data58, sizeof(data58), mimeAppOctetStream},
590     {data59, sizeof(data59), mimeAppXZip},
591     {data60, sizeof(data60), mimeTextPlain},
592     {data61, sizeof(data61), mimeTextHtml, mimeAppXZip /* IE8 */},
593     {data62, sizeof(data62), mimeAppJava},
594     {data63, sizeof(data63), mimeTextPlain},
595     {data64, sizeof(data64), mimeTextHtml, mimeAppJava /* IE8 */},
596     {data65, sizeof(data65), mimeAppPdf},
597     {data66, sizeof(data66), mimeTextPlain},
598     {data67, sizeof(data67), mimeTextHtml, mimeAppPdf /* IE8 */},
599     {data68, sizeof(data68), mimeAppXMSDownload},
600     {data69, sizeof(data69), mimeTextPlain},
601     {data70, sizeof(data70), mimeTextHtml, mimeAppXMSDownload /* IE8 */},
602     {data71, sizeof(data71), mimeTextRichtext},
603     {data72, sizeof(data72), mimeTextPlain},
604     {data73, sizeof(data73), mimeTextPlain},
605     {data74, sizeof(data74), mimeTextHtml, mimeTextRichtext /* IE8 */},
606     {data75, sizeof(data75), mimeAudioWav},
607     {data76, sizeof(data76), mimeTextPlain},
608     {data77, sizeof(data77), mimeTextPlain},
609     {data78, sizeof(data78), mimeTextHtml, mimeTextPlain /* IE8 */},
610     {data79, sizeof(data79), mimeAppPostscript},
611     {data80, sizeof(data80), mimeTextPlain},
612     {data81, sizeof(data81), mimeTextHtml, mimeAppPostscript /* IE8 */},
613     {data82, sizeof(data82), mimeAudioBasic},
614     {data83, sizeof(data83), mimeTextPlain},
615     {data84, sizeof(data84), mimeTextHtml, mimeAudioBasic /* IE8 */},
616     {data85, sizeof(data85), mimeTextPlain}
617 };
618
619 static void test_FindMimeFromData(void)
620 {
621     HRESULT hres;
622     LPWSTR mime;
623     int i;
624
625     for(i=0; i<sizeof(mime_tests)/sizeof(mime_tests[0]); i++) {
626         mime = (LPWSTR)0xf0f0f0f0;
627         hres = FindMimeFromData(NULL, mime_tests[i].url, NULL, 0, NULL, 0, &mime, 0);
628         if(mime_tests[i].mime) {
629             ok(hres == S_OK, "[%d] FindMimeFromData failed: %08x\n", i, hres);
630             ok(!lstrcmpW(mime, mime_tests[i].mime), "[%d] wrong mime\n", i);
631             CoTaskMemFree(mime);
632         }else {
633             ok(hres == E_FAIL || hres == mime_tests[i].hres,
634                "[%d] FindMimeFromData failed: %08x, expected %08x\n",
635                i, hres, mime_tests[i].hres);
636             ok(mime == (LPWSTR)0xf0f0f0f0, "[%d] mime != 0xf0f0f0f0\n", i);
637         }
638
639         mime = (LPWSTR)0xf0f0f0f0;
640         hres = FindMimeFromData(NULL, mime_tests[i].url, NULL, 0, mimeTextPlain, 0, &mime, 0);
641         ok(hres == S_OK, "[%d] FindMimeFromData failed: %08x\n", i, hres);
642         ok(!lstrcmpW(mime, mimeTextPlain), "[%d] wrong mime\n", i);
643         CoTaskMemFree(mime);
644
645         mime = (LPWSTR)0xf0f0f0f0;
646         hres = FindMimeFromData(NULL, mime_tests[i].url, NULL, 0, mimeAppOctetStream, 0, &mime, 0);
647         ok(hres == S_OK, "[%d] FindMimeFromData failed: %08x\n", i, hres);
648         ok(!lstrcmpW(mime, mimeAppOctetStream), "[%d] wrong mime\n", i);
649         CoTaskMemFree(mime);
650     }
651
652     for(i=0; i < sizeof(mime_tests2)/sizeof(mime_tests2[0]); i++) {
653         hres = FindMimeFromData(NULL, NULL, mime_tests2[i].data, mime_tests2[i].size,
654                 NULL, 0, &mime, 0);
655         ok(hres == S_OK, "[%d] FindMimeFromData failed: %08x\n", i, hres);
656         ok(!lstrcmpW(mime, mime_tests2[i].mime), "[%d] wrong mime: %s\n", i, debugstr_w(mime));
657         CoTaskMemFree(mime);
658
659         hres = FindMimeFromData(NULL, NULL, mime_tests2[i].data, mime_tests2[i].size,
660                 mimeTextHtml, 0, &mime, 0);
661         ok(hres == S_OK, "[%d] FindMimeFromData failed: %08x\n", i, hres);
662         if(!lstrcmpW(mimeAppOctetStream, mime_tests2[i].mime)
663            || !lstrcmpW(mimeTextPlain, mime_tests2[i].mime))
664             ok(!lstrcmpW(mime, mimeTextHtml), "[%d] wrong mime\n", i);
665         else
666             ok(!lstrcmpW(mime, mime_tests2[i].mime), "[%d] wrong mime\n", i);
667         CoTaskMemFree(mime);
668
669         hres = FindMimeFromData(NULL, NULL, mime_tests2[i].data, mime_tests2[i].size,
670                 mimeImagePjpeg, 0, &mime, 0);
671         ok(hres == S_OK, "[%d] FindMimeFromData failed: %08x\n", i, hres);
672         if(!lstrcmpW(mimeAppOctetStream, mime_tests2[i].mime) || i == 17)
673             ok(!lstrcmpW(mime, mimeImagePjpeg), "[%d] wrong mime\n", i);
674         else
675             ok(!lstrcmpW(mime, mime_tests2[i].mime) ||
676                     (mime_tests2[i].mime_alt && !lstrcmpW(mime, mime_tests2[i].mime_alt)),
677                     "[%d] wrong mime, got '%s'\n", i, debugstr_w(mime));
678
679         CoTaskMemFree(mime);
680     }
681
682     hres = FindMimeFromData(NULL, url1, data1, sizeof(data1), NULL, 0, &mime, 0);
683     ok(hres == S_OK, "FindMimeFromData failed: %08x\n", hres);
684     ok(!lstrcmpW(mime, mimeTextPlain), "wrong mime\n");
685     CoTaskMemFree(mime);
686
687     hres = FindMimeFromData(NULL, url1, data1, sizeof(data1), mimeAppOctetStream, 0, &mime, 0);
688     ok(hres == S_OK, "FindMimeFromData failed: %08x\n", hres);
689     ok(!lstrcmpW(mime, mimeTextPlain), "wrong mime\n");
690     CoTaskMemFree(mime);
691
692     hres = FindMimeFromData(NULL, url4, data1, sizeof(data1), mimeAppOctetStream, 0, &mime, 0);
693     ok(hres == S_OK, "FindMimeFromData failed: %08x\n", hres);
694     ok(!lstrcmpW(mime, mimeTextPlain), "wrong mime\n");
695     CoTaskMemFree(mime);
696
697     hres = FindMimeFromData(NULL, NULL, NULL, 0, NULL, 0, &mime, 0);
698     ok(hres == E_INVALIDARG, "FindMimeFromData failed: %08x, excepted E_INVALIDARG\n", hres);
699
700     hres = FindMimeFromData(NULL, NULL, NULL, 0, mimeTextPlain, 0, &mime, 0);
701     ok(hres == E_INVALIDARG, "FindMimeFromData failed: %08x, expected E_INVALIDARG\n", hres);
702
703     hres = FindMimeFromData(NULL, NULL, data1, 0, NULL, 0, &mime, 0);
704     ok(hres == E_FAIL, "FindMimeFromData failed: %08x, expected E_FAIL\n", hres);
705
706     hres = FindMimeFromData(NULL, url1, data1, 0, NULL, 0, &mime, 0);
707     ok(hres == E_FAIL, "FindMimeFromData failed: %08x, expected E_FAIL\n", hres);
708
709     hres = FindMimeFromData(NULL, NULL, data1, 0, mimeTextPlain, 0, &mime, 0);
710     ok(hres == S_OK, "FindMimeFromData failed: %08x\n", hres);
711     ok(!lstrcmpW(mime, mimeTextPlain), "wrong mime\n");
712     CoTaskMemFree(mime);
713
714     hres = FindMimeFromData(NULL, NULL, data1, 0, mimeTextPlain, 0, NULL, 0);
715     ok(hres == E_INVALIDARG, "FindMimeFromData failed: %08x, expected E_INVALIDARG\n", hres);
716 }
717
718 static const BYTE secid1[] = {'f','i','l','e',':',0,0,0,0};
719 static const BYTE secid5[] = {'h','t','t','p',':','w','w','w','.','w','i','n','e','h','q',
720     '.','o','r','g',3,0,0,0};
721 static const BYTE secid6[] = {'a','b','o','u','t',':','b','l','a','n','k',3,0,0,0};
722 static const BYTE secid7[] = {'f','t','p',':','w','i','n','e','h','q','.','o','r','g',
723                               3,0,0,0};
724 static const BYTE secid10[] =
725     {'f','i','l','e',':','s','o','m','e','%','2','0','f','i','l','e','.','j','p','g',3,0,0,0};
726 static const BYTE secid10_2[] =
727     {'f','i','l','e',':','s','o','m','e',' ','f','i','l','e','.','j','p','g',3,0,0,0};
728
729 static struct secmgr_test {
730     LPCWSTR url;
731     DWORD zone;
732     HRESULT zone_hres;
733     DWORD secid_size;
734     const BYTE *secid;
735     HRESULT secid_hres;
736 } secmgr_tests[] = {
737     {url1, 0,   S_OK, sizeof(secid1), secid1, S_OK},
738     {url2, 100, 0x80041001, 0, NULL, E_INVALIDARG},
739     {url3, 0,   S_OK, sizeof(secid1), secid1, S_OK},
740     {url5, 3,   S_OK, sizeof(secid5), secid5, S_OK},
741     {url6, 3,   S_OK, sizeof(secid6), secid6, S_OK},
742     {url7, 3,   S_OK, sizeof(secid7), secid7, S_OK}
743 };
744
745 static void test_SecurityManager(void)
746 {
747     int i;
748     IInternetSecurityManager *secmgr = NULL;
749     BYTE buf[512];
750     DWORD zone, size, policy;
751     HRESULT hres;
752
753     hres = CoInternetCreateSecurityManager(NULL, &secmgr, 0);
754     ok(hres == S_OK, "CoInternetCreateSecurityManager failed: %08x\n", hres);
755     if(FAILED(hres))
756         return;
757
758     for(i=0; i < sizeof(secmgr_tests)/sizeof(secmgr_tests[0]); i++) {
759         zone = 100;
760         hres = IInternetSecurityManager_MapUrlToZone(secmgr, secmgr_tests[i].url,
761                                                      &zone, 0);
762         ok(hres == secmgr_tests[i].zone_hres /* IE <=6 */
763            || (FAILED(secmgr_tests[i].zone_hres) && hres == E_INVALIDARG), /* IE7 */
764            "[%d] MapUrlToZone failed: %08x, expected %08x\n",
765                 i, hres, secmgr_tests[i].zone_hres);
766         if(SUCCEEDED(hres))
767             ok(zone == secmgr_tests[i].zone, "[%d] zone=%d, expected %d\n", i, zone,
768                secmgr_tests[i].zone);
769         else
770             ok(zone == secmgr_tests[i].zone || zone == -1, "[%d] zone=%d\n", i, zone);
771
772         size = sizeof(buf);
773         memset(buf, 0xf0, sizeof(buf));
774         hres = IInternetSecurityManager_GetSecurityId(secmgr, secmgr_tests[i].url,
775                 buf, &size, 0);
776         ok(hres == secmgr_tests[i].secid_hres,
777            "[%d] GetSecurityId failed: %08x, expected %08x\n",
778            i, hres, secmgr_tests[i].secid_hres);
779         if(secmgr_tests[i].secid) {
780             ok(size == secmgr_tests[i].secid_size, "[%d] size=%d, expected %d\n",
781                     i, size, secmgr_tests[i].secid_size);
782             ok(!memcmp(buf, secmgr_tests[i].secid, size), "[%d] wrong secid\n", i);
783         }
784     }
785
786     zone = 100;
787     hres = IInternetSecurityManager_MapUrlToZone(secmgr, url10, &zone, 0);
788     ok(hres == S_OK, "MapUrlToZone failed: %08x, expected S_OK\n", hres);
789     ok(zone == 3, "zone=%d, expected 3\n", zone);
790
791     /* win2k3 translates %20 into a space */
792     size = sizeof(buf);
793     memset(buf, 0xf0, sizeof(buf));
794     hres = IInternetSecurityManager_GetSecurityId(secmgr, url10, buf, &size, 0);
795     ok(hres == S_OK, "GetSecurityId failed: %08x, expected S_OK\n", hres);
796     ok(size == sizeof(secid10) ||
797        size == sizeof(secid10_2), /* win2k3 */
798        "size=%d\n", size);
799     ok(!memcmp(buf, secid10, size) ||
800        !memcmp(buf, secid10_2, size), /* win2k3 */
801        "wrong secid\n");
802
803     zone = 100;
804     hres = IInternetSecurityManager_MapUrlToZone(secmgr, NULL, &zone, 0);
805     ok(hres == E_INVALIDARG, "MapUrlToZone failed: %08x, expected E_INVALIDARG\n", hres);
806     ok(zone == 100 || zone == -1, "zone=%d\n", zone);
807
808     size = sizeof(buf);
809     hres = IInternetSecurityManager_GetSecurityId(secmgr, NULL, buf, &size, 0);
810     ok(hres == E_INVALIDARG,
811        "GetSecurityId failed: %08x, expected E_INVALIDARG\n", hres);
812     hres = IInternetSecurityManager_GetSecurityId(secmgr, secmgr_tests[1].url,
813                                                   NULL, &size, 0);
814     ok(hres == E_INVALIDARG,
815        "GetSecurityId failed: %08x, expected E_INVALIDARG\n", hres);
816     hres = IInternetSecurityManager_GetSecurityId(secmgr, secmgr_tests[1].url,
817                                                   buf, NULL, 0);
818     ok(hres == E_INVALIDARG,
819        "GetSecurityId failed: %08x, expected E_INVALIDARG\n", hres);
820
821     hres = IInternetSecurityManager_ProcessUrlAction(secmgr, NULL, URLACTION_SCRIPT_RUN, (BYTE*)&policy,
822             sizeof(WCHAR), NULL, 0, 0, 0);
823     ok(hres == E_INVALIDARG, "ProcessUrlAction failed: %08x, expected E_INVALIDARG\n", hres);
824
825     IInternetSecurityManager_Release(secmgr);
826 }
827
828 /* Check if Internet Explorer is configured to run in "Enhanced Security Configuration" (aka hardened mode) */
829 /* Note: this code is duplicated in dlls/mshtml/tests/dom.c, dlls/mshtml/tests/script.c and dlls/urlmon/tests/misc.c */
830 static BOOL is_ie_hardened(void)
831 {
832     HKEY zone_map;
833     DWORD ie_harden, type, size;
834
835     ie_harden = 0;
836     if(RegOpenKeyEx(HKEY_CURRENT_USER, "Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings\\ZoneMap",
837                     0, KEY_QUERY_VALUE, &zone_map) == ERROR_SUCCESS) {
838         size = sizeof(DWORD);
839         if (RegQueryValueEx(zone_map, "IEHarden", NULL, &type, (LPBYTE) &ie_harden, &size) != ERROR_SUCCESS ||
840             type != REG_DWORD) {
841             ie_harden = 0;
842         }
843     RegCloseKey(zone_map);
844     }
845
846     return ie_harden != 0;
847 }
848
849 static void test_url_action(IInternetSecurityManager *secmgr, IInternetZoneManager *zonemgr, DWORD action)
850 {
851     DWORD res, size, policy, reg_policy;
852     char buf[10];
853     HKEY hkey;
854     HRESULT hres;
855
856     /* FIXME: HKEY_CURRENT_USER is most of the time the default but this can be changed on a system.
857      * The test should be changed to cope with that, if need be.
858      */
859     res = RegOpenKeyA(HKEY_CURRENT_USER,
860             "Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings\\Zones\\3", &hkey);
861     if(res != ERROR_SUCCESS) {
862         ok(0, "Could not open zone key\n");
863         return;
864     }
865
866     wsprintf(buf, "%X", action);
867     size = sizeof(DWORD);
868     res = RegQueryValueExA(hkey, buf, NULL, NULL, (BYTE*)&reg_policy, &size);
869     RegCloseKey(hkey);
870     if(res != ERROR_SUCCESS || size != sizeof(DWORD)) {
871         policy = 0xdeadbeef;
872         hres = IInternetSecurityManager_ProcessUrlAction(secmgr, url9, action, (BYTE*)&policy,
873                 sizeof(WCHAR), NULL, 0, 0, 0);
874         ok(hres == E_FAIL, "ProcessUrlAction(%x) failed: %08x, expected E_FAIL\n", action, hres);
875         ok(policy == 0xdeadbeef, "(%x) policy=%x\n", action, policy);
876
877         policy = 0xdeadbeef;
878         hres = IInternetZoneManager_GetZoneActionPolicy(zonemgr, 3, action, (BYTE*)&policy,
879                 sizeof(DWORD), URLZONEREG_DEFAULT);
880         ok(hres == E_FAIL, "GetZoneActionPolicy failed: %08x, expected E_FAIL\n", hres);
881         ok(policy == 0xdeadbeef, "(%x) policy=%x\n", action, policy);
882         return;
883     }
884
885     policy = 0xdeadbeef;
886     hres = IInternetZoneManager_GetZoneActionPolicy(zonemgr, 3, action, (BYTE*)&policy,
887             sizeof(DWORD), URLZONEREG_DEFAULT);
888     ok(hres == S_OK, "GetZoneActionPolicy failed: %08x\n", hres);
889     ok(policy == reg_policy, "(%x) policy=%x, expected %x\n", action, policy, reg_policy);
890
891     if(policy != URLPOLICY_QUERY) {
892         if(winetest_interactive || ! is_ie_hardened()) {
893             policy = 0xdeadbeef;
894             hres = IInternetSecurityManager_ProcessUrlAction(secmgr, url9, action, (BYTE*)&policy,
895                     sizeof(WCHAR), NULL, 0, 0, 0);
896             if(reg_policy == URLPOLICY_DISALLOW)
897                 ok(hres == S_FALSE, "ProcessUrlAction(%x) failed: %08x, expected S_FALSE\n", action, hres);
898             else
899                 ok(hres == S_OK, "ProcessUrlAction(%x) failed: %08x\n", action, hres);
900             ok(policy == 0xdeadbeef, "(%x) policy=%x\n", action, policy);
901         }else {
902             skip("IE running in Enhanced Security Configuration\n");
903         }
904         }
905 }
906
907 static void test_special_url_action(IInternetSecurityManager *secmgr, IInternetZoneManager *zonemgr, DWORD action)
908 {
909     DWORD policy;
910     HRESULT hres;
911
912     policy = 0xdeadbeef;
913     hres = IInternetZoneManager_GetZoneActionPolicy(zonemgr, 3, action, (BYTE*)&policy,
914             sizeof(DWORD), URLZONEREG_DEFAULT);
915     ok(hres == S_OK, "GetZoneActionPolicy failed: %08x\n", hres);
916     ok(policy == URLPOLICY_DISALLOW, "(%x) policy=%x, expected URLPOLIVY_DISALLOW\n", action, policy);
917
918     policy = 0xdeadbeef;
919     hres = IInternetSecurityManager_ProcessUrlAction(secmgr, url1, action, (BYTE*)&policy,
920             sizeof(WCHAR), NULL, 0, 0, 0);
921     ok(hres == S_FALSE, "ProcessUrlAction(%x) failed: %08x, expected S_FALSE\n", action, hres);
922 }
923
924 static void test_polices(void)
925 {
926     IInternetZoneManager *zonemgr = NULL;
927     IInternetSecurityManager *secmgr = NULL;
928     HRESULT hres;
929
930     hres = CoInternetCreateSecurityManager(NULL, &secmgr, 0);
931     ok(hres == S_OK, "CoInternetCreateSecurityManager failed: %08x\n", hres);
932     hres = CoInternetCreateZoneManager(NULL, &zonemgr, 0);
933     ok(hres == S_OK, "CoInternetCreateZoneManager failed: %08x\n", hres);
934
935     test_url_action(secmgr, zonemgr, URLACTION_SCRIPT_RUN);
936     test_url_action(secmgr, zonemgr, URLACTION_ACTIVEX_OVERRIDE_OBJECT_SAFETY);
937     test_url_action(secmgr, zonemgr, URLACTION_CHANNEL_SOFTDIST_PERMISSIONS);
938     test_url_action(secmgr, zonemgr, 0xdeadbeef);
939
940     test_special_url_action(secmgr, zonemgr, URLACTION_SCRIPT_OVERRIDE_SAFETY);
941
942     IInternetSecurityManager_Release(secmgr);
943     IInternetZoneManager_Release(zonemgr);
944 }
945
946 static void test_ZoneManager(void)
947 {
948     IInternetZoneManager *zonemgr = NULL;
949     BYTE buf[32];
950     HRESULT hres;
951     DWORD action = URLACTION_CREDENTIALS_USE; /* Implemented on all IE versions */
952
953     hres = CoInternetCreateZoneManager(NULL, &zonemgr, 0);
954     ok(hres == S_OK, "CoInternetCreateZoneManager failed: %08x\n", hres);
955     if(FAILED(hres))
956         return;
957
958     hres = IInternetZoneManager_GetZoneActionPolicy(zonemgr, 3, action, buf,
959             sizeof(DWORD), URLZONEREG_DEFAULT);
960     ok(hres == S_OK, "GetZoneActionPolicy failed: %08x\n", hres);
961     ok(*(DWORD*)buf == URLPOLICY_CREDENTIALS_SILENT_LOGON_OK ||
962             *(DWORD*)buf == URLPOLICY_CREDENTIALS_MUST_PROMPT_USER ||
963             *(DWORD*)buf == URLPOLICY_CREDENTIALS_CONDITIONAL_PROMPT ||
964             *(DWORD*)buf == URLPOLICY_CREDENTIALS_ANONYMOUS_ONLY,
965             "unexpected policy=%d\n", *(DWORD*)buf);
966
967     hres = IInternetZoneManager_GetZoneActionPolicy(zonemgr, 3, action, NULL,
968             sizeof(DWORD), URLZONEREG_DEFAULT);
969     ok(hres == E_INVALIDARG, "GetZoneActionPolicy failed: %08x, expected E_INVALIDARG\n", hres);
970
971     hres = IInternetZoneManager_GetZoneActionPolicy(zonemgr, 3, action, buf,
972             2, URLZONEREG_DEFAULT);
973     ok(hres == E_INVALIDARG, "GetZoneActionPolicy failed: %08x, expected E_INVALIDARG\n", hres);
974
975     hres = IInternetZoneManager_GetZoneActionPolicy(zonemgr, 3, 0x1fff, buf,
976             sizeof(DWORD), URLZONEREG_DEFAULT);
977     ok(hres == E_FAIL, "GetZoneActionPolicy failed: %08x, expected E_FAIL\n", hres);
978
979     hres = IInternetZoneManager_GetZoneActionPolicy(zonemgr, 13, action, buf,
980             sizeof(DWORD), URLZONEREG_DEFAULT);
981     ok(hres == E_INVALIDARG, "GetZoneActionPolicy failed: %08x, expected E_INVALIDARG\n", hres);
982
983     IInternetZoneManager_Release(zonemgr);
984 }
985
986 static void register_protocols(void)
987 {
988     IInternetSession *session;
989     IClassFactory *factory;
990     HRESULT hres;
991
992     static const WCHAR wszAbout[] = {'a','b','o','u','t',0};
993
994     hres = CoInternetGetSession(0, &session, 0);
995     ok(hres == S_OK, "CoInternetGetSession failed: %08x\n", hres);
996     if(FAILED(hres))
997         return;
998
999     hres = CoGetClassObject(&CLSID_AboutProtocol, CLSCTX_INPROC_SERVER, NULL,
1000             &IID_IClassFactory, (void**)&factory);
1001     ok(hres == S_OK, "Coud not get AboutProtocol factory: %08x\n", hres);
1002     if(FAILED(hres))
1003         return;
1004
1005     IInternetSession_RegisterNameSpace(session, factory, &CLSID_AboutProtocol,
1006                                        wszAbout, 0, NULL, 0);
1007     IClassFactory_Release(factory);
1008
1009     IInternetSession_Release(session);
1010 }
1011
1012 static HRESULT WINAPI InternetProtocolInfo_QueryInterface(IInternetProtocolInfo *iface,
1013                                                           REFIID riid, void **ppv)
1014 {
1015     ok(0, "unexpected call\n");
1016     return E_NOINTERFACE;
1017 }
1018
1019 static ULONG WINAPI InternetProtocolInfo_AddRef(IInternetProtocolInfo *iface)
1020 {
1021     return 2;
1022 }
1023
1024 static ULONG WINAPI InternetProtocolInfo_Release(IInternetProtocolInfo *iface)
1025 {
1026     return 1;
1027 }
1028
1029 static HRESULT WINAPI InternetProtocolInfo_ParseUrl(IInternetProtocolInfo *iface, LPCWSTR pwzUrl,
1030         PARSEACTION ParseAction, DWORD dwParseFlags, LPWSTR pwzResult, DWORD cchResult,
1031         DWORD *pcchResult, DWORD dwReserved)
1032 {
1033     CHECK_EXPECT(ParseUrl);
1034     return E_NOTIMPL;
1035 }
1036
1037 static HRESULT WINAPI InternetProtocolInfo_CombineUrl(IInternetProtocolInfo *iface,
1038         LPCWSTR pwzBaseUrl, LPCWSTR pwzRelativeUrl, DWORD dwCombineFlags,
1039         LPWSTR pwzResult, DWORD cchResult, DWORD *pcchResult, DWORD dwReserved)
1040 {
1041     ok(0, "unexpected call\n");
1042     return E_NOTIMPL;
1043 }
1044
1045 static HRESULT WINAPI InternetProtocolInfo_CompareUrl(IInternetProtocolInfo *iface,
1046         LPCWSTR pwzUrl1, LPCWSTR pwzUrl2, DWORD dwCompareFlags)
1047 {
1048     ok(0, "unexpected call\n");
1049     return E_NOTIMPL;
1050 }
1051
1052 static HRESULT WINAPI InternetProtocolInfo_QueryInfo(IInternetProtocolInfo *iface,
1053         LPCWSTR pwzUrl, QUERYOPTION OueryOption, DWORD dwQueryFlags, LPVOID pBuffer,
1054         DWORD cbBuffer, DWORD *pcbBuf, DWORD dwReserved)
1055 {
1056     ok(0, "unexpected call\n");
1057     return E_NOTIMPL;
1058 }
1059
1060 static const IInternetProtocolInfoVtbl InternetProtocolInfoVtbl = {
1061     InternetProtocolInfo_QueryInterface,
1062     InternetProtocolInfo_AddRef,
1063     InternetProtocolInfo_Release,
1064     InternetProtocolInfo_ParseUrl,
1065     InternetProtocolInfo_CombineUrl,
1066     InternetProtocolInfo_CompareUrl,
1067     InternetProtocolInfo_QueryInfo
1068 };
1069
1070 static IInternetProtocolInfo protocol_info = { &InternetProtocolInfoVtbl };
1071
1072 static HRESULT qiret;
1073 static IClassFactory *expect_cf;
1074
1075 static HRESULT WINAPI ClassFactory_QueryInterface(IClassFactory *iface, REFIID riid, void **ppv)
1076 {
1077     if(IsEqualGUID(&IID_IInternetProtocolInfo, riid)) {
1078         CHECK_EXPECT(QI_IInternetProtocolInfo);
1079         ok(iface == expect_cf, "unexpected iface\n");
1080         *ppv = &protocol_info;
1081         return qiret;
1082     }
1083
1084     ok(0, "unexpected call\n");
1085     return E_NOINTERFACE;
1086 }
1087
1088 static ULONG WINAPI ClassFactory_AddRef(IClassFactory *iface)
1089 {
1090     return 2;
1091 }
1092
1093 static ULONG WINAPI ClassFactory_Release(IClassFactory *iface)
1094 {
1095     return 1;
1096 }
1097
1098 static HRESULT WINAPI ClassFactory_CreateInstance(IClassFactory *iface, IUnknown *pOuter,
1099                                         REFIID riid, void **ppv)
1100 {
1101     ok(0, "unexpected call\n");
1102     return E_NOTIMPL;
1103 }
1104
1105 static HRESULT WINAPI ProtocolCF_CreateInstance(IClassFactory *iface, IUnknown *pOuter,
1106                                         REFIID riid, void **ppv)
1107 {
1108     CHECK_EXPECT(CreateInstance);
1109
1110     ok(iface == expect_cf, "unexpected iface\n");
1111     ok(pOuter == NULL, "pOuter = %p\n", pOuter);
1112     ok(IsEqualGUID(&IID_IInternetProtocolInfo, riid), "unexpected riid\n");
1113     ok(ppv != NULL, "ppv == NULL\n");
1114
1115     *ppv = &protocol_info;
1116     return S_OK;
1117 }
1118
1119 static HRESULT WINAPI ClassFactory_LockServer(IClassFactory *iface, BOOL dolock)
1120 {
1121     ok(0, "unexpected call\n");
1122     return S_OK;
1123 }
1124
1125 static const IClassFactoryVtbl ClassFactoryVtbl = {
1126     ClassFactory_QueryInterface,
1127     ClassFactory_AddRef,
1128     ClassFactory_Release,
1129     ClassFactory_CreateInstance,
1130     ClassFactory_LockServer
1131 };
1132
1133 static const IClassFactoryVtbl ProtocolCFVtbl = {
1134     ClassFactory_QueryInterface,
1135     ClassFactory_AddRef,
1136     ClassFactory_Release,
1137     ProtocolCF_CreateInstance,
1138     ClassFactory_LockServer
1139 };
1140
1141 static IClassFactory test_protocol_cf = { &ProtocolCFVtbl };
1142 static IClassFactory test_protocol_cf2 = { &ProtocolCFVtbl };
1143 static IClassFactory test_cf = { &ClassFactoryVtbl };
1144
1145 static void test_NameSpace(void)
1146 {
1147     IInternetSession *session;
1148     WCHAR buf[200];
1149     DWORD size;
1150     HRESULT hres;
1151
1152     static const WCHAR wszTest[] = {'t','e','s','t',0};
1153
1154     hres = CoInternetGetSession(0, &session, 0);
1155     ok(hres == S_OK, "CoInternetGetSession failed: %08x\n", hres);
1156     if(FAILED(hres))
1157         return;
1158
1159     hres = IInternetSession_RegisterNameSpace(session, NULL, &IID_NULL,
1160                                               wszTest, 0, NULL, 0);
1161     ok(hres == E_INVALIDARG, "RegisterNameSpace failed: %08x\n", hres);
1162
1163     hres = IInternetSession_RegisterNameSpace(session, &test_protocol_cf, &IID_NULL,
1164                                               NULL, 0, NULL, 0);
1165     ok(hres == E_INVALIDARG, "RegisterNameSpace failed: %08x\n", hres);
1166
1167     hres = IInternetSession_RegisterNameSpace(session, &test_protocol_cf, &IID_NULL,
1168                                               wszTest, 0, NULL, 0);
1169     ok(hres == S_OK, "RegisterNameSpace failed: %08x\n", hres);
1170
1171     qiret = E_NOINTERFACE;
1172     expect_cf = &test_protocol_cf;
1173     SET_EXPECT(QI_IInternetProtocolInfo);
1174     SET_EXPECT(CreateInstance);
1175     SET_EXPECT(ParseUrl);
1176
1177     hres = CoInternetParseUrl(url8, PARSE_ENCODE, 0, buf, sizeof(buf)/sizeof(WCHAR),
1178                               &size, 0);
1179     ok(hres == S_OK, "CoInternetParseUrl failed: %08x\n", hres);
1180
1181     CHECK_CALLED(QI_IInternetProtocolInfo);
1182     CHECK_CALLED(CreateInstance);
1183     CHECK_CALLED(ParseUrl);
1184
1185     qiret = S_OK;
1186     SET_EXPECT(QI_IInternetProtocolInfo);
1187     SET_EXPECT(ParseUrl);
1188
1189     hres = CoInternetParseUrl(url8, PARSE_ENCODE, 0, buf, sizeof(buf)/sizeof(WCHAR),
1190                               &size, 0);
1191     ok(hres == S_OK, "CoInternetParseUrl failed: %08x\n", hres);
1192
1193     CHECK_CALLED(QI_IInternetProtocolInfo);
1194     CHECK_CALLED(ParseUrl);
1195
1196     hres = IInternetSession_UnregisterNameSpace(session, &test_protocol_cf, wszTest);
1197     ok(hres == S_OK, "UnregisterNameSpace failed: %08x\n", hres);
1198
1199     hres = CoInternetParseUrl(url8, PARSE_ENCODE, 0, buf, sizeof(buf)/sizeof(WCHAR),
1200                               &size, 0);
1201     ok(hres == S_OK, "CoInternetParseUrl failed: %08x\n", hres);
1202
1203     hres = IInternetSession_RegisterNameSpace(session, &test_protocol_cf2, &IID_NULL,
1204                                               wszTest, 0, NULL, 0);
1205     ok(hres == S_OK, "RegisterNameSpace failed: %08x\n", hres);
1206
1207     hres = IInternetSession_RegisterNameSpace(session, &test_protocol_cf, &IID_NULL,
1208                                               wszTest, 0, NULL, 0);
1209     ok(hres == S_OK, "RegisterNameSpace failed: %08x\n", hres);
1210
1211     hres = IInternetSession_RegisterNameSpace(session, &test_protocol_cf, &IID_NULL,
1212                                               wszTest, 0, NULL, 0);
1213     ok(hres == S_OK, "RegisterNameSpace failed: %08x\n", hres);
1214
1215     SET_EXPECT(QI_IInternetProtocolInfo);
1216     SET_EXPECT(ParseUrl);
1217
1218     hres = CoInternetParseUrl(url8, PARSE_ENCODE, 0, buf, sizeof(buf)/sizeof(WCHAR),
1219                               &size, 0);
1220     ok(hres == S_OK, "CoInternetParseUrl failed: %08x\n", hres);
1221
1222     CHECK_CALLED(QI_IInternetProtocolInfo);
1223     CHECK_CALLED(ParseUrl);
1224
1225     hres = IInternetSession_UnregisterNameSpace(session, &test_protocol_cf, wszTest);
1226     ok(hres == S_OK, "UnregisterNameSpace failed: %08x\n", hres);
1227
1228     SET_EXPECT(QI_IInternetProtocolInfo);
1229     SET_EXPECT(ParseUrl);
1230
1231     hres = CoInternetParseUrl(url8, PARSE_ENCODE, 0, buf, sizeof(buf)/sizeof(WCHAR),
1232                               &size, 0);
1233     ok(hres == S_OK, "CoInternetParseUrl failed: %08x\n", hres);
1234
1235     CHECK_CALLED(QI_IInternetProtocolInfo);
1236     CHECK_CALLED(ParseUrl);
1237
1238     hres = IInternetSession_UnregisterNameSpace(session, &test_protocol_cf, wszTest);
1239     ok(hres == S_OK, "UnregisterNameSpace failed: %08x\n", hres);
1240
1241     expect_cf = &test_protocol_cf2;
1242     SET_EXPECT(QI_IInternetProtocolInfo);
1243     SET_EXPECT(ParseUrl);
1244
1245     hres = CoInternetParseUrl(url8, PARSE_ENCODE, 0, buf, sizeof(buf)/sizeof(WCHAR),
1246                               &size, 0);
1247     ok(hres == S_OK, "CoInternetParseUrl failed: %08x\n", hres);
1248
1249     CHECK_CALLED(QI_IInternetProtocolInfo);
1250     CHECK_CALLED(ParseUrl);
1251
1252     hres = IInternetSession_UnregisterNameSpace(session, &test_protocol_cf, wszTest);
1253     ok(hres == S_OK, "UnregisterNameSpace failed: %08x\n", hres);
1254     hres = IInternetSession_UnregisterNameSpace(session, &test_protocol_cf, wszTest);
1255     ok(hres == S_OK, "UnregisterNameSpace failed: %08x\n", hres);
1256     hres = IInternetSession_UnregisterNameSpace(session, &test_protocol_cf, NULL);
1257     ok(hres == E_INVALIDARG, "UnregisterNameSpace failed: %08x\n", hres);
1258     hres = IInternetSession_UnregisterNameSpace(session, NULL, wszTest);
1259     ok(hres == E_INVALIDARG, "UnregisterNameSpace failed: %08x\n", hres);
1260
1261     hres = IInternetSession_UnregisterNameSpace(session, &test_protocol_cf2, wszTest);
1262     ok(hres == S_OK, "UnregisterNameSpace failed: %08x\n", hres);
1263
1264     hres = CoInternetParseUrl(url8, PARSE_ENCODE, 0, buf, sizeof(buf)/sizeof(WCHAR),
1265                               &size, 0);
1266     ok(hres == S_OK, "CoInternetParseUrl failed: %08x\n", hres);
1267
1268     IInternetSession_Release(session);
1269 }
1270
1271 static void test_MimeFilter(void)
1272 {
1273     IInternetSession *session;
1274     HRESULT hres;
1275
1276     static const WCHAR mimeW[] = {'t','e','s','t','/','m','i','m','e',0};
1277
1278     hres = CoInternetGetSession(0, &session, 0);
1279     ok(hres == S_OK, "CoInternetGetSession failed: %08x\n", hres);
1280     if(FAILED(hres))
1281         return;
1282
1283     hres = IInternetSession_RegisterMimeFilter(session, &test_cf, &IID_NULL, mimeW);
1284     ok(hres == S_OK, "RegisterMimeFilter failed: %08x\n", hres);
1285
1286     hres = IInternetSession_UnregisterMimeFilter(session, &test_cf, mimeW);
1287     ok(hres == S_OK, "UnregisterMimeFilter failed: %08x\n", hres);
1288
1289     hres = IInternetSession_UnregisterMimeFilter(session, &test_cf, mimeW);
1290     ok(hres == S_OK, "UnregisterMimeFilter failed: %08x\n", hres);
1291
1292     hres = IInternetSession_UnregisterMimeFilter(session, (void*)0xdeadbeef, mimeW);
1293     ok(hres == S_OK, "UnregisterMimeFilter failed: %08x\n", hres);
1294
1295     IInternetSession_Release(session);
1296 }
1297
1298 static ULONG WINAPI unk_Release(IUnknown *iface)
1299 {
1300     CHECK_EXPECT(unk_Release);
1301     return 0;
1302 }
1303
1304 static const IUnknownVtbl unk_vtbl = {
1305     (void*)0xdeadbeef,
1306     (void*)0xdeadbeef,
1307     unk_Release
1308 };
1309
1310 static void test_ReleaseBindInfo(void)
1311 {
1312     BINDINFO bi;
1313     IUnknown unk = { &unk_vtbl };
1314
1315     ReleaseBindInfo(NULL); /* shouldn't crash */
1316
1317     memset(&bi, 0, sizeof(bi));
1318     bi.cbSize = sizeof(BINDINFO);
1319     bi.pUnk = &unk;
1320     SET_EXPECT(unk_Release);
1321     ReleaseBindInfo(&bi);
1322     ok(bi.cbSize == sizeof(BINDINFO), "bi.cbSize=%d\n", bi.cbSize);
1323     ok(bi.pUnk == NULL, "bi.pUnk=%p, expected NULL\n", bi.pUnk);
1324     CHECK_CALLED(unk_Release);
1325
1326     memset(&bi, 0, sizeof(bi));
1327     bi.cbSize = offsetof(BINDINFO, pUnk);
1328     bi.pUnk = &unk;
1329     ReleaseBindInfo(&bi);
1330     ok(bi.cbSize == offsetof(BINDINFO, pUnk), "bi.cbSize=%d\n", bi.cbSize);
1331     ok(bi.pUnk == &unk, "bi.pUnk=%p, expected %p\n", bi.pUnk, &unk);
1332
1333     memset(&bi, 0, sizeof(bi));
1334     bi.pUnk = &unk;
1335     ReleaseBindInfo(&bi);
1336     ok(!bi.cbSize, "bi.cbSize=%d, expected 0\n", bi.cbSize);
1337     ok(bi.pUnk == &unk, "bi.pUnk=%p, expected %p\n", bi.pUnk, &unk);
1338 }
1339
1340 static void test_CopyStgMedium(void)
1341 {
1342     STGMEDIUM src, dst;
1343     HGLOBAL empty;
1344     HRESULT hres;
1345
1346     static WCHAR fileW[] = {'f','i','l','e',0};
1347
1348     memset(&src, 0xf0, sizeof(src));
1349     memset(&dst, 0xe0, sizeof(dst));
1350     memset(&empty, 0xf0, sizeof(empty));
1351     src.tymed = TYMED_NULL;
1352     src.pUnkForRelease = NULL;
1353     hres = CopyStgMedium(&src, &dst);
1354     ok(hres == S_OK, "CopyStgMedium failed: %08x\n", hres);
1355     ok(dst.tymed == TYMED_NULL, "tymed=%d\n", dst.tymed);
1356     ok(dst.u.hGlobal == empty, "u=%p\n", dst.u.hGlobal);
1357     ok(!dst.pUnkForRelease, "pUnkForRelease=%p, expected NULL\n", dst.pUnkForRelease);
1358
1359     memset(&dst, 0xe0, sizeof(dst));
1360     src.tymed = TYMED_ISTREAM;
1361     src.u.pstm = NULL;
1362     src.pUnkForRelease = NULL;
1363     hres = CopyStgMedium(&src, &dst);
1364     ok(hres == S_OK, "CopyStgMedium failed: %08x\n", hres);
1365     ok(dst.tymed == TYMED_ISTREAM, "tymed=%d\n", dst.tymed);
1366     ok(!dst.u.pstm, "pstm=%p\n", dst.u.pstm);
1367     ok(!dst.pUnkForRelease, "pUnkForRelease=%p, expected NULL\n", dst.pUnkForRelease);
1368
1369     memset(&dst, 0xe0, sizeof(dst));
1370     src.tymed = TYMED_FILE;
1371     src.u.lpszFileName = fileW;
1372     src.pUnkForRelease = NULL;
1373     hres = CopyStgMedium(&src, &dst);
1374     ok(hres == S_OK, "CopyStgMedium failed: %08x\n", hres);
1375     ok(dst.tymed == TYMED_FILE, "tymed=%d\n", dst.tymed);
1376     ok(dst.u.lpszFileName && dst.u.lpszFileName != fileW, "lpszFileName=%p\n", dst.u.lpszFileName);
1377     ok(!lstrcmpW(dst.u.lpszFileName, fileW), "wrong file name\n");
1378     ok(!dst.pUnkForRelease, "pUnkForRelease=%p, expected NULL\n", dst.pUnkForRelease);
1379
1380     hres = CopyStgMedium(&src, NULL);
1381     ok(hres == E_POINTER, "CopyStgMedium failed: %08x, expected E_POINTER\n", hres);
1382     hres = CopyStgMedium(NULL, &dst);
1383     ok(hres == E_POINTER, "CopyStgMedium failed: %08x, expected E_POINTER\n", hres);
1384 }
1385
1386 static void test_UrlMkGetSessionOption(void)
1387 {
1388     DWORD encoding, size;
1389     HRESULT hres;
1390
1391     size = encoding = 0xdeadbeef;
1392     hres = UrlMkGetSessionOption(URLMON_OPTION_URL_ENCODING, &encoding,
1393                                  sizeof(encoding), &size, 0);
1394     ok(hres == S_OK, "UrlMkGetSessionOption failed: %08x\n", hres);
1395     ok(encoding != 0xdeadbeef, "encoding not changed\n");
1396     ok(size == sizeof(encoding), "size=%d\n", size);
1397
1398     size = encoding = 0xdeadbeef;
1399     hres = UrlMkGetSessionOption(URLMON_OPTION_URL_ENCODING, &encoding,
1400                                  sizeof(encoding)+1, &size, 0);
1401     ok(hres == S_OK, "UrlMkGetSessionOption failed: %08x\n", hres);
1402     ok(encoding != 0xdeadbeef, "encoding not changed\n");
1403     ok(size == sizeof(encoding), "size=%d\n", size);
1404
1405     size = encoding = 0xdeadbeef;
1406     hres = UrlMkGetSessionOption(URLMON_OPTION_URL_ENCODING, &encoding,
1407                                  sizeof(encoding)-1, &size, 0);
1408     ok(hres == E_INVALIDARG, "UrlMkGetSessionOption failed: %08x\n", hres);
1409     ok(encoding == 0xdeadbeef, "encoding = %08x, exepcted 0xdeadbeef\n", encoding);
1410     ok(size == 0xdeadbeef, "size=%d\n", size);
1411
1412     size = encoding = 0xdeadbeef;
1413     hres = UrlMkGetSessionOption(URLMON_OPTION_URL_ENCODING, NULL,
1414                                  sizeof(encoding)-1, &size, 0);
1415     ok(hres == E_INVALIDARG, "UrlMkGetSessionOption failed: %08x\n", hres);
1416     ok(encoding == 0xdeadbeef, "encoding = %08x, exepcted 0xdeadbeef\n", encoding);
1417     ok(size == 0xdeadbeef, "size=%d\n", size);
1418
1419     encoding = 0xdeadbeef;
1420     hres = UrlMkGetSessionOption(URLMON_OPTION_URL_ENCODING, &encoding,
1421                                  sizeof(encoding)-1, NULL, 0);
1422     ok(hres == E_INVALIDARG, "UrlMkGetSessionOption failed: %08x\n", hres);
1423     ok(encoding == 0xdeadbeef, "encoding = %08x, exepcted 0xdeadbeef\n", encoding);
1424 }
1425
1426 static void test_ObtainUserAgentString(void)
1427 {
1428     static const CHAR expected[] = "Mozilla/4.0 (compatible; MSIE ";
1429     static CHAR str[3];
1430     LPSTR str2 = NULL;
1431     HRESULT hres;
1432     DWORD size, saved;
1433
1434     hres = ObtainUserAgentString(0, NULL, NULL);
1435     ok(hres == E_INVALIDARG, "ObtainUserAgentString failed: %08x\n", hres);
1436
1437     size = 100;
1438     hres = ObtainUserAgentString(0, NULL, &size);
1439     ok(hres == E_INVALIDARG, "ObtainUserAgentString failed: %08x\n", hres);
1440     ok(size == 100, "size=%d, expected %d\n", size, 100);
1441
1442     size = 0;
1443     hres = ObtainUserAgentString(0, str, &size);
1444     ok(hres == E_OUTOFMEMORY, "ObtainUserAgentString failed: %08x\n", hres);
1445     ok(size > 0, "size=%d, expected non-zero\n", size);
1446
1447     size = 2;
1448     str[0] = 'a';
1449     hres = ObtainUserAgentString(0, str, &size);
1450     ok(hres == E_OUTOFMEMORY, "ObtainUserAgentString failed: %08x\n", hres);
1451     ok(size > 0, "size=%d, expected non-zero\n", size);
1452     ok(str[0] == 'a', "str[0]=%c, expected 'a'\n", str[0]);
1453
1454     size = 0;
1455     hres = ObtainUserAgentString(1, str, &size);
1456     ok(hres == E_OUTOFMEMORY, "ObtainUserAgentString failed: %08x\n", hres);
1457     ok(size > 0, "size=%d, expected non-zero\n", size);
1458
1459     str2 = HeapAlloc(GetProcessHeap(), 0, (size+20)*sizeof(CHAR));
1460     if (!str2)
1461     {
1462         skip("skipping rest of ObtainUserAgent tests, out of memory\n");
1463     }
1464     else
1465     {
1466         saved = size;
1467         hres = ObtainUserAgentString(0, str2, &size);
1468         ok(hres == S_OK, "ObtainUserAgentString failed: %08x\n", hres);
1469         ok(size == saved, "size=%d, expected %d\n", size, saved);
1470         ok(strlen(expected) <= strlen(str2) &&
1471            !memcmp(expected, str2, strlen(expected)*sizeof(CHAR)),
1472            "user agent was \"%s\", expected to start with \"%s\"\n",
1473            str2, expected);
1474
1475         size = saved+10;
1476         hres = ObtainUserAgentString(0, str2, &size);
1477         ok(hres == S_OK, "ObtainUserAgentString failed: %08x\n", hres);
1478         ok(size == saved, "size=%d, expected %d\n", size, saved);
1479     }
1480     HeapFree(GetProcessHeap(), 0, str2);
1481 }
1482
1483 static void test_MkParseDisplayNameEx(void)
1484 {
1485     IMoniker *mon = NULL;
1486     LPWSTR name;
1487     DWORD issys;
1488     ULONG eaten = 0;
1489     IBindCtx *bctx;
1490     HRESULT hres;
1491
1492     static const WCHAR clsid_nameW[] = {'c','l','s','i','d',':',
1493             '2','0','D','0','4','F','E','0','-','3','A','E','A','-','1','0','6','9','-','A','2','D','8',
1494             '-','0','8','0','0','2','B','3','0','3','0','9','D',':',0};
1495
1496     CreateBindCtx(0, &bctx);
1497
1498     hres = MkParseDisplayNameEx(bctx, url9, &eaten, &mon);
1499     ok(hres == S_OK, "MkParseDisplayNameEx failed: %08x\n", hres);
1500     ok(eaten == sizeof(url9)/sizeof(WCHAR)-1, "eaten=%d\n", eaten);
1501     ok(mon != NULL, "mon == NULL\n");
1502
1503     hres = IMoniker_GetDisplayName(mon, NULL, 0, &name);
1504     ok(hres == S_OK, "GetDiasplayName failed: %08x\n", hres);
1505     ok(!lstrcmpW(name, url9), "wrong display name %s\n", debugstr_w(name));
1506     CoTaskMemFree(name);
1507
1508     hres = IMoniker_IsSystemMoniker(mon, &issys);
1509     ok(hres == S_OK, "IsSystemMoniker failed: %08x\n", hres);
1510     ok(issys == MKSYS_URLMONIKER, "issys=%x\n", issys);
1511
1512     IMoniker_Release(mon);
1513
1514     hres = MkParseDisplayNameEx(bctx, clsid_nameW, &eaten, &mon);
1515     ok(hres == S_OK, "MkParseDisplayNameEx failed: %08x\n", hres);
1516     ok(eaten == sizeof(clsid_nameW)/sizeof(WCHAR)-1, "eaten=%d\n", eaten);
1517     ok(mon != NULL, "mon == NULL\n");
1518
1519     hres = IMoniker_IsSystemMoniker(mon, &issys);
1520     ok(hres == S_OK, "IsSystemMoniker failed: %08x\n", hres);
1521     ok(issys == MKSYS_CLASSMONIKER, "issys=%x\n", issys);
1522
1523     IMoniker_Release(mon);
1524
1525     hres = MkParseDisplayNameEx(bctx, url8, &eaten, &mon);
1526     ok(FAILED(hres), "MkParseDisplayNameEx succeeded: %08x\n", hres);
1527
1528     IBindCtx_Release(bctx);
1529 }
1530
1531 START_TEST(misc)
1532 {
1533     OleInitialize(NULL);
1534
1535     register_protocols();
1536
1537     test_CreateFormatEnum();
1538     test_RegisterFormatEnumerator();
1539     test_CoInternetParseUrl();
1540     test_CoInternetCompareUrl();
1541     test_CoInternetQueryInfo();
1542     test_FindMimeFromData();
1543     test_SecurityManager();
1544     test_polices();
1545     test_ZoneManager();
1546     test_NameSpace();
1547     test_MimeFilter();
1548     test_ReleaseBindInfo();
1549     test_CopyStgMedium();
1550     test_UrlMkGetSessionOption();
1551     test_ObtainUserAgentString();
1552     test_MkParseDisplayNameEx();
1553
1554     OleUninitialize();
1555 }