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_EXPECT(func) \
40 ok(expect_ ##func, "unexpected call " #func "\n"); \
41 expect_ ## func = FALSE; \
42 called_ ## func = TRUE; \
45 #define CHECK_EXPECT2(func) \
47 ok(expect_ ##func, "unexpected call " #func "\n"); \
48 called_ ## func = TRUE; \
51 #define CHECK_CALLED(func) \
53 ok(called_ ## func, "expected " #func "\n"); \
54 expect_ ## func = called_ ## func = FALSE; \
57 #define CHECK_NOT_CALLED(func) \
59 ok(!called_ ## func, "unexpected " #func "\n"); \
60 expect_ ## func = called_ ## func = FALSE; \
63 #define CLEAR_CALLED(func) \
64 expect_ ## func = called_ ## func = FALSE
66 DEFINE_EXPECT(GetBindInfo);
67 DEFINE_EXPECT(ReportProgress_MIMETYPEAVAILABLE);
68 DEFINE_EXPECT(ReportProgress_DIRECTBIND);
69 DEFINE_EXPECT(ReportProgress_RAWMIMETYPE);
70 DEFINE_EXPECT(ReportProgress_FINDINGRESOURCE);
71 DEFINE_EXPECT(ReportProgress_CONNECTING);
72 DEFINE_EXPECT(ReportProgress_SENDINGREQUEST);
73 DEFINE_EXPECT(ReportProgress_CACHEFILENAMEAVAILABLE);
74 DEFINE_EXPECT(ReportProgress_VERIFIEDMIMETYPEAVAILABLE);
75 DEFINE_EXPECT(ReportProgress_PROTOCOLCLASSID);
76 DEFINE_EXPECT(ReportData);
77 DEFINE_EXPECT(ReportResult);
78 DEFINE_EXPECT(GetBindString_ACCEPT_MIMES);
79 DEFINE_EXPECT(GetBindString_USER_AGENT);
80 DEFINE_EXPECT(GetBindString_POST_COOKIE);
81 DEFINE_EXPECT(QueryService_HttpNegotiate);
82 DEFINE_EXPECT(QueryService_InternetProtocol);
83 DEFINE_EXPECT(BeginningTransaction);
84 DEFINE_EXPECT(GetRootSecurityId);
85 DEFINE_EXPECT(OnResponse);
86 DEFINE_EXPECT(Switch);
87 DEFINE_EXPECT(CreateInstance);
89 DEFINE_EXPECT(Terminate);
91 DEFINE_EXPECT(SetPriority);
93 static const WCHAR wszIndexHtml[] = {'i','n','d','e','x','.','h','t','m','l',0};
94 static const WCHAR index_url[] =
95 {'f','i','l','e',':','i','n','d','e','x','.','h','t','m','l',0};
97 static HRESULT expect_hrResult;
98 static LPCWSTR file_name, http_url, expect_wsz;
99 static IInternetProtocol *http_protocol = NULL;
100 static BOOL first_data_notif = FALSE, http_is_first = FALSE,
101 http_post_test = FALSE;
102 static HWND protocol_hwnd;
103 static int state = 0;
104 static DWORD bindf = 0;
105 static IInternetBindInfo *prot_bind_info;
106 static void *expect_pv;
115 static HRESULT WINAPI HttpNegotiate_QueryInterface(IHttpNegotiate2 *iface, REFIID riid, void **ppv)
117 if(IsEqualGUID(&IID_IUnknown, riid)
118 || IsEqualGUID(&IID_IHttpNegotiate, riid)
119 || IsEqualGUID(&IID_IHttpNegotiate2, riid)) {
124 ok(0, "unexpected call\n");
125 return E_NOINTERFACE;
128 static ULONG WINAPI HttpNegotiate_AddRef(IHttpNegotiate2 *iface)
133 static ULONG WINAPI HttpNegotiate_Release(IHttpNegotiate2 *iface)
138 static HRESULT WINAPI HttpNegotiate_BeginningTransaction(IHttpNegotiate2 *iface, LPCWSTR szURL,
139 LPCWSTR szHeaders, DWORD dwReserved, LPWSTR *pszAdditionalHeaders)
143 static const WCHAR wszHeaders[] =
144 {'C','o','n','t','e','n','t','-','T','y','p','e',':',' ','a','p','p','l','i','c','a','t',
145 'i','o','n','/','x','-','w','w','w','-','f','o','r','m','-','u','r','l','e','n','c','o',
146 'd','e','d','\r','\n',0};
148 CHECK_EXPECT(BeginningTransaction);
150 ok(!lstrcmpW(szURL, http_url), "szURL != http_url\n");
151 ok(!dwReserved, "dwReserved=%d, expected 0\n", dwReserved);
152 ok(pszAdditionalHeaders != NULL, "pszAdditionalHeaders == NULL\n");
153 if(pszAdditionalHeaders)
155 ok(*pszAdditionalHeaders == NULL, "*pszAdditionalHeaders != NULL\n");
158 addl_headers = CoTaskMemAlloc(sizeof(wszHeaders));
161 skip("Out of memory\n");
162 return E_OUTOFMEMORY;
164 lstrcpyW(addl_headers, wszHeaders);
165 *pszAdditionalHeaders = addl_headers;
172 static HRESULT WINAPI HttpNegotiate_OnResponse(IHttpNegotiate2 *iface, DWORD dwResponseCode,
173 LPCWSTR szResponseHeaders, LPCWSTR szRequestHeaders, LPWSTR *pszAdditionalRequestHeaders)
175 CHECK_EXPECT(OnResponse);
177 ok(dwResponseCode == 200, "dwResponseCode=%d, expected 200\n", dwResponseCode);
178 ok(szResponseHeaders != NULL, "szResponseHeaders == NULL\n");
179 ok(szRequestHeaders == NULL, "szRequestHeaders != NULL\n");
180 ok(pszAdditionalRequestHeaders == NULL, "pszAdditionalHeaders != NULL\n");
185 static HRESULT WINAPI HttpNegotiate_GetRootSecurityId(IHttpNegotiate2 *iface,
186 BYTE *pbSecurityId, DWORD *pcbSecurityId, DWORD_PTR dwReserved)
188 static const BYTE sec_id[] = {'h','t','t','p',':','t','e','s','t',1,0,0,0};
190 CHECK_EXPECT(GetRootSecurityId);
192 ok(!dwReserved, "dwReserved=%ld, expected 0\n", dwReserved);
193 ok(pbSecurityId != NULL, "pbSecurityId == NULL\n");
194 ok(pcbSecurityId != NULL, "pcbSecurityId == NULL\n");
197 ok(*pcbSecurityId == 512, "*pcbSecurityId=%d, expected 512\n", *pcbSecurityId);
198 *pcbSecurityId = sizeof(sec_id);
202 memcpy(pbSecurityId, sec_id, sizeof(sec_id));
207 static IHttpNegotiate2Vtbl HttpNegotiateVtbl = {
208 HttpNegotiate_QueryInterface,
209 HttpNegotiate_AddRef,
210 HttpNegotiate_Release,
211 HttpNegotiate_BeginningTransaction,
212 HttpNegotiate_OnResponse,
213 HttpNegotiate_GetRootSecurityId
216 static IHttpNegotiate2 http_negotiate = { &HttpNegotiateVtbl };
218 static HRESULT QueryInterface(REFIID,void**);
220 static HRESULT WINAPI ServiceProvider_QueryInterface(IServiceProvider *iface, REFIID riid, void **ppv)
222 return QueryInterface(riid, ppv);
225 static ULONG WINAPI ServiceProvider_AddRef(IServiceProvider *iface)
230 static ULONG WINAPI ServiceProvider_Release(IServiceProvider *iface)
235 static HRESULT WINAPI ServiceProvider_QueryService(IServiceProvider *iface, REFGUID guidService,
236 REFIID riid, void **ppv)
238 if(IsEqualGUID(&IID_IHttpNegotiate, guidService) || IsEqualGUID(&IID_IHttpNegotiate2, riid)) {
239 CHECK_EXPECT2(QueryService_HttpNegotiate);
240 return IHttpNegotiate2_QueryInterface(&http_negotiate, riid, ppv);
243 if(IsEqualGUID(&IID_IInternetProtocol, guidService)) {
244 ok(IsEqualGUID(&IID_IInternetProtocol, riid), "unexpected riid\n");
245 CHECK_EXPECT(QueryService_InternetProtocol);
246 return E_NOINTERFACE;
249 ok(0, "unexpected call\n");
253 static const IServiceProviderVtbl ServiceProviderVtbl = {
254 ServiceProvider_QueryInterface,
255 ServiceProvider_AddRef,
256 ServiceProvider_Release,
257 ServiceProvider_QueryService
260 static IServiceProvider service_provider = { &ServiceProviderVtbl };
262 static HRESULT WINAPI ProtocolSink_QueryInterface(IInternetProtocolSink *iface, REFIID riid, void **ppv)
264 return QueryInterface(riid, ppv);
267 static ULONG WINAPI ProtocolSink_AddRef(IInternetProtocolSink *iface)
272 static ULONG WINAPI ProtocolSink_Release(IInternetProtocolSink *iface)
277 static HRESULT WINAPI ProtocolSink_Switch(IInternetProtocolSink *iface, PROTOCOLDATA *pProtocolData)
279 CHECK_EXPECT2(Switch);
280 ok(pProtocolData != NULL, "pProtocolData == NULL\n");
281 SendMessage(protocol_hwnd, WM_USER, 0, (LPARAM)pProtocolData);
285 static HRESULT WINAPI ProtocolSink_ReportProgress(IInternetProtocolSink *iface, ULONG ulStatusCode,
286 LPCWSTR szStatusText)
288 static const WCHAR null_guid[] = {'{','0','0','0','0','0','0','0','0','-','0','0','0','0','-',
289 '0','0','0','0','-','0','0','0','0','-','0','0','0','0','0','0','0','0','0','0','0','0','}',0};
290 static const WCHAR text_html[] = {'t','e','x','t','/','h','t','m','l',0};
291 static const WCHAR text_plain[] = {'t','e','x','t','/','p','l','a','i','n',0};
292 static const WCHAR host[] =
293 {'w','w','w','.','w','i','n','e','h','q','.','o','r','g',0};
294 static const WCHAR post_host[] =
295 {'c','r','o','s','s','o','v','e','r','.','c','o','d','e',
296 'w','e','a','v','e','r','s','.','c','o','m',0};
297 static const WCHAR wszWineHQIP[] =
298 {'2','0','9','.','4','6','.','2','5','.','1','3','4',0};
299 static const WCHAR wszCrossoverIP[] =
300 {'2','0','9','.','4','6','.','2','5','.','1','3','2',0};
301 /* I'm not sure if it's a good idea to hardcode here the IP address... */
303 switch(ulStatusCode) {
304 case BINDSTATUS_MIMETYPEAVAILABLE:
305 CHECK_EXPECT(ReportProgress_MIMETYPEAVAILABLE);
306 ok(szStatusText != NULL, "szStatusText == NULL\n");
308 if(tested_protocol == BIND_TEST)
309 ok(szStatusText == expect_wsz, "unexpected szStatusText\n");
310 else if (http_post_test)
311 ok(lstrlenW(text_plain) <= lstrlenW(szStatusText) &&
312 !memcmp(szStatusText, text_plain, lstrlenW(text_plain)*sizeof(WCHAR)),
313 "szStatusText != text/plain\n");
315 ok(lstrlenW(text_html) <= lstrlenW(szStatusText) &&
316 !memcmp(szStatusText, text_html, lstrlenW(text_html)*sizeof(WCHAR)),
317 "szStatusText != text/html\n");
320 case BINDSTATUS_DIRECTBIND:
321 CHECK_EXPECT2(ReportProgress_DIRECTBIND);
322 ok(szStatusText == NULL, "szStatusText != NULL\n");
324 case BINDSTATUS_RAWMIMETYPE:
325 CHECK_EXPECT2(ReportProgress_RAWMIMETYPE);
326 ok(szStatusText != NULL, "szStatusText == NULL\n");
328 ok(lstrlenW(szStatusText) < lstrlenW(text_html) ||
329 !memcmp(szStatusText, text_html, lstrlenW(text_html)*sizeof(WCHAR)),
330 "szStatusText != text/html\n");
332 case BINDSTATUS_CACHEFILENAMEAVAILABLE:
333 CHECK_EXPECT(ReportProgress_CACHEFILENAMEAVAILABLE);
334 ok(szStatusText != NULL, "szStatusText == NULL\n");
336 if(tested_protocol == BIND_TEST)
337 ok(szStatusText == expect_wsz, "unexpected szStatusText\n");
339 ok(!lstrcmpW(szStatusText, file_name), "szStatusText != file_name\n");
342 case BINDSTATUS_FINDINGRESOURCE:
343 CHECK_EXPECT(ReportProgress_FINDINGRESOURCE);
344 ok(szStatusText != NULL, "szStatusText == NULL\n");
348 ok(!lstrcmpW(szStatusText, host),
349 "szStatustext != \"www.winehq.org\"\n");
351 ok(!lstrcmpW(szStatusText, post_host),
352 "szStatustext != \"crossover.codeweavers.com\"\n");
355 case BINDSTATUS_CONNECTING:
356 CHECK_EXPECT(ReportProgress_CONNECTING);
357 ok(szStatusText != NULL, "szStatusText == NULL\n");
359 ok(!lstrcmpW(szStatusText, http_post_test ?
360 wszCrossoverIP : wszWineHQIP),
361 "Unexpected szStatusText\n");
363 case BINDSTATUS_SENDINGREQUEST:
364 CHECK_EXPECT(ReportProgress_SENDINGREQUEST);
365 if(tested_protocol == FILE_TEST) {
366 ok(szStatusText != NULL, "szStatusText == NULL\n");
368 ok(!*szStatusText, "wrong szStatusText\n");
370 ok(szStatusText == NULL, "szStatusText != NULL\n");
373 case BINDSTATUS_VERIFIEDMIMETYPEAVAILABLE:
374 CHECK_EXPECT(ReportProgress_VERIFIEDMIMETYPEAVAILABLE);
375 ok(szStatusText != NULL, "szStatusText == NULL\n");
377 ok(!lstrcmpW(szStatusText, text_html), "szStatusText != text/html\n");
379 case BINDSTATUS_PROTOCOLCLASSID:
380 CHECK_EXPECT(ReportProgress_PROTOCOLCLASSID);
381 ok(szStatusText != NULL, "szStatusText == NULL\n");
382 ok(!lstrcmpW(szStatusText, null_guid), "unexpected szStatusText\n");
385 ok(0, "Unexpected call %d\n", ulStatusCode);
391 static HRESULT WINAPI ProtocolSink_ReportData(IInternetProtocolSink *iface, DWORD grfBSCF,
392 ULONG ulProgress, ULONG ulProgressMax)
394 if(tested_protocol == FILE_TEST) {
395 CHECK_EXPECT2(ReportData);
397 ok(ulProgress == ulProgressMax, "ulProgress (%d) != ulProgressMax (%d)\n",
398 ulProgress, ulProgressMax);
399 ok(ulProgressMax == 13, "ulProgressMax=%d, expected 13\n", ulProgressMax);
400 ok(grfBSCF == (BSCF_FIRSTDATANOTIFICATION | BSCF_LASTDATANOTIFICATION),
401 "grcfBSCF = %08x\n", grfBSCF);
402 }else if(tested_protocol == HTTP_TEST) {
403 if(!(grfBSCF & BSCF_LASTDATANOTIFICATION))
404 CHECK_EXPECT(ReportData);
405 else if (http_post_test) todo_wine
406 ok(ulProgress == 13, "Read %u bytes instead of 13\n", ulProgress);
408 ok(ulProgress, "ulProgress == 0\n");
410 if(first_data_notif) {
411 ok(grfBSCF == BSCF_FIRSTDATANOTIFICATION, "grcfBSCF = %08x\n", grfBSCF);
412 first_data_notif = FALSE;
414 ok(grfBSCF == BSCF_INTERMEDIATEDATANOTIFICATION
415 || grfBSCF == (BSCF_LASTDATANOTIFICATION|BSCF_INTERMEDIATEDATANOTIFICATION),
416 "grcfBSCF = %08x\n", grfBSCF);
419 if (!(grfBSCF & BSCF_LASTDATANOTIFICATION) &&
420 !(bindf & BINDF_FROMURLMON))
421 SendMessage(protocol_hwnd, WM_USER, 0, 0);
426 static HRESULT WINAPI ProtocolSink_ReportResult(IInternetProtocolSink *iface, HRESULT hrResult,
427 DWORD dwError, LPCWSTR szResult)
429 CHECK_EXPECT(ReportResult);
431 ok(hrResult == expect_hrResult, "hrResult = %08x, expected: %08x\n",
432 hrResult, expect_hrResult);
433 if(SUCCEEDED(hrResult))
434 ok(dwError == ERROR_SUCCESS, "dwError = %d, expected ERROR_SUCCESS\n", dwError);
436 ok(dwError != ERROR_SUCCESS, "dwError == ERROR_SUCCESS\n");
437 ok(!szResult, "szResult != NULL\n");
442 static IInternetProtocolSinkVtbl protocol_sink_vtbl = {
443 ProtocolSink_QueryInterface,
445 ProtocolSink_Release,
447 ProtocolSink_ReportProgress,
448 ProtocolSink_ReportData,
449 ProtocolSink_ReportResult
452 static IInternetProtocolSink protocol_sink = { &protocol_sink_vtbl };
454 static HRESULT QueryInterface(REFIID riid, void **ppv)
458 if(IsEqualGUID(&IID_IUnknown, riid) || IsEqualGUID(&IID_IInternetProtocolSink, riid))
459 *ppv = &protocol_sink;
460 if(IsEqualGUID(&IID_IServiceProvider, riid))
461 *ppv = &service_provider;
466 return E_NOINTERFACE;
469 static HRESULT WINAPI BindInfo_QueryInterface(IInternetBindInfo *iface, REFIID riid, void **ppv)
471 if(IsEqualGUID(&IID_IUnknown, riid) || IsEqualGUID(&IID_IInternetBindInfo, riid)) {
475 return E_NOINTERFACE;
478 static ULONG WINAPI BindInfo_AddRef(IInternetBindInfo *iface)
483 static ULONG WINAPI BindInfo_Release(IInternetBindInfo *iface)
488 static HRESULT WINAPI BindInfo_GetBindInfo(IInternetBindInfo *iface, DWORD *grfBINDF, BINDINFO *pbindinfo)
492 static const CHAR szPostData[] = "mode=Test";
494 CHECK_EXPECT(GetBindInfo);
496 ok(grfBINDF != NULL, "grfBINDF == NULL\n");
497 ok(pbindinfo != NULL, "pbindinfo == NULL\n");
498 ok(pbindinfo->cbSize == sizeof(BINDINFO), "wrong size of pbindinfo: %d\n", pbindinfo->cbSize);
501 cbSize = pbindinfo->cbSize;
502 memset(pbindinfo, 0, cbSize);
503 pbindinfo->cbSize = cbSize;
507 pbindinfo->dwBindVerb = BINDVERB_POST;
508 pbindinfo->stgmedData.tymed = TYMED_HGLOBAL;
509 /* Must be GMEM_FIXED, GMEM_MOVABLE does not work properly
510 * with urlmon on native (Win98 and WinXP) */
511 pbindinfo->stgmedData.hGlobal = GlobalAlloc(GPTR, sizeof(szPostData));
512 if (!pbindinfo->stgmedData.hGlobal)
514 skip("Out of memory\n");
515 return E_OUTOFMEMORY;
517 lstrcpy((LPSTR)pbindinfo->stgmedData.hGlobal, szPostData);
518 pbindinfo->cbstgmedData = sizeof(szPostData)-1;
524 static HRESULT WINAPI BindInfo_GetBindString(IInternetBindInfo *iface, ULONG ulStringType,
525 LPOLESTR *ppwzStr, ULONG cEl, ULONG *pcElFetched)
527 static const WCHAR acc_mime[] = {'*','/','*',0};
528 static const WCHAR user_agent[] = {'W','i','n','e',0};
530 ok(ppwzStr != NULL, "ppwzStr == NULL\n");
531 ok(pcElFetched != NULL, "pcElFetched == NULL\n");
533 switch(ulStringType) {
534 case BINDSTRING_ACCEPT_MIMES:
535 CHECK_EXPECT(GetBindString_ACCEPT_MIMES);
536 ok(cEl == 256, "cEl=%d, expected 256\n", cEl);
538 ok(*pcElFetched == 256, "*pcElFetched=%d, expected 256\n", *pcElFetched);
542 *ppwzStr = CoTaskMemAlloc(sizeof(acc_mime));
543 memcpy(*ppwzStr, acc_mime, sizeof(acc_mime));
546 case BINDSTRING_USER_AGENT:
547 CHECK_EXPECT(GetBindString_USER_AGENT);
548 ok(cEl == 1, "cEl=%d, expected 1\n", cEl);
550 ok(*pcElFetched == 0, "*pcElFetch=%d, expectd 0\n", *pcElFetched);
554 *ppwzStr = CoTaskMemAlloc(sizeof(user_agent));
555 memcpy(*ppwzStr, user_agent, sizeof(user_agent));
558 case BINDSTRING_POST_COOKIE:
559 CHECK_EXPECT(GetBindString_POST_COOKIE);
560 ok(cEl == 1, "cEl=%d, expected 1\n", cEl);
562 ok(*pcElFetched == 0, "*pcElFetch=%d, expectd 0\n", *pcElFetched);
565 ok(0, "unexpected call\n");
571 static IInternetBindInfoVtbl bind_info_vtbl = {
572 BindInfo_QueryInterface,
575 BindInfo_GetBindInfo,
576 BindInfo_GetBindString
579 static IInternetBindInfo bind_info = { &bind_info_vtbl };
581 static HRESULT WINAPI InternetPriority_QueryInterface(IInternetPriority *iface,
582 REFIID riid, void **ppv)
584 ok(0, "unexpected call\n");
585 return E_NOINTERFACE;
588 static ULONG WINAPI InternetPriority_AddRef(IInternetPriority *iface)
593 static ULONG WINAPI InternetPriority_Release(IInternetPriority *iface)
598 static HRESULT WINAPI InternetPriority_SetPriority(IInternetPriority *iface, LONG nPriority)
600 CHECK_EXPECT(SetPriority);
601 ok(nPriority == 100, "nPriority=%d\n", nPriority);
605 static HRESULT WINAPI InternetPriority_GetPriority(IInternetPriority *iface, LONG *pnPriority)
607 ok(0, "unexpected call\n");
612 static const IInternetPriorityVtbl InternetPriorityVtbl = {
613 InternetPriority_QueryInterface,
614 InternetPriority_AddRef,
615 InternetPriority_Release,
616 InternetPriority_SetPriority,
617 InternetPriority_GetPriority
620 static IInternetPriority InternetPriority = { &InternetPriorityVtbl };
622 static HRESULT WINAPI Protocol_QueryInterface(IInternetProtocol *iface, REFIID riid, void **ppv)
624 if(IsEqualGUID(&IID_IUnknown, riid) || IsEqualGUID(&IID_IInternetProtocol, riid)) {
629 if(IsEqualGUID(&IID_IInternetPriority, riid)) {
630 *ppv = &InternetPriority;
634 ok(0, "unexpected call\n");
636 return E_NOINTERFACE;
639 static ULONG WINAPI Protocol_AddRef(IInternetProtocol *iface)
644 static ULONG WINAPI Protocol_Release(IInternetProtocol *iface)
649 static HRESULT WINAPI Protocol_Start(IInternetProtocol *iface, LPCWSTR szUrl,
650 IInternetProtocolSink *pOIProtSink, IInternetBindInfo *pOIBindInfo,
651 DWORD grfPI, DWORD dwReserved)
653 BINDINFO bindinfo, exp_bindinfo;
657 static const WCHAR wszTextHtml[] = {'t','e','x','t','/','h','t','m','l',0};
658 static const WCHAR empty_str[] = {0};
662 ok(pOIProtSink != NULL, "pOIProtSink == NULL\n");
663 ok(pOIBindInfo != NULL, "pOIBindInfo == NULL\n");
664 ok(!grfPI, "grfPI = %x\n", grfPI);
665 ok(!dwReserved, "dwReserved = %d\n", dwReserved);
667 memset(&bindinfo, 0, sizeof(bindinfo));
668 bindinfo.cbSize = sizeof(bindinfo);
669 memcpy(&exp_bindinfo, &bindinfo, sizeof(bindinfo));
670 SET_EXPECT(GetBindInfo);
671 hres = IInternetBindInfo_GetBindInfo(pOIBindInfo, &cbindf, &bindinfo);
672 ok(hres == S_OK, "GetBindInfo failed: %08x\n", hres);
673 CHECK_CALLED(GetBindInfo);
674 ok(cbindf == (bindf|BINDF_FROMURLMON), "bindf = %x, expected %x\n",
675 cbindf, (bindf|BINDF_FROMURLMON));
676 ok(!memcmp(&exp_bindinfo, &bindinfo, sizeof(bindinfo)), "unexpected bindinfo\n");
678 SET_EXPECT(ReportProgress_SENDINGREQUEST);
679 hres = IInternetProtocolSink_ReportProgress(pOIProtSink,
680 BINDSTATUS_SENDINGREQUEST, empty_str);
681 ok(hres == S_OK, "ReportProgress(BINDSTATUS_SENDINGREQUEST) failed: %08x\n", hres);
682 CHECK_CALLED(ReportProgress_SENDINGREQUEST);
684 SET_EXPECT(ReportProgress_CACHEFILENAMEAVAILABLE);
685 hres = IInternetProtocolSink_ReportProgress(pOIProtSink,
686 BINDSTATUS_CACHEFILENAMEAVAILABLE, expect_wsz = empty_str);
687 ok(hres == S_OK, "ReportProgress(BINDSTATUS_CACHEFILENAMEAVAILABLE) failed: %08x\n", hres);
688 CHECK_CALLED(ReportProgress_CACHEFILENAMEAVAILABLE);
690 SET_EXPECT(ReportProgress_MIMETYPEAVAILABLE);
691 hres = IInternetProtocolSink_ReportProgress(pOIProtSink,
692 BINDSTATUS_VERIFIEDMIMETYPEAVAILABLE, expect_wsz = wszTextHtml);
694 "ReportProgress(BINDSTATUS_VERIFIEDMIMETYPEAVAILABLE) failed: %08x\n", hres);
695 CHECK_CALLED(ReportProgress_MIMETYPEAVAILABLE);
697 hres = IInternetProtocolSink_ReportData(pOIProtSink,
698 BSCF_FIRSTDATANOTIFICATION | BSCF_LASTDATANOTIFICATION, 13, 13);
699 ok(hres == S_OK, "ReportData failed: %08x\n", hres);
701 SET_EXPECT(ReportResult);
702 hres = IInternetProtocolSink_ReportResult(pOIProtSink, S_OK, 0, NULL);
703 ok(hres == S_OK, "ReportResult failed: %08x\n", hres);
704 CHECK_CALLED(ReportResult);
709 static HRESULT WINAPI Protocol_Continue(IInternetProtocol *iface,
710 PROTOCOLDATA *pProtocolData)
712 ok(0, "unexpected call\n");
716 static HRESULT WINAPI Protocol_Abort(IInternetProtocol *iface, HRESULT hrReason,
719 ok(0, "unexpected call\n");
723 static HRESULT WINAPI Protocol_Terminate(IInternetProtocol *iface, DWORD dwOptions)
725 CHECK_EXPECT(Terminate);
726 ok(!dwOptions, "dwOptions=%d\n", dwOptions);
730 static HRESULT WINAPI Protocol_Suspend(IInternetProtocol *iface)
732 ok(0, "unexpected call\n");
736 static HRESULT WINAPI Protocol_Resume(IInternetProtocol *iface)
738 ok(0, "unexpected call\n");
742 static HRESULT WINAPI Protocol_Read(IInternetProtocol *iface, void *pv,
743 ULONG cb, ULONG *pcbRead)
749 ok(pv == expect_pv, "pv != expect_pv\n");
750 ok(cb == 1000, "cb=%d\n", cb);
751 ok(pcbRead != NULL, "pcbRead == NULL\n");
752 ok(!*pcbRead, "*pcbRead = %d\n", *pcbRead);
757 memset(pv, 'x', 100);
758 *pcbRead = read = 100;
762 static HRESULT WINAPI Protocol_Seek(IInternetProtocol *iface,
763 LARGE_INTEGER dlibMove, DWORD dwOrigin, ULARGE_INTEGER *plibNewPosition)
765 ok(0, "unexpected call\n");
769 static HRESULT WINAPI Protocol_LockRequest(IInternetProtocol *iface, DWORD dwOptions)
771 ok(0, "unexpected call\n");
775 static HRESULT WINAPI Protocol_UnlockRequest(IInternetProtocol *iface)
777 ok(0, "unexpected call\n");
781 static const IInternetProtocolVtbl ProtocolVtbl = {
782 Protocol_QueryInterface,
793 Protocol_LockRequest,
794 Protocol_UnlockRequest
797 static IInternetProtocol Protocol = { &ProtocolVtbl };
799 static HRESULT WINAPI ClassFactory_QueryInterface(IClassFactory *iface, REFIID riid, void **ppv)
801 ok(0, "unexpected call\n");
802 return E_NOINTERFACE;
805 static ULONG WINAPI ClassFactory_AddRef(IClassFactory *iface)
810 static ULONG WINAPI ClassFactory_Release(IClassFactory *iface)
815 static HRESULT WINAPI ClassFactory_CreateInstance(IClassFactory *iface, IUnknown *pOuter,
816 REFIID riid, void **ppv)
818 CHECK_EXPECT(CreateInstance);
820 ok(pOuter == (IUnknown*)prot_bind_info, "pOuter != protocol_unk\n");
821 ok(IsEqualGUID(&IID_IUnknown, riid), "unexpected riid\n");
822 ok(ppv != NULL, "ppv == NULL\n");
828 static HRESULT WINAPI ClassFactory_LockServer(IClassFactory *iface, BOOL dolock)
830 ok(0, "unexpected call\n");
834 static const IClassFactoryVtbl ClassFactoryVtbl = {
835 ClassFactory_QueryInterface,
837 ClassFactory_Release,
838 ClassFactory_CreateInstance,
839 ClassFactory_LockServer
842 static IClassFactory ClassFactory = { &ClassFactoryVtbl };
844 static void test_priority(IInternetProtocol *protocol)
846 IInternetPriority *priority;
850 hres = IInternetProtocol_QueryInterface(protocol, &IID_IInternetPriority,
852 ok(hres == S_OK, "QueryInterface(IID_IInternetPriority) failed: %08x\n", hres);
856 hres = IInternetPriority_GetPriority(priority, &pr);
857 ok(hres == S_OK, "GetPriority failed: %08x\n", hres);
858 ok(pr == 0, "pr=%d, expected 0\n", pr);
860 hres = IInternetPriority_SetPriority(priority, 1);
861 ok(hres == S_OK, "SetPriority failed: %08x\n", hres);
863 hres = IInternetPriority_GetPriority(priority, &pr);
864 ok(hres == S_OK, "GetPriority failed: %08x\n", hres);
865 ok(pr == 1, "pr=%d, expected 1\n", pr);
867 IInternetPriority_Release(priority);
870 static void file_protocol_start(IInternetProtocol *protocol, LPCWSTR url, BOOL is_first)
874 SET_EXPECT(GetBindInfo);
875 if(!(bindf & BINDF_FROMURLMON))
876 SET_EXPECT(ReportProgress_DIRECTBIND);
878 SET_EXPECT(ReportProgress_SENDINGREQUEST);
879 SET_EXPECT(ReportProgress_CACHEFILENAMEAVAILABLE);
880 if(bindf & BINDF_FROMURLMON)
881 SET_EXPECT(ReportProgress_VERIFIEDMIMETYPEAVAILABLE);
883 SET_EXPECT(ReportProgress_MIMETYPEAVAILABLE);
885 SET_EXPECT(ReportData);
887 SET_EXPECT(ReportResult);
889 expect_hrResult = S_OK;
891 hres = IInternetProtocol_Start(protocol, url, &protocol_sink, &bind_info, 0, 0);
892 ok(hres == S_OK, "Start failed: %08x\n", hres);
894 CHECK_CALLED(GetBindInfo);
895 if(!(bindf & BINDF_FROMURLMON))
896 CHECK_CALLED(ReportProgress_DIRECTBIND);
898 CHECK_CALLED(ReportProgress_SENDINGREQUEST);
899 CHECK_CALLED(ReportProgress_CACHEFILENAMEAVAILABLE);
900 if(bindf & BINDF_FROMURLMON)
901 CHECK_CALLED(ReportProgress_VERIFIEDMIMETYPEAVAILABLE);
903 CHECK_CALLED(ReportProgress_MIMETYPEAVAILABLE);
905 CHECK_CALLED(ReportData);
907 CHECK_CALLED(ReportResult);
910 static void test_file_protocol_url(LPCWSTR url)
912 IInternetProtocolInfo *protocol_info;
914 IClassFactory *factory;
917 hres = CoGetClassObject(&CLSID_FileProtocol, CLSCTX_INPROC_SERVER, NULL,
918 &IID_IUnknown, (void**)&unk);
919 ok(hres == S_OK, "CoGetClassObject failed: %08x\n", hres);
923 hres = IUnknown_QueryInterface(unk, &IID_IInternetProtocolInfo, (void**)&protocol_info);
924 ok(hres == E_NOINTERFACE,
925 "Could not get IInternetProtocolInfo interface: %08x, expected E_NOINTERFACE\n", hres);
927 hres = IUnknown_QueryInterface(unk, &IID_IClassFactory, (void**)&factory);
928 ok(hres == S_OK, "Could not get IClassFactory interface\n");
929 if(SUCCEEDED(hres)) {
930 IInternetProtocol *protocol;
933 hres = IClassFactory_CreateInstance(factory, NULL, &IID_IInternetProtocol, (void**)&protocol);
934 ok(hres == S_OK, "Could not get IInternetProtocol: %08x\n", hres);
936 if(SUCCEEDED(hres)) {
937 file_protocol_start(protocol, url, TRUE);
938 hres = IInternetProtocol_Read(protocol, buf, 2, &cb);
939 ok(hres == S_OK, "Read failed: %08x\n", hres);
940 ok(cb == 2, "cb=%u expected 2\n", cb);
941 hres = IInternetProtocol_Read(protocol, buf, sizeof(buf), &cb);
942 ok(hres == S_FALSE, "Read failed: %08x\n", hres);
943 hres = IInternetProtocol_Read(protocol, buf, sizeof(buf), &cb);
944 ok(hres == S_FALSE, "Read failed: %08x expected S_FALSE\n", hres);
945 ok(cb == 0, "cb=%u expected 0\n", cb);
946 hres = IInternetProtocol_UnlockRequest(protocol);
947 ok(hres == S_OK, "UnlockRequest failed: %08x\n", hres);
949 file_protocol_start(protocol, url, FALSE);
950 hres = IInternetProtocol_Read(protocol, buf, 2, &cb);
951 ok(hres == S_FALSE, "Read failed: %08x\n", hres);
952 hres = IInternetProtocol_LockRequest(protocol, 0);
953 ok(hres == S_OK, "LockRequest failed: %08x\n", hres);
954 hres = IInternetProtocol_UnlockRequest(protocol);
955 ok(hres == S_OK, "UnlockRequest failed: %08x\n", hres);
957 IInternetProtocol_Release(protocol);
960 hres = IClassFactory_CreateInstance(factory, NULL, &IID_IInternetProtocol, (void**)&protocol);
961 ok(hres == S_OK, "Could not get IInternetProtocol: %08x\n", hres);
963 if(SUCCEEDED(hres)) {
964 file_protocol_start(protocol, url, TRUE);
965 hres = IInternetProtocol_LockRequest(protocol, 0);
966 ok(hres == S_OK, "LockRequest failed: %08x\n", hres);
967 hres = IInternetProtocol_Terminate(protocol, 0);
968 ok(hres == S_OK, "Terminate failed: %08x\n", hres);
969 hres = IInternetProtocol_Read(protocol, buf, 2, &cb);
970 ok(hres == S_OK, "Read failed: %08x\n\n", hres);
971 hres = IInternetProtocol_UnlockRequest(protocol);
972 ok(hres == S_OK, "UnlockRequest failed: %08x\n", hres);
973 hres = IInternetProtocol_Read(protocol, buf, 2, &cb);
974 ok(hres == S_OK, "Read failed: %08x\n", hres);
975 hres = IInternetProtocol_Terminate(protocol, 0);
976 ok(hres == S_OK, "Terminate failed: %08x\n", hres);
978 IInternetProtocol_Release(protocol);
981 hres = IClassFactory_CreateInstance(factory, NULL, &IID_IInternetProtocol, (void**)&protocol);
982 ok(hres == S_OK, "Could not get IInternetProtocol: %08x\n", hres);
984 if(SUCCEEDED(hres)) {
985 file_protocol_start(protocol, url, TRUE);
986 hres = IInternetProtocol_Terminate(protocol, 0);
987 ok(hres == S_OK, "Terminate failed: %08x\n", hres);
988 hres = IInternetProtocol_Read(protocol, buf, 2, &cb);
989 ok(hres == S_OK, "Read failed: %08x\n", hres);
990 ok(cb == 2, "cb=%u expected 2\n", cb);
992 IInternetProtocol_Release(protocol);
995 IClassFactory_Release(factory);
998 IUnknown_Release(unk);
1001 static void test_file_protocol_fail(void)
1003 IInternetProtocol *protocol;
1006 static const WCHAR index_url2[] =
1007 {'f','i','l','e',':','/','/','i','n','d','e','x','.','h','t','m','l',0};
1009 hres = CoCreateInstance(&CLSID_FileProtocol, NULL, CLSCTX_INPROC_SERVER|CLSCTX_INPROC_HANDLER,
1010 &IID_IInternetProtocol, (void**)&protocol);
1011 ok(hres == S_OK, "CoCreateInstance failed: %08x\n", hres);
1015 SET_EXPECT(GetBindInfo);
1016 expect_hrResult = MK_E_SYNTAX;
1017 hres = IInternetProtocol_Start(protocol, wszIndexHtml, &protocol_sink, &bind_info, 0, 0);
1018 ok(hres == MK_E_SYNTAX, "Start failed: %08x, expected MK_E_SYNTAX\n", hres);
1019 CHECK_CALLED(GetBindInfo);
1021 SET_EXPECT(GetBindInfo);
1022 if(!(bindf & BINDF_FROMURLMON))
1023 SET_EXPECT(ReportProgress_DIRECTBIND);
1024 SET_EXPECT(ReportProgress_SENDINGREQUEST);
1025 SET_EXPECT(ReportResult);
1026 expect_hrResult = INET_E_RESOURCE_NOT_FOUND;
1027 hres = IInternetProtocol_Start(protocol, index_url, &protocol_sink, &bind_info, 0, 0);
1028 ok(hres == INET_E_RESOURCE_NOT_FOUND,
1029 "Start failed: %08x expected INET_E_RESOURCE_NOT_FOUND\n", hres);
1030 CHECK_CALLED(GetBindInfo);
1031 if(!(bindf & BINDF_FROMURLMON))
1032 CHECK_CALLED(ReportProgress_DIRECTBIND);
1033 CHECK_CALLED(ReportProgress_SENDINGREQUEST);
1034 CHECK_CALLED(ReportResult);
1036 IInternetProtocol_Release(protocol);
1038 hres = CoCreateInstance(&CLSID_FileProtocol, NULL, CLSCTX_INPROC_SERVER|CLSCTX_INPROC_HANDLER,
1039 &IID_IInternetProtocol, (void**)&protocol);
1040 ok(hres == S_OK, "CoCreateInstance failed: %08x\n", hres);
1044 SET_EXPECT(GetBindInfo);
1045 if(!(bindf & BINDF_FROMURLMON))
1046 SET_EXPECT(ReportProgress_DIRECTBIND);
1047 SET_EXPECT(ReportProgress_SENDINGREQUEST);
1048 SET_EXPECT(ReportResult);
1049 expect_hrResult = INET_E_RESOURCE_NOT_FOUND;
1051 hres = IInternetProtocol_Start(protocol, index_url2, &protocol_sink, &bind_info, 0, 0);
1052 ok(hres == INET_E_RESOURCE_NOT_FOUND,
1053 "Start failed: %08x, expected INET_E_RESOURCE_NOT_FOUND\n", hres);
1054 CHECK_CALLED(GetBindInfo);
1055 if(!(bindf & BINDF_FROMURLMON))
1056 CHECK_CALLED(ReportProgress_DIRECTBIND);
1057 CHECK_CALLED(ReportProgress_SENDINGREQUEST);
1058 CHECK_CALLED(ReportResult);
1060 IInternetProtocol_Release(protocol);
1063 static void test_file_protocol(void) {
1064 WCHAR buf[MAX_PATH];
1069 static const WCHAR wszFile[] = {'f','i','l','e',':',0};
1070 static const WCHAR wszFile2[] = {'f','i','l','e',':','/','/',0};
1071 static const WCHAR wszFile3[] = {'f','i','l','e',':','/','/','/',0};
1072 static const char html_doc[] = "<HTML></HTML>";
1074 trace("Testing file protocol...\n");
1075 tested_protocol = FILE_TEST;
1077 file = CreateFileW(wszIndexHtml, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS,
1078 FILE_ATTRIBUTE_NORMAL, NULL);
1079 ok(file != INVALID_HANDLE_VALUE, "CreateFile failed\n");
1080 if(file == INVALID_HANDLE_VALUE)
1082 WriteFile(file, html_doc, sizeof(html_doc)-1, &size, NULL);
1085 file_name = wszIndexHtml;
1087 test_file_protocol_url(index_url);
1088 bindf = BINDF_FROMURLMON;
1089 test_file_protocol_url(index_url);
1091 memcpy(buf, wszFile, sizeof(wszFile));
1092 len = sizeof(wszFile)/sizeof(WCHAR)-1;
1093 len += GetCurrentDirectoryW(sizeof(buf)/sizeof(WCHAR)-len, buf+len);
1095 memcpy(buf+len, wszIndexHtml, sizeof(wszIndexHtml));
1097 file_name = buf + sizeof(wszFile)/sizeof(WCHAR)-1;
1099 test_file_protocol_url(buf);
1100 bindf = BINDF_FROMURLMON;
1101 test_file_protocol_url(buf);
1103 memcpy(buf, wszFile2, sizeof(wszFile2));
1104 len = sizeof(wszFile2)/sizeof(WCHAR)-1;
1105 len += GetCurrentDirectoryW(sizeof(buf)/sizeof(WCHAR)-len, buf+len);
1107 memcpy(buf+len, wszIndexHtml, sizeof(wszIndexHtml));
1109 file_name = buf + sizeof(wszFile2)/sizeof(WCHAR)-1;
1111 test_file_protocol_url(buf);
1112 bindf = BINDF_FROMURLMON;
1113 test_file_protocol_url(buf);
1115 memcpy(buf, wszFile3, sizeof(wszFile3));
1116 len = sizeof(wszFile3)/sizeof(WCHAR)-1;
1117 len += GetCurrentDirectoryW(sizeof(buf)/sizeof(WCHAR)-len, buf+len);
1119 memcpy(buf+len, wszIndexHtml, sizeof(wszIndexHtml));
1121 file_name = buf + sizeof(wszFile3)/sizeof(WCHAR)-1;
1123 test_file_protocol_url(buf);
1124 bindf = BINDF_FROMURLMON;
1125 test_file_protocol_url(buf);
1127 DeleteFileW(wszIndexHtml);
1130 test_file_protocol_fail();
1131 bindf = BINDF_FROMURLMON;
1132 test_file_protocol_fail();
1135 static BOOL http_protocol_start(LPCWSTR url, BOOL is_first)
1137 static BOOL got_user_agent = FALSE;
1140 first_data_notif = TRUE;
1143 SET_EXPECT(GetBindInfo);
1144 if (!(bindf & BINDF_FROMURLMON))
1145 SET_EXPECT(ReportProgress_DIRECTBIND);
1146 SET_EXPECT(GetBindString_USER_AGENT);
1147 SET_EXPECT(GetBindString_ACCEPT_MIMES);
1148 SET_EXPECT(QueryService_HttpNegotiate);
1149 SET_EXPECT(BeginningTransaction);
1150 SET_EXPECT(GetRootSecurityId);
1152 SET_EXPECT(GetBindString_POST_COOKIE);
1154 hres = IInternetProtocol_Start(http_protocol, url, &protocol_sink, &bind_info, 0, 0);
1155 ok(hres == S_OK, "Start failed: %08x\n", hres);
1159 CHECK_CALLED(GetBindInfo);
1160 if (!(bindf & BINDF_FROMURLMON))
1161 CHECK_CALLED(ReportProgress_DIRECTBIND);
1162 if (!got_user_agent)
1164 CHECK_CALLED(GetBindString_USER_AGENT);
1165 got_user_agent = TRUE;
1169 /* user agent only retrieved once, even with different URLs */
1170 CHECK_NOT_CALLED(GetBindString_USER_AGENT);
1172 CHECK_CALLED(GetBindString_ACCEPT_MIMES);
1173 CHECK_CALLED(QueryService_HttpNegotiate);
1174 CHECK_CALLED(BeginningTransaction);
1175 /* GetRootSecurityId called on WinXP but not on Win98 */
1176 CLEAR_CALLED(GetRootSecurityId);
1177 if (http_post_test) todo_wine
1178 CHECK_CALLED(GetBindString_POST_COOKIE);
1183 /* is_first refers to whether this is the first call to this function
1185 static void test_http_protocol_url(LPCWSTR url, BOOL is_first)
1187 IInternetProtocolInfo *protocol_info;
1188 IClassFactory *factory;
1192 trace("Testing http protocol...\n");
1194 http_is_first = is_first;
1196 hres = CoGetClassObject(&CLSID_HttpProtocol, CLSCTX_INPROC_SERVER, NULL,
1197 &IID_IUnknown, (void**)&unk);
1198 ok(hres == S_OK, "CoGetClassObject failed: %08x\n", hres);
1199 if(!SUCCEEDED(hres))
1202 hres = IUnknown_QueryInterface(unk, &IID_IInternetProtocolInfo, (void**)&protocol_info);
1203 ok(hres == E_NOINTERFACE,
1204 "Could not get IInternetProtocolInfo interface: %08x, expected E_NOINTERFACE\n",
1207 hres = IUnknown_QueryInterface(unk, &IID_IClassFactory, (void**)&factory);
1208 ok(hres == S_OK, "Could not get IClassFactory interface\n");
1209 IUnknown_Release(unk);
1213 hres = IClassFactory_CreateInstance(factory, NULL, &IID_IInternetProtocol,
1214 (void**)&http_protocol);
1215 ok(hres == S_OK, "Could not get IInternetProtocol: %08x\n", hres);
1216 if(SUCCEEDED(hres)) {
1221 test_priority(http_protocol);
1223 SET_EXPECT(ReportProgress_FINDINGRESOURCE);
1224 SET_EXPECT(ReportProgress_CONNECTING);
1225 SET_EXPECT(ReportProgress_SENDINGREQUEST);
1226 if(!(bindf & BINDF_FROMURLMON))
1228 SET_EXPECT(OnResponse);
1229 SET_EXPECT(ReportProgress_RAWMIMETYPE);
1230 SET_EXPECT(ReportData);
1233 if(!http_protocol_start(url, is_first))
1236 hres = IInternetProtocol_Read(http_protocol, buf, 2, &cb);
1237 ok(hres == E_PENDING, "Read failed: %08x, expected E_PENDING\n", hres);
1238 ok(!cb, "cb=%d, expected 0\n", cb);
1240 if(bindf & BINDF_FROMURLMON)
1242 SET_EXPECT(ReportResult);
1243 expect_hrResult = S_OK;
1245 GetMessage(&msg, NULL, 0, 0);
1247 if(bindf & BINDF_FROMURLMON)
1248 CHECK_CALLED(Switch);
1249 CHECK_CALLED(ReportResult);
1251 hres = IInternetProtocol_Terminate(http_protocol, 0);
1252 ok(hres == S_OK, "Terminate failed: %08x\n", hres);
1254 IInternetProtocol_Release(http_protocol);
1257 IClassFactory_Release(factory);
1260 static void test_http_protocol(void)
1262 static const WCHAR winehq_url[] =
1263 {'h','t','t','p',':','/','/','w','w','w','.','w','i','n','e','h','q','.',
1264 'o','r','g','/','s','i','t','e','/','a','b','o','u','t',0};
1265 static const WCHAR posttest_url[] =
1266 {'h','t','t','p',':','/','/','c','r','o','s','s','o','v','e','r','.',
1267 'c','o','d','e','w','e','a','v','e','r','s','.','c','o','m','/',
1268 'p','o','s','t','t','e','s','t','.','p','h','p',0};
1270 tested_protocol = HTTP_TEST;
1271 bindf = BINDF_ASYNCHRONOUS | BINDF_ASYNCSTORAGE | BINDF_PULLDATA;
1272 test_http_protocol_url(winehq_url, TRUE);
1273 bindf = BINDF_ASYNCHRONOUS | BINDF_ASYNCSTORAGE | BINDF_PULLDATA | BINDF_FROMURLMON;
1274 test_http_protocol_url(winehq_url, FALSE);
1276 http_post_test = TRUE;
1277 /* Without this flag we get a ReportProgress_CACHEFILENAMEAVAILABLE
1278 * notification with BINDVERB_POST */
1279 bindf |= BINDF_NOWRITECACHE;
1280 test_http_protocol_url(posttest_url, TRUE);
1281 http_post_test = FALSE;
1284 static LRESULT WINAPI wnd_proc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
1286 if(msg == WM_USER) {
1287 BOOL first_call = FALSE;
1298 CHECK_CALLED(ReportProgress_FINDINGRESOURCE);
1299 CHECK_CALLED(ReportProgress_CONNECTING);
1303 CHECK_NOT_CALLED(ReportProgress_FINDINGRESOURCE);
1304 CHECK_NOT_CALLED(ReportProgress_CONNECTING);
1306 CHECK_CALLED(ReportProgress_SENDINGREQUEST);
1307 if(!(bindf & BINDF_FROMURLMON))
1309 CHECK_CALLED(OnResponse);
1310 CHECK_CALLED(ReportProgress_RAWMIMETYPE);
1311 CHECK_CALLED(ReportData);
1315 SET_EXPECT(OnResponse);
1316 SET_EXPECT(ReportProgress_MIMETYPEAVAILABLE);
1319 SET_EXPECT(ReportData);
1321 if (bindf & BINDF_FROMURLMON)
1323 hres = IInternetProtocol_Continue(http_protocol, (PROTOCOLDATA*)lParam);
1324 ok(hres == S_OK, "Continue failed: %08x\n", hres);
1326 CHECK_CALLED(ReportData);
1328 CHECK_CALLED(OnResponse);
1329 CHECK_CALLED(ReportProgress_MIMETYPEAVAILABLE);
1333 do hres = IInternetProtocol_Read(http_protocol, buf, sizeof(buf), &cb);
1336 ok(hres == S_FALSE || hres == E_PENDING, "Read failed: %08x\n", hres);
1339 PostMessage(protocol_hwnd, WM_USER+1, 0, 0);
1342 hres = IInternetProtocol_LockRequest(http_protocol, 0);
1343 ok(hres == S_OK, "LockRequest failed: %08x\n", hres);
1345 do hres = IInternetProtocol_Read(http_protocol, buf, sizeof(buf), &cb);
1347 ok(hres == S_FALSE || hres == E_PENDING, "Read failed: %08x\n", hres);
1351 return DefWindowProc(hwnd, msg, wParam, lParam);
1354 static HWND create_protocol_window(void)
1356 static WNDCLASSEX wndclass = {
1360 0, 0, NULL, NULL, NULL, NULL, NULL,
1365 RegisterClassEx(&wndclass);
1366 return CreateWindow("ProtocolWindow", "ProtocolWindow",
1367 WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
1368 CW_USEDEFAULT, NULL, NULL, NULL, NULL);
1371 static void test_mk_protocol(void)
1373 IInternetProtocolInfo *protocol_info;
1374 IInternetProtocol *protocol;
1375 IClassFactory *factory;
1379 static const WCHAR wrong_url1[] = {'t','e','s','t',':','@','M','S','I','T','S','t','o','r','e',
1380 ':',':','/','t','e','s','t','.','h','t','m','l',0};
1381 static const WCHAR wrong_url2[] = {'m','k',':','/','t','e','s','t','.','h','t','m','l',0};
1383 trace("Testing mk protocol...\n");
1384 tested_protocol = MK_TEST;
1386 hres = CoGetClassObject(&CLSID_MkProtocol, CLSCTX_INPROC_SERVER, NULL,
1387 &IID_IUnknown, (void**)&unk);
1388 ok(hres == S_OK, "CoGetClassObject failed: %08x\n", hres);
1390 hres = IUnknown_QueryInterface(unk, &IID_IInternetProtocolInfo, (void**)&protocol_info);
1391 ok(hres == E_NOINTERFACE,
1392 "Could not get IInternetProtocolInfo interface: %08x, expected E_NOINTERFACE\n",
1395 hres = IUnknown_QueryInterface(unk, &IID_IClassFactory, (void**)&factory);
1396 ok(hres == S_OK, "Could not get IClassFactory interface\n");
1397 IUnknown_Release(unk);
1401 hres = IClassFactory_CreateInstance(factory, NULL, &IID_IInternetProtocol,
1403 IClassFactory_Release(factory);
1404 ok(hres == S_OK, "Could not get IInternetProtocol: %08x\n", hres);
1406 SET_EXPECT(GetBindInfo);
1407 hres = IInternetProtocol_Start(protocol, wrong_url1, &protocol_sink, &bind_info, 0, 0);
1408 ok(hres == MK_E_SYNTAX, "Start failed: %08x, expected MK_E_SYNTAX\n", hres);
1409 CHECK_CALLED(GetBindInfo);
1411 SET_EXPECT(GetBindInfo);
1412 SET_EXPECT(ReportProgress_DIRECTBIND);
1413 SET_EXPECT(ReportProgress_SENDINGREQUEST);
1414 SET_EXPECT(ReportProgress_MIMETYPEAVAILABLE);
1415 SET_EXPECT(ReportResult);
1416 expect_hrResult = INET_E_RESOURCE_NOT_FOUND;
1418 hres = IInternetProtocol_Start(protocol, wrong_url2, &protocol_sink, &bind_info, 0, 0);
1419 ok(hres == INET_E_RESOURCE_NOT_FOUND, "Start failed: %08x, expected INET_E_RESOURCE_NOT_FOUND\n", hres);
1421 CHECK_CALLED(GetBindInfo);
1422 CHECK_CALLED(ReportProgress_DIRECTBIND);
1423 CHECK_CALLED(ReportProgress_SENDINGREQUEST);
1424 CHECK_CALLED(ReportProgress_MIMETYPEAVAILABLE);
1425 CHECK_CALLED(ReportResult);
1427 IInternetProtocol_Release(protocol);
1430 static void test_CreateBinding(void)
1432 IInternetProtocol *protocol;
1433 IInternetPriority *priority;
1434 IInternetSession *session;
1440 static const WCHAR test_url[] =
1441 {'t','e','s','t',':','/','/','f','i','l','e','.','h','t','m','l',0};
1442 static const WCHAR wsz_test[] = {'t','e','s','t',0};
1444 trace("Testing CreateBinding...\n");
1445 tested_protocol = BIND_TEST;
1447 hres = CoInternetGetSession(0, &session, 0);
1448 ok(hres == S_OK, "CoInternetGetSession failed: %08x\n", hres);
1450 hres = IInternetSession_RegisterNameSpace(session, &ClassFactory, &IID_NULL, wsz_test, 0, NULL, 0);
1451 ok(hres == S_OK, "RegisterNameSpace failed: %08x\n", hres);
1453 hres = IInternetSession_CreateBinding(session, NULL, test_url, NULL, NULL, &protocol, 0);
1454 ok(hres == S_OK, "CreateBinding failed: %08x\n", hres);
1455 ok(protocol != NULL, "protocol == NULL\n");
1457 hres = IInternetProtocol_QueryInterface(protocol, &IID_IInternetBindInfo, (void**)&prot_bind_info);
1458 ok(hres == S_OK, "QueryInterface(IID_IInternetBindInfo) failed: %08x\n", hres);
1460 hres = IInternetProtocol_Start(protocol, test_url, NULL, &bind_info, 0, 0);
1461 ok(hres == E_INVALIDARG, "Start failed: %08x, expected E_INVALIDARG\n", hres);
1462 hres = IInternetProtocol_Start(protocol, test_url, &protocol_sink, NULL, 0, 0);
1463 ok(hres == E_INVALIDARG, "Start failed: %08x, expected E_INVALIDARG\n", hres);
1464 hres = IInternetProtocol_Start(protocol, NULL, &protocol_sink, &bind_info, 0, 0);
1465 ok(hres == E_INVALIDARG, "Start failed: %08x, expected E_INVALIDARG\n", hres);
1467 hres = IInternetProtocol_QueryInterface(protocol, &IID_IInternetPriority, (void**)&priority);
1468 ok(hres == S_OK, "QueryInterface(IID_IInternetPriority) failed: %08x\n", hres);
1471 hres = IInternetPriority_GetPriority(priority, &p);
1472 ok(hres == S_OK, "GetPriority failed: %08x\n", hres);
1473 ok(!p, "p=%d\n", p);
1475 hres = IInternetPriority_SetPriority(priority, 100);
1476 ok(hres == S_OK, "SetPriority failed: %08x\n", hres);
1479 hres = IInternetPriority_GetPriority(priority, &p);
1480 ok(hres == S_OK, "GetPriority failed: %08x\n", hres);
1481 ok(p == 100, "p=%d\n", p);
1483 SET_EXPECT(QueryService_InternetProtocol);
1484 SET_EXPECT(CreateInstance);
1485 SET_EXPECT(ReportProgress_PROTOCOLCLASSID);
1486 SET_EXPECT(SetPriority);
1489 expect_hrResult = S_OK;
1490 hres = IInternetProtocol_Start(protocol, test_url, &protocol_sink, &bind_info, 0, 0);
1491 ok(hres == S_OK, "Start failed: %08x\n", hres);
1493 CHECK_CALLED(QueryService_InternetProtocol);
1494 CHECK_CALLED(CreateInstance);
1495 CHECK_CALLED(ReportProgress_PROTOCOLCLASSID);
1496 CHECK_CALLED(SetPriority);
1497 CHECK_CALLED(Start);
1501 hres = IInternetProtocol_Read(protocol, expect_pv = buf, sizeof(buf), &read);
1502 ok(hres == S_OK, "Read failed: %08x\n", hres);
1503 ok(read == 100, "read = %d\n", read);
1508 hres = IInternetProtocol_Read(protocol, expect_pv = buf, sizeof(buf), &read);
1509 ok(hres == S_FALSE, "Read failed: %08x\n", hres);
1510 ok(!read, "read = %d\n", read);
1514 hres = IInternetPriority_GetPriority(priority, &p);
1515 ok(hres == S_OK, "GetPriority failed: %08x\n", hres);
1516 ok(p == 100, "p=%d\n", p);
1518 hres = IInternetPriority_SetPriority(priority, 101);
1519 ok(hres == S_OK, "SetPriority failed: %08x\n", hres);
1521 SET_EXPECT(Terminate);
1522 hres = IInternetProtocol_Terminate(protocol, 0xdeadbeef);
1523 ok(hres == S_OK, "Terminate failed: %08x\n", hres);
1524 CHECK_CALLED(Terminate);
1526 IInternetPriority_Release(priority);
1527 IInternetBindInfo_Release(prot_bind_info);
1528 IInternetProtocol_Release(protocol);
1529 IInternetSession_Release(session);
1532 START_TEST(protocol)
1534 OleInitialize(NULL);
1536 protocol_hwnd = create_protocol_window();
1538 test_file_protocol();
1539 test_http_protocol();
1541 test_CreateBinding();
1543 DestroyWindow(protocol_hwnd);