2 * Copyright 2005-2011 Jacek Caban for CodeWeavers
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
22 #include <wine/test.h>
32 static HRESULT (WINAPI *pCoInternetGetSession)(DWORD, IInternetSession **, DWORD);
33 static HRESULT (WINAPI *pReleaseBindInfo)(BINDINFO*);
34 static HRESULT (WINAPI *pCreateUri)(LPCWSTR, DWORD, DWORD_PTR, IUri**);
36 #define DEFINE_EXPECT(func) \
37 static BOOL expect_ ## func = FALSE, called_ ## func = FALSE
39 #define SET_EXPECT(func) \
40 expect_ ## func = TRUE
42 #define CHECK_EXPECT2(func) \
44 ok(expect_ ##func, "unexpected call " #func "\n"); \
45 called_ ## func = TRUE; \
48 #define CHECK_EXPECT(func) \
50 CHECK_EXPECT2(func); \
51 expect_ ## func = FALSE; \
54 #define CHECK_CALLED(func) \
56 ok(called_ ## func, "expected " #func "\n"); \
57 expect_ ## func = called_ ## func = FALSE; \
60 #define CHECK_NOT_CALLED(func) \
62 ok(!called_ ## func, "unexpected " #func "\n"); \
63 expect_ ## func = called_ ## func = FALSE; \
66 #define CLEAR_CALLED(func) \
67 expect_ ## func = called_ ## func = FALSE
69 DEFINE_EXPECT(GetBindInfo);
70 DEFINE_EXPECT(ReportProgress_MIMETYPEAVAILABLE);
71 DEFINE_EXPECT(ReportProgress_DIRECTBIND);
72 DEFINE_EXPECT(ReportProgress_RAWMIMETYPE);
73 DEFINE_EXPECT(ReportProgress_FINDINGRESOURCE);
74 DEFINE_EXPECT(ReportProgress_CONNECTING);
75 DEFINE_EXPECT(ReportProgress_SENDINGREQUEST);
76 DEFINE_EXPECT(ReportProgress_CACHEFILENAMEAVAILABLE);
77 DEFINE_EXPECT(ReportProgress_VERIFIEDMIMETYPEAVAILABLE);
78 DEFINE_EXPECT(ReportProgress_PROTOCOLCLASSID);
79 DEFINE_EXPECT(ReportProgress_COOKIE_SENT);
80 DEFINE_EXPECT(ReportProgress_REDIRECTING);
81 DEFINE_EXPECT(ReportProgress_ENCODING);
82 DEFINE_EXPECT(ReportProgress_ACCEPTRANGES);
83 DEFINE_EXPECT(ReportProgress_PROXYDETECTING);
84 DEFINE_EXPECT(ReportProgress_LOADINGMIMEHANDLER);
85 DEFINE_EXPECT(ReportProgress_DECODING);
86 DEFINE_EXPECT(ReportData);
87 DEFINE_EXPECT(ReportData2);
88 DEFINE_EXPECT(ReportResult);
89 DEFINE_EXPECT(GetBindString_ACCEPT_MIMES);
90 DEFINE_EXPECT(GetBindString_USER_AGENT);
91 DEFINE_EXPECT(GetBindString_POST_COOKIE);
92 DEFINE_EXPECT(GetBindString_URL);
93 DEFINE_EXPECT(QueryService_HttpNegotiate);
94 DEFINE_EXPECT(QueryService_InternetProtocol);
95 DEFINE_EXPECT(QueryService_HttpSecurity);
96 DEFINE_EXPECT(QueryInterface_IWinInetInfo);
97 DEFINE_EXPECT(QueryInterface_IWinInetHttpInfo);
98 DEFINE_EXPECT(BeginningTransaction);
99 DEFINE_EXPECT(GetRootSecurityId);
100 DEFINE_EXPECT(OnResponse);
101 DEFINE_EXPECT(Switch);
102 DEFINE_EXPECT(Continue);
103 DEFINE_EXPECT(CreateInstance);
104 DEFINE_EXPECT(Start);
105 DEFINE_EXPECT(StartEx);
106 DEFINE_EXPECT(Terminate);
108 DEFINE_EXPECT(Read2);
109 DEFINE_EXPECT(SetPriority);
110 DEFINE_EXPECT(LockRequest);
111 DEFINE_EXPECT(UnlockRequest);
112 DEFINE_EXPECT(Abort);
113 DEFINE_EXPECT(MimeFilter_CreateInstance);
114 DEFINE_EXPECT(MimeFilter_Start);
115 DEFINE_EXPECT(MimeFilter_ReportProgress);
116 DEFINE_EXPECT(MimeFilter_ReportData);
117 DEFINE_EXPECT(MimeFilter_ReportResult);
118 DEFINE_EXPECT(MimeFilter_Terminate);
119 DEFINE_EXPECT(MimeFilter_LockRequest);
120 DEFINE_EXPECT(MimeFilter_UnlockRequest);
121 DEFINE_EXPECT(MimeFilter_Read);
122 DEFINE_EXPECT(MimeFilter_Switch);
123 DEFINE_EXPECT(MimeFilter_Continue);
124 DEFINE_EXPECT(Stream_Seek);
125 DEFINE_EXPECT(Stream_Read);
127 static const WCHAR wszIndexHtml[] = {'i','n','d','e','x','.','h','t','m','l',0};
128 static const WCHAR index_url[] =
129 {'f','i','l','e',':','i','n','d','e','x','.','h','t','m','l',0};
131 static const WCHAR acc_mimeW[] = {'*','/','*',0};
132 static const WCHAR user_agentW[] = {'W','i','n','e',0};
133 static const WCHAR text_htmlW[] = {'t','e','x','t','/','h','t','m','l',0};
134 static const WCHAR hostW[] = {'w','w','w','.','w','i','n','e','h','q','.','o','r','g',0};
135 static const WCHAR winehq_ipW[] = {'2','0','9','.','4','6','.','2','5','.','1','3','4',0};
136 static const WCHAR emptyW[] = {0};
137 static const WCHAR gzipW[] = {'g','z','i','p',0};
139 static HRESULT expect_hrResult;
140 static LPCWSTR file_name, http_url, expect_wsz;
141 static IInternetProtocol *async_protocol = NULL;
142 static BOOL first_data_notif, http_is_first, test_redirect;
143 static int prot_state, read_report_data, post_stream_read;
144 static DWORD bindf, ex_priority , pi;
145 static IInternetProtocol *binding_protocol, *filtered_protocol;
146 static IInternetBindInfo *prot_bind_info;
147 static IInternetProtocolSink *binding_sink, *filtered_sink;
148 static void *expect_pv;
149 static HANDLE event_complete, event_complete2, event_continue, event_continue_done;
150 static BOOL binding_test;
151 static PROTOCOLDATA protocoldata, *pdata, continue_protdata;
152 static DWORD prot_read, pi, filter_state, http_post_test, thread_id;
153 static BOOL security_problem, test_async_req, impl_protex;
154 static BOOL async_read_pending, mimefilter_test, direct_read, wait_for_switch, emulate_prot, short_read, test_abort;
158 STATE_SENDINGREQUEST,
159 STATE_STARTDOWNLOADING,
173 static const WCHAR protocol_names[][10] = {
176 {'h','t','t','p','s',0},
183 static const WCHAR binding_urls[][130] = {
184 {'f','i','l','e',':','t','e','s','t','.','h','t','m','l',0},
185 {'h','t','t','p',':','/','/','w','w','w','.','w','i','n','e','h','q','.',
186 'o','r','g','/','s','i','t','e','/','a','b','o','u','t',0},
187 {'h','t','t','p','s',':','/','/','w','w','w','.','c','o','d','e','w','e','a','v','e','r','s',
188 '.','c','o','m','/','t','e','s','t','.','h','t','m','l',0},
189 {'f','t','p',':','/','/','f','t','p','.','w','i','n','e','h','q','.','o','r','g',
190 '/','p','u','b','/','o','t','h','e','r',
191 '/','w','i','n','e','l','o','g','o','.','x','c','f','.','t','a','r','.','b','z','2',0},
192 {'m','k',':','t','e','s','t',0},
193 {'i','t','s',':','t','e','s','t','.','c','h','m',':',':','/','b','l','a','n','k','.','h','t','m','l',0},
194 {'t','e','s','t',':','/','/','f','i','l','e','.','h','t','m','l',0}
197 static const CHAR post_data[] = "mode=Test";
199 static const char *debugstr_guid(REFIID riid)
203 sprintf(buf, "{%08X-%04X-%04X-%02X%02X-%02X%02X%02X%02X%02X%02X}",
204 riid->Data1, riid->Data2, riid->Data3, riid->Data4[0],
205 riid->Data4[1], riid->Data4[2], riid->Data4[3], riid->Data4[4],
206 riid->Data4[5], riid->Data4[6], riid->Data4[7]);
211 static int strcmp_wa(LPCWSTR strw, const char *stra)
214 WideCharToMultiByte(CP_ACP, 0, strw, -1, buf, sizeof(buf), NULL, NULL);
215 return lstrcmpA(stra, buf);
218 static BOOL proxy_active(void)
220 HKEY internet_settings;
224 if (RegOpenKeyExA(HKEY_CURRENT_USER, "Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings",
225 0, KEY_QUERY_VALUE, &internet_settings) != ERROR_SUCCESS)
228 size = sizeof(DWORD);
229 if (RegQueryValueExA(internet_settings, "ProxyEnable", NULL, NULL, (LPBYTE) &proxy_enable, &size) != ERROR_SUCCESS)
232 RegCloseKey(internet_settings);
234 return proxy_enable != 0;
237 static HRESULT WINAPI HttpSecurity_QueryInterface(IHttpSecurity *iface, REFIID riid, void **ppv)
239 if(IsEqualGUID(&IID_IUnknown, riid)
240 || IsEqualGUID(&IID_IHttpSecurity, riid)) {
245 ok(0, "unexpected call\n");
246 return E_NOINTERFACE;
249 static ULONG WINAPI HttpSecurity_AddRef(IHttpSecurity *iface)
254 static ULONG WINAPI HttpSecurity_Release(IHttpSecurity *iface)
259 static HRESULT WINAPI HttpSecurity_GetWindow(IHttpSecurity* iface, REFGUID rguidReason, HWND *phwnd)
261 trace("HttpSecurity_GetWindow\n");
266 static HRESULT WINAPI HttpSecurity_OnSecurityProblem(IHttpSecurity *iface, DWORD dwProblem)
268 trace("Security problem: %u\n", dwProblem);
269 ok(dwProblem == ERROR_INTERNET_SEC_CERT_REV_FAILED, "Expected ERROR_INTERNET_SEC_CERT_REV_FAILED got %u\n", dwProblem);
271 /* Only retry once */
272 if (security_problem)
275 security_problem = TRUE;
276 SET_EXPECT(BeginningTransaction);
281 static IHttpSecurityVtbl HttpSecurityVtbl = {
282 HttpSecurity_QueryInterface,
284 HttpSecurity_Release,
285 HttpSecurity_GetWindow,
286 HttpSecurity_OnSecurityProblem
289 static IHttpSecurity http_security = { &HttpSecurityVtbl };
291 static HRESULT WINAPI HttpNegotiate_QueryInterface(IHttpNegotiate2 *iface, REFIID riid, void **ppv)
293 if(IsEqualGUID(&IID_IUnknown, riid)
294 || IsEqualGUID(&IID_IHttpNegotiate, riid)
295 || IsEqualGUID(&IID_IHttpNegotiate2, riid)) {
300 ok(0, "unexpected call\n");
301 return E_NOINTERFACE;
304 static ULONG WINAPI HttpNegotiate_AddRef(IHttpNegotiate2 *iface)
309 static ULONG WINAPI HttpNegotiate_Release(IHttpNegotiate2 *iface)
314 static HRESULT WINAPI HttpNegotiate_BeginningTransaction(IHttpNegotiate2 *iface, LPCWSTR szURL,
315 LPCWSTR szHeaders, DWORD dwReserved, LPWSTR *pszAdditionalHeaders)
319 static const WCHAR wszHeaders[] =
320 {'C','o','n','t','e','n','t','-','T','y','p','e',':',' ','a','p','p','l','i','c','a','t',
321 'i','o','n','/','x','-','w','w','w','-','f','o','r','m','-','u','r','l','e','n','c','o',
322 'd','e','d','\r','\n',0};
324 CHECK_EXPECT(BeginningTransaction);
327 ok(!lstrcmpW(szURL, binding_urls[tested_protocol]), "szURL != http_url\n");
329 ok(!lstrcmpW(szURL, http_url), "szURL != http_url\n");
330 ok(!dwReserved, "dwReserved=%d, expected 0\n", dwReserved);
331 ok(pszAdditionalHeaders != NULL, "pszAdditionalHeaders == NULL\n");
332 if(pszAdditionalHeaders)
334 ok(*pszAdditionalHeaders == NULL, "*pszAdditionalHeaders != NULL\n");
337 addl_headers = CoTaskMemAlloc(sizeof(wszHeaders));
338 memcpy(addl_headers, wszHeaders, sizeof(wszHeaders));
339 *pszAdditionalHeaders = addl_headers;
346 static HRESULT WINAPI HttpNegotiate_OnResponse(IHttpNegotiate2 *iface, DWORD dwResponseCode,
347 LPCWSTR szResponseHeaders, LPCWSTR szRequestHeaders, LPWSTR *pszAdditionalRequestHeaders)
349 CHECK_EXPECT(OnResponse);
351 ok(dwResponseCode == 200, "dwResponseCode=%d, expected 200\n", dwResponseCode);
352 ok(szResponseHeaders != NULL, "szResponseHeaders == NULL\n");
353 ok(szRequestHeaders == NULL, "szRequestHeaders != NULL\n");
354 ok(pszAdditionalRequestHeaders == NULL, "pszAdditionalHeaders != NULL\n");
359 static HRESULT WINAPI HttpNegotiate_GetRootSecurityId(IHttpNegotiate2 *iface,
360 BYTE *pbSecurityId, DWORD *pcbSecurityId, DWORD_PTR dwReserved)
362 static const BYTE sec_id[] = {'h','t','t','p',':','t','e','s','t',1,0,0,0};
364 CHECK_EXPECT(GetRootSecurityId);
366 ok(!dwReserved, "dwReserved=%ld, expected 0\n", dwReserved);
367 ok(pbSecurityId != NULL, "pbSecurityId == NULL\n");
368 ok(pcbSecurityId != NULL, "pcbSecurityId == NULL\n");
371 ok(*pcbSecurityId == 512, "*pcbSecurityId=%d, expected 512\n", *pcbSecurityId);
372 *pcbSecurityId = sizeof(sec_id);
376 memcpy(pbSecurityId, sec_id, sizeof(sec_id));
381 static IHttpNegotiate2Vtbl HttpNegotiateVtbl = {
382 HttpNegotiate_QueryInterface,
383 HttpNegotiate_AddRef,
384 HttpNegotiate_Release,
385 HttpNegotiate_BeginningTransaction,
386 HttpNegotiate_OnResponse,
387 HttpNegotiate_GetRootSecurityId
390 static IHttpNegotiate2 http_negotiate = { &HttpNegotiateVtbl };
392 static HRESULT QueryInterface(REFIID,void**);
394 static HRESULT WINAPI ServiceProvider_QueryInterface(IServiceProvider *iface, REFIID riid, void **ppv)
396 return QueryInterface(riid, ppv);
399 static ULONG WINAPI ServiceProvider_AddRef(IServiceProvider *iface)
404 static ULONG WINAPI ServiceProvider_Release(IServiceProvider *iface)
409 static HRESULT WINAPI ServiceProvider_QueryService(IServiceProvider *iface, REFGUID guidService,
410 REFIID riid, void **ppv)
412 if(IsEqualGUID(&IID_IHttpNegotiate, guidService) || IsEqualGUID(&IID_IHttpNegotiate2, riid)) {
413 CHECK_EXPECT2(QueryService_HttpNegotiate);
414 return IHttpNegotiate2_QueryInterface(&http_negotiate, riid, ppv);
417 if(IsEqualGUID(&IID_IInternetProtocol, guidService)) {
418 ok(IsEqualGUID(&IID_IInternetProtocol, riid), "unexpected riid\n");
419 CHECK_EXPECT(QueryService_InternetProtocol);
420 return E_NOINTERFACE;
423 if(IsEqualGUID(&IID_IHttpSecurity, guidService)) {
424 ok(IsEqualGUID(&IID_IHttpSecurity, riid), "unexpected riid\n");
425 CHECK_EXPECT(QueryService_HttpSecurity);
426 return IHttpSecurity_QueryInterface(&http_security, riid, ppv);
429 ok(0, "unexpected service %s\n", debugstr_guid(guidService));
433 static const IServiceProviderVtbl ServiceProviderVtbl = {
434 ServiceProvider_QueryInterface,
435 ServiceProvider_AddRef,
436 ServiceProvider_Release,
437 ServiceProvider_QueryService
440 static IServiceProvider service_provider = { &ServiceProviderVtbl };
442 static HRESULT WINAPI Stream_QueryInterface(IStream *iface, REFIID riid, void **ppv)
444 ok(0, "unexpected call\n");
445 return E_NOINTERFACE;
448 static ULONG WINAPI Stream_AddRef(IStream *iface)
453 static ULONG WINAPI Stream_Release(IStream *iface)
458 static HRESULT WINAPI Stream_Read(IStream *iface, void *pv,
459 ULONG cb, ULONG *pcbRead)
461 CHECK_EXPECT2(Stream_Read);
463 ok(GetCurrentThreadId() != thread_id, "wrong thread %d\n", GetCurrentThreadId());
465 ok(pv != NULL, "pv == NULL\n");
466 ok(cb == 0x20000 || broken(cb == 0x2000), "cb = %d\n", cb);
467 ok(pcbRead != NULL, "pcbRead == NULL\n");
469 if(post_stream_read) {
474 memcpy(pv, post_data, sizeof(post_data)-1);
475 post_stream_read += *pcbRead = sizeof(post_data)-1;
479 static HRESULT WINAPI Stream_Write(IStream *iface, const void *pv,
480 ULONG cb, ULONG *pcbWritten)
482 ok(0, "unexpected call\n");
486 static HRESULT WINAPI Stream_Seek(IStream *iface, LARGE_INTEGER dlibMove,
487 DWORD dwOrigin, ULARGE_INTEGER *plibNewPosition)
489 CHECK_EXPECT(Stream_Seek);
491 ok(!dlibMove.QuadPart, "dlibMove != 0\n");
492 ok(dwOrigin == STREAM_SEEK_SET, "dwOrigin = %d\n", dwOrigin);
493 ok(!plibNewPosition, "plibNewPosition == NULL\n");
498 static HRESULT WINAPI Stream_SetSize(IStream *iface, ULARGE_INTEGER libNewSize)
500 ok(0, "unexpected call\n");
504 static HRESULT WINAPI Stream_CopyTo(IStream *iface, IStream *pstm,
505 ULARGE_INTEGER cb, ULARGE_INTEGER *pcbRead, ULARGE_INTEGER *pcbWritten)
507 ok(0, "unexpected call\n");
511 static HRESULT WINAPI Stream_Commit(IStream *iface, DWORD grfCommitFlags)
513 ok(0, "unexpected call\n");
517 static HRESULT WINAPI Stream_Revert(IStream *iface)
519 ok(0, "unexpected call\n");
523 static HRESULT WINAPI Stream_LockRegion(IStream *iface, ULARGE_INTEGER libOffset,
524 ULARGE_INTEGER cb, DWORD dwLockType)
526 ok(0, "unexpected call\n");
530 static HRESULT WINAPI Stream_UnlockRegion(IStream *iface,
531 ULARGE_INTEGER libOffset, ULARGE_INTEGER cb, DWORD dwLockType)
533 ok(0, "unexpected call\n");
537 static HRESULT WINAPI Stream_Stat(IStream *iface, STATSTG *pstatstg,
540 ok(0, "unexpected call\n");
544 static HRESULT WINAPI Stream_Clone(IStream *iface, IStream **ppstm)
546 ok(0, "unexpected call\n");
550 static const IStreamVtbl StreamVtbl = {
551 Stream_QueryInterface,
567 static IStream Stream = { &StreamVtbl };
569 static HRESULT WINAPI ProtocolSink_QueryInterface(IInternetProtocolSink *iface, REFIID riid, void **ppv)
571 return QueryInterface(riid, ppv);
574 static ULONG WINAPI ProtocolSink_AddRef(IInternetProtocolSink *iface)
579 static ULONG WINAPI ProtocolSink_Release(IInternetProtocolSink *iface)
584 static void call_continue(PROTOCOLDATA *protocol_data)
588 if(state == STATE_CONNECTING) {
589 if(tested_protocol == HTTP_TEST || tested_protocol == HTTPS_TEST)
590 CLEAR_CALLED(ReportProgress_COOKIE_SENT);
591 if(tested_protocol == HTTP_TEST || tested_protocol == HTTPS_TEST || tested_protocol == FTP_TEST) {
593 CLEAR_CALLED(ReportProgress_FINDINGRESOURCE);
594 CLEAR_CALLED(ReportProgress_CONNECTING);
595 CLEAR_CALLED(ReportProgress_PROXYDETECTING);
596 }else if(test_redirect) {
597 if (! proxy_active())
598 CHECK_CALLED(ReportProgress_FINDINGRESOURCE);
600 CLEAR_CALLED(ReportProgress_FINDINGRESOURCE);
602 CHECK_NOT_CALLED(ReportProgress_FINDINGRESOURCE);
603 /* IE7 does call this */
604 CLEAR_CALLED(ReportProgress_CONNECTING);
607 if(tested_protocol == FTP_TEST)
608 todo_wine CHECK_CALLED(ReportProgress_SENDINGREQUEST);
609 else if (tested_protocol != HTTPS_TEST)
610 CHECK_CALLED(ReportProgress_SENDINGREQUEST);
612 CHECK_CALLED(ReportProgress_REDIRECTING);
613 state = test_async_req ? STATE_SENDINGREQUEST : STATE_STARTDOWNLOADING;
617 case STATE_SENDINGREQUEST:
618 SET_EXPECT(Stream_Read);
619 SET_EXPECT(ReportProgress_SENDINGREQUEST);
621 case STATE_STARTDOWNLOADING:
622 if(tested_protocol == HTTP_TEST || tested_protocol == HTTPS_TEST) {
623 SET_EXPECT(OnResponse);
624 if(tested_protocol == HTTPS_TEST || test_redirect || test_abort)
625 SET_EXPECT(ReportProgress_ACCEPTRANGES);
626 SET_EXPECT(ReportProgress_MIMETYPEAVAILABLE);
627 if(bindf & BINDF_NEEDFILE)
628 SET_EXPECT(ReportProgress_CACHEFILENAMEAVAILABLE);
634 if(state != STATE_SENDINGREQUEST)
635 SET_EXPECT(ReportData);
636 hres = IInternetProtocol_Continue(async_protocol, protocol_data);
637 ok(hres == S_OK, "Continue failed: %08x\n", hres);
638 if(tested_protocol == FTP_TEST || security_problem)
639 CLEAR_CALLED(ReportData);
640 else if(state != STATE_SENDINGREQUEST)
641 CHECK_CALLED(ReportData);
644 case STATE_SENDINGREQUEST:
645 CHECK_CALLED(Stream_Read);
646 CHECK_CALLED(ReportProgress_SENDINGREQUEST);
647 state = STATE_STARTDOWNLOADING;
649 case STATE_STARTDOWNLOADING:
650 if (! security_problem)
652 state = STATE_DOWNLOADING;
653 if(tested_protocol == HTTP_TEST || tested_protocol == HTTPS_TEST) {
654 CHECK_CALLED(OnResponse);
655 if(tested_protocol == HTTPS_TEST || test_abort)
656 CHECK_CALLED(ReportProgress_ACCEPTRANGES);
657 else if(test_redirect)
658 CLEAR_CALLED(ReportProgress_ACCEPTRANGES);
659 CHECK_CALLED(ReportProgress_MIMETYPEAVAILABLE);
660 if(bindf & BINDF_NEEDFILE)
661 CHECK_CALLED(ReportProgress_CACHEFILENAMEAVAILABLE);
666 security_problem = FALSE;
667 SET_EXPECT(ReportProgress_CONNECTING);
674 static HRESULT WINAPI ProtocolSink_Switch(IInternetProtocolSink *iface, PROTOCOLDATA *pProtocolData)
676 if(tested_protocol == FTP_TEST)
677 CHECK_EXPECT2(Switch);
679 CHECK_EXPECT(Switch);
681 ok(pProtocolData != NULL, "pProtocolData == NULL\n");
683 ok(pProtocolData != &protocoldata, "pProtocolData == &protocoldata\n");
684 ok(pProtocolData->grfFlags == protocoldata.grfFlags, "grfFlags wrong %x/%x\n",
685 pProtocolData->grfFlags, protocoldata.grfFlags );
686 ok(pProtocolData->dwState == protocoldata.dwState, "dwState wrong %x/%x\n",
687 pProtocolData->dwState, protocoldata.dwState );
688 ok(pProtocolData->pData == protocoldata.pData, "pData wrong %p/%p\n",
689 pProtocolData->pData, protocoldata.pData );
690 ok(pProtocolData->cbData == protocoldata.cbData, "cbData wrong %x/%x\n",
691 pProtocolData->cbData, protocoldata.cbData );
694 pdata = pProtocolData;
697 SetEvent(event_complete);
698 WaitForSingleObject(event_complete2, INFINITE);
701 continue_protdata = *pProtocolData;
702 SetEvent(event_continue);
703 WaitForSingleObject(event_continue_done, INFINITE);
705 call_continue(pProtocolData);
706 SetEvent(event_complete);
712 static HRESULT WINAPI ProtocolSink_ReportProgress(IInternetProtocolSink *iface, ULONG ulStatusCode,
713 LPCWSTR szStatusText)
715 static const WCHAR null_guid[] = {'{','0','0','0','0','0','0','0','0','-','0','0','0','0','-',
716 '0','0','0','0','-','0','0','0','0','-','0','0','0','0','0','0','0','0','0','0','0','0','}',0};
717 static const WCHAR text_plain[] = {'t','e','x','t','/','p','l','a','i','n',0};
719 switch(ulStatusCode) {
720 case BINDSTATUS_MIMETYPEAVAILABLE:
721 CHECK_EXPECT(ReportProgress_MIMETYPEAVAILABLE);
722 if(tested_protocol != FILE_TEST && tested_protocol != ITS_TEST && !mimefilter_test && (pi & PI_MIMEVERIFICATION)) {
723 if(!short_read || !direct_read)
724 CHECK_CALLED(Read); /* set in Continue */
726 CHECK_CALLED(Read2); /* set in Read */
728 ok(szStatusText != NULL, "szStatusText == NULL\n");
730 if(tested_protocol == BIND_TEST)
731 ok(szStatusText == expect_wsz, "unexpected szStatusText\n");
732 else if (http_post_test)
733 ok(lstrlenW(text_plain) <= lstrlenW(szStatusText) &&
734 !memcmp(szStatusText, text_plain, lstrlenW(text_plain)*sizeof(WCHAR)),
735 "szStatusText != text/plain\n");
736 else if(!mimefilter_test)
737 ok(lstrlenW(text_htmlW) <= lstrlenW(szStatusText) &&
738 !memcmp(szStatusText, text_htmlW, lstrlenW(text_htmlW)*sizeof(WCHAR)),
739 "szStatusText != text/html\n");
742 case BINDSTATUS_DIRECTBIND:
743 CHECK_EXPECT2(ReportProgress_DIRECTBIND);
744 ok(szStatusText == NULL, "szStatusText != NULL\n");
746 case BINDSTATUS_RAWMIMETYPE:
747 CHECK_EXPECT2(ReportProgress_RAWMIMETYPE);
748 ok(szStatusText != NULL, "szStatusText == NULL\n");
750 ok(lstrlenW(szStatusText) < lstrlenW(text_htmlW) ||
751 !memcmp(szStatusText, text_htmlW, lstrlenW(text_htmlW)*sizeof(WCHAR)),
752 "szStatusText != text/html\n");
754 case BINDSTATUS_CACHEFILENAMEAVAILABLE:
755 CHECK_EXPECT(ReportProgress_CACHEFILENAMEAVAILABLE);
756 ok(szStatusText != NULL, "szStatusText == NULL\n");
759 ok(!lstrcmpW(szStatusText, expect_wsz), "unexpected szStatusText\n");
760 else if(tested_protocol == FILE_TEST)
761 ok(!lstrcmpW(szStatusText, file_name), "szStatusText = %s\n", wine_dbgstr_w(szStatusText));
763 ok(szStatusText != NULL, "szStatusText == NULL\n");
766 case BINDSTATUS_FINDINGRESOURCE:
767 CHECK_EXPECT2(ReportProgress_FINDINGRESOURCE);
768 ok(szStatusText != NULL, "szStatusText == NULL\n");
770 case BINDSTATUS_CONNECTING:
771 CHECK_EXPECT2(ReportProgress_CONNECTING);
772 ok(szStatusText != NULL, "szStatusText == NULL\n");
774 case BINDSTATUS_SENDINGREQUEST:
775 CHECK_EXPECT2(ReportProgress_SENDINGREQUEST);
776 if(tested_protocol == FILE_TEST || tested_protocol == ITS_TEST) {
777 ok(szStatusText != NULL, "szStatusText == NULL\n");
779 ok(!*szStatusText, "wrong szStatusText\n");
782 case BINDSTATUS_VERIFIEDMIMETYPEAVAILABLE:
783 CHECK_EXPECT(ReportProgress_VERIFIEDMIMETYPEAVAILABLE);
784 ok(szStatusText != NULL, "szStatusText == NULL\n");
786 ok(!lstrcmpW(szStatusText, text_htmlW), "szStatusText != text/html\n");
788 case BINDSTATUS_PROTOCOLCLASSID:
789 CHECK_EXPECT(ReportProgress_PROTOCOLCLASSID);
790 ok(szStatusText != NULL, "szStatusText == NULL\n");
791 ok(!lstrcmpW(szStatusText, null_guid), "unexpected classid %s\n", wine_dbgstr_w(szStatusText));
793 case BINDSTATUS_COOKIE_SENT:
794 CHECK_EXPECT(ReportProgress_COOKIE_SENT);
795 ok(szStatusText == NULL, "szStatusText != NULL\n");
797 case BINDSTATUS_REDIRECTING:
798 CHECK_EXPECT(ReportProgress_REDIRECTING);
800 ok(!strcmp_wa(szStatusText, "http://test.winehq.org/hello.html"), "szStatusText = %s\n", wine_dbgstr_w(szStatusText));
802 ok(szStatusText == NULL, "szStatusText = %s\n", wine_dbgstr_w(szStatusText));
804 case BINDSTATUS_ENCODING:
805 CHECK_EXPECT(ReportProgress_ENCODING);
806 ok(!strcmp_wa(szStatusText, "gzip"), "szStatusText = %s\n", wine_dbgstr_w(szStatusText));
808 case BINDSTATUS_ACCEPTRANGES:
809 CHECK_EXPECT(ReportProgress_ACCEPTRANGES);
810 ok(!szStatusText, "szStatusText = %s\n", wine_dbgstr_w(szStatusText));
812 case BINDSTATUS_PROXYDETECTING:
813 CHECK_EXPECT(ReportProgress_PROXYDETECTING);
814 SET_EXPECT(ReportProgress_CONNECTING);
815 ok(!szStatusText, "szStatusText = %s\n", wine_dbgstr_w(szStatusText));
817 case BINDSTATUS_LOADINGMIMEHANDLER:
818 CHECK_EXPECT(ReportProgress_LOADINGMIMEHANDLER);
819 ok(!szStatusText, "szStatusText = %s\n", wine_dbgstr_w(szStatusText));
821 case BINDSTATUS_DECODING:
822 CHECK_EXPECT(ReportProgress_DECODING);
823 ok(!lstrcmpW(szStatusText, gzipW), "szStatusText = %s\n", wine_dbgstr_w(szStatusText));
826 ok(0, "Unexpected status %d\n", ulStatusCode);
832 static HRESULT WINAPI ProtocolSink_ReportData(IInternetProtocolSink *iface, DWORD grfBSCF,
833 ULONG ulProgress, ULONG ulProgressMax)
837 static int rec_depth;
840 if(!mimefilter_test && (tested_protocol == FILE_TEST || tested_protocol == ITS_TEST)) {
841 CHECK_EXPECT2(ReportData);
843 ok(ulProgress == ulProgressMax, "ulProgress (%d) != ulProgressMax (%d)\n",
844 ulProgress, ulProgressMax);
845 ok(ulProgressMax == 13, "ulProgressMax=%d, expected 13\n", ulProgressMax);
846 /* BSCF_SKIPDRAINDATAFORFILEURLS added in IE8 */
847 if(tested_protocol == FILE_TEST)
848 ok((grfBSCF == (BSCF_FIRSTDATANOTIFICATION | BSCF_LASTDATANOTIFICATION)) ||
849 (grfBSCF == (BSCF_FIRSTDATANOTIFICATION | BSCF_LASTDATANOTIFICATION | BSCF_SKIPDRAINDATAFORFILEURLS)),
850 "grcfBSCF = %08x\n", grfBSCF);
852 ok(grfBSCF == (BSCF_FIRSTDATANOTIFICATION | BSCF_DATAFULLYAVAILABLE), "grcfBSCF = %08x\n", grfBSCF);
853 }else if(direct_read) {
857 if(!read_report_data && rec_depth == 1) {
858 BOOL reported_all_data = called_ReportData2;
860 CHECK_EXPECT2(ReportData);
863 ok(grfBSCF == (BSCF_FIRSTDATANOTIFICATION|BSCF_LASTDATANOTIFICATION|BSCF_DATAFULLYAVAILABLE)
864 || grfBSCF == BSCF_FIRSTDATANOTIFICATION, /* < IE8 */
865 "grcfBSCF = %08x\n", grfBSCF);
866 CHECK_CALLED(Read); /* Set in Continue */
867 first_data_notif = FALSE;
868 }else if(first_data_notif) {
869 ok(grfBSCF == BSCF_FIRSTDATANOTIFICATION, "grcfBSCF = %08x\n", grfBSCF);
870 first_data_notif = FALSE;
871 }else if(reported_all_data) {
872 ok(grfBSCF == (BSCF_LASTDATANOTIFICATION|BSCF_INTERMEDIATEDATANOTIFICATION),
873 "grcfBSCF = %08x\n", grfBSCF);
874 }else if(!direct_read) {
875 ok(grfBSCF == BSCF_INTERMEDIATEDATANOTIFICATION, "grcfBSCF = %08x\n", grfBSCF);
883 SET_EXPECT(ReportData2);
884 SET_EXPECT(ReportResult);
887 hres = IInternetProtocol_Read(binding_test ? binding_protocol : async_protocol, expect_pv = buf, sizeof(buf), &read);
888 ok(hres == E_PENDING || hres == S_FALSE || hres == S_OK, "Read failed: %08x\n", hres);
890 ok(read, "read == 0\n");
891 if(reported_all_data)
892 ok(hres == S_FALSE, "Read failed: %08x, expected S_FALSE\n", hres);
893 if(!emulate_prot && hres != E_PENDING)
894 CHECK_NOT_CALLED(Switch); /* otherwise checked in wait_for_switch loop */
897 if(!reported_all_data && called_ReportData2) {
899 CHECK_CALLED(ReportData2);
900 CHECK_CALLED(ReportResult);
901 ok(hres == S_OK, "Read failed: %08x\n", hres);
902 reported_all_data = TRUE;
905 CHECK_NOT_CALLED(ReportData2);
906 CHECK_NOT_CALLED(ReportResult);
908 }while(hres == S_OK);
910 wait_for_switch = FALSE;
912 CHECK_EXPECT(ReportData2);
914 ok(grfBSCF & BSCF_LASTDATANOTIFICATION, "grfBSCF = %08x\n", grfBSCF);
919 hres = IInternetProtocol_Read(binding_test ? binding_protocol : async_protocol, expect_pv = buf, sizeof(buf), &read);
922 ok(hres == S_FALSE, "Read returned: %08x, expected E_FALSE\n", hres);
923 ok(!read, "read = %d\n", read);
925 }else if(!binding_test && (tested_protocol == HTTP_TEST || tested_protocol == HTTPS_TEST
926 || tested_protocol == FTP_TEST)) {
927 if(!(grfBSCF & BSCF_LASTDATANOTIFICATION) || (grfBSCF & BSCF_DATAFULLYAVAILABLE))
928 CHECK_EXPECT(ReportData);
929 else if (http_post_test)
930 ok(ulProgress == 13, "Read %u bytes instead of 13\n", ulProgress);
932 ok(ulProgress, "ulProgress == 0\n");
934 if(first_data_notif) {
935 ok(grfBSCF == BSCF_FIRSTDATANOTIFICATION
936 || grfBSCF == (BSCF_LASTDATANOTIFICATION|BSCF_DATAFULLYAVAILABLE),
937 "grcfBSCF = %08x\n", grfBSCF);
938 first_data_notif = FALSE;
940 ok(grfBSCF == BSCF_INTERMEDIATEDATANOTIFICATION
941 || grfBSCF == (BSCF_LASTDATANOTIFICATION|BSCF_INTERMEDIATEDATANOTIFICATION)
942 || broken(grfBSCF == (BSCF_FIRSTDATANOTIFICATION|BSCF_LASTDATANOTIFICATION)),
943 "grcfBSCF = %08x\n", grfBSCF);
946 if(!(bindf & BINDF_FROMURLMON) &&
947 !(grfBSCF & BSCF_LASTDATANOTIFICATION)) {
948 if(state == STATE_CONNECTING) {
949 state = STATE_DOWNLOADING;
951 CHECK_CALLED(ReportProgress_FINDINGRESOURCE);
952 CHECK_CALLED(ReportProgress_CONNECTING);
954 CHECK_NOT_CALLED(ReportProgress_FINDINGRESOURCE);
955 CHECK_NOT_CALLED(ReportProgress_CONNECTING);
957 CHECK_CALLED(ReportProgress_SENDINGREQUEST);
958 CHECK_CALLED(OnResponse);
959 CHECK_CALLED(ReportProgress_RAWMIMETYPE);
961 SetEvent(event_complete);
963 }else if(!read_report_data) {
968 CHECK_EXPECT(ReportData);
970 if(tested_protocol != BIND_TEST) {
973 SET_EXPECT(MimeFilter_Read);
974 else if(rec_depth > 1)
978 hres = IInternetProtocol_Read(binding_protocol, expect_pv=buf, sizeof(buf), &read);
980 CHECK_CALLED(MimeFilter_Read);
981 else if(rec_depth > 1)
985 }while(hres == S_OK);
993 static HRESULT WINAPI ProtocolSink_ReportResult(IInternetProtocolSink *iface, HRESULT hrResult,
994 DWORD dwError, LPCWSTR szResult)
996 CHECK_EXPECT(ReportResult);
998 if(tested_protocol == FTP_TEST)
999 ok(hrResult == E_PENDING || hrResult == S_OK, "hrResult = %08x, expected E_PENDING or S_OK\n", hrResult);
1001 ok(hrResult == expect_hrResult, "hrResult = %08x, expected: %08x\n",
1002 hrResult, expect_hrResult);
1003 if(SUCCEEDED(hrResult) || tested_protocol == FTP_TEST || test_abort)
1004 ok(dwError == ERROR_SUCCESS, "dwError = %d, expected ERROR_SUCCESS\n", dwError);
1006 ok(dwError != ERROR_SUCCESS ||
1007 broken(tested_protocol == MK_TEST), /* WinME and NT4 */
1008 "dwError == ERROR_SUCCESS\n");
1009 ok(!szResult, "szResult != NULL\n");
1012 SET_EXPECT(ReportData); /* checked after main loop */
1017 static IInternetProtocolSinkVtbl protocol_sink_vtbl = {
1018 ProtocolSink_QueryInterface,
1019 ProtocolSink_AddRef,
1020 ProtocolSink_Release,
1021 ProtocolSink_Switch,
1022 ProtocolSink_ReportProgress,
1023 ProtocolSink_ReportData,
1024 ProtocolSink_ReportResult
1027 static IInternetProtocolSink protocol_sink = { &protocol_sink_vtbl };
1029 static HRESULT WINAPI MimeProtocolSink_QueryInterface(IInternetProtocolSink *iface, REFIID riid, void **ppv)
1031 ok(0, "unexpected call\n");
1035 static ULONG WINAPI MimeProtocolSink_AddRef(IInternetProtocolSink *iface)
1040 static ULONG WINAPI MimeProtocolSink_Release(IInternetProtocolSink *iface)
1045 static HRESULT WINAPI MimeProtocolSink_Switch(IInternetProtocolSink *iface, PROTOCOLDATA *pProtocolData)
1049 CHECK_EXPECT(MimeFilter_Switch);
1052 hres = IInternetProtocolSink_Switch(filtered_sink, pProtocolData);
1053 ok(hres == S_OK, "Switch failed: %08x\n", hres);
1054 CHECK_CALLED(Switch);
1059 static HRESULT WINAPI MimeProtocolSink_ReportProgress(IInternetProtocolSink *iface, ULONG ulStatusCode,
1060 LPCWSTR szStatusText)
1062 CHECK_EXPECT(MimeFilter_ReportProgress);
1066 static HRESULT WINAPI MimeProtocolSink_ReportData(IInternetProtocolSink *iface, DWORD grfBSCF,
1067 ULONG ulProgress, ULONG ulProgressMax)
1073 CHECK_EXPECT(MimeFilter_ReportData);
1077 hres = IInternetProtocol_Read(filtered_protocol, buf, sizeof(buf), &read);
1078 if(tested_protocol == HTTP_TEST)
1079 ok(hres == S_OK || hres == E_PENDING || hres == S_FALSE, "Read failed: %08x\n", hres);
1081 ok(hres == S_OK, "Read failed: %08x\n", hres);
1084 SET_EXPECT(ReportProgress_MIMETYPEAVAILABLE);
1085 hres = IInternetProtocolSink_ReportProgress(filtered_sink, BINDSTATUS_VERIFIEDMIMETYPEAVAILABLE, text_htmlW);
1086 ok(hres == S_OK, "ReportProgress failed: %08x\n", hres);
1087 CHECK_CALLED(ReportProgress_MIMETYPEAVAILABLE);
1089 /* FIXME: test BINDSTATUS_CACHEFILENAMEAVAILABLE */
1092 if(!read_report_data)
1093 SET_EXPECT(ReportData);
1094 hres = IInternetProtocolSink_ReportData(filtered_sink, grfBSCF, ulProgress, ulProgressMax);
1095 ok(hres == S_OK, "ReportData failed: %08x\n", hres);
1096 if(!read_report_data)
1097 CHECK_CALLED(ReportData);
1105 static HRESULT WINAPI MimeProtocolSink_ReportResult(IInternetProtocolSink *iface, HRESULT hrResult,
1106 DWORD dwError, LPCWSTR szResult)
1110 CHECK_EXPECT(MimeFilter_ReportResult);
1112 ok(hrResult == S_OK, "hrResult = %08x\n", hrResult);
1113 ok(dwError == ERROR_SUCCESS, "dwError = %u\n", dwError);
1114 ok(!szResult, "szResult = %s\n", wine_dbgstr_w(szResult));
1116 SET_EXPECT(ReportResult);
1117 hres = IInternetProtocolSink_ReportResult(filtered_sink, hrResult, dwError, szResult);
1118 ok(SUCCEEDED(hres), "ReportResult failed: %08x\n", hres);
1119 CHECK_CALLED(ReportResult);
1124 static IInternetProtocolSinkVtbl mime_protocol_sink_vtbl = {
1125 MimeProtocolSink_QueryInterface,
1126 MimeProtocolSink_AddRef,
1127 MimeProtocolSink_Release,
1128 MimeProtocolSink_Switch,
1129 MimeProtocolSink_ReportProgress,
1130 MimeProtocolSink_ReportData,
1131 MimeProtocolSink_ReportResult
1134 static IInternetProtocolSink mime_protocol_sink = { &mime_protocol_sink_vtbl };
1136 static HRESULT QueryInterface(REFIID riid, void **ppv)
1138 static const IID IID_undocumented = {0x58DFC7D0,0x5381,0x43E5,{0x9D,0x72,0x4C,0xDD,0xE4,0xCB,0x0F,0x1A}};
1142 if(IsEqualGUID(&IID_IUnknown, riid) || IsEqualGUID(&IID_IInternetProtocolSink, riid))
1143 *ppv = &protocol_sink;
1144 if(IsEqualGUID(&IID_IServiceProvider, riid))
1145 *ppv = &service_provider;
1146 if(IsEqualGUID(&IID_IUriContainer, riid))
1147 return E_NOINTERFACE; /* TODO */
1149 /* NOTE: IE8 queries for undocumented {58DFC7D0-5381-43E5-9D72-4CDDE4CB0F1A} interface. */
1150 if(IsEqualGUID(&IID_undocumented, riid))
1151 return E_NOINTERFACE;
1156 ok(0, "unexpected call %s\n", debugstr_guid(riid));
1157 return E_NOINTERFACE;
1160 static HRESULT WINAPI BindInfo_QueryInterface(IInternetBindInfo *iface, REFIID riid, void **ppv)
1162 if(IsEqualGUID(&IID_IUnknown, riid) || IsEqualGUID(&IID_IInternetBindInfo, riid)) {
1166 return E_NOINTERFACE;
1169 static ULONG WINAPI BindInfo_AddRef(IInternetBindInfo *iface)
1174 static ULONG WINAPI BindInfo_Release(IInternetBindInfo *iface)
1179 static HRESULT WINAPI BindInfo_GetBindInfo(IInternetBindInfo *iface, DWORD *grfBINDF, BINDINFO *pbindinfo)
1183 CHECK_EXPECT(GetBindInfo);
1185 ok(grfBINDF != NULL, "grfBINDF == NULL\n");
1186 ok(pbindinfo != NULL, "pbindinfo == NULL\n");
1187 ok(pbindinfo->cbSize == sizeof(BINDINFO), "wrong size of pbindinfo: %d\n", pbindinfo->cbSize);
1191 *grfBINDF |= BINDF_FROMURLMON;
1192 cbSize = pbindinfo->cbSize;
1193 memset(pbindinfo, 0, cbSize);
1194 pbindinfo->cbSize = cbSize;
1198 pbindinfo->cbstgmedData = sizeof(post_data)-1;
1199 pbindinfo->dwBindVerb = BINDVERB_POST;
1200 pbindinfo->stgmedData.tymed = http_post_test;
1202 if(http_post_test == TYMED_HGLOBAL) {
1205 /* Must be GMEM_FIXED, GMEM_MOVABLE does not work properly */
1206 data = GlobalAlloc(GPTR, sizeof(post_data));
1207 memcpy(data, post_data, sizeof(post_data));
1208 U(pbindinfo->stgmedData).hGlobal = data;
1210 IStream *post_stream;
1215 /* Must be GMEM_FIXED, GMEM_MOVABLE does not work properly */
1216 data = GlobalAlloc(GPTR, sizeof(post_data));
1217 memcpy(data, post_data, sizeof(post_data));
1218 U(pbindinfo->stgmedData).hGlobal = data;
1220 hres = CreateStreamOnHGlobal(data, FALSE, &post_stream);
1221 ok(hres == S_OK, "CreateStreamOnHGlobal failed: %08x\n", hres);
1223 U(pbindinfo->stgmedData).pstm =post_stream;/* &Stream; */
1225 U(pbindinfo->stgmedData).pstm = &Stream;
1232 static HRESULT WINAPI BindInfo_GetBindString(IInternetBindInfo *iface, ULONG ulStringType,
1233 LPOLESTR *ppwzStr, ULONG cEl, ULONG *pcElFetched)
1235 ok(ppwzStr != NULL, "ppwzStr == NULL\n");
1236 ok(pcElFetched != NULL, "pcElFetched == NULL\n");
1238 switch(ulStringType) {
1239 case BINDSTRING_ACCEPT_MIMES:
1240 CHECK_EXPECT(GetBindString_ACCEPT_MIMES);
1241 ok(cEl == 256, "cEl=%d, expected 256\n", cEl);
1243 ok(*pcElFetched == 256, "*pcElFetched=%d, expected 256\n", *pcElFetched);
1247 *ppwzStr = CoTaskMemAlloc(sizeof(acc_mimeW));
1248 memcpy(*ppwzStr, acc_mimeW, sizeof(acc_mimeW));
1251 case BINDSTRING_USER_AGENT:
1252 CHECK_EXPECT(GetBindString_USER_AGENT);
1253 ok(cEl == 1, "cEl=%d, expected 1\n", cEl);
1255 ok(*pcElFetched == 0, "*pcElFetch=%d, expectd 0\n", *pcElFetched);
1259 *ppwzStr = CoTaskMemAlloc(sizeof(user_agentW));
1260 memcpy(*ppwzStr, user_agentW, sizeof(user_agentW));
1263 case BINDSTRING_POST_COOKIE:
1264 CHECK_EXPECT(GetBindString_POST_COOKIE);
1265 ok(cEl == 1, "cEl=%d, expected 1\n", cEl);
1267 ok(*pcElFetched == 0, "*pcElFetch=%d, expectd 0\n", *pcElFetched);
1269 case BINDSTRING_URL: {
1272 CHECK_EXPECT(GetBindString_URL);
1273 ok(cEl == 1, "cEl=%d, expected 1\n", cEl);
1274 ok(*pcElFetched == 0, "*pcElFetch=%d, expectd 0\n", *pcElFetched);
1277 size = (lstrlenW(binding_urls[tested_protocol])+1)*sizeof(WCHAR);
1278 *ppwzStr = CoTaskMemAlloc(size);
1279 memcpy(*ppwzStr, binding_urls[tested_protocol], size);
1283 ok(0, "unexpected call\n");
1289 static IInternetBindInfoVtbl bind_info_vtbl = {
1290 BindInfo_QueryInterface,
1293 BindInfo_GetBindInfo,
1294 BindInfo_GetBindString
1297 static IInternetBindInfo bind_info = { &bind_info_vtbl };
1299 static HRESULT WINAPI InternetPriority_QueryInterface(IInternetPriority *iface,
1300 REFIID riid, void **ppv)
1302 ok(0, "unexpected call\n");
1303 return E_NOINTERFACE;
1306 static ULONG WINAPI InternetPriority_AddRef(IInternetPriority *iface)
1311 static ULONG WINAPI InternetPriority_Release(IInternetPriority *iface)
1316 static HRESULT WINAPI InternetPriority_SetPriority(IInternetPriority *iface, LONG nPriority)
1318 CHECK_EXPECT(SetPriority);
1319 ok(nPriority == ex_priority, "nPriority=%d\n", nPriority);
1323 static HRESULT WINAPI InternetPriority_GetPriority(IInternetPriority *iface, LONG *pnPriority)
1325 ok(0, "unexpected call\n");
1330 static const IInternetPriorityVtbl InternetPriorityVtbl = {
1331 InternetPriority_QueryInterface,
1332 InternetPriority_AddRef,
1333 InternetPriority_Release,
1334 InternetPriority_SetPriority,
1335 InternetPriority_GetPriority
1338 static IInternetPriority InternetPriority = { &InternetPriorityVtbl };
1340 static ULONG WINAPI Protocol_AddRef(IInternetProtocolEx *iface)
1345 static ULONG WINAPI Protocol_Release(IInternetProtocolEx *iface)
1350 static HRESULT WINAPI Protocol_Abort(IInternetProtocolEx *iface, HRESULT hrReason,
1355 CHECK_EXPECT(Abort);
1357 SET_EXPECT(ReportResult);
1358 hres = IInternetProtocolSink_ReportResult(binding_sink, S_OK, ERROR_SUCCESS, NULL);
1359 ok(hres == S_OK, "ReportResult failed: %08x\n", hres);
1360 CHECK_CALLED(ReportResult);
1365 static HRESULT WINAPI Protocol_Suspend(IInternetProtocolEx *iface)
1367 ok(0, "unexpected call\n");
1371 static HRESULT WINAPI Protocol_Resume(IInternetProtocolEx *iface)
1373 ok(0, "unexpected call\n");
1377 static HRESULT WINAPI Protocol_Seek(IInternetProtocolEx *iface,
1378 LARGE_INTEGER dlibMove, DWORD dwOrigin, ULARGE_INTEGER *plibNewPosition)
1380 ok(0, "unexpected call\n");
1384 static HRESULT WINAPI ProtocolEmul_QueryInterface(IInternetProtocolEx *iface, REFIID riid, void **ppv)
1386 if(IsEqualGUID(&IID_IUnknown, riid) || IsEqualGUID(&IID_IInternetProtocol, riid)) {
1391 if(IsEqualGUID(&IID_IInternetProtocolEx, riid)) {
1397 return E_NOINTERFACE;
1400 if(IsEqualGUID(&IID_IInternetPriority, riid)) {
1401 *ppv = &InternetPriority;
1405 if(IsEqualGUID(&IID_IWinInetInfo, riid)) {
1406 CHECK_EXPECT(QueryInterface_IWinInetInfo);
1408 return E_NOINTERFACE;
1411 if(IsEqualGUID(&IID_IWinInetHttpInfo, riid)) {
1412 CHECK_EXPECT(QueryInterface_IWinInetHttpInfo);
1414 return E_NOINTERFACE;
1417 ok(0, "unexpected riid %s\n", debugstr_guid(riid));
1419 return E_NOINTERFACE;
1422 static DWORD WINAPI thread_proc(PVOID arg)
1426 memset(&protocoldata, -1, sizeof(protocoldata));
1430 SET_EXPECT(ReportProgress_FINDINGRESOURCE);
1431 hres = IInternetProtocolSink_ReportProgress(binding_sink,
1432 BINDSTATUS_FINDINGRESOURCE, hostW);
1433 CHECK_CALLED(ReportProgress_FINDINGRESOURCE);
1434 ok(hres == S_OK, "ReportProgress failed: %08x\n", hres);
1436 SET_EXPECT(ReportProgress_CONNECTING);
1437 hres = IInternetProtocolSink_ReportProgress(binding_sink,
1438 BINDSTATUS_CONNECTING, winehq_ipW);
1439 CHECK_CALLED(ReportProgress_CONNECTING);
1440 ok(hres == S_OK, "ReportProgress failed: %08x\n", hres);
1442 SET_EXPECT(ReportProgress_SENDINGREQUEST);
1443 hres = IInternetProtocolSink_ReportProgress(binding_sink,
1444 BINDSTATUS_SENDINGREQUEST, NULL);
1445 CHECK_CALLED(ReportProgress_SENDINGREQUEST);
1446 ok(hres == S_OK, "ReportProgress failed: %08x\n", hres);
1450 hres = IInternetProtocolSink_Switch(binding_sink, &protocoldata);
1451 CHECK_CALLED(Switch);
1452 ok(hres == S_OK, "Switch failed: %08x\n", hres);
1457 SET_EXPECT(MimeFilter_Switch);
1460 hres = IInternetProtocolSink_Switch(binding_sink, &protocoldata);
1461 ok(hres == S_OK, "Switch failed: %08x\n", hres);
1463 CHECK_CALLED(MimeFilter_Switch);
1465 CHECK_CALLED(Switch);
1468 SetEvent(event_complete);
1474 SET_EXPECT(MimeFilter_Switch);
1477 hres = IInternetProtocolSink_Switch(binding_sink, &protocoldata);
1478 ok(hres == S_OK, "Switch failed: %08x\n", hres);
1480 CHECK_CALLED(MimeFilter_Switch);
1482 CHECK_CALLED(Switch);
1486 SET_EXPECT(MimeFilter_Switch);
1489 hres = IInternetProtocolSink_Switch(binding_sink, &protocoldata);
1490 ok(hres == S_OK, "Switch failed: %08x\n", hres);
1492 CHECK_CALLED(MimeFilter_Switch);
1494 CHECK_CALLED(Switch);
1497 SetEvent(event_complete);
1502 static void protocol_start(IInternetProtocolSink *pOIProtSink, IInternetBindInfo *pOIBindInfo, DWORD pi)
1504 BINDINFO bindinfo, exp_bindinfo;
1508 ok(pOIProtSink != NULL, "pOIProtSink == NULL\n");
1509 ok(pOIBindInfo != NULL, "pOIBindInfo == NULL\n");
1510 ok(pOIProtSink != &protocol_sink, "unexpected pOIProtSink\n");
1511 ok(pOIBindInfo != &bind_info, "unexpected pOIBindInfo\n");
1512 ok(!pi, "pi = %x\n", pi);
1515 ok(pOIProtSink == binding_sink, "pOIProtSink != binding_sink\n");
1517 memset(&bindinfo, 0, sizeof(bindinfo));
1518 bindinfo.cbSize = sizeof(bindinfo);
1519 memcpy(&exp_bindinfo, &bindinfo, sizeof(bindinfo));
1520 SET_EXPECT(GetBindInfo);
1521 hres = IInternetBindInfo_GetBindInfo(pOIBindInfo, &cbindf, &bindinfo);
1522 ok(hres == S_OK, "GetBindInfo failed: %08x\n", hres);
1523 CHECK_CALLED(GetBindInfo);
1524 ok(cbindf == (bindf|BINDF_FROMURLMON), "bindf = %x, expected %x\n",
1525 cbindf, (bindf|BINDF_FROMURLMON));
1526 ok(!memcmp(&exp_bindinfo, &bindinfo, sizeof(bindinfo)), "unexpected bindinfo\n");
1527 pReleaseBindInfo(&bindinfo);
1529 SET_EXPECT(ReportProgress_SENDINGREQUEST);
1530 hres = IInternetProtocolSink_ReportProgress(pOIProtSink, BINDSTATUS_SENDINGREQUEST, emptyW);
1531 ok(hres == S_OK, "ReportProgress(BINDSTATUS_SENDINGREQUEST) failed: %08x\n", hres);
1532 CHECK_CALLED(ReportProgress_SENDINGREQUEST);
1534 if(tested_protocol == HTTP_TEST || tested_protocol == HTTPS_TEST) {
1535 IServiceProvider *service_provider;
1536 IHttpNegotiate *http_negotiate;
1537 IHttpNegotiate2 *http_negotiate2;
1538 LPWSTR ua = (LPWSTR)0xdeadbeef, accept_mimes[256];
1539 LPWSTR additional_headers = NULL;
1541 DWORD fetched = 0, size = 100;
1544 SET_EXPECT(GetBindString_USER_AGENT);
1545 hres = IInternetBindInfo_GetBindString(pOIBindInfo, BINDSTRING_USER_AGENT,
1547 CHECK_CALLED(GetBindString_USER_AGENT);
1548 ok(hres == S_OK, "GetBindString(BINDSTRING_USER_AGETNT) failed: %08x\n", hres);
1549 ok(fetched == 1, "fetched = %d, expected 254\n", fetched);
1550 ok(ua != NULL, "ua = %p\n", ua);
1551 ok(!lstrcmpW(ua, user_agentW), "unexpected user agent %s\n", wine_dbgstr_w(ua));
1555 SET_EXPECT(GetBindString_ACCEPT_MIMES);
1556 hres = IInternetBindInfo_GetBindString(pOIBindInfo, BINDSTRING_ACCEPT_MIMES,
1557 accept_mimes, 256, &fetched);
1558 CHECK_CALLED(GetBindString_ACCEPT_MIMES);
1561 "GetBindString(BINDSTRING_ACCEPT_MIMES) failed: %08x\n", hres);
1562 ok(fetched == 1, "fetched = %d, expected 1\n", fetched);
1563 ok(!lstrcmpW(acc_mimeW, accept_mimes[0]), "unexpected mimes %s\n", wine_dbgstr_w(accept_mimes[0]));
1564 CoTaskMemFree(accept_mimes[0]);
1566 hres = IInternetBindInfo_QueryInterface(pOIBindInfo, &IID_IServiceProvider,
1567 (void**)&service_provider);
1568 ok(hres == S_OK, "QueryInterface failed: %08x\n", hres);
1570 SET_EXPECT(QueryService_HttpNegotiate);
1571 hres = IServiceProvider_QueryService(service_provider, &IID_IHttpNegotiate,
1572 &IID_IHttpNegotiate, (void**)&http_negotiate);
1573 CHECK_CALLED(QueryService_HttpNegotiate);
1574 ok(hres == S_OK, "QueryService failed: %08x\n", hres);
1576 SET_EXPECT(BeginningTransaction);
1577 hres = IHttpNegotiate_BeginningTransaction(http_negotiate, binding_urls[tested_protocol],
1578 NULL, 0, &additional_headers);
1579 CHECK_CALLED(BeginningTransaction);
1580 IHttpNegotiate_Release(http_negotiate);
1581 ok(hres == S_OK, "BeginningTransction failed: %08x\n", hres);
1582 ok(additional_headers == NULL, "additional_headers=%p\n", additional_headers);
1584 SET_EXPECT(QueryService_HttpNegotiate);
1585 hres = IServiceProvider_QueryService(service_provider, &IID_IHttpNegotiate2,
1586 &IID_IHttpNegotiate2, (void**)&http_negotiate2);
1587 CHECK_CALLED(QueryService_HttpNegotiate);
1588 ok(hres == S_OK, "QueryService failed: %08x\n", hres);
1591 SET_EXPECT(GetRootSecurityId);
1592 hres = IHttpNegotiate2_GetRootSecurityId(http_negotiate2, sec_id, &size, 0);
1593 CHECK_CALLED(GetRootSecurityId);
1594 IHttpNegotiate2_Release(http_negotiate2);
1595 ok(hres == E_FAIL, "GetRootSecurityId failed: %08x, expected E_FAIL\n", hres);
1596 ok(size == 13, "size=%d\n", size);
1598 IServiceProvider_Release(service_provider);
1600 CreateThread(NULL, 0, thread_proc, NULL, 0, &tid);
1604 SET_EXPECT(ReportProgress_CACHEFILENAMEAVAILABLE);
1605 hres = IInternetProtocolSink_ReportProgress(pOIProtSink,
1606 BINDSTATUS_CACHEFILENAMEAVAILABLE, expect_wsz = emptyW);
1607 ok(hres == S_OK, "ReportProgress(BINDSTATUS_CACHEFILENAMEAVAILABLE) failed: %08x\n", hres);
1608 CHECK_CALLED(ReportProgress_CACHEFILENAMEAVAILABLE);
1610 if(mimefilter_test) {
1611 SET_EXPECT(MimeFilter_CreateInstance);
1612 SET_EXPECT(MimeFilter_Start);
1613 SET_EXPECT(ReportProgress_LOADINGMIMEHANDLER);
1615 SET_EXPECT(ReportProgress_MIMETYPEAVAILABLE);
1616 hres = IInternetProtocolSink_ReportProgress(pOIProtSink, BINDSTATUS_VERIFIEDMIMETYPEAVAILABLE,
1617 mimefilter_test ? gzipW : (expect_wsz = text_htmlW));
1619 "ReportProgress(BINDSTATUS_VERIFIEDMIMETYPEAVAILABLE) failed: %08x\n", hres);
1620 if(mimefilter_test) {
1621 CHECK_CALLED(MimeFilter_CreateInstance);
1622 CHECK_CALLED(MimeFilter_Start);
1623 CHECK_CALLED(ReportProgress_LOADINGMIMEHANDLER);
1624 todo_wine CHECK_CALLED(ReportProgress_MIMETYPEAVAILABLE);
1626 CHECK_CALLED(ReportProgress_MIMETYPEAVAILABLE);
1630 SET_EXPECT(MimeFilter_ReportData);
1632 SET_EXPECT(ReportData);
1633 hres = IInternetProtocolSink_ReportData(pOIProtSink,
1634 BSCF_FIRSTDATANOTIFICATION | (tested_protocol == ITS_TEST ? BSCF_DATAFULLYAVAILABLE : BSCF_LASTDATANOTIFICATION),
1636 ok(hres == S_OK, "ReportData failed: %08x\n", hres);
1638 CHECK_CALLED(MimeFilter_ReportData);
1640 CHECK_CALLED(ReportData);
1642 if(tested_protocol == ITS_TEST) {
1643 SET_EXPECT(ReportData);
1644 hres = IInternetProtocolSink_ReportProgress(pOIProtSink, BINDSTATUS_BEGINDOWNLOADDATA, NULL);
1645 ok(hres == S_OK, "ReportProgress(BINDSTATUS_BEGINDOWNLOADDATA) failed: %08x\n", hres);
1646 CHECK_CALLED(ReportData);
1649 if(tested_protocol == BIND_TEST) {
1650 hres = IInternetProtocol_Terminate(binding_protocol, 0);
1651 ok(hres == E_FAIL, "Termiante failed: %08x\n", hres);
1655 SET_EXPECT(MimeFilter_ReportResult);
1657 SET_EXPECT(ReportResult);
1658 hres = IInternetProtocolSink_ReportResult(pOIProtSink, S_OK, 0, NULL);
1659 ok(hres == S_OK, "ReportResult failed: %08x\n", hres);
1661 CHECK_CALLED(MimeFilter_ReportResult);
1663 CHECK_CALLED(ReportResult);
1666 static HRESULT WINAPI ProtocolEmul_Start(IInternetProtocolEx *iface, LPCWSTR szUrl,
1667 IInternetProtocolSink *pOIProtSink, IInternetBindInfo *pOIBindInfo,
1668 DWORD grfPI, HANDLE_PTR dwReserved)
1670 CHECK_EXPECT(Start);
1672 ok(!dwReserved, "dwReserved = %lx\n", dwReserved);
1673 protocol_start(pOIProtSink, pOIBindInfo, grfPI);
1677 static HRESULT WINAPI ProtocolEmul_Continue(IInternetProtocolEx *iface,
1678 PROTOCOLDATA *pProtocolData)
1683 CHECK_EXPECT(Continue);
1685 ok(pProtocolData != NULL, "pProtocolData == NULL\n");
1686 if(!pProtocolData || tested_protocol == BIND_TEST)
1689 ok(pProtocolData != &protocoldata, "pProtocolData == &protocoldata\n");
1690 ok(pProtocolData->grfFlags == protocoldata.grfFlags, "grfFlags wrong %x/%x\n",
1691 pProtocolData->grfFlags, protocoldata.grfFlags );
1692 ok(pProtocolData->dwState == protocoldata.dwState, "dwState wrong %x/%x\n",
1693 pProtocolData->dwState, protocoldata.dwState );
1694 ok(pProtocolData->pData == protocoldata.pData, "pData wrong %p/%p\n",
1695 pProtocolData->pData, protocoldata.pData );
1696 ok(pProtocolData->cbData == protocoldata.cbData, "cbData wrong %x/%x\n",
1697 pProtocolData->cbData, protocoldata.cbData );
1700 switch(prot_state) {
1702 IServiceProvider *service_provider;
1703 IHttpNegotiate *http_negotiate;
1704 static WCHAR header[] = {'?',0};
1706 hres = IInternetProtocolSink_QueryInterface(binding_sink, &IID_IServiceProvider,
1707 (void**)&service_provider);
1708 ok(hres == S_OK, "Could not get IServiceProvicder\n");
1710 SET_EXPECT(QueryService_HttpNegotiate);
1711 hres = IServiceProvider_QueryService(service_provider, &IID_IHttpNegotiate,
1712 &IID_IHttpNegotiate, (void**)&http_negotiate);
1713 IServiceProvider_Release(service_provider);
1714 CHECK_CALLED(QueryService_HttpNegotiate);
1715 ok(hres == S_OK, "Could not get IHttpNegotiate\n");
1717 SET_EXPECT(OnResponse);
1718 hres = IHttpNegotiate_OnResponse(http_negotiate, 200, header, NULL, NULL);
1719 IHttpNegotiate_Release(http_negotiate);
1720 CHECK_CALLED(OnResponse);
1721 IHttpNegotiate_Release(http_negotiate);
1722 ok(hres == S_OK, "OnResponse failed: %08x\n", hres);
1724 if(mimefilter_test) {
1725 SET_EXPECT(MimeFilter_CreateInstance);
1726 SET_EXPECT(MimeFilter_Start);
1727 SET_EXPECT(ReportProgress_LOADINGMIMEHANDLER);
1728 }else if(!(pi & PI_MIMEVERIFICATION)) {
1729 SET_EXPECT(ReportProgress_MIMETYPEAVAILABLE);
1731 hres = IInternetProtocolSink_ReportProgress(binding_sink,
1732 BINDSTATUS_MIMETYPEAVAILABLE, mimefilter_test ? gzipW : text_htmlW);
1733 if(mimefilter_test) {
1734 CHECK_CALLED(MimeFilter_CreateInstance);
1735 CHECK_CALLED(MimeFilter_Start);
1736 CHECK_CALLED(ReportProgress_LOADINGMIMEHANDLER);
1737 }else if(!(pi & PI_MIMEVERIFICATION)) {
1738 CHECK_CALLED(ReportProgress_MIMETYPEAVAILABLE);
1741 "ReportProgress(BINDSTATUS_MIMETYPEAVAILABLE) failed: %08x\n", hres);
1743 bscf |= BSCF_FIRSTDATANOTIFICATION;
1748 bscf = BSCF_INTERMEDIATEDATANOTIFICATION;
1753 if(mimefilter_test) {
1754 SET_EXPECT(MimeFilter_ReportData);
1755 }else if(pi & PI_MIMEVERIFICATION) {
1757 SET_EXPECT(Read); /* checked in ReportData for short_read */
1759 if(!mimefilter_test)
1760 SET_EXPECT(Read); /* checked in BINDSTATUS_MIMETYPEAVAILABLE or ReportData */
1761 SET_EXPECT(ReportProgress_MIMETYPEAVAILABLE);
1764 SET_EXPECT(ReportData);
1766 SET_EXPECT(ReportData);
1769 hres = IInternetProtocolSink_ReportData(binding_sink, bscf, pr, 400);
1770 ok(hres == S_OK, "ReportData failed: %08x\n", hres);
1772 if(mimefilter_test) {
1773 SET_EXPECT(MimeFilter_ReportData);
1774 }else if(pi & PI_MIMEVERIFICATION) {
1775 if(!short_read && pr < 200)
1778 CHECK_CALLED(ReportProgress_MIMETYPEAVAILABLE);
1781 CHECK_CALLED(ReportData);
1790 static HRESULT WINAPI ProtocolEmul_Terminate(IInternetProtocolEx *iface, DWORD dwOptions)
1792 CHECK_EXPECT(Terminate);
1793 ok(!dwOptions, "dwOptions=%d\n", dwOptions);
1797 static HRESULT WINAPI ProtocolEmul_Read(IInternetProtocolEx *iface, void *pv,
1798 ULONG cb, ULONG *pcbRead)
1800 if(read_report_data)
1801 CHECK_EXPECT2(Read2);
1803 if(mimefilter_test || short_read) {
1804 if(!read_report_data)
1805 CHECK_EXPECT2(Read);
1806 }else if((pi & PI_MIMEVERIFICATION)) {
1807 if(!read_report_data)
1808 CHECK_EXPECT2(Read);
1810 if(prot_read < 300) {
1811 ok(pv != expect_pv, "pv == expect_pv\n");
1813 ok(cb == 2048-prot_read, "cb=%d\n", cb);
1815 ok(cb == 700, "cb=%d\n", cb);
1817 ok(expect_pv <= pv && (BYTE*)pv < (BYTE*)expect_pv + cb, "pv != expect_pv\n");
1820 if(!read_report_data)
1823 ok(pv == expect_pv, "pv != expect_pv\n");
1824 ok(cb == 1000, "cb=%d\n", cb);
1825 ok(!*pcbRead, "*pcbRead = %d\n", *pcbRead);
1827 ok(pcbRead != NULL, "pcbRead == NULL\n");
1829 if(prot_state == 3 || (short_read && prot_state != 4)) {
1834 SET_EXPECT(Read2); /* checked in BINDSTATUS_MIMETYPEAVAILABLE */
1835 SET_EXPECT(ReportProgress_MIMETYPEAVAILABLE);
1838 SET_EXPECT(MimeFilter_ReportData);
1839 else if(direct_read)
1840 SET_EXPECT(ReportData2);
1842 hres = IInternetProtocolSink_ReportData(binding_sink,
1843 BSCF_LASTDATANOTIFICATION|BSCF_INTERMEDIATEDATANOTIFICATION, 0, 0);
1845 ok(hres == S_OK, "ReportData failed: %08x\n", hres);
1847 CHECK_CALLED(ReportProgress_MIMETYPEAVAILABLE);
1849 CHECK_CALLED(MimeFilter_ReportData);
1850 else if(direct_read)
1851 CHECK_CALLED(ReportData2);
1854 SET_EXPECT(MimeFilter_ReportResult);
1856 SET_EXPECT(ReportResult);
1857 hres = IInternetProtocolSink_ReportResult(binding_sink, S_OK, ERROR_SUCCESS, NULL);
1858 ok(hres == S_OK, "ReportResult failed: %08x\n", hres);
1860 CHECK_CALLED(MimeFilter_ReportResult);
1862 CHECK_CALLED(ReportResult);
1864 memset(pv, 'x', 100);
1865 prot_read += *pcbRead = 100;
1867 }if(prot_state == 4) {
1872 if((async_read_pending = !async_read_pending)) {
1874 return tested_protocol == HTTP_TEST || tested_protocol == HTTPS_TEST ? E_PENDING : S_FALSE;
1877 memset(pv, 'x', 100);
1878 prot_read += *pcbRead = 100;
1882 static HRESULT WINAPI ProtocolEmul_LockRequest(IInternetProtocolEx *iface, DWORD dwOptions)
1884 CHECK_EXPECT(LockRequest);
1885 ok(dwOptions == 0, "dwOptions=%x\n", dwOptions);
1889 static HRESULT WINAPI ProtocolEmul_UnlockRequest(IInternetProtocolEx *iface)
1891 CHECK_EXPECT(UnlockRequest);
1895 static HRESULT WINAPI ProtocolEmul_StartEx(IInternetProtocolEx *iface, IUri *pUri,
1896 IInternetProtocolSink *pOIProtSink, IInternetBindInfo *pOIBindInfo,
1897 DWORD grfPI, HANDLE *dwReserved)
1899 CHECK_EXPECT(StartEx);
1900 ok(!dwReserved, "dwReserved = %p\n", dwReserved);
1901 protocol_start(pOIProtSink, pOIBindInfo, grfPI);
1905 static const IInternetProtocolExVtbl ProtocolVtbl = {
1906 ProtocolEmul_QueryInterface,
1910 ProtocolEmul_Continue,
1912 ProtocolEmul_Terminate,
1917 ProtocolEmul_LockRequest,
1918 ProtocolEmul_UnlockRequest,
1919 ProtocolEmul_StartEx
1922 static IInternetProtocolEx Protocol = { &ProtocolVtbl };
1924 static HRESULT WINAPI MimeProtocol_QueryInterface(IInternetProtocolEx *iface, REFIID riid, void **ppv)
1926 if(IsEqualGUID(&IID_IUnknown, riid) || IsEqualGUID(&IID_IInternetProtocol, riid)) {
1931 if(IsEqualGUID(&IID_IInternetProtocolSink, riid)) {
1932 *ppv = &mime_protocol_sink;
1936 ok(0, "unexpected riid %s\n", debugstr_guid(riid));
1938 return E_NOINTERFACE;
1941 static HRESULT WINAPI MimeProtocol_Start(IInternetProtocolEx *iface, LPCWSTR szUrl,
1942 IInternetProtocolSink *pOIProtSink, IInternetBindInfo *pOIBindInfo,
1943 DWORD grfPI, HANDLE_PTR dwReserved)
1945 PROTOCOLFILTERDATA *data;
1946 LPOLESTR url_str = NULL;
1952 CHECK_EXPECT(MimeFilter_Start);
1954 ok(!lstrcmpW(szUrl, gzipW), "wrong url %s\n", wine_dbgstr_w(szUrl));
1955 ok(grfPI == (PI_FILTER_MODE|PI_FORCE_ASYNC), "grfPI=%x, expected PI_FILTER_MODE|PI_FORCE_ASYNC\n", grfPI);
1956 ok(dwReserved, "dwReserved == 0\n");
1957 ok(pOIProtSink != NULL, "pOIProtSink == NULL\n");
1958 ok(pOIBindInfo != NULL, "pOIBindInfo == NULL\n");
1961 ok(pOIProtSink != binding_sink, "pOIProtSink == protocol_sink\n");
1962 ok(pOIBindInfo == prot_bind_info, "pOIBindInfo != bind_info\n");
1964 ok(pOIProtSink == &protocol_sink, "pOIProtSink != protocol_sink\n");
1965 ok(pOIBindInfo == &bind_info, "pOIBindInfo != bind_info\n");
1968 data = (void*)dwReserved;
1969 ok(data->cbSize == sizeof(*data), "data->cbSize = %d\n", data->cbSize);
1970 ok(!data->pProtocolSink, "data->pProtocolSink != NULL\n");
1971 ok(data->pProtocol != NULL, "data->pProtocol == NULL\n");
1972 ok(!data->pUnk, "data->pUnk != NULL\n");
1973 ok(!data->dwFilterFlags, "data->dwProtocolFlags = %x\n", data->dwFilterFlags);
1975 IInternetProtocolSink *prot_sink;
1977 IInternetProtocol_QueryInterface(data->pProtocol, &IID_IInternetProtocolSink, (void**)&prot_sink);
1978 ok(prot_sink == pOIProtSink, "QI(data->pProtocol, IID_IInternetProtocolSink) != pOIProtSink\n");
1979 IInternetProtocolSink_Release(prot_sink);
1981 ok(data->pProtocol != binding_protocol, "data->pProtocol == binding_protocol\n");
1983 filtered_protocol = data->pProtocol;
1984 IInternetProtocol_AddRef(filtered_protocol);
1986 IInternetProtocol *prot;
1988 IInternetProtocol_QueryInterface(data->pProtocol, &IID_IInternetProtocol, (void**)&prot);
1989 ok(prot == async_protocol, "QI(data->pProtocol, IID_IInternetProtocol) != async_protocol\n");
1990 IInternetProtocol_Release(prot);
1992 ok(data->pProtocol != async_protocol, "data->pProtocol == async_protocol\n");
1995 filtered_sink = pOIProtSink;
1997 SET_EXPECT(ReportProgress_DECODING);
1998 hres = IInternetProtocolSink_ReportProgress(pOIProtSink, BINDSTATUS_DECODING, gzipW);
1999 ok(hres == S_OK, "ReportProgress(BINDSTATUS_DECODING) failed: %08x\n", hres);
2000 CHECK_CALLED(ReportProgress_DECODING);
2002 SET_EXPECT(GetBindInfo);
2003 memset(&bindinfo, 0, sizeof(bindinfo));
2004 bindinfo.cbSize = sizeof(bindinfo);
2005 hres = IInternetBindInfo_GetBindInfo(pOIBindInfo, &cbindf, &bindinfo);
2006 ok(hres == S_OK, "GetBindInfo failed: %08x\n", hres);
2007 ok(cbindf == (bindf|BINDF_FROMURLMON), "cbindf = %x, expected %x\n", cbindf, bindf);
2008 CHECK_CALLED(GetBindInfo);
2010 SET_EXPECT(GetBindString_URL);
2011 hres = IInternetBindInfo_GetBindString(pOIBindInfo, BINDSTRING_URL, &url_str, 1, &fetched);
2012 ok(hres == S_OK, "GetBindString(BINDSTRING_URL) failed: %08x\n", hres);
2013 ok(fetched == 1, "fetched = %d\n", fetched);
2014 ok(!lstrcmpW(url_str, binding_urls[tested_protocol]), "wrong url_str %s\n", wine_dbgstr_w(url_str));
2015 CoTaskMemFree(url_str);
2016 CHECK_CALLED(GetBindString_URL);
2021 static HRESULT WINAPI Protocol_Continue(IInternetProtocolEx *iface,
2022 PROTOCOLDATA *pProtocolData)
2024 CHECK_EXPECT(MimeFilter_Continue);
2028 static HRESULT WINAPI MimeProtocol_Terminate(IInternetProtocolEx *iface, DWORD dwOptions)
2032 CHECK_EXPECT(MimeFilter_Terminate);
2034 ok(!dwOptions, "dwOptions = %x\n", dwOptions);
2036 SET_EXPECT(Terminate);
2037 hres = IInternetProtocol_Terminate(filtered_protocol, dwOptions);
2038 ok(hres == S_OK, "Terminate failed: %08x\n", hres);
2039 CHECK_CALLED(Terminate);
2044 static HRESULT WINAPI MimeProtocol_Read(IInternetProtocolEx *iface, void *pv,
2045 ULONG cb, ULONG *pcbRead)
2051 CHECK_EXPECT(MimeFilter_Read);
2053 ok(pv != NULL, "pv == NULL\n");
2054 ok(cb != 0, "cb == 0\n");
2055 ok(pcbRead != NULL, "pcbRead == NULL\n");
2057 if(read_report_data)
2061 hres = IInternetProtocol_Read(filtered_protocol, buf, sizeof(buf), &read);
2062 ok(hres == S_OK || hres == S_FALSE || hres == E_PENDING, "Read failed: %08x\n", hres);
2063 if(read_report_data)
2064 CHECK_CALLED(Read2);
2069 ok(*pcbRead == 0, "*pcbRead=%d, expected 0\n", *pcbRead);
2073 memset(pv, 'x', read);
2077 static HRESULT WINAPI MimeProtocol_LockRequest(IInternetProtocolEx *iface, DWORD dwOptions)
2081 CHECK_EXPECT(MimeFilter_LockRequest);
2083 ok(!dwOptions, "dwOptions = %x\n", dwOptions);
2085 SET_EXPECT(LockRequest);
2086 hres = IInternetProtocol_LockRequest(filtered_protocol, dwOptions);
2087 ok(hres == S_OK, "LockRequest failed: %08x\n", hres);
2088 CHECK_CALLED(LockRequest);
2093 static HRESULT WINAPI MimeProtocol_UnlockRequest(IInternetProtocolEx *iface)
2097 CHECK_EXPECT(MimeFilter_UnlockRequest);
2099 SET_EXPECT(UnlockRequest);
2100 hres = IInternetProtocol_UnlockRequest(filtered_protocol);
2101 ok(hres == S_OK, "UnlockRequest failed: %08x\n", hres);
2102 CHECK_CALLED(UnlockRequest);
2107 static const IInternetProtocolExVtbl MimeProtocolVtbl = {
2108 MimeProtocol_QueryInterface,
2114 MimeProtocol_Terminate,
2119 MimeProtocol_LockRequest,
2120 MimeProtocol_UnlockRequest
2123 static IInternetProtocolEx MimeProtocol = { &MimeProtocolVtbl };
2125 static HRESULT WINAPI ClassFactory_QueryInterface(IClassFactory *iface, REFIID riid, void **ppv)
2127 ok(0, "unexpected call\n");
2128 return E_NOINTERFACE;
2131 static ULONG WINAPI ClassFactory_AddRef(IClassFactory *iface)
2136 static ULONG WINAPI ClassFactory_Release(IClassFactory *iface)
2141 static HRESULT WINAPI ClassFactory_CreateInstance(IClassFactory *iface, IUnknown *pOuter,
2142 REFIID riid, void **ppv)
2144 CHECK_EXPECT(CreateInstance);
2146 ok(pOuter == (IUnknown*)prot_bind_info, "pOuter != protocol_unk\n");
2147 ok(IsEqualGUID(&IID_IUnknown, riid), "unexpected riid %s\n", debugstr_guid(riid));
2148 ok(ppv != NULL, "ppv == NULL\n");
2154 static HRESULT WINAPI ClassFactory_LockServer(IClassFactory *iface, BOOL dolock)
2156 ok(0, "unexpected call\n");
2160 static const IClassFactoryVtbl ClassFactoryVtbl = {
2161 ClassFactory_QueryInterface,
2162 ClassFactory_AddRef,
2163 ClassFactory_Release,
2164 ClassFactory_CreateInstance,
2165 ClassFactory_LockServer
2168 static IClassFactory ClassFactory = { &ClassFactoryVtbl };
2170 static HRESULT WINAPI MimeFilter_CreateInstance(IClassFactory *iface, IUnknown *outer, REFIID riid, void **ppv)
2172 CHECK_EXPECT(MimeFilter_CreateInstance);
2174 ok(!outer, "outer = %p\n", outer);
2175 ok(IsEqualGUID(&IID_IInternetProtocol, riid), "unexpected riid %s\n", debugstr_guid(riid));
2177 *ppv = &MimeProtocol;
2181 static const IClassFactoryVtbl MimeFilterCFVtbl = {
2182 ClassFactory_QueryInterface,
2183 ClassFactory_AddRef,
2184 ClassFactory_Release,
2185 MimeFilter_CreateInstance,
2186 ClassFactory_LockServer
2189 static IClassFactory mimefilter_cf = { &MimeFilterCFVtbl };
2191 #define TEST_BINDING 0x0001
2192 #define TEST_FILTER 0x0002
2193 #define TEST_FIRST_HTTP 0x0004
2194 #define TEST_DIRECT_READ 0x0008
2195 #define TEST_POST 0x0010
2196 #define TEST_EMULATEPROT 0x0020
2197 #define TEST_SHORT_READ 0x0040
2198 #define TEST_REDIRECT 0x0080
2199 #define TEST_ABORT 0x0100
2200 #define TEST_ASYNCREQ 0x0200
2201 #define TEST_USEIURI 0x0400
2202 #define TEST_IMPLPROTEX 0x0800
2204 static void register_filter(BOOL do_register)
2206 IInternetSession *session;
2209 static const WCHAR gzipW[] = {'g','z','i','p',0};
2211 hres = pCoInternetGetSession(0, &session, 0);
2212 ok(hres == S_OK, "CoInternetGetSession failed: %08x\n", hres);
2215 hres = IInternetSession_RegisterMimeFilter(session, &mimefilter_cf, &IID_IInternetProtocol, gzipW);
2216 ok(hres == S_OK, "RegisterMimeFilter failed: %08x\n", hres);
2218 hres = IInternetSession_UnregisterMimeFilter(session, &mimefilter_cf, gzipW);
2219 ok(hres == S_OK, "RegisterMimeFilter failed: %08x\n", hres);
2222 IInternetSession_Release(session);
2225 static void init_test(int prot, DWORD flags)
2227 tested_protocol = prot;
2228 binding_test = (flags & TEST_BINDING) != 0;
2229 first_data_notif = TRUE;
2232 async_read_pending = TRUE;
2233 mimefilter_test = (flags & TEST_FILTER) != 0;
2235 post_stream_read = 0;
2236 ResetEvent(event_complete);
2237 ResetEvent(event_complete2);
2238 ResetEvent(event_continue);
2239 ResetEvent(event_continue_done);
2240 async_protocol = binding_protocol = filtered_protocol = NULL;
2241 filtered_sink = NULL;
2242 http_is_first = (flags & TEST_FIRST_HTTP) != 0;
2243 first_data_notif = TRUE;
2244 state = STATE_CONNECTING;
2245 test_async_req = (flags & TEST_ASYNCREQ) != 0;
2246 direct_read = (flags & TEST_DIRECT_READ) != 0;
2247 emulate_prot = (flags & TEST_EMULATEPROT) != 0;
2248 wait_for_switch = TRUE;
2249 short_read = (flags & TEST_SHORT_READ) != 0;
2250 http_post_test = TYMED_NULL;
2251 test_redirect = (flags & TEST_REDIRECT) != 0;
2252 test_abort = (flags & TEST_ABORT) != 0;
2253 impl_protex = (flags & TEST_IMPLPROTEX) != 0;
2255 register_filter(mimefilter_test);
2258 static void test_priority(IInternetProtocol *protocol)
2260 IInternetPriority *priority;
2264 hres = IInternetProtocol_QueryInterface(protocol, &IID_IInternetPriority,
2266 ok(hres == S_OK, "QueryInterface(IID_IInternetPriority) failed: %08x\n", hres);
2270 hres = IInternetPriority_GetPriority(priority, &pr);
2271 ok(hres == S_OK, "GetPriority failed: %08x\n", hres);
2272 ok(pr == 0, "pr=%d, expected 0\n", pr);
2274 hres = IInternetPriority_SetPriority(priority, 1);
2275 ok(hres == S_OK, "SetPriority failed: %08x\n", hres);
2277 hres = IInternetPriority_GetPriority(priority, &pr);
2278 ok(hres == S_OK, "GetPriority failed: %08x\n", hres);
2279 ok(pr == 1, "pr=%d, expected 1\n", pr);
2281 IInternetPriority_Release(priority);
2284 static void test_early_abort(const CLSID *clsid)
2286 IInternetProtocol *protocol;
2289 hres = CoCreateInstance(clsid, NULL, CLSCTX_INPROC_SERVER|CLSCTX_INPROC_HANDLER,
2290 &IID_IInternetProtocol, (void**)&protocol);
2291 ok(hres == S_OK, "CoCreateInstance failed: %08x\n", hres);
2293 hres = IInternetProtocol_Abort(protocol, E_ABORT, 0);
2294 ok(hres == S_OK, "Abort failed: %08x\n", hres);
2296 hres = IInternetProtocol_Abort(protocol, E_FAIL, 0);
2297 ok(hres == S_OK, "Abort failed: %08x\n", hres);
2299 IInternetProtocol_Release(protocol);
2302 static BOOL file_protocol_start(IInternetProtocol *protocol, LPCWSTR url,
2303 IInternetProtocolEx *protocolex, IUri *uri, BOOL is_first)
2307 SET_EXPECT(GetBindInfo);
2308 if(!(bindf & BINDF_FROMURLMON))
2309 SET_EXPECT(ReportProgress_DIRECTBIND);
2311 SET_EXPECT(ReportProgress_SENDINGREQUEST);
2312 SET_EXPECT(ReportProgress_CACHEFILENAMEAVAILABLE);
2313 if(bindf & BINDF_FROMURLMON)
2314 SET_EXPECT(ReportProgress_VERIFIEDMIMETYPEAVAILABLE);
2316 SET_EXPECT(ReportProgress_MIMETYPEAVAILABLE);
2318 SET_EXPECT(ReportData);
2320 SET_EXPECT(ReportResult);
2322 expect_hrResult = S_OK;
2325 hres = IInternetProtocolEx_StartEx(protocolex, uri, &protocol_sink, &bind_info, 0, 0);
2326 ok(hres == S_OK, "StartEx failed: %08x\n", hres);
2328 hres = IInternetProtocol_Start(protocol, url, &protocol_sink, &bind_info, 0, 0);
2329 if(hres == INET_E_RESOURCE_NOT_FOUND) {
2330 win_skip("Start failed\n");
2333 ok(hres == S_OK, "Start failed: %08x\n", hres);
2336 CHECK_CALLED(GetBindInfo);
2337 if(!(bindf & BINDF_FROMURLMON))
2338 CHECK_CALLED(ReportProgress_DIRECTBIND);
2340 CHECK_CALLED(ReportProgress_SENDINGREQUEST);
2341 CHECK_CALLED(ReportProgress_CACHEFILENAMEAVAILABLE);
2342 if(bindf & BINDF_FROMURLMON)
2343 CHECK_CALLED(ReportProgress_VERIFIEDMIMETYPEAVAILABLE);
2345 CHECK_CALLED(ReportProgress_MIMETYPEAVAILABLE);
2347 CHECK_CALLED(ReportData);
2349 CHECK_CALLED(ReportResult);
2354 static void test_file_protocol_url(LPCWSTR url)
2356 IInternetProtocolInfo *protocol_info;
2358 IClassFactory *factory;
2359 IInternetProtocol *protocol;
2364 hres = CoGetClassObject(&CLSID_FileProtocol, CLSCTX_INPROC_SERVER, NULL,
2365 &IID_IUnknown, (void**)&unk);
2366 ok(hres == S_OK, "CoGetClassObject failed: %08x\n", hres);
2370 hres = IUnknown_QueryInterface(unk, &IID_IInternetProtocolInfo, (void**)&protocol_info);
2371 ok(hres == E_NOINTERFACE,
2372 "Could not get IInternetProtocolInfo interface: %08x, expected E_NOINTERFACE\n", hres);
2374 hres = IUnknown_QueryInterface(unk, &IID_IClassFactory, (void**)&factory);
2375 ok(hres == S_OK, "Could not get IClassFactory interface\n");
2376 IUnknown_Release(unk);
2380 hres = IClassFactory_CreateInstance(factory, NULL, &IID_IInternetProtocol, (void**)&protocol);
2381 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_Read(protocol, buf, 2, &cb);
2386 ok(hres == S_OK, "Read failed: %08x\n", hres);
2387 ok(cb == 2, "cb=%u expected 2\n", cb);
2388 hres = IInternetProtocol_Read(protocol, buf, sizeof(buf), &cb);
2389 ok(hres == S_FALSE, "Read failed: %08x\n", hres);
2390 hres = IInternetProtocol_Read(protocol, buf, sizeof(buf), &cb);
2391 ok(hres == S_FALSE, "Read failed: %08x expected S_FALSE\n", hres);
2392 ok(cb == 0, "cb=%u expected 0\n", cb);
2393 hres = IInternetProtocol_UnlockRequest(protocol);
2394 ok(hres == S_OK, "UnlockRequest failed: %08x\n", hres);
2397 if(file_protocol_start(protocol, url, NULL, NULL, FALSE)) {
2398 hres = IInternetProtocol_Read(protocol, buf, 2, &cb);
2399 ok(hres == S_FALSE, "Read failed: %08x\n", hres);
2400 hres = IInternetProtocol_LockRequest(protocol, 0);
2401 ok(hres == S_OK, "LockRequest failed: %08x\n", hres);
2402 hres = IInternetProtocol_UnlockRequest(protocol);
2403 ok(hres == S_OK, "UnlockRequest failed: %08x\n", hres);
2406 IInternetProtocol_Release(protocol);
2409 hres = IClassFactory_CreateInstance(factory, NULL, &IID_IInternetProtocol, (void**)&protocol);
2410 ok(hres == S_OK, "Could not get IInternetProtocol: %08x\n", hres);
2411 if(SUCCEEDED(hres)) {
2412 if(file_protocol_start(protocol, url, NULL, NULL, TRUE)) {
2413 hres = IInternetProtocol_LockRequest(protocol, 0);
2414 ok(hres == S_OK, "LockRequest failed: %08x\n", hres);
2415 hres = IInternetProtocol_Terminate(protocol, 0);
2416 ok(hres == S_OK, "Terminate failed: %08x\n", hres);
2417 hres = IInternetProtocol_Read(protocol, buf, 2, &cb);
2418 ok(hres == S_OK, "Read failed: %08x\n\n", hres);
2419 hres = IInternetProtocol_UnlockRequest(protocol);
2420 ok(hres == S_OK, "UnlockRequest failed: %08x\n", hres);
2421 hres = IInternetProtocol_Read(protocol, buf, 2, &cb);
2422 ok(hres == S_OK, "Read failed: %08x\n", hres);
2423 hres = IInternetProtocol_Terminate(protocol, 0);
2424 ok(hres == S_OK, "Terminate failed: %08x\n", hres);
2427 IInternetProtocol_Release(protocol);
2430 hres = IClassFactory_CreateInstance(factory, NULL, &IID_IInternetProtocol, (void**)&protocol);
2431 ok(hres == S_OK, "Could not get IInternetProtocol: %08x\n", hres);
2432 if(SUCCEEDED(hres)) {
2433 if(file_protocol_start(protocol, url, NULL, NULL, TRUE)) {
2434 hres = IInternetProtocol_Terminate(protocol, 0);
2435 ok(hres == S_OK, "Terminate failed: %08x\n", hres);
2436 hres = IInternetProtocol_Read(protocol, buf, 2, &cb);
2437 ok(hres == S_OK, "Read failed: %08x\n", hres);
2438 ok(cb == 2, "cb=%u expected 2\n", cb);
2441 IInternetProtocol_Release(protocol);
2445 IInternetProtocolEx *protocolex;
2448 hres = pCreateUri(url, Uri_CREATE_FILE_USE_DOS_PATH, 0, &uri);
2449 ok(hres == S_OK, "CreateUri failed: %08x\n", hres);
2451 hres = IClassFactory_CreateInstance(factory, NULL, &IID_IInternetProtocolEx, (void**)&protocolex);
2452 ok(hres == S_OK, "Could not get IInternetProtocolEx: %08x\n", hres);
2454 if(file_protocol_start(NULL, NULL, protocolex, uri, TRUE)) {
2455 hres = IInternetProtocolEx_Read(protocolex, buf, 2, &cb);
2456 ok(hres == S_OK, "Read failed: %08x\n", hres);
2457 hres = IInternetProtocolEx_LockRequest(protocolex, 0);
2458 ok(hres == S_OK, "LockRequest failed: %08x\n", hres);
2459 hres = IInternetProtocolEx_UnlockRequest(protocolex);
2460 ok(hres == S_OK, "UnlockRequest failed: %08x\n", hres);
2464 IInternetProtocolEx_Release(protocolex);
2466 win_skip("Skipping file protocol StartEx tests\n");
2469 IClassFactory_Release(factory);
2472 static void test_file_protocol_fail(void)
2474 IInternetProtocol *protocol;
2477 static const WCHAR index_url2[] =
2478 {'f','i','l','e',':','/','/','i','n','d','e','x','.','h','t','m','l',0};
2480 hres = CoCreateInstance(&CLSID_FileProtocol, NULL, CLSCTX_INPROC_SERVER|CLSCTX_INPROC_HANDLER,
2481 &IID_IInternetProtocol, (void**)&protocol);
2482 ok(hres == S_OK, "CoCreateInstance failed: %08x\n", hres);
2486 SET_EXPECT(GetBindInfo);
2487 expect_hrResult = MK_E_SYNTAX;
2488 hres = IInternetProtocol_Start(protocol, wszIndexHtml, &protocol_sink, &bind_info, 0, 0);
2489 ok(hres == MK_E_SYNTAX ||
2490 hres == E_INVALIDARG,
2491 "Start failed: %08x, expected MK_E_SYNTAX or E_INVALIDARG\n", hres);
2492 CLEAR_CALLED(GetBindInfo); /* GetBindInfo not called in IE7 */
2494 SET_EXPECT(GetBindInfo);
2495 if(!(bindf & BINDF_FROMURLMON))
2496 SET_EXPECT(ReportProgress_DIRECTBIND);
2497 SET_EXPECT(ReportProgress_SENDINGREQUEST);
2498 SET_EXPECT(ReportResult);
2499 expect_hrResult = INET_E_RESOURCE_NOT_FOUND;
2500 hres = IInternetProtocol_Start(protocol, index_url, &protocol_sink, &bind_info, 0, 0);
2501 ok(hres == INET_E_RESOURCE_NOT_FOUND,
2502 "Start failed: %08x expected INET_E_RESOURCE_NOT_FOUND\n", hres);
2503 CHECK_CALLED(GetBindInfo);
2504 if(!(bindf & BINDF_FROMURLMON))
2505 CHECK_CALLED(ReportProgress_DIRECTBIND);
2506 CHECK_CALLED(ReportProgress_SENDINGREQUEST);
2507 CHECK_CALLED(ReportResult);
2509 IInternetProtocol_Release(protocol);
2511 hres = CoCreateInstance(&CLSID_FileProtocol, NULL, CLSCTX_INPROC_SERVER|CLSCTX_INPROC_HANDLER,
2512 &IID_IInternetProtocol, (void**)&protocol);
2513 ok(hres == S_OK, "CoCreateInstance failed: %08x\n", hres);
2517 SET_EXPECT(GetBindInfo);
2518 if(!(bindf & BINDF_FROMURLMON))
2519 SET_EXPECT(ReportProgress_DIRECTBIND);
2520 SET_EXPECT(ReportProgress_SENDINGREQUEST);
2521 SET_EXPECT(ReportResult);
2522 expect_hrResult = INET_E_RESOURCE_NOT_FOUND;
2524 hres = IInternetProtocol_Start(protocol, index_url2, &protocol_sink, &bind_info, 0, 0);
2525 ok(hres == INET_E_RESOURCE_NOT_FOUND,
2526 "Start failed: %08x, expected INET_E_RESOURCE_NOT_FOUND\n", hres);
2527 CHECK_CALLED(GetBindInfo);
2528 if(!(bindf & BINDF_FROMURLMON))
2529 CHECK_CALLED(ReportProgress_DIRECTBIND);
2530 CHECK_CALLED(ReportProgress_SENDINGREQUEST);
2531 CHECK_CALLED(ReportResult);
2533 SET_EXPECT(GetBindInfo);
2534 hres = IInternetProtocol_Start(protocol, NULL, &protocol_sink, &bind_info, 0, 0);
2535 ok(hres == E_INVALIDARG, "Start failed: %08x, expected E_INVALIDARG\n", hres);
2536 CLEAR_CALLED(GetBindInfo); /* GetBindInfo not called in IE7 */
2538 SET_EXPECT(GetBindInfo);
2539 hres = IInternetProtocol_Start(protocol, emptyW, &protocol_sink, &bind_info, 0, 0);
2540 ok(hres == E_INVALIDARG, "Start failed: %08x, expected E_INVALIDARG\n", hres);
2541 CLEAR_CALLED(GetBindInfo); /* GetBindInfo not called in IE7 */
2543 IInternetProtocol_Release(protocol);
2546 static void test_file_protocol(void) {
2547 WCHAR buf[INTERNET_MAX_URL_LENGTH], file_name_buf[MAX_PATH];
2552 static const WCHAR wszFile[] = {'f','i','l','e',':',0};
2553 static const WCHAR wszFile2[] = {'f','i','l','e',':','/','/',0};
2554 static const WCHAR wszFile3[] = {'f','i','l','e',':','/','/','/',0};
2555 static const WCHAR wszFile4[] = {'f','i','l','e',':','\\','\\',0};
2556 static const char html_doc[] = "<HTML></HTML>";
2558 trace("Testing file protocol...\n");
2559 init_test(FILE_TEST, 0);
2561 SetLastError(0xdeadbeef);
2562 file = CreateFileW(wszIndexHtml, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS,
2563 FILE_ATTRIBUTE_NORMAL, NULL);
2564 ok(file != INVALID_HANDLE_VALUE, "CreateFile failed\n");
2565 if(file == INVALID_HANDLE_VALUE)
2567 WriteFile(file, html_doc, sizeof(html_doc)-1, &size, NULL);
2570 file_name = wszIndexHtml;
2572 test_file_protocol_url(index_url);
2573 bindf = BINDF_FROMURLMON;
2574 test_file_protocol_url(index_url);
2575 bindf = BINDF_FROMURLMON | BINDF_NEEDFILE;
2576 test_file_protocol_url(index_url);
2578 memcpy(buf, wszFile, sizeof(wszFile));
2579 len = sizeof(wszFile)/sizeof(WCHAR)-1;
2580 len += GetCurrentDirectoryW(sizeof(buf)/sizeof(WCHAR)-len, buf+len);
2582 memcpy(buf+len, wszIndexHtml, sizeof(wszIndexHtml));
2584 file_name = buf + sizeof(wszFile)/sizeof(WCHAR)-1;
2586 test_file_protocol_url(buf);
2587 bindf = BINDF_FROMURLMON;
2588 test_file_protocol_url(buf);
2590 memcpy(buf, wszFile2, sizeof(wszFile2));
2591 len = GetCurrentDirectoryW(sizeof(file_name_buf)/sizeof(WCHAR), file_name_buf);
2592 file_name_buf[len++] = '\\';
2593 memcpy(file_name_buf+len, wszIndexHtml, sizeof(wszIndexHtml));
2594 lstrcpyW(buf+sizeof(wszFile2)/sizeof(WCHAR)-1, file_name_buf);
2595 file_name = file_name_buf;
2597 test_file_protocol_url(buf);
2598 bindf = BINDF_FROMURLMON;
2599 test_file_protocol_url(buf);
2601 buf[sizeof(wszFile2)/sizeof(WCHAR)] = '|';
2602 test_file_protocol_url(buf);
2604 memcpy(buf, wszFile3, sizeof(wszFile3));
2605 len = sizeof(wszFile3)/sizeof(WCHAR)-1;
2606 len += GetCurrentDirectoryW(sizeof(buf)/sizeof(WCHAR)-len, buf+len);
2608 memcpy(buf+len, wszIndexHtml, sizeof(wszIndexHtml));
2610 file_name = buf + sizeof(wszFile3)/sizeof(WCHAR)-1;
2612 test_file_protocol_url(buf);
2613 bindf = BINDF_FROMURLMON;
2614 test_file_protocol_url(buf);
2616 memcpy(buf, wszFile4, sizeof(wszFile4));
2617 len = GetCurrentDirectoryW(sizeof(file_name_buf)/sizeof(WCHAR), file_name_buf);
2618 file_name_buf[len++] = '\\';
2619 memcpy(file_name_buf+len, wszIndexHtml, sizeof(wszIndexHtml));
2620 lstrcpyW(buf+sizeof(wszFile4)/sizeof(WCHAR)-1, file_name_buf);
2621 file_name = file_name_buf;
2623 test_file_protocol_url(buf);
2624 bindf = BINDF_FROMURLMON;
2625 test_file_protocol_url(buf);
2627 buf[sizeof(wszFile4)/sizeof(WCHAR)] = '|';
2628 test_file_protocol_url(buf);
2630 DeleteFileW(wszIndexHtml);
2633 test_file_protocol_fail();
2634 bindf = BINDF_FROMURLMON;
2635 test_file_protocol_fail();
2638 static BOOL http_protocol_start(LPCWSTR url, BOOL use_iuri)
2640 static BOOL got_user_agent = FALSE;
2644 if(use_iuri && pCreateUri) {
2645 hres = pCreateUri(url, 0, 0, &uri);
2646 ok(hres == S_OK, "CreateUri failed: %08x\n", hres);
2649 SET_EXPECT(GetBindInfo);
2650 if (!(bindf & BINDF_FROMURLMON))
2651 SET_EXPECT(ReportProgress_DIRECTBIND);
2653 SET_EXPECT(GetBindString_USER_AGENT);
2654 SET_EXPECT(GetBindString_ACCEPT_MIMES);
2655 SET_EXPECT(QueryService_HttpNegotiate);
2656 SET_EXPECT(BeginningTransaction);
2657 SET_EXPECT(GetRootSecurityId);
2658 if(http_post_test) {
2659 SET_EXPECT(GetBindString_POST_COOKIE);
2660 if(http_post_test == TYMED_ISTREAM)
2661 SET_EXPECT(Stream_Seek);
2665 IInternetProtocolEx *protocolex;
2667 hres = IInternetProtocol_QueryInterface(async_protocol, &IID_IInternetProtocolEx, (void**)&protocolex);
2668 ok(hres == S_OK, "Could not get IInternetProtocolEx iface: %08x\n", hres);
2670 hres = IInternetProtocolEx_StartEx(protocolex, uri, &protocol_sink, &bind_info, 0, 0);
2671 ok(hres == S_OK, "Start failed: %08x\n", hres);
2673 IInternetProtocolEx_Release(protocolex);
2676 hres = IInternetProtocol_Start(async_protocol, url, &protocol_sink, &bind_info, 0, 0);
2677 ok(hres == S_OK, "Start failed: %08x\n", hres);
2682 CHECK_CALLED(GetBindInfo);
2683 if (!(bindf & BINDF_FROMURLMON))
2684 CHECK_CALLED(ReportProgress_DIRECTBIND);
2685 if (!got_user_agent)
2687 CHECK_CALLED(GetBindString_USER_AGENT);
2688 got_user_agent = TRUE;
2690 CHECK_CALLED(GetBindString_ACCEPT_MIMES);
2691 CHECK_CALLED(QueryService_HttpNegotiate);
2692 CHECK_CALLED(BeginningTransaction);
2693 /* GetRootSecurityId called on WinXP but not on Win98 */
2694 CLEAR_CALLED(GetRootSecurityId);
2695 if(http_post_test) {
2696 CHECK_CALLED(GetBindString_POST_COOKIE);
2697 if(http_post_test == TYMED_ISTREAM)
2698 CHECK_CALLED(Stream_Seek);
2704 static void test_protocol_terminate(IInternetProtocol *protocol)
2710 hres = IInternetProtocol_LockRequest(protocol, 0);
2711 ok(hres == S_OK, "LockRequest failed: %08x\n", hres);
2713 hres = IInternetProtocol_Read(protocol, buf, 1, &cb);
2714 ok(hres == test_abort ? S_OK : S_FALSE, "Read failed: %08x\n", hres);
2716 hres = IInternetProtocol_Terminate(protocol, 0);
2717 ok(hres == S_OK, "Terminate failed: %08x\n", hres);
2719 /* This wait is to give the internet handles being freed in Terminate
2720 * enough time to actually terminate in all cases. Internet handles
2721 * terminate asynchronously and native reuses the main InternetOpen
2722 * handle. The only case in which this seems to be necessary is on
2723 * wine with native wininet and urlmon, resulting in the next time
2724 * test_http_protocol_url being called the first data notification actually
2725 * being an extra last data notification from the previous connection
2726 * about once out of every ten times. */
2729 hres = IInternetProtocol_UnlockRequest(protocol);
2730 ok(hres == S_OK, "UnlockRequest failed: %08x\n", hres);
2733 static void test_http_info(IInternetProtocol *protocol)
2735 IWinInetHttpInfo *info;
2738 hres = IInternetProtocol_QueryInterface(protocol, &IID_IWinInetHttpInfo, (void**)&info);
2739 ok(hres == S_OK, "Could not get IWinInterHttpInfo iface: %08x\n", hres);
2743 IWinInetHttpInfo_Release(info);
2746 /* is_first refers to whether this is the first call to this function
2748 static void test_http_protocol_url(LPCWSTR url, int prot, DWORD flags, DWORD tymed)
2750 IInternetProtocolInfo *protocol_info;
2751 IClassFactory *factory;
2755 init_test(prot, flags);
2757 http_post_test = tymed;
2759 hres = CoGetClassObject(prot == HTTPS_TEST ? &CLSID_HttpSProtocol : &CLSID_HttpProtocol,
2760 CLSCTX_INPROC_SERVER, NULL, &IID_IUnknown, (void**)&unk);
2761 ok(hres == S_OK, "CoGetClassObject failed: %08x\n", hres);
2765 hres = IUnknown_QueryInterface(unk, &IID_IInternetProtocolInfo, (void**)&protocol_info);
2766 ok(hres == E_NOINTERFACE,
2767 "Could not get IInternetProtocolInfo interface: %08x, expected E_NOINTERFACE\n",
2770 hres = IUnknown_QueryInterface(unk, &IID_IClassFactory, (void**)&factory);
2771 ok(hres == S_OK, "Could not get IClassFactory interface\n");
2772 IUnknown_Release(unk);
2776 hres = IClassFactory_CreateInstance(factory, NULL, &IID_IInternetProtocol,
2777 (void**)&async_protocol);
2778 ok(hres == S_OK, "Could not get IInternetProtocol: %08x\n", hres);
2779 if(SUCCEEDED(hres)) {
2784 test_priority(async_protocol);
2785 test_http_info(async_protocol);
2787 SET_EXPECT(ReportProgress_COOKIE_SENT);
2788 SET_EXPECT(ReportProgress_FINDINGRESOURCE);
2789 SET_EXPECT(ReportProgress_CONNECTING);
2790 SET_EXPECT(ReportProgress_SENDINGREQUEST);
2792 SET_EXPECT(ReportProgress_REDIRECTING);
2793 SET_EXPECT(ReportProgress_PROXYDETECTING);
2794 if(prot == HTTP_TEST)
2795 SET_EXPECT(ReportProgress_CACHEFILENAMEAVAILABLE);
2797 SET_EXPECT(QueryService_HttpSecurity);
2798 if(!(bindf & BINDF_FROMURLMON)) {
2799 SET_EXPECT(OnResponse);
2800 SET_EXPECT(ReportProgress_RAWMIMETYPE);
2801 SET_EXPECT(ReportData);
2806 if(!http_protocol_start(url, (flags & TEST_USEIURI) != 0))
2809 if(!direct_read && !test_abort)
2810 SET_EXPECT(ReportResult);
2811 expect_hrResult = test_abort ? E_ABORT : S_OK;
2815 while(wait_for_switch) {
2816 WaitForSingleObject(event_continue, INFINITE);
2817 CHECK_CALLED(Switch); /* Set in ReportData */
2818 call_continue(&continue_protdata);
2819 SetEvent(event_continue_done);
2822 hres = IInternetProtocol_Read(async_protocol, buf, 1, &cb);
2823 ok((hres == E_PENDING && cb==0) ||
2824 (hres == S_OK && cb==1), "Read failed: %08x (%d bytes)\n", hres, cb);
2826 WaitForSingleObject(event_complete, INFINITE);
2827 if(bindf & BINDF_FROMURLMON)
2828 CHECK_CALLED(Switch);
2830 CHECK_CALLED(ReportData);
2831 if(prot == HTTPS_TEST)
2832 CLEAR_CALLED(QueryService_HttpSecurity);
2835 if(bindf & BINDF_FROMURLMON)
2838 SET_EXPECT(ReportData);
2839 hres = IInternetProtocol_Read(async_protocol, buf, sizeof(buf), &cb);
2840 if(hres == E_PENDING) {
2841 hres = IInternetProtocol_Read(async_protocol, buf, 1, &cb);
2842 ok((hres == E_PENDING && cb==0) ||
2843 (hres == S_OK && cb==1), "Read failed: %08x (%d bytes)\n", hres, cb);
2844 WaitForSingleObject(event_complete, INFINITE);
2845 if(bindf & BINDF_FROMURLMON)
2846 CHECK_CALLED(Switch);
2848 CHECK_CALLED(ReportData);
2853 SET_EXPECT(ReportResult);
2854 hres = IInternetProtocol_Abort(async_protocol, E_ABORT, 0);
2855 ok(hres == S_OK, "Abort failed: %08x\n", hres);
2856 CHECK_CALLED(ReportResult);
2858 hres = IInternetProtocol_Abort(async_protocol, E_ABORT, 0);
2859 ok(hres == INET_E_RESULT_DISPATCHED, "Abort failed: %08x\n", hres);
2863 if(bindf & BINDF_FROMURLMON)
2864 CHECK_NOT_CALLED(Switch);
2866 CHECK_NOT_CALLED(ReportData);
2871 ok(hres == S_FALSE, "Read failed: %08x\n", hres);
2872 CHECK_CALLED(ReportResult);
2875 if(prot == HTTPS_TEST)
2876 CLEAR_CALLED(ReportProgress_SENDINGREQUEST);
2878 hres = IInternetProtocol_Abort(async_protocol, E_ABORT, 0);
2879 ok(hres == INET_E_RESULT_DISPATCHED, "Abort failed: %08x\n", hres);
2881 test_protocol_terminate(async_protocol);
2883 hres = IInternetProtocol_Abort(async_protocol, E_ABORT, 0);
2884 ok(hres == S_OK, "Abort failed: %08x\n", hres);
2886 ref = IInternetProtocol_Release(async_protocol);
2887 ok(!ref, "ref=%x\n", ref);
2890 IClassFactory_Release(factory);
2893 static void test_http_protocol(void)
2895 static const WCHAR winehq_url[] =
2896 {'h','t','t','p',':','/','/','w','w','w','.','w','i','n','e','h','q','.',
2897 'o','r','g','/','s','i','t','e','/','a','b','o','u','t',0};
2898 static const WCHAR posttest_url[] =
2899 {'h','t','t','p',':','/','/','c','r','o','s','s','o','v','e','r','.',
2900 'c','o','d','e','w','e','a','v','e','r','s','.','c','o','m','/',
2901 'p','o','s','t','t','e','s','t','.','p','h','p',0};
2902 static const WCHAR redirect_url[] =
2903 {'h','t','t','p',':','/','/','t','e','s','t','.','w','i','n','e','h','q','.','o','r','g','/',
2904 't','e','s','t','r','e','d','i','r','e','c','t',0};
2905 static const WCHAR winetest_url[] =
2906 {'h','t','t','p',':','/','/','t','e','s','t','.','w','i','n','e','h','q','.','o','r','g','/','d','a','t','a','/',0};
2908 trace("Testing http protocol (not from urlmon)...\n");
2909 bindf = BINDF_ASYNCHRONOUS | BINDF_ASYNCSTORAGE | BINDF_PULLDATA;
2910 test_http_protocol_url(winehq_url, HTTP_TEST, TEST_FIRST_HTTP, TYMED_NULL);
2912 trace("Testing http protocol (from urlmon)...\n");
2913 bindf = BINDF_ASYNCHRONOUS | BINDF_ASYNCSTORAGE | BINDF_PULLDATA | BINDF_FROMURLMON;
2914 test_http_protocol_url(winehq_url, HTTP_TEST, 0, TYMED_NULL);
2916 trace("Testing http protocol (to file)...\n");
2917 bindf = BINDF_ASYNCHRONOUS | BINDF_ASYNCSTORAGE | BINDF_PULLDATA | BINDF_FROMURLMON | BINDF_NEEDFILE;
2918 test_http_protocol_url(winehq_url, HTTP_TEST, 0, TYMED_NULL);
2920 trace("Testing http protocol (post data)...\n");
2921 /* Without this flag we get a ReportProgress_CACHEFILENAMEAVAILABLE
2922 * notification with BINDVERB_POST */
2923 bindf = BINDF_ASYNCHRONOUS | BINDF_ASYNCSTORAGE | BINDF_PULLDATA | BINDF_FROMURLMON | BINDF_NOWRITECACHE;
2924 test_http_protocol_url(posttest_url, HTTP_TEST, TEST_FIRST_HTTP|TEST_POST, TYMED_HGLOBAL);
2926 trace("Testing http protocol (post data stream)...\n");
2927 test_http_protocol_url(posttest_url, HTTP_TEST, TEST_FIRST_HTTP|TEST_POST|TEST_ASYNCREQ, TYMED_ISTREAM);
2929 trace("Testing http protocol (direct read)...\n");
2930 bindf = BINDF_ASYNCHRONOUS | BINDF_ASYNCSTORAGE | BINDF_PULLDATA | BINDF_FROMURLMON;
2931 test_http_protocol_url(winehq_url, HTTP_TEST, TEST_DIRECT_READ|TEST_USEIURI, TYMED_NULL);
2933 trace("Testing http protocol (redirected)...\n");
2934 bindf = BINDF_ASYNCHRONOUS | BINDF_ASYNCSTORAGE | BINDF_PULLDATA | BINDF_FROMURLMON;
2935 test_http_protocol_url(redirect_url, HTTP_TEST, TEST_REDIRECT, TYMED_NULL);
2937 trace("Testing http protocol abort...\n");
2938 test_http_protocol_url(winetest_url, HTTP_TEST, TEST_ABORT, TYMED_NULL);
2940 test_early_abort(&CLSID_HttpProtocol);
2941 test_early_abort(&CLSID_HttpSProtocol);
2944 static void test_https_protocol(void)
2946 static const WCHAR codeweavers_url[] =
2947 {'h','t','t','p','s',':','/','/','w','w','w','.','c','o','d','e','w','e','a','v','e','r','s',
2948 '.','c','o','m','/','t','e','s','t','.','h','t','m','l',0};
2950 trace("Testing https protocol (from urlmon)...\n");
2951 bindf = BINDF_ASYNCHRONOUS | BINDF_ASYNCSTORAGE | BINDF_PULLDATA | BINDF_FROMURLMON | BINDF_NOWRITECACHE;
2952 test_http_protocol_url(codeweavers_url, HTTPS_TEST, TEST_FIRST_HTTP, TYMED_NULL);
2956 static void test_ftp_protocol(void)
2958 IInternetProtocolInfo *protocol_info;
2959 IClassFactory *factory;
2966 static const WCHAR ftp_urlW[] = {'f','t','p',':','/','/','f','t','p','.','w','i','n','e','h','q','.','o','r','g',
2967 '/','p','u','b','/','o','t','h','e','r','/',
2968 'w','i','n','e','l','o','g','o','.','x','c','f','.','t','a','r','.','b','z','2',0};
2970 trace("Testing ftp protocol...\n");
2972 bindf = BINDF_ASYNCHRONOUS | BINDF_ASYNCSTORAGE | BINDF_PULLDATA | BINDF_FROMURLMON | BINDF_NOWRITECACHE;
2973 state = STATE_STARTDOWNLOADING;
2974 tested_protocol = FTP_TEST;
2975 first_data_notif = TRUE;
2976 expect_hrResult = E_PENDING;
2978 hres = CoGetClassObject(&CLSID_FtpProtocol, CLSCTX_INPROC_SERVER, NULL, &IID_IUnknown, (void**)&unk);
2979 ok(hres == S_OK, "CoGetClassObject failed: %08x\n", hres);
2983 hres = IUnknown_QueryInterface(unk, &IID_IInternetProtocolInfo, (void**)&protocol_info);
2984 ok(hres == E_NOINTERFACE, "Could not get IInternetProtocolInfo interface: %08x, expected E_NOINTERFACE\n", hres);
2986 hres = IUnknown_QueryInterface(unk, &IID_IClassFactory, (void**)&factory);
2987 ok(hres == S_OK, "Could not get IClassFactory interface\n");
2988 IUnknown_Release(unk);
2992 hres = IClassFactory_CreateInstance(factory, NULL, &IID_IInternetProtocol,
2993 (void**)&async_protocol);
2994 IClassFactory_Release(factory);
2995 ok(hres == S_OK, "Could not get IInternetProtocol: %08x\n", hres);
2997 test_priority(async_protocol);
2998 test_http_info(async_protocol);
3000 SET_EXPECT(GetBindInfo);
3001 SET_EXPECT(ReportProgress_FINDINGRESOURCE);
3002 SET_EXPECT(ReportProgress_CONNECTING);
3003 SET_EXPECT(ReportProgress_SENDINGREQUEST);
3006 hres = IInternetProtocol_Start(async_protocol, ftp_urlW, &protocol_sink, &bind_info, 0, 0);
3007 ok(hres == S_OK, "Start failed: %08x\n", hres);
3008 CHECK_CALLED(GetBindInfo);
3010 SET_EXPECT(ReportResult);
3012 hres = IInternetProtocol_Read(async_protocol, buf, 1, &cb);
3013 ok((hres == E_PENDING && cb==0) ||
3014 (hres == S_OK && cb==1), "Read failed: %08x (%d bytes)\n", hres, cb);
3016 WaitForSingleObject(event_complete, INFINITE);
3019 hres = IInternetProtocol_Read(async_protocol, buf, sizeof(buf), &cb);
3020 if(hres == E_PENDING)
3021 WaitForSingleObject(event_complete, INFINITE);
3026 ok(hres == S_FALSE, "Read failed: %08x\n", hres);
3027 CHECK_CALLED(ReportResult);
3028 CHECK_CALLED(Switch);
3030 test_protocol_terminate(async_protocol);
3033 IInternetProtocolEx *protocolex;
3035 hres = IInternetProtocol_QueryInterface(async_protocol, &IID_IInternetProtocolEx, (void**)&protocolex);
3036 ok(hres == S_OK, "Could not get IInternetProtocolEx iface: %08x\n", hres);
3037 IInternetProtocolEx_Release(protocolex);
3040 ref = IInternetProtocol_Release(async_protocol);
3041 ok(!ref, "ref=%d\n", ref);
3043 test_early_abort(&CLSID_FtpProtocol);
3046 static void test_gopher_protocol(void)
3048 IInternetProtocolInfo *protocol_info;
3049 IClassFactory *factory;
3053 trace("Testing gopher protocol...\n");
3055 hres = CoGetClassObject(&CLSID_GopherProtocol, CLSCTX_INPROC_SERVER, NULL, &IID_IUnknown, (void**)&unk);
3057 hres == REGDB_E_CLASSNOTREG, /* Gopher protocol has been removed as of Vista */
3058 "CoGetClassObject failed: %08x\n", hres);
3062 hres = IUnknown_QueryInterface(unk, &IID_IInternetProtocolInfo, (void**)&protocol_info);
3063 ok(hres == E_NOINTERFACE, "Could not get IInternetProtocolInfo interface: %08x, expected E_NOINTERFACE\n", hres);
3065 hres = IUnknown_QueryInterface(unk, &IID_IClassFactory, (void**)&factory);
3066 ok(hres == S_OK, "Could not get IClassFactory interface\n");
3067 IUnknown_Release(unk);
3071 hres = IClassFactory_CreateInstance(factory, NULL, &IID_IInternetProtocol,
3072 (void**)&async_protocol);
3073 IClassFactory_Release(factory);
3074 ok(hres == S_OK, "Could not get IInternetProtocol: %08x\n", hres);
3076 test_priority(async_protocol);
3078 IInternetProtocol_Release(async_protocol);
3080 test_early_abort(&CLSID_GopherProtocol);
3083 static void test_mk_protocol(void)
3085 IInternetProtocolInfo *protocol_info;
3086 IInternetProtocol *protocol;
3087 IClassFactory *factory;
3091 static const WCHAR wrong_url1[] = {'t','e','s','t',':','@','M','S','I','T','S','t','o','r','e',
3092 ':',':','/','t','e','s','t','.','h','t','m','l',0};
3093 static const WCHAR wrong_url2[] = {'m','k',':','/','t','e','s','t','.','h','t','m','l',0};
3095 trace("Testing mk protocol...\n");
3096 init_test(MK_TEST, 0);
3098 hres = CoGetClassObject(&CLSID_MkProtocol, CLSCTX_INPROC_SERVER, NULL,
3099 &IID_IUnknown, (void**)&unk);
3100 ok(hres == S_OK, "CoGetClassObject failed: %08x\n", hres);
3102 hres = IUnknown_QueryInterface(unk, &IID_IInternetProtocolInfo, (void**)&protocol_info);
3103 ok(hres == E_NOINTERFACE,
3104 "Could not get IInternetProtocolInfo interface: %08x, expected E_NOINTERFACE\n",
3107 hres = IUnknown_QueryInterface(unk, &IID_IClassFactory, (void**)&factory);
3108 ok(hres == S_OK, "Could not get IClassFactory interface\n");
3109 IUnknown_Release(unk);
3113 hres = IClassFactory_CreateInstance(factory, NULL, &IID_IInternetProtocol,
3115 IClassFactory_Release(factory);
3116 ok(hres == S_OK, "Could not get IInternetProtocol: %08x\n", hres);
3118 SET_EXPECT(GetBindInfo);
3119 hres = IInternetProtocol_Start(protocol, wrong_url1, &protocol_sink, &bind_info, 0, 0);
3120 ok(hres == MK_E_SYNTAX || hres == INET_E_INVALID_URL,
3121 "Start failed: %08x, expected MK_E_SYNTAX or INET_E_INVALID_URL\n", hres);
3122 CLEAR_CALLED(GetBindInfo);
3124 SET_EXPECT(GetBindInfo);
3125 SET_EXPECT(ReportProgress_DIRECTBIND);
3126 SET_EXPECT(ReportProgress_SENDINGREQUEST);
3127 SET_EXPECT(ReportProgress_MIMETYPEAVAILABLE);
3128 SET_EXPECT(ReportResult);
3129 expect_hrResult = INET_E_RESOURCE_NOT_FOUND;
3131 hres = IInternetProtocol_Start(protocol, wrong_url2, &protocol_sink, &bind_info, 0, 0);
3132 ok(hres == INET_E_RESOURCE_NOT_FOUND ||
3133 hres == INET_E_INVALID_URL, /* win2k3 */
3134 "Start failed: %08x, expected INET_E_RESOURCE_NOT_FOUND or INET_E_INVALID_URL\n", hres);
3136 if (hres == INET_E_RESOURCE_NOT_FOUND) {
3137 CHECK_CALLED(GetBindInfo);
3138 CLEAR_CALLED(ReportProgress_DIRECTBIND);
3139 CHECK_CALLED(ReportProgress_SENDINGREQUEST);
3140 CHECK_CALLED(ReportProgress_MIMETYPEAVAILABLE);
3141 CHECK_CALLED(ReportResult);
3143 CLEAR_CALLED(GetBindInfo);
3144 CLEAR_CALLED(ReportProgress_DIRECTBIND);
3145 CLEAR_CALLED(ReportProgress_SENDINGREQUEST);
3146 CLEAR_CALLED(ReportProgress_MIMETYPEAVAILABLE);
3147 CLEAR_CALLED(ReportResult);
3150 IInternetProtocol_Release(protocol);
3153 static void test_CreateBinding(void)
3155 IInternetProtocol *protocol;
3156 IInternetPriority *priority;
3157 IInternetSession *session;
3158 IWinInetHttpInfo *http_info;
3159 IWinInetInfo *inet_info;
3165 static const WCHAR test_url[] =
3166 {'t','e','s','t',':','/','/','f','i','l','e','.','h','t','m','l',0};
3167 static const WCHAR wsz_test[] = {'t','e','s','t',0};
3169 trace("Testing CreateBinding...\n");
3170 init_test(BIND_TEST, TEST_BINDING);
3172 hres = pCoInternetGetSession(0, &session, 0);
3173 ok(hres == S_OK, "CoInternetGetSession failed: %08x\n", hres);
3175 hres = IInternetSession_RegisterNameSpace(session, &ClassFactory, &IID_NULL, wsz_test, 0, NULL, 0);
3176 ok(hres == S_OK, "RegisterNameSpace failed: %08x\n", hres);
3178 hres = IInternetSession_CreateBinding(session, NULL, test_url, NULL, NULL, &protocol, 0);
3179 binding_protocol = protocol;
3180 ok(hres == S_OK, "CreateBinding failed: %08x\n", hres);
3181 ok(protocol != NULL, "protocol == NULL\n");
3183 hres = IInternetProtocol_QueryInterface(protocol, &IID_IInternetBindInfo, (void**)&prot_bind_info);
3184 ok(hres == S_OK, "QueryInterface(IID_IInternetBindInfo) failed: %08x\n", hres);
3186 hres = IInternetProtocol_QueryInterface(protocol, &IID_IInternetProtocolSink, (void**)&binding_sink);
3187 ok(hres == S_OK, "Could not get IInternetProtocolSink: %08x\n", hres);
3189 hres = IInternetProtocol_Start(protocol, test_url, NULL, &bind_info, 0, 0);
3190 ok(hres == E_INVALIDARG, "Start failed: %08x, expected E_INVALIDARG\n", hres);
3191 hres = IInternetProtocol_Start(protocol, test_url, &protocol_sink, NULL, 0, 0);
3192 ok(hres == E_INVALIDARG, "Start failed: %08x, expected E_INVALIDARG\n", hres);
3193 hres = IInternetProtocol_Start(protocol, NULL, &protocol_sink, &bind_info, 0, 0);
3194 ok(hres == E_INVALIDARG, "Start failed: %08x, expected E_INVALIDARG\n", hres);
3196 hres = IInternetProtocol_QueryInterface(protocol, &IID_IInternetPriority, (void**)&priority);
3197 ok(hres == S_OK, "QueryInterface(IID_IInternetPriority) failed: %08x\n", hres);
3200 hres = IInternetPriority_GetPriority(priority, &p);
3201 ok(hres == S_OK, "GetPriority failed: %08x\n", hres);
3202 ok(!p, "p=%d\n", p);
3205 hres = IInternetPriority_SetPriority(priority, 100);
3206 ok(hres == S_OK, "SetPriority failed: %08x\n", hres);
3209 hres = IInternetPriority_GetPriority(priority, &p);
3210 ok(hres == S_OK, "GetPriority failed: %08x\n", hres);
3211 ok(p == 100, "p=%d\n", p);
3213 hres = IInternetProtocol_QueryInterface(protocol, &IID_IWinInetInfo, (void**)&inet_info);
3214 ok(hres == E_NOINTERFACE, "Could not get IWinInetInfo protocol: %08x\n", hres);
3216 SET_EXPECT(QueryService_InternetProtocol);
3217 SET_EXPECT(CreateInstance);
3218 SET_EXPECT(ReportProgress_PROTOCOLCLASSID);
3219 SET_EXPECT(SetPriority);
3222 expect_hrResult = S_OK;
3223 hres = IInternetProtocol_Start(protocol, test_url, &protocol_sink, &bind_info, 0, 0);
3224 ok(hres == S_OK, "Start failed: %08x\n", hres);
3226 CHECK_CALLED(QueryService_InternetProtocol);
3227 CHECK_CALLED(CreateInstance);
3228 CHECK_CALLED(ReportProgress_PROTOCOLCLASSID);
3229 CHECK_CALLED(SetPriority);
3230 CHECK_CALLED(Start);
3232 SET_EXPECT(QueryInterface_IWinInetInfo);
3233 hres = IInternetProtocol_QueryInterface(protocol, &IID_IWinInetInfo, (void**)&inet_info);
3234 ok(hres == E_NOINTERFACE, "Could not get IWinInetInfo protocol: %08x\n", hres);
3235 CHECK_CALLED(QueryInterface_IWinInetInfo);
3237 SET_EXPECT(QueryInterface_IWinInetInfo);
3238 hres = IInternetProtocol_QueryInterface(protocol, &IID_IWinInetInfo, (void**)&inet_info);
3239 ok(hres == E_NOINTERFACE, "Could not get IWinInetInfo protocol: %08x\n", hres);
3240 CHECK_CALLED(QueryInterface_IWinInetInfo);
3242 SET_EXPECT(QueryInterface_IWinInetHttpInfo);
3243 hres = IInternetProtocol_QueryInterface(protocol, &IID_IWinInetHttpInfo, (void**)&http_info);
3244 ok(hres == E_NOINTERFACE, "Could not get IWinInetInfo protocol: %08x\n", hres);
3245 CHECK_CALLED(QueryInterface_IWinInetHttpInfo);
3249 hres = IInternetProtocol_Read(protocol, expect_pv = buf, sizeof(buf), &read);
3250 ok(hres == S_OK, "Read failed: %08x\n", hres);
3251 ok(read == 100, "read = %d\n", read);
3256 hres = IInternetProtocol_Read(protocol, expect_pv = buf, sizeof(buf), &read);
3257 ok(hres == S_FALSE, "Read failed: %08x\n", hres);
3258 ok(!read, "read = %d\n", read);
3262 hres = IInternetPriority_GetPriority(priority, &p);
3263 ok(hres == S_OK, "GetPriority failed: %08x\n", hres);
3264 ok(p == 100, "p=%d\n", p);
3266 hres = IInternetPriority_SetPriority(priority, 101);
3267 ok(hres == S_OK, "SetPriority failed: %08x\n", hres);
3269 SET_EXPECT(Terminate);
3270 hres = IInternetProtocol_Terminate(protocol, 0xdeadbeef);
3271 ok(hres == S_OK, "Terminate failed: %08x\n", hres);
3272 CHECK_CALLED(Terminate);
3274 SET_EXPECT(Continue);
3275 hres = IInternetProtocolSink_Switch(binding_sink, &protocoldata);
3276 ok(hres == S_OK, "Switch failed: %08x\n", hres);
3277 CHECK_CALLED(Continue);
3279 hres = IInternetProtocolSink_ReportProgress(binding_sink,
3280 BINDSTATUS_CACHEFILENAMEAVAILABLE, expect_wsz = emptyW);
3281 ok(hres == S_OK, "ReportProgress(BINDSTATUS_CACHEFILENAMEAVAILABLE) failed: %08x\n", hres);
3283 hres = IInternetProtocolSink_ReportResult(binding_sink, S_OK, ERROR_SUCCESS, NULL);
3284 ok(hres == E_FAIL, "ReportResult failed: %08x, expected E_FAIL\n", hres);
3286 hres = IInternetProtocolSink_ReportData(binding_sink, 0, 0, 0);
3287 ok(hres == S_OK, "ReportData failed: %08x\n", hres);
3289 IInternetProtocolSink_Release(binding_sink);
3290 IInternetPriority_Release(priority);
3291 IInternetBindInfo_Release(prot_bind_info);
3292 IInternetProtocol_Release(protocol);
3294 hres = IInternetSession_CreateBinding(session, NULL, test_url, NULL, NULL, &protocol, 0);
3295 ok(hres == S_OK, "CreateBinding failed: %08x\n", hres);
3296 ok(protocol != NULL, "protocol == NULL\n");
3298 hres = IInternetProtocol_Abort(protocol, E_ABORT, 0);
3299 ok(hres == S_OK, "Abort failed: %08x\n", hres);
3301 hres = IInternetProtocol_Abort(protocol, E_FAIL, 0);
3302 ok(hres == S_OK, "Abort failed: %08x\n", hres);
3304 IInternetProtocol_Release(protocol);
3306 hres = IInternetSession_UnregisterNameSpace(session, &ClassFactory, wsz_test);
3307 ok(hres == S_OK, "UnregisterNameSpace failed: %08x\n", hres);
3309 hres = IInternetSession_CreateBinding(session, NULL, test_url, NULL, NULL, &protocol, 0);
3310 ok(hres == S_OK, "CreateBinding failed: %08x\n", hres);
3311 ok(protocol != NULL, "protocol == NULL\n");
3313 SET_EXPECT(QueryService_InternetProtocol);
3314 hres = IInternetProtocol_Start(protocol, test_url, &protocol_sink, &bind_info, 0, 0);
3315 ok(hres == MK_E_SYNTAX, "Start failed: %08x, expected MK_E_SYNTAX\n", hres);
3316 CHECK_CALLED(QueryService_InternetProtocol);
3318 IInternetProtocol_Release(protocol);
3320 IInternetSession_Release(session);
3323 static void test_binding(int prot, DWORD grf_pi, DWORD test_flags)
3325 IInternetProtocolEx *protocolex = NULL;
3326 IInternetProtocol *protocol;
3327 IInternetSession *session;
3334 init_test(prot, test_flags|TEST_BINDING);
3336 hres = pCoInternetGetSession(0, &session, 0);
3337 ok(hres == S_OK, "CoInternetGetSession failed: %08x\n", hres);
3339 if(test_flags & TEST_EMULATEPROT) {
3340 hres = IInternetSession_RegisterNameSpace(session, &ClassFactory, &IID_NULL, protocol_names[prot], 0, NULL, 0);
3341 ok(hres == S_OK, "RegisterNameSpace failed: %08x\n", hres);
3344 hres = IInternetSession_CreateBinding(session, NULL, binding_urls[prot], NULL, NULL, &protocol, 0);
3345 binding_protocol = protocol;
3346 ok(hres == S_OK, "CreateBinding failed: %08x\n", hres);
3347 ok(protocol != NULL, "protocol == NULL\n");
3349 hres = IInternetProtocol_QueryInterface(protocol, &IID_IInternetBindInfo, (void**)&prot_bind_info);
3350 ok(hres == S_OK, "QueryInterface(IID_IInternetBindInfo) failed: %08x\n", hres);
3352 hres = IInternetProtocol_QueryInterface(protocol, &IID_IInternetProtocolSink, (void**)&binding_sink);
3353 ok(hres == S_OK, "QueryInterface(IID_IInternetProtocolSink) failed: %08x\n", hres);
3355 if(test_flags & TEST_USEIURI) {
3356 hres = IInternetProtocol_QueryInterface(protocol, &IID_IInternetProtocolEx, (void**)&protocolex);
3357 ok(hres == S_OK, "Could not get IInternetProtocolEx iface: %08x\n", hres);
3359 hres = pCreateUri(binding_urls[prot], Uri_CREATE_FILE_USE_DOS_PATH, 0, &uri);
3360 ok(hres == S_OK, "CreateUri failed: %08x\n", hres);
3364 SET_EXPECT(QueryService_InternetProtocol);
3365 SET_EXPECT(CreateInstance);
3366 SET_EXPECT(ReportProgress_PROTOCOLCLASSID);
3367 SET_EXPECT(SetPriority);
3369 SET_EXPECT(StartEx);
3373 expect_hrResult = S_OK;
3376 hres = IInternetProtocolEx_StartEx(protocolex, uri, &protocol_sink, &bind_info, pi, 0);
3377 ok(hres == S_OK, "StartEx failed: %08x\n", hres);
3379 hres = IInternetProtocol_Start(protocol, binding_urls[prot], &protocol_sink, &bind_info, pi, 0);
3380 ok(hres == S_OK, "Start failed: %08x\n", hres);
3383 CHECK_CALLED(QueryService_InternetProtocol);
3384 CHECK_CALLED(CreateInstance);
3385 CHECK_CALLED(ReportProgress_PROTOCOLCLASSID);
3386 CHECK_CALLED(SetPriority);
3388 CHECK_CALLED(StartEx);
3390 CHECK_CALLED(Start);
3393 IInternetProtocolEx_Release(protocolex);
3397 if(prot == HTTP_TEST || prot == HTTPS_TEST) {
3398 while(prot_state < 4) {
3399 WaitForSingleObject(event_complete, INFINITE);
3400 if(mimefilter_test && filtered_protocol) {
3401 SET_EXPECT(Continue);
3402 IInternetProtocol_Continue(filtered_protocol, pdata);
3403 CHECK_CALLED(Continue);
3405 SET_EXPECT(Continue);
3406 IInternetProtocol_Continue(protocol, pdata);
3407 CHECK_CALLED(Continue);
3409 if(test_abort && prot_state == 2) {
3411 hres = IInternetProtocol_Abort(protocol, E_ABORT, 0);
3412 ok(hres == S_OK, "Abort failed: %08x\n", hres);
3413 CHECK_CALLED(Abort);
3415 hres = IInternetProtocol_Abort(protocol, E_ABORT, 0);
3416 ok(hres == S_OK, "Abort failed: %08x\n", hres);
3417 SetEvent(event_complete2);
3420 SetEvent(event_complete2);
3423 CHECK_CALLED(ReportData); /* Set in ReportResult */
3424 WaitForSingleObject(event_complete, INFINITE);
3427 SET_EXPECT(MimeFilter_LockRequest);
3429 SET_EXPECT(LockRequest);
3430 hres = IInternetProtocol_LockRequest(protocol, 0);
3431 ok(hres == S_OK, "LockRequest failed: %08x\n", hres);
3433 CHECK_CALLED(MimeFilter_LockRequest);
3435 CHECK_CALLED(LockRequest);
3438 SET_EXPECT(MimeFilter_UnlockRequest);
3440 SET_EXPECT(UnlockRequest);
3441 hres = IInternetProtocol_UnlockRequest(protocol);
3442 ok(hres == S_OK, "UnlockRequest failed: %08x\n", hres);
3444 CHECK_CALLED(MimeFilter_UnlockRequest);
3446 CHECK_CALLED(UnlockRequest);
3450 SET_EXPECT(MimeFilter_Terminate);
3452 SET_EXPECT(Terminate);
3453 hres = IInternetProtocol_Terminate(protocol, 0);
3454 ok(hres == S_OK, "Terminate failed: %08x\n", hres);
3456 CLEAR_CALLED(MimeFilter_Terminate);
3458 CHECK_CALLED(Terminate);
3460 if(filtered_protocol)
3461 IInternetProtocol_Release(filtered_protocol);
3462 IInternetBindInfo_Release(prot_bind_info);
3463 IInternetProtocolSink_Release(binding_sink);
3464 ref = IInternetProtocol_Release(protocol);
3465 ok(!ref, "ref=%u, expected 0\n", ref);
3467 if(test_flags & TEST_EMULATEPROT) {
3468 hres = IInternetSession_UnregisterNameSpace(session, &ClassFactory, protocol_names[prot]);
3469 ok(hres == S_OK, "UnregisterNameSpace failed: %08x\n", hres);
3472 IInternetSession_Release(session);
3475 START_TEST(protocol)
3479 hurlmon = GetModuleHandle("urlmon.dll");
3480 pCoInternetGetSession = (void*) GetProcAddress(hurlmon, "CoInternetGetSession");
3481 pReleaseBindInfo = (void*) GetProcAddress(hurlmon, "ReleaseBindInfo");
3482 pCreateUri = (void*) GetProcAddress(hurlmon, "CreateUri");
3484 if(!GetProcAddress(hurlmon, "CompareSecurityIds")) {
3485 win_skip("Various needed functions not present, too old IE\n");
3490 win_skip("CreateUri not supported\n");
3492 OleInitialize(NULL);
3494 event_complete = CreateEvent(NULL, FALSE, FALSE, NULL);
3495 event_complete2 = CreateEvent(NULL, FALSE, FALSE, NULL);
3496 event_continue = CreateEvent(NULL, FALSE, FALSE, NULL);
3497 event_continue_done = CreateEvent(NULL, FALSE, FALSE, NULL);
3498 thread_id = GetCurrentThreadId();
3500 test_file_protocol();
3501 test_http_protocol();
3502 test_https_protocol();
3503 test_ftp_protocol();
3504 test_gopher_protocol();
3506 test_CreateBinding();
3508 bindf &= ~BINDF_FROMURLMON;
3509 trace("Testing file binding (mime verification, emulate prot)...\n");
3510 test_binding(FILE_TEST, PI_MIMEVERIFICATION, TEST_EMULATEPROT);
3511 trace("Testing http binding (mime verification, emulate prot)...\n");
3512 test_binding(HTTP_TEST, PI_MIMEVERIFICATION, TEST_EMULATEPROT);
3513 trace("Testing its binding (mime verification, emulate prot)...\n");
3514 test_binding(ITS_TEST, PI_MIMEVERIFICATION, TEST_EMULATEPROT);
3515 trace("Testing http binding (mime verification, emulate prot, short read, direct read)...\n");
3516 test_binding(HTTP_TEST, PI_MIMEVERIFICATION, TEST_EMULATEPROT|TEST_SHORT_READ|TEST_DIRECT_READ);
3517 trace("Testing file binding (mime verification, emulate prot, mime filter)...\n");
3518 test_binding(FILE_TEST, PI_MIMEVERIFICATION, TEST_EMULATEPROT|TEST_FILTER);
3519 trace("Testing http binding (mime verification, emulate prot, mime filter)...\n");
3520 test_binding(HTTP_TEST, PI_MIMEVERIFICATION, TEST_EMULATEPROT|TEST_FILTER);
3521 trace("Testing http binding (mime verification, emulate prot, direct read)...\n");
3522 test_binding(HTTP_TEST, PI_MIMEVERIFICATION, TEST_EMULATEPROT|TEST_DIRECT_READ);
3523 trace("Testing http binding (mime verification, emulate prot, abort)...\n");
3524 test_binding(HTTP_TEST, PI_MIMEVERIFICATION, TEST_EMULATEPROT|TEST_ABORT);
3526 trace("Testing file binding (use IUri, mime verification, emulate prot)...\n");
3527 test_binding(FILE_TEST, PI_MIMEVERIFICATION, TEST_EMULATEPROT|TEST_USEIURI);
3528 trace("Testing file binding (use IUri, impl StartEx, mime verification, emulate prot)...\n");
3529 test_binding(FILE_TEST, PI_MIMEVERIFICATION, TEST_EMULATEPROT|TEST_USEIURI|TEST_IMPLPROTEX);
3530 trace("Testing file binding (impl StartEx, mime verification, emulate prot)...\n");
3531 test_binding(FILE_TEST, PI_MIMEVERIFICATION, TEST_EMULATEPROT|TEST_IMPLPROTEX);
3534 CloseHandle(event_complete);
3535 CloseHandle(event_complete2);
3536 CloseHandle(event_continue);
3537 CloseHandle(event_continue_done);