urlmon: Added HTTP redirecting test.
[wine] / dlls / urlmon / tests / protocol.c
1 /*
2  * Copyright 2005-2009 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
22 #include <wine/test.h>
23 #include <stdarg.h>
24 #include <stdio.h>
25
26 #include "windef.h"
27 #include "winbase.h"
28 #include "ole2.h"
29 #include "urlmon.h"
30 #include "wininet.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_EXPECT2(func) \
39     do { \
40         ok(expect_ ##func, "unexpected call " #func  "\n"); \
41         called_ ## func = TRUE; \
42     }while(0)
43
44 #define CHECK_EXPECT(func) \
45     do { \
46         CHECK_EXPECT2(func);     \
47         expect_ ## func = FALSE; \
48     }while(0)
49
50 #define CHECK_CALLED(func) \
51     do { \
52         ok(called_ ## func, "expected " #func "\n"); \
53         expect_ ## func = called_ ## func = FALSE; \
54     }while(0)
55
56 #define CHECK_NOT_CALLED(func) \
57     do { \
58         ok(!called_ ## func, "unexpected " #func "\n"); \
59         expect_ ## func = called_ ## func = FALSE; \
60     }while(0)
61
62 #define CLEAR_CALLED(func) \
63     expect_ ## func = called_ ## func = FALSE
64
65 DEFINE_EXPECT(GetBindInfo);
66 DEFINE_EXPECT(ReportProgress_MIMETYPEAVAILABLE);
67 DEFINE_EXPECT(ReportProgress_DIRECTBIND);
68 DEFINE_EXPECT(ReportProgress_RAWMIMETYPE);
69 DEFINE_EXPECT(ReportProgress_FINDINGRESOURCE);
70 DEFINE_EXPECT(ReportProgress_CONNECTING);
71 DEFINE_EXPECT(ReportProgress_SENDINGREQUEST);
72 DEFINE_EXPECT(ReportProgress_CACHEFILENAMEAVAILABLE);
73 DEFINE_EXPECT(ReportProgress_VERIFIEDMIMETYPEAVAILABLE);
74 DEFINE_EXPECT(ReportProgress_PROTOCOLCLASSID);
75 DEFINE_EXPECT(ReportProgress_COOKIE_SENT);
76 DEFINE_EXPECT(ReportProgress_REDIRECTING);
77 DEFINE_EXPECT(ReportProgress_ENCODING);
78 DEFINE_EXPECT(ReportProgress_ACCEPTRANGES);
79 DEFINE_EXPECT(ReportProgress_PROXYDETECTING);
80 DEFINE_EXPECT(ReportProgress_LOADINGMIMEHANDLER);
81 DEFINE_EXPECT(ReportProgress_DECODING);
82 DEFINE_EXPECT(ReportData);
83 DEFINE_EXPECT(ReportData2);
84 DEFINE_EXPECT(ReportResult);
85 DEFINE_EXPECT(GetBindString_ACCEPT_MIMES);
86 DEFINE_EXPECT(GetBindString_USER_AGENT);
87 DEFINE_EXPECT(GetBindString_POST_COOKIE);
88 DEFINE_EXPECT(GetBindString_URL);
89 DEFINE_EXPECT(QueryService_HttpNegotiate);
90 DEFINE_EXPECT(QueryService_InternetProtocol);
91 DEFINE_EXPECT(QueryService_HttpSecurity);
92 DEFINE_EXPECT(QueryInterface_IWinInetInfo);
93 DEFINE_EXPECT(QueryInterface_IWinInetHttpInfo);
94 DEFINE_EXPECT(BeginningTransaction);
95 DEFINE_EXPECT(GetRootSecurityId);
96 DEFINE_EXPECT(OnResponse);
97 DEFINE_EXPECT(Switch);
98 DEFINE_EXPECT(Continue);
99 DEFINE_EXPECT(CreateInstance);
100 DEFINE_EXPECT(Start);
101 DEFINE_EXPECT(Terminate);
102 DEFINE_EXPECT(Read);
103 DEFINE_EXPECT(Read2);
104 DEFINE_EXPECT(SetPriority);
105 DEFINE_EXPECT(LockRequest);
106 DEFINE_EXPECT(UnlockRequest);
107 DEFINE_EXPECT(MimeFilter_CreateInstance);
108 DEFINE_EXPECT(MimeFilter_Start);
109 DEFINE_EXPECT(MimeFilter_ReportProgress);
110 DEFINE_EXPECT(MimeFilter_ReportData);
111 DEFINE_EXPECT(MimeFilter_ReportResult);
112 DEFINE_EXPECT(MimeFilter_Terminate);
113 DEFINE_EXPECT(MimeFilter_LockRequest);
114 DEFINE_EXPECT(MimeFilter_UnlockRequest);
115 DEFINE_EXPECT(MimeFilter_Read);
116 DEFINE_EXPECT(MimeFilter_Switch);
117 DEFINE_EXPECT(MimeFilter_Continue);
118
119 static const WCHAR wszIndexHtml[] = {'i','n','d','e','x','.','h','t','m','l',0};
120 static const WCHAR index_url[] =
121     {'f','i','l','e',':','i','n','d','e','x','.','h','t','m','l',0};
122
123 static const WCHAR acc_mimeW[] = {'*','/','*',0};
124 static const WCHAR user_agentW[] = {'W','i','n','e',0};
125 static const WCHAR text_htmlW[] = {'t','e','x','t','/','h','t','m','l',0};
126 static const WCHAR hostW[] = {'w','w','w','.','w','i','n','e','h','q','.','o','r','g',0};
127 static const WCHAR winehq_ipW[] = {'2','0','9','.','4','6','.','2','5','.','1','3','4',0};
128 static const WCHAR emptyW[] = {0};
129 static const WCHAR gzipW[] = {'g','z','i','p',0};
130
131 static HRESULT expect_hrResult;
132 static LPCWSTR file_name, http_url, expect_wsz;
133 static IInternetProtocol *async_protocol = NULL;
134 static BOOL first_data_notif, http_is_first, http_post_test, test_redirect;
135 static int state = 0, prot_state, read_report_data;
136 static DWORD bindf, ex_priority , pi;
137 static IInternetProtocol *binding_protocol, *filtered_protocol;
138 static IInternetBindInfo *prot_bind_info;
139 static IInternetProtocolSink *binding_sink, *filtered_sink;
140 static void *expect_pv;
141 static HANDLE event_complete, event_complete2, event_continue, event_continue_done;
142 static BOOL binding_test;
143 static PROTOCOLDATA protocoldata, *pdata, continue_protdata;
144 static DWORD prot_read, pi, filter_state;
145 static BOOL security_problem;
146 static BOOL async_read_pending, mimefilter_test, direct_read, wait_for_switch, emulate_prot, short_read;
147
148 static enum {
149     FILE_TEST,
150     HTTP_TEST,
151     HTTPS_TEST,
152     FTP_TEST,
153     MK_TEST,
154     BIND_TEST
155 } tested_protocol;
156
157 static const WCHAR protocol_names[][10] = {
158     {'f','i','l','e',0},
159     {'h','t','t','p',0},
160     {'h','t','t','p','s',0},
161     {'f','t','p',0},
162     {'m','k',0},
163     {'t','e','s','t',0}
164 };
165
166 static const WCHAR binding_urls[][130] = {
167     {'f','i','l','e',':','t','e','s','t','.','h','t','m','l',0},
168     {'h','t','t','p',':','/','/','w','w','w','.','w','i','n','e','h','q','.',
169      'o','r','g','/','s','i','t','e','/','a','b','o','u','t',0},
170     {'h','t','t','p','s',':','/','/','w','w','w','.','c','o','d','e','w','e','a','v','e','r','s',
171      '.','c','o','m','/','t','e','s','t','.','h','t','m','l',0},
172     {'f','t','p',':','/','/','f','t','p','.','w','i','n','e','h','q','.','o','r','g',
173      '/','p','u','b','/','o','t','h','e','r',
174      '/','w','i','n','e','l','o','g','o','.','x','c','f','.','t','a','r','.','b','z','2',0},
175     {'m','k',':','t','e','s','t',0},
176     {'t','e','s','t',':','/','/','f','i','l','e','.','h','t','m','l',0}
177 };
178
179 static const char *debugstr_guid(REFIID riid)
180 {
181     static char buf[50];
182
183     sprintf(buf, "{%08X-%04X-%04X-%02X%02X-%02X%02X%02X%02X%02X%02X}",
184             riid->Data1, riid->Data2, riid->Data3, riid->Data4[0],
185             riid->Data4[1], riid->Data4[2], riid->Data4[3], riid->Data4[4],
186             riid->Data4[5], riid->Data4[6], riid->Data4[7]);
187
188     return buf;
189 }
190
191 static int strcmp_wa(LPCWSTR strw, const char *stra)
192 {
193     CHAR buf[512];
194     WideCharToMultiByte(CP_ACP, 0, strw, -1, buf, sizeof(buf), NULL, NULL);
195     return lstrcmpA(stra, buf);
196 }
197
198 /* lstrcmpW is not implemented on Win9x */
199 static int strcmp_ww(LPCWSTR strw1, LPCWSTR strw2)
200 {
201     CHAR stra1[512], stra2[512];
202     WideCharToMultiByte(CP_ACP, 0, strw1, -1, stra1, MAX_PATH, NULL, NULL);
203     WideCharToMultiByte(CP_ACP, 0, strw2, -1, stra2, MAX_PATH, NULL, NULL);
204     return lstrcmpA(stra1, stra2);
205 }
206
207 static HRESULT WINAPI HttpSecurity_QueryInterface(IHttpSecurity *iface, REFIID riid, void **ppv)
208 {
209     if(IsEqualGUID(&IID_IUnknown, riid)
210             || IsEqualGUID(&IID_IHttpSecurity, riid)) {
211         *ppv = iface;
212         return S_OK;
213     }
214
215     ok(0, "unexpected call\n");
216     return E_NOINTERFACE;
217 }
218
219 static ULONG WINAPI HttpSecurity_AddRef(IHttpSecurity *iface)
220 {
221     return 2;
222 }
223
224 static ULONG WINAPI HttpSecurity_Release(IHttpSecurity *iface)
225 {
226     return 1;
227 }
228
229 static  HRESULT WINAPI HttpSecurity_GetWindow(IHttpSecurity* iface, REFGUID rguidReason, HWND *phwnd)
230 {
231     trace("HttpSecurity_GetWindow\n");
232
233     return S_FALSE;
234 }
235
236 static HRESULT WINAPI HttpSecurity_OnSecurityProblem(IHttpSecurity *iface, DWORD dwProblem)
237 {
238     trace("Security problem: %u\n", dwProblem);
239     ok(dwProblem == ERROR_INTERNET_SEC_CERT_REV_FAILED, "Expected ERROR_INTERNET_SEC_CERT_REV_FAILED got %u\n", dwProblem);
240
241     /* Only retry once */
242     if (security_problem)
243         return E_ABORT;
244
245     security_problem = TRUE;
246     SET_EXPECT(BeginningTransaction);
247
248     return RPC_E_RETRY;
249 }
250
251 static IHttpSecurityVtbl HttpSecurityVtbl = {
252     HttpSecurity_QueryInterface,
253     HttpSecurity_AddRef,
254     HttpSecurity_Release,
255     HttpSecurity_GetWindow,
256     HttpSecurity_OnSecurityProblem
257 };
258
259 static IHttpSecurity http_security = { &HttpSecurityVtbl };
260
261 static HRESULT WINAPI HttpNegotiate_QueryInterface(IHttpNegotiate2 *iface, REFIID riid, void **ppv)
262 {
263     if(IsEqualGUID(&IID_IUnknown, riid)
264             || IsEqualGUID(&IID_IHttpNegotiate, riid)
265             || IsEqualGUID(&IID_IHttpNegotiate2, riid)) {
266         *ppv = iface;
267         return S_OK;
268     }
269
270     ok(0, "unexpected call\n");
271     return E_NOINTERFACE;
272 }
273
274 static ULONG WINAPI HttpNegotiate_AddRef(IHttpNegotiate2 *iface)
275 {
276     return 2;
277 }
278
279 static ULONG WINAPI HttpNegotiate_Release(IHttpNegotiate2 *iface)
280 {
281     return 1;
282 }
283
284 static HRESULT WINAPI HttpNegotiate_BeginningTransaction(IHttpNegotiate2 *iface, LPCWSTR szURL,
285         LPCWSTR szHeaders, DWORD dwReserved, LPWSTR *pszAdditionalHeaders)
286 {
287     LPWSTR addl_headers;
288
289     static const WCHAR wszHeaders[] =
290         {'C','o','n','t','e','n','t','-','T','y','p','e',':',' ','a','p','p','l','i','c','a','t',
291          'i','o','n','/','x','-','w','w','w','-','f','o','r','m','-','u','r','l','e','n','c','o',
292          'd','e','d','\r','\n',0};
293
294     CHECK_EXPECT(BeginningTransaction);
295
296     if(binding_test)
297         ok(!strcmp_ww(szURL, binding_urls[tested_protocol]), "szURL != http_url\n");
298     else
299         ok(!strcmp_ww(szURL, http_url), "szURL != http_url\n");
300     ok(!dwReserved, "dwReserved=%d, expected 0\n", dwReserved);
301     ok(pszAdditionalHeaders != NULL, "pszAdditionalHeaders == NULL\n");
302     if(pszAdditionalHeaders)
303     {
304         ok(*pszAdditionalHeaders == NULL, "*pszAdditionalHeaders != NULL\n");
305         if (http_post_test)
306         {
307             addl_headers = CoTaskMemAlloc(sizeof(wszHeaders));
308             if (!addl_headers)
309             {
310                 http_post_test = FALSE;
311                 skip("Out of memory\n");
312                 return E_OUTOFMEMORY;
313             }
314             memcpy(addl_headers, wszHeaders, sizeof(wszHeaders));
315             *pszAdditionalHeaders = addl_headers;
316         }
317     }
318
319     return S_OK;
320 }
321
322 static HRESULT WINAPI HttpNegotiate_OnResponse(IHttpNegotiate2 *iface, DWORD dwResponseCode,
323         LPCWSTR szResponseHeaders, LPCWSTR szRequestHeaders, LPWSTR *pszAdditionalRequestHeaders)
324 {
325     CHECK_EXPECT(OnResponse);
326
327     ok(dwResponseCode == 200, "dwResponseCode=%d, expected 200\n", dwResponseCode);
328     ok(szResponseHeaders != NULL, "szResponseHeaders == NULL\n");
329     ok(szRequestHeaders == NULL, "szRequestHeaders != NULL\n");
330     ok(pszAdditionalRequestHeaders == NULL, "pszAdditionalHeaders != NULL\n");
331
332     return S_OK;
333 }
334
335 static HRESULT WINAPI HttpNegotiate_GetRootSecurityId(IHttpNegotiate2 *iface,
336         BYTE *pbSecurityId, DWORD *pcbSecurityId, DWORD_PTR dwReserved)
337 {
338     static const BYTE sec_id[] = {'h','t','t','p',':','t','e','s','t',1,0,0,0};
339     
340     CHECK_EXPECT(GetRootSecurityId);
341
342     ok(!dwReserved, "dwReserved=%ld, expected 0\n", dwReserved);
343     ok(pbSecurityId != NULL, "pbSecurityId == NULL\n");
344     ok(pcbSecurityId != NULL, "pcbSecurityId == NULL\n");
345
346     if(pcbSecurityId) {
347         ok(*pcbSecurityId == 512, "*pcbSecurityId=%d, expected 512\n", *pcbSecurityId);
348         *pcbSecurityId = sizeof(sec_id);
349     }
350
351     if(pbSecurityId)
352         memcpy(pbSecurityId, sec_id, sizeof(sec_id));
353
354     return E_FAIL;
355 }
356
357 static IHttpNegotiate2Vtbl HttpNegotiateVtbl = {
358     HttpNegotiate_QueryInterface,
359     HttpNegotiate_AddRef,
360     HttpNegotiate_Release,
361     HttpNegotiate_BeginningTransaction,
362     HttpNegotiate_OnResponse,
363     HttpNegotiate_GetRootSecurityId
364 };
365
366 static IHttpNegotiate2 http_negotiate = { &HttpNegotiateVtbl };
367
368 static HRESULT QueryInterface(REFIID,void**);
369
370 static HRESULT WINAPI ServiceProvider_QueryInterface(IServiceProvider *iface, REFIID riid, void **ppv)
371 {
372     return QueryInterface(riid, ppv);
373 }
374
375 static ULONG WINAPI ServiceProvider_AddRef(IServiceProvider *iface)
376 {
377     return 2;
378 }
379
380 static ULONG WINAPI ServiceProvider_Release(IServiceProvider *iface)
381 {
382     return 1;
383 }
384
385 static HRESULT WINAPI ServiceProvider_QueryService(IServiceProvider *iface, REFGUID guidService,
386         REFIID riid, void **ppv)
387 {
388     if(IsEqualGUID(&IID_IHttpNegotiate, guidService) || IsEqualGUID(&IID_IHttpNegotiate2, riid)) {
389         CHECK_EXPECT2(QueryService_HttpNegotiate);
390         return IHttpNegotiate2_QueryInterface(&http_negotiate, riid, ppv);
391     }
392
393     if(IsEqualGUID(&IID_IInternetProtocol, guidService)) {
394         ok(IsEqualGUID(&IID_IInternetProtocol, riid), "unexpected riid\n");
395         CHECK_EXPECT(QueryService_InternetProtocol);
396         return E_NOINTERFACE;
397     }
398
399     if(IsEqualGUID(&IID_IHttpSecurity, guidService)) {
400         ok(IsEqualGUID(&IID_IHttpSecurity, riid), "unexpected riid\n");
401         CHECK_EXPECT(QueryService_HttpSecurity);
402         return IHttpSecurity_QueryInterface(&http_security, riid, ppv);
403     }
404
405     ok(0, "unexpected service %s\n", debugstr_guid(guidService));
406     return E_FAIL;
407 }
408
409 static const IServiceProviderVtbl ServiceProviderVtbl = {
410     ServiceProvider_QueryInterface,
411     ServiceProvider_AddRef,
412     ServiceProvider_Release,
413     ServiceProvider_QueryService
414 };
415
416 static IServiceProvider service_provider = { &ServiceProviderVtbl };
417
418 static HRESULT WINAPI ProtocolSink_QueryInterface(IInternetProtocolSink *iface, REFIID riid, void **ppv)
419 {
420     return QueryInterface(riid, ppv);
421 }
422
423 static ULONG WINAPI ProtocolSink_AddRef(IInternetProtocolSink *iface)
424 {
425     return 2;
426 }
427
428 static ULONG WINAPI ProtocolSink_Release(IInternetProtocolSink *iface)
429 {
430     return 1;
431 }
432
433 static void call_continue(PROTOCOLDATA *protocol_data)
434 {
435     HRESULT hres;
436
437     if(!state) {
438         if(tested_protocol == HTTP_TEST || tested_protocol == HTTPS_TEST)
439             CLEAR_CALLED(ReportProgress_COOKIE_SENT);
440         if(tested_protocol == HTTP_TEST || tested_protocol == HTTPS_TEST || tested_protocol == FTP_TEST) {
441             if (http_is_first) {
442                 CLEAR_CALLED(ReportProgress_FINDINGRESOURCE);
443                 CLEAR_CALLED(ReportProgress_CONNECTING);
444                 CLEAR_CALLED(ReportProgress_PROXYDETECTING);
445             }else if(test_redirect) {
446                 CHECK_CALLED(ReportProgress_FINDINGRESOURCE);
447             }else todo_wine {
448                 CHECK_NOT_CALLED(ReportProgress_FINDINGRESOURCE);
449                 /* IE7 does call this */
450                 CLEAR_CALLED(ReportProgress_CONNECTING);
451             }
452         }
453         if(tested_protocol == FTP_TEST)
454             todo_wine CHECK_CALLED(ReportProgress_SENDINGREQUEST);
455         else if (tested_protocol != HTTPS_TEST)
456             CHECK_CALLED(ReportProgress_SENDINGREQUEST);
457         if(test_redirect)
458             CHECK_CALLED(ReportProgress_REDIRECTING);
459         if(tested_protocol == HTTP_TEST || tested_protocol == HTTPS_TEST) {
460             SET_EXPECT(OnResponse);
461             if(tested_protocol == HTTPS_TEST || test_redirect)
462                 SET_EXPECT(ReportProgress_ACCEPTRANGES);
463             SET_EXPECT(ReportProgress_MIMETYPEAVAILABLE);
464             if(bindf & BINDF_NEEDFILE)
465                 SET_EXPECT(ReportProgress_CACHEFILENAMEAVAILABLE);
466         }
467     }
468
469     SET_EXPECT(ReportData);
470     hres = IInternetProtocol_Continue(async_protocol, protocol_data);
471     ok(hres == S_OK, "Continue failed: %08x\n", hres);
472     if(tested_protocol == FTP_TEST)
473         CLEAR_CALLED(ReportData);
474     else if (! security_problem)
475         CHECK_CALLED(ReportData);
476
477     if (!state) {
478         if (! security_problem)
479         {
480             state = 1;
481             if(tested_protocol == HTTP_TEST || tested_protocol == HTTPS_TEST) {
482                 CHECK_CALLED(OnResponse);
483                 if(tested_protocol == HTTPS_TEST)
484                     CHECK_CALLED(ReportProgress_ACCEPTRANGES);
485                 else if(test_redirect)
486                     CLEAR_CALLED(ReportProgress_ACCEPTRANGES);
487                 CHECK_CALLED(ReportProgress_MIMETYPEAVAILABLE);
488                 if(bindf & BINDF_NEEDFILE)
489                     CHECK_CALLED(ReportProgress_CACHEFILENAMEAVAILABLE);
490             }
491         }
492         else
493         {
494             security_problem = FALSE;
495             SET_EXPECT(ReportProgress_CONNECTING);
496         }
497     }
498 }
499
500 static HRESULT WINAPI ProtocolSink_Switch(IInternetProtocolSink *iface, PROTOCOLDATA *pProtocolData)
501 {
502     if(tested_protocol == FTP_TEST)
503         CHECK_EXPECT2(Switch);
504     else
505         CHECK_EXPECT(Switch);
506
507     ok(pProtocolData != NULL, "pProtocolData == NULL\n");
508     if(binding_test) {
509         ok(pProtocolData != &protocoldata, "pProtocolData == &protocoldata\n");
510         ok(pProtocolData->grfFlags == protocoldata.grfFlags, "grfFlags wrong %x/%x\n",
511            pProtocolData->grfFlags, protocoldata.grfFlags );
512         ok(pProtocolData->dwState == protocoldata.dwState, "dwState wrong %x/%x\n",
513            pProtocolData->dwState, protocoldata.dwState );
514         ok(pProtocolData->pData == protocoldata.pData, "pData wrong %p/%p\n",
515            pProtocolData->pData, protocoldata.pData );
516         ok(pProtocolData->cbData == protocoldata.cbData, "cbData wrong %x/%x\n",
517            pProtocolData->cbData, protocoldata.cbData );
518     }
519
520     pdata = pProtocolData;
521
522     if(binding_test) {
523         SetEvent(event_complete);
524         WaitForSingleObject(event_complete2, INFINITE);
525         return S_OK;
526     }if(direct_read) {
527         continue_protdata = *pProtocolData;
528         SetEvent(event_continue);
529         WaitForSingleObject(event_continue_done, INFINITE);
530     }else {
531         call_continue(pProtocolData);
532         SetEvent(event_complete);
533     }
534
535     return S_OK;
536 }
537
538 static HRESULT WINAPI ProtocolSink_ReportProgress(IInternetProtocolSink *iface, ULONG ulStatusCode,
539         LPCWSTR szStatusText)
540 {
541     static const WCHAR null_guid[] = {'{','0','0','0','0','0','0','0','0','-','0','0','0','0','-',
542         '0','0','0','0','-','0','0','0','0','-','0','0','0','0','0','0','0','0','0','0','0','0','}',0};
543     static const WCHAR text_plain[] = {'t','e','x','t','/','p','l','a','i','n',0};
544
545     switch(ulStatusCode) {
546     case BINDSTATUS_MIMETYPEAVAILABLE:
547         CHECK_EXPECT(ReportProgress_MIMETYPEAVAILABLE);
548         if(tested_protocol != FILE_TEST && !mimefilter_test && (pi & PI_MIMEVERIFICATION)) {
549             if(!short_read || !direct_read)
550                 CHECK_CALLED(Read); /* set in Continue */
551             else if(short_read)
552                 CHECK_CALLED(Read2); /* set in Read */
553         }
554         ok(szStatusText != NULL, "szStatusText == NULL\n");
555         if(szStatusText) {
556             if(tested_protocol == BIND_TEST)
557                 ok(szStatusText == expect_wsz, "unexpected szStatusText\n");
558             else if (http_post_test)
559                 ok(lstrlenW(text_plain) <= lstrlenW(szStatusText) &&
560                    !memcmp(szStatusText, text_plain, lstrlenW(text_plain)*sizeof(WCHAR)),
561                    "szStatusText != text/plain\n");
562             else if(!mimefilter_test)
563                 ok(lstrlenW(text_htmlW) <= lstrlenW(szStatusText) &&
564                    !memcmp(szStatusText, text_htmlW, lstrlenW(text_htmlW)*sizeof(WCHAR)),
565                    "szStatusText != text/html\n");
566         }
567         break;
568     case BINDSTATUS_DIRECTBIND:
569         CHECK_EXPECT2(ReportProgress_DIRECTBIND);
570         ok(szStatusText == NULL, "szStatusText != NULL\n");
571         break;
572     case BINDSTATUS_RAWMIMETYPE:
573         CHECK_EXPECT2(ReportProgress_RAWMIMETYPE);
574         ok(szStatusText != NULL, "szStatusText == NULL\n");
575         if(szStatusText)
576             ok(lstrlenW(szStatusText) < lstrlenW(text_htmlW) ||
577                !memcmp(szStatusText, text_htmlW, lstrlenW(text_htmlW)*sizeof(WCHAR)),
578                "szStatusText != text/html\n");
579         break;
580     case BINDSTATUS_CACHEFILENAMEAVAILABLE:
581         CHECK_EXPECT(ReportProgress_CACHEFILENAMEAVAILABLE);
582         ok(szStatusText != NULL, "szStatusText == NULL\n");
583         if(szStatusText) {
584             if(binding_test)
585                 ok(!strcmp_ww(szStatusText, expect_wsz), "unexpected szStatusText\n");
586             else if(tested_protocol == FILE_TEST)
587                 ok(!strcmp_ww(szStatusText, file_name), "szStatusText = %s\n", wine_dbgstr_w(szStatusText));
588             else
589                 ok(szStatusText != NULL, "szStatusText == NULL\n");
590         }
591         break;
592     case BINDSTATUS_FINDINGRESOURCE:
593         CHECK_EXPECT2(ReportProgress_FINDINGRESOURCE);
594         ok(szStatusText != NULL, "szStatusText == NULL\n");
595         break;
596     case BINDSTATUS_CONNECTING:
597         CHECK_EXPECT2(ReportProgress_CONNECTING);
598         ok(szStatusText != NULL, "szStatusText == NULL\n");
599         break;
600     case BINDSTATUS_SENDINGREQUEST:
601         CHECK_EXPECT2(ReportProgress_SENDINGREQUEST);
602         if(tested_protocol == FILE_TEST) {
603             ok(szStatusText != NULL, "szStatusText == NULL\n");
604             if(szStatusText)
605                 ok(!*szStatusText, "wrong szStatusText\n");
606         }
607         break;
608     case BINDSTATUS_VERIFIEDMIMETYPEAVAILABLE:
609         CHECK_EXPECT(ReportProgress_VERIFIEDMIMETYPEAVAILABLE);
610         ok(szStatusText != NULL, "szStatusText == NULL\n");
611         if(szStatusText)
612             ok(!strcmp_ww(szStatusText, text_htmlW), "szStatusText != text/html\n");
613         break;
614     case BINDSTATUS_PROTOCOLCLASSID:
615         CHECK_EXPECT(ReportProgress_PROTOCOLCLASSID);
616         ok(szStatusText != NULL, "szStatusText == NULL\n");
617         ok(!strcmp_ww(szStatusText, null_guid), "unexpected classid %s\n", wine_dbgstr_w(szStatusText));
618         break;
619     case BINDSTATUS_COOKIE_SENT:
620         CHECK_EXPECT(ReportProgress_COOKIE_SENT);
621         ok(szStatusText == NULL, "szStatusText != NULL\n");
622         break;
623     case BINDSTATUS_REDIRECTING:
624         CHECK_EXPECT(ReportProgress_REDIRECTING);
625         if(test_redirect)
626             ok(!strcmp_wa(szStatusText, "http://test.winehq.org/hello.html"), "szStatusText = %s\n", wine_dbgstr_w(szStatusText));
627         else
628             ok(szStatusText == NULL, "szStatusText = %s\n", wine_dbgstr_w(szStatusText));
629         break;
630     case BINDSTATUS_ENCODING:
631         CHECK_EXPECT(ReportProgress_ENCODING);
632         ok(!strcmp_wa(szStatusText, "gzip"), "szStatusText = %s\n", wine_dbgstr_w(szStatusText));
633         break;
634     case BINDSTATUS_ACCEPTRANGES:
635         CHECK_EXPECT(ReportProgress_ACCEPTRANGES);
636         ok(!szStatusText, "szStatusText = %s\n", wine_dbgstr_w(szStatusText));
637         break;
638     case BINDSTATUS_PROXYDETECTING:
639         CHECK_EXPECT(ReportProgress_PROXYDETECTING);
640         SET_EXPECT(ReportProgress_CONNECTING);
641         ok(!szStatusText, "szStatusText = %s\n", wine_dbgstr_w(szStatusText));
642         break;
643     case BINDSTATUS_LOADINGMIMEHANDLER:
644         CHECK_EXPECT(ReportProgress_LOADINGMIMEHANDLER);
645         ok(!szStatusText, "szStatusText = %s\n", wine_dbgstr_w(szStatusText));
646         break;
647     case BINDSTATUS_DECODING:
648         CHECK_EXPECT(ReportProgress_DECODING);
649         ok(!strcmp_ww(szStatusText, gzipW), "szStatusText = %s\n", wine_dbgstr_w(szStatusText));
650         break;
651     default:
652         ok(0, "Unexpected status %d\n", ulStatusCode);
653     };
654
655     return S_OK;
656 }
657
658 static HRESULT WINAPI ProtocolSink_ReportData(IInternetProtocolSink *iface, DWORD grfBSCF,
659         ULONG ulProgress, ULONG ulProgressMax)
660 {
661     HRESULT hres;
662
663     static int rec_depth;
664     rec_depth++;
665
666     if(!mimefilter_test && tested_protocol == FILE_TEST) {
667         CHECK_EXPECT2(ReportData);
668
669         ok(ulProgress == ulProgressMax, "ulProgress (%d) != ulProgressMax (%d)\n",
670            ulProgress, ulProgressMax);
671         ok(ulProgressMax == 13, "ulProgressMax=%d, expected 13\n", ulProgressMax);
672         /* BSCF_SKIPDRAINDATAFORFILEURLS added in IE8 */
673         ok((grfBSCF == (BSCF_FIRSTDATANOTIFICATION | BSCF_LASTDATANOTIFICATION)) ||
674            (grfBSCF == (BSCF_FIRSTDATANOTIFICATION | BSCF_LASTDATANOTIFICATION | BSCF_SKIPDRAINDATAFORFILEURLS)),
675                 "grcfBSCF = %08x\n", grfBSCF);
676     }else if(direct_read) {
677         BYTE buf[14096];
678         ULONG read;
679
680         if(!read_report_data && rec_depth == 1) {
681             BOOL reported_all_data = called_ReportData2;
682
683             CHECK_EXPECT2(ReportData);
684
685             if(short_read) {
686                 ok(grfBSCF == (BSCF_FIRSTDATANOTIFICATION|BSCF_LASTDATANOTIFICATION|BSCF_DATAFULLYAVAILABLE)
687                    || grfBSCF == BSCF_FIRSTDATANOTIFICATION, /* < IE8 */
688                    "grcfBSCF = %08x\n", grfBSCF);
689                 CHECK_CALLED(Read); /* Set in Continue */
690                 first_data_notif = FALSE;
691             }else if(first_data_notif) {
692                 ok(grfBSCF == BSCF_FIRSTDATANOTIFICATION, "grcfBSCF = %08x\n", grfBSCF);
693                 first_data_notif = FALSE;
694             }else if(reported_all_data) {
695                 ok(grfBSCF == (BSCF_LASTDATANOTIFICATION|BSCF_INTERMEDIATEDATANOTIFICATION),
696                    "grcfBSCF = %08x\n", grfBSCF);
697             }else if(!direct_read) {
698                 ok(grfBSCF == BSCF_INTERMEDIATEDATANOTIFICATION, "grcfBSCF = %08x\n", grfBSCF);
699             }
700
701             do {
702                 read = 0;
703                 if(emulate_prot)
704                     SET_EXPECT(Read);
705                 else
706                     SET_EXPECT(ReportData2);
707                 SET_EXPECT(ReportResult);
708                 hres = IInternetProtocol_Read(binding_test ? binding_protocol : async_protocol, expect_pv = buf, sizeof(buf), &read);
709                 if(hres == S_OK)
710                     ok(read, "read == 0\n");
711                 if(reported_all_data) {
712                     ok(hres == S_FALSE, "Read failed: %08x, expected S_FALSE\n", hres);
713                 }
714                 if(emulate_prot)
715                     CHECK_CALLED(Read);
716                 if(!reported_all_data && called_ReportData2) {
717                     if(!emulate_prot)
718                         CHECK_CALLED(ReportData2);
719                     CHECK_CALLED(ReportResult);
720                     ok(hres == S_OK, "Read failed: %08x\n", hres);
721                     reported_all_data = TRUE;
722                 }else {
723                     if(!emulate_prot)
724                         CHECK_NOT_CALLED(ReportData2);
725                     CHECK_NOT_CALLED(ReportResult);
726                 }
727             }while(hres == S_OK);
728             if(hres == S_FALSE)
729                 wait_for_switch = FALSE;
730         }else {
731             CHECK_EXPECT(ReportData2);
732
733             ok(grfBSCF & BSCF_LASTDATANOTIFICATION, "grfBSCF = %08x\n", grfBSCF);
734
735             read = 0xdeadbeef;
736             if(emulate_prot)
737                 SET_EXPECT(Read2);
738             hres = IInternetProtocol_Read(binding_test ? binding_protocol : async_protocol, expect_pv = buf, sizeof(buf), &read);
739             if(emulate_prot)
740                 CHECK_CALLED(Read2);
741             ok(hres == S_FALSE, "Read returned: %08x, expected E_FALSE\n", hres);
742             ok(!read, "read = %d\n", read);
743         }
744     }else if(!binding_test && (tested_protocol == HTTP_TEST || tested_protocol == HTTPS_TEST
745             || tested_protocol == FTP_TEST)) {
746         if(!(grfBSCF & BSCF_LASTDATANOTIFICATION) || (grfBSCF & BSCF_DATAFULLYAVAILABLE))
747             CHECK_EXPECT(ReportData);
748         else if (http_post_test)
749             ok(ulProgress == 13, "Read %u bytes instead of 13\n", ulProgress);
750
751         ok(ulProgress, "ulProgress == 0\n");
752
753         if(first_data_notif) {
754             ok(grfBSCF == BSCF_FIRSTDATANOTIFICATION
755                || grfBSCF == (BSCF_LASTDATANOTIFICATION|BSCF_DATAFULLYAVAILABLE),
756                "grcfBSCF = %08x\n", grfBSCF);
757             first_data_notif = FALSE;
758         } else {
759             ok(grfBSCF == BSCF_INTERMEDIATEDATANOTIFICATION
760                || grfBSCF == (BSCF_LASTDATANOTIFICATION|BSCF_INTERMEDIATEDATANOTIFICATION)
761                || broken(grfBSCF == (BSCF_FIRSTDATANOTIFICATION|BSCF_LASTDATANOTIFICATION)),
762                "grcfBSCF = %08x\n", grfBSCF);
763         }
764
765         if(!(bindf & BINDF_FROMURLMON) &&
766            !(grfBSCF & BSCF_LASTDATANOTIFICATION)) {
767             if(!state) {
768                 state = 1;
769                 if(http_is_first) {
770                     CHECK_CALLED(ReportProgress_FINDINGRESOURCE);
771                     CHECK_CALLED(ReportProgress_CONNECTING);
772                 } else todo_wine {
773                     CHECK_NOT_CALLED(ReportProgress_FINDINGRESOURCE);
774                     CHECK_NOT_CALLED(ReportProgress_CONNECTING);
775                 }
776                 CHECK_CALLED(ReportProgress_SENDINGREQUEST);
777                 CHECK_CALLED(OnResponse);
778                 CHECK_CALLED(ReportProgress_RAWMIMETYPE);
779             }
780             SetEvent(event_complete);
781         }
782     }else if(!read_report_data) {
783         BYTE buf[1000];
784         ULONG read;
785         HRESULT hres;
786
787         CHECK_EXPECT(ReportData);
788
789         if(tested_protocol != BIND_TEST) {
790             do {
791                 if(mimefilter_test)
792                     SET_EXPECT(MimeFilter_Read);
793                 else if(rec_depth > 1)
794                     SET_EXPECT(Read2);
795                 else
796                     SET_EXPECT(Read);
797                 hres = IInternetProtocol_Read(binding_protocol, expect_pv=buf, sizeof(buf), &read);
798                 if(mimefilter_test)
799                     CHECK_CALLED(MimeFilter_Read);
800                 else if(rec_depth > 1)
801                     CHECK_CALLED(Read2);
802                 else
803                     CHECK_CALLED(Read);
804             }while(hres == S_OK);
805         }
806     }
807
808     rec_depth--;
809     return S_OK;
810 }
811
812 static HRESULT WINAPI ProtocolSink_ReportResult(IInternetProtocolSink *iface, HRESULT hrResult,
813         DWORD dwError, LPCWSTR szResult)
814 {
815     CHECK_EXPECT(ReportResult);
816
817     if(tested_protocol == FTP_TEST)
818         ok(hrResult == E_PENDING || hrResult == S_OK, "hrResult = %08x, expected E_PENDING or S_OK\n", hrResult);
819     else
820         ok(hrResult == expect_hrResult, "hrResult = %08x, expected: %08x\n",
821            hrResult, expect_hrResult);
822     if(SUCCEEDED(hrResult) || tested_protocol == FTP_TEST)
823         ok(dwError == ERROR_SUCCESS, "dwError = %d, expected ERROR_SUCCESS\n", dwError);
824     else
825         ok(dwError != ERROR_SUCCESS ||
826            broken(tested_protocol == MK_TEST), /* Win9x, WinME and NT4 */
827            "dwError == ERROR_SUCCESS\n");
828     ok(!szResult, "szResult != NULL\n");
829
830     if(direct_read)
831         SET_EXPECT(ReportData); /* checked after main loop */
832
833     return S_OK;
834 }
835
836 static IInternetProtocolSinkVtbl protocol_sink_vtbl = {
837     ProtocolSink_QueryInterface,
838     ProtocolSink_AddRef,
839     ProtocolSink_Release,
840     ProtocolSink_Switch,
841     ProtocolSink_ReportProgress,
842     ProtocolSink_ReportData,
843     ProtocolSink_ReportResult
844 };
845
846 static IInternetProtocolSink protocol_sink = { &protocol_sink_vtbl };
847
848 static HRESULT WINAPI MimeProtocolSink_QueryInterface(IInternetProtocolSink *iface, REFIID riid, void **ppv)
849 {
850     ok(0, "unexpected call\n");
851     return E_NOTIMPL;
852 }
853
854 static ULONG WINAPI MimeProtocolSink_AddRef(IInternetProtocolSink *iface)
855 {
856     return 2;
857 }
858
859 static ULONG WINAPI MimeProtocolSink_Release(IInternetProtocolSink *iface)
860 {
861     return 1;
862 }
863
864 static HRESULT WINAPI MimeProtocolSink_Switch(IInternetProtocolSink *iface, PROTOCOLDATA *pProtocolData)
865 {
866     HRESULT hres;
867
868     CHECK_EXPECT(MimeFilter_Switch);
869
870     SET_EXPECT(Switch);
871     hres = IInternetProtocolSink_Switch(filtered_sink, pProtocolData);
872     ok(hres == S_OK, "Switch failed: %08x\n", hres);
873     CHECK_CALLED(Switch);
874
875     return S_OK;
876 }
877
878 static HRESULT WINAPI MimeProtocolSink_ReportProgress(IInternetProtocolSink *iface, ULONG ulStatusCode,
879         LPCWSTR szStatusText)
880 {
881     CHECK_EXPECT(MimeFilter_ReportProgress);
882     return S_OK;
883 }
884
885 static HRESULT WINAPI MimeProtocolSink_ReportData(IInternetProtocolSink *iface, DWORD grfBSCF,
886         ULONG ulProgress, ULONG ulProgressMax)
887 {
888     DWORD read = 0;
889     BYTE buf[8192];
890     HRESULT hres;
891
892     CHECK_EXPECT(MimeFilter_ReportData);
893
894     if(!filter_state) {
895         SET_EXPECT(Read);
896         hres = IInternetProtocol_Read(filtered_protocol, buf, sizeof(buf), &read);
897         if(tested_protocol == HTTP_TEST)
898             ok(hres == S_OK || hres == E_PENDING || hres == S_FALSE, "Read failed: %08x\n", hres);
899         else
900             ok(hres == S_OK, "Read failed: %08x\n", hres);
901         CHECK_CALLED(Read);
902
903         SET_EXPECT(ReportProgress_MIMETYPEAVAILABLE);
904         hres = IInternetProtocolSink_ReportProgress(filtered_sink, BINDSTATUS_VERIFIEDMIMETYPEAVAILABLE, text_htmlW);
905         ok(hres == S_OK, "ReportProgress failed: %08x\n", hres);
906         CHECK_CALLED(ReportProgress_MIMETYPEAVAILABLE);
907
908         /* FIXME: test BINDSTATUS_CACHEFILENAMEAVAILABLE */
909     }
910
911     if(!read_report_data)
912         SET_EXPECT(ReportData);
913     hres = IInternetProtocolSink_ReportData(filtered_sink, grfBSCF, ulProgress, ulProgressMax);
914     ok(hres == S_OK, "ReportData failed: %08x\n", hres);
915     if(!read_report_data)
916         CHECK_CALLED(ReportData);
917
918     if(!filter_state)
919         filter_state = 1;
920
921     return S_OK;
922 }
923
924 static HRESULT WINAPI MimeProtocolSink_ReportResult(IInternetProtocolSink *iface, HRESULT hrResult,
925         DWORD dwError, LPCWSTR szResult)
926 {
927     HRESULT hres;
928
929     CHECK_EXPECT(MimeFilter_ReportResult);
930
931     ok(hrResult == S_OK, "hrResult = %08x\n", hrResult);
932     ok(dwError == ERROR_SUCCESS, "dwError = %u\n", dwError);
933     ok(!szResult, "szResult = %s\n", wine_dbgstr_w(szResult));
934
935     SET_EXPECT(ReportResult);
936     hres = IInternetProtocolSink_ReportResult(filtered_sink, hrResult, dwError, szResult);
937     ok(SUCCEEDED(hres), "ReportResult failed: %08x\n", hres);
938     CHECK_CALLED(ReportResult);
939
940     return S_OK;
941 }
942
943 static IInternetProtocolSinkVtbl mime_protocol_sink_vtbl = {
944     MimeProtocolSink_QueryInterface,
945     MimeProtocolSink_AddRef,
946     MimeProtocolSink_Release,
947     MimeProtocolSink_Switch,
948     MimeProtocolSink_ReportProgress,
949     MimeProtocolSink_ReportData,
950     MimeProtocolSink_ReportResult
951 };
952
953 static IInternetProtocolSink mime_protocol_sink = { &mime_protocol_sink_vtbl };
954
955 static HRESULT QueryInterface(REFIID riid, void **ppv)
956 {
957     static const IID IID_undocumented = {0x58DFC7D0,0x5381,0x43E5,{0x9D,0x72,0x4C,0xDD,0xE4,0xCB,0x0F,0x1A}};
958
959     *ppv = NULL;
960
961     if(IsEqualGUID(&IID_IUnknown, riid) || IsEqualGUID(&IID_IInternetProtocolSink, riid))
962         *ppv = &protocol_sink;
963     if(IsEqualGUID(&IID_IServiceProvider, riid))
964         *ppv = &service_provider;
965     if(IsEqualGUID(&IID_IUriContainer, riid))
966         return E_NOINTERFACE; /* TODO */
967
968     /* NOTE: IE8 queries for undocumented {58DFC7D0-5381-43E5-9D72-4CDDE4CB0F1A} interface. */
969     if(IsEqualGUID(&IID_undocumented, riid))
970         return E_NOINTERFACE;
971
972     if(*ppv)
973         return S_OK;
974
975     ok(0, "unexpected call %s\n", debugstr_guid(riid));
976     return E_NOINTERFACE;
977 }
978
979 static HRESULT WINAPI BindInfo_QueryInterface(IInternetBindInfo *iface, REFIID riid, void **ppv)
980 {
981     if(IsEqualGUID(&IID_IUnknown, riid) || IsEqualGUID(&IID_IInternetBindInfo, riid)) {
982         *ppv = iface;
983         return S_OK;
984     }
985     return E_NOINTERFACE;
986 }
987
988 static ULONG WINAPI BindInfo_AddRef(IInternetBindInfo *iface)
989 {
990     return 2;
991 }
992
993 static ULONG WINAPI BindInfo_Release(IInternetBindInfo *iface)
994 {
995     return 1;
996 }
997
998 static HRESULT WINAPI BindInfo_GetBindInfo(IInternetBindInfo *iface, DWORD *grfBINDF, BINDINFO *pbindinfo)
999 {
1000     DWORD cbSize;
1001
1002     static const CHAR szPostData[] = "mode=Test";
1003
1004     CHECK_EXPECT(GetBindInfo);
1005
1006     ok(grfBINDF != NULL, "grfBINDF == NULL\n");
1007     ok(pbindinfo != NULL, "pbindinfo == NULL\n");
1008     ok(pbindinfo->cbSize == sizeof(BINDINFO), "wrong size of pbindinfo: %d\n", pbindinfo->cbSize);
1009
1010     *grfBINDF = bindf;
1011     if(binding_test)
1012         *grfBINDF |= BINDF_FROMURLMON;
1013     cbSize = pbindinfo->cbSize;
1014     memset(pbindinfo, 0, cbSize);
1015     pbindinfo->cbSize = cbSize;
1016
1017     if (http_post_test)
1018     {
1019         /* Must be GMEM_FIXED, GMEM_MOVABLE does not work properly
1020          * with urlmon on native (Win98 and WinXP) */
1021         U(pbindinfo->stgmedData).hGlobal = GlobalAlloc(GPTR, sizeof(szPostData));
1022         if (!U(pbindinfo->stgmedData).hGlobal)
1023         {
1024             http_post_test = FALSE;
1025             skip("Out of memory\n");
1026             return E_OUTOFMEMORY;
1027         }
1028         lstrcpy((LPSTR)U(pbindinfo->stgmedData).hGlobal, szPostData);
1029         pbindinfo->cbstgmedData = sizeof(szPostData)-1;
1030         pbindinfo->dwBindVerb = BINDVERB_POST;
1031         pbindinfo->stgmedData.tymed = TYMED_HGLOBAL;
1032     }
1033
1034     return S_OK;
1035 }
1036
1037 static HRESULT WINAPI BindInfo_GetBindString(IInternetBindInfo *iface, ULONG ulStringType,
1038         LPOLESTR *ppwzStr, ULONG cEl, ULONG *pcElFetched)
1039 {
1040     ok(ppwzStr != NULL, "ppwzStr == NULL\n");
1041     ok(pcElFetched != NULL, "pcElFetched == NULL\n");
1042
1043     switch(ulStringType) {
1044     case BINDSTRING_ACCEPT_MIMES:
1045         CHECK_EXPECT(GetBindString_ACCEPT_MIMES);
1046         ok(cEl == 256, "cEl=%d, expected 256\n", cEl);
1047         if(pcElFetched) {
1048             ok(*pcElFetched == 256, "*pcElFetched=%d, expected 256\n", *pcElFetched);
1049             *pcElFetched = 1;
1050         }
1051         if(ppwzStr) {
1052             *ppwzStr = CoTaskMemAlloc(sizeof(acc_mimeW));
1053             memcpy(*ppwzStr, acc_mimeW, sizeof(acc_mimeW));
1054         }
1055         return S_OK;
1056     case BINDSTRING_USER_AGENT:
1057         CHECK_EXPECT(GetBindString_USER_AGENT);
1058         ok(cEl == 1, "cEl=%d, expected 1\n", cEl);
1059         if(pcElFetched) {
1060             ok(*pcElFetched == 0, "*pcElFetch=%d, expectd 0\n", *pcElFetched);
1061             *pcElFetched = 1;
1062         }
1063         if(ppwzStr) {
1064             *ppwzStr = CoTaskMemAlloc(sizeof(user_agentW));
1065             memcpy(*ppwzStr, user_agentW, sizeof(user_agentW));
1066         }
1067         return S_OK;
1068     case BINDSTRING_POST_COOKIE:
1069         CHECK_EXPECT(GetBindString_POST_COOKIE);
1070         ok(cEl == 1, "cEl=%d, expected 1\n", cEl);
1071         if(pcElFetched)
1072             ok(*pcElFetched == 0, "*pcElFetch=%d, expectd 0\n", *pcElFetched);
1073         return S_OK;
1074     case BINDSTRING_URL: {
1075         DWORD size;
1076
1077         CHECK_EXPECT(GetBindString_URL);
1078         ok(cEl == 1, "cEl=%d, expected 1\n", cEl);
1079         ok(*pcElFetched == 0, "*pcElFetch=%d, expectd 0\n", *pcElFetched);
1080         *pcElFetched = 1;
1081
1082         size = (lstrlenW(binding_urls[tested_protocol])+1)*sizeof(WCHAR);
1083         *ppwzStr = CoTaskMemAlloc(size);
1084         memcpy(*ppwzStr, binding_urls[tested_protocol], size);
1085         return S_OK;
1086     }
1087     default:
1088         ok(0, "unexpected call\n");
1089     }
1090
1091     return E_NOTIMPL;
1092 }
1093
1094 static IInternetBindInfoVtbl bind_info_vtbl = {
1095     BindInfo_QueryInterface,
1096     BindInfo_AddRef,
1097     BindInfo_Release,
1098     BindInfo_GetBindInfo,
1099     BindInfo_GetBindString
1100 };
1101
1102 static IInternetBindInfo bind_info = { &bind_info_vtbl };
1103
1104 static HRESULT WINAPI InternetPriority_QueryInterface(IInternetPriority *iface,
1105                                                   REFIID riid, void **ppv)
1106 {
1107     ok(0, "unexpected call\n");
1108     return E_NOINTERFACE;
1109 }
1110
1111 static ULONG WINAPI InternetPriority_AddRef(IInternetPriority *iface)
1112 {
1113     return 2;
1114 }
1115
1116 static ULONG WINAPI InternetPriority_Release(IInternetPriority *iface)
1117 {
1118     return 1;
1119 }
1120
1121 static HRESULT WINAPI InternetPriority_SetPriority(IInternetPriority *iface, LONG nPriority)
1122 {
1123     CHECK_EXPECT(SetPriority);
1124     ok(nPriority == ex_priority, "nPriority=%d\n", nPriority);
1125     return S_OK;
1126 }
1127
1128 static HRESULT WINAPI InternetPriority_GetPriority(IInternetPriority *iface, LONG *pnPriority)
1129 {
1130     ok(0, "unexpected call\n");
1131     return E_NOTIMPL;
1132 }
1133
1134
1135 static const IInternetPriorityVtbl InternetPriorityVtbl = {
1136     InternetPriority_QueryInterface,
1137     InternetPriority_AddRef,
1138     InternetPriority_Release,
1139     InternetPriority_SetPriority,
1140     InternetPriority_GetPriority
1141 };
1142
1143 static IInternetPriority InternetPriority = { &InternetPriorityVtbl };
1144
1145 static ULONG WINAPI Protocol_AddRef(IInternetProtocol *iface)
1146 {
1147     return 2;
1148 }
1149
1150 static ULONG WINAPI Protocol_Release(IInternetProtocol *iface)
1151 {
1152     return 1;
1153 }
1154
1155 static HRESULT WINAPI Protocol_Abort(IInternetProtocol *iface, HRESULT hrReason,
1156         DWORD dwOptions)
1157 {
1158     ok(0, "unexpected call\n");
1159     return E_NOTIMPL;
1160 }
1161
1162 static HRESULT WINAPI Protocol_Suspend(IInternetProtocol *iface)
1163 {
1164     ok(0, "unexpected call\n");
1165     return E_NOTIMPL;
1166 }
1167
1168 static HRESULT WINAPI Protocol_Resume(IInternetProtocol *iface)
1169 {
1170     ok(0, "unexpected call\n");
1171     return E_NOTIMPL;
1172 }
1173
1174 static HRESULT WINAPI Protocol_Seek(IInternetProtocol *iface,
1175         LARGE_INTEGER dlibMove, DWORD dwOrigin, ULARGE_INTEGER *plibNewPosition)
1176 {
1177     ok(0, "unexpected call\n");
1178     return E_NOTIMPL;
1179 }
1180
1181 static HRESULT WINAPI ProtocolEmul_QueryInterface(IInternetProtocol *iface, REFIID riid, void **ppv)
1182 {
1183     if(IsEqualGUID(&IID_IUnknown, riid) || IsEqualGUID(&IID_IInternetProtocol, riid)) {
1184         *ppv = iface;
1185         return S_OK;
1186     }
1187
1188     if(IsEqualGUID(&IID_IInternetProtocolEx, riid)) {
1189         trace("IID_IInternetProtocolEx not supported\n");
1190         *ppv = NULL;
1191         return E_NOINTERFACE;
1192     }
1193
1194     if(IsEqualGUID(&IID_IInternetPriority, riid)) {
1195         *ppv = &InternetPriority;
1196         return S_OK;
1197     }
1198
1199     if(IsEqualGUID(&IID_IWinInetInfo, riid)) {
1200         CHECK_EXPECT(QueryInterface_IWinInetInfo);
1201         *ppv = NULL;
1202         return E_NOINTERFACE;
1203     }
1204
1205     if(IsEqualGUID(&IID_IWinInetHttpInfo, riid)) {
1206         CHECK_EXPECT(QueryInterface_IWinInetHttpInfo);
1207         *ppv = NULL;
1208         return E_NOINTERFACE;
1209     }
1210
1211     ok(0, "unexpected riid %s\n", debugstr_guid(riid));
1212     *ppv = NULL;
1213     return E_NOINTERFACE;
1214 }
1215
1216 static DWORD WINAPI thread_proc(PVOID arg)
1217 {
1218     HRESULT hres;
1219
1220     memset(&protocoldata, -1, sizeof(protocoldata));
1221
1222     prot_state = 0;
1223
1224     SET_EXPECT(ReportProgress_FINDINGRESOURCE);
1225     hres = IInternetProtocolSink_ReportProgress(binding_sink,
1226             BINDSTATUS_FINDINGRESOURCE, hostW);
1227     CHECK_CALLED(ReportProgress_FINDINGRESOURCE);
1228     ok(hres == S_OK, "ReportProgress failed: %08x\n", hres);
1229
1230     SET_EXPECT(ReportProgress_CONNECTING);
1231     hres = IInternetProtocolSink_ReportProgress(binding_sink,
1232             BINDSTATUS_CONNECTING, winehq_ipW);
1233     CHECK_CALLED(ReportProgress_CONNECTING);
1234     ok(hres == S_OK, "ReportProgress failed: %08x\n", hres);
1235
1236     SET_EXPECT(ReportProgress_SENDINGREQUEST);
1237     hres = IInternetProtocolSink_ReportProgress(binding_sink,
1238             BINDSTATUS_SENDINGREQUEST, NULL);
1239     CHECK_CALLED(ReportProgress_SENDINGREQUEST);
1240     ok(hres == S_OK, "ReportProgress failed: %08x\n", hres);
1241
1242     prot_state = 1;
1243     SET_EXPECT(Switch);
1244     hres = IInternetProtocolSink_Switch(binding_sink, &protocoldata);
1245     CHECK_CALLED(Switch);
1246     ok(hres == S_OK, "Switch failed: %08x\n", hres);
1247
1248     if(!short_read) {
1249         prot_state = 2;
1250         if(mimefilter_test)
1251             SET_EXPECT(MimeFilter_Switch);
1252         else
1253             SET_EXPECT(Switch);
1254         hres = IInternetProtocolSink_Switch(binding_sink, &protocoldata);
1255         ok(hres == S_OK, "Switch failed: %08x\n", hres);
1256         if(mimefilter_test)
1257             CHECK_CALLED(MimeFilter_Switch);
1258         else
1259             CHECK_CALLED(Switch);
1260
1261         prot_state = 2;
1262         if(mimefilter_test)
1263             SET_EXPECT(MimeFilter_Switch);
1264         else
1265             SET_EXPECT(Switch);
1266         hres = IInternetProtocolSink_Switch(binding_sink, &protocoldata);
1267         ok(hres == S_OK, "Switch failed: %08x\n", hres);
1268         if(mimefilter_test)
1269             CHECK_CALLED(MimeFilter_Switch);
1270         else
1271             CHECK_CALLED(Switch);
1272
1273         prot_state = 3;
1274         if(mimefilter_test)
1275             SET_EXPECT(MimeFilter_Switch);
1276         else
1277             SET_EXPECT(Switch);
1278         hres = IInternetProtocolSink_Switch(binding_sink, &protocoldata);
1279         ok(hres == S_OK, "Switch failed: %08x\n", hres);
1280         if(mimefilter_test)
1281             CHECK_CALLED(MimeFilter_Switch);
1282         else
1283             CHECK_CALLED(Switch);
1284     }
1285
1286     SetEvent(event_complete);
1287
1288     return 0;
1289 }
1290
1291 static HRESULT WINAPI ProtocolEmul_Start(IInternetProtocol *iface, LPCWSTR szUrl,
1292         IInternetProtocolSink *pOIProtSink, IInternetBindInfo *pOIBindInfo,
1293         DWORD grfPI, HANDLE_PTR dwReserved)
1294 {
1295     BINDINFO bindinfo, exp_bindinfo;
1296     DWORD cbindf = 0;
1297     HRESULT hres;
1298
1299     CHECK_EXPECT(Start);
1300
1301     ok(pOIProtSink != NULL, "pOIProtSink == NULL\n");
1302     ok(pOIBindInfo != NULL, "pOIBindInfo == NULL\n");
1303     ok(pOIProtSink != &protocol_sink, "unexpected pOIProtSink\n");
1304     ok(pOIBindInfo != &bind_info, "unexpected pOIBindInfo\n");
1305     ok(!grfPI, "grfPI = %x\n", grfPI);
1306     ok(!dwReserved, "dwReserved = %lx\n", dwReserved);
1307
1308     if(binding_test)
1309         ok(pOIProtSink == binding_sink, "pOIProtSink != binding_sink\n");
1310
1311     memset(&bindinfo, 0, sizeof(bindinfo));
1312     bindinfo.cbSize = sizeof(bindinfo);
1313     memcpy(&exp_bindinfo, &bindinfo, sizeof(bindinfo));
1314     SET_EXPECT(GetBindInfo);
1315     hres = IInternetBindInfo_GetBindInfo(pOIBindInfo, &cbindf, &bindinfo);
1316     ok(hres == S_OK, "GetBindInfo failed: %08x\n", hres);
1317     CHECK_CALLED(GetBindInfo);
1318     ok(cbindf == (bindf|BINDF_FROMURLMON), "bindf = %x, expected %x\n",
1319        cbindf, (bindf|BINDF_FROMURLMON));
1320     ok(!memcmp(&exp_bindinfo, &bindinfo, sizeof(bindinfo)), "unexpected bindinfo\n");
1321     ReleaseBindInfo(&bindinfo);
1322
1323     SET_EXPECT(ReportProgress_SENDINGREQUEST);
1324     hres = IInternetProtocolSink_ReportProgress(pOIProtSink, BINDSTATUS_SENDINGREQUEST, emptyW);
1325     ok(hres == S_OK, "ReportProgress(BINDSTATUS_SENDINGREQUEST) failed: %08x\n", hres);
1326     CHECK_CALLED(ReportProgress_SENDINGREQUEST);
1327
1328     if(tested_protocol == HTTP_TEST || tested_protocol == HTTPS_TEST) {
1329         IServiceProvider *service_provider;
1330         IHttpNegotiate *http_negotiate;
1331         IHttpNegotiate2 *http_negotiate2;
1332         LPWSTR ua = (LPWSTR)0xdeadbeef, accept_mimes[256];
1333         LPWSTR additional_headers = NULL;
1334         BYTE sec_id[100];
1335         DWORD fetched = 0, size = 100;
1336         DWORD tid;
1337
1338         SET_EXPECT(GetBindString_USER_AGENT);
1339         hres = IInternetBindInfo_GetBindString(pOIBindInfo, BINDSTRING_USER_AGENT,
1340                                                &ua, 1, &fetched);
1341         CHECK_CALLED(GetBindString_USER_AGENT);
1342         ok(hres == S_OK, "GetBindString(BINDSTRING_USER_AGETNT) failed: %08x\n", hres);
1343         ok(fetched == 1, "fetched = %d, expected 254\n", fetched);
1344         ok(ua != NULL, "ua =  %p\n", ua);
1345         ok(!strcmp_ww(ua, user_agentW), "unexpected user agent %s\n", wine_dbgstr_w(ua));
1346         CoTaskMemFree(ua);
1347
1348         fetched = 256;
1349         SET_EXPECT(GetBindString_ACCEPT_MIMES);
1350         hres = IInternetBindInfo_GetBindString(pOIBindInfo, BINDSTRING_ACCEPT_MIMES,
1351                                                accept_mimes, 256, &fetched);
1352         CHECK_CALLED(GetBindString_ACCEPT_MIMES);
1353
1354         ok(hres == S_OK,
1355            "GetBindString(BINDSTRING_ACCEPT_MIMES) failed: %08x\n", hres);
1356         ok(fetched == 1, "fetched = %d, expected 1\n", fetched);
1357         ok(!strcmp_ww(acc_mimeW, accept_mimes[0]), "unexpected mimes %s\n", wine_dbgstr_w(accept_mimes[0]));
1358
1359         hres = IInternetBindInfo_QueryInterface(pOIBindInfo, &IID_IServiceProvider,
1360                                                 (void**)&service_provider);
1361         ok(hres == S_OK, "QueryInterface failed: %08x\n", hres);
1362
1363         SET_EXPECT(QueryService_HttpNegotiate);
1364         hres = IServiceProvider_QueryService(service_provider, &IID_IHttpNegotiate,
1365                 &IID_IHttpNegotiate, (void**)&http_negotiate);
1366         CHECK_CALLED(QueryService_HttpNegotiate);
1367         ok(hres == S_OK, "QueryService failed: %08x\n", hres);
1368
1369         SET_EXPECT(BeginningTransaction);
1370         hres = IHttpNegotiate_BeginningTransaction(http_negotiate, binding_urls[tested_protocol],
1371                                                    NULL, 0, &additional_headers);
1372         CHECK_CALLED(BeginningTransaction);
1373         IHttpNegotiate_Release(http_negotiate);
1374         ok(hres == S_OK, "BeginningTransction failed: %08x\n", hres);
1375         ok(additional_headers == NULL, "additional_headers=%p\n", additional_headers);
1376
1377         SET_EXPECT(QueryService_HttpNegotiate);
1378         hres = IServiceProvider_QueryService(service_provider, &IID_IHttpNegotiate2,
1379                 &IID_IHttpNegotiate2, (void**)&http_negotiate2);
1380         CHECK_CALLED(QueryService_HttpNegotiate);
1381         ok(hres == S_OK, "QueryService failed: %08x\n", hres);
1382
1383         size = 512;
1384         SET_EXPECT(GetRootSecurityId);
1385         hres = IHttpNegotiate2_GetRootSecurityId(http_negotiate2, sec_id, &size, 0);
1386         CHECK_CALLED(GetRootSecurityId);
1387         IHttpNegotiate2_Release(http_negotiate2);
1388         ok(hres == E_FAIL, "GetRootSecurityId failed: %08x, expected E_FAIL\n", hres);
1389         ok(size == 13, "size=%d\n", size);
1390
1391         IServiceProvider_Release(service_provider);
1392
1393         CreateThread(NULL, 0, thread_proc, NULL, 0, &tid);
1394
1395         return S_OK;
1396     }
1397
1398     SET_EXPECT(ReportProgress_CACHEFILENAMEAVAILABLE);
1399     hres = IInternetProtocolSink_ReportProgress(pOIProtSink,
1400             BINDSTATUS_CACHEFILENAMEAVAILABLE, expect_wsz = emptyW);
1401     ok(hres == S_OK, "ReportProgress(BINDSTATUS_CACHEFILENAMEAVAILABLE) failed: %08x\n", hres);
1402     CHECK_CALLED(ReportProgress_CACHEFILENAMEAVAILABLE);
1403
1404     if(mimefilter_test) {
1405         SET_EXPECT(MimeFilter_CreateInstance);
1406         SET_EXPECT(MimeFilter_Start);
1407         SET_EXPECT(ReportProgress_LOADINGMIMEHANDLER);
1408     }
1409     SET_EXPECT(ReportProgress_MIMETYPEAVAILABLE);
1410     hres = IInternetProtocolSink_ReportProgress(pOIProtSink, BINDSTATUS_VERIFIEDMIMETYPEAVAILABLE,
1411             mimefilter_test ? gzipW : (expect_wsz = text_htmlW));
1412     ok(hres == S_OK,
1413        "ReportProgress(BINDSTATUS_VERIFIEDMIMETYPEAVAILABLE) failed: %08x\n", hres);
1414     if(mimefilter_test) {
1415         CHECK_CALLED(MimeFilter_CreateInstance);
1416         CHECK_CALLED(MimeFilter_Start);
1417         CHECK_CALLED(ReportProgress_LOADINGMIMEHANDLER);
1418         todo_wine CHECK_CALLED(ReportProgress_MIMETYPEAVAILABLE);
1419     }else {
1420         CHECK_CALLED(ReportProgress_MIMETYPEAVAILABLE);
1421     }
1422
1423     if(mimefilter_test)
1424         SET_EXPECT(MimeFilter_ReportData);
1425     else
1426         SET_EXPECT(ReportData);
1427     hres = IInternetProtocolSink_ReportData(pOIProtSink,
1428             BSCF_FIRSTDATANOTIFICATION | BSCF_LASTDATANOTIFICATION, 13, 13);
1429     ok(hres == S_OK, "ReportData failed: %08x\n", hres);
1430     if(mimefilter_test)
1431         CHECK_CALLED(MimeFilter_ReportData);
1432     else
1433         CHECK_CALLED(ReportData);
1434
1435     if(tested_protocol == BIND_TEST) {
1436         hres = IInternetProtocol_Terminate(binding_protocol, 0);
1437         ok(hres == E_FAIL, "Termiante failed: %08x\n", hres);
1438     }
1439
1440     if(mimefilter_test)
1441         SET_EXPECT(MimeFilter_ReportResult);
1442     else
1443         SET_EXPECT(ReportResult);
1444     hres = IInternetProtocolSink_ReportResult(pOIProtSink, S_OK, 0, NULL);
1445     ok(hres == S_OK, "ReportResult failed: %08x\n", hres);
1446     if(mimefilter_test)
1447         CHECK_CALLED(MimeFilter_ReportResult);
1448     else
1449         CHECK_CALLED(ReportResult);
1450
1451     return S_OK;
1452 }
1453
1454 static HRESULT WINAPI ProtocolEmul_Continue(IInternetProtocol *iface,
1455         PROTOCOLDATA *pProtocolData)
1456 {
1457     DWORD bscf = 0, pr;
1458     HRESULT hres;
1459
1460     CHECK_EXPECT(Continue);
1461
1462     ok(pProtocolData != NULL, "pProtocolData == NULL\n");
1463     if(!pProtocolData || tested_protocol == BIND_TEST)
1464         return S_OK;
1465     if(binding_test) {
1466         ok(pProtocolData != &protocoldata, "pProtocolData == &protocoldata\n");
1467         ok(pProtocolData->grfFlags == protocoldata.grfFlags, "grfFlags wrong %x/%x\n",
1468            pProtocolData->grfFlags, protocoldata.grfFlags );
1469         ok(pProtocolData->dwState == protocoldata.dwState, "dwState wrong %x/%x\n",
1470            pProtocolData->dwState, protocoldata.dwState );
1471         ok(pProtocolData->pData == protocoldata.pData, "pData wrong %p/%p\n",
1472            pProtocolData->pData, protocoldata.pData );
1473         ok(pProtocolData->cbData == protocoldata.cbData, "cbData wrong %x/%x\n",
1474            pProtocolData->cbData, protocoldata.cbData );
1475     }
1476
1477     switch(prot_state) {
1478     case 1: {
1479         IServiceProvider *service_provider;
1480         IHttpNegotiate *http_negotiate;
1481         static WCHAR header[] = {'?',0};
1482
1483         hres = IInternetProtocolSink_QueryInterface(binding_sink, &IID_IServiceProvider,
1484                                                     (void**)&service_provider);
1485         ok(hres == S_OK, "Could not get IServiceProvicder\n");
1486
1487         SET_EXPECT(QueryService_HttpNegotiate);
1488         hres = IServiceProvider_QueryService(service_provider, &IID_IHttpNegotiate,
1489                                              &IID_IHttpNegotiate, (void**)&http_negotiate);
1490         IServiceProvider_Release(service_provider);
1491         CHECK_CALLED(QueryService_HttpNegotiate);
1492         ok(hres == S_OK, "Could not get IHttpNegotiate\n");
1493
1494         SET_EXPECT(OnResponse);
1495         hres = IHttpNegotiate_OnResponse(http_negotiate, 200, header, NULL, NULL);
1496         IHttpNegotiate_Release(http_negotiate);
1497         CHECK_CALLED(OnResponse);
1498         IHttpNegotiate_Release(http_negotiate);
1499         ok(hres == S_OK, "OnResponse failed: %08x\n", hres);
1500
1501         if(mimefilter_test) {
1502             SET_EXPECT(MimeFilter_CreateInstance);
1503             SET_EXPECT(MimeFilter_Start);
1504             SET_EXPECT(ReportProgress_LOADINGMIMEHANDLER);
1505         }else if(!(pi & PI_MIMEVERIFICATION)) {
1506             SET_EXPECT(ReportProgress_MIMETYPEAVAILABLE);
1507         }
1508         hres = IInternetProtocolSink_ReportProgress(binding_sink,
1509                 BINDSTATUS_MIMETYPEAVAILABLE, mimefilter_test ? gzipW : text_htmlW);
1510         if(mimefilter_test) {
1511             CHECK_CALLED(MimeFilter_CreateInstance);
1512             CHECK_CALLED(MimeFilter_Start);
1513             CHECK_CALLED(ReportProgress_LOADINGMIMEHANDLER);
1514         }else if(!(pi & PI_MIMEVERIFICATION)) {
1515             CHECK_CALLED(ReportProgress_MIMETYPEAVAILABLE);
1516         }
1517         ok(hres == S_OK,
1518            "ReportProgress(BINDSTATUS_MIMETYPEAVAILABLE) failed: %08x\n", hres);
1519
1520         bscf |= BSCF_FIRSTDATANOTIFICATION;
1521         break;
1522     }
1523     case 2:
1524     case 3:
1525         bscf = BSCF_INTERMEDIATEDATANOTIFICATION;
1526         break;
1527     }
1528
1529     pr = prot_read;
1530     if(mimefilter_test) {
1531         SET_EXPECT(MimeFilter_ReportData);
1532     }else if(pi & PI_MIMEVERIFICATION) {
1533         if(pr < 200)
1534             SET_EXPECT(Read); /* checked in ReportData for short_read */
1535         if(pr == 200) {
1536             if(!mimefilter_test)
1537                 SET_EXPECT(Read); /* checked in BINDSTATUS_MIMETYPEAVAILABLE or ReportData */
1538             SET_EXPECT(ReportProgress_MIMETYPEAVAILABLE);
1539         }
1540         if(pr >= 200)
1541             SET_EXPECT(ReportData);
1542     }else {
1543         SET_EXPECT(ReportData);
1544     }
1545
1546     hres = IInternetProtocolSink_ReportData(binding_sink, bscf, pr, 400);
1547     ok(hres == S_OK, "ReportData failed: %08x\n", hres);
1548
1549     if(mimefilter_test) {
1550         SET_EXPECT(MimeFilter_ReportData);
1551     }else if(pi & PI_MIMEVERIFICATION) {
1552         if(!short_read && pr < 200)
1553             CHECK_CALLED(Read);
1554         if(pr == 200) {
1555             CHECK_CALLED(ReportProgress_MIMETYPEAVAILABLE);
1556         }
1557     }else {
1558         CHECK_CALLED(ReportData);
1559     }
1560
1561     if(prot_state == 3)
1562         prot_state = 4;
1563
1564     return S_OK;
1565 }
1566
1567 static HRESULT WINAPI ProtocolEmul_Terminate(IInternetProtocol *iface, DWORD dwOptions)
1568 {
1569     CHECK_EXPECT(Terminate);
1570     ok(!dwOptions, "dwOptions=%d\n", dwOptions);
1571     return S_OK;
1572 }
1573
1574 static HRESULT WINAPI ProtocolEmul_Read(IInternetProtocol *iface, void *pv,
1575         ULONG cb, ULONG *pcbRead)
1576 {
1577     if(read_report_data)
1578         CHECK_EXPECT2(Read2);
1579
1580     if(mimefilter_test || short_read) {
1581         if(!read_report_data)
1582             CHECK_EXPECT2(Read);
1583     }else if((pi & PI_MIMEVERIFICATION)) {
1584         if(!read_report_data)
1585             CHECK_EXPECT2(Read);
1586
1587         if(prot_read < 300) {
1588             ok(pv != expect_pv, "pv == expect_pv\n");
1589             if(prot_read < 300)
1590                 ok(cb == 2048-prot_read, "cb=%d\n", cb);
1591             else
1592                 ok(cb == 700, "cb=%d\n", cb);
1593         }else {
1594             ok(expect_pv <= pv && (BYTE*)pv < (BYTE*)expect_pv + cb, "pv != expect_pv\n");
1595         }
1596     }else {
1597         if(!read_report_data)
1598             CHECK_EXPECT(Read);
1599
1600         ok(pv == expect_pv, "pv != expect_pv\n");
1601         ok(cb == 1000, "cb=%d\n", cb);
1602         ok(!*pcbRead, "*pcbRead = %d\n", *pcbRead);
1603     }
1604     ok(pcbRead != NULL, "pcbRead == NULL\n");
1605
1606     if(prot_state == 3 || (short_read && prot_state != 4)) {
1607         HRESULT hres;
1608
1609         prot_state = 4;
1610         if(short_read) {
1611             SET_EXPECT(Read2); /* checked in BINDSTATUS_MIMETYPEAVAILABLE */
1612             SET_EXPECT(ReportProgress_MIMETYPEAVAILABLE);
1613         }
1614         if(mimefilter_test)
1615             SET_EXPECT(MimeFilter_ReportData);
1616         else if(direct_read)
1617             SET_EXPECT(ReportData2);
1618         read_report_data++;
1619         hres = IInternetProtocolSink_ReportData(binding_sink,
1620                 BSCF_LASTDATANOTIFICATION|BSCF_INTERMEDIATEDATANOTIFICATION, 0, 0);
1621         read_report_data--;
1622         ok(hres == S_OK, "ReportData failed: %08x\n", hres);
1623         if(short_read)
1624             CHECK_CALLED(ReportProgress_MIMETYPEAVAILABLE);
1625         if(mimefilter_test)
1626             CHECK_CALLED(MimeFilter_ReportData);
1627         else if(direct_read)
1628             CHECK_CALLED(ReportData2);
1629
1630         if(mimefilter_test)
1631             SET_EXPECT(MimeFilter_ReportResult);
1632         else
1633             SET_EXPECT(ReportResult);
1634         hres = IInternetProtocolSink_ReportResult(binding_sink, S_OK, ERROR_SUCCESS, NULL);
1635         ok(hres == S_OK, "ReportResult failed: %08x\n", hres);
1636         if(mimefilter_test)
1637             CHECK_CALLED(MimeFilter_ReportResult);
1638         else
1639             CHECK_CALLED(ReportResult);
1640
1641         memset(pv, 'x', 100);
1642         prot_read += *pcbRead = 100;
1643         return S_OK;
1644     }if(prot_state == 4) {
1645         *pcbRead = 0;
1646         return S_FALSE;
1647     }
1648
1649     if((async_read_pending = !async_read_pending)) {
1650         *pcbRead = 0;
1651         return tested_protocol == HTTP_TEST || tested_protocol == HTTPS_TEST ? E_PENDING : S_FALSE;
1652     }
1653
1654     memset(pv, 'x', 100);
1655     prot_read += *pcbRead = 100;
1656     return S_OK;
1657 }
1658
1659 static HRESULT WINAPI ProtocolEmul_LockRequest(IInternetProtocol *iface, DWORD dwOptions)
1660 {
1661     CHECK_EXPECT(LockRequest);
1662     ok(dwOptions == 0, "dwOptions=%x\n", dwOptions);
1663     return S_OK;
1664 }
1665
1666 static HRESULT WINAPI ProtocolEmul_UnlockRequest(IInternetProtocol *iface)
1667 {
1668     CHECK_EXPECT(UnlockRequest);
1669     return S_OK;
1670 }
1671
1672 static const IInternetProtocolVtbl ProtocolVtbl = {
1673     ProtocolEmul_QueryInterface,
1674     Protocol_AddRef,
1675     Protocol_Release,
1676     ProtocolEmul_Start,
1677     ProtocolEmul_Continue,
1678     Protocol_Abort,
1679     ProtocolEmul_Terminate,
1680     Protocol_Suspend,
1681     Protocol_Resume,
1682     ProtocolEmul_Read,
1683     Protocol_Seek,
1684     ProtocolEmul_LockRequest,
1685     ProtocolEmul_UnlockRequest
1686 };
1687
1688 static IInternetProtocol Protocol = { &ProtocolVtbl };
1689
1690 static HRESULT WINAPI MimeProtocol_QueryInterface(IInternetProtocol *iface, REFIID riid, void **ppv)
1691 {
1692     if(IsEqualGUID(&IID_IUnknown, riid) || IsEqualGUID(&IID_IInternetProtocol, riid)) {
1693         *ppv = iface;
1694         return S_OK;
1695     }
1696
1697     if(IsEqualGUID(&IID_IInternetProtocolSink, riid)) {
1698         *ppv = &mime_protocol_sink;
1699         return S_OK;
1700     }
1701
1702     ok(0, "unexpected riid %s\n", debugstr_guid(riid));
1703     *ppv = NULL;
1704     return E_NOINTERFACE;
1705 }
1706
1707 static HRESULT WINAPI MimeProtocol_Start(IInternetProtocol *iface, LPCWSTR szUrl,
1708         IInternetProtocolSink *pOIProtSink, IInternetBindInfo *pOIBindInfo,
1709         DWORD grfPI, HANDLE_PTR dwReserved)
1710 {
1711     PROTOCOLFILTERDATA *data;
1712     LPOLESTR url_str = NULL;
1713     DWORD fetched = 0;
1714     BINDINFO bindinfo;
1715     DWORD cbindf = 0;
1716     HRESULT hres;
1717
1718     CHECK_EXPECT(MimeFilter_Start);
1719
1720     ok(!strcmp_ww(szUrl, gzipW), "wrong url %s\n", wine_dbgstr_w(szUrl));
1721     ok(grfPI == (PI_FILTER_MODE|PI_FORCE_ASYNC), "grfPI=%x, expected PI_FILTER_MODE|PI_FORCE_ASYNC\n", grfPI);
1722     ok(dwReserved, "dwReserved == 0\n");
1723     ok(pOIProtSink != NULL, "pOIProtSink == NULL\n");
1724     ok(pOIBindInfo != NULL, "pOIBindInfo == NULL\n");
1725
1726     if(binding_test) {
1727         ok(pOIProtSink != binding_sink, "pOIProtSink == protocol_sink\n");
1728         ok(pOIBindInfo == prot_bind_info, "pOIBindInfo != bind_info\n");
1729     }else {
1730         ok(pOIProtSink == &protocol_sink, "pOIProtSink != protocol_sink\n");
1731         ok(pOIBindInfo == &bind_info, "pOIBindInfo != bind_info\n");
1732     }
1733
1734     data = (void*)dwReserved;
1735     ok(data->cbSize == sizeof(*data), "data->cbSize = %d\n", data->cbSize);
1736     ok(!data->pProtocolSink, "data->pProtocolSink != NULL\n");
1737     ok(data->pProtocol != NULL, "data->pProtocol == NULL\n");
1738     ok(!data->pUnk, "data->pUnk != NULL\n");
1739     ok(!data->dwFilterFlags, "data->dwProtocolFlags = %x\n", data->dwFilterFlags);
1740     if(binding_test) {
1741         IInternetProtocolSink *prot_sink;
1742
1743         IInternetProtocol_QueryInterface(data->pProtocol, &IID_IInternetProtocolSink, (void**)&prot_sink);
1744         ok(prot_sink == pOIProtSink, "QI(data->pProtocol, IID_IInternetProtocolSink) != pOIProtSink\n");
1745         IInternetProtocolSink_Release(prot_sink);
1746
1747         ok(data->pProtocol != binding_protocol, "data->pProtocol == binding_protocol\n");
1748
1749         filtered_protocol = data->pProtocol;
1750         IInternetProtocol_AddRef(filtered_protocol);
1751     }else {
1752         IInternetProtocol *prot;
1753
1754         IInternetProtocol_QueryInterface(data->pProtocol, &IID_IInternetProtocol, (void**)&prot);
1755         ok(prot == async_protocol, "QI(data->pProtocol, IID_IInternetProtocol) != async_protocol\n");
1756         IInternetProtocol_Release(prot);
1757
1758         ok(data->pProtocol != async_protocol, "data->pProtocol == async_protocol\n");
1759     }
1760
1761     filtered_sink = pOIProtSink;
1762
1763     SET_EXPECT(ReportProgress_DECODING);
1764     hres = IInternetProtocolSink_ReportProgress(pOIProtSink, BINDSTATUS_DECODING, gzipW);
1765     ok(hres == S_OK, "ReportProgress(BINDSTATUS_DECODING) failed: %08x\n", hres);
1766     CHECK_CALLED(ReportProgress_DECODING);
1767
1768     SET_EXPECT(GetBindInfo);
1769     memset(&bindinfo, 0, sizeof(bindinfo));
1770     bindinfo.cbSize = sizeof(bindinfo);
1771     hres = IInternetBindInfo_GetBindInfo(pOIBindInfo, &cbindf, &bindinfo);
1772     ok(hres == S_OK, "GetBindInfo failed: %08x\n", hres);
1773     ok(cbindf == (bindf|BINDF_FROMURLMON), "cbindf = %x, expected %x\n", cbindf, bindf);
1774     CHECK_CALLED(GetBindInfo);
1775
1776     SET_EXPECT(GetBindString_URL);
1777     hres = IInternetBindInfo_GetBindString(pOIBindInfo, BINDSTRING_URL, &url_str, 1, &fetched);
1778     ok(hres == S_OK, "GetBindString(BINDSTRING_URL) failed: %08x\n", hres);
1779     ok(fetched == 1, "fetched = %d\n", fetched);
1780     ok(!strcmp_ww(url_str, binding_urls[tested_protocol]), "wrong url_str %s\n", wine_dbgstr_w(url_str));
1781     CoTaskMemFree(url_str);
1782     CHECK_CALLED(GetBindString_URL);
1783
1784     return S_OK;
1785 }
1786
1787 static HRESULT WINAPI Protocol_Continue(IInternetProtocol *iface,
1788         PROTOCOLDATA *pProtocolData)
1789 {
1790     CHECK_EXPECT(MimeFilter_Continue);
1791     return E_NOTIMPL;
1792 }
1793
1794 static HRESULT WINAPI MimeProtocol_Terminate(IInternetProtocol *iface, DWORD dwOptions)
1795 {
1796     HRESULT hres;
1797
1798     CHECK_EXPECT(MimeFilter_Terminate);
1799
1800     ok(!dwOptions, "dwOptions = %x\n", dwOptions);
1801
1802     SET_EXPECT(Terminate);
1803     hres = IInternetProtocol_Terminate(filtered_protocol, dwOptions);
1804     ok(hres == S_OK, "Terminate failed: %08x\n", hres);
1805     CHECK_CALLED(Terminate);
1806
1807     return S_OK;
1808 }
1809
1810 static HRESULT WINAPI MimeProtocol_Read(IInternetProtocol *iface, void *pv,
1811         ULONG cb, ULONG *pcbRead)
1812 {
1813     BYTE buf[2096];
1814     DWORD read = 0;
1815     HRESULT hres;
1816
1817     CHECK_EXPECT(MimeFilter_Read);
1818
1819     ok(pv != NULL, "pv == NULL\n");
1820     ok(cb != 0, "cb == 0\n");
1821     ok(pcbRead != NULL, "pcbRead == NULL\n");
1822
1823     if(read_report_data)
1824         SET_EXPECT(Read2);
1825     else
1826         SET_EXPECT(Read);
1827     hres = IInternetProtocol_Read(filtered_protocol, buf, sizeof(buf), &read);
1828     ok(hres == S_OK || hres == S_FALSE || hres == E_PENDING, "Read failed: %08x\n", hres);
1829     if(read_report_data)
1830         CHECK_CALLED(Read2);
1831     else
1832         CHECK_CALLED(Read);
1833
1834     if(pcbRead) {
1835         ok(*pcbRead == 0, "*pcbRead=%d, expected 0\n", *pcbRead);
1836         *pcbRead = read;
1837     }
1838
1839     memset(pv, 'x', read);
1840     return hres;
1841 }
1842
1843 static HRESULT WINAPI MimeProtocol_LockRequest(IInternetProtocol *iface, DWORD dwOptions)
1844 {
1845     HRESULT hres;
1846
1847     CHECK_EXPECT(MimeFilter_LockRequest);
1848
1849     ok(!dwOptions, "dwOptions = %x\n", dwOptions);
1850
1851     SET_EXPECT(LockRequest);
1852     hres = IInternetProtocol_LockRequest(filtered_protocol, dwOptions);
1853     ok(hres == S_OK, "LockRequest failed: %08x\n", hres);
1854     CHECK_CALLED(LockRequest);
1855
1856     return S_OK;
1857 }
1858
1859 static HRESULT WINAPI MimeProtocol_UnlockRequest(IInternetProtocol *iface)
1860 {
1861     HRESULT hres;
1862
1863     CHECK_EXPECT(MimeFilter_UnlockRequest);
1864
1865     SET_EXPECT(UnlockRequest);
1866     hres = IInternetProtocol_UnlockRequest(filtered_protocol);
1867     ok(hres == S_OK, "UnlockRequest failed: %08x\n", hres);
1868     CHECK_CALLED(UnlockRequest);
1869
1870     return S_OK;
1871 }
1872
1873 static const IInternetProtocolVtbl MimeProtocolVtbl = {
1874     MimeProtocol_QueryInterface,
1875     Protocol_AddRef,
1876     Protocol_Release,
1877     MimeProtocol_Start,
1878     Protocol_Continue,
1879     Protocol_Abort,
1880     MimeProtocol_Terminate,
1881     Protocol_Suspend,
1882     Protocol_Resume,
1883     MimeProtocol_Read,
1884     Protocol_Seek,
1885     MimeProtocol_LockRequest,
1886     MimeProtocol_UnlockRequest
1887 };
1888
1889 static IInternetProtocol MimeProtocol = { &MimeProtocolVtbl };
1890
1891 static HRESULT WINAPI ClassFactory_QueryInterface(IClassFactory *iface, REFIID riid, void **ppv)
1892 {
1893     ok(0, "unexpected call\n");
1894     return E_NOINTERFACE;
1895 }
1896
1897 static ULONG WINAPI ClassFactory_AddRef(IClassFactory *iface)
1898 {
1899     return 2;
1900 }
1901
1902 static ULONG WINAPI ClassFactory_Release(IClassFactory *iface)
1903 {
1904     return 1;
1905 }
1906
1907 static HRESULT WINAPI ClassFactory_CreateInstance(IClassFactory *iface, IUnknown *pOuter,
1908                                         REFIID riid, void **ppv)
1909 {
1910     CHECK_EXPECT(CreateInstance);
1911
1912     ok(pOuter == (IUnknown*)prot_bind_info, "pOuter != protocol_unk\n");
1913     ok(IsEqualGUID(&IID_IUnknown, riid), "unexpected riid %s\n", debugstr_guid(riid));
1914     ok(ppv != NULL, "ppv == NULL\n");
1915
1916     *ppv = &Protocol;
1917     return S_OK;
1918 }
1919
1920 static HRESULT WINAPI ClassFactory_LockServer(IClassFactory *iface, BOOL dolock)
1921 {
1922     ok(0, "unexpected call\n");
1923     return S_OK;
1924 }
1925
1926 static const IClassFactoryVtbl ClassFactoryVtbl = {
1927     ClassFactory_QueryInterface,
1928     ClassFactory_AddRef,
1929     ClassFactory_Release,
1930     ClassFactory_CreateInstance,
1931     ClassFactory_LockServer
1932 };
1933
1934 static IClassFactory ClassFactory = { &ClassFactoryVtbl };
1935
1936 static HRESULT WINAPI MimeFilter_CreateInstance(IClassFactory *iface, IUnknown *outer, REFIID riid, void **ppv)
1937 {
1938     CHECK_EXPECT(MimeFilter_CreateInstance);
1939
1940     ok(!outer, "outer = %p\n", outer);
1941     ok(IsEqualGUID(&IID_IInternetProtocol, riid), "unexpected riid %s\n", debugstr_guid(riid));
1942
1943     *ppv = &MimeProtocol;
1944     return S_OK;
1945 }
1946
1947 static const IClassFactoryVtbl MimeFilterCFVtbl = {
1948     ClassFactory_QueryInterface,
1949     ClassFactory_AddRef,
1950     ClassFactory_Release,
1951     MimeFilter_CreateInstance,
1952     ClassFactory_LockServer
1953 };
1954
1955 static IClassFactory mimefilter_cf = { &MimeFilterCFVtbl };
1956
1957 #define TEST_BINDING     0x01
1958 #define TEST_FILTER      0x02
1959 #define TEST_FIRST_HTTP  0x04
1960 #define TEST_DIRECT_READ 0x08
1961 #define TEST_POST        0x10
1962 #define TEST_EMULATEPROT 0x20
1963 #define TEST_SHORT_READ  0x40
1964 #define TEST_REDIRECT    0x80
1965
1966 static void init_test(int prot, DWORD flags)
1967 {
1968     tested_protocol = prot;
1969     binding_test = (flags & TEST_BINDING) != 0;
1970     first_data_notif = TRUE;
1971     prot_read = 0;
1972     prot_state = 0;
1973     async_read_pending = TRUE;
1974     mimefilter_test = (flags & TEST_FILTER) != 0;
1975     filter_state = 0;
1976     ResetEvent(event_complete);
1977     ResetEvent(event_complete2);
1978     ResetEvent(event_continue);
1979     ResetEvent(event_continue_done);
1980     async_protocol = binding_protocol = filtered_protocol = NULL;
1981     filtered_sink = NULL;
1982     http_is_first = (flags & TEST_FIRST_HTTP) != 0;
1983     first_data_notif = TRUE;
1984     state = 0;
1985     direct_read = (flags & TEST_DIRECT_READ) != 0;
1986     http_post_test = (flags & TEST_POST) != 0;
1987     emulate_prot = (flags & TEST_EMULATEPROT) != 0;
1988     wait_for_switch = TRUE;
1989     short_read = (flags & TEST_SHORT_READ) != 0;
1990     test_redirect = (flags & TEST_REDIRECT) != 0;
1991 }
1992
1993 static void test_priority(IInternetProtocol *protocol)
1994 {
1995     IInternetPriority *priority;
1996     LONG pr;
1997     HRESULT hres;
1998
1999     hres = IInternetProtocol_QueryInterface(protocol, &IID_IInternetPriority,
2000                                             (void**)&priority);
2001     ok(hres == S_OK, "QueryInterface(IID_IInternetPriority) failed: %08x\n", hres);
2002     if(FAILED(hres))
2003         return;
2004
2005     hres = IInternetPriority_GetPriority(priority, &pr);
2006     ok(hres == S_OK, "GetPriority failed: %08x\n", hres);
2007     ok(pr == 0, "pr=%d, expected 0\n", pr);
2008
2009     hres = IInternetPriority_SetPriority(priority, 1);
2010     ok(hres == S_OK, "SetPriority failed: %08x\n", hres);
2011
2012     hres = IInternetPriority_GetPriority(priority, &pr);
2013     ok(hres == S_OK, "GetPriority failed: %08x\n", hres);
2014     ok(pr == 1, "pr=%d, expected 1\n", pr);
2015
2016     IInternetPriority_Release(priority);
2017 }
2018
2019 static BOOL file_protocol_start(IInternetProtocol *protocol, LPCWSTR url, BOOL is_first)
2020 {
2021     HRESULT hres;
2022
2023     SET_EXPECT(GetBindInfo);
2024     if(!(bindf & BINDF_FROMURLMON))
2025        SET_EXPECT(ReportProgress_DIRECTBIND);
2026     if(is_first) {
2027         SET_EXPECT(ReportProgress_SENDINGREQUEST);
2028         SET_EXPECT(ReportProgress_CACHEFILENAMEAVAILABLE);
2029         if(bindf & BINDF_FROMURLMON)
2030             SET_EXPECT(ReportProgress_VERIFIEDMIMETYPEAVAILABLE);
2031         else
2032             SET_EXPECT(ReportProgress_MIMETYPEAVAILABLE);
2033     }
2034     SET_EXPECT(ReportData);
2035     if(is_first)
2036         SET_EXPECT(ReportResult);
2037
2038     expect_hrResult = S_OK;
2039
2040     hres = IInternetProtocol_Start(protocol, url, &protocol_sink, &bind_info, 0, 0);
2041     if(hres == INET_E_RESOURCE_NOT_FOUND) {
2042         win_skip("Start failed\n");
2043         return FALSE;
2044     }
2045     ok(hres == S_OK, "Start failed: %08x\n", hres);
2046
2047     CHECK_CALLED(GetBindInfo);
2048     if(!(bindf & BINDF_FROMURLMON))
2049        CHECK_CALLED(ReportProgress_DIRECTBIND);
2050     if(is_first) {
2051         CHECK_CALLED(ReportProgress_SENDINGREQUEST);
2052         CHECK_CALLED(ReportProgress_CACHEFILENAMEAVAILABLE);
2053         if(bindf & BINDF_FROMURLMON)
2054             CHECK_CALLED(ReportProgress_VERIFIEDMIMETYPEAVAILABLE);
2055         else
2056             CHECK_CALLED(ReportProgress_MIMETYPEAVAILABLE);
2057     }
2058     CHECK_CALLED(ReportData);
2059     if(is_first)
2060         CHECK_CALLED(ReportResult);
2061
2062     return TRUE;
2063 }
2064
2065 static void test_file_protocol_url(LPCWSTR url)
2066 {
2067     IInternetProtocolInfo *protocol_info;
2068     IUnknown *unk;
2069     IClassFactory *factory;
2070     HRESULT hres;
2071
2072     hres = CoGetClassObject(&CLSID_FileProtocol, CLSCTX_INPROC_SERVER, NULL,
2073             &IID_IUnknown, (void**)&unk);
2074     ok(hres == S_OK, "CoGetClassObject failed: %08x\n", hres);
2075     if(FAILED(hres))
2076         return;
2077
2078     hres = IUnknown_QueryInterface(unk, &IID_IInternetProtocolInfo, (void**)&protocol_info);
2079     ok(hres == E_NOINTERFACE,
2080             "Could not get IInternetProtocolInfo interface: %08x, expected E_NOINTERFACE\n", hres);
2081
2082     hres = IUnknown_QueryInterface(unk, &IID_IClassFactory, (void**)&factory);
2083     ok(hres == S_OK, "Could not get IClassFactory interface\n");
2084     if(SUCCEEDED(hres)) {
2085         IInternetProtocol *protocol;
2086         BYTE buf[512];
2087         ULONG cb;
2088         hres = IClassFactory_CreateInstance(factory, NULL, &IID_IInternetProtocol, (void**)&protocol);
2089         ok(hres == S_OK, "Could not get IInternetProtocol: %08x\n", hres);
2090
2091         if(SUCCEEDED(hres)) {
2092             if(file_protocol_start(protocol, url, TRUE)) {
2093                 hres = IInternetProtocol_Read(protocol, buf, 2, &cb);
2094                 ok(hres == S_OK, "Read failed: %08x\n", hres);
2095                 ok(cb == 2, "cb=%u expected 2\n", cb);
2096                 hres = IInternetProtocol_Read(protocol, buf, sizeof(buf), &cb);
2097                 ok(hres == S_FALSE, "Read failed: %08x\n", hres);
2098                 hres = IInternetProtocol_Read(protocol, buf, sizeof(buf), &cb);
2099                 ok(hres == S_FALSE, "Read failed: %08x expected S_FALSE\n", hres);
2100                 ok(cb == 0, "cb=%u expected 0\n", cb);
2101                 hres = IInternetProtocol_UnlockRequest(protocol);
2102                 ok(hres == S_OK, "UnlockRequest failed: %08x\n", hres);
2103             }
2104
2105             if(file_protocol_start(protocol, url, FALSE)) {
2106                 hres = IInternetProtocol_Read(protocol, buf, 2, &cb);
2107                 ok(hres == S_FALSE, "Read failed: %08x\n", hres);
2108                 hres = IInternetProtocol_LockRequest(protocol, 0);
2109                 ok(hres == S_OK, "LockRequest failed: %08x\n", hres);
2110                 hres = IInternetProtocol_UnlockRequest(protocol);
2111                 ok(hres == S_OK, "UnlockRequest failed: %08x\n", hres);
2112             }
2113
2114             IInternetProtocol_Release(protocol);
2115         }
2116
2117         hres = IClassFactory_CreateInstance(factory, NULL, &IID_IInternetProtocol, (void**)&protocol);
2118         ok(hres == S_OK, "Could not get IInternetProtocol: %08x\n", hres);
2119
2120         if(SUCCEEDED(hres)) {
2121             if(file_protocol_start(protocol, url, TRUE)) {
2122                 hres = IInternetProtocol_LockRequest(protocol, 0);
2123                 ok(hres == S_OK, "LockRequest failed: %08x\n", hres);
2124                 hres = IInternetProtocol_Terminate(protocol, 0);
2125                 ok(hres == S_OK, "Terminate failed: %08x\n", hres);
2126                 hres = IInternetProtocol_Read(protocol, buf, 2, &cb);
2127                 ok(hres == S_OK, "Read failed: %08x\n\n", hres);
2128                 hres = IInternetProtocol_UnlockRequest(protocol);
2129                 ok(hres == S_OK, "UnlockRequest failed: %08x\n", hres);
2130                 hres = IInternetProtocol_Read(protocol, buf, 2, &cb);
2131                 ok(hres == S_OK, "Read failed: %08x\n", hres);
2132                 hres = IInternetProtocol_Terminate(protocol, 0);
2133                 ok(hres == S_OK, "Terminate failed: %08x\n", hres);
2134             }
2135
2136             IInternetProtocol_Release(protocol);
2137         }
2138
2139         hres = IClassFactory_CreateInstance(factory, NULL, &IID_IInternetProtocol, (void**)&protocol);
2140         ok(hres == S_OK, "Could not get IInternetProtocol: %08x\n", hres);
2141
2142         if(SUCCEEDED(hres)) {
2143             if(file_protocol_start(protocol, url, TRUE)) {
2144                 hres = IInternetProtocol_Terminate(protocol, 0);
2145                 ok(hres == S_OK, "Terminate failed: %08x\n", hres);
2146                 hres = IInternetProtocol_Read(protocol, buf, 2, &cb);
2147                 ok(hres == S_OK, "Read failed: %08x\n", hres);
2148                 ok(cb == 2, "cb=%u expected 2\n", cb);
2149             }
2150
2151             IInternetProtocol_Release(protocol);
2152         }
2153
2154         IClassFactory_Release(factory);
2155     }
2156
2157     IUnknown_Release(unk);
2158 }
2159
2160 static void test_file_protocol_fail(void)
2161 {
2162     IInternetProtocol *protocol;
2163     HRESULT hres;
2164
2165     static const WCHAR index_url2[] =
2166         {'f','i','l','e',':','/','/','i','n','d','e','x','.','h','t','m','l',0};
2167
2168     hres = CoCreateInstance(&CLSID_FileProtocol, NULL, CLSCTX_INPROC_SERVER|CLSCTX_INPROC_HANDLER,
2169             &IID_IInternetProtocol, (void**)&protocol);
2170     ok(hres == S_OK, "CoCreateInstance failed: %08x\n", hres);
2171     if(FAILED(hres))
2172         return;
2173
2174     SET_EXPECT(GetBindInfo);
2175     expect_hrResult = MK_E_SYNTAX;
2176     hres = IInternetProtocol_Start(protocol, wszIndexHtml, &protocol_sink, &bind_info, 0, 0);
2177     ok(hres == MK_E_SYNTAX ||
2178        hres == E_INVALIDARG,
2179        "Start failed: %08x, expected MK_E_SYNTAX or E_INVALIDARG\n", hres);
2180     CLEAR_CALLED(GetBindInfo); /* GetBindInfo not called in IE7 */
2181
2182     SET_EXPECT(GetBindInfo);
2183     if(!(bindf & BINDF_FROMURLMON))
2184         SET_EXPECT(ReportProgress_DIRECTBIND);
2185     SET_EXPECT(ReportProgress_SENDINGREQUEST);
2186     SET_EXPECT(ReportResult);
2187     expect_hrResult = INET_E_RESOURCE_NOT_FOUND;
2188     hres = IInternetProtocol_Start(protocol, index_url, &protocol_sink, &bind_info, 0, 0);
2189     ok(hres == INET_E_RESOURCE_NOT_FOUND,
2190             "Start failed: %08x expected INET_E_RESOURCE_NOT_FOUND\n", hres);
2191     CHECK_CALLED(GetBindInfo);
2192     if(!(bindf & BINDF_FROMURLMON))
2193         CHECK_CALLED(ReportProgress_DIRECTBIND);
2194     CHECK_CALLED(ReportProgress_SENDINGREQUEST);
2195     CHECK_CALLED(ReportResult);
2196
2197     IInternetProtocol_Release(protocol);
2198
2199     hres = CoCreateInstance(&CLSID_FileProtocol, NULL, CLSCTX_INPROC_SERVER|CLSCTX_INPROC_HANDLER,
2200             &IID_IInternetProtocol, (void**)&protocol);
2201     ok(hres == S_OK, "CoCreateInstance failed: %08x\n", hres);
2202     if(FAILED(hres))
2203         return;
2204
2205     SET_EXPECT(GetBindInfo);
2206     if(!(bindf & BINDF_FROMURLMON))
2207         SET_EXPECT(ReportProgress_DIRECTBIND);
2208     SET_EXPECT(ReportProgress_SENDINGREQUEST);
2209     SET_EXPECT(ReportResult);
2210     expect_hrResult = INET_E_RESOURCE_NOT_FOUND;
2211
2212     hres = IInternetProtocol_Start(protocol, index_url2, &protocol_sink, &bind_info, 0, 0);
2213     ok(hres == INET_E_RESOURCE_NOT_FOUND,
2214             "Start failed: %08x, expected INET_E_RESOURCE_NOT_FOUND\n", hres);
2215     CHECK_CALLED(GetBindInfo);
2216     if(!(bindf & BINDF_FROMURLMON))
2217         CHECK_CALLED(ReportProgress_DIRECTBIND);
2218     CHECK_CALLED(ReportProgress_SENDINGREQUEST);
2219     CHECK_CALLED(ReportResult);
2220
2221     SET_EXPECT(GetBindInfo);
2222     hres = IInternetProtocol_Start(protocol, NULL, &protocol_sink, &bind_info, 0, 0);
2223     ok(hres == E_INVALIDARG, "Start failed: %08x, expected E_INVALIDARG\n", hres);
2224     CLEAR_CALLED(GetBindInfo); /* GetBindInfo not called in IE7 */
2225
2226     SET_EXPECT(GetBindInfo);
2227     hres = IInternetProtocol_Start(protocol, emptyW, &protocol_sink, &bind_info, 0, 0);
2228     ok(hres == E_INVALIDARG, "Start failed: %08x, expected E_INVALIDARG\n", hres);
2229     CLEAR_CALLED(GetBindInfo); /* GetBindInfo not called in IE7 */
2230
2231     IInternetProtocol_Release(protocol);
2232 }
2233
2234 static void test_file_protocol(void) {
2235     WCHAR buf[INTERNET_MAX_URL_LENGTH], file_name_buf[MAX_PATH];
2236     DWORD size;
2237     ULONG len;
2238     HANDLE file;
2239
2240     static const WCHAR wszFile[] = {'f','i','l','e',':',0};
2241     static const WCHAR wszFile2[] = {'f','i','l','e',':','/','/',0};
2242     static const WCHAR wszFile3[] = {'f','i','l','e',':','/','/','/',0};
2243     static const char html_doc[] = "<HTML></HTML>";
2244
2245     trace("Testing file protocol...\n");
2246     init_test(FILE_TEST, 0);
2247
2248     SetLastError(0xdeadbeef);
2249     file = CreateFileW(wszIndexHtml, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS,
2250             FILE_ATTRIBUTE_NORMAL, NULL);
2251     if(!file && GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)
2252     {
2253         win_skip("Detected Win9x or WinMe\n");
2254         return;
2255     }
2256     ok(file != INVALID_HANDLE_VALUE, "CreateFile failed\n");
2257     if(file == INVALID_HANDLE_VALUE)
2258         return;
2259     WriteFile(file, html_doc, sizeof(html_doc)-1, &size, NULL);
2260     CloseHandle(file);
2261
2262     file_name = wszIndexHtml;
2263     bindf = 0;
2264     test_file_protocol_url(index_url);
2265     bindf = BINDF_FROMURLMON;
2266     test_file_protocol_url(index_url);
2267     bindf = BINDF_FROMURLMON | BINDF_NEEDFILE;
2268     test_file_protocol_url(index_url);
2269
2270     memcpy(buf, wszFile, sizeof(wszFile));
2271     len = sizeof(wszFile)/sizeof(WCHAR)-1;
2272     len += GetCurrentDirectoryW(sizeof(buf)/sizeof(WCHAR)-len, buf+len);
2273     buf[len++] = '\\';
2274     memcpy(buf+len, wszIndexHtml, sizeof(wszIndexHtml));
2275
2276     file_name = buf + sizeof(wszFile)/sizeof(WCHAR)-1;
2277     bindf = 0;
2278     test_file_protocol_url(buf);
2279     bindf = BINDF_FROMURLMON;
2280     test_file_protocol_url(buf);
2281
2282     memcpy(buf, wszFile2, sizeof(wszFile2));
2283     len = GetCurrentDirectoryW(sizeof(file_name_buf)/sizeof(WCHAR), file_name_buf);
2284     file_name_buf[len++] = '\\';
2285     memcpy(file_name_buf+len, wszIndexHtml, sizeof(wszIndexHtml));
2286     lstrcpyW(buf+sizeof(wszFile2)/sizeof(WCHAR)-1, file_name_buf);
2287     file_name = file_name_buf;
2288     bindf = 0;
2289     test_file_protocol_url(buf);
2290     bindf = BINDF_FROMURLMON;
2291     test_file_protocol_url(buf);
2292
2293     buf[sizeof(wszFile2)/sizeof(WCHAR)] = '|';
2294     test_file_protocol_url(buf);
2295
2296     memcpy(buf, wszFile3, sizeof(wszFile3));
2297     len = sizeof(wszFile3)/sizeof(WCHAR)-1;
2298     len += GetCurrentDirectoryW(sizeof(buf)/sizeof(WCHAR)-len, buf+len);
2299     buf[len++] = '\\';
2300     memcpy(buf+len, wszIndexHtml, sizeof(wszIndexHtml));
2301
2302     file_name = buf + sizeof(wszFile3)/sizeof(WCHAR)-1;
2303     bindf = 0;
2304     test_file_protocol_url(buf);
2305     bindf = BINDF_FROMURLMON;
2306     test_file_protocol_url(buf);
2307
2308     DeleteFileW(wszIndexHtml);
2309
2310     bindf = 0;
2311     test_file_protocol_fail();
2312     bindf = BINDF_FROMURLMON;
2313     test_file_protocol_fail();
2314 }
2315
2316 static BOOL http_protocol_start(LPCWSTR url)
2317 {
2318     static BOOL got_user_agent = FALSE;
2319     HRESULT hres;
2320
2321     SET_EXPECT(GetBindInfo);
2322     if (!(bindf & BINDF_FROMURLMON))
2323         SET_EXPECT(ReportProgress_DIRECTBIND);
2324     if(!got_user_agent)
2325         SET_EXPECT(GetBindString_USER_AGENT);
2326     SET_EXPECT(GetBindString_ACCEPT_MIMES);
2327     SET_EXPECT(QueryService_HttpNegotiate);
2328     SET_EXPECT(BeginningTransaction);
2329     SET_EXPECT(GetRootSecurityId);
2330     if (http_post_test)
2331         SET_EXPECT(GetBindString_POST_COOKIE);
2332
2333     hres = IInternetProtocol_Start(async_protocol, url, &protocol_sink, &bind_info, 0, 0);
2334     ok(hres == S_OK, "Start failed: %08x\n", hres);
2335     if(FAILED(hres))
2336         return FALSE;
2337
2338     CHECK_CALLED(GetBindInfo);
2339     if (!(bindf & BINDF_FROMURLMON))
2340         CHECK_CALLED(ReportProgress_DIRECTBIND);
2341     if (!got_user_agent)
2342     {
2343         CHECK_CALLED(GetBindString_USER_AGENT);
2344         got_user_agent = TRUE;
2345     }
2346     CHECK_CALLED(GetBindString_ACCEPT_MIMES);
2347     CHECK_CALLED(QueryService_HttpNegotiate);
2348     CHECK_CALLED(BeginningTransaction);
2349     /* GetRootSecurityId called on WinXP but not on Win98 */
2350     CLEAR_CALLED(GetRootSecurityId);
2351     if (http_post_test)
2352         CHECK_CALLED(GetBindString_POST_COOKIE);
2353
2354     return TRUE;
2355 }
2356
2357 static void test_protocol_terminate(IInternetProtocol *protocol)
2358 {
2359     BYTE buf[3600];
2360     DWORD cb;
2361     HRESULT hres;
2362
2363     hres = IInternetProtocol_LockRequest(protocol, 0);
2364     ok(hres == S_OK, "LockRequest failed: %08x\n", hres);
2365
2366     hres = IInternetProtocol_Read(protocol, buf, 1, &cb);
2367     ok(hres == S_FALSE, "Read failed: %08x\n", hres);
2368
2369     hres = IInternetProtocol_Terminate(protocol, 0);
2370     ok(hres == S_OK, "Terminate failed: %08x\n", hres);
2371
2372     /* This wait is to give the internet handles being freed in Terminate
2373      * enough time to actually terminate in all cases. Internet handles
2374      * terminate asynchronously and native reuses the main InternetOpen
2375      * handle. The only case in which this seems to be necessary is on
2376      * wine with native wininet and urlmon, resulting in the next time
2377      * test_http_protocol_url being called the first data notification actually
2378      * being an extra last data notification from the previous connection
2379      * about once out of every ten times. */
2380     Sleep(100);
2381
2382     hres = IInternetProtocol_UnlockRequest(protocol);
2383     ok(hres == S_OK, "UnlockRequest failed: %08x\n", hres);
2384 }
2385
2386 static void test_http_info(IInternetProtocol *protocol)
2387 {
2388     IWinInetHttpInfo *info;
2389     HRESULT hres;
2390
2391     hres = IInternetProtocol_QueryInterface(protocol, &IID_IWinInetHttpInfo, (void**)&info);
2392     ok(hres == S_OK, "Could not get IWinInterHttpInfo iface: %08x\n", hres);
2393
2394     /* TODO */
2395
2396     IWinInetHttpInfo_Release(info);
2397 }
2398
2399 /* is_first refers to whether this is the first call to this function
2400  * _for this url_ */
2401 static void test_http_protocol_url(LPCWSTR url, int prot, DWORD flags)
2402 {
2403     IInternetProtocolInfo *protocol_info;
2404     IClassFactory *factory;
2405     IUnknown *unk;
2406     HRESULT hres;
2407
2408     init_test(prot, flags);
2409     http_url = url;
2410
2411     hres = CoGetClassObject(prot == HTTPS_TEST ? &CLSID_HttpSProtocol : &CLSID_HttpProtocol,
2412             CLSCTX_INPROC_SERVER, NULL, &IID_IUnknown, (void**)&unk);
2413     ok(hres == S_OK, "CoGetClassObject failed: %08x\n", hres);
2414     if(FAILED(hres))
2415         return;
2416
2417     hres = IUnknown_QueryInterface(unk, &IID_IInternetProtocolInfo, (void**)&protocol_info);
2418     ok(hres == E_NOINTERFACE,
2419         "Could not get IInternetProtocolInfo interface: %08x, expected E_NOINTERFACE\n",
2420         hres);
2421
2422     hres = IUnknown_QueryInterface(unk, &IID_IClassFactory, (void**)&factory);
2423     ok(hres == S_OK, "Could not get IClassFactory interface\n");
2424     IUnknown_Release(unk);
2425     if(FAILED(hres))
2426         return;
2427
2428     hres = IClassFactory_CreateInstance(factory, NULL, &IID_IInternetProtocol,
2429                                         (void**)&async_protocol);
2430     ok(hres == S_OK, "Could not get IInternetProtocol: %08x\n", hres);
2431     if(SUCCEEDED(hres)) {
2432         BYTE buf[3600];
2433         DWORD cb;
2434         ULONG ref;
2435
2436         test_priority(async_protocol);
2437         test_http_info(async_protocol);
2438
2439         SET_EXPECT(ReportProgress_COOKIE_SENT);
2440         SET_EXPECT(ReportProgress_FINDINGRESOURCE);
2441         SET_EXPECT(ReportProgress_CONNECTING);
2442         SET_EXPECT(ReportProgress_SENDINGREQUEST);
2443         if(test_redirect)
2444             SET_EXPECT(ReportProgress_REDIRECTING);
2445         SET_EXPECT(ReportProgress_PROXYDETECTING);
2446         if(prot == HTTP_TEST)
2447             SET_EXPECT(ReportProgress_CACHEFILENAMEAVAILABLE);
2448         else
2449             SET_EXPECT(QueryService_HttpSecurity);
2450         if(!(bindf & BINDF_FROMURLMON)) {
2451             SET_EXPECT(OnResponse);
2452             SET_EXPECT(ReportProgress_RAWMIMETYPE);
2453             SET_EXPECT(ReportData);
2454         } else {
2455             SET_EXPECT(Switch);
2456         }
2457
2458         if(!http_protocol_start(url))
2459             return;
2460
2461         if(!direct_read)
2462             SET_EXPECT(ReportResult);
2463         expect_hrResult = S_OK;
2464
2465         if(direct_read) {
2466             while(wait_for_switch) {
2467                 SET_EXPECT(Switch);
2468                 WaitForSingleObject(event_continue, INFINITE);
2469                 CHECK_CALLED(Switch);
2470                 call_continue(&continue_protdata);
2471                 SetEvent(event_continue_done);
2472             }
2473         }else {
2474             hres = IInternetProtocol_Read(async_protocol, buf, 1, &cb);
2475             ok((hres == E_PENDING && cb==0) ||
2476                (hres == S_OK && cb==1), "Read failed: %08x (%d bytes)\n", hres, cb);
2477
2478             WaitForSingleObject(event_complete, INFINITE);
2479             if(bindf & BINDF_FROMURLMON)
2480                 CHECK_CALLED(Switch);
2481             else
2482                 CHECK_CALLED(ReportData);
2483             if(prot == HTTPS_TEST)
2484                 CLEAR_CALLED(QueryService_HttpSecurity);
2485
2486             while(1) {
2487                 if(bindf & BINDF_FROMURLMON)
2488                     SET_EXPECT(Switch);
2489                 else
2490                     SET_EXPECT(ReportData);
2491                 hres = IInternetProtocol_Read(async_protocol, buf, sizeof(buf), &cb);
2492                 if(hres == E_PENDING) {
2493                     hres = IInternetProtocol_Read(async_protocol, buf, 1, &cb);
2494                     ok((hres == E_PENDING && cb==0) ||
2495                        (hres == S_OK && cb==1), "Read failed: %08x (%d bytes)\n", hres, cb);
2496                     WaitForSingleObject(event_complete, INFINITE);
2497                     if(bindf & BINDF_FROMURLMON)
2498                         CHECK_CALLED(Switch);
2499                     else
2500                         CHECK_CALLED(ReportData);
2501                 }else {
2502                     if(bindf & BINDF_FROMURLMON)
2503                         CHECK_NOT_CALLED(Switch);
2504                     else
2505                         CHECK_NOT_CALLED(ReportData);
2506                     if(cb == 0) break;
2507                 }
2508             }
2509             ok(hres == S_FALSE, "Read failed: %08x\n", hres);
2510             CHECK_CALLED(ReportResult);
2511         }
2512         if(prot == HTTPS_TEST)
2513             CLEAR_CALLED(ReportProgress_SENDINGREQUEST);
2514
2515         test_protocol_terminate(async_protocol);
2516         ref = IInternetProtocol_Release(async_protocol);
2517         ok(!ref, "ref=%x\n", hres);
2518     }
2519
2520     IClassFactory_Release(factory);
2521 }
2522
2523 static void test_http_protocol(void)
2524 {
2525     static const WCHAR winehq_url[] =
2526         {'h','t','t','p',':','/','/','w','w','w','.','w','i','n','e','h','q','.',
2527             'o','r','g','/','s','i','t','e','/','a','b','o','u','t',0};
2528     static const WCHAR posttest_url[] =
2529         {'h','t','t','p',':','/','/','c','r','o','s','s','o','v','e','r','.',
2530          'c','o','d','e','w','e','a','v','e','r','s','.','c','o','m','/',
2531          'p','o','s','t','t','e','s','t','.','p','h','p',0};
2532     static const WCHAR redirect_url[] =
2533         {'h','t','t','p',':','/','/','t','e','s','t','.','w','i','n','e','h','q','.','o','r','g','/',
2534          't','e','s','t','r','e','d','i','r','e','c','t',0};
2535
2536     trace("Testing http protocol (not from urlmon)...\n");
2537     bindf = BINDF_ASYNCHRONOUS | BINDF_ASYNCSTORAGE | BINDF_PULLDATA;
2538     test_http_protocol_url(winehq_url, HTTP_TEST, TEST_FIRST_HTTP);
2539
2540     trace("Testing http protocol (from urlmon)...\n");
2541     bindf = BINDF_ASYNCHRONOUS | BINDF_ASYNCSTORAGE | BINDF_PULLDATA | BINDF_FROMURLMON;
2542     test_http_protocol_url(winehq_url, HTTP_TEST, 0);
2543
2544     trace("Testing http protocol (to file)...\n");
2545     bindf = BINDF_ASYNCHRONOUS | BINDF_ASYNCSTORAGE | BINDF_PULLDATA | BINDF_FROMURLMON | BINDF_NEEDFILE;
2546     test_http_protocol_url(winehq_url, HTTP_TEST, 0);
2547
2548     trace("Testing http protocol (post data)...\n");
2549     /* Without this flag we get a ReportProgress_CACHEFILENAMEAVAILABLE
2550      * notification with BINDVERB_POST */
2551     bindf = BINDF_ASYNCHRONOUS | BINDF_ASYNCSTORAGE | BINDF_PULLDATA | BINDF_FROMURLMON | BINDF_NOWRITECACHE;
2552     test_http_protocol_url(posttest_url, HTTP_TEST, TEST_FIRST_HTTP|TEST_POST);
2553
2554     trace("Testing http protocol (direct read)...\n");
2555     bindf = BINDF_ASYNCHRONOUS | BINDF_ASYNCSTORAGE | BINDF_PULLDATA | BINDF_FROMURLMON;
2556     test_http_protocol_url(winehq_url, HTTP_TEST, TEST_DIRECT_READ);
2557
2558     trace("Testing http protocol (redirected)...\n");
2559     bindf = BINDF_ASYNCHRONOUS | BINDF_ASYNCSTORAGE | BINDF_PULLDATA | BINDF_FROMURLMON;
2560     test_http_protocol_url(redirect_url, HTTP_TEST, TEST_REDIRECT);
2561 }
2562
2563 static void test_https_protocol(void)
2564 {
2565     static const WCHAR codeweavers_url[] =
2566         {'h','t','t','p','s',':','/','/','w','w','w','.','c','o','d','e','w','e','a','v','e','r','s',
2567          '.','c','o','m','/','t','e','s','t','.','h','t','m','l',0};
2568
2569     trace("Testing https protocol (from urlmon)...\n");
2570     bindf = BINDF_ASYNCHRONOUS | BINDF_ASYNCSTORAGE | BINDF_PULLDATA | BINDF_FROMURLMON | BINDF_NOWRITECACHE;
2571     test_http_protocol_url(codeweavers_url, HTTPS_TEST, TEST_FIRST_HTTP);
2572 }
2573
2574
2575 static void test_ftp_protocol(void)
2576 {
2577     IInternetProtocolInfo *protocol_info;
2578     IClassFactory *factory;
2579     IUnknown *unk;
2580     BYTE buf[4096];
2581     ULONG ref;
2582     DWORD cb;
2583     HRESULT hres;
2584
2585     static const WCHAR ftp_urlW[] = {'f','t','p',':','/','/','f','t','p','.','w','i','n','e','h','q','.','o','r','g',
2586     '/','p','u','b','/','o','t','h','e','r','/',
2587     'w','i','n','e','l','o','g','o','.','x','c','f','.','t','a','r','.','b','z','2',0};
2588
2589     trace("Testing ftp protocol...\n");
2590
2591     bindf = BINDF_ASYNCHRONOUS | BINDF_ASYNCSTORAGE | BINDF_PULLDATA | BINDF_FROMURLMON | BINDF_NOWRITECACHE;
2592     state = 0;
2593     tested_protocol = FTP_TEST;
2594     first_data_notif = TRUE;
2595     expect_hrResult = E_PENDING;
2596
2597     hres = CoGetClassObject(&CLSID_FtpProtocol, CLSCTX_INPROC_SERVER, NULL, &IID_IUnknown, (void**)&unk);
2598     ok(hres == S_OK, "CoGetClassObject failed: %08x\n", hres);
2599     if(FAILED(hres))
2600         return;
2601
2602     hres = IUnknown_QueryInterface(unk, &IID_IInternetProtocolInfo, (void**)&protocol_info);
2603     ok(hres == E_NOINTERFACE, "Could not get IInternetProtocolInfo interface: %08x, expected E_NOINTERFACE\n", hres);
2604
2605     hres = IUnknown_QueryInterface(unk, &IID_IClassFactory, (void**)&factory);
2606     ok(hres == S_OK, "Could not get IClassFactory interface\n");
2607     IUnknown_Release(unk);
2608     if(FAILED(hres))
2609         return;
2610
2611     hres = IClassFactory_CreateInstance(factory, NULL, &IID_IInternetProtocol,
2612                                         (void**)&async_protocol);
2613     IClassFactory_Release(factory);
2614     ok(hres == S_OK, "Could not get IInternetProtocol: %08x\n", hres);
2615
2616     test_priority(async_protocol);
2617     test_http_info(async_protocol);
2618
2619     SET_EXPECT(GetBindInfo);
2620     SET_EXPECT(ReportProgress_FINDINGRESOURCE);
2621     SET_EXPECT(ReportProgress_CONNECTING);
2622     SET_EXPECT(ReportProgress_SENDINGREQUEST);
2623     SET_EXPECT(Switch);
2624
2625     hres = IInternetProtocol_Start(async_protocol, ftp_urlW, &protocol_sink, &bind_info, 0, 0);
2626     ok(hres == S_OK, "Start failed: %08x\n", hres);
2627     CHECK_CALLED(GetBindInfo);
2628
2629     SET_EXPECT(ReportResult);
2630
2631     hres = IInternetProtocol_Read(async_protocol, buf, 1, &cb);
2632     ok((hres == E_PENDING && cb==0) ||
2633        (hres == S_OK && cb==1), "Read failed: %08x (%d bytes)\n", hres, cb);
2634
2635     WaitForSingleObject(event_complete, INFINITE);
2636
2637     while(1) {
2638
2639         hres = IInternetProtocol_Read(async_protocol, buf, sizeof(buf), &cb);
2640         if(hres == E_PENDING)
2641             WaitForSingleObject(event_complete, INFINITE);
2642         else
2643             if(cb == 0) break;
2644     }
2645
2646     ok(hres == S_FALSE, "Read failed: %08x\n", hres);
2647     CHECK_CALLED(ReportResult);
2648     CHECK_CALLED(Switch);
2649
2650     test_protocol_terminate(async_protocol);
2651
2652     ref = IInternetProtocol_Release(async_protocol);
2653     ok(!ref, "ref=%d\n", ref);
2654 }
2655
2656 static void test_gopher_protocol(void)
2657 {
2658     IInternetProtocolInfo *protocol_info;
2659     IClassFactory *factory;
2660     IUnknown *unk;
2661     HRESULT hres;
2662
2663     trace("Testing gopher protocol...\n");
2664
2665     hres = CoGetClassObject(&CLSID_GopherProtocol, CLSCTX_INPROC_SERVER, NULL, &IID_IUnknown, (void**)&unk);
2666     ok(hres == S_OK ||
2667        hres == REGDB_E_CLASSNOTREG, /* Gopher protocol has been removed as of Vista */
2668        "CoGetClassObject failed: %08x\n", hres);
2669     if(FAILED(hres))
2670         return;
2671
2672     hres = IUnknown_QueryInterface(unk, &IID_IInternetProtocolInfo, (void**)&protocol_info);
2673     ok(hres == E_NOINTERFACE, "Could not get IInternetProtocolInfo interface: %08x, expected E_NOINTERFACE\n", hres);
2674
2675     hres = IUnknown_QueryInterface(unk, &IID_IClassFactory, (void**)&factory);
2676     ok(hres == S_OK, "Could not get IClassFactory interface\n");
2677     IUnknown_Release(unk);
2678     if(FAILED(hres))
2679         return;
2680
2681     hres = IClassFactory_CreateInstance(factory, NULL, &IID_IInternetProtocol,
2682                                         (void**)&async_protocol);
2683     IClassFactory_Release(factory);
2684     ok(hres == S_OK, "Could not get IInternetProtocol: %08x\n", hres);
2685
2686     test_priority(async_protocol);
2687
2688     IInternetProtocol_Release(async_protocol);
2689 }
2690
2691 static void test_mk_protocol(void)
2692 {
2693     IInternetProtocolInfo *protocol_info;
2694     IInternetProtocol *protocol;
2695     IClassFactory *factory;
2696     IUnknown *unk;
2697     HRESULT hres;
2698
2699     static const WCHAR wrong_url1[] = {'t','e','s','t',':','@','M','S','I','T','S','t','o','r','e',
2700                                        ':',':','/','t','e','s','t','.','h','t','m','l',0};
2701     static const WCHAR wrong_url2[] = {'m','k',':','/','t','e','s','t','.','h','t','m','l',0};
2702
2703     trace("Testing mk protocol...\n");
2704     init_test(MK_TEST, 0);
2705
2706     hres = CoGetClassObject(&CLSID_MkProtocol, CLSCTX_INPROC_SERVER, NULL,
2707             &IID_IUnknown, (void**)&unk);
2708     ok(hres == S_OK, "CoGetClassObject failed: %08x\n", hres);
2709
2710     hres = IUnknown_QueryInterface(unk, &IID_IInternetProtocolInfo, (void**)&protocol_info);
2711     ok(hres == E_NOINTERFACE,
2712         "Could not get IInternetProtocolInfo interface: %08x, expected E_NOINTERFACE\n",
2713         hres);
2714
2715     hres = IUnknown_QueryInterface(unk, &IID_IClassFactory, (void**)&factory);
2716     ok(hres == S_OK, "Could not get IClassFactory interface\n");
2717     IUnknown_Release(unk);
2718     if(FAILED(hres))
2719         return;
2720
2721     hres = IClassFactory_CreateInstance(factory, NULL, &IID_IInternetProtocol,
2722                                         (void**)&protocol);
2723     IClassFactory_Release(factory);
2724     ok(hres == S_OK, "Could not get IInternetProtocol: %08x\n", hres);
2725
2726     SET_EXPECT(GetBindInfo);
2727     hres = IInternetProtocol_Start(protocol, wrong_url1, &protocol_sink, &bind_info, 0, 0);
2728     ok(hres == MK_E_SYNTAX || hres == INET_E_INVALID_URL,
2729        "Start failed: %08x, expected MK_E_SYNTAX or INET_E_INVALID_URL\n", hres);
2730     CLEAR_CALLED(GetBindInfo);
2731
2732     SET_EXPECT(GetBindInfo);
2733     SET_EXPECT(ReportProgress_DIRECTBIND);
2734     SET_EXPECT(ReportProgress_SENDINGREQUEST);
2735     SET_EXPECT(ReportProgress_MIMETYPEAVAILABLE);
2736     SET_EXPECT(ReportResult);
2737     expect_hrResult = INET_E_RESOURCE_NOT_FOUND;
2738
2739     hres = IInternetProtocol_Start(protocol, wrong_url2, &protocol_sink, &bind_info, 0, 0);
2740     ok(hres == INET_E_RESOURCE_NOT_FOUND ||
2741        hres == INET_E_INVALID_URL, /* win2k3 */
2742        "Start failed: %08x, expected INET_E_RESOURCE_NOT_FOUND or INET_E_INVALID_URL\n", hres);
2743
2744     if (hres == INET_E_RESOURCE_NOT_FOUND) {
2745         CHECK_CALLED(GetBindInfo);
2746         CLEAR_CALLED(ReportProgress_DIRECTBIND);
2747         CHECK_CALLED(ReportProgress_SENDINGREQUEST);
2748         CHECK_CALLED(ReportProgress_MIMETYPEAVAILABLE);
2749         CHECK_CALLED(ReportResult);
2750     }else {
2751         CLEAR_CALLED(GetBindInfo);
2752         CLEAR_CALLED(ReportProgress_DIRECTBIND);
2753         CLEAR_CALLED(ReportProgress_SENDINGREQUEST);
2754         CLEAR_CALLED(ReportProgress_MIMETYPEAVAILABLE);
2755         CLEAR_CALLED(ReportResult);
2756     }
2757
2758     IInternetProtocol_Release(protocol);
2759 }
2760
2761 static void test_CreateBinding(void)
2762 {
2763     IInternetProtocol *protocol;
2764     IInternetPriority *priority;
2765     IInternetSession *session;
2766     IWinInetHttpInfo *http_info;
2767     IWinInetInfo *inet_info;
2768     LONG p;
2769     BYTE buf[1000];
2770     DWORD read;
2771     HRESULT hres;
2772
2773     static const WCHAR test_url[] =
2774         {'t','e','s','t',':','/','/','f','i','l','e','.','h','t','m','l',0};
2775     static const WCHAR wsz_test[] = {'t','e','s','t',0};
2776
2777     trace("Testing CreateBinding...\n");
2778     init_test(BIND_TEST, TEST_BINDING);
2779
2780     hres = CoInternetGetSession(0, &session, 0);
2781     ok(hres == S_OK, "CoInternetGetSession failed: %08x\n", hres);
2782
2783     hres = IInternetSession_RegisterNameSpace(session, &ClassFactory, &IID_NULL, wsz_test, 0, NULL, 0);
2784     ok(hres == S_OK, "RegisterNameSpace failed: %08x\n", hres);
2785
2786     hres = IInternetSession_CreateBinding(session, NULL, test_url, NULL, NULL, &protocol, 0);
2787     binding_protocol = protocol;
2788     ok(hres == S_OK, "CreateBinding failed: %08x\n", hres);
2789     ok(protocol != NULL, "protocol == NULL\n");
2790
2791     hres = IInternetProtocol_QueryInterface(protocol, &IID_IInternetBindInfo, (void**)&prot_bind_info);
2792     ok(hres == S_OK, "QueryInterface(IID_IInternetBindInfo) failed: %08x\n", hres);
2793
2794     hres = IInternetProtocol_QueryInterface(protocol, &IID_IInternetProtocolSink, (void**)&binding_sink);
2795     ok(hres == S_OK, "Could not get IInternetProtocolSink: %08x\n", hres);
2796
2797     hres = IInternetProtocol_Start(protocol, test_url, NULL, &bind_info, 0, 0);
2798     ok(hres == E_INVALIDARG, "Start failed: %08x, expected E_INVALIDARG\n", hres);
2799     hres = IInternetProtocol_Start(protocol, test_url, &protocol_sink, NULL, 0, 0);
2800     ok(hres == E_INVALIDARG, "Start failed: %08x, expected E_INVALIDARG\n", hres);
2801     hres = IInternetProtocol_Start(protocol, NULL, &protocol_sink, &bind_info, 0, 0);
2802     ok(hres == E_INVALIDARG, "Start failed: %08x, expected E_INVALIDARG\n", hres);
2803
2804     hres = IInternetProtocol_QueryInterface(protocol, &IID_IInternetPriority, (void**)&priority);
2805     ok(hres == S_OK, "QueryInterface(IID_IInternetPriority) failed: %08x\n", hres);
2806
2807     p = 0xdeadbeef;
2808     hres = IInternetPriority_GetPriority(priority, &p);
2809     ok(hres == S_OK, "GetPriority failed: %08x\n", hres);
2810     ok(!p, "p=%d\n", p);
2811
2812     ex_priority = 100;
2813     hres = IInternetPriority_SetPriority(priority, 100);
2814     ok(hres == S_OK, "SetPriority failed: %08x\n", hres);
2815
2816     p = 0xdeadbeef;
2817     hres = IInternetPriority_GetPriority(priority, &p);
2818     ok(hres == S_OK, "GetPriority failed: %08x\n", hres);
2819     ok(p == 100, "p=%d\n", p);
2820
2821     hres = IInternetProtocol_QueryInterface(protocol, &IID_IWinInetInfo, (void**)&inet_info);
2822     ok(hres == E_NOINTERFACE, "Could not get IWinInetInfo protocol: %08x\n", hres);
2823
2824     SET_EXPECT(QueryService_InternetProtocol);
2825     SET_EXPECT(CreateInstance);
2826     SET_EXPECT(ReportProgress_PROTOCOLCLASSID);
2827     SET_EXPECT(SetPriority);
2828     SET_EXPECT(Start);
2829
2830     expect_hrResult = S_OK;
2831     hres = IInternetProtocol_Start(protocol, test_url, &protocol_sink, &bind_info, 0, 0);
2832     ok(hres == S_OK, "Start failed: %08x\n", hres);
2833
2834     CHECK_CALLED(QueryService_InternetProtocol);
2835     CHECK_CALLED(CreateInstance);
2836     CHECK_CALLED(ReportProgress_PROTOCOLCLASSID);
2837     CHECK_CALLED(SetPriority);
2838     CHECK_CALLED(Start);
2839
2840     SET_EXPECT(QueryInterface_IWinInetInfo);
2841     hres = IInternetProtocol_QueryInterface(protocol, &IID_IWinInetInfo, (void**)&inet_info);
2842     ok(hres == E_NOINTERFACE, "Could not get IWinInetInfo protocol: %08x\n", hres);
2843     CHECK_CALLED(QueryInterface_IWinInetInfo);
2844
2845     SET_EXPECT(QueryInterface_IWinInetInfo);
2846     hres = IInternetProtocol_QueryInterface(protocol, &IID_IWinInetInfo, (void**)&inet_info);
2847     ok(hres == E_NOINTERFACE, "Could not get IWinInetInfo protocol: %08x\n", hres);
2848     CHECK_CALLED(QueryInterface_IWinInetInfo);
2849
2850     SET_EXPECT(QueryInterface_IWinInetHttpInfo);
2851     hres = IInternetProtocol_QueryInterface(protocol, &IID_IWinInetHttpInfo, (void**)&http_info);
2852     ok(hres == E_NOINTERFACE, "Could not get IWinInetInfo protocol: %08x\n", hres);
2853     CHECK_CALLED(QueryInterface_IWinInetHttpInfo);
2854
2855     SET_EXPECT(Read);
2856     read = 0xdeadbeef;
2857     hres = IInternetProtocol_Read(protocol, expect_pv = buf, sizeof(buf), &read);
2858     ok(hres == S_OK, "Read failed: %08x\n", hres);
2859     ok(read == 100, "read = %d\n", read);
2860     CHECK_CALLED(Read);
2861
2862     SET_EXPECT(Read);
2863     read = 0xdeadbeef;
2864     hres = IInternetProtocol_Read(protocol, expect_pv = buf, sizeof(buf), &read);
2865     ok(hres == S_FALSE, "Read failed: %08x\n", hres);
2866     ok(!read, "read = %d\n", read);
2867     CHECK_CALLED(Read);
2868
2869     p = 0xdeadbeef;
2870     hres = IInternetPriority_GetPriority(priority, &p);
2871     ok(hres == S_OK, "GetPriority failed: %08x\n", hres);
2872     ok(p == 100, "p=%d\n", p);
2873
2874     hres = IInternetPriority_SetPriority(priority, 101);
2875     ok(hres == S_OK, "SetPriority failed: %08x\n", hres);
2876
2877     SET_EXPECT(Terminate);
2878     hres = IInternetProtocol_Terminate(protocol, 0xdeadbeef);
2879     ok(hres == S_OK, "Terminate failed: %08x\n", hres);
2880     CHECK_CALLED(Terminate);
2881
2882     SET_EXPECT(Continue);
2883     hres = IInternetProtocolSink_Switch(binding_sink, &protocoldata);
2884     ok(hres == S_OK, "Switch failed: %08x\n", hres);
2885     CHECK_CALLED(Continue);
2886
2887     hres = IInternetProtocolSink_ReportProgress(binding_sink,
2888             BINDSTATUS_CACHEFILENAMEAVAILABLE, expect_wsz = emptyW);
2889     ok(hres == S_OK, "ReportProgress(BINDSTATUS_CACHEFILENAMEAVAILABLE) failed: %08x\n", hres);
2890
2891     hres = IInternetProtocolSink_ReportResult(binding_sink, S_OK, ERROR_SUCCESS, NULL);
2892     ok(hres == E_FAIL, "ReportResult failed: %08x, expected E_FAIL\n", hres);
2893
2894     hres = IInternetProtocolSink_ReportData(binding_sink, 0, 0, 0);
2895     ok(hres == S_OK, "ReportData failed: %08x\n", hres);
2896
2897     IInternetProtocolSink_Release(binding_sink);
2898     IInternetPriority_Release(priority);
2899     IInternetBindInfo_Release(prot_bind_info);
2900     IInternetProtocol_Release(protocol);
2901
2902     hres = IInternetSession_UnregisterNameSpace(session, &ClassFactory, wsz_test);
2903     ok(hres == S_OK, "UnregisterNameSpace failed: %08x\n", hres);
2904
2905     IInternetSession_Release(session);
2906 }
2907
2908 static void test_binding(int prot, DWORD grf_pi, DWORD test_flags)
2909 {
2910     IInternetProtocol *protocol;
2911     IInternetSession *session;
2912     ULONG ref;
2913     HRESULT hres;
2914
2915     pi = grf_pi;
2916
2917     init_test(prot, test_flags|TEST_BINDING);
2918
2919     hres = CoInternetGetSession(0, &session, 0);
2920     ok(hres == S_OK, "CoInternetGetSession failed: %08x\n", hres);
2921
2922     if(test_flags & TEST_EMULATEPROT) {
2923         hres = IInternetSession_RegisterNameSpace(session, &ClassFactory, &IID_NULL, protocol_names[prot], 0, NULL, 0);
2924         ok(hres == S_OK, "RegisterNameSpace failed: %08x\n", hres);
2925     }
2926
2927     hres = IInternetSession_CreateBinding(session, NULL, binding_urls[prot], NULL, NULL, &protocol, 0);
2928     binding_protocol = protocol;
2929     ok(hres == S_OK, "CreateBinding failed: %08x\n", hres);
2930     ok(protocol != NULL, "protocol == NULL\n");
2931
2932     hres = IInternetProtocol_QueryInterface(protocol, &IID_IInternetBindInfo, (void**)&prot_bind_info);
2933     ok(hres == S_OK, "QueryInterface(IID_IInternetBindInfo) failed: %08x\n", hres);
2934
2935     hres = IInternetProtocol_QueryInterface(protocol, &IID_IInternetProtocolSink, (void**)&binding_sink);
2936     ok(hres == S_OK, "QueryInterface(IID_IInternetProtocolSink) failed: %08x\n", hres);
2937
2938     ex_priority = 0;
2939     SET_EXPECT(QueryService_InternetProtocol);
2940     SET_EXPECT(CreateInstance);
2941     SET_EXPECT(ReportProgress_PROTOCOLCLASSID);
2942     SET_EXPECT(SetPriority);
2943     SET_EXPECT(Start);
2944
2945     expect_hrResult = S_OK;
2946     hres = IInternetProtocol_Start(protocol, binding_urls[prot], &protocol_sink, &bind_info, pi, 0);
2947     ok(hres == S_OK, "Start failed: %08x\n", hres);
2948
2949     CHECK_CALLED(QueryService_InternetProtocol);
2950     CHECK_CALLED(CreateInstance);
2951     CHECK_CALLED(ReportProgress_PROTOCOLCLASSID);
2952     CHECK_CALLED(SetPriority);
2953     CHECK_CALLED(Start);
2954
2955     if(prot == HTTP_TEST || prot == HTTPS_TEST) {
2956         while(prot_state < 4) {
2957             WaitForSingleObject(event_complete, INFINITE);
2958             if(mimefilter_test && filtered_protocol) {
2959                 SET_EXPECT(Continue);
2960                 IInternetProtocol_Continue(filtered_protocol, pdata);
2961                 CHECK_CALLED(Continue);
2962             }else {
2963                 SET_EXPECT(Continue);
2964                 IInternetProtocol_Continue(protocol, pdata);
2965                 CHECK_CALLED(Continue);
2966             }
2967             SetEvent(event_complete2);
2968         }
2969         if(direct_read)
2970             CHECK_CALLED(ReportData); /* Set in ReportResult */
2971         WaitForSingleObject(event_complete, INFINITE);
2972     }else {
2973         if(mimefilter_test)
2974             SET_EXPECT(MimeFilter_LockRequest);
2975         else
2976             SET_EXPECT(LockRequest);
2977         hres = IInternetProtocol_LockRequest(protocol, 0);
2978         ok(hres == S_OK, "LockRequest failed: %08x\n", hres);
2979         if(mimefilter_test)
2980             CHECK_CALLED(MimeFilter_LockRequest);
2981         else
2982             CHECK_CALLED(LockRequest);
2983
2984         if(mimefilter_test)
2985             SET_EXPECT(MimeFilter_UnlockRequest);
2986         else
2987             SET_EXPECT(UnlockRequest);
2988         hres = IInternetProtocol_UnlockRequest(protocol);
2989         ok(hres == S_OK, "UnlockRequest failed: %08x\n", hres);
2990         if(mimefilter_test)
2991             CHECK_CALLED(MimeFilter_UnlockRequest);
2992         else
2993             CHECK_CALLED(UnlockRequest);
2994     }
2995
2996     if(mimefilter_test)
2997         SET_EXPECT(MimeFilter_Terminate);
2998     else
2999         SET_EXPECT(Terminate);
3000     hres = IInternetProtocol_Terminate(protocol, 0);
3001     ok(hres == S_OK, "Terminate failed: %08x\n", hres);
3002     if(mimefilter_test)
3003         CLEAR_CALLED(MimeFilter_Terminate);
3004     else
3005         CHECK_CALLED(Terminate);
3006
3007     if(filtered_protocol)
3008         IInternetProtocol_Release(filtered_protocol);
3009     IInternetBindInfo_Release(prot_bind_info);
3010     IInternetProtocolSink_Release(binding_sink);
3011     ref = IInternetProtocol_Release(protocol);
3012     ok(!ref, "ref=%u, expected 0\n", ref);
3013
3014     if(test_flags & TEST_EMULATEPROT) {
3015         hres = IInternetSession_UnregisterNameSpace(session, &ClassFactory, protocol_names[prot]);
3016         ok(hres == S_OK, "UnregisterNameSpace failed: %08x\n", hres);
3017     }
3018
3019     IInternetSession_Release(session);
3020 }
3021
3022 static void register_filter(void)
3023 {
3024     IInternetSession *session;
3025     HRESULT hres;
3026
3027     static const WCHAR gzipW[] = {'g','z','i','p',0};
3028
3029     CoInternetGetSession(0, &session, 0);
3030
3031     hres = IInternetSession_RegisterMimeFilter(session, &mimefilter_cf, &IID_IInternetProtocol, gzipW);
3032     ok(hres == S_OK, "RegisterMimeFilter failed: %08x\n", hres);
3033
3034     IInternetSession_Release(session);
3035 }
3036
3037 START_TEST(protocol)
3038 {
3039     OleInitialize(NULL);
3040
3041     event_complete = CreateEvent(NULL, FALSE, FALSE, NULL);
3042     event_complete2 = CreateEvent(NULL, FALSE, FALSE, NULL);
3043     event_continue = CreateEvent(NULL, FALSE, FALSE, NULL);
3044     event_continue_done = CreateEvent(NULL, FALSE, FALSE, NULL);
3045
3046     register_filter();
3047
3048     test_file_protocol();
3049     test_http_protocol();
3050     test_https_protocol();
3051     test_ftp_protocol();
3052     test_gopher_protocol();
3053     test_mk_protocol();
3054     test_CreateBinding();
3055
3056     bindf &= ~BINDF_FROMURLMON;
3057     trace("Testing file binding (mime verification, emulate prot)...\n");
3058     test_binding(FILE_TEST, PI_MIMEVERIFICATION, TEST_EMULATEPROT);
3059     trace("Testing http binding (mime verification, emulate prot)...\n");
3060     test_binding(HTTP_TEST, PI_MIMEVERIFICATION, TEST_EMULATEPROT);
3061     trace("Testing http binding (mime verification, emulate prot, short read, direct read)...\n");
3062     test_binding(HTTP_TEST, PI_MIMEVERIFICATION, TEST_EMULATEPROT|TEST_SHORT_READ|TEST_DIRECT_READ);
3063     trace("Testing file binding (mime verification, emulate prot, mime filter)...\n");
3064     test_binding(FILE_TEST, PI_MIMEVERIFICATION, TEST_EMULATEPROT|TEST_FILTER);
3065     trace("Testing http binding (mime verification, emulate prot, mime filter)...\n");
3066     test_binding(HTTP_TEST, PI_MIMEVERIFICATION, TEST_EMULATEPROT|TEST_FILTER);
3067     trace("Testing http binding (mime verification, emulate prot, direct read)...\n");
3068     test_binding(HTTP_TEST, PI_MIMEVERIFICATION, TEST_EMULATEPROT|TEST_DIRECT_READ);
3069
3070     CloseHandle(event_complete);
3071     CloseHandle(event_complete2);
3072     CloseHandle(event_continue);
3073     CloseHandle(event_continue_done);
3074
3075     OleUninitialize();
3076 }