2 * Copyright 2005-2011 Jacek Caban for CodeWeavers
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
22 #include <wine/test.h>
32 static HRESULT (WINAPI
*pCoInternetGetSession
)(DWORD
, IInternetSession
**, DWORD
);
33 static HRESULT (WINAPI
*pReleaseBindInfo
)(BINDINFO
*);
34 static HRESULT (WINAPI
*pCreateUri
)(LPCWSTR
, DWORD
, DWORD_PTR
, IUri
**);
36 #define DEFINE_EXPECT(func) \
37 static BOOL expect_ ## func = FALSE, called_ ## func = FALSE
39 #define SET_EXPECT(func) \
40 expect_ ## func = TRUE
42 #define CHECK_EXPECT2(func) \
44 ok(expect_ ##func, "unexpected call " #func "\n"); \
45 called_ ## func = TRUE; \
48 #define CHECK_EXPECT(func) \
50 CHECK_EXPECT2(func); \
51 expect_ ## func = FALSE; \
54 #define CHECK_CALLED(func) \
56 ok(called_ ## func, "expected " #func "\n"); \
57 expect_ ## func = called_ ## func = FALSE; \
60 #define CHECK_NOT_CALLED(func) \
62 ok(!called_ ## func, "unexpected " #func "\n"); \
63 expect_ ## func = called_ ## func = FALSE; \
66 #define CLEAR_CALLED(func) \
67 expect_ ## func = called_ ## func = FALSE
69 DEFINE_EXPECT(GetBindInfo
);
70 DEFINE_EXPECT(ReportProgress_MIMETYPEAVAILABLE
);
71 DEFINE_EXPECT(ReportProgress_DIRECTBIND
);
72 DEFINE_EXPECT(ReportProgress_RAWMIMETYPE
);
73 DEFINE_EXPECT(ReportProgress_FINDINGRESOURCE
);
74 DEFINE_EXPECT(ReportProgress_CONNECTING
);
75 DEFINE_EXPECT(ReportProgress_SENDINGREQUEST
);
76 DEFINE_EXPECT(ReportProgress_CACHEFILENAMEAVAILABLE
);
77 DEFINE_EXPECT(ReportProgress_VERIFIEDMIMETYPEAVAILABLE
);
78 DEFINE_EXPECT(ReportProgress_PROTOCOLCLASSID
);
79 DEFINE_EXPECT(ReportProgress_COOKIE_SENT
);
80 DEFINE_EXPECT(ReportProgress_REDIRECTING
);
81 DEFINE_EXPECT(ReportProgress_ENCODING
);
82 DEFINE_EXPECT(ReportProgress_ACCEPTRANGES
);
83 DEFINE_EXPECT(ReportProgress_PROXYDETECTING
);
84 DEFINE_EXPECT(ReportProgress_LOADINGMIMEHANDLER
);
85 DEFINE_EXPECT(ReportProgress_DECODING
);
86 DEFINE_EXPECT(ReportData
);
87 DEFINE_EXPECT(ReportData2
);
88 DEFINE_EXPECT(ReportResult
);
89 DEFINE_EXPECT(GetBindString_ACCEPT_MIMES
);
90 DEFINE_EXPECT(GetBindString_USER_AGENT
);
91 DEFINE_EXPECT(GetBindString_POST_COOKIE
);
92 DEFINE_EXPECT(GetBindString_URL
);
93 DEFINE_EXPECT(QueryService_HttpNegotiate
);
94 DEFINE_EXPECT(QueryService_InternetProtocol
);
95 DEFINE_EXPECT(QueryService_HttpSecurity
);
96 DEFINE_EXPECT(QueryInterface_IWinInetInfo
);
97 DEFINE_EXPECT(QueryInterface_IWinInetHttpInfo
);
98 DEFINE_EXPECT(BeginningTransaction
);
99 DEFINE_EXPECT(GetRootSecurityId
);
100 DEFINE_EXPECT(OnResponse
);
101 DEFINE_EXPECT(Switch
);
102 DEFINE_EXPECT(Continue
);
103 DEFINE_EXPECT(CreateInstance
);
104 DEFINE_EXPECT(Start
);
105 DEFINE_EXPECT(StartEx
);
106 DEFINE_EXPECT(Terminate
);
108 DEFINE_EXPECT(Read2
);
109 DEFINE_EXPECT(SetPriority
);
110 DEFINE_EXPECT(LockRequest
);
111 DEFINE_EXPECT(UnlockRequest
);
112 DEFINE_EXPECT(Abort
);
113 DEFINE_EXPECT(MimeFilter_CreateInstance
);
114 DEFINE_EXPECT(MimeFilter_Start
);
115 DEFINE_EXPECT(MimeFilter_ReportProgress
);
116 DEFINE_EXPECT(MimeFilter_ReportData
);
117 DEFINE_EXPECT(MimeFilter_ReportResult
);
118 DEFINE_EXPECT(MimeFilter_Terminate
);
119 DEFINE_EXPECT(MimeFilter_LockRequest
);
120 DEFINE_EXPECT(MimeFilter_UnlockRequest
);
121 DEFINE_EXPECT(MimeFilter_Read
);
122 DEFINE_EXPECT(MimeFilter_Switch
);
123 DEFINE_EXPECT(MimeFilter_Continue
);
124 DEFINE_EXPECT(Stream_Seek
);
125 DEFINE_EXPECT(Stream_Read
);
127 static const WCHAR wszIndexHtml
[] = {'i','n','d','e','x','.','h','t','m','l',0};
128 static const WCHAR index_url
[] =
129 {'f','i','l','e',':','i','n','d','e','x','.','h','t','m','l',0};
131 static const WCHAR acc_mimeW
[] = {'*','/','*',0};
132 static const WCHAR user_agentW
[] = {'W','i','n','e',0};
133 static const WCHAR text_htmlW
[] = {'t','e','x','t','/','h','t','m','l',0};
134 static const WCHAR hostW
[] = {'w','w','w','.','w','i','n','e','h','q','.','o','r','g',0};
135 static const WCHAR winehq_ipW
[] = {'2','0','9','.','4','6','.','2','5','.','1','3','4',0};
136 static const WCHAR emptyW
[] = {0};
137 static const WCHAR gzipW
[] = {'g','z','i','p',0};
139 static HRESULT expect_hrResult
;
140 static LPCWSTR file_name
, http_url
, expect_wsz
;
141 static IInternetProtocol
*async_protocol
= NULL
;
142 static BOOL first_data_notif
, http_is_first
, test_redirect
;
143 static int prot_state
, read_report_data
, post_stream_read
;
144 static DWORD bindf
, ex_priority
, pi
;
145 static IInternetProtocol
*binding_protocol
, *filtered_protocol
;
146 static IInternetBindInfo
*prot_bind_info
;
147 static IInternetProtocolSink
*binding_sink
, *filtered_sink
;
148 static void *expect_pv
;
149 static HANDLE event_complete
, event_complete2
, event_continue
, event_continue_done
;
150 static BOOL binding_test
;
151 static PROTOCOLDATA protocoldata
, *pdata
, continue_protdata
;
152 static DWORD prot_read
, pi
, filter_state
, http_post_test
, thread_id
;
153 static BOOL security_problem
, test_async_req
, impl_protex
;
154 static BOOL async_read_pending
, mimefilter_test
, direct_read
, wait_for_switch
, emulate_prot
, short_read
, test_abort
;
155 static BOOL empty_file
;
159 STATE_SENDINGREQUEST
,
160 STATE_STARTDOWNLOADING
,
174 static const WCHAR protocol_names
[][10] = {
177 {'h','t','t','p','s',0},
184 static const WCHAR binding_urls
[][130] = {
185 {'f','i','l','e',':','t','e','s','t','.','h','t','m','l',0},
186 {'h','t','t','p',':','/','/','w','w','w','.','w','i','n','e','h','q','.',
187 'o','r','g','/','s','i','t','e','/','a','b','o','u','t',0},
188 {'h','t','t','p','s',':','/','/','w','w','w','.','c','o','d','e','w','e','a','v','e','r','s',
189 '.','c','o','m','/','t','e','s','t','.','h','t','m','l',0},
190 {'f','t','p',':','/','/','f','t','p','.','w','i','n','e','h','q','.','o','r','g',
191 '/','p','u','b','/','o','t','h','e','r',
192 '/','w','i','n','e','l','o','g','o','.','x','c','f','.','t','a','r','.','b','z','2',0},
193 {'m','k',':','t','e','s','t',0},
194 {'i','t','s',':','t','e','s','t','.','c','h','m',':',':','/','b','l','a','n','k','.','h','t','m','l',0},
195 {'t','e','s','t',':','/','/','f','i','l','e','.','h','t','m','l',0}
198 static const CHAR post_data
[] = "mode=Test";
200 static const char *debugstr_guid(REFIID riid
)
204 sprintf(buf
, "{%08X-%04X-%04X-%02X%02X-%02X%02X%02X%02X%02X%02X}",
205 riid
->Data1
, riid
->Data2
, riid
->Data3
, riid
->Data4
[0],
206 riid
->Data4
[1], riid
->Data4
[2], riid
->Data4
[3], riid
->Data4
[4],
207 riid
->Data4
[5], riid
->Data4
[6], riid
->Data4
[7]);
212 static int strcmp_wa(LPCWSTR strw
, const char *stra
)
215 WideCharToMultiByte(CP_ACP
, 0, strw
, -1, buf
, sizeof(buf
), NULL
, NULL
);
216 return lstrcmpA(stra
, buf
);
219 static HRESULT WINAPI
HttpSecurity_QueryInterface(IHttpSecurity
*iface
, REFIID riid
, void **ppv
)
221 if(IsEqualGUID(&IID_IUnknown
, riid
)
222 || IsEqualGUID(&IID_IHttpSecurity
, riid
)) {
227 ok(0, "unexpected call\n");
228 return E_NOINTERFACE
;
231 static ULONG WINAPI
HttpSecurity_AddRef(IHttpSecurity
*iface
)
236 static ULONG WINAPI
HttpSecurity_Release(IHttpSecurity
*iface
)
241 static HRESULT WINAPI
HttpSecurity_GetWindow(IHttpSecurity
* iface
, REFGUID rguidReason
, HWND
*phwnd
)
243 trace("HttpSecurity_GetWindow\n");
248 static HRESULT WINAPI
HttpSecurity_OnSecurityProblem(IHttpSecurity
*iface
, DWORD dwProblem
)
250 trace("Security problem: %u\n", dwProblem
);
251 ok(dwProblem
== ERROR_INTERNET_SEC_CERT_REV_FAILED
, "Expected ERROR_INTERNET_SEC_CERT_REV_FAILED got %u\n", dwProblem
);
253 /* Only retry once */
254 if (security_problem
)
257 security_problem
= TRUE
;
258 SET_EXPECT(BeginningTransaction
);
263 static IHttpSecurityVtbl HttpSecurityVtbl
= {
264 HttpSecurity_QueryInterface
,
266 HttpSecurity_Release
,
267 HttpSecurity_GetWindow
,
268 HttpSecurity_OnSecurityProblem
271 static IHttpSecurity http_security
= { &HttpSecurityVtbl
};
273 static HRESULT WINAPI
HttpNegotiate_QueryInterface(IHttpNegotiate2
*iface
, REFIID riid
, void **ppv
)
275 if(IsEqualGUID(&IID_IUnknown
, riid
)
276 || IsEqualGUID(&IID_IHttpNegotiate
, riid
)
277 || IsEqualGUID(&IID_IHttpNegotiate2
, riid
)) {
282 ok(0, "unexpected call\n");
283 return E_NOINTERFACE
;
286 static ULONG WINAPI
HttpNegotiate_AddRef(IHttpNegotiate2
*iface
)
291 static ULONG WINAPI
HttpNegotiate_Release(IHttpNegotiate2
*iface
)
296 static HRESULT WINAPI
HttpNegotiate_BeginningTransaction(IHttpNegotiate2
*iface
, LPCWSTR szURL
,
297 LPCWSTR szHeaders
, DWORD dwReserved
, LPWSTR
*pszAdditionalHeaders
)
301 static const WCHAR wszHeaders
[] =
302 {'C','o','n','t','e','n','t','-','T','y','p','e',':',' ','a','p','p','l','i','c','a','t',
303 'i','o','n','/','x','-','w','w','w','-','f','o','r','m','-','u','r','l','e','n','c','o',
304 'd','e','d','\r','\n',0};
306 CHECK_EXPECT(BeginningTransaction
);
309 ok(!lstrcmpW(szURL
, binding_urls
[tested_protocol
]), "szURL != http_url\n");
311 ok(!lstrcmpW(szURL
, http_url
), "szURL != http_url\n");
312 ok(!dwReserved
, "dwReserved=%d, expected 0\n", dwReserved
);
313 ok(pszAdditionalHeaders
!= NULL
, "pszAdditionalHeaders == NULL\n");
314 if(pszAdditionalHeaders
)
316 ok(*pszAdditionalHeaders
== NULL
, "*pszAdditionalHeaders != NULL\n");
319 addl_headers
= CoTaskMemAlloc(sizeof(wszHeaders
));
320 memcpy(addl_headers
, wszHeaders
, sizeof(wszHeaders
));
321 *pszAdditionalHeaders
= addl_headers
;
328 static HRESULT WINAPI
HttpNegotiate_OnResponse(IHttpNegotiate2
*iface
, DWORD dwResponseCode
,
329 LPCWSTR szResponseHeaders
, LPCWSTR szRequestHeaders
, LPWSTR
*pszAdditionalRequestHeaders
)
331 CHECK_EXPECT(OnResponse
);
333 ok(dwResponseCode
== 200, "dwResponseCode=%d, expected 200\n", dwResponseCode
);
334 ok(szResponseHeaders
!= NULL
, "szResponseHeaders == NULL\n");
335 ok(szRequestHeaders
== NULL
, "szRequestHeaders != NULL\n");
336 ok(pszAdditionalRequestHeaders
== NULL
, "pszAdditionalHeaders != NULL\n");
341 static HRESULT WINAPI
HttpNegotiate_GetRootSecurityId(IHttpNegotiate2
*iface
,
342 BYTE
*pbSecurityId
, DWORD
*pcbSecurityId
, DWORD_PTR dwReserved
)
344 static const BYTE sec_id
[] = {'h','t','t','p',':','t','e','s','t',1,0,0,0};
346 CHECK_EXPECT(GetRootSecurityId
);
348 ok(!dwReserved
, "dwReserved=%ld, expected 0\n", dwReserved
);
349 ok(pbSecurityId
!= NULL
, "pbSecurityId == NULL\n");
350 ok(pcbSecurityId
!= NULL
, "pcbSecurityId == NULL\n");
353 ok(*pcbSecurityId
== 512, "*pcbSecurityId=%d, expected 512\n", *pcbSecurityId
);
354 *pcbSecurityId
= sizeof(sec_id
);
358 memcpy(pbSecurityId
, sec_id
, sizeof(sec_id
));
363 static IHttpNegotiate2Vtbl HttpNegotiateVtbl
= {
364 HttpNegotiate_QueryInterface
,
365 HttpNegotiate_AddRef
,
366 HttpNegotiate_Release
,
367 HttpNegotiate_BeginningTransaction
,
368 HttpNegotiate_OnResponse
,
369 HttpNegotiate_GetRootSecurityId
372 static IHttpNegotiate2 http_negotiate
= { &HttpNegotiateVtbl
};
374 static HRESULT
QueryInterface(REFIID
,void**);
376 static HRESULT WINAPI
ServiceProvider_QueryInterface(IServiceProvider
*iface
, REFIID riid
, void **ppv
)
378 return QueryInterface(riid
, ppv
);
381 static ULONG WINAPI
ServiceProvider_AddRef(IServiceProvider
*iface
)
386 static ULONG WINAPI
ServiceProvider_Release(IServiceProvider
*iface
)
391 static HRESULT WINAPI
ServiceProvider_QueryService(IServiceProvider
*iface
, REFGUID guidService
,
392 REFIID riid
, void **ppv
)
394 if(IsEqualGUID(&IID_IHttpNegotiate
, guidService
) || IsEqualGUID(&IID_IHttpNegotiate2
, riid
)) {
395 CHECK_EXPECT2(QueryService_HttpNegotiate
);
396 return IHttpNegotiate2_QueryInterface(&http_negotiate
, riid
, ppv
);
399 if(IsEqualGUID(&IID_IInternetProtocol
, guidService
)) {
400 ok(IsEqualGUID(&IID_IInternetProtocol
, riid
), "unexpected riid\n");
401 CHECK_EXPECT(QueryService_InternetProtocol
);
402 return E_NOINTERFACE
;
405 if(IsEqualGUID(&IID_IHttpSecurity
, guidService
)) {
406 ok(IsEqualGUID(&IID_IHttpSecurity
, riid
), "unexpected riid\n");
407 CHECK_EXPECT(QueryService_HttpSecurity
);
408 return IHttpSecurity_QueryInterface(&http_security
, riid
, ppv
);
411 ok(0, "unexpected service %s\n", debugstr_guid(guidService
));
415 static const IServiceProviderVtbl ServiceProviderVtbl
= {
416 ServiceProvider_QueryInterface
,
417 ServiceProvider_AddRef
,
418 ServiceProvider_Release
,
419 ServiceProvider_QueryService
422 static IServiceProvider service_provider
= { &ServiceProviderVtbl
};
424 static HRESULT WINAPI
Stream_QueryInterface(IStream
*iface
, REFIID riid
, void **ppv
)
426 ok(0, "unexpected call\n");
427 return E_NOINTERFACE
;
430 static ULONG WINAPI
Stream_AddRef(IStream
*iface
)
435 static ULONG WINAPI
Stream_Release(IStream
*iface
)
440 static HRESULT WINAPI
Stream_Read(IStream
*iface
, void *pv
,
441 ULONG cb
, ULONG
*pcbRead
)
443 CHECK_EXPECT2(Stream_Read
);
445 ok(GetCurrentThreadId() != thread_id
, "wrong thread %d\n", GetCurrentThreadId());
447 ok(pv
!= NULL
, "pv == NULL\n");
448 ok(cb
== 0x20000 || broken(cb
== 0x2000), "cb = %d\n", cb
);
449 ok(pcbRead
!= NULL
, "pcbRead == NULL\n");
451 if(post_stream_read
) {
456 memcpy(pv
, post_data
, sizeof(post_data
)-1);
457 post_stream_read
+= *pcbRead
= sizeof(post_data
)-1;
461 static HRESULT WINAPI
Stream_Write(IStream
*iface
, const void *pv
,
462 ULONG cb
, ULONG
*pcbWritten
)
464 ok(0, "unexpected call\n");
468 static HRESULT WINAPI
Stream_Seek(IStream
*iface
, LARGE_INTEGER dlibMove
,
469 DWORD dwOrigin
, ULARGE_INTEGER
*plibNewPosition
)
471 CHECK_EXPECT(Stream_Seek
);
473 ok(!dlibMove
.QuadPart
, "dlibMove != 0\n");
474 ok(dwOrigin
== STREAM_SEEK_SET
, "dwOrigin = %d\n", dwOrigin
);
475 ok(!plibNewPosition
, "plibNewPosition == NULL\n");
480 static HRESULT WINAPI
Stream_SetSize(IStream
*iface
, ULARGE_INTEGER libNewSize
)
482 ok(0, "unexpected call\n");
486 static HRESULT WINAPI
Stream_CopyTo(IStream
*iface
, IStream
*pstm
,
487 ULARGE_INTEGER cb
, ULARGE_INTEGER
*pcbRead
, ULARGE_INTEGER
*pcbWritten
)
489 ok(0, "unexpected call\n");
493 static HRESULT WINAPI
Stream_Commit(IStream
*iface
, DWORD grfCommitFlags
)
495 ok(0, "unexpected call\n");
499 static HRESULT WINAPI
Stream_Revert(IStream
*iface
)
501 ok(0, "unexpected call\n");
505 static HRESULT WINAPI
Stream_LockRegion(IStream
*iface
, ULARGE_INTEGER libOffset
,
506 ULARGE_INTEGER cb
, DWORD dwLockType
)
508 ok(0, "unexpected call\n");
512 static HRESULT WINAPI
Stream_UnlockRegion(IStream
*iface
,
513 ULARGE_INTEGER libOffset
, ULARGE_INTEGER cb
, DWORD dwLockType
)
515 ok(0, "unexpected call\n");
519 static HRESULT WINAPI
Stream_Stat(IStream
*iface
, STATSTG
*pstatstg
,
522 ok(0, "unexpected call\n");
526 static HRESULT WINAPI
Stream_Clone(IStream
*iface
, IStream
**ppstm
)
528 ok(0, "unexpected call\n");
532 static const IStreamVtbl StreamVtbl
= {
533 Stream_QueryInterface
,
549 static IStream Stream
= { &StreamVtbl
};
551 static HRESULT WINAPI
ProtocolSink_QueryInterface(IInternetProtocolSink
*iface
, REFIID riid
, void **ppv
)
553 return QueryInterface(riid
, ppv
);
556 static ULONG WINAPI
ProtocolSink_AddRef(IInternetProtocolSink
*iface
)
561 static ULONG WINAPI
ProtocolSink_Release(IInternetProtocolSink
*iface
)
566 static void call_continue(PROTOCOLDATA
*protocol_data
)
570 if(state
== STATE_CONNECTING
) {
571 if(tested_protocol
== HTTP_TEST
|| tested_protocol
== HTTPS_TEST
)
572 CLEAR_CALLED(ReportProgress_COOKIE_SENT
);
573 if(tested_protocol
== HTTP_TEST
|| tested_protocol
== HTTPS_TEST
|| tested_protocol
== FTP_TEST
) {
575 CLEAR_CALLED(ReportProgress_FINDINGRESOURCE
);
576 CLEAR_CALLED(ReportProgress_PROXYDETECTING
);
578 CLEAR_CALLED(ReportProgress_CONNECTING
);
580 if(tested_protocol
== FTP_TEST
)
581 todo_wine
CHECK_CALLED(ReportProgress_SENDINGREQUEST
);
582 else if (tested_protocol
!= HTTPS_TEST
)
583 CHECK_CALLED(ReportProgress_SENDINGREQUEST
);
585 CHECK_CALLED(ReportProgress_REDIRECTING
);
586 state
= test_async_req
? STATE_SENDINGREQUEST
: STATE_STARTDOWNLOADING
;
590 case STATE_SENDINGREQUEST
:
591 SET_EXPECT(Stream_Read
);
592 SET_EXPECT(ReportProgress_SENDINGREQUEST
);
594 case STATE_STARTDOWNLOADING
:
595 if(tested_protocol
== HTTP_TEST
|| tested_protocol
== HTTPS_TEST
) {
596 SET_EXPECT(OnResponse
);
597 if(tested_protocol
== HTTPS_TEST
|| test_redirect
|| test_abort
|| empty_file
)
598 SET_EXPECT(ReportProgress_ACCEPTRANGES
);
599 SET_EXPECT(ReportProgress_MIMETYPEAVAILABLE
);
600 if(bindf
& BINDF_NEEDFILE
)
601 SET_EXPECT(ReportProgress_CACHEFILENAMEAVAILABLE
);
607 if(state
!= STATE_SENDINGREQUEST
)
608 SET_EXPECT(ReportData
);
609 hres
= IInternetProtocol_Continue(async_protocol
, protocol_data
);
610 ok(hres
== S_OK
, "Continue failed: %08x\n", hres
);
611 if(tested_protocol
== FTP_TEST
|| security_problem
)
612 CLEAR_CALLED(ReportData
);
613 else if(state
!= STATE_SENDINGREQUEST
)
614 CHECK_CALLED(ReportData
);
617 case STATE_SENDINGREQUEST
:
618 CHECK_CALLED(Stream_Read
);
619 CHECK_CALLED(ReportProgress_SENDINGREQUEST
);
620 state
= STATE_STARTDOWNLOADING
;
622 case STATE_STARTDOWNLOADING
:
623 if (! security_problem
)
625 state
= STATE_DOWNLOADING
;
626 if(tested_protocol
== HTTP_TEST
|| tested_protocol
== HTTPS_TEST
) {
627 CHECK_CALLED(OnResponse
);
628 if(tested_protocol
== HTTPS_TEST
|| empty_file
)
629 CHECK_CALLED(ReportProgress_ACCEPTRANGES
);
630 else if(test_redirect
|| test_abort
)
631 CLEAR_CALLED(ReportProgress_ACCEPTRANGES
);
632 CHECK_CALLED(ReportProgress_MIMETYPEAVAILABLE
);
633 if(bindf
& BINDF_NEEDFILE
)
634 CHECK_CALLED(ReportProgress_CACHEFILENAMEAVAILABLE
);
639 security_problem
= FALSE
;
640 SET_EXPECT(ReportProgress_CONNECTING
);
647 static HRESULT WINAPI
ProtocolSink_Switch(IInternetProtocolSink
*iface
, PROTOCOLDATA
*pProtocolData
)
649 if(tested_protocol
== FTP_TEST
)
650 CHECK_EXPECT2(Switch
);
652 CHECK_EXPECT(Switch
);
654 ok(pProtocolData
!= NULL
, "pProtocolData == NULL\n");
656 ok(pProtocolData
!= &protocoldata
, "pProtocolData == &protocoldata\n");
657 ok(pProtocolData
->grfFlags
== protocoldata
.grfFlags
, "grfFlags wrong %x/%x\n",
658 pProtocolData
->grfFlags
, protocoldata
.grfFlags
);
659 ok(pProtocolData
->dwState
== protocoldata
.dwState
, "dwState wrong %x/%x\n",
660 pProtocolData
->dwState
, protocoldata
.dwState
);
661 ok(pProtocolData
->pData
== protocoldata
.pData
, "pData wrong %p/%p\n",
662 pProtocolData
->pData
, protocoldata
.pData
);
663 ok(pProtocolData
->cbData
== protocoldata
.cbData
, "cbData wrong %x/%x\n",
664 pProtocolData
->cbData
, protocoldata
.cbData
);
667 pdata
= pProtocolData
;
670 SetEvent(event_complete
);
671 WaitForSingleObject(event_complete2
, INFINITE
);
674 continue_protdata
= *pProtocolData
;
675 SetEvent(event_continue
);
676 WaitForSingleObject(event_continue_done
, INFINITE
);
678 call_continue(pProtocolData
);
679 SetEvent(event_complete
);
685 static HRESULT WINAPI
ProtocolSink_ReportProgress(IInternetProtocolSink
*iface
, ULONG ulStatusCode
,
686 LPCWSTR szStatusText
)
688 static const WCHAR null_guid
[] = {'{','0','0','0','0','0','0','0','0','-','0','0','0','0','-',
689 '0','0','0','0','-','0','0','0','0','-','0','0','0','0','0','0','0','0','0','0','0','0','}',0};
690 static const WCHAR text_plain
[] = {'t','e','x','t','/','p','l','a','i','n',0};
692 switch(ulStatusCode
) {
693 case BINDSTATUS_MIMETYPEAVAILABLE
:
694 CHECK_EXPECT(ReportProgress_MIMETYPEAVAILABLE
);
695 if(tested_protocol
!= FILE_TEST
&& tested_protocol
!= ITS_TEST
&& !mimefilter_test
&& (pi
& PI_MIMEVERIFICATION
)) {
696 if(!short_read
|| !direct_read
)
697 CHECK_CALLED(Read
); /* set in Continue */
699 CHECK_CALLED(Read2
); /* set in Read */
701 ok(szStatusText
!= NULL
, "szStatusText == NULL\n");
703 if(tested_protocol
== BIND_TEST
)
704 ok(!lstrcmpW(szStatusText
, expect_wsz
), "unexpected szStatusText %s\n", wine_dbgstr_w(szStatusText
));
705 else if (http_post_test
)
706 ok(lstrlenW(text_plain
) <= lstrlenW(szStatusText
) &&
707 !memcmp(szStatusText
, text_plain
, lstrlenW(text_plain
)*sizeof(WCHAR
)),
708 "szStatusText != text/plain\n");
710 ok(!strcmp_wa(szStatusText
, "application/javascript"), "szStatusText = %s\n", wine_dbgstr_w(szStatusText
));
711 else if(!mimefilter_test
)
712 ok(lstrlenW(text_htmlW
) <= lstrlenW(szStatusText
) &&
713 !memcmp(szStatusText
, text_htmlW
, lstrlenW(text_htmlW
)*sizeof(WCHAR
)),
714 "szStatusText != text/html\n");
717 case BINDSTATUS_DIRECTBIND
:
718 CHECK_EXPECT2(ReportProgress_DIRECTBIND
);
719 ok(szStatusText
== NULL
, "szStatusText != NULL\n");
721 case BINDSTATUS_RAWMIMETYPE
:
722 CHECK_EXPECT2(ReportProgress_RAWMIMETYPE
);
723 ok(szStatusText
!= NULL
, "szStatusText == NULL\n");
725 ok(lstrlenW(szStatusText
) < lstrlenW(text_htmlW
) ||
726 !memcmp(szStatusText
, text_htmlW
, lstrlenW(text_htmlW
)*sizeof(WCHAR
)),
727 "szStatusText != text/html\n");
729 case BINDSTATUS_CACHEFILENAMEAVAILABLE
:
730 CHECK_EXPECT(ReportProgress_CACHEFILENAMEAVAILABLE
);
731 ok(szStatusText
!= NULL
, "szStatusText == NULL\n");
734 ok(!lstrcmpW(szStatusText
, expect_wsz
), "unexpected szStatusText\n");
735 else if(tested_protocol
== FILE_TEST
)
736 ok(!lstrcmpW(szStatusText
, file_name
), "szStatusText = %s\n", wine_dbgstr_w(szStatusText
));
738 ok(szStatusText
!= NULL
, "szStatusText == NULL\n");
741 case BINDSTATUS_FINDINGRESOURCE
:
742 CHECK_EXPECT2(ReportProgress_FINDINGRESOURCE
);
743 ok(szStatusText
!= NULL
, "szStatusText == NULL\n");
745 case BINDSTATUS_CONNECTING
:
746 CHECK_EXPECT2(ReportProgress_CONNECTING
);
747 ok(szStatusText
!= NULL
, "szStatusText == NULL\n");
749 case BINDSTATUS_SENDINGREQUEST
:
750 CHECK_EXPECT2(ReportProgress_SENDINGREQUEST
);
751 if(tested_protocol
== FILE_TEST
|| tested_protocol
== ITS_TEST
) {
752 ok(szStatusText
!= NULL
, "szStatusText == NULL\n");
754 ok(!*szStatusText
, "wrong szStatusText\n");
757 case BINDSTATUS_VERIFIEDMIMETYPEAVAILABLE
:
758 CHECK_EXPECT(ReportProgress_VERIFIEDMIMETYPEAVAILABLE
);
759 ok(szStatusText
!= NULL
, "szStatusText == NULL\n");
761 ok(!strcmp_wa(szStatusText
, "text/html"), "szStatusText != text/html\n");
763 case BINDSTATUS_PROTOCOLCLASSID
:
764 CHECK_EXPECT(ReportProgress_PROTOCOLCLASSID
);
765 ok(szStatusText
!= NULL
, "szStatusText == NULL\n");
766 ok(!lstrcmpW(szStatusText
, null_guid
), "unexpected classid %s\n", wine_dbgstr_w(szStatusText
));
768 case BINDSTATUS_COOKIE_SENT
:
769 CHECK_EXPECT(ReportProgress_COOKIE_SENT
);
770 ok(szStatusText
== NULL
, "szStatusText != NULL\n");
772 case BINDSTATUS_REDIRECTING
:
773 CHECK_EXPECT(ReportProgress_REDIRECTING
);
775 ok(!strcmp_wa(szStatusText
, "http://test.winehq.org/tests/hello.html"), "szStatusText = %s\n", wine_dbgstr_w(szStatusText
));
777 ok(szStatusText
== NULL
, "szStatusText = %s\n", wine_dbgstr_w(szStatusText
));
779 case BINDSTATUS_ENCODING
:
780 CHECK_EXPECT(ReportProgress_ENCODING
);
781 ok(!strcmp_wa(szStatusText
, "gzip"), "szStatusText = %s\n", wine_dbgstr_w(szStatusText
));
783 case BINDSTATUS_ACCEPTRANGES
:
784 CHECK_EXPECT(ReportProgress_ACCEPTRANGES
);
785 ok(!szStatusText
, "szStatusText = %s\n", wine_dbgstr_w(szStatusText
));
787 case BINDSTATUS_PROXYDETECTING
:
788 if(!called_ReportProgress_PROXYDETECTING
)
789 SET_EXPECT(ReportProgress_CONNECTING
);
790 CHECK_EXPECT2(ReportProgress_PROXYDETECTING
);
791 ok(!szStatusText
, "szStatusText = %s\n", wine_dbgstr_w(szStatusText
));
793 case BINDSTATUS_LOADINGMIMEHANDLER
:
794 CHECK_EXPECT(ReportProgress_LOADINGMIMEHANDLER
);
795 ok(!szStatusText
, "szStatusText = %s\n", wine_dbgstr_w(szStatusText
));
797 case BINDSTATUS_DECODING
:
798 CHECK_EXPECT(ReportProgress_DECODING
);
799 ok(!lstrcmpW(szStatusText
, gzipW
), "szStatusText = %s\n", wine_dbgstr_w(szStatusText
));
802 ok(0, "Unexpected status %d\n", ulStatusCode
);
808 static HRESULT WINAPI
ProtocolSink_ReportData(IInternetProtocolSink
*iface
, DWORD grfBSCF
,
809 ULONG ulProgress
, ULONG ulProgressMax
)
813 static int rec_depth
;
816 if(!mimefilter_test
&& (tested_protocol
== FILE_TEST
|| tested_protocol
== ITS_TEST
)) {
817 CHECK_EXPECT2(ReportData
);
819 ok(ulProgress
== ulProgressMax
, "ulProgress (%d) != ulProgressMax (%d)\n",
820 ulProgress
, ulProgressMax
);
821 ok(ulProgressMax
== 13, "ulProgressMax=%d, expected 13\n", ulProgressMax
);
822 /* BSCF_SKIPDRAINDATAFORFILEURLS added in IE8 */
823 if(tested_protocol
== FILE_TEST
)
824 ok((grfBSCF
== (BSCF_FIRSTDATANOTIFICATION
| BSCF_LASTDATANOTIFICATION
)) ||
825 (grfBSCF
== (BSCF_FIRSTDATANOTIFICATION
| BSCF_LASTDATANOTIFICATION
| BSCF_SKIPDRAINDATAFORFILEURLS
)),
826 "grcfBSCF = %08x\n", grfBSCF
);
828 ok(grfBSCF
== (BSCF_FIRSTDATANOTIFICATION
| BSCF_DATAFULLYAVAILABLE
), "grcfBSCF = %08x\n", grfBSCF
);
829 }else if(direct_read
) {
833 if(!read_report_data
&& rec_depth
== 1) {
834 BOOL reported_all_data
= called_ReportData2
;
836 CHECK_EXPECT2(ReportData
);
839 ok(grfBSCF
== (BSCF_FIRSTDATANOTIFICATION
|BSCF_LASTDATANOTIFICATION
|BSCF_DATAFULLYAVAILABLE
)
840 || grfBSCF
== BSCF_FIRSTDATANOTIFICATION
, /* < IE8 */
841 "grcfBSCF = %08x\n", grfBSCF
);
842 CHECK_CALLED(Read
); /* Set in Continue */
843 first_data_notif
= FALSE
;
844 }else if(first_data_notif
) {
845 ok(grfBSCF
== BSCF_FIRSTDATANOTIFICATION
, "grcfBSCF = %08x\n", grfBSCF
);
846 first_data_notif
= FALSE
;
847 }else if(reported_all_data
) {
848 ok(grfBSCF
== (BSCF_LASTDATANOTIFICATION
|BSCF_INTERMEDIATEDATANOTIFICATION
),
849 "grcfBSCF = %08x\n", grfBSCF
);
850 }else if(!direct_read
) {
851 ok(grfBSCF
== BSCF_INTERMEDIATEDATANOTIFICATION
, "grcfBSCF = %08x\n", grfBSCF
);
859 SET_EXPECT(ReportData2
);
860 SET_EXPECT(ReportResult
);
863 hres
= IInternetProtocol_Read(binding_test
? binding_protocol
: async_protocol
, expect_pv
= buf
, sizeof(buf
), &read
);
864 ok(hres
== E_PENDING
|| hres
== S_FALSE
|| hres
== S_OK
, "Read failed: %08x\n", hres
);
866 ok(read
, "read == 0\n");
867 if(reported_all_data
)
868 ok(hres
== S_FALSE
, "Read failed: %08x, expected S_FALSE\n", hres
);
869 if(!emulate_prot
&& hres
!= E_PENDING
)
870 CHECK_NOT_CALLED(Switch
); /* otherwise checked in wait_for_switch loop */
873 if(!reported_all_data
&& called_ReportData2
) {
875 CHECK_CALLED(ReportData2
);
876 CHECK_CALLED(ReportResult
);
877 ok(hres
== S_OK
, "Read failed: %08x\n", hres
);
878 reported_all_data
= TRUE
;
881 CHECK_NOT_CALLED(ReportData2
);
882 CHECK_NOT_CALLED(ReportResult
);
884 }while(hres
== S_OK
);
886 wait_for_switch
= FALSE
;
888 CHECK_EXPECT(ReportData2
);
890 ok(grfBSCF
& BSCF_LASTDATANOTIFICATION
, "grfBSCF = %08x\n", grfBSCF
);
895 hres
= IInternetProtocol_Read(binding_test
? binding_protocol
: async_protocol
, expect_pv
= buf
, sizeof(buf
), &read
);
898 ok(hres
== S_FALSE
, "Read returned: %08x, expected E_FALSE\n", hres
);
899 ok(!read
, "read = %d\n", read
);
901 }else if(!binding_test
&& (tested_protocol
== HTTP_TEST
|| tested_protocol
== HTTPS_TEST
902 || tested_protocol
== FTP_TEST
)) {
904 CHECK_EXPECT2(ReportData
);
905 else if(!(grfBSCF
& BSCF_LASTDATANOTIFICATION
) || (grfBSCF
& BSCF_DATAFULLYAVAILABLE
))
906 CHECK_EXPECT(ReportData
);
907 else if (http_post_test
)
908 ok(ulProgress
== 13, "Read %u bytes instead of 13\n", ulProgress
);
911 ok(!ulProgress
, "ulProgress = %d\n", ulProgress
);
912 ok(!ulProgressMax
, "ulProgressMax = %d\n", ulProgressMax
);
914 ok(ulProgress
, "ulProgress == 0\n");
918 ok(grfBSCF
== (BSCF_FIRSTDATANOTIFICATION
|BSCF_LASTDATANOTIFICATION
),
919 "grcfBSCF = %08x\n", grfBSCF
);
920 first_data_notif
= FALSE
;
921 }else if(first_data_notif
) {
922 ok(grfBSCF
== BSCF_FIRSTDATANOTIFICATION
923 || grfBSCF
== (BSCF_LASTDATANOTIFICATION
|BSCF_DATAFULLYAVAILABLE
),
924 "grcfBSCF = %08x\n", grfBSCF
);
925 first_data_notif
= FALSE
;
927 ok(grfBSCF
== BSCF_INTERMEDIATEDATANOTIFICATION
928 || grfBSCF
== (BSCF_LASTDATANOTIFICATION
|BSCF_INTERMEDIATEDATANOTIFICATION
)
929 || broken(grfBSCF
== (BSCF_FIRSTDATANOTIFICATION
|BSCF_LASTDATANOTIFICATION
)),
930 "grcfBSCF = %08x\n", grfBSCF
);
933 if(!(bindf
& BINDF_FROMURLMON
) &&
934 !(grfBSCF
& BSCF_LASTDATANOTIFICATION
)) {
935 if(state
== STATE_CONNECTING
) {
936 state
= STATE_DOWNLOADING
;
938 CHECK_CALLED(ReportProgress_FINDINGRESOURCE
);
939 CHECK_CALLED(ReportProgress_CONNECTING
);
941 CHECK_CALLED(ReportProgress_SENDINGREQUEST
);
942 CHECK_CALLED(OnResponse
);
943 CHECK_CALLED(ReportProgress_RAWMIMETYPE
);
945 SetEvent(event_complete
);
947 }else if(!read_report_data
) {
952 CHECK_EXPECT(ReportData
);
954 if(tested_protocol
!= BIND_TEST
) {
957 SET_EXPECT(MimeFilter_Read
);
958 else if(rec_depth
> 1)
962 hres
= IInternetProtocol_Read(binding_protocol
, expect_pv
=buf
, sizeof(buf
), &read
);
964 CHECK_CALLED(MimeFilter_Read
);
965 else if(rec_depth
> 1)
969 }while(hres
== S_OK
);
977 static HRESULT WINAPI
ProtocolSink_ReportResult(IInternetProtocolSink
*iface
, HRESULT hrResult
,
978 DWORD dwError
, LPCWSTR szResult
)
980 CHECK_EXPECT(ReportResult
);
982 if(tested_protocol
== FTP_TEST
)
983 ok(hrResult
== E_PENDING
|| hrResult
== S_OK
, "hrResult = %08x, expected E_PENDING or S_OK\n", hrResult
);
985 ok(hrResult
== expect_hrResult
, "hrResult = %08x, expected: %08x\n",
986 hrResult
, expect_hrResult
);
987 if(SUCCEEDED(hrResult
) || tested_protocol
== FTP_TEST
|| test_abort
)
988 ok(dwError
== ERROR_SUCCESS
, "dwError = %d, expected ERROR_SUCCESS\n", dwError
);
990 ok(dwError
!= ERROR_SUCCESS
||
991 broken(tested_protocol
== MK_TEST
), /* WinME and NT4 */
992 "dwError == ERROR_SUCCESS\n");
993 ok(!szResult
, "szResult != NULL\n");
996 SET_EXPECT(ReportData
); /* checked after main loop */
1001 static IInternetProtocolSinkVtbl protocol_sink_vtbl
= {
1002 ProtocolSink_QueryInterface
,
1003 ProtocolSink_AddRef
,
1004 ProtocolSink_Release
,
1005 ProtocolSink_Switch
,
1006 ProtocolSink_ReportProgress
,
1007 ProtocolSink_ReportData
,
1008 ProtocolSink_ReportResult
1011 static IInternetProtocolSink protocol_sink
= { &protocol_sink_vtbl
};
1013 static HRESULT WINAPI
MimeProtocolSink_QueryInterface(IInternetProtocolSink
*iface
, REFIID riid
, void **ppv
)
1015 ok(0, "unexpected call\n");
1019 static ULONG WINAPI
MimeProtocolSink_AddRef(IInternetProtocolSink
*iface
)
1024 static ULONG WINAPI
MimeProtocolSink_Release(IInternetProtocolSink
*iface
)
1029 static HRESULT WINAPI
MimeProtocolSink_Switch(IInternetProtocolSink
*iface
, PROTOCOLDATA
*pProtocolData
)
1033 CHECK_EXPECT(MimeFilter_Switch
);
1036 hres
= IInternetProtocolSink_Switch(filtered_sink
, pProtocolData
);
1037 ok(hres
== S_OK
, "Switch failed: %08x\n", hres
);
1038 CHECK_CALLED(Switch
);
1043 static HRESULT WINAPI
MimeProtocolSink_ReportProgress(IInternetProtocolSink
*iface
, ULONG ulStatusCode
,
1044 LPCWSTR szStatusText
)
1046 CHECK_EXPECT(MimeFilter_ReportProgress
);
1050 static HRESULT WINAPI
MimeProtocolSink_ReportData(IInternetProtocolSink
*iface
, DWORD grfBSCF
,
1051 ULONG ulProgress
, ULONG ulProgressMax
)
1057 CHECK_EXPECT(MimeFilter_ReportData
);
1061 hres
= IInternetProtocol_Read(filtered_protocol
, buf
, sizeof(buf
), &read
);
1062 if(tested_protocol
== HTTP_TEST
)
1063 ok(hres
== S_OK
|| hres
== E_PENDING
|| hres
== S_FALSE
, "Read failed: %08x\n", hres
);
1065 ok(hres
== S_OK
, "Read failed: %08x\n", hres
);
1068 SET_EXPECT(ReportProgress_MIMETYPEAVAILABLE
);
1069 hres
= IInternetProtocolSink_ReportProgress(filtered_sink
, BINDSTATUS_VERIFIEDMIMETYPEAVAILABLE
, text_htmlW
);
1070 ok(hres
== S_OK
, "ReportProgress failed: %08x\n", hres
);
1071 CHECK_CALLED(ReportProgress_MIMETYPEAVAILABLE
);
1073 /* FIXME: test BINDSTATUS_CACHEFILENAMEAVAILABLE */
1076 if(!read_report_data
)
1077 SET_EXPECT(ReportData
);
1078 hres
= IInternetProtocolSink_ReportData(filtered_sink
, grfBSCF
, ulProgress
, ulProgressMax
);
1079 ok(hres
== S_OK
, "ReportData failed: %08x\n", hres
);
1080 if(!read_report_data
)
1081 CHECK_CALLED(ReportData
);
1089 static HRESULT WINAPI
MimeProtocolSink_ReportResult(IInternetProtocolSink
*iface
, HRESULT hrResult
,
1090 DWORD dwError
, LPCWSTR szResult
)
1094 CHECK_EXPECT(MimeFilter_ReportResult
);
1096 ok(hrResult
== S_OK
, "hrResult = %08x\n", hrResult
);
1097 ok(dwError
== ERROR_SUCCESS
, "dwError = %u\n", dwError
);
1098 ok(!szResult
, "szResult = %s\n", wine_dbgstr_w(szResult
));
1100 SET_EXPECT(ReportResult
);
1101 hres
= IInternetProtocolSink_ReportResult(filtered_sink
, hrResult
, dwError
, szResult
);
1102 ok(SUCCEEDED(hres
), "ReportResult failed: %08x\n", hres
);
1103 CHECK_CALLED(ReportResult
);
1108 static IInternetProtocolSinkVtbl mime_protocol_sink_vtbl
= {
1109 MimeProtocolSink_QueryInterface
,
1110 MimeProtocolSink_AddRef
,
1111 MimeProtocolSink_Release
,
1112 MimeProtocolSink_Switch
,
1113 MimeProtocolSink_ReportProgress
,
1114 MimeProtocolSink_ReportData
,
1115 MimeProtocolSink_ReportResult
1118 static IInternetProtocolSink mime_protocol_sink
= { &mime_protocol_sink_vtbl
};
1120 static HRESULT
QueryInterface(REFIID riid
, void **ppv
)
1122 static const IID IID_undocumented
= {0x58DFC7D0,0x5381,0x43E5,{0x9D,0x72,0x4C,0xDD,0xE4,0xCB,0x0F,0x1A}};
1126 if(IsEqualGUID(&IID_IUnknown
, riid
) || IsEqualGUID(&IID_IInternetProtocolSink
, riid
))
1127 *ppv
= &protocol_sink
;
1128 if(IsEqualGUID(&IID_IServiceProvider
, riid
))
1129 *ppv
= &service_provider
;
1130 if(IsEqualGUID(&IID_IUriContainer
, riid
))
1131 return E_NOINTERFACE
; /* TODO */
1133 /* NOTE: IE8 queries for undocumented {58DFC7D0-5381-43E5-9D72-4CDDE4CB0F1A} interface. */
1134 if(IsEqualGUID(&IID_undocumented
, riid
))
1135 return E_NOINTERFACE
;
1140 ok(0, "unexpected call %s\n", debugstr_guid(riid
));
1141 return E_NOINTERFACE
;
1144 static HRESULT WINAPI
BindInfo_QueryInterface(IInternetBindInfo
*iface
, REFIID riid
, void **ppv
)
1146 if(IsEqualGUID(&IID_IUnknown
, riid
) || IsEqualGUID(&IID_IInternetBindInfo
, riid
)) {
1150 return E_NOINTERFACE
;
1153 static ULONG WINAPI
BindInfo_AddRef(IInternetBindInfo
*iface
)
1158 static ULONG WINAPI
BindInfo_Release(IInternetBindInfo
*iface
)
1163 static HRESULT WINAPI
BindInfo_GetBindInfo(IInternetBindInfo
*iface
, DWORD
*grfBINDF
, BINDINFO
*pbindinfo
)
1167 CHECK_EXPECT(GetBindInfo
);
1169 ok(grfBINDF
!= NULL
, "grfBINDF == NULL\n");
1170 ok(pbindinfo
!= NULL
, "pbindinfo == NULL\n");
1171 ok(pbindinfo
->cbSize
== sizeof(BINDINFO
), "wrong size of pbindinfo: %d\n", pbindinfo
->cbSize
);
1175 *grfBINDF
|= BINDF_FROMURLMON
;
1176 cbSize
= pbindinfo
->cbSize
;
1177 memset(pbindinfo
, 0, cbSize
);
1178 pbindinfo
->cbSize
= cbSize
;
1182 pbindinfo
->cbstgmedData
= sizeof(post_data
)-1;
1183 pbindinfo
->dwBindVerb
= BINDVERB_POST
;
1184 pbindinfo
->stgmedData
.tymed
= http_post_test
;
1186 if(http_post_test
== TYMED_HGLOBAL
) {
1189 /* Must be GMEM_FIXED, GMEM_MOVABLE does not work properly */
1190 data
= GlobalAlloc(GPTR
, sizeof(post_data
));
1191 memcpy(data
, post_data
, sizeof(post_data
));
1192 U(pbindinfo
->stgmedData
).hGlobal
= data
;
1194 IStream
*post_stream
;
1199 /* Must be GMEM_FIXED, GMEM_MOVABLE does not work properly */
1200 data
= GlobalAlloc(GPTR
, sizeof(post_data
));
1201 memcpy(data
, post_data
, sizeof(post_data
));
1202 U(pbindinfo
->stgmedData
).hGlobal
= data
;
1204 hres
= CreateStreamOnHGlobal(data
, FALSE
, &post_stream
);
1205 ok(hres
== S_OK
, "CreateStreamOnHGlobal failed: %08x\n", hres
);
1207 U(pbindinfo
->stgmedData
).pstm
=post_stream
;/* &Stream; */
1209 U(pbindinfo
->stgmedData
).pstm
= &Stream
;
1216 static HRESULT WINAPI
BindInfo_GetBindString(IInternetBindInfo
*iface
, ULONG ulStringType
,
1217 LPOLESTR
*ppwzStr
, ULONG cEl
, ULONG
*pcElFetched
)
1219 ok(ppwzStr
!= NULL
, "ppwzStr == NULL\n");
1220 ok(pcElFetched
!= NULL
, "pcElFetched == NULL\n");
1222 switch(ulStringType
) {
1223 case BINDSTRING_ACCEPT_MIMES
:
1224 CHECK_EXPECT(GetBindString_ACCEPT_MIMES
);
1225 ok(cEl
== 256, "cEl=%d, expected 256\n", cEl
);
1227 ok(*pcElFetched
== 256, "*pcElFetched=%d, expected 256\n", *pcElFetched
);
1231 *ppwzStr
= CoTaskMemAlloc(sizeof(acc_mimeW
));
1232 memcpy(*ppwzStr
, acc_mimeW
, sizeof(acc_mimeW
));
1235 case BINDSTRING_USER_AGENT
:
1236 CHECK_EXPECT(GetBindString_USER_AGENT
);
1237 ok(cEl
== 1, "cEl=%d, expected 1\n", cEl
);
1239 ok(*pcElFetched
== 0, "*pcElFetch=%d, expectd 0\n", *pcElFetched
);
1243 *ppwzStr
= CoTaskMemAlloc(sizeof(user_agentW
));
1244 memcpy(*ppwzStr
, user_agentW
, sizeof(user_agentW
));
1247 case BINDSTRING_POST_COOKIE
:
1248 CHECK_EXPECT(GetBindString_POST_COOKIE
);
1249 ok(cEl
== 1, "cEl=%d, expected 1\n", cEl
);
1251 ok(*pcElFetched
== 0, "*pcElFetch=%d, expectd 0\n", *pcElFetched
);
1253 case BINDSTRING_URL
: {
1256 CHECK_EXPECT(GetBindString_URL
);
1257 ok(cEl
== 1, "cEl=%d, expected 1\n", cEl
);
1258 ok(*pcElFetched
== 0, "*pcElFetch=%d, expectd 0\n", *pcElFetched
);
1261 size
= (lstrlenW(binding_urls
[tested_protocol
])+1)*sizeof(WCHAR
);
1262 *ppwzStr
= CoTaskMemAlloc(size
);
1263 memcpy(*ppwzStr
, binding_urls
[tested_protocol
], size
);
1267 ok(0, "unexpected call\n");
1273 static IInternetBindInfoVtbl bind_info_vtbl
= {
1274 BindInfo_QueryInterface
,
1277 BindInfo_GetBindInfo
,
1278 BindInfo_GetBindString
1281 static IInternetBindInfo bind_info
= { &bind_info_vtbl
};
1283 static HRESULT WINAPI
InternetPriority_QueryInterface(IInternetPriority
*iface
,
1284 REFIID riid
, void **ppv
)
1286 ok(0, "unexpected call\n");
1287 return E_NOINTERFACE
;
1290 static ULONG WINAPI
InternetPriority_AddRef(IInternetPriority
*iface
)
1295 static ULONG WINAPI
InternetPriority_Release(IInternetPriority
*iface
)
1300 static HRESULT WINAPI
InternetPriority_SetPriority(IInternetPriority
*iface
, LONG nPriority
)
1302 CHECK_EXPECT(SetPriority
);
1303 ok(nPriority
== ex_priority
, "nPriority=%d\n", nPriority
);
1307 static HRESULT WINAPI
InternetPriority_GetPriority(IInternetPriority
*iface
, LONG
*pnPriority
)
1309 ok(0, "unexpected call\n");
1314 static const IInternetPriorityVtbl InternetPriorityVtbl
= {
1315 InternetPriority_QueryInterface
,
1316 InternetPriority_AddRef
,
1317 InternetPriority_Release
,
1318 InternetPriority_SetPriority
,
1319 InternetPriority_GetPriority
1322 static IInternetPriority InternetPriority
= { &InternetPriorityVtbl
};
1324 static ULONG WINAPI
Protocol_AddRef(IInternetProtocolEx
*iface
)
1329 static ULONG WINAPI
Protocol_Release(IInternetProtocolEx
*iface
)
1334 static HRESULT WINAPI
Protocol_Abort(IInternetProtocolEx
*iface
, HRESULT hrReason
,
1339 CHECK_EXPECT(Abort
);
1341 SET_EXPECT(ReportResult
);
1342 hres
= IInternetProtocolSink_ReportResult(binding_sink
, S_OK
, ERROR_SUCCESS
, NULL
);
1343 ok(hres
== S_OK
, "ReportResult failed: %08x\n", hres
);
1344 CHECK_CALLED(ReportResult
);
1349 static HRESULT WINAPI
Protocol_Suspend(IInternetProtocolEx
*iface
)
1351 ok(0, "unexpected call\n");
1355 static HRESULT WINAPI
Protocol_Resume(IInternetProtocolEx
*iface
)
1357 ok(0, "unexpected call\n");
1361 static HRESULT WINAPI
Protocol_Seek(IInternetProtocolEx
*iface
,
1362 LARGE_INTEGER dlibMove
, DWORD dwOrigin
, ULARGE_INTEGER
*plibNewPosition
)
1364 ok(0, "unexpected call\n");
1368 static HRESULT WINAPI
ProtocolEmul_QueryInterface(IInternetProtocolEx
*iface
, REFIID riid
, void **ppv
)
1370 if(IsEqualGUID(&IID_IUnknown
, riid
) || IsEqualGUID(&IID_IInternetProtocol
, riid
)) {
1375 if(IsEqualGUID(&IID_IInternetProtocolEx
, riid
)) {
1381 return E_NOINTERFACE
;
1384 if(IsEqualGUID(&IID_IInternetPriority
, riid
)) {
1385 *ppv
= &InternetPriority
;
1389 if(IsEqualGUID(&IID_IWinInetInfo
, riid
)) {
1390 CHECK_EXPECT(QueryInterface_IWinInetInfo
);
1392 return E_NOINTERFACE
;
1395 if(IsEqualGUID(&IID_IWinInetHttpInfo
, riid
)) {
1396 CHECK_EXPECT(QueryInterface_IWinInetHttpInfo
);
1398 return E_NOINTERFACE
;
1401 ok(0, "unexpected riid %s\n", debugstr_guid(riid
));
1403 return E_NOINTERFACE
;
1406 static DWORD WINAPI
thread_proc(PVOID arg
)
1410 memset(&protocoldata
, -1, sizeof(protocoldata
));
1414 SET_EXPECT(ReportProgress_FINDINGRESOURCE
);
1415 hres
= IInternetProtocolSink_ReportProgress(binding_sink
,
1416 BINDSTATUS_FINDINGRESOURCE
, hostW
);
1417 CHECK_CALLED(ReportProgress_FINDINGRESOURCE
);
1418 ok(hres
== S_OK
, "ReportProgress failed: %08x\n", hres
);
1420 SET_EXPECT(ReportProgress_CONNECTING
);
1421 hres
= IInternetProtocolSink_ReportProgress(binding_sink
,
1422 BINDSTATUS_CONNECTING
, winehq_ipW
);
1423 CHECK_CALLED(ReportProgress_CONNECTING
);
1424 ok(hres
== S_OK
, "ReportProgress failed: %08x\n", hres
);
1426 SET_EXPECT(ReportProgress_SENDINGREQUEST
);
1427 hres
= IInternetProtocolSink_ReportProgress(binding_sink
,
1428 BINDSTATUS_SENDINGREQUEST
, NULL
);
1429 CHECK_CALLED(ReportProgress_SENDINGREQUEST
);
1430 ok(hres
== S_OK
, "ReportProgress failed: %08x\n", hres
);
1434 hres
= IInternetProtocolSink_Switch(binding_sink
, &protocoldata
);
1435 CHECK_CALLED(Switch
);
1436 ok(hres
== S_OK
, "Switch failed: %08x\n", hres
);
1441 SET_EXPECT(MimeFilter_Switch
);
1444 hres
= IInternetProtocolSink_Switch(binding_sink
, &protocoldata
);
1445 ok(hres
== S_OK
, "Switch failed: %08x\n", hres
);
1447 CHECK_CALLED(MimeFilter_Switch
);
1449 CHECK_CALLED(Switch
);
1452 SetEvent(event_complete
);
1458 SET_EXPECT(MimeFilter_Switch
);
1461 hres
= IInternetProtocolSink_Switch(binding_sink
, &protocoldata
);
1462 ok(hres
== S_OK
, "Switch failed: %08x\n", hres
);
1464 CHECK_CALLED(MimeFilter_Switch
);
1466 CHECK_CALLED(Switch
);
1470 SET_EXPECT(MimeFilter_Switch
);
1473 hres
= IInternetProtocolSink_Switch(binding_sink
, &protocoldata
);
1474 ok(hres
== S_OK
, "Switch failed: %08x\n", hres
);
1476 CHECK_CALLED(MimeFilter_Switch
);
1478 CHECK_CALLED(Switch
);
1481 SetEvent(event_complete
);
1486 static void protocol_start(IInternetProtocolSink
*pOIProtSink
, IInternetBindInfo
*pOIBindInfo
, DWORD pi
)
1488 BINDINFO bindinfo
, exp_bindinfo
;
1492 ok(pOIProtSink
!= NULL
, "pOIProtSink == NULL\n");
1493 ok(pOIBindInfo
!= NULL
, "pOIBindInfo == NULL\n");
1494 ok(pOIProtSink
!= &protocol_sink
, "unexpected pOIProtSink\n");
1495 ok(pOIBindInfo
!= &bind_info
, "unexpected pOIBindInfo\n");
1496 ok(!pi
, "pi = %x\n", pi
);
1499 ok(pOIProtSink
== binding_sink
, "pOIProtSink != binding_sink\n");
1501 memset(&bindinfo
, 0, sizeof(bindinfo
));
1502 bindinfo
.cbSize
= sizeof(bindinfo
);
1503 memcpy(&exp_bindinfo
, &bindinfo
, sizeof(bindinfo
));
1504 SET_EXPECT(GetBindInfo
);
1505 hres
= IInternetBindInfo_GetBindInfo(pOIBindInfo
, &cbindf
, &bindinfo
);
1506 ok(hres
== S_OK
, "GetBindInfo failed: %08x\n", hres
);
1507 CHECK_CALLED(GetBindInfo
);
1508 ok(cbindf
== (bindf
|BINDF_FROMURLMON
), "bindf = %x, expected %x\n",
1509 cbindf
, (bindf
|BINDF_FROMURLMON
));
1510 ok(!memcmp(&exp_bindinfo
, &bindinfo
, sizeof(bindinfo
)), "unexpected bindinfo\n");
1511 pReleaseBindInfo(&bindinfo
);
1513 SET_EXPECT(ReportProgress_SENDINGREQUEST
);
1514 hres
= IInternetProtocolSink_ReportProgress(pOIProtSink
, BINDSTATUS_SENDINGREQUEST
, emptyW
);
1515 ok(hres
== S_OK
, "ReportProgress(BINDSTATUS_SENDINGREQUEST) failed: %08x\n", hres
);
1516 CHECK_CALLED(ReportProgress_SENDINGREQUEST
);
1518 if(tested_protocol
== HTTP_TEST
|| tested_protocol
== HTTPS_TEST
) {
1519 IServiceProvider
*service_provider
;
1520 IHttpNegotiate
*http_negotiate
;
1521 IHttpNegotiate2
*http_negotiate2
;
1522 LPWSTR ua
= (LPWSTR
)0xdeadbeef, accept_mimes
[256];
1523 LPWSTR additional_headers
= NULL
;
1525 DWORD fetched
= 0, size
= 100;
1528 SET_EXPECT(GetBindString_USER_AGENT
);
1529 hres
= IInternetBindInfo_GetBindString(pOIBindInfo
, BINDSTRING_USER_AGENT
,
1531 CHECK_CALLED(GetBindString_USER_AGENT
);
1532 ok(hres
== S_OK
, "GetBindString(BINDSTRING_USER_AGETNT) failed: %08x\n", hres
);
1533 ok(fetched
== 1, "fetched = %d, expected 254\n", fetched
);
1534 ok(ua
!= NULL
, "ua = %p\n", ua
);
1535 ok(!lstrcmpW(ua
, user_agentW
), "unexpected user agent %s\n", wine_dbgstr_w(ua
));
1539 SET_EXPECT(GetBindString_ACCEPT_MIMES
);
1540 hres
= IInternetBindInfo_GetBindString(pOIBindInfo
, BINDSTRING_ACCEPT_MIMES
,
1541 accept_mimes
, 256, &fetched
);
1542 CHECK_CALLED(GetBindString_ACCEPT_MIMES
);
1545 "GetBindString(BINDSTRING_ACCEPT_MIMES) failed: %08x\n", hres
);
1546 ok(fetched
== 1, "fetched = %d, expected 1\n", fetched
);
1547 ok(!lstrcmpW(acc_mimeW
, accept_mimes
[0]), "unexpected mimes %s\n", wine_dbgstr_w(accept_mimes
[0]));
1548 CoTaskMemFree(accept_mimes
[0]);
1550 hres
= IInternetBindInfo_QueryInterface(pOIBindInfo
, &IID_IServiceProvider
,
1551 (void**)&service_provider
);
1552 ok(hres
== S_OK
, "QueryInterface failed: %08x\n", hres
);
1554 SET_EXPECT(QueryService_HttpNegotiate
);
1555 hres
= IServiceProvider_QueryService(service_provider
, &IID_IHttpNegotiate
,
1556 &IID_IHttpNegotiate
, (void**)&http_negotiate
);
1557 CHECK_CALLED(QueryService_HttpNegotiate
);
1558 ok(hres
== S_OK
, "QueryService failed: %08x\n", hres
);
1560 SET_EXPECT(BeginningTransaction
);
1561 hres
= IHttpNegotiate_BeginningTransaction(http_negotiate
, binding_urls
[tested_protocol
],
1562 NULL
, 0, &additional_headers
);
1563 CHECK_CALLED(BeginningTransaction
);
1564 IHttpNegotiate_Release(http_negotiate
);
1565 ok(hres
== S_OK
, "BeginningTransction failed: %08x\n", hres
);
1566 ok(additional_headers
== NULL
, "additional_headers=%p\n", additional_headers
);
1568 SET_EXPECT(QueryService_HttpNegotiate
);
1569 hres
= IServiceProvider_QueryService(service_provider
, &IID_IHttpNegotiate2
,
1570 &IID_IHttpNegotiate2
, (void**)&http_negotiate2
);
1571 CHECK_CALLED(QueryService_HttpNegotiate
);
1572 ok(hres
== S_OK
, "QueryService failed: %08x\n", hres
);
1575 SET_EXPECT(GetRootSecurityId
);
1576 hres
= IHttpNegotiate2_GetRootSecurityId(http_negotiate2
, sec_id
, &size
, 0);
1577 CHECK_CALLED(GetRootSecurityId
);
1578 IHttpNegotiate2_Release(http_negotiate2
);
1579 ok(hres
== E_FAIL
, "GetRootSecurityId failed: %08x, expected E_FAIL\n", hres
);
1580 ok(size
== 13, "size=%d\n", size
);
1582 IServiceProvider_Release(service_provider
);
1584 CreateThread(NULL
, 0, thread_proc
, NULL
, 0, &tid
);
1588 SET_EXPECT(ReportProgress_CACHEFILENAMEAVAILABLE
);
1589 hres
= IInternetProtocolSink_ReportProgress(pOIProtSink
,
1590 BINDSTATUS_CACHEFILENAMEAVAILABLE
, expect_wsz
= emptyW
);
1591 ok(hres
== S_OK
, "ReportProgress(BINDSTATUS_CACHEFILENAMEAVAILABLE) failed: %08x\n", hres
);
1592 CHECK_CALLED(ReportProgress_CACHEFILENAMEAVAILABLE
);
1594 if(mimefilter_test
) {
1595 SET_EXPECT(MimeFilter_CreateInstance
);
1596 SET_EXPECT(MimeFilter_Start
);
1597 SET_EXPECT(ReportProgress_LOADINGMIMEHANDLER
);
1599 SET_EXPECT(ReportProgress_MIMETYPEAVAILABLE
);
1600 hres
= IInternetProtocolSink_ReportProgress(pOIProtSink
, BINDSTATUS_VERIFIEDMIMETYPEAVAILABLE
,
1601 mimefilter_test
? gzipW
: (expect_wsz
= text_htmlW
));
1603 "ReportProgress(BINDSTATUS_VERIFIEDMIMETYPEAVAILABLE) failed: %08x\n", hres
);
1604 if(mimefilter_test
) {
1605 CHECK_CALLED(MimeFilter_CreateInstance
);
1606 CHECK_CALLED(MimeFilter_Start
);
1607 CHECK_CALLED(ReportProgress_LOADINGMIMEHANDLER
);
1608 todo_wine
CHECK_CALLED(ReportProgress_MIMETYPEAVAILABLE
);
1610 CHECK_CALLED(ReportProgress_MIMETYPEAVAILABLE
);
1614 SET_EXPECT(MimeFilter_ReportData
);
1616 SET_EXPECT(ReportData
);
1617 hres
= IInternetProtocolSink_ReportData(pOIProtSink
,
1618 BSCF_FIRSTDATANOTIFICATION
| (tested_protocol
== ITS_TEST
? BSCF_DATAFULLYAVAILABLE
: BSCF_LASTDATANOTIFICATION
),
1620 ok(hres
== S_OK
, "ReportData failed: %08x\n", hres
);
1622 CHECK_CALLED(MimeFilter_ReportData
);
1624 CHECK_CALLED(ReportData
);
1626 if(tested_protocol
== ITS_TEST
) {
1627 SET_EXPECT(ReportData
);
1628 hres
= IInternetProtocolSink_ReportProgress(pOIProtSink
, BINDSTATUS_BEGINDOWNLOADDATA
, NULL
);
1629 ok(hres
== S_OK
, "ReportProgress(BINDSTATUS_BEGINDOWNLOADDATA) failed: %08x\n", hres
);
1630 CHECK_CALLED(ReportData
);
1633 if(tested_protocol
== BIND_TEST
) {
1634 hres
= IInternetProtocol_Terminate(binding_protocol
, 0);
1635 ok(hres
== E_FAIL
, "Termiante failed: %08x\n", hres
);
1639 SET_EXPECT(MimeFilter_ReportResult
);
1641 SET_EXPECT(ReportResult
);
1642 hres
= IInternetProtocolSink_ReportResult(pOIProtSink
, S_OK
, 0, NULL
);
1643 ok(hres
== S_OK
, "ReportResult failed: %08x\n", hres
);
1645 CHECK_CALLED(MimeFilter_ReportResult
);
1647 CHECK_CALLED(ReportResult
);
1650 static HRESULT WINAPI
ProtocolEmul_Start(IInternetProtocolEx
*iface
, LPCWSTR szUrl
,
1651 IInternetProtocolSink
*pOIProtSink
, IInternetBindInfo
*pOIBindInfo
,
1652 DWORD grfPI
, HANDLE_PTR dwReserved
)
1654 CHECK_EXPECT(Start
);
1656 ok(!dwReserved
, "dwReserved = %lx\n", dwReserved
);
1657 protocol_start(pOIProtSink
, pOIBindInfo
, grfPI
);
1661 static HRESULT WINAPI
ProtocolEmul_Continue(IInternetProtocolEx
*iface
,
1662 PROTOCOLDATA
*pProtocolData
)
1667 CHECK_EXPECT(Continue
);
1669 ok(pProtocolData
!= NULL
, "pProtocolData == NULL\n");
1670 if(!pProtocolData
|| tested_protocol
== BIND_TEST
)
1673 ok(pProtocolData
!= &protocoldata
, "pProtocolData == &protocoldata\n");
1674 ok(pProtocolData
->grfFlags
== protocoldata
.grfFlags
, "grfFlags wrong %x/%x\n",
1675 pProtocolData
->grfFlags
, protocoldata
.grfFlags
);
1676 ok(pProtocolData
->dwState
== protocoldata
.dwState
, "dwState wrong %x/%x\n",
1677 pProtocolData
->dwState
, protocoldata
.dwState
);
1678 ok(pProtocolData
->pData
== protocoldata
.pData
, "pData wrong %p/%p\n",
1679 pProtocolData
->pData
, protocoldata
.pData
);
1680 ok(pProtocolData
->cbData
== protocoldata
.cbData
, "cbData wrong %x/%x\n",
1681 pProtocolData
->cbData
, protocoldata
.cbData
);
1684 switch(prot_state
) {
1686 IServiceProvider
*service_provider
;
1687 IHttpNegotiate
*http_negotiate
;
1688 static WCHAR header
[] = {'?',0};
1690 hres
= IInternetProtocolSink_QueryInterface(binding_sink
, &IID_IServiceProvider
,
1691 (void**)&service_provider
);
1692 ok(hres
== S_OK
, "Could not get IServiceProvicder\n");
1694 SET_EXPECT(QueryService_HttpNegotiate
);
1695 hres
= IServiceProvider_QueryService(service_provider
, &IID_IHttpNegotiate
,
1696 &IID_IHttpNegotiate
, (void**)&http_negotiate
);
1697 IServiceProvider_Release(service_provider
);
1698 CHECK_CALLED(QueryService_HttpNegotiate
);
1699 ok(hres
== S_OK
, "Could not get IHttpNegotiate\n");
1701 SET_EXPECT(OnResponse
);
1702 hres
= IHttpNegotiate_OnResponse(http_negotiate
, 200, header
, NULL
, NULL
);
1703 IHttpNegotiate_Release(http_negotiate
);
1704 CHECK_CALLED(OnResponse
);
1705 IHttpNegotiate_Release(http_negotiate
);
1706 ok(hres
== S_OK
, "OnResponse failed: %08x\n", hres
);
1708 if(mimefilter_test
) {
1709 SET_EXPECT(MimeFilter_CreateInstance
);
1710 SET_EXPECT(MimeFilter_Start
);
1711 SET_EXPECT(ReportProgress_LOADINGMIMEHANDLER
);
1712 }else if(!(pi
& PI_MIMEVERIFICATION
)) {
1713 SET_EXPECT(ReportProgress_MIMETYPEAVAILABLE
);
1715 hres
= IInternetProtocolSink_ReportProgress(binding_sink
,
1716 BINDSTATUS_MIMETYPEAVAILABLE
, mimefilter_test
? gzipW
: text_htmlW
);
1717 if(mimefilter_test
) {
1718 CHECK_CALLED(MimeFilter_CreateInstance
);
1719 CHECK_CALLED(MimeFilter_Start
);
1720 CHECK_CALLED(ReportProgress_LOADINGMIMEHANDLER
);
1721 }else if(!(pi
& PI_MIMEVERIFICATION
)) {
1722 CHECK_CALLED(ReportProgress_MIMETYPEAVAILABLE
);
1725 "ReportProgress(BINDSTATUS_MIMETYPEAVAILABLE) failed: %08x\n", hres
);
1727 bscf
|= BSCF_FIRSTDATANOTIFICATION
;
1732 bscf
= BSCF_INTERMEDIATEDATANOTIFICATION
;
1737 if(mimefilter_test
) {
1738 SET_EXPECT(MimeFilter_ReportData
);
1739 }else if(pi
& PI_MIMEVERIFICATION
) {
1741 SET_EXPECT(Read
); /* checked in ReportData for short_read */
1743 if(!mimefilter_test
)
1744 SET_EXPECT(Read
); /* checked in BINDSTATUS_MIMETYPEAVAILABLE or ReportData */
1745 SET_EXPECT(ReportProgress_MIMETYPEAVAILABLE
);
1748 SET_EXPECT(ReportData
);
1750 SET_EXPECT(ReportData
);
1753 hres
= IInternetProtocolSink_ReportData(binding_sink
, bscf
, pr
, 400);
1754 ok(hres
== S_OK
, "ReportData failed: %08x\n", hres
);
1756 if(mimefilter_test
) {
1757 SET_EXPECT(MimeFilter_ReportData
);
1758 }else if(pi
& PI_MIMEVERIFICATION
) {
1759 if(!short_read
&& pr
< 200)
1762 CHECK_CALLED(ReportProgress_MIMETYPEAVAILABLE
);
1765 CHECK_CALLED(ReportData
);
1774 static HRESULT WINAPI
ProtocolEmul_Terminate(IInternetProtocolEx
*iface
, DWORD dwOptions
)
1776 CHECK_EXPECT(Terminate
);
1777 ok(!dwOptions
, "dwOptions=%d\n", dwOptions
);
1781 static HRESULT WINAPI
ProtocolEmul_Read(IInternetProtocolEx
*iface
, void *pv
,
1782 ULONG cb
, ULONG
*pcbRead
)
1784 if(read_report_data
)
1785 CHECK_EXPECT2(Read2
);
1787 if(mimefilter_test
|| short_read
) {
1788 if(!read_report_data
)
1789 CHECK_EXPECT2(Read
);
1790 }else if((pi
& PI_MIMEVERIFICATION
)) {
1791 if(!read_report_data
)
1792 CHECK_EXPECT2(Read
);
1794 if(prot_read
< 300) {
1795 ok(pv
!= expect_pv
, "pv == expect_pv\n");
1797 ok(cb
== 2048-prot_read
, "cb=%d\n", cb
);
1799 ok(cb
== 700, "cb=%d\n", cb
);
1801 ok(expect_pv
<= pv
&& (BYTE
*)pv
< (BYTE
*)expect_pv
+ cb
, "pv != expect_pv\n");
1804 if(!read_report_data
)
1807 ok(pv
== expect_pv
, "pv != expect_pv\n");
1808 ok(cb
== 1000, "cb=%d\n", cb
);
1809 ok(!*pcbRead
, "*pcbRead = %d\n", *pcbRead
);
1811 ok(pcbRead
!= NULL
, "pcbRead == NULL\n");
1813 if(prot_state
== 3 || (short_read
&& prot_state
!= 4)) {
1818 SET_EXPECT(Read2
); /* checked in BINDSTATUS_MIMETYPEAVAILABLE */
1819 SET_EXPECT(ReportProgress_MIMETYPEAVAILABLE
);
1822 SET_EXPECT(MimeFilter_ReportData
);
1823 else if(direct_read
)
1824 SET_EXPECT(ReportData2
);
1826 hres
= IInternetProtocolSink_ReportData(binding_sink
,
1827 BSCF_LASTDATANOTIFICATION
|BSCF_INTERMEDIATEDATANOTIFICATION
, 0, 0);
1829 ok(hres
== S_OK
, "ReportData failed: %08x\n", hres
);
1831 CHECK_CALLED(ReportProgress_MIMETYPEAVAILABLE
);
1833 CHECK_CALLED(MimeFilter_ReportData
);
1834 else if(direct_read
)
1835 CHECK_CALLED(ReportData2
);
1838 SET_EXPECT(MimeFilter_ReportResult
);
1840 SET_EXPECT(ReportResult
);
1841 hres
= IInternetProtocolSink_ReportResult(binding_sink
, S_OK
, ERROR_SUCCESS
, NULL
);
1842 ok(hres
== S_OK
, "ReportResult failed: %08x\n", hres
);
1844 CHECK_CALLED(MimeFilter_ReportResult
);
1846 CHECK_CALLED(ReportResult
);
1848 memset(pv
, 'x', 100);
1849 prot_read
+= *pcbRead
= 100;
1851 }if(prot_state
== 4) {
1856 if((async_read_pending
= !async_read_pending
)) {
1858 return tested_protocol
== HTTP_TEST
|| tested_protocol
== HTTPS_TEST
? E_PENDING
: S_FALSE
;
1861 memset(pv
, 'x', 100);
1862 prot_read
+= *pcbRead
= 100;
1866 static HRESULT WINAPI
ProtocolEmul_LockRequest(IInternetProtocolEx
*iface
, DWORD dwOptions
)
1868 CHECK_EXPECT(LockRequest
);
1869 ok(dwOptions
== 0, "dwOptions=%x\n", dwOptions
);
1873 static HRESULT WINAPI
ProtocolEmul_UnlockRequest(IInternetProtocolEx
*iface
)
1875 CHECK_EXPECT(UnlockRequest
);
1879 static HRESULT WINAPI
ProtocolEmul_StartEx(IInternetProtocolEx
*iface
, IUri
*pUri
,
1880 IInternetProtocolSink
*pOIProtSink
, IInternetBindInfo
*pOIBindInfo
,
1881 DWORD grfPI
, HANDLE
*dwReserved
)
1883 CHECK_EXPECT(StartEx
);
1884 ok(!dwReserved
, "dwReserved = %p\n", dwReserved
);
1885 protocol_start(pOIProtSink
, pOIBindInfo
, grfPI
);
1889 static const IInternetProtocolExVtbl ProtocolVtbl
= {
1890 ProtocolEmul_QueryInterface
,
1894 ProtocolEmul_Continue
,
1896 ProtocolEmul_Terminate
,
1901 ProtocolEmul_LockRequest
,
1902 ProtocolEmul_UnlockRequest
,
1903 ProtocolEmul_StartEx
1906 static IInternetProtocolEx Protocol
= { &ProtocolVtbl
};
1908 static HRESULT WINAPI
MimeProtocol_QueryInterface(IInternetProtocolEx
*iface
, REFIID riid
, void **ppv
)
1910 if(IsEqualGUID(&IID_IUnknown
, riid
) || IsEqualGUID(&IID_IInternetProtocol
, riid
)) {
1915 if(IsEqualGUID(&IID_IInternetProtocolSink
, riid
)) {
1916 *ppv
= &mime_protocol_sink
;
1920 ok(0, "unexpected riid %s\n", debugstr_guid(riid
));
1922 return E_NOINTERFACE
;
1925 static HRESULT WINAPI
MimeProtocol_Start(IInternetProtocolEx
*iface
, LPCWSTR szUrl
,
1926 IInternetProtocolSink
*pOIProtSink
, IInternetBindInfo
*pOIBindInfo
,
1927 DWORD grfPI
, HANDLE_PTR dwReserved
)
1929 PROTOCOLFILTERDATA
*data
;
1930 LPOLESTR url_str
= NULL
;
1936 CHECK_EXPECT(MimeFilter_Start
);
1938 ok(!lstrcmpW(szUrl
, gzipW
), "wrong url %s\n", wine_dbgstr_w(szUrl
));
1939 ok(grfPI
== (PI_FILTER_MODE
|PI_FORCE_ASYNC
), "grfPI=%x, expected PI_FILTER_MODE|PI_FORCE_ASYNC\n", grfPI
);
1940 ok(dwReserved
, "dwReserved == 0\n");
1941 ok(pOIProtSink
!= NULL
, "pOIProtSink == NULL\n");
1942 ok(pOIBindInfo
!= NULL
, "pOIBindInfo == NULL\n");
1945 ok(pOIProtSink
!= binding_sink
, "pOIProtSink == protocol_sink\n");
1946 ok(pOIBindInfo
== prot_bind_info
, "pOIBindInfo != bind_info\n");
1948 ok(pOIProtSink
== &protocol_sink
, "pOIProtSink != protocol_sink\n");
1949 ok(pOIBindInfo
== &bind_info
, "pOIBindInfo != bind_info\n");
1952 data
= (void*)dwReserved
;
1953 ok(data
->cbSize
== sizeof(*data
), "data->cbSize = %d\n", data
->cbSize
);
1954 ok(!data
->pProtocolSink
, "data->pProtocolSink != NULL\n");
1955 ok(data
->pProtocol
!= NULL
, "data->pProtocol == NULL\n");
1956 ok(!data
->pUnk
, "data->pUnk != NULL\n");
1957 ok(!data
->dwFilterFlags
, "data->dwProtocolFlags = %x\n", data
->dwFilterFlags
);
1959 IInternetProtocolSink
*prot_sink
;
1961 IInternetProtocol_QueryInterface(data
->pProtocol
, &IID_IInternetProtocolSink
, (void**)&prot_sink
);
1962 ok(prot_sink
== pOIProtSink
, "QI(data->pProtocol, IID_IInternetProtocolSink) != pOIProtSink\n");
1963 IInternetProtocolSink_Release(prot_sink
);
1965 ok(data
->pProtocol
!= binding_protocol
, "data->pProtocol == binding_protocol\n");
1967 filtered_protocol
= data
->pProtocol
;
1968 IInternetProtocol_AddRef(filtered_protocol
);
1970 IInternetProtocol
*prot
;
1972 IInternetProtocol_QueryInterface(data
->pProtocol
, &IID_IInternetProtocol
, (void**)&prot
);
1973 ok(prot
== async_protocol
, "QI(data->pProtocol, IID_IInternetProtocol) != async_protocol\n");
1974 IInternetProtocol_Release(prot
);
1976 ok(data
->pProtocol
!= async_protocol
, "data->pProtocol == async_protocol\n");
1979 filtered_sink
= pOIProtSink
;
1981 SET_EXPECT(ReportProgress_DECODING
);
1982 hres
= IInternetProtocolSink_ReportProgress(pOIProtSink
, BINDSTATUS_DECODING
, gzipW
);
1983 ok(hres
== S_OK
, "ReportProgress(BINDSTATUS_DECODING) failed: %08x\n", hres
);
1984 CHECK_CALLED(ReportProgress_DECODING
);
1986 SET_EXPECT(GetBindInfo
);
1987 memset(&bindinfo
, 0, sizeof(bindinfo
));
1988 bindinfo
.cbSize
= sizeof(bindinfo
);
1989 hres
= IInternetBindInfo_GetBindInfo(pOIBindInfo
, &cbindf
, &bindinfo
);
1990 ok(hres
== S_OK
, "GetBindInfo failed: %08x\n", hres
);
1991 ok(cbindf
== (bindf
|BINDF_FROMURLMON
), "cbindf = %x, expected %x\n", cbindf
, bindf
);
1992 CHECK_CALLED(GetBindInfo
);
1994 SET_EXPECT(GetBindString_URL
);
1995 hres
= IInternetBindInfo_GetBindString(pOIBindInfo
, BINDSTRING_URL
, &url_str
, 1, &fetched
);
1996 ok(hres
== S_OK
, "GetBindString(BINDSTRING_URL) failed: %08x\n", hres
);
1997 ok(fetched
== 1, "fetched = %d\n", fetched
);
1998 ok(!lstrcmpW(url_str
, binding_urls
[tested_protocol
]), "wrong url_str %s\n", wine_dbgstr_w(url_str
));
1999 CoTaskMemFree(url_str
);
2000 CHECK_CALLED(GetBindString_URL
);
2005 static HRESULT WINAPI
Protocol_Continue(IInternetProtocolEx
*iface
,
2006 PROTOCOLDATA
*pProtocolData
)
2008 CHECK_EXPECT(MimeFilter_Continue
);
2012 static HRESULT WINAPI
MimeProtocol_Terminate(IInternetProtocolEx
*iface
, DWORD dwOptions
)
2016 CHECK_EXPECT(MimeFilter_Terminate
);
2018 ok(!dwOptions
, "dwOptions = %x\n", dwOptions
);
2020 SET_EXPECT(Terminate
);
2021 hres
= IInternetProtocol_Terminate(filtered_protocol
, dwOptions
);
2022 ok(hres
== S_OK
, "Terminate failed: %08x\n", hres
);
2023 CHECK_CALLED(Terminate
);
2028 static HRESULT WINAPI
MimeProtocol_Read(IInternetProtocolEx
*iface
, void *pv
,
2029 ULONG cb
, ULONG
*pcbRead
)
2035 CHECK_EXPECT(MimeFilter_Read
);
2037 ok(pv
!= NULL
, "pv == NULL\n");
2038 ok(cb
!= 0, "cb == 0\n");
2039 ok(pcbRead
!= NULL
, "pcbRead == NULL\n");
2041 if(read_report_data
)
2045 hres
= IInternetProtocol_Read(filtered_protocol
, buf
, sizeof(buf
), &read
);
2046 ok(hres
== S_OK
|| hres
== S_FALSE
|| hres
== E_PENDING
, "Read failed: %08x\n", hres
);
2047 if(read_report_data
)
2048 CHECK_CALLED(Read2
);
2053 ok(*pcbRead
== 0, "*pcbRead=%d, expected 0\n", *pcbRead
);
2057 memset(pv
, 'x', read
);
2061 static HRESULT WINAPI
MimeProtocol_LockRequest(IInternetProtocolEx
*iface
, DWORD dwOptions
)
2065 CHECK_EXPECT(MimeFilter_LockRequest
);
2067 ok(!dwOptions
, "dwOptions = %x\n", dwOptions
);
2069 SET_EXPECT(LockRequest
);
2070 hres
= IInternetProtocol_LockRequest(filtered_protocol
, dwOptions
);
2071 ok(hres
== S_OK
, "LockRequest failed: %08x\n", hres
);
2072 CHECK_CALLED(LockRequest
);
2077 static HRESULT WINAPI
MimeProtocol_UnlockRequest(IInternetProtocolEx
*iface
)
2081 CHECK_EXPECT(MimeFilter_UnlockRequest
);
2083 SET_EXPECT(UnlockRequest
);
2084 hres
= IInternetProtocol_UnlockRequest(filtered_protocol
);
2085 ok(hres
== S_OK
, "UnlockRequest failed: %08x\n", hres
);
2086 CHECK_CALLED(UnlockRequest
);
2091 static const IInternetProtocolExVtbl MimeProtocolVtbl
= {
2092 MimeProtocol_QueryInterface
,
2098 MimeProtocol_Terminate
,
2103 MimeProtocol_LockRequest
,
2104 MimeProtocol_UnlockRequest
2107 static IInternetProtocolEx MimeProtocol
= { &MimeProtocolVtbl
};
2109 static HRESULT WINAPI
ClassFactory_QueryInterface(IClassFactory
*iface
, REFIID riid
, void **ppv
)
2111 ok(0, "unexpected call\n");
2112 return E_NOINTERFACE
;
2115 static ULONG WINAPI
ClassFactory_AddRef(IClassFactory
*iface
)
2120 static ULONG WINAPI
ClassFactory_Release(IClassFactory
*iface
)
2125 static HRESULT WINAPI
ClassFactory_CreateInstance(IClassFactory
*iface
, IUnknown
*pOuter
,
2126 REFIID riid
, void **ppv
)
2128 CHECK_EXPECT(CreateInstance
);
2130 ok(pOuter
== (IUnknown
*)prot_bind_info
, "pOuter != protocol_unk\n");
2131 ok(IsEqualGUID(&IID_IUnknown
, riid
), "unexpected riid %s\n", debugstr_guid(riid
));
2132 ok(ppv
!= NULL
, "ppv == NULL\n");
2138 static HRESULT WINAPI
ClassFactory_LockServer(IClassFactory
*iface
, BOOL dolock
)
2140 ok(0, "unexpected call\n");
2144 static const IClassFactoryVtbl ClassFactoryVtbl
= {
2145 ClassFactory_QueryInterface
,
2146 ClassFactory_AddRef
,
2147 ClassFactory_Release
,
2148 ClassFactory_CreateInstance
,
2149 ClassFactory_LockServer
2152 static IClassFactory ClassFactory
= { &ClassFactoryVtbl
};
2154 static HRESULT WINAPI
MimeFilter_CreateInstance(IClassFactory
*iface
, IUnknown
*outer
, REFIID riid
, void **ppv
)
2156 CHECK_EXPECT(MimeFilter_CreateInstance
);
2158 ok(!outer
, "outer = %p\n", outer
);
2159 ok(IsEqualGUID(&IID_IInternetProtocol
, riid
), "unexpected riid %s\n", debugstr_guid(riid
));
2161 *ppv
= &MimeProtocol
;
2165 static const IClassFactoryVtbl MimeFilterCFVtbl
= {
2166 ClassFactory_QueryInterface
,
2167 ClassFactory_AddRef
,
2168 ClassFactory_Release
,
2169 MimeFilter_CreateInstance
,
2170 ClassFactory_LockServer
2173 static IClassFactory mimefilter_cf
= { &MimeFilterCFVtbl
};
2175 #define TEST_BINDING 0x0001
2176 #define TEST_FILTER 0x0002
2177 #define TEST_FIRST_HTTP 0x0004
2178 #define TEST_DIRECT_READ 0x0008
2179 #define TEST_POST 0x0010
2180 #define TEST_EMULATEPROT 0x0020
2181 #define TEST_SHORT_READ 0x0040
2182 #define TEST_REDIRECT 0x0080
2183 #define TEST_ABORT 0x0100
2184 #define TEST_ASYNCREQ 0x0200
2185 #define TEST_USEIURI 0x0400
2186 #define TEST_IMPLPROTEX 0x0800
2187 #define TEST_EMPTY 0x1000
2189 static void register_filter(BOOL do_register
)
2191 IInternetSession
*session
;
2194 static const WCHAR gzipW
[] = {'g','z','i','p',0};
2196 hres
= pCoInternetGetSession(0, &session
, 0);
2197 ok(hres
== S_OK
, "CoInternetGetSession failed: %08x\n", hres
);
2200 hres
= IInternetSession_RegisterMimeFilter(session
, &mimefilter_cf
, &IID_IInternetProtocol
, gzipW
);
2201 ok(hres
== S_OK
, "RegisterMimeFilter failed: %08x\n", hres
);
2203 hres
= IInternetSession_UnregisterMimeFilter(session
, &mimefilter_cf
, gzipW
);
2204 ok(hres
== S_OK
, "RegisterMimeFilter failed: %08x\n", hres
);
2207 IInternetSession_Release(session
);
2210 static void init_test(int prot
, DWORD flags
)
2212 tested_protocol
= prot
;
2213 binding_test
= (flags
& TEST_BINDING
) != 0;
2214 first_data_notif
= TRUE
;
2217 async_read_pending
= TRUE
;
2218 mimefilter_test
= (flags
& TEST_FILTER
) != 0;
2220 post_stream_read
= 0;
2221 ResetEvent(event_complete
);
2222 ResetEvent(event_complete2
);
2223 ResetEvent(event_continue
);
2224 ResetEvent(event_continue_done
);
2225 async_protocol
= binding_protocol
= filtered_protocol
= NULL
;
2226 filtered_sink
= NULL
;
2227 http_is_first
= (flags
& TEST_FIRST_HTTP
) != 0;
2228 first_data_notif
= TRUE
;
2229 state
= STATE_CONNECTING
;
2230 test_async_req
= (flags
& TEST_ASYNCREQ
) != 0;
2231 direct_read
= (flags
& TEST_DIRECT_READ
) != 0;
2232 emulate_prot
= (flags
& TEST_EMULATEPROT
) != 0;
2233 wait_for_switch
= TRUE
;
2234 short_read
= (flags
& TEST_SHORT_READ
) != 0;
2235 http_post_test
= TYMED_NULL
;
2236 test_redirect
= (flags
& TEST_REDIRECT
) != 0;
2237 test_abort
= (flags
& TEST_ABORT
) != 0;
2238 impl_protex
= (flags
& TEST_IMPLPROTEX
) != 0;
2239 empty_file
= (flags
& TEST_EMPTY
) != 0;
2241 register_filter(mimefilter_test
);
2244 static void test_priority(IInternetProtocol
*protocol
)
2246 IInternetPriority
*priority
;
2250 hres
= IInternetProtocol_QueryInterface(protocol
, &IID_IInternetPriority
,
2252 ok(hres
== S_OK
, "QueryInterface(IID_IInternetPriority) failed: %08x\n", hres
);
2256 hres
= IInternetPriority_GetPriority(priority
, &pr
);
2257 ok(hres
== S_OK
, "GetPriority failed: %08x\n", hres
);
2258 ok(pr
== 0, "pr=%d, expected 0\n", pr
);
2260 hres
= IInternetPriority_SetPriority(priority
, 1);
2261 ok(hres
== S_OK
, "SetPriority failed: %08x\n", hres
);
2263 hres
= IInternetPriority_GetPriority(priority
, &pr
);
2264 ok(hres
== S_OK
, "GetPriority failed: %08x\n", hres
);
2265 ok(pr
== 1, "pr=%d, expected 1\n", pr
);
2267 IInternetPriority_Release(priority
);
2270 static void test_early_abort(const CLSID
*clsid
)
2272 IInternetProtocol
*protocol
;
2275 hres
= CoCreateInstance(clsid
, NULL
, CLSCTX_INPROC_SERVER
|CLSCTX_INPROC_HANDLER
,
2276 &IID_IInternetProtocol
, (void**)&protocol
);
2277 ok(hres
== S_OK
, "CoCreateInstance failed: %08x\n", hres
);
2279 hres
= IInternetProtocol_Abort(protocol
, E_ABORT
, 0);
2280 ok(hres
== S_OK
, "Abort failed: %08x\n", hres
);
2282 hres
= IInternetProtocol_Abort(protocol
, E_FAIL
, 0);
2283 ok(hres
== S_OK
, "Abort failed: %08x\n", hres
);
2285 IInternetProtocol_Release(protocol
);
2288 static BOOL
file_protocol_start(IInternetProtocol
*protocol
, LPCWSTR url
,
2289 IInternetProtocolEx
*protocolex
, IUri
*uri
, BOOL is_first
)
2293 SET_EXPECT(GetBindInfo
);
2294 if(!(bindf
& BINDF_FROMURLMON
))
2295 SET_EXPECT(ReportProgress_DIRECTBIND
);
2297 SET_EXPECT(ReportProgress_SENDINGREQUEST
);
2298 SET_EXPECT(ReportProgress_CACHEFILENAMEAVAILABLE
);
2299 if(bindf
& BINDF_FROMURLMON
)
2300 SET_EXPECT(ReportProgress_VERIFIEDMIMETYPEAVAILABLE
);
2302 SET_EXPECT(ReportProgress_MIMETYPEAVAILABLE
);
2304 SET_EXPECT(ReportData
);
2306 SET_EXPECT(ReportResult
);
2308 expect_hrResult
= S_OK
;
2311 hres
= IInternetProtocolEx_StartEx(protocolex
, uri
, &protocol_sink
, &bind_info
, 0, 0);
2312 ok(hres
== S_OK
, "StartEx failed: %08x\n", hres
);
2314 hres
= IInternetProtocol_Start(protocol
, url
, &protocol_sink
, &bind_info
, 0, 0);
2315 if(hres
== INET_E_RESOURCE_NOT_FOUND
) {
2316 win_skip("Start failed\n");
2319 ok(hres
== S_OK
, "Start failed: %08x\n", hres
);
2322 CHECK_CALLED(GetBindInfo
);
2323 if(!(bindf
& BINDF_FROMURLMON
))
2324 CHECK_CALLED(ReportProgress_DIRECTBIND
);
2326 CHECK_CALLED(ReportProgress_SENDINGREQUEST
);
2327 CHECK_CALLED(ReportProgress_CACHEFILENAMEAVAILABLE
);
2328 if(bindf
& BINDF_FROMURLMON
)
2329 CHECK_CALLED(ReportProgress_VERIFIEDMIMETYPEAVAILABLE
);
2331 CHECK_CALLED(ReportProgress_MIMETYPEAVAILABLE
);
2333 CHECK_CALLED(ReportData
);
2335 CHECK_CALLED(ReportResult
);
2340 static void test_file_protocol_url(LPCWSTR url
)
2342 IInternetProtocolInfo
*protocol_info
;
2344 IClassFactory
*factory
;
2345 IInternetProtocol
*protocol
;
2350 hres
= CoGetClassObject(&CLSID_FileProtocol
, CLSCTX_INPROC_SERVER
, NULL
,
2351 &IID_IUnknown
, (void**)&unk
);
2352 ok(hres
== S_OK
, "CoGetClassObject failed: %08x\n", hres
);
2356 hres
= IUnknown_QueryInterface(unk
, &IID_IInternetProtocolInfo
, (void**)&protocol_info
);
2357 ok(hres
== E_NOINTERFACE
,
2358 "Could not get IInternetProtocolInfo interface: %08x, expected E_NOINTERFACE\n", hres
);
2360 hres
= IUnknown_QueryInterface(unk
, &IID_IClassFactory
, (void**)&factory
);
2361 ok(hres
== S_OK
, "Could not get IClassFactory interface\n");
2362 IUnknown_Release(unk
);
2366 hres
= IClassFactory_CreateInstance(factory
, NULL
, &IID_IInternetProtocol
, (void**)&protocol
);
2367 ok(hres
== S_OK
, "Could not get IInternetProtocol: %08x\n", hres
);
2369 if(SUCCEEDED(hres
)) {
2370 if(file_protocol_start(protocol
, url
, NULL
, NULL
, TRUE
)) {
2371 hres
= IInternetProtocol_Read(protocol
, buf
, 2, &cb
);
2372 ok(hres
== S_OK
, "Read failed: %08x\n", hres
);
2373 ok(cb
== 2, "cb=%u expected 2\n", cb
);
2374 hres
= IInternetProtocol_Read(protocol
, buf
, sizeof(buf
), &cb
);
2375 ok(hres
== S_FALSE
, "Read failed: %08x\n", hres
);
2376 hres
= IInternetProtocol_Read(protocol
, buf
, sizeof(buf
), &cb
);
2377 ok(hres
== S_FALSE
, "Read failed: %08x expected S_FALSE\n", hres
);
2378 ok(cb
== 0, "cb=%u expected 0\n", cb
);
2379 hres
= IInternetProtocol_UnlockRequest(protocol
);
2380 ok(hres
== S_OK
, "UnlockRequest failed: %08x\n", hres
);
2383 if(file_protocol_start(protocol
, url
, NULL
, NULL
, FALSE
)) {
2384 hres
= IInternetProtocol_Read(protocol
, buf
, 2, &cb
);
2385 ok(hres
== S_FALSE
, "Read failed: %08x\n", hres
);
2386 hres
= IInternetProtocol_LockRequest(protocol
, 0);
2387 ok(hres
== S_OK
, "LockRequest failed: %08x\n", hres
);
2388 hres
= IInternetProtocol_UnlockRequest(protocol
);
2389 ok(hres
== S_OK
, "UnlockRequest failed: %08x\n", hres
);
2392 IInternetProtocol_Release(protocol
);
2395 hres
= IClassFactory_CreateInstance(factory
, NULL
, &IID_IInternetProtocol
, (void**)&protocol
);
2396 ok(hres
== S_OK
, "Could not get IInternetProtocol: %08x\n", hres
);
2397 if(SUCCEEDED(hres
)) {
2398 if(file_protocol_start(protocol
, url
, NULL
, NULL
, TRUE
)) {
2399 hres
= IInternetProtocol_LockRequest(protocol
, 0);
2400 ok(hres
== S_OK
, "LockRequest failed: %08x\n", hres
);
2401 hres
= IInternetProtocol_Terminate(protocol
, 0);
2402 ok(hres
== S_OK
, "Terminate failed: %08x\n", hres
);
2403 hres
= IInternetProtocol_Read(protocol
, buf
, 2, &cb
);
2404 ok(hres
== S_OK
, "Read failed: %08x\n\n", hres
);
2405 hres
= IInternetProtocol_UnlockRequest(protocol
);
2406 ok(hres
== S_OK
, "UnlockRequest failed: %08x\n", hres
);
2407 hres
= IInternetProtocol_Read(protocol
, buf
, 2, &cb
);
2408 ok(hres
== S_OK
, "Read failed: %08x\n", hres
);
2409 hres
= IInternetProtocol_Terminate(protocol
, 0);
2410 ok(hres
== S_OK
, "Terminate failed: %08x\n", hres
);
2413 IInternetProtocol_Release(protocol
);
2416 hres
= IClassFactory_CreateInstance(factory
, NULL
, &IID_IInternetProtocol
, (void**)&protocol
);
2417 ok(hres
== S_OK
, "Could not get IInternetProtocol: %08x\n", hres
);
2418 if(SUCCEEDED(hres
)) {
2419 if(file_protocol_start(protocol
, url
, NULL
, NULL
, TRUE
)) {
2420 hres
= IInternetProtocol_Terminate(protocol
, 0);
2421 ok(hres
== S_OK
, "Terminate failed: %08x\n", hres
);
2422 hres
= IInternetProtocol_Read(protocol
, buf
, 2, &cb
);
2423 ok(hres
== S_OK
, "Read failed: %08x\n", hres
);
2424 ok(cb
== 2, "cb=%u expected 2\n", cb
);
2427 IInternetProtocol_Release(protocol
);
2431 IInternetProtocolEx
*protocolex
;
2434 hres
= pCreateUri(url
, Uri_CREATE_FILE_USE_DOS_PATH
, 0, &uri
);
2435 ok(hres
== S_OK
, "CreateUri failed: %08x\n", hres
);
2437 hres
= IClassFactory_CreateInstance(factory
, NULL
, &IID_IInternetProtocolEx
, (void**)&protocolex
);
2438 ok(hres
== S_OK
, "Could not get IInternetProtocolEx: %08x\n", hres
);
2440 if(file_protocol_start(NULL
, NULL
, protocolex
, uri
, TRUE
)) {
2441 hres
= IInternetProtocolEx_Read(protocolex
, buf
, 2, &cb
);
2442 ok(hres
== S_OK
, "Read failed: %08x\n", hres
);
2443 hres
= IInternetProtocolEx_LockRequest(protocolex
, 0);
2444 ok(hres
== S_OK
, "LockRequest failed: %08x\n", hres
);
2445 hres
= IInternetProtocolEx_UnlockRequest(protocolex
);
2446 ok(hres
== S_OK
, "UnlockRequest failed: %08x\n", hres
);
2450 IInternetProtocolEx_Release(protocolex
);
2452 hres
= pCreateUri(url
, 0, 0, &uri
);
2453 ok(hres
== S_OK
, "CreateUri failed: %08x\n", hres
);
2455 hres
= IClassFactory_CreateInstance(factory
, NULL
, &IID_IInternetProtocolEx
, (void**)&protocolex
);
2456 ok(hres
== S_OK
, "Could not get IInternetProtocolEx: %08x\n", hres
);
2458 if(file_protocol_start(NULL
, NULL
, protocolex
, uri
, TRUE
)) {
2459 hres
= IInternetProtocolEx_Read(protocolex
, buf
, 2, &cb
);
2460 ok(hres
== S_OK
, "Read failed: %08x\n", hres
);
2461 hres
= IInternetProtocolEx_LockRequest(protocolex
, 0);
2462 ok(hres
== S_OK
, "LockRequest failed: %08x\n", hres
);
2463 hres
= IInternetProtocolEx_UnlockRequest(protocolex
);
2464 ok(hres
== S_OK
, "UnlockRequest failed: %08x\n", hres
);
2468 IInternetProtocolEx_Release(protocolex
);
2470 win_skip("Skipping file protocol StartEx tests\n");
2473 IClassFactory_Release(factory
);
2476 static void test_file_protocol_fail(void)
2478 IInternetProtocol
*protocol
;
2481 static const WCHAR index_url2
[] =
2482 {'f','i','l','e',':','/','/','i','n','d','e','x','.','h','t','m','l',0};
2484 hres
= CoCreateInstance(&CLSID_FileProtocol
, NULL
, CLSCTX_INPROC_SERVER
|CLSCTX_INPROC_HANDLER
,
2485 &IID_IInternetProtocol
, (void**)&protocol
);
2486 ok(hres
== S_OK
, "CoCreateInstance failed: %08x\n", hres
);
2490 SET_EXPECT(GetBindInfo
);
2491 expect_hrResult
= MK_E_SYNTAX
;
2492 hres
= IInternetProtocol_Start(protocol
, wszIndexHtml
, &protocol_sink
, &bind_info
, 0, 0);
2493 ok(hres
== MK_E_SYNTAX
||
2494 hres
== E_INVALIDARG
,
2495 "Start failed: %08x, expected MK_E_SYNTAX or E_INVALIDARG\n", hres
);
2496 CLEAR_CALLED(GetBindInfo
); /* GetBindInfo not called in IE7 */
2498 SET_EXPECT(GetBindInfo
);
2499 if(!(bindf
& BINDF_FROMURLMON
))
2500 SET_EXPECT(ReportProgress_DIRECTBIND
);
2501 SET_EXPECT(ReportProgress_SENDINGREQUEST
);
2502 SET_EXPECT(ReportResult
);
2503 expect_hrResult
= INET_E_RESOURCE_NOT_FOUND
;
2504 hres
= IInternetProtocol_Start(protocol
, index_url
, &protocol_sink
, &bind_info
, 0, 0);
2505 ok(hres
== INET_E_RESOURCE_NOT_FOUND
,
2506 "Start failed: %08x expected INET_E_RESOURCE_NOT_FOUND\n", hres
);
2507 CHECK_CALLED(GetBindInfo
);
2508 if(!(bindf
& BINDF_FROMURLMON
))
2509 CHECK_CALLED(ReportProgress_DIRECTBIND
);
2510 CHECK_CALLED(ReportProgress_SENDINGREQUEST
);
2511 CHECK_CALLED(ReportResult
);
2513 IInternetProtocol_Release(protocol
);
2515 hres
= CoCreateInstance(&CLSID_FileProtocol
, NULL
, CLSCTX_INPROC_SERVER
|CLSCTX_INPROC_HANDLER
,
2516 &IID_IInternetProtocol
, (void**)&protocol
);
2517 ok(hres
== S_OK
, "CoCreateInstance failed: %08x\n", hres
);
2521 SET_EXPECT(GetBindInfo
);
2522 if(!(bindf
& BINDF_FROMURLMON
))
2523 SET_EXPECT(ReportProgress_DIRECTBIND
);
2524 SET_EXPECT(ReportProgress_SENDINGREQUEST
);
2525 SET_EXPECT(ReportResult
);
2526 expect_hrResult
= INET_E_RESOURCE_NOT_FOUND
;
2528 hres
= IInternetProtocol_Start(protocol
, index_url2
, &protocol_sink
, &bind_info
, 0, 0);
2529 ok(hres
== INET_E_RESOURCE_NOT_FOUND
,
2530 "Start failed: %08x, expected INET_E_RESOURCE_NOT_FOUND\n", hres
);
2531 CHECK_CALLED(GetBindInfo
);
2532 if(!(bindf
& BINDF_FROMURLMON
))
2533 CHECK_CALLED(ReportProgress_DIRECTBIND
);
2534 CHECK_CALLED(ReportProgress_SENDINGREQUEST
);
2535 CHECK_CALLED(ReportResult
);
2537 SET_EXPECT(GetBindInfo
);
2538 hres
= IInternetProtocol_Start(protocol
, NULL
, &protocol_sink
, &bind_info
, 0, 0);
2539 ok(hres
== E_INVALIDARG
, "Start failed: %08x, expected E_INVALIDARG\n", hres
);
2540 CLEAR_CALLED(GetBindInfo
); /* GetBindInfo not called in IE7 */
2542 SET_EXPECT(GetBindInfo
);
2543 hres
= IInternetProtocol_Start(protocol
, emptyW
, &protocol_sink
, &bind_info
, 0, 0);
2544 ok(hres
== E_INVALIDARG
, "Start failed: %08x, expected E_INVALIDARG\n", hres
);
2545 CLEAR_CALLED(GetBindInfo
); /* GetBindInfo not called in IE7 */
2547 IInternetProtocol_Release(protocol
);
2550 static void test_file_protocol(void) {
2551 WCHAR buf
[INTERNET_MAX_URL_LENGTH
], file_name_buf
[MAX_PATH
];
2556 static const WCHAR wszFile
[] = {'f','i','l','e',':',0};
2557 static const WCHAR wszFile2
[] = {'f','i','l','e',':','/','/',0};
2558 static const WCHAR wszFile3
[] = {'f','i','l','e',':','/','/','/',0};
2559 static const WCHAR wszFile4
[] = {'f','i','l','e',':','\\','\\',0};
2560 static const char html_doc
[] = "<HTML></HTML>";
2562 trace("Testing file protocol...\n");
2563 init_test(FILE_TEST
, 0);
2565 SetLastError(0xdeadbeef);
2566 file
= CreateFileW(wszIndexHtml
, GENERIC_WRITE
, 0, NULL
, CREATE_ALWAYS
,
2567 FILE_ATTRIBUTE_NORMAL
, NULL
);
2568 ok(file
!= INVALID_HANDLE_VALUE
, "CreateFile failed\n");
2569 if(file
== INVALID_HANDLE_VALUE
)
2571 WriteFile(file
, html_doc
, sizeof(html_doc
)-1, &size
, NULL
);
2574 file_name
= wszIndexHtml
;
2576 test_file_protocol_url(index_url
);
2577 bindf
= BINDF_FROMURLMON
;
2578 test_file_protocol_url(index_url
);
2579 bindf
= BINDF_FROMURLMON
| BINDF_NEEDFILE
;
2580 test_file_protocol_url(index_url
);
2582 memcpy(buf
, wszFile
, sizeof(wszFile
));
2583 len
= sizeof(wszFile
)/sizeof(WCHAR
)-1;
2584 len
+= GetCurrentDirectoryW(sizeof(buf
)/sizeof(WCHAR
)-len
, buf
+len
);
2586 memcpy(buf
+len
, wszIndexHtml
, sizeof(wszIndexHtml
));
2588 file_name
= buf
+ sizeof(wszFile
)/sizeof(WCHAR
)-1;
2590 test_file_protocol_url(buf
);
2591 bindf
= BINDF_FROMURLMON
;
2592 test_file_protocol_url(buf
);
2594 memcpy(buf
, wszFile2
, sizeof(wszFile2
));
2595 len
= GetCurrentDirectoryW(sizeof(file_name_buf
)/sizeof(WCHAR
), file_name_buf
);
2596 file_name_buf
[len
++] = '\\';
2597 memcpy(file_name_buf
+len
, wszIndexHtml
, sizeof(wszIndexHtml
));
2598 lstrcpyW(buf
+sizeof(wszFile2
)/sizeof(WCHAR
)-1, file_name_buf
);
2599 file_name
= file_name_buf
;
2601 test_file_protocol_url(buf
);
2602 bindf
= BINDF_FROMURLMON
;
2603 test_file_protocol_url(buf
);
2605 buf
[sizeof(wszFile2
)/sizeof(WCHAR
)] = '|';
2606 test_file_protocol_url(buf
);
2608 memcpy(buf
, wszFile3
, sizeof(wszFile3
));
2609 len
= sizeof(wszFile3
)/sizeof(WCHAR
)-1;
2610 len
+= GetCurrentDirectoryW(sizeof(buf
)/sizeof(WCHAR
)-len
, buf
+len
);
2612 memcpy(buf
+len
, wszIndexHtml
, sizeof(wszIndexHtml
));
2614 file_name
= buf
+ sizeof(wszFile3
)/sizeof(WCHAR
)-1;
2616 test_file_protocol_url(buf
);
2617 bindf
= BINDF_FROMURLMON
;
2618 test_file_protocol_url(buf
);
2620 memcpy(buf
, wszFile4
, sizeof(wszFile4
));
2621 len
= GetCurrentDirectoryW(sizeof(file_name_buf
)/sizeof(WCHAR
), file_name_buf
);
2622 file_name_buf
[len
++] = '\\';
2623 memcpy(file_name_buf
+len
, wszIndexHtml
, sizeof(wszIndexHtml
));
2624 lstrcpyW(buf
+sizeof(wszFile4
)/sizeof(WCHAR
)-1, file_name_buf
);
2625 file_name
= file_name_buf
;
2627 test_file_protocol_url(buf
);
2628 bindf
= BINDF_FROMURLMON
;
2629 test_file_protocol_url(buf
);
2631 buf
[sizeof(wszFile4
)/sizeof(WCHAR
)] = '|';
2632 test_file_protocol_url(buf
);
2634 DeleteFileW(wszIndexHtml
);
2637 test_file_protocol_fail();
2638 bindf
= BINDF_FROMURLMON
;
2639 test_file_protocol_fail();
2642 static BOOL
http_protocol_start(LPCWSTR url
, BOOL use_iuri
)
2644 static BOOL got_user_agent
= FALSE
;
2648 if(use_iuri
&& pCreateUri
) {
2649 hres
= pCreateUri(url
, 0, 0, &uri
);
2650 ok(hres
== S_OK
, "CreateUri failed: %08x\n", hres
);
2653 SET_EXPECT(GetBindInfo
);
2654 if (!(bindf
& BINDF_FROMURLMON
))
2655 SET_EXPECT(ReportProgress_DIRECTBIND
);
2657 SET_EXPECT(GetBindString_USER_AGENT
);
2658 SET_EXPECT(GetBindString_ACCEPT_MIMES
);
2659 SET_EXPECT(QueryService_HttpNegotiate
);
2660 SET_EXPECT(BeginningTransaction
);
2661 SET_EXPECT(GetRootSecurityId
);
2662 if(http_post_test
) {
2663 SET_EXPECT(GetBindString_POST_COOKIE
);
2664 if(http_post_test
== TYMED_ISTREAM
)
2665 SET_EXPECT(Stream_Seek
);
2669 IInternetProtocolEx
*protocolex
;
2671 hres
= IInternetProtocol_QueryInterface(async_protocol
, &IID_IInternetProtocolEx
, (void**)&protocolex
);
2672 ok(hres
== S_OK
, "Could not get IInternetProtocolEx iface: %08x\n", hres
);
2674 hres
= IInternetProtocolEx_StartEx(protocolex
, uri
, &protocol_sink
, &bind_info
, 0, 0);
2675 ok(hres
== S_OK
, "Start failed: %08x\n", hres
);
2677 IInternetProtocolEx_Release(protocolex
);
2680 hres
= IInternetProtocol_Start(async_protocol
, url
, &protocol_sink
, &bind_info
, 0, 0);
2681 ok(hres
== S_OK
, "Start failed: %08x\n", hres
);
2686 CHECK_CALLED(GetBindInfo
);
2687 if (!(bindf
& BINDF_FROMURLMON
))
2688 CHECK_CALLED(ReportProgress_DIRECTBIND
);
2689 if (!got_user_agent
)
2691 CHECK_CALLED(GetBindString_USER_AGENT
);
2692 got_user_agent
= TRUE
;
2694 CHECK_CALLED(GetBindString_ACCEPT_MIMES
);
2695 CHECK_CALLED(QueryService_HttpNegotiate
);
2696 CHECK_CALLED(BeginningTransaction
);
2697 /* GetRootSecurityId called on WinXP but not on Win98 */
2698 CLEAR_CALLED(GetRootSecurityId
);
2699 if(http_post_test
) {
2700 CHECK_CALLED(GetBindString_POST_COOKIE
);
2701 if(http_post_test
== TYMED_ISTREAM
)
2702 CHECK_CALLED(Stream_Seek
);
2708 static void test_protocol_terminate(IInternetProtocol
*protocol
)
2714 hres
= IInternetProtocol_LockRequest(protocol
, 0);
2715 ok(hres
== S_OK
, "LockRequest failed: %08x\n", hres
);
2717 hres
= IInternetProtocol_Read(protocol
, buf
, 1, &cb
);
2718 ok(hres
== test_abort
? S_OK
: S_FALSE
, "Read failed: %08x\n", hres
);
2720 hres
= IInternetProtocol_Terminate(protocol
, 0);
2721 ok(hres
== S_OK
, "Terminate failed: %08x\n", hres
);
2723 /* This wait is to give the internet handles being freed in Terminate
2724 * enough time to actually terminate in all cases. Internet handles
2725 * terminate asynchronously and native reuses the main InternetOpen
2726 * handle. The only case in which this seems to be necessary is on
2727 * wine with native wininet and urlmon, resulting in the next time
2728 * test_http_protocol_url being called the first data notification actually
2729 * being an extra last data notification from the previous connection
2730 * about once out of every ten times. */
2733 hres
= IInternetProtocol_UnlockRequest(protocol
);
2734 ok(hres
== S_OK
, "UnlockRequest failed: %08x\n", hres
);
2737 static void test_http_info(IInternetProtocol
*protocol
)
2739 IWinInetHttpInfo
*info
;
2742 hres
= IInternetProtocol_QueryInterface(protocol
, &IID_IWinInetHttpInfo
, (void**)&info
);
2743 ok(hres
== S_OK
, "Could not get IWinInterHttpInfo iface: %08x\n", hres
);
2747 IWinInetHttpInfo_Release(info
);
2750 /* is_first refers to whether this is the first call to this function
2752 static void test_http_protocol_url(LPCWSTR url
, int prot
, DWORD flags
, DWORD tymed
)
2754 IInternetProtocolInfo
*protocol_info
;
2755 IClassFactory
*factory
;
2759 init_test(prot
, flags
);
2761 http_post_test
= tymed
;
2763 hres
= CoGetClassObject(prot
== HTTPS_TEST
? &CLSID_HttpSProtocol
: &CLSID_HttpProtocol
,
2764 CLSCTX_INPROC_SERVER
, NULL
, &IID_IUnknown
, (void**)&unk
);
2765 ok(hres
== S_OK
, "CoGetClassObject failed: %08x\n", hres
);
2769 hres
= IUnknown_QueryInterface(unk
, &IID_IInternetProtocolInfo
, (void**)&protocol_info
);
2770 ok(hres
== E_NOINTERFACE
,
2771 "Could not get IInternetProtocolInfo interface: %08x, expected E_NOINTERFACE\n",
2774 hres
= IUnknown_QueryInterface(unk
, &IID_IClassFactory
, (void**)&factory
);
2775 ok(hres
== S_OK
, "Could not get IClassFactory interface\n");
2776 IUnknown_Release(unk
);
2780 hres
= IClassFactory_CreateInstance(factory
, NULL
, &IID_IInternetProtocol
,
2781 (void**)&async_protocol
);
2782 ok(hres
== S_OK
, "Could not get IInternetProtocol: %08x\n", hres
);
2783 if(SUCCEEDED(hres
)) {
2788 test_priority(async_protocol
);
2789 test_http_info(async_protocol
);
2791 SET_EXPECT(ReportProgress_COOKIE_SENT
);
2793 SET_EXPECT(ReportProgress_FINDINGRESOURCE
);
2794 SET_EXPECT(ReportProgress_CONNECTING
);
2796 SET_EXPECT(ReportProgress_SENDINGREQUEST
);
2798 SET_EXPECT(ReportProgress_REDIRECTING
);
2799 SET_EXPECT(ReportProgress_PROXYDETECTING
);
2800 if(prot
== HTTP_TEST
)
2801 SET_EXPECT(ReportProgress_CACHEFILENAMEAVAILABLE
);
2803 SET_EXPECT(QueryService_HttpSecurity
);
2804 if(!(bindf
& BINDF_FROMURLMON
)) {
2805 SET_EXPECT(OnResponse
);
2806 SET_EXPECT(ReportProgress_RAWMIMETYPE
);
2807 SET_EXPECT(ReportData
);
2812 if(!http_protocol_start(url
, (flags
& TEST_USEIURI
) != 0))
2815 if(!direct_read
&& !test_abort
)
2816 SET_EXPECT(ReportResult
);
2817 expect_hrResult
= test_abort
? E_ABORT
: S_OK
;
2821 while(wait_for_switch
) {
2822 WaitForSingleObject(event_continue
, INFINITE
);
2823 CHECK_CALLED(Switch
); /* Set in ReportData */
2824 call_continue(&continue_protdata
);
2825 SetEvent(event_continue_done
);
2828 hres
= IInternetProtocol_Read(async_protocol
, buf
, 1, &cb
);
2829 ok((hres
== E_PENDING
&& cb
==0) ||
2830 (hres
== S_OK
&& cb
==1), "Read failed: %08x (%d bytes)\n", hres
, cb
);
2832 WaitForSingleObject(event_complete
, INFINITE
);
2833 if(bindf
& BINDF_FROMURLMON
)
2834 CHECK_CALLED(Switch
);
2836 CHECK_CALLED(ReportData
);
2837 if(prot
== HTTPS_TEST
)
2838 CLEAR_CALLED(QueryService_HttpSecurity
);
2841 if(bindf
& BINDF_FROMURLMON
)
2844 SET_EXPECT(ReportData
);
2845 hres
= IInternetProtocol_Read(async_protocol
, buf
, sizeof(buf
), &cb
);
2846 if(hres
== E_PENDING
) {
2847 hres
= IInternetProtocol_Read(async_protocol
, buf
, 1, &cb
);
2848 ok((hres
== E_PENDING
&& cb
==0) ||
2849 (hres
== S_OK
&& cb
==1), "Read failed: %08x (%d bytes)\n", hres
, cb
);
2850 WaitForSingleObject(event_complete
, INFINITE
);
2851 if(bindf
& BINDF_FROMURLMON
)
2852 CHECK_CALLED(Switch
);
2854 CHECK_CALLED(ReportData
);
2859 SET_EXPECT(ReportResult
);
2860 hres
= IInternetProtocol_Abort(async_protocol
, E_ABORT
, 0);
2861 ok(hres
== S_OK
, "Abort failed: %08x\n", hres
);
2862 CHECK_CALLED(ReportResult
);
2864 hres
= IInternetProtocol_Abort(async_protocol
, E_ABORT
, 0);
2865 ok(hres
== INET_E_RESULT_DISPATCHED
, "Abort failed: %08x\n", hres
);
2869 if(bindf
& BINDF_FROMURLMON
)
2870 CHECK_NOT_CALLED(Switch
);
2872 CHECK_NOT_CALLED(ReportData
);
2877 ok(hres
== S_FALSE
, "Read failed: %08x\n", hres
);
2878 CHECK_CALLED(ReportResult
);
2881 if(prot
== HTTPS_TEST
)
2882 CLEAR_CALLED(ReportProgress_SENDINGREQUEST
);
2884 hres
= IInternetProtocol_Abort(async_protocol
, E_ABORT
, 0);
2885 ok(hres
== INET_E_RESULT_DISPATCHED
, "Abort failed: %08x\n", hres
);
2887 test_protocol_terminate(async_protocol
);
2889 hres
= IInternetProtocol_Abort(async_protocol
, E_ABORT
, 0);
2890 ok(hres
== S_OK
, "Abort failed: %08x\n", hres
);
2892 ref
= IInternetProtocol_Release(async_protocol
);
2893 ok(!ref
, "ref=%x\n", ref
);
2896 IClassFactory_Release(factory
);
2899 static void test_http_protocol(void)
2901 static const WCHAR posttest_url
[] =
2902 {'h','t','t','p',':','/','/','t','e','s','t','.','w','i','n','e','h','q','.','o','r','g','/',
2903 't','e','s','t','s','/','p','o','s','t','.','p','h','p',0};
2904 static const WCHAR redirect_url
[] =
2905 {'h','t','t','p',':','/','/','t','e','s','t','.','w','i','n','e','h','q','.','o','r','g','/',
2906 't','e','s','t','s','/','r','e','d','i','r','e','c','t',0};
2907 static const WCHAR winetest_url
[] =
2908 {'h','t','t','p',':','/','/','t','e','s','t','.','w','i','n','e','h','q','.','o','r','g','/',
2909 't','e','s','t','s','/','d','a','t','a','.','p','h','p',0};
2910 static const WCHAR empty_url
[] =
2911 {'h','t','t','p',':','/','/','t','e','s','t','.','w','i','n','e','h','q','.','o','r','g','/',
2912 't','e','s','t','s','/','e','m','p','t','y','.','j','s',0};
2914 trace("Testing http protocol (not from urlmon)...\n");
2915 bindf
= BINDF_ASYNCHRONOUS
| BINDF_ASYNCSTORAGE
| BINDF_PULLDATA
;
2916 test_http_protocol_url(winetest_url
, HTTP_TEST
, TEST_FIRST_HTTP
, TYMED_NULL
);
2918 trace("Testing http protocol (from urlmon)...\n");
2919 bindf
= BINDF_ASYNCHRONOUS
| BINDF_ASYNCSTORAGE
| BINDF_PULLDATA
| BINDF_FROMURLMON
;
2920 test_http_protocol_url(winetest_url
, HTTP_TEST
, 0, TYMED_NULL
);
2922 trace("Testing http protocol (to file)...\n");
2923 bindf
= BINDF_ASYNCHRONOUS
| BINDF_ASYNCSTORAGE
| BINDF_PULLDATA
| BINDF_FROMURLMON
| BINDF_NEEDFILE
;
2924 test_http_protocol_url(winetest_url
, HTTP_TEST
, 0, TYMED_NULL
);
2926 trace("Testing http protocol (post data)...\n");
2927 bindf
= BINDF_ASYNCHRONOUS
| BINDF_ASYNCSTORAGE
| BINDF_PULLDATA
| BINDF_FROMURLMON
;
2928 test_http_protocol_url(posttest_url
, HTTP_TEST
, TEST_FIRST_HTTP
|TEST_POST
, TYMED_HGLOBAL
);
2930 trace("Testing http protocol (post data stream)...\n");
2931 test_http_protocol_url(posttest_url
, HTTP_TEST
, TEST_FIRST_HTTP
|TEST_POST
|TEST_ASYNCREQ
, TYMED_ISTREAM
);
2933 trace("Testing http protocol (direct read)...\n");
2934 bindf
= BINDF_ASYNCHRONOUS
| BINDF_ASYNCSTORAGE
| BINDF_PULLDATA
| BINDF_FROMURLMON
;
2935 test_http_protocol_url(winetest_url
, HTTP_TEST
, TEST_DIRECT_READ
|TEST_USEIURI
, TYMED_NULL
);
2937 trace("Testing http protocol (redirected)...\n");
2938 bindf
= BINDF_ASYNCHRONOUS
| BINDF_ASYNCSTORAGE
| BINDF_PULLDATA
| BINDF_FROMURLMON
;
2939 test_http_protocol_url(redirect_url
, HTTP_TEST
, TEST_REDIRECT
, TYMED_NULL
);
2941 trace("Testing http protocol empty file...\n");
2942 test_http_protocol_url(empty_url
, HTTP_TEST
, TEST_EMPTY
, TYMED_NULL
);
2944 trace("Testing http protocol abort...\n");
2945 test_http_protocol_url(winetest_url
, HTTP_TEST
, TEST_ABORT
, TYMED_NULL
);
2947 test_early_abort(&CLSID_HttpProtocol
);
2948 test_early_abort(&CLSID_HttpSProtocol
);
2951 static void test_https_protocol(void)
2953 static const WCHAR codeweavers_url
[] =
2954 {'h','t','t','p','s',':','/','/','w','w','w','.','c','o','d','e','w','e','a','v','e','r','s',
2955 '.','c','o','m','/','t','e','s','t','.','h','t','m','l',0};
2957 trace("Testing https protocol (from urlmon)...\n");
2958 bindf
= BINDF_ASYNCHRONOUS
| BINDF_ASYNCSTORAGE
| BINDF_PULLDATA
| BINDF_FROMURLMON
| BINDF_NOWRITECACHE
;
2959 test_http_protocol_url(codeweavers_url
, HTTPS_TEST
, TEST_FIRST_HTTP
, TYMED_NULL
);
2963 static void test_ftp_protocol(void)
2965 IInternetProtocolInfo
*protocol_info
;
2966 IClassFactory
*factory
;
2973 static const WCHAR ftp_urlW
[] = {'f','t','p',':','/','/','f','t','p','.','w','i','n','e','h','q','.','o','r','g',
2974 '/','p','u','b','/','o','t','h','e','r','/',
2975 'w','i','n','e','l','o','g','o','.','x','c','f','.','t','a','r','.','b','z','2',0};
2977 trace("Testing ftp protocol...\n");
2979 bindf
= BINDF_ASYNCHRONOUS
| BINDF_ASYNCSTORAGE
| BINDF_PULLDATA
| BINDF_FROMURLMON
| BINDF_NOWRITECACHE
;
2980 state
= STATE_STARTDOWNLOADING
;
2981 tested_protocol
= FTP_TEST
;
2982 first_data_notif
= TRUE
;
2983 expect_hrResult
= E_PENDING
;
2985 hres
= CoGetClassObject(&CLSID_FtpProtocol
, CLSCTX_INPROC_SERVER
, NULL
, &IID_IUnknown
, (void**)&unk
);
2986 ok(hres
== S_OK
, "CoGetClassObject failed: %08x\n", hres
);
2990 hres
= IUnknown_QueryInterface(unk
, &IID_IInternetProtocolInfo
, (void**)&protocol_info
);
2991 ok(hres
== E_NOINTERFACE
, "Could not get IInternetProtocolInfo interface: %08x, expected E_NOINTERFACE\n", hres
);
2993 hres
= IUnknown_QueryInterface(unk
, &IID_IClassFactory
, (void**)&factory
);
2994 ok(hres
== S_OK
, "Could not get IClassFactory interface\n");
2995 IUnknown_Release(unk
);
2999 hres
= IClassFactory_CreateInstance(factory
, NULL
, &IID_IInternetProtocol
,
3000 (void**)&async_protocol
);
3001 IClassFactory_Release(factory
);
3002 ok(hres
== S_OK
, "Could not get IInternetProtocol: %08x\n", hres
);
3004 test_priority(async_protocol
);
3005 test_http_info(async_protocol
);
3007 SET_EXPECT(GetBindInfo
);
3008 SET_EXPECT(ReportProgress_FINDINGRESOURCE
);
3009 SET_EXPECT(ReportProgress_CONNECTING
);
3010 SET_EXPECT(ReportProgress_SENDINGREQUEST
);
3013 hres
= IInternetProtocol_Start(async_protocol
, ftp_urlW
, &protocol_sink
, &bind_info
, 0, 0);
3014 ok(hres
== S_OK
, "Start failed: %08x\n", hres
);
3015 CHECK_CALLED(GetBindInfo
);
3017 SET_EXPECT(ReportResult
);
3019 hres
= IInternetProtocol_Read(async_protocol
, buf
, 1, &cb
);
3020 ok((hres
== E_PENDING
&& cb
==0) ||
3021 (hres
== S_OK
&& cb
==1), "Read failed: %08x (%d bytes)\n", hres
, cb
);
3023 WaitForSingleObject(event_complete
, INFINITE
);
3026 hres
= IInternetProtocol_Read(async_protocol
, buf
, sizeof(buf
), &cb
);
3027 if(hres
== E_PENDING
)
3028 WaitForSingleObject(event_complete
, INFINITE
);
3033 ok(hres
== S_FALSE
, "Read failed: %08x\n", hres
);
3034 CHECK_CALLED(ReportResult
);
3035 CHECK_CALLED(Switch
);
3037 test_protocol_terminate(async_protocol
);
3040 IInternetProtocolEx
*protocolex
;
3042 hres
= IInternetProtocol_QueryInterface(async_protocol
, &IID_IInternetProtocolEx
, (void**)&protocolex
);
3043 ok(hres
== S_OK
, "Could not get IInternetProtocolEx iface: %08x\n", hres
);
3044 IInternetProtocolEx_Release(protocolex
);
3047 ref
= IInternetProtocol_Release(async_protocol
);
3048 ok(!ref
, "ref=%d\n", ref
);
3050 test_early_abort(&CLSID_FtpProtocol
);
3053 static void test_gopher_protocol(void)
3055 IInternetProtocolInfo
*protocol_info
;
3056 IClassFactory
*factory
;
3060 trace("Testing gopher protocol...\n");
3062 hres
= CoGetClassObject(&CLSID_GopherProtocol
, CLSCTX_INPROC_SERVER
, NULL
, &IID_IUnknown
, (void**)&unk
);
3064 hres
== REGDB_E_CLASSNOTREG
, /* Gopher protocol has been removed as of Vista */
3065 "CoGetClassObject failed: %08x\n", hres
);
3069 hres
= IUnknown_QueryInterface(unk
, &IID_IInternetProtocolInfo
, (void**)&protocol_info
);
3070 ok(hres
== E_NOINTERFACE
, "Could not get IInternetProtocolInfo interface: %08x, expected E_NOINTERFACE\n", hres
);
3072 hres
= IUnknown_QueryInterface(unk
, &IID_IClassFactory
, (void**)&factory
);
3073 ok(hres
== S_OK
, "Could not get IClassFactory interface\n");
3074 IUnknown_Release(unk
);
3078 hres
= IClassFactory_CreateInstance(factory
, NULL
, &IID_IInternetProtocol
,
3079 (void**)&async_protocol
);
3080 IClassFactory_Release(factory
);
3081 ok(hres
== S_OK
, "Could not get IInternetProtocol: %08x\n", hres
);
3083 test_priority(async_protocol
);
3085 IInternetProtocol_Release(async_protocol
);
3087 test_early_abort(&CLSID_GopherProtocol
);
3090 static void test_mk_protocol(void)
3092 IInternetProtocolInfo
*protocol_info
;
3093 IInternetProtocol
*protocol
;
3094 IClassFactory
*factory
;
3098 static const WCHAR wrong_url1
[] = {'t','e','s','t',':','@','M','S','I','T','S','t','o','r','e',
3099 ':',':','/','t','e','s','t','.','h','t','m','l',0};
3100 static const WCHAR wrong_url2
[] = {'m','k',':','/','t','e','s','t','.','h','t','m','l',0};
3102 trace("Testing mk protocol...\n");
3103 init_test(MK_TEST
, 0);
3105 hres
= CoGetClassObject(&CLSID_MkProtocol
, CLSCTX_INPROC_SERVER
, NULL
,
3106 &IID_IUnknown
, (void**)&unk
);
3107 ok(hres
== S_OK
, "CoGetClassObject failed: %08x\n", hres
);
3109 hres
= IUnknown_QueryInterface(unk
, &IID_IInternetProtocolInfo
, (void**)&protocol_info
);
3110 ok(hres
== E_NOINTERFACE
,
3111 "Could not get IInternetProtocolInfo interface: %08x, expected E_NOINTERFACE\n",
3114 hres
= IUnknown_QueryInterface(unk
, &IID_IClassFactory
, (void**)&factory
);
3115 ok(hres
== S_OK
, "Could not get IClassFactory interface\n");
3116 IUnknown_Release(unk
);
3120 hres
= IClassFactory_CreateInstance(factory
, NULL
, &IID_IInternetProtocol
,
3122 IClassFactory_Release(factory
);
3123 ok(hres
== S_OK
, "Could not get IInternetProtocol: %08x\n", hres
);
3125 SET_EXPECT(GetBindInfo
);
3126 hres
= IInternetProtocol_Start(protocol
, wrong_url1
, &protocol_sink
, &bind_info
, 0, 0);
3127 ok(hres
== MK_E_SYNTAX
|| hres
== INET_E_INVALID_URL
,
3128 "Start failed: %08x, expected MK_E_SYNTAX or INET_E_INVALID_URL\n", hres
);
3129 CLEAR_CALLED(GetBindInfo
);
3131 SET_EXPECT(GetBindInfo
);
3132 SET_EXPECT(ReportProgress_DIRECTBIND
);
3133 SET_EXPECT(ReportProgress_SENDINGREQUEST
);
3134 SET_EXPECT(ReportProgress_MIMETYPEAVAILABLE
);
3135 SET_EXPECT(ReportResult
);
3136 expect_hrResult
= INET_E_RESOURCE_NOT_FOUND
;
3138 hres
= IInternetProtocol_Start(protocol
, wrong_url2
, &protocol_sink
, &bind_info
, 0, 0);
3139 ok(hres
== INET_E_RESOURCE_NOT_FOUND
||
3140 hres
== INET_E_INVALID_URL
, /* win2k3 */
3141 "Start failed: %08x, expected INET_E_RESOURCE_NOT_FOUND or INET_E_INVALID_URL\n", hres
);
3143 if (hres
== INET_E_RESOURCE_NOT_FOUND
) {
3144 CHECK_CALLED(GetBindInfo
);
3145 CLEAR_CALLED(ReportProgress_DIRECTBIND
);
3146 CHECK_CALLED(ReportProgress_SENDINGREQUEST
);
3147 CHECK_CALLED(ReportProgress_MIMETYPEAVAILABLE
);
3148 CHECK_CALLED(ReportResult
);
3150 CLEAR_CALLED(GetBindInfo
);
3151 CLEAR_CALLED(ReportProgress_DIRECTBIND
);
3152 CLEAR_CALLED(ReportProgress_SENDINGREQUEST
);
3153 CLEAR_CALLED(ReportProgress_MIMETYPEAVAILABLE
);
3154 CLEAR_CALLED(ReportResult
);
3157 IInternetProtocol_Release(protocol
);
3160 static void test_CreateBinding(void)
3162 IInternetProtocol
*protocol
;
3163 IInternetPriority
*priority
;
3164 IInternetSession
*session
;
3165 IWinInetHttpInfo
*http_info
;
3166 IWinInetInfo
*inet_info
;
3172 static const WCHAR test_url
[] =
3173 {'t','e','s','t',':','/','/','f','i','l','e','.','h','t','m','l',0};
3174 static const WCHAR wsz_test
[] = {'t','e','s','t',0};
3176 trace("Testing CreateBinding...\n");
3177 init_test(BIND_TEST
, TEST_BINDING
);
3179 hres
= pCoInternetGetSession(0, &session
, 0);
3180 ok(hres
== S_OK
, "CoInternetGetSession failed: %08x\n", hres
);
3182 hres
= IInternetSession_RegisterNameSpace(session
, &ClassFactory
, &IID_NULL
, wsz_test
, 0, NULL
, 0);
3183 ok(hres
== S_OK
, "RegisterNameSpace failed: %08x\n", hres
);
3185 hres
= IInternetSession_CreateBinding(session
, NULL
, test_url
, NULL
, NULL
, &protocol
, 0);
3186 binding_protocol
= protocol
;
3187 ok(hres
== S_OK
, "CreateBinding failed: %08x\n", hres
);
3188 ok(protocol
!= NULL
, "protocol == NULL\n");
3190 hres
= IInternetProtocol_QueryInterface(protocol
, &IID_IInternetBindInfo
, (void**)&prot_bind_info
);
3191 ok(hres
== S_OK
, "QueryInterface(IID_IInternetBindInfo) failed: %08x\n", hres
);
3193 hres
= IInternetProtocol_QueryInterface(protocol
, &IID_IInternetProtocolSink
, (void**)&binding_sink
);
3194 ok(hres
== S_OK
, "Could not get IInternetProtocolSink: %08x\n", hres
);
3196 hres
= IInternetProtocol_Start(protocol
, test_url
, NULL
, &bind_info
, 0, 0);
3197 ok(hres
== E_INVALIDARG
, "Start failed: %08x, expected E_INVALIDARG\n", hres
);
3198 hres
= IInternetProtocol_Start(protocol
, test_url
, &protocol_sink
, NULL
, 0, 0);
3199 ok(hres
== E_INVALIDARG
, "Start failed: %08x, expected E_INVALIDARG\n", hres
);
3200 hres
= IInternetProtocol_Start(protocol
, NULL
, &protocol_sink
, &bind_info
, 0, 0);
3201 ok(hres
== E_INVALIDARG
, "Start failed: %08x, expected E_INVALIDARG\n", hres
);
3203 hres
= IInternetProtocol_QueryInterface(protocol
, &IID_IInternetPriority
, (void**)&priority
);
3204 ok(hres
== S_OK
, "QueryInterface(IID_IInternetPriority) failed: %08x\n", hres
);
3207 hres
= IInternetPriority_GetPriority(priority
, &p
);
3208 ok(hres
== S_OK
, "GetPriority failed: %08x\n", hres
);
3209 ok(!p
, "p=%d\n", p
);
3212 hres
= IInternetPriority_SetPriority(priority
, 100);
3213 ok(hres
== S_OK
, "SetPriority failed: %08x\n", hres
);
3216 hres
= IInternetPriority_GetPriority(priority
, &p
);
3217 ok(hres
== S_OK
, "GetPriority failed: %08x\n", hres
);
3218 ok(p
== 100, "p=%d\n", p
);
3220 hres
= IInternetProtocol_QueryInterface(protocol
, &IID_IWinInetInfo
, (void**)&inet_info
);
3221 ok(hres
== E_NOINTERFACE
, "Could not get IWinInetInfo protocol: %08x\n", hres
);
3223 SET_EXPECT(QueryService_InternetProtocol
);
3224 SET_EXPECT(CreateInstance
);
3225 SET_EXPECT(ReportProgress_PROTOCOLCLASSID
);
3226 SET_EXPECT(SetPriority
);
3229 expect_hrResult
= S_OK
;
3230 hres
= IInternetProtocol_Start(protocol
, test_url
, &protocol_sink
, &bind_info
, 0, 0);
3231 ok(hres
== S_OK
, "Start failed: %08x\n", hres
);
3233 CHECK_CALLED(QueryService_InternetProtocol
);
3234 CHECK_CALLED(CreateInstance
);
3235 CHECK_CALLED(ReportProgress_PROTOCOLCLASSID
);
3236 CHECK_CALLED(SetPriority
);
3237 CHECK_CALLED(Start
);
3239 SET_EXPECT(QueryInterface_IWinInetInfo
);
3240 hres
= IInternetProtocol_QueryInterface(protocol
, &IID_IWinInetInfo
, (void**)&inet_info
);
3241 ok(hres
== E_NOINTERFACE
, "Could not get IWinInetInfo protocol: %08x\n", hres
);
3242 CHECK_CALLED(QueryInterface_IWinInetInfo
);
3244 SET_EXPECT(QueryInterface_IWinInetInfo
);
3245 hres
= IInternetProtocol_QueryInterface(protocol
, &IID_IWinInetInfo
, (void**)&inet_info
);
3246 ok(hres
== E_NOINTERFACE
, "Could not get IWinInetInfo protocol: %08x\n", hres
);
3247 CHECK_CALLED(QueryInterface_IWinInetInfo
);
3249 SET_EXPECT(QueryInterface_IWinInetHttpInfo
);
3250 hres
= IInternetProtocol_QueryInterface(protocol
, &IID_IWinInetHttpInfo
, (void**)&http_info
);
3251 ok(hres
== E_NOINTERFACE
, "Could not get IWinInetInfo protocol: %08x\n", hres
);
3252 CHECK_CALLED(QueryInterface_IWinInetHttpInfo
);
3256 hres
= IInternetProtocol_Read(protocol
, expect_pv
= buf
, sizeof(buf
), &read
);
3257 ok(hres
== S_OK
, "Read failed: %08x\n", hres
);
3258 ok(read
== 100, "read = %d\n", read
);
3263 hres
= IInternetProtocol_Read(protocol
, expect_pv
= buf
, sizeof(buf
), &read
);
3264 ok(hres
== S_FALSE
, "Read failed: %08x\n", hres
);
3265 ok(!read
, "read = %d\n", read
);
3269 hres
= IInternetPriority_GetPriority(priority
, &p
);
3270 ok(hres
== S_OK
, "GetPriority failed: %08x\n", hres
);
3271 ok(p
== 100, "p=%d\n", p
);
3273 hres
= IInternetPriority_SetPriority(priority
, 101);
3274 ok(hres
== S_OK
, "SetPriority failed: %08x\n", hres
);
3276 SET_EXPECT(Terminate
);
3277 hres
= IInternetProtocol_Terminate(protocol
, 0xdeadbeef);
3278 ok(hres
== S_OK
, "Terminate failed: %08x\n", hres
);
3279 CHECK_CALLED(Terminate
);
3281 SET_EXPECT(Continue
);
3282 hres
= IInternetProtocolSink_Switch(binding_sink
, &protocoldata
);
3283 ok(hres
== S_OK
, "Switch failed: %08x\n", hres
);
3284 CHECK_CALLED(Continue
);
3286 hres
= IInternetProtocolSink_ReportProgress(binding_sink
,
3287 BINDSTATUS_CACHEFILENAMEAVAILABLE
, expect_wsz
= emptyW
);
3288 ok(hres
== S_OK
, "ReportProgress(BINDSTATUS_CACHEFILENAMEAVAILABLE) failed: %08x\n", hres
);
3290 hres
= IInternetProtocolSink_ReportResult(binding_sink
, S_OK
, ERROR_SUCCESS
, NULL
);
3291 ok(hres
== E_FAIL
, "ReportResult failed: %08x, expected E_FAIL\n", hres
);
3293 hres
= IInternetProtocolSink_ReportData(binding_sink
, 0, 0, 0);
3294 ok(hres
== S_OK
, "ReportData failed: %08x\n", hres
);
3296 IInternetProtocolSink_Release(binding_sink
);
3297 IInternetPriority_Release(priority
);
3298 IInternetBindInfo_Release(prot_bind_info
);
3299 IInternetProtocol_Release(protocol
);
3301 hres
= IInternetSession_CreateBinding(session
, NULL
, test_url
, NULL
, NULL
, &protocol
, 0);
3302 ok(hres
== S_OK
, "CreateBinding failed: %08x\n", hres
);
3303 ok(protocol
!= NULL
, "protocol == NULL\n");
3305 hres
= IInternetProtocol_Abort(protocol
, E_ABORT
, 0);
3306 ok(hres
== S_OK
, "Abort failed: %08x\n", hres
);
3308 hres
= IInternetProtocol_Abort(protocol
, E_FAIL
, 0);
3309 ok(hres
== S_OK
, "Abort failed: %08x\n", hres
);
3311 IInternetProtocol_Release(protocol
);
3313 hres
= IInternetSession_UnregisterNameSpace(session
, &ClassFactory
, wsz_test
);
3314 ok(hres
== S_OK
, "UnregisterNameSpace failed: %08x\n", hres
);
3316 hres
= IInternetSession_CreateBinding(session
, NULL
, test_url
, NULL
, NULL
, &protocol
, 0);
3317 ok(hres
== S_OK
, "CreateBinding failed: %08x\n", hres
);
3318 ok(protocol
!= NULL
, "protocol == NULL\n");
3320 SET_EXPECT(QueryService_InternetProtocol
);
3321 hres
= IInternetProtocol_Start(protocol
, test_url
, &protocol_sink
, &bind_info
, 0, 0);
3322 ok(hres
== MK_E_SYNTAX
, "Start failed: %08x, expected MK_E_SYNTAX\n", hres
);
3323 CHECK_CALLED(QueryService_InternetProtocol
);
3325 IInternetProtocol_Release(protocol
);
3327 IInternetSession_Release(session
);
3330 static void test_binding(int prot
, DWORD grf_pi
, DWORD test_flags
)
3332 IInternetProtocolEx
*protocolex
= NULL
;
3333 IInternetProtocol
*protocol
;
3334 IInternetSession
*session
;
3341 init_test(prot
, test_flags
|TEST_BINDING
);
3343 hres
= pCoInternetGetSession(0, &session
, 0);
3344 ok(hres
== S_OK
, "CoInternetGetSession failed: %08x\n", hres
);
3346 if(test_flags
& TEST_EMULATEPROT
) {
3347 hres
= IInternetSession_RegisterNameSpace(session
, &ClassFactory
, &IID_NULL
, protocol_names
[prot
], 0, NULL
, 0);
3348 ok(hres
== S_OK
, "RegisterNameSpace failed: %08x\n", hres
);
3351 hres
= IInternetSession_CreateBinding(session
, NULL
, binding_urls
[prot
], NULL
, NULL
, &protocol
, 0);
3352 binding_protocol
= protocol
;
3353 ok(hres
== S_OK
, "CreateBinding failed: %08x\n", hres
);
3354 ok(protocol
!= NULL
, "protocol == NULL\n");
3356 hres
= IInternetProtocol_QueryInterface(protocol
, &IID_IInternetBindInfo
, (void**)&prot_bind_info
);
3357 ok(hres
== S_OK
, "QueryInterface(IID_IInternetBindInfo) failed: %08x\n", hres
);
3359 hres
= IInternetProtocol_QueryInterface(protocol
, &IID_IInternetProtocolSink
, (void**)&binding_sink
);
3360 ok(hres
== S_OK
, "QueryInterface(IID_IInternetProtocolSink) failed: %08x\n", hres
);
3362 if(test_flags
& TEST_USEIURI
) {
3363 hres
= IInternetProtocol_QueryInterface(protocol
, &IID_IInternetProtocolEx
, (void**)&protocolex
);
3364 ok(hres
== S_OK
, "Could not get IInternetProtocolEx iface: %08x\n", hres
);
3366 hres
= pCreateUri(binding_urls
[prot
], Uri_CREATE_FILE_USE_DOS_PATH
, 0, &uri
);
3367 ok(hres
== S_OK
, "CreateUri failed: %08x\n", hres
);
3371 SET_EXPECT(QueryService_InternetProtocol
);
3372 SET_EXPECT(CreateInstance
);
3373 SET_EXPECT(ReportProgress_PROTOCOLCLASSID
);
3374 SET_EXPECT(SetPriority
);
3376 SET_EXPECT(StartEx
);
3380 expect_hrResult
= S_OK
;
3383 hres
= IInternetProtocolEx_StartEx(protocolex
, uri
, &protocol_sink
, &bind_info
, pi
, 0);
3384 ok(hres
== S_OK
, "StartEx failed: %08x\n", hres
);
3386 hres
= IInternetProtocol_Start(protocol
, binding_urls
[prot
], &protocol_sink
, &bind_info
, pi
, 0);
3387 ok(hres
== S_OK
, "Start failed: %08x\n", hres
);
3390 CHECK_CALLED(QueryService_InternetProtocol
);
3391 CHECK_CALLED(CreateInstance
);
3392 CHECK_CALLED(ReportProgress_PROTOCOLCLASSID
);
3393 CHECK_CALLED(SetPriority
);
3395 CHECK_CALLED(StartEx
);
3397 CHECK_CALLED(Start
);
3400 IInternetProtocolEx_Release(protocolex
);
3404 if(prot
== HTTP_TEST
|| prot
== HTTPS_TEST
) {
3405 while(prot_state
< 4) {
3406 WaitForSingleObject(event_complete
, INFINITE
);
3407 if(mimefilter_test
&& filtered_protocol
) {
3408 SET_EXPECT(Continue
);
3409 IInternetProtocol_Continue(filtered_protocol
, pdata
);
3410 CHECK_CALLED(Continue
);
3412 SET_EXPECT(Continue
);
3413 IInternetProtocol_Continue(protocol
, pdata
);
3414 CHECK_CALLED(Continue
);
3416 if(test_abort
&& prot_state
== 2) {
3418 hres
= IInternetProtocol_Abort(protocol
, E_ABORT
, 0);
3419 ok(hres
== S_OK
, "Abort failed: %08x\n", hres
);
3420 CHECK_CALLED(Abort
);
3422 hres
= IInternetProtocol_Abort(protocol
, E_ABORT
, 0);
3423 ok(hres
== S_OK
, "Abort failed: %08x\n", hres
);
3424 SetEvent(event_complete2
);
3427 SetEvent(event_complete2
);
3430 CHECK_CALLED(ReportData
); /* Set in ReportResult */
3431 WaitForSingleObject(event_complete
, INFINITE
);
3434 SET_EXPECT(MimeFilter_LockRequest
);
3436 SET_EXPECT(LockRequest
);
3437 hres
= IInternetProtocol_LockRequest(protocol
, 0);
3438 ok(hres
== S_OK
, "LockRequest failed: %08x\n", hres
);
3440 CHECK_CALLED(MimeFilter_LockRequest
);
3442 CHECK_CALLED(LockRequest
);
3445 SET_EXPECT(MimeFilter_UnlockRequest
);
3447 SET_EXPECT(UnlockRequest
);
3448 hres
= IInternetProtocol_UnlockRequest(protocol
);
3449 ok(hres
== S_OK
, "UnlockRequest failed: %08x\n", hres
);
3451 CHECK_CALLED(MimeFilter_UnlockRequest
);
3453 CHECK_CALLED(UnlockRequest
);
3457 SET_EXPECT(MimeFilter_Terminate
);
3459 SET_EXPECT(Terminate
);
3460 hres
= IInternetProtocol_Terminate(protocol
, 0);
3461 ok(hres
== S_OK
, "Terminate failed: %08x\n", hres
);
3463 CLEAR_CALLED(MimeFilter_Terminate
);
3465 CHECK_CALLED(Terminate
);
3467 if(filtered_protocol
)
3468 IInternetProtocol_Release(filtered_protocol
);
3469 IInternetBindInfo_Release(prot_bind_info
);
3470 IInternetProtocolSink_Release(binding_sink
);
3471 ref
= IInternetProtocol_Release(protocol
);
3472 ok(!ref
, "ref=%u, expected 0\n", ref
);
3474 if(test_flags
& TEST_EMULATEPROT
) {
3475 hres
= IInternetSession_UnregisterNameSpace(session
, &ClassFactory
, protocol_names
[prot
]);
3476 ok(hres
== S_OK
, "UnregisterNameSpace failed: %08x\n", hres
);
3479 IInternetSession_Release(session
);
3482 START_TEST(protocol
)
3486 hurlmon
= GetModuleHandle("urlmon.dll");
3487 pCoInternetGetSession
= (void*) GetProcAddress(hurlmon
, "CoInternetGetSession");
3488 pReleaseBindInfo
= (void*) GetProcAddress(hurlmon
, "ReleaseBindInfo");
3489 pCreateUri
= (void*) GetProcAddress(hurlmon
, "CreateUri");
3491 if(!GetProcAddress(hurlmon
, "CompareSecurityIds")) {
3492 win_skip("Various needed functions not present, too old IE\n");
3497 win_skip("CreateUri not supported\n");
3499 OleInitialize(NULL
);
3501 event_complete
= CreateEvent(NULL
, FALSE
, FALSE
, NULL
);
3502 event_complete2
= CreateEvent(NULL
, FALSE
, FALSE
, NULL
);
3503 event_continue
= CreateEvent(NULL
, FALSE
, FALSE
, NULL
);
3504 event_continue_done
= CreateEvent(NULL
, FALSE
, FALSE
, NULL
);
3505 thread_id
= GetCurrentThreadId();
3507 test_file_protocol();
3508 test_http_protocol();
3509 test_https_protocol();
3510 test_ftp_protocol();
3511 test_gopher_protocol();
3513 test_CreateBinding();
3515 bindf
&= ~BINDF_FROMURLMON
;
3516 trace("Testing file binding (mime verification, emulate prot)...\n");
3517 test_binding(FILE_TEST
, PI_MIMEVERIFICATION
, TEST_EMULATEPROT
);
3518 trace("Testing http binding (mime verification, emulate prot)...\n");
3519 test_binding(HTTP_TEST
, PI_MIMEVERIFICATION
, TEST_EMULATEPROT
);
3520 trace("Testing its binding (mime verification, emulate prot)...\n");
3521 test_binding(ITS_TEST
, PI_MIMEVERIFICATION
, TEST_EMULATEPROT
);
3522 trace("Testing http binding (mime verification, emulate prot, short read, direct read)...\n");
3523 test_binding(HTTP_TEST
, PI_MIMEVERIFICATION
, TEST_EMULATEPROT
|TEST_SHORT_READ
|TEST_DIRECT_READ
);
3524 trace("Testing file binding (mime verification, emulate prot, mime filter)...\n");
3525 test_binding(FILE_TEST
, PI_MIMEVERIFICATION
, TEST_EMULATEPROT
|TEST_FILTER
);
3526 trace("Testing http binding (mime verification, emulate prot, mime filter)...\n");
3527 test_binding(HTTP_TEST
, PI_MIMEVERIFICATION
, TEST_EMULATEPROT
|TEST_FILTER
);
3528 trace("Testing http binding (mime verification, emulate prot, direct read)...\n");
3529 test_binding(HTTP_TEST
, PI_MIMEVERIFICATION
, TEST_EMULATEPROT
|TEST_DIRECT_READ
);
3530 trace("Testing http binding (mime verification, emulate prot, abort)...\n");
3531 test_binding(HTTP_TEST
, PI_MIMEVERIFICATION
, TEST_EMULATEPROT
|TEST_ABORT
);
3533 trace("Testing file binding (use IUri, mime verification, emulate prot)...\n");
3534 test_binding(FILE_TEST
, PI_MIMEVERIFICATION
, TEST_EMULATEPROT
|TEST_USEIURI
);
3535 trace("Testing file binding (use IUri, impl StartEx, mime verification, emulate prot)...\n");
3536 test_binding(FILE_TEST
, PI_MIMEVERIFICATION
, TEST_EMULATEPROT
|TEST_USEIURI
|TEST_IMPLPROTEX
);
3537 trace("Testing file binding (impl StartEx, mime verification, emulate prot)...\n");
3538 test_binding(FILE_TEST
, PI_MIMEVERIFICATION
, TEST_EMULATEPROT
|TEST_IMPLPROTEX
);
3541 CloseHandle(event_complete
);
3542 CloseHandle(event_complete2
);
3543 CloseHandle(event_continue
);
3544 CloseHandle(event_continue_done
);