2 * Copyright 2005-2011 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,
173 static const WCHAR protocol_names[][10] = {
176 {'h','t','t','p','s',0},
183 static const WCHAR binding_urls[][130] = {
184 {'f','i','l','e',':','t','e','s','t','.','h','t','m','l',0},
185 {'h','t','t','p',':','/','/','w','w','w','.','w','i','n','e','h','q','.',
186 'o','r','g','/','s','i','t','e','/','a','b','o','u','t',0},
187 {'h','t','t','p','s',':','/','/','w','w','w','.','c','o','d','e','w','e','a','v','e','r','s',
188 '.','c','o','m','/','t','e','s','t','.','h','t','m','l',0},
189 {'f','t','p',':','/','/','f','t','p','.','w','i','n','e','h','q','.','o','r','g',
190 '/','p','u','b','/','o','t','h','e','r',
191 '/','w','i','n','e','l','o','g','o','.','x','c','f','.','t','a','r','.','b','z','2',0},
192 {'m','k',':','t','e','s','t',0},
193 {'i','t','s',':','t','e','s','t','.','c','h','m',':',':','/','b','l','a','n','k','.','h','t','m','l',0},
194 {'t','e','s','t',':','/','/','f','i','l','e','.','h','t','m','l',0}
197 static const CHAR post_data[] = "mode=Test";
199 static const char *debugstr_guid(REFIID riid)
203 sprintf(buf, "{%08X-%04X-%04X-%02X%02X-%02X%02X%02X%02X%02X%02X}",
204 riid->Data1, riid->Data2, riid->Data3, riid->Data4[0],
205 riid->Data4[1], riid->Data4[2], riid->Data4[3], riid->Data4[4],
206 riid->Data4[5], riid->Data4[6], riid->Data4[7]);
211 static int strcmp_wa(LPCWSTR strw, const char *stra)
214 WideCharToMultiByte(CP_ACP, 0, strw, -1, buf, sizeof(buf), NULL, NULL);
215 return lstrcmpA(stra, buf);
218 static HRESULT WINAPI HttpSecurity_QueryInterface(IHttpSecurity *iface, REFIID riid, void **ppv)
220 if(IsEqualGUID(&IID_IUnknown, riid)
221 || IsEqualGUID(&IID_IHttpSecurity, riid)) {
226 ok(0, "unexpected call\n");
227 return E_NOINTERFACE;
230 static ULONG WINAPI HttpSecurity_AddRef(IHttpSecurity *iface)
235 static ULONG WINAPI HttpSecurity_Release(IHttpSecurity *iface)
240 static HRESULT WINAPI HttpSecurity_GetWindow(IHttpSecurity* iface, REFGUID rguidReason, HWND *phwnd)
242 trace("HttpSecurity_GetWindow\n");
247 static HRESULT WINAPI HttpSecurity_OnSecurityProblem(IHttpSecurity *iface, DWORD dwProblem)
249 trace("Security problem: %u\n", dwProblem);
250 ok(dwProblem == ERROR_INTERNET_SEC_CERT_REV_FAILED, "Expected ERROR_INTERNET_SEC_CERT_REV_FAILED got %u\n", dwProblem);
252 /* Only retry once */
253 if (security_problem)
256 security_problem = TRUE;
257 SET_EXPECT(BeginningTransaction);
262 static IHttpSecurityVtbl HttpSecurityVtbl = {
263 HttpSecurity_QueryInterface,
265 HttpSecurity_Release,
266 HttpSecurity_GetWindow,
267 HttpSecurity_OnSecurityProblem
270 static IHttpSecurity http_security = { &HttpSecurityVtbl };
272 static HRESULT WINAPI HttpNegotiate_QueryInterface(IHttpNegotiate2 *iface, REFIID riid, void **ppv)
274 if(IsEqualGUID(&IID_IUnknown, riid)
275 || IsEqualGUID(&IID_IHttpNegotiate, riid)
276 || IsEqualGUID(&IID_IHttpNegotiate2, riid)) {
281 ok(0, "unexpected call\n");
282 return E_NOINTERFACE;
285 static ULONG WINAPI HttpNegotiate_AddRef(IHttpNegotiate2 *iface)
290 static ULONG WINAPI HttpNegotiate_Release(IHttpNegotiate2 *iface)
295 static HRESULT WINAPI HttpNegotiate_BeginningTransaction(IHttpNegotiate2 *iface, LPCWSTR szURL,
296 LPCWSTR szHeaders, DWORD dwReserved, LPWSTR *pszAdditionalHeaders)
300 static const WCHAR wszHeaders[] =
301 {'C','o','n','t','e','n','t','-','T','y','p','e',':',' ','a','p','p','l','i','c','a','t',
302 'i','o','n','/','x','-','w','w','w','-','f','o','r','m','-','u','r','l','e','n','c','o',
303 'd','e','d','\r','\n',0};
305 CHECK_EXPECT(BeginningTransaction);
308 ok(!lstrcmpW(szURL, binding_urls[tested_protocol]), "szURL != http_url\n");
310 ok(!lstrcmpW(szURL, http_url), "szURL != http_url\n");
311 ok(!dwReserved, "dwReserved=%d, expected 0\n", dwReserved);
312 ok(pszAdditionalHeaders != NULL, "pszAdditionalHeaders == NULL\n");
313 if(pszAdditionalHeaders)
315 ok(*pszAdditionalHeaders == NULL, "*pszAdditionalHeaders != NULL\n");
318 addl_headers = CoTaskMemAlloc(sizeof(wszHeaders));
319 memcpy(addl_headers, wszHeaders, sizeof(wszHeaders));
320 *pszAdditionalHeaders = addl_headers;
327 static HRESULT WINAPI HttpNegotiate_OnResponse(IHttpNegotiate2 *iface, DWORD dwResponseCode,
328 LPCWSTR szResponseHeaders, LPCWSTR szRequestHeaders, LPWSTR *pszAdditionalRequestHeaders)
330 CHECK_EXPECT(OnResponse);
332 ok(dwResponseCode == 200, "dwResponseCode=%d, expected 200\n", dwResponseCode);
333 ok(szResponseHeaders != NULL, "szResponseHeaders == NULL\n");
334 ok(szRequestHeaders == NULL, "szRequestHeaders != NULL\n");
335 ok(pszAdditionalRequestHeaders == NULL, "pszAdditionalHeaders != NULL\n");
340 static HRESULT WINAPI HttpNegotiate_GetRootSecurityId(IHttpNegotiate2 *iface,
341 BYTE *pbSecurityId, DWORD *pcbSecurityId, DWORD_PTR dwReserved)
343 static const BYTE sec_id[] = {'h','t','t','p',':','t','e','s','t',1,0,0,0};
345 CHECK_EXPECT(GetRootSecurityId);
347 ok(!dwReserved, "dwReserved=%ld, expected 0\n", dwReserved);
348 ok(pbSecurityId != NULL, "pbSecurityId == NULL\n");
349 ok(pcbSecurityId != NULL, "pcbSecurityId == NULL\n");
352 ok(*pcbSecurityId == 512, "*pcbSecurityId=%d, expected 512\n", *pcbSecurityId);
353 *pcbSecurityId = sizeof(sec_id);
357 memcpy(pbSecurityId, sec_id, sizeof(sec_id));
362 static IHttpNegotiate2Vtbl HttpNegotiateVtbl = {
363 HttpNegotiate_QueryInterface,
364 HttpNegotiate_AddRef,
365 HttpNegotiate_Release,
366 HttpNegotiate_BeginningTransaction,
367 HttpNegotiate_OnResponse,
368 HttpNegotiate_GetRootSecurityId
371 static IHttpNegotiate2 http_negotiate = { &HttpNegotiateVtbl };
373 static HRESULT QueryInterface(REFIID,void**);
375 static HRESULT WINAPI ServiceProvider_QueryInterface(IServiceProvider *iface, REFIID riid, void **ppv)
377 return QueryInterface(riid, ppv);
380 static ULONG WINAPI ServiceProvider_AddRef(IServiceProvider *iface)
385 static ULONG WINAPI ServiceProvider_Release(IServiceProvider *iface)
390 static HRESULT WINAPI ServiceProvider_QueryService(IServiceProvider *iface, REFGUID guidService,
391 REFIID riid, void **ppv)
393 if(IsEqualGUID(&IID_IHttpNegotiate, guidService) || IsEqualGUID(&IID_IHttpNegotiate2, riid)) {
394 CHECK_EXPECT2(QueryService_HttpNegotiate);
395 return IHttpNegotiate2_QueryInterface(&http_negotiate, riid, ppv);
398 if(IsEqualGUID(&IID_IInternetProtocol, guidService)) {
399 ok(IsEqualGUID(&IID_IInternetProtocol, riid), "unexpected riid\n");
400 CHECK_EXPECT(QueryService_InternetProtocol);
401 return E_NOINTERFACE;
404 if(IsEqualGUID(&IID_IHttpSecurity, guidService)) {
405 ok(IsEqualGUID(&IID_IHttpSecurity, riid), "unexpected riid\n");
406 CHECK_EXPECT(QueryService_HttpSecurity);
407 return IHttpSecurity_QueryInterface(&http_security, riid, ppv);
410 ok(0, "unexpected service %s\n", debugstr_guid(guidService));
414 static const IServiceProviderVtbl ServiceProviderVtbl = {
415 ServiceProvider_QueryInterface,
416 ServiceProvider_AddRef,
417 ServiceProvider_Release,
418 ServiceProvider_QueryService
421 static IServiceProvider service_provider = { &ServiceProviderVtbl };
423 static HRESULT WINAPI Stream_QueryInterface(IStream *iface, REFIID riid, void **ppv)
425 ok(0, "unexpected call\n");
426 return E_NOINTERFACE;
429 static ULONG WINAPI Stream_AddRef(IStream *iface)
434 static ULONG WINAPI Stream_Release(IStream *iface)
439 static HRESULT WINAPI Stream_Read(IStream *iface, void *pv,
440 ULONG cb, ULONG *pcbRead)
442 CHECK_EXPECT2(Stream_Read);
444 ok(GetCurrentThreadId() != thread_id, "wrong thread %d\n", GetCurrentThreadId());
446 ok(pv != NULL, "pv == NULL\n");
447 ok(cb == 0x20000 || broken(cb == 0x2000), "cb = %d\n", cb);
448 ok(pcbRead != NULL, "pcbRead == NULL\n");
450 if(post_stream_read) {
455 memcpy(pv, post_data, sizeof(post_data)-1);
456 post_stream_read += *pcbRead = sizeof(post_data)-1;
460 static HRESULT WINAPI Stream_Write(IStream *iface, const void *pv,
461 ULONG cb, ULONG *pcbWritten)
463 ok(0, "unexpected call\n");
467 static HRESULT WINAPI Stream_Seek(IStream *iface, LARGE_INTEGER dlibMove,
468 DWORD dwOrigin, ULARGE_INTEGER *plibNewPosition)
470 CHECK_EXPECT(Stream_Seek);
472 ok(!dlibMove.QuadPart, "dlibMove != 0\n");
473 ok(dwOrigin == STREAM_SEEK_SET, "dwOrigin = %d\n", dwOrigin);
474 ok(!plibNewPosition, "plibNewPosition == NULL\n");
479 static HRESULT WINAPI Stream_SetSize(IStream *iface, ULARGE_INTEGER libNewSize)
481 ok(0, "unexpected call\n");
485 static HRESULT WINAPI Stream_CopyTo(IStream *iface, IStream *pstm,
486 ULARGE_INTEGER cb, ULARGE_INTEGER *pcbRead, ULARGE_INTEGER *pcbWritten)
488 ok(0, "unexpected call\n");
492 static HRESULT WINAPI Stream_Commit(IStream *iface, DWORD grfCommitFlags)
494 ok(0, "unexpected call\n");
498 static HRESULT WINAPI Stream_Revert(IStream *iface)
500 ok(0, "unexpected call\n");
504 static HRESULT WINAPI Stream_LockRegion(IStream *iface, ULARGE_INTEGER libOffset,
505 ULARGE_INTEGER cb, DWORD dwLockType)
507 ok(0, "unexpected call\n");
511 static HRESULT WINAPI Stream_UnlockRegion(IStream *iface,
512 ULARGE_INTEGER libOffset, ULARGE_INTEGER cb, DWORD dwLockType)
514 ok(0, "unexpected call\n");
518 static HRESULT WINAPI Stream_Stat(IStream *iface, STATSTG *pstatstg,
521 ok(0, "unexpected call\n");
525 static HRESULT WINAPI Stream_Clone(IStream *iface, IStream **ppstm)
527 ok(0, "unexpected call\n");
531 static const IStreamVtbl StreamVtbl = {
532 Stream_QueryInterface,
548 static IStream Stream = { &StreamVtbl };
550 static HRESULT WINAPI ProtocolSink_QueryInterface(IInternetProtocolSink *iface, REFIID riid, void **ppv)
552 return QueryInterface(riid, ppv);
555 static ULONG WINAPI ProtocolSink_AddRef(IInternetProtocolSink *iface)
560 static ULONG WINAPI ProtocolSink_Release(IInternetProtocolSink *iface)
565 static void call_continue(PROTOCOLDATA *protocol_data)
569 if(state == STATE_CONNECTING) {
570 if(tested_protocol == HTTP_TEST || tested_protocol == HTTPS_TEST)
571 CLEAR_CALLED(ReportProgress_COOKIE_SENT);
572 if(tested_protocol == HTTP_TEST || tested_protocol == HTTPS_TEST || tested_protocol == FTP_TEST) {
574 CLEAR_CALLED(ReportProgress_FINDINGRESOURCE);
575 CLEAR_CALLED(ReportProgress_PROXYDETECTING);
577 CLEAR_CALLED(ReportProgress_CONNECTING);
579 if(tested_protocol == FTP_TEST)
580 todo_wine CHECK_CALLED(ReportProgress_SENDINGREQUEST);
581 else if (tested_protocol != HTTPS_TEST)
582 CHECK_CALLED(ReportProgress_SENDINGREQUEST);
584 CHECK_CALLED(ReportProgress_REDIRECTING);
585 state = test_async_req ? STATE_SENDINGREQUEST : STATE_STARTDOWNLOADING;
589 case STATE_SENDINGREQUEST:
590 SET_EXPECT(Stream_Read);
591 SET_EXPECT(ReportProgress_SENDINGREQUEST);
593 case STATE_STARTDOWNLOADING:
594 if(tested_protocol == HTTP_TEST || tested_protocol == HTTPS_TEST) {
595 SET_EXPECT(OnResponse);
596 if(tested_protocol == HTTPS_TEST || test_redirect || test_abort)
597 SET_EXPECT(ReportProgress_ACCEPTRANGES);
598 SET_EXPECT(ReportProgress_MIMETYPEAVAILABLE);
599 if(bindf & BINDF_NEEDFILE)
600 SET_EXPECT(ReportProgress_CACHEFILENAMEAVAILABLE);
606 if(state != STATE_SENDINGREQUEST)
607 SET_EXPECT(ReportData);
608 hres = IInternetProtocol_Continue(async_protocol, protocol_data);
609 ok(hres == S_OK, "Continue failed: %08x\n", hres);
610 if(tested_protocol == FTP_TEST || security_problem)
611 CLEAR_CALLED(ReportData);
612 else if(state != STATE_SENDINGREQUEST)
613 CHECK_CALLED(ReportData);
616 case STATE_SENDINGREQUEST:
617 CHECK_CALLED(Stream_Read);
618 CHECK_CALLED(ReportProgress_SENDINGREQUEST);
619 state = STATE_STARTDOWNLOADING;
621 case STATE_STARTDOWNLOADING:
622 if (! security_problem)
624 state = STATE_DOWNLOADING;
625 if(tested_protocol == HTTP_TEST || tested_protocol == HTTPS_TEST) {
626 CHECK_CALLED(OnResponse);
627 if(tested_protocol == HTTPS_TEST)
628 CHECK_CALLED(ReportProgress_ACCEPTRANGES);
629 else if(test_redirect)
630 CLEAR_CALLED(ReportProgress_ACCEPTRANGES);
631 CHECK_CALLED(ReportProgress_MIMETYPEAVAILABLE);
632 if(bindf & BINDF_NEEDFILE)
633 CHECK_CALLED(ReportProgress_CACHEFILENAMEAVAILABLE);
638 security_problem = FALSE;
639 SET_EXPECT(ReportProgress_CONNECTING);
646 static HRESULT WINAPI ProtocolSink_Switch(IInternetProtocolSink *iface, PROTOCOLDATA *pProtocolData)
648 if(tested_protocol == FTP_TEST)
649 CHECK_EXPECT2(Switch);
651 CHECK_EXPECT(Switch);
653 ok(pProtocolData != NULL, "pProtocolData == NULL\n");
655 ok(pProtocolData != &protocoldata, "pProtocolData == &protocoldata\n");
656 ok(pProtocolData->grfFlags == protocoldata.grfFlags, "grfFlags wrong %x/%x\n",
657 pProtocolData->grfFlags, protocoldata.grfFlags );
658 ok(pProtocolData->dwState == protocoldata.dwState, "dwState wrong %x/%x\n",
659 pProtocolData->dwState, protocoldata.dwState );
660 ok(pProtocolData->pData == protocoldata.pData, "pData wrong %p/%p\n",
661 pProtocolData->pData, protocoldata.pData );
662 ok(pProtocolData->cbData == protocoldata.cbData, "cbData wrong %x/%x\n",
663 pProtocolData->cbData, protocoldata.cbData );
666 pdata = pProtocolData;
669 SetEvent(event_complete);
670 WaitForSingleObject(event_complete2, INFINITE);
673 continue_protdata = *pProtocolData;
674 SetEvent(event_continue);
675 WaitForSingleObject(event_continue_done, INFINITE);
677 call_continue(pProtocolData);
678 SetEvent(event_complete);
684 static HRESULT WINAPI ProtocolSink_ReportProgress(IInternetProtocolSink *iface, ULONG ulStatusCode,
685 LPCWSTR szStatusText)
687 static const WCHAR null_guid[] = {'{','0','0','0','0','0','0','0','0','-','0','0','0','0','-',
688 '0','0','0','0','-','0','0','0','0','-','0','0','0','0','0','0','0','0','0','0','0','0','}',0};
689 static const WCHAR text_plain[] = {'t','e','x','t','/','p','l','a','i','n',0};
691 switch(ulStatusCode) {
692 case BINDSTATUS_MIMETYPEAVAILABLE:
693 CHECK_EXPECT(ReportProgress_MIMETYPEAVAILABLE);
694 if(tested_protocol != FILE_TEST && tested_protocol != ITS_TEST && !mimefilter_test && (pi & PI_MIMEVERIFICATION)) {
695 if(!short_read || !direct_read)
696 CHECK_CALLED(Read); /* set in Continue */
698 CHECK_CALLED(Read2); /* set in Read */
700 ok(szStatusText != NULL, "szStatusText == NULL\n");
702 if(tested_protocol == BIND_TEST)
703 ok(szStatusText == expect_wsz, "unexpected szStatusText\n");
704 else if (http_post_test)
705 ok(lstrlenW(text_plain) <= lstrlenW(szStatusText) &&
706 !memcmp(szStatusText, text_plain, lstrlenW(text_plain)*sizeof(WCHAR)),
707 "szStatusText != text/plain\n");
708 else if(!mimefilter_test)
709 ok(lstrlenW(text_htmlW) <= lstrlenW(szStatusText) &&
710 !memcmp(szStatusText, text_htmlW, lstrlenW(text_htmlW)*sizeof(WCHAR)),
711 "szStatusText != text/html\n");
714 case BINDSTATUS_DIRECTBIND:
715 CHECK_EXPECT2(ReportProgress_DIRECTBIND);
716 ok(szStatusText == NULL, "szStatusText != NULL\n");
718 case BINDSTATUS_RAWMIMETYPE:
719 CHECK_EXPECT2(ReportProgress_RAWMIMETYPE);
720 ok(szStatusText != NULL, "szStatusText == NULL\n");
722 ok(lstrlenW(szStatusText) < lstrlenW(text_htmlW) ||
723 !memcmp(szStatusText, text_htmlW, lstrlenW(text_htmlW)*sizeof(WCHAR)),
724 "szStatusText != text/html\n");
726 case BINDSTATUS_CACHEFILENAMEAVAILABLE:
727 CHECK_EXPECT(ReportProgress_CACHEFILENAMEAVAILABLE);
728 ok(szStatusText != NULL, "szStatusText == NULL\n");
731 ok(!lstrcmpW(szStatusText, expect_wsz), "unexpected szStatusText\n");
732 else if(tested_protocol == FILE_TEST)
733 ok(!lstrcmpW(szStatusText, file_name), "szStatusText = %s\n", wine_dbgstr_w(szStatusText));
735 ok(szStatusText != NULL, "szStatusText == NULL\n");
738 case BINDSTATUS_FINDINGRESOURCE:
739 CHECK_EXPECT2(ReportProgress_FINDINGRESOURCE);
740 ok(szStatusText != NULL, "szStatusText == NULL\n");
742 case BINDSTATUS_CONNECTING:
743 CHECK_EXPECT2(ReportProgress_CONNECTING);
744 ok(szStatusText != NULL, "szStatusText == NULL\n");
746 case BINDSTATUS_SENDINGREQUEST:
747 CHECK_EXPECT2(ReportProgress_SENDINGREQUEST);
748 if(tested_protocol == FILE_TEST || tested_protocol == ITS_TEST) {
749 ok(szStatusText != NULL, "szStatusText == NULL\n");
751 ok(!*szStatusText, "wrong szStatusText\n");
754 case BINDSTATUS_VERIFIEDMIMETYPEAVAILABLE:
755 CHECK_EXPECT(ReportProgress_VERIFIEDMIMETYPEAVAILABLE);
756 ok(szStatusText != NULL, "szStatusText == NULL\n");
758 ok(!lstrcmpW(szStatusText, text_htmlW), "szStatusText != text/html\n");
760 case BINDSTATUS_PROTOCOLCLASSID:
761 CHECK_EXPECT(ReportProgress_PROTOCOLCLASSID);
762 ok(szStatusText != NULL, "szStatusText == NULL\n");
763 ok(!lstrcmpW(szStatusText, null_guid), "unexpected classid %s\n", wine_dbgstr_w(szStatusText));
765 case BINDSTATUS_COOKIE_SENT:
766 CHECK_EXPECT(ReportProgress_COOKIE_SENT);
767 ok(szStatusText == NULL, "szStatusText != NULL\n");
769 case BINDSTATUS_REDIRECTING:
770 CHECK_EXPECT(ReportProgress_REDIRECTING);
772 ok(!strcmp_wa(szStatusText, "http://test.winehq.org/tests/hello.html"), "szStatusText = %s\n", wine_dbgstr_w(szStatusText));
774 ok(szStatusText == NULL, "szStatusText = %s\n", wine_dbgstr_w(szStatusText));
776 case BINDSTATUS_ENCODING:
777 CHECK_EXPECT(ReportProgress_ENCODING);
778 ok(!strcmp_wa(szStatusText, "gzip"), "szStatusText = %s\n", wine_dbgstr_w(szStatusText));
780 case BINDSTATUS_ACCEPTRANGES:
781 CHECK_EXPECT(ReportProgress_ACCEPTRANGES);
782 ok(!szStatusText, "szStatusText = %s\n", wine_dbgstr_w(szStatusText));
784 case BINDSTATUS_PROXYDETECTING:
785 CHECK_EXPECT(ReportProgress_PROXYDETECTING);
786 SET_EXPECT(ReportProgress_CONNECTING);
787 ok(!szStatusText, "szStatusText = %s\n", wine_dbgstr_w(szStatusText));
789 case BINDSTATUS_LOADINGMIMEHANDLER:
790 CHECK_EXPECT(ReportProgress_LOADINGMIMEHANDLER);
791 ok(!szStatusText, "szStatusText = %s\n", wine_dbgstr_w(szStatusText));
793 case BINDSTATUS_DECODING:
794 CHECK_EXPECT(ReportProgress_DECODING);
795 ok(!lstrcmpW(szStatusText, gzipW), "szStatusText = %s\n", wine_dbgstr_w(szStatusText));
798 ok(0, "Unexpected status %d\n", ulStatusCode);
804 static HRESULT WINAPI ProtocolSink_ReportData(IInternetProtocolSink *iface, DWORD grfBSCF,
805 ULONG ulProgress, ULONG ulProgressMax)
809 static int rec_depth;
812 if(!mimefilter_test && (tested_protocol == FILE_TEST || tested_protocol == ITS_TEST)) {
813 CHECK_EXPECT2(ReportData);
815 ok(ulProgress == ulProgressMax, "ulProgress (%d) != ulProgressMax (%d)\n",
816 ulProgress, ulProgressMax);
817 ok(ulProgressMax == 13, "ulProgressMax=%d, expected 13\n", ulProgressMax);
818 /* BSCF_SKIPDRAINDATAFORFILEURLS added in IE8 */
819 if(tested_protocol == FILE_TEST)
820 ok((grfBSCF == (BSCF_FIRSTDATANOTIFICATION | BSCF_LASTDATANOTIFICATION)) ||
821 (grfBSCF == (BSCF_FIRSTDATANOTIFICATION | BSCF_LASTDATANOTIFICATION | BSCF_SKIPDRAINDATAFORFILEURLS)),
822 "grcfBSCF = %08x\n", grfBSCF);
824 ok(grfBSCF == (BSCF_FIRSTDATANOTIFICATION | BSCF_DATAFULLYAVAILABLE), "grcfBSCF = %08x\n", grfBSCF);
825 }else if(direct_read) {
829 if(!read_report_data && rec_depth == 1) {
830 BOOL reported_all_data = called_ReportData2;
832 CHECK_EXPECT2(ReportData);
835 ok(grfBSCF == (BSCF_FIRSTDATANOTIFICATION|BSCF_LASTDATANOTIFICATION|BSCF_DATAFULLYAVAILABLE)
836 || grfBSCF == BSCF_FIRSTDATANOTIFICATION, /* < IE8 */
837 "grcfBSCF = %08x\n", grfBSCF);
838 CHECK_CALLED(Read); /* Set in Continue */
839 first_data_notif = FALSE;
840 }else if(first_data_notif) {
841 ok(grfBSCF == BSCF_FIRSTDATANOTIFICATION, "grcfBSCF = %08x\n", grfBSCF);
842 first_data_notif = FALSE;
843 }else if(reported_all_data) {
844 ok(grfBSCF == (BSCF_LASTDATANOTIFICATION|BSCF_INTERMEDIATEDATANOTIFICATION),
845 "grcfBSCF = %08x\n", grfBSCF);
846 }else if(!direct_read) {
847 ok(grfBSCF == BSCF_INTERMEDIATEDATANOTIFICATION, "grcfBSCF = %08x\n", grfBSCF);
855 SET_EXPECT(ReportData2);
856 SET_EXPECT(ReportResult);
859 hres = IInternetProtocol_Read(binding_test ? binding_protocol : async_protocol, expect_pv = buf, sizeof(buf), &read);
860 ok(hres == E_PENDING || hres == S_FALSE || hres == S_OK, "Read failed: %08x\n", hres);
862 ok(read, "read == 0\n");
863 if(reported_all_data)
864 ok(hres == S_FALSE, "Read failed: %08x, expected S_FALSE\n", hres);
865 if(!emulate_prot && hres != E_PENDING)
866 CHECK_NOT_CALLED(Switch); /* otherwise checked in wait_for_switch loop */
869 if(!reported_all_data && called_ReportData2) {
871 CHECK_CALLED(ReportData2);
872 CHECK_CALLED(ReportResult);
873 ok(hres == S_OK, "Read failed: %08x\n", hres);
874 reported_all_data = TRUE;
877 CHECK_NOT_CALLED(ReportData2);
878 CHECK_NOT_CALLED(ReportResult);
880 }while(hres == S_OK);
882 wait_for_switch = FALSE;
884 CHECK_EXPECT(ReportData2);
886 ok(grfBSCF & BSCF_LASTDATANOTIFICATION, "grfBSCF = %08x\n", grfBSCF);
891 hres = IInternetProtocol_Read(binding_test ? binding_protocol : async_protocol, expect_pv = buf, sizeof(buf), &read);
894 ok(hres == S_FALSE, "Read returned: %08x, expected E_FALSE\n", hres);
895 ok(!read, "read = %d\n", read);
897 }else if(!binding_test && (tested_protocol == HTTP_TEST || tested_protocol == HTTPS_TEST
898 || tested_protocol == FTP_TEST)) {
899 if(!(grfBSCF & BSCF_LASTDATANOTIFICATION) || (grfBSCF & BSCF_DATAFULLYAVAILABLE))
900 CHECK_EXPECT(ReportData);
901 else if (http_post_test)
902 ok(ulProgress == 13, "Read %u bytes instead of 13\n", ulProgress);
904 ok(ulProgress, "ulProgress == 0\n");
906 if(first_data_notif) {
907 ok(grfBSCF == BSCF_FIRSTDATANOTIFICATION
908 || grfBSCF == (BSCF_LASTDATANOTIFICATION|BSCF_DATAFULLYAVAILABLE),
909 "grcfBSCF = %08x\n", grfBSCF);
910 first_data_notif = FALSE;
912 ok(grfBSCF == BSCF_INTERMEDIATEDATANOTIFICATION
913 || grfBSCF == (BSCF_LASTDATANOTIFICATION|BSCF_INTERMEDIATEDATANOTIFICATION)
914 || broken(grfBSCF == (BSCF_FIRSTDATANOTIFICATION|BSCF_LASTDATANOTIFICATION)),
915 "grcfBSCF = %08x\n", grfBSCF);
918 if(!(bindf & BINDF_FROMURLMON) &&
919 !(grfBSCF & BSCF_LASTDATANOTIFICATION)) {
920 if(state == STATE_CONNECTING) {
921 state = STATE_DOWNLOADING;
923 CHECK_CALLED(ReportProgress_FINDINGRESOURCE);
924 CHECK_CALLED(ReportProgress_CONNECTING);
926 CHECK_CALLED(ReportProgress_SENDINGREQUEST);
927 CHECK_CALLED(OnResponse);
928 CHECK_CALLED(ReportProgress_RAWMIMETYPE);
930 SetEvent(event_complete);
932 }else if(!read_report_data) {
937 CHECK_EXPECT(ReportData);
939 if(tested_protocol != BIND_TEST) {
942 SET_EXPECT(MimeFilter_Read);
943 else if(rec_depth > 1)
947 hres = IInternetProtocol_Read(binding_protocol, expect_pv=buf, sizeof(buf), &read);
949 CHECK_CALLED(MimeFilter_Read);
950 else if(rec_depth > 1)
954 }while(hres == S_OK);
962 static HRESULT WINAPI ProtocolSink_ReportResult(IInternetProtocolSink *iface, HRESULT hrResult,
963 DWORD dwError, LPCWSTR szResult)
965 CHECK_EXPECT(ReportResult);
967 if(tested_protocol == FTP_TEST)
968 ok(hrResult == E_PENDING || hrResult == S_OK, "hrResult = %08x, expected E_PENDING or S_OK\n", hrResult);
970 ok(hrResult == expect_hrResult, "hrResult = %08x, expected: %08x\n",
971 hrResult, expect_hrResult);
972 if(SUCCEEDED(hrResult) || tested_protocol == FTP_TEST || test_abort)
973 ok(dwError == ERROR_SUCCESS, "dwError = %d, expected ERROR_SUCCESS\n", dwError);
975 ok(dwError != ERROR_SUCCESS ||
976 broken(tested_protocol == MK_TEST), /* WinME and NT4 */
977 "dwError == ERROR_SUCCESS\n");
978 ok(!szResult, "szResult != NULL\n");
981 SET_EXPECT(ReportData); /* checked after main loop */
986 static IInternetProtocolSinkVtbl protocol_sink_vtbl = {
987 ProtocolSink_QueryInterface,
989 ProtocolSink_Release,
991 ProtocolSink_ReportProgress,
992 ProtocolSink_ReportData,
993 ProtocolSink_ReportResult
996 static IInternetProtocolSink protocol_sink = { &protocol_sink_vtbl };
998 static HRESULT WINAPI MimeProtocolSink_QueryInterface(IInternetProtocolSink *iface, REFIID riid, void **ppv)
1000 ok(0, "unexpected call\n");
1004 static ULONG WINAPI MimeProtocolSink_AddRef(IInternetProtocolSink *iface)
1009 static ULONG WINAPI MimeProtocolSink_Release(IInternetProtocolSink *iface)
1014 static HRESULT WINAPI MimeProtocolSink_Switch(IInternetProtocolSink *iface, PROTOCOLDATA *pProtocolData)
1018 CHECK_EXPECT(MimeFilter_Switch);
1021 hres = IInternetProtocolSink_Switch(filtered_sink, pProtocolData);
1022 ok(hres == S_OK, "Switch failed: %08x\n", hres);
1023 CHECK_CALLED(Switch);
1028 static HRESULT WINAPI MimeProtocolSink_ReportProgress(IInternetProtocolSink *iface, ULONG ulStatusCode,
1029 LPCWSTR szStatusText)
1031 CHECK_EXPECT(MimeFilter_ReportProgress);
1035 static HRESULT WINAPI MimeProtocolSink_ReportData(IInternetProtocolSink *iface, DWORD grfBSCF,
1036 ULONG ulProgress, ULONG ulProgressMax)
1042 CHECK_EXPECT(MimeFilter_ReportData);
1046 hres = IInternetProtocol_Read(filtered_protocol, buf, sizeof(buf), &read);
1047 if(tested_protocol == HTTP_TEST)
1048 ok(hres == S_OK || hres == E_PENDING || hres == S_FALSE, "Read failed: %08x\n", hres);
1050 ok(hres == S_OK, "Read failed: %08x\n", hres);
1053 SET_EXPECT(ReportProgress_MIMETYPEAVAILABLE);
1054 hres = IInternetProtocolSink_ReportProgress(filtered_sink, BINDSTATUS_VERIFIEDMIMETYPEAVAILABLE, text_htmlW);
1055 ok(hres == S_OK, "ReportProgress failed: %08x\n", hres);
1056 CHECK_CALLED(ReportProgress_MIMETYPEAVAILABLE);
1058 /* FIXME: test BINDSTATUS_CACHEFILENAMEAVAILABLE */
1061 if(!read_report_data)
1062 SET_EXPECT(ReportData);
1063 hres = IInternetProtocolSink_ReportData(filtered_sink, grfBSCF, ulProgress, ulProgressMax);
1064 ok(hres == S_OK, "ReportData failed: %08x\n", hres);
1065 if(!read_report_data)
1066 CHECK_CALLED(ReportData);
1074 static HRESULT WINAPI MimeProtocolSink_ReportResult(IInternetProtocolSink *iface, HRESULT hrResult,
1075 DWORD dwError, LPCWSTR szResult)
1079 CHECK_EXPECT(MimeFilter_ReportResult);
1081 ok(hrResult == S_OK, "hrResult = %08x\n", hrResult);
1082 ok(dwError == ERROR_SUCCESS, "dwError = %u\n", dwError);
1083 ok(!szResult, "szResult = %s\n", wine_dbgstr_w(szResult));
1085 SET_EXPECT(ReportResult);
1086 hres = IInternetProtocolSink_ReportResult(filtered_sink, hrResult, dwError, szResult);
1087 ok(SUCCEEDED(hres), "ReportResult failed: %08x\n", hres);
1088 CHECK_CALLED(ReportResult);
1093 static IInternetProtocolSinkVtbl mime_protocol_sink_vtbl = {
1094 MimeProtocolSink_QueryInterface,
1095 MimeProtocolSink_AddRef,
1096 MimeProtocolSink_Release,
1097 MimeProtocolSink_Switch,
1098 MimeProtocolSink_ReportProgress,
1099 MimeProtocolSink_ReportData,
1100 MimeProtocolSink_ReportResult
1103 static IInternetProtocolSink mime_protocol_sink = { &mime_protocol_sink_vtbl };
1105 static HRESULT QueryInterface(REFIID riid, void **ppv)
1107 static const IID IID_undocumented = {0x58DFC7D0,0x5381,0x43E5,{0x9D,0x72,0x4C,0xDD,0xE4,0xCB,0x0F,0x1A}};
1111 if(IsEqualGUID(&IID_IUnknown, riid) || IsEqualGUID(&IID_IInternetProtocolSink, riid))
1112 *ppv = &protocol_sink;
1113 if(IsEqualGUID(&IID_IServiceProvider, riid))
1114 *ppv = &service_provider;
1115 if(IsEqualGUID(&IID_IUriContainer, riid))
1116 return E_NOINTERFACE; /* TODO */
1118 /* NOTE: IE8 queries for undocumented {58DFC7D0-5381-43E5-9D72-4CDDE4CB0F1A} interface. */
1119 if(IsEqualGUID(&IID_undocumented, riid))
1120 return E_NOINTERFACE;
1125 ok(0, "unexpected call %s\n", debugstr_guid(riid));
1126 return E_NOINTERFACE;
1129 static HRESULT WINAPI BindInfo_QueryInterface(IInternetBindInfo *iface, REFIID riid, void **ppv)
1131 if(IsEqualGUID(&IID_IUnknown, riid) || IsEqualGUID(&IID_IInternetBindInfo, riid)) {
1135 return E_NOINTERFACE;
1138 static ULONG WINAPI BindInfo_AddRef(IInternetBindInfo *iface)
1143 static ULONG WINAPI BindInfo_Release(IInternetBindInfo *iface)
1148 static HRESULT WINAPI BindInfo_GetBindInfo(IInternetBindInfo *iface, DWORD *grfBINDF, BINDINFO *pbindinfo)
1152 CHECK_EXPECT(GetBindInfo);
1154 ok(grfBINDF != NULL, "grfBINDF == NULL\n");
1155 ok(pbindinfo != NULL, "pbindinfo == NULL\n");
1156 ok(pbindinfo->cbSize == sizeof(BINDINFO), "wrong size of pbindinfo: %d\n", pbindinfo->cbSize);
1160 *grfBINDF |= BINDF_FROMURLMON;
1161 cbSize = pbindinfo->cbSize;
1162 memset(pbindinfo, 0, cbSize);
1163 pbindinfo->cbSize = cbSize;
1167 pbindinfo->cbstgmedData = sizeof(post_data)-1;
1168 pbindinfo->dwBindVerb = BINDVERB_POST;
1169 pbindinfo->stgmedData.tymed = http_post_test;
1171 if(http_post_test == TYMED_HGLOBAL) {
1174 /* Must be GMEM_FIXED, GMEM_MOVABLE does not work properly */
1175 data = GlobalAlloc(GPTR, sizeof(post_data));
1176 memcpy(data, post_data, sizeof(post_data));
1177 U(pbindinfo->stgmedData).hGlobal = data;
1179 IStream *post_stream;
1184 /* Must be GMEM_FIXED, GMEM_MOVABLE does not work properly */
1185 data = GlobalAlloc(GPTR, sizeof(post_data));
1186 memcpy(data, post_data, sizeof(post_data));
1187 U(pbindinfo->stgmedData).hGlobal = data;
1189 hres = CreateStreamOnHGlobal(data, FALSE, &post_stream);
1190 ok(hres == S_OK, "CreateStreamOnHGlobal failed: %08x\n", hres);
1192 U(pbindinfo->stgmedData).pstm =post_stream;/* &Stream; */
1194 U(pbindinfo->stgmedData).pstm = &Stream;
1201 static HRESULT WINAPI BindInfo_GetBindString(IInternetBindInfo *iface, ULONG ulStringType,
1202 LPOLESTR *ppwzStr, ULONG cEl, ULONG *pcElFetched)
1204 ok(ppwzStr != NULL, "ppwzStr == NULL\n");
1205 ok(pcElFetched != NULL, "pcElFetched == NULL\n");
1207 switch(ulStringType) {
1208 case BINDSTRING_ACCEPT_MIMES:
1209 CHECK_EXPECT(GetBindString_ACCEPT_MIMES);
1210 ok(cEl == 256, "cEl=%d, expected 256\n", cEl);
1212 ok(*pcElFetched == 256, "*pcElFetched=%d, expected 256\n", *pcElFetched);
1216 *ppwzStr = CoTaskMemAlloc(sizeof(acc_mimeW));
1217 memcpy(*ppwzStr, acc_mimeW, sizeof(acc_mimeW));
1220 case BINDSTRING_USER_AGENT:
1221 CHECK_EXPECT(GetBindString_USER_AGENT);
1222 ok(cEl == 1, "cEl=%d, expected 1\n", cEl);
1224 ok(*pcElFetched == 0, "*pcElFetch=%d, expectd 0\n", *pcElFetched);
1228 *ppwzStr = CoTaskMemAlloc(sizeof(user_agentW));
1229 memcpy(*ppwzStr, user_agentW, sizeof(user_agentW));
1232 case BINDSTRING_POST_COOKIE:
1233 CHECK_EXPECT(GetBindString_POST_COOKIE);
1234 ok(cEl == 1, "cEl=%d, expected 1\n", cEl);
1236 ok(*pcElFetched == 0, "*pcElFetch=%d, expectd 0\n", *pcElFetched);
1238 case BINDSTRING_URL: {
1241 CHECK_EXPECT(GetBindString_URL);
1242 ok(cEl == 1, "cEl=%d, expected 1\n", cEl);
1243 ok(*pcElFetched == 0, "*pcElFetch=%d, expectd 0\n", *pcElFetched);
1246 size = (lstrlenW(binding_urls[tested_protocol])+1)*sizeof(WCHAR);
1247 *ppwzStr = CoTaskMemAlloc(size);
1248 memcpy(*ppwzStr, binding_urls[tested_protocol], size);
1252 ok(0, "unexpected call\n");
1258 static IInternetBindInfoVtbl bind_info_vtbl = {
1259 BindInfo_QueryInterface,
1262 BindInfo_GetBindInfo,
1263 BindInfo_GetBindString
1266 static IInternetBindInfo bind_info = { &bind_info_vtbl };
1268 static HRESULT WINAPI InternetPriority_QueryInterface(IInternetPriority *iface,
1269 REFIID riid, void **ppv)
1271 ok(0, "unexpected call\n");
1272 return E_NOINTERFACE;
1275 static ULONG WINAPI InternetPriority_AddRef(IInternetPriority *iface)
1280 static ULONG WINAPI InternetPriority_Release(IInternetPriority *iface)
1285 static HRESULT WINAPI InternetPriority_SetPriority(IInternetPriority *iface, LONG nPriority)
1287 CHECK_EXPECT(SetPriority);
1288 ok(nPriority == ex_priority, "nPriority=%d\n", nPriority);
1292 static HRESULT WINAPI InternetPriority_GetPriority(IInternetPriority *iface, LONG *pnPriority)
1294 ok(0, "unexpected call\n");
1299 static const IInternetPriorityVtbl InternetPriorityVtbl = {
1300 InternetPriority_QueryInterface,
1301 InternetPriority_AddRef,
1302 InternetPriority_Release,
1303 InternetPriority_SetPriority,
1304 InternetPriority_GetPriority
1307 static IInternetPriority InternetPriority = { &InternetPriorityVtbl };
1309 static ULONG WINAPI Protocol_AddRef(IInternetProtocolEx *iface)
1314 static ULONG WINAPI Protocol_Release(IInternetProtocolEx *iface)
1319 static HRESULT WINAPI Protocol_Abort(IInternetProtocolEx *iface, HRESULT hrReason,
1324 CHECK_EXPECT(Abort);
1326 SET_EXPECT(ReportResult);
1327 hres = IInternetProtocolSink_ReportResult(binding_sink, S_OK, ERROR_SUCCESS, NULL);
1328 ok(hres == S_OK, "ReportResult failed: %08x\n", hres);
1329 CHECK_CALLED(ReportResult);
1334 static HRESULT WINAPI Protocol_Suspend(IInternetProtocolEx *iface)
1336 ok(0, "unexpected call\n");
1340 static HRESULT WINAPI Protocol_Resume(IInternetProtocolEx *iface)
1342 ok(0, "unexpected call\n");
1346 static HRESULT WINAPI Protocol_Seek(IInternetProtocolEx *iface,
1347 LARGE_INTEGER dlibMove, DWORD dwOrigin, ULARGE_INTEGER *plibNewPosition)
1349 ok(0, "unexpected call\n");
1353 static HRESULT WINAPI ProtocolEmul_QueryInterface(IInternetProtocolEx *iface, REFIID riid, void **ppv)
1355 if(IsEqualGUID(&IID_IUnknown, riid) || IsEqualGUID(&IID_IInternetProtocol, riid)) {
1360 if(IsEqualGUID(&IID_IInternetProtocolEx, riid)) {
1366 return E_NOINTERFACE;
1369 if(IsEqualGUID(&IID_IInternetPriority, riid)) {
1370 *ppv = &InternetPriority;
1374 if(IsEqualGUID(&IID_IWinInetInfo, riid)) {
1375 CHECK_EXPECT(QueryInterface_IWinInetInfo);
1377 return E_NOINTERFACE;
1380 if(IsEqualGUID(&IID_IWinInetHttpInfo, riid)) {
1381 CHECK_EXPECT(QueryInterface_IWinInetHttpInfo);
1383 return E_NOINTERFACE;
1386 ok(0, "unexpected riid %s\n", debugstr_guid(riid));
1388 return E_NOINTERFACE;
1391 static DWORD WINAPI thread_proc(PVOID arg)
1395 memset(&protocoldata, -1, sizeof(protocoldata));
1399 SET_EXPECT(ReportProgress_FINDINGRESOURCE);
1400 hres = IInternetProtocolSink_ReportProgress(binding_sink,
1401 BINDSTATUS_FINDINGRESOURCE, hostW);
1402 CHECK_CALLED(ReportProgress_FINDINGRESOURCE);
1403 ok(hres == S_OK, "ReportProgress failed: %08x\n", hres);
1405 SET_EXPECT(ReportProgress_CONNECTING);
1406 hres = IInternetProtocolSink_ReportProgress(binding_sink,
1407 BINDSTATUS_CONNECTING, winehq_ipW);
1408 CHECK_CALLED(ReportProgress_CONNECTING);
1409 ok(hres == S_OK, "ReportProgress failed: %08x\n", hres);
1411 SET_EXPECT(ReportProgress_SENDINGREQUEST);
1412 hres = IInternetProtocolSink_ReportProgress(binding_sink,
1413 BINDSTATUS_SENDINGREQUEST, NULL);
1414 CHECK_CALLED(ReportProgress_SENDINGREQUEST);
1415 ok(hres == S_OK, "ReportProgress failed: %08x\n", hres);
1419 hres = IInternetProtocolSink_Switch(binding_sink, &protocoldata);
1420 CHECK_CALLED(Switch);
1421 ok(hres == S_OK, "Switch failed: %08x\n", hres);
1426 SET_EXPECT(MimeFilter_Switch);
1429 hres = IInternetProtocolSink_Switch(binding_sink, &protocoldata);
1430 ok(hres == S_OK, "Switch failed: %08x\n", hres);
1432 CHECK_CALLED(MimeFilter_Switch);
1434 CHECK_CALLED(Switch);
1437 SetEvent(event_complete);
1443 SET_EXPECT(MimeFilter_Switch);
1446 hres = IInternetProtocolSink_Switch(binding_sink, &protocoldata);
1447 ok(hres == S_OK, "Switch failed: %08x\n", hres);
1449 CHECK_CALLED(MimeFilter_Switch);
1451 CHECK_CALLED(Switch);
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);
1466 SetEvent(event_complete);
1471 static void protocol_start(IInternetProtocolSink *pOIProtSink, IInternetBindInfo *pOIBindInfo, DWORD pi)
1473 BINDINFO bindinfo, exp_bindinfo;
1477 ok(pOIProtSink != NULL, "pOIProtSink == NULL\n");
1478 ok(pOIBindInfo != NULL, "pOIBindInfo == NULL\n");
1479 ok(pOIProtSink != &protocol_sink, "unexpected pOIProtSink\n");
1480 ok(pOIBindInfo != &bind_info, "unexpected pOIBindInfo\n");
1481 ok(!pi, "pi = %x\n", pi);
1484 ok(pOIProtSink == binding_sink, "pOIProtSink != binding_sink\n");
1486 memset(&bindinfo, 0, sizeof(bindinfo));
1487 bindinfo.cbSize = sizeof(bindinfo);
1488 memcpy(&exp_bindinfo, &bindinfo, sizeof(bindinfo));
1489 SET_EXPECT(GetBindInfo);
1490 hres = IInternetBindInfo_GetBindInfo(pOIBindInfo, &cbindf, &bindinfo);
1491 ok(hres == S_OK, "GetBindInfo failed: %08x\n", hres);
1492 CHECK_CALLED(GetBindInfo);
1493 ok(cbindf == (bindf|BINDF_FROMURLMON), "bindf = %x, expected %x\n",
1494 cbindf, (bindf|BINDF_FROMURLMON));
1495 ok(!memcmp(&exp_bindinfo, &bindinfo, sizeof(bindinfo)), "unexpected bindinfo\n");
1496 pReleaseBindInfo(&bindinfo);
1498 SET_EXPECT(ReportProgress_SENDINGREQUEST);
1499 hres = IInternetProtocolSink_ReportProgress(pOIProtSink, BINDSTATUS_SENDINGREQUEST, emptyW);
1500 ok(hres == S_OK, "ReportProgress(BINDSTATUS_SENDINGREQUEST) failed: %08x\n", hres);
1501 CHECK_CALLED(ReportProgress_SENDINGREQUEST);
1503 if(tested_protocol == HTTP_TEST || tested_protocol == HTTPS_TEST) {
1504 IServiceProvider *service_provider;
1505 IHttpNegotiate *http_negotiate;
1506 IHttpNegotiate2 *http_negotiate2;
1507 LPWSTR ua = (LPWSTR)0xdeadbeef, accept_mimes[256];
1508 LPWSTR additional_headers = NULL;
1510 DWORD fetched = 0, size = 100;
1513 SET_EXPECT(GetBindString_USER_AGENT);
1514 hres = IInternetBindInfo_GetBindString(pOIBindInfo, BINDSTRING_USER_AGENT,
1516 CHECK_CALLED(GetBindString_USER_AGENT);
1517 ok(hres == S_OK, "GetBindString(BINDSTRING_USER_AGETNT) failed: %08x\n", hres);
1518 ok(fetched == 1, "fetched = %d, expected 254\n", fetched);
1519 ok(ua != NULL, "ua = %p\n", ua);
1520 ok(!lstrcmpW(ua, user_agentW), "unexpected user agent %s\n", wine_dbgstr_w(ua));
1524 SET_EXPECT(GetBindString_ACCEPT_MIMES);
1525 hres = IInternetBindInfo_GetBindString(pOIBindInfo, BINDSTRING_ACCEPT_MIMES,
1526 accept_mimes, 256, &fetched);
1527 CHECK_CALLED(GetBindString_ACCEPT_MIMES);
1530 "GetBindString(BINDSTRING_ACCEPT_MIMES) failed: %08x\n", hres);
1531 ok(fetched == 1, "fetched = %d, expected 1\n", fetched);
1532 ok(!lstrcmpW(acc_mimeW, accept_mimes[0]), "unexpected mimes %s\n", wine_dbgstr_w(accept_mimes[0]));
1533 CoTaskMemFree(accept_mimes[0]);
1535 hres = IInternetBindInfo_QueryInterface(pOIBindInfo, &IID_IServiceProvider,
1536 (void**)&service_provider);
1537 ok(hres == S_OK, "QueryInterface failed: %08x\n", hres);
1539 SET_EXPECT(QueryService_HttpNegotiate);
1540 hres = IServiceProvider_QueryService(service_provider, &IID_IHttpNegotiate,
1541 &IID_IHttpNegotiate, (void**)&http_negotiate);
1542 CHECK_CALLED(QueryService_HttpNegotiate);
1543 ok(hres == S_OK, "QueryService failed: %08x\n", hres);
1545 SET_EXPECT(BeginningTransaction);
1546 hres = IHttpNegotiate_BeginningTransaction(http_negotiate, binding_urls[tested_protocol],
1547 NULL, 0, &additional_headers);
1548 CHECK_CALLED(BeginningTransaction);
1549 IHttpNegotiate_Release(http_negotiate);
1550 ok(hres == S_OK, "BeginningTransction failed: %08x\n", hres);
1551 ok(additional_headers == NULL, "additional_headers=%p\n", additional_headers);
1553 SET_EXPECT(QueryService_HttpNegotiate);
1554 hres = IServiceProvider_QueryService(service_provider, &IID_IHttpNegotiate2,
1555 &IID_IHttpNegotiate2, (void**)&http_negotiate2);
1556 CHECK_CALLED(QueryService_HttpNegotiate);
1557 ok(hres == S_OK, "QueryService failed: %08x\n", hres);
1560 SET_EXPECT(GetRootSecurityId);
1561 hres = IHttpNegotiate2_GetRootSecurityId(http_negotiate2, sec_id, &size, 0);
1562 CHECK_CALLED(GetRootSecurityId);
1563 IHttpNegotiate2_Release(http_negotiate2);
1564 ok(hres == E_FAIL, "GetRootSecurityId failed: %08x, expected E_FAIL\n", hres);
1565 ok(size == 13, "size=%d\n", size);
1567 IServiceProvider_Release(service_provider);
1569 CreateThread(NULL, 0, thread_proc, NULL, 0, &tid);
1573 SET_EXPECT(ReportProgress_CACHEFILENAMEAVAILABLE);
1574 hres = IInternetProtocolSink_ReportProgress(pOIProtSink,
1575 BINDSTATUS_CACHEFILENAMEAVAILABLE, expect_wsz = emptyW);
1576 ok(hres == S_OK, "ReportProgress(BINDSTATUS_CACHEFILENAMEAVAILABLE) failed: %08x\n", hres);
1577 CHECK_CALLED(ReportProgress_CACHEFILENAMEAVAILABLE);
1579 if(mimefilter_test) {
1580 SET_EXPECT(MimeFilter_CreateInstance);
1581 SET_EXPECT(MimeFilter_Start);
1582 SET_EXPECT(ReportProgress_LOADINGMIMEHANDLER);
1584 SET_EXPECT(ReportProgress_MIMETYPEAVAILABLE);
1585 hres = IInternetProtocolSink_ReportProgress(pOIProtSink, BINDSTATUS_VERIFIEDMIMETYPEAVAILABLE,
1586 mimefilter_test ? gzipW : (expect_wsz = text_htmlW));
1588 "ReportProgress(BINDSTATUS_VERIFIEDMIMETYPEAVAILABLE) failed: %08x\n", hres);
1589 if(mimefilter_test) {
1590 CHECK_CALLED(MimeFilter_CreateInstance);
1591 CHECK_CALLED(MimeFilter_Start);
1592 CHECK_CALLED(ReportProgress_LOADINGMIMEHANDLER);
1593 todo_wine CHECK_CALLED(ReportProgress_MIMETYPEAVAILABLE);
1595 CHECK_CALLED(ReportProgress_MIMETYPEAVAILABLE);
1599 SET_EXPECT(MimeFilter_ReportData);
1601 SET_EXPECT(ReportData);
1602 hres = IInternetProtocolSink_ReportData(pOIProtSink,
1603 BSCF_FIRSTDATANOTIFICATION | (tested_protocol == ITS_TEST ? BSCF_DATAFULLYAVAILABLE : BSCF_LASTDATANOTIFICATION),
1605 ok(hres == S_OK, "ReportData failed: %08x\n", hres);
1607 CHECK_CALLED(MimeFilter_ReportData);
1609 CHECK_CALLED(ReportData);
1611 if(tested_protocol == ITS_TEST) {
1612 SET_EXPECT(ReportData);
1613 hres = IInternetProtocolSink_ReportProgress(pOIProtSink, BINDSTATUS_BEGINDOWNLOADDATA, NULL);
1614 ok(hres == S_OK, "ReportProgress(BINDSTATUS_BEGINDOWNLOADDATA) failed: %08x\n", hres);
1615 CHECK_CALLED(ReportData);
1618 if(tested_protocol == BIND_TEST) {
1619 hres = IInternetProtocol_Terminate(binding_protocol, 0);
1620 ok(hres == E_FAIL, "Termiante failed: %08x\n", hres);
1624 SET_EXPECT(MimeFilter_ReportResult);
1626 SET_EXPECT(ReportResult);
1627 hres = IInternetProtocolSink_ReportResult(pOIProtSink, S_OK, 0, NULL);
1628 ok(hres == S_OK, "ReportResult failed: %08x\n", hres);
1630 CHECK_CALLED(MimeFilter_ReportResult);
1632 CHECK_CALLED(ReportResult);
1635 static HRESULT WINAPI ProtocolEmul_Start(IInternetProtocolEx *iface, LPCWSTR szUrl,
1636 IInternetProtocolSink *pOIProtSink, IInternetBindInfo *pOIBindInfo,
1637 DWORD grfPI, HANDLE_PTR dwReserved)
1639 CHECK_EXPECT(Start);
1641 ok(!dwReserved, "dwReserved = %lx\n", dwReserved);
1642 protocol_start(pOIProtSink, pOIBindInfo, grfPI);
1646 static HRESULT WINAPI ProtocolEmul_Continue(IInternetProtocolEx *iface,
1647 PROTOCOLDATA *pProtocolData)
1652 CHECK_EXPECT(Continue);
1654 ok(pProtocolData != NULL, "pProtocolData == NULL\n");
1655 if(!pProtocolData || tested_protocol == BIND_TEST)
1658 ok(pProtocolData != &protocoldata, "pProtocolData == &protocoldata\n");
1659 ok(pProtocolData->grfFlags == protocoldata.grfFlags, "grfFlags wrong %x/%x\n",
1660 pProtocolData->grfFlags, protocoldata.grfFlags );
1661 ok(pProtocolData->dwState == protocoldata.dwState, "dwState wrong %x/%x\n",
1662 pProtocolData->dwState, protocoldata.dwState );
1663 ok(pProtocolData->pData == protocoldata.pData, "pData wrong %p/%p\n",
1664 pProtocolData->pData, protocoldata.pData );
1665 ok(pProtocolData->cbData == protocoldata.cbData, "cbData wrong %x/%x\n",
1666 pProtocolData->cbData, protocoldata.cbData );
1669 switch(prot_state) {
1671 IServiceProvider *service_provider;
1672 IHttpNegotiate *http_negotiate;
1673 static WCHAR header[] = {'?',0};
1675 hres = IInternetProtocolSink_QueryInterface(binding_sink, &IID_IServiceProvider,
1676 (void**)&service_provider);
1677 ok(hres == S_OK, "Could not get IServiceProvicder\n");
1679 SET_EXPECT(QueryService_HttpNegotiate);
1680 hres = IServiceProvider_QueryService(service_provider, &IID_IHttpNegotiate,
1681 &IID_IHttpNegotiate, (void**)&http_negotiate);
1682 IServiceProvider_Release(service_provider);
1683 CHECK_CALLED(QueryService_HttpNegotiate);
1684 ok(hres == S_OK, "Could not get IHttpNegotiate\n");
1686 SET_EXPECT(OnResponse);
1687 hres = IHttpNegotiate_OnResponse(http_negotiate, 200, header, NULL, NULL);
1688 IHttpNegotiate_Release(http_negotiate);
1689 CHECK_CALLED(OnResponse);
1690 IHttpNegotiate_Release(http_negotiate);
1691 ok(hres == S_OK, "OnResponse failed: %08x\n", hres);
1693 if(mimefilter_test) {
1694 SET_EXPECT(MimeFilter_CreateInstance);
1695 SET_EXPECT(MimeFilter_Start);
1696 SET_EXPECT(ReportProgress_LOADINGMIMEHANDLER);
1697 }else if(!(pi & PI_MIMEVERIFICATION)) {
1698 SET_EXPECT(ReportProgress_MIMETYPEAVAILABLE);
1700 hres = IInternetProtocolSink_ReportProgress(binding_sink,
1701 BINDSTATUS_MIMETYPEAVAILABLE, mimefilter_test ? gzipW : text_htmlW);
1702 if(mimefilter_test) {
1703 CHECK_CALLED(MimeFilter_CreateInstance);
1704 CHECK_CALLED(MimeFilter_Start);
1705 CHECK_CALLED(ReportProgress_LOADINGMIMEHANDLER);
1706 }else if(!(pi & PI_MIMEVERIFICATION)) {
1707 CHECK_CALLED(ReportProgress_MIMETYPEAVAILABLE);
1710 "ReportProgress(BINDSTATUS_MIMETYPEAVAILABLE) failed: %08x\n", hres);
1712 bscf |= BSCF_FIRSTDATANOTIFICATION;
1717 bscf = BSCF_INTERMEDIATEDATANOTIFICATION;
1722 if(mimefilter_test) {
1723 SET_EXPECT(MimeFilter_ReportData);
1724 }else if(pi & PI_MIMEVERIFICATION) {
1726 SET_EXPECT(Read); /* checked in ReportData for short_read */
1728 if(!mimefilter_test)
1729 SET_EXPECT(Read); /* checked in BINDSTATUS_MIMETYPEAVAILABLE or ReportData */
1730 SET_EXPECT(ReportProgress_MIMETYPEAVAILABLE);
1733 SET_EXPECT(ReportData);
1735 SET_EXPECT(ReportData);
1738 hres = IInternetProtocolSink_ReportData(binding_sink, bscf, pr, 400);
1739 ok(hres == S_OK, "ReportData failed: %08x\n", hres);
1741 if(mimefilter_test) {
1742 SET_EXPECT(MimeFilter_ReportData);
1743 }else if(pi & PI_MIMEVERIFICATION) {
1744 if(!short_read && pr < 200)
1747 CHECK_CALLED(ReportProgress_MIMETYPEAVAILABLE);
1750 CHECK_CALLED(ReportData);
1759 static HRESULT WINAPI ProtocolEmul_Terminate(IInternetProtocolEx *iface, DWORD dwOptions)
1761 CHECK_EXPECT(Terminate);
1762 ok(!dwOptions, "dwOptions=%d\n", dwOptions);
1766 static HRESULT WINAPI ProtocolEmul_Read(IInternetProtocolEx *iface, void *pv,
1767 ULONG cb, ULONG *pcbRead)
1769 if(read_report_data)
1770 CHECK_EXPECT2(Read2);
1772 if(mimefilter_test || short_read) {
1773 if(!read_report_data)
1774 CHECK_EXPECT2(Read);
1775 }else if((pi & PI_MIMEVERIFICATION)) {
1776 if(!read_report_data)
1777 CHECK_EXPECT2(Read);
1779 if(prot_read < 300) {
1780 ok(pv != expect_pv, "pv == expect_pv\n");
1782 ok(cb == 2048-prot_read, "cb=%d\n", cb);
1784 ok(cb == 700, "cb=%d\n", cb);
1786 ok(expect_pv <= pv && (BYTE*)pv < (BYTE*)expect_pv + cb, "pv != expect_pv\n");
1789 if(!read_report_data)
1792 ok(pv == expect_pv, "pv != expect_pv\n");
1793 ok(cb == 1000, "cb=%d\n", cb);
1794 ok(!*pcbRead, "*pcbRead = %d\n", *pcbRead);
1796 ok(pcbRead != NULL, "pcbRead == NULL\n");
1798 if(prot_state == 3 || (short_read && prot_state != 4)) {
1803 SET_EXPECT(Read2); /* checked in BINDSTATUS_MIMETYPEAVAILABLE */
1804 SET_EXPECT(ReportProgress_MIMETYPEAVAILABLE);
1807 SET_EXPECT(MimeFilter_ReportData);
1808 else if(direct_read)
1809 SET_EXPECT(ReportData2);
1811 hres = IInternetProtocolSink_ReportData(binding_sink,
1812 BSCF_LASTDATANOTIFICATION|BSCF_INTERMEDIATEDATANOTIFICATION, 0, 0);
1814 ok(hres == S_OK, "ReportData failed: %08x\n", hres);
1816 CHECK_CALLED(ReportProgress_MIMETYPEAVAILABLE);
1818 CHECK_CALLED(MimeFilter_ReportData);
1819 else if(direct_read)
1820 CHECK_CALLED(ReportData2);
1823 SET_EXPECT(MimeFilter_ReportResult);
1825 SET_EXPECT(ReportResult);
1826 hres = IInternetProtocolSink_ReportResult(binding_sink, S_OK, ERROR_SUCCESS, NULL);
1827 ok(hres == S_OK, "ReportResult failed: %08x\n", hres);
1829 CHECK_CALLED(MimeFilter_ReportResult);
1831 CHECK_CALLED(ReportResult);
1833 memset(pv, 'x', 100);
1834 prot_read += *pcbRead = 100;
1836 }if(prot_state == 4) {
1841 if((async_read_pending = !async_read_pending)) {
1843 return tested_protocol == HTTP_TEST || tested_protocol == HTTPS_TEST ? E_PENDING : S_FALSE;
1846 memset(pv, 'x', 100);
1847 prot_read += *pcbRead = 100;
1851 static HRESULT WINAPI ProtocolEmul_LockRequest(IInternetProtocolEx *iface, DWORD dwOptions)
1853 CHECK_EXPECT(LockRequest);
1854 ok(dwOptions == 0, "dwOptions=%x\n", dwOptions);
1858 static HRESULT WINAPI ProtocolEmul_UnlockRequest(IInternetProtocolEx *iface)
1860 CHECK_EXPECT(UnlockRequest);
1864 static HRESULT WINAPI ProtocolEmul_StartEx(IInternetProtocolEx *iface, IUri *pUri,
1865 IInternetProtocolSink *pOIProtSink, IInternetBindInfo *pOIBindInfo,
1866 DWORD grfPI, HANDLE *dwReserved)
1868 CHECK_EXPECT(StartEx);
1869 ok(!dwReserved, "dwReserved = %p\n", dwReserved);
1870 protocol_start(pOIProtSink, pOIBindInfo, grfPI);
1874 static const IInternetProtocolExVtbl ProtocolVtbl = {
1875 ProtocolEmul_QueryInterface,
1879 ProtocolEmul_Continue,
1881 ProtocolEmul_Terminate,
1886 ProtocolEmul_LockRequest,
1887 ProtocolEmul_UnlockRequest,
1888 ProtocolEmul_StartEx
1891 static IInternetProtocolEx Protocol = { &ProtocolVtbl };
1893 static HRESULT WINAPI MimeProtocol_QueryInterface(IInternetProtocolEx *iface, REFIID riid, void **ppv)
1895 if(IsEqualGUID(&IID_IUnknown, riid) || IsEqualGUID(&IID_IInternetProtocol, riid)) {
1900 if(IsEqualGUID(&IID_IInternetProtocolSink, riid)) {
1901 *ppv = &mime_protocol_sink;
1905 ok(0, "unexpected riid %s\n", debugstr_guid(riid));
1907 return E_NOINTERFACE;
1910 static HRESULT WINAPI MimeProtocol_Start(IInternetProtocolEx *iface, LPCWSTR szUrl,
1911 IInternetProtocolSink *pOIProtSink, IInternetBindInfo *pOIBindInfo,
1912 DWORD grfPI, HANDLE_PTR dwReserved)
1914 PROTOCOLFILTERDATA *data;
1915 LPOLESTR url_str = NULL;
1921 CHECK_EXPECT(MimeFilter_Start);
1923 ok(!lstrcmpW(szUrl, gzipW), "wrong url %s\n", wine_dbgstr_w(szUrl));
1924 ok(grfPI == (PI_FILTER_MODE|PI_FORCE_ASYNC), "grfPI=%x, expected PI_FILTER_MODE|PI_FORCE_ASYNC\n", grfPI);
1925 ok(dwReserved, "dwReserved == 0\n");
1926 ok(pOIProtSink != NULL, "pOIProtSink == NULL\n");
1927 ok(pOIBindInfo != NULL, "pOIBindInfo == NULL\n");
1930 ok(pOIProtSink != binding_sink, "pOIProtSink == protocol_sink\n");
1931 ok(pOIBindInfo == prot_bind_info, "pOIBindInfo != bind_info\n");
1933 ok(pOIProtSink == &protocol_sink, "pOIProtSink != protocol_sink\n");
1934 ok(pOIBindInfo == &bind_info, "pOIBindInfo != bind_info\n");
1937 data = (void*)dwReserved;
1938 ok(data->cbSize == sizeof(*data), "data->cbSize = %d\n", data->cbSize);
1939 ok(!data->pProtocolSink, "data->pProtocolSink != NULL\n");
1940 ok(data->pProtocol != NULL, "data->pProtocol == NULL\n");
1941 ok(!data->pUnk, "data->pUnk != NULL\n");
1942 ok(!data->dwFilterFlags, "data->dwProtocolFlags = %x\n", data->dwFilterFlags);
1944 IInternetProtocolSink *prot_sink;
1946 IInternetProtocol_QueryInterface(data->pProtocol, &IID_IInternetProtocolSink, (void**)&prot_sink);
1947 ok(prot_sink == pOIProtSink, "QI(data->pProtocol, IID_IInternetProtocolSink) != pOIProtSink\n");
1948 IInternetProtocolSink_Release(prot_sink);
1950 ok(data->pProtocol != binding_protocol, "data->pProtocol == binding_protocol\n");
1952 filtered_protocol = data->pProtocol;
1953 IInternetProtocol_AddRef(filtered_protocol);
1955 IInternetProtocol *prot;
1957 IInternetProtocol_QueryInterface(data->pProtocol, &IID_IInternetProtocol, (void**)&prot);
1958 ok(prot == async_protocol, "QI(data->pProtocol, IID_IInternetProtocol) != async_protocol\n");
1959 IInternetProtocol_Release(prot);
1961 ok(data->pProtocol != async_protocol, "data->pProtocol == async_protocol\n");
1964 filtered_sink = pOIProtSink;
1966 SET_EXPECT(ReportProgress_DECODING);
1967 hres = IInternetProtocolSink_ReportProgress(pOIProtSink, BINDSTATUS_DECODING, gzipW);
1968 ok(hres == S_OK, "ReportProgress(BINDSTATUS_DECODING) failed: %08x\n", hres);
1969 CHECK_CALLED(ReportProgress_DECODING);
1971 SET_EXPECT(GetBindInfo);
1972 memset(&bindinfo, 0, sizeof(bindinfo));
1973 bindinfo.cbSize = sizeof(bindinfo);
1974 hres = IInternetBindInfo_GetBindInfo(pOIBindInfo, &cbindf, &bindinfo);
1975 ok(hres == S_OK, "GetBindInfo failed: %08x\n", hres);
1976 ok(cbindf == (bindf|BINDF_FROMURLMON), "cbindf = %x, expected %x\n", cbindf, bindf);
1977 CHECK_CALLED(GetBindInfo);
1979 SET_EXPECT(GetBindString_URL);
1980 hres = IInternetBindInfo_GetBindString(pOIBindInfo, BINDSTRING_URL, &url_str, 1, &fetched);
1981 ok(hres == S_OK, "GetBindString(BINDSTRING_URL) failed: %08x\n", hres);
1982 ok(fetched == 1, "fetched = %d\n", fetched);
1983 ok(!lstrcmpW(url_str, binding_urls[tested_protocol]), "wrong url_str %s\n", wine_dbgstr_w(url_str));
1984 CoTaskMemFree(url_str);
1985 CHECK_CALLED(GetBindString_URL);
1990 static HRESULT WINAPI Protocol_Continue(IInternetProtocolEx *iface,
1991 PROTOCOLDATA *pProtocolData)
1993 CHECK_EXPECT(MimeFilter_Continue);
1997 static HRESULT WINAPI MimeProtocol_Terminate(IInternetProtocolEx *iface, DWORD dwOptions)
2001 CHECK_EXPECT(MimeFilter_Terminate);
2003 ok(!dwOptions, "dwOptions = %x\n", dwOptions);
2005 SET_EXPECT(Terminate);
2006 hres = IInternetProtocol_Terminate(filtered_protocol, dwOptions);
2007 ok(hres == S_OK, "Terminate failed: %08x\n", hres);
2008 CHECK_CALLED(Terminate);
2013 static HRESULT WINAPI MimeProtocol_Read(IInternetProtocolEx *iface, void *pv,
2014 ULONG cb, ULONG *pcbRead)
2020 CHECK_EXPECT(MimeFilter_Read);
2022 ok(pv != NULL, "pv == NULL\n");
2023 ok(cb != 0, "cb == 0\n");
2024 ok(pcbRead != NULL, "pcbRead == NULL\n");
2026 if(read_report_data)
2030 hres = IInternetProtocol_Read(filtered_protocol, buf, sizeof(buf), &read);
2031 ok(hres == S_OK || hres == S_FALSE || hres == E_PENDING, "Read failed: %08x\n", hres);
2032 if(read_report_data)
2033 CHECK_CALLED(Read2);
2038 ok(*pcbRead == 0, "*pcbRead=%d, expected 0\n", *pcbRead);
2042 memset(pv, 'x', read);
2046 static HRESULT WINAPI MimeProtocol_LockRequest(IInternetProtocolEx *iface, DWORD dwOptions)
2050 CHECK_EXPECT(MimeFilter_LockRequest);
2052 ok(!dwOptions, "dwOptions = %x\n", dwOptions);
2054 SET_EXPECT(LockRequest);
2055 hres = IInternetProtocol_LockRequest(filtered_protocol, dwOptions);
2056 ok(hres == S_OK, "LockRequest failed: %08x\n", hres);
2057 CHECK_CALLED(LockRequest);
2062 static HRESULT WINAPI MimeProtocol_UnlockRequest(IInternetProtocolEx *iface)
2066 CHECK_EXPECT(MimeFilter_UnlockRequest);
2068 SET_EXPECT(UnlockRequest);
2069 hres = IInternetProtocol_UnlockRequest(filtered_protocol);
2070 ok(hres == S_OK, "UnlockRequest failed: %08x\n", hres);
2071 CHECK_CALLED(UnlockRequest);
2076 static const IInternetProtocolExVtbl MimeProtocolVtbl = {
2077 MimeProtocol_QueryInterface,
2083 MimeProtocol_Terminate,
2088 MimeProtocol_LockRequest,
2089 MimeProtocol_UnlockRequest
2092 static IInternetProtocolEx MimeProtocol = { &MimeProtocolVtbl };
2094 static HRESULT WINAPI ClassFactory_QueryInterface(IClassFactory *iface, REFIID riid, void **ppv)
2096 ok(0, "unexpected call\n");
2097 return E_NOINTERFACE;
2100 static ULONG WINAPI ClassFactory_AddRef(IClassFactory *iface)
2105 static ULONG WINAPI ClassFactory_Release(IClassFactory *iface)
2110 static HRESULT WINAPI ClassFactory_CreateInstance(IClassFactory *iface, IUnknown *pOuter,
2111 REFIID riid, void **ppv)
2113 CHECK_EXPECT(CreateInstance);
2115 ok(pOuter == (IUnknown*)prot_bind_info, "pOuter != protocol_unk\n");
2116 ok(IsEqualGUID(&IID_IUnknown, riid), "unexpected riid %s\n", debugstr_guid(riid));
2117 ok(ppv != NULL, "ppv == NULL\n");
2123 static HRESULT WINAPI ClassFactory_LockServer(IClassFactory *iface, BOOL dolock)
2125 ok(0, "unexpected call\n");
2129 static const IClassFactoryVtbl ClassFactoryVtbl = {
2130 ClassFactory_QueryInterface,
2131 ClassFactory_AddRef,
2132 ClassFactory_Release,
2133 ClassFactory_CreateInstance,
2134 ClassFactory_LockServer
2137 static IClassFactory ClassFactory = { &ClassFactoryVtbl };
2139 static HRESULT WINAPI MimeFilter_CreateInstance(IClassFactory *iface, IUnknown *outer, REFIID riid, void **ppv)
2141 CHECK_EXPECT(MimeFilter_CreateInstance);
2143 ok(!outer, "outer = %p\n", outer);
2144 ok(IsEqualGUID(&IID_IInternetProtocol, riid), "unexpected riid %s\n", debugstr_guid(riid));
2146 *ppv = &MimeProtocol;
2150 static const IClassFactoryVtbl MimeFilterCFVtbl = {
2151 ClassFactory_QueryInterface,
2152 ClassFactory_AddRef,
2153 ClassFactory_Release,
2154 MimeFilter_CreateInstance,
2155 ClassFactory_LockServer
2158 static IClassFactory mimefilter_cf = { &MimeFilterCFVtbl };
2160 #define TEST_BINDING 0x0001
2161 #define TEST_FILTER 0x0002
2162 #define TEST_FIRST_HTTP 0x0004
2163 #define TEST_DIRECT_READ 0x0008
2164 #define TEST_POST 0x0010
2165 #define TEST_EMULATEPROT 0x0020
2166 #define TEST_SHORT_READ 0x0040
2167 #define TEST_REDIRECT 0x0080
2168 #define TEST_ABORT 0x0100
2169 #define TEST_ASYNCREQ 0x0200
2170 #define TEST_USEIURI 0x0400
2171 #define TEST_IMPLPROTEX 0x0800
2173 static void register_filter(BOOL do_register)
2175 IInternetSession *session;
2178 static const WCHAR gzipW[] = {'g','z','i','p',0};
2180 hres = pCoInternetGetSession(0, &session, 0);
2181 ok(hres == S_OK, "CoInternetGetSession failed: %08x\n", hres);
2184 hres = IInternetSession_RegisterMimeFilter(session, &mimefilter_cf, &IID_IInternetProtocol, gzipW);
2185 ok(hres == S_OK, "RegisterMimeFilter failed: %08x\n", hres);
2187 hres = IInternetSession_UnregisterMimeFilter(session, &mimefilter_cf, gzipW);
2188 ok(hres == S_OK, "RegisterMimeFilter failed: %08x\n", hres);
2191 IInternetSession_Release(session);
2194 static void init_test(int prot, DWORD flags)
2196 tested_protocol = prot;
2197 binding_test = (flags & TEST_BINDING) != 0;
2198 first_data_notif = TRUE;
2201 async_read_pending = TRUE;
2202 mimefilter_test = (flags & TEST_FILTER) != 0;
2204 post_stream_read = 0;
2205 ResetEvent(event_complete);
2206 ResetEvent(event_complete2);
2207 ResetEvent(event_continue);
2208 ResetEvent(event_continue_done);
2209 async_protocol = binding_protocol = filtered_protocol = NULL;
2210 filtered_sink = NULL;
2211 http_is_first = (flags & TEST_FIRST_HTTP) != 0;
2212 first_data_notif = TRUE;
2213 state = STATE_CONNECTING;
2214 test_async_req = (flags & TEST_ASYNCREQ) != 0;
2215 direct_read = (flags & TEST_DIRECT_READ) != 0;
2216 emulate_prot = (flags & TEST_EMULATEPROT) != 0;
2217 wait_for_switch = TRUE;
2218 short_read = (flags & TEST_SHORT_READ) != 0;
2219 http_post_test = TYMED_NULL;
2220 test_redirect = (flags & TEST_REDIRECT) != 0;
2221 test_abort = (flags & TEST_ABORT) != 0;
2222 impl_protex = (flags & TEST_IMPLPROTEX) != 0;
2224 register_filter(mimefilter_test);
2227 static void test_priority(IInternetProtocol *protocol)
2229 IInternetPriority *priority;
2233 hres = IInternetProtocol_QueryInterface(protocol, &IID_IInternetPriority,
2235 ok(hres == S_OK, "QueryInterface(IID_IInternetPriority) failed: %08x\n", hres);
2239 hres = IInternetPriority_GetPriority(priority, &pr);
2240 ok(hres == S_OK, "GetPriority failed: %08x\n", hres);
2241 ok(pr == 0, "pr=%d, expected 0\n", pr);
2243 hres = IInternetPriority_SetPriority(priority, 1);
2244 ok(hres == S_OK, "SetPriority failed: %08x\n", hres);
2246 hres = IInternetPriority_GetPriority(priority, &pr);
2247 ok(hres == S_OK, "GetPriority failed: %08x\n", hres);
2248 ok(pr == 1, "pr=%d, expected 1\n", pr);
2250 IInternetPriority_Release(priority);
2253 static void test_early_abort(const CLSID *clsid)
2255 IInternetProtocol *protocol;
2258 hres = CoCreateInstance(clsid, NULL, CLSCTX_INPROC_SERVER|CLSCTX_INPROC_HANDLER,
2259 &IID_IInternetProtocol, (void**)&protocol);
2260 ok(hres == S_OK, "CoCreateInstance failed: %08x\n", hres);
2262 hres = IInternetProtocol_Abort(protocol, E_ABORT, 0);
2263 ok(hres == S_OK, "Abort failed: %08x\n", hres);
2265 hres = IInternetProtocol_Abort(protocol, E_FAIL, 0);
2266 ok(hres == S_OK, "Abort failed: %08x\n", hres);
2268 IInternetProtocol_Release(protocol);
2271 static BOOL file_protocol_start(IInternetProtocol *protocol, LPCWSTR url,
2272 IInternetProtocolEx *protocolex, IUri *uri, BOOL is_first)
2276 SET_EXPECT(GetBindInfo);
2277 if(!(bindf & BINDF_FROMURLMON))
2278 SET_EXPECT(ReportProgress_DIRECTBIND);
2280 SET_EXPECT(ReportProgress_SENDINGREQUEST);
2281 SET_EXPECT(ReportProgress_CACHEFILENAMEAVAILABLE);
2282 if(bindf & BINDF_FROMURLMON)
2283 SET_EXPECT(ReportProgress_VERIFIEDMIMETYPEAVAILABLE);
2285 SET_EXPECT(ReportProgress_MIMETYPEAVAILABLE);
2287 SET_EXPECT(ReportData);
2289 SET_EXPECT(ReportResult);
2291 expect_hrResult = S_OK;
2294 hres = IInternetProtocolEx_StartEx(protocolex, uri, &protocol_sink, &bind_info, 0, 0);
2295 ok(hres == S_OK, "StartEx failed: %08x\n", hres);
2297 hres = IInternetProtocol_Start(protocol, url, &protocol_sink, &bind_info, 0, 0);
2298 if(hres == INET_E_RESOURCE_NOT_FOUND) {
2299 win_skip("Start failed\n");
2302 ok(hres == S_OK, "Start failed: %08x\n", hres);
2305 CHECK_CALLED(GetBindInfo);
2306 if(!(bindf & BINDF_FROMURLMON))
2307 CHECK_CALLED(ReportProgress_DIRECTBIND);
2309 CHECK_CALLED(ReportProgress_SENDINGREQUEST);
2310 CHECK_CALLED(ReportProgress_CACHEFILENAMEAVAILABLE);
2311 if(bindf & BINDF_FROMURLMON)
2312 CHECK_CALLED(ReportProgress_VERIFIEDMIMETYPEAVAILABLE);
2314 CHECK_CALLED(ReportProgress_MIMETYPEAVAILABLE);
2316 CHECK_CALLED(ReportData);
2318 CHECK_CALLED(ReportResult);
2323 static void test_file_protocol_url(LPCWSTR url)
2325 IInternetProtocolInfo *protocol_info;
2327 IClassFactory *factory;
2328 IInternetProtocol *protocol;
2333 hres = CoGetClassObject(&CLSID_FileProtocol, CLSCTX_INPROC_SERVER, NULL,
2334 &IID_IUnknown, (void**)&unk);
2335 ok(hres == S_OK, "CoGetClassObject failed: %08x\n", hres);
2339 hres = IUnknown_QueryInterface(unk, &IID_IInternetProtocolInfo, (void**)&protocol_info);
2340 ok(hres == E_NOINTERFACE,
2341 "Could not get IInternetProtocolInfo interface: %08x, expected E_NOINTERFACE\n", hres);
2343 hres = IUnknown_QueryInterface(unk, &IID_IClassFactory, (void**)&factory);
2344 ok(hres == S_OK, "Could not get IClassFactory interface\n");
2345 IUnknown_Release(unk);
2349 hres = IClassFactory_CreateInstance(factory, NULL, &IID_IInternetProtocol, (void**)&protocol);
2350 ok(hres == S_OK, "Could not get IInternetProtocol: %08x\n", hres);
2352 if(SUCCEEDED(hres)) {
2353 if(file_protocol_start(protocol, url, NULL, NULL, TRUE)) {
2354 hres = IInternetProtocol_Read(protocol, buf, 2, &cb);
2355 ok(hres == S_OK, "Read failed: %08x\n", hres);
2356 ok(cb == 2, "cb=%u expected 2\n", cb);
2357 hres = IInternetProtocol_Read(protocol, buf, sizeof(buf), &cb);
2358 ok(hres == S_FALSE, "Read failed: %08x\n", hres);
2359 hres = IInternetProtocol_Read(protocol, buf, sizeof(buf), &cb);
2360 ok(hres == S_FALSE, "Read failed: %08x expected S_FALSE\n", hres);
2361 ok(cb == 0, "cb=%u expected 0\n", cb);
2362 hres = IInternetProtocol_UnlockRequest(protocol);
2363 ok(hres == S_OK, "UnlockRequest failed: %08x\n", hres);
2366 if(file_protocol_start(protocol, url, NULL, NULL, FALSE)) {
2367 hres = IInternetProtocol_Read(protocol, buf, 2, &cb);
2368 ok(hres == S_FALSE, "Read failed: %08x\n", hres);
2369 hres = IInternetProtocol_LockRequest(protocol, 0);
2370 ok(hres == S_OK, "LockRequest failed: %08x\n", hres);
2371 hres = IInternetProtocol_UnlockRequest(protocol);
2372 ok(hres == S_OK, "UnlockRequest failed: %08x\n", hres);
2375 IInternetProtocol_Release(protocol);
2378 hres = IClassFactory_CreateInstance(factory, NULL, &IID_IInternetProtocol, (void**)&protocol);
2379 ok(hres == S_OK, "Could not get IInternetProtocol: %08x\n", hres);
2380 if(SUCCEEDED(hres)) {
2381 if(file_protocol_start(protocol, url, NULL, NULL, TRUE)) {
2382 hres = IInternetProtocol_LockRequest(protocol, 0);
2383 ok(hres == S_OK, "LockRequest failed: %08x\n", hres);
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\n", hres);
2388 hres = IInternetProtocol_UnlockRequest(protocol);
2389 ok(hres == S_OK, "UnlockRequest failed: %08x\n", hres);
2390 hres = IInternetProtocol_Read(protocol, buf, 2, &cb);
2391 ok(hres == S_OK, "Read failed: %08x\n", hres);
2392 hres = IInternetProtocol_Terminate(protocol, 0);
2393 ok(hres == S_OK, "Terminate failed: %08x\n", hres);
2396 IInternetProtocol_Release(protocol);
2399 hres = IClassFactory_CreateInstance(factory, NULL, &IID_IInternetProtocol, (void**)&protocol);
2400 ok(hres == S_OK, "Could not get IInternetProtocol: %08x\n", hres);
2401 if(SUCCEEDED(hres)) {
2402 if(file_protocol_start(protocol, url, NULL, NULL, TRUE)) {
2403 hres = IInternetProtocol_Terminate(protocol, 0);
2404 ok(hres == S_OK, "Terminate failed: %08x\n", hres);
2405 hres = IInternetProtocol_Read(protocol, buf, 2, &cb);
2406 ok(hres == S_OK, "Read failed: %08x\n", hres);
2407 ok(cb == 2, "cb=%u expected 2\n", cb);
2410 IInternetProtocol_Release(protocol);
2414 IInternetProtocolEx *protocolex;
2417 hres = pCreateUri(url, Uri_CREATE_FILE_USE_DOS_PATH, 0, &uri);
2418 ok(hres == S_OK, "CreateUri failed: %08x\n", hres);
2420 hres = IClassFactory_CreateInstance(factory, NULL, &IID_IInternetProtocolEx, (void**)&protocolex);
2421 ok(hres == S_OK, "Could not get IInternetProtocolEx: %08x\n", hres);
2423 if(file_protocol_start(NULL, NULL, protocolex, uri, TRUE)) {
2424 hres = IInternetProtocolEx_Read(protocolex, buf, 2, &cb);
2425 ok(hres == S_OK, "Read failed: %08x\n", hres);
2426 hres = IInternetProtocolEx_LockRequest(protocolex, 0);
2427 ok(hres == S_OK, "LockRequest failed: %08x\n", hres);
2428 hres = IInternetProtocolEx_UnlockRequest(protocolex);
2429 ok(hres == S_OK, "UnlockRequest failed: %08x\n", hres);
2433 IInternetProtocolEx_Release(protocolex);
2435 win_skip("Skipping file protocol StartEx tests\n");
2438 IClassFactory_Release(factory);
2441 static void test_file_protocol_fail(void)
2443 IInternetProtocol *protocol;
2446 static const WCHAR index_url2[] =
2447 {'f','i','l','e',':','/','/','i','n','d','e','x','.','h','t','m','l',0};
2449 hres = CoCreateInstance(&CLSID_FileProtocol, NULL, CLSCTX_INPROC_SERVER|CLSCTX_INPROC_HANDLER,
2450 &IID_IInternetProtocol, (void**)&protocol);
2451 ok(hres == S_OK, "CoCreateInstance failed: %08x\n", hres);
2455 SET_EXPECT(GetBindInfo);
2456 expect_hrResult = MK_E_SYNTAX;
2457 hres = IInternetProtocol_Start(protocol, wszIndexHtml, &protocol_sink, &bind_info, 0, 0);
2458 ok(hres == MK_E_SYNTAX ||
2459 hres == E_INVALIDARG,
2460 "Start failed: %08x, expected MK_E_SYNTAX or E_INVALIDARG\n", hres);
2461 CLEAR_CALLED(GetBindInfo); /* GetBindInfo not called in IE7 */
2463 SET_EXPECT(GetBindInfo);
2464 if(!(bindf & BINDF_FROMURLMON))
2465 SET_EXPECT(ReportProgress_DIRECTBIND);
2466 SET_EXPECT(ReportProgress_SENDINGREQUEST);
2467 SET_EXPECT(ReportResult);
2468 expect_hrResult = INET_E_RESOURCE_NOT_FOUND;
2469 hres = IInternetProtocol_Start(protocol, index_url, &protocol_sink, &bind_info, 0, 0);
2470 ok(hres == INET_E_RESOURCE_NOT_FOUND,
2471 "Start failed: %08x expected INET_E_RESOURCE_NOT_FOUND\n", hres);
2472 CHECK_CALLED(GetBindInfo);
2473 if(!(bindf & BINDF_FROMURLMON))
2474 CHECK_CALLED(ReportProgress_DIRECTBIND);
2475 CHECK_CALLED(ReportProgress_SENDINGREQUEST);
2476 CHECK_CALLED(ReportResult);
2478 IInternetProtocol_Release(protocol);
2480 hres = CoCreateInstance(&CLSID_FileProtocol, NULL, CLSCTX_INPROC_SERVER|CLSCTX_INPROC_HANDLER,
2481 &IID_IInternetProtocol, (void**)&protocol);
2482 ok(hres == S_OK, "CoCreateInstance failed: %08x\n", hres);
2486 SET_EXPECT(GetBindInfo);
2487 if(!(bindf & BINDF_FROMURLMON))
2488 SET_EXPECT(ReportProgress_DIRECTBIND);
2489 SET_EXPECT(ReportProgress_SENDINGREQUEST);
2490 SET_EXPECT(ReportResult);
2491 expect_hrResult = INET_E_RESOURCE_NOT_FOUND;
2493 hres = IInternetProtocol_Start(protocol, index_url2, &protocol_sink, &bind_info, 0, 0);
2494 ok(hres == INET_E_RESOURCE_NOT_FOUND,
2495 "Start failed: %08x, expected INET_E_RESOURCE_NOT_FOUND\n", hres);
2496 CHECK_CALLED(GetBindInfo);
2497 if(!(bindf & BINDF_FROMURLMON))
2498 CHECK_CALLED(ReportProgress_DIRECTBIND);
2499 CHECK_CALLED(ReportProgress_SENDINGREQUEST);
2500 CHECK_CALLED(ReportResult);
2502 SET_EXPECT(GetBindInfo);
2503 hres = IInternetProtocol_Start(protocol, NULL, &protocol_sink, &bind_info, 0, 0);
2504 ok(hres == E_INVALIDARG, "Start failed: %08x, expected E_INVALIDARG\n", hres);
2505 CLEAR_CALLED(GetBindInfo); /* GetBindInfo not called in IE7 */
2507 SET_EXPECT(GetBindInfo);
2508 hres = IInternetProtocol_Start(protocol, emptyW, &protocol_sink, &bind_info, 0, 0);
2509 ok(hres == E_INVALIDARG, "Start failed: %08x, expected E_INVALIDARG\n", hres);
2510 CLEAR_CALLED(GetBindInfo); /* GetBindInfo not called in IE7 */
2512 IInternetProtocol_Release(protocol);
2515 static void test_file_protocol(void) {
2516 WCHAR buf[INTERNET_MAX_URL_LENGTH], file_name_buf[MAX_PATH];
2521 static const WCHAR wszFile[] = {'f','i','l','e',':',0};
2522 static const WCHAR wszFile2[] = {'f','i','l','e',':','/','/',0};
2523 static const WCHAR wszFile3[] = {'f','i','l','e',':','/','/','/',0};
2524 static const WCHAR wszFile4[] = {'f','i','l','e',':','\\','\\',0};
2525 static const char html_doc[] = "<HTML></HTML>";
2527 trace("Testing file protocol...\n");
2528 init_test(FILE_TEST, 0);
2530 SetLastError(0xdeadbeef);
2531 file = CreateFileW(wszIndexHtml, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS,
2532 FILE_ATTRIBUTE_NORMAL, NULL);
2533 ok(file != INVALID_HANDLE_VALUE, "CreateFile failed\n");
2534 if(file == INVALID_HANDLE_VALUE)
2536 WriteFile(file, html_doc, sizeof(html_doc)-1, &size, NULL);
2539 file_name = wszIndexHtml;
2541 test_file_protocol_url(index_url);
2542 bindf = BINDF_FROMURLMON;
2543 test_file_protocol_url(index_url);
2544 bindf = BINDF_FROMURLMON | BINDF_NEEDFILE;
2545 test_file_protocol_url(index_url);
2547 memcpy(buf, wszFile, sizeof(wszFile));
2548 len = sizeof(wszFile)/sizeof(WCHAR)-1;
2549 len += GetCurrentDirectoryW(sizeof(buf)/sizeof(WCHAR)-len, buf+len);
2551 memcpy(buf+len, wszIndexHtml, sizeof(wszIndexHtml));
2553 file_name = buf + sizeof(wszFile)/sizeof(WCHAR)-1;
2555 test_file_protocol_url(buf);
2556 bindf = BINDF_FROMURLMON;
2557 test_file_protocol_url(buf);
2559 memcpy(buf, wszFile2, sizeof(wszFile2));
2560 len = GetCurrentDirectoryW(sizeof(file_name_buf)/sizeof(WCHAR), file_name_buf);
2561 file_name_buf[len++] = '\\';
2562 memcpy(file_name_buf+len, wszIndexHtml, sizeof(wszIndexHtml));
2563 lstrcpyW(buf+sizeof(wszFile2)/sizeof(WCHAR)-1, file_name_buf);
2564 file_name = file_name_buf;
2566 test_file_protocol_url(buf);
2567 bindf = BINDF_FROMURLMON;
2568 test_file_protocol_url(buf);
2570 buf[sizeof(wszFile2)/sizeof(WCHAR)] = '|';
2571 test_file_protocol_url(buf);
2573 memcpy(buf, wszFile3, sizeof(wszFile3));
2574 len = sizeof(wszFile3)/sizeof(WCHAR)-1;
2575 len += GetCurrentDirectoryW(sizeof(buf)/sizeof(WCHAR)-len, buf+len);
2577 memcpy(buf+len, wszIndexHtml, sizeof(wszIndexHtml));
2579 file_name = buf + sizeof(wszFile3)/sizeof(WCHAR)-1;
2581 test_file_protocol_url(buf);
2582 bindf = BINDF_FROMURLMON;
2583 test_file_protocol_url(buf);
2585 memcpy(buf, wszFile4, sizeof(wszFile4));
2586 len = GetCurrentDirectoryW(sizeof(file_name_buf)/sizeof(WCHAR), file_name_buf);
2587 file_name_buf[len++] = '\\';
2588 memcpy(file_name_buf+len, wszIndexHtml, sizeof(wszIndexHtml));
2589 lstrcpyW(buf+sizeof(wszFile4)/sizeof(WCHAR)-1, file_name_buf);
2590 file_name = file_name_buf;
2592 test_file_protocol_url(buf);
2593 bindf = BINDF_FROMURLMON;
2594 test_file_protocol_url(buf);
2596 buf[sizeof(wszFile4)/sizeof(WCHAR)] = '|';
2597 test_file_protocol_url(buf);
2599 DeleteFileW(wszIndexHtml);
2602 test_file_protocol_fail();
2603 bindf = BINDF_FROMURLMON;
2604 test_file_protocol_fail();
2607 static BOOL http_protocol_start(LPCWSTR url, BOOL use_iuri)
2609 static BOOL got_user_agent = FALSE;
2613 if(use_iuri && pCreateUri) {
2614 hres = pCreateUri(url, 0, 0, &uri);
2615 ok(hres == S_OK, "CreateUri failed: %08x\n", hres);
2618 SET_EXPECT(GetBindInfo);
2619 if (!(bindf & BINDF_FROMURLMON))
2620 SET_EXPECT(ReportProgress_DIRECTBIND);
2622 SET_EXPECT(GetBindString_USER_AGENT);
2623 SET_EXPECT(GetBindString_ACCEPT_MIMES);
2624 SET_EXPECT(QueryService_HttpNegotiate);
2625 SET_EXPECT(BeginningTransaction);
2626 SET_EXPECT(GetRootSecurityId);
2627 if(http_post_test) {
2628 SET_EXPECT(GetBindString_POST_COOKIE);
2629 if(http_post_test == TYMED_ISTREAM)
2630 SET_EXPECT(Stream_Seek);
2634 IInternetProtocolEx *protocolex;
2636 hres = IInternetProtocol_QueryInterface(async_protocol, &IID_IInternetProtocolEx, (void**)&protocolex);
2637 ok(hres == S_OK, "Could not get IInternetProtocolEx iface: %08x\n", hres);
2639 hres = IInternetProtocolEx_StartEx(protocolex, uri, &protocol_sink, &bind_info, 0, 0);
2640 ok(hres == S_OK, "Start failed: %08x\n", hres);
2642 IInternetProtocolEx_Release(protocolex);
2645 hres = IInternetProtocol_Start(async_protocol, url, &protocol_sink, &bind_info, 0, 0);
2646 ok(hres == S_OK, "Start failed: %08x\n", hres);
2651 CHECK_CALLED(GetBindInfo);
2652 if (!(bindf & BINDF_FROMURLMON))
2653 CHECK_CALLED(ReportProgress_DIRECTBIND);
2654 if (!got_user_agent)
2656 CHECK_CALLED(GetBindString_USER_AGENT);
2657 got_user_agent = TRUE;
2659 CHECK_CALLED(GetBindString_ACCEPT_MIMES);
2660 CHECK_CALLED(QueryService_HttpNegotiate);
2661 CHECK_CALLED(BeginningTransaction);
2662 /* GetRootSecurityId called on WinXP but not on Win98 */
2663 CLEAR_CALLED(GetRootSecurityId);
2664 if(http_post_test) {
2665 CHECK_CALLED(GetBindString_POST_COOKIE);
2666 if(http_post_test == TYMED_ISTREAM)
2667 CHECK_CALLED(Stream_Seek);
2673 static void test_protocol_terminate(IInternetProtocol *protocol)
2679 hres = IInternetProtocol_LockRequest(protocol, 0);
2680 ok(hres == S_OK, "LockRequest failed: %08x\n", hres);
2682 hres = IInternetProtocol_Read(protocol, buf, 1, &cb);
2683 ok(hres == test_abort ? S_OK : S_FALSE, "Read failed: %08x\n", hres);
2685 hres = IInternetProtocol_Terminate(protocol, 0);
2686 ok(hres == S_OK, "Terminate failed: %08x\n", hres);
2688 /* This wait is to give the internet handles being freed in Terminate
2689 * enough time to actually terminate in all cases. Internet handles
2690 * terminate asynchronously and native reuses the main InternetOpen
2691 * handle. The only case in which this seems to be necessary is on
2692 * wine with native wininet and urlmon, resulting in the next time
2693 * test_http_protocol_url being called the first data notification actually
2694 * being an extra last data notification from the previous connection
2695 * about once out of every ten times. */
2698 hres = IInternetProtocol_UnlockRequest(protocol);
2699 ok(hres == S_OK, "UnlockRequest failed: %08x\n", hres);
2702 static void test_http_info(IInternetProtocol *protocol)
2704 IWinInetHttpInfo *info;
2707 hres = IInternetProtocol_QueryInterface(protocol, &IID_IWinInetHttpInfo, (void**)&info);
2708 ok(hres == S_OK, "Could not get IWinInterHttpInfo iface: %08x\n", hres);
2712 IWinInetHttpInfo_Release(info);
2715 /* is_first refers to whether this is the first call to this function
2717 static void test_http_protocol_url(LPCWSTR url, int prot, DWORD flags, DWORD tymed)
2719 IInternetProtocolInfo *protocol_info;
2720 IClassFactory *factory;
2724 init_test(prot, flags);
2726 http_post_test = tymed;
2728 hres = CoGetClassObject(prot == HTTPS_TEST ? &CLSID_HttpSProtocol : &CLSID_HttpProtocol,
2729 CLSCTX_INPROC_SERVER, NULL, &IID_IUnknown, (void**)&unk);
2730 ok(hres == S_OK, "CoGetClassObject failed: %08x\n", hres);
2734 hres = IUnknown_QueryInterface(unk, &IID_IInternetProtocolInfo, (void**)&protocol_info);
2735 ok(hres == E_NOINTERFACE,
2736 "Could not get IInternetProtocolInfo interface: %08x, expected E_NOINTERFACE\n",
2739 hres = IUnknown_QueryInterface(unk, &IID_IClassFactory, (void**)&factory);
2740 ok(hres == S_OK, "Could not get IClassFactory interface\n");
2741 IUnknown_Release(unk);
2745 hres = IClassFactory_CreateInstance(factory, NULL, &IID_IInternetProtocol,
2746 (void**)&async_protocol);
2747 ok(hres == S_OK, "Could not get IInternetProtocol: %08x\n", hres);
2748 if(SUCCEEDED(hres)) {
2753 test_priority(async_protocol);
2754 test_http_info(async_protocol);
2756 SET_EXPECT(ReportProgress_COOKIE_SENT);
2758 SET_EXPECT(ReportProgress_FINDINGRESOURCE);
2759 SET_EXPECT(ReportProgress_CONNECTING);
2761 SET_EXPECT(ReportProgress_SENDINGREQUEST);
2763 SET_EXPECT(ReportProgress_REDIRECTING);
2764 SET_EXPECT(ReportProgress_PROXYDETECTING);
2765 if(prot == HTTP_TEST)
2766 SET_EXPECT(ReportProgress_CACHEFILENAMEAVAILABLE);
2768 SET_EXPECT(QueryService_HttpSecurity);
2769 if(!(bindf & BINDF_FROMURLMON)) {
2770 SET_EXPECT(OnResponse);
2771 SET_EXPECT(ReportProgress_RAWMIMETYPE);
2772 SET_EXPECT(ReportData);
2777 if(!http_protocol_start(url, (flags & TEST_USEIURI) != 0))
2780 if(!direct_read && !test_abort)
2781 SET_EXPECT(ReportResult);
2782 expect_hrResult = test_abort ? E_ABORT : S_OK;
2786 while(wait_for_switch) {
2787 WaitForSingleObject(event_continue, INFINITE);
2788 CHECK_CALLED(Switch); /* Set in ReportData */
2789 call_continue(&continue_protdata);
2790 SetEvent(event_continue_done);
2793 hres = IInternetProtocol_Read(async_protocol, buf, 1, &cb);
2794 ok((hres == E_PENDING && cb==0) ||
2795 (hres == S_OK && cb==1), "Read failed: %08x (%d bytes)\n", hres, cb);
2797 WaitForSingleObject(event_complete, INFINITE);
2798 if(bindf & BINDF_FROMURLMON)
2799 CHECK_CALLED(Switch);
2801 CHECK_CALLED(ReportData);
2802 if(prot == HTTPS_TEST)
2803 CLEAR_CALLED(QueryService_HttpSecurity);
2806 if(bindf & BINDF_FROMURLMON)
2809 SET_EXPECT(ReportData);
2810 hres = IInternetProtocol_Read(async_protocol, buf, sizeof(buf), &cb);
2811 if(hres == E_PENDING) {
2812 hres = IInternetProtocol_Read(async_protocol, buf, 1, &cb);
2813 ok((hres == E_PENDING && cb==0) ||
2814 (hres == S_OK && cb==1), "Read failed: %08x (%d bytes)\n", hres, cb);
2815 WaitForSingleObject(event_complete, INFINITE);
2816 if(bindf & BINDF_FROMURLMON)
2817 CHECK_CALLED(Switch);
2819 CHECK_CALLED(ReportData);
2824 SET_EXPECT(ReportResult);
2825 hres = IInternetProtocol_Abort(async_protocol, E_ABORT, 0);
2826 ok(hres == S_OK, "Abort failed: %08x\n", hres);
2827 CHECK_CALLED(ReportResult);
2829 hres = IInternetProtocol_Abort(async_protocol, E_ABORT, 0);
2830 ok(hres == INET_E_RESULT_DISPATCHED, "Abort failed: %08x\n", hres);
2834 if(bindf & BINDF_FROMURLMON)
2835 CHECK_NOT_CALLED(Switch);
2837 CHECK_NOT_CALLED(ReportData);
2842 ok(hres == S_FALSE, "Read failed: %08x\n", hres);
2843 CHECK_CALLED(ReportResult);
2846 if(prot == HTTPS_TEST)
2847 CLEAR_CALLED(ReportProgress_SENDINGREQUEST);
2849 hres = IInternetProtocol_Abort(async_protocol, E_ABORT, 0);
2850 ok(hres == INET_E_RESULT_DISPATCHED, "Abort failed: %08x\n", hres);
2852 test_protocol_terminate(async_protocol);
2854 hres = IInternetProtocol_Abort(async_protocol, E_ABORT, 0);
2855 ok(hres == S_OK, "Abort failed: %08x\n", hres);
2857 ref = IInternetProtocol_Release(async_protocol);
2858 ok(!ref, "ref=%x\n", ref);
2861 IClassFactory_Release(factory);
2864 static void test_http_protocol(void)
2866 static const WCHAR posttest_url[] =
2867 {'h','t','t','p',':','/','/','t','e','s','t','.','w','i','n','e','h','q','.','o','r','g','/',
2868 't','e','s','t','s','/','p','o','s','t','.','p','h','p',0};
2869 static const WCHAR redirect_url[] =
2870 {'h','t','t','p',':','/','/','t','e','s','t','.','w','i','n','e','h','q','.','o','r','g','/',
2871 't','e','s','t','s','/','r','e','d','i','r','e','c','t',0};
2872 static const WCHAR winetest_url[] =
2873 {'h','t','t','p',':','/','/','t','e','s','t','.','w','i','n','e','h','q','.','o','r','g','/',
2874 't','e','s','t','s','/','d','a','t','a','.','p','h','p',0};
2876 trace("Testing http protocol (not from urlmon)...\n");
2877 bindf = BINDF_ASYNCHRONOUS | BINDF_ASYNCSTORAGE | BINDF_PULLDATA;
2878 test_http_protocol_url(winetest_url, HTTP_TEST, TEST_FIRST_HTTP, TYMED_NULL);
2880 trace("Testing http protocol (from urlmon)...\n");
2881 bindf = BINDF_ASYNCHRONOUS | BINDF_ASYNCSTORAGE | BINDF_PULLDATA | BINDF_FROMURLMON;
2882 test_http_protocol_url(winetest_url, HTTP_TEST, 0, TYMED_NULL);
2884 trace("Testing http protocol (to file)...\n");
2885 bindf = BINDF_ASYNCHRONOUS | BINDF_ASYNCSTORAGE | BINDF_PULLDATA | BINDF_FROMURLMON | BINDF_NEEDFILE;
2886 test_http_protocol_url(winetest_url, HTTP_TEST, 0, TYMED_NULL);
2888 trace("Testing http protocol (post data)...\n");
2889 bindf = BINDF_ASYNCHRONOUS | BINDF_ASYNCSTORAGE | BINDF_PULLDATA | BINDF_FROMURLMON;
2890 test_http_protocol_url(posttest_url, HTTP_TEST, TEST_FIRST_HTTP|TEST_POST, TYMED_HGLOBAL);
2892 trace("Testing http protocol (post data stream)...\n");
2893 test_http_protocol_url(posttest_url, HTTP_TEST, TEST_FIRST_HTTP|TEST_POST|TEST_ASYNCREQ, TYMED_ISTREAM);
2895 trace("Testing http protocol (direct read)...\n");
2896 bindf = BINDF_ASYNCHRONOUS | BINDF_ASYNCSTORAGE | BINDF_PULLDATA | BINDF_FROMURLMON;
2897 test_http_protocol_url(winetest_url, HTTP_TEST, TEST_DIRECT_READ|TEST_USEIURI, TYMED_NULL);
2899 trace("Testing http protocol (redirected)...\n");
2900 bindf = BINDF_ASYNCHRONOUS | BINDF_ASYNCSTORAGE | BINDF_PULLDATA | BINDF_FROMURLMON;
2901 test_http_protocol_url(redirect_url, HTTP_TEST, TEST_REDIRECT, TYMED_NULL);
2903 trace("Testing http protocol abort...\n");
2904 test_http_protocol_url(winetest_url, HTTP_TEST, TEST_ABORT, TYMED_NULL);
2906 test_early_abort(&CLSID_HttpProtocol);
2907 test_early_abort(&CLSID_HttpSProtocol);
2910 static void test_https_protocol(void)
2912 static const WCHAR codeweavers_url[] =
2913 {'h','t','t','p','s',':','/','/','w','w','w','.','c','o','d','e','w','e','a','v','e','r','s',
2914 '.','c','o','m','/','t','e','s','t','.','h','t','m','l',0};
2916 trace("Testing https protocol (from urlmon)...\n");
2917 bindf = BINDF_ASYNCHRONOUS | BINDF_ASYNCSTORAGE | BINDF_PULLDATA | BINDF_FROMURLMON | BINDF_NOWRITECACHE;
2918 test_http_protocol_url(codeweavers_url, HTTPS_TEST, TEST_FIRST_HTTP, TYMED_NULL);
2922 static void test_ftp_protocol(void)
2924 IInternetProtocolInfo *protocol_info;
2925 IClassFactory *factory;
2932 static const WCHAR ftp_urlW[] = {'f','t','p',':','/','/','f','t','p','.','w','i','n','e','h','q','.','o','r','g',
2933 '/','p','u','b','/','o','t','h','e','r','/',
2934 'w','i','n','e','l','o','g','o','.','x','c','f','.','t','a','r','.','b','z','2',0};
2936 trace("Testing ftp protocol...\n");
2938 bindf = BINDF_ASYNCHRONOUS | BINDF_ASYNCSTORAGE | BINDF_PULLDATA | BINDF_FROMURLMON | BINDF_NOWRITECACHE;
2939 state = STATE_STARTDOWNLOADING;
2940 tested_protocol = FTP_TEST;
2941 first_data_notif = TRUE;
2942 expect_hrResult = E_PENDING;
2944 hres = CoGetClassObject(&CLSID_FtpProtocol, CLSCTX_INPROC_SERVER, NULL, &IID_IUnknown, (void**)&unk);
2945 ok(hres == S_OK, "CoGetClassObject failed: %08x\n", hres);
2949 hres = IUnknown_QueryInterface(unk, &IID_IInternetProtocolInfo, (void**)&protocol_info);
2950 ok(hres == E_NOINTERFACE, "Could not get IInternetProtocolInfo interface: %08x, expected E_NOINTERFACE\n", hres);
2952 hres = IUnknown_QueryInterface(unk, &IID_IClassFactory, (void**)&factory);
2953 ok(hres == S_OK, "Could not get IClassFactory interface\n");
2954 IUnknown_Release(unk);
2958 hres = IClassFactory_CreateInstance(factory, NULL, &IID_IInternetProtocol,
2959 (void**)&async_protocol);
2960 IClassFactory_Release(factory);
2961 ok(hres == S_OK, "Could not get IInternetProtocol: %08x\n", hres);
2963 test_priority(async_protocol);
2964 test_http_info(async_protocol);
2966 SET_EXPECT(GetBindInfo);
2967 SET_EXPECT(ReportProgress_FINDINGRESOURCE);
2968 SET_EXPECT(ReportProgress_CONNECTING);
2969 SET_EXPECT(ReportProgress_SENDINGREQUEST);
2972 hres = IInternetProtocol_Start(async_protocol, ftp_urlW, &protocol_sink, &bind_info, 0, 0);
2973 ok(hres == S_OK, "Start failed: %08x\n", hres);
2974 CHECK_CALLED(GetBindInfo);
2976 SET_EXPECT(ReportResult);
2978 hres = IInternetProtocol_Read(async_protocol, buf, 1, &cb);
2979 ok((hres == E_PENDING && cb==0) ||
2980 (hres == S_OK && cb==1), "Read failed: %08x (%d bytes)\n", hres, cb);
2982 WaitForSingleObject(event_complete, INFINITE);
2985 hres = IInternetProtocol_Read(async_protocol, buf, sizeof(buf), &cb);
2986 if(hres == E_PENDING)
2987 WaitForSingleObject(event_complete, INFINITE);
2992 ok(hres == S_FALSE, "Read failed: %08x\n", hres);
2993 CHECK_CALLED(ReportResult);
2994 CHECK_CALLED(Switch);
2996 test_protocol_terminate(async_protocol);
2999 IInternetProtocolEx *protocolex;
3001 hres = IInternetProtocol_QueryInterface(async_protocol, &IID_IInternetProtocolEx, (void**)&protocolex);
3002 ok(hres == S_OK, "Could not get IInternetProtocolEx iface: %08x\n", hres);
3003 IInternetProtocolEx_Release(protocolex);
3006 ref = IInternetProtocol_Release(async_protocol);
3007 ok(!ref, "ref=%d\n", ref);
3009 test_early_abort(&CLSID_FtpProtocol);
3012 static void test_gopher_protocol(void)
3014 IInternetProtocolInfo *protocol_info;
3015 IClassFactory *factory;
3019 trace("Testing gopher protocol...\n");
3021 hres = CoGetClassObject(&CLSID_GopherProtocol, CLSCTX_INPROC_SERVER, NULL, &IID_IUnknown, (void**)&unk);
3023 hres == REGDB_E_CLASSNOTREG, /* Gopher protocol has been removed as of Vista */
3024 "CoGetClassObject failed: %08x\n", hres);
3028 hres = IUnknown_QueryInterface(unk, &IID_IInternetProtocolInfo, (void**)&protocol_info);
3029 ok(hres == E_NOINTERFACE, "Could not get IInternetProtocolInfo interface: %08x, expected E_NOINTERFACE\n", hres);
3031 hres = IUnknown_QueryInterface(unk, &IID_IClassFactory, (void**)&factory);
3032 ok(hres == S_OK, "Could not get IClassFactory interface\n");
3033 IUnknown_Release(unk);
3037 hres = IClassFactory_CreateInstance(factory, NULL, &IID_IInternetProtocol,
3038 (void**)&async_protocol);
3039 IClassFactory_Release(factory);
3040 ok(hres == S_OK, "Could not get IInternetProtocol: %08x\n", hres);
3042 test_priority(async_protocol);
3044 IInternetProtocol_Release(async_protocol);
3046 test_early_abort(&CLSID_GopherProtocol);
3049 static void test_mk_protocol(void)
3051 IInternetProtocolInfo *protocol_info;
3052 IInternetProtocol *protocol;
3053 IClassFactory *factory;
3057 static const WCHAR wrong_url1[] = {'t','e','s','t',':','@','M','S','I','T','S','t','o','r','e',
3058 ':',':','/','t','e','s','t','.','h','t','m','l',0};
3059 static const WCHAR wrong_url2[] = {'m','k',':','/','t','e','s','t','.','h','t','m','l',0};
3061 trace("Testing mk protocol...\n");
3062 init_test(MK_TEST, 0);
3064 hres = CoGetClassObject(&CLSID_MkProtocol, CLSCTX_INPROC_SERVER, NULL,
3065 &IID_IUnknown, (void**)&unk);
3066 ok(hres == S_OK, "CoGetClassObject failed: %08x\n", hres);
3068 hres = IUnknown_QueryInterface(unk, &IID_IInternetProtocolInfo, (void**)&protocol_info);
3069 ok(hres == E_NOINTERFACE,
3070 "Could not get IInternetProtocolInfo interface: %08x, expected E_NOINTERFACE\n",
3073 hres = IUnknown_QueryInterface(unk, &IID_IClassFactory, (void**)&factory);
3074 ok(hres == S_OK, "Could not get IClassFactory interface\n");
3075 IUnknown_Release(unk);
3079 hres = IClassFactory_CreateInstance(factory, NULL, &IID_IInternetProtocol,
3081 IClassFactory_Release(factory);
3082 ok(hres == S_OK, "Could not get IInternetProtocol: %08x\n", hres);
3084 SET_EXPECT(GetBindInfo);
3085 hres = IInternetProtocol_Start(protocol, wrong_url1, &protocol_sink, &bind_info, 0, 0);
3086 ok(hres == MK_E_SYNTAX || hres == INET_E_INVALID_URL,
3087 "Start failed: %08x, expected MK_E_SYNTAX or INET_E_INVALID_URL\n", hres);
3088 CLEAR_CALLED(GetBindInfo);
3090 SET_EXPECT(GetBindInfo);
3091 SET_EXPECT(ReportProgress_DIRECTBIND);
3092 SET_EXPECT(ReportProgress_SENDINGREQUEST);
3093 SET_EXPECT(ReportProgress_MIMETYPEAVAILABLE);
3094 SET_EXPECT(ReportResult);
3095 expect_hrResult = INET_E_RESOURCE_NOT_FOUND;
3097 hres = IInternetProtocol_Start(protocol, wrong_url2, &protocol_sink, &bind_info, 0, 0);
3098 ok(hres == INET_E_RESOURCE_NOT_FOUND ||
3099 hres == INET_E_INVALID_URL, /* win2k3 */
3100 "Start failed: %08x, expected INET_E_RESOURCE_NOT_FOUND or INET_E_INVALID_URL\n", hres);
3102 if (hres == INET_E_RESOURCE_NOT_FOUND) {
3103 CHECK_CALLED(GetBindInfo);
3104 CLEAR_CALLED(ReportProgress_DIRECTBIND);
3105 CHECK_CALLED(ReportProgress_SENDINGREQUEST);
3106 CHECK_CALLED(ReportProgress_MIMETYPEAVAILABLE);
3107 CHECK_CALLED(ReportResult);
3109 CLEAR_CALLED(GetBindInfo);
3110 CLEAR_CALLED(ReportProgress_DIRECTBIND);
3111 CLEAR_CALLED(ReportProgress_SENDINGREQUEST);
3112 CLEAR_CALLED(ReportProgress_MIMETYPEAVAILABLE);
3113 CLEAR_CALLED(ReportResult);
3116 IInternetProtocol_Release(protocol);
3119 static void test_CreateBinding(void)
3121 IInternetProtocol *protocol;
3122 IInternetPriority *priority;
3123 IInternetSession *session;
3124 IWinInetHttpInfo *http_info;
3125 IWinInetInfo *inet_info;
3131 static const WCHAR test_url[] =
3132 {'t','e','s','t',':','/','/','f','i','l','e','.','h','t','m','l',0};
3133 static const WCHAR wsz_test[] = {'t','e','s','t',0};
3135 trace("Testing CreateBinding...\n");
3136 init_test(BIND_TEST, TEST_BINDING);
3138 hres = pCoInternetGetSession(0, &session, 0);
3139 ok(hres == S_OK, "CoInternetGetSession failed: %08x\n", hres);
3141 hres = IInternetSession_RegisterNameSpace(session, &ClassFactory, &IID_NULL, wsz_test, 0, NULL, 0);
3142 ok(hres == S_OK, "RegisterNameSpace failed: %08x\n", hres);
3144 hres = IInternetSession_CreateBinding(session, NULL, test_url, NULL, NULL, &protocol, 0);
3145 binding_protocol = protocol;
3146 ok(hres == S_OK, "CreateBinding failed: %08x\n", hres);
3147 ok(protocol != NULL, "protocol == NULL\n");
3149 hres = IInternetProtocol_QueryInterface(protocol, &IID_IInternetBindInfo, (void**)&prot_bind_info);
3150 ok(hres == S_OK, "QueryInterface(IID_IInternetBindInfo) failed: %08x\n", hres);
3152 hres = IInternetProtocol_QueryInterface(protocol, &IID_IInternetProtocolSink, (void**)&binding_sink);
3153 ok(hres == S_OK, "Could not get IInternetProtocolSink: %08x\n", hres);
3155 hres = IInternetProtocol_Start(protocol, test_url, NULL, &bind_info, 0, 0);
3156 ok(hres == E_INVALIDARG, "Start failed: %08x, expected E_INVALIDARG\n", hres);
3157 hres = IInternetProtocol_Start(protocol, test_url, &protocol_sink, NULL, 0, 0);
3158 ok(hres == E_INVALIDARG, "Start failed: %08x, expected E_INVALIDARG\n", hres);
3159 hres = IInternetProtocol_Start(protocol, NULL, &protocol_sink, &bind_info, 0, 0);
3160 ok(hres == E_INVALIDARG, "Start failed: %08x, expected E_INVALIDARG\n", hres);
3162 hres = IInternetProtocol_QueryInterface(protocol, &IID_IInternetPriority, (void**)&priority);
3163 ok(hres == S_OK, "QueryInterface(IID_IInternetPriority) failed: %08x\n", hres);
3166 hres = IInternetPriority_GetPriority(priority, &p);
3167 ok(hres == S_OK, "GetPriority failed: %08x\n", hres);
3168 ok(!p, "p=%d\n", p);
3171 hres = IInternetPriority_SetPriority(priority, 100);
3172 ok(hres == S_OK, "SetPriority failed: %08x\n", hres);
3175 hres = IInternetPriority_GetPriority(priority, &p);
3176 ok(hres == S_OK, "GetPriority failed: %08x\n", hres);
3177 ok(p == 100, "p=%d\n", p);
3179 hres = IInternetProtocol_QueryInterface(protocol, &IID_IWinInetInfo, (void**)&inet_info);
3180 ok(hres == E_NOINTERFACE, "Could not get IWinInetInfo protocol: %08x\n", hres);
3182 SET_EXPECT(QueryService_InternetProtocol);
3183 SET_EXPECT(CreateInstance);
3184 SET_EXPECT(ReportProgress_PROTOCOLCLASSID);
3185 SET_EXPECT(SetPriority);
3188 expect_hrResult = S_OK;
3189 hres = IInternetProtocol_Start(protocol, test_url, &protocol_sink, &bind_info, 0, 0);
3190 ok(hres == S_OK, "Start failed: %08x\n", hres);
3192 CHECK_CALLED(QueryService_InternetProtocol);
3193 CHECK_CALLED(CreateInstance);
3194 CHECK_CALLED(ReportProgress_PROTOCOLCLASSID);
3195 CHECK_CALLED(SetPriority);
3196 CHECK_CALLED(Start);
3198 SET_EXPECT(QueryInterface_IWinInetInfo);
3199 hres = IInternetProtocol_QueryInterface(protocol, &IID_IWinInetInfo, (void**)&inet_info);
3200 ok(hres == E_NOINTERFACE, "Could not get IWinInetInfo protocol: %08x\n", hres);
3201 CHECK_CALLED(QueryInterface_IWinInetInfo);
3203 SET_EXPECT(QueryInterface_IWinInetInfo);
3204 hres = IInternetProtocol_QueryInterface(protocol, &IID_IWinInetInfo, (void**)&inet_info);
3205 ok(hres == E_NOINTERFACE, "Could not get IWinInetInfo protocol: %08x\n", hres);
3206 CHECK_CALLED(QueryInterface_IWinInetInfo);
3208 SET_EXPECT(QueryInterface_IWinInetHttpInfo);
3209 hres = IInternetProtocol_QueryInterface(protocol, &IID_IWinInetHttpInfo, (void**)&http_info);
3210 ok(hres == E_NOINTERFACE, "Could not get IWinInetInfo protocol: %08x\n", hres);
3211 CHECK_CALLED(QueryInterface_IWinInetHttpInfo);
3215 hres = IInternetProtocol_Read(protocol, expect_pv = buf, sizeof(buf), &read);
3216 ok(hres == S_OK, "Read failed: %08x\n", hres);
3217 ok(read == 100, "read = %d\n", read);
3222 hres = IInternetProtocol_Read(protocol, expect_pv = buf, sizeof(buf), &read);
3223 ok(hres == S_FALSE, "Read failed: %08x\n", hres);
3224 ok(!read, "read = %d\n", read);
3228 hres = IInternetPriority_GetPriority(priority, &p);
3229 ok(hres == S_OK, "GetPriority failed: %08x\n", hres);
3230 ok(p == 100, "p=%d\n", p);
3232 hres = IInternetPriority_SetPriority(priority, 101);
3233 ok(hres == S_OK, "SetPriority failed: %08x\n", hres);
3235 SET_EXPECT(Terminate);
3236 hres = IInternetProtocol_Terminate(protocol, 0xdeadbeef);
3237 ok(hres == S_OK, "Terminate failed: %08x\n", hres);
3238 CHECK_CALLED(Terminate);
3240 SET_EXPECT(Continue);
3241 hres = IInternetProtocolSink_Switch(binding_sink, &protocoldata);
3242 ok(hres == S_OK, "Switch failed: %08x\n", hres);
3243 CHECK_CALLED(Continue);
3245 hres = IInternetProtocolSink_ReportProgress(binding_sink,
3246 BINDSTATUS_CACHEFILENAMEAVAILABLE, expect_wsz = emptyW);
3247 ok(hres == S_OK, "ReportProgress(BINDSTATUS_CACHEFILENAMEAVAILABLE) failed: %08x\n", hres);
3249 hres = IInternetProtocolSink_ReportResult(binding_sink, S_OK, ERROR_SUCCESS, NULL);
3250 ok(hres == E_FAIL, "ReportResult failed: %08x, expected E_FAIL\n", hres);
3252 hres = IInternetProtocolSink_ReportData(binding_sink, 0, 0, 0);
3253 ok(hres == S_OK, "ReportData failed: %08x\n", hres);
3255 IInternetProtocolSink_Release(binding_sink);
3256 IInternetPriority_Release(priority);
3257 IInternetBindInfo_Release(prot_bind_info);
3258 IInternetProtocol_Release(protocol);
3260 hres = IInternetSession_CreateBinding(session, NULL, test_url, NULL, NULL, &protocol, 0);
3261 ok(hres == S_OK, "CreateBinding failed: %08x\n", hres);
3262 ok(protocol != NULL, "protocol == NULL\n");
3264 hres = IInternetProtocol_Abort(protocol, E_ABORT, 0);
3265 ok(hres == S_OK, "Abort failed: %08x\n", hres);
3267 hres = IInternetProtocol_Abort(protocol, E_FAIL, 0);
3268 ok(hres == S_OK, "Abort failed: %08x\n", hres);
3270 IInternetProtocol_Release(protocol);
3272 hres = IInternetSession_UnregisterNameSpace(session, &ClassFactory, wsz_test);
3273 ok(hres == S_OK, "UnregisterNameSpace failed: %08x\n", hres);
3275 hres = IInternetSession_CreateBinding(session, NULL, test_url, NULL, NULL, &protocol, 0);
3276 ok(hres == S_OK, "CreateBinding failed: %08x\n", hres);
3277 ok(protocol != NULL, "protocol == NULL\n");
3279 SET_EXPECT(QueryService_InternetProtocol);
3280 hres = IInternetProtocol_Start(protocol, test_url, &protocol_sink, &bind_info, 0, 0);
3281 ok(hres == MK_E_SYNTAX, "Start failed: %08x, expected MK_E_SYNTAX\n", hres);
3282 CHECK_CALLED(QueryService_InternetProtocol);
3284 IInternetProtocol_Release(protocol);
3286 IInternetSession_Release(session);
3289 static void test_binding(int prot, DWORD grf_pi, DWORD test_flags)
3291 IInternetProtocolEx *protocolex = NULL;
3292 IInternetProtocol *protocol;
3293 IInternetSession *session;
3300 init_test(prot, test_flags|TEST_BINDING);
3302 hres = pCoInternetGetSession(0, &session, 0);
3303 ok(hres == S_OK, "CoInternetGetSession failed: %08x\n", hres);
3305 if(test_flags & TEST_EMULATEPROT) {
3306 hres = IInternetSession_RegisterNameSpace(session, &ClassFactory, &IID_NULL, protocol_names[prot], 0, NULL, 0);
3307 ok(hres == S_OK, "RegisterNameSpace failed: %08x\n", hres);
3310 hres = IInternetSession_CreateBinding(session, NULL, binding_urls[prot], NULL, NULL, &protocol, 0);
3311 binding_protocol = protocol;
3312 ok(hres == S_OK, "CreateBinding failed: %08x\n", hres);
3313 ok(protocol != NULL, "protocol == NULL\n");
3315 hres = IInternetProtocol_QueryInterface(protocol, &IID_IInternetBindInfo, (void**)&prot_bind_info);
3316 ok(hres == S_OK, "QueryInterface(IID_IInternetBindInfo) failed: %08x\n", hres);
3318 hres = IInternetProtocol_QueryInterface(protocol, &IID_IInternetProtocolSink, (void**)&binding_sink);
3319 ok(hres == S_OK, "QueryInterface(IID_IInternetProtocolSink) failed: %08x\n", hres);
3321 if(test_flags & TEST_USEIURI) {
3322 hres = IInternetProtocol_QueryInterface(protocol, &IID_IInternetProtocolEx, (void**)&protocolex);
3323 ok(hres == S_OK, "Could not get IInternetProtocolEx iface: %08x\n", hres);
3325 hres = pCreateUri(binding_urls[prot], Uri_CREATE_FILE_USE_DOS_PATH, 0, &uri);
3326 ok(hres == S_OK, "CreateUri failed: %08x\n", hres);
3330 SET_EXPECT(QueryService_InternetProtocol);
3331 SET_EXPECT(CreateInstance);
3332 SET_EXPECT(ReportProgress_PROTOCOLCLASSID);
3333 SET_EXPECT(SetPriority);
3335 SET_EXPECT(StartEx);
3339 expect_hrResult = S_OK;
3342 hres = IInternetProtocolEx_StartEx(protocolex, uri, &protocol_sink, &bind_info, pi, 0);
3343 ok(hres == S_OK, "StartEx failed: %08x\n", hres);
3345 hres = IInternetProtocol_Start(protocol, binding_urls[prot], &protocol_sink, &bind_info, pi, 0);
3346 ok(hres == S_OK, "Start failed: %08x\n", hres);
3349 CHECK_CALLED(QueryService_InternetProtocol);
3350 CHECK_CALLED(CreateInstance);
3351 CHECK_CALLED(ReportProgress_PROTOCOLCLASSID);
3352 CHECK_CALLED(SetPriority);
3354 CHECK_CALLED(StartEx);
3356 CHECK_CALLED(Start);
3359 IInternetProtocolEx_Release(protocolex);
3363 if(prot == HTTP_TEST || prot == HTTPS_TEST) {
3364 while(prot_state < 4) {
3365 WaitForSingleObject(event_complete, INFINITE);
3366 if(mimefilter_test && filtered_protocol) {
3367 SET_EXPECT(Continue);
3368 IInternetProtocol_Continue(filtered_protocol, pdata);
3369 CHECK_CALLED(Continue);
3371 SET_EXPECT(Continue);
3372 IInternetProtocol_Continue(protocol, pdata);
3373 CHECK_CALLED(Continue);
3375 if(test_abort && prot_state == 2) {
3377 hres = IInternetProtocol_Abort(protocol, E_ABORT, 0);
3378 ok(hres == S_OK, "Abort failed: %08x\n", hres);
3379 CHECK_CALLED(Abort);
3381 hres = IInternetProtocol_Abort(protocol, E_ABORT, 0);
3382 ok(hres == S_OK, "Abort failed: %08x\n", hres);
3383 SetEvent(event_complete2);
3386 SetEvent(event_complete2);
3389 CHECK_CALLED(ReportData); /* Set in ReportResult */
3390 WaitForSingleObject(event_complete, INFINITE);
3393 SET_EXPECT(MimeFilter_LockRequest);
3395 SET_EXPECT(LockRequest);
3396 hres = IInternetProtocol_LockRequest(protocol, 0);
3397 ok(hres == S_OK, "LockRequest failed: %08x\n", hres);
3399 CHECK_CALLED(MimeFilter_LockRequest);
3401 CHECK_CALLED(LockRequest);
3404 SET_EXPECT(MimeFilter_UnlockRequest);
3406 SET_EXPECT(UnlockRequest);
3407 hres = IInternetProtocol_UnlockRequest(protocol);
3408 ok(hres == S_OK, "UnlockRequest failed: %08x\n", hres);
3410 CHECK_CALLED(MimeFilter_UnlockRequest);
3412 CHECK_CALLED(UnlockRequest);
3416 SET_EXPECT(MimeFilter_Terminate);
3418 SET_EXPECT(Terminate);
3419 hres = IInternetProtocol_Terminate(protocol, 0);
3420 ok(hres == S_OK, "Terminate failed: %08x\n", hres);
3422 CLEAR_CALLED(MimeFilter_Terminate);
3424 CHECK_CALLED(Terminate);
3426 if(filtered_protocol)
3427 IInternetProtocol_Release(filtered_protocol);
3428 IInternetBindInfo_Release(prot_bind_info);
3429 IInternetProtocolSink_Release(binding_sink);
3430 ref = IInternetProtocol_Release(protocol);
3431 ok(!ref, "ref=%u, expected 0\n", ref);
3433 if(test_flags & TEST_EMULATEPROT) {
3434 hres = IInternetSession_UnregisterNameSpace(session, &ClassFactory, protocol_names[prot]);
3435 ok(hres == S_OK, "UnregisterNameSpace failed: %08x\n", hres);
3438 IInternetSession_Release(session);
3441 START_TEST(protocol)
3445 hurlmon = GetModuleHandle("urlmon.dll");
3446 pCoInternetGetSession = (void*) GetProcAddress(hurlmon, "CoInternetGetSession");
3447 pReleaseBindInfo = (void*) GetProcAddress(hurlmon, "ReleaseBindInfo");
3448 pCreateUri = (void*) GetProcAddress(hurlmon, "CreateUri");
3450 if(!GetProcAddress(hurlmon, "CompareSecurityIds")) {
3451 win_skip("Various needed functions not present, too old IE\n");
3456 win_skip("CreateUri not supported\n");
3458 OleInitialize(NULL);
3460 event_complete = CreateEvent(NULL, FALSE, FALSE, NULL);
3461 event_complete2 = CreateEvent(NULL, FALSE, FALSE, NULL);
3462 event_continue = CreateEvent(NULL, FALSE, FALSE, NULL);
3463 event_continue_done = CreateEvent(NULL, FALSE, FALSE, NULL);
3464 thread_id = GetCurrentThreadId();
3466 test_file_protocol();
3467 test_http_protocol();
3468 test_https_protocol();
3469 test_ftp_protocol();
3470 test_gopher_protocol();
3472 test_CreateBinding();
3474 bindf &= ~BINDF_FROMURLMON;
3475 trace("Testing file binding (mime verification, emulate prot)...\n");
3476 test_binding(FILE_TEST, PI_MIMEVERIFICATION, TEST_EMULATEPROT);
3477 trace("Testing http binding (mime verification, emulate prot)...\n");
3478 test_binding(HTTP_TEST, PI_MIMEVERIFICATION, TEST_EMULATEPROT);
3479 trace("Testing its binding (mime verification, emulate prot)...\n");
3480 test_binding(ITS_TEST, PI_MIMEVERIFICATION, TEST_EMULATEPROT);
3481 trace("Testing http binding (mime verification, emulate prot, short read, direct read)...\n");
3482 test_binding(HTTP_TEST, PI_MIMEVERIFICATION, TEST_EMULATEPROT|TEST_SHORT_READ|TEST_DIRECT_READ);
3483 trace("Testing file binding (mime verification, emulate prot, mime filter)...\n");
3484 test_binding(FILE_TEST, PI_MIMEVERIFICATION, TEST_EMULATEPROT|TEST_FILTER);
3485 trace("Testing http binding (mime verification, emulate prot, mime filter)...\n");
3486 test_binding(HTTP_TEST, PI_MIMEVERIFICATION, TEST_EMULATEPROT|TEST_FILTER);
3487 trace("Testing http binding (mime verification, emulate prot, direct read)...\n");
3488 test_binding(HTTP_TEST, PI_MIMEVERIFICATION, TEST_EMULATEPROT|TEST_DIRECT_READ);
3489 trace("Testing http binding (mime verification, emulate prot, abort)...\n");
3490 test_binding(HTTP_TEST, PI_MIMEVERIFICATION, TEST_EMULATEPROT|TEST_ABORT);
3492 trace("Testing file binding (use IUri, mime verification, emulate prot)...\n");
3493 test_binding(FILE_TEST, PI_MIMEVERIFICATION, TEST_EMULATEPROT|TEST_USEIURI);
3494 trace("Testing file binding (use IUri, impl StartEx, mime verification, emulate prot)...\n");
3495 test_binding(FILE_TEST, PI_MIMEVERIFICATION, TEST_EMULATEPROT|TEST_USEIURI|TEST_IMPLPROTEX);
3496 trace("Testing file binding (impl StartEx, mime verification, emulate prot)...\n");
3497 test_binding(FILE_TEST, PI_MIMEVERIFICATION, TEST_EMULATEPROT|TEST_IMPLPROTEX);
3500 CloseHandle(event_complete);
3501 CloseHandle(event_complete2);
3502 CloseHandle(event_continue);
3503 CloseHandle(event_continue_done);