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)
858 if(IsEqualGUID(&IID_IUnknown, riid) || IsEqualGUID(&IID_IInternetProtocolSink, riid))
859 *ppv = &protocol_sink;
860 if(IsEqualGUID(&IID_IServiceProvider, riid))
861 *ppv = &service_provider;
862 if(IsEqualGUID(&IID_IUriContainer, riid))
863 return E_NOINTERFACE; /* TODO */
868 ok(0, "unexpected call %s\n", debugstr_guid(riid));
869 return E_NOINTERFACE;
872 static HRESULT WINAPI BindInfo_QueryInterface(IInternetBindInfo *iface, REFIID riid, void **ppv)
874 if(IsEqualGUID(&IID_IUnknown, riid) || IsEqualGUID(&IID_IInternetBindInfo, riid)) {
878 return E_NOINTERFACE;
881 static ULONG WINAPI BindInfo_AddRef(IInternetBindInfo *iface)
886 static ULONG WINAPI BindInfo_Release(IInternetBindInfo *iface)
891 static HRESULT WINAPI BindInfo_GetBindInfo(IInternetBindInfo *iface, DWORD *grfBINDF, BINDINFO *pbindinfo)
895 static const CHAR szPostData[] = "mode=Test";
897 CHECK_EXPECT(GetBindInfo);
899 ok(grfBINDF != NULL, "grfBINDF == NULL\n");
900 ok(pbindinfo != NULL, "pbindinfo == NULL\n");
901 ok(pbindinfo->cbSize == sizeof(BINDINFO), "wrong size of pbindinfo: %d\n", pbindinfo->cbSize);
905 *grfBINDF |= BINDF_FROMURLMON;
906 cbSize = pbindinfo->cbSize;
907 memset(pbindinfo, 0, cbSize);
908 pbindinfo->cbSize = cbSize;
912 /* Must be GMEM_FIXED, GMEM_MOVABLE does not work properly
913 * with urlmon on native (Win98 and WinXP) */
914 U(pbindinfo->stgmedData).hGlobal = GlobalAlloc(GPTR, sizeof(szPostData));
915 if (!U(pbindinfo->stgmedData).hGlobal)
917 http_post_test = FALSE;
918 skip("Out of memory\n");
919 return E_OUTOFMEMORY;
921 lstrcpy((LPSTR)U(pbindinfo->stgmedData).hGlobal, szPostData);
922 pbindinfo->cbstgmedData = sizeof(szPostData)-1;
923 pbindinfo->dwBindVerb = BINDVERB_POST;
924 pbindinfo->stgmedData.tymed = TYMED_HGLOBAL;
930 static HRESULT WINAPI BindInfo_GetBindString(IInternetBindInfo *iface, ULONG ulStringType,
931 LPOLESTR *ppwzStr, ULONG cEl, ULONG *pcElFetched)
933 ok(ppwzStr != NULL, "ppwzStr == NULL\n");
934 ok(pcElFetched != NULL, "pcElFetched == NULL\n");
936 switch(ulStringType) {
937 case BINDSTRING_ACCEPT_MIMES:
938 CHECK_EXPECT(GetBindString_ACCEPT_MIMES);
939 ok(cEl == 256, "cEl=%d, expected 256\n", cEl);
941 ok(*pcElFetched == 256, "*pcElFetched=%d, expected 256\n", *pcElFetched);
945 *ppwzStr = CoTaskMemAlloc(sizeof(acc_mimeW));
946 memcpy(*ppwzStr, acc_mimeW, sizeof(acc_mimeW));
949 case BINDSTRING_USER_AGENT:
950 CHECK_EXPECT(GetBindString_USER_AGENT);
951 ok(cEl == 1, "cEl=%d, expected 1\n", cEl);
953 ok(*pcElFetched == 0, "*pcElFetch=%d, expectd 0\n", *pcElFetched);
957 *ppwzStr = CoTaskMemAlloc(sizeof(user_agentW));
958 memcpy(*ppwzStr, user_agentW, sizeof(user_agentW));
961 case BINDSTRING_POST_COOKIE:
962 CHECK_EXPECT(GetBindString_POST_COOKIE);
963 ok(cEl == 1, "cEl=%d, expected 1\n", cEl);
965 ok(*pcElFetched == 0, "*pcElFetch=%d, expectd 0\n", *pcElFetched);
967 case BINDSTRING_URL: {
970 CHECK_EXPECT(GetBindString_URL);
971 ok(cEl == 1, "cEl=%d, expected 1\n", cEl);
972 ok(*pcElFetched == 0, "*pcElFetch=%d, expectd 0\n", *pcElFetched);
975 size = (lstrlenW(binding_urls[tested_protocol])+1)*sizeof(WCHAR);
976 *ppwzStr = CoTaskMemAlloc(size);
977 memcpy(*ppwzStr, binding_urls[tested_protocol], size);
981 ok(0, "unexpected call\n");
987 static IInternetBindInfoVtbl bind_info_vtbl = {
988 BindInfo_QueryInterface,
991 BindInfo_GetBindInfo,
992 BindInfo_GetBindString
995 static IInternetBindInfo bind_info = { &bind_info_vtbl };
997 static HRESULT WINAPI InternetPriority_QueryInterface(IInternetPriority *iface,
998 REFIID riid, void **ppv)
1000 ok(0, "unexpected call\n");
1001 return E_NOINTERFACE;
1004 static ULONG WINAPI InternetPriority_AddRef(IInternetPriority *iface)
1009 static ULONG WINAPI InternetPriority_Release(IInternetPriority *iface)
1014 static HRESULT WINAPI InternetPriority_SetPriority(IInternetPriority *iface, LONG nPriority)
1016 CHECK_EXPECT(SetPriority);
1017 ok(nPriority == ex_priority, "nPriority=%d\n", nPriority);
1021 static HRESULT WINAPI InternetPriority_GetPriority(IInternetPriority *iface, LONG *pnPriority)
1023 ok(0, "unexpected call\n");
1028 static const IInternetPriorityVtbl InternetPriorityVtbl = {
1029 InternetPriority_QueryInterface,
1030 InternetPriority_AddRef,
1031 InternetPriority_Release,
1032 InternetPriority_SetPriority,
1033 InternetPriority_GetPriority
1036 static IInternetPriority InternetPriority = { &InternetPriorityVtbl };
1038 static ULONG WINAPI Protocol_AddRef(IInternetProtocol *iface)
1043 static ULONG WINAPI Protocol_Release(IInternetProtocol *iface)
1048 static HRESULT WINAPI Protocol_Abort(IInternetProtocol *iface, HRESULT hrReason,
1051 ok(0, "unexpected call\n");
1055 static HRESULT WINAPI Protocol_Suspend(IInternetProtocol *iface)
1057 ok(0, "unexpected call\n");
1061 static HRESULT WINAPI Protocol_Resume(IInternetProtocol *iface)
1063 ok(0, "unexpected call\n");
1067 static HRESULT WINAPI Protocol_Seek(IInternetProtocol *iface,
1068 LARGE_INTEGER dlibMove, DWORD dwOrigin, ULARGE_INTEGER *plibNewPosition)
1070 ok(0, "unexpected call\n");
1074 static HRESULT WINAPI ProtocolEmul_QueryInterface(IInternetProtocol *iface, REFIID riid, void **ppv)
1076 if(IsEqualGUID(&IID_IUnknown, riid) || IsEqualGUID(&IID_IInternetProtocol, riid)) {
1081 if(IsEqualGUID(&IID_IInternetProtocolEx, riid)) {
1082 trace("IID_IInternetProtocolEx not supported\n");
1084 return E_NOINTERFACE;
1087 if(IsEqualGUID(&IID_IInternetPriority, riid)) {
1088 *ppv = &InternetPriority;
1092 ok(0, "unexpected riid %s\n", debugstr_guid(riid));
1094 return E_NOINTERFACE;
1097 static DWORD WINAPI thread_proc(PVOID arg)
1101 memset(&protocoldata, -1, sizeof(protocoldata));
1105 SET_EXPECT(ReportProgress_FINDINGRESOURCE);
1106 hres = IInternetProtocolSink_ReportProgress(binding_sink,
1107 BINDSTATUS_FINDINGRESOURCE, hostW);
1108 CHECK_CALLED(ReportProgress_FINDINGRESOURCE);
1109 ok(hres == S_OK, "ReportProgress failed: %08x\n", hres);
1111 SET_EXPECT(ReportProgress_CONNECTING);
1112 hres = IInternetProtocolSink_ReportProgress(binding_sink,
1113 BINDSTATUS_CONNECTING, winehq_ipW);
1114 CHECK_CALLED(ReportProgress_CONNECTING);
1115 ok(hres == S_OK, "ReportProgress failed: %08x\n", hres);
1117 SET_EXPECT(ReportProgress_SENDINGREQUEST);
1118 hres = IInternetProtocolSink_ReportProgress(binding_sink,
1119 BINDSTATUS_SENDINGREQUEST, NULL);
1120 CHECK_CALLED(ReportProgress_SENDINGREQUEST);
1121 ok(hres == S_OK, "ReportProgress failed: %08x\n", hres);
1125 hres = IInternetProtocolSink_Switch(binding_sink, &protocoldata);
1126 CHECK_CALLED(Switch);
1127 ok(hres == S_OK, "Switch failed: %08x\n", hres);
1131 SET_EXPECT(MimeFilter_Switch);
1134 hres = IInternetProtocolSink_Switch(binding_sink, &protocoldata);
1135 ok(hres == S_OK, "Switch failed: %08x\n", hres);
1137 CHECK_CALLED(MimeFilter_Switch);
1139 CHECK_CALLED(Switch);
1143 SET_EXPECT(MimeFilter_Switch);
1146 hres = IInternetProtocolSink_Switch(binding_sink, &protocoldata);
1147 ok(hres == S_OK, "Switch failed: %08x\n", hres);
1149 CHECK_CALLED(MimeFilter_Switch);
1151 CHECK_CALLED(Switch);
1155 SET_EXPECT(MimeFilter_Switch);
1158 hres = IInternetProtocolSink_Switch(binding_sink, &protocoldata);
1159 ok(hres == S_OK, "Switch failed: %08x\n", hres);
1161 CHECK_CALLED(MimeFilter_Switch);
1163 CHECK_CALLED(Switch);
1165 SetEvent(event_complete);
1170 static HRESULT WINAPI ProtocolEmul_Start(IInternetProtocol *iface, LPCWSTR szUrl,
1171 IInternetProtocolSink *pOIProtSink, IInternetBindInfo *pOIBindInfo,
1172 DWORD grfPI, HANDLE_PTR dwReserved)
1174 BINDINFO bindinfo, exp_bindinfo;
1178 CHECK_EXPECT(Start);
1180 ok(pOIProtSink != NULL, "pOIProtSink == NULL\n");
1181 ok(pOIBindInfo != NULL, "pOIBindInfo == NULL\n");
1182 ok(pOIProtSink != &protocol_sink, "unexpected pOIProtSink\n");
1183 ok(pOIBindInfo != &bind_info, "unexpected pOIBindInfo\n");
1184 ok(!grfPI, "grfPI = %x\n", grfPI);
1185 ok(!dwReserved, "dwReserved = %lx\n", dwReserved);
1188 ok(pOIProtSink == binding_sink, "pOIProtSink != binding_sink\n");
1190 memset(&bindinfo, 0, sizeof(bindinfo));
1191 bindinfo.cbSize = sizeof(bindinfo);
1192 memcpy(&exp_bindinfo, &bindinfo, sizeof(bindinfo));
1193 SET_EXPECT(GetBindInfo);
1194 hres = IInternetBindInfo_GetBindInfo(pOIBindInfo, &cbindf, &bindinfo);
1195 ok(hres == S_OK, "GetBindInfo failed: %08x\n", hres);
1196 CHECK_CALLED(GetBindInfo);
1197 ok(cbindf == (bindf|BINDF_FROMURLMON), "bindf = %x, expected %x\n",
1198 cbindf, (bindf|BINDF_FROMURLMON));
1199 ok(!memcmp(&exp_bindinfo, &bindinfo, sizeof(bindinfo)), "unexpected bindinfo\n");
1200 ReleaseBindInfo(&bindinfo);
1202 SET_EXPECT(ReportProgress_SENDINGREQUEST);
1203 hres = IInternetProtocolSink_ReportProgress(pOIProtSink, BINDSTATUS_SENDINGREQUEST, emptyW);
1204 ok(hres == S_OK, "ReportProgress(BINDSTATUS_SENDINGREQUEST) failed: %08x\n", hres);
1205 CHECK_CALLED(ReportProgress_SENDINGREQUEST);
1207 if(tested_protocol == HTTP_TEST || tested_protocol == HTTPS_TEST) {
1208 IServiceProvider *service_provider;
1209 IHttpNegotiate *http_negotiate;
1210 IHttpNegotiate2 *http_negotiate2;
1211 LPWSTR ua = (LPWSTR)0xdeadbeef, accept_mimes[256];
1212 LPWSTR additional_headers = NULL;
1214 DWORD fetched = 0, size = 100;
1217 SET_EXPECT(GetBindString_USER_AGENT);
1218 hres = IInternetBindInfo_GetBindString(pOIBindInfo, BINDSTRING_USER_AGENT,
1220 CHECK_CALLED(GetBindString_USER_AGENT);
1221 ok(hres == S_OK, "GetBindString(BINDSTRING_USER_AGETNT) failed: %08x\n", hres);
1222 ok(fetched == 1, "fetched = %d, expected 254\n", fetched);
1223 ok(ua != NULL, "ua = %p\n", ua);
1224 ok(!strcmp_ww(ua, user_agentW), "unexpected user agent %s\n", debugstr_w(ua));
1228 SET_EXPECT(GetBindString_ACCEPT_MIMES);
1229 hres = IInternetBindInfo_GetBindString(pOIBindInfo, BINDSTRING_ACCEPT_MIMES,
1230 accept_mimes, 256, &fetched);
1231 CHECK_CALLED(GetBindString_ACCEPT_MIMES);
1234 "GetBindString(BINDSTRING_ACCEPT_MIMES) failed: %08x\n", hres);
1235 ok(fetched == 1, "fetched = %d, expected 1\n", fetched);
1236 ok(!strcmp_ww(acc_mimeW, accept_mimes[0]), "unexpected mimes %s\n", debugstr_w(accept_mimes[0]));
1238 hres = IInternetBindInfo_QueryInterface(pOIBindInfo, &IID_IServiceProvider,
1239 (void**)&service_provider);
1240 ok(hres == S_OK, "QueryInterface failed: %08x\n", hres);
1242 SET_EXPECT(QueryService_HttpNegotiate);
1243 hres = IServiceProvider_QueryService(service_provider, &IID_IHttpNegotiate,
1244 &IID_IHttpNegotiate, (void**)&http_negotiate);
1245 CHECK_CALLED(QueryService_HttpNegotiate);
1246 ok(hres == S_OK, "QueryService failed: %08x\n", hres);
1248 SET_EXPECT(BeginningTransaction);
1249 hres = IHttpNegotiate_BeginningTransaction(http_negotiate, binding_urls[tested_protocol],
1250 NULL, 0, &additional_headers);
1251 CHECK_CALLED(BeginningTransaction);
1252 IHttpNegotiate_Release(http_negotiate);
1253 ok(hres == S_OK, "BeginningTransction failed: %08x\n", hres);
1254 ok(additional_headers == NULL, "additional_headers=%p\n", additional_headers);
1256 SET_EXPECT(QueryService_HttpNegotiate);
1257 hres = IServiceProvider_QueryService(service_provider, &IID_IHttpNegotiate2,
1258 &IID_IHttpNegotiate2, (void**)&http_negotiate2);
1259 CHECK_CALLED(QueryService_HttpNegotiate);
1260 ok(hres == S_OK, "QueryService failed: %08x\n", hres);
1263 SET_EXPECT(GetRootSecurityId);
1264 hres = IHttpNegotiate2_GetRootSecurityId(http_negotiate2, sec_id, &size, 0);
1265 CHECK_CALLED(GetRootSecurityId);
1266 IHttpNegotiate2_Release(http_negotiate2);
1267 ok(hres == E_FAIL, "GetRootSecurityId failed: %08x, expected E_FAIL\n", hres);
1268 ok(size == 13, "size=%d\n", size);
1270 IServiceProvider_Release(service_provider);
1272 CreateThread(NULL, 0, thread_proc, NULL, 0, &tid);
1277 SET_EXPECT(ReportProgress_CACHEFILENAMEAVAILABLE);
1278 hres = IInternetProtocolSink_ReportProgress(pOIProtSink,
1279 BINDSTATUS_CACHEFILENAMEAVAILABLE, expect_wsz = emptyW);
1280 ok(hres == S_OK, "ReportProgress(BINDSTATUS_CACHEFILENAMEAVAILABLE) failed: %08x\n", hres);
1281 CHECK_CALLED(ReportProgress_CACHEFILENAMEAVAILABLE);
1283 if(mimefilter_test) {
1284 SET_EXPECT(MimeFilter_CreateInstance);
1285 SET_EXPECT(MimeFilter_Start);
1286 SET_EXPECT(ReportProgress_LOADINGMIMEHANDLER);
1288 SET_EXPECT(ReportProgress_MIMETYPEAVAILABLE);
1289 hres = IInternetProtocolSink_ReportProgress(pOIProtSink, BINDSTATUS_VERIFIEDMIMETYPEAVAILABLE,
1290 mimefilter_test ? gzipW : (expect_wsz = text_htmlW));
1292 "ReportProgress(BINDSTATUS_VERIFIEDMIMETYPEAVAILABLE) failed: %08x\n", hres);
1293 if(mimefilter_test) {
1294 CHECK_CALLED(MimeFilter_CreateInstance);
1295 CHECK_CALLED(MimeFilter_Start);
1296 CHECK_CALLED(ReportProgress_LOADINGMIMEHANDLER);
1297 todo_wine CHECK_CALLED(ReportProgress_MIMETYPEAVAILABLE);
1299 CHECK_CALLED(ReportProgress_MIMETYPEAVAILABLE);
1303 SET_EXPECT(MimeFilter_ReportData);
1305 SET_EXPECT(ReportData);
1306 hres = IInternetProtocolSink_ReportData(pOIProtSink,
1307 BSCF_FIRSTDATANOTIFICATION | BSCF_LASTDATANOTIFICATION, 13, 13);
1308 ok(hres == S_OK, "ReportData failed: %08x\n", hres);
1310 CHECK_CALLED(MimeFilter_ReportData);
1312 CHECK_CALLED(ReportData);
1314 if(tested_protocol == BIND_TEST) {
1315 hres = IInternetProtocol_Terminate(binding_protocol, 0);
1316 ok(hres == E_FAIL, "Termiante failed: %08x\n", hres);
1320 SET_EXPECT(MimeFilter_ReportResult);
1322 SET_EXPECT(ReportResult);
1323 hres = IInternetProtocolSink_ReportResult(pOIProtSink, S_OK, 0, NULL);
1324 ok(hres == S_OK, "ReportResult failed: %08x\n", hres);
1326 CHECK_CALLED(MimeFilter_ReportResult);
1328 CHECK_CALLED(ReportResult);
1333 static HRESULT WINAPI ProtocolEmul_Continue(IInternetProtocol *iface,
1334 PROTOCOLDATA *pProtocolData)
1339 CHECK_EXPECT(Continue);
1341 ok(pProtocolData != NULL, "pProtocolData == NULL\n");
1342 if(!pProtocolData || tested_protocol == BIND_TEST)
1345 ok(pProtocolData != &protocoldata, "pProtocolData == &protocoldata\n");
1346 ok(pProtocolData->grfFlags == protocoldata.grfFlags, "grfFlags wrong %x/%x\n",
1347 pProtocolData->grfFlags, protocoldata.grfFlags );
1348 ok(pProtocolData->dwState == protocoldata.dwState, "dwState wrong %x/%x\n",
1349 pProtocolData->dwState, protocoldata.dwState );
1350 ok(pProtocolData->pData == protocoldata.pData, "pData wrong %p/%p\n",
1351 pProtocolData->pData, protocoldata.pData );
1352 ok(pProtocolData->cbData == protocoldata.cbData, "cbData wrong %x/%x\n",
1353 pProtocolData->cbData, protocoldata.cbData );
1356 switch(prot_state) {
1358 IServiceProvider *service_provider;
1359 IHttpNegotiate *http_negotiate;
1360 static WCHAR header[] = {'?',0};
1362 hres = IInternetProtocolSink_QueryInterface(binding_sink, &IID_IServiceProvider,
1363 (void**)&service_provider);
1364 ok(hres == S_OK, "Could not get IServiceProvicder\n");
1366 SET_EXPECT(QueryService_HttpNegotiate);
1367 hres = IServiceProvider_QueryService(service_provider, &IID_IHttpNegotiate,
1368 &IID_IHttpNegotiate, (void**)&http_negotiate);
1369 IServiceProvider_Release(service_provider);
1370 CHECK_CALLED(QueryService_HttpNegotiate);
1371 ok(hres == S_OK, "Could not get IHttpNegotiate\n");
1373 SET_EXPECT(OnResponse);
1374 hres = IHttpNegotiate_OnResponse(http_negotiate, 200, header, NULL, NULL);
1375 IHttpNegotiate_Release(http_negotiate);
1376 CHECK_CALLED(OnResponse);
1377 IHttpNegotiate_Release(http_negotiate);
1378 ok(hres == S_OK, "OnResponse failed: %08x\n", hres);
1380 if(mimefilter_test) {
1381 SET_EXPECT(MimeFilter_CreateInstance);
1382 SET_EXPECT(MimeFilter_Start);
1383 SET_EXPECT(ReportProgress_LOADINGMIMEHANDLER);
1384 }else if(!(pi & PI_MIMEVERIFICATION)) {
1385 SET_EXPECT(ReportProgress_MIMETYPEAVAILABLE);
1387 hres = IInternetProtocolSink_ReportProgress(binding_sink,
1388 BINDSTATUS_MIMETYPEAVAILABLE, mimefilter_test ? gzipW : text_htmlW);
1389 if(mimefilter_test) {
1390 CHECK_CALLED(MimeFilter_CreateInstance);
1391 CHECK_CALLED(MimeFilter_Start);
1392 CHECK_CALLED(ReportProgress_LOADINGMIMEHANDLER);
1393 }else if(!(pi & PI_MIMEVERIFICATION)) {
1394 CHECK_CALLED(ReportProgress_MIMETYPEAVAILABLE);
1397 "ReportProgress(BINDSTATUS_MIMETYPEAVAILABLE) failed: %08x\n", hres);
1399 bscf |= BSCF_FIRSTDATANOTIFICATION;
1404 bscf = BSCF_INTERMEDIATEDATANOTIFICATION;
1409 if(mimefilter_test) {
1410 SET_EXPECT(MimeFilter_ReportData);
1411 }else if(pi & PI_MIMEVERIFICATION) {
1416 SET_EXPECT(ReportProgress_MIMETYPEAVAILABLE);
1419 SET_EXPECT(ReportData);
1421 SET_EXPECT(ReportData);
1424 hres = IInternetProtocolSink_ReportData(binding_sink, bscf, 100, 400);
1425 ok(hres == S_OK, "ReportData failed: %08x\n", hres);
1427 if(mimefilter_test) {
1428 SET_EXPECT(MimeFilter_ReportData);
1429 }else if(pi & PI_MIMEVERIFICATION) {
1434 CHECK_CALLED(ReportProgress_MIMETYPEAVAILABLE);
1437 CHECK_CALLED(ReportData);
1446 static HRESULT WINAPI ProtocolEmul_Terminate(IInternetProtocol *iface, DWORD dwOptions)
1448 CHECK_EXPECT(Terminate);
1449 ok(!dwOptions, "dwOptions=%d\n", dwOptions);
1453 static HRESULT WINAPI ProtocolEmul_Read(IInternetProtocol *iface, void *pv,
1454 ULONG cb, ULONG *pcbRead)
1456 if(mimefilter_test) {
1457 CHECK_EXPECT2(Read);
1458 }else if((pi & PI_MIMEVERIFICATION)) {
1459 CHECK_EXPECT2(Read);
1461 if(prot_read < 300) {
1462 ok(pv != expect_pv, "pv == expect_pv\n");
1464 ok(cb == 2048-prot_read, "cb=%d\n", cb);
1466 ok(cb == 700, "cb=%d\n", cb);
1468 ok(expect_pv <= pv && (BYTE*)pv < (BYTE*)expect_pv + cb, "pv != expect_pv\n");
1473 ok(pv == expect_pv, "pv != expect_pv\n");
1474 ok(cb == 1000, "cb=%d\n", cb);
1475 ok(!*pcbRead, "*pcbRead = %d\n", *pcbRead);
1477 ok(pcbRead != NULL, "pcbRead == NULL\n");
1479 if(prot_state == 3) {
1483 SET_EXPECT(MimeFilter_ReportResult);
1485 SET_EXPECT(ReportResult);
1486 hres = IInternetProtocolSink_ReportResult(binding_sink, S_OK, ERROR_SUCCESS, NULL);
1487 ok(hres == S_OK, "ReportResult failed: %08x\n", hres);
1489 CHECK_CALLED(MimeFilter_ReportResult);
1491 CHECK_CALLED(ReportResult);
1496 if((async_read_pending = !async_read_pending)) {
1498 return tested_protocol == HTTP_TEST || tested_protocol == HTTPS_TEST ? E_PENDING : S_FALSE;
1501 memset(pv, 'x', 100);
1502 prot_read += *pcbRead = 100;
1506 static HRESULT WINAPI ProtocolEmul_LockRequest(IInternetProtocol *iface, DWORD dwOptions)
1508 CHECK_EXPECT(LockRequest);
1509 ok(dwOptions == 0, "dwOptions=%x\n", dwOptions);
1513 static HRESULT WINAPI ProtocolEmul_UnlockRequest(IInternetProtocol *iface)
1515 CHECK_EXPECT(UnlockRequest);
1519 static const IInternetProtocolVtbl ProtocolVtbl = {
1520 ProtocolEmul_QueryInterface,
1524 ProtocolEmul_Continue,
1526 ProtocolEmul_Terminate,
1531 ProtocolEmul_LockRequest,
1532 ProtocolEmul_UnlockRequest
1535 static IInternetProtocol Protocol = { &ProtocolVtbl };
1537 static HRESULT WINAPI MimeProtocol_QueryInterface(IInternetProtocol *iface, REFIID riid, void **ppv)
1539 if(IsEqualGUID(&IID_IUnknown, riid) || IsEqualGUID(&IID_IInternetProtocol, riid)) {
1544 if(IsEqualGUID(&IID_IInternetProtocolSink, riid)) {
1545 *ppv = &mime_protocol_sink;
1549 ok(0, "unexpected riid %s\n", debugstr_guid(riid));
1551 return E_NOINTERFACE;
1554 static HRESULT WINAPI MimeProtocol_Start(IInternetProtocol *iface, LPCWSTR szUrl,
1555 IInternetProtocolSink *pOIProtSink, IInternetBindInfo *pOIBindInfo,
1556 DWORD grfPI, HANDLE_PTR dwReserved)
1558 PROTOCOLFILTERDATA *data;
1559 LPOLESTR url_str = NULL;
1565 CHECK_EXPECT(MimeFilter_Start);
1567 ok(!strcmp_ww(szUrl, gzipW), "wrong url %s\n", debugstr_w(szUrl));
1568 ok(grfPI == (PI_FILTER_MODE|PI_FORCE_ASYNC), "grfPI=%x, expected PI_FILTER_MODE|PI_FORCE_ASYNC\n", grfPI);
1569 ok(dwReserved, "dwReserved == 0\n");
1570 ok(pOIProtSink != NULL, "pOIProtSink == NULL\n");
1571 ok(pOIBindInfo != NULL, "pOIBindInfo == NULL\n");
1574 ok(pOIProtSink != binding_sink, "pOIProtSink == protocol_sink\n");
1575 ok(pOIBindInfo == prot_bind_info, "pOIBindInfo != bind_info\n");
1577 ok(pOIProtSink == &protocol_sink, "pOIProtSink != protocol_sink\n");
1578 ok(pOIBindInfo == &bind_info, "pOIBindInfo != bind_info\n");
1581 data = (void*)dwReserved;
1582 ok(data->cbSize == sizeof(*data), "data->cbSize = %d\n", data->cbSize);
1583 ok(!data->pProtocolSink, "data->pProtocolSink != NULL\n");
1584 ok(data->pProtocol != NULL, "data->pProtocol == NULL\n");
1585 ok(!data->pUnk, "data->pUnk != NULL\n");
1586 ok(!data->dwFilterFlags, "data->dwProtocolFlags = %x\n", data->dwFilterFlags);
1588 IInternetProtocolSink *prot_sink;
1590 IInternetProtocol_QueryInterface(data->pProtocol, &IID_IInternetProtocolSink, (void**)&prot_sink);
1591 ok(prot_sink == pOIProtSink, "QI(data->pProtocol, IID_IInternetProtocolSink) != pOIProtSink\n");
1592 IInternetProtocolSink_Release(prot_sink);
1594 ok(data->pProtocol != binding_protocol, "data->pProtocol == binding_protocol\n");
1596 filtered_protocol = data->pProtocol;
1597 IInternetProtocol_AddRef(filtered_protocol);
1599 IInternetProtocol *prot;
1601 IInternetProtocol_QueryInterface(data->pProtocol, &IID_IInternetProtocol, (void**)&prot);
1602 ok(prot == async_protocol, "QI(data->pProtocol, IID_IInternetProtocol) != async_protocol\n");
1603 IInternetProtocol_Release(prot);
1605 ok(data->pProtocol != async_protocol, "data->pProtocol == async_protocol\n");
1608 filtered_sink = pOIProtSink;
1610 SET_EXPECT(ReportProgress_DECODING);
1611 hres = IInternetProtocolSink_ReportProgress(pOIProtSink, BINDSTATUS_DECODING, gzipW);
1612 ok(hres == S_OK, "ReportProgress(BINDSTATUS_DECODING) failed: %08x\n", hres);
1613 CHECK_CALLED(ReportProgress_DECODING);
1615 SET_EXPECT(GetBindInfo);
1616 memset(&bindinfo, 0, sizeof(bindinfo));
1617 bindinfo.cbSize = sizeof(bindinfo);
1618 hres = IInternetBindInfo_GetBindInfo(pOIBindInfo, &cbindf, &bindinfo);
1619 ok(hres == S_OK, "GetBindInfo failed: %08x\n", hres);
1620 ok(cbindf == bindf, "cbindf = %x\n", cbindf);
1621 CHECK_CALLED(GetBindInfo);
1623 SET_EXPECT(GetBindString_URL);
1624 hres = IInternetBindInfo_GetBindString(pOIBindInfo, BINDSTRING_URL, &url_str, 1, &fetched);
1625 ok(hres == S_OK, "GetBindString(BINDSTRING_URL) failed: %08x\n", hres);
1626 ok(fetched == 1, "fetched = %d\n", fetched);
1627 ok(!strcmp_ww(url_str, binding_urls[tested_protocol]), "wrong url_str %s\n", debugstr_w(url_str));
1628 CoTaskMemFree(url_str);
1629 CHECK_CALLED(GetBindString_URL);
1634 static HRESULT WINAPI Protocol_Continue(IInternetProtocol *iface,
1635 PROTOCOLDATA *pProtocolData)
1637 CHECK_EXPECT(MimeFilter_Continue);
1641 static HRESULT WINAPI MimeProtocol_Terminate(IInternetProtocol *iface, DWORD dwOptions)
1645 CHECK_EXPECT(MimeFilter_Terminate);
1647 ok(!dwOptions, "dwOptions = %x\n", dwOptions);
1649 SET_EXPECT(Terminate);
1650 hres = IInternetProtocol_Terminate(filtered_protocol, dwOptions);
1651 ok(hres == S_OK, "Terminate failed: %08x\n", hres);
1652 CHECK_CALLED(Terminate);
1657 static HRESULT WINAPI MimeProtocol_Read(IInternetProtocol *iface, void *pv,
1658 ULONG cb, ULONG *pcbRead)
1664 CHECK_EXPECT(MimeFilter_Read);
1666 ok(pv != NULL, "pv == NULL\n");
1667 ok(cb != 0, "cb == 0\n");
1668 ok(pcbRead != NULL, "pcbRead == NULL\n");
1671 hres = IInternetProtocol_Read(filtered_protocol, buf, sizeof(buf), &read);
1672 ok(hres == S_OK || hres == S_FALSE || hres == E_PENDING, "Read failed: %08x\n", hres);
1676 ok(*pcbRead == 0, "*pcbRead=%d, expected 0\n", *pcbRead);
1680 memset(pv, 'x', read);
1684 static HRESULT WINAPI MimeProtocol_LockRequest(IInternetProtocol *iface, DWORD dwOptions)
1688 CHECK_EXPECT(MimeFilter_LockRequest);
1690 ok(!dwOptions, "dwOptions = %x\n", dwOptions);
1692 SET_EXPECT(LockRequest);
1693 hres = IInternetProtocol_LockRequest(filtered_protocol, dwOptions);
1694 ok(hres == S_OK, "LockRequest failed: %08x\n", hres);
1695 CHECK_CALLED(LockRequest);
1700 static HRESULT WINAPI MimeProtocol_UnlockRequest(IInternetProtocol *iface)
1704 CHECK_EXPECT(MimeFilter_UnlockRequest);
1706 SET_EXPECT(UnlockRequest);
1707 hres = IInternetProtocol_UnlockRequest(filtered_protocol);
1708 ok(hres == S_OK, "UnlockRequest failed: %08x\n", hres);
1709 CHECK_CALLED(UnlockRequest);
1714 static const IInternetProtocolVtbl MimeProtocolVtbl = {
1715 MimeProtocol_QueryInterface,
1721 MimeProtocol_Terminate,
1726 MimeProtocol_LockRequest,
1727 MimeProtocol_UnlockRequest
1730 static IInternetProtocol MimeProtocol = { &MimeProtocolVtbl };
1732 static HRESULT WINAPI ClassFactory_QueryInterface(IClassFactory *iface, REFIID riid, void **ppv)
1734 ok(0, "unexpected call\n");
1735 return E_NOINTERFACE;
1738 static ULONG WINAPI ClassFactory_AddRef(IClassFactory *iface)
1743 static ULONG WINAPI ClassFactory_Release(IClassFactory *iface)
1748 static HRESULT WINAPI ClassFactory_CreateInstance(IClassFactory *iface, IUnknown *pOuter,
1749 REFIID riid, void **ppv)
1751 CHECK_EXPECT(CreateInstance);
1753 ok(pOuter == (IUnknown*)prot_bind_info, "pOuter != protocol_unk\n");
1754 ok(IsEqualGUID(&IID_IUnknown, riid), "unexpected riid %s\n", debugstr_guid(riid));
1755 ok(ppv != NULL, "ppv == NULL\n");
1761 static HRESULT WINAPI ClassFactory_LockServer(IClassFactory *iface, BOOL dolock)
1763 ok(0, "unexpected call\n");
1767 static const IClassFactoryVtbl ClassFactoryVtbl = {
1768 ClassFactory_QueryInterface,
1769 ClassFactory_AddRef,
1770 ClassFactory_Release,
1771 ClassFactory_CreateInstance,
1772 ClassFactory_LockServer
1775 static IClassFactory ClassFactory = { &ClassFactoryVtbl };
1777 static HRESULT WINAPI MimeFilter_CreateInstance(IClassFactory *iface, IUnknown *outer, REFIID riid, void **ppv)
1779 CHECK_EXPECT(MimeFilter_CreateInstance);
1781 ok(!outer, "outer = %p\n", outer);
1782 ok(IsEqualGUID(&IID_IInternetProtocol, riid), "unexpected riid %s\n", debugstr_guid(riid));
1784 *ppv = &MimeProtocol;
1788 static const IClassFactoryVtbl MimeFilterCFVtbl = {
1789 ClassFactory_QueryInterface,
1790 ClassFactory_AddRef,
1791 ClassFactory_Release,
1792 MimeFilter_CreateInstance,
1793 ClassFactory_LockServer
1796 static IClassFactory mimefilter_cf = { &MimeFilterCFVtbl };
1798 #define TEST_BINDING 1
1799 #define TEST_FILTER 2
1801 static void init_test(int prot, DWORD flags)
1803 tested_protocol = prot;
1804 binding_test = (flags & TEST_BINDING) != 0;
1805 first_data_notif = TRUE;
1808 async_read_pending = TRUE;
1809 mimefilter_test = (flags & TEST_FILTER) != 0;
1811 ResetEvent(event_complete);
1812 ResetEvent(event_complete2);
1813 async_protocol = binding_protocol = filtered_protocol = NULL;
1814 filtered_sink = NULL;
1817 static void test_priority(IInternetProtocol *protocol)
1819 IInternetPriority *priority;
1823 hres = IInternetProtocol_QueryInterface(protocol, &IID_IInternetPriority,
1825 ok(hres == S_OK, "QueryInterface(IID_IInternetPriority) failed: %08x\n", hres);
1829 hres = IInternetPriority_GetPriority(priority, &pr);
1830 ok(hres == S_OK, "GetPriority failed: %08x\n", hres);
1831 ok(pr == 0, "pr=%d, expected 0\n", pr);
1833 hres = IInternetPriority_SetPriority(priority, 1);
1834 ok(hres == S_OK, "SetPriority failed: %08x\n", hres);
1836 hres = IInternetPriority_GetPriority(priority, &pr);
1837 ok(hres == S_OK, "GetPriority failed: %08x\n", hres);
1838 ok(pr == 1, "pr=%d, expected 1\n", pr);
1840 IInternetPriority_Release(priority);
1843 static BOOL file_protocol_start(IInternetProtocol *protocol, LPCWSTR url, BOOL is_first)
1847 SET_EXPECT(GetBindInfo);
1848 if(!(bindf & BINDF_FROMURLMON))
1849 SET_EXPECT(ReportProgress_DIRECTBIND);
1851 SET_EXPECT(ReportProgress_SENDINGREQUEST);
1852 SET_EXPECT(ReportProgress_CACHEFILENAMEAVAILABLE);
1853 if(bindf & BINDF_FROMURLMON)
1854 SET_EXPECT(ReportProgress_VERIFIEDMIMETYPEAVAILABLE);
1856 SET_EXPECT(ReportProgress_MIMETYPEAVAILABLE);
1858 SET_EXPECT(ReportData);
1860 SET_EXPECT(ReportResult);
1862 expect_hrResult = S_OK;
1864 hres = IInternetProtocol_Start(protocol, url, &protocol_sink, &bind_info, 0, 0);
1865 if(hres == INET_E_RESOURCE_NOT_FOUND) {
1866 win_skip("Start failed\n");
1869 ok(hres == S_OK, "Start failed: %08x\n", hres);
1871 CHECK_CALLED(GetBindInfo);
1872 if(!(bindf & BINDF_FROMURLMON))
1873 CHECK_CALLED(ReportProgress_DIRECTBIND);
1875 CHECK_CALLED(ReportProgress_SENDINGREQUEST);
1876 CHECK_CALLED(ReportProgress_CACHEFILENAMEAVAILABLE);
1877 if(bindf & BINDF_FROMURLMON)
1878 CHECK_CALLED(ReportProgress_VERIFIEDMIMETYPEAVAILABLE);
1880 CHECK_CALLED(ReportProgress_MIMETYPEAVAILABLE);
1882 CHECK_CALLED(ReportData);
1884 CHECK_CALLED(ReportResult);
1889 static void test_file_protocol_url(LPCWSTR url)
1891 IInternetProtocolInfo *protocol_info;
1893 IClassFactory *factory;
1896 hres = CoGetClassObject(&CLSID_FileProtocol, CLSCTX_INPROC_SERVER, NULL,
1897 &IID_IUnknown, (void**)&unk);
1898 ok(hres == S_OK, "CoGetClassObject failed: %08x\n", hres);
1902 hres = IUnknown_QueryInterface(unk, &IID_IInternetProtocolInfo, (void**)&protocol_info);
1903 ok(hres == E_NOINTERFACE,
1904 "Could not get IInternetProtocolInfo interface: %08x, expected E_NOINTERFACE\n", hres);
1906 hres = IUnknown_QueryInterface(unk, &IID_IClassFactory, (void**)&factory);
1907 ok(hres == S_OK, "Could not get IClassFactory interface\n");
1908 if(SUCCEEDED(hres)) {
1909 IInternetProtocol *protocol;
1912 hres = IClassFactory_CreateInstance(factory, NULL, &IID_IInternetProtocol, (void**)&protocol);
1913 ok(hres == S_OK, "Could not get IInternetProtocol: %08x\n", hres);
1915 if(SUCCEEDED(hres)) {
1916 if(file_protocol_start(protocol, url, TRUE)) {
1917 hres = IInternetProtocol_Read(protocol, buf, 2, &cb);
1918 ok(hres == S_OK, "Read failed: %08x\n", hres);
1919 ok(cb == 2, "cb=%u expected 2\n", cb);
1920 hres = IInternetProtocol_Read(protocol, buf, sizeof(buf), &cb);
1921 ok(hres == S_FALSE, "Read failed: %08x\n", hres);
1922 hres = IInternetProtocol_Read(protocol, buf, sizeof(buf), &cb);
1923 ok(hres == S_FALSE, "Read failed: %08x expected S_FALSE\n", hres);
1924 ok(cb == 0, "cb=%u expected 0\n", cb);
1925 hres = IInternetProtocol_UnlockRequest(protocol);
1926 ok(hres == S_OK, "UnlockRequest failed: %08x\n", hres);
1929 if(file_protocol_start(protocol, url, FALSE)) {
1930 hres = IInternetProtocol_Read(protocol, buf, 2, &cb);
1931 ok(hres == S_FALSE, "Read failed: %08x\n", hres);
1932 hres = IInternetProtocol_LockRequest(protocol, 0);
1933 ok(hres == S_OK, "LockRequest failed: %08x\n", hres);
1934 hres = IInternetProtocol_UnlockRequest(protocol);
1935 ok(hres == S_OK, "UnlockRequest failed: %08x\n", hres);
1938 IInternetProtocol_Release(protocol);
1941 hres = IClassFactory_CreateInstance(factory, NULL, &IID_IInternetProtocol, (void**)&protocol);
1942 ok(hres == S_OK, "Could not get IInternetProtocol: %08x\n", hres);
1944 if(SUCCEEDED(hres)) {
1945 if(file_protocol_start(protocol, url, TRUE)) {
1946 hres = IInternetProtocol_LockRequest(protocol, 0);
1947 ok(hres == S_OK, "LockRequest failed: %08x\n", hres);
1948 hres = IInternetProtocol_Terminate(protocol, 0);
1949 ok(hres == S_OK, "Terminate failed: %08x\n", hres);
1950 hres = IInternetProtocol_Read(protocol, buf, 2, &cb);
1951 ok(hres == S_OK, "Read failed: %08x\n\n", hres);
1952 hres = IInternetProtocol_UnlockRequest(protocol);
1953 ok(hres == S_OK, "UnlockRequest failed: %08x\n", hres);
1954 hres = IInternetProtocol_Read(protocol, buf, 2, &cb);
1955 ok(hres == S_OK, "Read failed: %08x\n", hres);
1956 hres = IInternetProtocol_Terminate(protocol, 0);
1957 ok(hres == S_OK, "Terminate failed: %08x\n", hres);
1960 IInternetProtocol_Release(protocol);
1963 hres = IClassFactory_CreateInstance(factory, NULL, &IID_IInternetProtocol, (void**)&protocol);
1964 ok(hres == S_OK, "Could not get IInternetProtocol: %08x\n", hres);
1966 if(SUCCEEDED(hres)) {
1967 if(file_protocol_start(protocol, url, TRUE)) {
1968 hres = IInternetProtocol_Terminate(protocol, 0);
1969 ok(hres == S_OK, "Terminate failed: %08x\n", hres);
1970 hres = IInternetProtocol_Read(protocol, buf, 2, &cb);
1971 ok(hres == S_OK, "Read failed: %08x\n", hres);
1972 ok(cb == 2, "cb=%u expected 2\n", cb);
1975 IInternetProtocol_Release(protocol);
1978 IClassFactory_Release(factory);
1981 IUnknown_Release(unk);
1984 static void test_file_protocol_fail(void)
1986 IInternetProtocol *protocol;
1989 static const WCHAR index_url2[] =
1990 {'f','i','l','e',':','/','/','i','n','d','e','x','.','h','t','m','l',0};
1992 hres = CoCreateInstance(&CLSID_FileProtocol, NULL, CLSCTX_INPROC_SERVER|CLSCTX_INPROC_HANDLER,
1993 &IID_IInternetProtocol, (void**)&protocol);
1994 ok(hres == S_OK, "CoCreateInstance failed: %08x\n", hres);
1998 SET_EXPECT(GetBindInfo);
1999 expect_hrResult = MK_E_SYNTAX;
2000 hres = IInternetProtocol_Start(protocol, wszIndexHtml, &protocol_sink, &bind_info, 0, 0);
2001 ok(hres == MK_E_SYNTAX ||
2002 hres == E_INVALIDARG,
2003 "Start failed: %08x, expected MK_E_SYNTAX or E_INVALIDARG\n", hres);
2004 CLEAR_CALLED(GetBindInfo); /* GetBindInfo not called in IE7 */
2006 SET_EXPECT(GetBindInfo);
2007 if(!(bindf & BINDF_FROMURLMON))
2008 SET_EXPECT(ReportProgress_DIRECTBIND);
2009 SET_EXPECT(ReportProgress_SENDINGREQUEST);
2010 SET_EXPECT(ReportResult);
2011 expect_hrResult = INET_E_RESOURCE_NOT_FOUND;
2012 hres = IInternetProtocol_Start(protocol, index_url, &protocol_sink, &bind_info, 0, 0);
2013 ok(hres == INET_E_RESOURCE_NOT_FOUND,
2014 "Start failed: %08x expected INET_E_RESOURCE_NOT_FOUND\n", hres);
2015 CHECK_CALLED(GetBindInfo);
2016 if(!(bindf & BINDF_FROMURLMON))
2017 CHECK_CALLED(ReportProgress_DIRECTBIND);
2018 CHECK_CALLED(ReportProgress_SENDINGREQUEST);
2019 CHECK_CALLED(ReportResult);
2021 IInternetProtocol_Release(protocol);
2023 hres = CoCreateInstance(&CLSID_FileProtocol, NULL, CLSCTX_INPROC_SERVER|CLSCTX_INPROC_HANDLER,
2024 &IID_IInternetProtocol, (void**)&protocol);
2025 ok(hres == S_OK, "CoCreateInstance failed: %08x\n", hres);
2029 SET_EXPECT(GetBindInfo);
2030 if(!(bindf & BINDF_FROMURLMON))
2031 SET_EXPECT(ReportProgress_DIRECTBIND);
2032 SET_EXPECT(ReportProgress_SENDINGREQUEST);
2033 SET_EXPECT(ReportResult);
2034 expect_hrResult = INET_E_RESOURCE_NOT_FOUND;
2036 hres = IInternetProtocol_Start(protocol, index_url2, &protocol_sink, &bind_info, 0, 0);
2037 ok(hres == INET_E_RESOURCE_NOT_FOUND,
2038 "Start failed: %08x, expected INET_E_RESOURCE_NOT_FOUND\n", hres);
2039 CHECK_CALLED(GetBindInfo);
2040 if(!(bindf & BINDF_FROMURLMON))
2041 CHECK_CALLED(ReportProgress_DIRECTBIND);
2042 CHECK_CALLED(ReportProgress_SENDINGREQUEST);
2043 CHECK_CALLED(ReportResult);
2045 SET_EXPECT(GetBindInfo);
2046 hres = IInternetProtocol_Start(protocol, NULL, &protocol_sink, &bind_info, 0, 0);
2047 ok(hres == E_INVALIDARG, "Start failed: %08x, expected E_INVALIDARG\n", hres);
2048 CLEAR_CALLED(GetBindInfo); /* GetBindInfo not called in IE7 */
2050 SET_EXPECT(GetBindInfo);
2051 hres = IInternetProtocol_Start(protocol, emptyW, &protocol_sink, &bind_info, 0, 0);
2052 ok(hres == E_INVALIDARG, "Start failed: %08x, expected E_INVALIDARG\n", hres);
2053 CLEAR_CALLED(GetBindInfo); /* GetBindInfo not called in IE7 */
2055 IInternetProtocol_Release(protocol);
2058 static void test_file_protocol(void) {
2059 WCHAR buf[INTERNET_MAX_URL_LENGTH], file_name_buf[MAX_PATH];
2064 static const WCHAR wszFile[] = {'f','i','l','e',':',0};
2065 static const WCHAR wszFile2[] = {'f','i','l','e',':','/','/',0};
2066 static const WCHAR wszFile3[] = {'f','i','l','e',':','/','/','/',0};
2067 static const char html_doc[] = "<HTML></HTML>";
2069 trace("Testing file protocol...\n");
2070 init_test(FILE_TEST, 0);
2072 SetLastError(0xdeadbeef);
2073 file = CreateFileW(wszIndexHtml, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS,
2074 FILE_ATTRIBUTE_NORMAL, NULL);
2075 if(!file && GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)
2077 win_skip("Detected Win9x or WinMe\n");
2080 ok(file != INVALID_HANDLE_VALUE, "CreateFile failed\n");
2081 if(file == INVALID_HANDLE_VALUE)
2083 WriteFile(file, html_doc, sizeof(html_doc)-1, &size, NULL);
2086 file_name = wszIndexHtml;
2088 test_file_protocol_url(index_url);
2089 bindf = BINDF_FROMURLMON;
2090 test_file_protocol_url(index_url);
2091 bindf = BINDF_FROMURLMON | BINDF_NEEDFILE;
2092 test_file_protocol_url(index_url);
2094 memcpy(buf, wszFile, sizeof(wszFile));
2095 len = sizeof(wszFile)/sizeof(WCHAR)-1;
2096 len += GetCurrentDirectoryW(sizeof(buf)/sizeof(WCHAR)-len, buf+len);
2098 memcpy(buf+len, wszIndexHtml, sizeof(wszIndexHtml));
2100 file_name = buf + sizeof(wszFile)/sizeof(WCHAR)-1;
2102 test_file_protocol_url(buf);
2103 bindf = BINDF_FROMURLMON;
2104 test_file_protocol_url(buf);
2106 memcpy(buf, wszFile2, sizeof(wszFile2));
2107 len = GetCurrentDirectoryW(sizeof(file_name_buf)/sizeof(WCHAR), file_name_buf);
2108 file_name_buf[len++] = '\\';
2109 memcpy(file_name_buf+len, wszIndexHtml, sizeof(wszIndexHtml));
2110 lstrcpyW(buf+sizeof(wszFile2)/sizeof(WCHAR)-1, file_name_buf);
2111 file_name = file_name_buf;
2113 test_file_protocol_url(buf);
2114 bindf = BINDF_FROMURLMON;
2115 test_file_protocol_url(buf);
2117 buf[sizeof(wszFile2)/sizeof(WCHAR)] = '|';
2118 test_file_protocol_url(buf);
2120 memcpy(buf, wszFile3, sizeof(wszFile3));
2121 len = sizeof(wszFile3)/sizeof(WCHAR)-1;
2122 len += GetCurrentDirectoryW(sizeof(buf)/sizeof(WCHAR)-len, buf+len);
2124 memcpy(buf+len, wszIndexHtml, sizeof(wszIndexHtml));
2126 file_name = buf + sizeof(wszFile3)/sizeof(WCHAR)-1;
2128 test_file_protocol_url(buf);
2129 bindf = BINDF_FROMURLMON;
2130 test_file_protocol_url(buf);
2132 DeleteFileW(wszIndexHtml);
2135 test_file_protocol_fail();
2136 bindf = BINDF_FROMURLMON;
2137 test_file_protocol_fail();
2140 static BOOL http_protocol_start(LPCWSTR url, BOOL is_first)
2142 static BOOL got_user_agent = FALSE;
2145 first_data_notif = TRUE;
2148 SET_EXPECT(GetBindInfo);
2149 if (!(bindf & BINDF_FROMURLMON))
2150 SET_EXPECT(ReportProgress_DIRECTBIND);
2151 SET_EXPECT(GetBindString_USER_AGENT);
2152 SET_EXPECT(GetBindString_ACCEPT_MIMES);
2153 SET_EXPECT(QueryService_HttpNegotiate);
2154 SET_EXPECT(BeginningTransaction);
2155 SET_EXPECT(GetRootSecurityId);
2157 SET_EXPECT(GetBindString_POST_COOKIE);
2159 hres = IInternetProtocol_Start(async_protocol, url, &protocol_sink, &bind_info, 0, 0);
2160 ok(hres == S_OK, "Start failed: %08x\n", hres);
2164 CHECK_CALLED(GetBindInfo);
2165 if (!(bindf & BINDF_FROMURLMON))
2166 CHECK_CALLED(ReportProgress_DIRECTBIND);
2167 if (!got_user_agent)
2169 CHECK_CALLED(GetBindString_USER_AGENT);
2170 got_user_agent = TRUE;
2174 /* user agent only retrieved once, even with different URLs */
2175 CHECK_NOT_CALLED(GetBindString_USER_AGENT);
2177 CHECK_CALLED(GetBindString_ACCEPT_MIMES);
2178 CHECK_CALLED(QueryService_HttpNegotiate);
2179 CHECK_CALLED(BeginningTransaction);
2180 /* GetRootSecurityId called on WinXP but not on Win98 */
2181 CLEAR_CALLED(GetRootSecurityId);
2183 CHECK_CALLED(GetBindString_POST_COOKIE);
2188 static void test_protocol_terminate(IInternetProtocol *protocol)
2194 hres = IInternetProtocol_LockRequest(protocol, 0);
2195 ok(hres == S_OK, "LockRequest failed: %08x\n", hres);
2197 hres = IInternetProtocol_Read(protocol, buf, 1, &cb);
2198 ok(hres == S_FALSE, "Read failed: %08x\n", hres);
2200 hres = IInternetProtocol_Terminate(protocol, 0);
2201 ok(hres == S_OK, "Terminate failed: %08x\n", hres);
2203 /* This wait is to give the internet handles being freed in Terminate
2204 * enough time to actually terminate in all cases. Internet handles
2205 * terminate asynchronously and native reuses the main InternetOpen
2206 * handle. The only case in which this seems to be necessary is on
2207 * wine with native wininet and urlmon, resulting in the next time
2208 * test_http_protocol_url being called the first data notification actually
2209 * being an extra last data notification from the previous connection
2210 * about once out of every ten times. */
2213 hres = IInternetProtocol_UnlockRequest(protocol);
2214 ok(hres == S_OK, "UnlockRequest failed: %08x\n", hres);
2217 static void test_http_info(IInternetProtocol *protocol)
2219 IWinInetHttpInfo *info;
2222 hres = IInternetProtocol_QueryInterface(protocol, &IID_IWinInetHttpInfo, (void**)&info);
2223 ok(hres == S_OK, "Could not get IWinInterHttpInfo iface: %08x\n", hres);
2227 IWinInetHttpInfo_Release(info);
2230 /* is_first refers to whether this is the first call to this function
2232 static void test_http_protocol_url(LPCWSTR url, BOOL is_https, BOOL is_first)
2234 IInternetProtocolInfo *protocol_info;
2235 IClassFactory *factory;
2240 http_is_first = is_first;
2242 hres = CoGetClassObject(is_https ? &CLSID_HttpSProtocol : &CLSID_HttpProtocol,
2243 CLSCTX_INPROC_SERVER, NULL, &IID_IUnknown, (void**)&unk);
2244 ok(hres == S_OK, "CoGetClassObject failed: %08x\n", hres);
2248 hres = IUnknown_QueryInterface(unk, &IID_IInternetProtocolInfo, (void**)&protocol_info);
2249 ok(hres == E_NOINTERFACE,
2250 "Could not get IInternetProtocolInfo interface: %08x, expected E_NOINTERFACE\n",
2253 hres = IUnknown_QueryInterface(unk, &IID_IClassFactory, (void**)&factory);
2254 ok(hres == S_OK, "Could not get IClassFactory interface\n");
2255 IUnknown_Release(unk);
2259 hres = IClassFactory_CreateInstance(factory, NULL, &IID_IInternetProtocol,
2260 (void**)&async_protocol);
2261 ok(hres == S_OK, "Could not get IInternetProtocol: %08x\n", hres);
2262 if(SUCCEEDED(hres)) {
2267 test_priority(async_protocol);
2268 test_http_info(async_protocol);
2270 SET_EXPECT(ReportProgress_FINDINGRESOURCE);
2271 SET_EXPECT(ReportProgress_CONNECTING);
2272 SET_EXPECT(ReportProgress_SENDINGREQUEST);
2273 SET_EXPECT(ReportProgress_PROXYDETECTING);
2275 SET_EXPECT(ReportProgress_CACHEFILENAMEAVAILABLE);
2277 SET_EXPECT(QueryService_HttpSecurity);
2278 if(!(bindf & BINDF_FROMURLMON)) {
2279 SET_EXPECT(OnResponse);
2280 SET_EXPECT(ReportProgress_RAWMIMETYPE);
2281 SET_EXPECT(ReportData);
2286 if(!http_protocol_start(url, is_first))
2289 SET_EXPECT(ReportResult);
2290 expect_hrResult = S_OK;
2292 hres = IInternetProtocol_Read(async_protocol, buf, 1, &cb);
2293 ok((hres == E_PENDING && cb==0) ||
2294 (hres == S_OK && cb==1), "Read failed: %08x (%d bytes)\n", hres, cb);
2296 WaitForSingleObject(event_complete, INFINITE);
2297 if(bindf & BINDF_FROMURLMON)
2298 CHECK_CALLED(Switch);
2300 CHECK_CALLED(ReportData);
2302 CLEAR_CALLED(QueryService_HttpSecurity);
2305 if(bindf & BINDF_FROMURLMON)
2308 SET_EXPECT(ReportData);
2309 hres = IInternetProtocol_Read(async_protocol, buf, sizeof(buf), &cb);
2310 if(hres == E_PENDING) {
2311 hres = IInternetProtocol_Read(async_protocol, buf, 1, &cb);
2312 ok((hres == E_PENDING && cb==0) ||
2313 (hres == S_OK && cb==1), "Read failed: %08x (%d bytes)\n", hres, cb);
2314 WaitForSingleObject(event_complete, INFINITE);
2315 if(bindf & BINDF_FROMURLMON)
2316 CHECK_CALLED(Switch);
2318 CHECK_CALLED(ReportData);
2320 if(bindf & BINDF_FROMURLMON)
2321 CHECK_NOT_CALLED(Switch);
2323 CHECK_NOT_CALLED(ReportData);
2327 ok(hres == S_FALSE, "Read failed: %08x\n", hres);
2328 CHECK_CALLED(ReportResult);
2330 CLEAR_CALLED(ReportProgress_SENDINGREQUEST);
2332 test_protocol_terminate(async_protocol);
2333 ref = IInternetProtocol_Release(async_protocol);
2334 ok(!ref, "ref=%x\n", hres);
2337 IClassFactory_Release(factory);
2340 static void test_http_protocol(void)
2342 static const WCHAR winehq_url[] =
2343 {'h','t','t','p',':','/','/','w','w','w','.','w','i','n','e','h','q','.',
2344 'o','r','g','/','s','i','t','e','/','a','b','o','u','t',0};
2345 static const WCHAR posttest_url[] =
2346 {'h','t','t','p',':','/','/','c','r','o','s','s','o','v','e','r','.',
2347 'c','o','d','e','w','e','a','v','e','r','s','.','c','o','m','/',
2348 'p','o','s','t','t','e','s','t','.','p','h','p',0};
2350 trace("Testing http protocol (not from urlmon)...\n");
2351 tested_protocol = HTTP_TEST;
2352 bindf = BINDF_ASYNCHRONOUS | BINDF_ASYNCSTORAGE | BINDF_PULLDATA;
2353 test_http_protocol_url(winehq_url, FALSE, TRUE);
2355 trace("Testing http protocol (from urlmon)...\n");
2356 bindf = BINDF_ASYNCHRONOUS | BINDF_ASYNCSTORAGE | BINDF_PULLDATA | BINDF_FROMURLMON;
2357 test_http_protocol_url(winehq_url, FALSE, FALSE);
2359 trace("Testing http protocol (to file)...\n");
2360 bindf = BINDF_ASYNCHRONOUS | BINDF_ASYNCSTORAGE | BINDF_PULLDATA | BINDF_FROMURLMON | BINDF_NEEDFILE;
2361 test_http_protocol_url(winehq_url, FALSE, FALSE);
2363 trace("Testing http protocol (post data)...\n");
2364 http_post_test = TRUE;
2365 /* Without this flag we get a ReportProgress_CACHEFILENAMEAVAILABLE
2366 * notification with BINDVERB_POST */
2367 bindf = BINDF_ASYNCHRONOUS | BINDF_ASYNCSTORAGE | BINDF_PULLDATA | BINDF_FROMURLMON | BINDF_NOWRITECACHE;
2368 test_http_protocol_url(posttest_url, FALSE, TRUE);
2369 http_post_test = FALSE;
2372 static void test_https_protocol(void)
2374 static const WCHAR codeweavers_url[] =
2375 {'h','t','t','p','s',':','/','/','w','w','w','.','c','o','d','e','w','e','a','v','e','r','s',
2376 '.','c','o','m','/','t','e','s','t','.','h','t','m','l',0};
2378 trace("Testing https protocol (from urlmon)...\n");
2379 init_test(HTTPS_TEST, 0);
2380 bindf = BINDF_ASYNCHRONOUS | BINDF_ASYNCSTORAGE | BINDF_PULLDATA | BINDF_FROMURLMON | BINDF_NOWRITECACHE;
2381 test_http_protocol_url(codeweavers_url, TRUE, TRUE);
2385 static void test_ftp_protocol(void)
2387 IInternetProtocolInfo *protocol_info;
2388 IClassFactory *factory;
2395 static const WCHAR ftp_urlW[] = {'f','t','p',':','/','/','f','t','p','.','w','i','n','e','h','q','.','o','r','g',
2396 '/','p','u','b','/','o','t','h','e','r','/',
2397 'w','i','n','e','l','o','g','o','.','x','c','f','.','t','a','r','.','b','z','2',0};
2399 trace("Testing ftp protocol...\n");
2401 bindf = BINDF_ASYNCHRONOUS | BINDF_ASYNCSTORAGE | BINDF_PULLDATA | BINDF_FROMURLMON | BINDF_NOWRITECACHE;
2403 tested_protocol = FTP_TEST;
2404 first_data_notif = TRUE;
2405 expect_hrResult = E_PENDING;
2407 hres = CoGetClassObject(&CLSID_FtpProtocol, CLSCTX_INPROC_SERVER, NULL, &IID_IUnknown, (void**)&unk);
2408 ok(hres == S_OK, "CoGetClassObject failed: %08x\n", hres);
2412 hres = IUnknown_QueryInterface(unk, &IID_IInternetProtocolInfo, (void**)&protocol_info);
2413 ok(hres == E_NOINTERFACE, "Could not get IInternetProtocolInfo interface: %08x, expected E_NOINTERFACE\n", hres);
2415 hres = IUnknown_QueryInterface(unk, &IID_IClassFactory, (void**)&factory);
2416 ok(hres == S_OK, "Could not get IClassFactory interface\n");
2417 IUnknown_Release(unk);
2421 hres = IClassFactory_CreateInstance(factory, NULL, &IID_IInternetProtocol,
2422 (void**)&async_protocol);
2423 IClassFactory_Release(factory);
2424 ok(hres == S_OK, "Could not get IInternetProtocol: %08x\n", hres);
2426 test_priority(async_protocol);
2427 test_http_info(async_protocol);
2429 SET_EXPECT(GetBindInfo);
2430 SET_EXPECT(GetBindString_USER_AGENT);
2431 SET_EXPECT(ReportProgress_FINDINGRESOURCE);
2432 SET_EXPECT(ReportProgress_CONNECTING);
2433 SET_EXPECT(ReportProgress_SENDINGREQUEST);
2436 hres = IInternetProtocol_Start(async_protocol, ftp_urlW, &protocol_sink, &bind_info, 0, 0);
2437 ok(hres == S_OK, "Start failed: %08x\n", hres);
2438 CHECK_CALLED(GetBindInfo);
2439 todo_wine CHECK_NOT_CALLED(GetBindString_USER_AGENT);
2441 SET_EXPECT(ReportResult);
2443 hres = IInternetProtocol_Read(async_protocol, buf, 1, &cb);
2444 ok((hres == E_PENDING && cb==0) ||
2445 (hres == S_OK && cb==1), "Read failed: %08x (%d bytes)\n", hres, cb);
2447 WaitForSingleObject(event_complete, INFINITE);
2451 hres = IInternetProtocol_Read(async_protocol, buf, sizeof(buf), &cb);
2452 if(hres == E_PENDING)
2453 WaitForSingleObject(event_complete, INFINITE);
2458 ok(hres == S_FALSE, "Read failed: %08x\n", hres);
2459 CHECK_CALLED(ReportResult);
2460 CHECK_CALLED(Switch);
2462 test_protocol_terminate(async_protocol);
2464 ref = IInternetProtocol_Release(async_protocol);
2465 ok(!ref, "ref=%d\n", ref);
2468 static void test_gopher_protocol(void)
2470 IInternetProtocolInfo *protocol_info;
2471 IClassFactory *factory;
2475 trace("Testing gopher protocol...\n");
2477 hres = CoGetClassObject(&CLSID_GopherProtocol, CLSCTX_INPROC_SERVER, NULL, &IID_IUnknown, (void**)&unk);
2479 hres == REGDB_E_CLASSNOTREG, /* Gopher protocol has been removed as of Vista */
2480 "CoGetClassObject failed: %08x\n", hres);
2484 hres = IUnknown_QueryInterface(unk, &IID_IInternetProtocolInfo, (void**)&protocol_info);
2485 ok(hres == E_NOINTERFACE, "Could not get IInternetProtocolInfo interface: %08x, expected E_NOINTERFACE\n", hres);
2487 hres = IUnknown_QueryInterface(unk, &IID_IClassFactory, (void**)&factory);
2488 ok(hres == S_OK, "Could not get IClassFactory interface\n");
2489 IUnknown_Release(unk);
2493 hres = IClassFactory_CreateInstance(factory, NULL, &IID_IInternetProtocol,
2494 (void**)&async_protocol);
2495 IClassFactory_Release(factory);
2496 ok(hres == S_OK, "Could not get IInternetProtocol: %08x\n", hres);
2498 test_priority(async_protocol);
2500 IInternetProtocol_Release(async_protocol);
2503 static void test_mk_protocol(void)
2505 IInternetProtocolInfo *protocol_info;
2506 IInternetProtocol *protocol;
2507 IClassFactory *factory;
2511 static const WCHAR wrong_url1[] = {'t','e','s','t',':','@','M','S','I','T','S','t','o','r','e',
2512 ':',':','/','t','e','s','t','.','h','t','m','l',0};
2513 static const WCHAR wrong_url2[] = {'m','k',':','/','t','e','s','t','.','h','t','m','l',0};
2515 trace("Testing mk protocol...\n");
2516 init_test(MK_TEST, 0);
2518 hres = CoGetClassObject(&CLSID_MkProtocol, CLSCTX_INPROC_SERVER, NULL,
2519 &IID_IUnknown, (void**)&unk);
2520 ok(hres == S_OK, "CoGetClassObject failed: %08x\n", hres);
2522 hres = IUnknown_QueryInterface(unk, &IID_IInternetProtocolInfo, (void**)&protocol_info);
2523 ok(hres == E_NOINTERFACE,
2524 "Could not get IInternetProtocolInfo interface: %08x, expected E_NOINTERFACE\n",
2527 hres = IUnknown_QueryInterface(unk, &IID_IClassFactory, (void**)&factory);
2528 ok(hres == S_OK, "Could not get IClassFactory interface\n");
2529 IUnknown_Release(unk);
2533 hres = IClassFactory_CreateInstance(factory, NULL, &IID_IInternetProtocol,
2535 IClassFactory_Release(factory);
2536 ok(hres == S_OK, "Could not get IInternetProtocol: %08x\n", hres);
2538 SET_EXPECT(GetBindInfo);
2539 hres = IInternetProtocol_Start(protocol, wrong_url1, &protocol_sink, &bind_info, 0, 0);
2540 ok(hres == MK_E_SYNTAX || hres == INET_E_INVALID_URL,
2541 "Start failed: %08x, expected MK_E_SYNTAX or INET_E_INVALID_URL\n", hres);
2542 CLEAR_CALLED(GetBindInfo);
2544 SET_EXPECT(GetBindInfo);
2545 SET_EXPECT(ReportProgress_DIRECTBIND);
2546 SET_EXPECT(ReportProgress_SENDINGREQUEST);
2547 SET_EXPECT(ReportProgress_MIMETYPEAVAILABLE);
2548 SET_EXPECT(ReportResult);
2549 expect_hrResult = INET_E_RESOURCE_NOT_FOUND;
2551 hres = IInternetProtocol_Start(protocol, wrong_url2, &protocol_sink, &bind_info, 0, 0);
2552 ok(hres == INET_E_RESOURCE_NOT_FOUND ||
2553 hres == INET_E_INVALID_URL, /* win2k3 */
2554 "Start failed: %08x, expected INET_E_RESOURCE_NOT_FOUND or INET_E_INVALID_URL\n", hres);
2556 if (hres == INET_E_RESOURCE_NOT_FOUND) {
2557 CHECK_CALLED(GetBindInfo);
2558 CLEAR_CALLED(ReportProgress_DIRECTBIND);
2559 CHECK_CALLED(ReportProgress_SENDINGREQUEST);
2560 CHECK_CALLED(ReportProgress_MIMETYPEAVAILABLE);
2561 CHECK_CALLED(ReportResult);
2563 CLEAR_CALLED(GetBindInfo);
2564 CLEAR_CALLED(ReportProgress_DIRECTBIND);
2565 CLEAR_CALLED(ReportProgress_SENDINGREQUEST);
2566 CLEAR_CALLED(ReportProgress_MIMETYPEAVAILABLE);
2567 CLEAR_CALLED(ReportResult);
2570 IInternetProtocol_Release(protocol);
2573 static void test_CreateBinding(void)
2575 IInternetProtocol *protocol;
2576 IInternetPriority *priority;
2577 IInternetSession *session;
2583 static const WCHAR test_url[] =
2584 {'t','e','s','t',':','/','/','f','i','l','e','.','h','t','m','l',0};
2585 static const WCHAR wsz_test[] = {'t','e','s','t',0};
2587 trace("Testing CreateBinding...\n");
2588 init_test(BIND_TEST, TEST_BINDING);
2590 hres = CoInternetGetSession(0, &session, 0);
2591 ok(hres == S_OK, "CoInternetGetSession failed: %08x\n", hres);
2593 hres = IInternetSession_RegisterNameSpace(session, &ClassFactory, &IID_NULL, wsz_test, 0, NULL, 0);
2594 ok(hres == S_OK, "RegisterNameSpace failed: %08x\n", hres);
2596 hres = IInternetSession_CreateBinding(session, NULL, test_url, NULL, NULL, &protocol, 0);
2597 binding_protocol = protocol;
2598 ok(hres == S_OK, "CreateBinding failed: %08x\n", hres);
2599 ok(protocol != NULL, "protocol == NULL\n");
2601 hres = IInternetProtocol_QueryInterface(protocol, &IID_IInternetBindInfo, (void**)&prot_bind_info);
2602 ok(hres == S_OK, "QueryInterface(IID_IInternetBindInfo) failed: %08x\n", hres);
2604 hres = IInternetProtocol_QueryInterface(protocol, &IID_IInternetProtocolSink, (void**)&binding_sink);
2605 ok(hres == S_OK, "Could not get IInternetProtocolSink: %08x\n", hres);
2607 hres = IInternetProtocol_Start(protocol, test_url, NULL, &bind_info, 0, 0);
2608 ok(hres == E_INVALIDARG, "Start failed: %08x, expected E_INVALIDARG\n", hres);
2609 hres = IInternetProtocol_Start(protocol, test_url, &protocol_sink, NULL, 0, 0);
2610 ok(hres == E_INVALIDARG, "Start failed: %08x, expected E_INVALIDARG\n", hres);
2611 hres = IInternetProtocol_Start(protocol, NULL, &protocol_sink, &bind_info, 0, 0);
2612 ok(hres == E_INVALIDARG, "Start failed: %08x, expected E_INVALIDARG\n", hres);
2614 hres = IInternetProtocol_QueryInterface(protocol, &IID_IInternetPriority, (void**)&priority);
2615 ok(hres == S_OK, "QueryInterface(IID_IInternetPriority) failed: %08x\n", hres);
2618 hres = IInternetPriority_GetPriority(priority, &p);
2619 ok(hres == S_OK, "GetPriority failed: %08x\n", hres);
2620 ok(!p, "p=%d\n", p);
2623 hres = IInternetPriority_SetPriority(priority, 100);
2624 ok(hres == S_OK, "SetPriority failed: %08x\n", hres);
2627 hres = IInternetPriority_GetPriority(priority, &p);
2628 ok(hres == S_OK, "GetPriority failed: %08x\n", hres);
2629 ok(p == 100, "p=%d\n", p);
2631 SET_EXPECT(QueryService_InternetProtocol);
2632 SET_EXPECT(CreateInstance);
2633 SET_EXPECT(ReportProgress_PROTOCOLCLASSID);
2634 SET_EXPECT(SetPriority);
2637 expect_hrResult = S_OK;
2638 hres = IInternetProtocol_Start(protocol, test_url, &protocol_sink, &bind_info, 0, 0);
2639 ok(hres == S_OK, "Start failed: %08x\n", hres);
2641 CHECK_CALLED(QueryService_InternetProtocol);
2642 CHECK_CALLED(CreateInstance);
2643 CHECK_CALLED(ReportProgress_PROTOCOLCLASSID);
2644 CHECK_CALLED(SetPriority);
2645 CHECK_CALLED(Start);
2649 hres = IInternetProtocol_Read(protocol, expect_pv = buf, sizeof(buf), &read);
2650 ok(hres == S_OK, "Read failed: %08x\n", hres);
2651 ok(read == 100, "read = %d\n", read);
2656 hres = IInternetProtocol_Read(protocol, expect_pv = buf, sizeof(buf), &read);
2657 ok(hres == S_FALSE, "Read failed: %08x\n", hres);
2658 ok(!read, "read = %d\n", read);
2662 hres = IInternetPriority_GetPriority(priority, &p);
2663 ok(hres == S_OK, "GetPriority failed: %08x\n", hres);
2664 ok(p == 100, "p=%d\n", p);
2666 hres = IInternetPriority_SetPriority(priority, 101);
2667 ok(hres == S_OK, "SetPriority failed: %08x\n", hres);
2669 SET_EXPECT(Terminate);
2670 hres = IInternetProtocol_Terminate(protocol, 0xdeadbeef);
2671 ok(hres == S_OK, "Terminate failed: %08x\n", hres);
2672 CHECK_CALLED(Terminate);
2674 SET_EXPECT(Continue);
2675 hres = IInternetProtocolSink_Switch(binding_sink, &protocoldata);
2676 ok(hres == S_OK, "Switch failed: %08x\n", hres);
2677 CHECK_CALLED(Continue);
2679 hres = IInternetProtocolSink_ReportProgress(binding_sink,
2680 BINDSTATUS_CACHEFILENAMEAVAILABLE, expect_wsz = emptyW);
2681 ok(hres == S_OK, "ReportProgress(BINDSTATUS_CACHEFILENAMEAVAILABLE) failed: %08x\n", hres);
2683 hres = IInternetProtocolSink_ReportResult(binding_sink, S_OK, ERROR_SUCCESS, NULL);
2684 ok(hres == E_FAIL, "ReportResult failed: %08x, expected E_FAIL\n", hres);
2686 hres = IInternetProtocolSink_ReportData(binding_sink, 0, 0, 0);
2687 ok(hres == S_OK, "ReportData failed: %08x\n", hres);
2689 IInternetProtocolSink_Release(binding_sink);
2690 IInternetPriority_Release(priority);
2691 IInternetBindInfo_Release(prot_bind_info);
2692 IInternetProtocol_Release(protocol);
2693 IInternetSession_Release(session);
2696 static void test_binding(int prot, DWORD grf_pi, BOOL test_filter)
2698 IInternetProtocol *protocol;
2699 IInternetSession *session;
2703 trace("Testing %s binding (grfPI %x%s)...\n", debugstr_w(protocol_names[prot]), grf_pi,
2704 test_filter ? " testing MIME filter" : "");
2705 init_test(prot, TEST_BINDING | (test_filter ? TEST_FILTER : 0));
2708 hres = CoInternetGetSession(0, &session, 0);
2709 ok(hres == S_OK, "CoInternetGetSession failed: %08x\n", hres);
2711 hres = IInternetSession_RegisterNameSpace(session, &ClassFactory, &IID_NULL, protocol_names[prot], 0, NULL, 0);
2712 ok(hres == S_OK, "RegisterNameSpace failed: %08x\n", hres);
2714 hres = IInternetSession_CreateBinding(session, NULL, binding_urls[prot], NULL, NULL, &protocol, 0);
2715 binding_protocol = protocol;
2716 IInternetSession_Release(session);
2717 ok(hres == S_OK, "CreateBinding failed: %08x\n", hres);
2718 ok(protocol != NULL, "protocol == NULL\n");
2720 hres = IInternetProtocol_QueryInterface(protocol, &IID_IInternetBindInfo, (void**)&prot_bind_info);
2721 ok(hres == S_OK, "QueryInterface(IID_IInternetBindInfo) failed: %08x\n", hres);
2723 hres = IInternetProtocol_QueryInterface(protocol, &IID_IInternetProtocolSink, (void**)&binding_sink);
2724 ok(hres == S_OK, "QueryInterface(IID_IInternetProtocolSink) failed: %08x\n", hres);
2727 SET_EXPECT(QueryService_InternetProtocol);
2728 SET_EXPECT(CreateInstance);
2729 SET_EXPECT(ReportProgress_PROTOCOLCLASSID);
2730 SET_EXPECT(SetPriority);
2733 expect_hrResult = S_OK;
2734 hres = IInternetProtocol_Start(protocol, binding_urls[prot], &protocol_sink, &bind_info, pi, 0);
2735 ok(hres == S_OK, "Start failed: %08x\n", hres);
2737 CHECK_CALLED(QueryService_InternetProtocol);
2738 CHECK_CALLED(CreateInstance);
2739 CHECK_CALLED(ReportProgress_PROTOCOLCLASSID);
2740 CHECK_CALLED(SetPriority);
2741 CHECK_CALLED(Start);
2743 if(prot == HTTP_TEST || prot == HTTPS_TEST) {
2744 while(prot_state < 4) {
2745 WaitForSingleObject(event_complete, INFINITE);
2746 if(mimefilter_test && filtered_protocol) {
2747 SET_EXPECT(Continue);
2748 IInternetProtocol_Continue(filtered_protocol, pdata);
2749 CHECK_CALLED(Continue);
2751 SET_EXPECT(Continue);
2752 IInternetProtocol_Continue(protocol, pdata);
2753 CHECK_CALLED(Continue);
2755 SetEvent(event_complete2);
2757 WaitForSingleObject(event_complete, INFINITE);
2760 SET_EXPECT(MimeFilter_LockRequest);
2762 SET_EXPECT(LockRequest);
2763 hres = IInternetProtocol_LockRequest(protocol, 0);
2764 ok(hres == S_OK, "LockRequest failed: %08x\n", hres);
2766 CHECK_CALLED(MimeFilter_LockRequest);
2768 CHECK_CALLED(LockRequest);
2771 SET_EXPECT(MimeFilter_UnlockRequest);
2773 SET_EXPECT(UnlockRequest);
2774 hres = IInternetProtocol_UnlockRequest(protocol);
2775 ok(hres == S_OK, "UnlockRequest failed: %08x\n", hres);
2777 CHECK_CALLED(MimeFilter_UnlockRequest);
2779 CHECK_CALLED(UnlockRequest);
2783 SET_EXPECT(MimeFilter_Terminate);
2785 SET_EXPECT(Terminate);
2786 hres = IInternetProtocol_Terminate(protocol, 0);
2787 ok(hres == S_OK, "Terminate failed: %08x\n", hres);
2789 CHECK_CALLED(MimeFilter_Terminate);
2791 CHECK_CALLED(Terminate);
2793 if(filtered_protocol)
2794 IInternetProtocol_Release(filtered_protocol);
2795 IInternetBindInfo_Release(prot_bind_info);
2796 IInternetProtocolSink_Release(binding_sink);
2797 ref = IInternetProtocol_Release(protocol);
2798 ok(!ref, "ref=%u, expected 0\n", ref);
2801 static void register_filter(void)
2803 IInternetSession *session;
2806 static const WCHAR gzipW[] = {'g','z','i','p',0};
2808 CoInternetGetSession(0, &session, 0);
2810 hres = IInternetSession_RegisterMimeFilter(session, &mimefilter_cf, &IID_IInternetProtocol, gzipW);
2811 ok(hres == S_OK, "RegisterMimeFilter failed: %08x\n", hres);
2813 IInternetSession_Release(session);
2816 START_TEST(protocol)
2818 OleInitialize(NULL);
2820 event_complete = CreateEvent(NULL, FALSE, FALSE, NULL);
2821 event_complete2 = CreateEvent(NULL, FALSE, FALSE, NULL);
2825 test_file_protocol();
2826 test_http_protocol();
2827 test_https_protocol();
2828 test_ftp_protocol();
2829 test_gopher_protocol();
2831 test_CreateBinding();
2832 test_binding(FILE_TEST, 0, FALSE);
2833 test_binding(HTTP_TEST, 0, FALSE);
2834 test_binding(FILE_TEST, PI_MIMEVERIFICATION, FALSE);
2835 test_binding(HTTP_TEST, PI_MIMEVERIFICATION, FALSE);
2836 test_binding(FILE_TEST, PI_MIMEVERIFICATION, TRUE);
2837 test_binding(HTTP_TEST, PI_MIMEVERIFICATION, TRUE);
2839 CloseHandle(event_complete);
2840 CloseHandle(event_complete2);