2 * Copyright 2005-2009 Jacek Caban for CodeWeavers
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
22 #include <wine/test.h>
32 static HRESULT (WINAPI *pCoInternetGetSession)(DWORD, IInternetSession **, DWORD);
33 static HRESULT (WINAPI *pReleaseBindInfo)(BINDINFO*);
34 static HRESULT (WINAPI *pCreateUri)(LPCWSTR, DWORD, DWORD_PTR, IUri**);
36 #define DEFINE_EXPECT(func) \
37 static BOOL expect_ ## func = FALSE, called_ ## func = FALSE
39 #define SET_EXPECT(func) \
40 expect_ ## func = TRUE
42 #define CHECK_EXPECT2(func) \
44 ok(expect_ ##func, "unexpected call " #func "\n"); \
45 called_ ## func = TRUE; \
48 #define CHECK_EXPECT(func) \
50 CHECK_EXPECT2(func); \
51 expect_ ## func = FALSE; \
54 #define CHECK_CALLED(func) \
56 ok(called_ ## func, "expected " #func "\n"); \
57 expect_ ## func = called_ ## func = FALSE; \
60 #define CHECK_NOT_CALLED(func) \
62 ok(!called_ ## func, "unexpected " #func "\n"); \
63 expect_ ## func = called_ ## func = FALSE; \
66 #define CLEAR_CALLED(func) \
67 expect_ ## func = called_ ## func = FALSE
69 DEFINE_EXPECT(GetBindInfo);
70 DEFINE_EXPECT(ReportProgress_MIMETYPEAVAILABLE);
71 DEFINE_EXPECT(ReportProgress_DIRECTBIND);
72 DEFINE_EXPECT(ReportProgress_RAWMIMETYPE);
73 DEFINE_EXPECT(ReportProgress_FINDINGRESOURCE);
74 DEFINE_EXPECT(ReportProgress_CONNECTING);
75 DEFINE_EXPECT(ReportProgress_SENDINGREQUEST);
76 DEFINE_EXPECT(ReportProgress_CACHEFILENAMEAVAILABLE);
77 DEFINE_EXPECT(ReportProgress_VERIFIEDMIMETYPEAVAILABLE);
78 DEFINE_EXPECT(ReportProgress_PROTOCOLCLASSID);
79 DEFINE_EXPECT(ReportProgress_COOKIE_SENT);
80 DEFINE_EXPECT(ReportProgress_REDIRECTING);
81 DEFINE_EXPECT(ReportProgress_ENCODING);
82 DEFINE_EXPECT(ReportProgress_ACCEPTRANGES);
83 DEFINE_EXPECT(ReportProgress_PROXYDETECTING);
84 DEFINE_EXPECT(ReportProgress_LOADINGMIMEHANDLER);
85 DEFINE_EXPECT(ReportProgress_DECODING);
86 DEFINE_EXPECT(ReportData);
87 DEFINE_EXPECT(ReportData2);
88 DEFINE_EXPECT(ReportResult);
89 DEFINE_EXPECT(GetBindString_ACCEPT_MIMES);
90 DEFINE_EXPECT(GetBindString_USER_AGENT);
91 DEFINE_EXPECT(GetBindString_POST_COOKIE);
92 DEFINE_EXPECT(GetBindString_URL);
93 DEFINE_EXPECT(QueryService_HttpNegotiate);
94 DEFINE_EXPECT(QueryService_InternetProtocol);
95 DEFINE_EXPECT(QueryService_HttpSecurity);
96 DEFINE_EXPECT(QueryInterface_IWinInetInfo);
97 DEFINE_EXPECT(QueryInterface_IWinInetHttpInfo);
98 DEFINE_EXPECT(BeginningTransaction);
99 DEFINE_EXPECT(GetRootSecurityId);
100 DEFINE_EXPECT(OnResponse);
101 DEFINE_EXPECT(Switch);
102 DEFINE_EXPECT(Continue);
103 DEFINE_EXPECT(CreateInstance);
104 DEFINE_EXPECT(Start);
105 DEFINE_EXPECT(StartEx);
106 DEFINE_EXPECT(Terminate);
108 DEFINE_EXPECT(Read2);
109 DEFINE_EXPECT(SetPriority);
110 DEFINE_EXPECT(LockRequest);
111 DEFINE_EXPECT(UnlockRequest);
112 DEFINE_EXPECT(Abort);
113 DEFINE_EXPECT(MimeFilter_CreateInstance);
114 DEFINE_EXPECT(MimeFilter_Start);
115 DEFINE_EXPECT(MimeFilter_ReportProgress);
116 DEFINE_EXPECT(MimeFilter_ReportData);
117 DEFINE_EXPECT(MimeFilter_ReportResult);
118 DEFINE_EXPECT(MimeFilter_Terminate);
119 DEFINE_EXPECT(MimeFilter_LockRequest);
120 DEFINE_EXPECT(MimeFilter_UnlockRequest);
121 DEFINE_EXPECT(MimeFilter_Read);
122 DEFINE_EXPECT(MimeFilter_Switch);
123 DEFINE_EXPECT(MimeFilter_Continue);
124 DEFINE_EXPECT(Stream_Seek);
125 DEFINE_EXPECT(Stream_Read);
127 static const WCHAR wszIndexHtml[] = {'i','n','d','e','x','.','h','t','m','l',0};
128 static const WCHAR index_url[] =
129 {'f','i','l','e',':','i','n','d','e','x','.','h','t','m','l',0};
131 static const WCHAR acc_mimeW[] = {'*','/','*',0};
132 static const WCHAR user_agentW[] = {'W','i','n','e',0};
133 static const WCHAR text_htmlW[] = {'t','e','x','t','/','h','t','m','l',0};
134 static const WCHAR hostW[] = {'w','w','w','.','w','i','n','e','h','q','.','o','r','g',0};
135 static const WCHAR winehq_ipW[] = {'2','0','9','.','4','6','.','2','5','.','1','3','4',0};
136 static const WCHAR emptyW[] = {0};
137 static const WCHAR gzipW[] = {'g','z','i','p',0};
139 static HRESULT expect_hrResult;
140 static LPCWSTR file_name, http_url, expect_wsz;
141 static IInternetProtocol *async_protocol = NULL;
142 static BOOL first_data_notif, http_is_first, test_redirect;
143 static int prot_state, read_report_data, post_stream_read;
144 static DWORD bindf, ex_priority , pi;
145 static IInternetProtocol *binding_protocol, *filtered_protocol;
146 static IInternetBindInfo *prot_bind_info;
147 static IInternetProtocolSink *binding_sink, *filtered_sink;
148 static void *expect_pv;
149 static HANDLE event_complete, event_complete2, event_continue, event_continue_done;
150 static BOOL binding_test;
151 static PROTOCOLDATA protocoldata, *pdata, continue_protdata;
152 static DWORD prot_read, pi, filter_state, http_post_test, thread_id;
153 static BOOL security_problem, test_async_req, impl_protex;
154 static BOOL async_read_pending, mimefilter_test, direct_read, wait_for_switch, emulate_prot, short_read, test_abort;
158 STATE_SENDINGREQUEST,
159 STATE_STARTDOWNLOADING,
172 static const WCHAR protocol_names[][10] = {
175 {'h','t','t','p','s',0},
181 static const WCHAR binding_urls[][130] = {
182 {'f','i','l','e',':','t','e','s','t','.','h','t','m','l',0},
183 {'h','t','t','p',':','/','/','w','w','w','.','w','i','n','e','h','q','.',
184 'o','r','g','/','s','i','t','e','/','a','b','o','u','t',0},
185 {'h','t','t','p','s',':','/','/','w','w','w','.','c','o','d','e','w','e','a','v','e','r','s',
186 '.','c','o','m','/','t','e','s','t','.','h','t','m','l',0},
187 {'f','t','p',':','/','/','f','t','p','.','w','i','n','e','h','q','.','o','r','g',
188 '/','p','u','b','/','o','t','h','e','r',
189 '/','w','i','n','e','l','o','g','o','.','x','c','f','.','t','a','r','.','b','z','2',0},
190 {'m','k',':','t','e','s','t',0},
191 {'t','e','s','t',':','/','/','f','i','l','e','.','h','t','m','l',0}
194 static const CHAR post_data[] = "mode=Test";
196 static const char *debugstr_guid(REFIID riid)
200 sprintf(buf, "{%08X-%04X-%04X-%02X%02X-%02X%02X%02X%02X%02X%02X}",
201 riid->Data1, riid->Data2, riid->Data3, riid->Data4[0],
202 riid->Data4[1], riid->Data4[2], riid->Data4[3], riid->Data4[4],
203 riid->Data4[5], riid->Data4[6], riid->Data4[7]);
208 static int strcmp_wa(LPCWSTR strw, const char *stra)
211 WideCharToMultiByte(CP_ACP, 0, strw, -1, buf, sizeof(buf), NULL, NULL);
212 return lstrcmpA(stra, buf);
215 /* lstrcmpW is not implemented on Win9x */
216 static int strcmp_ww(LPCWSTR strw1, LPCWSTR strw2)
218 CHAR stra1[512], stra2[512];
219 WideCharToMultiByte(CP_ACP, 0, strw1, -1, stra1, MAX_PATH, NULL, NULL);
220 WideCharToMultiByte(CP_ACP, 0, strw2, -1, stra2, MAX_PATH, NULL, NULL);
221 return lstrcmpA(stra1, stra2);
224 static BOOL proxy_active(void)
226 HKEY internet_settings;
230 if (RegOpenKeyExA(HKEY_CURRENT_USER, "Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings",
231 0, KEY_QUERY_VALUE, &internet_settings) != ERROR_SUCCESS)
234 size = sizeof(DWORD);
235 if (RegQueryValueExA(internet_settings, "ProxyEnable", NULL, NULL, (LPBYTE) &proxy_enable, &size) != ERROR_SUCCESS)
238 RegCloseKey(internet_settings);
240 return proxy_enable != 0;
243 static HRESULT WINAPI HttpSecurity_QueryInterface(IHttpSecurity *iface, REFIID riid, void **ppv)
245 if(IsEqualGUID(&IID_IUnknown, riid)
246 || IsEqualGUID(&IID_IHttpSecurity, riid)) {
251 ok(0, "unexpected call\n");
252 return E_NOINTERFACE;
255 static ULONG WINAPI HttpSecurity_AddRef(IHttpSecurity *iface)
260 static ULONG WINAPI HttpSecurity_Release(IHttpSecurity *iface)
265 static HRESULT WINAPI HttpSecurity_GetWindow(IHttpSecurity* iface, REFGUID rguidReason, HWND *phwnd)
267 trace("HttpSecurity_GetWindow\n");
272 static HRESULT WINAPI HttpSecurity_OnSecurityProblem(IHttpSecurity *iface, DWORD dwProblem)
274 trace("Security problem: %u\n", dwProblem);
275 ok(dwProblem == ERROR_INTERNET_SEC_CERT_REV_FAILED, "Expected ERROR_INTERNET_SEC_CERT_REV_FAILED got %u\n", dwProblem);
277 /* Only retry once */
278 if (security_problem)
281 security_problem = TRUE;
282 SET_EXPECT(BeginningTransaction);
287 static IHttpSecurityVtbl HttpSecurityVtbl = {
288 HttpSecurity_QueryInterface,
290 HttpSecurity_Release,
291 HttpSecurity_GetWindow,
292 HttpSecurity_OnSecurityProblem
295 static IHttpSecurity http_security = { &HttpSecurityVtbl };
297 static HRESULT WINAPI HttpNegotiate_QueryInterface(IHttpNegotiate2 *iface, REFIID riid, void **ppv)
299 if(IsEqualGUID(&IID_IUnknown, riid)
300 || IsEqualGUID(&IID_IHttpNegotiate, riid)
301 || IsEqualGUID(&IID_IHttpNegotiate2, riid)) {
306 ok(0, "unexpected call\n");
307 return E_NOINTERFACE;
310 static ULONG WINAPI HttpNegotiate_AddRef(IHttpNegotiate2 *iface)
315 static ULONG WINAPI HttpNegotiate_Release(IHttpNegotiate2 *iface)
320 static HRESULT WINAPI HttpNegotiate_BeginningTransaction(IHttpNegotiate2 *iface, LPCWSTR szURL,
321 LPCWSTR szHeaders, DWORD dwReserved, LPWSTR *pszAdditionalHeaders)
325 static const WCHAR wszHeaders[] =
326 {'C','o','n','t','e','n','t','-','T','y','p','e',':',' ','a','p','p','l','i','c','a','t',
327 'i','o','n','/','x','-','w','w','w','-','f','o','r','m','-','u','r','l','e','n','c','o',
328 'd','e','d','\r','\n',0};
330 CHECK_EXPECT(BeginningTransaction);
333 ok(!strcmp_ww(szURL, binding_urls[tested_protocol]), "szURL != http_url\n");
335 ok(!strcmp_ww(szURL, http_url), "szURL != http_url\n");
336 ok(!dwReserved, "dwReserved=%d, expected 0\n", dwReserved);
337 ok(pszAdditionalHeaders != NULL, "pszAdditionalHeaders == NULL\n");
338 if(pszAdditionalHeaders)
340 ok(*pszAdditionalHeaders == NULL, "*pszAdditionalHeaders != NULL\n");
343 addl_headers = CoTaskMemAlloc(sizeof(wszHeaders));
344 memcpy(addl_headers, wszHeaders, sizeof(wszHeaders));
345 *pszAdditionalHeaders = addl_headers;
352 static HRESULT WINAPI HttpNegotiate_OnResponse(IHttpNegotiate2 *iface, DWORD dwResponseCode,
353 LPCWSTR szResponseHeaders, LPCWSTR szRequestHeaders, LPWSTR *pszAdditionalRequestHeaders)
355 CHECK_EXPECT(OnResponse);
357 ok(dwResponseCode == 200, "dwResponseCode=%d, expected 200\n", dwResponseCode);
358 ok(szResponseHeaders != NULL, "szResponseHeaders == NULL\n");
359 ok(szRequestHeaders == NULL, "szRequestHeaders != NULL\n");
360 ok(pszAdditionalRequestHeaders == NULL, "pszAdditionalHeaders != NULL\n");
365 static HRESULT WINAPI HttpNegotiate_GetRootSecurityId(IHttpNegotiate2 *iface,
366 BYTE *pbSecurityId, DWORD *pcbSecurityId, DWORD_PTR dwReserved)
368 static const BYTE sec_id[] = {'h','t','t','p',':','t','e','s','t',1,0,0,0};
370 CHECK_EXPECT(GetRootSecurityId);
372 ok(!dwReserved, "dwReserved=%ld, expected 0\n", dwReserved);
373 ok(pbSecurityId != NULL, "pbSecurityId == NULL\n");
374 ok(pcbSecurityId != NULL, "pcbSecurityId == NULL\n");
377 ok(*pcbSecurityId == 512, "*pcbSecurityId=%d, expected 512\n", *pcbSecurityId);
378 *pcbSecurityId = sizeof(sec_id);
382 memcpy(pbSecurityId, sec_id, sizeof(sec_id));
387 static IHttpNegotiate2Vtbl HttpNegotiateVtbl = {
388 HttpNegotiate_QueryInterface,
389 HttpNegotiate_AddRef,
390 HttpNegotiate_Release,
391 HttpNegotiate_BeginningTransaction,
392 HttpNegotiate_OnResponse,
393 HttpNegotiate_GetRootSecurityId
396 static IHttpNegotiate2 http_negotiate = { &HttpNegotiateVtbl };
398 static HRESULT QueryInterface(REFIID,void**);
400 static HRESULT WINAPI ServiceProvider_QueryInterface(IServiceProvider *iface, REFIID riid, void **ppv)
402 return QueryInterface(riid, ppv);
405 static ULONG WINAPI ServiceProvider_AddRef(IServiceProvider *iface)
410 static ULONG WINAPI ServiceProvider_Release(IServiceProvider *iface)
415 static HRESULT WINAPI ServiceProvider_QueryService(IServiceProvider *iface, REFGUID guidService,
416 REFIID riid, void **ppv)
418 if(IsEqualGUID(&IID_IHttpNegotiate, guidService) || IsEqualGUID(&IID_IHttpNegotiate2, riid)) {
419 CHECK_EXPECT2(QueryService_HttpNegotiate);
420 return IHttpNegotiate2_QueryInterface(&http_negotiate, riid, ppv);
423 if(IsEqualGUID(&IID_IInternetProtocol, guidService)) {
424 ok(IsEqualGUID(&IID_IInternetProtocol, riid), "unexpected riid\n");
425 CHECK_EXPECT(QueryService_InternetProtocol);
426 return E_NOINTERFACE;
429 if(IsEqualGUID(&IID_IHttpSecurity, guidService)) {
430 ok(IsEqualGUID(&IID_IHttpSecurity, riid), "unexpected riid\n");
431 CHECK_EXPECT(QueryService_HttpSecurity);
432 return IHttpSecurity_QueryInterface(&http_security, riid, ppv);
435 ok(0, "unexpected service %s\n", debugstr_guid(guidService));
439 static const IServiceProviderVtbl ServiceProviderVtbl = {
440 ServiceProvider_QueryInterface,
441 ServiceProvider_AddRef,
442 ServiceProvider_Release,
443 ServiceProvider_QueryService
446 static IServiceProvider service_provider = { &ServiceProviderVtbl };
448 static HRESULT WINAPI Stream_QueryInterface(IStream *iface, REFIID riid, void **ppv)
450 ok(0, "unexpected call\n");
451 return E_NOINTERFACE;
454 static ULONG WINAPI Stream_AddRef(IStream *iface)
459 static ULONG WINAPI Stream_Release(IStream *iface)
464 static HRESULT WINAPI Stream_Read(IStream *iface, void *pv,
465 ULONG cb, ULONG *pcbRead)
467 CHECK_EXPECT2(Stream_Read);
469 ok(GetCurrentThreadId() != thread_id, "wrong thread %d\n", GetCurrentThreadId());
471 ok(pv != NULL, "pv == NULL\n");
472 ok(cb == 0x20000 || broken(cb == 0x2000), "cb = %d\n", cb);
473 ok(pcbRead != NULL, "pcbRead == NULL\n");
475 if(post_stream_read) {
480 memcpy(pv, post_data, sizeof(post_data)-1);
481 post_stream_read += *pcbRead = sizeof(post_data)-1;
485 static HRESULT WINAPI Stream_Write(IStream *iface, const void *pv,
486 ULONG cb, ULONG *pcbWritten)
488 ok(0, "unexpected call\n");
492 static HRESULT WINAPI Stream_Seek(IStream *iface, LARGE_INTEGER dlibMove,
493 DWORD dwOrigin, ULARGE_INTEGER *plibNewPosition)
495 CHECK_EXPECT(Stream_Seek);
497 ok(!dlibMove.QuadPart, "dlibMove != 0\n");
498 ok(dwOrigin == STREAM_SEEK_SET, "dwOrigin = %d\n", dwOrigin);
499 ok(!plibNewPosition, "plibNewPosition == NULL\n");
504 static HRESULT WINAPI Stream_SetSize(IStream *iface, ULARGE_INTEGER libNewSize)
506 ok(0, "unexpected call\n");
510 static HRESULT WINAPI Stream_CopyTo(IStream *iface, IStream *pstm,
511 ULARGE_INTEGER cb, ULARGE_INTEGER *pcbRead, ULARGE_INTEGER *pcbWritten)
513 ok(0, "unexpected call\n");
517 static HRESULT WINAPI Stream_Commit(IStream *iface, DWORD grfCommitFlags)
519 ok(0, "unexpected call\n");
523 static HRESULT WINAPI Stream_Revert(IStream *iface)
525 ok(0, "unexpected call\n");
529 static HRESULT WINAPI Stream_LockRegion(IStream *iface, ULARGE_INTEGER libOffset,
530 ULARGE_INTEGER cb, DWORD dwLockType)
532 ok(0, "unexpected call\n");
536 static HRESULT WINAPI Stream_UnlockRegion(IStream *iface,
537 ULARGE_INTEGER libOffset, ULARGE_INTEGER cb, DWORD dwLockType)
539 ok(0, "unexpected call\n");
543 static HRESULT WINAPI Stream_Stat(IStream *iface, STATSTG *pstatstg,
546 ok(0, "unexpected call\n");
550 static HRESULT WINAPI Stream_Clone(IStream *iface, IStream **ppstm)
552 ok(0, "unexpected call\n");
556 static const IStreamVtbl StreamVtbl = {
557 Stream_QueryInterface,
573 static IStream Stream = { &StreamVtbl };
575 static HRESULT WINAPI ProtocolSink_QueryInterface(IInternetProtocolSink *iface, REFIID riid, void **ppv)
577 return QueryInterface(riid, ppv);
580 static ULONG WINAPI ProtocolSink_AddRef(IInternetProtocolSink *iface)
585 static ULONG WINAPI ProtocolSink_Release(IInternetProtocolSink *iface)
590 static void call_continue(PROTOCOLDATA *protocol_data)
594 if(state == STATE_CONNECTING) {
595 if(tested_protocol == HTTP_TEST || tested_protocol == HTTPS_TEST)
596 CLEAR_CALLED(ReportProgress_COOKIE_SENT);
597 if(tested_protocol == HTTP_TEST || tested_protocol == HTTPS_TEST || tested_protocol == FTP_TEST) {
599 CLEAR_CALLED(ReportProgress_FINDINGRESOURCE);
600 CLEAR_CALLED(ReportProgress_CONNECTING);
601 CLEAR_CALLED(ReportProgress_PROXYDETECTING);
602 }else if(test_redirect) {
603 if (! proxy_active())
604 CHECK_CALLED(ReportProgress_FINDINGRESOURCE);
606 CLEAR_CALLED(ReportProgress_FINDINGRESOURCE);
608 CHECK_NOT_CALLED(ReportProgress_FINDINGRESOURCE);
609 /* IE7 does call this */
610 CLEAR_CALLED(ReportProgress_CONNECTING);
613 if(tested_protocol == FTP_TEST)
614 todo_wine CHECK_CALLED(ReportProgress_SENDINGREQUEST);
615 else if (tested_protocol != HTTPS_TEST)
616 CHECK_CALLED(ReportProgress_SENDINGREQUEST);
618 CHECK_CALLED(ReportProgress_REDIRECTING);
619 state = test_async_req ? STATE_SENDINGREQUEST : STATE_STARTDOWNLOADING;
623 case STATE_SENDINGREQUEST:
624 SET_EXPECT(Stream_Read);
625 SET_EXPECT(ReportProgress_SENDINGREQUEST);
627 case STATE_STARTDOWNLOADING:
628 if(tested_protocol == HTTP_TEST || tested_protocol == HTTPS_TEST) {
629 SET_EXPECT(OnResponse);
630 if(tested_protocol == HTTPS_TEST || test_redirect)
631 SET_EXPECT(ReportProgress_ACCEPTRANGES);
632 SET_EXPECT(ReportProgress_MIMETYPEAVAILABLE);
633 if(bindf & BINDF_NEEDFILE)
634 SET_EXPECT(ReportProgress_CACHEFILENAMEAVAILABLE);
640 if(state != STATE_SENDINGREQUEST)
641 SET_EXPECT(ReportData);
642 hres = IInternetProtocol_Continue(async_protocol, protocol_data);
643 ok(hres == S_OK, "Continue failed: %08x\n", hres);
644 if(tested_protocol == FTP_TEST || security_problem)
645 CLEAR_CALLED(ReportData);
646 else if(state != STATE_SENDINGREQUEST)
647 CHECK_CALLED(ReportData);
650 case STATE_SENDINGREQUEST:
651 CHECK_CALLED(Stream_Read);
652 CHECK_CALLED(ReportProgress_SENDINGREQUEST);
653 state = STATE_STARTDOWNLOADING;
655 case STATE_STARTDOWNLOADING:
656 if (! security_problem)
658 state = STATE_DOWNLOADING;
659 if(tested_protocol == HTTP_TEST || tested_protocol == HTTPS_TEST) {
660 CHECK_CALLED(OnResponse);
661 if(tested_protocol == HTTPS_TEST)
662 CHECK_CALLED(ReportProgress_ACCEPTRANGES);
663 else if(test_redirect)
664 CLEAR_CALLED(ReportProgress_ACCEPTRANGES);
665 CHECK_CALLED(ReportProgress_MIMETYPEAVAILABLE);
666 if(bindf & BINDF_NEEDFILE)
667 CHECK_CALLED(ReportProgress_CACHEFILENAMEAVAILABLE);
672 security_problem = FALSE;
673 SET_EXPECT(ReportProgress_CONNECTING);
680 static HRESULT WINAPI ProtocolSink_Switch(IInternetProtocolSink *iface, PROTOCOLDATA *pProtocolData)
682 if(tested_protocol == FTP_TEST)
683 CHECK_EXPECT2(Switch);
685 CHECK_EXPECT(Switch);
687 ok(pProtocolData != NULL, "pProtocolData == NULL\n");
689 ok(pProtocolData != &protocoldata, "pProtocolData == &protocoldata\n");
690 ok(pProtocolData->grfFlags == protocoldata.grfFlags, "grfFlags wrong %x/%x\n",
691 pProtocolData->grfFlags, protocoldata.grfFlags );
692 ok(pProtocolData->dwState == protocoldata.dwState, "dwState wrong %x/%x\n",
693 pProtocolData->dwState, protocoldata.dwState );
694 ok(pProtocolData->pData == protocoldata.pData, "pData wrong %p/%p\n",
695 pProtocolData->pData, protocoldata.pData );
696 ok(pProtocolData->cbData == protocoldata.cbData, "cbData wrong %x/%x\n",
697 pProtocolData->cbData, protocoldata.cbData );
700 pdata = pProtocolData;
703 SetEvent(event_complete);
704 WaitForSingleObject(event_complete2, INFINITE);
707 continue_protdata = *pProtocolData;
708 SetEvent(event_continue);
709 WaitForSingleObject(event_continue_done, INFINITE);
711 call_continue(pProtocolData);
712 SetEvent(event_complete);
718 static HRESULT WINAPI ProtocolSink_ReportProgress(IInternetProtocolSink *iface, ULONG ulStatusCode,
719 LPCWSTR szStatusText)
721 static const WCHAR null_guid[] = {'{','0','0','0','0','0','0','0','0','-','0','0','0','0','-',
722 '0','0','0','0','-','0','0','0','0','-','0','0','0','0','0','0','0','0','0','0','0','0','}',0};
723 static const WCHAR text_plain[] = {'t','e','x','t','/','p','l','a','i','n',0};
725 switch(ulStatusCode) {
726 case BINDSTATUS_MIMETYPEAVAILABLE:
727 CHECK_EXPECT(ReportProgress_MIMETYPEAVAILABLE);
728 if(tested_protocol != FILE_TEST && !mimefilter_test && (pi & PI_MIMEVERIFICATION)) {
729 if(!short_read || !direct_read)
730 CHECK_CALLED(Read); /* set in Continue */
732 CHECK_CALLED(Read2); /* set in Read */
734 ok(szStatusText != NULL, "szStatusText == NULL\n");
736 if(tested_protocol == BIND_TEST)
737 ok(szStatusText == expect_wsz, "unexpected szStatusText\n");
738 else if (http_post_test)
739 ok(lstrlenW(text_plain) <= lstrlenW(szStatusText) &&
740 !memcmp(szStatusText, text_plain, lstrlenW(text_plain)*sizeof(WCHAR)),
741 "szStatusText != text/plain\n");
742 else if(!mimefilter_test)
743 ok(lstrlenW(text_htmlW) <= lstrlenW(szStatusText) &&
744 !memcmp(szStatusText, text_htmlW, lstrlenW(text_htmlW)*sizeof(WCHAR)),
745 "szStatusText != text/html\n");
748 case BINDSTATUS_DIRECTBIND:
749 CHECK_EXPECT2(ReportProgress_DIRECTBIND);
750 ok(szStatusText == NULL, "szStatusText != NULL\n");
752 case BINDSTATUS_RAWMIMETYPE:
753 CHECK_EXPECT2(ReportProgress_RAWMIMETYPE);
754 ok(szStatusText != NULL, "szStatusText == NULL\n");
756 ok(lstrlenW(szStatusText) < lstrlenW(text_htmlW) ||
757 !memcmp(szStatusText, text_htmlW, lstrlenW(text_htmlW)*sizeof(WCHAR)),
758 "szStatusText != text/html\n");
760 case BINDSTATUS_CACHEFILENAMEAVAILABLE:
761 CHECK_EXPECT(ReportProgress_CACHEFILENAMEAVAILABLE);
762 ok(szStatusText != NULL, "szStatusText == NULL\n");
765 ok(!strcmp_ww(szStatusText, expect_wsz), "unexpected szStatusText\n");
766 else if(tested_protocol == FILE_TEST)
767 ok(!strcmp_ww(szStatusText, file_name), "szStatusText = %s\n", wine_dbgstr_w(szStatusText));
769 ok(szStatusText != NULL, "szStatusText == NULL\n");
772 case BINDSTATUS_FINDINGRESOURCE:
773 CHECK_EXPECT2(ReportProgress_FINDINGRESOURCE);
774 ok(szStatusText != NULL, "szStatusText == NULL\n");
776 case BINDSTATUS_CONNECTING:
777 CHECK_EXPECT2(ReportProgress_CONNECTING);
778 ok(szStatusText != NULL, "szStatusText == NULL\n");
780 case BINDSTATUS_SENDINGREQUEST:
781 CHECK_EXPECT2(ReportProgress_SENDINGREQUEST);
782 if(tested_protocol == FILE_TEST) {
783 ok(szStatusText != NULL, "szStatusText == NULL\n");
785 ok(!*szStatusText, "wrong szStatusText\n");
788 case BINDSTATUS_VERIFIEDMIMETYPEAVAILABLE:
789 CHECK_EXPECT(ReportProgress_VERIFIEDMIMETYPEAVAILABLE);
790 ok(szStatusText != NULL, "szStatusText == NULL\n");
792 ok(!strcmp_ww(szStatusText, text_htmlW), "szStatusText != text/html\n");
794 case BINDSTATUS_PROTOCOLCLASSID:
795 CHECK_EXPECT(ReportProgress_PROTOCOLCLASSID);
796 ok(szStatusText != NULL, "szStatusText == NULL\n");
797 ok(!strcmp_ww(szStatusText, null_guid), "unexpected classid %s\n", wine_dbgstr_w(szStatusText));
799 case BINDSTATUS_COOKIE_SENT:
800 CHECK_EXPECT(ReportProgress_COOKIE_SENT);
801 ok(szStatusText == NULL, "szStatusText != NULL\n");
803 case BINDSTATUS_REDIRECTING:
804 CHECK_EXPECT(ReportProgress_REDIRECTING);
806 ok(!strcmp_wa(szStatusText, "http://test.winehq.org/hello.html"), "szStatusText = %s\n", wine_dbgstr_w(szStatusText));
808 ok(szStatusText == NULL, "szStatusText = %s\n", wine_dbgstr_w(szStatusText));
810 case BINDSTATUS_ENCODING:
811 CHECK_EXPECT(ReportProgress_ENCODING);
812 ok(!strcmp_wa(szStatusText, "gzip"), "szStatusText = %s\n", wine_dbgstr_w(szStatusText));
814 case BINDSTATUS_ACCEPTRANGES:
815 CHECK_EXPECT(ReportProgress_ACCEPTRANGES);
816 ok(!szStatusText, "szStatusText = %s\n", wine_dbgstr_w(szStatusText));
818 case BINDSTATUS_PROXYDETECTING:
819 CHECK_EXPECT(ReportProgress_PROXYDETECTING);
820 SET_EXPECT(ReportProgress_CONNECTING);
821 ok(!szStatusText, "szStatusText = %s\n", wine_dbgstr_w(szStatusText));
823 case BINDSTATUS_LOADINGMIMEHANDLER:
824 CHECK_EXPECT(ReportProgress_LOADINGMIMEHANDLER);
825 ok(!szStatusText, "szStatusText = %s\n", wine_dbgstr_w(szStatusText));
827 case BINDSTATUS_DECODING:
828 CHECK_EXPECT(ReportProgress_DECODING);
829 ok(!strcmp_ww(szStatusText, gzipW), "szStatusText = %s\n", wine_dbgstr_w(szStatusText));
832 ok(0, "Unexpected status %d\n", ulStatusCode);
838 static HRESULT WINAPI ProtocolSink_ReportData(IInternetProtocolSink *iface, DWORD grfBSCF,
839 ULONG ulProgress, ULONG ulProgressMax)
843 static int rec_depth;
846 if(!mimefilter_test && tested_protocol == FILE_TEST) {
847 CHECK_EXPECT2(ReportData);
849 ok(ulProgress == ulProgressMax, "ulProgress (%d) != ulProgressMax (%d)\n",
850 ulProgress, ulProgressMax);
851 ok(ulProgressMax == 13, "ulProgressMax=%d, expected 13\n", ulProgressMax);
852 /* BSCF_SKIPDRAINDATAFORFILEURLS added in IE8 */
853 ok((grfBSCF == (BSCF_FIRSTDATANOTIFICATION | BSCF_LASTDATANOTIFICATION)) ||
854 (grfBSCF == (BSCF_FIRSTDATANOTIFICATION | BSCF_LASTDATANOTIFICATION | BSCF_SKIPDRAINDATAFORFILEURLS)),
855 "grcfBSCF = %08x\n", grfBSCF);
856 }else if(direct_read) {
860 if(!read_report_data && rec_depth == 1) {
861 BOOL reported_all_data = called_ReportData2;
863 CHECK_EXPECT2(ReportData);
866 ok(grfBSCF == (BSCF_FIRSTDATANOTIFICATION|BSCF_LASTDATANOTIFICATION|BSCF_DATAFULLYAVAILABLE)
867 || grfBSCF == BSCF_FIRSTDATANOTIFICATION, /* < IE8 */
868 "grcfBSCF = %08x\n", grfBSCF);
869 CHECK_CALLED(Read); /* Set in Continue */
870 first_data_notif = FALSE;
871 }else if(first_data_notif) {
872 ok(grfBSCF == BSCF_FIRSTDATANOTIFICATION, "grcfBSCF = %08x\n", grfBSCF);
873 first_data_notif = FALSE;
874 }else if(reported_all_data) {
875 ok(grfBSCF == (BSCF_LASTDATANOTIFICATION|BSCF_INTERMEDIATEDATANOTIFICATION),
876 "grcfBSCF = %08x\n", grfBSCF);
877 }else if(!direct_read) {
878 ok(grfBSCF == BSCF_INTERMEDIATEDATANOTIFICATION, "grcfBSCF = %08x\n", grfBSCF);
886 SET_EXPECT(ReportData2);
887 SET_EXPECT(ReportResult);
890 hres = IInternetProtocol_Read(binding_test ? binding_protocol : async_protocol, expect_pv = buf, sizeof(buf), &read);
891 ok(hres == E_PENDING || hres == S_FALSE || hres == S_OK, "Read failed: %08x\n", hres);
893 ok(read, "read == 0\n");
894 if(reported_all_data)
895 ok(hres == S_FALSE, "Read failed: %08x, expected S_FALSE\n", hres);
896 if(!emulate_prot && hres != E_PENDING)
897 CHECK_NOT_CALLED(Switch); /* otherwise checked in wait_for_switch loop */
900 if(!reported_all_data && called_ReportData2) {
902 CHECK_CALLED(ReportData2);
903 CHECK_CALLED(ReportResult);
904 ok(hres == S_OK, "Read failed: %08x\n", hres);
905 reported_all_data = TRUE;
908 CHECK_NOT_CALLED(ReportData2);
909 CHECK_NOT_CALLED(ReportResult);
911 }while(hres == S_OK);
913 wait_for_switch = FALSE;
915 CHECK_EXPECT(ReportData2);
917 ok(grfBSCF & BSCF_LASTDATANOTIFICATION, "grfBSCF = %08x\n", grfBSCF);
922 hres = IInternetProtocol_Read(binding_test ? binding_protocol : async_protocol, expect_pv = buf, sizeof(buf), &read);
925 ok(hres == S_FALSE, "Read returned: %08x, expected E_FALSE\n", hres);
926 ok(!read, "read = %d\n", read);
928 }else if(!binding_test && (tested_protocol == HTTP_TEST || tested_protocol == HTTPS_TEST
929 || tested_protocol == FTP_TEST)) {
930 if(!(grfBSCF & BSCF_LASTDATANOTIFICATION) || (grfBSCF & BSCF_DATAFULLYAVAILABLE))
931 CHECK_EXPECT(ReportData);
932 else if (http_post_test)
933 ok(ulProgress == 13, "Read %u bytes instead of 13\n", ulProgress);
935 ok(ulProgress, "ulProgress == 0\n");
937 if(first_data_notif) {
938 ok(grfBSCF == BSCF_FIRSTDATANOTIFICATION
939 || grfBSCF == (BSCF_LASTDATANOTIFICATION|BSCF_DATAFULLYAVAILABLE),
940 "grcfBSCF = %08x\n", grfBSCF);
941 first_data_notif = FALSE;
943 ok(grfBSCF == BSCF_INTERMEDIATEDATANOTIFICATION
944 || grfBSCF == (BSCF_LASTDATANOTIFICATION|BSCF_INTERMEDIATEDATANOTIFICATION)
945 || broken(grfBSCF == (BSCF_FIRSTDATANOTIFICATION|BSCF_LASTDATANOTIFICATION)),
946 "grcfBSCF = %08x\n", grfBSCF);
949 if(!(bindf & BINDF_FROMURLMON) &&
950 !(grfBSCF & BSCF_LASTDATANOTIFICATION)) {
951 if(state == STATE_CONNECTING) {
952 state = STATE_DOWNLOADING;
954 CHECK_CALLED(ReportProgress_FINDINGRESOURCE);
955 CHECK_CALLED(ReportProgress_CONNECTING);
957 CHECK_NOT_CALLED(ReportProgress_FINDINGRESOURCE);
958 CHECK_NOT_CALLED(ReportProgress_CONNECTING);
960 CHECK_CALLED(ReportProgress_SENDINGREQUEST);
961 CHECK_CALLED(OnResponse);
962 CHECK_CALLED(ReportProgress_RAWMIMETYPE);
964 SetEvent(event_complete);
966 }else if(!read_report_data) {
971 CHECK_EXPECT(ReportData);
973 if(tested_protocol != BIND_TEST) {
976 SET_EXPECT(MimeFilter_Read);
977 else if(rec_depth > 1)
981 hres = IInternetProtocol_Read(binding_protocol, expect_pv=buf, sizeof(buf), &read);
983 CHECK_CALLED(MimeFilter_Read);
984 else if(rec_depth > 1)
988 }while(hres == S_OK);
996 static HRESULT WINAPI ProtocolSink_ReportResult(IInternetProtocolSink *iface, HRESULT hrResult,
997 DWORD dwError, LPCWSTR szResult)
999 CHECK_EXPECT(ReportResult);
1001 if(tested_protocol == FTP_TEST)
1002 ok(hrResult == E_PENDING || hrResult == S_OK, "hrResult = %08x, expected E_PENDING or S_OK\n", hrResult);
1004 ok(hrResult == expect_hrResult, "hrResult = %08x, expected: %08x\n",
1005 hrResult, expect_hrResult);
1006 if(SUCCEEDED(hrResult) || tested_protocol == FTP_TEST || test_abort)
1007 ok(dwError == ERROR_SUCCESS, "dwError = %d, expected ERROR_SUCCESS\n", dwError);
1009 ok(dwError != ERROR_SUCCESS ||
1010 broken(tested_protocol == MK_TEST), /* Win9x, WinME and NT4 */
1011 "dwError == ERROR_SUCCESS\n");
1012 ok(!szResult, "szResult != NULL\n");
1015 SET_EXPECT(ReportData); /* checked after main loop */
1020 static IInternetProtocolSinkVtbl protocol_sink_vtbl = {
1021 ProtocolSink_QueryInterface,
1022 ProtocolSink_AddRef,
1023 ProtocolSink_Release,
1024 ProtocolSink_Switch,
1025 ProtocolSink_ReportProgress,
1026 ProtocolSink_ReportData,
1027 ProtocolSink_ReportResult
1030 static IInternetProtocolSink protocol_sink = { &protocol_sink_vtbl };
1032 static HRESULT WINAPI MimeProtocolSink_QueryInterface(IInternetProtocolSink *iface, REFIID riid, void **ppv)
1034 ok(0, "unexpected call\n");
1038 static ULONG WINAPI MimeProtocolSink_AddRef(IInternetProtocolSink *iface)
1043 static ULONG WINAPI MimeProtocolSink_Release(IInternetProtocolSink *iface)
1048 static HRESULT WINAPI MimeProtocolSink_Switch(IInternetProtocolSink *iface, PROTOCOLDATA *pProtocolData)
1052 CHECK_EXPECT(MimeFilter_Switch);
1055 hres = IInternetProtocolSink_Switch(filtered_sink, pProtocolData);
1056 ok(hres == S_OK, "Switch failed: %08x\n", hres);
1057 CHECK_CALLED(Switch);
1062 static HRESULT WINAPI MimeProtocolSink_ReportProgress(IInternetProtocolSink *iface, ULONG ulStatusCode,
1063 LPCWSTR szStatusText)
1065 CHECK_EXPECT(MimeFilter_ReportProgress);
1069 static HRESULT WINAPI MimeProtocolSink_ReportData(IInternetProtocolSink *iface, DWORD grfBSCF,
1070 ULONG ulProgress, ULONG ulProgressMax)
1076 CHECK_EXPECT(MimeFilter_ReportData);
1080 hres = IInternetProtocol_Read(filtered_protocol, buf, sizeof(buf), &read);
1081 if(tested_protocol == HTTP_TEST)
1082 ok(hres == S_OK || hres == E_PENDING || hres == S_FALSE, "Read failed: %08x\n", hres);
1084 ok(hres == S_OK, "Read failed: %08x\n", hres);
1087 SET_EXPECT(ReportProgress_MIMETYPEAVAILABLE);
1088 hres = IInternetProtocolSink_ReportProgress(filtered_sink, BINDSTATUS_VERIFIEDMIMETYPEAVAILABLE, text_htmlW);
1089 ok(hres == S_OK, "ReportProgress failed: %08x\n", hres);
1090 CHECK_CALLED(ReportProgress_MIMETYPEAVAILABLE);
1092 /* FIXME: test BINDSTATUS_CACHEFILENAMEAVAILABLE */
1095 if(!read_report_data)
1096 SET_EXPECT(ReportData);
1097 hres = IInternetProtocolSink_ReportData(filtered_sink, grfBSCF, ulProgress, ulProgressMax);
1098 ok(hres == S_OK, "ReportData failed: %08x\n", hres);
1099 if(!read_report_data)
1100 CHECK_CALLED(ReportData);
1108 static HRESULT WINAPI MimeProtocolSink_ReportResult(IInternetProtocolSink *iface, HRESULT hrResult,
1109 DWORD dwError, LPCWSTR szResult)
1113 CHECK_EXPECT(MimeFilter_ReportResult);
1115 ok(hrResult == S_OK, "hrResult = %08x\n", hrResult);
1116 ok(dwError == ERROR_SUCCESS, "dwError = %u\n", dwError);
1117 ok(!szResult, "szResult = %s\n", wine_dbgstr_w(szResult));
1119 SET_EXPECT(ReportResult);
1120 hres = IInternetProtocolSink_ReportResult(filtered_sink, hrResult, dwError, szResult);
1121 ok(SUCCEEDED(hres), "ReportResult failed: %08x\n", hres);
1122 CHECK_CALLED(ReportResult);
1127 static IInternetProtocolSinkVtbl mime_protocol_sink_vtbl = {
1128 MimeProtocolSink_QueryInterface,
1129 MimeProtocolSink_AddRef,
1130 MimeProtocolSink_Release,
1131 MimeProtocolSink_Switch,
1132 MimeProtocolSink_ReportProgress,
1133 MimeProtocolSink_ReportData,
1134 MimeProtocolSink_ReportResult
1137 static IInternetProtocolSink mime_protocol_sink = { &mime_protocol_sink_vtbl };
1139 static HRESULT QueryInterface(REFIID riid, void **ppv)
1141 static const IID IID_undocumented = {0x58DFC7D0,0x5381,0x43E5,{0x9D,0x72,0x4C,0xDD,0xE4,0xCB,0x0F,0x1A}};
1145 if(IsEqualGUID(&IID_IUnknown, riid) || IsEqualGUID(&IID_IInternetProtocolSink, riid))
1146 *ppv = &protocol_sink;
1147 if(IsEqualGUID(&IID_IServiceProvider, riid))
1148 *ppv = &service_provider;
1149 if(IsEqualGUID(&IID_IUriContainer, riid))
1150 return E_NOINTERFACE; /* TODO */
1152 /* NOTE: IE8 queries for undocumented {58DFC7D0-5381-43E5-9D72-4CDDE4CB0F1A} interface. */
1153 if(IsEqualGUID(&IID_undocumented, riid))
1154 return E_NOINTERFACE;
1159 ok(0, "unexpected call %s\n", debugstr_guid(riid));
1160 return E_NOINTERFACE;
1163 static HRESULT WINAPI BindInfo_QueryInterface(IInternetBindInfo *iface, REFIID riid, void **ppv)
1165 if(IsEqualGUID(&IID_IUnknown, riid) || IsEqualGUID(&IID_IInternetBindInfo, riid)) {
1169 return E_NOINTERFACE;
1172 static ULONG WINAPI BindInfo_AddRef(IInternetBindInfo *iface)
1177 static ULONG WINAPI BindInfo_Release(IInternetBindInfo *iface)
1182 static HRESULT WINAPI BindInfo_GetBindInfo(IInternetBindInfo *iface, DWORD *grfBINDF, BINDINFO *pbindinfo)
1186 CHECK_EXPECT(GetBindInfo);
1188 ok(grfBINDF != NULL, "grfBINDF == NULL\n");
1189 ok(pbindinfo != NULL, "pbindinfo == NULL\n");
1190 ok(pbindinfo->cbSize == sizeof(BINDINFO), "wrong size of pbindinfo: %d\n", pbindinfo->cbSize);
1194 *grfBINDF |= BINDF_FROMURLMON;
1195 cbSize = pbindinfo->cbSize;
1196 memset(pbindinfo, 0, cbSize);
1197 pbindinfo->cbSize = cbSize;
1201 pbindinfo->cbstgmedData = sizeof(post_data)-1;
1202 pbindinfo->dwBindVerb = BINDVERB_POST;
1203 pbindinfo->stgmedData.tymed = http_post_test;
1205 if(http_post_test == TYMED_HGLOBAL) {
1208 /* Must be GMEM_FIXED, GMEM_MOVABLE does not work properly */
1209 data = GlobalAlloc(GPTR, sizeof(post_data));
1210 memcpy(data, post_data, sizeof(post_data));
1211 U(pbindinfo->stgmedData).hGlobal = data;
1213 IStream *post_stream;
1218 /* Must be GMEM_FIXED, GMEM_MOVABLE does not work properly */
1219 data = GlobalAlloc(GPTR, sizeof(post_data));
1220 memcpy(data, post_data, sizeof(post_data));
1221 U(pbindinfo->stgmedData).hGlobal = data;
1223 hres = CreateStreamOnHGlobal(data, FALSE, &post_stream);
1224 ok(hres == S_OK, "CreateStreamOnHGlobal failed: %08x\n", hres);
1226 U(pbindinfo->stgmedData).pstm =post_stream;/* &Stream; */
1228 U(pbindinfo->stgmedData).pstm = &Stream;
1235 static HRESULT WINAPI BindInfo_GetBindString(IInternetBindInfo *iface, ULONG ulStringType,
1236 LPOLESTR *ppwzStr, ULONG cEl, ULONG *pcElFetched)
1238 ok(ppwzStr != NULL, "ppwzStr == NULL\n");
1239 ok(pcElFetched != NULL, "pcElFetched == NULL\n");
1241 switch(ulStringType) {
1242 case BINDSTRING_ACCEPT_MIMES:
1243 CHECK_EXPECT(GetBindString_ACCEPT_MIMES);
1244 ok(cEl == 256, "cEl=%d, expected 256\n", cEl);
1246 ok(*pcElFetched == 256, "*pcElFetched=%d, expected 256\n", *pcElFetched);
1250 *ppwzStr = CoTaskMemAlloc(sizeof(acc_mimeW));
1251 memcpy(*ppwzStr, acc_mimeW, sizeof(acc_mimeW));
1254 case BINDSTRING_USER_AGENT:
1255 CHECK_EXPECT(GetBindString_USER_AGENT);
1256 ok(cEl == 1, "cEl=%d, expected 1\n", cEl);
1258 ok(*pcElFetched == 0, "*pcElFetch=%d, expectd 0\n", *pcElFetched);
1262 *ppwzStr = CoTaskMemAlloc(sizeof(user_agentW));
1263 memcpy(*ppwzStr, user_agentW, sizeof(user_agentW));
1266 case BINDSTRING_POST_COOKIE:
1267 CHECK_EXPECT(GetBindString_POST_COOKIE);
1268 ok(cEl == 1, "cEl=%d, expected 1\n", cEl);
1270 ok(*pcElFetched == 0, "*pcElFetch=%d, expectd 0\n", *pcElFetched);
1272 case BINDSTRING_URL: {
1275 CHECK_EXPECT(GetBindString_URL);
1276 ok(cEl == 1, "cEl=%d, expected 1\n", cEl);
1277 ok(*pcElFetched == 0, "*pcElFetch=%d, expectd 0\n", *pcElFetched);
1280 size = (lstrlenW(binding_urls[tested_protocol])+1)*sizeof(WCHAR);
1281 *ppwzStr = CoTaskMemAlloc(size);
1282 memcpy(*ppwzStr, binding_urls[tested_protocol], size);
1286 ok(0, "unexpected call\n");
1292 static IInternetBindInfoVtbl bind_info_vtbl = {
1293 BindInfo_QueryInterface,
1296 BindInfo_GetBindInfo,
1297 BindInfo_GetBindString
1300 static IInternetBindInfo bind_info = { &bind_info_vtbl };
1302 static HRESULT WINAPI InternetPriority_QueryInterface(IInternetPriority *iface,
1303 REFIID riid, void **ppv)
1305 ok(0, "unexpected call\n");
1306 return E_NOINTERFACE;
1309 static ULONG WINAPI InternetPriority_AddRef(IInternetPriority *iface)
1314 static ULONG WINAPI InternetPriority_Release(IInternetPriority *iface)
1319 static HRESULT WINAPI InternetPriority_SetPriority(IInternetPriority *iface, LONG nPriority)
1321 CHECK_EXPECT(SetPriority);
1322 ok(nPriority == ex_priority, "nPriority=%d\n", nPriority);
1326 static HRESULT WINAPI InternetPriority_GetPriority(IInternetPriority *iface, LONG *pnPriority)
1328 ok(0, "unexpected call\n");
1333 static const IInternetPriorityVtbl InternetPriorityVtbl = {
1334 InternetPriority_QueryInterface,
1335 InternetPriority_AddRef,
1336 InternetPriority_Release,
1337 InternetPriority_SetPriority,
1338 InternetPriority_GetPriority
1341 static IInternetPriority InternetPriority = { &InternetPriorityVtbl };
1343 static ULONG WINAPI Protocol_AddRef(IInternetProtocolEx *iface)
1348 static ULONG WINAPI Protocol_Release(IInternetProtocolEx *iface)
1353 static HRESULT WINAPI Protocol_Abort(IInternetProtocolEx *iface, HRESULT hrReason,
1358 CHECK_EXPECT(Abort);
1360 SET_EXPECT(ReportResult);
1361 hres = IInternetProtocolSink_ReportResult(binding_sink, S_OK, ERROR_SUCCESS, NULL);
1362 ok(hres == S_OK, "ReportResult failed: %08x\n", hres);
1363 CHECK_CALLED(ReportResult);
1368 static HRESULT WINAPI Protocol_Suspend(IInternetProtocolEx *iface)
1370 ok(0, "unexpected call\n");
1374 static HRESULT WINAPI Protocol_Resume(IInternetProtocolEx *iface)
1376 ok(0, "unexpected call\n");
1380 static HRESULT WINAPI Protocol_Seek(IInternetProtocolEx *iface,
1381 LARGE_INTEGER dlibMove, DWORD dwOrigin, ULARGE_INTEGER *plibNewPosition)
1383 ok(0, "unexpected call\n");
1387 static HRESULT WINAPI ProtocolEmul_QueryInterface(IInternetProtocolEx *iface, REFIID riid, void **ppv)
1389 if(IsEqualGUID(&IID_IUnknown, riid) || IsEqualGUID(&IID_IInternetProtocol, riid)) {
1394 if(IsEqualGUID(&IID_IInternetProtocolEx, riid)) {
1400 return E_NOINTERFACE;
1403 if(IsEqualGUID(&IID_IInternetPriority, riid)) {
1404 *ppv = &InternetPriority;
1408 if(IsEqualGUID(&IID_IWinInetInfo, riid)) {
1409 CHECK_EXPECT(QueryInterface_IWinInetInfo);
1411 return E_NOINTERFACE;
1414 if(IsEqualGUID(&IID_IWinInetHttpInfo, riid)) {
1415 CHECK_EXPECT(QueryInterface_IWinInetHttpInfo);
1417 return E_NOINTERFACE;
1420 ok(0, "unexpected riid %s\n", debugstr_guid(riid));
1422 return E_NOINTERFACE;
1425 static DWORD WINAPI thread_proc(PVOID arg)
1429 memset(&protocoldata, -1, sizeof(protocoldata));
1433 SET_EXPECT(ReportProgress_FINDINGRESOURCE);
1434 hres = IInternetProtocolSink_ReportProgress(binding_sink,
1435 BINDSTATUS_FINDINGRESOURCE, hostW);
1436 CHECK_CALLED(ReportProgress_FINDINGRESOURCE);
1437 ok(hres == S_OK, "ReportProgress failed: %08x\n", hres);
1439 SET_EXPECT(ReportProgress_CONNECTING);
1440 hres = IInternetProtocolSink_ReportProgress(binding_sink,
1441 BINDSTATUS_CONNECTING, winehq_ipW);
1442 CHECK_CALLED(ReportProgress_CONNECTING);
1443 ok(hres == S_OK, "ReportProgress failed: %08x\n", hres);
1445 SET_EXPECT(ReportProgress_SENDINGREQUEST);
1446 hres = IInternetProtocolSink_ReportProgress(binding_sink,
1447 BINDSTATUS_SENDINGREQUEST, NULL);
1448 CHECK_CALLED(ReportProgress_SENDINGREQUEST);
1449 ok(hres == S_OK, "ReportProgress failed: %08x\n", hres);
1453 hres = IInternetProtocolSink_Switch(binding_sink, &protocoldata);
1454 CHECK_CALLED(Switch);
1455 ok(hres == S_OK, "Switch failed: %08x\n", hres);
1460 SET_EXPECT(MimeFilter_Switch);
1463 hres = IInternetProtocolSink_Switch(binding_sink, &protocoldata);
1464 ok(hres == S_OK, "Switch failed: %08x\n", hres);
1466 CHECK_CALLED(MimeFilter_Switch);
1468 CHECK_CALLED(Switch);
1471 SetEvent(event_complete);
1477 SET_EXPECT(MimeFilter_Switch);
1480 hres = IInternetProtocolSink_Switch(binding_sink, &protocoldata);
1481 ok(hres == S_OK, "Switch failed: %08x\n", hres);
1483 CHECK_CALLED(MimeFilter_Switch);
1485 CHECK_CALLED(Switch);
1489 SET_EXPECT(MimeFilter_Switch);
1492 hres = IInternetProtocolSink_Switch(binding_sink, &protocoldata);
1493 ok(hres == S_OK, "Switch failed: %08x\n", hres);
1495 CHECK_CALLED(MimeFilter_Switch);
1497 CHECK_CALLED(Switch);
1500 SetEvent(event_complete);
1505 static void protocol_start(IInternetProtocolSink *pOIProtSink, IInternetBindInfo *pOIBindInfo, DWORD pi)
1507 BINDINFO bindinfo, exp_bindinfo;
1511 ok(pOIProtSink != NULL, "pOIProtSink == NULL\n");
1512 ok(pOIBindInfo != NULL, "pOIBindInfo == NULL\n");
1513 ok(pOIProtSink != &protocol_sink, "unexpected pOIProtSink\n");
1514 ok(pOIBindInfo != &bind_info, "unexpected pOIBindInfo\n");
1515 ok(!pi, "pi = %x\n", pi);
1518 ok(pOIProtSink == binding_sink, "pOIProtSink != binding_sink\n");
1520 memset(&bindinfo, 0, sizeof(bindinfo));
1521 bindinfo.cbSize = sizeof(bindinfo);
1522 memcpy(&exp_bindinfo, &bindinfo, sizeof(bindinfo));
1523 SET_EXPECT(GetBindInfo);
1524 hres = IInternetBindInfo_GetBindInfo(pOIBindInfo, &cbindf, &bindinfo);
1525 ok(hres == S_OK, "GetBindInfo failed: %08x\n", hres);
1526 CHECK_CALLED(GetBindInfo);
1527 ok(cbindf == (bindf|BINDF_FROMURLMON), "bindf = %x, expected %x\n",
1528 cbindf, (bindf|BINDF_FROMURLMON));
1529 ok(!memcmp(&exp_bindinfo, &bindinfo, sizeof(bindinfo)), "unexpected bindinfo\n");
1530 pReleaseBindInfo(&bindinfo);
1532 SET_EXPECT(ReportProgress_SENDINGREQUEST);
1533 hres = IInternetProtocolSink_ReportProgress(pOIProtSink, BINDSTATUS_SENDINGREQUEST, emptyW);
1534 ok(hres == S_OK, "ReportProgress(BINDSTATUS_SENDINGREQUEST) failed: %08x\n", hres);
1535 CHECK_CALLED(ReportProgress_SENDINGREQUEST);
1537 if(tested_protocol == HTTP_TEST || tested_protocol == HTTPS_TEST) {
1538 IServiceProvider *service_provider;
1539 IHttpNegotiate *http_negotiate;
1540 IHttpNegotiate2 *http_negotiate2;
1541 LPWSTR ua = (LPWSTR)0xdeadbeef, accept_mimes[256];
1542 LPWSTR additional_headers = NULL;
1544 DWORD fetched = 0, size = 100;
1547 SET_EXPECT(GetBindString_USER_AGENT);
1548 hres = IInternetBindInfo_GetBindString(pOIBindInfo, BINDSTRING_USER_AGENT,
1550 CHECK_CALLED(GetBindString_USER_AGENT);
1551 ok(hres == S_OK, "GetBindString(BINDSTRING_USER_AGETNT) failed: %08x\n", hres);
1552 ok(fetched == 1, "fetched = %d, expected 254\n", fetched);
1553 ok(ua != NULL, "ua = %p\n", ua);
1554 ok(!strcmp_ww(ua, user_agentW), "unexpected user agent %s\n", wine_dbgstr_w(ua));
1558 SET_EXPECT(GetBindString_ACCEPT_MIMES);
1559 hres = IInternetBindInfo_GetBindString(pOIBindInfo, BINDSTRING_ACCEPT_MIMES,
1560 accept_mimes, 256, &fetched);
1561 CHECK_CALLED(GetBindString_ACCEPT_MIMES);
1564 "GetBindString(BINDSTRING_ACCEPT_MIMES) failed: %08x\n", hres);
1565 ok(fetched == 1, "fetched = %d, expected 1\n", fetched);
1566 ok(!strcmp_ww(acc_mimeW, accept_mimes[0]), "unexpected mimes %s\n", wine_dbgstr_w(accept_mimes[0]));
1567 CoTaskMemFree(accept_mimes[0]);
1569 hres = IInternetBindInfo_QueryInterface(pOIBindInfo, &IID_IServiceProvider,
1570 (void**)&service_provider);
1571 ok(hres == S_OK, "QueryInterface failed: %08x\n", hres);
1573 SET_EXPECT(QueryService_HttpNegotiate);
1574 hres = IServiceProvider_QueryService(service_provider, &IID_IHttpNegotiate,
1575 &IID_IHttpNegotiate, (void**)&http_negotiate);
1576 CHECK_CALLED(QueryService_HttpNegotiate);
1577 ok(hres == S_OK, "QueryService failed: %08x\n", hres);
1579 SET_EXPECT(BeginningTransaction);
1580 hres = IHttpNegotiate_BeginningTransaction(http_negotiate, binding_urls[tested_protocol],
1581 NULL, 0, &additional_headers);
1582 CHECK_CALLED(BeginningTransaction);
1583 IHttpNegotiate_Release(http_negotiate);
1584 ok(hres == S_OK, "BeginningTransction failed: %08x\n", hres);
1585 ok(additional_headers == NULL, "additional_headers=%p\n", additional_headers);
1587 SET_EXPECT(QueryService_HttpNegotiate);
1588 hres = IServiceProvider_QueryService(service_provider, &IID_IHttpNegotiate2,
1589 &IID_IHttpNegotiate2, (void**)&http_negotiate2);
1590 CHECK_CALLED(QueryService_HttpNegotiate);
1591 ok(hres == S_OK, "QueryService failed: %08x\n", hres);
1594 SET_EXPECT(GetRootSecurityId);
1595 hres = IHttpNegotiate2_GetRootSecurityId(http_negotiate2, sec_id, &size, 0);
1596 CHECK_CALLED(GetRootSecurityId);
1597 IHttpNegotiate2_Release(http_negotiate2);
1598 ok(hres == E_FAIL, "GetRootSecurityId failed: %08x, expected E_FAIL\n", hres);
1599 ok(size == 13, "size=%d\n", size);
1601 IServiceProvider_Release(service_provider);
1603 CreateThread(NULL, 0, thread_proc, NULL, 0, &tid);
1607 SET_EXPECT(ReportProgress_CACHEFILENAMEAVAILABLE);
1608 hres = IInternetProtocolSink_ReportProgress(pOIProtSink,
1609 BINDSTATUS_CACHEFILENAMEAVAILABLE, expect_wsz = emptyW);
1610 ok(hres == S_OK, "ReportProgress(BINDSTATUS_CACHEFILENAMEAVAILABLE) failed: %08x\n", hres);
1611 CHECK_CALLED(ReportProgress_CACHEFILENAMEAVAILABLE);
1613 if(mimefilter_test) {
1614 SET_EXPECT(MimeFilter_CreateInstance);
1615 SET_EXPECT(MimeFilter_Start);
1616 SET_EXPECT(ReportProgress_LOADINGMIMEHANDLER);
1618 SET_EXPECT(ReportProgress_MIMETYPEAVAILABLE);
1619 hres = IInternetProtocolSink_ReportProgress(pOIProtSink, BINDSTATUS_VERIFIEDMIMETYPEAVAILABLE,
1620 mimefilter_test ? gzipW : (expect_wsz = text_htmlW));
1622 "ReportProgress(BINDSTATUS_VERIFIEDMIMETYPEAVAILABLE) failed: %08x\n", hres);
1623 if(mimefilter_test) {
1624 CHECK_CALLED(MimeFilter_CreateInstance);
1625 CHECK_CALLED(MimeFilter_Start);
1626 CHECK_CALLED(ReportProgress_LOADINGMIMEHANDLER);
1627 todo_wine CHECK_CALLED(ReportProgress_MIMETYPEAVAILABLE);
1629 CHECK_CALLED(ReportProgress_MIMETYPEAVAILABLE);
1633 SET_EXPECT(MimeFilter_ReportData);
1635 SET_EXPECT(ReportData);
1636 hres = IInternetProtocolSink_ReportData(pOIProtSink,
1637 BSCF_FIRSTDATANOTIFICATION | BSCF_LASTDATANOTIFICATION, 13, 13);
1638 ok(hres == S_OK, "ReportData failed: %08x\n", hres);
1640 CHECK_CALLED(MimeFilter_ReportData);
1642 CHECK_CALLED(ReportData);
1644 if(tested_protocol == BIND_TEST) {
1645 hres = IInternetProtocol_Terminate(binding_protocol, 0);
1646 ok(hres == E_FAIL, "Termiante failed: %08x\n", hres);
1650 SET_EXPECT(MimeFilter_ReportResult);
1652 SET_EXPECT(ReportResult);
1653 hres = IInternetProtocolSink_ReportResult(pOIProtSink, S_OK, 0, NULL);
1654 ok(hres == S_OK, "ReportResult failed: %08x\n", hres);
1656 CHECK_CALLED(MimeFilter_ReportResult);
1658 CHECK_CALLED(ReportResult);
1661 static HRESULT WINAPI ProtocolEmul_Start(IInternetProtocolEx *iface, LPCWSTR szUrl,
1662 IInternetProtocolSink *pOIProtSink, IInternetBindInfo *pOIBindInfo,
1663 DWORD grfPI, HANDLE_PTR dwReserved)
1665 CHECK_EXPECT(Start);
1667 ok(!dwReserved, "dwReserved = %lx\n", dwReserved);
1668 protocol_start(pOIProtSink, pOIBindInfo, grfPI);
1672 static HRESULT WINAPI ProtocolEmul_Continue(IInternetProtocolEx *iface,
1673 PROTOCOLDATA *pProtocolData)
1678 CHECK_EXPECT(Continue);
1680 ok(pProtocolData != NULL, "pProtocolData == NULL\n");
1681 if(!pProtocolData || tested_protocol == BIND_TEST)
1684 ok(pProtocolData != &protocoldata, "pProtocolData == &protocoldata\n");
1685 ok(pProtocolData->grfFlags == protocoldata.grfFlags, "grfFlags wrong %x/%x\n",
1686 pProtocolData->grfFlags, protocoldata.grfFlags );
1687 ok(pProtocolData->dwState == protocoldata.dwState, "dwState wrong %x/%x\n",
1688 pProtocolData->dwState, protocoldata.dwState );
1689 ok(pProtocolData->pData == protocoldata.pData, "pData wrong %p/%p\n",
1690 pProtocolData->pData, protocoldata.pData );
1691 ok(pProtocolData->cbData == protocoldata.cbData, "cbData wrong %x/%x\n",
1692 pProtocolData->cbData, protocoldata.cbData );
1695 switch(prot_state) {
1697 IServiceProvider *service_provider;
1698 IHttpNegotiate *http_negotiate;
1699 static WCHAR header[] = {'?',0};
1701 hres = IInternetProtocolSink_QueryInterface(binding_sink, &IID_IServiceProvider,
1702 (void**)&service_provider);
1703 ok(hres == S_OK, "Could not get IServiceProvicder\n");
1705 SET_EXPECT(QueryService_HttpNegotiate);
1706 hres = IServiceProvider_QueryService(service_provider, &IID_IHttpNegotiate,
1707 &IID_IHttpNegotiate, (void**)&http_negotiate);
1708 IServiceProvider_Release(service_provider);
1709 CHECK_CALLED(QueryService_HttpNegotiate);
1710 ok(hres == S_OK, "Could not get IHttpNegotiate\n");
1712 SET_EXPECT(OnResponse);
1713 hres = IHttpNegotiate_OnResponse(http_negotiate, 200, header, NULL, NULL);
1714 IHttpNegotiate_Release(http_negotiate);
1715 CHECK_CALLED(OnResponse);
1716 IHttpNegotiate_Release(http_negotiate);
1717 ok(hres == S_OK, "OnResponse failed: %08x\n", hres);
1719 if(mimefilter_test) {
1720 SET_EXPECT(MimeFilter_CreateInstance);
1721 SET_EXPECT(MimeFilter_Start);
1722 SET_EXPECT(ReportProgress_LOADINGMIMEHANDLER);
1723 }else if(!(pi & PI_MIMEVERIFICATION)) {
1724 SET_EXPECT(ReportProgress_MIMETYPEAVAILABLE);
1726 hres = IInternetProtocolSink_ReportProgress(binding_sink,
1727 BINDSTATUS_MIMETYPEAVAILABLE, mimefilter_test ? gzipW : text_htmlW);
1728 if(mimefilter_test) {
1729 CHECK_CALLED(MimeFilter_CreateInstance);
1730 CHECK_CALLED(MimeFilter_Start);
1731 CHECK_CALLED(ReportProgress_LOADINGMIMEHANDLER);
1732 }else if(!(pi & PI_MIMEVERIFICATION)) {
1733 CHECK_CALLED(ReportProgress_MIMETYPEAVAILABLE);
1736 "ReportProgress(BINDSTATUS_MIMETYPEAVAILABLE) failed: %08x\n", hres);
1738 bscf |= BSCF_FIRSTDATANOTIFICATION;
1743 bscf = BSCF_INTERMEDIATEDATANOTIFICATION;
1748 if(mimefilter_test) {
1749 SET_EXPECT(MimeFilter_ReportData);
1750 }else if(pi & PI_MIMEVERIFICATION) {
1752 SET_EXPECT(Read); /* checked in ReportData for short_read */
1754 if(!mimefilter_test)
1755 SET_EXPECT(Read); /* checked in BINDSTATUS_MIMETYPEAVAILABLE or ReportData */
1756 SET_EXPECT(ReportProgress_MIMETYPEAVAILABLE);
1759 SET_EXPECT(ReportData);
1761 SET_EXPECT(ReportData);
1764 hres = IInternetProtocolSink_ReportData(binding_sink, bscf, pr, 400);
1765 ok(hres == S_OK, "ReportData failed: %08x\n", hres);
1767 if(mimefilter_test) {
1768 SET_EXPECT(MimeFilter_ReportData);
1769 }else if(pi & PI_MIMEVERIFICATION) {
1770 if(!short_read && pr < 200)
1773 CHECK_CALLED(ReportProgress_MIMETYPEAVAILABLE);
1776 CHECK_CALLED(ReportData);
1785 static HRESULT WINAPI ProtocolEmul_Terminate(IInternetProtocolEx *iface, DWORD dwOptions)
1787 CHECK_EXPECT(Terminate);
1788 ok(!dwOptions, "dwOptions=%d\n", dwOptions);
1792 static HRESULT WINAPI ProtocolEmul_Read(IInternetProtocolEx *iface, void *pv,
1793 ULONG cb, ULONG *pcbRead)
1795 if(read_report_data)
1796 CHECK_EXPECT2(Read2);
1798 if(mimefilter_test || short_read) {
1799 if(!read_report_data)
1800 CHECK_EXPECT2(Read);
1801 }else if((pi & PI_MIMEVERIFICATION)) {
1802 if(!read_report_data)
1803 CHECK_EXPECT2(Read);
1805 if(prot_read < 300) {
1806 ok(pv != expect_pv, "pv == expect_pv\n");
1808 ok(cb == 2048-prot_read, "cb=%d\n", cb);
1810 ok(cb == 700, "cb=%d\n", cb);
1812 ok(expect_pv <= pv && (BYTE*)pv < (BYTE*)expect_pv + cb, "pv != expect_pv\n");
1815 if(!read_report_data)
1818 ok(pv == expect_pv, "pv != expect_pv\n");
1819 ok(cb == 1000, "cb=%d\n", cb);
1820 ok(!*pcbRead, "*pcbRead = %d\n", *pcbRead);
1822 ok(pcbRead != NULL, "pcbRead == NULL\n");
1824 if(prot_state == 3 || (short_read && prot_state != 4)) {
1829 SET_EXPECT(Read2); /* checked in BINDSTATUS_MIMETYPEAVAILABLE */
1830 SET_EXPECT(ReportProgress_MIMETYPEAVAILABLE);
1833 SET_EXPECT(MimeFilter_ReportData);
1834 else if(direct_read)
1835 SET_EXPECT(ReportData2);
1837 hres = IInternetProtocolSink_ReportData(binding_sink,
1838 BSCF_LASTDATANOTIFICATION|BSCF_INTERMEDIATEDATANOTIFICATION, 0, 0);
1840 ok(hres == S_OK, "ReportData failed: %08x\n", hres);
1842 CHECK_CALLED(ReportProgress_MIMETYPEAVAILABLE);
1844 CHECK_CALLED(MimeFilter_ReportData);
1845 else if(direct_read)
1846 CHECK_CALLED(ReportData2);
1849 SET_EXPECT(MimeFilter_ReportResult);
1851 SET_EXPECT(ReportResult);
1852 hres = IInternetProtocolSink_ReportResult(binding_sink, S_OK, ERROR_SUCCESS, NULL);
1853 ok(hres == S_OK, "ReportResult failed: %08x\n", hres);
1855 CHECK_CALLED(MimeFilter_ReportResult);
1857 CHECK_CALLED(ReportResult);
1859 memset(pv, 'x', 100);
1860 prot_read += *pcbRead = 100;
1862 }if(prot_state == 4) {
1867 if((async_read_pending = !async_read_pending)) {
1869 return tested_protocol == HTTP_TEST || tested_protocol == HTTPS_TEST ? E_PENDING : S_FALSE;
1872 memset(pv, 'x', 100);
1873 prot_read += *pcbRead = 100;
1877 static HRESULT WINAPI ProtocolEmul_LockRequest(IInternetProtocolEx *iface, DWORD dwOptions)
1879 CHECK_EXPECT(LockRequest);
1880 ok(dwOptions == 0, "dwOptions=%x\n", dwOptions);
1884 static HRESULT WINAPI ProtocolEmul_UnlockRequest(IInternetProtocolEx *iface)
1886 CHECK_EXPECT(UnlockRequest);
1890 static HRESULT WINAPI ProtocolEmul_StartEx(IInternetProtocolEx *iface, IUri *pUri,
1891 IInternetProtocolSink *pOIProtSink, IInternetBindInfo *pOIBindInfo,
1892 DWORD grfPI, HANDLE *dwReserved)
1894 CHECK_EXPECT(StartEx);
1895 ok(!dwReserved, "dwReserved = %p\n", dwReserved);
1896 protocol_start(pOIProtSink, pOIBindInfo, grfPI);
1900 static const IInternetProtocolExVtbl ProtocolVtbl = {
1901 ProtocolEmul_QueryInterface,
1905 ProtocolEmul_Continue,
1907 ProtocolEmul_Terminate,
1912 ProtocolEmul_LockRequest,
1913 ProtocolEmul_UnlockRequest,
1914 ProtocolEmul_StartEx
1917 static IInternetProtocolEx Protocol = { &ProtocolVtbl };
1919 static HRESULT WINAPI MimeProtocol_QueryInterface(IInternetProtocolEx *iface, REFIID riid, void **ppv)
1921 if(IsEqualGUID(&IID_IUnknown, riid) || IsEqualGUID(&IID_IInternetProtocol, riid)) {
1926 if(IsEqualGUID(&IID_IInternetProtocolSink, riid)) {
1927 *ppv = &mime_protocol_sink;
1931 ok(0, "unexpected riid %s\n", debugstr_guid(riid));
1933 return E_NOINTERFACE;
1936 static HRESULT WINAPI MimeProtocol_Start(IInternetProtocolEx *iface, LPCWSTR szUrl,
1937 IInternetProtocolSink *pOIProtSink, IInternetBindInfo *pOIBindInfo,
1938 DWORD grfPI, HANDLE_PTR dwReserved)
1940 PROTOCOLFILTERDATA *data;
1941 LPOLESTR url_str = NULL;
1947 CHECK_EXPECT(MimeFilter_Start);
1949 ok(!strcmp_ww(szUrl, gzipW), "wrong url %s\n", wine_dbgstr_w(szUrl));
1950 ok(grfPI == (PI_FILTER_MODE|PI_FORCE_ASYNC), "grfPI=%x, expected PI_FILTER_MODE|PI_FORCE_ASYNC\n", grfPI);
1951 ok(dwReserved, "dwReserved == 0\n");
1952 ok(pOIProtSink != NULL, "pOIProtSink == NULL\n");
1953 ok(pOIBindInfo != NULL, "pOIBindInfo == NULL\n");
1956 ok(pOIProtSink != binding_sink, "pOIProtSink == protocol_sink\n");
1957 ok(pOIBindInfo == prot_bind_info, "pOIBindInfo != bind_info\n");
1959 ok(pOIProtSink == &protocol_sink, "pOIProtSink != protocol_sink\n");
1960 ok(pOIBindInfo == &bind_info, "pOIBindInfo != bind_info\n");
1963 data = (void*)dwReserved;
1964 ok(data->cbSize == sizeof(*data), "data->cbSize = %d\n", data->cbSize);
1965 ok(!data->pProtocolSink, "data->pProtocolSink != NULL\n");
1966 ok(data->pProtocol != NULL, "data->pProtocol == NULL\n");
1967 ok(!data->pUnk, "data->pUnk != NULL\n");
1968 ok(!data->dwFilterFlags, "data->dwProtocolFlags = %x\n", data->dwFilterFlags);
1970 IInternetProtocolSink *prot_sink;
1972 IInternetProtocol_QueryInterface(data->pProtocol, &IID_IInternetProtocolSink, (void**)&prot_sink);
1973 ok(prot_sink == pOIProtSink, "QI(data->pProtocol, IID_IInternetProtocolSink) != pOIProtSink\n");
1974 IInternetProtocolSink_Release(prot_sink);
1976 ok(data->pProtocol != binding_protocol, "data->pProtocol == binding_protocol\n");
1978 filtered_protocol = data->pProtocol;
1979 IInternetProtocol_AddRef(filtered_protocol);
1981 IInternetProtocol *prot;
1983 IInternetProtocol_QueryInterface(data->pProtocol, &IID_IInternetProtocol, (void**)&prot);
1984 ok(prot == async_protocol, "QI(data->pProtocol, IID_IInternetProtocol) != async_protocol\n");
1985 IInternetProtocol_Release(prot);
1987 ok(data->pProtocol != async_protocol, "data->pProtocol == async_protocol\n");
1990 filtered_sink = pOIProtSink;
1992 SET_EXPECT(ReportProgress_DECODING);
1993 hres = IInternetProtocolSink_ReportProgress(pOIProtSink, BINDSTATUS_DECODING, gzipW);
1994 ok(hres == S_OK, "ReportProgress(BINDSTATUS_DECODING) failed: %08x\n", hres);
1995 CHECK_CALLED(ReportProgress_DECODING);
1997 SET_EXPECT(GetBindInfo);
1998 memset(&bindinfo, 0, sizeof(bindinfo));
1999 bindinfo.cbSize = sizeof(bindinfo);
2000 hres = IInternetBindInfo_GetBindInfo(pOIBindInfo, &cbindf, &bindinfo);
2001 ok(hres == S_OK, "GetBindInfo failed: %08x\n", hres);
2002 ok(cbindf == (bindf|BINDF_FROMURLMON), "cbindf = %x, expected %x\n", cbindf, bindf);
2003 CHECK_CALLED(GetBindInfo);
2005 SET_EXPECT(GetBindString_URL);
2006 hres = IInternetBindInfo_GetBindString(pOIBindInfo, BINDSTRING_URL, &url_str, 1, &fetched);
2007 ok(hres == S_OK, "GetBindString(BINDSTRING_URL) failed: %08x\n", hres);
2008 ok(fetched == 1, "fetched = %d\n", fetched);
2009 ok(!strcmp_ww(url_str, binding_urls[tested_protocol]), "wrong url_str %s\n", wine_dbgstr_w(url_str));
2010 CoTaskMemFree(url_str);
2011 CHECK_CALLED(GetBindString_URL);
2016 static HRESULT WINAPI Protocol_Continue(IInternetProtocolEx *iface,
2017 PROTOCOLDATA *pProtocolData)
2019 CHECK_EXPECT(MimeFilter_Continue);
2023 static HRESULT WINAPI MimeProtocol_Terminate(IInternetProtocolEx *iface, DWORD dwOptions)
2027 CHECK_EXPECT(MimeFilter_Terminate);
2029 ok(!dwOptions, "dwOptions = %x\n", dwOptions);
2031 SET_EXPECT(Terminate);
2032 hres = IInternetProtocol_Terminate(filtered_protocol, dwOptions);
2033 ok(hres == S_OK, "Terminate failed: %08x\n", hres);
2034 CHECK_CALLED(Terminate);
2039 static HRESULT WINAPI MimeProtocol_Read(IInternetProtocolEx *iface, void *pv,
2040 ULONG cb, ULONG *pcbRead)
2046 CHECK_EXPECT(MimeFilter_Read);
2048 ok(pv != NULL, "pv == NULL\n");
2049 ok(cb != 0, "cb == 0\n");
2050 ok(pcbRead != NULL, "pcbRead == NULL\n");
2052 if(read_report_data)
2056 hres = IInternetProtocol_Read(filtered_protocol, buf, sizeof(buf), &read);
2057 ok(hres == S_OK || hres == S_FALSE || hres == E_PENDING, "Read failed: %08x\n", hres);
2058 if(read_report_data)
2059 CHECK_CALLED(Read2);
2064 ok(*pcbRead == 0, "*pcbRead=%d, expected 0\n", *pcbRead);
2068 memset(pv, 'x', read);
2072 static HRESULT WINAPI MimeProtocol_LockRequest(IInternetProtocolEx *iface, DWORD dwOptions)
2076 CHECK_EXPECT(MimeFilter_LockRequest);
2078 ok(!dwOptions, "dwOptions = %x\n", dwOptions);
2080 SET_EXPECT(LockRequest);
2081 hres = IInternetProtocol_LockRequest(filtered_protocol, dwOptions);
2082 ok(hres == S_OK, "LockRequest failed: %08x\n", hres);
2083 CHECK_CALLED(LockRequest);
2088 static HRESULT WINAPI MimeProtocol_UnlockRequest(IInternetProtocolEx *iface)
2092 CHECK_EXPECT(MimeFilter_UnlockRequest);
2094 SET_EXPECT(UnlockRequest);
2095 hres = IInternetProtocol_UnlockRequest(filtered_protocol);
2096 ok(hres == S_OK, "UnlockRequest failed: %08x\n", hres);
2097 CHECK_CALLED(UnlockRequest);
2102 static const IInternetProtocolExVtbl MimeProtocolVtbl = {
2103 MimeProtocol_QueryInterface,
2109 MimeProtocol_Terminate,
2114 MimeProtocol_LockRequest,
2115 MimeProtocol_UnlockRequest
2118 static IInternetProtocolEx MimeProtocol = { &MimeProtocolVtbl };
2120 static HRESULT WINAPI ClassFactory_QueryInterface(IClassFactory *iface, REFIID riid, void **ppv)
2122 ok(0, "unexpected call\n");
2123 return E_NOINTERFACE;
2126 static ULONG WINAPI ClassFactory_AddRef(IClassFactory *iface)
2131 static ULONG WINAPI ClassFactory_Release(IClassFactory *iface)
2136 static HRESULT WINAPI ClassFactory_CreateInstance(IClassFactory *iface, IUnknown *pOuter,
2137 REFIID riid, void **ppv)
2139 CHECK_EXPECT(CreateInstance);
2141 ok(pOuter == (IUnknown*)prot_bind_info, "pOuter != protocol_unk\n");
2142 ok(IsEqualGUID(&IID_IUnknown, riid), "unexpected riid %s\n", debugstr_guid(riid));
2143 ok(ppv != NULL, "ppv == NULL\n");
2149 static HRESULT WINAPI ClassFactory_LockServer(IClassFactory *iface, BOOL dolock)
2151 ok(0, "unexpected call\n");
2155 static const IClassFactoryVtbl ClassFactoryVtbl = {
2156 ClassFactory_QueryInterface,
2157 ClassFactory_AddRef,
2158 ClassFactory_Release,
2159 ClassFactory_CreateInstance,
2160 ClassFactory_LockServer
2163 static IClassFactory ClassFactory = { &ClassFactoryVtbl };
2165 static HRESULT WINAPI MimeFilter_CreateInstance(IClassFactory *iface, IUnknown *outer, REFIID riid, void **ppv)
2167 CHECK_EXPECT(MimeFilter_CreateInstance);
2169 ok(!outer, "outer = %p\n", outer);
2170 ok(IsEqualGUID(&IID_IInternetProtocol, riid), "unexpected riid %s\n", debugstr_guid(riid));
2172 *ppv = &MimeProtocol;
2176 static const IClassFactoryVtbl MimeFilterCFVtbl = {
2177 ClassFactory_QueryInterface,
2178 ClassFactory_AddRef,
2179 ClassFactory_Release,
2180 MimeFilter_CreateInstance,
2181 ClassFactory_LockServer
2184 static IClassFactory mimefilter_cf = { &MimeFilterCFVtbl };
2186 #define TEST_BINDING 0x0001
2187 #define TEST_FILTER 0x0002
2188 #define TEST_FIRST_HTTP 0x0004
2189 #define TEST_DIRECT_READ 0x0008
2190 #define TEST_POST 0x0010
2191 #define TEST_EMULATEPROT 0x0020
2192 #define TEST_SHORT_READ 0x0040
2193 #define TEST_REDIRECT 0x0080
2194 #define TEST_ABORT 0x0100
2195 #define TEST_ASYNCREQ 0x0200
2196 #define TEST_USEIURI 0x0400
2197 #define TEST_IMPLPROTEX 0x0800
2199 static void init_test(int prot, DWORD flags)
2201 tested_protocol = prot;
2202 binding_test = (flags & TEST_BINDING) != 0;
2203 first_data_notif = TRUE;
2206 async_read_pending = TRUE;
2207 mimefilter_test = (flags & TEST_FILTER) != 0;
2209 post_stream_read = 0;
2210 ResetEvent(event_complete);
2211 ResetEvent(event_complete2);
2212 ResetEvent(event_continue);
2213 ResetEvent(event_continue_done);
2214 async_protocol = binding_protocol = filtered_protocol = NULL;
2215 filtered_sink = NULL;
2216 http_is_first = (flags & TEST_FIRST_HTTP) != 0;
2217 first_data_notif = TRUE;
2218 state = STATE_CONNECTING;
2219 test_async_req = (flags & TEST_ASYNCREQ) != 0;
2220 direct_read = (flags & TEST_DIRECT_READ) != 0;
2221 emulate_prot = (flags & TEST_EMULATEPROT) != 0;
2222 wait_for_switch = TRUE;
2223 short_read = (flags & TEST_SHORT_READ) != 0;
2224 http_post_test = TYMED_NULL;
2225 test_redirect = (flags & TEST_REDIRECT) != 0;
2226 test_abort = (flags & TEST_ABORT) != 0;
2227 impl_protex = (flags & TEST_IMPLPROTEX) != 0;
2230 static void test_priority(IInternetProtocol *protocol)
2232 IInternetPriority *priority;
2236 hres = IInternetProtocol_QueryInterface(protocol, &IID_IInternetPriority,
2238 ok(hres == S_OK, "QueryInterface(IID_IInternetPriority) failed: %08x\n", hres);
2242 hres = IInternetPriority_GetPriority(priority, &pr);
2243 ok(hres == S_OK, "GetPriority failed: %08x\n", hres);
2244 ok(pr == 0, "pr=%d, expected 0\n", pr);
2246 hres = IInternetPriority_SetPriority(priority, 1);
2247 ok(hres == S_OK, "SetPriority failed: %08x\n", hres);
2249 hres = IInternetPriority_GetPriority(priority, &pr);
2250 ok(hres == S_OK, "GetPriority failed: %08x\n", hres);
2251 ok(pr == 1, "pr=%d, expected 1\n", pr);
2253 IInternetPriority_Release(priority);
2256 static void test_early_abort(const CLSID *clsid)
2258 IInternetProtocol *protocol;
2261 hres = CoCreateInstance(clsid, NULL, CLSCTX_INPROC_SERVER|CLSCTX_INPROC_HANDLER,
2262 &IID_IInternetProtocol, (void**)&protocol);
2263 ok(hres == S_OK, "CoCreateInstance failed: %08x\n", hres);
2265 hres = IInternetProtocol_Abort(protocol, E_ABORT, 0);
2266 ok(hres == S_OK, "Abort failed: %08x\n", hres);
2268 hres = IInternetProtocol_Abort(protocol, E_FAIL, 0);
2269 ok(hres == S_OK, "Abort failed: %08x\n", hres);
2271 IInternetProtocol_Release(protocol);
2274 static BOOL file_protocol_start(IInternetProtocol *protocol, LPCWSTR url,
2275 IInternetProtocolEx *protocolex, IUri *uri, BOOL is_first)
2279 SET_EXPECT(GetBindInfo);
2280 if(!(bindf & BINDF_FROMURLMON))
2281 SET_EXPECT(ReportProgress_DIRECTBIND);
2283 SET_EXPECT(ReportProgress_SENDINGREQUEST);
2284 SET_EXPECT(ReportProgress_CACHEFILENAMEAVAILABLE);
2285 if(bindf & BINDF_FROMURLMON)
2286 SET_EXPECT(ReportProgress_VERIFIEDMIMETYPEAVAILABLE);
2288 SET_EXPECT(ReportProgress_MIMETYPEAVAILABLE);
2290 SET_EXPECT(ReportData);
2292 SET_EXPECT(ReportResult);
2294 expect_hrResult = S_OK;
2297 hres = IInternetProtocolEx_StartEx(protocolex, uri, &protocol_sink, &bind_info, 0, 0);
2298 ok(hres == S_OK, "StartEx failed: %08x\n", hres);
2300 hres = IInternetProtocol_Start(protocol, url, &protocol_sink, &bind_info, 0, 0);
2301 if(hres == INET_E_RESOURCE_NOT_FOUND) {
2302 win_skip("Start failed\n");
2305 ok(hres == S_OK, "Start failed: %08x\n", hres);
2308 CHECK_CALLED(GetBindInfo);
2309 if(!(bindf & BINDF_FROMURLMON))
2310 CHECK_CALLED(ReportProgress_DIRECTBIND);
2312 CHECK_CALLED(ReportProgress_SENDINGREQUEST);
2313 CHECK_CALLED(ReportProgress_CACHEFILENAMEAVAILABLE);
2314 if(bindf & BINDF_FROMURLMON)
2315 CHECK_CALLED(ReportProgress_VERIFIEDMIMETYPEAVAILABLE);
2317 CHECK_CALLED(ReportProgress_MIMETYPEAVAILABLE);
2319 CHECK_CALLED(ReportData);
2321 CHECK_CALLED(ReportResult);
2326 static void test_file_protocol_url(LPCWSTR url)
2328 IInternetProtocolInfo *protocol_info;
2330 IClassFactory *factory;
2331 IInternetProtocol *protocol;
2336 hres = CoGetClassObject(&CLSID_FileProtocol, CLSCTX_INPROC_SERVER, NULL,
2337 &IID_IUnknown, (void**)&unk);
2338 ok(hres == S_OK, "CoGetClassObject failed: %08x\n", hres);
2342 hres = IUnknown_QueryInterface(unk, &IID_IInternetProtocolInfo, (void**)&protocol_info);
2343 ok(hres == E_NOINTERFACE,
2344 "Could not get IInternetProtocolInfo interface: %08x, expected E_NOINTERFACE\n", hres);
2346 hres = IUnknown_QueryInterface(unk, &IID_IClassFactory, (void**)&factory);
2347 ok(hres == S_OK, "Could not get IClassFactory interface\n");
2348 IUnknown_Release(unk);
2352 hres = IClassFactory_CreateInstance(factory, NULL, &IID_IInternetProtocol, (void**)&protocol);
2353 ok(hres == S_OK, "Could not get IInternetProtocol: %08x\n", hres);
2355 if(SUCCEEDED(hres)) {
2356 if(file_protocol_start(protocol, url, NULL, NULL, TRUE)) {
2357 hres = IInternetProtocol_Read(protocol, buf, 2, &cb);
2358 ok(hres == S_OK, "Read failed: %08x\n", hres);
2359 ok(cb == 2, "cb=%u expected 2\n", cb);
2360 hres = IInternetProtocol_Read(protocol, buf, sizeof(buf), &cb);
2361 ok(hres == S_FALSE, "Read failed: %08x\n", hres);
2362 hres = IInternetProtocol_Read(protocol, buf, sizeof(buf), &cb);
2363 ok(hres == S_FALSE, "Read failed: %08x expected S_FALSE\n", hres);
2364 ok(cb == 0, "cb=%u expected 0\n", cb);
2365 hres = IInternetProtocol_UnlockRequest(protocol);
2366 ok(hres == S_OK, "UnlockRequest failed: %08x\n", hres);
2369 if(file_protocol_start(protocol, url, NULL, NULL, FALSE)) {
2370 hres = IInternetProtocol_Read(protocol, buf, 2, &cb);
2371 ok(hres == S_FALSE, "Read failed: %08x\n", hres);
2372 hres = IInternetProtocol_LockRequest(protocol, 0);
2373 ok(hres == S_OK, "LockRequest failed: %08x\n", hres);
2374 hres = IInternetProtocol_UnlockRequest(protocol);
2375 ok(hres == S_OK, "UnlockRequest failed: %08x\n", hres);
2378 IInternetProtocol_Release(protocol);
2381 hres = IClassFactory_CreateInstance(factory, NULL, &IID_IInternetProtocol, (void**)&protocol);
2382 ok(hres == S_OK, "Could not get IInternetProtocol: %08x\n", hres);
2383 if(SUCCEEDED(hres)) {
2384 if(file_protocol_start(protocol, url, NULL, NULL, TRUE)) {
2385 hres = IInternetProtocol_LockRequest(protocol, 0);
2386 ok(hres == S_OK, "LockRequest failed: %08x\n", hres);
2387 hres = IInternetProtocol_Terminate(protocol, 0);
2388 ok(hres == S_OK, "Terminate failed: %08x\n", hres);
2389 hres = IInternetProtocol_Read(protocol, buf, 2, &cb);
2390 ok(hres == S_OK, "Read failed: %08x\n\n", hres);
2391 hres = IInternetProtocol_UnlockRequest(protocol);
2392 ok(hres == S_OK, "UnlockRequest failed: %08x\n", hres);
2393 hres = IInternetProtocol_Read(protocol, buf, 2, &cb);
2394 ok(hres == S_OK, "Read failed: %08x\n", hres);
2395 hres = IInternetProtocol_Terminate(protocol, 0);
2396 ok(hres == S_OK, "Terminate failed: %08x\n", hres);
2399 IInternetProtocol_Release(protocol);
2402 hres = IClassFactory_CreateInstance(factory, NULL, &IID_IInternetProtocol, (void**)&protocol);
2403 ok(hres == S_OK, "Could not get IInternetProtocol: %08x\n", hres);
2404 if(SUCCEEDED(hres)) {
2405 if(file_protocol_start(protocol, url, NULL, NULL, TRUE)) {
2406 hres = IInternetProtocol_Terminate(protocol, 0);
2407 ok(hres == S_OK, "Terminate failed: %08x\n", hres);
2408 hres = IInternetProtocol_Read(protocol, buf, 2, &cb);
2409 ok(hres == S_OK, "Read failed: %08x\n", hres);
2410 ok(cb == 2, "cb=%u expected 2\n", cb);
2413 IInternetProtocol_Release(protocol);
2417 IInternetProtocolEx *protocolex;
2420 hres = pCreateUri(url, Uri_CREATE_FILE_USE_DOS_PATH, 0, &uri);
2421 ok(hres == S_OK, "CreateUri failed: %08x\n", hres);
2423 hres = IClassFactory_CreateInstance(factory, NULL, &IID_IInternetProtocolEx, (void**)&protocolex);
2424 ok(hres == S_OK, "Could not get IInternetProtocolEx: %08x\n", hres);
2426 if(file_protocol_start(NULL, NULL, protocolex, uri, TRUE)) {
2427 hres = IInternetProtocolEx_Read(protocolex, buf, 2, &cb);
2428 ok(hres == S_OK, "Read failed: %08x\n", hres);
2429 hres = IInternetProtocolEx_LockRequest(protocolex, 0);
2430 ok(hres == S_OK, "LockRequest failed: %08x\n", hres);
2431 hres = IInternetProtocolEx_UnlockRequest(protocolex);
2432 ok(hres == S_OK, "UnlockRequest failed: %08x\n", hres);
2436 IInternetProtocolEx_Release(protocolex);
2438 win_skip("Skipping file protocol StartEx tests\n");
2441 IClassFactory_Release(factory);
2444 static void test_file_protocol_fail(void)
2446 IInternetProtocol *protocol;
2449 static const WCHAR index_url2[] =
2450 {'f','i','l','e',':','/','/','i','n','d','e','x','.','h','t','m','l',0};
2452 hres = CoCreateInstance(&CLSID_FileProtocol, NULL, CLSCTX_INPROC_SERVER|CLSCTX_INPROC_HANDLER,
2453 &IID_IInternetProtocol, (void**)&protocol);
2454 ok(hres == S_OK, "CoCreateInstance failed: %08x\n", hres);
2458 SET_EXPECT(GetBindInfo);
2459 expect_hrResult = MK_E_SYNTAX;
2460 hres = IInternetProtocol_Start(protocol, wszIndexHtml, &protocol_sink, &bind_info, 0, 0);
2461 ok(hres == MK_E_SYNTAX ||
2462 hres == E_INVALIDARG,
2463 "Start failed: %08x, expected MK_E_SYNTAX or E_INVALIDARG\n", hres);
2464 CLEAR_CALLED(GetBindInfo); /* GetBindInfo not called in IE7 */
2466 SET_EXPECT(GetBindInfo);
2467 if(!(bindf & BINDF_FROMURLMON))
2468 SET_EXPECT(ReportProgress_DIRECTBIND);
2469 SET_EXPECT(ReportProgress_SENDINGREQUEST);
2470 SET_EXPECT(ReportResult);
2471 expect_hrResult = INET_E_RESOURCE_NOT_FOUND;
2472 hres = IInternetProtocol_Start(protocol, index_url, &protocol_sink, &bind_info, 0, 0);
2473 ok(hres == INET_E_RESOURCE_NOT_FOUND,
2474 "Start failed: %08x expected INET_E_RESOURCE_NOT_FOUND\n", hres);
2475 CHECK_CALLED(GetBindInfo);
2476 if(!(bindf & BINDF_FROMURLMON))
2477 CHECK_CALLED(ReportProgress_DIRECTBIND);
2478 CHECK_CALLED(ReportProgress_SENDINGREQUEST);
2479 CHECK_CALLED(ReportResult);
2481 IInternetProtocol_Release(protocol);
2483 hres = CoCreateInstance(&CLSID_FileProtocol, NULL, CLSCTX_INPROC_SERVER|CLSCTX_INPROC_HANDLER,
2484 &IID_IInternetProtocol, (void**)&protocol);
2485 ok(hres == S_OK, "CoCreateInstance failed: %08x\n", hres);
2489 SET_EXPECT(GetBindInfo);
2490 if(!(bindf & BINDF_FROMURLMON))
2491 SET_EXPECT(ReportProgress_DIRECTBIND);
2492 SET_EXPECT(ReportProgress_SENDINGREQUEST);
2493 SET_EXPECT(ReportResult);
2494 expect_hrResult = INET_E_RESOURCE_NOT_FOUND;
2496 hres = IInternetProtocol_Start(protocol, index_url2, &protocol_sink, &bind_info, 0, 0);
2497 ok(hres == INET_E_RESOURCE_NOT_FOUND,
2498 "Start failed: %08x, expected INET_E_RESOURCE_NOT_FOUND\n", hres);
2499 CHECK_CALLED(GetBindInfo);
2500 if(!(bindf & BINDF_FROMURLMON))
2501 CHECK_CALLED(ReportProgress_DIRECTBIND);
2502 CHECK_CALLED(ReportProgress_SENDINGREQUEST);
2503 CHECK_CALLED(ReportResult);
2505 SET_EXPECT(GetBindInfo);
2506 hres = IInternetProtocol_Start(protocol, NULL, &protocol_sink, &bind_info, 0, 0);
2507 ok(hres == E_INVALIDARG, "Start failed: %08x, expected E_INVALIDARG\n", hres);
2508 CLEAR_CALLED(GetBindInfo); /* GetBindInfo not called in IE7 */
2510 SET_EXPECT(GetBindInfo);
2511 hres = IInternetProtocol_Start(protocol, emptyW, &protocol_sink, &bind_info, 0, 0);
2512 ok(hres == E_INVALIDARG, "Start failed: %08x, expected E_INVALIDARG\n", hres);
2513 CLEAR_CALLED(GetBindInfo); /* GetBindInfo not called in IE7 */
2515 IInternetProtocol_Release(protocol);
2518 static void test_file_protocol(void) {
2519 WCHAR buf[INTERNET_MAX_URL_LENGTH], file_name_buf[MAX_PATH];
2524 static const WCHAR wszFile[] = {'f','i','l','e',':',0};
2525 static const WCHAR wszFile2[] = {'f','i','l','e',':','/','/',0};
2526 static const WCHAR wszFile3[] = {'f','i','l','e',':','/','/','/',0};
2527 static const WCHAR wszFile4[] = {'f','i','l','e',':','\\','\\',0};
2528 static const char html_doc[] = "<HTML></HTML>";
2530 trace("Testing file protocol...\n");
2531 init_test(FILE_TEST, 0);
2533 SetLastError(0xdeadbeef);
2534 file = CreateFileW(wszIndexHtml, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS,
2535 FILE_ATTRIBUTE_NORMAL, NULL);
2536 if(!file && GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)
2538 win_skip("Detected Win9x or WinMe\n");
2541 ok(file != INVALID_HANDLE_VALUE, "CreateFile failed\n");
2542 if(file == INVALID_HANDLE_VALUE)
2544 WriteFile(file, html_doc, sizeof(html_doc)-1, &size, NULL);
2547 file_name = wszIndexHtml;
2549 test_file_protocol_url(index_url);
2550 bindf = BINDF_FROMURLMON;
2551 test_file_protocol_url(index_url);
2552 bindf = BINDF_FROMURLMON | BINDF_NEEDFILE;
2553 test_file_protocol_url(index_url);
2555 memcpy(buf, wszFile, sizeof(wszFile));
2556 len = sizeof(wszFile)/sizeof(WCHAR)-1;
2557 len += GetCurrentDirectoryW(sizeof(buf)/sizeof(WCHAR)-len, buf+len);
2559 memcpy(buf+len, wszIndexHtml, sizeof(wszIndexHtml));
2561 file_name = buf + sizeof(wszFile)/sizeof(WCHAR)-1;
2563 test_file_protocol_url(buf);
2564 bindf = BINDF_FROMURLMON;
2565 test_file_protocol_url(buf);
2567 memcpy(buf, wszFile2, sizeof(wszFile2));
2568 len = GetCurrentDirectoryW(sizeof(file_name_buf)/sizeof(WCHAR), file_name_buf);
2569 file_name_buf[len++] = '\\';
2570 memcpy(file_name_buf+len, wszIndexHtml, sizeof(wszIndexHtml));
2571 lstrcpyW(buf+sizeof(wszFile2)/sizeof(WCHAR)-1, file_name_buf);
2572 file_name = file_name_buf;
2574 test_file_protocol_url(buf);
2575 bindf = BINDF_FROMURLMON;
2576 test_file_protocol_url(buf);
2578 buf[sizeof(wszFile2)/sizeof(WCHAR)] = '|';
2579 test_file_protocol_url(buf);
2581 memcpy(buf, wszFile3, sizeof(wszFile3));
2582 len = sizeof(wszFile3)/sizeof(WCHAR)-1;
2583 len += GetCurrentDirectoryW(sizeof(buf)/sizeof(WCHAR)-len, buf+len);
2585 memcpy(buf+len, wszIndexHtml, sizeof(wszIndexHtml));
2587 file_name = buf + sizeof(wszFile3)/sizeof(WCHAR)-1;
2589 test_file_protocol_url(buf);
2590 bindf = BINDF_FROMURLMON;
2591 test_file_protocol_url(buf);
2593 memcpy(buf, wszFile4, sizeof(wszFile4));
2594 len = GetCurrentDirectoryW(sizeof(file_name_buf)/sizeof(WCHAR), file_name_buf);
2595 file_name_buf[len++] = '\\';
2596 memcpy(file_name_buf+len, wszIndexHtml, sizeof(wszIndexHtml));
2597 lstrcpyW(buf+sizeof(wszFile4)/sizeof(WCHAR)-1, file_name_buf);
2598 file_name = file_name_buf;
2600 test_file_protocol_url(buf);
2601 bindf = BINDF_FROMURLMON;
2602 test_file_protocol_url(buf);
2604 buf[sizeof(wszFile4)/sizeof(WCHAR)] = '|';
2605 test_file_protocol_url(buf);
2607 DeleteFileW(wszIndexHtml);
2610 test_file_protocol_fail();
2611 bindf = BINDF_FROMURLMON;
2612 test_file_protocol_fail();
2615 static BOOL http_protocol_start(LPCWSTR url, BOOL use_iuri)
2617 static BOOL got_user_agent = FALSE;
2621 if(use_iuri && pCreateUri) {
2622 hres = pCreateUri(url, 0, 0, &uri);
2623 ok(hres == S_OK, "CreateUri failed: %08x\n", hres);
2626 SET_EXPECT(GetBindInfo);
2627 if (!(bindf & BINDF_FROMURLMON))
2628 SET_EXPECT(ReportProgress_DIRECTBIND);
2630 SET_EXPECT(GetBindString_USER_AGENT);
2631 SET_EXPECT(GetBindString_ACCEPT_MIMES);
2632 SET_EXPECT(QueryService_HttpNegotiate);
2633 SET_EXPECT(BeginningTransaction);
2634 SET_EXPECT(GetRootSecurityId);
2635 if(http_post_test) {
2636 SET_EXPECT(GetBindString_POST_COOKIE);
2637 if(http_post_test == TYMED_ISTREAM)
2638 SET_EXPECT(Stream_Seek);
2642 IInternetProtocolEx *protocolex;
2644 hres = IInternetProtocol_QueryInterface(async_protocol, &IID_IInternetProtocolEx, (void**)&protocolex);
2645 ok(hres == S_OK, "Could not get IInternetProtocolEx iface: %08x\n", hres);
2647 hres = IInternetProtocolEx_StartEx(protocolex, uri, &protocol_sink, &bind_info, 0, 0);
2648 ok(hres == S_OK, "Start failed: %08x\n", hres);
2650 IInternetProtocolEx_Release(protocolex);
2653 hres = IInternetProtocol_Start(async_protocol, url, &protocol_sink, &bind_info, 0, 0);
2654 ok(hres == S_OK, "Start failed: %08x\n", hres);
2659 CHECK_CALLED(GetBindInfo);
2660 if (!(bindf & BINDF_FROMURLMON))
2661 CHECK_CALLED(ReportProgress_DIRECTBIND);
2662 if (!got_user_agent)
2664 CHECK_CALLED(GetBindString_USER_AGENT);
2665 got_user_agent = TRUE;
2667 CHECK_CALLED(GetBindString_ACCEPT_MIMES);
2668 CHECK_CALLED(QueryService_HttpNegotiate);
2669 CHECK_CALLED(BeginningTransaction);
2670 /* GetRootSecurityId called on WinXP but not on Win98 */
2671 CLEAR_CALLED(GetRootSecurityId);
2672 if(http_post_test) {
2673 CHECK_CALLED(GetBindString_POST_COOKIE);
2674 if(http_post_test == TYMED_ISTREAM)
2675 CHECK_CALLED(Stream_Seek);
2681 static void test_protocol_terminate(IInternetProtocol *protocol)
2687 hres = IInternetProtocol_LockRequest(protocol, 0);
2688 ok(hres == S_OK, "LockRequest failed: %08x\n", hres);
2690 hres = IInternetProtocol_Read(protocol, buf, 1, &cb);
2691 ok(hres == test_abort ? S_OK : S_FALSE, "Read failed: %08x\n", hres);
2693 hres = IInternetProtocol_Terminate(protocol, 0);
2694 ok(hres == S_OK, "Terminate failed: %08x\n", hres);
2696 /* This wait is to give the internet handles being freed in Terminate
2697 * enough time to actually terminate in all cases. Internet handles
2698 * terminate asynchronously and native reuses the main InternetOpen
2699 * handle. The only case in which this seems to be necessary is on
2700 * wine with native wininet and urlmon, resulting in the next time
2701 * test_http_protocol_url being called the first data notification actually
2702 * being an extra last data notification from the previous connection
2703 * about once out of every ten times. */
2706 hres = IInternetProtocol_UnlockRequest(protocol);
2707 ok(hres == S_OK, "UnlockRequest failed: %08x\n", hres);
2710 static void test_http_info(IInternetProtocol *protocol)
2712 IWinInetHttpInfo *info;
2715 hres = IInternetProtocol_QueryInterface(protocol, &IID_IWinInetHttpInfo, (void**)&info);
2716 ok(hres == S_OK, "Could not get IWinInterHttpInfo iface: %08x\n", hres);
2720 IWinInetHttpInfo_Release(info);
2723 /* is_first refers to whether this is the first call to this function
2725 static void test_http_protocol_url(LPCWSTR url, int prot, DWORD flags, DWORD tymed)
2727 IInternetProtocolInfo *protocol_info;
2728 IClassFactory *factory;
2732 init_test(prot, flags);
2734 http_post_test = tymed;
2736 hres = CoGetClassObject(prot == HTTPS_TEST ? &CLSID_HttpSProtocol : &CLSID_HttpProtocol,
2737 CLSCTX_INPROC_SERVER, NULL, &IID_IUnknown, (void**)&unk);
2738 ok(hres == S_OK, "CoGetClassObject failed: %08x\n", hres);
2742 hres = IUnknown_QueryInterface(unk, &IID_IInternetProtocolInfo, (void**)&protocol_info);
2743 ok(hres == E_NOINTERFACE,
2744 "Could not get IInternetProtocolInfo interface: %08x, expected E_NOINTERFACE\n",
2747 hres = IUnknown_QueryInterface(unk, &IID_IClassFactory, (void**)&factory);
2748 ok(hres == S_OK, "Could not get IClassFactory interface\n");
2749 IUnknown_Release(unk);
2753 hres = IClassFactory_CreateInstance(factory, NULL, &IID_IInternetProtocol,
2754 (void**)&async_protocol);
2755 ok(hres == S_OK, "Could not get IInternetProtocol: %08x\n", hres);
2756 if(SUCCEEDED(hres)) {
2761 test_priority(async_protocol);
2762 test_http_info(async_protocol);
2764 SET_EXPECT(ReportProgress_COOKIE_SENT);
2765 SET_EXPECT(ReportProgress_FINDINGRESOURCE);
2766 SET_EXPECT(ReportProgress_CONNECTING);
2767 SET_EXPECT(ReportProgress_SENDINGREQUEST);
2769 SET_EXPECT(ReportProgress_REDIRECTING);
2770 SET_EXPECT(ReportProgress_PROXYDETECTING);
2771 if(prot == HTTP_TEST)
2772 SET_EXPECT(ReportProgress_CACHEFILENAMEAVAILABLE);
2774 SET_EXPECT(QueryService_HttpSecurity);
2775 if(!(bindf & BINDF_FROMURLMON)) {
2776 SET_EXPECT(OnResponse);
2777 SET_EXPECT(ReportProgress_RAWMIMETYPE);
2778 SET_EXPECT(ReportData);
2783 if(!http_protocol_start(url, (flags & TEST_USEIURI) != 0))
2786 if(!direct_read && !test_abort)
2787 SET_EXPECT(ReportResult);
2788 expect_hrResult = test_abort ? E_ABORT : S_OK;
2792 while(wait_for_switch) {
2793 WaitForSingleObject(event_continue, INFINITE);
2794 CHECK_CALLED(Switch); /* Set in ReportData */
2795 call_continue(&continue_protdata);
2796 SetEvent(event_continue_done);
2799 hres = IInternetProtocol_Read(async_protocol, buf, 1, &cb);
2800 ok((hres == E_PENDING && cb==0) ||
2801 (hres == S_OK && cb==1), "Read failed: %08x (%d bytes)\n", hres, cb);
2803 WaitForSingleObject(event_complete, INFINITE);
2804 if(bindf & BINDF_FROMURLMON)
2805 CHECK_CALLED(Switch);
2807 CHECK_CALLED(ReportData);
2808 if(prot == HTTPS_TEST)
2809 CLEAR_CALLED(QueryService_HttpSecurity);
2812 if(bindf & BINDF_FROMURLMON)
2815 SET_EXPECT(ReportData);
2816 hres = IInternetProtocol_Read(async_protocol, buf, sizeof(buf), &cb);
2817 if(hres == E_PENDING) {
2818 hres = IInternetProtocol_Read(async_protocol, buf, 1, &cb);
2819 ok((hres == E_PENDING && cb==0) ||
2820 (hres == S_OK && cb==1), "Read failed: %08x (%d bytes)\n", hres, cb);
2821 WaitForSingleObject(event_complete, INFINITE);
2822 if(bindf & BINDF_FROMURLMON)
2823 CHECK_CALLED(Switch);
2825 CHECK_CALLED(ReportData);
2830 SET_EXPECT(ReportResult);
2831 hres = IInternetProtocol_Abort(async_protocol, E_ABORT, 0);
2832 ok(hres == S_OK, "Abort failed: %08x\n", hres);
2833 CHECK_CALLED(ReportResult);
2835 hres = IInternetProtocol_Abort(async_protocol, E_ABORT, 0);
2836 ok(hres == INET_E_RESULT_DISPATCHED, "Abort failed: %08x\n", hres);
2840 if(bindf & BINDF_FROMURLMON)
2841 CHECK_NOT_CALLED(Switch);
2843 CHECK_NOT_CALLED(ReportData);
2848 ok(hres == S_FALSE, "Read failed: %08x\n", hres);
2849 CHECK_CALLED(ReportResult);
2852 if(prot == HTTPS_TEST)
2853 CLEAR_CALLED(ReportProgress_SENDINGREQUEST);
2855 hres = IInternetProtocol_Abort(async_protocol, E_ABORT, 0);
2856 ok(hres == INET_E_RESULT_DISPATCHED, "Abort failed: %08x\n", hres);
2858 test_protocol_terminate(async_protocol);
2860 hres = IInternetProtocol_Abort(async_protocol, E_ABORT, 0);
2861 ok(hres == S_OK, "Abort failed: %08x\n", hres);
2863 ref = IInternetProtocol_Release(async_protocol);
2864 ok(!ref, "ref=%x\n", ref);
2867 IClassFactory_Release(factory);
2870 static void test_http_protocol(void)
2872 static const WCHAR winehq_url[] =
2873 {'h','t','t','p',':','/','/','w','w','w','.','w','i','n','e','h','q','.',
2874 'o','r','g','/','s','i','t','e','/','a','b','o','u','t',0};
2875 static const WCHAR posttest_url[] =
2876 {'h','t','t','p',':','/','/','c','r','o','s','s','o','v','e','r','.',
2877 'c','o','d','e','w','e','a','v','e','r','s','.','c','o','m','/',
2878 'p','o','s','t','t','e','s','t','.','p','h','p',0};
2879 static const WCHAR redirect_url[] =
2880 {'h','t','t','p',':','/','/','t','e','s','t','.','w','i','n','e','h','q','.','o','r','g','/',
2881 't','e','s','t','r','e','d','i','r','e','c','t',0};
2883 trace("Testing http protocol (not from urlmon)...\n");
2884 bindf = BINDF_ASYNCHRONOUS | BINDF_ASYNCSTORAGE | BINDF_PULLDATA;
2885 test_http_protocol_url(winehq_url, HTTP_TEST, TEST_FIRST_HTTP, TYMED_NULL);
2887 trace("Testing http protocol (from urlmon)...\n");
2888 bindf = BINDF_ASYNCHRONOUS | BINDF_ASYNCSTORAGE | BINDF_PULLDATA | BINDF_FROMURLMON;
2889 test_http_protocol_url(winehq_url, HTTP_TEST, 0, TYMED_NULL);
2891 trace("Testing http protocol (to file)...\n");
2892 bindf = BINDF_ASYNCHRONOUS | BINDF_ASYNCSTORAGE | BINDF_PULLDATA | BINDF_FROMURLMON | BINDF_NEEDFILE;
2893 test_http_protocol_url(winehq_url, HTTP_TEST, 0, TYMED_NULL);
2895 trace("Testing http protocol (post data)...\n");
2896 /* Without this flag we get a ReportProgress_CACHEFILENAMEAVAILABLE
2897 * notification with BINDVERB_POST */
2898 bindf = BINDF_ASYNCHRONOUS | BINDF_ASYNCSTORAGE | BINDF_PULLDATA | BINDF_FROMURLMON | BINDF_NOWRITECACHE;
2899 test_http_protocol_url(posttest_url, HTTP_TEST, TEST_FIRST_HTTP|TEST_POST, TYMED_HGLOBAL);
2901 trace("Testing http protocol (post data stream)...\n");
2902 test_http_protocol_url(posttest_url, HTTP_TEST, TEST_FIRST_HTTP|TEST_POST|TEST_ASYNCREQ, TYMED_ISTREAM);
2904 trace("Testing http protocol (direct read)...\n");
2905 bindf = BINDF_ASYNCHRONOUS | BINDF_ASYNCSTORAGE | BINDF_PULLDATA | BINDF_FROMURLMON;
2906 test_http_protocol_url(winehq_url, HTTP_TEST, TEST_DIRECT_READ|TEST_USEIURI, TYMED_NULL);
2908 trace("Testing http protocol (redirected)...\n");
2909 bindf = BINDF_ASYNCHRONOUS | BINDF_ASYNCSTORAGE | BINDF_PULLDATA | BINDF_FROMURLMON;
2910 test_http_protocol_url(redirect_url, HTTP_TEST, TEST_REDIRECT, TYMED_NULL);
2912 trace("Testing http protocol abort...\n");
2913 test_http_protocol_url(winehq_url, HTTP_TEST, TEST_ABORT, TYMED_NULL);
2915 test_early_abort(&CLSID_HttpProtocol);
2916 test_early_abort(&CLSID_HttpSProtocol);
2919 static void test_https_protocol(void)
2921 static const WCHAR codeweavers_url[] =
2922 {'h','t','t','p','s',':','/','/','w','w','w','.','c','o','d','e','w','e','a','v','e','r','s',
2923 '.','c','o','m','/','t','e','s','t','.','h','t','m','l',0};
2925 trace("Testing https protocol (from urlmon)...\n");
2926 bindf = BINDF_ASYNCHRONOUS | BINDF_ASYNCSTORAGE | BINDF_PULLDATA | BINDF_FROMURLMON | BINDF_NOWRITECACHE;
2927 test_http_protocol_url(codeweavers_url, HTTPS_TEST, TEST_FIRST_HTTP, TYMED_NULL);
2931 static void test_ftp_protocol(void)
2933 IInternetProtocolInfo *protocol_info;
2934 IClassFactory *factory;
2941 static const WCHAR ftp_urlW[] = {'f','t','p',':','/','/','f','t','p','.','w','i','n','e','h','q','.','o','r','g',
2942 '/','p','u','b','/','o','t','h','e','r','/',
2943 'w','i','n','e','l','o','g','o','.','x','c','f','.','t','a','r','.','b','z','2',0};
2945 trace("Testing ftp protocol...\n");
2947 bindf = BINDF_ASYNCHRONOUS | BINDF_ASYNCSTORAGE | BINDF_PULLDATA | BINDF_FROMURLMON | BINDF_NOWRITECACHE;
2948 state = STATE_STARTDOWNLOADING;
2949 tested_protocol = FTP_TEST;
2950 first_data_notif = TRUE;
2951 expect_hrResult = E_PENDING;
2953 hres = CoGetClassObject(&CLSID_FtpProtocol, CLSCTX_INPROC_SERVER, NULL, &IID_IUnknown, (void**)&unk);
2954 ok(hres == S_OK, "CoGetClassObject failed: %08x\n", hres);
2958 hres = IUnknown_QueryInterface(unk, &IID_IInternetProtocolInfo, (void**)&protocol_info);
2959 ok(hres == E_NOINTERFACE, "Could not get IInternetProtocolInfo interface: %08x, expected E_NOINTERFACE\n", hres);
2961 hres = IUnknown_QueryInterface(unk, &IID_IClassFactory, (void**)&factory);
2962 ok(hres == S_OK, "Could not get IClassFactory interface\n");
2963 IUnknown_Release(unk);
2967 hres = IClassFactory_CreateInstance(factory, NULL, &IID_IInternetProtocol,
2968 (void**)&async_protocol);
2969 IClassFactory_Release(factory);
2970 ok(hres == S_OK, "Could not get IInternetProtocol: %08x\n", hres);
2972 test_priority(async_protocol);
2973 test_http_info(async_protocol);
2975 SET_EXPECT(GetBindInfo);
2976 SET_EXPECT(ReportProgress_FINDINGRESOURCE);
2977 SET_EXPECT(ReportProgress_CONNECTING);
2978 SET_EXPECT(ReportProgress_SENDINGREQUEST);
2981 hres = IInternetProtocol_Start(async_protocol, ftp_urlW, &protocol_sink, &bind_info, 0, 0);
2982 ok(hres == S_OK, "Start failed: %08x\n", hres);
2983 CHECK_CALLED(GetBindInfo);
2985 SET_EXPECT(ReportResult);
2987 hres = IInternetProtocol_Read(async_protocol, buf, 1, &cb);
2988 ok((hres == E_PENDING && cb==0) ||
2989 (hres == S_OK && cb==1), "Read failed: %08x (%d bytes)\n", hres, cb);
2991 WaitForSingleObject(event_complete, INFINITE);
2994 hres = IInternetProtocol_Read(async_protocol, buf, sizeof(buf), &cb);
2995 if(hres == E_PENDING)
2996 WaitForSingleObject(event_complete, INFINITE);
3001 ok(hres == S_FALSE, "Read failed: %08x\n", hres);
3002 CHECK_CALLED(ReportResult);
3003 CHECK_CALLED(Switch);
3005 test_protocol_terminate(async_protocol);
3008 IInternetProtocolEx *protocolex;
3010 hres = IInternetProtocol_QueryInterface(async_protocol, &IID_IInternetProtocolEx, (void**)&protocolex);
3011 ok(hres == S_OK, "Could not get IInternetProtocolEx iface: %08x\n", hres);
3012 IInternetProtocolEx_Release(protocolex);
3015 ref = IInternetProtocol_Release(async_protocol);
3016 ok(!ref, "ref=%d\n", ref);
3018 test_early_abort(&CLSID_FtpProtocol);
3021 static void test_gopher_protocol(void)
3023 IInternetProtocolInfo *protocol_info;
3024 IClassFactory *factory;
3028 trace("Testing gopher protocol...\n");
3030 hres = CoGetClassObject(&CLSID_GopherProtocol, CLSCTX_INPROC_SERVER, NULL, &IID_IUnknown, (void**)&unk);
3032 hres == REGDB_E_CLASSNOTREG, /* Gopher protocol has been removed as of Vista */
3033 "CoGetClassObject failed: %08x\n", hres);
3037 hres = IUnknown_QueryInterface(unk, &IID_IInternetProtocolInfo, (void**)&protocol_info);
3038 ok(hres == E_NOINTERFACE, "Could not get IInternetProtocolInfo interface: %08x, expected E_NOINTERFACE\n", hres);
3040 hres = IUnknown_QueryInterface(unk, &IID_IClassFactory, (void**)&factory);
3041 ok(hres == S_OK, "Could not get IClassFactory interface\n");
3042 IUnknown_Release(unk);
3046 hres = IClassFactory_CreateInstance(factory, NULL, &IID_IInternetProtocol,
3047 (void**)&async_protocol);
3048 IClassFactory_Release(factory);
3049 ok(hres == S_OK, "Could not get IInternetProtocol: %08x\n", hres);
3051 test_priority(async_protocol);
3053 IInternetProtocol_Release(async_protocol);
3055 test_early_abort(&CLSID_GopherProtocol);
3058 static void test_mk_protocol(void)
3060 IInternetProtocolInfo *protocol_info;
3061 IInternetProtocol *protocol;
3062 IClassFactory *factory;
3066 static const WCHAR wrong_url1[] = {'t','e','s','t',':','@','M','S','I','T','S','t','o','r','e',
3067 ':',':','/','t','e','s','t','.','h','t','m','l',0};
3068 static const WCHAR wrong_url2[] = {'m','k',':','/','t','e','s','t','.','h','t','m','l',0};
3070 trace("Testing mk protocol...\n");
3071 init_test(MK_TEST, 0);
3073 hres = CoGetClassObject(&CLSID_MkProtocol, CLSCTX_INPROC_SERVER, NULL,
3074 &IID_IUnknown, (void**)&unk);
3075 ok(hres == S_OK, "CoGetClassObject failed: %08x\n", hres);
3077 hres = IUnknown_QueryInterface(unk, &IID_IInternetProtocolInfo, (void**)&protocol_info);
3078 ok(hres == E_NOINTERFACE,
3079 "Could not get IInternetProtocolInfo interface: %08x, expected E_NOINTERFACE\n",
3082 hres = IUnknown_QueryInterface(unk, &IID_IClassFactory, (void**)&factory);
3083 ok(hres == S_OK, "Could not get IClassFactory interface\n");
3084 IUnknown_Release(unk);
3088 hres = IClassFactory_CreateInstance(factory, NULL, &IID_IInternetProtocol,
3090 IClassFactory_Release(factory);
3091 ok(hres == S_OK, "Could not get IInternetProtocol: %08x\n", hres);
3093 SET_EXPECT(GetBindInfo);
3094 hres = IInternetProtocol_Start(protocol, wrong_url1, &protocol_sink, &bind_info, 0, 0);
3095 ok(hres == MK_E_SYNTAX || hres == INET_E_INVALID_URL,
3096 "Start failed: %08x, expected MK_E_SYNTAX or INET_E_INVALID_URL\n", hres);
3097 CLEAR_CALLED(GetBindInfo);
3099 SET_EXPECT(GetBindInfo);
3100 SET_EXPECT(ReportProgress_DIRECTBIND);
3101 SET_EXPECT(ReportProgress_SENDINGREQUEST);
3102 SET_EXPECT(ReportProgress_MIMETYPEAVAILABLE);
3103 SET_EXPECT(ReportResult);
3104 expect_hrResult = INET_E_RESOURCE_NOT_FOUND;
3106 hres = IInternetProtocol_Start(protocol, wrong_url2, &protocol_sink, &bind_info, 0, 0);
3107 ok(hres == INET_E_RESOURCE_NOT_FOUND ||
3108 hres == INET_E_INVALID_URL, /* win2k3 */
3109 "Start failed: %08x, expected INET_E_RESOURCE_NOT_FOUND or INET_E_INVALID_URL\n", hres);
3111 if (hres == INET_E_RESOURCE_NOT_FOUND) {
3112 CHECK_CALLED(GetBindInfo);
3113 CLEAR_CALLED(ReportProgress_DIRECTBIND);
3114 CHECK_CALLED(ReportProgress_SENDINGREQUEST);
3115 CHECK_CALLED(ReportProgress_MIMETYPEAVAILABLE);
3116 CHECK_CALLED(ReportResult);
3118 CLEAR_CALLED(GetBindInfo);
3119 CLEAR_CALLED(ReportProgress_DIRECTBIND);
3120 CLEAR_CALLED(ReportProgress_SENDINGREQUEST);
3121 CLEAR_CALLED(ReportProgress_MIMETYPEAVAILABLE);
3122 CLEAR_CALLED(ReportResult);
3125 IInternetProtocol_Release(protocol);
3128 static void test_CreateBinding(void)
3130 IInternetProtocol *protocol;
3131 IInternetPriority *priority;
3132 IInternetSession *session;
3133 IWinInetHttpInfo *http_info;
3134 IWinInetInfo *inet_info;
3140 static const WCHAR test_url[] =
3141 {'t','e','s','t',':','/','/','f','i','l','e','.','h','t','m','l',0};
3142 static const WCHAR wsz_test[] = {'t','e','s','t',0};
3144 trace("Testing CreateBinding...\n");
3145 init_test(BIND_TEST, TEST_BINDING);
3147 hres = pCoInternetGetSession(0, &session, 0);
3148 ok(hres == S_OK, "CoInternetGetSession failed: %08x\n", hres);
3150 hres = IInternetSession_RegisterNameSpace(session, &ClassFactory, &IID_NULL, wsz_test, 0, NULL, 0);
3151 ok(hres == S_OK, "RegisterNameSpace failed: %08x\n", hres);
3153 hres = IInternetSession_CreateBinding(session, NULL, test_url, NULL, NULL, &protocol, 0);
3154 binding_protocol = protocol;
3155 ok(hres == S_OK, "CreateBinding failed: %08x\n", hres);
3156 ok(protocol != NULL, "protocol == NULL\n");
3158 hres = IInternetProtocol_QueryInterface(protocol, &IID_IInternetBindInfo, (void**)&prot_bind_info);
3159 ok(hres == S_OK, "QueryInterface(IID_IInternetBindInfo) failed: %08x\n", hres);
3161 hres = IInternetProtocol_QueryInterface(protocol, &IID_IInternetProtocolSink, (void**)&binding_sink);
3162 ok(hres == S_OK, "Could not get IInternetProtocolSink: %08x\n", hres);
3164 hres = IInternetProtocol_Start(protocol, test_url, NULL, &bind_info, 0, 0);
3165 ok(hres == E_INVALIDARG, "Start failed: %08x, expected E_INVALIDARG\n", hres);
3166 hres = IInternetProtocol_Start(protocol, test_url, &protocol_sink, NULL, 0, 0);
3167 ok(hres == E_INVALIDARG, "Start failed: %08x, expected E_INVALIDARG\n", hres);
3168 hres = IInternetProtocol_Start(protocol, NULL, &protocol_sink, &bind_info, 0, 0);
3169 ok(hres == E_INVALIDARG, "Start failed: %08x, expected E_INVALIDARG\n", hres);
3171 hres = IInternetProtocol_QueryInterface(protocol, &IID_IInternetPriority, (void**)&priority);
3172 ok(hres == S_OK, "QueryInterface(IID_IInternetPriority) failed: %08x\n", hres);
3175 hres = IInternetPriority_GetPriority(priority, &p);
3176 ok(hres == S_OK, "GetPriority failed: %08x\n", hres);
3177 ok(!p, "p=%d\n", p);
3180 hres = IInternetPriority_SetPriority(priority, 100);
3181 ok(hres == S_OK, "SetPriority failed: %08x\n", hres);
3184 hres = IInternetPriority_GetPriority(priority, &p);
3185 ok(hres == S_OK, "GetPriority failed: %08x\n", hres);
3186 ok(p == 100, "p=%d\n", p);
3188 hres = IInternetProtocol_QueryInterface(protocol, &IID_IWinInetInfo, (void**)&inet_info);
3189 ok(hres == E_NOINTERFACE, "Could not get IWinInetInfo protocol: %08x\n", hres);
3191 SET_EXPECT(QueryService_InternetProtocol);
3192 SET_EXPECT(CreateInstance);
3193 SET_EXPECT(ReportProgress_PROTOCOLCLASSID);
3194 SET_EXPECT(SetPriority);
3197 expect_hrResult = S_OK;
3198 hres = IInternetProtocol_Start(protocol, test_url, &protocol_sink, &bind_info, 0, 0);
3199 ok(hres == S_OK, "Start failed: %08x\n", hres);
3201 CHECK_CALLED(QueryService_InternetProtocol);
3202 CHECK_CALLED(CreateInstance);
3203 CHECK_CALLED(ReportProgress_PROTOCOLCLASSID);
3204 CHECK_CALLED(SetPriority);
3205 CHECK_CALLED(Start);
3207 SET_EXPECT(QueryInterface_IWinInetInfo);
3208 hres = IInternetProtocol_QueryInterface(protocol, &IID_IWinInetInfo, (void**)&inet_info);
3209 ok(hres == E_NOINTERFACE, "Could not get IWinInetInfo protocol: %08x\n", hres);
3210 CHECK_CALLED(QueryInterface_IWinInetInfo);
3212 SET_EXPECT(QueryInterface_IWinInetInfo);
3213 hres = IInternetProtocol_QueryInterface(protocol, &IID_IWinInetInfo, (void**)&inet_info);
3214 ok(hres == E_NOINTERFACE, "Could not get IWinInetInfo protocol: %08x\n", hres);
3215 CHECK_CALLED(QueryInterface_IWinInetInfo);
3217 SET_EXPECT(QueryInterface_IWinInetHttpInfo);
3218 hres = IInternetProtocol_QueryInterface(protocol, &IID_IWinInetHttpInfo, (void**)&http_info);
3219 ok(hres == E_NOINTERFACE, "Could not get IWinInetInfo protocol: %08x\n", hres);
3220 CHECK_CALLED(QueryInterface_IWinInetHttpInfo);
3224 hres = IInternetProtocol_Read(protocol, expect_pv = buf, sizeof(buf), &read);
3225 ok(hres == S_OK, "Read failed: %08x\n", hres);
3226 ok(read == 100, "read = %d\n", read);
3231 hres = IInternetProtocol_Read(protocol, expect_pv = buf, sizeof(buf), &read);
3232 ok(hres == S_FALSE, "Read failed: %08x\n", hres);
3233 ok(!read, "read = %d\n", read);
3237 hres = IInternetPriority_GetPriority(priority, &p);
3238 ok(hres == S_OK, "GetPriority failed: %08x\n", hres);
3239 ok(p == 100, "p=%d\n", p);
3241 hres = IInternetPriority_SetPriority(priority, 101);
3242 ok(hres == S_OK, "SetPriority failed: %08x\n", hres);
3244 SET_EXPECT(Terminate);
3245 hres = IInternetProtocol_Terminate(protocol, 0xdeadbeef);
3246 ok(hres == S_OK, "Terminate failed: %08x\n", hres);
3247 CHECK_CALLED(Terminate);
3249 SET_EXPECT(Continue);
3250 hres = IInternetProtocolSink_Switch(binding_sink, &protocoldata);
3251 ok(hres == S_OK, "Switch failed: %08x\n", hres);
3252 CHECK_CALLED(Continue);
3254 hres = IInternetProtocolSink_ReportProgress(binding_sink,
3255 BINDSTATUS_CACHEFILENAMEAVAILABLE, expect_wsz = emptyW);
3256 ok(hres == S_OK, "ReportProgress(BINDSTATUS_CACHEFILENAMEAVAILABLE) failed: %08x\n", hres);
3258 hres = IInternetProtocolSink_ReportResult(binding_sink, S_OK, ERROR_SUCCESS, NULL);
3259 ok(hres == E_FAIL, "ReportResult failed: %08x, expected E_FAIL\n", hres);
3261 hres = IInternetProtocolSink_ReportData(binding_sink, 0, 0, 0);
3262 ok(hres == S_OK, "ReportData failed: %08x\n", hres);
3264 IInternetProtocolSink_Release(binding_sink);
3265 IInternetPriority_Release(priority);
3266 IInternetBindInfo_Release(prot_bind_info);
3267 IInternetProtocol_Release(protocol);
3269 hres = IInternetSession_CreateBinding(session, NULL, test_url, NULL, NULL, &protocol, 0);
3270 ok(hres == S_OK, "CreateBinding failed: %08x\n", hres);
3271 ok(protocol != NULL, "protocol == NULL\n");
3273 hres = IInternetProtocol_Abort(protocol, E_ABORT, 0);
3274 ok(hres == S_OK, "Abort failed: %08x\n", hres);
3276 hres = IInternetProtocol_Abort(protocol, E_FAIL, 0);
3277 ok(hres == S_OK, "Abort failed: %08x\n", hres);
3279 IInternetProtocol_Release(protocol);
3281 hres = IInternetSession_UnregisterNameSpace(session, &ClassFactory, wsz_test);
3282 ok(hres == S_OK, "UnregisterNameSpace failed: %08x\n", hres);
3284 hres = IInternetSession_CreateBinding(session, NULL, test_url, NULL, NULL, &protocol, 0);
3285 ok(hres == S_OK, "CreateBinding failed: %08x\n", hres);
3286 ok(protocol != NULL, "protocol == NULL\n");
3288 SET_EXPECT(QueryService_InternetProtocol);
3289 hres = IInternetProtocol_Start(protocol, test_url, &protocol_sink, &bind_info, 0, 0);
3290 ok(hres == MK_E_SYNTAX, "Start failed: %08x, expected MK_E_SYNTAX\n", hres);
3291 CHECK_CALLED(QueryService_InternetProtocol);
3293 IInternetProtocol_Release(protocol);
3295 IInternetSession_Release(session);
3298 static void test_binding(int prot, DWORD grf_pi, DWORD test_flags)
3300 IInternetProtocolEx *protocolex = NULL;
3301 IInternetProtocol *protocol;
3302 IInternetSession *session;
3309 init_test(prot, test_flags|TEST_BINDING);
3311 hres = pCoInternetGetSession(0, &session, 0);
3312 ok(hres == S_OK, "CoInternetGetSession failed: %08x\n", hres);
3314 if(test_flags & TEST_EMULATEPROT) {
3315 hres = IInternetSession_RegisterNameSpace(session, &ClassFactory, &IID_NULL, protocol_names[prot], 0, NULL, 0);
3316 ok(hres == S_OK, "RegisterNameSpace failed: %08x\n", hres);
3319 hres = IInternetSession_CreateBinding(session, NULL, binding_urls[prot], NULL, NULL, &protocol, 0);
3320 binding_protocol = protocol;
3321 ok(hres == S_OK, "CreateBinding failed: %08x\n", hres);
3322 ok(protocol != NULL, "protocol == NULL\n");
3324 hres = IInternetProtocol_QueryInterface(protocol, &IID_IInternetBindInfo, (void**)&prot_bind_info);
3325 ok(hres == S_OK, "QueryInterface(IID_IInternetBindInfo) failed: %08x\n", hres);
3327 hres = IInternetProtocol_QueryInterface(protocol, &IID_IInternetProtocolSink, (void**)&binding_sink);
3328 ok(hres == S_OK, "QueryInterface(IID_IInternetProtocolSink) failed: %08x\n", hres);
3330 if(test_flags & TEST_USEIURI) {
3331 hres = IInternetProtocol_QueryInterface(protocol, &IID_IInternetProtocolEx, (void**)&protocolex);
3332 ok(hres == S_OK, "Could not get IInternetProtocolEx iface: %08x\n", hres);
3334 hres = pCreateUri(binding_urls[prot], Uri_CREATE_FILE_USE_DOS_PATH, 0, &uri);
3335 ok(hres == S_OK, "CreateUri failed: %08x\n", hres);
3339 SET_EXPECT(QueryService_InternetProtocol);
3340 SET_EXPECT(CreateInstance);
3341 SET_EXPECT(ReportProgress_PROTOCOLCLASSID);
3342 SET_EXPECT(SetPriority);
3344 SET_EXPECT(StartEx);
3348 expect_hrResult = S_OK;
3351 hres = IInternetProtocolEx_StartEx(protocolex, uri, &protocol_sink, &bind_info, pi, 0);
3352 ok(hres == S_OK, "StartEx failed: %08x\n", hres);
3354 hres = IInternetProtocol_Start(protocol, binding_urls[prot], &protocol_sink, &bind_info, pi, 0);
3355 ok(hres == S_OK, "Start failed: %08x\n", hres);
3358 CHECK_CALLED(QueryService_InternetProtocol);
3359 CHECK_CALLED(CreateInstance);
3360 CHECK_CALLED(ReportProgress_PROTOCOLCLASSID);
3361 CHECK_CALLED(SetPriority);
3363 CHECK_CALLED(StartEx);
3365 CHECK_CALLED(Start);
3368 IInternetProtocolEx_Release(protocolex);
3372 if(prot == HTTP_TEST || prot == HTTPS_TEST) {
3373 while(prot_state < 4) {
3374 WaitForSingleObject(event_complete, INFINITE);
3375 if(mimefilter_test && filtered_protocol) {
3376 SET_EXPECT(Continue);
3377 IInternetProtocol_Continue(filtered_protocol, pdata);
3378 CHECK_CALLED(Continue);
3380 SET_EXPECT(Continue);
3381 IInternetProtocol_Continue(protocol, pdata);
3382 CHECK_CALLED(Continue);
3384 if(test_abort && prot_state == 2) {
3386 hres = IInternetProtocol_Abort(protocol, E_ABORT, 0);
3387 ok(hres == S_OK, "Abort failed: %08x\n", hres);
3388 CHECK_CALLED(Abort);
3390 hres = IInternetProtocol_Abort(protocol, E_ABORT, 0);
3391 ok(hres == S_OK, "Abort failed: %08x\n", hres);
3392 SetEvent(event_complete2);
3395 SetEvent(event_complete2);
3398 CHECK_CALLED(ReportData); /* Set in ReportResult */
3399 WaitForSingleObject(event_complete, INFINITE);
3402 SET_EXPECT(MimeFilter_LockRequest);
3404 SET_EXPECT(LockRequest);
3405 hres = IInternetProtocol_LockRequest(protocol, 0);
3406 ok(hres == S_OK, "LockRequest failed: %08x\n", hres);
3408 CHECK_CALLED(MimeFilter_LockRequest);
3410 CHECK_CALLED(LockRequest);
3413 SET_EXPECT(MimeFilter_UnlockRequest);
3415 SET_EXPECT(UnlockRequest);
3416 hres = IInternetProtocol_UnlockRequest(protocol);
3417 ok(hres == S_OK, "UnlockRequest failed: %08x\n", hres);
3419 CHECK_CALLED(MimeFilter_UnlockRequest);
3421 CHECK_CALLED(UnlockRequest);
3425 SET_EXPECT(MimeFilter_Terminate);
3427 SET_EXPECT(Terminate);
3428 hres = IInternetProtocol_Terminate(protocol, 0);
3429 ok(hres == S_OK, "Terminate failed: %08x\n", hres);
3431 CLEAR_CALLED(MimeFilter_Terminate);
3433 CHECK_CALLED(Terminate);
3435 if(filtered_protocol)
3436 IInternetProtocol_Release(filtered_protocol);
3437 IInternetBindInfo_Release(prot_bind_info);
3438 IInternetProtocolSink_Release(binding_sink);
3439 ref = IInternetProtocol_Release(protocol);
3440 ok(!ref, "ref=%u, expected 0\n", ref);
3442 if(test_flags & TEST_EMULATEPROT) {
3443 hres = IInternetSession_UnregisterNameSpace(session, &ClassFactory, protocol_names[prot]);
3444 ok(hres == S_OK, "UnregisterNameSpace failed: %08x\n", hres);
3447 IInternetSession_Release(session);
3450 static void register_filter(void)
3452 IInternetSession *session;
3455 static const WCHAR gzipW[] = {'g','z','i','p',0};
3457 hres = pCoInternetGetSession(0, &session, 0);
3458 ok(hres == S_OK, "CoInternetGetSession failed: %08x\n", hres);
3460 hres = IInternetSession_RegisterMimeFilter(session, &mimefilter_cf, &IID_IInternetProtocol, gzipW);
3461 ok(hres == S_OK, "RegisterMimeFilter failed: %08x\n", hres);
3463 IInternetSession_Release(session);
3466 START_TEST(protocol)
3470 hurlmon = GetModuleHandle("urlmon.dll");
3471 pCoInternetGetSession = (void*) GetProcAddress(hurlmon, "CoInternetGetSession");
3472 pReleaseBindInfo = (void*) GetProcAddress(hurlmon, "ReleaseBindInfo");
3473 pCreateUri = (void*) GetProcAddress(hurlmon, "CreateUri");
3475 if(!GetProcAddress(hurlmon, "CompareSecurityIds")) {
3476 win_skip("Various needed functions not present, too old IE\n");
3481 win_skip("CreateUri not supported\n");
3483 OleInitialize(NULL);
3485 event_complete = CreateEvent(NULL, FALSE, FALSE, NULL);
3486 event_complete2 = CreateEvent(NULL, FALSE, FALSE, NULL);
3487 event_continue = CreateEvent(NULL, FALSE, FALSE, NULL);
3488 event_continue_done = CreateEvent(NULL, FALSE, FALSE, NULL);
3489 thread_id = GetCurrentThreadId();
3493 test_file_protocol();
3494 test_http_protocol();
3495 test_https_protocol();
3496 test_ftp_protocol();
3497 test_gopher_protocol();
3499 test_CreateBinding();
3501 bindf &= ~BINDF_FROMURLMON;
3502 trace("Testing file binding (mime verification, emulate prot)...\n");
3503 test_binding(FILE_TEST, PI_MIMEVERIFICATION, TEST_EMULATEPROT);
3504 trace("Testing http binding (mime verification, emulate prot)...\n");
3505 test_binding(HTTP_TEST, PI_MIMEVERIFICATION, TEST_EMULATEPROT);
3506 trace("Testing http binding (mime verification, emulate prot, short read, direct read)...\n");
3507 test_binding(HTTP_TEST, PI_MIMEVERIFICATION, TEST_EMULATEPROT|TEST_SHORT_READ|TEST_DIRECT_READ);
3508 trace("Testing file binding (mime verification, emulate prot, mime filter)...\n");
3509 test_binding(FILE_TEST, PI_MIMEVERIFICATION, TEST_EMULATEPROT|TEST_FILTER);
3510 trace("Testing http binding (mime verification, emulate prot, mime filter)...\n");
3511 test_binding(HTTP_TEST, PI_MIMEVERIFICATION, TEST_EMULATEPROT|TEST_FILTER);
3512 trace("Testing http binding (mime verification, emulate prot, direct read)...\n");
3513 test_binding(HTTP_TEST, PI_MIMEVERIFICATION, TEST_EMULATEPROT|TEST_DIRECT_READ);
3514 trace("Testing http binding (mime verification, emulate prot, abort)...\n");
3515 test_binding(HTTP_TEST, PI_MIMEVERIFICATION, TEST_EMULATEPROT|TEST_ABORT);
3517 trace("Testing file binding (use IUri, mime verification, emulate prot)...\n");
3518 test_binding(FILE_TEST, PI_MIMEVERIFICATION, TEST_EMULATEPROT|TEST_USEIURI);
3519 trace("Testing file binding (use IUri, impl StartEx, mime verification, emulate prot)...\n");
3520 test_binding(FILE_TEST, PI_MIMEVERIFICATION, TEST_EMULATEPROT|TEST_USEIURI|TEST_IMPLPROTEX);
3521 trace("Testing file binding (impl StartEx, mime verification, emulate prot)...\n");
3522 test_binding(FILE_TEST, PI_MIMEVERIFICATION, TEST_EMULATEPROT|TEST_IMPLPROTEX);
3525 CloseHandle(event_complete);
3526 CloseHandle(event_complete2);
3527 CloseHandle(event_continue);
3528 CloseHandle(event_continue_done);