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>
23 #include <wine/heap.h>
33 static HRESULT (WINAPI
*pCoInternetGetSession
)(DWORD
, IInternetSession
**, DWORD
);
34 static HRESULT (WINAPI
*pReleaseBindInfo
)(BINDINFO
*);
35 static HRESULT (WINAPI
*pCreateUri
)(LPCWSTR
, DWORD
, DWORD_PTR
, IUri
**);
37 #define DEFINE_EXPECT(func) \
38 static BOOL expect_ ## func = FALSE, called_ ## func = FALSE
40 #define SET_EXPECT(func) \
41 expect_ ## func = TRUE
43 #define CHECK_EXPECT2(func) \
45 ok(expect_ ##func, "unexpected call " #func "\n"); \
46 called_ ## func = TRUE; \
49 #define CHECK_EXPECT(func) \
51 CHECK_EXPECT2(func); \
52 expect_ ## func = FALSE; \
55 #define CHECK_CALLED(func) \
57 ok(called_ ## func, "expected " #func "\n"); \
58 expect_ ## func = called_ ## func = FALSE; \
61 #define CHECK_NOT_CALLED(func) \
63 ok(!called_ ## func, "unexpected " #func "\n"); \
64 expect_ ## func = called_ ## func = FALSE; \
67 #define CLEAR_CALLED(func) \
68 expect_ ## func = called_ ## func = FALSE
70 DEFINE_EXPECT(GetBindInfo
);
71 DEFINE_EXPECT(ReportProgress_MIMETYPEAVAILABLE
);
72 DEFINE_EXPECT(ReportProgress_DIRECTBIND
);
73 DEFINE_EXPECT(ReportProgress_RAWMIMETYPE
);
74 DEFINE_EXPECT(ReportProgress_FINDINGRESOURCE
);
75 DEFINE_EXPECT(ReportProgress_CONNECTING
);
76 DEFINE_EXPECT(ReportProgress_SENDINGREQUEST
);
77 DEFINE_EXPECT(ReportProgress_CACHEFILENAMEAVAILABLE
);
78 DEFINE_EXPECT(ReportProgress_VERIFIEDMIMETYPEAVAILABLE
);
79 DEFINE_EXPECT(ReportProgress_PROTOCOLCLASSID
);
80 DEFINE_EXPECT(ReportProgress_COOKIE_SENT
);
81 DEFINE_EXPECT(ReportProgress_REDIRECTING
);
82 DEFINE_EXPECT(ReportProgress_ENCODING
);
83 DEFINE_EXPECT(ReportProgress_ACCEPTRANGES
);
84 DEFINE_EXPECT(ReportProgress_PROXYDETECTING
);
85 DEFINE_EXPECT(ReportProgress_LOADINGMIMEHANDLER
);
86 DEFINE_EXPECT(ReportProgress_DECODING
);
87 DEFINE_EXPECT(ReportData
);
88 DEFINE_EXPECT(ReportData2
);
89 DEFINE_EXPECT(ReportResult
);
90 DEFINE_EXPECT(GetBindString_ACCEPT_MIMES
);
91 DEFINE_EXPECT(GetBindString_USER_AGENT
);
92 DEFINE_EXPECT(GetBindString_POST_COOKIE
);
93 DEFINE_EXPECT(GetBindString_URL
);
94 DEFINE_EXPECT(GetBindString_ROOTDOC_URL
);
95 DEFINE_EXPECT(QueryService_HttpNegotiate
);
96 DEFINE_EXPECT(QueryService_InternetProtocol
);
97 DEFINE_EXPECT(QueryService_HttpSecurity
);
98 DEFINE_EXPECT(QueryService_IBindCallbackRedirect
);
99 DEFINE_EXPECT(QueryInterface_IWinInetInfo
);
100 DEFINE_EXPECT(QueryInterface_IWinInetHttpInfo
);
101 DEFINE_EXPECT(BeginningTransaction
);
102 DEFINE_EXPECT(GetRootSecurityId
);
103 DEFINE_EXPECT(OnResponse
);
104 DEFINE_EXPECT(Switch
);
105 DEFINE_EXPECT(Continue
);
106 DEFINE_EXPECT(CreateInstance
);
107 DEFINE_EXPECT(Start
);
108 DEFINE_EXPECT(StartEx
);
109 DEFINE_EXPECT(Terminate
);
111 DEFINE_EXPECT(Read2
);
112 DEFINE_EXPECT(SetPriority
);
113 DEFINE_EXPECT(LockRequest
);
114 DEFINE_EXPECT(UnlockRequest
);
115 DEFINE_EXPECT(Abort
);
116 DEFINE_EXPECT(MimeFilter_CreateInstance
);
117 DEFINE_EXPECT(MimeFilter_Start
);
118 DEFINE_EXPECT(MimeFilter_ReportData
);
119 DEFINE_EXPECT(MimeFilter_ReportResult
);
120 DEFINE_EXPECT(MimeFilter_Terminate
);
121 DEFINE_EXPECT(MimeFilter_LockRequest
);
122 DEFINE_EXPECT(MimeFilter_UnlockRequest
);
123 DEFINE_EXPECT(MimeFilter_Read
);
124 DEFINE_EXPECT(MimeFilter_Switch
);
125 DEFINE_EXPECT(MimeFilter_Continue
);
126 DEFINE_EXPECT(Stream_Seek
);
127 DEFINE_EXPECT(Stream_Read
);
128 DEFINE_EXPECT(Redirect
);
129 DEFINE_EXPECT(outer_QI_test
);
130 DEFINE_EXPECT(Protocol_destructor
);
132 static const WCHAR wszIndexHtml
[] = {'i','n','d','e','x','.','h','t','m','l',0};
133 static const WCHAR index_url
[] =
134 {'f','i','l','e',':','i','n','d','e','x','.','h','t','m','l',0};
136 static const WCHAR acc_mimeW
[] = {'*','/','*',0};
137 static const WCHAR user_agentW
[] = {'W','i','n','e',0};
138 static const WCHAR text_htmlW
[] = {'t','e','x','t','/','h','t','m','l',0};
139 static const WCHAR hostW
[] = {'w','w','w','.','w','i','n','e','h','q','.','o','r','g',0};
140 static const WCHAR winehq_ipW
[] = {'2','0','9','.','4','6','.','2','5','.','1','3','4',0};
141 static const WCHAR emptyW
[] = {0};
142 static const WCHAR pjpegW
[] = {'i','m','a','g','e','/','p','j','p','e','g',0};
143 static const WCHAR gifW
[] = {'i','m','a','g','e','/','g','i','f',0};
145 static HRESULT expect_hrResult
;
146 static LPCWSTR file_name
, http_url
, expect_wsz
;
147 static IInternetProtocol
*async_protocol
= NULL
;
148 static BOOL first_data_notif
, http_is_first
, test_redirect
, redirect_on_continue
;
149 static int prot_state
, read_report_data
, post_stream_read
;
150 static DWORD bindf
, ex_priority
, pi
, bindinfo_options
;
151 static IInternetProtocol
*binding_protocol
, *filtered_protocol
;
152 static IInternetBindInfo
*prot_bind_info
;
153 static IInternetProtocolSink
*binding_sink
, *filtered_sink
;
154 static void *expect_pv
;
155 static HANDLE event_complete
, event_complete2
, event_continue
, event_continue_done
;
156 static BOOL binding_test
;
157 static PROTOCOLDATA protocoldata
, *pdata
, continue_protdata
;
158 static DWORD prot_read
, filter_state
, http_post_test
, thread_id
;
159 static BOOL security_problem
, test_async_req
, impl_protex
;
160 static BOOL async_read_pending
, mimefilter_test
, direct_read
, wait_for_switch
, emulate_prot
, short_read
, test_abort
;
161 static BOOL empty_file
, no_mime
, bind_from_cache
, file_with_hash
, reuse_protocol_thread
;
165 STATE_SENDINGREQUEST
,
166 STATE_STARTDOWNLOADING
,
181 IUnknown IUnknown_inner
;
182 IInternetProtocolEx IInternetProtocolEx_iface
;
183 IInternetPriority IInternetPriority_iface
;
189 static Protocol
*protocol_emul
;
191 static const WCHAR protocol_names
[][10] = {
194 {'h','t','t','p','s',0},
201 static const WCHAR binding_urls
[][130] = {
202 {'f','i','l','e',':','t','e','s','t','.','h','t','m','l',0},
203 {'h','t','t','p',':','/','/','w','w','w','.','w','i','n','e','h','q','.',
204 'o','r','g','/','s','i','t','e','/','a','b','o','u','t',0},
205 {'h','t','t','p','s',':','/','/','w','w','w','.','c','o','d','e','w','e','a','v','e','r','s',
206 '.','c','o','m','/','t','e','s','t','.','h','t','m','l',0},
207 {'f','t','p',':','/','/','f','t','p','.','w','i','n','e','h','q','.','o','r','g',
208 '/','p','u','b','/','o','t','h','e','r',
209 '/','w','i','n','e','l','o','g','o','.','x','c','f','.','t','a','r','.','b','z','2',0},
210 {'m','k',':','t','e','s','t',0},
211 {'i','t','s',':','t','e','s','t','.','c','h','m',':',':','/','b','l','a','n','k','.','h','t','m','l',0},
212 {'t','e','s','t',':','/','/','f','i','l','e','.','h','t','m','l',0}
215 static const CHAR post_data
[] = "mode=Test";
217 static int strcmp_wa(LPCWSTR strw
, const char *stra
)
220 WideCharToMultiByte(CP_ACP
, 0, strw
, -1, buf
, sizeof(buf
), NULL
, NULL
);
221 return lstrcmpA(stra
, buf
);
224 static const char *w2a(LPCWSTR str
)
226 static char buf
[INTERNET_MAX_URL_LENGTH
];
227 WideCharToMultiByte(CP_ACP
, 0, str
, -1, buf
, sizeof(buf
), NULL
, NULL
);
231 static HRESULT WINAPI
HttpSecurity_QueryInterface(IHttpSecurity
*iface
, REFIID riid
, void **ppv
)
233 if(IsEqualGUID(&IID_IUnknown
, riid
)
234 || IsEqualGUID(&IID_IHttpSecurity
, riid
)) {
239 ok(0, "unexpected call\n");
240 return E_NOINTERFACE
;
243 static ULONG WINAPI
HttpSecurity_AddRef(IHttpSecurity
*iface
)
248 static ULONG WINAPI
HttpSecurity_Release(IHttpSecurity
*iface
)
253 static HRESULT WINAPI
HttpSecurity_GetWindow(IHttpSecurity
* iface
, REFGUID rguidReason
, HWND
*phwnd
)
255 trace("HttpSecurity_GetWindow\n");
260 static HRESULT WINAPI
HttpSecurity_OnSecurityProblem(IHttpSecurity
*iface
, DWORD dwProblem
)
262 win_skip("Security problem: %u\n", dwProblem
);
263 ok(dwProblem
== ERROR_INTERNET_SEC_CERT_REV_FAILED
|| dwProblem
== ERROR_INTERNET_INVALID_CA
,
264 "Expected got %u security problem\n", dwProblem
);
266 /* Only retry once */
267 if (security_problem
)
270 security_problem
= TRUE
;
271 if(dwProblem
== ERROR_INTERNET_INVALID_CA
)
273 SET_EXPECT(BeginningTransaction
);
278 static IHttpSecurityVtbl HttpSecurityVtbl
= {
279 HttpSecurity_QueryInterface
,
281 HttpSecurity_Release
,
282 HttpSecurity_GetWindow
,
283 HttpSecurity_OnSecurityProblem
286 static IHttpSecurity http_security
= { &HttpSecurityVtbl
};
288 static HRESULT WINAPI
HttpNegotiate_QueryInterface(IHttpNegotiate2
*iface
, REFIID riid
, void **ppv
)
290 if(IsEqualGUID(&IID_IUnknown
, riid
)
291 || IsEqualGUID(&IID_IHttpNegotiate
, riid
)
292 || IsEqualGUID(&IID_IHttpNegotiate2
, riid
)) {
297 ok(0, "unexpected call\n");
298 return E_NOINTERFACE
;
301 static ULONG WINAPI
HttpNegotiate_AddRef(IHttpNegotiate2
*iface
)
306 static ULONG WINAPI
HttpNegotiate_Release(IHttpNegotiate2
*iface
)
311 static HRESULT WINAPI
HttpNegotiate_BeginningTransaction(IHttpNegotiate2
*iface
, LPCWSTR szURL
,
312 LPCWSTR szHeaders
, DWORD dwReserved
, LPWSTR
*pszAdditionalHeaders
)
316 static const WCHAR wszHeaders
[] =
317 {'C','o','n','t','e','n','t','-','T','y','p','e',':',' ','a','p','p','l','i','c','a','t',
318 'i','o','n','/','x','-','w','w','w','-','f','o','r','m','-','u','r','l','e','n','c','o',
319 'd','e','d','\r','\n',0};
321 CHECK_EXPECT(BeginningTransaction
);
324 ok(!lstrcmpW(szURL
, binding_urls
[tested_protocol
]), "szURL != http_url\n");
326 ok(!lstrcmpW(szURL
, http_url
), "szURL != http_url\n");
327 ok(!dwReserved
, "dwReserved=%d, expected 0\n", dwReserved
);
328 ok(pszAdditionalHeaders
!= NULL
, "pszAdditionalHeaders == NULL\n");
329 if(pszAdditionalHeaders
)
331 ok(*pszAdditionalHeaders
== NULL
, "*pszAdditionalHeaders != NULL\n");
334 addl_headers
= CoTaskMemAlloc(sizeof(wszHeaders
));
335 memcpy(addl_headers
, wszHeaders
, sizeof(wszHeaders
));
336 *pszAdditionalHeaders
= addl_headers
;
343 static HRESULT WINAPI
HttpNegotiate_OnResponse(IHttpNegotiate2
*iface
, DWORD dwResponseCode
,
344 LPCWSTR szResponseHeaders
, LPCWSTR szRequestHeaders
, LPWSTR
*pszAdditionalRequestHeaders
)
346 CHECK_EXPECT(OnResponse
);
348 ok(dwResponseCode
== 200, "dwResponseCode=%d, expected 200\n", dwResponseCode
);
349 ok(szResponseHeaders
!= NULL
, "szResponseHeaders == NULL\n");
350 ok(szRequestHeaders
== NULL
, "szRequestHeaders != NULL\n");
351 ok(pszAdditionalRequestHeaders
== NULL
, "pszAdditionalHeaders != NULL\n");
356 static HRESULT WINAPI
HttpNegotiate_GetRootSecurityId(IHttpNegotiate2
*iface
,
357 BYTE
*pbSecurityId
, DWORD
*pcbSecurityId
, DWORD_PTR dwReserved
)
359 static const BYTE sec_id
[] = {'h','t','t','p',':','t','e','s','t',1,0,0,0};
361 CHECK_EXPECT(GetRootSecurityId
);
363 ok(!dwReserved
, "dwReserved=%ld, expected 0\n", dwReserved
);
364 ok(pbSecurityId
!= NULL
, "pbSecurityId == NULL\n");
365 ok(pcbSecurityId
!= NULL
, "pcbSecurityId == NULL\n");
368 ok(*pcbSecurityId
== 512, "*pcbSecurityId=%d, expected 512\n", *pcbSecurityId
);
369 *pcbSecurityId
= sizeof(sec_id
);
373 memcpy(pbSecurityId
, sec_id
, sizeof(sec_id
));
378 static IHttpNegotiate2Vtbl HttpNegotiateVtbl
= {
379 HttpNegotiate_QueryInterface
,
380 HttpNegotiate_AddRef
,
381 HttpNegotiate_Release
,
382 HttpNegotiate_BeginningTransaction
,
383 HttpNegotiate_OnResponse
,
384 HttpNegotiate_GetRootSecurityId
387 static IHttpNegotiate2 http_negotiate
= { &HttpNegotiateVtbl
};
389 static HRESULT WINAPI
BindCallbackRedirect_QueryInterface(IBindCallbackRedirect
*iface
, REFIID riid
, void **ppv
)
391 ok(0, "unexpected call %s\n", wine_dbgstr_guid(riid
));
393 return E_NOINTERFACE
;
396 static ULONG WINAPI
BindCallbackRedirect_AddRef(IBindCallbackRedirect
*iface
)
401 static ULONG WINAPI
BindCallbackRedirect_Release(IBindCallbackRedirect
*iface
)
406 static HRESULT WINAPI
BindCallbackRedirect_Redirect(IBindCallbackRedirect
*iface
, const WCHAR
*url
, VARIANT_BOOL
*cancel
)
408 CHECK_EXPECT(Redirect
);
409 *cancel
= VARIANT_FALSE
;
413 static const IBindCallbackRedirectVtbl BindCallbackRedirectVtbl
= {
414 BindCallbackRedirect_QueryInterface
,
415 BindCallbackRedirect_AddRef
,
416 BindCallbackRedirect_Release
,
417 BindCallbackRedirect_Redirect
420 static IBindCallbackRedirect redirect_callback
= { &BindCallbackRedirectVtbl
};
422 static HRESULT
QueryInterface(REFIID
,void**);
424 static HRESULT WINAPI
ServiceProvider_QueryInterface(IServiceProvider
*iface
, REFIID riid
, void **ppv
)
426 return QueryInterface(riid
, ppv
);
429 static ULONG WINAPI
ServiceProvider_AddRef(IServiceProvider
*iface
)
434 static ULONG WINAPI
ServiceProvider_Release(IServiceProvider
*iface
)
439 static HRESULT WINAPI
ServiceProvider_QueryService(IServiceProvider
*iface
, REFGUID guidService
,
440 REFIID riid
, void **ppv
)
442 if(IsEqualGUID(&IID_IHttpNegotiate
, guidService
) || IsEqualGUID(&IID_IHttpNegotiate2
, riid
)) {
443 CHECK_EXPECT2(QueryService_HttpNegotiate
);
444 return IHttpNegotiate2_QueryInterface(&http_negotiate
, riid
, ppv
);
447 if(IsEqualGUID(&IID_IInternetProtocol
, guidService
)) {
448 ok(IsEqualGUID(&IID_IInternetProtocol
, riid
), "unexpected riid\n");
449 CHECK_EXPECT(QueryService_InternetProtocol
);
450 return E_NOINTERFACE
;
453 if(IsEqualGUID(&IID_IHttpSecurity
, guidService
)) {
454 ok(IsEqualGUID(&IID_IHttpSecurity
, riid
), "unexpected riid\n");
455 CHECK_EXPECT(QueryService_HttpSecurity
);
456 return IHttpSecurity_QueryInterface(&http_security
, riid
, ppv
);
459 if(IsEqualGUID(&IID_IBindCallbackRedirect
, guidService
)) {
460 CHECK_EXPECT(QueryService_IBindCallbackRedirect
);
461 ok(IsEqualGUID(&IID_IBindCallbackRedirect
, riid
), "riid = %s\n", wine_dbgstr_guid(riid
));
462 *ppv
= &redirect_callback
;
466 if(IsEqualGUID(&IID_IGetBindHandle
, guidService
)) {
467 trace("QueryService(IID_IGetBindHandle)\n");
469 return E_NOINTERFACE
;
472 if(IsEqualGUID(&IID_IWindowForBindingUI
, guidService
)) {
473 trace("QueryService(IID_IWindowForBindingUI)\n");
475 return E_NOINTERFACE
;
478 ok(0, "unexpected service %s\n", wine_dbgstr_guid(guidService
));
482 static const IServiceProviderVtbl ServiceProviderVtbl
= {
483 ServiceProvider_QueryInterface
,
484 ServiceProvider_AddRef
,
485 ServiceProvider_Release
,
486 ServiceProvider_QueryService
489 static IServiceProvider service_provider
= { &ServiceProviderVtbl
};
491 static HRESULT WINAPI
Stream_QueryInterface(IStream
*iface
, REFIID riid
, void **ppv
)
493 static const IID IID_strm_unknown
= {0x2f68429a,0x199a,0x4043,{0x93,0x11,0xf2,0xfe,0x7c,0x13,0xcc,0xb9}};
495 if(!IsEqualGUID(&IID_strm_unknown
, riid
)) /* IE11 */
496 ok(0, "unexpected call %s\n", wine_dbgstr_guid(riid
));
499 return E_NOINTERFACE
;
502 static ULONG WINAPI
Stream_AddRef(IStream
*iface
)
507 static ULONG WINAPI
Stream_Release(IStream
*iface
)
512 static HRESULT WINAPI
Stream_Read(IStream
*iface
, void *pv
,
513 ULONG cb
, ULONG
*pcbRead
)
515 CHECK_EXPECT2(Stream_Read
);
517 ok(GetCurrentThreadId() != thread_id
, "wrong thread %d\n", GetCurrentThreadId());
519 ok(pv
!= NULL
, "pv == NULL\n");
520 ok(cb
== 0x20000 || broken(cb
== 0x2000), "cb = %d\n", cb
);
521 ok(pcbRead
!= NULL
, "pcbRead == NULL\n");
523 if(post_stream_read
) {
528 memcpy(pv
, post_data
, sizeof(post_data
)-1);
529 post_stream_read
+= *pcbRead
= sizeof(post_data
)-1;
533 static HRESULT WINAPI
Stream_Write(IStream
*iface
, const void *pv
,
534 ULONG cb
, ULONG
*pcbWritten
)
536 ok(0, "unexpected call\n");
540 static HRESULT WINAPI
Stream_Seek(IStream
*iface
, LARGE_INTEGER dlibMove
,
541 DWORD dwOrigin
, ULARGE_INTEGER
*plibNewPosition
)
543 CHECK_EXPECT(Stream_Seek
);
545 ok(!dlibMove
.QuadPart
, "dlibMove != 0\n");
546 ok(dwOrigin
== STREAM_SEEK_SET
, "dwOrigin = %d\n", dwOrigin
);
547 ok(!plibNewPosition
, "plibNewPosition == NULL\n");
552 static HRESULT WINAPI
Stream_SetSize(IStream
*iface
, ULARGE_INTEGER libNewSize
)
554 ok(0, "unexpected call\n");
558 static HRESULT WINAPI
Stream_CopyTo(IStream
*iface
, IStream
*pstm
,
559 ULARGE_INTEGER cb
, ULARGE_INTEGER
*pcbRead
, ULARGE_INTEGER
*pcbWritten
)
561 ok(0, "unexpected call\n");
565 static HRESULT WINAPI
Stream_Commit(IStream
*iface
, DWORD grfCommitFlags
)
567 ok(0, "unexpected call\n");
571 static HRESULT WINAPI
Stream_Revert(IStream
*iface
)
573 ok(0, "unexpected call\n");
577 static HRESULT WINAPI
Stream_LockRegion(IStream
*iface
, ULARGE_INTEGER libOffset
,
578 ULARGE_INTEGER cb
, DWORD dwLockType
)
580 ok(0, "unexpected call\n");
584 static HRESULT WINAPI
Stream_UnlockRegion(IStream
*iface
,
585 ULARGE_INTEGER libOffset
, ULARGE_INTEGER cb
, DWORD dwLockType
)
587 ok(0, "unexpected call\n");
591 static HRESULT WINAPI
Stream_Stat(IStream
*iface
, STATSTG
*pstatstg
,
594 ok(0, "unexpected call\n");
598 static HRESULT WINAPI
Stream_Clone(IStream
*iface
, IStream
**ppstm
)
600 ok(0, "unexpected call\n");
604 static const IStreamVtbl StreamVtbl
= {
605 Stream_QueryInterface
,
621 static IStream Stream
= { &StreamVtbl
};
623 static HRESULT WINAPI
ProtocolSink_QueryInterface(IInternetProtocolSink
*iface
, REFIID riid
, void **ppv
)
625 return QueryInterface(riid
, ppv
);
628 static ULONG WINAPI
ProtocolSink_AddRef(IInternetProtocolSink
*iface
)
633 static ULONG WINAPI
ProtocolSink_Release(IInternetProtocolSink
*iface
)
638 static void call_continue(PROTOCOLDATA
*protocol_data
)
642 if (winetest_debug
> 1)
643 trace("continue in state %d\n", state
);
645 if(state
== STATE_CONNECTING
) {
646 if(tested_protocol
== HTTP_TEST
|| tested_protocol
== HTTPS_TEST
|| tested_protocol
== FTP_TEST
) {
648 CLEAR_CALLED(ReportProgress_FINDINGRESOURCE
);
649 CLEAR_CALLED(ReportProgress_PROXYDETECTING
);
651 CLEAR_CALLED(ReportProgress_CONNECTING
);
653 if(tested_protocol
== FTP_TEST
)
654 todo_wine
CHECK_CALLED(ReportProgress_SENDINGREQUEST
);
655 else if (tested_protocol
!= HTTPS_TEST
)
656 CHECK_CALLED(ReportProgress_SENDINGREQUEST
);
657 if(test_redirect
&& !(bindinfo_options
& BINDINFO_OPTIONS_DISABLEAUTOREDIRECTS
))
658 CHECK_CALLED(ReportProgress_REDIRECTING
);
659 state
= test_async_req
? STATE_SENDINGREQUEST
: STATE_STARTDOWNLOADING
;
663 case STATE_SENDINGREQUEST
:
664 SET_EXPECT(Stream_Read
);
665 SET_EXPECT(ReportProgress_SENDINGREQUEST
);
667 case STATE_STARTDOWNLOADING
:
668 if((tested_protocol
== HTTP_TEST
|| tested_protocol
== HTTPS_TEST
)
669 && (!test_redirect
|| !(bindinfo_options
& BINDINFO_OPTIONS_DISABLEAUTOREDIRECTS
))) {
670 SET_EXPECT(OnResponse
);
671 if(tested_protocol
== HTTPS_TEST
|| test_redirect
|| test_abort
|| empty_file
)
672 SET_EXPECT(ReportProgress_ACCEPTRANGES
);
673 SET_EXPECT(ReportProgress_ENCODING
);
674 SET_EXPECT(ReportProgress_MIMETYPEAVAILABLE
);
675 if(bindf
& BINDF_NEEDFILE
)
676 SET_EXPECT(ReportProgress_CACHEFILENAMEAVAILABLE
);
682 if(state
!= STATE_SENDINGREQUEST
&& (!test_redirect
|| !(bindinfo_options
& BINDINFO_OPTIONS_DISABLEAUTOREDIRECTS
)))
683 SET_EXPECT(ReportData
);
684 hres
= IInternetProtocol_Continue(async_protocol
, protocol_data
);
685 ok(hres
== S_OK
, "Continue failed: %08x\n", hres
);
686 if(tested_protocol
== FTP_TEST
|| security_problem
)
687 CLEAR_CALLED(ReportData
);
688 else if(state
!= STATE_SENDINGREQUEST
&& (!test_redirect
|| !(bindinfo_options
& BINDINFO_OPTIONS_DISABLEAUTOREDIRECTS
)))
689 CHECK_CALLED(ReportData
);
692 case STATE_SENDINGREQUEST
:
693 CHECK_CALLED(Stream_Read
);
694 CHECK_CALLED(ReportProgress_SENDINGREQUEST
);
695 state
= STATE_STARTDOWNLOADING
;
697 case STATE_STARTDOWNLOADING
:
698 if(!security_problem
) {
699 state
= STATE_DOWNLOADING
;
700 if((tested_protocol
== HTTP_TEST
|| tested_protocol
== HTTPS_TEST
)
701 && (!test_redirect
|| !(bindinfo_options
& BINDINFO_OPTIONS_DISABLEAUTOREDIRECTS
))) {
702 CHECK_CALLED(OnResponse
);
703 if(tested_protocol
== HTTPS_TEST
|| empty_file
)
704 CHECK_CALLED(ReportProgress_ACCEPTRANGES
);
705 else if(test_redirect
|| test_abort
)
706 CLEAR_CALLED(ReportProgress_ACCEPTRANGES
);
707 CLEAR_CALLED(ReportProgress_ENCODING
);
708 CHECK_CALLED(ReportProgress_MIMETYPEAVAILABLE
);
709 if(bindf
& BINDF_NEEDFILE
)
710 CHECK_CALLED(ReportProgress_CACHEFILENAMEAVAILABLE
);
715 security_problem
= FALSE
;
716 SET_EXPECT(ReportProgress_CONNECTING
);
723 static HRESULT WINAPI
ProtocolSink_Switch(IInternetProtocolSink
*iface
, PROTOCOLDATA
*pProtocolData
)
725 if(tested_protocol
== FTP_TEST
)
726 CHECK_EXPECT2(Switch
);
728 CHECK_EXPECT(Switch
);
730 ok(pProtocolData
!= NULL
, "pProtocolData == NULL\n");
732 ok(pProtocolData
!= &protocoldata
, "pProtocolData == &protocoldata\n");
733 ok(pProtocolData
->grfFlags
== protocoldata
.grfFlags
, "grfFlags wrong %x/%x\n",
734 pProtocolData
->grfFlags
, protocoldata
.grfFlags
);
735 ok(pProtocolData
->dwState
== protocoldata
.dwState
, "dwState wrong %x/%x\n",
736 pProtocolData
->dwState
, protocoldata
.dwState
);
737 ok(pProtocolData
->pData
== protocoldata
.pData
, "pData wrong %p/%p\n",
738 pProtocolData
->pData
, protocoldata
.pData
);
739 ok(pProtocolData
->cbData
== protocoldata
.cbData
, "cbData wrong %x/%x\n",
740 pProtocolData
->cbData
, protocoldata
.cbData
);
743 pdata
= pProtocolData
;
746 SetEvent(event_complete
);
747 ok( WaitForSingleObject(event_complete2
, 90000) == WAIT_OBJECT_0
, "wait timed out\n" );
750 continue_protdata
= *pProtocolData
;
751 SetEvent(event_continue
);
752 ok( WaitForSingleObject(event_continue_done
, 90000) == WAIT_OBJECT_0
, "wait timed out\n" );
754 call_continue(pProtocolData
);
755 SetEvent(event_complete
);
761 static const char *status_names
[] =
770 "BEGINDOWNLOADCOMPONENTS",
771 "INSTALLINGCOMPONENTS",
772 "ENDDOWNLOADCOMPONENTS",
777 "CACHEFILENAMEAVAILABLE",
778 "BEGINSYNCOPERATION",
785 "VERIFIEDMIMETYPEAVAILABLE",
786 "CLASSINSTALLLOCATION",
788 "LOADINGMIMEHANDLER",
789 "CONTENTDISPOSITIONATTACH",
790 "FILTERREPORTMIMETYPE",
791 "CLSIDCANINSTANTIATE",
798 "COMPACT_POLICY_RECEIVED",
800 "COOKIE_STATE_UNKNOWN",
801 "COOKIE_STATE_ACCEPT",
802 "COOKIE_STATE_REJECT",
803 "COOKIE_STATE_PROMPT",
804 "COOKIE_STATE_LEASH",
805 "COOKIE_STATE_DOWNGRADE",
808 "SESSION_COOKIE_RECEIVED",
809 "PERSISTENT_COOKIE_RECEIVED",
810 "SESSION_COOKIES_ALLOWED",
812 "CONTENTDISPOSITIONFILENAME",
813 "MIMETEXTPLAINMISMATCH",
814 "PUBLISHERAVAILABLE",
815 "DISPLAYNAMEAVAILABLE"
818 static HRESULT WINAPI
ProtocolSink_ReportProgress(IInternetProtocolSink
*iface
, ULONG ulStatusCode
,
819 LPCWSTR szStatusText
)
821 static const WCHAR null_guid
[] = {'{','0','0','0','0','0','0','0','0','-','0','0','0','0','-',
822 '0','0','0','0','-','0','0','0','0','-','0','0','0','0','0','0','0','0','0','0','0','0','}',0};
823 static const WCHAR text_plain
[] = {'t','e','x','t','/','p','l','a','i','n',0};
825 if (winetest_debug
> 1)
827 if (ulStatusCode
< sizeof(status_names
)/sizeof(status_names
[0]))
828 trace( "progress: %s %s\n", status_names
[ulStatusCode
], wine_dbgstr_w(szStatusText
) );
830 trace( "progress: %u %s\n", ulStatusCode
, wine_dbgstr_w(szStatusText
) );
833 switch(ulStatusCode
) {
834 case BINDSTATUS_MIMETYPEAVAILABLE
:
835 CHECK_EXPECT2(ReportProgress_MIMETYPEAVAILABLE
);
836 if(tested_protocol
!= FILE_TEST
&& tested_protocol
!= ITS_TEST
&& !mimefilter_test
&& (pi
& PI_MIMEVERIFICATION
)) {
837 if(!short_read
|| !direct_read
)
838 CHECK_CALLED(Read
); /* set in Continue */
840 CHECK_CALLED(Read2
); /* set in Read */
842 ok(szStatusText
!= NULL
, "szStatusText == NULL\n");
844 if(tested_protocol
== BIND_TEST
)
845 ok(!lstrcmpW(szStatusText
, expect_wsz
), "unexpected szStatusText %s\n", wine_dbgstr_w(szStatusText
));
846 else if (http_post_test
)
847 ok(lstrlenW(text_plain
) <= lstrlenW(szStatusText
) &&
848 !memcmp(szStatusText
, text_plain
, lstrlenW(text_plain
)*sizeof(WCHAR
)),
849 "szStatusText != text/plain\n");
851 ok(!strcmp_wa(szStatusText
, "application/javascript"), "szStatusText = %s\n", wine_dbgstr_w(szStatusText
));
852 else if((pi
& PI_MIMEVERIFICATION
) && emulate_prot
&& !mimefilter_test
853 && tested_protocol
==HTTP_TEST
&& !short_read
)
854 ok(lstrlenW(gifW
) <= lstrlenW(szStatusText
) &&
855 !memcmp(szStatusText
, gifW
, lstrlenW(gifW
)*sizeof(WCHAR
)),
856 "szStatusText != image/gif\n");
857 else if(!mimefilter_test
)
858 ok(lstrlenW(text_htmlW
) <= lstrlenW(szStatusText
) &&
859 !memcmp(szStatusText
, text_htmlW
, lstrlenW(text_htmlW
)*sizeof(WCHAR
)),
860 "szStatusText != text/html\n");
863 case BINDSTATUS_DIRECTBIND
:
864 CHECK_EXPECT2(ReportProgress_DIRECTBIND
);
865 ok(szStatusText
== NULL
, "szStatusText != NULL\n");
867 case BINDSTATUS_RAWMIMETYPE
:
868 CHECK_EXPECT2(ReportProgress_RAWMIMETYPE
);
869 ok(szStatusText
!= NULL
, "szStatusText == NULL\n");
871 ok(lstrlenW(szStatusText
) < lstrlenW(text_htmlW
) ||
872 !memcmp(szStatusText
, text_htmlW
, lstrlenW(text_htmlW
)*sizeof(WCHAR
)),
873 "szStatusText != text/html\n");
875 case BINDSTATUS_CACHEFILENAMEAVAILABLE
:
876 CHECK_EXPECT(ReportProgress_CACHEFILENAMEAVAILABLE
);
877 ok(szStatusText
!= NULL
, "szStatusText == NULL\n");
880 ok(!lstrcmpW(szStatusText
, expect_wsz
), "unexpected szStatusText\n");
881 else if(tested_protocol
== FILE_TEST
)
882 ok(!lstrcmpW(szStatusText
, file_name
), "szStatusText = %s\n", wine_dbgstr_w(szStatusText
));
884 ok(szStatusText
!= NULL
, "szStatusText == NULL\n");
887 case BINDSTATUS_FINDINGRESOURCE
:
888 CHECK_EXPECT2(ReportProgress_FINDINGRESOURCE
);
889 ok(szStatusText
!= NULL
, "szStatusText == NULL\n");
891 case BINDSTATUS_CONNECTING
:
892 CHECK_EXPECT2(ReportProgress_CONNECTING
);
893 ok(szStatusText
!= NULL
, "szStatusText == NULL\n");
895 case BINDSTATUS_SENDINGREQUEST
:
896 CHECK_EXPECT2(ReportProgress_SENDINGREQUEST
);
897 if(tested_protocol
== FILE_TEST
|| tested_protocol
== ITS_TEST
) {
898 ok(szStatusText
!= NULL
, "szStatusText == NULL\n");
900 ok(!*szStatusText
, "wrong szStatusText\n");
903 case BINDSTATUS_VERIFIEDMIMETYPEAVAILABLE
:
904 CHECK_EXPECT(ReportProgress_VERIFIEDMIMETYPEAVAILABLE
);
905 ok(szStatusText
!= NULL
, "szStatusText == NULL\n");
907 ok(!strcmp_wa(szStatusText
, "text/html"), "szStatusText != text/html\n");
909 case BINDSTATUS_PROTOCOLCLASSID
:
910 CHECK_EXPECT(ReportProgress_PROTOCOLCLASSID
);
911 ok(szStatusText
!= NULL
, "szStatusText == NULL\n");
912 ok(!lstrcmpW(szStatusText
, null_guid
), "unexpected classid %s\n", wine_dbgstr_w(szStatusText
));
914 case BINDSTATUS_COOKIE_SENT
:
915 CHECK_EXPECT2(ReportProgress_COOKIE_SENT
);
916 ok(szStatusText
== NULL
, "szStatusText != NULL\n");
918 case BINDSTATUS_REDIRECTING
:
919 CHECK_EXPECT(ReportProgress_REDIRECTING
);
921 ok(!strcmp_wa(szStatusText
, "http://test.winehq.org/tests/hello.html"), "szStatusText = %s\n", wine_dbgstr_w(szStatusText
));
923 ok(szStatusText
== NULL
, "szStatusText = %s\n", wine_dbgstr_w(szStatusText
));
925 case BINDSTATUS_ENCODING
:
926 CHECK_EXPECT(ReportProgress_ENCODING
);
927 ok(!strcmp_wa(szStatusText
, "gzip"), "szStatusText = %s\n", wine_dbgstr_w(szStatusText
));
929 case BINDSTATUS_ACCEPTRANGES
:
930 CHECK_EXPECT(ReportProgress_ACCEPTRANGES
);
931 ok(!szStatusText
, "szStatusText = %s\n", wine_dbgstr_w(szStatusText
));
933 case BINDSTATUS_PROXYDETECTING
:
934 if(!called_ReportProgress_PROXYDETECTING
)
935 SET_EXPECT(ReportProgress_CONNECTING
);
936 CHECK_EXPECT2(ReportProgress_PROXYDETECTING
);
937 ok(!szStatusText
, "szStatusText = %s\n", wine_dbgstr_w(szStatusText
));
939 case BINDSTATUS_LOADINGMIMEHANDLER
:
940 CHECK_EXPECT(ReportProgress_LOADINGMIMEHANDLER
);
941 ok(!szStatusText
, "szStatusText = %s\n", wine_dbgstr_w(szStatusText
));
943 case BINDSTATUS_DECODING
:
944 CHECK_EXPECT(ReportProgress_DECODING
);
945 ok(!lstrcmpW(szStatusText
, pjpegW
), "szStatusText = %s\n", wine_dbgstr_w(szStatusText
));
947 case BINDSTATUS_RESERVED_7
:
948 trace("BINDSTATUS_RESERVED_7\n");
950 case BINDSTATUS_RESERVED_8
:
951 trace("BINDSTATUS_RESERVED_8\n");
954 ok(0, "Unexpected status %d (%d)\n", ulStatusCode
, ulStatusCode
-BINDSTATUS_LAST
);
960 static void test_http_info(IInternetProtocol
*protocol
)
962 IWinInetHttpInfo
*info
;
967 static const WCHAR connectionW
[] = {'c','o','n','n','e','c','t','i','o','n',0};
969 hres
= IInternetProtocol_QueryInterface(protocol
, &IID_IWinInetHttpInfo
, (void**)&info
);
970 ok(hres
== S_OK
, "Could not get IWinInterHttpInfo iface: %08x\n", hres
);
973 strcpy(buf
, "connection");
974 hres
= IWinInetHttpInfo_QueryInfo(info
, HTTP_QUERY_CUSTOM
, buf
, &size
, NULL
, NULL
);
975 if(tested_protocol
!= FTP_TEST
) {
976 ok(hres
== S_OK
, "QueryInfo failed: %08x\n", hres
);
978 ok(!strcmp(buf
, "Keep-Alive"), "buf = %s\n", buf
);
980 ok(size
== len
, "size = %u, expected %u\n", size
, len
);
983 memcpy(buf
, connectionW
, sizeof(connectionW
));
984 hres
= IWinInetHttpInfo_QueryInfo(info
, HTTP_QUERY_CUSTOM
, buf
, &size
, NULL
, NULL
);
985 ok(hres
== S_FALSE
, "QueryInfo returned %08x\n", hres
);
987 ok(hres
== S_FALSE
, "QueryInfo failed: %08x\n", hres
);
990 IWinInetHttpInfo_Release(info
);
993 static HRESULT WINAPI
ProtocolSink_ReportData(IInternetProtocolSink
*iface
, DWORD grfBSCF
,
994 ULONG ulProgress
, ULONG ulProgressMax
)
998 static int rec_depth
;
1001 if(!mimefilter_test
&& (tested_protocol
== FILE_TEST
|| tested_protocol
== ITS_TEST
)) {
1002 CHECK_EXPECT2(ReportData
);
1004 ok(ulProgress
== ulProgressMax
, "ulProgress (%d) != ulProgressMax (%d)\n",
1005 ulProgress
, ulProgressMax
);
1007 ok(ulProgressMax
== 13, "ulProgressMax=%d, expected 13\n", ulProgressMax
);
1008 /* BSCF_SKIPDRAINDATAFORFILEURLS added in IE8 */
1009 if(tested_protocol
== FILE_TEST
)
1010 ok((grfBSCF
== (BSCF_FIRSTDATANOTIFICATION
| BSCF_LASTDATANOTIFICATION
)) ||
1011 (grfBSCF
== (BSCF_FIRSTDATANOTIFICATION
| BSCF_LASTDATANOTIFICATION
| BSCF_SKIPDRAINDATAFORFILEURLS
)),
1012 "grcfBSCF = %08x\n", grfBSCF
);
1014 ok(grfBSCF
== (BSCF_FIRSTDATANOTIFICATION
| BSCF_DATAFULLYAVAILABLE
), "grcfBSCF = %08x\n", grfBSCF
);
1015 }else if(bind_from_cache
) {
1016 CHECK_EXPECT(ReportData
);
1018 ok(grfBSCF
== (BSCF_LASTDATANOTIFICATION
|BSCF_DATAFULLYAVAILABLE
), "grcfBSCF = %08x\n", grfBSCF
);
1019 ok(ulProgress
== 1000, "ulProgress = %u\n", ulProgress
);
1020 ok(!ulProgressMax
, "ulProgressMax = %u\n", ulProgressMax
);
1021 }else if(direct_read
) {
1025 if(!read_report_data
&& rec_depth
== 1) {
1026 BOOL reported_all_data
= called_ReportData2
;
1028 CHECK_EXPECT2(ReportData
);
1031 ok(grfBSCF
== (BSCF_FIRSTDATANOTIFICATION
|BSCF_LASTDATANOTIFICATION
|BSCF_DATAFULLYAVAILABLE
)
1032 || grfBSCF
== BSCF_FIRSTDATANOTIFICATION
, /* < IE8 */
1033 "grcfBSCF = %08x\n", grfBSCF
);
1034 CHECK_CALLED(Read
); /* Set in Continue */
1035 first_data_notif
= FALSE
;
1036 }else if(first_data_notif
) {
1037 ok(grfBSCF
== BSCF_FIRSTDATANOTIFICATION
, "grcfBSCF = %08x\n", grfBSCF
);
1038 first_data_notif
= FALSE
;
1039 }else if(reported_all_data
) {
1040 ok(grfBSCF
== (BSCF_LASTDATANOTIFICATION
|BSCF_INTERMEDIATEDATANOTIFICATION
),
1041 "grcfBSCF = %08x\n", grfBSCF
);
1042 }else if(!direct_read
) {
1043 ok(grfBSCF
== BSCF_INTERMEDIATEDATANOTIFICATION
, "grcfBSCF = %08x\n", grfBSCF
);
1051 SET_EXPECT(ReportData2
);
1052 SET_EXPECT(ReportResult
);
1055 hres
= IInternetProtocol_Read(binding_test
? binding_protocol
: async_protocol
, expect_pv
= buf
, sizeof(buf
), &read
);
1056 ok(hres
== E_PENDING
|| hres
== S_FALSE
|| hres
== S_OK
, "Read failed: %08x\n", hres
);
1058 ok(read
, "read == 0\n");
1059 if(reported_all_data
)
1060 ok(hres
== S_FALSE
, "Read failed: %08x, expected S_FALSE\n", hres
);
1061 if(!emulate_prot
&& hres
!= E_PENDING
)
1062 CHECK_NOT_CALLED(Switch
); /* otherwise checked in wait_for_switch loop */
1065 if(!reported_all_data
&& called_ReportData2
) {
1067 CHECK_CALLED(ReportData2
);
1068 CHECK_CALLED(ReportResult
);
1069 reported_all_data
= TRUE
;
1072 CHECK_NOT_CALLED(ReportData2
);
1073 CHECK_NOT_CALLED(ReportResult
);
1075 }while(hres
== S_OK
);
1077 wait_for_switch
= FALSE
;
1079 CHECK_EXPECT(ReportData2
);
1081 ok(grfBSCF
& BSCF_LASTDATANOTIFICATION
, "grfBSCF = %08x\n", grfBSCF
);
1086 hres
= IInternetProtocol_Read(binding_test
? binding_protocol
: async_protocol
, expect_pv
= buf
, sizeof(buf
), &read
);
1088 CHECK_CALLED(Read2
);
1089 ok(hres
== S_FALSE
, "Read returned: %08x, expected E_FALSE\n", hres
);
1090 ok(!read
, "read = %d\n", read
);
1092 }else if(!binding_test
&& (tested_protocol
== HTTP_TEST
|| tested_protocol
== HTTPS_TEST
1093 || tested_protocol
== FTP_TEST
)) {
1095 CHECK_EXPECT2(ReportData
);
1096 else if(!(grfBSCF
& BSCF_LASTDATANOTIFICATION
) || (grfBSCF
& BSCF_DATAFULLYAVAILABLE
))
1097 CHECK_EXPECT(ReportData
);
1098 else if (http_post_test
)
1099 ok(ulProgress
== 13, "Read %u bytes instead of 13\n", ulProgress
);
1102 ok(!ulProgress
, "ulProgress = %d\n", ulProgress
);
1103 ok(!ulProgressMax
, "ulProgressMax = %d\n", ulProgressMax
);
1105 ok(ulProgress
, "ulProgress == 0\n");
1109 ok(grfBSCF
== (BSCF_FIRSTDATANOTIFICATION
|BSCF_LASTDATANOTIFICATION
),
1110 "grcfBSCF = %08x\n", grfBSCF
);
1111 first_data_notif
= FALSE
;
1112 }else if(first_data_notif
) {
1113 ok(grfBSCF
== BSCF_FIRSTDATANOTIFICATION
1114 || grfBSCF
== (BSCF_LASTDATANOTIFICATION
|BSCF_DATAFULLYAVAILABLE
),
1115 "grcfBSCF = %08x\n", grfBSCF
);
1116 first_data_notif
= FALSE
;
1118 ok(grfBSCF
== BSCF_INTERMEDIATEDATANOTIFICATION
1119 || grfBSCF
== (BSCF_LASTDATANOTIFICATION
|BSCF_INTERMEDIATEDATANOTIFICATION
)
1120 || broken(grfBSCF
== (BSCF_FIRSTDATANOTIFICATION
|BSCF_LASTDATANOTIFICATION
)),
1121 "grcfBSCF = %08x\n", grfBSCF
);
1124 if((grfBSCF
& BSCF_FIRSTDATANOTIFICATION
) && !binding_test
)
1125 test_http_info(async_protocol
);
1127 if(!(bindf
& BINDF_FROMURLMON
) &&
1128 !(grfBSCF
& BSCF_LASTDATANOTIFICATION
)) {
1129 if(state
== STATE_CONNECTING
) {
1130 state
= STATE_DOWNLOADING
;
1132 CHECK_CALLED(ReportProgress_FINDINGRESOURCE
);
1133 CHECK_CALLED(ReportProgress_CONNECTING
);
1135 CHECK_CALLED(ReportProgress_SENDINGREQUEST
);
1136 CHECK_CALLED(OnResponse
);
1137 CHECK_CALLED(ReportProgress_RAWMIMETYPE
);
1139 SetEvent(event_complete
);
1141 }else if(!read_report_data
) {
1146 CHECK_EXPECT(ReportData
);
1148 if(tested_protocol
!= BIND_TEST
) {
1151 SET_EXPECT(MimeFilter_Read
);
1152 else if(rec_depth
> 1)
1156 hres
= IInternetProtocol_Read(binding_protocol
, expect_pv
=buf
, sizeof(buf
), &read
);
1158 CHECK_CALLED(MimeFilter_Read
);
1159 else if(rec_depth
> 1)
1160 CHECK_CALLED(Read2
);
1163 }while(hres
== S_OK
);
1171 static HRESULT WINAPI
ProtocolSink_ReportResult(IInternetProtocolSink
*iface
, HRESULT hrResult
,
1172 DWORD dwError
, LPCWSTR szResult
)
1174 CHECK_EXPECT(ReportResult
);
1176 if(security_problem
)
1179 if(tested_protocol
== FTP_TEST
)
1180 ok(hrResult
== E_PENDING
|| hrResult
== S_OK
, "hrResult = %08x, expected E_PENDING or S_OK\n", hrResult
);
1182 ok(hrResult
== expect_hrResult
, "hrResult = %08x, expected: %08x\n",
1183 hrResult
, expect_hrResult
);
1185 if(!winetest_interactive
&& tested_protocol
!= FTP_TEST
&& hrResult
!= expect_hrResult
) {
1186 skip("CORE-10360/ROSTESTS-192: Test might hang, skipping the rest!\n");
1190 if(SUCCEEDED(hrResult
) || tested_protocol
== FTP_TEST
|| test_abort
|| hrResult
== INET_E_REDIRECT_FAILED
)
1191 ok(dwError
== ERROR_SUCCESS
, "dwError = %d, expected ERROR_SUCCESS\n", dwError
);
1193 ok(dwError
!= ERROR_SUCCESS
||
1194 broken(tested_protocol
== MK_TEST
), /* WinME and NT4 */
1195 "dwError == ERROR_SUCCESS\n");
1197 if(hrResult
== INET_E_REDIRECT_FAILED
)
1198 ok(!strcmp_wa(szResult
, "http://test.winehq.org/tests/hello.html"), "szResult = %s\n", wine_dbgstr_w(szResult
));
1200 ok(!szResult
, "szResult = %s\n", wine_dbgstr_w(szResult
));
1203 SET_EXPECT(ReportData
); /* checked after main loop */
1208 static IInternetProtocolSinkVtbl protocol_sink_vtbl
= {
1209 ProtocolSink_QueryInterface
,
1210 ProtocolSink_AddRef
,
1211 ProtocolSink_Release
,
1212 ProtocolSink_Switch
,
1213 ProtocolSink_ReportProgress
,
1214 ProtocolSink_ReportData
,
1215 ProtocolSink_ReportResult
1218 static IInternetProtocolSink protocol_sink
= { &protocol_sink_vtbl
};
1220 static HRESULT WINAPI
MimeProtocolSink_QueryInterface(IInternetProtocolSink
*iface
, REFIID riid
, void **ppv
)
1222 if(IsEqualGUID(&IID_IUnknown
, riid
)
1223 || IsEqualGUID(&IID_IInternetProtocolSink
, riid
)) {
1228 ok(0, "unexpected call\n");
1232 static ULONG WINAPI
MimeProtocolSink_AddRef(IInternetProtocolSink
*iface
)
1237 static ULONG WINAPI
MimeProtocolSink_Release(IInternetProtocolSink
*iface
)
1242 static HRESULT WINAPI
MimeProtocolSink_Switch(IInternetProtocolSink
*iface
, PROTOCOLDATA
*pProtocolData
)
1246 CHECK_EXPECT(MimeFilter_Switch
);
1249 hres
= IInternetProtocolSink_Switch(filtered_sink
, pProtocolData
);
1250 ok(hres
== S_OK
, "Switch failed: %08x\n", hres
);
1251 CHECK_CALLED(Switch
);
1256 static HRESULT WINAPI
MimeProtocolSink_ReportProgress(IInternetProtocolSink
*iface
, ULONG ulStatusCode
,
1257 LPCWSTR szStatusText
)
1259 switch(ulStatusCode
) {
1260 case BINDSTATUS_LOADINGMIMEHANDLER
:
1262 * IE9 for some reason (bug?) calls this on mime handler's protocol sink instead of the
1263 * main protocol sink. We check ReportProgress_LOADINGMIMEHANDLER both here and in
1264 * ProtocolSink_ReportProgress to workaround it.
1266 CHECK_EXPECT(ReportProgress_LOADINGMIMEHANDLER
);
1267 ok(!szStatusText
, "szStatusText = %s\n", wine_dbgstr_w(szStatusText
));
1270 ok(0, "Unexpected status code %d\n", ulStatusCode
);
1276 static HRESULT WINAPI
MimeProtocolSink_ReportData(IInternetProtocolSink
*iface
, DWORD grfBSCF
,
1277 ULONG ulProgress
, ULONG ulProgressMax
)
1282 BOOL report_mime
= FALSE
;
1284 CHECK_EXPECT(MimeFilter_ReportData
);
1286 if(!filter_state
&& !no_mime
) {
1288 hres
= IInternetProtocol_Read(filtered_protocol
, buf
, sizeof(buf
), &read
);
1289 if(tested_protocol
== HTTP_TEST
)
1290 ok(hres
== S_OK
|| hres
== E_PENDING
|| hres
== S_FALSE
, "Read failed: %08x\n", hres
);
1292 ok(hres
== S_OK
, "Read failed: %08x\n", hres
);
1295 SET_EXPECT(ReportProgress_MIMETYPEAVAILABLE
);
1296 hres
= IInternetProtocolSink_ReportProgress(filtered_sink
, BINDSTATUS_VERIFIEDMIMETYPEAVAILABLE
, text_htmlW
);
1297 ok(hres
== S_OK
, "ReportProgress failed: %08x\n", hres
);
1298 CHECK_CALLED(ReportProgress_MIMETYPEAVAILABLE
);
1300 SET_EXPECT(ReportProgress_MIMETYPEAVAILABLE
);
1301 hres
= IInternetProtocolSink_ReportProgress(filtered_sink
, BINDSTATUS_MIMETYPEAVAILABLE
, text_htmlW
);
1302 ok(hres
== S_OK
, "ReportProgress failed: %08x\n", hres
);
1303 CHECK_CALLED(ReportProgress_MIMETYPEAVAILABLE
);
1305 /* FIXME: test BINDSTATUS_CACHEFILENAMEAVAILABLE */
1308 if(no_mime
&& prot_read
<200) {
1310 }else if(no_mime
&& prot_read
<300) {
1313 SET_EXPECT(ReportProgress_MIMETYPEAVAILABLE
);
1314 SET_EXPECT(ReportData
);
1315 }else if(!read_report_data
) {
1316 SET_EXPECT(ReportData
);
1318 hres
= IInternetProtocolSink_ReportData(filtered_sink
, grfBSCF
, ulProgress
, ulProgressMax
);
1319 ok(hres
== S_OK
, "ReportData failed: %08x\n", hres
);
1320 if(no_mime
&& prot_read
<=200) {
1322 }else if(report_mime
) {
1323 CHECK_CALLED(ReportProgress_MIMETYPEAVAILABLE
);
1324 CHECK_CALLED(ReportData
);
1325 }else if(!read_report_data
) {
1326 CHECK_CALLED(ReportData
);
1335 static HRESULT WINAPI
MimeProtocolSink_ReportResult(IInternetProtocolSink
*iface
, HRESULT hrResult
,
1336 DWORD dwError
, LPCWSTR szResult
)
1340 CHECK_EXPECT(MimeFilter_ReportResult
);
1342 ok(hrResult
== S_OK
, "hrResult = %08x\n", hrResult
);
1343 ok(dwError
== ERROR_SUCCESS
, "dwError = %u\n", dwError
);
1344 ok(!szResult
, "szResult = %s\n", wine_dbgstr_w(szResult
));
1346 SET_EXPECT(ReportResult
);
1347 hres
= IInternetProtocolSink_ReportResult(filtered_sink
, hrResult
, dwError
, szResult
);
1348 ok(SUCCEEDED(hres
), "ReportResult failed: %08x\n", hres
);
1349 CHECK_CALLED(ReportResult
);
1354 static IInternetProtocolSinkVtbl mime_protocol_sink_vtbl
= {
1355 MimeProtocolSink_QueryInterface
,
1356 MimeProtocolSink_AddRef
,
1357 MimeProtocolSink_Release
,
1358 MimeProtocolSink_Switch
,
1359 MimeProtocolSink_ReportProgress
,
1360 MimeProtocolSink_ReportData
,
1361 MimeProtocolSink_ReportResult
1364 static IInternetProtocolSink mime_protocol_sink
= { &mime_protocol_sink_vtbl
};
1366 static HRESULT
QueryInterface(REFIID riid
, void **ppv
)
1368 static const IID IID_undocumented
= {0x58DFC7D0,0x5381,0x43E5,{0x9D,0x72,0x4C,0xDD,0xE4,0xCB,0x0F,0x1A}};
1369 static const IID IID_undocumentedIE10
= {0xc28722e5,0xbc1a,0x4c55,{0xa6,0x8d,0x33,0x21,0x9f,0x69,0x89,0x10}};
1373 if(IsEqualGUID(&IID_IUnknown
, riid
) || IsEqualGUID(&IID_IInternetProtocolSink
, riid
))
1374 *ppv
= &protocol_sink
;
1375 if(IsEqualGUID(&IID_IServiceProvider
, riid
))
1376 *ppv
= &service_provider
;
1377 if(IsEqualGUID(&IID_IUriContainer
, riid
))
1378 return E_NOINTERFACE
; /* TODO */
1380 /* NOTE: IE8 queries for undocumented {58DFC7D0-5381-43E5-9D72-4CDDE4CB0F1A} interface. */
1381 if(IsEqualGUID(&IID_undocumented
, riid
))
1382 return E_NOINTERFACE
;
1383 /* NOTE: IE10 queries for undocumented {c28722e5-bc1a-4c55-a68d-33219f698910} interface. */
1384 if(IsEqualGUID(&IID_undocumentedIE10
, riid
))
1385 return E_NOINTERFACE
;
1390 ok(0, "unexpected call %s\n", wine_dbgstr_guid(riid
));
1391 return E_NOINTERFACE
;
1394 static HRESULT WINAPI
BindInfo_QueryInterface(IInternetBindInfo
*iface
, REFIID riid
, void **ppv
)
1396 if(IsEqualGUID(&IID_IUnknown
, riid
) || IsEqualGUID(&IID_IInternetBindInfo
, riid
)) {
1400 return E_NOINTERFACE
;
1403 static ULONG WINAPI
BindInfo_AddRef(IInternetBindInfo
*iface
)
1408 static ULONG WINAPI
BindInfo_Release(IInternetBindInfo
*iface
)
1413 static HRESULT WINAPI
BindInfo_GetBindInfo(IInternetBindInfo
*iface
, DWORD
*grfBINDF
, BINDINFO
*pbindinfo
)
1417 CHECK_EXPECT(GetBindInfo
);
1419 ok(grfBINDF
!= NULL
, "grfBINDF == NULL\n");
1420 ok(pbindinfo
!= NULL
, "pbindinfo == NULL\n");
1421 ok(pbindinfo
->cbSize
== sizeof(BINDINFO
), "wrong size of pbindinfo: %d\n", pbindinfo
->cbSize
);
1425 *grfBINDF
|= BINDF_FROMURLMON
;
1426 cbSize
= pbindinfo
->cbSize
;
1427 memset(pbindinfo
, 0, cbSize
);
1428 pbindinfo
->cbSize
= cbSize
;
1429 pbindinfo
->dwOptions
= bindinfo_options
;
1433 pbindinfo
->cbstgmedData
= sizeof(post_data
)-1;
1434 pbindinfo
->dwBindVerb
= BINDVERB_POST
;
1435 pbindinfo
->stgmedData
.tymed
= http_post_test
;
1437 if(http_post_test
== TYMED_HGLOBAL
) {
1440 /* Must be GMEM_FIXED, GMEM_MOVABLE does not work properly */
1441 data
= GlobalAlloc(GPTR
, sizeof(post_data
));
1442 memcpy(data
, post_data
, sizeof(post_data
));
1443 U(pbindinfo
->stgmedData
).hGlobal
= data
;
1445 U(pbindinfo
->stgmedData
).pstm
= &Stream
;
1452 static HRESULT WINAPI
BindInfo_GetBindString(IInternetBindInfo
*iface
, ULONG ulStringType
,
1453 LPOLESTR
*ppwzStr
, ULONG cEl
, ULONG
*pcElFetched
)
1455 ok(ppwzStr
!= NULL
, "ppwzStr == NULL\n");
1456 ok(pcElFetched
!= NULL
, "pcElFetched == NULL\n");
1458 switch(ulStringType
) {
1459 case BINDSTRING_ACCEPT_MIMES
:
1460 CHECK_EXPECT(GetBindString_ACCEPT_MIMES
);
1461 ok(cEl
== 256, "cEl=%d, expected 256\n", cEl
);
1463 ok(*pcElFetched
== 256, "*pcElFetched=%d, expected 256\n", *pcElFetched
);
1467 *ppwzStr
= CoTaskMemAlloc(sizeof(acc_mimeW
));
1468 memcpy(*ppwzStr
, acc_mimeW
, sizeof(acc_mimeW
));
1471 case BINDSTRING_USER_AGENT
:
1472 CHECK_EXPECT(GetBindString_USER_AGENT
);
1473 ok(cEl
== 1, "cEl=%d, expected 1\n", cEl
);
1475 ok(*pcElFetched
== 0, "*pcElFetch=%d, expected 0\n", *pcElFetched
);
1479 *ppwzStr
= CoTaskMemAlloc(sizeof(user_agentW
));
1480 memcpy(*ppwzStr
, user_agentW
, sizeof(user_agentW
));
1483 case BINDSTRING_POST_COOKIE
:
1484 CHECK_EXPECT(GetBindString_POST_COOKIE
);
1485 ok(cEl
== 1, "cEl=%d, expected 1\n", cEl
);
1487 ok(*pcElFetched
== 0, "*pcElFetch=%d, expected 0\n", *pcElFetched
);
1489 case BINDSTRING_URL
: {
1492 CHECK_EXPECT(GetBindString_URL
);
1493 ok(cEl
== 1, "cEl=%d, expected 1\n", cEl
);
1494 ok(*pcElFetched
== 0, "*pcElFetch=%d, expected 0\n", *pcElFetched
);
1497 size
= (lstrlenW(binding_urls
[tested_protocol
])+1)*sizeof(WCHAR
);
1498 *ppwzStr
= CoTaskMemAlloc(size
);
1499 memcpy(*ppwzStr
, binding_urls
[tested_protocol
], size
);
1502 case BINDSTRING_ROOTDOC_URL
:
1503 CHECK_EXPECT(GetBindString_ROOTDOC_URL
);
1504 ok(cEl
== 1, "cEl=%d, expected 1\n", cEl
);
1506 case BINDSTRING_ENTERPRISE_ID
:
1507 ok(cEl
== 1, "cEl=%d, expected 1\n", cEl
);
1510 ok(0, "unexpected ulStringType %d\n", ulStringType
);
1516 static IInternetBindInfoVtbl bind_info_vtbl
= {
1517 BindInfo_QueryInterface
,
1520 BindInfo_GetBindInfo
,
1521 BindInfo_GetBindString
1524 static IInternetBindInfo bind_info
= { &bind_info_vtbl
};
1526 static Protocol
*impl_from_IInternetPriority(IInternetPriority
*iface
)
1528 return CONTAINING_RECORD(iface
, Protocol
, IInternetPriority_iface
);
1531 static HRESULT WINAPI
InternetPriority_QueryInterface(IInternetPriority
*iface
,
1532 REFIID riid
, void **ppv
)
1534 ok(0, "unexpected call\n");
1535 return E_NOINTERFACE
;
1538 static ULONG WINAPI
InternetPriority_AddRef(IInternetPriority
*iface
)
1540 Protocol
*This
= impl_from_IInternetPriority(iface
);
1542 return IUnknown_AddRef(This
->outer
);
1545 static ULONG WINAPI
InternetPriority_Release(IInternetPriority
*iface
)
1547 Protocol
*This
= impl_from_IInternetPriority(iface
);
1549 return IUnknown_Release(This
->outer
);
1552 static HRESULT WINAPI
InternetPriority_SetPriority(IInternetPriority
*iface
, LONG nPriority
)
1554 CHECK_EXPECT(SetPriority
);
1555 ok(nPriority
== ex_priority
, "nPriority=%d\n", nPriority
);
1559 static HRESULT WINAPI
InternetPriority_GetPriority(IInternetPriority
*iface
, LONG
*pnPriority
)
1561 ok(0, "unexpected call\n");
1566 static const IInternetPriorityVtbl InternetPriorityVtbl
= {
1567 InternetPriority_QueryInterface
,
1568 InternetPriority_AddRef
,
1569 InternetPriority_Release
,
1570 InternetPriority_SetPriority
,
1571 InternetPriority_GetPriority
1574 static ULONG WINAPI
Protocol_AddRef(IInternetProtocolEx
*iface
)
1579 static ULONG WINAPI
Protocol_Release(IInternetProtocolEx
*iface
)
1584 static HRESULT WINAPI
Protocol_Abort(IInternetProtocolEx
*iface
, HRESULT hrReason
,
1589 CHECK_EXPECT(Abort
);
1591 SET_EXPECT(ReportResult
);
1592 hres
= IInternetProtocolSink_ReportResult(binding_sink
, S_OK
, ERROR_SUCCESS
, NULL
);
1593 ok(hres
== S_OK
, "ReportResult failed: %08x\n", hres
);
1594 CHECK_CALLED(ReportResult
);
1599 static HRESULT WINAPI
Protocol_Suspend(IInternetProtocolEx
*iface
)
1601 ok(0, "unexpected call\n");
1605 static HRESULT WINAPI
Protocol_Resume(IInternetProtocolEx
*iface
)
1607 ok(0, "unexpected call\n");
1611 static HRESULT WINAPI
Protocol_Seek(IInternetProtocolEx
*iface
,
1612 LARGE_INTEGER dlibMove
, DWORD dwOrigin
, ULARGE_INTEGER
*plibNewPosition
)
1614 ok(0, "unexpected call\n");
1618 static Protocol
*impl_from_IInternetProtocolEx(IInternetProtocolEx
*iface
)
1620 return CONTAINING_RECORD(iface
, Protocol
, IInternetProtocolEx_iface
);
1623 static HRESULT WINAPI
ProtocolEmul_QueryInterface(IInternetProtocolEx
*iface
, REFIID riid
, void **ppv
)
1625 Protocol
*This
= impl_from_IInternetProtocolEx(iface
);
1627 static const IID unknown_iid
= {0x7daf9908,0x8415,0x4005,{0x95,0xae, 0xbd,0x27,0xf6,0xe3,0xdc,0x00}};
1628 static const IID unknown_iid2
= {0x5b7ebc0c,0xf630,0x4cea,{0x89,0xd3,0x5a,0xf0,0x38,0xed,0x05,0x5c}};
1630 /* FIXME: Why is it calling here instead of outer IUnknown? */
1631 if(IsEqualGUID(riid
, &IID_IInternetPriority
)) {
1632 *ppv
= &This
->IInternetPriority_iface
;
1633 IInternetPriority_AddRef(&This
->IInternetPriority_iface
);
1636 if(!IsEqualGUID(riid
, &unknown_iid
) && !IsEqualGUID(riid
, &unknown_iid2
)) /* IE10 */
1637 ok(0, "unexpected riid %s\n", wine_dbgstr_guid(riid
));
1639 return E_NOINTERFACE
;
1642 static ULONG WINAPI
ProtocolEmul_AddRef(IInternetProtocolEx
*iface
)
1644 Protocol
*This
= impl_from_IInternetProtocolEx(iface
);
1646 return IUnknown_AddRef(This
->outer
);
1649 static ULONG WINAPI
ProtocolEmul_Release(IInternetProtocolEx
*iface
)
1651 Protocol
*This
= impl_from_IInternetProtocolEx(iface
);
1653 return IUnknown_Release(This
->outer
);
1656 static DWORD WINAPI
thread_proc(PVOID arg
)
1658 BOOL redirect
= redirect_on_continue
;
1661 memset(&protocoldata
, -1, sizeof(protocoldata
));
1666 SET_EXPECT(ReportProgress_FINDINGRESOURCE
);
1667 hres
= IInternetProtocolSink_ReportProgress(binding_sink
,
1668 BINDSTATUS_FINDINGRESOURCE
, hostW
);
1669 CHECK_CALLED(ReportProgress_FINDINGRESOURCE
);
1670 ok(hres
== S_OK
, "ReportProgress failed: %08x\n", hres
);
1672 SET_EXPECT(ReportProgress_CONNECTING
);
1673 hres
= IInternetProtocolSink_ReportProgress(binding_sink
,
1674 BINDSTATUS_CONNECTING
, winehq_ipW
);
1675 CHECK_CALLED(ReportProgress_CONNECTING
);
1676 ok(hres
== S_OK
, "ReportProgress failed: %08x\n", hres
);
1678 SET_EXPECT(ReportProgress_SENDINGREQUEST
);
1679 hres
= IInternetProtocolSink_ReportProgress(binding_sink
,
1680 BINDSTATUS_SENDINGREQUEST
, NULL
);
1681 CHECK_CALLED(ReportProgress_SENDINGREQUEST
);
1682 ok(hres
== S_OK
, "ReportProgress failed: %08x\n", hres
);
1686 hres
= IInternetProtocolSink_Switch(binding_sink
, &protocoldata
);
1687 CHECK_CALLED(Switch
);
1688 ok(hres
== S_OK
, "Switch failed: %08x\n", hres
);
1698 SET_EXPECT(MimeFilter_Switch
);
1701 hres
= IInternetProtocolSink_Switch(binding_sink
, &protocoldata
);
1702 ok(hres
== S_OK
, "Switch failed: %08x\n", hres
);
1704 CHECK_CALLED(MimeFilter_Switch
);
1706 CHECK_CALLED(Switch
);
1709 SetEvent(event_complete
);
1715 SET_EXPECT(MimeFilter_Switch
);
1718 hres
= IInternetProtocolSink_Switch(binding_sink
, &protocoldata
);
1719 ok(hres
== S_OK
, "Switch failed: %08x\n", hres
);
1721 CHECK_CALLED(MimeFilter_Switch
);
1723 CHECK_CALLED(Switch
);
1727 SET_EXPECT(MimeFilter_Switch
);
1730 hres
= IInternetProtocolSink_Switch(binding_sink
, &protocoldata
);
1731 ok(hres
== S_OK
, "Switch failed: %08x\n", hres
);
1733 CHECK_CALLED(MimeFilter_Switch
);
1735 CHECK_CALLED(Switch
);
1738 SetEvent(event_complete
);
1743 static void protocol_start(IInternetProtocolSink
*pOIProtSink
, IInternetBindInfo
*pOIBindInfo
, DWORD pi
)
1745 BINDINFO bindinfo
, exp_bindinfo
;
1749 ok(pOIProtSink
!= NULL
, "pOIProtSink == NULL\n");
1750 ok(pOIBindInfo
!= NULL
, "pOIBindInfo == NULL\n");
1751 ok(pOIProtSink
!= &protocol_sink
, "unexpected pOIProtSink\n");
1752 ok(pOIBindInfo
!= &bind_info
, "unexpected pOIBindInfo\n");
1753 ok(!pi
, "pi = %x\n", pi
);
1756 ok(pOIProtSink
== binding_sink
, "pOIProtSink != binding_sink\n");
1758 memset(&bindinfo
, 0, sizeof(bindinfo
));
1759 bindinfo
.cbSize
= sizeof(bindinfo
);
1760 memcpy(&exp_bindinfo
, &bindinfo
, sizeof(bindinfo
));
1762 exp_bindinfo
.dwOptions
= bindinfo_options
;
1763 SET_EXPECT(GetBindInfo
);
1764 if(redirect_on_continue
&& (bindinfo_options
& BINDINFO_OPTIONS_DISABLEAUTOREDIRECTS
))
1765 SET_EXPECT(QueryService_IBindCallbackRedirect
);
1766 hres
= IInternetBindInfo_GetBindInfo(pOIBindInfo
, &cbindf
, &bindinfo
);
1767 if(redirect_on_continue
&& (bindinfo_options
& BINDINFO_OPTIONS_DISABLEAUTOREDIRECTS
))
1768 CHECK_CALLED(QueryService_IBindCallbackRedirect
);
1769 ok(hres
== S_OK
, "GetBindInfo failed: %08x\n", hres
);
1770 CHECK_CALLED(GetBindInfo
);
1771 ok(cbindf
== (bindf
|BINDF_FROMURLMON
), "bindf = %x, expected %x\n",
1772 cbindf
, (bindf
|BINDF_FROMURLMON
));
1773 ok(!memcmp(&exp_bindinfo
, &bindinfo
, sizeof(bindinfo
)), "unexpected bindinfo\n");
1774 pReleaseBindInfo(&bindinfo
);
1776 SET_EXPECT(ReportProgress_SENDINGREQUEST
);
1777 hres
= IInternetProtocolSink_ReportProgress(pOIProtSink
, BINDSTATUS_SENDINGREQUEST
, emptyW
);
1778 ok(hres
== S_OK
, "ReportProgress(BINDSTATUS_SENDINGREQUEST) failed: %08x\n", hres
);
1779 CHECK_CALLED(ReportProgress_SENDINGREQUEST
);
1781 if(tested_protocol
== HTTP_TEST
|| tested_protocol
== HTTPS_TEST
) {
1782 IServiceProvider
*service_provider
;
1783 IHttpNegotiate
*http_negotiate
;
1784 IHttpNegotiate2
*http_negotiate2
;
1785 LPWSTR ua
= (LPWSTR
)0xdeadbeef, accept_mimes
[256];
1786 LPWSTR additional_headers
= NULL
;
1788 DWORD fetched
= 0, size
= 100;
1791 SET_EXPECT(GetBindString_USER_AGENT
);
1792 hres
= IInternetBindInfo_GetBindString(pOIBindInfo
, BINDSTRING_USER_AGENT
,
1794 CHECK_CALLED(GetBindString_USER_AGENT
);
1795 ok(hres
== S_OK
, "GetBindString(BINDSTRING_USER_AGETNT) failed: %08x\n", hres
);
1796 ok(fetched
== 1, "fetched = %d, expected 254\n", fetched
);
1797 ok(ua
!= NULL
, "ua = %p\n", ua
);
1798 ok(!lstrcmpW(ua
, user_agentW
), "unexpected user agent %s\n", wine_dbgstr_w(ua
));
1802 SET_EXPECT(GetBindString_ACCEPT_MIMES
);
1803 hres
= IInternetBindInfo_GetBindString(pOIBindInfo
, BINDSTRING_ACCEPT_MIMES
,
1804 accept_mimes
, 256, &fetched
);
1805 CHECK_CALLED(GetBindString_ACCEPT_MIMES
);
1808 "GetBindString(BINDSTRING_ACCEPT_MIMES) failed: %08x\n", hres
);
1809 ok(fetched
== 1, "fetched = %d, expected 1\n", fetched
);
1810 ok(!lstrcmpW(acc_mimeW
, accept_mimes
[0]), "unexpected mimes %s\n", wine_dbgstr_w(accept_mimes
[0]));
1811 CoTaskMemFree(accept_mimes
[0]);
1813 hres
= IInternetBindInfo_QueryInterface(pOIBindInfo
, &IID_IServiceProvider
,
1814 (void**)&service_provider
);
1815 ok(hres
== S_OK
, "QueryInterface failed: %08x\n", hres
);
1817 SET_EXPECT(QueryService_HttpNegotiate
);
1818 hres
= IServiceProvider_QueryService(service_provider
, &IID_IHttpNegotiate
,
1819 &IID_IHttpNegotiate
, (void**)&http_negotiate
);
1820 CHECK_CALLED(QueryService_HttpNegotiate
);
1821 ok(hres
== S_OK
, "QueryService failed: %08x\n", hres
);
1823 SET_EXPECT(BeginningTransaction
);
1824 hres
= IHttpNegotiate_BeginningTransaction(http_negotiate
, binding_urls
[tested_protocol
],
1825 NULL
, 0, &additional_headers
);
1826 CHECK_CALLED(BeginningTransaction
);
1827 IHttpNegotiate_Release(http_negotiate
);
1828 ok(hres
== S_OK
, "BeginningTransction failed: %08x\n", hres
);
1829 ok(additional_headers
== NULL
, "additional_headers=%p\n", additional_headers
);
1831 SET_EXPECT(QueryService_HttpNegotiate
);
1832 hres
= IServiceProvider_QueryService(service_provider
, &IID_IHttpNegotiate2
,
1833 &IID_IHttpNegotiate2
, (void**)&http_negotiate2
);
1834 CHECK_CALLED(QueryService_HttpNegotiate
);
1835 ok(hres
== S_OK
, "QueryService failed: %08x\n", hres
);
1838 SET_EXPECT(GetRootSecurityId
);
1839 hres
= IHttpNegotiate2_GetRootSecurityId(http_negotiate2
, sec_id
, &size
, 0);
1840 CHECK_CALLED(GetRootSecurityId
);
1841 IHttpNegotiate2_Release(http_negotiate2
);
1842 ok(hres
== E_FAIL
, "GetRootSecurityId failed: %08x, expected E_FAIL\n", hres
);
1843 ok(size
== 13, "size=%d\n", size
);
1845 IServiceProvider_Release(service_provider
);
1847 if(!reuse_protocol_thread
)
1848 CreateThread(NULL
, 0, thread_proc
, NULL
, 0, &tid
);
1852 SET_EXPECT(ReportProgress_CACHEFILENAMEAVAILABLE
);
1853 hres
= IInternetProtocolSink_ReportProgress(pOIProtSink
,
1854 BINDSTATUS_CACHEFILENAMEAVAILABLE
, expect_wsz
= emptyW
);
1855 ok(hres
== S_OK
, "ReportProgress(BINDSTATUS_CACHEFILENAMEAVAILABLE) failed: %08x\n", hres
);
1856 CHECK_CALLED(ReportProgress_CACHEFILENAMEAVAILABLE
);
1858 if(mimefilter_test
) {
1859 SET_EXPECT(MimeFilter_CreateInstance
);
1860 SET_EXPECT(MimeFilter_Start
);
1861 SET_EXPECT(ReportProgress_LOADINGMIMEHANDLER
);
1863 SET_EXPECT(ReportProgress_MIMETYPEAVAILABLE
);
1864 hres
= IInternetProtocolSink_ReportProgress(pOIProtSink
, BINDSTATUS_VERIFIEDMIMETYPEAVAILABLE
,
1865 mimefilter_test
? pjpegW
: (expect_wsz
= text_htmlW
));
1867 "ReportProgress(BINDSTATUS_VERIFIEDMIMETYPEAVAILABLE) failed: %08x\n", hres
);
1868 if(mimefilter_test
) {
1869 CHECK_CALLED(MimeFilter_CreateInstance
);
1870 CHECK_CALLED(MimeFilter_Start
);
1871 CHECK_CALLED(ReportProgress_LOADINGMIMEHANDLER
);
1872 CHECK_CALLED(ReportProgress_MIMETYPEAVAILABLE
);
1874 CHECK_CALLED(ReportProgress_MIMETYPEAVAILABLE
);
1878 SET_EXPECT(MimeFilter_ReportData
);
1880 SET_EXPECT(ReportData
);
1881 hres
= IInternetProtocolSink_ReportData(pOIProtSink
,
1882 BSCF_FIRSTDATANOTIFICATION
| (tested_protocol
== ITS_TEST
? BSCF_DATAFULLYAVAILABLE
: BSCF_LASTDATANOTIFICATION
),
1884 ok(hres
== S_OK
, "ReportData failed: %08x\n", hres
);
1886 CHECK_CALLED(MimeFilter_ReportData
);
1888 CHECK_CALLED(ReportData
);
1890 if(tested_protocol
== ITS_TEST
) {
1891 SET_EXPECT(ReportData
);
1892 hres
= IInternetProtocolSink_ReportProgress(pOIProtSink
, BINDSTATUS_BEGINDOWNLOADDATA
, NULL
);
1893 ok(hres
== S_OK
, "ReportProgress(BINDSTATUS_BEGINDOWNLOADDATA) failed: %08x\n", hres
);
1894 CHECK_CALLED(ReportData
);
1897 if(tested_protocol
== BIND_TEST
) {
1898 hres
= IInternetProtocol_Terminate(binding_protocol
, 0);
1899 ok(hres
== E_FAIL
, "Termiante failed: %08x\n", hres
);
1903 SET_EXPECT(MimeFilter_ReportResult
);
1905 SET_EXPECT(ReportResult
);
1906 hres
= IInternetProtocolSink_ReportResult(pOIProtSink
, S_OK
, 0, NULL
);
1907 ok(hres
== S_OK
, "ReportResult failed: %08x\n", hres
);
1909 CHECK_CALLED(MimeFilter_ReportResult
);
1911 CHECK_CALLED(ReportResult
);
1914 static HRESULT WINAPI
ProtocolEmul_Start(IInternetProtocolEx
*iface
, LPCWSTR szUrl
,
1915 IInternetProtocolSink
*pOIProtSink
, IInternetBindInfo
*pOIBindInfo
,
1916 DWORD grfPI
, HANDLE_PTR dwReserved
)
1918 CHECK_EXPECT(Start
);
1920 ok(!dwReserved
, "dwReserved = %lx\n", dwReserved
);
1921 protocol_start(pOIProtSink
, pOIBindInfo
, grfPI
);
1925 static HRESULT WINAPI
ProtocolEmul_Continue(IInternetProtocolEx
*iface
,
1926 PROTOCOLDATA
*pProtocolData
)
1931 CHECK_EXPECT(Continue
);
1933 ok(pProtocolData
!= NULL
, "pProtocolData == NULL\n");
1934 if(!pProtocolData
|| tested_protocol
== BIND_TEST
)
1937 ok(pProtocolData
!= &protocoldata
, "pProtocolData == &protocoldata\n");
1938 ok(pProtocolData
->grfFlags
== protocoldata
.grfFlags
, "grfFlags wrong %x/%x\n",
1939 pProtocolData
->grfFlags
, protocoldata
.grfFlags
);
1940 ok(pProtocolData
->dwState
== protocoldata
.dwState
, "dwState wrong %x/%x\n",
1941 pProtocolData
->dwState
, protocoldata
.dwState
);
1942 ok(pProtocolData
->pData
== protocoldata
.pData
, "pData wrong %p/%p\n",
1943 pProtocolData
->pData
, protocoldata
.pData
);
1944 ok(pProtocolData
->cbData
== protocoldata
.cbData
, "cbData wrong %x/%x\n",
1945 pProtocolData
->cbData
, protocoldata
.cbData
);
1948 switch(prot_state
) {
1950 IServiceProvider
*service_provider
;
1951 IHttpNegotiate
*http_negotiate
;
1952 static const WCHAR header
[] = {'?',0};
1953 static const WCHAR redirect_urlW
[] = {'h','t','t','p',':','/','/','t','e','s','t','.','w','i','n','e','h','q','.','o','r','g',
1954 '/','t','e','s','t','s','/','h','e','l','l','o','.','h','t','m','l',0};
1956 if(redirect_on_continue
) {
1957 redirect_on_continue
= FALSE
;
1958 reuse_protocol_thread
= TRUE
;
1960 if(bindinfo_options
& BINDINFO_OPTIONS_DISABLEAUTOREDIRECTS
)
1961 SET_EXPECT(Redirect
);
1962 SET_EXPECT(ReportProgress_REDIRECTING
);
1963 SET_EXPECT(Terminate
);
1964 SET_EXPECT(Protocol_destructor
);
1965 SET_EXPECT(QueryService_InternetProtocol
);
1966 SET_EXPECT(CreateInstance
);
1967 SET_EXPECT(ReportProgress_PROTOCOLCLASSID
);
1968 SET_EXPECT(SetPriority
);
1970 hres
= IInternetProtocolSink_ReportResult(binding_sink
, INET_E_REDIRECT_FAILED
, ERROR_SUCCESS
, redirect_urlW
);
1971 ok(hres
== S_OK
, "ReportResult failed: %08x\n", hres
);
1972 if(bindinfo_options
& BINDINFO_OPTIONS_DISABLEAUTOREDIRECTS
)
1973 CHECK_CALLED(Redirect
);
1974 CHECK_CALLED(ReportProgress_REDIRECTING
);
1975 CHECK_CALLED(Terminate
);
1976 CHECK_CALLED(Protocol_destructor
);
1977 CHECK_CALLED(QueryService_InternetProtocol
);
1978 CHECK_CALLED(CreateInstance
);
1979 CHECK_CALLED(ReportProgress_PROTOCOLCLASSID
);
1980 todo_wine
CHECK_NOT_CALLED(SetPriority
);
1981 CHECK_CALLED(Start
);
1986 hres
= IInternetProtocolSink_QueryInterface(binding_sink
, &IID_IServiceProvider
,
1987 (void**)&service_provider
);
1988 ok(hres
== S_OK
, "Could not get IServiceProvicder\n");
1990 SET_EXPECT(QueryService_HttpNegotiate
);
1991 hres
= IServiceProvider_QueryService(service_provider
, &IID_IHttpNegotiate
,
1992 &IID_IHttpNegotiate
, (void**)&http_negotiate
);
1993 IServiceProvider_Release(service_provider
);
1994 CHECK_CALLED(QueryService_HttpNegotiate
);
1995 ok(hres
== S_OK
, "Could not get IHttpNegotiate\n");
1997 SET_EXPECT(OnResponse
);
1998 hres
= IHttpNegotiate_OnResponse(http_negotiate
, 200, header
, NULL
, NULL
);
1999 IHttpNegotiate_Release(http_negotiate
);
2000 CHECK_CALLED(OnResponse
);
2001 IHttpNegotiate_Release(http_negotiate
);
2002 ok(hres
== S_OK
, "OnResponse failed: %08x\n", hres
);
2004 if(mimefilter_test
) {
2005 SET_EXPECT(MimeFilter_CreateInstance
);
2006 SET_EXPECT(MimeFilter_Start
);
2007 SET_EXPECT(ReportProgress_LOADINGMIMEHANDLER
);
2008 }else if(!(pi
& PI_MIMEVERIFICATION
)) {
2009 SET_EXPECT(ReportProgress_MIMETYPEAVAILABLE
);
2011 hres
= IInternetProtocolSink_ReportProgress(binding_sink
,
2012 BINDSTATUS_MIMETYPEAVAILABLE
, mimefilter_test
? pjpegW
: text_htmlW
);
2013 if(mimefilter_test
) {
2014 CHECK_CALLED(MimeFilter_CreateInstance
);
2015 CHECK_CALLED(MimeFilter_Start
);
2016 CHECK_CALLED(ReportProgress_LOADINGMIMEHANDLER
);
2017 }else if(!(pi
& PI_MIMEVERIFICATION
)) {
2018 CHECK_CALLED(ReportProgress_MIMETYPEAVAILABLE
);
2021 "ReportProgress(BINDSTATUS_MIMETYPEAVAILABLE) failed: %08x\n", hres
);
2023 bscf
|= BSCF_FIRSTDATANOTIFICATION
;
2028 bscf
= BSCF_INTERMEDIATEDATANOTIFICATION
;
2034 SET_EXPECT(MimeFilter_ReportData
);
2035 if((!mimefilter_test
|| no_mime
) && (pi
& PI_MIMEVERIFICATION
)) {
2037 SET_EXPECT(Read
); /* checked in ReportData for short_read */
2039 if(!mimefilter_test
)
2040 SET_EXPECT(Read
); /* checked in BINDSTATUS_MIMETYPEAVAILABLE or ReportData */
2041 SET_EXPECT(GetBindInfo
);
2042 SET_EXPECT(ReportProgress_MIMETYPEAVAILABLE
);
2045 SET_EXPECT(ReportData
);
2047 SET_EXPECT(ReportData
);
2050 hres
= IInternetProtocolSink_ReportData(binding_sink
, bscf
, pr
, 400);
2051 ok(hres
== S_OK
, "ReportData failed: %08x\n", hres
);
2053 if(mimefilter_test
) {
2054 SET_EXPECT(MimeFilter_ReportData
);
2055 }else if(pi
& PI_MIMEVERIFICATION
) {
2056 if(!short_read
&& pr
< 200)
2059 CLEAR_CALLED(GetBindInfo
); /* IE9 */
2060 CHECK_CALLED(ReportProgress_MIMETYPEAVAILABLE
);
2063 CHECK_CALLED(ReportData
);
2072 static HRESULT WINAPI
ProtocolEmul_Terminate(IInternetProtocolEx
*iface
, DWORD dwOptions
)
2074 CHECK_EXPECT(Terminate
);
2075 ok(!dwOptions
, "dwOptions=%d\n", dwOptions
);
2079 static HRESULT WINAPI
ProtocolEmul_Read(IInternetProtocolEx
*iface
, void *pv
,
2080 ULONG cb
, ULONG
*pcbRead
)
2082 if(read_report_data
)
2083 CHECK_EXPECT2(Read2
);
2085 if(mimefilter_test
|| short_read
) {
2086 if(!read_report_data
)
2087 CHECK_EXPECT2(Read
);
2088 }else if((pi
& PI_MIMEVERIFICATION
)) {
2089 if(!read_report_data
)
2090 CHECK_EXPECT2(Read
);
2092 if(prot_read
< 300) {
2093 ok(pv
!= expect_pv
, "pv == expect_pv\n");
2095 ok(cb
== 2048-prot_read
, "cb=%d\n", cb
);
2097 ok(cb
== 700, "cb=%d\n", cb
);
2099 ok(expect_pv
<= pv
&& (BYTE
*)pv
< (BYTE
*)expect_pv
+ cb
, "pv != expect_pv\n");
2102 if(!read_report_data
)
2105 ok(pv
== expect_pv
, "pv != expect_pv\n");
2106 ok(cb
== 1000, "cb=%d\n", cb
);
2107 ok(!*pcbRead
, "*pcbRead = %d\n", *pcbRead
);
2109 ok(pcbRead
!= NULL
, "pcbRead == NULL\n");
2111 if(prot_state
== 3 || (short_read
&& prot_state
!= 4)) {
2116 SET_EXPECT(Read2
); /* checked in BINDSTATUS_MIMETYPEAVAILABLE */
2117 SET_EXPECT(GetBindInfo
);
2118 SET_EXPECT(ReportProgress_MIMETYPEAVAILABLE
);
2121 SET_EXPECT(MimeFilter_ReportData
);
2122 else if(direct_read
)
2123 SET_EXPECT(ReportData2
);
2125 hres
= IInternetProtocolSink_ReportData(binding_sink
,
2126 BSCF_LASTDATANOTIFICATION
|BSCF_INTERMEDIATEDATANOTIFICATION
, 0, 0);
2128 ok(hres
== S_OK
, "ReportData failed: %08x\n", hres
);
2130 CLEAR_CALLED(GetBindInfo
); /* IE9 */
2131 CHECK_CALLED(ReportProgress_MIMETYPEAVAILABLE
);
2134 CHECK_CALLED(MimeFilter_ReportData
);
2135 else if(direct_read
)
2136 CHECK_CALLED(ReportData2
);
2139 SET_EXPECT(MimeFilter_ReportResult
);
2141 SET_EXPECT(ReportResult
);
2142 hres
= IInternetProtocolSink_ReportResult(binding_sink
, S_OK
, ERROR_SUCCESS
, NULL
);
2143 ok(hres
== S_OK
, "ReportResult failed: %08x\n", hres
);
2145 CHECK_CALLED(MimeFilter_ReportResult
);
2147 CHECK_CALLED(ReportResult
);
2151 memset(pv
, 'x', cb
);
2153 memcpy(pv
, "gif87a", 6);
2154 prot_read
+= *pcbRead
= cb
;
2158 if(prot_state
== 4) {
2163 if((async_read_pending
= !async_read_pending
)) {
2165 return tested_protocol
== HTTP_TEST
|| tested_protocol
== HTTPS_TEST
? E_PENDING
: S_FALSE
;
2170 memset(pv
, 'x', cb
);
2172 memcpy(pv
, "gif87a", 6);
2173 prot_read
+= *pcbRead
= cb
;
2177 static HRESULT WINAPI
ProtocolEmul_LockRequest(IInternetProtocolEx
*iface
, DWORD dwOptions
)
2179 CHECK_EXPECT(LockRequest
);
2180 ok(dwOptions
== 0, "dwOptions=%x\n", dwOptions
);
2184 static HRESULT WINAPI
ProtocolEmul_UnlockRequest(IInternetProtocolEx
*iface
)
2186 CHECK_EXPECT(UnlockRequest
);
2190 static HRESULT WINAPI
ProtocolEmul_StartEx(IInternetProtocolEx
*iface
, IUri
*pUri
,
2191 IInternetProtocolSink
*pOIProtSink
, IInternetBindInfo
*pOIBindInfo
,
2192 DWORD grfPI
, HANDLE
*dwReserved
)
2194 CHECK_EXPECT(StartEx
);
2195 ok(!dwReserved
, "dwReserved = %p\n", dwReserved
);
2196 protocol_start(pOIProtSink
, pOIBindInfo
, grfPI
);
2200 static const IInternetProtocolExVtbl ProtocolVtbl
= {
2201 ProtocolEmul_QueryInterface
,
2202 ProtocolEmul_AddRef
,
2203 ProtocolEmul_Release
,
2205 ProtocolEmul_Continue
,
2207 ProtocolEmul_Terminate
,
2212 ProtocolEmul_LockRequest
,
2213 ProtocolEmul_UnlockRequest
,
2214 ProtocolEmul_StartEx
2217 static Protocol
*impl_from_IUnknown(IUnknown
*iface
)
2219 return CONTAINING_RECORD(iface
, Protocol
, IUnknown_inner
);
2222 static HRESULT WINAPI
ProtocolUnk_QueryInterface(IUnknown
*iface
, REFIID riid
, void **ppv
)
2224 Protocol
*This
= impl_from_IUnknown(iface
);
2226 if(IsEqualGUID(&IID_IUnknown
, riid
)) {
2227 trace("QI(IUnknown)\n");
2228 *ppv
= &This
->IUnknown_inner
;
2229 }else if(IsEqualGUID(&IID_IInternetProtocol
, riid
)) {
2230 trace("QI(InternetProtocol)\n");
2231 *ppv
= &This
->IInternetProtocolEx_iface
;
2232 }else if(IsEqualGUID(&IID_IInternetProtocolEx
, riid
)) {
2233 trace("QI(InternetProtocolEx)\n");
2236 return E_NOINTERFACE
;
2238 *ppv
= &This
->IInternetProtocolEx_iface
;
2239 }else if(IsEqualGUID(&IID_IInternetPriority
, riid
)) {
2240 trace("QI(InternetPriority)\n");
2241 *ppv
= &This
->IInternetPriority_iface
;
2242 }else if(IsEqualGUID(&IID_IWinInetInfo
, riid
)) {
2243 trace("QI(IWinInetInfo)\n");
2244 CHECK_EXPECT(QueryInterface_IWinInetInfo
);
2246 return E_NOINTERFACE
;
2247 }else if(IsEqualGUID(&IID_IWinInetHttpInfo
, riid
)) {
2248 trace("QI(IWinInetHttpInfo)\n");
2249 CHECK_EXPECT(QueryInterface_IWinInetHttpInfo
);
2251 return E_NOINTERFACE
;
2253 ok(0, "unexpected call %s\n", wine_dbgstr_guid(riid
));
2255 return E_NOINTERFACE
;
2258 IUnknown_AddRef((IUnknown
*)*ppv
);
2262 static ULONG WINAPI
ProtocolUnk_AddRef(IUnknown
*iface
)
2264 Protocol
*This
= impl_from_IUnknown(iface
);
2265 return ++This
->inner_ref
;
2268 static ULONG WINAPI
ProtocolUnk_Release(IUnknown
*iface
)
2270 Protocol
*This
= impl_from_IUnknown(iface
);
2271 LONG ref
= --This
->inner_ref
;
2273 /* IE9 is broken on redirects. It will cause -1 outer_ref on original protocol handler
2274 * and 1 on redirected handler. */
2276 || broken(test_redirect
&& (This
->outer_ref
== -1 || This
->outer_ref
== 1)),
2277 "outer_ref = %d\n", This
->outer_ref
);
2279 trace("outer_ref %d\n", This
->outer_ref
);
2280 CHECK_EXPECT(Protocol_destructor
);
2286 static const IUnknownVtbl ProtocolUnkVtbl
= {
2287 ProtocolUnk_QueryInterface
,
2292 static HRESULT WINAPI
MimeProtocol_QueryInterface(IInternetProtocolEx
*iface
, REFIID riid
, void **ppv
)
2294 if(IsEqualGUID(&IID_IUnknown
, riid
) || IsEqualGUID(&IID_IInternetProtocol
, riid
)) {
2299 if(IsEqualGUID(&IID_IInternetProtocolSink
, riid
)) {
2300 *ppv
= &mime_protocol_sink
;
2304 ok(0, "unexpected riid %s\n", wine_dbgstr_guid(riid
));
2306 return E_NOINTERFACE
;
2309 static HRESULT WINAPI
MimeProtocol_Start(IInternetProtocolEx
*iface
, LPCWSTR szUrl
,
2310 IInternetProtocolSink
*pOIProtSink
, IInternetBindInfo
*pOIBindInfo
,
2311 DWORD grfPI
, HANDLE_PTR dwReserved
)
2313 PROTOCOLFILTERDATA
*data
;
2314 LPOLESTR url_str
= NULL
;
2320 CHECK_EXPECT(MimeFilter_Start
);
2322 ok(!lstrcmpW(szUrl
, pjpegW
), "wrong url %s\n", wine_dbgstr_w(szUrl
));
2323 ok(grfPI
== (PI_FILTER_MODE
|PI_FORCE_ASYNC
), "grfPI=%x, expected PI_FILTER_MODE|PI_FORCE_ASYNC\n", grfPI
);
2324 ok(dwReserved
, "dwReserved == 0\n");
2325 ok(pOIProtSink
!= NULL
, "pOIProtSink == NULL\n");
2326 ok(pOIBindInfo
!= NULL
, "pOIBindInfo == NULL\n");
2329 ok(pOIProtSink
!= binding_sink
, "pOIProtSink == protocol_sink\n");
2330 ok(pOIBindInfo
== prot_bind_info
, "pOIBindInfo != bind_info\n");
2332 ok(pOIProtSink
== &protocol_sink
, "pOIProtSink != protocol_sink\n");
2333 ok(pOIBindInfo
== &bind_info
, "pOIBindInfo != bind_info\n");
2336 data
= (void*)dwReserved
;
2337 ok(data
->cbSize
== sizeof(*data
), "data->cbSize = %d\n", data
->cbSize
);
2338 ok(!data
->pProtocolSink
, "data->pProtocolSink != NULL\n");
2339 ok(data
->pProtocol
!= NULL
, "data->pProtocol == NULL\n");
2340 ok(!data
->pUnk
, "data->pUnk != NULL\n");
2341 ok(!data
->dwFilterFlags
, "data->dwProtocolFlags = %x\n", data
->dwFilterFlags
);
2343 IInternetProtocolSink
*prot_sink
;
2345 IInternetProtocol_QueryInterface(data
->pProtocol
, &IID_IInternetProtocolSink
, (void**)&prot_sink
);
2346 ok(prot_sink
== pOIProtSink
, "QI(data->pProtocol, IID_IInternetProtocolSink) != pOIProtSink\n");
2347 IInternetProtocolSink_Release(prot_sink
);
2349 ok(data
->pProtocol
!= binding_protocol
, "data->pProtocol == binding_protocol\n");
2351 filtered_protocol
= data
->pProtocol
;
2352 IInternetProtocol_AddRef(filtered_protocol
);
2354 IInternetProtocol
*prot
;
2356 IInternetProtocol_QueryInterface(data
->pProtocol
, &IID_IInternetProtocol
, (void**)&prot
);
2357 ok(prot
== async_protocol
, "QI(data->pProtocol, IID_IInternetProtocol) != async_protocol\n");
2358 IInternetProtocol_Release(prot
);
2360 ok(data
->pProtocol
!= async_protocol
, "data->pProtocol == async_protocol\n");
2363 filtered_sink
= pOIProtSink
;
2365 SET_EXPECT(ReportProgress_DECODING
);
2366 hres
= IInternetProtocolSink_ReportProgress(pOIProtSink
, BINDSTATUS_DECODING
, pjpegW
);
2367 ok(hres
== S_OK
, "ReportProgress(BINDSTATUS_DECODING) failed: %08x\n", hres
);
2368 CHECK_CALLED(ReportProgress_DECODING
);
2370 SET_EXPECT(GetBindInfo
);
2371 memset(&bindinfo
, 0, sizeof(bindinfo
));
2372 bindinfo
.cbSize
= sizeof(bindinfo
);
2373 hres
= IInternetBindInfo_GetBindInfo(pOIBindInfo
, &cbindf
, &bindinfo
);
2374 ok(hres
== S_OK
, "GetBindInfo failed: %08x\n", hres
);
2375 ok(cbindf
== (bindf
|BINDF_FROMURLMON
), "cbindf = %x, expected %x\n", cbindf
, bindf
);
2376 CHECK_CALLED(GetBindInfo
);
2378 SET_EXPECT(GetBindString_URL
);
2379 hres
= IInternetBindInfo_GetBindString(pOIBindInfo
, BINDSTRING_URL
, &url_str
, 1, &fetched
);
2380 ok(hres
== S_OK
, "GetBindString(BINDSTRING_URL) failed: %08x\n", hres
);
2381 ok(fetched
== 1, "fetched = %d\n", fetched
);
2382 ok(!lstrcmpW(url_str
, binding_urls
[tested_protocol
]), "wrong url_str %s\n", wine_dbgstr_w(url_str
));
2383 CoTaskMemFree(url_str
);
2384 CHECK_CALLED(GetBindString_URL
);
2389 static HRESULT WINAPI
Protocol_Continue(IInternetProtocolEx
*iface
,
2390 PROTOCOLDATA
*pProtocolData
)
2392 CHECK_EXPECT(MimeFilter_Continue
);
2396 static HRESULT WINAPI
MimeProtocol_Terminate(IInternetProtocolEx
*iface
, DWORD dwOptions
)
2400 CHECK_EXPECT(MimeFilter_Terminate
);
2402 ok(!dwOptions
, "dwOptions = %x\n", dwOptions
);
2404 SET_EXPECT(Terminate
);
2405 hres
= IInternetProtocol_Terminate(filtered_protocol
, dwOptions
);
2406 ok(hres
== S_OK
, "Terminate failed: %08x\n", hres
);
2407 CHECK_CALLED(Terminate
);
2412 static HRESULT WINAPI
MimeProtocol_Read(IInternetProtocolEx
*iface
, void *pv
,
2413 ULONG cb
, ULONG
*pcbRead
)
2419 CHECK_EXPECT(MimeFilter_Read
);
2421 ok(pv
!= NULL
, "pv == NULL\n");
2422 ok(cb
!= 0, "cb == 0\n");
2423 ok(pcbRead
!= NULL
, "pcbRead == NULL\n");
2425 if(read_report_data
)
2429 hres
= IInternetProtocol_Read(filtered_protocol
, buf
, sizeof(buf
), &read
);
2430 ok(hres
== S_OK
|| hres
== S_FALSE
|| hres
== E_PENDING
, "Read failed: %08x\n", hres
);
2431 if(read_report_data
)
2432 CHECK_CALLED(Read2
);
2437 ok(*pcbRead
== 0, "*pcbRead=%d, expected 0\n", *pcbRead
);
2441 memset(pv
, 'x', read
);
2445 static HRESULT WINAPI
MimeProtocol_LockRequest(IInternetProtocolEx
*iface
, DWORD dwOptions
)
2449 CHECK_EXPECT(MimeFilter_LockRequest
);
2451 ok(!dwOptions
, "dwOptions = %x\n", dwOptions
);
2453 SET_EXPECT(LockRequest
);
2454 hres
= IInternetProtocol_LockRequest(filtered_protocol
, dwOptions
);
2455 ok(hres
== S_OK
, "LockRequest failed: %08x\n", hres
);
2456 CHECK_CALLED(LockRequest
);
2461 static HRESULT WINAPI
MimeProtocol_UnlockRequest(IInternetProtocolEx
*iface
)
2465 CHECK_EXPECT(MimeFilter_UnlockRequest
);
2467 SET_EXPECT(UnlockRequest
);
2468 hres
= IInternetProtocol_UnlockRequest(filtered_protocol
);
2469 ok(hres
== S_OK
, "UnlockRequest failed: %08x\n", hres
);
2470 CHECK_CALLED(UnlockRequest
);
2475 static const IInternetProtocolExVtbl MimeProtocolVtbl
= {
2476 MimeProtocol_QueryInterface
,
2482 MimeProtocol_Terminate
,
2487 MimeProtocol_LockRequest
,
2488 MimeProtocol_UnlockRequest
2491 static IInternetProtocolEx MimeProtocol
= { &MimeProtocolVtbl
};
2493 static HRESULT WINAPI
InternetProtocolInfo_QueryInterface(IInternetProtocolInfo
*iface
, REFIID riid
, void **ppv
)
2495 ok(0, "unexpected call\n");
2496 return E_NOINTERFACE
;
2499 static ULONG WINAPI
InternetProtocolInfo_AddRef(IInternetProtocolInfo
*iface
)
2504 static ULONG WINAPI
InternetProtocolInfo_Release(IInternetProtocolInfo
*iface
)
2509 static HRESULT WINAPI
InternetProtocolInfo_ParseUrl(IInternetProtocolInfo
*iface
, LPCWSTR pwzUrl
,
2510 PARSEACTION ParseAction
, DWORD dwParseFlags
, LPWSTR pwzResult
, DWORD cchResult
,
2511 DWORD
*pcchResult
, DWORD dwReserved
)
2513 ok(0, "unexpected call %d\n", ParseAction
);
2517 static HRESULT WINAPI
InternetProtocolInfo_CombineUrl(IInternetProtocolInfo
*iface
,
2518 LPCWSTR pwzBaseUrl
, LPCWSTR pwzRelativeUrl
, DWORD dwCombineFlags
,
2519 LPWSTR pwzResult
, DWORD cchResult
, DWORD
*pcchResult
, DWORD dwReserved
)
2521 ok(0, "unexpected call\n");
2525 static HRESULT WINAPI
InternetProtocolInfo_CompareUrl(IInternetProtocolInfo
*iface
,
2526 LPCWSTR pwzUrl1
, LPCWSTR pwzUrl2
, DWORD dwCompareFlags
)
2528 ok(0, "unexpected call\n");
2532 static HRESULT WINAPI
InternetProtocolInfo_QueryInfo(IInternetProtocolInfo
*iface
,
2533 LPCWSTR pwzUrl
, QUERYOPTION OueryOption
, DWORD dwQueryFlags
, LPVOID pBuffer
,
2534 DWORD cbBuffer
, DWORD
*pcbBuf
, DWORD dwReserved
)
2536 ok(0, "unexpected call\n");
2540 static const IInternetProtocolInfoVtbl InternetProtocolInfoVtbl
= {
2541 InternetProtocolInfo_QueryInterface
,
2542 InternetProtocolInfo_AddRef
,
2543 InternetProtocolInfo_Release
,
2544 InternetProtocolInfo_ParseUrl
,
2545 InternetProtocolInfo_CombineUrl
,
2546 InternetProtocolInfo_CompareUrl
,
2547 InternetProtocolInfo_QueryInfo
2550 static IInternetProtocolInfo protocol_info
= { &InternetProtocolInfoVtbl
};
2552 static HRESULT WINAPI
ClassFactory_QueryInterface(IClassFactory
*iface
, REFIID riid
, void **ppv
)
2554 if(IsEqualGUID(&IID_IInternetProtocolInfo
, riid
)) {
2555 *ppv
= &protocol_info
;
2559 ok(0, "unexpected call %s\n", wine_dbgstr_guid(riid
));
2560 return E_NOINTERFACE
;
2563 static ULONG WINAPI
ClassFactory_AddRef(IClassFactory
*iface
)
2568 static ULONG WINAPI
ClassFactory_Release(IClassFactory
*iface
)
2573 static HRESULT WINAPI
ClassFactory_CreateInstance(IClassFactory
*iface
, IUnknown
*pOuter
,
2574 REFIID riid
, void **ppv
)
2578 CHECK_EXPECT(CreateInstance
);
2580 ok(pOuter
== (IUnknown
*)prot_bind_info
, "pOuter != protocol_unk\n");
2581 ok(IsEqualGUID(&IID_IUnknown
, riid
), "unexpected riid %s\n", wine_dbgstr_guid(riid
));
2582 ok(ppv
!= NULL
, "ppv == NULL\n");
2584 ret
= heap_alloc(sizeof(*ret
));
2585 ret
->IUnknown_inner
.lpVtbl
= &ProtocolUnkVtbl
;
2586 ret
->IInternetProtocolEx_iface
.lpVtbl
= &ProtocolVtbl
;
2587 ret
->IInternetPriority_iface
.lpVtbl
= &InternetPriorityVtbl
;
2588 ret
->outer
= pOuter
;
2592 protocol_emul
= ret
;
2593 *ppv
= &ret
->IUnknown_inner
;
2597 static HRESULT WINAPI
ClassFactory_LockServer(IClassFactory
*iface
, BOOL dolock
)
2599 ok(0, "unexpected call\n");
2603 static const IClassFactoryVtbl ClassFactoryVtbl
= {
2604 ClassFactory_QueryInterface
,
2605 ClassFactory_AddRef
,
2606 ClassFactory_Release
,
2607 ClassFactory_CreateInstance
,
2608 ClassFactory_LockServer
2611 static IClassFactory ClassFactory
= { &ClassFactoryVtbl
};
2613 static HRESULT WINAPI
MimeFilter_CreateInstance(IClassFactory
*iface
, IUnknown
*outer
, REFIID riid
, void **ppv
)
2615 CHECK_EXPECT(MimeFilter_CreateInstance
);
2617 ok(!outer
, "outer = %p\n", outer
);
2618 ok(IsEqualGUID(&IID_IInternetProtocol
, riid
), "unexpected riid %s\n", wine_dbgstr_guid(riid
));
2620 *ppv
= &MimeProtocol
;
2624 static const IClassFactoryVtbl MimeFilterCFVtbl
= {
2625 ClassFactory_QueryInterface
,
2626 ClassFactory_AddRef
,
2627 ClassFactory_Release
,
2628 MimeFilter_CreateInstance
,
2629 ClassFactory_LockServer
2632 static IClassFactory mimefilter_cf
= { &MimeFilterCFVtbl
};
2634 #define TEST_BINDING 0x0001
2635 #define TEST_FILTER 0x0002
2636 #define TEST_FIRST_HTTP 0x0004
2637 #define TEST_DIRECT_READ 0x0008
2638 #define TEST_POST 0x0010
2639 #define TEST_EMULATEPROT 0x0020
2640 #define TEST_SHORT_READ 0x0040
2641 #define TEST_REDIRECT 0x0080
2642 #define TEST_ABORT 0x0100
2643 #define TEST_ASYNCREQ 0x0200
2644 #define TEST_USEIURI 0x0400
2645 #define TEST_IMPLPROTEX 0x0800
2646 #define TEST_EMPTY 0x1000
2647 #define TEST_NOMIME 0x2000
2648 #define TEST_FROMCACHE 0x4000
2649 #define TEST_DISABLEAUTOREDIRECT 0x8000
2651 static void register_filter(BOOL do_register
)
2653 IInternetSession
*session
;
2656 hres
= pCoInternetGetSession(0, &session
, 0);
2657 ok(hres
== S_OK
, "CoInternetGetSession failed: %08x\n", hres
);
2660 hres
= IInternetSession_RegisterMimeFilter(session
, &mimefilter_cf
, &IID_IInternetProtocol
, pjpegW
);
2661 ok(hres
== S_OK
, "RegisterMimeFilter failed: %08x\n", hres
);
2662 hres
= IInternetSession_RegisterMimeFilter(session
, &mimefilter_cf
, &IID_IInternetProtocol
, gifW
);
2663 ok(hres
== S_OK
, "RegisterMimeFilter failed: %08x\n", hres
);
2665 hres
= IInternetSession_UnregisterMimeFilter(session
, &mimefilter_cf
, pjpegW
);
2666 ok(hres
== S_OK
, "RegisterMimeFilter failed: %08x\n", hres
);
2667 hres
= IInternetSession_UnregisterMimeFilter(session
, &mimefilter_cf
, gifW
);
2668 ok(hres
== S_OK
, "RegisterMimeFilter failed: %08x\n", hres
);
2671 IInternetSession_Release(session
);
2674 static void init_test(int prot
, DWORD flags
)
2676 tested_protocol
= prot
;
2677 binding_test
= (flags
& TEST_BINDING
) != 0;
2678 first_data_notif
= TRUE
;
2681 async_read_pending
= TRUE
;
2682 mimefilter_test
= (flags
& TEST_FILTER
) != 0;
2683 no_mime
= (flags
& TEST_NOMIME
) != 0;
2685 post_stream_read
= 0;
2686 ResetEvent(event_complete
);
2687 ResetEvent(event_complete2
);
2688 ResetEvent(event_continue
);
2689 ResetEvent(event_continue_done
);
2690 async_protocol
= binding_protocol
= filtered_protocol
= NULL
;
2691 filtered_sink
= NULL
;
2692 http_is_first
= (flags
& TEST_FIRST_HTTP
) != 0;
2693 first_data_notif
= TRUE
;
2694 state
= STATE_CONNECTING
;
2695 test_async_req
= (flags
& TEST_ASYNCREQ
) != 0;
2696 direct_read
= (flags
& TEST_DIRECT_READ
) != 0;
2697 emulate_prot
= (flags
& TEST_EMULATEPROT
) != 0;
2698 wait_for_switch
= TRUE
;
2699 short_read
= (flags
& TEST_SHORT_READ
) != 0;
2700 http_post_test
= TYMED_NULL
;
2701 redirect_on_continue
= test_redirect
= (flags
& TEST_REDIRECT
) != 0;
2702 test_abort
= (flags
& TEST_ABORT
) != 0;
2703 impl_protex
= (flags
& TEST_IMPLPROTEX
) != 0;
2704 empty_file
= (flags
& TEST_EMPTY
) != 0;
2705 bind_from_cache
= (flags
& TEST_FROMCACHE
) != 0;
2706 file_with_hash
= FALSE
;
2707 security_problem
= FALSE
;
2708 reuse_protocol_thread
= FALSE
;
2710 bindinfo_options
= 0;
2711 if(flags
& TEST_DISABLEAUTOREDIRECT
)
2712 bindinfo_options
|= BINDINFO_OPTIONS_DISABLEAUTOREDIRECTS
;
2714 register_filter(mimefilter_test
);
2717 static void test_priority(IInternetProtocol
*protocol
)
2719 IInternetPriority
*priority
;
2723 hres
= IInternetProtocol_QueryInterface(protocol
, &IID_IInternetPriority
,
2725 ok(hres
== S_OK
, "QueryInterface(IID_IInternetPriority) failed: %08x\n", hres
);
2729 hres
= IInternetPriority_GetPriority(priority
, &pr
);
2730 ok(hres
== S_OK
, "GetPriority failed: %08x\n", hres
);
2731 ok(pr
== 0, "pr=%d, expected 0\n", pr
);
2733 hres
= IInternetPriority_SetPriority(priority
, 1);
2734 ok(hres
== S_OK
, "SetPriority failed: %08x\n", hres
);
2736 hres
= IInternetPriority_GetPriority(priority
, &pr
);
2737 ok(hres
== S_OK
, "GetPriority failed: %08x\n", hres
);
2738 ok(pr
== 1, "pr=%d, expected 1\n", pr
);
2740 IInternetPriority_Release(priority
);
2743 static void test_early_abort(const CLSID
*clsid
)
2745 IInternetProtocol
*protocol
;
2748 hres
= CoCreateInstance(clsid
, NULL
, CLSCTX_INPROC_SERVER
|CLSCTX_INPROC_HANDLER
,
2749 &IID_IInternetProtocol
, (void**)&protocol
);
2750 ok(hres
== S_OK
, "CoCreateInstance failed: %08x\n", hres
);
2752 hres
= IInternetProtocol_Abort(protocol
, E_ABORT
, 0);
2753 ok(hres
== S_OK
, "Abort failed: %08x\n", hres
);
2755 hres
= IInternetProtocol_Abort(protocol
, E_FAIL
, 0);
2756 ok(hres
== S_OK
, "Abort failed: %08x\n", hres
);
2758 IInternetProtocol_Release(protocol
);
2761 static BOOL
file_protocol_start(IInternetProtocol
*protocol
, LPCWSTR url
,
2762 IInternetProtocolEx
*protocolex
, IUri
*uri
, BOOL is_first
)
2766 SET_EXPECT(GetBindInfo
);
2767 if(!(bindf
& BINDF_FROMURLMON
))
2768 SET_EXPECT(ReportProgress_DIRECTBIND
);
2770 SET_EXPECT(ReportProgress_SENDINGREQUEST
);
2771 SET_EXPECT(ReportProgress_CACHEFILENAMEAVAILABLE
);
2772 if(bindf
& BINDF_FROMURLMON
)
2773 SET_EXPECT(ReportProgress_VERIFIEDMIMETYPEAVAILABLE
);
2775 SET_EXPECT(ReportProgress_MIMETYPEAVAILABLE
);
2777 SET_EXPECT(ReportData
);
2779 SET_EXPECT(ReportResult
);
2781 expect_hrResult
= S_OK
;
2784 hres
= IInternetProtocolEx_StartEx(protocolex
, uri
, &protocol_sink
, &bind_info
, 0, 0);
2785 ok(hres
== S_OK
, "StartEx failed: %08x\n", hres
);
2787 hres
= IInternetProtocol_Start(protocol
, url
, &protocol_sink
, &bind_info
, 0, 0);
2788 if(hres
== INET_E_RESOURCE_NOT_FOUND
) {
2789 win_skip("Start failed\n");
2792 ok(hres
== S_OK
, "Start failed: %08x\n", hres
);
2795 CHECK_CALLED(GetBindInfo
);
2796 if(!(bindf
& BINDF_FROMURLMON
))
2797 CLEAR_CALLED(ReportProgress_DIRECTBIND
); /* Not called by IE10 */
2799 CHECK_CALLED(ReportProgress_SENDINGREQUEST
);
2800 CHECK_CALLED(ReportProgress_CACHEFILENAMEAVAILABLE
);
2801 if(bindf
& BINDF_FROMURLMON
)
2802 CHECK_CALLED(ReportProgress_VERIFIEDMIMETYPEAVAILABLE
);
2804 CHECK_CALLED(ReportProgress_MIMETYPEAVAILABLE
);
2806 CHECK_CALLED(ReportData
);
2808 CHECK_CALLED(ReportResult
);
2813 static void test_file_protocol_url(LPCWSTR url
)
2815 IInternetProtocolInfo
*protocol_info
;
2817 IClassFactory
*factory
;
2818 IInternetProtocol
*protocol
;
2823 hres
= CoGetClassObject(&CLSID_FileProtocol
, CLSCTX_INPROC_SERVER
, NULL
,
2824 &IID_IUnknown
, (void**)&unk
);
2825 ok(hres
== S_OK
, "CoGetClassObject failed: %08x\n", hres
);
2829 hres
= IUnknown_QueryInterface(unk
, &IID_IInternetProtocolInfo
, (void**)&protocol_info
);
2830 ok(hres
== E_NOINTERFACE
,
2831 "Could not get IInternetProtocolInfo interface: %08x, expected E_NOINTERFACE\n", hres
);
2833 hres
= IUnknown_QueryInterface(unk
, &IID_IClassFactory
, (void**)&factory
);
2834 ok(hres
== S_OK
, "Could not get IClassFactory interface\n");
2835 IUnknown_Release(unk
);
2839 hres
= IClassFactory_CreateInstance(factory
, NULL
, &IID_IInternetProtocol
, (void**)&protocol
);
2840 ok(hres
== S_OK
, "Could not get IInternetProtocol: %08x\n", hres
);
2842 if(SUCCEEDED(hres
)) {
2843 if(file_protocol_start(protocol
, url
, NULL
, NULL
, TRUE
)) {
2844 hres
= IInternetProtocol_Read(protocol
, buf
, 2, &cb
);
2845 ok(hres
== S_OK
, "Read failed: %08x\n", hres
);
2846 ok(cb
== 2, "cb=%u expected 2\n", cb
);
2848 ok(!memcmp(buf
, file_with_hash
? "XX" : "<H", 2), "Unexpected data %s\n", buf
);
2849 hres
= IInternetProtocol_Read(protocol
, buf
, sizeof(buf
), &cb
);
2850 ok(hres
== S_FALSE
, "Read failed: %08x\n", hres
);
2851 hres
= IInternetProtocol_Read(protocol
, buf
, sizeof(buf
), &cb
);
2852 ok(hres
== S_FALSE
, "Read failed: %08x expected S_FALSE\n", hres
);
2853 ok(cb
== 0, "cb=%u expected 0\n", cb
);
2854 hres
= IInternetProtocol_UnlockRequest(protocol
);
2855 ok(hres
== S_OK
, "UnlockRequest failed: %08x\n", hres
);
2858 if(file_protocol_start(protocol
, url
, NULL
, NULL
, FALSE
)) {
2859 hres
= IInternetProtocol_Read(protocol
, buf
, 2, &cb
);
2860 ok(hres
== S_FALSE
, "Read failed: %08x\n", hres
);
2861 hres
= IInternetProtocol_LockRequest(protocol
, 0);
2862 ok(hres
== S_OK
, "LockRequest failed: %08x\n", hres
);
2863 hres
= IInternetProtocol_UnlockRequest(protocol
);
2864 ok(hres
== S_OK
, "UnlockRequest failed: %08x\n", hres
);
2867 IInternetProtocol_Release(protocol
);
2870 hres
= IClassFactory_CreateInstance(factory
, NULL
, &IID_IInternetProtocol
, (void**)&protocol
);
2871 ok(hres
== S_OK
, "Could not get IInternetProtocol: %08x\n", hres
);
2872 if(SUCCEEDED(hres
)) {
2873 if(file_protocol_start(protocol
, url
, NULL
, NULL
, TRUE
)) {
2874 hres
= IInternetProtocol_LockRequest(protocol
, 0);
2875 ok(hres
== S_OK
, "LockRequest failed: %08x\n", hres
);
2876 hres
= IInternetProtocol_Terminate(protocol
, 0);
2877 ok(hres
== S_OK
, "Terminate failed: %08x\n", hres
);
2878 hres
= IInternetProtocol_Read(protocol
, buf
, 2, &cb
);
2879 ok(hres
== S_OK
, "Read failed: %08x\n\n", hres
);
2880 hres
= IInternetProtocol_UnlockRequest(protocol
);
2881 ok(hres
== S_OK
, "UnlockRequest failed: %08x\n", hres
);
2882 hres
= IInternetProtocol_Read(protocol
, buf
, 2, &cb
);
2883 todo_wine_if(file_with_hash
) /* FIXME: An effect of UnlockRequest call? */
2884 ok(hres
== S_OK
, "Read failed: %08x\n", hres
);
2885 hres
= IInternetProtocol_Terminate(protocol
, 0);
2886 ok(hres
== S_OK
, "Terminate failed: %08x\n", hres
);
2889 IInternetProtocol_Release(protocol
);
2892 hres
= IClassFactory_CreateInstance(factory
, NULL
, &IID_IInternetProtocol
, (void**)&protocol
);
2893 ok(hres
== S_OK
, "Could not get IInternetProtocol: %08x\n", hres
);
2894 if(SUCCEEDED(hres
)) {
2895 if(file_protocol_start(protocol
, url
, NULL
, NULL
, TRUE
)) {
2896 hres
= IInternetProtocol_Terminate(protocol
, 0);
2897 ok(hres
== S_OK
, "Terminate failed: %08x\n", hres
);
2898 hres
= IInternetProtocol_Read(protocol
, buf
, 2, &cb
);
2899 ok(hres
== S_OK
, "Read failed: %08x\n", hres
);
2900 ok(cb
== 2, "cb=%u expected 2\n", cb
);
2903 IInternetProtocol_Release(protocol
);
2907 IInternetProtocolEx
*protocolex
;
2910 hres
= pCreateUri(url
, Uri_CREATE_FILE_USE_DOS_PATH
, 0, &uri
);
2911 ok(hres
== S_OK
, "CreateUri failed: %08x\n", hres
);
2913 hres
= IClassFactory_CreateInstance(factory
, NULL
, &IID_IInternetProtocolEx
, (void**)&protocolex
);
2914 ok(hres
== S_OK
, "Could not get IInternetProtocolEx: %08x\n", hres
);
2916 if(file_protocol_start(NULL
, NULL
, protocolex
, uri
, TRUE
)) {
2917 hres
= IInternetProtocolEx_Read(protocolex
, buf
, 2, &cb
);
2918 ok(hres
== S_OK
, "Read failed: %08x\n", hres
);
2919 hres
= IInternetProtocolEx_LockRequest(protocolex
, 0);
2920 ok(hres
== S_OK
, "LockRequest failed: %08x\n", hres
);
2921 hres
= IInternetProtocolEx_UnlockRequest(protocolex
);
2922 ok(hres
== S_OK
, "UnlockRequest failed: %08x\n", hres
);
2926 IInternetProtocolEx_Release(protocolex
);
2928 hres
= pCreateUri(url
, 0, 0, &uri
);
2929 ok(hres
== S_OK
, "CreateUri failed: %08x\n", hres
);
2931 hres
= IClassFactory_CreateInstance(factory
, NULL
, &IID_IInternetProtocolEx
, (void**)&protocolex
);
2932 ok(hres
== S_OK
, "Could not get IInternetProtocolEx: %08x\n", hres
);
2934 if(file_protocol_start(NULL
, NULL
, protocolex
, uri
, TRUE
)) {
2935 hres
= IInternetProtocolEx_Read(protocolex
, buf
, 2, &cb
);
2936 ok(hres
== S_OK
, "Read failed: %08x\n", hres
);
2937 hres
= IInternetProtocolEx_LockRequest(protocolex
, 0);
2938 ok(hres
== S_OK
, "LockRequest failed: %08x\n", hres
);
2939 hres
= IInternetProtocolEx_UnlockRequest(protocolex
);
2940 ok(hres
== S_OK
, "UnlockRequest failed: %08x\n", hres
);
2944 IInternetProtocolEx_Release(protocolex
);
2946 win_skip("Skipping file protocol StartEx tests\n");
2949 IClassFactory_Release(factory
);
2952 static void test_file_protocol_fail(void)
2954 IInternetProtocol
*protocol
;
2957 static const WCHAR index_url2
[] =
2958 {'f','i','l','e',':','/','/','i','n','d','e','x','.','h','t','m','l',0};
2960 hres
= CoCreateInstance(&CLSID_FileProtocol
, NULL
, CLSCTX_INPROC_SERVER
|CLSCTX_INPROC_HANDLER
,
2961 &IID_IInternetProtocol
, (void**)&protocol
);
2962 ok(hres
== S_OK
, "CoCreateInstance failed: %08x\n", hres
);
2966 SET_EXPECT(GetBindInfo
);
2967 expect_hrResult
= MK_E_SYNTAX
;
2968 hres
= IInternetProtocol_Start(protocol
, wszIndexHtml
, &protocol_sink
, &bind_info
, 0, 0);
2969 ok(hres
== MK_E_SYNTAX
||
2970 hres
== E_INVALIDARG
,
2971 "Start failed: %08x, expected MK_E_SYNTAX or E_INVALIDARG\n", hres
);
2972 CLEAR_CALLED(GetBindInfo
); /* GetBindInfo not called in IE7 */
2974 SET_EXPECT(GetBindInfo
);
2975 if(!(bindf
& BINDF_FROMURLMON
))
2976 SET_EXPECT(ReportProgress_DIRECTBIND
);
2977 SET_EXPECT(ReportProgress_SENDINGREQUEST
);
2978 SET_EXPECT(ReportResult
);
2979 expect_hrResult
= INET_E_RESOURCE_NOT_FOUND
;
2980 hres
= IInternetProtocol_Start(protocol
, index_url
, &protocol_sink
, &bind_info
, 0, 0);
2981 ok(hres
== INET_E_RESOURCE_NOT_FOUND
,
2982 "Start failed: %08x expected INET_E_RESOURCE_NOT_FOUND\n", hres
);
2983 CHECK_CALLED(GetBindInfo
);
2984 if(!(bindf
& BINDF_FROMURLMON
))
2985 CHECK_CALLED(ReportProgress_DIRECTBIND
);
2986 CHECK_CALLED(ReportProgress_SENDINGREQUEST
);
2987 CHECK_CALLED(ReportResult
);
2989 IInternetProtocol_Release(protocol
);
2991 hres
= CoCreateInstance(&CLSID_FileProtocol
, NULL
, CLSCTX_INPROC_SERVER
|CLSCTX_INPROC_HANDLER
,
2992 &IID_IInternetProtocol
, (void**)&protocol
);
2993 ok(hres
== S_OK
, "CoCreateInstance failed: %08x\n", hres
);
2997 SET_EXPECT(GetBindInfo
);
2998 if(!(bindf
& BINDF_FROMURLMON
))
2999 SET_EXPECT(ReportProgress_DIRECTBIND
);
3000 SET_EXPECT(ReportProgress_SENDINGREQUEST
);
3001 SET_EXPECT(ReportResult
);
3002 expect_hrResult
= INET_E_RESOURCE_NOT_FOUND
;
3004 hres
= IInternetProtocol_Start(protocol
, index_url2
, &protocol_sink
, &bind_info
, 0, 0);
3005 ok(hres
== INET_E_RESOURCE_NOT_FOUND
,
3006 "Start failed: %08x, expected INET_E_RESOURCE_NOT_FOUND\n", hres
);
3007 CHECK_CALLED(GetBindInfo
);
3008 if(!(bindf
& BINDF_FROMURLMON
))
3009 CHECK_CALLED(ReportProgress_DIRECTBIND
);
3010 CHECK_CALLED(ReportProgress_SENDINGREQUEST
);
3011 CHECK_CALLED(ReportResult
);
3013 SET_EXPECT(GetBindInfo
);
3014 hres
= IInternetProtocol_Start(protocol
, NULL
, &protocol_sink
, &bind_info
, 0, 0);
3015 ok(hres
== E_INVALIDARG
, "Start failed: %08x, expected E_INVALIDARG\n", hres
);
3016 CLEAR_CALLED(GetBindInfo
); /* GetBindInfo not called in IE7 */
3018 SET_EXPECT(GetBindInfo
);
3019 hres
= IInternetProtocol_Start(protocol
, emptyW
, &protocol_sink
, &bind_info
, 0, 0);
3020 ok(hres
== E_INVALIDARG
, "Start failed: %08x, expected E_INVALIDARG\n", hres
);
3021 CLEAR_CALLED(GetBindInfo
); /* GetBindInfo not called in IE7 */
3023 IInternetProtocol_Release(protocol
);
3026 static void test_file_protocol(void) {
3027 WCHAR buf
[INTERNET_MAX_URL_LENGTH
], file_name_buf
[MAX_PATH
];
3032 static const WCHAR wszFile
[] = {'f','i','l','e',':',0};
3033 static const WCHAR wszFile2
[] = {'f','i','l','e',':','/','/',0};
3034 static const WCHAR wszFile3
[] = {'f','i','l','e',':','/','/','/',0};
3035 static const WCHAR wszFile4
[] = {'f','i','l','e',':','\\','\\',0};
3036 static const char html_doc
[] = "<HTML></HTML>";
3037 static const WCHAR fragmentW
[] = {'#','f','r','a','g',0};
3039 trace("Testing file protocol...\n");
3040 init_test(FILE_TEST
, 0);
3042 SetLastError(0xdeadbeef);
3043 file
= CreateFileW(wszIndexHtml
, GENERIC_WRITE
, 0, NULL
, CREATE_ALWAYS
,
3044 FILE_ATTRIBUTE_NORMAL
, NULL
);
3045 ok(file
!= INVALID_HANDLE_VALUE
, "CreateFile failed\n");
3046 if(file
== INVALID_HANDLE_VALUE
)
3048 WriteFile(file
, html_doc
, sizeof(html_doc
)-1, &size
, NULL
);
3051 file_name
= wszIndexHtml
;
3053 test_file_protocol_url(index_url
);
3054 bindf
= BINDF_FROMURLMON
;
3055 test_file_protocol_url(index_url
);
3056 bindf
= BINDF_FROMURLMON
| BINDF_NEEDFILE
;
3057 test_file_protocol_url(index_url
);
3059 memcpy(buf
, wszFile
, sizeof(wszFile
));
3060 len
= sizeof(wszFile
)/sizeof(WCHAR
)-1;
3061 len
+= GetCurrentDirectoryW(sizeof(buf
)/sizeof(WCHAR
)-len
, buf
+len
);
3063 memcpy(buf
+len
, wszIndexHtml
, sizeof(wszIndexHtml
));
3065 file_name
= buf
+ sizeof(wszFile
)/sizeof(WCHAR
)-1;
3067 test_file_protocol_url(buf
);
3068 bindf
= BINDF_FROMURLMON
;
3069 test_file_protocol_url(buf
);
3071 memcpy(buf
, wszFile2
, sizeof(wszFile2
));
3072 len
= GetCurrentDirectoryW(sizeof(file_name_buf
)/sizeof(WCHAR
), file_name_buf
);
3073 file_name_buf
[len
++] = '\\';
3074 memcpy(file_name_buf
+len
, wszIndexHtml
, sizeof(wszIndexHtml
));
3075 lstrcpyW(buf
+sizeof(wszFile2
)/sizeof(WCHAR
)-1, file_name_buf
);
3076 file_name
= file_name_buf
;
3078 test_file_protocol_url(buf
);
3079 bindf
= BINDF_FROMURLMON
;
3080 test_file_protocol_url(buf
);
3082 buf
[sizeof(wszFile2
)/sizeof(WCHAR
)] = '|';
3083 test_file_protocol_url(buf
);
3085 memcpy(buf
, wszFile3
, sizeof(wszFile3
));
3086 len
= sizeof(wszFile3
)/sizeof(WCHAR
)-1;
3087 len
+= GetCurrentDirectoryW(sizeof(buf
)/sizeof(WCHAR
)-len
, buf
+len
);
3089 memcpy(buf
+len
, wszIndexHtml
, sizeof(wszIndexHtml
));
3091 file_name
= buf
+ sizeof(wszFile3
)/sizeof(WCHAR
)-1;
3093 test_file_protocol_url(buf
);
3094 bindf
= BINDF_FROMURLMON
;
3095 test_file_protocol_url(buf
);
3097 memcpy(buf
, wszFile4
, sizeof(wszFile4
));
3098 len
= GetCurrentDirectoryW(sizeof(file_name_buf
)/sizeof(WCHAR
), file_name_buf
);
3099 file_name_buf
[len
++] = '\\';
3100 memcpy(file_name_buf
+len
, wszIndexHtml
, sizeof(wszIndexHtml
));
3101 lstrcpyW(buf
+sizeof(wszFile4
)/sizeof(WCHAR
)-1, file_name_buf
);
3102 file_name
= file_name_buf
;
3104 test_file_protocol_url(buf
);
3105 bindf
= BINDF_FROMURLMON
;
3106 test_file_protocol_url(buf
);
3108 buf
[sizeof(wszFile4
)/sizeof(WCHAR
)] = '|';
3109 test_file_protocol_url(buf
);
3111 /* Fragment part of URL is skipped if the file doesn't exist. */
3112 lstrcatW(buf
, fragmentW
);
3113 test_file_protocol_url(buf
);
3115 /* Fragment part is considered a part of the file name, if the file exsists. */
3116 len
= lstrlenW(file_name_buf
);
3117 lstrcpyW(file_name_buf
+len
, fragmentW
);
3118 file
= CreateFileW(wszIndexHtml
, GENERIC_WRITE
, 0, NULL
, CREATE_ALWAYS
,
3119 FILE_ATTRIBUTE_NORMAL
, NULL
);
3120 ok(file
!= INVALID_HANDLE_VALUE
, "CreateFile failed\n");
3121 WriteFile(file
, "XXX", 3, &size
, NULL
);
3123 file_name_buf
[len
] = 0;
3125 file_with_hash
= TRUE
;
3126 test_file_protocol_url(buf
);
3128 DeleteFileW(wszIndexHtml
);
3129 DeleteFileW(file_name_buf
);
3132 test_file_protocol_fail();
3133 bindf
= BINDF_FROMURLMON
;
3134 test_file_protocol_fail();
3137 static void create_cache_entry(const WCHAR
*urlw
)
3139 FILETIME now
, tomorrow
, yesterday
;
3140 char file_path
[MAX_PATH
];
3149 BYTE cache_headers
[] = "HTTP/1.1 200 OK\r\n\r\n";
3151 trace("Testing cache read...\n");
3155 for(i
= 0; i
< sizeof(content
); i
++)
3156 content
[i
] = '0' + (i
%10);
3158 GetSystemTimeAsFileTime(&now
);
3159 li
.u
.HighPart
= now
.dwHighDateTime
;
3160 li
.u
.LowPart
= now
.dwLowDateTime
;
3161 li
.QuadPart
+= (LONGLONG
)10000000 * 3600 * 24;
3162 tomorrow
.dwHighDateTime
= li
.u
.HighPart
;
3163 tomorrow
.dwLowDateTime
= li
.u
.LowPart
;
3164 li
.QuadPart
-= (LONGLONG
)10000000 * 3600 * 24 * 2;
3165 yesterday
.dwHighDateTime
= li
.u
.HighPart
;
3166 yesterday
.dwLowDateTime
= li
.u
.LowPart
;
3168 res
= CreateUrlCacheEntryA(url
, sizeof(content
), "", file_path
, 0);
3169 ok(res
, "CreateUrlCacheEntryA failed: %u\n", GetLastError());
3171 file
= CreateFileA(file_path
, GENERIC_WRITE
, 0, NULL
, CREATE_ALWAYS
, FILE_ATTRIBUTE_NORMAL
, NULL
);
3172 ok(file
!= INVALID_HANDLE_VALUE
, "CreateFile failed\n");
3174 WriteFile(file
, content
, sizeof(content
), &size
, NULL
);
3177 res
= CommitUrlCacheEntryA(url
, file_path
, tomorrow
, yesterday
, NORMAL_CACHE_ENTRY
,
3178 cache_headers
, sizeof(cache_headers
)-1, "", 0);
3179 ok(res
, "CommitUrlCacheEntryA failed: %u\n", GetLastError());
3182 static BOOL
http_protocol_start(LPCWSTR url
, BOOL use_iuri
)
3184 static BOOL got_user_agent
= FALSE
;
3188 if(use_iuri
&& pCreateUri
) {
3189 hres
= pCreateUri(url
, 0, 0, &uri
);
3190 ok(hres
== S_OK
, "CreateUri failed: %08x\n", hres
);
3193 SET_EXPECT(GetBindInfo
);
3194 if (!(bindf
& BINDF_FROMURLMON
))
3195 SET_EXPECT(ReportProgress_DIRECTBIND
);
3197 SET_EXPECT(GetBindString_USER_AGENT
);
3198 SET_EXPECT(GetBindString_ROOTDOC_URL
);
3199 SET_EXPECT(GetBindString_ACCEPT_MIMES
);
3200 SET_EXPECT(QueryService_HttpNegotiate
);
3201 SET_EXPECT(BeginningTransaction
);
3202 SET_EXPECT(GetRootSecurityId
);
3203 if(http_post_test
) {
3204 SET_EXPECT(GetBindString_POST_COOKIE
);
3205 if(http_post_test
== TYMED_ISTREAM
)
3206 SET_EXPECT(Stream_Seek
);
3208 if(bind_from_cache
) {
3209 SET_EXPECT(OnResponse
);
3210 SET_EXPECT(ReportProgress_MIMETYPEAVAILABLE
);
3211 SET_EXPECT(ReportData
);
3215 IInternetProtocolEx
*protocolex
;
3217 hres
= IInternetProtocol_QueryInterface(async_protocol
, &IID_IInternetProtocolEx
, (void**)&protocolex
);
3218 ok(hres
== S_OK
, "Could not get IInternetProtocolEx iface: %08x\n", hres
);
3220 hres
= IInternetProtocolEx_StartEx(protocolex
, uri
, &protocol_sink
, &bind_info
, 0, 0);
3221 ok(hres
== S_OK
, "Start failed: %08x\n", hres
);
3223 IInternetProtocolEx_Release(protocolex
);
3226 hres
= IInternetProtocol_Start(async_protocol
, url
, &protocol_sink
, &bind_info
, 0, 0);
3227 ok(hres
== S_OK
, "Start failed: %08x\n", hres
);
3232 CHECK_CALLED(GetBindInfo
);
3233 if (!(bindf
& BINDF_FROMURLMON
))
3234 CHECK_CALLED(ReportProgress_DIRECTBIND
);
3235 if (!got_user_agent
)
3237 CHECK_CALLED(GetBindString_USER_AGENT
);
3238 got_user_agent
= TRUE
;
3240 CLEAR_CALLED(GetBindString_ROOTDOC_URL
); /* New in IE11 */
3241 CHECK_CALLED(GetBindString_ACCEPT_MIMES
);
3242 CHECK_CALLED(QueryService_HttpNegotiate
);
3243 CHECK_CALLED(BeginningTransaction
);
3244 /* GetRootSecurityId called on WinXP but not on Win98 */
3245 CLEAR_CALLED(GetRootSecurityId
);
3246 if(http_post_test
) {
3247 CHECK_CALLED(GetBindString_POST_COOKIE
);
3248 if(http_post_test
== TYMED_ISTREAM
)
3249 CHECK_CALLED(Stream_Seek
);
3251 if(bind_from_cache
) {
3252 CHECK_CALLED(OnResponse
);
3253 CHECK_CALLED(ReportProgress_MIMETYPEAVAILABLE
);
3254 CHECK_CALLED(ReportData
);
3260 static void test_protocol_terminate(IInternetProtocol
*protocol
)
3266 hres
= IInternetProtocol_LockRequest(protocol
, 0);
3267 ok(hres
== S_OK
, "LockRequest failed: %08x\n", hres
);
3269 hres
= IInternetProtocol_Read(protocol
, buf
, 1, &cb
);
3270 ok(hres
== (test_abort
? S_OK
: S_FALSE
), "Read failed: %08x\n", hres
);
3272 hres
= IInternetProtocol_Terminate(protocol
, 0);
3273 ok(hres
== S_OK
, "Terminate failed: %08x\n", hres
);
3275 /* This wait is to give the internet handles being freed in Terminate
3276 * enough time to actually terminate in all cases. Internet handles
3277 * terminate asynchronously and native reuses the main InternetOpen
3278 * handle. The only case in which this seems to be necessary is on
3279 * wine with native wininet and urlmon, resulting in the next time
3280 * test_http_protocol_url being called the first data notification actually
3281 * being an extra last data notification from the previous connection
3282 * about once out of every ten times. */
3285 hres
= IInternetProtocol_UnlockRequest(protocol
);
3286 ok(hres
== S_OK
, "UnlockRequest failed: %08x\n", hres
);
3289 /* is_first refers to whether this is the first call to this function
3291 static void test_http_protocol_url(LPCWSTR url
, int prot
, DWORD flags
, DWORD tymed
)
3293 IInternetProtocolInfo
*protocol_info
;
3294 IClassFactory
*factory
;
3298 init_test(prot
, flags
);
3300 http_post_test
= tymed
;
3301 if(flags
& TEST_FROMCACHE
)
3302 create_cache_entry(url
);
3304 hres
= CoGetClassObject(prot
== HTTPS_TEST
? &CLSID_HttpSProtocol
: &CLSID_HttpProtocol
,
3305 CLSCTX_INPROC_SERVER
, NULL
, &IID_IUnknown
, (void**)&unk
);
3306 ok(hres
== S_OK
, "CoGetClassObject failed: %08x\n", hres
);
3310 hres
= IUnknown_QueryInterface(unk
, &IID_IInternetProtocolInfo
, (void**)&protocol_info
);
3311 ok(hres
== E_NOINTERFACE
,
3312 "Could not get IInternetProtocolInfo interface: %08x, expected E_NOINTERFACE\n",
3315 hres
= IUnknown_QueryInterface(unk
, &IID_IClassFactory
, (void**)&factory
);
3316 ok(hres
== S_OK
, "Could not get IClassFactory interface\n");
3317 IUnknown_Release(unk
);
3321 hres
= IClassFactory_CreateInstance(factory
, NULL
, &IID_IInternetProtocol
,
3322 (void**)&async_protocol
);
3323 ok(hres
== S_OK
, "Could not get IInternetProtocol: %08x\n", hres
);
3324 if(SUCCEEDED(hres
)) {
3329 test_priority(async_protocol
);
3331 SET_EXPECT(ReportProgress_COOKIE_SENT
);
3333 SET_EXPECT(ReportProgress_FINDINGRESOURCE
);
3334 SET_EXPECT(ReportProgress_CONNECTING
);
3336 SET_EXPECT(ReportProgress_SENDINGREQUEST
);
3337 if(test_redirect
&& !(bindinfo_options
& BINDINFO_OPTIONS_DISABLEAUTOREDIRECTS
))
3338 SET_EXPECT(ReportProgress_REDIRECTING
);
3339 SET_EXPECT(ReportProgress_PROXYDETECTING
);
3340 if(prot
== HTTP_TEST
)
3341 SET_EXPECT(ReportProgress_CACHEFILENAMEAVAILABLE
);
3343 SET_EXPECT(QueryService_HttpSecurity
);
3344 if(!(bindf
& BINDF_FROMURLMON
)) {
3345 SET_EXPECT(OnResponse
);
3346 SET_EXPECT(ReportProgress_RAWMIMETYPE
);
3347 SET_EXPECT(ReportData
);
3352 if(!http_protocol_start(url
, (flags
& TEST_USEIURI
) != 0)) {
3353 IInternetProtocol_Abort(async_protocol
, E_ABORT
, 0);
3354 IInternetProtocol_Release(async_protocol
);
3358 if(!direct_read
&& !test_abort
&& !bind_from_cache
)
3359 SET_EXPECT(ReportResult
);
3361 if(flags
& TEST_DISABLEAUTOREDIRECT
)
3362 expect_hrResult
= INET_E_REDIRECT_FAILED
;
3364 expect_hrResult
= E_ABORT
;
3366 expect_hrResult
= S_OK
;
3370 while(wait_for_switch
) {
3371 ok( WaitForSingleObject(event_continue
, 90000) == WAIT_OBJECT_0
, "wait timed out\n" );
3372 CHECK_CALLED(Switch
); /* Set in ReportData */
3373 call_continue(&continue_protdata
);
3374 SetEvent(event_continue_done
);
3376 }else if(bind_from_cache
) {
3379 hres
= IInternetProtocol_Read(async_protocol
, buf
, 100, &cb
);
3380 ok(hres
== S_OK
&& cb
== 100, "Read failed: %08x (%d bytes)\n", hres
, cb
);
3382 SET_EXPECT(ReportResult
);
3383 hres
= IInternetProtocol_Read(async_protocol
, buf
, sizeof(buf
), &cb
);
3384 ok(hres
== S_OK
&& cb
== 900, "Read failed: %08x (%d bytes)\n", hres
, cb
);
3385 CHECK_CALLED(ReportResult
);
3387 hres
= IInternetProtocol_Read(async_protocol
, buf
, sizeof(buf
), &cb
);
3388 ok(hres
== S_FALSE
&& !cb
, "Read failed: %08x (%d bytes)\n", hres
, cb
);
3390 hres
= IInternetProtocol_Read(async_protocol
, buf
, 1, &cb
);
3391 ok((hres
== E_PENDING
&& cb
==0) ||
3392 (hres
== S_OK
&& cb
==1), "Read failed: %08x (%d bytes)\n", hres
, cb
);
3394 ok( WaitForSingleObject(event_complete
, 90000) == WAIT_OBJECT_0
, "wait timed out\n" );
3395 if(bindf
& BINDF_FROMURLMON
)
3396 CHECK_CALLED(Switch
);
3398 CHECK_CALLED(ReportData
);
3399 if(prot
== HTTPS_TEST
)
3400 CLEAR_CALLED(QueryService_HttpSecurity
);
3403 if(bindf
& BINDF_FROMURLMON
)
3406 SET_EXPECT(ReportData
);
3407 hres
= IInternetProtocol_Read(async_protocol
, buf
, sizeof(buf
), &cb
);
3408 if(hres
== E_PENDING
) {
3409 hres
= IInternetProtocol_Read(async_protocol
, buf
, 1, &cb
);
3410 ok((hres
== E_PENDING
&& cb
==0) ||
3411 (hres
== S_OK
&& cb
==1), "Read failed: %08x (%d bytes)\n", hres
, cb
);
3412 ok( WaitForSingleObject(event_complete
, 90000) == WAIT_OBJECT_0
, "wait timed out\n" );
3413 if(bindf
& BINDF_FROMURLMON
)
3414 CHECK_CALLED(Switch
);
3416 CHECK_CALLED(ReportData
);
3421 SET_EXPECT(ReportResult
);
3422 hres
= IInternetProtocol_Abort(async_protocol
, E_ABORT
, 0);
3423 ok(hres
== S_OK
, "Abort failed: %08x\n", hres
);
3424 CHECK_CALLED(ReportResult
);
3426 hres
= IInternetProtocol_Abort(async_protocol
, E_ABORT
, 0);
3427 ok(hres
== INET_E_RESULT_DISPATCHED
|| hres
== S_OK
/* IE10 */, "Abort failed: %08x\n", hres
);
3431 if(bindf
& BINDF_FROMURLMON
)
3432 CHECK_NOT_CALLED(Switch
);
3434 CHECK_NOT_CALLED(ReportData
);
3439 ok(hres
== S_FALSE
, "Read failed: %08x\n", hres
);
3440 CHECK_CALLED(ReportResult
);
3443 if(prot
== HTTPS_TEST
)
3444 CLEAR_CALLED(ReportProgress_SENDINGREQUEST
);
3446 if (prot
== HTTP_TEST
|| prot
== HTTPS_TEST
)
3447 CLEAR_CALLED(ReportProgress_COOKIE_SENT
);
3449 hres
= IInternetProtocol_Abort(async_protocol
, E_ABORT
, 0);
3450 ok(hres
== INET_E_RESULT_DISPATCHED
|| hres
== S_OK
/* IE10 */, "Abort failed: %08x\n", hres
);
3452 test_protocol_terminate(async_protocol
);
3454 hres
= IInternetProtocol_Abort(async_protocol
, E_ABORT
, 0);
3455 ok(hres
== S_OK
, "Abort failed: %08x\n", hres
);
3457 ref
= IInternetProtocol_Release(async_protocol
);
3458 ok(!ref
, "ref=%x\n", ref
);
3461 IClassFactory_Release(factory
);
3463 if(flags
& TEST_FROMCACHE
) {
3466 res
= DeleteUrlCacheEntryW(url
);
3467 ok(res
, "DeleteUrlCacheEntryA failed: %u\n", GetLastError());
3471 static void test_http_protocol(void)
3473 static const WCHAR posttest_url
[] =
3474 {'h','t','t','p',':','/','/','t','e','s','t','.','w','i','n','e','h','q','.','o','r','g','/',
3475 't','e','s','t','s','/','p','o','s','t','.','p','h','p',0};
3476 static const WCHAR redirect_url
[] =
3477 {'h','t','t','p',':','/','/','t','e','s','t','.','w','i','n','e','h','q','.','o','r','g','/',
3478 't','e','s','t','s','/','r','e','d','i','r','e','c','t',0};
3479 static const WCHAR winetest_url
[] =
3480 {'h','t','t','p',':','/','/','t','e','s','t','.','w','i','n','e','h','q','.','o','r','g','/',
3481 't','e','s','t','s','/','d','a','t','a','.','p','h','p',0};
3482 static const WCHAR empty_url
[] =
3483 {'h','t','t','p',':','/','/','t','e','s','t','.','w','i','n','e','h','q','.','o','r','g','/',
3484 't','e','s','t','s','/','e','m','p','t','y','.','j','s',0};
3485 static const WCHAR cache_only_url
[] =
3486 {'h','t','t','p',':','/','/','t','e','s','t','.','w','i','n','e','h','q','.','o','r','g','/',
3487 't','e','s','t','s','/','c','a','c','h','e','-','o','n','l','y',0};
3490 trace("Testing http protocol (not from urlmon)...\n");
3491 bindf
= BINDF_ASYNCHRONOUS
| BINDF_ASYNCSTORAGE
| BINDF_PULLDATA
;
3492 test_http_protocol_url(winetest_url
, HTTP_TEST
, TEST_FIRST_HTTP
, TYMED_NULL
);
3494 trace("Testing http protocol (from urlmon)...\n");
3495 bindf
= BINDF_ASYNCHRONOUS
| BINDF_ASYNCSTORAGE
| BINDF_PULLDATA
| BINDF_FROMURLMON
;
3496 test_http_protocol_url(winetest_url
, HTTP_TEST
, 0, TYMED_NULL
);
3498 trace("Testing http protocol (to file)...\n");
3499 bindf
= BINDF_ASYNCHRONOUS
| BINDF_ASYNCSTORAGE
| BINDF_PULLDATA
| BINDF_FROMURLMON
| BINDF_NEEDFILE
;
3500 test_http_protocol_url(winetest_url
, HTTP_TEST
, 0, TYMED_NULL
);
3502 trace("Testing http protocol (post data)...\n");
3503 bindf
= BINDF_ASYNCHRONOUS
| BINDF_ASYNCSTORAGE
| BINDF_PULLDATA
| BINDF_FROMURLMON
;
3504 test_http_protocol_url(posttest_url
, HTTP_TEST
, TEST_FIRST_HTTP
|TEST_POST
, TYMED_HGLOBAL
);
3506 trace("Testing http protocol (post data stream)...\n");
3507 test_http_protocol_url(posttest_url
, HTTP_TEST
, TEST_FIRST_HTTP
|TEST_POST
|TEST_ASYNCREQ
, TYMED_ISTREAM
);
3509 trace("Testing http protocol (direct read)...\n");
3510 bindf
= BINDF_ASYNCHRONOUS
| BINDF_ASYNCSTORAGE
| BINDF_PULLDATA
| BINDF_FROMURLMON
;
3511 test_http_protocol_url(winetest_url
, HTTP_TEST
, TEST_DIRECT_READ
|TEST_USEIURI
, TYMED_NULL
);
3513 trace("Testing http protocol (redirected)...\n");
3514 bindf
= BINDF_ASYNCHRONOUS
| BINDF_ASYNCSTORAGE
| BINDF_PULLDATA
| BINDF_FROMURLMON
| BINDF_NOWRITECACHE
;
3515 test_http_protocol_url(redirect_url
, HTTP_TEST
, TEST_REDIRECT
, TYMED_NULL
);
3517 trace("Testing http protocol (redirected, disable auto redirect)...\n");
3518 bindf
= BINDF_ASYNCHRONOUS
| BINDF_ASYNCSTORAGE
| BINDF_PULLDATA
| BINDF_FROMURLMON
| BINDF_NOWRITECACHE
;
3519 test_http_protocol_url(redirect_url
, HTTP_TEST
, TEST_REDIRECT
| TEST_DISABLEAUTOREDIRECT
, TYMED_NULL
);
3521 trace("Testing http protocol empty file...\n");
3522 bindf
= BINDF_ASYNCHRONOUS
| BINDF_ASYNCSTORAGE
| BINDF_PULLDATA
| BINDF_FROMURLMON
| BINDF_NOWRITECACHE
;
3523 test_http_protocol_url(empty_url
, HTTP_TEST
, TEST_EMPTY
, TYMED_NULL
);
3525 /* This is a bit ugly. We unconditionally disable this test on Wine. This won't work until we have
3526 * support for reading from cache via HTTP layer in wininet. Until then, Wine will fail badly, affecting
3527 * other, unrelated, tests. Working around it is not worth the trouble, we may simply make sure those
3528 * tests work on Windows and have them around for the future.
3531 trace("Testing http protocol (from cache)...\n");
3532 bindf
= BINDF_ASYNCHRONOUS
| BINDF_ASYNCSTORAGE
| BINDF_PULLDATA
| BINDF_FROMURLMON
;
3533 test_http_protocol_url(cache_only_url
, HTTP_TEST
, TEST_FROMCACHE
, TYMED_NULL
);
3536 trace("Testing http protocol abort...\n");
3537 bindf
= BINDF_ASYNCHRONOUS
| BINDF_ASYNCSTORAGE
| BINDF_PULLDATA
| BINDF_FROMURLMON
| BINDF_NOWRITECACHE
;
3538 test_http_protocol_url(winetest_url
, HTTP_TEST
, TEST_ABORT
, TYMED_NULL
);
3540 test_early_abort(&CLSID_HttpProtocol
);
3541 test_early_abort(&CLSID_HttpSProtocol
);
3544 static void test_https_protocol(void)
3546 static const WCHAR https_winehq_url
[] =
3547 {'h','t','t','p','s',':','/','/','t','e','s','t','.','w','i','n','e','h','q','.','o','r','g','/',
3548 't','e','s','t','s','/','h','e','l','l','o','.','h','t','m','l',0};
3550 trace("Testing https protocol (from urlmon)...\n");
3551 bindf
= BINDF_ASYNCHRONOUS
| BINDF_ASYNCSTORAGE
| BINDF_PULLDATA
| BINDF_FROMURLMON
| BINDF_NOWRITECACHE
;
3552 test_http_protocol_url(https_winehq_url
, HTTPS_TEST
, TEST_FIRST_HTTP
, TYMED_NULL
);
3556 static void test_ftp_protocol(void)
3558 IInternetProtocolInfo
*protocol_info
;
3559 IClassFactory
*factory
;
3566 static const WCHAR ftp_urlW
[] = {'f','t','p',':','/','/','f','t','p','.','w','i','n','e','h','q','.','o','r','g',
3567 '/','p','u','b','/','o','t','h','e','r','/',
3568 'w','i','n','e','l','o','g','o','.','x','c','f','.','t','a','r','.','b','z','2',0};
3570 trace("Testing ftp protocol...\n");
3572 init_test(FTP_TEST
, 0);
3574 bindf
= BINDF_ASYNCHRONOUS
| BINDF_ASYNCSTORAGE
| BINDF_PULLDATA
| BINDF_FROMURLMON
| BINDF_NOWRITECACHE
;
3575 state
= STATE_STARTDOWNLOADING
;
3576 expect_hrResult
= E_PENDING
;
3578 hres
= CoGetClassObject(&CLSID_FtpProtocol
, CLSCTX_INPROC_SERVER
, NULL
, &IID_IUnknown
, (void**)&unk
);
3579 ok(hres
== S_OK
, "CoGetClassObject failed: %08x\n", hres
);
3583 hres
= IUnknown_QueryInterface(unk
, &IID_IInternetProtocolInfo
, (void**)&protocol_info
);
3584 ok(hres
== E_NOINTERFACE
, "Could not get IInternetProtocolInfo interface: %08x, expected E_NOINTERFACE\n", hres
);
3586 hres
= IUnknown_QueryInterface(unk
, &IID_IClassFactory
, (void**)&factory
);
3587 ok(hres
== S_OK
, "Could not get IClassFactory interface\n");
3588 IUnknown_Release(unk
);
3592 hres
= IClassFactory_CreateInstance(factory
, NULL
, &IID_IInternetProtocol
,
3593 (void**)&async_protocol
);
3594 IClassFactory_Release(factory
);
3595 ok(hres
== S_OK
, "Could not get IInternetProtocol: %08x\n", hres
);
3597 test_priority(async_protocol
);
3599 SET_EXPECT(GetBindInfo
);
3600 SET_EXPECT(ReportProgress_FINDINGRESOURCE
);
3601 SET_EXPECT(ReportProgress_CONNECTING
);
3602 SET_EXPECT(ReportProgress_SENDINGREQUEST
);
3605 hres
= IInternetProtocol_Start(async_protocol
, ftp_urlW
, &protocol_sink
, &bind_info
, 0, 0);
3606 ok(hres
== S_OK
, "Start failed: %08x\n", hres
);
3607 CHECK_CALLED(GetBindInfo
);
3609 SET_EXPECT(ReportResult
);
3611 hres
= IInternetProtocol_Read(async_protocol
, buf
, 1, &cb
);
3612 ok((hres
== E_PENDING
&& cb
==0) ||
3613 (hres
== S_OK
&& cb
==1), "Read failed: %08x (%d bytes)\n", hres
, cb
);
3615 ok( WaitForSingleObject(event_complete
, 90000) == WAIT_OBJECT_0
, "wait timed out\n" );
3618 hres
= IInternetProtocol_Read(async_protocol
, buf
, sizeof(buf
), &cb
);
3619 if(hres
== E_PENDING
)
3621 DWORD ret
= WaitForSingleObject(event_complete
, 90000);
3622 ok( ret
== WAIT_OBJECT_0
, "wait timed out\n" );
3623 if (ret
!= WAIT_OBJECT_0
) break;
3629 ok(hres
== S_FALSE
, "Read failed: %08x\n", hres
);
3630 CHECK_CALLED(ReportResult
);
3631 CHECK_CALLED(Switch
);
3633 test_protocol_terminate(async_protocol
);
3636 IInternetProtocolEx
*protocolex
;
3638 hres
= IInternetProtocol_QueryInterface(async_protocol
, &IID_IInternetProtocolEx
, (void**)&protocolex
);
3639 ok(hres
== S_OK
, "Could not get IInternetProtocolEx iface: %08x\n", hres
);
3640 IInternetProtocolEx_Release(protocolex
);
3643 ref
= IInternetProtocol_Release(async_protocol
);
3644 ok(!ref
, "ref=%d\n", ref
);
3646 test_early_abort(&CLSID_FtpProtocol
);
3649 static void test_gopher_protocol(void)
3651 IInternetProtocolInfo
*protocol_info
;
3652 IClassFactory
*factory
;
3656 trace("Testing gopher protocol...\n");
3658 hres
= CoGetClassObject(&CLSID_GopherProtocol
, CLSCTX_INPROC_SERVER
, NULL
, &IID_IUnknown
, (void**)&unk
);
3660 broken(hres
== REGDB_E_CLASSNOTREG
|| hres
== CLASS_E_CLASSNOTAVAILABLE
), /* Gopher protocol has been removed as of Vista */
3661 "CoGetClassObject failed: %08x\n", hres
);
3665 hres
= IUnknown_QueryInterface(unk
, &IID_IInternetProtocolInfo
, (void**)&protocol_info
);
3666 ok(hres
== E_NOINTERFACE
, "Could not get IInternetProtocolInfo interface: %08x, expected E_NOINTERFACE\n", hres
);
3668 hres
= IUnknown_QueryInterface(unk
, &IID_IClassFactory
, (void**)&factory
);
3669 ok(hres
== S_OK
, "Could not get IClassFactory interface\n");
3670 IUnknown_Release(unk
);
3674 hres
= IClassFactory_CreateInstance(factory
, NULL
, &IID_IInternetProtocol
,
3675 (void**)&async_protocol
);
3676 IClassFactory_Release(factory
);
3677 ok(hres
== S_OK
, "Could not get IInternetProtocol: %08x\n", hres
);
3679 test_priority(async_protocol
);
3681 IInternetProtocol_Release(async_protocol
);
3683 test_early_abort(&CLSID_GopherProtocol
);
3686 static void test_mk_protocol(void)
3688 IInternetProtocolInfo
*protocol_info
;
3689 IInternetProtocol
*protocol
;
3690 IClassFactory
*factory
;
3694 static const WCHAR wrong_url1
[] = {'t','e','s','t',':','@','M','S','I','T','S','t','o','r','e',
3695 ':',':','/','t','e','s','t','.','h','t','m','l',0};
3696 static const WCHAR wrong_url2
[] = {'m','k',':','/','t','e','s','t','.','h','t','m','l',0};
3698 trace("Testing mk protocol...\n");
3699 init_test(MK_TEST
, 0);
3701 hres
= CoGetClassObject(&CLSID_MkProtocol
, CLSCTX_INPROC_SERVER
, NULL
,
3702 &IID_IUnknown
, (void**)&unk
);
3703 ok(hres
== S_OK
, "CoGetClassObject failed: %08x\n", hres
);
3705 hres
= IUnknown_QueryInterface(unk
, &IID_IInternetProtocolInfo
, (void**)&protocol_info
);
3706 ok(hres
== E_NOINTERFACE
,
3707 "Could not get IInternetProtocolInfo interface: %08x, expected E_NOINTERFACE\n",
3710 hres
= IUnknown_QueryInterface(unk
, &IID_IClassFactory
, (void**)&factory
);
3711 ok(hres
== S_OK
, "Could not get IClassFactory interface\n");
3712 IUnknown_Release(unk
);
3716 hres
= IClassFactory_CreateInstance(factory
, NULL
, &IID_IInternetProtocol
,
3718 IClassFactory_Release(factory
);
3719 ok(hres
== S_OK
, "Could not get IInternetProtocol: %08x\n", hres
);
3721 SET_EXPECT(GetBindInfo
);
3722 hres
= IInternetProtocol_Start(protocol
, wrong_url1
, &protocol_sink
, &bind_info
, 0, 0);
3723 ok(hres
== MK_E_SYNTAX
|| hres
== INET_E_INVALID_URL
,
3724 "Start failed: %08x, expected MK_E_SYNTAX or INET_E_INVALID_URL\n", hres
);
3725 CLEAR_CALLED(GetBindInfo
);
3727 SET_EXPECT(GetBindInfo
);
3728 SET_EXPECT(ReportProgress_DIRECTBIND
);
3729 SET_EXPECT(ReportProgress_SENDINGREQUEST
);
3730 SET_EXPECT(ReportProgress_MIMETYPEAVAILABLE
);
3731 SET_EXPECT(ReportResult
);
3732 expect_hrResult
= INET_E_RESOURCE_NOT_FOUND
;
3734 hres
= IInternetProtocol_Start(protocol
, wrong_url2
, &protocol_sink
, &bind_info
, 0, 0);
3735 ok(hres
== INET_E_RESOURCE_NOT_FOUND
||
3736 hres
== INET_E_INVALID_URL
, /* win2k3 */
3737 "Start failed: %08x, expected INET_E_RESOURCE_NOT_FOUND or INET_E_INVALID_URL\n", hres
);
3739 if (hres
== INET_E_RESOURCE_NOT_FOUND
) {
3740 CHECK_CALLED(GetBindInfo
);
3741 CLEAR_CALLED(ReportProgress_DIRECTBIND
);
3742 CHECK_CALLED(ReportProgress_SENDINGREQUEST
);
3743 CHECK_CALLED(ReportProgress_MIMETYPEAVAILABLE
);
3744 CHECK_CALLED(ReportResult
);
3746 CLEAR_CALLED(GetBindInfo
);
3747 CLEAR_CALLED(ReportProgress_DIRECTBIND
);
3748 CLEAR_CALLED(ReportProgress_SENDINGREQUEST
);
3749 CLEAR_CALLED(ReportProgress_MIMETYPEAVAILABLE
);
3750 CLEAR_CALLED(ReportResult
);
3753 IInternetProtocol_Release(protocol
);
3756 static void test_CreateBinding(void)
3758 IInternetProtocol
*protocol
;
3759 IInternetPriority
*priority
;
3760 IInternetSession
*session
;
3761 IWinInetHttpInfo
*http_info
;
3762 IWinInetInfo
*inet_info
;
3768 static const WCHAR test_url
[] =
3769 {'t','e','s','t',':','/','/','f','i','l','e','.','h','t','m','l',0};
3770 static const WCHAR wsz_test
[] = {'t','e','s','t',0};
3772 trace("Testing CreateBinding...\n");
3773 init_test(BIND_TEST
, TEST_BINDING
);
3775 hres
= pCoInternetGetSession(0, &session
, 0);
3776 ok(hres
== S_OK
, "CoInternetGetSession failed: %08x\n", hres
);
3778 hres
= IInternetSession_RegisterNameSpace(session
, &ClassFactory
, &IID_NULL
, wsz_test
, 0, NULL
, 0);
3779 ok(hres
== S_OK
, "RegisterNameSpace failed: %08x\n", hres
);
3781 hres
= IInternetSession_CreateBinding(session
, NULL
, test_url
, NULL
, NULL
, &protocol
, 0);
3782 binding_protocol
= protocol
;
3783 ok(hres
== S_OK
, "CreateBinding failed: %08x\n", hres
);
3784 ok(protocol
!= NULL
, "protocol == NULL\n");
3786 hres
= IInternetProtocol_QueryInterface(protocol
, &IID_IInternetBindInfo
, (void**)&prot_bind_info
);
3787 ok(hres
== S_OK
, "QueryInterface(IID_IInternetBindInfo) failed: %08x\n", hres
);
3789 hres
= IInternetProtocol_QueryInterface(protocol
, &IID_IInternetProtocolSink
, (void**)&binding_sink
);
3790 ok(hres
== S_OK
, "Could not get IInternetProtocolSink: %08x\n", hres
);
3792 hres
= IInternetProtocol_Start(protocol
, test_url
, NULL
, &bind_info
, 0, 0);
3793 ok(hres
== E_INVALIDARG
, "Start failed: %08x, expected E_INVALIDARG\n", hres
);
3794 hres
= IInternetProtocol_Start(protocol
, test_url
, &protocol_sink
, NULL
, 0, 0);
3795 ok(hres
== E_INVALIDARG
, "Start failed: %08x, expected E_INVALIDARG\n", hres
);
3796 hres
= IInternetProtocol_Start(protocol
, NULL
, &protocol_sink
, &bind_info
, 0, 0);
3797 ok(hres
== E_INVALIDARG
, "Start failed: %08x, expected E_INVALIDARG\n", hres
);
3799 hres
= IInternetProtocol_QueryInterface(protocol
, &IID_IInternetPriority
, (void**)&priority
);
3800 ok(hres
== S_OK
, "QueryInterface(IID_IInternetPriority) failed: %08x\n", hres
);
3803 hres
= IInternetPriority_GetPriority(priority
, &p
);
3804 ok(hres
== S_OK
, "GetPriority failed: %08x\n", hres
);
3805 ok(!p
, "p=%d\n", p
);
3808 hres
= IInternetPriority_SetPriority(priority
, 100);
3809 ok(hres
== S_OK
, "SetPriority failed: %08x\n", hres
);
3812 hres
= IInternetPriority_GetPriority(priority
, &p
);
3813 ok(hres
== S_OK
, "GetPriority failed: %08x\n", hres
);
3814 ok(p
== 100, "p=%d\n", p
);
3816 hres
= IInternetProtocol_QueryInterface(protocol
, &IID_IWinInetInfo
, (void**)&inet_info
);
3817 ok(hres
== E_NOINTERFACE
, "Could not get IWinInetInfo protocol: %08x\n", hres
);
3819 SET_EXPECT(QueryService_InternetProtocol
);
3820 SET_EXPECT(CreateInstance
);
3821 SET_EXPECT(ReportProgress_PROTOCOLCLASSID
);
3822 SET_EXPECT(SetPriority
);
3826 expect_hrResult
= S_OK
;
3827 hres
= IInternetProtocol_Start(protocol
, test_url
, &protocol_sink
, &bind_info
, 0, 0);
3828 ok(hres
== S_OK
, "Start failed: %08x\n", hres
);
3831 CHECK_CALLED(QueryService_InternetProtocol
);
3832 CHECK_CALLED(CreateInstance
);
3833 CHECK_CALLED(ReportProgress_PROTOCOLCLASSID
);
3834 CHECK_CALLED(SetPriority
);
3835 CHECK_CALLED(Start
);
3837 SET_EXPECT(QueryInterface_IWinInetInfo
);
3838 hres
= IInternetProtocol_QueryInterface(protocol
, &IID_IWinInetInfo
, (void**)&inet_info
);
3839 ok(hres
== E_NOINTERFACE
, "Could not get IWinInetInfo protocol: %08x\n", hres
);
3840 CHECK_CALLED(QueryInterface_IWinInetInfo
);
3842 SET_EXPECT(QueryInterface_IWinInetInfo
);
3843 hres
= IInternetProtocol_QueryInterface(protocol
, &IID_IWinInetInfo
, (void**)&inet_info
);
3844 ok(hres
== E_NOINTERFACE
, "Could not get IWinInetInfo protocol: %08x\n", hres
);
3845 CHECK_CALLED(QueryInterface_IWinInetInfo
);
3847 SET_EXPECT(QueryInterface_IWinInetHttpInfo
);
3848 hres
= IInternetProtocol_QueryInterface(protocol
, &IID_IWinInetHttpInfo
, (void**)&http_info
);
3849 ok(hres
== E_NOINTERFACE
, "Could not get IWinInetInfo protocol: %08x\n", hres
);
3850 CHECK_CALLED(QueryInterface_IWinInetHttpInfo
);
3854 hres
= IInternetProtocol_Read(protocol
, expect_pv
= buf
, sizeof(buf
), &read
);
3855 ok(hres
== S_OK
, "Read failed: %08x\n", hres
);
3856 ok(read
== 100, "read = %d\n", read
);
3861 hres
= IInternetProtocol_Read(protocol
, expect_pv
= buf
, sizeof(buf
), &read
);
3862 ok(hres
== S_FALSE
, "Read failed: %08x\n", hres
);
3863 ok(!read
, "read = %d\n", read
);
3867 hres
= IInternetPriority_GetPriority(priority
, &p
);
3868 ok(hres
== S_OK
, "GetPriority failed: %08x\n", hres
);
3869 ok(p
== 100, "p=%d\n", p
);
3871 hres
= IInternetPriority_SetPriority(priority
, 101);
3872 ok(hres
== S_OK
, "SetPriority failed: %08x\n", hres
);
3874 SET_EXPECT(Terminate
);
3875 hres
= IInternetProtocol_Terminate(protocol
, 0xdeadbeef);
3876 ok(hres
== S_OK
, "Terminate failed: %08x\n", hres
);
3877 CHECK_CALLED(Terminate
);
3879 ok(protocol_emul
->outer_ref
== 0, "protocol_outer_ref = %u\n", protocol_emul
->outer_ref
);
3881 SET_EXPECT(Continue
);
3882 hres
= IInternetProtocolSink_Switch(binding_sink
, &protocoldata
);
3883 ok(hres
== S_OK
, "Switch failed: %08x\n", hres
);
3884 CHECK_CALLED(Continue
);
3888 hres
= IInternetProtocol_Read(protocol
, expect_pv
= buf
, sizeof(buf
), &read
);
3890 ok(hres
== E_ABORT
, "Read failed: %08x\n", hres
);
3892 ok(read
== 0, "read = %d\n", read
);
3894 CHECK_NOT_CALLED(Read
);
3896 hres
= IInternetProtocolSink_ReportProgress(binding_sink
,
3897 BINDSTATUS_CACHEFILENAMEAVAILABLE
, expect_wsz
= emptyW
);
3898 ok(hres
== S_OK
, "ReportProgress(BINDSTATUS_CACHEFILENAMEAVAILABLE) failed: %08x\n", hres
);
3900 hres
= IInternetProtocolSink_ReportResult(binding_sink
, S_OK
, ERROR_SUCCESS
, NULL
);
3901 ok(hres
== E_FAIL
, "ReportResult failed: %08x, expected E_FAIL\n", hres
);
3903 hres
= IInternetProtocolSink_ReportData(binding_sink
, 0, 0, 0);
3904 ok(hres
== S_OK
, "ReportData failed: %08x\n", hres
);
3906 IInternetProtocolSink_Release(binding_sink
);
3907 IInternetPriority_Release(priority
);
3908 IInternetBindInfo_Release(prot_bind_info
);
3910 SET_EXPECT(Protocol_destructor
);
3911 IInternetProtocol_Release(protocol
);
3912 CHECK_CALLED(Protocol_destructor
);
3914 hres
= IInternetSession_CreateBinding(session
, NULL
, test_url
, NULL
, NULL
, &protocol
, 0);
3915 ok(hres
== S_OK
, "CreateBinding failed: %08x\n", hres
);
3916 ok(protocol
!= NULL
, "protocol == NULL\n");
3918 hres
= IInternetProtocol_Abort(protocol
, E_ABORT
, 0);
3919 ok(hres
== S_OK
, "Abort failed: %08x\n", hres
);
3921 hres
= IInternetProtocol_Abort(protocol
, E_FAIL
, 0);
3922 ok(hres
== S_OK
, "Abort failed: %08x\n", hres
);
3924 IInternetProtocol_Release(protocol
);
3926 hres
= IInternetSession_UnregisterNameSpace(session
, &ClassFactory
, wsz_test
);
3927 ok(hres
== S_OK
, "UnregisterNameSpace failed: %08x\n", hres
);
3929 hres
= IInternetSession_CreateBinding(session
, NULL
, test_url
, NULL
, NULL
, &protocol
, 0);
3930 ok(hres
== S_OK
, "CreateBinding failed: %08x\n", hres
);
3931 ok(protocol
!= NULL
, "protocol == NULL\n");
3933 SET_EXPECT(QueryService_InternetProtocol
);
3934 hres
= IInternetProtocol_Start(protocol
, test_url
, &protocol_sink
, &bind_info
, 0, 0);
3935 ok(hres
== MK_E_SYNTAX
, "Start failed: %08x, expected MK_E_SYNTAX\n", hres
);
3936 CHECK_CALLED(QueryService_InternetProtocol
);
3938 IInternetProtocol_Release(protocol
);
3940 IInternetSession_Release(session
);
3943 static void test_binding(int prot
, DWORD grf_pi
, DWORD test_flags
)
3945 IInternetProtocolEx
*protocolex
= NULL
;
3946 IInternetProtocol
*protocol
;
3947 IInternetSession
*session
;
3954 init_test(prot
, test_flags
|TEST_BINDING
);
3956 hres
= pCoInternetGetSession(0, &session
, 0);
3957 ok(hres
== S_OK
, "CoInternetGetSession failed: %08x\n", hres
);
3959 if(test_flags
& TEST_EMULATEPROT
) {
3960 hres
= IInternetSession_RegisterNameSpace(session
, &ClassFactory
, &IID_NULL
, protocol_names
[prot
], 0, NULL
, 0);
3961 ok(hres
== S_OK
, "RegisterNameSpace failed: %08x\n", hres
);
3964 hres
= IInternetSession_CreateBinding(session
, NULL
, binding_urls
[prot
], NULL
, NULL
, &protocol
, 0);
3965 binding_protocol
= protocol
;
3966 ok(hres
== S_OK
, "CreateBinding failed: %08x\n", hres
);
3967 ok(protocol
!= NULL
, "protocol == NULL\n");
3969 hres
= IInternetProtocol_QueryInterface(protocol
, &IID_IInternetBindInfo
, (void**)&prot_bind_info
);
3970 ok(hres
== S_OK
, "QueryInterface(IID_IInternetBindInfo) failed: %08x\n", hres
);
3972 hres
= IInternetProtocol_QueryInterface(protocol
, &IID_IInternetProtocolSink
, (void**)&binding_sink
);
3973 ok(hres
== S_OK
, "QueryInterface(IID_IInternetProtocolSink) failed: %08x\n", hres
);
3975 if(test_flags
& TEST_USEIURI
) {
3976 hres
= IInternetProtocol_QueryInterface(protocol
, &IID_IInternetProtocolEx
, (void**)&protocolex
);
3977 ok(hres
== S_OK
, "Could not get IInternetProtocolEx iface: %08x\n", hres
);
3979 hres
= pCreateUri(binding_urls
[prot
], Uri_CREATE_FILE_USE_DOS_PATH
, 0, &uri
);
3980 ok(hres
== S_OK
, "CreateUri failed: %08x\n", hres
);
3984 SET_EXPECT(QueryService_InternetProtocol
);
3985 SET_EXPECT(CreateInstance
);
3986 SET_EXPECT(ReportProgress_PROTOCOLCLASSID
);
3987 SET_EXPECT(SetPriority
);
3989 SET_EXPECT(StartEx
);
3993 expect_hrResult
= S_OK
;
3996 hres
= IInternetProtocolEx_StartEx(protocolex
, uri
, &protocol_sink
, &bind_info
, pi
, 0);
3997 ok(hres
== S_OK
, "StartEx failed: %08x\n", hres
);
3999 hres
= IInternetProtocol_Start(protocol
, binding_urls
[prot
], &protocol_sink
, &bind_info
, pi
, 0);
4000 ok(hres
== S_OK
, "Start failed: %08x\n", hres
);
4003 CHECK_CALLED(QueryService_InternetProtocol
);
4004 CHECK_CALLED(CreateInstance
);
4005 CHECK_CALLED(ReportProgress_PROTOCOLCLASSID
);
4006 CLEAR_CALLED(SetPriority
); /* IE11 does not call it. */
4008 CHECK_CALLED(StartEx
);
4010 CHECK_CALLED(Start
);
4013 IInternetProtocolEx_Release(protocolex
);
4017 if(prot
== HTTP_TEST
|| prot
== HTTPS_TEST
) {
4018 while(prot_state
< 4) {
4019 ok( WaitForSingleObject(event_complete
, 90000) == WAIT_OBJECT_0
, "wait timed out\n" );
4020 if(mimefilter_test
&& filtered_protocol
) {
4021 SET_EXPECT(Continue
);
4022 IInternetProtocol_Continue(filtered_protocol
, pdata
);
4023 CHECK_CALLED(Continue
);
4025 SET_EXPECT(Continue
);
4026 IInternetProtocol_Continue(protocol
, pdata
);
4027 CHECK_CALLED(Continue
);
4029 if(test_abort
&& prot_state
== 2) {
4031 hres
= IInternetProtocol_Abort(protocol
, E_ABORT
, 0);
4032 ok(hres
== S_OK
, "Abort failed: %08x\n", hres
);
4033 CHECK_CALLED(Abort
);
4035 hres
= IInternetProtocol_Abort(protocol
, E_ABORT
, 0);
4036 ok(hres
== S_OK
, "Abort failed: %08x\n", hres
);
4037 SetEvent(event_complete2
);
4040 SetEvent(event_complete2
);
4043 CHECK_CALLED(ReportData
); /* Set in ReportResult */
4044 ok( WaitForSingleObject(event_complete
, 90000) == WAIT_OBJECT_0
, "wait timed out\n" );
4047 SET_EXPECT(MimeFilter_LockRequest
);
4049 SET_EXPECT(LockRequest
);
4050 hres
= IInternetProtocol_LockRequest(protocol
, 0);
4051 ok(hres
== S_OK
, "LockRequest failed: %08x\n", hres
);
4053 CHECK_CALLED(MimeFilter_LockRequest
);
4055 CHECK_CALLED(LockRequest
);
4058 SET_EXPECT(MimeFilter_UnlockRequest
);
4060 SET_EXPECT(UnlockRequest
);
4061 hres
= IInternetProtocol_UnlockRequest(protocol
);
4062 ok(hres
== S_OK
, "UnlockRequest failed: %08x\n", hres
);
4064 CHECK_CALLED(MimeFilter_UnlockRequest
);
4066 CHECK_CALLED(UnlockRequest
);
4070 SET_EXPECT(MimeFilter_Terminate
);
4072 SET_EXPECT(Terminate
);
4073 hres
= IInternetProtocol_Terminate(protocol
, 0);
4074 ok(hres
== S_OK
, "Terminate failed: %08x\n", hres
);
4076 CLEAR_CALLED(MimeFilter_Terminate
);
4078 CHECK_CALLED(Terminate
);
4080 if(filtered_protocol
)
4081 IInternetProtocol_Release(filtered_protocol
);
4082 IInternetBindInfo_Release(prot_bind_info
);
4083 IInternetProtocolSink_Release(binding_sink
);
4085 SET_EXPECT(Protocol_destructor
);
4086 ref
= IInternetProtocol_Release(protocol
);
4087 ok(!ref
, "ref=%u, expected 0\n", ref
);
4088 CHECK_CALLED(Protocol_destructor
);
4090 if(test_flags
& TEST_EMULATEPROT
) {
4091 hres
= IInternetSession_UnregisterNameSpace(session
, &ClassFactory
, protocol_names
[prot
]);
4092 ok(hres
== S_OK
, "UnregisterNameSpace failed: %08x\n", hres
);
4095 IInternetSession_Release(session
);
4098 static const IID outer_test_iid
= {0xabcabc00,0,0,{0,0,0,0,0,0,0,0x66}};
4100 static HRESULT WINAPI
outer_QueryInterface(IUnknown
*iface
, REFIID riid
, void **ppv
)
4102 if(IsEqualGUID(riid
, &outer_test_iid
)) {
4103 CHECK_EXPECT(outer_QI_test
);
4104 *ppv
= (IUnknown
*)0xdeadbeef;
4107 ok(0, "unexpected call %s\n", wine_dbgstr_guid(riid
));
4108 return E_NOINTERFACE
;
4111 static ULONG WINAPI
outer_AddRef(IUnknown
*iface
)
4116 static ULONG WINAPI
outer_Release(IUnknown
*iface
)
4121 static const IUnknownVtbl outer_vtbl
= {
4122 outer_QueryInterface
,
4127 static void test_com_aggregation(const CLSID
*clsid
)
4129 IUnknown outer
= { &outer_vtbl
};
4130 IClassFactory
*class_factory
;
4131 IUnknown
*unk
, *unk2
, *unk3
;
4134 hres
= CoGetClassObject(clsid
, CLSCTX_INPROC_SERVER
, NULL
, &IID_IClassFactory
, (void**)&class_factory
);
4135 ok(hres
== S_OK
, "CoGetClassObject failed: %08x\n", hres
);
4137 hres
= IClassFactory_CreateInstance(class_factory
, &outer
, &IID_IUnknown
, (void**)&unk
);
4138 ok(hres
== S_OK
, "CreateInstance returned: %08x\n", hres
);
4140 hres
= IUnknown_QueryInterface(unk
, &IID_IInternetProtocol
, (void**)&unk2
);
4141 ok(hres
== S_OK
, "Could not get IDispatch iface: %08x\n", hres
);
4143 SET_EXPECT(outer_QI_test
);
4144 hres
= IUnknown_QueryInterface(unk2
, &outer_test_iid
, (void**)&unk3
);
4145 CHECK_CALLED(outer_QI_test
);
4146 ok(hres
== S_OK
, "Could not get IInternetProtocol iface: %08x\n", hres
);
4147 ok(unk3
== (IUnknown
*)0xdeadbeef, "unexpected unk2\n");
4149 IUnknown_Release(unk2
);
4150 IUnknown_Release(unk
);
4152 unk
= (void*)0xdeadbeef;
4153 hres
= IClassFactory_CreateInstance(class_factory
, &outer
, &IID_IInternetProtocol
, (void**)&unk
);
4154 ok(hres
== CLASS_E_NOAGGREGATION
, "CreateInstance returned: %08x\n", hres
);
4155 ok(!unk
, "unk = %p\n", unk
);
4157 IClassFactory_Release(class_factory
);
4160 START_TEST(protocol
)
4164 hurlmon
= GetModuleHandleA("urlmon.dll");
4165 pCoInternetGetSession
= (void*) GetProcAddress(hurlmon
, "CoInternetGetSession");
4166 pReleaseBindInfo
= (void*) GetProcAddress(hurlmon
, "ReleaseBindInfo");
4167 pCreateUri
= (void*) GetProcAddress(hurlmon
, "CreateUri");
4169 if(!GetProcAddress(hurlmon
, "CompareSecurityIds")) {
4170 win_skip("Various needed functions not present, too old IE\n");
4175 win_skip("CreateUri not supported\n");
4177 OleInitialize(NULL
);
4179 event_complete
= CreateEventW(NULL
, FALSE
, FALSE
, NULL
);
4180 event_complete2
= CreateEventW(NULL
, FALSE
, FALSE
, NULL
);
4181 event_continue
= CreateEventW(NULL
, FALSE
, FALSE
, NULL
);
4182 event_continue_done
= CreateEventW(NULL
, FALSE
, FALSE
, NULL
);
4183 thread_id
= GetCurrentThreadId();
4185 test_file_protocol();
4186 test_http_protocol();
4188 test_https_protocol();
4190 win_skip("Skipping https tests on too old platform\n");
4191 test_ftp_protocol();
4192 test_gopher_protocol();
4194 test_CreateBinding();
4196 bindf
&= ~BINDF_FROMURLMON
;
4197 trace("Testing file binding (mime verification, emulate prot)...\n");
4198 test_binding(FILE_TEST
, PI_MIMEVERIFICATION
, TEST_EMULATEPROT
);
4199 trace("Testing http binding (mime verification, emulate prot)...\n");
4200 test_binding(HTTP_TEST
, PI_MIMEVERIFICATION
, TEST_EMULATEPROT
);
4201 trace("Testing its binding (mime verification, emulate prot)...\n");
4202 test_binding(ITS_TEST
, PI_MIMEVERIFICATION
, TEST_EMULATEPROT
);
4203 trace("Testing http binding (mime verification, emulate prot, short read, direct read)...\n");
4204 test_binding(HTTP_TEST
, PI_MIMEVERIFICATION
, TEST_EMULATEPROT
|TEST_SHORT_READ
|TEST_DIRECT_READ
);
4205 trace("Testing http binding (mime verification, redirect, emulate prot)...\n");
4206 test_binding(HTTP_TEST
, PI_MIMEVERIFICATION
, TEST_EMULATEPROT
|TEST_REDIRECT
);
4207 trace("Testing http binding (mime verification, redirect, disable auto redirect, emulate prot)...\n");
4208 test_binding(HTTP_TEST
, PI_MIMEVERIFICATION
, TEST_EMULATEPROT
|TEST_REDIRECT
|TEST_DISABLEAUTOREDIRECT
);
4209 trace("Testing file binding (mime verification, emulate prot, mime filter)...\n");
4210 test_binding(FILE_TEST
, PI_MIMEVERIFICATION
, TEST_EMULATEPROT
|TEST_FILTER
);
4211 trace("Testing http binding (mime verification, emulate prot, mime filter)...\n");
4212 test_binding(HTTP_TEST
, PI_MIMEVERIFICATION
, TEST_EMULATEPROT
|TEST_FILTER
);
4213 trace("Testing http binding (mime verification, emulate prot, mime filter, no mime)...\n");
4214 test_binding(HTTP_TEST
, PI_MIMEVERIFICATION
, TEST_EMULATEPROT
|TEST_FILTER
|TEST_NOMIME
);
4215 trace("Testing http binding (mime verification, emulate prot, direct read)...\n");
4216 test_binding(HTTP_TEST
, PI_MIMEVERIFICATION
, TEST_EMULATEPROT
|TEST_DIRECT_READ
);
4217 trace("Testing http binding (mime verification, emulate prot, abort)...\n");
4218 test_binding(HTTP_TEST
, PI_MIMEVERIFICATION
, TEST_EMULATEPROT
|TEST_ABORT
);
4220 trace("Testing file binding (use IUri, mime verification, emulate prot)...\n");
4221 test_binding(FILE_TEST
, PI_MIMEVERIFICATION
, TEST_EMULATEPROT
|TEST_USEIURI
);
4222 trace("Testing file binding (use IUri, impl StartEx, mime verification, emulate prot)...\n");
4223 test_binding(FILE_TEST
, PI_MIMEVERIFICATION
, TEST_EMULATEPROT
|TEST_USEIURI
|TEST_IMPLPROTEX
);
4224 trace("Testing file binding (impl StartEx, mime verification, emulate prot)...\n");
4225 test_binding(FILE_TEST
, PI_MIMEVERIFICATION
, TEST_EMULATEPROT
|TEST_IMPLPROTEX
);
4228 CloseHandle(event_complete
);
4229 CloseHandle(event_complete2
);
4230 CloseHandle(event_continue
);
4231 CloseHandle(event_continue_done
);
4233 test_com_aggregation(&CLSID_FileProtocol
);
4234 test_com_aggregation(&CLSID_HttpProtocol
);
4235 test_com_aggregation(&CLSID_HttpSProtocol
);
4236 test_com_aggregation(&CLSID_FtpProtocol
);
4237 test_com_aggregation(&CLSID_MkProtocol
);