crypt32: Make sure we show Unicode characters (Dutch translation).
[wine] / dlls / mshtml / tests / protocol.c
1 /*
2  * Copyright 2005 Jacek Caban
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
21 #include <wine/test.h>
22 #include <stdarg.h>
23
24 #include "windef.h"
25 #include "winbase.h"
26 #include "ole2.h"
27 #include "urlmon.h"
28 #include "shlwapi.h"
29
30 #include "initguid.h"
31
32 #define DEFINE_EXPECT(func) \
33     static BOOL expect_ ## func = FALSE, called_ ## func = FALSE
34
35 #define SET_EXPECT(func) \
36     expect_ ## func = TRUE
37
38 #define CHECK_EXPECT(func) \
39     do { \
40         ok(expect_ ##func, "unexpected call " #func "\n"); \
41         expect_ ## func = FALSE; \
42         called_ ## func = TRUE; \
43     }while(0)
44
45 #define CHECK_EXPECT2(func) \
46     do { \
47         ok(expect_ ##func, "unexpected call " #func  "\n"); \
48         called_ ## func = TRUE; \
49     }while(0)
50
51 #define CHECK_CALLED(func) \
52     do { \
53         ok(called_ ## func, "expected " #func "\n"); \
54         expect_ ## func = called_ ## func = FALSE; \
55     }while(0)
56
57 DEFINE_GUID(CLSID_ResProtocol, 0x3050F3BC, 0x98B5, 0x11CF, 0xBB,0x82, 0x00,0xAA,0x00,0xBD,0xCE,0x0B);
58 DEFINE_GUID(CLSID_AboutProtocol, 0x3050F406, 0x98B5, 0x11CF, 0xBB,0x82, 0x00,0xAA,0x00,0xBD,0xCE,0x0B);
59
60 DEFINE_EXPECT(GetBindInfo);
61 DEFINE_EXPECT(ReportProgress);
62 DEFINE_EXPECT(ReportData);
63 DEFINE_EXPECT(ReportResult);
64
65 static HRESULT expect_hrResult;
66 static BOOL expect_hr_win32err = FALSE;
67 static DWORD bindf;
68
69 static const WCHAR about_blank_url[] = {'a','b','o','u','t',':','b','l','a','n','k',0};
70 static const WCHAR about_test_url[] = {'a','b','o','u','t',':','t','e','s','t',0};
71 static const WCHAR about_res_url[] = {'r','e','s',':','b','l','a','n','k',0};
72
73 static const char *debugstr_w(LPCWSTR str)
74 {
75     static char buf[1024];
76     WideCharToMultiByte(CP_ACP, 0, str, -1, buf, sizeof(buf), NULL, NULL);
77     return buf;
78 }
79
80 static HRESULT WINAPI ProtocolSink_QueryInterface(IInternetProtocolSink *iface, REFIID riid, void **ppv)
81 {
82     if(IsEqualGUID(&IID_IUnknown, riid) || IsEqualGUID(&IID_IInternetProtocolSink, riid)) {
83         *ppv = iface;
84         return S_OK;
85     }
86     return E_NOINTERFACE;
87 }
88
89 static ULONG WINAPI ProtocolSink_AddRef(IInternetProtocolSink *iface)
90 {
91     return 2;
92 }
93
94 static ULONG WINAPI ProtocolSink_Release(IInternetProtocolSink *iface)
95 {
96     return 1;
97 }
98
99 static HRESULT WINAPI ProtocolSink_Switch(IInternetProtocolSink *iface, PROTOCOLDATA *pProtocolData)
100 {
101     ok(0, "unexpected call\n");
102     return E_NOTIMPL;
103 }
104
105 static HRESULT WINAPI ProtocolSink_ReportProgress(IInternetProtocolSink *iface, ULONG ulStatusCode,
106         LPCWSTR szStatusText)
107 {
108     static const WCHAR text_html[] = {'t','e','x','t','/','h','t','m','l',0};
109
110     CHECK_EXPECT(ReportProgress);
111
112     ok(ulStatusCode == BINDSTATUS_MIMETYPEAVAILABLE
113             || ulStatusCode == BINDSTATUS_VERIFIEDMIMETYPEAVAILABLE,
114             "ulStatusCode=%d\n", ulStatusCode);
115     ok(!lstrcmpW(szStatusText, text_html), "szStatusText != text/html\n");
116
117     return S_OK;
118 }
119
120 static HRESULT WINAPI ProtocolSink_ReportData(IInternetProtocolSink *iface, DWORD grfBSCF, ULONG ulProgress,
121         ULONG ulProgressMax)
122 {
123     CHECK_EXPECT(ReportData);
124
125     ok(ulProgress == ulProgressMax, "ulProgress != ulProgressMax\n");
126     ok(grfBSCF == (BSCF_FIRSTDATANOTIFICATION | BSCF_LASTDATANOTIFICATION | BSCF_DATAFULLYAVAILABLE),
127             "grcf = %08x\n", grfBSCF);
128
129     return S_OK;
130 }
131
132 static HRESULT WINAPI ProtocolSink_ReportResult(IInternetProtocolSink *iface, HRESULT hrResult, DWORD dwError,
133         LPCWSTR szResult)
134 {
135     CHECK_EXPECT(ReportResult);
136
137     if(expect_hr_win32err)
138         ok((hrResult&0xffff0000) == ((FACILITY_WIN32 << 16)|0x80000000) || expect_hrResult,
139                 "expected win32 err or %08x got: %08x\n", expect_hrResult, hrResult);
140     else
141         ok(hrResult == expect_hrResult || ((expect_hrResult == E_INVALIDARG ||
142            expect_hrResult == HRESULT_FROM_WIN32(ERROR_RESOURCE_TYPE_NOT_FOUND)) &&
143            hrResult == MK_E_SYNTAX), "expected: %08x got: %08x\n", expect_hrResult, hrResult);
144     ok(dwError == 0, "dwError = %d\n", dwError);
145     ok(!szResult, "szResult != NULL\n");
146
147     return S_OK;
148 }
149
150 static IInternetProtocolSinkVtbl protocol_sink_vtbl = {
151     ProtocolSink_QueryInterface,
152     ProtocolSink_AddRef,
153     ProtocolSink_Release,
154     ProtocolSink_Switch,
155     ProtocolSink_ReportProgress,
156     ProtocolSink_ReportData,
157     ProtocolSink_ReportResult
158 };
159
160 static IInternetProtocolSink protocol_sink = {
161     &protocol_sink_vtbl
162 };
163
164 static HRESULT WINAPI BindInfo_QueryInterface(IInternetBindInfo *iface, REFIID riid, void **ppv)
165 {
166     if(IsEqualGUID(&IID_IUnknown, riid) || IsEqualGUID(&IID_IInternetBindInfo, riid)) {
167         *ppv = iface;
168         return S_OK;
169     }
170     return E_NOINTERFACE;
171 }
172
173 static ULONG WINAPI BindInfo_AddRef(IInternetBindInfo *iface)
174 {
175     return 2;
176 }
177
178 static ULONG WINAPI BindInfo_Release(IInternetBindInfo *iface)
179 {
180     return 1;
181 }
182
183 static HRESULT WINAPI BindInfo_GetBindInfo(IInternetBindInfo *iface, DWORD *grfBINDF, BINDINFO *pbindinfo)
184 {
185     CHECK_EXPECT(GetBindInfo);
186
187     ok(grfBINDF != NULL, "grfBINDF == NULL\n");
188     ok(pbindinfo != NULL, "pbindinfo == NULL\n");
189     ok(pbindinfo->cbSize == sizeof(BINDINFO), "wrong size of pbindinfo: %d\n", pbindinfo->cbSize);
190
191     *grfBINDF = bindf;
192     return S_OK;
193 }
194
195 static HRESULT WINAPI BindInfo_GetBindString(IInternetBindInfo *iface, ULONG ulStringType, LPOLESTR *ppwzStr,
196         ULONG cEl, ULONG *pcElFetched)
197 {
198     ok(0, "unexpected call\n");
199     return E_NOTIMPL;
200 }
201
202 static IInternetBindInfoVtbl bind_info_vtbl = {
203     BindInfo_QueryInterface,
204     BindInfo_AddRef,
205     BindInfo_Release,
206     BindInfo_GetBindInfo,
207     BindInfo_GetBindString
208 };
209
210 static IInternetBindInfo bind_info = {
211     &bind_info_vtbl
212 };
213
214 static void test_protocol_fail(IInternetProtocol *protocol, LPCWSTR url, HRESULT expected_hres,
215         BOOL expect_win32err)
216 {
217     HRESULT hres;
218
219     SET_EXPECT(GetBindInfo);
220     SET_EXPECT(ReportResult);
221
222     expect_hrResult = expected_hres;
223     expect_hr_win32err = expect_win32err;
224     hres = IInternetProtocol_Start(protocol, url, &protocol_sink, &bind_info, 0, 0);
225     if(expect_win32err)
226         ok((hres&0xffff0000) == ((FACILITY_WIN32 << 16)|0x80000000) || hres == expect_hrResult,
227                 "expected win32 err or %08x got: %08x\n", expected_hres, hres);
228     else
229         ok(hres == expected_hres || ((expected_hres == E_INVALIDARG ||
230            expected_hres == HRESULT_FROM_WIN32(ERROR_RESOURCE_TYPE_NOT_FOUND)) && hres == MK_E_SYNTAX),
231            "expected: %08x got: %08x\n", expected_hres, hres);
232
233     CHECK_CALLED(GetBindInfo);
234     CHECK_CALLED(ReportResult);
235 }
236
237 static void protocol_start(IInternetProtocol *protocol, LPCWSTR url)
238 {
239     HRESULT hres;
240
241     SET_EXPECT(GetBindInfo);
242     SET_EXPECT(ReportResult);
243     SET_EXPECT(ReportProgress);
244     SET_EXPECT(ReportData);
245     expect_hrResult = S_OK;
246     expect_hr_win32err = FALSE;
247
248     hres = IInternetProtocol_Start(protocol, url, &protocol_sink, &bind_info, 0, 0);
249     ok(hres == S_OK, "Start failed: %08x\n", hres);
250
251     CHECK_CALLED(GetBindInfo);
252     CHECK_CALLED(ReportProgress);
253     CHECK_CALLED(ReportData);
254     CHECK_CALLED(ReportResult);
255 }
256
257 static void res_sec_url_cmp(LPCWSTR url, DWORD size, LPCWSTR file)
258 {
259     WCHAR buf[MAX_PATH];
260     DWORD len;
261
262     static const WCHAR fileW[] = {'f','i','l','e',':','/','/'};
263
264     if(size < sizeof(fileW)/sizeof(WCHAR) || memcmp(url, fileW, sizeof(fileW))) {
265         ok(0, "wrong URL protocol\n");
266         return;
267     }
268
269     SetLastError(0xdeadbeef);
270     len = SearchPathW(NULL, file, NULL, sizeof(buf)/sizeof(WCHAR), buf, NULL);
271     if(!len) {
272         if (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)
273             win_skip("SearchPathW is not implemented\n");
274         else
275             ok(0, "SearchPath failed: %u\n", GetLastError());
276         return;
277     }
278
279     len += sizeof(fileW)/sizeof(WCHAR)+1;
280     ok(len == size, "wrong size %u, expected %u\n", size, len);
281     ok(!lstrcmpW(url + sizeof(fileW)/sizeof(WCHAR), buf), "wrong file part %s\n", debugstr_w(url));
282 }
283
284 static void test_res_protocol(void)
285 {
286     IInternetProtocolInfo *protocol_info;
287     IUnknown *unk;
288     IClassFactory *factory;
289     HRESULT hres;
290
291     static const WCHAR blank_url[] =
292         {'r','e','s',':','/','/','m','s','h','t','m','l','.','d','l','l','/','b','l','a','n','k','.','h','t','m',0};
293     static const WCHAR test_part_url[] = {'r','e','s',':','/','/','C','S','S','/','t','e','s','t',0};
294     static const WCHAR wrong_url1[] =
295         {'m','s','h','t','m','l','.','d','l','l','/','b','l','a','n','k','.','m','t','h',0};
296     static const WCHAR wrong_url2[] =
297         {'r','e','s',':','/','/','m','s','h','t','m','l','.','d','l','l',0};
298     static const WCHAR wrong_url3[] =
299         {'r','e','s',':','/','/','m','s','h','t','m','l','.','d','l','l','/','x','x','.','h','t','m',0};
300     static const WCHAR wrong_url4[] =
301         {'r','e','s',':','/','/','x','x','.','d','l','l','/','b','l','a','n','k','.','h','t','m',0};
302     static const WCHAR wrong_url5[] =
303         {'r','e','s',':','/','/','s','h','t','m','l','.','d','l','l','/','b','l','a','n','k','.','h','t','m',0};
304     static const WCHAR mshtml_dllW[] = {'m','s','h','t','m','l','.','d','l','l',0};
305
306     hres = CoGetClassObject(&CLSID_ResProtocol, CLSCTX_INPROC_SERVER, NULL, &IID_IUnknown, (void**)&unk);
307     ok(hres == S_OK, "CoGetClassObject failed: %08x\n", hres);
308     if(FAILED(hres))
309         return;
310
311     hres = IUnknown_QueryInterface(unk, &IID_IInternetProtocolInfo, (void**)&protocol_info);
312     ok(hres == S_OK, "Could not get IInternetProtocolInfo interface: %08x\n", hres);
313     if(SUCCEEDED(hres)) {
314         WCHAR buf[128];
315         DWORD size;
316         int i;
317
318         for(i = PARSE_CANONICALIZE; i <= PARSE_UNESCAPE; i++) {
319             if(i != PARSE_SECURITY_URL && i != PARSE_DOMAIN) {
320                 hres = IInternetProtocolInfo_ParseUrl(protocol_info, blank_url, i, 0, buf,
321                         sizeof(buf)/sizeof(buf[0]), &size, 0);
322                 ok(hres == INET_E_DEFAULT_ACTION,
323                         "[%d] failed: %08x, expected INET_E_DEFAULT_ACTION\n", i, hres);
324             }
325         }
326
327         hres = IInternetProtocolInfo_ParseUrl(protocol_info, blank_url, PARSE_SECURITY_URL, 0, buf,
328                 sizeof(buf)/sizeof(buf[0]), &size, 0);
329         ok(hres == S_OK, "ParseUrl failed: %08x\n", hres);
330         res_sec_url_cmp(buf, size, mshtml_dllW);
331
332         size = 0;
333         hres = IInternetProtocolInfo_ParseUrl(protocol_info, blank_url, PARSE_SECURITY_URL, 0, buf,
334                 3, &size, 0);
335         ok(hres == S_FALSE, "ParseUrl failed: %08x, expected S_FALSE\n", hres);
336         ok(size, "size=0\n");
337
338         hres = IInternetProtocolInfo_ParseUrl(protocol_info, wrong_url1, PARSE_SECURITY_URL, 0, buf,
339                 sizeof(buf)/sizeof(buf[0]), &size, 0);
340         ok(hres == MK_E_SYNTAX || hres == E_INVALIDARG,
341            "ParseUrl failed: %08x, expected MK_E_SYNTAX\n", hres);
342
343         hres = IInternetProtocolInfo_ParseUrl(protocol_info, wrong_url5, PARSE_SECURITY_URL, 0, buf,
344                 sizeof(buf)/sizeof(buf[0]), &size, 0);
345         ok(hres == MK_E_SYNTAX, "ParseUrl failed: %08x, expected MK_E_SYNTAX\n", hres);
346
347         size = 0xdeadbeef;
348         buf[0] = '?';
349         hres = IInternetProtocolInfo_ParseUrl(protocol_info, blank_url, PARSE_DOMAIN, 0, buf,
350                 sizeof(buf)/sizeof(buf[0]), &size, 0);
351         ok(hres == S_OK || hres == E_FAIL, "ParseUrl failed: %08x\n", hres);
352         ok(buf[0] == '?', "buf changed\n");
353         ok(size == sizeof(blank_url)/sizeof(WCHAR) ||
354            size == sizeof(buf)/sizeof(buf[0]), /* IE8 */
355            "size=%d\n", size);
356
357         size = 0xdeadbeef;
358         hres = IInternetProtocolInfo_ParseUrl(protocol_info, wrong_url1, PARSE_DOMAIN, 0, buf,
359                 sizeof(buf)/sizeof(buf[0]), &size, 0);
360         ok(hres == S_OK || hres == E_FAIL, "ParseUrl failed: %08x\n", hres);
361         ok(buf[0] == '?', "buf changed\n");
362         ok(size == sizeof(wrong_url1)/sizeof(WCHAR) ||
363            size == sizeof(buf)/sizeof(buf[0]), /* IE8 */
364            "size=%d\n", size);
365
366         if (0)
367         {
368         /* Crashes on win9x */
369         size = 0xdeadbeef;
370         buf[0] = '?';
371         hres = IInternetProtocolInfo_ParseUrl(protocol_info, NULL, PARSE_DOMAIN, 0, buf,
372                 sizeof(buf)/sizeof(buf[0]), &size, 0);
373         ok(hres == E_FAIL, "ParseUrl failed: %08x\n", hres);
374         ok(buf[0] == '?', "buf changed\n");
375         ok(size == 1, "size=%u, expected 1\n", size);
376
377         buf[0] = '?';
378         hres = IInternetProtocolInfo_ParseUrl(protocol_info, blank_url, PARSE_DOMAIN, 0, buf,
379                 sizeof(buf)/sizeof(buf[0]), NULL, 0);
380         ok(hres == E_POINTER, "ParseUrl failed: %08x\n", hres);
381         ok(buf[0] == '?', "buf changed\n");
382
383         buf[0] = '?';
384         hres = IInternetProtocolInfo_ParseUrl(protocol_info, NULL, PARSE_DOMAIN, 0, buf,
385                 sizeof(buf)/sizeof(buf[0]), NULL, 0);
386         ok(hres == E_POINTER, "ParseUrl failed: %08x\n", hres);
387         ok(buf[0] == '?', "buf changed\n");
388         }
389
390         buf[0] = '?';
391         hres = IInternetProtocolInfo_ParseUrl(protocol_info, blank_url, PARSE_UNESCAPE+1, 0, buf,
392                 sizeof(buf)/sizeof(buf[0]), &size, 0);
393         ok(hres == INET_E_DEFAULT_ACTION,
394                 "ParseUrl failed: %08x, expected INET_E_DEFAULT_ACTION\n", hres);
395         ok(buf[0] == '?', "buf changed\n");
396
397         size = 0xdeadbeef;
398         hres = IInternetProtocolInfo_CombineUrl(protocol_info, blank_url, test_part_url,
399                 0, buf, sizeof(buf)/sizeof(buf[0]), &size, 0);
400         ok(hres == INET_E_USE_DEFAULT_PROTOCOLHANDLER, "CombineUrl failed: %08x\n", hres);
401         ok(size == 0xdeadbeef, "size=%d\n", size);
402
403         size = 0xdeadbeef;
404         hres = IInternetProtocolInfo_CombineUrl(protocol_info, blank_url, test_part_url,
405                 URL_FILE_USE_PATHURL, buf, sizeof(buf)/sizeof(buf[0]), &size, 0);
406         ok(hres == INET_E_USE_DEFAULT_PROTOCOLHANDLER, "CombineUrl failed: %08x\n", hres);
407         ok(size == 0xdeadbeef, "size=%d\n", size);
408
409         size = 0xdeadbeef;
410         hres = IInternetProtocolInfo_CombineUrl(protocol_info, NULL, NULL,
411                 URL_FILE_USE_PATHURL, NULL, 0xdeadbeef, NULL, 0);
412         ok(hres == INET_E_USE_DEFAULT_PROTOCOLHANDLER, "CombineUrl failed: %08x\n", hres);
413         ok(size == 0xdeadbeef, "size=%d\n", size);
414
415         hres = IInternetProtocolInfo_CompareUrl(protocol_info, blank_url, blank_url, 0);
416         ok(hres == E_NOTIMPL, "CompareUrl failed: %08x\n", hres);
417
418         hres = IInternetProtocolInfo_CompareUrl(protocol_info, NULL, NULL, 0xdeadbeef);
419         ok(hres == E_NOTIMPL, "CompareUrl failed: %08x\n", hres);
420
421         for(i=0; i<30; i++) {
422             if(i == QUERY_USES_NETWORK || i == QUERY_IS_SECURE || i == QUERY_IS_SAFE)
423                 continue;
424
425             hres = IInternetProtocolInfo_QueryInfo(protocol_info, blank_url, i, 0,
426                                                    buf, sizeof(buf), &size, 0);
427             ok(hres == INET_E_USE_DEFAULT_PROTOCOLHANDLER,
428                "QueryInfo(%d) returned: %08x, expected INET_E_USE_DEFAULT_PROTOCOLHANDLER\n", i, hres);
429         }
430
431         size = 0xdeadbeef;
432         memset(buf, '?', sizeof(buf));
433         hres = IInternetProtocolInfo_QueryInfo(protocol_info, blank_url, QUERY_USES_NETWORK, 0,
434                                                buf, sizeof(buf), &size, 0);
435         ok(hres == S_OK, "QueryInfo(QUERY_USES_NETWORK) failed: %08x\n", hres);
436         ok(size == sizeof(DWORD), "size=%d\n", size);
437         ok(!*(DWORD*)buf, "buf=%d\n", *(DWORD*)buf);
438
439         memset(buf, '?', sizeof(buf));
440         hres = IInternetProtocolInfo_QueryInfo(protocol_info, blank_url, QUERY_USES_NETWORK, 0,
441                                                buf, sizeof(buf), NULL, 0);
442         ok(hres == S_OK, "QueryInfo(QUERY_USES_NETWORK) failed: %08x\n", hres);
443         ok(!*(DWORD*)buf, "buf=%d\n", *(DWORD*)buf);
444
445         hres = IInternetProtocolInfo_QueryInfo(protocol_info, blank_url, QUERY_USES_NETWORK, 0,
446                                                buf, 3, &size, 0);
447         ok(hres == E_FAIL, "QueryInfo(QUERY_USES_NETWORK) failed: %08x, expected E_FAIL\n", hres);
448
449         size = 0xdeadbeef;
450         memset(buf, '?', sizeof(buf));
451         hres = IInternetProtocolInfo_QueryInfo(protocol_info, NULL, QUERY_USES_NETWORK, 0,
452                                                buf, sizeof(buf), &size, 0);
453         ok(hres == S_OK, "QueryInfo(QUERY_USES_NETWORK) failed: %08x, expected E_FAIL\n", hres);
454         ok(hres == S_OK, "QueryInfo(QUERY_USES_NETWORK) failed: %08x\n", hres);
455         ok(size == sizeof(DWORD), "size=%d\n", size);
456         ok(!*(DWORD*)buf, "buf=%d\n", *(DWORD*)buf);
457
458         hres = IInternetProtocolInfo_QueryInfo(protocol_info, blank_url, QUERY_USES_NETWORK, 0,
459                                                NULL, sizeof(buf), &size, 0);
460         ok(hres == E_FAIL, "QueryInfo(QUERY_USES_NETWORK) failed: %08x, expected E_FAIL\n", hres);
461
462         hres = IInternetProtocolInfo_QueryInfo(protocol_info, blank_url, 60, 0,
463                                                NULL, sizeof(buf), &size, 0);
464         ok(hres == INET_E_USE_DEFAULT_PROTOCOLHANDLER,
465            "QueryInfo failed: %08x, expected INET_E_USE_DEFAULT_PROTOCOLHANDLER\n", hres);
466
467         IInternetProtocolInfo_Release(protocol_info);
468     }
469
470     hres = IUnknown_QueryInterface(unk, &IID_IClassFactory, (void**)&factory);
471     ok(hres == S_OK, "Could not get IClassFactory interface\n");
472     if(SUCCEEDED(hres)) {
473         IInternetProtocol *protocol;
474         BYTE buf[512];
475         ULONG cb;
476         hres = IClassFactory_CreateInstance(factory, NULL, &IID_IInternetProtocol, (void**)&protocol);
477         ok(hres == S_OK, "Could not get IInternetProtocol: %08x\n", hres);
478
479         if(SUCCEEDED(hres)) {
480             IInternetPriority *priority;
481
482             hres = IInternetProtocol_QueryInterface(protocol, &IID_IInternetPriority, (void**)&priority);
483             ok(hres == E_NOINTERFACE,
484                "QueryInterface(IInternetPriority) returned %08x, expected E_NOINTEFACE\n", hres);
485
486             test_protocol_fail(protocol, wrong_url1, E_INVALIDARG, FALSE);
487             test_protocol_fail(protocol, wrong_url2,
488                                HRESULT_FROM_WIN32(ERROR_RESOURCE_TYPE_NOT_FOUND), FALSE);
489             test_protocol_fail(protocol, wrong_url3, E_FAIL, TRUE);
490             test_protocol_fail(protocol, wrong_url4, E_FAIL, TRUE);
491
492             cb = 0xdeadbeef;
493             hres = IInternetProtocol_Read(protocol, buf, sizeof(buf), &cb);
494             ok(hres == E_FAIL, "Read returned %08x expected E_FAIL\n", hres);
495             ok(cb == 0xdeadbeef, "cb=%u expected 0xdeadbeef\n", cb);
496     
497             protocol_start(protocol, blank_url);
498             hres = IInternetProtocol_Read(protocol, buf, 2, &cb);
499             ok(hres == S_OK, "Read failed: %08x\n", hres);
500             ok(cb == 2, "cb=%u expected 2\n", cb);
501             hres = IInternetProtocol_Read(protocol, buf, sizeof(buf), &cb);
502             ok(hres == S_OK, "Read failed: %08x\n", hres);
503             hres = IInternetProtocol_Read(protocol, buf, sizeof(buf), &cb);
504             ok(hres == S_FALSE, "Read failed: %08x expected S_FALSE\n", hres);
505             ok(cb == 0, "cb=%u expected 0\n", cb);
506             hres = IInternetProtocol_UnlockRequest(protocol);
507             ok(hres == S_OK, "UnlockRequest failed: %08x\n", hres);
508
509             protocol_start(protocol, blank_url);
510             hres = IInternetProtocol_Read(protocol, buf, 2, &cb);
511             ok(hres == S_OK, "Read failed: %08x\n", hres);
512             hres = IInternetProtocol_LockRequest(protocol, 0);
513             ok(hres == S_OK, "LockRequest failed: %08x\n", hres);
514             hres = IInternetProtocol_UnlockRequest(protocol);
515             ok(hres == S_OK, "UnlockRequest failed: %08x\n", hres);
516             hres = IInternetProtocol_Read(protocol, buf, sizeof(buf), &cb);
517             ok(hres == S_OK, "Read failed: %08x\n", hres);
518
519             protocol_start(protocol, blank_url);
520             hres = IInternetProtocol_LockRequest(protocol, 0);
521             ok(hres == S_OK, "LockRequest failed: %08x\n", hres);
522             hres = IInternetProtocol_Terminate(protocol, 0);
523             ok(hres == S_OK, "Terminate failed: %08x\n", hres);
524             hres = IInternetProtocol_Read(protocol, buf, 2, &cb);
525             ok(hres == S_OK, "Read failed: %08x\n\n", hres);
526             hres = IInternetProtocol_UnlockRequest(protocol);
527             ok(hres == S_OK, "UnlockRequest failed: %08x\n", hres);
528             hres = IInternetProtocol_Read(protocol, buf, 2, &cb);
529             ok(hres == S_OK, "Read failed: %08x\n", hres);
530             hres = IInternetProtocol_Terminate(protocol, 0);
531             ok(hres == S_OK, "Terminate failed: %08x\n", hres);
532             hres = IInternetProtocol_Read(protocol, buf, 2, &cb);
533             ok(hres == S_OK, "Read failed: %08x\n", hres);
534             ok(cb == 2, "cb=%u expected 2\n", cb);
535
536             protocol_start(protocol, blank_url);
537             hres = IInternetProtocol_LockRequest(protocol, 0);
538             ok(hres == S_OK, "LockRequest failed: %08x\n", hres);
539             hres = IInternetProtocol_Read(protocol, buf, sizeof(buf), &cb);
540             ok(hres == S_OK, "Read failed: %08x\n", hres);
541             protocol_start(protocol, blank_url);
542             hres = IInternetProtocol_Read(protocol, buf, sizeof(buf), &cb);
543             ok(hres == S_OK, "Read failed: %08x\n", hres);
544             hres = IInternetProtocol_Terminate(protocol, 0);
545             ok(hres == S_OK, "Terminate failed: %08x\n", hres);
546
547             IInternetProtocol_Release(protocol);
548         }
549
550         IClassFactory_Release(factory);
551     }
552
553     IUnknown_Release(unk);
554 }
555
556 static void do_test_about_protocol(IClassFactory *factory, DWORD bf)
557 {
558     IInternetProtocol *protocol;
559     IInternetPriority *priority;
560     BYTE buf[512];
561     ULONG cb;
562     HRESULT hres;
563
564     static const WCHAR blank_html[] = {0xfeff,'<','H','T','M','L','>','<','/','H','T','M','L','>',0};
565     static const WCHAR test_html[] =
566         {0xfeff,'<','H','T','M','L','>','t','e','s','t','<','/','H','T','M','L','>',0};
567
568     bindf = bf;
569
570     hres = IClassFactory_CreateInstance(factory, NULL, &IID_IInternetProtocol, (void**)&protocol);
571     ok(hres == S_OK, "Could not get IInternetProtocol: %08x\n", hres);
572     if(FAILED(hres))
573         return;
574
575     hres = IInternetProtocol_QueryInterface(protocol, &IID_IInternetPriority, (void**)&priority);
576     ok(hres == E_NOINTERFACE,
577        "QueryInterface(IInternetPriority) returned %08x, expected E_NOINTEFACE\n", hres);
578
579     protocol_start(protocol, about_blank_url);
580     hres = IInternetProtocol_LockRequest(protocol, 0);
581     ok(hres == S_OK, "LockRequest failed: %08x\n", hres);
582     hres = IInternetProtocol_Read(protocol, buf, sizeof(buf), &cb);
583     ok(hres == S_OK, "Read failed: %08x\n", hres);
584     ok(cb == sizeof(blank_html), "cb=%d\n", cb);
585     ok(!memcmp(buf, blank_html, cb), "Readed wrong data\n");
586     hres = IInternetProtocol_UnlockRequest(protocol);
587     ok(hres == S_OK, "UnlockRequest failed: %08x\n", hres);
588
589     protocol_start(protocol, about_test_url);
590     hres = IInternetProtocol_LockRequest(protocol, 0);
591     ok(hres == S_OK, "LockRequest failed: %08x\n", hres);
592     hres = IInternetProtocol_Read(protocol, buf, sizeof(buf), &cb);
593     ok(hres == S_OK, "Read failed: %08x\n", hres);
594     ok(cb == sizeof(test_html), "cb=%d\n", cb);
595     ok(!memcmp(buf, test_html, cb), "Readed wrong data\n");
596     hres = IInternetProtocol_UnlockRequest(protocol);
597     ok(hres == S_OK, "UnlockRequest failed: %08x\n", hres);
598
599     protocol_start(protocol, about_res_url);
600     hres = IInternetProtocol_LockRequest(protocol, 0);
601     ok(hres == S_OK, "LockRequest failed: %08x\n", hres);
602     hres = IInternetProtocol_Read(protocol, buf, sizeof(buf), &cb);
603     ok(hres == S_OK, "Read failed: %08x\n", hres);
604     ok(cb == sizeof(blank_html), "cb=%d\n", cb);
605     ok(!memcmp(buf, blank_html, cb), "Readed wrong data\n");
606     hres = IInternetProtocol_UnlockRequest(protocol);
607     ok(hres == S_OK, "UnlockRequest failed: %08x\n", hres);
608
609     IInternetProtocol_Release(protocol);
610 }
611
612 static void test_about_protocol(void)
613 {
614     IInternetProtocolInfo *protocol_info;
615     IUnknown *unk;
616     IClassFactory *factory;
617     HRESULT hres;
618
619     hres = CoGetClassObject(&CLSID_AboutProtocol, CLSCTX_INPROC_SERVER, NULL, &IID_IUnknown, (void**)&unk);
620     ok(hres == S_OK, "CoGetClassObject failed: %08x\n", hres);
621     if(FAILED(hres))
622         return;
623
624     hres = IUnknown_QueryInterface(unk, &IID_IInternetProtocolInfo, (void**)&protocol_info);
625     ok(hres == S_OK, "Could not get IInternetProtocolInfo interface: %08x\n", hres);
626     if(SUCCEEDED(hres)) {
627         WCHAR buf[128];
628         DWORD size;
629         int i;
630
631         for(i = PARSE_CANONICALIZE; i <= PARSE_UNESCAPE; i++) {
632             if(i != PARSE_SECURITY_URL && i != PARSE_DOMAIN) {
633                 hres = IInternetProtocolInfo_ParseUrl(protocol_info, about_blank_url, i, 0, buf,
634                         sizeof(buf)/sizeof(buf[0]), &size, 0);
635                 ok(hres == INET_E_DEFAULT_ACTION,
636                         "[%d] failed: %08x, expected INET_E_DEFAULT_ACTION\n", i, hres);
637             }
638         }
639
640         hres = IInternetProtocolInfo_ParseUrl(protocol_info, about_blank_url, PARSE_SECURITY_URL, 0, buf,
641                 sizeof(buf)/sizeof(buf[0]), &size, 0);
642         ok(hres == S_OK, "ParseUrl failed: %08x\n", hres);
643         ok(!lstrcmpW(about_blank_url, buf), "buf != blank_url\n");
644
645         hres = IInternetProtocolInfo_ParseUrl(protocol_info, about_blank_url, PARSE_SECURITY_URL, 0, buf,
646                 3, &size, 0);
647         ok(hres == S_FALSE, "ParseUrl failed: %08x, expected S_FALSE\n", hres);
648
649         hres = IInternetProtocolInfo_ParseUrl(protocol_info, about_test_url, PARSE_SECURITY_URL, 0, buf,
650                 sizeof(buf)/sizeof(buf[0]), &size, 0);
651         ok(hres == S_OK, "ParseUrl failed: %08x\n", hres);
652         ok(!lstrcmpW(about_test_url, buf), "buf != test_url\n");
653
654         size = 0xdeadbeef;
655         buf[0] = '?';
656         hres = IInternetProtocolInfo_ParseUrl(protocol_info, about_blank_url, PARSE_DOMAIN, 0, buf,
657                 sizeof(buf)/sizeof(buf[0]), &size, 0);
658         ok(hres == S_OK || hres == E_FAIL, "ParseUrl failed: %08x\n", hres);
659         ok(buf[0] == '?', "buf changed\n");
660         ok(size == sizeof(about_blank_url)/sizeof(WCHAR) ||
661            size == sizeof(buf)/sizeof(buf[0]), /* IE8 */
662            "size=%d\n", size);
663
664         if (0)
665         {
666         /* Crashes on win9x */
667         size = 0xdeadbeef;
668         buf[0] = '?';
669         hres = IInternetProtocolInfo_ParseUrl(protocol_info, NULL, PARSE_DOMAIN, 0, buf,
670                 sizeof(buf)/sizeof(buf[0]), &size, 0);
671         ok(hres == E_FAIL, "ParseUrl failed: %08x\n", hres);
672         ok(buf[0] == '?', "buf changed\n");
673         ok(size == 1, "size=%u, expected 1\n", size);
674
675         buf[0] = '?';
676         hres = IInternetProtocolInfo_ParseUrl(protocol_info, about_blank_url, PARSE_DOMAIN, 0, buf,
677                 sizeof(buf)/sizeof(buf[0]), NULL, 0);
678         ok(hres == E_POINTER, "ParseUrl failed: %08x\n", hres);
679         ok(buf[0] == '?', "buf changed\n");
680
681         buf[0] = '?';
682         hres = IInternetProtocolInfo_ParseUrl(protocol_info, NULL, PARSE_DOMAIN, 0, buf,
683                 sizeof(buf)/sizeof(buf[0]), NULL, 0);
684         ok(hres == E_POINTER, "ParseUrl failed: %08x\n", hres);
685         ok(buf[0] == '?', "buf changed\n");
686         }
687
688         hres = IInternetProtocolInfo_ParseUrl(protocol_info, about_blank_url, PARSE_UNESCAPE+1, 0, buf,
689                 sizeof(buf)/sizeof(buf[0]), &size, 0);
690         ok(hres == INET_E_DEFAULT_ACTION,
691                 "ParseUrl failed: %08x, expected INET_E_DEFAULT_ACTION\n", hres);
692
693         size = 0xdeadbeef;
694         hres = IInternetProtocolInfo_CombineUrl(protocol_info, about_blank_url, about_test_url,
695                 0, buf, sizeof(buf)/sizeof(buf[0]), &size, 0);
696         ok(hres == INET_E_USE_DEFAULT_PROTOCOLHANDLER, "CombineUrl failed: %08x\n", hres);
697         ok(size == 0xdeadbeef, "size=%d\n", size);
698
699         size = 0xdeadbeef;
700         hres = IInternetProtocolInfo_CombineUrl(protocol_info, about_blank_url, about_test_url,
701                 URL_FILE_USE_PATHURL, buf, sizeof(buf)/sizeof(buf[0]), &size, 0);
702         ok(hres == INET_E_USE_DEFAULT_PROTOCOLHANDLER, "CombineUrl failed: %08x\n", hres);
703         ok(size == 0xdeadbeef, "size=%d\n", size);
704
705         size = 0xdeadbeef;
706         hres = IInternetProtocolInfo_CombineUrl(protocol_info, NULL, NULL,
707                 URL_FILE_USE_PATHURL, buf, sizeof(buf)/sizeof(buf[0]), &size, 0);
708         ok(hres == INET_E_USE_DEFAULT_PROTOCOLHANDLER, "CombineUrl failed: %08x\n", hres);
709         ok(size == 0xdeadbeef, "size=%d\n", size);
710
711         hres = IInternetProtocolInfo_CompareUrl(protocol_info, about_blank_url, about_blank_url, 0);
712         ok(hres == E_NOTIMPL, "CompareUrl failed: %08x\n", hres);
713
714         hres = IInternetProtocolInfo_CompareUrl(protocol_info, NULL, NULL, 0xdeadbeef);
715         ok(hres == E_NOTIMPL, "CompareUrl failed: %08x\n", hres);
716
717         for(i=0; i<30; i++) {
718             switch(i) {
719             case QUERY_CAN_NAVIGATE:
720             case QUERY_USES_NETWORK:
721             case QUERY_IS_CACHED:
722             case QUERY_IS_INSTALLEDENTRY:
723             case QUERY_IS_CACHED_OR_MAPPED:
724             case QUERY_IS_SECURE:
725             case QUERY_IS_SAFE:
726             case QUERY_USES_HISTORYFOLDER:
727                 break;
728             default:
729                 hres = IInternetProtocolInfo_QueryInfo(protocol_info, about_blank_url, i, 0,
730                                                        buf, sizeof(buf), &size, 0);
731                 ok(hres == E_FAIL, "QueryInfo(%d) returned: %08x, expected E_FAIL\n", i, hres);
732             }
733         }
734
735         hres = IInternetProtocolInfo_QueryInfo(protocol_info, about_blank_url, QUERY_CAN_NAVIGATE, 0,
736                                                buf, sizeof(buf), &size, 0);
737         ok(hres == INET_E_USE_DEFAULT_PROTOCOLHANDLER ||
738            hres == E_FAIL, /* win2k */
739            "QueryInfo returned: %08x, expected INET_E_USE_DEFAULT_PROTOCOLHANDLER or E_FAIL\n", hres);
740
741         size = 0xdeadbeef;
742         memset(buf, '?', sizeof(buf));
743         hres = IInternetProtocolInfo_QueryInfo(protocol_info, about_blank_url, QUERY_USES_NETWORK, 0,
744                                                buf, sizeof(buf), &size, 0);
745         ok(hres == S_OK, "QueryInfo(QUERY_USES_NETWORK) failed: %08x\n", hres);
746         ok(size == sizeof(DWORD), "size=%d\n", size);
747         ok(!*(DWORD*)buf, "buf=%d\n", *(DWORD*)buf);
748
749         memset(buf, '?', sizeof(buf));
750         hres = IInternetProtocolInfo_QueryInfo(protocol_info, about_blank_url, QUERY_USES_NETWORK, 0,
751                                                buf, sizeof(buf), NULL, 0);
752         ok(hres == S_OK, "QueryInfo(QUERY_USES_NETWORK) failed: %08x\n", hres);
753         ok(!*(DWORD*)buf, "buf=%d\n", *(DWORD*)buf);
754
755         hres = IInternetProtocolInfo_QueryInfo(protocol_info, about_blank_url, QUERY_USES_NETWORK, 0,
756                                                buf, 3, &size, 0);
757         ok(hres == E_FAIL, "QueryInfo(QUERY_USES_NETWORK) failed: %08x, expected E_FAIL\n", hres);
758
759         hres = IInternetProtocolInfo_QueryInfo(protocol_info, about_blank_url, QUERY_USES_NETWORK, 0,
760                                                NULL, sizeof(buf), &size, 0);
761         ok(hres == E_FAIL, "QueryInfo(QUERY_USES_NETWORK) failed: %08x, expected E_FAIL\n", hres);
762
763         hres = IInternetProtocolInfo_QueryInfo(protocol_info, about_blank_url, 60, 0,
764                                                NULL, sizeof(buf), &size, 0);
765         ok(hres == E_FAIL, "QueryInfo failed: %08x, expected E_FAIL\n", hres);
766
767         IInternetProtocolInfo_Release(protocol_info);
768     }
769
770     hres = IUnknown_QueryInterface(unk, &IID_IClassFactory, (void**)&factory);
771     ok(hres == S_OK, "Could not get IClassFactory interface\n");
772     if(SUCCEEDED(hres)) {
773         do_test_about_protocol(factory, 0);
774         do_test_about_protocol(factory,
775                 BINDF_ASYNCHRONOUS | BINDF_ASYNCSTORAGE | BINDF_PULLDATA | BINDF_FROMURLMON | BINDF_NEEDFILE);
776
777         IClassFactory_Release(factory);
778     }
779
780     IUnknown_Release(unk);
781 }
782
783 START_TEST(protocol)
784 {
785     OleInitialize(NULL);
786
787     test_res_protocol();
788     test_about_protocol();
789
790     OleUninitialize();
791 }