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]));
1358 CoTaskMemFree(accept_mimes[0]);
1360 hres = IInternetBindInfo_QueryInterface(pOIBindInfo, &IID_IServiceProvider,
1361 (void**)&service_provider);
1362 ok(hres == S_OK, "QueryInterface failed: %08x\n", hres);
1364 SET_EXPECT(QueryService_HttpNegotiate);
1365 hres = IServiceProvider_QueryService(service_provider, &IID_IHttpNegotiate,
1366 &IID_IHttpNegotiate, (void**)&http_negotiate);
1367 CHECK_CALLED(QueryService_HttpNegotiate);
1368 ok(hres == S_OK, "QueryService failed: %08x\n", hres);
1370 SET_EXPECT(BeginningTransaction);
1371 hres = IHttpNegotiate_BeginningTransaction(http_negotiate, binding_urls[tested_protocol],
1372 NULL, 0, &additional_headers);
1373 CHECK_CALLED(BeginningTransaction);
1374 IHttpNegotiate_Release(http_negotiate);
1375 ok(hres == S_OK, "BeginningTransction failed: %08x\n", hres);
1376 ok(additional_headers == NULL, "additional_headers=%p\n", additional_headers);
1378 SET_EXPECT(QueryService_HttpNegotiate);
1379 hres = IServiceProvider_QueryService(service_provider, &IID_IHttpNegotiate2,
1380 &IID_IHttpNegotiate2, (void**)&http_negotiate2);
1381 CHECK_CALLED(QueryService_HttpNegotiate);
1382 ok(hres == S_OK, "QueryService failed: %08x\n", hres);
1385 SET_EXPECT(GetRootSecurityId);
1386 hres = IHttpNegotiate2_GetRootSecurityId(http_negotiate2, sec_id, &size, 0);
1387 CHECK_CALLED(GetRootSecurityId);
1388 IHttpNegotiate2_Release(http_negotiate2);
1389 ok(hres == E_FAIL, "GetRootSecurityId failed: %08x, expected E_FAIL\n", hres);
1390 ok(size == 13, "size=%d\n", size);
1392 IServiceProvider_Release(service_provider);
1394 CreateThread(NULL, 0, thread_proc, NULL, 0, &tid);
1399 SET_EXPECT(ReportProgress_CACHEFILENAMEAVAILABLE);
1400 hres = IInternetProtocolSink_ReportProgress(pOIProtSink,
1401 BINDSTATUS_CACHEFILENAMEAVAILABLE, expect_wsz = emptyW);
1402 ok(hres == S_OK, "ReportProgress(BINDSTATUS_CACHEFILENAMEAVAILABLE) failed: %08x\n", hres);
1403 CHECK_CALLED(ReportProgress_CACHEFILENAMEAVAILABLE);
1405 if(mimefilter_test) {
1406 SET_EXPECT(MimeFilter_CreateInstance);
1407 SET_EXPECT(MimeFilter_Start);
1408 SET_EXPECT(ReportProgress_LOADINGMIMEHANDLER);
1410 SET_EXPECT(ReportProgress_MIMETYPEAVAILABLE);
1411 hres = IInternetProtocolSink_ReportProgress(pOIProtSink, BINDSTATUS_VERIFIEDMIMETYPEAVAILABLE,
1412 mimefilter_test ? gzipW : (expect_wsz = text_htmlW));
1414 "ReportProgress(BINDSTATUS_VERIFIEDMIMETYPEAVAILABLE) failed: %08x\n", hres);
1415 if(mimefilter_test) {
1416 CHECK_CALLED(MimeFilter_CreateInstance);
1417 CHECK_CALLED(MimeFilter_Start);
1418 CHECK_CALLED(ReportProgress_LOADINGMIMEHANDLER);
1419 todo_wine CHECK_CALLED(ReportProgress_MIMETYPEAVAILABLE);
1421 CHECK_CALLED(ReportProgress_MIMETYPEAVAILABLE);
1425 SET_EXPECT(MimeFilter_ReportData);
1427 SET_EXPECT(ReportData);
1428 hres = IInternetProtocolSink_ReportData(pOIProtSink,
1429 BSCF_FIRSTDATANOTIFICATION | BSCF_LASTDATANOTIFICATION, 13, 13);
1430 ok(hres == S_OK, "ReportData failed: %08x\n", hres);
1432 CHECK_CALLED(MimeFilter_ReportData);
1434 CHECK_CALLED(ReportData);
1436 if(tested_protocol == BIND_TEST) {
1437 hres = IInternetProtocol_Terminate(binding_protocol, 0);
1438 ok(hres == E_FAIL, "Termiante failed: %08x\n", hres);
1442 SET_EXPECT(MimeFilter_ReportResult);
1444 SET_EXPECT(ReportResult);
1445 hres = IInternetProtocolSink_ReportResult(pOIProtSink, S_OK, 0, NULL);
1446 ok(hres == S_OK, "ReportResult failed: %08x\n", hres);
1448 CHECK_CALLED(MimeFilter_ReportResult);
1450 CHECK_CALLED(ReportResult);
1455 static HRESULT WINAPI ProtocolEmul_Continue(IInternetProtocol *iface,
1456 PROTOCOLDATA *pProtocolData)
1461 CHECK_EXPECT(Continue);
1463 ok(pProtocolData != NULL, "pProtocolData == NULL\n");
1464 if(!pProtocolData || tested_protocol == BIND_TEST)
1467 ok(pProtocolData != &protocoldata, "pProtocolData == &protocoldata\n");
1468 ok(pProtocolData->grfFlags == protocoldata.grfFlags, "grfFlags wrong %x/%x\n",
1469 pProtocolData->grfFlags, protocoldata.grfFlags );
1470 ok(pProtocolData->dwState == protocoldata.dwState, "dwState wrong %x/%x\n",
1471 pProtocolData->dwState, protocoldata.dwState );
1472 ok(pProtocolData->pData == protocoldata.pData, "pData wrong %p/%p\n",
1473 pProtocolData->pData, protocoldata.pData );
1474 ok(pProtocolData->cbData == protocoldata.cbData, "cbData wrong %x/%x\n",
1475 pProtocolData->cbData, protocoldata.cbData );
1478 switch(prot_state) {
1480 IServiceProvider *service_provider;
1481 IHttpNegotiate *http_negotiate;
1482 static WCHAR header[] = {'?',0};
1484 hres = IInternetProtocolSink_QueryInterface(binding_sink, &IID_IServiceProvider,
1485 (void**)&service_provider);
1486 ok(hres == S_OK, "Could not get IServiceProvicder\n");
1488 SET_EXPECT(QueryService_HttpNegotiate);
1489 hres = IServiceProvider_QueryService(service_provider, &IID_IHttpNegotiate,
1490 &IID_IHttpNegotiate, (void**)&http_negotiate);
1491 IServiceProvider_Release(service_provider);
1492 CHECK_CALLED(QueryService_HttpNegotiate);
1493 ok(hres == S_OK, "Could not get IHttpNegotiate\n");
1495 SET_EXPECT(OnResponse);
1496 hres = IHttpNegotiate_OnResponse(http_negotiate, 200, header, NULL, NULL);
1497 IHttpNegotiate_Release(http_negotiate);
1498 CHECK_CALLED(OnResponse);
1499 IHttpNegotiate_Release(http_negotiate);
1500 ok(hres == S_OK, "OnResponse failed: %08x\n", hres);
1502 if(mimefilter_test) {
1503 SET_EXPECT(MimeFilter_CreateInstance);
1504 SET_EXPECT(MimeFilter_Start);
1505 SET_EXPECT(ReportProgress_LOADINGMIMEHANDLER);
1506 }else if(!(pi & PI_MIMEVERIFICATION)) {
1507 SET_EXPECT(ReportProgress_MIMETYPEAVAILABLE);
1509 hres = IInternetProtocolSink_ReportProgress(binding_sink,
1510 BINDSTATUS_MIMETYPEAVAILABLE, mimefilter_test ? gzipW : text_htmlW);
1511 if(mimefilter_test) {
1512 CHECK_CALLED(MimeFilter_CreateInstance);
1513 CHECK_CALLED(MimeFilter_Start);
1514 CHECK_CALLED(ReportProgress_LOADINGMIMEHANDLER);
1515 }else if(!(pi & PI_MIMEVERIFICATION)) {
1516 CHECK_CALLED(ReportProgress_MIMETYPEAVAILABLE);
1519 "ReportProgress(BINDSTATUS_MIMETYPEAVAILABLE) failed: %08x\n", hres);
1521 bscf |= BSCF_FIRSTDATANOTIFICATION;
1526 bscf = BSCF_INTERMEDIATEDATANOTIFICATION;
1531 if(mimefilter_test) {
1532 SET_EXPECT(MimeFilter_ReportData);
1533 }else if(pi & PI_MIMEVERIFICATION) {
1535 SET_EXPECT(Read); /* checked in ReportData for short_read */
1537 if(!mimefilter_test)
1538 SET_EXPECT(Read); /* checked in BINDSTATUS_MIMETYPEAVAILABLE or ReportData */
1539 SET_EXPECT(ReportProgress_MIMETYPEAVAILABLE);
1542 SET_EXPECT(ReportData);
1544 SET_EXPECT(ReportData);
1547 hres = IInternetProtocolSink_ReportData(binding_sink, bscf, pr, 400);
1548 ok(hres == S_OK, "ReportData failed: %08x\n", hres);
1550 if(mimefilter_test) {
1551 SET_EXPECT(MimeFilter_ReportData);
1552 }else if(pi & PI_MIMEVERIFICATION) {
1553 if(!short_read && pr < 200)
1556 CHECK_CALLED(ReportProgress_MIMETYPEAVAILABLE);
1559 CHECK_CALLED(ReportData);
1568 static HRESULT WINAPI ProtocolEmul_Terminate(IInternetProtocol *iface, DWORD dwOptions)
1570 CHECK_EXPECT(Terminate);
1571 ok(!dwOptions, "dwOptions=%d\n", dwOptions);
1575 static HRESULT WINAPI ProtocolEmul_Read(IInternetProtocol *iface, void *pv,
1576 ULONG cb, ULONG *pcbRead)
1578 if(read_report_data)
1579 CHECK_EXPECT2(Read2);
1581 if(mimefilter_test || short_read) {
1582 if(!read_report_data)
1583 CHECK_EXPECT2(Read);
1584 }else if((pi & PI_MIMEVERIFICATION)) {
1585 if(!read_report_data)
1586 CHECK_EXPECT2(Read);
1588 if(prot_read < 300) {
1589 ok(pv != expect_pv, "pv == expect_pv\n");
1591 ok(cb == 2048-prot_read, "cb=%d\n", cb);
1593 ok(cb == 700, "cb=%d\n", cb);
1595 ok(expect_pv <= pv && (BYTE*)pv < (BYTE*)expect_pv + cb, "pv != expect_pv\n");
1598 if(!read_report_data)
1601 ok(pv == expect_pv, "pv != expect_pv\n");
1602 ok(cb == 1000, "cb=%d\n", cb);
1603 ok(!*pcbRead, "*pcbRead = %d\n", *pcbRead);
1605 ok(pcbRead != NULL, "pcbRead == NULL\n");
1607 if(prot_state == 3 || (short_read && prot_state != 4)) {
1612 SET_EXPECT(Read2); /* checked in BINDSTATUS_MIMETYPEAVAILABLE */
1613 SET_EXPECT(ReportProgress_MIMETYPEAVAILABLE);
1616 SET_EXPECT(MimeFilter_ReportData);
1617 else if(direct_read)
1618 SET_EXPECT(ReportData2);
1620 hres = IInternetProtocolSink_ReportData(binding_sink,
1621 BSCF_LASTDATANOTIFICATION|BSCF_INTERMEDIATEDATANOTIFICATION, 0, 0);
1623 ok(hres == S_OK, "ReportData failed: %08x\n", hres);
1625 CHECK_CALLED(ReportProgress_MIMETYPEAVAILABLE);
1627 CHECK_CALLED(MimeFilter_ReportData);
1628 else if(direct_read)
1629 CHECK_CALLED(ReportData2);
1632 SET_EXPECT(MimeFilter_ReportResult);
1634 SET_EXPECT(ReportResult);
1635 hres = IInternetProtocolSink_ReportResult(binding_sink, S_OK, ERROR_SUCCESS, NULL);
1636 ok(hres == S_OK, "ReportResult failed: %08x\n", hres);
1638 CHECK_CALLED(MimeFilter_ReportResult);
1640 CHECK_CALLED(ReportResult);
1642 memset(pv, 'x', 100);
1643 prot_read += *pcbRead = 100;
1645 }if(prot_state == 4) {
1650 if((async_read_pending = !async_read_pending)) {
1652 return tested_protocol == HTTP_TEST || tested_protocol == HTTPS_TEST ? E_PENDING : S_FALSE;
1655 memset(pv, 'x', 100);
1656 prot_read += *pcbRead = 100;
1660 static HRESULT WINAPI ProtocolEmul_LockRequest(IInternetProtocol *iface, DWORD dwOptions)
1662 CHECK_EXPECT(LockRequest);
1663 ok(dwOptions == 0, "dwOptions=%x\n", dwOptions);
1667 static HRESULT WINAPI ProtocolEmul_UnlockRequest(IInternetProtocol *iface)
1669 CHECK_EXPECT(UnlockRequest);
1673 static const IInternetProtocolVtbl ProtocolVtbl = {
1674 ProtocolEmul_QueryInterface,
1678 ProtocolEmul_Continue,
1680 ProtocolEmul_Terminate,
1685 ProtocolEmul_LockRequest,
1686 ProtocolEmul_UnlockRequest
1689 static IInternetProtocol Protocol = { &ProtocolVtbl };
1691 static HRESULT WINAPI MimeProtocol_QueryInterface(IInternetProtocol *iface, REFIID riid, void **ppv)
1693 if(IsEqualGUID(&IID_IUnknown, riid) || IsEqualGUID(&IID_IInternetProtocol, riid)) {
1698 if(IsEqualGUID(&IID_IInternetProtocolSink, riid)) {
1699 *ppv = &mime_protocol_sink;
1703 ok(0, "unexpected riid %s\n", debugstr_guid(riid));
1705 return E_NOINTERFACE;
1708 static HRESULT WINAPI MimeProtocol_Start(IInternetProtocol *iface, LPCWSTR szUrl,
1709 IInternetProtocolSink *pOIProtSink, IInternetBindInfo *pOIBindInfo,
1710 DWORD grfPI, HANDLE_PTR dwReserved)
1712 PROTOCOLFILTERDATA *data;
1713 LPOLESTR url_str = NULL;
1719 CHECK_EXPECT(MimeFilter_Start);
1721 ok(!strcmp_ww(szUrl, gzipW), "wrong url %s\n", wine_dbgstr_w(szUrl));
1722 ok(grfPI == (PI_FILTER_MODE|PI_FORCE_ASYNC), "grfPI=%x, expected PI_FILTER_MODE|PI_FORCE_ASYNC\n", grfPI);
1723 ok(dwReserved, "dwReserved == 0\n");
1724 ok(pOIProtSink != NULL, "pOIProtSink == NULL\n");
1725 ok(pOIBindInfo != NULL, "pOIBindInfo == NULL\n");
1728 ok(pOIProtSink != binding_sink, "pOIProtSink == protocol_sink\n");
1729 ok(pOIBindInfo == prot_bind_info, "pOIBindInfo != bind_info\n");
1731 ok(pOIProtSink == &protocol_sink, "pOIProtSink != protocol_sink\n");
1732 ok(pOIBindInfo == &bind_info, "pOIBindInfo != bind_info\n");
1735 data = (void*)dwReserved;
1736 ok(data->cbSize == sizeof(*data), "data->cbSize = %d\n", data->cbSize);
1737 ok(!data->pProtocolSink, "data->pProtocolSink != NULL\n");
1738 ok(data->pProtocol != NULL, "data->pProtocol == NULL\n");
1739 ok(!data->pUnk, "data->pUnk != NULL\n");
1740 ok(!data->dwFilterFlags, "data->dwProtocolFlags = %x\n", data->dwFilterFlags);
1742 IInternetProtocolSink *prot_sink;
1744 IInternetProtocol_QueryInterface(data->pProtocol, &IID_IInternetProtocolSink, (void**)&prot_sink);
1745 ok(prot_sink == pOIProtSink, "QI(data->pProtocol, IID_IInternetProtocolSink) != pOIProtSink\n");
1746 IInternetProtocolSink_Release(prot_sink);
1748 ok(data->pProtocol != binding_protocol, "data->pProtocol == binding_protocol\n");
1750 filtered_protocol = data->pProtocol;
1751 IInternetProtocol_AddRef(filtered_protocol);
1753 IInternetProtocol *prot;
1755 IInternetProtocol_QueryInterface(data->pProtocol, &IID_IInternetProtocol, (void**)&prot);
1756 ok(prot == async_protocol, "QI(data->pProtocol, IID_IInternetProtocol) != async_protocol\n");
1757 IInternetProtocol_Release(prot);
1759 ok(data->pProtocol != async_protocol, "data->pProtocol == async_protocol\n");
1762 filtered_sink = pOIProtSink;
1764 SET_EXPECT(ReportProgress_DECODING);
1765 hres = IInternetProtocolSink_ReportProgress(pOIProtSink, BINDSTATUS_DECODING, gzipW);
1766 ok(hres == S_OK, "ReportProgress(BINDSTATUS_DECODING) failed: %08x\n", hres);
1767 CHECK_CALLED(ReportProgress_DECODING);
1769 SET_EXPECT(GetBindInfo);
1770 memset(&bindinfo, 0, sizeof(bindinfo));
1771 bindinfo.cbSize = sizeof(bindinfo);
1772 hres = IInternetBindInfo_GetBindInfo(pOIBindInfo, &cbindf, &bindinfo);
1773 ok(hres == S_OK, "GetBindInfo failed: %08x\n", hres);
1774 ok(cbindf == (bindf|BINDF_FROMURLMON), "cbindf = %x, expected %x\n", cbindf, bindf);
1775 CHECK_CALLED(GetBindInfo);
1777 SET_EXPECT(GetBindString_URL);
1778 hres = IInternetBindInfo_GetBindString(pOIBindInfo, BINDSTRING_URL, &url_str, 1, &fetched);
1779 ok(hres == S_OK, "GetBindString(BINDSTRING_URL) failed: %08x\n", hres);
1780 ok(fetched == 1, "fetched = %d\n", fetched);
1781 ok(!strcmp_ww(url_str, binding_urls[tested_protocol]), "wrong url_str %s\n", wine_dbgstr_w(url_str));
1782 CoTaskMemFree(url_str);
1783 CHECK_CALLED(GetBindString_URL);
1788 static HRESULT WINAPI Protocol_Continue(IInternetProtocol *iface,
1789 PROTOCOLDATA *pProtocolData)
1791 CHECK_EXPECT(MimeFilter_Continue);
1795 static HRESULT WINAPI MimeProtocol_Terminate(IInternetProtocol *iface, DWORD dwOptions)
1799 CHECK_EXPECT(MimeFilter_Terminate);
1801 ok(!dwOptions, "dwOptions = %x\n", dwOptions);
1803 SET_EXPECT(Terminate);
1804 hres = IInternetProtocol_Terminate(filtered_protocol, dwOptions);
1805 ok(hres == S_OK, "Terminate failed: %08x\n", hres);
1806 CHECK_CALLED(Terminate);
1811 static HRESULT WINAPI MimeProtocol_Read(IInternetProtocol *iface, void *pv,
1812 ULONG cb, ULONG *pcbRead)
1818 CHECK_EXPECT(MimeFilter_Read);
1820 ok(pv != NULL, "pv == NULL\n");
1821 ok(cb != 0, "cb == 0\n");
1822 ok(pcbRead != NULL, "pcbRead == NULL\n");
1824 if(read_report_data)
1828 hres = IInternetProtocol_Read(filtered_protocol, buf, sizeof(buf), &read);
1829 ok(hres == S_OK || hres == S_FALSE || hres == E_PENDING, "Read failed: %08x\n", hres);
1830 if(read_report_data)
1831 CHECK_CALLED(Read2);
1836 ok(*pcbRead == 0, "*pcbRead=%d, expected 0\n", *pcbRead);
1840 memset(pv, 'x', read);
1844 static HRESULT WINAPI MimeProtocol_LockRequest(IInternetProtocol *iface, DWORD dwOptions)
1848 CHECK_EXPECT(MimeFilter_LockRequest);
1850 ok(!dwOptions, "dwOptions = %x\n", dwOptions);
1852 SET_EXPECT(LockRequest);
1853 hres = IInternetProtocol_LockRequest(filtered_protocol, dwOptions);
1854 ok(hres == S_OK, "LockRequest failed: %08x\n", hres);
1855 CHECK_CALLED(LockRequest);
1860 static HRESULT WINAPI MimeProtocol_UnlockRequest(IInternetProtocol *iface)
1864 CHECK_EXPECT(MimeFilter_UnlockRequest);
1866 SET_EXPECT(UnlockRequest);
1867 hres = IInternetProtocol_UnlockRequest(filtered_protocol);
1868 ok(hres == S_OK, "UnlockRequest failed: %08x\n", hres);
1869 CHECK_CALLED(UnlockRequest);
1874 static const IInternetProtocolVtbl MimeProtocolVtbl = {
1875 MimeProtocol_QueryInterface,
1881 MimeProtocol_Terminate,
1886 MimeProtocol_LockRequest,
1887 MimeProtocol_UnlockRequest
1890 static IInternetProtocol MimeProtocol = { &MimeProtocolVtbl };
1892 static HRESULT WINAPI ClassFactory_QueryInterface(IClassFactory *iface, REFIID riid, void **ppv)
1894 ok(0, "unexpected call\n");
1895 return E_NOINTERFACE;
1898 static ULONG WINAPI ClassFactory_AddRef(IClassFactory *iface)
1903 static ULONG WINAPI ClassFactory_Release(IClassFactory *iface)
1908 static HRESULT WINAPI ClassFactory_CreateInstance(IClassFactory *iface, IUnknown *pOuter,
1909 REFIID riid, void **ppv)
1911 CHECK_EXPECT(CreateInstance);
1913 ok(pOuter == (IUnknown*)prot_bind_info, "pOuter != protocol_unk\n");
1914 ok(IsEqualGUID(&IID_IUnknown, riid), "unexpected riid %s\n", debugstr_guid(riid));
1915 ok(ppv != NULL, "ppv == NULL\n");
1921 static HRESULT WINAPI ClassFactory_LockServer(IClassFactory *iface, BOOL dolock)
1923 ok(0, "unexpected call\n");
1927 static const IClassFactoryVtbl ClassFactoryVtbl = {
1928 ClassFactory_QueryInterface,
1929 ClassFactory_AddRef,
1930 ClassFactory_Release,
1931 ClassFactory_CreateInstance,
1932 ClassFactory_LockServer
1935 static IClassFactory ClassFactory = { &ClassFactoryVtbl };
1937 static HRESULT WINAPI MimeFilter_CreateInstance(IClassFactory *iface, IUnknown *outer, REFIID riid, void **ppv)
1939 CHECK_EXPECT(MimeFilter_CreateInstance);
1941 ok(!outer, "outer = %p\n", outer);
1942 ok(IsEqualGUID(&IID_IInternetProtocol, riid), "unexpected riid %s\n", debugstr_guid(riid));
1944 *ppv = &MimeProtocol;
1948 static const IClassFactoryVtbl MimeFilterCFVtbl = {
1949 ClassFactory_QueryInterface,
1950 ClassFactory_AddRef,
1951 ClassFactory_Release,
1952 MimeFilter_CreateInstance,
1953 ClassFactory_LockServer
1956 static IClassFactory mimefilter_cf = { &MimeFilterCFVtbl };
1958 #define TEST_BINDING 0x01
1959 #define TEST_FILTER 0x02
1960 #define TEST_FIRST_HTTP 0x04
1961 #define TEST_DIRECT_READ 0x08
1962 #define TEST_POST 0x10
1963 #define TEST_EMULATEPROT 0x20
1964 #define TEST_SHORT_READ 0x40
1965 #define TEST_REDIRECT 0x80
1967 static void init_test(int prot, DWORD flags)
1969 tested_protocol = prot;
1970 binding_test = (flags & TEST_BINDING) != 0;
1971 first_data_notif = TRUE;
1974 async_read_pending = TRUE;
1975 mimefilter_test = (flags & TEST_FILTER) != 0;
1977 ResetEvent(event_complete);
1978 ResetEvent(event_complete2);
1979 ResetEvent(event_continue);
1980 ResetEvent(event_continue_done);
1981 async_protocol = binding_protocol = filtered_protocol = NULL;
1982 filtered_sink = NULL;
1983 http_is_first = (flags & TEST_FIRST_HTTP) != 0;
1984 first_data_notif = TRUE;
1986 direct_read = (flags & TEST_DIRECT_READ) != 0;
1987 http_post_test = (flags & TEST_POST) != 0;
1988 emulate_prot = (flags & TEST_EMULATEPROT) != 0;
1989 wait_for_switch = TRUE;
1990 short_read = (flags & TEST_SHORT_READ) != 0;
1991 test_redirect = (flags & TEST_REDIRECT) != 0;
1994 static void test_priority(IInternetProtocol *protocol)
1996 IInternetPriority *priority;
2000 hres = IInternetProtocol_QueryInterface(protocol, &IID_IInternetPriority,
2002 ok(hres == S_OK, "QueryInterface(IID_IInternetPriority) failed: %08x\n", hres);
2006 hres = IInternetPriority_GetPriority(priority, &pr);
2007 ok(hres == S_OK, "GetPriority failed: %08x\n", hres);
2008 ok(pr == 0, "pr=%d, expected 0\n", pr);
2010 hres = IInternetPriority_SetPriority(priority, 1);
2011 ok(hres == S_OK, "SetPriority failed: %08x\n", hres);
2013 hres = IInternetPriority_GetPriority(priority, &pr);
2014 ok(hres == S_OK, "GetPriority failed: %08x\n", hres);
2015 ok(pr == 1, "pr=%d, expected 1\n", pr);
2017 IInternetPriority_Release(priority);
2020 static BOOL file_protocol_start(IInternetProtocol *protocol, LPCWSTR url, BOOL is_first)
2024 SET_EXPECT(GetBindInfo);
2025 if(!(bindf & BINDF_FROMURLMON))
2026 SET_EXPECT(ReportProgress_DIRECTBIND);
2028 SET_EXPECT(ReportProgress_SENDINGREQUEST);
2029 SET_EXPECT(ReportProgress_CACHEFILENAMEAVAILABLE);
2030 if(bindf & BINDF_FROMURLMON)
2031 SET_EXPECT(ReportProgress_VERIFIEDMIMETYPEAVAILABLE);
2033 SET_EXPECT(ReportProgress_MIMETYPEAVAILABLE);
2035 SET_EXPECT(ReportData);
2037 SET_EXPECT(ReportResult);
2039 expect_hrResult = S_OK;
2041 hres = IInternetProtocol_Start(protocol, url, &protocol_sink, &bind_info, 0, 0);
2042 if(hres == INET_E_RESOURCE_NOT_FOUND) {
2043 win_skip("Start failed\n");
2046 ok(hres == S_OK, "Start failed: %08x\n", hres);
2048 CHECK_CALLED(GetBindInfo);
2049 if(!(bindf & BINDF_FROMURLMON))
2050 CHECK_CALLED(ReportProgress_DIRECTBIND);
2052 CHECK_CALLED(ReportProgress_SENDINGREQUEST);
2053 CHECK_CALLED(ReportProgress_CACHEFILENAMEAVAILABLE);
2054 if(bindf & BINDF_FROMURLMON)
2055 CHECK_CALLED(ReportProgress_VERIFIEDMIMETYPEAVAILABLE);
2057 CHECK_CALLED(ReportProgress_MIMETYPEAVAILABLE);
2059 CHECK_CALLED(ReportData);
2061 CHECK_CALLED(ReportResult);
2066 static void test_file_protocol_url(LPCWSTR url)
2068 IInternetProtocolInfo *protocol_info;
2070 IClassFactory *factory;
2073 hres = CoGetClassObject(&CLSID_FileProtocol, CLSCTX_INPROC_SERVER, NULL,
2074 &IID_IUnknown, (void**)&unk);
2075 ok(hres == S_OK, "CoGetClassObject failed: %08x\n", hres);
2079 hres = IUnknown_QueryInterface(unk, &IID_IInternetProtocolInfo, (void**)&protocol_info);
2080 ok(hres == E_NOINTERFACE,
2081 "Could not get IInternetProtocolInfo interface: %08x, expected E_NOINTERFACE\n", hres);
2083 hres = IUnknown_QueryInterface(unk, &IID_IClassFactory, (void**)&factory);
2084 ok(hres == S_OK, "Could not get IClassFactory interface\n");
2085 if(SUCCEEDED(hres)) {
2086 IInternetProtocol *protocol;
2089 hres = IClassFactory_CreateInstance(factory, NULL, &IID_IInternetProtocol, (void**)&protocol);
2090 ok(hres == S_OK, "Could not get IInternetProtocol: %08x\n", hres);
2092 if(SUCCEEDED(hres)) {
2093 if(file_protocol_start(protocol, url, TRUE)) {
2094 hres = IInternetProtocol_Read(protocol, buf, 2, &cb);
2095 ok(hres == S_OK, "Read failed: %08x\n", hres);
2096 ok(cb == 2, "cb=%u expected 2\n", cb);
2097 hres = IInternetProtocol_Read(protocol, buf, sizeof(buf), &cb);
2098 ok(hres == S_FALSE, "Read failed: %08x\n", hres);
2099 hres = IInternetProtocol_Read(protocol, buf, sizeof(buf), &cb);
2100 ok(hres == S_FALSE, "Read failed: %08x expected S_FALSE\n", hres);
2101 ok(cb == 0, "cb=%u expected 0\n", cb);
2102 hres = IInternetProtocol_UnlockRequest(protocol);
2103 ok(hres == S_OK, "UnlockRequest failed: %08x\n", hres);
2106 if(file_protocol_start(protocol, url, FALSE)) {
2107 hres = IInternetProtocol_Read(protocol, buf, 2, &cb);
2108 ok(hres == S_FALSE, "Read failed: %08x\n", hres);
2109 hres = IInternetProtocol_LockRequest(protocol, 0);
2110 ok(hres == S_OK, "LockRequest failed: %08x\n", hres);
2111 hres = IInternetProtocol_UnlockRequest(protocol);
2112 ok(hres == S_OK, "UnlockRequest failed: %08x\n", hres);
2115 IInternetProtocol_Release(protocol);
2118 hres = IClassFactory_CreateInstance(factory, NULL, &IID_IInternetProtocol, (void**)&protocol);
2119 ok(hres == S_OK, "Could not get IInternetProtocol: %08x\n", hres);
2121 if(SUCCEEDED(hres)) {
2122 if(file_protocol_start(protocol, url, TRUE)) {
2123 hres = IInternetProtocol_LockRequest(protocol, 0);
2124 ok(hres == S_OK, "LockRequest failed: %08x\n", hres);
2125 hres = IInternetProtocol_Terminate(protocol, 0);
2126 ok(hres == S_OK, "Terminate failed: %08x\n", hres);
2127 hres = IInternetProtocol_Read(protocol, buf, 2, &cb);
2128 ok(hres == S_OK, "Read failed: %08x\n\n", hres);
2129 hres = IInternetProtocol_UnlockRequest(protocol);
2130 ok(hres == S_OK, "UnlockRequest failed: %08x\n", hres);
2131 hres = IInternetProtocol_Read(protocol, buf, 2, &cb);
2132 ok(hres == S_OK, "Read failed: %08x\n", hres);
2133 hres = IInternetProtocol_Terminate(protocol, 0);
2134 ok(hres == S_OK, "Terminate failed: %08x\n", hres);
2137 IInternetProtocol_Release(protocol);
2140 hres = IClassFactory_CreateInstance(factory, NULL, &IID_IInternetProtocol, (void**)&protocol);
2141 ok(hres == S_OK, "Could not get IInternetProtocol: %08x\n", hres);
2143 if(SUCCEEDED(hres)) {
2144 if(file_protocol_start(protocol, url, TRUE)) {
2145 hres = IInternetProtocol_Terminate(protocol, 0);
2146 ok(hres == S_OK, "Terminate failed: %08x\n", hres);
2147 hres = IInternetProtocol_Read(protocol, buf, 2, &cb);
2148 ok(hres == S_OK, "Read failed: %08x\n", hres);
2149 ok(cb == 2, "cb=%u expected 2\n", cb);
2152 IInternetProtocol_Release(protocol);
2155 IClassFactory_Release(factory);
2158 IUnknown_Release(unk);
2161 static void test_file_protocol_fail(void)
2163 IInternetProtocol *protocol;
2166 static const WCHAR index_url2[] =
2167 {'f','i','l','e',':','/','/','i','n','d','e','x','.','h','t','m','l',0};
2169 hres = CoCreateInstance(&CLSID_FileProtocol, NULL, CLSCTX_INPROC_SERVER|CLSCTX_INPROC_HANDLER,
2170 &IID_IInternetProtocol, (void**)&protocol);
2171 ok(hres == S_OK, "CoCreateInstance failed: %08x\n", hres);
2175 SET_EXPECT(GetBindInfo);
2176 expect_hrResult = MK_E_SYNTAX;
2177 hres = IInternetProtocol_Start(protocol, wszIndexHtml, &protocol_sink, &bind_info, 0, 0);
2178 ok(hres == MK_E_SYNTAX ||
2179 hres == E_INVALIDARG,
2180 "Start failed: %08x, expected MK_E_SYNTAX or E_INVALIDARG\n", hres);
2181 CLEAR_CALLED(GetBindInfo); /* GetBindInfo not called in IE7 */
2183 SET_EXPECT(GetBindInfo);
2184 if(!(bindf & BINDF_FROMURLMON))
2185 SET_EXPECT(ReportProgress_DIRECTBIND);
2186 SET_EXPECT(ReportProgress_SENDINGREQUEST);
2187 SET_EXPECT(ReportResult);
2188 expect_hrResult = INET_E_RESOURCE_NOT_FOUND;
2189 hres = IInternetProtocol_Start(protocol, index_url, &protocol_sink, &bind_info, 0, 0);
2190 ok(hres == INET_E_RESOURCE_NOT_FOUND,
2191 "Start failed: %08x expected INET_E_RESOURCE_NOT_FOUND\n", hres);
2192 CHECK_CALLED(GetBindInfo);
2193 if(!(bindf & BINDF_FROMURLMON))
2194 CHECK_CALLED(ReportProgress_DIRECTBIND);
2195 CHECK_CALLED(ReportProgress_SENDINGREQUEST);
2196 CHECK_CALLED(ReportResult);
2198 IInternetProtocol_Release(protocol);
2200 hres = CoCreateInstance(&CLSID_FileProtocol, NULL, CLSCTX_INPROC_SERVER|CLSCTX_INPROC_HANDLER,
2201 &IID_IInternetProtocol, (void**)&protocol);
2202 ok(hres == S_OK, "CoCreateInstance failed: %08x\n", hres);
2206 SET_EXPECT(GetBindInfo);
2207 if(!(bindf & BINDF_FROMURLMON))
2208 SET_EXPECT(ReportProgress_DIRECTBIND);
2209 SET_EXPECT(ReportProgress_SENDINGREQUEST);
2210 SET_EXPECT(ReportResult);
2211 expect_hrResult = INET_E_RESOURCE_NOT_FOUND;
2213 hres = IInternetProtocol_Start(protocol, index_url2, &protocol_sink, &bind_info, 0, 0);
2214 ok(hres == INET_E_RESOURCE_NOT_FOUND,
2215 "Start failed: %08x, expected INET_E_RESOURCE_NOT_FOUND\n", hres);
2216 CHECK_CALLED(GetBindInfo);
2217 if(!(bindf & BINDF_FROMURLMON))
2218 CHECK_CALLED(ReportProgress_DIRECTBIND);
2219 CHECK_CALLED(ReportProgress_SENDINGREQUEST);
2220 CHECK_CALLED(ReportResult);
2222 SET_EXPECT(GetBindInfo);
2223 hres = IInternetProtocol_Start(protocol, NULL, &protocol_sink, &bind_info, 0, 0);
2224 ok(hres == E_INVALIDARG, "Start failed: %08x, expected E_INVALIDARG\n", hres);
2225 CLEAR_CALLED(GetBindInfo); /* GetBindInfo not called in IE7 */
2227 SET_EXPECT(GetBindInfo);
2228 hres = IInternetProtocol_Start(protocol, emptyW, &protocol_sink, &bind_info, 0, 0);
2229 ok(hres == E_INVALIDARG, "Start failed: %08x, expected E_INVALIDARG\n", hres);
2230 CLEAR_CALLED(GetBindInfo); /* GetBindInfo not called in IE7 */
2232 IInternetProtocol_Release(protocol);
2235 static void test_file_protocol(void) {
2236 WCHAR buf[INTERNET_MAX_URL_LENGTH], file_name_buf[MAX_PATH];
2241 static const WCHAR wszFile[] = {'f','i','l','e',':',0};
2242 static const WCHAR wszFile2[] = {'f','i','l','e',':','/','/',0};
2243 static const WCHAR wszFile3[] = {'f','i','l','e',':','/','/','/',0};
2244 static const char html_doc[] = "<HTML></HTML>";
2246 trace("Testing file protocol...\n");
2247 init_test(FILE_TEST, 0);
2249 SetLastError(0xdeadbeef);
2250 file = CreateFileW(wszIndexHtml, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS,
2251 FILE_ATTRIBUTE_NORMAL, NULL);
2252 if(!file && GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)
2254 win_skip("Detected Win9x or WinMe\n");
2257 ok(file != INVALID_HANDLE_VALUE, "CreateFile failed\n");
2258 if(file == INVALID_HANDLE_VALUE)
2260 WriteFile(file, html_doc, sizeof(html_doc)-1, &size, NULL);
2263 file_name = wszIndexHtml;
2265 test_file_protocol_url(index_url);
2266 bindf = BINDF_FROMURLMON;
2267 test_file_protocol_url(index_url);
2268 bindf = BINDF_FROMURLMON | BINDF_NEEDFILE;
2269 test_file_protocol_url(index_url);
2271 memcpy(buf, wszFile, sizeof(wszFile));
2272 len = sizeof(wszFile)/sizeof(WCHAR)-1;
2273 len += GetCurrentDirectoryW(sizeof(buf)/sizeof(WCHAR)-len, buf+len);
2275 memcpy(buf+len, wszIndexHtml, sizeof(wszIndexHtml));
2277 file_name = buf + sizeof(wszFile)/sizeof(WCHAR)-1;
2279 test_file_protocol_url(buf);
2280 bindf = BINDF_FROMURLMON;
2281 test_file_protocol_url(buf);
2283 memcpy(buf, wszFile2, sizeof(wszFile2));
2284 len = GetCurrentDirectoryW(sizeof(file_name_buf)/sizeof(WCHAR), file_name_buf);
2285 file_name_buf[len++] = '\\';
2286 memcpy(file_name_buf+len, wszIndexHtml, sizeof(wszIndexHtml));
2287 lstrcpyW(buf+sizeof(wszFile2)/sizeof(WCHAR)-1, file_name_buf);
2288 file_name = file_name_buf;
2290 test_file_protocol_url(buf);
2291 bindf = BINDF_FROMURLMON;
2292 test_file_protocol_url(buf);
2294 buf[sizeof(wszFile2)/sizeof(WCHAR)] = '|';
2295 test_file_protocol_url(buf);
2297 memcpy(buf, wszFile3, sizeof(wszFile3));
2298 len = sizeof(wszFile3)/sizeof(WCHAR)-1;
2299 len += GetCurrentDirectoryW(sizeof(buf)/sizeof(WCHAR)-len, buf+len);
2301 memcpy(buf+len, wszIndexHtml, sizeof(wszIndexHtml));
2303 file_name = buf + sizeof(wszFile3)/sizeof(WCHAR)-1;
2305 test_file_protocol_url(buf);
2306 bindf = BINDF_FROMURLMON;
2307 test_file_protocol_url(buf);
2309 DeleteFileW(wszIndexHtml);
2312 test_file_protocol_fail();
2313 bindf = BINDF_FROMURLMON;
2314 test_file_protocol_fail();
2317 static BOOL http_protocol_start(LPCWSTR url)
2319 static BOOL got_user_agent = FALSE;
2322 SET_EXPECT(GetBindInfo);
2323 if (!(bindf & BINDF_FROMURLMON))
2324 SET_EXPECT(ReportProgress_DIRECTBIND);
2326 SET_EXPECT(GetBindString_USER_AGENT);
2327 SET_EXPECT(GetBindString_ACCEPT_MIMES);
2328 SET_EXPECT(QueryService_HttpNegotiate);
2329 SET_EXPECT(BeginningTransaction);
2330 SET_EXPECT(GetRootSecurityId);
2332 SET_EXPECT(GetBindString_POST_COOKIE);
2334 hres = IInternetProtocol_Start(async_protocol, url, &protocol_sink, &bind_info, 0, 0);
2335 ok(hres == S_OK, "Start failed: %08x\n", hres);
2339 CHECK_CALLED(GetBindInfo);
2340 if (!(bindf & BINDF_FROMURLMON))
2341 CHECK_CALLED(ReportProgress_DIRECTBIND);
2342 if (!got_user_agent)
2344 CHECK_CALLED(GetBindString_USER_AGENT);
2345 got_user_agent = TRUE;
2347 CHECK_CALLED(GetBindString_ACCEPT_MIMES);
2348 CHECK_CALLED(QueryService_HttpNegotiate);
2349 CHECK_CALLED(BeginningTransaction);
2350 /* GetRootSecurityId called on WinXP but not on Win98 */
2351 CLEAR_CALLED(GetRootSecurityId);
2353 CHECK_CALLED(GetBindString_POST_COOKIE);
2358 static void test_protocol_terminate(IInternetProtocol *protocol)
2364 hres = IInternetProtocol_LockRequest(protocol, 0);
2365 ok(hres == S_OK, "LockRequest failed: %08x\n", hres);
2367 hres = IInternetProtocol_Read(protocol, buf, 1, &cb);
2368 ok(hres == S_FALSE, "Read failed: %08x\n", hres);
2370 hres = IInternetProtocol_Terminate(protocol, 0);
2371 ok(hres == S_OK, "Terminate failed: %08x\n", hres);
2373 /* This wait is to give the internet handles being freed in Terminate
2374 * enough time to actually terminate in all cases. Internet handles
2375 * terminate asynchronously and native reuses the main InternetOpen
2376 * handle. The only case in which this seems to be necessary is on
2377 * wine with native wininet and urlmon, resulting in the next time
2378 * test_http_protocol_url being called the first data notification actually
2379 * being an extra last data notification from the previous connection
2380 * about once out of every ten times. */
2383 hres = IInternetProtocol_UnlockRequest(protocol);
2384 ok(hres == S_OK, "UnlockRequest failed: %08x\n", hres);
2387 static void test_http_info(IInternetProtocol *protocol)
2389 IWinInetHttpInfo *info;
2392 hres = IInternetProtocol_QueryInterface(protocol, &IID_IWinInetHttpInfo, (void**)&info);
2393 ok(hres == S_OK, "Could not get IWinInterHttpInfo iface: %08x\n", hres);
2397 IWinInetHttpInfo_Release(info);
2400 /* is_first refers to whether this is the first call to this function
2402 static void test_http_protocol_url(LPCWSTR url, int prot, DWORD flags)
2404 IInternetProtocolInfo *protocol_info;
2405 IClassFactory *factory;
2409 init_test(prot, flags);
2412 hres = CoGetClassObject(prot == HTTPS_TEST ? &CLSID_HttpSProtocol : &CLSID_HttpProtocol,
2413 CLSCTX_INPROC_SERVER, NULL, &IID_IUnknown, (void**)&unk);
2414 ok(hres == S_OK, "CoGetClassObject failed: %08x\n", hres);
2418 hres = IUnknown_QueryInterface(unk, &IID_IInternetProtocolInfo, (void**)&protocol_info);
2419 ok(hres == E_NOINTERFACE,
2420 "Could not get IInternetProtocolInfo interface: %08x, expected E_NOINTERFACE\n",
2423 hres = IUnknown_QueryInterface(unk, &IID_IClassFactory, (void**)&factory);
2424 ok(hres == S_OK, "Could not get IClassFactory interface\n");
2425 IUnknown_Release(unk);
2429 hres = IClassFactory_CreateInstance(factory, NULL, &IID_IInternetProtocol,
2430 (void**)&async_protocol);
2431 ok(hres == S_OK, "Could not get IInternetProtocol: %08x\n", hres);
2432 if(SUCCEEDED(hres)) {
2437 test_priority(async_protocol);
2438 test_http_info(async_protocol);
2440 SET_EXPECT(ReportProgress_COOKIE_SENT);
2441 SET_EXPECT(ReportProgress_FINDINGRESOURCE);
2442 SET_EXPECT(ReportProgress_CONNECTING);
2443 SET_EXPECT(ReportProgress_SENDINGREQUEST);
2445 SET_EXPECT(ReportProgress_REDIRECTING);
2446 SET_EXPECT(ReportProgress_PROXYDETECTING);
2447 if(prot == HTTP_TEST)
2448 SET_EXPECT(ReportProgress_CACHEFILENAMEAVAILABLE);
2450 SET_EXPECT(QueryService_HttpSecurity);
2451 if(!(bindf & BINDF_FROMURLMON)) {
2452 SET_EXPECT(OnResponse);
2453 SET_EXPECT(ReportProgress_RAWMIMETYPE);
2454 SET_EXPECT(ReportData);
2459 if(!http_protocol_start(url))
2463 SET_EXPECT(ReportResult);
2464 expect_hrResult = S_OK;
2467 while(wait_for_switch) {
2469 WaitForSingleObject(event_continue, INFINITE);
2470 CHECK_CALLED(Switch);
2471 call_continue(&continue_protdata);
2472 SetEvent(event_continue_done);
2475 hres = IInternetProtocol_Read(async_protocol, buf, 1, &cb);
2476 ok((hres == E_PENDING && cb==0) ||
2477 (hres == S_OK && cb==1), "Read failed: %08x (%d bytes)\n", hres, cb);
2479 WaitForSingleObject(event_complete, INFINITE);
2480 if(bindf & BINDF_FROMURLMON)
2481 CHECK_CALLED(Switch);
2483 CHECK_CALLED(ReportData);
2484 if(prot == HTTPS_TEST)
2485 CLEAR_CALLED(QueryService_HttpSecurity);
2488 if(bindf & BINDF_FROMURLMON)
2491 SET_EXPECT(ReportData);
2492 hres = IInternetProtocol_Read(async_protocol, buf, sizeof(buf), &cb);
2493 if(hres == E_PENDING) {
2494 hres = IInternetProtocol_Read(async_protocol, buf, 1, &cb);
2495 ok((hres == E_PENDING && cb==0) ||
2496 (hres == S_OK && cb==1), "Read failed: %08x (%d bytes)\n", hres, cb);
2497 WaitForSingleObject(event_complete, INFINITE);
2498 if(bindf & BINDF_FROMURLMON)
2499 CHECK_CALLED(Switch);
2501 CHECK_CALLED(ReportData);
2503 if(bindf & BINDF_FROMURLMON)
2504 CHECK_NOT_CALLED(Switch);
2506 CHECK_NOT_CALLED(ReportData);
2510 ok(hres == S_FALSE, "Read failed: %08x\n", hres);
2511 CHECK_CALLED(ReportResult);
2513 if(prot == HTTPS_TEST)
2514 CLEAR_CALLED(ReportProgress_SENDINGREQUEST);
2516 test_protocol_terminate(async_protocol);
2517 ref = IInternetProtocol_Release(async_protocol);
2518 ok(!ref, "ref=%x\n", hres);
2521 IClassFactory_Release(factory);
2524 static void test_http_protocol(void)
2526 static const WCHAR winehq_url[] =
2527 {'h','t','t','p',':','/','/','w','w','w','.','w','i','n','e','h','q','.',
2528 'o','r','g','/','s','i','t','e','/','a','b','o','u','t',0};
2529 static const WCHAR posttest_url[] =
2530 {'h','t','t','p',':','/','/','c','r','o','s','s','o','v','e','r','.',
2531 'c','o','d','e','w','e','a','v','e','r','s','.','c','o','m','/',
2532 'p','o','s','t','t','e','s','t','.','p','h','p',0};
2533 static const WCHAR redirect_url[] =
2534 {'h','t','t','p',':','/','/','t','e','s','t','.','w','i','n','e','h','q','.','o','r','g','/',
2535 't','e','s','t','r','e','d','i','r','e','c','t',0};
2537 trace("Testing http protocol (not from urlmon)...\n");
2538 bindf = BINDF_ASYNCHRONOUS | BINDF_ASYNCSTORAGE | BINDF_PULLDATA;
2539 test_http_protocol_url(winehq_url, HTTP_TEST, TEST_FIRST_HTTP);
2541 trace("Testing http protocol (from urlmon)...\n");
2542 bindf = BINDF_ASYNCHRONOUS | BINDF_ASYNCSTORAGE | BINDF_PULLDATA | BINDF_FROMURLMON;
2543 test_http_protocol_url(winehq_url, HTTP_TEST, 0);
2545 trace("Testing http protocol (to file)...\n");
2546 bindf = BINDF_ASYNCHRONOUS | BINDF_ASYNCSTORAGE | BINDF_PULLDATA | BINDF_FROMURLMON | BINDF_NEEDFILE;
2547 test_http_protocol_url(winehq_url, HTTP_TEST, 0);
2549 trace("Testing http protocol (post data)...\n");
2550 /* Without this flag we get a ReportProgress_CACHEFILENAMEAVAILABLE
2551 * notification with BINDVERB_POST */
2552 bindf = BINDF_ASYNCHRONOUS | BINDF_ASYNCSTORAGE | BINDF_PULLDATA | BINDF_FROMURLMON | BINDF_NOWRITECACHE;
2553 test_http_protocol_url(posttest_url, HTTP_TEST, TEST_FIRST_HTTP|TEST_POST);
2555 trace("Testing http protocol (direct read)...\n");
2556 bindf = BINDF_ASYNCHRONOUS | BINDF_ASYNCSTORAGE | BINDF_PULLDATA | BINDF_FROMURLMON;
2557 test_http_protocol_url(winehq_url, HTTP_TEST, TEST_DIRECT_READ);
2559 trace("Testing http protocol (redirected)...\n");
2560 bindf = BINDF_ASYNCHRONOUS | BINDF_ASYNCSTORAGE | BINDF_PULLDATA | BINDF_FROMURLMON;
2561 test_http_protocol_url(redirect_url, HTTP_TEST, TEST_REDIRECT);
2564 static void test_https_protocol(void)
2566 static const WCHAR codeweavers_url[] =
2567 {'h','t','t','p','s',':','/','/','w','w','w','.','c','o','d','e','w','e','a','v','e','r','s',
2568 '.','c','o','m','/','t','e','s','t','.','h','t','m','l',0};
2570 trace("Testing https protocol (from urlmon)...\n");
2571 bindf = BINDF_ASYNCHRONOUS | BINDF_ASYNCSTORAGE | BINDF_PULLDATA | BINDF_FROMURLMON | BINDF_NOWRITECACHE;
2572 test_http_protocol_url(codeweavers_url, HTTPS_TEST, TEST_FIRST_HTTP);
2576 static void test_ftp_protocol(void)
2578 IInternetProtocolInfo *protocol_info;
2579 IClassFactory *factory;
2586 static const WCHAR ftp_urlW[] = {'f','t','p',':','/','/','f','t','p','.','w','i','n','e','h','q','.','o','r','g',
2587 '/','p','u','b','/','o','t','h','e','r','/',
2588 'w','i','n','e','l','o','g','o','.','x','c','f','.','t','a','r','.','b','z','2',0};
2590 trace("Testing ftp protocol...\n");
2592 bindf = BINDF_ASYNCHRONOUS | BINDF_ASYNCSTORAGE | BINDF_PULLDATA | BINDF_FROMURLMON | BINDF_NOWRITECACHE;
2594 tested_protocol = FTP_TEST;
2595 first_data_notif = TRUE;
2596 expect_hrResult = E_PENDING;
2598 hres = CoGetClassObject(&CLSID_FtpProtocol, CLSCTX_INPROC_SERVER, NULL, &IID_IUnknown, (void**)&unk);
2599 ok(hres == S_OK, "CoGetClassObject failed: %08x\n", hres);
2603 hres = IUnknown_QueryInterface(unk, &IID_IInternetProtocolInfo, (void**)&protocol_info);
2604 ok(hres == E_NOINTERFACE, "Could not get IInternetProtocolInfo interface: %08x, expected E_NOINTERFACE\n", hres);
2606 hres = IUnknown_QueryInterface(unk, &IID_IClassFactory, (void**)&factory);
2607 ok(hres == S_OK, "Could not get IClassFactory interface\n");
2608 IUnknown_Release(unk);
2612 hres = IClassFactory_CreateInstance(factory, NULL, &IID_IInternetProtocol,
2613 (void**)&async_protocol);
2614 IClassFactory_Release(factory);
2615 ok(hres == S_OK, "Could not get IInternetProtocol: %08x\n", hres);
2617 test_priority(async_protocol);
2618 test_http_info(async_protocol);
2620 SET_EXPECT(GetBindInfo);
2621 SET_EXPECT(ReportProgress_FINDINGRESOURCE);
2622 SET_EXPECT(ReportProgress_CONNECTING);
2623 SET_EXPECT(ReportProgress_SENDINGREQUEST);
2626 hres = IInternetProtocol_Start(async_protocol, ftp_urlW, &protocol_sink, &bind_info, 0, 0);
2627 ok(hres == S_OK, "Start failed: %08x\n", hres);
2628 CHECK_CALLED(GetBindInfo);
2630 SET_EXPECT(ReportResult);
2632 hres = IInternetProtocol_Read(async_protocol, buf, 1, &cb);
2633 ok((hres == E_PENDING && cb==0) ||
2634 (hres == S_OK && cb==1), "Read failed: %08x (%d bytes)\n", hres, cb);
2636 WaitForSingleObject(event_complete, INFINITE);
2640 hres = IInternetProtocol_Read(async_protocol, buf, sizeof(buf), &cb);
2641 if(hres == E_PENDING)
2642 WaitForSingleObject(event_complete, INFINITE);
2647 ok(hres == S_FALSE, "Read failed: %08x\n", hres);
2648 CHECK_CALLED(ReportResult);
2649 CHECK_CALLED(Switch);
2651 test_protocol_terminate(async_protocol);
2653 ref = IInternetProtocol_Release(async_protocol);
2654 ok(!ref, "ref=%d\n", ref);
2657 static void test_gopher_protocol(void)
2659 IInternetProtocolInfo *protocol_info;
2660 IClassFactory *factory;
2664 trace("Testing gopher protocol...\n");
2666 hres = CoGetClassObject(&CLSID_GopherProtocol, CLSCTX_INPROC_SERVER, NULL, &IID_IUnknown, (void**)&unk);
2668 hres == REGDB_E_CLASSNOTREG, /* Gopher protocol has been removed as of Vista */
2669 "CoGetClassObject failed: %08x\n", hres);
2673 hres = IUnknown_QueryInterface(unk, &IID_IInternetProtocolInfo, (void**)&protocol_info);
2674 ok(hres == E_NOINTERFACE, "Could not get IInternetProtocolInfo interface: %08x, expected E_NOINTERFACE\n", hres);
2676 hres = IUnknown_QueryInterface(unk, &IID_IClassFactory, (void**)&factory);
2677 ok(hres == S_OK, "Could not get IClassFactory interface\n");
2678 IUnknown_Release(unk);
2682 hres = IClassFactory_CreateInstance(factory, NULL, &IID_IInternetProtocol,
2683 (void**)&async_protocol);
2684 IClassFactory_Release(factory);
2685 ok(hres == S_OK, "Could not get IInternetProtocol: %08x\n", hres);
2687 test_priority(async_protocol);
2689 IInternetProtocol_Release(async_protocol);
2692 static void test_mk_protocol(void)
2694 IInternetProtocolInfo *protocol_info;
2695 IInternetProtocol *protocol;
2696 IClassFactory *factory;
2700 static const WCHAR wrong_url1[] = {'t','e','s','t',':','@','M','S','I','T','S','t','o','r','e',
2701 ':',':','/','t','e','s','t','.','h','t','m','l',0};
2702 static const WCHAR wrong_url2[] = {'m','k',':','/','t','e','s','t','.','h','t','m','l',0};
2704 trace("Testing mk protocol...\n");
2705 init_test(MK_TEST, 0);
2707 hres = CoGetClassObject(&CLSID_MkProtocol, CLSCTX_INPROC_SERVER, NULL,
2708 &IID_IUnknown, (void**)&unk);
2709 ok(hres == S_OK, "CoGetClassObject failed: %08x\n", hres);
2711 hres = IUnknown_QueryInterface(unk, &IID_IInternetProtocolInfo, (void**)&protocol_info);
2712 ok(hres == E_NOINTERFACE,
2713 "Could not get IInternetProtocolInfo interface: %08x, expected E_NOINTERFACE\n",
2716 hres = IUnknown_QueryInterface(unk, &IID_IClassFactory, (void**)&factory);
2717 ok(hres == S_OK, "Could not get IClassFactory interface\n");
2718 IUnknown_Release(unk);
2722 hres = IClassFactory_CreateInstance(factory, NULL, &IID_IInternetProtocol,
2724 IClassFactory_Release(factory);
2725 ok(hres == S_OK, "Could not get IInternetProtocol: %08x\n", hres);
2727 SET_EXPECT(GetBindInfo);
2728 hres = IInternetProtocol_Start(protocol, wrong_url1, &protocol_sink, &bind_info, 0, 0);
2729 ok(hres == MK_E_SYNTAX || hres == INET_E_INVALID_URL,
2730 "Start failed: %08x, expected MK_E_SYNTAX or INET_E_INVALID_URL\n", hres);
2731 CLEAR_CALLED(GetBindInfo);
2733 SET_EXPECT(GetBindInfo);
2734 SET_EXPECT(ReportProgress_DIRECTBIND);
2735 SET_EXPECT(ReportProgress_SENDINGREQUEST);
2736 SET_EXPECT(ReportProgress_MIMETYPEAVAILABLE);
2737 SET_EXPECT(ReportResult);
2738 expect_hrResult = INET_E_RESOURCE_NOT_FOUND;
2740 hres = IInternetProtocol_Start(protocol, wrong_url2, &protocol_sink, &bind_info, 0, 0);
2741 ok(hres == INET_E_RESOURCE_NOT_FOUND ||
2742 hres == INET_E_INVALID_URL, /* win2k3 */
2743 "Start failed: %08x, expected INET_E_RESOURCE_NOT_FOUND or INET_E_INVALID_URL\n", hres);
2745 if (hres == INET_E_RESOURCE_NOT_FOUND) {
2746 CHECK_CALLED(GetBindInfo);
2747 CLEAR_CALLED(ReportProgress_DIRECTBIND);
2748 CHECK_CALLED(ReportProgress_SENDINGREQUEST);
2749 CHECK_CALLED(ReportProgress_MIMETYPEAVAILABLE);
2750 CHECK_CALLED(ReportResult);
2752 CLEAR_CALLED(GetBindInfo);
2753 CLEAR_CALLED(ReportProgress_DIRECTBIND);
2754 CLEAR_CALLED(ReportProgress_SENDINGREQUEST);
2755 CLEAR_CALLED(ReportProgress_MIMETYPEAVAILABLE);
2756 CLEAR_CALLED(ReportResult);
2759 IInternetProtocol_Release(protocol);
2762 static void test_CreateBinding(void)
2764 IInternetProtocol *protocol;
2765 IInternetPriority *priority;
2766 IInternetSession *session;
2767 IWinInetHttpInfo *http_info;
2768 IWinInetInfo *inet_info;
2774 static const WCHAR test_url[] =
2775 {'t','e','s','t',':','/','/','f','i','l','e','.','h','t','m','l',0};
2776 static const WCHAR wsz_test[] = {'t','e','s','t',0};
2778 trace("Testing CreateBinding...\n");
2779 init_test(BIND_TEST, TEST_BINDING);
2781 hres = CoInternetGetSession(0, &session, 0);
2782 ok(hres == S_OK, "CoInternetGetSession failed: %08x\n", hres);
2784 hres = IInternetSession_RegisterNameSpace(session, &ClassFactory, &IID_NULL, wsz_test, 0, NULL, 0);
2785 ok(hres == S_OK, "RegisterNameSpace failed: %08x\n", hres);
2787 hres = IInternetSession_CreateBinding(session, NULL, test_url, NULL, NULL, &protocol, 0);
2788 binding_protocol = protocol;
2789 ok(hres == S_OK, "CreateBinding failed: %08x\n", hres);
2790 ok(protocol != NULL, "protocol == NULL\n");
2792 hres = IInternetProtocol_QueryInterface(protocol, &IID_IInternetBindInfo, (void**)&prot_bind_info);
2793 ok(hres == S_OK, "QueryInterface(IID_IInternetBindInfo) failed: %08x\n", hres);
2795 hres = IInternetProtocol_QueryInterface(protocol, &IID_IInternetProtocolSink, (void**)&binding_sink);
2796 ok(hres == S_OK, "Could not get IInternetProtocolSink: %08x\n", hres);
2798 hres = IInternetProtocol_Start(protocol, test_url, NULL, &bind_info, 0, 0);
2799 ok(hres == E_INVALIDARG, "Start failed: %08x, expected E_INVALIDARG\n", hres);
2800 hres = IInternetProtocol_Start(protocol, test_url, &protocol_sink, NULL, 0, 0);
2801 ok(hres == E_INVALIDARG, "Start failed: %08x, expected E_INVALIDARG\n", hres);
2802 hres = IInternetProtocol_Start(protocol, NULL, &protocol_sink, &bind_info, 0, 0);
2803 ok(hres == E_INVALIDARG, "Start failed: %08x, expected E_INVALIDARG\n", hres);
2805 hres = IInternetProtocol_QueryInterface(protocol, &IID_IInternetPriority, (void**)&priority);
2806 ok(hres == S_OK, "QueryInterface(IID_IInternetPriority) failed: %08x\n", hres);
2809 hres = IInternetPriority_GetPriority(priority, &p);
2810 ok(hres == S_OK, "GetPriority failed: %08x\n", hres);
2811 ok(!p, "p=%d\n", p);
2814 hres = IInternetPriority_SetPriority(priority, 100);
2815 ok(hres == S_OK, "SetPriority failed: %08x\n", hres);
2818 hres = IInternetPriority_GetPriority(priority, &p);
2819 ok(hres == S_OK, "GetPriority failed: %08x\n", hres);
2820 ok(p == 100, "p=%d\n", p);
2822 hres = IInternetProtocol_QueryInterface(protocol, &IID_IWinInetInfo, (void**)&inet_info);
2823 ok(hres == E_NOINTERFACE, "Could not get IWinInetInfo protocol: %08x\n", hres);
2825 SET_EXPECT(QueryService_InternetProtocol);
2826 SET_EXPECT(CreateInstance);
2827 SET_EXPECT(ReportProgress_PROTOCOLCLASSID);
2828 SET_EXPECT(SetPriority);
2831 expect_hrResult = S_OK;
2832 hres = IInternetProtocol_Start(protocol, test_url, &protocol_sink, &bind_info, 0, 0);
2833 ok(hres == S_OK, "Start failed: %08x\n", hres);
2835 CHECK_CALLED(QueryService_InternetProtocol);
2836 CHECK_CALLED(CreateInstance);
2837 CHECK_CALLED(ReportProgress_PROTOCOLCLASSID);
2838 CHECK_CALLED(SetPriority);
2839 CHECK_CALLED(Start);
2841 SET_EXPECT(QueryInterface_IWinInetInfo);
2842 hres = IInternetProtocol_QueryInterface(protocol, &IID_IWinInetInfo, (void**)&inet_info);
2843 ok(hres == E_NOINTERFACE, "Could not get IWinInetInfo protocol: %08x\n", hres);
2844 CHECK_CALLED(QueryInterface_IWinInetInfo);
2846 SET_EXPECT(QueryInterface_IWinInetInfo);
2847 hres = IInternetProtocol_QueryInterface(protocol, &IID_IWinInetInfo, (void**)&inet_info);
2848 ok(hres == E_NOINTERFACE, "Could not get IWinInetInfo protocol: %08x\n", hres);
2849 CHECK_CALLED(QueryInterface_IWinInetInfo);
2851 SET_EXPECT(QueryInterface_IWinInetHttpInfo);
2852 hres = IInternetProtocol_QueryInterface(protocol, &IID_IWinInetHttpInfo, (void**)&http_info);
2853 ok(hres == E_NOINTERFACE, "Could not get IWinInetInfo protocol: %08x\n", hres);
2854 CHECK_CALLED(QueryInterface_IWinInetHttpInfo);
2858 hres = IInternetProtocol_Read(protocol, expect_pv = buf, sizeof(buf), &read);
2859 ok(hres == S_OK, "Read failed: %08x\n", hres);
2860 ok(read == 100, "read = %d\n", read);
2865 hres = IInternetProtocol_Read(protocol, expect_pv = buf, sizeof(buf), &read);
2866 ok(hres == S_FALSE, "Read failed: %08x\n", hres);
2867 ok(!read, "read = %d\n", read);
2871 hres = IInternetPriority_GetPriority(priority, &p);
2872 ok(hres == S_OK, "GetPriority failed: %08x\n", hres);
2873 ok(p == 100, "p=%d\n", p);
2875 hres = IInternetPriority_SetPriority(priority, 101);
2876 ok(hres == S_OK, "SetPriority failed: %08x\n", hres);
2878 SET_EXPECT(Terminate);
2879 hres = IInternetProtocol_Terminate(protocol, 0xdeadbeef);
2880 ok(hres == S_OK, "Terminate failed: %08x\n", hres);
2881 CHECK_CALLED(Terminate);
2883 SET_EXPECT(Continue);
2884 hres = IInternetProtocolSink_Switch(binding_sink, &protocoldata);
2885 ok(hres == S_OK, "Switch failed: %08x\n", hres);
2886 CHECK_CALLED(Continue);
2888 hres = IInternetProtocolSink_ReportProgress(binding_sink,
2889 BINDSTATUS_CACHEFILENAMEAVAILABLE, expect_wsz = emptyW);
2890 ok(hres == S_OK, "ReportProgress(BINDSTATUS_CACHEFILENAMEAVAILABLE) failed: %08x\n", hres);
2892 hres = IInternetProtocolSink_ReportResult(binding_sink, S_OK, ERROR_SUCCESS, NULL);
2893 ok(hres == E_FAIL, "ReportResult failed: %08x, expected E_FAIL\n", hres);
2895 hres = IInternetProtocolSink_ReportData(binding_sink, 0, 0, 0);
2896 ok(hres == S_OK, "ReportData failed: %08x\n", hres);
2898 IInternetProtocolSink_Release(binding_sink);
2899 IInternetPriority_Release(priority);
2900 IInternetBindInfo_Release(prot_bind_info);
2901 IInternetProtocol_Release(protocol);
2903 hres = IInternetSession_UnregisterNameSpace(session, &ClassFactory, wsz_test);
2904 ok(hres == S_OK, "UnregisterNameSpace failed: %08x\n", hres);
2906 IInternetSession_Release(session);
2909 static void test_binding(int prot, DWORD grf_pi, DWORD test_flags)
2911 IInternetProtocol *protocol;
2912 IInternetSession *session;
2918 init_test(prot, test_flags|TEST_BINDING);
2920 hres = CoInternetGetSession(0, &session, 0);
2921 ok(hres == S_OK, "CoInternetGetSession failed: %08x\n", hres);
2923 if(test_flags & TEST_EMULATEPROT) {
2924 hres = IInternetSession_RegisterNameSpace(session, &ClassFactory, &IID_NULL, protocol_names[prot], 0, NULL, 0);
2925 ok(hres == S_OK, "RegisterNameSpace failed: %08x\n", hres);
2928 hres = IInternetSession_CreateBinding(session, NULL, binding_urls[prot], NULL, NULL, &protocol, 0);
2929 binding_protocol = protocol;
2930 ok(hres == S_OK, "CreateBinding failed: %08x\n", hres);
2931 ok(protocol != NULL, "protocol == NULL\n");
2933 hres = IInternetProtocol_QueryInterface(protocol, &IID_IInternetBindInfo, (void**)&prot_bind_info);
2934 ok(hres == S_OK, "QueryInterface(IID_IInternetBindInfo) failed: %08x\n", hres);
2936 hres = IInternetProtocol_QueryInterface(protocol, &IID_IInternetProtocolSink, (void**)&binding_sink);
2937 ok(hres == S_OK, "QueryInterface(IID_IInternetProtocolSink) failed: %08x\n", hres);
2940 SET_EXPECT(QueryService_InternetProtocol);
2941 SET_EXPECT(CreateInstance);
2942 SET_EXPECT(ReportProgress_PROTOCOLCLASSID);
2943 SET_EXPECT(SetPriority);
2946 expect_hrResult = S_OK;
2947 hres = IInternetProtocol_Start(protocol, binding_urls[prot], &protocol_sink, &bind_info, pi, 0);
2948 ok(hres == S_OK, "Start failed: %08x\n", hres);
2950 CHECK_CALLED(QueryService_InternetProtocol);
2951 CHECK_CALLED(CreateInstance);
2952 CHECK_CALLED(ReportProgress_PROTOCOLCLASSID);
2953 CHECK_CALLED(SetPriority);
2954 CHECK_CALLED(Start);
2956 if(prot == HTTP_TEST || prot == HTTPS_TEST) {
2957 while(prot_state < 4) {
2958 WaitForSingleObject(event_complete, INFINITE);
2959 if(mimefilter_test && filtered_protocol) {
2960 SET_EXPECT(Continue);
2961 IInternetProtocol_Continue(filtered_protocol, pdata);
2962 CHECK_CALLED(Continue);
2964 SET_EXPECT(Continue);
2965 IInternetProtocol_Continue(protocol, pdata);
2966 CHECK_CALLED(Continue);
2968 SetEvent(event_complete2);
2971 CHECK_CALLED(ReportData); /* Set in ReportResult */
2972 WaitForSingleObject(event_complete, INFINITE);
2975 SET_EXPECT(MimeFilter_LockRequest);
2977 SET_EXPECT(LockRequest);
2978 hres = IInternetProtocol_LockRequest(protocol, 0);
2979 ok(hres == S_OK, "LockRequest failed: %08x\n", hres);
2981 CHECK_CALLED(MimeFilter_LockRequest);
2983 CHECK_CALLED(LockRequest);
2986 SET_EXPECT(MimeFilter_UnlockRequest);
2988 SET_EXPECT(UnlockRequest);
2989 hres = IInternetProtocol_UnlockRequest(protocol);
2990 ok(hres == S_OK, "UnlockRequest failed: %08x\n", hres);
2992 CHECK_CALLED(MimeFilter_UnlockRequest);
2994 CHECK_CALLED(UnlockRequest);
2998 SET_EXPECT(MimeFilter_Terminate);
3000 SET_EXPECT(Terminate);
3001 hres = IInternetProtocol_Terminate(protocol, 0);
3002 ok(hres == S_OK, "Terminate failed: %08x\n", hres);
3004 CLEAR_CALLED(MimeFilter_Terminate);
3006 CHECK_CALLED(Terminate);
3008 if(filtered_protocol)
3009 IInternetProtocol_Release(filtered_protocol);
3010 IInternetBindInfo_Release(prot_bind_info);
3011 IInternetProtocolSink_Release(binding_sink);
3012 ref = IInternetProtocol_Release(protocol);
3013 ok(!ref, "ref=%u, expected 0\n", ref);
3015 if(test_flags & TEST_EMULATEPROT) {
3016 hres = IInternetSession_UnregisterNameSpace(session, &ClassFactory, protocol_names[prot]);
3017 ok(hres == S_OK, "UnregisterNameSpace failed: %08x\n", hres);
3020 IInternetSession_Release(session);
3023 static void register_filter(void)
3025 IInternetSession *session;
3028 static const WCHAR gzipW[] = {'g','z','i','p',0};
3030 CoInternetGetSession(0, &session, 0);
3032 hres = IInternetSession_RegisterMimeFilter(session, &mimefilter_cf, &IID_IInternetProtocol, gzipW);
3033 ok(hres == S_OK, "RegisterMimeFilter failed: %08x\n", hres);
3035 IInternetSession_Release(session);
3038 START_TEST(protocol)
3040 OleInitialize(NULL);
3042 event_complete = CreateEvent(NULL, FALSE, FALSE, NULL);
3043 event_complete2 = CreateEvent(NULL, FALSE, FALSE, NULL);
3044 event_continue = CreateEvent(NULL, FALSE, FALSE, NULL);
3045 event_continue_done = CreateEvent(NULL, FALSE, FALSE, NULL);
3049 test_file_protocol();
3050 test_http_protocol();
3051 test_https_protocol();
3052 test_ftp_protocol();
3053 test_gopher_protocol();
3055 test_CreateBinding();
3057 bindf &= ~BINDF_FROMURLMON;
3058 trace("Testing file binding (mime verification, emulate prot)...\n");
3059 test_binding(FILE_TEST, PI_MIMEVERIFICATION, TEST_EMULATEPROT);
3060 trace("Testing http binding (mime verification, emulate prot)...\n");
3061 test_binding(HTTP_TEST, PI_MIMEVERIFICATION, TEST_EMULATEPROT);
3062 trace("Testing http binding (mime verification, emulate prot, short read, direct read)...\n");
3063 test_binding(HTTP_TEST, PI_MIMEVERIFICATION, TEST_EMULATEPROT|TEST_SHORT_READ|TEST_DIRECT_READ);
3064 trace("Testing file binding (mime verification, emulate prot, mime filter)...\n");
3065 test_binding(FILE_TEST, PI_MIMEVERIFICATION, TEST_EMULATEPROT|TEST_FILTER);
3066 trace("Testing http binding (mime verification, emulate prot, mime filter)...\n");
3067 test_binding(HTTP_TEST, PI_MIMEVERIFICATION, TEST_EMULATEPROT|TEST_FILTER);
3068 trace("Testing http binding (mime verification, emulate prot, direct read)...\n");
3069 test_binding(HTTP_TEST, PI_MIMEVERIFICATION, TEST_EMULATEPROT|TEST_DIRECT_READ);
3071 CloseHandle(event_complete);
3072 CloseHandle(event_complete2);
3073 CloseHandle(event_continue);
3074 CloseHandle(event_continue_done);