push cc8bc80451cc24f4d7cf75168b569f0ebfe19547
[wine/hacks.git] / dlls / urlmon / tests / protocol.c
blob44276b11830181ae4efc519b09349c1e718468d9
1 /*
2 * Copyright 2005-2009 Jacek Caban for CodeWeavers
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.
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.
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
19 #define COBJMACROS
20 #define CONST_VTABLE
22 #include <wine/test.h>
23 #include <stdarg.h>
24 #include <stdio.h>
26 #include "windef.h"
27 #include "winbase.h"
28 #include "ole2.h"
29 #include "urlmon.h"
30 #include "wininet.h"
32 #define DEFINE_EXPECT(func) \
33 static BOOL expect_ ## func = FALSE, called_ ## func = FALSE
35 #define SET_EXPECT(func) \
36 expect_ ## func = TRUE
38 #define CHECK_EXPECT2(func) \
39 do { \
40 ok(expect_ ##func, "unexpected call " #func "\n"); \
41 called_ ## func = TRUE; \
42 }while(0)
44 #define CHECK_EXPECT(func) \
45 do { \
46 CHECK_EXPECT2(func); \
47 expect_ ## func = FALSE; \
48 }while(0)
50 #define CHECK_CALLED(func) \
51 do { \
52 ok(called_ ## func, "expected " #func "\n"); \
53 expect_ ## func = called_ ## func = FALSE; \
54 }while(0)
56 #define CHECK_NOT_CALLED(func) \
57 do { \
58 ok(!called_ ## func, "unexpected " #func "\n"); \
59 expect_ ## func = called_ ## func = FALSE; \
60 }while(0)
62 #define CLEAR_CALLED(func) \
63 expect_ ## func = called_ ## func = FALSE
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(ReportResult);
84 DEFINE_EXPECT(GetBindString_ACCEPT_MIMES);
85 DEFINE_EXPECT(GetBindString_USER_AGENT);
86 DEFINE_EXPECT(GetBindString_POST_COOKIE);
87 DEFINE_EXPECT(GetBindString_URL);
88 DEFINE_EXPECT(QueryService_HttpNegotiate);
89 DEFINE_EXPECT(QueryService_InternetProtocol);
90 DEFINE_EXPECT(QueryService_HttpSecurity);
91 DEFINE_EXPECT(BeginningTransaction);
92 DEFINE_EXPECT(GetRootSecurityId);
93 DEFINE_EXPECT(OnResponse);
94 DEFINE_EXPECT(Switch);
95 DEFINE_EXPECT(Continue);
96 DEFINE_EXPECT(CreateInstance);
97 DEFINE_EXPECT(Start);
98 DEFINE_EXPECT(Terminate);
99 DEFINE_EXPECT(Read);
100 DEFINE_EXPECT(SetPriority);
101 DEFINE_EXPECT(LockRequest);
102 DEFINE_EXPECT(UnlockRequest);
103 DEFINE_EXPECT(MimeFilter_CreateInstance);
104 DEFINE_EXPECT(MimeFilter_Start);
105 DEFINE_EXPECT(MimeFilter_ReportProgress);
106 DEFINE_EXPECT(MimeFilter_ReportData);
107 DEFINE_EXPECT(MimeFilter_ReportResult);
108 DEFINE_EXPECT(MimeFilter_Terminate);
109 DEFINE_EXPECT(MimeFilter_LockRequest);
110 DEFINE_EXPECT(MimeFilter_UnlockRequest);
111 DEFINE_EXPECT(MimeFilter_Read);
112 DEFINE_EXPECT(MimeFilter_Switch);
113 DEFINE_EXPECT(MimeFilter_Continue);
115 static const WCHAR wszIndexHtml[] = {'i','n','d','e','x','.','h','t','m','l',0};
116 static const WCHAR index_url[] =
117 {'f','i','l','e',':','i','n','d','e','x','.','h','t','m','l',0};
119 static const WCHAR acc_mimeW[] = {'*','/','*',0};
120 static const WCHAR user_agentW[] = {'W','i','n','e',0};
121 static const WCHAR text_htmlW[] = {'t','e','x','t','/','h','t','m','l',0};
122 static const WCHAR hostW[] = {'w','w','w','.','w','i','n','e','h','q','.','o','r','g',0};
123 static const WCHAR winehq_ipW[] = {'2','0','9','.','4','6','.','2','5','.','1','3','4',0};
124 static const WCHAR emptyW[] = {0};
125 static const WCHAR gzipW[] = {'g','z','i','p',0};
127 static HRESULT expect_hrResult;
128 static LPCWSTR file_name, http_url, expect_wsz;
129 static IInternetProtocol *async_protocol = NULL;
130 static BOOL first_data_notif = FALSE, http_is_first = FALSE,
131 http_post_test = FALSE;
132 static int state = 0, prot_state;
133 static DWORD bindf, ex_priority , pi;
134 static IInternetProtocol *binding_protocol, *filtered_protocol;
135 static IInternetBindInfo *prot_bind_info;
136 static IInternetProtocolSink *binding_sink, *filtered_sink;
137 static void *expect_pv;
138 static HANDLE event_complete, event_complete2;
139 static BOOL binding_test;
140 static PROTOCOLDATA protocoldata, *pdata;
141 static DWORD prot_read, pi, filter_state;
142 static BOOL security_problem = FALSE;
143 static BOOL async_read_pending, mimefilter_test;
145 static enum {
146 FILE_TEST,
147 HTTP_TEST,
148 HTTPS_TEST,
149 FTP_TEST,
150 MK_TEST,
151 BIND_TEST
152 } tested_protocol;
154 static const WCHAR protocol_names[][10] = {
155 {'f','i','l','e',0},
156 {'h','t','t','p',0},
157 {'h','t','t','p','s',0},
158 {'f','t','p',0},
159 {'m','k',0},
160 {'t','e','s','t',0}
163 static const WCHAR binding_urls[][130] = {
164 {'f','i','l','e',':','t','e','s','t','.','h','t','m','l',0},
165 {'h','t','t','p',':','/','/','t','e','s','t','/','t','e','s','t','.','h','t','m','l',0},
166 {'h','t','t','p','s',':','/','/','w','w','w','.','c','o','d','e','w','e','a','v','e','r','s',
167 '.','c','o','m','/','t','e','s','t','.','h','t','m','l',0},
168 {'f','t','p',':','/','/','f','t','p','.','w','i','n','e','h','q','.','o','r','g',
169 '/','p','u','b','/','o','t','h','e','r',
170 '/','w','i','n','e','l','o','g','o','.','x','c','f','.','t','a','r','.','b','z','2',0},
171 {'m','k',':','t','e','s','t',0},
172 {'t','e','s','t',':','/','/','f','i','l','e','.','h','t','m','l',0}
175 static const char *debugstr_w(LPCWSTR str)
177 static char buf[512];
178 if(!str)
179 return "(null)";
180 WideCharToMultiByte(CP_ACP, 0, str, -1, buf, sizeof(buf), NULL, NULL);
181 return buf;
184 static const char *debugstr_guid(REFIID riid)
186 static char buf[50];
188 sprintf(buf, "{%08X-%04X-%04X-%02X%02X-%02X%02X%02X%02X%02X%02X}",
189 riid->Data1, riid->Data2, riid->Data3, riid->Data4[0],
190 riid->Data4[1], riid->Data4[2], riid->Data4[3], riid->Data4[4],
191 riid->Data4[5], riid->Data4[6], riid->Data4[7]);
193 return buf;
196 static int strcmp_wa(LPCWSTR strw, const char *stra)
198 WCHAR buf[512];
199 MultiByteToWideChar(CP_ACP, 0, stra, -1, buf, sizeof(buf)/sizeof(WCHAR));
200 return lstrcmpW(strw, buf);
203 static HRESULT WINAPI HttpSecurity_QueryInterface(IHttpSecurity *iface, REFIID riid, void **ppv)
205 if(IsEqualGUID(&IID_IUnknown, riid)
206 || IsEqualGUID(&IID_IHttpSecurity, riid)) {
207 *ppv = iface;
208 return S_OK;
211 ok(0, "unexpected call\n");
212 return E_NOINTERFACE;
215 static ULONG WINAPI HttpSecurity_AddRef(IHttpSecurity *iface)
217 return 2;
220 static ULONG WINAPI HttpSecurity_Release(IHttpSecurity *iface)
222 return 1;
225 static HRESULT WINAPI HttpSecurity_GetWindow(IHttpSecurity* iface, REFGUID rguidReason, HWND *phwnd)
227 trace("HttpSecurity_GetWindow\n");
229 return S_FALSE;
232 static HRESULT WINAPI HttpSecurity_OnSecurityProblem(IHttpSecurity *iface, DWORD dwProblem)
234 trace("Security problem: %u\n", dwProblem);
235 ok(dwProblem == ERROR_INTERNET_SEC_CERT_REV_FAILED, "Expected ERROR_INTERNET_SEC_CERT_REV_FAILED got %u\n", dwProblem);
237 /* Only retry once */
238 if (security_problem)
239 return E_ABORT;
241 security_problem = TRUE;
242 SET_EXPECT(BeginningTransaction);
244 return RPC_E_RETRY;
247 static IHttpSecurityVtbl HttpSecurityVtbl = {
248 HttpSecurity_QueryInterface,
249 HttpSecurity_AddRef,
250 HttpSecurity_Release,
251 HttpSecurity_GetWindow,
252 HttpSecurity_OnSecurityProblem
255 static IHttpSecurity http_security = { &HttpSecurityVtbl };
257 static HRESULT WINAPI HttpNegotiate_QueryInterface(IHttpNegotiate2 *iface, REFIID riid, void **ppv)
259 if(IsEqualGUID(&IID_IUnknown, riid)
260 || IsEqualGUID(&IID_IHttpNegotiate, riid)
261 || IsEqualGUID(&IID_IHttpNegotiate2, riid)) {
262 *ppv = iface;
263 return S_OK;
266 ok(0, "unexpected call\n");
267 return E_NOINTERFACE;
270 static ULONG WINAPI HttpNegotiate_AddRef(IHttpNegotiate2 *iface)
272 return 2;
275 static ULONG WINAPI HttpNegotiate_Release(IHttpNegotiate2 *iface)
277 return 1;
280 static HRESULT WINAPI HttpNegotiate_BeginningTransaction(IHttpNegotiate2 *iface, LPCWSTR szURL,
281 LPCWSTR szHeaders, DWORD dwReserved, LPWSTR *pszAdditionalHeaders)
283 LPWSTR addl_headers;
285 static const WCHAR wszHeaders[] =
286 {'C','o','n','t','e','n','t','-','T','y','p','e',':',' ','a','p','p','l','i','c','a','t',
287 'i','o','n','/','x','-','w','w','w','-','f','o','r','m','-','u','r','l','e','n','c','o',
288 'd','e','d','\r','\n',0};
290 CHECK_EXPECT(BeginningTransaction);
292 if(binding_test)
293 ok(!lstrcmpW(szURL, binding_urls[tested_protocol]), "szURL != http_url\n");
294 else
295 ok(!lstrcmpW(szURL, http_url), "szURL != http_url\n");
296 ok(!dwReserved, "dwReserved=%d, expected 0\n", dwReserved);
297 ok(pszAdditionalHeaders != NULL, "pszAdditionalHeaders == NULL\n");
298 if(pszAdditionalHeaders)
300 ok(*pszAdditionalHeaders == NULL, "*pszAdditionalHeaders != NULL\n");
301 if (http_post_test)
303 addl_headers = CoTaskMemAlloc(sizeof(wszHeaders));
304 if (!addl_headers)
306 http_post_test = FALSE;
307 skip("Out of memory\n");
308 return E_OUTOFMEMORY;
310 lstrcpyW(addl_headers, wszHeaders);
311 *pszAdditionalHeaders = addl_headers;
315 return S_OK;
318 static HRESULT WINAPI HttpNegotiate_OnResponse(IHttpNegotiate2 *iface, DWORD dwResponseCode,
319 LPCWSTR szResponseHeaders, LPCWSTR szRequestHeaders, LPWSTR *pszAdditionalRequestHeaders)
321 CHECK_EXPECT(OnResponse);
323 ok(dwResponseCode == 200, "dwResponseCode=%d, expected 200\n", dwResponseCode);
324 ok(szResponseHeaders != NULL, "szResponseHeaders == NULL\n");
325 ok(szRequestHeaders == NULL, "szRequestHeaders != NULL\n");
326 ok(pszAdditionalRequestHeaders == NULL, "pszAdditionalHeaders != NULL\n");
328 return S_OK;
331 static HRESULT WINAPI HttpNegotiate_GetRootSecurityId(IHttpNegotiate2 *iface,
332 BYTE *pbSecurityId, DWORD *pcbSecurityId, DWORD_PTR dwReserved)
334 static const BYTE sec_id[] = {'h','t','t','p',':','t','e','s','t',1,0,0,0};
336 CHECK_EXPECT(GetRootSecurityId);
338 ok(!dwReserved, "dwReserved=%ld, expected 0\n", dwReserved);
339 ok(pbSecurityId != NULL, "pbSecurityId == NULL\n");
340 ok(pcbSecurityId != NULL, "pcbSecurityId == NULL\n");
342 if(pcbSecurityId) {
343 ok(*pcbSecurityId == 512, "*pcbSecurityId=%d, expected 512\n", *pcbSecurityId);
344 *pcbSecurityId = sizeof(sec_id);
347 if(pbSecurityId)
348 memcpy(pbSecurityId, sec_id, sizeof(sec_id));
350 return E_FAIL;
353 static IHttpNegotiate2Vtbl HttpNegotiateVtbl = {
354 HttpNegotiate_QueryInterface,
355 HttpNegotiate_AddRef,
356 HttpNegotiate_Release,
357 HttpNegotiate_BeginningTransaction,
358 HttpNegotiate_OnResponse,
359 HttpNegotiate_GetRootSecurityId
362 static IHttpNegotiate2 http_negotiate = { &HttpNegotiateVtbl };
364 static HRESULT QueryInterface(REFIID,void**);
366 static HRESULT WINAPI ServiceProvider_QueryInterface(IServiceProvider *iface, REFIID riid, void **ppv)
368 return QueryInterface(riid, ppv);
371 static ULONG WINAPI ServiceProvider_AddRef(IServiceProvider *iface)
373 return 2;
376 static ULONG WINAPI ServiceProvider_Release(IServiceProvider *iface)
378 return 1;
381 static HRESULT WINAPI ServiceProvider_QueryService(IServiceProvider *iface, REFGUID guidService,
382 REFIID riid, void **ppv)
384 if(IsEqualGUID(&IID_IHttpNegotiate, guidService) || IsEqualGUID(&IID_IHttpNegotiate2, riid)) {
385 CHECK_EXPECT2(QueryService_HttpNegotiate);
386 return IHttpNegotiate2_QueryInterface(&http_negotiate, riid, ppv);
389 if(IsEqualGUID(&IID_IInternetProtocol, guidService)) {
390 ok(IsEqualGUID(&IID_IInternetProtocol, riid), "unexpected riid\n");
391 CHECK_EXPECT(QueryService_InternetProtocol);
392 return E_NOINTERFACE;
395 if(IsEqualGUID(&IID_IHttpSecurity, guidService)) {
396 ok(IsEqualGUID(&IID_IHttpSecurity, riid), "unexpected riid\n");
397 CHECK_EXPECT(QueryService_HttpSecurity);
398 return IHttpSecurity_QueryInterface(&http_security, riid, ppv);
401 ok(0, "unexpected service %s\n", debugstr_guid(guidService));
402 return E_FAIL;
405 static const IServiceProviderVtbl ServiceProviderVtbl = {
406 ServiceProvider_QueryInterface,
407 ServiceProvider_AddRef,
408 ServiceProvider_Release,
409 ServiceProvider_QueryService
412 static IServiceProvider service_provider = { &ServiceProviderVtbl };
414 static HRESULT WINAPI ProtocolSink_QueryInterface(IInternetProtocolSink *iface, REFIID riid, void **ppv)
416 return QueryInterface(riid, ppv);
419 static ULONG WINAPI ProtocolSink_AddRef(IInternetProtocolSink *iface)
421 return 2;
424 static ULONG WINAPI ProtocolSink_Release(IInternetProtocolSink *iface)
426 return 1;
429 static HRESULT WINAPI ProtocolSink_Switch(IInternetProtocolSink *iface, PROTOCOLDATA *pProtocolData)
431 HRESULT hres;
433 if(tested_protocol == FTP_TEST)
434 CHECK_EXPECT2(Switch);
435 else
436 CHECK_EXPECT(Switch);
438 ok(pProtocolData != NULL, "pProtocolData == NULL\n");
439 if(binding_test) {
440 ok(pProtocolData != &protocoldata, "pProtocolData == &protocoldata\n");
441 ok(pProtocolData->grfFlags == protocoldata.grfFlags, "grfFlags wrong %x/%x\n",
442 pProtocolData->grfFlags, protocoldata.grfFlags );
443 ok(pProtocolData->dwState == protocoldata.dwState, "dwState wrong %x/%x\n",
444 pProtocolData->dwState, protocoldata.dwState );
445 ok(pProtocolData->pData == protocoldata.pData, "pData wrong %p/%p\n",
446 pProtocolData->pData, protocoldata.pData );
447 ok(pProtocolData->cbData == protocoldata.cbData, "cbData wrong %x/%x\n",
448 pProtocolData->cbData, protocoldata.cbData );
451 pdata = pProtocolData;
453 if(binding_test) {
454 SetEvent(event_complete);
455 WaitForSingleObject(event_complete2, INFINITE);
456 return S_OK;
459 if (!state) {
460 if(tested_protocol == HTTP_TEST || tested_protocol == HTTPS_TEST || tested_protocol == FTP_TEST) {
461 if (http_is_first) {
462 CLEAR_CALLED(ReportProgress_FINDINGRESOURCE);
463 CLEAR_CALLED(ReportProgress_CONNECTING);
464 CLEAR_CALLED(ReportProgress_PROXYDETECTING);
465 } else todo_wine {
466 CHECK_NOT_CALLED(ReportProgress_FINDINGRESOURCE);
467 /* IE7 does call this */
468 CLEAR_CALLED(ReportProgress_CONNECTING);
471 if(tested_protocol == FTP_TEST)
472 todo_wine CHECK_CALLED(ReportProgress_SENDINGREQUEST);
473 else if (tested_protocol != HTTPS_TEST)
474 CHECK_CALLED(ReportProgress_SENDINGREQUEST);
475 if(tested_protocol == HTTP_TEST || tested_protocol == HTTPS_TEST) {
476 SET_EXPECT(OnResponse);
477 if(tested_protocol == HTTPS_TEST)
478 SET_EXPECT(ReportProgress_ACCEPTRANGES);
479 SET_EXPECT(ReportProgress_MIMETYPEAVAILABLE);
480 if(bindf & BINDF_NEEDFILE)
481 SET_EXPECT(ReportProgress_CACHEFILENAMEAVAILABLE);
485 SET_EXPECT(ReportData);
486 hres = IInternetProtocol_Continue(async_protocol, pProtocolData);
487 ok(hres == S_OK, "Continue failed: %08x\n", hres);
488 if(tested_protocol == FTP_TEST)
489 CLEAR_CALLED(ReportData);
490 else if (! security_problem)
491 CHECK_CALLED(ReportData);
493 if (!state) {
494 if (! security_problem)
496 state = 1;
497 if(tested_protocol == HTTP_TEST || tested_protocol == HTTPS_TEST) {
498 CHECK_CALLED(OnResponse);
499 if(tested_protocol == HTTPS_TEST)
500 CHECK_CALLED(ReportProgress_ACCEPTRANGES);
501 CHECK_CALLED(ReportProgress_MIMETYPEAVAILABLE);
502 if(bindf & BINDF_NEEDFILE)
503 CHECK_CALLED(ReportProgress_CACHEFILENAMEAVAILABLE);
506 else
508 security_problem = FALSE;
509 SET_EXPECT(ReportProgress_CONNECTING);
513 SetEvent(event_complete);
515 return S_OK;
518 static HRESULT WINAPI ProtocolSink_ReportProgress(IInternetProtocolSink *iface, ULONG ulStatusCode,
519 LPCWSTR szStatusText)
521 static const WCHAR null_guid[] = {'{','0','0','0','0','0','0','0','0','-','0','0','0','0','-',
522 '0','0','0','0','-','0','0','0','0','-','0','0','0','0','0','0','0','0','0','0','0','0','}',0};
523 static const WCHAR text_plain[] = {'t','e','x','t','/','p','l','a','i','n',0};
525 switch(ulStatusCode) {
526 case BINDSTATUS_MIMETYPEAVAILABLE:
527 CHECK_EXPECT(ReportProgress_MIMETYPEAVAILABLE);
528 ok(szStatusText != NULL, "szStatusText == NULL\n");
529 if(szStatusText) {
530 if(tested_protocol == BIND_TEST)
531 ok(szStatusText == expect_wsz, "unexpected szStatusText\n");
532 else if (http_post_test)
533 ok(lstrlenW(text_plain) <= lstrlenW(szStatusText) &&
534 !memcmp(szStatusText, text_plain, lstrlenW(text_plain)*sizeof(WCHAR)),
535 "szStatusText != text/plain\n");
536 else if(!mimefilter_test)
537 ok(lstrlenW(text_htmlW) <= lstrlenW(szStatusText) &&
538 !memcmp(szStatusText, text_htmlW, lstrlenW(text_htmlW)*sizeof(WCHAR)),
539 "szStatusText != text/html\n");
541 break;
542 case BINDSTATUS_DIRECTBIND:
543 CHECK_EXPECT2(ReportProgress_DIRECTBIND);
544 ok(szStatusText == NULL, "szStatusText != NULL\n");
545 break;
546 case BINDSTATUS_RAWMIMETYPE:
547 CHECK_EXPECT2(ReportProgress_RAWMIMETYPE);
548 ok(szStatusText != NULL, "szStatusText == NULL\n");
549 if(szStatusText)
550 ok(lstrlenW(szStatusText) < lstrlenW(text_htmlW) ||
551 !memcmp(szStatusText, text_htmlW, lstrlenW(text_htmlW)*sizeof(WCHAR)),
552 "szStatusText != text/html\n");
553 break;
554 case BINDSTATUS_CACHEFILENAMEAVAILABLE:
555 CHECK_EXPECT(ReportProgress_CACHEFILENAMEAVAILABLE);
556 ok(szStatusText != NULL, "szStatusText == NULL\n");
557 if(szStatusText) {
558 if(binding_test)
559 ok(!lstrcmpW(szStatusText, expect_wsz), "unexpected szStatusText\n");
560 else if(tested_protocol == FILE_TEST)
561 ok(!lstrcmpW(szStatusText, file_name), "szStatusText = \"%s\"\n", debugstr_w(szStatusText));
562 else
563 ok(szStatusText != NULL, "szStatusText == NULL\n");
565 break;
566 case BINDSTATUS_FINDINGRESOURCE:
567 CHECK_EXPECT2(ReportProgress_FINDINGRESOURCE);
568 ok(szStatusText != NULL, "szStatusText == NULL\n");
569 break;
570 case BINDSTATUS_CONNECTING:
571 CHECK_EXPECT2(ReportProgress_CONNECTING);
572 ok(szStatusText != NULL, "szStatusText == NULL\n");
573 break;
574 case BINDSTATUS_SENDINGREQUEST:
575 CHECK_EXPECT2(ReportProgress_SENDINGREQUEST);
576 if(tested_protocol == FILE_TEST) {
577 ok(szStatusText != NULL, "szStatusText == NULL\n");
578 if(szStatusText)
579 ok(!*szStatusText, "wrong szStatusText\n");
581 break;
582 case BINDSTATUS_VERIFIEDMIMETYPEAVAILABLE:
583 CHECK_EXPECT(ReportProgress_VERIFIEDMIMETYPEAVAILABLE);
584 ok(szStatusText != NULL, "szStatusText == NULL\n");
585 if(szStatusText)
586 ok(!lstrcmpW(szStatusText, text_htmlW), "szStatusText != text/html\n");
587 break;
588 case BINDSTATUS_PROTOCOLCLASSID:
589 CHECK_EXPECT(ReportProgress_PROTOCOLCLASSID);
590 ok(szStatusText != NULL, "szStatusText == NULL\n");
591 ok(!lstrcmpW(szStatusText, null_guid), "unexpected szStatusText\n");
592 break;
593 case BINDSTATUS_COOKIE_SENT:
594 CHECK_EXPECT(ReportProgress_COOKIE_SENT);
595 ok(szStatusText == NULL, "szStatusText != NULL\n");
596 break;
597 case BINDSTATUS_REDIRECTING:
598 CHECK_EXPECT(ReportProgress_REDIRECTING);
599 ok(szStatusText == NULL, "szStatusText = %s\n", debugstr_w(szStatusText));
600 break;
601 case BINDSTATUS_ENCODING:
602 CHECK_EXPECT(ReportProgress_ENCODING);
603 ok(!strcmp_wa(szStatusText, "gzip"), "szStatusText = %s\n", debugstr_w(szStatusText));
604 break;
605 case BINDSTATUS_ACCEPTRANGES:
606 CHECK_EXPECT(ReportProgress_ACCEPTRANGES);
607 ok(!szStatusText, "szStatusText = %s\n", debugstr_w(szStatusText));
608 break;
609 case BINDSTATUS_PROXYDETECTING:
610 CHECK_EXPECT(ReportProgress_PROXYDETECTING);
611 SET_EXPECT(ReportProgress_CONNECTING);
612 ok(!szStatusText, "szStatusText = %s\n", debugstr_w(szStatusText));
613 break;
614 case BINDSTATUS_LOADINGMIMEHANDLER:
615 CHECK_EXPECT(ReportProgress_LOADINGMIMEHANDLER);
616 ok(!szStatusText, "szStatusText = %s\n", debugstr_w(szStatusText));
617 break;
618 case BINDSTATUS_DECODING:
619 CHECK_EXPECT(ReportProgress_DECODING);
620 ok(!lstrcmpW(szStatusText, gzipW), "szStatusText = %s\n", debugstr_w(szStatusText));
621 break;
622 default:
623 ok(0, "Unexpected status %d\n", ulStatusCode);
626 return S_OK;
629 static HRESULT WINAPI ProtocolSink_ReportData(IInternetProtocolSink *iface, DWORD grfBSCF,
630 ULONG ulProgress, ULONG ulProgressMax)
632 if(!mimefilter_test && tested_protocol == FILE_TEST) {
633 CHECK_EXPECT2(ReportData);
635 ok(ulProgress == ulProgressMax, "ulProgress (%d) != ulProgressMax (%d)\n",
636 ulProgress, ulProgressMax);
637 ok(ulProgressMax == 13, "ulProgressMax=%d, expected 13\n", ulProgressMax);
638 /* BSCF_SKIPDRAINDATAFORFILEURLS added in IE8 */
639 ok((grfBSCF == (BSCF_FIRSTDATANOTIFICATION | BSCF_LASTDATANOTIFICATION)) ||
640 (grfBSCF == (BSCF_FIRSTDATANOTIFICATION | BSCF_LASTDATANOTIFICATION | BSCF_SKIPDRAINDATAFORFILEURLS)),
641 "grcfBSCF = %08x\n", grfBSCF);
642 }else if(!binding_test && (tested_protocol == HTTP_TEST || tested_protocol == HTTPS_TEST || tested_protocol == FTP_TEST)) {
643 if(!(grfBSCF & BSCF_LASTDATANOTIFICATION) || (grfBSCF & BSCF_DATAFULLYAVAILABLE))
644 CHECK_EXPECT(ReportData);
645 else if (http_post_test)
646 ok(ulProgress == 13, "Read %u bytes instead of 13\n", ulProgress);
648 ok(ulProgress, "ulProgress == 0\n");
650 if(first_data_notif) {
651 ok(grfBSCF == BSCF_FIRSTDATANOTIFICATION
652 || grfBSCF == (BSCF_LASTDATANOTIFICATION|BSCF_DATAFULLYAVAILABLE),
653 "grcfBSCF = %08x\n", grfBSCF);
654 first_data_notif = FALSE;
655 } else {
656 ok(grfBSCF == BSCF_INTERMEDIATEDATANOTIFICATION
657 || grfBSCF == (BSCF_LASTDATANOTIFICATION|BSCF_INTERMEDIATEDATANOTIFICATION)
658 || broken(grfBSCF == (BSCF_FIRSTDATANOTIFICATION|BSCF_LASTDATANOTIFICATION)),
659 "grcfBSCF = %08x\n", grfBSCF);
662 if(!(bindf & BINDF_FROMURLMON) &&
663 !(grfBSCF & BSCF_LASTDATANOTIFICATION)) {
664 if(!state) {
665 state = 1;
666 if(http_is_first) {
667 CHECK_CALLED(ReportProgress_FINDINGRESOURCE);
668 CHECK_CALLED(ReportProgress_CONNECTING);
669 } else todo_wine {
670 CHECK_NOT_CALLED(ReportProgress_FINDINGRESOURCE);
671 CHECK_NOT_CALLED(ReportProgress_CONNECTING);
673 CHECK_CALLED(ReportProgress_SENDINGREQUEST);
674 CHECK_CALLED(OnResponse);
675 CHECK_CALLED(ReportProgress_RAWMIMETYPE);
677 SetEvent(event_complete);
679 }else {
680 BYTE buf[1000];
681 ULONG read;
682 HRESULT hres;
684 CHECK_EXPECT(ReportData);
686 if(tested_protocol == BIND_TEST)
687 return S_OK;
689 do {
690 if(mimefilter_test)
691 SET_EXPECT(MimeFilter_Read);
692 else
693 SET_EXPECT(Read);
694 hres = IInternetProtocol_Read(binding_protocol, expect_pv=buf, sizeof(buf), &read);
695 if(mimefilter_test)
696 CHECK_CALLED(MimeFilter_Read);
697 else
698 CHECK_CALLED(Read);
699 }while(hres == S_OK);
702 return S_OK;
705 static HRESULT WINAPI ProtocolSink_ReportResult(IInternetProtocolSink *iface, HRESULT hrResult,
706 DWORD dwError, LPCWSTR szResult)
708 CHECK_EXPECT(ReportResult);
710 if(tested_protocol == FTP_TEST)
711 ok(hrResult == E_PENDING || hrResult == S_OK, "hrResult = %08x, expected E_PENDING or S_OK\n", hrResult);
712 else
713 ok(hrResult == expect_hrResult, "hrResult = %08x, expected: %08x\n",
714 hrResult, expect_hrResult);
715 if(SUCCEEDED(hrResult) || tested_protocol == FTP_TEST)
716 ok(dwError == ERROR_SUCCESS, "dwError = %d, expected ERROR_SUCCESS\n", dwError);
717 else
718 ok(dwError != ERROR_SUCCESS ||
719 broken(tested_protocol == MK_TEST), /* Win9x, WinME and NT4 */
720 "dwError == ERROR_SUCCESS\n");
721 ok(!szResult, "szResult != NULL\n");
723 return S_OK;
726 static IInternetProtocolSinkVtbl protocol_sink_vtbl = {
727 ProtocolSink_QueryInterface,
728 ProtocolSink_AddRef,
729 ProtocolSink_Release,
730 ProtocolSink_Switch,
731 ProtocolSink_ReportProgress,
732 ProtocolSink_ReportData,
733 ProtocolSink_ReportResult
736 static IInternetProtocolSink protocol_sink = { &protocol_sink_vtbl };
738 static HRESULT WINAPI MimeProtocolSink_QueryInterface(IInternetProtocolSink *iface, REFIID riid, void **ppv)
740 ok(0, "unexpected call\n");
741 return E_NOTIMPL;
744 static ULONG WINAPI MimeProtocolSink_AddRef(IInternetProtocolSink *iface)
746 return 2;
749 static ULONG WINAPI MimeProtocolSink_Release(IInternetProtocolSink *iface)
751 return 1;
754 static HRESULT WINAPI MimeProtocolSink_Switch(IInternetProtocolSink *iface, PROTOCOLDATA *pProtocolData)
756 HRESULT hres;
758 CHECK_EXPECT(MimeFilter_Switch);
760 SET_EXPECT(Switch);
761 hres = IInternetProtocolSink_Switch(filtered_sink, pProtocolData);
762 ok(hres == S_OK, "Switch failed: %08x\n", hres);
763 CHECK_CALLED(Switch);
765 return S_OK;
768 static HRESULT WINAPI MimeProtocolSink_ReportProgress(IInternetProtocolSink *iface, ULONG ulStatusCode,
769 LPCWSTR szStatusText)
771 CHECK_EXPECT(MimeFilter_ReportProgress);
772 return S_OK;
775 static HRESULT WINAPI MimeProtocolSink_ReportData(IInternetProtocolSink *iface, DWORD grfBSCF,
776 ULONG ulProgress, ULONG ulProgressMax)
778 DWORD read = 0;
779 BYTE buf[8192];
780 HRESULT hres;
782 CHECK_EXPECT(MimeFilter_ReportData);
784 ok(ulProgress, "ulProgress == 0\n");
786 if(!filter_state) {
787 SET_EXPECT(Read);
788 hres = IInternetProtocol_Read(filtered_protocol, buf, sizeof(buf), &read);
789 if(tested_protocol == HTTP_TEST)
790 ok(hres == S_OK || hres == E_PENDING || hres == S_FALSE, "Read failed: %08x\n", hres);
791 else
792 ok(hres == S_OK, "Read failed: %08x\n", hres);
793 CHECK_CALLED(Read);
795 SET_EXPECT(ReportProgress_MIMETYPEAVAILABLE);
796 hres = IInternetProtocolSink_ReportProgress(filtered_sink, BINDSTATUS_VERIFIEDMIMETYPEAVAILABLE, text_htmlW);
797 ok(hres == S_OK, "ReportProgress failed: %08x\n", hres);
798 CHECK_CALLED(ReportProgress_MIMETYPEAVAILABLE);
800 /* FIXME: test BINDSTATUS_CACHEFILENAMEAVAILABLE */
803 SET_EXPECT(ReportData);
804 hres = IInternetProtocolSink_ReportData(filtered_sink, grfBSCF, ulProgress, ulProgressMax);
805 ok(hres == S_OK, "ReportData failed: %08x\n", hres);
806 CHECK_CALLED(ReportData);
808 if(!filter_state)
809 filter_state = 1;
811 return S_OK;
814 static HRESULT WINAPI MimeProtocolSink_ReportResult(IInternetProtocolSink *iface, HRESULT hrResult,
815 DWORD dwError, LPCWSTR szResult)
817 HRESULT hres;
819 CHECK_EXPECT(MimeFilter_ReportResult);
821 ok(hrResult == S_OK, "hrResult = %08x\n", hrResult);
822 ok(dwError == ERROR_SUCCESS, "dwError = %u\n", dwError);
823 ok(!szResult, "szResult = %s\n", debugstr_w(szResult));
825 SET_EXPECT(ReportResult);
826 hres = IInternetProtocolSink_ReportResult(filtered_sink, hrResult, dwError, szResult);
827 ok(SUCCEEDED(hres), "ReportResult failed: %08x\n", hres);
828 CHECK_CALLED(ReportResult);
830 return S_OK;
833 static IInternetProtocolSinkVtbl mime_protocol_sink_vtbl = {
834 MimeProtocolSink_QueryInterface,
835 MimeProtocolSink_AddRef,
836 MimeProtocolSink_Release,
837 MimeProtocolSink_Switch,
838 MimeProtocolSink_ReportProgress,
839 MimeProtocolSink_ReportData,
840 MimeProtocolSink_ReportResult
843 static IInternetProtocolSink mime_protocol_sink = { &mime_protocol_sink_vtbl };
845 static HRESULT QueryInterface(REFIID riid, void **ppv)
847 *ppv = NULL;
849 if(IsEqualGUID(&IID_IUnknown, riid) || IsEqualGUID(&IID_IInternetProtocolSink, riid))
850 *ppv = &protocol_sink;
851 if(IsEqualGUID(&IID_IServiceProvider, riid))
852 *ppv = &service_provider;
853 if(IsEqualGUID(&IID_IUriContainer, riid))
854 return E_NOINTERFACE; /* TODO */
856 if(*ppv)
857 return S_OK;
859 ok(0, "unexpected call %s\n", debugstr_guid(riid));
860 return E_NOINTERFACE;
863 static HRESULT WINAPI BindInfo_QueryInterface(IInternetBindInfo *iface, REFIID riid, void **ppv)
865 if(IsEqualGUID(&IID_IUnknown, riid) || IsEqualGUID(&IID_IInternetBindInfo, riid)) {
866 *ppv = iface;
867 return S_OK;
869 return E_NOINTERFACE;
872 static ULONG WINAPI BindInfo_AddRef(IInternetBindInfo *iface)
874 return 2;
877 static ULONG WINAPI BindInfo_Release(IInternetBindInfo *iface)
879 return 1;
882 static HRESULT WINAPI BindInfo_GetBindInfo(IInternetBindInfo *iface, DWORD *grfBINDF, BINDINFO *pbindinfo)
884 DWORD cbSize;
886 static const CHAR szPostData[] = "mode=Test";
888 CHECK_EXPECT(GetBindInfo);
890 ok(grfBINDF != NULL, "grfBINDF == NULL\n");
891 ok(pbindinfo != NULL, "pbindinfo == NULL\n");
892 ok(pbindinfo->cbSize == sizeof(BINDINFO), "wrong size of pbindinfo: %d\n", pbindinfo->cbSize);
894 *grfBINDF = bindf;
895 if(binding_test)
896 *grfBINDF |= BINDF_FROMURLMON;
897 cbSize = pbindinfo->cbSize;
898 memset(pbindinfo, 0, cbSize);
899 pbindinfo->cbSize = cbSize;
901 if (http_post_test)
903 /* Must be GMEM_FIXED, GMEM_MOVABLE does not work properly
904 * with urlmon on native (Win98 and WinXP) */
905 U(pbindinfo->stgmedData).hGlobal = GlobalAlloc(GPTR, sizeof(szPostData));
906 if (!U(pbindinfo->stgmedData).hGlobal)
908 http_post_test = FALSE;
909 skip("Out of memory\n");
910 return E_OUTOFMEMORY;
912 lstrcpy((LPSTR)U(pbindinfo->stgmedData).hGlobal, szPostData);
913 pbindinfo->cbstgmedData = sizeof(szPostData)-1;
914 pbindinfo->dwBindVerb = BINDVERB_POST;
915 pbindinfo->stgmedData.tymed = TYMED_HGLOBAL;
918 return S_OK;
921 static HRESULT WINAPI BindInfo_GetBindString(IInternetBindInfo *iface, ULONG ulStringType,
922 LPOLESTR *ppwzStr, ULONG cEl, ULONG *pcElFetched)
924 ok(ppwzStr != NULL, "ppwzStr == NULL\n");
925 ok(pcElFetched != NULL, "pcElFetched == NULL\n");
927 switch(ulStringType) {
928 case BINDSTRING_ACCEPT_MIMES:
929 CHECK_EXPECT(GetBindString_ACCEPT_MIMES);
930 ok(cEl == 256, "cEl=%d, expected 256\n", cEl);
931 if(pcElFetched) {
932 ok(*pcElFetched == 256, "*pcElFetched=%d, expected 256\n", *pcElFetched);
933 *pcElFetched = 1;
935 if(ppwzStr) {
936 *ppwzStr = CoTaskMemAlloc(sizeof(acc_mimeW));
937 memcpy(*ppwzStr, acc_mimeW, sizeof(acc_mimeW));
939 return S_OK;
940 case BINDSTRING_USER_AGENT:
941 CHECK_EXPECT(GetBindString_USER_AGENT);
942 ok(cEl == 1, "cEl=%d, expected 1\n", cEl);
943 if(pcElFetched) {
944 ok(*pcElFetched == 0, "*pcElFetch=%d, expectd 0\n", *pcElFetched);
945 *pcElFetched = 1;
947 if(ppwzStr) {
948 *ppwzStr = CoTaskMemAlloc(sizeof(user_agentW));
949 memcpy(*ppwzStr, user_agentW, sizeof(user_agentW));
951 return S_OK;
952 case BINDSTRING_POST_COOKIE:
953 CHECK_EXPECT(GetBindString_POST_COOKIE);
954 ok(cEl == 1, "cEl=%d, expected 1\n", cEl);
955 if(pcElFetched)
956 ok(*pcElFetched == 0, "*pcElFetch=%d, expectd 0\n", *pcElFetched);
957 return S_OK;
958 case BINDSTRING_URL: {
959 DWORD size;
961 CHECK_EXPECT(GetBindString_URL);
962 ok(cEl == 1, "cEl=%d, expected 1\n", cEl);
963 ok(*pcElFetched == 0, "*pcElFetch=%d, expectd 0\n", *pcElFetched);
964 *pcElFetched = 1;
966 size = (lstrlenW(binding_urls[tested_protocol])+1)*sizeof(WCHAR);
967 *ppwzStr = CoTaskMemAlloc(size);
968 memcpy(*ppwzStr, binding_urls[tested_protocol], size);
969 return S_OK;
971 default:
972 ok(0, "unexpected call\n");
975 return E_NOTIMPL;
978 static IInternetBindInfoVtbl bind_info_vtbl = {
979 BindInfo_QueryInterface,
980 BindInfo_AddRef,
981 BindInfo_Release,
982 BindInfo_GetBindInfo,
983 BindInfo_GetBindString
986 static IInternetBindInfo bind_info = { &bind_info_vtbl };
988 static HRESULT WINAPI InternetPriority_QueryInterface(IInternetPriority *iface,
989 REFIID riid, void **ppv)
991 ok(0, "unexpected call\n");
992 return E_NOINTERFACE;
995 static ULONG WINAPI InternetPriority_AddRef(IInternetPriority *iface)
997 return 2;
1000 static ULONG WINAPI InternetPriority_Release(IInternetPriority *iface)
1002 return 1;
1005 static HRESULT WINAPI InternetPriority_SetPriority(IInternetPriority *iface, LONG nPriority)
1007 CHECK_EXPECT(SetPriority);
1008 ok(nPriority == ex_priority, "nPriority=%d\n", nPriority);
1009 return S_OK;
1012 static HRESULT WINAPI InternetPriority_GetPriority(IInternetPriority *iface, LONG *pnPriority)
1014 ok(0, "unexpected call\n");
1015 return E_NOTIMPL;
1019 static const IInternetPriorityVtbl InternetPriorityVtbl = {
1020 InternetPriority_QueryInterface,
1021 InternetPriority_AddRef,
1022 InternetPriority_Release,
1023 InternetPriority_SetPriority,
1024 InternetPriority_GetPriority
1027 static IInternetPriority InternetPriority = { &InternetPriorityVtbl };
1029 static ULONG WINAPI Protocol_AddRef(IInternetProtocol *iface)
1031 return 2;
1034 static ULONG WINAPI Protocol_Release(IInternetProtocol *iface)
1036 return 1;
1039 static HRESULT WINAPI Protocol_Abort(IInternetProtocol *iface, HRESULT hrReason,
1040 DWORD dwOptions)
1042 ok(0, "unexpected call\n");
1043 return E_NOTIMPL;
1046 static HRESULT WINAPI Protocol_Suspend(IInternetProtocol *iface)
1048 ok(0, "unexpected call\n");
1049 return E_NOTIMPL;
1052 static HRESULT WINAPI Protocol_Resume(IInternetProtocol *iface)
1054 ok(0, "unexpected call\n");
1055 return E_NOTIMPL;
1058 static HRESULT WINAPI Protocol_Seek(IInternetProtocol *iface,
1059 LARGE_INTEGER dlibMove, DWORD dwOrigin, ULARGE_INTEGER *plibNewPosition)
1061 ok(0, "unexpected call\n");
1062 return E_NOTIMPL;
1065 static HRESULT WINAPI ProtocolEmul_QueryInterface(IInternetProtocol *iface, REFIID riid, void **ppv)
1067 if(IsEqualGUID(&IID_IUnknown, riid) || IsEqualGUID(&IID_IInternetProtocol, riid)) {
1068 *ppv = iface;
1069 return S_OK;
1072 if(IsEqualGUID(&IID_IInternetProtocolEx, riid)) {
1073 trace("IID_IInternetProtocolEx not supported\n");
1074 *ppv = NULL;
1075 return E_NOINTERFACE;
1078 if(IsEqualGUID(&IID_IInternetPriority, riid)) {
1079 *ppv = &InternetPriority;
1080 return S_OK;
1083 ok(0, "unexpected riid %s\n", debugstr_guid(riid));
1084 *ppv = NULL;
1085 return E_NOINTERFACE;
1088 static DWORD WINAPI thread_proc(PVOID arg)
1090 HRESULT hres;
1092 memset(&protocoldata, -1, sizeof(protocoldata));
1094 prot_state = 0;
1096 SET_EXPECT(ReportProgress_FINDINGRESOURCE);
1097 hres = IInternetProtocolSink_ReportProgress(binding_sink,
1098 BINDSTATUS_FINDINGRESOURCE, hostW);
1099 CHECK_CALLED(ReportProgress_FINDINGRESOURCE);
1100 ok(hres == S_OK, "ReportProgress failed: %08x\n", hres);
1102 SET_EXPECT(ReportProgress_CONNECTING);
1103 hres = IInternetProtocolSink_ReportProgress(binding_sink,
1104 BINDSTATUS_CONNECTING, winehq_ipW);
1105 CHECK_CALLED(ReportProgress_CONNECTING);
1106 ok(hres == S_OK, "ReportProgress failed: %08x\n", hres);
1108 SET_EXPECT(ReportProgress_SENDINGREQUEST);
1109 hres = IInternetProtocolSink_ReportProgress(binding_sink,
1110 BINDSTATUS_SENDINGREQUEST, NULL);
1111 CHECK_CALLED(ReportProgress_SENDINGREQUEST);
1112 ok(hres == S_OK, "ReportProgress failed: %08x\n", hres);
1114 prot_state = 1;
1115 SET_EXPECT(Switch);
1116 hres = IInternetProtocolSink_Switch(binding_sink, &protocoldata);
1117 CHECK_CALLED(Switch);
1118 ok(hres == S_OK, "Switch failed: %08x\n", hres);
1120 prot_state = 2;
1121 if(mimefilter_test)
1122 SET_EXPECT(MimeFilter_Switch);
1123 else
1124 SET_EXPECT(Switch);
1125 hres = IInternetProtocolSink_Switch(binding_sink, &protocoldata);
1126 ok(hres == S_OK, "Switch failed: %08x\n", hres);
1127 if(mimefilter_test)
1128 CHECK_CALLED(MimeFilter_Switch);
1129 else
1130 CHECK_CALLED(Switch);
1132 prot_state = 2;
1133 if(mimefilter_test)
1134 SET_EXPECT(MimeFilter_Switch);
1135 else
1136 SET_EXPECT(Switch);
1137 hres = IInternetProtocolSink_Switch(binding_sink, &protocoldata);
1138 ok(hres == S_OK, "Switch failed: %08x\n", hres);
1139 if(mimefilter_test)
1140 CHECK_CALLED(MimeFilter_Switch);
1141 else
1142 CHECK_CALLED(Switch);
1144 prot_state = 3;
1145 if(mimefilter_test)
1146 SET_EXPECT(MimeFilter_Switch);
1147 else
1148 SET_EXPECT(Switch);
1149 hres = IInternetProtocolSink_Switch(binding_sink, &protocoldata);
1150 ok(hres == S_OK, "Switch failed: %08x\n", hres);
1151 if(mimefilter_test)
1152 CHECK_CALLED(MimeFilter_Switch);
1153 else
1154 CHECK_CALLED(Switch);
1156 SetEvent(event_complete);
1158 return 0;
1161 static HRESULT WINAPI ProtocolEmul_Start(IInternetProtocol *iface, LPCWSTR szUrl,
1162 IInternetProtocolSink *pOIProtSink, IInternetBindInfo *pOIBindInfo,
1163 DWORD grfPI, HANDLE_PTR dwReserved)
1165 BINDINFO bindinfo, exp_bindinfo;
1166 DWORD cbindf = 0;
1167 HRESULT hres;
1169 CHECK_EXPECT(Start);
1171 ok(pOIProtSink != NULL, "pOIProtSink == NULL\n");
1172 ok(pOIBindInfo != NULL, "pOIBindInfo == NULL\n");
1173 ok(pOIProtSink != &protocol_sink, "unexpected pOIProtSink\n");
1174 ok(pOIBindInfo != &bind_info, "unexpected pOIBindInfo\n");
1175 ok(!grfPI, "grfPI = %x\n", grfPI);
1176 ok(!dwReserved, "dwReserved = %lx\n", dwReserved);
1178 if(binding_test)
1179 ok(pOIProtSink == binding_sink, "pOIProtSink != binding_sink\n");
1181 memset(&bindinfo, 0, sizeof(bindinfo));
1182 bindinfo.cbSize = sizeof(bindinfo);
1183 memcpy(&exp_bindinfo, &bindinfo, sizeof(bindinfo));
1184 SET_EXPECT(GetBindInfo);
1185 hres = IInternetBindInfo_GetBindInfo(pOIBindInfo, &cbindf, &bindinfo);
1186 ok(hres == S_OK, "GetBindInfo failed: %08x\n", hres);
1187 CHECK_CALLED(GetBindInfo);
1188 ok(cbindf == (bindf|BINDF_FROMURLMON), "bindf = %x, expected %x\n",
1189 cbindf, (bindf|BINDF_FROMURLMON));
1190 ok(!memcmp(&exp_bindinfo, &bindinfo, sizeof(bindinfo)), "unexpected bindinfo\n");
1191 ReleaseBindInfo(&bindinfo);
1193 SET_EXPECT(ReportProgress_SENDINGREQUEST);
1194 hres = IInternetProtocolSink_ReportProgress(pOIProtSink, BINDSTATUS_SENDINGREQUEST, emptyW);
1195 ok(hres == S_OK, "ReportProgress(BINDSTATUS_SENDINGREQUEST) failed: %08x\n", hres);
1196 CHECK_CALLED(ReportProgress_SENDINGREQUEST);
1198 if(tested_protocol == HTTP_TEST || tested_protocol == HTTPS_TEST) {
1199 IServiceProvider *service_provider;
1200 IHttpNegotiate *http_negotiate;
1201 IHttpNegotiate2 *http_negotiate2;
1202 LPWSTR ua = (LPWSTR)0xdeadbeef, accept_mimes[256];
1203 LPWSTR additional_headers = NULL;
1204 BYTE sec_id[100];
1205 DWORD fetched = 0, size = 100;
1206 DWORD tid;
1208 SET_EXPECT(GetBindString_USER_AGENT);
1209 hres = IInternetBindInfo_GetBindString(pOIBindInfo, BINDSTRING_USER_AGENT,
1210 &ua, 1, &fetched);
1211 CHECK_CALLED(GetBindString_USER_AGENT);
1212 ok(hres == S_OK, "GetBindString(BINDSTRING_USER_AGETNT) failed: %08x\n", hres);
1213 ok(fetched == 1, "fetched = %d, expected 254\n", fetched);
1214 ok(ua != NULL, "ua = %p\n", ua);
1215 ok(!lstrcmpW(ua, user_agentW), "unexpected user agent %s\n", debugstr_w(ua));
1216 CoTaskMemFree(ua);
1218 fetched = 256;
1219 SET_EXPECT(GetBindString_ACCEPT_MIMES);
1220 hres = IInternetBindInfo_GetBindString(pOIBindInfo, BINDSTRING_ACCEPT_MIMES,
1221 accept_mimes, 256, &fetched);
1222 CHECK_CALLED(GetBindString_ACCEPT_MIMES);
1224 ok(hres == S_OK,
1225 "GetBindString(BINDSTRING_ACCEPT_MIMES) failed: %08x\n", hres);
1226 ok(fetched == 1, "fetched = %d, expected 1\n", fetched);
1227 ok(!lstrcmpW(acc_mimeW, accept_mimes[0]), "unexpected mimes %s\n", debugstr_w(accept_mimes[0]));
1229 hres = IInternetBindInfo_QueryInterface(pOIBindInfo, &IID_IServiceProvider,
1230 (void**)&service_provider);
1231 ok(hres == S_OK, "QueryInterface failed: %08x\n", hres);
1233 SET_EXPECT(QueryService_HttpNegotiate);
1234 hres = IServiceProvider_QueryService(service_provider, &IID_IHttpNegotiate,
1235 &IID_IHttpNegotiate, (void**)&http_negotiate);
1236 CHECK_CALLED(QueryService_HttpNegotiate);
1237 ok(hres == S_OK, "QueryService failed: %08x\n", hres);
1239 SET_EXPECT(BeginningTransaction);
1240 hres = IHttpNegotiate_BeginningTransaction(http_negotiate, binding_urls[tested_protocol],
1241 NULL, 0, &additional_headers);
1242 CHECK_CALLED(BeginningTransaction);
1243 IHttpNegotiate_Release(http_negotiate);
1244 ok(hres == S_OK, "BeginningTransction failed: %08x\n", hres);
1245 ok(additional_headers == NULL, "additional_headers=%p\n", additional_headers);
1247 SET_EXPECT(QueryService_HttpNegotiate);
1248 hres = IServiceProvider_QueryService(service_provider, &IID_IHttpNegotiate2,
1249 &IID_IHttpNegotiate2, (void**)&http_negotiate2);
1250 CHECK_CALLED(QueryService_HttpNegotiate);
1251 ok(hres == S_OK, "QueryService failed: %08x\n", hres);
1253 size = 512;
1254 SET_EXPECT(GetRootSecurityId);
1255 hres = IHttpNegotiate2_GetRootSecurityId(http_negotiate2, sec_id, &size, 0);
1256 CHECK_CALLED(GetRootSecurityId);
1257 IHttpNegotiate2_Release(http_negotiate2);
1258 ok(hres == E_FAIL, "GetRootSecurityId failed: %08x, expected E_FAIL\n", hres);
1259 ok(size == 13, "size=%d\n", size);
1261 IServiceProvider_Release(service_provider);
1263 CreateThread(NULL, 0, thread_proc, NULL, 0, &tid);
1265 return S_OK;
1268 SET_EXPECT(ReportProgress_CACHEFILENAMEAVAILABLE);
1269 hres = IInternetProtocolSink_ReportProgress(pOIProtSink,
1270 BINDSTATUS_CACHEFILENAMEAVAILABLE, expect_wsz = emptyW);
1271 ok(hres == S_OK, "ReportProgress(BINDSTATUS_CACHEFILENAMEAVAILABLE) failed: %08x\n", hres);
1272 CHECK_CALLED(ReportProgress_CACHEFILENAMEAVAILABLE);
1274 if(mimefilter_test) {
1275 SET_EXPECT(MimeFilter_CreateInstance);
1276 SET_EXPECT(MimeFilter_Start);
1277 SET_EXPECT(ReportProgress_LOADINGMIMEHANDLER);
1279 SET_EXPECT(ReportProgress_MIMETYPEAVAILABLE);
1280 hres = IInternetProtocolSink_ReportProgress(pOIProtSink, BINDSTATUS_VERIFIEDMIMETYPEAVAILABLE,
1281 mimefilter_test ? gzipW : (expect_wsz = text_htmlW));
1282 ok(hres == S_OK,
1283 "ReportProgress(BINDSTATUS_VERIFIEDMIMETYPEAVAILABLE) failed: %08x\n", hres);
1284 if(mimefilter_test) {
1285 CHECK_CALLED(MimeFilter_CreateInstance);
1286 CHECK_CALLED(MimeFilter_Start);
1287 CHECK_CALLED(ReportProgress_LOADINGMIMEHANDLER);
1288 todo_wine CHECK_CALLED(ReportProgress_MIMETYPEAVAILABLE);
1289 }else {
1290 CHECK_CALLED(ReportProgress_MIMETYPEAVAILABLE);
1293 if(mimefilter_test)
1294 SET_EXPECT(MimeFilter_ReportData);
1295 else
1296 SET_EXPECT(ReportData);
1297 hres = IInternetProtocolSink_ReportData(pOIProtSink,
1298 BSCF_FIRSTDATANOTIFICATION | BSCF_LASTDATANOTIFICATION, 13, 13);
1299 ok(hres == S_OK, "ReportData failed: %08x\n", hres);
1300 if(mimefilter_test)
1301 CHECK_CALLED(MimeFilter_ReportData);
1302 else
1303 CHECK_CALLED(ReportData);
1305 if(tested_protocol == BIND_TEST) {
1306 hres = IInternetProtocol_Terminate(binding_protocol, 0);
1307 ok(hres == E_FAIL, "Termiante failed: %08x\n", hres);
1310 if(mimefilter_test)
1311 SET_EXPECT(MimeFilter_ReportResult);
1312 else
1313 SET_EXPECT(ReportResult);
1314 hres = IInternetProtocolSink_ReportResult(pOIProtSink, S_OK, 0, NULL);
1315 ok(hres == S_OK, "ReportResult failed: %08x\n", hres);
1316 if(mimefilter_test)
1317 CHECK_CALLED(MimeFilter_ReportResult);
1318 else
1319 CHECK_CALLED(ReportResult);
1321 return S_OK;
1324 static HRESULT WINAPI ProtocolEmul_Continue(IInternetProtocol *iface,
1325 PROTOCOLDATA *pProtocolData)
1327 DWORD bscf = 0, pr;
1328 HRESULT hres;
1330 CHECK_EXPECT(Continue);
1332 ok(pProtocolData != NULL, "pProtocolData == NULL\n");
1333 if(!pProtocolData || tested_protocol == BIND_TEST)
1334 return S_OK;
1335 if(binding_test) {
1336 ok(pProtocolData != &protocoldata, "pProtocolData == &protocoldata\n");
1337 ok(pProtocolData->grfFlags == protocoldata.grfFlags, "grfFlags wrong %x/%x\n",
1338 pProtocolData->grfFlags, protocoldata.grfFlags );
1339 ok(pProtocolData->dwState == protocoldata.dwState, "dwState wrong %x/%x\n",
1340 pProtocolData->dwState, protocoldata.dwState );
1341 ok(pProtocolData->pData == protocoldata.pData, "pData wrong %p/%p\n",
1342 pProtocolData->pData, protocoldata.pData );
1343 ok(pProtocolData->cbData == protocoldata.cbData, "cbData wrong %x/%x\n",
1344 pProtocolData->cbData, protocoldata.cbData );
1347 switch(prot_state) {
1348 case 1: {
1349 IServiceProvider *service_provider;
1350 IHttpNegotiate *http_negotiate;
1351 static WCHAR header[] = {'?',0};
1353 hres = IInternetProtocolSink_QueryInterface(binding_sink, &IID_IServiceProvider,
1354 (void**)&service_provider);
1355 ok(hres == S_OK, "Could not get IServiceProvicder\n");
1357 SET_EXPECT(QueryService_HttpNegotiate);
1358 hres = IServiceProvider_QueryService(service_provider, &IID_IHttpNegotiate,
1359 &IID_IHttpNegotiate, (void**)&http_negotiate);
1360 IServiceProvider_Release(service_provider);
1361 CHECK_CALLED(QueryService_HttpNegotiate);
1362 ok(hres == S_OK, "Could not get IHttpNegotiate\n");
1364 SET_EXPECT(OnResponse);
1365 hres = IHttpNegotiate_OnResponse(http_negotiate, 200, header, NULL, NULL);
1366 IHttpNegotiate_Release(http_negotiate);
1367 CHECK_CALLED(OnResponse);
1368 IHttpNegotiate_Release(http_negotiate);
1369 ok(hres == S_OK, "OnResponse failed: %08x\n", hres);
1371 if(mimefilter_test) {
1372 SET_EXPECT(MimeFilter_CreateInstance);
1373 SET_EXPECT(MimeFilter_Start);
1374 SET_EXPECT(ReportProgress_LOADINGMIMEHANDLER);
1375 }else if(!(pi & PI_MIMEVERIFICATION)) {
1376 SET_EXPECT(ReportProgress_MIMETYPEAVAILABLE);
1378 hres = IInternetProtocolSink_ReportProgress(binding_sink,
1379 BINDSTATUS_MIMETYPEAVAILABLE, mimefilter_test ? gzipW : text_htmlW);
1380 if(mimefilter_test) {
1381 CHECK_CALLED(MimeFilter_CreateInstance);
1382 CHECK_CALLED(MimeFilter_Start);
1383 CHECK_CALLED(ReportProgress_LOADINGMIMEHANDLER);
1384 }else if(!(pi & PI_MIMEVERIFICATION)) {
1385 CHECK_CALLED(ReportProgress_MIMETYPEAVAILABLE);
1387 ok(hres == S_OK,
1388 "ReportProgress(BINDSTATUS_MIMETYPEAVAILABLE) failed: %08x\n", hres);
1390 bscf |= BSCF_FIRSTDATANOTIFICATION;
1391 break;
1393 case 2:
1394 case 3:
1395 bscf = BSCF_INTERMEDIATEDATANOTIFICATION;
1396 break;
1399 pr = prot_read;
1400 if(mimefilter_test) {
1401 SET_EXPECT(MimeFilter_ReportData);
1402 }else if(pi & PI_MIMEVERIFICATION) {
1403 if(pr < 200)
1404 SET_EXPECT(Read);
1405 if(pr == 200) {
1406 SET_EXPECT(Read);
1407 SET_EXPECT(ReportProgress_MIMETYPEAVAILABLE);
1409 if(pr >= 200)
1410 SET_EXPECT(ReportData);
1411 }else {
1412 SET_EXPECT(ReportData);
1415 hres = IInternetProtocolSink_ReportData(binding_sink, bscf, 100, 400);
1416 ok(hres == S_OK, "ReportData failed: %08x\n", hres);
1418 if(mimefilter_test) {
1419 SET_EXPECT(MimeFilter_ReportData);
1420 }else if(pi & PI_MIMEVERIFICATION) {
1421 if(pr < 200)
1422 CHECK_CALLED(Read);
1423 if(pr == 200) {
1424 CLEAR_CALLED(Read);
1425 CHECK_CALLED(ReportProgress_MIMETYPEAVAILABLE);
1427 }else {
1428 CHECK_CALLED(ReportData);
1431 if(prot_state == 3)
1432 prot_state = 4;
1434 return S_OK;
1437 static HRESULT WINAPI ProtocolEmul_Terminate(IInternetProtocol *iface, DWORD dwOptions)
1439 CHECK_EXPECT(Terminate);
1440 ok(!dwOptions, "dwOptions=%d\n", dwOptions);
1441 return S_OK;
1444 static HRESULT WINAPI ProtocolEmul_Read(IInternetProtocol *iface, void *pv,
1445 ULONG cb, ULONG *pcbRead)
1447 if(mimefilter_test) {
1448 CHECK_EXPECT2(Read);
1449 }else if((pi & PI_MIMEVERIFICATION)) {
1450 CHECK_EXPECT2(Read);
1452 if(prot_read < 300) {
1453 ok(pv != expect_pv, "pv == expect_pv\n");
1454 if(prot_read < 300)
1455 ok(cb == 2048-prot_read, "cb=%d\n", cb);
1456 else
1457 ok(cb == 700, "cb=%d\n", cb);
1458 }else {
1459 ok(expect_pv <= pv && (BYTE*)pv < (BYTE*)expect_pv + cb, "pv != expect_pv\n");
1461 }else {
1462 CHECK_EXPECT(Read);
1464 ok(pv == expect_pv, "pv != expect_pv\n");
1465 ok(cb == 1000, "cb=%d\n", cb);
1466 ok(!*pcbRead, "*pcbRead = %d\n", *pcbRead);
1468 ok(pcbRead != NULL, "pcbRead == NULL\n");
1470 if(prot_state == 3) {
1471 HRESULT hres;
1473 if(mimefilter_test)
1474 SET_EXPECT(MimeFilter_ReportResult);
1475 else
1476 SET_EXPECT(ReportResult);
1477 hres = IInternetProtocolSink_ReportResult(binding_sink, S_OK, ERROR_SUCCESS, NULL);
1478 ok(hres == S_OK, "ReportResult failed: %08x\n", hres);
1479 if(mimefilter_test)
1480 CHECK_CALLED(MimeFilter_ReportResult);
1481 else
1482 CHECK_CALLED(ReportResult);
1484 return S_FALSE;
1487 if((async_read_pending = !async_read_pending)) {
1488 *pcbRead = 0;
1489 return tested_protocol == HTTP_TEST || tested_protocol == HTTPS_TEST ? E_PENDING : S_FALSE;
1492 memset(pv, 'x', 100);
1493 prot_read += *pcbRead = 100;
1494 return S_OK;
1497 static HRESULT WINAPI ProtocolEmul_LockRequest(IInternetProtocol *iface, DWORD dwOptions)
1499 CHECK_EXPECT(LockRequest);
1500 ok(dwOptions == 0, "dwOptions=%x\n", dwOptions);
1501 return S_OK;
1504 static HRESULT WINAPI ProtocolEmul_UnlockRequest(IInternetProtocol *iface)
1506 CHECK_EXPECT(UnlockRequest);
1507 return S_OK;
1510 static const IInternetProtocolVtbl ProtocolVtbl = {
1511 ProtocolEmul_QueryInterface,
1512 Protocol_AddRef,
1513 Protocol_Release,
1514 ProtocolEmul_Start,
1515 ProtocolEmul_Continue,
1516 Protocol_Abort,
1517 ProtocolEmul_Terminate,
1518 Protocol_Suspend,
1519 Protocol_Resume,
1520 ProtocolEmul_Read,
1521 Protocol_Seek,
1522 ProtocolEmul_LockRequest,
1523 ProtocolEmul_UnlockRequest
1526 static IInternetProtocol Protocol = { &ProtocolVtbl };
1528 static HRESULT WINAPI MimeProtocol_QueryInterface(IInternetProtocol *iface, REFIID riid, void **ppv)
1530 if(IsEqualGUID(&IID_IUnknown, riid) || IsEqualGUID(&IID_IInternetProtocol, riid)) {
1531 *ppv = iface;
1532 return S_OK;
1535 if(IsEqualGUID(&IID_IInternetProtocolSink, riid)) {
1536 *ppv = &mime_protocol_sink;
1537 return S_OK;
1540 ok(0, "unexpected riid %s\n", debugstr_guid(riid));
1541 *ppv = NULL;
1542 return E_NOINTERFACE;
1545 static HRESULT WINAPI MimeProtocol_Start(IInternetProtocol *iface, LPCWSTR szUrl,
1546 IInternetProtocolSink *pOIProtSink, IInternetBindInfo *pOIBindInfo,
1547 DWORD grfPI, HANDLE_PTR dwReserved)
1549 PROTOCOLFILTERDATA *data;
1550 LPOLESTR url_str = NULL;
1551 DWORD fetched = 0;
1552 BINDINFO bindinfo;
1553 DWORD cbindf = 0;
1554 HRESULT hres;
1556 CHECK_EXPECT(MimeFilter_Start);
1558 ok(!lstrcmpW(szUrl, gzipW), "wrong url %s\n", debugstr_w(szUrl));
1559 ok(grfPI == (PI_FILTER_MODE|PI_FORCE_ASYNC), "grfPI=%x, expected PI_FILTER_MODE|PI_FORCE_ASYNC\n", grfPI);
1560 ok(dwReserved, "dwReserved == 0\n");
1561 ok(pOIProtSink != NULL, "pOIProtSink == NULL\n");
1562 ok(pOIBindInfo != NULL, "pOIBindInfo == NULL\n");
1564 if(binding_test) {
1565 ok(pOIProtSink != binding_sink, "pOIProtSink == protocol_sink\n");
1566 ok(pOIBindInfo == prot_bind_info, "pOIBindInfo != bind_info\n");
1567 }else {
1568 ok(pOIProtSink == &protocol_sink, "pOIProtSink != protocol_sink\n");
1569 ok(pOIBindInfo == &bind_info, "pOIBindInfo != bind_info\n");
1572 data = (void*)dwReserved;
1573 ok(data->cbSize == sizeof(*data), "data->cbSize = %d\n", data->cbSize);
1574 ok(!data->pProtocolSink, "data->pProtocolSink != NULL\n");
1575 ok(data->pProtocol != NULL, "data->pProtocol == NULL\n");
1576 ok(!data->pUnk, "data->pUnk != NULL\n");
1577 ok(!data->dwFilterFlags, "data->dwProtocolFlags = %x\n", data->dwFilterFlags);
1578 if(binding_test) {
1579 IInternetProtocolSink *prot_sink;
1581 IInternetProtocol_QueryInterface(data->pProtocol, &IID_IInternetProtocolSink, (void**)&prot_sink);
1582 ok(prot_sink == pOIProtSink, "QI(data->pProtocol, IID_IInternetProtocolSink) != pOIProtSink\n");
1583 IInternetProtocolSink_Release(prot_sink);
1585 ok(data->pProtocol != binding_protocol, "data->pProtocol == binding_protocol\n");
1587 filtered_protocol = data->pProtocol;
1588 IInternetProtocol_AddRef(filtered_protocol);
1589 }else {
1590 IInternetProtocol *prot;
1592 IInternetProtocol_QueryInterface(data->pProtocol, &IID_IInternetProtocol, (void**)&prot);
1593 ok(prot == async_protocol, "QI(data->pProtocol, IID_IInternetProtocol) != async_protocol\n");
1594 IInternetProtocol_Release(prot);
1596 ok(data->pProtocol != async_protocol, "data->pProtocol == async_protocol\n");
1599 filtered_sink = pOIProtSink;
1601 SET_EXPECT(ReportProgress_DECODING);
1602 hres = IInternetProtocolSink_ReportProgress(pOIProtSink, BINDSTATUS_DECODING, gzipW);
1603 ok(hres == S_OK, "ReportProgress(BINDSTATUS_DECODING) failed: %08x\n", hres);
1604 CHECK_CALLED(ReportProgress_DECODING);
1606 SET_EXPECT(GetBindInfo);
1607 memset(&bindinfo, 0, sizeof(bindinfo));
1608 bindinfo.cbSize = sizeof(bindinfo);
1609 hres = IInternetBindInfo_GetBindInfo(pOIBindInfo, &cbindf, &bindinfo);
1610 ok(hres == S_OK, "GetBindInfo failed: %08x\n", hres);
1611 ok(cbindf == bindf, "cbindf = %x\n", cbindf);
1612 CHECK_CALLED(GetBindInfo);
1614 SET_EXPECT(GetBindString_URL);
1615 hres = IInternetBindInfo_GetBindString(pOIBindInfo, BINDSTRING_URL, &url_str, 1, &fetched);
1616 ok(hres == S_OK, "GetBindString(BINDSTRING_URL) failed: %08x\n", hres);
1617 ok(fetched == 1, "fetched = %d\n", fetched);
1618 ok(!lstrcmpW(url_str, binding_urls[tested_protocol]), "wrong url_str %s\n", debugstr_w(url_str));
1619 CoTaskMemFree(url_str);
1620 CHECK_CALLED(GetBindString_URL);
1622 return S_OK;
1625 static HRESULT WINAPI Protocol_Continue(IInternetProtocol *iface,
1626 PROTOCOLDATA *pProtocolData)
1628 CHECK_EXPECT(MimeFilter_Continue);
1629 return E_NOTIMPL;
1632 static HRESULT WINAPI MimeProtocol_Terminate(IInternetProtocol *iface, DWORD dwOptions)
1634 HRESULT hres;
1636 CHECK_EXPECT(MimeFilter_Terminate);
1638 ok(!dwOptions, "dwOptions = %x\n", dwOptions);
1640 SET_EXPECT(Terminate);
1641 hres = IInternetProtocol_Terminate(filtered_protocol, dwOptions);
1642 ok(hres == S_OK, "Terminate failed: %08x\n", hres);
1643 CHECK_CALLED(Terminate);
1645 return S_OK;
1648 static HRESULT WINAPI MimeProtocol_Read(IInternetProtocol *iface, void *pv,
1649 ULONG cb, ULONG *pcbRead)
1651 BYTE buf[2096];
1652 DWORD read = 0;
1653 HRESULT hres;
1655 CHECK_EXPECT(MimeFilter_Read);
1657 ok(pv != NULL, "pv == NULL\n");
1658 ok(cb != 0, "cb == 0\n");
1659 ok(pcbRead != NULL, "pcbRead == NULL\n");
1661 SET_EXPECT(Read);
1662 hres = IInternetProtocol_Read(filtered_protocol, buf, sizeof(buf), &read);
1663 ok(hres == S_OK || hres == S_FALSE || hres == E_PENDING, "Read failed: %08x\n", hres);
1664 CHECK_CALLED(Read);
1666 if(pcbRead) {
1667 ok(*pcbRead == 0, "*pcbRead=%d, expected 0\n", *pcbRead);
1668 *pcbRead = read;
1671 memset(pv, 'x', read);
1672 return hres;
1675 static HRESULT WINAPI MimeProtocol_LockRequest(IInternetProtocol *iface, DWORD dwOptions)
1677 HRESULT hres;
1679 CHECK_EXPECT(MimeFilter_LockRequest);
1681 ok(!dwOptions, "dwOptions = %x\n", dwOptions);
1683 SET_EXPECT(LockRequest);
1684 hres = IInternetProtocol_LockRequest(filtered_protocol, dwOptions);
1685 ok(hres == S_OK, "LockRequest failed: %08x\n", hres);
1686 CHECK_CALLED(LockRequest);
1688 return S_OK;
1691 static HRESULT WINAPI MimeProtocol_UnlockRequest(IInternetProtocol *iface)
1693 HRESULT hres;
1695 CHECK_EXPECT(MimeFilter_UnlockRequest);
1697 SET_EXPECT(UnlockRequest);
1698 hres = IInternetProtocol_UnlockRequest(filtered_protocol);
1699 ok(hres == S_OK, "UnlockRequest failed: %08x\n", hres);
1700 CHECK_CALLED(UnlockRequest);
1702 return S_OK;
1705 static const IInternetProtocolVtbl MimeProtocolVtbl = {
1706 MimeProtocol_QueryInterface,
1707 Protocol_AddRef,
1708 Protocol_Release,
1709 MimeProtocol_Start,
1710 Protocol_Continue,
1711 Protocol_Abort,
1712 MimeProtocol_Terminate,
1713 Protocol_Suspend,
1714 Protocol_Resume,
1715 MimeProtocol_Read,
1716 Protocol_Seek,
1717 MimeProtocol_LockRequest,
1718 MimeProtocol_UnlockRequest
1721 static IInternetProtocol MimeProtocol = { &MimeProtocolVtbl };
1723 static HRESULT WINAPI ClassFactory_QueryInterface(IClassFactory *iface, REFIID riid, void **ppv)
1725 ok(0, "unexpected call\n");
1726 return E_NOINTERFACE;
1729 static ULONG WINAPI ClassFactory_AddRef(IClassFactory *iface)
1731 return 2;
1734 static ULONG WINAPI ClassFactory_Release(IClassFactory *iface)
1736 return 1;
1739 static HRESULT WINAPI ClassFactory_CreateInstance(IClassFactory *iface, IUnknown *pOuter,
1740 REFIID riid, void **ppv)
1742 CHECK_EXPECT(CreateInstance);
1744 ok(pOuter == (IUnknown*)prot_bind_info, "pOuter != protocol_unk\n");
1745 ok(IsEqualGUID(&IID_IUnknown, riid), "unexpected riid %s\n", debugstr_guid(riid));
1746 ok(ppv != NULL, "ppv == NULL\n");
1748 *ppv = &Protocol;
1749 return S_OK;
1752 static HRESULT WINAPI ClassFactory_LockServer(IClassFactory *iface, BOOL dolock)
1754 ok(0, "unexpected call\n");
1755 return S_OK;
1758 static const IClassFactoryVtbl ClassFactoryVtbl = {
1759 ClassFactory_QueryInterface,
1760 ClassFactory_AddRef,
1761 ClassFactory_Release,
1762 ClassFactory_CreateInstance,
1763 ClassFactory_LockServer
1766 static IClassFactory ClassFactory = { &ClassFactoryVtbl };
1768 static HRESULT WINAPI MimeFilter_CreateInstance(IClassFactory *iface, IUnknown *outer, REFIID riid, void **ppv)
1770 CHECK_EXPECT(MimeFilter_CreateInstance);
1772 ok(!outer, "outer = %p\n", outer);
1773 ok(IsEqualGUID(&IID_IInternetProtocol, riid), "unexpected riid %s\n", debugstr_guid(riid));
1775 *ppv = &MimeProtocol;
1776 return S_OK;
1779 static const IClassFactoryVtbl MimeFilterCFVtbl = {
1780 ClassFactory_QueryInterface,
1781 ClassFactory_AddRef,
1782 ClassFactory_Release,
1783 MimeFilter_CreateInstance,
1784 ClassFactory_LockServer
1787 static IClassFactory mimefilter_cf = { &MimeFilterCFVtbl };
1789 #define TEST_BINDING 1
1790 #define TEST_FILTER 2
1792 static void init_test(int prot, DWORD flags)
1794 tested_protocol = prot;
1795 binding_test = (flags & TEST_BINDING) != 0;
1796 first_data_notif = TRUE;
1797 prot_read = 0;
1798 prot_state = 0;
1799 async_read_pending = TRUE;
1800 mimefilter_test = (flags & TEST_FILTER) != 0;
1801 filter_state = 0;
1802 ResetEvent(event_complete);
1803 ResetEvent(event_complete2);
1804 async_protocol = binding_protocol = filtered_protocol = NULL;
1805 filtered_sink = NULL;
1808 static void test_priority(IInternetProtocol *protocol)
1810 IInternetPriority *priority;
1811 LONG pr;
1812 HRESULT hres;
1814 hres = IInternetProtocol_QueryInterface(protocol, &IID_IInternetPriority,
1815 (void**)&priority);
1816 ok(hres == S_OK, "QueryInterface(IID_IInternetPriority) failed: %08x\n", hres);
1817 if(FAILED(hres))
1818 return;
1820 hres = IInternetPriority_GetPriority(priority, &pr);
1821 ok(hres == S_OK, "GetPriority failed: %08x\n", hres);
1822 ok(pr == 0, "pr=%d, expected 0\n", pr);
1824 hres = IInternetPriority_SetPriority(priority, 1);
1825 ok(hres == S_OK, "SetPriority failed: %08x\n", hres);
1827 hres = IInternetPriority_GetPriority(priority, &pr);
1828 ok(hres == S_OK, "GetPriority failed: %08x\n", hres);
1829 ok(pr == 1, "pr=%d, expected 1\n", pr);
1831 IInternetPriority_Release(priority);
1834 static BOOL file_protocol_start(IInternetProtocol *protocol, LPCWSTR url, BOOL is_first)
1836 HRESULT hres;
1838 SET_EXPECT(GetBindInfo);
1839 if(!(bindf & BINDF_FROMURLMON))
1840 SET_EXPECT(ReportProgress_DIRECTBIND);
1841 if(is_first) {
1842 SET_EXPECT(ReportProgress_SENDINGREQUEST);
1843 SET_EXPECT(ReportProgress_CACHEFILENAMEAVAILABLE);
1844 if(bindf & BINDF_FROMURLMON)
1845 SET_EXPECT(ReportProgress_VERIFIEDMIMETYPEAVAILABLE);
1846 else
1847 SET_EXPECT(ReportProgress_MIMETYPEAVAILABLE);
1849 SET_EXPECT(ReportData);
1850 if(is_first)
1851 SET_EXPECT(ReportResult);
1853 expect_hrResult = S_OK;
1855 hres = IInternetProtocol_Start(protocol, url, &protocol_sink, &bind_info, 0, 0);
1856 if(hres == INET_E_RESOURCE_NOT_FOUND) {
1857 win_skip("Start failed\n");
1858 return FALSE;
1860 ok(hres == S_OK, "Start failed: %08x\n", hres);
1862 CHECK_CALLED(GetBindInfo);
1863 if(!(bindf & BINDF_FROMURLMON))
1864 CHECK_CALLED(ReportProgress_DIRECTBIND);
1865 if(is_first) {
1866 CHECK_CALLED(ReportProgress_SENDINGREQUEST);
1867 CHECK_CALLED(ReportProgress_CACHEFILENAMEAVAILABLE);
1868 if(bindf & BINDF_FROMURLMON)
1869 CHECK_CALLED(ReportProgress_VERIFIEDMIMETYPEAVAILABLE);
1870 else
1871 CHECK_CALLED(ReportProgress_MIMETYPEAVAILABLE);
1873 CHECK_CALLED(ReportData);
1874 if(is_first)
1875 CHECK_CALLED(ReportResult);
1877 return TRUE;
1880 static void test_file_protocol_url(LPCWSTR url)
1882 IInternetProtocolInfo *protocol_info;
1883 IUnknown *unk;
1884 IClassFactory *factory;
1885 HRESULT hres;
1887 hres = CoGetClassObject(&CLSID_FileProtocol, CLSCTX_INPROC_SERVER, NULL,
1888 &IID_IUnknown, (void**)&unk);
1889 ok(hres == S_OK, "CoGetClassObject failed: %08x\n", hres);
1890 if(FAILED(hres))
1891 return;
1893 hres = IUnknown_QueryInterface(unk, &IID_IInternetProtocolInfo, (void**)&protocol_info);
1894 ok(hres == E_NOINTERFACE,
1895 "Could not get IInternetProtocolInfo interface: %08x, expected E_NOINTERFACE\n", hres);
1897 hres = IUnknown_QueryInterface(unk, &IID_IClassFactory, (void**)&factory);
1898 ok(hres == S_OK, "Could not get IClassFactory interface\n");
1899 if(SUCCEEDED(hres)) {
1900 IInternetProtocol *protocol;
1901 BYTE buf[512];
1902 ULONG cb;
1903 hres = IClassFactory_CreateInstance(factory, NULL, &IID_IInternetProtocol, (void**)&protocol);
1904 ok(hres == S_OK, "Could not get IInternetProtocol: %08x\n", hres);
1906 if(SUCCEEDED(hres)) {
1907 if(file_protocol_start(protocol, url, TRUE)) {
1908 hres = IInternetProtocol_Read(protocol, buf, 2, &cb);
1909 ok(hres == S_OK, "Read failed: %08x\n", hres);
1910 ok(cb == 2, "cb=%u expected 2\n", cb);
1911 hres = IInternetProtocol_Read(protocol, buf, sizeof(buf), &cb);
1912 ok(hres == S_FALSE, "Read failed: %08x\n", hres);
1913 hres = IInternetProtocol_Read(protocol, buf, sizeof(buf), &cb);
1914 ok(hres == S_FALSE, "Read failed: %08x expected S_FALSE\n", hres);
1915 ok(cb == 0, "cb=%u expected 0\n", cb);
1916 hres = IInternetProtocol_UnlockRequest(protocol);
1917 ok(hres == S_OK, "UnlockRequest failed: %08x\n", hres);
1920 if(file_protocol_start(protocol, url, FALSE)) {
1921 hres = IInternetProtocol_Read(protocol, buf, 2, &cb);
1922 ok(hres == S_FALSE, "Read failed: %08x\n", hres);
1923 hres = IInternetProtocol_LockRequest(protocol, 0);
1924 ok(hres == S_OK, "LockRequest failed: %08x\n", hres);
1925 hres = IInternetProtocol_UnlockRequest(protocol);
1926 ok(hres == S_OK, "UnlockRequest failed: %08x\n", hres);
1929 IInternetProtocol_Release(protocol);
1932 hres = IClassFactory_CreateInstance(factory, NULL, &IID_IInternetProtocol, (void**)&protocol);
1933 ok(hres == S_OK, "Could not get IInternetProtocol: %08x\n", hres);
1935 if(SUCCEEDED(hres)) {
1936 if(file_protocol_start(protocol, url, TRUE)) {
1937 hres = IInternetProtocol_LockRequest(protocol, 0);
1938 ok(hres == S_OK, "LockRequest failed: %08x\n", hres);
1939 hres = IInternetProtocol_Terminate(protocol, 0);
1940 ok(hres == S_OK, "Terminate failed: %08x\n", hres);
1941 hres = IInternetProtocol_Read(protocol, buf, 2, &cb);
1942 ok(hres == S_OK, "Read failed: %08x\n\n", hres);
1943 hres = IInternetProtocol_UnlockRequest(protocol);
1944 ok(hres == S_OK, "UnlockRequest failed: %08x\n", hres);
1945 hres = IInternetProtocol_Read(protocol, buf, 2, &cb);
1946 ok(hres == S_OK, "Read failed: %08x\n", hres);
1947 hres = IInternetProtocol_Terminate(protocol, 0);
1948 ok(hres == S_OK, "Terminate failed: %08x\n", hres);
1951 IInternetProtocol_Release(protocol);
1954 hres = IClassFactory_CreateInstance(factory, NULL, &IID_IInternetProtocol, (void**)&protocol);
1955 ok(hres == S_OK, "Could not get IInternetProtocol: %08x\n", hres);
1957 if(SUCCEEDED(hres)) {
1958 if(file_protocol_start(protocol, url, TRUE)) {
1959 hres = IInternetProtocol_Terminate(protocol, 0);
1960 ok(hres == S_OK, "Terminate failed: %08x\n", hres);
1961 hres = IInternetProtocol_Read(protocol, buf, 2, &cb);
1962 ok(hres == S_OK, "Read failed: %08x\n", hres);
1963 ok(cb == 2, "cb=%u expected 2\n", cb);
1966 IInternetProtocol_Release(protocol);
1969 IClassFactory_Release(factory);
1972 IUnknown_Release(unk);
1975 static void test_file_protocol_fail(void)
1977 IInternetProtocol *protocol;
1978 HRESULT hres;
1980 static const WCHAR index_url2[] =
1981 {'f','i','l','e',':','/','/','i','n','d','e','x','.','h','t','m','l',0};
1983 hres = CoCreateInstance(&CLSID_FileProtocol, NULL, CLSCTX_INPROC_SERVER|CLSCTX_INPROC_HANDLER,
1984 &IID_IInternetProtocol, (void**)&protocol);
1985 ok(hres == S_OK, "CoCreateInstance failed: %08x\n", hres);
1986 if(FAILED(hres))
1987 return;
1989 SET_EXPECT(GetBindInfo);
1990 expect_hrResult = MK_E_SYNTAX;
1991 hres = IInternetProtocol_Start(protocol, wszIndexHtml, &protocol_sink, &bind_info, 0, 0);
1992 ok(hres == MK_E_SYNTAX ||
1993 hres == E_INVALIDARG,
1994 "Start failed: %08x, expected MK_E_SYNTAX or E_INVALIDARG\n", hres);
1995 CLEAR_CALLED(GetBindInfo); /* GetBindInfo not called in IE7 */
1997 SET_EXPECT(GetBindInfo);
1998 if(!(bindf & BINDF_FROMURLMON))
1999 SET_EXPECT(ReportProgress_DIRECTBIND);
2000 SET_EXPECT(ReportProgress_SENDINGREQUEST);
2001 SET_EXPECT(ReportResult);
2002 expect_hrResult = INET_E_RESOURCE_NOT_FOUND;
2003 hres = IInternetProtocol_Start(protocol, index_url, &protocol_sink, &bind_info, 0, 0);
2004 ok(hres == INET_E_RESOURCE_NOT_FOUND,
2005 "Start failed: %08x expected INET_E_RESOURCE_NOT_FOUND\n", hres);
2006 CHECK_CALLED(GetBindInfo);
2007 if(!(bindf & BINDF_FROMURLMON))
2008 CHECK_CALLED(ReportProgress_DIRECTBIND);
2009 CHECK_CALLED(ReportProgress_SENDINGREQUEST);
2010 CHECK_CALLED(ReportResult);
2012 IInternetProtocol_Release(protocol);
2014 hres = CoCreateInstance(&CLSID_FileProtocol, NULL, CLSCTX_INPROC_SERVER|CLSCTX_INPROC_HANDLER,
2015 &IID_IInternetProtocol, (void**)&protocol);
2016 ok(hres == S_OK, "CoCreateInstance failed: %08x\n", hres);
2017 if(FAILED(hres))
2018 return;
2020 SET_EXPECT(GetBindInfo);
2021 if(!(bindf & BINDF_FROMURLMON))
2022 SET_EXPECT(ReportProgress_DIRECTBIND);
2023 SET_EXPECT(ReportProgress_SENDINGREQUEST);
2024 SET_EXPECT(ReportResult);
2025 expect_hrResult = INET_E_RESOURCE_NOT_FOUND;
2027 hres = IInternetProtocol_Start(protocol, index_url2, &protocol_sink, &bind_info, 0, 0);
2028 ok(hres == INET_E_RESOURCE_NOT_FOUND,
2029 "Start failed: %08x, expected INET_E_RESOURCE_NOT_FOUND\n", hres);
2030 CHECK_CALLED(GetBindInfo);
2031 if(!(bindf & BINDF_FROMURLMON))
2032 CHECK_CALLED(ReportProgress_DIRECTBIND);
2033 CHECK_CALLED(ReportProgress_SENDINGREQUEST);
2034 CHECK_CALLED(ReportResult);
2036 SET_EXPECT(GetBindInfo);
2037 hres = IInternetProtocol_Start(protocol, NULL, &protocol_sink, &bind_info, 0, 0);
2038 ok(hres == E_INVALIDARG, "Start failed: %08x, expected E_INVALIDARG\n", hres);
2039 CLEAR_CALLED(GetBindInfo); /* GetBindInfo not called in IE7 */
2041 SET_EXPECT(GetBindInfo);
2042 hres = IInternetProtocol_Start(protocol, emptyW, &protocol_sink, &bind_info, 0, 0);
2043 ok(hres == E_INVALIDARG, "Start failed: %08x, expected E_INVALIDARG\n", hres);
2044 CLEAR_CALLED(GetBindInfo); /* GetBindInfo not called in IE7 */
2046 IInternetProtocol_Release(protocol);
2049 static void test_file_protocol(void) {
2050 WCHAR buf[INTERNET_MAX_URL_LENGTH], file_name_buf[MAX_PATH];
2051 DWORD size;
2052 ULONG len;
2053 HANDLE file;
2055 static const WCHAR wszFile[] = {'f','i','l','e',':',0};
2056 static const WCHAR wszFile2[] = {'f','i','l','e',':','/','/',0};
2057 static const WCHAR wszFile3[] = {'f','i','l','e',':','/','/','/',0};
2058 static const char html_doc[] = "<HTML></HTML>";
2060 trace("Testing file protocol...\n");
2061 init_test(FILE_TEST, 0);
2063 SetLastError(0xdeadbeef);
2064 file = CreateFileW(wszIndexHtml, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS,
2065 FILE_ATTRIBUTE_NORMAL, NULL);
2066 if(!file && GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)
2068 win_skip("Detected Win9x or WinMe\n");
2069 return;
2071 ok(file != INVALID_HANDLE_VALUE, "CreateFile failed\n");
2072 if(file == INVALID_HANDLE_VALUE)
2073 return;
2074 WriteFile(file, html_doc, sizeof(html_doc)-1, &size, NULL);
2075 CloseHandle(file);
2077 file_name = wszIndexHtml;
2078 bindf = 0;
2079 test_file_protocol_url(index_url);
2080 bindf = BINDF_FROMURLMON;
2081 test_file_protocol_url(index_url);
2082 bindf = BINDF_FROMURLMON | BINDF_NEEDFILE;
2083 test_file_protocol_url(index_url);
2085 memcpy(buf, wszFile, sizeof(wszFile));
2086 len = sizeof(wszFile)/sizeof(WCHAR)-1;
2087 len += GetCurrentDirectoryW(sizeof(buf)/sizeof(WCHAR)-len, buf+len);
2088 buf[len++] = '\\';
2089 memcpy(buf+len, wszIndexHtml, sizeof(wszIndexHtml));
2091 file_name = buf + sizeof(wszFile)/sizeof(WCHAR)-1;
2092 bindf = 0;
2093 test_file_protocol_url(buf);
2094 bindf = BINDF_FROMURLMON;
2095 test_file_protocol_url(buf);
2097 memcpy(buf, wszFile2, sizeof(wszFile2));
2098 len = GetCurrentDirectoryW(sizeof(file_name_buf)/sizeof(WCHAR), file_name_buf);
2099 file_name_buf[len++] = '\\';
2100 memcpy(file_name_buf+len, wszIndexHtml, sizeof(wszIndexHtml));
2101 lstrcpyW(buf+sizeof(wszFile2)/sizeof(WCHAR)-1, file_name_buf);
2102 file_name = file_name_buf;
2103 bindf = 0;
2104 test_file_protocol_url(buf);
2105 bindf = BINDF_FROMURLMON;
2106 test_file_protocol_url(buf);
2108 buf[sizeof(wszFile2)/sizeof(WCHAR)] = '|';
2109 test_file_protocol_url(buf);
2111 memcpy(buf, wszFile3, sizeof(wszFile3));
2112 len = sizeof(wszFile3)/sizeof(WCHAR)-1;
2113 len += GetCurrentDirectoryW(sizeof(buf)/sizeof(WCHAR)-len, buf+len);
2114 buf[len++] = '\\';
2115 memcpy(buf+len, wszIndexHtml, sizeof(wszIndexHtml));
2117 file_name = buf + sizeof(wszFile3)/sizeof(WCHAR)-1;
2118 bindf = 0;
2119 test_file_protocol_url(buf);
2120 bindf = BINDF_FROMURLMON;
2121 test_file_protocol_url(buf);
2123 DeleteFileW(wszIndexHtml);
2125 bindf = 0;
2126 test_file_protocol_fail();
2127 bindf = BINDF_FROMURLMON;
2128 test_file_protocol_fail();
2131 static BOOL http_protocol_start(LPCWSTR url, BOOL is_first)
2133 static BOOL got_user_agent = FALSE;
2134 HRESULT hres;
2136 first_data_notif = TRUE;
2137 state = 0;
2139 SET_EXPECT(GetBindInfo);
2140 if (!(bindf & BINDF_FROMURLMON))
2141 SET_EXPECT(ReportProgress_DIRECTBIND);
2142 SET_EXPECT(GetBindString_USER_AGENT);
2143 SET_EXPECT(GetBindString_ACCEPT_MIMES);
2144 SET_EXPECT(QueryService_HttpNegotiate);
2145 SET_EXPECT(BeginningTransaction);
2146 SET_EXPECT(GetRootSecurityId);
2147 if (http_post_test)
2148 SET_EXPECT(GetBindString_POST_COOKIE);
2150 hres = IInternetProtocol_Start(async_protocol, url, &protocol_sink, &bind_info, 0, 0);
2151 ok(hres == S_OK, "Start failed: %08x\n", hres);
2152 if(FAILED(hres))
2153 return FALSE;
2155 CHECK_CALLED(GetBindInfo);
2156 if (!(bindf & BINDF_FROMURLMON))
2157 CHECK_CALLED(ReportProgress_DIRECTBIND);
2158 if (!got_user_agent)
2160 CHECK_CALLED(GetBindString_USER_AGENT);
2161 got_user_agent = TRUE;
2163 else todo_wine
2165 /* user agent only retrieved once, even with different URLs */
2166 CHECK_NOT_CALLED(GetBindString_USER_AGENT);
2168 CHECK_CALLED(GetBindString_ACCEPT_MIMES);
2169 CHECK_CALLED(QueryService_HttpNegotiate);
2170 CHECK_CALLED(BeginningTransaction);
2171 /* GetRootSecurityId called on WinXP but not on Win98 */
2172 CLEAR_CALLED(GetRootSecurityId);
2173 if (http_post_test)
2174 CHECK_CALLED(GetBindString_POST_COOKIE);
2176 return TRUE;
2179 static void test_protocol_terminate(IInternetProtocol *protocol)
2181 BYTE buf[3600];
2182 DWORD cb;
2183 HRESULT hres;
2185 hres = IInternetProtocol_LockRequest(protocol, 0);
2186 ok(hres == S_OK, "LockRequest failed: %08x\n", hres);
2188 hres = IInternetProtocol_Read(protocol, buf, 1, &cb);
2189 ok(hres == S_FALSE, "Read failed: %08x\n", hres);
2191 hres = IInternetProtocol_Terminate(protocol, 0);
2192 ok(hres == S_OK, "Terminate failed: %08x\n", hres);
2194 /* This wait is to give the internet handles being freed in Terminate
2195 * enough time to actually terminate in all cases. Internet handles
2196 * terminate asynchronously and native reuses the main InternetOpen
2197 * handle. The only case in which this seems to be necessary is on
2198 * wine with native wininet and urlmon, resulting in the next time
2199 * test_http_protocol_url being called the first data notification actually
2200 * being an extra last data notification from the previous connection
2201 * about once out of every ten times. */
2202 Sleep(100);
2204 hres = IInternetProtocol_UnlockRequest(protocol);
2205 ok(hres == S_OK, "UnlockRequest failed: %08x\n", hres);
2208 static void test_http_info(IInternetProtocol *protocol)
2210 IWinInetHttpInfo *info;
2211 HRESULT hres;
2213 hres = IInternetProtocol_QueryInterface(protocol, &IID_IWinInetHttpInfo, (void**)&info);
2214 ok(hres == S_OK, "Could not get IWinInterHttpInfo iface: %08x\n", hres);
2216 /* TODO */
2218 IWinInetHttpInfo_Release(info);
2221 /* is_first refers to whether this is the first call to this function
2222 * _for this url_ */
2223 static void test_http_protocol_url(LPCWSTR url, BOOL is_https, BOOL is_first)
2225 IInternetProtocolInfo *protocol_info;
2226 IClassFactory *factory;
2227 IUnknown *unk;
2228 HRESULT hres;
2230 http_url = url;
2231 http_is_first = is_first;
2233 hres = CoGetClassObject(is_https ? &CLSID_HttpSProtocol : &CLSID_HttpProtocol,
2234 CLSCTX_INPROC_SERVER, NULL, &IID_IUnknown, (void**)&unk);
2235 ok(hres == S_OK, "CoGetClassObject failed: %08x\n", hres);
2236 if(FAILED(hres))
2237 return;
2239 hres = IUnknown_QueryInterface(unk, &IID_IInternetProtocolInfo, (void**)&protocol_info);
2240 ok(hres == E_NOINTERFACE,
2241 "Could not get IInternetProtocolInfo interface: %08x, expected E_NOINTERFACE\n",
2242 hres);
2244 hres = IUnknown_QueryInterface(unk, &IID_IClassFactory, (void**)&factory);
2245 ok(hres == S_OK, "Could not get IClassFactory interface\n");
2246 IUnknown_Release(unk);
2247 if(FAILED(hres))
2248 return;
2250 hres = IClassFactory_CreateInstance(factory, NULL, &IID_IInternetProtocol,
2251 (void**)&async_protocol);
2252 ok(hres == S_OK, "Could not get IInternetProtocol: %08x\n", hres);
2253 if(SUCCEEDED(hres)) {
2254 BYTE buf[3600];
2255 DWORD cb;
2256 ULONG ref;
2258 test_priority(async_protocol);
2259 test_http_info(async_protocol);
2261 SET_EXPECT(ReportProgress_FINDINGRESOURCE);
2262 SET_EXPECT(ReportProgress_CONNECTING);
2263 SET_EXPECT(ReportProgress_SENDINGREQUEST);
2264 SET_EXPECT(ReportProgress_PROXYDETECTING);
2265 if(! is_https)
2266 SET_EXPECT(ReportProgress_CACHEFILENAMEAVAILABLE);
2267 else
2268 SET_EXPECT(QueryService_HttpSecurity);
2269 if(!(bindf & BINDF_FROMURLMON)) {
2270 SET_EXPECT(OnResponse);
2271 SET_EXPECT(ReportProgress_RAWMIMETYPE);
2272 SET_EXPECT(ReportData);
2273 } else {
2274 SET_EXPECT(Switch);
2277 if(!http_protocol_start(url, is_first))
2278 return;
2280 SET_EXPECT(ReportResult);
2281 expect_hrResult = S_OK;
2283 hres = IInternetProtocol_Read(async_protocol, buf, 1, &cb);
2284 ok((hres == E_PENDING && cb==0) ||
2285 (hres == S_OK && cb==1), "Read failed: %08x (%d bytes)\n", hres, cb);
2287 WaitForSingleObject(event_complete, INFINITE);
2288 if(bindf & BINDF_FROMURLMON)
2289 CHECK_CALLED(Switch);
2290 else
2291 CHECK_CALLED(ReportData);
2292 if (is_https)
2293 CLEAR_CALLED(QueryService_HttpSecurity);
2295 while(1) {
2296 if(bindf & BINDF_FROMURLMON)
2297 SET_EXPECT(Switch);
2298 else
2299 SET_EXPECT(ReportData);
2300 hres = IInternetProtocol_Read(async_protocol, buf, sizeof(buf), &cb);
2301 if(hres == E_PENDING) {
2302 hres = IInternetProtocol_Read(async_protocol, buf, 1, &cb);
2303 ok((hres == E_PENDING && cb==0) ||
2304 (hres == S_OK && cb==1), "Read failed: %08x (%d bytes)\n", hres, cb);
2305 WaitForSingleObject(event_complete, INFINITE);
2306 if(bindf & BINDF_FROMURLMON)
2307 CHECK_CALLED(Switch);
2308 else
2309 CHECK_CALLED(ReportData);
2310 }else {
2311 if(bindf & BINDF_FROMURLMON)
2312 CHECK_NOT_CALLED(Switch);
2313 else
2314 CHECK_NOT_CALLED(ReportData);
2315 if(cb == 0) break;
2318 ok(hres == S_FALSE, "Read failed: %08x\n", hres);
2319 CHECK_CALLED(ReportResult);
2320 if (is_https)
2321 CLEAR_CALLED(ReportProgress_SENDINGREQUEST);
2323 test_protocol_terminate(async_protocol);
2324 ref = IInternetProtocol_Release(async_protocol);
2325 ok(!ref, "ref=%x\n", hres);
2328 IClassFactory_Release(factory);
2331 static void test_http_protocol(void)
2333 static const WCHAR winehq_url[] =
2334 {'h','t','t','p',':','/','/','w','w','w','.','w','i','n','e','h','q','.',
2335 'o','r','g','/','s','i','t','e','/','a','b','o','u','t',0};
2336 static const WCHAR posttest_url[] =
2337 {'h','t','t','p',':','/','/','c','r','o','s','s','o','v','e','r','.',
2338 'c','o','d','e','w','e','a','v','e','r','s','.','c','o','m','/',
2339 'p','o','s','t','t','e','s','t','.','p','h','p',0};
2341 trace("Testing http protocol (not from urlmon)...\n");
2342 tested_protocol = HTTP_TEST;
2343 bindf = BINDF_ASYNCHRONOUS | BINDF_ASYNCSTORAGE | BINDF_PULLDATA;
2344 test_http_protocol_url(winehq_url, FALSE, TRUE);
2346 trace("Testing http protocol (from urlmon)...\n");
2347 bindf = BINDF_ASYNCHRONOUS | BINDF_ASYNCSTORAGE | BINDF_PULLDATA | BINDF_FROMURLMON;
2348 test_http_protocol_url(winehq_url, FALSE, FALSE);
2350 trace("Testing http protocol (to file)...\n");
2351 bindf = BINDF_ASYNCHRONOUS | BINDF_ASYNCSTORAGE | BINDF_PULLDATA | BINDF_FROMURLMON | BINDF_NEEDFILE;
2352 test_http_protocol_url(winehq_url, FALSE, FALSE);
2354 trace("Testing http protocol (post data)...\n");
2355 http_post_test = TRUE;
2356 /* Without this flag we get a ReportProgress_CACHEFILENAMEAVAILABLE
2357 * notification with BINDVERB_POST */
2358 bindf = BINDF_ASYNCHRONOUS | BINDF_ASYNCSTORAGE | BINDF_PULLDATA | BINDF_FROMURLMON | BINDF_NOWRITECACHE;
2359 test_http_protocol_url(posttest_url, FALSE, TRUE);
2360 http_post_test = FALSE;
2363 static void test_https_protocol(void)
2365 static const WCHAR codeweavers_url[] =
2366 {'h','t','t','p','s',':','/','/','w','w','w','.','c','o','d','e','w','e','a','v','e','r','s',
2367 '.','c','o','m','/','t','e','s','t','.','h','t','m','l',0};
2369 trace("Testing https protocol (from urlmon)...\n");
2370 init_test(HTTPS_TEST, 0);
2371 bindf = BINDF_ASYNCHRONOUS | BINDF_ASYNCSTORAGE | BINDF_PULLDATA | BINDF_FROMURLMON | BINDF_NOWRITECACHE;
2372 test_http_protocol_url(codeweavers_url, TRUE, TRUE);
2376 static void test_ftp_protocol(void)
2378 IInternetProtocolInfo *protocol_info;
2379 IClassFactory *factory;
2380 IUnknown *unk;
2381 BYTE buf[4096];
2382 ULONG ref;
2383 DWORD cb;
2384 HRESULT hres;
2386 static const WCHAR ftp_urlW[] = {'f','t','p',':','/','/','f','t','p','.','w','i','n','e','h','q','.','o','r','g',
2387 '/','p','u','b','/','o','t','h','e','r','/',
2388 'w','i','n','e','l','o','g','o','.','x','c','f','.','t','a','r','.','b','z','2',0};
2390 trace("Testing ftp protocol...\n");
2392 bindf = BINDF_ASYNCHRONOUS | BINDF_ASYNCSTORAGE | BINDF_PULLDATA | BINDF_FROMURLMON | BINDF_NOWRITECACHE;
2393 state = 0;
2394 tested_protocol = FTP_TEST;
2395 first_data_notif = TRUE;
2396 expect_hrResult = E_PENDING;
2398 hres = CoGetClassObject(&CLSID_FtpProtocol, CLSCTX_INPROC_SERVER, NULL, &IID_IUnknown, (void**)&unk);
2399 ok(hres == S_OK, "CoGetClassObject failed: %08x\n", hres);
2400 if(FAILED(hres))
2401 return;
2403 hres = IUnknown_QueryInterface(unk, &IID_IInternetProtocolInfo, (void**)&protocol_info);
2404 ok(hres == E_NOINTERFACE, "Could not get IInternetProtocolInfo interface: %08x, expected E_NOINTERFACE\n", hres);
2406 hres = IUnknown_QueryInterface(unk, &IID_IClassFactory, (void**)&factory);
2407 ok(hres == S_OK, "Could not get IClassFactory interface\n");
2408 IUnknown_Release(unk);
2409 if(FAILED(hres))
2410 return;
2412 hres = IClassFactory_CreateInstance(factory, NULL, &IID_IInternetProtocol,
2413 (void**)&async_protocol);
2414 IClassFactory_Release(factory);
2415 ok(hres == S_OK, "Could not get IInternetProtocol: %08x\n", hres);
2417 test_priority(async_protocol);
2418 test_http_info(async_protocol);
2420 SET_EXPECT(GetBindInfo);
2421 SET_EXPECT(GetBindString_USER_AGENT);
2422 SET_EXPECT(ReportProgress_FINDINGRESOURCE);
2423 SET_EXPECT(ReportProgress_CONNECTING);
2424 SET_EXPECT(ReportProgress_SENDINGREQUEST);
2425 SET_EXPECT(Switch);
2427 hres = IInternetProtocol_Start(async_protocol, ftp_urlW, &protocol_sink, &bind_info, 0, 0);
2428 ok(hres == S_OK, "Start failed: %08x\n", hres);
2429 CHECK_CALLED(GetBindInfo);
2430 todo_wine CHECK_NOT_CALLED(GetBindString_USER_AGENT);
2432 SET_EXPECT(ReportResult);
2434 hres = IInternetProtocol_Read(async_protocol, buf, 1, &cb);
2435 ok((hres == E_PENDING && cb==0) ||
2436 (hres == S_OK && cb==1), "Read failed: %08x (%d bytes)\n", hres, cb);
2438 WaitForSingleObject(event_complete, INFINITE);
2440 while(1) {
2442 hres = IInternetProtocol_Read(async_protocol, buf, sizeof(buf), &cb);
2443 if(hres == E_PENDING)
2444 WaitForSingleObject(event_complete, INFINITE);
2445 else
2446 if(cb == 0) break;
2449 ok(hres == S_FALSE, "Read failed: %08x\n", hres);
2450 CHECK_CALLED(ReportResult);
2451 CHECK_CALLED(Switch);
2453 test_protocol_terminate(async_protocol);
2455 ref = IInternetProtocol_Release(async_protocol);
2456 ok(!ref, "ref=%d\n", ref);
2459 static void test_gopher_protocol(void)
2461 IInternetProtocolInfo *protocol_info;
2462 IClassFactory *factory;
2463 IUnknown *unk;
2464 HRESULT hres;
2466 trace("Testing gopher protocol...\n");
2468 hres = CoGetClassObject(&CLSID_GopherProtocol, CLSCTX_INPROC_SERVER, NULL, &IID_IUnknown, (void**)&unk);
2469 ok(hres == S_OK ||
2470 hres == REGDB_E_CLASSNOTREG, /* Gopher protocol has been removed as of Vista */
2471 "CoGetClassObject failed: %08x\n", hres);
2472 if(FAILED(hres))
2473 return;
2475 hres = IUnknown_QueryInterface(unk, &IID_IInternetProtocolInfo, (void**)&protocol_info);
2476 ok(hres == E_NOINTERFACE, "Could not get IInternetProtocolInfo interface: %08x, expected E_NOINTERFACE\n", hres);
2478 hres = IUnknown_QueryInterface(unk, &IID_IClassFactory, (void**)&factory);
2479 ok(hres == S_OK, "Could not get IClassFactory interface\n");
2480 IUnknown_Release(unk);
2481 if(FAILED(hres))
2482 return;
2484 hres = IClassFactory_CreateInstance(factory, NULL, &IID_IInternetProtocol,
2485 (void**)&async_protocol);
2486 IClassFactory_Release(factory);
2487 ok(hres == S_OK, "Could not get IInternetProtocol: %08x\n", hres);
2489 test_priority(async_protocol);
2491 IInternetProtocol_Release(async_protocol);
2494 static void test_mk_protocol(void)
2496 IInternetProtocolInfo *protocol_info;
2497 IInternetProtocol *protocol;
2498 IClassFactory *factory;
2499 IUnknown *unk;
2500 HRESULT hres;
2502 static const WCHAR wrong_url1[] = {'t','e','s','t',':','@','M','S','I','T','S','t','o','r','e',
2503 ':',':','/','t','e','s','t','.','h','t','m','l',0};
2504 static const WCHAR wrong_url2[] = {'m','k',':','/','t','e','s','t','.','h','t','m','l',0};
2506 trace("Testing mk protocol...\n");
2507 init_test(MK_TEST, 0);
2509 hres = CoGetClassObject(&CLSID_MkProtocol, CLSCTX_INPROC_SERVER, NULL,
2510 &IID_IUnknown, (void**)&unk);
2511 ok(hres == S_OK, "CoGetClassObject failed: %08x\n", hres);
2513 hres = IUnknown_QueryInterface(unk, &IID_IInternetProtocolInfo, (void**)&protocol_info);
2514 ok(hres == E_NOINTERFACE,
2515 "Could not get IInternetProtocolInfo interface: %08x, expected E_NOINTERFACE\n",
2516 hres);
2518 hres = IUnknown_QueryInterface(unk, &IID_IClassFactory, (void**)&factory);
2519 ok(hres == S_OK, "Could not get IClassFactory interface\n");
2520 IUnknown_Release(unk);
2521 if(FAILED(hres))
2522 return;
2524 hres = IClassFactory_CreateInstance(factory, NULL, &IID_IInternetProtocol,
2525 (void**)&protocol);
2526 IClassFactory_Release(factory);
2527 ok(hres == S_OK, "Could not get IInternetProtocol: %08x\n", hres);
2529 SET_EXPECT(GetBindInfo);
2530 hres = IInternetProtocol_Start(protocol, wrong_url1, &protocol_sink, &bind_info, 0, 0);
2531 ok(hres == MK_E_SYNTAX || hres == INET_E_INVALID_URL,
2532 "Start failed: %08x, expected MK_E_SYNTAX or INET_E_INVALID_URL\n", hres);
2533 CLEAR_CALLED(GetBindInfo);
2535 SET_EXPECT(GetBindInfo);
2536 SET_EXPECT(ReportProgress_DIRECTBIND);
2537 SET_EXPECT(ReportProgress_SENDINGREQUEST);
2538 SET_EXPECT(ReportProgress_MIMETYPEAVAILABLE);
2539 SET_EXPECT(ReportResult);
2540 expect_hrResult = INET_E_RESOURCE_NOT_FOUND;
2542 hres = IInternetProtocol_Start(protocol, wrong_url2, &protocol_sink, &bind_info, 0, 0);
2543 ok(hres == INET_E_RESOURCE_NOT_FOUND ||
2544 hres == INET_E_INVALID_URL, /* win2k3 */
2545 "Start failed: %08x, expected INET_E_RESOURCE_NOT_FOUND or INET_E_INVALID_URL\n", hres);
2547 if (hres == INET_E_RESOURCE_NOT_FOUND) {
2548 CHECK_CALLED(GetBindInfo);
2549 CLEAR_CALLED(ReportProgress_DIRECTBIND);
2550 CHECK_CALLED(ReportProgress_SENDINGREQUEST);
2551 CHECK_CALLED(ReportProgress_MIMETYPEAVAILABLE);
2552 CHECK_CALLED(ReportResult);
2553 }else {
2554 CLEAR_CALLED(GetBindInfo);
2555 CLEAR_CALLED(ReportProgress_DIRECTBIND);
2556 CLEAR_CALLED(ReportProgress_SENDINGREQUEST);
2557 CLEAR_CALLED(ReportProgress_MIMETYPEAVAILABLE);
2558 CLEAR_CALLED(ReportResult);
2561 IInternetProtocol_Release(protocol);
2564 static void test_CreateBinding(void)
2566 IInternetProtocol *protocol;
2567 IInternetPriority *priority;
2568 IInternetSession *session;
2569 LONG p;
2570 BYTE buf[1000];
2571 DWORD read;
2572 HRESULT hres;
2574 static const WCHAR test_url[] =
2575 {'t','e','s','t',':','/','/','f','i','l','e','.','h','t','m','l',0};
2576 static const WCHAR wsz_test[] = {'t','e','s','t',0};
2578 trace("Testing CreateBinding...\n");
2579 init_test(BIND_TEST, TEST_BINDING);
2581 hres = CoInternetGetSession(0, &session, 0);
2582 ok(hres == S_OK, "CoInternetGetSession failed: %08x\n", hres);
2584 hres = IInternetSession_RegisterNameSpace(session, &ClassFactory, &IID_NULL, wsz_test, 0, NULL, 0);
2585 ok(hres == S_OK, "RegisterNameSpace failed: %08x\n", hres);
2587 hres = IInternetSession_CreateBinding(session, NULL, test_url, NULL, NULL, &protocol, 0);
2588 binding_protocol = protocol;
2589 ok(hres == S_OK, "CreateBinding failed: %08x\n", hres);
2590 ok(protocol != NULL, "protocol == NULL\n");
2592 hres = IInternetProtocol_QueryInterface(protocol, &IID_IInternetBindInfo, (void**)&prot_bind_info);
2593 ok(hres == S_OK, "QueryInterface(IID_IInternetBindInfo) failed: %08x\n", hres);
2595 hres = IInternetProtocol_QueryInterface(protocol, &IID_IInternetProtocolSink, (void**)&binding_sink);
2596 ok(hres == S_OK, "Could not get IInternetProtocolSink: %08x\n", hres);
2598 hres = IInternetProtocol_Start(protocol, test_url, NULL, &bind_info, 0, 0);
2599 ok(hres == E_INVALIDARG, "Start failed: %08x, expected E_INVALIDARG\n", hres);
2600 hres = IInternetProtocol_Start(protocol, test_url, &protocol_sink, NULL, 0, 0);
2601 ok(hres == E_INVALIDARG, "Start failed: %08x, expected E_INVALIDARG\n", hres);
2602 hres = IInternetProtocol_Start(protocol, NULL, &protocol_sink, &bind_info, 0, 0);
2603 ok(hres == E_INVALIDARG, "Start failed: %08x, expected E_INVALIDARG\n", hres);
2605 hres = IInternetProtocol_QueryInterface(protocol, &IID_IInternetPriority, (void**)&priority);
2606 ok(hres == S_OK, "QueryInterface(IID_IInternetPriority) failed: %08x\n", hres);
2608 p = 0xdeadbeef;
2609 hres = IInternetPriority_GetPriority(priority, &p);
2610 ok(hres == S_OK, "GetPriority failed: %08x\n", hres);
2611 ok(!p, "p=%d\n", p);
2613 ex_priority = 100;
2614 hres = IInternetPriority_SetPriority(priority, 100);
2615 ok(hres == S_OK, "SetPriority failed: %08x\n", hres);
2617 p = 0xdeadbeef;
2618 hres = IInternetPriority_GetPriority(priority, &p);
2619 ok(hres == S_OK, "GetPriority failed: %08x\n", hres);
2620 ok(p == 100, "p=%d\n", p);
2622 SET_EXPECT(QueryService_InternetProtocol);
2623 SET_EXPECT(CreateInstance);
2624 SET_EXPECT(ReportProgress_PROTOCOLCLASSID);
2625 SET_EXPECT(SetPriority);
2626 SET_EXPECT(Start);
2628 expect_hrResult = S_OK;
2629 hres = IInternetProtocol_Start(protocol, test_url, &protocol_sink, &bind_info, 0, 0);
2630 ok(hres == S_OK, "Start failed: %08x\n", hres);
2632 CHECK_CALLED(QueryService_InternetProtocol);
2633 CHECK_CALLED(CreateInstance);
2634 CHECK_CALLED(ReportProgress_PROTOCOLCLASSID);
2635 CHECK_CALLED(SetPriority);
2636 CHECK_CALLED(Start);
2638 SET_EXPECT(Read);
2639 read = 0xdeadbeef;
2640 hres = IInternetProtocol_Read(protocol, expect_pv = buf, sizeof(buf), &read);
2641 ok(hres == S_OK, "Read failed: %08x\n", hres);
2642 ok(read == 100, "read = %d\n", read);
2643 CHECK_CALLED(Read);
2645 SET_EXPECT(Read);
2646 read = 0xdeadbeef;
2647 hres = IInternetProtocol_Read(protocol, expect_pv = buf, sizeof(buf), &read);
2648 ok(hres == S_FALSE, "Read failed: %08x\n", hres);
2649 ok(!read, "read = %d\n", read);
2650 CHECK_CALLED(Read);
2652 p = 0xdeadbeef;
2653 hres = IInternetPriority_GetPriority(priority, &p);
2654 ok(hres == S_OK, "GetPriority failed: %08x\n", hres);
2655 ok(p == 100, "p=%d\n", p);
2657 hres = IInternetPriority_SetPriority(priority, 101);
2658 ok(hres == S_OK, "SetPriority failed: %08x\n", hres);
2660 SET_EXPECT(Terminate);
2661 hres = IInternetProtocol_Terminate(protocol, 0xdeadbeef);
2662 ok(hres == S_OK, "Terminate failed: %08x\n", hres);
2663 CHECK_CALLED(Terminate);
2665 SET_EXPECT(Continue);
2666 hres = IInternetProtocolSink_Switch(binding_sink, &protocoldata);
2667 ok(hres == S_OK, "Switch failed: %08x\n", hres);
2668 CHECK_CALLED(Continue);
2670 hres = IInternetProtocolSink_ReportProgress(binding_sink,
2671 BINDSTATUS_CACHEFILENAMEAVAILABLE, expect_wsz = emptyW);
2672 ok(hres == S_OK, "ReportProgress(BINDSTATUS_CACHEFILENAMEAVAILABLE) failed: %08x\n", hres);
2674 hres = IInternetProtocolSink_ReportResult(binding_sink, S_OK, ERROR_SUCCESS, NULL);
2675 ok(hres == E_FAIL, "ReportResult failed: %08x, expected E_FAIL\n", hres);
2677 hres = IInternetProtocolSink_ReportData(binding_sink, 0, 0, 0);
2678 ok(hres == S_OK, "ReportData failed: %08x\n", hres);
2680 IInternetProtocolSink_Release(binding_sink);
2681 IInternetPriority_Release(priority);
2682 IInternetBindInfo_Release(prot_bind_info);
2683 IInternetProtocol_Release(protocol);
2684 IInternetSession_Release(session);
2687 static void test_binding(int prot, DWORD grf_pi, BOOL test_filter)
2689 IInternetProtocol *protocol;
2690 IInternetSession *session;
2691 ULONG ref;
2692 HRESULT hres;
2694 trace("Testing %s binding (grfPI %x%s)...\n", debugstr_w(protocol_names[prot]), grf_pi,
2695 test_filter ? " testing MIME filter" : "");
2696 init_test(prot, TEST_BINDING | (test_filter ? TEST_FILTER : 0));
2697 pi = grf_pi;
2699 hres = CoInternetGetSession(0, &session, 0);
2700 ok(hres == S_OK, "CoInternetGetSession failed: %08x\n", hres);
2702 hres = IInternetSession_RegisterNameSpace(session, &ClassFactory, &IID_NULL, protocol_names[prot], 0, NULL, 0);
2703 ok(hres == S_OK, "RegisterNameSpace failed: %08x\n", hres);
2705 hres = IInternetSession_CreateBinding(session, NULL, binding_urls[prot], NULL, NULL, &protocol, 0);
2706 binding_protocol = protocol;
2707 IInternetSession_Release(session);
2708 ok(hres == S_OK, "CreateBinding failed: %08x\n", hres);
2709 ok(protocol != NULL, "protocol == NULL\n");
2711 hres = IInternetProtocol_QueryInterface(protocol, &IID_IInternetBindInfo, (void**)&prot_bind_info);
2712 ok(hres == S_OK, "QueryInterface(IID_IInternetBindInfo) failed: %08x\n", hres);
2714 hres = IInternetProtocol_QueryInterface(protocol, &IID_IInternetProtocolSink, (void**)&binding_sink);
2715 ok(hres == S_OK, "QueryInterface(IID_IInternetProtocolSink) failed: %08x\n", hres);
2717 ex_priority = 0;
2718 SET_EXPECT(QueryService_InternetProtocol);
2719 SET_EXPECT(CreateInstance);
2720 SET_EXPECT(ReportProgress_PROTOCOLCLASSID);
2721 SET_EXPECT(SetPriority);
2722 SET_EXPECT(Start);
2724 expect_hrResult = S_OK;
2725 hres = IInternetProtocol_Start(protocol, binding_urls[prot], &protocol_sink, &bind_info, pi, 0);
2726 ok(hres == S_OK, "Start failed: %08x\n", hres);
2728 CHECK_CALLED(QueryService_InternetProtocol);
2729 CHECK_CALLED(CreateInstance);
2730 CHECK_CALLED(ReportProgress_PROTOCOLCLASSID);
2731 CHECK_CALLED(SetPriority);
2732 CHECK_CALLED(Start);
2734 if(prot == HTTP_TEST || prot == HTTPS_TEST) {
2735 while(prot_state < 4) {
2736 WaitForSingleObject(event_complete, INFINITE);
2737 if(mimefilter_test && filtered_protocol) {
2738 SET_EXPECT(Continue);
2739 IInternetProtocol_Continue(filtered_protocol, pdata);
2740 CHECK_CALLED(Continue);
2741 }else {
2742 SET_EXPECT(Continue);
2743 IInternetProtocol_Continue(protocol, pdata);
2744 CHECK_CALLED(Continue);
2746 SetEvent(event_complete2);
2748 WaitForSingleObject(event_complete, INFINITE);
2749 }else {
2750 if(mimefilter_test)
2751 SET_EXPECT(MimeFilter_LockRequest);
2752 else
2753 SET_EXPECT(LockRequest);
2754 hres = IInternetProtocol_LockRequest(protocol, 0);
2755 ok(hres == S_OK, "LockRequest failed: %08x\n", hres);
2756 if(mimefilter_test)
2757 CHECK_CALLED(MimeFilter_LockRequest);
2758 else
2759 CHECK_CALLED(LockRequest);
2761 if(mimefilter_test)
2762 SET_EXPECT(MimeFilter_UnlockRequest);
2763 else
2764 SET_EXPECT(UnlockRequest);
2765 hres = IInternetProtocol_UnlockRequest(protocol);
2766 ok(hres == S_OK, "UnlockRequest failed: %08x\n", hres);
2767 if(mimefilter_test)
2768 CHECK_CALLED(MimeFilter_UnlockRequest);
2769 else
2770 CHECK_CALLED(UnlockRequest);
2773 if(mimefilter_test)
2774 SET_EXPECT(MimeFilter_Terminate);
2775 else
2776 SET_EXPECT(Terminate);
2777 hres = IInternetProtocol_Terminate(protocol, 0);
2778 ok(hres == S_OK, "Terminate failed: %08x\n", hres);
2779 if(mimefilter_test)
2780 CHECK_CALLED(MimeFilter_Terminate);
2781 else
2782 CHECK_CALLED(Terminate);
2784 if(filtered_protocol)
2785 IInternetProtocol_Release(filtered_protocol);
2786 IInternetBindInfo_Release(prot_bind_info);
2787 IInternetProtocolSink_Release(binding_sink);
2788 ref = IInternetProtocol_Release(protocol);
2789 ok(!ref, "ref=%u, expected 0\n", ref);
2792 static void register_filter(void)
2794 IInternetSession *session;
2795 HRESULT hres;
2797 static const WCHAR gzipW[] = {'g','z','i','p',0};
2799 CoInternetGetSession(0, &session, 0);
2801 hres = IInternetSession_RegisterMimeFilter(session, &mimefilter_cf, &IID_IInternetProtocol, gzipW);
2802 ok(hres == S_OK, "RegisterMimeFilter failed: %08x\n", hres);
2804 IInternetSession_Release(session);
2807 START_TEST(protocol)
2809 OleInitialize(NULL);
2811 event_complete = CreateEvent(NULL, FALSE, FALSE, NULL);
2812 event_complete2 = CreateEvent(NULL, FALSE, FALSE, NULL);
2814 register_filter();
2816 test_file_protocol();
2817 test_http_protocol();
2818 test_https_protocol();
2819 test_ftp_protocol();
2820 test_gopher_protocol();
2821 test_mk_protocol();
2822 test_CreateBinding();
2823 test_binding(FILE_TEST, 0, FALSE);
2824 test_binding(HTTP_TEST, 0, FALSE);
2825 test_binding(FILE_TEST, PI_MIMEVERIFICATION, FALSE);
2826 test_binding(HTTP_TEST, PI_MIMEVERIFICATION, FALSE);
2827 test_binding(FILE_TEST, PI_MIMEVERIFICATION, TRUE);
2828 test_binding(HTTP_TEST, PI_MIMEVERIFICATION, TRUE);
2830 CloseHandle(event_complete);
2831 CloseHandle(event_complete2);
2833 OleUninitialize();