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(ReportData);
78 DEFINE_EXPECT(ReportResult);
79 DEFINE_EXPECT(GetBindString_ACCEPT_MIMES);
80 DEFINE_EXPECT(GetBindString_USER_AGENT);
81 DEFINE_EXPECT(GetBindString_POST_COOKIE);
82 DEFINE_EXPECT(QueryService_HttpNegotiate);
83 DEFINE_EXPECT(QueryService_InternetProtocol);
84 DEFINE_EXPECT(BeginningTransaction);
85 DEFINE_EXPECT(GetRootSecurityId);
86 DEFINE_EXPECT(OnResponse);
87 DEFINE_EXPECT(Switch);
88 DEFINE_EXPECT(Continue);
89 DEFINE_EXPECT(CreateInstance);
91 DEFINE_EXPECT(Terminate);
93 DEFINE_EXPECT(SetPriority);
94 DEFINE_EXPECT(LockRequest);
95 DEFINE_EXPECT(UnlockRequest);
97 static const WCHAR wszIndexHtml[] = {'i','n','d','e','x','.','h','t','m','l',0};
98 static const WCHAR index_url[] =
99 {'f','i','l','e',':','i','n','d','e','x','.','h','t','m','l',0};
101 static const WCHAR acc_mimeW[] = {'*','/','*',0};
102 static const WCHAR user_agentW[] = {'W','i','n','e',0};
103 static const WCHAR text_htmlW[] = {'t','e','x','t','/','h','t','m','l',0};
104 static const WCHAR hostW[] = {'w','w','w','.','w','i','n','e','h','q','.','o','r','g',0};
105 static const WCHAR winehq_ipW[] = {'2','0','9','.','4','6','.','2','5','.','1','3','4',0};
106 static const WCHAR emptyW[] = {0};
108 static HRESULT expect_hrResult;
109 static LPCWSTR file_name, http_url, expect_wsz;
110 static IInternetProtocol *http_protocol = NULL;
111 static BOOL first_data_notif = FALSE, http_is_first = FALSE,
112 http_post_test = FALSE;
113 static int state = 0, prot_state;
114 static DWORD bindf = 0, ex_priority = 0;
115 static IInternetProtocol *binding_protocol;
116 static IInternetBindInfo *prot_bind_info;
117 static IInternetProtocolSink *binding_sink;
118 static void *expect_pv;
119 static HANDLE event_complete, event_complete2;
120 static BOOL binding_test;
121 static PROTOCOLDATA protocoldata, *pdata;
122 static DWORD prot_read;
131 static const WCHAR protocol_names[][10] = {
138 static const WCHAR binding_urls[][30] = {
139 {'f','i','l','e',':','t','e','s','t','.','h','t','m','l',0},
140 {'h','t','t','p',':','/','/','t','e','s','t','/','t','e','s','t','.','h','t','m','l',0},
141 {'m','k',':','t','e','s','t',0},
142 {'t','e','s','t',':','/','/','f','i','l','e','.','h','t','m','l',0}
145 static const char *debugstr_w(LPCWSTR str)
147 static char buf[512];
150 WideCharToMultiByte(CP_ACP, 0, str, -1, buf, sizeof(buf), NULL, NULL);
154 static const char *debugstr_guid(REFIID riid)
158 sprintf(buf, "{%08X-%04X-%04X-%02X%02X-%02X%02X%02X%02X%02X%02X}",
159 riid->Data1, riid->Data2, riid->Data3, riid->Data4[0],
160 riid->Data4[1], riid->Data4[2], riid->Data4[3], riid->Data4[4],
161 riid->Data4[5], riid->Data4[6], riid->Data4[7]);
166 static HRESULT WINAPI HttpNegotiate_QueryInterface(IHttpNegotiate2 *iface, REFIID riid, void **ppv)
168 if(IsEqualGUID(&IID_IUnknown, riid)
169 || IsEqualGUID(&IID_IHttpNegotiate, riid)
170 || IsEqualGUID(&IID_IHttpNegotiate2, riid)) {
175 ok(0, "unexpected call\n");
176 return E_NOINTERFACE;
179 static ULONG WINAPI HttpNegotiate_AddRef(IHttpNegotiate2 *iface)
184 static ULONG WINAPI HttpNegotiate_Release(IHttpNegotiate2 *iface)
189 static HRESULT WINAPI HttpNegotiate_BeginningTransaction(IHttpNegotiate2 *iface, LPCWSTR szURL,
190 LPCWSTR szHeaders, DWORD dwReserved, LPWSTR *pszAdditionalHeaders)
194 static const WCHAR wszHeaders[] =
195 {'C','o','n','t','e','n','t','-','T','y','p','e',':',' ','a','p','p','l','i','c','a','t',
196 'i','o','n','/','x','-','w','w','w','-','f','o','r','m','-','u','r','l','e','n','c','o',
197 'd','e','d','\r','\n',0};
199 CHECK_EXPECT(BeginningTransaction);
202 ok(!lstrcmpW(szURL, binding_urls[tested_protocol]), "szURL != http_url\n");
204 ok(!lstrcmpW(szURL, http_url), "szURL != http_url\n");
205 ok(!dwReserved, "dwReserved=%d, expected 0\n", dwReserved);
206 ok(pszAdditionalHeaders != NULL, "pszAdditionalHeaders == NULL\n");
207 if(pszAdditionalHeaders)
209 ok(*pszAdditionalHeaders == NULL, "*pszAdditionalHeaders != NULL\n");
212 addl_headers = CoTaskMemAlloc(sizeof(wszHeaders));
215 http_post_test = FALSE;
216 skip("Out of memory\n");
217 return E_OUTOFMEMORY;
219 lstrcpyW(addl_headers, wszHeaders);
220 *pszAdditionalHeaders = addl_headers;
227 static HRESULT WINAPI HttpNegotiate_OnResponse(IHttpNegotiate2 *iface, DWORD dwResponseCode,
228 LPCWSTR szResponseHeaders, LPCWSTR szRequestHeaders, LPWSTR *pszAdditionalRequestHeaders)
230 CHECK_EXPECT(OnResponse);
232 ok(dwResponseCode == 200, "dwResponseCode=%d, expected 200\n", dwResponseCode);
233 ok(szResponseHeaders != NULL, "szResponseHeaders == NULL\n");
234 ok(szRequestHeaders == NULL, "szRequestHeaders != NULL\n");
235 ok(pszAdditionalRequestHeaders == NULL, "pszAdditionalHeaders != NULL\n");
240 static HRESULT WINAPI HttpNegotiate_GetRootSecurityId(IHttpNegotiate2 *iface,
241 BYTE *pbSecurityId, DWORD *pcbSecurityId, DWORD_PTR dwReserved)
243 static const BYTE sec_id[] = {'h','t','t','p',':','t','e','s','t',1,0,0,0};
245 CHECK_EXPECT(GetRootSecurityId);
247 ok(!dwReserved, "dwReserved=%ld, expected 0\n", dwReserved);
248 ok(pbSecurityId != NULL, "pbSecurityId == NULL\n");
249 ok(pcbSecurityId != NULL, "pcbSecurityId == NULL\n");
252 ok(*pcbSecurityId == 512, "*pcbSecurityId=%d, expected 512\n", *pcbSecurityId);
253 *pcbSecurityId = sizeof(sec_id);
257 memcpy(pbSecurityId, sec_id, sizeof(sec_id));
262 static IHttpNegotiate2Vtbl HttpNegotiateVtbl = {
263 HttpNegotiate_QueryInterface,
264 HttpNegotiate_AddRef,
265 HttpNegotiate_Release,
266 HttpNegotiate_BeginningTransaction,
267 HttpNegotiate_OnResponse,
268 HttpNegotiate_GetRootSecurityId
271 static IHttpNegotiate2 http_negotiate = { &HttpNegotiateVtbl };
273 static HRESULT QueryInterface(REFIID,void**);
275 static HRESULT WINAPI ServiceProvider_QueryInterface(IServiceProvider *iface, REFIID riid, void **ppv)
277 return QueryInterface(riid, ppv);
280 static ULONG WINAPI ServiceProvider_AddRef(IServiceProvider *iface)
285 static ULONG WINAPI ServiceProvider_Release(IServiceProvider *iface)
290 static HRESULT WINAPI ServiceProvider_QueryService(IServiceProvider *iface, REFGUID guidService,
291 REFIID riid, void **ppv)
293 if(IsEqualGUID(&IID_IHttpNegotiate, guidService) || IsEqualGUID(&IID_IHttpNegotiate2, riid)) {
294 CHECK_EXPECT2(QueryService_HttpNegotiate);
295 return IHttpNegotiate2_QueryInterface(&http_negotiate, riid, ppv);
298 if(IsEqualGUID(&IID_IInternetProtocol, guidService)) {
299 ok(IsEqualGUID(&IID_IInternetProtocol, riid), "unexpected riid\n");
300 CHECK_EXPECT(QueryService_InternetProtocol);
301 return E_NOINTERFACE;
304 ok(0, "unexpected service %s\n", debugstr_guid(guidService));
308 static const IServiceProviderVtbl ServiceProviderVtbl = {
309 ServiceProvider_QueryInterface,
310 ServiceProvider_AddRef,
311 ServiceProvider_Release,
312 ServiceProvider_QueryService
315 static IServiceProvider service_provider = { &ServiceProviderVtbl };
317 static HRESULT WINAPI ProtocolSink_QueryInterface(IInternetProtocolSink *iface, REFIID riid, void **ppv)
319 return QueryInterface(riid, ppv);
322 static ULONG WINAPI ProtocolSink_AddRef(IInternetProtocolSink *iface)
327 static ULONG WINAPI ProtocolSink_Release(IInternetProtocolSink *iface)
332 static HRESULT WINAPI ProtocolSink_Switch(IInternetProtocolSink *iface, PROTOCOLDATA *pProtocolData)
336 CHECK_EXPECT(Switch);
337 ok(pProtocolData != NULL, "pProtocolData == NULL\n");
339 pdata = pProtocolData;
342 SetEvent(event_complete);
343 WaitForSingleObject(event_complete2, INFINITE);
349 CHECK_CALLED(ReportProgress_FINDINGRESOURCE);
350 CHECK_CALLED(ReportProgress_CONNECTING);
352 CHECK_NOT_CALLED(ReportProgress_FINDINGRESOURCE);
353 /* IE7 does call this */
354 CLEAR_CALLED(ReportProgress_CONNECTING);
356 CHECK_CALLED(ReportProgress_SENDINGREQUEST);
357 SET_EXPECT(OnResponse);
358 SET_EXPECT(ReportProgress_MIMETYPEAVAILABLE);
359 if(bindf & BINDF_NEEDFILE)
360 SET_EXPECT(ReportProgress_CACHEFILENAMEAVAILABLE);
363 SET_EXPECT(ReportData);
364 hres = IInternetProtocol_Continue(http_protocol, pProtocolData);
365 ok(hres == S_OK, "Continue failed: %08x\n", hres);
366 CHECK_CALLED(ReportData);
370 CHECK_CALLED(OnResponse);
371 CHECK_CALLED(ReportProgress_MIMETYPEAVAILABLE);
372 if(bindf & BINDF_NEEDFILE)
373 CHECK_CALLED(ReportProgress_CACHEFILENAMEAVAILABLE);
376 SetEvent(event_complete);
381 static HRESULT WINAPI ProtocolSink_ReportProgress(IInternetProtocolSink *iface, ULONG ulStatusCode,
382 LPCWSTR szStatusText)
384 static const WCHAR null_guid[] = {'{','0','0','0','0','0','0','0','0','-','0','0','0','0','-',
385 '0','0','0','0','-','0','0','0','0','-','0','0','0','0','0','0','0','0','0','0','0','0','}',0};
386 static const WCHAR text_plain[] = {'t','e','x','t','/','p','l','a','i','n',0};
387 static const WCHAR post_host[] =
388 {'c','r','o','s','s','o','v','e','r','.','c','o','d','e',
389 'w','e','a','v','e','r','s','.','c','o','m',0};
390 static const WCHAR wszCrossoverIP[] =
391 {'2','0','9','.','4','6','.','2','5','.','1','3','2',0};
392 /* I'm not sure if it's a good idea to hardcode here the IP address... */
394 switch(ulStatusCode) {
395 case BINDSTATUS_MIMETYPEAVAILABLE:
396 CHECK_EXPECT(ReportProgress_MIMETYPEAVAILABLE);
397 ok(szStatusText != NULL, "szStatusText == NULL\n");
399 if(tested_protocol == BIND_TEST)
400 ok(szStatusText == expect_wsz, "unexpected szStatusText\n");
401 else if (http_post_test)
402 ok(lstrlenW(text_plain) <= lstrlenW(szStatusText) &&
403 !memcmp(szStatusText, text_plain, lstrlenW(text_plain)*sizeof(WCHAR)),
404 "szStatusText != text/plain\n");
406 ok(lstrlenW(text_htmlW) <= lstrlenW(szStatusText) &&
407 !memcmp(szStatusText, text_htmlW, lstrlenW(text_htmlW)*sizeof(WCHAR)),
408 "szStatusText != text/html\n");
411 case BINDSTATUS_DIRECTBIND:
412 CHECK_EXPECT2(ReportProgress_DIRECTBIND);
413 ok(szStatusText == NULL, "szStatusText != NULL\n");
415 case BINDSTATUS_RAWMIMETYPE:
416 CHECK_EXPECT2(ReportProgress_RAWMIMETYPE);
417 ok(szStatusText != NULL, "szStatusText == NULL\n");
419 ok(lstrlenW(szStatusText) < lstrlenW(text_htmlW) ||
420 !memcmp(szStatusText, text_htmlW, lstrlenW(text_htmlW)*sizeof(WCHAR)),
421 "szStatusText != text/html\n");
423 case BINDSTATUS_CACHEFILENAMEAVAILABLE:
424 CHECK_EXPECT(ReportProgress_CACHEFILENAMEAVAILABLE);
425 ok(szStatusText != NULL, "szStatusText == NULL\n");
428 ok(!lstrcmpW(szStatusText, expect_wsz), "unexpected szStatusText\n");
429 else if(tested_protocol == FILE_TEST)
430 ok(!lstrcmpW(szStatusText, file_name), "szStatusText = \"%s\"\n", debugstr_w(szStatusText));
432 ok(szStatusText != NULL, "szStatusText == NULL\n");
435 case BINDSTATUS_FINDINGRESOURCE:
436 CHECK_EXPECT(ReportProgress_FINDINGRESOURCE);
437 ok(szStatusText != NULL, "szStatusText == NULL\n");
441 ok(!lstrcmpW(szStatusText, hostW),
442 "szStatustext != \"www.winehq.org\"\n");
444 ok(!lstrcmpW(szStatusText, post_host),
445 "szStatustext != \"crossover.codeweavers.com\"\n");
448 case BINDSTATUS_CONNECTING:
449 CHECK_EXPECT(ReportProgress_CONNECTING);
450 ok(szStatusText != NULL, "szStatusText == NULL\n");
452 ok(!lstrcmpW(szStatusText, http_post_test ?
453 wszCrossoverIP : winehq_ipW),
454 "Unexpected szStatusText\n");
456 case BINDSTATUS_SENDINGREQUEST:
457 CHECK_EXPECT(ReportProgress_SENDINGREQUEST);
458 if(tested_protocol == FILE_TEST) {
459 ok(szStatusText != NULL, "szStatusText == NULL\n");
461 ok(!*szStatusText, "wrong szStatusText\n");
464 case BINDSTATUS_VERIFIEDMIMETYPEAVAILABLE:
465 CHECK_EXPECT(ReportProgress_VERIFIEDMIMETYPEAVAILABLE);
466 ok(szStatusText != NULL, "szStatusText == NULL\n");
468 ok(!lstrcmpW(szStatusText, text_htmlW), "szStatusText != text/html\n");
470 case BINDSTATUS_PROTOCOLCLASSID:
471 CHECK_EXPECT(ReportProgress_PROTOCOLCLASSID);
472 ok(szStatusText != NULL, "szStatusText == NULL\n");
473 ok(!lstrcmpW(szStatusText, null_guid), "unexpected szStatusText\n");
475 case BINDSTATUS_COOKIE_SENT:
476 CHECK_EXPECT(ReportProgress_COOKIE_SENT);
477 ok(szStatusText == NULL, "szStatusText != NULL\n");
479 case BINDSTATUS_REDIRECTING:
480 CHECK_EXPECT(ReportProgress_REDIRECTING);
481 ok(szStatusText == NULL, "szStatusText != NULL\n");
484 ok(0, "Unexpected status %d\n", ulStatusCode);
490 static HRESULT WINAPI ProtocolSink_ReportData(IInternetProtocolSink *iface, DWORD grfBSCF,
491 ULONG ulProgress, ULONG ulProgressMax)
493 if(tested_protocol == FILE_TEST) {
494 CHECK_EXPECT2(ReportData);
496 ok(ulProgress == ulProgressMax, "ulProgress (%d) != ulProgressMax (%d)\n",
497 ulProgress, ulProgressMax);
498 ok(ulProgressMax == 13, "ulProgressMax=%d, expected 13\n", ulProgressMax);
499 ok(grfBSCF == (BSCF_FIRSTDATANOTIFICATION | BSCF_LASTDATANOTIFICATION),
500 "grcfBSCF = %08x\n", grfBSCF);
501 }else if(!binding_test && tested_protocol == HTTP_TEST) {
502 if(!(grfBSCF & BSCF_LASTDATANOTIFICATION))
503 CHECK_EXPECT(ReportData);
504 else if (http_post_test)
505 ok(ulProgress == 13, "Read %u bytes instead of 13\n", ulProgress);
507 ok(ulProgress, "ulProgress == 0\n");
509 if(first_data_notif) {
510 ok(grfBSCF == BSCF_FIRSTDATANOTIFICATION, "grcfBSCF = %08x\n", grfBSCF);
511 first_data_notif = FALSE;
513 ok(grfBSCF == BSCF_INTERMEDIATEDATANOTIFICATION
514 || grfBSCF == (BSCF_LASTDATANOTIFICATION|BSCF_INTERMEDIATEDATANOTIFICATION),
515 "grcfBSCF = %08x\n", grfBSCF);
518 if(!(bindf & BINDF_FROMURLMON) &&
519 !(grfBSCF & BSCF_LASTDATANOTIFICATION)) {
523 CHECK_CALLED(ReportProgress_FINDINGRESOURCE);
524 CHECK_CALLED(ReportProgress_CONNECTING);
526 CHECK_NOT_CALLED(ReportProgress_FINDINGRESOURCE);
527 CHECK_NOT_CALLED(ReportProgress_CONNECTING);
529 CHECK_CALLED(ReportProgress_SENDINGREQUEST);
530 CHECK_CALLED(OnResponse);
531 CHECK_CALLED(ReportProgress_RAWMIMETYPE);
533 SetEvent(event_complete);
540 CHECK_EXPECT(ReportData);
542 if(tested_protocol == BIND_TEST)
547 hres = IInternetProtocol_Read(binding_protocol, expect_pv=buf, sizeof(buf), &read);
549 }while(hres == S_OK);
555 static HRESULT WINAPI ProtocolSink_ReportResult(IInternetProtocolSink *iface, HRESULT hrResult,
556 DWORD dwError, LPCWSTR szResult)
558 CHECK_EXPECT(ReportResult);
560 ok(hrResult == expect_hrResult, "hrResult = %08x, expected: %08x\n",
561 hrResult, expect_hrResult);
562 if(SUCCEEDED(hrResult))
563 ok(dwError == ERROR_SUCCESS, "dwError = %d, expected ERROR_SUCCESS\n", dwError);
565 ok(dwError != ERROR_SUCCESS, "dwError == ERROR_SUCCESS\n");
566 ok(!szResult, "szResult != NULL\n");
571 static IInternetProtocolSinkVtbl protocol_sink_vtbl = {
572 ProtocolSink_QueryInterface,
574 ProtocolSink_Release,
576 ProtocolSink_ReportProgress,
577 ProtocolSink_ReportData,
578 ProtocolSink_ReportResult
581 static IInternetProtocolSink protocol_sink = { &protocol_sink_vtbl };
583 static HRESULT QueryInterface(REFIID riid, void **ppv)
587 if(IsEqualGUID(&IID_IUnknown, riid) || IsEqualGUID(&IID_IInternetProtocolSink, riid))
588 *ppv = &protocol_sink;
589 if(IsEqualGUID(&IID_IServiceProvider, riid))
590 *ppv = &service_provider;
595 return E_NOINTERFACE;
598 static HRESULT WINAPI BindInfo_QueryInterface(IInternetBindInfo *iface, REFIID riid, void **ppv)
600 if(IsEqualGUID(&IID_IUnknown, riid) || IsEqualGUID(&IID_IInternetBindInfo, riid)) {
604 return E_NOINTERFACE;
607 static ULONG WINAPI BindInfo_AddRef(IInternetBindInfo *iface)
612 static ULONG WINAPI BindInfo_Release(IInternetBindInfo *iface)
617 static HRESULT WINAPI BindInfo_GetBindInfo(IInternetBindInfo *iface, DWORD *grfBINDF, BINDINFO *pbindinfo)
621 static const CHAR szPostData[] = "mode=Test";
623 CHECK_EXPECT(GetBindInfo);
625 ok(grfBINDF != NULL, "grfBINDF == NULL\n");
626 ok(pbindinfo != NULL, "pbindinfo == NULL\n");
627 ok(pbindinfo->cbSize == sizeof(BINDINFO), "wrong size of pbindinfo: %d\n", pbindinfo->cbSize);
631 *grfBINDF |= BINDF_FROMURLMON;
632 cbSize = pbindinfo->cbSize;
633 memset(pbindinfo, 0, cbSize);
634 pbindinfo->cbSize = cbSize;
638 /* Must be GMEM_FIXED, GMEM_MOVABLE does not work properly
639 * with urlmon on native (Win98 and WinXP) */
640 U(pbindinfo->stgmedData).hGlobal = GlobalAlloc(GPTR, sizeof(szPostData));
641 if (!U(pbindinfo->stgmedData).hGlobal)
643 http_post_test = FALSE;
644 skip("Out of memory\n");
645 return E_OUTOFMEMORY;
647 lstrcpy((LPSTR)U(pbindinfo->stgmedData).hGlobal, szPostData);
648 pbindinfo->cbstgmedData = sizeof(szPostData)-1;
649 pbindinfo->dwBindVerb = BINDVERB_POST;
650 pbindinfo->stgmedData.tymed = TYMED_HGLOBAL;
656 static HRESULT WINAPI BindInfo_GetBindString(IInternetBindInfo *iface, ULONG ulStringType,
657 LPOLESTR *ppwzStr, ULONG cEl, ULONG *pcElFetched)
659 ok(ppwzStr != NULL, "ppwzStr == NULL\n");
660 ok(pcElFetched != NULL, "pcElFetched == NULL\n");
662 switch(ulStringType) {
663 case BINDSTRING_ACCEPT_MIMES:
664 CHECK_EXPECT(GetBindString_ACCEPT_MIMES);
665 ok(cEl == 256, "cEl=%d, expected 256\n", cEl);
667 ok(*pcElFetched == 256, "*pcElFetched=%d, expected 256\n", *pcElFetched);
671 *ppwzStr = CoTaskMemAlloc(sizeof(acc_mimeW));
672 memcpy(*ppwzStr, acc_mimeW, sizeof(acc_mimeW));
675 case BINDSTRING_USER_AGENT:
676 CHECK_EXPECT(GetBindString_USER_AGENT);
677 ok(cEl == 1, "cEl=%d, expected 1\n", cEl);
679 ok(*pcElFetched == 0, "*pcElFetch=%d, expectd 0\n", *pcElFetched);
683 *ppwzStr = CoTaskMemAlloc(sizeof(user_agentW));
684 memcpy(*ppwzStr, user_agentW, sizeof(user_agentW));
687 case BINDSTRING_POST_COOKIE:
688 CHECK_EXPECT(GetBindString_POST_COOKIE);
689 ok(cEl == 1, "cEl=%d, expected 1\n", cEl);
691 ok(*pcElFetched == 0, "*pcElFetch=%d, expectd 0\n", *pcElFetched);
694 ok(0, "unexpected call\n");
700 static IInternetBindInfoVtbl bind_info_vtbl = {
701 BindInfo_QueryInterface,
704 BindInfo_GetBindInfo,
705 BindInfo_GetBindString
708 static IInternetBindInfo bind_info = { &bind_info_vtbl };
710 static HRESULT WINAPI InternetPriority_QueryInterface(IInternetPriority *iface,
711 REFIID riid, void **ppv)
713 ok(0, "unexpected call\n");
714 return E_NOINTERFACE;
717 static ULONG WINAPI InternetPriority_AddRef(IInternetPriority *iface)
722 static ULONG WINAPI InternetPriority_Release(IInternetPriority *iface)
727 static HRESULT WINAPI InternetPriority_SetPriority(IInternetPriority *iface, LONG nPriority)
729 CHECK_EXPECT(SetPriority);
730 ok(nPriority == ex_priority, "nPriority=%d\n", nPriority);
734 static HRESULT WINAPI InternetPriority_GetPriority(IInternetPriority *iface, LONG *pnPriority)
736 ok(0, "unexpected call\n");
741 static const IInternetPriorityVtbl InternetPriorityVtbl = {
742 InternetPriority_QueryInterface,
743 InternetPriority_AddRef,
744 InternetPriority_Release,
745 InternetPriority_SetPriority,
746 InternetPriority_GetPriority
749 static IInternetPriority InternetPriority = { &InternetPriorityVtbl };
751 static HRESULT WINAPI Protocol_QueryInterface(IInternetProtocol *iface, REFIID riid, void **ppv)
753 if(IsEqualGUID(&IID_IUnknown, riid) || IsEqualGUID(&IID_IInternetProtocol, riid)) {
758 if(IsEqualGUID(&IID_IInternetPriority, riid)) {
759 *ppv = &InternetPriority;
763 ok(0, "unexpected riid %s\n", debugstr_guid(riid));
765 return E_NOINTERFACE;
768 static ULONG WINAPI Protocol_AddRef(IInternetProtocol *iface)
773 static ULONG WINAPI Protocol_Release(IInternetProtocol *iface)
778 static DWORD WINAPI thread_proc(PVOID arg)
782 memset(&protocoldata, -1, sizeof(protocoldata));
786 SET_EXPECT(ReportProgress_FINDINGRESOURCE);
787 hres = IInternetProtocolSink_ReportProgress(binding_sink,
788 BINDSTATUS_FINDINGRESOURCE, hostW);
789 CHECK_CALLED(ReportProgress_FINDINGRESOURCE);
790 ok(hres == S_OK, "ReportProgress failed: %08x\n", hres);
792 SET_EXPECT(ReportProgress_CONNECTING);
793 hres = IInternetProtocolSink_ReportProgress(binding_sink,
794 BINDSTATUS_CONNECTING, winehq_ipW);
795 CHECK_CALLED(ReportProgress_CONNECTING);
796 ok(hres == S_OK, "ReportProgress failed: %08x\n", hres);
798 SET_EXPECT(ReportProgress_SENDINGREQUEST);
799 hres = IInternetProtocolSink_ReportProgress(binding_sink,
800 BINDSTATUS_SENDINGREQUEST, NULL);
801 CHECK_CALLED(ReportProgress_SENDINGREQUEST);
802 ok(hres == S_OK, "ReportProgress failed: %08x\n", hres);
806 hres = IInternetProtocolSink_Switch(binding_sink, &protocoldata);
807 CHECK_CALLED(Switch);
808 ok(hres == S_OK, "Switch failed: %08x\n", hres);
812 hres = IInternetProtocolSink_Switch(binding_sink, &protocoldata);
813 CHECK_CALLED(Switch);
814 ok(hres == S_OK, "Switch failed: %08x\n", hres);
818 hres = IInternetProtocolSink_Switch(binding_sink, &protocoldata);
819 CHECK_CALLED(Switch);
820 ok(hres == S_OK, "Switch failed: %08x\n", hres);
824 hres = IInternetProtocolSink_Switch(binding_sink, &protocoldata);
825 CHECK_CALLED(Switch);
826 ok(hres == S_OK, "Switch failed: %08x\n", hres);
828 SetEvent(event_complete);
833 static HRESULT WINAPI Protocol_Start(IInternetProtocol *iface, LPCWSTR szUrl,
834 IInternetProtocolSink *pOIProtSink, IInternetBindInfo *pOIBindInfo,
835 DWORD grfPI, DWORD dwReserved)
837 BINDINFO bindinfo, exp_bindinfo;
843 ok(pOIProtSink != NULL, "pOIProtSink == NULL\n");
844 ok(pOIBindInfo != NULL, "pOIBindInfo == NULL\n");
845 ok(pOIProtSink != &protocol_sink, "unexpected pOIProtSink\n");
846 ok(pOIBindInfo != &bind_info, "unexpected pOIBindInfo\n");
847 ok(!grfPI, "grfPI = %x\n", grfPI);
848 ok(!dwReserved, "dwReserved = %d\n", dwReserved);
850 memset(&bindinfo, 0, sizeof(bindinfo));
851 bindinfo.cbSize = sizeof(bindinfo);
852 memcpy(&exp_bindinfo, &bindinfo, sizeof(bindinfo));
853 SET_EXPECT(GetBindInfo);
854 hres = IInternetBindInfo_GetBindInfo(pOIBindInfo, &cbindf, &bindinfo);
855 ok(hres == S_OK, "GetBindInfo failed: %08x\n", hres);
856 CHECK_CALLED(GetBindInfo);
857 ok(cbindf == (bindf|BINDF_FROMURLMON), "bindf = %x, expected %x\n",
858 cbindf, (bindf|BINDF_FROMURLMON));
859 ok(!memcmp(&exp_bindinfo, &bindinfo, sizeof(bindinfo)), "unexpected bindinfo\n");
860 ReleaseBindInfo(&bindinfo);
862 SET_EXPECT(ReportProgress_SENDINGREQUEST);
863 hres = IInternetProtocolSink_ReportProgress(pOIProtSink, BINDSTATUS_SENDINGREQUEST, emptyW);
864 ok(hres == S_OK, "ReportProgress(BINDSTATUS_SENDINGREQUEST) failed: %08x\n", hres);
865 CHECK_CALLED(ReportProgress_SENDINGREQUEST);
867 if(tested_protocol == HTTP_TEST) {
868 IServiceProvider *service_provider;
869 IHttpNegotiate *http_negotiate;
870 IHttpNegotiate2 *http_negotiate2;
871 LPWSTR ua = (LPWSTR)0xdeadbeef, accept_mimes[256];
872 LPWSTR additional_headers = NULL;
874 DWORD fetched = 0, size = 100;
877 SET_EXPECT(GetBindString_USER_AGENT);
878 hres = IInternetBindInfo_GetBindString(pOIBindInfo, BINDSTRING_USER_AGENT,
880 CHECK_CALLED(GetBindString_USER_AGENT);
881 ok(hres == S_OK, "GetBindString(BINDSTRING_USER_AGETNT) failed: %08x\n", hres);
882 ok(fetched == 1, "fetched = %d, expected 254\n", fetched);
883 ok(ua != NULL, "ua = %p\n", ua);
884 ok(!lstrcmpW(ua, user_agentW), "unexpected user agent %s\n", debugstr_w(ua));
888 SET_EXPECT(GetBindString_ACCEPT_MIMES);
889 hres = IInternetBindInfo_GetBindString(pOIBindInfo, BINDSTRING_ACCEPT_MIMES,
890 accept_mimes, 256, &fetched);
891 CHECK_CALLED(GetBindString_ACCEPT_MIMES);
894 "GetBindString(BINDSTRING_ACCEPT_MIMES) failed: %08x\n", hres);
895 ok(fetched == 1, "fetched = %d, expected 1\n", fetched);
896 ok(!lstrcmpW(acc_mimeW, accept_mimes[0]), "unexpected mimes %s\n", debugstr_w(accept_mimes[0]));
898 hres = IInternetBindInfo_QueryInterface(pOIBindInfo, &IID_IServiceProvider,
899 (void**)&service_provider);
900 ok(hres == S_OK, "QueryInterface failed: %08x\n", hres);
902 SET_EXPECT(QueryService_HttpNegotiate);
903 hres = IServiceProvider_QueryService(service_provider, &IID_IHttpNegotiate,
904 &IID_IHttpNegotiate, (void**)&http_negotiate);
905 CHECK_CALLED(QueryService_HttpNegotiate);
906 ok(hres == S_OK, "QueryService failed: %08x\n", hres);
908 SET_EXPECT(BeginningTransaction);
909 hres = IHttpNegotiate_BeginningTransaction(http_negotiate, binding_urls[tested_protocol],
910 NULL, 0, &additional_headers);
911 CHECK_CALLED(BeginningTransaction);
912 IHttpNegotiate_Release(http_negotiate);
913 ok(hres == S_OK, "BeginningTransction failed: %08x\n", hres);
914 ok(additional_headers == NULL, "additional_headers=%p\n", additional_headers);
916 SET_EXPECT(QueryService_HttpNegotiate);
917 hres = IServiceProvider_QueryService(service_provider, &IID_IHttpNegotiate2,
918 &IID_IHttpNegotiate2, (void**)&http_negotiate2);
919 CHECK_CALLED(QueryService_HttpNegotiate);
920 ok(hres == S_OK, "QueryService failed: %08x\n", hres);
923 SET_EXPECT(GetRootSecurityId);
924 hres = IHttpNegotiate2_GetRootSecurityId(http_negotiate2, sec_id, &size, 0);
925 CHECK_CALLED(GetRootSecurityId);
926 IHttpNegotiate2_Release(http_negotiate2);
927 ok(hres == E_FAIL, "GetRootSecurityId failed: %08x, expected E_FAIL\n", hres);
928 ok(size == 13, "size=%d\n", size);
930 IServiceProvider_Release(service_provider);
932 CreateThread(NULL, 0, thread_proc, NULL, 0, &tid);
937 SET_EXPECT(ReportProgress_CACHEFILENAMEAVAILABLE);
938 hres = IInternetProtocolSink_ReportProgress(pOIProtSink,
939 BINDSTATUS_CACHEFILENAMEAVAILABLE, expect_wsz = emptyW);
940 ok(hres == S_OK, "ReportProgress(BINDSTATUS_CACHEFILENAMEAVAILABLE) failed: %08x\n", hres);
941 CHECK_CALLED(ReportProgress_CACHEFILENAMEAVAILABLE);
943 SET_EXPECT(ReportProgress_MIMETYPEAVAILABLE);
944 hres = IInternetProtocolSink_ReportProgress(pOIProtSink, BINDSTATUS_VERIFIEDMIMETYPEAVAILABLE,
945 expect_wsz = text_htmlW);
947 "ReportProgress(BINDSTATUS_VERIFIEDMIMETYPEAVAILABLE) failed: %08x\n", hres);
948 CHECK_CALLED(ReportProgress_MIMETYPEAVAILABLE);
950 SET_EXPECT(ReportData);
951 hres = IInternetProtocolSink_ReportData(pOIProtSink,
952 BSCF_FIRSTDATANOTIFICATION | BSCF_LASTDATANOTIFICATION, 13, 13);
953 ok(hres == S_OK, "ReportData failed: %08x\n", hres);
954 CHECK_CALLED(ReportData);
956 if(tested_protocol == BIND_TEST) {
957 hres = IInternetProtocol_Terminate(binding_protocol, 0);
958 ok(hres == E_FAIL, "Termiante failed: %08x\n", hres);
961 SET_EXPECT(ReportResult);
962 hres = IInternetProtocolSink_ReportResult(pOIProtSink, S_OK, 0, NULL);
963 ok(hres == S_OK, "ReportResult failed: %08x\n", hres);
964 CHECK_CALLED(ReportResult);
969 static HRESULT WINAPI Protocol_Continue(IInternetProtocol *iface,
970 PROTOCOLDATA *pProtocolData)
975 CHECK_EXPECT(Continue);
977 ok(pProtocolData != NULL, "pProtocolData == NULL\n");
978 if(!pProtocolData || tested_protocol == BIND_TEST)
983 IServiceProvider *service_provider;
984 IHttpNegotiate *http_negotiate;
985 static WCHAR header[] = {'?',0};
987 hres = IInternetProtocolSink_QueryInterface(binding_sink, &IID_IServiceProvider,
988 (void**)&service_provider);
989 ok(hres == S_OK, "Could not get IServiceProvicder\n");
991 SET_EXPECT(QueryService_HttpNegotiate);
992 hres = IServiceProvider_QueryService(service_provider, &IID_IHttpNegotiate,
993 &IID_IHttpNegotiate, (void**)&http_negotiate);
994 IServiceProvider_Release(service_provider);
995 CHECK_CALLED(QueryService_HttpNegotiate);
996 ok(hres == S_OK, "Could not get IHttpNegotiate\n");
998 SET_EXPECT(OnResponse);
999 hres = IHttpNegotiate_OnResponse(http_negotiate, 200, header, NULL, NULL);
1000 IHttpNegotiate_Release(http_negotiate);
1001 CHECK_CALLED(OnResponse);
1002 IHttpNegotiate_Release(http_negotiate);
1003 ok(hres == S_OK, "OnResponse failed: %08x\n", hres);
1005 SET_EXPECT(ReportProgress_MIMETYPEAVAILABLE);
1006 hres = IInternetProtocolSink_ReportProgress(binding_sink,
1007 BINDSTATUS_MIMETYPEAVAILABLE, text_htmlW);
1008 CHECK_CALLED(ReportProgress_MIMETYPEAVAILABLE);
1010 "ReportProgress(BINDSTATUS_MIMETYPEAVAILABLE) failed: %08x\n", hres);
1012 bscf |= BSCF_FIRSTDATANOTIFICATION;
1017 bscf = BSCF_INTERMEDIATEDATANOTIFICATION;
1021 SET_EXPECT(ReportData);
1022 hres = IInternetProtocolSink_ReportData(binding_sink, bscf, 100, 400);
1023 CHECK_CALLED(ReportData);
1024 ok(hres == S_OK, "ReportData failed: %08x\n", hres);
1032 static HRESULT WINAPI Protocol_Abort(IInternetProtocol *iface, HRESULT hrReason,
1035 ok(0, "unexpected call\n");
1039 static HRESULT WINAPI Protocol_Terminate(IInternetProtocol *iface, DWORD dwOptions)
1041 CHECK_EXPECT(Terminate);
1042 ok(!dwOptions, "dwOptions=%d\n", dwOptions);
1046 static HRESULT WINAPI Protocol_Suspend(IInternetProtocol *iface)
1048 ok(0, "unexpected call\n");
1052 static HRESULT WINAPI Protocol_Resume(IInternetProtocol *iface)
1054 ok(0, "unexpected call\n");
1058 static HRESULT WINAPI Protocol_Read(IInternetProtocol *iface, void *pv,
1059 ULONG cb, ULONG *pcbRead)
1061 static BOOL b = TRUE;
1065 ok(pv == expect_pv, "pv != expect_pv\n");
1066 ok(cb == 1000, "cb=%d\n", cb);
1067 ok(pcbRead != NULL, "pcbRead == NULL\n");
1068 ok(!*pcbRead, "*pcbRead = %d\n", *pcbRead);
1070 if(prot_state == 3) {
1073 SET_EXPECT(ReportResult);
1074 hres = IInternetProtocolSink_ReportResult(binding_sink, S_OK, ERROR_SUCCESS, NULL);
1075 CHECK_CALLED(ReportResult);
1081 return tested_protocol == HTTP_TEST ? E_PENDING : S_FALSE;
1083 memset(pv, 'x', 100);
1084 prot_read += *pcbRead = 100;
1088 static HRESULT WINAPI Protocol_Seek(IInternetProtocol *iface,
1089 LARGE_INTEGER dlibMove, DWORD dwOrigin, ULARGE_INTEGER *plibNewPosition)
1091 ok(0, "unexpected call\n");
1095 static HRESULT WINAPI Protocol_LockRequest(IInternetProtocol *iface, DWORD dwOptions)
1097 CHECK_EXPECT(LockRequest);
1098 ok(dwOptions == 0, "dwOptions=%x\n", dwOptions);
1102 static HRESULT WINAPI Protocol_UnlockRequest(IInternetProtocol *iface)
1104 CHECK_EXPECT(UnlockRequest);
1108 static const IInternetProtocolVtbl ProtocolVtbl = {
1109 Protocol_QueryInterface,
1120 Protocol_LockRequest,
1121 Protocol_UnlockRequest
1124 static IInternetProtocol Protocol = { &ProtocolVtbl };
1126 static HRESULT WINAPI ClassFactory_QueryInterface(IClassFactory *iface, REFIID riid, void **ppv)
1128 ok(0, "unexpected call\n");
1129 return E_NOINTERFACE;
1132 static ULONG WINAPI ClassFactory_AddRef(IClassFactory *iface)
1137 static ULONG WINAPI ClassFactory_Release(IClassFactory *iface)
1142 static HRESULT WINAPI ClassFactory_CreateInstance(IClassFactory *iface, IUnknown *pOuter,
1143 REFIID riid, void **ppv)
1145 CHECK_EXPECT(CreateInstance);
1147 ok(pOuter == (IUnknown*)prot_bind_info, "pOuter != protocol_unk\n");
1148 ok(IsEqualGUID(&IID_IUnknown, riid), "unexpected riid %s\n", debugstr_guid(riid));
1149 ok(ppv != NULL, "ppv == NULL\n");
1155 static HRESULT WINAPI ClassFactory_LockServer(IClassFactory *iface, BOOL dolock)
1157 ok(0, "unexpected call\n");
1161 static const IClassFactoryVtbl ClassFactoryVtbl = {
1162 ClassFactory_QueryInterface,
1163 ClassFactory_AddRef,
1164 ClassFactory_Release,
1165 ClassFactory_CreateInstance,
1166 ClassFactory_LockServer
1169 static IClassFactory ClassFactory = { &ClassFactoryVtbl };
1171 static void test_priority(IInternetProtocol *protocol)
1173 IInternetPriority *priority;
1177 hres = IInternetProtocol_QueryInterface(protocol, &IID_IInternetPriority,
1179 ok(hres == S_OK, "QueryInterface(IID_IInternetPriority) failed: %08x\n", hres);
1183 hres = IInternetPriority_GetPriority(priority, &pr);
1184 ok(hres == S_OK, "GetPriority failed: %08x\n", hres);
1185 ok(pr == 0, "pr=%d, expected 0\n", pr);
1187 hres = IInternetPriority_SetPriority(priority, 1);
1188 ok(hres == S_OK, "SetPriority failed: %08x\n", hres);
1190 hres = IInternetPriority_GetPriority(priority, &pr);
1191 ok(hres == S_OK, "GetPriority failed: %08x\n", hres);
1192 ok(pr == 1, "pr=%d, expected 1\n", pr);
1194 IInternetPriority_Release(priority);
1197 static BOOL file_protocol_start(IInternetProtocol *protocol, LPCWSTR url, BOOL is_first)
1201 SET_EXPECT(GetBindInfo);
1202 if(!(bindf & BINDF_FROMURLMON))
1203 SET_EXPECT(ReportProgress_DIRECTBIND);
1205 SET_EXPECT(ReportProgress_SENDINGREQUEST);
1206 SET_EXPECT(ReportProgress_CACHEFILENAMEAVAILABLE);
1207 if(bindf & BINDF_FROMURLMON)
1208 SET_EXPECT(ReportProgress_VERIFIEDMIMETYPEAVAILABLE);
1210 SET_EXPECT(ReportProgress_MIMETYPEAVAILABLE);
1212 SET_EXPECT(ReportData);
1214 SET_EXPECT(ReportResult);
1216 expect_hrResult = S_OK;
1218 hres = IInternetProtocol_Start(protocol, url, &protocol_sink, &bind_info, 0, 0);
1219 if(hres == INET_E_RESOURCE_NOT_FOUND) {
1220 win_skip("Start failed\n");
1223 ok(hres == S_OK, "Start failed: %08x\n", hres);
1225 CHECK_CALLED(GetBindInfo);
1226 if(!(bindf & BINDF_FROMURLMON))
1227 CHECK_CALLED(ReportProgress_DIRECTBIND);
1229 CHECK_CALLED(ReportProgress_SENDINGREQUEST);
1230 CHECK_CALLED(ReportProgress_CACHEFILENAMEAVAILABLE);
1231 if(bindf & BINDF_FROMURLMON)
1232 CHECK_CALLED(ReportProgress_VERIFIEDMIMETYPEAVAILABLE);
1234 CHECK_CALLED(ReportProgress_MIMETYPEAVAILABLE);
1236 CHECK_CALLED(ReportData);
1238 CHECK_CALLED(ReportResult);
1243 static void test_file_protocol_url(LPCWSTR url)
1245 IInternetProtocolInfo *protocol_info;
1247 IClassFactory *factory;
1250 hres = CoGetClassObject(&CLSID_FileProtocol, CLSCTX_INPROC_SERVER, NULL,
1251 &IID_IUnknown, (void**)&unk);
1252 ok(hres == S_OK, "CoGetClassObject failed: %08x\n", hres);
1253 if(!SUCCEEDED(hres))
1256 hres = IUnknown_QueryInterface(unk, &IID_IInternetProtocolInfo, (void**)&protocol_info);
1257 ok(hres == E_NOINTERFACE,
1258 "Could not get IInternetProtocolInfo interface: %08x, expected E_NOINTERFACE\n", hres);
1260 hres = IUnknown_QueryInterface(unk, &IID_IClassFactory, (void**)&factory);
1261 ok(hres == S_OK, "Could not get IClassFactory interface\n");
1262 if(SUCCEEDED(hres)) {
1263 IInternetProtocol *protocol;
1266 hres = IClassFactory_CreateInstance(factory, NULL, &IID_IInternetProtocol, (void**)&protocol);
1267 ok(hres == S_OK, "Could not get IInternetProtocol: %08x\n", hres);
1269 if(SUCCEEDED(hres)) {
1270 if(file_protocol_start(protocol, url, TRUE)) {
1271 hres = IInternetProtocol_Read(protocol, buf, 2, &cb);
1272 ok(hres == S_OK, "Read failed: %08x\n", hres);
1273 ok(cb == 2, "cb=%u expected 2\n", cb);
1274 hres = IInternetProtocol_Read(protocol, buf, sizeof(buf), &cb);
1275 ok(hres == S_FALSE, "Read failed: %08x\n", hres);
1276 hres = IInternetProtocol_Read(protocol, buf, sizeof(buf), &cb);
1277 ok(hres == S_FALSE, "Read failed: %08x expected S_FALSE\n", hres);
1278 ok(cb == 0, "cb=%u expected 0\n", cb);
1279 hres = IInternetProtocol_UnlockRequest(protocol);
1280 ok(hres == S_OK, "UnlockRequest failed: %08x\n", hres);
1283 if(file_protocol_start(protocol, url, FALSE)) {
1284 hres = IInternetProtocol_Read(protocol, buf, 2, &cb);
1285 ok(hres == S_FALSE, "Read failed: %08x\n", hres);
1286 hres = IInternetProtocol_LockRequest(protocol, 0);
1287 ok(hres == S_OK, "LockRequest failed: %08x\n", hres);
1288 hres = IInternetProtocol_UnlockRequest(protocol);
1289 ok(hres == S_OK, "UnlockRequest failed: %08x\n", hres);
1292 IInternetProtocol_Release(protocol);
1295 hres = IClassFactory_CreateInstance(factory, NULL, &IID_IInternetProtocol, (void**)&protocol);
1296 ok(hres == S_OK, "Could not get IInternetProtocol: %08x\n", hres);
1298 if(SUCCEEDED(hres)) {
1299 if(file_protocol_start(protocol, url, TRUE)) {
1300 hres = IInternetProtocol_LockRequest(protocol, 0);
1301 ok(hres == S_OK, "LockRequest failed: %08x\n", hres);
1302 hres = IInternetProtocol_Terminate(protocol, 0);
1303 ok(hres == S_OK, "Terminate failed: %08x\n", hres);
1304 hres = IInternetProtocol_Read(protocol, buf, 2, &cb);
1305 ok(hres == S_OK, "Read failed: %08x\n\n", hres);
1306 hres = IInternetProtocol_UnlockRequest(protocol);
1307 ok(hres == S_OK, "UnlockRequest failed: %08x\n", hres);
1308 hres = IInternetProtocol_Read(protocol, buf, 2, &cb);
1309 ok(hres == S_OK, "Read failed: %08x\n", hres);
1310 hres = IInternetProtocol_Terminate(protocol, 0);
1311 ok(hres == S_OK, "Terminate failed: %08x\n", hres);
1314 IInternetProtocol_Release(protocol);
1317 hres = IClassFactory_CreateInstance(factory, NULL, &IID_IInternetProtocol, (void**)&protocol);
1318 ok(hres == S_OK, "Could not get IInternetProtocol: %08x\n", hres);
1320 if(SUCCEEDED(hres)) {
1321 if(file_protocol_start(protocol, url, TRUE)) {
1322 hres = IInternetProtocol_Terminate(protocol, 0);
1323 ok(hres == S_OK, "Terminate failed: %08x\n", hres);
1324 hres = IInternetProtocol_Read(protocol, buf, 2, &cb);
1325 ok(hres == S_OK, "Read failed: %08x\n", hres);
1326 ok(cb == 2, "cb=%u expected 2\n", cb);
1329 IInternetProtocol_Release(protocol);
1332 IClassFactory_Release(factory);
1335 IUnknown_Release(unk);
1338 static void test_file_protocol_fail(void)
1340 IInternetProtocol *protocol;
1343 static const WCHAR index_url2[] =
1344 {'f','i','l','e',':','/','/','i','n','d','e','x','.','h','t','m','l',0};
1346 hres = CoCreateInstance(&CLSID_FileProtocol, NULL, CLSCTX_INPROC_SERVER|CLSCTX_INPROC_HANDLER,
1347 &IID_IInternetProtocol, (void**)&protocol);
1348 ok(hres == S_OK, "CoCreateInstance failed: %08x\n", hres);
1352 SET_EXPECT(GetBindInfo);
1353 expect_hrResult = MK_E_SYNTAX;
1354 hres = IInternetProtocol_Start(protocol, wszIndexHtml, &protocol_sink, &bind_info, 0, 0);
1355 ok(hres == MK_E_SYNTAX ||
1356 hres == E_INVALIDARG,
1357 "Start failed: %08x, expected MK_E_SYNTAX or E_INVALIDARG\n", hres);
1358 CLEAR_CALLED(GetBindInfo); /* GetBindInfo not called in IE7 */
1360 SET_EXPECT(GetBindInfo);
1361 if(!(bindf & BINDF_FROMURLMON))
1362 SET_EXPECT(ReportProgress_DIRECTBIND);
1363 SET_EXPECT(ReportProgress_SENDINGREQUEST);
1364 SET_EXPECT(ReportResult);
1365 expect_hrResult = INET_E_RESOURCE_NOT_FOUND;
1366 hres = IInternetProtocol_Start(protocol, index_url, &protocol_sink, &bind_info, 0, 0);
1367 ok(hres == INET_E_RESOURCE_NOT_FOUND,
1368 "Start failed: %08x expected INET_E_RESOURCE_NOT_FOUND\n", hres);
1369 CHECK_CALLED(GetBindInfo);
1370 if(!(bindf & BINDF_FROMURLMON))
1371 CHECK_CALLED(ReportProgress_DIRECTBIND);
1372 CHECK_CALLED(ReportProgress_SENDINGREQUEST);
1373 CHECK_CALLED(ReportResult);
1375 IInternetProtocol_Release(protocol);
1377 hres = CoCreateInstance(&CLSID_FileProtocol, NULL, CLSCTX_INPROC_SERVER|CLSCTX_INPROC_HANDLER,
1378 &IID_IInternetProtocol, (void**)&protocol);
1379 ok(hres == S_OK, "CoCreateInstance failed: %08x\n", hres);
1383 SET_EXPECT(GetBindInfo);
1384 if(!(bindf & BINDF_FROMURLMON))
1385 SET_EXPECT(ReportProgress_DIRECTBIND);
1386 SET_EXPECT(ReportProgress_SENDINGREQUEST);
1387 SET_EXPECT(ReportResult);
1388 expect_hrResult = INET_E_RESOURCE_NOT_FOUND;
1390 hres = IInternetProtocol_Start(protocol, index_url2, &protocol_sink, &bind_info, 0, 0);
1391 ok(hres == INET_E_RESOURCE_NOT_FOUND,
1392 "Start failed: %08x, expected INET_E_RESOURCE_NOT_FOUND\n", hres);
1393 CHECK_CALLED(GetBindInfo);
1394 if(!(bindf & BINDF_FROMURLMON))
1395 CHECK_CALLED(ReportProgress_DIRECTBIND);
1396 CHECK_CALLED(ReportProgress_SENDINGREQUEST);
1397 CHECK_CALLED(ReportResult);
1399 SET_EXPECT(GetBindInfo);
1400 hres = IInternetProtocol_Start(protocol, NULL, &protocol_sink, &bind_info, 0, 0);
1401 ok(hres == E_INVALIDARG, "Start failed: %08x, expected E_INVALIDARG\n", hres);
1402 CLEAR_CALLED(GetBindInfo); /* GetBindInfo not called in IE7 */
1404 SET_EXPECT(GetBindInfo);
1405 hres = IInternetProtocol_Start(protocol, emptyW, &protocol_sink, &bind_info, 0, 0);
1406 ok(hres == E_INVALIDARG, "Start failed: %08x, expected E_INVALIDARG\n", hres);
1407 CLEAR_CALLED(GetBindInfo); /* GetBindInfo not called in IE7 */
1409 IInternetProtocol_Release(protocol);
1412 static void test_file_protocol(void) {
1413 WCHAR buf[INTERNET_MAX_URL_LENGTH], file_name_buf[MAX_PATH];
1418 static const WCHAR wszFile[] = {'f','i','l','e',':',0};
1419 static const WCHAR wszFile2[] = {'f','i','l','e',':','/','/',0};
1420 static const WCHAR wszFile3[] = {'f','i','l','e',':','/','/','/',0};
1421 static const char html_doc[] = "<HTML></HTML>";
1423 trace("Testing file protocol...\n");
1424 tested_protocol = FILE_TEST;
1426 file = CreateFileW(wszIndexHtml, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS,
1427 FILE_ATTRIBUTE_NORMAL, NULL);
1428 ok(file != INVALID_HANDLE_VALUE, "CreateFile failed\n");
1429 if(file == INVALID_HANDLE_VALUE)
1431 WriteFile(file, html_doc, sizeof(html_doc)-1, &size, NULL);
1434 file_name = wszIndexHtml;
1436 test_file_protocol_url(index_url);
1437 bindf = BINDF_FROMURLMON;
1438 test_file_protocol_url(index_url);
1439 bindf = BINDF_FROMURLMON | BINDF_NEEDFILE;
1440 test_file_protocol_url(index_url);
1442 memcpy(buf, wszFile, sizeof(wszFile));
1443 len = sizeof(wszFile)/sizeof(WCHAR)-1;
1444 len += GetCurrentDirectoryW(sizeof(buf)/sizeof(WCHAR)-len, buf+len);
1446 memcpy(buf+len, wszIndexHtml, sizeof(wszIndexHtml));
1448 file_name = buf + sizeof(wszFile)/sizeof(WCHAR)-1;
1450 test_file_protocol_url(buf);
1451 bindf = BINDF_FROMURLMON;
1452 test_file_protocol_url(buf);
1454 memcpy(buf, wszFile2, sizeof(wszFile2));
1455 len = GetCurrentDirectoryW(sizeof(file_name_buf)/sizeof(WCHAR), file_name_buf);
1456 file_name_buf[len++] = '\\';
1457 memcpy(file_name_buf+len, wszIndexHtml, sizeof(wszIndexHtml));
1458 lstrcpyW(buf+sizeof(wszFile2)/sizeof(WCHAR)-1, file_name_buf);
1459 file_name = file_name_buf;
1461 test_file_protocol_url(buf);
1462 bindf = BINDF_FROMURLMON;
1463 test_file_protocol_url(buf);
1465 buf[sizeof(wszFile2)/sizeof(WCHAR)] = '|';
1466 test_file_protocol_url(buf);
1468 memcpy(buf, wszFile3, sizeof(wszFile3));
1469 len = sizeof(wszFile3)/sizeof(WCHAR)-1;
1470 len += GetCurrentDirectoryW(sizeof(buf)/sizeof(WCHAR)-len, buf+len);
1472 memcpy(buf+len, wszIndexHtml, sizeof(wszIndexHtml));
1474 file_name = buf + sizeof(wszFile3)/sizeof(WCHAR)-1;
1476 test_file_protocol_url(buf);
1477 bindf = BINDF_FROMURLMON;
1478 test_file_protocol_url(buf);
1480 DeleteFileW(wszIndexHtml);
1483 test_file_protocol_fail();
1484 bindf = BINDF_FROMURLMON;
1485 test_file_protocol_fail();
1488 static BOOL http_protocol_start(LPCWSTR url, BOOL is_first)
1490 static BOOL got_user_agent = FALSE;
1493 first_data_notif = TRUE;
1496 SET_EXPECT(GetBindInfo);
1497 if (!(bindf & BINDF_FROMURLMON))
1498 SET_EXPECT(ReportProgress_DIRECTBIND);
1499 SET_EXPECT(GetBindString_USER_AGENT);
1500 SET_EXPECT(GetBindString_ACCEPT_MIMES);
1501 SET_EXPECT(QueryService_HttpNegotiate);
1502 SET_EXPECT(BeginningTransaction);
1503 SET_EXPECT(GetRootSecurityId);
1505 SET_EXPECT(GetBindString_POST_COOKIE);
1507 hres = IInternetProtocol_Start(http_protocol, url, &protocol_sink, &bind_info, 0, 0);
1508 ok(hres == S_OK, "Start failed: %08x\n", hres);
1512 CHECK_CALLED(GetBindInfo);
1513 if (!(bindf & BINDF_FROMURLMON))
1514 CHECK_CALLED(ReportProgress_DIRECTBIND);
1515 if (!got_user_agent)
1517 CHECK_CALLED(GetBindString_USER_AGENT);
1518 got_user_agent = TRUE;
1522 /* user agent only retrieved once, even with different URLs */
1523 CHECK_NOT_CALLED(GetBindString_USER_AGENT);
1525 CHECK_CALLED(GetBindString_ACCEPT_MIMES);
1526 CHECK_CALLED(QueryService_HttpNegotiate);
1527 CHECK_CALLED(BeginningTransaction);
1528 /* GetRootSecurityId called on WinXP but not on Win98 */
1529 CLEAR_CALLED(GetRootSecurityId);
1531 CHECK_CALLED(GetBindString_POST_COOKIE);
1536 /* is_first refers to whether this is the first call to this function
1538 static void test_http_protocol_url(LPCWSTR url, BOOL is_first)
1540 IInternetProtocolInfo *protocol_info;
1541 IClassFactory *factory;
1546 http_is_first = is_first;
1548 hres = CoGetClassObject(&CLSID_HttpProtocol, CLSCTX_INPROC_SERVER, NULL, &IID_IUnknown, (void**)&unk);
1549 ok(hres == S_OK, "CoGetClassObject failed: %08x\n", hres);
1550 if(!SUCCEEDED(hres))
1553 hres = IUnknown_QueryInterface(unk, &IID_IInternetProtocolInfo, (void**)&protocol_info);
1554 ok(hres == E_NOINTERFACE,
1555 "Could not get IInternetProtocolInfo interface: %08x, expected E_NOINTERFACE\n",
1558 hres = IUnknown_QueryInterface(unk, &IID_IClassFactory, (void**)&factory);
1559 ok(hres == S_OK, "Could not get IClassFactory interface\n");
1560 IUnknown_Release(unk);
1564 hres = IClassFactory_CreateInstance(factory, NULL, &IID_IInternetProtocol,
1565 (void**)&http_protocol);
1566 ok(hres == S_OK, "Could not get IInternetProtocol: %08x\n", hres);
1567 if(SUCCEEDED(hres)) {
1571 test_priority(http_protocol);
1573 SET_EXPECT(ReportProgress_FINDINGRESOURCE);
1574 SET_EXPECT(ReportProgress_CONNECTING);
1575 SET_EXPECT(ReportProgress_SENDINGREQUEST);
1576 if(!(bindf & BINDF_FROMURLMON)) {
1577 SET_EXPECT(OnResponse);
1578 SET_EXPECT(ReportProgress_RAWMIMETYPE);
1579 SET_EXPECT(ReportData);
1584 if(!http_protocol_start(url, is_first))
1587 SET_EXPECT(ReportResult);
1588 expect_hrResult = S_OK;
1590 hres = IInternetProtocol_Read(http_protocol, buf, 1, &cb);
1591 ok((hres == E_PENDING && cb==0) ||
1592 (hres == S_OK && cb==1), "Read failed: %08x (%d bytes)\n", hres, cb);
1594 WaitForSingleObject(event_complete, INFINITE);
1595 if(bindf & BINDF_FROMURLMON)
1596 CHECK_CALLED(Switch);
1598 CHECK_CALLED(ReportData);
1601 if(bindf & BINDF_FROMURLMON)
1604 SET_EXPECT(ReportData);
1605 hres = IInternetProtocol_Read(http_protocol, buf, sizeof(buf), &cb);
1606 if(hres == E_PENDING) {
1607 hres = IInternetProtocol_Read(http_protocol, buf, 1, &cb);
1608 ok((hres == E_PENDING && cb==0) ||
1609 (hres == S_OK && cb==1), "Read failed: %08x (%d bytes)\n", hres, cb);
1610 WaitForSingleObject(event_complete, INFINITE);
1611 if(bindf & BINDF_FROMURLMON)
1612 CHECK_CALLED(Switch);
1614 CHECK_CALLED(ReportData);
1616 if(bindf & BINDF_FROMURLMON)
1617 CHECK_NOT_CALLED(Switch);
1619 CHECK_NOT_CALLED(ReportData);
1623 ok(hres == S_FALSE, "Read failed: %08x\n", hres);
1624 CHECK_CALLED(ReportResult);
1626 hres = IInternetProtocol_LockRequest(http_protocol, 0);
1627 ok(hres == S_OK, "LockRequest failed: %08x\n", hres);
1629 hres = IInternetProtocol_Read(http_protocol, buf, 1, &cb);
1630 ok(hres == S_FALSE, "Read failed: %08x\n", hres);
1632 hres = IInternetProtocol_Terminate(http_protocol, 0);
1633 ok(hres == S_OK, "Terminate failed: %08x\n", hres);
1635 /* This wait is to give the internet handles being freed in Terminate
1636 * enough time to actually terminate in all cases. Internet handles
1637 * terminate asynchronously and native reuses the main InternetOpen
1638 * handle. The only case in which this seems to be necessary is on
1639 * wine with native wininet and urlmon, resulting in the next time
1640 * test_http_protocol_url being called the first data notification actually
1641 * being an extra last data notification from the previous connection
1642 * about once out of every ten times. */
1645 hres = IInternetProtocol_UnlockRequest(http_protocol);
1646 ok(hres == S_OK, "UnlockRequest failed: %08x\n", hres);
1648 IInternetProtocol_Release(http_protocol);
1651 IClassFactory_Release(factory);
1654 static void test_http_protocol(void)
1656 static const WCHAR winehq_url[] =
1657 {'h','t','t','p',':','/','/','w','w','w','.','w','i','n','e','h','q','.',
1658 'o','r','g','/','s','i','t','e','/','a','b','o','u','t',0};
1659 static const WCHAR posttest_url[] =
1660 {'h','t','t','p',':','/','/','c','r','o','s','s','o','v','e','r','.',
1661 'c','o','d','e','w','e','a','v','e','r','s','.','c','o','m','/',
1662 'p','o','s','t','t','e','s','t','.','p','h','p',0};
1664 trace("Testing http protocol (not from urlmon)...\n");
1665 tested_protocol = HTTP_TEST;
1666 bindf = BINDF_ASYNCHRONOUS | BINDF_ASYNCSTORAGE | BINDF_PULLDATA;
1667 test_http_protocol_url(winehq_url, TRUE);
1669 trace("Testing http protocol (from urlmon)...\n");
1670 bindf = BINDF_ASYNCHRONOUS | BINDF_ASYNCSTORAGE | BINDF_PULLDATA | BINDF_FROMURLMON;
1671 test_http_protocol_url(winehq_url, FALSE);
1673 trace("Testing http protocol (to file)...\n");
1674 bindf = BINDF_ASYNCHRONOUS | BINDF_ASYNCSTORAGE | BINDF_PULLDATA | BINDF_FROMURLMON | BINDF_NEEDFILE;
1675 test_http_protocol_url(winehq_url, FALSE);
1677 trace("Testing http protocol (post data)...\n");
1678 http_post_test = TRUE;
1679 /* Without this flag we get a ReportProgress_CACHEFILENAMEAVAILABLE
1680 * notification with BINDVERB_POST */
1681 bindf = BINDF_ASYNCHRONOUS | BINDF_ASYNCSTORAGE | BINDF_PULLDATA | BINDF_FROMURLMON | BINDF_NOWRITECACHE;
1682 test_http_protocol_url(posttest_url, TRUE);
1683 http_post_test = FALSE;
1686 static void test_mk_protocol(void)
1688 IInternetProtocolInfo *protocol_info;
1689 IInternetProtocol *protocol;
1690 IClassFactory *factory;
1694 static const WCHAR wrong_url1[] = {'t','e','s','t',':','@','M','S','I','T','S','t','o','r','e',
1695 ':',':','/','t','e','s','t','.','h','t','m','l',0};
1696 static const WCHAR wrong_url2[] = {'m','k',':','/','t','e','s','t','.','h','t','m','l',0};
1698 trace("Testing mk protocol...\n");
1699 tested_protocol = MK_TEST;
1701 hres = CoGetClassObject(&CLSID_MkProtocol, CLSCTX_INPROC_SERVER, NULL,
1702 &IID_IUnknown, (void**)&unk);
1703 ok(hres == S_OK, "CoGetClassObject failed: %08x\n", hres);
1705 hres = IUnknown_QueryInterface(unk, &IID_IInternetProtocolInfo, (void**)&protocol_info);
1706 ok(hres == E_NOINTERFACE,
1707 "Could not get IInternetProtocolInfo interface: %08x, expected E_NOINTERFACE\n",
1710 hres = IUnknown_QueryInterface(unk, &IID_IClassFactory, (void**)&factory);
1711 ok(hres == S_OK, "Could not get IClassFactory interface\n");
1712 IUnknown_Release(unk);
1716 hres = IClassFactory_CreateInstance(factory, NULL, &IID_IInternetProtocol,
1718 IClassFactory_Release(factory);
1719 ok(hres == S_OK, "Could not get IInternetProtocol: %08x\n", hres);
1721 SET_EXPECT(GetBindInfo);
1722 hres = IInternetProtocol_Start(protocol, wrong_url1, &protocol_sink, &bind_info, 0, 0);
1723 ok(hres == MK_E_SYNTAX || hres == INET_E_INVALID_URL,
1724 "Start failed: %08x, expected MK_E_SYNTAX or INET_E_INVALID_URL\n", hres);
1725 CLEAR_CALLED(GetBindInfo);
1727 SET_EXPECT(GetBindInfo);
1728 SET_EXPECT(ReportProgress_DIRECTBIND);
1729 SET_EXPECT(ReportProgress_SENDINGREQUEST);
1730 SET_EXPECT(ReportProgress_MIMETYPEAVAILABLE);
1731 SET_EXPECT(ReportResult);
1732 expect_hrResult = INET_E_RESOURCE_NOT_FOUND;
1734 hres = IInternetProtocol_Start(protocol, wrong_url2, &protocol_sink, &bind_info, 0, 0);
1735 ok(hres == INET_E_RESOURCE_NOT_FOUND ||
1736 hres == INET_E_INVALID_URL, /* win2k3 */
1737 "Start failed: %08x, expected INET_E_RESOURCE_NOT_FOUND or INET_E_INVALID_URL\n", hres);
1739 if (hres == INET_E_RESOURCE_NOT_FOUND) {
1740 CHECK_CALLED(GetBindInfo);
1741 CLEAR_CALLED(ReportProgress_DIRECTBIND);
1742 CHECK_CALLED(ReportProgress_SENDINGREQUEST);
1743 CHECK_CALLED(ReportProgress_MIMETYPEAVAILABLE);
1744 CHECK_CALLED(ReportResult);
1746 CLEAR_CALLED(GetBindInfo);
1747 CLEAR_CALLED(ReportProgress_DIRECTBIND);
1748 CLEAR_CALLED(ReportProgress_SENDINGREQUEST);
1749 CLEAR_CALLED(ReportProgress_MIMETYPEAVAILABLE);
1750 CLEAR_CALLED(ReportResult);
1753 IInternetProtocol_Release(protocol);
1756 static void test_CreateBinding(void)
1758 IInternetProtocolSink *sink;
1759 IInternetProtocol *protocol;
1760 IInternetPriority *priority;
1761 IInternetSession *session;
1767 static const WCHAR test_url[] =
1768 {'t','e','s','t',':','/','/','f','i','l','e','.','h','t','m','l',0};
1769 static const WCHAR wsz_test[] = {'t','e','s','t',0};
1771 trace("Testing CreateBinding...\n");
1772 tested_protocol = BIND_TEST;
1773 binding_test = TRUE;
1775 hres = CoInternetGetSession(0, &session, 0);
1776 ok(hres == S_OK, "CoInternetGetSession failed: %08x\n", hres);
1778 hres = IInternetSession_RegisterNameSpace(session, &ClassFactory, &IID_NULL, wsz_test, 0, NULL, 0);
1779 ok(hres == S_OK, "RegisterNameSpace failed: %08x\n", hres);
1781 hres = IInternetSession_CreateBinding(session, NULL, test_url, NULL, NULL, &protocol, 0);
1782 binding_protocol = protocol;
1783 ok(hres == S_OK, "CreateBinding failed: %08x\n", hres);
1784 ok(protocol != NULL, "protocol == NULL\n");
1786 hres = IInternetProtocol_QueryInterface(protocol, &IID_IInternetBindInfo, (void**)&prot_bind_info);
1787 ok(hres == S_OK, "QueryInterface(IID_IInternetBindInfo) failed: %08x\n", hres);
1789 hres = IInternetProtocol_QueryInterface(protocol, &IID_IInternetProtocolSink, (void**)&sink);
1790 ok(hres == S_OK, "Could not get IInternetProtocolSink: %08x\n", hres);
1792 hres = IInternetProtocol_Start(protocol, test_url, NULL, &bind_info, 0, 0);
1793 ok(hres == E_INVALIDARG, "Start failed: %08x, expected E_INVALIDARG\n", hres);
1794 hres = IInternetProtocol_Start(protocol, test_url, &protocol_sink, NULL, 0, 0);
1795 ok(hres == E_INVALIDARG, "Start failed: %08x, expected E_INVALIDARG\n", hres);
1796 hres = IInternetProtocol_Start(protocol, NULL, &protocol_sink, &bind_info, 0, 0);
1797 ok(hres == E_INVALIDARG, "Start failed: %08x, expected E_INVALIDARG\n", hres);
1799 hres = IInternetProtocol_QueryInterface(protocol, &IID_IInternetPriority, (void**)&priority);
1800 ok(hres == S_OK, "QueryInterface(IID_IInternetPriority) failed: %08x\n", hres);
1803 hres = IInternetPriority_GetPriority(priority, &p);
1804 ok(hres == S_OK, "GetPriority failed: %08x\n", hres);
1805 ok(!p, "p=%d\n", p);
1808 hres = IInternetPriority_SetPriority(priority, 100);
1809 ok(hres == S_OK, "SetPriority failed: %08x\n", hres);
1812 hres = IInternetPriority_GetPriority(priority, &p);
1813 ok(hres == S_OK, "GetPriority failed: %08x\n", hres);
1814 ok(p == 100, "p=%d\n", p);
1816 SET_EXPECT(QueryService_InternetProtocol);
1817 SET_EXPECT(CreateInstance);
1818 SET_EXPECT(ReportProgress_PROTOCOLCLASSID);
1819 SET_EXPECT(SetPriority);
1822 expect_hrResult = S_OK;
1823 hres = IInternetProtocol_Start(protocol, test_url, &protocol_sink, &bind_info, 0, 0);
1824 ok(hres == S_OK, "Start failed: %08x\n", hres);
1826 CHECK_CALLED(QueryService_InternetProtocol);
1827 CHECK_CALLED(CreateInstance);
1828 CHECK_CALLED(ReportProgress_PROTOCOLCLASSID);
1829 CHECK_CALLED(SetPriority);
1830 CHECK_CALLED(Start);
1834 hres = IInternetProtocol_Read(protocol, expect_pv = buf, sizeof(buf), &read);
1835 ok(hres == S_OK, "Read failed: %08x\n", hres);
1836 ok(read == 100, "read = %d\n", read);
1841 hres = IInternetProtocol_Read(protocol, expect_pv = buf, sizeof(buf), &read);
1842 ok(hres == S_FALSE, "Read failed: %08x\n", hres);
1843 ok(!read, "read = %d\n", read);
1847 hres = IInternetPriority_GetPriority(priority, &p);
1848 ok(hres == S_OK, "GetPriority failed: %08x\n", hres);
1849 ok(p == 100, "p=%d\n", p);
1851 hres = IInternetPriority_SetPriority(priority, 101);
1852 ok(hres == S_OK, "SetPriority failed: %08x\n", hres);
1854 SET_EXPECT(Terminate);
1855 hres = IInternetProtocol_Terminate(protocol, 0xdeadbeef);
1856 ok(hres == S_OK, "Terminate failed: %08x\n", hres);
1857 CHECK_CALLED(Terminate);
1859 SET_EXPECT(Continue);
1860 hres = IInternetProtocolSink_Switch(sink, &protocoldata);
1861 ok(hres == S_OK, "Switch failed: %08x\n", hres);
1862 CHECK_CALLED(Continue);
1864 hres = IInternetProtocolSink_ReportProgress(sink,
1865 BINDSTATUS_CACHEFILENAMEAVAILABLE, expect_wsz = emptyW);
1866 ok(hres == S_OK, "ReportProgress(BINDSTATUS_CACHEFILENAMEAVAILABLE) failed: %08x\n", hres);
1868 hres = IInternetProtocolSink_ReportResult(sink, S_OK, ERROR_SUCCESS, NULL);
1869 ok(hres == E_FAIL, "ReportResult failed: %08x, expected E_FAIL\n", hres);
1871 hres = IInternetProtocolSink_ReportData(sink, 0, 0, 0);
1872 ok(hres == S_OK, "ReportData failed: %08x\n", hres);
1874 IInternetProtocolSink_Release(sink);
1875 IInternetPriority_Release(priority);
1876 IInternetBindInfo_Release(prot_bind_info);
1877 IInternetProtocol_Release(protocol);
1878 IInternetSession_Release(session);
1881 static void test_binding(int prot)
1883 IInternetProtocol *protocol;
1884 IInternetSession *session;
1888 trace("Testing %s binding...\n", debugstr_w(protocol_names[prot]));
1890 tested_protocol = prot;
1891 binding_test = TRUE;
1892 first_data_notif = TRUE;
1895 hres = CoInternetGetSession(0, &session, 0);
1896 ok(hres == S_OK, "CoInternetGetSession failed: %08x\n", hres);
1898 hres = IInternetSession_RegisterNameSpace(session, &ClassFactory, &IID_NULL, protocol_names[prot], 0, NULL, 0);
1899 ok(hres == S_OK, "RegisterNameSpace failed: %08x\n", hres);
1901 hres = IInternetSession_CreateBinding(session, NULL, binding_urls[prot], NULL, NULL, &protocol, 0);
1902 binding_protocol = protocol;
1903 IInternetSession_Release(session);
1904 ok(hres == S_OK, "CreateBinding failed: %08x\n", hres);
1905 ok(protocol != NULL, "protocol == NULL\n");
1907 hres = IInternetProtocol_QueryInterface(protocol, &IID_IInternetBindInfo, (void**)&prot_bind_info);
1908 ok(hres == S_OK, "QueryInterface(IID_IInternetBindInfo) failed: %08x\n", hres);
1910 hres = IInternetProtocol_QueryInterface(protocol, &IID_IInternetProtocolSink, (void**)&binding_sink);
1911 ok(hres == S_OK, "QueryInterface(IID_IInternetProtocolSink) failed: %08x\n", hres);
1914 SET_EXPECT(QueryService_InternetProtocol);
1915 SET_EXPECT(CreateInstance);
1916 SET_EXPECT(ReportProgress_PROTOCOLCLASSID);
1917 SET_EXPECT(SetPriority);
1920 expect_hrResult = S_OK;
1921 hres = IInternetProtocol_Start(protocol, binding_urls[prot], &protocol_sink, &bind_info, 0, 0);
1922 ok(hres == S_OK, "Start failed: %08x\n", hres);
1924 CHECK_CALLED(QueryService_InternetProtocol);
1925 CHECK_CALLED(CreateInstance);
1926 CHECK_CALLED(ReportProgress_PROTOCOLCLASSID);
1927 CHECK_CALLED(SetPriority);
1928 CHECK_CALLED(Start);
1930 if(prot == HTTP_TEST) {
1931 while(prot_state < 4) {
1932 WaitForSingleObject(event_complete, INFINITE);
1933 SET_EXPECT(Continue);
1934 IInternetProtocol_Continue(protocol, pdata);
1935 CHECK_CALLED(Continue);
1936 SetEvent(event_complete2);
1939 WaitForSingleObject(event_complete, INFINITE);
1941 SET_EXPECT(LockRequest);
1942 hres = IInternetProtocol_LockRequest(protocol, 0);
1943 ok(hres == S_OK, "LockRequest failed: %08x\n", hres);
1944 CHECK_CALLED(LockRequest);
1946 SET_EXPECT(UnlockRequest);
1947 hres = IInternetProtocol_UnlockRequest(protocol);
1948 ok(hres == S_OK, "UnlockRequest failed: %08x\n", hres);
1949 CHECK_CALLED(UnlockRequest);
1952 SET_EXPECT(Terminate);
1953 hres = IInternetProtocol_Terminate(protocol, 0);
1954 ok(hres == S_OK, "Terminate failed: %08x\n", hres);
1955 CHECK_CALLED(Terminate);
1957 IInternetBindInfo_Release(prot_bind_info);
1958 IInternetProtocolSink_Release(binding_sink);
1959 ref = IInternetProtocol_Release(protocol);
1960 ok(!ref, "ref=%u, expected 0\n", ref);
1963 START_TEST(protocol)
1965 OleInitialize(NULL);
1967 event_complete = CreateEvent(NULL, FALSE, FALSE, NULL);
1968 event_complete2 = CreateEvent(NULL, FALSE, FALSE, NULL);
1970 test_file_protocol();
1971 test_http_protocol();
1973 test_CreateBinding();
1974 test_binding(FILE_TEST);
1975 test_binding(HTTP_TEST);
1977 CloseHandle(event_complete);
1978 CloseHandle(event_complete2);