urlmon/tests: Fixed protocol tests on IE9.
[wine/multimedia.git] / dlls / urlmon / tests / protocol.c
blob98422feab18954f004a151c505cefad6ed4ed414
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_ReportData);
116 DEFINE_EXPECT(MimeFilter_ReportResult);
117 DEFINE_EXPECT(MimeFilter_Terminate);
118 DEFINE_EXPECT(MimeFilter_LockRequest);
119 DEFINE_EXPECT(MimeFilter_UnlockRequest);
120 DEFINE_EXPECT(MimeFilter_Read);
121 DEFINE_EXPECT(MimeFilter_Switch);
122 DEFINE_EXPECT(MimeFilter_Continue);
123 DEFINE_EXPECT(Stream_Seek);
124 DEFINE_EXPECT(Stream_Read);
126 static const WCHAR wszIndexHtml[] = {'i','n','d','e','x','.','h','t','m','l',0};
127 static const WCHAR index_url[] =
128 {'f','i','l','e',':','i','n','d','e','x','.','h','t','m','l',0};
130 static const WCHAR acc_mimeW[] = {'*','/','*',0};
131 static const WCHAR user_agentW[] = {'W','i','n','e',0};
132 static const WCHAR text_htmlW[] = {'t','e','x','t','/','h','t','m','l',0};
133 static const WCHAR hostW[] = {'w','w','w','.','w','i','n','e','h','q','.','o','r','g',0};
134 static const WCHAR winehq_ipW[] = {'2','0','9','.','4','6','.','2','5','.','1','3','4',0};
135 static const WCHAR emptyW[] = {0};
136 static const WCHAR gzipW[] = {'g','z','i','p',0};
138 static HRESULT expect_hrResult;
139 static LPCWSTR file_name, http_url, expect_wsz;
140 static IInternetProtocol *async_protocol = NULL;
141 static BOOL first_data_notif, http_is_first, test_redirect;
142 static int prot_state, read_report_data, post_stream_read;
143 static DWORD bindf, ex_priority , pi;
144 static IInternetProtocol *binding_protocol, *filtered_protocol;
145 static IInternetBindInfo *prot_bind_info;
146 static IInternetProtocolSink *binding_sink, *filtered_sink;
147 static void *expect_pv;
148 static HANDLE event_complete, event_complete2, event_continue, event_continue_done;
149 static BOOL binding_test;
150 static PROTOCOLDATA protocoldata, *pdata, continue_protdata;
151 static DWORD prot_read, pi, filter_state, http_post_test, thread_id;
152 static BOOL security_problem, test_async_req, impl_protex;
153 static BOOL async_read_pending, mimefilter_test, direct_read, wait_for_switch, emulate_prot, short_read, test_abort;
154 static BOOL empty_file;
156 enum {
157 STATE_CONNECTING,
158 STATE_SENDINGREQUEST,
159 STATE_STARTDOWNLOADING,
160 STATE_DOWNLOADING
161 } state;
163 static enum {
164 FILE_TEST,
165 HTTP_TEST,
166 HTTPS_TEST,
167 FTP_TEST,
168 MK_TEST,
169 ITS_TEST,
170 BIND_TEST
171 } tested_protocol;
173 static const WCHAR protocol_names[][10] = {
174 {'f','i','l','e',0},
175 {'h','t','t','p',0},
176 {'h','t','t','p','s',0},
177 {'f','t','p',0},
178 {'m','k',0},
179 {'i','t','s',0},
180 {'t','e','s','t',0}
183 static const WCHAR binding_urls[][130] = {
184 {'f','i','l','e',':','t','e','s','t','.','h','t','m','l',0},
185 {'h','t','t','p',':','/','/','w','w','w','.','w','i','n','e','h','q','.',
186 'o','r','g','/','s','i','t','e','/','a','b','o','u','t',0},
187 {'h','t','t','p','s',':','/','/','w','w','w','.','c','o','d','e','w','e','a','v','e','r','s',
188 '.','c','o','m','/','t','e','s','t','.','h','t','m','l',0},
189 {'f','t','p',':','/','/','f','t','p','.','w','i','n','e','h','q','.','o','r','g',
190 '/','p','u','b','/','o','t','h','e','r',
191 '/','w','i','n','e','l','o','g','o','.','x','c','f','.','t','a','r','.','b','z','2',0},
192 {'m','k',':','t','e','s','t',0},
193 {'i','t','s',':','t','e','s','t','.','c','h','m',':',':','/','b','l','a','n','k','.','h','t','m','l',0},
194 {'t','e','s','t',':','/','/','f','i','l','e','.','h','t','m','l',0}
197 static const CHAR post_data[] = "mode=Test";
199 static const char *debugstr_guid(REFIID riid)
201 static char buf[50];
203 sprintf(buf, "{%08X-%04X-%04X-%02X%02X-%02X%02X%02X%02X%02X%02X}",
204 riid->Data1, riid->Data2, riid->Data3, riid->Data4[0],
205 riid->Data4[1], riid->Data4[2], riid->Data4[3], riid->Data4[4],
206 riid->Data4[5], riid->Data4[6], riid->Data4[7]);
208 return buf;
211 static int strcmp_wa(LPCWSTR strw, const char *stra)
213 CHAR buf[512];
214 WideCharToMultiByte(CP_ACP, 0, strw, -1, buf, sizeof(buf), NULL, NULL);
215 return lstrcmpA(stra, buf);
218 static HRESULT WINAPI HttpSecurity_QueryInterface(IHttpSecurity *iface, REFIID riid, void **ppv)
220 if(IsEqualGUID(&IID_IUnknown, riid)
221 || IsEqualGUID(&IID_IHttpSecurity, riid)) {
222 *ppv = iface;
223 return S_OK;
226 ok(0, "unexpected call\n");
227 return E_NOINTERFACE;
230 static ULONG WINAPI HttpSecurity_AddRef(IHttpSecurity *iface)
232 return 2;
235 static ULONG WINAPI HttpSecurity_Release(IHttpSecurity *iface)
237 return 1;
240 static HRESULT WINAPI HttpSecurity_GetWindow(IHttpSecurity* iface, REFGUID rguidReason, HWND *phwnd)
242 trace("HttpSecurity_GetWindow\n");
244 return S_FALSE;
247 static HRESULT WINAPI HttpSecurity_OnSecurityProblem(IHttpSecurity *iface, DWORD dwProblem)
249 trace("Security problem: %u\n", dwProblem);
250 ok(dwProblem == ERROR_INTERNET_SEC_CERT_REV_FAILED, "Expected ERROR_INTERNET_SEC_CERT_REV_FAILED got %u\n", dwProblem);
252 /* Only retry once */
253 if (security_problem)
254 return E_ABORT;
256 security_problem = TRUE;
257 SET_EXPECT(BeginningTransaction);
259 return RPC_E_RETRY;
262 static IHttpSecurityVtbl HttpSecurityVtbl = {
263 HttpSecurity_QueryInterface,
264 HttpSecurity_AddRef,
265 HttpSecurity_Release,
266 HttpSecurity_GetWindow,
267 HttpSecurity_OnSecurityProblem
270 static IHttpSecurity http_security = { &HttpSecurityVtbl };
272 static HRESULT WINAPI HttpNegotiate_QueryInterface(IHttpNegotiate2 *iface, REFIID riid, void **ppv)
274 if(IsEqualGUID(&IID_IUnknown, riid)
275 || IsEqualGUID(&IID_IHttpNegotiate, riid)
276 || IsEqualGUID(&IID_IHttpNegotiate2, riid)) {
277 *ppv = iface;
278 return S_OK;
281 ok(0, "unexpected call\n");
282 return E_NOINTERFACE;
285 static ULONG WINAPI HttpNegotiate_AddRef(IHttpNegotiate2 *iface)
287 return 2;
290 static ULONG WINAPI HttpNegotiate_Release(IHttpNegotiate2 *iface)
292 return 1;
295 static HRESULT WINAPI HttpNegotiate_BeginningTransaction(IHttpNegotiate2 *iface, LPCWSTR szURL,
296 LPCWSTR szHeaders, DWORD dwReserved, LPWSTR *pszAdditionalHeaders)
298 LPWSTR addl_headers;
300 static const WCHAR wszHeaders[] =
301 {'C','o','n','t','e','n','t','-','T','y','p','e',':',' ','a','p','p','l','i','c','a','t',
302 'i','o','n','/','x','-','w','w','w','-','f','o','r','m','-','u','r','l','e','n','c','o',
303 'd','e','d','\r','\n',0};
305 CHECK_EXPECT(BeginningTransaction);
307 if(binding_test)
308 ok(!lstrcmpW(szURL, binding_urls[tested_protocol]), "szURL != http_url\n");
309 else
310 ok(!lstrcmpW(szURL, http_url), "szURL != http_url\n");
311 ok(!dwReserved, "dwReserved=%d, expected 0\n", dwReserved);
312 ok(pszAdditionalHeaders != NULL, "pszAdditionalHeaders == NULL\n");
313 if(pszAdditionalHeaders)
315 ok(*pszAdditionalHeaders == NULL, "*pszAdditionalHeaders != NULL\n");
316 if (http_post_test)
318 addl_headers = CoTaskMemAlloc(sizeof(wszHeaders));
319 memcpy(addl_headers, wszHeaders, sizeof(wszHeaders));
320 *pszAdditionalHeaders = addl_headers;
324 return S_OK;
327 static HRESULT WINAPI HttpNegotiate_OnResponse(IHttpNegotiate2 *iface, DWORD dwResponseCode,
328 LPCWSTR szResponseHeaders, LPCWSTR szRequestHeaders, LPWSTR *pszAdditionalRequestHeaders)
330 CHECK_EXPECT(OnResponse);
332 ok(dwResponseCode == 200, "dwResponseCode=%d, expected 200\n", dwResponseCode);
333 ok(szResponseHeaders != NULL, "szResponseHeaders == NULL\n");
334 ok(szRequestHeaders == NULL, "szRequestHeaders != NULL\n");
335 ok(pszAdditionalRequestHeaders == NULL, "pszAdditionalHeaders != NULL\n");
337 return S_OK;
340 static HRESULT WINAPI HttpNegotiate_GetRootSecurityId(IHttpNegotiate2 *iface,
341 BYTE *pbSecurityId, DWORD *pcbSecurityId, DWORD_PTR dwReserved)
343 static const BYTE sec_id[] = {'h','t','t','p',':','t','e','s','t',1,0,0,0};
345 CHECK_EXPECT(GetRootSecurityId);
347 ok(!dwReserved, "dwReserved=%ld, expected 0\n", dwReserved);
348 ok(pbSecurityId != NULL, "pbSecurityId == NULL\n");
349 ok(pcbSecurityId != NULL, "pcbSecurityId == NULL\n");
351 if(pcbSecurityId) {
352 ok(*pcbSecurityId == 512, "*pcbSecurityId=%d, expected 512\n", *pcbSecurityId);
353 *pcbSecurityId = sizeof(sec_id);
356 if(pbSecurityId)
357 memcpy(pbSecurityId, sec_id, sizeof(sec_id));
359 return E_FAIL;
362 static IHttpNegotiate2Vtbl HttpNegotiateVtbl = {
363 HttpNegotiate_QueryInterface,
364 HttpNegotiate_AddRef,
365 HttpNegotiate_Release,
366 HttpNegotiate_BeginningTransaction,
367 HttpNegotiate_OnResponse,
368 HttpNegotiate_GetRootSecurityId
371 static IHttpNegotiate2 http_negotiate = { &HttpNegotiateVtbl };
373 static HRESULT QueryInterface(REFIID,void**);
375 static HRESULT WINAPI ServiceProvider_QueryInterface(IServiceProvider *iface, REFIID riid, void **ppv)
377 return QueryInterface(riid, ppv);
380 static ULONG WINAPI ServiceProvider_AddRef(IServiceProvider *iface)
382 return 2;
385 static ULONG WINAPI ServiceProvider_Release(IServiceProvider *iface)
387 return 1;
390 static HRESULT WINAPI ServiceProvider_QueryService(IServiceProvider *iface, REFGUID guidService,
391 REFIID riid, void **ppv)
393 if(IsEqualGUID(&IID_IHttpNegotiate, guidService) || IsEqualGUID(&IID_IHttpNegotiate2, riid)) {
394 CHECK_EXPECT2(QueryService_HttpNegotiate);
395 return IHttpNegotiate2_QueryInterface(&http_negotiate, riid, ppv);
398 if(IsEqualGUID(&IID_IInternetProtocol, guidService)) {
399 ok(IsEqualGUID(&IID_IInternetProtocol, riid), "unexpected riid\n");
400 CHECK_EXPECT(QueryService_InternetProtocol);
401 return E_NOINTERFACE;
404 if(IsEqualGUID(&IID_IHttpSecurity, guidService)) {
405 ok(IsEqualGUID(&IID_IHttpSecurity, riid), "unexpected riid\n");
406 CHECK_EXPECT(QueryService_HttpSecurity);
407 return IHttpSecurity_QueryInterface(&http_security, riid, ppv);
410 ok(0, "unexpected service %s\n", debugstr_guid(guidService));
411 return E_FAIL;
414 static const IServiceProviderVtbl ServiceProviderVtbl = {
415 ServiceProvider_QueryInterface,
416 ServiceProvider_AddRef,
417 ServiceProvider_Release,
418 ServiceProvider_QueryService
421 static IServiceProvider service_provider = { &ServiceProviderVtbl };
423 static HRESULT WINAPI Stream_QueryInterface(IStream *iface, REFIID riid, void **ppv)
425 ok(0, "unexpected call\n");
426 return E_NOINTERFACE;
429 static ULONG WINAPI Stream_AddRef(IStream *iface)
431 return 2;
434 static ULONG WINAPI Stream_Release(IStream *iface)
436 return 1;
439 static HRESULT WINAPI Stream_Read(IStream *iface, void *pv,
440 ULONG cb, ULONG *pcbRead)
442 CHECK_EXPECT2(Stream_Read);
444 ok(GetCurrentThreadId() != thread_id, "wrong thread %d\n", GetCurrentThreadId());
446 ok(pv != NULL, "pv == NULL\n");
447 ok(cb == 0x20000 || broken(cb == 0x2000), "cb = %d\n", cb);
448 ok(pcbRead != NULL, "pcbRead == NULL\n");
450 if(post_stream_read) {
451 *pcbRead = 0;
452 return S_FALSE;
455 memcpy(pv, post_data, sizeof(post_data)-1);
456 post_stream_read += *pcbRead = sizeof(post_data)-1;
457 return S_OK;
460 static HRESULT WINAPI Stream_Write(IStream *iface, const void *pv,
461 ULONG cb, ULONG *pcbWritten)
463 ok(0, "unexpected call\n");
464 return E_NOTIMPL;
467 static HRESULT WINAPI Stream_Seek(IStream *iface, LARGE_INTEGER dlibMove,
468 DWORD dwOrigin, ULARGE_INTEGER *plibNewPosition)
470 CHECK_EXPECT(Stream_Seek);
472 ok(!dlibMove.QuadPart, "dlibMove != 0\n");
473 ok(dwOrigin == STREAM_SEEK_SET, "dwOrigin = %d\n", dwOrigin);
474 ok(!plibNewPosition, "plibNewPosition == NULL\n");
476 return S_OK;
479 static HRESULT WINAPI Stream_SetSize(IStream *iface, ULARGE_INTEGER libNewSize)
481 ok(0, "unexpected call\n");
482 return E_NOTIMPL;
485 static HRESULT WINAPI Stream_CopyTo(IStream *iface, IStream *pstm,
486 ULARGE_INTEGER cb, ULARGE_INTEGER *pcbRead, ULARGE_INTEGER *pcbWritten)
488 ok(0, "unexpected call\n");
489 return E_NOTIMPL;
492 static HRESULT WINAPI Stream_Commit(IStream *iface, DWORD grfCommitFlags)
494 ok(0, "unexpected call\n");
495 return E_NOTIMPL;
498 static HRESULT WINAPI Stream_Revert(IStream *iface)
500 ok(0, "unexpected call\n");
501 return E_NOTIMPL;
504 static HRESULT WINAPI Stream_LockRegion(IStream *iface, ULARGE_INTEGER libOffset,
505 ULARGE_INTEGER cb, DWORD dwLockType)
507 ok(0, "unexpected call\n");
508 return E_NOTIMPL;
511 static HRESULT WINAPI Stream_UnlockRegion(IStream *iface,
512 ULARGE_INTEGER libOffset, ULARGE_INTEGER cb, DWORD dwLockType)
514 ok(0, "unexpected call\n");
515 return E_NOTIMPL;
518 static HRESULT WINAPI Stream_Stat(IStream *iface, STATSTG *pstatstg,
519 DWORD dwStatFlag)
521 ok(0, "unexpected call\n");
522 return E_NOTIMPL;
525 static HRESULT WINAPI Stream_Clone(IStream *iface, IStream **ppstm)
527 ok(0, "unexpected call\n");
528 return E_NOTIMPL;
531 static const IStreamVtbl StreamVtbl = {
532 Stream_QueryInterface,
533 Stream_AddRef,
534 Stream_Release,
535 Stream_Read,
536 Stream_Write,
537 Stream_Seek,
538 Stream_SetSize,
539 Stream_CopyTo,
540 Stream_Commit,
541 Stream_Revert,
542 Stream_LockRegion,
543 Stream_UnlockRegion,
544 Stream_Stat,
545 Stream_Clone
548 static IStream Stream = { &StreamVtbl };
550 static HRESULT WINAPI ProtocolSink_QueryInterface(IInternetProtocolSink *iface, REFIID riid, void **ppv)
552 return QueryInterface(riid, ppv);
555 static ULONG WINAPI ProtocolSink_AddRef(IInternetProtocolSink *iface)
557 return 2;
560 static ULONG WINAPI ProtocolSink_Release(IInternetProtocolSink *iface)
562 return 1;
565 static void call_continue(PROTOCOLDATA *protocol_data)
567 HRESULT hres;
569 if(state == STATE_CONNECTING) {
570 if(tested_protocol == HTTP_TEST || tested_protocol == HTTPS_TEST)
571 CLEAR_CALLED(ReportProgress_COOKIE_SENT);
572 if(tested_protocol == HTTP_TEST || tested_protocol == HTTPS_TEST || tested_protocol == FTP_TEST) {
573 if (http_is_first){
574 CLEAR_CALLED(ReportProgress_FINDINGRESOURCE);
575 CLEAR_CALLED(ReportProgress_PROXYDETECTING);
577 CLEAR_CALLED(ReportProgress_CONNECTING);
579 if(tested_protocol == FTP_TEST)
580 todo_wine CHECK_CALLED(ReportProgress_SENDINGREQUEST);
581 else if (tested_protocol != HTTPS_TEST)
582 CHECK_CALLED(ReportProgress_SENDINGREQUEST);
583 if(test_redirect)
584 CHECK_CALLED(ReportProgress_REDIRECTING);
585 state = test_async_req ? STATE_SENDINGREQUEST : STATE_STARTDOWNLOADING;
588 switch(state) {
589 case STATE_SENDINGREQUEST:
590 SET_EXPECT(Stream_Read);
591 SET_EXPECT(ReportProgress_SENDINGREQUEST);
592 break;
593 case STATE_STARTDOWNLOADING:
594 if(tested_protocol == HTTP_TEST || tested_protocol == HTTPS_TEST) {
595 SET_EXPECT(OnResponse);
596 if(tested_protocol == HTTPS_TEST || test_redirect || test_abort || empty_file)
597 SET_EXPECT(ReportProgress_ACCEPTRANGES);
598 SET_EXPECT(ReportProgress_MIMETYPEAVAILABLE);
599 if(bindf & BINDF_NEEDFILE)
600 SET_EXPECT(ReportProgress_CACHEFILENAMEAVAILABLE);
602 default:
603 break;
606 if(state != STATE_SENDINGREQUEST)
607 SET_EXPECT(ReportData);
608 hres = IInternetProtocol_Continue(async_protocol, protocol_data);
609 ok(hres == S_OK, "Continue failed: %08x\n", hres);
610 if(tested_protocol == FTP_TEST || security_problem)
611 CLEAR_CALLED(ReportData);
612 else if(state != STATE_SENDINGREQUEST)
613 CHECK_CALLED(ReportData);
615 switch(state) {
616 case STATE_SENDINGREQUEST:
617 CHECK_CALLED(Stream_Read);
618 CHECK_CALLED(ReportProgress_SENDINGREQUEST);
619 state = STATE_STARTDOWNLOADING;
620 break;
621 case STATE_STARTDOWNLOADING:
622 if (! security_problem)
624 state = STATE_DOWNLOADING;
625 if(tested_protocol == HTTP_TEST || tested_protocol == HTTPS_TEST) {
626 CHECK_CALLED(OnResponse);
627 if(tested_protocol == HTTPS_TEST || empty_file)
628 CHECK_CALLED(ReportProgress_ACCEPTRANGES);
629 else if(test_redirect || test_abort)
630 CLEAR_CALLED(ReportProgress_ACCEPTRANGES);
631 CHECK_CALLED(ReportProgress_MIMETYPEAVAILABLE);
632 if(bindf & BINDF_NEEDFILE)
633 CHECK_CALLED(ReportProgress_CACHEFILENAMEAVAILABLE);
636 else
638 security_problem = FALSE;
639 SET_EXPECT(ReportProgress_CONNECTING);
641 default:
642 break;
646 static HRESULT WINAPI ProtocolSink_Switch(IInternetProtocolSink *iface, PROTOCOLDATA *pProtocolData)
648 if(tested_protocol == FTP_TEST)
649 CHECK_EXPECT2(Switch);
650 else
651 CHECK_EXPECT(Switch);
653 ok(pProtocolData != NULL, "pProtocolData == NULL\n");
654 if(binding_test) {
655 ok(pProtocolData != &protocoldata, "pProtocolData == &protocoldata\n");
656 ok(pProtocolData->grfFlags == protocoldata.grfFlags, "grfFlags wrong %x/%x\n",
657 pProtocolData->grfFlags, protocoldata.grfFlags );
658 ok(pProtocolData->dwState == protocoldata.dwState, "dwState wrong %x/%x\n",
659 pProtocolData->dwState, protocoldata.dwState );
660 ok(pProtocolData->pData == protocoldata.pData, "pData wrong %p/%p\n",
661 pProtocolData->pData, protocoldata.pData );
662 ok(pProtocolData->cbData == protocoldata.cbData, "cbData wrong %x/%x\n",
663 pProtocolData->cbData, protocoldata.cbData );
666 pdata = pProtocolData;
668 if(binding_test) {
669 SetEvent(event_complete);
670 WaitForSingleObject(event_complete2, INFINITE);
671 return S_OK;
672 }if(direct_read) {
673 continue_protdata = *pProtocolData;
674 SetEvent(event_continue);
675 WaitForSingleObject(event_continue_done, INFINITE);
676 }else {
677 call_continue(pProtocolData);
678 SetEvent(event_complete);
681 return S_OK;
684 static HRESULT WINAPI ProtocolSink_ReportProgress(IInternetProtocolSink *iface, ULONG ulStatusCode,
685 LPCWSTR szStatusText)
687 static const WCHAR null_guid[] = {'{','0','0','0','0','0','0','0','0','-','0','0','0','0','-',
688 '0','0','0','0','-','0','0','0','0','-','0','0','0','0','0','0','0','0','0','0','0','0','}',0};
689 static const WCHAR text_plain[] = {'t','e','x','t','/','p','l','a','i','n',0};
691 switch(ulStatusCode) {
692 case BINDSTATUS_MIMETYPEAVAILABLE:
693 CHECK_EXPECT(ReportProgress_MIMETYPEAVAILABLE);
694 if(tested_protocol != FILE_TEST && tested_protocol != ITS_TEST && !mimefilter_test && (pi & PI_MIMEVERIFICATION)) {
695 if(!short_read || !direct_read)
696 CHECK_CALLED(Read); /* set in Continue */
697 else if(short_read)
698 CHECK_CALLED(Read2); /* set in Read */
700 ok(szStatusText != NULL, "szStatusText == NULL\n");
701 if(szStatusText) {
702 if(tested_protocol == BIND_TEST)
703 ok(!lstrcmpW(szStatusText, expect_wsz), "unexpected szStatusText %s\n", wine_dbgstr_w(szStatusText));
704 else if (http_post_test)
705 ok(lstrlenW(text_plain) <= lstrlenW(szStatusText) &&
706 !memcmp(szStatusText, text_plain, lstrlenW(text_plain)*sizeof(WCHAR)),
707 "szStatusText != text/plain\n");
708 else if(empty_file)
709 ok(!strcmp_wa(szStatusText, "application/javascript"), "szStatusText = %s\n", wine_dbgstr_w(szStatusText));
710 else if(!mimefilter_test)
711 ok(lstrlenW(text_htmlW) <= lstrlenW(szStatusText) &&
712 !memcmp(szStatusText, text_htmlW, lstrlenW(text_htmlW)*sizeof(WCHAR)),
713 "szStatusText != text/html\n");
715 break;
716 case BINDSTATUS_DIRECTBIND:
717 CHECK_EXPECT2(ReportProgress_DIRECTBIND);
718 ok(szStatusText == NULL, "szStatusText != NULL\n");
719 break;
720 case BINDSTATUS_RAWMIMETYPE:
721 CHECK_EXPECT2(ReportProgress_RAWMIMETYPE);
722 ok(szStatusText != NULL, "szStatusText == NULL\n");
723 if(szStatusText)
724 ok(lstrlenW(szStatusText) < lstrlenW(text_htmlW) ||
725 !memcmp(szStatusText, text_htmlW, lstrlenW(text_htmlW)*sizeof(WCHAR)),
726 "szStatusText != text/html\n");
727 break;
728 case BINDSTATUS_CACHEFILENAMEAVAILABLE:
729 CHECK_EXPECT(ReportProgress_CACHEFILENAMEAVAILABLE);
730 ok(szStatusText != NULL, "szStatusText == NULL\n");
731 if(szStatusText) {
732 if(binding_test)
733 ok(!lstrcmpW(szStatusText, expect_wsz), "unexpected szStatusText\n");
734 else if(tested_protocol == FILE_TEST)
735 ok(!lstrcmpW(szStatusText, file_name), "szStatusText = %s\n", wine_dbgstr_w(szStatusText));
736 else
737 ok(szStatusText != NULL, "szStatusText == NULL\n");
739 break;
740 case BINDSTATUS_FINDINGRESOURCE:
741 CHECK_EXPECT2(ReportProgress_FINDINGRESOURCE);
742 ok(szStatusText != NULL, "szStatusText == NULL\n");
743 break;
744 case BINDSTATUS_CONNECTING:
745 CHECK_EXPECT2(ReportProgress_CONNECTING);
746 ok(szStatusText != NULL, "szStatusText == NULL\n");
747 break;
748 case BINDSTATUS_SENDINGREQUEST:
749 CHECK_EXPECT2(ReportProgress_SENDINGREQUEST);
750 if(tested_protocol == FILE_TEST || tested_protocol == ITS_TEST) {
751 ok(szStatusText != NULL, "szStatusText == NULL\n");
752 if(szStatusText)
753 ok(!*szStatusText, "wrong szStatusText\n");
755 break;
756 case BINDSTATUS_VERIFIEDMIMETYPEAVAILABLE:
757 CHECK_EXPECT(ReportProgress_VERIFIEDMIMETYPEAVAILABLE);
758 ok(szStatusText != NULL, "szStatusText == NULL\n");
759 if(szStatusText)
760 ok(!strcmp_wa(szStatusText, "text/html"), "szStatusText != text/html\n");
761 break;
762 case BINDSTATUS_PROTOCOLCLASSID:
763 CHECK_EXPECT(ReportProgress_PROTOCOLCLASSID);
764 ok(szStatusText != NULL, "szStatusText == NULL\n");
765 ok(!lstrcmpW(szStatusText, null_guid), "unexpected classid %s\n", wine_dbgstr_w(szStatusText));
766 break;
767 case BINDSTATUS_COOKIE_SENT:
768 CHECK_EXPECT(ReportProgress_COOKIE_SENT);
769 ok(szStatusText == NULL, "szStatusText != NULL\n");
770 break;
771 case BINDSTATUS_REDIRECTING:
772 CHECK_EXPECT(ReportProgress_REDIRECTING);
773 if(test_redirect)
774 ok(!strcmp_wa(szStatusText, "http://test.winehq.org/tests/hello.html"), "szStatusText = %s\n", wine_dbgstr_w(szStatusText));
775 else
776 ok(szStatusText == NULL, "szStatusText = %s\n", wine_dbgstr_w(szStatusText));
777 break;
778 case BINDSTATUS_ENCODING:
779 CHECK_EXPECT(ReportProgress_ENCODING);
780 ok(!strcmp_wa(szStatusText, "gzip"), "szStatusText = %s\n", wine_dbgstr_w(szStatusText));
781 break;
782 case BINDSTATUS_ACCEPTRANGES:
783 CHECK_EXPECT(ReportProgress_ACCEPTRANGES);
784 ok(!szStatusText, "szStatusText = %s\n", wine_dbgstr_w(szStatusText));
785 break;
786 case BINDSTATUS_PROXYDETECTING:
787 if(!called_ReportProgress_PROXYDETECTING)
788 SET_EXPECT(ReportProgress_CONNECTING);
789 CHECK_EXPECT2(ReportProgress_PROXYDETECTING);
790 ok(!szStatusText, "szStatusText = %s\n", wine_dbgstr_w(szStatusText));
791 break;
792 case BINDSTATUS_LOADINGMIMEHANDLER:
793 CHECK_EXPECT(ReportProgress_LOADINGMIMEHANDLER);
794 ok(!szStatusText, "szStatusText = %s\n", wine_dbgstr_w(szStatusText));
795 break;
796 case BINDSTATUS_DECODING:
797 CHECK_EXPECT(ReportProgress_DECODING);
798 ok(!lstrcmpW(szStatusText, gzipW), "szStatusText = %s\n", wine_dbgstr_w(szStatusText));
799 break;
800 default:
801 ok(0, "Unexpected status %d\n", ulStatusCode);
804 return S_OK;
807 static HRESULT WINAPI ProtocolSink_ReportData(IInternetProtocolSink *iface, DWORD grfBSCF,
808 ULONG ulProgress, ULONG ulProgressMax)
810 HRESULT hres;
812 static int rec_depth;
813 rec_depth++;
815 if(!mimefilter_test && (tested_protocol == FILE_TEST || tested_protocol == ITS_TEST)) {
816 CHECK_EXPECT2(ReportData);
818 ok(ulProgress == ulProgressMax, "ulProgress (%d) != ulProgressMax (%d)\n",
819 ulProgress, ulProgressMax);
820 ok(ulProgressMax == 13, "ulProgressMax=%d, expected 13\n", ulProgressMax);
821 /* BSCF_SKIPDRAINDATAFORFILEURLS added in IE8 */
822 if(tested_protocol == FILE_TEST)
823 ok((grfBSCF == (BSCF_FIRSTDATANOTIFICATION | BSCF_LASTDATANOTIFICATION)) ||
824 (grfBSCF == (BSCF_FIRSTDATANOTIFICATION | BSCF_LASTDATANOTIFICATION | BSCF_SKIPDRAINDATAFORFILEURLS)),
825 "grcfBSCF = %08x\n", grfBSCF);
826 else
827 ok(grfBSCF == (BSCF_FIRSTDATANOTIFICATION | BSCF_DATAFULLYAVAILABLE), "grcfBSCF = %08x\n", grfBSCF);
828 }else if(direct_read) {
829 BYTE buf[14096];
830 ULONG read;
832 if(!read_report_data && rec_depth == 1) {
833 BOOL reported_all_data = called_ReportData2;
835 CHECK_EXPECT2(ReportData);
837 if(short_read) {
838 ok(grfBSCF == (BSCF_FIRSTDATANOTIFICATION|BSCF_LASTDATANOTIFICATION|BSCF_DATAFULLYAVAILABLE)
839 || grfBSCF == BSCF_FIRSTDATANOTIFICATION, /* < IE8 */
840 "grcfBSCF = %08x\n", grfBSCF);
841 CHECK_CALLED(Read); /* Set in Continue */
842 first_data_notif = FALSE;
843 }else if(first_data_notif) {
844 ok(grfBSCF == BSCF_FIRSTDATANOTIFICATION, "grcfBSCF = %08x\n", grfBSCF);
845 first_data_notif = FALSE;
846 }else if(reported_all_data) {
847 ok(grfBSCF == (BSCF_LASTDATANOTIFICATION|BSCF_INTERMEDIATEDATANOTIFICATION),
848 "grcfBSCF = %08x\n", grfBSCF);
849 }else if(!direct_read) {
850 ok(grfBSCF == BSCF_INTERMEDIATEDATANOTIFICATION, "grcfBSCF = %08x\n", grfBSCF);
853 do {
854 read = 0;
855 if(emulate_prot)
856 SET_EXPECT(Read);
857 else
858 SET_EXPECT(ReportData2);
859 SET_EXPECT(ReportResult);
860 if(!emulate_prot)
861 SET_EXPECT(Switch);
862 hres = IInternetProtocol_Read(binding_test ? binding_protocol : async_protocol, expect_pv = buf, sizeof(buf), &read);
863 ok(hres == E_PENDING || hres == S_FALSE || hres == S_OK, "Read failed: %08x\n", hres);
864 if(hres == S_OK)
865 ok(read, "read == 0\n");
866 if(reported_all_data)
867 ok(hres == S_FALSE, "Read failed: %08x, expected S_FALSE\n", hres);
868 if(!emulate_prot && hres != E_PENDING)
869 CHECK_NOT_CALLED(Switch); /* otherwise checked in wait_for_switch loop */
870 if(emulate_prot)
871 CHECK_CALLED(Read);
872 if(!reported_all_data && called_ReportData2) {
873 if(!emulate_prot)
874 CHECK_CALLED(ReportData2);
875 CHECK_CALLED(ReportResult);
876 ok(hres == S_OK, "Read failed: %08x\n", hres);
877 reported_all_data = TRUE;
878 }else {
879 if(!emulate_prot)
880 CHECK_NOT_CALLED(ReportData2);
881 CHECK_NOT_CALLED(ReportResult);
883 }while(hres == S_OK);
884 if(hres == S_FALSE)
885 wait_for_switch = FALSE;
886 }else {
887 CHECK_EXPECT(ReportData2);
889 ok(grfBSCF & BSCF_LASTDATANOTIFICATION, "grfBSCF = %08x\n", grfBSCF);
891 read = 0xdeadbeef;
892 if(emulate_prot)
893 SET_EXPECT(Read2);
894 hres = IInternetProtocol_Read(binding_test ? binding_protocol : async_protocol, expect_pv = buf, sizeof(buf), &read);
895 if(emulate_prot)
896 CHECK_CALLED(Read2);
897 ok(hres == S_FALSE, "Read returned: %08x, expected E_FALSE\n", hres);
898 ok(!read, "read = %d\n", read);
900 }else if(!binding_test && (tested_protocol == HTTP_TEST || tested_protocol == HTTPS_TEST
901 || tested_protocol == FTP_TEST)) {
902 if(empty_file)
903 CHECK_EXPECT2(ReportData);
904 else if(!(grfBSCF & BSCF_LASTDATANOTIFICATION) || (grfBSCF & BSCF_DATAFULLYAVAILABLE))
905 CHECK_EXPECT(ReportData);
906 else if (http_post_test)
907 ok(ulProgress == 13, "Read %u bytes instead of 13\n", ulProgress);
909 if(empty_file) {
910 ok(!ulProgress, "ulProgress = %d\n", ulProgress);
911 ok(!ulProgressMax, "ulProgressMax = %d\n", ulProgressMax);
912 }else {
913 ok(ulProgress, "ulProgress == 0\n");
916 if(empty_file) {
917 ok(grfBSCF == (BSCF_FIRSTDATANOTIFICATION|BSCF_LASTDATANOTIFICATION),
918 "grcfBSCF = %08x\n", grfBSCF);
919 first_data_notif = FALSE;
920 }else if(first_data_notif) {
921 ok(grfBSCF == BSCF_FIRSTDATANOTIFICATION
922 || grfBSCF == (BSCF_LASTDATANOTIFICATION|BSCF_DATAFULLYAVAILABLE),
923 "grcfBSCF = %08x\n", grfBSCF);
924 first_data_notif = FALSE;
925 } else {
926 ok(grfBSCF == BSCF_INTERMEDIATEDATANOTIFICATION
927 || grfBSCF == (BSCF_LASTDATANOTIFICATION|BSCF_INTERMEDIATEDATANOTIFICATION)
928 || broken(grfBSCF == (BSCF_FIRSTDATANOTIFICATION|BSCF_LASTDATANOTIFICATION)),
929 "grcfBSCF = %08x\n", grfBSCF);
932 if(!(bindf & BINDF_FROMURLMON) &&
933 !(grfBSCF & BSCF_LASTDATANOTIFICATION)) {
934 if(state == STATE_CONNECTING) {
935 state = STATE_DOWNLOADING;
936 if(http_is_first) {
937 CHECK_CALLED(ReportProgress_FINDINGRESOURCE);
938 CHECK_CALLED(ReportProgress_CONNECTING);
940 CHECK_CALLED(ReportProgress_SENDINGREQUEST);
941 CHECK_CALLED(OnResponse);
942 CHECK_CALLED(ReportProgress_RAWMIMETYPE);
944 SetEvent(event_complete);
946 }else if(!read_report_data) {
947 BYTE buf[1000];
948 ULONG read;
949 HRESULT hres;
951 CHECK_EXPECT(ReportData);
953 if(tested_protocol != BIND_TEST) {
954 do {
955 if(mimefilter_test)
956 SET_EXPECT(MimeFilter_Read);
957 else if(rec_depth > 1)
958 SET_EXPECT(Read2);
959 else
960 SET_EXPECT(Read);
961 hres = IInternetProtocol_Read(binding_protocol, expect_pv=buf, sizeof(buf), &read);
962 if(mimefilter_test)
963 CHECK_CALLED(MimeFilter_Read);
964 else if(rec_depth > 1)
965 CHECK_CALLED(Read2);
966 else
967 CHECK_CALLED(Read);
968 }while(hres == S_OK);
972 rec_depth--;
973 return S_OK;
976 static HRESULT WINAPI ProtocolSink_ReportResult(IInternetProtocolSink *iface, HRESULT hrResult,
977 DWORD dwError, LPCWSTR szResult)
979 CHECK_EXPECT(ReportResult);
981 if(tested_protocol == FTP_TEST)
982 ok(hrResult == E_PENDING || hrResult == S_OK, "hrResult = %08x, expected E_PENDING or S_OK\n", hrResult);
983 else
984 ok(hrResult == expect_hrResult, "hrResult = %08x, expected: %08x\n",
985 hrResult, expect_hrResult);
986 if(SUCCEEDED(hrResult) || tested_protocol == FTP_TEST || test_abort)
987 ok(dwError == ERROR_SUCCESS, "dwError = %d, expected ERROR_SUCCESS\n", dwError);
988 else
989 ok(dwError != ERROR_SUCCESS ||
990 broken(tested_protocol == MK_TEST), /* WinME and NT4 */
991 "dwError == ERROR_SUCCESS\n");
992 ok(!szResult, "szResult != NULL\n");
994 if(direct_read)
995 SET_EXPECT(ReportData); /* checked after main loop */
997 return S_OK;
1000 static IInternetProtocolSinkVtbl protocol_sink_vtbl = {
1001 ProtocolSink_QueryInterface,
1002 ProtocolSink_AddRef,
1003 ProtocolSink_Release,
1004 ProtocolSink_Switch,
1005 ProtocolSink_ReportProgress,
1006 ProtocolSink_ReportData,
1007 ProtocolSink_ReportResult
1010 static IInternetProtocolSink protocol_sink = { &protocol_sink_vtbl };
1012 static HRESULT WINAPI MimeProtocolSink_QueryInterface(IInternetProtocolSink *iface, REFIID riid, void **ppv)
1014 ok(0, "unexpected call\n");
1015 return E_NOTIMPL;
1018 static ULONG WINAPI MimeProtocolSink_AddRef(IInternetProtocolSink *iface)
1020 return 2;
1023 static ULONG WINAPI MimeProtocolSink_Release(IInternetProtocolSink *iface)
1025 return 1;
1028 static HRESULT WINAPI MimeProtocolSink_Switch(IInternetProtocolSink *iface, PROTOCOLDATA *pProtocolData)
1030 HRESULT hres;
1032 CHECK_EXPECT(MimeFilter_Switch);
1034 SET_EXPECT(Switch);
1035 hres = IInternetProtocolSink_Switch(filtered_sink, pProtocolData);
1036 ok(hres == S_OK, "Switch failed: %08x\n", hres);
1037 CHECK_CALLED(Switch);
1039 return S_OK;
1042 static HRESULT WINAPI MimeProtocolSink_ReportProgress(IInternetProtocolSink *iface, ULONG ulStatusCode,
1043 LPCWSTR szStatusText)
1045 switch(ulStatusCode) {
1046 case BINDSTATUS_LOADINGMIMEHANDLER:
1048 * IE9 for some reason (bug?) calls this on mime handler's protocol sink instead of the
1049 * main protocol sink. We check ReportProgress_LOADINGMIMEHANDLER both here and in
1050 * ProtocolSink_ReportProgress to workaround it.
1052 CHECK_EXPECT(ReportProgress_LOADINGMIMEHANDLER);
1053 ok(!szStatusText, "szStatusText = %s\n", wine_dbgstr_w(szStatusText));
1054 break;
1055 default:
1056 ok(0, "Unexpected status code %d\n", ulStatusCode);
1059 return S_OK;
1062 static HRESULT WINAPI MimeProtocolSink_ReportData(IInternetProtocolSink *iface, DWORD grfBSCF,
1063 ULONG ulProgress, ULONG ulProgressMax)
1065 DWORD read = 0;
1066 BYTE buf[8192];
1067 HRESULT hres;
1069 CHECK_EXPECT(MimeFilter_ReportData);
1071 if(!filter_state) {
1072 SET_EXPECT(Read);
1073 hres = IInternetProtocol_Read(filtered_protocol, buf, sizeof(buf), &read);
1074 if(tested_protocol == HTTP_TEST)
1075 ok(hres == S_OK || hres == E_PENDING || hres == S_FALSE, "Read failed: %08x\n", hres);
1076 else
1077 ok(hres == S_OK, "Read failed: %08x\n", hres);
1078 CHECK_CALLED(Read);
1080 SET_EXPECT(ReportProgress_MIMETYPEAVAILABLE);
1081 hres = IInternetProtocolSink_ReportProgress(filtered_sink, BINDSTATUS_VERIFIEDMIMETYPEAVAILABLE, text_htmlW);
1082 ok(hres == S_OK, "ReportProgress failed: %08x\n", hres);
1083 CHECK_CALLED(ReportProgress_MIMETYPEAVAILABLE);
1085 /* FIXME: test BINDSTATUS_CACHEFILENAMEAVAILABLE */
1088 if(!read_report_data)
1089 SET_EXPECT(ReportData);
1090 hres = IInternetProtocolSink_ReportData(filtered_sink, grfBSCF, ulProgress, ulProgressMax);
1091 ok(hres == S_OK, "ReportData failed: %08x\n", hres);
1092 if(!read_report_data)
1093 CHECK_CALLED(ReportData);
1095 if(!filter_state)
1096 filter_state = 1;
1098 return S_OK;
1101 static HRESULT WINAPI MimeProtocolSink_ReportResult(IInternetProtocolSink *iface, HRESULT hrResult,
1102 DWORD dwError, LPCWSTR szResult)
1104 HRESULT hres;
1106 CHECK_EXPECT(MimeFilter_ReportResult);
1108 ok(hrResult == S_OK, "hrResult = %08x\n", hrResult);
1109 ok(dwError == ERROR_SUCCESS, "dwError = %u\n", dwError);
1110 ok(!szResult, "szResult = %s\n", wine_dbgstr_w(szResult));
1112 SET_EXPECT(ReportResult);
1113 hres = IInternetProtocolSink_ReportResult(filtered_sink, hrResult, dwError, szResult);
1114 ok(SUCCEEDED(hres), "ReportResult failed: %08x\n", hres);
1115 CHECK_CALLED(ReportResult);
1117 return S_OK;
1120 static IInternetProtocolSinkVtbl mime_protocol_sink_vtbl = {
1121 MimeProtocolSink_QueryInterface,
1122 MimeProtocolSink_AddRef,
1123 MimeProtocolSink_Release,
1124 MimeProtocolSink_Switch,
1125 MimeProtocolSink_ReportProgress,
1126 MimeProtocolSink_ReportData,
1127 MimeProtocolSink_ReportResult
1130 static IInternetProtocolSink mime_protocol_sink = { &mime_protocol_sink_vtbl };
1132 static HRESULT QueryInterface(REFIID riid, void **ppv)
1134 static const IID IID_undocumented = {0x58DFC7D0,0x5381,0x43E5,{0x9D,0x72,0x4C,0xDD,0xE4,0xCB,0x0F,0x1A}};
1136 *ppv = NULL;
1138 if(IsEqualGUID(&IID_IUnknown, riid) || IsEqualGUID(&IID_IInternetProtocolSink, riid))
1139 *ppv = &protocol_sink;
1140 if(IsEqualGUID(&IID_IServiceProvider, riid))
1141 *ppv = &service_provider;
1142 if(IsEqualGUID(&IID_IUriContainer, riid))
1143 return E_NOINTERFACE; /* TODO */
1145 /* NOTE: IE8 queries for undocumented {58DFC7D0-5381-43E5-9D72-4CDDE4CB0F1A} interface. */
1146 if(IsEqualGUID(&IID_undocumented, riid))
1147 return E_NOINTERFACE;
1149 if(*ppv)
1150 return S_OK;
1152 ok(0, "unexpected call %s\n", debugstr_guid(riid));
1153 return E_NOINTERFACE;
1156 static HRESULT WINAPI BindInfo_QueryInterface(IInternetBindInfo *iface, REFIID riid, void **ppv)
1158 if(IsEqualGUID(&IID_IUnknown, riid) || IsEqualGUID(&IID_IInternetBindInfo, riid)) {
1159 *ppv = iface;
1160 return S_OK;
1162 return E_NOINTERFACE;
1165 static ULONG WINAPI BindInfo_AddRef(IInternetBindInfo *iface)
1167 return 2;
1170 static ULONG WINAPI BindInfo_Release(IInternetBindInfo *iface)
1172 return 1;
1175 static HRESULT WINAPI BindInfo_GetBindInfo(IInternetBindInfo *iface, DWORD *grfBINDF, BINDINFO *pbindinfo)
1177 DWORD cbSize;
1179 CHECK_EXPECT(GetBindInfo);
1181 ok(grfBINDF != NULL, "grfBINDF == NULL\n");
1182 ok(pbindinfo != NULL, "pbindinfo == NULL\n");
1183 ok(pbindinfo->cbSize == sizeof(BINDINFO), "wrong size of pbindinfo: %d\n", pbindinfo->cbSize);
1185 *grfBINDF = bindf;
1186 if(binding_test)
1187 *grfBINDF |= BINDF_FROMURLMON;
1188 cbSize = pbindinfo->cbSize;
1189 memset(pbindinfo, 0, cbSize);
1190 pbindinfo->cbSize = cbSize;
1192 if(http_post_test)
1194 pbindinfo->cbstgmedData = sizeof(post_data)-1;
1195 pbindinfo->dwBindVerb = BINDVERB_POST;
1196 pbindinfo->stgmedData.tymed = http_post_test;
1198 if(http_post_test == TYMED_HGLOBAL) {
1199 HGLOBAL data;
1201 /* Must be GMEM_FIXED, GMEM_MOVABLE does not work properly */
1202 data = GlobalAlloc(GPTR, sizeof(post_data));
1203 memcpy(data, post_data, sizeof(post_data));
1204 U(pbindinfo->stgmedData).hGlobal = data;
1205 }else {
1206 IStream *post_stream;
1207 HGLOBAL data;
1208 HRESULT hres;
1210 if(0) {
1211 /* Must be GMEM_FIXED, GMEM_MOVABLE does not work properly */
1212 data = GlobalAlloc(GPTR, sizeof(post_data));
1213 memcpy(data, post_data, sizeof(post_data));
1214 U(pbindinfo->stgmedData).hGlobal = data;
1216 hres = CreateStreamOnHGlobal(data, FALSE, &post_stream);
1217 ok(hres == S_OK, "CreateStreamOnHGlobal failed: %08x\n", hres);
1219 U(pbindinfo->stgmedData).pstm =post_stream;/* &Stream; */
1221 U(pbindinfo->stgmedData).pstm = &Stream;
1225 return S_OK;
1228 static HRESULT WINAPI BindInfo_GetBindString(IInternetBindInfo *iface, ULONG ulStringType,
1229 LPOLESTR *ppwzStr, ULONG cEl, ULONG *pcElFetched)
1231 ok(ppwzStr != NULL, "ppwzStr == NULL\n");
1232 ok(pcElFetched != NULL, "pcElFetched == NULL\n");
1234 switch(ulStringType) {
1235 case BINDSTRING_ACCEPT_MIMES:
1236 CHECK_EXPECT(GetBindString_ACCEPT_MIMES);
1237 ok(cEl == 256, "cEl=%d, expected 256\n", cEl);
1238 if(pcElFetched) {
1239 ok(*pcElFetched == 256, "*pcElFetched=%d, expected 256\n", *pcElFetched);
1240 *pcElFetched = 1;
1242 if(ppwzStr) {
1243 *ppwzStr = CoTaskMemAlloc(sizeof(acc_mimeW));
1244 memcpy(*ppwzStr, acc_mimeW, sizeof(acc_mimeW));
1246 return S_OK;
1247 case BINDSTRING_USER_AGENT:
1248 CHECK_EXPECT(GetBindString_USER_AGENT);
1249 ok(cEl == 1, "cEl=%d, expected 1\n", cEl);
1250 if(pcElFetched) {
1251 ok(*pcElFetched == 0, "*pcElFetch=%d, expectd 0\n", *pcElFetched);
1252 *pcElFetched = 1;
1254 if(ppwzStr) {
1255 *ppwzStr = CoTaskMemAlloc(sizeof(user_agentW));
1256 memcpy(*ppwzStr, user_agentW, sizeof(user_agentW));
1258 return S_OK;
1259 case BINDSTRING_POST_COOKIE:
1260 CHECK_EXPECT(GetBindString_POST_COOKIE);
1261 ok(cEl == 1, "cEl=%d, expected 1\n", cEl);
1262 if(pcElFetched)
1263 ok(*pcElFetched == 0, "*pcElFetch=%d, expectd 0\n", *pcElFetched);
1264 return S_OK;
1265 case BINDSTRING_URL: {
1266 DWORD size;
1268 CHECK_EXPECT(GetBindString_URL);
1269 ok(cEl == 1, "cEl=%d, expected 1\n", cEl);
1270 ok(*pcElFetched == 0, "*pcElFetch=%d, expectd 0\n", *pcElFetched);
1271 *pcElFetched = 1;
1273 size = (lstrlenW(binding_urls[tested_protocol])+1)*sizeof(WCHAR);
1274 *ppwzStr = CoTaskMemAlloc(size);
1275 memcpy(*ppwzStr, binding_urls[tested_protocol], size);
1276 return S_OK;
1278 default:
1279 ok(0, "unexpected call\n");
1282 return E_NOTIMPL;
1285 static IInternetBindInfoVtbl bind_info_vtbl = {
1286 BindInfo_QueryInterface,
1287 BindInfo_AddRef,
1288 BindInfo_Release,
1289 BindInfo_GetBindInfo,
1290 BindInfo_GetBindString
1293 static IInternetBindInfo bind_info = { &bind_info_vtbl };
1295 static HRESULT WINAPI InternetPriority_QueryInterface(IInternetPriority *iface,
1296 REFIID riid, void **ppv)
1298 ok(0, "unexpected call\n");
1299 return E_NOINTERFACE;
1302 static ULONG WINAPI InternetPriority_AddRef(IInternetPriority *iface)
1304 return 2;
1307 static ULONG WINAPI InternetPriority_Release(IInternetPriority *iface)
1309 return 1;
1312 static HRESULT WINAPI InternetPriority_SetPriority(IInternetPriority *iface, LONG nPriority)
1314 CHECK_EXPECT(SetPriority);
1315 ok(nPriority == ex_priority, "nPriority=%d\n", nPriority);
1316 return S_OK;
1319 static HRESULT WINAPI InternetPriority_GetPriority(IInternetPriority *iface, LONG *pnPriority)
1321 ok(0, "unexpected call\n");
1322 return E_NOTIMPL;
1326 static const IInternetPriorityVtbl InternetPriorityVtbl = {
1327 InternetPriority_QueryInterface,
1328 InternetPriority_AddRef,
1329 InternetPriority_Release,
1330 InternetPriority_SetPriority,
1331 InternetPriority_GetPriority
1334 static IInternetPriority InternetPriority = { &InternetPriorityVtbl };
1336 static ULONG WINAPI Protocol_AddRef(IInternetProtocolEx *iface)
1338 return 2;
1341 static ULONG WINAPI Protocol_Release(IInternetProtocolEx *iface)
1343 return 1;
1346 static HRESULT WINAPI Protocol_Abort(IInternetProtocolEx *iface, HRESULT hrReason,
1347 DWORD dwOptions)
1349 HRESULT hres;
1351 CHECK_EXPECT(Abort);
1353 SET_EXPECT(ReportResult);
1354 hres = IInternetProtocolSink_ReportResult(binding_sink, S_OK, ERROR_SUCCESS, NULL);
1355 ok(hres == S_OK, "ReportResult failed: %08x\n", hres);
1356 CHECK_CALLED(ReportResult);
1358 return S_OK;
1361 static HRESULT WINAPI Protocol_Suspend(IInternetProtocolEx *iface)
1363 ok(0, "unexpected call\n");
1364 return E_NOTIMPL;
1367 static HRESULT WINAPI Protocol_Resume(IInternetProtocolEx *iface)
1369 ok(0, "unexpected call\n");
1370 return E_NOTIMPL;
1373 static HRESULT WINAPI Protocol_Seek(IInternetProtocolEx *iface,
1374 LARGE_INTEGER dlibMove, DWORD dwOrigin, ULARGE_INTEGER *plibNewPosition)
1376 ok(0, "unexpected call\n");
1377 return E_NOTIMPL;
1380 static HRESULT WINAPI ProtocolEmul_QueryInterface(IInternetProtocolEx *iface, REFIID riid, void **ppv)
1382 if(IsEqualGUID(&IID_IUnknown, riid) || IsEqualGUID(&IID_IInternetProtocol, riid)) {
1383 *ppv = iface;
1384 return S_OK;
1387 if(IsEqualGUID(&IID_IInternetProtocolEx, riid)) {
1388 if(impl_protex) {
1389 *ppv = iface;
1390 return S_OK;
1392 *ppv = NULL;
1393 return E_NOINTERFACE;
1396 if(IsEqualGUID(&IID_IInternetPriority, riid)) {
1397 *ppv = &InternetPriority;
1398 return S_OK;
1401 if(IsEqualGUID(&IID_IWinInetInfo, riid)) {
1402 CHECK_EXPECT(QueryInterface_IWinInetInfo);
1403 *ppv = NULL;
1404 return E_NOINTERFACE;
1407 if(IsEqualGUID(&IID_IWinInetHttpInfo, riid)) {
1408 CHECK_EXPECT(QueryInterface_IWinInetHttpInfo);
1409 *ppv = NULL;
1410 return E_NOINTERFACE;
1413 ok(0, "unexpected riid %s\n", debugstr_guid(riid));
1414 *ppv = NULL;
1415 return E_NOINTERFACE;
1418 static DWORD WINAPI thread_proc(PVOID arg)
1420 HRESULT hres;
1422 memset(&protocoldata, -1, sizeof(protocoldata));
1424 prot_state = 0;
1426 SET_EXPECT(ReportProgress_FINDINGRESOURCE);
1427 hres = IInternetProtocolSink_ReportProgress(binding_sink,
1428 BINDSTATUS_FINDINGRESOURCE, hostW);
1429 CHECK_CALLED(ReportProgress_FINDINGRESOURCE);
1430 ok(hres == S_OK, "ReportProgress failed: %08x\n", hres);
1432 SET_EXPECT(ReportProgress_CONNECTING);
1433 hres = IInternetProtocolSink_ReportProgress(binding_sink,
1434 BINDSTATUS_CONNECTING, winehq_ipW);
1435 CHECK_CALLED(ReportProgress_CONNECTING);
1436 ok(hres == S_OK, "ReportProgress failed: %08x\n", hres);
1438 SET_EXPECT(ReportProgress_SENDINGREQUEST);
1439 hres = IInternetProtocolSink_ReportProgress(binding_sink,
1440 BINDSTATUS_SENDINGREQUEST, NULL);
1441 CHECK_CALLED(ReportProgress_SENDINGREQUEST);
1442 ok(hres == S_OK, "ReportProgress failed: %08x\n", hres);
1444 prot_state = 1;
1445 SET_EXPECT(Switch);
1446 hres = IInternetProtocolSink_Switch(binding_sink, &protocoldata);
1447 CHECK_CALLED(Switch);
1448 ok(hres == S_OK, "Switch failed: %08x\n", hres);
1450 if(!short_read) {
1451 prot_state = 2;
1452 if(mimefilter_test)
1453 SET_EXPECT(MimeFilter_Switch);
1454 else
1455 SET_EXPECT(Switch);
1456 hres = IInternetProtocolSink_Switch(binding_sink, &protocoldata);
1457 ok(hres == S_OK, "Switch failed: %08x\n", hres);
1458 if(mimefilter_test)
1459 CHECK_CALLED(MimeFilter_Switch);
1460 else
1461 CHECK_CALLED(Switch);
1463 if(test_abort) {
1464 SetEvent(event_complete);
1465 return 0;
1468 prot_state = 2;
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);
1480 prot_state = 3;
1481 if(mimefilter_test)
1482 SET_EXPECT(MimeFilter_Switch);
1483 else
1484 SET_EXPECT(Switch);
1485 hres = IInternetProtocolSink_Switch(binding_sink, &protocoldata);
1486 ok(hres == S_OK, "Switch failed: %08x\n", hres);
1487 if(mimefilter_test)
1488 CHECK_CALLED(MimeFilter_Switch);
1489 else
1490 CHECK_CALLED(Switch);
1493 SetEvent(event_complete);
1495 return 0;
1498 static void protocol_start(IInternetProtocolSink *pOIProtSink, IInternetBindInfo *pOIBindInfo, DWORD pi)
1500 BINDINFO bindinfo, exp_bindinfo;
1501 DWORD cbindf = 0;
1502 HRESULT hres;
1504 ok(pOIProtSink != NULL, "pOIProtSink == NULL\n");
1505 ok(pOIBindInfo != NULL, "pOIBindInfo == NULL\n");
1506 ok(pOIProtSink != &protocol_sink, "unexpected pOIProtSink\n");
1507 ok(pOIBindInfo != &bind_info, "unexpected pOIBindInfo\n");
1508 ok(!pi, "pi = %x\n", pi);
1510 if(binding_test)
1511 ok(pOIProtSink == binding_sink, "pOIProtSink != binding_sink\n");
1513 memset(&bindinfo, 0, sizeof(bindinfo));
1514 bindinfo.cbSize = sizeof(bindinfo);
1515 memcpy(&exp_bindinfo, &bindinfo, sizeof(bindinfo));
1516 SET_EXPECT(GetBindInfo);
1517 hres = IInternetBindInfo_GetBindInfo(pOIBindInfo, &cbindf, &bindinfo);
1518 ok(hres == S_OK, "GetBindInfo failed: %08x\n", hres);
1519 CHECK_CALLED(GetBindInfo);
1520 ok(cbindf == (bindf|BINDF_FROMURLMON), "bindf = %x, expected %x\n",
1521 cbindf, (bindf|BINDF_FROMURLMON));
1522 ok(!memcmp(&exp_bindinfo, &bindinfo, sizeof(bindinfo)), "unexpected bindinfo\n");
1523 pReleaseBindInfo(&bindinfo);
1525 SET_EXPECT(ReportProgress_SENDINGREQUEST);
1526 hres = IInternetProtocolSink_ReportProgress(pOIProtSink, BINDSTATUS_SENDINGREQUEST, emptyW);
1527 ok(hres == S_OK, "ReportProgress(BINDSTATUS_SENDINGREQUEST) failed: %08x\n", hres);
1528 CHECK_CALLED(ReportProgress_SENDINGREQUEST);
1530 if(tested_protocol == HTTP_TEST || tested_protocol == HTTPS_TEST) {
1531 IServiceProvider *service_provider;
1532 IHttpNegotiate *http_negotiate;
1533 IHttpNegotiate2 *http_negotiate2;
1534 LPWSTR ua = (LPWSTR)0xdeadbeef, accept_mimes[256];
1535 LPWSTR additional_headers = NULL;
1536 BYTE sec_id[100];
1537 DWORD fetched = 0, size = 100;
1538 DWORD tid;
1540 SET_EXPECT(GetBindString_USER_AGENT);
1541 hres = IInternetBindInfo_GetBindString(pOIBindInfo, BINDSTRING_USER_AGENT,
1542 &ua, 1, &fetched);
1543 CHECK_CALLED(GetBindString_USER_AGENT);
1544 ok(hres == S_OK, "GetBindString(BINDSTRING_USER_AGETNT) failed: %08x\n", hres);
1545 ok(fetched == 1, "fetched = %d, expected 254\n", fetched);
1546 ok(ua != NULL, "ua = %p\n", ua);
1547 ok(!lstrcmpW(ua, user_agentW), "unexpected user agent %s\n", wine_dbgstr_w(ua));
1548 CoTaskMemFree(ua);
1550 fetched = 256;
1551 SET_EXPECT(GetBindString_ACCEPT_MIMES);
1552 hres = IInternetBindInfo_GetBindString(pOIBindInfo, BINDSTRING_ACCEPT_MIMES,
1553 accept_mimes, 256, &fetched);
1554 CHECK_CALLED(GetBindString_ACCEPT_MIMES);
1556 ok(hres == S_OK,
1557 "GetBindString(BINDSTRING_ACCEPT_MIMES) failed: %08x\n", hres);
1558 ok(fetched == 1, "fetched = %d, expected 1\n", fetched);
1559 ok(!lstrcmpW(acc_mimeW, accept_mimes[0]), "unexpected mimes %s\n", wine_dbgstr_w(accept_mimes[0]));
1560 CoTaskMemFree(accept_mimes[0]);
1562 hres = IInternetBindInfo_QueryInterface(pOIBindInfo, &IID_IServiceProvider,
1563 (void**)&service_provider);
1564 ok(hres == S_OK, "QueryInterface failed: %08x\n", hres);
1566 SET_EXPECT(QueryService_HttpNegotiate);
1567 hres = IServiceProvider_QueryService(service_provider, &IID_IHttpNegotiate,
1568 &IID_IHttpNegotiate, (void**)&http_negotiate);
1569 CHECK_CALLED(QueryService_HttpNegotiate);
1570 ok(hres == S_OK, "QueryService failed: %08x\n", hres);
1572 SET_EXPECT(BeginningTransaction);
1573 hres = IHttpNegotiate_BeginningTransaction(http_negotiate, binding_urls[tested_protocol],
1574 NULL, 0, &additional_headers);
1575 CHECK_CALLED(BeginningTransaction);
1576 IHttpNegotiate_Release(http_negotiate);
1577 ok(hres == S_OK, "BeginningTransction failed: %08x\n", hres);
1578 ok(additional_headers == NULL, "additional_headers=%p\n", additional_headers);
1580 SET_EXPECT(QueryService_HttpNegotiate);
1581 hres = IServiceProvider_QueryService(service_provider, &IID_IHttpNegotiate2,
1582 &IID_IHttpNegotiate2, (void**)&http_negotiate2);
1583 CHECK_CALLED(QueryService_HttpNegotiate);
1584 ok(hres == S_OK, "QueryService failed: %08x\n", hres);
1586 size = 512;
1587 SET_EXPECT(GetRootSecurityId);
1588 hres = IHttpNegotiate2_GetRootSecurityId(http_negotiate2, sec_id, &size, 0);
1589 CHECK_CALLED(GetRootSecurityId);
1590 IHttpNegotiate2_Release(http_negotiate2);
1591 ok(hres == E_FAIL, "GetRootSecurityId failed: %08x, expected E_FAIL\n", hres);
1592 ok(size == 13, "size=%d\n", size);
1594 IServiceProvider_Release(service_provider);
1596 CreateThread(NULL, 0, thread_proc, NULL, 0, &tid);
1597 return;
1600 SET_EXPECT(ReportProgress_CACHEFILENAMEAVAILABLE);
1601 hres = IInternetProtocolSink_ReportProgress(pOIProtSink,
1602 BINDSTATUS_CACHEFILENAMEAVAILABLE, expect_wsz = emptyW);
1603 ok(hres == S_OK, "ReportProgress(BINDSTATUS_CACHEFILENAMEAVAILABLE) failed: %08x\n", hres);
1604 CHECK_CALLED(ReportProgress_CACHEFILENAMEAVAILABLE);
1606 if(mimefilter_test) {
1607 SET_EXPECT(MimeFilter_CreateInstance);
1608 SET_EXPECT(MimeFilter_Start);
1609 SET_EXPECT(ReportProgress_LOADINGMIMEHANDLER);
1611 SET_EXPECT(ReportProgress_MIMETYPEAVAILABLE);
1612 hres = IInternetProtocolSink_ReportProgress(pOIProtSink, BINDSTATUS_VERIFIEDMIMETYPEAVAILABLE,
1613 mimefilter_test ? gzipW : (expect_wsz = text_htmlW));
1614 ok(hres == S_OK,
1615 "ReportProgress(BINDSTATUS_VERIFIEDMIMETYPEAVAILABLE) failed: %08x\n", hres);
1616 if(mimefilter_test) {
1617 CHECK_CALLED(MimeFilter_CreateInstance);
1618 CHECK_CALLED(MimeFilter_Start);
1619 CHECK_CALLED(ReportProgress_LOADINGMIMEHANDLER);
1620 todo_wine CHECK_CALLED(ReportProgress_MIMETYPEAVAILABLE);
1621 }else {
1622 CHECK_CALLED(ReportProgress_MIMETYPEAVAILABLE);
1625 if(mimefilter_test)
1626 SET_EXPECT(MimeFilter_ReportData);
1627 else
1628 SET_EXPECT(ReportData);
1629 hres = IInternetProtocolSink_ReportData(pOIProtSink,
1630 BSCF_FIRSTDATANOTIFICATION | (tested_protocol == ITS_TEST ? BSCF_DATAFULLYAVAILABLE : BSCF_LASTDATANOTIFICATION),
1631 13, 13);
1632 ok(hres == S_OK, "ReportData failed: %08x\n", hres);
1633 if(mimefilter_test)
1634 CHECK_CALLED(MimeFilter_ReportData);
1635 else
1636 CHECK_CALLED(ReportData);
1638 if(tested_protocol == ITS_TEST) {
1639 SET_EXPECT(ReportData);
1640 hres = IInternetProtocolSink_ReportProgress(pOIProtSink, BINDSTATUS_BEGINDOWNLOADDATA, NULL);
1641 ok(hres == S_OK, "ReportProgress(BINDSTATUS_BEGINDOWNLOADDATA) failed: %08x\n", hres);
1642 CHECK_CALLED(ReportData);
1645 if(tested_protocol == BIND_TEST) {
1646 hres = IInternetProtocol_Terminate(binding_protocol, 0);
1647 ok(hres == E_FAIL, "Termiante failed: %08x\n", hres);
1650 if(mimefilter_test)
1651 SET_EXPECT(MimeFilter_ReportResult);
1652 else
1653 SET_EXPECT(ReportResult);
1654 hres = IInternetProtocolSink_ReportResult(pOIProtSink, S_OK, 0, NULL);
1655 ok(hres == S_OK, "ReportResult failed: %08x\n", hres);
1656 if(mimefilter_test)
1657 CHECK_CALLED(MimeFilter_ReportResult);
1658 else
1659 CHECK_CALLED(ReportResult);
1662 static HRESULT WINAPI ProtocolEmul_Start(IInternetProtocolEx *iface, LPCWSTR szUrl,
1663 IInternetProtocolSink *pOIProtSink, IInternetBindInfo *pOIBindInfo,
1664 DWORD grfPI, HANDLE_PTR dwReserved)
1666 CHECK_EXPECT(Start);
1668 ok(!dwReserved, "dwReserved = %lx\n", dwReserved);
1669 protocol_start(pOIProtSink, pOIBindInfo, grfPI);
1670 return S_OK;
1673 static HRESULT WINAPI ProtocolEmul_Continue(IInternetProtocolEx *iface,
1674 PROTOCOLDATA *pProtocolData)
1676 DWORD bscf = 0, pr;
1677 HRESULT hres;
1679 CHECK_EXPECT(Continue);
1681 ok(pProtocolData != NULL, "pProtocolData == NULL\n");
1682 if(!pProtocolData || tested_protocol == BIND_TEST)
1683 return S_OK;
1684 if(binding_test) {
1685 ok(pProtocolData != &protocoldata, "pProtocolData == &protocoldata\n");
1686 ok(pProtocolData->grfFlags == protocoldata.grfFlags, "grfFlags wrong %x/%x\n",
1687 pProtocolData->grfFlags, protocoldata.grfFlags );
1688 ok(pProtocolData->dwState == protocoldata.dwState, "dwState wrong %x/%x\n",
1689 pProtocolData->dwState, protocoldata.dwState );
1690 ok(pProtocolData->pData == protocoldata.pData, "pData wrong %p/%p\n",
1691 pProtocolData->pData, protocoldata.pData );
1692 ok(pProtocolData->cbData == protocoldata.cbData, "cbData wrong %x/%x\n",
1693 pProtocolData->cbData, protocoldata.cbData );
1696 switch(prot_state) {
1697 case 1: {
1698 IServiceProvider *service_provider;
1699 IHttpNegotiate *http_negotiate;
1700 static WCHAR header[] = {'?',0};
1702 hres = IInternetProtocolSink_QueryInterface(binding_sink, &IID_IServiceProvider,
1703 (void**)&service_provider);
1704 ok(hres == S_OK, "Could not get IServiceProvicder\n");
1706 SET_EXPECT(QueryService_HttpNegotiate);
1707 hres = IServiceProvider_QueryService(service_provider, &IID_IHttpNegotiate,
1708 &IID_IHttpNegotiate, (void**)&http_negotiate);
1709 IServiceProvider_Release(service_provider);
1710 CHECK_CALLED(QueryService_HttpNegotiate);
1711 ok(hres == S_OK, "Could not get IHttpNegotiate\n");
1713 SET_EXPECT(OnResponse);
1714 hres = IHttpNegotiate_OnResponse(http_negotiate, 200, header, NULL, NULL);
1715 IHttpNegotiate_Release(http_negotiate);
1716 CHECK_CALLED(OnResponse);
1717 IHttpNegotiate_Release(http_negotiate);
1718 ok(hres == S_OK, "OnResponse failed: %08x\n", hres);
1720 if(mimefilter_test) {
1721 SET_EXPECT(MimeFilter_CreateInstance);
1722 SET_EXPECT(MimeFilter_Start);
1723 SET_EXPECT(ReportProgress_LOADINGMIMEHANDLER);
1724 }else if(!(pi & PI_MIMEVERIFICATION)) {
1725 SET_EXPECT(ReportProgress_MIMETYPEAVAILABLE);
1727 hres = IInternetProtocolSink_ReportProgress(binding_sink,
1728 BINDSTATUS_MIMETYPEAVAILABLE, mimefilter_test ? gzipW : text_htmlW);
1729 if(mimefilter_test) {
1730 CHECK_CALLED(MimeFilter_CreateInstance);
1731 CHECK_CALLED(MimeFilter_Start);
1732 CHECK_CALLED(ReportProgress_LOADINGMIMEHANDLER);
1733 }else if(!(pi & PI_MIMEVERIFICATION)) {
1734 CHECK_CALLED(ReportProgress_MIMETYPEAVAILABLE);
1736 ok(hres == S_OK,
1737 "ReportProgress(BINDSTATUS_MIMETYPEAVAILABLE) failed: %08x\n", hres);
1739 bscf |= BSCF_FIRSTDATANOTIFICATION;
1740 break;
1742 case 2:
1743 case 3:
1744 bscf = BSCF_INTERMEDIATEDATANOTIFICATION;
1745 break;
1748 pr = prot_read;
1749 if(mimefilter_test) {
1750 SET_EXPECT(MimeFilter_ReportData);
1751 }else if(pi & PI_MIMEVERIFICATION) {
1752 if(pr < 200)
1753 SET_EXPECT(Read); /* checked in ReportData for short_read */
1754 if(pr == 200) {
1755 if(!mimefilter_test)
1756 SET_EXPECT(Read); /* checked in BINDSTATUS_MIMETYPEAVAILABLE or ReportData */
1757 SET_EXPECT(GetBindInfo);
1758 SET_EXPECT(ReportProgress_MIMETYPEAVAILABLE);
1760 if(pr >= 200)
1761 SET_EXPECT(ReportData);
1762 }else {
1763 SET_EXPECT(ReportData);
1766 hres = IInternetProtocolSink_ReportData(binding_sink, bscf, pr, 400);
1767 ok(hres == S_OK, "ReportData failed: %08x\n", hres);
1769 if(mimefilter_test) {
1770 SET_EXPECT(MimeFilter_ReportData);
1771 }else if(pi & PI_MIMEVERIFICATION) {
1772 if(!short_read && pr < 200)
1773 CHECK_CALLED(Read);
1774 if(pr == 200) {
1775 CLEAR_CALLED(GetBindInfo); /* IE9 */
1776 CHECK_CALLED(ReportProgress_MIMETYPEAVAILABLE);
1778 }else {
1779 CHECK_CALLED(ReportData);
1782 if(prot_state == 3)
1783 prot_state = 4;
1785 return S_OK;
1788 static HRESULT WINAPI ProtocolEmul_Terminate(IInternetProtocolEx *iface, DWORD dwOptions)
1790 CHECK_EXPECT(Terminate);
1791 ok(!dwOptions, "dwOptions=%d\n", dwOptions);
1792 return S_OK;
1795 static HRESULT WINAPI ProtocolEmul_Read(IInternetProtocolEx *iface, void *pv,
1796 ULONG cb, ULONG *pcbRead)
1798 if(read_report_data)
1799 CHECK_EXPECT2(Read2);
1801 if(mimefilter_test || short_read) {
1802 if(!read_report_data)
1803 CHECK_EXPECT2(Read);
1804 }else if((pi & PI_MIMEVERIFICATION)) {
1805 if(!read_report_data)
1806 CHECK_EXPECT2(Read);
1808 if(prot_read < 300) {
1809 ok(pv != expect_pv, "pv == expect_pv\n");
1810 if(prot_read < 300)
1811 ok(cb == 2048-prot_read, "cb=%d\n", cb);
1812 else
1813 ok(cb == 700, "cb=%d\n", cb);
1814 }else {
1815 ok(expect_pv <= pv && (BYTE*)pv < (BYTE*)expect_pv + cb, "pv != expect_pv\n");
1817 }else {
1818 if(!read_report_data)
1819 CHECK_EXPECT(Read);
1821 ok(pv == expect_pv, "pv != expect_pv\n");
1822 ok(cb == 1000, "cb=%d\n", cb);
1823 ok(!*pcbRead, "*pcbRead = %d\n", *pcbRead);
1825 ok(pcbRead != NULL, "pcbRead == NULL\n");
1827 if(prot_state == 3 || (short_read && prot_state != 4)) {
1828 HRESULT hres;
1830 prot_state = 4;
1831 if(short_read) {
1832 SET_EXPECT(Read2); /* checked in BINDSTATUS_MIMETYPEAVAILABLE */
1833 SET_EXPECT(GetBindInfo);
1834 SET_EXPECT(ReportProgress_MIMETYPEAVAILABLE);
1836 if(mimefilter_test)
1837 SET_EXPECT(MimeFilter_ReportData);
1838 else if(direct_read)
1839 SET_EXPECT(ReportData2);
1840 read_report_data++;
1841 hres = IInternetProtocolSink_ReportData(binding_sink,
1842 BSCF_LASTDATANOTIFICATION|BSCF_INTERMEDIATEDATANOTIFICATION, 0, 0);
1843 read_report_data--;
1844 ok(hres == S_OK, "ReportData failed: %08x\n", hres);
1845 if(short_read) {
1846 CLEAR_CALLED(GetBindInfo); /* IE9 */
1847 CHECK_CALLED(ReportProgress_MIMETYPEAVAILABLE);
1849 if(mimefilter_test)
1850 CHECK_CALLED(MimeFilter_ReportData);
1851 else if(direct_read)
1852 CHECK_CALLED(ReportData2);
1854 if(mimefilter_test)
1855 SET_EXPECT(MimeFilter_ReportResult);
1856 else
1857 SET_EXPECT(ReportResult);
1858 hres = IInternetProtocolSink_ReportResult(binding_sink, S_OK, ERROR_SUCCESS, NULL);
1859 ok(hres == S_OK, "ReportResult failed: %08x\n", hres);
1860 if(mimefilter_test)
1861 CHECK_CALLED(MimeFilter_ReportResult);
1862 else
1863 CHECK_CALLED(ReportResult);
1865 memset(pv, 'x', 100);
1866 prot_read += *pcbRead = 100;
1867 return S_OK;
1868 }if(prot_state == 4) {
1869 *pcbRead = 0;
1870 return S_FALSE;
1873 if((async_read_pending = !async_read_pending)) {
1874 *pcbRead = 0;
1875 return tested_protocol == HTTP_TEST || tested_protocol == HTTPS_TEST ? E_PENDING : S_FALSE;
1878 memset(pv, 'x', 100);
1879 prot_read += *pcbRead = 100;
1880 return S_OK;
1883 static HRESULT WINAPI ProtocolEmul_LockRequest(IInternetProtocolEx *iface, DWORD dwOptions)
1885 CHECK_EXPECT(LockRequest);
1886 ok(dwOptions == 0, "dwOptions=%x\n", dwOptions);
1887 return S_OK;
1890 static HRESULT WINAPI ProtocolEmul_UnlockRequest(IInternetProtocolEx *iface)
1892 CHECK_EXPECT(UnlockRequest);
1893 return S_OK;
1896 static HRESULT WINAPI ProtocolEmul_StartEx(IInternetProtocolEx *iface, IUri *pUri,
1897 IInternetProtocolSink *pOIProtSink, IInternetBindInfo *pOIBindInfo,
1898 DWORD grfPI, HANDLE *dwReserved)
1900 CHECK_EXPECT(StartEx);
1901 ok(!dwReserved, "dwReserved = %p\n", dwReserved);
1902 protocol_start(pOIProtSink, pOIBindInfo, grfPI);
1903 return S_OK;
1906 static const IInternetProtocolExVtbl ProtocolVtbl = {
1907 ProtocolEmul_QueryInterface,
1908 Protocol_AddRef,
1909 Protocol_Release,
1910 ProtocolEmul_Start,
1911 ProtocolEmul_Continue,
1912 Protocol_Abort,
1913 ProtocolEmul_Terminate,
1914 Protocol_Suspend,
1915 Protocol_Resume,
1916 ProtocolEmul_Read,
1917 Protocol_Seek,
1918 ProtocolEmul_LockRequest,
1919 ProtocolEmul_UnlockRequest,
1920 ProtocolEmul_StartEx
1923 static IInternetProtocolEx Protocol = { &ProtocolVtbl };
1925 static HRESULT WINAPI MimeProtocol_QueryInterface(IInternetProtocolEx *iface, REFIID riid, void **ppv)
1927 if(IsEqualGUID(&IID_IUnknown, riid) || IsEqualGUID(&IID_IInternetProtocol, riid)) {
1928 *ppv = iface;
1929 return S_OK;
1932 if(IsEqualGUID(&IID_IInternetProtocolSink, riid)) {
1933 *ppv = &mime_protocol_sink;
1934 return S_OK;
1937 ok(0, "unexpected riid %s\n", debugstr_guid(riid));
1938 *ppv = NULL;
1939 return E_NOINTERFACE;
1942 static HRESULT WINAPI MimeProtocol_Start(IInternetProtocolEx *iface, LPCWSTR szUrl,
1943 IInternetProtocolSink *pOIProtSink, IInternetBindInfo *pOIBindInfo,
1944 DWORD grfPI, HANDLE_PTR dwReserved)
1946 PROTOCOLFILTERDATA *data;
1947 LPOLESTR url_str = NULL;
1948 DWORD fetched = 0;
1949 BINDINFO bindinfo;
1950 DWORD cbindf = 0;
1951 HRESULT hres;
1953 CHECK_EXPECT(MimeFilter_Start);
1955 ok(!lstrcmpW(szUrl, gzipW), "wrong url %s\n", wine_dbgstr_w(szUrl));
1956 ok(grfPI == (PI_FILTER_MODE|PI_FORCE_ASYNC), "grfPI=%x, expected PI_FILTER_MODE|PI_FORCE_ASYNC\n", grfPI);
1957 ok(dwReserved, "dwReserved == 0\n");
1958 ok(pOIProtSink != NULL, "pOIProtSink == NULL\n");
1959 ok(pOIBindInfo != NULL, "pOIBindInfo == NULL\n");
1961 if(binding_test) {
1962 ok(pOIProtSink != binding_sink, "pOIProtSink == protocol_sink\n");
1963 ok(pOIBindInfo == prot_bind_info, "pOIBindInfo != bind_info\n");
1964 }else {
1965 ok(pOIProtSink == &protocol_sink, "pOIProtSink != protocol_sink\n");
1966 ok(pOIBindInfo == &bind_info, "pOIBindInfo != bind_info\n");
1969 data = (void*)dwReserved;
1970 ok(data->cbSize == sizeof(*data), "data->cbSize = %d\n", data->cbSize);
1971 ok(!data->pProtocolSink, "data->pProtocolSink != NULL\n");
1972 ok(data->pProtocol != NULL, "data->pProtocol == NULL\n");
1973 ok(!data->pUnk, "data->pUnk != NULL\n");
1974 ok(!data->dwFilterFlags, "data->dwProtocolFlags = %x\n", data->dwFilterFlags);
1975 if(binding_test) {
1976 IInternetProtocolSink *prot_sink;
1978 IInternetProtocol_QueryInterface(data->pProtocol, &IID_IInternetProtocolSink, (void**)&prot_sink);
1979 ok(prot_sink == pOIProtSink, "QI(data->pProtocol, IID_IInternetProtocolSink) != pOIProtSink\n");
1980 IInternetProtocolSink_Release(prot_sink);
1982 ok(data->pProtocol != binding_protocol, "data->pProtocol == binding_protocol\n");
1984 filtered_protocol = data->pProtocol;
1985 IInternetProtocol_AddRef(filtered_protocol);
1986 }else {
1987 IInternetProtocol *prot;
1989 IInternetProtocol_QueryInterface(data->pProtocol, &IID_IInternetProtocol, (void**)&prot);
1990 ok(prot == async_protocol, "QI(data->pProtocol, IID_IInternetProtocol) != async_protocol\n");
1991 IInternetProtocol_Release(prot);
1993 ok(data->pProtocol != async_protocol, "data->pProtocol == async_protocol\n");
1996 filtered_sink = pOIProtSink;
1998 SET_EXPECT(ReportProgress_DECODING);
1999 hres = IInternetProtocolSink_ReportProgress(pOIProtSink, BINDSTATUS_DECODING, gzipW);
2000 ok(hres == S_OK, "ReportProgress(BINDSTATUS_DECODING) failed: %08x\n", hres);
2001 CHECK_CALLED(ReportProgress_DECODING);
2003 SET_EXPECT(GetBindInfo);
2004 memset(&bindinfo, 0, sizeof(bindinfo));
2005 bindinfo.cbSize = sizeof(bindinfo);
2006 hres = IInternetBindInfo_GetBindInfo(pOIBindInfo, &cbindf, &bindinfo);
2007 ok(hres == S_OK, "GetBindInfo failed: %08x\n", hres);
2008 ok(cbindf == (bindf|BINDF_FROMURLMON), "cbindf = %x, expected %x\n", cbindf, bindf);
2009 CHECK_CALLED(GetBindInfo);
2011 SET_EXPECT(GetBindString_URL);
2012 hres = IInternetBindInfo_GetBindString(pOIBindInfo, BINDSTRING_URL, &url_str, 1, &fetched);
2013 ok(hres == S_OK, "GetBindString(BINDSTRING_URL) failed: %08x\n", hres);
2014 ok(fetched == 1, "fetched = %d\n", fetched);
2015 ok(!lstrcmpW(url_str, binding_urls[tested_protocol]), "wrong url_str %s\n", wine_dbgstr_w(url_str));
2016 CoTaskMemFree(url_str);
2017 CHECK_CALLED(GetBindString_URL);
2019 return S_OK;
2022 static HRESULT WINAPI Protocol_Continue(IInternetProtocolEx *iface,
2023 PROTOCOLDATA *pProtocolData)
2025 CHECK_EXPECT(MimeFilter_Continue);
2026 return E_NOTIMPL;
2029 static HRESULT WINAPI MimeProtocol_Terminate(IInternetProtocolEx *iface, DWORD dwOptions)
2031 HRESULT hres;
2033 CHECK_EXPECT(MimeFilter_Terminate);
2035 ok(!dwOptions, "dwOptions = %x\n", dwOptions);
2037 SET_EXPECT(Terminate);
2038 hres = IInternetProtocol_Terminate(filtered_protocol, dwOptions);
2039 ok(hres == S_OK, "Terminate failed: %08x\n", hres);
2040 CHECK_CALLED(Terminate);
2042 return S_OK;
2045 static HRESULT WINAPI MimeProtocol_Read(IInternetProtocolEx *iface, void *pv,
2046 ULONG cb, ULONG *pcbRead)
2048 BYTE buf[2096];
2049 DWORD read = 0;
2050 HRESULT hres;
2052 CHECK_EXPECT(MimeFilter_Read);
2054 ok(pv != NULL, "pv == NULL\n");
2055 ok(cb != 0, "cb == 0\n");
2056 ok(pcbRead != NULL, "pcbRead == NULL\n");
2058 if(read_report_data)
2059 SET_EXPECT(Read2);
2060 else
2061 SET_EXPECT(Read);
2062 hres = IInternetProtocol_Read(filtered_protocol, buf, sizeof(buf), &read);
2063 ok(hres == S_OK || hres == S_FALSE || hres == E_PENDING, "Read failed: %08x\n", hres);
2064 if(read_report_data)
2065 CHECK_CALLED(Read2);
2066 else
2067 CHECK_CALLED(Read);
2069 if(pcbRead) {
2070 ok(*pcbRead == 0, "*pcbRead=%d, expected 0\n", *pcbRead);
2071 *pcbRead = read;
2074 memset(pv, 'x', read);
2075 return hres;
2078 static HRESULT WINAPI MimeProtocol_LockRequest(IInternetProtocolEx *iface, DWORD dwOptions)
2080 HRESULT hres;
2082 CHECK_EXPECT(MimeFilter_LockRequest);
2084 ok(!dwOptions, "dwOptions = %x\n", dwOptions);
2086 SET_EXPECT(LockRequest);
2087 hres = IInternetProtocol_LockRequest(filtered_protocol, dwOptions);
2088 ok(hres == S_OK, "LockRequest failed: %08x\n", hres);
2089 CHECK_CALLED(LockRequest);
2091 return S_OK;
2094 static HRESULT WINAPI MimeProtocol_UnlockRequest(IInternetProtocolEx *iface)
2096 HRESULT hres;
2098 CHECK_EXPECT(MimeFilter_UnlockRequest);
2100 SET_EXPECT(UnlockRequest);
2101 hres = IInternetProtocol_UnlockRequest(filtered_protocol);
2102 ok(hres == S_OK, "UnlockRequest failed: %08x\n", hres);
2103 CHECK_CALLED(UnlockRequest);
2105 return S_OK;
2108 static const IInternetProtocolExVtbl MimeProtocolVtbl = {
2109 MimeProtocol_QueryInterface,
2110 Protocol_AddRef,
2111 Protocol_Release,
2112 MimeProtocol_Start,
2113 Protocol_Continue,
2114 Protocol_Abort,
2115 MimeProtocol_Terminate,
2116 Protocol_Suspend,
2117 Protocol_Resume,
2118 MimeProtocol_Read,
2119 Protocol_Seek,
2120 MimeProtocol_LockRequest,
2121 MimeProtocol_UnlockRequest
2124 static IInternetProtocolEx MimeProtocol = { &MimeProtocolVtbl };
2126 static HRESULT WINAPI ClassFactory_QueryInterface(IClassFactory *iface, REFIID riid, void **ppv)
2128 ok(0, "unexpected call\n");
2129 return E_NOINTERFACE;
2132 static ULONG WINAPI ClassFactory_AddRef(IClassFactory *iface)
2134 return 2;
2137 static ULONG WINAPI ClassFactory_Release(IClassFactory *iface)
2139 return 1;
2142 static HRESULT WINAPI ClassFactory_CreateInstance(IClassFactory *iface, IUnknown *pOuter,
2143 REFIID riid, void **ppv)
2145 CHECK_EXPECT(CreateInstance);
2147 ok(pOuter == (IUnknown*)prot_bind_info, "pOuter != protocol_unk\n");
2148 ok(IsEqualGUID(&IID_IUnknown, riid), "unexpected riid %s\n", debugstr_guid(riid));
2149 ok(ppv != NULL, "ppv == NULL\n");
2151 *ppv = &Protocol;
2152 return S_OK;
2155 static HRESULT WINAPI ClassFactory_LockServer(IClassFactory *iface, BOOL dolock)
2157 ok(0, "unexpected call\n");
2158 return S_OK;
2161 static const IClassFactoryVtbl ClassFactoryVtbl = {
2162 ClassFactory_QueryInterface,
2163 ClassFactory_AddRef,
2164 ClassFactory_Release,
2165 ClassFactory_CreateInstance,
2166 ClassFactory_LockServer
2169 static IClassFactory ClassFactory = { &ClassFactoryVtbl };
2171 static HRESULT WINAPI MimeFilter_CreateInstance(IClassFactory *iface, IUnknown *outer, REFIID riid, void **ppv)
2173 CHECK_EXPECT(MimeFilter_CreateInstance);
2175 ok(!outer, "outer = %p\n", outer);
2176 ok(IsEqualGUID(&IID_IInternetProtocol, riid), "unexpected riid %s\n", debugstr_guid(riid));
2178 *ppv = &MimeProtocol;
2179 return S_OK;
2182 static const IClassFactoryVtbl MimeFilterCFVtbl = {
2183 ClassFactory_QueryInterface,
2184 ClassFactory_AddRef,
2185 ClassFactory_Release,
2186 MimeFilter_CreateInstance,
2187 ClassFactory_LockServer
2190 static IClassFactory mimefilter_cf = { &MimeFilterCFVtbl };
2192 #define TEST_BINDING 0x0001
2193 #define TEST_FILTER 0x0002
2194 #define TEST_FIRST_HTTP 0x0004
2195 #define TEST_DIRECT_READ 0x0008
2196 #define TEST_POST 0x0010
2197 #define TEST_EMULATEPROT 0x0020
2198 #define TEST_SHORT_READ 0x0040
2199 #define TEST_REDIRECT 0x0080
2200 #define TEST_ABORT 0x0100
2201 #define TEST_ASYNCREQ 0x0200
2202 #define TEST_USEIURI 0x0400
2203 #define TEST_IMPLPROTEX 0x0800
2204 #define TEST_EMPTY 0x1000
2206 static void register_filter(BOOL do_register)
2208 IInternetSession *session;
2209 HRESULT hres;
2211 static const WCHAR gzipW[] = {'g','z','i','p',0};
2213 hres = pCoInternetGetSession(0, &session, 0);
2214 ok(hres == S_OK, "CoInternetGetSession failed: %08x\n", hres);
2216 if(do_register) {
2217 hres = IInternetSession_RegisterMimeFilter(session, &mimefilter_cf, &IID_IInternetProtocol, gzipW);
2218 ok(hres == S_OK, "RegisterMimeFilter failed: %08x\n", hres);
2219 }else {
2220 hres = IInternetSession_UnregisterMimeFilter(session, &mimefilter_cf, gzipW);
2221 ok(hres == S_OK, "RegisterMimeFilter failed: %08x\n", hres);
2224 IInternetSession_Release(session);
2227 static void init_test(int prot, DWORD flags)
2229 tested_protocol = prot;
2230 binding_test = (flags & TEST_BINDING) != 0;
2231 first_data_notif = TRUE;
2232 prot_read = 0;
2233 prot_state = 0;
2234 async_read_pending = TRUE;
2235 mimefilter_test = (flags & TEST_FILTER) != 0;
2236 filter_state = 0;
2237 post_stream_read = 0;
2238 ResetEvent(event_complete);
2239 ResetEvent(event_complete2);
2240 ResetEvent(event_continue);
2241 ResetEvent(event_continue_done);
2242 async_protocol = binding_protocol = filtered_protocol = NULL;
2243 filtered_sink = NULL;
2244 http_is_first = (flags & TEST_FIRST_HTTP) != 0;
2245 first_data_notif = TRUE;
2246 state = STATE_CONNECTING;
2247 test_async_req = (flags & TEST_ASYNCREQ) != 0;
2248 direct_read = (flags & TEST_DIRECT_READ) != 0;
2249 emulate_prot = (flags & TEST_EMULATEPROT) != 0;
2250 wait_for_switch = TRUE;
2251 short_read = (flags & TEST_SHORT_READ) != 0;
2252 http_post_test = TYMED_NULL;
2253 test_redirect = (flags & TEST_REDIRECT) != 0;
2254 test_abort = (flags & TEST_ABORT) != 0;
2255 impl_protex = (flags & TEST_IMPLPROTEX) != 0;
2256 empty_file = (flags & TEST_EMPTY) != 0;
2258 register_filter(mimefilter_test);
2261 static void test_priority(IInternetProtocol *protocol)
2263 IInternetPriority *priority;
2264 LONG pr;
2265 HRESULT hres;
2267 hres = IInternetProtocol_QueryInterface(protocol, &IID_IInternetPriority,
2268 (void**)&priority);
2269 ok(hres == S_OK, "QueryInterface(IID_IInternetPriority) failed: %08x\n", hres);
2270 if(FAILED(hres))
2271 return;
2273 hres = IInternetPriority_GetPriority(priority, &pr);
2274 ok(hres == S_OK, "GetPriority failed: %08x\n", hres);
2275 ok(pr == 0, "pr=%d, expected 0\n", pr);
2277 hres = IInternetPriority_SetPriority(priority, 1);
2278 ok(hres == S_OK, "SetPriority failed: %08x\n", hres);
2280 hres = IInternetPriority_GetPriority(priority, &pr);
2281 ok(hres == S_OK, "GetPriority failed: %08x\n", hres);
2282 ok(pr == 1, "pr=%d, expected 1\n", pr);
2284 IInternetPriority_Release(priority);
2287 static void test_early_abort(const CLSID *clsid)
2289 IInternetProtocol *protocol;
2290 HRESULT hres;
2292 hres = CoCreateInstance(clsid, NULL, CLSCTX_INPROC_SERVER|CLSCTX_INPROC_HANDLER,
2293 &IID_IInternetProtocol, (void**)&protocol);
2294 ok(hres == S_OK, "CoCreateInstance failed: %08x\n", hres);
2296 hres = IInternetProtocol_Abort(protocol, E_ABORT, 0);
2297 ok(hres == S_OK, "Abort failed: %08x\n", hres);
2299 hres = IInternetProtocol_Abort(protocol, E_FAIL, 0);
2300 ok(hres == S_OK, "Abort failed: %08x\n", hres);
2302 IInternetProtocol_Release(protocol);
2305 static BOOL file_protocol_start(IInternetProtocol *protocol, LPCWSTR url,
2306 IInternetProtocolEx *protocolex, IUri *uri, BOOL is_first)
2308 HRESULT hres;
2310 SET_EXPECT(GetBindInfo);
2311 if(!(bindf & BINDF_FROMURLMON))
2312 SET_EXPECT(ReportProgress_DIRECTBIND);
2313 if(is_first) {
2314 SET_EXPECT(ReportProgress_SENDINGREQUEST);
2315 SET_EXPECT(ReportProgress_CACHEFILENAMEAVAILABLE);
2316 if(bindf & BINDF_FROMURLMON)
2317 SET_EXPECT(ReportProgress_VERIFIEDMIMETYPEAVAILABLE);
2318 else
2319 SET_EXPECT(ReportProgress_MIMETYPEAVAILABLE);
2321 SET_EXPECT(ReportData);
2322 if(is_first)
2323 SET_EXPECT(ReportResult);
2325 expect_hrResult = S_OK;
2327 if(protocolex) {
2328 hres = IInternetProtocolEx_StartEx(protocolex, uri, &protocol_sink, &bind_info, 0, 0);
2329 ok(hres == S_OK, "StartEx failed: %08x\n", hres);
2330 }else {
2331 hres = IInternetProtocol_Start(protocol, url, &protocol_sink, &bind_info, 0, 0);
2332 if(hres == INET_E_RESOURCE_NOT_FOUND) {
2333 win_skip("Start failed\n");
2334 return FALSE;
2336 ok(hres == S_OK, "Start failed: %08x\n", hres);
2339 CHECK_CALLED(GetBindInfo);
2340 if(!(bindf & BINDF_FROMURLMON))
2341 CHECK_CALLED(ReportProgress_DIRECTBIND);
2342 if(is_first) {
2343 CHECK_CALLED(ReportProgress_SENDINGREQUEST);
2344 CHECK_CALLED(ReportProgress_CACHEFILENAMEAVAILABLE);
2345 if(bindf & BINDF_FROMURLMON)
2346 CHECK_CALLED(ReportProgress_VERIFIEDMIMETYPEAVAILABLE);
2347 else
2348 CHECK_CALLED(ReportProgress_MIMETYPEAVAILABLE);
2350 CHECK_CALLED(ReportData);
2351 if(is_first)
2352 CHECK_CALLED(ReportResult);
2354 return TRUE;
2357 static void test_file_protocol_url(LPCWSTR url)
2359 IInternetProtocolInfo *protocol_info;
2360 IUnknown *unk;
2361 IClassFactory *factory;
2362 IInternetProtocol *protocol;
2363 BYTE buf[512];
2364 ULONG cb;
2365 HRESULT hres;
2367 hres = CoGetClassObject(&CLSID_FileProtocol, CLSCTX_INPROC_SERVER, NULL,
2368 &IID_IUnknown, (void**)&unk);
2369 ok(hres == S_OK, "CoGetClassObject failed: %08x\n", hres);
2370 if(FAILED(hres))
2371 return;
2373 hres = IUnknown_QueryInterface(unk, &IID_IInternetProtocolInfo, (void**)&protocol_info);
2374 ok(hres == E_NOINTERFACE,
2375 "Could not get IInternetProtocolInfo interface: %08x, expected E_NOINTERFACE\n", hres);
2377 hres = IUnknown_QueryInterface(unk, &IID_IClassFactory, (void**)&factory);
2378 ok(hres == S_OK, "Could not get IClassFactory interface\n");
2379 IUnknown_Release(unk);
2380 if(FAILED(hres))
2381 return;
2383 hres = IClassFactory_CreateInstance(factory, NULL, &IID_IInternetProtocol, (void**)&protocol);
2384 ok(hres == S_OK, "Could not get IInternetProtocol: %08x\n", hres);
2386 if(SUCCEEDED(hres)) {
2387 if(file_protocol_start(protocol, url, NULL, NULL, TRUE)) {
2388 hres = IInternetProtocol_Read(protocol, buf, 2, &cb);
2389 ok(hres == S_OK, "Read failed: %08x\n", hres);
2390 ok(cb == 2, "cb=%u expected 2\n", cb);
2391 hres = IInternetProtocol_Read(protocol, buf, sizeof(buf), &cb);
2392 ok(hres == S_FALSE, "Read failed: %08x\n", hres);
2393 hres = IInternetProtocol_Read(protocol, buf, sizeof(buf), &cb);
2394 ok(hres == S_FALSE, "Read failed: %08x expected S_FALSE\n", hres);
2395 ok(cb == 0, "cb=%u expected 0\n", cb);
2396 hres = IInternetProtocol_UnlockRequest(protocol);
2397 ok(hres == S_OK, "UnlockRequest failed: %08x\n", hres);
2400 if(file_protocol_start(protocol, url, NULL, NULL, FALSE)) {
2401 hres = IInternetProtocol_Read(protocol, buf, 2, &cb);
2402 ok(hres == S_FALSE, "Read failed: %08x\n", hres);
2403 hres = IInternetProtocol_LockRequest(protocol, 0);
2404 ok(hres == S_OK, "LockRequest failed: %08x\n", hres);
2405 hres = IInternetProtocol_UnlockRequest(protocol);
2406 ok(hres == S_OK, "UnlockRequest failed: %08x\n", hres);
2409 IInternetProtocol_Release(protocol);
2412 hres = IClassFactory_CreateInstance(factory, NULL, &IID_IInternetProtocol, (void**)&protocol);
2413 ok(hres == S_OK, "Could not get IInternetProtocol: %08x\n", hres);
2414 if(SUCCEEDED(hres)) {
2415 if(file_protocol_start(protocol, url, NULL, NULL, TRUE)) {
2416 hres = IInternetProtocol_LockRequest(protocol, 0);
2417 ok(hres == S_OK, "LockRequest failed: %08x\n", hres);
2418 hres = IInternetProtocol_Terminate(protocol, 0);
2419 ok(hres == S_OK, "Terminate failed: %08x\n", hres);
2420 hres = IInternetProtocol_Read(protocol, buf, 2, &cb);
2421 ok(hres == S_OK, "Read failed: %08x\n\n", hres);
2422 hres = IInternetProtocol_UnlockRequest(protocol);
2423 ok(hres == S_OK, "UnlockRequest failed: %08x\n", hres);
2424 hres = IInternetProtocol_Read(protocol, buf, 2, &cb);
2425 ok(hres == S_OK, "Read failed: %08x\n", hres);
2426 hres = IInternetProtocol_Terminate(protocol, 0);
2427 ok(hres == S_OK, "Terminate failed: %08x\n", hres);
2430 IInternetProtocol_Release(protocol);
2433 hres = IClassFactory_CreateInstance(factory, NULL, &IID_IInternetProtocol, (void**)&protocol);
2434 ok(hres == S_OK, "Could not get IInternetProtocol: %08x\n", hres);
2435 if(SUCCEEDED(hres)) {
2436 if(file_protocol_start(protocol, url, NULL, NULL, TRUE)) {
2437 hres = IInternetProtocol_Terminate(protocol, 0);
2438 ok(hres == S_OK, "Terminate failed: %08x\n", hres);
2439 hres = IInternetProtocol_Read(protocol, buf, 2, &cb);
2440 ok(hres == S_OK, "Read failed: %08x\n", hres);
2441 ok(cb == 2, "cb=%u expected 2\n", cb);
2444 IInternetProtocol_Release(protocol);
2447 if(pCreateUri) {
2448 IInternetProtocolEx *protocolex;
2449 IUri *uri;
2451 hres = pCreateUri(url, Uri_CREATE_FILE_USE_DOS_PATH, 0, &uri);
2452 ok(hres == S_OK, "CreateUri failed: %08x\n", hres);
2454 hres = IClassFactory_CreateInstance(factory, NULL, &IID_IInternetProtocolEx, (void**)&protocolex);
2455 ok(hres == S_OK, "Could not get IInternetProtocolEx: %08x\n", hres);
2457 if(file_protocol_start(NULL, NULL, protocolex, uri, TRUE)) {
2458 hres = IInternetProtocolEx_Read(protocolex, buf, 2, &cb);
2459 ok(hres == S_OK, "Read failed: %08x\n", hres);
2460 hres = IInternetProtocolEx_LockRequest(protocolex, 0);
2461 ok(hres == S_OK, "LockRequest failed: %08x\n", hres);
2462 hres = IInternetProtocolEx_UnlockRequest(protocolex);
2463 ok(hres == S_OK, "UnlockRequest failed: %08x\n", hres);
2466 IUri_Release(uri);
2467 IInternetProtocolEx_Release(protocolex);
2469 hres = pCreateUri(url, 0, 0, &uri);
2470 ok(hres == S_OK, "CreateUri failed: %08x\n", hres);
2472 hres = IClassFactory_CreateInstance(factory, NULL, &IID_IInternetProtocolEx, (void**)&protocolex);
2473 ok(hres == S_OK, "Could not get IInternetProtocolEx: %08x\n", hres);
2475 if(file_protocol_start(NULL, NULL, protocolex, uri, TRUE)) {
2476 hres = IInternetProtocolEx_Read(protocolex, buf, 2, &cb);
2477 ok(hres == S_OK, "Read failed: %08x\n", hres);
2478 hres = IInternetProtocolEx_LockRequest(protocolex, 0);
2479 ok(hres == S_OK, "LockRequest failed: %08x\n", hres);
2480 hres = IInternetProtocolEx_UnlockRequest(protocolex);
2481 ok(hres == S_OK, "UnlockRequest failed: %08x\n", hres);
2484 IUri_Release(uri);
2485 IInternetProtocolEx_Release(protocolex);
2486 }else {
2487 win_skip("Skipping file protocol StartEx tests\n");
2490 IClassFactory_Release(factory);
2493 static void test_file_protocol_fail(void)
2495 IInternetProtocol *protocol;
2496 HRESULT hres;
2498 static const WCHAR index_url2[] =
2499 {'f','i','l','e',':','/','/','i','n','d','e','x','.','h','t','m','l',0};
2501 hres = CoCreateInstance(&CLSID_FileProtocol, NULL, CLSCTX_INPROC_SERVER|CLSCTX_INPROC_HANDLER,
2502 &IID_IInternetProtocol, (void**)&protocol);
2503 ok(hres == S_OK, "CoCreateInstance failed: %08x\n", hres);
2504 if(FAILED(hres))
2505 return;
2507 SET_EXPECT(GetBindInfo);
2508 expect_hrResult = MK_E_SYNTAX;
2509 hres = IInternetProtocol_Start(protocol, wszIndexHtml, &protocol_sink, &bind_info, 0, 0);
2510 ok(hres == MK_E_SYNTAX ||
2511 hres == E_INVALIDARG,
2512 "Start failed: %08x, expected MK_E_SYNTAX or E_INVALIDARG\n", hres);
2513 CLEAR_CALLED(GetBindInfo); /* GetBindInfo not called in IE7 */
2515 SET_EXPECT(GetBindInfo);
2516 if(!(bindf & BINDF_FROMURLMON))
2517 SET_EXPECT(ReportProgress_DIRECTBIND);
2518 SET_EXPECT(ReportProgress_SENDINGREQUEST);
2519 SET_EXPECT(ReportResult);
2520 expect_hrResult = INET_E_RESOURCE_NOT_FOUND;
2521 hres = IInternetProtocol_Start(protocol, index_url, &protocol_sink, &bind_info, 0, 0);
2522 ok(hres == INET_E_RESOURCE_NOT_FOUND,
2523 "Start failed: %08x expected INET_E_RESOURCE_NOT_FOUND\n", hres);
2524 CHECK_CALLED(GetBindInfo);
2525 if(!(bindf & BINDF_FROMURLMON))
2526 CHECK_CALLED(ReportProgress_DIRECTBIND);
2527 CHECK_CALLED(ReportProgress_SENDINGREQUEST);
2528 CHECK_CALLED(ReportResult);
2530 IInternetProtocol_Release(protocol);
2532 hres = CoCreateInstance(&CLSID_FileProtocol, NULL, CLSCTX_INPROC_SERVER|CLSCTX_INPROC_HANDLER,
2533 &IID_IInternetProtocol, (void**)&protocol);
2534 ok(hres == S_OK, "CoCreateInstance failed: %08x\n", hres);
2535 if(FAILED(hres))
2536 return;
2538 SET_EXPECT(GetBindInfo);
2539 if(!(bindf & BINDF_FROMURLMON))
2540 SET_EXPECT(ReportProgress_DIRECTBIND);
2541 SET_EXPECT(ReportProgress_SENDINGREQUEST);
2542 SET_EXPECT(ReportResult);
2543 expect_hrResult = INET_E_RESOURCE_NOT_FOUND;
2545 hres = IInternetProtocol_Start(protocol, index_url2, &protocol_sink, &bind_info, 0, 0);
2546 ok(hres == INET_E_RESOURCE_NOT_FOUND,
2547 "Start failed: %08x, expected INET_E_RESOURCE_NOT_FOUND\n", hres);
2548 CHECK_CALLED(GetBindInfo);
2549 if(!(bindf & BINDF_FROMURLMON))
2550 CHECK_CALLED(ReportProgress_DIRECTBIND);
2551 CHECK_CALLED(ReportProgress_SENDINGREQUEST);
2552 CHECK_CALLED(ReportResult);
2554 SET_EXPECT(GetBindInfo);
2555 hres = IInternetProtocol_Start(protocol, NULL, &protocol_sink, &bind_info, 0, 0);
2556 ok(hres == E_INVALIDARG, "Start failed: %08x, expected E_INVALIDARG\n", hres);
2557 CLEAR_CALLED(GetBindInfo); /* GetBindInfo not called in IE7 */
2559 SET_EXPECT(GetBindInfo);
2560 hres = IInternetProtocol_Start(protocol, emptyW, &protocol_sink, &bind_info, 0, 0);
2561 ok(hres == E_INVALIDARG, "Start failed: %08x, expected E_INVALIDARG\n", hres);
2562 CLEAR_CALLED(GetBindInfo); /* GetBindInfo not called in IE7 */
2564 IInternetProtocol_Release(protocol);
2567 static void test_file_protocol(void) {
2568 WCHAR buf[INTERNET_MAX_URL_LENGTH], file_name_buf[MAX_PATH];
2569 DWORD size;
2570 ULONG len;
2571 HANDLE file;
2573 static const WCHAR wszFile[] = {'f','i','l','e',':',0};
2574 static const WCHAR wszFile2[] = {'f','i','l','e',':','/','/',0};
2575 static const WCHAR wszFile3[] = {'f','i','l','e',':','/','/','/',0};
2576 static const WCHAR wszFile4[] = {'f','i','l','e',':','\\','\\',0};
2577 static const char html_doc[] = "<HTML></HTML>";
2579 trace("Testing file protocol...\n");
2580 init_test(FILE_TEST, 0);
2582 SetLastError(0xdeadbeef);
2583 file = CreateFileW(wszIndexHtml, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS,
2584 FILE_ATTRIBUTE_NORMAL, NULL);
2585 ok(file != INVALID_HANDLE_VALUE, "CreateFile failed\n");
2586 if(file == INVALID_HANDLE_VALUE)
2587 return;
2588 WriteFile(file, html_doc, sizeof(html_doc)-1, &size, NULL);
2589 CloseHandle(file);
2591 file_name = wszIndexHtml;
2592 bindf = 0;
2593 test_file_protocol_url(index_url);
2594 bindf = BINDF_FROMURLMON;
2595 test_file_protocol_url(index_url);
2596 bindf = BINDF_FROMURLMON | BINDF_NEEDFILE;
2597 test_file_protocol_url(index_url);
2599 memcpy(buf, wszFile, sizeof(wszFile));
2600 len = sizeof(wszFile)/sizeof(WCHAR)-1;
2601 len += GetCurrentDirectoryW(sizeof(buf)/sizeof(WCHAR)-len, buf+len);
2602 buf[len++] = '\\';
2603 memcpy(buf+len, wszIndexHtml, sizeof(wszIndexHtml));
2605 file_name = buf + sizeof(wszFile)/sizeof(WCHAR)-1;
2606 bindf = 0;
2607 test_file_protocol_url(buf);
2608 bindf = BINDF_FROMURLMON;
2609 test_file_protocol_url(buf);
2611 memcpy(buf, wszFile2, sizeof(wszFile2));
2612 len = GetCurrentDirectoryW(sizeof(file_name_buf)/sizeof(WCHAR), file_name_buf);
2613 file_name_buf[len++] = '\\';
2614 memcpy(file_name_buf+len, wszIndexHtml, sizeof(wszIndexHtml));
2615 lstrcpyW(buf+sizeof(wszFile2)/sizeof(WCHAR)-1, file_name_buf);
2616 file_name = file_name_buf;
2617 bindf = 0;
2618 test_file_protocol_url(buf);
2619 bindf = BINDF_FROMURLMON;
2620 test_file_protocol_url(buf);
2622 buf[sizeof(wszFile2)/sizeof(WCHAR)] = '|';
2623 test_file_protocol_url(buf);
2625 memcpy(buf, wszFile3, sizeof(wszFile3));
2626 len = sizeof(wszFile3)/sizeof(WCHAR)-1;
2627 len += GetCurrentDirectoryW(sizeof(buf)/sizeof(WCHAR)-len, buf+len);
2628 buf[len++] = '\\';
2629 memcpy(buf+len, wszIndexHtml, sizeof(wszIndexHtml));
2631 file_name = buf + sizeof(wszFile3)/sizeof(WCHAR)-1;
2632 bindf = 0;
2633 test_file_protocol_url(buf);
2634 bindf = BINDF_FROMURLMON;
2635 test_file_protocol_url(buf);
2637 memcpy(buf, wszFile4, sizeof(wszFile4));
2638 len = GetCurrentDirectoryW(sizeof(file_name_buf)/sizeof(WCHAR), file_name_buf);
2639 file_name_buf[len++] = '\\';
2640 memcpy(file_name_buf+len, wszIndexHtml, sizeof(wszIndexHtml));
2641 lstrcpyW(buf+sizeof(wszFile4)/sizeof(WCHAR)-1, file_name_buf);
2642 file_name = file_name_buf;
2643 bindf = 0;
2644 test_file_protocol_url(buf);
2645 bindf = BINDF_FROMURLMON;
2646 test_file_protocol_url(buf);
2648 buf[sizeof(wszFile4)/sizeof(WCHAR)] = '|';
2649 test_file_protocol_url(buf);
2651 DeleteFileW(wszIndexHtml);
2653 bindf = 0;
2654 test_file_protocol_fail();
2655 bindf = BINDF_FROMURLMON;
2656 test_file_protocol_fail();
2659 static BOOL http_protocol_start(LPCWSTR url, BOOL use_iuri)
2661 static BOOL got_user_agent = FALSE;
2662 IUri *uri = NULL;
2663 HRESULT hres;
2665 if(use_iuri && pCreateUri) {
2666 hres = pCreateUri(url, 0, 0, &uri);
2667 ok(hres == S_OK, "CreateUri failed: %08x\n", hres);
2670 SET_EXPECT(GetBindInfo);
2671 if (!(bindf & BINDF_FROMURLMON))
2672 SET_EXPECT(ReportProgress_DIRECTBIND);
2673 if(!got_user_agent)
2674 SET_EXPECT(GetBindString_USER_AGENT);
2675 SET_EXPECT(GetBindString_ACCEPT_MIMES);
2676 SET_EXPECT(QueryService_HttpNegotiate);
2677 SET_EXPECT(BeginningTransaction);
2678 SET_EXPECT(GetRootSecurityId);
2679 if(http_post_test) {
2680 SET_EXPECT(GetBindString_POST_COOKIE);
2681 if(http_post_test == TYMED_ISTREAM)
2682 SET_EXPECT(Stream_Seek);
2685 if(uri) {
2686 IInternetProtocolEx *protocolex;
2688 hres = IInternetProtocol_QueryInterface(async_protocol, &IID_IInternetProtocolEx, (void**)&protocolex);
2689 ok(hres == S_OK, "Could not get IInternetProtocolEx iface: %08x\n", hres);
2691 hres = IInternetProtocolEx_StartEx(protocolex, uri, &protocol_sink, &bind_info, 0, 0);
2692 ok(hres == S_OK, "Start failed: %08x\n", hres);
2694 IInternetProtocolEx_Release(protocolex);
2695 IUri_Release(uri);
2696 }else {
2697 hres = IInternetProtocol_Start(async_protocol, url, &protocol_sink, &bind_info, 0, 0);
2698 ok(hres == S_OK, "Start failed: %08x\n", hres);
2700 if(FAILED(hres))
2701 return FALSE;
2703 CHECK_CALLED(GetBindInfo);
2704 if (!(bindf & BINDF_FROMURLMON))
2705 CHECK_CALLED(ReportProgress_DIRECTBIND);
2706 if (!got_user_agent)
2708 CHECK_CALLED(GetBindString_USER_AGENT);
2709 got_user_agent = TRUE;
2711 CHECK_CALLED(GetBindString_ACCEPT_MIMES);
2712 CHECK_CALLED(QueryService_HttpNegotiate);
2713 CHECK_CALLED(BeginningTransaction);
2714 /* GetRootSecurityId called on WinXP but not on Win98 */
2715 CLEAR_CALLED(GetRootSecurityId);
2716 if(http_post_test) {
2717 CHECK_CALLED(GetBindString_POST_COOKIE);
2718 if(http_post_test == TYMED_ISTREAM)
2719 CHECK_CALLED(Stream_Seek);
2722 return TRUE;
2725 static void test_protocol_terminate(IInternetProtocol *protocol)
2727 BYTE buf[3600];
2728 DWORD cb;
2729 HRESULT hres;
2731 hres = IInternetProtocol_LockRequest(protocol, 0);
2732 ok(hres == S_OK, "LockRequest failed: %08x\n", hres);
2734 hres = IInternetProtocol_Read(protocol, buf, 1, &cb);
2735 ok(hres == test_abort ? S_OK : S_FALSE, "Read failed: %08x\n", hres);
2737 hres = IInternetProtocol_Terminate(protocol, 0);
2738 ok(hres == S_OK, "Terminate failed: %08x\n", hres);
2740 /* This wait is to give the internet handles being freed in Terminate
2741 * enough time to actually terminate in all cases. Internet handles
2742 * terminate asynchronously and native reuses the main InternetOpen
2743 * handle. The only case in which this seems to be necessary is on
2744 * wine with native wininet and urlmon, resulting in the next time
2745 * test_http_protocol_url being called the first data notification actually
2746 * being an extra last data notification from the previous connection
2747 * about once out of every ten times. */
2748 Sleep(100);
2750 hres = IInternetProtocol_UnlockRequest(protocol);
2751 ok(hres == S_OK, "UnlockRequest failed: %08x\n", hres);
2754 static void test_http_info(IInternetProtocol *protocol)
2756 IWinInetHttpInfo *info;
2757 HRESULT hres;
2759 hres = IInternetProtocol_QueryInterface(protocol, &IID_IWinInetHttpInfo, (void**)&info);
2760 ok(hres == S_OK, "Could not get IWinInterHttpInfo iface: %08x\n", hres);
2762 /* TODO */
2764 IWinInetHttpInfo_Release(info);
2767 /* is_first refers to whether this is the first call to this function
2768 * _for this url_ */
2769 static void test_http_protocol_url(LPCWSTR url, int prot, DWORD flags, DWORD tymed)
2771 IInternetProtocolInfo *protocol_info;
2772 IClassFactory *factory;
2773 IUnknown *unk;
2774 HRESULT hres;
2776 init_test(prot, flags);
2777 http_url = url;
2778 http_post_test = tymed;
2780 hres = CoGetClassObject(prot == HTTPS_TEST ? &CLSID_HttpSProtocol : &CLSID_HttpProtocol,
2781 CLSCTX_INPROC_SERVER, NULL, &IID_IUnknown, (void**)&unk);
2782 ok(hres == S_OK, "CoGetClassObject failed: %08x\n", hres);
2783 if(FAILED(hres))
2784 return;
2786 hres = IUnknown_QueryInterface(unk, &IID_IInternetProtocolInfo, (void**)&protocol_info);
2787 ok(hres == E_NOINTERFACE,
2788 "Could not get IInternetProtocolInfo interface: %08x, expected E_NOINTERFACE\n",
2789 hres);
2791 hres = IUnknown_QueryInterface(unk, &IID_IClassFactory, (void**)&factory);
2792 ok(hres == S_OK, "Could not get IClassFactory interface\n");
2793 IUnknown_Release(unk);
2794 if(FAILED(hres))
2795 return;
2797 hres = IClassFactory_CreateInstance(factory, NULL, &IID_IInternetProtocol,
2798 (void**)&async_protocol);
2799 ok(hres == S_OK, "Could not get IInternetProtocol: %08x\n", hres);
2800 if(SUCCEEDED(hres)) {
2801 BYTE buf[3600];
2802 DWORD cb;
2803 ULONG ref;
2805 test_priority(async_protocol);
2806 test_http_info(async_protocol);
2808 SET_EXPECT(ReportProgress_COOKIE_SENT);
2809 if(http_is_first) {
2810 SET_EXPECT(ReportProgress_FINDINGRESOURCE);
2811 SET_EXPECT(ReportProgress_CONNECTING);
2813 SET_EXPECT(ReportProgress_SENDINGREQUEST);
2814 if(test_redirect)
2815 SET_EXPECT(ReportProgress_REDIRECTING);
2816 SET_EXPECT(ReportProgress_PROXYDETECTING);
2817 if(prot == HTTP_TEST)
2818 SET_EXPECT(ReportProgress_CACHEFILENAMEAVAILABLE);
2819 else
2820 SET_EXPECT(QueryService_HttpSecurity);
2821 if(!(bindf & BINDF_FROMURLMON)) {
2822 SET_EXPECT(OnResponse);
2823 SET_EXPECT(ReportProgress_RAWMIMETYPE);
2824 SET_EXPECT(ReportData);
2825 } else {
2826 SET_EXPECT(Switch);
2829 if(!http_protocol_start(url, (flags & TEST_USEIURI) != 0))
2830 return;
2832 if(!direct_read && !test_abort)
2833 SET_EXPECT(ReportResult);
2834 expect_hrResult = test_abort ? E_ABORT : S_OK;
2836 if(direct_read) {
2837 SET_EXPECT(Switch);
2838 while(wait_for_switch) {
2839 WaitForSingleObject(event_continue, INFINITE);
2840 CHECK_CALLED(Switch); /* Set in ReportData */
2841 call_continue(&continue_protdata);
2842 SetEvent(event_continue_done);
2844 }else {
2845 hres = IInternetProtocol_Read(async_protocol, buf, 1, &cb);
2846 ok((hres == E_PENDING && cb==0) ||
2847 (hres == S_OK && cb==1), "Read failed: %08x (%d bytes)\n", hres, cb);
2849 WaitForSingleObject(event_complete, INFINITE);
2850 if(bindf & BINDF_FROMURLMON)
2851 CHECK_CALLED(Switch);
2852 else
2853 CHECK_CALLED(ReportData);
2854 if(prot == HTTPS_TEST)
2855 CLEAR_CALLED(QueryService_HttpSecurity);
2857 while(1) {
2858 if(bindf & BINDF_FROMURLMON)
2859 SET_EXPECT(Switch);
2860 else
2861 SET_EXPECT(ReportData);
2862 hres = IInternetProtocol_Read(async_protocol, buf, sizeof(buf), &cb);
2863 if(hres == E_PENDING) {
2864 hres = IInternetProtocol_Read(async_protocol, buf, 1, &cb);
2865 ok((hres == E_PENDING && cb==0) ||
2866 (hres == S_OK && cb==1), "Read failed: %08x (%d bytes)\n", hres, cb);
2867 WaitForSingleObject(event_complete, INFINITE);
2868 if(bindf & BINDF_FROMURLMON)
2869 CHECK_CALLED(Switch);
2870 else
2871 CHECK_CALLED(ReportData);
2873 if(test_abort) {
2874 HRESULT hres;
2876 SET_EXPECT(ReportResult);
2877 hres = IInternetProtocol_Abort(async_protocol, E_ABORT, 0);
2878 ok(hres == S_OK, "Abort failed: %08x\n", hres);
2879 CHECK_CALLED(ReportResult);
2881 hres = IInternetProtocol_Abort(async_protocol, E_ABORT, 0);
2882 ok(hres == INET_E_RESULT_DISPATCHED, "Abort failed: %08x\n", hres);
2883 break;
2885 }else {
2886 if(bindf & BINDF_FROMURLMON)
2887 CHECK_NOT_CALLED(Switch);
2888 else
2889 CHECK_NOT_CALLED(ReportData);
2890 if(cb == 0) break;
2893 if(!test_abort) {
2894 ok(hres == S_FALSE, "Read failed: %08x\n", hres);
2895 CHECK_CALLED(ReportResult);
2898 if(prot == HTTPS_TEST)
2899 CLEAR_CALLED(ReportProgress_SENDINGREQUEST);
2901 hres = IInternetProtocol_Abort(async_protocol, E_ABORT, 0);
2902 ok(hres == INET_E_RESULT_DISPATCHED, "Abort failed: %08x\n", hres);
2904 test_protocol_terminate(async_protocol);
2906 hres = IInternetProtocol_Abort(async_protocol, E_ABORT, 0);
2907 ok(hres == S_OK, "Abort failed: %08x\n", hres);
2909 ref = IInternetProtocol_Release(async_protocol);
2910 ok(!ref, "ref=%x\n", ref);
2913 IClassFactory_Release(factory);
2916 static void test_http_protocol(void)
2918 static const WCHAR posttest_url[] =
2919 {'h','t','t','p',':','/','/','t','e','s','t','.','w','i','n','e','h','q','.','o','r','g','/',
2920 't','e','s','t','s','/','p','o','s','t','.','p','h','p',0};
2921 static const WCHAR redirect_url[] =
2922 {'h','t','t','p',':','/','/','t','e','s','t','.','w','i','n','e','h','q','.','o','r','g','/',
2923 't','e','s','t','s','/','r','e','d','i','r','e','c','t',0};
2924 static const WCHAR winetest_url[] =
2925 {'h','t','t','p',':','/','/','t','e','s','t','.','w','i','n','e','h','q','.','o','r','g','/',
2926 't','e','s','t','s','/','d','a','t','a','.','p','h','p',0};
2927 static const WCHAR empty_url[] =
2928 {'h','t','t','p',':','/','/','t','e','s','t','.','w','i','n','e','h','q','.','o','r','g','/',
2929 't','e','s','t','s','/','e','m','p','t','y','.','j','s',0};
2931 trace("Testing http protocol (not from urlmon)...\n");
2932 bindf = BINDF_ASYNCHRONOUS | BINDF_ASYNCSTORAGE | BINDF_PULLDATA;
2933 test_http_protocol_url(winetest_url, HTTP_TEST, TEST_FIRST_HTTP, TYMED_NULL);
2935 trace("Testing http protocol (from urlmon)...\n");
2936 bindf = BINDF_ASYNCHRONOUS | BINDF_ASYNCSTORAGE | BINDF_PULLDATA | BINDF_FROMURLMON;
2937 test_http_protocol_url(winetest_url, HTTP_TEST, 0, TYMED_NULL);
2939 trace("Testing http protocol (to file)...\n");
2940 bindf = BINDF_ASYNCHRONOUS | BINDF_ASYNCSTORAGE | BINDF_PULLDATA | BINDF_FROMURLMON | BINDF_NEEDFILE;
2941 test_http_protocol_url(winetest_url, HTTP_TEST, 0, TYMED_NULL);
2943 trace("Testing http protocol (post data)...\n");
2944 bindf = BINDF_ASYNCHRONOUS | BINDF_ASYNCSTORAGE | BINDF_PULLDATA | BINDF_FROMURLMON;
2945 test_http_protocol_url(posttest_url, HTTP_TEST, TEST_FIRST_HTTP|TEST_POST, TYMED_HGLOBAL);
2947 trace("Testing http protocol (post data stream)...\n");
2948 test_http_protocol_url(posttest_url, HTTP_TEST, TEST_FIRST_HTTP|TEST_POST|TEST_ASYNCREQ, TYMED_ISTREAM);
2950 trace("Testing http protocol (direct read)...\n");
2951 bindf = BINDF_ASYNCHRONOUS | BINDF_ASYNCSTORAGE | BINDF_PULLDATA | BINDF_FROMURLMON;
2952 test_http_protocol_url(winetest_url, HTTP_TEST, TEST_DIRECT_READ|TEST_USEIURI, TYMED_NULL);
2954 trace("Testing http protocol (redirected)...\n");
2955 bindf = BINDF_ASYNCHRONOUS | BINDF_ASYNCSTORAGE | BINDF_PULLDATA | BINDF_FROMURLMON | BINDF_NOWRITECACHE;
2956 test_http_protocol_url(redirect_url, HTTP_TEST, TEST_REDIRECT, TYMED_NULL);
2958 trace("Testing http protocol empty file...\n");
2959 test_http_protocol_url(empty_url, HTTP_TEST, TEST_EMPTY, TYMED_NULL);
2961 trace("Testing http protocol abort...\n");
2962 test_http_protocol_url(winetest_url, HTTP_TEST, TEST_ABORT, TYMED_NULL);
2964 test_early_abort(&CLSID_HttpProtocol);
2965 test_early_abort(&CLSID_HttpSProtocol);
2968 static void test_https_protocol(void)
2970 static const WCHAR codeweavers_url[] =
2971 {'h','t','t','p','s',':','/','/','w','w','w','.','c','o','d','e','w','e','a','v','e','r','s',
2972 '.','c','o','m','/','t','e','s','t','.','h','t','m','l',0};
2974 trace("Testing https protocol (from urlmon)...\n");
2975 bindf = BINDF_ASYNCHRONOUS | BINDF_ASYNCSTORAGE | BINDF_PULLDATA | BINDF_FROMURLMON | BINDF_NOWRITECACHE;
2976 test_http_protocol_url(codeweavers_url, HTTPS_TEST, TEST_FIRST_HTTP, TYMED_NULL);
2980 static void test_ftp_protocol(void)
2982 IInternetProtocolInfo *protocol_info;
2983 IClassFactory *factory;
2984 IUnknown *unk;
2985 BYTE buf[4096];
2986 ULONG ref;
2987 DWORD cb;
2988 HRESULT hres;
2990 static const WCHAR ftp_urlW[] = {'f','t','p',':','/','/','f','t','p','.','w','i','n','e','h','q','.','o','r','g',
2991 '/','p','u','b','/','o','t','h','e','r','/',
2992 'w','i','n','e','l','o','g','o','.','x','c','f','.','t','a','r','.','b','z','2',0};
2994 trace("Testing ftp protocol...\n");
2996 bindf = BINDF_ASYNCHRONOUS | BINDF_ASYNCSTORAGE | BINDF_PULLDATA | BINDF_FROMURLMON | BINDF_NOWRITECACHE;
2997 state = STATE_STARTDOWNLOADING;
2998 tested_protocol = FTP_TEST;
2999 first_data_notif = TRUE;
3000 expect_hrResult = E_PENDING;
3002 hres = CoGetClassObject(&CLSID_FtpProtocol, CLSCTX_INPROC_SERVER, NULL, &IID_IUnknown, (void**)&unk);
3003 ok(hres == S_OK, "CoGetClassObject failed: %08x\n", hres);
3004 if(FAILED(hres))
3005 return;
3007 hres = IUnknown_QueryInterface(unk, &IID_IInternetProtocolInfo, (void**)&protocol_info);
3008 ok(hres == E_NOINTERFACE, "Could not get IInternetProtocolInfo interface: %08x, expected E_NOINTERFACE\n", hres);
3010 hres = IUnknown_QueryInterface(unk, &IID_IClassFactory, (void**)&factory);
3011 ok(hres == S_OK, "Could not get IClassFactory interface\n");
3012 IUnknown_Release(unk);
3013 if(FAILED(hres))
3014 return;
3016 hres = IClassFactory_CreateInstance(factory, NULL, &IID_IInternetProtocol,
3017 (void**)&async_protocol);
3018 IClassFactory_Release(factory);
3019 ok(hres == S_OK, "Could not get IInternetProtocol: %08x\n", hres);
3021 test_priority(async_protocol);
3022 test_http_info(async_protocol);
3024 SET_EXPECT(GetBindInfo);
3025 SET_EXPECT(ReportProgress_FINDINGRESOURCE);
3026 SET_EXPECT(ReportProgress_CONNECTING);
3027 SET_EXPECT(ReportProgress_SENDINGREQUEST);
3028 SET_EXPECT(Switch);
3030 hres = IInternetProtocol_Start(async_protocol, ftp_urlW, &protocol_sink, &bind_info, 0, 0);
3031 ok(hres == S_OK, "Start failed: %08x\n", hres);
3032 CHECK_CALLED(GetBindInfo);
3034 SET_EXPECT(ReportResult);
3036 hres = IInternetProtocol_Read(async_protocol, buf, 1, &cb);
3037 ok((hres == E_PENDING && cb==0) ||
3038 (hres == S_OK && cb==1), "Read failed: %08x (%d bytes)\n", hres, cb);
3040 WaitForSingleObject(event_complete, INFINITE);
3042 while(1) {
3043 hres = IInternetProtocol_Read(async_protocol, buf, sizeof(buf), &cb);
3044 if(hres == E_PENDING)
3045 WaitForSingleObject(event_complete, INFINITE);
3046 else
3047 if(cb == 0) break;
3050 ok(hres == S_FALSE, "Read failed: %08x\n", hres);
3051 CHECK_CALLED(ReportResult);
3052 CHECK_CALLED(Switch);
3054 test_protocol_terminate(async_protocol);
3056 if(pCreateUri) {
3057 IInternetProtocolEx *protocolex;
3059 hres = IInternetProtocol_QueryInterface(async_protocol, &IID_IInternetProtocolEx, (void**)&protocolex);
3060 ok(hres == S_OK, "Could not get IInternetProtocolEx iface: %08x\n", hres);
3061 IInternetProtocolEx_Release(protocolex);
3064 ref = IInternetProtocol_Release(async_protocol);
3065 ok(!ref, "ref=%d\n", ref);
3067 test_early_abort(&CLSID_FtpProtocol);
3070 static void test_gopher_protocol(void)
3072 IInternetProtocolInfo *protocol_info;
3073 IClassFactory *factory;
3074 IUnknown *unk;
3075 HRESULT hres;
3077 trace("Testing gopher protocol...\n");
3079 hres = CoGetClassObject(&CLSID_GopherProtocol, CLSCTX_INPROC_SERVER, NULL, &IID_IUnknown, (void**)&unk);
3080 ok(hres == S_OK ||
3081 hres == REGDB_E_CLASSNOTREG, /* Gopher protocol has been removed as of Vista */
3082 "CoGetClassObject failed: %08x\n", hres);
3083 if(FAILED(hres))
3084 return;
3086 hres = IUnknown_QueryInterface(unk, &IID_IInternetProtocolInfo, (void**)&protocol_info);
3087 ok(hres == E_NOINTERFACE, "Could not get IInternetProtocolInfo interface: %08x, expected E_NOINTERFACE\n", hres);
3089 hres = IUnknown_QueryInterface(unk, &IID_IClassFactory, (void**)&factory);
3090 ok(hres == S_OK, "Could not get IClassFactory interface\n");
3091 IUnknown_Release(unk);
3092 if(FAILED(hres))
3093 return;
3095 hres = IClassFactory_CreateInstance(factory, NULL, &IID_IInternetProtocol,
3096 (void**)&async_protocol);
3097 IClassFactory_Release(factory);
3098 ok(hres == S_OK, "Could not get IInternetProtocol: %08x\n", hres);
3100 test_priority(async_protocol);
3102 IInternetProtocol_Release(async_protocol);
3104 test_early_abort(&CLSID_GopherProtocol);
3107 static void test_mk_protocol(void)
3109 IInternetProtocolInfo *protocol_info;
3110 IInternetProtocol *protocol;
3111 IClassFactory *factory;
3112 IUnknown *unk;
3113 HRESULT hres;
3115 static const WCHAR wrong_url1[] = {'t','e','s','t',':','@','M','S','I','T','S','t','o','r','e',
3116 ':',':','/','t','e','s','t','.','h','t','m','l',0};
3117 static const WCHAR wrong_url2[] = {'m','k',':','/','t','e','s','t','.','h','t','m','l',0};
3119 trace("Testing mk protocol...\n");
3120 init_test(MK_TEST, 0);
3122 hres = CoGetClassObject(&CLSID_MkProtocol, CLSCTX_INPROC_SERVER, NULL,
3123 &IID_IUnknown, (void**)&unk);
3124 ok(hres == S_OK, "CoGetClassObject failed: %08x\n", hres);
3126 hres = IUnknown_QueryInterface(unk, &IID_IInternetProtocolInfo, (void**)&protocol_info);
3127 ok(hres == E_NOINTERFACE,
3128 "Could not get IInternetProtocolInfo interface: %08x, expected E_NOINTERFACE\n",
3129 hres);
3131 hres = IUnknown_QueryInterface(unk, &IID_IClassFactory, (void**)&factory);
3132 ok(hres == S_OK, "Could not get IClassFactory interface\n");
3133 IUnknown_Release(unk);
3134 if(FAILED(hres))
3135 return;
3137 hres = IClassFactory_CreateInstance(factory, NULL, &IID_IInternetProtocol,
3138 (void**)&protocol);
3139 IClassFactory_Release(factory);
3140 ok(hres == S_OK, "Could not get IInternetProtocol: %08x\n", hres);
3142 SET_EXPECT(GetBindInfo);
3143 hres = IInternetProtocol_Start(protocol, wrong_url1, &protocol_sink, &bind_info, 0, 0);
3144 ok(hres == MK_E_SYNTAX || hres == INET_E_INVALID_URL,
3145 "Start failed: %08x, expected MK_E_SYNTAX or INET_E_INVALID_URL\n", hres);
3146 CLEAR_CALLED(GetBindInfo);
3148 SET_EXPECT(GetBindInfo);
3149 SET_EXPECT(ReportProgress_DIRECTBIND);
3150 SET_EXPECT(ReportProgress_SENDINGREQUEST);
3151 SET_EXPECT(ReportProgress_MIMETYPEAVAILABLE);
3152 SET_EXPECT(ReportResult);
3153 expect_hrResult = INET_E_RESOURCE_NOT_FOUND;
3155 hres = IInternetProtocol_Start(protocol, wrong_url2, &protocol_sink, &bind_info, 0, 0);
3156 ok(hres == INET_E_RESOURCE_NOT_FOUND ||
3157 hres == INET_E_INVALID_URL, /* win2k3 */
3158 "Start failed: %08x, expected INET_E_RESOURCE_NOT_FOUND or INET_E_INVALID_URL\n", hres);
3160 if (hres == INET_E_RESOURCE_NOT_FOUND) {
3161 CHECK_CALLED(GetBindInfo);
3162 CLEAR_CALLED(ReportProgress_DIRECTBIND);
3163 CHECK_CALLED(ReportProgress_SENDINGREQUEST);
3164 CHECK_CALLED(ReportProgress_MIMETYPEAVAILABLE);
3165 CHECK_CALLED(ReportResult);
3166 }else {
3167 CLEAR_CALLED(GetBindInfo);
3168 CLEAR_CALLED(ReportProgress_DIRECTBIND);
3169 CLEAR_CALLED(ReportProgress_SENDINGREQUEST);
3170 CLEAR_CALLED(ReportProgress_MIMETYPEAVAILABLE);
3171 CLEAR_CALLED(ReportResult);
3174 IInternetProtocol_Release(protocol);
3177 static void test_CreateBinding(void)
3179 IInternetProtocol *protocol;
3180 IInternetPriority *priority;
3181 IInternetSession *session;
3182 IWinInetHttpInfo *http_info;
3183 IWinInetInfo *inet_info;
3184 LONG p;
3185 BYTE buf[1000];
3186 DWORD read;
3187 HRESULT hres;
3189 static const WCHAR test_url[] =
3190 {'t','e','s','t',':','/','/','f','i','l','e','.','h','t','m','l',0};
3191 static const WCHAR wsz_test[] = {'t','e','s','t',0};
3193 trace("Testing CreateBinding...\n");
3194 init_test(BIND_TEST, TEST_BINDING);
3196 hres = pCoInternetGetSession(0, &session, 0);
3197 ok(hres == S_OK, "CoInternetGetSession failed: %08x\n", hres);
3199 hres = IInternetSession_RegisterNameSpace(session, &ClassFactory, &IID_NULL, wsz_test, 0, NULL, 0);
3200 ok(hres == S_OK, "RegisterNameSpace failed: %08x\n", hres);
3202 hres = IInternetSession_CreateBinding(session, NULL, test_url, NULL, NULL, &protocol, 0);
3203 binding_protocol = protocol;
3204 ok(hres == S_OK, "CreateBinding failed: %08x\n", hres);
3205 ok(protocol != NULL, "protocol == NULL\n");
3207 hres = IInternetProtocol_QueryInterface(protocol, &IID_IInternetBindInfo, (void**)&prot_bind_info);
3208 ok(hres == S_OK, "QueryInterface(IID_IInternetBindInfo) failed: %08x\n", hres);
3210 hres = IInternetProtocol_QueryInterface(protocol, &IID_IInternetProtocolSink, (void**)&binding_sink);
3211 ok(hres == S_OK, "Could not get IInternetProtocolSink: %08x\n", hres);
3213 hres = IInternetProtocol_Start(protocol, test_url, NULL, &bind_info, 0, 0);
3214 ok(hres == E_INVALIDARG, "Start failed: %08x, expected E_INVALIDARG\n", hres);
3215 hres = IInternetProtocol_Start(protocol, test_url, &protocol_sink, NULL, 0, 0);
3216 ok(hres == E_INVALIDARG, "Start failed: %08x, expected E_INVALIDARG\n", hres);
3217 hres = IInternetProtocol_Start(protocol, NULL, &protocol_sink, &bind_info, 0, 0);
3218 ok(hres == E_INVALIDARG, "Start failed: %08x, expected E_INVALIDARG\n", hres);
3220 hres = IInternetProtocol_QueryInterface(protocol, &IID_IInternetPriority, (void**)&priority);
3221 ok(hres == S_OK, "QueryInterface(IID_IInternetPriority) failed: %08x\n", hres);
3223 p = 0xdeadbeef;
3224 hres = IInternetPriority_GetPriority(priority, &p);
3225 ok(hres == S_OK, "GetPriority failed: %08x\n", hres);
3226 ok(!p, "p=%d\n", p);
3228 ex_priority = 100;
3229 hres = IInternetPriority_SetPriority(priority, 100);
3230 ok(hres == S_OK, "SetPriority failed: %08x\n", hres);
3232 p = 0xdeadbeef;
3233 hres = IInternetPriority_GetPriority(priority, &p);
3234 ok(hres == S_OK, "GetPriority failed: %08x\n", hres);
3235 ok(p == 100, "p=%d\n", p);
3237 hres = IInternetProtocol_QueryInterface(protocol, &IID_IWinInetInfo, (void**)&inet_info);
3238 ok(hres == E_NOINTERFACE, "Could not get IWinInetInfo protocol: %08x\n", hres);
3240 SET_EXPECT(QueryService_InternetProtocol);
3241 SET_EXPECT(CreateInstance);
3242 SET_EXPECT(ReportProgress_PROTOCOLCLASSID);
3243 SET_EXPECT(SetPriority);
3244 SET_EXPECT(Start);
3246 expect_hrResult = S_OK;
3247 hres = IInternetProtocol_Start(protocol, test_url, &protocol_sink, &bind_info, 0, 0);
3248 ok(hres == S_OK, "Start failed: %08x\n", hres);
3250 CHECK_CALLED(QueryService_InternetProtocol);
3251 CHECK_CALLED(CreateInstance);
3252 CHECK_CALLED(ReportProgress_PROTOCOLCLASSID);
3253 CHECK_CALLED(SetPriority);
3254 CHECK_CALLED(Start);
3256 SET_EXPECT(QueryInterface_IWinInetInfo);
3257 hres = IInternetProtocol_QueryInterface(protocol, &IID_IWinInetInfo, (void**)&inet_info);
3258 ok(hres == E_NOINTERFACE, "Could not get IWinInetInfo protocol: %08x\n", hres);
3259 CHECK_CALLED(QueryInterface_IWinInetInfo);
3261 SET_EXPECT(QueryInterface_IWinInetInfo);
3262 hres = IInternetProtocol_QueryInterface(protocol, &IID_IWinInetInfo, (void**)&inet_info);
3263 ok(hres == E_NOINTERFACE, "Could not get IWinInetInfo protocol: %08x\n", hres);
3264 CHECK_CALLED(QueryInterface_IWinInetInfo);
3266 SET_EXPECT(QueryInterface_IWinInetHttpInfo);
3267 hres = IInternetProtocol_QueryInterface(protocol, &IID_IWinInetHttpInfo, (void**)&http_info);
3268 ok(hres == E_NOINTERFACE, "Could not get IWinInetInfo protocol: %08x\n", hres);
3269 CHECK_CALLED(QueryInterface_IWinInetHttpInfo);
3271 SET_EXPECT(Read);
3272 read = 0xdeadbeef;
3273 hres = IInternetProtocol_Read(protocol, expect_pv = buf, sizeof(buf), &read);
3274 ok(hres == S_OK, "Read failed: %08x\n", hres);
3275 ok(read == 100, "read = %d\n", read);
3276 CHECK_CALLED(Read);
3278 SET_EXPECT(Read);
3279 read = 0xdeadbeef;
3280 hres = IInternetProtocol_Read(protocol, expect_pv = buf, sizeof(buf), &read);
3281 ok(hres == S_FALSE, "Read failed: %08x\n", hres);
3282 ok(!read, "read = %d\n", read);
3283 CHECK_CALLED(Read);
3285 p = 0xdeadbeef;
3286 hres = IInternetPriority_GetPriority(priority, &p);
3287 ok(hres == S_OK, "GetPriority failed: %08x\n", hres);
3288 ok(p == 100, "p=%d\n", p);
3290 hres = IInternetPriority_SetPriority(priority, 101);
3291 ok(hres == S_OK, "SetPriority failed: %08x\n", hres);
3293 SET_EXPECT(Terminate);
3294 hres = IInternetProtocol_Terminate(protocol, 0xdeadbeef);
3295 ok(hres == S_OK, "Terminate failed: %08x\n", hres);
3296 CHECK_CALLED(Terminate);
3298 SET_EXPECT(Continue);
3299 hres = IInternetProtocolSink_Switch(binding_sink, &protocoldata);
3300 ok(hres == S_OK, "Switch failed: %08x\n", hres);
3301 CHECK_CALLED(Continue);
3303 hres = IInternetProtocolSink_ReportProgress(binding_sink,
3304 BINDSTATUS_CACHEFILENAMEAVAILABLE, expect_wsz = emptyW);
3305 ok(hres == S_OK, "ReportProgress(BINDSTATUS_CACHEFILENAMEAVAILABLE) failed: %08x\n", hres);
3307 hres = IInternetProtocolSink_ReportResult(binding_sink, S_OK, ERROR_SUCCESS, NULL);
3308 ok(hres == E_FAIL, "ReportResult failed: %08x, expected E_FAIL\n", hres);
3310 hres = IInternetProtocolSink_ReportData(binding_sink, 0, 0, 0);
3311 ok(hres == S_OK, "ReportData failed: %08x\n", hres);
3313 IInternetProtocolSink_Release(binding_sink);
3314 IInternetPriority_Release(priority);
3315 IInternetBindInfo_Release(prot_bind_info);
3316 IInternetProtocol_Release(protocol);
3318 hres = IInternetSession_CreateBinding(session, NULL, test_url, NULL, NULL, &protocol, 0);
3319 ok(hres == S_OK, "CreateBinding failed: %08x\n", hres);
3320 ok(protocol != NULL, "protocol == NULL\n");
3322 hres = IInternetProtocol_Abort(protocol, E_ABORT, 0);
3323 ok(hres == S_OK, "Abort failed: %08x\n", hres);
3325 hres = IInternetProtocol_Abort(protocol, E_FAIL, 0);
3326 ok(hres == S_OK, "Abort failed: %08x\n", hres);
3328 IInternetProtocol_Release(protocol);
3330 hres = IInternetSession_UnregisterNameSpace(session, &ClassFactory, wsz_test);
3331 ok(hres == S_OK, "UnregisterNameSpace failed: %08x\n", hres);
3333 hres = IInternetSession_CreateBinding(session, NULL, test_url, NULL, NULL, &protocol, 0);
3334 ok(hres == S_OK, "CreateBinding failed: %08x\n", hres);
3335 ok(protocol != NULL, "protocol == NULL\n");
3337 SET_EXPECT(QueryService_InternetProtocol);
3338 hres = IInternetProtocol_Start(protocol, test_url, &protocol_sink, &bind_info, 0, 0);
3339 ok(hres == MK_E_SYNTAX, "Start failed: %08x, expected MK_E_SYNTAX\n", hres);
3340 CHECK_CALLED(QueryService_InternetProtocol);
3342 IInternetProtocol_Release(protocol);
3344 IInternetSession_Release(session);
3347 static void test_binding(int prot, DWORD grf_pi, DWORD test_flags)
3349 IInternetProtocolEx *protocolex = NULL;
3350 IInternetProtocol *protocol;
3351 IInternetSession *session;
3352 IUri *uri = NULL;
3353 ULONG ref;
3354 HRESULT hres;
3356 pi = grf_pi;
3358 init_test(prot, test_flags|TEST_BINDING);
3360 hres = pCoInternetGetSession(0, &session, 0);
3361 ok(hres == S_OK, "CoInternetGetSession failed: %08x\n", hres);
3363 if(test_flags & TEST_EMULATEPROT) {
3364 hres = IInternetSession_RegisterNameSpace(session, &ClassFactory, &IID_NULL, protocol_names[prot], 0, NULL, 0);
3365 ok(hres == S_OK, "RegisterNameSpace failed: %08x\n", hres);
3368 hres = IInternetSession_CreateBinding(session, NULL, binding_urls[prot], NULL, NULL, &protocol, 0);
3369 binding_protocol = protocol;
3370 ok(hres == S_OK, "CreateBinding failed: %08x\n", hres);
3371 ok(protocol != NULL, "protocol == NULL\n");
3373 hres = IInternetProtocol_QueryInterface(protocol, &IID_IInternetBindInfo, (void**)&prot_bind_info);
3374 ok(hres == S_OK, "QueryInterface(IID_IInternetBindInfo) failed: %08x\n", hres);
3376 hres = IInternetProtocol_QueryInterface(protocol, &IID_IInternetProtocolSink, (void**)&binding_sink);
3377 ok(hres == S_OK, "QueryInterface(IID_IInternetProtocolSink) failed: %08x\n", hres);
3379 if(test_flags & TEST_USEIURI) {
3380 hres = IInternetProtocol_QueryInterface(protocol, &IID_IInternetProtocolEx, (void**)&protocolex);
3381 ok(hres == S_OK, "Could not get IInternetProtocolEx iface: %08x\n", hres);
3383 hres = pCreateUri(binding_urls[prot], Uri_CREATE_FILE_USE_DOS_PATH, 0, &uri);
3384 ok(hres == S_OK, "CreateUri failed: %08x\n", hres);
3387 ex_priority = 0;
3388 SET_EXPECT(QueryService_InternetProtocol);
3389 SET_EXPECT(CreateInstance);
3390 SET_EXPECT(ReportProgress_PROTOCOLCLASSID);
3391 SET_EXPECT(SetPriority);
3392 if(impl_protex)
3393 SET_EXPECT(StartEx);
3394 else
3395 SET_EXPECT(Start);
3397 expect_hrResult = S_OK;
3399 if(protocolex) {
3400 hres = IInternetProtocolEx_StartEx(protocolex, uri, &protocol_sink, &bind_info, pi, 0);
3401 ok(hres == S_OK, "StartEx failed: %08x\n", hres);
3402 }else {
3403 hres = IInternetProtocol_Start(protocol, binding_urls[prot], &protocol_sink, &bind_info, pi, 0);
3404 ok(hres == S_OK, "Start failed: %08x\n", hres);
3407 CHECK_CALLED(QueryService_InternetProtocol);
3408 CHECK_CALLED(CreateInstance);
3409 CHECK_CALLED(ReportProgress_PROTOCOLCLASSID);
3410 CHECK_CALLED(SetPriority);
3411 if(impl_protex)
3412 CHECK_CALLED(StartEx);
3413 else
3414 CHECK_CALLED(Start);
3416 if(protocolex)
3417 IInternetProtocolEx_Release(protocolex);
3418 if(uri)
3419 IUri_Release(uri);
3421 if(prot == HTTP_TEST || prot == HTTPS_TEST) {
3422 while(prot_state < 4) {
3423 WaitForSingleObject(event_complete, INFINITE);
3424 if(mimefilter_test && filtered_protocol) {
3425 SET_EXPECT(Continue);
3426 IInternetProtocol_Continue(filtered_protocol, pdata);
3427 CHECK_CALLED(Continue);
3428 }else {
3429 SET_EXPECT(Continue);
3430 IInternetProtocol_Continue(protocol, pdata);
3431 CHECK_CALLED(Continue);
3433 if(test_abort && prot_state == 2) {
3434 SET_EXPECT(Abort);
3435 hres = IInternetProtocol_Abort(protocol, E_ABORT, 0);
3436 ok(hres == S_OK, "Abort failed: %08x\n", hres);
3437 CHECK_CALLED(Abort);
3439 hres = IInternetProtocol_Abort(protocol, E_ABORT, 0);
3440 ok(hres == S_OK, "Abort failed: %08x\n", hres);
3441 SetEvent(event_complete2);
3442 break;
3444 SetEvent(event_complete2);
3446 if(direct_read)
3447 CHECK_CALLED(ReportData); /* Set in ReportResult */
3448 WaitForSingleObject(event_complete, INFINITE);
3449 }else {
3450 if(mimefilter_test)
3451 SET_EXPECT(MimeFilter_LockRequest);
3452 else
3453 SET_EXPECT(LockRequest);
3454 hres = IInternetProtocol_LockRequest(protocol, 0);
3455 ok(hres == S_OK, "LockRequest failed: %08x\n", hres);
3456 if(mimefilter_test)
3457 CHECK_CALLED(MimeFilter_LockRequest);
3458 else
3459 CHECK_CALLED(LockRequest);
3461 if(mimefilter_test)
3462 SET_EXPECT(MimeFilter_UnlockRequest);
3463 else
3464 SET_EXPECT(UnlockRequest);
3465 hres = IInternetProtocol_UnlockRequest(protocol);
3466 ok(hres == S_OK, "UnlockRequest failed: %08x\n", hres);
3467 if(mimefilter_test)
3468 CHECK_CALLED(MimeFilter_UnlockRequest);
3469 else
3470 CHECK_CALLED(UnlockRequest);
3473 if(mimefilter_test)
3474 SET_EXPECT(MimeFilter_Terminate);
3475 else
3476 SET_EXPECT(Terminate);
3477 hres = IInternetProtocol_Terminate(protocol, 0);
3478 ok(hres == S_OK, "Terminate failed: %08x\n", hres);
3479 if(mimefilter_test)
3480 CLEAR_CALLED(MimeFilter_Terminate);
3481 else
3482 CHECK_CALLED(Terminate);
3484 if(filtered_protocol)
3485 IInternetProtocol_Release(filtered_protocol);
3486 IInternetBindInfo_Release(prot_bind_info);
3487 IInternetProtocolSink_Release(binding_sink);
3488 ref = IInternetProtocol_Release(protocol);
3489 ok(!ref, "ref=%u, expected 0\n", ref);
3491 if(test_flags & TEST_EMULATEPROT) {
3492 hres = IInternetSession_UnregisterNameSpace(session, &ClassFactory, protocol_names[prot]);
3493 ok(hres == S_OK, "UnregisterNameSpace failed: %08x\n", hres);
3496 IInternetSession_Release(session);
3499 START_TEST(protocol)
3501 HMODULE hurlmon;
3503 hurlmon = GetModuleHandle("urlmon.dll");
3504 pCoInternetGetSession = (void*) GetProcAddress(hurlmon, "CoInternetGetSession");
3505 pReleaseBindInfo = (void*) GetProcAddress(hurlmon, "ReleaseBindInfo");
3506 pCreateUri = (void*) GetProcAddress(hurlmon, "CreateUri");
3508 if(!GetProcAddress(hurlmon, "CompareSecurityIds")) {
3509 win_skip("Various needed functions not present, too old IE\n");
3510 return;
3513 if(!pCreateUri)
3514 win_skip("CreateUri not supported\n");
3516 OleInitialize(NULL);
3518 event_complete = CreateEvent(NULL, FALSE, FALSE, NULL);
3519 event_complete2 = CreateEvent(NULL, FALSE, FALSE, NULL);
3520 event_continue = CreateEvent(NULL, FALSE, FALSE, NULL);
3521 event_continue_done = CreateEvent(NULL, FALSE, FALSE, NULL);
3522 thread_id = GetCurrentThreadId();
3524 test_file_protocol();
3525 test_http_protocol();
3526 test_https_protocol();
3527 test_ftp_protocol();
3528 test_gopher_protocol();
3529 test_mk_protocol();
3530 test_CreateBinding();
3532 bindf &= ~BINDF_FROMURLMON;
3533 trace("Testing file binding (mime verification, emulate prot)...\n");
3534 test_binding(FILE_TEST, PI_MIMEVERIFICATION, TEST_EMULATEPROT);
3535 trace("Testing http binding (mime verification, emulate prot)...\n");
3536 test_binding(HTTP_TEST, PI_MIMEVERIFICATION, TEST_EMULATEPROT);
3537 trace("Testing its binding (mime verification, emulate prot)...\n");
3538 test_binding(ITS_TEST, PI_MIMEVERIFICATION, TEST_EMULATEPROT);
3539 trace("Testing http binding (mime verification, emulate prot, short read, direct read)...\n");
3540 test_binding(HTTP_TEST, PI_MIMEVERIFICATION, TEST_EMULATEPROT|TEST_SHORT_READ|TEST_DIRECT_READ);
3541 trace("Testing file binding (mime verification, emulate prot, mime filter)...\n");
3542 test_binding(FILE_TEST, PI_MIMEVERIFICATION, TEST_EMULATEPROT|TEST_FILTER);
3543 trace("Testing http binding (mime verification, emulate prot, mime filter)...\n");
3544 test_binding(HTTP_TEST, PI_MIMEVERIFICATION, TEST_EMULATEPROT|TEST_FILTER);
3545 trace("Testing http binding (mime verification, emulate prot, direct read)...\n");
3546 test_binding(HTTP_TEST, PI_MIMEVERIFICATION, TEST_EMULATEPROT|TEST_DIRECT_READ);
3547 trace("Testing http binding (mime verification, emulate prot, abort)...\n");
3548 test_binding(HTTP_TEST, PI_MIMEVERIFICATION, TEST_EMULATEPROT|TEST_ABORT);
3549 if(pCreateUri) {
3550 trace("Testing file binding (use IUri, mime verification, emulate prot)...\n");
3551 test_binding(FILE_TEST, PI_MIMEVERIFICATION, TEST_EMULATEPROT|TEST_USEIURI);
3552 trace("Testing file binding (use IUri, impl StartEx, mime verification, emulate prot)...\n");
3553 test_binding(FILE_TEST, PI_MIMEVERIFICATION, TEST_EMULATEPROT|TEST_USEIURI|TEST_IMPLPROTEX);
3554 trace("Testing file binding (impl StartEx, mime verification, emulate prot)...\n");
3555 test_binding(FILE_TEST, PI_MIMEVERIFICATION, TEST_EMULATEPROT|TEST_IMPLPROTEX);
3558 CloseHandle(event_complete);
3559 CloseHandle(event_complete2);
3560 CloseHandle(event_continue);
3561 CloseHandle(event_continue_done);
3563 OleUninitialize();