2 * Copyright 2005-2009 Jacek Caban for CodeWeavers
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
22 #include <wine/test.h>
32 static HRESULT (WINAPI *pCoInternetGetSession)(DWORD, IInternetSession **, DWORD);
33 static HRESULT (WINAPI *pReleaseBindInfo)(BINDINFO*);
34 static HRESULT (WINAPI *pCreateUri)(LPCWSTR, DWORD, DWORD_PTR, IUri**);
36 #define DEFINE_EXPECT(func) \
37 static BOOL expect_ ## func = FALSE, called_ ## func = FALSE
39 #define SET_EXPECT(func) \
40 expect_ ## func = TRUE
42 #define CHECK_EXPECT2(func) \
44 ok(expect_ ##func, "unexpected call " #func "\n"); \
45 called_ ## func = TRUE; \
48 #define CHECK_EXPECT(func) \
50 CHECK_EXPECT2(func); \
51 expect_ ## func = FALSE; \
54 #define CHECK_CALLED(func) \
56 ok(called_ ## func, "expected " #func "\n"); \
57 expect_ ## func = called_ ## func = FALSE; \
60 #define CHECK_NOT_CALLED(func) \
62 ok(!called_ ## func, "unexpected " #func "\n"); \
63 expect_ ## func = called_ ## func = FALSE; \
66 #define CLEAR_CALLED(func) \
67 expect_ ## func = called_ ## func = FALSE
69 DEFINE_EXPECT(GetBindInfo);
70 DEFINE_EXPECT(ReportProgress_MIMETYPEAVAILABLE);
71 DEFINE_EXPECT(ReportProgress_DIRECTBIND);
72 DEFINE_EXPECT(ReportProgress_RAWMIMETYPE);
73 DEFINE_EXPECT(ReportProgress_FINDINGRESOURCE);
74 DEFINE_EXPECT(ReportProgress_CONNECTING);
75 DEFINE_EXPECT(ReportProgress_SENDINGREQUEST);
76 DEFINE_EXPECT(ReportProgress_CACHEFILENAMEAVAILABLE);
77 DEFINE_EXPECT(ReportProgress_VERIFIEDMIMETYPEAVAILABLE);
78 DEFINE_EXPECT(ReportProgress_PROTOCOLCLASSID);
79 DEFINE_EXPECT(ReportProgress_COOKIE_SENT);
80 DEFINE_EXPECT(ReportProgress_REDIRECTING);
81 DEFINE_EXPECT(ReportProgress_ENCODING);
82 DEFINE_EXPECT(ReportProgress_ACCEPTRANGES);
83 DEFINE_EXPECT(ReportProgress_PROXYDETECTING);
84 DEFINE_EXPECT(ReportProgress_LOADINGMIMEHANDLER);
85 DEFINE_EXPECT(ReportProgress_DECODING);
86 DEFINE_EXPECT(ReportData);
87 DEFINE_EXPECT(ReportData2);
88 DEFINE_EXPECT(ReportResult);
89 DEFINE_EXPECT(GetBindString_ACCEPT_MIMES);
90 DEFINE_EXPECT(GetBindString_USER_AGENT);
91 DEFINE_EXPECT(GetBindString_POST_COOKIE);
92 DEFINE_EXPECT(GetBindString_URL);
93 DEFINE_EXPECT(QueryService_HttpNegotiate);
94 DEFINE_EXPECT(QueryService_InternetProtocol);
95 DEFINE_EXPECT(QueryService_HttpSecurity);
96 DEFINE_EXPECT(QueryInterface_IWinInetInfo);
97 DEFINE_EXPECT(QueryInterface_IWinInetHttpInfo);
98 DEFINE_EXPECT(BeginningTransaction);
99 DEFINE_EXPECT(GetRootSecurityId);
100 DEFINE_EXPECT(OnResponse);
101 DEFINE_EXPECT(Switch);
102 DEFINE_EXPECT(Continue);
103 DEFINE_EXPECT(CreateInstance);
104 DEFINE_EXPECT(Start);
105 DEFINE_EXPECT(Terminate);
107 DEFINE_EXPECT(Read2);
108 DEFINE_EXPECT(SetPriority);
109 DEFINE_EXPECT(LockRequest);
110 DEFINE_EXPECT(UnlockRequest);
111 DEFINE_EXPECT(Abort);
112 DEFINE_EXPECT(MimeFilter_CreateInstance);
113 DEFINE_EXPECT(MimeFilter_Start);
114 DEFINE_EXPECT(MimeFilter_ReportProgress);
115 DEFINE_EXPECT(MimeFilter_ReportData);
116 DEFINE_EXPECT(MimeFilter_ReportResult);
117 DEFINE_EXPECT(MimeFilter_Terminate);
118 DEFINE_EXPECT(MimeFilter_LockRequest);
119 DEFINE_EXPECT(MimeFilter_UnlockRequest);
120 DEFINE_EXPECT(MimeFilter_Read);
121 DEFINE_EXPECT(MimeFilter_Switch);
122 DEFINE_EXPECT(MimeFilter_Continue);
123 DEFINE_EXPECT(Stream_Seek);
124 DEFINE_EXPECT(Stream_Read);
126 static const WCHAR wszIndexHtml[] = {'i','n','d','e','x','.','h','t','m','l',0};
127 static const WCHAR index_url[] =
128 {'f','i','l','e',':','i','n','d','e','x','.','h','t','m','l',0};
130 static const WCHAR acc_mimeW[] = {'*','/','*',0};
131 static const WCHAR user_agentW[] = {'W','i','n','e',0};
132 static const WCHAR text_htmlW[] = {'t','e','x','t','/','h','t','m','l',0};
133 static const WCHAR hostW[] = {'w','w','w','.','w','i','n','e','h','q','.','o','r','g',0};
134 static const WCHAR winehq_ipW[] = {'2','0','9','.','4','6','.','2','5','.','1','3','4',0};
135 static const WCHAR emptyW[] = {0};
136 static const WCHAR gzipW[] = {'g','z','i','p',0};
138 static HRESULT expect_hrResult;
139 static LPCWSTR file_name, http_url, expect_wsz;
140 static IInternetProtocol *async_protocol = NULL;
141 static BOOL first_data_notif, http_is_first, test_redirect;
142 static int prot_state, read_report_data, post_stream_read;
143 static DWORD bindf, ex_priority , pi;
144 static IInternetProtocol *binding_protocol, *filtered_protocol;
145 static IInternetBindInfo *prot_bind_info;
146 static IInternetProtocolSink *binding_sink, *filtered_sink;
147 static void *expect_pv;
148 static HANDLE event_complete, event_complete2, event_continue, event_continue_done;
149 static BOOL binding_test;
150 static PROTOCOLDATA protocoldata, *pdata, continue_protdata;
151 static DWORD prot_read, pi, filter_state, http_post_test, thread_id;
152 static BOOL security_problem, test_async_req;
153 static BOOL async_read_pending, mimefilter_test, direct_read, wait_for_switch, emulate_prot, short_read, test_abort;
157 STATE_SENDINGREQUEST,
158 STATE_STARTDOWNLOADING,
171 static const WCHAR protocol_names[][10] = {
174 {'h','t','t','p','s',0},
180 static const WCHAR binding_urls[][130] = {
181 {'f','i','l','e',':','t','e','s','t','.','h','t','m','l',0},
182 {'h','t','t','p',':','/','/','w','w','w','.','w','i','n','e','h','q','.',
183 'o','r','g','/','s','i','t','e','/','a','b','o','u','t',0},
184 {'h','t','t','p','s',':','/','/','w','w','w','.','c','o','d','e','w','e','a','v','e','r','s',
185 '.','c','o','m','/','t','e','s','t','.','h','t','m','l',0},
186 {'f','t','p',':','/','/','f','t','p','.','w','i','n','e','h','q','.','o','r','g',
187 '/','p','u','b','/','o','t','h','e','r',
188 '/','w','i','n','e','l','o','g','o','.','x','c','f','.','t','a','r','.','b','z','2',0},
189 {'m','k',':','t','e','s','t',0},
190 {'t','e','s','t',':','/','/','f','i','l','e','.','h','t','m','l',0}
193 static const CHAR post_data[] = "mode=Test";
195 static const char *debugstr_guid(REFIID riid)
199 sprintf(buf, "{%08X-%04X-%04X-%02X%02X-%02X%02X%02X%02X%02X%02X}",
200 riid->Data1, riid->Data2, riid->Data3, riid->Data4[0],
201 riid->Data4[1], riid->Data4[2], riid->Data4[3], riid->Data4[4],
202 riid->Data4[5], riid->Data4[6], riid->Data4[7]);
207 static int strcmp_wa(LPCWSTR strw, const char *stra)
210 WideCharToMultiByte(CP_ACP, 0, strw, -1, buf, sizeof(buf), NULL, NULL);
211 return lstrcmpA(stra, buf);
214 /* lstrcmpW is not implemented on Win9x */
215 static int strcmp_ww(LPCWSTR strw1, LPCWSTR strw2)
217 CHAR stra1[512], stra2[512];
218 WideCharToMultiByte(CP_ACP, 0, strw1, -1, stra1, MAX_PATH, NULL, NULL);
219 WideCharToMultiByte(CP_ACP, 0, strw2, -1, stra2, MAX_PATH, NULL, NULL);
220 return lstrcmpA(stra1, stra2);
223 static HRESULT WINAPI HttpSecurity_QueryInterface(IHttpSecurity *iface, REFIID riid, void **ppv)
225 if(IsEqualGUID(&IID_IUnknown, riid)
226 || IsEqualGUID(&IID_IHttpSecurity, riid)) {
231 ok(0, "unexpected call\n");
232 return E_NOINTERFACE;
235 static ULONG WINAPI HttpSecurity_AddRef(IHttpSecurity *iface)
240 static ULONG WINAPI HttpSecurity_Release(IHttpSecurity *iface)
245 static HRESULT WINAPI HttpSecurity_GetWindow(IHttpSecurity* iface, REFGUID rguidReason, HWND *phwnd)
247 trace("HttpSecurity_GetWindow\n");
252 static HRESULT WINAPI HttpSecurity_OnSecurityProblem(IHttpSecurity *iface, DWORD dwProblem)
254 trace("Security problem: %u\n", dwProblem);
255 ok(dwProblem == ERROR_INTERNET_SEC_CERT_REV_FAILED, "Expected ERROR_INTERNET_SEC_CERT_REV_FAILED got %u\n", dwProblem);
257 /* Only retry once */
258 if (security_problem)
261 security_problem = TRUE;
262 SET_EXPECT(BeginningTransaction);
267 static IHttpSecurityVtbl HttpSecurityVtbl = {
268 HttpSecurity_QueryInterface,
270 HttpSecurity_Release,
271 HttpSecurity_GetWindow,
272 HttpSecurity_OnSecurityProblem
275 static IHttpSecurity http_security = { &HttpSecurityVtbl };
277 static HRESULT WINAPI HttpNegotiate_QueryInterface(IHttpNegotiate2 *iface, REFIID riid, void **ppv)
279 if(IsEqualGUID(&IID_IUnknown, riid)
280 || IsEqualGUID(&IID_IHttpNegotiate, riid)
281 || IsEqualGUID(&IID_IHttpNegotiate2, riid)) {
286 ok(0, "unexpected call\n");
287 return E_NOINTERFACE;
290 static ULONG WINAPI HttpNegotiate_AddRef(IHttpNegotiate2 *iface)
295 static ULONG WINAPI HttpNegotiate_Release(IHttpNegotiate2 *iface)
300 static HRESULT WINAPI HttpNegotiate_BeginningTransaction(IHttpNegotiate2 *iface, LPCWSTR szURL,
301 LPCWSTR szHeaders, DWORD dwReserved, LPWSTR *pszAdditionalHeaders)
305 static const WCHAR wszHeaders[] =
306 {'C','o','n','t','e','n','t','-','T','y','p','e',':',' ','a','p','p','l','i','c','a','t',
307 'i','o','n','/','x','-','w','w','w','-','f','o','r','m','-','u','r','l','e','n','c','o',
308 'd','e','d','\r','\n',0};
310 CHECK_EXPECT(BeginningTransaction);
313 ok(!strcmp_ww(szURL, binding_urls[tested_protocol]), "szURL != http_url\n");
315 ok(!strcmp_ww(szURL, http_url), "szURL != http_url\n");
316 ok(!dwReserved, "dwReserved=%d, expected 0\n", dwReserved);
317 ok(pszAdditionalHeaders != NULL, "pszAdditionalHeaders == NULL\n");
318 if(pszAdditionalHeaders)
320 ok(*pszAdditionalHeaders == NULL, "*pszAdditionalHeaders != NULL\n");
323 addl_headers = CoTaskMemAlloc(sizeof(wszHeaders));
324 memcpy(addl_headers, wszHeaders, sizeof(wszHeaders));
325 *pszAdditionalHeaders = addl_headers;
332 static HRESULT WINAPI HttpNegotiate_OnResponse(IHttpNegotiate2 *iface, DWORD dwResponseCode,
333 LPCWSTR szResponseHeaders, LPCWSTR szRequestHeaders, LPWSTR *pszAdditionalRequestHeaders)
335 CHECK_EXPECT(OnResponse);
337 ok(dwResponseCode == 200, "dwResponseCode=%d, expected 200\n", dwResponseCode);
338 ok(szResponseHeaders != NULL, "szResponseHeaders == NULL\n");
339 ok(szRequestHeaders == NULL, "szRequestHeaders != NULL\n");
340 ok(pszAdditionalRequestHeaders == NULL, "pszAdditionalHeaders != NULL\n");
345 static HRESULT WINAPI HttpNegotiate_GetRootSecurityId(IHttpNegotiate2 *iface,
346 BYTE *pbSecurityId, DWORD *pcbSecurityId, DWORD_PTR dwReserved)
348 static const BYTE sec_id[] = {'h','t','t','p',':','t','e','s','t',1,0,0,0};
350 CHECK_EXPECT(GetRootSecurityId);
352 ok(!dwReserved, "dwReserved=%ld, expected 0\n", dwReserved);
353 ok(pbSecurityId != NULL, "pbSecurityId == NULL\n");
354 ok(pcbSecurityId != NULL, "pcbSecurityId == NULL\n");
357 ok(*pcbSecurityId == 512, "*pcbSecurityId=%d, expected 512\n", *pcbSecurityId);
358 *pcbSecurityId = sizeof(sec_id);
362 memcpy(pbSecurityId, sec_id, sizeof(sec_id));
367 static IHttpNegotiate2Vtbl HttpNegotiateVtbl = {
368 HttpNegotiate_QueryInterface,
369 HttpNegotiate_AddRef,
370 HttpNegotiate_Release,
371 HttpNegotiate_BeginningTransaction,
372 HttpNegotiate_OnResponse,
373 HttpNegotiate_GetRootSecurityId
376 static IHttpNegotiate2 http_negotiate = { &HttpNegotiateVtbl };
378 static HRESULT QueryInterface(REFIID,void**);
380 static HRESULT WINAPI ServiceProvider_QueryInterface(IServiceProvider *iface, REFIID riid, void **ppv)
382 return QueryInterface(riid, ppv);
385 static ULONG WINAPI ServiceProvider_AddRef(IServiceProvider *iface)
390 static ULONG WINAPI ServiceProvider_Release(IServiceProvider *iface)
395 static HRESULT WINAPI ServiceProvider_QueryService(IServiceProvider *iface, REFGUID guidService,
396 REFIID riid, void **ppv)
398 if(IsEqualGUID(&IID_IHttpNegotiate, guidService) || IsEqualGUID(&IID_IHttpNegotiate2, riid)) {
399 CHECK_EXPECT2(QueryService_HttpNegotiate);
400 return IHttpNegotiate2_QueryInterface(&http_negotiate, riid, ppv);
403 if(IsEqualGUID(&IID_IInternetProtocol, guidService)) {
404 ok(IsEqualGUID(&IID_IInternetProtocol, riid), "unexpected riid\n");
405 CHECK_EXPECT(QueryService_InternetProtocol);
406 return E_NOINTERFACE;
409 if(IsEqualGUID(&IID_IHttpSecurity, guidService)) {
410 ok(IsEqualGUID(&IID_IHttpSecurity, riid), "unexpected riid\n");
411 CHECK_EXPECT(QueryService_HttpSecurity);
412 return IHttpSecurity_QueryInterface(&http_security, riid, ppv);
415 ok(0, "unexpected service %s\n", debugstr_guid(guidService));
419 static const IServiceProviderVtbl ServiceProviderVtbl = {
420 ServiceProvider_QueryInterface,
421 ServiceProvider_AddRef,
422 ServiceProvider_Release,
423 ServiceProvider_QueryService
426 static IServiceProvider service_provider = { &ServiceProviderVtbl };
428 static HRESULT WINAPI Stream_QueryInterface(IStream *iface, REFIID riid, void **ppv)
430 ok(0, "unexpected call\n");
431 return E_NOINTERFACE;
434 static ULONG WINAPI Stream_AddRef(IStream *iface)
439 static ULONG WINAPI Stream_Release(IStream *iface)
444 static HRESULT WINAPI Stream_Read(IStream *iface, void *pv,
445 ULONG cb, ULONG *pcbRead)
447 CHECK_EXPECT2(Stream_Read);
449 ok(GetCurrentThreadId() != thread_id, "wrong thread %d\n", GetCurrentThreadId());
451 ok(pv != NULL, "pv == NULL\n");
452 ok(cb == 0x20000 || broken(cb == 0x2000), "cb = %d\n", cb);
453 ok(pcbRead != NULL, "pcbRead == NULL\n");
455 if(post_stream_read) {
460 memcpy(pv, post_data, sizeof(post_data)-1);
461 post_stream_read += *pcbRead = sizeof(post_data)-1;
465 static HRESULT WINAPI Stream_Write(IStream *iface, const void *pv,
466 ULONG cb, ULONG *pcbWritten)
468 ok(0, "unexpected call\n");
472 static HRESULT WINAPI Stream_Seek(IStream *iface, LARGE_INTEGER dlibMove,
473 DWORD dwOrigin, ULARGE_INTEGER *plibNewPosition)
475 CHECK_EXPECT(Stream_Seek);
477 ok(!dlibMove.QuadPart, "dlibMove != 0\n");
478 ok(dwOrigin == STREAM_SEEK_SET, "dwOrigin = %d\n", dwOrigin);
479 ok(!plibNewPosition, "plibNewPosition == NULL\n");
484 static HRESULT WINAPI Stream_SetSize(IStream *iface, ULARGE_INTEGER libNewSize)
486 ok(0, "unexpected call\n");
490 static HRESULT WINAPI Stream_CopyTo(IStream *iface, IStream *pstm,
491 ULARGE_INTEGER cb, ULARGE_INTEGER *pcbRead, ULARGE_INTEGER *pcbWritten)
493 ok(0, "unexpected call\n");
497 static HRESULT WINAPI Stream_Commit(IStream *iface, DWORD grfCommitFlags)
499 ok(0, "unexpected call\n");
503 static HRESULT WINAPI Stream_Revert(IStream *iface)
505 ok(0, "unexpected call\n");
509 static HRESULT WINAPI Stream_LockRegion(IStream *iface, ULARGE_INTEGER libOffset,
510 ULARGE_INTEGER cb, DWORD dwLockType)
512 ok(0, "unexpected call\n");
516 static HRESULT WINAPI Stream_UnlockRegion(IStream *iface,
517 ULARGE_INTEGER libOffset, ULARGE_INTEGER cb, DWORD dwLockType)
519 ok(0, "unexpected call\n");
523 static HRESULT WINAPI Stream_Stat(IStream *iface, STATSTG *pstatstg,
526 ok(0, "unexpected call\n");
530 static HRESULT WINAPI Stream_Clone(IStream *iface, IStream **ppstm)
532 ok(0, "unexpected call\n");
536 static const IStreamVtbl StreamVtbl = {
537 Stream_QueryInterface,
553 static IStream Stream = { &StreamVtbl };
555 static HRESULT WINAPI ProtocolSink_QueryInterface(IInternetProtocolSink *iface, REFIID riid, void **ppv)
557 return QueryInterface(riid, ppv);
560 static ULONG WINAPI ProtocolSink_AddRef(IInternetProtocolSink *iface)
565 static ULONG WINAPI ProtocolSink_Release(IInternetProtocolSink *iface)
570 static void call_continue(PROTOCOLDATA *protocol_data)
574 if(state == STATE_CONNECTING) {
575 if(tested_protocol == HTTP_TEST || tested_protocol == HTTPS_TEST)
576 CLEAR_CALLED(ReportProgress_COOKIE_SENT);
577 if(tested_protocol == HTTP_TEST || tested_protocol == HTTPS_TEST || tested_protocol == FTP_TEST) {
579 CLEAR_CALLED(ReportProgress_FINDINGRESOURCE);
580 CLEAR_CALLED(ReportProgress_CONNECTING);
581 CLEAR_CALLED(ReportProgress_PROXYDETECTING);
582 }else if(test_redirect) {
583 CHECK_CALLED(ReportProgress_FINDINGRESOURCE);
585 CHECK_NOT_CALLED(ReportProgress_FINDINGRESOURCE);
586 /* IE7 does call this */
587 CLEAR_CALLED(ReportProgress_CONNECTING);
590 if(tested_protocol == FTP_TEST)
591 todo_wine CHECK_CALLED(ReportProgress_SENDINGREQUEST);
592 else if (tested_protocol != HTTPS_TEST)
593 CHECK_CALLED(ReportProgress_SENDINGREQUEST);
595 CHECK_CALLED(ReportProgress_REDIRECTING);
596 state = test_async_req ? STATE_SENDINGREQUEST : STATE_STARTDOWNLOADING;
600 case STATE_SENDINGREQUEST:
601 SET_EXPECT(Stream_Read);
602 SET_EXPECT(ReportProgress_SENDINGREQUEST);
604 case STATE_STARTDOWNLOADING:
605 if(tested_protocol == HTTP_TEST || tested_protocol == HTTPS_TEST) {
606 SET_EXPECT(OnResponse);
607 if(tested_protocol == HTTPS_TEST || test_redirect)
608 SET_EXPECT(ReportProgress_ACCEPTRANGES);
609 SET_EXPECT(ReportProgress_MIMETYPEAVAILABLE);
610 if(bindf & BINDF_NEEDFILE)
611 SET_EXPECT(ReportProgress_CACHEFILENAMEAVAILABLE);
617 if(state != STATE_SENDINGREQUEST)
618 SET_EXPECT(ReportData);
619 hres = IInternetProtocol_Continue(async_protocol, protocol_data);
620 ok(hres == S_OK, "Continue failed: %08x\n", hres);
621 if(tested_protocol == FTP_TEST || security_problem)
622 CLEAR_CALLED(ReportData);
623 else if(state != STATE_SENDINGREQUEST)
624 CHECK_CALLED(ReportData);
627 case STATE_SENDINGREQUEST:
628 CHECK_CALLED(Stream_Read);
629 CHECK_CALLED(ReportProgress_SENDINGREQUEST);
630 state = STATE_STARTDOWNLOADING;
632 case STATE_STARTDOWNLOADING:
633 if (! security_problem)
635 state = STATE_DOWNLOADING;
636 if(tested_protocol == HTTP_TEST || tested_protocol == HTTPS_TEST) {
637 CHECK_CALLED(OnResponse);
638 if(tested_protocol == HTTPS_TEST)
639 CHECK_CALLED(ReportProgress_ACCEPTRANGES);
640 else if(test_redirect)
641 CLEAR_CALLED(ReportProgress_ACCEPTRANGES);
642 CHECK_CALLED(ReportProgress_MIMETYPEAVAILABLE);
643 if(bindf & BINDF_NEEDFILE)
644 CHECK_CALLED(ReportProgress_CACHEFILENAMEAVAILABLE);
649 security_problem = FALSE;
650 SET_EXPECT(ReportProgress_CONNECTING);
657 static HRESULT WINAPI ProtocolSink_Switch(IInternetProtocolSink *iface, PROTOCOLDATA *pProtocolData)
659 if(tested_protocol == FTP_TEST)
660 CHECK_EXPECT2(Switch);
662 CHECK_EXPECT(Switch);
664 ok(pProtocolData != NULL, "pProtocolData == NULL\n");
666 ok(pProtocolData != &protocoldata, "pProtocolData == &protocoldata\n");
667 ok(pProtocolData->grfFlags == protocoldata.grfFlags, "grfFlags wrong %x/%x\n",
668 pProtocolData->grfFlags, protocoldata.grfFlags );
669 ok(pProtocolData->dwState == protocoldata.dwState, "dwState wrong %x/%x\n",
670 pProtocolData->dwState, protocoldata.dwState );
671 ok(pProtocolData->pData == protocoldata.pData, "pData wrong %p/%p\n",
672 pProtocolData->pData, protocoldata.pData );
673 ok(pProtocolData->cbData == protocoldata.cbData, "cbData wrong %x/%x\n",
674 pProtocolData->cbData, protocoldata.cbData );
677 pdata = pProtocolData;
680 SetEvent(event_complete);
681 WaitForSingleObject(event_complete2, INFINITE);
684 continue_protdata = *pProtocolData;
685 SetEvent(event_continue);
686 WaitForSingleObject(event_continue_done, INFINITE);
688 call_continue(pProtocolData);
689 SetEvent(event_complete);
695 static HRESULT WINAPI ProtocolSink_ReportProgress(IInternetProtocolSink *iface, ULONG ulStatusCode,
696 LPCWSTR szStatusText)
698 static const WCHAR null_guid[] = {'{','0','0','0','0','0','0','0','0','-','0','0','0','0','-',
699 '0','0','0','0','-','0','0','0','0','-','0','0','0','0','0','0','0','0','0','0','0','0','}',0};
700 static const WCHAR text_plain[] = {'t','e','x','t','/','p','l','a','i','n',0};
702 switch(ulStatusCode) {
703 case BINDSTATUS_MIMETYPEAVAILABLE:
704 CHECK_EXPECT(ReportProgress_MIMETYPEAVAILABLE);
705 if(tested_protocol != FILE_TEST && !mimefilter_test && (pi & PI_MIMEVERIFICATION)) {
706 if(!short_read || !direct_read)
707 CHECK_CALLED(Read); /* set in Continue */
709 CHECK_CALLED(Read2); /* set in Read */
711 ok(szStatusText != NULL, "szStatusText == NULL\n");
713 if(tested_protocol == BIND_TEST)
714 ok(szStatusText == expect_wsz, "unexpected szStatusText\n");
715 else if (http_post_test)
716 ok(lstrlenW(text_plain) <= lstrlenW(szStatusText) &&
717 !memcmp(szStatusText, text_plain, lstrlenW(text_plain)*sizeof(WCHAR)),
718 "szStatusText != text/plain\n");
719 else if(!mimefilter_test)
720 ok(lstrlenW(text_htmlW) <= lstrlenW(szStatusText) &&
721 !memcmp(szStatusText, text_htmlW, lstrlenW(text_htmlW)*sizeof(WCHAR)),
722 "szStatusText != text/html\n");
725 case BINDSTATUS_DIRECTBIND:
726 CHECK_EXPECT2(ReportProgress_DIRECTBIND);
727 ok(szStatusText == NULL, "szStatusText != NULL\n");
729 case BINDSTATUS_RAWMIMETYPE:
730 CHECK_EXPECT2(ReportProgress_RAWMIMETYPE);
731 ok(szStatusText != NULL, "szStatusText == NULL\n");
733 ok(lstrlenW(szStatusText) < lstrlenW(text_htmlW) ||
734 !memcmp(szStatusText, text_htmlW, lstrlenW(text_htmlW)*sizeof(WCHAR)),
735 "szStatusText != text/html\n");
737 case BINDSTATUS_CACHEFILENAMEAVAILABLE:
738 CHECK_EXPECT(ReportProgress_CACHEFILENAMEAVAILABLE);
739 ok(szStatusText != NULL, "szStatusText == NULL\n");
742 ok(!strcmp_ww(szStatusText, expect_wsz), "unexpected szStatusText\n");
743 else if(tested_protocol == FILE_TEST)
744 ok(!strcmp_ww(szStatusText, file_name), "szStatusText = %s\n", wine_dbgstr_w(szStatusText));
746 ok(szStatusText != NULL, "szStatusText == NULL\n");
749 case BINDSTATUS_FINDINGRESOURCE:
750 CHECK_EXPECT2(ReportProgress_FINDINGRESOURCE);
751 ok(szStatusText != NULL, "szStatusText == NULL\n");
753 case BINDSTATUS_CONNECTING:
754 CHECK_EXPECT2(ReportProgress_CONNECTING);
755 ok(szStatusText != NULL, "szStatusText == NULL\n");
757 case BINDSTATUS_SENDINGREQUEST:
758 CHECK_EXPECT2(ReportProgress_SENDINGREQUEST);
759 if(tested_protocol == FILE_TEST) {
760 ok(szStatusText != NULL, "szStatusText == NULL\n");
762 ok(!*szStatusText, "wrong szStatusText\n");
765 case BINDSTATUS_VERIFIEDMIMETYPEAVAILABLE:
766 CHECK_EXPECT(ReportProgress_VERIFIEDMIMETYPEAVAILABLE);
767 ok(szStatusText != NULL, "szStatusText == NULL\n");
769 ok(!strcmp_ww(szStatusText, text_htmlW), "szStatusText != text/html\n");
771 case BINDSTATUS_PROTOCOLCLASSID:
772 CHECK_EXPECT(ReportProgress_PROTOCOLCLASSID);
773 ok(szStatusText != NULL, "szStatusText == NULL\n");
774 ok(!strcmp_ww(szStatusText, null_guid), "unexpected classid %s\n", wine_dbgstr_w(szStatusText));
776 case BINDSTATUS_COOKIE_SENT:
777 CHECK_EXPECT(ReportProgress_COOKIE_SENT);
778 ok(szStatusText == NULL, "szStatusText != NULL\n");
780 case BINDSTATUS_REDIRECTING:
781 CHECK_EXPECT(ReportProgress_REDIRECTING);
783 ok(!strcmp_wa(szStatusText, "http://test.winehq.org/hello.html"), "szStatusText = %s\n", wine_dbgstr_w(szStatusText));
785 ok(szStatusText == NULL, "szStatusText = %s\n", wine_dbgstr_w(szStatusText));
787 case BINDSTATUS_ENCODING:
788 CHECK_EXPECT(ReportProgress_ENCODING);
789 ok(!strcmp_wa(szStatusText, "gzip"), "szStatusText = %s\n", wine_dbgstr_w(szStatusText));
791 case BINDSTATUS_ACCEPTRANGES:
792 CHECK_EXPECT(ReportProgress_ACCEPTRANGES);
793 ok(!szStatusText, "szStatusText = %s\n", wine_dbgstr_w(szStatusText));
795 case BINDSTATUS_PROXYDETECTING:
796 CHECK_EXPECT(ReportProgress_PROXYDETECTING);
797 SET_EXPECT(ReportProgress_CONNECTING);
798 ok(!szStatusText, "szStatusText = %s\n", wine_dbgstr_w(szStatusText));
800 case BINDSTATUS_LOADINGMIMEHANDLER:
801 CHECK_EXPECT(ReportProgress_LOADINGMIMEHANDLER);
802 ok(!szStatusText, "szStatusText = %s\n", wine_dbgstr_w(szStatusText));
804 case BINDSTATUS_DECODING:
805 CHECK_EXPECT(ReportProgress_DECODING);
806 ok(!strcmp_ww(szStatusText, gzipW), "szStatusText = %s\n", wine_dbgstr_w(szStatusText));
809 ok(0, "Unexpected status %d\n", ulStatusCode);
815 static HRESULT WINAPI ProtocolSink_ReportData(IInternetProtocolSink *iface, DWORD grfBSCF,
816 ULONG ulProgress, ULONG ulProgressMax)
820 static int rec_depth;
823 if(!mimefilter_test && tested_protocol == FILE_TEST) {
824 CHECK_EXPECT2(ReportData);
826 ok(ulProgress == ulProgressMax, "ulProgress (%d) != ulProgressMax (%d)\n",
827 ulProgress, ulProgressMax);
828 ok(ulProgressMax == 13, "ulProgressMax=%d, expected 13\n", ulProgressMax);
829 /* BSCF_SKIPDRAINDATAFORFILEURLS added in IE8 */
830 ok((grfBSCF == (BSCF_FIRSTDATANOTIFICATION | BSCF_LASTDATANOTIFICATION)) ||
831 (grfBSCF == (BSCF_FIRSTDATANOTIFICATION | BSCF_LASTDATANOTIFICATION | BSCF_SKIPDRAINDATAFORFILEURLS)),
832 "grcfBSCF = %08x\n", grfBSCF);
833 }else if(direct_read) {
837 if(!read_report_data && rec_depth == 1) {
838 BOOL reported_all_data = called_ReportData2;
840 CHECK_EXPECT2(ReportData);
843 ok(grfBSCF == (BSCF_FIRSTDATANOTIFICATION|BSCF_LASTDATANOTIFICATION|BSCF_DATAFULLYAVAILABLE)
844 || grfBSCF == BSCF_FIRSTDATANOTIFICATION, /* < IE8 */
845 "grcfBSCF = %08x\n", grfBSCF);
846 CHECK_CALLED(Read); /* Set in Continue */
847 first_data_notif = FALSE;
848 }else if(first_data_notif) {
849 ok(grfBSCF == BSCF_FIRSTDATANOTIFICATION, "grcfBSCF = %08x\n", grfBSCF);
850 first_data_notif = FALSE;
851 }else if(reported_all_data) {
852 ok(grfBSCF == (BSCF_LASTDATANOTIFICATION|BSCF_INTERMEDIATEDATANOTIFICATION),
853 "grcfBSCF = %08x\n", grfBSCF);
854 }else if(!direct_read) {
855 ok(grfBSCF == BSCF_INTERMEDIATEDATANOTIFICATION, "grcfBSCF = %08x\n", grfBSCF);
863 SET_EXPECT(ReportData2);
864 SET_EXPECT(ReportResult);
865 hres = IInternetProtocol_Read(binding_test ? binding_protocol : async_protocol, expect_pv = buf, sizeof(buf), &read);
867 ok(read, "read == 0\n");
868 if(reported_all_data) {
869 ok(hres == S_FALSE, "Read failed: %08x, expected S_FALSE\n", hres);
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), /* Win9x, 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(IInternetProtocol *iface)
1321 static ULONG WINAPI Protocol_Release(IInternetProtocol *iface)
1326 static HRESULT WINAPI Protocol_Abort(IInternetProtocol *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(IInternetProtocol *iface)
1343 ok(0, "unexpected call\n");
1347 static HRESULT WINAPI Protocol_Resume(IInternetProtocol *iface)
1349 ok(0, "unexpected call\n");
1353 static HRESULT WINAPI Protocol_Seek(IInternetProtocol *iface,
1354 LARGE_INTEGER dlibMove, DWORD dwOrigin, ULARGE_INTEGER *plibNewPosition)
1356 ok(0, "unexpected call\n");
1360 static HRESULT WINAPI ProtocolEmul_QueryInterface(IInternetProtocol *iface, REFIID riid, void **ppv)
1362 if(IsEqualGUID(&IID_IUnknown, riid) || IsEqualGUID(&IID_IInternetProtocol, riid)) {
1367 if(IsEqualGUID(&IID_IInternetProtocolEx, riid)) {
1368 trace("IID_IInternetProtocolEx not supported\n");
1370 return E_NOINTERFACE;
1373 if(IsEqualGUID(&IID_IInternetPriority, riid)) {
1374 *ppv = &InternetPriority;
1378 if(IsEqualGUID(&IID_IWinInetInfo, riid)) {
1379 CHECK_EXPECT(QueryInterface_IWinInetInfo);
1381 return E_NOINTERFACE;
1384 if(IsEqualGUID(&IID_IWinInetHttpInfo, riid)) {
1385 CHECK_EXPECT(QueryInterface_IWinInetHttpInfo);
1387 return E_NOINTERFACE;
1390 ok(0, "unexpected riid %s\n", debugstr_guid(riid));
1392 return E_NOINTERFACE;
1395 static DWORD WINAPI thread_proc(PVOID arg)
1399 memset(&protocoldata, -1, sizeof(protocoldata));
1403 SET_EXPECT(ReportProgress_FINDINGRESOURCE);
1404 hres = IInternetProtocolSink_ReportProgress(binding_sink,
1405 BINDSTATUS_FINDINGRESOURCE, hostW);
1406 CHECK_CALLED(ReportProgress_FINDINGRESOURCE);
1407 ok(hres == S_OK, "ReportProgress failed: %08x\n", hres);
1409 SET_EXPECT(ReportProgress_CONNECTING);
1410 hres = IInternetProtocolSink_ReportProgress(binding_sink,
1411 BINDSTATUS_CONNECTING, winehq_ipW);
1412 CHECK_CALLED(ReportProgress_CONNECTING);
1413 ok(hres == S_OK, "ReportProgress failed: %08x\n", hres);
1415 SET_EXPECT(ReportProgress_SENDINGREQUEST);
1416 hres = IInternetProtocolSink_ReportProgress(binding_sink,
1417 BINDSTATUS_SENDINGREQUEST, NULL);
1418 CHECK_CALLED(ReportProgress_SENDINGREQUEST);
1419 ok(hres == S_OK, "ReportProgress failed: %08x\n", hres);
1423 hres = IInternetProtocolSink_Switch(binding_sink, &protocoldata);
1424 CHECK_CALLED(Switch);
1425 ok(hres == S_OK, "Switch failed: %08x\n", hres);
1430 SET_EXPECT(MimeFilter_Switch);
1433 hres = IInternetProtocolSink_Switch(binding_sink, &protocoldata);
1434 ok(hres == S_OK, "Switch failed: %08x\n", hres);
1436 CHECK_CALLED(MimeFilter_Switch);
1438 CHECK_CALLED(Switch);
1441 SetEvent(event_complete);
1447 SET_EXPECT(MimeFilter_Switch);
1450 hres = IInternetProtocolSink_Switch(binding_sink, &protocoldata);
1451 ok(hres == S_OK, "Switch failed: %08x\n", hres);
1453 CHECK_CALLED(MimeFilter_Switch);
1455 CHECK_CALLED(Switch);
1459 SET_EXPECT(MimeFilter_Switch);
1462 hres = IInternetProtocolSink_Switch(binding_sink, &protocoldata);
1463 ok(hres == S_OK, "Switch failed: %08x\n", hres);
1465 CHECK_CALLED(MimeFilter_Switch);
1467 CHECK_CALLED(Switch);
1470 SetEvent(event_complete);
1475 static HRESULT WINAPI ProtocolEmul_Start(IInternetProtocol *iface, LPCWSTR szUrl,
1476 IInternetProtocolSink *pOIProtSink, IInternetBindInfo *pOIBindInfo,
1477 DWORD grfPI, HANDLE_PTR dwReserved)
1479 BINDINFO bindinfo, exp_bindinfo;
1483 CHECK_EXPECT(Start);
1485 ok(pOIProtSink != NULL, "pOIProtSink == NULL\n");
1486 ok(pOIBindInfo != NULL, "pOIBindInfo == NULL\n");
1487 ok(pOIProtSink != &protocol_sink, "unexpected pOIProtSink\n");
1488 ok(pOIBindInfo != &bind_info, "unexpected pOIBindInfo\n");
1489 ok(!grfPI, "grfPI = %x\n", grfPI);
1490 ok(!dwReserved, "dwReserved = %lx\n", dwReserved);
1493 ok(pOIProtSink == binding_sink, "pOIProtSink != binding_sink\n");
1495 memset(&bindinfo, 0, sizeof(bindinfo));
1496 bindinfo.cbSize = sizeof(bindinfo);
1497 memcpy(&exp_bindinfo, &bindinfo, sizeof(bindinfo));
1498 SET_EXPECT(GetBindInfo);
1499 hres = IInternetBindInfo_GetBindInfo(pOIBindInfo, &cbindf, &bindinfo);
1500 ok(hres == S_OK, "GetBindInfo failed: %08x\n", hres);
1501 CHECK_CALLED(GetBindInfo);
1502 ok(cbindf == (bindf|BINDF_FROMURLMON), "bindf = %x, expected %x\n",
1503 cbindf, (bindf|BINDF_FROMURLMON));
1504 ok(!memcmp(&exp_bindinfo, &bindinfo, sizeof(bindinfo)), "unexpected bindinfo\n");
1505 pReleaseBindInfo(&bindinfo);
1507 SET_EXPECT(ReportProgress_SENDINGREQUEST);
1508 hres = IInternetProtocolSink_ReportProgress(pOIProtSink, BINDSTATUS_SENDINGREQUEST, emptyW);
1509 ok(hres == S_OK, "ReportProgress(BINDSTATUS_SENDINGREQUEST) failed: %08x\n", hres);
1510 CHECK_CALLED(ReportProgress_SENDINGREQUEST);
1512 if(tested_protocol == HTTP_TEST || tested_protocol == HTTPS_TEST) {
1513 IServiceProvider *service_provider;
1514 IHttpNegotiate *http_negotiate;
1515 IHttpNegotiate2 *http_negotiate2;
1516 LPWSTR ua = (LPWSTR)0xdeadbeef, accept_mimes[256];
1517 LPWSTR additional_headers = NULL;
1519 DWORD fetched = 0, size = 100;
1522 SET_EXPECT(GetBindString_USER_AGENT);
1523 hres = IInternetBindInfo_GetBindString(pOIBindInfo, BINDSTRING_USER_AGENT,
1525 CHECK_CALLED(GetBindString_USER_AGENT);
1526 ok(hres == S_OK, "GetBindString(BINDSTRING_USER_AGETNT) failed: %08x\n", hres);
1527 ok(fetched == 1, "fetched = %d, expected 254\n", fetched);
1528 ok(ua != NULL, "ua = %p\n", ua);
1529 ok(!strcmp_ww(ua, user_agentW), "unexpected user agent %s\n", wine_dbgstr_w(ua));
1533 SET_EXPECT(GetBindString_ACCEPT_MIMES);
1534 hres = IInternetBindInfo_GetBindString(pOIBindInfo, BINDSTRING_ACCEPT_MIMES,
1535 accept_mimes, 256, &fetched);
1536 CHECK_CALLED(GetBindString_ACCEPT_MIMES);
1539 "GetBindString(BINDSTRING_ACCEPT_MIMES) failed: %08x\n", hres);
1540 ok(fetched == 1, "fetched = %d, expected 1\n", fetched);
1541 ok(!strcmp_ww(acc_mimeW, accept_mimes[0]), "unexpected mimes %s\n", wine_dbgstr_w(accept_mimes[0]));
1542 CoTaskMemFree(accept_mimes[0]);
1544 hres = IInternetBindInfo_QueryInterface(pOIBindInfo, &IID_IServiceProvider,
1545 (void**)&service_provider);
1546 ok(hres == S_OK, "QueryInterface failed: %08x\n", hres);
1548 SET_EXPECT(QueryService_HttpNegotiate);
1549 hres = IServiceProvider_QueryService(service_provider, &IID_IHttpNegotiate,
1550 &IID_IHttpNegotiate, (void**)&http_negotiate);
1551 CHECK_CALLED(QueryService_HttpNegotiate);
1552 ok(hres == S_OK, "QueryService failed: %08x\n", hres);
1554 SET_EXPECT(BeginningTransaction);
1555 hres = IHttpNegotiate_BeginningTransaction(http_negotiate, binding_urls[tested_protocol],
1556 NULL, 0, &additional_headers);
1557 CHECK_CALLED(BeginningTransaction);
1558 IHttpNegotiate_Release(http_negotiate);
1559 ok(hres == S_OK, "BeginningTransction failed: %08x\n", hres);
1560 ok(additional_headers == NULL, "additional_headers=%p\n", additional_headers);
1562 SET_EXPECT(QueryService_HttpNegotiate);
1563 hres = IServiceProvider_QueryService(service_provider, &IID_IHttpNegotiate2,
1564 &IID_IHttpNegotiate2, (void**)&http_negotiate2);
1565 CHECK_CALLED(QueryService_HttpNegotiate);
1566 ok(hres == S_OK, "QueryService failed: %08x\n", hres);
1569 SET_EXPECT(GetRootSecurityId);
1570 hres = IHttpNegotiate2_GetRootSecurityId(http_negotiate2, sec_id, &size, 0);
1571 CHECK_CALLED(GetRootSecurityId);
1572 IHttpNegotiate2_Release(http_negotiate2);
1573 ok(hres == E_FAIL, "GetRootSecurityId failed: %08x, expected E_FAIL\n", hres);
1574 ok(size == 13, "size=%d\n", size);
1576 IServiceProvider_Release(service_provider);
1578 CreateThread(NULL, 0, thread_proc, NULL, 0, &tid);
1583 SET_EXPECT(ReportProgress_CACHEFILENAMEAVAILABLE);
1584 hres = IInternetProtocolSink_ReportProgress(pOIProtSink,
1585 BINDSTATUS_CACHEFILENAMEAVAILABLE, expect_wsz = emptyW);
1586 ok(hres == S_OK, "ReportProgress(BINDSTATUS_CACHEFILENAMEAVAILABLE) failed: %08x\n", hres);
1587 CHECK_CALLED(ReportProgress_CACHEFILENAMEAVAILABLE);
1589 if(mimefilter_test) {
1590 SET_EXPECT(MimeFilter_CreateInstance);
1591 SET_EXPECT(MimeFilter_Start);
1592 SET_EXPECT(ReportProgress_LOADINGMIMEHANDLER);
1594 SET_EXPECT(ReportProgress_MIMETYPEAVAILABLE);
1595 hres = IInternetProtocolSink_ReportProgress(pOIProtSink, BINDSTATUS_VERIFIEDMIMETYPEAVAILABLE,
1596 mimefilter_test ? gzipW : (expect_wsz = text_htmlW));
1598 "ReportProgress(BINDSTATUS_VERIFIEDMIMETYPEAVAILABLE) failed: %08x\n", hres);
1599 if(mimefilter_test) {
1600 CHECK_CALLED(MimeFilter_CreateInstance);
1601 CHECK_CALLED(MimeFilter_Start);
1602 CHECK_CALLED(ReportProgress_LOADINGMIMEHANDLER);
1603 todo_wine CHECK_CALLED(ReportProgress_MIMETYPEAVAILABLE);
1605 CHECK_CALLED(ReportProgress_MIMETYPEAVAILABLE);
1609 SET_EXPECT(MimeFilter_ReportData);
1611 SET_EXPECT(ReportData);
1612 hres = IInternetProtocolSink_ReportData(pOIProtSink,
1613 BSCF_FIRSTDATANOTIFICATION | BSCF_LASTDATANOTIFICATION, 13, 13);
1614 ok(hres == S_OK, "ReportData failed: %08x\n", hres);
1616 CHECK_CALLED(MimeFilter_ReportData);
1618 CHECK_CALLED(ReportData);
1620 if(tested_protocol == BIND_TEST) {
1621 hres = IInternetProtocol_Terminate(binding_protocol, 0);
1622 ok(hres == E_FAIL, "Termiante failed: %08x\n", hres);
1626 SET_EXPECT(MimeFilter_ReportResult);
1628 SET_EXPECT(ReportResult);
1629 hres = IInternetProtocolSink_ReportResult(pOIProtSink, S_OK, 0, NULL);
1630 ok(hres == S_OK, "ReportResult failed: %08x\n", hres);
1632 CHECK_CALLED(MimeFilter_ReportResult);
1634 CHECK_CALLED(ReportResult);
1639 static HRESULT WINAPI ProtocolEmul_Continue(IInternetProtocol *iface,
1640 PROTOCOLDATA *pProtocolData)
1645 CHECK_EXPECT(Continue);
1647 ok(pProtocolData != NULL, "pProtocolData == NULL\n");
1648 if(!pProtocolData || tested_protocol == BIND_TEST)
1651 ok(pProtocolData != &protocoldata, "pProtocolData == &protocoldata\n");
1652 ok(pProtocolData->grfFlags == protocoldata.grfFlags, "grfFlags wrong %x/%x\n",
1653 pProtocolData->grfFlags, protocoldata.grfFlags );
1654 ok(pProtocolData->dwState == protocoldata.dwState, "dwState wrong %x/%x\n",
1655 pProtocolData->dwState, protocoldata.dwState );
1656 ok(pProtocolData->pData == protocoldata.pData, "pData wrong %p/%p\n",
1657 pProtocolData->pData, protocoldata.pData );
1658 ok(pProtocolData->cbData == protocoldata.cbData, "cbData wrong %x/%x\n",
1659 pProtocolData->cbData, protocoldata.cbData );
1662 switch(prot_state) {
1664 IServiceProvider *service_provider;
1665 IHttpNegotiate *http_negotiate;
1666 static WCHAR header[] = {'?',0};
1668 hres = IInternetProtocolSink_QueryInterface(binding_sink, &IID_IServiceProvider,
1669 (void**)&service_provider);
1670 ok(hres == S_OK, "Could not get IServiceProvicder\n");
1672 SET_EXPECT(QueryService_HttpNegotiate);
1673 hres = IServiceProvider_QueryService(service_provider, &IID_IHttpNegotiate,
1674 &IID_IHttpNegotiate, (void**)&http_negotiate);
1675 IServiceProvider_Release(service_provider);
1676 CHECK_CALLED(QueryService_HttpNegotiate);
1677 ok(hres == S_OK, "Could not get IHttpNegotiate\n");
1679 SET_EXPECT(OnResponse);
1680 hres = IHttpNegotiate_OnResponse(http_negotiate, 200, header, NULL, NULL);
1681 IHttpNegotiate_Release(http_negotiate);
1682 CHECK_CALLED(OnResponse);
1683 IHttpNegotiate_Release(http_negotiate);
1684 ok(hres == S_OK, "OnResponse failed: %08x\n", hres);
1686 if(mimefilter_test) {
1687 SET_EXPECT(MimeFilter_CreateInstance);
1688 SET_EXPECT(MimeFilter_Start);
1689 SET_EXPECT(ReportProgress_LOADINGMIMEHANDLER);
1690 }else if(!(pi & PI_MIMEVERIFICATION)) {
1691 SET_EXPECT(ReportProgress_MIMETYPEAVAILABLE);
1693 hres = IInternetProtocolSink_ReportProgress(binding_sink,
1694 BINDSTATUS_MIMETYPEAVAILABLE, mimefilter_test ? gzipW : text_htmlW);
1695 if(mimefilter_test) {
1696 CHECK_CALLED(MimeFilter_CreateInstance);
1697 CHECK_CALLED(MimeFilter_Start);
1698 CHECK_CALLED(ReportProgress_LOADINGMIMEHANDLER);
1699 }else if(!(pi & PI_MIMEVERIFICATION)) {
1700 CHECK_CALLED(ReportProgress_MIMETYPEAVAILABLE);
1703 "ReportProgress(BINDSTATUS_MIMETYPEAVAILABLE) failed: %08x\n", hres);
1705 bscf |= BSCF_FIRSTDATANOTIFICATION;
1710 bscf = BSCF_INTERMEDIATEDATANOTIFICATION;
1715 if(mimefilter_test) {
1716 SET_EXPECT(MimeFilter_ReportData);
1717 }else if(pi & PI_MIMEVERIFICATION) {
1719 SET_EXPECT(Read); /* checked in ReportData for short_read */
1721 if(!mimefilter_test)
1722 SET_EXPECT(Read); /* checked in BINDSTATUS_MIMETYPEAVAILABLE or ReportData */
1723 SET_EXPECT(ReportProgress_MIMETYPEAVAILABLE);
1726 SET_EXPECT(ReportData);
1728 SET_EXPECT(ReportData);
1731 hres = IInternetProtocolSink_ReportData(binding_sink, bscf, pr, 400);
1732 ok(hres == S_OK, "ReportData failed: %08x\n", hres);
1734 if(mimefilter_test) {
1735 SET_EXPECT(MimeFilter_ReportData);
1736 }else if(pi & PI_MIMEVERIFICATION) {
1737 if(!short_read && pr < 200)
1740 CHECK_CALLED(ReportProgress_MIMETYPEAVAILABLE);
1743 CHECK_CALLED(ReportData);
1752 static HRESULT WINAPI ProtocolEmul_Terminate(IInternetProtocol *iface, DWORD dwOptions)
1754 CHECK_EXPECT(Terminate);
1755 ok(!dwOptions, "dwOptions=%d\n", dwOptions);
1759 static HRESULT WINAPI ProtocolEmul_Read(IInternetProtocol *iface, void *pv,
1760 ULONG cb, ULONG *pcbRead)
1762 if(read_report_data)
1763 CHECK_EXPECT2(Read2);
1765 if(mimefilter_test || short_read) {
1766 if(!read_report_data)
1767 CHECK_EXPECT2(Read);
1768 }else if((pi & PI_MIMEVERIFICATION)) {
1769 if(!read_report_data)
1770 CHECK_EXPECT2(Read);
1772 if(prot_read < 300) {
1773 ok(pv != expect_pv, "pv == expect_pv\n");
1775 ok(cb == 2048-prot_read, "cb=%d\n", cb);
1777 ok(cb == 700, "cb=%d\n", cb);
1779 ok(expect_pv <= pv && (BYTE*)pv < (BYTE*)expect_pv + cb, "pv != expect_pv\n");
1782 if(!read_report_data)
1785 ok(pv == expect_pv, "pv != expect_pv\n");
1786 ok(cb == 1000, "cb=%d\n", cb);
1787 ok(!*pcbRead, "*pcbRead = %d\n", *pcbRead);
1789 ok(pcbRead != NULL, "pcbRead == NULL\n");
1791 if(prot_state == 3 || (short_read && prot_state != 4)) {
1796 SET_EXPECT(Read2); /* checked in BINDSTATUS_MIMETYPEAVAILABLE */
1797 SET_EXPECT(ReportProgress_MIMETYPEAVAILABLE);
1800 SET_EXPECT(MimeFilter_ReportData);
1801 else if(direct_read)
1802 SET_EXPECT(ReportData2);
1804 hres = IInternetProtocolSink_ReportData(binding_sink,
1805 BSCF_LASTDATANOTIFICATION|BSCF_INTERMEDIATEDATANOTIFICATION, 0, 0);
1807 ok(hres == S_OK, "ReportData failed: %08x\n", hres);
1809 CHECK_CALLED(ReportProgress_MIMETYPEAVAILABLE);
1811 CHECK_CALLED(MimeFilter_ReportData);
1812 else if(direct_read)
1813 CHECK_CALLED(ReportData2);
1816 SET_EXPECT(MimeFilter_ReportResult);
1818 SET_EXPECT(ReportResult);
1819 hres = IInternetProtocolSink_ReportResult(binding_sink, S_OK, ERROR_SUCCESS, NULL);
1820 ok(hres == S_OK, "ReportResult failed: %08x\n", hres);
1822 CHECK_CALLED(MimeFilter_ReportResult);
1824 CHECK_CALLED(ReportResult);
1826 memset(pv, 'x', 100);
1827 prot_read += *pcbRead = 100;
1829 }if(prot_state == 4) {
1834 if((async_read_pending = !async_read_pending)) {
1836 return tested_protocol == HTTP_TEST || tested_protocol == HTTPS_TEST ? E_PENDING : S_FALSE;
1839 memset(pv, 'x', 100);
1840 prot_read += *pcbRead = 100;
1844 static HRESULT WINAPI ProtocolEmul_LockRequest(IInternetProtocol *iface, DWORD dwOptions)
1846 CHECK_EXPECT(LockRequest);
1847 ok(dwOptions == 0, "dwOptions=%x\n", dwOptions);
1851 static HRESULT WINAPI ProtocolEmul_UnlockRequest(IInternetProtocol *iface)
1853 CHECK_EXPECT(UnlockRequest);
1857 static const IInternetProtocolVtbl ProtocolVtbl = {
1858 ProtocolEmul_QueryInterface,
1862 ProtocolEmul_Continue,
1864 ProtocolEmul_Terminate,
1869 ProtocolEmul_LockRequest,
1870 ProtocolEmul_UnlockRequest
1873 static IInternetProtocol Protocol = { &ProtocolVtbl };
1875 static HRESULT WINAPI MimeProtocol_QueryInterface(IInternetProtocol *iface, REFIID riid, void **ppv)
1877 if(IsEqualGUID(&IID_IUnknown, riid) || IsEqualGUID(&IID_IInternetProtocol, riid)) {
1882 if(IsEqualGUID(&IID_IInternetProtocolSink, riid)) {
1883 *ppv = &mime_protocol_sink;
1887 ok(0, "unexpected riid %s\n", debugstr_guid(riid));
1889 return E_NOINTERFACE;
1892 static HRESULT WINAPI MimeProtocol_Start(IInternetProtocol *iface, LPCWSTR szUrl,
1893 IInternetProtocolSink *pOIProtSink, IInternetBindInfo *pOIBindInfo,
1894 DWORD grfPI, HANDLE_PTR dwReserved)
1896 PROTOCOLFILTERDATA *data;
1897 LPOLESTR url_str = NULL;
1903 CHECK_EXPECT(MimeFilter_Start);
1905 ok(!strcmp_ww(szUrl, gzipW), "wrong url %s\n", wine_dbgstr_w(szUrl));
1906 ok(grfPI == (PI_FILTER_MODE|PI_FORCE_ASYNC), "grfPI=%x, expected PI_FILTER_MODE|PI_FORCE_ASYNC\n", grfPI);
1907 ok(dwReserved, "dwReserved == 0\n");
1908 ok(pOIProtSink != NULL, "pOIProtSink == NULL\n");
1909 ok(pOIBindInfo != NULL, "pOIBindInfo == NULL\n");
1912 ok(pOIProtSink != binding_sink, "pOIProtSink == protocol_sink\n");
1913 ok(pOIBindInfo == prot_bind_info, "pOIBindInfo != bind_info\n");
1915 ok(pOIProtSink == &protocol_sink, "pOIProtSink != protocol_sink\n");
1916 ok(pOIBindInfo == &bind_info, "pOIBindInfo != bind_info\n");
1919 data = (void*)dwReserved;
1920 ok(data->cbSize == sizeof(*data), "data->cbSize = %d\n", data->cbSize);
1921 ok(!data->pProtocolSink, "data->pProtocolSink != NULL\n");
1922 ok(data->pProtocol != NULL, "data->pProtocol == NULL\n");
1923 ok(!data->pUnk, "data->pUnk != NULL\n");
1924 ok(!data->dwFilterFlags, "data->dwProtocolFlags = %x\n", data->dwFilterFlags);
1926 IInternetProtocolSink *prot_sink;
1928 IInternetProtocol_QueryInterface(data->pProtocol, &IID_IInternetProtocolSink, (void**)&prot_sink);
1929 ok(prot_sink == pOIProtSink, "QI(data->pProtocol, IID_IInternetProtocolSink) != pOIProtSink\n");
1930 IInternetProtocolSink_Release(prot_sink);
1932 ok(data->pProtocol != binding_protocol, "data->pProtocol == binding_protocol\n");
1934 filtered_protocol = data->pProtocol;
1935 IInternetProtocol_AddRef(filtered_protocol);
1937 IInternetProtocol *prot;
1939 IInternetProtocol_QueryInterface(data->pProtocol, &IID_IInternetProtocol, (void**)&prot);
1940 ok(prot == async_protocol, "QI(data->pProtocol, IID_IInternetProtocol) != async_protocol\n");
1941 IInternetProtocol_Release(prot);
1943 ok(data->pProtocol != async_protocol, "data->pProtocol == async_protocol\n");
1946 filtered_sink = pOIProtSink;
1948 SET_EXPECT(ReportProgress_DECODING);
1949 hres = IInternetProtocolSink_ReportProgress(pOIProtSink, BINDSTATUS_DECODING, gzipW);
1950 ok(hres == S_OK, "ReportProgress(BINDSTATUS_DECODING) failed: %08x\n", hres);
1951 CHECK_CALLED(ReportProgress_DECODING);
1953 SET_EXPECT(GetBindInfo);
1954 memset(&bindinfo, 0, sizeof(bindinfo));
1955 bindinfo.cbSize = sizeof(bindinfo);
1956 hres = IInternetBindInfo_GetBindInfo(pOIBindInfo, &cbindf, &bindinfo);
1957 ok(hres == S_OK, "GetBindInfo failed: %08x\n", hres);
1958 ok(cbindf == (bindf|BINDF_FROMURLMON), "cbindf = %x, expected %x\n", cbindf, bindf);
1959 CHECK_CALLED(GetBindInfo);
1961 SET_EXPECT(GetBindString_URL);
1962 hres = IInternetBindInfo_GetBindString(pOIBindInfo, BINDSTRING_URL, &url_str, 1, &fetched);
1963 ok(hres == S_OK, "GetBindString(BINDSTRING_URL) failed: %08x\n", hres);
1964 ok(fetched == 1, "fetched = %d\n", fetched);
1965 ok(!strcmp_ww(url_str, binding_urls[tested_protocol]), "wrong url_str %s\n", wine_dbgstr_w(url_str));
1966 CoTaskMemFree(url_str);
1967 CHECK_CALLED(GetBindString_URL);
1972 static HRESULT WINAPI Protocol_Continue(IInternetProtocol *iface,
1973 PROTOCOLDATA *pProtocolData)
1975 CHECK_EXPECT(MimeFilter_Continue);
1979 static HRESULT WINAPI MimeProtocol_Terminate(IInternetProtocol *iface, DWORD dwOptions)
1983 CHECK_EXPECT(MimeFilter_Terminate);
1985 ok(!dwOptions, "dwOptions = %x\n", dwOptions);
1987 SET_EXPECT(Terminate);
1988 hres = IInternetProtocol_Terminate(filtered_protocol, dwOptions);
1989 ok(hres == S_OK, "Terminate failed: %08x\n", hres);
1990 CHECK_CALLED(Terminate);
1995 static HRESULT WINAPI MimeProtocol_Read(IInternetProtocol *iface, void *pv,
1996 ULONG cb, ULONG *pcbRead)
2002 CHECK_EXPECT(MimeFilter_Read);
2004 ok(pv != NULL, "pv == NULL\n");
2005 ok(cb != 0, "cb == 0\n");
2006 ok(pcbRead != NULL, "pcbRead == NULL\n");
2008 if(read_report_data)
2012 hres = IInternetProtocol_Read(filtered_protocol, buf, sizeof(buf), &read);
2013 ok(hres == S_OK || hres == S_FALSE || hres == E_PENDING, "Read failed: %08x\n", hres);
2014 if(read_report_data)
2015 CHECK_CALLED(Read2);
2020 ok(*pcbRead == 0, "*pcbRead=%d, expected 0\n", *pcbRead);
2024 memset(pv, 'x', read);
2028 static HRESULT WINAPI MimeProtocol_LockRequest(IInternetProtocol *iface, DWORD dwOptions)
2032 CHECK_EXPECT(MimeFilter_LockRequest);
2034 ok(!dwOptions, "dwOptions = %x\n", dwOptions);
2036 SET_EXPECT(LockRequest);
2037 hres = IInternetProtocol_LockRequest(filtered_protocol, dwOptions);
2038 ok(hres == S_OK, "LockRequest failed: %08x\n", hres);
2039 CHECK_CALLED(LockRequest);
2044 static HRESULT WINAPI MimeProtocol_UnlockRequest(IInternetProtocol *iface)
2048 CHECK_EXPECT(MimeFilter_UnlockRequest);
2050 SET_EXPECT(UnlockRequest);
2051 hres = IInternetProtocol_UnlockRequest(filtered_protocol);
2052 ok(hres == S_OK, "UnlockRequest failed: %08x\n", hres);
2053 CHECK_CALLED(UnlockRequest);
2058 static const IInternetProtocolVtbl MimeProtocolVtbl = {
2059 MimeProtocol_QueryInterface,
2065 MimeProtocol_Terminate,
2070 MimeProtocol_LockRequest,
2071 MimeProtocol_UnlockRequest
2074 static IInternetProtocol MimeProtocol = { &MimeProtocolVtbl };
2076 static HRESULT WINAPI ClassFactory_QueryInterface(IClassFactory *iface, REFIID riid, void **ppv)
2078 ok(0, "unexpected call\n");
2079 return E_NOINTERFACE;
2082 static ULONG WINAPI ClassFactory_AddRef(IClassFactory *iface)
2087 static ULONG WINAPI ClassFactory_Release(IClassFactory *iface)
2092 static HRESULT WINAPI ClassFactory_CreateInstance(IClassFactory *iface, IUnknown *pOuter,
2093 REFIID riid, void **ppv)
2095 CHECK_EXPECT(CreateInstance);
2097 ok(pOuter == (IUnknown*)prot_bind_info, "pOuter != protocol_unk\n");
2098 ok(IsEqualGUID(&IID_IUnknown, riid), "unexpected riid %s\n", debugstr_guid(riid));
2099 ok(ppv != NULL, "ppv == NULL\n");
2105 static HRESULT WINAPI ClassFactory_LockServer(IClassFactory *iface, BOOL dolock)
2107 ok(0, "unexpected call\n");
2111 static const IClassFactoryVtbl ClassFactoryVtbl = {
2112 ClassFactory_QueryInterface,
2113 ClassFactory_AddRef,
2114 ClassFactory_Release,
2115 ClassFactory_CreateInstance,
2116 ClassFactory_LockServer
2119 static IClassFactory ClassFactory = { &ClassFactoryVtbl };
2121 static HRESULT WINAPI MimeFilter_CreateInstance(IClassFactory *iface, IUnknown *outer, REFIID riid, void **ppv)
2123 CHECK_EXPECT(MimeFilter_CreateInstance);
2125 ok(!outer, "outer = %p\n", outer);
2126 ok(IsEqualGUID(&IID_IInternetProtocol, riid), "unexpected riid %s\n", debugstr_guid(riid));
2128 *ppv = &MimeProtocol;
2132 static const IClassFactoryVtbl MimeFilterCFVtbl = {
2133 ClassFactory_QueryInterface,
2134 ClassFactory_AddRef,
2135 ClassFactory_Release,
2136 MimeFilter_CreateInstance,
2137 ClassFactory_LockServer
2140 static IClassFactory mimefilter_cf = { &MimeFilterCFVtbl };
2142 #define TEST_BINDING 0x0001
2143 #define TEST_FILTER 0x0002
2144 #define TEST_FIRST_HTTP 0x0004
2145 #define TEST_DIRECT_READ 0x0008
2146 #define TEST_POST 0x0010
2147 #define TEST_EMULATEPROT 0x0020
2148 #define TEST_SHORT_READ 0x0040
2149 #define TEST_REDIRECT 0x0080
2150 #define TEST_ABORT 0x0100
2151 #define TEST_ASYNCREQ 0x0200
2152 #define TEST_USEIURI 0x0400
2154 static void init_test(int prot, DWORD flags)
2156 tested_protocol = prot;
2157 binding_test = (flags & TEST_BINDING) != 0;
2158 first_data_notif = TRUE;
2161 async_read_pending = TRUE;
2162 mimefilter_test = (flags & TEST_FILTER) != 0;
2164 post_stream_read = 0;
2165 ResetEvent(event_complete);
2166 ResetEvent(event_complete2);
2167 ResetEvent(event_continue);
2168 ResetEvent(event_continue_done);
2169 async_protocol = binding_protocol = filtered_protocol = NULL;
2170 filtered_sink = NULL;
2171 http_is_first = (flags & TEST_FIRST_HTTP) != 0;
2172 first_data_notif = TRUE;
2173 state = STATE_CONNECTING;
2174 test_async_req = (flags & TEST_ASYNCREQ) != 0;
2175 direct_read = (flags & TEST_DIRECT_READ) != 0;
2176 emulate_prot = (flags & TEST_EMULATEPROT) != 0;
2177 wait_for_switch = TRUE;
2178 short_read = (flags & TEST_SHORT_READ) != 0;
2179 http_post_test = TYMED_NULL;
2180 test_redirect = (flags & TEST_REDIRECT) != 0;
2181 test_abort = (flags & TEST_ABORT) != 0;
2184 static void test_priority(IInternetProtocol *protocol)
2186 IInternetPriority *priority;
2190 hres = IInternetProtocol_QueryInterface(protocol, &IID_IInternetPriority,
2192 ok(hres == S_OK, "QueryInterface(IID_IInternetPriority) failed: %08x\n", hres);
2196 hres = IInternetPriority_GetPriority(priority, &pr);
2197 ok(hres == S_OK, "GetPriority failed: %08x\n", hres);
2198 ok(pr == 0, "pr=%d, expected 0\n", pr);
2200 hres = IInternetPriority_SetPriority(priority, 1);
2201 ok(hres == S_OK, "SetPriority failed: %08x\n", hres);
2203 hres = IInternetPriority_GetPriority(priority, &pr);
2204 ok(hres == S_OK, "GetPriority failed: %08x\n", hres);
2205 ok(pr == 1, "pr=%d, expected 1\n", pr);
2207 IInternetPriority_Release(priority);
2210 static void test_early_abort(const CLSID *clsid)
2212 IInternetProtocol *protocol;
2215 hres = CoCreateInstance(clsid, NULL, CLSCTX_INPROC_SERVER|CLSCTX_INPROC_HANDLER,
2216 &IID_IInternetProtocol, (void**)&protocol);
2217 ok(hres == S_OK, "CoCreateInstance failed: %08x\n", hres);
2219 hres = IInternetProtocol_Abort(protocol, E_ABORT, 0);
2220 ok(hres == S_OK, "Abort failed: %08x\n", hres);
2222 hres = IInternetProtocol_Abort(protocol, E_FAIL, 0);
2223 ok(hres == S_OK, "Abort failed: %08x\n", hres);
2225 IInternetProtocol_Release(protocol);
2228 static BOOL file_protocol_start(IInternetProtocol *protocol, LPCWSTR url,
2229 IInternetProtocolEx *protocolex, IUri *uri, BOOL is_first)
2233 SET_EXPECT(GetBindInfo);
2234 if(!(bindf & BINDF_FROMURLMON))
2235 SET_EXPECT(ReportProgress_DIRECTBIND);
2237 SET_EXPECT(ReportProgress_SENDINGREQUEST);
2238 SET_EXPECT(ReportProgress_CACHEFILENAMEAVAILABLE);
2239 if(bindf & BINDF_FROMURLMON)
2240 SET_EXPECT(ReportProgress_VERIFIEDMIMETYPEAVAILABLE);
2242 SET_EXPECT(ReportProgress_MIMETYPEAVAILABLE);
2244 SET_EXPECT(ReportData);
2246 SET_EXPECT(ReportResult);
2248 expect_hrResult = S_OK;
2251 hres = IInternetProtocolEx_StartEx(protocolex, uri, &protocol_sink, &bind_info, 0, 0);
2252 ok(hres == S_OK, "StartEx failed: %08x\n", hres);
2254 hres = IInternetProtocol_Start(protocol, url, &protocol_sink, &bind_info, 0, 0);
2255 if(hres == INET_E_RESOURCE_NOT_FOUND) {
2256 win_skip("Start failed\n");
2259 ok(hres == S_OK, "Start failed: %08x\n", hres);
2262 CHECK_CALLED(GetBindInfo);
2263 if(!(bindf & BINDF_FROMURLMON))
2264 CHECK_CALLED(ReportProgress_DIRECTBIND);
2266 CHECK_CALLED(ReportProgress_SENDINGREQUEST);
2267 CHECK_CALLED(ReportProgress_CACHEFILENAMEAVAILABLE);
2268 if(bindf & BINDF_FROMURLMON)
2269 CHECK_CALLED(ReportProgress_VERIFIEDMIMETYPEAVAILABLE);
2271 CHECK_CALLED(ReportProgress_MIMETYPEAVAILABLE);
2273 CHECK_CALLED(ReportData);
2275 CHECK_CALLED(ReportResult);
2280 static void test_file_protocol_url(LPCWSTR url)
2282 IInternetProtocolInfo *protocol_info;
2284 IClassFactory *factory;
2285 IInternetProtocol *protocol;
2290 hres = CoGetClassObject(&CLSID_FileProtocol, CLSCTX_INPROC_SERVER, NULL,
2291 &IID_IUnknown, (void**)&unk);
2292 ok(hres == S_OK, "CoGetClassObject failed: %08x\n", hres);
2296 hres = IUnknown_QueryInterface(unk, &IID_IInternetProtocolInfo, (void**)&protocol_info);
2297 ok(hres == E_NOINTERFACE,
2298 "Could not get IInternetProtocolInfo interface: %08x, expected E_NOINTERFACE\n", hres);
2300 hres = IUnknown_QueryInterface(unk, &IID_IClassFactory, (void**)&factory);
2301 ok(hres == S_OK, "Could not get IClassFactory interface\n");
2302 IUnknown_Release(unk);
2306 hres = IClassFactory_CreateInstance(factory, NULL, &IID_IInternetProtocol, (void**)&protocol);
2307 ok(hres == S_OK, "Could not get IInternetProtocol: %08x\n", hres);
2309 if(SUCCEEDED(hres)) {
2310 if(file_protocol_start(protocol, url, NULL, NULL, TRUE)) {
2311 hres = IInternetProtocol_Read(protocol, buf, 2, &cb);
2312 ok(hres == S_OK, "Read failed: %08x\n", hres);
2313 ok(cb == 2, "cb=%u expected 2\n", cb);
2314 hres = IInternetProtocol_Read(protocol, buf, sizeof(buf), &cb);
2315 ok(hres == S_FALSE, "Read failed: %08x\n", hres);
2316 hres = IInternetProtocol_Read(protocol, buf, sizeof(buf), &cb);
2317 ok(hres == S_FALSE, "Read failed: %08x expected S_FALSE\n", hres);
2318 ok(cb == 0, "cb=%u expected 0\n", cb);
2319 hres = IInternetProtocol_UnlockRequest(protocol);
2320 ok(hres == S_OK, "UnlockRequest failed: %08x\n", hres);
2323 if(file_protocol_start(protocol, url, NULL, NULL, FALSE)) {
2324 hres = IInternetProtocol_Read(protocol, buf, 2, &cb);
2325 ok(hres == S_FALSE, "Read failed: %08x\n", hres);
2326 hres = IInternetProtocol_LockRequest(protocol, 0);
2327 ok(hres == S_OK, "LockRequest failed: %08x\n", hres);
2328 hres = IInternetProtocol_UnlockRequest(protocol);
2329 ok(hres == S_OK, "UnlockRequest failed: %08x\n", hres);
2332 IInternetProtocol_Release(protocol);
2335 hres = IClassFactory_CreateInstance(factory, NULL, &IID_IInternetProtocol, (void**)&protocol);
2336 ok(hres == S_OK, "Could not get IInternetProtocol: %08x\n", hres);
2337 if(SUCCEEDED(hres)) {
2338 if(file_protocol_start(protocol, url, NULL, NULL, TRUE)) {
2339 hres = IInternetProtocol_LockRequest(protocol, 0);
2340 ok(hres == S_OK, "LockRequest failed: %08x\n", hres);
2341 hres = IInternetProtocol_Terminate(protocol, 0);
2342 ok(hres == S_OK, "Terminate failed: %08x\n", hres);
2343 hres = IInternetProtocol_Read(protocol, buf, 2, &cb);
2344 ok(hres == S_OK, "Read failed: %08x\n\n", hres);
2345 hres = IInternetProtocol_UnlockRequest(protocol);
2346 ok(hres == S_OK, "UnlockRequest failed: %08x\n", hres);
2347 hres = IInternetProtocol_Read(protocol, buf, 2, &cb);
2348 ok(hres == S_OK, "Read failed: %08x\n", hres);
2349 hres = IInternetProtocol_Terminate(protocol, 0);
2350 ok(hres == S_OK, "Terminate failed: %08x\n", hres);
2353 IInternetProtocol_Release(protocol);
2356 hres = IClassFactory_CreateInstance(factory, NULL, &IID_IInternetProtocol, (void**)&protocol);
2357 ok(hres == S_OK, "Could not get IInternetProtocol: %08x\n", hres);
2358 if(SUCCEEDED(hres)) {
2359 if(file_protocol_start(protocol, url, NULL, NULL, TRUE)) {
2360 hres = IInternetProtocol_Terminate(protocol, 0);
2361 ok(hres == S_OK, "Terminate failed: %08x\n", hres);
2362 hres = IInternetProtocol_Read(protocol, buf, 2, &cb);
2363 ok(hres == S_OK, "Read failed: %08x\n", hres);
2364 ok(cb == 2, "cb=%u expected 2\n", cb);
2367 IInternetProtocol_Release(protocol);
2371 IInternetProtocolEx *protocolex;
2374 hres = pCreateUri(url, Uri_CREATE_FILE_USE_DOS_PATH, 0, &uri);
2375 ok(hres == S_OK, "CreateUri failed: %08x\n", hres);
2377 hres = IClassFactory_CreateInstance(factory, NULL, &IID_IInternetProtocolEx, (void**)&protocolex);
2378 ok(hres == S_OK, "Could not get IInternetProtocolEx: %08x\n", hres);
2380 if(file_protocol_start(NULL, NULL, protocolex, uri, TRUE)) {
2381 hres = IInternetProtocolEx_Read(protocolex, buf, 2, &cb);
2382 ok(hres == S_OK, "Read failed: %08x\n", hres);
2383 hres = IInternetProtocolEx_LockRequest(protocolex, 0);
2384 ok(hres == S_OK, "LockRequest failed: %08x\n", hres);
2385 hres = IInternetProtocolEx_UnlockRequest(protocolex);
2386 ok(hres == S_OK, "UnlockRequest failed: %08x\n", hres);
2390 IInternetProtocolEx_Release(protocolex);
2392 win_skip("Skipping file protocol StartEx tests\n");
2395 IClassFactory_Release(factory);
2398 static void test_file_protocol_fail(void)
2400 IInternetProtocol *protocol;
2403 static const WCHAR index_url2[] =
2404 {'f','i','l','e',':','/','/','i','n','d','e','x','.','h','t','m','l',0};
2406 hres = CoCreateInstance(&CLSID_FileProtocol, NULL, CLSCTX_INPROC_SERVER|CLSCTX_INPROC_HANDLER,
2407 &IID_IInternetProtocol, (void**)&protocol);
2408 ok(hres == S_OK, "CoCreateInstance failed: %08x\n", hres);
2412 SET_EXPECT(GetBindInfo);
2413 expect_hrResult = MK_E_SYNTAX;
2414 hres = IInternetProtocol_Start(protocol, wszIndexHtml, &protocol_sink, &bind_info, 0, 0);
2415 ok(hres == MK_E_SYNTAX ||
2416 hres == E_INVALIDARG,
2417 "Start failed: %08x, expected MK_E_SYNTAX or E_INVALIDARG\n", hres);
2418 CLEAR_CALLED(GetBindInfo); /* GetBindInfo not called in IE7 */
2420 SET_EXPECT(GetBindInfo);
2421 if(!(bindf & BINDF_FROMURLMON))
2422 SET_EXPECT(ReportProgress_DIRECTBIND);
2423 SET_EXPECT(ReportProgress_SENDINGREQUEST);
2424 SET_EXPECT(ReportResult);
2425 expect_hrResult = INET_E_RESOURCE_NOT_FOUND;
2426 hres = IInternetProtocol_Start(protocol, index_url, &protocol_sink, &bind_info, 0, 0);
2427 ok(hres == INET_E_RESOURCE_NOT_FOUND,
2428 "Start failed: %08x expected INET_E_RESOURCE_NOT_FOUND\n", hres);
2429 CHECK_CALLED(GetBindInfo);
2430 if(!(bindf & BINDF_FROMURLMON))
2431 CHECK_CALLED(ReportProgress_DIRECTBIND);
2432 CHECK_CALLED(ReportProgress_SENDINGREQUEST);
2433 CHECK_CALLED(ReportResult);
2435 IInternetProtocol_Release(protocol);
2437 hres = CoCreateInstance(&CLSID_FileProtocol, NULL, CLSCTX_INPROC_SERVER|CLSCTX_INPROC_HANDLER,
2438 &IID_IInternetProtocol, (void**)&protocol);
2439 ok(hres == S_OK, "CoCreateInstance failed: %08x\n", hres);
2443 SET_EXPECT(GetBindInfo);
2444 if(!(bindf & BINDF_FROMURLMON))
2445 SET_EXPECT(ReportProgress_DIRECTBIND);
2446 SET_EXPECT(ReportProgress_SENDINGREQUEST);
2447 SET_EXPECT(ReportResult);
2448 expect_hrResult = INET_E_RESOURCE_NOT_FOUND;
2450 hres = IInternetProtocol_Start(protocol, index_url2, &protocol_sink, &bind_info, 0, 0);
2451 ok(hres == INET_E_RESOURCE_NOT_FOUND,
2452 "Start failed: %08x, expected INET_E_RESOURCE_NOT_FOUND\n", hres);
2453 CHECK_CALLED(GetBindInfo);
2454 if(!(bindf & BINDF_FROMURLMON))
2455 CHECK_CALLED(ReportProgress_DIRECTBIND);
2456 CHECK_CALLED(ReportProgress_SENDINGREQUEST);
2457 CHECK_CALLED(ReportResult);
2459 SET_EXPECT(GetBindInfo);
2460 hres = IInternetProtocol_Start(protocol, NULL, &protocol_sink, &bind_info, 0, 0);
2461 ok(hres == E_INVALIDARG, "Start failed: %08x, expected E_INVALIDARG\n", hres);
2462 CLEAR_CALLED(GetBindInfo); /* GetBindInfo not called in IE7 */
2464 SET_EXPECT(GetBindInfo);
2465 hres = IInternetProtocol_Start(protocol, emptyW, &protocol_sink, &bind_info, 0, 0);
2466 ok(hres == E_INVALIDARG, "Start failed: %08x, expected E_INVALIDARG\n", hres);
2467 CLEAR_CALLED(GetBindInfo); /* GetBindInfo not called in IE7 */
2469 IInternetProtocol_Release(protocol);
2472 static void test_file_protocol(void) {
2473 WCHAR buf[INTERNET_MAX_URL_LENGTH], file_name_buf[MAX_PATH];
2478 static const WCHAR wszFile[] = {'f','i','l','e',':',0};
2479 static const WCHAR wszFile2[] = {'f','i','l','e',':','/','/',0};
2480 static const WCHAR wszFile3[] = {'f','i','l','e',':','/','/','/',0};
2481 static const WCHAR wszFile4[] = {'f','i','l','e',':','\\','\\',0};
2482 static const char html_doc[] = "<HTML></HTML>";
2484 trace("Testing file protocol...\n");
2485 init_test(FILE_TEST, 0);
2487 SetLastError(0xdeadbeef);
2488 file = CreateFileW(wszIndexHtml, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS,
2489 FILE_ATTRIBUTE_NORMAL, NULL);
2490 if(!file && GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)
2492 win_skip("Detected Win9x or WinMe\n");
2495 ok(file != INVALID_HANDLE_VALUE, "CreateFile failed\n");
2496 if(file == INVALID_HANDLE_VALUE)
2498 WriteFile(file, html_doc, sizeof(html_doc)-1, &size, NULL);
2501 file_name = wszIndexHtml;
2503 test_file_protocol_url(index_url);
2504 bindf = BINDF_FROMURLMON;
2505 test_file_protocol_url(index_url);
2506 bindf = BINDF_FROMURLMON | BINDF_NEEDFILE;
2507 test_file_protocol_url(index_url);
2509 memcpy(buf, wszFile, sizeof(wszFile));
2510 len = sizeof(wszFile)/sizeof(WCHAR)-1;
2511 len += GetCurrentDirectoryW(sizeof(buf)/sizeof(WCHAR)-len, buf+len);
2513 memcpy(buf+len, wszIndexHtml, sizeof(wszIndexHtml));
2515 file_name = buf + sizeof(wszFile)/sizeof(WCHAR)-1;
2517 test_file_protocol_url(buf);
2518 bindf = BINDF_FROMURLMON;
2519 test_file_protocol_url(buf);
2521 memcpy(buf, wszFile2, sizeof(wszFile2));
2522 len = GetCurrentDirectoryW(sizeof(file_name_buf)/sizeof(WCHAR), file_name_buf);
2523 file_name_buf[len++] = '\\';
2524 memcpy(file_name_buf+len, wszIndexHtml, sizeof(wszIndexHtml));
2525 lstrcpyW(buf+sizeof(wszFile2)/sizeof(WCHAR)-1, file_name_buf);
2526 file_name = file_name_buf;
2528 test_file_protocol_url(buf);
2529 bindf = BINDF_FROMURLMON;
2530 test_file_protocol_url(buf);
2532 buf[sizeof(wszFile2)/sizeof(WCHAR)] = '|';
2533 test_file_protocol_url(buf);
2535 memcpy(buf, wszFile3, sizeof(wszFile3));
2536 len = sizeof(wszFile3)/sizeof(WCHAR)-1;
2537 len += GetCurrentDirectoryW(sizeof(buf)/sizeof(WCHAR)-len, buf+len);
2539 memcpy(buf+len, wszIndexHtml, sizeof(wszIndexHtml));
2541 file_name = buf + sizeof(wszFile3)/sizeof(WCHAR)-1;
2543 test_file_protocol_url(buf);
2544 bindf = BINDF_FROMURLMON;
2545 test_file_protocol_url(buf);
2547 memcpy(buf, wszFile4, sizeof(wszFile4));
2548 len = GetCurrentDirectoryW(sizeof(file_name_buf)/sizeof(WCHAR), file_name_buf);
2549 file_name_buf[len++] = '\\';
2550 memcpy(file_name_buf+len, wszIndexHtml, sizeof(wszIndexHtml));
2551 lstrcpyW(buf+sizeof(wszFile4)/sizeof(WCHAR)-1, file_name_buf);
2552 file_name = file_name_buf;
2554 test_file_protocol_url(buf);
2555 bindf = BINDF_FROMURLMON;
2556 test_file_protocol_url(buf);
2558 buf[sizeof(wszFile4)/sizeof(WCHAR)] = '|';
2559 test_file_protocol_url(buf);
2561 DeleteFileW(wszIndexHtml);
2564 test_file_protocol_fail();
2565 bindf = BINDF_FROMURLMON;
2566 test_file_protocol_fail();
2569 static BOOL http_protocol_start(LPCWSTR url, BOOL use_iuri)
2571 static BOOL got_user_agent = FALSE;
2575 if(use_iuri && pCreateUri) {
2576 hres = pCreateUri(url, 0, 0, &uri);
2577 ok(hres == S_OK, "CreateUri failed: %08x\n", hres);
2580 SET_EXPECT(GetBindInfo);
2581 if (!(bindf & BINDF_FROMURLMON))
2582 SET_EXPECT(ReportProgress_DIRECTBIND);
2584 SET_EXPECT(GetBindString_USER_AGENT);
2585 SET_EXPECT(GetBindString_ACCEPT_MIMES);
2586 SET_EXPECT(QueryService_HttpNegotiate);
2587 SET_EXPECT(BeginningTransaction);
2588 SET_EXPECT(GetRootSecurityId);
2589 if(http_post_test) {
2590 SET_EXPECT(GetBindString_POST_COOKIE);
2591 if(http_post_test == TYMED_ISTREAM)
2592 SET_EXPECT(Stream_Seek);
2596 IInternetProtocolEx *protocolex;
2598 hres = IInternetProtocol_QueryInterface(async_protocol, &IID_IInternetProtocolEx, (void**)&protocolex);
2599 ok(hres == S_OK, "Could not get IInternetProtocolEx iface: %08x\n", hres);
2601 hres = IInternetProtocolEx_StartEx(protocolex, uri, &protocol_sink, &bind_info, 0, 0);
2602 ok(hres == S_OK, "Start failed: %08x\n", hres);
2604 IInternetProtocolEx_Release(protocolex);
2607 hres = IInternetProtocol_Start(async_protocol, url, &protocol_sink, &bind_info, 0, 0);
2608 ok(hres == S_OK, "Start failed: %08x\n", hres);
2613 CHECK_CALLED(GetBindInfo);
2614 if (!(bindf & BINDF_FROMURLMON))
2615 CHECK_CALLED(ReportProgress_DIRECTBIND);
2616 if (!got_user_agent)
2618 CHECK_CALLED(GetBindString_USER_AGENT);
2619 got_user_agent = TRUE;
2621 CHECK_CALLED(GetBindString_ACCEPT_MIMES);
2622 CHECK_CALLED(QueryService_HttpNegotiate);
2623 CHECK_CALLED(BeginningTransaction);
2624 /* GetRootSecurityId called on WinXP but not on Win98 */
2625 CLEAR_CALLED(GetRootSecurityId);
2626 if(http_post_test) {
2627 CHECK_CALLED(GetBindString_POST_COOKIE);
2628 if(http_post_test == TYMED_ISTREAM)
2629 CHECK_CALLED(Stream_Seek);
2635 static void test_protocol_terminate(IInternetProtocol *protocol)
2641 hres = IInternetProtocol_LockRequest(protocol, 0);
2642 ok(hres == S_OK, "LockRequest failed: %08x\n", hres);
2644 hres = IInternetProtocol_Read(protocol, buf, 1, &cb);
2645 ok(hres == test_abort ? S_OK : S_FALSE, "Read failed: %08x\n", hres);
2647 hres = IInternetProtocol_Terminate(protocol, 0);
2648 ok(hres == S_OK, "Terminate failed: %08x\n", hres);
2650 /* This wait is to give the internet handles being freed in Terminate
2651 * enough time to actually terminate in all cases. Internet handles
2652 * terminate asynchronously and native reuses the main InternetOpen
2653 * handle. The only case in which this seems to be necessary is on
2654 * wine with native wininet and urlmon, resulting in the next time
2655 * test_http_protocol_url being called the first data notification actually
2656 * being an extra last data notification from the previous connection
2657 * about once out of every ten times. */
2660 hres = IInternetProtocol_UnlockRequest(protocol);
2661 ok(hres == S_OK, "UnlockRequest failed: %08x\n", hres);
2664 static void test_http_info(IInternetProtocol *protocol)
2666 IWinInetHttpInfo *info;
2669 hres = IInternetProtocol_QueryInterface(protocol, &IID_IWinInetHttpInfo, (void**)&info);
2670 ok(hres == S_OK, "Could not get IWinInterHttpInfo iface: %08x\n", hres);
2674 IWinInetHttpInfo_Release(info);
2677 /* is_first refers to whether this is the first call to this function
2679 static void test_http_protocol_url(LPCWSTR url, int prot, DWORD flags, DWORD tymed)
2681 IInternetProtocolInfo *protocol_info;
2682 IClassFactory *factory;
2686 init_test(prot, flags);
2688 http_post_test = tymed;
2690 hres = CoGetClassObject(prot == HTTPS_TEST ? &CLSID_HttpSProtocol : &CLSID_HttpProtocol,
2691 CLSCTX_INPROC_SERVER, NULL, &IID_IUnknown, (void**)&unk);
2692 ok(hres == S_OK, "CoGetClassObject failed: %08x\n", hres);
2696 hres = IUnknown_QueryInterface(unk, &IID_IInternetProtocolInfo, (void**)&protocol_info);
2697 ok(hres == E_NOINTERFACE,
2698 "Could not get IInternetProtocolInfo interface: %08x, expected E_NOINTERFACE\n",
2701 hres = IUnknown_QueryInterface(unk, &IID_IClassFactory, (void**)&factory);
2702 ok(hres == S_OK, "Could not get IClassFactory interface\n");
2703 IUnknown_Release(unk);
2707 hres = IClassFactory_CreateInstance(factory, NULL, &IID_IInternetProtocol,
2708 (void**)&async_protocol);
2709 ok(hres == S_OK, "Could not get IInternetProtocol: %08x\n", hres);
2710 if(SUCCEEDED(hres)) {
2715 test_priority(async_protocol);
2716 test_http_info(async_protocol);
2718 SET_EXPECT(ReportProgress_COOKIE_SENT);
2719 SET_EXPECT(ReportProgress_FINDINGRESOURCE);
2720 SET_EXPECT(ReportProgress_CONNECTING);
2721 SET_EXPECT(ReportProgress_SENDINGREQUEST);
2723 SET_EXPECT(ReportProgress_REDIRECTING);
2724 SET_EXPECT(ReportProgress_PROXYDETECTING);
2725 if(prot == HTTP_TEST)
2726 SET_EXPECT(ReportProgress_CACHEFILENAMEAVAILABLE);
2728 SET_EXPECT(QueryService_HttpSecurity);
2729 if(!(bindf & BINDF_FROMURLMON)) {
2730 SET_EXPECT(OnResponse);
2731 SET_EXPECT(ReportProgress_RAWMIMETYPE);
2732 SET_EXPECT(ReportData);
2737 if(!http_protocol_start(url, (flags & TEST_USEIURI) != 0))
2740 if(!direct_read && !test_abort)
2741 SET_EXPECT(ReportResult);
2742 expect_hrResult = test_abort ? E_ABORT : S_OK;
2745 while(wait_for_switch) {
2747 WaitForSingleObject(event_continue, INFINITE);
2748 CHECK_CALLED(Switch);
2749 call_continue(&continue_protdata);
2750 SetEvent(event_continue_done);
2753 hres = IInternetProtocol_Read(async_protocol, buf, 1, &cb);
2754 ok((hres == E_PENDING && cb==0) ||
2755 (hres == S_OK && cb==1), "Read failed: %08x (%d bytes)\n", hres, cb);
2757 WaitForSingleObject(event_complete, INFINITE);
2758 if(bindf & BINDF_FROMURLMON)
2759 CHECK_CALLED(Switch);
2761 CHECK_CALLED(ReportData);
2762 if(prot == HTTPS_TEST)
2763 CLEAR_CALLED(QueryService_HttpSecurity);
2766 if(bindf & BINDF_FROMURLMON)
2769 SET_EXPECT(ReportData);
2770 hres = IInternetProtocol_Read(async_protocol, buf, sizeof(buf), &cb);
2771 if(hres == E_PENDING) {
2772 hres = IInternetProtocol_Read(async_protocol, buf, 1, &cb);
2773 ok((hres == E_PENDING && cb==0) ||
2774 (hres == S_OK && cb==1), "Read failed: %08x (%d bytes)\n", hres, cb);
2775 WaitForSingleObject(event_complete, INFINITE);
2776 if(bindf & BINDF_FROMURLMON)
2777 CHECK_CALLED(Switch);
2779 CHECK_CALLED(ReportData);
2784 SET_EXPECT(ReportResult);
2785 hres = IInternetProtocol_Abort(async_protocol, E_ABORT, 0);
2786 ok(hres == S_OK, "Abort failed: %08x\n", hres);
2787 CHECK_CALLED(ReportResult);
2789 hres = IInternetProtocol_Abort(async_protocol, E_ABORT, 0);
2790 ok(hres == INET_E_RESULT_DISPATCHED, "Abort failed: %08x\n", hres);
2794 if(bindf & BINDF_FROMURLMON)
2795 CHECK_NOT_CALLED(Switch);
2797 CHECK_NOT_CALLED(ReportData);
2802 ok(hres == S_FALSE, "Read failed: %08x\n", hres);
2803 CHECK_CALLED(ReportResult);
2806 if(prot == HTTPS_TEST)
2807 CLEAR_CALLED(ReportProgress_SENDINGREQUEST);
2809 hres = IInternetProtocol_Abort(async_protocol, E_ABORT, 0);
2810 ok(hres == INET_E_RESULT_DISPATCHED, "Abort failed: %08x\n", hres);
2812 test_protocol_terminate(async_protocol);
2814 hres = IInternetProtocol_Abort(async_protocol, E_ABORT, 0);
2815 ok(hres == S_OK, "Abort failed: %08x\n", hres);
2817 ref = IInternetProtocol_Release(async_protocol);
2818 ok(!ref, "ref=%x\n", ref);
2821 IClassFactory_Release(factory);
2824 static void test_http_protocol(void)
2826 static const WCHAR winehq_url[] =
2827 {'h','t','t','p',':','/','/','w','w','w','.','w','i','n','e','h','q','.',
2828 'o','r','g','/','s','i','t','e','/','a','b','o','u','t',0};
2829 static const WCHAR posttest_url[] =
2830 {'h','t','t','p',':','/','/','c','r','o','s','s','o','v','e','r','.',
2831 'c','o','d','e','w','e','a','v','e','r','s','.','c','o','m','/',
2832 'p','o','s','t','t','e','s','t','.','p','h','p',0};
2833 static const WCHAR redirect_url[] =
2834 {'h','t','t','p',':','/','/','t','e','s','t','.','w','i','n','e','h','q','.','o','r','g','/',
2835 't','e','s','t','r','e','d','i','r','e','c','t',0};
2837 trace("Testing http protocol (not from urlmon)...\n");
2838 bindf = BINDF_ASYNCHRONOUS | BINDF_ASYNCSTORAGE | BINDF_PULLDATA;
2839 test_http_protocol_url(winehq_url, HTTP_TEST, TEST_FIRST_HTTP, TYMED_NULL);
2841 trace("Testing http protocol (from urlmon)...\n");
2842 bindf = BINDF_ASYNCHRONOUS | BINDF_ASYNCSTORAGE | BINDF_PULLDATA | BINDF_FROMURLMON;
2843 test_http_protocol_url(winehq_url, HTTP_TEST, 0, TYMED_NULL);
2845 trace("Testing http protocol (to file)...\n");
2846 bindf = BINDF_ASYNCHRONOUS | BINDF_ASYNCSTORAGE | BINDF_PULLDATA | BINDF_FROMURLMON | BINDF_NEEDFILE;
2847 test_http_protocol_url(winehq_url, HTTP_TEST, 0, TYMED_NULL);
2849 trace("Testing http protocol (post data)...\n");
2850 /* Without this flag we get a ReportProgress_CACHEFILENAMEAVAILABLE
2851 * notification with BINDVERB_POST */
2852 bindf = BINDF_ASYNCHRONOUS | BINDF_ASYNCSTORAGE | BINDF_PULLDATA | BINDF_FROMURLMON | BINDF_NOWRITECACHE;
2853 test_http_protocol_url(posttest_url, HTTP_TEST, TEST_FIRST_HTTP|TEST_POST, TYMED_HGLOBAL);
2855 trace("Testing http protocol (post data stream)...\n");
2856 test_http_protocol_url(posttest_url, HTTP_TEST, TEST_FIRST_HTTP|TEST_POST|TEST_ASYNCREQ, TYMED_ISTREAM);
2858 trace("Testing http protocol (direct read)...\n");
2859 bindf = BINDF_ASYNCHRONOUS | BINDF_ASYNCSTORAGE | BINDF_PULLDATA | BINDF_FROMURLMON;
2860 test_http_protocol_url(winehq_url, HTTP_TEST, TEST_DIRECT_READ|TEST_USEIURI, TYMED_NULL);
2862 trace("Testing http protocol (redirected)...\n");
2863 bindf = BINDF_ASYNCHRONOUS | BINDF_ASYNCSTORAGE | BINDF_PULLDATA | BINDF_FROMURLMON;
2864 test_http_protocol_url(redirect_url, HTTP_TEST, TEST_REDIRECT, TYMED_NULL);
2866 trace("Testing http protocol abort...\n");
2867 test_http_protocol_url(winehq_url, HTTP_TEST, TEST_ABORT, TYMED_NULL);
2869 test_early_abort(&CLSID_HttpProtocol);
2870 test_early_abort(&CLSID_HttpSProtocol);
2873 static void test_https_protocol(void)
2875 static const WCHAR codeweavers_url[] =
2876 {'h','t','t','p','s',':','/','/','w','w','w','.','c','o','d','e','w','e','a','v','e','r','s',
2877 '.','c','o','m','/','t','e','s','t','.','h','t','m','l',0};
2879 trace("Testing https protocol (from urlmon)...\n");
2880 bindf = BINDF_ASYNCHRONOUS | BINDF_ASYNCSTORAGE | BINDF_PULLDATA | BINDF_FROMURLMON | BINDF_NOWRITECACHE;
2881 test_http_protocol_url(codeweavers_url, HTTPS_TEST, TEST_FIRST_HTTP, TYMED_NULL);
2885 static void test_ftp_protocol(void)
2887 IInternetProtocolInfo *protocol_info;
2888 IClassFactory *factory;
2895 static const WCHAR ftp_urlW[] = {'f','t','p',':','/','/','f','t','p','.','w','i','n','e','h','q','.','o','r','g',
2896 '/','p','u','b','/','o','t','h','e','r','/',
2897 'w','i','n','e','l','o','g','o','.','x','c','f','.','t','a','r','.','b','z','2',0};
2899 trace("Testing ftp protocol...\n");
2901 bindf = BINDF_ASYNCHRONOUS | BINDF_ASYNCSTORAGE | BINDF_PULLDATA | BINDF_FROMURLMON | BINDF_NOWRITECACHE;
2902 state = STATE_STARTDOWNLOADING;
2903 tested_protocol = FTP_TEST;
2904 first_data_notif = TRUE;
2905 expect_hrResult = E_PENDING;
2907 hres = CoGetClassObject(&CLSID_FtpProtocol, CLSCTX_INPROC_SERVER, NULL, &IID_IUnknown, (void**)&unk);
2908 ok(hres == S_OK, "CoGetClassObject failed: %08x\n", hres);
2912 hres = IUnknown_QueryInterface(unk, &IID_IInternetProtocolInfo, (void**)&protocol_info);
2913 ok(hres == E_NOINTERFACE, "Could not get IInternetProtocolInfo interface: %08x, expected E_NOINTERFACE\n", hres);
2915 hres = IUnknown_QueryInterface(unk, &IID_IClassFactory, (void**)&factory);
2916 ok(hres == S_OK, "Could not get IClassFactory interface\n");
2917 IUnknown_Release(unk);
2921 hres = IClassFactory_CreateInstance(factory, NULL, &IID_IInternetProtocol,
2922 (void**)&async_protocol);
2923 IClassFactory_Release(factory);
2924 ok(hres == S_OK, "Could not get IInternetProtocol: %08x\n", hres);
2926 test_priority(async_protocol);
2927 test_http_info(async_protocol);
2929 SET_EXPECT(GetBindInfo);
2930 SET_EXPECT(ReportProgress_FINDINGRESOURCE);
2931 SET_EXPECT(ReportProgress_CONNECTING);
2932 SET_EXPECT(ReportProgress_SENDINGREQUEST);
2935 hres = IInternetProtocol_Start(async_protocol, ftp_urlW, &protocol_sink, &bind_info, 0, 0);
2936 ok(hres == S_OK, "Start failed: %08x\n", hres);
2937 CHECK_CALLED(GetBindInfo);
2939 SET_EXPECT(ReportResult);
2941 hres = IInternetProtocol_Read(async_protocol, buf, 1, &cb);
2942 ok((hres == E_PENDING && cb==0) ||
2943 (hres == S_OK && cb==1), "Read failed: %08x (%d bytes)\n", hres, cb);
2945 WaitForSingleObject(event_complete, INFINITE);
2948 hres = IInternetProtocol_Read(async_protocol, buf, sizeof(buf), &cb);
2949 if(hres == E_PENDING)
2950 WaitForSingleObject(event_complete, INFINITE);
2955 ok(hres == S_FALSE, "Read failed: %08x\n", hres);
2956 CHECK_CALLED(ReportResult);
2957 CHECK_CALLED(Switch);
2959 test_protocol_terminate(async_protocol);
2962 IInternetProtocolEx *protocolex;
2964 hres = IInternetProtocol_QueryInterface(async_protocol, &IID_IInternetProtocolEx, (void**)&protocolex);
2965 ok(hres == S_OK, "Could not get IInternetProtocolEx iface: %08x\n", hres);
2966 IInternetProtocolEx_Release(protocolex);
2969 ref = IInternetProtocol_Release(async_protocol);
2970 ok(!ref, "ref=%d\n", ref);
2972 test_early_abort(&CLSID_FtpProtocol);
2975 static void test_gopher_protocol(void)
2977 IInternetProtocolInfo *protocol_info;
2978 IClassFactory *factory;
2982 trace("Testing gopher protocol...\n");
2984 hres = CoGetClassObject(&CLSID_GopherProtocol, CLSCTX_INPROC_SERVER, NULL, &IID_IUnknown, (void**)&unk);
2986 hres == REGDB_E_CLASSNOTREG, /* Gopher protocol has been removed as of Vista */
2987 "CoGetClassObject failed: %08x\n", hres);
2991 hres = IUnknown_QueryInterface(unk, &IID_IInternetProtocolInfo, (void**)&protocol_info);
2992 ok(hres == E_NOINTERFACE, "Could not get IInternetProtocolInfo interface: %08x, expected E_NOINTERFACE\n", hres);
2994 hres = IUnknown_QueryInterface(unk, &IID_IClassFactory, (void**)&factory);
2995 ok(hres == S_OK, "Could not get IClassFactory interface\n");
2996 IUnknown_Release(unk);
3000 hres = IClassFactory_CreateInstance(factory, NULL, &IID_IInternetProtocol,
3001 (void**)&async_protocol);
3002 IClassFactory_Release(factory);
3003 ok(hres == S_OK, "Could not get IInternetProtocol: %08x\n", hres);
3005 test_priority(async_protocol);
3007 IInternetProtocol_Release(async_protocol);
3009 test_early_abort(&CLSID_GopherProtocol);
3012 static void test_mk_protocol(void)
3014 IInternetProtocolInfo *protocol_info;
3015 IInternetProtocol *protocol;
3016 IClassFactory *factory;
3020 static const WCHAR wrong_url1[] = {'t','e','s','t',':','@','M','S','I','T','S','t','o','r','e',
3021 ':',':','/','t','e','s','t','.','h','t','m','l',0};
3022 static const WCHAR wrong_url2[] = {'m','k',':','/','t','e','s','t','.','h','t','m','l',0};
3024 trace("Testing mk protocol...\n");
3025 init_test(MK_TEST, 0);
3027 hres = CoGetClassObject(&CLSID_MkProtocol, CLSCTX_INPROC_SERVER, NULL,
3028 &IID_IUnknown, (void**)&unk);
3029 ok(hres == S_OK, "CoGetClassObject failed: %08x\n", hres);
3031 hres = IUnknown_QueryInterface(unk, &IID_IInternetProtocolInfo, (void**)&protocol_info);
3032 ok(hres == E_NOINTERFACE,
3033 "Could not get IInternetProtocolInfo interface: %08x, expected E_NOINTERFACE\n",
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,
3044 IClassFactory_Release(factory);
3045 ok(hres == S_OK, "Could not get IInternetProtocol: %08x\n", hres);
3047 SET_EXPECT(GetBindInfo);
3048 hres = IInternetProtocol_Start(protocol, wrong_url1, &protocol_sink, &bind_info, 0, 0);
3049 ok(hres == MK_E_SYNTAX || hres == INET_E_INVALID_URL,
3050 "Start failed: %08x, expected MK_E_SYNTAX or INET_E_INVALID_URL\n", hres);
3051 CLEAR_CALLED(GetBindInfo);
3053 SET_EXPECT(GetBindInfo);
3054 SET_EXPECT(ReportProgress_DIRECTBIND);
3055 SET_EXPECT(ReportProgress_SENDINGREQUEST);
3056 SET_EXPECT(ReportProgress_MIMETYPEAVAILABLE);
3057 SET_EXPECT(ReportResult);
3058 expect_hrResult = INET_E_RESOURCE_NOT_FOUND;
3060 hres = IInternetProtocol_Start(protocol, wrong_url2, &protocol_sink, &bind_info, 0, 0);
3061 ok(hres == INET_E_RESOURCE_NOT_FOUND ||
3062 hres == INET_E_INVALID_URL, /* win2k3 */
3063 "Start failed: %08x, expected INET_E_RESOURCE_NOT_FOUND or INET_E_INVALID_URL\n", hres);
3065 if (hres == INET_E_RESOURCE_NOT_FOUND) {
3066 CHECK_CALLED(GetBindInfo);
3067 CLEAR_CALLED(ReportProgress_DIRECTBIND);
3068 CHECK_CALLED(ReportProgress_SENDINGREQUEST);
3069 CHECK_CALLED(ReportProgress_MIMETYPEAVAILABLE);
3070 CHECK_CALLED(ReportResult);
3072 CLEAR_CALLED(GetBindInfo);
3073 CLEAR_CALLED(ReportProgress_DIRECTBIND);
3074 CLEAR_CALLED(ReportProgress_SENDINGREQUEST);
3075 CLEAR_CALLED(ReportProgress_MIMETYPEAVAILABLE);
3076 CLEAR_CALLED(ReportResult);
3079 IInternetProtocol_Release(protocol);
3082 static void test_CreateBinding(void)
3084 IInternetProtocol *protocol;
3085 IInternetPriority *priority;
3086 IInternetSession *session;
3087 IWinInetHttpInfo *http_info;
3088 IWinInetInfo *inet_info;
3094 static const WCHAR test_url[] =
3095 {'t','e','s','t',':','/','/','f','i','l','e','.','h','t','m','l',0};
3096 static const WCHAR wsz_test[] = {'t','e','s','t',0};
3098 trace("Testing CreateBinding...\n");
3099 init_test(BIND_TEST, TEST_BINDING);
3101 hres = pCoInternetGetSession(0, &session, 0);
3102 ok(hres == S_OK, "CoInternetGetSession failed: %08x\n", hres);
3104 hres = IInternetSession_RegisterNameSpace(session, &ClassFactory, &IID_NULL, wsz_test, 0, NULL, 0);
3105 ok(hres == S_OK, "RegisterNameSpace failed: %08x\n", hres);
3107 hres = IInternetSession_CreateBinding(session, NULL, test_url, NULL, NULL, &protocol, 0);
3108 binding_protocol = protocol;
3109 ok(hres == S_OK, "CreateBinding failed: %08x\n", hres);
3110 ok(protocol != NULL, "protocol == NULL\n");
3112 hres = IInternetProtocol_QueryInterface(protocol, &IID_IInternetBindInfo, (void**)&prot_bind_info);
3113 ok(hres == S_OK, "QueryInterface(IID_IInternetBindInfo) failed: %08x\n", hres);
3115 hres = IInternetProtocol_QueryInterface(protocol, &IID_IInternetProtocolSink, (void**)&binding_sink);
3116 ok(hres == S_OK, "Could not get IInternetProtocolSink: %08x\n", hres);
3118 hres = IInternetProtocol_Start(protocol, test_url, NULL, &bind_info, 0, 0);
3119 ok(hres == E_INVALIDARG, "Start failed: %08x, expected E_INVALIDARG\n", hres);
3120 hres = IInternetProtocol_Start(protocol, test_url, &protocol_sink, NULL, 0, 0);
3121 ok(hres == E_INVALIDARG, "Start failed: %08x, expected E_INVALIDARG\n", hres);
3122 hres = IInternetProtocol_Start(protocol, NULL, &protocol_sink, &bind_info, 0, 0);
3123 ok(hres == E_INVALIDARG, "Start failed: %08x, expected E_INVALIDARG\n", hres);
3125 hres = IInternetProtocol_QueryInterface(protocol, &IID_IInternetPriority, (void**)&priority);
3126 ok(hres == S_OK, "QueryInterface(IID_IInternetPriority) failed: %08x\n", hres);
3129 hres = IInternetPriority_GetPriority(priority, &p);
3130 ok(hres == S_OK, "GetPriority failed: %08x\n", hres);
3131 ok(!p, "p=%d\n", p);
3134 hres = IInternetPriority_SetPriority(priority, 100);
3135 ok(hres == S_OK, "SetPriority failed: %08x\n", hres);
3138 hres = IInternetPriority_GetPriority(priority, &p);
3139 ok(hres == S_OK, "GetPriority failed: %08x\n", hres);
3140 ok(p == 100, "p=%d\n", p);
3142 hres = IInternetProtocol_QueryInterface(protocol, &IID_IWinInetInfo, (void**)&inet_info);
3143 ok(hres == E_NOINTERFACE, "Could not get IWinInetInfo protocol: %08x\n", hres);
3145 SET_EXPECT(QueryService_InternetProtocol);
3146 SET_EXPECT(CreateInstance);
3147 SET_EXPECT(ReportProgress_PROTOCOLCLASSID);
3148 SET_EXPECT(SetPriority);
3151 expect_hrResult = S_OK;
3152 hres = IInternetProtocol_Start(protocol, test_url, &protocol_sink, &bind_info, 0, 0);
3153 ok(hres == S_OK, "Start failed: %08x\n", hres);
3155 CHECK_CALLED(QueryService_InternetProtocol);
3156 CHECK_CALLED(CreateInstance);
3157 CHECK_CALLED(ReportProgress_PROTOCOLCLASSID);
3158 CHECK_CALLED(SetPriority);
3159 CHECK_CALLED(Start);
3161 SET_EXPECT(QueryInterface_IWinInetInfo);
3162 hres = IInternetProtocol_QueryInterface(protocol, &IID_IWinInetInfo, (void**)&inet_info);
3163 ok(hres == E_NOINTERFACE, "Could not get IWinInetInfo protocol: %08x\n", hres);
3164 CHECK_CALLED(QueryInterface_IWinInetInfo);
3166 SET_EXPECT(QueryInterface_IWinInetInfo);
3167 hres = IInternetProtocol_QueryInterface(protocol, &IID_IWinInetInfo, (void**)&inet_info);
3168 ok(hres == E_NOINTERFACE, "Could not get IWinInetInfo protocol: %08x\n", hres);
3169 CHECK_CALLED(QueryInterface_IWinInetInfo);
3171 SET_EXPECT(QueryInterface_IWinInetHttpInfo);
3172 hres = IInternetProtocol_QueryInterface(protocol, &IID_IWinInetHttpInfo, (void**)&http_info);
3173 ok(hres == E_NOINTERFACE, "Could not get IWinInetInfo protocol: %08x\n", hres);
3174 CHECK_CALLED(QueryInterface_IWinInetHttpInfo);
3178 hres = IInternetProtocol_Read(protocol, expect_pv = buf, sizeof(buf), &read);
3179 ok(hres == S_OK, "Read failed: %08x\n", hres);
3180 ok(read == 100, "read = %d\n", read);
3185 hres = IInternetProtocol_Read(protocol, expect_pv = buf, sizeof(buf), &read);
3186 ok(hres == S_FALSE, "Read failed: %08x\n", hres);
3187 ok(!read, "read = %d\n", read);
3191 hres = IInternetPriority_GetPriority(priority, &p);
3192 ok(hres == S_OK, "GetPriority failed: %08x\n", hres);
3193 ok(p == 100, "p=%d\n", p);
3195 hres = IInternetPriority_SetPriority(priority, 101);
3196 ok(hres == S_OK, "SetPriority failed: %08x\n", hres);
3198 SET_EXPECT(Terminate);
3199 hres = IInternetProtocol_Terminate(protocol, 0xdeadbeef);
3200 ok(hres == S_OK, "Terminate failed: %08x\n", hres);
3201 CHECK_CALLED(Terminate);
3203 SET_EXPECT(Continue);
3204 hres = IInternetProtocolSink_Switch(binding_sink, &protocoldata);
3205 ok(hres == S_OK, "Switch failed: %08x\n", hres);
3206 CHECK_CALLED(Continue);
3208 hres = IInternetProtocolSink_ReportProgress(binding_sink,
3209 BINDSTATUS_CACHEFILENAMEAVAILABLE, expect_wsz = emptyW);
3210 ok(hres == S_OK, "ReportProgress(BINDSTATUS_CACHEFILENAMEAVAILABLE) failed: %08x\n", hres);
3212 hres = IInternetProtocolSink_ReportResult(binding_sink, S_OK, ERROR_SUCCESS, NULL);
3213 ok(hres == E_FAIL, "ReportResult failed: %08x, expected E_FAIL\n", hres);
3215 hres = IInternetProtocolSink_ReportData(binding_sink, 0, 0, 0);
3216 ok(hres == S_OK, "ReportData failed: %08x\n", hres);
3218 IInternetProtocolSink_Release(binding_sink);
3219 IInternetPriority_Release(priority);
3220 IInternetBindInfo_Release(prot_bind_info);
3221 IInternetProtocol_Release(protocol);
3223 hres = IInternetSession_CreateBinding(session, NULL, test_url, NULL, NULL, &protocol, 0);
3224 ok(hres == S_OK, "CreateBinding failed: %08x\n", hres);
3225 ok(protocol != NULL, "protocol == NULL\n");
3227 hres = IInternetProtocol_Abort(protocol, E_ABORT, 0);
3228 ok(hres == S_OK, "Abort failed: %08x\n", hres);
3230 hres = IInternetProtocol_Abort(protocol, E_FAIL, 0);
3231 ok(hres == S_OK, "Abort failed: %08x\n", hres);
3233 IInternetProtocol_Release(protocol);
3235 hres = IInternetSession_UnregisterNameSpace(session, &ClassFactory, wsz_test);
3236 ok(hres == S_OK, "UnregisterNameSpace failed: %08x\n", hres);
3238 hres = IInternetSession_CreateBinding(session, NULL, test_url, NULL, NULL, &protocol, 0);
3239 ok(hres == S_OK, "CreateBinding failed: %08x\n", hres);
3240 ok(protocol != NULL, "protocol == NULL\n");
3242 SET_EXPECT(QueryService_InternetProtocol);
3243 hres = IInternetProtocol_Start(protocol, test_url, &protocol_sink, &bind_info, 0, 0);
3244 ok(hres == MK_E_SYNTAX, "Start failed: %08x, expected MK_E_SYNTAX\n", hres);
3245 CHECK_CALLED(QueryService_InternetProtocol);
3247 IInternetProtocol_Release(protocol);
3249 IInternetSession_Release(session);
3252 static void test_binding(int prot, DWORD grf_pi, DWORD test_flags)
3254 IInternetProtocol *protocol;
3255 IInternetSession *session;
3261 init_test(prot, test_flags|TEST_BINDING);
3263 hres = pCoInternetGetSession(0, &session, 0);
3264 ok(hres == S_OK, "CoInternetGetSession failed: %08x\n", hres);
3266 if(test_flags & TEST_EMULATEPROT) {
3267 hres = IInternetSession_RegisterNameSpace(session, &ClassFactory, &IID_NULL, protocol_names[prot], 0, NULL, 0);
3268 ok(hres == S_OK, "RegisterNameSpace failed: %08x\n", hres);
3271 hres = IInternetSession_CreateBinding(session, NULL, binding_urls[prot], NULL, NULL, &protocol, 0);
3272 binding_protocol = protocol;
3273 ok(hres == S_OK, "CreateBinding failed: %08x\n", hres);
3274 ok(protocol != NULL, "protocol == NULL\n");
3276 hres = IInternetProtocol_QueryInterface(protocol, &IID_IInternetBindInfo, (void**)&prot_bind_info);
3277 ok(hres == S_OK, "QueryInterface(IID_IInternetBindInfo) failed: %08x\n", hres);
3279 hres = IInternetProtocol_QueryInterface(protocol, &IID_IInternetProtocolSink, (void**)&binding_sink);
3280 ok(hres == S_OK, "QueryInterface(IID_IInternetProtocolSink) failed: %08x\n", hres);
3283 SET_EXPECT(QueryService_InternetProtocol);
3284 SET_EXPECT(CreateInstance);
3285 SET_EXPECT(ReportProgress_PROTOCOLCLASSID);
3286 SET_EXPECT(SetPriority);
3289 expect_hrResult = S_OK;
3290 hres = IInternetProtocol_Start(protocol, binding_urls[prot], &protocol_sink, &bind_info, pi, 0);
3291 ok(hres == S_OK, "Start failed: %08x\n", hres);
3293 CHECK_CALLED(QueryService_InternetProtocol);
3294 CHECK_CALLED(CreateInstance);
3295 CHECK_CALLED(ReportProgress_PROTOCOLCLASSID);
3296 CHECK_CALLED(SetPriority);
3297 CHECK_CALLED(Start);
3299 if(prot == HTTP_TEST || prot == HTTPS_TEST) {
3300 while(prot_state < 4) {
3301 WaitForSingleObject(event_complete, INFINITE);
3302 if(mimefilter_test && filtered_protocol) {
3303 SET_EXPECT(Continue);
3304 IInternetProtocol_Continue(filtered_protocol, pdata);
3305 CHECK_CALLED(Continue);
3307 SET_EXPECT(Continue);
3308 IInternetProtocol_Continue(protocol, pdata);
3309 CHECK_CALLED(Continue);
3311 if(test_abort && prot_state == 2) {
3313 hres = IInternetProtocol_Abort(protocol, E_ABORT, 0);
3314 ok(hres == S_OK, "Abort failed: %08x\n", hres);
3315 CHECK_CALLED(Abort);
3317 hres = IInternetProtocol_Abort(protocol, E_ABORT, 0);
3318 ok(hres == S_OK, "Abort failed: %08x\n", hres);
3319 SetEvent(event_complete2);
3322 SetEvent(event_complete2);
3325 CHECK_CALLED(ReportData); /* Set in ReportResult */
3326 WaitForSingleObject(event_complete, INFINITE);
3329 SET_EXPECT(MimeFilter_LockRequest);
3331 SET_EXPECT(LockRequest);
3332 hres = IInternetProtocol_LockRequest(protocol, 0);
3333 ok(hres == S_OK, "LockRequest failed: %08x\n", hres);
3335 CHECK_CALLED(MimeFilter_LockRequest);
3337 CHECK_CALLED(LockRequest);
3340 SET_EXPECT(MimeFilter_UnlockRequest);
3342 SET_EXPECT(UnlockRequest);
3343 hres = IInternetProtocol_UnlockRequest(protocol);
3344 ok(hres == S_OK, "UnlockRequest failed: %08x\n", hres);
3346 CHECK_CALLED(MimeFilter_UnlockRequest);
3348 CHECK_CALLED(UnlockRequest);
3352 SET_EXPECT(MimeFilter_Terminate);
3354 SET_EXPECT(Terminate);
3355 hres = IInternetProtocol_Terminate(protocol, 0);
3356 ok(hres == S_OK, "Terminate failed: %08x\n", hres);
3358 CLEAR_CALLED(MimeFilter_Terminate);
3360 CHECK_CALLED(Terminate);
3362 if(filtered_protocol)
3363 IInternetProtocol_Release(filtered_protocol);
3364 IInternetBindInfo_Release(prot_bind_info);
3365 IInternetProtocolSink_Release(binding_sink);
3366 ref = IInternetProtocol_Release(protocol);
3367 ok(!ref, "ref=%u, expected 0\n", ref);
3369 if(test_flags & TEST_EMULATEPROT) {
3370 hres = IInternetSession_UnregisterNameSpace(session, &ClassFactory, protocol_names[prot]);
3371 ok(hres == S_OK, "UnregisterNameSpace failed: %08x\n", hres);
3374 IInternetSession_Release(session);
3377 static void register_filter(void)
3379 IInternetSession *session;
3382 static const WCHAR gzipW[] = {'g','z','i','p',0};
3384 hres = pCoInternetGetSession(0, &session, 0);
3385 ok(hres == S_OK, "CoInternetGetSession failed: %08x\n", hres);
3387 hres = IInternetSession_RegisterMimeFilter(session, &mimefilter_cf, &IID_IInternetProtocol, gzipW);
3388 ok(hres == S_OK, "RegisterMimeFilter failed: %08x\n", hres);
3390 IInternetSession_Release(session);
3393 START_TEST(protocol)
3397 hurlmon = GetModuleHandle("urlmon.dll");
3398 pCoInternetGetSession = (void*) GetProcAddress(hurlmon, "CoInternetGetSession");
3399 pReleaseBindInfo = (void*) GetProcAddress(hurlmon, "ReleaseBindInfo");
3400 pCreateUri = (void*) GetProcAddress(hurlmon, "CreateUri");
3402 if(!GetProcAddress(hurlmon, "CompareSecurityIds")) {
3403 win_skip("Various needed functions not present, too old IE\n");
3408 win_skip("CreateUri not supported\n");
3410 OleInitialize(NULL);
3412 event_complete = CreateEvent(NULL, FALSE, FALSE, NULL);
3413 event_complete2 = CreateEvent(NULL, FALSE, FALSE, NULL);
3414 event_continue = CreateEvent(NULL, FALSE, FALSE, NULL);
3415 event_continue_done = CreateEvent(NULL, FALSE, FALSE, NULL);
3416 thread_id = GetCurrentThreadId();
3420 test_file_protocol();
3421 test_http_protocol();
3422 test_https_protocol();
3423 test_ftp_protocol();
3424 test_gopher_protocol();
3426 test_CreateBinding();
3428 bindf &= ~BINDF_FROMURLMON;
3429 trace("Testing file binding (mime verification, emulate prot)...\n");
3430 test_binding(FILE_TEST, PI_MIMEVERIFICATION, TEST_EMULATEPROT);
3431 trace("Testing http binding (mime verification, emulate prot)...\n");
3432 test_binding(HTTP_TEST, PI_MIMEVERIFICATION, TEST_EMULATEPROT);
3433 trace("Testing http binding (mime verification, emulate prot, short read, direct read)...\n");
3434 test_binding(HTTP_TEST, PI_MIMEVERIFICATION, TEST_EMULATEPROT|TEST_SHORT_READ|TEST_DIRECT_READ);
3435 trace("Testing file binding (mime verification, emulate prot, mime filter)...\n");
3436 test_binding(FILE_TEST, PI_MIMEVERIFICATION, TEST_EMULATEPROT|TEST_FILTER);
3437 trace("Testing http binding (mime verification, emulate prot, mime filter)...\n");
3438 test_binding(HTTP_TEST, PI_MIMEVERIFICATION, TEST_EMULATEPROT|TEST_FILTER);
3439 trace("Testing http binding (mime verification, emulate prot, direct read)...\n");
3440 test_binding(HTTP_TEST, PI_MIMEVERIFICATION, TEST_EMULATEPROT|TEST_DIRECT_READ);
3441 trace("Testing http binding (mime verification, emulate prot, abort)...\n");
3442 test_binding(HTTP_TEST, PI_MIMEVERIFICATION, TEST_EMULATEPROT|TEST_ABORT);
3444 CloseHandle(event_complete);
3445 CloseHandle(event_complete2);
3446 CloseHandle(event_continue);
3447 CloseHandle(event_continue_done);