2 * Copyright 2005-2009 Jacek Caban for CodeWeavers
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
22 #include <wine/test.h>
32 #define DEFINE_EXPECT(func) \
33 static BOOL expect_ ## func = FALSE, called_ ## func = FALSE
35 #define SET_EXPECT(func) \
36 expect_ ## func = TRUE
38 #define CHECK_EXPECT2(func) \
40 ok(expect_ ##func, "unexpected call " #func "\n"); \
41 called_ ## func = TRUE; \
44 #define CHECK_EXPECT(func) \
46 CHECK_EXPECT2(func); \
47 expect_ ## func = FALSE; \
50 #define CHECK_CALLED(func) \
52 ok(called_ ## func, "expected " #func "\n"); \
53 expect_ ## func = called_ ## func = FALSE; \
56 #define CHECK_NOT_CALLED(func) \
58 ok(!called_ ## func, "unexpected " #func "\n"); \
59 expect_ ## func = called_ ## func = FALSE; \
62 #define CLEAR_CALLED(func) \
63 expect_ ## func = called_ ## func = FALSE
65 DEFINE_EXPECT(GetBindInfo
);
66 DEFINE_EXPECT(ReportProgress_MIMETYPEAVAILABLE
);
67 DEFINE_EXPECT(ReportProgress_DIRECTBIND
);
68 DEFINE_EXPECT(ReportProgress_RAWMIMETYPE
);
69 DEFINE_EXPECT(ReportProgress_FINDINGRESOURCE
);
70 DEFINE_EXPECT(ReportProgress_CONNECTING
);
71 DEFINE_EXPECT(ReportProgress_SENDINGREQUEST
);
72 DEFINE_EXPECT(ReportProgress_CACHEFILENAMEAVAILABLE
);
73 DEFINE_EXPECT(ReportProgress_VERIFIEDMIMETYPEAVAILABLE
);
74 DEFINE_EXPECT(ReportProgress_PROTOCOLCLASSID
);
75 DEFINE_EXPECT(ReportProgress_COOKIE_SENT
);
76 DEFINE_EXPECT(ReportProgress_REDIRECTING
);
77 DEFINE_EXPECT(ReportProgress_ENCODING
);
78 DEFINE_EXPECT(ReportProgress_ACCEPTRANGES
);
79 DEFINE_EXPECT(ReportProgress_PROXYDETECTING
);
80 DEFINE_EXPECT(ReportProgress_LOADINGMIMEHANDLER
);
81 DEFINE_EXPECT(ReportProgress_DECODING
);
82 DEFINE_EXPECT(ReportData
);
83 DEFINE_EXPECT(ReportResult
);
84 DEFINE_EXPECT(GetBindString_ACCEPT_MIMES
);
85 DEFINE_EXPECT(GetBindString_USER_AGENT
);
86 DEFINE_EXPECT(GetBindString_POST_COOKIE
);
87 DEFINE_EXPECT(GetBindString_URL
);
88 DEFINE_EXPECT(QueryService_HttpNegotiate
);
89 DEFINE_EXPECT(QueryService_InternetProtocol
);
90 DEFINE_EXPECT(QueryService_HttpSecurity
);
91 DEFINE_EXPECT(BeginningTransaction
);
92 DEFINE_EXPECT(GetRootSecurityId
);
93 DEFINE_EXPECT(OnResponse
);
94 DEFINE_EXPECT(Switch
);
95 DEFINE_EXPECT(Continue
);
96 DEFINE_EXPECT(CreateInstance
);
98 DEFINE_EXPECT(Terminate
);
100 DEFINE_EXPECT(SetPriority
);
101 DEFINE_EXPECT(LockRequest
);
102 DEFINE_EXPECT(UnlockRequest
);
103 DEFINE_EXPECT(MimeFilter_CreateInstance
);
104 DEFINE_EXPECT(MimeFilter_Start
);
105 DEFINE_EXPECT(MimeFilter_ReportProgress
);
106 DEFINE_EXPECT(MimeFilter_ReportData
);
107 DEFINE_EXPECT(MimeFilter_ReportResult
);
108 DEFINE_EXPECT(MimeFilter_Terminate
);
109 DEFINE_EXPECT(MimeFilter_LockRequest
);
110 DEFINE_EXPECT(MimeFilter_UnlockRequest
);
111 DEFINE_EXPECT(MimeFilter_Read
);
112 DEFINE_EXPECT(MimeFilter_Switch
);
113 DEFINE_EXPECT(MimeFilter_Continue
);
115 static const WCHAR wszIndexHtml
[] = {'i','n','d','e','x','.','h','t','m','l',0};
116 static const WCHAR index_url
[] =
117 {'f','i','l','e',':','i','n','d','e','x','.','h','t','m','l',0};
119 static const WCHAR acc_mimeW
[] = {'*','/','*',0};
120 static const WCHAR user_agentW
[] = {'W','i','n','e',0};
121 static const WCHAR text_htmlW
[] = {'t','e','x','t','/','h','t','m','l',0};
122 static const WCHAR hostW
[] = {'w','w','w','.','w','i','n','e','h','q','.','o','r','g',0};
123 static const WCHAR winehq_ipW
[] = {'2','0','9','.','4','6','.','2','5','.','1','3','4',0};
124 static const WCHAR emptyW
[] = {0};
125 static const WCHAR gzipW
[] = {'g','z','i','p',0};
127 static HRESULT expect_hrResult
;
128 static LPCWSTR file_name
, http_url
, expect_wsz
;
129 static IInternetProtocol
*async_protocol
= NULL
;
130 static BOOL first_data_notif
= FALSE
, http_is_first
= FALSE
,
131 http_post_test
= FALSE
;
132 static int state
= 0, prot_state
;
133 static DWORD bindf
, ex_priority
, pi
;
134 static IInternetProtocol
*binding_protocol
, *filtered_protocol
;
135 static IInternetBindInfo
*prot_bind_info
;
136 static IInternetProtocolSink
*binding_sink
, *filtered_sink
;
137 static void *expect_pv
;
138 static HANDLE event_complete
, event_complete2
;
139 static BOOL binding_test
;
140 static PROTOCOLDATA protocoldata
, *pdata
;
141 static DWORD prot_read
, pi
, filter_state
;
142 static BOOL security_problem
= FALSE
;
143 static BOOL async_read_pending
, mimefilter_test
;
154 static const WCHAR protocol_names
[][10] = {
157 {'h','t','t','p','s',0},
163 static const WCHAR binding_urls
[][130] = {
164 {'f','i','l','e',':','t','e','s','t','.','h','t','m','l',0},
165 {'h','t','t','p',':','/','/','t','e','s','t','/','t','e','s','t','.','h','t','m','l',0},
166 {'h','t','t','p','s',':','/','/','w','w','w','.','c','o','d','e','w','e','a','v','e','r','s',
167 '.','c','o','m','/','t','e','s','t','.','h','t','m','l',0},
168 {'f','t','p',':','/','/','f','t','p','.','w','i','n','e','h','q','.','o','r','g',
169 '/','p','u','b','/','o','t','h','e','r',
170 '/','w','i','n','e','l','o','g','o','.','x','c','f','.','t','a','r','.','b','z','2',0},
171 {'m','k',':','t','e','s','t',0},
172 {'t','e','s','t',':','/','/','f','i','l','e','.','h','t','m','l',0}
175 static const char *debugstr_w(LPCWSTR str
)
177 static char buf
[512];
180 WideCharToMultiByte(CP_ACP
, 0, str
, -1, buf
, sizeof(buf
), NULL
, NULL
);
184 static const char *debugstr_guid(REFIID riid
)
188 sprintf(buf
, "{%08X-%04X-%04X-%02X%02X-%02X%02X%02X%02X%02X%02X}",
189 riid
->Data1
, riid
->Data2
, riid
->Data3
, riid
->Data4
[0],
190 riid
->Data4
[1], riid
->Data4
[2], riid
->Data4
[3], riid
->Data4
[4],
191 riid
->Data4
[5], riid
->Data4
[6], riid
->Data4
[7]);
196 static int strcmp_wa(LPCWSTR strw
, const char *stra
)
199 MultiByteToWideChar(CP_ACP
, 0, stra
, -1, buf
, sizeof(buf
)/sizeof(WCHAR
));
200 return lstrcmpW(strw
, buf
);
203 static HRESULT WINAPI
HttpSecurity_QueryInterface(IHttpSecurity
*iface
, REFIID riid
, void **ppv
)
205 if(IsEqualGUID(&IID_IUnknown
, riid
)
206 || IsEqualGUID(&IID_IHttpSecurity
, riid
)) {
211 ok(0, "unexpected call\n");
212 return E_NOINTERFACE
;
215 static ULONG WINAPI
HttpSecurity_AddRef(IHttpSecurity
*iface
)
220 static ULONG WINAPI
HttpSecurity_Release(IHttpSecurity
*iface
)
225 static HRESULT WINAPI
HttpSecurity_GetWindow(IHttpSecurity
* iface
, REFGUID rguidReason
, HWND
*phwnd
)
227 trace("HttpSecurity_GetWindow\n");
232 static HRESULT WINAPI
HttpSecurity_OnSecurityProblem(IHttpSecurity
*iface
, DWORD dwProblem
)
234 trace("Security problem: %u\n", dwProblem
);
235 ok(dwProblem
== ERROR_INTERNET_SEC_CERT_REV_FAILED
, "Expected ERROR_INTERNET_SEC_CERT_REV_FAILED got %u\n", dwProblem
);
237 /* Only retry once */
238 if (security_problem
)
241 security_problem
= TRUE
;
242 SET_EXPECT(BeginningTransaction
);
247 static IHttpSecurityVtbl HttpSecurityVtbl
= {
248 HttpSecurity_QueryInterface
,
250 HttpSecurity_Release
,
251 HttpSecurity_GetWindow
,
252 HttpSecurity_OnSecurityProblem
255 static IHttpSecurity http_security
= { &HttpSecurityVtbl
};
257 static HRESULT WINAPI
HttpNegotiate_QueryInterface(IHttpNegotiate2
*iface
, REFIID riid
, void **ppv
)
259 if(IsEqualGUID(&IID_IUnknown
, riid
)
260 || IsEqualGUID(&IID_IHttpNegotiate
, riid
)
261 || IsEqualGUID(&IID_IHttpNegotiate2
, riid
)) {
266 ok(0, "unexpected call\n");
267 return E_NOINTERFACE
;
270 static ULONG WINAPI
HttpNegotiate_AddRef(IHttpNegotiate2
*iface
)
275 static ULONG WINAPI
HttpNegotiate_Release(IHttpNegotiate2
*iface
)
280 static HRESULT WINAPI
HttpNegotiate_BeginningTransaction(IHttpNegotiate2
*iface
, LPCWSTR szURL
,
281 LPCWSTR szHeaders
, DWORD dwReserved
, LPWSTR
*pszAdditionalHeaders
)
285 static const WCHAR wszHeaders
[] =
286 {'C','o','n','t','e','n','t','-','T','y','p','e',':',' ','a','p','p','l','i','c','a','t',
287 'i','o','n','/','x','-','w','w','w','-','f','o','r','m','-','u','r','l','e','n','c','o',
288 'd','e','d','\r','\n',0};
290 CHECK_EXPECT(BeginningTransaction
);
293 ok(!lstrcmpW(szURL
, binding_urls
[tested_protocol
]), "szURL != http_url\n");
295 ok(!lstrcmpW(szURL
, http_url
), "szURL != http_url\n");
296 ok(!dwReserved
, "dwReserved=%d, expected 0\n", dwReserved
);
297 ok(pszAdditionalHeaders
!= NULL
, "pszAdditionalHeaders == NULL\n");
298 if(pszAdditionalHeaders
)
300 ok(*pszAdditionalHeaders
== NULL
, "*pszAdditionalHeaders != NULL\n");
303 addl_headers
= CoTaskMemAlloc(sizeof(wszHeaders
));
306 http_post_test
= FALSE
;
307 skip("Out of memory\n");
308 return E_OUTOFMEMORY
;
310 lstrcpyW(addl_headers
, wszHeaders
);
311 *pszAdditionalHeaders
= addl_headers
;
318 static HRESULT WINAPI
HttpNegotiate_OnResponse(IHttpNegotiate2
*iface
, DWORD dwResponseCode
,
319 LPCWSTR szResponseHeaders
, LPCWSTR szRequestHeaders
, LPWSTR
*pszAdditionalRequestHeaders
)
321 CHECK_EXPECT(OnResponse
);
323 ok(dwResponseCode
== 200, "dwResponseCode=%d, expected 200\n", dwResponseCode
);
324 ok(szResponseHeaders
!= NULL
, "szResponseHeaders == NULL\n");
325 ok(szRequestHeaders
== NULL
, "szRequestHeaders != NULL\n");
326 ok(pszAdditionalRequestHeaders
== NULL
, "pszAdditionalHeaders != NULL\n");
331 static HRESULT WINAPI
HttpNegotiate_GetRootSecurityId(IHttpNegotiate2
*iface
,
332 BYTE
*pbSecurityId
, DWORD
*pcbSecurityId
, DWORD_PTR dwReserved
)
334 static const BYTE sec_id
[] = {'h','t','t','p',':','t','e','s','t',1,0,0,0};
336 CHECK_EXPECT(GetRootSecurityId
);
338 ok(!dwReserved
, "dwReserved=%ld, expected 0\n", dwReserved
);
339 ok(pbSecurityId
!= NULL
, "pbSecurityId == NULL\n");
340 ok(pcbSecurityId
!= NULL
, "pcbSecurityId == NULL\n");
343 ok(*pcbSecurityId
== 512, "*pcbSecurityId=%d, expected 512\n", *pcbSecurityId
);
344 *pcbSecurityId
= sizeof(sec_id
);
348 memcpy(pbSecurityId
, sec_id
, sizeof(sec_id
));
353 static IHttpNegotiate2Vtbl HttpNegotiateVtbl
= {
354 HttpNegotiate_QueryInterface
,
355 HttpNegotiate_AddRef
,
356 HttpNegotiate_Release
,
357 HttpNegotiate_BeginningTransaction
,
358 HttpNegotiate_OnResponse
,
359 HttpNegotiate_GetRootSecurityId
362 static IHttpNegotiate2 http_negotiate
= { &HttpNegotiateVtbl
};
364 static HRESULT
QueryInterface(REFIID
,void**);
366 static HRESULT WINAPI
ServiceProvider_QueryInterface(IServiceProvider
*iface
, REFIID riid
, void **ppv
)
368 return QueryInterface(riid
, ppv
);
371 static ULONG WINAPI
ServiceProvider_AddRef(IServiceProvider
*iface
)
376 static ULONG WINAPI
ServiceProvider_Release(IServiceProvider
*iface
)
381 static HRESULT WINAPI
ServiceProvider_QueryService(IServiceProvider
*iface
, REFGUID guidService
,
382 REFIID riid
, void **ppv
)
384 if(IsEqualGUID(&IID_IHttpNegotiate
, guidService
) || IsEqualGUID(&IID_IHttpNegotiate2
, riid
)) {
385 CHECK_EXPECT2(QueryService_HttpNegotiate
);
386 return IHttpNegotiate2_QueryInterface(&http_negotiate
, riid
, ppv
);
389 if(IsEqualGUID(&IID_IInternetProtocol
, guidService
)) {
390 ok(IsEqualGUID(&IID_IInternetProtocol
, riid
), "unexpected riid\n");
391 CHECK_EXPECT(QueryService_InternetProtocol
);
392 return E_NOINTERFACE
;
395 if(IsEqualGUID(&IID_IHttpSecurity
, guidService
)) {
396 ok(IsEqualGUID(&IID_IHttpSecurity
, riid
), "unexpected riid\n");
397 CHECK_EXPECT(QueryService_HttpSecurity
);
398 return IHttpSecurity_QueryInterface(&http_security
, riid
, ppv
);
401 ok(0, "unexpected service %s\n", debugstr_guid(guidService
));
405 static const IServiceProviderVtbl ServiceProviderVtbl
= {
406 ServiceProvider_QueryInterface
,
407 ServiceProvider_AddRef
,
408 ServiceProvider_Release
,
409 ServiceProvider_QueryService
412 static IServiceProvider service_provider
= { &ServiceProviderVtbl
};
414 static HRESULT WINAPI
ProtocolSink_QueryInterface(IInternetProtocolSink
*iface
, REFIID riid
, void **ppv
)
416 return QueryInterface(riid
, ppv
);
419 static ULONG WINAPI
ProtocolSink_AddRef(IInternetProtocolSink
*iface
)
424 static ULONG WINAPI
ProtocolSink_Release(IInternetProtocolSink
*iface
)
429 static HRESULT WINAPI
ProtocolSink_Switch(IInternetProtocolSink
*iface
, PROTOCOLDATA
*pProtocolData
)
433 if(tested_protocol
== FTP_TEST
)
434 CHECK_EXPECT2(Switch
);
436 CHECK_EXPECT(Switch
);
438 ok(pProtocolData
!= NULL
, "pProtocolData == NULL\n");
440 pdata
= pProtocolData
;
443 SetEvent(event_complete
);
444 WaitForSingleObject(event_complete2
, INFINITE
);
449 if(tested_protocol
== HTTP_TEST
|| tested_protocol
== HTTPS_TEST
|| tested_protocol
== FTP_TEST
) {
451 CLEAR_CALLED(ReportProgress_FINDINGRESOURCE
);
452 CLEAR_CALLED(ReportProgress_CONNECTING
);
453 CLEAR_CALLED(ReportProgress_PROXYDETECTING
);
455 CHECK_NOT_CALLED(ReportProgress_FINDINGRESOURCE
);
456 /* IE7 does call this */
457 CLEAR_CALLED(ReportProgress_CONNECTING
);
460 if(tested_protocol
== FTP_TEST
)
461 todo_wine
CHECK_CALLED(ReportProgress_SENDINGREQUEST
);
462 else if (tested_protocol
!= HTTPS_TEST
)
463 CHECK_CALLED(ReportProgress_SENDINGREQUEST
);
464 if(tested_protocol
== HTTP_TEST
|| tested_protocol
== HTTPS_TEST
) {
465 SET_EXPECT(OnResponse
);
466 if(tested_protocol
== HTTPS_TEST
)
467 SET_EXPECT(ReportProgress_ACCEPTRANGES
);
468 SET_EXPECT(ReportProgress_MIMETYPEAVAILABLE
);
469 if(bindf
& BINDF_NEEDFILE
)
470 SET_EXPECT(ReportProgress_CACHEFILENAMEAVAILABLE
);
474 SET_EXPECT(ReportData
);
475 hres
= IInternetProtocol_Continue(async_protocol
, pProtocolData
);
476 ok(hres
== S_OK
, "Continue failed: %08x\n", hres
);
477 if(tested_protocol
== FTP_TEST
)
478 CLEAR_CALLED(ReportData
);
479 else if (! security_problem
)
480 CHECK_CALLED(ReportData
);
483 if (! security_problem
)
486 if(tested_protocol
== HTTP_TEST
|| tested_protocol
== HTTPS_TEST
) {
487 CHECK_CALLED(OnResponse
);
488 if(tested_protocol
== HTTPS_TEST
)
489 CHECK_CALLED(ReportProgress_ACCEPTRANGES
);
490 CHECK_CALLED(ReportProgress_MIMETYPEAVAILABLE
);
491 if(bindf
& BINDF_NEEDFILE
)
492 CHECK_CALLED(ReportProgress_CACHEFILENAMEAVAILABLE
);
497 security_problem
= FALSE
;
498 SET_EXPECT(ReportProgress_CONNECTING
);
502 SetEvent(event_complete
);
507 static HRESULT WINAPI
ProtocolSink_ReportProgress(IInternetProtocolSink
*iface
, ULONG ulStatusCode
,
508 LPCWSTR szStatusText
)
510 static const WCHAR null_guid
[] = {'{','0','0','0','0','0','0','0','0','-','0','0','0','0','-',
511 '0','0','0','0','-','0','0','0','0','-','0','0','0','0','0','0','0','0','0','0','0','0','}',0};
512 static const WCHAR text_plain
[] = {'t','e','x','t','/','p','l','a','i','n',0};
514 switch(ulStatusCode
) {
515 case BINDSTATUS_MIMETYPEAVAILABLE
:
516 CHECK_EXPECT(ReportProgress_MIMETYPEAVAILABLE
);
517 ok(szStatusText
!= NULL
, "szStatusText == NULL\n");
519 if(tested_protocol
== BIND_TEST
)
520 ok(szStatusText
== expect_wsz
, "unexpected szStatusText\n");
521 else if (http_post_test
)
522 ok(lstrlenW(text_plain
) <= lstrlenW(szStatusText
) &&
523 !memcmp(szStatusText
, text_plain
, lstrlenW(text_plain
)*sizeof(WCHAR
)),
524 "szStatusText != text/plain\n");
525 else if(!mimefilter_test
)
526 ok(lstrlenW(text_htmlW
) <= lstrlenW(szStatusText
) &&
527 !memcmp(szStatusText
, text_htmlW
, lstrlenW(text_htmlW
)*sizeof(WCHAR
)),
528 "szStatusText != text/html\n");
531 case BINDSTATUS_DIRECTBIND
:
532 CHECK_EXPECT2(ReportProgress_DIRECTBIND
);
533 ok(szStatusText
== NULL
, "szStatusText != NULL\n");
535 case BINDSTATUS_RAWMIMETYPE
:
536 CHECK_EXPECT2(ReportProgress_RAWMIMETYPE
);
537 ok(szStatusText
!= NULL
, "szStatusText == NULL\n");
539 ok(lstrlenW(szStatusText
) < lstrlenW(text_htmlW
) ||
540 !memcmp(szStatusText
, text_htmlW
, lstrlenW(text_htmlW
)*sizeof(WCHAR
)),
541 "szStatusText != text/html\n");
543 case BINDSTATUS_CACHEFILENAMEAVAILABLE
:
544 CHECK_EXPECT(ReportProgress_CACHEFILENAMEAVAILABLE
);
545 ok(szStatusText
!= NULL
, "szStatusText == NULL\n");
548 ok(!lstrcmpW(szStatusText
, expect_wsz
), "unexpected szStatusText\n");
549 else if(tested_protocol
== FILE_TEST
)
550 ok(!lstrcmpW(szStatusText
, file_name
), "szStatusText = \"%s\"\n", debugstr_w(szStatusText
));
552 ok(szStatusText
!= NULL
, "szStatusText == NULL\n");
555 case BINDSTATUS_FINDINGRESOURCE
:
556 CHECK_EXPECT2(ReportProgress_FINDINGRESOURCE
);
557 ok(szStatusText
!= NULL
, "szStatusText == NULL\n");
559 case BINDSTATUS_CONNECTING
:
560 CHECK_EXPECT2(ReportProgress_CONNECTING
);
561 ok(szStatusText
!= NULL
, "szStatusText == NULL\n");
563 case BINDSTATUS_SENDINGREQUEST
:
564 CHECK_EXPECT2(ReportProgress_SENDINGREQUEST
);
565 if(tested_protocol
== FILE_TEST
) {
566 ok(szStatusText
!= NULL
, "szStatusText == NULL\n");
568 ok(!*szStatusText
, "wrong szStatusText\n");
571 case BINDSTATUS_VERIFIEDMIMETYPEAVAILABLE
:
572 CHECK_EXPECT(ReportProgress_VERIFIEDMIMETYPEAVAILABLE
);
573 ok(szStatusText
!= NULL
, "szStatusText == NULL\n");
575 ok(!lstrcmpW(szStatusText
, text_htmlW
), "szStatusText != text/html\n");
577 case BINDSTATUS_PROTOCOLCLASSID
:
578 CHECK_EXPECT(ReportProgress_PROTOCOLCLASSID
);
579 ok(szStatusText
!= NULL
, "szStatusText == NULL\n");
580 ok(!lstrcmpW(szStatusText
, null_guid
), "unexpected szStatusText\n");
582 case BINDSTATUS_COOKIE_SENT
:
583 CHECK_EXPECT(ReportProgress_COOKIE_SENT
);
584 ok(szStatusText
== NULL
, "szStatusText != NULL\n");
586 case BINDSTATUS_REDIRECTING
:
587 CHECK_EXPECT(ReportProgress_REDIRECTING
);
588 ok(szStatusText
== NULL
, "szStatusText = %s\n", debugstr_w(szStatusText
));
590 case BINDSTATUS_ENCODING
:
591 CHECK_EXPECT(ReportProgress_ENCODING
);
592 ok(!strcmp_wa(szStatusText
, "gzip"), "szStatusText = %s\n", debugstr_w(szStatusText
));
594 case BINDSTATUS_ACCEPTRANGES
:
595 CHECK_EXPECT(ReportProgress_ACCEPTRANGES
);
596 ok(!szStatusText
, "szStatusText = %s\n", debugstr_w(szStatusText
));
598 case BINDSTATUS_PROXYDETECTING
:
599 CHECK_EXPECT(ReportProgress_PROXYDETECTING
);
600 SET_EXPECT(ReportProgress_CONNECTING
);
601 ok(!szStatusText
, "szStatusText = %s\n", debugstr_w(szStatusText
));
603 case BINDSTATUS_LOADINGMIMEHANDLER
:
604 CHECK_EXPECT(ReportProgress_LOADINGMIMEHANDLER
);
605 ok(!szStatusText
, "szStatusText = %s\n", debugstr_w(szStatusText
));
607 case BINDSTATUS_DECODING
:
608 CHECK_EXPECT(ReportProgress_DECODING
);
609 ok(!lstrcmpW(szStatusText
, gzipW
), "szStatusText = %s\n", debugstr_w(szStatusText
));
612 ok(0, "Unexpected status %d\n", ulStatusCode
);
618 static HRESULT WINAPI
ProtocolSink_ReportData(IInternetProtocolSink
*iface
, DWORD grfBSCF
,
619 ULONG ulProgress
, ULONG ulProgressMax
)
621 if(!mimefilter_test
&& tested_protocol
== FILE_TEST
) {
622 CHECK_EXPECT2(ReportData
);
624 ok(ulProgress
== ulProgressMax
, "ulProgress (%d) != ulProgressMax (%d)\n",
625 ulProgress
, ulProgressMax
);
626 ok(ulProgressMax
== 13, "ulProgressMax=%d, expected 13\n", ulProgressMax
);
627 /* BSCF_SKIPDRAINDATAFORFILEURLS added in IE8 */
628 ok((grfBSCF
== (BSCF_FIRSTDATANOTIFICATION
| BSCF_LASTDATANOTIFICATION
)) ||
629 (grfBSCF
== (BSCF_FIRSTDATANOTIFICATION
| BSCF_LASTDATANOTIFICATION
| BSCF_SKIPDRAINDATAFORFILEURLS
)),
630 "grcfBSCF = %08x\n", grfBSCF
);
631 }else if(!binding_test
&& (tested_protocol
== HTTP_TEST
|| tested_protocol
== HTTPS_TEST
|| tested_protocol
== FTP_TEST
)) {
632 if(!(grfBSCF
& BSCF_LASTDATANOTIFICATION
) || (grfBSCF
& BSCF_DATAFULLYAVAILABLE
))
633 CHECK_EXPECT(ReportData
);
634 else if (http_post_test
)
635 ok(ulProgress
== 13, "Read %u bytes instead of 13\n", ulProgress
);
637 ok(ulProgress
, "ulProgress == 0\n");
639 if(first_data_notif
) {
640 ok(grfBSCF
== BSCF_FIRSTDATANOTIFICATION
641 || grfBSCF
== (BSCF_LASTDATANOTIFICATION
|BSCF_DATAFULLYAVAILABLE
),
642 "grcfBSCF = %08x\n", grfBSCF
);
643 first_data_notif
= FALSE
;
645 ok(grfBSCF
== BSCF_INTERMEDIATEDATANOTIFICATION
646 || grfBSCF
== (BSCF_LASTDATANOTIFICATION
|BSCF_INTERMEDIATEDATANOTIFICATION
)
647 || broken(grfBSCF
== (BSCF_FIRSTDATANOTIFICATION
|BSCF_LASTDATANOTIFICATION
)),
648 "grcfBSCF = %08x\n", grfBSCF
);
651 if(!(bindf
& BINDF_FROMURLMON
) &&
652 !(grfBSCF
& BSCF_LASTDATANOTIFICATION
)) {
656 CHECK_CALLED(ReportProgress_FINDINGRESOURCE
);
657 CHECK_CALLED(ReportProgress_CONNECTING
);
659 CHECK_NOT_CALLED(ReportProgress_FINDINGRESOURCE
);
660 CHECK_NOT_CALLED(ReportProgress_CONNECTING
);
662 CHECK_CALLED(ReportProgress_SENDINGREQUEST
);
663 CHECK_CALLED(OnResponse
);
664 CHECK_CALLED(ReportProgress_RAWMIMETYPE
);
666 SetEvent(event_complete
);
673 CHECK_EXPECT(ReportData
);
675 if(tested_protocol
== BIND_TEST
)
680 SET_EXPECT(MimeFilter_Read
);
683 hres
= IInternetProtocol_Read(binding_protocol
, expect_pv
=buf
, sizeof(buf
), &read
);
685 CHECK_CALLED(MimeFilter_Read
);
688 }while(hres
== S_OK
);
694 static HRESULT WINAPI
ProtocolSink_ReportResult(IInternetProtocolSink
*iface
, HRESULT hrResult
,
695 DWORD dwError
, LPCWSTR szResult
)
697 CHECK_EXPECT(ReportResult
);
699 if(tested_protocol
== FTP_TEST
)
700 ok(hrResult
== E_PENDING
|| hrResult
== S_OK
, "hrResult = %08x, expected E_PENDING or S_OK\n", hrResult
);
702 ok(hrResult
== expect_hrResult
, "hrResult = %08x, expected: %08x\n",
703 hrResult
, expect_hrResult
);
704 if(SUCCEEDED(hrResult
) || tested_protocol
== FTP_TEST
)
705 ok(dwError
== ERROR_SUCCESS
, "dwError = %d, expected ERROR_SUCCESS\n", dwError
);
707 ok(dwError
!= ERROR_SUCCESS
||
708 broken(tested_protocol
== MK_TEST
), /* Win9x, WinME and NT4 */
709 "dwError == ERROR_SUCCESS\n");
710 ok(!szResult
, "szResult != NULL\n");
715 static IInternetProtocolSinkVtbl protocol_sink_vtbl
= {
716 ProtocolSink_QueryInterface
,
718 ProtocolSink_Release
,
720 ProtocolSink_ReportProgress
,
721 ProtocolSink_ReportData
,
722 ProtocolSink_ReportResult
725 static IInternetProtocolSink protocol_sink
= { &protocol_sink_vtbl
};
727 static HRESULT WINAPI
MimeProtocolSink_QueryInterface(IInternetProtocolSink
*iface
, REFIID riid
, void **ppv
)
729 ok(0, "unexpected call\n");
733 static ULONG WINAPI
MimeProtocolSink_AddRef(IInternetProtocolSink
*iface
)
738 static ULONG WINAPI
MimeProtocolSink_Release(IInternetProtocolSink
*iface
)
743 static HRESULT WINAPI
MimeProtocolSink_Switch(IInternetProtocolSink
*iface
, PROTOCOLDATA
*pProtocolData
)
747 CHECK_EXPECT(MimeFilter_Switch
);
750 hres
= IInternetProtocolSink_Switch(filtered_sink
, pProtocolData
);
751 ok(hres
== S_OK
, "Switch failed: %08x\n", hres
);
752 CHECK_CALLED(Switch
);
757 static HRESULT WINAPI
MimeProtocolSink_ReportProgress(IInternetProtocolSink
*iface
, ULONG ulStatusCode
,
758 LPCWSTR szStatusText
)
760 CHECK_EXPECT(MimeFilter_ReportProgress
);
764 static HRESULT WINAPI
MimeProtocolSink_ReportData(IInternetProtocolSink
*iface
, DWORD grfBSCF
,
765 ULONG ulProgress
, ULONG ulProgressMax
)
771 CHECK_EXPECT(MimeFilter_ReportData
);
773 ok(ulProgress
, "ulProgress == 0\n");
777 hres
= IInternetProtocol_Read(filtered_protocol
, buf
, sizeof(buf
), &read
);
778 if(tested_protocol
== HTTP_TEST
)
779 ok(hres
== S_OK
|| hres
== E_PENDING
|| hres
== S_FALSE
, "Read failed: %08x\n", hres
);
781 ok(hres
== S_OK
, "Read failed: %08x\n", hres
);
784 SET_EXPECT(ReportProgress_MIMETYPEAVAILABLE
);
785 hres
= IInternetProtocolSink_ReportProgress(filtered_sink
, BINDSTATUS_VERIFIEDMIMETYPEAVAILABLE
, text_htmlW
);
786 ok(hres
== S_OK
, "ReportProgress failed: %08x\n", hres
);
787 CHECK_CALLED(ReportProgress_MIMETYPEAVAILABLE
);
789 /* FIXME: test BINDSTATUS_CACHEFILENAMEAVAILABLE */
792 SET_EXPECT(ReportData
);
793 hres
= IInternetProtocolSink_ReportData(filtered_sink
, grfBSCF
, ulProgress
, ulProgressMax
);
794 ok(hres
== S_OK
, "ReportData failed: %08x\n", hres
);
795 CHECK_CALLED(ReportData
);
803 static HRESULT WINAPI
MimeProtocolSink_ReportResult(IInternetProtocolSink
*iface
, HRESULT hrResult
,
804 DWORD dwError
, LPCWSTR szResult
)
808 CHECK_EXPECT(MimeFilter_ReportResult
);
810 ok(hrResult
== S_OK
, "hrResult = %08x\n", hrResult
);
811 ok(dwError
== ERROR_SUCCESS
, "dwError = %u\n", dwError
);
812 ok(!szResult
, "szResult = %s\n", debugstr_w(szResult
));
814 SET_EXPECT(ReportResult
);
815 hres
= IInternetProtocolSink_ReportResult(filtered_sink
, hrResult
, dwError
, szResult
);
816 ok(SUCCEEDED(hres
), "ReportResult failed: %08x\n", hres
);
817 CHECK_CALLED(ReportResult
);
822 static IInternetProtocolSinkVtbl mime_protocol_sink_vtbl
= {
823 MimeProtocolSink_QueryInterface
,
824 MimeProtocolSink_AddRef
,
825 MimeProtocolSink_Release
,
826 MimeProtocolSink_Switch
,
827 MimeProtocolSink_ReportProgress
,
828 MimeProtocolSink_ReportData
,
829 MimeProtocolSink_ReportResult
832 static IInternetProtocolSink mime_protocol_sink
= { &mime_protocol_sink_vtbl
};
834 static HRESULT
QueryInterface(REFIID riid
, void **ppv
)
838 if(IsEqualGUID(&IID_IUnknown
, riid
) || IsEqualGUID(&IID_IInternetProtocolSink
, riid
))
839 *ppv
= &protocol_sink
;
840 if(IsEqualGUID(&IID_IServiceProvider
, riid
))
841 *ppv
= &service_provider
;
842 if(IsEqualGUID(&IID_IUriContainer
, riid
))
843 return E_NOINTERFACE
; /* TODO */
848 ok(0, "unexpected call %s\n", debugstr_guid(riid
));
849 return E_NOINTERFACE
;
852 static HRESULT WINAPI
BindInfo_QueryInterface(IInternetBindInfo
*iface
, REFIID riid
, void **ppv
)
854 if(IsEqualGUID(&IID_IUnknown
, riid
) || IsEqualGUID(&IID_IInternetBindInfo
, riid
)) {
858 return E_NOINTERFACE
;
861 static ULONG WINAPI
BindInfo_AddRef(IInternetBindInfo
*iface
)
866 static ULONG WINAPI
BindInfo_Release(IInternetBindInfo
*iface
)
871 static HRESULT WINAPI
BindInfo_GetBindInfo(IInternetBindInfo
*iface
, DWORD
*grfBINDF
, BINDINFO
*pbindinfo
)
875 static const CHAR szPostData
[] = "mode=Test";
877 CHECK_EXPECT(GetBindInfo
);
879 ok(grfBINDF
!= NULL
, "grfBINDF == NULL\n");
880 ok(pbindinfo
!= NULL
, "pbindinfo == NULL\n");
881 ok(pbindinfo
->cbSize
== sizeof(BINDINFO
), "wrong size of pbindinfo: %d\n", pbindinfo
->cbSize
);
885 *grfBINDF
|= BINDF_FROMURLMON
;
886 cbSize
= pbindinfo
->cbSize
;
887 memset(pbindinfo
, 0, cbSize
);
888 pbindinfo
->cbSize
= cbSize
;
892 /* Must be GMEM_FIXED, GMEM_MOVABLE does not work properly
893 * with urlmon on native (Win98 and WinXP) */
894 U(pbindinfo
->stgmedData
).hGlobal
= GlobalAlloc(GPTR
, sizeof(szPostData
));
895 if (!U(pbindinfo
->stgmedData
).hGlobal
)
897 http_post_test
= FALSE
;
898 skip("Out of memory\n");
899 return E_OUTOFMEMORY
;
901 lstrcpy((LPSTR
)U(pbindinfo
->stgmedData
).hGlobal
, szPostData
);
902 pbindinfo
->cbstgmedData
= sizeof(szPostData
)-1;
903 pbindinfo
->dwBindVerb
= BINDVERB_POST
;
904 pbindinfo
->stgmedData
.tymed
= TYMED_HGLOBAL
;
910 static HRESULT WINAPI
BindInfo_GetBindString(IInternetBindInfo
*iface
, ULONG ulStringType
,
911 LPOLESTR
*ppwzStr
, ULONG cEl
, ULONG
*pcElFetched
)
913 ok(ppwzStr
!= NULL
, "ppwzStr == NULL\n");
914 ok(pcElFetched
!= NULL
, "pcElFetched == NULL\n");
916 switch(ulStringType
) {
917 case BINDSTRING_ACCEPT_MIMES
:
918 CHECK_EXPECT(GetBindString_ACCEPT_MIMES
);
919 ok(cEl
== 256, "cEl=%d, expected 256\n", cEl
);
921 ok(*pcElFetched
== 256, "*pcElFetched=%d, expected 256\n", *pcElFetched
);
925 *ppwzStr
= CoTaskMemAlloc(sizeof(acc_mimeW
));
926 memcpy(*ppwzStr
, acc_mimeW
, sizeof(acc_mimeW
));
929 case BINDSTRING_USER_AGENT
:
930 CHECK_EXPECT(GetBindString_USER_AGENT
);
931 ok(cEl
== 1, "cEl=%d, expected 1\n", cEl
);
933 ok(*pcElFetched
== 0, "*pcElFetch=%d, expectd 0\n", *pcElFetched
);
937 *ppwzStr
= CoTaskMemAlloc(sizeof(user_agentW
));
938 memcpy(*ppwzStr
, user_agentW
, sizeof(user_agentW
));
941 case BINDSTRING_POST_COOKIE
:
942 CHECK_EXPECT(GetBindString_POST_COOKIE
);
943 ok(cEl
== 1, "cEl=%d, expected 1\n", cEl
);
945 ok(*pcElFetched
== 0, "*pcElFetch=%d, expectd 0\n", *pcElFetched
);
947 case BINDSTRING_URL
: {
950 CHECK_EXPECT(GetBindString_URL
);
951 ok(cEl
== 1, "cEl=%d, expected 1\n", cEl
);
952 ok(*pcElFetched
== 0, "*pcElFetch=%d, expectd 0\n", *pcElFetched
);
955 size
= (lstrlenW(binding_urls
[tested_protocol
])+1)*sizeof(WCHAR
);
956 *ppwzStr
= CoTaskMemAlloc(size
);
957 memcpy(*ppwzStr
, binding_urls
[tested_protocol
], size
);
961 ok(0, "unexpected call\n");
967 static IInternetBindInfoVtbl bind_info_vtbl
= {
968 BindInfo_QueryInterface
,
971 BindInfo_GetBindInfo
,
972 BindInfo_GetBindString
975 static IInternetBindInfo bind_info
= { &bind_info_vtbl
};
977 static HRESULT WINAPI
InternetPriority_QueryInterface(IInternetPriority
*iface
,
978 REFIID riid
, void **ppv
)
980 ok(0, "unexpected call\n");
981 return E_NOINTERFACE
;
984 static ULONG WINAPI
InternetPriority_AddRef(IInternetPriority
*iface
)
989 static ULONG WINAPI
InternetPriority_Release(IInternetPriority
*iface
)
994 static HRESULT WINAPI
InternetPriority_SetPriority(IInternetPriority
*iface
, LONG nPriority
)
996 CHECK_EXPECT(SetPriority
);
997 ok(nPriority
== ex_priority
, "nPriority=%d\n", nPriority
);
1001 static HRESULT WINAPI
InternetPriority_GetPriority(IInternetPriority
*iface
, LONG
*pnPriority
)
1003 ok(0, "unexpected call\n");
1008 static const IInternetPriorityVtbl InternetPriorityVtbl
= {
1009 InternetPriority_QueryInterface
,
1010 InternetPriority_AddRef
,
1011 InternetPriority_Release
,
1012 InternetPriority_SetPriority
,
1013 InternetPriority_GetPriority
1016 static IInternetPriority InternetPriority
= { &InternetPriorityVtbl
};
1018 static ULONG WINAPI
Protocol_AddRef(IInternetProtocol
*iface
)
1023 static ULONG WINAPI
Protocol_Release(IInternetProtocol
*iface
)
1028 static HRESULT WINAPI
Protocol_Abort(IInternetProtocol
*iface
, HRESULT hrReason
,
1031 ok(0, "unexpected call\n");
1035 static HRESULT WINAPI
Protocol_Suspend(IInternetProtocol
*iface
)
1037 ok(0, "unexpected call\n");
1041 static HRESULT WINAPI
Protocol_Resume(IInternetProtocol
*iface
)
1043 ok(0, "unexpected call\n");
1047 static HRESULT WINAPI
Protocol_Seek(IInternetProtocol
*iface
,
1048 LARGE_INTEGER dlibMove
, DWORD dwOrigin
, ULARGE_INTEGER
*plibNewPosition
)
1050 ok(0, "unexpected call\n");
1054 static HRESULT WINAPI
ProtocolEmul_QueryInterface(IInternetProtocol
*iface
, REFIID riid
, void **ppv
)
1056 if(IsEqualGUID(&IID_IUnknown
, riid
) || IsEqualGUID(&IID_IInternetProtocol
, riid
)) {
1061 if(IsEqualGUID(&IID_IInternetProtocolEx
, riid
)) {
1062 trace("IID_IInternetProtocolEx not supported\n");
1064 return E_NOINTERFACE
;
1067 if(IsEqualGUID(&IID_IInternetPriority
, riid
)) {
1068 *ppv
= &InternetPriority
;
1072 ok(0, "unexpected riid %s\n", debugstr_guid(riid
));
1074 return E_NOINTERFACE
;
1077 static DWORD WINAPI
thread_proc(PVOID arg
)
1081 memset(&protocoldata
, -1, sizeof(protocoldata
));
1085 SET_EXPECT(ReportProgress_FINDINGRESOURCE
);
1086 hres
= IInternetProtocolSink_ReportProgress(binding_sink
,
1087 BINDSTATUS_FINDINGRESOURCE
, hostW
);
1088 CHECK_CALLED(ReportProgress_FINDINGRESOURCE
);
1089 ok(hres
== S_OK
, "ReportProgress failed: %08x\n", hres
);
1091 SET_EXPECT(ReportProgress_CONNECTING
);
1092 hres
= IInternetProtocolSink_ReportProgress(binding_sink
,
1093 BINDSTATUS_CONNECTING
, winehq_ipW
);
1094 CHECK_CALLED(ReportProgress_CONNECTING
);
1095 ok(hres
== S_OK
, "ReportProgress failed: %08x\n", hres
);
1097 SET_EXPECT(ReportProgress_SENDINGREQUEST
);
1098 hres
= IInternetProtocolSink_ReportProgress(binding_sink
,
1099 BINDSTATUS_SENDINGREQUEST
, NULL
);
1100 CHECK_CALLED(ReportProgress_SENDINGREQUEST
);
1101 ok(hres
== S_OK
, "ReportProgress failed: %08x\n", hres
);
1105 hres
= IInternetProtocolSink_Switch(binding_sink
, &protocoldata
);
1106 CHECK_CALLED(Switch
);
1107 ok(hres
== S_OK
, "Switch failed: %08x\n", hres
);
1111 SET_EXPECT(MimeFilter_Switch
);
1114 hres
= IInternetProtocolSink_Switch(binding_sink
, &protocoldata
);
1115 ok(hres
== S_OK
, "Switch failed: %08x\n", hres
);
1117 CHECK_CALLED(MimeFilter_Switch
);
1119 CHECK_CALLED(Switch
);
1123 SET_EXPECT(MimeFilter_Switch
);
1126 hres
= IInternetProtocolSink_Switch(binding_sink
, &protocoldata
);
1127 ok(hres
== S_OK
, "Switch failed: %08x\n", hres
);
1129 CHECK_CALLED(MimeFilter_Switch
);
1131 CHECK_CALLED(Switch
);
1135 SET_EXPECT(MimeFilter_Switch
);
1138 hres
= IInternetProtocolSink_Switch(binding_sink
, &protocoldata
);
1139 ok(hres
== S_OK
, "Switch failed: %08x\n", hres
);
1141 CHECK_CALLED(MimeFilter_Switch
);
1143 CHECK_CALLED(Switch
);
1145 SetEvent(event_complete
);
1150 static HRESULT WINAPI
ProtocolEmul_Start(IInternetProtocol
*iface
, LPCWSTR szUrl
,
1151 IInternetProtocolSink
*pOIProtSink
, IInternetBindInfo
*pOIBindInfo
,
1152 DWORD grfPI
, HANDLE_PTR dwReserved
)
1154 BINDINFO bindinfo
, exp_bindinfo
;
1158 CHECK_EXPECT(Start
);
1160 ok(pOIProtSink
!= NULL
, "pOIProtSink == NULL\n");
1161 ok(pOIBindInfo
!= NULL
, "pOIBindInfo == NULL\n");
1162 ok(pOIProtSink
!= &protocol_sink
, "unexpected pOIProtSink\n");
1163 ok(pOIBindInfo
!= &bind_info
, "unexpected pOIBindInfo\n");
1164 ok(!grfPI
, "grfPI = %x\n", grfPI
);
1165 ok(!dwReserved
, "dwReserved = %lx\n", dwReserved
);
1168 ok(pOIProtSink
== binding_sink
, "pOIProtSink != binding_sink\n");
1170 memset(&bindinfo
, 0, sizeof(bindinfo
));
1171 bindinfo
.cbSize
= sizeof(bindinfo
);
1172 memcpy(&exp_bindinfo
, &bindinfo
, sizeof(bindinfo
));
1173 SET_EXPECT(GetBindInfo
);
1174 hres
= IInternetBindInfo_GetBindInfo(pOIBindInfo
, &cbindf
, &bindinfo
);
1175 ok(hres
== S_OK
, "GetBindInfo failed: %08x\n", hres
);
1176 CHECK_CALLED(GetBindInfo
);
1177 ok(cbindf
== (bindf
|BINDF_FROMURLMON
), "bindf = %x, expected %x\n",
1178 cbindf
, (bindf
|BINDF_FROMURLMON
));
1179 ok(!memcmp(&exp_bindinfo
, &bindinfo
, sizeof(bindinfo
)), "unexpected bindinfo\n");
1180 ReleaseBindInfo(&bindinfo
);
1182 SET_EXPECT(ReportProgress_SENDINGREQUEST
);
1183 hres
= IInternetProtocolSink_ReportProgress(pOIProtSink
, BINDSTATUS_SENDINGREQUEST
, emptyW
);
1184 ok(hres
== S_OK
, "ReportProgress(BINDSTATUS_SENDINGREQUEST) failed: %08x\n", hres
);
1185 CHECK_CALLED(ReportProgress_SENDINGREQUEST
);
1187 if(tested_protocol
== HTTP_TEST
|| tested_protocol
== HTTPS_TEST
) {
1188 IServiceProvider
*service_provider
;
1189 IHttpNegotiate
*http_negotiate
;
1190 IHttpNegotiate2
*http_negotiate2
;
1191 LPWSTR ua
= (LPWSTR
)0xdeadbeef, accept_mimes
[256];
1192 LPWSTR additional_headers
= NULL
;
1194 DWORD fetched
= 0, size
= 100;
1197 SET_EXPECT(GetBindString_USER_AGENT
);
1198 hres
= IInternetBindInfo_GetBindString(pOIBindInfo
, BINDSTRING_USER_AGENT
,
1200 CHECK_CALLED(GetBindString_USER_AGENT
);
1201 ok(hres
== S_OK
, "GetBindString(BINDSTRING_USER_AGETNT) failed: %08x\n", hres
);
1202 ok(fetched
== 1, "fetched = %d, expected 254\n", fetched
);
1203 ok(ua
!= NULL
, "ua = %p\n", ua
);
1204 ok(!lstrcmpW(ua
, user_agentW
), "unexpected user agent %s\n", debugstr_w(ua
));
1208 SET_EXPECT(GetBindString_ACCEPT_MIMES
);
1209 hres
= IInternetBindInfo_GetBindString(pOIBindInfo
, BINDSTRING_ACCEPT_MIMES
,
1210 accept_mimes
, 256, &fetched
);
1211 CHECK_CALLED(GetBindString_ACCEPT_MIMES
);
1214 "GetBindString(BINDSTRING_ACCEPT_MIMES) failed: %08x\n", hres
);
1215 ok(fetched
== 1, "fetched = %d, expected 1\n", fetched
);
1216 ok(!lstrcmpW(acc_mimeW
, accept_mimes
[0]), "unexpected mimes %s\n", debugstr_w(accept_mimes
[0]));
1218 hres
= IInternetBindInfo_QueryInterface(pOIBindInfo
, &IID_IServiceProvider
,
1219 (void**)&service_provider
);
1220 ok(hres
== S_OK
, "QueryInterface failed: %08x\n", hres
);
1222 SET_EXPECT(QueryService_HttpNegotiate
);
1223 hres
= IServiceProvider_QueryService(service_provider
, &IID_IHttpNegotiate
,
1224 &IID_IHttpNegotiate
, (void**)&http_negotiate
);
1225 CHECK_CALLED(QueryService_HttpNegotiate
);
1226 ok(hres
== S_OK
, "QueryService failed: %08x\n", hres
);
1228 SET_EXPECT(BeginningTransaction
);
1229 hres
= IHttpNegotiate_BeginningTransaction(http_negotiate
, binding_urls
[tested_protocol
],
1230 NULL
, 0, &additional_headers
);
1231 CHECK_CALLED(BeginningTransaction
);
1232 IHttpNegotiate_Release(http_negotiate
);
1233 ok(hres
== S_OK
, "BeginningTransction failed: %08x\n", hres
);
1234 ok(additional_headers
== NULL
, "additional_headers=%p\n", additional_headers
);
1236 SET_EXPECT(QueryService_HttpNegotiate
);
1237 hres
= IServiceProvider_QueryService(service_provider
, &IID_IHttpNegotiate2
,
1238 &IID_IHttpNegotiate2
, (void**)&http_negotiate2
);
1239 CHECK_CALLED(QueryService_HttpNegotiate
);
1240 ok(hres
== S_OK
, "QueryService failed: %08x\n", hres
);
1243 SET_EXPECT(GetRootSecurityId
);
1244 hres
= IHttpNegotiate2_GetRootSecurityId(http_negotiate2
, sec_id
, &size
, 0);
1245 CHECK_CALLED(GetRootSecurityId
);
1246 IHttpNegotiate2_Release(http_negotiate2
);
1247 ok(hres
== E_FAIL
, "GetRootSecurityId failed: %08x, expected E_FAIL\n", hres
);
1248 ok(size
== 13, "size=%d\n", size
);
1250 IServiceProvider_Release(service_provider
);
1252 CreateThread(NULL
, 0, thread_proc
, NULL
, 0, &tid
);
1257 SET_EXPECT(ReportProgress_CACHEFILENAMEAVAILABLE
);
1258 hres
= IInternetProtocolSink_ReportProgress(pOIProtSink
,
1259 BINDSTATUS_CACHEFILENAMEAVAILABLE
, expect_wsz
= emptyW
);
1260 ok(hres
== S_OK
, "ReportProgress(BINDSTATUS_CACHEFILENAMEAVAILABLE) failed: %08x\n", hres
);
1261 CHECK_CALLED(ReportProgress_CACHEFILENAMEAVAILABLE
);
1263 if(mimefilter_test
) {
1264 SET_EXPECT(MimeFilter_CreateInstance
);
1265 SET_EXPECT(MimeFilter_Start
);
1266 SET_EXPECT(ReportProgress_LOADINGMIMEHANDLER
);
1268 SET_EXPECT(ReportProgress_MIMETYPEAVAILABLE
);
1269 hres
= IInternetProtocolSink_ReportProgress(pOIProtSink
, BINDSTATUS_VERIFIEDMIMETYPEAVAILABLE
,
1270 mimefilter_test
? gzipW
: (expect_wsz
= text_htmlW
));
1272 "ReportProgress(BINDSTATUS_VERIFIEDMIMETYPEAVAILABLE) failed: %08x\n", hres
);
1273 if(mimefilter_test
) {
1274 CHECK_CALLED(MimeFilter_CreateInstance
);
1275 CHECK_CALLED(MimeFilter_Start
);
1276 CHECK_CALLED(ReportProgress_LOADINGMIMEHANDLER
);
1277 todo_wine
CHECK_CALLED(ReportProgress_MIMETYPEAVAILABLE
);
1279 CHECK_CALLED(ReportProgress_MIMETYPEAVAILABLE
);
1283 SET_EXPECT(MimeFilter_ReportData
);
1285 SET_EXPECT(ReportData
);
1286 hres
= IInternetProtocolSink_ReportData(pOIProtSink
,
1287 BSCF_FIRSTDATANOTIFICATION
| BSCF_LASTDATANOTIFICATION
, 13, 13);
1288 ok(hres
== S_OK
, "ReportData failed: %08x\n", hres
);
1290 CHECK_CALLED(MimeFilter_ReportData
);
1292 CHECK_CALLED(ReportData
);
1294 if(tested_protocol
== BIND_TEST
) {
1295 hres
= IInternetProtocol_Terminate(binding_protocol
, 0);
1296 ok(hres
== E_FAIL
, "Termiante failed: %08x\n", hres
);
1300 SET_EXPECT(MimeFilter_ReportResult
);
1302 SET_EXPECT(ReportResult
);
1303 hres
= IInternetProtocolSink_ReportResult(pOIProtSink
, S_OK
, 0, NULL
);
1304 ok(hres
== S_OK
, "ReportResult failed: %08x\n", hres
);
1306 CHECK_CALLED(MimeFilter_ReportResult
);
1308 CHECK_CALLED(ReportResult
);
1313 static HRESULT WINAPI
ProtocolEmul_Continue(IInternetProtocol
*iface
,
1314 PROTOCOLDATA
*pProtocolData
)
1319 CHECK_EXPECT(Continue
);
1321 ok(pProtocolData
!= NULL
, "pProtocolData == NULL\n");
1322 if(!pProtocolData
|| tested_protocol
== BIND_TEST
)
1325 switch(prot_state
) {
1327 IServiceProvider
*service_provider
;
1328 IHttpNegotiate
*http_negotiate
;
1329 static WCHAR header
[] = {'?',0};
1331 hres
= IInternetProtocolSink_QueryInterface(binding_sink
, &IID_IServiceProvider
,
1332 (void**)&service_provider
);
1333 ok(hres
== S_OK
, "Could not get IServiceProvicder\n");
1335 SET_EXPECT(QueryService_HttpNegotiate
);
1336 hres
= IServiceProvider_QueryService(service_provider
, &IID_IHttpNegotiate
,
1337 &IID_IHttpNegotiate
, (void**)&http_negotiate
);
1338 IServiceProvider_Release(service_provider
);
1339 CHECK_CALLED(QueryService_HttpNegotiate
);
1340 ok(hres
== S_OK
, "Could not get IHttpNegotiate\n");
1342 SET_EXPECT(OnResponse
);
1343 hres
= IHttpNegotiate_OnResponse(http_negotiate
, 200, header
, NULL
, NULL
);
1344 IHttpNegotiate_Release(http_negotiate
);
1345 CHECK_CALLED(OnResponse
);
1346 IHttpNegotiate_Release(http_negotiate
);
1347 ok(hres
== S_OK
, "OnResponse failed: %08x\n", hres
);
1349 if(mimefilter_test
) {
1350 SET_EXPECT(MimeFilter_CreateInstance
);
1351 SET_EXPECT(MimeFilter_Start
);
1352 SET_EXPECT(ReportProgress_LOADINGMIMEHANDLER
);
1353 }else if(!(pi
& PI_MIMEVERIFICATION
)) {
1354 SET_EXPECT(ReportProgress_MIMETYPEAVAILABLE
);
1356 hres
= IInternetProtocolSink_ReportProgress(binding_sink
,
1357 BINDSTATUS_MIMETYPEAVAILABLE
, mimefilter_test
? gzipW
: text_htmlW
);
1358 if(mimefilter_test
) {
1359 CHECK_CALLED(MimeFilter_CreateInstance
);
1360 CHECK_CALLED(MimeFilter_Start
);
1361 CHECK_CALLED(ReportProgress_LOADINGMIMEHANDLER
);
1362 }else if(!(pi
& PI_MIMEVERIFICATION
)) {
1363 CHECK_CALLED(ReportProgress_MIMETYPEAVAILABLE
);
1366 "ReportProgress(BINDSTATUS_MIMETYPEAVAILABLE) failed: %08x\n", hres
);
1368 bscf
|= BSCF_FIRSTDATANOTIFICATION
;
1373 bscf
= BSCF_INTERMEDIATEDATANOTIFICATION
;
1378 if(mimefilter_test
) {
1379 SET_EXPECT(MimeFilter_ReportData
);
1380 }else if(pi
& PI_MIMEVERIFICATION
) {
1385 SET_EXPECT(ReportProgress_MIMETYPEAVAILABLE
);
1388 SET_EXPECT(ReportData
);
1390 SET_EXPECT(ReportData
);
1393 hres
= IInternetProtocolSink_ReportData(binding_sink
, bscf
, 100, 400);
1394 ok(hres
== S_OK
, "ReportData failed: %08x\n", hres
);
1396 if(mimefilter_test
) {
1397 SET_EXPECT(MimeFilter_ReportData
);
1398 }else if(pi
& PI_MIMEVERIFICATION
) {
1403 CHECK_CALLED(ReportProgress_MIMETYPEAVAILABLE
);
1406 CHECK_CALLED(ReportData
);
1415 static HRESULT WINAPI
ProtocolEmul_Terminate(IInternetProtocol
*iface
, DWORD dwOptions
)
1417 CHECK_EXPECT(Terminate
);
1418 ok(!dwOptions
, "dwOptions=%d\n", dwOptions
);
1422 static HRESULT WINAPI
ProtocolEmul_Read(IInternetProtocol
*iface
, void *pv
,
1423 ULONG cb
, ULONG
*pcbRead
)
1425 if(mimefilter_test
) {
1426 CHECK_EXPECT2(Read
);
1427 }else if((pi
& PI_MIMEVERIFICATION
)) {
1428 CHECK_EXPECT2(Read
);
1430 if(prot_read
< 300) {
1431 ok(pv
!= expect_pv
, "pv == expect_pv\n");
1433 ok(cb
== 2048-prot_read
, "cb=%d\n", cb
);
1435 ok(cb
== 700, "cb=%d\n", cb
);
1437 ok(expect_pv
<= pv
&& (BYTE
*)pv
< (BYTE
*)expect_pv
+ cb
, "pv != expect_pv\n");
1442 ok(pv
== expect_pv
, "pv != expect_pv\n");
1443 ok(cb
== 1000, "cb=%d\n", cb
);
1444 ok(!*pcbRead
, "*pcbRead = %d\n", *pcbRead
);
1446 ok(pcbRead
!= NULL
, "pcbRead == NULL\n");
1448 if(prot_state
== 3) {
1452 SET_EXPECT(MimeFilter_ReportResult
);
1454 SET_EXPECT(ReportResult
);
1455 hres
= IInternetProtocolSink_ReportResult(binding_sink
, S_OK
, ERROR_SUCCESS
, NULL
);
1456 ok(hres
== S_OK
, "ReportResult failed: %08x\n", hres
);
1458 CHECK_CALLED(MimeFilter_ReportResult
);
1460 CHECK_CALLED(ReportResult
);
1465 if((async_read_pending
= !async_read_pending
)) {
1467 return tested_protocol
== HTTP_TEST
|| tested_protocol
== HTTPS_TEST
? E_PENDING
: S_FALSE
;
1470 memset(pv
, 'x', 100);
1471 prot_read
+= *pcbRead
= 100;
1475 static HRESULT WINAPI
ProtocolEmul_LockRequest(IInternetProtocol
*iface
, DWORD dwOptions
)
1477 CHECK_EXPECT(LockRequest
);
1478 ok(dwOptions
== 0, "dwOptions=%x\n", dwOptions
);
1482 static HRESULT WINAPI
ProtocolEmul_UnlockRequest(IInternetProtocol
*iface
)
1484 CHECK_EXPECT(UnlockRequest
);
1488 static const IInternetProtocolVtbl ProtocolVtbl
= {
1489 ProtocolEmul_QueryInterface
,
1493 ProtocolEmul_Continue
,
1495 ProtocolEmul_Terminate
,
1500 ProtocolEmul_LockRequest
,
1501 ProtocolEmul_UnlockRequest
1504 static IInternetProtocol Protocol
= { &ProtocolVtbl
};
1506 static HRESULT WINAPI
MimeProtocol_QueryInterface(IInternetProtocol
*iface
, REFIID riid
, void **ppv
)
1508 if(IsEqualGUID(&IID_IUnknown
, riid
) || IsEqualGUID(&IID_IInternetProtocol
, riid
)) {
1513 if(IsEqualGUID(&IID_IInternetProtocolSink
, riid
)) {
1514 *ppv
= &mime_protocol_sink
;
1518 ok(0, "unexpected riid %s\n", debugstr_guid(riid
));
1520 return E_NOINTERFACE
;
1523 static HRESULT WINAPI
MimeProtocol_Start(IInternetProtocol
*iface
, LPCWSTR szUrl
,
1524 IInternetProtocolSink
*pOIProtSink
, IInternetBindInfo
*pOIBindInfo
,
1525 DWORD grfPI
, HANDLE_PTR dwReserved
)
1527 PROTOCOLFILTERDATA
*data
;
1528 LPOLESTR url_str
= NULL
;
1534 CHECK_EXPECT(MimeFilter_Start
);
1536 ok(!lstrcmpW(szUrl
, gzipW
), "wrong url %s\n", debugstr_w(szUrl
));
1537 ok(grfPI
== (PI_FILTER_MODE
|PI_FORCE_ASYNC
), "grfPI=%x, expected PI_FILTER_MODE|PI_FORCE_ASYNC\n", grfPI
);
1538 ok(dwReserved
, "dwReserved == 0\n");
1539 ok(pOIProtSink
!= NULL
, "pOIProtSink == NULL\n");
1540 ok(pOIBindInfo
!= NULL
, "pOIBindInfo == NULL\n");
1543 ok(pOIProtSink
!= binding_sink
, "pOIProtSink == protocol_sink\n");
1544 ok(pOIBindInfo
== prot_bind_info
, "pOIBindInfo != bind_info\n");
1546 ok(pOIProtSink
== &protocol_sink
, "pOIProtSink != protocol_sink\n");
1547 ok(pOIBindInfo
== &bind_info
, "pOIBindInfo != bind_info\n");
1550 data
= (void*)dwReserved
;
1551 ok(data
->cbSize
== sizeof(*data
), "data->cbSize = %d\n", data
->cbSize
);
1552 ok(!data
->pProtocolSink
, "data->pProtocolSink != NULL\n");
1553 ok(data
->pProtocol
!= NULL
, "data->pProtocol == NULL\n");
1554 ok(!data
->pUnk
, "data->pUnk != NULL\n");
1555 ok(!data
->dwFilterFlags
, "data->dwProtocolFlags = %x\n", data
->dwFilterFlags
);
1557 IInternetProtocolSink
*prot_sink
;
1559 IInternetProtocol_QueryInterface(data
->pProtocol
, &IID_IInternetProtocolSink
, (void**)&prot_sink
);
1560 ok(prot_sink
== pOIProtSink
, "QI(data->pProtocol, IID_IInternetProtocolSink) != pOIProtSink\n");
1561 IInternetProtocolSink_Release(prot_sink
);
1563 ok(data
->pProtocol
!= binding_protocol
, "data->pProtocol == binding_protocol\n");
1565 filtered_protocol
= data
->pProtocol
;
1566 IInternetProtocol_AddRef(filtered_protocol
);
1568 IInternetProtocol
*prot
;
1570 IInternetProtocol_QueryInterface(data
->pProtocol
, &IID_IInternetProtocol
, (void**)&prot
);
1571 ok(prot
== async_protocol
, "QI(data->pProtocol, IID_IInternetProtocol) != async_protocol\n");
1572 IInternetProtocol_Release(prot
);
1574 ok(data
->pProtocol
!= async_protocol
, "data->pProtocol == async_protocol\n");
1577 filtered_sink
= pOIProtSink
;
1579 SET_EXPECT(ReportProgress_DECODING
);
1580 hres
= IInternetProtocolSink_ReportProgress(pOIProtSink
, BINDSTATUS_DECODING
, gzipW
);
1581 ok(hres
== S_OK
, "ReportProgress(BINDSTATUS_DECODING) failed: %08x\n", hres
);
1582 CHECK_CALLED(ReportProgress_DECODING
);
1584 SET_EXPECT(GetBindInfo
);
1585 memset(&bindinfo
, 0, sizeof(bindinfo
));
1586 bindinfo
.cbSize
= sizeof(bindinfo
);
1587 hres
= IInternetBindInfo_GetBindInfo(pOIBindInfo
, &cbindf
, &bindinfo
);
1588 ok(hres
== S_OK
, "GetBindInfo failed: %08x\n", hres
);
1589 ok(cbindf
== bindf
, "cbindf = %x\n", cbindf
);
1590 CHECK_CALLED(GetBindInfo
);
1592 SET_EXPECT(GetBindString_URL
);
1593 hres
= IInternetBindInfo_GetBindString(pOIBindInfo
, BINDSTRING_URL
, &url_str
, 1, &fetched
);
1594 ok(hres
== S_OK
, "GetBindString(BINDSTRING_URL) failed: %08x\n", hres
);
1595 ok(fetched
== 1, "fetched = %d\n", fetched
);
1596 ok(!lstrcmpW(url_str
, binding_urls
[tested_protocol
]), "wrong url_str %s\n", debugstr_w(url_str
));
1597 CoTaskMemFree(url_str
);
1598 CHECK_CALLED(GetBindString_URL
);
1603 static HRESULT WINAPI
Protocol_Continue(IInternetProtocol
*iface
,
1604 PROTOCOLDATA
*pProtocolData
)
1606 CHECK_EXPECT(MimeFilter_Continue
);
1610 static HRESULT WINAPI
MimeProtocol_Terminate(IInternetProtocol
*iface
, DWORD dwOptions
)
1614 CHECK_EXPECT(MimeFilter_Terminate
);
1616 ok(!dwOptions
, "dwOptions = %x\n", dwOptions
);
1618 SET_EXPECT(Terminate
);
1619 hres
= IInternetProtocol_Terminate(filtered_protocol
, dwOptions
);
1620 ok(hres
== S_OK
, "Terminate failed: %08x\n", hres
);
1621 CHECK_CALLED(Terminate
);
1626 static HRESULT WINAPI
MimeProtocol_Read(IInternetProtocol
*iface
, void *pv
,
1627 ULONG cb
, ULONG
*pcbRead
)
1633 CHECK_EXPECT(MimeFilter_Read
);
1635 ok(pv
!= NULL
, "pv == NULL\n");
1636 ok(cb
!= 0, "cb == 0\n");
1637 ok(pcbRead
!= NULL
, "pcbRead == NULL\n");
1640 hres
= IInternetProtocol_Read(filtered_protocol
, buf
, sizeof(buf
), &read
);
1641 ok(hres
== S_OK
|| hres
== S_FALSE
|| hres
== E_PENDING
, "Read failed: %08x\n", hres
);
1645 ok(*pcbRead
== 0, "*pcbRead=%d, expected 0\n", *pcbRead
);
1649 memset(pv
, 'x', read
);
1653 static HRESULT WINAPI
MimeProtocol_LockRequest(IInternetProtocol
*iface
, DWORD dwOptions
)
1657 CHECK_EXPECT(MimeFilter_LockRequest
);
1659 ok(!dwOptions
, "dwOptions = %x\n", dwOptions
);
1661 SET_EXPECT(LockRequest
);
1662 hres
= IInternetProtocol_LockRequest(filtered_protocol
, dwOptions
);
1663 ok(hres
== S_OK
, "LockRequest failed: %08x\n", hres
);
1664 CHECK_CALLED(LockRequest
);
1669 static HRESULT WINAPI
MimeProtocol_UnlockRequest(IInternetProtocol
*iface
)
1673 CHECK_EXPECT(MimeFilter_UnlockRequest
);
1675 SET_EXPECT(UnlockRequest
);
1676 hres
= IInternetProtocol_UnlockRequest(filtered_protocol
);
1677 ok(hres
== S_OK
, "UnlockRequest failed: %08x\n", hres
);
1678 CHECK_CALLED(UnlockRequest
);
1683 static const IInternetProtocolVtbl MimeProtocolVtbl
= {
1684 MimeProtocol_QueryInterface
,
1690 MimeProtocol_Terminate
,
1695 MimeProtocol_LockRequest
,
1696 MimeProtocol_UnlockRequest
1699 static IInternetProtocol MimeProtocol
= { &MimeProtocolVtbl
};
1701 static HRESULT WINAPI
ClassFactory_QueryInterface(IClassFactory
*iface
, REFIID riid
, void **ppv
)
1703 ok(0, "unexpected call\n");
1704 return E_NOINTERFACE
;
1707 static ULONG WINAPI
ClassFactory_AddRef(IClassFactory
*iface
)
1712 static ULONG WINAPI
ClassFactory_Release(IClassFactory
*iface
)
1717 static HRESULT WINAPI
ClassFactory_CreateInstance(IClassFactory
*iface
, IUnknown
*pOuter
,
1718 REFIID riid
, void **ppv
)
1720 CHECK_EXPECT(CreateInstance
);
1722 ok(pOuter
== (IUnknown
*)prot_bind_info
, "pOuter != protocol_unk\n");
1723 ok(IsEqualGUID(&IID_IUnknown
, riid
), "unexpected riid %s\n", debugstr_guid(riid
));
1724 ok(ppv
!= NULL
, "ppv == NULL\n");
1730 static HRESULT WINAPI
ClassFactory_LockServer(IClassFactory
*iface
, BOOL dolock
)
1732 ok(0, "unexpected call\n");
1736 static const IClassFactoryVtbl ClassFactoryVtbl
= {
1737 ClassFactory_QueryInterface
,
1738 ClassFactory_AddRef
,
1739 ClassFactory_Release
,
1740 ClassFactory_CreateInstance
,
1741 ClassFactory_LockServer
1744 static IClassFactory ClassFactory
= { &ClassFactoryVtbl
};
1746 static HRESULT WINAPI
MimeFilter_CreateInstance(IClassFactory
*iface
, IUnknown
*outer
, REFIID riid
, void **ppv
)
1748 CHECK_EXPECT(MimeFilter_CreateInstance
);
1750 ok(!outer
, "outer = %p\n", outer
);
1751 ok(IsEqualGUID(&IID_IInternetProtocol
, riid
), "unexpected riid %s\n", debugstr_guid(riid
));
1753 *ppv
= &MimeProtocol
;
1757 static const IClassFactoryVtbl MimeFilterCFVtbl
= {
1758 ClassFactory_QueryInterface
,
1759 ClassFactory_AddRef
,
1760 ClassFactory_Release
,
1761 MimeFilter_CreateInstance
,
1762 ClassFactory_LockServer
1765 static IClassFactory mimefilter_cf
= { &MimeFilterCFVtbl
};
1767 #define TEST_BINDING 1
1768 #define TEST_FILTER 2
1770 static void init_test(int prot
, DWORD flags
)
1772 tested_protocol
= prot
;
1773 binding_test
= (flags
& TEST_BINDING
) != 0;
1774 first_data_notif
= TRUE
;
1777 async_read_pending
= TRUE
;
1778 mimefilter_test
= (flags
& TEST_FILTER
) != 0;
1780 ResetEvent(event_complete
);
1781 ResetEvent(event_complete2
);
1782 async_protocol
= binding_protocol
= filtered_protocol
= NULL
;
1783 filtered_sink
= NULL
;
1786 static void test_priority(IInternetProtocol
*protocol
)
1788 IInternetPriority
*priority
;
1792 hres
= IInternetProtocol_QueryInterface(protocol
, &IID_IInternetPriority
,
1794 ok(hres
== S_OK
, "QueryInterface(IID_IInternetPriority) failed: %08x\n", hres
);
1798 hres
= IInternetPriority_GetPriority(priority
, &pr
);
1799 ok(hres
== S_OK
, "GetPriority failed: %08x\n", hres
);
1800 ok(pr
== 0, "pr=%d, expected 0\n", pr
);
1802 hres
= IInternetPriority_SetPriority(priority
, 1);
1803 ok(hres
== S_OK
, "SetPriority failed: %08x\n", hres
);
1805 hres
= IInternetPriority_GetPriority(priority
, &pr
);
1806 ok(hres
== S_OK
, "GetPriority failed: %08x\n", hres
);
1807 ok(pr
== 1, "pr=%d, expected 1\n", pr
);
1809 IInternetPriority_Release(priority
);
1812 static BOOL
file_protocol_start(IInternetProtocol
*protocol
, LPCWSTR url
, BOOL is_first
)
1816 SET_EXPECT(GetBindInfo
);
1817 if(!(bindf
& BINDF_FROMURLMON
))
1818 SET_EXPECT(ReportProgress_DIRECTBIND
);
1820 SET_EXPECT(ReportProgress_SENDINGREQUEST
);
1821 SET_EXPECT(ReportProgress_CACHEFILENAMEAVAILABLE
);
1822 if(bindf
& BINDF_FROMURLMON
)
1823 SET_EXPECT(ReportProgress_VERIFIEDMIMETYPEAVAILABLE
);
1825 SET_EXPECT(ReportProgress_MIMETYPEAVAILABLE
);
1827 SET_EXPECT(ReportData
);
1829 SET_EXPECT(ReportResult
);
1831 expect_hrResult
= S_OK
;
1833 hres
= IInternetProtocol_Start(protocol
, url
, &protocol_sink
, &bind_info
, 0, 0);
1834 if(hres
== INET_E_RESOURCE_NOT_FOUND
) {
1835 win_skip("Start failed\n");
1838 ok(hres
== S_OK
, "Start failed: %08x\n", hres
);
1840 CHECK_CALLED(GetBindInfo
);
1841 if(!(bindf
& BINDF_FROMURLMON
))
1842 CHECK_CALLED(ReportProgress_DIRECTBIND
);
1844 CHECK_CALLED(ReportProgress_SENDINGREQUEST
);
1845 CHECK_CALLED(ReportProgress_CACHEFILENAMEAVAILABLE
);
1846 if(bindf
& BINDF_FROMURLMON
)
1847 CHECK_CALLED(ReportProgress_VERIFIEDMIMETYPEAVAILABLE
);
1849 CHECK_CALLED(ReportProgress_MIMETYPEAVAILABLE
);
1851 CHECK_CALLED(ReportData
);
1853 CHECK_CALLED(ReportResult
);
1858 static void test_file_protocol_url(LPCWSTR url
)
1860 IInternetProtocolInfo
*protocol_info
;
1862 IClassFactory
*factory
;
1865 hres
= CoGetClassObject(&CLSID_FileProtocol
, CLSCTX_INPROC_SERVER
, NULL
,
1866 &IID_IUnknown
, (void**)&unk
);
1867 ok(hres
== S_OK
, "CoGetClassObject failed: %08x\n", hres
);
1871 hres
= IUnknown_QueryInterface(unk
, &IID_IInternetProtocolInfo
, (void**)&protocol_info
);
1872 ok(hres
== E_NOINTERFACE
,
1873 "Could not get IInternetProtocolInfo interface: %08x, expected E_NOINTERFACE\n", hres
);
1875 hres
= IUnknown_QueryInterface(unk
, &IID_IClassFactory
, (void**)&factory
);
1876 ok(hres
== S_OK
, "Could not get IClassFactory interface\n");
1877 if(SUCCEEDED(hres
)) {
1878 IInternetProtocol
*protocol
;
1881 hres
= IClassFactory_CreateInstance(factory
, NULL
, &IID_IInternetProtocol
, (void**)&protocol
);
1882 ok(hres
== S_OK
, "Could not get IInternetProtocol: %08x\n", hres
);
1884 if(SUCCEEDED(hres
)) {
1885 if(file_protocol_start(protocol
, url
, TRUE
)) {
1886 hres
= IInternetProtocol_Read(protocol
, buf
, 2, &cb
);
1887 ok(hres
== S_OK
, "Read failed: %08x\n", hres
);
1888 ok(cb
== 2, "cb=%u expected 2\n", cb
);
1889 hres
= IInternetProtocol_Read(protocol
, buf
, sizeof(buf
), &cb
);
1890 ok(hres
== S_FALSE
, "Read failed: %08x\n", hres
);
1891 hres
= IInternetProtocol_Read(protocol
, buf
, sizeof(buf
), &cb
);
1892 ok(hres
== S_FALSE
, "Read failed: %08x expected S_FALSE\n", hres
);
1893 ok(cb
== 0, "cb=%u expected 0\n", cb
);
1894 hres
= IInternetProtocol_UnlockRequest(protocol
);
1895 ok(hres
== S_OK
, "UnlockRequest failed: %08x\n", hres
);
1898 if(file_protocol_start(protocol
, url
, FALSE
)) {
1899 hres
= IInternetProtocol_Read(protocol
, buf
, 2, &cb
);
1900 ok(hres
== S_FALSE
, "Read failed: %08x\n", hres
);
1901 hres
= IInternetProtocol_LockRequest(protocol
, 0);
1902 ok(hres
== S_OK
, "LockRequest failed: %08x\n", hres
);
1903 hres
= IInternetProtocol_UnlockRequest(protocol
);
1904 ok(hres
== S_OK
, "UnlockRequest failed: %08x\n", hres
);
1907 IInternetProtocol_Release(protocol
);
1910 hres
= IClassFactory_CreateInstance(factory
, NULL
, &IID_IInternetProtocol
, (void**)&protocol
);
1911 ok(hres
== S_OK
, "Could not get IInternetProtocol: %08x\n", hres
);
1913 if(SUCCEEDED(hres
)) {
1914 if(file_protocol_start(protocol
, url
, TRUE
)) {
1915 hres
= IInternetProtocol_LockRequest(protocol
, 0);
1916 ok(hres
== S_OK
, "LockRequest failed: %08x\n", hres
);
1917 hres
= IInternetProtocol_Terminate(protocol
, 0);
1918 ok(hres
== S_OK
, "Terminate failed: %08x\n", hres
);
1919 hres
= IInternetProtocol_Read(protocol
, buf
, 2, &cb
);
1920 ok(hres
== S_OK
, "Read failed: %08x\n\n", hres
);
1921 hres
= IInternetProtocol_UnlockRequest(protocol
);
1922 ok(hres
== S_OK
, "UnlockRequest failed: %08x\n", hres
);
1923 hres
= IInternetProtocol_Read(protocol
, buf
, 2, &cb
);
1924 ok(hres
== S_OK
, "Read failed: %08x\n", hres
);
1925 hres
= IInternetProtocol_Terminate(protocol
, 0);
1926 ok(hres
== S_OK
, "Terminate failed: %08x\n", hres
);
1929 IInternetProtocol_Release(protocol
);
1932 hres
= IClassFactory_CreateInstance(factory
, NULL
, &IID_IInternetProtocol
, (void**)&protocol
);
1933 ok(hres
== S_OK
, "Could not get IInternetProtocol: %08x\n", hres
);
1935 if(SUCCEEDED(hres
)) {
1936 if(file_protocol_start(protocol
, url
, TRUE
)) {
1937 hres
= IInternetProtocol_Terminate(protocol
, 0);
1938 ok(hres
== S_OK
, "Terminate failed: %08x\n", hres
);
1939 hres
= IInternetProtocol_Read(protocol
, buf
, 2, &cb
);
1940 ok(hres
== S_OK
, "Read failed: %08x\n", hres
);
1941 ok(cb
== 2, "cb=%u expected 2\n", cb
);
1944 IInternetProtocol_Release(protocol
);
1947 IClassFactory_Release(factory
);
1950 IUnknown_Release(unk
);
1953 static void test_file_protocol_fail(void)
1955 IInternetProtocol
*protocol
;
1958 static const WCHAR index_url2
[] =
1959 {'f','i','l','e',':','/','/','i','n','d','e','x','.','h','t','m','l',0};
1961 hres
= CoCreateInstance(&CLSID_FileProtocol
, NULL
, CLSCTX_INPROC_SERVER
|CLSCTX_INPROC_HANDLER
,
1962 &IID_IInternetProtocol
, (void**)&protocol
);
1963 ok(hres
== S_OK
, "CoCreateInstance failed: %08x\n", hres
);
1967 SET_EXPECT(GetBindInfo
);
1968 expect_hrResult
= MK_E_SYNTAX
;
1969 hres
= IInternetProtocol_Start(protocol
, wszIndexHtml
, &protocol_sink
, &bind_info
, 0, 0);
1970 ok(hres
== MK_E_SYNTAX
||
1971 hres
== E_INVALIDARG
,
1972 "Start failed: %08x, expected MK_E_SYNTAX or E_INVALIDARG\n", hres
);
1973 CLEAR_CALLED(GetBindInfo
); /* GetBindInfo not called in IE7 */
1975 SET_EXPECT(GetBindInfo
);
1976 if(!(bindf
& BINDF_FROMURLMON
))
1977 SET_EXPECT(ReportProgress_DIRECTBIND
);
1978 SET_EXPECT(ReportProgress_SENDINGREQUEST
);
1979 SET_EXPECT(ReportResult
);
1980 expect_hrResult
= INET_E_RESOURCE_NOT_FOUND
;
1981 hres
= IInternetProtocol_Start(protocol
, index_url
, &protocol_sink
, &bind_info
, 0, 0);
1982 ok(hres
== INET_E_RESOURCE_NOT_FOUND
,
1983 "Start failed: %08x expected INET_E_RESOURCE_NOT_FOUND\n", hres
);
1984 CHECK_CALLED(GetBindInfo
);
1985 if(!(bindf
& BINDF_FROMURLMON
))
1986 CHECK_CALLED(ReportProgress_DIRECTBIND
);
1987 CHECK_CALLED(ReportProgress_SENDINGREQUEST
);
1988 CHECK_CALLED(ReportResult
);
1990 IInternetProtocol_Release(protocol
);
1992 hres
= CoCreateInstance(&CLSID_FileProtocol
, NULL
, CLSCTX_INPROC_SERVER
|CLSCTX_INPROC_HANDLER
,
1993 &IID_IInternetProtocol
, (void**)&protocol
);
1994 ok(hres
== S_OK
, "CoCreateInstance failed: %08x\n", hres
);
1998 SET_EXPECT(GetBindInfo
);
1999 if(!(bindf
& BINDF_FROMURLMON
))
2000 SET_EXPECT(ReportProgress_DIRECTBIND
);
2001 SET_EXPECT(ReportProgress_SENDINGREQUEST
);
2002 SET_EXPECT(ReportResult
);
2003 expect_hrResult
= INET_E_RESOURCE_NOT_FOUND
;
2005 hres
= IInternetProtocol_Start(protocol
, index_url2
, &protocol_sink
, &bind_info
, 0, 0);
2006 ok(hres
== INET_E_RESOURCE_NOT_FOUND
,
2007 "Start failed: %08x, expected INET_E_RESOURCE_NOT_FOUND\n", hres
);
2008 CHECK_CALLED(GetBindInfo
);
2009 if(!(bindf
& BINDF_FROMURLMON
))
2010 CHECK_CALLED(ReportProgress_DIRECTBIND
);
2011 CHECK_CALLED(ReportProgress_SENDINGREQUEST
);
2012 CHECK_CALLED(ReportResult
);
2014 SET_EXPECT(GetBindInfo
);
2015 hres
= IInternetProtocol_Start(protocol
, NULL
, &protocol_sink
, &bind_info
, 0, 0);
2016 ok(hres
== E_INVALIDARG
, "Start failed: %08x, expected E_INVALIDARG\n", hres
);
2017 CLEAR_CALLED(GetBindInfo
); /* GetBindInfo not called in IE7 */
2019 SET_EXPECT(GetBindInfo
);
2020 hres
= IInternetProtocol_Start(protocol
, emptyW
, &protocol_sink
, &bind_info
, 0, 0);
2021 ok(hres
== E_INVALIDARG
, "Start failed: %08x, expected E_INVALIDARG\n", hres
);
2022 CLEAR_CALLED(GetBindInfo
); /* GetBindInfo not called in IE7 */
2024 IInternetProtocol_Release(protocol
);
2027 static void test_file_protocol(void) {
2028 WCHAR buf
[INTERNET_MAX_URL_LENGTH
], file_name_buf
[MAX_PATH
];
2033 static const WCHAR wszFile
[] = {'f','i','l','e',':',0};
2034 static const WCHAR wszFile2
[] = {'f','i','l','e',':','/','/',0};
2035 static const WCHAR wszFile3
[] = {'f','i','l','e',':','/','/','/',0};
2036 static const char html_doc
[] = "<HTML></HTML>";
2038 trace("Testing file protocol...\n");
2039 init_test(FILE_TEST
, 0);
2041 SetLastError(0xdeadbeef);
2042 file
= CreateFileW(wszIndexHtml
, GENERIC_WRITE
, 0, NULL
, CREATE_ALWAYS
,
2043 FILE_ATTRIBUTE_NORMAL
, NULL
);
2044 if(!file
&& GetLastError() == ERROR_CALL_NOT_IMPLEMENTED
)
2046 win_skip("Detected Win9x or WinMe\n");
2049 ok(file
!= INVALID_HANDLE_VALUE
, "CreateFile failed\n");
2050 if(file
== INVALID_HANDLE_VALUE
)
2052 WriteFile(file
, html_doc
, sizeof(html_doc
)-1, &size
, NULL
);
2055 file_name
= wszIndexHtml
;
2057 test_file_protocol_url(index_url
);
2058 bindf
= BINDF_FROMURLMON
;
2059 test_file_protocol_url(index_url
);
2060 bindf
= BINDF_FROMURLMON
| BINDF_NEEDFILE
;
2061 test_file_protocol_url(index_url
);
2063 memcpy(buf
, wszFile
, sizeof(wszFile
));
2064 len
= sizeof(wszFile
)/sizeof(WCHAR
)-1;
2065 len
+= GetCurrentDirectoryW(sizeof(buf
)/sizeof(WCHAR
)-len
, buf
+len
);
2067 memcpy(buf
+len
, wszIndexHtml
, sizeof(wszIndexHtml
));
2069 file_name
= buf
+ sizeof(wszFile
)/sizeof(WCHAR
)-1;
2071 test_file_protocol_url(buf
);
2072 bindf
= BINDF_FROMURLMON
;
2073 test_file_protocol_url(buf
);
2075 memcpy(buf
, wszFile2
, sizeof(wszFile2
));
2076 len
= GetCurrentDirectoryW(sizeof(file_name_buf
)/sizeof(WCHAR
), file_name_buf
);
2077 file_name_buf
[len
++] = '\\';
2078 memcpy(file_name_buf
+len
, wszIndexHtml
, sizeof(wszIndexHtml
));
2079 lstrcpyW(buf
+sizeof(wszFile2
)/sizeof(WCHAR
)-1, file_name_buf
);
2080 file_name
= file_name_buf
;
2082 test_file_protocol_url(buf
);
2083 bindf
= BINDF_FROMURLMON
;
2084 test_file_protocol_url(buf
);
2086 buf
[sizeof(wszFile2
)/sizeof(WCHAR
)] = '|';
2087 test_file_protocol_url(buf
);
2089 memcpy(buf
, wszFile3
, sizeof(wszFile3
));
2090 len
= sizeof(wszFile3
)/sizeof(WCHAR
)-1;
2091 len
+= GetCurrentDirectoryW(sizeof(buf
)/sizeof(WCHAR
)-len
, buf
+len
);
2093 memcpy(buf
+len
, wszIndexHtml
, sizeof(wszIndexHtml
));
2095 file_name
= buf
+ sizeof(wszFile3
)/sizeof(WCHAR
)-1;
2097 test_file_protocol_url(buf
);
2098 bindf
= BINDF_FROMURLMON
;
2099 test_file_protocol_url(buf
);
2101 DeleteFileW(wszIndexHtml
);
2104 test_file_protocol_fail();
2105 bindf
= BINDF_FROMURLMON
;
2106 test_file_protocol_fail();
2109 static BOOL
http_protocol_start(LPCWSTR url
, BOOL is_first
)
2111 static BOOL got_user_agent
= FALSE
;
2114 first_data_notif
= TRUE
;
2117 SET_EXPECT(GetBindInfo
);
2118 if (!(bindf
& BINDF_FROMURLMON
))
2119 SET_EXPECT(ReportProgress_DIRECTBIND
);
2120 SET_EXPECT(GetBindString_USER_AGENT
);
2121 SET_EXPECT(GetBindString_ACCEPT_MIMES
);
2122 SET_EXPECT(QueryService_HttpNegotiate
);
2123 SET_EXPECT(BeginningTransaction
);
2124 SET_EXPECT(GetRootSecurityId
);
2126 SET_EXPECT(GetBindString_POST_COOKIE
);
2128 hres
= IInternetProtocol_Start(async_protocol
, url
, &protocol_sink
, &bind_info
, 0, 0);
2129 ok(hres
== S_OK
, "Start failed: %08x\n", hres
);
2133 CHECK_CALLED(GetBindInfo
);
2134 if (!(bindf
& BINDF_FROMURLMON
))
2135 CHECK_CALLED(ReportProgress_DIRECTBIND
);
2136 if (!got_user_agent
)
2138 CHECK_CALLED(GetBindString_USER_AGENT
);
2139 got_user_agent
= TRUE
;
2143 /* user agent only retrieved once, even with different URLs */
2144 CHECK_NOT_CALLED(GetBindString_USER_AGENT
);
2146 CHECK_CALLED(GetBindString_ACCEPT_MIMES
);
2147 CHECK_CALLED(QueryService_HttpNegotiate
);
2148 CHECK_CALLED(BeginningTransaction
);
2149 /* GetRootSecurityId called on WinXP but not on Win98 */
2150 CLEAR_CALLED(GetRootSecurityId
);
2152 CHECK_CALLED(GetBindString_POST_COOKIE
);
2157 static void test_protocol_terminate(IInternetProtocol
*protocol
)
2163 hres
= IInternetProtocol_LockRequest(protocol
, 0);
2164 ok(hres
== S_OK
, "LockRequest failed: %08x\n", hres
);
2166 hres
= IInternetProtocol_Read(protocol
, buf
, 1, &cb
);
2167 ok(hres
== S_FALSE
, "Read failed: %08x\n", hres
);
2169 hres
= IInternetProtocol_Terminate(protocol
, 0);
2170 ok(hres
== S_OK
, "Terminate failed: %08x\n", hres
);
2172 /* This wait is to give the internet handles being freed in Terminate
2173 * enough time to actually terminate in all cases. Internet handles
2174 * terminate asynchronously and native reuses the main InternetOpen
2175 * handle. The only case in which this seems to be necessary is on
2176 * wine with native wininet and urlmon, resulting in the next time
2177 * test_http_protocol_url being called the first data notification actually
2178 * being an extra last data notification from the previous connection
2179 * about once out of every ten times. */
2182 hres
= IInternetProtocol_UnlockRequest(protocol
);
2183 ok(hres
== S_OK
, "UnlockRequest failed: %08x\n", hres
);
2186 static void test_http_info(IInternetProtocol
*protocol
)
2188 IWinInetHttpInfo
*info
;
2191 hres
= IInternetProtocol_QueryInterface(protocol
, &IID_IWinInetHttpInfo
, (void**)&info
);
2192 ok(hres
== S_OK
, "Could not get IWinInterHttpInfo iface: %08x\n", hres
);
2196 IWinInetHttpInfo_Release(info
);
2199 /* is_first refers to whether this is the first call to this function
2201 static void test_http_protocol_url(LPCWSTR url
, BOOL is_https
, BOOL is_first
)
2203 IInternetProtocolInfo
*protocol_info
;
2204 IClassFactory
*factory
;
2209 http_is_first
= is_first
;
2211 hres
= CoGetClassObject(is_https
? &CLSID_HttpSProtocol
: &CLSID_HttpProtocol
,
2212 CLSCTX_INPROC_SERVER
, NULL
, &IID_IUnknown
, (void**)&unk
);
2213 ok(hres
== S_OK
, "CoGetClassObject failed: %08x\n", hres
);
2217 hres
= IUnknown_QueryInterface(unk
, &IID_IInternetProtocolInfo
, (void**)&protocol_info
);
2218 ok(hres
== E_NOINTERFACE
,
2219 "Could not get IInternetProtocolInfo interface: %08x, expected E_NOINTERFACE\n",
2222 hres
= IUnknown_QueryInterface(unk
, &IID_IClassFactory
, (void**)&factory
);
2223 ok(hres
== S_OK
, "Could not get IClassFactory interface\n");
2224 IUnknown_Release(unk
);
2228 hres
= IClassFactory_CreateInstance(factory
, NULL
, &IID_IInternetProtocol
,
2229 (void**)&async_protocol
);
2230 ok(hres
== S_OK
, "Could not get IInternetProtocol: %08x\n", hres
);
2231 if(SUCCEEDED(hres
)) {
2236 test_priority(async_protocol
);
2237 test_http_info(async_protocol
);
2239 SET_EXPECT(ReportProgress_FINDINGRESOURCE
);
2240 SET_EXPECT(ReportProgress_CONNECTING
);
2241 SET_EXPECT(ReportProgress_SENDINGREQUEST
);
2242 SET_EXPECT(ReportProgress_PROXYDETECTING
);
2244 SET_EXPECT(ReportProgress_CACHEFILENAMEAVAILABLE
);
2246 SET_EXPECT(QueryService_HttpSecurity
);
2247 if(!(bindf
& BINDF_FROMURLMON
)) {
2248 SET_EXPECT(OnResponse
);
2249 SET_EXPECT(ReportProgress_RAWMIMETYPE
);
2250 SET_EXPECT(ReportData
);
2255 if(!http_protocol_start(url
, is_first
))
2258 SET_EXPECT(ReportResult
);
2259 expect_hrResult
= S_OK
;
2261 hres
= IInternetProtocol_Read(async_protocol
, buf
, 1, &cb
);
2262 ok((hres
== E_PENDING
&& cb
==0) ||
2263 (hres
== S_OK
&& cb
==1), "Read failed: %08x (%d bytes)\n", hres
, cb
);
2265 WaitForSingleObject(event_complete
, INFINITE
);
2266 if(bindf
& BINDF_FROMURLMON
)
2267 CHECK_CALLED(Switch
);
2269 CHECK_CALLED(ReportData
);
2271 CLEAR_CALLED(QueryService_HttpSecurity
);
2274 if(bindf
& BINDF_FROMURLMON
)
2277 SET_EXPECT(ReportData
);
2278 hres
= IInternetProtocol_Read(async_protocol
, buf
, sizeof(buf
), &cb
);
2279 if(hres
== E_PENDING
) {
2280 hres
= IInternetProtocol_Read(async_protocol
, buf
, 1, &cb
);
2281 ok((hres
== E_PENDING
&& cb
==0) ||
2282 (hres
== S_OK
&& cb
==1), "Read failed: %08x (%d bytes)\n", hres
, cb
);
2283 WaitForSingleObject(event_complete
, INFINITE
);
2284 if(bindf
& BINDF_FROMURLMON
)
2285 CHECK_CALLED(Switch
);
2287 CHECK_CALLED(ReportData
);
2289 if(bindf
& BINDF_FROMURLMON
)
2290 CHECK_NOT_CALLED(Switch
);
2292 CHECK_NOT_CALLED(ReportData
);
2296 ok(hres
== S_FALSE
, "Read failed: %08x\n", hres
);
2297 CHECK_CALLED(ReportResult
);
2299 CLEAR_CALLED(ReportProgress_SENDINGREQUEST
);
2301 test_protocol_terminate(async_protocol
);
2302 ref
= IInternetProtocol_Release(async_protocol
);
2303 ok(!ref
, "ref=%x\n", hres
);
2306 IClassFactory_Release(factory
);
2309 static void test_http_protocol(void)
2311 static const WCHAR winehq_url
[] =
2312 {'h','t','t','p',':','/','/','w','w','w','.','w','i','n','e','h','q','.',
2313 'o','r','g','/','s','i','t','e','/','a','b','o','u','t',0};
2314 static const WCHAR posttest_url
[] =
2315 {'h','t','t','p',':','/','/','c','r','o','s','s','o','v','e','r','.',
2316 'c','o','d','e','w','e','a','v','e','r','s','.','c','o','m','/',
2317 'p','o','s','t','t','e','s','t','.','p','h','p',0};
2319 trace("Testing http protocol (not from urlmon)...\n");
2320 tested_protocol
= HTTP_TEST
;
2321 bindf
= BINDF_ASYNCHRONOUS
| BINDF_ASYNCSTORAGE
| BINDF_PULLDATA
;
2322 test_http_protocol_url(winehq_url
, FALSE
, TRUE
);
2324 trace("Testing http protocol (from urlmon)...\n");
2325 bindf
= BINDF_ASYNCHRONOUS
| BINDF_ASYNCSTORAGE
| BINDF_PULLDATA
| BINDF_FROMURLMON
;
2326 test_http_protocol_url(winehq_url
, FALSE
, FALSE
);
2328 trace("Testing http protocol (to file)...\n");
2329 bindf
= BINDF_ASYNCHRONOUS
| BINDF_ASYNCSTORAGE
| BINDF_PULLDATA
| BINDF_FROMURLMON
| BINDF_NEEDFILE
;
2330 test_http_protocol_url(winehq_url
, FALSE
, FALSE
);
2332 trace("Testing http protocol (post data)...\n");
2333 http_post_test
= TRUE
;
2334 /* Without this flag we get a ReportProgress_CACHEFILENAMEAVAILABLE
2335 * notification with BINDVERB_POST */
2336 bindf
= BINDF_ASYNCHRONOUS
| BINDF_ASYNCSTORAGE
| BINDF_PULLDATA
| BINDF_FROMURLMON
| BINDF_NOWRITECACHE
;
2337 test_http_protocol_url(posttest_url
, FALSE
, TRUE
);
2338 http_post_test
= FALSE
;
2341 static void test_https_protocol(void)
2343 static const WCHAR codeweavers_url
[] =
2344 {'h','t','t','p','s',':','/','/','w','w','w','.','c','o','d','e','w','e','a','v','e','r','s',
2345 '.','c','o','m','/','t','e','s','t','.','h','t','m','l',0};
2347 trace("Testing https protocol (from urlmon)...\n");
2348 init_test(HTTPS_TEST
, 0);
2349 bindf
= BINDF_ASYNCHRONOUS
| BINDF_ASYNCSTORAGE
| BINDF_PULLDATA
| BINDF_FROMURLMON
| BINDF_NOWRITECACHE
;
2350 test_http_protocol_url(codeweavers_url
, TRUE
, TRUE
);
2354 static void test_ftp_protocol(void)
2356 IInternetProtocolInfo
*protocol_info
;
2357 IClassFactory
*factory
;
2364 static const WCHAR ftp_urlW
[] = {'f','t','p',':','/','/','f','t','p','.','w','i','n','e','h','q','.','o','r','g',
2365 '/','p','u','b','/','o','t','h','e','r','/',
2366 'w','i','n','e','l','o','g','o','.','x','c','f','.','t','a','r','.','b','z','2',0};
2368 trace("Testing ftp protocol...\n");
2370 bindf
= BINDF_ASYNCHRONOUS
| BINDF_ASYNCSTORAGE
| BINDF_PULLDATA
| BINDF_FROMURLMON
| BINDF_NOWRITECACHE
;
2372 tested_protocol
= FTP_TEST
;
2373 first_data_notif
= TRUE
;
2374 expect_hrResult
= E_PENDING
;
2376 hres
= CoGetClassObject(&CLSID_FtpProtocol
, CLSCTX_INPROC_SERVER
, NULL
, &IID_IUnknown
, (void**)&unk
);
2377 ok(hres
== S_OK
, "CoGetClassObject failed: %08x\n", hres
);
2381 hres
= IUnknown_QueryInterface(unk
, &IID_IInternetProtocolInfo
, (void**)&protocol_info
);
2382 ok(hres
== E_NOINTERFACE
, "Could not get IInternetProtocolInfo interface: %08x, expected E_NOINTERFACE\n", hres
);
2384 hres
= IUnknown_QueryInterface(unk
, &IID_IClassFactory
, (void**)&factory
);
2385 ok(hres
== S_OK
, "Could not get IClassFactory interface\n");
2386 IUnknown_Release(unk
);
2390 hres
= IClassFactory_CreateInstance(factory
, NULL
, &IID_IInternetProtocol
,
2391 (void**)&async_protocol
);
2392 IClassFactory_Release(factory
);
2393 ok(hres
== S_OK
, "Could not get IInternetProtocol: %08x\n", hres
);
2395 test_priority(async_protocol
);
2396 test_http_info(async_protocol
);
2398 SET_EXPECT(GetBindInfo
);
2399 SET_EXPECT(GetBindString_USER_AGENT
);
2400 SET_EXPECT(ReportProgress_FINDINGRESOURCE
);
2401 SET_EXPECT(ReportProgress_CONNECTING
);
2402 SET_EXPECT(ReportProgress_SENDINGREQUEST
);
2405 hres
= IInternetProtocol_Start(async_protocol
, ftp_urlW
, &protocol_sink
, &bind_info
, 0, 0);
2406 ok(hres
== S_OK
, "Start failed: %08x\n", hres
);
2407 CHECK_CALLED(GetBindInfo
);
2408 todo_wine
CHECK_NOT_CALLED(GetBindString_USER_AGENT
);
2410 SET_EXPECT(ReportResult
);
2412 hres
= IInternetProtocol_Read(async_protocol
, buf
, 1, &cb
);
2413 ok((hres
== E_PENDING
&& cb
==0) ||
2414 (hres
== S_OK
&& cb
==1), "Read failed: %08x (%d bytes)\n", hres
, cb
);
2416 WaitForSingleObject(event_complete
, INFINITE
);
2420 hres
= IInternetProtocol_Read(async_protocol
, buf
, sizeof(buf
), &cb
);
2421 if(hres
== E_PENDING
)
2422 WaitForSingleObject(event_complete
, INFINITE
);
2427 ok(hres
== S_FALSE
, "Read failed: %08x\n", hres
);
2428 CHECK_CALLED(ReportResult
);
2429 CHECK_CALLED(Switch
);
2431 test_protocol_terminate(async_protocol
);
2433 ref
= IInternetProtocol_Release(async_protocol
);
2434 ok(!ref
, "ref=%d\n", ref
);
2437 static void test_gopher_protocol(void)
2439 IInternetProtocolInfo
*protocol_info
;
2440 IClassFactory
*factory
;
2444 trace("Testing gopher protocol...\n");
2446 hres
= CoGetClassObject(&CLSID_GopherProtocol
, CLSCTX_INPROC_SERVER
, NULL
, &IID_IUnknown
, (void**)&unk
);
2448 hres
== REGDB_E_CLASSNOTREG
, /* Gopher protocol has been removed as of Vista */
2449 "CoGetClassObject failed: %08x\n", hres
);
2453 hres
= IUnknown_QueryInterface(unk
, &IID_IInternetProtocolInfo
, (void**)&protocol_info
);
2454 ok(hres
== E_NOINTERFACE
, "Could not get IInternetProtocolInfo interface: %08x, expected E_NOINTERFACE\n", hres
);
2456 hres
= IUnknown_QueryInterface(unk
, &IID_IClassFactory
, (void**)&factory
);
2457 ok(hres
== S_OK
, "Could not get IClassFactory interface\n");
2458 IUnknown_Release(unk
);
2462 hres
= IClassFactory_CreateInstance(factory
, NULL
, &IID_IInternetProtocol
,
2463 (void**)&async_protocol
);
2464 IClassFactory_Release(factory
);
2465 ok(hres
== S_OK
, "Could not get IInternetProtocol: %08x\n", hres
);
2467 test_priority(async_protocol
);
2469 IInternetProtocol_Release(async_protocol
);
2472 static void test_mk_protocol(void)
2474 IInternetProtocolInfo
*protocol_info
;
2475 IInternetProtocol
*protocol
;
2476 IClassFactory
*factory
;
2480 static const WCHAR wrong_url1
[] = {'t','e','s','t',':','@','M','S','I','T','S','t','o','r','e',
2481 ':',':','/','t','e','s','t','.','h','t','m','l',0};
2482 static const WCHAR wrong_url2
[] = {'m','k',':','/','t','e','s','t','.','h','t','m','l',0};
2484 trace("Testing mk protocol...\n");
2485 init_test(MK_TEST
, 0);
2487 hres
= CoGetClassObject(&CLSID_MkProtocol
, CLSCTX_INPROC_SERVER
, NULL
,
2488 &IID_IUnknown
, (void**)&unk
);
2489 ok(hres
== S_OK
, "CoGetClassObject failed: %08x\n", hres
);
2491 hres
= IUnknown_QueryInterface(unk
, &IID_IInternetProtocolInfo
, (void**)&protocol_info
);
2492 ok(hres
== E_NOINTERFACE
,
2493 "Could not get IInternetProtocolInfo interface: %08x, expected E_NOINTERFACE\n",
2496 hres
= IUnknown_QueryInterface(unk
, &IID_IClassFactory
, (void**)&factory
);
2497 ok(hres
== S_OK
, "Could not get IClassFactory interface\n");
2498 IUnknown_Release(unk
);
2502 hres
= IClassFactory_CreateInstance(factory
, NULL
, &IID_IInternetProtocol
,
2504 IClassFactory_Release(factory
);
2505 ok(hres
== S_OK
, "Could not get IInternetProtocol: %08x\n", hres
);
2507 SET_EXPECT(GetBindInfo
);
2508 hres
= IInternetProtocol_Start(protocol
, wrong_url1
, &protocol_sink
, &bind_info
, 0, 0);
2509 ok(hres
== MK_E_SYNTAX
|| hres
== INET_E_INVALID_URL
,
2510 "Start failed: %08x, expected MK_E_SYNTAX or INET_E_INVALID_URL\n", hres
);
2511 CLEAR_CALLED(GetBindInfo
);
2513 SET_EXPECT(GetBindInfo
);
2514 SET_EXPECT(ReportProgress_DIRECTBIND
);
2515 SET_EXPECT(ReportProgress_SENDINGREQUEST
);
2516 SET_EXPECT(ReportProgress_MIMETYPEAVAILABLE
);
2517 SET_EXPECT(ReportResult
);
2518 expect_hrResult
= INET_E_RESOURCE_NOT_FOUND
;
2520 hres
= IInternetProtocol_Start(protocol
, wrong_url2
, &protocol_sink
, &bind_info
, 0, 0);
2521 ok(hres
== INET_E_RESOURCE_NOT_FOUND
||
2522 hres
== INET_E_INVALID_URL
, /* win2k3 */
2523 "Start failed: %08x, expected INET_E_RESOURCE_NOT_FOUND or INET_E_INVALID_URL\n", hres
);
2525 if (hres
== INET_E_RESOURCE_NOT_FOUND
) {
2526 CHECK_CALLED(GetBindInfo
);
2527 CLEAR_CALLED(ReportProgress_DIRECTBIND
);
2528 CHECK_CALLED(ReportProgress_SENDINGREQUEST
);
2529 CHECK_CALLED(ReportProgress_MIMETYPEAVAILABLE
);
2530 CHECK_CALLED(ReportResult
);
2532 CLEAR_CALLED(GetBindInfo
);
2533 CLEAR_CALLED(ReportProgress_DIRECTBIND
);
2534 CLEAR_CALLED(ReportProgress_SENDINGREQUEST
);
2535 CLEAR_CALLED(ReportProgress_MIMETYPEAVAILABLE
);
2536 CLEAR_CALLED(ReportResult
);
2539 IInternetProtocol_Release(protocol
);
2542 static void test_CreateBinding(void)
2544 IInternetProtocol
*protocol
;
2545 IInternetPriority
*priority
;
2546 IInternetSession
*session
;
2552 static const WCHAR test_url
[] =
2553 {'t','e','s','t',':','/','/','f','i','l','e','.','h','t','m','l',0};
2554 static const WCHAR wsz_test
[] = {'t','e','s','t',0};
2556 trace("Testing CreateBinding...\n");
2557 init_test(BIND_TEST
, TEST_BINDING
);
2559 hres
= CoInternetGetSession(0, &session
, 0);
2560 ok(hres
== S_OK
, "CoInternetGetSession failed: %08x\n", hres
);
2562 hres
= IInternetSession_RegisterNameSpace(session
, &ClassFactory
, &IID_NULL
, wsz_test
, 0, NULL
, 0);
2563 ok(hres
== S_OK
, "RegisterNameSpace failed: %08x\n", hres
);
2565 hres
= IInternetSession_CreateBinding(session
, NULL
, test_url
, NULL
, NULL
, &protocol
, 0);
2566 binding_protocol
= protocol
;
2567 ok(hres
== S_OK
, "CreateBinding failed: %08x\n", hres
);
2568 ok(protocol
!= NULL
, "protocol == NULL\n");
2570 hres
= IInternetProtocol_QueryInterface(protocol
, &IID_IInternetBindInfo
, (void**)&prot_bind_info
);
2571 ok(hres
== S_OK
, "QueryInterface(IID_IInternetBindInfo) failed: %08x\n", hres
);
2573 hres
= IInternetProtocol_QueryInterface(protocol
, &IID_IInternetProtocolSink
, (void**)&binding_sink
);
2574 ok(hres
== S_OK
, "Could not get IInternetProtocolSink: %08x\n", hres
);
2576 hres
= IInternetProtocol_Start(protocol
, test_url
, NULL
, &bind_info
, 0, 0);
2577 ok(hres
== E_INVALIDARG
, "Start failed: %08x, expected E_INVALIDARG\n", hres
);
2578 hres
= IInternetProtocol_Start(protocol
, test_url
, &protocol_sink
, NULL
, 0, 0);
2579 ok(hres
== E_INVALIDARG
, "Start failed: %08x, expected E_INVALIDARG\n", hres
);
2580 hres
= IInternetProtocol_Start(protocol
, NULL
, &protocol_sink
, &bind_info
, 0, 0);
2581 ok(hres
== E_INVALIDARG
, "Start failed: %08x, expected E_INVALIDARG\n", hres
);
2583 hres
= IInternetProtocol_QueryInterface(protocol
, &IID_IInternetPriority
, (void**)&priority
);
2584 ok(hres
== S_OK
, "QueryInterface(IID_IInternetPriority) failed: %08x\n", hres
);
2587 hres
= IInternetPriority_GetPriority(priority
, &p
);
2588 ok(hres
== S_OK
, "GetPriority failed: %08x\n", hres
);
2589 ok(!p
, "p=%d\n", p
);
2592 hres
= IInternetPriority_SetPriority(priority
, 100);
2593 ok(hres
== S_OK
, "SetPriority failed: %08x\n", hres
);
2596 hres
= IInternetPriority_GetPriority(priority
, &p
);
2597 ok(hres
== S_OK
, "GetPriority failed: %08x\n", hres
);
2598 ok(p
== 100, "p=%d\n", p
);
2600 SET_EXPECT(QueryService_InternetProtocol
);
2601 SET_EXPECT(CreateInstance
);
2602 SET_EXPECT(ReportProgress_PROTOCOLCLASSID
);
2603 SET_EXPECT(SetPriority
);
2606 expect_hrResult
= S_OK
;
2607 hres
= IInternetProtocol_Start(protocol
, test_url
, &protocol_sink
, &bind_info
, 0, 0);
2608 ok(hres
== S_OK
, "Start failed: %08x\n", hres
);
2610 CHECK_CALLED(QueryService_InternetProtocol
);
2611 CHECK_CALLED(CreateInstance
);
2612 CHECK_CALLED(ReportProgress_PROTOCOLCLASSID
);
2613 CHECK_CALLED(SetPriority
);
2614 CHECK_CALLED(Start
);
2618 hres
= IInternetProtocol_Read(protocol
, expect_pv
= buf
, sizeof(buf
), &read
);
2619 ok(hres
== S_OK
, "Read failed: %08x\n", hres
);
2620 ok(read
== 100, "read = %d\n", read
);
2625 hres
= IInternetProtocol_Read(protocol
, expect_pv
= buf
, sizeof(buf
), &read
);
2626 ok(hres
== S_FALSE
, "Read failed: %08x\n", hres
);
2627 ok(!read
, "read = %d\n", read
);
2631 hres
= IInternetPriority_GetPriority(priority
, &p
);
2632 ok(hres
== S_OK
, "GetPriority failed: %08x\n", hres
);
2633 ok(p
== 100, "p=%d\n", p
);
2635 hres
= IInternetPriority_SetPriority(priority
, 101);
2636 ok(hres
== S_OK
, "SetPriority failed: %08x\n", hres
);
2638 SET_EXPECT(Terminate
);
2639 hres
= IInternetProtocol_Terminate(protocol
, 0xdeadbeef);
2640 ok(hres
== S_OK
, "Terminate failed: %08x\n", hres
);
2641 CHECK_CALLED(Terminate
);
2643 SET_EXPECT(Continue
);
2644 hres
= IInternetProtocolSink_Switch(binding_sink
, &protocoldata
);
2645 ok(hres
== S_OK
, "Switch failed: %08x\n", hres
);
2646 CHECK_CALLED(Continue
);
2648 hres
= IInternetProtocolSink_ReportProgress(binding_sink
,
2649 BINDSTATUS_CACHEFILENAMEAVAILABLE
, expect_wsz
= emptyW
);
2650 ok(hres
== S_OK
, "ReportProgress(BINDSTATUS_CACHEFILENAMEAVAILABLE) failed: %08x\n", hres
);
2652 hres
= IInternetProtocolSink_ReportResult(binding_sink
, S_OK
, ERROR_SUCCESS
, NULL
);
2653 ok(hres
== E_FAIL
, "ReportResult failed: %08x, expected E_FAIL\n", hres
);
2655 hres
= IInternetProtocolSink_ReportData(binding_sink
, 0, 0, 0);
2656 ok(hres
== S_OK
, "ReportData failed: %08x\n", hres
);
2658 IInternetProtocolSink_Release(binding_sink
);
2659 IInternetPriority_Release(priority
);
2660 IInternetBindInfo_Release(prot_bind_info
);
2661 IInternetProtocol_Release(protocol
);
2662 IInternetSession_Release(session
);
2665 static void test_binding(int prot
, DWORD grf_pi
, BOOL test_filter
)
2667 IInternetProtocol
*protocol
;
2668 IInternetSession
*session
;
2672 trace("Testing %s binding (grfPI %x%s)...\n", debugstr_w(protocol_names
[prot
]), grf_pi
,
2673 test_filter
? " testing MIME filter" : "");
2674 init_test(prot
, TEST_BINDING
| (test_filter
? TEST_FILTER
: 0));
2677 hres
= CoInternetGetSession(0, &session
, 0);
2678 ok(hres
== S_OK
, "CoInternetGetSession failed: %08x\n", hres
);
2680 hres
= IInternetSession_RegisterNameSpace(session
, &ClassFactory
, &IID_NULL
, protocol_names
[prot
], 0, NULL
, 0);
2681 ok(hres
== S_OK
, "RegisterNameSpace failed: %08x\n", hres
);
2683 hres
= IInternetSession_CreateBinding(session
, NULL
, binding_urls
[prot
], NULL
, NULL
, &protocol
, 0);
2684 binding_protocol
= protocol
;
2685 IInternetSession_Release(session
);
2686 ok(hres
== S_OK
, "CreateBinding failed: %08x\n", hres
);
2687 ok(protocol
!= NULL
, "protocol == NULL\n");
2689 hres
= IInternetProtocol_QueryInterface(protocol
, &IID_IInternetBindInfo
, (void**)&prot_bind_info
);
2690 ok(hres
== S_OK
, "QueryInterface(IID_IInternetBindInfo) failed: %08x\n", hres
);
2692 hres
= IInternetProtocol_QueryInterface(protocol
, &IID_IInternetProtocolSink
, (void**)&binding_sink
);
2693 ok(hres
== S_OK
, "QueryInterface(IID_IInternetProtocolSink) failed: %08x\n", hres
);
2696 SET_EXPECT(QueryService_InternetProtocol
);
2697 SET_EXPECT(CreateInstance
);
2698 SET_EXPECT(ReportProgress_PROTOCOLCLASSID
);
2699 SET_EXPECT(SetPriority
);
2702 expect_hrResult
= S_OK
;
2703 hres
= IInternetProtocol_Start(protocol
, binding_urls
[prot
], &protocol_sink
, &bind_info
, pi
, 0);
2704 ok(hres
== S_OK
, "Start failed: %08x\n", hres
);
2706 CHECK_CALLED(QueryService_InternetProtocol
);
2707 CHECK_CALLED(CreateInstance
);
2708 CHECK_CALLED(ReportProgress_PROTOCOLCLASSID
);
2709 CHECK_CALLED(SetPriority
);
2710 CHECK_CALLED(Start
);
2712 if(prot
== HTTP_TEST
|| prot
== HTTPS_TEST
) {
2713 while(prot_state
< 4) {
2714 WaitForSingleObject(event_complete
, INFINITE
);
2715 if(mimefilter_test
&& filtered_protocol
) {
2716 SET_EXPECT(Continue
);
2717 IInternetProtocol_Continue(filtered_protocol
, pdata
);
2718 CHECK_CALLED(Continue
);
2720 SET_EXPECT(Continue
);
2721 IInternetProtocol_Continue(protocol
, pdata
);
2722 CHECK_CALLED(Continue
);
2724 SetEvent(event_complete2
);
2726 WaitForSingleObject(event_complete
, INFINITE
);
2729 SET_EXPECT(MimeFilter_LockRequest
);
2731 SET_EXPECT(LockRequest
);
2732 hres
= IInternetProtocol_LockRequest(protocol
, 0);
2733 ok(hres
== S_OK
, "LockRequest failed: %08x\n", hres
);
2735 CHECK_CALLED(MimeFilter_LockRequest
);
2737 CHECK_CALLED(LockRequest
);
2740 SET_EXPECT(MimeFilter_UnlockRequest
);
2742 SET_EXPECT(UnlockRequest
);
2743 hres
= IInternetProtocol_UnlockRequest(protocol
);
2744 ok(hres
== S_OK
, "UnlockRequest failed: %08x\n", hres
);
2746 CHECK_CALLED(MimeFilter_UnlockRequest
);
2748 CHECK_CALLED(UnlockRequest
);
2752 SET_EXPECT(MimeFilter_Terminate
);
2754 SET_EXPECT(Terminate
);
2755 hres
= IInternetProtocol_Terminate(protocol
, 0);
2756 ok(hres
== S_OK
, "Terminate failed: %08x\n", hres
);
2758 CHECK_CALLED(MimeFilter_Terminate
);
2760 CHECK_CALLED(Terminate
);
2762 if(filtered_protocol
)
2763 IInternetProtocol_Release(filtered_protocol
);
2764 IInternetBindInfo_Release(prot_bind_info
);
2765 IInternetProtocolSink_Release(binding_sink
);
2766 ref
= IInternetProtocol_Release(protocol
);
2767 ok(!ref
, "ref=%u, expected 0\n", ref
);
2770 static void register_filter(void)
2772 IInternetSession
*session
;
2775 static const WCHAR gzipW
[] = {'g','z','i','p',0};
2777 CoInternetGetSession(0, &session
, 0);
2779 hres
= IInternetSession_RegisterMimeFilter(session
, &mimefilter_cf
, &IID_IInternetProtocol
, gzipW
);
2780 ok(hres
== S_OK
, "RegisterMimeFilter failed: %08x\n", hres
);
2782 IInternetSession_Release(session
);
2785 START_TEST(protocol
)
2787 OleInitialize(NULL
);
2789 event_complete
= CreateEvent(NULL
, FALSE
, FALSE
, NULL
);
2790 event_complete2
= CreateEvent(NULL
, FALSE
, FALSE
, NULL
);
2794 test_file_protocol();
2795 test_http_protocol();
2796 test_https_protocol();
2797 test_ftp_protocol();
2798 test_gopher_protocol();
2800 test_CreateBinding();
2801 test_binding(FILE_TEST
, 0, FALSE
);
2802 test_binding(HTTP_TEST
, 0, FALSE
);
2803 test_binding(FILE_TEST
, PI_MIMEVERIFICATION
, FALSE
);
2804 test_binding(HTTP_TEST
, PI_MIMEVERIFICATION
, FALSE
);
2805 test_binding(FILE_TEST
, PI_MIMEVERIFICATION
, TRUE
);
2806 test_binding(HTTP_TEST
, PI_MIMEVERIFICATION
, TRUE
);
2808 CloseHandle(event_complete
);
2809 CloseHandle(event_complete2
);