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(ReportResult);
84 DEFINE_EXPECT(GetBindString_ACCEPT_MIMES);
85 DEFINE_EXPECT(GetBindString_USER_AGENT);
86 DEFINE_EXPECT(GetBindString_POST_COOKIE);
87 DEFINE_EXPECT(GetBindString_URL);
88 DEFINE_EXPECT(QueryService_HttpNegotiate);
89 DEFINE_EXPECT(QueryService_InternetProtocol);
90 DEFINE_EXPECT(QueryService_HttpSecurity);
91 DEFINE_EXPECT(BeginningTransaction);
92 DEFINE_EXPECT(GetRootSecurityId);
93 DEFINE_EXPECT(OnResponse);
94 DEFINE_EXPECT(Switch);
95 DEFINE_EXPECT(Continue);
96 DEFINE_EXPECT(CreateInstance);
98 DEFINE_EXPECT(Terminate);
100 DEFINE_EXPECT(SetPriority);
101 DEFINE_EXPECT(LockRequest);
102 DEFINE_EXPECT(UnlockRequest);
103 DEFINE_EXPECT(MimeFilter_CreateInstance);
104 DEFINE_EXPECT(MimeFilter_Start);
105 DEFINE_EXPECT(MimeFilter_ReportProgress);
106 DEFINE_EXPECT(MimeFilter_ReportData);
107 DEFINE_EXPECT(MimeFilter_ReportResult);
108 DEFINE_EXPECT(MimeFilter_Terminate);
109 DEFINE_EXPECT(MimeFilter_LockRequest);
110 DEFINE_EXPECT(MimeFilter_UnlockRequest);
111 DEFINE_EXPECT(MimeFilter_Read);
112 DEFINE_EXPECT(MimeFilter_Switch);
113 DEFINE_EXPECT(MimeFilter_Continue);
115 static const WCHAR wszIndexHtml[] = {'i','n','d','e','x','.','h','t','m','l',0};
116 static const WCHAR index_url[] =
117 {'f','i','l','e',':','i','n','d','e','x','.','h','t','m','l',0};
119 static const WCHAR acc_mimeW[] = {'*','/','*',0};
120 static const WCHAR user_agentW[] = {'W','i','n','e',0};
121 static const WCHAR text_htmlW[] = {'t','e','x','t','/','h','t','m','l',0};
122 static const WCHAR hostW[] = {'w','w','w','.','w','i','n','e','h','q','.','o','r','g',0};
123 static const WCHAR winehq_ipW[] = {'2','0','9','.','4','6','.','2','5','.','1','3','4',0};
124 static const WCHAR emptyW[] = {0};
125 static const WCHAR gzipW[] = {'g','z','i','p',0};
127 static HRESULT expect_hrResult;
128 static LPCWSTR file_name, http_url, expect_wsz;
129 static IInternetProtocol *async_protocol = NULL;
130 static BOOL first_data_notif = FALSE, http_is_first = FALSE,
131 http_post_test = FALSE;
132 static int state = 0, prot_state;
133 static DWORD bindf, ex_priority , pi;
134 static IInternetProtocol *binding_protocol, *filtered_protocol;
135 static IInternetBindInfo *prot_bind_info;
136 static IInternetProtocolSink *binding_sink, *filtered_sink;
137 static void *expect_pv;
138 static HANDLE event_complete, event_complete2;
139 static BOOL binding_test;
140 static PROTOCOLDATA protocoldata, *pdata;
141 static DWORD prot_read, pi, filter_state;
142 static BOOL security_problem = FALSE;
143 static BOOL async_read_pending, mimefilter_test;
154 static const WCHAR protocol_names[][10] = {
157 {'h','t','t','p','s',0},
163 static const WCHAR binding_urls[][130] = {
164 {'f','i','l','e',':','t','e','s','t','.','h','t','m','l',0},
165 {'h','t','t','p',':','/','/','t','e','s','t','/','t','e','s','t','.','h','t','m','l',0},
166 {'h','t','t','p','s',':','/','/','w','w','w','.','c','o','d','e','w','e','a','v','e','r','s',
167 '.','c','o','m','/','t','e','s','t','.','h','t','m','l',0},
168 {'f','t','p',':','/','/','f','t','p','.','w','i','n','e','h','q','.','o','r','g',
169 '/','p','u','b','/','o','t','h','e','r',
170 '/','w','i','n','e','l','o','g','o','.','x','c','f','.','t','a','r','.','b','z','2',0},
171 {'m','k',':','t','e','s','t',0},
172 {'t','e','s','t',':','/','/','f','i','l','e','.','h','t','m','l',0}
175 static const char *debugstr_w(LPCWSTR str)
177 static char buf[512];
180 WideCharToMultiByte(CP_ACP, 0, str, -1, buf, sizeof(buf), NULL, NULL);
184 static const char *debugstr_guid(REFIID riid)
188 sprintf(buf, "{%08X-%04X-%04X-%02X%02X-%02X%02X%02X%02X%02X%02X}",
189 riid->Data1, riid->Data2, riid->Data3, riid->Data4[0],
190 riid->Data4[1], riid->Data4[2], riid->Data4[3], riid->Data4[4],
191 riid->Data4[5], riid->Data4[6], riid->Data4[7]);
196 static int strcmp_wa(LPCWSTR strw, const char *stra)
199 WideCharToMultiByte(CP_ACP, 0, strw, -1, buf, sizeof(buf), NULL, NULL);
200 return lstrcmpA(stra, buf);
203 /* lstrcmpW is not implemented on Win9x */
204 static int strcmp_ww(LPCWSTR strw1, LPCWSTR strw2)
206 CHAR stra1[512], stra2[512];
207 WideCharToMultiByte(CP_ACP, 0, strw1, -1, stra1, MAX_PATH, NULL, NULL);
208 WideCharToMultiByte(CP_ACP, 0, strw2, -1, stra2, MAX_PATH, NULL, NULL);
209 return lstrcmpA(stra1, stra2);
212 static HRESULT WINAPI HttpSecurity_QueryInterface(IHttpSecurity *iface, REFIID riid, void **ppv)
214 if(IsEqualGUID(&IID_IUnknown, riid)
215 || IsEqualGUID(&IID_IHttpSecurity, riid)) {
220 ok(0, "unexpected call\n");
221 return E_NOINTERFACE;
224 static ULONG WINAPI HttpSecurity_AddRef(IHttpSecurity *iface)
229 static ULONG WINAPI HttpSecurity_Release(IHttpSecurity *iface)
234 static HRESULT WINAPI HttpSecurity_GetWindow(IHttpSecurity* iface, REFGUID rguidReason, HWND *phwnd)
236 trace("HttpSecurity_GetWindow\n");
241 static HRESULT WINAPI HttpSecurity_OnSecurityProblem(IHttpSecurity *iface, DWORD dwProblem)
243 trace("Security problem: %u\n", dwProblem);
244 ok(dwProblem == ERROR_INTERNET_SEC_CERT_REV_FAILED, "Expected ERROR_INTERNET_SEC_CERT_REV_FAILED got %u\n", dwProblem);
246 /* Only retry once */
247 if (security_problem)
250 security_problem = TRUE;
251 SET_EXPECT(BeginningTransaction);
256 static IHttpSecurityVtbl HttpSecurityVtbl = {
257 HttpSecurity_QueryInterface,
259 HttpSecurity_Release,
260 HttpSecurity_GetWindow,
261 HttpSecurity_OnSecurityProblem
264 static IHttpSecurity http_security = { &HttpSecurityVtbl };
266 static HRESULT WINAPI HttpNegotiate_QueryInterface(IHttpNegotiate2 *iface, REFIID riid, void **ppv)
268 if(IsEqualGUID(&IID_IUnknown, riid)
269 || IsEqualGUID(&IID_IHttpNegotiate, riid)
270 || IsEqualGUID(&IID_IHttpNegotiate2, riid)) {
275 ok(0, "unexpected call\n");
276 return E_NOINTERFACE;
279 static ULONG WINAPI HttpNegotiate_AddRef(IHttpNegotiate2 *iface)
284 static ULONG WINAPI HttpNegotiate_Release(IHttpNegotiate2 *iface)
289 static HRESULT WINAPI HttpNegotiate_BeginningTransaction(IHttpNegotiate2 *iface, LPCWSTR szURL,
290 LPCWSTR szHeaders, DWORD dwReserved, LPWSTR *pszAdditionalHeaders)
294 static const WCHAR wszHeaders[] =
295 {'C','o','n','t','e','n','t','-','T','y','p','e',':',' ','a','p','p','l','i','c','a','t',
296 'i','o','n','/','x','-','w','w','w','-','f','o','r','m','-','u','r','l','e','n','c','o',
297 'd','e','d','\r','\n',0};
299 CHECK_EXPECT(BeginningTransaction);
302 ok(!strcmp_ww(szURL, binding_urls[tested_protocol]), "szURL != http_url\n");
304 ok(!strcmp_ww(szURL, http_url), "szURL != http_url\n");
305 ok(!dwReserved, "dwReserved=%d, expected 0\n", dwReserved);
306 ok(pszAdditionalHeaders != NULL, "pszAdditionalHeaders == NULL\n");
307 if(pszAdditionalHeaders)
309 ok(*pszAdditionalHeaders == NULL, "*pszAdditionalHeaders != NULL\n");
312 addl_headers = CoTaskMemAlloc(sizeof(wszHeaders));
315 http_post_test = FALSE;
316 skip("Out of memory\n");
317 return E_OUTOFMEMORY;
319 memcpy(addl_headers, wszHeaders, sizeof(wszHeaders));
320 *pszAdditionalHeaders = addl_headers;
327 static HRESULT WINAPI HttpNegotiate_OnResponse(IHttpNegotiate2 *iface, DWORD dwResponseCode,
328 LPCWSTR szResponseHeaders, LPCWSTR szRequestHeaders, LPWSTR *pszAdditionalRequestHeaders)
330 CHECK_EXPECT(OnResponse);
332 ok(dwResponseCode == 200, "dwResponseCode=%d, expected 200\n", dwResponseCode);
333 ok(szResponseHeaders != NULL, "szResponseHeaders == NULL\n");
334 ok(szRequestHeaders == NULL, "szRequestHeaders != NULL\n");
335 ok(pszAdditionalRequestHeaders == NULL, "pszAdditionalHeaders != NULL\n");
340 static HRESULT WINAPI HttpNegotiate_GetRootSecurityId(IHttpNegotiate2 *iface,
341 BYTE *pbSecurityId, DWORD *pcbSecurityId, DWORD_PTR dwReserved)
343 static const BYTE sec_id[] = {'h','t','t','p',':','t','e','s','t',1,0,0,0};
345 CHECK_EXPECT(GetRootSecurityId);
347 ok(!dwReserved, "dwReserved=%ld, expected 0\n", dwReserved);
348 ok(pbSecurityId != NULL, "pbSecurityId == NULL\n");
349 ok(pcbSecurityId != NULL, "pcbSecurityId == NULL\n");
352 ok(*pcbSecurityId == 512, "*pcbSecurityId=%d, expected 512\n", *pcbSecurityId);
353 *pcbSecurityId = sizeof(sec_id);
357 memcpy(pbSecurityId, sec_id, sizeof(sec_id));
362 static IHttpNegotiate2Vtbl HttpNegotiateVtbl = {
363 HttpNegotiate_QueryInterface,
364 HttpNegotiate_AddRef,
365 HttpNegotiate_Release,
366 HttpNegotiate_BeginningTransaction,
367 HttpNegotiate_OnResponse,
368 HttpNegotiate_GetRootSecurityId
371 static IHttpNegotiate2 http_negotiate = { &HttpNegotiateVtbl };
373 static HRESULT QueryInterface(REFIID,void**);
375 static HRESULT WINAPI ServiceProvider_QueryInterface(IServiceProvider *iface, REFIID riid, void **ppv)
377 return QueryInterface(riid, ppv);
380 static ULONG WINAPI ServiceProvider_AddRef(IServiceProvider *iface)
385 static ULONG WINAPI ServiceProvider_Release(IServiceProvider *iface)
390 static HRESULT WINAPI ServiceProvider_QueryService(IServiceProvider *iface, REFGUID guidService,
391 REFIID riid, void **ppv)
393 if(IsEqualGUID(&IID_IHttpNegotiate, guidService) || IsEqualGUID(&IID_IHttpNegotiate2, riid)) {
394 CHECK_EXPECT2(QueryService_HttpNegotiate);
395 return IHttpNegotiate2_QueryInterface(&http_negotiate, riid, ppv);
398 if(IsEqualGUID(&IID_IInternetProtocol, guidService)) {
399 ok(IsEqualGUID(&IID_IInternetProtocol, riid), "unexpected riid\n");
400 CHECK_EXPECT(QueryService_InternetProtocol);
401 return E_NOINTERFACE;
404 if(IsEqualGUID(&IID_IHttpSecurity, guidService)) {
405 ok(IsEqualGUID(&IID_IHttpSecurity, riid), "unexpected riid\n");
406 CHECK_EXPECT(QueryService_HttpSecurity);
407 return IHttpSecurity_QueryInterface(&http_security, riid, ppv);
410 ok(0, "unexpected service %s\n", debugstr_guid(guidService));
414 static const IServiceProviderVtbl ServiceProviderVtbl = {
415 ServiceProvider_QueryInterface,
416 ServiceProvider_AddRef,
417 ServiceProvider_Release,
418 ServiceProvider_QueryService
421 static IServiceProvider service_provider = { &ServiceProviderVtbl };
423 static HRESULT WINAPI ProtocolSink_QueryInterface(IInternetProtocolSink *iface, REFIID riid, void **ppv)
425 return QueryInterface(riid, ppv);
428 static ULONG WINAPI ProtocolSink_AddRef(IInternetProtocolSink *iface)
433 static ULONG WINAPI ProtocolSink_Release(IInternetProtocolSink *iface)
438 static HRESULT WINAPI ProtocolSink_Switch(IInternetProtocolSink *iface, PROTOCOLDATA *pProtocolData)
442 if(tested_protocol == FTP_TEST)
443 CHECK_EXPECT2(Switch);
445 CHECK_EXPECT(Switch);
447 ok(pProtocolData != NULL, "pProtocolData == NULL\n");
449 ok(pProtocolData != &protocoldata, "pProtocolData == &protocoldata\n");
450 ok(pProtocolData->grfFlags == protocoldata.grfFlags, "grfFlags wrong %x/%x\n",
451 pProtocolData->grfFlags, protocoldata.grfFlags );
452 ok(pProtocolData->dwState == protocoldata.dwState, "dwState wrong %x/%x\n",
453 pProtocolData->dwState, protocoldata.dwState );
454 ok(pProtocolData->pData == protocoldata.pData, "pData wrong %p/%p\n",
455 pProtocolData->pData, protocoldata.pData );
456 ok(pProtocolData->cbData == protocoldata.cbData, "cbData wrong %x/%x\n",
457 pProtocolData->cbData, protocoldata.cbData );
460 pdata = pProtocolData;
463 SetEvent(event_complete);
464 WaitForSingleObject(event_complete2, INFINITE);
469 if(tested_protocol == HTTP_TEST || tested_protocol == HTTPS_TEST || tested_protocol == FTP_TEST) {
471 CLEAR_CALLED(ReportProgress_FINDINGRESOURCE);
472 CLEAR_CALLED(ReportProgress_CONNECTING);
473 CLEAR_CALLED(ReportProgress_PROXYDETECTING);
475 CHECK_NOT_CALLED(ReportProgress_FINDINGRESOURCE);
476 /* IE7 does call this */
477 CLEAR_CALLED(ReportProgress_CONNECTING);
480 if(tested_protocol == FTP_TEST)
481 todo_wine CHECK_CALLED(ReportProgress_SENDINGREQUEST);
482 else if (tested_protocol != HTTPS_TEST)
483 CHECK_CALLED(ReportProgress_SENDINGREQUEST);
484 if(tested_protocol == HTTP_TEST || tested_protocol == HTTPS_TEST) {
485 SET_EXPECT(OnResponse);
486 if(tested_protocol == HTTPS_TEST)
487 SET_EXPECT(ReportProgress_ACCEPTRANGES);
488 SET_EXPECT(ReportProgress_MIMETYPEAVAILABLE);
489 if(bindf & BINDF_NEEDFILE)
490 SET_EXPECT(ReportProgress_CACHEFILENAMEAVAILABLE);
494 SET_EXPECT(ReportData);
495 hres = IInternetProtocol_Continue(async_protocol, pProtocolData);
496 ok(hres == S_OK, "Continue failed: %08x\n", hres);
497 if(tested_protocol == FTP_TEST)
498 CLEAR_CALLED(ReportData);
499 else if (! security_problem)
500 CHECK_CALLED(ReportData);
503 if (! security_problem)
506 if(tested_protocol == HTTP_TEST || tested_protocol == HTTPS_TEST) {
507 CHECK_CALLED(OnResponse);
508 if(tested_protocol == HTTPS_TEST)
509 CHECK_CALLED(ReportProgress_ACCEPTRANGES);
510 CHECK_CALLED(ReportProgress_MIMETYPEAVAILABLE);
511 if(bindf & BINDF_NEEDFILE)
512 CHECK_CALLED(ReportProgress_CACHEFILENAMEAVAILABLE);
517 security_problem = FALSE;
518 SET_EXPECT(ReportProgress_CONNECTING);
522 SetEvent(event_complete);
527 static HRESULT WINAPI ProtocolSink_ReportProgress(IInternetProtocolSink *iface, ULONG ulStatusCode,
528 LPCWSTR szStatusText)
530 static const WCHAR null_guid[] = {'{','0','0','0','0','0','0','0','0','-','0','0','0','0','-',
531 '0','0','0','0','-','0','0','0','0','-','0','0','0','0','0','0','0','0','0','0','0','0','}',0};
532 static const WCHAR text_plain[] = {'t','e','x','t','/','p','l','a','i','n',0};
534 switch(ulStatusCode) {
535 case BINDSTATUS_MIMETYPEAVAILABLE:
536 CHECK_EXPECT(ReportProgress_MIMETYPEAVAILABLE);
537 ok(szStatusText != NULL, "szStatusText == NULL\n");
539 if(tested_protocol == BIND_TEST)
540 ok(szStatusText == expect_wsz, "unexpected szStatusText\n");
541 else if (http_post_test)
542 ok(lstrlenW(text_plain) <= lstrlenW(szStatusText) &&
543 !memcmp(szStatusText, text_plain, lstrlenW(text_plain)*sizeof(WCHAR)),
544 "szStatusText != text/plain\n");
545 else if(!mimefilter_test)
546 ok(lstrlenW(text_htmlW) <= lstrlenW(szStatusText) &&
547 !memcmp(szStatusText, text_htmlW, lstrlenW(text_htmlW)*sizeof(WCHAR)),
548 "szStatusText != text/html\n");
551 case BINDSTATUS_DIRECTBIND:
552 CHECK_EXPECT2(ReportProgress_DIRECTBIND);
553 ok(szStatusText == NULL, "szStatusText != NULL\n");
555 case BINDSTATUS_RAWMIMETYPE:
556 CHECK_EXPECT2(ReportProgress_RAWMIMETYPE);
557 ok(szStatusText != NULL, "szStatusText == NULL\n");
559 ok(lstrlenW(szStatusText) < lstrlenW(text_htmlW) ||
560 !memcmp(szStatusText, text_htmlW, lstrlenW(text_htmlW)*sizeof(WCHAR)),
561 "szStatusText != text/html\n");
563 case BINDSTATUS_CACHEFILENAMEAVAILABLE:
564 CHECK_EXPECT(ReportProgress_CACHEFILENAMEAVAILABLE);
565 ok(szStatusText != NULL, "szStatusText == NULL\n");
568 ok(!strcmp_ww(szStatusText, expect_wsz), "unexpected szStatusText\n");
569 else if(tested_protocol == FILE_TEST)
570 ok(!strcmp_ww(szStatusText, file_name), "szStatusText = \"%s\"\n", debugstr_w(szStatusText));
572 ok(szStatusText != NULL, "szStatusText == NULL\n");
575 case BINDSTATUS_FINDINGRESOURCE:
576 CHECK_EXPECT2(ReportProgress_FINDINGRESOURCE);
577 ok(szStatusText != NULL, "szStatusText == NULL\n");
579 case BINDSTATUS_CONNECTING:
580 CHECK_EXPECT2(ReportProgress_CONNECTING);
581 ok(szStatusText != NULL, "szStatusText == NULL\n");
583 case BINDSTATUS_SENDINGREQUEST:
584 CHECK_EXPECT2(ReportProgress_SENDINGREQUEST);
585 if(tested_protocol == FILE_TEST) {
586 ok(szStatusText != NULL, "szStatusText == NULL\n");
588 ok(!*szStatusText, "wrong szStatusText\n");
591 case BINDSTATUS_VERIFIEDMIMETYPEAVAILABLE:
592 CHECK_EXPECT(ReportProgress_VERIFIEDMIMETYPEAVAILABLE);
593 ok(szStatusText != NULL, "szStatusText == NULL\n");
595 ok(!strcmp_ww(szStatusText, text_htmlW), "szStatusText != text/html\n");
597 case BINDSTATUS_PROTOCOLCLASSID:
598 CHECK_EXPECT(ReportProgress_PROTOCOLCLASSID);
599 ok(szStatusText != NULL, "szStatusText == NULL\n");
600 ok(!strcmp_ww(szStatusText, null_guid), "unexpected szStatusText\n");
602 case BINDSTATUS_COOKIE_SENT:
603 CHECK_EXPECT(ReportProgress_COOKIE_SENT);
604 ok(szStatusText == NULL, "szStatusText != NULL\n");
606 case BINDSTATUS_REDIRECTING:
607 CHECK_EXPECT(ReportProgress_REDIRECTING);
608 ok(szStatusText == NULL, "szStatusText = %s\n", debugstr_w(szStatusText));
610 case BINDSTATUS_ENCODING:
611 CHECK_EXPECT(ReportProgress_ENCODING);
612 ok(!strcmp_wa(szStatusText, "gzip"), "szStatusText = %s\n", debugstr_w(szStatusText));
614 case BINDSTATUS_ACCEPTRANGES:
615 CHECK_EXPECT(ReportProgress_ACCEPTRANGES);
616 ok(!szStatusText, "szStatusText = %s\n", debugstr_w(szStatusText));
618 case BINDSTATUS_PROXYDETECTING:
619 CHECK_EXPECT(ReportProgress_PROXYDETECTING);
620 SET_EXPECT(ReportProgress_CONNECTING);
621 ok(!szStatusText, "szStatusText = %s\n", debugstr_w(szStatusText));
623 case BINDSTATUS_LOADINGMIMEHANDLER:
624 CHECK_EXPECT(ReportProgress_LOADINGMIMEHANDLER);
625 ok(!szStatusText, "szStatusText = %s\n", debugstr_w(szStatusText));
627 case BINDSTATUS_DECODING:
628 CHECK_EXPECT(ReportProgress_DECODING);
629 ok(!strcmp_ww(szStatusText, gzipW), "szStatusText = %s\n", debugstr_w(szStatusText));
632 ok(0, "Unexpected status %d\n", ulStatusCode);
638 static HRESULT WINAPI ProtocolSink_ReportData(IInternetProtocolSink *iface, DWORD grfBSCF,
639 ULONG ulProgress, ULONG ulProgressMax)
641 if(!mimefilter_test && tested_protocol == FILE_TEST) {
642 CHECK_EXPECT2(ReportData);
644 ok(ulProgress == ulProgressMax, "ulProgress (%d) != ulProgressMax (%d)\n",
645 ulProgress, ulProgressMax);
646 ok(ulProgressMax == 13, "ulProgressMax=%d, expected 13\n", ulProgressMax);
647 /* BSCF_SKIPDRAINDATAFORFILEURLS added in IE8 */
648 ok((grfBSCF == (BSCF_FIRSTDATANOTIFICATION | BSCF_LASTDATANOTIFICATION)) ||
649 (grfBSCF == (BSCF_FIRSTDATANOTIFICATION | BSCF_LASTDATANOTIFICATION | BSCF_SKIPDRAINDATAFORFILEURLS)),
650 "grcfBSCF = %08x\n", grfBSCF);
651 }else if(!binding_test && (tested_protocol == HTTP_TEST || tested_protocol == HTTPS_TEST || tested_protocol == FTP_TEST)) {
652 if(!(grfBSCF & BSCF_LASTDATANOTIFICATION) || (grfBSCF & BSCF_DATAFULLYAVAILABLE))
653 CHECK_EXPECT(ReportData);
654 else if (http_post_test)
655 ok(ulProgress == 13, "Read %u bytes instead of 13\n", ulProgress);
657 ok(ulProgress, "ulProgress == 0\n");
659 if(first_data_notif) {
660 ok(grfBSCF == BSCF_FIRSTDATANOTIFICATION
661 || grfBSCF == (BSCF_LASTDATANOTIFICATION|BSCF_DATAFULLYAVAILABLE),
662 "grcfBSCF = %08x\n", grfBSCF);
663 first_data_notif = FALSE;
665 ok(grfBSCF == BSCF_INTERMEDIATEDATANOTIFICATION
666 || grfBSCF == (BSCF_LASTDATANOTIFICATION|BSCF_INTERMEDIATEDATANOTIFICATION)
667 || broken(grfBSCF == (BSCF_FIRSTDATANOTIFICATION|BSCF_LASTDATANOTIFICATION)),
668 "grcfBSCF = %08x\n", grfBSCF);
671 if(!(bindf & BINDF_FROMURLMON) &&
672 !(grfBSCF & BSCF_LASTDATANOTIFICATION)) {
676 CHECK_CALLED(ReportProgress_FINDINGRESOURCE);
677 CHECK_CALLED(ReportProgress_CONNECTING);
679 CHECK_NOT_CALLED(ReportProgress_FINDINGRESOURCE);
680 CHECK_NOT_CALLED(ReportProgress_CONNECTING);
682 CHECK_CALLED(ReportProgress_SENDINGREQUEST);
683 CHECK_CALLED(OnResponse);
684 CHECK_CALLED(ReportProgress_RAWMIMETYPE);
686 SetEvent(event_complete);
693 CHECK_EXPECT(ReportData);
695 if(tested_protocol == BIND_TEST)
700 SET_EXPECT(MimeFilter_Read);
703 hres = IInternetProtocol_Read(binding_protocol, expect_pv=buf, sizeof(buf), &read);
705 CHECK_CALLED(MimeFilter_Read);
708 }while(hres == S_OK);
714 static HRESULT WINAPI ProtocolSink_ReportResult(IInternetProtocolSink *iface, HRESULT hrResult,
715 DWORD dwError, LPCWSTR szResult)
717 CHECK_EXPECT(ReportResult);
719 if(tested_protocol == FTP_TEST)
720 ok(hrResult == E_PENDING || hrResult == S_OK, "hrResult = %08x, expected E_PENDING or S_OK\n", hrResult);
722 ok(hrResult == expect_hrResult, "hrResult = %08x, expected: %08x\n",
723 hrResult, expect_hrResult);
724 if(SUCCEEDED(hrResult) || tested_protocol == FTP_TEST)
725 ok(dwError == ERROR_SUCCESS, "dwError = %d, expected ERROR_SUCCESS\n", dwError);
727 ok(dwError != ERROR_SUCCESS ||
728 broken(tested_protocol == MK_TEST), /* Win9x, WinME and NT4 */
729 "dwError == ERROR_SUCCESS\n");
730 ok(!szResult, "szResult != NULL\n");
735 static IInternetProtocolSinkVtbl protocol_sink_vtbl = {
736 ProtocolSink_QueryInterface,
738 ProtocolSink_Release,
740 ProtocolSink_ReportProgress,
741 ProtocolSink_ReportData,
742 ProtocolSink_ReportResult
745 static IInternetProtocolSink protocol_sink = { &protocol_sink_vtbl };
747 static HRESULT WINAPI MimeProtocolSink_QueryInterface(IInternetProtocolSink *iface, REFIID riid, void **ppv)
749 ok(0, "unexpected call\n");
753 static ULONG WINAPI MimeProtocolSink_AddRef(IInternetProtocolSink *iface)
758 static ULONG WINAPI MimeProtocolSink_Release(IInternetProtocolSink *iface)
763 static HRESULT WINAPI MimeProtocolSink_Switch(IInternetProtocolSink *iface, PROTOCOLDATA *pProtocolData)
767 CHECK_EXPECT(MimeFilter_Switch);
770 hres = IInternetProtocolSink_Switch(filtered_sink, pProtocolData);
771 ok(hres == S_OK, "Switch failed: %08x\n", hres);
772 CHECK_CALLED(Switch);
777 static HRESULT WINAPI MimeProtocolSink_ReportProgress(IInternetProtocolSink *iface, ULONG ulStatusCode,
778 LPCWSTR szStatusText)
780 CHECK_EXPECT(MimeFilter_ReportProgress);
784 static HRESULT WINAPI MimeProtocolSink_ReportData(IInternetProtocolSink *iface, DWORD grfBSCF,
785 ULONG ulProgress, ULONG ulProgressMax)
791 CHECK_EXPECT(MimeFilter_ReportData);
793 ok(ulProgress, "ulProgress == 0\n");
797 hres = IInternetProtocol_Read(filtered_protocol, buf, sizeof(buf), &read);
798 if(tested_protocol == HTTP_TEST)
799 ok(hres == S_OK || hres == E_PENDING || hres == S_FALSE, "Read failed: %08x\n", hres);
801 ok(hres == S_OK, "Read failed: %08x\n", hres);
804 SET_EXPECT(ReportProgress_MIMETYPEAVAILABLE);
805 hres = IInternetProtocolSink_ReportProgress(filtered_sink, BINDSTATUS_VERIFIEDMIMETYPEAVAILABLE, text_htmlW);
806 ok(hres == S_OK, "ReportProgress failed: %08x\n", hres);
807 CHECK_CALLED(ReportProgress_MIMETYPEAVAILABLE);
809 /* FIXME: test BINDSTATUS_CACHEFILENAMEAVAILABLE */
812 SET_EXPECT(ReportData);
813 hres = IInternetProtocolSink_ReportData(filtered_sink, grfBSCF, ulProgress, ulProgressMax);
814 ok(hres == S_OK, "ReportData failed: %08x\n", hres);
815 CHECK_CALLED(ReportData);
823 static HRESULT WINAPI MimeProtocolSink_ReportResult(IInternetProtocolSink *iface, HRESULT hrResult,
824 DWORD dwError, LPCWSTR szResult)
828 CHECK_EXPECT(MimeFilter_ReportResult);
830 ok(hrResult == S_OK, "hrResult = %08x\n", hrResult);
831 ok(dwError == ERROR_SUCCESS, "dwError = %u\n", dwError);
832 ok(!szResult, "szResult = %s\n", debugstr_w(szResult));
834 SET_EXPECT(ReportResult);
835 hres = IInternetProtocolSink_ReportResult(filtered_sink, hrResult, dwError, szResult);
836 ok(SUCCEEDED(hres), "ReportResult failed: %08x\n", hres);
837 CHECK_CALLED(ReportResult);
842 static IInternetProtocolSinkVtbl mime_protocol_sink_vtbl = {
843 MimeProtocolSink_QueryInterface,
844 MimeProtocolSink_AddRef,
845 MimeProtocolSink_Release,
846 MimeProtocolSink_Switch,
847 MimeProtocolSink_ReportProgress,
848 MimeProtocolSink_ReportData,
849 MimeProtocolSink_ReportResult
852 static IInternetProtocolSink mime_protocol_sink = { &mime_protocol_sink_vtbl };
854 static HRESULT QueryInterface(REFIID riid, void **ppv)
856 static const IID IID_undocumented = {0x58DFC7D0,0x5381,0x43E5,{0x9D,0x72,0x4C,0xDD,0xE4,0xCB,0x0F,0x1A}};
860 if(IsEqualGUID(&IID_IUnknown, riid) || IsEqualGUID(&IID_IInternetProtocolSink, riid))
861 *ppv = &protocol_sink;
862 if(IsEqualGUID(&IID_IServiceProvider, riid))
863 *ppv = &service_provider;
864 if(IsEqualGUID(&IID_IUriContainer, riid))
865 return E_NOINTERFACE; /* TODO */
867 /* NOTE: IE8 queries for undocumented {58DFC7D0-5381-43E5-9D72-4CDDE4CB0F1A} interface. */
868 if(IsEqualGUID(&IID_undocumented, riid))
869 return E_NOINTERFACE;
874 ok(0, "unexpected call %s\n", debugstr_guid(riid));
875 return E_NOINTERFACE;
878 static HRESULT WINAPI BindInfo_QueryInterface(IInternetBindInfo *iface, REFIID riid, void **ppv)
880 if(IsEqualGUID(&IID_IUnknown, riid) || IsEqualGUID(&IID_IInternetBindInfo, riid)) {
884 return E_NOINTERFACE;
887 static ULONG WINAPI BindInfo_AddRef(IInternetBindInfo *iface)
892 static ULONG WINAPI BindInfo_Release(IInternetBindInfo *iface)
897 static HRESULT WINAPI BindInfo_GetBindInfo(IInternetBindInfo *iface, DWORD *grfBINDF, BINDINFO *pbindinfo)
901 static const CHAR szPostData[] = "mode=Test";
903 CHECK_EXPECT(GetBindInfo);
905 ok(grfBINDF != NULL, "grfBINDF == NULL\n");
906 ok(pbindinfo != NULL, "pbindinfo == NULL\n");
907 ok(pbindinfo->cbSize == sizeof(BINDINFO), "wrong size of pbindinfo: %d\n", pbindinfo->cbSize);
911 *grfBINDF |= BINDF_FROMURLMON;
912 cbSize = pbindinfo->cbSize;
913 memset(pbindinfo, 0, cbSize);
914 pbindinfo->cbSize = cbSize;
918 /* Must be GMEM_FIXED, GMEM_MOVABLE does not work properly
919 * with urlmon on native (Win98 and WinXP) */
920 U(pbindinfo->stgmedData).hGlobal = GlobalAlloc(GPTR, sizeof(szPostData));
921 if (!U(pbindinfo->stgmedData).hGlobal)
923 http_post_test = FALSE;
924 skip("Out of memory\n");
925 return E_OUTOFMEMORY;
927 lstrcpy((LPSTR)U(pbindinfo->stgmedData).hGlobal, szPostData);
928 pbindinfo->cbstgmedData = sizeof(szPostData)-1;
929 pbindinfo->dwBindVerb = BINDVERB_POST;
930 pbindinfo->stgmedData.tymed = TYMED_HGLOBAL;
936 static HRESULT WINAPI BindInfo_GetBindString(IInternetBindInfo *iface, ULONG ulStringType,
937 LPOLESTR *ppwzStr, ULONG cEl, ULONG *pcElFetched)
939 ok(ppwzStr != NULL, "ppwzStr == NULL\n");
940 ok(pcElFetched != NULL, "pcElFetched == NULL\n");
942 switch(ulStringType) {
943 case BINDSTRING_ACCEPT_MIMES:
944 CHECK_EXPECT(GetBindString_ACCEPT_MIMES);
945 ok(cEl == 256, "cEl=%d, expected 256\n", cEl);
947 ok(*pcElFetched == 256, "*pcElFetched=%d, expected 256\n", *pcElFetched);
951 *ppwzStr = CoTaskMemAlloc(sizeof(acc_mimeW));
952 memcpy(*ppwzStr, acc_mimeW, sizeof(acc_mimeW));
955 case BINDSTRING_USER_AGENT:
956 CHECK_EXPECT(GetBindString_USER_AGENT);
957 ok(cEl == 1, "cEl=%d, expected 1\n", cEl);
959 ok(*pcElFetched == 0, "*pcElFetch=%d, expectd 0\n", *pcElFetched);
963 *ppwzStr = CoTaskMemAlloc(sizeof(user_agentW));
964 memcpy(*ppwzStr, user_agentW, sizeof(user_agentW));
967 case BINDSTRING_POST_COOKIE:
968 CHECK_EXPECT(GetBindString_POST_COOKIE);
969 ok(cEl == 1, "cEl=%d, expected 1\n", cEl);
971 ok(*pcElFetched == 0, "*pcElFetch=%d, expectd 0\n", *pcElFetched);
973 case BINDSTRING_URL: {
976 CHECK_EXPECT(GetBindString_URL);
977 ok(cEl == 1, "cEl=%d, expected 1\n", cEl);
978 ok(*pcElFetched == 0, "*pcElFetch=%d, expectd 0\n", *pcElFetched);
981 size = (lstrlenW(binding_urls[tested_protocol])+1)*sizeof(WCHAR);
982 *ppwzStr = CoTaskMemAlloc(size);
983 memcpy(*ppwzStr, binding_urls[tested_protocol], size);
987 ok(0, "unexpected call\n");
993 static IInternetBindInfoVtbl bind_info_vtbl = {
994 BindInfo_QueryInterface,
997 BindInfo_GetBindInfo,
998 BindInfo_GetBindString
1001 static IInternetBindInfo bind_info = { &bind_info_vtbl };
1003 static HRESULT WINAPI InternetPriority_QueryInterface(IInternetPriority *iface,
1004 REFIID riid, void **ppv)
1006 ok(0, "unexpected call\n");
1007 return E_NOINTERFACE;
1010 static ULONG WINAPI InternetPriority_AddRef(IInternetPriority *iface)
1015 static ULONG WINAPI InternetPriority_Release(IInternetPriority *iface)
1020 static HRESULT WINAPI InternetPriority_SetPriority(IInternetPriority *iface, LONG nPriority)
1022 CHECK_EXPECT(SetPriority);
1023 ok(nPriority == ex_priority, "nPriority=%d\n", nPriority);
1027 static HRESULT WINAPI InternetPriority_GetPriority(IInternetPriority *iface, LONG *pnPriority)
1029 ok(0, "unexpected call\n");
1034 static const IInternetPriorityVtbl InternetPriorityVtbl = {
1035 InternetPriority_QueryInterface,
1036 InternetPriority_AddRef,
1037 InternetPriority_Release,
1038 InternetPriority_SetPriority,
1039 InternetPriority_GetPriority
1042 static IInternetPriority InternetPriority = { &InternetPriorityVtbl };
1044 static ULONG WINAPI Protocol_AddRef(IInternetProtocol *iface)
1049 static ULONG WINAPI Protocol_Release(IInternetProtocol *iface)
1054 static HRESULT WINAPI Protocol_Abort(IInternetProtocol *iface, HRESULT hrReason,
1057 ok(0, "unexpected call\n");
1061 static HRESULT WINAPI Protocol_Suspend(IInternetProtocol *iface)
1063 ok(0, "unexpected call\n");
1067 static HRESULT WINAPI Protocol_Resume(IInternetProtocol *iface)
1069 ok(0, "unexpected call\n");
1073 static HRESULT WINAPI Protocol_Seek(IInternetProtocol *iface,
1074 LARGE_INTEGER dlibMove, DWORD dwOrigin, ULARGE_INTEGER *plibNewPosition)
1076 ok(0, "unexpected call\n");
1080 static HRESULT WINAPI ProtocolEmul_QueryInterface(IInternetProtocol *iface, REFIID riid, void **ppv)
1082 if(IsEqualGUID(&IID_IUnknown, riid) || IsEqualGUID(&IID_IInternetProtocol, riid)) {
1087 if(IsEqualGUID(&IID_IInternetProtocolEx, riid)) {
1088 trace("IID_IInternetProtocolEx not supported\n");
1090 return E_NOINTERFACE;
1093 if(IsEqualGUID(&IID_IInternetPriority, riid)) {
1094 *ppv = &InternetPriority;
1098 ok(0, "unexpected riid %s\n", debugstr_guid(riid));
1100 return E_NOINTERFACE;
1103 static DWORD WINAPI thread_proc(PVOID arg)
1107 memset(&protocoldata, -1, sizeof(protocoldata));
1111 SET_EXPECT(ReportProgress_FINDINGRESOURCE);
1112 hres = IInternetProtocolSink_ReportProgress(binding_sink,
1113 BINDSTATUS_FINDINGRESOURCE, hostW);
1114 CHECK_CALLED(ReportProgress_FINDINGRESOURCE);
1115 ok(hres == S_OK, "ReportProgress failed: %08x\n", hres);
1117 SET_EXPECT(ReportProgress_CONNECTING);
1118 hres = IInternetProtocolSink_ReportProgress(binding_sink,
1119 BINDSTATUS_CONNECTING, winehq_ipW);
1120 CHECK_CALLED(ReportProgress_CONNECTING);
1121 ok(hres == S_OK, "ReportProgress failed: %08x\n", hres);
1123 SET_EXPECT(ReportProgress_SENDINGREQUEST);
1124 hres = IInternetProtocolSink_ReportProgress(binding_sink,
1125 BINDSTATUS_SENDINGREQUEST, NULL);
1126 CHECK_CALLED(ReportProgress_SENDINGREQUEST);
1127 ok(hres == S_OK, "ReportProgress failed: %08x\n", hres);
1131 hres = IInternetProtocolSink_Switch(binding_sink, &protocoldata);
1132 CHECK_CALLED(Switch);
1133 ok(hres == S_OK, "Switch failed: %08x\n", hres);
1137 SET_EXPECT(MimeFilter_Switch);
1140 hres = IInternetProtocolSink_Switch(binding_sink, &protocoldata);
1141 ok(hres == S_OK, "Switch failed: %08x\n", hres);
1143 CHECK_CALLED(MimeFilter_Switch);
1145 CHECK_CALLED(Switch);
1149 SET_EXPECT(MimeFilter_Switch);
1152 hres = IInternetProtocolSink_Switch(binding_sink, &protocoldata);
1153 ok(hres == S_OK, "Switch failed: %08x\n", hres);
1155 CHECK_CALLED(MimeFilter_Switch);
1157 CHECK_CALLED(Switch);
1161 SET_EXPECT(MimeFilter_Switch);
1164 hres = IInternetProtocolSink_Switch(binding_sink, &protocoldata);
1165 ok(hres == S_OK, "Switch failed: %08x\n", hres);
1167 CHECK_CALLED(MimeFilter_Switch);
1169 CHECK_CALLED(Switch);
1171 SetEvent(event_complete);
1176 static HRESULT WINAPI ProtocolEmul_Start(IInternetProtocol *iface, LPCWSTR szUrl,
1177 IInternetProtocolSink *pOIProtSink, IInternetBindInfo *pOIBindInfo,
1178 DWORD grfPI, HANDLE_PTR dwReserved)
1180 BINDINFO bindinfo, exp_bindinfo;
1184 CHECK_EXPECT(Start);
1186 ok(pOIProtSink != NULL, "pOIProtSink == NULL\n");
1187 ok(pOIBindInfo != NULL, "pOIBindInfo == NULL\n");
1188 ok(pOIProtSink != &protocol_sink, "unexpected pOIProtSink\n");
1189 ok(pOIBindInfo != &bind_info, "unexpected pOIBindInfo\n");
1190 ok(!grfPI, "grfPI = %x\n", grfPI);
1191 ok(!dwReserved, "dwReserved = %lx\n", dwReserved);
1194 ok(pOIProtSink == binding_sink, "pOIProtSink != binding_sink\n");
1196 memset(&bindinfo, 0, sizeof(bindinfo));
1197 bindinfo.cbSize = sizeof(bindinfo);
1198 memcpy(&exp_bindinfo, &bindinfo, sizeof(bindinfo));
1199 SET_EXPECT(GetBindInfo);
1200 hres = IInternetBindInfo_GetBindInfo(pOIBindInfo, &cbindf, &bindinfo);
1201 ok(hres == S_OK, "GetBindInfo failed: %08x\n", hres);
1202 CHECK_CALLED(GetBindInfo);
1203 ok(cbindf == (bindf|BINDF_FROMURLMON), "bindf = %x, expected %x\n",
1204 cbindf, (bindf|BINDF_FROMURLMON));
1205 ok(!memcmp(&exp_bindinfo, &bindinfo, sizeof(bindinfo)), "unexpected bindinfo\n");
1206 ReleaseBindInfo(&bindinfo);
1208 SET_EXPECT(ReportProgress_SENDINGREQUEST);
1209 hres = IInternetProtocolSink_ReportProgress(pOIProtSink, BINDSTATUS_SENDINGREQUEST, emptyW);
1210 ok(hres == S_OK, "ReportProgress(BINDSTATUS_SENDINGREQUEST) failed: %08x\n", hres);
1211 CHECK_CALLED(ReportProgress_SENDINGREQUEST);
1213 if(tested_protocol == HTTP_TEST || tested_protocol == HTTPS_TEST) {
1214 IServiceProvider *service_provider;
1215 IHttpNegotiate *http_negotiate;
1216 IHttpNegotiate2 *http_negotiate2;
1217 LPWSTR ua = (LPWSTR)0xdeadbeef, accept_mimes[256];
1218 LPWSTR additional_headers = NULL;
1220 DWORD fetched = 0, size = 100;
1223 SET_EXPECT(GetBindString_USER_AGENT);
1224 hres = IInternetBindInfo_GetBindString(pOIBindInfo, BINDSTRING_USER_AGENT,
1226 CHECK_CALLED(GetBindString_USER_AGENT);
1227 ok(hres == S_OK, "GetBindString(BINDSTRING_USER_AGETNT) failed: %08x\n", hres);
1228 ok(fetched == 1, "fetched = %d, expected 254\n", fetched);
1229 ok(ua != NULL, "ua = %p\n", ua);
1230 ok(!strcmp_ww(ua, user_agentW), "unexpected user agent %s\n", debugstr_w(ua));
1234 SET_EXPECT(GetBindString_ACCEPT_MIMES);
1235 hres = IInternetBindInfo_GetBindString(pOIBindInfo, BINDSTRING_ACCEPT_MIMES,
1236 accept_mimes, 256, &fetched);
1237 CHECK_CALLED(GetBindString_ACCEPT_MIMES);
1240 "GetBindString(BINDSTRING_ACCEPT_MIMES) failed: %08x\n", hres);
1241 ok(fetched == 1, "fetched = %d, expected 1\n", fetched);
1242 ok(!strcmp_ww(acc_mimeW, accept_mimes[0]), "unexpected mimes %s\n", debugstr_w(accept_mimes[0]));
1244 hres = IInternetBindInfo_QueryInterface(pOIBindInfo, &IID_IServiceProvider,
1245 (void**)&service_provider);
1246 ok(hres == S_OK, "QueryInterface failed: %08x\n", hres);
1248 SET_EXPECT(QueryService_HttpNegotiate);
1249 hres = IServiceProvider_QueryService(service_provider, &IID_IHttpNegotiate,
1250 &IID_IHttpNegotiate, (void**)&http_negotiate);
1251 CHECK_CALLED(QueryService_HttpNegotiate);
1252 ok(hres == S_OK, "QueryService failed: %08x\n", hres);
1254 SET_EXPECT(BeginningTransaction);
1255 hres = IHttpNegotiate_BeginningTransaction(http_negotiate, binding_urls[tested_protocol],
1256 NULL, 0, &additional_headers);
1257 CHECK_CALLED(BeginningTransaction);
1258 IHttpNegotiate_Release(http_negotiate);
1259 ok(hres == S_OK, "BeginningTransction failed: %08x\n", hres);
1260 ok(additional_headers == NULL, "additional_headers=%p\n", additional_headers);
1262 SET_EXPECT(QueryService_HttpNegotiate);
1263 hres = IServiceProvider_QueryService(service_provider, &IID_IHttpNegotiate2,
1264 &IID_IHttpNegotiate2, (void**)&http_negotiate2);
1265 CHECK_CALLED(QueryService_HttpNegotiate);
1266 ok(hres == S_OK, "QueryService failed: %08x\n", hres);
1269 SET_EXPECT(GetRootSecurityId);
1270 hres = IHttpNegotiate2_GetRootSecurityId(http_negotiate2, sec_id, &size, 0);
1271 CHECK_CALLED(GetRootSecurityId);
1272 IHttpNegotiate2_Release(http_negotiate2);
1273 ok(hres == E_FAIL, "GetRootSecurityId failed: %08x, expected E_FAIL\n", hres);
1274 ok(size == 13, "size=%d\n", size);
1276 IServiceProvider_Release(service_provider);
1278 CreateThread(NULL, 0, thread_proc, NULL, 0, &tid);
1283 SET_EXPECT(ReportProgress_CACHEFILENAMEAVAILABLE);
1284 hres = IInternetProtocolSink_ReportProgress(pOIProtSink,
1285 BINDSTATUS_CACHEFILENAMEAVAILABLE, expect_wsz = emptyW);
1286 ok(hres == S_OK, "ReportProgress(BINDSTATUS_CACHEFILENAMEAVAILABLE) failed: %08x\n", hres);
1287 CHECK_CALLED(ReportProgress_CACHEFILENAMEAVAILABLE);
1289 if(mimefilter_test) {
1290 SET_EXPECT(MimeFilter_CreateInstance);
1291 SET_EXPECT(MimeFilter_Start);
1292 SET_EXPECT(ReportProgress_LOADINGMIMEHANDLER);
1294 SET_EXPECT(ReportProgress_MIMETYPEAVAILABLE);
1295 hres = IInternetProtocolSink_ReportProgress(pOIProtSink, BINDSTATUS_VERIFIEDMIMETYPEAVAILABLE,
1296 mimefilter_test ? gzipW : (expect_wsz = text_htmlW));
1298 "ReportProgress(BINDSTATUS_VERIFIEDMIMETYPEAVAILABLE) failed: %08x\n", hres);
1299 if(mimefilter_test) {
1300 CHECK_CALLED(MimeFilter_CreateInstance);
1301 CHECK_CALLED(MimeFilter_Start);
1302 CHECK_CALLED(ReportProgress_LOADINGMIMEHANDLER);
1303 todo_wine CHECK_CALLED(ReportProgress_MIMETYPEAVAILABLE);
1305 CHECK_CALLED(ReportProgress_MIMETYPEAVAILABLE);
1309 SET_EXPECT(MimeFilter_ReportData);
1311 SET_EXPECT(ReportData);
1312 hres = IInternetProtocolSink_ReportData(pOIProtSink,
1313 BSCF_FIRSTDATANOTIFICATION | BSCF_LASTDATANOTIFICATION, 13, 13);
1314 ok(hres == S_OK, "ReportData failed: %08x\n", hres);
1316 CHECK_CALLED(MimeFilter_ReportData);
1318 CHECK_CALLED(ReportData);
1320 if(tested_protocol == BIND_TEST) {
1321 hres = IInternetProtocol_Terminate(binding_protocol, 0);
1322 ok(hres == E_FAIL, "Termiante failed: %08x\n", hres);
1326 SET_EXPECT(MimeFilter_ReportResult);
1328 SET_EXPECT(ReportResult);
1329 hres = IInternetProtocolSink_ReportResult(pOIProtSink, S_OK, 0, NULL);
1330 ok(hres == S_OK, "ReportResult failed: %08x\n", hres);
1332 CHECK_CALLED(MimeFilter_ReportResult);
1334 CHECK_CALLED(ReportResult);
1339 static HRESULT WINAPI ProtocolEmul_Continue(IInternetProtocol *iface,
1340 PROTOCOLDATA *pProtocolData)
1345 CHECK_EXPECT(Continue);
1347 ok(pProtocolData != NULL, "pProtocolData == NULL\n");
1348 if(!pProtocolData || tested_protocol == BIND_TEST)
1351 ok(pProtocolData != &protocoldata, "pProtocolData == &protocoldata\n");
1352 ok(pProtocolData->grfFlags == protocoldata.grfFlags, "grfFlags wrong %x/%x\n",
1353 pProtocolData->grfFlags, protocoldata.grfFlags );
1354 ok(pProtocolData->dwState == protocoldata.dwState, "dwState wrong %x/%x\n",
1355 pProtocolData->dwState, protocoldata.dwState );
1356 ok(pProtocolData->pData == protocoldata.pData, "pData wrong %p/%p\n",
1357 pProtocolData->pData, protocoldata.pData );
1358 ok(pProtocolData->cbData == protocoldata.cbData, "cbData wrong %x/%x\n",
1359 pProtocolData->cbData, protocoldata.cbData );
1362 switch(prot_state) {
1364 IServiceProvider *service_provider;
1365 IHttpNegotiate *http_negotiate;
1366 static WCHAR header[] = {'?',0};
1368 hres = IInternetProtocolSink_QueryInterface(binding_sink, &IID_IServiceProvider,
1369 (void**)&service_provider);
1370 ok(hres == S_OK, "Could not get IServiceProvicder\n");
1372 SET_EXPECT(QueryService_HttpNegotiate);
1373 hres = IServiceProvider_QueryService(service_provider, &IID_IHttpNegotiate,
1374 &IID_IHttpNegotiate, (void**)&http_negotiate);
1375 IServiceProvider_Release(service_provider);
1376 CHECK_CALLED(QueryService_HttpNegotiate);
1377 ok(hres == S_OK, "Could not get IHttpNegotiate\n");
1379 SET_EXPECT(OnResponse);
1380 hres = IHttpNegotiate_OnResponse(http_negotiate, 200, header, NULL, NULL);
1381 IHttpNegotiate_Release(http_negotiate);
1382 CHECK_CALLED(OnResponse);
1383 IHttpNegotiate_Release(http_negotiate);
1384 ok(hres == S_OK, "OnResponse failed: %08x\n", hres);
1386 if(mimefilter_test) {
1387 SET_EXPECT(MimeFilter_CreateInstance);
1388 SET_EXPECT(MimeFilter_Start);
1389 SET_EXPECT(ReportProgress_LOADINGMIMEHANDLER);
1390 }else if(!(pi & PI_MIMEVERIFICATION)) {
1391 SET_EXPECT(ReportProgress_MIMETYPEAVAILABLE);
1393 hres = IInternetProtocolSink_ReportProgress(binding_sink,
1394 BINDSTATUS_MIMETYPEAVAILABLE, mimefilter_test ? gzipW : text_htmlW);
1395 if(mimefilter_test) {
1396 CHECK_CALLED(MimeFilter_CreateInstance);
1397 CHECK_CALLED(MimeFilter_Start);
1398 CHECK_CALLED(ReportProgress_LOADINGMIMEHANDLER);
1399 }else if(!(pi & PI_MIMEVERIFICATION)) {
1400 CHECK_CALLED(ReportProgress_MIMETYPEAVAILABLE);
1403 "ReportProgress(BINDSTATUS_MIMETYPEAVAILABLE) failed: %08x\n", hres);
1405 bscf |= BSCF_FIRSTDATANOTIFICATION;
1410 bscf = BSCF_INTERMEDIATEDATANOTIFICATION;
1415 if(mimefilter_test) {
1416 SET_EXPECT(MimeFilter_ReportData);
1417 }else if(pi & PI_MIMEVERIFICATION) {
1422 SET_EXPECT(ReportProgress_MIMETYPEAVAILABLE);
1425 SET_EXPECT(ReportData);
1427 SET_EXPECT(ReportData);
1430 hres = IInternetProtocolSink_ReportData(binding_sink, bscf, 100, 400);
1431 ok(hres == S_OK, "ReportData failed: %08x\n", hres);
1433 if(mimefilter_test) {
1434 SET_EXPECT(MimeFilter_ReportData);
1435 }else if(pi & PI_MIMEVERIFICATION) {
1440 CHECK_CALLED(ReportProgress_MIMETYPEAVAILABLE);
1443 CHECK_CALLED(ReportData);
1452 static HRESULT WINAPI ProtocolEmul_Terminate(IInternetProtocol *iface, DWORD dwOptions)
1454 CHECK_EXPECT(Terminate);
1455 ok(!dwOptions, "dwOptions=%d\n", dwOptions);
1459 static HRESULT WINAPI ProtocolEmul_Read(IInternetProtocol *iface, void *pv,
1460 ULONG cb, ULONG *pcbRead)
1462 if(mimefilter_test) {
1463 CHECK_EXPECT2(Read);
1464 }else if((pi & PI_MIMEVERIFICATION)) {
1465 CHECK_EXPECT2(Read);
1467 if(prot_read < 300) {
1468 ok(pv != expect_pv, "pv == expect_pv\n");
1470 ok(cb == 2048-prot_read, "cb=%d\n", cb);
1472 ok(cb == 700, "cb=%d\n", cb);
1474 ok(expect_pv <= pv && (BYTE*)pv < (BYTE*)expect_pv + cb, "pv != expect_pv\n");
1479 ok(pv == expect_pv, "pv != expect_pv\n");
1480 ok(cb == 1000, "cb=%d\n", cb);
1481 ok(!*pcbRead, "*pcbRead = %d\n", *pcbRead);
1483 ok(pcbRead != NULL, "pcbRead == NULL\n");
1485 if(prot_state == 3) {
1489 SET_EXPECT(MimeFilter_ReportResult);
1491 SET_EXPECT(ReportResult);
1492 hres = IInternetProtocolSink_ReportResult(binding_sink, S_OK, ERROR_SUCCESS, NULL);
1493 ok(hres == S_OK, "ReportResult failed: %08x\n", hres);
1495 CHECK_CALLED(MimeFilter_ReportResult);
1497 CHECK_CALLED(ReportResult);
1502 if((async_read_pending = !async_read_pending)) {
1504 return tested_protocol == HTTP_TEST || tested_protocol == HTTPS_TEST ? E_PENDING : S_FALSE;
1507 memset(pv, 'x', 100);
1508 prot_read += *pcbRead = 100;
1512 static HRESULT WINAPI ProtocolEmul_LockRequest(IInternetProtocol *iface, DWORD dwOptions)
1514 CHECK_EXPECT(LockRequest);
1515 ok(dwOptions == 0, "dwOptions=%x\n", dwOptions);
1519 static HRESULT WINAPI ProtocolEmul_UnlockRequest(IInternetProtocol *iface)
1521 CHECK_EXPECT(UnlockRequest);
1525 static const IInternetProtocolVtbl ProtocolVtbl = {
1526 ProtocolEmul_QueryInterface,
1530 ProtocolEmul_Continue,
1532 ProtocolEmul_Terminate,
1537 ProtocolEmul_LockRequest,
1538 ProtocolEmul_UnlockRequest
1541 static IInternetProtocol Protocol = { &ProtocolVtbl };
1543 static HRESULT WINAPI MimeProtocol_QueryInterface(IInternetProtocol *iface, REFIID riid, void **ppv)
1545 if(IsEqualGUID(&IID_IUnknown, riid) || IsEqualGUID(&IID_IInternetProtocol, riid)) {
1550 if(IsEqualGUID(&IID_IInternetProtocolSink, riid)) {
1551 *ppv = &mime_protocol_sink;
1555 ok(0, "unexpected riid %s\n", debugstr_guid(riid));
1557 return E_NOINTERFACE;
1560 static HRESULT WINAPI MimeProtocol_Start(IInternetProtocol *iface, LPCWSTR szUrl,
1561 IInternetProtocolSink *pOIProtSink, IInternetBindInfo *pOIBindInfo,
1562 DWORD grfPI, HANDLE_PTR dwReserved)
1564 PROTOCOLFILTERDATA *data;
1565 LPOLESTR url_str = NULL;
1571 CHECK_EXPECT(MimeFilter_Start);
1573 ok(!strcmp_ww(szUrl, gzipW), "wrong url %s\n", debugstr_w(szUrl));
1574 ok(grfPI == (PI_FILTER_MODE|PI_FORCE_ASYNC), "grfPI=%x, expected PI_FILTER_MODE|PI_FORCE_ASYNC\n", grfPI);
1575 ok(dwReserved, "dwReserved == 0\n");
1576 ok(pOIProtSink != NULL, "pOIProtSink == NULL\n");
1577 ok(pOIBindInfo != NULL, "pOIBindInfo == NULL\n");
1580 ok(pOIProtSink != binding_sink, "pOIProtSink == protocol_sink\n");
1581 ok(pOIBindInfo == prot_bind_info, "pOIBindInfo != bind_info\n");
1583 ok(pOIProtSink == &protocol_sink, "pOIProtSink != protocol_sink\n");
1584 ok(pOIBindInfo == &bind_info, "pOIBindInfo != bind_info\n");
1587 data = (void*)dwReserved;
1588 ok(data->cbSize == sizeof(*data), "data->cbSize = %d\n", data->cbSize);
1589 ok(!data->pProtocolSink, "data->pProtocolSink != NULL\n");
1590 ok(data->pProtocol != NULL, "data->pProtocol == NULL\n");
1591 ok(!data->pUnk, "data->pUnk != NULL\n");
1592 ok(!data->dwFilterFlags, "data->dwProtocolFlags = %x\n", data->dwFilterFlags);
1594 IInternetProtocolSink *prot_sink;
1596 IInternetProtocol_QueryInterface(data->pProtocol, &IID_IInternetProtocolSink, (void**)&prot_sink);
1597 ok(prot_sink == pOIProtSink, "QI(data->pProtocol, IID_IInternetProtocolSink) != pOIProtSink\n");
1598 IInternetProtocolSink_Release(prot_sink);
1600 ok(data->pProtocol != binding_protocol, "data->pProtocol == binding_protocol\n");
1602 filtered_protocol = data->pProtocol;
1603 IInternetProtocol_AddRef(filtered_protocol);
1605 IInternetProtocol *prot;
1607 IInternetProtocol_QueryInterface(data->pProtocol, &IID_IInternetProtocol, (void**)&prot);
1608 ok(prot == async_protocol, "QI(data->pProtocol, IID_IInternetProtocol) != async_protocol\n");
1609 IInternetProtocol_Release(prot);
1611 ok(data->pProtocol != async_protocol, "data->pProtocol == async_protocol\n");
1614 filtered_sink = pOIProtSink;
1616 SET_EXPECT(ReportProgress_DECODING);
1617 hres = IInternetProtocolSink_ReportProgress(pOIProtSink, BINDSTATUS_DECODING, gzipW);
1618 ok(hres == S_OK, "ReportProgress(BINDSTATUS_DECODING) failed: %08x\n", hres);
1619 CHECK_CALLED(ReportProgress_DECODING);
1621 SET_EXPECT(GetBindInfo);
1622 memset(&bindinfo, 0, sizeof(bindinfo));
1623 bindinfo.cbSize = sizeof(bindinfo);
1624 hres = IInternetBindInfo_GetBindInfo(pOIBindInfo, &cbindf, &bindinfo);
1625 ok(hres == S_OK, "GetBindInfo failed: %08x\n", hres);
1626 ok(cbindf == bindf, "cbindf = %x\n", cbindf);
1627 CHECK_CALLED(GetBindInfo);
1629 SET_EXPECT(GetBindString_URL);
1630 hres = IInternetBindInfo_GetBindString(pOIBindInfo, BINDSTRING_URL, &url_str, 1, &fetched);
1631 ok(hres == S_OK, "GetBindString(BINDSTRING_URL) failed: %08x\n", hres);
1632 ok(fetched == 1, "fetched = %d\n", fetched);
1633 ok(!strcmp_ww(url_str, binding_urls[tested_protocol]), "wrong url_str %s\n", debugstr_w(url_str));
1634 CoTaskMemFree(url_str);
1635 CHECK_CALLED(GetBindString_URL);
1640 static HRESULT WINAPI Protocol_Continue(IInternetProtocol *iface,
1641 PROTOCOLDATA *pProtocolData)
1643 CHECK_EXPECT(MimeFilter_Continue);
1647 static HRESULT WINAPI MimeProtocol_Terminate(IInternetProtocol *iface, DWORD dwOptions)
1651 CHECK_EXPECT(MimeFilter_Terminate);
1653 ok(!dwOptions, "dwOptions = %x\n", dwOptions);
1655 SET_EXPECT(Terminate);
1656 hres = IInternetProtocol_Terminate(filtered_protocol, dwOptions);
1657 ok(hres == S_OK, "Terminate failed: %08x\n", hres);
1658 CHECK_CALLED(Terminate);
1663 static HRESULT WINAPI MimeProtocol_Read(IInternetProtocol *iface, void *pv,
1664 ULONG cb, ULONG *pcbRead)
1670 CHECK_EXPECT(MimeFilter_Read);
1672 ok(pv != NULL, "pv == NULL\n");
1673 ok(cb != 0, "cb == 0\n");
1674 ok(pcbRead != NULL, "pcbRead == NULL\n");
1677 hres = IInternetProtocol_Read(filtered_protocol, buf, sizeof(buf), &read);
1678 ok(hres == S_OK || hres == S_FALSE || hres == E_PENDING, "Read failed: %08x\n", hres);
1682 ok(*pcbRead == 0, "*pcbRead=%d, expected 0\n", *pcbRead);
1686 memset(pv, 'x', read);
1690 static HRESULT WINAPI MimeProtocol_LockRequest(IInternetProtocol *iface, DWORD dwOptions)
1694 CHECK_EXPECT(MimeFilter_LockRequest);
1696 ok(!dwOptions, "dwOptions = %x\n", dwOptions);
1698 SET_EXPECT(LockRequest);
1699 hres = IInternetProtocol_LockRequest(filtered_protocol, dwOptions);
1700 ok(hres == S_OK, "LockRequest failed: %08x\n", hres);
1701 CHECK_CALLED(LockRequest);
1706 static HRESULT WINAPI MimeProtocol_UnlockRequest(IInternetProtocol *iface)
1710 CHECK_EXPECT(MimeFilter_UnlockRequest);
1712 SET_EXPECT(UnlockRequest);
1713 hres = IInternetProtocol_UnlockRequest(filtered_protocol);
1714 ok(hres == S_OK, "UnlockRequest failed: %08x\n", hres);
1715 CHECK_CALLED(UnlockRequest);
1720 static const IInternetProtocolVtbl MimeProtocolVtbl = {
1721 MimeProtocol_QueryInterface,
1727 MimeProtocol_Terminate,
1732 MimeProtocol_LockRequest,
1733 MimeProtocol_UnlockRequest
1736 static IInternetProtocol MimeProtocol = { &MimeProtocolVtbl };
1738 static HRESULT WINAPI ClassFactory_QueryInterface(IClassFactory *iface, REFIID riid, void **ppv)
1740 ok(0, "unexpected call\n");
1741 return E_NOINTERFACE;
1744 static ULONG WINAPI ClassFactory_AddRef(IClassFactory *iface)
1749 static ULONG WINAPI ClassFactory_Release(IClassFactory *iface)
1754 static HRESULT WINAPI ClassFactory_CreateInstance(IClassFactory *iface, IUnknown *pOuter,
1755 REFIID riid, void **ppv)
1757 CHECK_EXPECT(CreateInstance);
1759 ok(pOuter == (IUnknown*)prot_bind_info, "pOuter != protocol_unk\n");
1760 ok(IsEqualGUID(&IID_IUnknown, riid), "unexpected riid %s\n", debugstr_guid(riid));
1761 ok(ppv != NULL, "ppv == NULL\n");
1767 static HRESULT WINAPI ClassFactory_LockServer(IClassFactory *iface, BOOL dolock)
1769 ok(0, "unexpected call\n");
1773 static const IClassFactoryVtbl ClassFactoryVtbl = {
1774 ClassFactory_QueryInterface,
1775 ClassFactory_AddRef,
1776 ClassFactory_Release,
1777 ClassFactory_CreateInstance,
1778 ClassFactory_LockServer
1781 static IClassFactory ClassFactory = { &ClassFactoryVtbl };
1783 static HRESULT WINAPI MimeFilter_CreateInstance(IClassFactory *iface, IUnknown *outer, REFIID riid, void **ppv)
1785 CHECK_EXPECT(MimeFilter_CreateInstance);
1787 ok(!outer, "outer = %p\n", outer);
1788 ok(IsEqualGUID(&IID_IInternetProtocol, riid), "unexpected riid %s\n", debugstr_guid(riid));
1790 *ppv = &MimeProtocol;
1794 static const IClassFactoryVtbl MimeFilterCFVtbl = {
1795 ClassFactory_QueryInterface,
1796 ClassFactory_AddRef,
1797 ClassFactory_Release,
1798 MimeFilter_CreateInstance,
1799 ClassFactory_LockServer
1802 static IClassFactory mimefilter_cf = { &MimeFilterCFVtbl };
1804 #define TEST_BINDING 1
1805 #define TEST_FILTER 2
1807 static void init_test(int prot, DWORD flags)
1809 tested_protocol = prot;
1810 binding_test = (flags & TEST_BINDING) != 0;
1811 first_data_notif = TRUE;
1814 async_read_pending = TRUE;
1815 mimefilter_test = (flags & TEST_FILTER) != 0;
1817 ResetEvent(event_complete);
1818 ResetEvent(event_complete2);
1819 async_protocol = binding_protocol = filtered_protocol = NULL;
1820 filtered_sink = NULL;
1823 static void test_priority(IInternetProtocol *protocol)
1825 IInternetPriority *priority;
1829 hres = IInternetProtocol_QueryInterface(protocol, &IID_IInternetPriority,
1831 ok(hres == S_OK, "QueryInterface(IID_IInternetPriority) failed: %08x\n", hres);
1835 hres = IInternetPriority_GetPriority(priority, &pr);
1836 ok(hres == S_OK, "GetPriority failed: %08x\n", hres);
1837 ok(pr == 0, "pr=%d, expected 0\n", pr);
1839 hres = IInternetPriority_SetPriority(priority, 1);
1840 ok(hres == S_OK, "SetPriority failed: %08x\n", hres);
1842 hres = IInternetPriority_GetPriority(priority, &pr);
1843 ok(hres == S_OK, "GetPriority failed: %08x\n", hres);
1844 ok(pr == 1, "pr=%d, expected 1\n", pr);
1846 IInternetPriority_Release(priority);
1849 static BOOL file_protocol_start(IInternetProtocol *protocol, LPCWSTR url, BOOL is_first)
1853 SET_EXPECT(GetBindInfo);
1854 if(!(bindf & BINDF_FROMURLMON))
1855 SET_EXPECT(ReportProgress_DIRECTBIND);
1857 SET_EXPECT(ReportProgress_SENDINGREQUEST);
1858 SET_EXPECT(ReportProgress_CACHEFILENAMEAVAILABLE);
1859 if(bindf & BINDF_FROMURLMON)
1860 SET_EXPECT(ReportProgress_VERIFIEDMIMETYPEAVAILABLE);
1862 SET_EXPECT(ReportProgress_MIMETYPEAVAILABLE);
1864 SET_EXPECT(ReportData);
1866 SET_EXPECT(ReportResult);
1868 expect_hrResult = S_OK;
1870 hres = IInternetProtocol_Start(protocol, url, &protocol_sink, &bind_info, 0, 0);
1871 if(hres == INET_E_RESOURCE_NOT_FOUND) {
1872 win_skip("Start failed\n");
1875 ok(hres == S_OK, "Start failed: %08x\n", hres);
1877 CHECK_CALLED(GetBindInfo);
1878 if(!(bindf & BINDF_FROMURLMON))
1879 CHECK_CALLED(ReportProgress_DIRECTBIND);
1881 CHECK_CALLED(ReportProgress_SENDINGREQUEST);
1882 CHECK_CALLED(ReportProgress_CACHEFILENAMEAVAILABLE);
1883 if(bindf & BINDF_FROMURLMON)
1884 CHECK_CALLED(ReportProgress_VERIFIEDMIMETYPEAVAILABLE);
1886 CHECK_CALLED(ReportProgress_MIMETYPEAVAILABLE);
1888 CHECK_CALLED(ReportData);
1890 CHECK_CALLED(ReportResult);
1895 static void test_file_protocol_url(LPCWSTR url)
1897 IInternetProtocolInfo *protocol_info;
1899 IClassFactory *factory;
1902 hres = CoGetClassObject(&CLSID_FileProtocol, CLSCTX_INPROC_SERVER, NULL,
1903 &IID_IUnknown, (void**)&unk);
1904 ok(hres == S_OK, "CoGetClassObject failed: %08x\n", hres);
1908 hres = IUnknown_QueryInterface(unk, &IID_IInternetProtocolInfo, (void**)&protocol_info);
1909 ok(hres == E_NOINTERFACE,
1910 "Could not get IInternetProtocolInfo interface: %08x, expected E_NOINTERFACE\n", hres);
1912 hres = IUnknown_QueryInterface(unk, &IID_IClassFactory, (void**)&factory);
1913 ok(hres == S_OK, "Could not get IClassFactory interface\n");
1914 if(SUCCEEDED(hres)) {
1915 IInternetProtocol *protocol;
1918 hres = IClassFactory_CreateInstance(factory, NULL, &IID_IInternetProtocol, (void**)&protocol);
1919 ok(hres == S_OK, "Could not get IInternetProtocol: %08x\n", hres);
1921 if(SUCCEEDED(hres)) {
1922 if(file_protocol_start(protocol, url, TRUE)) {
1923 hres = IInternetProtocol_Read(protocol, buf, 2, &cb);
1924 ok(hres == S_OK, "Read failed: %08x\n", hres);
1925 ok(cb == 2, "cb=%u expected 2\n", cb);
1926 hres = IInternetProtocol_Read(protocol, buf, sizeof(buf), &cb);
1927 ok(hres == S_FALSE, "Read failed: %08x\n", hres);
1928 hres = IInternetProtocol_Read(protocol, buf, sizeof(buf), &cb);
1929 ok(hres == S_FALSE, "Read failed: %08x expected S_FALSE\n", hres);
1930 ok(cb == 0, "cb=%u expected 0\n", cb);
1931 hres = IInternetProtocol_UnlockRequest(protocol);
1932 ok(hres == S_OK, "UnlockRequest failed: %08x\n", hres);
1935 if(file_protocol_start(protocol, url, FALSE)) {
1936 hres = IInternetProtocol_Read(protocol, buf, 2, &cb);
1937 ok(hres == S_FALSE, "Read failed: %08x\n", hres);
1938 hres = IInternetProtocol_LockRequest(protocol, 0);
1939 ok(hres == S_OK, "LockRequest failed: %08x\n", hres);
1940 hres = IInternetProtocol_UnlockRequest(protocol);
1941 ok(hres == S_OK, "UnlockRequest failed: %08x\n", hres);
1944 IInternetProtocol_Release(protocol);
1947 hres = IClassFactory_CreateInstance(factory, NULL, &IID_IInternetProtocol, (void**)&protocol);
1948 ok(hres == S_OK, "Could not get IInternetProtocol: %08x\n", hres);
1950 if(SUCCEEDED(hres)) {
1951 if(file_protocol_start(protocol, url, TRUE)) {
1952 hres = IInternetProtocol_LockRequest(protocol, 0);
1953 ok(hres == S_OK, "LockRequest failed: %08x\n", hres);
1954 hres = IInternetProtocol_Terminate(protocol, 0);
1955 ok(hres == S_OK, "Terminate failed: %08x\n", hres);
1956 hres = IInternetProtocol_Read(protocol, buf, 2, &cb);
1957 ok(hres == S_OK, "Read failed: %08x\n\n", hres);
1958 hres = IInternetProtocol_UnlockRequest(protocol);
1959 ok(hres == S_OK, "UnlockRequest failed: %08x\n", hres);
1960 hres = IInternetProtocol_Read(protocol, buf, 2, &cb);
1961 ok(hres == S_OK, "Read failed: %08x\n", hres);
1962 hres = IInternetProtocol_Terminate(protocol, 0);
1963 ok(hres == S_OK, "Terminate failed: %08x\n", hres);
1966 IInternetProtocol_Release(protocol);
1969 hres = IClassFactory_CreateInstance(factory, NULL, &IID_IInternetProtocol, (void**)&protocol);
1970 ok(hres == S_OK, "Could not get IInternetProtocol: %08x\n", hres);
1972 if(SUCCEEDED(hres)) {
1973 if(file_protocol_start(protocol, url, TRUE)) {
1974 hres = IInternetProtocol_Terminate(protocol, 0);
1975 ok(hres == S_OK, "Terminate failed: %08x\n", hres);
1976 hres = IInternetProtocol_Read(protocol, buf, 2, &cb);
1977 ok(hres == S_OK, "Read failed: %08x\n", hres);
1978 ok(cb == 2, "cb=%u expected 2\n", cb);
1981 IInternetProtocol_Release(protocol);
1984 IClassFactory_Release(factory);
1987 IUnknown_Release(unk);
1990 static void test_file_protocol_fail(void)
1992 IInternetProtocol *protocol;
1995 static const WCHAR index_url2[] =
1996 {'f','i','l','e',':','/','/','i','n','d','e','x','.','h','t','m','l',0};
1998 hres = CoCreateInstance(&CLSID_FileProtocol, NULL, CLSCTX_INPROC_SERVER|CLSCTX_INPROC_HANDLER,
1999 &IID_IInternetProtocol, (void**)&protocol);
2000 ok(hres == S_OK, "CoCreateInstance failed: %08x\n", hres);
2004 SET_EXPECT(GetBindInfo);
2005 expect_hrResult = MK_E_SYNTAX;
2006 hres = IInternetProtocol_Start(protocol, wszIndexHtml, &protocol_sink, &bind_info, 0, 0);
2007 ok(hres == MK_E_SYNTAX ||
2008 hres == E_INVALIDARG,
2009 "Start failed: %08x, expected MK_E_SYNTAX or E_INVALIDARG\n", hres);
2010 CLEAR_CALLED(GetBindInfo); /* GetBindInfo not called in IE7 */
2012 SET_EXPECT(GetBindInfo);
2013 if(!(bindf & BINDF_FROMURLMON))
2014 SET_EXPECT(ReportProgress_DIRECTBIND);
2015 SET_EXPECT(ReportProgress_SENDINGREQUEST);
2016 SET_EXPECT(ReportResult);
2017 expect_hrResult = INET_E_RESOURCE_NOT_FOUND;
2018 hres = IInternetProtocol_Start(protocol, index_url, &protocol_sink, &bind_info, 0, 0);
2019 ok(hres == INET_E_RESOURCE_NOT_FOUND,
2020 "Start failed: %08x expected INET_E_RESOURCE_NOT_FOUND\n", hres);
2021 CHECK_CALLED(GetBindInfo);
2022 if(!(bindf & BINDF_FROMURLMON))
2023 CHECK_CALLED(ReportProgress_DIRECTBIND);
2024 CHECK_CALLED(ReportProgress_SENDINGREQUEST);
2025 CHECK_CALLED(ReportResult);
2027 IInternetProtocol_Release(protocol);
2029 hres = CoCreateInstance(&CLSID_FileProtocol, NULL, CLSCTX_INPROC_SERVER|CLSCTX_INPROC_HANDLER,
2030 &IID_IInternetProtocol, (void**)&protocol);
2031 ok(hres == S_OK, "CoCreateInstance failed: %08x\n", hres);
2035 SET_EXPECT(GetBindInfo);
2036 if(!(bindf & BINDF_FROMURLMON))
2037 SET_EXPECT(ReportProgress_DIRECTBIND);
2038 SET_EXPECT(ReportProgress_SENDINGREQUEST);
2039 SET_EXPECT(ReportResult);
2040 expect_hrResult = INET_E_RESOURCE_NOT_FOUND;
2042 hres = IInternetProtocol_Start(protocol, index_url2, &protocol_sink, &bind_info, 0, 0);
2043 ok(hres == INET_E_RESOURCE_NOT_FOUND,
2044 "Start failed: %08x, expected INET_E_RESOURCE_NOT_FOUND\n", hres);
2045 CHECK_CALLED(GetBindInfo);
2046 if(!(bindf & BINDF_FROMURLMON))
2047 CHECK_CALLED(ReportProgress_DIRECTBIND);
2048 CHECK_CALLED(ReportProgress_SENDINGREQUEST);
2049 CHECK_CALLED(ReportResult);
2051 SET_EXPECT(GetBindInfo);
2052 hres = IInternetProtocol_Start(protocol, NULL, &protocol_sink, &bind_info, 0, 0);
2053 ok(hres == E_INVALIDARG, "Start failed: %08x, expected E_INVALIDARG\n", hres);
2054 CLEAR_CALLED(GetBindInfo); /* GetBindInfo not called in IE7 */
2056 SET_EXPECT(GetBindInfo);
2057 hres = IInternetProtocol_Start(protocol, emptyW, &protocol_sink, &bind_info, 0, 0);
2058 ok(hres == E_INVALIDARG, "Start failed: %08x, expected E_INVALIDARG\n", hres);
2059 CLEAR_CALLED(GetBindInfo); /* GetBindInfo not called in IE7 */
2061 IInternetProtocol_Release(protocol);
2064 static void test_file_protocol(void) {
2065 WCHAR buf[INTERNET_MAX_URL_LENGTH], file_name_buf[MAX_PATH];
2070 static const WCHAR wszFile[] = {'f','i','l','e',':',0};
2071 static const WCHAR wszFile2[] = {'f','i','l','e',':','/','/',0};
2072 static const WCHAR wszFile3[] = {'f','i','l','e',':','/','/','/',0};
2073 static const char html_doc[] = "<HTML></HTML>";
2075 trace("Testing file protocol...\n");
2076 init_test(FILE_TEST, 0);
2078 SetLastError(0xdeadbeef);
2079 file = CreateFileW(wszIndexHtml, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS,
2080 FILE_ATTRIBUTE_NORMAL, NULL);
2081 if(!file && GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)
2083 win_skip("Detected Win9x or WinMe\n");
2086 ok(file != INVALID_HANDLE_VALUE, "CreateFile failed\n");
2087 if(file == INVALID_HANDLE_VALUE)
2089 WriteFile(file, html_doc, sizeof(html_doc)-1, &size, NULL);
2092 file_name = wszIndexHtml;
2094 test_file_protocol_url(index_url);
2095 bindf = BINDF_FROMURLMON;
2096 test_file_protocol_url(index_url);
2097 bindf = BINDF_FROMURLMON | BINDF_NEEDFILE;
2098 test_file_protocol_url(index_url);
2100 memcpy(buf, wszFile, sizeof(wszFile));
2101 len = sizeof(wszFile)/sizeof(WCHAR)-1;
2102 len += GetCurrentDirectoryW(sizeof(buf)/sizeof(WCHAR)-len, buf+len);
2104 memcpy(buf+len, wszIndexHtml, sizeof(wszIndexHtml));
2106 file_name = buf + sizeof(wszFile)/sizeof(WCHAR)-1;
2108 test_file_protocol_url(buf);
2109 bindf = BINDF_FROMURLMON;
2110 test_file_protocol_url(buf);
2112 memcpy(buf, wszFile2, sizeof(wszFile2));
2113 len = GetCurrentDirectoryW(sizeof(file_name_buf)/sizeof(WCHAR), file_name_buf);
2114 file_name_buf[len++] = '\\';
2115 memcpy(file_name_buf+len, wszIndexHtml, sizeof(wszIndexHtml));
2116 lstrcpyW(buf+sizeof(wszFile2)/sizeof(WCHAR)-1, file_name_buf);
2117 file_name = file_name_buf;
2119 test_file_protocol_url(buf);
2120 bindf = BINDF_FROMURLMON;
2121 test_file_protocol_url(buf);
2123 buf[sizeof(wszFile2)/sizeof(WCHAR)] = '|';
2124 test_file_protocol_url(buf);
2126 memcpy(buf, wszFile3, sizeof(wszFile3));
2127 len = sizeof(wszFile3)/sizeof(WCHAR)-1;
2128 len += GetCurrentDirectoryW(sizeof(buf)/sizeof(WCHAR)-len, buf+len);
2130 memcpy(buf+len, wszIndexHtml, sizeof(wszIndexHtml));
2132 file_name = buf + sizeof(wszFile3)/sizeof(WCHAR)-1;
2134 test_file_protocol_url(buf);
2135 bindf = BINDF_FROMURLMON;
2136 test_file_protocol_url(buf);
2138 DeleteFileW(wszIndexHtml);
2141 test_file_protocol_fail();
2142 bindf = BINDF_FROMURLMON;
2143 test_file_protocol_fail();
2146 static BOOL http_protocol_start(LPCWSTR url, BOOL is_first)
2148 static BOOL got_user_agent = FALSE;
2151 first_data_notif = TRUE;
2154 SET_EXPECT(GetBindInfo);
2155 if (!(bindf & BINDF_FROMURLMON))
2156 SET_EXPECT(ReportProgress_DIRECTBIND);
2157 SET_EXPECT(GetBindString_USER_AGENT);
2158 SET_EXPECT(GetBindString_ACCEPT_MIMES);
2159 SET_EXPECT(QueryService_HttpNegotiate);
2160 SET_EXPECT(BeginningTransaction);
2161 SET_EXPECT(GetRootSecurityId);
2163 SET_EXPECT(GetBindString_POST_COOKIE);
2165 hres = IInternetProtocol_Start(async_protocol, url, &protocol_sink, &bind_info, 0, 0);
2166 ok(hres == S_OK, "Start failed: %08x\n", hres);
2170 CHECK_CALLED(GetBindInfo);
2171 if (!(bindf & BINDF_FROMURLMON))
2172 CHECK_CALLED(ReportProgress_DIRECTBIND);
2173 if (!got_user_agent)
2175 CHECK_CALLED(GetBindString_USER_AGENT);
2176 got_user_agent = TRUE;
2180 /* user agent only retrieved once, even with different URLs */
2181 CHECK_NOT_CALLED(GetBindString_USER_AGENT);
2183 CHECK_CALLED(GetBindString_ACCEPT_MIMES);
2184 CHECK_CALLED(QueryService_HttpNegotiate);
2185 CHECK_CALLED(BeginningTransaction);
2186 /* GetRootSecurityId called on WinXP but not on Win98 */
2187 CLEAR_CALLED(GetRootSecurityId);
2189 CHECK_CALLED(GetBindString_POST_COOKIE);
2194 static void test_protocol_terminate(IInternetProtocol *protocol)
2200 hres = IInternetProtocol_LockRequest(protocol, 0);
2201 ok(hres == S_OK, "LockRequest failed: %08x\n", hres);
2203 hres = IInternetProtocol_Read(protocol, buf, 1, &cb);
2204 ok(hres == S_FALSE, "Read failed: %08x\n", hres);
2206 hres = IInternetProtocol_Terminate(protocol, 0);
2207 ok(hres == S_OK, "Terminate failed: %08x\n", hres);
2209 /* This wait is to give the internet handles being freed in Terminate
2210 * enough time to actually terminate in all cases. Internet handles
2211 * terminate asynchronously and native reuses the main InternetOpen
2212 * handle. The only case in which this seems to be necessary is on
2213 * wine with native wininet and urlmon, resulting in the next time
2214 * test_http_protocol_url being called the first data notification actually
2215 * being an extra last data notification from the previous connection
2216 * about once out of every ten times. */
2219 hres = IInternetProtocol_UnlockRequest(protocol);
2220 ok(hres == S_OK, "UnlockRequest failed: %08x\n", hres);
2223 static void test_http_info(IInternetProtocol *protocol)
2225 IWinInetHttpInfo *info;
2228 hres = IInternetProtocol_QueryInterface(protocol, &IID_IWinInetHttpInfo, (void**)&info);
2229 ok(hres == S_OK, "Could not get IWinInterHttpInfo iface: %08x\n", hres);
2233 IWinInetHttpInfo_Release(info);
2236 /* is_first refers to whether this is the first call to this function
2238 static void test_http_protocol_url(LPCWSTR url, BOOL is_https, BOOL is_first)
2240 IInternetProtocolInfo *protocol_info;
2241 IClassFactory *factory;
2246 http_is_first = is_first;
2248 hres = CoGetClassObject(is_https ? &CLSID_HttpSProtocol : &CLSID_HttpProtocol,
2249 CLSCTX_INPROC_SERVER, NULL, &IID_IUnknown, (void**)&unk);
2250 ok(hres == S_OK, "CoGetClassObject failed: %08x\n", hres);
2254 hres = IUnknown_QueryInterface(unk, &IID_IInternetProtocolInfo, (void**)&protocol_info);
2255 ok(hres == E_NOINTERFACE,
2256 "Could not get IInternetProtocolInfo interface: %08x, expected E_NOINTERFACE\n",
2259 hres = IUnknown_QueryInterface(unk, &IID_IClassFactory, (void**)&factory);
2260 ok(hres == S_OK, "Could not get IClassFactory interface\n");
2261 IUnknown_Release(unk);
2265 hres = IClassFactory_CreateInstance(factory, NULL, &IID_IInternetProtocol,
2266 (void**)&async_protocol);
2267 ok(hres == S_OK, "Could not get IInternetProtocol: %08x\n", hres);
2268 if(SUCCEEDED(hres)) {
2273 test_priority(async_protocol);
2274 test_http_info(async_protocol);
2276 SET_EXPECT(ReportProgress_FINDINGRESOURCE);
2277 SET_EXPECT(ReportProgress_CONNECTING);
2278 SET_EXPECT(ReportProgress_SENDINGREQUEST);
2279 SET_EXPECT(ReportProgress_PROXYDETECTING);
2281 SET_EXPECT(ReportProgress_CACHEFILENAMEAVAILABLE);
2283 SET_EXPECT(QueryService_HttpSecurity);
2284 if(!(bindf & BINDF_FROMURLMON)) {
2285 SET_EXPECT(OnResponse);
2286 SET_EXPECT(ReportProgress_RAWMIMETYPE);
2287 SET_EXPECT(ReportData);
2292 if(!http_protocol_start(url, is_first))
2295 SET_EXPECT(ReportResult);
2296 expect_hrResult = S_OK;
2298 hres = IInternetProtocol_Read(async_protocol, buf, 1, &cb);
2299 ok((hres == E_PENDING && cb==0) ||
2300 (hres == S_OK && cb==1), "Read failed: %08x (%d bytes)\n", hres, cb);
2302 WaitForSingleObject(event_complete, INFINITE);
2303 if(bindf & BINDF_FROMURLMON)
2304 CHECK_CALLED(Switch);
2306 CHECK_CALLED(ReportData);
2308 CLEAR_CALLED(QueryService_HttpSecurity);
2311 if(bindf & BINDF_FROMURLMON)
2314 SET_EXPECT(ReportData);
2315 hres = IInternetProtocol_Read(async_protocol, buf, sizeof(buf), &cb);
2316 if(hres == E_PENDING) {
2317 hres = IInternetProtocol_Read(async_protocol, buf, 1, &cb);
2318 ok((hres == E_PENDING && cb==0) ||
2319 (hres == S_OK && cb==1), "Read failed: %08x (%d bytes)\n", hres, cb);
2320 WaitForSingleObject(event_complete, INFINITE);
2321 if(bindf & BINDF_FROMURLMON)
2322 CHECK_CALLED(Switch);
2324 CHECK_CALLED(ReportData);
2326 if(bindf & BINDF_FROMURLMON)
2327 CHECK_NOT_CALLED(Switch);
2329 CHECK_NOT_CALLED(ReportData);
2333 ok(hres == S_FALSE, "Read failed: %08x\n", hres);
2334 CHECK_CALLED(ReportResult);
2336 CLEAR_CALLED(ReportProgress_SENDINGREQUEST);
2338 test_protocol_terminate(async_protocol);
2339 ref = IInternetProtocol_Release(async_protocol);
2340 ok(!ref, "ref=%x\n", hres);
2343 IClassFactory_Release(factory);
2346 static void test_http_protocol(void)
2348 static const WCHAR winehq_url[] =
2349 {'h','t','t','p',':','/','/','w','w','w','.','w','i','n','e','h','q','.',
2350 'o','r','g','/','s','i','t','e','/','a','b','o','u','t',0};
2351 static const WCHAR posttest_url[] =
2352 {'h','t','t','p',':','/','/','c','r','o','s','s','o','v','e','r','.',
2353 'c','o','d','e','w','e','a','v','e','r','s','.','c','o','m','/',
2354 'p','o','s','t','t','e','s','t','.','p','h','p',0};
2356 trace("Testing http protocol (not from urlmon)...\n");
2357 tested_protocol = HTTP_TEST;
2358 bindf = BINDF_ASYNCHRONOUS | BINDF_ASYNCSTORAGE | BINDF_PULLDATA;
2359 test_http_protocol_url(winehq_url, FALSE, TRUE);
2361 trace("Testing http protocol (from urlmon)...\n");
2362 bindf = BINDF_ASYNCHRONOUS | BINDF_ASYNCSTORAGE | BINDF_PULLDATA | BINDF_FROMURLMON;
2363 test_http_protocol_url(winehq_url, FALSE, FALSE);
2365 trace("Testing http protocol (to file)...\n");
2366 bindf = BINDF_ASYNCHRONOUS | BINDF_ASYNCSTORAGE | BINDF_PULLDATA | BINDF_FROMURLMON | BINDF_NEEDFILE;
2367 test_http_protocol_url(winehq_url, FALSE, FALSE);
2369 trace("Testing http protocol (post data)...\n");
2370 http_post_test = TRUE;
2371 /* Without this flag we get a ReportProgress_CACHEFILENAMEAVAILABLE
2372 * notification with BINDVERB_POST */
2373 bindf = BINDF_ASYNCHRONOUS | BINDF_ASYNCSTORAGE | BINDF_PULLDATA | BINDF_FROMURLMON | BINDF_NOWRITECACHE;
2374 test_http_protocol_url(posttest_url, FALSE, TRUE);
2375 http_post_test = FALSE;
2378 static void test_https_protocol(void)
2380 static const WCHAR codeweavers_url[] =
2381 {'h','t','t','p','s',':','/','/','w','w','w','.','c','o','d','e','w','e','a','v','e','r','s',
2382 '.','c','o','m','/','t','e','s','t','.','h','t','m','l',0};
2384 trace("Testing https protocol (from urlmon)...\n");
2385 init_test(HTTPS_TEST, 0);
2386 bindf = BINDF_ASYNCHRONOUS | BINDF_ASYNCSTORAGE | BINDF_PULLDATA | BINDF_FROMURLMON | BINDF_NOWRITECACHE;
2387 test_http_protocol_url(codeweavers_url, TRUE, TRUE);
2391 static void test_ftp_protocol(void)
2393 IInternetProtocolInfo *protocol_info;
2394 IClassFactory *factory;
2401 static const WCHAR ftp_urlW[] = {'f','t','p',':','/','/','f','t','p','.','w','i','n','e','h','q','.','o','r','g',
2402 '/','p','u','b','/','o','t','h','e','r','/',
2403 'w','i','n','e','l','o','g','o','.','x','c','f','.','t','a','r','.','b','z','2',0};
2405 trace("Testing ftp protocol...\n");
2407 bindf = BINDF_ASYNCHRONOUS | BINDF_ASYNCSTORAGE | BINDF_PULLDATA | BINDF_FROMURLMON | BINDF_NOWRITECACHE;
2409 tested_protocol = FTP_TEST;
2410 first_data_notif = TRUE;
2411 expect_hrResult = E_PENDING;
2413 hres = CoGetClassObject(&CLSID_FtpProtocol, 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, "Could not get IInternetProtocolInfo interface: %08x, expected E_NOINTERFACE\n", hres);
2421 hres = IUnknown_QueryInterface(unk, &IID_IClassFactory, (void**)&factory);
2422 ok(hres == S_OK, "Could not get IClassFactory interface\n");
2423 IUnknown_Release(unk);
2427 hres = IClassFactory_CreateInstance(factory, NULL, &IID_IInternetProtocol,
2428 (void**)&async_protocol);
2429 IClassFactory_Release(factory);
2430 ok(hres == S_OK, "Could not get IInternetProtocol: %08x\n", hres);
2432 test_priority(async_protocol);
2433 test_http_info(async_protocol);
2435 SET_EXPECT(GetBindInfo);
2436 SET_EXPECT(GetBindString_USER_AGENT);
2437 SET_EXPECT(ReportProgress_FINDINGRESOURCE);
2438 SET_EXPECT(ReportProgress_CONNECTING);
2439 SET_EXPECT(ReportProgress_SENDINGREQUEST);
2442 hres = IInternetProtocol_Start(async_protocol, ftp_urlW, &protocol_sink, &bind_info, 0, 0);
2443 ok(hres == S_OK, "Start failed: %08x\n", hres);
2444 CHECK_CALLED(GetBindInfo);
2445 todo_wine CHECK_NOT_CALLED(GetBindString_USER_AGENT);
2447 SET_EXPECT(ReportResult);
2449 hres = IInternetProtocol_Read(async_protocol, buf, 1, &cb);
2450 ok((hres == E_PENDING && cb==0) ||
2451 (hres == S_OK && cb==1), "Read failed: %08x (%d bytes)\n", hres, cb);
2453 WaitForSingleObject(event_complete, INFINITE);
2457 hres = IInternetProtocol_Read(async_protocol, buf, sizeof(buf), &cb);
2458 if(hres == E_PENDING)
2459 WaitForSingleObject(event_complete, INFINITE);
2464 ok(hres == S_FALSE, "Read failed: %08x\n", hres);
2465 CHECK_CALLED(ReportResult);
2466 CHECK_CALLED(Switch);
2468 test_protocol_terminate(async_protocol);
2470 ref = IInternetProtocol_Release(async_protocol);
2471 ok(!ref, "ref=%d\n", ref);
2474 static void test_gopher_protocol(void)
2476 IInternetProtocolInfo *protocol_info;
2477 IClassFactory *factory;
2481 trace("Testing gopher protocol...\n");
2483 hres = CoGetClassObject(&CLSID_GopherProtocol, CLSCTX_INPROC_SERVER, NULL, &IID_IUnknown, (void**)&unk);
2485 hres == REGDB_E_CLASSNOTREG, /* Gopher protocol has been removed as of Vista */
2486 "CoGetClassObject failed: %08x\n", hres);
2490 hres = IUnknown_QueryInterface(unk, &IID_IInternetProtocolInfo, (void**)&protocol_info);
2491 ok(hres == E_NOINTERFACE, "Could not get IInternetProtocolInfo interface: %08x, expected E_NOINTERFACE\n", hres);
2493 hres = IUnknown_QueryInterface(unk, &IID_IClassFactory, (void**)&factory);
2494 ok(hres == S_OK, "Could not get IClassFactory interface\n");
2495 IUnknown_Release(unk);
2499 hres = IClassFactory_CreateInstance(factory, NULL, &IID_IInternetProtocol,
2500 (void**)&async_protocol);
2501 IClassFactory_Release(factory);
2502 ok(hres == S_OK, "Could not get IInternetProtocol: %08x\n", hres);
2504 test_priority(async_protocol);
2506 IInternetProtocol_Release(async_protocol);
2509 static void test_mk_protocol(void)
2511 IInternetProtocolInfo *protocol_info;
2512 IInternetProtocol *protocol;
2513 IClassFactory *factory;
2517 static const WCHAR wrong_url1[] = {'t','e','s','t',':','@','M','S','I','T','S','t','o','r','e',
2518 ':',':','/','t','e','s','t','.','h','t','m','l',0};
2519 static const WCHAR wrong_url2[] = {'m','k',':','/','t','e','s','t','.','h','t','m','l',0};
2521 trace("Testing mk protocol...\n");
2522 init_test(MK_TEST, 0);
2524 hres = CoGetClassObject(&CLSID_MkProtocol, CLSCTX_INPROC_SERVER, NULL,
2525 &IID_IUnknown, (void**)&unk);
2526 ok(hres == S_OK, "CoGetClassObject failed: %08x\n", hres);
2528 hres = IUnknown_QueryInterface(unk, &IID_IInternetProtocolInfo, (void**)&protocol_info);
2529 ok(hres == E_NOINTERFACE,
2530 "Could not get IInternetProtocolInfo interface: %08x, expected E_NOINTERFACE\n",
2533 hres = IUnknown_QueryInterface(unk, &IID_IClassFactory, (void**)&factory);
2534 ok(hres == S_OK, "Could not get IClassFactory interface\n");
2535 IUnknown_Release(unk);
2539 hres = IClassFactory_CreateInstance(factory, NULL, &IID_IInternetProtocol,
2541 IClassFactory_Release(factory);
2542 ok(hres == S_OK, "Could not get IInternetProtocol: %08x\n", hres);
2544 SET_EXPECT(GetBindInfo);
2545 hres = IInternetProtocol_Start(protocol, wrong_url1, &protocol_sink, &bind_info, 0, 0);
2546 ok(hres == MK_E_SYNTAX || hres == INET_E_INVALID_URL,
2547 "Start failed: %08x, expected MK_E_SYNTAX or INET_E_INVALID_URL\n", hres);
2548 CLEAR_CALLED(GetBindInfo);
2550 SET_EXPECT(GetBindInfo);
2551 SET_EXPECT(ReportProgress_DIRECTBIND);
2552 SET_EXPECT(ReportProgress_SENDINGREQUEST);
2553 SET_EXPECT(ReportProgress_MIMETYPEAVAILABLE);
2554 SET_EXPECT(ReportResult);
2555 expect_hrResult = INET_E_RESOURCE_NOT_FOUND;
2557 hres = IInternetProtocol_Start(protocol, wrong_url2, &protocol_sink, &bind_info, 0, 0);
2558 ok(hres == INET_E_RESOURCE_NOT_FOUND ||
2559 hres == INET_E_INVALID_URL, /* win2k3 */
2560 "Start failed: %08x, expected INET_E_RESOURCE_NOT_FOUND or INET_E_INVALID_URL\n", hres);
2562 if (hres == INET_E_RESOURCE_NOT_FOUND) {
2563 CHECK_CALLED(GetBindInfo);
2564 CLEAR_CALLED(ReportProgress_DIRECTBIND);
2565 CHECK_CALLED(ReportProgress_SENDINGREQUEST);
2566 CHECK_CALLED(ReportProgress_MIMETYPEAVAILABLE);
2567 CHECK_CALLED(ReportResult);
2569 CLEAR_CALLED(GetBindInfo);
2570 CLEAR_CALLED(ReportProgress_DIRECTBIND);
2571 CLEAR_CALLED(ReportProgress_SENDINGREQUEST);
2572 CLEAR_CALLED(ReportProgress_MIMETYPEAVAILABLE);
2573 CLEAR_CALLED(ReportResult);
2576 IInternetProtocol_Release(protocol);
2579 static void test_CreateBinding(void)
2581 IInternetProtocol *protocol;
2582 IInternetPriority *priority;
2583 IInternetSession *session;
2589 static const WCHAR test_url[] =
2590 {'t','e','s','t',':','/','/','f','i','l','e','.','h','t','m','l',0};
2591 static const WCHAR wsz_test[] = {'t','e','s','t',0};
2593 trace("Testing CreateBinding...\n");
2594 init_test(BIND_TEST, TEST_BINDING);
2596 hres = CoInternetGetSession(0, &session, 0);
2597 ok(hres == S_OK, "CoInternetGetSession failed: %08x\n", hres);
2599 hres = IInternetSession_RegisterNameSpace(session, &ClassFactory, &IID_NULL, wsz_test, 0, NULL, 0);
2600 ok(hres == S_OK, "RegisterNameSpace failed: %08x\n", hres);
2602 hres = IInternetSession_CreateBinding(session, NULL, test_url, NULL, NULL, &protocol, 0);
2603 binding_protocol = protocol;
2604 ok(hres == S_OK, "CreateBinding failed: %08x\n", hres);
2605 ok(protocol != NULL, "protocol == NULL\n");
2607 hres = IInternetProtocol_QueryInterface(protocol, &IID_IInternetBindInfo, (void**)&prot_bind_info);
2608 ok(hres == S_OK, "QueryInterface(IID_IInternetBindInfo) failed: %08x\n", hres);
2610 hres = IInternetProtocol_QueryInterface(protocol, &IID_IInternetProtocolSink, (void**)&binding_sink);
2611 ok(hres == S_OK, "Could not get IInternetProtocolSink: %08x\n", hres);
2613 hres = IInternetProtocol_Start(protocol, test_url, NULL, &bind_info, 0, 0);
2614 ok(hres == E_INVALIDARG, "Start failed: %08x, expected E_INVALIDARG\n", hres);
2615 hres = IInternetProtocol_Start(protocol, test_url, &protocol_sink, NULL, 0, 0);
2616 ok(hres == E_INVALIDARG, "Start failed: %08x, expected E_INVALIDARG\n", hres);
2617 hres = IInternetProtocol_Start(protocol, NULL, &protocol_sink, &bind_info, 0, 0);
2618 ok(hres == E_INVALIDARG, "Start failed: %08x, expected E_INVALIDARG\n", hres);
2620 hres = IInternetProtocol_QueryInterface(protocol, &IID_IInternetPriority, (void**)&priority);
2621 ok(hres == S_OK, "QueryInterface(IID_IInternetPriority) failed: %08x\n", hres);
2624 hres = IInternetPriority_GetPriority(priority, &p);
2625 ok(hres == S_OK, "GetPriority failed: %08x\n", hres);
2626 ok(!p, "p=%d\n", p);
2629 hres = IInternetPriority_SetPriority(priority, 100);
2630 ok(hres == S_OK, "SetPriority failed: %08x\n", hres);
2633 hres = IInternetPriority_GetPriority(priority, &p);
2634 ok(hres == S_OK, "GetPriority failed: %08x\n", hres);
2635 ok(p == 100, "p=%d\n", p);
2637 SET_EXPECT(QueryService_InternetProtocol);
2638 SET_EXPECT(CreateInstance);
2639 SET_EXPECT(ReportProgress_PROTOCOLCLASSID);
2640 SET_EXPECT(SetPriority);
2643 expect_hrResult = S_OK;
2644 hres = IInternetProtocol_Start(protocol, test_url, &protocol_sink, &bind_info, 0, 0);
2645 ok(hres == S_OK, "Start failed: %08x\n", hres);
2647 CHECK_CALLED(QueryService_InternetProtocol);
2648 CHECK_CALLED(CreateInstance);
2649 CHECK_CALLED(ReportProgress_PROTOCOLCLASSID);
2650 CHECK_CALLED(SetPriority);
2651 CHECK_CALLED(Start);
2655 hres = IInternetProtocol_Read(protocol, expect_pv = buf, sizeof(buf), &read);
2656 ok(hres == S_OK, "Read failed: %08x\n", hres);
2657 ok(read == 100, "read = %d\n", read);
2662 hres = IInternetProtocol_Read(protocol, expect_pv = buf, sizeof(buf), &read);
2663 ok(hres == S_FALSE, "Read failed: %08x\n", hres);
2664 ok(!read, "read = %d\n", read);
2668 hres = IInternetPriority_GetPriority(priority, &p);
2669 ok(hres == S_OK, "GetPriority failed: %08x\n", hres);
2670 ok(p == 100, "p=%d\n", p);
2672 hres = IInternetPriority_SetPriority(priority, 101);
2673 ok(hres == S_OK, "SetPriority failed: %08x\n", hres);
2675 SET_EXPECT(Terminate);
2676 hres = IInternetProtocol_Terminate(protocol, 0xdeadbeef);
2677 ok(hres == S_OK, "Terminate failed: %08x\n", hres);
2678 CHECK_CALLED(Terminate);
2680 SET_EXPECT(Continue);
2681 hres = IInternetProtocolSink_Switch(binding_sink, &protocoldata);
2682 ok(hres == S_OK, "Switch failed: %08x\n", hres);
2683 CHECK_CALLED(Continue);
2685 hres = IInternetProtocolSink_ReportProgress(binding_sink,
2686 BINDSTATUS_CACHEFILENAMEAVAILABLE, expect_wsz = emptyW);
2687 ok(hres == S_OK, "ReportProgress(BINDSTATUS_CACHEFILENAMEAVAILABLE) failed: %08x\n", hres);
2689 hres = IInternetProtocolSink_ReportResult(binding_sink, S_OK, ERROR_SUCCESS, NULL);
2690 ok(hres == E_FAIL, "ReportResult failed: %08x, expected E_FAIL\n", hres);
2692 hres = IInternetProtocolSink_ReportData(binding_sink, 0, 0, 0);
2693 ok(hres == S_OK, "ReportData failed: %08x\n", hres);
2695 IInternetProtocolSink_Release(binding_sink);
2696 IInternetPriority_Release(priority);
2697 IInternetBindInfo_Release(prot_bind_info);
2698 IInternetProtocol_Release(protocol);
2699 IInternetSession_Release(session);
2702 static void test_binding(int prot, DWORD grf_pi, BOOL test_filter)
2704 IInternetProtocol *protocol;
2705 IInternetSession *session;
2709 trace("Testing %s binding (grfPI %x%s)...\n", debugstr_w(protocol_names[prot]), grf_pi,
2710 test_filter ? " testing MIME filter" : "");
2711 init_test(prot, TEST_BINDING | (test_filter ? TEST_FILTER : 0));
2714 hres = CoInternetGetSession(0, &session, 0);
2715 ok(hres == S_OK, "CoInternetGetSession failed: %08x\n", hres);
2717 hres = IInternetSession_RegisterNameSpace(session, &ClassFactory, &IID_NULL, protocol_names[prot], 0, NULL, 0);
2718 ok(hres == S_OK, "RegisterNameSpace failed: %08x\n", hres);
2720 hres = IInternetSession_CreateBinding(session, NULL, binding_urls[prot], NULL, NULL, &protocol, 0);
2721 binding_protocol = protocol;
2722 IInternetSession_Release(session);
2723 ok(hres == S_OK, "CreateBinding failed: %08x\n", hres);
2724 ok(protocol != NULL, "protocol == NULL\n");
2726 hres = IInternetProtocol_QueryInterface(protocol, &IID_IInternetBindInfo, (void**)&prot_bind_info);
2727 ok(hres == S_OK, "QueryInterface(IID_IInternetBindInfo) failed: %08x\n", hres);
2729 hres = IInternetProtocol_QueryInterface(protocol, &IID_IInternetProtocolSink, (void**)&binding_sink);
2730 ok(hres == S_OK, "QueryInterface(IID_IInternetProtocolSink) failed: %08x\n", hres);
2733 SET_EXPECT(QueryService_InternetProtocol);
2734 SET_EXPECT(CreateInstance);
2735 SET_EXPECT(ReportProgress_PROTOCOLCLASSID);
2736 SET_EXPECT(SetPriority);
2739 expect_hrResult = S_OK;
2740 hres = IInternetProtocol_Start(protocol, binding_urls[prot], &protocol_sink, &bind_info, pi, 0);
2741 ok(hres == S_OK, "Start failed: %08x\n", hres);
2743 CHECK_CALLED(QueryService_InternetProtocol);
2744 CHECK_CALLED(CreateInstance);
2745 CHECK_CALLED(ReportProgress_PROTOCOLCLASSID);
2746 CHECK_CALLED(SetPriority);
2747 CHECK_CALLED(Start);
2749 if(prot == HTTP_TEST || prot == HTTPS_TEST) {
2750 while(prot_state < 4) {
2751 WaitForSingleObject(event_complete, INFINITE);
2752 if(mimefilter_test && filtered_protocol) {
2753 SET_EXPECT(Continue);
2754 IInternetProtocol_Continue(filtered_protocol, pdata);
2755 CHECK_CALLED(Continue);
2757 SET_EXPECT(Continue);
2758 IInternetProtocol_Continue(protocol, pdata);
2759 CHECK_CALLED(Continue);
2761 SetEvent(event_complete2);
2763 WaitForSingleObject(event_complete, INFINITE);
2766 SET_EXPECT(MimeFilter_LockRequest);
2768 SET_EXPECT(LockRequest);
2769 hres = IInternetProtocol_LockRequest(protocol, 0);
2770 ok(hres == S_OK, "LockRequest failed: %08x\n", hres);
2772 CHECK_CALLED(MimeFilter_LockRequest);
2774 CHECK_CALLED(LockRequest);
2777 SET_EXPECT(MimeFilter_UnlockRequest);
2779 SET_EXPECT(UnlockRequest);
2780 hres = IInternetProtocol_UnlockRequest(protocol);
2781 ok(hres == S_OK, "UnlockRequest failed: %08x\n", hres);
2783 CHECK_CALLED(MimeFilter_UnlockRequest);
2785 CHECK_CALLED(UnlockRequest);
2789 SET_EXPECT(MimeFilter_Terminate);
2791 SET_EXPECT(Terminate);
2792 hres = IInternetProtocol_Terminate(protocol, 0);
2793 ok(hres == S_OK, "Terminate failed: %08x\n", hres);
2795 CHECK_CALLED(MimeFilter_Terminate);
2797 CHECK_CALLED(Terminate);
2799 if(filtered_protocol)
2800 IInternetProtocol_Release(filtered_protocol);
2801 IInternetBindInfo_Release(prot_bind_info);
2802 IInternetProtocolSink_Release(binding_sink);
2803 ref = IInternetProtocol_Release(protocol);
2804 ok(!ref, "ref=%u, expected 0\n", ref);
2807 static void register_filter(void)
2809 IInternetSession *session;
2812 static const WCHAR gzipW[] = {'g','z','i','p',0};
2814 CoInternetGetSession(0, &session, 0);
2816 hres = IInternetSession_RegisterMimeFilter(session, &mimefilter_cf, &IID_IInternetProtocol, gzipW);
2817 ok(hres == S_OK, "RegisterMimeFilter failed: %08x\n", hres);
2819 IInternetSession_Release(session);
2822 START_TEST(protocol)
2824 OleInitialize(NULL);
2826 event_complete = CreateEvent(NULL, FALSE, FALSE, NULL);
2827 event_complete2 = CreateEvent(NULL, FALSE, FALSE, NULL);
2831 test_file_protocol();
2832 test_http_protocol();
2833 test_https_protocol();
2834 test_ftp_protocol();
2835 test_gopher_protocol();
2837 test_CreateBinding();
2838 test_binding(FILE_TEST, 0, FALSE);
2839 test_binding(HTTP_TEST, 0, FALSE);
2840 test_binding(FILE_TEST, PI_MIMEVERIFICATION, FALSE);
2841 test_binding(HTTP_TEST, PI_MIMEVERIFICATION, FALSE);
2842 test_binding(FILE_TEST, PI_MIMEVERIFICATION, TRUE);
2843 test_binding(HTTP_TEST, PI_MIMEVERIFICATION, TRUE);
2845 CloseHandle(event_complete);
2846 CloseHandle(event_complete2);