push 556f62bab943c37bb6cbad95a6ecb3d73e04a93f
[wine/hacks.git] / dlls / urlmon / tests / protocol.c
blobcc9d41a3479b53e03668e8969677c14e2628ac7a
1 /*
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
19 #define COBJMACROS
20 #define CONST_VTABLE
22 #include <wine/test.h>
23 #include <stdarg.h>
24 #include <stdio.h>
26 #include "windef.h"
27 #include "winbase.h"
28 #include "ole2.h"
29 #include "urlmon.h"
30 #include "wininet.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) \
39 do { \
40 ok(expect_ ##func, "unexpected call " #func "\n"); \
41 called_ ## func = TRUE; \
42 }while(0)
44 #define CHECK_EXPECT(func) \
45 do { \
46 CHECK_EXPECT2(func); \
47 expect_ ## func = FALSE; \
48 }while(0)
50 #define CHECK_CALLED(func) \
51 do { \
52 ok(called_ ## func, "expected " #func "\n"); \
53 expect_ ## func = called_ ## func = FALSE; \
54 }while(0)
56 #define CHECK_NOT_CALLED(func) \
57 do { \
58 ok(!called_ ## func, "unexpected " #func "\n"); \
59 expect_ ## func = called_ ## func = FALSE; \
60 }while(0)
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);
93 DEFINE_EXPECT(Start);
94 DEFINE_EXPECT(Terminate);
95 DEFINE_EXPECT(Read);
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;
127 static enum {
128 FILE_TEST,
129 HTTP_TEST,
130 HTTPS_TEST,
131 FTP_TEST,
132 MK_TEST,
133 BIND_TEST
134 } tested_protocol;
136 static const WCHAR protocol_names[][10] = {
137 {'f','i','l','e',0},
138 {'h','t','t','p',0},
139 {'h','t','t','p','s',0},
140 {'f','t','p',0},
141 {'m','k',0},
142 {'t','e','s','t',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];
160 if(!str)
161 return "(null)";
162 WideCharToMultiByte(CP_ACP, 0, str, -1, buf, sizeof(buf), NULL, NULL);
163 return buf;
166 static const char *debugstr_guid(REFIID riid)
168 static char buf[50];
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]);
175 return buf;
178 static int strcmp_wa(LPCWSTR strw, const char *stra)
180 WCHAR buf[512];
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)) {
190 *ppv = iface;
191 return S_OK;
194 ok(0, "unexpected call\n");
195 return E_NOINTERFACE;
198 static ULONG WINAPI HttpNegotiate_AddRef(IHttpNegotiate2 *iface)
200 return 2;
203 static ULONG WINAPI HttpNegotiate_Release(IHttpNegotiate2 *iface)
205 return 1;
208 static HRESULT WINAPI HttpNegotiate_BeginningTransaction(IHttpNegotiate2 *iface, LPCWSTR szURL,
209 LPCWSTR szHeaders, DWORD dwReserved, LPWSTR *pszAdditionalHeaders)
211 LPWSTR addl_headers;
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);
220 if(binding_test)
221 ok(!lstrcmpW(szURL, binding_urls[tested_protocol]), "szURL != http_url\n");
222 else
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");
229 if (http_post_test)
231 addl_headers = CoTaskMemAlloc(sizeof(wszHeaders));
232 if (!addl_headers)
234 http_post_test = FALSE;
235 skip("Out of memory\n");
236 return E_OUTOFMEMORY;
238 lstrcpyW(addl_headers, wszHeaders);
239 *pszAdditionalHeaders = addl_headers;
243 return S_OK;
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");
256 return S_OK;
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");
270 if(pcbSecurityId) {
271 ok(*pcbSecurityId == 512, "*pcbSecurityId=%d, expected 512\n", *pcbSecurityId);
272 *pcbSecurityId = sizeof(sec_id);
275 if(pbSecurityId)
276 memcpy(pbSecurityId, sec_id, sizeof(sec_id));
278 return E_FAIL;
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)
301 return 2;
304 static ULONG WINAPI ServiceProvider_Release(IServiceProvider *iface)
306 return 1;
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));
324 return E_FAIL;
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)
343 return 2;
346 static ULONG WINAPI ProtocolSink_Release(IInternetProtocolSink *iface)
348 return 1;
351 static HRESULT WINAPI ProtocolSink_Switch(IInternetProtocolSink *iface, PROTOCOLDATA *pProtocolData)
353 HRESULT hres;
355 if(tested_protocol == FTP_TEST)
356 CHECK_EXPECT2(Switch);
357 else
358 CHECK_EXPECT(Switch);
359 ok(pProtocolData != NULL, "pProtocolData == NULL\n");
361 pdata = pProtocolData;
363 if(binding_test) {
364 SetEvent(event_complete);
365 WaitForSingleObject(event_complete2, INFINITE);
366 return S_OK;
369 if (!state) {
370 if(tested_protocol == HTTP_TEST || tested_protocol == HTTPS_TEST || tested_protocol == FTP_TEST) {
371 if (http_is_first) {
372 CLEAR_CALLED(ReportProgress_FINDINGRESOURCE);
373 CLEAR_CALLED(ReportProgress_CONNECTING);
374 CLEAR_CALLED(ReportProgress_PROXYDETECTING);
375 } else todo_wine {
376 CHECK_NOT_CALLED(ReportProgress_FINDINGRESOURCE);
377 /* IE7 does call this */
378 CLEAR_CALLED(ReportProgress_CONNECTING);
381 if(tested_protocol == FTP_TEST)
382 todo_wine CHECK_CALLED(ReportProgress_SENDINGREQUEST);
383 else
384 CHECK_CALLED(ReportProgress_SENDINGREQUEST);
385 if(tested_protocol == HTTP_TEST || tested_protocol == HTTPS_TEST) {
386 SET_EXPECT(OnResponse);
387 if(tested_protocol == HTTPS_TEST)
388 SET_EXPECT(ReportProgress_ACCEPTRANGES);
389 SET_EXPECT(ReportProgress_MIMETYPEAVAILABLE);
390 if(bindf & BINDF_NEEDFILE)
391 SET_EXPECT(ReportProgress_CACHEFILENAMEAVAILABLE);
395 SET_EXPECT(ReportData);
396 hres = IInternetProtocol_Continue(async_protocol, pProtocolData);
397 ok(hres == S_OK, "Continue failed: %08x\n", hres);
398 if(tested_protocol == FTP_TEST)
399 CLEAR_CALLED(ReportData);
400 else
401 CHECK_CALLED(ReportData);
403 if (!state) {
404 state = 1;
405 if(tested_protocol == HTTP_TEST || tested_protocol == HTTPS_TEST) {
406 CHECK_CALLED(OnResponse);
407 if(tested_protocol == HTTPS_TEST)
408 CHECK_CALLED(ReportProgress_ACCEPTRANGES);
409 CHECK_CALLED(ReportProgress_MIMETYPEAVAILABLE);
410 if(bindf & BINDF_NEEDFILE)
411 CHECK_CALLED(ReportProgress_CACHEFILENAMEAVAILABLE);
415 SetEvent(event_complete);
417 return S_OK;
420 static HRESULT WINAPI ProtocolSink_ReportProgress(IInternetProtocolSink *iface, ULONG ulStatusCode,
421 LPCWSTR szStatusText)
423 static const WCHAR null_guid[] = {'{','0','0','0','0','0','0','0','0','-','0','0','0','0','-',
424 '0','0','0','0','-','0','0','0','0','-','0','0','0','0','0','0','0','0','0','0','0','0','}',0};
425 static const WCHAR text_plain[] = {'t','e','x','t','/','p','l','a','i','n',0};
427 switch(ulStatusCode) {
428 case BINDSTATUS_MIMETYPEAVAILABLE:
429 CHECK_EXPECT(ReportProgress_MIMETYPEAVAILABLE);
430 ok(szStatusText != NULL, "szStatusText == NULL\n");
431 if(szStatusText) {
432 if(tested_protocol == BIND_TEST)
433 ok(szStatusText == expect_wsz, "unexpected szStatusText\n");
434 else if (http_post_test)
435 ok(lstrlenW(text_plain) <= lstrlenW(szStatusText) &&
436 !memcmp(szStatusText, text_plain, lstrlenW(text_plain)*sizeof(WCHAR)),
437 "szStatusText != text/plain\n");
438 else
439 ok(lstrlenW(text_htmlW) <= lstrlenW(szStatusText) &&
440 !memcmp(szStatusText, text_htmlW, lstrlenW(text_htmlW)*sizeof(WCHAR)),
441 "szStatusText != text/html\n");
443 break;
444 case BINDSTATUS_DIRECTBIND:
445 CHECK_EXPECT2(ReportProgress_DIRECTBIND);
446 ok(szStatusText == NULL, "szStatusText != NULL\n");
447 break;
448 case BINDSTATUS_RAWMIMETYPE:
449 CHECK_EXPECT2(ReportProgress_RAWMIMETYPE);
450 ok(szStatusText != NULL, "szStatusText == NULL\n");
451 if(szStatusText)
452 ok(lstrlenW(szStatusText) < lstrlenW(text_htmlW) ||
453 !memcmp(szStatusText, text_htmlW, lstrlenW(text_htmlW)*sizeof(WCHAR)),
454 "szStatusText != text/html\n");
455 break;
456 case BINDSTATUS_CACHEFILENAMEAVAILABLE:
457 CHECK_EXPECT(ReportProgress_CACHEFILENAMEAVAILABLE);
458 ok(szStatusText != NULL, "szStatusText == NULL\n");
459 if(szStatusText) {
460 if(binding_test)
461 ok(!lstrcmpW(szStatusText, expect_wsz), "unexpected szStatusText\n");
462 else if(tested_protocol == FILE_TEST)
463 ok(!lstrcmpW(szStatusText, file_name), "szStatusText = \"%s\"\n", debugstr_w(szStatusText));
464 else
465 ok(szStatusText != NULL, "szStatusText == NULL\n");
467 break;
468 case BINDSTATUS_FINDINGRESOURCE:
469 CHECK_EXPECT(ReportProgress_FINDINGRESOURCE);
470 ok(szStatusText != NULL, "szStatusText == NULL\n");
471 break;
472 case BINDSTATUS_CONNECTING:
473 CHECK_EXPECT(ReportProgress_CONNECTING);
474 ok(szStatusText != NULL, "szStatusText == NULL\n");
475 break;
476 case BINDSTATUS_SENDINGREQUEST:
477 CHECK_EXPECT2(ReportProgress_SENDINGREQUEST);
478 if(tested_protocol == FILE_TEST) {
479 ok(szStatusText != NULL, "szStatusText == NULL\n");
480 if(szStatusText)
481 ok(!*szStatusText, "wrong szStatusText\n");
483 break;
484 case BINDSTATUS_VERIFIEDMIMETYPEAVAILABLE:
485 CHECK_EXPECT(ReportProgress_VERIFIEDMIMETYPEAVAILABLE);
486 ok(szStatusText != NULL, "szStatusText == NULL\n");
487 if(szStatusText)
488 ok(!lstrcmpW(szStatusText, text_htmlW), "szStatusText != text/html\n");
489 break;
490 case BINDSTATUS_PROTOCOLCLASSID:
491 CHECK_EXPECT(ReportProgress_PROTOCOLCLASSID);
492 ok(szStatusText != NULL, "szStatusText == NULL\n");
493 ok(!lstrcmpW(szStatusText, null_guid), "unexpected szStatusText\n");
494 break;
495 case BINDSTATUS_COOKIE_SENT:
496 CHECK_EXPECT(ReportProgress_COOKIE_SENT);
497 ok(szStatusText == NULL, "szStatusText != NULL\n");
498 break;
499 case BINDSTATUS_REDIRECTING:
500 CHECK_EXPECT(ReportProgress_REDIRECTING);
501 ok(szStatusText == NULL, "szStatusText = %s\n", debugstr_w(szStatusText));
502 break;
503 case BINDSTATUS_ENCODING:
504 CHECK_EXPECT(ReportProgress_ENCODING);
505 ok(!strcmp_wa(szStatusText, "gzip"), "szStatusText = %s\n", debugstr_w(szStatusText));
506 break;
507 case BINDSTATUS_ACCEPTRANGES:
508 CHECK_EXPECT(ReportProgress_ACCEPTRANGES);
509 ok(!szStatusText, "szStatusText = %s\n", debugstr_w(szStatusText));
510 break;
511 case BINDSTATUS_PROXYDETECTING:
512 CHECK_EXPECT(ReportProgress_PROXYDETECTING);
513 SET_EXPECT(ReportProgress_CONNECTING);
514 ok(!szStatusText, "szStatusText = %s\n", debugstr_w(szStatusText));
515 break;
516 default:
517 ok(0, "Unexpected status %d\n", ulStatusCode);
520 return S_OK;
523 static HRESULT WINAPI ProtocolSink_ReportData(IInternetProtocolSink *iface, DWORD grfBSCF,
524 ULONG ulProgress, ULONG ulProgressMax)
526 if(tested_protocol == FILE_TEST) {
527 CHECK_EXPECT2(ReportData);
529 ok(ulProgress == ulProgressMax, "ulProgress (%d) != ulProgressMax (%d)\n",
530 ulProgress, ulProgressMax);
531 ok(ulProgressMax == 13, "ulProgressMax=%d, expected 13\n", ulProgressMax);
532 ok(grfBSCF == (BSCF_FIRSTDATANOTIFICATION | BSCF_LASTDATANOTIFICATION),
533 "grcfBSCF = %08x\n", grfBSCF);
534 }else if(!binding_test && (tested_protocol == HTTP_TEST || tested_protocol == HTTPS_TEST || tested_protocol == FTP_TEST)) {
535 if(!(grfBSCF & BSCF_LASTDATANOTIFICATION) || (grfBSCF & BSCF_DATAFULLYAVAILABLE))
536 CHECK_EXPECT(ReportData);
537 else if (http_post_test)
538 ok(ulProgress == 13, "Read %u bytes instead of 13\n", ulProgress);
540 ok(ulProgress, "ulProgress == 0\n");
542 if(first_data_notif) {
543 ok(grfBSCF == BSCF_FIRSTDATANOTIFICATION
544 || grfBSCF == (BSCF_LASTDATANOTIFICATION|BSCF_DATAFULLYAVAILABLE),
545 "grcfBSCF = %08x\n", grfBSCF);
546 first_data_notif = FALSE;
547 } else {
548 ok(grfBSCF == BSCF_INTERMEDIATEDATANOTIFICATION
549 || grfBSCF == (BSCF_LASTDATANOTIFICATION|BSCF_INTERMEDIATEDATANOTIFICATION)
550 || broken(grfBSCF == (BSCF_FIRSTDATANOTIFICATION|BSCF_LASTDATANOTIFICATION)),
551 "grcfBSCF = %08x\n", grfBSCF);
554 if(!(bindf & BINDF_FROMURLMON) &&
555 !(grfBSCF & BSCF_LASTDATANOTIFICATION)) {
556 if(!state) {
557 state = 1;
558 if(http_is_first) {
559 CHECK_CALLED(ReportProgress_FINDINGRESOURCE);
560 CHECK_CALLED(ReportProgress_CONNECTING);
561 } else todo_wine {
562 CHECK_NOT_CALLED(ReportProgress_FINDINGRESOURCE);
563 CHECK_NOT_CALLED(ReportProgress_CONNECTING);
565 CHECK_CALLED(ReportProgress_SENDINGREQUEST);
566 CHECK_CALLED(OnResponse);
567 CHECK_CALLED(ReportProgress_RAWMIMETYPE);
569 SetEvent(event_complete);
571 }else {
572 BYTE buf[1000];
573 ULONG read;
574 HRESULT hres;
576 CHECK_EXPECT(ReportData);
578 if(tested_protocol == BIND_TEST)
579 return S_OK;
581 do {
582 SET_EXPECT(Read);
583 hres = IInternetProtocol_Read(binding_protocol, expect_pv=buf, sizeof(buf), &read);
584 CHECK_CALLED(Read);
585 }while(hres == S_OK);
588 return S_OK;
591 static HRESULT WINAPI ProtocolSink_ReportResult(IInternetProtocolSink *iface, HRESULT hrResult,
592 DWORD dwError, LPCWSTR szResult)
594 CHECK_EXPECT(ReportResult);
596 if(tested_protocol == FTP_TEST)
597 ok(hrResult == E_PENDING || hrResult == S_OK, "hrResult = %08x, expected E_PENDING or S_OK\n", hrResult);
598 else
599 ok(hrResult == expect_hrResult, "hrResult = %08x, expected: %08x\n",
600 hrResult, expect_hrResult);
601 if(SUCCEEDED(hrResult) || tested_protocol == FTP_TEST)
602 ok(dwError == ERROR_SUCCESS, "dwError = %d, expected ERROR_SUCCESS\n", dwError);
603 else
604 ok(dwError != ERROR_SUCCESS, "dwError == ERROR_SUCCESS\n");
605 ok(!szResult, "szResult != NULL\n");
607 return S_OK;
610 static IInternetProtocolSinkVtbl protocol_sink_vtbl = {
611 ProtocolSink_QueryInterface,
612 ProtocolSink_AddRef,
613 ProtocolSink_Release,
614 ProtocolSink_Switch,
615 ProtocolSink_ReportProgress,
616 ProtocolSink_ReportData,
617 ProtocolSink_ReportResult
620 static IInternetProtocolSink protocol_sink = { &protocol_sink_vtbl };
622 static HRESULT QueryInterface(REFIID riid, void **ppv)
624 *ppv = NULL;
626 if(IsEqualGUID(&IID_IUnknown, riid) || IsEqualGUID(&IID_IInternetProtocolSink, riid))
627 *ppv = &protocol_sink;
628 if(IsEqualGUID(&IID_IServiceProvider, riid))
629 *ppv = &service_provider;
631 if(*ppv)
632 return S_OK;
634 return E_NOINTERFACE;
637 static HRESULT WINAPI BindInfo_QueryInterface(IInternetBindInfo *iface, REFIID riid, void **ppv)
639 if(IsEqualGUID(&IID_IUnknown, riid) || IsEqualGUID(&IID_IInternetBindInfo, riid)) {
640 *ppv = iface;
641 return S_OK;
643 return E_NOINTERFACE;
646 static ULONG WINAPI BindInfo_AddRef(IInternetBindInfo *iface)
648 return 2;
651 static ULONG WINAPI BindInfo_Release(IInternetBindInfo *iface)
653 return 1;
656 static HRESULT WINAPI BindInfo_GetBindInfo(IInternetBindInfo *iface, DWORD *grfBINDF, BINDINFO *pbindinfo)
658 DWORD cbSize;
660 static const CHAR szPostData[] = "mode=Test";
662 CHECK_EXPECT(GetBindInfo);
664 ok(grfBINDF != NULL, "grfBINDF == NULL\n");
665 ok(pbindinfo != NULL, "pbindinfo == NULL\n");
666 ok(pbindinfo->cbSize == sizeof(BINDINFO), "wrong size of pbindinfo: %d\n", pbindinfo->cbSize);
668 *grfBINDF = bindf;
669 if(binding_test)
670 *grfBINDF |= BINDF_FROMURLMON;
671 cbSize = pbindinfo->cbSize;
672 memset(pbindinfo, 0, cbSize);
673 pbindinfo->cbSize = cbSize;
675 if (http_post_test)
677 /* Must be GMEM_FIXED, GMEM_MOVABLE does not work properly
678 * with urlmon on native (Win98 and WinXP) */
679 U(pbindinfo->stgmedData).hGlobal = GlobalAlloc(GPTR, sizeof(szPostData));
680 if (!U(pbindinfo->stgmedData).hGlobal)
682 http_post_test = FALSE;
683 skip("Out of memory\n");
684 return E_OUTOFMEMORY;
686 lstrcpy((LPSTR)U(pbindinfo->stgmedData).hGlobal, szPostData);
687 pbindinfo->cbstgmedData = sizeof(szPostData)-1;
688 pbindinfo->dwBindVerb = BINDVERB_POST;
689 pbindinfo->stgmedData.tymed = TYMED_HGLOBAL;
692 return S_OK;
695 static HRESULT WINAPI BindInfo_GetBindString(IInternetBindInfo *iface, ULONG ulStringType,
696 LPOLESTR *ppwzStr, ULONG cEl, ULONG *pcElFetched)
698 ok(ppwzStr != NULL, "ppwzStr == NULL\n");
699 ok(pcElFetched != NULL, "pcElFetched == NULL\n");
701 switch(ulStringType) {
702 case BINDSTRING_ACCEPT_MIMES:
703 CHECK_EXPECT(GetBindString_ACCEPT_MIMES);
704 ok(cEl == 256, "cEl=%d, expected 256\n", cEl);
705 if(pcElFetched) {
706 ok(*pcElFetched == 256, "*pcElFetched=%d, expected 256\n", *pcElFetched);
707 *pcElFetched = 1;
709 if(ppwzStr) {
710 *ppwzStr = CoTaskMemAlloc(sizeof(acc_mimeW));
711 memcpy(*ppwzStr, acc_mimeW, sizeof(acc_mimeW));
713 return S_OK;
714 case BINDSTRING_USER_AGENT:
715 CHECK_EXPECT(GetBindString_USER_AGENT);
716 ok(cEl == 1, "cEl=%d, expected 1\n", cEl);
717 if(pcElFetched) {
718 ok(*pcElFetched == 0, "*pcElFetch=%d, expectd 0\n", *pcElFetched);
719 *pcElFetched = 1;
721 if(ppwzStr) {
722 *ppwzStr = CoTaskMemAlloc(sizeof(user_agentW));
723 memcpy(*ppwzStr, user_agentW, sizeof(user_agentW));
725 return S_OK;
726 case BINDSTRING_POST_COOKIE:
727 CHECK_EXPECT(GetBindString_POST_COOKIE);
728 ok(cEl == 1, "cEl=%d, expected 1\n", cEl);
729 if(pcElFetched)
730 ok(*pcElFetched == 0, "*pcElFetch=%d, expectd 0\n", *pcElFetched);
731 return S_OK;
732 default:
733 ok(0, "unexpected call\n");
736 return E_NOTIMPL;
739 static IInternetBindInfoVtbl bind_info_vtbl = {
740 BindInfo_QueryInterface,
741 BindInfo_AddRef,
742 BindInfo_Release,
743 BindInfo_GetBindInfo,
744 BindInfo_GetBindString
747 static IInternetBindInfo bind_info = { &bind_info_vtbl };
749 static HRESULT WINAPI InternetPriority_QueryInterface(IInternetPriority *iface,
750 REFIID riid, void **ppv)
752 ok(0, "unexpected call\n");
753 return E_NOINTERFACE;
756 static ULONG WINAPI InternetPriority_AddRef(IInternetPriority *iface)
758 return 2;
761 static ULONG WINAPI InternetPriority_Release(IInternetPriority *iface)
763 return 1;
766 static HRESULT WINAPI InternetPriority_SetPriority(IInternetPriority *iface, LONG nPriority)
768 CHECK_EXPECT(SetPriority);
769 ok(nPriority == ex_priority, "nPriority=%d\n", nPriority);
770 return S_OK;
773 static HRESULT WINAPI InternetPriority_GetPriority(IInternetPriority *iface, LONG *pnPriority)
775 ok(0, "unexpected call\n");
776 return E_NOTIMPL;
780 static const IInternetPriorityVtbl InternetPriorityVtbl = {
781 InternetPriority_QueryInterface,
782 InternetPriority_AddRef,
783 InternetPriority_Release,
784 InternetPriority_SetPriority,
785 InternetPriority_GetPriority
788 static IInternetPriority InternetPriority = { &InternetPriorityVtbl };
790 static HRESULT WINAPI Protocol_QueryInterface(IInternetProtocol *iface, REFIID riid, void **ppv)
792 if(IsEqualGUID(&IID_IUnknown, riid) || IsEqualGUID(&IID_IInternetProtocol, riid)) {
793 *ppv = iface;
794 return S_OK;
797 if(IsEqualGUID(&IID_IInternetProtocolEx, riid)) {
798 trace("IID_IInternetProtocolEx not supported\n");
799 *ppv = NULL;
800 return E_NOINTERFACE;
803 if(IsEqualGUID(&IID_IInternetPriority, riid)) {
804 *ppv = &InternetPriority;
805 return S_OK;
808 ok(0, "unexpected riid %s\n", debugstr_guid(riid));
809 *ppv = NULL;
810 return E_NOINTERFACE;
813 static ULONG WINAPI Protocol_AddRef(IInternetProtocol *iface)
815 return 2;
818 static ULONG WINAPI Protocol_Release(IInternetProtocol *iface)
820 return 1;
823 static DWORD WINAPI thread_proc(PVOID arg)
825 HRESULT hres;
827 memset(&protocoldata, -1, sizeof(protocoldata));
829 prot_state = 0;
831 SET_EXPECT(ReportProgress_FINDINGRESOURCE);
832 hres = IInternetProtocolSink_ReportProgress(binding_sink,
833 BINDSTATUS_FINDINGRESOURCE, hostW);
834 CHECK_CALLED(ReportProgress_FINDINGRESOURCE);
835 ok(hres == S_OK, "ReportProgress failed: %08x\n", hres);
837 SET_EXPECT(ReportProgress_CONNECTING);
838 hres = IInternetProtocolSink_ReportProgress(binding_sink,
839 BINDSTATUS_CONNECTING, winehq_ipW);
840 CHECK_CALLED(ReportProgress_CONNECTING);
841 ok(hres == S_OK, "ReportProgress failed: %08x\n", hres);
843 SET_EXPECT(ReportProgress_SENDINGREQUEST);
844 hres = IInternetProtocolSink_ReportProgress(binding_sink,
845 BINDSTATUS_SENDINGREQUEST, NULL);
846 CHECK_CALLED(ReportProgress_SENDINGREQUEST);
847 ok(hres == S_OK, "ReportProgress failed: %08x\n", hres);
849 prot_state = 1;
850 SET_EXPECT(Switch);
851 hres = IInternetProtocolSink_Switch(binding_sink, &protocoldata);
852 CHECK_CALLED(Switch);
853 ok(hres == S_OK, "Switch failed: %08x\n", hres);
855 prot_state = 2;
856 SET_EXPECT(Switch);
857 hres = IInternetProtocolSink_Switch(binding_sink, &protocoldata);
858 CHECK_CALLED(Switch);
859 ok(hres == S_OK, "Switch failed: %08x\n", hres);
861 prot_state = 2;
862 SET_EXPECT(Switch);
863 hres = IInternetProtocolSink_Switch(binding_sink, &protocoldata);
864 CHECK_CALLED(Switch);
865 ok(hres == S_OK, "Switch failed: %08x\n", hres);
867 prot_state = 3;
868 SET_EXPECT(Switch);
869 hres = IInternetProtocolSink_Switch(binding_sink, &protocoldata);
870 CHECK_CALLED(Switch);
871 ok(hres == S_OK, "Switch failed: %08x\n", hres);
873 SetEvent(event_complete);
875 return 0;
878 static HRESULT WINAPI Protocol_Start(IInternetProtocol *iface, LPCWSTR szUrl,
879 IInternetProtocolSink *pOIProtSink, IInternetBindInfo *pOIBindInfo,
880 DWORD grfPI, HANDLE_PTR dwReserved)
882 BINDINFO bindinfo, exp_bindinfo;
883 DWORD cbindf = 0;
884 HRESULT hres;
886 CHECK_EXPECT(Start);
888 ok(pOIProtSink != NULL, "pOIProtSink == NULL\n");
889 ok(pOIBindInfo != NULL, "pOIBindInfo == NULL\n");
890 ok(pOIProtSink != &protocol_sink, "unexpected pOIProtSink\n");
891 ok(pOIBindInfo != &bind_info, "unexpected pOIBindInfo\n");
892 ok(!grfPI, "grfPI = %x\n", grfPI);
893 ok(!dwReserved, "dwReserved = %lx\n", dwReserved);
895 memset(&bindinfo, 0, sizeof(bindinfo));
896 bindinfo.cbSize = sizeof(bindinfo);
897 memcpy(&exp_bindinfo, &bindinfo, sizeof(bindinfo));
898 SET_EXPECT(GetBindInfo);
899 hres = IInternetBindInfo_GetBindInfo(pOIBindInfo, &cbindf, &bindinfo);
900 ok(hres == S_OK, "GetBindInfo failed: %08x\n", hres);
901 CHECK_CALLED(GetBindInfo);
902 ok(cbindf == (bindf|BINDF_FROMURLMON), "bindf = %x, expected %x\n",
903 cbindf, (bindf|BINDF_FROMURLMON));
904 ok(!memcmp(&exp_bindinfo, &bindinfo, sizeof(bindinfo)), "unexpected bindinfo\n");
905 ReleaseBindInfo(&bindinfo);
907 SET_EXPECT(ReportProgress_SENDINGREQUEST);
908 hres = IInternetProtocolSink_ReportProgress(pOIProtSink, BINDSTATUS_SENDINGREQUEST, emptyW);
909 ok(hres == S_OK, "ReportProgress(BINDSTATUS_SENDINGREQUEST) failed: %08x\n", hres);
910 CHECK_CALLED(ReportProgress_SENDINGREQUEST);
912 if(tested_protocol == HTTP_TEST || tested_protocol == HTTPS_TEST) {
913 IServiceProvider *service_provider;
914 IHttpNegotiate *http_negotiate;
915 IHttpNegotiate2 *http_negotiate2;
916 LPWSTR ua = (LPWSTR)0xdeadbeef, accept_mimes[256];
917 LPWSTR additional_headers = NULL;
918 BYTE sec_id[100];
919 DWORD fetched = 0, size = 100;
920 DWORD tid;
922 SET_EXPECT(GetBindString_USER_AGENT);
923 hres = IInternetBindInfo_GetBindString(pOIBindInfo, BINDSTRING_USER_AGENT,
924 &ua, 1, &fetched);
925 CHECK_CALLED(GetBindString_USER_AGENT);
926 ok(hres == S_OK, "GetBindString(BINDSTRING_USER_AGETNT) failed: %08x\n", hres);
927 ok(fetched == 1, "fetched = %d, expected 254\n", fetched);
928 ok(ua != NULL, "ua = %p\n", ua);
929 ok(!lstrcmpW(ua, user_agentW), "unexpected user agent %s\n", debugstr_w(ua));
930 CoTaskMemFree(ua);
932 fetched = 256;
933 SET_EXPECT(GetBindString_ACCEPT_MIMES);
934 hres = IInternetBindInfo_GetBindString(pOIBindInfo, BINDSTRING_ACCEPT_MIMES,
935 accept_mimes, 256, &fetched);
936 CHECK_CALLED(GetBindString_ACCEPT_MIMES);
938 ok(hres == S_OK,
939 "GetBindString(BINDSTRING_ACCEPT_MIMES) failed: %08x\n", hres);
940 ok(fetched == 1, "fetched = %d, expected 1\n", fetched);
941 ok(!lstrcmpW(acc_mimeW, accept_mimes[0]), "unexpected mimes %s\n", debugstr_w(accept_mimes[0]));
943 hres = IInternetBindInfo_QueryInterface(pOIBindInfo, &IID_IServiceProvider,
944 (void**)&service_provider);
945 ok(hres == S_OK, "QueryInterface failed: %08x\n", hres);
947 SET_EXPECT(QueryService_HttpNegotiate);
948 hres = IServiceProvider_QueryService(service_provider, &IID_IHttpNegotiate,
949 &IID_IHttpNegotiate, (void**)&http_negotiate);
950 CHECK_CALLED(QueryService_HttpNegotiate);
951 ok(hres == S_OK, "QueryService failed: %08x\n", hres);
953 SET_EXPECT(BeginningTransaction);
954 hres = IHttpNegotiate_BeginningTransaction(http_negotiate, binding_urls[tested_protocol],
955 NULL, 0, &additional_headers);
956 CHECK_CALLED(BeginningTransaction);
957 IHttpNegotiate_Release(http_negotiate);
958 ok(hres == S_OK, "BeginningTransction failed: %08x\n", hres);
959 ok(additional_headers == NULL, "additional_headers=%p\n", additional_headers);
961 SET_EXPECT(QueryService_HttpNegotiate);
962 hres = IServiceProvider_QueryService(service_provider, &IID_IHttpNegotiate2,
963 &IID_IHttpNegotiate2, (void**)&http_negotiate2);
964 CHECK_CALLED(QueryService_HttpNegotiate);
965 ok(hres == S_OK, "QueryService failed: %08x\n", hres);
967 size = 512;
968 SET_EXPECT(GetRootSecurityId);
969 hres = IHttpNegotiate2_GetRootSecurityId(http_negotiate2, sec_id, &size, 0);
970 CHECK_CALLED(GetRootSecurityId);
971 IHttpNegotiate2_Release(http_negotiate2);
972 ok(hres == E_FAIL, "GetRootSecurityId failed: %08x, expected E_FAIL\n", hres);
973 ok(size == 13, "size=%d\n", size);
975 IServiceProvider_Release(service_provider);
977 CreateThread(NULL, 0, thread_proc, NULL, 0, &tid);
979 return S_OK;
982 SET_EXPECT(ReportProgress_CACHEFILENAMEAVAILABLE);
983 hres = IInternetProtocolSink_ReportProgress(pOIProtSink,
984 BINDSTATUS_CACHEFILENAMEAVAILABLE, expect_wsz = emptyW);
985 ok(hres == S_OK, "ReportProgress(BINDSTATUS_CACHEFILENAMEAVAILABLE) failed: %08x\n", hres);
986 CHECK_CALLED(ReportProgress_CACHEFILENAMEAVAILABLE);
988 SET_EXPECT(ReportProgress_MIMETYPEAVAILABLE);
989 hres = IInternetProtocolSink_ReportProgress(pOIProtSink, BINDSTATUS_VERIFIEDMIMETYPEAVAILABLE,
990 expect_wsz = text_htmlW);
991 ok(hres == S_OK,
992 "ReportProgress(BINDSTATUS_VERIFIEDMIMETYPEAVAILABLE) failed: %08x\n", hres);
993 CHECK_CALLED(ReportProgress_MIMETYPEAVAILABLE);
995 SET_EXPECT(ReportData);
996 hres = IInternetProtocolSink_ReportData(pOIProtSink,
997 BSCF_FIRSTDATANOTIFICATION | BSCF_LASTDATANOTIFICATION, 13, 13);
998 ok(hres == S_OK, "ReportData failed: %08x\n", hres);
999 CHECK_CALLED(ReportData);
1001 if(tested_protocol == BIND_TEST) {
1002 hres = IInternetProtocol_Terminate(binding_protocol, 0);
1003 ok(hres == E_FAIL, "Termiante failed: %08x\n", hres);
1006 SET_EXPECT(ReportResult);
1007 hres = IInternetProtocolSink_ReportResult(pOIProtSink, S_OK, 0, NULL);
1008 ok(hres == S_OK, "ReportResult failed: %08x\n", hres);
1009 CHECK_CALLED(ReportResult);
1011 return S_OK;
1014 static HRESULT WINAPI Protocol_Continue(IInternetProtocol *iface,
1015 PROTOCOLDATA *pProtocolData)
1017 DWORD bscf = 0;
1018 HRESULT hres;
1020 CHECK_EXPECT(Continue);
1022 ok(pProtocolData != NULL, "pProtocolData == NULL\n");
1023 if(!pProtocolData || tested_protocol == BIND_TEST)
1024 return S_OK;
1026 switch(prot_state) {
1027 case 1: {
1028 IServiceProvider *service_provider;
1029 IHttpNegotiate *http_negotiate;
1030 static WCHAR header[] = {'?',0};
1032 hres = IInternetProtocolSink_QueryInterface(binding_sink, &IID_IServiceProvider,
1033 (void**)&service_provider);
1034 ok(hres == S_OK, "Could not get IServiceProvicder\n");
1036 SET_EXPECT(QueryService_HttpNegotiate);
1037 hres = IServiceProvider_QueryService(service_provider, &IID_IHttpNegotiate,
1038 &IID_IHttpNegotiate, (void**)&http_negotiate);
1039 IServiceProvider_Release(service_provider);
1040 CHECK_CALLED(QueryService_HttpNegotiate);
1041 ok(hres == S_OK, "Could not get IHttpNegotiate\n");
1043 SET_EXPECT(OnResponse);
1044 hres = IHttpNegotiate_OnResponse(http_negotiate, 200, header, NULL, NULL);
1045 IHttpNegotiate_Release(http_negotiate);
1046 CHECK_CALLED(OnResponse);
1047 IHttpNegotiate_Release(http_negotiate);
1048 ok(hres == S_OK, "OnResponse failed: %08x\n", hres);
1050 SET_EXPECT(ReportProgress_MIMETYPEAVAILABLE);
1051 hres = IInternetProtocolSink_ReportProgress(binding_sink,
1052 BINDSTATUS_MIMETYPEAVAILABLE, text_htmlW);
1053 CHECK_CALLED(ReportProgress_MIMETYPEAVAILABLE);
1054 ok(hres == S_OK,
1055 "ReportProgress(BINDSTATUS_MIMETYPEAVAILABLE) failed: %08x\n", hres);
1057 bscf |= BSCF_FIRSTDATANOTIFICATION;
1058 break;
1060 case 2:
1061 case 3:
1062 bscf = BSCF_INTERMEDIATEDATANOTIFICATION;
1063 break;
1066 SET_EXPECT(ReportData);
1067 hres = IInternetProtocolSink_ReportData(binding_sink, bscf, 100, 400);
1068 CHECK_CALLED(ReportData);
1069 ok(hres == S_OK, "ReportData failed: %08x\n", hres);
1071 if(prot_state == 3)
1072 prot_state = 4;
1074 return S_OK;
1077 static HRESULT WINAPI Protocol_Abort(IInternetProtocol *iface, HRESULT hrReason,
1078 DWORD dwOptions)
1080 ok(0, "unexpected call\n");
1081 return E_NOTIMPL;
1084 static HRESULT WINAPI Protocol_Terminate(IInternetProtocol *iface, DWORD dwOptions)
1086 CHECK_EXPECT(Terminate);
1087 ok(!dwOptions, "dwOptions=%d\n", dwOptions);
1088 return S_OK;
1091 static HRESULT WINAPI Protocol_Suspend(IInternetProtocol *iface)
1093 ok(0, "unexpected call\n");
1094 return E_NOTIMPL;
1097 static HRESULT WINAPI Protocol_Resume(IInternetProtocol *iface)
1099 ok(0, "unexpected call\n");
1100 return E_NOTIMPL;
1103 static HRESULT WINAPI Protocol_Read(IInternetProtocol *iface, void *pv,
1104 ULONG cb, ULONG *pcbRead)
1106 static BOOL b = TRUE;
1108 CHECK_EXPECT(Read);
1110 ok(pv == expect_pv, "pv != expect_pv\n");
1111 ok(cb == 1000, "cb=%d\n", cb);
1112 ok(pcbRead != NULL, "pcbRead == NULL\n");
1113 ok(!*pcbRead, "*pcbRead = %d\n", *pcbRead);
1115 if(prot_state == 3) {
1116 HRESULT hres;
1118 SET_EXPECT(ReportResult);
1119 hres = IInternetProtocolSink_ReportResult(binding_sink, S_OK, ERROR_SUCCESS, NULL);
1120 CHECK_CALLED(ReportResult);
1122 return S_FALSE;
1125 if((b = !b))
1126 return tested_protocol == HTTP_TEST || tested_protocol == HTTPS_TEST ? E_PENDING : S_FALSE;
1128 memset(pv, 'x', 100);
1129 prot_read += *pcbRead = 100;
1130 return S_OK;
1133 static HRESULT WINAPI Protocol_Seek(IInternetProtocol *iface,
1134 LARGE_INTEGER dlibMove, DWORD dwOrigin, ULARGE_INTEGER *plibNewPosition)
1136 ok(0, "unexpected call\n");
1137 return E_NOTIMPL;
1140 static HRESULT WINAPI Protocol_LockRequest(IInternetProtocol *iface, DWORD dwOptions)
1142 CHECK_EXPECT(LockRequest);
1143 ok(dwOptions == 0, "dwOptions=%x\n", dwOptions);
1144 return S_OK;
1147 static HRESULT WINAPI Protocol_UnlockRequest(IInternetProtocol *iface)
1149 CHECK_EXPECT(UnlockRequest);
1150 return S_OK;
1153 static const IInternetProtocolVtbl ProtocolVtbl = {
1154 Protocol_QueryInterface,
1155 Protocol_AddRef,
1156 Protocol_Release,
1157 Protocol_Start,
1158 Protocol_Continue,
1159 Protocol_Abort,
1160 Protocol_Terminate,
1161 Protocol_Suspend,
1162 Protocol_Resume,
1163 Protocol_Read,
1164 Protocol_Seek,
1165 Protocol_LockRequest,
1166 Protocol_UnlockRequest
1169 static IInternetProtocol Protocol = { &ProtocolVtbl };
1171 static HRESULT WINAPI ClassFactory_QueryInterface(IClassFactory *iface, REFIID riid, void **ppv)
1173 ok(0, "unexpected call\n");
1174 return E_NOINTERFACE;
1177 static ULONG WINAPI ClassFactory_AddRef(IClassFactory *iface)
1179 return 2;
1182 static ULONG WINAPI ClassFactory_Release(IClassFactory *iface)
1184 return 1;
1187 static HRESULT WINAPI ClassFactory_CreateInstance(IClassFactory *iface, IUnknown *pOuter,
1188 REFIID riid, void **ppv)
1190 CHECK_EXPECT(CreateInstance);
1192 ok(pOuter == (IUnknown*)prot_bind_info, "pOuter != protocol_unk\n");
1193 ok(IsEqualGUID(&IID_IUnknown, riid), "unexpected riid %s\n", debugstr_guid(riid));
1194 ok(ppv != NULL, "ppv == NULL\n");
1196 *ppv = &Protocol;
1197 return S_OK;
1200 static HRESULT WINAPI ClassFactory_LockServer(IClassFactory *iface, BOOL dolock)
1202 ok(0, "unexpected call\n");
1203 return S_OK;
1206 static const IClassFactoryVtbl ClassFactoryVtbl = {
1207 ClassFactory_QueryInterface,
1208 ClassFactory_AddRef,
1209 ClassFactory_Release,
1210 ClassFactory_CreateInstance,
1211 ClassFactory_LockServer
1214 static IClassFactory ClassFactory = { &ClassFactoryVtbl };
1216 static void test_priority(IInternetProtocol *protocol)
1218 IInternetPriority *priority;
1219 LONG pr;
1220 HRESULT hres;
1222 hres = IInternetProtocol_QueryInterface(protocol, &IID_IInternetPriority,
1223 (void**)&priority);
1224 ok(hres == S_OK, "QueryInterface(IID_IInternetPriority) failed: %08x\n", hres);
1225 if(FAILED(hres))
1226 return;
1228 hres = IInternetPriority_GetPriority(priority, &pr);
1229 ok(hres == S_OK, "GetPriority failed: %08x\n", hres);
1230 ok(pr == 0, "pr=%d, expected 0\n", pr);
1232 hres = IInternetPriority_SetPriority(priority, 1);
1233 ok(hres == S_OK, "SetPriority failed: %08x\n", hres);
1235 hres = IInternetPriority_GetPriority(priority, &pr);
1236 ok(hres == S_OK, "GetPriority failed: %08x\n", hres);
1237 ok(pr == 1, "pr=%d, expected 1\n", pr);
1239 IInternetPriority_Release(priority);
1242 static BOOL file_protocol_start(IInternetProtocol *protocol, LPCWSTR url, BOOL is_first)
1244 HRESULT hres;
1246 SET_EXPECT(GetBindInfo);
1247 if(!(bindf & BINDF_FROMURLMON))
1248 SET_EXPECT(ReportProgress_DIRECTBIND);
1249 if(is_first) {
1250 SET_EXPECT(ReportProgress_SENDINGREQUEST);
1251 SET_EXPECT(ReportProgress_CACHEFILENAMEAVAILABLE);
1252 if(bindf & BINDF_FROMURLMON)
1253 SET_EXPECT(ReportProgress_VERIFIEDMIMETYPEAVAILABLE);
1254 else
1255 SET_EXPECT(ReportProgress_MIMETYPEAVAILABLE);
1257 SET_EXPECT(ReportData);
1258 if(is_first)
1259 SET_EXPECT(ReportResult);
1261 expect_hrResult = S_OK;
1263 hres = IInternetProtocol_Start(protocol, url, &protocol_sink, &bind_info, 0, 0);
1264 if(hres == INET_E_RESOURCE_NOT_FOUND) {
1265 win_skip("Start failed\n");
1266 return FALSE;
1268 ok(hres == S_OK, "Start failed: %08x\n", hres);
1270 CHECK_CALLED(GetBindInfo);
1271 if(!(bindf & BINDF_FROMURLMON))
1272 CHECK_CALLED(ReportProgress_DIRECTBIND);
1273 if(is_first) {
1274 CHECK_CALLED(ReportProgress_SENDINGREQUEST);
1275 CHECK_CALLED(ReportProgress_CACHEFILENAMEAVAILABLE);
1276 if(bindf & BINDF_FROMURLMON)
1277 CHECK_CALLED(ReportProgress_VERIFIEDMIMETYPEAVAILABLE);
1278 else
1279 CHECK_CALLED(ReportProgress_MIMETYPEAVAILABLE);
1281 CHECK_CALLED(ReportData);
1282 if(is_first)
1283 CHECK_CALLED(ReportResult);
1285 return TRUE;
1288 static void test_file_protocol_url(LPCWSTR url)
1290 IInternetProtocolInfo *protocol_info;
1291 IUnknown *unk;
1292 IClassFactory *factory;
1293 HRESULT hres;
1295 hres = CoGetClassObject(&CLSID_FileProtocol, CLSCTX_INPROC_SERVER, NULL,
1296 &IID_IUnknown, (void**)&unk);
1297 ok(hres == S_OK, "CoGetClassObject failed: %08x\n", hres);
1298 if(FAILED(hres))
1299 return;
1301 hres = IUnknown_QueryInterface(unk, &IID_IInternetProtocolInfo, (void**)&protocol_info);
1302 ok(hres == E_NOINTERFACE,
1303 "Could not get IInternetProtocolInfo interface: %08x, expected E_NOINTERFACE\n", hres);
1305 hres = IUnknown_QueryInterface(unk, &IID_IClassFactory, (void**)&factory);
1306 ok(hres == S_OK, "Could not get IClassFactory interface\n");
1307 if(SUCCEEDED(hres)) {
1308 IInternetProtocol *protocol;
1309 BYTE buf[512];
1310 ULONG cb;
1311 hres = IClassFactory_CreateInstance(factory, NULL, &IID_IInternetProtocol, (void**)&protocol);
1312 ok(hres == S_OK, "Could not get IInternetProtocol: %08x\n", hres);
1314 if(SUCCEEDED(hres)) {
1315 if(file_protocol_start(protocol, url, TRUE)) {
1316 hres = IInternetProtocol_Read(protocol, buf, 2, &cb);
1317 ok(hres == S_OK, "Read failed: %08x\n", hres);
1318 ok(cb == 2, "cb=%u expected 2\n", cb);
1319 hres = IInternetProtocol_Read(protocol, buf, sizeof(buf), &cb);
1320 ok(hres == S_FALSE, "Read failed: %08x\n", hres);
1321 hres = IInternetProtocol_Read(protocol, buf, sizeof(buf), &cb);
1322 ok(hres == S_FALSE, "Read failed: %08x expected S_FALSE\n", hres);
1323 ok(cb == 0, "cb=%u expected 0\n", cb);
1324 hres = IInternetProtocol_UnlockRequest(protocol);
1325 ok(hres == S_OK, "UnlockRequest failed: %08x\n", hres);
1328 if(file_protocol_start(protocol, url, FALSE)) {
1329 hres = IInternetProtocol_Read(protocol, buf, 2, &cb);
1330 ok(hres == S_FALSE, "Read failed: %08x\n", hres);
1331 hres = IInternetProtocol_LockRequest(protocol, 0);
1332 ok(hres == S_OK, "LockRequest failed: %08x\n", hres);
1333 hres = IInternetProtocol_UnlockRequest(protocol);
1334 ok(hres == S_OK, "UnlockRequest failed: %08x\n", hres);
1337 IInternetProtocol_Release(protocol);
1340 hres = IClassFactory_CreateInstance(factory, NULL, &IID_IInternetProtocol, (void**)&protocol);
1341 ok(hres == S_OK, "Could not get IInternetProtocol: %08x\n", hres);
1343 if(SUCCEEDED(hres)) {
1344 if(file_protocol_start(protocol, url, TRUE)) {
1345 hres = IInternetProtocol_LockRequest(protocol, 0);
1346 ok(hres == S_OK, "LockRequest failed: %08x\n", hres);
1347 hres = IInternetProtocol_Terminate(protocol, 0);
1348 ok(hres == S_OK, "Terminate failed: %08x\n", hres);
1349 hres = IInternetProtocol_Read(protocol, buf, 2, &cb);
1350 ok(hres == S_OK, "Read failed: %08x\n\n", hres);
1351 hres = IInternetProtocol_UnlockRequest(protocol);
1352 ok(hres == S_OK, "UnlockRequest failed: %08x\n", hres);
1353 hres = IInternetProtocol_Read(protocol, buf, 2, &cb);
1354 ok(hres == S_OK, "Read failed: %08x\n", hres);
1355 hres = IInternetProtocol_Terminate(protocol, 0);
1356 ok(hres == S_OK, "Terminate failed: %08x\n", hres);
1359 IInternetProtocol_Release(protocol);
1362 hres = IClassFactory_CreateInstance(factory, NULL, &IID_IInternetProtocol, (void**)&protocol);
1363 ok(hres == S_OK, "Could not get IInternetProtocol: %08x\n", hres);
1365 if(SUCCEEDED(hres)) {
1366 if(file_protocol_start(protocol, url, TRUE)) {
1367 hres = IInternetProtocol_Terminate(protocol, 0);
1368 ok(hres == S_OK, "Terminate failed: %08x\n", hres);
1369 hres = IInternetProtocol_Read(protocol, buf, 2, &cb);
1370 ok(hres == S_OK, "Read failed: %08x\n", hres);
1371 ok(cb == 2, "cb=%u expected 2\n", cb);
1374 IInternetProtocol_Release(protocol);
1377 IClassFactory_Release(factory);
1380 IUnknown_Release(unk);
1383 static void test_file_protocol_fail(void)
1385 IInternetProtocol *protocol;
1386 HRESULT hres;
1388 static const WCHAR index_url2[] =
1389 {'f','i','l','e',':','/','/','i','n','d','e','x','.','h','t','m','l',0};
1391 hres = CoCreateInstance(&CLSID_FileProtocol, NULL, CLSCTX_INPROC_SERVER|CLSCTX_INPROC_HANDLER,
1392 &IID_IInternetProtocol, (void**)&protocol);
1393 ok(hres == S_OK, "CoCreateInstance failed: %08x\n", hres);
1394 if(FAILED(hres))
1395 return;
1397 SET_EXPECT(GetBindInfo);
1398 expect_hrResult = MK_E_SYNTAX;
1399 hres = IInternetProtocol_Start(protocol, wszIndexHtml, &protocol_sink, &bind_info, 0, 0);
1400 ok(hres == MK_E_SYNTAX ||
1401 hres == E_INVALIDARG,
1402 "Start failed: %08x, expected MK_E_SYNTAX or E_INVALIDARG\n", hres);
1403 CLEAR_CALLED(GetBindInfo); /* GetBindInfo not called in IE7 */
1405 SET_EXPECT(GetBindInfo);
1406 if(!(bindf & BINDF_FROMURLMON))
1407 SET_EXPECT(ReportProgress_DIRECTBIND);
1408 SET_EXPECT(ReportProgress_SENDINGREQUEST);
1409 SET_EXPECT(ReportResult);
1410 expect_hrResult = INET_E_RESOURCE_NOT_FOUND;
1411 hres = IInternetProtocol_Start(protocol, index_url, &protocol_sink, &bind_info, 0, 0);
1412 ok(hres == INET_E_RESOURCE_NOT_FOUND,
1413 "Start failed: %08x expected INET_E_RESOURCE_NOT_FOUND\n", hres);
1414 CHECK_CALLED(GetBindInfo);
1415 if(!(bindf & BINDF_FROMURLMON))
1416 CHECK_CALLED(ReportProgress_DIRECTBIND);
1417 CHECK_CALLED(ReportProgress_SENDINGREQUEST);
1418 CHECK_CALLED(ReportResult);
1420 IInternetProtocol_Release(protocol);
1422 hres = CoCreateInstance(&CLSID_FileProtocol, NULL, CLSCTX_INPROC_SERVER|CLSCTX_INPROC_HANDLER,
1423 &IID_IInternetProtocol, (void**)&protocol);
1424 ok(hres == S_OK, "CoCreateInstance failed: %08x\n", hres);
1425 if(FAILED(hres))
1426 return;
1428 SET_EXPECT(GetBindInfo);
1429 if(!(bindf & BINDF_FROMURLMON))
1430 SET_EXPECT(ReportProgress_DIRECTBIND);
1431 SET_EXPECT(ReportProgress_SENDINGREQUEST);
1432 SET_EXPECT(ReportResult);
1433 expect_hrResult = INET_E_RESOURCE_NOT_FOUND;
1435 hres = IInternetProtocol_Start(protocol, index_url2, &protocol_sink, &bind_info, 0, 0);
1436 ok(hres == INET_E_RESOURCE_NOT_FOUND,
1437 "Start failed: %08x, expected INET_E_RESOURCE_NOT_FOUND\n", hres);
1438 CHECK_CALLED(GetBindInfo);
1439 if(!(bindf & BINDF_FROMURLMON))
1440 CHECK_CALLED(ReportProgress_DIRECTBIND);
1441 CHECK_CALLED(ReportProgress_SENDINGREQUEST);
1442 CHECK_CALLED(ReportResult);
1444 SET_EXPECT(GetBindInfo);
1445 hres = IInternetProtocol_Start(protocol, NULL, &protocol_sink, &bind_info, 0, 0);
1446 ok(hres == E_INVALIDARG, "Start failed: %08x, expected E_INVALIDARG\n", hres);
1447 CLEAR_CALLED(GetBindInfo); /* GetBindInfo not called in IE7 */
1449 SET_EXPECT(GetBindInfo);
1450 hres = IInternetProtocol_Start(protocol, emptyW, &protocol_sink, &bind_info, 0, 0);
1451 ok(hres == E_INVALIDARG, "Start failed: %08x, expected E_INVALIDARG\n", hres);
1452 CLEAR_CALLED(GetBindInfo); /* GetBindInfo not called in IE7 */
1454 IInternetProtocol_Release(protocol);
1457 static void test_file_protocol(void) {
1458 WCHAR buf[INTERNET_MAX_URL_LENGTH], file_name_buf[MAX_PATH];
1459 DWORD size;
1460 ULONG len;
1461 HANDLE file;
1463 static const WCHAR wszFile[] = {'f','i','l','e',':',0};
1464 static const WCHAR wszFile2[] = {'f','i','l','e',':','/','/',0};
1465 static const WCHAR wszFile3[] = {'f','i','l','e',':','/','/','/',0};
1466 static const char html_doc[] = "<HTML></HTML>";
1468 trace("Testing file protocol...\n");
1469 tested_protocol = FILE_TEST;
1471 SetLastError(0xdeadbeef);
1472 file = CreateFileW(wszIndexHtml, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS,
1473 FILE_ATTRIBUTE_NORMAL, NULL);
1474 if(!file && GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)
1476 win_skip("Detected Win9x or WinMe\n");
1477 return;
1479 ok(file != INVALID_HANDLE_VALUE, "CreateFile failed\n");
1480 if(file == INVALID_HANDLE_VALUE)
1481 return;
1482 WriteFile(file, html_doc, sizeof(html_doc)-1, &size, NULL);
1483 CloseHandle(file);
1485 file_name = wszIndexHtml;
1486 bindf = 0;
1487 test_file_protocol_url(index_url);
1488 bindf = BINDF_FROMURLMON;
1489 test_file_protocol_url(index_url);
1490 bindf = BINDF_FROMURLMON | BINDF_NEEDFILE;
1491 test_file_protocol_url(index_url);
1493 memcpy(buf, wszFile, sizeof(wszFile));
1494 len = sizeof(wszFile)/sizeof(WCHAR)-1;
1495 len += GetCurrentDirectoryW(sizeof(buf)/sizeof(WCHAR)-len, buf+len);
1496 buf[len++] = '\\';
1497 memcpy(buf+len, wszIndexHtml, sizeof(wszIndexHtml));
1499 file_name = buf + sizeof(wszFile)/sizeof(WCHAR)-1;
1500 bindf = 0;
1501 test_file_protocol_url(buf);
1502 bindf = BINDF_FROMURLMON;
1503 test_file_protocol_url(buf);
1505 memcpy(buf, wszFile2, sizeof(wszFile2));
1506 len = GetCurrentDirectoryW(sizeof(file_name_buf)/sizeof(WCHAR), file_name_buf);
1507 file_name_buf[len++] = '\\';
1508 memcpy(file_name_buf+len, wszIndexHtml, sizeof(wszIndexHtml));
1509 lstrcpyW(buf+sizeof(wszFile2)/sizeof(WCHAR)-1, file_name_buf);
1510 file_name = file_name_buf;
1511 bindf = 0;
1512 test_file_protocol_url(buf);
1513 bindf = BINDF_FROMURLMON;
1514 test_file_protocol_url(buf);
1516 buf[sizeof(wszFile2)/sizeof(WCHAR)] = '|';
1517 test_file_protocol_url(buf);
1519 memcpy(buf, wszFile3, sizeof(wszFile3));
1520 len = sizeof(wszFile3)/sizeof(WCHAR)-1;
1521 len += GetCurrentDirectoryW(sizeof(buf)/sizeof(WCHAR)-len, buf+len);
1522 buf[len++] = '\\';
1523 memcpy(buf+len, wszIndexHtml, sizeof(wszIndexHtml));
1525 file_name = buf + sizeof(wszFile3)/sizeof(WCHAR)-1;
1526 bindf = 0;
1527 test_file_protocol_url(buf);
1528 bindf = BINDF_FROMURLMON;
1529 test_file_protocol_url(buf);
1531 DeleteFileW(wszIndexHtml);
1533 bindf = 0;
1534 test_file_protocol_fail();
1535 bindf = BINDF_FROMURLMON;
1536 test_file_protocol_fail();
1539 static BOOL http_protocol_start(LPCWSTR url, BOOL is_first)
1541 static BOOL got_user_agent = FALSE;
1542 HRESULT hres;
1544 first_data_notif = TRUE;
1545 state = 0;
1547 SET_EXPECT(GetBindInfo);
1548 if (!(bindf & BINDF_FROMURLMON))
1549 SET_EXPECT(ReportProgress_DIRECTBIND);
1550 SET_EXPECT(GetBindString_USER_AGENT);
1551 SET_EXPECT(GetBindString_ACCEPT_MIMES);
1552 SET_EXPECT(QueryService_HttpNegotiate);
1553 SET_EXPECT(BeginningTransaction);
1554 SET_EXPECT(GetRootSecurityId);
1555 if (http_post_test)
1556 SET_EXPECT(GetBindString_POST_COOKIE);
1558 hres = IInternetProtocol_Start(async_protocol, url, &protocol_sink, &bind_info, 0, 0);
1559 ok(hres == S_OK, "Start failed: %08x\n", hres);
1560 if(FAILED(hres))
1561 return FALSE;
1563 CHECK_CALLED(GetBindInfo);
1564 if (!(bindf & BINDF_FROMURLMON))
1565 CHECK_CALLED(ReportProgress_DIRECTBIND);
1566 if (!got_user_agent)
1568 CHECK_CALLED(GetBindString_USER_AGENT);
1569 got_user_agent = TRUE;
1571 else todo_wine
1573 /* user agent only retrieved once, even with different URLs */
1574 CHECK_NOT_CALLED(GetBindString_USER_AGENT);
1576 CHECK_CALLED(GetBindString_ACCEPT_MIMES);
1577 CHECK_CALLED(QueryService_HttpNegotiate);
1578 CHECK_CALLED(BeginningTransaction);
1579 /* GetRootSecurityId called on WinXP but not on Win98 */
1580 CLEAR_CALLED(GetRootSecurityId);
1581 if (http_post_test)
1582 CHECK_CALLED(GetBindString_POST_COOKIE);
1584 return TRUE;
1587 static void test_protocol_terminate(IInternetProtocol *protocol)
1589 BYTE buf[3600];
1590 DWORD cb;
1591 HRESULT hres;
1593 hres = IInternetProtocol_LockRequest(protocol, 0);
1594 ok(hres == S_OK, "LockRequest failed: %08x\n", hres);
1596 hres = IInternetProtocol_Read(protocol, buf, 1, &cb);
1597 ok(hres == S_FALSE, "Read failed: %08x\n", hres);
1599 hres = IInternetProtocol_Terminate(protocol, 0);
1600 ok(hres == S_OK, "Terminate failed: %08x\n", hres);
1602 /* This wait is to give the internet handles being freed in Terminate
1603 * enough time to actually terminate in all cases. Internet handles
1604 * terminate asynchronously and native reuses the main InternetOpen
1605 * handle. The only case in which this seems to be necessary is on
1606 * wine with native wininet and urlmon, resulting in the next time
1607 * test_http_protocol_url being called the first data notification actually
1608 * being an extra last data notification from the previous connection
1609 * about once out of every ten times. */
1610 Sleep(100);
1612 hres = IInternetProtocol_UnlockRequest(protocol);
1613 ok(hres == S_OK, "UnlockRequest failed: %08x\n", hres);
1616 static void test_http_info(IInternetProtocol *protocol)
1618 IWinInetHttpInfo *info;
1619 HRESULT hres;
1621 hres = IInternetProtocol_QueryInterface(protocol, &IID_IWinInetHttpInfo, (void**)&info);
1622 ok(hres == S_OK, "Could not get IWinInterHttpInfo iface: %08x\n", hres);
1624 /* TODO */
1626 IWinInetHttpInfo_Release(info);
1629 /* is_first refers to whether this is the first call to this function
1630 * _for this url_ */
1631 static void test_http_protocol_url(LPCWSTR url, BOOL is_https, BOOL is_first)
1633 IInternetProtocolInfo *protocol_info;
1634 IClassFactory *factory;
1635 IUnknown *unk;
1636 HRESULT hres;
1638 http_url = url;
1639 http_is_first = is_first;
1641 hres = CoGetClassObject(is_https ? &CLSID_HttpSProtocol : &CLSID_HttpProtocol,
1642 CLSCTX_INPROC_SERVER, NULL, &IID_IUnknown, (void**)&unk);
1643 ok(hres == S_OK, "CoGetClassObject failed: %08x\n", hres);
1644 if(FAILED(hres))
1645 return;
1647 hres = IUnknown_QueryInterface(unk, &IID_IInternetProtocolInfo, (void**)&protocol_info);
1648 ok(hres == E_NOINTERFACE,
1649 "Could not get IInternetProtocolInfo interface: %08x, expected E_NOINTERFACE\n",
1650 hres);
1652 hres = IUnknown_QueryInterface(unk, &IID_IClassFactory, (void**)&factory);
1653 ok(hres == S_OK, "Could not get IClassFactory interface\n");
1654 IUnknown_Release(unk);
1655 if(FAILED(hres))
1656 return;
1658 hres = IClassFactory_CreateInstance(factory, NULL, &IID_IInternetProtocol,
1659 (void**)&async_protocol);
1660 ok(hres == S_OK, "Could not get IInternetProtocol: %08x\n", hres);
1661 if(SUCCEEDED(hres)) {
1662 BYTE buf[3600];
1663 DWORD cb;
1664 ULONG ref;
1666 test_priority(async_protocol);
1667 test_http_info(async_protocol);
1669 SET_EXPECT(ReportProgress_FINDINGRESOURCE);
1670 SET_EXPECT(ReportProgress_CONNECTING);
1671 SET_EXPECT(ReportProgress_SENDINGREQUEST);
1672 SET_EXPECT(ReportProgress_PROXYDETECTING);
1673 if(! is_https)
1674 SET_EXPECT(ReportProgress_CACHEFILENAMEAVAILABLE);
1675 if(!(bindf & BINDF_FROMURLMON)) {
1676 SET_EXPECT(OnResponse);
1677 SET_EXPECT(ReportProgress_RAWMIMETYPE);
1678 SET_EXPECT(ReportData);
1679 } else {
1680 SET_EXPECT(Switch);
1683 if(!http_protocol_start(url, is_first))
1684 return;
1686 SET_EXPECT(ReportResult);
1687 expect_hrResult = S_OK;
1689 hres = IInternetProtocol_Read(async_protocol, buf, 1, &cb);
1690 ok((hres == E_PENDING && cb==0) ||
1691 (hres == S_OK && cb==1), "Read failed: %08x (%d bytes)\n", hres, cb);
1693 WaitForSingleObject(event_complete, INFINITE);
1694 if(bindf & BINDF_FROMURLMON)
1695 CHECK_CALLED(Switch);
1696 else
1697 CHECK_CALLED(ReportData);
1699 while(1) {
1700 if(bindf & BINDF_FROMURLMON)
1701 SET_EXPECT(Switch);
1702 else
1703 SET_EXPECT(ReportData);
1704 hres = IInternetProtocol_Read(async_protocol, buf, sizeof(buf), &cb);
1705 if(hres == E_PENDING) {
1706 hres = IInternetProtocol_Read(async_protocol, buf, 1, &cb);
1707 ok((hres == E_PENDING && cb==0) ||
1708 (hres == S_OK && cb==1), "Read failed: %08x (%d bytes)\n", hres, cb);
1709 WaitForSingleObject(event_complete, INFINITE);
1710 if(bindf & BINDF_FROMURLMON)
1711 CHECK_CALLED(Switch);
1712 else
1713 CHECK_CALLED(ReportData);
1714 }else {
1715 if(bindf & BINDF_FROMURLMON)
1716 CHECK_NOT_CALLED(Switch);
1717 else
1718 CHECK_NOT_CALLED(ReportData);
1719 if(cb == 0) break;
1722 ok(hres == S_FALSE, "Read failed: %08x\n", hres);
1723 CHECK_CALLED(ReportResult);
1725 test_protocol_terminate(async_protocol);
1726 ref = IInternetProtocol_Release(async_protocol);
1727 ok(!ref, "ref=%x\n", hres);
1730 IClassFactory_Release(factory);
1733 static void test_http_protocol(void)
1735 static const WCHAR winehq_url[] =
1736 {'h','t','t','p',':','/','/','w','w','w','.','w','i','n','e','h','q','.',
1737 'o','r','g','/','s','i','t','e','/','a','b','o','u','t',0};
1738 static const WCHAR posttest_url[] =
1739 {'h','t','t','p',':','/','/','c','r','o','s','s','o','v','e','r','.',
1740 'c','o','d','e','w','e','a','v','e','r','s','.','c','o','m','/',
1741 'p','o','s','t','t','e','s','t','.','p','h','p',0};
1743 trace("Testing http protocol (not from urlmon)...\n");
1744 tested_protocol = HTTP_TEST;
1745 bindf = BINDF_ASYNCHRONOUS | BINDF_ASYNCSTORAGE | BINDF_PULLDATA;
1746 test_http_protocol_url(winehq_url, FALSE, TRUE);
1748 trace("Testing http protocol (from urlmon)...\n");
1749 bindf = BINDF_ASYNCHRONOUS | BINDF_ASYNCSTORAGE | BINDF_PULLDATA | BINDF_FROMURLMON;
1750 test_http_protocol_url(winehq_url, FALSE, FALSE);
1752 trace("Testing http protocol (to file)...\n");
1753 bindf = BINDF_ASYNCHRONOUS | BINDF_ASYNCSTORAGE | BINDF_PULLDATA | BINDF_FROMURLMON | BINDF_NEEDFILE;
1754 test_http_protocol_url(winehq_url, FALSE, FALSE);
1756 trace("Testing http protocol (post data)...\n");
1757 http_post_test = TRUE;
1758 /* Without this flag we get a ReportProgress_CACHEFILENAMEAVAILABLE
1759 * notification with BINDVERB_POST */
1760 bindf = BINDF_ASYNCHRONOUS | BINDF_ASYNCSTORAGE | BINDF_PULLDATA | BINDF_FROMURLMON | BINDF_NOWRITECACHE;
1761 test_http_protocol_url(posttest_url, FALSE, TRUE);
1762 http_post_test = FALSE;
1765 static void test_https_protocol(void)
1767 static const WCHAR codeweavers_url[] =
1768 {'h','t','t','p','s',':','/','/','w','w','w','.','c','o','d','e','w','e','a','v','e','r','s',
1769 '.','c','o','m','/','t','e','s','t','.','h','t','m','l',0};
1771 trace("Testing https protocol (from urlmon)...\n");
1772 tested_protocol = HTTPS_TEST;
1773 bindf = BINDF_ASYNCHRONOUS | BINDF_ASYNCSTORAGE | BINDF_PULLDATA | BINDF_FROMURLMON | BINDF_NOWRITECACHE;
1774 test_http_protocol_url(codeweavers_url, TRUE, TRUE);
1778 static void test_ftp_protocol(void)
1780 IInternetProtocolInfo *protocol_info;
1781 IClassFactory *factory;
1782 IUnknown *unk;
1783 BYTE buf[4096];
1784 ULONG ref;
1785 DWORD cb;
1786 HRESULT hres;
1788 static const WCHAR ftp_urlW[] = {'f','t','p',':','/','/','f','t','p','.','w','i','n','e','h','q','.','o','r','g',
1789 '/','p','u','b','/','o','t','h','e','r','/',
1790 'w','i','n','e','l','o','g','o','.','x','c','f','.','t','a','r','.','b','z','2',0};
1792 trace("Testing ftp protocol...\n");
1794 bindf = BINDF_ASYNCHRONOUS | BINDF_ASYNCSTORAGE | BINDF_PULLDATA | BINDF_FROMURLMON | BINDF_NOWRITECACHE;
1795 state = 0;
1796 tested_protocol = FTP_TEST;
1797 first_data_notif = TRUE;
1798 expect_hrResult = E_PENDING;
1800 hres = CoGetClassObject(&CLSID_FtpProtocol, CLSCTX_INPROC_SERVER, NULL, &IID_IUnknown, (void**)&unk);
1801 ok(hres == S_OK, "CoGetClassObject failed: %08x\n", hres);
1802 if(FAILED(hres))
1803 return;
1805 hres = IUnknown_QueryInterface(unk, &IID_IInternetProtocolInfo, (void**)&protocol_info);
1806 ok(hres == E_NOINTERFACE, "Could not get IInternetProtocolInfo interface: %08x, expected E_NOINTERFACE\n", hres);
1808 hres = IUnknown_QueryInterface(unk, &IID_IClassFactory, (void**)&factory);
1809 ok(hres == S_OK, "Could not get IClassFactory interface\n");
1810 IUnknown_Release(unk);
1811 if(FAILED(hres))
1812 return;
1814 hres = IClassFactory_CreateInstance(factory, NULL, &IID_IInternetProtocol,
1815 (void**)&async_protocol);
1816 IClassFactory_Release(factory);
1817 ok(hres == S_OK, "Could not get IInternetProtocol: %08x\n", hres);
1819 test_priority(async_protocol);
1820 test_http_info(async_protocol);
1822 SET_EXPECT(GetBindInfo);
1823 SET_EXPECT(GetBindString_USER_AGENT);
1824 SET_EXPECT(ReportProgress_FINDINGRESOURCE);
1825 SET_EXPECT(ReportProgress_CONNECTING);
1826 SET_EXPECT(ReportProgress_SENDINGREQUEST);
1827 SET_EXPECT(Switch);
1829 hres = IInternetProtocol_Start(async_protocol, ftp_urlW, &protocol_sink, &bind_info, 0, 0);
1830 ok(hres == S_OK, "Start failed: %08x\n", hres);
1831 CHECK_CALLED(GetBindInfo);
1832 todo_wine CHECK_NOT_CALLED(GetBindString_USER_AGENT);
1834 SET_EXPECT(ReportResult);
1836 hres = IInternetProtocol_Read(async_protocol, buf, 1, &cb);
1837 ok((hres == E_PENDING && cb==0) ||
1838 (hres == S_OK && cb==1), "Read failed: %08x (%d bytes)\n", hres, cb);
1840 WaitForSingleObject(event_complete, INFINITE);
1842 while(1) {
1844 hres = IInternetProtocol_Read(async_protocol, buf, sizeof(buf), &cb);
1845 if(hres == E_PENDING)
1846 WaitForSingleObject(event_complete, INFINITE);
1847 else
1848 if(cb == 0) break;
1851 ok(hres == S_FALSE, "Read failed: %08x\n", hres);
1852 CHECK_CALLED(ReportResult);
1853 CHECK_CALLED(Switch);
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;
1865 IUnknown *unk;
1866 HRESULT hres;
1868 trace("Testing gopher protocol...\n");
1870 hres = CoGetClassObject(&CLSID_GopherProtocol, CLSCTX_INPROC_SERVER, NULL, &IID_IUnknown, (void**)&unk);
1871 ok(hres == S_OK ||
1872 hres == REGDB_E_CLASSNOTREG, /* Gopher protocol has been removed as of Vista */
1873 "CoGetClassObject failed: %08x\n", hres);
1874 if(FAILED(hres))
1875 return;
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);
1883 if(FAILED(hres))
1884 return;
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;
1901 IUnknown *unk;
1902 HRESULT hres;
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",
1918 hres);
1920 hres = IUnknown_QueryInterface(unk, &IID_IClassFactory, (void**)&factory);
1921 ok(hres == S_OK, "Could not get IClassFactory interface\n");
1922 IUnknown_Release(unk);
1923 if(FAILED(hres))
1924 return;
1926 hres = IClassFactory_CreateInstance(factory, NULL, &IID_IInternetProtocol,
1927 (void**)&protocol);
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);
1955 }else {
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;
1972 LONG p;
1973 BYTE buf[1000];
1974 DWORD read;
1975 HRESULT hres;
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);
2012 p = 0xdeadbeef;
2013 hres = IInternetPriority_GetPriority(priority, &p);
2014 ok(hres == S_OK, "GetPriority failed: %08x\n", hres);
2015 ok(!p, "p=%d\n", p);
2017 ex_priority = 100;
2018 hres = IInternetPriority_SetPriority(priority, 100);
2019 ok(hres == S_OK, "SetPriority failed: %08x\n", hres);
2021 p = 0xdeadbeef;
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);
2030 SET_EXPECT(Start);
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);
2042 SET_EXPECT(Read);
2043 read = 0xdeadbeef;
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);
2047 CHECK_CALLED(Read);
2049 SET_EXPECT(Read);
2050 read = 0xdeadbeef;
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);
2054 CHECK_CALLED(Read);
2056 p = 0xdeadbeef;
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;
2095 ULONG ref;
2096 HRESULT hres;
2098 trace("Testing %s binding...\n", debugstr_w(protocol_names[prot]));
2100 tested_protocol = prot;
2101 binding_test = TRUE;
2102 first_data_notif = TRUE;
2103 prot_read = 0;
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);
2123 ex_priority = 0;
2124 SET_EXPECT(QueryService_InternetProtocol);
2125 SET_EXPECT(CreateInstance);
2126 SET_EXPECT(ReportProgress_PROTOCOLCLASSID);
2127 SET_EXPECT(SetPriority);
2128 SET_EXPECT(Start);
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);
2150 }else {
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();
2185 test_mk_protocol();
2186 test_CreateBinding();
2187 test_binding(FILE_TEST);
2188 test_binding(HTTP_TEST);
2190 CloseHandle(event_complete);
2191 CloseHandle(event_complete2);
2193 OleUninitialize();