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 static HRESULT (WINAPI *pCoInternetGetSession)(DWORD, IInternetSession **, DWORD);
33 static HRESULT (WINAPI *pReleaseBindInfo)(BINDINFO*);
34 static HRESULT (WINAPI *pCreateUri)(LPCWSTR, DWORD, DWORD_PTR, IUri**);
36 #define DEFINE_EXPECT(func) \
37 static BOOL expect_ ## func = FALSE, called_ ## func = FALSE
39 #define SET_EXPECT(func) \
40 expect_ ## func = TRUE
42 #define CHECK_EXPECT2(func) \
44 ok(expect_ ##func, "unexpected call " #func "\n"); \
45 called_ ## func = TRUE; \
48 #define CHECK_EXPECT(func) \
50 CHECK_EXPECT2(func); \
51 expect_ ## func = FALSE; \
54 #define CHECK_CALLED(func) \
56 ok(called_ ## func, "expected " #func "\n"); \
57 expect_ ## func = called_ ## func = FALSE; \
60 #define CHECK_NOT_CALLED(func) \
62 ok(!called_ ## func, "unexpected " #func "\n"); \
63 expect_ ## func = called_ ## func = FALSE; \
66 #define CLEAR_CALLED(func) \
67 expect_ ## func = called_ ## func = FALSE
69 DEFINE_EXPECT(GetBindInfo);
70 DEFINE_EXPECT(ReportProgress_MIMETYPEAVAILABLE);
71 DEFINE_EXPECT(ReportProgress_DIRECTBIND);
72 DEFINE_EXPECT(ReportProgress_RAWMIMETYPE);
73 DEFINE_EXPECT(ReportProgress_FINDINGRESOURCE);
74 DEFINE_EXPECT(ReportProgress_CONNECTING);
75 DEFINE_EXPECT(ReportProgress_SENDINGREQUEST);
76 DEFINE_EXPECT(ReportProgress_CACHEFILENAMEAVAILABLE);
77 DEFINE_EXPECT(ReportProgress_VERIFIEDMIMETYPEAVAILABLE);
78 DEFINE_EXPECT(ReportProgress_PROTOCOLCLASSID);
79 DEFINE_EXPECT(ReportProgress_COOKIE_SENT);
80 DEFINE_EXPECT(ReportProgress_REDIRECTING);
81 DEFINE_EXPECT(ReportProgress_ENCODING);
82 DEFINE_EXPECT(ReportProgress_ACCEPTRANGES);
83 DEFINE_EXPECT(ReportProgress_PROXYDETECTING);
84 DEFINE_EXPECT(ReportProgress_LOADINGMIMEHANDLER);
85 DEFINE_EXPECT(ReportProgress_DECODING);
86 DEFINE_EXPECT(ReportData);
87 DEFINE_EXPECT(ReportData2);
88 DEFINE_EXPECT(ReportResult);
89 DEFINE_EXPECT(GetBindString_ACCEPT_MIMES);
90 DEFINE_EXPECT(GetBindString_USER_AGENT);
91 DEFINE_EXPECT(GetBindString_POST_COOKIE);
92 DEFINE_EXPECT(GetBindString_URL);
93 DEFINE_EXPECT(QueryService_HttpNegotiate);
94 DEFINE_EXPECT(QueryService_InternetProtocol);
95 DEFINE_EXPECT(QueryService_HttpSecurity);
96 DEFINE_EXPECT(QueryInterface_IWinInetInfo);
97 DEFINE_EXPECT(QueryInterface_IWinInetHttpInfo);
98 DEFINE_EXPECT(BeginningTransaction);
99 DEFINE_EXPECT(GetRootSecurityId);
100 DEFINE_EXPECT(OnResponse);
101 DEFINE_EXPECT(Switch);
102 DEFINE_EXPECT(Continue);
103 DEFINE_EXPECT(CreateInstance);
104 DEFINE_EXPECT(Start);
105 DEFINE_EXPECT(StartEx);
106 DEFINE_EXPECT(Terminate);
108 DEFINE_EXPECT(Read2);
109 DEFINE_EXPECT(SetPriority);
110 DEFINE_EXPECT(LockRequest);
111 DEFINE_EXPECT(UnlockRequest);
112 DEFINE_EXPECT(Abort);
113 DEFINE_EXPECT(MimeFilter_CreateInstance);
114 DEFINE_EXPECT(MimeFilter_Start);
115 DEFINE_EXPECT(MimeFilter_ReportProgress);
116 DEFINE_EXPECT(MimeFilter_ReportData);
117 DEFINE_EXPECT(MimeFilter_ReportResult);
118 DEFINE_EXPECT(MimeFilter_Terminate);
119 DEFINE_EXPECT(MimeFilter_LockRequest);
120 DEFINE_EXPECT(MimeFilter_UnlockRequest);
121 DEFINE_EXPECT(MimeFilter_Read);
122 DEFINE_EXPECT(MimeFilter_Switch);
123 DEFINE_EXPECT(MimeFilter_Continue);
124 DEFINE_EXPECT(Stream_Seek);
125 DEFINE_EXPECT(Stream_Read);
127 static const WCHAR wszIndexHtml[] = {'i','n','d','e','x','.','h','t','m','l',0};
128 static const WCHAR index_url[] =
129 {'f','i','l','e',':','i','n','d','e','x','.','h','t','m','l',0};
131 static const WCHAR acc_mimeW[] = {'*','/','*',0};
132 static const WCHAR user_agentW[] = {'W','i','n','e',0};
133 static const WCHAR text_htmlW[] = {'t','e','x','t','/','h','t','m','l',0};
134 static const WCHAR hostW[] = {'w','w','w','.','w','i','n','e','h','q','.','o','r','g',0};
135 static const WCHAR winehq_ipW[] = {'2','0','9','.','4','6','.','2','5','.','1','3','4',0};
136 static const WCHAR emptyW[] = {0};
137 static const WCHAR gzipW[] = {'g','z','i','p',0};
139 static HRESULT expect_hrResult;
140 static LPCWSTR file_name, http_url, expect_wsz;
141 static IInternetProtocol *async_protocol = NULL;
142 static BOOL first_data_notif, http_is_first, test_redirect;
143 static int prot_state, read_report_data, post_stream_read;
144 static DWORD bindf, ex_priority , pi;
145 static IInternetProtocol *binding_protocol, *filtered_protocol;
146 static IInternetBindInfo *prot_bind_info;
147 static IInternetProtocolSink *binding_sink, *filtered_sink;
148 static void *expect_pv;
149 static HANDLE event_complete, event_complete2, event_continue, event_continue_done;
150 static BOOL binding_test;
151 static PROTOCOLDATA protocoldata, *pdata, continue_protdata;
152 static DWORD prot_read, pi, filter_state, http_post_test, thread_id;
153 static BOOL security_problem, test_async_req, impl_protex;
154 static BOOL async_read_pending, mimefilter_test, direct_read, wait_for_switch, emulate_prot, short_read, test_abort;
158 STATE_SENDINGREQUEST,
159 STATE_STARTDOWNLOADING,
172 static const WCHAR protocol_names[][10] = {
175 {'h','t','t','p','s',0},
181 static const WCHAR binding_urls[][130] = {
182 {'f','i','l','e',':','t','e','s','t','.','h','t','m','l',0},
183 {'h','t','t','p',':','/','/','w','w','w','.','w','i','n','e','h','q','.',
184 'o','r','g','/','s','i','t','e','/','a','b','o','u','t',0},
185 {'h','t','t','p','s',':','/','/','w','w','w','.','c','o','d','e','w','e','a','v','e','r','s',
186 '.','c','o','m','/','t','e','s','t','.','h','t','m','l',0},
187 {'f','t','p',':','/','/','f','t','p','.','w','i','n','e','h','q','.','o','r','g',
188 '/','p','u','b','/','o','t','h','e','r',
189 '/','w','i','n','e','l','o','g','o','.','x','c','f','.','t','a','r','.','b','z','2',0},
190 {'m','k',':','t','e','s','t',0},
191 {'t','e','s','t',':','/','/','f','i','l','e','.','h','t','m','l',0}
194 static const CHAR post_data[] = "mode=Test";
196 static const char *debugstr_guid(REFIID riid)
200 sprintf(buf, "{%08X-%04X-%04X-%02X%02X-%02X%02X%02X%02X%02X%02X}",
201 riid->Data1, riid->Data2, riid->Data3, riid->Data4[0],
202 riid->Data4[1], riid->Data4[2], riid->Data4[3], riid->Data4[4],
203 riid->Data4[5], riid->Data4[6], riid->Data4[7]);
208 static int strcmp_wa(LPCWSTR strw, const char *stra)
211 WideCharToMultiByte(CP_ACP, 0, strw, -1, buf, sizeof(buf), NULL, NULL);
212 return lstrcmpA(stra, buf);
215 /* lstrcmpW is not implemented on Win9x */
216 static int strcmp_ww(LPCWSTR strw1, LPCWSTR strw2)
218 CHAR stra1[512], stra2[512];
219 WideCharToMultiByte(CP_ACP, 0, strw1, -1, stra1, MAX_PATH, NULL, NULL);
220 WideCharToMultiByte(CP_ACP, 0, strw2, -1, stra2, MAX_PATH, NULL, NULL);
221 return lstrcmpA(stra1, stra2);
224 static HRESULT WINAPI HttpSecurity_QueryInterface(IHttpSecurity *iface, REFIID riid, void **ppv)
226 if(IsEqualGUID(&IID_IUnknown, riid)
227 || IsEqualGUID(&IID_IHttpSecurity, riid)) {
232 ok(0, "unexpected call\n");
233 return E_NOINTERFACE;
236 static ULONG WINAPI HttpSecurity_AddRef(IHttpSecurity *iface)
241 static ULONG WINAPI HttpSecurity_Release(IHttpSecurity *iface)
246 static HRESULT WINAPI HttpSecurity_GetWindow(IHttpSecurity* iface, REFGUID rguidReason, HWND *phwnd)
248 trace("HttpSecurity_GetWindow\n");
253 static HRESULT WINAPI HttpSecurity_OnSecurityProblem(IHttpSecurity *iface, DWORD dwProblem)
255 trace("Security problem: %u\n", dwProblem);
256 ok(dwProblem == ERROR_INTERNET_SEC_CERT_REV_FAILED, "Expected ERROR_INTERNET_SEC_CERT_REV_FAILED got %u\n", dwProblem);
258 /* Only retry once */
259 if (security_problem)
262 security_problem = TRUE;
263 SET_EXPECT(BeginningTransaction);
268 static IHttpSecurityVtbl HttpSecurityVtbl = {
269 HttpSecurity_QueryInterface,
271 HttpSecurity_Release,
272 HttpSecurity_GetWindow,
273 HttpSecurity_OnSecurityProblem
276 static IHttpSecurity http_security = { &HttpSecurityVtbl };
278 static HRESULT WINAPI HttpNegotiate_QueryInterface(IHttpNegotiate2 *iface, REFIID riid, void **ppv)
280 if(IsEqualGUID(&IID_IUnknown, riid)
281 || IsEqualGUID(&IID_IHttpNegotiate, riid)
282 || IsEqualGUID(&IID_IHttpNegotiate2, riid)) {
287 ok(0, "unexpected call\n");
288 return E_NOINTERFACE;
291 static ULONG WINAPI HttpNegotiate_AddRef(IHttpNegotiate2 *iface)
296 static ULONG WINAPI HttpNegotiate_Release(IHttpNegotiate2 *iface)
301 static HRESULT WINAPI HttpNegotiate_BeginningTransaction(IHttpNegotiate2 *iface, LPCWSTR szURL,
302 LPCWSTR szHeaders, DWORD dwReserved, LPWSTR *pszAdditionalHeaders)
306 static const WCHAR wszHeaders[] =
307 {'C','o','n','t','e','n','t','-','T','y','p','e',':',' ','a','p','p','l','i','c','a','t',
308 'i','o','n','/','x','-','w','w','w','-','f','o','r','m','-','u','r','l','e','n','c','o',
309 'd','e','d','\r','\n',0};
311 CHECK_EXPECT(BeginningTransaction);
314 ok(!strcmp_ww(szURL, binding_urls[tested_protocol]), "szURL != http_url\n");
316 ok(!strcmp_ww(szURL, http_url), "szURL != http_url\n");
317 ok(!dwReserved, "dwReserved=%d, expected 0\n", dwReserved);
318 ok(pszAdditionalHeaders != NULL, "pszAdditionalHeaders == NULL\n");
319 if(pszAdditionalHeaders)
321 ok(*pszAdditionalHeaders == NULL, "*pszAdditionalHeaders != NULL\n");
324 addl_headers = CoTaskMemAlloc(sizeof(wszHeaders));
325 memcpy(addl_headers, wszHeaders, sizeof(wszHeaders));
326 *pszAdditionalHeaders = addl_headers;
333 static HRESULT WINAPI HttpNegotiate_OnResponse(IHttpNegotiate2 *iface, DWORD dwResponseCode,
334 LPCWSTR szResponseHeaders, LPCWSTR szRequestHeaders, LPWSTR *pszAdditionalRequestHeaders)
336 CHECK_EXPECT(OnResponse);
338 ok(dwResponseCode == 200, "dwResponseCode=%d, expected 200\n", dwResponseCode);
339 ok(szResponseHeaders != NULL, "szResponseHeaders == NULL\n");
340 ok(szRequestHeaders == NULL, "szRequestHeaders != NULL\n");
341 ok(pszAdditionalRequestHeaders == NULL, "pszAdditionalHeaders != NULL\n");
346 static HRESULT WINAPI HttpNegotiate_GetRootSecurityId(IHttpNegotiate2 *iface,
347 BYTE *pbSecurityId, DWORD *pcbSecurityId, DWORD_PTR dwReserved)
349 static const BYTE sec_id[] = {'h','t','t','p',':','t','e','s','t',1,0,0,0};
351 CHECK_EXPECT(GetRootSecurityId);
353 ok(!dwReserved, "dwReserved=%ld, expected 0\n", dwReserved);
354 ok(pbSecurityId != NULL, "pbSecurityId == NULL\n");
355 ok(pcbSecurityId != NULL, "pcbSecurityId == NULL\n");
358 ok(*pcbSecurityId == 512, "*pcbSecurityId=%d, expected 512\n", *pcbSecurityId);
359 *pcbSecurityId = sizeof(sec_id);
363 memcpy(pbSecurityId, sec_id, sizeof(sec_id));
368 static IHttpNegotiate2Vtbl HttpNegotiateVtbl = {
369 HttpNegotiate_QueryInterface,
370 HttpNegotiate_AddRef,
371 HttpNegotiate_Release,
372 HttpNegotiate_BeginningTransaction,
373 HttpNegotiate_OnResponse,
374 HttpNegotiate_GetRootSecurityId
377 static IHttpNegotiate2 http_negotiate = { &HttpNegotiateVtbl };
379 static HRESULT QueryInterface(REFIID,void**);
381 static HRESULT WINAPI ServiceProvider_QueryInterface(IServiceProvider *iface, REFIID riid, void **ppv)
383 return QueryInterface(riid, ppv);
386 static ULONG WINAPI ServiceProvider_AddRef(IServiceProvider *iface)
391 static ULONG WINAPI ServiceProvider_Release(IServiceProvider *iface)
396 static HRESULT WINAPI ServiceProvider_QueryService(IServiceProvider *iface, REFGUID guidService,
397 REFIID riid, void **ppv)
399 if(IsEqualGUID(&IID_IHttpNegotiate, guidService) || IsEqualGUID(&IID_IHttpNegotiate2, riid)) {
400 CHECK_EXPECT2(QueryService_HttpNegotiate);
401 return IHttpNegotiate2_QueryInterface(&http_negotiate, riid, ppv);
404 if(IsEqualGUID(&IID_IInternetProtocol, guidService)) {
405 ok(IsEqualGUID(&IID_IInternetProtocol, riid), "unexpected riid\n");
406 CHECK_EXPECT(QueryService_InternetProtocol);
407 return E_NOINTERFACE;
410 if(IsEqualGUID(&IID_IHttpSecurity, guidService)) {
411 ok(IsEqualGUID(&IID_IHttpSecurity, riid), "unexpected riid\n");
412 CHECK_EXPECT(QueryService_HttpSecurity);
413 return IHttpSecurity_QueryInterface(&http_security, riid, ppv);
416 ok(0, "unexpected service %s\n", debugstr_guid(guidService));
420 static const IServiceProviderVtbl ServiceProviderVtbl = {
421 ServiceProvider_QueryInterface,
422 ServiceProvider_AddRef,
423 ServiceProvider_Release,
424 ServiceProvider_QueryService
427 static IServiceProvider service_provider = { &ServiceProviderVtbl };
429 static HRESULT WINAPI Stream_QueryInterface(IStream *iface, REFIID riid, void **ppv)
431 ok(0, "unexpected call\n");
432 return E_NOINTERFACE;
435 static ULONG WINAPI Stream_AddRef(IStream *iface)
440 static ULONG WINAPI Stream_Release(IStream *iface)
445 static HRESULT WINAPI Stream_Read(IStream *iface, void *pv,
446 ULONG cb, ULONG *pcbRead)
448 CHECK_EXPECT2(Stream_Read);
450 ok(GetCurrentThreadId() != thread_id, "wrong thread %d\n", GetCurrentThreadId());
452 ok(pv != NULL, "pv == NULL\n");
453 ok(cb == 0x20000 || broken(cb == 0x2000), "cb = %d\n", cb);
454 ok(pcbRead != NULL, "pcbRead == NULL\n");
456 if(post_stream_read) {
461 memcpy(pv, post_data, sizeof(post_data)-1);
462 post_stream_read += *pcbRead = sizeof(post_data)-1;
466 static HRESULT WINAPI Stream_Write(IStream *iface, const void *pv,
467 ULONG cb, ULONG *pcbWritten)
469 ok(0, "unexpected call\n");
473 static HRESULT WINAPI Stream_Seek(IStream *iface, LARGE_INTEGER dlibMove,
474 DWORD dwOrigin, ULARGE_INTEGER *plibNewPosition)
476 CHECK_EXPECT(Stream_Seek);
478 ok(!dlibMove.QuadPart, "dlibMove != 0\n");
479 ok(dwOrigin == STREAM_SEEK_SET, "dwOrigin = %d\n", dwOrigin);
480 ok(!plibNewPosition, "plibNewPosition == NULL\n");
485 static HRESULT WINAPI Stream_SetSize(IStream *iface, ULARGE_INTEGER libNewSize)
487 ok(0, "unexpected call\n");
491 static HRESULT WINAPI Stream_CopyTo(IStream *iface, IStream *pstm,
492 ULARGE_INTEGER cb, ULARGE_INTEGER *pcbRead, ULARGE_INTEGER *pcbWritten)
494 ok(0, "unexpected call\n");
498 static HRESULT WINAPI Stream_Commit(IStream *iface, DWORD grfCommitFlags)
500 ok(0, "unexpected call\n");
504 static HRESULT WINAPI Stream_Revert(IStream *iface)
506 ok(0, "unexpected call\n");
510 static HRESULT WINAPI Stream_LockRegion(IStream *iface, ULARGE_INTEGER libOffset,
511 ULARGE_INTEGER cb, DWORD dwLockType)
513 ok(0, "unexpected call\n");
517 static HRESULT WINAPI Stream_UnlockRegion(IStream *iface,
518 ULARGE_INTEGER libOffset, ULARGE_INTEGER cb, DWORD dwLockType)
520 ok(0, "unexpected call\n");
524 static HRESULT WINAPI Stream_Stat(IStream *iface, STATSTG *pstatstg,
527 ok(0, "unexpected call\n");
531 static HRESULT WINAPI Stream_Clone(IStream *iface, IStream **ppstm)
533 ok(0, "unexpected call\n");
537 static const IStreamVtbl StreamVtbl = {
538 Stream_QueryInterface,
554 static IStream Stream = { &StreamVtbl };
556 static HRESULT WINAPI ProtocolSink_QueryInterface(IInternetProtocolSink *iface, REFIID riid, void **ppv)
558 return QueryInterface(riid, ppv);
561 static ULONG WINAPI ProtocolSink_AddRef(IInternetProtocolSink *iface)
566 static ULONG WINAPI ProtocolSink_Release(IInternetProtocolSink *iface)
571 static void call_continue(PROTOCOLDATA *protocol_data)
575 if(state == STATE_CONNECTING) {
576 if(tested_protocol == HTTP_TEST || tested_protocol == HTTPS_TEST)
577 CLEAR_CALLED(ReportProgress_COOKIE_SENT);
578 if(tested_protocol == HTTP_TEST || tested_protocol == HTTPS_TEST || tested_protocol == FTP_TEST) {
580 CLEAR_CALLED(ReportProgress_FINDINGRESOURCE);
581 CLEAR_CALLED(ReportProgress_CONNECTING);
582 CLEAR_CALLED(ReportProgress_PROXYDETECTING);
583 }else if(test_redirect) {
584 CHECK_CALLED(ReportProgress_FINDINGRESOURCE);
586 CHECK_NOT_CALLED(ReportProgress_FINDINGRESOURCE);
587 /* IE7 does call this */
588 CLEAR_CALLED(ReportProgress_CONNECTING);
591 if(tested_protocol == FTP_TEST)
592 todo_wine CHECK_CALLED(ReportProgress_SENDINGREQUEST);
593 else if (tested_protocol != HTTPS_TEST)
594 CHECK_CALLED(ReportProgress_SENDINGREQUEST);
596 CHECK_CALLED(ReportProgress_REDIRECTING);
597 state = test_async_req ? STATE_SENDINGREQUEST : STATE_STARTDOWNLOADING;
601 case STATE_SENDINGREQUEST:
602 SET_EXPECT(Stream_Read);
603 SET_EXPECT(ReportProgress_SENDINGREQUEST);
605 case STATE_STARTDOWNLOADING:
606 if(tested_protocol == HTTP_TEST || tested_protocol == HTTPS_TEST) {
607 SET_EXPECT(OnResponse);
608 if(tested_protocol == HTTPS_TEST || test_redirect)
609 SET_EXPECT(ReportProgress_ACCEPTRANGES);
610 SET_EXPECT(ReportProgress_MIMETYPEAVAILABLE);
611 if(bindf & BINDF_NEEDFILE)
612 SET_EXPECT(ReportProgress_CACHEFILENAMEAVAILABLE);
618 if(state != STATE_SENDINGREQUEST)
619 SET_EXPECT(ReportData);
620 hres = IInternetProtocol_Continue(async_protocol, protocol_data);
621 ok(hres == S_OK, "Continue failed: %08x\n", hres);
622 if(tested_protocol == FTP_TEST || security_problem)
623 CLEAR_CALLED(ReportData);
624 else if(state != STATE_SENDINGREQUEST)
625 CHECK_CALLED(ReportData);
628 case STATE_SENDINGREQUEST:
629 CHECK_CALLED(Stream_Read);
630 CHECK_CALLED(ReportProgress_SENDINGREQUEST);
631 state = STATE_STARTDOWNLOADING;
633 case STATE_STARTDOWNLOADING:
634 if (! security_problem)
636 state = STATE_DOWNLOADING;
637 if(tested_protocol == HTTP_TEST || tested_protocol == HTTPS_TEST) {
638 CHECK_CALLED(OnResponse);
639 if(tested_protocol == HTTPS_TEST)
640 CHECK_CALLED(ReportProgress_ACCEPTRANGES);
641 else if(test_redirect)
642 CLEAR_CALLED(ReportProgress_ACCEPTRANGES);
643 CHECK_CALLED(ReportProgress_MIMETYPEAVAILABLE);
644 if(bindf & BINDF_NEEDFILE)
645 CHECK_CALLED(ReportProgress_CACHEFILENAMEAVAILABLE);
650 security_problem = FALSE;
651 SET_EXPECT(ReportProgress_CONNECTING);
658 static HRESULT WINAPI ProtocolSink_Switch(IInternetProtocolSink *iface, PROTOCOLDATA *pProtocolData)
660 if(tested_protocol == FTP_TEST)
661 CHECK_EXPECT2(Switch);
663 CHECK_EXPECT(Switch);
665 ok(pProtocolData != NULL, "pProtocolData == NULL\n");
667 ok(pProtocolData != &protocoldata, "pProtocolData == &protocoldata\n");
668 ok(pProtocolData->grfFlags == protocoldata.grfFlags, "grfFlags wrong %x/%x\n",
669 pProtocolData->grfFlags, protocoldata.grfFlags );
670 ok(pProtocolData->dwState == protocoldata.dwState, "dwState wrong %x/%x\n",
671 pProtocolData->dwState, protocoldata.dwState );
672 ok(pProtocolData->pData == protocoldata.pData, "pData wrong %p/%p\n",
673 pProtocolData->pData, protocoldata.pData );
674 ok(pProtocolData->cbData == protocoldata.cbData, "cbData wrong %x/%x\n",
675 pProtocolData->cbData, protocoldata.cbData );
678 pdata = pProtocolData;
681 SetEvent(event_complete);
682 WaitForSingleObject(event_complete2, INFINITE);
685 continue_protdata = *pProtocolData;
686 SetEvent(event_continue);
687 WaitForSingleObject(event_continue_done, INFINITE);
689 call_continue(pProtocolData);
690 SetEvent(event_complete);
696 static HRESULT WINAPI ProtocolSink_ReportProgress(IInternetProtocolSink *iface, ULONG ulStatusCode,
697 LPCWSTR szStatusText)
699 static const WCHAR null_guid[] = {'{','0','0','0','0','0','0','0','0','-','0','0','0','0','-',
700 '0','0','0','0','-','0','0','0','0','-','0','0','0','0','0','0','0','0','0','0','0','0','}',0};
701 static const WCHAR text_plain[] = {'t','e','x','t','/','p','l','a','i','n',0};
703 switch(ulStatusCode) {
704 case BINDSTATUS_MIMETYPEAVAILABLE:
705 CHECK_EXPECT(ReportProgress_MIMETYPEAVAILABLE);
706 if(tested_protocol != FILE_TEST && !mimefilter_test && (pi & PI_MIMEVERIFICATION)) {
707 if(!short_read || !direct_read)
708 CHECK_CALLED(Read); /* set in Continue */
710 CHECK_CALLED(Read2); /* set in Read */
712 ok(szStatusText != NULL, "szStatusText == NULL\n");
714 if(tested_protocol == BIND_TEST)
715 ok(szStatusText == expect_wsz, "unexpected szStatusText\n");
716 else if (http_post_test)
717 ok(lstrlenW(text_plain) <= lstrlenW(szStatusText) &&
718 !memcmp(szStatusText, text_plain, lstrlenW(text_plain)*sizeof(WCHAR)),
719 "szStatusText != text/plain\n");
720 else if(!mimefilter_test)
721 ok(lstrlenW(text_htmlW) <= lstrlenW(szStatusText) &&
722 !memcmp(szStatusText, text_htmlW, lstrlenW(text_htmlW)*sizeof(WCHAR)),
723 "szStatusText != text/html\n");
726 case BINDSTATUS_DIRECTBIND:
727 CHECK_EXPECT2(ReportProgress_DIRECTBIND);
728 ok(szStatusText == NULL, "szStatusText != NULL\n");
730 case BINDSTATUS_RAWMIMETYPE:
731 CHECK_EXPECT2(ReportProgress_RAWMIMETYPE);
732 ok(szStatusText != NULL, "szStatusText == NULL\n");
734 ok(lstrlenW(szStatusText) < lstrlenW(text_htmlW) ||
735 !memcmp(szStatusText, text_htmlW, lstrlenW(text_htmlW)*sizeof(WCHAR)),
736 "szStatusText != text/html\n");
738 case BINDSTATUS_CACHEFILENAMEAVAILABLE:
739 CHECK_EXPECT(ReportProgress_CACHEFILENAMEAVAILABLE);
740 ok(szStatusText != NULL, "szStatusText == NULL\n");
743 ok(!strcmp_ww(szStatusText, expect_wsz), "unexpected szStatusText\n");
744 else if(tested_protocol == FILE_TEST)
745 ok(!strcmp_ww(szStatusText, file_name), "szStatusText = %s\n", wine_dbgstr_w(szStatusText));
747 ok(szStatusText != NULL, "szStatusText == NULL\n");
750 case BINDSTATUS_FINDINGRESOURCE:
751 CHECK_EXPECT2(ReportProgress_FINDINGRESOURCE);
752 ok(szStatusText != NULL, "szStatusText == NULL\n");
754 case BINDSTATUS_CONNECTING:
755 CHECK_EXPECT2(ReportProgress_CONNECTING);
756 ok(szStatusText != NULL, "szStatusText == NULL\n");
758 case BINDSTATUS_SENDINGREQUEST:
759 CHECK_EXPECT2(ReportProgress_SENDINGREQUEST);
760 if(tested_protocol == FILE_TEST) {
761 ok(szStatusText != NULL, "szStatusText == NULL\n");
763 ok(!*szStatusText, "wrong szStatusText\n");
766 case BINDSTATUS_VERIFIEDMIMETYPEAVAILABLE:
767 CHECK_EXPECT(ReportProgress_VERIFIEDMIMETYPEAVAILABLE);
768 ok(szStatusText != NULL, "szStatusText == NULL\n");
770 ok(!strcmp_ww(szStatusText, text_htmlW), "szStatusText != text/html\n");
772 case BINDSTATUS_PROTOCOLCLASSID:
773 CHECK_EXPECT(ReportProgress_PROTOCOLCLASSID);
774 ok(szStatusText != NULL, "szStatusText == NULL\n");
775 ok(!strcmp_ww(szStatusText, null_guid), "unexpected classid %s\n", wine_dbgstr_w(szStatusText));
777 case BINDSTATUS_COOKIE_SENT:
778 CHECK_EXPECT(ReportProgress_COOKIE_SENT);
779 ok(szStatusText == NULL, "szStatusText != NULL\n");
781 case BINDSTATUS_REDIRECTING:
782 CHECK_EXPECT(ReportProgress_REDIRECTING);
784 ok(!strcmp_wa(szStatusText, "http://test.winehq.org/hello.html"), "szStatusText = %s\n", wine_dbgstr_w(szStatusText));
786 ok(szStatusText == NULL, "szStatusText = %s\n", wine_dbgstr_w(szStatusText));
788 case BINDSTATUS_ENCODING:
789 CHECK_EXPECT(ReportProgress_ENCODING);
790 ok(!strcmp_wa(szStatusText, "gzip"), "szStatusText = %s\n", wine_dbgstr_w(szStatusText));
792 case BINDSTATUS_ACCEPTRANGES:
793 CHECK_EXPECT(ReportProgress_ACCEPTRANGES);
794 ok(!szStatusText, "szStatusText = %s\n", wine_dbgstr_w(szStatusText));
796 case BINDSTATUS_PROXYDETECTING:
797 CHECK_EXPECT(ReportProgress_PROXYDETECTING);
798 SET_EXPECT(ReportProgress_CONNECTING);
799 ok(!szStatusText, "szStatusText = %s\n", wine_dbgstr_w(szStatusText));
801 case BINDSTATUS_LOADINGMIMEHANDLER:
802 CHECK_EXPECT(ReportProgress_LOADINGMIMEHANDLER);
803 ok(!szStatusText, "szStatusText = %s\n", wine_dbgstr_w(szStatusText));
805 case BINDSTATUS_DECODING:
806 CHECK_EXPECT(ReportProgress_DECODING);
807 ok(!strcmp_ww(szStatusText, gzipW), "szStatusText = %s\n", wine_dbgstr_w(szStatusText));
810 ok(0, "Unexpected status %d\n", ulStatusCode);
816 static HRESULT WINAPI ProtocolSink_ReportData(IInternetProtocolSink *iface, DWORD grfBSCF,
817 ULONG ulProgress, ULONG ulProgressMax)
821 static int rec_depth;
824 if(!mimefilter_test && tested_protocol == FILE_TEST) {
825 CHECK_EXPECT2(ReportData);
827 ok(ulProgress == ulProgressMax, "ulProgress (%d) != ulProgressMax (%d)\n",
828 ulProgress, ulProgressMax);
829 ok(ulProgressMax == 13, "ulProgressMax=%d, expected 13\n", ulProgressMax);
830 /* BSCF_SKIPDRAINDATAFORFILEURLS added in IE8 */
831 ok((grfBSCF == (BSCF_FIRSTDATANOTIFICATION | BSCF_LASTDATANOTIFICATION)) ||
832 (grfBSCF == (BSCF_FIRSTDATANOTIFICATION | BSCF_LASTDATANOTIFICATION | BSCF_SKIPDRAINDATAFORFILEURLS)),
833 "grcfBSCF = %08x\n", grfBSCF);
834 }else if(direct_read) {
838 if(!read_report_data && rec_depth == 1) {
839 BOOL reported_all_data = called_ReportData2;
841 CHECK_EXPECT2(ReportData);
844 ok(grfBSCF == (BSCF_FIRSTDATANOTIFICATION|BSCF_LASTDATANOTIFICATION|BSCF_DATAFULLYAVAILABLE)
845 || grfBSCF == BSCF_FIRSTDATANOTIFICATION, /* < IE8 */
846 "grcfBSCF = %08x\n", grfBSCF);
847 CHECK_CALLED(Read); /* Set in Continue */
848 first_data_notif = FALSE;
849 }else if(first_data_notif) {
850 ok(grfBSCF == BSCF_FIRSTDATANOTIFICATION, "grcfBSCF = %08x\n", grfBSCF);
851 first_data_notif = FALSE;
852 }else if(reported_all_data) {
853 ok(grfBSCF == (BSCF_LASTDATANOTIFICATION|BSCF_INTERMEDIATEDATANOTIFICATION),
854 "grcfBSCF = %08x\n", grfBSCF);
855 }else if(!direct_read) {
856 ok(grfBSCF == BSCF_INTERMEDIATEDATANOTIFICATION, "grcfBSCF = %08x\n", grfBSCF);
864 SET_EXPECT(ReportData2);
865 SET_EXPECT(ReportResult);
868 hres = IInternetProtocol_Read(binding_test ? binding_protocol : async_protocol, expect_pv = buf, sizeof(buf), &read);
869 ok(hres == E_PENDING || hres == S_FALSE || hres == S_OK, "Read failed: %08x\n", hres);
871 ok(read, "read == 0\n");
872 if(reported_all_data)
873 ok(hres == S_FALSE, "Read failed: %08x, expected S_FALSE\n", hres);
874 if(!emulate_prot && hres != E_PENDING)
875 CHECK_NOT_CALLED(Switch); /* otherwise checked in wait_for_switch loop */
878 if(!reported_all_data && called_ReportData2) {
880 CHECK_CALLED(ReportData2);
881 CHECK_CALLED(ReportResult);
882 ok(hres == S_OK, "Read failed: %08x\n", hres);
883 reported_all_data = TRUE;
886 CHECK_NOT_CALLED(ReportData2);
887 CHECK_NOT_CALLED(ReportResult);
889 }while(hres == S_OK);
891 wait_for_switch = FALSE;
893 CHECK_EXPECT(ReportData2);
895 ok(grfBSCF & BSCF_LASTDATANOTIFICATION, "grfBSCF = %08x\n", grfBSCF);
900 hres = IInternetProtocol_Read(binding_test ? binding_protocol : async_protocol, expect_pv = buf, sizeof(buf), &read);
903 ok(hres == S_FALSE, "Read returned: %08x, expected E_FALSE\n", hres);
904 ok(!read, "read = %d\n", read);
906 }else if(!binding_test && (tested_protocol == HTTP_TEST || tested_protocol == HTTPS_TEST
907 || tested_protocol == FTP_TEST)) {
908 if(!(grfBSCF & BSCF_LASTDATANOTIFICATION) || (grfBSCF & BSCF_DATAFULLYAVAILABLE))
909 CHECK_EXPECT(ReportData);
910 else if (http_post_test)
911 ok(ulProgress == 13, "Read %u bytes instead of 13\n", ulProgress);
913 ok(ulProgress, "ulProgress == 0\n");
915 if(first_data_notif) {
916 ok(grfBSCF == BSCF_FIRSTDATANOTIFICATION
917 || grfBSCF == (BSCF_LASTDATANOTIFICATION|BSCF_DATAFULLYAVAILABLE),
918 "grcfBSCF = %08x\n", grfBSCF);
919 first_data_notif = FALSE;
921 ok(grfBSCF == BSCF_INTERMEDIATEDATANOTIFICATION
922 || grfBSCF == (BSCF_LASTDATANOTIFICATION|BSCF_INTERMEDIATEDATANOTIFICATION)
923 || broken(grfBSCF == (BSCF_FIRSTDATANOTIFICATION|BSCF_LASTDATANOTIFICATION)),
924 "grcfBSCF = %08x\n", grfBSCF);
927 if(!(bindf & BINDF_FROMURLMON) &&
928 !(grfBSCF & BSCF_LASTDATANOTIFICATION)) {
929 if(state == STATE_CONNECTING) {
930 state = STATE_DOWNLOADING;
932 CHECK_CALLED(ReportProgress_FINDINGRESOURCE);
933 CHECK_CALLED(ReportProgress_CONNECTING);
935 CHECK_NOT_CALLED(ReportProgress_FINDINGRESOURCE);
936 CHECK_NOT_CALLED(ReportProgress_CONNECTING);
938 CHECK_CALLED(ReportProgress_SENDINGREQUEST);
939 CHECK_CALLED(OnResponse);
940 CHECK_CALLED(ReportProgress_RAWMIMETYPE);
942 SetEvent(event_complete);
944 }else if(!read_report_data) {
949 CHECK_EXPECT(ReportData);
951 if(tested_protocol != BIND_TEST) {
954 SET_EXPECT(MimeFilter_Read);
955 else if(rec_depth > 1)
959 hres = IInternetProtocol_Read(binding_protocol, expect_pv=buf, sizeof(buf), &read);
961 CHECK_CALLED(MimeFilter_Read);
962 else if(rec_depth > 1)
966 }while(hres == S_OK);
974 static HRESULT WINAPI ProtocolSink_ReportResult(IInternetProtocolSink *iface, HRESULT hrResult,
975 DWORD dwError, LPCWSTR szResult)
977 CHECK_EXPECT(ReportResult);
979 if(tested_protocol == FTP_TEST)
980 ok(hrResult == E_PENDING || hrResult == S_OK, "hrResult = %08x, expected E_PENDING or S_OK\n", hrResult);
982 ok(hrResult == expect_hrResult, "hrResult = %08x, expected: %08x\n",
983 hrResult, expect_hrResult);
984 if(SUCCEEDED(hrResult) || tested_protocol == FTP_TEST || test_abort)
985 ok(dwError == ERROR_SUCCESS, "dwError = %d, expected ERROR_SUCCESS\n", dwError);
987 ok(dwError != ERROR_SUCCESS ||
988 broken(tested_protocol == MK_TEST), /* Win9x, WinME and NT4 */
989 "dwError == ERROR_SUCCESS\n");
990 ok(!szResult, "szResult != NULL\n");
993 SET_EXPECT(ReportData); /* checked after main loop */
998 static IInternetProtocolSinkVtbl protocol_sink_vtbl = {
999 ProtocolSink_QueryInterface,
1000 ProtocolSink_AddRef,
1001 ProtocolSink_Release,
1002 ProtocolSink_Switch,
1003 ProtocolSink_ReportProgress,
1004 ProtocolSink_ReportData,
1005 ProtocolSink_ReportResult
1008 static IInternetProtocolSink protocol_sink = { &protocol_sink_vtbl };
1010 static HRESULT WINAPI MimeProtocolSink_QueryInterface(IInternetProtocolSink *iface, REFIID riid, void **ppv)
1012 ok(0, "unexpected call\n");
1016 static ULONG WINAPI MimeProtocolSink_AddRef(IInternetProtocolSink *iface)
1021 static ULONG WINAPI MimeProtocolSink_Release(IInternetProtocolSink *iface)
1026 static HRESULT WINAPI MimeProtocolSink_Switch(IInternetProtocolSink *iface, PROTOCOLDATA *pProtocolData)
1030 CHECK_EXPECT(MimeFilter_Switch);
1033 hres = IInternetProtocolSink_Switch(filtered_sink, pProtocolData);
1034 ok(hres == S_OK, "Switch failed: %08x\n", hres);
1035 CHECK_CALLED(Switch);
1040 static HRESULT WINAPI MimeProtocolSink_ReportProgress(IInternetProtocolSink *iface, ULONG ulStatusCode,
1041 LPCWSTR szStatusText)
1043 CHECK_EXPECT(MimeFilter_ReportProgress);
1047 static HRESULT WINAPI MimeProtocolSink_ReportData(IInternetProtocolSink *iface, DWORD grfBSCF,
1048 ULONG ulProgress, ULONG ulProgressMax)
1054 CHECK_EXPECT(MimeFilter_ReportData);
1058 hres = IInternetProtocol_Read(filtered_protocol, buf, sizeof(buf), &read);
1059 if(tested_protocol == HTTP_TEST)
1060 ok(hres == S_OK || hres == E_PENDING || hres == S_FALSE, "Read failed: %08x\n", hres);
1062 ok(hres == S_OK, "Read failed: %08x\n", hres);
1065 SET_EXPECT(ReportProgress_MIMETYPEAVAILABLE);
1066 hres = IInternetProtocolSink_ReportProgress(filtered_sink, BINDSTATUS_VERIFIEDMIMETYPEAVAILABLE, text_htmlW);
1067 ok(hres == S_OK, "ReportProgress failed: %08x\n", hres);
1068 CHECK_CALLED(ReportProgress_MIMETYPEAVAILABLE);
1070 /* FIXME: test BINDSTATUS_CACHEFILENAMEAVAILABLE */
1073 if(!read_report_data)
1074 SET_EXPECT(ReportData);
1075 hres = IInternetProtocolSink_ReportData(filtered_sink, grfBSCF, ulProgress, ulProgressMax);
1076 ok(hres == S_OK, "ReportData failed: %08x\n", hres);
1077 if(!read_report_data)
1078 CHECK_CALLED(ReportData);
1086 static HRESULT WINAPI MimeProtocolSink_ReportResult(IInternetProtocolSink *iface, HRESULT hrResult,
1087 DWORD dwError, LPCWSTR szResult)
1091 CHECK_EXPECT(MimeFilter_ReportResult);
1093 ok(hrResult == S_OK, "hrResult = %08x\n", hrResult);
1094 ok(dwError == ERROR_SUCCESS, "dwError = %u\n", dwError);
1095 ok(!szResult, "szResult = %s\n", wine_dbgstr_w(szResult));
1097 SET_EXPECT(ReportResult);
1098 hres = IInternetProtocolSink_ReportResult(filtered_sink, hrResult, dwError, szResult);
1099 ok(SUCCEEDED(hres), "ReportResult failed: %08x\n", hres);
1100 CHECK_CALLED(ReportResult);
1105 static IInternetProtocolSinkVtbl mime_protocol_sink_vtbl = {
1106 MimeProtocolSink_QueryInterface,
1107 MimeProtocolSink_AddRef,
1108 MimeProtocolSink_Release,
1109 MimeProtocolSink_Switch,
1110 MimeProtocolSink_ReportProgress,
1111 MimeProtocolSink_ReportData,
1112 MimeProtocolSink_ReportResult
1115 static IInternetProtocolSink mime_protocol_sink = { &mime_protocol_sink_vtbl };
1117 static HRESULT QueryInterface(REFIID riid, void **ppv)
1119 static const IID IID_undocumented = {0x58DFC7D0,0x5381,0x43E5,{0x9D,0x72,0x4C,0xDD,0xE4,0xCB,0x0F,0x1A}};
1123 if(IsEqualGUID(&IID_IUnknown, riid) || IsEqualGUID(&IID_IInternetProtocolSink, riid))
1124 *ppv = &protocol_sink;
1125 if(IsEqualGUID(&IID_IServiceProvider, riid))
1126 *ppv = &service_provider;
1127 if(IsEqualGUID(&IID_IUriContainer, riid))
1128 return E_NOINTERFACE; /* TODO */
1130 /* NOTE: IE8 queries for undocumented {58DFC7D0-5381-43E5-9D72-4CDDE4CB0F1A} interface. */
1131 if(IsEqualGUID(&IID_undocumented, riid))
1132 return E_NOINTERFACE;
1137 ok(0, "unexpected call %s\n", debugstr_guid(riid));
1138 return E_NOINTERFACE;
1141 static HRESULT WINAPI BindInfo_QueryInterface(IInternetBindInfo *iface, REFIID riid, void **ppv)
1143 if(IsEqualGUID(&IID_IUnknown, riid) || IsEqualGUID(&IID_IInternetBindInfo, riid)) {
1147 return E_NOINTERFACE;
1150 static ULONG WINAPI BindInfo_AddRef(IInternetBindInfo *iface)
1155 static ULONG WINAPI BindInfo_Release(IInternetBindInfo *iface)
1160 static HRESULT WINAPI BindInfo_GetBindInfo(IInternetBindInfo *iface, DWORD *grfBINDF, BINDINFO *pbindinfo)
1164 CHECK_EXPECT(GetBindInfo);
1166 ok(grfBINDF != NULL, "grfBINDF == NULL\n");
1167 ok(pbindinfo != NULL, "pbindinfo == NULL\n");
1168 ok(pbindinfo->cbSize == sizeof(BINDINFO), "wrong size of pbindinfo: %d\n", pbindinfo->cbSize);
1172 *grfBINDF |= BINDF_FROMURLMON;
1173 cbSize = pbindinfo->cbSize;
1174 memset(pbindinfo, 0, cbSize);
1175 pbindinfo->cbSize = cbSize;
1179 pbindinfo->cbstgmedData = sizeof(post_data)-1;
1180 pbindinfo->dwBindVerb = BINDVERB_POST;
1181 pbindinfo->stgmedData.tymed = http_post_test;
1183 if(http_post_test == TYMED_HGLOBAL) {
1186 /* Must be GMEM_FIXED, GMEM_MOVABLE does not work properly */
1187 data = GlobalAlloc(GPTR, sizeof(post_data));
1188 memcpy(data, post_data, sizeof(post_data));
1189 U(pbindinfo->stgmedData).hGlobal = data;
1191 IStream *post_stream;
1196 /* Must be GMEM_FIXED, GMEM_MOVABLE does not work properly */
1197 data = GlobalAlloc(GPTR, sizeof(post_data));
1198 memcpy(data, post_data, sizeof(post_data));
1199 U(pbindinfo->stgmedData).hGlobal = data;
1201 hres = CreateStreamOnHGlobal(data, FALSE, &post_stream);
1202 ok(hres == S_OK, "CreateStreamOnHGlobal failed: %08x\n", hres);
1204 U(pbindinfo->stgmedData).pstm =post_stream;/* &Stream; */
1206 U(pbindinfo->stgmedData).pstm = &Stream;
1213 static HRESULT WINAPI BindInfo_GetBindString(IInternetBindInfo *iface, ULONG ulStringType,
1214 LPOLESTR *ppwzStr, ULONG cEl, ULONG *pcElFetched)
1216 ok(ppwzStr != NULL, "ppwzStr == NULL\n");
1217 ok(pcElFetched != NULL, "pcElFetched == NULL\n");
1219 switch(ulStringType) {
1220 case BINDSTRING_ACCEPT_MIMES:
1221 CHECK_EXPECT(GetBindString_ACCEPT_MIMES);
1222 ok(cEl == 256, "cEl=%d, expected 256\n", cEl);
1224 ok(*pcElFetched == 256, "*pcElFetched=%d, expected 256\n", *pcElFetched);
1228 *ppwzStr = CoTaskMemAlloc(sizeof(acc_mimeW));
1229 memcpy(*ppwzStr, acc_mimeW, sizeof(acc_mimeW));
1232 case BINDSTRING_USER_AGENT:
1233 CHECK_EXPECT(GetBindString_USER_AGENT);
1234 ok(cEl == 1, "cEl=%d, expected 1\n", cEl);
1236 ok(*pcElFetched == 0, "*pcElFetch=%d, expectd 0\n", *pcElFetched);
1240 *ppwzStr = CoTaskMemAlloc(sizeof(user_agentW));
1241 memcpy(*ppwzStr, user_agentW, sizeof(user_agentW));
1244 case BINDSTRING_POST_COOKIE:
1245 CHECK_EXPECT(GetBindString_POST_COOKIE);
1246 ok(cEl == 1, "cEl=%d, expected 1\n", cEl);
1248 ok(*pcElFetched == 0, "*pcElFetch=%d, expectd 0\n", *pcElFetched);
1250 case BINDSTRING_URL: {
1253 CHECK_EXPECT(GetBindString_URL);
1254 ok(cEl == 1, "cEl=%d, expected 1\n", cEl);
1255 ok(*pcElFetched == 0, "*pcElFetch=%d, expectd 0\n", *pcElFetched);
1258 size = (lstrlenW(binding_urls[tested_protocol])+1)*sizeof(WCHAR);
1259 *ppwzStr = CoTaskMemAlloc(size);
1260 memcpy(*ppwzStr, binding_urls[tested_protocol], size);
1264 ok(0, "unexpected call\n");
1270 static IInternetBindInfoVtbl bind_info_vtbl = {
1271 BindInfo_QueryInterface,
1274 BindInfo_GetBindInfo,
1275 BindInfo_GetBindString
1278 static IInternetBindInfo bind_info = { &bind_info_vtbl };
1280 static HRESULT WINAPI InternetPriority_QueryInterface(IInternetPriority *iface,
1281 REFIID riid, void **ppv)
1283 ok(0, "unexpected call\n");
1284 return E_NOINTERFACE;
1287 static ULONG WINAPI InternetPriority_AddRef(IInternetPriority *iface)
1292 static ULONG WINAPI InternetPriority_Release(IInternetPriority *iface)
1297 static HRESULT WINAPI InternetPriority_SetPriority(IInternetPriority *iface, LONG nPriority)
1299 CHECK_EXPECT(SetPriority);
1300 ok(nPriority == ex_priority, "nPriority=%d\n", nPriority);
1304 static HRESULT WINAPI InternetPriority_GetPriority(IInternetPriority *iface, LONG *pnPriority)
1306 ok(0, "unexpected call\n");
1311 static const IInternetPriorityVtbl InternetPriorityVtbl = {
1312 InternetPriority_QueryInterface,
1313 InternetPriority_AddRef,
1314 InternetPriority_Release,
1315 InternetPriority_SetPriority,
1316 InternetPriority_GetPriority
1319 static IInternetPriority InternetPriority = { &InternetPriorityVtbl };
1321 static ULONG WINAPI Protocol_AddRef(IInternetProtocolEx *iface)
1326 static ULONG WINAPI Protocol_Release(IInternetProtocolEx *iface)
1331 static HRESULT WINAPI Protocol_Abort(IInternetProtocolEx *iface, HRESULT hrReason,
1336 CHECK_EXPECT(Abort);
1338 SET_EXPECT(ReportResult);
1339 hres = IInternetProtocolSink_ReportResult(binding_sink, S_OK, ERROR_SUCCESS, NULL);
1340 ok(hres == S_OK, "ReportResult failed: %08x\n", hres);
1341 CHECK_CALLED(ReportResult);
1346 static HRESULT WINAPI Protocol_Suspend(IInternetProtocolEx *iface)
1348 ok(0, "unexpected call\n");
1352 static HRESULT WINAPI Protocol_Resume(IInternetProtocolEx *iface)
1354 ok(0, "unexpected call\n");
1358 static HRESULT WINAPI Protocol_Seek(IInternetProtocolEx *iface,
1359 LARGE_INTEGER dlibMove, DWORD dwOrigin, ULARGE_INTEGER *plibNewPosition)
1361 ok(0, "unexpected call\n");
1365 static HRESULT WINAPI ProtocolEmul_QueryInterface(IInternetProtocolEx *iface, REFIID riid, void **ppv)
1367 if(IsEqualGUID(&IID_IUnknown, riid) || IsEqualGUID(&IID_IInternetProtocol, riid)) {
1372 if(IsEqualGUID(&IID_IInternetProtocolEx, riid)) {
1378 return E_NOINTERFACE;
1381 if(IsEqualGUID(&IID_IInternetPriority, riid)) {
1382 *ppv = &InternetPriority;
1386 if(IsEqualGUID(&IID_IWinInetInfo, riid)) {
1387 CHECK_EXPECT(QueryInterface_IWinInetInfo);
1389 return E_NOINTERFACE;
1392 if(IsEqualGUID(&IID_IWinInetHttpInfo, riid)) {
1393 CHECK_EXPECT(QueryInterface_IWinInetHttpInfo);
1395 return E_NOINTERFACE;
1398 ok(0, "unexpected riid %s\n", debugstr_guid(riid));
1400 return E_NOINTERFACE;
1403 static DWORD WINAPI thread_proc(PVOID arg)
1407 memset(&protocoldata, -1, sizeof(protocoldata));
1411 SET_EXPECT(ReportProgress_FINDINGRESOURCE);
1412 hres = IInternetProtocolSink_ReportProgress(binding_sink,
1413 BINDSTATUS_FINDINGRESOURCE, hostW);
1414 CHECK_CALLED(ReportProgress_FINDINGRESOURCE);
1415 ok(hres == S_OK, "ReportProgress failed: %08x\n", hres);
1417 SET_EXPECT(ReportProgress_CONNECTING);
1418 hres = IInternetProtocolSink_ReportProgress(binding_sink,
1419 BINDSTATUS_CONNECTING, winehq_ipW);
1420 CHECK_CALLED(ReportProgress_CONNECTING);
1421 ok(hres == S_OK, "ReportProgress failed: %08x\n", hres);
1423 SET_EXPECT(ReportProgress_SENDINGREQUEST);
1424 hres = IInternetProtocolSink_ReportProgress(binding_sink,
1425 BINDSTATUS_SENDINGREQUEST, NULL);
1426 CHECK_CALLED(ReportProgress_SENDINGREQUEST);
1427 ok(hres == S_OK, "ReportProgress failed: %08x\n", hres);
1431 hres = IInternetProtocolSink_Switch(binding_sink, &protocoldata);
1432 CHECK_CALLED(Switch);
1433 ok(hres == S_OK, "Switch failed: %08x\n", hres);
1438 SET_EXPECT(MimeFilter_Switch);
1441 hres = IInternetProtocolSink_Switch(binding_sink, &protocoldata);
1442 ok(hres == S_OK, "Switch failed: %08x\n", hres);
1444 CHECK_CALLED(MimeFilter_Switch);
1446 CHECK_CALLED(Switch);
1449 SetEvent(event_complete);
1455 SET_EXPECT(MimeFilter_Switch);
1458 hres = IInternetProtocolSink_Switch(binding_sink, &protocoldata);
1459 ok(hres == S_OK, "Switch failed: %08x\n", hres);
1461 CHECK_CALLED(MimeFilter_Switch);
1463 CHECK_CALLED(Switch);
1467 SET_EXPECT(MimeFilter_Switch);
1470 hres = IInternetProtocolSink_Switch(binding_sink, &protocoldata);
1471 ok(hres == S_OK, "Switch failed: %08x\n", hres);
1473 CHECK_CALLED(MimeFilter_Switch);
1475 CHECK_CALLED(Switch);
1478 SetEvent(event_complete);
1483 static void protocol_start(IInternetProtocolSink *pOIProtSink, IInternetBindInfo *pOIBindInfo, DWORD pi)
1485 BINDINFO bindinfo, exp_bindinfo;
1489 ok(pOIProtSink != NULL, "pOIProtSink == NULL\n");
1490 ok(pOIBindInfo != NULL, "pOIBindInfo == NULL\n");
1491 ok(pOIProtSink != &protocol_sink, "unexpected pOIProtSink\n");
1492 ok(pOIBindInfo != &bind_info, "unexpected pOIBindInfo\n");
1493 ok(!pi, "pi = %x\n", pi);
1496 ok(pOIProtSink == binding_sink, "pOIProtSink != binding_sink\n");
1498 memset(&bindinfo, 0, sizeof(bindinfo));
1499 bindinfo.cbSize = sizeof(bindinfo);
1500 memcpy(&exp_bindinfo, &bindinfo, sizeof(bindinfo));
1501 SET_EXPECT(GetBindInfo);
1502 hres = IInternetBindInfo_GetBindInfo(pOIBindInfo, &cbindf, &bindinfo);
1503 ok(hres == S_OK, "GetBindInfo failed: %08x\n", hres);
1504 CHECK_CALLED(GetBindInfo);
1505 ok(cbindf == (bindf|BINDF_FROMURLMON), "bindf = %x, expected %x\n",
1506 cbindf, (bindf|BINDF_FROMURLMON));
1507 ok(!memcmp(&exp_bindinfo, &bindinfo, sizeof(bindinfo)), "unexpected bindinfo\n");
1508 pReleaseBindInfo(&bindinfo);
1510 SET_EXPECT(ReportProgress_SENDINGREQUEST);
1511 hres = IInternetProtocolSink_ReportProgress(pOIProtSink, BINDSTATUS_SENDINGREQUEST, emptyW);
1512 ok(hres == S_OK, "ReportProgress(BINDSTATUS_SENDINGREQUEST) failed: %08x\n", hres);
1513 CHECK_CALLED(ReportProgress_SENDINGREQUEST);
1515 if(tested_protocol == HTTP_TEST || tested_protocol == HTTPS_TEST) {
1516 IServiceProvider *service_provider;
1517 IHttpNegotiate *http_negotiate;
1518 IHttpNegotiate2 *http_negotiate2;
1519 LPWSTR ua = (LPWSTR)0xdeadbeef, accept_mimes[256];
1520 LPWSTR additional_headers = NULL;
1522 DWORD fetched = 0, size = 100;
1525 SET_EXPECT(GetBindString_USER_AGENT);
1526 hres = IInternetBindInfo_GetBindString(pOIBindInfo, BINDSTRING_USER_AGENT,
1528 CHECK_CALLED(GetBindString_USER_AGENT);
1529 ok(hres == S_OK, "GetBindString(BINDSTRING_USER_AGETNT) failed: %08x\n", hres);
1530 ok(fetched == 1, "fetched = %d, expected 254\n", fetched);
1531 ok(ua != NULL, "ua = %p\n", ua);
1532 ok(!strcmp_ww(ua, user_agentW), "unexpected user agent %s\n", wine_dbgstr_w(ua));
1536 SET_EXPECT(GetBindString_ACCEPT_MIMES);
1537 hres = IInternetBindInfo_GetBindString(pOIBindInfo, BINDSTRING_ACCEPT_MIMES,
1538 accept_mimes, 256, &fetched);
1539 CHECK_CALLED(GetBindString_ACCEPT_MIMES);
1542 "GetBindString(BINDSTRING_ACCEPT_MIMES) failed: %08x\n", hres);
1543 ok(fetched == 1, "fetched = %d, expected 1\n", fetched);
1544 ok(!strcmp_ww(acc_mimeW, accept_mimes[0]), "unexpected mimes %s\n", wine_dbgstr_w(accept_mimes[0]));
1545 CoTaskMemFree(accept_mimes[0]);
1547 hres = IInternetBindInfo_QueryInterface(pOIBindInfo, &IID_IServiceProvider,
1548 (void**)&service_provider);
1549 ok(hres == S_OK, "QueryInterface failed: %08x\n", hres);
1551 SET_EXPECT(QueryService_HttpNegotiate);
1552 hres = IServiceProvider_QueryService(service_provider, &IID_IHttpNegotiate,
1553 &IID_IHttpNegotiate, (void**)&http_negotiate);
1554 CHECK_CALLED(QueryService_HttpNegotiate);
1555 ok(hres == S_OK, "QueryService failed: %08x\n", hres);
1557 SET_EXPECT(BeginningTransaction);
1558 hres = IHttpNegotiate_BeginningTransaction(http_negotiate, binding_urls[tested_protocol],
1559 NULL, 0, &additional_headers);
1560 CHECK_CALLED(BeginningTransaction);
1561 IHttpNegotiate_Release(http_negotiate);
1562 ok(hres == S_OK, "BeginningTransction failed: %08x\n", hres);
1563 ok(additional_headers == NULL, "additional_headers=%p\n", additional_headers);
1565 SET_EXPECT(QueryService_HttpNegotiate);
1566 hres = IServiceProvider_QueryService(service_provider, &IID_IHttpNegotiate2,
1567 &IID_IHttpNegotiate2, (void**)&http_negotiate2);
1568 CHECK_CALLED(QueryService_HttpNegotiate);
1569 ok(hres == S_OK, "QueryService failed: %08x\n", hres);
1572 SET_EXPECT(GetRootSecurityId);
1573 hres = IHttpNegotiate2_GetRootSecurityId(http_negotiate2, sec_id, &size, 0);
1574 CHECK_CALLED(GetRootSecurityId);
1575 IHttpNegotiate2_Release(http_negotiate2);
1576 ok(hres == E_FAIL, "GetRootSecurityId failed: %08x, expected E_FAIL\n", hres);
1577 ok(size == 13, "size=%d\n", size);
1579 IServiceProvider_Release(service_provider);
1581 CreateThread(NULL, 0, thread_proc, NULL, 0, &tid);
1585 SET_EXPECT(ReportProgress_CACHEFILENAMEAVAILABLE);
1586 hres = IInternetProtocolSink_ReportProgress(pOIProtSink,
1587 BINDSTATUS_CACHEFILENAMEAVAILABLE, expect_wsz = emptyW);
1588 ok(hres == S_OK, "ReportProgress(BINDSTATUS_CACHEFILENAMEAVAILABLE) failed: %08x\n", hres);
1589 CHECK_CALLED(ReportProgress_CACHEFILENAMEAVAILABLE);
1591 if(mimefilter_test) {
1592 SET_EXPECT(MimeFilter_CreateInstance);
1593 SET_EXPECT(MimeFilter_Start);
1594 SET_EXPECT(ReportProgress_LOADINGMIMEHANDLER);
1596 SET_EXPECT(ReportProgress_MIMETYPEAVAILABLE);
1597 hres = IInternetProtocolSink_ReportProgress(pOIProtSink, BINDSTATUS_VERIFIEDMIMETYPEAVAILABLE,
1598 mimefilter_test ? gzipW : (expect_wsz = text_htmlW));
1600 "ReportProgress(BINDSTATUS_VERIFIEDMIMETYPEAVAILABLE) failed: %08x\n", hres);
1601 if(mimefilter_test) {
1602 CHECK_CALLED(MimeFilter_CreateInstance);
1603 CHECK_CALLED(MimeFilter_Start);
1604 CHECK_CALLED(ReportProgress_LOADINGMIMEHANDLER);
1605 todo_wine CHECK_CALLED(ReportProgress_MIMETYPEAVAILABLE);
1607 CHECK_CALLED(ReportProgress_MIMETYPEAVAILABLE);
1611 SET_EXPECT(MimeFilter_ReportData);
1613 SET_EXPECT(ReportData);
1614 hres = IInternetProtocolSink_ReportData(pOIProtSink,
1615 BSCF_FIRSTDATANOTIFICATION | BSCF_LASTDATANOTIFICATION, 13, 13);
1616 ok(hres == S_OK, "ReportData failed: %08x\n", hres);
1618 CHECK_CALLED(MimeFilter_ReportData);
1620 CHECK_CALLED(ReportData);
1622 if(tested_protocol == BIND_TEST) {
1623 hres = IInternetProtocol_Terminate(binding_protocol, 0);
1624 ok(hres == E_FAIL, "Termiante failed: %08x\n", hres);
1628 SET_EXPECT(MimeFilter_ReportResult);
1630 SET_EXPECT(ReportResult);
1631 hres = IInternetProtocolSink_ReportResult(pOIProtSink, S_OK, 0, NULL);
1632 ok(hres == S_OK, "ReportResult failed: %08x\n", hres);
1634 CHECK_CALLED(MimeFilter_ReportResult);
1636 CHECK_CALLED(ReportResult);
1639 static HRESULT WINAPI ProtocolEmul_Start(IInternetProtocolEx *iface, LPCWSTR szUrl,
1640 IInternetProtocolSink *pOIProtSink, IInternetBindInfo *pOIBindInfo,
1641 DWORD grfPI, HANDLE_PTR dwReserved)
1643 CHECK_EXPECT(Start);
1645 ok(!dwReserved, "dwReserved = %lx\n", dwReserved);
1646 protocol_start(pOIProtSink, pOIBindInfo, grfPI);
1650 static HRESULT WINAPI ProtocolEmul_Continue(IInternetProtocolEx *iface,
1651 PROTOCOLDATA *pProtocolData)
1656 CHECK_EXPECT(Continue);
1658 ok(pProtocolData != NULL, "pProtocolData == NULL\n");
1659 if(!pProtocolData || tested_protocol == BIND_TEST)
1662 ok(pProtocolData != &protocoldata, "pProtocolData == &protocoldata\n");
1663 ok(pProtocolData->grfFlags == protocoldata.grfFlags, "grfFlags wrong %x/%x\n",
1664 pProtocolData->grfFlags, protocoldata.grfFlags );
1665 ok(pProtocolData->dwState == protocoldata.dwState, "dwState wrong %x/%x\n",
1666 pProtocolData->dwState, protocoldata.dwState );
1667 ok(pProtocolData->pData == protocoldata.pData, "pData wrong %p/%p\n",
1668 pProtocolData->pData, protocoldata.pData );
1669 ok(pProtocolData->cbData == protocoldata.cbData, "cbData wrong %x/%x\n",
1670 pProtocolData->cbData, protocoldata.cbData );
1673 switch(prot_state) {
1675 IServiceProvider *service_provider;
1676 IHttpNegotiate *http_negotiate;
1677 static WCHAR header[] = {'?',0};
1679 hres = IInternetProtocolSink_QueryInterface(binding_sink, &IID_IServiceProvider,
1680 (void**)&service_provider);
1681 ok(hres == S_OK, "Could not get IServiceProvicder\n");
1683 SET_EXPECT(QueryService_HttpNegotiate);
1684 hres = IServiceProvider_QueryService(service_provider, &IID_IHttpNegotiate,
1685 &IID_IHttpNegotiate, (void**)&http_negotiate);
1686 IServiceProvider_Release(service_provider);
1687 CHECK_CALLED(QueryService_HttpNegotiate);
1688 ok(hres == S_OK, "Could not get IHttpNegotiate\n");
1690 SET_EXPECT(OnResponse);
1691 hres = IHttpNegotiate_OnResponse(http_negotiate, 200, header, NULL, NULL);
1692 IHttpNegotiate_Release(http_negotiate);
1693 CHECK_CALLED(OnResponse);
1694 IHttpNegotiate_Release(http_negotiate);
1695 ok(hres == S_OK, "OnResponse failed: %08x\n", hres);
1697 if(mimefilter_test) {
1698 SET_EXPECT(MimeFilter_CreateInstance);
1699 SET_EXPECT(MimeFilter_Start);
1700 SET_EXPECT(ReportProgress_LOADINGMIMEHANDLER);
1701 }else if(!(pi & PI_MIMEVERIFICATION)) {
1702 SET_EXPECT(ReportProgress_MIMETYPEAVAILABLE);
1704 hres = IInternetProtocolSink_ReportProgress(binding_sink,
1705 BINDSTATUS_MIMETYPEAVAILABLE, mimefilter_test ? gzipW : text_htmlW);
1706 if(mimefilter_test) {
1707 CHECK_CALLED(MimeFilter_CreateInstance);
1708 CHECK_CALLED(MimeFilter_Start);
1709 CHECK_CALLED(ReportProgress_LOADINGMIMEHANDLER);
1710 }else if(!(pi & PI_MIMEVERIFICATION)) {
1711 CHECK_CALLED(ReportProgress_MIMETYPEAVAILABLE);
1714 "ReportProgress(BINDSTATUS_MIMETYPEAVAILABLE) failed: %08x\n", hres);
1716 bscf |= BSCF_FIRSTDATANOTIFICATION;
1721 bscf = BSCF_INTERMEDIATEDATANOTIFICATION;
1726 if(mimefilter_test) {
1727 SET_EXPECT(MimeFilter_ReportData);
1728 }else if(pi & PI_MIMEVERIFICATION) {
1730 SET_EXPECT(Read); /* checked in ReportData for short_read */
1732 if(!mimefilter_test)
1733 SET_EXPECT(Read); /* checked in BINDSTATUS_MIMETYPEAVAILABLE or ReportData */
1734 SET_EXPECT(ReportProgress_MIMETYPEAVAILABLE);
1737 SET_EXPECT(ReportData);
1739 SET_EXPECT(ReportData);
1742 hres = IInternetProtocolSink_ReportData(binding_sink, bscf, pr, 400);
1743 ok(hres == S_OK, "ReportData failed: %08x\n", hres);
1745 if(mimefilter_test) {
1746 SET_EXPECT(MimeFilter_ReportData);
1747 }else if(pi & PI_MIMEVERIFICATION) {
1748 if(!short_read && pr < 200)
1751 CHECK_CALLED(ReportProgress_MIMETYPEAVAILABLE);
1754 CHECK_CALLED(ReportData);
1763 static HRESULT WINAPI ProtocolEmul_Terminate(IInternetProtocolEx *iface, DWORD dwOptions)
1765 CHECK_EXPECT(Terminate);
1766 ok(!dwOptions, "dwOptions=%d\n", dwOptions);
1770 static HRESULT WINAPI ProtocolEmul_Read(IInternetProtocolEx *iface, void *pv,
1771 ULONG cb, ULONG *pcbRead)
1773 if(read_report_data)
1774 CHECK_EXPECT2(Read2);
1776 if(mimefilter_test || short_read) {
1777 if(!read_report_data)
1778 CHECK_EXPECT2(Read);
1779 }else if((pi & PI_MIMEVERIFICATION)) {
1780 if(!read_report_data)
1781 CHECK_EXPECT2(Read);
1783 if(prot_read < 300) {
1784 ok(pv != expect_pv, "pv == expect_pv\n");
1786 ok(cb == 2048-prot_read, "cb=%d\n", cb);
1788 ok(cb == 700, "cb=%d\n", cb);
1790 ok(expect_pv <= pv && (BYTE*)pv < (BYTE*)expect_pv + cb, "pv != expect_pv\n");
1793 if(!read_report_data)
1796 ok(pv == expect_pv, "pv != expect_pv\n");
1797 ok(cb == 1000, "cb=%d\n", cb);
1798 ok(!*pcbRead, "*pcbRead = %d\n", *pcbRead);
1800 ok(pcbRead != NULL, "pcbRead == NULL\n");
1802 if(prot_state == 3 || (short_read && prot_state != 4)) {
1807 SET_EXPECT(Read2); /* checked in BINDSTATUS_MIMETYPEAVAILABLE */
1808 SET_EXPECT(ReportProgress_MIMETYPEAVAILABLE);
1811 SET_EXPECT(MimeFilter_ReportData);
1812 else if(direct_read)
1813 SET_EXPECT(ReportData2);
1815 hres = IInternetProtocolSink_ReportData(binding_sink,
1816 BSCF_LASTDATANOTIFICATION|BSCF_INTERMEDIATEDATANOTIFICATION, 0, 0);
1818 ok(hres == S_OK, "ReportData failed: %08x\n", hres);
1820 CHECK_CALLED(ReportProgress_MIMETYPEAVAILABLE);
1822 CHECK_CALLED(MimeFilter_ReportData);
1823 else if(direct_read)
1824 CHECK_CALLED(ReportData2);
1827 SET_EXPECT(MimeFilter_ReportResult);
1829 SET_EXPECT(ReportResult);
1830 hres = IInternetProtocolSink_ReportResult(binding_sink, S_OK, ERROR_SUCCESS, NULL);
1831 ok(hres == S_OK, "ReportResult failed: %08x\n", hres);
1833 CHECK_CALLED(MimeFilter_ReportResult);
1835 CHECK_CALLED(ReportResult);
1837 memset(pv, 'x', 100);
1838 prot_read += *pcbRead = 100;
1840 }if(prot_state == 4) {
1845 if((async_read_pending = !async_read_pending)) {
1847 return tested_protocol == HTTP_TEST || tested_protocol == HTTPS_TEST ? E_PENDING : S_FALSE;
1850 memset(pv, 'x', 100);
1851 prot_read += *pcbRead = 100;
1855 static HRESULT WINAPI ProtocolEmul_LockRequest(IInternetProtocolEx *iface, DWORD dwOptions)
1857 CHECK_EXPECT(LockRequest);
1858 ok(dwOptions == 0, "dwOptions=%x\n", dwOptions);
1862 static HRESULT WINAPI ProtocolEmul_UnlockRequest(IInternetProtocolEx *iface)
1864 CHECK_EXPECT(UnlockRequest);
1868 static HRESULT WINAPI ProtocolEmul_StartEx(IInternetProtocolEx *iface, IUri *pUri,
1869 IInternetProtocolSink *pOIProtSink, IInternetBindInfo *pOIBindInfo,
1870 DWORD grfPI, HANDLE *dwReserved)
1872 CHECK_EXPECT(StartEx);
1873 ok(!dwReserved, "dwReserved = %p\n", dwReserved);
1874 protocol_start(pOIProtSink, pOIBindInfo, grfPI);
1878 static const IInternetProtocolExVtbl ProtocolVtbl = {
1879 ProtocolEmul_QueryInterface,
1883 ProtocolEmul_Continue,
1885 ProtocolEmul_Terminate,
1890 ProtocolEmul_LockRequest,
1891 ProtocolEmul_UnlockRequest,
1892 ProtocolEmul_StartEx
1895 static IInternetProtocolEx Protocol = { &ProtocolVtbl };
1897 static HRESULT WINAPI MimeProtocol_QueryInterface(IInternetProtocolEx *iface, REFIID riid, void **ppv)
1899 if(IsEqualGUID(&IID_IUnknown, riid) || IsEqualGUID(&IID_IInternetProtocol, riid)) {
1904 if(IsEqualGUID(&IID_IInternetProtocolSink, riid)) {
1905 *ppv = &mime_protocol_sink;
1909 ok(0, "unexpected riid %s\n", debugstr_guid(riid));
1911 return E_NOINTERFACE;
1914 static HRESULT WINAPI MimeProtocol_Start(IInternetProtocolEx *iface, LPCWSTR szUrl,
1915 IInternetProtocolSink *pOIProtSink, IInternetBindInfo *pOIBindInfo,
1916 DWORD grfPI, HANDLE_PTR dwReserved)
1918 PROTOCOLFILTERDATA *data;
1919 LPOLESTR url_str = NULL;
1925 CHECK_EXPECT(MimeFilter_Start);
1927 ok(!strcmp_ww(szUrl, gzipW), "wrong url %s\n", wine_dbgstr_w(szUrl));
1928 ok(grfPI == (PI_FILTER_MODE|PI_FORCE_ASYNC), "grfPI=%x, expected PI_FILTER_MODE|PI_FORCE_ASYNC\n", grfPI);
1929 ok(dwReserved, "dwReserved == 0\n");
1930 ok(pOIProtSink != NULL, "pOIProtSink == NULL\n");
1931 ok(pOIBindInfo != NULL, "pOIBindInfo == NULL\n");
1934 ok(pOIProtSink != binding_sink, "pOIProtSink == protocol_sink\n");
1935 ok(pOIBindInfo == prot_bind_info, "pOIBindInfo != bind_info\n");
1937 ok(pOIProtSink == &protocol_sink, "pOIProtSink != protocol_sink\n");
1938 ok(pOIBindInfo == &bind_info, "pOIBindInfo != bind_info\n");
1941 data = (void*)dwReserved;
1942 ok(data->cbSize == sizeof(*data), "data->cbSize = %d\n", data->cbSize);
1943 ok(!data->pProtocolSink, "data->pProtocolSink != NULL\n");
1944 ok(data->pProtocol != NULL, "data->pProtocol == NULL\n");
1945 ok(!data->pUnk, "data->pUnk != NULL\n");
1946 ok(!data->dwFilterFlags, "data->dwProtocolFlags = %x\n", data->dwFilterFlags);
1948 IInternetProtocolSink *prot_sink;
1950 IInternetProtocol_QueryInterface(data->pProtocol, &IID_IInternetProtocolSink, (void**)&prot_sink);
1951 ok(prot_sink == pOIProtSink, "QI(data->pProtocol, IID_IInternetProtocolSink) != pOIProtSink\n");
1952 IInternetProtocolSink_Release(prot_sink);
1954 ok(data->pProtocol != binding_protocol, "data->pProtocol == binding_protocol\n");
1956 filtered_protocol = data->pProtocol;
1957 IInternetProtocol_AddRef(filtered_protocol);
1959 IInternetProtocol *prot;
1961 IInternetProtocol_QueryInterface(data->pProtocol, &IID_IInternetProtocol, (void**)&prot);
1962 ok(prot == async_protocol, "QI(data->pProtocol, IID_IInternetProtocol) != async_protocol\n");
1963 IInternetProtocol_Release(prot);
1965 ok(data->pProtocol != async_protocol, "data->pProtocol == async_protocol\n");
1968 filtered_sink = pOIProtSink;
1970 SET_EXPECT(ReportProgress_DECODING);
1971 hres = IInternetProtocolSink_ReportProgress(pOIProtSink, BINDSTATUS_DECODING, gzipW);
1972 ok(hres == S_OK, "ReportProgress(BINDSTATUS_DECODING) failed: %08x\n", hres);
1973 CHECK_CALLED(ReportProgress_DECODING);
1975 SET_EXPECT(GetBindInfo);
1976 memset(&bindinfo, 0, sizeof(bindinfo));
1977 bindinfo.cbSize = sizeof(bindinfo);
1978 hres = IInternetBindInfo_GetBindInfo(pOIBindInfo, &cbindf, &bindinfo);
1979 ok(hres == S_OK, "GetBindInfo failed: %08x\n", hres);
1980 ok(cbindf == (bindf|BINDF_FROMURLMON), "cbindf = %x, expected %x\n", cbindf, bindf);
1981 CHECK_CALLED(GetBindInfo);
1983 SET_EXPECT(GetBindString_URL);
1984 hres = IInternetBindInfo_GetBindString(pOIBindInfo, BINDSTRING_URL, &url_str, 1, &fetched);
1985 ok(hres == S_OK, "GetBindString(BINDSTRING_URL) failed: %08x\n", hres);
1986 ok(fetched == 1, "fetched = %d\n", fetched);
1987 ok(!strcmp_ww(url_str, binding_urls[tested_protocol]), "wrong url_str %s\n", wine_dbgstr_w(url_str));
1988 CoTaskMemFree(url_str);
1989 CHECK_CALLED(GetBindString_URL);
1994 static HRESULT WINAPI Protocol_Continue(IInternetProtocolEx *iface,
1995 PROTOCOLDATA *pProtocolData)
1997 CHECK_EXPECT(MimeFilter_Continue);
2001 static HRESULT WINAPI MimeProtocol_Terminate(IInternetProtocolEx *iface, DWORD dwOptions)
2005 CHECK_EXPECT(MimeFilter_Terminate);
2007 ok(!dwOptions, "dwOptions = %x\n", dwOptions);
2009 SET_EXPECT(Terminate);
2010 hres = IInternetProtocol_Terminate(filtered_protocol, dwOptions);
2011 ok(hres == S_OK, "Terminate failed: %08x\n", hres);
2012 CHECK_CALLED(Terminate);
2017 static HRESULT WINAPI MimeProtocol_Read(IInternetProtocolEx *iface, void *pv,
2018 ULONG cb, ULONG *pcbRead)
2024 CHECK_EXPECT(MimeFilter_Read);
2026 ok(pv != NULL, "pv == NULL\n");
2027 ok(cb != 0, "cb == 0\n");
2028 ok(pcbRead != NULL, "pcbRead == NULL\n");
2030 if(read_report_data)
2034 hres = IInternetProtocol_Read(filtered_protocol, buf, sizeof(buf), &read);
2035 ok(hres == S_OK || hres == S_FALSE || hres == E_PENDING, "Read failed: %08x\n", hres);
2036 if(read_report_data)
2037 CHECK_CALLED(Read2);
2042 ok(*pcbRead == 0, "*pcbRead=%d, expected 0\n", *pcbRead);
2046 memset(pv, 'x', read);
2050 static HRESULT WINAPI MimeProtocol_LockRequest(IInternetProtocolEx *iface, DWORD dwOptions)
2054 CHECK_EXPECT(MimeFilter_LockRequest);
2056 ok(!dwOptions, "dwOptions = %x\n", dwOptions);
2058 SET_EXPECT(LockRequest);
2059 hres = IInternetProtocol_LockRequest(filtered_protocol, dwOptions);
2060 ok(hres == S_OK, "LockRequest failed: %08x\n", hres);
2061 CHECK_CALLED(LockRequest);
2066 static HRESULT WINAPI MimeProtocol_UnlockRequest(IInternetProtocolEx *iface)
2070 CHECK_EXPECT(MimeFilter_UnlockRequest);
2072 SET_EXPECT(UnlockRequest);
2073 hres = IInternetProtocol_UnlockRequest(filtered_protocol);
2074 ok(hres == S_OK, "UnlockRequest failed: %08x\n", hres);
2075 CHECK_CALLED(UnlockRequest);
2080 static const IInternetProtocolExVtbl MimeProtocolVtbl = {
2081 MimeProtocol_QueryInterface,
2087 MimeProtocol_Terminate,
2092 MimeProtocol_LockRequest,
2093 MimeProtocol_UnlockRequest
2096 static IInternetProtocolEx MimeProtocol = { &MimeProtocolVtbl };
2098 static HRESULT WINAPI ClassFactory_QueryInterface(IClassFactory *iface, REFIID riid, void **ppv)
2100 ok(0, "unexpected call\n");
2101 return E_NOINTERFACE;
2104 static ULONG WINAPI ClassFactory_AddRef(IClassFactory *iface)
2109 static ULONG WINAPI ClassFactory_Release(IClassFactory *iface)
2114 static HRESULT WINAPI ClassFactory_CreateInstance(IClassFactory *iface, IUnknown *pOuter,
2115 REFIID riid, void **ppv)
2117 CHECK_EXPECT(CreateInstance);
2119 ok(pOuter == (IUnknown*)prot_bind_info, "pOuter != protocol_unk\n");
2120 ok(IsEqualGUID(&IID_IUnknown, riid), "unexpected riid %s\n", debugstr_guid(riid));
2121 ok(ppv != NULL, "ppv == NULL\n");
2127 static HRESULT WINAPI ClassFactory_LockServer(IClassFactory *iface, BOOL dolock)
2129 ok(0, "unexpected call\n");
2133 static const IClassFactoryVtbl ClassFactoryVtbl = {
2134 ClassFactory_QueryInterface,
2135 ClassFactory_AddRef,
2136 ClassFactory_Release,
2137 ClassFactory_CreateInstance,
2138 ClassFactory_LockServer
2141 static IClassFactory ClassFactory = { &ClassFactoryVtbl };
2143 static HRESULT WINAPI MimeFilter_CreateInstance(IClassFactory *iface, IUnknown *outer, REFIID riid, void **ppv)
2145 CHECK_EXPECT(MimeFilter_CreateInstance);
2147 ok(!outer, "outer = %p\n", outer);
2148 ok(IsEqualGUID(&IID_IInternetProtocol, riid), "unexpected riid %s\n", debugstr_guid(riid));
2150 *ppv = &MimeProtocol;
2154 static const IClassFactoryVtbl MimeFilterCFVtbl = {
2155 ClassFactory_QueryInterface,
2156 ClassFactory_AddRef,
2157 ClassFactory_Release,
2158 MimeFilter_CreateInstance,
2159 ClassFactory_LockServer
2162 static IClassFactory mimefilter_cf = { &MimeFilterCFVtbl };
2164 #define TEST_BINDING 0x0001
2165 #define TEST_FILTER 0x0002
2166 #define TEST_FIRST_HTTP 0x0004
2167 #define TEST_DIRECT_READ 0x0008
2168 #define TEST_POST 0x0010
2169 #define TEST_EMULATEPROT 0x0020
2170 #define TEST_SHORT_READ 0x0040
2171 #define TEST_REDIRECT 0x0080
2172 #define TEST_ABORT 0x0100
2173 #define TEST_ASYNCREQ 0x0200
2174 #define TEST_USEIURI 0x0400
2175 #define TEST_IMPLPROTEX 0x0800
2177 static void init_test(int prot, DWORD flags)
2179 tested_protocol = prot;
2180 binding_test = (flags & TEST_BINDING) != 0;
2181 first_data_notif = TRUE;
2184 async_read_pending = TRUE;
2185 mimefilter_test = (flags & TEST_FILTER) != 0;
2187 post_stream_read = 0;
2188 ResetEvent(event_complete);
2189 ResetEvent(event_complete2);
2190 ResetEvent(event_continue);
2191 ResetEvent(event_continue_done);
2192 async_protocol = binding_protocol = filtered_protocol = NULL;
2193 filtered_sink = NULL;
2194 http_is_first = (flags & TEST_FIRST_HTTP) != 0;
2195 first_data_notif = TRUE;
2196 state = STATE_CONNECTING;
2197 test_async_req = (flags & TEST_ASYNCREQ) != 0;
2198 direct_read = (flags & TEST_DIRECT_READ) != 0;
2199 emulate_prot = (flags & TEST_EMULATEPROT) != 0;
2200 wait_for_switch = TRUE;
2201 short_read = (flags & TEST_SHORT_READ) != 0;
2202 http_post_test = TYMED_NULL;
2203 test_redirect = (flags & TEST_REDIRECT) != 0;
2204 test_abort = (flags & TEST_ABORT) != 0;
2205 impl_protex = (flags & TEST_IMPLPROTEX) != 0;
2208 static void test_priority(IInternetProtocol *protocol)
2210 IInternetPriority *priority;
2214 hres = IInternetProtocol_QueryInterface(protocol, &IID_IInternetPriority,
2216 ok(hres == S_OK, "QueryInterface(IID_IInternetPriority) failed: %08x\n", hres);
2220 hres = IInternetPriority_GetPriority(priority, &pr);
2221 ok(hres == S_OK, "GetPriority failed: %08x\n", hres);
2222 ok(pr == 0, "pr=%d, expected 0\n", pr);
2224 hres = IInternetPriority_SetPriority(priority, 1);
2225 ok(hres == S_OK, "SetPriority failed: %08x\n", hres);
2227 hres = IInternetPriority_GetPriority(priority, &pr);
2228 ok(hres == S_OK, "GetPriority failed: %08x\n", hres);
2229 ok(pr == 1, "pr=%d, expected 1\n", pr);
2231 IInternetPriority_Release(priority);
2234 static void test_early_abort(const CLSID *clsid)
2236 IInternetProtocol *protocol;
2239 hres = CoCreateInstance(clsid, NULL, CLSCTX_INPROC_SERVER|CLSCTX_INPROC_HANDLER,
2240 &IID_IInternetProtocol, (void**)&protocol);
2241 ok(hres == S_OK, "CoCreateInstance failed: %08x\n", hres);
2243 hres = IInternetProtocol_Abort(protocol, E_ABORT, 0);
2244 ok(hres == S_OK, "Abort failed: %08x\n", hres);
2246 hres = IInternetProtocol_Abort(protocol, E_FAIL, 0);
2247 ok(hres == S_OK, "Abort failed: %08x\n", hres);
2249 IInternetProtocol_Release(protocol);
2252 static BOOL file_protocol_start(IInternetProtocol *protocol, LPCWSTR url,
2253 IInternetProtocolEx *protocolex, IUri *uri, BOOL is_first)
2257 SET_EXPECT(GetBindInfo);
2258 if(!(bindf & BINDF_FROMURLMON))
2259 SET_EXPECT(ReportProgress_DIRECTBIND);
2261 SET_EXPECT(ReportProgress_SENDINGREQUEST);
2262 SET_EXPECT(ReportProgress_CACHEFILENAMEAVAILABLE);
2263 if(bindf & BINDF_FROMURLMON)
2264 SET_EXPECT(ReportProgress_VERIFIEDMIMETYPEAVAILABLE);
2266 SET_EXPECT(ReportProgress_MIMETYPEAVAILABLE);
2268 SET_EXPECT(ReportData);
2270 SET_EXPECT(ReportResult);
2272 expect_hrResult = S_OK;
2275 hres = IInternetProtocolEx_StartEx(protocolex, uri, &protocol_sink, &bind_info, 0, 0);
2276 ok(hres == S_OK, "StartEx failed: %08x\n", hres);
2278 hres = IInternetProtocol_Start(protocol, url, &protocol_sink, &bind_info, 0, 0);
2279 if(hres == INET_E_RESOURCE_NOT_FOUND) {
2280 win_skip("Start failed\n");
2283 ok(hres == S_OK, "Start failed: %08x\n", hres);
2286 CHECK_CALLED(GetBindInfo);
2287 if(!(bindf & BINDF_FROMURLMON))
2288 CHECK_CALLED(ReportProgress_DIRECTBIND);
2290 CHECK_CALLED(ReportProgress_SENDINGREQUEST);
2291 CHECK_CALLED(ReportProgress_CACHEFILENAMEAVAILABLE);
2292 if(bindf & BINDF_FROMURLMON)
2293 CHECK_CALLED(ReportProgress_VERIFIEDMIMETYPEAVAILABLE);
2295 CHECK_CALLED(ReportProgress_MIMETYPEAVAILABLE);
2297 CHECK_CALLED(ReportData);
2299 CHECK_CALLED(ReportResult);
2304 static void test_file_protocol_url(LPCWSTR url)
2306 IInternetProtocolInfo *protocol_info;
2308 IClassFactory *factory;
2309 IInternetProtocol *protocol;
2314 hres = CoGetClassObject(&CLSID_FileProtocol, CLSCTX_INPROC_SERVER, NULL,
2315 &IID_IUnknown, (void**)&unk);
2316 ok(hres == S_OK, "CoGetClassObject failed: %08x\n", hres);
2320 hres = IUnknown_QueryInterface(unk, &IID_IInternetProtocolInfo, (void**)&protocol_info);
2321 ok(hres == E_NOINTERFACE,
2322 "Could not get IInternetProtocolInfo interface: %08x, expected E_NOINTERFACE\n", hres);
2324 hres = IUnknown_QueryInterface(unk, &IID_IClassFactory, (void**)&factory);
2325 ok(hres == S_OK, "Could not get IClassFactory interface\n");
2326 IUnknown_Release(unk);
2330 hres = IClassFactory_CreateInstance(factory, NULL, &IID_IInternetProtocol, (void**)&protocol);
2331 ok(hres == S_OK, "Could not get IInternetProtocol: %08x\n", hres);
2333 if(SUCCEEDED(hres)) {
2334 if(file_protocol_start(protocol, url, NULL, NULL, TRUE)) {
2335 hres = IInternetProtocol_Read(protocol, buf, 2, &cb);
2336 ok(hres == S_OK, "Read failed: %08x\n", hres);
2337 ok(cb == 2, "cb=%u expected 2\n", cb);
2338 hres = IInternetProtocol_Read(protocol, buf, sizeof(buf), &cb);
2339 ok(hres == S_FALSE, "Read failed: %08x\n", hres);
2340 hres = IInternetProtocol_Read(protocol, buf, sizeof(buf), &cb);
2341 ok(hres == S_FALSE, "Read failed: %08x expected S_FALSE\n", hres);
2342 ok(cb == 0, "cb=%u expected 0\n", cb);
2343 hres = IInternetProtocol_UnlockRequest(protocol);
2344 ok(hres == S_OK, "UnlockRequest failed: %08x\n", hres);
2347 if(file_protocol_start(protocol, url, NULL, NULL, FALSE)) {
2348 hres = IInternetProtocol_Read(protocol, buf, 2, &cb);
2349 ok(hres == S_FALSE, "Read failed: %08x\n", hres);
2350 hres = IInternetProtocol_LockRequest(protocol, 0);
2351 ok(hres == S_OK, "LockRequest failed: %08x\n", hres);
2352 hres = IInternetProtocol_UnlockRequest(protocol);
2353 ok(hres == S_OK, "UnlockRequest failed: %08x\n", hres);
2356 IInternetProtocol_Release(protocol);
2359 hres = IClassFactory_CreateInstance(factory, NULL, &IID_IInternetProtocol, (void**)&protocol);
2360 ok(hres == S_OK, "Could not get IInternetProtocol: %08x\n", hres);
2361 if(SUCCEEDED(hres)) {
2362 if(file_protocol_start(protocol, url, NULL, NULL, TRUE)) {
2363 hres = IInternetProtocol_LockRequest(protocol, 0);
2364 ok(hres == S_OK, "LockRequest failed: %08x\n", hres);
2365 hres = IInternetProtocol_Terminate(protocol, 0);
2366 ok(hres == S_OK, "Terminate failed: %08x\n", hres);
2367 hres = IInternetProtocol_Read(protocol, buf, 2, &cb);
2368 ok(hres == S_OK, "Read failed: %08x\n\n", hres);
2369 hres = IInternetProtocol_UnlockRequest(protocol);
2370 ok(hres == S_OK, "UnlockRequest failed: %08x\n", hres);
2371 hres = IInternetProtocol_Read(protocol, buf, 2, &cb);
2372 ok(hres == S_OK, "Read failed: %08x\n", hres);
2373 hres = IInternetProtocol_Terminate(protocol, 0);
2374 ok(hres == S_OK, "Terminate failed: %08x\n", hres);
2377 IInternetProtocol_Release(protocol);
2380 hres = IClassFactory_CreateInstance(factory, NULL, &IID_IInternetProtocol, (void**)&protocol);
2381 ok(hres == S_OK, "Could not get IInternetProtocol: %08x\n", hres);
2382 if(SUCCEEDED(hres)) {
2383 if(file_protocol_start(protocol, url, NULL, NULL, TRUE)) {
2384 hres = IInternetProtocol_Terminate(protocol, 0);
2385 ok(hres == S_OK, "Terminate failed: %08x\n", hres);
2386 hres = IInternetProtocol_Read(protocol, buf, 2, &cb);
2387 ok(hres == S_OK, "Read failed: %08x\n", hres);
2388 ok(cb == 2, "cb=%u expected 2\n", cb);
2391 IInternetProtocol_Release(protocol);
2395 IInternetProtocolEx *protocolex;
2398 hres = pCreateUri(url, Uri_CREATE_FILE_USE_DOS_PATH, 0, &uri);
2399 ok(hres == S_OK, "CreateUri failed: %08x\n", hres);
2401 hres = IClassFactory_CreateInstance(factory, NULL, &IID_IInternetProtocolEx, (void**)&protocolex);
2402 ok(hres == S_OK, "Could not get IInternetProtocolEx: %08x\n", hres);
2404 if(file_protocol_start(NULL, NULL, protocolex, uri, TRUE)) {
2405 hres = IInternetProtocolEx_Read(protocolex, buf, 2, &cb);
2406 ok(hres == S_OK, "Read failed: %08x\n", hres);
2407 hres = IInternetProtocolEx_LockRequest(protocolex, 0);
2408 ok(hres == S_OK, "LockRequest failed: %08x\n", hres);
2409 hres = IInternetProtocolEx_UnlockRequest(protocolex);
2410 ok(hres == S_OK, "UnlockRequest failed: %08x\n", hres);
2414 IInternetProtocolEx_Release(protocolex);
2416 win_skip("Skipping file protocol StartEx tests\n");
2419 IClassFactory_Release(factory);
2422 static void test_file_protocol_fail(void)
2424 IInternetProtocol *protocol;
2427 static const WCHAR index_url2[] =
2428 {'f','i','l','e',':','/','/','i','n','d','e','x','.','h','t','m','l',0};
2430 hres = CoCreateInstance(&CLSID_FileProtocol, NULL, CLSCTX_INPROC_SERVER|CLSCTX_INPROC_HANDLER,
2431 &IID_IInternetProtocol, (void**)&protocol);
2432 ok(hres == S_OK, "CoCreateInstance failed: %08x\n", hres);
2436 SET_EXPECT(GetBindInfo);
2437 expect_hrResult = MK_E_SYNTAX;
2438 hres = IInternetProtocol_Start(protocol, wszIndexHtml, &protocol_sink, &bind_info, 0, 0);
2439 ok(hres == MK_E_SYNTAX ||
2440 hres == E_INVALIDARG,
2441 "Start failed: %08x, expected MK_E_SYNTAX or E_INVALIDARG\n", hres);
2442 CLEAR_CALLED(GetBindInfo); /* GetBindInfo not called in IE7 */
2444 SET_EXPECT(GetBindInfo);
2445 if(!(bindf & BINDF_FROMURLMON))
2446 SET_EXPECT(ReportProgress_DIRECTBIND);
2447 SET_EXPECT(ReportProgress_SENDINGREQUEST);
2448 SET_EXPECT(ReportResult);
2449 expect_hrResult = INET_E_RESOURCE_NOT_FOUND;
2450 hres = IInternetProtocol_Start(protocol, index_url, &protocol_sink, &bind_info, 0, 0);
2451 ok(hres == INET_E_RESOURCE_NOT_FOUND,
2452 "Start failed: %08x expected INET_E_RESOURCE_NOT_FOUND\n", hres);
2453 CHECK_CALLED(GetBindInfo);
2454 if(!(bindf & BINDF_FROMURLMON))
2455 CHECK_CALLED(ReportProgress_DIRECTBIND);
2456 CHECK_CALLED(ReportProgress_SENDINGREQUEST);
2457 CHECK_CALLED(ReportResult);
2459 IInternetProtocol_Release(protocol);
2461 hres = CoCreateInstance(&CLSID_FileProtocol, NULL, CLSCTX_INPROC_SERVER|CLSCTX_INPROC_HANDLER,
2462 &IID_IInternetProtocol, (void**)&protocol);
2463 ok(hres == S_OK, "CoCreateInstance failed: %08x\n", hres);
2467 SET_EXPECT(GetBindInfo);
2468 if(!(bindf & BINDF_FROMURLMON))
2469 SET_EXPECT(ReportProgress_DIRECTBIND);
2470 SET_EXPECT(ReportProgress_SENDINGREQUEST);
2471 SET_EXPECT(ReportResult);
2472 expect_hrResult = INET_E_RESOURCE_NOT_FOUND;
2474 hres = IInternetProtocol_Start(protocol, index_url2, &protocol_sink, &bind_info, 0, 0);
2475 ok(hres == INET_E_RESOURCE_NOT_FOUND,
2476 "Start failed: %08x, expected INET_E_RESOURCE_NOT_FOUND\n", hres);
2477 CHECK_CALLED(GetBindInfo);
2478 if(!(bindf & BINDF_FROMURLMON))
2479 CHECK_CALLED(ReportProgress_DIRECTBIND);
2480 CHECK_CALLED(ReportProgress_SENDINGREQUEST);
2481 CHECK_CALLED(ReportResult);
2483 SET_EXPECT(GetBindInfo);
2484 hres = IInternetProtocol_Start(protocol, NULL, &protocol_sink, &bind_info, 0, 0);
2485 ok(hres == E_INVALIDARG, "Start failed: %08x, expected E_INVALIDARG\n", hres);
2486 CLEAR_CALLED(GetBindInfo); /* GetBindInfo not called in IE7 */
2488 SET_EXPECT(GetBindInfo);
2489 hres = IInternetProtocol_Start(protocol, emptyW, &protocol_sink, &bind_info, 0, 0);
2490 ok(hres == E_INVALIDARG, "Start failed: %08x, expected E_INVALIDARG\n", hres);
2491 CLEAR_CALLED(GetBindInfo); /* GetBindInfo not called in IE7 */
2493 IInternetProtocol_Release(protocol);
2496 static void test_file_protocol(void) {
2497 WCHAR buf[INTERNET_MAX_URL_LENGTH], file_name_buf[MAX_PATH];
2502 static const WCHAR wszFile[] = {'f','i','l','e',':',0};
2503 static const WCHAR wszFile2[] = {'f','i','l','e',':','/','/',0};
2504 static const WCHAR wszFile3[] = {'f','i','l','e',':','/','/','/',0};
2505 static const WCHAR wszFile4[] = {'f','i','l','e',':','\\','\\',0};
2506 static const char html_doc[] = "<HTML></HTML>";
2508 trace("Testing file protocol...\n");
2509 init_test(FILE_TEST, 0);
2511 SetLastError(0xdeadbeef);
2512 file = CreateFileW(wszIndexHtml, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS,
2513 FILE_ATTRIBUTE_NORMAL, NULL);
2514 if(!file && GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)
2516 win_skip("Detected Win9x or WinMe\n");
2519 ok(file != INVALID_HANDLE_VALUE, "CreateFile failed\n");
2520 if(file == INVALID_HANDLE_VALUE)
2522 WriteFile(file, html_doc, sizeof(html_doc)-1, &size, NULL);
2525 file_name = wszIndexHtml;
2527 test_file_protocol_url(index_url);
2528 bindf = BINDF_FROMURLMON;
2529 test_file_protocol_url(index_url);
2530 bindf = BINDF_FROMURLMON | BINDF_NEEDFILE;
2531 test_file_protocol_url(index_url);
2533 memcpy(buf, wszFile, sizeof(wszFile));
2534 len = sizeof(wszFile)/sizeof(WCHAR)-1;
2535 len += GetCurrentDirectoryW(sizeof(buf)/sizeof(WCHAR)-len, buf+len);
2537 memcpy(buf+len, wszIndexHtml, sizeof(wszIndexHtml));
2539 file_name = buf + sizeof(wszFile)/sizeof(WCHAR)-1;
2541 test_file_protocol_url(buf);
2542 bindf = BINDF_FROMURLMON;
2543 test_file_protocol_url(buf);
2545 memcpy(buf, wszFile2, sizeof(wszFile2));
2546 len = GetCurrentDirectoryW(sizeof(file_name_buf)/sizeof(WCHAR), file_name_buf);
2547 file_name_buf[len++] = '\\';
2548 memcpy(file_name_buf+len, wszIndexHtml, sizeof(wszIndexHtml));
2549 lstrcpyW(buf+sizeof(wszFile2)/sizeof(WCHAR)-1, file_name_buf);
2550 file_name = file_name_buf;
2552 test_file_protocol_url(buf);
2553 bindf = BINDF_FROMURLMON;
2554 test_file_protocol_url(buf);
2556 buf[sizeof(wszFile2)/sizeof(WCHAR)] = '|';
2557 test_file_protocol_url(buf);
2559 memcpy(buf, wszFile3, sizeof(wszFile3));
2560 len = sizeof(wszFile3)/sizeof(WCHAR)-1;
2561 len += GetCurrentDirectoryW(sizeof(buf)/sizeof(WCHAR)-len, buf+len);
2563 memcpy(buf+len, wszIndexHtml, sizeof(wszIndexHtml));
2565 file_name = buf + sizeof(wszFile3)/sizeof(WCHAR)-1;
2567 test_file_protocol_url(buf);
2568 bindf = BINDF_FROMURLMON;
2569 test_file_protocol_url(buf);
2571 memcpy(buf, wszFile4, sizeof(wszFile4));
2572 len = GetCurrentDirectoryW(sizeof(file_name_buf)/sizeof(WCHAR), file_name_buf);
2573 file_name_buf[len++] = '\\';
2574 memcpy(file_name_buf+len, wszIndexHtml, sizeof(wszIndexHtml));
2575 lstrcpyW(buf+sizeof(wszFile4)/sizeof(WCHAR)-1, file_name_buf);
2576 file_name = file_name_buf;
2578 test_file_protocol_url(buf);
2579 bindf = BINDF_FROMURLMON;
2580 test_file_protocol_url(buf);
2582 buf[sizeof(wszFile4)/sizeof(WCHAR)] = '|';
2583 test_file_protocol_url(buf);
2585 DeleteFileW(wszIndexHtml);
2588 test_file_protocol_fail();
2589 bindf = BINDF_FROMURLMON;
2590 test_file_protocol_fail();
2593 static BOOL http_protocol_start(LPCWSTR url, BOOL use_iuri)
2595 static BOOL got_user_agent = FALSE;
2599 if(use_iuri && pCreateUri) {
2600 hres = pCreateUri(url, 0, 0, &uri);
2601 ok(hres == S_OK, "CreateUri failed: %08x\n", hres);
2604 SET_EXPECT(GetBindInfo);
2605 if (!(bindf & BINDF_FROMURLMON))
2606 SET_EXPECT(ReportProgress_DIRECTBIND);
2608 SET_EXPECT(GetBindString_USER_AGENT);
2609 SET_EXPECT(GetBindString_ACCEPT_MIMES);
2610 SET_EXPECT(QueryService_HttpNegotiate);
2611 SET_EXPECT(BeginningTransaction);
2612 SET_EXPECT(GetRootSecurityId);
2613 if(http_post_test) {
2614 SET_EXPECT(GetBindString_POST_COOKIE);
2615 if(http_post_test == TYMED_ISTREAM)
2616 SET_EXPECT(Stream_Seek);
2620 IInternetProtocolEx *protocolex;
2622 hres = IInternetProtocol_QueryInterface(async_protocol, &IID_IInternetProtocolEx, (void**)&protocolex);
2623 ok(hres == S_OK, "Could not get IInternetProtocolEx iface: %08x\n", hres);
2625 hres = IInternetProtocolEx_StartEx(protocolex, uri, &protocol_sink, &bind_info, 0, 0);
2626 ok(hres == S_OK, "Start failed: %08x\n", hres);
2628 IInternetProtocolEx_Release(protocolex);
2631 hres = IInternetProtocol_Start(async_protocol, url, &protocol_sink, &bind_info, 0, 0);
2632 ok(hres == S_OK, "Start failed: %08x\n", hres);
2637 CHECK_CALLED(GetBindInfo);
2638 if (!(bindf & BINDF_FROMURLMON))
2639 CHECK_CALLED(ReportProgress_DIRECTBIND);
2640 if (!got_user_agent)
2642 CHECK_CALLED(GetBindString_USER_AGENT);
2643 got_user_agent = TRUE;
2645 CHECK_CALLED(GetBindString_ACCEPT_MIMES);
2646 CHECK_CALLED(QueryService_HttpNegotiate);
2647 CHECK_CALLED(BeginningTransaction);
2648 /* GetRootSecurityId called on WinXP but not on Win98 */
2649 CLEAR_CALLED(GetRootSecurityId);
2650 if(http_post_test) {
2651 CHECK_CALLED(GetBindString_POST_COOKIE);
2652 if(http_post_test == TYMED_ISTREAM)
2653 CHECK_CALLED(Stream_Seek);
2659 static void test_protocol_terminate(IInternetProtocol *protocol)
2665 hres = IInternetProtocol_LockRequest(protocol, 0);
2666 ok(hres == S_OK, "LockRequest failed: %08x\n", hres);
2668 hres = IInternetProtocol_Read(protocol, buf, 1, &cb);
2669 ok(hres == test_abort ? S_OK : S_FALSE, "Read failed: %08x\n", hres);
2671 hres = IInternetProtocol_Terminate(protocol, 0);
2672 ok(hres == S_OK, "Terminate failed: %08x\n", hres);
2674 /* This wait is to give the internet handles being freed in Terminate
2675 * enough time to actually terminate in all cases. Internet handles
2676 * terminate asynchronously and native reuses the main InternetOpen
2677 * handle. The only case in which this seems to be necessary is on
2678 * wine with native wininet and urlmon, resulting in the next time
2679 * test_http_protocol_url being called the first data notification actually
2680 * being an extra last data notification from the previous connection
2681 * about once out of every ten times. */
2684 hres = IInternetProtocol_UnlockRequest(protocol);
2685 ok(hres == S_OK, "UnlockRequest failed: %08x\n", hres);
2688 static void test_http_info(IInternetProtocol *protocol)
2690 IWinInetHttpInfo *info;
2693 hres = IInternetProtocol_QueryInterface(protocol, &IID_IWinInetHttpInfo, (void**)&info);
2694 ok(hres == S_OK, "Could not get IWinInterHttpInfo iface: %08x\n", hres);
2698 IWinInetHttpInfo_Release(info);
2701 /* is_first refers to whether this is the first call to this function
2703 static void test_http_protocol_url(LPCWSTR url, int prot, DWORD flags, DWORD tymed)
2705 IInternetProtocolInfo *protocol_info;
2706 IClassFactory *factory;
2710 init_test(prot, flags);
2712 http_post_test = tymed;
2714 hres = CoGetClassObject(prot == HTTPS_TEST ? &CLSID_HttpSProtocol : &CLSID_HttpProtocol,
2715 CLSCTX_INPROC_SERVER, NULL, &IID_IUnknown, (void**)&unk);
2716 ok(hres == S_OK, "CoGetClassObject failed: %08x\n", hres);
2720 hres = IUnknown_QueryInterface(unk, &IID_IInternetProtocolInfo, (void**)&protocol_info);
2721 ok(hres == E_NOINTERFACE,
2722 "Could not get IInternetProtocolInfo interface: %08x, expected E_NOINTERFACE\n",
2725 hres = IUnknown_QueryInterface(unk, &IID_IClassFactory, (void**)&factory);
2726 ok(hres == S_OK, "Could not get IClassFactory interface\n");
2727 IUnknown_Release(unk);
2731 hres = IClassFactory_CreateInstance(factory, NULL, &IID_IInternetProtocol,
2732 (void**)&async_protocol);
2733 ok(hres == S_OK, "Could not get IInternetProtocol: %08x\n", hres);
2734 if(SUCCEEDED(hres)) {
2739 test_priority(async_protocol);
2740 test_http_info(async_protocol);
2742 SET_EXPECT(ReportProgress_COOKIE_SENT);
2743 SET_EXPECT(ReportProgress_FINDINGRESOURCE);
2744 SET_EXPECT(ReportProgress_CONNECTING);
2745 SET_EXPECT(ReportProgress_SENDINGREQUEST);
2747 SET_EXPECT(ReportProgress_REDIRECTING);
2748 SET_EXPECT(ReportProgress_PROXYDETECTING);
2749 if(prot == HTTP_TEST)
2750 SET_EXPECT(ReportProgress_CACHEFILENAMEAVAILABLE);
2752 SET_EXPECT(QueryService_HttpSecurity);
2753 if(!(bindf & BINDF_FROMURLMON)) {
2754 SET_EXPECT(OnResponse);
2755 SET_EXPECT(ReportProgress_RAWMIMETYPE);
2756 SET_EXPECT(ReportData);
2761 if(!http_protocol_start(url, (flags & TEST_USEIURI) != 0))
2764 if(!direct_read && !test_abort)
2765 SET_EXPECT(ReportResult);
2766 expect_hrResult = test_abort ? E_ABORT : S_OK;
2770 while(wait_for_switch) {
2771 WaitForSingleObject(event_continue, INFINITE);
2772 CHECK_CALLED(Switch); /* Set in ReportData */
2773 call_continue(&continue_protdata);
2774 SetEvent(event_continue_done);
2777 hres = IInternetProtocol_Read(async_protocol, buf, 1, &cb);
2778 ok((hres == E_PENDING && cb==0) ||
2779 (hres == S_OK && cb==1), "Read failed: %08x (%d bytes)\n", hres, cb);
2781 WaitForSingleObject(event_complete, INFINITE);
2782 if(bindf & BINDF_FROMURLMON)
2783 CHECK_CALLED(Switch);
2785 CHECK_CALLED(ReportData);
2786 if(prot == HTTPS_TEST)
2787 CLEAR_CALLED(QueryService_HttpSecurity);
2790 if(bindf & BINDF_FROMURLMON)
2793 SET_EXPECT(ReportData);
2794 hres = IInternetProtocol_Read(async_protocol, buf, sizeof(buf), &cb);
2795 if(hres == E_PENDING) {
2796 hres = IInternetProtocol_Read(async_protocol, buf, 1, &cb);
2797 ok((hres == E_PENDING && cb==0) ||
2798 (hres == S_OK && cb==1), "Read failed: %08x (%d bytes)\n", hres, cb);
2799 WaitForSingleObject(event_complete, INFINITE);
2800 if(bindf & BINDF_FROMURLMON)
2801 CHECK_CALLED(Switch);
2803 CHECK_CALLED(ReportData);
2808 SET_EXPECT(ReportResult);
2809 hres = IInternetProtocol_Abort(async_protocol, E_ABORT, 0);
2810 ok(hres == S_OK, "Abort failed: %08x\n", hres);
2811 CHECK_CALLED(ReportResult);
2813 hres = IInternetProtocol_Abort(async_protocol, E_ABORT, 0);
2814 ok(hres == INET_E_RESULT_DISPATCHED, "Abort failed: %08x\n", hres);
2818 if(bindf & BINDF_FROMURLMON)
2819 CHECK_NOT_CALLED(Switch);
2821 CHECK_NOT_CALLED(ReportData);
2826 ok(hres == S_FALSE, "Read failed: %08x\n", hres);
2827 CHECK_CALLED(ReportResult);
2830 if(prot == HTTPS_TEST)
2831 CLEAR_CALLED(ReportProgress_SENDINGREQUEST);
2833 hres = IInternetProtocol_Abort(async_protocol, E_ABORT, 0);
2834 ok(hres == INET_E_RESULT_DISPATCHED, "Abort failed: %08x\n", hres);
2836 test_protocol_terminate(async_protocol);
2838 hres = IInternetProtocol_Abort(async_protocol, E_ABORT, 0);
2839 ok(hres == S_OK, "Abort failed: %08x\n", hres);
2841 ref = IInternetProtocol_Release(async_protocol);
2842 ok(!ref, "ref=%x\n", ref);
2845 IClassFactory_Release(factory);
2848 static void test_http_protocol(void)
2850 static const WCHAR winehq_url[] =
2851 {'h','t','t','p',':','/','/','w','w','w','.','w','i','n','e','h','q','.',
2852 'o','r','g','/','s','i','t','e','/','a','b','o','u','t',0};
2853 static const WCHAR posttest_url[] =
2854 {'h','t','t','p',':','/','/','c','r','o','s','s','o','v','e','r','.',
2855 'c','o','d','e','w','e','a','v','e','r','s','.','c','o','m','/',
2856 'p','o','s','t','t','e','s','t','.','p','h','p',0};
2857 static const WCHAR redirect_url[] =
2858 {'h','t','t','p',':','/','/','t','e','s','t','.','w','i','n','e','h','q','.','o','r','g','/',
2859 't','e','s','t','r','e','d','i','r','e','c','t',0};
2861 trace("Testing http protocol (not from urlmon)...\n");
2862 bindf = BINDF_ASYNCHRONOUS | BINDF_ASYNCSTORAGE | BINDF_PULLDATA;
2863 test_http_protocol_url(winehq_url, HTTP_TEST, TEST_FIRST_HTTP, TYMED_NULL);
2865 trace("Testing http protocol (from urlmon)...\n");
2866 bindf = BINDF_ASYNCHRONOUS | BINDF_ASYNCSTORAGE | BINDF_PULLDATA | BINDF_FROMURLMON;
2867 test_http_protocol_url(winehq_url, HTTP_TEST, 0, TYMED_NULL);
2869 trace("Testing http protocol (to file)...\n");
2870 bindf = BINDF_ASYNCHRONOUS | BINDF_ASYNCSTORAGE | BINDF_PULLDATA | BINDF_FROMURLMON | BINDF_NEEDFILE;
2871 test_http_protocol_url(winehq_url, HTTP_TEST, 0, TYMED_NULL);
2873 trace("Testing http protocol (post data)...\n");
2874 /* Without this flag we get a ReportProgress_CACHEFILENAMEAVAILABLE
2875 * notification with BINDVERB_POST */
2876 bindf = BINDF_ASYNCHRONOUS | BINDF_ASYNCSTORAGE | BINDF_PULLDATA | BINDF_FROMURLMON | BINDF_NOWRITECACHE;
2877 test_http_protocol_url(posttest_url, HTTP_TEST, TEST_FIRST_HTTP|TEST_POST, TYMED_HGLOBAL);
2879 trace("Testing http protocol (post data stream)...\n");
2880 test_http_protocol_url(posttest_url, HTTP_TEST, TEST_FIRST_HTTP|TEST_POST|TEST_ASYNCREQ, TYMED_ISTREAM);
2882 trace("Testing http protocol (direct read)...\n");
2883 bindf = BINDF_ASYNCHRONOUS | BINDF_ASYNCSTORAGE | BINDF_PULLDATA | BINDF_FROMURLMON;
2884 test_http_protocol_url(winehq_url, HTTP_TEST, TEST_DIRECT_READ|TEST_USEIURI, TYMED_NULL);
2886 trace("Testing http protocol (redirected)...\n");
2887 bindf = BINDF_ASYNCHRONOUS | BINDF_ASYNCSTORAGE | BINDF_PULLDATA | BINDF_FROMURLMON;
2888 test_http_protocol_url(redirect_url, HTTP_TEST, TEST_REDIRECT, TYMED_NULL);
2890 trace("Testing http protocol abort...\n");
2891 test_http_protocol_url(winehq_url, HTTP_TEST, TEST_ABORT, TYMED_NULL);
2893 test_early_abort(&CLSID_HttpProtocol);
2894 test_early_abort(&CLSID_HttpSProtocol);
2897 static void test_https_protocol(void)
2899 static const WCHAR codeweavers_url[] =
2900 {'h','t','t','p','s',':','/','/','w','w','w','.','c','o','d','e','w','e','a','v','e','r','s',
2901 '.','c','o','m','/','t','e','s','t','.','h','t','m','l',0};
2903 trace("Testing https protocol (from urlmon)...\n");
2904 bindf = BINDF_ASYNCHRONOUS | BINDF_ASYNCSTORAGE | BINDF_PULLDATA | BINDF_FROMURLMON | BINDF_NOWRITECACHE;
2905 test_http_protocol_url(codeweavers_url, HTTPS_TEST, TEST_FIRST_HTTP, TYMED_NULL);
2909 static void test_ftp_protocol(void)
2911 IInternetProtocolInfo *protocol_info;
2912 IClassFactory *factory;
2919 static const WCHAR ftp_urlW[] = {'f','t','p',':','/','/','f','t','p','.','w','i','n','e','h','q','.','o','r','g',
2920 '/','p','u','b','/','o','t','h','e','r','/',
2921 'w','i','n','e','l','o','g','o','.','x','c','f','.','t','a','r','.','b','z','2',0};
2923 trace("Testing ftp protocol...\n");
2925 bindf = BINDF_ASYNCHRONOUS | BINDF_ASYNCSTORAGE | BINDF_PULLDATA | BINDF_FROMURLMON | BINDF_NOWRITECACHE;
2926 state = STATE_STARTDOWNLOADING;
2927 tested_protocol = FTP_TEST;
2928 first_data_notif = TRUE;
2929 expect_hrResult = E_PENDING;
2931 hres = CoGetClassObject(&CLSID_FtpProtocol, CLSCTX_INPROC_SERVER, NULL, &IID_IUnknown, (void**)&unk);
2932 ok(hres == S_OK, "CoGetClassObject failed: %08x\n", hres);
2936 hres = IUnknown_QueryInterface(unk, &IID_IInternetProtocolInfo, (void**)&protocol_info);
2937 ok(hres == E_NOINTERFACE, "Could not get IInternetProtocolInfo interface: %08x, expected E_NOINTERFACE\n", hres);
2939 hres = IUnknown_QueryInterface(unk, &IID_IClassFactory, (void**)&factory);
2940 ok(hres == S_OK, "Could not get IClassFactory interface\n");
2941 IUnknown_Release(unk);
2945 hres = IClassFactory_CreateInstance(factory, NULL, &IID_IInternetProtocol,
2946 (void**)&async_protocol);
2947 IClassFactory_Release(factory);
2948 ok(hres == S_OK, "Could not get IInternetProtocol: %08x\n", hres);
2950 test_priority(async_protocol);
2951 test_http_info(async_protocol);
2953 SET_EXPECT(GetBindInfo);
2954 SET_EXPECT(ReportProgress_FINDINGRESOURCE);
2955 SET_EXPECT(ReportProgress_CONNECTING);
2956 SET_EXPECT(ReportProgress_SENDINGREQUEST);
2959 hres = IInternetProtocol_Start(async_protocol, ftp_urlW, &protocol_sink, &bind_info, 0, 0);
2960 ok(hres == S_OK, "Start failed: %08x\n", hres);
2961 CHECK_CALLED(GetBindInfo);
2963 SET_EXPECT(ReportResult);
2965 hres = IInternetProtocol_Read(async_protocol, buf, 1, &cb);
2966 ok((hres == E_PENDING && cb==0) ||
2967 (hres == S_OK && cb==1), "Read failed: %08x (%d bytes)\n", hres, cb);
2969 WaitForSingleObject(event_complete, INFINITE);
2972 hres = IInternetProtocol_Read(async_protocol, buf, sizeof(buf), &cb);
2973 if(hres == E_PENDING)
2974 WaitForSingleObject(event_complete, INFINITE);
2979 ok(hres == S_FALSE, "Read failed: %08x\n", hres);
2980 CHECK_CALLED(ReportResult);
2981 CHECK_CALLED(Switch);
2983 test_protocol_terminate(async_protocol);
2986 IInternetProtocolEx *protocolex;
2988 hres = IInternetProtocol_QueryInterface(async_protocol, &IID_IInternetProtocolEx, (void**)&protocolex);
2989 ok(hres == S_OK, "Could not get IInternetProtocolEx iface: %08x\n", hres);
2990 IInternetProtocolEx_Release(protocolex);
2993 ref = IInternetProtocol_Release(async_protocol);
2994 ok(!ref, "ref=%d\n", ref);
2996 test_early_abort(&CLSID_FtpProtocol);
2999 static void test_gopher_protocol(void)
3001 IInternetProtocolInfo *protocol_info;
3002 IClassFactory *factory;
3006 trace("Testing gopher protocol...\n");
3008 hres = CoGetClassObject(&CLSID_GopherProtocol, CLSCTX_INPROC_SERVER, NULL, &IID_IUnknown, (void**)&unk);
3010 hres == REGDB_E_CLASSNOTREG, /* Gopher protocol has been removed as of Vista */
3011 "CoGetClassObject failed: %08x\n", hres);
3015 hres = IUnknown_QueryInterface(unk, &IID_IInternetProtocolInfo, (void**)&protocol_info);
3016 ok(hres == E_NOINTERFACE, "Could not get IInternetProtocolInfo interface: %08x, expected E_NOINTERFACE\n", hres);
3018 hres = IUnknown_QueryInterface(unk, &IID_IClassFactory, (void**)&factory);
3019 ok(hres == S_OK, "Could not get IClassFactory interface\n");
3020 IUnknown_Release(unk);
3024 hres = IClassFactory_CreateInstance(factory, NULL, &IID_IInternetProtocol,
3025 (void**)&async_protocol);
3026 IClassFactory_Release(factory);
3027 ok(hres == S_OK, "Could not get IInternetProtocol: %08x\n", hres);
3029 test_priority(async_protocol);
3031 IInternetProtocol_Release(async_protocol);
3033 test_early_abort(&CLSID_GopherProtocol);
3036 static void test_mk_protocol(void)
3038 IInternetProtocolInfo *protocol_info;
3039 IInternetProtocol *protocol;
3040 IClassFactory *factory;
3044 static const WCHAR wrong_url1[] = {'t','e','s','t',':','@','M','S','I','T','S','t','o','r','e',
3045 ':',':','/','t','e','s','t','.','h','t','m','l',0};
3046 static const WCHAR wrong_url2[] = {'m','k',':','/','t','e','s','t','.','h','t','m','l',0};
3048 trace("Testing mk protocol...\n");
3049 init_test(MK_TEST, 0);
3051 hres = CoGetClassObject(&CLSID_MkProtocol, CLSCTX_INPROC_SERVER, NULL,
3052 &IID_IUnknown, (void**)&unk);
3053 ok(hres == S_OK, "CoGetClassObject failed: %08x\n", hres);
3055 hres = IUnknown_QueryInterface(unk, &IID_IInternetProtocolInfo, (void**)&protocol_info);
3056 ok(hres == E_NOINTERFACE,
3057 "Could not get IInternetProtocolInfo interface: %08x, expected E_NOINTERFACE\n",
3060 hres = IUnknown_QueryInterface(unk, &IID_IClassFactory, (void**)&factory);
3061 ok(hres == S_OK, "Could not get IClassFactory interface\n");
3062 IUnknown_Release(unk);
3066 hres = IClassFactory_CreateInstance(factory, NULL, &IID_IInternetProtocol,
3068 IClassFactory_Release(factory);
3069 ok(hres == S_OK, "Could not get IInternetProtocol: %08x\n", hres);
3071 SET_EXPECT(GetBindInfo);
3072 hres = IInternetProtocol_Start(protocol, wrong_url1, &protocol_sink, &bind_info, 0, 0);
3073 ok(hres == MK_E_SYNTAX || hres == INET_E_INVALID_URL,
3074 "Start failed: %08x, expected MK_E_SYNTAX or INET_E_INVALID_URL\n", hres);
3075 CLEAR_CALLED(GetBindInfo);
3077 SET_EXPECT(GetBindInfo);
3078 SET_EXPECT(ReportProgress_DIRECTBIND);
3079 SET_EXPECT(ReportProgress_SENDINGREQUEST);
3080 SET_EXPECT(ReportProgress_MIMETYPEAVAILABLE);
3081 SET_EXPECT(ReportResult);
3082 expect_hrResult = INET_E_RESOURCE_NOT_FOUND;
3084 hres = IInternetProtocol_Start(protocol, wrong_url2, &protocol_sink, &bind_info, 0, 0);
3085 ok(hres == INET_E_RESOURCE_NOT_FOUND ||
3086 hres == INET_E_INVALID_URL, /* win2k3 */
3087 "Start failed: %08x, expected INET_E_RESOURCE_NOT_FOUND or INET_E_INVALID_URL\n", hres);
3089 if (hres == INET_E_RESOURCE_NOT_FOUND) {
3090 CHECK_CALLED(GetBindInfo);
3091 CLEAR_CALLED(ReportProgress_DIRECTBIND);
3092 CHECK_CALLED(ReportProgress_SENDINGREQUEST);
3093 CHECK_CALLED(ReportProgress_MIMETYPEAVAILABLE);
3094 CHECK_CALLED(ReportResult);
3096 CLEAR_CALLED(GetBindInfo);
3097 CLEAR_CALLED(ReportProgress_DIRECTBIND);
3098 CLEAR_CALLED(ReportProgress_SENDINGREQUEST);
3099 CLEAR_CALLED(ReportProgress_MIMETYPEAVAILABLE);
3100 CLEAR_CALLED(ReportResult);
3103 IInternetProtocol_Release(protocol);
3106 static void test_CreateBinding(void)
3108 IInternetProtocol *protocol;
3109 IInternetPriority *priority;
3110 IInternetSession *session;
3111 IWinInetHttpInfo *http_info;
3112 IWinInetInfo *inet_info;
3118 static const WCHAR test_url[] =
3119 {'t','e','s','t',':','/','/','f','i','l','e','.','h','t','m','l',0};
3120 static const WCHAR wsz_test[] = {'t','e','s','t',0};
3122 trace("Testing CreateBinding...\n");
3123 init_test(BIND_TEST, TEST_BINDING);
3125 hres = pCoInternetGetSession(0, &session, 0);
3126 ok(hres == S_OK, "CoInternetGetSession failed: %08x\n", hres);
3128 hres = IInternetSession_RegisterNameSpace(session, &ClassFactory, &IID_NULL, wsz_test, 0, NULL, 0);
3129 ok(hres == S_OK, "RegisterNameSpace failed: %08x\n", hres);
3131 hres = IInternetSession_CreateBinding(session, NULL, test_url, NULL, NULL, &protocol, 0);
3132 binding_protocol = protocol;
3133 ok(hres == S_OK, "CreateBinding failed: %08x\n", hres);
3134 ok(protocol != NULL, "protocol == NULL\n");
3136 hres = IInternetProtocol_QueryInterface(protocol, &IID_IInternetBindInfo, (void**)&prot_bind_info);
3137 ok(hres == S_OK, "QueryInterface(IID_IInternetBindInfo) failed: %08x\n", hres);
3139 hres = IInternetProtocol_QueryInterface(protocol, &IID_IInternetProtocolSink, (void**)&binding_sink);
3140 ok(hres == S_OK, "Could not get IInternetProtocolSink: %08x\n", hres);
3142 hres = IInternetProtocol_Start(protocol, test_url, NULL, &bind_info, 0, 0);
3143 ok(hres == E_INVALIDARG, "Start failed: %08x, expected E_INVALIDARG\n", hres);
3144 hres = IInternetProtocol_Start(protocol, test_url, &protocol_sink, NULL, 0, 0);
3145 ok(hres == E_INVALIDARG, "Start failed: %08x, expected E_INVALIDARG\n", hres);
3146 hres = IInternetProtocol_Start(protocol, NULL, &protocol_sink, &bind_info, 0, 0);
3147 ok(hres == E_INVALIDARG, "Start failed: %08x, expected E_INVALIDARG\n", hres);
3149 hres = IInternetProtocol_QueryInterface(protocol, &IID_IInternetPriority, (void**)&priority);
3150 ok(hres == S_OK, "QueryInterface(IID_IInternetPriority) failed: %08x\n", hres);
3153 hres = IInternetPriority_GetPriority(priority, &p);
3154 ok(hres == S_OK, "GetPriority failed: %08x\n", hres);
3155 ok(!p, "p=%d\n", p);
3158 hres = IInternetPriority_SetPriority(priority, 100);
3159 ok(hres == S_OK, "SetPriority failed: %08x\n", hres);
3162 hres = IInternetPriority_GetPriority(priority, &p);
3163 ok(hres == S_OK, "GetPriority failed: %08x\n", hres);
3164 ok(p == 100, "p=%d\n", p);
3166 hres = IInternetProtocol_QueryInterface(protocol, &IID_IWinInetInfo, (void**)&inet_info);
3167 ok(hres == E_NOINTERFACE, "Could not get IWinInetInfo protocol: %08x\n", hres);
3169 SET_EXPECT(QueryService_InternetProtocol);
3170 SET_EXPECT(CreateInstance);
3171 SET_EXPECT(ReportProgress_PROTOCOLCLASSID);
3172 SET_EXPECT(SetPriority);
3175 expect_hrResult = S_OK;
3176 hres = IInternetProtocol_Start(protocol, test_url, &protocol_sink, &bind_info, 0, 0);
3177 ok(hres == S_OK, "Start failed: %08x\n", hres);
3179 CHECK_CALLED(QueryService_InternetProtocol);
3180 CHECK_CALLED(CreateInstance);
3181 CHECK_CALLED(ReportProgress_PROTOCOLCLASSID);
3182 CHECK_CALLED(SetPriority);
3183 CHECK_CALLED(Start);
3185 SET_EXPECT(QueryInterface_IWinInetInfo);
3186 hres = IInternetProtocol_QueryInterface(protocol, &IID_IWinInetInfo, (void**)&inet_info);
3187 ok(hres == E_NOINTERFACE, "Could not get IWinInetInfo protocol: %08x\n", hres);
3188 CHECK_CALLED(QueryInterface_IWinInetInfo);
3190 SET_EXPECT(QueryInterface_IWinInetInfo);
3191 hres = IInternetProtocol_QueryInterface(protocol, &IID_IWinInetInfo, (void**)&inet_info);
3192 ok(hres == E_NOINTERFACE, "Could not get IWinInetInfo protocol: %08x\n", hres);
3193 CHECK_CALLED(QueryInterface_IWinInetInfo);
3195 SET_EXPECT(QueryInterface_IWinInetHttpInfo);
3196 hres = IInternetProtocol_QueryInterface(protocol, &IID_IWinInetHttpInfo, (void**)&http_info);
3197 ok(hres == E_NOINTERFACE, "Could not get IWinInetInfo protocol: %08x\n", hres);
3198 CHECK_CALLED(QueryInterface_IWinInetHttpInfo);
3202 hres = IInternetProtocol_Read(protocol, expect_pv = buf, sizeof(buf), &read);
3203 ok(hres == S_OK, "Read failed: %08x\n", hres);
3204 ok(read == 100, "read = %d\n", read);
3209 hres = IInternetProtocol_Read(protocol, expect_pv = buf, sizeof(buf), &read);
3210 ok(hres == S_FALSE, "Read failed: %08x\n", hres);
3211 ok(!read, "read = %d\n", read);
3215 hres = IInternetPriority_GetPriority(priority, &p);
3216 ok(hres == S_OK, "GetPriority failed: %08x\n", hres);
3217 ok(p == 100, "p=%d\n", p);
3219 hres = IInternetPriority_SetPriority(priority, 101);
3220 ok(hres == S_OK, "SetPriority failed: %08x\n", hres);
3222 SET_EXPECT(Terminate);
3223 hres = IInternetProtocol_Terminate(protocol, 0xdeadbeef);
3224 ok(hres == S_OK, "Terminate failed: %08x\n", hres);
3225 CHECK_CALLED(Terminate);
3227 SET_EXPECT(Continue);
3228 hres = IInternetProtocolSink_Switch(binding_sink, &protocoldata);
3229 ok(hres == S_OK, "Switch failed: %08x\n", hres);
3230 CHECK_CALLED(Continue);
3232 hres = IInternetProtocolSink_ReportProgress(binding_sink,
3233 BINDSTATUS_CACHEFILENAMEAVAILABLE, expect_wsz = emptyW);
3234 ok(hres == S_OK, "ReportProgress(BINDSTATUS_CACHEFILENAMEAVAILABLE) failed: %08x\n", hres);
3236 hres = IInternetProtocolSink_ReportResult(binding_sink, S_OK, ERROR_SUCCESS, NULL);
3237 ok(hres == E_FAIL, "ReportResult failed: %08x, expected E_FAIL\n", hres);
3239 hres = IInternetProtocolSink_ReportData(binding_sink, 0, 0, 0);
3240 ok(hres == S_OK, "ReportData failed: %08x\n", hres);
3242 IInternetProtocolSink_Release(binding_sink);
3243 IInternetPriority_Release(priority);
3244 IInternetBindInfo_Release(prot_bind_info);
3245 IInternetProtocol_Release(protocol);
3247 hres = IInternetSession_CreateBinding(session, NULL, test_url, NULL, NULL, &protocol, 0);
3248 ok(hres == S_OK, "CreateBinding failed: %08x\n", hres);
3249 ok(protocol != NULL, "protocol == NULL\n");
3251 hres = IInternetProtocol_Abort(protocol, E_ABORT, 0);
3252 ok(hres == S_OK, "Abort failed: %08x\n", hres);
3254 hres = IInternetProtocol_Abort(protocol, E_FAIL, 0);
3255 ok(hres == S_OK, "Abort failed: %08x\n", hres);
3257 IInternetProtocol_Release(protocol);
3259 hres = IInternetSession_UnregisterNameSpace(session, &ClassFactory, wsz_test);
3260 ok(hres == S_OK, "UnregisterNameSpace failed: %08x\n", hres);
3262 hres = IInternetSession_CreateBinding(session, NULL, test_url, NULL, NULL, &protocol, 0);
3263 ok(hres == S_OK, "CreateBinding failed: %08x\n", hres);
3264 ok(protocol != NULL, "protocol == NULL\n");
3266 SET_EXPECT(QueryService_InternetProtocol);
3267 hres = IInternetProtocol_Start(protocol, test_url, &protocol_sink, &bind_info, 0, 0);
3268 ok(hres == MK_E_SYNTAX, "Start failed: %08x, expected MK_E_SYNTAX\n", hres);
3269 CHECK_CALLED(QueryService_InternetProtocol);
3271 IInternetProtocol_Release(protocol);
3273 IInternetSession_Release(session);
3276 static void test_binding(int prot, DWORD grf_pi, DWORD test_flags)
3278 IInternetProtocolEx *protocolex = NULL;
3279 IInternetProtocol *protocol;
3280 IInternetSession *session;
3287 init_test(prot, test_flags|TEST_BINDING);
3289 hres = pCoInternetGetSession(0, &session, 0);
3290 ok(hres == S_OK, "CoInternetGetSession failed: %08x\n", hres);
3292 if(test_flags & TEST_EMULATEPROT) {
3293 hres = IInternetSession_RegisterNameSpace(session, &ClassFactory, &IID_NULL, protocol_names[prot], 0, NULL, 0);
3294 ok(hres == S_OK, "RegisterNameSpace failed: %08x\n", hres);
3297 hres = IInternetSession_CreateBinding(session, NULL, binding_urls[prot], NULL, NULL, &protocol, 0);
3298 binding_protocol = protocol;
3299 ok(hres == S_OK, "CreateBinding failed: %08x\n", hres);
3300 ok(protocol != NULL, "protocol == NULL\n");
3302 hres = IInternetProtocol_QueryInterface(protocol, &IID_IInternetBindInfo, (void**)&prot_bind_info);
3303 ok(hres == S_OK, "QueryInterface(IID_IInternetBindInfo) failed: %08x\n", hres);
3305 hres = IInternetProtocol_QueryInterface(protocol, &IID_IInternetProtocolSink, (void**)&binding_sink);
3306 ok(hres == S_OK, "QueryInterface(IID_IInternetProtocolSink) failed: %08x\n", hres);
3308 if(test_flags & TEST_USEIURI) {
3309 hres = IInternetProtocol_QueryInterface(protocol, &IID_IInternetProtocolEx, (void**)&protocolex);
3310 ok(hres == S_OK, "Could not get IInternetProtocolEx iface: %08x\n", hres);
3312 hres = pCreateUri(binding_urls[prot], Uri_CREATE_FILE_USE_DOS_PATH, 0, &uri);
3313 ok(hres == S_OK, "CreateUri failed: %08x\n", hres);
3317 SET_EXPECT(QueryService_InternetProtocol);
3318 SET_EXPECT(CreateInstance);
3319 SET_EXPECT(ReportProgress_PROTOCOLCLASSID);
3320 SET_EXPECT(SetPriority);
3322 SET_EXPECT(StartEx);
3326 expect_hrResult = S_OK;
3329 hres = IInternetProtocolEx_StartEx(protocolex, uri, &protocol_sink, &bind_info, pi, 0);
3330 ok(hres == S_OK, "StartEx failed: %08x\n", hres);
3332 hres = IInternetProtocol_Start(protocol, binding_urls[prot], &protocol_sink, &bind_info, pi, 0);
3333 ok(hres == S_OK, "Start failed: %08x\n", hres);
3336 CHECK_CALLED(QueryService_InternetProtocol);
3337 CHECK_CALLED(CreateInstance);
3338 CHECK_CALLED(ReportProgress_PROTOCOLCLASSID);
3339 CHECK_CALLED(SetPriority);
3341 CHECK_CALLED(StartEx);
3343 CHECK_CALLED(Start);
3346 IInternetProtocolEx_Release(protocolex);
3350 if(prot == HTTP_TEST || prot == HTTPS_TEST) {
3351 while(prot_state < 4) {
3352 WaitForSingleObject(event_complete, INFINITE);
3353 if(mimefilter_test && filtered_protocol) {
3354 SET_EXPECT(Continue);
3355 IInternetProtocol_Continue(filtered_protocol, pdata);
3356 CHECK_CALLED(Continue);
3358 SET_EXPECT(Continue);
3359 IInternetProtocol_Continue(protocol, pdata);
3360 CHECK_CALLED(Continue);
3362 if(test_abort && prot_state == 2) {
3364 hres = IInternetProtocol_Abort(protocol, E_ABORT, 0);
3365 ok(hres == S_OK, "Abort failed: %08x\n", hres);
3366 CHECK_CALLED(Abort);
3368 hres = IInternetProtocol_Abort(protocol, E_ABORT, 0);
3369 ok(hres == S_OK, "Abort failed: %08x\n", hres);
3370 SetEvent(event_complete2);
3373 SetEvent(event_complete2);
3376 CHECK_CALLED(ReportData); /* Set in ReportResult */
3377 WaitForSingleObject(event_complete, INFINITE);
3380 SET_EXPECT(MimeFilter_LockRequest);
3382 SET_EXPECT(LockRequest);
3383 hres = IInternetProtocol_LockRequest(protocol, 0);
3384 ok(hres == S_OK, "LockRequest failed: %08x\n", hres);
3386 CHECK_CALLED(MimeFilter_LockRequest);
3388 CHECK_CALLED(LockRequest);
3391 SET_EXPECT(MimeFilter_UnlockRequest);
3393 SET_EXPECT(UnlockRequest);
3394 hres = IInternetProtocol_UnlockRequest(protocol);
3395 ok(hres == S_OK, "UnlockRequest failed: %08x\n", hres);
3397 CHECK_CALLED(MimeFilter_UnlockRequest);
3399 CHECK_CALLED(UnlockRequest);
3403 SET_EXPECT(MimeFilter_Terminate);
3405 SET_EXPECT(Terminate);
3406 hres = IInternetProtocol_Terminate(protocol, 0);
3407 ok(hres == S_OK, "Terminate failed: %08x\n", hres);
3409 CLEAR_CALLED(MimeFilter_Terminate);
3411 CHECK_CALLED(Terminate);
3413 if(filtered_protocol)
3414 IInternetProtocol_Release(filtered_protocol);
3415 IInternetBindInfo_Release(prot_bind_info);
3416 IInternetProtocolSink_Release(binding_sink);
3417 ref = IInternetProtocol_Release(protocol);
3418 ok(!ref, "ref=%u, expected 0\n", ref);
3420 if(test_flags & TEST_EMULATEPROT) {
3421 hres = IInternetSession_UnregisterNameSpace(session, &ClassFactory, protocol_names[prot]);
3422 ok(hres == S_OK, "UnregisterNameSpace failed: %08x\n", hres);
3425 IInternetSession_Release(session);
3428 static void register_filter(void)
3430 IInternetSession *session;
3433 static const WCHAR gzipW[] = {'g','z','i','p',0};
3435 hres = pCoInternetGetSession(0, &session, 0);
3436 ok(hres == S_OK, "CoInternetGetSession failed: %08x\n", hres);
3438 hres = IInternetSession_RegisterMimeFilter(session, &mimefilter_cf, &IID_IInternetProtocol, gzipW);
3439 ok(hres == S_OK, "RegisterMimeFilter failed: %08x\n", hres);
3441 IInternetSession_Release(session);
3444 START_TEST(protocol)
3448 hurlmon = GetModuleHandle("urlmon.dll");
3449 pCoInternetGetSession = (void*) GetProcAddress(hurlmon, "CoInternetGetSession");
3450 pReleaseBindInfo = (void*) GetProcAddress(hurlmon, "ReleaseBindInfo");
3451 pCreateUri = (void*) GetProcAddress(hurlmon, "CreateUri");
3453 if(!GetProcAddress(hurlmon, "CompareSecurityIds")) {
3454 win_skip("Various needed functions not present, too old IE\n");
3459 win_skip("CreateUri not supported\n");
3461 OleInitialize(NULL);
3463 event_complete = CreateEvent(NULL, FALSE, FALSE, NULL);
3464 event_complete2 = CreateEvent(NULL, FALSE, FALSE, NULL);
3465 event_continue = CreateEvent(NULL, FALSE, FALSE, NULL);
3466 event_continue_done = CreateEvent(NULL, FALSE, FALSE, NULL);
3467 thread_id = GetCurrentThreadId();
3471 test_file_protocol();
3472 test_http_protocol();
3473 test_https_protocol();
3474 test_ftp_protocol();
3475 test_gopher_protocol();
3477 test_CreateBinding();
3479 bindf &= ~BINDF_FROMURLMON;
3480 trace("Testing file binding (mime verification, emulate prot)...\n");
3481 test_binding(FILE_TEST, PI_MIMEVERIFICATION, TEST_EMULATEPROT);
3482 trace("Testing http binding (mime verification, emulate prot)...\n");
3483 test_binding(HTTP_TEST, PI_MIMEVERIFICATION, TEST_EMULATEPROT);
3484 trace("Testing http binding (mime verification, emulate prot, short read, direct read)...\n");
3485 test_binding(HTTP_TEST, PI_MIMEVERIFICATION, TEST_EMULATEPROT|TEST_SHORT_READ|TEST_DIRECT_READ);
3486 trace("Testing file binding (mime verification, emulate prot, mime filter)...\n");
3487 test_binding(FILE_TEST, PI_MIMEVERIFICATION, TEST_EMULATEPROT|TEST_FILTER);
3488 trace("Testing http binding (mime verification, emulate prot, mime filter)...\n");
3489 test_binding(HTTP_TEST, PI_MIMEVERIFICATION, TEST_EMULATEPROT|TEST_FILTER);
3490 trace("Testing http binding (mime verification, emulate prot, direct read)...\n");
3491 test_binding(HTTP_TEST, PI_MIMEVERIFICATION, TEST_EMULATEPROT|TEST_DIRECT_READ);
3492 trace("Testing http binding (mime verification, emulate prot, abort)...\n");
3493 test_binding(HTTP_TEST, PI_MIMEVERIFICATION, TEST_EMULATEPROT|TEST_ABORT);
3495 trace("Testing file binding (use IUri, mime verification, emulate prot)...\n");
3496 test_binding(FILE_TEST, PI_MIMEVERIFICATION, TEST_EMULATEPROT|TEST_USEIURI);
3497 trace("Testing file binding (use IUri, impl StartEx, mime verification, emulate prot)...\n");
3498 test_binding(FILE_TEST, PI_MIMEVERIFICATION, TEST_EMULATEPROT|TEST_USEIURI|TEST_IMPLPROTEX);
3499 trace("Testing file binding (impl StartEx, mime verification, emulate prot)...\n");
3500 test_binding(FILE_TEST, PI_MIMEVERIFICATION, TEST_EMULATEPROT|TEST_IMPLPROTEX);
3503 CloseHandle(event_complete);
3504 CloseHandle(event_complete2);
3505 CloseHandle(event_continue);
3506 CloseHandle(event_continue_done);