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_CONNECTING);
576 CLEAR_CALLED(ReportProgress_PROXYDETECTING);
578 CHECK_NOT_CALLED(ReportProgress_FINDINGRESOURCE);
579 /* IE7 does call this */
580 CLEAR_CALLED(ReportProgress_CONNECTING);
583 if(tested_protocol == FTP_TEST)
584 todo_wine CHECK_CALLED(ReportProgress_SENDINGREQUEST);
585 else if (tested_protocol != HTTPS_TEST)
586 CHECK_CALLED(ReportProgress_SENDINGREQUEST);
588 CHECK_CALLED(ReportProgress_REDIRECTING);
589 state = test_async_req ? STATE_SENDINGREQUEST : STATE_STARTDOWNLOADING;
593 case STATE_SENDINGREQUEST:
594 SET_EXPECT(Stream_Read);
595 SET_EXPECT(ReportProgress_SENDINGREQUEST);
597 case STATE_STARTDOWNLOADING:
598 if(tested_protocol == HTTP_TEST || tested_protocol == HTTPS_TEST) {
599 SET_EXPECT(OnResponse);
600 if(tested_protocol == HTTPS_TEST || test_redirect || test_abort)
601 SET_EXPECT(ReportProgress_ACCEPTRANGES);
602 SET_EXPECT(ReportProgress_MIMETYPEAVAILABLE);
603 if(bindf & BINDF_NEEDFILE)
604 SET_EXPECT(ReportProgress_CACHEFILENAMEAVAILABLE);
610 if(state != STATE_SENDINGREQUEST)
611 SET_EXPECT(ReportData);
612 hres = IInternetProtocol_Continue(async_protocol, protocol_data);
613 ok(hres == S_OK, "Continue failed: %08x\n", hres);
614 if(tested_protocol == FTP_TEST || security_problem)
615 CLEAR_CALLED(ReportData);
616 else if(state != STATE_SENDINGREQUEST)
617 CHECK_CALLED(ReportData);
620 case STATE_SENDINGREQUEST:
621 CHECK_CALLED(Stream_Read);
622 CHECK_CALLED(ReportProgress_SENDINGREQUEST);
623 state = STATE_STARTDOWNLOADING;
625 case STATE_STARTDOWNLOADING:
626 if (! security_problem)
628 state = STATE_DOWNLOADING;
629 if(tested_protocol == HTTP_TEST || tested_protocol == HTTPS_TEST) {
630 CHECK_CALLED(OnResponse);
631 if(tested_protocol == HTTPS_TEST)
632 CHECK_CALLED(ReportProgress_ACCEPTRANGES);
633 else if(test_redirect)
634 CLEAR_CALLED(ReportProgress_ACCEPTRANGES);
635 CHECK_CALLED(ReportProgress_MIMETYPEAVAILABLE);
636 if(bindf & BINDF_NEEDFILE)
637 CHECK_CALLED(ReportProgress_CACHEFILENAMEAVAILABLE);
642 security_problem = FALSE;
643 SET_EXPECT(ReportProgress_CONNECTING);
650 static HRESULT WINAPI ProtocolSink_Switch(IInternetProtocolSink *iface, PROTOCOLDATA *pProtocolData)
652 if(tested_protocol == FTP_TEST)
653 CHECK_EXPECT2(Switch);
655 CHECK_EXPECT(Switch);
657 ok(pProtocolData != NULL, "pProtocolData == NULL\n");
659 ok(pProtocolData != &protocoldata, "pProtocolData == &protocoldata\n");
660 ok(pProtocolData->grfFlags == protocoldata.grfFlags, "grfFlags wrong %x/%x\n",
661 pProtocolData->grfFlags, protocoldata.grfFlags );
662 ok(pProtocolData->dwState == protocoldata.dwState, "dwState wrong %x/%x\n",
663 pProtocolData->dwState, protocoldata.dwState );
664 ok(pProtocolData->pData == protocoldata.pData, "pData wrong %p/%p\n",
665 pProtocolData->pData, protocoldata.pData );
666 ok(pProtocolData->cbData == protocoldata.cbData, "cbData wrong %x/%x\n",
667 pProtocolData->cbData, protocoldata.cbData );
670 pdata = pProtocolData;
673 SetEvent(event_complete);
674 WaitForSingleObject(event_complete2, INFINITE);
677 continue_protdata = *pProtocolData;
678 SetEvent(event_continue);
679 WaitForSingleObject(event_continue_done, INFINITE);
681 call_continue(pProtocolData);
682 SetEvent(event_complete);
688 static HRESULT WINAPI ProtocolSink_ReportProgress(IInternetProtocolSink *iface, ULONG ulStatusCode,
689 LPCWSTR szStatusText)
691 static const WCHAR null_guid[] = {'{','0','0','0','0','0','0','0','0','-','0','0','0','0','-',
692 '0','0','0','0','-','0','0','0','0','-','0','0','0','0','0','0','0','0','0','0','0','0','}',0};
693 static const WCHAR text_plain[] = {'t','e','x','t','/','p','l','a','i','n',0};
695 switch(ulStatusCode) {
696 case BINDSTATUS_MIMETYPEAVAILABLE:
697 CHECK_EXPECT(ReportProgress_MIMETYPEAVAILABLE);
698 if(tested_protocol != FILE_TEST && tested_protocol != ITS_TEST && !mimefilter_test && (pi & PI_MIMEVERIFICATION)) {
699 if(!short_read || !direct_read)
700 CHECK_CALLED(Read); /* set in Continue */
702 CHECK_CALLED(Read2); /* set in Read */
704 ok(szStatusText != NULL, "szStatusText == NULL\n");
706 if(tested_protocol == BIND_TEST)
707 ok(szStatusText == expect_wsz, "unexpected szStatusText\n");
708 else if (http_post_test)
709 ok(lstrlenW(text_plain) <= lstrlenW(szStatusText) &&
710 !memcmp(szStatusText, text_plain, lstrlenW(text_plain)*sizeof(WCHAR)),
711 "szStatusText != text/plain\n");
712 else if(!mimefilter_test)
713 ok(lstrlenW(text_htmlW) <= lstrlenW(szStatusText) &&
714 !memcmp(szStatusText, text_htmlW, lstrlenW(text_htmlW)*sizeof(WCHAR)),
715 "szStatusText != text/html\n");
718 case BINDSTATUS_DIRECTBIND:
719 CHECK_EXPECT2(ReportProgress_DIRECTBIND);
720 ok(szStatusText == NULL, "szStatusText != NULL\n");
722 case BINDSTATUS_RAWMIMETYPE:
723 CHECK_EXPECT2(ReportProgress_RAWMIMETYPE);
724 ok(szStatusText != NULL, "szStatusText == NULL\n");
726 ok(lstrlenW(szStatusText) < lstrlenW(text_htmlW) ||
727 !memcmp(szStatusText, text_htmlW, lstrlenW(text_htmlW)*sizeof(WCHAR)),
728 "szStatusText != text/html\n");
730 case BINDSTATUS_CACHEFILENAMEAVAILABLE:
731 CHECK_EXPECT(ReportProgress_CACHEFILENAMEAVAILABLE);
732 ok(szStatusText != NULL, "szStatusText == NULL\n");
735 ok(!lstrcmpW(szStatusText, expect_wsz), "unexpected szStatusText\n");
736 else if(tested_protocol == FILE_TEST)
737 ok(!lstrcmpW(szStatusText, file_name), "szStatusText = %s\n", wine_dbgstr_w(szStatusText));
739 ok(szStatusText != NULL, "szStatusText == NULL\n");
742 case BINDSTATUS_FINDINGRESOURCE:
743 CHECK_EXPECT2(ReportProgress_FINDINGRESOURCE);
744 ok(szStatusText != NULL, "szStatusText == NULL\n");
746 case BINDSTATUS_CONNECTING:
747 CHECK_EXPECT2(ReportProgress_CONNECTING);
748 ok(szStatusText != NULL, "szStatusText == NULL\n");
750 case BINDSTATUS_SENDINGREQUEST:
751 CHECK_EXPECT2(ReportProgress_SENDINGREQUEST);
752 if(tested_protocol == FILE_TEST || tested_protocol == ITS_TEST) {
753 ok(szStatusText != NULL, "szStatusText == NULL\n");
755 ok(!*szStatusText, "wrong szStatusText\n");
758 case BINDSTATUS_VERIFIEDMIMETYPEAVAILABLE:
759 CHECK_EXPECT(ReportProgress_VERIFIEDMIMETYPEAVAILABLE);
760 ok(szStatusText != NULL, "szStatusText == NULL\n");
762 ok(!lstrcmpW(szStatusText, text_htmlW), "szStatusText != text/html\n");
764 case BINDSTATUS_PROTOCOLCLASSID:
765 CHECK_EXPECT(ReportProgress_PROTOCOLCLASSID);
766 ok(szStatusText != NULL, "szStatusText == NULL\n");
767 ok(!lstrcmpW(szStatusText, null_guid), "unexpected classid %s\n", wine_dbgstr_w(szStatusText));
769 case BINDSTATUS_COOKIE_SENT:
770 CHECK_EXPECT(ReportProgress_COOKIE_SENT);
771 ok(szStatusText == NULL, "szStatusText != NULL\n");
773 case BINDSTATUS_REDIRECTING:
774 CHECK_EXPECT(ReportProgress_REDIRECTING);
776 ok(!strcmp_wa(szStatusText, "http://test.winehq.org/tests/hello.html"), "szStatusText = %s\n", wine_dbgstr_w(szStatusText));
778 ok(szStatusText == NULL, "szStatusText = %s\n", wine_dbgstr_w(szStatusText));
780 case BINDSTATUS_ENCODING:
781 CHECK_EXPECT(ReportProgress_ENCODING);
782 ok(!strcmp_wa(szStatusText, "gzip"), "szStatusText = %s\n", wine_dbgstr_w(szStatusText));
784 case BINDSTATUS_ACCEPTRANGES:
785 CHECK_EXPECT(ReportProgress_ACCEPTRANGES);
786 ok(!szStatusText, "szStatusText = %s\n", wine_dbgstr_w(szStatusText));
788 case BINDSTATUS_PROXYDETECTING:
789 CHECK_EXPECT(ReportProgress_PROXYDETECTING);
790 SET_EXPECT(ReportProgress_CONNECTING);
791 ok(!szStatusText, "szStatusText = %s\n", wine_dbgstr_w(szStatusText));
793 case BINDSTATUS_LOADINGMIMEHANDLER:
794 CHECK_EXPECT(ReportProgress_LOADINGMIMEHANDLER);
795 ok(!szStatusText, "szStatusText = %s\n", wine_dbgstr_w(szStatusText));
797 case BINDSTATUS_DECODING:
798 CHECK_EXPECT(ReportProgress_DECODING);
799 ok(!lstrcmpW(szStatusText, gzipW), "szStatusText = %s\n", wine_dbgstr_w(szStatusText));
802 ok(0, "Unexpected status %d\n", ulStatusCode);
808 static HRESULT WINAPI ProtocolSink_ReportData(IInternetProtocolSink *iface, DWORD grfBSCF,
809 ULONG ulProgress, ULONG ulProgressMax)
813 static int rec_depth;
816 if(!mimefilter_test && (tested_protocol == FILE_TEST || tested_protocol == ITS_TEST)) {
817 CHECK_EXPECT2(ReportData);
819 ok(ulProgress == ulProgressMax, "ulProgress (%d) != ulProgressMax (%d)\n",
820 ulProgress, ulProgressMax);
821 ok(ulProgressMax == 13, "ulProgressMax=%d, expected 13\n", ulProgressMax);
822 /* BSCF_SKIPDRAINDATAFORFILEURLS added in IE8 */
823 if(tested_protocol == FILE_TEST)
824 ok((grfBSCF == (BSCF_FIRSTDATANOTIFICATION | BSCF_LASTDATANOTIFICATION)) ||
825 (grfBSCF == (BSCF_FIRSTDATANOTIFICATION | BSCF_LASTDATANOTIFICATION | BSCF_SKIPDRAINDATAFORFILEURLS)),
826 "grcfBSCF = %08x\n", grfBSCF);
828 ok(grfBSCF == (BSCF_FIRSTDATANOTIFICATION | BSCF_DATAFULLYAVAILABLE), "grcfBSCF = %08x\n", grfBSCF);
829 }else if(direct_read) {
833 if(!read_report_data && rec_depth == 1) {
834 BOOL reported_all_data = called_ReportData2;
836 CHECK_EXPECT2(ReportData);
839 ok(grfBSCF == (BSCF_FIRSTDATANOTIFICATION|BSCF_LASTDATANOTIFICATION|BSCF_DATAFULLYAVAILABLE)
840 || grfBSCF == BSCF_FIRSTDATANOTIFICATION, /* < IE8 */
841 "grcfBSCF = %08x\n", grfBSCF);
842 CHECK_CALLED(Read); /* Set in Continue */
843 first_data_notif = FALSE;
844 }else if(first_data_notif) {
845 ok(grfBSCF == BSCF_FIRSTDATANOTIFICATION, "grcfBSCF = %08x\n", grfBSCF);
846 first_data_notif = FALSE;
847 }else if(reported_all_data) {
848 ok(grfBSCF == (BSCF_LASTDATANOTIFICATION|BSCF_INTERMEDIATEDATANOTIFICATION),
849 "grcfBSCF = %08x\n", grfBSCF);
850 }else if(!direct_read) {
851 ok(grfBSCF == BSCF_INTERMEDIATEDATANOTIFICATION, "grcfBSCF = %08x\n", grfBSCF);
859 SET_EXPECT(ReportData2);
860 SET_EXPECT(ReportResult);
863 hres = IInternetProtocol_Read(binding_test ? binding_protocol : async_protocol, expect_pv = buf, sizeof(buf), &read);
864 ok(hres == E_PENDING || hres == S_FALSE || hres == S_OK, "Read failed: %08x\n", hres);
866 ok(read, "read == 0\n");
867 if(reported_all_data)
868 ok(hres == S_FALSE, "Read failed: %08x, expected S_FALSE\n", hres);
869 if(!emulate_prot && hres != E_PENDING)
870 CHECK_NOT_CALLED(Switch); /* otherwise checked in wait_for_switch loop */
873 if(!reported_all_data && called_ReportData2) {
875 CHECK_CALLED(ReportData2);
876 CHECK_CALLED(ReportResult);
877 ok(hres == S_OK, "Read failed: %08x\n", hres);
878 reported_all_data = TRUE;
881 CHECK_NOT_CALLED(ReportData2);
882 CHECK_NOT_CALLED(ReportResult);
884 }while(hres == S_OK);
886 wait_for_switch = FALSE;
888 CHECK_EXPECT(ReportData2);
890 ok(grfBSCF & BSCF_LASTDATANOTIFICATION, "grfBSCF = %08x\n", grfBSCF);
895 hres = IInternetProtocol_Read(binding_test ? binding_protocol : async_protocol, expect_pv = buf, sizeof(buf), &read);
898 ok(hres == S_FALSE, "Read returned: %08x, expected E_FALSE\n", hres);
899 ok(!read, "read = %d\n", read);
901 }else if(!binding_test && (tested_protocol == HTTP_TEST || tested_protocol == HTTPS_TEST
902 || tested_protocol == FTP_TEST)) {
903 if(!(grfBSCF & BSCF_LASTDATANOTIFICATION) || (grfBSCF & BSCF_DATAFULLYAVAILABLE))
904 CHECK_EXPECT(ReportData);
905 else if (http_post_test)
906 ok(ulProgress == 13, "Read %u bytes instead of 13\n", ulProgress);
908 ok(ulProgress, "ulProgress == 0\n");
910 if(first_data_notif) {
911 ok(grfBSCF == BSCF_FIRSTDATANOTIFICATION
912 || grfBSCF == (BSCF_LASTDATANOTIFICATION|BSCF_DATAFULLYAVAILABLE),
913 "grcfBSCF = %08x\n", grfBSCF);
914 first_data_notif = FALSE;
916 ok(grfBSCF == BSCF_INTERMEDIATEDATANOTIFICATION
917 || grfBSCF == (BSCF_LASTDATANOTIFICATION|BSCF_INTERMEDIATEDATANOTIFICATION)
918 || broken(grfBSCF == (BSCF_FIRSTDATANOTIFICATION|BSCF_LASTDATANOTIFICATION)),
919 "grcfBSCF = %08x\n", grfBSCF);
922 if(!(bindf & BINDF_FROMURLMON) &&
923 !(grfBSCF & BSCF_LASTDATANOTIFICATION)) {
924 if(state == STATE_CONNECTING) {
925 state = STATE_DOWNLOADING;
927 CHECK_CALLED(ReportProgress_FINDINGRESOURCE);
928 CHECK_CALLED(ReportProgress_CONNECTING);
930 CHECK_NOT_CALLED(ReportProgress_FINDINGRESOURCE);
931 CHECK_NOT_CALLED(ReportProgress_CONNECTING);
933 CHECK_CALLED(ReportProgress_SENDINGREQUEST);
934 CHECK_CALLED(OnResponse);
935 CHECK_CALLED(ReportProgress_RAWMIMETYPE);
937 SetEvent(event_complete);
939 }else if(!read_report_data) {
944 CHECK_EXPECT(ReportData);
946 if(tested_protocol != BIND_TEST) {
949 SET_EXPECT(MimeFilter_Read);
950 else if(rec_depth > 1)
954 hres = IInternetProtocol_Read(binding_protocol, expect_pv=buf, sizeof(buf), &read);
956 CHECK_CALLED(MimeFilter_Read);
957 else if(rec_depth > 1)
961 }while(hres == S_OK);
969 static HRESULT WINAPI ProtocolSink_ReportResult(IInternetProtocolSink *iface, HRESULT hrResult,
970 DWORD dwError, LPCWSTR szResult)
972 CHECK_EXPECT(ReportResult);
974 if(tested_protocol == FTP_TEST)
975 ok(hrResult == E_PENDING || hrResult == S_OK, "hrResult = %08x, expected E_PENDING or S_OK\n", hrResult);
977 ok(hrResult == expect_hrResult, "hrResult = %08x, expected: %08x\n",
978 hrResult, expect_hrResult);
979 if(SUCCEEDED(hrResult) || tested_protocol == FTP_TEST || test_abort)
980 ok(dwError == ERROR_SUCCESS, "dwError = %d, expected ERROR_SUCCESS\n", dwError);
982 ok(dwError != ERROR_SUCCESS ||
983 broken(tested_protocol == MK_TEST), /* WinME and NT4 */
984 "dwError == ERROR_SUCCESS\n");
985 ok(!szResult, "szResult != NULL\n");
988 SET_EXPECT(ReportData); /* checked after main loop */
993 static IInternetProtocolSinkVtbl protocol_sink_vtbl = {
994 ProtocolSink_QueryInterface,
996 ProtocolSink_Release,
998 ProtocolSink_ReportProgress,
999 ProtocolSink_ReportData,
1000 ProtocolSink_ReportResult
1003 static IInternetProtocolSink protocol_sink = { &protocol_sink_vtbl };
1005 static HRESULT WINAPI MimeProtocolSink_QueryInterface(IInternetProtocolSink *iface, REFIID riid, void **ppv)
1007 ok(0, "unexpected call\n");
1011 static ULONG WINAPI MimeProtocolSink_AddRef(IInternetProtocolSink *iface)
1016 static ULONG WINAPI MimeProtocolSink_Release(IInternetProtocolSink *iface)
1021 static HRESULT WINAPI MimeProtocolSink_Switch(IInternetProtocolSink *iface, PROTOCOLDATA *pProtocolData)
1025 CHECK_EXPECT(MimeFilter_Switch);
1028 hres = IInternetProtocolSink_Switch(filtered_sink, pProtocolData);
1029 ok(hres == S_OK, "Switch failed: %08x\n", hres);
1030 CHECK_CALLED(Switch);
1035 static HRESULT WINAPI MimeProtocolSink_ReportProgress(IInternetProtocolSink *iface, ULONG ulStatusCode,
1036 LPCWSTR szStatusText)
1038 CHECK_EXPECT(MimeFilter_ReportProgress);
1042 static HRESULT WINAPI MimeProtocolSink_ReportData(IInternetProtocolSink *iface, DWORD grfBSCF,
1043 ULONG ulProgress, ULONG ulProgressMax)
1049 CHECK_EXPECT(MimeFilter_ReportData);
1053 hres = IInternetProtocol_Read(filtered_protocol, buf, sizeof(buf), &read);
1054 if(tested_protocol == HTTP_TEST)
1055 ok(hres == S_OK || hres == E_PENDING || hres == S_FALSE, "Read failed: %08x\n", hres);
1057 ok(hres == S_OK, "Read failed: %08x\n", hres);
1060 SET_EXPECT(ReportProgress_MIMETYPEAVAILABLE);
1061 hres = IInternetProtocolSink_ReportProgress(filtered_sink, BINDSTATUS_VERIFIEDMIMETYPEAVAILABLE, text_htmlW);
1062 ok(hres == S_OK, "ReportProgress failed: %08x\n", hres);
1063 CHECK_CALLED(ReportProgress_MIMETYPEAVAILABLE);
1065 /* FIXME: test BINDSTATUS_CACHEFILENAMEAVAILABLE */
1068 if(!read_report_data)
1069 SET_EXPECT(ReportData);
1070 hres = IInternetProtocolSink_ReportData(filtered_sink, grfBSCF, ulProgress, ulProgressMax);
1071 ok(hres == S_OK, "ReportData failed: %08x\n", hres);
1072 if(!read_report_data)
1073 CHECK_CALLED(ReportData);
1081 static HRESULT WINAPI MimeProtocolSink_ReportResult(IInternetProtocolSink *iface, HRESULT hrResult,
1082 DWORD dwError, LPCWSTR szResult)
1086 CHECK_EXPECT(MimeFilter_ReportResult);
1088 ok(hrResult == S_OK, "hrResult = %08x\n", hrResult);
1089 ok(dwError == ERROR_SUCCESS, "dwError = %u\n", dwError);
1090 ok(!szResult, "szResult = %s\n", wine_dbgstr_w(szResult));
1092 SET_EXPECT(ReportResult);
1093 hres = IInternetProtocolSink_ReportResult(filtered_sink, hrResult, dwError, szResult);
1094 ok(SUCCEEDED(hres), "ReportResult failed: %08x\n", hres);
1095 CHECK_CALLED(ReportResult);
1100 static IInternetProtocolSinkVtbl mime_protocol_sink_vtbl = {
1101 MimeProtocolSink_QueryInterface,
1102 MimeProtocolSink_AddRef,
1103 MimeProtocolSink_Release,
1104 MimeProtocolSink_Switch,
1105 MimeProtocolSink_ReportProgress,
1106 MimeProtocolSink_ReportData,
1107 MimeProtocolSink_ReportResult
1110 static IInternetProtocolSink mime_protocol_sink = { &mime_protocol_sink_vtbl };
1112 static HRESULT QueryInterface(REFIID riid, void **ppv)
1114 static const IID IID_undocumented = {0x58DFC7D0,0x5381,0x43E5,{0x9D,0x72,0x4C,0xDD,0xE4,0xCB,0x0F,0x1A}};
1118 if(IsEqualGUID(&IID_IUnknown, riid) || IsEqualGUID(&IID_IInternetProtocolSink, riid))
1119 *ppv = &protocol_sink;
1120 if(IsEqualGUID(&IID_IServiceProvider, riid))
1121 *ppv = &service_provider;
1122 if(IsEqualGUID(&IID_IUriContainer, riid))
1123 return E_NOINTERFACE; /* TODO */
1125 /* NOTE: IE8 queries for undocumented {58DFC7D0-5381-43E5-9D72-4CDDE4CB0F1A} interface. */
1126 if(IsEqualGUID(&IID_undocumented, riid))
1127 return E_NOINTERFACE;
1132 ok(0, "unexpected call %s\n", debugstr_guid(riid));
1133 return E_NOINTERFACE;
1136 static HRESULT WINAPI BindInfo_QueryInterface(IInternetBindInfo *iface, REFIID riid, void **ppv)
1138 if(IsEqualGUID(&IID_IUnknown, riid) || IsEqualGUID(&IID_IInternetBindInfo, riid)) {
1142 return E_NOINTERFACE;
1145 static ULONG WINAPI BindInfo_AddRef(IInternetBindInfo *iface)
1150 static ULONG WINAPI BindInfo_Release(IInternetBindInfo *iface)
1155 static HRESULT WINAPI BindInfo_GetBindInfo(IInternetBindInfo *iface, DWORD *grfBINDF, BINDINFO *pbindinfo)
1159 CHECK_EXPECT(GetBindInfo);
1161 ok(grfBINDF != NULL, "grfBINDF == NULL\n");
1162 ok(pbindinfo != NULL, "pbindinfo == NULL\n");
1163 ok(pbindinfo->cbSize == sizeof(BINDINFO), "wrong size of pbindinfo: %d\n", pbindinfo->cbSize);
1167 *grfBINDF |= BINDF_FROMURLMON;
1168 cbSize = pbindinfo->cbSize;
1169 memset(pbindinfo, 0, cbSize);
1170 pbindinfo->cbSize = cbSize;
1174 pbindinfo->cbstgmedData = sizeof(post_data)-1;
1175 pbindinfo->dwBindVerb = BINDVERB_POST;
1176 pbindinfo->stgmedData.tymed = http_post_test;
1178 if(http_post_test == TYMED_HGLOBAL) {
1181 /* Must be GMEM_FIXED, GMEM_MOVABLE does not work properly */
1182 data = GlobalAlloc(GPTR, sizeof(post_data));
1183 memcpy(data, post_data, sizeof(post_data));
1184 U(pbindinfo->stgmedData).hGlobal = data;
1186 IStream *post_stream;
1191 /* Must be GMEM_FIXED, GMEM_MOVABLE does not work properly */
1192 data = GlobalAlloc(GPTR, sizeof(post_data));
1193 memcpy(data, post_data, sizeof(post_data));
1194 U(pbindinfo->stgmedData).hGlobal = data;
1196 hres = CreateStreamOnHGlobal(data, FALSE, &post_stream);
1197 ok(hres == S_OK, "CreateStreamOnHGlobal failed: %08x\n", hres);
1199 U(pbindinfo->stgmedData).pstm =post_stream;/* &Stream; */
1201 U(pbindinfo->stgmedData).pstm = &Stream;
1208 static HRESULT WINAPI BindInfo_GetBindString(IInternetBindInfo *iface, ULONG ulStringType,
1209 LPOLESTR *ppwzStr, ULONG cEl, ULONG *pcElFetched)
1211 ok(ppwzStr != NULL, "ppwzStr == NULL\n");
1212 ok(pcElFetched != NULL, "pcElFetched == NULL\n");
1214 switch(ulStringType) {
1215 case BINDSTRING_ACCEPT_MIMES:
1216 CHECK_EXPECT(GetBindString_ACCEPT_MIMES);
1217 ok(cEl == 256, "cEl=%d, expected 256\n", cEl);
1219 ok(*pcElFetched == 256, "*pcElFetched=%d, expected 256\n", *pcElFetched);
1223 *ppwzStr = CoTaskMemAlloc(sizeof(acc_mimeW));
1224 memcpy(*ppwzStr, acc_mimeW, sizeof(acc_mimeW));
1227 case BINDSTRING_USER_AGENT:
1228 CHECK_EXPECT(GetBindString_USER_AGENT);
1229 ok(cEl == 1, "cEl=%d, expected 1\n", cEl);
1231 ok(*pcElFetched == 0, "*pcElFetch=%d, expectd 0\n", *pcElFetched);
1235 *ppwzStr = CoTaskMemAlloc(sizeof(user_agentW));
1236 memcpy(*ppwzStr, user_agentW, sizeof(user_agentW));
1239 case BINDSTRING_POST_COOKIE:
1240 CHECK_EXPECT(GetBindString_POST_COOKIE);
1241 ok(cEl == 1, "cEl=%d, expected 1\n", cEl);
1243 ok(*pcElFetched == 0, "*pcElFetch=%d, expectd 0\n", *pcElFetched);
1245 case BINDSTRING_URL: {
1248 CHECK_EXPECT(GetBindString_URL);
1249 ok(cEl == 1, "cEl=%d, expected 1\n", cEl);
1250 ok(*pcElFetched == 0, "*pcElFetch=%d, expectd 0\n", *pcElFetched);
1253 size = (lstrlenW(binding_urls[tested_protocol])+1)*sizeof(WCHAR);
1254 *ppwzStr = CoTaskMemAlloc(size);
1255 memcpy(*ppwzStr, binding_urls[tested_protocol], size);
1259 ok(0, "unexpected call\n");
1265 static IInternetBindInfoVtbl bind_info_vtbl = {
1266 BindInfo_QueryInterface,
1269 BindInfo_GetBindInfo,
1270 BindInfo_GetBindString
1273 static IInternetBindInfo bind_info = { &bind_info_vtbl };
1275 static HRESULT WINAPI InternetPriority_QueryInterface(IInternetPriority *iface,
1276 REFIID riid, void **ppv)
1278 ok(0, "unexpected call\n");
1279 return E_NOINTERFACE;
1282 static ULONG WINAPI InternetPriority_AddRef(IInternetPriority *iface)
1287 static ULONG WINAPI InternetPriority_Release(IInternetPriority *iface)
1292 static HRESULT WINAPI InternetPriority_SetPriority(IInternetPriority *iface, LONG nPriority)
1294 CHECK_EXPECT(SetPriority);
1295 ok(nPriority == ex_priority, "nPriority=%d\n", nPriority);
1299 static HRESULT WINAPI InternetPriority_GetPriority(IInternetPriority *iface, LONG *pnPriority)
1301 ok(0, "unexpected call\n");
1306 static const IInternetPriorityVtbl InternetPriorityVtbl = {
1307 InternetPriority_QueryInterface,
1308 InternetPriority_AddRef,
1309 InternetPriority_Release,
1310 InternetPriority_SetPriority,
1311 InternetPriority_GetPriority
1314 static IInternetPriority InternetPriority = { &InternetPriorityVtbl };
1316 static ULONG WINAPI Protocol_AddRef(IInternetProtocolEx *iface)
1321 static ULONG WINAPI Protocol_Release(IInternetProtocolEx *iface)
1326 static HRESULT WINAPI Protocol_Abort(IInternetProtocolEx *iface, HRESULT hrReason,
1331 CHECK_EXPECT(Abort);
1333 SET_EXPECT(ReportResult);
1334 hres = IInternetProtocolSink_ReportResult(binding_sink, S_OK, ERROR_SUCCESS, NULL);
1335 ok(hres == S_OK, "ReportResult failed: %08x\n", hres);
1336 CHECK_CALLED(ReportResult);
1341 static HRESULT WINAPI Protocol_Suspend(IInternetProtocolEx *iface)
1343 ok(0, "unexpected call\n");
1347 static HRESULT WINAPI Protocol_Resume(IInternetProtocolEx *iface)
1349 ok(0, "unexpected call\n");
1353 static HRESULT WINAPI Protocol_Seek(IInternetProtocolEx *iface,
1354 LARGE_INTEGER dlibMove, DWORD dwOrigin, ULARGE_INTEGER *plibNewPosition)
1356 ok(0, "unexpected call\n");
1360 static HRESULT WINAPI ProtocolEmul_QueryInterface(IInternetProtocolEx *iface, REFIID riid, void **ppv)
1362 if(IsEqualGUID(&IID_IUnknown, riid) || IsEqualGUID(&IID_IInternetProtocol, riid)) {
1367 if(IsEqualGUID(&IID_IInternetProtocolEx, riid)) {
1373 return E_NOINTERFACE;
1376 if(IsEqualGUID(&IID_IInternetPriority, riid)) {
1377 *ppv = &InternetPriority;
1381 if(IsEqualGUID(&IID_IWinInetInfo, riid)) {
1382 CHECK_EXPECT(QueryInterface_IWinInetInfo);
1384 return E_NOINTERFACE;
1387 if(IsEqualGUID(&IID_IWinInetHttpInfo, riid)) {
1388 CHECK_EXPECT(QueryInterface_IWinInetHttpInfo);
1390 return E_NOINTERFACE;
1393 ok(0, "unexpected riid %s\n", debugstr_guid(riid));
1395 return E_NOINTERFACE;
1398 static DWORD WINAPI thread_proc(PVOID arg)
1402 memset(&protocoldata, -1, sizeof(protocoldata));
1406 SET_EXPECT(ReportProgress_FINDINGRESOURCE);
1407 hres = IInternetProtocolSink_ReportProgress(binding_sink,
1408 BINDSTATUS_FINDINGRESOURCE, hostW);
1409 CHECK_CALLED(ReportProgress_FINDINGRESOURCE);
1410 ok(hres == S_OK, "ReportProgress failed: %08x\n", hres);
1412 SET_EXPECT(ReportProgress_CONNECTING);
1413 hres = IInternetProtocolSink_ReportProgress(binding_sink,
1414 BINDSTATUS_CONNECTING, winehq_ipW);
1415 CHECK_CALLED(ReportProgress_CONNECTING);
1416 ok(hres == S_OK, "ReportProgress failed: %08x\n", hres);
1418 SET_EXPECT(ReportProgress_SENDINGREQUEST);
1419 hres = IInternetProtocolSink_ReportProgress(binding_sink,
1420 BINDSTATUS_SENDINGREQUEST, NULL);
1421 CHECK_CALLED(ReportProgress_SENDINGREQUEST);
1422 ok(hres == S_OK, "ReportProgress failed: %08x\n", hres);
1426 hres = IInternetProtocolSink_Switch(binding_sink, &protocoldata);
1427 CHECK_CALLED(Switch);
1428 ok(hres == S_OK, "Switch failed: %08x\n", hres);
1433 SET_EXPECT(MimeFilter_Switch);
1436 hres = IInternetProtocolSink_Switch(binding_sink, &protocoldata);
1437 ok(hres == S_OK, "Switch failed: %08x\n", hres);
1439 CHECK_CALLED(MimeFilter_Switch);
1441 CHECK_CALLED(Switch);
1444 SetEvent(event_complete);
1450 SET_EXPECT(MimeFilter_Switch);
1453 hres = IInternetProtocolSink_Switch(binding_sink, &protocoldata);
1454 ok(hres == S_OK, "Switch failed: %08x\n", hres);
1456 CHECK_CALLED(MimeFilter_Switch);
1458 CHECK_CALLED(Switch);
1462 SET_EXPECT(MimeFilter_Switch);
1465 hres = IInternetProtocolSink_Switch(binding_sink, &protocoldata);
1466 ok(hres == S_OK, "Switch failed: %08x\n", hres);
1468 CHECK_CALLED(MimeFilter_Switch);
1470 CHECK_CALLED(Switch);
1473 SetEvent(event_complete);
1478 static void protocol_start(IInternetProtocolSink *pOIProtSink, IInternetBindInfo *pOIBindInfo, DWORD pi)
1480 BINDINFO bindinfo, exp_bindinfo;
1484 ok(pOIProtSink != NULL, "pOIProtSink == NULL\n");
1485 ok(pOIBindInfo != NULL, "pOIBindInfo == NULL\n");
1486 ok(pOIProtSink != &protocol_sink, "unexpected pOIProtSink\n");
1487 ok(pOIBindInfo != &bind_info, "unexpected pOIBindInfo\n");
1488 ok(!pi, "pi = %x\n", pi);
1491 ok(pOIProtSink == binding_sink, "pOIProtSink != binding_sink\n");
1493 memset(&bindinfo, 0, sizeof(bindinfo));
1494 bindinfo.cbSize = sizeof(bindinfo);
1495 memcpy(&exp_bindinfo, &bindinfo, sizeof(bindinfo));
1496 SET_EXPECT(GetBindInfo);
1497 hres = IInternetBindInfo_GetBindInfo(pOIBindInfo, &cbindf, &bindinfo);
1498 ok(hres == S_OK, "GetBindInfo failed: %08x\n", hres);
1499 CHECK_CALLED(GetBindInfo);
1500 ok(cbindf == (bindf|BINDF_FROMURLMON), "bindf = %x, expected %x\n",
1501 cbindf, (bindf|BINDF_FROMURLMON));
1502 ok(!memcmp(&exp_bindinfo, &bindinfo, sizeof(bindinfo)), "unexpected bindinfo\n");
1503 pReleaseBindInfo(&bindinfo);
1505 SET_EXPECT(ReportProgress_SENDINGREQUEST);
1506 hres = IInternetProtocolSink_ReportProgress(pOIProtSink, BINDSTATUS_SENDINGREQUEST, emptyW);
1507 ok(hres == S_OK, "ReportProgress(BINDSTATUS_SENDINGREQUEST) failed: %08x\n", hres);
1508 CHECK_CALLED(ReportProgress_SENDINGREQUEST);
1510 if(tested_protocol == HTTP_TEST || tested_protocol == HTTPS_TEST) {
1511 IServiceProvider *service_provider;
1512 IHttpNegotiate *http_negotiate;
1513 IHttpNegotiate2 *http_negotiate2;
1514 LPWSTR ua = (LPWSTR)0xdeadbeef, accept_mimes[256];
1515 LPWSTR additional_headers = NULL;
1517 DWORD fetched = 0, size = 100;
1520 SET_EXPECT(GetBindString_USER_AGENT);
1521 hres = IInternetBindInfo_GetBindString(pOIBindInfo, BINDSTRING_USER_AGENT,
1523 CHECK_CALLED(GetBindString_USER_AGENT);
1524 ok(hres == S_OK, "GetBindString(BINDSTRING_USER_AGETNT) failed: %08x\n", hres);
1525 ok(fetched == 1, "fetched = %d, expected 254\n", fetched);
1526 ok(ua != NULL, "ua = %p\n", ua);
1527 ok(!lstrcmpW(ua, user_agentW), "unexpected user agent %s\n", wine_dbgstr_w(ua));
1531 SET_EXPECT(GetBindString_ACCEPT_MIMES);
1532 hres = IInternetBindInfo_GetBindString(pOIBindInfo, BINDSTRING_ACCEPT_MIMES,
1533 accept_mimes, 256, &fetched);
1534 CHECK_CALLED(GetBindString_ACCEPT_MIMES);
1537 "GetBindString(BINDSTRING_ACCEPT_MIMES) failed: %08x\n", hres);
1538 ok(fetched == 1, "fetched = %d, expected 1\n", fetched);
1539 ok(!lstrcmpW(acc_mimeW, accept_mimes[0]), "unexpected mimes %s\n", wine_dbgstr_w(accept_mimes[0]));
1540 CoTaskMemFree(accept_mimes[0]);
1542 hres = IInternetBindInfo_QueryInterface(pOIBindInfo, &IID_IServiceProvider,
1543 (void**)&service_provider);
1544 ok(hres == S_OK, "QueryInterface failed: %08x\n", hres);
1546 SET_EXPECT(QueryService_HttpNegotiate);
1547 hres = IServiceProvider_QueryService(service_provider, &IID_IHttpNegotiate,
1548 &IID_IHttpNegotiate, (void**)&http_negotiate);
1549 CHECK_CALLED(QueryService_HttpNegotiate);
1550 ok(hres == S_OK, "QueryService failed: %08x\n", hres);
1552 SET_EXPECT(BeginningTransaction);
1553 hres = IHttpNegotiate_BeginningTransaction(http_negotiate, binding_urls[tested_protocol],
1554 NULL, 0, &additional_headers);
1555 CHECK_CALLED(BeginningTransaction);
1556 IHttpNegotiate_Release(http_negotiate);
1557 ok(hres == S_OK, "BeginningTransction failed: %08x\n", hres);
1558 ok(additional_headers == NULL, "additional_headers=%p\n", additional_headers);
1560 SET_EXPECT(QueryService_HttpNegotiate);
1561 hres = IServiceProvider_QueryService(service_provider, &IID_IHttpNegotiate2,
1562 &IID_IHttpNegotiate2, (void**)&http_negotiate2);
1563 CHECK_CALLED(QueryService_HttpNegotiate);
1564 ok(hres == S_OK, "QueryService failed: %08x\n", hres);
1567 SET_EXPECT(GetRootSecurityId);
1568 hres = IHttpNegotiate2_GetRootSecurityId(http_negotiate2, sec_id, &size, 0);
1569 CHECK_CALLED(GetRootSecurityId);
1570 IHttpNegotiate2_Release(http_negotiate2);
1571 ok(hres == E_FAIL, "GetRootSecurityId failed: %08x, expected E_FAIL\n", hres);
1572 ok(size == 13, "size=%d\n", size);
1574 IServiceProvider_Release(service_provider);
1576 CreateThread(NULL, 0, thread_proc, NULL, 0, &tid);
1580 SET_EXPECT(ReportProgress_CACHEFILENAMEAVAILABLE);
1581 hres = IInternetProtocolSink_ReportProgress(pOIProtSink,
1582 BINDSTATUS_CACHEFILENAMEAVAILABLE, expect_wsz = emptyW);
1583 ok(hres == S_OK, "ReportProgress(BINDSTATUS_CACHEFILENAMEAVAILABLE) failed: %08x\n", hres);
1584 CHECK_CALLED(ReportProgress_CACHEFILENAMEAVAILABLE);
1586 if(mimefilter_test) {
1587 SET_EXPECT(MimeFilter_CreateInstance);
1588 SET_EXPECT(MimeFilter_Start);
1589 SET_EXPECT(ReportProgress_LOADINGMIMEHANDLER);
1591 SET_EXPECT(ReportProgress_MIMETYPEAVAILABLE);
1592 hres = IInternetProtocolSink_ReportProgress(pOIProtSink, BINDSTATUS_VERIFIEDMIMETYPEAVAILABLE,
1593 mimefilter_test ? gzipW : (expect_wsz = text_htmlW));
1595 "ReportProgress(BINDSTATUS_VERIFIEDMIMETYPEAVAILABLE) failed: %08x\n", hres);
1596 if(mimefilter_test) {
1597 CHECK_CALLED(MimeFilter_CreateInstance);
1598 CHECK_CALLED(MimeFilter_Start);
1599 CHECK_CALLED(ReportProgress_LOADINGMIMEHANDLER);
1600 todo_wine CHECK_CALLED(ReportProgress_MIMETYPEAVAILABLE);
1602 CHECK_CALLED(ReportProgress_MIMETYPEAVAILABLE);
1606 SET_EXPECT(MimeFilter_ReportData);
1608 SET_EXPECT(ReportData);
1609 hres = IInternetProtocolSink_ReportData(pOIProtSink,
1610 BSCF_FIRSTDATANOTIFICATION | (tested_protocol == ITS_TEST ? BSCF_DATAFULLYAVAILABLE : BSCF_LASTDATANOTIFICATION),
1612 ok(hres == S_OK, "ReportData failed: %08x\n", hres);
1614 CHECK_CALLED(MimeFilter_ReportData);
1616 CHECK_CALLED(ReportData);
1618 if(tested_protocol == ITS_TEST) {
1619 SET_EXPECT(ReportData);
1620 hres = IInternetProtocolSink_ReportProgress(pOIProtSink, BINDSTATUS_BEGINDOWNLOADDATA, NULL);
1621 ok(hres == S_OK, "ReportProgress(BINDSTATUS_BEGINDOWNLOADDATA) failed: %08x\n", hres);
1622 CHECK_CALLED(ReportData);
1625 if(tested_protocol == BIND_TEST) {
1626 hres = IInternetProtocol_Terminate(binding_protocol, 0);
1627 ok(hres == E_FAIL, "Termiante failed: %08x\n", hres);
1631 SET_EXPECT(MimeFilter_ReportResult);
1633 SET_EXPECT(ReportResult);
1634 hres = IInternetProtocolSink_ReportResult(pOIProtSink, S_OK, 0, NULL);
1635 ok(hres == S_OK, "ReportResult failed: %08x\n", hres);
1637 CHECK_CALLED(MimeFilter_ReportResult);
1639 CHECK_CALLED(ReportResult);
1642 static HRESULT WINAPI ProtocolEmul_Start(IInternetProtocolEx *iface, LPCWSTR szUrl,
1643 IInternetProtocolSink *pOIProtSink, IInternetBindInfo *pOIBindInfo,
1644 DWORD grfPI, HANDLE_PTR dwReserved)
1646 CHECK_EXPECT(Start);
1648 ok(!dwReserved, "dwReserved = %lx\n", dwReserved);
1649 protocol_start(pOIProtSink, pOIBindInfo, grfPI);
1653 static HRESULT WINAPI ProtocolEmul_Continue(IInternetProtocolEx *iface,
1654 PROTOCOLDATA *pProtocolData)
1659 CHECK_EXPECT(Continue);
1661 ok(pProtocolData != NULL, "pProtocolData == NULL\n");
1662 if(!pProtocolData || tested_protocol == BIND_TEST)
1665 ok(pProtocolData != &protocoldata, "pProtocolData == &protocoldata\n");
1666 ok(pProtocolData->grfFlags == protocoldata.grfFlags, "grfFlags wrong %x/%x\n",
1667 pProtocolData->grfFlags, protocoldata.grfFlags );
1668 ok(pProtocolData->dwState == protocoldata.dwState, "dwState wrong %x/%x\n",
1669 pProtocolData->dwState, protocoldata.dwState );
1670 ok(pProtocolData->pData == protocoldata.pData, "pData wrong %p/%p\n",
1671 pProtocolData->pData, protocoldata.pData );
1672 ok(pProtocolData->cbData == protocoldata.cbData, "cbData wrong %x/%x\n",
1673 pProtocolData->cbData, protocoldata.cbData );
1676 switch(prot_state) {
1678 IServiceProvider *service_provider;
1679 IHttpNegotiate *http_negotiate;
1680 static WCHAR header[] = {'?',0};
1682 hres = IInternetProtocolSink_QueryInterface(binding_sink, &IID_IServiceProvider,
1683 (void**)&service_provider);
1684 ok(hres == S_OK, "Could not get IServiceProvicder\n");
1686 SET_EXPECT(QueryService_HttpNegotiate);
1687 hres = IServiceProvider_QueryService(service_provider, &IID_IHttpNegotiate,
1688 &IID_IHttpNegotiate, (void**)&http_negotiate);
1689 IServiceProvider_Release(service_provider);
1690 CHECK_CALLED(QueryService_HttpNegotiate);
1691 ok(hres == S_OK, "Could not get IHttpNegotiate\n");
1693 SET_EXPECT(OnResponse);
1694 hres = IHttpNegotiate_OnResponse(http_negotiate, 200, header, NULL, NULL);
1695 IHttpNegotiate_Release(http_negotiate);
1696 CHECK_CALLED(OnResponse);
1697 IHttpNegotiate_Release(http_negotiate);
1698 ok(hres == S_OK, "OnResponse failed: %08x\n", hres);
1700 if(mimefilter_test) {
1701 SET_EXPECT(MimeFilter_CreateInstance);
1702 SET_EXPECT(MimeFilter_Start);
1703 SET_EXPECT(ReportProgress_LOADINGMIMEHANDLER);
1704 }else if(!(pi & PI_MIMEVERIFICATION)) {
1705 SET_EXPECT(ReportProgress_MIMETYPEAVAILABLE);
1707 hres = IInternetProtocolSink_ReportProgress(binding_sink,
1708 BINDSTATUS_MIMETYPEAVAILABLE, mimefilter_test ? gzipW : text_htmlW);
1709 if(mimefilter_test) {
1710 CHECK_CALLED(MimeFilter_CreateInstance);
1711 CHECK_CALLED(MimeFilter_Start);
1712 CHECK_CALLED(ReportProgress_LOADINGMIMEHANDLER);
1713 }else if(!(pi & PI_MIMEVERIFICATION)) {
1714 CHECK_CALLED(ReportProgress_MIMETYPEAVAILABLE);
1717 "ReportProgress(BINDSTATUS_MIMETYPEAVAILABLE) failed: %08x\n", hres);
1719 bscf |= BSCF_FIRSTDATANOTIFICATION;
1724 bscf = BSCF_INTERMEDIATEDATANOTIFICATION;
1729 if(mimefilter_test) {
1730 SET_EXPECT(MimeFilter_ReportData);
1731 }else if(pi & PI_MIMEVERIFICATION) {
1733 SET_EXPECT(Read); /* checked in ReportData for short_read */
1735 if(!mimefilter_test)
1736 SET_EXPECT(Read); /* checked in BINDSTATUS_MIMETYPEAVAILABLE or ReportData */
1737 SET_EXPECT(ReportProgress_MIMETYPEAVAILABLE);
1740 SET_EXPECT(ReportData);
1742 SET_EXPECT(ReportData);
1745 hres = IInternetProtocolSink_ReportData(binding_sink, bscf, pr, 400);
1746 ok(hres == S_OK, "ReportData failed: %08x\n", hres);
1748 if(mimefilter_test) {
1749 SET_EXPECT(MimeFilter_ReportData);
1750 }else if(pi & PI_MIMEVERIFICATION) {
1751 if(!short_read && pr < 200)
1754 CHECK_CALLED(ReportProgress_MIMETYPEAVAILABLE);
1757 CHECK_CALLED(ReportData);
1766 static HRESULT WINAPI ProtocolEmul_Terminate(IInternetProtocolEx *iface, DWORD dwOptions)
1768 CHECK_EXPECT(Terminate);
1769 ok(!dwOptions, "dwOptions=%d\n", dwOptions);
1773 static HRESULT WINAPI ProtocolEmul_Read(IInternetProtocolEx *iface, void *pv,
1774 ULONG cb, ULONG *pcbRead)
1776 if(read_report_data)
1777 CHECK_EXPECT2(Read2);
1779 if(mimefilter_test || short_read) {
1780 if(!read_report_data)
1781 CHECK_EXPECT2(Read);
1782 }else if((pi & PI_MIMEVERIFICATION)) {
1783 if(!read_report_data)
1784 CHECK_EXPECT2(Read);
1786 if(prot_read < 300) {
1787 ok(pv != expect_pv, "pv == expect_pv\n");
1789 ok(cb == 2048-prot_read, "cb=%d\n", cb);
1791 ok(cb == 700, "cb=%d\n", cb);
1793 ok(expect_pv <= pv && (BYTE*)pv < (BYTE*)expect_pv + cb, "pv != expect_pv\n");
1796 if(!read_report_data)
1799 ok(pv == expect_pv, "pv != expect_pv\n");
1800 ok(cb == 1000, "cb=%d\n", cb);
1801 ok(!*pcbRead, "*pcbRead = %d\n", *pcbRead);
1803 ok(pcbRead != NULL, "pcbRead == NULL\n");
1805 if(prot_state == 3 || (short_read && prot_state != 4)) {
1810 SET_EXPECT(Read2); /* checked in BINDSTATUS_MIMETYPEAVAILABLE */
1811 SET_EXPECT(ReportProgress_MIMETYPEAVAILABLE);
1814 SET_EXPECT(MimeFilter_ReportData);
1815 else if(direct_read)
1816 SET_EXPECT(ReportData2);
1818 hres = IInternetProtocolSink_ReportData(binding_sink,
1819 BSCF_LASTDATANOTIFICATION|BSCF_INTERMEDIATEDATANOTIFICATION, 0, 0);
1821 ok(hres == S_OK, "ReportData failed: %08x\n", hres);
1823 CHECK_CALLED(ReportProgress_MIMETYPEAVAILABLE);
1825 CHECK_CALLED(MimeFilter_ReportData);
1826 else if(direct_read)
1827 CHECK_CALLED(ReportData2);
1830 SET_EXPECT(MimeFilter_ReportResult);
1832 SET_EXPECT(ReportResult);
1833 hres = IInternetProtocolSink_ReportResult(binding_sink, S_OK, ERROR_SUCCESS, NULL);
1834 ok(hres == S_OK, "ReportResult failed: %08x\n", hres);
1836 CHECK_CALLED(MimeFilter_ReportResult);
1838 CHECK_CALLED(ReportResult);
1840 memset(pv, 'x', 100);
1841 prot_read += *pcbRead = 100;
1843 }if(prot_state == 4) {
1848 if((async_read_pending = !async_read_pending)) {
1850 return tested_protocol == HTTP_TEST || tested_protocol == HTTPS_TEST ? E_PENDING : S_FALSE;
1853 memset(pv, 'x', 100);
1854 prot_read += *pcbRead = 100;
1858 static HRESULT WINAPI ProtocolEmul_LockRequest(IInternetProtocolEx *iface, DWORD dwOptions)
1860 CHECK_EXPECT(LockRequest);
1861 ok(dwOptions == 0, "dwOptions=%x\n", dwOptions);
1865 static HRESULT WINAPI ProtocolEmul_UnlockRequest(IInternetProtocolEx *iface)
1867 CHECK_EXPECT(UnlockRequest);
1871 static HRESULT WINAPI ProtocolEmul_StartEx(IInternetProtocolEx *iface, IUri *pUri,
1872 IInternetProtocolSink *pOIProtSink, IInternetBindInfo *pOIBindInfo,
1873 DWORD grfPI, HANDLE *dwReserved)
1875 CHECK_EXPECT(StartEx);
1876 ok(!dwReserved, "dwReserved = %p\n", dwReserved);
1877 protocol_start(pOIProtSink, pOIBindInfo, grfPI);
1881 static const IInternetProtocolExVtbl ProtocolVtbl = {
1882 ProtocolEmul_QueryInterface,
1886 ProtocolEmul_Continue,
1888 ProtocolEmul_Terminate,
1893 ProtocolEmul_LockRequest,
1894 ProtocolEmul_UnlockRequest,
1895 ProtocolEmul_StartEx
1898 static IInternetProtocolEx Protocol = { &ProtocolVtbl };
1900 static HRESULT WINAPI MimeProtocol_QueryInterface(IInternetProtocolEx *iface, REFIID riid, void **ppv)
1902 if(IsEqualGUID(&IID_IUnknown, riid) || IsEqualGUID(&IID_IInternetProtocol, riid)) {
1907 if(IsEqualGUID(&IID_IInternetProtocolSink, riid)) {
1908 *ppv = &mime_protocol_sink;
1912 ok(0, "unexpected riid %s\n", debugstr_guid(riid));
1914 return E_NOINTERFACE;
1917 static HRESULT WINAPI MimeProtocol_Start(IInternetProtocolEx *iface, LPCWSTR szUrl,
1918 IInternetProtocolSink *pOIProtSink, IInternetBindInfo *pOIBindInfo,
1919 DWORD grfPI, HANDLE_PTR dwReserved)
1921 PROTOCOLFILTERDATA *data;
1922 LPOLESTR url_str = NULL;
1928 CHECK_EXPECT(MimeFilter_Start);
1930 ok(!lstrcmpW(szUrl, gzipW), "wrong url %s\n", wine_dbgstr_w(szUrl));
1931 ok(grfPI == (PI_FILTER_MODE|PI_FORCE_ASYNC), "grfPI=%x, expected PI_FILTER_MODE|PI_FORCE_ASYNC\n", grfPI);
1932 ok(dwReserved, "dwReserved == 0\n");
1933 ok(pOIProtSink != NULL, "pOIProtSink == NULL\n");
1934 ok(pOIBindInfo != NULL, "pOIBindInfo == NULL\n");
1937 ok(pOIProtSink != binding_sink, "pOIProtSink == protocol_sink\n");
1938 ok(pOIBindInfo == prot_bind_info, "pOIBindInfo != bind_info\n");
1940 ok(pOIProtSink == &protocol_sink, "pOIProtSink != protocol_sink\n");
1941 ok(pOIBindInfo == &bind_info, "pOIBindInfo != bind_info\n");
1944 data = (void*)dwReserved;
1945 ok(data->cbSize == sizeof(*data), "data->cbSize = %d\n", data->cbSize);
1946 ok(!data->pProtocolSink, "data->pProtocolSink != NULL\n");
1947 ok(data->pProtocol != NULL, "data->pProtocol == NULL\n");
1948 ok(!data->pUnk, "data->pUnk != NULL\n");
1949 ok(!data->dwFilterFlags, "data->dwProtocolFlags = %x\n", data->dwFilterFlags);
1951 IInternetProtocolSink *prot_sink;
1953 IInternetProtocol_QueryInterface(data->pProtocol, &IID_IInternetProtocolSink, (void**)&prot_sink);
1954 ok(prot_sink == pOIProtSink, "QI(data->pProtocol, IID_IInternetProtocolSink) != pOIProtSink\n");
1955 IInternetProtocolSink_Release(prot_sink);
1957 ok(data->pProtocol != binding_protocol, "data->pProtocol == binding_protocol\n");
1959 filtered_protocol = data->pProtocol;
1960 IInternetProtocol_AddRef(filtered_protocol);
1962 IInternetProtocol *prot;
1964 IInternetProtocol_QueryInterface(data->pProtocol, &IID_IInternetProtocol, (void**)&prot);
1965 ok(prot == async_protocol, "QI(data->pProtocol, IID_IInternetProtocol) != async_protocol\n");
1966 IInternetProtocol_Release(prot);
1968 ok(data->pProtocol != async_protocol, "data->pProtocol == async_protocol\n");
1971 filtered_sink = pOIProtSink;
1973 SET_EXPECT(ReportProgress_DECODING);
1974 hres = IInternetProtocolSink_ReportProgress(pOIProtSink, BINDSTATUS_DECODING, gzipW);
1975 ok(hres == S_OK, "ReportProgress(BINDSTATUS_DECODING) failed: %08x\n", hres);
1976 CHECK_CALLED(ReportProgress_DECODING);
1978 SET_EXPECT(GetBindInfo);
1979 memset(&bindinfo, 0, sizeof(bindinfo));
1980 bindinfo.cbSize = sizeof(bindinfo);
1981 hres = IInternetBindInfo_GetBindInfo(pOIBindInfo, &cbindf, &bindinfo);
1982 ok(hres == S_OK, "GetBindInfo failed: %08x\n", hres);
1983 ok(cbindf == (bindf|BINDF_FROMURLMON), "cbindf = %x, expected %x\n", cbindf, bindf);
1984 CHECK_CALLED(GetBindInfo);
1986 SET_EXPECT(GetBindString_URL);
1987 hres = IInternetBindInfo_GetBindString(pOIBindInfo, BINDSTRING_URL, &url_str, 1, &fetched);
1988 ok(hres == S_OK, "GetBindString(BINDSTRING_URL) failed: %08x\n", hres);
1989 ok(fetched == 1, "fetched = %d\n", fetched);
1990 ok(!lstrcmpW(url_str, binding_urls[tested_protocol]), "wrong url_str %s\n", wine_dbgstr_w(url_str));
1991 CoTaskMemFree(url_str);
1992 CHECK_CALLED(GetBindString_URL);
1997 static HRESULT WINAPI Protocol_Continue(IInternetProtocolEx *iface,
1998 PROTOCOLDATA *pProtocolData)
2000 CHECK_EXPECT(MimeFilter_Continue);
2004 static HRESULT WINAPI MimeProtocol_Terminate(IInternetProtocolEx *iface, DWORD dwOptions)
2008 CHECK_EXPECT(MimeFilter_Terminate);
2010 ok(!dwOptions, "dwOptions = %x\n", dwOptions);
2012 SET_EXPECT(Terminate);
2013 hres = IInternetProtocol_Terminate(filtered_protocol, dwOptions);
2014 ok(hres == S_OK, "Terminate failed: %08x\n", hres);
2015 CHECK_CALLED(Terminate);
2020 static HRESULT WINAPI MimeProtocol_Read(IInternetProtocolEx *iface, void *pv,
2021 ULONG cb, ULONG *pcbRead)
2027 CHECK_EXPECT(MimeFilter_Read);
2029 ok(pv != NULL, "pv == NULL\n");
2030 ok(cb != 0, "cb == 0\n");
2031 ok(pcbRead != NULL, "pcbRead == NULL\n");
2033 if(read_report_data)
2037 hres = IInternetProtocol_Read(filtered_protocol, buf, sizeof(buf), &read);
2038 ok(hres == S_OK || hres == S_FALSE || hres == E_PENDING, "Read failed: %08x\n", hres);
2039 if(read_report_data)
2040 CHECK_CALLED(Read2);
2045 ok(*pcbRead == 0, "*pcbRead=%d, expected 0\n", *pcbRead);
2049 memset(pv, 'x', read);
2053 static HRESULT WINAPI MimeProtocol_LockRequest(IInternetProtocolEx *iface, DWORD dwOptions)
2057 CHECK_EXPECT(MimeFilter_LockRequest);
2059 ok(!dwOptions, "dwOptions = %x\n", dwOptions);
2061 SET_EXPECT(LockRequest);
2062 hres = IInternetProtocol_LockRequest(filtered_protocol, dwOptions);
2063 ok(hres == S_OK, "LockRequest failed: %08x\n", hres);
2064 CHECK_CALLED(LockRequest);
2069 static HRESULT WINAPI MimeProtocol_UnlockRequest(IInternetProtocolEx *iface)
2073 CHECK_EXPECT(MimeFilter_UnlockRequest);
2075 SET_EXPECT(UnlockRequest);
2076 hres = IInternetProtocol_UnlockRequest(filtered_protocol);
2077 ok(hres == S_OK, "UnlockRequest failed: %08x\n", hres);
2078 CHECK_CALLED(UnlockRequest);
2083 static const IInternetProtocolExVtbl MimeProtocolVtbl = {
2084 MimeProtocol_QueryInterface,
2090 MimeProtocol_Terminate,
2095 MimeProtocol_LockRequest,
2096 MimeProtocol_UnlockRequest
2099 static IInternetProtocolEx MimeProtocol = { &MimeProtocolVtbl };
2101 static HRESULT WINAPI ClassFactory_QueryInterface(IClassFactory *iface, REFIID riid, void **ppv)
2103 ok(0, "unexpected call\n");
2104 return E_NOINTERFACE;
2107 static ULONG WINAPI ClassFactory_AddRef(IClassFactory *iface)
2112 static ULONG WINAPI ClassFactory_Release(IClassFactory *iface)
2117 static HRESULT WINAPI ClassFactory_CreateInstance(IClassFactory *iface, IUnknown *pOuter,
2118 REFIID riid, void **ppv)
2120 CHECK_EXPECT(CreateInstance);
2122 ok(pOuter == (IUnknown*)prot_bind_info, "pOuter != protocol_unk\n");
2123 ok(IsEqualGUID(&IID_IUnknown, riid), "unexpected riid %s\n", debugstr_guid(riid));
2124 ok(ppv != NULL, "ppv == NULL\n");
2130 static HRESULT WINAPI ClassFactory_LockServer(IClassFactory *iface, BOOL dolock)
2132 ok(0, "unexpected call\n");
2136 static const IClassFactoryVtbl ClassFactoryVtbl = {
2137 ClassFactory_QueryInterface,
2138 ClassFactory_AddRef,
2139 ClassFactory_Release,
2140 ClassFactory_CreateInstance,
2141 ClassFactory_LockServer
2144 static IClassFactory ClassFactory = { &ClassFactoryVtbl };
2146 static HRESULT WINAPI MimeFilter_CreateInstance(IClassFactory *iface, IUnknown *outer, REFIID riid, void **ppv)
2148 CHECK_EXPECT(MimeFilter_CreateInstance);
2150 ok(!outer, "outer = %p\n", outer);
2151 ok(IsEqualGUID(&IID_IInternetProtocol, riid), "unexpected riid %s\n", debugstr_guid(riid));
2153 *ppv = &MimeProtocol;
2157 static const IClassFactoryVtbl MimeFilterCFVtbl = {
2158 ClassFactory_QueryInterface,
2159 ClassFactory_AddRef,
2160 ClassFactory_Release,
2161 MimeFilter_CreateInstance,
2162 ClassFactory_LockServer
2165 static IClassFactory mimefilter_cf = { &MimeFilterCFVtbl };
2167 #define TEST_BINDING 0x0001
2168 #define TEST_FILTER 0x0002
2169 #define TEST_FIRST_HTTP 0x0004
2170 #define TEST_DIRECT_READ 0x0008
2171 #define TEST_POST 0x0010
2172 #define TEST_EMULATEPROT 0x0020
2173 #define TEST_SHORT_READ 0x0040
2174 #define TEST_REDIRECT 0x0080
2175 #define TEST_ABORT 0x0100
2176 #define TEST_ASYNCREQ 0x0200
2177 #define TEST_USEIURI 0x0400
2178 #define TEST_IMPLPROTEX 0x0800
2180 static void register_filter(BOOL do_register)
2182 IInternetSession *session;
2185 static const WCHAR gzipW[] = {'g','z','i','p',0};
2187 hres = pCoInternetGetSession(0, &session, 0);
2188 ok(hres == S_OK, "CoInternetGetSession failed: %08x\n", hres);
2191 hres = IInternetSession_RegisterMimeFilter(session, &mimefilter_cf, &IID_IInternetProtocol, gzipW);
2192 ok(hres == S_OK, "RegisterMimeFilter failed: %08x\n", hres);
2194 hres = IInternetSession_UnregisterMimeFilter(session, &mimefilter_cf, gzipW);
2195 ok(hres == S_OK, "RegisterMimeFilter failed: %08x\n", hres);
2198 IInternetSession_Release(session);
2201 static void init_test(int prot, DWORD flags)
2203 tested_protocol = prot;
2204 binding_test = (flags & TEST_BINDING) != 0;
2205 first_data_notif = TRUE;
2208 async_read_pending = TRUE;
2209 mimefilter_test = (flags & TEST_FILTER) != 0;
2211 post_stream_read = 0;
2212 ResetEvent(event_complete);
2213 ResetEvent(event_complete2);
2214 ResetEvent(event_continue);
2215 ResetEvent(event_continue_done);
2216 async_protocol = binding_protocol = filtered_protocol = NULL;
2217 filtered_sink = NULL;
2218 http_is_first = (flags & TEST_FIRST_HTTP) != 0;
2219 first_data_notif = TRUE;
2220 state = STATE_CONNECTING;
2221 test_async_req = (flags & TEST_ASYNCREQ) != 0;
2222 direct_read = (flags & TEST_DIRECT_READ) != 0;
2223 emulate_prot = (flags & TEST_EMULATEPROT) != 0;
2224 wait_for_switch = TRUE;
2225 short_read = (flags & TEST_SHORT_READ) != 0;
2226 http_post_test = TYMED_NULL;
2227 test_redirect = (flags & TEST_REDIRECT) != 0;
2228 test_abort = (flags & TEST_ABORT) != 0;
2229 impl_protex = (flags & TEST_IMPLPROTEX) != 0;
2231 register_filter(mimefilter_test);
2234 static void test_priority(IInternetProtocol *protocol)
2236 IInternetPriority *priority;
2240 hres = IInternetProtocol_QueryInterface(protocol, &IID_IInternetPriority,
2242 ok(hres == S_OK, "QueryInterface(IID_IInternetPriority) failed: %08x\n", hres);
2246 hres = IInternetPriority_GetPriority(priority, &pr);
2247 ok(hres == S_OK, "GetPriority failed: %08x\n", hres);
2248 ok(pr == 0, "pr=%d, expected 0\n", pr);
2250 hres = IInternetPriority_SetPriority(priority, 1);
2251 ok(hres == S_OK, "SetPriority failed: %08x\n", hres);
2253 hres = IInternetPriority_GetPriority(priority, &pr);
2254 ok(hres == S_OK, "GetPriority failed: %08x\n", hres);
2255 ok(pr == 1, "pr=%d, expected 1\n", pr);
2257 IInternetPriority_Release(priority);
2260 static void test_early_abort(const CLSID *clsid)
2262 IInternetProtocol *protocol;
2265 hres = CoCreateInstance(clsid, NULL, CLSCTX_INPROC_SERVER|CLSCTX_INPROC_HANDLER,
2266 &IID_IInternetProtocol, (void**)&protocol);
2267 ok(hres == S_OK, "CoCreateInstance failed: %08x\n", hres);
2269 hres = IInternetProtocol_Abort(protocol, E_ABORT, 0);
2270 ok(hres == S_OK, "Abort failed: %08x\n", hres);
2272 hres = IInternetProtocol_Abort(protocol, E_FAIL, 0);
2273 ok(hres == S_OK, "Abort failed: %08x\n", hres);
2275 IInternetProtocol_Release(protocol);
2278 static BOOL file_protocol_start(IInternetProtocol *protocol, LPCWSTR url,
2279 IInternetProtocolEx *protocolex, IUri *uri, BOOL is_first)
2283 SET_EXPECT(GetBindInfo);
2284 if(!(bindf & BINDF_FROMURLMON))
2285 SET_EXPECT(ReportProgress_DIRECTBIND);
2287 SET_EXPECT(ReportProgress_SENDINGREQUEST);
2288 SET_EXPECT(ReportProgress_CACHEFILENAMEAVAILABLE);
2289 if(bindf & BINDF_FROMURLMON)
2290 SET_EXPECT(ReportProgress_VERIFIEDMIMETYPEAVAILABLE);
2292 SET_EXPECT(ReportProgress_MIMETYPEAVAILABLE);
2294 SET_EXPECT(ReportData);
2296 SET_EXPECT(ReportResult);
2298 expect_hrResult = S_OK;
2301 hres = IInternetProtocolEx_StartEx(protocolex, uri, &protocol_sink, &bind_info, 0, 0);
2302 ok(hres == S_OK, "StartEx failed: %08x\n", hres);
2304 hres = IInternetProtocol_Start(protocol, url, &protocol_sink, &bind_info, 0, 0);
2305 if(hres == INET_E_RESOURCE_NOT_FOUND) {
2306 win_skip("Start failed\n");
2309 ok(hres == S_OK, "Start failed: %08x\n", hres);
2312 CHECK_CALLED(GetBindInfo);
2313 if(!(bindf & BINDF_FROMURLMON))
2314 CHECK_CALLED(ReportProgress_DIRECTBIND);
2316 CHECK_CALLED(ReportProgress_SENDINGREQUEST);
2317 CHECK_CALLED(ReportProgress_CACHEFILENAMEAVAILABLE);
2318 if(bindf & BINDF_FROMURLMON)
2319 CHECK_CALLED(ReportProgress_VERIFIEDMIMETYPEAVAILABLE);
2321 CHECK_CALLED(ReportProgress_MIMETYPEAVAILABLE);
2323 CHECK_CALLED(ReportData);
2325 CHECK_CALLED(ReportResult);
2330 static void test_file_protocol_url(LPCWSTR url)
2332 IInternetProtocolInfo *protocol_info;
2334 IClassFactory *factory;
2335 IInternetProtocol *protocol;
2340 hres = CoGetClassObject(&CLSID_FileProtocol, CLSCTX_INPROC_SERVER, NULL,
2341 &IID_IUnknown, (void**)&unk);
2342 ok(hres == S_OK, "CoGetClassObject failed: %08x\n", hres);
2346 hres = IUnknown_QueryInterface(unk, &IID_IInternetProtocolInfo, (void**)&protocol_info);
2347 ok(hres == E_NOINTERFACE,
2348 "Could not get IInternetProtocolInfo interface: %08x, expected E_NOINTERFACE\n", hres);
2350 hres = IUnknown_QueryInterface(unk, &IID_IClassFactory, (void**)&factory);
2351 ok(hres == S_OK, "Could not get IClassFactory interface\n");
2352 IUnknown_Release(unk);
2356 hres = IClassFactory_CreateInstance(factory, NULL, &IID_IInternetProtocol, (void**)&protocol);
2357 ok(hres == S_OK, "Could not get IInternetProtocol: %08x\n", hres);
2359 if(SUCCEEDED(hres)) {
2360 if(file_protocol_start(protocol, url, NULL, NULL, TRUE)) {
2361 hres = IInternetProtocol_Read(protocol, buf, 2, &cb);
2362 ok(hres == S_OK, "Read failed: %08x\n", hres);
2363 ok(cb == 2, "cb=%u expected 2\n", cb);
2364 hres = IInternetProtocol_Read(protocol, buf, sizeof(buf), &cb);
2365 ok(hres == S_FALSE, "Read failed: %08x\n", hres);
2366 hres = IInternetProtocol_Read(protocol, buf, sizeof(buf), &cb);
2367 ok(hres == S_FALSE, "Read failed: %08x expected S_FALSE\n", hres);
2368 ok(cb == 0, "cb=%u expected 0\n", cb);
2369 hres = IInternetProtocol_UnlockRequest(protocol);
2370 ok(hres == S_OK, "UnlockRequest failed: %08x\n", hres);
2373 if(file_protocol_start(protocol, url, NULL, NULL, FALSE)) {
2374 hres = IInternetProtocol_Read(protocol, buf, 2, &cb);
2375 ok(hres == S_FALSE, "Read failed: %08x\n", hres);
2376 hres = IInternetProtocol_LockRequest(protocol, 0);
2377 ok(hres == S_OK, "LockRequest failed: %08x\n", hres);
2378 hres = IInternetProtocol_UnlockRequest(protocol);
2379 ok(hres == S_OK, "UnlockRequest failed: %08x\n", hres);
2382 IInternetProtocol_Release(protocol);
2385 hres = IClassFactory_CreateInstance(factory, NULL, &IID_IInternetProtocol, (void**)&protocol);
2386 ok(hres == S_OK, "Could not get IInternetProtocol: %08x\n", hres);
2387 if(SUCCEEDED(hres)) {
2388 if(file_protocol_start(protocol, url, NULL, NULL, TRUE)) {
2389 hres = IInternetProtocol_LockRequest(protocol, 0);
2390 ok(hres == S_OK, "LockRequest failed: %08x\n", hres);
2391 hres = IInternetProtocol_Terminate(protocol, 0);
2392 ok(hres == S_OK, "Terminate failed: %08x\n", hres);
2393 hres = IInternetProtocol_Read(protocol, buf, 2, &cb);
2394 ok(hres == S_OK, "Read failed: %08x\n\n", hres);
2395 hres = IInternetProtocol_UnlockRequest(protocol);
2396 ok(hres == S_OK, "UnlockRequest failed: %08x\n", hres);
2397 hres = IInternetProtocol_Read(protocol, buf, 2, &cb);
2398 ok(hres == S_OK, "Read failed: %08x\n", hres);
2399 hres = IInternetProtocol_Terminate(protocol, 0);
2400 ok(hres == S_OK, "Terminate failed: %08x\n", hres);
2403 IInternetProtocol_Release(protocol);
2406 hres = IClassFactory_CreateInstance(factory, NULL, &IID_IInternetProtocol, (void**)&protocol);
2407 ok(hres == S_OK, "Could not get IInternetProtocol: %08x\n", hres);
2408 if(SUCCEEDED(hres)) {
2409 if(file_protocol_start(protocol, url, NULL, NULL, TRUE)) {
2410 hres = IInternetProtocol_Terminate(protocol, 0);
2411 ok(hres == S_OK, "Terminate failed: %08x\n", hres);
2412 hres = IInternetProtocol_Read(protocol, buf, 2, &cb);
2413 ok(hres == S_OK, "Read failed: %08x\n", hres);
2414 ok(cb == 2, "cb=%u expected 2\n", cb);
2417 IInternetProtocol_Release(protocol);
2421 IInternetProtocolEx *protocolex;
2424 hres = pCreateUri(url, Uri_CREATE_FILE_USE_DOS_PATH, 0, &uri);
2425 ok(hres == S_OK, "CreateUri failed: %08x\n", hres);
2427 hres = IClassFactory_CreateInstance(factory, NULL, &IID_IInternetProtocolEx, (void**)&protocolex);
2428 ok(hres == S_OK, "Could not get IInternetProtocolEx: %08x\n", hres);
2430 if(file_protocol_start(NULL, NULL, protocolex, uri, TRUE)) {
2431 hres = IInternetProtocolEx_Read(protocolex, buf, 2, &cb);
2432 ok(hres == S_OK, "Read failed: %08x\n", hres);
2433 hres = IInternetProtocolEx_LockRequest(protocolex, 0);
2434 ok(hres == S_OK, "LockRequest failed: %08x\n", hres);
2435 hres = IInternetProtocolEx_UnlockRequest(protocolex);
2436 ok(hres == S_OK, "UnlockRequest failed: %08x\n", hres);
2440 IInternetProtocolEx_Release(protocolex);
2442 win_skip("Skipping file protocol StartEx tests\n");
2445 IClassFactory_Release(factory);
2448 static void test_file_protocol_fail(void)
2450 IInternetProtocol *protocol;
2453 static const WCHAR index_url2[] =
2454 {'f','i','l','e',':','/','/','i','n','d','e','x','.','h','t','m','l',0};
2456 hres = CoCreateInstance(&CLSID_FileProtocol, NULL, CLSCTX_INPROC_SERVER|CLSCTX_INPROC_HANDLER,
2457 &IID_IInternetProtocol, (void**)&protocol);
2458 ok(hres == S_OK, "CoCreateInstance failed: %08x\n", hres);
2462 SET_EXPECT(GetBindInfo);
2463 expect_hrResult = MK_E_SYNTAX;
2464 hres = IInternetProtocol_Start(protocol, wszIndexHtml, &protocol_sink, &bind_info, 0, 0);
2465 ok(hres == MK_E_SYNTAX ||
2466 hres == E_INVALIDARG,
2467 "Start failed: %08x, expected MK_E_SYNTAX or E_INVALIDARG\n", hres);
2468 CLEAR_CALLED(GetBindInfo); /* GetBindInfo not called in IE7 */
2470 SET_EXPECT(GetBindInfo);
2471 if(!(bindf & BINDF_FROMURLMON))
2472 SET_EXPECT(ReportProgress_DIRECTBIND);
2473 SET_EXPECT(ReportProgress_SENDINGREQUEST);
2474 SET_EXPECT(ReportResult);
2475 expect_hrResult = INET_E_RESOURCE_NOT_FOUND;
2476 hres = IInternetProtocol_Start(protocol, index_url, &protocol_sink, &bind_info, 0, 0);
2477 ok(hres == INET_E_RESOURCE_NOT_FOUND,
2478 "Start failed: %08x expected INET_E_RESOURCE_NOT_FOUND\n", hres);
2479 CHECK_CALLED(GetBindInfo);
2480 if(!(bindf & BINDF_FROMURLMON))
2481 CHECK_CALLED(ReportProgress_DIRECTBIND);
2482 CHECK_CALLED(ReportProgress_SENDINGREQUEST);
2483 CHECK_CALLED(ReportResult);
2485 IInternetProtocol_Release(protocol);
2487 hres = CoCreateInstance(&CLSID_FileProtocol, NULL, CLSCTX_INPROC_SERVER|CLSCTX_INPROC_HANDLER,
2488 &IID_IInternetProtocol, (void**)&protocol);
2489 ok(hres == S_OK, "CoCreateInstance failed: %08x\n", hres);
2493 SET_EXPECT(GetBindInfo);
2494 if(!(bindf & BINDF_FROMURLMON))
2495 SET_EXPECT(ReportProgress_DIRECTBIND);
2496 SET_EXPECT(ReportProgress_SENDINGREQUEST);
2497 SET_EXPECT(ReportResult);
2498 expect_hrResult = INET_E_RESOURCE_NOT_FOUND;
2500 hres = IInternetProtocol_Start(protocol, index_url2, &protocol_sink, &bind_info, 0, 0);
2501 ok(hres == INET_E_RESOURCE_NOT_FOUND,
2502 "Start failed: %08x, expected INET_E_RESOURCE_NOT_FOUND\n", hres);
2503 CHECK_CALLED(GetBindInfo);
2504 if(!(bindf & BINDF_FROMURLMON))
2505 CHECK_CALLED(ReportProgress_DIRECTBIND);
2506 CHECK_CALLED(ReportProgress_SENDINGREQUEST);
2507 CHECK_CALLED(ReportResult);
2509 SET_EXPECT(GetBindInfo);
2510 hres = IInternetProtocol_Start(protocol, NULL, &protocol_sink, &bind_info, 0, 0);
2511 ok(hres == E_INVALIDARG, "Start failed: %08x, expected E_INVALIDARG\n", hres);
2512 CLEAR_CALLED(GetBindInfo); /* GetBindInfo not called in IE7 */
2514 SET_EXPECT(GetBindInfo);
2515 hres = IInternetProtocol_Start(protocol, emptyW, &protocol_sink, &bind_info, 0, 0);
2516 ok(hres == E_INVALIDARG, "Start failed: %08x, expected E_INVALIDARG\n", hres);
2517 CLEAR_CALLED(GetBindInfo); /* GetBindInfo not called in IE7 */
2519 IInternetProtocol_Release(protocol);
2522 static void test_file_protocol(void) {
2523 WCHAR buf[INTERNET_MAX_URL_LENGTH], file_name_buf[MAX_PATH];
2528 static const WCHAR wszFile[] = {'f','i','l','e',':',0};
2529 static const WCHAR wszFile2[] = {'f','i','l','e',':','/','/',0};
2530 static const WCHAR wszFile3[] = {'f','i','l','e',':','/','/','/',0};
2531 static const WCHAR wszFile4[] = {'f','i','l','e',':','\\','\\',0};
2532 static const char html_doc[] = "<HTML></HTML>";
2534 trace("Testing file protocol...\n");
2535 init_test(FILE_TEST, 0);
2537 SetLastError(0xdeadbeef);
2538 file = CreateFileW(wszIndexHtml, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS,
2539 FILE_ATTRIBUTE_NORMAL, NULL);
2540 ok(file != INVALID_HANDLE_VALUE, "CreateFile failed\n");
2541 if(file == INVALID_HANDLE_VALUE)
2543 WriteFile(file, html_doc, sizeof(html_doc)-1, &size, NULL);
2546 file_name = wszIndexHtml;
2548 test_file_protocol_url(index_url);
2549 bindf = BINDF_FROMURLMON;
2550 test_file_protocol_url(index_url);
2551 bindf = BINDF_FROMURLMON | BINDF_NEEDFILE;
2552 test_file_protocol_url(index_url);
2554 memcpy(buf, wszFile, sizeof(wszFile));
2555 len = sizeof(wszFile)/sizeof(WCHAR)-1;
2556 len += GetCurrentDirectoryW(sizeof(buf)/sizeof(WCHAR)-len, buf+len);
2558 memcpy(buf+len, wszIndexHtml, sizeof(wszIndexHtml));
2560 file_name = buf + sizeof(wszFile)/sizeof(WCHAR)-1;
2562 test_file_protocol_url(buf);
2563 bindf = BINDF_FROMURLMON;
2564 test_file_protocol_url(buf);
2566 memcpy(buf, wszFile2, sizeof(wszFile2));
2567 len = GetCurrentDirectoryW(sizeof(file_name_buf)/sizeof(WCHAR), file_name_buf);
2568 file_name_buf[len++] = '\\';
2569 memcpy(file_name_buf+len, wszIndexHtml, sizeof(wszIndexHtml));
2570 lstrcpyW(buf+sizeof(wszFile2)/sizeof(WCHAR)-1, file_name_buf);
2571 file_name = file_name_buf;
2573 test_file_protocol_url(buf);
2574 bindf = BINDF_FROMURLMON;
2575 test_file_protocol_url(buf);
2577 buf[sizeof(wszFile2)/sizeof(WCHAR)] = '|';
2578 test_file_protocol_url(buf);
2580 memcpy(buf, wszFile3, sizeof(wszFile3));
2581 len = sizeof(wszFile3)/sizeof(WCHAR)-1;
2582 len += GetCurrentDirectoryW(sizeof(buf)/sizeof(WCHAR)-len, buf+len);
2584 memcpy(buf+len, wszIndexHtml, sizeof(wszIndexHtml));
2586 file_name = buf + sizeof(wszFile3)/sizeof(WCHAR)-1;
2588 test_file_protocol_url(buf);
2589 bindf = BINDF_FROMURLMON;
2590 test_file_protocol_url(buf);
2592 memcpy(buf, wszFile4, sizeof(wszFile4));
2593 len = GetCurrentDirectoryW(sizeof(file_name_buf)/sizeof(WCHAR), file_name_buf);
2594 file_name_buf[len++] = '\\';
2595 memcpy(file_name_buf+len, wszIndexHtml, sizeof(wszIndexHtml));
2596 lstrcpyW(buf+sizeof(wszFile4)/sizeof(WCHAR)-1, file_name_buf);
2597 file_name = file_name_buf;
2599 test_file_protocol_url(buf);
2600 bindf = BINDF_FROMURLMON;
2601 test_file_protocol_url(buf);
2603 buf[sizeof(wszFile4)/sizeof(WCHAR)] = '|';
2604 test_file_protocol_url(buf);
2606 DeleteFileW(wszIndexHtml);
2609 test_file_protocol_fail();
2610 bindf = BINDF_FROMURLMON;
2611 test_file_protocol_fail();
2614 static BOOL http_protocol_start(LPCWSTR url, BOOL use_iuri)
2616 static BOOL got_user_agent = FALSE;
2620 if(use_iuri && pCreateUri) {
2621 hres = pCreateUri(url, 0, 0, &uri);
2622 ok(hres == S_OK, "CreateUri failed: %08x\n", hres);
2625 SET_EXPECT(GetBindInfo);
2626 if (!(bindf & BINDF_FROMURLMON))
2627 SET_EXPECT(ReportProgress_DIRECTBIND);
2629 SET_EXPECT(GetBindString_USER_AGENT);
2630 SET_EXPECT(GetBindString_ACCEPT_MIMES);
2631 SET_EXPECT(QueryService_HttpNegotiate);
2632 SET_EXPECT(BeginningTransaction);
2633 SET_EXPECT(GetRootSecurityId);
2634 if(http_post_test) {
2635 SET_EXPECT(GetBindString_POST_COOKIE);
2636 if(http_post_test == TYMED_ISTREAM)
2637 SET_EXPECT(Stream_Seek);
2641 IInternetProtocolEx *protocolex;
2643 hres = IInternetProtocol_QueryInterface(async_protocol, &IID_IInternetProtocolEx, (void**)&protocolex);
2644 ok(hres == S_OK, "Could not get IInternetProtocolEx iface: %08x\n", hres);
2646 hres = IInternetProtocolEx_StartEx(protocolex, uri, &protocol_sink, &bind_info, 0, 0);
2647 ok(hres == S_OK, "Start failed: %08x\n", hres);
2649 IInternetProtocolEx_Release(protocolex);
2652 hres = IInternetProtocol_Start(async_protocol, url, &protocol_sink, &bind_info, 0, 0);
2653 ok(hres == S_OK, "Start failed: %08x\n", hres);
2658 CHECK_CALLED(GetBindInfo);
2659 if (!(bindf & BINDF_FROMURLMON))
2660 CHECK_CALLED(ReportProgress_DIRECTBIND);
2661 if (!got_user_agent)
2663 CHECK_CALLED(GetBindString_USER_AGENT);
2664 got_user_agent = TRUE;
2666 CHECK_CALLED(GetBindString_ACCEPT_MIMES);
2667 CHECK_CALLED(QueryService_HttpNegotiate);
2668 CHECK_CALLED(BeginningTransaction);
2669 /* GetRootSecurityId called on WinXP but not on Win98 */
2670 CLEAR_CALLED(GetRootSecurityId);
2671 if(http_post_test) {
2672 CHECK_CALLED(GetBindString_POST_COOKIE);
2673 if(http_post_test == TYMED_ISTREAM)
2674 CHECK_CALLED(Stream_Seek);
2680 static void test_protocol_terminate(IInternetProtocol *protocol)
2686 hres = IInternetProtocol_LockRequest(protocol, 0);
2687 ok(hres == S_OK, "LockRequest failed: %08x\n", hres);
2689 hres = IInternetProtocol_Read(protocol, buf, 1, &cb);
2690 ok(hres == test_abort ? S_OK : S_FALSE, "Read failed: %08x\n", hres);
2692 hres = IInternetProtocol_Terminate(protocol, 0);
2693 ok(hres == S_OK, "Terminate failed: %08x\n", hres);
2695 /* This wait is to give the internet handles being freed in Terminate
2696 * enough time to actually terminate in all cases. Internet handles
2697 * terminate asynchronously and native reuses the main InternetOpen
2698 * handle. The only case in which this seems to be necessary is on
2699 * wine with native wininet and urlmon, resulting in the next time
2700 * test_http_protocol_url being called the first data notification actually
2701 * being an extra last data notification from the previous connection
2702 * about once out of every ten times. */
2705 hres = IInternetProtocol_UnlockRequest(protocol);
2706 ok(hres == S_OK, "UnlockRequest failed: %08x\n", hres);
2709 static void test_http_info(IInternetProtocol *protocol)
2711 IWinInetHttpInfo *info;
2714 hres = IInternetProtocol_QueryInterface(protocol, &IID_IWinInetHttpInfo, (void**)&info);
2715 ok(hres == S_OK, "Could not get IWinInterHttpInfo iface: %08x\n", hres);
2719 IWinInetHttpInfo_Release(info);
2722 /* is_first refers to whether this is the first call to this function
2724 static void test_http_protocol_url(LPCWSTR url, int prot, DWORD flags, DWORD tymed)
2726 IInternetProtocolInfo *protocol_info;
2727 IClassFactory *factory;
2731 init_test(prot, flags);
2733 http_post_test = tymed;
2735 hres = CoGetClassObject(prot == HTTPS_TEST ? &CLSID_HttpSProtocol : &CLSID_HttpProtocol,
2736 CLSCTX_INPROC_SERVER, NULL, &IID_IUnknown, (void**)&unk);
2737 ok(hres == S_OK, "CoGetClassObject failed: %08x\n", hres);
2741 hres = IUnknown_QueryInterface(unk, &IID_IInternetProtocolInfo, (void**)&protocol_info);
2742 ok(hres == E_NOINTERFACE,
2743 "Could not get IInternetProtocolInfo interface: %08x, expected E_NOINTERFACE\n",
2746 hres = IUnknown_QueryInterface(unk, &IID_IClassFactory, (void**)&factory);
2747 ok(hres == S_OK, "Could not get IClassFactory interface\n");
2748 IUnknown_Release(unk);
2752 hres = IClassFactory_CreateInstance(factory, NULL, &IID_IInternetProtocol,
2753 (void**)&async_protocol);
2754 ok(hres == S_OK, "Could not get IInternetProtocol: %08x\n", hres);
2755 if(SUCCEEDED(hres)) {
2760 test_priority(async_protocol);
2761 test_http_info(async_protocol);
2763 SET_EXPECT(ReportProgress_COOKIE_SENT);
2764 SET_EXPECT(ReportProgress_FINDINGRESOURCE);
2765 SET_EXPECT(ReportProgress_CONNECTING);
2766 SET_EXPECT(ReportProgress_SENDINGREQUEST);
2768 SET_EXPECT(ReportProgress_REDIRECTING);
2769 SET_EXPECT(ReportProgress_PROXYDETECTING);
2770 if(prot == HTTP_TEST)
2771 SET_EXPECT(ReportProgress_CACHEFILENAMEAVAILABLE);
2773 SET_EXPECT(QueryService_HttpSecurity);
2774 if(!(bindf & BINDF_FROMURLMON)) {
2775 SET_EXPECT(OnResponse);
2776 SET_EXPECT(ReportProgress_RAWMIMETYPE);
2777 SET_EXPECT(ReportData);
2782 if(!http_protocol_start(url, (flags & TEST_USEIURI) != 0))
2785 if(!direct_read && !test_abort)
2786 SET_EXPECT(ReportResult);
2787 expect_hrResult = test_abort ? E_ABORT : S_OK;
2791 while(wait_for_switch) {
2792 WaitForSingleObject(event_continue, INFINITE);
2793 CHECK_CALLED(Switch); /* Set in ReportData */
2794 call_continue(&continue_protdata);
2795 SetEvent(event_continue_done);
2798 hres = IInternetProtocol_Read(async_protocol, buf, 1, &cb);
2799 ok((hres == E_PENDING && cb==0) ||
2800 (hres == S_OK && cb==1), "Read failed: %08x (%d bytes)\n", hres, cb);
2802 WaitForSingleObject(event_complete, INFINITE);
2803 if(bindf & BINDF_FROMURLMON)
2804 CHECK_CALLED(Switch);
2806 CHECK_CALLED(ReportData);
2807 if(prot == HTTPS_TEST)
2808 CLEAR_CALLED(QueryService_HttpSecurity);
2811 if(bindf & BINDF_FROMURLMON)
2814 SET_EXPECT(ReportData);
2815 hres = IInternetProtocol_Read(async_protocol, buf, sizeof(buf), &cb);
2816 if(hres == E_PENDING) {
2817 hres = IInternetProtocol_Read(async_protocol, buf, 1, &cb);
2818 ok((hres == E_PENDING && cb==0) ||
2819 (hres == S_OK && cb==1), "Read failed: %08x (%d bytes)\n", hres, cb);
2820 WaitForSingleObject(event_complete, INFINITE);
2821 if(bindf & BINDF_FROMURLMON)
2822 CHECK_CALLED(Switch);
2824 CHECK_CALLED(ReportData);
2829 SET_EXPECT(ReportResult);
2830 hres = IInternetProtocol_Abort(async_protocol, E_ABORT, 0);
2831 ok(hres == S_OK, "Abort failed: %08x\n", hres);
2832 CHECK_CALLED(ReportResult);
2834 hres = IInternetProtocol_Abort(async_protocol, E_ABORT, 0);
2835 ok(hres == INET_E_RESULT_DISPATCHED, "Abort failed: %08x\n", hres);
2839 if(bindf & BINDF_FROMURLMON)
2840 CHECK_NOT_CALLED(Switch);
2842 CHECK_NOT_CALLED(ReportData);
2847 ok(hres == S_FALSE, "Read failed: %08x\n", hres);
2848 CHECK_CALLED(ReportResult);
2851 if(prot == HTTPS_TEST)
2852 CLEAR_CALLED(ReportProgress_SENDINGREQUEST);
2854 hres = IInternetProtocol_Abort(async_protocol, E_ABORT, 0);
2855 ok(hres == INET_E_RESULT_DISPATCHED, "Abort failed: %08x\n", hres);
2857 test_protocol_terminate(async_protocol);
2859 hres = IInternetProtocol_Abort(async_protocol, E_ABORT, 0);
2860 ok(hres == S_OK, "Abort failed: %08x\n", hres);
2862 ref = IInternetProtocol_Release(async_protocol);
2863 ok(!ref, "ref=%x\n", ref);
2866 IClassFactory_Release(factory);
2869 static void test_http_protocol(void)
2871 static const WCHAR posttest_url[] =
2872 {'h','t','t','p',':','/','/','t','e','s','t','.','w','i','n','e','h','q','.','o','r','g','/',
2873 't','e','s','t','s','/','p','o','s','t','.','p','h','p',0};
2874 static const WCHAR redirect_url[] =
2875 {'h','t','t','p',':','/','/','t','e','s','t','.','w','i','n','e','h','q','.','o','r','g','/',
2876 't','e','s','t','s','/','r','e','d','i','r','e','c','t',0};
2877 static const WCHAR winetest_url[] =
2878 {'h','t','t','p',':','/','/','t','e','s','t','.','w','i','n','e','h','q','.','o','r','g','/',
2879 't','e','s','t','s','/','d','a','t','a','.','p','h','p',0};
2881 trace("Testing http protocol (not from urlmon)...\n");
2882 bindf = BINDF_ASYNCHRONOUS | BINDF_ASYNCSTORAGE | BINDF_PULLDATA;
2883 test_http_protocol_url(winetest_url, HTTP_TEST, TEST_FIRST_HTTP, TYMED_NULL);
2885 trace("Testing http protocol (from urlmon)...\n");
2886 bindf = BINDF_ASYNCHRONOUS | BINDF_ASYNCSTORAGE | BINDF_PULLDATA | BINDF_FROMURLMON;
2887 test_http_protocol_url(winetest_url, HTTP_TEST, 0, TYMED_NULL);
2889 trace("Testing http protocol (to file)...\n");
2890 bindf = BINDF_ASYNCHRONOUS | BINDF_ASYNCSTORAGE | BINDF_PULLDATA | BINDF_FROMURLMON | BINDF_NEEDFILE;
2891 test_http_protocol_url(winetest_url, HTTP_TEST, 0, TYMED_NULL);
2893 trace("Testing http protocol (post data)...\n");
2894 bindf = BINDF_ASYNCHRONOUS | BINDF_ASYNCSTORAGE | BINDF_PULLDATA | BINDF_FROMURLMON;
2895 test_http_protocol_url(posttest_url, HTTP_TEST, TEST_FIRST_HTTP|TEST_POST, TYMED_HGLOBAL);
2897 trace("Testing http protocol (post data stream)...\n");
2898 test_http_protocol_url(posttest_url, HTTP_TEST, TEST_FIRST_HTTP|TEST_POST|TEST_ASYNCREQ, TYMED_ISTREAM);
2900 trace("Testing http protocol (direct read)...\n");
2901 bindf = BINDF_ASYNCHRONOUS | BINDF_ASYNCSTORAGE | BINDF_PULLDATA | BINDF_FROMURLMON;
2902 test_http_protocol_url(winetest_url, HTTP_TEST, TEST_DIRECT_READ|TEST_USEIURI, TYMED_NULL);
2904 trace("Testing http protocol (redirected)...\n");
2905 bindf = BINDF_ASYNCHRONOUS | BINDF_ASYNCSTORAGE | BINDF_PULLDATA | BINDF_FROMURLMON;
2906 test_http_protocol_url(redirect_url, HTTP_TEST, TEST_REDIRECT, TYMED_NULL);
2908 trace("Testing http protocol abort...\n");
2909 test_http_protocol_url(winetest_url, HTTP_TEST, TEST_ABORT, TYMED_NULL);
2911 test_early_abort(&CLSID_HttpProtocol);
2912 test_early_abort(&CLSID_HttpSProtocol);
2915 static void test_https_protocol(void)
2917 static const WCHAR codeweavers_url[] =
2918 {'h','t','t','p','s',':','/','/','w','w','w','.','c','o','d','e','w','e','a','v','e','r','s',
2919 '.','c','o','m','/','t','e','s','t','.','h','t','m','l',0};
2921 trace("Testing https protocol (from urlmon)...\n");
2922 bindf = BINDF_ASYNCHRONOUS | BINDF_ASYNCSTORAGE | BINDF_PULLDATA | BINDF_FROMURLMON | BINDF_NOWRITECACHE;
2923 test_http_protocol_url(codeweavers_url, HTTPS_TEST, TEST_FIRST_HTTP, TYMED_NULL);
2927 static void test_ftp_protocol(void)
2929 IInternetProtocolInfo *protocol_info;
2930 IClassFactory *factory;
2937 static const WCHAR ftp_urlW[] = {'f','t','p',':','/','/','f','t','p','.','w','i','n','e','h','q','.','o','r','g',
2938 '/','p','u','b','/','o','t','h','e','r','/',
2939 'w','i','n','e','l','o','g','o','.','x','c','f','.','t','a','r','.','b','z','2',0};
2941 trace("Testing ftp protocol...\n");
2943 bindf = BINDF_ASYNCHRONOUS | BINDF_ASYNCSTORAGE | BINDF_PULLDATA | BINDF_FROMURLMON | BINDF_NOWRITECACHE;
2944 state = STATE_STARTDOWNLOADING;
2945 tested_protocol = FTP_TEST;
2946 first_data_notif = TRUE;
2947 expect_hrResult = E_PENDING;
2949 hres = CoGetClassObject(&CLSID_FtpProtocol, CLSCTX_INPROC_SERVER, NULL, &IID_IUnknown, (void**)&unk);
2950 ok(hres == S_OK, "CoGetClassObject failed: %08x\n", hres);
2954 hres = IUnknown_QueryInterface(unk, &IID_IInternetProtocolInfo, (void**)&protocol_info);
2955 ok(hres == E_NOINTERFACE, "Could not get IInternetProtocolInfo interface: %08x, expected E_NOINTERFACE\n", hres);
2957 hres = IUnknown_QueryInterface(unk, &IID_IClassFactory, (void**)&factory);
2958 ok(hres == S_OK, "Could not get IClassFactory interface\n");
2959 IUnknown_Release(unk);
2963 hres = IClassFactory_CreateInstance(factory, NULL, &IID_IInternetProtocol,
2964 (void**)&async_protocol);
2965 IClassFactory_Release(factory);
2966 ok(hres == S_OK, "Could not get IInternetProtocol: %08x\n", hres);
2968 test_priority(async_protocol);
2969 test_http_info(async_protocol);
2971 SET_EXPECT(GetBindInfo);
2972 SET_EXPECT(ReportProgress_FINDINGRESOURCE);
2973 SET_EXPECT(ReportProgress_CONNECTING);
2974 SET_EXPECT(ReportProgress_SENDINGREQUEST);
2977 hres = IInternetProtocol_Start(async_protocol, ftp_urlW, &protocol_sink, &bind_info, 0, 0);
2978 ok(hres == S_OK, "Start failed: %08x\n", hres);
2979 CHECK_CALLED(GetBindInfo);
2981 SET_EXPECT(ReportResult);
2983 hres = IInternetProtocol_Read(async_protocol, buf, 1, &cb);
2984 ok((hres == E_PENDING && cb==0) ||
2985 (hres == S_OK && cb==1), "Read failed: %08x (%d bytes)\n", hres, cb);
2987 WaitForSingleObject(event_complete, INFINITE);
2990 hres = IInternetProtocol_Read(async_protocol, buf, sizeof(buf), &cb);
2991 if(hres == E_PENDING)
2992 WaitForSingleObject(event_complete, INFINITE);
2997 ok(hres == S_FALSE, "Read failed: %08x\n", hres);
2998 CHECK_CALLED(ReportResult);
2999 CHECK_CALLED(Switch);
3001 test_protocol_terminate(async_protocol);
3004 IInternetProtocolEx *protocolex;
3006 hres = IInternetProtocol_QueryInterface(async_protocol, &IID_IInternetProtocolEx, (void**)&protocolex);
3007 ok(hres == S_OK, "Could not get IInternetProtocolEx iface: %08x\n", hres);
3008 IInternetProtocolEx_Release(protocolex);
3011 ref = IInternetProtocol_Release(async_protocol);
3012 ok(!ref, "ref=%d\n", ref);
3014 test_early_abort(&CLSID_FtpProtocol);
3017 static void test_gopher_protocol(void)
3019 IInternetProtocolInfo *protocol_info;
3020 IClassFactory *factory;
3024 trace("Testing gopher protocol...\n");
3026 hres = CoGetClassObject(&CLSID_GopherProtocol, CLSCTX_INPROC_SERVER, NULL, &IID_IUnknown, (void**)&unk);
3028 hres == REGDB_E_CLASSNOTREG, /* Gopher protocol has been removed as of Vista */
3029 "CoGetClassObject failed: %08x\n", hres);
3033 hres = IUnknown_QueryInterface(unk, &IID_IInternetProtocolInfo, (void**)&protocol_info);
3034 ok(hres == E_NOINTERFACE, "Could not get IInternetProtocolInfo interface: %08x, expected E_NOINTERFACE\n", hres);
3036 hres = IUnknown_QueryInterface(unk, &IID_IClassFactory, (void**)&factory);
3037 ok(hres == S_OK, "Could not get IClassFactory interface\n");
3038 IUnknown_Release(unk);
3042 hres = IClassFactory_CreateInstance(factory, NULL, &IID_IInternetProtocol,
3043 (void**)&async_protocol);
3044 IClassFactory_Release(factory);
3045 ok(hres == S_OK, "Could not get IInternetProtocol: %08x\n", hres);
3047 test_priority(async_protocol);
3049 IInternetProtocol_Release(async_protocol);
3051 test_early_abort(&CLSID_GopherProtocol);
3054 static void test_mk_protocol(void)
3056 IInternetProtocolInfo *protocol_info;
3057 IInternetProtocol *protocol;
3058 IClassFactory *factory;
3062 static const WCHAR wrong_url1[] = {'t','e','s','t',':','@','M','S','I','T','S','t','o','r','e',
3063 ':',':','/','t','e','s','t','.','h','t','m','l',0};
3064 static const WCHAR wrong_url2[] = {'m','k',':','/','t','e','s','t','.','h','t','m','l',0};
3066 trace("Testing mk protocol...\n");
3067 init_test(MK_TEST, 0);
3069 hres = CoGetClassObject(&CLSID_MkProtocol, CLSCTX_INPROC_SERVER, NULL,
3070 &IID_IUnknown, (void**)&unk);
3071 ok(hres == S_OK, "CoGetClassObject failed: %08x\n", hres);
3073 hres = IUnknown_QueryInterface(unk, &IID_IInternetProtocolInfo, (void**)&protocol_info);
3074 ok(hres == E_NOINTERFACE,
3075 "Could not get IInternetProtocolInfo interface: %08x, expected E_NOINTERFACE\n",
3078 hres = IUnknown_QueryInterface(unk, &IID_IClassFactory, (void**)&factory);
3079 ok(hres == S_OK, "Could not get IClassFactory interface\n");
3080 IUnknown_Release(unk);
3084 hres = IClassFactory_CreateInstance(factory, NULL, &IID_IInternetProtocol,
3086 IClassFactory_Release(factory);
3087 ok(hres == S_OK, "Could not get IInternetProtocol: %08x\n", hres);
3089 SET_EXPECT(GetBindInfo);
3090 hres = IInternetProtocol_Start(protocol, wrong_url1, &protocol_sink, &bind_info, 0, 0);
3091 ok(hres == MK_E_SYNTAX || hres == INET_E_INVALID_URL,
3092 "Start failed: %08x, expected MK_E_SYNTAX or INET_E_INVALID_URL\n", hres);
3093 CLEAR_CALLED(GetBindInfo);
3095 SET_EXPECT(GetBindInfo);
3096 SET_EXPECT(ReportProgress_DIRECTBIND);
3097 SET_EXPECT(ReportProgress_SENDINGREQUEST);
3098 SET_EXPECT(ReportProgress_MIMETYPEAVAILABLE);
3099 SET_EXPECT(ReportResult);
3100 expect_hrResult = INET_E_RESOURCE_NOT_FOUND;
3102 hres = IInternetProtocol_Start(protocol, wrong_url2, &protocol_sink, &bind_info, 0, 0);
3103 ok(hres == INET_E_RESOURCE_NOT_FOUND ||
3104 hres == INET_E_INVALID_URL, /* win2k3 */
3105 "Start failed: %08x, expected INET_E_RESOURCE_NOT_FOUND or INET_E_INVALID_URL\n", hres);
3107 if (hres == INET_E_RESOURCE_NOT_FOUND) {
3108 CHECK_CALLED(GetBindInfo);
3109 CLEAR_CALLED(ReportProgress_DIRECTBIND);
3110 CHECK_CALLED(ReportProgress_SENDINGREQUEST);
3111 CHECK_CALLED(ReportProgress_MIMETYPEAVAILABLE);
3112 CHECK_CALLED(ReportResult);
3114 CLEAR_CALLED(GetBindInfo);
3115 CLEAR_CALLED(ReportProgress_DIRECTBIND);
3116 CLEAR_CALLED(ReportProgress_SENDINGREQUEST);
3117 CLEAR_CALLED(ReportProgress_MIMETYPEAVAILABLE);
3118 CLEAR_CALLED(ReportResult);
3121 IInternetProtocol_Release(protocol);
3124 static void test_CreateBinding(void)
3126 IInternetProtocol *protocol;
3127 IInternetPriority *priority;
3128 IInternetSession *session;
3129 IWinInetHttpInfo *http_info;
3130 IWinInetInfo *inet_info;
3136 static const WCHAR test_url[] =
3137 {'t','e','s','t',':','/','/','f','i','l','e','.','h','t','m','l',0};
3138 static const WCHAR wsz_test[] = {'t','e','s','t',0};
3140 trace("Testing CreateBinding...\n");
3141 init_test(BIND_TEST, TEST_BINDING);
3143 hres = pCoInternetGetSession(0, &session, 0);
3144 ok(hres == S_OK, "CoInternetGetSession failed: %08x\n", hres);
3146 hres = IInternetSession_RegisterNameSpace(session, &ClassFactory, &IID_NULL, wsz_test, 0, NULL, 0);
3147 ok(hres == S_OK, "RegisterNameSpace failed: %08x\n", hres);
3149 hres = IInternetSession_CreateBinding(session, NULL, test_url, NULL, NULL, &protocol, 0);
3150 binding_protocol = protocol;
3151 ok(hres == S_OK, "CreateBinding failed: %08x\n", hres);
3152 ok(protocol != NULL, "protocol == NULL\n");
3154 hres = IInternetProtocol_QueryInterface(protocol, &IID_IInternetBindInfo, (void**)&prot_bind_info);
3155 ok(hres == S_OK, "QueryInterface(IID_IInternetBindInfo) failed: %08x\n", hres);
3157 hres = IInternetProtocol_QueryInterface(protocol, &IID_IInternetProtocolSink, (void**)&binding_sink);
3158 ok(hres == S_OK, "Could not get IInternetProtocolSink: %08x\n", hres);
3160 hres = IInternetProtocol_Start(protocol, test_url, NULL, &bind_info, 0, 0);
3161 ok(hres == E_INVALIDARG, "Start failed: %08x, expected E_INVALIDARG\n", hres);
3162 hres = IInternetProtocol_Start(protocol, test_url, &protocol_sink, NULL, 0, 0);
3163 ok(hres == E_INVALIDARG, "Start failed: %08x, expected E_INVALIDARG\n", hres);
3164 hres = IInternetProtocol_Start(protocol, NULL, &protocol_sink, &bind_info, 0, 0);
3165 ok(hres == E_INVALIDARG, "Start failed: %08x, expected E_INVALIDARG\n", hres);
3167 hres = IInternetProtocol_QueryInterface(protocol, &IID_IInternetPriority, (void**)&priority);
3168 ok(hres == S_OK, "QueryInterface(IID_IInternetPriority) failed: %08x\n", hres);
3171 hres = IInternetPriority_GetPriority(priority, &p);
3172 ok(hres == S_OK, "GetPriority failed: %08x\n", hres);
3173 ok(!p, "p=%d\n", p);
3176 hres = IInternetPriority_SetPriority(priority, 100);
3177 ok(hres == S_OK, "SetPriority failed: %08x\n", hres);
3180 hres = IInternetPriority_GetPriority(priority, &p);
3181 ok(hres == S_OK, "GetPriority failed: %08x\n", hres);
3182 ok(p == 100, "p=%d\n", p);
3184 hres = IInternetProtocol_QueryInterface(protocol, &IID_IWinInetInfo, (void**)&inet_info);
3185 ok(hres == E_NOINTERFACE, "Could not get IWinInetInfo protocol: %08x\n", hres);
3187 SET_EXPECT(QueryService_InternetProtocol);
3188 SET_EXPECT(CreateInstance);
3189 SET_EXPECT(ReportProgress_PROTOCOLCLASSID);
3190 SET_EXPECT(SetPriority);
3193 expect_hrResult = S_OK;
3194 hres = IInternetProtocol_Start(protocol, test_url, &protocol_sink, &bind_info, 0, 0);
3195 ok(hres == S_OK, "Start failed: %08x\n", hres);
3197 CHECK_CALLED(QueryService_InternetProtocol);
3198 CHECK_CALLED(CreateInstance);
3199 CHECK_CALLED(ReportProgress_PROTOCOLCLASSID);
3200 CHECK_CALLED(SetPriority);
3201 CHECK_CALLED(Start);
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_IWinInetInfo);
3209 hres = IInternetProtocol_QueryInterface(protocol, &IID_IWinInetInfo, (void**)&inet_info);
3210 ok(hres == E_NOINTERFACE, "Could not get IWinInetInfo protocol: %08x\n", hres);
3211 CHECK_CALLED(QueryInterface_IWinInetInfo);
3213 SET_EXPECT(QueryInterface_IWinInetHttpInfo);
3214 hres = IInternetProtocol_QueryInterface(protocol, &IID_IWinInetHttpInfo, (void**)&http_info);
3215 ok(hres == E_NOINTERFACE, "Could not get IWinInetInfo protocol: %08x\n", hres);
3216 CHECK_CALLED(QueryInterface_IWinInetHttpInfo);
3220 hres = IInternetProtocol_Read(protocol, expect_pv = buf, sizeof(buf), &read);
3221 ok(hres == S_OK, "Read failed: %08x\n", hres);
3222 ok(read == 100, "read = %d\n", read);
3227 hres = IInternetProtocol_Read(protocol, expect_pv = buf, sizeof(buf), &read);
3228 ok(hres == S_FALSE, "Read failed: %08x\n", hres);
3229 ok(!read, "read = %d\n", read);
3233 hres = IInternetPriority_GetPriority(priority, &p);
3234 ok(hres == S_OK, "GetPriority failed: %08x\n", hres);
3235 ok(p == 100, "p=%d\n", p);
3237 hres = IInternetPriority_SetPriority(priority, 101);
3238 ok(hres == S_OK, "SetPriority failed: %08x\n", hres);
3240 SET_EXPECT(Terminate);
3241 hres = IInternetProtocol_Terminate(protocol, 0xdeadbeef);
3242 ok(hres == S_OK, "Terminate failed: %08x\n", hres);
3243 CHECK_CALLED(Terminate);
3245 SET_EXPECT(Continue);
3246 hres = IInternetProtocolSink_Switch(binding_sink, &protocoldata);
3247 ok(hres == S_OK, "Switch failed: %08x\n", hres);
3248 CHECK_CALLED(Continue);
3250 hres = IInternetProtocolSink_ReportProgress(binding_sink,
3251 BINDSTATUS_CACHEFILENAMEAVAILABLE, expect_wsz = emptyW);
3252 ok(hres == S_OK, "ReportProgress(BINDSTATUS_CACHEFILENAMEAVAILABLE) failed: %08x\n", hres);
3254 hres = IInternetProtocolSink_ReportResult(binding_sink, S_OK, ERROR_SUCCESS, NULL);
3255 ok(hres == E_FAIL, "ReportResult failed: %08x, expected E_FAIL\n", hres);
3257 hres = IInternetProtocolSink_ReportData(binding_sink, 0, 0, 0);
3258 ok(hres == S_OK, "ReportData failed: %08x\n", hres);
3260 IInternetProtocolSink_Release(binding_sink);
3261 IInternetPriority_Release(priority);
3262 IInternetBindInfo_Release(prot_bind_info);
3263 IInternetProtocol_Release(protocol);
3265 hres = IInternetSession_CreateBinding(session, NULL, test_url, NULL, NULL, &protocol, 0);
3266 ok(hres == S_OK, "CreateBinding failed: %08x\n", hres);
3267 ok(protocol != NULL, "protocol == NULL\n");
3269 hres = IInternetProtocol_Abort(protocol, E_ABORT, 0);
3270 ok(hres == S_OK, "Abort failed: %08x\n", hres);
3272 hres = IInternetProtocol_Abort(protocol, E_FAIL, 0);
3273 ok(hres == S_OK, "Abort failed: %08x\n", hres);
3275 IInternetProtocol_Release(protocol);
3277 hres = IInternetSession_UnregisterNameSpace(session, &ClassFactory, wsz_test);
3278 ok(hres == S_OK, "UnregisterNameSpace failed: %08x\n", hres);
3280 hres = IInternetSession_CreateBinding(session, NULL, test_url, NULL, NULL, &protocol, 0);
3281 ok(hres == S_OK, "CreateBinding failed: %08x\n", hres);
3282 ok(protocol != NULL, "protocol == NULL\n");
3284 SET_EXPECT(QueryService_InternetProtocol);
3285 hres = IInternetProtocol_Start(protocol, test_url, &protocol_sink, &bind_info, 0, 0);
3286 ok(hres == MK_E_SYNTAX, "Start failed: %08x, expected MK_E_SYNTAX\n", hres);
3287 CHECK_CALLED(QueryService_InternetProtocol);
3289 IInternetProtocol_Release(protocol);
3291 IInternetSession_Release(session);
3294 static void test_binding(int prot, DWORD grf_pi, DWORD test_flags)
3296 IInternetProtocolEx *protocolex = NULL;
3297 IInternetProtocol *protocol;
3298 IInternetSession *session;
3305 init_test(prot, test_flags|TEST_BINDING);
3307 hres = pCoInternetGetSession(0, &session, 0);
3308 ok(hres == S_OK, "CoInternetGetSession failed: %08x\n", hres);
3310 if(test_flags & TEST_EMULATEPROT) {
3311 hres = IInternetSession_RegisterNameSpace(session, &ClassFactory, &IID_NULL, protocol_names[prot], 0, NULL, 0);
3312 ok(hres == S_OK, "RegisterNameSpace failed: %08x\n", hres);
3315 hres = IInternetSession_CreateBinding(session, NULL, binding_urls[prot], NULL, NULL, &protocol, 0);
3316 binding_protocol = protocol;
3317 ok(hres == S_OK, "CreateBinding failed: %08x\n", hres);
3318 ok(protocol != NULL, "protocol == NULL\n");
3320 hres = IInternetProtocol_QueryInterface(protocol, &IID_IInternetBindInfo, (void**)&prot_bind_info);
3321 ok(hres == S_OK, "QueryInterface(IID_IInternetBindInfo) failed: %08x\n", hres);
3323 hres = IInternetProtocol_QueryInterface(protocol, &IID_IInternetProtocolSink, (void**)&binding_sink);
3324 ok(hres == S_OK, "QueryInterface(IID_IInternetProtocolSink) failed: %08x\n", hres);
3326 if(test_flags & TEST_USEIURI) {
3327 hres = IInternetProtocol_QueryInterface(protocol, &IID_IInternetProtocolEx, (void**)&protocolex);
3328 ok(hres == S_OK, "Could not get IInternetProtocolEx iface: %08x\n", hres);
3330 hres = pCreateUri(binding_urls[prot], Uri_CREATE_FILE_USE_DOS_PATH, 0, &uri);
3331 ok(hres == S_OK, "CreateUri failed: %08x\n", hres);
3335 SET_EXPECT(QueryService_InternetProtocol);
3336 SET_EXPECT(CreateInstance);
3337 SET_EXPECT(ReportProgress_PROTOCOLCLASSID);
3338 SET_EXPECT(SetPriority);
3340 SET_EXPECT(StartEx);
3344 expect_hrResult = S_OK;
3347 hres = IInternetProtocolEx_StartEx(protocolex, uri, &protocol_sink, &bind_info, pi, 0);
3348 ok(hres == S_OK, "StartEx failed: %08x\n", hres);
3350 hres = IInternetProtocol_Start(protocol, binding_urls[prot], &protocol_sink, &bind_info, pi, 0);
3351 ok(hres == S_OK, "Start failed: %08x\n", hres);
3354 CHECK_CALLED(QueryService_InternetProtocol);
3355 CHECK_CALLED(CreateInstance);
3356 CHECK_CALLED(ReportProgress_PROTOCOLCLASSID);
3357 CHECK_CALLED(SetPriority);
3359 CHECK_CALLED(StartEx);
3361 CHECK_CALLED(Start);
3364 IInternetProtocolEx_Release(protocolex);
3368 if(prot == HTTP_TEST || prot == HTTPS_TEST) {
3369 while(prot_state < 4) {
3370 WaitForSingleObject(event_complete, INFINITE);
3371 if(mimefilter_test && filtered_protocol) {
3372 SET_EXPECT(Continue);
3373 IInternetProtocol_Continue(filtered_protocol, pdata);
3374 CHECK_CALLED(Continue);
3376 SET_EXPECT(Continue);
3377 IInternetProtocol_Continue(protocol, pdata);
3378 CHECK_CALLED(Continue);
3380 if(test_abort && prot_state == 2) {
3382 hres = IInternetProtocol_Abort(protocol, E_ABORT, 0);
3383 ok(hres == S_OK, "Abort failed: %08x\n", hres);
3384 CHECK_CALLED(Abort);
3386 hres = IInternetProtocol_Abort(protocol, E_ABORT, 0);
3387 ok(hres == S_OK, "Abort failed: %08x\n", hres);
3388 SetEvent(event_complete2);
3391 SetEvent(event_complete2);
3394 CHECK_CALLED(ReportData); /* Set in ReportResult */
3395 WaitForSingleObject(event_complete, INFINITE);
3398 SET_EXPECT(MimeFilter_LockRequest);
3400 SET_EXPECT(LockRequest);
3401 hres = IInternetProtocol_LockRequest(protocol, 0);
3402 ok(hres == S_OK, "LockRequest failed: %08x\n", hres);
3404 CHECK_CALLED(MimeFilter_LockRequest);
3406 CHECK_CALLED(LockRequest);
3409 SET_EXPECT(MimeFilter_UnlockRequest);
3411 SET_EXPECT(UnlockRequest);
3412 hres = IInternetProtocol_UnlockRequest(protocol);
3413 ok(hres == S_OK, "UnlockRequest failed: %08x\n", hres);
3415 CHECK_CALLED(MimeFilter_UnlockRequest);
3417 CHECK_CALLED(UnlockRequest);
3421 SET_EXPECT(MimeFilter_Terminate);
3423 SET_EXPECT(Terminate);
3424 hres = IInternetProtocol_Terminate(protocol, 0);
3425 ok(hres == S_OK, "Terminate failed: %08x\n", hres);
3427 CLEAR_CALLED(MimeFilter_Terminate);
3429 CHECK_CALLED(Terminate);
3431 if(filtered_protocol)
3432 IInternetProtocol_Release(filtered_protocol);
3433 IInternetBindInfo_Release(prot_bind_info);
3434 IInternetProtocolSink_Release(binding_sink);
3435 ref = IInternetProtocol_Release(protocol);
3436 ok(!ref, "ref=%u, expected 0\n", ref);
3438 if(test_flags & TEST_EMULATEPROT) {
3439 hres = IInternetSession_UnregisterNameSpace(session, &ClassFactory, protocol_names[prot]);
3440 ok(hres == S_OK, "UnregisterNameSpace failed: %08x\n", hres);
3443 IInternetSession_Release(session);
3446 START_TEST(protocol)
3450 hurlmon = GetModuleHandle("urlmon.dll");
3451 pCoInternetGetSession = (void*) GetProcAddress(hurlmon, "CoInternetGetSession");
3452 pReleaseBindInfo = (void*) GetProcAddress(hurlmon, "ReleaseBindInfo");
3453 pCreateUri = (void*) GetProcAddress(hurlmon, "CreateUri");
3455 if(!GetProcAddress(hurlmon, "CompareSecurityIds")) {
3456 win_skip("Various needed functions not present, too old IE\n");
3461 win_skip("CreateUri not supported\n");
3463 OleInitialize(NULL);
3465 event_complete = CreateEvent(NULL, FALSE, FALSE, NULL);
3466 event_complete2 = CreateEvent(NULL, FALSE, FALSE, NULL);
3467 event_continue = CreateEvent(NULL, FALSE, FALSE, NULL);
3468 event_continue_done = CreateEvent(NULL, FALSE, FALSE, NULL);
3469 thread_id = GetCurrentThreadId();
3471 test_file_protocol();
3472 test_http_protocol();
3473 test_https_protocol();
3474 test_ftp_protocol();
3475 test_gopher_protocol();
3477 test_CreateBinding();
3479 bindf &= ~BINDF_FROMURLMON;
3480 trace("Testing file binding (mime verification, emulate prot)...\n");
3481 test_binding(FILE_TEST, PI_MIMEVERIFICATION, TEST_EMULATEPROT);
3482 trace("Testing http binding (mime verification, emulate prot)...\n");
3483 test_binding(HTTP_TEST, PI_MIMEVERIFICATION, TEST_EMULATEPROT);
3484 trace("Testing its binding (mime verification, emulate prot)...\n");
3485 test_binding(ITS_TEST, PI_MIMEVERIFICATION, TEST_EMULATEPROT);
3486 trace("Testing http binding (mime verification, emulate prot, short read, direct read)...\n");
3487 test_binding(HTTP_TEST, PI_MIMEVERIFICATION, TEST_EMULATEPROT|TEST_SHORT_READ|TEST_DIRECT_READ);
3488 trace("Testing file binding (mime verification, emulate prot, mime filter)...\n");
3489 test_binding(FILE_TEST, PI_MIMEVERIFICATION, TEST_EMULATEPROT|TEST_FILTER);
3490 trace("Testing http binding (mime verification, emulate prot, mime filter)...\n");
3491 test_binding(HTTP_TEST, PI_MIMEVERIFICATION, TEST_EMULATEPROT|TEST_FILTER);
3492 trace("Testing http binding (mime verification, emulate prot, direct read)...\n");
3493 test_binding(HTTP_TEST, PI_MIMEVERIFICATION, TEST_EMULATEPROT|TEST_DIRECT_READ);
3494 trace("Testing http binding (mime verification, emulate prot, abort)...\n");
3495 test_binding(HTTP_TEST, PI_MIMEVERIFICATION, TEST_EMULATEPROT|TEST_ABORT);
3497 trace("Testing file binding (use IUri, mime verification, emulate prot)...\n");
3498 test_binding(FILE_TEST, PI_MIMEVERIFICATION, TEST_EMULATEPROT|TEST_USEIURI);
3499 trace("Testing file binding (use IUri, impl StartEx, mime verification, emulate prot)...\n");
3500 test_binding(FILE_TEST, PI_MIMEVERIFICATION, TEST_EMULATEPROT|TEST_USEIURI|TEST_IMPLPROTEX);
3501 trace("Testing file binding (impl StartEx, mime verification, emulate prot)...\n");
3502 test_binding(FILE_TEST, PI_MIMEVERIFICATION, TEST_EMULATEPROT|TEST_IMPLPROTEX);
3505 CloseHandle(event_complete);
3506 CloseHandle(event_complete2);
3507 CloseHandle(event_continue);
3508 CloseHandle(event_continue_done);