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
22 #include <wine/test.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) \
40 ok(expect_ ##func, "unexpected call " #func "\n"); \
41 called_ ## func = TRUE; \
44 #define CHECK_EXPECT(func) \
46 CHECK_EXPECT2(func); \
47 expect_ ## func = FALSE; \
50 #define CHECK_CALLED(func) \
52 ok(called_ ## func, "expected " #func "\n"); \
53 expect_ ## func = called_ ## func = FALSE; \
56 #define CHECK_NOT_CALLED(func) \
58 ok(!called_ ## func, "unexpected " #func "\n"); \
59 expect_ ## func = called_ ## func = FALSE; \
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(ReportData2);
84 DEFINE_EXPECT(ReportResult);
85 DEFINE_EXPECT(GetBindString_ACCEPT_MIMES);
86 DEFINE_EXPECT(GetBindString_USER_AGENT);
87 DEFINE_EXPECT(GetBindString_POST_COOKIE);
88 DEFINE_EXPECT(GetBindString_URL);
89 DEFINE_EXPECT(QueryService_HttpNegotiate);
90 DEFINE_EXPECT(QueryService_InternetProtocol);
91 DEFINE_EXPECT(QueryService_HttpSecurity);
92 DEFINE_EXPECT(QueryInterface_IWinInetInfo);
93 DEFINE_EXPECT(QueryInterface_IWinInetHttpInfo);
94 DEFINE_EXPECT(BeginningTransaction);
95 DEFINE_EXPECT(GetRootSecurityId);
96 DEFINE_EXPECT(OnResponse);
97 DEFINE_EXPECT(Switch);
98 DEFINE_EXPECT(Continue);
99 DEFINE_EXPECT(CreateInstance);
100 DEFINE_EXPECT(Start);
101 DEFINE_EXPECT(Terminate);
103 DEFINE_EXPECT(Read2);
104 DEFINE_EXPECT(SetPriority);
105 DEFINE_EXPECT(LockRequest);
106 DEFINE_EXPECT(UnlockRequest);
107 DEFINE_EXPECT(MimeFilter_CreateInstance);
108 DEFINE_EXPECT(MimeFilter_Start);
109 DEFINE_EXPECT(MimeFilter_ReportProgress);
110 DEFINE_EXPECT(MimeFilter_ReportData);
111 DEFINE_EXPECT(MimeFilter_ReportResult);
112 DEFINE_EXPECT(MimeFilter_Terminate);
113 DEFINE_EXPECT(MimeFilter_LockRequest);
114 DEFINE_EXPECT(MimeFilter_UnlockRequest);
115 DEFINE_EXPECT(MimeFilter_Read);
116 DEFINE_EXPECT(MimeFilter_Switch);
117 DEFINE_EXPECT(MimeFilter_Continue);
119 static const WCHAR wszIndexHtml[] = {'i','n','d','e','x','.','h','t','m','l',0};
120 static const WCHAR index_url[] =
121 {'f','i','l','e',':','i','n','d','e','x','.','h','t','m','l',0};
123 static const WCHAR acc_mimeW[] = {'*','/','*',0};
124 static const WCHAR user_agentW[] = {'W','i','n','e',0};
125 static const WCHAR text_htmlW[] = {'t','e','x','t','/','h','t','m','l',0};
126 static const WCHAR hostW[] = {'w','w','w','.','w','i','n','e','h','q','.','o','r','g',0};
127 static const WCHAR winehq_ipW[] = {'2','0','9','.','4','6','.','2','5','.','1','3','4',0};
128 static const WCHAR emptyW[] = {0};
129 static const WCHAR gzipW[] = {'g','z','i','p',0};
131 static HRESULT expect_hrResult;
132 static LPCWSTR file_name, http_url, expect_wsz;
133 static IInternetProtocol *async_protocol = NULL;
134 static BOOL first_data_notif, http_is_first, http_post_test, test_redirect;
135 static int state = 0, prot_state, read_report_data;
136 static DWORD bindf, ex_priority , pi;
137 static IInternetProtocol *binding_protocol, *filtered_protocol;
138 static IInternetBindInfo *prot_bind_info;
139 static IInternetProtocolSink *binding_sink, *filtered_sink;
140 static void *expect_pv;
141 static HANDLE event_complete, event_complete2, event_continue, event_continue_done;
142 static BOOL binding_test;
143 static PROTOCOLDATA protocoldata, *pdata, continue_protdata;
144 static DWORD prot_read, pi, filter_state;
145 static BOOL security_problem;
146 static BOOL async_read_pending, mimefilter_test, direct_read, wait_for_switch, emulate_prot, short_read;
157 static const WCHAR protocol_names[][10] = {
160 {'h','t','t','p','s',0},
166 static const WCHAR binding_urls[][130] = {
167 {'f','i','l','e',':','t','e','s','t','.','h','t','m','l',0},
168 {'h','t','t','p',':','/','/','w','w','w','.','w','i','n','e','h','q','.',
169 'o','r','g','/','s','i','t','e','/','a','b','o','u','t',0},
170 {'h','t','t','p','s',':','/','/','w','w','w','.','c','o','d','e','w','e','a','v','e','r','s',
171 '.','c','o','m','/','t','e','s','t','.','h','t','m','l',0},
172 {'f','t','p',':','/','/','f','t','p','.','w','i','n','e','h','q','.','o','r','g',
173 '/','p','u','b','/','o','t','h','e','r',
174 '/','w','i','n','e','l','o','g','o','.','x','c','f','.','t','a','r','.','b','z','2',0},
175 {'m','k',':','t','e','s','t',0},
176 {'t','e','s','t',':','/','/','f','i','l','e','.','h','t','m','l',0}
179 static const char *debugstr_guid(REFIID riid)
183 sprintf(buf, "{%08X-%04X-%04X-%02X%02X-%02X%02X%02X%02X%02X%02X}",
184 riid->Data1, riid->Data2, riid->Data3, riid->Data4[0],
185 riid->Data4[1], riid->Data4[2], riid->Data4[3], riid->Data4[4],
186 riid->Data4[5], riid->Data4[6], riid->Data4[7]);
191 static int strcmp_wa(LPCWSTR strw, const char *stra)
194 WideCharToMultiByte(CP_ACP, 0, strw, -1, buf, sizeof(buf), NULL, NULL);
195 return lstrcmpA(stra, buf);
198 /* lstrcmpW is not implemented on Win9x */
199 static int strcmp_ww(LPCWSTR strw1, LPCWSTR strw2)
201 CHAR stra1[512], stra2[512];
202 WideCharToMultiByte(CP_ACP, 0, strw1, -1, stra1, MAX_PATH, NULL, NULL);
203 WideCharToMultiByte(CP_ACP, 0, strw2, -1, stra2, MAX_PATH, NULL, NULL);
204 return lstrcmpA(stra1, stra2);
207 static HRESULT WINAPI HttpSecurity_QueryInterface(IHttpSecurity *iface, REFIID riid, void **ppv)
209 if(IsEqualGUID(&IID_IUnknown, riid)
210 || IsEqualGUID(&IID_IHttpSecurity, riid)) {
215 ok(0, "unexpected call\n");
216 return E_NOINTERFACE;
219 static ULONG WINAPI HttpSecurity_AddRef(IHttpSecurity *iface)
224 static ULONG WINAPI HttpSecurity_Release(IHttpSecurity *iface)
229 static HRESULT WINAPI HttpSecurity_GetWindow(IHttpSecurity* iface, REFGUID rguidReason, HWND *phwnd)
231 trace("HttpSecurity_GetWindow\n");
236 static HRESULT WINAPI HttpSecurity_OnSecurityProblem(IHttpSecurity *iface, DWORD dwProblem)
238 trace("Security problem: %u\n", dwProblem);
239 ok(dwProblem == ERROR_INTERNET_SEC_CERT_REV_FAILED, "Expected ERROR_INTERNET_SEC_CERT_REV_FAILED got %u\n", dwProblem);
241 /* Only retry once */
242 if (security_problem)
245 security_problem = TRUE;
246 SET_EXPECT(BeginningTransaction);
251 static IHttpSecurityVtbl HttpSecurityVtbl = {
252 HttpSecurity_QueryInterface,
254 HttpSecurity_Release,
255 HttpSecurity_GetWindow,
256 HttpSecurity_OnSecurityProblem
259 static IHttpSecurity http_security = { &HttpSecurityVtbl };
261 static HRESULT WINAPI HttpNegotiate_QueryInterface(IHttpNegotiate2 *iface, REFIID riid, void **ppv)
263 if(IsEqualGUID(&IID_IUnknown, riid)
264 || IsEqualGUID(&IID_IHttpNegotiate, riid)
265 || IsEqualGUID(&IID_IHttpNegotiate2, riid)) {
270 ok(0, "unexpected call\n");
271 return E_NOINTERFACE;
274 static ULONG WINAPI HttpNegotiate_AddRef(IHttpNegotiate2 *iface)
279 static ULONG WINAPI HttpNegotiate_Release(IHttpNegotiate2 *iface)
284 static HRESULT WINAPI HttpNegotiate_BeginningTransaction(IHttpNegotiate2 *iface, LPCWSTR szURL,
285 LPCWSTR szHeaders, DWORD dwReserved, LPWSTR *pszAdditionalHeaders)
289 static const WCHAR wszHeaders[] =
290 {'C','o','n','t','e','n','t','-','T','y','p','e',':',' ','a','p','p','l','i','c','a','t',
291 'i','o','n','/','x','-','w','w','w','-','f','o','r','m','-','u','r','l','e','n','c','o',
292 'd','e','d','\r','\n',0};
294 CHECK_EXPECT(BeginningTransaction);
297 ok(!strcmp_ww(szURL, binding_urls[tested_protocol]), "szURL != http_url\n");
299 ok(!strcmp_ww(szURL, http_url), "szURL != http_url\n");
300 ok(!dwReserved, "dwReserved=%d, expected 0\n", dwReserved);
301 ok(pszAdditionalHeaders != NULL, "pszAdditionalHeaders == NULL\n");
302 if(pszAdditionalHeaders)
304 ok(*pszAdditionalHeaders == NULL, "*pszAdditionalHeaders != NULL\n");
307 addl_headers = CoTaskMemAlloc(sizeof(wszHeaders));
310 http_post_test = FALSE;
311 skip("Out of memory\n");
312 return E_OUTOFMEMORY;
314 memcpy(addl_headers, wszHeaders, sizeof(wszHeaders));
315 *pszAdditionalHeaders = addl_headers;
322 static HRESULT WINAPI HttpNegotiate_OnResponse(IHttpNegotiate2 *iface, DWORD dwResponseCode,
323 LPCWSTR szResponseHeaders, LPCWSTR szRequestHeaders, LPWSTR *pszAdditionalRequestHeaders)
325 CHECK_EXPECT(OnResponse);
327 ok(dwResponseCode == 200, "dwResponseCode=%d, expected 200\n", dwResponseCode);
328 ok(szResponseHeaders != NULL, "szResponseHeaders == NULL\n");
329 ok(szRequestHeaders == NULL, "szRequestHeaders != NULL\n");
330 ok(pszAdditionalRequestHeaders == NULL, "pszAdditionalHeaders != NULL\n");
335 static HRESULT WINAPI HttpNegotiate_GetRootSecurityId(IHttpNegotiate2 *iface,
336 BYTE *pbSecurityId, DWORD *pcbSecurityId, DWORD_PTR dwReserved)
338 static const BYTE sec_id[] = {'h','t','t','p',':','t','e','s','t',1,0,0,0};
340 CHECK_EXPECT(GetRootSecurityId);
342 ok(!dwReserved, "dwReserved=%ld, expected 0\n", dwReserved);
343 ok(pbSecurityId != NULL, "pbSecurityId == NULL\n");
344 ok(pcbSecurityId != NULL, "pcbSecurityId == NULL\n");
347 ok(*pcbSecurityId == 512, "*pcbSecurityId=%d, expected 512\n", *pcbSecurityId);
348 *pcbSecurityId = sizeof(sec_id);
352 memcpy(pbSecurityId, sec_id, sizeof(sec_id));
357 static IHttpNegotiate2Vtbl HttpNegotiateVtbl = {
358 HttpNegotiate_QueryInterface,
359 HttpNegotiate_AddRef,
360 HttpNegotiate_Release,
361 HttpNegotiate_BeginningTransaction,
362 HttpNegotiate_OnResponse,
363 HttpNegotiate_GetRootSecurityId
366 static IHttpNegotiate2 http_negotiate = { &HttpNegotiateVtbl };
368 static HRESULT QueryInterface(REFIID,void**);
370 static HRESULT WINAPI ServiceProvider_QueryInterface(IServiceProvider *iface, REFIID riid, void **ppv)
372 return QueryInterface(riid, ppv);
375 static ULONG WINAPI ServiceProvider_AddRef(IServiceProvider *iface)
380 static ULONG WINAPI ServiceProvider_Release(IServiceProvider *iface)
385 static HRESULT WINAPI ServiceProvider_QueryService(IServiceProvider *iface, REFGUID guidService,
386 REFIID riid, void **ppv)
388 if(IsEqualGUID(&IID_IHttpNegotiate, guidService) || IsEqualGUID(&IID_IHttpNegotiate2, riid)) {
389 CHECK_EXPECT2(QueryService_HttpNegotiate);
390 return IHttpNegotiate2_QueryInterface(&http_negotiate, riid, ppv);
393 if(IsEqualGUID(&IID_IInternetProtocol, guidService)) {
394 ok(IsEqualGUID(&IID_IInternetProtocol, riid), "unexpected riid\n");
395 CHECK_EXPECT(QueryService_InternetProtocol);
396 return E_NOINTERFACE;
399 if(IsEqualGUID(&IID_IHttpSecurity, guidService)) {
400 ok(IsEqualGUID(&IID_IHttpSecurity, riid), "unexpected riid\n");
401 CHECK_EXPECT(QueryService_HttpSecurity);
402 return IHttpSecurity_QueryInterface(&http_security, riid, ppv);
405 ok(0, "unexpected service %s\n", debugstr_guid(guidService));
409 static const IServiceProviderVtbl ServiceProviderVtbl = {
410 ServiceProvider_QueryInterface,
411 ServiceProvider_AddRef,
412 ServiceProvider_Release,
413 ServiceProvider_QueryService
416 static IServiceProvider service_provider = { &ServiceProviderVtbl };
418 static HRESULT WINAPI ProtocolSink_QueryInterface(IInternetProtocolSink *iface, REFIID riid, void **ppv)
420 return QueryInterface(riid, ppv);
423 static ULONG WINAPI ProtocolSink_AddRef(IInternetProtocolSink *iface)
428 static ULONG WINAPI ProtocolSink_Release(IInternetProtocolSink *iface)
433 static void call_continue(PROTOCOLDATA *protocol_data)
438 if(tested_protocol == HTTP_TEST || tested_protocol == HTTPS_TEST)
439 CLEAR_CALLED(ReportProgress_COOKIE_SENT);
440 if(tested_protocol == HTTP_TEST || tested_protocol == HTTPS_TEST || tested_protocol == FTP_TEST) {
442 CLEAR_CALLED(ReportProgress_FINDINGRESOURCE);
443 CLEAR_CALLED(ReportProgress_CONNECTING);
444 CLEAR_CALLED(ReportProgress_PROXYDETECTING);
445 }else if(test_redirect) {
446 CHECK_CALLED(ReportProgress_FINDINGRESOURCE);
448 CHECK_NOT_CALLED(ReportProgress_FINDINGRESOURCE);
449 /* IE7 does call this */
450 CLEAR_CALLED(ReportProgress_CONNECTING);
453 if(tested_protocol == FTP_TEST)
454 todo_wine CHECK_CALLED(ReportProgress_SENDINGREQUEST);
455 else if (tested_protocol != HTTPS_TEST)
456 CHECK_CALLED(ReportProgress_SENDINGREQUEST);
458 CHECK_CALLED(ReportProgress_REDIRECTING);
459 if(tested_protocol == HTTP_TEST || tested_protocol == HTTPS_TEST) {
460 SET_EXPECT(OnResponse);
461 if(tested_protocol == HTTPS_TEST || test_redirect)
462 SET_EXPECT(ReportProgress_ACCEPTRANGES);
463 SET_EXPECT(ReportProgress_MIMETYPEAVAILABLE);
464 if(bindf & BINDF_NEEDFILE)
465 SET_EXPECT(ReportProgress_CACHEFILENAMEAVAILABLE);
469 SET_EXPECT(ReportData);
470 hres = IInternetProtocol_Continue(async_protocol, protocol_data);
471 ok(hres == S_OK, "Continue failed: %08x\n", hres);
472 if(tested_protocol == FTP_TEST)
473 CLEAR_CALLED(ReportData);
474 else if (! security_problem)
475 CHECK_CALLED(ReportData);
478 if (! security_problem)
481 if(tested_protocol == HTTP_TEST || tested_protocol == HTTPS_TEST) {
482 CHECK_CALLED(OnResponse);
483 if(tested_protocol == HTTPS_TEST)
484 CHECK_CALLED(ReportProgress_ACCEPTRANGES);
485 else if(test_redirect)
486 CLEAR_CALLED(ReportProgress_ACCEPTRANGES);
487 CHECK_CALLED(ReportProgress_MIMETYPEAVAILABLE);
488 if(bindf & BINDF_NEEDFILE)
489 CHECK_CALLED(ReportProgress_CACHEFILENAMEAVAILABLE);
494 security_problem = FALSE;
495 SET_EXPECT(ReportProgress_CONNECTING);
500 static HRESULT WINAPI ProtocolSink_Switch(IInternetProtocolSink *iface, PROTOCOLDATA *pProtocolData)
502 if(tested_protocol == FTP_TEST)
503 CHECK_EXPECT2(Switch);
505 CHECK_EXPECT(Switch);
507 ok(pProtocolData != NULL, "pProtocolData == NULL\n");
509 ok(pProtocolData != &protocoldata, "pProtocolData == &protocoldata\n");
510 ok(pProtocolData->grfFlags == protocoldata.grfFlags, "grfFlags wrong %x/%x\n",
511 pProtocolData->grfFlags, protocoldata.grfFlags );
512 ok(pProtocolData->dwState == protocoldata.dwState, "dwState wrong %x/%x\n",
513 pProtocolData->dwState, protocoldata.dwState );
514 ok(pProtocolData->pData == protocoldata.pData, "pData wrong %p/%p\n",
515 pProtocolData->pData, protocoldata.pData );
516 ok(pProtocolData->cbData == protocoldata.cbData, "cbData wrong %x/%x\n",
517 pProtocolData->cbData, protocoldata.cbData );
520 pdata = pProtocolData;
523 SetEvent(event_complete);
524 WaitForSingleObject(event_complete2, INFINITE);
527 continue_protdata = *pProtocolData;
528 SetEvent(event_continue);
529 WaitForSingleObject(event_continue_done, INFINITE);
531 call_continue(pProtocolData);
532 SetEvent(event_complete);
538 static HRESULT WINAPI ProtocolSink_ReportProgress(IInternetProtocolSink *iface, ULONG ulStatusCode,
539 LPCWSTR szStatusText)
541 static const WCHAR null_guid[] = {'{','0','0','0','0','0','0','0','0','-','0','0','0','0','-',
542 '0','0','0','0','-','0','0','0','0','-','0','0','0','0','0','0','0','0','0','0','0','0','}',0};
543 static const WCHAR text_plain[] = {'t','e','x','t','/','p','l','a','i','n',0};
545 switch(ulStatusCode) {
546 case BINDSTATUS_MIMETYPEAVAILABLE:
547 CHECK_EXPECT(ReportProgress_MIMETYPEAVAILABLE);
548 if(tested_protocol != FILE_TEST && !mimefilter_test && (pi & PI_MIMEVERIFICATION)) {
549 if(!short_read || !direct_read)
550 CHECK_CALLED(Read); /* set in Continue */
552 CHECK_CALLED(Read2); /* set in Read */
554 ok(szStatusText != NULL, "szStatusText == NULL\n");
556 if(tested_protocol == BIND_TEST)
557 ok(szStatusText == expect_wsz, "unexpected szStatusText\n");
558 else if (http_post_test)
559 ok(lstrlenW(text_plain) <= lstrlenW(szStatusText) &&
560 !memcmp(szStatusText, text_plain, lstrlenW(text_plain)*sizeof(WCHAR)),
561 "szStatusText != text/plain\n");
562 else if(!mimefilter_test)
563 ok(lstrlenW(text_htmlW) <= lstrlenW(szStatusText) &&
564 !memcmp(szStatusText, text_htmlW, lstrlenW(text_htmlW)*sizeof(WCHAR)),
565 "szStatusText != text/html\n");
568 case BINDSTATUS_DIRECTBIND:
569 CHECK_EXPECT2(ReportProgress_DIRECTBIND);
570 ok(szStatusText == NULL, "szStatusText != NULL\n");
572 case BINDSTATUS_RAWMIMETYPE:
573 CHECK_EXPECT2(ReportProgress_RAWMIMETYPE);
574 ok(szStatusText != NULL, "szStatusText == NULL\n");
576 ok(lstrlenW(szStatusText) < lstrlenW(text_htmlW) ||
577 !memcmp(szStatusText, text_htmlW, lstrlenW(text_htmlW)*sizeof(WCHAR)),
578 "szStatusText != text/html\n");
580 case BINDSTATUS_CACHEFILENAMEAVAILABLE:
581 CHECK_EXPECT(ReportProgress_CACHEFILENAMEAVAILABLE);
582 ok(szStatusText != NULL, "szStatusText == NULL\n");
585 ok(!strcmp_ww(szStatusText, expect_wsz), "unexpected szStatusText\n");
586 else if(tested_protocol == FILE_TEST)
587 ok(!strcmp_ww(szStatusText, file_name), "szStatusText = %s\n", wine_dbgstr_w(szStatusText));
589 ok(szStatusText != NULL, "szStatusText == NULL\n");
592 case BINDSTATUS_FINDINGRESOURCE:
593 CHECK_EXPECT2(ReportProgress_FINDINGRESOURCE);
594 ok(szStatusText != NULL, "szStatusText == NULL\n");
596 case BINDSTATUS_CONNECTING:
597 CHECK_EXPECT2(ReportProgress_CONNECTING);
598 ok(szStatusText != NULL, "szStatusText == NULL\n");
600 case BINDSTATUS_SENDINGREQUEST:
601 CHECK_EXPECT2(ReportProgress_SENDINGREQUEST);
602 if(tested_protocol == FILE_TEST) {
603 ok(szStatusText != NULL, "szStatusText == NULL\n");
605 ok(!*szStatusText, "wrong szStatusText\n");
608 case BINDSTATUS_VERIFIEDMIMETYPEAVAILABLE:
609 CHECK_EXPECT(ReportProgress_VERIFIEDMIMETYPEAVAILABLE);
610 ok(szStatusText != NULL, "szStatusText == NULL\n");
612 ok(!strcmp_ww(szStatusText, text_htmlW), "szStatusText != text/html\n");
614 case BINDSTATUS_PROTOCOLCLASSID:
615 CHECK_EXPECT(ReportProgress_PROTOCOLCLASSID);
616 ok(szStatusText != NULL, "szStatusText == NULL\n");
617 ok(!strcmp_ww(szStatusText, null_guid), "unexpected classid %s\n", wine_dbgstr_w(szStatusText));
619 case BINDSTATUS_COOKIE_SENT:
620 CHECK_EXPECT(ReportProgress_COOKIE_SENT);
621 ok(szStatusText == NULL, "szStatusText != NULL\n");
623 case BINDSTATUS_REDIRECTING:
624 CHECK_EXPECT(ReportProgress_REDIRECTING);
626 ok(!strcmp_wa(szStatusText, "http://test.winehq.org/hello.html"), "szStatusText = %s\n", wine_dbgstr_w(szStatusText));
628 ok(szStatusText == NULL, "szStatusText = %s\n", wine_dbgstr_w(szStatusText));
630 case BINDSTATUS_ENCODING:
631 CHECK_EXPECT(ReportProgress_ENCODING);
632 ok(!strcmp_wa(szStatusText, "gzip"), "szStatusText = %s\n", wine_dbgstr_w(szStatusText));
634 case BINDSTATUS_ACCEPTRANGES:
635 CHECK_EXPECT(ReportProgress_ACCEPTRANGES);
636 ok(!szStatusText, "szStatusText = %s\n", wine_dbgstr_w(szStatusText));
638 case BINDSTATUS_PROXYDETECTING:
639 CHECK_EXPECT(ReportProgress_PROXYDETECTING);
640 SET_EXPECT(ReportProgress_CONNECTING);
641 ok(!szStatusText, "szStatusText = %s\n", wine_dbgstr_w(szStatusText));
643 case BINDSTATUS_LOADINGMIMEHANDLER:
644 CHECK_EXPECT(ReportProgress_LOADINGMIMEHANDLER);
645 ok(!szStatusText, "szStatusText = %s\n", wine_dbgstr_w(szStatusText));
647 case BINDSTATUS_DECODING:
648 CHECK_EXPECT(ReportProgress_DECODING);
649 ok(!strcmp_ww(szStatusText, gzipW), "szStatusText = %s\n", wine_dbgstr_w(szStatusText));
652 ok(0, "Unexpected status %d\n", ulStatusCode);
658 static HRESULT WINAPI ProtocolSink_ReportData(IInternetProtocolSink *iface, DWORD grfBSCF,
659 ULONG ulProgress, ULONG ulProgressMax)
663 static int rec_depth;
666 if(!mimefilter_test && tested_protocol == FILE_TEST) {
667 CHECK_EXPECT2(ReportData);
669 ok(ulProgress == ulProgressMax, "ulProgress (%d) != ulProgressMax (%d)\n",
670 ulProgress, ulProgressMax);
671 ok(ulProgressMax == 13, "ulProgressMax=%d, expected 13\n", ulProgressMax);
672 /* BSCF_SKIPDRAINDATAFORFILEURLS added in IE8 */
673 ok((grfBSCF == (BSCF_FIRSTDATANOTIFICATION | BSCF_LASTDATANOTIFICATION)) ||
674 (grfBSCF == (BSCF_FIRSTDATANOTIFICATION | BSCF_LASTDATANOTIFICATION | BSCF_SKIPDRAINDATAFORFILEURLS)),
675 "grcfBSCF = %08x\n", grfBSCF);
676 }else if(direct_read) {
680 if(!read_report_data && rec_depth == 1) {
681 BOOL reported_all_data = called_ReportData2;
683 CHECK_EXPECT2(ReportData);
686 ok(grfBSCF == (BSCF_FIRSTDATANOTIFICATION|BSCF_LASTDATANOTIFICATION|BSCF_DATAFULLYAVAILABLE)
687 || grfBSCF == BSCF_FIRSTDATANOTIFICATION, /* < IE8 */
688 "grcfBSCF = %08x\n", grfBSCF);
689 CHECK_CALLED(Read); /* Set in Continue */
690 first_data_notif = FALSE;
691 }else if(first_data_notif) {
692 ok(grfBSCF == BSCF_FIRSTDATANOTIFICATION, "grcfBSCF = %08x\n", grfBSCF);
693 first_data_notif = FALSE;
694 }else if(reported_all_data) {
695 ok(grfBSCF == (BSCF_LASTDATANOTIFICATION|BSCF_INTERMEDIATEDATANOTIFICATION),
696 "grcfBSCF = %08x\n", grfBSCF);
697 }else if(!direct_read) {
698 ok(grfBSCF == BSCF_INTERMEDIATEDATANOTIFICATION, "grcfBSCF = %08x\n", grfBSCF);
706 SET_EXPECT(ReportData2);
707 SET_EXPECT(ReportResult);
708 hres = IInternetProtocol_Read(binding_test ? binding_protocol : async_protocol, expect_pv = buf, sizeof(buf), &read);
710 ok(read, "read == 0\n");
711 if(reported_all_data) {
712 ok(hres == S_FALSE, "Read failed: %08x, expected S_FALSE\n", hres);
716 if(!reported_all_data && called_ReportData2) {
718 CHECK_CALLED(ReportData2);
719 CHECK_CALLED(ReportResult);
720 ok(hres == S_OK, "Read failed: %08x\n", hres);
721 reported_all_data = TRUE;
724 CHECK_NOT_CALLED(ReportData2);
725 CHECK_NOT_CALLED(ReportResult);
727 }while(hres == S_OK);
729 wait_for_switch = FALSE;
731 CHECK_EXPECT(ReportData2);
733 ok(grfBSCF & BSCF_LASTDATANOTIFICATION, "grfBSCF = %08x\n", grfBSCF);
738 hres = IInternetProtocol_Read(binding_test ? binding_protocol : async_protocol, expect_pv = buf, sizeof(buf), &read);
741 ok(hres == S_FALSE, "Read returned: %08x, expected E_FALSE\n", hres);
742 ok(!read, "read = %d\n", read);
744 }else if(!binding_test && (tested_protocol == HTTP_TEST || tested_protocol == HTTPS_TEST
745 || tested_protocol == FTP_TEST)) {
746 if(!(grfBSCF & BSCF_LASTDATANOTIFICATION) || (grfBSCF & BSCF_DATAFULLYAVAILABLE))
747 CHECK_EXPECT(ReportData);
748 else if (http_post_test)
749 ok(ulProgress == 13, "Read %u bytes instead of 13\n", ulProgress);
751 ok(ulProgress, "ulProgress == 0\n");
753 if(first_data_notif) {
754 ok(grfBSCF == BSCF_FIRSTDATANOTIFICATION
755 || grfBSCF == (BSCF_LASTDATANOTIFICATION|BSCF_DATAFULLYAVAILABLE),
756 "grcfBSCF = %08x\n", grfBSCF);
757 first_data_notif = FALSE;
759 ok(grfBSCF == BSCF_INTERMEDIATEDATANOTIFICATION
760 || grfBSCF == (BSCF_LASTDATANOTIFICATION|BSCF_INTERMEDIATEDATANOTIFICATION)
761 || broken(grfBSCF == (BSCF_FIRSTDATANOTIFICATION|BSCF_LASTDATANOTIFICATION)),
762 "grcfBSCF = %08x\n", grfBSCF);
765 if(!(bindf & BINDF_FROMURLMON) &&
766 !(grfBSCF & BSCF_LASTDATANOTIFICATION)) {
770 CHECK_CALLED(ReportProgress_FINDINGRESOURCE);
771 CHECK_CALLED(ReportProgress_CONNECTING);
773 CHECK_NOT_CALLED(ReportProgress_FINDINGRESOURCE);
774 CHECK_NOT_CALLED(ReportProgress_CONNECTING);
776 CHECK_CALLED(ReportProgress_SENDINGREQUEST);
777 CHECK_CALLED(OnResponse);
778 CHECK_CALLED(ReportProgress_RAWMIMETYPE);
780 SetEvent(event_complete);
782 }else if(!read_report_data) {
787 CHECK_EXPECT(ReportData);
789 if(tested_protocol != BIND_TEST) {
792 SET_EXPECT(MimeFilter_Read);
793 else if(rec_depth > 1)
797 hres = IInternetProtocol_Read(binding_protocol, expect_pv=buf, sizeof(buf), &read);
799 CHECK_CALLED(MimeFilter_Read);
800 else if(rec_depth > 1)
804 }while(hres == S_OK);
812 static HRESULT WINAPI ProtocolSink_ReportResult(IInternetProtocolSink *iface, HRESULT hrResult,
813 DWORD dwError, LPCWSTR szResult)
815 CHECK_EXPECT(ReportResult);
817 if(tested_protocol == FTP_TEST)
818 ok(hrResult == E_PENDING || hrResult == S_OK, "hrResult = %08x, expected E_PENDING or S_OK\n", hrResult);
820 ok(hrResult == expect_hrResult, "hrResult = %08x, expected: %08x\n",
821 hrResult, expect_hrResult);
822 if(SUCCEEDED(hrResult) || tested_protocol == FTP_TEST)
823 ok(dwError == ERROR_SUCCESS, "dwError = %d, expected ERROR_SUCCESS\n", dwError);
825 ok(dwError != ERROR_SUCCESS ||
826 broken(tested_protocol == MK_TEST), /* Win9x, WinME and NT4 */
827 "dwError == ERROR_SUCCESS\n");
828 ok(!szResult, "szResult != NULL\n");
831 SET_EXPECT(ReportData); /* checked after main loop */
836 static IInternetProtocolSinkVtbl protocol_sink_vtbl = {
837 ProtocolSink_QueryInterface,
839 ProtocolSink_Release,
841 ProtocolSink_ReportProgress,
842 ProtocolSink_ReportData,
843 ProtocolSink_ReportResult
846 static IInternetProtocolSink protocol_sink = { &protocol_sink_vtbl };
848 static HRESULT WINAPI MimeProtocolSink_QueryInterface(IInternetProtocolSink *iface, REFIID riid, void **ppv)
850 ok(0, "unexpected call\n");
854 static ULONG WINAPI MimeProtocolSink_AddRef(IInternetProtocolSink *iface)
859 static ULONG WINAPI MimeProtocolSink_Release(IInternetProtocolSink *iface)
864 static HRESULT WINAPI MimeProtocolSink_Switch(IInternetProtocolSink *iface, PROTOCOLDATA *pProtocolData)
868 CHECK_EXPECT(MimeFilter_Switch);
871 hres = IInternetProtocolSink_Switch(filtered_sink, pProtocolData);
872 ok(hres == S_OK, "Switch failed: %08x\n", hres);
873 CHECK_CALLED(Switch);
878 static HRESULT WINAPI MimeProtocolSink_ReportProgress(IInternetProtocolSink *iface, ULONG ulStatusCode,
879 LPCWSTR szStatusText)
881 CHECK_EXPECT(MimeFilter_ReportProgress);
885 static HRESULT WINAPI MimeProtocolSink_ReportData(IInternetProtocolSink *iface, DWORD grfBSCF,
886 ULONG ulProgress, ULONG ulProgressMax)
892 CHECK_EXPECT(MimeFilter_ReportData);
896 hres = IInternetProtocol_Read(filtered_protocol, buf, sizeof(buf), &read);
897 if(tested_protocol == HTTP_TEST)
898 ok(hres == S_OK || hres == E_PENDING || hres == S_FALSE, "Read failed: %08x\n", hres);
900 ok(hres == S_OK, "Read failed: %08x\n", hres);
903 SET_EXPECT(ReportProgress_MIMETYPEAVAILABLE);
904 hres = IInternetProtocolSink_ReportProgress(filtered_sink, BINDSTATUS_VERIFIEDMIMETYPEAVAILABLE, text_htmlW);
905 ok(hres == S_OK, "ReportProgress failed: %08x\n", hres);
906 CHECK_CALLED(ReportProgress_MIMETYPEAVAILABLE);
908 /* FIXME: test BINDSTATUS_CACHEFILENAMEAVAILABLE */
911 if(!read_report_data)
912 SET_EXPECT(ReportData);
913 hres = IInternetProtocolSink_ReportData(filtered_sink, grfBSCF, ulProgress, ulProgressMax);
914 ok(hres == S_OK, "ReportData failed: %08x\n", hres);
915 if(!read_report_data)
916 CHECK_CALLED(ReportData);
924 static HRESULT WINAPI MimeProtocolSink_ReportResult(IInternetProtocolSink *iface, HRESULT hrResult,
925 DWORD dwError, LPCWSTR szResult)
929 CHECK_EXPECT(MimeFilter_ReportResult);
931 ok(hrResult == S_OK, "hrResult = %08x\n", hrResult);
932 ok(dwError == ERROR_SUCCESS, "dwError = %u\n", dwError);
933 ok(!szResult, "szResult = %s\n", wine_dbgstr_w(szResult));
935 SET_EXPECT(ReportResult);
936 hres = IInternetProtocolSink_ReportResult(filtered_sink, hrResult, dwError, szResult);
937 ok(SUCCEEDED(hres), "ReportResult failed: %08x\n", hres);
938 CHECK_CALLED(ReportResult);
943 static IInternetProtocolSinkVtbl mime_protocol_sink_vtbl = {
944 MimeProtocolSink_QueryInterface,
945 MimeProtocolSink_AddRef,
946 MimeProtocolSink_Release,
947 MimeProtocolSink_Switch,
948 MimeProtocolSink_ReportProgress,
949 MimeProtocolSink_ReportData,
950 MimeProtocolSink_ReportResult
953 static IInternetProtocolSink mime_protocol_sink = { &mime_protocol_sink_vtbl };
955 static HRESULT QueryInterface(REFIID riid, void **ppv)
957 static const IID IID_undocumented = {0x58DFC7D0,0x5381,0x43E5,{0x9D,0x72,0x4C,0xDD,0xE4,0xCB,0x0F,0x1A}};
961 if(IsEqualGUID(&IID_IUnknown, riid) || IsEqualGUID(&IID_IInternetProtocolSink, riid))
962 *ppv = &protocol_sink;
963 if(IsEqualGUID(&IID_IServiceProvider, riid))
964 *ppv = &service_provider;
965 if(IsEqualGUID(&IID_IUriContainer, riid))
966 return E_NOINTERFACE; /* TODO */
968 /* NOTE: IE8 queries for undocumented {58DFC7D0-5381-43E5-9D72-4CDDE4CB0F1A} interface. */
969 if(IsEqualGUID(&IID_undocumented, riid))
970 return E_NOINTERFACE;
975 ok(0, "unexpected call %s\n", debugstr_guid(riid));
976 return E_NOINTERFACE;
979 static HRESULT WINAPI BindInfo_QueryInterface(IInternetBindInfo *iface, REFIID riid, void **ppv)
981 if(IsEqualGUID(&IID_IUnknown, riid) || IsEqualGUID(&IID_IInternetBindInfo, riid)) {
985 return E_NOINTERFACE;
988 static ULONG WINAPI BindInfo_AddRef(IInternetBindInfo *iface)
993 static ULONG WINAPI BindInfo_Release(IInternetBindInfo *iface)
998 static HRESULT WINAPI BindInfo_GetBindInfo(IInternetBindInfo *iface, DWORD *grfBINDF, BINDINFO *pbindinfo)
1002 static const CHAR szPostData[] = "mode=Test";
1004 CHECK_EXPECT(GetBindInfo);
1006 ok(grfBINDF != NULL, "grfBINDF == NULL\n");
1007 ok(pbindinfo != NULL, "pbindinfo == NULL\n");
1008 ok(pbindinfo->cbSize == sizeof(BINDINFO), "wrong size of pbindinfo: %d\n", pbindinfo->cbSize);
1012 *grfBINDF |= BINDF_FROMURLMON;
1013 cbSize = pbindinfo->cbSize;
1014 memset(pbindinfo, 0, cbSize);
1015 pbindinfo->cbSize = cbSize;
1019 /* Must be GMEM_FIXED, GMEM_MOVABLE does not work properly
1020 * with urlmon on native (Win98 and WinXP) */
1021 U(pbindinfo->stgmedData).hGlobal = GlobalAlloc(GPTR, sizeof(szPostData));
1022 if (!U(pbindinfo->stgmedData).hGlobal)
1024 http_post_test = FALSE;
1025 skip("Out of memory\n");
1026 return E_OUTOFMEMORY;
1028 lstrcpy((LPSTR)U(pbindinfo->stgmedData).hGlobal, szPostData);
1029 pbindinfo->cbstgmedData = sizeof(szPostData)-1;
1030 pbindinfo->dwBindVerb = BINDVERB_POST;
1031 pbindinfo->stgmedData.tymed = TYMED_HGLOBAL;
1037 static HRESULT WINAPI BindInfo_GetBindString(IInternetBindInfo *iface, ULONG ulStringType,
1038 LPOLESTR *ppwzStr, ULONG cEl, ULONG *pcElFetched)
1040 ok(ppwzStr != NULL, "ppwzStr == NULL\n");
1041 ok(pcElFetched != NULL, "pcElFetched == NULL\n");
1043 switch(ulStringType) {
1044 case BINDSTRING_ACCEPT_MIMES:
1045 CHECK_EXPECT(GetBindString_ACCEPT_MIMES);
1046 ok(cEl == 256, "cEl=%d, expected 256\n", cEl);
1048 ok(*pcElFetched == 256, "*pcElFetched=%d, expected 256\n", *pcElFetched);
1052 *ppwzStr = CoTaskMemAlloc(sizeof(acc_mimeW));
1053 memcpy(*ppwzStr, acc_mimeW, sizeof(acc_mimeW));
1056 case BINDSTRING_USER_AGENT:
1057 CHECK_EXPECT(GetBindString_USER_AGENT);
1058 ok(cEl == 1, "cEl=%d, expected 1\n", cEl);
1060 ok(*pcElFetched == 0, "*pcElFetch=%d, expectd 0\n", *pcElFetched);
1064 *ppwzStr = CoTaskMemAlloc(sizeof(user_agentW));
1065 memcpy(*ppwzStr, user_agentW, sizeof(user_agentW));
1068 case BINDSTRING_POST_COOKIE:
1069 CHECK_EXPECT(GetBindString_POST_COOKIE);
1070 ok(cEl == 1, "cEl=%d, expected 1\n", cEl);
1072 ok(*pcElFetched == 0, "*pcElFetch=%d, expectd 0\n", *pcElFetched);
1074 case BINDSTRING_URL: {
1077 CHECK_EXPECT(GetBindString_URL);
1078 ok(cEl == 1, "cEl=%d, expected 1\n", cEl);
1079 ok(*pcElFetched == 0, "*pcElFetch=%d, expectd 0\n", *pcElFetched);
1082 size = (lstrlenW(binding_urls[tested_protocol])+1)*sizeof(WCHAR);
1083 *ppwzStr = CoTaskMemAlloc(size);
1084 memcpy(*ppwzStr, binding_urls[tested_protocol], size);
1088 ok(0, "unexpected call\n");
1094 static IInternetBindInfoVtbl bind_info_vtbl = {
1095 BindInfo_QueryInterface,
1098 BindInfo_GetBindInfo,
1099 BindInfo_GetBindString
1102 static IInternetBindInfo bind_info = { &bind_info_vtbl };
1104 static HRESULT WINAPI InternetPriority_QueryInterface(IInternetPriority *iface,
1105 REFIID riid, void **ppv)
1107 ok(0, "unexpected call\n");
1108 return E_NOINTERFACE;
1111 static ULONG WINAPI InternetPriority_AddRef(IInternetPriority *iface)
1116 static ULONG WINAPI InternetPriority_Release(IInternetPriority *iface)
1121 static HRESULT WINAPI InternetPriority_SetPriority(IInternetPriority *iface, LONG nPriority)
1123 CHECK_EXPECT(SetPriority);
1124 ok(nPriority == ex_priority, "nPriority=%d\n", nPriority);
1128 static HRESULT WINAPI InternetPriority_GetPriority(IInternetPriority *iface, LONG *pnPriority)
1130 ok(0, "unexpected call\n");
1135 static const IInternetPriorityVtbl InternetPriorityVtbl = {
1136 InternetPriority_QueryInterface,
1137 InternetPriority_AddRef,
1138 InternetPriority_Release,
1139 InternetPriority_SetPriority,
1140 InternetPriority_GetPriority
1143 static IInternetPriority InternetPriority = { &InternetPriorityVtbl };
1145 static ULONG WINAPI Protocol_AddRef(IInternetProtocol *iface)
1150 static ULONG WINAPI Protocol_Release(IInternetProtocol *iface)
1155 static HRESULT WINAPI Protocol_Abort(IInternetProtocol *iface, HRESULT hrReason,
1158 ok(0, "unexpected call\n");
1162 static HRESULT WINAPI Protocol_Suspend(IInternetProtocol *iface)
1164 ok(0, "unexpected call\n");
1168 static HRESULT WINAPI Protocol_Resume(IInternetProtocol *iface)
1170 ok(0, "unexpected call\n");
1174 static HRESULT WINAPI Protocol_Seek(IInternetProtocol *iface,
1175 LARGE_INTEGER dlibMove, DWORD dwOrigin, ULARGE_INTEGER *plibNewPosition)
1177 ok(0, "unexpected call\n");
1181 static HRESULT WINAPI ProtocolEmul_QueryInterface(IInternetProtocol *iface, REFIID riid, void **ppv)
1183 if(IsEqualGUID(&IID_IUnknown, riid) || IsEqualGUID(&IID_IInternetProtocol, riid)) {
1188 if(IsEqualGUID(&IID_IInternetProtocolEx, riid)) {
1189 trace("IID_IInternetProtocolEx not supported\n");
1191 return E_NOINTERFACE;
1194 if(IsEqualGUID(&IID_IInternetPriority, riid)) {
1195 *ppv = &InternetPriority;
1199 if(IsEqualGUID(&IID_IWinInetInfo, riid)) {
1200 CHECK_EXPECT(QueryInterface_IWinInetInfo);
1202 return E_NOINTERFACE;
1205 if(IsEqualGUID(&IID_IWinInetHttpInfo, riid)) {
1206 CHECK_EXPECT(QueryInterface_IWinInetHttpInfo);
1208 return E_NOINTERFACE;
1211 ok(0, "unexpected riid %s\n", debugstr_guid(riid));
1213 return E_NOINTERFACE;
1216 static DWORD WINAPI thread_proc(PVOID arg)
1220 memset(&protocoldata, -1, sizeof(protocoldata));
1224 SET_EXPECT(ReportProgress_FINDINGRESOURCE);
1225 hres = IInternetProtocolSink_ReportProgress(binding_sink,
1226 BINDSTATUS_FINDINGRESOURCE, hostW);
1227 CHECK_CALLED(ReportProgress_FINDINGRESOURCE);
1228 ok(hres == S_OK, "ReportProgress failed: %08x\n", hres);
1230 SET_EXPECT(ReportProgress_CONNECTING);
1231 hres = IInternetProtocolSink_ReportProgress(binding_sink,
1232 BINDSTATUS_CONNECTING, winehq_ipW);
1233 CHECK_CALLED(ReportProgress_CONNECTING);
1234 ok(hres == S_OK, "ReportProgress failed: %08x\n", hres);
1236 SET_EXPECT(ReportProgress_SENDINGREQUEST);
1237 hres = IInternetProtocolSink_ReportProgress(binding_sink,
1238 BINDSTATUS_SENDINGREQUEST, NULL);
1239 CHECK_CALLED(ReportProgress_SENDINGREQUEST);
1240 ok(hres == S_OK, "ReportProgress failed: %08x\n", hres);
1244 hres = IInternetProtocolSink_Switch(binding_sink, &protocoldata);
1245 CHECK_CALLED(Switch);
1246 ok(hres == S_OK, "Switch failed: %08x\n", hres);
1251 SET_EXPECT(MimeFilter_Switch);
1254 hres = IInternetProtocolSink_Switch(binding_sink, &protocoldata);
1255 ok(hres == S_OK, "Switch failed: %08x\n", hres);
1257 CHECK_CALLED(MimeFilter_Switch);
1259 CHECK_CALLED(Switch);
1263 SET_EXPECT(MimeFilter_Switch);
1266 hres = IInternetProtocolSink_Switch(binding_sink, &protocoldata);
1267 ok(hres == S_OK, "Switch failed: %08x\n", hres);
1269 CHECK_CALLED(MimeFilter_Switch);
1271 CHECK_CALLED(Switch);
1275 SET_EXPECT(MimeFilter_Switch);
1278 hres = IInternetProtocolSink_Switch(binding_sink, &protocoldata);
1279 ok(hres == S_OK, "Switch failed: %08x\n", hres);
1281 CHECK_CALLED(MimeFilter_Switch);
1283 CHECK_CALLED(Switch);
1286 SetEvent(event_complete);
1291 static HRESULT WINAPI ProtocolEmul_Start(IInternetProtocol *iface, LPCWSTR szUrl,
1292 IInternetProtocolSink *pOIProtSink, IInternetBindInfo *pOIBindInfo,
1293 DWORD grfPI, HANDLE_PTR dwReserved)
1295 BINDINFO bindinfo, exp_bindinfo;
1299 CHECK_EXPECT(Start);
1301 ok(pOIProtSink != NULL, "pOIProtSink == NULL\n");
1302 ok(pOIBindInfo != NULL, "pOIBindInfo == NULL\n");
1303 ok(pOIProtSink != &protocol_sink, "unexpected pOIProtSink\n");
1304 ok(pOIBindInfo != &bind_info, "unexpected pOIBindInfo\n");
1305 ok(!grfPI, "grfPI = %x\n", grfPI);
1306 ok(!dwReserved, "dwReserved = %lx\n", dwReserved);
1309 ok(pOIProtSink == binding_sink, "pOIProtSink != binding_sink\n");
1311 memset(&bindinfo, 0, sizeof(bindinfo));
1312 bindinfo.cbSize = sizeof(bindinfo);
1313 memcpy(&exp_bindinfo, &bindinfo, sizeof(bindinfo));
1314 SET_EXPECT(GetBindInfo);
1315 hres = IInternetBindInfo_GetBindInfo(pOIBindInfo, &cbindf, &bindinfo);
1316 ok(hres == S_OK, "GetBindInfo failed: %08x\n", hres);
1317 CHECK_CALLED(GetBindInfo);
1318 ok(cbindf == (bindf|BINDF_FROMURLMON), "bindf = %x, expected %x\n",
1319 cbindf, (bindf|BINDF_FROMURLMON));
1320 ok(!memcmp(&exp_bindinfo, &bindinfo, sizeof(bindinfo)), "unexpected bindinfo\n");
1321 ReleaseBindInfo(&bindinfo);
1323 SET_EXPECT(ReportProgress_SENDINGREQUEST);
1324 hres = IInternetProtocolSink_ReportProgress(pOIProtSink, BINDSTATUS_SENDINGREQUEST, emptyW);
1325 ok(hres == S_OK, "ReportProgress(BINDSTATUS_SENDINGREQUEST) failed: %08x\n", hres);
1326 CHECK_CALLED(ReportProgress_SENDINGREQUEST);
1328 if(tested_protocol == HTTP_TEST || tested_protocol == HTTPS_TEST) {
1329 IServiceProvider *service_provider;
1330 IHttpNegotiate *http_negotiate;
1331 IHttpNegotiate2 *http_negotiate2;
1332 LPWSTR ua = (LPWSTR)0xdeadbeef, accept_mimes[256];
1333 LPWSTR additional_headers = NULL;
1335 DWORD fetched = 0, size = 100;
1338 SET_EXPECT(GetBindString_USER_AGENT);
1339 hres = IInternetBindInfo_GetBindString(pOIBindInfo, BINDSTRING_USER_AGENT,
1341 CHECK_CALLED(GetBindString_USER_AGENT);
1342 ok(hres == S_OK, "GetBindString(BINDSTRING_USER_AGETNT) failed: %08x\n", hres);
1343 ok(fetched == 1, "fetched = %d, expected 254\n", fetched);
1344 ok(ua != NULL, "ua = %p\n", ua);
1345 ok(!strcmp_ww(ua, user_agentW), "unexpected user agent %s\n", wine_dbgstr_w(ua));
1349 SET_EXPECT(GetBindString_ACCEPT_MIMES);
1350 hres = IInternetBindInfo_GetBindString(pOIBindInfo, BINDSTRING_ACCEPT_MIMES,
1351 accept_mimes, 256, &fetched);
1352 CHECK_CALLED(GetBindString_ACCEPT_MIMES);
1355 "GetBindString(BINDSTRING_ACCEPT_MIMES) failed: %08x\n", hres);
1356 ok(fetched == 1, "fetched = %d, expected 1\n", fetched);
1357 ok(!strcmp_ww(acc_mimeW, accept_mimes[0]), "unexpected mimes %s\n", wine_dbgstr_w(accept_mimes[0]));
1359 hres = IInternetBindInfo_QueryInterface(pOIBindInfo, &IID_IServiceProvider,
1360 (void**)&service_provider);
1361 ok(hres == S_OK, "QueryInterface failed: %08x\n", hres);
1363 SET_EXPECT(QueryService_HttpNegotiate);
1364 hres = IServiceProvider_QueryService(service_provider, &IID_IHttpNegotiate,
1365 &IID_IHttpNegotiate, (void**)&http_negotiate);
1366 CHECK_CALLED(QueryService_HttpNegotiate);
1367 ok(hres == S_OK, "QueryService failed: %08x\n", hres);
1369 SET_EXPECT(BeginningTransaction);
1370 hres = IHttpNegotiate_BeginningTransaction(http_negotiate, binding_urls[tested_protocol],
1371 NULL, 0, &additional_headers);
1372 CHECK_CALLED(BeginningTransaction);
1373 IHttpNegotiate_Release(http_negotiate);
1374 ok(hres == S_OK, "BeginningTransction failed: %08x\n", hres);
1375 ok(additional_headers == NULL, "additional_headers=%p\n", additional_headers);
1377 SET_EXPECT(QueryService_HttpNegotiate);
1378 hres = IServiceProvider_QueryService(service_provider, &IID_IHttpNegotiate2,
1379 &IID_IHttpNegotiate2, (void**)&http_negotiate2);
1380 CHECK_CALLED(QueryService_HttpNegotiate);
1381 ok(hres == S_OK, "QueryService failed: %08x\n", hres);
1384 SET_EXPECT(GetRootSecurityId);
1385 hres = IHttpNegotiate2_GetRootSecurityId(http_negotiate2, sec_id, &size, 0);
1386 CHECK_CALLED(GetRootSecurityId);
1387 IHttpNegotiate2_Release(http_negotiate2);
1388 ok(hres == E_FAIL, "GetRootSecurityId failed: %08x, expected E_FAIL\n", hres);
1389 ok(size == 13, "size=%d\n", size);
1391 IServiceProvider_Release(service_provider);
1393 CreateThread(NULL, 0, thread_proc, NULL, 0, &tid);
1398 SET_EXPECT(ReportProgress_CACHEFILENAMEAVAILABLE);
1399 hres = IInternetProtocolSink_ReportProgress(pOIProtSink,
1400 BINDSTATUS_CACHEFILENAMEAVAILABLE, expect_wsz = emptyW);
1401 ok(hres == S_OK, "ReportProgress(BINDSTATUS_CACHEFILENAMEAVAILABLE) failed: %08x\n", hres);
1402 CHECK_CALLED(ReportProgress_CACHEFILENAMEAVAILABLE);
1404 if(mimefilter_test) {
1405 SET_EXPECT(MimeFilter_CreateInstance);
1406 SET_EXPECT(MimeFilter_Start);
1407 SET_EXPECT(ReportProgress_LOADINGMIMEHANDLER);
1409 SET_EXPECT(ReportProgress_MIMETYPEAVAILABLE);
1410 hres = IInternetProtocolSink_ReportProgress(pOIProtSink, BINDSTATUS_VERIFIEDMIMETYPEAVAILABLE,
1411 mimefilter_test ? gzipW : (expect_wsz = text_htmlW));
1413 "ReportProgress(BINDSTATUS_VERIFIEDMIMETYPEAVAILABLE) failed: %08x\n", hres);
1414 if(mimefilter_test) {
1415 CHECK_CALLED(MimeFilter_CreateInstance);
1416 CHECK_CALLED(MimeFilter_Start);
1417 CHECK_CALLED(ReportProgress_LOADINGMIMEHANDLER);
1418 todo_wine CHECK_CALLED(ReportProgress_MIMETYPEAVAILABLE);
1420 CHECK_CALLED(ReportProgress_MIMETYPEAVAILABLE);
1424 SET_EXPECT(MimeFilter_ReportData);
1426 SET_EXPECT(ReportData);
1427 hres = IInternetProtocolSink_ReportData(pOIProtSink,
1428 BSCF_FIRSTDATANOTIFICATION | BSCF_LASTDATANOTIFICATION, 13, 13);
1429 ok(hres == S_OK, "ReportData failed: %08x\n", hres);
1431 CHECK_CALLED(MimeFilter_ReportData);
1433 CHECK_CALLED(ReportData);
1435 if(tested_protocol == BIND_TEST) {
1436 hres = IInternetProtocol_Terminate(binding_protocol, 0);
1437 ok(hres == E_FAIL, "Termiante failed: %08x\n", hres);
1441 SET_EXPECT(MimeFilter_ReportResult);
1443 SET_EXPECT(ReportResult);
1444 hres = IInternetProtocolSink_ReportResult(pOIProtSink, S_OK, 0, NULL);
1445 ok(hres == S_OK, "ReportResult failed: %08x\n", hres);
1447 CHECK_CALLED(MimeFilter_ReportResult);
1449 CHECK_CALLED(ReportResult);
1454 static HRESULT WINAPI ProtocolEmul_Continue(IInternetProtocol *iface,
1455 PROTOCOLDATA *pProtocolData)
1460 CHECK_EXPECT(Continue);
1462 ok(pProtocolData != NULL, "pProtocolData == NULL\n");
1463 if(!pProtocolData || tested_protocol == BIND_TEST)
1466 ok(pProtocolData != &protocoldata, "pProtocolData == &protocoldata\n");
1467 ok(pProtocolData->grfFlags == protocoldata.grfFlags, "grfFlags wrong %x/%x\n",
1468 pProtocolData->grfFlags, protocoldata.grfFlags );
1469 ok(pProtocolData->dwState == protocoldata.dwState, "dwState wrong %x/%x\n",
1470 pProtocolData->dwState, protocoldata.dwState );
1471 ok(pProtocolData->pData == protocoldata.pData, "pData wrong %p/%p\n",
1472 pProtocolData->pData, protocoldata.pData );
1473 ok(pProtocolData->cbData == protocoldata.cbData, "cbData wrong %x/%x\n",
1474 pProtocolData->cbData, protocoldata.cbData );
1477 switch(prot_state) {
1479 IServiceProvider *service_provider;
1480 IHttpNegotiate *http_negotiate;
1481 static WCHAR header[] = {'?',0};
1483 hres = IInternetProtocolSink_QueryInterface(binding_sink, &IID_IServiceProvider,
1484 (void**)&service_provider);
1485 ok(hres == S_OK, "Could not get IServiceProvicder\n");
1487 SET_EXPECT(QueryService_HttpNegotiate);
1488 hres = IServiceProvider_QueryService(service_provider, &IID_IHttpNegotiate,
1489 &IID_IHttpNegotiate, (void**)&http_negotiate);
1490 IServiceProvider_Release(service_provider);
1491 CHECK_CALLED(QueryService_HttpNegotiate);
1492 ok(hres == S_OK, "Could not get IHttpNegotiate\n");
1494 SET_EXPECT(OnResponse);
1495 hres = IHttpNegotiate_OnResponse(http_negotiate, 200, header, NULL, NULL);
1496 IHttpNegotiate_Release(http_negotiate);
1497 CHECK_CALLED(OnResponse);
1498 IHttpNegotiate_Release(http_negotiate);
1499 ok(hres == S_OK, "OnResponse failed: %08x\n", hres);
1501 if(mimefilter_test) {
1502 SET_EXPECT(MimeFilter_CreateInstance);
1503 SET_EXPECT(MimeFilter_Start);
1504 SET_EXPECT(ReportProgress_LOADINGMIMEHANDLER);
1505 }else if(!(pi & PI_MIMEVERIFICATION)) {
1506 SET_EXPECT(ReportProgress_MIMETYPEAVAILABLE);
1508 hres = IInternetProtocolSink_ReportProgress(binding_sink,
1509 BINDSTATUS_MIMETYPEAVAILABLE, mimefilter_test ? gzipW : text_htmlW);
1510 if(mimefilter_test) {
1511 CHECK_CALLED(MimeFilter_CreateInstance);
1512 CHECK_CALLED(MimeFilter_Start);
1513 CHECK_CALLED(ReportProgress_LOADINGMIMEHANDLER);
1514 }else if(!(pi & PI_MIMEVERIFICATION)) {
1515 CHECK_CALLED(ReportProgress_MIMETYPEAVAILABLE);
1518 "ReportProgress(BINDSTATUS_MIMETYPEAVAILABLE) failed: %08x\n", hres);
1520 bscf |= BSCF_FIRSTDATANOTIFICATION;
1525 bscf = BSCF_INTERMEDIATEDATANOTIFICATION;
1530 if(mimefilter_test) {
1531 SET_EXPECT(MimeFilter_ReportData);
1532 }else if(pi & PI_MIMEVERIFICATION) {
1534 SET_EXPECT(Read); /* checked in ReportData for short_read */
1536 if(!mimefilter_test)
1537 SET_EXPECT(Read); /* checked in BINDSTATUS_MIMETYPEAVAILABLE or ReportData */
1538 SET_EXPECT(ReportProgress_MIMETYPEAVAILABLE);
1541 SET_EXPECT(ReportData);
1543 SET_EXPECT(ReportData);
1546 hres = IInternetProtocolSink_ReportData(binding_sink, bscf, pr, 400);
1547 ok(hres == S_OK, "ReportData failed: %08x\n", hres);
1549 if(mimefilter_test) {
1550 SET_EXPECT(MimeFilter_ReportData);
1551 }else if(pi & PI_MIMEVERIFICATION) {
1552 if(!short_read && pr < 200)
1555 CHECK_CALLED(ReportProgress_MIMETYPEAVAILABLE);
1558 CHECK_CALLED(ReportData);
1567 static HRESULT WINAPI ProtocolEmul_Terminate(IInternetProtocol *iface, DWORD dwOptions)
1569 CHECK_EXPECT(Terminate);
1570 ok(!dwOptions, "dwOptions=%d\n", dwOptions);
1574 static HRESULT WINAPI ProtocolEmul_Read(IInternetProtocol *iface, void *pv,
1575 ULONG cb, ULONG *pcbRead)
1577 if(read_report_data)
1578 CHECK_EXPECT2(Read2);
1580 if(mimefilter_test || short_read) {
1581 if(!read_report_data)
1582 CHECK_EXPECT2(Read);
1583 }else if((pi & PI_MIMEVERIFICATION)) {
1584 if(!read_report_data)
1585 CHECK_EXPECT2(Read);
1587 if(prot_read < 300) {
1588 ok(pv != expect_pv, "pv == expect_pv\n");
1590 ok(cb == 2048-prot_read, "cb=%d\n", cb);
1592 ok(cb == 700, "cb=%d\n", cb);
1594 ok(expect_pv <= pv && (BYTE*)pv < (BYTE*)expect_pv + cb, "pv != expect_pv\n");
1597 if(!read_report_data)
1600 ok(pv == expect_pv, "pv != expect_pv\n");
1601 ok(cb == 1000, "cb=%d\n", cb);
1602 ok(!*pcbRead, "*pcbRead = %d\n", *pcbRead);
1604 ok(pcbRead != NULL, "pcbRead == NULL\n");
1606 if(prot_state == 3 || (short_read && prot_state != 4)) {
1611 SET_EXPECT(Read2); /* checked in BINDSTATUS_MIMETYPEAVAILABLE */
1612 SET_EXPECT(ReportProgress_MIMETYPEAVAILABLE);
1615 SET_EXPECT(MimeFilter_ReportData);
1616 else if(direct_read)
1617 SET_EXPECT(ReportData2);
1619 hres = IInternetProtocolSink_ReportData(binding_sink,
1620 BSCF_LASTDATANOTIFICATION|BSCF_INTERMEDIATEDATANOTIFICATION, 0, 0);
1622 ok(hres == S_OK, "ReportData failed: %08x\n", hres);
1624 CHECK_CALLED(ReportProgress_MIMETYPEAVAILABLE);
1626 CHECK_CALLED(MimeFilter_ReportData);
1627 else if(direct_read)
1628 CHECK_CALLED(ReportData2);
1631 SET_EXPECT(MimeFilter_ReportResult);
1633 SET_EXPECT(ReportResult);
1634 hres = IInternetProtocolSink_ReportResult(binding_sink, S_OK, ERROR_SUCCESS, NULL);
1635 ok(hres == S_OK, "ReportResult failed: %08x\n", hres);
1637 CHECK_CALLED(MimeFilter_ReportResult);
1639 CHECK_CALLED(ReportResult);
1641 memset(pv, 'x', 100);
1642 prot_read += *pcbRead = 100;
1644 }if(prot_state == 4) {
1649 if((async_read_pending = !async_read_pending)) {
1651 return tested_protocol == HTTP_TEST || tested_protocol == HTTPS_TEST ? E_PENDING : S_FALSE;
1654 memset(pv, 'x', 100);
1655 prot_read += *pcbRead = 100;
1659 static HRESULT WINAPI ProtocolEmul_LockRequest(IInternetProtocol *iface, DWORD dwOptions)
1661 CHECK_EXPECT(LockRequest);
1662 ok(dwOptions == 0, "dwOptions=%x\n", dwOptions);
1666 static HRESULT WINAPI ProtocolEmul_UnlockRequest(IInternetProtocol *iface)
1668 CHECK_EXPECT(UnlockRequest);
1672 static const IInternetProtocolVtbl ProtocolVtbl = {
1673 ProtocolEmul_QueryInterface,
1677 ProtocolEmul_Continue,
1679 ProtocolEmul_Terminate,
1684 ProtocolEmul_LockRequest,
1685 ProtocolEmul_UnlockRequest
1688 static IInternetProtocol Protocol = { &ProtocolVtbl };
1690 static HRESULT WINAPI MimeProtocol_QueryInterface(IInternetProtocol *iface, REFIID riid, void **ppv)
1692 if(IsEqualGUID(&IID_IUnknown, riid) || IsEqualGUID(&IID_IInternetProtocol, riid)) {
1697 if(IsEqualGUID(&IID_IInternetProtocolSink, riid)) {
1698 *ppv = &mime_protocol_sink;
1702 ok(0, "unexpected riid %s\n", debugstr_guid(riid));
1704 return E_NOINTERFACE;
1707 static HRESULT WINAPI MimeProtocol_Start(IInternetProtocol *iface, LPCWSTR szUrl,
1708 IInternetProtocolSink *pOIProtSink, IInternetBindInfo *pOIBindInfo,
1709 DWORD grfPI, HANDLE_PTR dwReserved)
1711 PROTOCOLFILTERDATA *data;
1712 LPOLESTR url_str = NULL;
1718 CHECK_EXPECT(MimeFilter_Start);
1720 ok(!strcmp_ww(szUrl, gzipW), "wrong url %s\n", wine_dbgstr_w(szUrl));
1721 ok(grfPI == (PI_FILTER_MODE|PI_FORCE_ASYNC), "grfPI=%x, expected PI_FILTER_MODE|PI_FORCE_ASYNC\n", grfPI);
1722 ok(dwReserved, "dwReserved == 0\n");
1723 ok(pOIProtSink != NULL, "pOIProtSink == NULL\n");
1724 ok(pOIBindInfo != NULL, "pOIBindInfo == NULL\n");
1727 ok(pOIProtSink != binding_sink, "pOIProtSink == protocol_sink\n");
1728 ok(pOIBindInfo == prot_bind_info, "pOIBindInfo != bind_info\n");
1730 ok(pOIProtSink == &protocol_sink, "pOIProtSink != protocol_sink\n");
1731 ok(pOIBindInfo == &bind_info, "pOIBindInfo != bind_info\n");
1734 data = (void*)dwReserved;
1735 ok(data->cbSize == sizeof(*data), "data->cbSize = %d\n", data->cbSize);
1736 ok(!data->pProtocolSink, "data->pProtocolSink != NULL\n");
1737 ok(data->pProtocol != NULL, "data->pProtocol == NULL\n");
1738 ok(!data->pUnk, "data->pUnk != NULL\n");
1739 ok(!data->dwFilterFlags, "data->dwProtocolFlags = %x\n", data->dwFilterFlags);
1741 IInternetProtocolSink *prot_sink;
1743 IInternetProtocol_QueryInterface(data->pProtocol, &IID_IInternetProtocolSink, (void**)&prot_sink);
1744 ok(prot_sink == pOIProtSink, "QI(data->pProtocol, IID_IInternetProtocolSink) != pOIProtSink\n");
1745 IInternetProtocolSink_Release(prot_sink);
1747 ok(data->pProtocol != binding_protocol, "data->pProtocol == binding_protocol\n");
1749 filtered_protocol = data->pProtocol;
1750 IInternetProtocol_AddRef(filtered_protocol);
1752 IInternetProtocol *prot;
1754 IInternetProtocol_QueryInterface(data->pProtocol, &IID_IInternetProtocol, (void**)&prot);
1755 ok(prot == async_protocol, "QI(data->pProtocol, IID_IInternetProtocol) != async_protocol\n");
1756 IInternetProtocol_Release(prot);
1758 ok(data->pProtocol != async_protocol, "data->pProtocol == async_protocol\n");
1761 filtered_sink = pOIProtSink;
1763 SET_EXPECT(ReportProgress_DECODING);
1764 hres = IInternetProtocolSink_ReportProgress(pOIProtSink, BINDSTATUS_DECODING, gzipW);
1765 ok(hres == S_OK, "ReportProgress(BINDSTATUS_DECODING) failed: %08x\n", hres);
1766 CHECK_CALLED(ReportProgress_DECODING);
1768 SET_EXPECT(GetBindInfo);
1769 memset(&bindinfo, 0, sizeof(bindinfo));
1770 bindinfo.cbSize = sizeof(bindinfo);
1771 hres = IInternetBindInfo_GetBindInfo(pOIBindInfo, &cbindf, &bindinfo);
1772 ok(hres == S_OK, "GetBindInfo failed: %08x\n", hres);
1773 ok(cbindf == (bindf|BINDF_FROMURLMON), "cbindf = %x, expected %x\n", cbindf, bindf);
1774 CHECK_CALLED(GetBindInfo);
1776 SET_EXPECT(GetBindString_URL);
1777 hres = IInternetBindInfo_GetBindString(pOIBindInfo, BINDSTRING_URL, &url_str, 1, &fetched);
1778 ok(hres == S_OK, "GetBindString(BINDSTRING_URL) failed: %08x\n", hres);
1779 ok(fetched == 1, "fetched = %d\n", fetched);
1780 ok(!strcmp_ww(url_str, binding_urls[tested_protocol]), "wrong url_str %s\n", wine_dbgstr_w(url_str));
1781 CoTaskMemFree(url_str);
1782 CHECK_CALLED(GetBindString_URL);
1787 static HRESULT WINAPI Protocol_Continue(IInternetProtocol *iface,
1788 PROTOCOLDATA *pProtocolData)
1790 CHECK_EXPECT(MimeFilter_Continue);
1794 static HRESULT WINAPI MimeProtocol_Terminate(IInternetProtocol *iface, DWORD dwOptions)
1798 CHECK_EXPECT(MimeFilter_Terminate);
1800 ok(!dwOptions, "dwOptions = %x\n", dwOptions);
1802 SET_EXPECT(Terminate);
1803 hres = IInternetProtocol_Terminate(filtered_protocol, dwOptions);
1804 ok(hres == S_OK, "Terminate failed: %08x\n", hres);
1805 CHECK_CALLED(Terminate);
1810 static HRESULT WINAPI MimeProtocol_Read(IInternetProtocol *iface, void *pv,
1811 ULONG cb, ULONG *pcbRead)
1817 CHECK_EXPECT(MimeFilter_Read);
1819 ok(pv != NULL, "pv == NULL\n");
1820 ok(cb != 0, "cb == 0\n");
1821 ok(pcbRead != NULL, "pcbRead == NULL\n");
1823 if(read_report_data)
1827 hres = IInternetProtocol_Read(filtered_protocol, buf, sizeof(buf), &read);
1828 ok(hres == S_OK || hres == S_FALSE || hres == E_PENDING, "Read failed: %08x\n", hres);
1829 if(read_report_data)
1830 CHECK_CALLED(Read2);
1835 ok(*pcbRead == 0, "*pcbRead=%d, expected 0\n", *pcbRead);
1839 memset(pv, 'x', read);
1843 static HRESULT WINAPI MimeProtocol_LockRequest(IInternetProtocol *iface, DWORD dwOptions)
1847 CHECK_EXPECT(MimeFilter_LockRequest);
1849 ok(!dwOptions, "dwOptions = %x\n", dwOptions);
1851 SET_EXPECT(LockRequest);
1852 hres = IInternetProtocol_LockRequest(filtered_protocol, dwOptions);
1853 ok(hres == S_OK, "LockRequest failed: %08x\n", hres);
1854 CHECK_CALLED(LockRequest);
1859 static HRESULT WINAPI MimeProtocol_UnlockRequest(IInternetProtocol *iface)
1863 CHECK_EXPECT(MimeFilter_UnlockRequest);
1865 SET_EXPECT(UnlockRequest);
1866 hres = IInternetProtocol_UnlockRequest(filtered_protocol);
1867 ok(hres == S_OK, "UnlockRequest failed: %08x\n", hres);
1868 CHECK_CALLED(UnlockRequest);
1873 static const IInternetProtocolVtbl MimeProtocolVtbl = {
1874 MimeProtocol_QueryInterface,
1880 MimeProtocol_Terminate,
1885 MimeProtocol_LockRequest,
1886 MimeProtocol_UnlockRequest
1889 static IInternetProtocol MimeProtocol = { &MimeProtocolVtbl };
1891 static HRESULT WINAPI ClassFactory_QueryInterface(IClassFactory *iface, REFIID riid, void **ppv)
1893 ok(0, "unexpected call\n");
1894 return E_NOINTERFACE;
1897 static ULONG WINAPI ClassFactory_AddRef(IClassFactory *iface)
1902 static ULONG WINAPI ClassFactory_Release(IClassFactory *iface)
1907 static HRESULT WINAPI ClassFactory_CreateInstance(IClassFactory *iface, IUnknown *pOuter,
1908 REFIID riid, void **ppv)
1910 CHECK_EXPECT(CreateInstance);
1912 ok(pOuter == (IUnknown*)prot_bind_info, "pOuter != protocol_unk\n");
1913 ok(IsEqualGUID(&IID_IUnknown, riid), "unexpected riid %s\n", debugstr_guid(riid));
1914 ok(ppv != NULL, "ppv == NULL\n");
1920 static HRESULT WINAPI ClassFactory_LockServer(IClassFactory *iface, BOOL dolock)
1922 ok(0, "unexpected call\n");
1926 static const IClassFactoryVtbl ClassFactoryVtbl = {
1927 ClassFactory_QueryInterface,
1928 ClassFactory_AddRef,
1929 ClassFactory_Release,
1930 ClassFactory_CreateInstance,
1931 ClassFactory_LockServer
1934 static IClassFactory ClassFactory = { &ClassFactoryVtbl };
1936 static HRESULT WINAPI MimeFilter_CreateInstance(IClassFactory *iface, IUnknown *outer, REFIID riid, void **ppv)
1938 CHECK_EXPECT(MimeFilter_CreateInstance);
1940 ok(!outer, "outer = %p\n", outer);
1941 ok(IsEqualGUID(&IID_IInternetProtocol, riid), "unexpected riid %s\n", debugstr_guid(riid));
1943 *ppv = &MimeProtocol;
1947 static const IClassFactoryVtbl MimeFilterCFVtbl = {
1948 ClassFactory_QueryInterface,
1949 ClassFactory_AddRef,
1950 ClassFactory_Release,
1951 MimeFilter_CreateInstance,
1952 ClassFactory_LockServer
1955 static IClassFactory mimefilter_cf = { &MimeFilterCFVtbl };
1957 #define TEST_BINDING 0x01
1958 #define TEST_FILTER 0x02
1959 #define TEST_FIRST_HTTP 0x04
1960 #define TEST_DIRECT_READ 0x08
1961 #define TEST_POST 0x10
1962 #define TEST_EMULATEPROT 0x20
1963 #define TEST_SHORT_READ 0x40
1964 #define TEST_REDIRECT 0x80
1966 static void init_test(int prot, DWORD flags)
1968 tested_protocol = prot;
1969 binding_test = (flags & TEST_BINDING) != 0;
1970 first_data_notif = TRUE;
1973 async_read_pending = TRUE;
1974 mimefilter_test = (flags & TEST_FILTER) != 0;
1976 ResetEvent(event_complete);
1977 ResetEvent(event_complete2);
1978 ResetEvent(event_continue);
1979 ResetEvent(event_continue_done);
1980 async_protocol = binding_protocol = filtered_protocol = NULL;
1981 filtered_sink = NULL;
1982 http_is_first = (flags & TEST_FIRST_HTTP) != 0;
1983 first_data_notif = TRUE;
1985 direct_read = (flags & TEST_DIRECT_READ) != 0;
1986 http_post_test = (flags & TEST_POST) != 0;
1987 emulate_prot = (flags & TEST_EMULATEPROT) != 0;
1988 wait_for_switch = TRUE;
1989 short_read = (flags & TEST_SHORT_READ) != 0;
1990 test_redirect = (flags & TEST_REDIRECT) != 0;
1993 static void test_priority(IInternetProtocol *protocol)
1995 IInternetPriority *priority;
1999 hres = IInternetProtocol_QueryInterface(protocol, &IID_IInternetPriority,
2001 ok(hres == S_OK, "QueryInterface(IID_IInternetPriority) failed: %08x\n", hres);
2005 hres = IInternetPriority_GetPriority(priority, &pr);
2006 ok(hres == S_OK, "GetPriority failed: %08x\n", hres);
2007 ok(pr == 0, "pr=%d, expected 0\n", pr);
2009 hres = IInternetPriority_SetPriority(priority, 1);
2010 ok(hres == S_OK, "SetPriority failed: %08x\n", hres);
2012 hres = IInternetPriority_GetPriority(priority, &pr);
2013 ok(hres == S_OK, "GetPriority failed: %08x\n", hres);
2014 ok(pr == 1, "pr=%d, expected 1\n", pr);
2016 IInternetPriority_Release(priority);
2019 static BOOL file_protocol_start(IInternetProtocol *protocol, LPCWSTR url, BOOL is_first)
2023 SET_EXPECT(GetBindInfo);
2024 if(!(bindf & BINDF_FROMURLMON))
2025 SET_EXPECT(ReportProgress_DIRECTBIND);
2027 SET_EXPECT(ReportProgress_SENDINGREQUEST);
2028 SET_EXPECT(ReportProgress_CACHEFILENAMEAVAILABLE);
2029 if(bindf & BINDF_FROMURLMON)
2030 SET_EXPECT(ReportProgress_VERIFIEDMIMETYPEAVAILABLE);
2032 SET_EXPECT(ReportProgress_MIMETYPEAVAILABLE);
2034 SET_EXPECT(ReportData);
2036 SET_EXPECT(ReportResult);
2038 expect_hrResult = S_OK;
2040 hres = IInternetProtocol_Start(protocol, url, &protocol_sink, &bind_info, 0, 0);
2041 if(hres == INET_E_RESOURCE_NOT_FOUND) {
2042 win_skip("Start failed\n");
2045 ok(hres == S_OK, "Start failed: %08x\n", hres);
2047 CHECK_CALLED(GetBindInfo);
2048 if(!(bindf & BINDF_FROMURLMON))
2049 CHECK_CALLED(ReportProgress_DIRECTBIND);
2051 CHECK_CALLED(ReportProgress_SENDINGREQUEST);
2052 CHECK_CALLED(ReportProgress_CACHEFILENAMEAVAILABLE);
2053 if(bindf & BINDF_FROMURLMON)
2054 CHECK_CALLED(ReportProgress_VERIFIEDMIMETYPEAVAILABLE);
2056 CHECK_CALLED(ReportProgress_MIMETYPEAVAILABLE);
2058 CHECK_CALLED(ReportData);
2060 CHECK_CALLED(ReportResult);
2065 static void test_file_protocol_url(LPCWSTR url)
2067 IInternetProtocolInfo *protocol_info;
2069 IClassFactory *factory;
2072 hres = CoGetClassObject(&CLSID_FileProtocol, CLSCTX_INPROC_SERVER, NULL,
2073 &IID_IUnknown, (void**)&unk);
2074 ok(hres == S_OK, "CoGetClassObject failed: %08x\n", hres);
2078 hres = IUnknown_QueryInterface(unk, &IID_IInternetProtocolInfo, (void**)&protocol_info);
2079 ok(hres == E_NOINTERFACE,
2080 "Could not get IInternetProtocolInfo interface: %08x, expected E_NOINTERFACE\n", hres);
2082 hres = IUnknown_QueryInterface(unk, &IID_IClassFactory, (void**)&factory);
2083 ok(hres == S_OK, "Could not get IClassFactory interface\n");
2084 if(SUCCEEDED(hres)) {
2085 IInternetProtocol *protocol;
2088 hres = IClassFactory_CreateInstance(factory, NULL, &IID_IInternetProtocol, (void**)&protocol);
2089 ok(hres == S_OK, "Could not get IInternetProtocol: %08x\n", hres);
2091 if(SUCCEEDED(hres)) {
2092 if(file_protocol_start(protocol, url, TRUE)) {
2093 hres = IInternetProtocol_Read(protocol, buf, 2, &cb);
2094 ok(hres == S_OK, "Read failed: %08x\n", hres);
2095 ok(cb == 2, "cb=%u expected 2\n", cb);
2096 hres = IInternetProtocol_Read(protocol, buf, sizeof(buf), &cb);
2097 ok(hres == S_FALSE, "Read failed: %08x\n", hres);
2098 hres = IInternetProtocol_Read(protocol, buf, sizeof(buf), &cb);
2099 ok(hres == S_FALSE, "Read failed: %08x expected S_FALSE\n", hres);
2100 ok(cb == 0, "cb=%u expected 0\n", cb);
2101 hres = IInternetProtocol_UnlockRequest(protocol);
2102 ok(hres == S_OK, "UnlockRequest failed: %08x\n", hres);
2105 if(file_protocol_start(protocol, url, FALSE)) {
2106 hres = IInternetProtocol_Read(protocol, buf, 2, &cb);
2107 ok(hres == S_FALSE, "Read failed: %08x\n", hres);
2108 hres = IInternetProtocol_LockRequest(protocol, 0);
2109 ok(hres == S_OK, "LockRequest failed: %08x\n", hres);
2110 hres = IInternetProtocol_UnlockRequest(protocol);
2111 ok(hres == S_OK, "UnlockRequest failed: %08x\n", hres);
2114 IInternetProtocol_Release(protocol);
2117 hres = IClassFactory_CreateInstance(factory, NULL, &IID_IInternetProtocol, (void**)&protocol);
2118 ok(hres == S_OK, "Could not get IInternetProtocol: %08x\n", hres);
2120 if(SUCCEEDED(hres)) {
2121 if(file_protocol_start(protocol, url, TRUE)) {
2122 hres = IInternetProtocol_LockRequest(protocol, 0);
2123 ok(hres == S_OK, "LockRequest failed: %08x\n", hres);
2124 hres = IInternetProtocol_Terminate(protocol, 0);
2125 ok(hres == S_OK, "Terminate failed: %08x\n", hres);
2126 hres = IInternetProtocol_Read(protocol, buf, 2, &cb);
2127 ok(hres == S_OK, "Read failed: %08x\n\n", hres);
2128 hres = IInternetProtocol_UnlockRequest(protocol);
2129 ok(hres == S_OK, "UnlockRequest failed: %08x\n", hres);
2130 hres = IInternetProtocol_Read(protocol, buf, 2, &cb);
2131 ok(hres == S_OK, "Read failed: %08x\n", hres);
2132 hres = IInternetProtocol_Terminate(protocol, 0);
2133 ok(hres == S_OK, "Terminate failed: %08x\n", hres);
2136 IInternetProtocol_Release(protocol);
2139 hres = IClassFactory_CreateInstance(factory, NULL, &IID_IInternetProtocol, (void**)&protocol);
2140 ok(hres == S_OK, "Could not get IInternetProtocol: %08x\n", hres);
2142 if(SUCCEEDED(hres)) {
2143 if(file_protocol_start(protocol, url, TRUE)) {
2144 hres = IInternetProtocol_Terminate(protocol, 0);
2145 ok(hres == S_OK, "Terminate failed: %08x\n", hres);
2146 hres = IInternetProtocol_Read(protocol, buf, 2, &cb);
2147 ok(hres == S_OK, "Read failed: %08x\n", hres);
2148 ok(cb == 2, "cb=%u expected 2\n", cb);
2151 IInternetProtocol_Release(protocol);
2154 IClassFactory_Release(factory);
2157 IUnknown_Release(unk);
2160 static void test_file_protocol_fail(void)
2162 IInternetProtocol *protocol;
2165 static const WCHAR index_url2[] =
2166 {'f','i','l','e',':','/','/','i','n','d','e','x','.','h','t','m','l',0};
2168 hres = CoCreateInstance(&CLSID_FileProtocol, NULL, CLSCTX_INPROC_SERVER|CLSCTX_INPROC_HANDLER,
2169 &IID_IInternetProtocol, (void**)&protocol);
2170 ok(hres == S_OK, "CoCreateInstance failed: %08x\n", hres);
2174 SET_EXPECT(GetBindInfo);
2175 expect_hrResult = MK_E_SYNTAX;
2176 hres = IInternetProtocol_Start(protocol, wszIndexHtml, &protocol_sink, &bind_info, 0, 0);
2177 ok(hres == MK_E_SYNTAX ||
2178 hres == E_INVALIDARG,
2179 "Start failed: %08x, expected MK_E_SYNTAX or E_INVALIDARG\n", hres);
2180 CLEAR_CALLED(GetBindInfo); /* GetBindInfo not called in IE7 */
2182 SET_EXPECT(GetBindInfo);
2183 if(!(bindf & BINDF_FROMURLMON))
2184 SET_EXPECT(ReportProgress_DIRECTBIND);
2185 SET_EXPECT(ReportProgress_SENDINGREQUEST);
2186 SET_EXPECT(ReportResult);
2187 expect_hrResult = INET_E_RESOURCE_NOT_FOUND;
2188 hres = IInternetProtocol_Start(protocol, index_url, &protocol_sink, &bind_info, 0, 0);
2189 ok(hres == INET_E_RESOURCE_NOT_FOUND,
2190 "Start failed: %08x expected INET_E_RESOURCE_NOT_FOUND\n", hres);
2191 CHECK_CALLED(GetBindInfo);
2192 if(!(bindf & BINDF_FROMURLMON))
2193 CHECK_CALLED(ReportProgress_DIRECTBIND);
2194 CHECK_CALLED(ReportProgress_SENDINGREQUEST);
2195 CHECK_CALLED(ReportResult);
2197 IInternetProtocol_Release(protocol);
2199 hres = CoCreateInstance(&CLSID_FileProtocol, NULL, CLSCTX_INPROC_SERVER|CLSCTX_INPROC_HANDLER,
2200 &IID_IInternetProtocol, (void**)&protocol);
2201 ok(hres == S_OK, "CoCreateInstance failed: %08x\n", hres);
2205 SET_EXPECT(GetBindInfo);
2206 if(!(bindf & BINDF_FROMURLMON))
2207 SET_EXPECT(ReportProgress_DIRECTBIND);
2208 SET_EXPECT(ReportProgress_SENDINGREQUEST);
2209 SET_EXPECT(ReportResult);
2210 expect_hrResult = INET_E_RESOURCE_NOT_FOUND;
2212 hres = IInternetProtocol_Start(protocol, index_url2, &protocol_sink, &bind_info, 0, 0);
2213 ok(hres == INET_E_RESOURCE_NOT_FOUND,
2214 "Start failed: %08x, expected INET_E_RESOURCE_NOT_FOUND\n", hres);
2215 CHECK_CALLED(GetBindInfo);
2216 if(!(bindf & BINDF_FROMURLMON))
2217 CHECK_CALLED(ReportProgress_DIRECTBIND);
2218 CHECK_CALLED(ReportProgress_SENDINGREQUEST);
2219 CHECK_CALLED(ReportResult);
2221 SET_EXPECT(GetBindInfo);
2222 hres = IInternetProtocol_Start(protocol, NULL, &protocol_sink, &bind_info, 0, 0);
2223 ok(hres == E_INVALIDARG, "Start failed: %08x, expected E_INVALIDARG\n", hres);
2224 CLEAR_CALLED(GetBindInfo); /* GetBindInfo not called in IE7 */
2226 SET_EXPECT(GetBindInfo);
2227 hres = IInternetProtocol_Start(protocol, emptyW, &protocol_sink, &bind_info, 0, 0);
2228 ok(hres == E_INVALIDARG, "Start failed: %08x, expected E_INVALIDARG\n", hres);
2229 CLEAR_CALLED(GetBindInfo); /* GetBindInfo not called in IE7 */
2231 IInternetProtocol_Release(protocol);
2234 static void test_file_protocol(void) {
2235 WCHAR buf[INTERNET_MAX_URL_LENGTH], file_name_buf[MAX_PATH];
2240 static const WCHAR wszFile[] = {'f','i','l','e',':',0};
2241 static const WCHAR wszFile2[] = {'f','i','l','e',':','/','/',0};
2242 static const WCHAR wszFile3[] = {'f','i','l','e',':','/','/','/',0};
2243 static const char html_doc[] = "<HTML></HTML>";
2245 trace("Testing file protocol...\n");
2246 init_test(FILE_TEST, 0);
2248 SetLastError(0xdeadbeef);
2249 file = CreateFileW(wszIndexHtml, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS,
2250 FILE_ATTRIBUTE_NORMAL, NULL);
2251 if(!file && GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)
2253 win_skip("Detected Win9x or WinMe\n");
2256 ok(file != INVALID_HANDLE_VALUE, "CreateFile failed\n");
2257 if(file == INVALID_HANDLE_VALUE)
2259 WriteFile(file, html_doc, sizeof(html_doc)-1, &size, NULL);
2262 file_name = wszIndexHtml;
2264 test_file_protocol_url(index_url);
2265 bindf = BINDF_FROMURLMON;
2266 test_file_protocol_url(index_url);
2267 bindf = BINDF_FROMURLMON | BINDF_NEEDFILE;
2268 test_file_protocol_url(index_url);
2270 memcpy(buf, wszFile, sizeof(wszFile));
2271 len = sizeof(wszFile)/sizeof(WCHAR)-1;
2272 len += GetCurrentDirectoryW(sizeof(buf)/sizeof(WCHAR)-len, buf+len);
2274 memcpy(buf+len, wszIndexHtml, sizeof(wszIndexHtml));
2276 file_name = buf + sizeof(wszFile)/sizeof(WCHAR)-1;
2278 test_file_protocol_url(buf);
2279 bindf = BINDF_FROMURLMON;
2280 test_file_protocol_url(buf);
2282 memcpy(buf, wszFile2, sizeof(wszFile2));
2283 len = GetCurrentDirectoryW(sizeof(file_name_buf)/sizeof(WCHAR), file_name_buf);
2284 file_name_buf[len++] = '\\';
2285 memcpy(file_name_buf+len, wszIndexHtml, sizeof(wszIndexHtml));
2286 lstrcpyW(buf+sizeof(wszFile2)/sizeof(WCHAR)-1, file_name_buf);
2287 file_name = file_name_buf;
2289 test_file_protocol_url(buf);
2290 bindf = BINDF_FROMURLMON;
2291 test_file_protocol_url(buf);
2293 buf[sizeof(wszFile2)/sizeof(WCHAR)] = '|';
2294 test_file_protocol_url(buf);
2296 memcpy(buf, wszFile3, sizeof(wszFile3));
2297 len = sizeof(wszFile3)/sizeof(WCHAR)-1;
2298 len += GetCurrentDirectoryW(sizeof(buf)/sizeof(WCHAR)-len, buf+len);
2300 memcpy(buf+len, wszIndexHtml, sizeof(wszIndexHtml));
2302 file_name = buf + sizeof(wszFile3)/sizeof(WCHAR)-1;
2304 test_file_protocol_url(buf);
2305 bindf = BINDF_FROMURLMON;
2306 test_file_protocol_url(buf);
2308 DeleteFileW(wszIndexHtml);
2311 test_file_protocol_fail();
2312 bindf = BINDF_FROMURLMON;
2313 test_file_protocol_fail();
2316 static BOOL http_protocol_start(LPCWSTR url)
2318 static BOOL got_user_agent = FALSE;
2321 SET_EXPECT(GetBindInfo);
2322 if (!(bindf & BINDF_FROMURLMON))
2323 SET_EXPECT(ReportProgress_DIRECTBIND);
2325 SET_EXPECT(GetBindString_USER_AGENT);
2326 SET_EXPECT(GetBindString_ACCEPT_MIMES);
2327 SET_EXPECT(QueryService_HttpNegotiate);
2328 SET_EXPECT(BeginningTransaction);
2329 SET_EXPECT(GetRootSecurityId);
2331 SET_EXPECT(GetBindString_POST_COOKIE);
2333 hres = IInternetProtocol_Start(async_protocol, url, &protocol_sink, &bind_info, 0, 0);
2334 ok(hres == S_OK, "Start failed: %08x\n", hres);
2338 CHECK_CALLED(GetBindInfo);
2339 if (!(bindf & BINDF_FROMURLMON))
2340 CHECK_CALLED(ReportProgress_DIRECTBIND);
2341 if (!got_user_agent)
2343 CHECK_CALLED(GetBindString_USER_AGENT);
2344 got_user_agent = TRUE;
2346 CHECK_CALLED(GetBindString_ACCEPT_MIMES);
2347 CHECK_CALLED(QueryService_HttpNegotiate);
2348 CHECK_CALLED(BeginningTransaction);
2349 /* GetRootSecurityId called on WinXP but not on Win98 */
2350 CLEAR_CALLED(GetRootSecurityId);
2352 CHECK_CALLED(GetBindString_POST_COOKIE);
2357 static void test_protocol_terminate(IInternetProtocol *protocol)
2363 hres = IInternetProtocol_LockRequest(protocol, 0);
2364 ok(hres == S_OK, "LockRequest failed: %08x\n", hres);
2366 hres = IInternetProtocol_Read(protocol, buf, 1, &cb);
2367 ok(hres == S_FALSE, "Read failed: %08x\n", hres);
2369 hres = IInternetProtocol_Terminate(protocol, 0);
2370 ok(hres == S_OK, "Terminate failed: %08x\n", hres);
2372 /* This wait is to give the internet handles being freed in Terminate
2373 * enough time to actually terminate in all cases. Internet handles
2374 * terminate asynchronously and native reuses the main InternetOpen
2375 * handle. The only case in which this seems to be necessary is on
2376 * wine with native wininet and urlmon, resulting in the next time
2377 * test_http_protocol_url being called the first data notification actually
2378 * being an extra last data notification from the previous connection
2379 * about once out of every ten times. */
2382 hres = IInternetProtocol_UnlockRequest(protocol);
2383 ok(hres == S_OK, "UnlockRequest failed: %08x\n", hres);
2386 static void test_http_info(IInternetProtocol *protocol)
2388 IWinInetHttpInfo *info;
2391 hres = IInternetProtocol_QueryInterface(protocol, &IID_IWinInetHttpInfo, (void**)&info);
2392 ok(hres == S_OK, "Could not get IWinInterHttpInfo iface: %08x\n", hres);
2396 IWinInetHttpInfo_Release(info);
2399 /* is_first refers to whether this is the first call to this function
2401 static void test_http_protocol_url(LPCWSTR url, int prot, DWORD flags)
2403 IInternetProtocolInfo *protocol_info;
2404 IClassFactory *factory;
2408 init_test(prot, flags);
2411 hres = CoGetClassObject(prot == HTTPS_TEST ? &CLSID_HttpSProtocol : &CLSID_HttpProtocol,
2412 CLSCTX_INPROC_SERVER, NULL, &IID_IUnknown, (void**)&unk);
2413 ok(hres == S_OK, "CoGetClassObject failed: %08x\n", hres);
2417 hres = IUnknown_QueryInterface(unk, &IID_IInternetProtocolInfo, (void**)&protocol_info);
2418 ok(hres == E_NOINTERFACE,
2419 "Could not get IInternetProtocolInfo interface: %08x, expected E_NOINTERFACE\n",
2422 hres = IUnknown_QueryInterface(unk, &IID_IClassFactory, (void**)&factory);
2423 ok(hres == S_OK, "Could not get IClassFactory interface\n");
2424 IUnknown_Release(unk);
2428 hres = IClassFactory_CreateInstance(factory, NULL, &IID_IInternetProtocol,
2429 (void**)&async_protocol);
2430 ok(hres == S_OK, "Could not get IInternetProtocol: %08x\n", hres);
2431 if(SUCCEEDED(hres)) {
2436 test_priority(async_protocol);
2437 test_http_info(async_protocol);
2439 SET_EXPECT(ReportProgress_COOKIE_SENT);
2440 SET_EXPECT(ReportProgress_FINDINGRESOURCE);
2441 SET_EXPECT(ReportProgress_CONNECTING);
2442 SET_EXPECT(ReportProgress_SENDINGREQUEST);
2444 SET_EXPECT(ReportProgress_REDIRECTING);
2445 SET_EXPECT(ReportProgress_PROXYDETECTING);
2446 if(prot == HTTP_TEST)
2447 SET_EXPECT(ReportProgress_CACHEFILENAMEAVAILABLE);
2449 SET_EXPECT(QueryService_HttpSecurity);
2450 if(!(bindf & BINDF_FROMURLMON)) {
2451 SET_EXPECT(OnResponse);
2452 SET_EXPECT(ReportProgress_RAWMIMETYPE);
2453 SET_EXPECT(ReportData);
2458 if(!http_protocol_start(url))
2462 SET_EXPECT(ReportResult);
2463 expect_hrResult = S_OK;
2466 while(wait_for_switch) {
2468 WaitForSingleObject(event_continue, INFINITE);
2469 CHECK_CALLED(Switch);
2470 call_continue(&continue_protdata);
2471 SetEvent(event_continue_done);
2474 hres = IInternetProtocol_Read(async_protocol, buf, 1, &cb);
2475 ok((hres == E_PENDING && cb==0) ||
2476 (hres == S_OK && cb==1), "Read failed: %08x (%d bytes)\n", hres, cb);
2478 WaitForSingleObject(event_complete, INFINITE);
2479 if(bindf & BINDF_FROMURLMON)
2480 CHECK_CALLED(Switch);
2482 CHECK_CALLED(ReportData);
2483 if(prot == HTTPS_TEST)
2484 CLEAR_CALLED(QueryService_HttpSecurity);
2487 if(bindf & BINDF_FROMURLMON)
2490 SET_EXPECT(ReportData);
2491 hres = IInternetProtocol_Read(async_protocol, buf, sizeof(buf), &cb);
2492 if(hres == E_PENDING) {
2493 hres = IInternetProtocol_Read(async_protocol, buf, 1, &cb);
2494 ok((hres == E_PENDING && cb==0) ||
2495 (hres == S_OK && cb==1), "Read failed: %08x (%d bytes)\n", hres, cb);
2496 WaitForSingleObject(event_complete, INFINITE);
2497 if(bindf & BINDF_FROMURLMON)
2498 CHECK_CALLED(Switch);
2500 CHECK_CALLED(ReportData);
2502 if(bindf & BINDF_FROMURLMON)
2503 CHECK_NOT_CALLED(Switch);
2505 CHECK_NOT_CALLED(ReportData);
2509 ok(hres == S_FALSE, "Read failed: %08x\n", hres);
2510 CHECK_CALLED(ReportResult);
2512 if(prot == HTTPS_TEST)
2513 CLEAR_CALLED(ReportProgress_SENDINGREQUEST);
2515 test_protocol_terminate(async_protocol);
2516 ref = IInternetProtocol_Release(async_protocol);
2517 ok(!ref, "ref=%x\n", hres);
2520 IClassFactory_Release(factory);
2523 static void test_http_protocol(void)
2525 static const WCHAR winehq_url[] =
2526 {'h','t','t','p',':','/','/','w','w','w','.','w','i','n','e','h','q','.',
2527 'o','r','g','/','s','i','t','e','/','a','b','o','u','t',0};
2528 static const WCHAR posttest_url[] =
2529 {'h','t','t','p',':','/','/','c','r','o','s','s','o','v','e','r','.',
2530 'c','o','d','e','w','e','a','v','e','r','s','.','c','o','m','/',
2531 'p','o','s','t','t','e','s','t','.','p','h','p',0};
2532 static const WCHAR redirect_url[] =
2533 {'h','t','t','p',':','/','/','t','e','s','t','.','w','i','n','e','h','q','.','o','r','g','/',
2534 't','e','s','t','r','e','d','i','r','e','c','t',0};
2536 trace("Testing http protocol (not from urlmon)...\n");
2537 bindf = BINDF_ASYNCHRONOUS | BINDF_ASYNCSTORAGE | BINDF_PULLDATA;
2538 test_http_protocol_url(winehq_url, HTTP_TEST, TEST_FIRST_HTTP);
2540 trace("Testing http protocol (from urlmon)...\n");
2541 bindf = BINDF_ASYNCHRONOUS | BINDF_ASYNCSTORAGE | BINDF_PULLDATA | BINDF_FROMURLMON;
2542 test_http_protocol_url(winehq_url, HTTP_TEST, 0);
2544 trace("Testing http protocol (to file)...\n");
2545 bindf = BINDF_ASYNCHRONOUS | BINDF_ASYNCSTORAGE | BINDF_PULLDATA | BINDF_FROMURLMON | BINDF_NEEDFILE;
2546 test_http_protocol_url(winehq_url, HTTP_TEST, 0);
2548 trace("Testing http protocol (post data)...\n");
2549 /* Without this flag we get a ReportProgress_CACHEFILENAMEAVAILABLE
2550 * notification with BINDVERB_POST */
2551 bindf = BINDF_ASYNCHRONOUS | BINDF_ASYNCSTORAGE | BINDF_PULLDATA | BINDF_FROMURLMON | BINDF_NOWRITECACHE;
2552 test_http_protocol_url(posttest_url, HTTP_TEST, TEST_FIRST_HTTP|TEST_POST);
2554 trace("Testing http protocol (direct read)...\n");
2555 bindf = BINDF_ASYNCHRONOUS | BINDF_ASYNCSTORAGE | BINDF_PULLDATA | BINDF_FROMURLMON;
2556 test_http_protocol_url(winehq_url, HTTP_TEST, TEST_DIRECT_READ);
2558 trace("Testing http protocol (redirected)...\n");
2559 bindf = BINDF_ASYNCHRONOUS | BINDF_ASYNCSTORAGE | BINDF_PULLDATA | BINDF_FROMURLMON;
2560 test_http_protocol_url(redirect_url, HTTP_TEST, TEST_REDIRECT);
2563 static void test_https_protocol(void)
2565 static const WCHAR codeweavers_url[] =
2566 {'h','t','t','p','s',':','/','/','w','w','w','.','c','o','d','e','w','e','a','v','e','r','s',
2567 '.','c','o','m','/','t','e','s','t','.','h','t','m','l',0};
2569 trace("Testing https protocol (from urlmon)...\n");
2570 bindf = BINDF_ASYNCHRONOUS | BINDF_ASYNCSTORAGE | BINDF_PULLDATA | BINDF_FROMURLMON | BINDF_NOWRITECACHE;
2571 test_http_protocol_url(codeweavers_url, HTTPS_TEST, TEST_FIRST_HTTP);
2575 static void test_ftp_protocol(void)
2577 IInternetProtocolInfo *protocol_info;
2578 IClassFactory *factory;
2585 static const WCHAR ftp_urlW[] = {'f','t','p',':','/','/','f','t','p','.','w','i','n','e','h','q','.','o','r','g',
2586 '/','p','u','b','/','o','t','h','e','r','/',
2587 'w','i','n','e','l','o','g','o','.','x','c','f','.','t','a','r','.','b','z','2',0};
2589 trace("Testing ftp protocol...\n");
2591 bindf = BINDF_ASYNCHRONOUS | BINDF_ASYNCSTORAGE | BINDF_PULLDATA | BINDF_FROMURLMON | BINDF_NOWRITECACHE;
2593 tested_protocol = FTP_TEST;
2594 first_data_notif = TRUE;
2595 expect_hrResult = E_PENDING;
2597 hres = CoGetClassObject(&CLSID_FtpProtocol, CLSCTX_INPROC_SERVER, NULL, &IID_IUnknown, (void**)&unk);
2598 ok(hres == S_OK, "CoGetClassObject failed: %08x\n", hres);
2602 hres = IUnknown_QueryInterface(unk, &IID_IInternetProtocolInfo, (void**)&protocol_info);
2603 ok(hres == E_NOINTERFACE, "Could not get IInternetProtocolInfo interface: %08x, expected E_NOINTERFACE\n", hres);
2605 hres = IUnknown_QueryInterface(unk, &IID_IClassFactory, (void**)&factory);
2606 ok(hres == S_OK, "Could not get IClassFactory interface\n");
2607 IUnknown_Release(unk);
2611 hres = IClassFactory_CreateInstance(factory, NULL, &IID_IInternetProtocol,
2612 (void**)&async_protocol);
2613 IClassFactory_Release(factory);
2614 ok(hres == S_OK, "Could not get IInternetProtocol: %08x\n", hres);
2616 test_priority(async_protocol);
2617 test_http_info(async_protocol);
2619 SET_EXPECT(GetBindInfo);
2620 SET_EXPECT(ReportProgress_FINDINGRESOURCE);
2621 SET_EXPECT(ReportProgress_CONNECTING);
2622 SET_EXPECT(ReportProgress_SENDINGREQUEST);
2625 hres = IInternetProtocol_Start(async_protocol, ftp_urlW, &protocol_sink, &bind_info, 0, 0);
2626 ok(hres == S_OK, "Start failed: %08x\n", hres);
2627 CHECK_CALLED(GetBindInfo);
2629 SET_EXPECT(ReportResult);
2631 hres = IInternetProtocol_Read(async_protocol, buf, 1, &cb);
2632 ok((hres == E_PENDING && cb==0) ||
2633 (hres == S_OK && cb==1), "Read failed: %08x (%d bytes)\n", hres, cb);
2635 WaitForSingleObject(event_complete, INFINITE);
2639 hres = IInternetProtocol_Read(async_protocol, buf, sizeof(buf), &cb);
2640 if(hres == E_PENDING)
2641 WaitForSingleObject(event_complete, INFINITE);
2646 ok(hres == S_FALSE, "Read failed: %08x\n", hres);
2647 CHECK_CALLED(ReportResult);
2648 CHECK_CALLED(Switch);
2650 test_protocol_terminate(async_protocol);
2652 ref = IInternetProtocol_Release(async_protocol);
2653 ok(!ref, "ref=%d\n", ref);
2656 static void test_gopher_protocol(void)
2658 IInternetProtocolInfo *protocol_info;
2659 IClassFactory *factory;
2663 trace("Testing gopher protocol...\n");
2665 hres = CoGetClassObject(&CLSID_GopherProtocol, CLSCTX_INPROC_SERVER, NULL, &IID_IUnknown, (void**)&unk);
2667 hres == REGDB_E_CLASSNOTREG, /* Gopher protocol has been removed as of Vista */
2668 "CoGetClassObject failed: %08x\n", hres);
2672 hres = IUnknown_QueryInterface(unk, &IID_IInternetProtocolInfo, (void**)&protocol_info);
2673 ok(hres == E_NOINTERFACE, "Could not get IInternetProtocolInfo interface: %08x, expected E_NOINTERFACE\n", hres);
2675 hres = IUnknown_QueryInterface(unk, &IID_IClassFactory, (void**)&factory);
2676 ok(hres == S_OK, "Could not get IClassFactory interface\n");
2677 IUnknown_Release(unk);
2681 hres = IClassFactory_CreateInstance(factory, NULL, &IID_IInternetProtocol,
2682 (void**)&async_protocol);
2683 IClassFactory_Release(factory);
2684 ok(hres == S_OK, "Could not get IInternetProtocol: %08x\n", hres);
2686 test_priority(async_protocol);
2688 IInternetProtocol_Release(async_protocol);
2691 static void test_mk_protocol(void)
2693 IInternetProtocolInfo *protocol_info;
2694 IInternetProtocol *protocol;
2695 IClassFactory *factory;
2699 static const WCHAR wrong_url1[] = {'t','e','s','t',':','@','M','S','I','T','S','t','o','r','e',
2700 ':',':','/','t','e','s','t','.','h','t','m','l',0};
2701 static const WCHAR wrong_url2[] = {'m','k',':','/','t','e','s','t','.','h','t','m','l',0};
2703 trace("Testing mk protocol...\n");
2704 init_test(MK_TEST, 0);
2706 hres = CoGetClassObject(&CLSID_MkProtocol, CLSCTX_INPROC_SERVER, NULL,
2707 &IID_IUnknown, (void**)&unk);
2708 ok(hres == S_OK, "CoGetClassObject failed: %08x\n", hres);
2710 hres = IUnknown_QueryInterface(unk, &IID_IInternetProtocolInfo, (void**)&protocol_info);
2711 ok(hres == E_NOINTERFACE,
2712 "Could not get IInternetProtocolInfo interface: %08x, expected E_NOINTERFACE\n",
2715 hres = IUnknown_QueryInterface(unk, &IID_IClassFactory, (void**)&factory);
2716 ok(hres == S_OK, "Could not get IClassFactory interface\n");
2717 IUnknown_Release(unk);
2721 hres = IClassFactory_CreateInstance(factory, NULL, &IID_IInternetProtocol,
2723 IClassFactory_Release(factory);
2724 ok(hres == S_OK, "Could not get IInternetProtocol: %08x\n", hres);
2726 SET_EXPECT(GetBindInfo);
2727 hres = IInternetProtocol_Start(protocol, wrong_url1, &protocol_sink, &bind_info, 0, 0);
2728 ok(hres == MK_E_SYNTAX || hres == INET_E_INVALID_URL,
2729 "Start failed: %08x, expected MK_E_SYNTAX or INET_E_INVALID_URL\n", hres);
2730 CLEAR_CALLED(GetBindInfo);
2732 SET_EXPECT(GetBindInfo);
2733 SET_EXPECT(ReportProgress_DIRECTBIND);
2734 SET_EXPECT(ReportProgress_SENDINGREQUEST);
2735 SET_EXPECT(ReportProgress_MIMETYPEAVAILABLE);
2736 SET_EXPECT(ReportResult);
2737 expect_hrResult = INET_E_RESOURCE_NOT_FOUND;
2739 hres = IInternetProtocol_Start(protocol, wrong_url2, &protocol_sink, &bind_info, 0, 0);
2740 ok(hres == INET_E_RESOURCE_NOT_FOUND ||
2741 hres == INET_E_INVALID_URL, /* win2k3 */
2742 "Start failed: %08x, expected INET_E_RESOURCE_NOT_FOUND or INET_E_INVALID_URL\n", hres);
2744 if (hres == INET_E_RESOURCE_NOT_FOUND) {
2745 CHECK_CALLED(GetBindInfo);
2746 CLEAR_CALLED(ReportProgress_DIRECTBIND);
2747 CHECK_CALLED(ReportProgress_SENDINGREQUEST);
2748 CHECK_CALLED(ReportProgress_MIMETYPEAVAILABLE);
2749 CHECK_CALLED(ReportResult);
2751 CLEAR_CALLED(GetBindInfo);
2752 CLEAR_CALLED(ReportProgress_DIRECTBIND);
2753 CLEAR_CALLED(ReportProgress_SENDINGREQUEST);
2754 CLEAR_CALLED(ReportProgress_MIMETYPEAVAILABLE);
2755 CLEAR_CALLED(ReportResult);
2758 IInternetProtocol_Release(protocol);
2761 static void test_CreateBinding(void)
2763 IInternetProtocol *protocol;
2764 IInternetPriority *priority;
2765 IInternetSession *session;
2766 IWinInetHttpInfo *http_info;
2767 IWinInetInfo *inet_info;
2773 static const WCHAR test_url[] =
2774 {'t','e','s','t',':','/','/','f','i','l','e','.','h','t','m','l',0};
2775 static const WCHAR wsz_test[] = {'t','e','s','t',0};
2777 trace("Testing CreateBinding...\n");
2778 init_test(BIND_TEST, TEST_BINDING);
2780 hres = CoInternetGetSession(0, &session, 0);
2781 ok(hres == S_OK, "CoInternetGetSession failed: %08x\n", hres);
2783 hres = IInternetSession_RegisterNameSpace(session, &ClassFactory, &IID_NULL, wsz_test, 0, NULL, 0);
2784 ok(hres == S_OK, "RegisterNameSpace failed: %08x\n", hres);
2786 hres = IInternetSession_CreateBinding(session, NULL, test_url, NULL, NULL, &protocol, 0);
2787 binding_protocol = protocol;
2788 ok(hres == S_OK, "CreateBinding failed: %08x\n", hres);
2789 ok(protocol != NULL, "protocol == NULL\n");
2791 hres = IInternetProtocol_QueryInterface(protocol, &IID_IInternetBindInfo, (void**)&prot_bind_info);
2792 ok(hres == S_OK, "QueryInterface(IID_IInternetBindInfo) failed: %08x\n", hres);
2794 hres = IInternetProtocol_QueryInterface(protocol, &IID_IInternetProtocolSink, (void**)&binding_sink);
2795 ok(hres == S_OK, "Could not get IInternetProtocolSink: %08x\n", hres);
2797 hres = IInternetProtocol_Start(protocol, test_url, NULL, &bind_info, 0, 0);
2798 ok(hres == E_INVALIDARG, "Start failed: %08x, expected E_INVALIDARG\n", hres);
2799 hres = IInternetProtocol_Start(protocol, test_url, &protocol_sink, NULL, 0, 0);
2800 ok(hres == E_INVALIDARG, "Start failed: %08x, expected E_INVALIDARG\n", hres);
2801 hres = IInternetProtocol_Start(protocol, NULL, &protocol_sink, &bind_info, 0, 0);
2802 ok(hres == E_INVALIDARG, "Start failed: %08x, expected E_INVALIDARG\n", hres);
2804 hres = IInternetProtocol_QueryInterface(protocol, &IID_IInternetPriority, (void**)&priority);
2805 ok(hres == S_OK, "QueryInterface(IID_IInternetPriority) failed: %08x\n", hres);
2808 hres = IInternetPriority_GetPriority(priority, &p);
2809 ok(hres == S_OK, "GetPriority failed: %08x\n", hres);
2810 ok(!p, "p=%d\n", p);
2813 hres = IInternetPriority_SetPriority(priority, 100);
2814 ok(hres == S_OK, "SetPriority failed: %08x\n", hres);
2817 hres = IInternetPriority_GetPriority(priority, &p);
2818 ok(hres == S_OK, "GetPriority failed: %08x\n", hres);
2819 ok(p == 100, "p=%d\n", p);
2821 hres = IInternetProtocol_QueryInterface(protocol, &IID_IWinInetInfo, (void**)&inet_info);
2822 ok(hres == E_NOINTERFACE, "Could not get IWinInetInfo protocol: %08x\n", hres);
2824 SET_EXPECT(QueryService_InternetProtocol);
2825 SET_EXPECT(CreateInstance);
2826 SET_EXPECT(ReportProgress_PROTOCOLCLASSID);
2827 SET_EXPECT(SetPriority);
2830 expect_hrResult = S_OK;
2831 hres = IInternetProtocol_Start(protocol, test_url, &protocol_sink, &bind_info, 0, 0);
2832 ok(hres == S_OK, "Start failed: %08x\n", hres);
2834 CHECK_CALLED(QueryService_InternetProtocol);
2835 CHECK_CALLED(CreateInstance);
2836 CHECK_CALLED(ReportProgress_PROTOCOLCLASSID);
2837 CHECK_CALLED(SetPriority);
2838 CHECK_CALLED(Start);
2840 SET_EXPECT(QueryInterface_IWinInetInfo);
2841 hres = IInternetProtocol_QueryInterface(protocol, &IID_IWinInetInfo, (void**)&inet_info);
2842 ok(hres == E_NOINTERFACE, "Could not get IWinInetInfo protocol: %08x\n", hres);
2843 CHECK_CALLED(QueryInterface_IWinInetInfo);
2845 SET_EXPECT(QueryInterface_IWinInetInfo);
2846 hres = IInternetProtocol_QueryInterface(protocol, &IID_IWinInetInfo, (void**)&inet_info);
2847 ok(hres == E_NOINTERFACE, "Could not get IWinInetInfo protocol: %08x\n", hres);
2848 CHECK_CALLED(QueryInterface_IWinInetInfo);
2850 SET_EXPECT(QueryInterface_IWinInetHttpInfo);
2851 hres = IInternetProtocol_QueryInterface(protocol, &IID_IWinInetHttpInfo, (void**)&http_info);
2852 ok(hres == E_NOINTERFACE, "Could not get IWinInetInfo protocol: %08x\n", hres);
2853 CHECK_CALLED(QueryInterface_IWinInetHttpInfo);
2857 hres = IInternetProtocol_Read(protocol, expect_pv = buf, sizeof(buf), &read);
2858 ok(hres == S_OK, "Read failed: %08x\n", hres);
2859 ok(read == 100, "read = %d\n", read);
2864 hres = IInternetProtocol_Read(protocol, expect_pv = buf, sizeof(buf), &read);
2865 ok(hres == S_FALSE, "Read failed: %08x\n", hres);
2866 ok(!read, "read = %d\n", read);
2870 hres = IInternetPriority_GetPriority(priority, &p);
2871 ok(hres == S_OK, "GetPriority failed: %08x\n", hres);
2872 ok(p == 100, "p=%d\n", p);
2874 hres = IInternetPriority_SetPriority(priority, 101);
2875 ok(hres == S_OK, "SetPriority failed: %08x\n", hres);
2877 SET_EXPECT(Terminate);
2878 hres = IInternetProtocol_Terminate(protocol, 0xdeadbeef);
2879 ok(hres == S_OK, "Terminate failed: %08x\n", hres);
2880 CHECK_CALLED(Terminate);
2882 SET_EXPECT(Continue);
2883 hres = IInternetProtocolSink_Switch(binding_sink, &protocoldata);
2884 ok(hres == S_OK, "Switch failed: %08x\n", hres);
2885 CHECK_CALLED(Continue);
2887 hres = IInternetProtocolSink_ReportProgress(binding_sink,
2888 BINDSTATUS_CACHEFILENAMEAVAILABLE, expect_wsz = emptyW);
2889 ok(hres == S_OK, "ReportProgress(BINDSTATUS_CACHEFILENAMEAVAILABLE) failed: %08x\n", hres);
2891 hres = IInternetProtocolSink_ReportResult(binding_sink, S_OK, ERROR_SUCCESS, NULL);
2892 ok(hres == E_FAIL, "ReportResult failed: %08x, expected E_FAIL\n", hres);
2894 hres = IInternetProtocolSink_ReportData(binding_sink, 0, 0, 0);
2895 ok(hres == S_OK, "ReportData failed: %08x\n", hres);
2897 IInternetProtocolSink_Release(binding_sink);
2898 IInternetPriority_Release(priority);
2899 IInternetBindInfo_Release(prot_bind_info);
2900 IInternetProtocol_Release(protocol);
2902 hres = IInternetSession_UnregisterNameSpace(session, &ClassFactory, wsz_test);
2903 ok(hres == S_OK, "UnregisterNameSpace failed: %08x\n", hres);
2905 IInternetSession_Release(session);
2908 static void test_binding(int prot, DWORD grf_pi, DWORD test_flags)
2910 IInternetProtocol *protocol;
2911 IInternetSession *session;
2917 init_test(prot, test_flags|TEST_BINDING);
2919 hres = CoInternetGetSession(0, &session, 0);
2920 ok(hres == S_OK, "CoInternetGetSession failed: %08x\n", hres);
2922 if(test_flags & TEST_EMULATEPROT) {
2923 hres = IInternetSession_RegisterNameSpace(session, &ClassFactory, &IID_NULL, protocol_names[prot], 0, NULL, 0);
2924 ok(hres == S_OK, "RegisterNameSpace failed: %08x\n", hres);
2927 hres = IInternetSession_CreateBinding(session, NULL, binding_urls[prot], NULL, NULL, &protocol, 0);
2928 binding_protocol = protocol;
2929 ok(hres == S_OK, "CreateBinding failed: %08x\n", hres);
2930 ok(protocol != NULL, "protocol == NULL\n");
2932 hres = IInternetProtocol_QueryInterface(protocol, &IID_IInternetBindInfo, (void**)&prot_bind_info);
2933 ok(hres == S_OK, "QueryInterface(IID_IInternetBindInfo) failed: %08x\n", hres);
2935 hres = IInternetProtocol_QueryInterface(protocol, &IID_IInternetProtocolSink, (void**)&binding_sink);
2936 ok(hres == S_OK, "QueryInterface(IID_IInternetProtocolSink) failed: %08x\n", hres);
2939 SET_EXPECT(QueryService_InternetProtocol);
2940 SET_EXPECT(CreateInstance);
2941 SET_EXPECT(ReportProgress_PROTOCOLCLASSID);
2942 SET_EXPECT(SetPriority);
2945 expect_hrResult = S_OK;
2946 hres = IInternetProtocol_Start(protocol, binding_urls[prot], &protocol_sink, &bind_info, pi, 0);
2947 ok(hres == S_OK, "Start failed: %08x\n", hres);
2949 CHECK_CALLED(QueryService_InternetProtocol);
2950 CHECK_CALLED(CreateInstance);
2951 CHECK_CALLED(ReportProgress_PROTOCOLCLASSID);
2952 CHECK_CALLED(SetPriority);
2953 CHECK_CALLED(Start);
2955 if(prot == HTTP_TEST || prot == HTTPS_TEST) {
2956 while(prot_state < 4) {
2957 WaitForSingleObject(event_complete, INFINITE);
2958 if(mimefilter_test && filtered_protocol) {
2959 SET_EXPECT(Continue);
2960 IInternetProtocol_Continue(filtered_protocol, pdata);
2961 CHECK_CALLED(Continue);
2963 SET_EXPECT(Continue);
2964 IInternetProtocol_Continue(protocol, pdata);
2965 CHECK_CALLED(Continue);
2967 SetEvent(event_complete2);
2970 CHECK_CALLED(ReportData); /* Set in ReportResult */
2971 WaitForSingleObject(event_complete, INFINITE);
2974 SET_EXPECT(MimeFilter_LockRequest);
2976 SET_EXPECT(LockRequest);
2977 hres = IInternetProtocol_LockRequest(protocol, 0);
2978 ok(hres == S_OK, "LockRequest failed: %08x\n", hres);
2980 CHECK_CALLED(MimeFilter_LockRequest);
2982 CHECK_CALLED(LockRequest);
2985 SET_EXPECT(MimeFilter_UnlockRequest);
2987 SET_EXPECT(UnlockRequest);
2988 hres = IInternetProtocol_UnlockRequest(protocol);
2989 ok(hres == S_OK, "UnlockRequest failed: %08x\n", hres);
2991 CHECK_CALLED(MimeFilter_UnlockRequest);
2993 CHECK_CALLED(UnlockRequest);
2997 SET_EXPECT(MimeFilter_Terminate);
2999 SET_EXPECT(Terminate);
3000 hres = IInternetProtocol_Terminate(protocol, 0);
3001 ok(hres == S_OK, "Terminate failed: %08x\n", hres);
3003 CLEAR_CALLED(MimeFilter_Terminate);
3005 CHECK_CALLED(Terminate);
3007 if(filtered_protocol)
3008 IInternetProtocol_Release(filtered_protocol);
3009 IInternetBindInfo_Release(prot_bind_info);
3010 IInternetProtocolSink_Release(binding_sink);
3011 ref = IInternetProtocol_Release(protocol);
3012 ok(!ref, "ref=%u, expected 0\n", ref);
3014 if(test_flags & TEST_EMULATEPROT) {
3015 hres = IInternetSession_UnregisterNameSpace(session, &ClassFactory, protocol_names[prot]);
3016 ok(hres == S_OK, "UnregisterNameSpace failed: %08x\n", hres);
3019 IInternetSession_Release(session);
3022 static void register_filter(void)
3024 IInternetSession *session;
3027 static const WCHAR gzipW[] = {'g','z','i','p',0};
3029 CoInternetGetSession(0, &session, 0);
3031 hres = IInternetSession_RegisterMimeFilter(session, &mimefilter_cf, &IID_IInternetProtocol, gzipW);
3032 ok(hres == S_OK, "RegisterMimeFilter failed: %08x\n", hres);
3034 IInternetSession_Release(session);
3037 START_TEST(protocol)
3039 OleInitialize(NULL);
3041 event_complete = CreateEvent(NULL, FALSE, FALSE, NULL);
3042 event_complete2 = CreateEvent(NULL, FALSE, FALSE, NULL);
3043 event_continue = CreateEvent(NULL, FALSE, FALSE, NULL);
3044 event_continue_done = CreateEvent(NULL, FALSE, FALSE, NULL);
3048 test_file_protocol();
3049 test_http_protocol();
3050 test_https_protocol();
3051 test_ftp_protocol();
3052 test_gopher_protocol();
3054 test_CreateBinding();
3056 bindf &= ~BINDF_FROMURLMON;
3057 trace("Testing file binding (mime verification, emulate prot)...\n");
3058 test_binding(FILE_TEST, PI_MIMEVERIFICATION, TEST_EMULATEPROT);
3059 trace("Testing http binding (mime verification, emulate prot)...\n");
3060 test_binding(HTTP_TEST, PI_MIMEVERIFICATION, TEST_EMULATEPROT);
3061 trace("Testing http binding (mime verification, emulate prot, short read, direct read)...\n");
3062 test_binding(HTTP_TEST, PI_MIMEVERIFICATION, TEST_EMULATEPROT|TEST_SHORT_READ|TEST_DIRECT_READ);
3063 trace("Testing file binding (mime verification, emulate prot, mime filter)...\n");
3064 test_binding(FILE_TEST, PI_MIMEVERIFICATION, TEST_EMULATEPROT|TEST_FILTER);
3065 trace("Testing http binding (mime verification, emulate prot, mime filter)...\n");
3066 test_binding(HTTP_TEST, PI_MIMEVERIFICATION, TEST_EMULATEPROT|TEST_FILTER);
3067 trace("Testing http binding (mime verification, emulate prot, direct read)...\n");
3068 test_binding(HTTP_TEST, PI_MIMEVERIFICATION, TEST_EMULATEPROT|TEST_DIRECT_READ);
3070 CloseHandle(event_complete);
3071 CloseHandle(event_complete2);
3072 CloseHandle(event_continue);
3073 CloseHandle(event_continue_done);