2 * Copyright 2005-2007 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(ReportData);
81 DEFINE_EXPECT(ReportResult);
82 DEFINE_EXPECT(GetBindString_ACCEPT_MIMES);
83 DEFINE_EXPECT(GetBindString_USER_AGENT);
84 DEFINE_EXPECT(GetBindString_POST_COOKIE);
85 DEFINE_EXPECT(QueryService_HttpNegotiate);
86 DEFINE_EXPECT(QueryService_InternetProtocol);
87 DEFINE_EXPECT(BeginningTransaction);
88 DEFINE_EXPECT(GetRootSecurityId);
89 DEFINE_EXPECT(OnResponse);
90 DEFINE_EXPECT(Switch);
91 DEFINE_EXPECT(Continue);
92 DEFINE_EXPECT(CreateInstance);
94 DEFINE_EXPECT(Terminate);
96 DEFINE_EXPECT(SetPriority);
97 DEFINE_EXPECT(LockRequest);
98 DEFINE_EXPECT(UnlockRequest);
100 static const WCHAR wszIndexHtml[] = {'i','n','d','e','x','.','h','t','m','l',0};
101 static const WCHAR index_url[] =
102 {'f','i','l','e',':','i','n','d','e','x','.','h','t','m','l',0};
104 static const WCHAR acc_mimeW[] = {'*','/','*',0};
105 static const WCHAR user_agentW[] = {'W','i','n','e',0};
106 static const WCHAR text_htmlW[] = {'t','e','x','t','/','h','t','m','l',0};
107 static const WCHAR hostW[] = {'w','w','w','.','w','i','n','e','h','q','.','o','r','g',0};
108 static const WCHAR winehq_ipW[] = {'2','0','9','.','4','6','.','2','5','.','1','3','4',0};
109 static const WCHAR emptyW[] = {0};
111 static HRESULT expect_hrResult;
112 static LPCWSTR file_name, http_url, expect_wsz;
113 static IInternetProtocol *async_protocol = NULL;
114 static BOOL first_data_notif = FALSE, http_is_first = FALSE,
115 http_post_test = FALSE;
116 static int state = 0, prot_state;
117 static DWORD bindf = 0, ex_priority = 0;
118 static IInternetProtocol *binding_protocol;
119 static IInternetBindInfo *prot_bind_info;
120 static IInternetProtocolSink *binding_sink;
121 static void *expect_pv;
122 static HANDLE event_complete, event_complete2;
123 static BOOL binding_test;
124 static PROTOCOLDATA protocoldata, *pdata;
125 static DWORD prot_read;
136 static const WCHAR protocol_names[][10] = {
139 {'h','t','t','p','s',0},
145 static const WCHAR binding_urls[][130] = {
146 {'f','i','l','e',':','t','e','s','t','.','h','t','m','l',0},
147 {'h','t','t','p',':','/','/','t','e','s','t','/','t','e','s','t','.','h','t','m','l',0},
148 {'h','t','t','p','s',':','/','/','w','w','w','.','c','o','d','e','w','e','a','v','e','r','s',
149 '.','c','o','m','/','t','e','s','t','.','h','t','m','l',0},
150 {'f','t','p',':','/','/','f','t','p','.','w','i','n','e','h','q','.','o','r','g',
151 '/','p','u','b','/','o','t','h','e','r',
152 '/','w','i','n','e','l','o','g','o','.','x','c','f','.','t','a','r','.','b','z','2',0},
153 {'m','k',':','t','e','s','t',0},
154 {'t','e','s','t',':','/','/','f','i','l','e','.','h','t','m','l',0}
157 static const char *debugstr_w(LPCWSTR str)
159 static char buf[512];
162 WideCharToMultiByte(CP_ACP, 0, str, -1, buf, sizeof(buf), NULL, NULL);
166 static const char *debugstr_guid(REFIID riid)
170 sprintf(buf, "{%08X-%04X-%04X-%02X%02X-%02X%02X%02X%02X%02X%02X}",
171 riid->Data1, riid->Data2, riid->Data3, riid->Data4[0],
172 riid->Data4[1], riid->Data4[2], riid->Data4[3], riid->Data4[4],
173 riid->Data4[5], riid->Data4[6], riid->Data4[7]);
178 static int strcmp_wa(LPCWSTR strw, const char *stra)
181 MultiByteToWideChar(CP_ACP, 0, stra, -1, buf, sizeof(buf)/sizeof(WCHAR));
182 return lstrcmpW(strw, buf);
185 static HRESULT WINAPI HttpNegotiate_QueryInterface(IHttpNegotiate2 *iface, REFIID riid, void **ppv)
187 if(IsEqualGUID(&IID_IUnknown, riid)
188 || IsEqualGUID(&IID_IHttpNegotiate, riid)
189 || IsEqualGUID(&IID_IHttpNegotiate2, riid)) {
194 ok(0, "unexpected call\n");
195 return E_NOINTERFACE;
198 static ULONG WINAPI HttpNegotiate_AddRef(IHttpNegotiate2 *iface)
203 static ULONG WINAPI HttpNegotiate_Release(IHttpNegotiate2 *iface)
208 static HRESULT WINAPI HttpNegotiate_BeginningTransaction(IHttpNegotiate2 *iface, LPCWSTR szURL,
209 LPCWSTR szHeaders, DWORD dwReserved, LPWSTR *pszAdditionalHeaders)
213 static const WCHAR wszHeaders[] =
214 {'C','o','n','t','e','n','t','-','T','y','p','e',':',' ','a','p','p','l','i','c','a','t',
215 'i','o','n','/','x','-','w','w','w','-','f','o','r','m','-','u','r','l','e','n','c','o',
216 'd','e','d','\r','\n',0};
218 CHECK_EXPECT(BeginningTransaction);
221 ok(!lstrcmpW(szURL, binding_urls[tested_protocol]), "szURL != http_url\n");
223 ok(!lstrcmpW(szURL, http_url), "szURL != http_url\n");
224 ok(!dwReserved, "dwReserved=%d, expected 0\n", dwReserved);
225 ok(pszAdditionalHeaders != NULL, "pszAdditionalHeaders == NULL\n");
226 if(pszAdditionalHeaders)
228 ok(*pszAdditionalHeaders == NULL, "*pszAdditionalHeaders != NULL\n");
231 addl_headers = CoTaskMemAlloc(sizeof(wszHeaders));
234 http_post_test = FALSE;
235 skip("Out of memory\n");
236 return E_OUTOFMEMORY;
238 lstrcpyW(addl_headers, wszHeaders);
239 *pszAdditionalHeaders = addl_headers;
246 static HRESULT WINAPI HttpNegotiate_OnResponse(IHttpNegotiate2 *iface, DWORD dwResponseCode,
247 LPCWSTR szResponseHeaders, LPCWSTR szRequestHeaders, LPWSTR *pszAdditionalRequestHeaders)
249 CHECK_EXPECT(OnResponse);
251 ok(dwResponseCode == 200, "dwResponseCode=%d, expected 200\n", dwResponseCode);
252 ok(szResponseHeaders != NULL, "szResponseHeaders == NULL\n");
253 ok(szRequestHeaders == NULL, "szRequestHeaders != NULL\n");
254 ok(pszAdditionalRequestHeaders == NULL, "pszAdditionalHeaders != NULL\n");
259 static HRESULT WINAPI HttpNegotiate_GetRootSecurityId(IHttpNegotiate2 *iface,
260 BYTE *pbSecurityId, DWORD *pcbSecurityId, DWORD_PTR dwReserved)
262 static const BYTE sec_id[] = {'h','t','t','p',':','t','e','s','t',1,0,0,0};
264 CHECK_EXPECT(GetRootSecurityId);
266 ok(!dwReserved, "dwReserved=%ld, expected 0\n", dwReserved);
267 ok(pbSecurityId != NULL, "pbSecurityId == NULL\n");
268 ok(pcbSecurityId != NULL, "pcbSecurityId == NULL\n");
271 ok(*pcbSecurityId == 512, "*pcbSecurityId=%d, expected 512\n", *pcbSecurityId);
272 *pcbSecurityId = sizeof(sec_id);
276 memcpy(pbSecurityId, sec_id, sizeof(sec_id));
281 static IHttpNegotiate2Vtbl HttpNegotiateVtbl = {
282 HttpNegotiate_QueryInterface,
283 HttpNegotiate_AddRef,
284 HttpNegotiate_Release,
285 HttpNegotiate_BeginningTransaction,
286 HttpNegotiate_OnResponse,
287 HttpNegotiate_GetRootSecurityId
290 static IHttpNegotiate2 http_negotiate = { &HttpNegotiateVtbl };
292 static HRESULT QueryInterface(REFIID,void**);
294 static HRESULT WINAPI ServiceProvider_QueryInterface(IServiceProvider *iface, REFIID riid, void **ppv)
296 return QueryInterface(riid, ppv);
299 static ULONG WINAPI ServiceProvider_AddRef(IServiceProvider *iface)
304 static ULONG WINAPI ServiceProvider_Release(IServiceProvider *iface)
309 static HRESULT WINAPI ServiceProvider_QueryService(IServiceProvider *iface, REFGUID guidService,
310 REFIID riid, void **ppv)
312 if(IsEqualGUID(&IID_IHttpNegotiate, guidService) || IsEqualGUID(&IID_IHttpNegotiate2, riid)) {
313 CHECK_EXPECT2(QueryService_HttpNegotiate);
314 return IHttpNegotiate2_QueryInterface(&http_negotiate, riid, ppv);
317 if(IsEqualGUID(&IID_IInternetProtocol, guidService)) {
318 ok(IsEqualGUID(&IID_IInternetProtocol, riid), "unexpected riid\n");
319 CHECK_EXPECT(QueryService_InternetProtocol);
320 return E_NOINTERFACE;
323 ok(0, "unexpected service %s\n", debugstr_guid(guidService));
327 static const IServiceProviderVtbl ServiceProviderVtbl = {
328 ServiceProvider_QueryInterface,
329 ServiceProvider_AddRef,
330 ServiceProvider_Release,
331 ServiceProvider_QueryService
334 static IServiceProvider service_provider = { &ServiceProviderVtbl };
336 static HRESULT WINAPI ProtocolSink_QueryInterface(IInternetProtocolSink *iface, REFIID riid, void **ppv)
338 return QueryInterface(riid, ppv);
341 static ULONG WINAPI ProtocolSink_AddRef(IInternetProtocolSink *iface)
346 static ULONG WINAPI ProtocolSink_Release(IInternetProtocolSink *iface)
351 static HRESULT WINAPI ProtocolSink_Switch(IInternetProtocolSink *iface, PROTOCOLDATA *pProtocolData)
355 CHECK_EXPECT(Switch);
356 ok(pProtocolData != NULL, "pProtocolData == NULL\n");
358 pdata = pProtocolData;
361 SetEvent(event_complete);
362 WaitForSingleObject(event_complete2, INFINITE);
367 if(tested_protocol == HTTP_TEST || tested_protocol == HTTPS_TEST || tested_protocol == FTP_TEST) {
369 CLEAR_CALLED(ReportProgress_FINDINGRESOURCE);
370 CLEAR_CALLED(ReportProgress_CONNECTING);
371 CLEAR_CALLED(ReportProgress_PROXYDETECTING);
373 CHECK_NOT_CALLED(ReportProgress_FINDINGRESOURCE);
374 /* IE7 does call this */
375 CLEAR_CALLED(ReportProgress_CONNECTING);
378 if(tested_protocol == FTP_TEST)
379 todo_wine CHECK_CALLED(ReportProgress_SENDINGREQUEST);
381 CHECK_CALLED(ReportProgress_SENDINGREQUEST);
382 if(tested_protocol == HTTP_TEST || tested_protocol == HTTPS_TEST) {
383 SET_EXPECT(OnResponse);
384 if(tested_protocol == HTTPS_TEST)
385 SET_EXPECT(ReportProgress_ACCEPTRANGES);
386 SET_EXPECT(ReportProgress_MIMETYPEAVAILABLE);
387 if(bindf & BINDF_NEEDFILE)
388 SET_EXPECT(ReportProgress_CACHEFILENAMEAVAILABLE);
392 SET_EXPECT(ReportData);
393 hres = IInternetProtocol_Continue(async_protocol, pProtocolData);
394 ok(hres == S_OK, "Continue failed: %08x\n", hres);
395 if(tested_protocol == FTP_TEST)
396 CLEAR_CALLED(ReportData);
398 CHECK_CALLED(ReportData);
402 if(tested_protocol == HTTP_TEST || tested_protocol == HTTPS_TEST) {
403 CHECK_CALLED(OnResponse);
404 if(tested_protocol == HTTPS_TEST)
405 CHECK_CALLED(ReportProgress_ACCEPTRANGES);
406 CHECK_CALLED(ReportProgress_MIMETYPEAVAILABLE);
407 if(bindf & BINDF_NEEDFILE)
408 CHECK_CALLED(ReportProgress_CACHEFILENAMEAVAILABLE);
412 SetEvent(event_complete);
417 static HRESULT WINAPI ProtocolSink_ReportProgress(IInternetProtocolSink *iface, ULONG ulStatusCode,
418 LPCWSTR szStatusText)
420 static const WCHAR null_guid[] = {'{','0','0','0','0','0','0','0','0','-','0','0','0','0','-',
421 '0','0','0','0','-','0','0','0','0','-','0','0','0','0','0','0','0','0','0','0','0','0','}',0};
422 static const WCHAR text_plain[] = {'t','e','x','t','/','p','l','a','i','n',0};
424 switch(ulStatusCode) {
425 case BINDSTATUS_MIMETYPEAVAILABLE:
426 CHECK_EXPECT(ReportProgress_MIMETYPEAVAILABLE);
427 ok(szStatusText != NULL, "szStatusText == NULL\n");
429 if(tested_protocol == BIND_TEST)
430 ok(szStatusText == expect_wsz, "unexpected szStatusText\n");
431 else if (http_post_test)
432 ok(lstrlenW(text_plain) <= lstrlenW(szStatusText) &&
433 !memcmp(szStatusText, text_plain, lstrlenW(text_plain)*sizeof(WCHAR)),
434 "szStatusText != text/plain\n");
436 ok(lstrlenW(text_htmlW) <= lstrlenW(szStatusText) &&
437 !memcmp(szStatusText, text_htmlW, lstrlenW(text_htmlW)*sizeof(WCHAR)),
438 "szStatusText != text/html\n");
441 case BINDSTATUS_DIRECTBIND:
442 CHECK_EXPECT2(ReportProgress_DIRECTBIND);
443 ok(szStatusText == NULL, "szStatusText != NULL\n");
445 case BINDSTATUS_RAWMIMETYPE:
446 CHECK_EXPECT2(ReportProgress_RAWMIMETYPE);
447 ok(szStatusText != NULL, "szStatusText == NULL\n");
449 ok(lstrlenW(szStatusText) < lstrlenW(text_htmlW) ||
450 !memcmp(szStatusText, text_htmlW, lstrlenW(text_htmlW)*sizeof(WCHAR)),
451 "szStatusText != text/html\n");
453 case BINDSTATUS_CACHEFILENAMEAVAILABLE:
454 CHECK_EXPECT(ReportProgress_CACHEFILENAMEAVAILABLE);
455 ok(szStatusText != NULL, "szStatusText == NULL\n");
458 ok(!lstrcmpW(szStatusText, expect_wsz), "unexpected szStatusText\n");
459 else if(tested_protocol == FILE_TEST)
460 ok(!lstrcmpW(szStatusText, file_name), "szStatusText = \"%s\"\n", debugstr_w(szStatusText));
462 ok(szStatusText != NULL, "szStatusText == NULL\n");
465 case BINDSTATUS_FINDINGRESOURCE:
466 CHECK_EXPECT(ReportProgress_FINDINGRESOURCE);
467 ok(szStatusText != NULL, "szStatusText == NULL\n");
469 case BINDSTATUS_CONNECTING:
470 CHECK_EXPECT(ReportProgress_CONNECTING);
471 ok(szStatusText != NULL, "szStatusText == NULL\n");
473 case BINDSTATUS_SENDINGREQUEST:
474 CHECK_EXPECT2(ReportProgress_SENDINGREQUEST);
475 if(tested_protocol == FILE_TEST) {
476 ok(szStatusText != NULL, "szStatusText == NULL\n");
478 ok(!*szStatusText, "wrong szStatusText\n");
481 case BINDSTATUS_VERIFIEDMIMETYPEAVAILABLE:
482 CHECK_EXPECT(ReportProgress_VERIFIEDMIMETYPEAVAILABLE);
483 ok(szStatusText != NULL, "szStatusText == NULL\n");
485 ok(!lstrcmpW(szStatusText, text_htmlW), "szStatusText != text/html\n");
487 case BINDSTATUS_PROTOCOLCLASSID:
488 CHECK_EXPECT(ReportProgress_PROTOCOLCLASSID);
489 ok(szStatusText != NULL, "szStatusText == NULL\n");
490 ok(!lstrcmpW(szStatusText, null_guid), "unexpected szStatusText\n");
492 case BINDSTATUS_COOKIE_SENT:
493 CHECK_EXPECT(ReportProgress_COOKIE_SENT);
494 ok(szStatusText == NULL, "szStatusText != NULL\n");
496 case BINDSTATUS_REDIRECTING:
497 CHECK_EXPECT(ReportProgress_REDIRECTING);
498 ok(szStatusText == NULL, "szStatusText = %s\n", debugstr_w(szStatusText));
500 case BINDSTATUS_ENCODING:
501 CHECK_EXPECT(ReportProgress_ENCODING);
502 ok(!strcmp_wa(szStatusText, "gzip"), "szStatusText = %s\n", debugstr_w(szStatusText));
504 case BINDSTATUS_ACCEPTRANGES:
505 CHECK_EXPECT(ReportProgress_ACCEPTRANGES);
506 ok(!szStatusText, "szStatusText = %s\n", debugstr_w(szStatusText));
508 case BINDSTATUS_PROXYDETECTING:
509 CHECK_EXPECT(ReportProgress_PROXYDETECTING);
510 SET_EXPECT(ReportProgress_CONNECTING);
511 ok(!szStatusText, "szStatusText = %s\n", debugstr_w(szStatusText));
514 ok(0, "Unexpected status %d\n", ulStatusCode);
520 static HRESULT WINAPI ProtocolSink_ReportData(IInternetProtocolSink *iface, DWORD grfBSCF,
521 ULONG ulProgress, ULONG ulProgressMax)
523 if(tested_protocol == FILE_TEST) {
524 CHECK_EXPECT2(ReportData);
526 ok(ulProgress == ulProgressMax, "ulProgress (%d) != ulProgressMax (%d)\n",
527 ulProgress, ulProgressMax);
528 ok(ulProgressMax == 13, "ulProgressMax=%d, expected 13\n", ulProgressMax);
529 ok(grfBSCF == (BSCF_FIRSTDATANOTIFICATION | BSCF_LASTDATANOTIFICATION),
530 "grcfBSCF = %08x\n", grfBSCF);
531 }else if(!binding_test && (tested_protocol == HTTP_TEST || tested_protocol == HTTPS_TEST || tested_protocol == FTP_TEST)) {
532 if(!(grfBSCF & BSCF_LASTDATANOTIFICATION) || (grfBSCF & BSCF_DATAFULLYAVAILABLE))
533 CHECK_EXPECT(ReportData);
534 else if (http_post_test)
535 ok(ulProgress == 13, "Read %u bytes instead of 13\n", ulProgress);
537 ok(ulProgress, "ulProgress == 0\n");
539 if(first_data_notif) {
540 ok(grfBSCF == BSCF_FIRSTDATANOTIFICATION
541 || grfBSCF == (BSCF_LASTDATANOTIFICATION|BSCF_DATAFULLYAVAILABLE),
542 "grcfBSCF = %08x\n", grfBSCF);
543 first_data_notif = FALSE;
545 ok(grfBSCF == BSCF_INTERMEDIATEDATANOTIFICATION
546 || grfBSCF == (BSCF_LASTDATANOTIFICATION|BSCF_INTERMEDIATEDATANOTIFICATION)
547 || broken(grfBSCF == (BSCF_FIRSTDATANOTIFICATION|BSCF_LASTDATANOTIFICATION)),
548 "grcfBSCF = %08x\n", grfBSCF);
551 if(!(bindf & BINDF_FROMURLMON) &&
552 !(grfBSCF & BSCF_LASTDATANOTIFICATION)) {
556 CHECK_CALLED(ReportProgress_FINDINGRESOURCE);
557 CHECK_CALLED(ReportProgress_CONNECTING);
559 CHECK_NOT_CALLED(ReportProgress_FINDINGRESOURCE);
560 CHECK_NOT_CALLED(ReportProgress_CONNECTING);
562 CHECK_CALLED(ReportProgress_SENDINGREQUEST);
563 CHECK_CALLED(OnResponse);
564 CHECK_CALLED(ReportProgress_RAWMIMETYPE);
566 SetEvent(event_complete);
573 CHECK_EXPECT(ReportData);
575 if(tested_protocol == BIND_TEST)
580 hres = IInternetProtocol_Read(binding_protocol, expect_pv=buf, sizeof(buf), &read);
582 }while(hres == S_OK);
588 static HRESULT WINAPI ProtocolSink_ReportResult(IInternetProtocolSink *iface, HRESULT hrResult,
589 DWORD dwError, LPCWSTR szResult)
591 CHECK_EXPECT(ReportResult);
593 if(tested_protocol == FTP_TEST)
594 ok(hrResult == E_PENDING || hrResult == S_OK, "hrResult = %08x, expected E_PENDING or S_OK\n", hrResult);
596 ok(hrResult == expect_hrResult, "hrResult = %08x, expected: %08x\n",
597 hrResult, expect_hrResult);
598 if(SUCCEEDED(hrResult) || tested_protocol == FTP_TEST)
599 ok(dwError == ERROR_SUCCESS, "dwError = %d, expected ERROR_SUCCESS\n", dwError);
601 ok(dwError != ERROR_SUCCESS, "dwError == ERROR_SUCCESS\n");
602 ok(!szResult, "szResult != NULL\n");
607 static IInternetProtocolSinkVtbl protocol_sink_vtbl = {
608 ProtocolSink_QueryInterface,
610 ProtocolSink_Release,
612 ProtocolSink_ReportProgress,
613 ProtocolSink_ReportData,
614 ProtocolSink_ReportResult
617 static IInternetProtocolSink protocol_sink = { &protocol_sink_vtbl };
619 static HRESULT QueryInterface(REFIID riid, void **ppv)
623 if(IsEqualGUID(&IID_IUnknown, riid) || IsEqualGUID(&IID_IInternetProtocolSink, riid))
624 *ppv = &protocol_sink;
625 if(IsEqualGUID(&IID_IServiceProvider, riid))
626 *ppv = &service_provider;
631 return E_NOINTERFACE;
634 static HRESULT WINAPI BindInfo_QueryInterface(IInternetBindInfo *iface, REFIID riid, void **ppv)
636 if(IsEqualGUID(&IID_IUnknown, riid) || IsEqualGUID(&IID_IInternetBindInfo, riid)) {
640 return E_NOINTERFACE;
643 static ULONG WINAPI BindInfo_AddRef(IInternetBindInfo *iface)
648 static ULONG WINAPI BindInfo_Release(IInternetBindInfo *iface)
653 static HRESULT WINAPI BindInfo_GetBindInfo(IInternetBindInfo *iface, DWORD *grfBINDF, BINDINFO *pbindinfo)
657 static const CHAR szPostData[] = "mode=Test";
659 CHECK_EXPECT(GetBindInfo);
661 ok(grfBINDF != NULL, "grfBINDF == NULL\n");
662 ok(pbindinfo != NULL, "pbindinfo == NULL\n");
663 ok(pbindinfo->cbSize == sizeof(BINDINFO), "wrong size of pbindinfo: %d\n", pbindinfo->cbSize);
667 *grfBINDF |= BINDF_FROMURLMON;
668 cbSize = pbindinfo->cbSize;
669 memset(pbindinfo, 0, cbSize);
670 pbindinfo->cbSize = cbSize;
674 /* Must be GMEM_FIXED, GMEM_MOVABLE does not work properly
675 * with urlmon on native (Win98 and WinXP) */
676 U(pbindinfo->stgmedData).hGlobal = GlobalAlloc(GPTR, sizeof(szPostData));
677 if (!U(pbindinfo->stgmedData).hGlobal)
679 http_post_test = FALSE;
680 skip("Out of memory\n");
681 return E_OUTOFMEMORY;
683 lstrcpy((LPSTR)U(pbindinfo->stgmedData).hGlobal, szPostData);
684 pbindinfo->cbstgmedData = sizeof(szPostData)-1;
685 pbindinfo->dwBindVerb = BINDVERB_POST;
686 pbindinfo->stgmedData.tymed = TYMED_HGLOBAL;
692 static HRESULT WINAPI BindInfo_GetBindString(IInternetBindInfo *iface, ULONG ulStringType,
693 LPOLESTR *ppwzStr, ULONG cEl, ULONG *pcElFetched)
695 ok(ppwzStr != NULL, "ppwzStr == NULL\n");
696 ok(pcElFetched != NULL, "pcElFetched == NULL\n");
698 switch(ulStringType) {
699 case BINDSTRING_ACCEPT_MIMES:
700 CHECK_EXPECT(GetBindString_ACCEPT_MIMES);
701 ok(cEl == 256, "cEl=%d, expected 256\n", cEl);
703 ok(*pcElFetched == 256, "*pcElFetched=%d, expected 256\n", *pcElFetched);
707 *ppwzStr = CoTaskMemAlloc(sizeof(acc_mimeW));
708 memcpy(*ppwzStr, acc_mimeW, sizeof(acc_mimeW));
711 case BINDSTRING_USER_AGENT:
712 CHECK_EXPECT(GetBindString_USER_AGENT);
713 ok(cEl == 1, "cEl=%d, expected 1\n", cEl);
715 ok(*pcElFetched == 0, "*pcElFetch=%d, expectd 0\n", *pcElFetched);
719 *ppwzStr = CoTaskMemAlloc(sizeof(user_agentW));
720 memcpy(*ppwzStr, user_agentW, sizeof(user_agentW));
723 case BINDSTRING_POST_COOKIE:
724 CHECK_EXPECT(GetBindString_POST_COOKIE);
725 ok(cEl == 1, "cEl=%d, expected 1\n", cEl);
727 ok(*pcElFetched == 0, "*pcElFetch=%d, expectd 0\n", *pcElFetched);
730 ok(0, "unexpected call\n");
736 static IInternetBindInfoVtbl bind_info_vtbl = {
737 BindInfo_QueryInterface,
740 BindInfo_GetBindInfo,
741 BindInfo_GetBindString
744 static IInternetBindInfo bind_info = { &bind_info_vtbl };
746 static HRESULT WINAPI InternetPriority_QueryInterface(IInternetPriority *iface,
747 REFIID riid, void **ppv)
749 ok(0, "unexpected call\n");
750 return E_NOINTERFACE;
753 static ULONG WINAPI InternetPriority_AddRef(IInternetPriority *iface)
758 static ULONG WINAPI InternetPriority_Release(IInternetPriority *iface)
763 static HRESULT WINAPI InternetPriority_SetPriority(IInternetPriority *iface, LONG nPriority)
765 CHECK_EXPECT(SetPriority);
766 ok(nPriority == ex_priority, "nPriority=%d\n", nPriority);
770 static HRESULT WINAPI InternetPriority_GetPriority(IInternetPriority *iface, LONG *pnPriority)
772 ok(0, "unexpected call\n");
777 static const IInternetPriorityVtbl InternetPriorityVtbl = {
778 InternetPriority_QueryInterface,
779 InternetPriority_AddRef,
780 InternetPriority_Release,
781 InternetPriority_SetPriority,
782 InternetPriority_GetPriority
785 static IInternetPriority InternetPriority = { &InternetPriorityVtbl };
787 static HRESULT WINAPI Protocol_QueryInterface(IInternetProtocol *iface, REFIID riid, void **ppv)
789 if(IsEqualGUID(&IID_IUnknown, riid) || IsEqualGUID(&IID_IInternetProtocol, riid)) {
794 if(IsEqualGUID(&IID_IInternetProtocolEx, riid)) {
795 trace("IID_IInternetProtocolEx not supported\n");
797 return E_NOINTERFACE;
800 if(IsEqualGUID(&IID_IInternetPriority, riid)) {
801 *ppv = &InternetPriority;
805 ok(0, "unexpected riid %s\n", debugstr_guid(riid));
807 return E_NOINTERFACE;
810 static ULONG WINAPI Protocol_AddRef(IInternetProtocol *iface)
815 static ULONG WINAPI Protocol_Release(IInternetProtocol *iface)
820 static DWORD WINAPI thread_proc(PVOID arg)
824 memset(&protocoldata, -1, sizeof(protocoldata));
828 SET_EXPECT(ReportProgress_FINDINGRESOURCE);
829 hres = IInternetProtocolSink_ReportProgress(binding_sink,
830 BINDSTATUS_FINDINGRESOURCE, hostW);
831 CHECK_CALLED(ReportProgress_FINDINGRESOURCE);
832 ok(hres == S_OK, "ReportProgress failed: %08x\n", hres);
834 SET_EXPECT(ReportProgress_CONNECTING);
835 hres = IInternetProtocolSink_ReportProgress(binding_sink,
836 BINDSTATUS_CONNECTING, winehq_ipW);
837 CHECK_CALLED(ReportProgress_CONNECTING);
838 ok(hres == S_OK, "ReportProgress failed: %08x\n", hres);
840 SET_EXPECT(ReportProgress_SENDINGREQUEST);
841 hres = IInternetProtocolSink_ReportProgress(binding_sink,
842 BINDSTATUS_SENDINGREQUEST, NULL);
843 CHECK_CALLED(ReportProgress_SENDINGREQUEST);
844 ok(hres == S_OK, "ReportProgress failed: %08x\n", hres);
848 hres = IInternetProtocolSink_Switch(binding_sink, &protocoldata);
849 CHECK_CALLED(Switch);
850 ok(hres == S_OK, "Switch failed: %08x\n", hres);
854 hres = IInternetProtocolSink_Switch(binding_sink, &protocoldata);
855 CHECK_CALLED(Switch);
856 ok(hres == S_OK, "Switch failed: %08x\n", hres);
860 hres = IInternetProtocolSink_Switch(binding_sink, &protocoldata);
861 CHECK_CALLED(Switch);
862 ok(hres == S_OK, "Switch failed: %08x\n", hres);
866 hres = IInternetProtocolSink_Switch(binding_sink, &protocoldata);
867 CHECK_CALLED(Switch);
868 ok(hres == S_OK, "Switch failed: %08x\n", hres);
870 SetEvent(event_complete);
875 static HRESULT WINAPI Protocol_Start(IInternetProtocol *iface, LPCWSTR szUrl,
876 IInternetProtocolSink *pOIProtSink, IInternetBindInfo *pOIBindInfo,
877 DWORD grfPI, DWORD dwReserved)
879 BINDINFO bindinfo, exp_bindinfo;
885 ok(pOIProtSink != NULL, "pOIProtSink == NULL\n");
886 ok(pOIBindInfo != NULL, "pOIBindInfo == NULL\n");
887 ok(pOIProtSink != &protocol_sink, "unexpected pOIProtSink\n");
888 ok(pOIBindInfo != &bind_info, "unexpected pOIBindInfo\n");
889 ok(!grfPI, "grfPI = %x\n", grfPI);
890 ok(!dwReserved, "dwReserved = %d\n", dwReserved);
892 memset(&bindinfo, 0, sizeof(bindinfo));
893 bindinfo.cbSize = sizeof(bindinfo);
894 memcpy(&exp_bindinfo, &bindinfo, sizeof(bindinfo));
895 SET_EXPECT(GetBindInfo);
896 hres = IInternetBindInfo_GetBindInfo(pOIBindInfo, &cbindf, &bindinfo);
897 ok(hres == S_OK, "GetBindInfo failed: %08x\n", hres);
898 CHECK_CALLED(GetBindInfo);
899 ok(cbindf == (bindf|BINDF_FROMURLMON), "bindf = %x, expected %x\n",
900 cbindf, (bindf|BINDF_FROMURLMON));
901 ok(!memcmp(&exp_bindinfo, &bindinfo, sizeof(bindinfo)), "unexpected bindinfo\n");
902 ReleaseBindInfo(&bindinfo);
904 SET_EXPECT(ReportProgress_SENDINGREQUEST);
905 hres = IInternetProtocolSink_ReportProgress(pOIProtSink, BINDSTATUS_SENDINGREQUEST, emptyW);
906 ok(hres == S_OK, "ReportProgress(BINDSTATUS_SENDINGREQUEST) failed: %08x\n", hres);
907 CHECK_CALLED(ReportProgress_SENDINGREQUEST);
909 if(tested_protocol == HTTP_TEST || tested_protocol == HTTPS_TEST) {
910 IServiceProvider *service_provider;
911 IHttpNegotiate *http_negotiate;
912 IHttpNegotiate2 *http_negotiate2;
913 LPWSTR ua = (LPWSTR)0xdeadbeef, accept_mimes[256];
914 LPWSTR additional_headers = NULL;
916 DWORD fetched = 0, size = 100;
919 SET_EXPECT(GetBindString_USER_AGENT);
920 hres = IInternetBindInfo_GetBindString(pOIBindInfo, BINDSTRING_USER_AGENT,
922 CHECK_CALLED(GetBindString_USER_AGENT);
923 ok(hres == S_OK, "GetBindString(BINDSTRING_USER_AGETNT) failed: %08x\n", hres);
924 ok(fetched == 1, "fetched = %d, expected 254\n", fetched);
925 ok(ua != NULL, "ua = %p\n", ua);
926 ok(!lstrcmpW(ua, user_agentW), "unexpected user agent %s\n", debugstr_w(ua));
930 SET_EXPECT(GetBindString_ACCEPT_MIMES);
931 hres = IInternetBindInfo_GetBindString(pOIBindInfo, BINDSTRING_ACCEPT_MIMES,
932 accept_mimes, 256, &fetched);
933 CHECK_CALLED(GetBindString_ACCEPT_MIMES);
936 "GetBindString(BINDSTRING_ACCEPT_MIMES) failed: %08x\n", hres);
937 ok(fetched == 1, "fetched = %d, expected 1\n", fetched);
938 ok(!lstrcmpW(acc_mimeW, accept_mimes[0]), "unexpected mimes %s\n", debugstr_w(accept_mimes[0]));
940 hres = IInternetBindInfo_QueryInterface(pOIBindInfo, &IID_IServiceProvider,
941 (void**)&service_provider);
942 ok(hres == S_OK, "QueryInterface failed: %08x\n", hres);
944 SET_EXPECT(QueryService_HttpNegotiate);
945 hres = IServiceProvider_QueryService(service_provider, &IID_IHttpNegotiate,
946 &IID_IHttpNegotiate, (void**)&http_negotiate);
947 CHECK_CALLED(QueryService_HttpNegotiate);
948 ok(hres == S_OK, "QueryService failed: %08x\n", hres);
950 SET_EXPECT(BeginningTransaction);
951 hres = IHttpNegotiate_BeginningTransaction(http_negotiate, binding_urls[tested_protocol],
952 NULL, 0, &additional_headers);
953 CHECK_CALLED(BeginningTransaction);
954 IHttpNegotiate_Release(http_negotiate);
955 ok(hres == S_OK, "BeginningTransction failed: %08x\n", hres);
956 ok(additional_headers == NULL, "additional_headers=%p\n", additional_headers);
958 SET_EXPECT(QueryService_HttpNegotiate);
959 hres = IServiceProvider_QueryService(service_provider, &IID_IHttpNegotiate2,
960 &IID_IHttpNegotiate2, (void**)&http_negotiate2);
961 CHECK_CALLED(QueryService_HttpNegotiate);
962 ok(hres == S_OK, "QueryService failed: %08x\n", hres);
965 SET_EXPECT(GetRootSecurityId);
966 hres = IHttpNegotiate2_GetRootSecurityId(http_negotiate2, sec_id, &size, 0);
967 CHECK_CALLED(GetRootSecurityId);
968 IHttpNegotiate2_Release(http_negotiate2);
969 ok(hres == E_FAIL, "GetRootSecurityId failed: %08x, expected E_FAIL\n", hres);
970 ok(size == 13, "size=%d\n", size);
972 IServiceProvider_Release(service_provider);
974 CreateThread(NULL, 0, thread_proc, NULL, 0, &tid);
979 SET_EXPECT(ReportProgress_CACHEFILENAMEAVAILABLE);
980 hres = IInternetProtocolSink_ReportProgress(pOIProtSink,
981 BINDSTATUS_CACHEFILENAMEAVAILABLE, expect_wsz = emptyW);
982 ok(hres == S_OK, "ReportProgress(BINDSTATUS_CACHEFILENAMEAVAILABLE) failed: %08x\n", hres);
983 CHECK_CALLED(ReportProgress_CACHEFILENAMEAVAILABLE);
985 SET_EXPECT(ReportProgress_MIMETYPEAVAILABLE);
986 hres = IInternetProtocolSink_ReportProgress(pOIProtSink, BINDSTATUS_VERIFIEDMIMETYPEAVAILABLE,
987 expect_wsz = text_htmlW);
989 "ReportProgress(BINDSTATUS_VERIFIEDMIMETYPEAVAILABLE) failed: %08x\n", hres);
990 CHECK_CALLED(ReportProgress_MIMETYPEAVAILABLE);
992 SET_EXPECT(ReportData);
993 hres = IInternetProtocolSink_ReportData(pOIProtSink,
994 BSCF_FIRSTDATANOTIFICATION | BSCF_LASTDATANOTIFICATION, 13, 13);
995 ok(hres == S_OK, "ReportData failed: %08x\n", hres);
996 CHECK_CALLED(ReportData);
998 if(tested_protocol == BIND_TEST) {
999 hres = IInternetProtocol_Terminate(binding_protocol, 0);
1000 ok(hres == E_FAIL, "Termiante failed: %08x\n", hres);
1003 SET_EXPECT(ReportResult);
1004 hres = IInternetProtocolSink_ReportResult(pOIProtSink, S_OK, 0, NULL);
1005 ok(hres == S_OK, "ReportResult failed: %08x\n", hres);
1006 CHECK_CALLED(ReportResult);
1011 static HRESULT WINAPI Protocol_Continue(IInternetProtocol *iface,
1012 PROTOCOLDATA *pProtocolData)
1017 CHECK_EXPECT(Continue);
1019 ok(pProtocolData != NULL, "pProtocolData == NULL\n");
1020 if(!pProtocolData || tested_protocol == BIND_TEST)
1023 switch(prot_state) {
1025 IServiceProvider *service_provider;
1026 IHttpNegotiate *http_negotiate;
1027 static WCHAR header[] = {'?',0};
1029 hres = IInternetProtocolSink_QueryInterface(binding_sink, &IID_IServiceProvider,
1030 (void**)&service_provider);
1031 ok(hres == S_OK, "Could not get IServiceProvicder\n");
1033 SET_EXPECT(QueryService_HttpNegotiate);
1034 hres = IServiceProvider_QueryService(service_provider, &IID_IHttpNegotiate,
1035 &IID_IHttpNegotiate, (void**)&http_negotiate);
1036 IServiceProvider_Release(service_provider);
1037 CHECK_CALLED(QueryService_HttpNegotiate);
1038 ok(hres == S_OK, "Could not get IHttpNegotiate\n");
1040 SET_EXPECT(OnResponse);
1041 hres = IHttpNegotiate_OnResponse(http_negotiate, 200, header, NULL, NULL);
1042 IHttpNegotiate_Release(http_negotiate);
1043 CHECK_CALLED(OnResponse);
1044 IHttpNegotiate_Release(http_negotiate);
1045 ok(hres == S_OK, "OnResponse failed: %08x\n", hres);
1047 SET_EXPECT(ReportProgress_MIMETYPEAVAILABLE);
1048 hres = IInternetProtocolSink_ReportProgress(binding_sink,
1049 BINDSTATUS_MIMETYPEAVAILABLE, text_htmlW);
1050 CHECK_CALLED(ReportProgress_MIMETYPEAVAILABLE);
1052 "ReportProgress(BINDSTATUS_MIMETYPEAVAILABLE) failed: %08x\n", hres);
1054 bscf |= BSCF_FIRSTDATANOTIFICATION;
1059 bscf = BSCF_INTERMEDIATEDATANOTIFICATION;
1063 SET_EXPECT(ReportData);
1064 hres = IInternetProtocolSink_ReportData(binding_sink, bscf, 100, 400);
1065 CHECK_CALLED(ReportData);
1066 ok(hres == S_OK, "ReportData failed: %08x\n", hres);
1074 static HRESULT WINAPI Protocol_Abort(IInternetProtocol *iface, HRESULT hrReason,
1077 ok(0, "unexpected call\n");
1081 static HRESULT WINAPI Protocol_Terminate(IInternetProtocol *iface, DWORD dwOptions)
1083 CHECK_EXPECT(Terminate);
1084 ok(!dwOptions, "dwOptions=%d\n", dwOptions);
1088 static HRESULT WINAPI Protocol_Suspend(IInternetProtocol *iface)
1090 ok(0, "unexpected call\n");
1094 static HRESULT WINAPI Protocol_Resume(IInternetProtocol *iface)
1096 ok(0, "unexpected call\n");
1100 static HRESULT WINAPI Protocol_Read(IInternetProtocol *iface, void *pv,
1101 ULONG cb, ULONG *pcbRead)
1103 static BOOL b = TRUE;
1107 ok(pv == expect_pv, "pv != expect_pv\n");
1108 ok(cb == 1000, "cb=%d\n", cb);
1109 ok(pcbRead != NULL, "pcbRead == NULL\n");
1110 ok(!*pcbRead, "*pcbRead = %d\n", *pcbRead);
1112 if(prot_state == 3) {
1115 SET_EXPECT(ReportResult);
1116 hres = IInternetProtocolSink_ReportResult(binding_sink, S_OK, ERROR_SUCCESS, NULL);
1117 CHECK_CALLED(ReportResult);
1123 return tested_protocol == HTTP_TEST || tested_protocol == HTTPS_TEST ? E_PENDING : S_FALSE;
1125 memset(pv, 'x', 100);
1126 prot_read += *pcbRead = 100;
1130 static HRESULT WINAPI Protocol_Seek(IInternetProtocol *iface,
1131 LARGE_INTEGER dlibMove, DWORD dwOrigin, ULARGE_INTEGER *plibNewPosition)
1133 ok(0, "unexpected call\n");
1137 static HRESULT WINAPI Protocol_LockRequest(IInternetProtocol *iface, DWORD dwOptions)
1139 CHECK_EXPECT(LockRequest);
1140 ok(dwOptions == 0, "dwOptions=%x\n", dwOptions);
1144 static HRESULT WINAPI Protocol_UnlockRequest(IInternetProtocol *iface)
1146 CHECK_EXPECT(UnlockRequest);
1150 static const IInternetProtocolVtbl ProtocolVtbl = {
1151 Protocol_QueryInterface,
1162 Protocol_LockRequest,
1163 Protocol_UnlockRequest
1166 static IInternetProtocol Protocol = { &ProtocolVtbl };
1168 static HRESULT WINAPI ClassFactory_QueryInterface(IClassFactory *iface, REFIID riid, void **ppv)
1170 ok(0, "unexpected call\n");
1171 return E_NOINTERFACE;
1174 static ULONG WINAPI ClassFactory_AddRef(IClassFactory *iface)
1179 static ULONG WINAPI ClassFactory_Release(IClassFactory *iface)
1184 static HRESULT WINAPI ClassFactory_CreateInstance(IClassFactory *iface, IUnknown *pOuter,
1185 REFIID riid, void **ppv)
1187 CHECK_EXPECT(CreateInstance);
1189 ok(pOuter == (IUnknown*)prot_bind_info, "pOuter != protocol_unk\n");
1190 ok(IsEqualGUID(&IID_IUnknown, riid), "unexpected riid %s\n", debugstr_guid(riid));
1191 ok(ppv != NULL, "ppv == NULL\n");
1197 static HRESULT WINAPI ClassFactory_LockServer(IClassFactory *iface, BOOL dolock)
1199 ok(0, "unexpected call\n");
1203 static const IClassFactoryVtbl ClassFactoryVtbl = {
1204 ClassFactory_QueryInterface,
1205 ClassFactory_AddRef,
1206 ClassFactory_Release,
1207 ClassFactory_CreateInstance,
1208 ClassFactory_LockServer
1211 static IClassFactory ClassFactory = { &ClassFactoryVtbl };
1213 static void test_priority(IInternetProtocol *protocol)
1215 IInternetPriority *priority;
1219 hres = IInternetProtocol_QueryInterface(protocol, &IID_IInternetPriority,
1221 ok(hres == S_OK, "QueryInterface(IID_IInternetPriority) failed: %08x\n", hres);
1225 hres = IInternetPriority_GetPriority(priority, &pr);
1226 ok(hres == S_OK, "GetPriority failed: %08x\n", hres);
1227 ok(pr == 0, "pr=%d, expected 0\n", pr);
1229 hres = IInternetPriority_SetPriority(priority, 1);
1230 ok(hres == S_OK, "SetPriority failed: %08x\n", hres);
1232 hres = IInternetPriority_GetPriority(priority, &pr);
1233 ok(hres == S_OK, "GetPriority failed: %08x\n", hres);
1234 ok(pr == 1, "pr=%d, expected 1\n", pr);
1236 IInternetPriority_Release(priority);
1239 static BOOL file_protocol_start(IInternetProtocol *protocol, LPCWSTR url, BOOL is_first)
1243 SET_EXPECT(GetBindInfo);
1244 if(!(bindf & BINDF_FROMURLMON))
1245 SET_EXPECT(ReportProgress_DIRECTBIND);
1247 SET_EXPECT(ReportProgress_SENDINGREQUEST);
1248 SET_EXPECT(ReportProgress_CACHEFILENAMEAVAILABLE);
1249 if(bindf & BINDF_FROMURLMON)
1250 SET_EXPECT(ReportProgress_VERIFIEDMIMETYPEAVAILABLE);
1252 SET_EXPECT(ReportProgress_MIMETYPEAVAILABLE);
1254 SET_EXPECT(ReportData);
1256 SET_EXPECT(ReportResult);
1258 expect_hrResult = S_OK;
1260 hres = IInternetProtocol_Start(protocol, url, &protocol_sink, &bind_info, 0, 0);
1261 if(hres == INET_E_RESOURCE_NOT_FOUND) {
1262 win_skip("Start failed\n");
1265 ok(hres == S_OK, "Start failed: %08x\n", hres);
1267 CHECK_CALLED(GetBindInfo);
1268 if(!(bindf & BINDF_FROMURLMON))
1269 CHECK_CALLED(ReportProgress_DIRECTBIND);
1271 CHECK_CALLED(ReportProgress_SENDINGREQUEST);
1272 CHECK_CALLED(ReportProgress_CACHEFILENAMEAVAILABLE);
1273 if(bindf & BINDF_FROMURLMON)
1274 CHECK_CALLED(ReportProgress_VERIFIEDMIMETYPEAVAILABLE);
1276 CHECK_CALLED(ReportProgress_MIMETYPEAVAILABLE);
1278 CHECK_CALLED(ReportData);
1280 CHECK_CALLED(ReportResult);
1285 static void test_file_protocol_url(LPCWSTR url)
1287 IInternetProtocolInfo *protocol_info;
1289 IClassFactory *factory;
1292 hres = CoGetClassObject(&CLSID_FileProtocol, CLSCTX_INPROC_SERVER, NULL,
1293 &IID_IUnknown, (void**)&unk);
1294 ok(hres == S_OK, "CoGetClassObject failed: %08x\n", hres);
1298 hres = IUnknown_QueryInterface(unk, &IID_IInternetProtocolInfo, (void**)&protocol_info);
1299 ok(hres == E_NOINTERFACE,
1300 "Could not get IInternetProtocolInfo interface: %08x, expected E_NOINTERFACE\n", hres);
1302 hres = IUnknown_QueryInterface(unk, &IID_IClassFactory, (void**)&factory);
1303 ok(hres == S_OK, "Could not get IClassFactory interface\n");
1304 if(SUCCEEDED(hres)) {
1305 IInternetProtocol *protocol;
1308 hres = IClassFactory_CreateInstance(factory, NULL, &IID_IInternetProtocol, (void**)&protocol);
1309 ok(hres == S_OK, "Could not get IInternetProtocol: %08x\n", hres);
1311 if(SUCCEEDED(hres)) {
1312 if(file_protocol_start(protocol, url, TRUE)) {
1313 hres = IInternetProtocol_Read(protocol, buf, 2, &cb);
1314 ok(hres == S_OK, "Read failed: %08x\n", hres);
1315 ok(cb == 2, "cb=%u expected 2\n", cb);
1316 hres = IInternetProtocol_Read(protocol, buf, sizeof(buf), &cb);
1317 ok(hres == S_FALSE, "Read failed: %08x\n", hres);
1318 hres = IInternetProtocol_Read(protocol, buf, sizeof(buf), &cb);
1319 ok(hres == S_FALSE, "Read failed: %08x expected S_FALSE\n", hres);
1320 ok(cb == 0, "cb=%u expected 0\n", cb);
1321 hres = IInternetProtocol_UnlockRequest(protocol);
1322 ok(hres == S_OK, "UnlockRequest failed: %08x\n", hres);
1325 if(file_protocol_start(protocol, url, FALSE)) {
1326 hres = IInternetProtocol_Read(protocol, buf, 2, &cb);
1327 ok(hres == S_FALSE, "Read failed: %08x\n", hres);
1328 hres = IInternetProtocol_LockRequest(protocol, 0);
1329 ok(hres == S_OK, "LockRequest failed: %08x\n", hres);
1330 hres = IInternetProtocol_UnlockRequest(protocol);
1331 ok(hres == S_OK, "UnlockRequest failed: %08x\n", hres);
1334 IInternetProtocol_Release(protocol);
1337 hres = IClassFactory_CreateInstance(factory, NULL, &IID_IInternetProtocol, (void**)&protocol);
1338 ok(hres == S_OK, "Could not get IInternetProtocol: %08x\n", hres);
1340 if(SUCCEEDED(hres)) {
1341 if(file_protocol_start(protocol, url, TRUE)) {
1342 hres = IInternetProtocol_LockRequest(protocol, 0);
1343 ok(hres == S_OK, "LockRequest failed: %08x\n", hres);
1344 hres = IInternetProtocol_Terminate(protocol, 0);
1345 ok(hres == S_OK, "Terminate failed: %08x\n", hres);
1346 hres = IInternetProtocol_Read(protocol, buf, 2, &cb);
1347 ok(hres == S_OK, "Read failed: %08x\n\n", hres);
1348 hres = IInternetProtocol_UnlockRequest(protocol);
1349 ok(hres == S_OK, "UnlockRequest failed: %08x\n", hres);
1350 hres = IInternetProtocol_Read(protocol, buf, 2, &cb);
1351 ok(hres == S_OK, "Read failed: %08x\n", hres);
1352 hres = IInternetProtocol_Terminate(protocol, 0);
1353 ok(hres == S_OK, "Terminate failed: %08x\n", hres);
1356 IInternetProtocol_Release(protocol);
1359 hres = IClassFactory_CreateInstance(factory, NULL, &IID_IInternetProtocol, (void**)&protocol);
1360 ok(hres == S_OK, "Could not get IInternetProtocol: %08x\n", hres);
1362 if(SUCCEEDED(hres)) {
1363 if(file_protocol_start(protocol, url, TRUE)) {
1364 hres = IInternetProtocol_Terminate(protocol, 0);
1365 ok(hres == S_OK, "Terminate failed: %08x\n", hres);
1366 hres = IInternetProtocol_Read(protocol, buf, 2, &cb);
1367 ok(hres == S_OK, "Read failed: %08x\n", hres);
1368 ok(cb == 2, "cb=%u expected 2\n", cb);
1371 IInternetProtocol_Release(protocol);
1374 IClassFactory_Release(factory);
1377 IUnknown_Release(unk);
1380 static void test_file_protocol_fail(void)
1382 IInternetProtocol *protocol;
1385 static const WCHAR index_url2[] =
1386 {'f','i','l','e',':','/','/','i','n','d','e','x','.','h','t','m','l',0};
1388 hres = CoCreateInstance(&CLSID_FileProtocol, NULL, CLSCTX_INPROC_SERVER|CLSCTX_INPROC_HANDLER,
1389 &IID_IInternetProtocol, (void**)&protocol);
1390 ok(hres == S_OK, "CoCreateInstance failed: %08x\n", hres);
1394 SET_EXPECT(GetBindInfo);
1395 expect_hrResult = MK_E_SYNTAX;
1396 hres = IInternetProtocol_Start(protocol, wszIndexHtml, &protocol_sink, &bind_info, 0, 0);
1397 ok(hres == MK_E_SYNTAX ||
1398 hres == E_INVALIDARG,
1399 "Start failed: %08x, expected MK_E_SYNTAX or E_INVALIDARG\n", hres);
1400 CLEAR_CALLED(GetBindInfo); /* GetBindInfo not called in IE7 */
1402 SET_EXPECT(GetBindInfo);
1403 if(!(bindf & BINDF_FROMURLMON))
1404 SET_EXPECT(ReportProgress_DIRECTBIND);
1405 SET_EXPECT(ReportProgress_SENDINGREQUEST);
1406 SET_EXPECT(ReportResult);
1407 expect_hrResult = INET_E_RESOURCE_NOT_FOUND;
1408 hres = IInternetProtocol_Start(protocol, index_url, &protocol_sink, &bind_info, 0, 0);
1409 ok(hres == INET_E_RESOURCE_NOT_FOUND,
1410 "Start failed: %08x expected INET_E_RESOURCE_NOT_FOUND\n", hres);
1411 CHECK_CALLED(GetBindInfo);
1412 if(!(bindf & BINDF_FROMURLMON))
1413 CHECK_CALLED(ReportProgress_DIRECTBIND);
1414 CHECK_CALLED(ReportProgress_SENDINGREQUEST);
1415 CHECK_CALLED(ReportResult);
1417 IInternetProtocol_Release(protocol);
1419 hres = CoCreateInstance(&CLSID_FileProtocol, NULL, CLSCTX_INPROC_SERVER|CLSCTX_INPROC_HANDLER,
1420 &IID_IInternetProtocol, (void**)&protocol);
1421 ok(hres == S_OK, "CoCreateInstance failed: %08x\n", hres);
1425 SET_EXPECT(GetBindInfo);
1426 if(!(bindf & BINDF_FROMURLMON))
1427 SET_EXPECT(ReportProgress_DIRECTBIND);
1428 SET_EXPECT(ReportProgress_SENDINGREQUEST);
1429 SET_EXPECT(ReportResult);
1430 expect_hrResult = INET_E_RESOURCE_NOT_FOUND;
1432 hres = IInternetProtocol_Start(protocol, index_url2, &protocol_sink, &bind_info, 0, 0);
1433 ok(hres == INET_E_RESOURCE_NOT_FOUND,
1434 "Start failed: %08x, expected INET_E_RESOURCE_NOT_FOUND\n", hres);
1435 CHECK_CALLED(GetBindInfo);
1436 if(!(bindf & BINDF_FROMURLMON))
1437 CHECK_CALLED(ReportProgress_DIRECTBIND);
1438 CHECK_CALLED(ReportProgress_SENDINGREQUEST);
1439 CHECK_CALLED(ReportResult);
1441 SET_EXPECT(GetBindInfo);
1442 hres = IInternetProtocol_Start(protocol, NULL, &protocol_sink, &bind_info, 0, 0);
1443 ok(hres == E_INVALIDARG, "Start failed: %08x, expected E_INVALIDARG\n", hres);
1444 CLEAR_CALLED(GetBindInfo); /* GetBindInfo not called in IE7 */
1446 SET_EXPECT(GetBindInfo);
1447 hres = IInternetProtocol_Start(protocol, emptyW, &protocol_sink, &bind_info, 0, 0);
1448 ok(hres == E_INVALIDARG, "Start failed: %08x, expected E_INVALIDARG\n", hres);
1449 CLEAR_CALLED(GetBindInfo); /* GetBindInfo not called in IE7 */
1451 IInternetProtocol_Release(protocol);
1454 static void test_file_protocol(void) {
1455 WCHAR buf[INTERNET_MAX_URL_LENGTH], file_name_buf[MAX_PATH];
1460 static const WCHAR wszFile[] = {'f','i','l','e',':',0};
1461 static const WCHAR wszFile2[] = {'f','i','l','e',':','/','/',0};
1462 static const WCHAR wszFile3[] = {'f','i','l','e',':','/','/','/',0};
1463 static const char html_doc[] = "<HTML></HTML>";
1465 trace("Testing file protocol...\n");
1466 tested_protocol = FILE_TEST;
1468 SetLastError(0xdeadbeef);
1469 file = CreateFileW(wszIndexHtml, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS,
1470 FILE_ATTRIBUTE_NORMAL, NULL);
1471 if(!file && GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)
1473 win_skip("Detected Win9x or WinMe\n");
1476 ok(file != INVALID_HANDLE_VALUE, "CreateFile failed\n");
1477 if(file == INVALID_HANDLE_VALUE)
1479 WriteFile(file, html_doc, sizeof(html_doc)-1, &size, NULL);
1482 file_name = wszIndexHtml;
1484 test_file_protocol_url(index_url);
1485 bindf = BINDF_FROMURLMON;
1486 test_file_protocol_url(index_url);
1487 bindf = BINDF_FROMURLMON | BINDF_NEEDFILE;
1488 test_file_protocol_url(index_url);
1490 memcpy(buf, wszFile, sizeof(wszFile));
1491 len = sizeof(wszFile)/sizeof(WCHAR)-1;
1492 len += GetCurrentDirectoryW(sizeof(buf)/sizeof(WCHAR)-len, buf+len);
1494 memcpy(buf+len, wszIndexHtml, sizeof(wszIndexHtml));
1496 file_name = buf + sizeof(wszFile)/sizeof(WCHAR)-1;
1498 test_file_protocol_url(buf);
1499 bindf = BINDF_FROMURLMON;
1500 test_file_protocol_url(buf);
1502 memcpy(buf, wszFile2, sizeof(wszFile2));
1503 len = GetCurrentDirectoryW(sizeof(file_name_buf)/sizeof(WCHAR), file_name_buf);
1504 file_name_buf[len++] = '\\';
1505 memcpy(file_name_buf+len, wszIndexHtml, sizeof(wszIndexHtml));
1506 lstrcpyW(buf+sizeof(wszFile2)/sizeof(WCHAR)-1, file_name_buf);
1507 file_name = file_name_buf;
1509 test_file_protocol_url(buf);
1510 bindf = BINDF_FROMURLMON;
1511 test_file_protocol_url(buf);
1513 buf[sizeof(wszFile2)/sizeof(WCHAR)] = '|';
1514 test_file_protocol_url(buf);
1516 memcpy(buf, wszFile3, sizeof(wszFile3));
1517 len = sizeof(wszFile3)/sizeof(WCHAR)-1;
1518 len += GetCurrentDirectoryW(sizeof(buf)/sizeof(WCHAR)-len, buf+len);
1520 memcpy(buf+len, wszIndexHtml, sizeof(wszIndexHtml));
1522 file_name = buf + sizeof(wszFile3)/sizeof(WCHAR)-1;
1524 test_file_protocol_url(buf);
1525 bindf = BINDF_FROMURLMON;
1526 test_file_protocol_url(buf);
1528 DeleteFileW(wszIndexHtml);
1531 test_file_protocol_fail();
1532 bindf = BINDF_FROMURLMON;
1533 test_file_protocol_fail();
1536 static BOOL http_protocol_start(LPCWSTR url, BOOL is_first)
1538 static BOOL got_user_agent = FALSE;
1541 first_data_notif = TRUE;
1544 SET_EXPECT(GetBindInfo);
1545 if (!(bindf & BINDF_FROMURLMON))
1546 SET_EXPECT(ReportProgress_DIRECTBIND);
1547 SET_EXPECT(GetBindString_USER_AGENT);
1548 SET_EXPECT(GetBindString_ACCEPT_MIMES);
1549 SET_EXPECT(QueryService_HttpNegotiate);
1550 SET_EXPECT(BeginningTransaction);
1551 SET_EXPECT(GetRootSecurityId);
1553 SET_EXPECT(GetBindString_POST_COOKIE);
1555 hres = IInternetProtocol_Start(async_protocol, url, &protocol_sink, &bind_info, 0, 0);
1556 ok(hres == S_OK, "Start failed: %08x\n", hres);
1560 CHECK_CALLED(GetBindInfo);
1561 if (!(bindf & BINDF_FROMURLMON))
1562 CHECK_CALLED(ReportProgress_DIRECTBIND);
1563 if (!got_user_agent)
1565 CHECK_CALLED(GetBindString_USER_AGENT);
1566 got_user_agent = TRUE;
1570 /* user agent only retrieved once, even with different URLs */
1571 CHECK_NOT_CALLED(GetBindString_USER_AGENT);
1573 CHECK_CALLED(GetBindString_ACCEPT_MIMES);
1574 CHECK_CALLED(QueryService_HttpNegotiate);
1575 CHECK_CALLED(BeginningTransaction);
1576 /* GetRootSecurityId called on WinXP but not on Win98 */
1577 CLEAR_CALLED(GetRootSecurityId);
1579 CHECK_CALLED(GetBindString_POST_COOKIE);
1584 static void test_protocol_terminate(IInternetProtocol *protocol)
1590 hres = IInternetProtocol_LockRequest(protocol, 0);
1591 ok(hres == S_OK, "LockRequest failed: %08x\n", hres);
1593 hres = IInternetProtocol_Read(protocol, buf, 1, &cb);
1594 ok(hres == S_FALSE, "Read failed: %08x\n", hres);
1596 hres = IInternetProtocol_Terminate(protocol, 0);
1597 ok(hres == S_OK, "Terminate failed: %08x\n", hres);
1599 /* This wait is to give the internet handles being freed in Terminate
1600 * enough time to actually terminate in all cases. Internet handles
1601 * terminate asynchronously and native reuses the main InternetOpen
1602 * handle. The only case in which this seems to be necessary is on
1603 * wine with native wininet and urlmon, resulting in the next time
1604 * test_http_protocol_url being called the first data notification actually
1605 * being an extra last data notification from the previous connection
1606 * about once out of every ten times. */
1609 hres = IInternetProtocol_UnlockRequest(protocol);
1610 ok(hres == S_OK, "UnlockRequest failed: %08x\n", hres);
1613 static void test_http_info(IInternetProtocol *protocol)
1615 IWinInetHttpInfo *info;
1618 hres = IInternetProtocol_QueryInterface(protocol, &IID_IWinInetHttpInfo, (void**)&info);
1619 ok(hres == S_OK, "Could not get IWinInterHttpInfo iface: %08x\n", hres);
1623 IWinInetHttpInfo_Release(info);
1626 /* is_first refers to whether this is the first call to this function
1628 static void test_http_protocol_url(LPCWSTR url, BOOL is_https, BOOL is_first)
1630 IInternetProtocolInfo *protocol_info;
1631 IClassFactory *factory;
1636 http_is_first = is_first;
1638 hres = CoGetClassObject(is_https ? &CLSID_HttpSProtocol : &CLSID_HttpProtocol,
1639 CLSCTX_INPROC_SERVER, NULL, &IID_IUnknown, (void**)&unk);
1640 ok(hres == S_OK, "CoGetClassObject failed: %08x\n", hres);
1644 hres = IUnknown_QueryInterface(unk, &IID_IInternetProtocolInfo, (void**)&protocol_info);
1645 ok(hres == E_NOINTERFACE,
1646 "Could not get IInternetProtocolInfo interface: %08x, expected E_NOINTERFACE\n",
1649 hres = IUnknown_QueryInterface(unk, &IID_IClassFactory, (void**)&factory);
1650 ok(hres == S_OK, "Could not get IClassFactory interface\n");
1651 IUnknown_Release(unk);
1655 hres = IClassFactory_CreateInstance(factory, NULL, &IID_IInternetProtocol,
1656 (void**)&async_protocol);
1657 ok(hres == S_OK, "Could not get IInternetProtocol: %08x\n", hres);
1658 if(SUCCEEDED(hres)) {
1663 test_priority(async_protocol);
1664 test_http_info(async_protocol);
1666 SET_EXPECT(ReportProgress_FINDINGRESOURCE);
1667 SET_EXPECT(ReportProgress_CONNECTING);
1668 SET_EXPECT(ReportProgress_SENDINGREQUEST);
1669 SET_EXPECT(ReportProgress_PROXYDETECTING);
1671 SET_EXPECT(ReportProgress_CACHEFILENAMEAVAILABLE);
1672 if(!(bindf & BINDF_FROMURLMON)) {
1673 SET_EXPECT(OnResponse);
1674 SET_EXPECT(ReportProgress_RAWMIMETYPE);
1675 SET_EXPECT(ReportData);
1680 if(!http_protocol_start(url, is_first))
1683 SET_EXPECT(ReportResult);
1684 expect_hrResult = S_OK;
1686 hres = IInternetProtocol_Read(async_protocol, buf, 1, &cb);
1687 ok((hres == E_PENDING && cb==0) ||
1688 (hres == S_OK && cb==1), "Read failed: %08x (%d bytes)\n", hres, cb);
1690 WaitForSingleObject(event_complete, INFINITE);
1691 if(bindf & BINDF_FROMURLMON)
1692 CHECK_CALLED(Switch);
1694 CHECK_CALLED(ReportData);
1697 if(bindf & BINDF_FROMURLMON)
1700 SET_EXPECT(ReportData);
1701 hres = IInternetProtocol_Read(async_protocol, buf, sizeof(buf), &cb);
1702 if(hres == E_PENDING) {
1703 hres = IInternetProtocol_Read(async_protocol, buf, 1, &cb);
1704 ok((hres == E_PENDING && cb==0) ||
1705 (hres == S_OK && cb==1), "Read failed: %08x (%d bytes)\n", hres, cb);
1706 WaitForSingleObject(event_complete, INFINITE);
1707 if(bindf & BINDF_FROMURLMON)
1708 CHECK_CALLED(Switch);
1710 CHECK_CALLED(ReportData);
1712 if(bindf & BINDF_FROMURLMON)
1713 CHECK_NOT_CALLED(Switch);
1715 CHECK_NOT_CALLED(ReportData);
1719 ok(hres == S_FALSE, "Read failed: %08x\n", hres);
1720 CHECK_CALLED(ReportResult);
1722 test_protocol_terminate(async_protocol);
1723 ref = IInternetProtocol_Release(async_protocol);
1724 ok(!ref, "ref=%x\n", hres);
1727 IClassFactory_Release(factory);
1730 static void test_http_protocol(void)
1732 static const WCHAR winehq_url[] =
1733 {'h','t','t','p',':','/','/','w','w','w','.','w','i','n','e','h','q','.',
1734 'o','r','g','/','s','i','t','e','/','a','b','o','u','t',0};
1735 static const WCHAR posttest_url[] =
1736 {'h','t','t','p',':','/','/','c','r','o','s','s','o','v','e','r','.',
1737 'c','o','d','e','w','e','a','v','e','r','s','.','c','o','m','/',
1738 'p','o','s','t','t','e','s','t','.','p','h','p',0};
1740 trace("Testing http protocol (not from urlmon)...\n");
1741 tested_protocol = HTTP_TEST;
1742 bindf = BINDF_ASYNCHRONOUS | BINDF_ASYNCSTORAGE | BINDF_PULLDATA;
1743 test_http_protocol_url(winehq_url, FALSE, TRUE);
1745 trace("Testing http protocol (from urlmon)...\n");
1746 bindf = BINDF_ASYNCHRONOUS | BINDF_ASYNCSTORAGE | BINDF_PULLDATA | BINDF_FROMURLMON;
1747 test_http_protocol_url(winehq_url, FALSE, FALSE);
1749 trace("Testing http protocol (to file)...\n");
1750 bindf = BINDF_ASYNCHRONOUS | BINDF_ASYNCSTORAGE | BINDF_PULLDATA | BINDF_FROMURLMON | BINDF_NEEDFILE;
1751 test_http_protocol_url(winehq_url, FALSE, FALSE);
1753 trace("Testing http protocol (post data)...\n");
1754 http_post_test = TRUE;
1755 /* Without this flag we get a ReportProgress_CACHEFILENAMEAVAILABLE
1756 * notification with BINDVERB_POST */
1757 bindf = BINDF_ASYNCHRONOUS | BINDF_ASYNCSTORAGE | BINDF_PULLDATA | BINDF_FROMURLMON | BINDF_NOWRITECACHE;
1758 test_http_protocol_url(posttest_url, FALSE, TRUE);
1759 http_post_test = FALSE;
1762 static void test_https_protocol(void)
1764 static const WCHAR codeweavers_url[] =
1765 {'h','t','t','p','s',':','/','/','w','w','w','.','c','o','d','e','w','e','a','v','e','r','s',
1766 '.','c','o','m','/','t','e','s','t','.','h','t','m','l',0};
1768 trace("Testing https protocol (from urlmon)...\n");
1769 tested_protocol = HTTPS_TEST;
1770 bindf = BINDF_ASYNCHRONOUS | BINDF_ASYNCSTORAGE | BINDF_PULLDATA | BINDF_FROMURLMON | BINDF_NOWRITECACHE;
1771 test_http_protocol_url(codeweavers_url, TRUE, TRUE);
1775 static void test_ftp_protocol(void)
1777 IInternetProtocolInfo *protocol_info;
1778 IClassFactory *factory;
1785 static const WCHAR ftp_urlW[] = {'f','t','p',':','/','/','f','t','p','.','w','i','n','e','h','q','.','o','r','g',
1786 '/','p','u','b','/','o','t','h','e','r','/',
1787 'w','i','n','e','l','o','g','o','.','x','c','f','.','t','a','r','.','b','z','2',0};
1789 trace("Testing ftp protocol...\n");
1791 bindf = BINDF_ASYNCHRONOUS | BINDF_ASYNCSTORAGE | BINDF_PULLDATA | BINDF_FROMURLMON | BINDF_NOWRITECACHE;
1793 tested_protocol = FTP_TEST;
1794 first_data_notif = TRUE;
1795 expect_hrResult = E_PENDING;
1797 hres = CoGetClassObject(&CLSID_FtpProtocol, CLSCTX_INPROC_SERVER, NULL, &IID_IUnknown, (void**)&unk);
1798 ok(hres == S_OK, "CoGetClassObject failed: %08x\n", hres);
1802 hres = IUnknown_QueryInterface(unk, &IID_IInternetProtocolInfo, (void**)&protocol_info);
1803 ok(hres == E_NOINTERFACE, "Could not get IInternetProtocolInfo interface: %08x, expected E_NOINTERFACE\n", hres);
1805 hres = IUnknown_QueryInterface(unk, &IID_IClassFactory, (void**)&factory);
1806 ok(hres == S_OK, "Could not get IClassFactory interface\n");
1807 IUnknown_Release(unk);
1811 hres = IClassFactory_CreateInstance(factory, NULL, &IID_IInternetProtocol,
1812 (void**)&async_protocol);
1813 IClassFactory_Release(factory);
1814 ok(hres == S_OK, "Could not get IInternetProtocol: %08x\n", hres);
1816 test_priority(async_protocol);
1818 SET_EXPECT(GetBindInfo);
1819 SET_EXPECT(GetBindString_USER_AGENT);
1820 SET_EXPECT(ReportProgress_FINDINGRESOURCE);
1821 SET_EXPECT(ReportProgress_CONNECTING);
1822 SET_EXPECT(ReportProgress_SENDINGREQUEST);
1825 hres = IInternetProtocol_Start(async_protocol, ftp_urlW, &protocol_sink, &bind_info, 0, 0);
1826 ok(hres == S_OK, "Start failed: %08x\n", hres);
1827 CHECK_CALLED(GetBindInfo);
1828 todo_wine CHECK_NOT_CALLED(GetBindString_USER_AGENT);
1830 SET_EXPECT(ReportResult);
1832 hres = IInternetProtocol_Read(async_protocol, buf, 1, &cb);
1833 ok((hres == E_PENDING && cb==0) ||
1834 (hres == S_OK && cb==1), "Read failed: %08x (%d bytes)\n", hres, cb);
1836 WaitForSingleObject(event_complete, INFINITE);
1837 CHECK_CALLED(Switch);
1842 hres = IInternetProtocol_Read(async_protocol, buf, sizeof(buf), &cb);
1843 if(hres == E_PENDING) {
1844 WaitForSingleObject(event_complete, INFINITE);
1845 CHECK_CALLED(Switch);
1847 CHECK_NOT_CALLED(Switch);
1852 ok(hres == S_FALSE, "Read failed: %08x\n", hres);
1853 CHECK_CALLED(ReportResult);
1855 test_protocol_terminate(async_protocol);
1857 ref = IInternetProtocol_Release(async_protocol);
1858 ok(!ref, "ref=%d\n", ref);
1861 static void test_gopher_protocol(void)
1863 IInternetProtocolInfo *protocol_info;
1864 IClassFactory *factory;
1868 trace("Testing gopher protocol...\n");
1870 hres = CoGetClassObject(&CLSID_GopherProtocol, CLSCTX_INPROC_SERVER, NULL, &IID_IUnknown, (void**)&unk);
1872 hres == REGDB_E_CLASSNOTREG, /* Gopher protocol has been removed as of Vista */
1873 "CoGetClassObject failed: %08x\n", hres);
1877 hres = IUnknown_QueryInterface(unk, &IID_IInternetProtocolInfo, (void**)&protocol_info);
1878 ok(hres == E_NOINTERFACE, "Could not get IInternetProtocolInfo interface: %08x, expected E_NOINTERFACE\n", hres);
1880 hres = IUnknown_QueryInterface(unk, &IID_IClassFactory, (void**)&factory);
1881 ok(hres == S_OK, "Could not get IClassFactory interface\n");
1882 IUnknown_Release(unk);
1886 hres = IClassFactory_CreateInstance(factory, NULL, &IID_IInternetProtocol,
1887 (void**)&async_protocol);
1888 IClassFactory_Release(factory);
1889 ok(hres == S_OK, "Could not get IInternetProtocol: %08x\n", hres);
1891 test_priority(async_protocol);
1893 IInternetProtocol_Release(async_protocol);
1896 static void test_mk_protocol(void)
1898 IInternetProtocolInfo *protocol_info;
1899 IInternetProtocol *protocol;
1900 IClassFactory *factory;
1904 static const WCHAR wrong_url1[] = {'t','e','s','t',':','@','M','S','I','T','S','t','o','r','e',
1905 ':',':','/','t','e','s','t','.','h','t','m','l',0};
1906 static const WCHAR wrong_url2[] = {'m','k',':','/','t','e','s','t','.','h','t','m','l',0};
1908 trace("Testing mk protocol...\n");
1909 tested_protocol = MK_TEST;
1911 hres = CoGetClassObject(&CLSID_MkProtocol, CLSCTX_INPROC_SERVER, NULL,
1912 &IID_IUnknown, (void**)&unk);
1913 ok(hres == S_OK, "CoGetClassObject failed: %08x\n", hres);
1915 hres = IUnknown_QueryInterface(unk, &IID_IInternetProtocolInfo, (void**)&protocol_info);
1916 ok(hres == E_NOINTERFACE,
1917 "Could not get IInternetProtocolInfo interface: %08x, expected E_NOINTERFACE\n",
1920 hres = IUnknown_QueryInterface(unk, &IID_IClassFactory, (void**)&factory);
1921 ok(hres == S_OK, "Could not get IClassFactory interface\n");
1922 IUnknown_Release(unk);
1926 hres = IClassFactory_CreateInstance(factory, NULL, &IID_IInternetProtocol,
1928 IClassFactory_Release(factory);
1929 ok(hres == S_OK, "Could not get IInternetProtocol: %08x\n", hres);
1931 SET_EXPECT(GetBindInfo);
1932 hres = IInternetProtocol_Start(protocol, wrong_url1, &protocol_sink, &bind_info, 0, 0);
1933 ok(hres == MK_E_SYNTAX || hres == INET_E_INVALID_URL,
1934 "Start failed: %08x, expected MK_E_SYNTAX or INET_E_INVALID_URL\n", hres);
1935 CLEAR_CALLED(GetBindInfo);
1937 SET_EXPECT(GetBindInfo);
1938 SET_EXPECT(ReportProgress_DIRECTBIND);
1939 SET_EXPECT(ReportProgress_SENDINGREQUEST);
1940 SET_EXPECT(ReportProgress_MIMETYPEAVAILABLE);
1941 SET_EXPECT(ReportResult);
1942 expect_hrResult = INET_E_RESOURCE_NOT_FOUND;
1944 hres = IInternetProtocol_Start(protocol, wrong_url2, &protocol_sink, &bind_info, 0, 0);
1945 ok(hres == INET_E_RESOURCE_NOT_FOUND ||
1946 hres == INET_E_INVALID_URL, /* win2k3 */
1947 "Start failed: %08x, expected INET_E_RESOURCE_NOT_FOUND or INET_E_INVALID_URL\n", hres);
1949 if (hres == INET_E_RESOURCE_NOT_FOUND) {
1950 CHECK_CALLED(GetBindInfo);
1951 CLEAR_CALLED(ReportProgress_DIRECTBIND);
1952 CHECK_CALLED(ReportProgress_SENDINGREQUEST);
1953 CHECK_CALLED(ReportProgress_MIMETYPEAVAILABLE);
1954 CHECK_CALLED(ReportResult);
1956 CLEAR_CALLED(GetBindInfo);
1957 CLEAR_CALLED(ReportProgress_DIRECTBIND);
1958 CLEAR_CALLED(ReportProgress_SENDINGREQUEST);
1959 CLEAR_CALLED(ReportProgress_MIMETYPEAVAILABLE);
1960 CLEAR_CALLED(ReportResult);
1963 IInternetProtocol_Release(protocol);
1966 static void test_CreateBinding(void)
1968 IInternetProtocolSink *sink;
1969 IInternetProtocol *protocol;
1970 IInternetPriority *priority;
1971 IInternetSession *session;
1977 static const WCHAR test_url[] =
1978 {'t','e','s','t',':','/','/','f','i','l','e','.','h','t','m','l',0};
1979 static const WCHAR wsz_test[] = {'t','e','s','t',0};
1981 trace("Testing CreateBinding...\n");
1982 tested_protocol = BIND_TEST;
1983 binding_test = TRUE;
1985 hres = CoInternetGetSession(0, &session, 0);
1986 ok(hres == S_OK, "CoInternetGetSession failed: %08x\n", hres);
1988 hres = IInternetSession_RegisterNameSpace(session, &ClassFactory, &IID_NULL, wsz_test, 0, NULL, 0);
1989 ok(hres == S_OK, "RegisterNameSpace failed: %08x\n", hres);
1991 hres = IInternetSession_CreateBinding(session, NULL, test_url, NULL, NULL, &protocol, 0);
1992 binding_protocol = protocol;
1993 ok(hres == S_OK, "CreateBinding failed: %08x\n", hres);
1994 ok(protocol != NULL, "protocol == NULL\n");
1996 hres = IInternetProtocol_QueryInterface(protocol, &IID_IInternetBindInfo, (void**)&prot_bind_info);
1997 ok(hres == S_OK, "QueryInterface(IID_IInternetBindInfo) failed: %08x\n", hres);
1999 hres = IInternetProtocol_QueryInterface(protocol, &IID_IInternetProtocolSink, (void**)&sink);
2000 ok(hres == S_OK, "Could not get IInternetProtocolSink: %08x\n", hres);
2002 hres = IInternetProtocol_Start(protocol, test_url, NULL, &bind_info, 0, 0);
2003 ok(hres == E_INVALIDARG, "Start failed: %08x, expected E_INVALIDARG\n", hres);
2004 hres = IInternetProtocol_Start(protocol, test_url, &protocol_sink, NULL, 0, 0);
2005 ok(hres == E_INVALIDARG, "Start failed: %08x, expected E_INVALIDARG\n", hres);
2006 hres = IInternetProtocol_Start(protocol, NULL, &protocol_sink, &bind_info, 0, 0);
2007 ok(hres == E_INVALIDARG, "Start failed: %08x, expected E_INVALIDARG\n", hres);
2009 hres = IInternetProtocol_QueryInterface(protocol, &IID_IInternetPriority, (void**)&priority);
2010 ok(hres == S_OK, "QueryInterface(IID_IInternetPriority) failed: %08x\n", hres);
2013 hres = IInternetPriority_GetPriority(priority, &p);
2014 ok(hres == S_OK, "GetPriority failed: %08x\n", hres);
2015 ok(!p, "p=%d\n", p);
2018 hres = IInternetPriority_SetPriority(priority, 100);
2019 ok(hres == S_OK, "SetPriority failed: %08x\n", hres);
2022 hres = IInternetPriority_GetPriority(priority, &p);
2023 ok(hres == S_OK, "GetPriority failed: %08x\n", hres);
2024 ok(p == 100, "p=%d\n", p);
2026 SET_EXPECT(QueryService_InternetProtocol);
2027 SET_EXPECT(CreateInstance);
2028 SET_EXPECT(ReportProgress_PROTOCOLCLASSID);
2029 SET_EXPECT(SetPriority);
2032 expect_hrResult = S_OK;
2033 hres = IInternetProtocol_Start(protocol, test_url, &protocol_sink, &bind_info, 0, 0);
2034 ok(hres == S_OK, "Start failed: %08x\n", hres);
2036 CHECK_CALLED(QueryService_InternetProtocol);
2037 CHECK_CALLED(CreateInstance);
2038 CHECK_CALLED(ReportProgress_PROTOCOLCLASSID);
2039 CHECK_CALLED(SetPriority);
2040 CHECK_CALLED(Start);
2044 hres = IInternetProtocol_Read(protocol, expect_pv = buf, sizeof(buf), &read);
2045 ok(hres == S_OK, "Read failed: %08x\n", hres);
2046 ok(read == 100, "read = %d\n", read);
2051 hres = IInternetProtocol_Read(protocol, expect_pv = buf, sizeof(buf), &read);
2052 ok(hres == S_FALSE, "Read failed: %08x\n", hres);
2053 ok(!read, "read = %d\n", read);
2057 hres = IInternetPriority_GetPriority(priority, &p);
2058 ok(hres == S_OK, "GetPriority failed: %08x\n", hres);
2059 ok(p == 100, "p=%d\n", p);
2061 hres = IInternetPriority_SetPriority(priority, 101);
2062 ok(hres == S_OK, "SetPriority failed: %08x\n", hres);
2064 SET_EXPECT(Terminate);
2065 hres = IInternetProtocol_Terminate(protocol, 0xdeadbeef);
2066 ok(hres == S_OK, "Terminate failed: %08x\n", hres);
2067 CHECK_CALLED(Terminate);
2069 SET_EXPECT(Continue);
2070 hres = IInternetProtocolSink_Switch(sink, &protocoldata);
2071 ok(hres == S_OK, "Switch failed: %08x\n", hres);
2072 CHECK_CALLED(Continue);
2074 hres = IInternetProtocolSink_ReportProgress(sink,
2075 BINDSTATUS_CACHEFILENAMEAVAILABLE, expect_wsz = emptyW);
2076 ok(hres == S_OK, "ReportProgress(BINDSTATUS_CACHEFILENAMEAVAILABLE) failed: %08x\n", hres);
2078 hres = IInternetProtocolSink_ReportResult(sink, S_OK, ERROR_SUCCESS, NULL);
2079 ok(hres == E_FAIL, "ReportResult failed: %08x, expected E_FAIL\n", hres);
2081 hres = IInternetProtocolSink_ReportData(sink, 0, 0, 0);
2082 ok(hres == S_OK, "ReportData failed: %08x\n", hres);
2084 IInternetProtocolSink_Release(sink);
2085 IInternetPriority_Release(priority);
2086 IInternetBindInfo_Release(prot_bind_info);
2087 IInternetProtocol_Release(protocol);
2088 IInternetSession_Release(session);
2091 static void test_binding(int prot)
2093 IInternetProtocol *protocol;
2094 IInternetSession *session;
2098 trace("Testing %s binding...\n", debugstr_w(protocol_names[prot]));
2100 tested_protocol = prot;
2101 binding_test = TRUE;
2102 first_data_notif = TRUE;
2105 hres = CoInternetGetSession(0, &session, 0);
2106 ok(hres == S_OK, "CoInternetGetSession failed: %08x\n", hres);
2108 hres = IInternetSession_RegisterNameSpace(session, &ClassFactory, &IID_NULL, protocol_names[prot], 0, NULL, 0);
2109 ok(hres == S_OK, "RegisterNameSpace failed: %08x\n", hres);
2111 hres = IInternetSession_CreateBinding(session, NULL, binding_urls[prot], NULL, NULL, &protocol, 0);
2112 binding_protocol = protocol;
2113 IInternetSession_Release(session);
2114 ok(hres == S_OK, "CreateBinding failed: %08x\n", hres);
2115 ok(protocol != NULL, "protocol == NULL\n");
2117 hres = IInternetProtocol_QueryInterface(protocol, &IID_IInternetBindInfo, (void**)&prot_bind_info);
2118 ok(hres == S_OK, "QueryInterface(IID_IInternetBindInfo) failed: %08x\n", hres);
2120 hres = IInternetProtocol_QueryInterface(protocol, &IID_IInternetProtocolSink, (void**)&binding_sink);
2121 ok(hres == S_OK, "QueryInterface(IID_IInternetProtocolSink) failed: %08x\n", hres);
2124 SET_EXPECT(QueryService_InternetProtocol);
2125 SET_EXPECT(CreateInstance);
2126 SET_EXPECT(ReportProgress_PROTOCOLCLASSID);
2127 SET_EXPECT(SetPriority);
2130 expect_hrResult = S_OK;
2131 hres = IInternetProtocol_Start(protocol, binding_urls[prot], &protocol_sink, &bind_info, 0, 0);
2132 ok(hres == S_OK, "Start failed: %08x\n", hres);
2134 CHECK_CALLED(QueryService_InternetProtocol);
2135 CHECK_CALLED(CreateInstance);
2136 CHECK_CALLED(ReportProgress_PROTOCOLCLASSID);
2137 CHECK_CALLED(SetPriority);
2138 CHECK_CALLED(Start);
2140 if(prot == HTTP_TEST || prot == HTTPS_TEST) {
2141 while(prot_state < 4) {
2142 WaitForSingleObject(event_complete, INFINITE);
2143 SET_EXPECT(Continue);
2144 IInternetProtocol_Continue(protocol, pdata);
2145 CHECK_CALLED(Continue);
2146 SetEvent(event_complete2);
2149 WaitForSingleObject(event_complete, INFINITE);
2151 SET_EXPECT(LockRequest);
2152 hres = IInternetProtocol_LockRequest(protocol, 0);
2153 ok(hres == S_OK, "LockRequest failed: %08x\n", hres);
2154 CHECK_CALLED(LockRequest);
2156 SET_EXPECT(UnlockRequest);
2157 hres = IInternetProtocol_UnlockRequest(protocol);
2158 ok(hres == S_OK, "UnlockRequest failed: %08x\n", hres);
2159 CHECK_CALLED(UnlockRequest);
2162 SET_EXPECT(Terminate);
2163 hres = IInternetProtocol_Terminate(protocol, 0);
2164 ok(hres == S_OK, "Terminate failed: %08x\n", hres);
2165 CHECK_CALLED(Terminate);
2167 IInternetBindInfo_Release(prot_bind_info);
2168 IInternetProtocolSink_Release(binding_sink);
2169 ref = IInternetProtocol_Release(protocol);
2170 ok(!ref, "ref=%u, expected 0\n", ref);
2173 START_TEST(protocol)
2175 OleInitialize(NULL);
2177 event_complete = CreateEvent(NULL, FALSE, FALSE, NULL);
2178 event_complete2 = CreateEvent(NULL, FALSE, FALSE, NULL);
2180 test_file_protocol();
2181 test_http_protocol();
2182 test_https_protocol();
2183 test_ftp_protocol();
2184 test_gopher_protocol();
2186 test_CreateBinding();
2187 test_binding(FILE_TEST);
2188 test_binding(HTTP_TEST);
2190 CloseHandle(event_complete);
2191 CloseHandle(event_complete2);