2 * Copyright 2005 Jacek Caban
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
21 #include <wine/test.h>
31 #define DEFINE_EXPECT(func) \
32 static BOOL expect_ ## func = FALSE, called_ ## func = FALSE
34 #define SET_EXPECT(func) \
35 expect_ ## func = TRUE
37 #define CHECK_EXPECT(func) \
39 ok(expect_ ##func, "unexpected call " #func "\n"); \
40 expect_ ## func = FALSE; \
41 called_ ## func = TRUE; \
44 #define CHECK_EXPECT2(func) \
46 ok(expect_ ##func, "unexpected call " #func "\n"); \
47 called_ ## func = TRUE; \
50 #define CHECK_CALLED(func) \
52 ok(called_ ## func, "expected " #func "\n"); \
53 expect_ ## func = called_ ## func = FALSE; \
56 DEFINE_EXPECT(GetBindInfo);
57 DEFINE_EXPECT(ReportProgress_MIMETYPEAVAILABLE);
58 DEFINE_EXPECT(ReportProgress_DIRECTBIND);
59 DEFINE_EXPECT(ReportProgress_FINDINGRESOURCE);
60 DEFINE_EXPECT(ReportProgress_CONNECTING);
61 DEFINE_EXPECT(ReportProgress_SENDINGREQUEST);
62 DEFINE_EXPECT(ReportProgress_CACHEFILENAMEAVAILABLE);
63 DEFINE_EXPECT(ReportProgress_VERIFIEDMIMETYPEAVAILABLE);
64 DEFINE_EXPECT(ReportData);
65 DEFINE_EXPECT(ReportResult);
66 DEFINE_EXPECT(GetBindString_ACCEPT_MIMES);
67 DEFINE_EXPECT(GetBindString_USER_AGENT);
68 DEFINE_EXPECT(QueryService_HttpNegotiate);
69 DEFINE_EXPECT(BeginningTransaction);
70 DEFINE_EXPECT(GetRootSecurityId);
71 DEFINE_EXPECT(OnResponse);
72 DEFINE_EXPECT(Switch);
74 static const WCHAR wszIndexHtml[] = {'i','n','d','e','x','.','h','t','m','l',0};
75 static const WCHAR index_url[] =
76 {'f','i','l','e',':','i','n','d','e','x','.','h','t','m','l',0};
78 static HRESULT expect_hrResult;
79 static LPCWSTR file_name, http_url;
80 static IInternetProtocol *http_protocol = NULL;
81 static BOOL first_data_notif = FALSE;
82 static HWND protocol_hwnd;
84 static DWORD bindf = 0;
91 static HRESULT WINAPI HttpNegotiate_QueryInterface(IHttpNegotiate2 *iface, REFIID riid, void **ppv)
93 if(IsEqualGUID(&IID_IUnknown, riid)
94 || IsEqualGUID(&IID_IHttpNegotiate, riid)
95 || IsEqualGUID(&IID_IHttpNegotiate2, riid)) {
100 ok(0, "unexpected call\n");
101 return E_NOINTERFACE;
104 static ULONG WINAPI HttpNegotiate_AddRef(IHttpNegotiate2 *iface)
109 static ULONG WINAPI HttpNegotiate_Release(IHttpNegotiate2 *iface)
114 static HRESULT WINAPI HttpNegotiate_BeginningTransaction(IHttpNegotiate2 *iface, LPCWSTR szURL,
115 LPCWSTR szHeaders, DWORD dwReserved, LPWSTR *pszAdditionalHeaders)
117 CHECK_EXPECT(BeginningTransaction);
119 ok(!lstrcmpW(szURL, http_url), "szURL != http_url\n");
121 ok(szHeaders != NULL, "szHeaders == NULL\n");
123 static const WCHAR header[] =
124 {'A','c','c','e','p','t','-','E','n','c','o','d','i','n','g',':',
125 ' ','g','z','i','p',',',' ','d','e','f','l','a','t','e',0};
126 ok(!lstrcmpW(header, szHeaders), "Unexpected szHeaders\n");
129 ok(!dwReserved, "dwReserved=%ld, expected 0\n", dwReserved);
130 ok(pszAdditionalHeaders != NULL, "pszAdditionalHeaders == NULL\n");
131 if(pszAdditionalHeaders)
132 ok(*pszAdditionalHeaders == NULL, "*pszAdditionalHeaders != NULL\n");
137 static HRESULT WINAPI HttpNegotiate_OnResponse(IHttpNegotiate2 *iface, DWORD dwResponseCode,
138 LPCWSTR szResponseHeaders, LPCWSTR szRequestHeaders, LPWSTR *pszAdditionalRequestHeaders)
140 CHECK_EXPECT(OnResponse);
142 ok(dwResponseCode == 200, "dwResponseCode=%ld, expected 200\n", dwResponseCode);
143 ok(szResponseHeaders != NULL, "szResponseHeaders == NULL\n");
144 ok(szRequestHeaders == NULL, "szRequestHeaders != NULL\n");
145 ok(pszAdditionalRequestHeaders == NULL, "pszAdditionalHeaders != NULL\n");
150 static HRESULT WINAPI HttpNegotiate_GetRootSecurityId(IHttpNegotiate2 *iface,
151 BYTE *pbSecurityId, DWORD *pcbSecurityId, DWORD_PTR dwReserved)
153 static const BYTE sec_id[] = {'h','t','t','p',':','t','e','s','t',1,0,0,0};
155 CHECK_EXPECT(GetRootSecurityId);
157 ok(!dwReserved, "dwReserved=%ld, expected 0\n", dwReserved);
158 ok(pbSecurityId != NULL, "pbSecurityId == NULL\n");
159 ok(pcbSecurityId != NULL, "pcbSecurityId == NULL\n");
162 ok(*pcbSecurityId == 512, "*pcbSecurityId=%ld, expected 512\n", *pcbSecurityId);
163 *pcbSecurityId = sizeof(sec_id);
167 memcpy(pbSecurityId, sec_id, sizeof(sec_id));
172 static IHttpNegotiate2Vtbl HttpNegotiateVtbl = {
173 HttpNegotiate_QueryInterface,
174 HttpNegotiate_AddRef,
175 HttpNegotiate_Release,
176 HttpNegotiate_BeginningTransaction,
177 HttpNegotiate_OnResponse,
178 HttpNegotiate_GetRootSecurityId
181 static IHttpNegotiate2 http_negotiate = { &HttpNegotiateVtbl };
183 static HRESULT QueryInterface(REFIID,void**);
185 static HRESULT WINAPI ServiceProvider_QueryInterface(IServiceProvider *iface, REFIID riid, void **ppv)
187 return QueryInterface(riid, ppv);
190 static ULONG WINAPI ServiceProvider_AddRef(IServiceProvider *iface)
195 static ULONG WINAPI ServiceProvider_Release(IServiceProvider *iface)
200 static HRESULT WINAPI ServiceProvider_QueryService(IServiceProvider *iface, REFGUID guidService,
201 REFIID riid, void **ppv)
203 if(IsEqualGUID(&IID_IHttpNegotiate, guidService) || IsEqualGUID(&IID_IHttpNegotiate2, riid)) {
204 CHECK_EXPECT2(QueryService_HttpNegotiate);
205 return IHttpNegotiate2_QueryInterface(&http_negotiate, riid, ppv);
208 ok(0, "unexpected call\n");
212 static const IServiceProviderVtbl ServiceProviderVtbl = {
213 ServiceProvider_QueryInterface,
214 ServiceProvider_AddRef,
215 ServiceProvider_Release,
216 ServiceProvider_QueryService
219 static IServiceProvider service_provider = { &ServiceProviderVtbl };
221 static HRESULT WINAPI ProtocolSink_QueryInterface(IInternetProtocolSink *iface, REFIID riid, void **ppv)
223 return QueryInterface(riid, ppv);
226 static ULONG WINAPI ProtocolSink_AddRef(IInternetProtocolSink *iface)
231 static ULONG WINAPI ProtocolSink_Release(IInternetProtocolSink *iface)
236 static HRESULT WINAPI ProtocolSink_Switch(IInternetProtocolSink *iface, PROTOCOLDATA *pProtocolData)
238 CHECK_EXPECT2(Switch);
239 ok(pProtocolData != NULL, "pProtocolData == NULL\n");
240 SendMessageW(protocol_hwnd, WM_USER, 0, (LPARAM)pProtocolData);
244 static HRESULT WINAPI ProtocolSink_ReportProgress(IInternetProtocolSink *iface, ULONG ulStatusCode,
245 LPCWSTR szStatusText)
247 static const WCHAR text_html[] = {'t','e','x','t','/','h','t','m','l',0};
248 static const WCHAR host[] =
249 {'w','w','w','.','w','i','n','e','h','q','.','o','r','g',0};
250 static const WCHAR wszWineHQIP[] =
251 {'2','0','9','.','3','2','.','1','4','1','.','3',0};
252 /* I'm not sure if it's a good idea to hardcode here the IP address... */
254 switch(ulStatusCode) {
255 case BINDSTATUS_MIMETYPEAVAILABLE:
256 CHECK_EXPECT(ReportProgress_MIMETYPEAVAILABLE);
257 ok(szStatusText != NULL, "szStatusText == NULL\n");
259 ok(!lstrcmpW(szStatusText, text_html), "szStatusText != text/html\n");
261 case BINDSTATUS_DIRECTBIND:
262 CHECK_EXPECT2(ReportProgress_DIRECTBIND);
263 ok(szStatusText == NULL, "szStatusText != NULL\n");
265 case BINDSTATUS_CACHEFILENAMEAVAILABLE:
266 CHECK_EXPECT(ReportProgress_CACHEFILENAMEAVAILABLE);
267 ok(szStatusText != NULL, "szStatusText == NULL\n");
269 ok(!lstrcmpW(szStatusText, file_name), "szStatusText != file_name\n");
271 case BINDSTATUS_FINDINGRESOURCE:
272 CHECK_EXPECT(ReportProgress_FINDINGRESOURCE);
273 ok(szStatusText != NULL, "szStatusText == NULL\n");
275 ok(!lstrcmpW(szStatusText, host), "szStatustext != \"www.winehq.org\"\n");
277 case BINDSTATUS_CONNECTING:
278 CHECK_EXPECT(ReportProgress_CONNECTING);
279 ok(szStatusText != NULL, "szStatusText == NULL\n");
281 ok(!lstrcmpW(szStatusText, wszWineHQIP), "Unexpected szStatusText\n");
283 case BINDSTATUS_SENDINGREQUEST:
284 CHECK_EXPECT(ReportProgress_SENDINGREQUEST);
285 if(tested_protocol == FILE_TEST) {
286 ok(szStatusText != NULL, "szStatusText == NULL\n");
288 ok(!*szStatusText, "wrong szStatusText\n");
290 ok(szStatusText == NULL, "szStatusText != NULL\n");
293 case BINDSTATUS_VERIFIEDMIMETYPEAVAILABLE:
294 CHECK_EXPECT(ReportProgress_VERIFIEDMIMETYPEAVAILABLE);
295 ok(szStatusText != NULL, "szStatusText == NULL\n");
297 ok(!lstrcmpW(szStatusText, text_html), "szStatusText != text/html\n");
300 ok(0, "Unexpected call %ld\n", ulStatusCode);
306 static HRESULT WINAPI ProtocolSink_ReportData(IInternetProtocolSink *iface, DWORD grfBSCF,
307 ULONG ulProgress, ULONG ulProgressMax)
309 if(tested_protocol == FILE_TEST) {
310 CHECK_EXPECT2(ReportData);
312 ok(ulProgress == ulProgressMax, "ulProgress (%ld) != ulProgressMax (%ld)\n",
313 ulProgress, ulProgressMax);
314 ok(ulProgressMax == 13, "ulProgressMax=%ld, expected 13\n", ulProgressMax);
315 ok(grfBSCF == (BSCF_FIRSTDATANOTIFICATION | BSCF_LASTDATANOTIFICATION),
316 "grcfBSCF = %08lx\n", grfBSCF);
317 }else if(tested_protocol == HTTP_TEST) {
318 if(!(grfBSCF & BSCF_LASTDATANOTIFICATION))
319 CHECK_EXPECT(ReportData);
321 ok(ulProgress, "ulProgress == 0\n");
323 if(first_data_notif) {
324 ok(grfBSCF == BSCF_FIRSTDATANOTIFICATION, "grcfBSCF = %08lx\n", grfBSCF);
325 first_data_notif = FALSE;
327 ok(grfBSCF == BSCF_INTERMEDIATEDATANOTIFICATION
328 || grfBSCF == (BSCF_LASTDATANOTIFICATION|BSCF_INTERMEDIATEDATANOTIFICATION),
329 "grcfBSCF = %08lx\n", grfBSCF);
335 static HRESULT WINAPI ProtocolSink_ReportResult(IInternetProtocolSink *iface, HRESULT hrResult,
336 DWORD dwError, LPCWSTR szResult)
338 CHECK_EXPECT(ReportResult);
340 ok(hrResult == expect_hrResult, "hrResult = %08lx, expected: %08lx\n",
341 hrResult, expect_hrResult);
342 if(SUCCEEDED(hrResult))
343 ok(dwError == ERROR_SUCCESS, "dwError = %ld, expected ERROR_SUCCESS\n", dwError);
345 ok(dwError != ERROR_SUCCESS, "dwError == ERROR_SUCCESS\n");
346 ok(!szResult, "szResult != NULL\n");
351 static IInternetProtocolSinkVtbl protocol_sink_vtbl = {
352 ProtocolSink_QueryInterface,
354 ProtocolSink_Release,
356 ProtocolSink_ReportProgress,
357 ProtocolSink_ReportData,
358 ProtocolSink_ReportResult
361 static IInternetProtocolSink protocol_sink = { &protocol_sink_vtbl };
363 static HRESULT QueryInterface(REFIID riid, void **ppv)
367 if(IsEqualGUID(&IID_IUnknown, riid) || IsEqualGUID(&IID_IInternetProtocolSink, riid))
368 *ppv = &protocol_sink;
369 if(IsEqualGUID(&IID_IServiceProvider, riid))
370 *ppv = &service_provider;
375 return E_NOINTERFACE;
378 static HRESULT WINAPI BindInfo_QueryInterface(IInternetBindInfo *iface, REFIID riid, void **ppv)
380 if(IsEqualGUID(&IID_IUnknown, riid) || IsEqualGUID(&IID_IInternetBindInfo, riid)) {
384 return E_NOINTERFACE;
387 static ULONG WINAPI BindInfo_AddRef(IInternetBindInfo *iface)
392 static ULONG WINAPI BindInfo_Release(IInternetBindInfo *iface)
397 static HRESULT WINAPI BindInfo_GetBindInfo(IInternetBindInfo *iface, DWORD *grfBINDF, BINDINFO *pbindinfo)
401 CHECK_EXPECT(GetBindInfo);
403 ok(grfBINDF != NULL, "grfBINDF == NULL\n");
404 ok(pbindinfo != NULL, "pbindinfo == NULL\n");
405 ok(pbindinfo->cbSize == sizeof(BINDINFO), "wrong size of pbindinfo: %ld\n", pbindinfo->cbSize);
408 cbSize = pbindinfo->cbSize;
409 memset(pbindinfo, 0, cbSize);
410 pbindinfo->cbSize = cbSize;
415 static HRESULT WINAPI BindInfo_GetBindString(IInternetBindInfo *iface, ULONG ulStringType,
416 LPOLESTR *ppwzStr, ULONG cEl, ULONG *pcElFetched)
418 static const WCHAR acc_mime[] = {'*','/','*',0};
419 static const WCHAR user_agent[] = {'W','i','n','e',0};
421 ok(ppwzStr != NULL, "ppwzStr == NULL\n");
422 ok(pcElFetched != NULL, "pcElFetched == NULL\n");
424 switch(ulStringType) {
425 case BINDSTRING_ACCEPT_MIMES:
426 CHECK_EXPECT(GetBindString_ACCEPT_MIMES);
427 ok(cEl == 256, "cEl=%ld, expected 256\n", cEl);
429 ok(*pcElFetched == 256, "*pcElFetched=%ld, expected 256\n", *pcElFetched);
433 *ppwzStr = CoTaskMemAlloc(sizeof(acc_mime));
434 memcpy(*ppwzStr, acc_mime, sizeof(acc_mime));
437 case BINDSTRING_USER_AGENT:
438 CHECK_EXPECT(GetBindString_USER_AGENT);
439 ok(cEl == 1, "cEl=%ld, expected 1\n", cEl);
441 ok(*pcElFetched == 0, "*pcElFetch=%ld, expectd 0\n", *pcElFetched);
445 *ppwzStr = CoTaskMemAlloc(sizeof(user_agent));
446 memcpy(*ppwzStr, user_agent, sizeof(user_agent));
450 ok(0, "unexpected call\n");
456 static IInternetBindInfoVtbl bind_info_vtbl = {
457 BindInfo_QueryInterface,
460 BindInfo_GetBindInfo,
461 BindInfo_GetBindString
464 static IInternetBindInfo bind_info = { &bind_info_vtbl };
466 static void test_priority(IInternetProtocol *protocol)
468 IInternetPriority *priority;
472 hres = IInternetProtocol_QueryInterface(protocol, &IID_IInternetPriority,
474 ok(hres == S_OK, "QueryInterface(IID_IInternetPriority) failed: %08lx\n", hres);
478 hres = IInternetPriority_GetPriority(priority, &pr);
479 ok(hres == S_OK, "GetPriority failed: %08lx\n", hres);
480 ok(pr == 0, "pr=%ld, expected 0\n", pr);
482 hres = IInternetPriority_SetPriority(priority, 1);
483 ok(hres == S_OK, "SetPriority failed: %08lx\n", hres);
485 hres = IInternetPriority_GetPriority(priority, &pr);
486 ok(hres == S_OK, "GetPriority failed: %08lx\n", hres);
487 ok(pr == 1, "pr=%ld, expected 1\n", pr);
489 IInternetPriority_Release(priority);
492 static void file_protocol_start(IInternetProtocol *protocol, LPCWSTR url, BOOL is_first)
496 SET_EXPECT(GetBindInfo);
497 if(!(bindf & BINDF_FROMURLMON))
498 SET_EXPECT(ReportProgress_DIRECTBIND);
500 SET_EXPECT(ReportProgress_SENDINGREQUEST);
501 SET_EXPECT(ReportProgress_CACHEFILENAMEAVAILABLE);
502 if(bindf & BINDF_FROMURLMON)
503 SET_EXPECT(ReportProgress_VERIFIEDMIMETYPEAVAILABLE);
505 SET_EXPECT(ReportProgress_MIMETYPEAVAILABLE);
507 SET_EXPECT(ReportData);
509 SET_EXPECT(ReportResult);
511 expect_hrResult = S_OK;
513 hres = IInternetProtocol_Start(protocol, url, &protocol_sink, &bind_info, 0, 0);
514 ok(hres == S_OK, "Start failed: %08lx\n", hres);
516 CHECK_CALLED(GetBindInfo);
517 if(!(bindf & BINDF_FROMURLMON))
518 CHECK_CALLED(ReportProgress_DIRECTBIND);
520 CHECK_CALLED(ReportProgress_SENDINGREQUEST);
521 CHECK_CALLED(ReportProgress_CACHEFILENAMEAVAILABLE);
522 if(bindf & BINDF_FROMURLMON)
523 CHECK_CALLED(ReportProgress_VERIFIEDMIMETYPEAVAILABLE);
525 CHECK_CALLED(ReportProgress_MIMETYPEAVAILABLE);
527 CHECK_CALLED(ReportData);
529 CHECK_CALLED(ReportResult);
532 static void test_file_protocol_url(LPCWSTR url)
534 IInternetProtocolInfo *protocol_info;
536 IClassFactory *factory;
539 hres = CoGetClassObject(&CLSID_FileProtocol, CLSCTX_INPROC_SERVER, NULL,
540 &IID_IUnknown, (void**)&unk);
541 ok(hres == S_OK, "CoGetClassObject failed: %08lx\n", hres);
545 hres = IUnknown_QueryInterface(unk, &IID_IInternetProtocolInfo, (void**)&protocol_info);
546 ok(hres == E_NOINTERFACE,
547 "Could not get IInternetProtocolInfo interface: %08lx, expected E_NOINTERFACE\n", hres);
549 hres = IUnknown_QueryInterface(unk, &IID_IClassFactory, (void**)&factory);
550 ok(hres == S_OK, "Could not get IClassFactory interface\n");
551 if(SUCCEEDED(hres)) {
552 IInternetProtocol *protocol;
555 hres = IClassFactory_CreateInstance(factory, NULL, &IID_IInternetProtocol, (void**)&protocol);
556 ok(hres == S_OK, "Could not get IInternetProtocol: %08lx\n", hres);
558 if(SUCCEEDED(hres)) {
559 file_protocol_start(protocol, url, TRUE);
560 hres = IInternetProtocol_Read(protocol, buf, 2, &cb);
561 ok(hres == S_OK, "Read failed: %08lx\n", hres);
562 ok(cb == 2, "cb=%lu expected 2\n", cb);
563 hres = IInternetProtocol_Read(protocol, buf, sizeof(buf), &cb);
564 ok(hres == S_FALSE, "Read failed: %08lx\n", hres);
565 hres = IInternetProtocol_Read(protocol, buf, sizeof(buf), &cb);
566 ok(hres == S_FALSE, "Read failed: %08lx expected S_FALSE\n", hres);
567 ok(cb == 0, "cb=%lu expected 0\n", cb);
568 hres = IInternetProtocol_UnlockRequest(protocol);
569 ok(hres == S_OK, "UnlockRequest failed: %08lx\n", hres);
571 file_protocol_start(protocol, url, FALSE);
572 hres = IInternetProtocol_Read(protocol, buf, 2, &cb);
573 ok(hres == S_FALSE, "Read failed: %08lx\n", hres);
574 hres = IInternetProtocol_LockRequest(protocol, 0);
575 ok(hres == S_OK, "LockRequest failed: %08lx\n", hres);
576 hres = IInternetProtocol_UnlockRequest(protocol);
577 ok(hres == S_OK, "UnlockRequest failed: %08lx\n", hres);
579 IInternetProtocol_Release(protocol);
582 hres = IClassFactory_CreateInstance(factory, NULL, &IID_IInternetProtocol, (void**)&protocol);
583 ok(hres == S_OK, "Could not get IInternetProtocol: %08lx\n", hres);
585 if(SUCCEEDED(hres)) {
586 file_protocol_start(protocol, url, TRUE);
587 hres = IInternetProtocol_LockRequest(protocol, 0);
588 ok(hres == S_OK, "LockRequest failed: %08lx\n", hres);
589 hres = IInternetProtocol_Terminate(protocol, 0);
590 ok(hres == S_OK, "Terminate failed: %08lx\n", hres);
591 hres = IInternetProtocol_Read(protocol, buf, 2, &cb);
592 ok(hres == S_OK, "Read failed: %08lx\n\n", hres);
593 hres = IInternetProtocol_UnlockRequest(protocol);
594 ok(hres == S_OK, "UnlockRequest failed: %08lx\n", hres);
595 hres = IInternetProtocol_Read(protocol, buf, 2, &cb);
596 ok(hres == S_OK, "Read failed: %08lx\n", hres);
597 hres = IInternetProtocol_Terminate(protocol, 0);
598 ok(hres == S_OK, "Terminate failed: %08lx\n", hres);
600 IInternetProtocol_Release(protocol);
603 hres = IClassFactory_CreateInstance(factory, NULL, &IID_IInternetProtocol, (void**)&protocol);
604 ok(hres == S_OK, "Could not get IInternetProtocol: %08lx\n", hres);
606 if(SUCCEEDED(hres)) {
607 file_protocol_start(protocol, url, TRUE);
608 hres = IInternetProtocol_Terminate(protocol, 0);
609 ok(hres == S_OK, "Terminate failed: %08lx\n", hres);
610 hres = IInternetProtocol_Read(protocol, buf, 2, &cb);
611 ok(hres == S_OK, "Read failed: %08lx\n", hres);
612 ok(cb == 2, "cb=%lu expected 2\n", cb);
614 IInternetProtocol_Release(protocol);
617 IClassFactory_Release(factory);
620 IUnknown_Release(unk);
623 static void test_file_protocol_fail(void)
625 IInternetProtocol *protocol;
628 static const WCHAR index_url2[] =
629 {'f','i','l','e',':','/','/','i','n','d','e','x','.','h','t','m','l',0};
631 hres = CoCreateInstance(&CLSID_FileProtocol, NULL, CLSCTX_INPROC_SERVER|CLSCTX_INPROC_HANDLER,
632 &IID_IInternetProtocol, (void**)&protocol);
633 ok(hres == S_OK, "CoCreateInstance failed: %08lx\n", hres);
637 SET_EXPECT(GetBindInfo);
638 expect_hrResult = MK_E_SYNTAX;
639 hres = IInternetProtocol_Start(protocol, wszIndexHtml, &protocol_sink, &bind_info, 0, 0);
640 ok(hres == MK_E_SYNTAX, "Start failed: %08lx, expected MK_E_SYNTAX\n", hres);
641 CHECK_CALLED(GetBindInfo);
643 SET_EXPECT(GetBindInfo);
644 if(!(bindf & BINDF_FROMURLMON))
645 SET_EXPECT(ReportProgress_DIRECTBIND);
646 SET_EXPECT(ReportProgress_SENDINGREQUEST);
647 SET_EXPECT(ReportResult);
648 expect_hrResult = INET_E_RESOURCE_NOT_FOUND;
649 hres = IInternetProtocol_Start(protocol, index_url, &protocol_sink, &bind_info, 0, 0);
650 ok(hres == INET_E_RESOURCE_NOT_FOUND,
651 "Start failed: %08lx expected INET_E_RESOURCE_NOT_FOUND\n", hres);
652 CHECK_CALLED(GetBindInfo);
653 if(!(bindf & BINDF_FROMURLMON))
654 CHECK_CALLED(ReportProgress_DIRECTBIND);
655 CHECK_CALLED(ReportProgress_SENDINGREQUEST);
656 CHECK_CALLED(ReportResult);
658 IInternetProtocol_Release(protocol);
660 hres = CoCreateInstance(&CLSID_FileProtocol, NULL, CLSCTX_INPROC_SERVER|CLSCTX_INPROC_HANDLER,
661 &IID_IInternetProtocol, (void**)&protocol);
662 ok(hres == S_OK, "CoCreateInstance failed: %08lx\n", hres);
666 SET_EXPECT(GetBindInfo);
667 if(!(bindf & BINDF_FROMURLMON))
668 SET_EXPECT(ReportProgress_DIRECTBIND);
669 SET_EXPECT(ReportProgress_SENDINGREQUEST);
670 SET_EXPECT(ReportResult);
671 expect_hrResult = INET_E_RESOURCE_NOT_FOUND;
673 hres = IInternetProtocol_Start(protocol, index_url2, &protocol_sink, &bind_info, 0, 0);
674 ok(hres == INET_E_RESOURCE_NOT_FOUND,
675 "Start failed: %08lx, expected INET_E_RESOURCE_NOT_FOUND\n", hres);
676 CHECK_CALLED(GetBindInfo);
677 if(!(bindf & BINDF_FROMURLMON))
678 CHECK_CALLED(ReportProgress_DIRECTBIND);
679 CHECK_CALLED(ReportProgress_SENDINGREQUEST);
680 CHECK_CALLED(ReportResult);
682 IInternetProtocol_Release(protocol);
685 static void test_file_protocol(void) {
691 static const WCHAR wszFile[] = {'f','i','l','e',':',0};
692 static const WCHAR wszFile2[] = {'f','i','l','e',':','/','/',0};
693 static const WCHAR wszFile3[] = {'f','i','l','e',':','/','/','/',0};
694 static const char html_doc[] = "<HTML></HTML>";
696 tested_protocol = FILE_TEST;
698 file = CreateFileW(wszIndexHtml, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS,
699 FILE_ATTRIBUTE_NORMAL, NULL);
700 ok(file != INVALID_HANDLE_VALUE, "CreateFile failed\n");
701 if(file == INVALID_HANDLE_VALUE)
703 WriteFile(file, html_doc, sizeof(html_doc)-1, &size, NULL);
706 file_name = wszIndexHtml;
708 test_file_protocol_url(index_url);
709 bindf = BINDF_FROMURLMON;
710 test_file_protocol_url(index_url);
712 memcpy(buf, wszFile, sizeof(wszFile));
713 len = sizeof(wszFile)/sizeof(WCHAR)-1;
714 len += GetCurrentDirectoryW(sizeof(buf)/sizeof(WCHAR)-len, buf+len);
716 memcpy(buf+len, wszIndexHtml, sizeof(wszIndexHtml));
718 file_name = buf + sizeof(wszFile)/sizeof(WCHAR)-1;
720 test_file_protocol_url(buf);
721 bindf = BINDF_FROMURLMON;
722 test_file_protocol_url(buf);
724 memcpy(buf, wszFile2, sizeof(wszFile2));
725 len = sizeof(wszFile2)/sizeof(WCHAR)-1;
726 len += GetCurrentDirectoryW(sizeof(buf)/sizeof(WCHAR)-len, buf+len);
728 memcpy(buf+len, wszIndexHtml, sizeof(wszIndexHtml));
730 file_name = buf + sizeof(wszFile2)/sizeof(WCHAR)-1;
732 test_file_protocol_url(buf);
733 bindf = BINDF_FROMURLMON;
734 test_file_protocol_url(buf);
736 memcpy(buf, wszFile3, sizeof(wszFile3));
737 len = sizeof(wszFile3)/sizeof(WCHAR)-1;
738 len += GetCurrentDirectoryW(sizeof(buf)/sizeof(WCHAR)-len, buf+len);
740 memcpy(buf+len, wszIndexHtml, sizeof(wszIndexHtml));
742 file_name = buf + sizeof(wszFile3)/sizeof(WCHAR)-1;
744 test_file_protocol_url(buf);
745 bindf = BINDF_FROMURLMON;
746 test_file_protocol_url(buf);
748 DeleteFileW(wszIndexHtml);
751 test_file_protocol_fail();
752 bindf = BINDF_FROMURLMON;
753 test_file_protocol_fail();
756 static BOOL http_protocol_start(LPCWSTR url, BOOL is_first)
760 first_data_notif = TRUE;
762 SET_EXPECT(GetBindInfo);
763 SET_EXPECT(GetBindString_USER_AGENT);
764 SET_EXPECT(GetBindString_ACCEPT_MIMES);
765 SET_EXPECT(QueryService_HttpNegotiate);
766 SET_EXPECT(BeginningTransaction);
767 SET_EXPECT(GetRootSecurityId);
769 hres = IInternetProtocol_Start(http_protocol, url, &protocol_sink, &bind_info, 0, 0);
771 ok(hres == S_OK, "Start failed: %08lx\n", hres);
776 CHECK_CALLED(GetBindInfo);
777 CHECK_CALLED(GetBindString_USER_AGENT);
778 CHECK_CALLED(GetBindString_ACCEPT_MIMES);
779 CHECK_CALLED(QueryService_HttpNegotiate);
780 CHECK_CALLED(BeginningTransaction);
781 CHECK_CALLED(GetRootSecurityId);
786 static void test_http_protocol_url(LPCWSTR url)
788 IInternetProtocolInfo *protocol_info;
789 IClassFactory *factory;
795 hres = CoGetClassObject(&CLSID_HttpProtocol, CLSCTX_INPROC_SERVER, NULL,
796 &IID_IUnknown, (void**)&unk);
797 ok(hres == S_OK, "CoGetClassObject failed: %08lx\n", hres);
801 hres = IUnknown_QueryInterface(unk, &IID_IInternetProtocolInfo, (void**)&protocol_info);
802 ok(hres == E_NOINTERFACE,
803 "Could not get IInternetProtocolInfo interface: %08lx, expected E_NOINTERFACE\n",
806 hres = IUnknown_QueryInterface(unk, &IID_IClassFactory, (void**)&factory);
807 ok(hres == S_OK, "Could not get IClassFactory interface\n");
808 IUnknown_Release(unk);
812 hres = IClassFactory_CreateInstance(factory, NULL, &IID_IInternetProtocol,
813 (void**)&http_protocol);
814 ok(hres == S_OK, "Could not get IInternetProtocol: %08lx\n", hres);
815 if(SUCCEEDED(hres)) {
820 bindf = BINDF_ASYNCHRONOUS | BINDF_ASYNCSTORAGE | BINDF_PULLDATA | BINDF_FROMURLMON;
822 test_priority(http_protocol);
824 SET_EXPECT(ReportProgress_FINDINGRESOURCE);
825 SET_EXPECT(ReportProgress_CONNECTING);
826 SET_EXPECT(ReportProgress_SENDINGREQUEST);
828 if(!http_protocol_start(url, TRUE))
831 hres = IInternetProtocol_Read(http_protocol, buf, 2, &cb);
832 ok(hres == E_PENDING, "Read failed: %08lx, expected E_PENDING\n", hres);
833 ok(!cb, "cb=%ld, expected 0\n", cb);
836 SET_EXPECT(ReportResult);
837 expect_hrResult = S_OK;
839 GetMessageW(&msg, NULL, 0, 0);
841 CHECK_CALLED(Switch);
842 CHECK_CALLED(ReportResult);
844 IInternetProtocol_Release(http_protocol);
847 IClassFactory_Release(factory);
850 static void test_http_protocol(void)
852 static const WCHAR winehq_url[] =
853 {'h','t','t','p',':','/','/','w','w','w','.','w','i','n','e','h','q','.',
854 'o','r','g','/','s','i','t','e','/','a','b','o','u','t',0};
856 tested_protocol = HTTP_TEST;
857 test_http_protocol_url(winehq_url);
861 static LRESULT WINAPI wnd_proc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
868 SET_EXPECT(ReportData);
870 CHECK_CALLED(ReportProgress_FINDINGRESOURCE);
871 CHECK_CALLED(ReportProgress_CONNECTING);
872 CHECK_CALLED(ReportProgress_SENDINGREQUEST);
874 SET_EXPECT(OnResponse);
875 SET_EXPECT(ReportProgress_MIMETYPEAVAILABLE);
878 hres = IInternetProtocol_Continue(http_protocol, (PROTOCOLDATA*)lParam);
879 ok(hres == S_OK, "Continue failed: %08lx\n", hres);
881 CHECK_CALLED(ReportData);
883 CHECK_CALLED(OnResponse);
884 CHECK_CALLED(ReportProgress_MIMETYPEAVAILABLE);
887 do hres = IInternetProtocol_Read(http_protocol, buf, sizeof(buf), &cb);
890 ok(hres == S_FALSE || hres == E_PENDING, "Read failed: %08lx\n", hres);
893 PostMessageW(protocol_hwnd, WM_USER+1, 0, 0);
898 hres = IInternetProtocol_LockRequest(http_protocol, 0);
899 ok(hres == S_OK, "LockRequest failed: %08lx\n", hres);
901 do hres = IInternetProtocol_Read(http_protocol, buf, sizeof(buf), &cb);
903 ok(hres == S_FALSE || hres == E_PENDING, "Read failed: %08lx\n", hres);
907 return DefWindowProc(hwnd, msg, wParam, lParam);
910 static HWND create_protocol_window(void)
912 static const WCHAR wszProtocolWindow[] =
913 {'P','r','o','t','o','c','o','l','W','i','n','d','o','w',0};
914 static WNDCLASSEXW wndclass = {
918 0, 0, NULL, NULL, NULL, NULL, NULL,
923 RegisterClassExW(&wndclass);
924 return CreateWindowW(wszProtocolWindow, wszProtocolWindow,
925 WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
926 CW_USEDEFAULT, NULL, NULL, NULL, NULL);
933 protocol_hwnd = create_protocol_window();
935 test_file_protocol();
936 test_http_protocol();
938 DestroyWindow(protocol_hwnd);