usp10: Merge neutral scripts.
[wine.git] / dlls / urlmon / tests / protocol.c
blob52da99b46eb35e301a8d7c7acae41f2610e3920f
1 /*
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
19 #define COBJMACROS
20 #define CONST_VTABLE
22 #include <wine/test.h>
23 #include <stdarg.h>
24 #include <stdio.h>
26 #include "windef.h"
27 #include "winbase.h"
28 #include "ole2.h"
29 #include "urlmon.h"
30 #include "wininet.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) \
43 do { \
44 ok(expect_ ##func, "unexpected call " #func "\n"); \
45 called_ ## func = TRUE; \
46 }while(0)
48 #define CHECK_EXPECT(func) \
49 do { \
50 CHECK_EXPECT2(func); \
51 expect_ ## func = FALSE; \
52 }while(0)
54 #define CHECK_CALLED(func) \
55 do { \
56 ok(called_ ## func, "expected " #func "\n"); \
57 expect_ ## func = called_ ## func = FALSE; \
58 }while(0)
60 #define CHECK_NOT_CALLED(func) \
61 do { \
62 ok(!called_ ## func, "unexpected " #func "\n"); \
63 expect_ ## func = called_ ## func = FALSE; \
64 }while(0)
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);
107 DEFINE_EXPECT(Read);
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;
155 static BOOL empty_file;
157 enum {
158 STATE_CONNECTING,
159 STATE_SENDINGREQUEST,
160 STATE_STARTDOWNLOADING,
161 STATE_DOWNLOADING
162 } state;
164 static enum {
165 FILE_TEST,
166 HTTP_TEST,
167 HTTPS_TEST,
168 FTP_TEST,
169 MK_TEST,
170 ITS_TEST,
171 BIND_TEST
172 } tested_protocol;
174 static const WCHAR protocol_names[][10] = {
175 {'f','i','l','e',0},
176 {'h','t','t','p',0},
177 {'h','t','t','p','s',0},
178 {'f','t','p',0},
179 {'m','k',0},
180 {'i','t','s',0},
181 {'t','e','s','t',0}
184 static const WCHAR binding_urls[][130] = {
185 {'f','i','l','e',':','t','e','s','t','.','h','t','m','l',0},
186 {'h','t','t','p',':','/','/','w','w','w','.','w','i','n','e','h','q','.',
187 'o','r','g','/','s','i','t','e','/','a','b','o','u','t',0},
188 {'h','t','t','p','s',':','/','/','w','w','w','.','c','o','d','e','w','e','a','v','e','r','s',
189 '.','c','o','m','/','t','e','s','t','.','h','t','m','l',0},
190 {'f','t','p',':','/','/','f','t','p','.','w','i','n','e','h','q','.','o','r','g',
191 '/','p','u','b','/','o','t','h','e','r',
192 '/','w','i','n','e','l','o','g','o','.','x','c','f','.','t','a','r','.','b','z','2',0},
193 {'m','k',':','t','e','s','t',0},
194 {'i','t','s',':','t','e','s','t','.','c','h','m',':',':','/','b','l','a','n','k','.','h','t','m','l',0},
195 {'t','e','s','t',':','/','/','f','i','l','e','.','h','t','m','l',0}
198 static const CHAR post_data[] = "mode=Test";
200 static const char *debugstr_guid(REFIID riid)
202 static char buf[50];
204 sprintf(buf, "{%08X-%04X-%04X-%02X%02X-%02X%02X%02X%02X%02X%02X}",
205 riid->Data1, riid->Data2, riid->Data3, riid->Data4[0],
206 riid->Data4[1], riid->Data4[2], riid->Data4[3], riid->Data4[4],
207 riid->Data4[5], riid->Data4[6], riid->Data4[7]);
209 return buf;
212 static int strcmp_wa(LPCWSTR strw, const char *stra)
214 CHAR buf[512];
215 WideCharToMultiByte(CP_ACP, 0, strw, -1, buf, sizeof(buf), NULL, NULL);
216 return lstrcmpA(stra, buf);
219 static HRESULT WINAPI HttpSecurity_QueryInterface(IHttpSecurity *iface, REFIID riid, void **ppv)
221 if(IsEqualGUID(&IID_IUnknown, riid)
222 || IsEqualGUID(&IID_IHttpSecurity, riid)) {
223 *ppv = iface;
224 return S_OK;
227 ok(0, "unexpected call\n");
228 return E_NOINTERFACE;
231 static ULONG WINAPI HttpSecurity_AddRef(IHttpSecurity *iface)
233 return 2;
236 static ULONG WINAPI HttpSecurity_Release(IHttpSecurity *iface)
238 return 1;
241 static HRESULT WINAPI HttpSecurity_GetWindow(IHttpSecurity* iface, REFGUID rguidReason, HWND *phwnd)
243 trace("HttpSecurity_GetWindow\n");
245 return S_FALSE;
248 static HRESULT WINAPI HttpSecurity_OnSecurityProblem(IHttpSecurity *iface, DWORD dwProblem)
250 trace("Security problem: %u\n", dwProblem);
251 ok(dwProblem == ERROR_INTERNET_SEC_CERT_REV_FAILED, "Expected ERROR_INTERNET_SEC_CERT_REV_FAILED got %u\n", dwProblem);
253 /* Only retry once */
254 if (security_problem)
255 return E_ABORT;
257 security_problem = TRUE;
258 SET_EXPECT(BeginningTransaction);
260 return RPC_E_RETRY;
263 static IHttpSecurityVtbl HttpSecurityVtbl = {
264 HttpSecurity_QueryInterface,
265 HttpSecurity_AddRef,
266 HttpSecurity_Release,
267 HttpSecurity_GetWindow,
268 HttpSecurity_OnSecurityProblem
271 static IHttpSecurity http_security = { &HttpSecurityVtbl };
273 static HRESULT WINAPI HttpNegotiate_QueryInterface(IHttpNegotiate2 *iface, REFIID riid, void **ppv)
275 if(IsEqualGUID(&IID_IUnknown, riid)
276 || IsEqualGUID(&IID_IHttpNegotiate, riid)
277 || IsEqualGUID(&IID_IHttpNegotiate2, riid)) {
278 *ppv = iface;
279 return S_OK;
282 ok(0, "unexpected call\n");
283 return E_NOINTERFACE;
286 static ULONG WINAPI HttpNegotiate_AddRef(IHttpNegotiate2 *iface)
288 return 2;
291 static ULONG WINAPI HttpNegotiate_Release(IHttpNegotiate2 *iface)
293 return 1;
296 static HRESULT WINAPI HttpNegotiate_BeginningTransaction(IHttpNegotiate2 *iface, LPCWSTR szURL,
297 LPCWSTR szHeaders, DWORD dwReserved, LPWSTR *pszAdditionalHeaders)
299 LPWSTR addl_headers;
301 static const WCHAR wszHeaders[] =
302 {'C','o','n','t','e','n','t','-','T','y','p','e',':',' ','a','p','p','l','i','c','a','t',
303 'i','o','n','/','x','-','w','w','w','-','f','o','r','m','-','u','r','l','e','n','c','o',
304 'd','e','d','\r','\n',0};
306 CHECK_EXPECT(BeginningTransaction);
308 if(binding_test)
309 ok(!lstrcmpW(szURL, binding_urls[tested_protocol]), "szURL != http_url\n");
310 else
311 ok(!lstrcmpW(szURL, http_url), "szURL != http_url\n");
312 ok(!dwReserved, "dwReserved=%d, expected 0\n", dwReserved);
313 ok(pszAdditionalHeaders != NULL, "pszAdditionalHeaders == NULL\n");
314 if(pszAdditionalHeaders)
316 ok(*pszAdditionalHeaders == NULL, "*pszAdditionalHeaders != NULL\n");
317 if (http_post_test)
319 addl_headers = CoTaskMemAlloc(sizeof(wszHeaders));
320 memcpy(addl_headers, wszHeaders, sizeof(wszHeaders));
321 *pszAdditionalHeaders = addl_headers;
325 return S_OK;
328 static HRESULT WINAPI HttpNegotiate_OnResponse(IHttpNegotiate2 *iface, DWORD dwResponseCode,
329 LPCWSTR szResponseHeaders, LPCWSTR szRequestHeaders, LPWSTR *pszAdditionalRequestHeaders)
331 CHECK_EXPECT(OnResponse);
333 ok(dwResponseCode == 200, "dwResponseCode=%d, expected 200\n", dwResponseCode);
334 ok(szResponseHeaders != NULL, "szResponseHeaders == NULL\n");
335 ok(szRequestHeaders == NULL, "szRequestHeaders != NULL\n");
336 ok(pszAdditionalRequestHeaders == NULL, "pszAdditionalHeaders != NULL\n");
338 return S_OK;
341 static HRESULT WINAPI HttpNegotiate_GetRootSecurityId(IHttpNegotiate2 *iface,
342 BYTE *pbSecurityId, DWORD *pcbSecurityId, DWORD_PTR dwReserved)
344 static const BYTE sec_id[] = {'h','t','t','p',':','t','e','s','t',1,0,0,0};
346 CHECK_EXPECT(GetRootSecurityId);
348 ok(!dwReserved, "dwReserved=%ld, expected 0\n", dwReserved);
349 ok(pbSecurityId != NULL, "pbSecurityId == NULL\n");
350 ok(pcbSecurityId != NULL, "pcbSecurityId == NULL\n");
352 if(pcbSecurityId) {
353 ok(*pcbSecurityId == 512, "*pcbSecurityId=%d, expected 512\n", *pcbSecurityId);
354 *pcbSecurityId = sizeof(sec_id);
357 if(pbSecurityId)
358 memcpy(pbSecurityId, sec_id, sizeof(sec_id));
360 return E_FAIL;
363 static IHttpNegotiate2Vtbl HttpNegotiateVtbl = {
364 HttpNegotiate_QueryInterface,
365 HttpNegotiate_AddRef,
366 HttpNegotiate_Release,
367 HttpNegotiate_BeginningTransaction,
368 HttpNegotiate_OnResponse,
369 HttpNegotiate_GetRootSecurityId
372 static IHttpNegotiate2 http_negotiate = { &HttpNegotiateVtbl };
374 static HRESULT QueryInterface(REFIID,void**);
376 static HRESULT WINAPI ServiceProvider_QueryInterface(IServiceProvider *iface, REFIID riid, void **ppv)
378 return QueryInterface(riid, ppv);
381 static ULONG WINAPI ServiceProvider_AddRef(IServiceProvider *iface)
383 return 2;
386 static ULONG WINAPI ServiceProvider_Release(IServiceProvider *iface)
388 return 1;
391 static HRESULT WINAPI ServiceProvider_QueryService(IServiceProvider *iface, REFGUID guidService,
392 REFIID riid, void **ppv)
394 if(IsEqualGUID(&IID_IHttpNegotiate, guidService) || IsEqualGUID(&IID_IHttpNegotiate2, riid)) {
395 CHECK_EXPECT2(QueryService_HttpNegotiate);
396 return IHttpNegotiate2_QueryInterface(&http_negotiate, riid, ppv);
399 if(IsEqualGUID(&IID_IInternetProtocol, guidService)) {
400 ok(IsEqualGUID(&IID_IInternetProtocol, riid), "unexpected riid\n");
401 CHECK_EXPECT(QueryService_InternetProtocol);
402 return E_NOINTERFACE;
405 if(IsEqualGUID(&IID_IHttpSecurity, guidService)) {
406 ok(IsEqualGUID(&IID_IHttpSecurity, riid), "unexpected riid\n");
407 CHECK_EXPECT(QueryService_HttpSecurity);
408 return IHttpSecurity_QueryInterface(&http_security, riid, ppv);
411 ok(0, "unexpected service %s\n", debugstr_guid(guidService));
412 return E_FAIL;
415 static const IServiceProviderVtbl ServiceProviderVtbl = {
416 ServiceProvider_QueryInterface,
417 ServiceProvider_AddRef,
418 ServiceProvider_Release,
419 ServiceProvider_QueryService
422 static IServiceProvider service_provider = { &ServiceProviderVtbl };
424 static HRESULT WINAPI Stream_QueryInterface(IStream *iface, REFIID riid, void **ppv)
426 ok(0, "unexpected call\n");
427 return E_NOINTERFACE;
430 static ULONG WINAPI Stream_AddRef(IStream *iface)
432 return 2;
435 static ULONG WINAPI Stream_Release(IStream *iface)
437 return 1;
440 static HRESULT WINAPI Stream_Read(IStream *iface, void *pv,
441 ULONG cb, ULONG *pcbRead)
443 CHECK_EXPECT2(Stream_Read);
445 ok(GetCurrentThreadId() != thread_id, "wrong thread %d\n", GetCurrentThreadId());
447 ok(pv != NULL, "pv == NULL\n");
448 ok(cb == 0x20000 || broken(cb == 0x2000), "cb = %d\n", cb);
449 ok(pcbRead != NULL, "pcbRead == NULL\n");
451 if(post_stream_read) {
452 *pcbRead = 0;
453 return S_FALSE;
456 memcpy(pv, post_data, sizeof(post_data)-1);
457 post_stream_read += *pcbRead = sizeof(post_data)-1;
458 return S_OK;
461 static HRESULT WINAPI Stream_Write(IStream *iface, const void *pv,
462 ULONG cb, ULONG *pcbWritten)
464 ok(0, "unexpected call\n");
465 return E_NOTIMPL;
468 static HRESULT WINAPI Stream_Seek(IStream *iface, LARGE_INTEGER dlibMove,
469 DWORD dwOrigin, ULARGE_INTEGER *plibNewPosition)
471 CHECK_EXPECT(Stream_Seek);
473 ok(!dlibMove.QuadPart, "dlibMove != 0\n");
474 ok(dwOrigin == STREAM_SEEK_SET, "dwOrigin = %d\n", dwOrigin);
475 ok(!plibNewPosition, "plibNewPosition == NULL\n");
477 return S_OK;
480 static HRESULT WINAPI Stream_SetSize(IStream *iface, ULARGE_INTEGER libNewSize)
482 ok(0, "unexpected call\n");
483 return E_NOTIMPL;
486 static HRESULT WINAPI Stream_CopyTo(IStream *iface, IStream *pstm,
487 ULARGE_INTEGER cb, ULARGE_INTEGER *pcbRead, ULARGE_INTEGER *pcbWritten)
489 ok(0, "unexpected call\n");
490 return E_NOTIMPL;
493 static HRESULT WINAPI Stream_Commit(IStream *iface, DWORD grfCommitFlags)
495 ok(0, "unexpected call\n");
496 return E_NOTIMPL;
499 static HRESULT WINAPI Stream_Revert(IStream *iface)
501 ok(0, "unexpected call\n");
502 return E_NOTIMPL;
505 static HRESULT WINAPI Stream_LockRegion(IStream *iface, ULARGE_INTEGER libOffset,
506 ULARGE_INTEGER cb, DWORD dwLockType)
508 ok(0, "unexpected call\n");
509 return E_NOTIMPL;
512 static HRESULT WINAPI Stream_UnlockRegion(IStream *iface,
513 ULARGE_INTEGER libOffset, ULARGE_INTEGER cb, DWORD dwLockType)
515 ok(0, "unexpected call\n");
516 return E_NOTIMPL;
519 static HRESULT WINAPI Stream_Stat(IStream *iface, STATSTG *pstatstg,
520 DWORD dwStatFlag)
522 ok(0, "unexpected call\n");
523 return E_NOTIMPL;
526 static HRESULT WINAPI Stream_Clone(IStream *iface, IStream **ppstm)
528 ok(0, "unexpected call\n");
529 return E_NOTIMPL;
532 static const IStreamVtbl StreamVtbl = {
533 Stream_QueryInterface,
534 Stream_AddRef,
535 Stream_Release,
536 Stream_Read,
537 Stream_Write,
538 Stream_Seek,
539 Stream_SetSize,
540 Stream_CopyTo,
541 Stream_Commit,
542 Stream_Revert,
543 Stream_LockRegion,
544 Stream_UnlockRegion,
545 Stream_Stat,
546 Stream_Clone
549 static IStream Stream = { &StreamVtbl };
551 static HRESULT WINAPI ProtocolSink_QueryInterface(IInternetProtocolSink *iface, REFIID riid, void **ppv)
553 return QueryInterface(riid, ppv);
556 static ULONG WINAPI ProtocolSink_AddRef(IInternetProtocolSink *iface)
558 return 2;
561 static ULONG WINAPI ProtocolSink_Release(IInternetProtocolSink *iface)
563 return 1;
566 static void call_continue(PROTOCOLDATA *protocol_data)
568 HRESULT hres;
570 if(state == STATE_CONNECTING) {
571 if(tested_protocol == HTTP_TEST || tested_protocol == HTTPS_TEST)
572 CLEAR_CALLED(ReportProgress_COOKIE_SENT);
573 if(tested_protocol == HTTP_TEST || tested_protocol == HTTPS_TEST || tested_protocol == FTP_TEST) {
574 if (http_is_first){
575 CLEAR_CALLED(ReportProgress_FINDINGRESOURCE);
576 CLEAR_CALLED(ReportProgress_PROXYDETECTING);
578 CLEAR_CALLED(ReportProgress_CONNECTING);
580 if(tested_protocol == FTP_TEST)
581 todo_wine CHECK_CALLED(ReportProgress_SENDINGREQUEST);
582 else if (tested_protocol != HTTPS_TEST)
583 CHECK_CALLED(ReportProgress_SENDINGREQUEST);
584 if(test_redirect)
585 CHECK_CALLED(ReportProgress_REDIRECTING);
586 state = test_async_req ? STATE_SENDINGREQUEST : STATE_STARTDOWNLOADING;
589 switch(state) {
590 case STATE_SENDINGREQUEST:
591 SET_EXPECT(Stream_Read);
592 SET_EXPECT(ReportProgress_SENDINGREQUEST);
593 break;
594 case STATE_STARTDOWNLOADING:
595 if(tested_protocol == HTTP_TEST || tested_protocol == HTTPS_TEST) {
596 SET_EXPECT(OnResponse);
597 if(tested_protocol == HTTPS_TEST || test_redirect || test_abort || empty_file)
598 SET_EXPECT(ReportProgress_ACCEPTRANGES);
599 SET_EXPECT(ReportProgress_MIMETYPEAVAILABLE);
600 if(bindf & BINDF_NEEDFILE)
601 SET_EXPECT(ReportProgress_CACHEFILENAMEAVAILABLE);
603 default:
604 break;
607 if(state != STATE_SENDINGREQUEST)
608 SET_EXPECT(ReportData);
609 hres = IInternetProtocol_Continue(async_protocol, protocol_data);
610 ok(hres == S_OK, "Continue failed: %08x\n", hres);
611 if(tested_protocol == FTP_TEST || security_problem)
612 CLEAR_CALLED(ReportData);
613 else if(state != STATE_SENDINGREQUEST)
614 CHECK_CALLED(ReportData);
616 switch(state) {
617 case STATE_SENDINGREQUEST:
618 CHECK_CALLED(Stream_Read);
619 CHECK_CALLED(ReportProgress_SENDINGREQUEST);
620 state = STATE_STARTDOWNLOADING;
621 break;
622 case STATE_STARTDOWNLOADING:
623 if (! security_problem)
625 state = STATE_DOWNLOADING;
626 if(tested_protocol == HTTP_TEST || tested_protocol == HTTPS_TEST) {
627 CHECK_CALLED(OnResponse);
628 if(tested_protocol == HTTPS_TEST || empty_file)
629 CHECK_CALLED(ReportProgress_ACCEPTRANGES);
630 else if(test_redirect || test_abort)
631 CLEAR_CALLED(ReportProgress_ACCEPTRANGES);
632 CHECK_CALLED(ReportProgress_MIMETYPEAVAILABLE);
633 if(bindf & BINDF_NEEDFILE)
634 CHECK_CALLED(ReportProgress_CACHEFILENAMEAVAILABLE);
637 else
639 security_problem = FALSE;
640 SET_EXPECT(ReportProgress_CONNECTING);
642 default:
643 break;
647 static HRESULT WINAPI ProtocolSink_Switch(IInternetProtocolSink *iface, PROTOCOLDATA *pProtocolData)
649 if(tested_protocol == FTP_TEST)
650 CHECK_EXPECT2(Switch);
651 else
652 CHECK_EXPECT(Switch);
654 ok(pProtocolData != NULL, "pProtocolData == NULL\n");
655 if(binding_test) {
656 ok(pProtocolData != &protocoldata, "pProtocolData == &protocoldata\n");
657 ok(pProtocolData->grfFlags == protocoldata.grfFlags, "grfFlags wrong %x/%x\n",
658 pProtocolData->grfFlags, protocoldata.grfFlags );
659 ok(pProtocolData->dwState == protocoldata.dwState, "dwState wrong %x/%x\n",
660 pProtocolData->dwState, protocoldata.dwState );
661 ok(pProtocolData->pData == protocoldata.pData, "pData wrong %p/%p\n",
662 pProtocolData->pData, protocoldata.pData );
663 ok(pProtocolData->cbData == protocoldata.cbData, "cbData wrong %x/%x\n",
664 pProtocolData->cbData, protocoldata.cbData );
667 pdata = pProtocolData;
669 if(binding_test) {
670 SetEvent(event_complete);
671 WaitForSingleObject(event_complete2, INFINITE);
672 return S_OK;
673 }if(direct_read) {
674 continue_protdata = *pProtocolData;
675 SetEvent(event_continue);
676 WaitForSingleObject(event_continue_done, INFINITE);
677 }else {
678 call_continue(pProtocolData);
679 SetEvent(event_complete);
682 return S_OK;
685 static HRESULT WINAPI ProtocolSink_ReportProgress(IInternetProtocolSink *iface, ULONG ulStatusCode,
686 LPCWSTR szStatusText)
688 static const WCHAR null_guid[] = {'{','0','0','0','0','0','0','0','0','-','0','0','0','0','-',
689 '0','0','0','0','-','0','0','0','0','-','0','0','0','0','0','0','0','0','0','0','0','0','}',0};
690 static const WCHAR text_plain[] = {'t','e','x','t','/','p','l','a','i','n',0};
692 switch(ulStatusCode) {
693 case BINDSTATUS_MIMETYPEAVAILABLE:
694 CHECK_EXPECT(ReportProgress_MIMETYPEAVAILABLE);
695 if(tested_protocol != FILE_TEST && tested_protocol != ITS_TEST && !mimefilter_test && (pi & PI_MIMEVERIFICATION)) {
696 if(!short_read || !direct_read)
697 CHECK_CALLED(Read); /* set in Continue */
698 else if(short_read)
699 CHECK_CALLED(Read2); /* set in Read */
701 ok(szStatusText != NULL, "szStatusText == NULL\n");
702 if(szStatusText) {
703 if(tested_protocol == BIND_TEST)
704 ok(!lstrcmpW(szStatusText, expect_wsz), "unexpected szStatusText %s\n", wine_dbgstr_w(szStatusText));
705 else if (http_post_test)
706 ok(lstrlenW(text_plain) <= lstrlenW(szStatusText) &&
707 !memcmp(szStatusText, text_plain, lstrlenW(text_plain)*sizeof(WCHAR)),
708 "szStatusText != text/plain\n");
709 else if(empty_file)
710 ok(!strcmp_wa(szStatusText, "application/javascript"), "szStatusText = %s\n", wine_dbgstr_w(szStatusText));
711 else if(!mimefilter_test)
712 ok(lstrlenW(text_htmlW) <= lstrlenW(szStatusText) &&
713 !memcmp(szStatusText, text_htmlW, lstrlenW(text_htmlW)*sizeof(WCHAR)),
714 "szStatusText != text/html\n");
716 break;
717 case BINDSTATUS_DIRECTBIND:
718 CHECK_EXPECT2(ReportProgress_DIRECTBIND);
719 ok(szStatusText == NULL, "szStatusText != NULL\n");
720 break;
721 case BINDSTATUS_RAWMIMETYPE:
722 CHECK_EXPECT2(ReportProgress_RAWMIMETYPE);
723 ok(szStatusText != NULL, "szStatusText == NULL\n");
724 if(szStatusText)
725 ok(lstrlenW(szStatusText) < lstrlenW(text_htmlW) ||
726 !memcmp(szStatusText, text_htmlW, lstrlenW(text_htmlW)*sizeof(WCHAR)),
727 "szStatusText != text/html\n");
728 break;
729 case BINDSTATUS_CACHEFILENAMEAVAILABLE:
730 CHECK_EXPECT(ReportProgress_CACHEFILENAMEAVAILABLE);
731 ok(szStatusText != NULL, "szStatusText == NULL\n");
732 if(szStatusText) {
733 if(binding_test)
734 ok(!lstrcmpW(szStatusText, expect_wsz), "unexpected szStatusText\n");
735 else if(tested_protocol == FILE_TEST)
736 ok(!lstrcmpW(szStatusText, file_name), "szStatusText = %s\n", wine_dbgstr_w(szStatusText));
737 else
738 ok(szStatusText != NULL, "szStatusText == NULL\n");
740 break;
741 case BINDSTATUS_FINDINGRESOURCE:
742 CHECK_EXPECT2(ReportProgress_FINDINGRESOURCE);
743 ok(szStatusText != NULL, "szStatusText == NULL\n");
744 break;
745 case BINDSTATUS_CONNECTING:
746 CHECK_EXPECT2(ReportProgress_CONNECTING);
747 ok(szStatusText != NULL, "szStatusText == NULL\n");
748 break;
749 case BINDSTATUS_SENDINGREQUEST:
750 CHECK_EXPECT2(ReportProgress_SENDINGREQUEST);
751 if(tested_protocol == FILE_TEST || tested_protocol == ITS_TEST) {
752 ok(szStatusText != NULL, "szStatusText == NULL\n");
753 if(szStatusText)
754 ok(!*szStatusText, "wrong szStatusText\n");
756 break;
757 case BINDSTATUS_VERIFIEDMIMETYPEAVAILABLE:
758 CHECK_EXPECT(ReportProgress_VERIFIEDMIMETYPEAVAILABLE);
759 ok(szStatusText != NULL, "szStatusText == NULL\n");
760 if(szStatusText)
761 ok(!strcmp_wa(szStatusText, "text/html"), "szStatusText != text/html\n");
762 break;
763 case BINDSTATUS_PROTOCOLCLASSID:
764 CHECK_EXPECT(ReportProgress_PROTOCOLCLASSID);
765 ok(szStatusText != NULL, "szStatusText == NULL\n");
766 ok(!lstrcmpW(szStatusText, null_guid), "unexpected classid %s\n", wine_dbgstr_w(szStatusText));
767 break;
768 case BINDSTATUS_COOKIE_SENT:
769 CHECK_EXPECT(ReportProgress_COOKIE_SENT);
770 ok(szStatusText == NULL, "szStatusText != NULL\n");
771 break;
772 case BINDSTATUS_REDIRECTING:
773 CHECK_EXPECT(ReportProgress_REDIRECTING);
774 if(test_redirect)
775 ok(!strcmp_wa(szStatusText, "http://test.winehq.org/tests/hello.html"), "szStatusText = %s\n", wine_dbgstr_w(szStatusText));
776 else
777 ok(szStatusText == NULL, "szStatusText = %s\n", wine_dbgstr_w(szStatusText));
778 break;
779 case BINDSTATUS_ENCODING:
780 CHECK_EXPECT(ReportProgress_ENCODING);
781 ok(!strcmp_wa(szStatusText, "gzip"), "szStatusText = %s\n", wine_dbgstr_w(szStatusText));
782 break;
783 case BINDSTATUS_ACCEPTRANGES:
784 CHECK_EXPECT(ReportProgress_ACCEPTRANGES);
785 ok(!szStatusText, "szStatusText = %s\n", wine_dbgstr_w(szStatusText));
786 break;
787 case BINDSTATUS_PROXYDETECTING:
788 if(!called_ReportProgress_PROXYDETECTING)
789 SET_EXPECT(ReportProgress_CONNECTING);
790 CHECK_EXPECT2(ReportProgress_PROXYDETECTING);
791 ok(!szStatusText, "szStatusText = %s\n", wine_dbgstr_w(szStatusText));
792 break;
793 case BINDSTATUS_LOADINGMIMEHANDLER:
794 CHECK_EXPECT(ReportProgress_LOADINGMIMEHANDLER);
795 ok(!szStatusText, "szStatusText = %s\n", wine_dbgstr_w(szStatusText));
796 break;
797 case BINDSTATUS_DECODING:
798 CHECK_EXPECT(ReportProgress_DECODING);
799 ok(!lstrcmpW(szStatusText, gzipW), "szStatusText = %s\n", wine_dbgstr_w(szStatusText));
800 break;
801 default:
802 ok(0, "Unexpected status %d\n", ulStatusCode);
805 return S_OK;
808 static HRESULT WINAPI ProtocolSink_ReportData(IInternetProtocolSink *iface, DWORD grfBSCF,
809 ULONG ulProgress, ULONG ulProgressMax)
811 HRESULT hres;
813 static int rec_depth;
814 rec_depth++;
816 if(!mimefilter_test && (tested_protocol == FILE_TEST || tested_protocol == ITS_TEST)) {
817 CHECK_EXPECT2(ReportData);
819 ok(ulProgress == ulProgressMax, "ulProgress (%d) != ulProgressMax (%d)\n",
820 ulProgress, ulProgressMax);
821 ok(ulProgressMax == 13, "ulProgressMax=%d, expected 13\n", ulProgressMax);
822 /* BSCF_SKIPDRAINDATAFORFILEURLS added in IE8 */
823 if(tested_protocol == FILE_TEST)
824 ok((grfBSCF == (BSCF_FIRSTDATANOTIFICATION | BSCF_LASTDATANOTIFICATION)) ||
825 (grfBSCF == (BSCF_FIRSTDATANOTIFICATION | BSCF_LASTDATANOTIFICATION | BSCF_SKIPDRAINDATAFORFILEURLS)),
826 "grcfBSCF = %08x\n", grfBSCF);
827 else
828 ok(grfBSCF == (BSCF_FIRSTDATANOTIFICATION | BSCF_DATAFULLYAVAILABLE), "grcfBSCF = %08x\n", grfBSCF);
829 }else if(direct_read) {
830 BYTE buf[14096];
831 ULONG read;
833 if(!read_report_data && rec_depth == 1) {
834 BOOL reported_all_data = called_ReportData2;
836 CHECK_EXPECT2(ReportData);
838 if(short_read) {
839 ok(grfBSCF == (BSCF_FIRSTDATANOTIFICATION|BSCF_LASTDATANOTIFICATION|BSCF_DATAFULLYAVAILABLE)
840 || grfBSCF == BSCF_FIRSTDATANOTIFICATION, /* < IE8 */
841 "grcfBSCF = %08x\n", grfBSCF);
842 CHECK_CALLED(Read); /* Set in Continue */
843 first_data_notif = FALSE;
844 }else if(first_data_notif) {
845 ok(grfBSCF == BSCF_FIRSTDATANOTIFICATION, "grcfBSCF = %08x\n", grfBSCF);
846 first_data_notif = FALSE;
847 }else if(reported_all_data) {
848 ok(grfBSCF == (BSCF_LASTDATANOTIFICATION|BSCF_INTERMEDIATEDATANOTIFICATION),
849 "grcfBSCF = %08x\n", grfBSCF);
850 }else if(!direct_read) {
851 ok(grfBSCF == BSCF_INTERMEDIATEDATANOTIFICATION, "grcfBSCF = %08x\n", grfBSCF);
854 do {
855 read = 0;
856 if(emulate_prot)
857 SET_EXPECT(Read);
858 else
859 SET_EXPECT(ReportData2);
860 SET_EXPECT(ReportResult);
861 if(!emulate_prot)
862 SET_EXPECT(Switch);
863 hres = IInternetProtocol_Read(binding_test ? binding_protocol : async_protocol, expect_pv = buf, sizeof(buf), &read);
864 ok(hres == E_PENDING || hres == S_FALSE || hres == S_OK, "Read failed: %08x\n", hres);
865 if(hres == S_OK)
866 ok(read, "read == 0\n");
867 if(reported_all_data)
868 ok(hres == S_FALSE, "Read failed: %08x, expected S_FALSE\n", hres);
869 if(!emulate_prot && hres != E_PENDING)
870 CHECK_NOT_CALLED(Switch); /* otherwise checked in wait_for_switch loop */
871 if(emulate_prot)
872 CHECK_CALLED(Read);
873 if(!reported_all_data && called_ReportData2) {
874 if(!emulate_prot)
875 CHECK_CALLED(ReportData2);
876 CHECK_CALLED(ReportResult);
877 ok(hres == S_OK, "Read failed: %08x\n", hres);
878 reported_all_data = TRUE;
879 }else {
880 if(!emulate_prot)
881 CHECK_NOT_CALLED(ReportData2);
882 CHECK_NOT_CALLED(ReportResult);
884 }while(hres == S_OK);
885 if(hres == S_FALSE)
886 wait_for_switch = FALSE;
887 }else {
888 CHECK_EXPECT(ReportData2);
890 ok(grfBSCF & BSCF_LASTDATANOTIFICATION, "grfBSCF = %08x\n", grfBSCF);
892 read = 0xdeadbeef;
893 if(emulate_prot)
894 SET_EXPECT(Read2);
895 hres = IInternetProtocol_Read(binding_test ? binding_protocol : async_protocol, expect_pv = buf, sizeof(buf), &read);
896 if(emulate_prot)
897 CHECK_CALLED(Read2);
898 ok(hres == S_FALSE, "Read returned: %08x, expected E_FALSE\n", hres);
899 ok(!read, "read = %d\n", read);
901 }else if(!binding_test && (tested_protocol == HTTP_TEST || tested_protocol == HTTPS_TEST
902 || tested_protocol == FTP_TEST)) {
903 if(empty_file)
904 CHECK_EXPECT2(ReportData);
905 else if(!(grfBSCF & BSCF_LASTDATANOTIFICATION) || (grfBSCF & BSCF_DATAFULLYAVAILABLE))
906 CHECK_EXPECT(ReportData);
907 else if (http_post_test)
908 ok(ulProgress == 13, "Read %u bytes instead of 13\n", ulProgress);
910 if(empty_file) {
911 ok(!ulProgress, "ulProgress = %d\n", ulProgress);
912 ok(!ulProgressMax, "ulProgressMax = %d\n", ulProgressMax);
913 }else {
914 ok(ulProgress, "ulProgress == 0\n");
917 if(empty_file) {
918 ok(grfBSCF == (BSCF_FIRSTDATANOTIFICATION|BSCF_LASTDATANOTIFICATION),
919 "grcfBSCF = %08x\n", grfBSCF);
920 first_data_notif = FALSE;
921 }else if(first_data_notif) {
922 ok(grfBSCF == BSCF_FIRSTDATANOTIFICATION
923 || grfBSCF == (BSCF_LASTDATANOTIFICATION|BSCF_DATAFULLYAVAILABLE),
924 "grcfBSCF = %08x\n", grfBSCF);
925 first_data_notif = FALSE;
926 } else {
927 ok(grfBSCF == BSCF_INTERMEDIATEDATANOTIFICATION
928 || grfBSCF == (BSCF_LASTDATANOTIFICATION|BSCF_INTERMEDIATEDATANOTIFICATION)
929 || broken(grfBSCF == (BSCF_FIRSTDATANOTIFICATION|BSCF_LASTDATANOTIFICATION)),
930 "grcfBSCF = %08x\n", grfBSCF);
933 if(!(bindf & BINDF_FROMURLMON) &&
934 !(grfBSCF & BSCF_LASTDATANOTIFICATION)) {
935 if(state == STATE_CONNECTING) {
936 state = STATE_DOWNLOADING;
937 if(http_is_first) {
938 CHECK_CALLED(ReportProgress_FINDINGRESOURCE);
939 CHECK_CALLED(ReportProgress_CONNECTING);
941 CHECK_CALLED(ReportProgress_SENDINGREQUEST);
942 CHECK_CALLED(OnResponse);
943 CHECK_CALLED(ReportProgress_RAWMIMETYPE);
945 SetEvent(event_complete);
947 }else if(!read_report_data) {
948 BYTE buf[1000];
949 ULONG read;
950 HRESULT hres;
952 CHECK_EXPECT(ReportData);
954 if(tested_protocol != BIND_TEST) {
955 do {
956 if(mimefilter_test)
957 SET_EXPECT(MimeFilter_Read);
958 else if(rec_depth > 1)
959 SET_EXPECT(Read2);
960 else
961 SET_EXPECT(Read);
962 hres = IInternetProtocol_Read(binding_protocol, expect_pv=buf, sizeof(buf), &read);
963 if(mimefilter_test)
964 CHECK_CALLED(MimeFilter_Read);
965 else if(rec_depth > 1)
966 CHECK_CALLED(Read2);
967 else
968 CHECK_CALLED(Read);
969 }while(hres == S_OK);
973 rec_depth--;
974 return S_OK;
977 static HRESULT WINAPI ProtocolSink_ReportResult(IInternetProtocolSink *iface, HRESULT hrResult,
978 DWORD dwError, LPCWSTR szResult)
980 CHECK_EXPECT(ReportResult);
982 if(tested_protocol == FTP_TEST)
983 ok(hrResult == E_PENDING || hrResult == S_OK, "hrResult = %08x, expected E_PENDING or S_OK\n", hrResult);
984 else
985 ok(hrResult == expect_hrResult, "hrResult = %08x, expected: %08x\n",
986 hrResult, expect_hrResult);
987 if(SUCCEEDED(hrResult) || tested_protocol == FTP_TEST || test_abort)
988 ok(dwError == ERROR_SUCCESS, "dwError = %d, expected ERROR_SUCCESS\n", dwError);
989 else
990 ok(dwError != ERROR_SUCCESS ||
991 broken(tested_protocol == MK_TEST), /* WinME and NT4 */
992 "dwError == ERROR_SUCCESS\n");
993 ok(!szResult, "szResult != NULL\n");
995 if(direct_read)
996 SET_EXPECT(ReportData); /* checked after main loop */
998 return S_OK;
1001 static IInternetProtocolSinkVtbl protocol_sink_vtbl = {
1002 ProtocolSink_QueryInterface,
1003 ProtocolSink_AddRef,
1004 ProtocolSink_Release,
1005 ProtocolSink_Switch,
1006 ProtocolSink_ReportProgress,
1007 ProtocolSink_ReportData,
1008 ProtocolSink_ReportResult
1011 static IInternetProtocolSink protocol_sink = { &protocol_sink_vtbl };
1013 static HRESULT WINAPI MimeProtocolSink_QueryInterface(IInternetProtocolSink *iface, REFIID riid, void **ppv)
1015 ok(0, "unexpected call\n");
1016 return E_NOTIMPL;
1019 static ULONG WINAPI MimeProtocolSink_AddRef(IInternetProtocolSink *iface)
1021 return 2;
1024 static ULONG WINAPI MimeProtocolSink_Release(IInternetProtocolSink *iface)
1026 return 1;
1029 static HRESULT WINAPI MimeProtocolSink_Switch(IInternetProtocolSink *iface, PROTOCOLDATA *pProtocolData)
1031 HRESULT hres;
1033 CHECK_EXPECT(MimeFilter_Switch);
1035 SET_EXPECT(Switch);
1036 hres = IInternetProtocolSink_Switch(filtered_sink, pProtocolData);
1037 ok(hres == S_OK, "Switch failed: %08x\n", hres);
1038 CHECK_CALLED(Switch);
1040 return S_OK;
1043 static HRESULT WINAPI MimeProtocolSink_ReportProgress(IInternetProtocolSink *iface, ULONG ulStatusCode,
1044 LPCWSTR szStatusText)
1046 CHECK_EXPECT(MimeFilter_ReportProgress);
1047 return S_OK;
1050 static HRESULT WINAPI MimeProtocolSink_ReportData(IInternetProtocolSink *iface, DWORD grfBSCF,
1051 ULONG ulProgress, ULONG ulProgressMax)
1053 DWORD read = 0;
1054 BYTE buf[8192];
1055 HRESULT hres;
1057 CHECK_EXPECT(MimeFilter_ReportData);
1059 if(!filter_state) {
1060 SET_EXPECT(Read);
1061 hres = IInternetProtocol_Read(filtered_protocol, buf, sizeof(buf), &read);
1062 if(tested_protocol == HTTP_TEST)
1063 ok(hres == S_OK || hres == E_PENDING || hres == S_FALSE, "Read failed: %08x\n", hres);
1064 else
1065 ok(hres == S_OK, "Read failed: %08x\n", hres);
1066 CHECK_CALLED(Read);
1068 SET_EXPECT(ReportProgress_MIMETYPEAVAILABLE);
1069 hres = IInternetProtocolSink_ReportProgress(filtered_sink, BINDSTATUS_VERIFIEDMIMETYPEAVAILABLE, text_htmlW);
1070 ok(hres == S_OK, "ReportProgress failed: %08x\n", hres);
1071 CHECK_CALLED(ReportProgress_MIMETYPEAVAILABLE);
1073 /* FIXME: test BINDSTATUS_CACHEFILENAMEAVAILABLE */
1076 if(!read_report_data)
1077 SET_EXPECT(ReportData);
1078 hres = IInternetProtocolSink_ReportData(filtered_sink, grfBSCF, ulProgress, ulProgressMax);
1079 ok(hres == S_OK, "ReportData failed: %08x\n", hres);
1080 if(!read_report_data)
1081 CHECK_CALLED(ReportData);
1083 if(!filter_state)
1084 filter_state = 1;
1086 return S_OK;
1089 static HRESULT WINAPI MimeProtocolSink_ReportResult(IInternetProtocolSink *iface, HRESULT hrResult,
1090 DWORD dwError, LPCWSTR szResult)
1092 HRESULT hres;
1094 CHECK_EXPECT(MimeFilter_ReportResult);
1096 ok(hrResult == S_OK, "hrResult = %08x\n", hrResult);
1097 ok(dwError == ERROR_SUCCESS, "dwError = %u\n", dwError);
1098 ok(!szResult, "szResult = %s\n", wine_dbgstr_w(szResult));
1100 SET_EXPECT(ReportResult);
1101 hres = IInternetProtocolSink_ReportResult(filtered_sink, hrResult, dwError, szResult);
1102 ok(SUCCEEDED(hres), "ReportResult failed: %08x\n", hres);
1103 CHECK_CALLED(ReportResult);
1105 return S_OK;
1108 static IInternetProtocolSinkVtbl mime_protocol_sink_vtbl = {
1109 MimeProtocolSink_QueryInterface,
1110 MimeProtocolSink_AddRef,
1111 MimeProtocolSink_Release,
1112 MimeProtocolSink_Switch,
1113 MimeProtocolSink_ReportProgress,
1114 MimeProtocolSink_ReportData,
1115 MimeProtocolSink_ReportResult
1118 static IInternetProtocolSink mime_protocol_sink = { &mime_protocol_sink_vtbl };
1120 static HRESULT QueryInterface(REFIID riid, void **ppv)
1122 static const IID IID_undocumented = {0x58DFC7D0,0x5381,0x43E5,{0x9D,0x72,0x4C,0xDD,0xE4,0xCB,0x0F,0x1A}};
1124 *ppv = NULL;
1126 if(IsEqualGUID(&IID_IUnknown, riid) || IsEqualGUID(&IID_IInternetProtocolSink, riid))
1127 *ppv = &protocol_sink;
1128 if(IsEqualGUID(&IID_IServiceProvider, riid))
1129 *ppv = &service_provider;
1130 if(IsEqualGUID(&IID_IUriContainer, riid))
1131 return E_NOINTERFACE; /* TODO */
1133 /* NOTE: IE8 queries for undocumented {58DFC7D0-5381-43E5-9D72-4CDDE4CB0F1A} interface. */
1134 if(IsEqualGUID(&IID_undocumented, riid))
1135 return E_NOINTERFACE;
1137 if(*ppv)
1138 return S_OK;
1140 ok(0, "unexpected call %s\n", debugstr_guid(riid));
1141 return E_NOINTERFACE;
1144 static HRESULT WINAPI BindInfo_QueryInterface(IInternetBindInfo *iface, REFIID riid, void **ppv)
1146 if(IsEqualGUID(&IID_IUnknown, riid) || IsEqualGUID(&IID_IInternetBindInfo, riid)) {
1147 *ppv = iface;
1148 return S_OK;
1150 return E_NOINTERFACE;
1153 static ULONG WINAPI BindInfo_AddRef(IInternetBindInfo *iface)
1155 return 2;
1158 static ULONG WINAPI BindInfo_Release(IInternetBindInfo *iface)
1160 return 1;
1163 static HRESULT WINAPI BindInfo_GetBindInfo(IInternetBindInfo *iface, DWORD *grfBINDF, BINDINFO *pbindinfo)
1165 DWORD cbSize;
1167 CHECK_EXPECT(GetBindInfo);
1169 ok(grfBINDF != NULL, "grfBINDF == NULL\n");
1170 ok(pbindinfo != NULL, "pbindinfo == NULL\n");
1171 ok(pbindinfo->cbSize == sizeof(BINDINFO), "wrong size of pbindinfo: %d\n", pbindinfo->cbSize);
1173 *grfBINDF = bindf;
1174 if(binding_test)
1175 *grfBINDF |= BINDF_FROMURLMON;
1176 cbSize = pbindinfo->cbSize;
1177 memset(pbindinfo, 0, cbSize);
1178 pbindinfo->cbSize = cbSize;
1180 if(http_post_test)
1182 pbindinfo->cbstgmedData = sizeof(post_data)-1;
1183 pbindinfo->dwBindVerb = BINDVERB_POST;
1184 pbindinfo->stgmedData.tymed = http_post_test;
1186 if(http_post_test == TYMED_HGLOBAL) {
1187 HGLOBAL data;
1189 /* Must be GMEM_FIXED, GMEM_MOVABLE does not work properly */
1190 data = GlobalAlloc(GPTR, sizeof(post_data));
1191 memcpy(data, post_data, sizeof(post_data));
1192 U(pbindinfo->stgmedData).hGlobal = data;
1193 }else {
1194 IStream *post_stream;
1195 HGLOBAL data;
1196 HRESULT hres;
1198 if(0) {
1199 /* Must be GMEM_FIXED, GMEM_MOVABLE does not work properly */
1200 data = GlobalAlloc(GPTR, sizeof(post_data));
1201 memcpy(data, post_data, sizeof(post_data));
1202 U(pbindinfo->stgmedData).hGlobal = data;
1204 hres = CreateStreamOnHGlobal(data, FALSE, &post_stream);
1205 ok(hres == S_OK, "CreateStreamOnHGlobal failed: %08x\n", hres);
1207 U(pbindinfo->stgmedData).pstm =post_stream;/* &Stream; */
1209 U(pbindinfo->stgmedData).pstm = &Stream;
1213 return S_OK;
1216 static HRESULT WINAPI BindInfo_GetBindString(IInternetBindInfo *iface, ULONG ulStringType,
1217 LPOLESTR *ppwzStr, ULONG cEl, ULONG *pcElFetched)
1219 ok(ppwzStr != NULL, "ppwzStr == NULL\n");
1220 ok(pcElFetched != NULL, "pcElFetched == NULL\n");
1222 switch(ulStringType) {
1223 case BINDSTRING_ACCEPT_MIMES:
1224 CHECK_EXPECT(GetBindString_ACCEPT_MIMES);
1225 ok(cEl == 256, "cEl=%d, expected 256\n", cEl);
1226 if(pcElFetched) {
1227 ok(*pcElFetched == 256, "*pcElFetched=%d, expected 256\n", *pcElFetched);
1228 *pcElFetched = 1;
1230 if(ppwzStr) {
1231 *ppwzStr = CoTaskMemAlloc(sizeof(acc_mimeW));
1232 memcpy(*ppwzStr, acc_mimeW, sizeof(acc_mimeW));
1234 return S_OK;
1235 case BINDSTRING_USER_AGENT:
1236 CHECK_EXPECT(GetBindString_USER_AGENT);
1237 ok(cEl == 1, "cEl=%d, expected 1\n", cEl);
1238 if(pcElFetched) {
1239 ok(*pcElFetched == 0, "*pcElFetch=%d, expectd 0\n", *pcElFetched);
1240 *pcElFetched = 1;
1242 if(ppwzStr) {
1243 *ppwzStr = CoTaskMemAlloc(sizeof(user_agentW));
1244 memcpy(*ppwzStr, user_agentW, sizeof(user_agentW));
1246 return S_OK;
1247 case BINDSTRING_POST_COOKIE:
1248 CHECK_EXPECT(GetBindString_POST_COOKIE);
1249 ok(cEl == 1, "cEl=%d, expected 1\n", cEl);
1250 if(pcElFetched)
1251 ok(*pcElFetched == 0, "*pcElFetch=%d, expectd 0\n", *pcElFetched);
1252 return S_OK;
1253 case BINDSTRING_URL: {
1254 DWORD size;
1256 CHECK_EXPECT(GetBindString_URL);
1257 ok(cEl == 1, "cEl=%d, expected 1\n", cEl);
1258 ok(*pcElFetched == 0, "*pcElFetch=%d, expectd 0\n", *pcElFetched);
1259 *pcElFetched = 1;
1261 size = (lstrlenW(binding_urls[tested_protocol])+1)*sizeof(WCHAR);
1262 *ppwzStr = CoTaskMemAlloc(size);
1263 memcpy(*ppwzStr, binding_urls[tested_protocol], size);
1264 return S_OK;
1266 default:
1267 ok(0, "unexpected call\n");
1270 return E_NOTIMPL;
1273 static IInternetBindInfoVtbl bind_info_vtbl = {
1274 BindInfo_QueryInterface,
1275 BindInfo_AddRef,
1276 BindInfo_Release,
1277 BindInfo_GetBindInfo,
1278 BindInfo_GetBindString
1281 static IInternetBindInfo bind_info = { &bind_info_vtbl };
1283 static HRESULT WINAPI InternetPriority_QueryInterface(IInternetPriority *iface,
1284 REFIID riid, void **ppv)
1286 ok(0, "unexpected call\n");
1287 return E_NOINTERFACE;
1290 static ULONG WINAPI InternetPriority_AddRef(IInternetPriority *iface)
1292 return 2;
1295 static ULONG WINAPI InternetPriority_Release(IInternetPriority *iface)
1297 return 1;
1300 static HRESULT WINAPI InternetPriority_SetPriority(IInternetPriority *iface, LONG nPriority)
1302 CHECK_EXPECT(SetPriority);
1303 ok(nPriority == ex_priority, "nPriority=%d\n", nPriority);
1304 return S_OK;
1307 static HRESULT WINAPI InternetPriority_GetPriority(IInternetPriority *iface, LONG *pnPriority)
1309 ok(0, "unexpected call\n");
1310 return E_NOTIMPL;
1314 static const IInternetPriorityVtbl InternetPriorityVtbl = {
1315 InternetPriority_QueryInterface,
1316 InternetPriority_AddRef,
1317 InternetPriority_Release,
1318 InternetPriority_SetPriority,
1319 InternetPriority_GetPriority
1322 static IInternetPriority InternetPriority = { &InternetPriorityVtbl };
1324 static ULONG WINAPI Protocol_AddRef(IInternetProtocolEx *iface)
1326 return 2;
1329 static ULONG WINAPI Protocol_Release(IInternetProtocolEx *iface)
1331 return 1;
1334 static HRESULT WINAPI Protocol_Abort(IInternetProtocolEx *iface, HRESULT hrReason,
1335 DWORD dwOptions)
1337 HRESULT hres;
1339 CHECK_EXPECT(Abort);
1341 SET_EXPECT(ReportResult);
1342 hres = IInternetProtocolSink_ReportResult(binding_sink, S_OK, ERROR_SUCCESS, NULL);
1343 ok(hres == S_OK, "ReportResult failed: %08x\n", hres);
1344 CHECK_CALLED(ReportResult);
1346 return S_OK;
1349 static HRESULT WINAPI Protocol_Suspend(IInternetProtocolEx *iface)
1351 ok(0, "unexpected call\n");
1352 return E_NOTIMPL;
1355 static HRESULT WINAPI Protocol_Resume(IInternetProtocolEx *iface)
1357 ok(0, "unexpected call\n");
1358 return E_NOTIMPL;
1361 static HRESULT WINAPI Protocol_Seek(IInternetProtocolEx *iface,
1362 LARGE_INTEGER dlibMove, DWORD dwOrigin, ULARGE_INTEGER *plibNewPosition)
1364 ok(0, "unexpected call\n");
1365 return E_NOTIMPL;
1368 static HRESULT WINAPI ProtocolEmul_QueryInterface(IInternetProtocolEx *iface, REFIID riid, void **ppv)
1370 if(IsEqualGUID(&IID_IUnknown, riid) || IsEqualGUID(&IID_IInternetProtocol, riid)) {
1371 *ppv = iface;
1372 return S_OK;
1375 if(IsEqualGUID(&IID_IInternetProtocolEx, riid)) {
1376 if(impl_protex) {
1377 *ppv = iface;
1378 return S_OK;
1380 *ppv = NULL;
1381 return E_NOINTERFACE;
1384 if(IsEqualGUID(&IID_IInternetPriority, riid)) {
1385 *ppv = &InternetPriority;
1386 return S_OK;
1389 if(IsEqualGUID(&IID_IWinInetInfo, riid)) {
1390 CHECK_EXPECT(QueryInterface_IWinInetInfo);
1391 *ppv = NULL;
1392 return E_NOINTERFACE;
1395 if(IsEqualGUID(&IID_IWinInetHttpInfo, riid)) {
1396 CHECK_EXPECT(QueryInterface_IWinInetHttpInfo);
1397 *ppv = NULL;
1398 return E_NOINTERFACE;
1401 ok(0, "unexpected riid %s\n", debugstr_guid(riid));
1402 *ppv = NULL;
1403 return E_NOINTERFACE;
1406 static DWORD WINAPI thread_proc(PVOID arg)
1408 HRESULT hres;
1410 memset(&protocoldata, -1, sizeof(protocoldata));
1412 prot_state = 0;
1414 SET_EXPECT(ReportProgress_FINDINGRESOURCE);
1415 hres = IInternetProtocolSink_ReportProgress(binding_sink,
1416 BINDSTATUS_FINDINGRESOURCE, hostW);
1417 CHECK_CALLED(ReportProgress_FINDINGRESOURCE);
1418 ok(hres == S_OK, "ReportProgress failed: %08x\n", hres);
1420 SET_EXPECT(ReportProgress_CONNECTING);
1421 hres = IInternetProtocolSink_ReportProgress(binding_sink,
1422 BINDSTATUS_CONNECTING, winehq_ipW);
1423 CHECK_CALLED(ReportProgress_CONNECTING);
1424 ok(hres == S_OK, "ReportProgress failed: %08x\n", hres);
1426 SET_EXPECT(ReportProgress_SENDINGREQUEST);
1427 hres = IInternetProtocolSink_ReportProgress(binding_sink,
1428 BINDSTATUS_SENDINGREQUEST, NULL);
1429 CHECK_CALLED(ReportProgress_SENDINGREQUEST);
1430 ok(hres == S_OK, "ReportProgress failed: %08x\n", hres);
1432 prot_state = 1;
1433 SET_EXPECT(Switch);
1434 hres = IInternetProtocolSink_Switch(binding_sink, &protocoldata);
1435 CHECK_CALLED(Switch);
1436 ok(hres == S_OK, "Switch failed: %08x\n", hres);
1438 if(!short_read) {
1439 prot_state = 2;
1440 if(mimefilter_test)
1441 SET_EXPECT(MimeFilter_Switch);
1442 else
1443 SET_EXPECT(Switch);
1444 hres = IInternetProtocolSink_Switch(binding_sink, &protocoldata);
1445 ok(hres == S_OK, "Switch failed: %08x\n", hres);
1446 if(mimefilter_test)
1447 CHECK_CALLED(MimeFilter_Switch);
1448 else
1449 CHECK_CALLED(Switch);
1451 if(test_abort) {
1452 SetEvent(event_complete);
1453 return 0;
1456 prot_state = 2;
1457 if(mimefilter_test)
1458 SET_EXPECT(MimeFilter_Switch);
1459 else
1460 SET_EXPECT(Switch);
1461 hres = IInternetProtocolSink_Switch(binding_sink, &protocoldata);
1462 ok(hres == S_OK, "Switch failed: %08x\n", hres);
1463 if(mimefilter_test)
1464 CHECK_CALLED(MimeFilter_Switch);
1465 else
1466 CHECK_CALLED(Switch);
1468 prot_state = 3;
1469 if(mimefilter_test)
1470 SET_EXPECT(MimeFilter_Switch);
1471 else
1472 SET_EXPECT(Switch);
1473 hres = IInternetProtocolSink_Switch(binding_sink, &protocoldata);
1474 ok(hres == S_OK, "Switch failed: %08x\n", hres);
1475 if(mimefilter_test)
1476 CHECK_CALLED(MimeFilter_Switch);
1477 else
1478 CHECK_CALLED(Switch);
1481 SetEvent(event_complete);
1483 return 0;
1486 static void protocol_start(IInternetProtocolSink *pOIProtSink, IInternetBindInfo *pOIBindInfo, DWORD pi)
1488 BINDINFO bindinfo, exp_bindinfo;
1489 DWORD cbindf = 0;
1490 HRESULT hres;
1492 ok(pOIProtSink != NULL, "pOIProtSink == NULL\n");
1493 ok(pOIBindInfo != NULL, "pOIBindInfo == NULL\n");
1494 ok(pOIProtSink != &protocol_sink, "unexpected pOIProtSink\n");
1495 ok(pOIBindInfo != &bind_info, "unexpected pOIBindInfo\n");
1496 ok(!pi, "pi = %x\n", pi);
1498 if(binding_test)
1499 ok(pOIProtSink == binding_sink, "pOIProtSink != binding_sink\n");
1501 memset(&bindinfo, 0, sizeof(bindinfo));
1502 bindinfo.cbSize = sizeof(bindinfo);
1503 memcpy(&exp_bindinfo, &bindinfo, sizeof(bindinfo));
1504 SET_EXPECT(GetBindInfo);
1505 hres = IInternetBindInfo_GetBindInfo(pOIBindInfo, &cbindf, &bindinfo);
1506 ok(hres == S_OK, "GetBindInfo failed: %08x\n", hres);
1507 CHECK_CALLED(GetBindInfo);
1508 ok(cbindf == (bindf|BINDF_FROMURLMON), "bindf = %x, expected %x\n",
1509 cbindf, (bindf|BINDF_FROMURLMON));
1510 ok(!memcmp(&exp_bindinfo, &bindinfo, sizeof(bindinfo)), "unexpected bindinfo\n");
1511 pReleaseBindInfo(&bindinfo);
1513 SET_EXPECT(ReportProgress_SENDINGREQUEST);
1514 hres = IInternetProtocolSink_ReportProgress(pOIProtSink, BINDSTATUS_SENDINGREQUEST, emptyW);
1515 ok(hres == S_OK, "ReportProgress(BINDSTATUS_SENDINGREQUEST) failed: %08x\n", hres);
1516 CHECK_CALLED(ReportProgress_SENDINGREQUEST);
1518 if(tested_protocol == HTTP_TEST || tested_protocol == HTTPS_TEST) {
1519 IServiceProvider *service_provider;
1520 IHttpNegotiate *http_negotiate;
1521 IHttpNegotiate2 *http_negotiate2;
1522 LPWSTR ua = (LPWSTR)0xdeadbeef, accept_mimes[256];
1523 LPWSTR additional_headers = NULL;
1524 BYTE sec_id[100];
1525 DWORD fetched = 0, size = 100;
1526 DWORD tid;
1528 SET_EXPECT(GetBindString_USER_AGENT);
1529 hres = IInternetBindInfo_GetBindString(pOIBindInfo, BINDSTRING_USER_AGENT,
1530 &ua, 1, &fetched);
1531 CHECK_CALLED(GetBindString_USER_AGENT);
1532 ok(hres == S_OK, "GetBindString(BINDSTRING_USER_AGETNT) failed: %08x\n", hres);
1533 ok(fetched == 1, "fetched = %d, expected 254\n", fetched);
1534 ok(ua != NULL, "ua = %p\n", ua);
1535 ok(!lstrcmpW(ua, user_agentW), "unexpected user agent %s\n", wine_dbgstr_w(ua));
1536 CoTaskMemFree(ua);
1538 fetched = 256;
1539 SET_EXPECT(GetBindString_ACCEPT_MIMES);
1540 hres = IInternetBindInfo_GetBindString(pOIBindInfo, BINDSTRING_ACCEPT_MIMES,
1541 accept_mimes, 256, &fetched);
1542 CHECK_CALLED(GetBindString_ACCEPT_MIMES);
1544 ok(hres == S_OK,
1545 "GetBindString(BINDSTRING_ACCEPT_MIMES) failed: %08x\n", hres);
1546 ok(fetched == 1, "fetched = %d, expected 1\n", fetched);
1547 ok(!lstrcmpW(acc_mimeW, accept_mimes[0]), "unexpected mimes %s\n", wine_dbgstr_w(accept_mimes[0]));
1548 CoTaskMemFree(accept_mimes[0]);
1550 hres = IInternetBindInfo_QueryInterface(pOIBindInfo, &IID_IServiceProvider,
1551 (void**)&service_provider);
1552 ok(hres == S_OK, "QueryInterface failed: %08x\n", hres);
1554 SET_EXPECT(QueryService_HttpNegotiate);
1555 hres = IServiceProvider_QueryService(service_provider, &IID_IHttpNegotiate,
1556 &IID_IHttpNegotiate, (void**)&http_negotiate);
1557 CHECK_CALLED(QueryService_HttpNegotiate);
1558 ok(hres == S_OK, "QueryService failed: %08x\n", hres);
1560 SET_EXPECT(BeginningTransaction);
1561 hres = IHttpNegotiate_BeginningTransaction(http_negotiate, binding_urls[tested_protocol],
1562 NULL, 0, &additional_headers);
1563 CHECK_CALLED(BeginningTransaction);
1564 IHttpNegotiate_Release(http_negotiate);
1565 ok(hres == S_OK, "BeginningTransction failed: %08x\n", hres);
1566 ok(additional_headers == NULL, "additional_headers=%p\n", additional_headers);
1568 SET_EXPECT(QueryService_HttpNegotiate);
1569 hres = IServiceProvider_QueryService(service_provider, &IID_IHttpNegotiate2,
1570 &IID_IHttpNegotiate2, (void**)&http_negotiate2);
1571 CHECK_CALLED(QueryService_HttpNegotiate);
1572 ok(hres == S_OK, "QueryService failed: %08x\n", hres);
1574 size = 512;
1575 SET_EXPECT(GetRootSecurityId);
1576 hres = IHttpNegotiate2_GetRootSecurityId(http_negotiate2, sec_id, &size, 0);
1577 CHECK_CALLED(GetRootSecurityId);
1578 IHttpNegotiate2_Release(http_negotiate2);
1579 ok(hres == E_FAIL, "GetRootSecurityId failed: %08x, expected E_FAIL\n", hres);
1580 ok(size == 13, "size=%d\n", size);
1582 IServiceProvider_Release(service_provider);
1584 CreateThread(NULL, 0, thread_proc, NULL, 0, &tid);
1585 return;
1588 SET_EXPECT(ReportProgress_CACHEFILENAMEAVAILABLE);
1589 hres = IInternetProtocolSink_ReportProgress(pOIProtSink,
1590 BINDSTATUS_CACHEFILENAMEAVAILABLE, expect_wsz = emptyW);
1591 ok(hres == S_OK, "ReportProgress(BINDSTATUS_CACHEFILENAMEAVAILABLE) failed: %08x\n", hres);
1592 CHECK_CALLED(ReportProgress_CACHEFILENAMEAVAILABLE);
1594 if(mimefilter_test) {
1595 SET_EXPECT(MimeFilter_CreateInstance);
1596 SET_EXPECT(MimeFilter_Start);
1597 SET_EXPECT(ReportProgress_LOADINGMIMEHANDLER);
1599 SET_EXPECT(ReportProgress_MIMETYPEAVAILABLE);
1600 hres = IInternetProtocolSink_ReportProgress(pOIProtSink, BINDSTATUS_VERIFIEDMIMETYPEAVAILABLE,
1601 mimefilter_test ? gzipW : (expect_wsz = text_htmlW));
1602 ok(hres == S_OK,
1603 "ReportProgress(BINDSTATUS_VERIFIEDMIMETYPEAVAILABLE) failed: %08x\n", hres);
1604 if(mimefilter_test) {
1605 CHECK_CALLED(MimeFilter_CreateInstance);
1606 CHECK_CALLED(MimeFilter_Start);
1607 CHECK_CALLED(ReportProgress_LOADINGMIMEHANDLER);
1608 todo_wine CHECK_CALLED(ReportProgress_MIMETYPEAVAILABLE);
1609 }else {
1610 CHECK_CALLED(ReportProgress_MIMETYPEAVAILABLE);
1613 if(mimefilter_test)
1614 SET_EXPECT(MimeFilter_ReportData);
1615 else
1616 SET_EXPECT(ReportData);
1617 hres = IInternetProtocolSink_ReportData(pOIProtSink,
1618 BSCF_FIRSTDATANOTIFICATION | (tested_protocol == ITS_TEST ? BSCF_DATAFULLYAVAILABLE : BSCF_LASTDATANOTIFICATION),
1619 13, 13);
1620 ok(hres == S_OK, "ReportData failed: %08x\n", hres);
1621 if(mimefilter_test)
1622 CHECK_CALLED(MimeFilter_ReportData);
1623 else
1624 CHECK_CALLED(ReportData);
1626 if(tested_protocol == ITS_TEST) {
1627 SET_EXPECT(ReportData);
1628 hres = IInternetProtocolSink_ReportProgress(pOIProtSink, BINDSTATUS_BEGINDOWNLOADDATA, NULL);
1629 ok(hres == S_OK, "ReportProgress(BINDSTATUS_BEGINDOWNLOADDATA) failed: %08x\n", hres);
1630 CHECK_CALLED(ReportData);
1633 if(tested_protocol == BIND_TEST) {
1634 hres = IInternetProtocol_Terminate(binding_protocol, 0);
1635 ok(hres == E_FAIL, "Termiante failed: %08x\n", hres);
1638 if(mimefilter_test)
1639 SET_EXPECT(MimeFilter_ReportResult);
1640 else
1641 SET_EXPECT(ReportResult);
1642 hres = IInternetProtocolSink_ReportResult(pOIProtSink, S_OK, 0, NULL);
1643 ok(hres == S_OK, "ReportResult failed: %08x\n", hres);
1644 if(mimefilter_test)
1645 CHECK_CALLED(MimeFilter_ReportResult);
1646 else
1647 CHECK_CALLED(ReportResult);
1650 static HRESULT WINAPI ProtocolEmul_Start(IInternetProtocolEx *iface, LPCWSTR szUrl,
1651 IInternetProtocolSink *pOIProtSink, IInternetBindInfo *pOIBindInfo,
1652 DWORD grfPI, HANDLE_PTR dwReserved)
1654 CHECK_EXPECT(Start);
1656 ok(!dwReserved, "dwReserved = %lx\n", dwReserved);
1657 protocol_start(pOIProtSink, pOIBindInfo, grfPI);
1658 return S_OK;
1661 static HRESULT WINAPI ProtocolEmul_Continue(IInternetProtocolEx *iface,
1662 PROTOCOLDATA *pProtocolData)
1664 DWORD bscf = 0, pr;
1665 HRESULT hres;
1667 CHECK_EXPECT(Continue);
1669 ok(pProtocolData != NULL, "pProtocolData == NULL\n");
1670 if(!pProtocolData || tested_protocol == BIND_TEST)
1671 return S_OK;
1672 if(binding_test) {
1673 ok(pProtocolData != &protocoldata, "pProtocolData == &protocoldata\n");
1674 ok(pProtocolData->grfFlags == protocoldata.grfFlags, "grfFlags wrong %x/%x\n",
1675 pProtocolData->grfFlags, protocoldata.grfFlags );
1676 ok(pProtocolData->dwState == protocoldata.dwState, "dwState wrong %x/%x\n",
1677 pProtocolData->dwState, protocoldata.dwState );
1678 ok(pProtocolData->pData == protocoldata.pData, "pData wrong %p/%p\n",
1679 pProtocolData->pData, protocoldata.pData );
1680 ok(pProtocolData->cbData == protocoldata.cbData, "cbData wrong %x/%x\n",
1681 pProtocolData->cbData, protocoldata.cbData );
1684 switch(prot_state) {
1685 case 1: {
1686 IServiceProvider *service_provider;
1687 IHttpNegotiate *http_negotiate;
1688 static WCHAR header[] = {'?',0};
1690 hres = IInternetProtocolSink_QueryInterface(binding_sink, &IID_IServiceProvider,
1691 (void**)&service_provider);
1692 ok(hres == S_OK, "Could not get IServiceProvicder\n");
1694 SET_EXPECT(QueryService_HttpNegotiate);
1695 hres = IServiceProvider_QueryService(service_provider, &IID_IHttpNegotiate,
1696 &IID_IHttpNegotiate, (void**)&http_negotiate);
1697 IServiceProvider_Release(service_provider);
1698 CHECK_CALLED(QueryService_HttpNegotiate);
1699 ok(hres == S_OK, "Could not get IHttpNegotiate\n");
1701 SET_EXPECT(OnResponse);
1702 hres = IHttpNegotiate_OnResponse(http_negotiate, 200, header, NULL, NULL);
1703 IHttpNegotiate_Release(http_negotiate);
1704 CHECK_CALLED(OnResponse);
1705 IHttpNegotiate_Release(http_negotiate);
1706 ok(hres == S_OK, "OnResponse failed: %08x\n", hres);
1708 if(mimefilter_test) {
1709 SET_EXPECT(MimeFilter_CreateInstance);
1710 SET_EXPECT(MimeFilter_Start);
1711 SET_EXPECT(ReportProgress_LOADINGMIMEHANDLER);
1712 }else if(!(pi & PI_MIMEVERIFICATION)) {
1713 SET_EXPECT(ReportProgress_MIMETYPEAVAILABLE);
1715 hres = IInternetProtocolSink_ReportProgress(binding_sink,
1716 BINDSTATUS_MIMETYPEAVAILABLE, mimefilter_test ? gzipW : text_htmlW);
1717 if(mimefilter_test) {
1718 CHECK_CALLED(MimeFilter_CreateInstance);
1719 CHECK_CALLED(MimeFilter_Start);
1720 CHECK_CALLED(ReportProgress_LOADINGMIMEHANDLER);
1721 }else if(!(pi & PI_MIMEVERIFICATION)) {
1722 CHECK_CALLED(ReportProgress_MIMETYPEAVAILABLE);
1724 ok(hres == S_OK,
1725 "ReportProgress(BINDSTATUS_MIMETYPEAVAILABLE) failed: %08x\n", hres);
1727 bscf |= BSCF_FIRSTDATANOTIFICATION;
1728 break;
1730 case 2:
1731 case 3:
1732 bscf = BSCF_INTERMEDIATEDATANOTIFICATION;
1733 break;
1736 pr = prot_read;
1737 if(mimefilter_test) {
1738 SET_EXPECT(MimeFilter_ReportData);
1739 }else if(pi & PI_MIMEVERIFICATION) {
1740 if(pr < 200)
1741 SET_EXPECT(Read); /* checked in ReportData for short_read */
1742 if(pr == 200) {
1743 if(!mimefilter_test)
1744 SET_EXPECT(Read); /* checked in BINDSTATUS_MIMETYPEAVAILABLE or ReportData */
1745 SET_EXPECT(ReportProgress_MIMETYPEAVAILABLE);
1747 if(pr >= 200)
1748 SET_EXPECT(ReportData);
1749 }else {
1750 SET_EXPECT(ReportData);
1753 hres = IInternetProtocolSink_ReportData(binding_sink, bscf, pr, 400);
1754 ok(hres == S_OK, "ReportData failed: %08x\n", hres);
1756 if(mimefilter_test) {
1757 SET_EXPECT(MimeFilter_ReportData);
1758 }else if(pi & PI_MIMEVERIFICATION) {
1759 if(!short_read && pr < 200)
1760 CHECK_CALLED(Read);
1761 if(pr == 200) {
1762 CHECK_CALLED(ReportProgress_MIMETYPEAVAILABLE);
1764 }else {
1765 CHECK_CALLED(ReportData);
1768 if(prot_state == 3)
1769 prot_state = 4;
1771 return S_OK;
1774 static HRESULT WINAPI ProtocolEmul_Terminate(IInternetProtocolEx *iface, DWORD dwOptions)
1776 CHECK_EXPECT(Terminate);
1777 ok(!dwOptions, "dwOptions=%d\n", dwOptions);
1778 return S_OK;
1781 static HRESULT WINAPI ProtocolEmul_Read(IInternetProtocolEx *iface, void *pv,
1782 ULONG cb, ULONG *pcbRead)
1784 if(read_report_data)
1785 CHECK_EXPECT2(Read2);
1787 if(mimefilter_test || short_read) {
1788 if(!read_report_data)
1789 CHECK_EXPECT2(Read);
1790 }else if((pi & PI_MIMEVERIFICATION)) {
1791 if(!read_report_data)
1792 CHECK_EXPECT2(Read);
1794 if(prot_read < 300) {
1795 ok(pv != expect_pv, "pv == expect_pv\n");
1796 if(prot_read < 300)
1797 ok(cb == 2048-prot_read, "cb=%d\n", cb);
1798 else
1799 ok(cb == 700, "cb=%d\n", cb);
1800 }else {
1801 ok(expect_pv <= pv && (BYTE*)pv < (BYTE*)expect_pv + cb, "pv != expect_pv\n");
1803 }else {
1804 if(!read_report_data)
1805 CHECK_EXPECT(Read);
1807 ok(pv == expect_pv, "pv != expect_pv\n");
1808 ok(cb == 1000, "cb=%d\n", cb);
1809 ok(!*pcbRead, "*pcbRead = %d\n", *pcbRead);
1811 ok(pcbRead != NULL, "pcbRead == NULL\n");
1813 if(prot_state == 3 || (short_read && prot_state != 4)) {
1814 HRESULT hres;
1816 prot_state = 4;
1817 if(short_read) {
1818 SET_EXPECT(Read2); /* checked in BINDSTATUS_MIMETYPEAVAILABLE */
1819 SET_EXPECT(ReportProgress_MIMETYPEAVAILABLE);
1821 if(mimefilter_test)
1822 SET_EXPECT(MimeFilter_ReportData);
1823 else if(direct_read)
1824 SET_EXPECT(ReportData2);
1825 read_report_data++;
1826 hres = IInternetProtocolSink_ReportData(binding_sink,
1827 BSCF_LASTDATANOTIFICATION|BSCF_INTERMEDIATEDATANOTIFICATION, 0, 0);
1828 read_report_data--;
1829 ok(hres == S_OK, "ReportData failed: %08x\n", hres);
1830 if(short_read)
1831 CHECK_CALLED(ReportProgress_MIMETYPEAVAILABLE);
1832 if(mimefilter_test)
1833 CHECK_CALLED(MimeFilter_ReportData);
1834 else if(direct_read)
1835 CHECK_CALLED(ReportData2);
1837 if(mimefilter_test)
1838 SET_EXPECT(MimeFilter_ReportResult);
1839 else
1840 SET_EXPECT(ReportResult);
1841 hres = IInternetProtocolSink_ReportResult(binding_sink, S_OK, ERROR_SUCCESS, NULL);
1842 ok(hres == S_OK, "ReportResult failed: %08x\n", hres);
1843 if(mimefilter_test)
1844 CHECK_CALLED(MimeFilter_ReportResult);
1845 else
1846 CHECK_CALLED(ReportResult);
1848 memset(pv, 'x', 100);
1849 prot_read += *pcbRead = 100;
1850 return S_OK;
1851 }if(prot_state == 4) {
1852 *pcbRead = 0;
1853 return S_FALSE;
1856 if((async_read_pending = !async_read_pending)) {
1857 *pcbRead = 0;
1858 return tested_protocol == HTTP_TEST || tested_protocol == HTTPS_TEST ? E_PENDING : S_FALSE;
1861 memset(pv, 'x', 100);
1862 prot_read += *pcbRead = 100;
1863 return S_OK;
1866 static HRESULT WINAPI ProtocolEmul_LockRequest(IInternetProtocolEx *iface, DWORD dwOptions)
1868 CHECK_EXPECT(LockRequest);
1869 ok(dwOptions == 0, "dwOptions=%x\n", dwOptions);
1870 return S_OK;
1873 static HRESULT WINAPI ProtocolEmul_UnlockRequest(IInternetProtocolEx *iface)
1875 CHECK_EXPECT(UnlockRequest);
1876 return S_OK;
1879 static HRESULT WINAPI ProtocolEmul_StartEx(IInternetProtocolEx *iface, IUri *pUri,
1880 IInternetProtocolSink *pOIProtSink, IInternetBindInfo *pOIBindInfo,
1881 DWORD grfPI, HANDLE *dwReserved)
1883 CHECK_EXPECT(StartEx);
1884 ok(!dwReserved, "dwReserved = %p\n", dwReserved);
1885 protocol_start(pOIProtSink, pOIBindInfo, grfPI);
1886 return S_OK;
1889 static const IInternetProtocolExVtbl ProtocolVtbl = {
1890 ProtocolEmul_QueryInterface,
1891 Protocol_AddRef,
1892 Protocol_Release,
1893 ProtocolEmul_Start,
1894 ProtocolEmul_Continue,
1895 Protocol_Abort,
1896 ProtocolEmul_Terminate,
1897 Protocol_Suspend,
1898 Protocol_Resume,
1899 ProtocolEmul_Read,
1900 Protocol_Seek,
1901 ProtocolEmul_LockRequest,
1902 ProtocolEmul_UnlockRequest,
1903 ProtocolEmul_StartEx
1906 static IInternetProtocolEx Protocol = { &ProtocolVtbl };
1908 static HRESULT WINAPI MimeProtocol_QueryInterface(IInternetProtocolEx *iface, REFIID riid, void **ppv)
1910 if(IsEqualGUID(&IID_IUnknown, riid) || IsEqualGUID(&IID_IInternetProtocol, riid)) {
1911 *ppv = iface;
1912 return S_OK;
1915 if(IsEqualGUID(&IID_IInternetProtocolSink, riid)) {
1916 *ppv = &mime_protocol_sink;
1917 return S_OK;
1920 ok(0, "unexpected riid %s\n", debugstr_guid(riid));
1921 *ppv = NULL;
1922 return E_NOINTERFACE;
1925 static HRESULT WINAPI MimeProtocol_Start(IInternetProtocolEx *iface, LPCWSTR szUrl,
1926 IInternetProtocolSink *pOIProtSink, IInternetBindInfo *pOIBindInfo,
1927 DWORD grfPI, HANDLE_PTR dwReserved)
1929 PROTOCOLFILTERDATA *data;
1930 LPOLESTR url_str = NULL;
1931 DWORD fetched = 0;
1932 BINDINFO bindinfo;
1933 DWORD cbindf = 0;
1934 HRESULT hres;
1936 CHECK_EXPECT(MimeFilter_Start);
1938 ok(!lstrcmpW(szUrl, gzipW), "wrong url %s\n", wine_dbgstr_w(szUrl));
1939 ok(grfPI == (PI_FILTER_MODE|PI_FORCE_ASYNC), "grfPI=%x, expected PI_FILTER_MODE|PI_FORCE_ASYNC\n", grfPI);
1940 ok(dwReserved, "dwReserved == 0\n");
1941 ok(pOIProtSink != NULL, "pOIProtSink == NULL\n");
1942 ok(pOIBindInfo != NULL, "pOIBindInfo == NULL\n");
1944 if(binding_test) {
1945 ok(pOIProtSink != binding_sink, "pOIProtSink == protocol_sink\n");
1946 ok(pOIBindInfo == prot_bind_info, "pOIBindInfo != bind_info\n");
1947 }else {
1948 ok(pOIProtSink == &protocol_sink, "pOIProtSink != protocol_sink\n");
1949 ok(pOIBindInfo == &bind_info, "pOIBindInfo != bind_info\n");
1952 data = (void*)dwReserved;
1953 ok(data->cbSize == sizeof(*data), "data->cbSize = %d\n", data->cbSize);
1954 ok(!data->pProtocolSink, "data->pProtocolSink != NULL\n");
1955 ok(data->pProtocol != NULL, "data->pProtocol == NULL\n");
1956 ok(!data->pUnk, "data->pUnk != NULL\n");
1957 ok(!data->dwFilterFlags, "data->dwProtocolFlags = %x\n", data->dwFilterFlags);
1958 if(binding_test) {
1959 IInternetProtocolSink *prot_sink;
1961 IInternetProtocol_QueryInterface(data->pProtocol, &IID_IInternetProtocolSink, (void**)&prot_sink);
1962 ok(prot_sink == pOIProtSink, "QI(data->pProtocol, IID_IInternetProtocolSink) != pOIProtSink\n");
1963 IInternetProtocolSink_Release(prot_sink);
1965 ok(data->pProtocol != binding_protocol, "data->pProtocol == binding_protocol\n");
1967 filtered_protocol = data->pProtocol;
1968 IInternetProtocol_AddRef(filtered_protocol);
1969 }else {
1970 IInternetProtocol *prot;
1972 IInternetProtocol_QueryInterface(data->pProtocol, &IID_IInternetProtocol, (void**)&prot);
1973 ok(prot == async_protocol, "QI(data->pProtocol, IID_IInternetProtocol) != async_protocol\n");
1974 IInternetProtocol_Release(prot);
1976 ok(data->pProtocol != async_protocol, "data->pProtocol == async_protocol\n");
1979 filtered_sink = pOIProtSink;
1981 SET_EXPECT(ReportProgress_DECODING);
1982 hres = IInternetProtocolSink_ReportProgress(pOIProtSink, BINDSTATUS_DECODING, gzipW);
1983 ok(hres == S_OK, "ReportProgress(BINDSTATUS_DECODING) failed: %08x\n", hres);
1984 CHECK_CALLED(ReportProgress_DECODING);
1986 SET_EXPECT(GetBindInfo);
1987 memset(&bindinfo, 0, sizeof(bindinfo));
1988 bindinfo.cbSize = sizeof(bindinfo);
1989 hres = IInternetBindInfo_GetBindInfo(pOIBindInfo, &cbindf, &bindinfo);
1990 ok(hres == S_OK, "GetBindInfo failed: %08x\n", hres);
1991 ok(cbindf == (bindf|BINDF_FROMURLMON), "cbindf = %x, expected %x\n", cbindf, bindf);
1992 CHECK_CALLED(GetBindInfo);
1994 SET_EXPECT(GetBindString_URL);
1995 hres = IInternetBindInfo_GetBindString(pOIBindInfo, BINDSTRING_URL, &url_str, 1, &fetched);
1996 ok(hres == S_OK, "GetBindString(BINDSTRING_URL) failed: %08x\n", hres);
1997 ok(fetched == 1, "fetched = %d\n", fetched);
1998 ok(!lstrcmpW(url_str, binding_urls[tested_protocol]), "wrong url_str %s\n", wine_dbgstr_w(url_str));
1999 CoTaskMemFree(url_str);
2000 CHECK_CALLED(GetBindString_URL);
2002 return S_OK;
2005 static HRESULT WINAPI Protocol_Continue(IInternetProtocolEx *iface,
2006 PROTOCOLDATA *pProtocolData)
2008 CHECK_EXPECT(MimeFilter_Continue);
2009 return E_NOTIMPL;
2012 static HRESULT WINAPI MimeProtocol_Terminate(IInternetProtocolEx *iface, DWORD dwOptions)
2014 HRESULT hres;
2016 CHECK_EXPECT(MimeFilter_Terminate);
2018 ok(!dwOptions, "dwOptions = %x\n", dwOptions);
2020 SET_EXPECT(Terminate);
2021 hres = IInternetProtocol_Terminate(filtered_protocol, dwOptions);
2022 ok(hres == S_OK, "Terminate failed: %08x\n", hres);
2023 CHECK_CALLED(Terminate);
2025 return S_OK;
2028 static HRESULT WINAPI MimeProtocol_Read(IInternetProtocolEx *iface, void *pv,
2029 ULONG cb, ULONG *pcbRead)
2031 BYTE buf[2096];
2032 DWORD read = 0;
2033 HRESULT hres;
2035 CHECK_EXPECT(MimeFilter_Read);
2037 ok(pv != NULL, "pv == NULL\n");
2038 ok(cb != 0, "cb == 0\n");
2039 ok(pcbRead != NULL, "pcbRead == NULL\n");
2041 if(read_report_data)
2042 SET_EXPECT(Read2);
2043 else
2044 SET_EXPECT(Read);
2045 hres = IInternetProtocol_Read(filtered_protocol, buf, sizeof(buf), &read);
2046 ok(hres == S_OK || hres == S_FALSE || hres == E_PENDING, "Read failed: %08x\n", hres);
2047 if(read_report_data)
2048 CHECK_CALLED(Read2);
2049 else
2050 CHECK_CALLED(Read);
2052 if(pcbRead) {
2053 ok(*pcbRead == 0, "*pcbRead=%d, expected 0\n", *pcbRead);
2054 *pcbRead = read;
2057 memset(pv, 'x', read);
2058 return hres;
2061 static HRESULT WINAPI MimeProtocol_LockRequest(IInternetProtocolEx *iface, DWORD dwOptions)
2063 HRESULT hres;
2065 CHECK_EXPECT(MimeFilter_LockRequest);
2067 ok(!dwOptions, "dwOptions = %x\n", dwOptions);
2069 SET_EXPECT(LockRequest);
2070 hres = IInternetProtocol_LockRequest(filtered_protocol, dwOptions);
2071 ok(hres == S_OK, "LockRequest failed: %08x\n", hres);
2072 CHECK_CALLED(LockRequest);
2074 return S_OK;
2077 static HRESULT WINAPI MimeProtocol_UnlockRequest(IInternetProtocolEx *iface)
2079 HRESULT hres;
2081 CHECK_EXPECT(MimeFilter_UnlockRequest);
2083 SET_EXPECT(UnlockRequest);
2084 hres = IInternetProtocol_UnlockRequest(filtered_protocol);
2085 ok(hres == S_OK, "UnlockRequest failed: %08x\n", hres);
2086 CHECK_CALLED(UnlockRequest);
2088 return S_OK;
2091 static const IInternetProtocolExVtbl MimeProtocolVtbl = {
2092 MimeProtocol_QueryInterface,
2093 Protocol_AddRef,
2094 Protocol_Release,
2095 MimeProtocol_Start,
2096 Protocol_Continue,
2097 Protocol_Abort,
2098 MimeProtocol_Terminate,
2099 Protocol_Suspend,
2100 Protocol_Resume,
2101 MimeProtocol_Read,
2102 Protocol_Seek,
2103 MimeProtocol_LockRequest,
2104 MimeProtocol_UnlockRequest
2107 static IInternetProtocolEx MimeProtocol = { &MimeProtocolVtbl };
2109 static HRESULT WINAPI ClassFactory_QueryInterface(IClassFactory *iface, REFIID riid, void **ppv)
2111 ok(0, "unexpected call\n");
2112 return E_NOINTERFACE;
2115 static ULONG WINAPI ClassFactory_AddRef(IClassFactory *iface)
2117 return 2;
2120 static ULONG WINAPI ClassFactory_Release(IClassFactory *iface)
2122 return 1;
2125 static HRESULT WINAPI ClassFactory_CreateInstance(IClassFactory *iface, IUnknown *pOuter,
2126 REFIID riid, void **ppv)
2128 CHECK_EXPECT(CreateInstance);
2130 ok(pOuter == (IUnknown*)prot_bind_info, "pOuter != protocol_unk\n");
2131 ok(IsEqualGUID(&IID_IUnknown, riid), "unexpected riid %s\n", debugstr_guid(riid));
2132 ok(ppv != NULL, "ppv == NULL\n");
2134 *ppv = &Protocol;
2135 return S_OK;
2138 static HRESULT WINAPI ClassFactory_LockServer(IClassFactory *iface, BOOL dolock)
2140 ok(0, "unexpected call\n");
2141 return S_OK;
2144 static const IClassFactoryVtbl ClassFactoryVtbl = {
2145 ClassFactory_QueryInterface,
2146 ClassFactory_AddRef,
2147 ClassFactory_Release,
2148 ClassFactory_CreateInstance,
2149 ClassFactory_LockServer
2152 static IClassFactory ClassFactory = { &ClassFactoryVtbl };
2154 static HRESULT WINAPI MimeFilter_CreateInstance(IClassFactory *iface, IUnknown *outer, REFIID riid, void **ppv)
2156 CHECK_EXPECT(MimeFilter_CreateInstance);
2158 ok(!outer, "outer = %p\n", outer);
2159 ok(IsEqualGUID(&IID_IInternetProtocol, riid), "unexpected riid %s\n", debugstr_guid(riid));
2161 *ppv = &MimeProtocol;
2162 return S_OK;
2165 static const IClassFactoryVtbl MimeFilterCFVtbl = {
2166 ClassFactory_QueryInterface,
2167 ClassFactory_AddRef,
2168 ClassFactory_Release,
2169 MimeFilter_CreateInstance,
2170 ClassFactory_LockServer
2173 static IClassFactory mimefilter_cf = { &MimeFilterCFVtbl };
2175 #define TEST_BINDING 0x0001
2176 #define TEST_FILTER 0x0002
2177 #define TEST_FIRST_HTTP 0x0004
2178 #define TEST_DIRECT_READ 0x0008
2179 #define TEST_POST 0x0010
2180 #define TEST_EMULATEPROT 0x0020
2181 #define TEST_SHORT_READ 0x0040
2182 #define TEST_REDIRECT 0x0080
2183 #define TEST_ABORT 0x0100
2184 #define TEST_ASYNCREQ 0x0200
2185 #define TEST_USEIURI 0x0400
2186 #define TEST_IMPLPROTEX 0x0800
2187 #define TEST_EMPTY 0x1000
2189 static void register_filter(BOOL do_register)
2191 IInternetSession *session;
2192 HRESULT hres;
2194 static const WCHAR gzipW[] = {'g','z','i','p',0};
2196 hres = pCoInternetGetSession(0, &session, 0);
2197 ok(hres == S_OK, "CoInternetGetSession failed: %08x\n", hres);
2199 if(do_register) {
2200 hres = IInternetSession_RegisterMimeFilter(session, &mimefilter_cf, &IID_IInternetProtocol, gzipW);
2201 ok(hres == S_OK, "RegisterMimeFilter failed: %08x\n", hres);
2202 }else {
2203 hres = IInternetSession_UnregisterMimeFilter(session, &mimefilter_cf, gzipW);
2204 ok(hres == S_OK, "RegisterMimeFilter failed: %08x\n", hres);
2207 IInternetSession_Release(session);
2210 static void init_test(int prot, DWORD flags)
2212 tested_protocol = prot;
2213 binding_test = (flags & TEST_BINDING) != 0;
2214 first_data_notif = TRUE;
2215 prot_read = 0;
2216 prot_state = 0;
2217 async_read_pending = TRUE;
2218 mimefilter_test = (flags & TEST_FILTER) != 0;
2219 filter_state = 0;
2220 post_stream_read = 0;
2221 ResetEvent(event_complete);
2222 ResetEvent(event_complete2);
2223 ResetEvent(event_continue);
2224 ResetEvent(event_continue_done);
2225 async_protocol = binding_protocol = filtered_protocol = NULL;
2226 filtered_sink = NULL;
2227 http_is_first = (flags & TEST_FIRST_HTTP) != 0;
2228 first_data_notif = TRUE;
2229 state = STATE_CONNECTING;
2230 test_async_req = (flags & TEST_ASYNCREQ) != 0;
2231 direct_read = (flags & TEST_DIRECT_READ) != 0;
2232 emulate_prot = (flags & TEST_EMULATEPROT) != 0;
2233 wait_for_switch = TRUE;
2234 short_read = (flags & TEST_SHORT_READ) != 0;
2235 http_post_test = TYMED_NULL;
2236 test_redirect = (flags & TEST_REDIRECT) != 0;
2237 test_abort = (flags & TEST_ABORT) != 0;
2238 impl_protex = (flags & TEST_IMPLPROTEX) != 0;
2239 empty_file = (flags & TEST_EMPTY) != 0;
2241 register_filter(mimefilter_test);
2244 static void test_priority(IInternetProtocol *protocol)
2246 IInternetPriority *priority;
2247 LONG pr;
2248 HRESULT hres;
2250 hres = IInternetProtocol_QueryInterface(protocol, &IID_IInternetPriority,
2251 (void**)&priority);
2252 ok(hres == S_OK, "QueryInterface(IID_IInternetPriority) failed: %08x\n", hres);
2253 if(FAILED(hres))
2254 return;
2256 hres = IInternetPriority_GetPriority(priority, &pr);
2257 ok(hres == S_OK, "GetPriority failed: %08x\n", hres);
2258 ok(pr == 0, "pr=%d, expected 0\n", pr);
2260 hres = IInternetPriority_SetPriority(priority, 1);
2261 ok(hres == S_OK, "SetPriority failed: %08x\n", hres);
2263 hres = IInternetPriority_GetPriority(priority, &pr);
2264 ok(hres == S_OK, "GetPriority failed: %08x\n", hres);
2265 ok(pr == 1, "pr=%d, expected 1\n", pr);
2267 IInternetPriority_Release(priority);
2270 static void test_early_abort(const CLSID *clsid)
2272 IInternetProtocol *protocol;
2273 HRESULT hres;
2275 hres = CoCreateInstance(clsid, NULL, CLSCTX_INPROC_SERVER|CLSCTX_INPROC_HANDLER,
2276 &IID_IInternetProtocol, (void**)&protocol);
2277 ok(hres == S_OK, "CoCreateInstance failed: %08x\n", hres);
2279 hres = IInternetProtocol_Abort(protocol, E_ABORT, 0);
2280 ok(hres == S_OK, "Abort failed: %08x\n", hres);
2282 hres = IInternetProtocol_Abort(protocol, E_FAIL, 0);
2283 ok(hres == S_OK, "Abort failed: %08x\n", hres);
2285 IInternetProtocol_Release(protocol);
2288 static BOOL file_protocol_start(IInternetProtocol *protocol, LPCWSTR url,
2289 IInternetProtocolEx *protocolex, IUri *uri, BOOL is_first)
2291 HRESULT hres;
2293 SET_EXPECT(GetBindInfo);
2294 if(!(bindf & BINDF_FROMURLMON))
2295 SET_EXPECT(ReportProgress_DIRECTBIND);
2296 if(is_first) {
2297 SET_EXPECT(ReportProgress_SENDINGREQUEST);
2298 SET_EXPECT(ReportProgress_CACHEFILENAMEAVAILABLE);
2299 if(bindf & BINDF_FROMURLMON)
2300 SET_EXPECT(ReportProgress_VERIFIEDMIMETYPEAVAILABLE);
2301 else
2302 SET_EXPECT(ReportProgress_MIMETYPEAVAILABLE);
2304 SET_EXPECT(ReportData);
2305 if(is_first)
2306 SET_EXPECT(ReportResult);
2308 expect_hrResult = S_OK;
2310 if(protocolex) {
2311 hres = IInternetProtocolEx_StartEx(protocolex, uri, &protocol_sink, &bind_info, 0, 0);
2312 ok(hres == S_OK, "StartEx failed: %08x\n", hres);
2313 }else {
2314 hres = IInternetProtocol_Start(protocol, url, &protocol_sink, &bind_info, 0, 0);
2315 if(hres == INET_E_RESOURCE_NOT_FOUND) {
2316 win_skip("Start failed\n");
2317 return FALSE;
2319 ok(hres == S_OK, "Start failed: %08x\n", hres);
2322 CHECK_CALLED(GetBindInfo);
2323 if(!(bindf & BINDF_FROMURLMON))
2324 CHECK_CALLED(ReportProgress_DIRECTBIND);
2325 if(is_first) {
2326 CHECK_CALLED(ReportProgress_SENDINGREQUEST);
2327 CHECK_CALLED(ReportProgress_CACHEFILENAMEAVAILABLE);
2328 if(bindf & BINDF_FROMURLMON)
2329 CHECK_CALLED(ReportProgress_VERIFIEDMIMETYPEAVAILABLE);
2330 else
2331 CHECK_CALLED(ReportProgress_MIMETYPEAVAILABLE);
2333 CHECK_CALLED(ReportData);
2334 if(is_first)
2335 CHECK_CALLED(ReportResult);
2337 return TRUE;
2340 static void test_file_protocol_url(LPCWSTR url)
2342 IInternetProtocolInfo *protocol_info;
2343 IUnknown *unk;
2344 IClassFactory *factory;
2345 IInternetProtocol *protocol;
2346 BYTE buf[512];
2347 ULONG cb;
2348 HRESULT hres;
2350 hres = CoGetClassObject(&CLSID_FileProtocol, CLSCTX_INPROC_SERVER, NULL,
2351 &IID_IUnknown, (void**)&unk);
2352 ok(hres == S_OK, "CoGetClassObject failed: %08x\n", hres);
2353 if(FAILED(hres))
2354 return;
2356 hres = IUnknown_QueryInterface(unk, &IID_IInternetProtocolInfo, (void**)&protocol_info);
2357 ok(hres == E_NOINTERFACE,
2358 "Could not get IInternetProtocolInfo interface: %08x, expected E_NOINTERFACE\n", hres);
2360 hres = IUnknown_QueryInterface(unk, &IID_IClassFactory, (void**)&factory);
2361 ok(hres == S_OK, "Could not get IClassFactory interface\n");
2362 IUnknown_Release(unk);
2363 if(FAILED(hres))
2364 return;
2366 hres = IClassFactory_CreateInstance(factory, NULL, &IID_IInternetProtocol, (void**)&protocol);
2367 ok(hres == S_OK, "Could not get IInternetProtocol: %08x\n", hres);
2369 if(SUCCEEDED(hres)) {
2370 if(file_protocol_start(protocol, url, NULL, NULL, TRUE)) {
2371 hres = IInternetProtocol_Read(protocol, buf, 2, &cb);
2372 ok(hres == S_OK, "Read failed: %08x\n", hres);
2373 ok(cb == 2, "cb=%u expected 2\n", cb);
2374 hres = IInternetProtocol_Read(protocol, buf, sizeof(buf), &cb);
2375 ok(hres == S_FALSE, "Read failed: %08x\n", hres);
2376 hres = IInternetProtocol_Read(protocol, buf, sizeof(buf), &cb);
2377 ok(hres == S_FALSE, "Read failed: %08x expected S_FALSE\n", hres);
2378 ok(cb == 0, "cb=%u expected 0\n", cb);
2379 hres = IInternetProtocol_UnlockRequest(protocol);
2380 ok(hres == S_OK, "UnlockRequest failed: %08x\n", hres);
2383 if(file_protocol_start(protocol, url, NULL, NULL, FALSE)) {
2384 hres = IInternetProtocol_Read(protocol, buf, 2, &cb);
2385 ok(hres == S_FALSE, "Read failed: %08x\n", hres);
2386 hres = IInternetProtocol_LockRequest(protocol, 0);
2387 ok(hres == S_OK, "LockRequest failed: %08x\n", hres);
2388 hres = IInternetProtocol_UnlockRequest(protocol);
2389 ok(hres == S_OK, "UnlockRequest failed: %08x\n", hres);
2392 IInternetProtocol_Release(protocol);
2395 hres = IClassFactory_CreateInstance(factory, NULL, &IID_IInternetProtocol, (void**)&protocol);
2396 ok(hres == S_OK, "Could not get IInternetProtocol: %08x\n", hres);
2397 if(SUCCEEDED(hres)) {
2398 if(file_protocol_start(protocol, url, NULL, NULL, TRUE)) {
2399 hres = IInternetProtocol_LockRequest(protocol, 0);
2400 ok(hres == S_OK, "LockRequest failed: %08x\n", hres);
2401 hres = IInternetProtocol_Terminate(protocol, 0);
2402 ok(hres == S_OK, "Terminate failed: %08x\n", hres);
2403 hres = IInternetProtocol_Read(protocol, buf, 2, &cb);
2404 ok(hres == S_OK, "Read failed: %08x\n\n", hres);
2405 hres = IInternetProtocol_UnlockRequest(protocol);
2406 ok(hres == S_OK, "UnlockRequest failed: %08x\n", hres);
2407 hres = IInternetProtocol_Read(protocol, buf, 2, &cb);
2408 ok(hres == S_OK, "Read failed: %08x\n", hres);
2409 hres = IInternetProtocol_Terminate(protocol, 0);
2410 ok(hres == S_OK, "Terminate failed: %08x\n", hres);
2413 IInternetProtocol_Release(protocol);
2416 hres = IClassFactory_CreateInstance(factory, NULL, &IID_IInternetProtocol, (void**)&protocol);
2417 ok(hres == S_OK, "Could not get IInternetProtocol: %08x\n", hres);
2418 if(SUCCEEDED(hres)) {
2419 if(file_protocol_start(protocol, url, NULL, NULL, TRUE)) {
2420 hres = IInternetProtocol_Terminate(protocol, 0);
2421 ok(hres == S_OK, "Terminate failed: %08x\n", hres);
2422 hres = IInternetProtocol_Read(protocol, buf, 2, &cb);
2423 ok(hres == S_OK, "Read failed: %08x\n", hres);
2424 ok(cb == 2, "cb=%u expected 2\n", cb);
2427 IInternetProtocol_Release(protocol);
2430 if(pCreateUri) {
2431 IInternetProtocolEx *protocolex;
2432 IUri *uri;
2434 hres = pCreateUri(url, Uri_CREATE_FILE_USE_DOS_PATH, 0, &uri);
2435 ok(hres == S_OK, "CreateUri failed: %08x\n", hres);
2437 hres = IClassFactory_CreateInstance(factory, NULL, &IID_IInternetProtocolEx, (void**)&protocolex);
2438 ok(hres == S_OK, "Could not get IInternetProtocolEx: %08x\n", hres);
2440 if(file_protocol_start(NULL, NULL, protocolex, uri, TRUE)) {
2441 hres = IInternetProtocolEx_Read(protocolex, buf, 2, &cb);
2442 ok(hres == S_OK, "Read failed: %08x\n", hres);
2443 hres = IInternetProtocolEx_LockRequest(protocolex, 0);
2444 ok(hres == S_OK, "LockRequest failed: %08x\n", hres);
2445 hres = IInternetProtocolEx_UnlockRequest(protocolex);
2446 ok(hres == S_OK, "UnlockRequest failed: %08x\n", hres);
2449 IUri_Release(uri);
2450 IInternetProtocolEx_Release(protocolex);
2452 hres = pCreateUri(url, 0, 0, &uri);
2453 ok(hres == S_OK, "CreateUri failed: %08x\n", hres);
2455 hres = IClassFactory_CreateInstance(factory, NULL, &IID_IInternetProtocolEx, (void**)&protocolex);
2456 ok(hres == S_OK, "Could not get IInternetProtocolEx: %08x\n", hres);
2458 if(file_protocol_start(NULL, NULL, protocolex, uri, TRUE)) {
2459 hres = IInternetProtocolEx_Read(protocolex, buf, 2, &cb);
2460 ok(hres == S_OK, "Read failed: %08x\n", hres);
2461 hres = IInternetProtocolEx_LockRequest(protocolex, 0);
2462 ok(hres == S_OK, "LockRequest failed: %08x\n", hres);
2463 hres = IInternetProtocolEx_UnlockRequest(protocolex);
2464 ok(hres == S_OK, "UnlockRequest failed: %08x\n", hres);
2467 IUri_Release(uri);
2468 IInternetProtocolEx_Release(protocolex);
2469 }else {
2470 win_skip("Skipping file protocol StartEx tests\n");
2473 IClassFactory_Release(factory);
2476 static void test_file_protocol_fail(void)
2478 IInternetProtocol *protocol;
2479 HRESULT hres;
2481 static const WCHAR index_url2[] =
2482 {'f','i','l','e',':','/','/','i','n','d','e','x','.','h','t','m','l',0};
2484 hres = CoCreateInstance(&CLSID_FileProtocol, NULL, CLSCTX_INPROC_SERVER|CLSCTX_INPROC_HANDLER,
2485 &IID_IInternetProtocol, (void**)&protocol);
2486 ok(hres == S_OK, "CoCreateInstance failed: %08x\n", hres);
2487 if(FAILED(hres))
2488 return;
2490 SET_EXPECT(GetBindInfo);
2491 expect_hrResult = MK_E_SYNTAX;
2492 hres = IInternetProtocol_Start(protocol, wszIndexHtml, &protocol_sink, &bind_info, 0, 0);
2493 ok(hres == MK_E_SYNTAX ||
2494 hres == E_INVALIDARG,
2495 "Start failed: %08x, expected MK_E_SYNTAX or E_INVALIDARG\n", hres);
2496 CLEAR_CALLED(GetBindInfo); /* GetBindInfo not called in IE7 */
2498 SET_EXPECT(GetBindInfo);
2499 if(!(bindf & BINDF_FROMURLMON))
2500 SET_EXPECT(ReportProgress_DIRECTBIND);
2501 SET_EXPECT(ReportProgress_SENDINGREQUEST);
2502 SET_EXPECT(ReportResult);
2503 expect_hrResult = INET_E_RESOURCE_NOT_FOUND;
2504 hres = IInternetProtocol_Start(protocol, index_url, &protocol_sink, &bind_info, 0, 0);
2505 ok(hres == INET_E_RESOURCE_NOT_FOUND,
2506 "Start failed: %08x expected INET_E_RESOURCE_NOT_FOUND\n", hres);
2507 CHECK_CALLED(GetBindInfo);
2508 if(!(bindf & BINDF_FROMURLMON))
2509 CHECK_CALLED(ReportProgress_DIRECTBIND);
2510 CHECK_CALLED(ReportProgress_SENDINGREQUEST);
2511 CHECK_CALLED(ReportResult);
2513 IInternetProtocol_Release(protocol);
2515 hres = CoCreateInstance(&CLSID_FileProtocol, NULL, CLSCTX_INPROC_SERVER|CLSCTX_INPROC_HANDLER,
2516 &IID_IInternetProtocol, (void**)&protocol);
2517 ok(hres == S_OK, "CoCreateInstance failed: %08x\n", hres);
2518 if(FAILED(hres))
2519 return;
2521 SET_EXPECT(GetBindInfo);
2522 if(!(bindf & BINDF_FROMURLMON))
2523 SET_EXPECT(ReportProgress_DIRECTBIND);
2524 SET_EXPECT(ReportProgress_SENDINGREQUEST);
2525 SET_EXPECT(ReportResult);
2526 expect_hrResult = INET_E_RESOURCE_NOT_FOUND;
2528 hres = IInternetProtocol_Start(protocol, index_url2, &protocol_sink, &bind_info, 0, 0);
2529 ok(hres == INET_E_RESOURCE_NOT_FOUND,
2530 "Start failed: %08x, expected INET_E_RESOURCE_NOT_FOUND\n", hres);
2531 CHECK_CALLED(GetBindInfo);
2532 if(!(bindf & BINDF_FROMURLMON))
2533 CHECK_CALLED(ReportProgress_DIRECTBIND);
2534 CHECK_CALLED(ReportProgress_SENDINGREQUEST);
2535 CHECK_CALLED(ReportResult);
2537 SET_EXPECT(GetBindInfo);
2538 hres = IInternetProtocol_Start(protocol, NULL, &protocol_sink, &bind_info, 0, 0);
2539 ok(hres == E_INVALIDARG, "Start failed: %08x, expected E_INVALIDARG\n", hres);
2540 CLEAR_CALLED(GetBindInfo); /* GetBindInfo not called in IE7 */
2542 SET_EXPECT(GetBindInfo);
2543 hres = IInternetProtocol_Start(protocol, emptyW, &protocol_sink, &bind_info, 0, 0);
2544 ok(hres == E_INVALIDARG, "Start failed: %08x, expected E_INVALIDARG\n", hres);
2545 CLEAR_CALLED(GetBindInfo); /* GetBindInfo not called in IE7 */
2547 IInternetProtocol_Release(protocol);
2550 static void test_file_protocol(void) {
2551 WCHAR buf[INTERNET_MAX_URL_LENGTH], file_name_buf[MAX_PATH];
2552 DWORD size;
2553 ULONG len;
2554 HANDLE file;
2556 static const WCHAR wszFile[] = {'f','i','l','e',':',0};
2557 static const WCHAR wszFile2[] = {'f','i','l','e',':','/','/',0};
2558 static const WCHAR wszFile3[] = {'f','i','l','e',':','/','/','/',0};
2559 static const WCHAR wszFile4[] = {'f','i','l','e',':','\\','\\',0};
2560 static const char html_doc[] = "<HTML></HTML>";
2562 trace("Testing file protocol...\n");
2563 init_test(FILE_TEST, 0);
2565 SetLastError(0xdeadbeef);
2566 file = CreateFileW(wszIndexHtml, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS,
2567 FILE_ATTRIBUTE_NORMAL, NULL);
2568 ok(file != INVALID_HANDLE_VALUE, "CreateFile failed\n");
2569 if(file == INVALID_HANDLE_VALUE)
2570 return;
2571 WriteFile(file, html_doc, sizeof(html_doc)-1, &size, NULL);
2572 CloseHandle(file);
2574 file_name = wszIndexHtml;
2575 bindf = 0;
2576 test_file_protocol_url(index_url);
2577 bindf = BINDF_FROMURLMON;
2578 test_file_protocol_url(index_url);
2579 bindf = BINDF_FROMURLMON | BINDF_NEEDFILE;
2580 test_file_protocol_url(index_url);
2582 memcpy(buf, wszFile, sizeof(wszFile));
2583 len = sizeof(wszFile)/sizeof(WCHAR)-1;
2584 len += GetCurrentDirectoryW(sizeof(buf)/sizeof(WCHAR)-len, buf+len);
2585 buf[len++] = '\\';
2586 memcpy(buf+len, wszIndexHtml, sizeof(wszIndexHtml));
2588 file_name = buf + sizeof(wszFile)/sizeof(WCHAR)-1;
2589 bindf = 0;
2590 test_file_protocol_url(buf);
2591 bindf = BINDF_FROMURLMON;
2592 test_file_protocol_url(buf);
2594 memcpy(buf, wszFile2, sizeof(wszFile2));
2595 len = GetCurrentDirectoryW(sizeof(file_name_buf)/sizeof(WCHAR), file_name_buf);
2596 file_name_buf[len++] = '\\';
2597 memcpy(file_name_buf+len, wszIndexHtml, sizeof(wszIndexHtml));
2598 lstrcpyW(buf+sizeof(wszFile2)/sizeof(WCHAR)-1, file_name_buf);
2599 file_name = file_name_buf;
2600 bindf = 0;
2601 test_file_protocol_url(buf);
2602 bindf = BINDF_FROMURLMON;
2603 test_file_protocol_url(buf);
2605 buf[sizeof(wszFile2)/sizeof(WCHAR)] = '|';
2606 test_file_protocol_url(buf);
2608 memcpy(buf, wszFile3, sizeof(wszFile3));
2609 len = sizeof(wszFile3)/sizeof(WCHAR)-1;
2610 len += GetCurrentDirectoryW(sizeof(buf)/sizeof(WCHAR)-len, buf+len);
2611 buf[len++] = '\\';
2612 memcpy(buf+len, wszIndexHtml, sizeof(wszIndexHtml));
2614 file_name = buf + sizeof(wszFile3)/sizeof(WCHAR)-1;
2615 bindf = 0;
2616 test_file_protocol_url(buf);
2617 bindf = BINDF_FROMURLMON;
2618 test_file_protocol_url(buf);
2620 memcpy(buf, wszFile4, sizeof(wszFile4));
2621 len = GetCurrentDirectoryW(sizeof(file_name_buf)/sizeof(WCHAR), file_name_buf);
2622 file_name_buf[len++] = '\\';
2623 memcpy(file_name_buf+len, wszIndexHtml, sizeof(wszIndexHtml));
2624 lstrcpyW(buf+sizeof(wszFile4)/sizeof(WCHAR)-1, file_name_buf);
2625 file_name = file_name_buf;
2626 bindf = 0;
2627 test_file_protocol_url(buf);
2628 bindf = BINDF_FROMURLMON;
2629 test_file_protocol_url(buf);
2631 buf[sizeof(wszFile4)/sizeof(WCHAR)] = '|';
2632 test_file_protocol_url(buf);
2634 DeleteFileW(wszIndexHtml);
2636 bindf = 0;
2637 test_file_protocol_fail();
2638 bindf = BINDF_FROMURLMON;
2639 test_file_protocol_fail();
2642 static BOOL http_protocol_start(LPCWSTR url, BOOL use_iuri)
2644 static BOOL got_user_agent = FALSE;
2645 IUri *uri = NULL;
2646 HRESULT hres;
2648 if(use_iuri && pCreateUri) {
2649 hres = pCreateUri(url, 0, 0, &uri);
2650 ok(hres == S_OK, "CreateUri failed: %08x\n", hres);
2653 SET_EXPECT(GetBindInfo);
2654 if (!(bindf & BINDF_FROMURLMON))
2655 SET_EXPECT(ReportProgress_DIRECTBIND);
2656 if(!got_user_agent)
2657 SET_EXPECT(GetBindString_USER_AGENT);
2658 SET_EXPECT(GetBindString_ACCEPT_MIMES);
2659 SET_EXPECT(QueryService_HttpNegotiate);
2660 SET_EXPECT(BeginningTransaction);
2661 SET_EXPECT(GetRootSecurityId);
2662 if(http_post_test) {
2663 SET_EXPECT(GetBindString_POST_COOKIE);
2664 if(http_post_test == TYMED_ISTREAM)
2665 SET_EXPECT(Stream_Seek);
2668 if(uri) {
2669 IInternetProtocolEx *protocolex;
2671 hres = IInternetProtocol_QueryInterface(async_protocol, &IID_IInternetProtocolEx, (void**)&protocolex);
2672 ok(hres == S_OK, "Could not get IInternetProtocolEx iface: %08x\n", hres);
2674 hres = IInternetProtocolEx_StartEx(protocolex, uri, &protocol_sink, &bind_info, 0, 0);
2675 ok(hres == S_OK, "Start failed: %08x\n", hres);
2677 IInternetProtocolEx_Release(protocolex);
2678 IUri_Release(uri);
2679 }else {
2680 hres = IInternetProtocol_Start(async_protocol, url, &protocol_sink, &bind_info, 0, 0);
2681 ok(hres == S_OK, "Start failed: %08x\n", hres);
2683 if(FAILED(hres))
2684 return FALSE;
2686 CHECK_CALLED(GetBindInfo);
2687 if (!(bindf & BINDF_FROMURLMON))
2688 CHECK_CALLED(ReportProgress_DIRECTBIND);
2689 if (!got_user_agent)
2691 CHECK_CALLED(GetBindString_USER_AGENT);
2692 got_user_agent = TRUE;
2694 CHECK_CALLED(GetBindString_ACCEPT_MIMES);
2695 CHECK_CALLED(QueryService_HttpNegotiate);
2696 CHECK_CALLED(BeginningTransaction);
2697 /* GetRootSecurityId called on WinXP but not on Win98 */
2698 CLEAR_CALLED(GetRootSecurityId);
2699 if(http_post_test) {
2700 CHECK_CALLED(GetBindString_POST_COOKIE);
2701 if(http_post_test == TYMED_ISTREAM)
2702 CHECK_CALLED(Stream_Seek);
2705 return TRUE;
2708 static void test_protocol_terminate(IInternetProtocol *protocol)
2710 BYTE buf[3600];
2711 DWORD cb;
2712 HRESULT hres;
2714 hres = IInternetProtocol_LockRequest(protocol, 0);
2715 ok(hres == S_OK, "LockRequest failed: %08x\n", hres);
2717 hres = IInternetProtocol_Read(protocol, buf, 1, &cb);
2718 ok(hres == test_abort ? S_OK : S_FALSE, "Read failed: %08x\n", hres);
2720 hres = IInternetProtocol_Terminate(protocol, 0);
2721 ok(hres == S_OK, "Terminate failed: %08x\n", hres);
2723 /* This wait is to give the internet handles being freed in Terminate
2724 * enough time to actually terminate in all cases. Internet handles
2725 * terminate asynchronously and native reuses the main InternetOpen
2726 * handle. The only case in which this seems to be necessary is on
2727 * wine with native wininet and urlmon, resulting in the next time
2728 * test_http_protocol_url being called the first data notification actually
2729 * being an extra last data notification from the previous connection
2730 * about once out of every ten times. */
2731 Sleep(100);
2733 hres = IInternetProtocol_UnlockRequest(protocol);
2734 ok(hres == S_OK, "UnlockRequest failed: %08x\n", hres);
2737 static void test_http_info(IInternetProtocol *protocol)
2739 IWinInetHttpInfo *info;
2740 HRESULT hres;
2742 hres = IInternetProtocol_QueryInterface(protocol, &IID_IWinInetHttpInfo, (void**)&info);
2743 ok(hres == S_OK, "Could not get IWinInterHttpInfo iface: %08x\n", hres);
2745 /* TODO */
2747 IWinInetHttpInfo_Release(info);
2750 /* is_first refers to whether this is the first call to this function
2751 * _for this url_ */
2752 static void test_http_protocol_url(LPCWSTR url, int prot, DWORD flags, DWORD tymed)
2754 IInternetProtocolInfo *protocol_info;
2755 IClassFactory *factory;
2756 IUnknown *unk;
2757 HRESULT hres;
2759 init_test(prot, flags);
2760 http_url = url;
2761 http_post_test = tymed;
2763 hres = CoGetClassObject(prot == HTTPS_TEST ? &CLSID_HttpSProtocol : &CLSID_HttpProtocol,
2764 CLSCTX_INPROC_SERVER, NULL, &IID_IUnknown, (void**)&unk);
2765 ok(hres == S_OK, "CoGetClassObject failed: %08x\n", hres);
2766 if(FAILED(hres))
2767 return;
2769 hres = IUnknown_QueryInterface(unk, &IID_IInternetProtocolInfo, (void**)&protocol_info);
2770 ok(hres == E_NOINTERFACE,
2771 "Could not get IInternetProtocolInfo interface: %08x, expected E_NOINTERFACE\n",
2772 hres);
2774 hres = IUnknown_QueryInterface(unk, &IID_IClassFactory, (void**)&factory);
2775 ok(hres == S_OK, "Could not get IClassFactory interface\n");
2776 IUnknown_Release(unk);
2777 if(FAILED(hres))
2778 return;
2780 hres = IClassFactory_CreateInstance(factory, NULL, &IID_IInternetProtocol,
2781 (void**)&async_protocol);
2782 ok(hres == S_OK, "Could not get IInternetProtocol: %08x\n", hres);
2783 if(SUCCEEDED(hres)) {
2784 BYTE buf[3600];
2785 DWORD cb;
2786 ULONG ref;
2788 test_priority(async_protocol);
2789 test_http_info(async_protocol);
2791 SET_EXPECT(ReportProgress_COOKIE_SENT);
2792 if(http_is_first) {
2793 SET_EXPECT(ReportProgress_FINDINGRESOURCE);
2794 SET_EXPECT(ReportProgress_CONNECTING);
2796 SET_EXPECT(ReportProgress_SENDINGREQUEST);
2797 if(test_redirect)
2798 SET_EXPECT(ReportProgress_REDIRECTING);
2799 SET_EXPECT(ReportProgress_PROXYDETECTING);
2800 if(prot == HTTP_TEST)
2801 SET_EXPECT(ReportProgress_CACHEFILENAMEAVAILABLE);
2802 else
2803 SET_EXPECT(QueryService_HttpSecurity);
2804 if(!(bindf & BINDF_FROMURLMON)) {
2805 SET_EXPECT(OnResponse);
2806 SET_EXPECT(ReportProgress_RAWMIMETYPE);
2807 SET_EXPECT(ReportData);
2808 } else {
2809 SET_EXPECT(Switch);
2812 if(!http_protocol_start(url, (flags & TEST_USEIURI) != 0))
2813 return;
2815 if(!direct_read && !test_abort)
2816 SET_EXPECT(ReportResult);
2817 expect_hrResult = test_abort ? E_ABORT : S_OK;
2819 if(direct_read) {
2820 SET_EXPECT(Switch);
2821 while(wait_for_switch) {
2822 WaitForSingleObject(event_continue, INFINITE);
2823 CHECK_CALLED(Switch); /* Set in ReportData */
2824 call_continue(&continue_protdata);
2825 SetEvent(event_continue_done);
2827 }else {
2828 hres = IInternetProtocol_Read(async_protocol, buf, 1, &cb);
2829 ok((hres == E_PENDING && cb==0) ||
2830 (hres == S_OK && cb==1), "Read failed: %08x (%d bytes)\n", hres, cb);
2832 WaitForSingleObject(event_complete, INFINITE);
2833 if(bindf & BINDF_FROMURLMON)
2834 CHECK_CALLED(Switch);
2835 else
2836 CHECK_CALLED(ReportData);
2837 if(prot == HTTPS_TEST)
2838 CLEAR_CALLED(QueryService_HttpSecurity);
2840 while(1) {
2841 if(bindf & BINDF_FROMURLMON)
2842 SET_EXPECT(Switch);
2843 else
2844 SET_EXPECT(ReportData);
2845 hres = IInternetProtocol_Read(async_protocol, buf, sizeof(buf), &cb);
2846 if(hres == E_PENDING) {
2847 hres = IInternetProtocol_Read(async_protocol, buf, 1, &cb);
2848 ok((hres == E_PENDING && cb==0) ||
2849 (hres == S_OK && cb==1), "Read failed: %08x (%d bytes)\n", hres, cb);
2850 WaitForSingleObject(event_complete, INFINITE);
2851 if(bindf & BINDF_FROMURLMON)
2852 CHECK_CALLED(Switch);
2853 else
2854 CHECK_CALLED(ReportData);
2856 if(test_abort) {
2857 HRESULT hres;
2859 SET_EXPECT(ReportResult);
2860 hres = IInternetProtocol_Abort(async_protocol, E_ABORT, 0);
2861 ok(hres == S_OK, "Abort failed: %08x\n", hres);
2862 CHECK_CALLED(ReportResult);
2864 hres = IInternetProtocol_Abort(async_protocol, E_ABORT, 0);
2865 ok(hres == INET_E_RESULT_DISPATCHED, "Abort failed: %08x\n", hres);
2866 break;
2868 }else {
2869 if(bindf & BINDF_FROMURLMON)
2870 CHECK_NOT_CALLED(Switch);
2871 else
2872 CHECK_NOT_CALLED(ReportData);
2873 if(cb == 0) break;
2876 if(!test_abort) {
2877 ok(hres == S_FALSE, "Read failed: %08x\n", hres);
2878 CHECK_CALLED(ReportResult);
2881 if(prot == HTTPS_TEST)
2882 CLEAR_CALLED(ReportProgress_SENDINGREQUEST);
2884 hres = IInternetProtocol_Abort(async_protocol, E_ABORT, 0);
2885 ok(hres == INET_E_RESULT_DISPATCHED, "Abort failed: %08x\n", hres);
2887 test_protocol_terminate(async_protocol);
2889 hres = IInternetProtocol_Abort(async_protocol, E_ABORT, 0);
2890 ok(hres == S_OK, "Abort failed: %08x\n", hres);
2892 ref = IInternetProtocol_Release(async_protocol);
2893 ok(!ref, "ref=%x\n", ref);
2896 IClassFactory_Release(factory);
2899 static void test_http_protocol(void)
2901 static const WCHAR posttest_url[] =
2902 {'h','t','t','p',':','/','/','t','e','s','t','.','w','i','n','e','h','q','.','o','r','g','/',
2903 't','e','s','t','s','/','p','o','s','t','.','p','h','p',0};
2904 static const WCHAR redirect_url[] =
2905 {'h','t','t','p',':','/','/','t','e','s','t','.','w','i','n','e','h','q','.','o','r','g','/',
2906 't','e','s','t','s','/','r','e','d','i','r','e','c','t',0};
2907 static const WCHAR winetest_url[] =
2908 {'h','t','t','p',':','/','/','t','e','s','t','.','w','i','n','e','h','q','.','o','r','g','/',
2909 't','e','s','t','s','/','d','a','t','a','.','p','h','p',0};
2910 static const WCHAR empty_url[] =
2911 {'h','t','t','p',':','/','/','t','e','s','t','.','w','i','n','e','h','q','.','o','r','g','/',
2912 't','e','s','t','s','/','e','m','p','t','y','.','j','s',0};
2914 trace("Testing http protocol (not from urlmon)...\n");
2915 bindf = BINDF_ASYNCHRONOUS | BINDF_ASYNCSTORAGE | BINDF_PULLDATA;
2916 test_http_protocol_url(winetest_url, HTTP_TEST, TEST_FIRST_HTTP, TYMED_NULL);
2918 trace("Testing http protocol (from urlmon)...\n");
2919 bindf = BINDF_ASYNCHRONOUS | BINDF_ASYNCSTORAGE | BINDF_PULLDATA | BINDF_FROMURLMON;
2920 test_http_protocol_url(winetest_url, HTTP_TEST, 0, TYMED_NULL);
2922 trace("Testing http protocol (to file)...\n");
2923 bindf = BINDF_ASYNCHRONOUS | BINDF_ASYNCSTORAGE | BINDF_PULLDATA | BINDF_FROMURLMON | BINDF_NEEDFILE;
2924 test_http_protocol_url(winetest_url, HTTP_TEST, 0, TYMED_NULL);
2926 trace("Testing http protocol (post data)...\n");
2927 bindf = BINDF_ASYNCHRONOUS | BINDF_ASYNCSTORAGE | BINDF_PULLDATA | BINDF_FROMURLMON;
2928 test_http_protocol_url(posttest_url, HTTP_TEST, TEST_FIRST_HTTP|TEST_POST, TYMED_HGLOBAL);
2930 trace("Testing http protocol (post data stream)...\n");
2931 test_http_protocol_url(posttest_url, HTTP_TEST, TEST_FIRST_HTTP|TEST_POST|TEST_ASYNCREQ, TYMED_ISTREAM);
2933 trace("Testing http protocol (direct read)...\n");
2934 bindf = BINDF_ASYNCHRONOUS | BINDF_ASYNCSTORAGE | BINDF_PULLDATA | BINDF_FROMURLMON;
2935 test_http_protocol_url(winetest_url, HTTP_TEST, TEST_DIRECT_READ|TEST_USEIURI, TYMED_NULL);
2937 trace("Testing http protocol (redirected)...\n");
2938 bindf = BINDF_ASYNCHRONOUS | BINDF_ASYNCSTORAGE | BINDF_PULLDATA | BINDF_FROMURLMON;
2939 test_http_protocol_url(redirect_url, HTTP_TEST, TEST_REDIRECT, TYMED_NULL);
2941 trace("Testing http protocol empty file...\n");
2942 test_http_protocol_url(empty_url, HTTP_TEST, TEST_EMPTY, TYMED_NULL);
2944 trace("Testing http protocol abort...\n");
2945 test_http_protocol_url(winetest_url, HTTP_TEST, TEST_ABORT, TYMED_NULL);
2947 test_early_abort(&CLSID_HttpProtocol);
2948 test_early_abort(&CLSID_HttpSProtocol);
2951 static void test_https_protocol(void)
2953 static const WCHAR codeweavers_url[] =
2954 {'h','t','t','p','s',':','/','/','w','w','w','.','c','o','d','e','w','e','a','v','e','r','s',
2955 '.','c','o','m','/','t','e','s','t','.','h','t','m','l',0};
2957 trace("Testing https protocol (from urlmon)...\n");
2958 bindf = BINDF_ASYNCHRONOUS | BINDF_ASYNCSTORAGE | BINDF_PULLDATA | BINDF_FROMURLMON | BINDF_NOWRITECACHE;
2959 test_http_protocol_url(codeweavers_url, HTTPS_TEST, TEST_FIRST_HTTP, TYMED_NULL);
2963 static void test_ftp_protocol(void)
2965 IInternetProtocolInfo *protocol_info;
2966 IClassFactory *factory;
2967 IUnknown *unk;
2968 BYTE buf[4096];
2969 ULONG ref;
2970 DWORD cb;
2971 HRESULT hres;
2973 static const WCHAR ftp_urlW[] = {'f','t','p',':','/','/','f','t','p','.','w','i','n','e','h','q','.','o','r','g',
2974 '/','p','u','b','/','o','t','h','e','r','/',
2975 'w','i','n','e','l','o','g','o','.','x','c','f','.','t','a','r','.','b','z','2',0};
2977 trace("Testing ftp protocol...\n");
2979 bindf = BINDF_ASYNCHRONOUS | BINDF_ASYNCSTORAGE | BINDF_PULLDATA | BINDF_FROMURLMON | BINDF_NOWRITECACHE;
2980 state = STATE_STARTDOWNLOADING;
2981 tested_protocol = FTP_TEST;
2982 first_data_notif = TRUE;
2983 expect_hrResult = E_PENDING;
2985 hres = CoGetClassObject(&CLSID_FtpProtocol, CLSCTX_INPROC_SERVER, NULL, &IID_IUnknown, (void**)&unk);
2986 ok(hres == S_OK, "CoGetClassObject failed: %08x\n", hres);
2987 if(FAILED(hres))
2988 return;
2990 hres = IUnknown_QueryInterface(unk, &IID_IInternetProtocolInfo, (void**)&protocol_info);
2991 ok(hres == E_NOINTERFACE, "Could not get IInternetProtocolInfo interface: %08x, expected E_NOINTERFACE\n", hres);
2993 hres = IUnknown_QueryInterface(unk, &IID_IClassFactory, (void**)&factory);
2994 ok(hres == S_OK, "Could not get IClassFactory interface\n");
2995 IUnknown_Release(unk);
2996 if(FAILED(hres))
2997 return;
2999 hres = IClassFactory_CreateInstance(factory, NULL, &IID_IInternetProtocol,
3000 (void**)&async_protocol);
3001 IClassFactory_Release(factory);
3002 ok(hres == S_OK, "Could not get IInternetProtocol: %08x\n", hres);
3004 test_priority(async_protocol);
3005 test_http_info(async_protocol);
3007 SET_EXPECT(GetBindInfo);
3008 SET_EXPECT(ReportProgress_FINDINGRESOURCE);
3009 SET_EXPECT(ReportProgress_CONNECTING);
3010 SET_EXPECT(ReportProgress_SENDINGREQUEST);
3011 SET_EXPECT(Switch);
3013 hres = IInternetProtocol_Start(async_protocol, ftp_urlW, &protocol_sink, &bind_info, 0, 0);
3014 ok(hres == S_OK, "Start failed: %08x\n", hres);
3015 CHECK_CALLED(GetBindInfo);
3017 SET_EXPECT(ReportResult);
3019 hres = IInternetProtocol_Read(async_protocol, buf, 1, &cb);
3020 ok((hres == E_PENDING && cb==0) ||
3021 (hres == S_OK && cb==1), "Read failed: %08x (%d bytes)\n", hres, cb);
3023 WaitForSingleObject(event_complete, INFINITE);
3025 while(1) {
3026 hres = IInternetProtocol_Read(async_protocol, buf, sizeof(buf), &cb);
3027 if(hres == E_PENDING)
3028 WaitForSingleObject(event_complete, INFINITE);
3029 else
3030 if(cb == 0) break;
3033 ok(hres == S_FALSE, "Read failed: %08x\n", hres);
3034 CHECK_CALLED(ReportResult);
3035 CHECK_CALLED(Switch);
3037 test_protocol_terminate(async_protocol);
3039 if(pCreateUri) {
3040 IInternetProtocolEx *protocolex;
3042 hres = IInternetProtocol_QueryInterface(async_protocol, &IID_IInternetProtocolEx, (void**)&protocolex);
3043 ok(hres == S_OK, "Could not get IInternetProtocolEx iface: %08x\n", hres);
3044 IInternetProtocolEx_Release(protocolex);
3047 ref = IInternetProtocol_Release(async_protocol);
3048 ok(!ref, "ref=%d\n", ref);
3050 test_early_abort(&CLSID_FtpProtocol);
3053 static void test_gopher_protocol(void)
3055 IInternetProtocolInfo *protocol_info;
3056 IClassFactory *factory;
3057 IUnknown *unk;
3058 HRESULT hres;
3060 trace("Testing gopher protocol...\n");
3062 hres = CoGetClassObject(&CLSID_GopherProtocol, CLSCTX_INPROC_SERVER, NULL, &IID_IUnknown, (void**)&unk);
3063 ok(hres == S_OK ||
3064 hres == REGDB_E_CLASSNOTREG, /* Gopher protocol has been removed as of Vista */
3065 "CoGetClassObject failed: %08x\n", hres);
3066 if(FAILED(hres))
3067 return;
3069 hres = IUnknown_QueryInterface(unk, &IID_IInternetProtocolInfo, (void**)&protocol_info);
3070 ok(hres == E_NOINTERFACE, "Could not get IInternetProtocolInfo interface: %08x, expected E_NOINTERFACE\n", hres);
3072 hres = IUnknown_QueryInterface(unk, &IID_IClassFactory, (void**)&factory);
3073 ok(hres == S_OK, "Could not get IClassFactory interface\n");
3074 IUnknown_Release(unk);
3075 if(FAILED(hres))
3076 return;
3078 hres = IClassFactory_CreateInstance(factory, NULL, &IID_IInternetProtocol,
3079 (void**)&async_protocol);
3080 IClassFactory_Release(factory);
3081 ok(hres == S_OK, "Could not get IInternetProtocol: %08x\n", hres);
3083 test_priority(async_protocol);
3085 IInternetProtocol_Release(async_protocol);
3087 test_early_abort(&CLSID_GopherProtocol);
3090 static void test_mk_protocol(void)
3092 IInternetProtocolInfo *protocol_info;
3093 IInternetProtocol *protocol;
3094 IClassFactory *factory;
3095 IUnknown *unk;
3096 HRESULT hres;
3098 static const WCHAR wrong_url1[] = {'t','e','s','t',':','@','M','S','I','T','S','t','o','r','e',
3099 ':',':','/','t','e','s','t','.','h','t','m','l',0};
3100 static const WCHAR wrong_url2[] = {'m','k',':','/','t','e','s','t','.','h','t','m','l',0};
3102 trace("Testing mk protocol...\n");
3103 init_test(MK_TEST, 0);
3105 hres = CoGetClassObject(&CLSID_MkProtocol, CLSCTX_INPROC_SERVER, NULL,
3106 &IID_IUnknown, (void**)&unk);
3107 ok(hres == S_OK, "CoGetClassObject failed: %08x\n", hres);
3109 hres = IUnknown_QueryInterface(unk, &IID_IInternetProtocolInfo, (void**)&protocol_info);
3110 ok(hres == E_NOINTERFACE,
3111 "Could not get IInternetProtocolInfo interface: %08x, expected E_NOINTERFACE\n",
3112 hres);
3114 hres = IUnknown_QueryInterface(unk, &IID_IClassFactory, (void**)&factory);
3115 ok(hres == S_OK, "Could not get IClassFactory interface\n");
3116 IUnknown_Release(unk);
3117 if(FAILED(hres))
3118 return;
3120 hres = IClassFactory_CreateInstance(factory, NULL, &IID_IInternetProtocol,
3121 (void**)&protocol);
3122 IClassFactory_Release(factory);
3123 ok(hres == S_OK, "Could not get IInternetProtocol: %08x\n", hres);
3125 SET_EXPECT(GetBindInfo);
3126 hres = IInternetProtocol_Start(protocol, wrong_url1, &protocol_sink, &bind_info, 0, 0);
3127 ok(hres == MK_E_SYNTAX || hres == INET_E_INVALID_URL,
3128 "Start failed: %08x, expected MK_E_SYNTAX or INET_E_INVALID_URL\n", hres);
3129 CLEAR_CALLED(GetBindInfo);
3131 SET_EXPECT(GetBindInfo);
3132 SET_EXPECT(ReportProgress_DIRECTBIND);
3133 SET_EXPECT(ReportProgress_SENDINGREQUEST);
3134 SET_EXPECT(ReportProgress_MIMETYPEAVAILABLE);
3135 SET_EXPECT(ReportResult);
3136 expect_hrResult = INET_E_RESOURCE_NOT_FOUND;
3138 hres = IInternetProtocol_Start(protocol, wrong_url2, &protocol_sink, &bind_info, 0, 0);
3139 ok(hres == INET_E_RESOURCE_NOT_FOUND ||
3140 hres == INET_E_INVALID_URL, /* win2k3 */
3141 "Start failed: %08x, expected INET_E_RESOURCE_NOT_FOUND or INET_E_INVALID_URL\n", hres);
3143 if (hres == INET_E_RESOURCE_NOT_FOUND) {
3144 CHECK_CALLED(GetBindInfo);
3145 CLEAR_CALLED(ReportProgress_DIRECTBIND);
3146 CHECK_CALLED(ReportProgress_SENDINGREQUEST);
3147 CHECK_CALLED(ReportProgress_MIMETYPEAVAILABLE);
3148 CHECK_CALLED(ReportResult);
3149 }else {
3150 CLEAR_CALLED(GetBindInfo);
3151 CLEAR_CALLED(ReportProgress_DIRECTBIND);
3152 CLEAR_CALLED(ReportProgress_SENDINGREQUEST);
3153 CLEAR_CALLED(ReportProgress_MIMETYPEAVAILABLE);
3154 CLEAR_CALLED(ReportResult);
3157 IInternetProtocol_Release(protocol);
3160 static void test_CreateBinding(void)
3162 IInternetProtocol *protocol;
3163 IInternetPriority *priority;
3164 IInternetSession *session;
3165 IWinInetHttpInfo *http_info;
3166 IWinInetInfo *inet_info;
3167 LONG p;
3168 BYTE buf[1000];
3169 DWORD read;
3170 HRESULT hres;
3172 static const WCHAR test_url[] =
3173 {'t','e','s','t',':','/','/','f','i','l','e','.','h','t','m','l',0};
3174 static const WCHAR wsz_test[] = {'t','e','s','t',0};
3176 trace("Testing CreateBinding...\n");
3177 init_test(BIND_TEST, TEST_BINDING);
3179 hres = pCoInternetGetSession(0, &session, 0);
3180 ok(hres == S_OK, "CoInternetGetSession failed: %08x\n", hres);
3182 hres = IInternetSession_RegisterNameSpace(session, &ClassFactory, &IID_NULL, wsz_test, 0, NULL, 0);
3183 ok(hres == S_OK, "RegisterNameSpace failed: %08x\n", hres);
3185 hres = IInternetSession_CreateBinding(session, NULL, test_url, NULL, NULL, &protocol, 0);
3186 binding_protocol = protocol;
3187 ok(hres == S_OK, "CreateBinding failed: %08x\n", hres);
3188 ok(protocol != NULL, "protocol == NULL\n");
3190 hres = IInternetProtocol_QueryInterface(protocol, &IID_IInternetBindInfo, (void**)&prot_bind_info);
3191 ok(hres == S_OK, "QueryInterface(IID_IInternetBindInfo) failed: %08x\n", hres);
3193 hres = IInternetProtocol_QueryInterface(protocol, &IID_IInternetProtocolSink, (void**)&binding_sink);
3194 ok(hres == S_OK, "Could not get IInternetProtocolSink: %08x\n", hres);
3196 hres = IInternetProtocol_Start(protocol, test_url, NULL, &bind_info, 0, 0);
3197 ok(hres == E_INVALIDARG, "Start failed: %08x, expected E_INVALIDARG\n", hres);
3198 hres = IInternetProtocol_Start(protocol, test_url, &protocol_sink, NULL, 0, 0);
3199 ok(hres == E_INVALIDARG, "Start failed: %08x, expected E_INVALIDARG\n", hres);
3200 hres = IInternetProtocol_Start(protocol, NULL, &protocol_sink, &bind_info, 0, 0);
3201 ok(hres == E_INVALIDARG, "Start failed: %08x, expected E_INVALIDARG\n", hres);
3203 hres = IInternetProtocol_QueryInterface(protocol, &IID_IInternetPriority, (void**)&priority);
3204 ok(hres == S_OK, "QueryInterface(IID_IInternetPriority) failed: %08x\n", hres);
3206 p = 0xdeadbeef;
3207 hres = IInternetPriority_GetPriority(priority, &p);
3208 ok(hres == S_OK, "GetPriority failed: %08x\n", hres);
3209 ok(!p, "p=%d\n", p);
3211 ex_priority = 100;
3212 hres = IInternetPriority_SetPriority(priority, 100);
3213 ok(hres == S_OK, "SetPriority failed: %08x\n", hres);
3215 p = 0xdeadbeef;
3216 hres = IInternetPriority_GetPriority(priority, &p);
3217 ok(hres == S_OK, "GetPriority failed: %08x\n", hres);
3218 ok(p == 100, "p=%d\n", p);
3220 hres = IInternetProtocol_QueryInterface(protocol, &IID_IWinInetInfo, (void**)&inet_info);
3221 ok(hres == E_NOINTERFACE, "Could not get IWinInetInfo protocol: %08x\n", hres);
3223 SET_EXPECT(QueryService_InternetProtocol);
3224 SET_EXPECT(CreateInstance);
3225 SET_EXPECT(ReportProgress_PROTOCOLCLASSID);
3226 SET_EXPECT(SetPriority);
3227 SET_EXPECT(Start);
3229 expect_hrResult = S_OK;
3230 hres = IInternetProtocol_Start(protocol, test_url, &protocol_sink, &bind_info, 0, 0);
3231 ok(hres == S_OK, "Start failed: %08x\n", hres);
3233 CHECK_CALLED(QueryService_InternetProtocol);
3234 CHECK_CALLED(CreateInstance);
3235 CHECK_CALLED(ReportProgress_PROTOCOLCLASSID);
3236 CHECK_CALLED(SetPriority);
3237 CHECK_CALLED(Start);
3239 SET_EXPECT(QueryInterface_IWinInetInfo);
3240 hres = IInternetProtocol_QueryInterface(protocol, &IID_IWinInetInfo, (void**)&inet_info);
3241 ok(hres == E_NOINTERFACE, "Could not get IWinInetInfo protocol: %08x\n", hres);
3242 CHECK_CALLED(QueryInterface_IWinInetInfo);
3244 SET_EXPECT(QueryInterface_IWinInetInfo);
3245 hres = IInternetProtocol_QueryInterface(protocol, &IID_IWinInetInfo, (void**)&inet_info);
3246 ok(hres == E_NOINTERFACE, "Could not get IWinInetInfo protocol: %08x\n", hres);
3247 CHECK_CALLED(QueryInterface_IWinInetInfo);
3249 SET_EXPECT(QueryInterface_IWinInetHttpInfo);
3250 hres = IInternetProtocol_QueryInterface(protocol, &IID_IWinInetHttpInfo, (void**)&http_info);
3251 ok(hres == E_NOINTERFACE, "Could not get IWinInetInfo protocol: %08x\n", hres);
3252 CHECK_CALLED(QueryInterface_IWinInetHttpInfo);
3254 SET_EXPECT(Read);
3255 read = 0xdeadbeef;
3256 hres = IInternetProtocol_Read(protocol, expect_pv = buf, sizeof(buf), &read);
3257 ok(hres == S_OK, "Read failed: %08x\n", hres);
3258 ok(read == 100, "read = %d\n", read);
3259 CHECK_CALLED(Read);
3261 SET_EXPECT(Read);
3262 read = 0xdeadbeef;
3263 hres = IInternetProtocol_Read(protocol, expect_pv = buf, sizeof(buf), &read);
3264 ok(hres == S_FALSE, "Read failed: %08x\n", hres);
3265 ok(!read, "read = %d\n", read);
3266 CHECK_CALLED(Read);
3268 p = 0xdeadbeef;
3269 hres = IInternetPriority_GetPriority(priority, &p);
3270 ok(hres == S_OK, "GetPriority failed: %08x\n", hres);
3271 ok(p == 100, "p=%d\n", p);
3273 hres = IInternetPriority_SetPriority(priority, 101);
3274 ok(hres == S_OK, "SetPriority failed: %08x\n", hres);
3276 SET_EXPECT(Terminate);
3277 hres = IInternetProtocol_Terminate(protocol, 0xdeadbeef);
3278 ok(hres == S_OK, "Terminate failed: %08x\n", hres);
3279 CHECK_CALLED(Terminate);
3281 SET_EXPECT(Continue);
3282 hres = IInternetProtocolSink_Switch(binding_sink, &protocoldata);
3283 ok(hres == S_OK, "Switch failed: %08x\n", hres);
3284 CHECK_CALLED(Continue);
3286 hres = IInternetProtocolSink_ReportProgress(binding_sink,
3287 BINDSTATUS_CACHEFILENAMEAVAILABLE, expect_wsz = emptyW);
3288 ok(hres == S_OK, "ReportProgress(BINDSTATUS_CACHEFILENAMEAVAILABLE) failed: %08x\n", hres);
3290 hres = IInternetProtocolSink_ReportResult(binding_sink, S_OK, ERROR_SUCCESS, NULL);
3291 ok(hres == E_FAIL, "ReportResult failed: %08x, expected E_FAIL\n", hres);
3293 hres = IInternetProtocolSink_ReportData(binding_sink, 0, 0, 0);
3294 ok(hres == S_OK, "ReportData failed: %08x\n", hres);
3296 IInternetProtocolSink_Release(binding_sink);
3297 IInternetPriority_Release(priority);
3298 IInternetBindInfo_Release(prot_bind_info);
3299 IInternetProtocol_Release(protocol);
3301 hres = IInternetSession_CreateBinding(session, NULL, test_url, NULL, NULL, &protocol, 0);
3302 ok(hres == S_OK, "CreateBinding failed: %08x\n", hres);
3303 ok(protocol != NULL, "protocol == NULL\n");
3305 hres = IInternetProtocol_Abort(protocol, E_ABORT, 0);
3306 ok(hres == S_OK, "Abort failed: %08x\n", hres);
3308 hres = IInternetProtocol_Abort(protocol, E_FAIL, 0);
3309 ok(hres == S_OK, "Abort failed: %08x\n", hres);
3311 IInternetProtocol_Release(protocol);
3313 hres = IInternetSession_UnregisterNameSpace(session, &ClassFactory, wsz_test);
3314 ok(hres == S_OK, "UnregisterNameSpace failed: %08x\n", hres);
3316 hres = IInternetSession_CreateBinding(session, NULL, test_url, NULL, NULL, &protocol, 0);
3317 ok(hres == S_OK, "CreateBinding failed: %08x\n", hres);
3318 ok(protocol != NULL, "protocol == NULL\n");
3320 SET_EXPECT(QueryService_InternetProtocol);
3321 hres = IInternetProtocol_Start(protocol, test_url, &protocol_sink, &bind_info, 0, 0);
3322 ok(hres == MK_E_SYNTAX, "Start failed: %08x, expected MK_E_SYNTAX\n", hres);
3323 CHECK_CALLED(QueryService_InternetProtocol);
3325 IInternetProtocol_Release(protocol);
3327 IInternetSession_Release(session);
3330 static void test_binding(int prot, DWORD grf_pi, DWORD test_flags)
3332 IInternetProtocolEx *protocolex = NULL;
3333 IInternetProtocol *protocol;
3334 IInternetSession *session;
3335 IUri *uri = NULL;
3336 ULONG ref;
3337 HRESULT hres;
3339 pi = grf_pi;
3341 init_test(prot, test_flags|TEST_BINDING);
3343 hres = pCoInternetGetSession(0, &session, 0);
3344 ok(hres == S_OK, "CoInternetGetSession failed: %08x\n", hres);
3346 if(test_flags & TEST_EMULATEPROT) {
3347 hres = IInternetSession_RegisterNameSpace(session, &ClassFactory, &IID_NULL, protocol_names[prot], 0, NULL, 0);
3348 ok(hres == S_OK, "RegisterNameSpace failed: %08x\n", hres);
3351 hres = IInternetSession_CreateBinding(session, NULL, binding_urls[prot], NULL, NULL, &protocol, 0);
3352 binding_protocol = protocol;
3353 ok(hres == S_OK, "CreateBinding failed: %08x\n", hres);
3354 ok(protocol != NULL, "protocol == NULL\n");
3356 hres = IInternetProtocol_QueryInterface(protocol, &IID_IInternetBindInfo, (void**)&prot_bind_info);
3357 ok(hres == S_OK, "QueryInterface(IID_IInternetBindInfo) failed: %08x\n", hres);
3359 hres = IInternetProtocol_QueryInterface(protocol, &IID_IInternetProtocolSink, (void**)&binding_sink);
3360 ok(hres == S_OK, "QueryInterface(IID_IInternetProtocolSink) failed: %08x\n", hres);
3362 if(test_flags & TEST_USEIURI) {
3363 hres = IInternetProtocol_QueryInterface(protocol, &IID_IInternetProtocolEx, (void**)&protocolex);
3364 ok(hres == S_OK, "Could not get IInternetProtocolEx iface: %08x\n", hres);
3366 hres = pCreateUri(binding_urls[prot], Uri_CREATE_FILE_USE_DOS_PATH, 0, &uri);
3367 ok(hres == S_OK, "CreateUri failed: %08x\n", hres);
3370 ex_priority = 0;
3371 SET_EXPECT(QueryService_InternetProtocol);
3372 SET_EXPECT(CreateInstance);
3373 SET_EXPECT(ReportProgress_PROTOCOLCLASSID);
3374 SET_EXPECT(SetPriority);
3375 if(impl_protex)
3376 SET_EXPECT(StartEx);
3377 else
3378 SET_EXPECT(Start);
3380 expect_hrResult = S_OK;
3382 if(protocolex) {
3383 hres = IInternetProtocolEx_StartEx(protocolex, uri, &protocol_sink, &bind_info, pi, 0);
3384 ok(hres == S_OK, "StartEx failed: %08x\n", hres);
3385 }else {
3386 hres = IInternetProtocol_Start(protocol, binding_urls[prot], &protocol_sink, &bind_info, pi, 0);
3387 ok(hres == S_OK, "Start failed: %08x\n", hres);
3390 CHECK_CALLED(QueryService_InternetProtocol);
3391 CHECK_CALLED(CreateInstance);
3392 CHECK_CALLED(ReportProgress_PROTOCOLCLASSID);
3393 CHECK_CALLED(SetPriority);
3394 if(impl_protex)
3395 CHECK_CALLED(StartEx);
3396 else
3397 CHECK_CALLED(Start);
3399 if(protocolex)
3400 IInternetProtocolEx_Release(protocolex);
3401 if(uri)
3402 IUri_Release(uri);
3404 if(prot == HTTP_TEST || prot == HTTPS_TEST) {
3405 while(prot_state < 4) {
3406 WaitForSingleObject(event_complete, INFINITE);
3407 if(mimefilter_test && filtered_protocol) {
3408 SET_EXPECT(Continue);
3409 IInternetProtocol_Continue(filtered_protocol, pdata);
3410 CHECK_CALLED(Continue);
3411 }else {
3412 SET_EXPECT(Continue);
3413 IInternetProtocol_Continue(protocol, pdata);
3414 CHECK_CALLED(Continue);
3416 if(test_abort && prot_state == 2) {
3417 SET_EXPECT(Abort);
3418 hres = IInternetProtocol_Abort(protocol, E_ABORT, 0);
3419 ok(hres == S_OK, "Abort failed: %08x\n", hres);
3420 CHECK_CALLED(Abort);
3422 hres = IInternetProtocol_Abort(protocol, E_ABORT, 0);
3423 ok(hres == S_OK, "Abort failed: %08x\n", hres);
3424 SetEvent(event_complete2);
3425 break;
3427 SetEvent(event_complete2);
3429 if(direct_read)
3430 CHECK_CALLED(ReportData); /* Set in ReportResult */
3431 WaitForSingleObject(event_complete, INFINITE);
3432 }else {
3433 if(mimefilter_test)
3434 SET_EXPECT(MimeFilter_LockRequest);
3435 else
3436 SET_EXPECT(LockRequest);
3437 hres = IInternetProtocol_LockRequest(protocol, 0);
3438 ok(hres == S_OK, "LockRequest failed: %08x\n", hres);
3439 if(mimefilter_test)
3440 CHECK_CALLED(MimeFilter_LockRequest);
3441 else
3442 CHECK_CALLED(LockRequest);
3444 if(mimefilter_test)
3445 SET_EXPECT(MimeFilter_UnlockRequest);
3446 else
3447 SET_EXPECT(UnlockRequest);
3448 hres = IInternetProtocol_UnlockRequest(protocol);
3449 ok(hres == S_OK, "UnlockRequest failed: %08x\n", hres);
3450 if(mimefilter_test)
3451 CHECK_CALLED(MimeFilter_UnlockRequest);
3452 else
3453 CHECK_CALLED(UnlockRequest);
3456 if(mimefilter_test)
3457 SET_EXPECT(MimeFilter_Terminate);
3458 else
3459 SET_EXPECT(Terminate);
3460 hres = IInternetProtocol_Terminate(protocol, 0);
3461 ok(hres == S_OK, "Terminate failed: %08x\n", hres);
3462 if(mimefilter_test)
3463 CLEAR_CALLED(MimeFilter_Terminate);
3464 else
3465 CHECK_CALLED(Terminate);
3467 if(filtered_protocol)
3468 IInternetProtocol_Release(filtered_protocol);
3469 IInternetBindInfo_Release(prot_bind_info);
3470 IInternetProtocolSink_Release(binding_sink);
3471 ref = IInternetProtocol_Release(protocol);
3472 ok(!ref, "ref=%u, expected 0\n", ref);
3474 if(test_flags & TEST_EMULATEPROT) {
3475 hres = IInternetSession_UnregisterNameSpace(session, &ClassFactory, protocol_names[prot]);
3476 ok(hres == S_OK, "UnregisterNameSpace failed: %08x\n", hres);
3479 IInternetSession_Release(session);
3482 START_TEST(protocol)
3484 HMODULE hurlmon;
3486 hurlmon = GetModuleHandle("urlmon.dll");
3487 pCoInternetGetSession = (void*) GetProcAddress(hurlmon, "CoInternetGetSession");
3488 pReleaseBindInfo = (void*) GetProcAddress(hurlmon, "ReleaseBindInfo");
3489 pCreateUri = (void*) GetProcAddress(hurlmon, "CreateUri");
3491 if(!GetProcAddress(hurlmon, "CompareSecurityIds")) {
3492 win_skip("Various needed functions not present, too old IE\n");
3493 return;
3496 if(!pCreateUri)
3497 win_skip("CreateUri not supported\n");
3499 OleInitialize(NULL);
3501 event_complete = CreateEvent(NULL, FALSE, FALSE, NULL);
3502 event_complete2 = CreateEvent(NULL, FALSE, FALSE, NULL);
3503 event_continue = CreateEvent(NULL, FALSE, FALSE, NULL);
3504 event_continue_done = CreateEvent(NULL, FALSE, FALSE, NULL);
3505 thread_id = GetCurrentThreadId();
3507 test_file_protocol();
3508 test_http_protocol();
3509 test_https_protocol();
3510 test_ftp_protocol();
3511 test_gopher_protocol();
3512 test_mk_protocol();
3513 test_CreateBinding();
3515 bindf &= ~BINDF_FROMURLMON;
3516 trace("Testing file binding (mime verification, emulate prot)...\n");
3517 test_binding(FILE_TEST, PI_MIMEVERIFICATION, TEST_EMULATEPROT);
3518 trace("Testing http binding (mime verification, emulate prot)...\n");
3519 test_binding(HTTP_TEST, PI_MIMEVERIFICATION, TEST_EMULATEPROT);
3520 trace("Testing its binding (mime verification, emulate prot)...\n");
3521 test_binding(ITS_TEST, PI_MIMEVERIFICATION, TEST_EMULATEPROT);
3522 trace("Testing http binding (mime verification, emulate prot, short read, direct read)...\n");
3523 test_binding(HTTP_TEST, PI_MIMEVERIFICATION, TEST_EMULATEPROT|TEST_SHORT_READ|TEST_DIRECT_READ);
3524 trace("Testing file binding (mime verification, emulate prot, mime filter)...\n");
3525 test_binding(FILE_TEST, PI_MIMEVERIFICATION, TEST_EMULATEPROT|TEST_FILTER);
3526 trace("Testing http binding (mime verification, emulate prot, mime filter)...\n");
3527 test_binding(HTTP_TEST, PI_MIMEVERIFICATION, TEST_EMULATEPROT|TEST_FILTER);
3528 trace("Testing http binding (mime verification, emulate prot, direct read)...\n");
3529 test_binding(HTTP_TEST, PI_MIMEVERIFICATION, TEST_EMULATEPROT|TEST_DIRECT_READ);
3530 trace("Testing http binding (mime verification, emulate prot, abort)...\n");
3531 test_binding(HTTP_TEST, PI_MIMEVERIFICATION, TEST_EMULATEPROT|TEST_ABORT);
3532 if(pCreateUri) {
3533 trace("Testing file binding (use IUri, mime verification, emulate prot)...\n");
3534 test_binding(FILE_TEST, PI_MIMEVERIFICATION, TEST_EMULATEPROT|TEST_USEIURI);
3535 trace("Testing file binding (use IUri, impl StartEx, mime verification, emulate prot)...\n");
3536 test_binding(FILE_TEST, PI_MIMEVERIFICATION, TEST_EMULATEPROT|TEST_USEIURI|TEST_IMPLPROTEX);
3537 trace("Testing file binding (impl StartEx, mime verification, emulate prot)...\n");
3538 test_binding(FILE_TEST, PI_MIMEVERIFICATION, TEST_EMULATEPROT|TEST_IMPLPROTEX);
3541 CloseHandle(event_complete);
3542 CloseHandle(event_complete2);
3543 CloseHandle(event_continue);
3544 CloseHandle(event_continue_done);
3546 OleUninitialize();